diff -r 35c88c53cf64 -r ecc10f0afb76 .gitignore --- a/.gitignore Fri Jul 26 23:14:22 2013 -0700 +++ b/.gitignore Fri Feb 01 23:12:09 2013 +0100 @@ -15,13 +15,11 @@ Doc/tools/pygments/ Doc/tools/sphinx/ Lib/lib2to3/*.pickle -Lib/test/data/* Lib/_sysconfigdata.py Lib/plat-mac/errors.rsrc.df.rsrc Makefile Makefile.pre Misc/python.pc -Misc/python-config.sh Modules/Setup Modules/Setup.config Modules/Setup.local @@ -59,8 +57,6 @@ pybuilddir.txt pyconfig.h python -python-config -python-config.py python.exe python-gdb.py python.exe-gdb.py diff -r 35c88c53cf64 -r ecc10f0afb76 .hgignore --- a/.hgignore Fri Jul 26 23:14:22 2013 -0700 +++ b/.hgignore Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,6 @@ .gdb_history .purify .svn/ -.DS_Store Makefile$ Makefile.pre$ TAGS$ @@ -18,8 +17,6 @@ pyconfig.h$ python$ python.exe$ -python-config$ -python-config.py$ reflog.txt$ tags$ Lib/plat-mac/errors.rsrc.df.rsrc @@ -29,7 +26,6 @@ Doc/tools/jinja2/ Doc/tools/pygments/ Misc/python.pc -Misc/python-config.sh$ Modules/Setup$ Modules/Setup.config Modules/Setup.local diff -r 35c88c53cf64 -r ecc10f0afb76 .hgtags --- a/.hgtags Fri Jul 26 23:14:22 2013 -0700 +++ b/.hgtags Fri Feb 01 23:12:09 2013 +0100 @@ -99,8 +99,6 @@ 7085403daf439adb3f9e70ef13f6bedb1c447376 v3.2.3rc1 428f05cb7277e1d42bb9dd8d1af6b6270ebc6112 v3.2.3rc2 3d0686d90f55a78f96d9403da2c52dc2411419d0 v3.2.3 -b2cb7bc1edb8493c0a78f9331eae3e8fba6a881d v3.2.4rc1 -1e10bdeabe3de02f038a63c001911561ac1d13a7 v3.2.4 f1a9a6505731714f0e157453ff850e3b71615c45 v3.3.0a1 2f69db52d6de306cdaef0a0cc00cc823fb350b01 v3.3.0a2 0b53b70a40a00013505eb35e3660057b62be77be v3.3.0a3 @@ -111,6 +109,3 @@ 88a0792e8ba3e4916b24c7e7a522c277d326d66e v3.3.0rc2 c191d21cefafb3832c45570e84854e309aa62eaa v3.3.0rc3 bd8afb90ebf28ba4edc901d4a235f75e7bbc79fd v3.3.0 -92c2cfb924055ce68c4f78f836dcfe688437ceb8 v3.3.1rc1 -d9893d13c6289aa03d33559ec67f97dcbf5c9e3c v3.3.1 -d047928ae3f6314a13b6137051315453d0ae89b6 v3.3.2 diff -r 35c88c53cf64 -r ecc10f0afb76 .hgtouch --- a/.hgtouch Fri Jul 26 23:14:22 2013 -0700 +++ b/.hgtouch Fri Feb 01 23:12:09 2013 +0100 @@ -2,14 +2,11 @@ # Define dependencies of generated files that are checked into hg. # The syntax of this file uses make rule dependencies, without actions -Python/importlib.h: Lib/importlib/_bootstrap.py Modules/_freeze_importlib.c +Python/importlib.h: Lib/importlib/_bootstrap.py Python/freeze_importlib.py Include/ast.h: Parser/Python.asdl Parser/asdl.py Parser/asdl_c.py Python/Python-ast.c: Include/ast.h Python/opcode_targets.h: Python/makeopcodetargets.py Lib/opcode.py -Objects/typeslots.inc: Include/typeslots.h Objects/typeslots.py - -Include/graminit.h: Grammar/Grammar Parser/acceler.c Parser/grammar1.c Parser/listnode.c Parser/node.c Parser/parser.c Parser/bitset.c Parser/metagrammar.c Parser/firstsets.c Parser/grammar.c Parser/pgen.c Objects/obmalloc.c Python/dynamic_annotations.c Python/mysnprintf.c Python/pyctype.c Parser/tokenizer_pgen.c Parser/printgrammar.c Parser/parsetok_pgen.c Parser/pgenmain.c -Python/graminit.c: Include/graminit.h Grammar/Grammar Parser/acceler.c Parser/grammar1.c Parser/listnode.c Parser/node.c Parser/parser.c Parser/bitset.c Parser/metagrammar.c Parser/firstsets.c Parser/grammar.c Parser/pgen.c Objects/obmalloc.c Python/dynamic_annotations.c Python/mysnprintf.c Python/pyctype.c Parser/tokenizer_pgen.c Parser/printgrammar.c Parser/parsetok_pgen.c Parser/pgenmain.c +Objects/typeslots.inc: Include/typeslots.h Objects/typeslots.py \ No newline at end of file diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/apiabiversion.rst --- a/Doc/c-api/apiabiversion.rst Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -.. highlightlang:: c - -.. _apiabiversion: - -*********************** -API and ABI Versioning -*********************** - -``PY_VERSION_HEX`` is the Python version number encoded in a single integer. - -For example if the ``PY_VERSION_HEX`` is set to ``0x030401a2``, the underlying -version information can be found by treating it as a 32 bit number in -the following manner: - - +-------+-------------------------+------------------------------------------------+ - | Bytes | Bits (big endian order) | Meaning | - +=======+=========================+================================================+ - | ``1`` | ``1-8`` | ``PY_MAJOR_VERSION`` (the ``3`` in | - | | | ``3.4.1a2``) | - +-------+-------------------------+------------------------------------------------+ - | ``2`` | ``9-16`` | ``PY_MINOR_VERSION`` (the ``4`` in | - | | | ``3.4.1a2``) | - +-------+-------------------------+------------------------------------------------+ - | ``3`` | ``17-24`` | ``PY_MICRO_VERSION`` (the ``1`` in | - | | | ``3.4.1a2``) | - +-------+-------------------------+------------------------------------------------+ - | ``4`` | ``25-28`` | ``PY_RELEASE_LEVEL`` (``0xA`` for alpha, | - | | | ``0xB`` for beta, ``0xC`` for release | - | | | candidate and ``0xF`` for final), in this | - | | | case it is alpha. | - +-------+-------------------------+------------------------------------------------+ - | | ``29-32`` | ``PY_RELEASE_SERIAL`` (the ``2`` in | - | | | ``3.4.1a2``, zero for final releases) | - +-------+-------------------------+------------------------------------------------+ - -Thus ``3.4.1a2`` is hexversion ``0x030401a2``. - -All the given macros are defined in :source:`Include/patchlevel.h`. - diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/arg.rst --- a/Doc/c-api/arg.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/arg.rst Fri Feb 01 23:12:09 2013 +0100 @@ -70,7 +70,8 @@ as *converter*. ``s*`` (:class:`str`, :class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer] - This format accepts Unicode objects as well as :term:`bytes-like object`\ s. + This format accepts Unicode objects as well as objects supporting the + buffer protocol. It fills a :c:type:`Py_buffer` structure provided by the caller. In this case the resulting C string may contain embedded NUL bytes. Unicode objects are converted to C strings using ``'utf-8'`` encoding. @@ -100,14 +101,14 @@ contain embedded NUL bytes; if it does, a :exc:`TypeError` exception is raised. -``y*`` (:class:`bytes`, :class:`bytearray` or :term:`bytes-like object`) [Py_buffer] - This variant on ``s*`` doesn't accept Unicode objects, only - :term:`bytes-like object`\ s. **This is the recommended way to accept +``y*`` (:class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer] + This variant on ``s*`` doesn't accept Unicode objects, only objects + supporting the buffer protocol. **This is the recommended way to accept binary data.** ``y#`` (:class:`bytes`) [const char \*, int] - This variant on ``s#`` doesn't accept Unicode objects, only :term:`bytes-like - object`\ s. + This variant on ``s#`` doesn't accept Unicode objects, only bytes-like + objects. ``S`` (:class:`bytes`) [PyBytesObject \*] Requires that the Python object is a :class:`bytes` object, without diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/buffer.rst --- a/Doc/c-api/buffer.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/buffer.rst Fri Feb 01 23:12:09 2013 +0100 @@ -263,7 +263,6 @@ in decreasing order of complexity. Note that each flag contains all bits of the flags below it. -.. tabularcolumns:: |p{0.35\linewidth}|l|l|l| +-----------------------------+-------+---------+------------+ | Request | shape | strides | suboffsets | @@ -284,8 +283,6 @@ C or Fortran contiguity can be explicitly requested, with and without stride information. Without stride information, the buffer must be C-contiguous. -.. tabularcolumns:: |p{0.35\linewidth}|l|l|l|l| - +-----------------------------------+-------+---------+------------+--------+ | Request | shape | strides | suboffsets | contig | +===================================+=======+=========+============+========+ @@ -309,7 +306,7 @@ In the following table *U* stands for undefined contiguity. The consumer would have to call :c:func:`PyBuffer_IsContiguous` to determine contiguity. -.. tabularcolumns:: |p{0.35\linewidth}|l|l|l|l|l|l| + +-------------------------------+-------+---------+------------+--------+----------+--------+ | Request | shape | strides | suboffsets | contig | readonly | format | diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/bytearray.rst --- a/Doc/c-api/bytearray.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/bytearray.rst Fri Feb 01 23:12:09 2013 +0100 @@ -40,7 +40,7 @@ .. c:function:: PyObject* PyByteArray_FromObject(PyObject *o) Return a new bytearray object from any object, *o*, that implements the - :ref:`buffer protocol `. + buffer protocol. .. XXX expand about the buffer protocol, at least somewhere diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/bytes.rst --- a/Doc/c-api/bytes.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/bytes.rst Fri Feb 01 23:12:09 2013 +0100 @@ -62,8 +62,6 @@ .. % because not all compilers support the %z width modifier -- we fake it .. % when necessary via interpolating PY_FORMAT_SIZE_T. - .. tabularcolumns:: |l|l|L| - +-------------------+---------------+--------------------------------+ | Format Characters | Type | Comment | +===================+===============+================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/dict.rst --- a/Doc/c-api/dict.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/dict.rst Fri Feb 01 23:12:09 2013 +0100 @@ -110,15 +110,6 @@ :c:type:`char\*`, rather than a :c:type:`PyObject\*`. -.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default) - - This is the same as the Python-level :meth:`dict.setdefault`. If present, it - returns the value corresponding to *key* from the dictionary *p*. If the key - is not in the dict, it is inserted with value *defaultobj* and *defaultobj* - is returned. This function evaluates the hash function of *key* only once, - instead of evaluating it independently for the lookup and the insertion. - - .. c:function:: PyObject* PyDict_Items(PyObject *p) Return a :c:type:`PyListObject` containing all the items from the dictionary. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/exceptions.rst --- a/Doc/c-api/exceptions.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/exceptions.rst Fri Feb 01 23:12:09 2013 +0100 @@ -222,19 +222,13 @@ when the system call returns an error. -.. c:function:: PyObject* PyErr_SetFromErrnoWithFilenameObject(PyObject *type, PyObject *filenameObject) +.. c:function:: PyObject* PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename) Similar to :c:func:`PyErr_SetFromErrno`, with the additional behavior that if - *filenameObject* is not *NULL*, it is passed to the constructor of *type* as - a third parameter. In the case of exceptions such as :exc:`IOError` and - :exc:`OSError`, this is used to define the :attr:`filename` attribute of the - exception instance. - - -.. c:function:: PyObject* PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename) - - Similar to :c:func:`PyErr_SetFromErrnoWithFilenameObject`, but the filename - is given as a C string. *filename* is decoded from the filesystem encoding + *filename* is not *NULL*, it is passed to the constructor of *type* as a third + parameter. In the case of exceptions such as :exc:`IOError` and :exc:`OSError`, + this is used to define the :attr:`filename` attribute of the exception instance. + *filename* is decoded from the filesystem encoding (:func:`sys.getfilesystemencoding`). @@ -256,28 +250,16 @@ specifying the exception type to be raised. Availability: Windows. -.. c:function:: PyObject* PyErr_SetFromWindowsErrWithFilenameObject(int ierr, PyObject *filenameObject) - - Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior - that if *filenameObject* is not *NULL*, it is passed to the constructor of - :exc:`WindowsError` as a third parameter. Availability: Windows. - - .. c:function:: PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename) - Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, but the - filename is given as a C string. *filename* is decoded from the filesystem - encoding (:func:`sys.getfilesystemencoding`). Availability: Windows. + Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior that + if *filename* is not *NULL*, it is passed to the constructor of + :exc:`WindowsError` as a third parameter. *filename* is decoded from the + filesystem encoding (:func:`sys.getfilesystemencoding`). Availability: + Windows. -.. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type, int ierr, PyObject *filename) - - Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, with an - additional parameter specifying the exception type to be raised. - Availability: Windows. - - -.. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, const char *filename) +.. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, char *filename) Similar to :c:func:`PyErr_SetFromWindowsErrWithFilename`, with an additional parameter specifying the exception type to be raised. Availability: Windows. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/index.rst --- a/Doc/c-api/index.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/index.rst Fri Feb 01 23:12:09 2013 +0100 @@ -23,4 +23,3 @@ memory.rst objimpl.rst stable.rst - apiabiversion.rst diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/init.rst --- a/Doc/c-api/init.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/init.rst Fri Feb 01 23:12:09 2013 +0100 @@ -654,20 +654,6 @@ made on the main thread. This is mainly a helper/diagnostic function. -.. c:function:: int PyGILState_Check() - - Return 1 if the current thread is holding the GIL and 0 otherwise. - This function can be called from any thread at any time. - Only if it has had its Python thread state initialized and currently is - holding the GIL will it return 1. - This is mainly a helper/diagnostic function. It can be useful - for example in callback contexts or memory allocation functions when - knowing that the GIL is locked can allow the caller to perform sensitive - actions or otherwise behave differently. - - .. versionadded:: 3.4 - - The following macros are normally used without a trailing semicolon; look for example usage in the Python source distribution. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/intro.rst --- a/Doc/c-api/intro.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/intro.rst Fri Feb 01 23:12:09 2013 +0100 @@ -210,7 +210,7 @@ t = PyTuple_New(3); PyTuple_SetItem(t, 0, PyLong_FromLong(1L)); PyTuple_SetItem(t, 1, PyLong_FromLong(2L)); - PyTuple_SetItem(t, 2, PyUnicode_FromString("three")); + PyTuple_SetItem(t, 2, PyString_FromString("three")); Here, :c:func:`PyLong_FromLong` returns a new reference which is immediately stolen by :c:func:`PyTuple_SetItem`. When you want to keep using an object @@ -433,7 +433,7 @@ .. index:: single: sum_sequence() A simple example of detecting exceptions and passing them on is shown in the -:c:func:`sum_sequence` example above. It so happens that this example doesn't +:c:func:`sum_sequence` example above. It so happens that that example doesn't need to clean up any owned references when it detects an error. The following example function shows some error cleanup. First, to remind you why you like Python, we show the equivalent Python code:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/long.rst --- a/Doc/c-api/long.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/long.rst Fri Feb 01 23:12:09 2013 +0100 @@ -203,7 +203,7 @@ .. c:function:: size_t PyLong_AsSize_t(PyObject *pylong) - Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be + Return a C :c:type:`size_t` representation of of *pylong*. *pylong* must be an instance of :c:type:`PyLongObject`. Raise :exc:`OverflowError` if the value of *pylong* is out of range for a @@ -215,7 +215,7 @@ .. index:: single: OverflowError (built-in exception) - Return a C :c:type:`unsigned PY_LONG_LONG` representation of *pylong*. + Return a C :c:type:`unsigned PY_LONG_LONG` representation of of *pylong*. *pylong* must be an instance of :c:type:`PyLongObject`. Raise :exc:`OverflowError` if the value of *pylong* is out of range for an diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/memory.rst --- a/Doc/c-api/memory.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/memory.rst Fri Feb 01 23:12:09 2013 +0100 @@ -61,7 +61,7 @@ if (buf == NULL) return PyErr_NoMemory(); ...Do some I/O operation involving buf... - res = PyBytes_FromString(buf); + res = PyString_FromString(buf); free(buf); /* malloc'ed */ return res; @@ -84,48 +84,6 @@ for the I/O buffer escapes completely the Python memory manager. -Raw Memory Interface -==================== - -The following function sets are wrappers to the system allocator. These -functions are thread-safe, the :term:`GIL ` does not -need to be held. - -The default raw memory block allocator uses the following functions: -:c:func:`malloc`, :c:func:`realloc` and :c:func:`free`; call ``malloc(1)`` when -requesting zero bytes. - -.. versionadded:: 3.4 - -.. c:function:: void* PyMem_RawMalloc(size_t n) - - Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the - allocated memory, or *NULL* if the request fails. Requesting zero bytes - returns a distinct non-*NULL* pointer if possible, as if - ``PyMem_RawMalloc(1)`` had been called instead. The memory will not have - been initialized in any way. - - -.. c:function:: void* PyMem_RawRealloc(void *p, size_t n) - - Resizes the memory block pointed to by *p* to *n* bytes. The contents will - be unchanged to the minimum of the old and the new sizes. If *p* is *NULL*, - the call is equivalent to ``PyMem_RawMalloc(n)``; else if *n* is equal to - zero, the memory block is resized but is not freed, and the returned pointer - is non-*NULL*. Unless *p* is *NULL*, it must have been returned by a - previous call to :c:func:`PyMem_RawMalloc` or :c:func:`PyMem_RawRealloc`. If - the request fails, :c:func:`PyMem_RawRealloc` returns *NULL* and *p* remains - a valid pointer to the previous memory area. - - -.. c:function:: void PyMem_RawFree(void *p) - - Frees the memory block pointed to by *p*, which must have been returned by a - previous call to :c:func:`PyMem_RawMalloc` or :c:func:`PyMem_RawRealloc`. - Otherwise, or if ``PyMem_Free(p)`` has been called before, undefined - behavior occurs. If *p* is *NULL*, no operation is performed. - - .. _memoryinterface: Memory Interface @@ -133,16 +91,8 @@ The following function sets, modeled after the ANSI C standard, but specifying behavior when requesting zero bytes, are available for allocating and releasing -memory from the Python heap. +memory from the Python heap: -The default memory block allocator uses the following functions: -:c:func:`malloc`, :c:func:`realloc` and :c:func:`free`; call ``malloc(1)`` when -requesting zero bytes. - -.. warning:: - - The :term:`GIL ` must be held when using these - functions. .. c:function:: void* PyMem_Malloc(size_t n) @@ -205,125 +155,6 @@ :c:func:`PyMem_NEW`, :c:func:`PyMem_RESIZE`, :c:func:`PyMem_DEL`. -Customize Memory Allocators -=========================== - -.. versionadded:: 3.4 - -.. c:type:: PyMemAllocator - - Structure used to describe a memory block allocator. The structure has - four fields: - - +----------------------------------------------------------+---------------------------------------+ - | Field | Meaning | - +==========================================================+=======================================+ - | ``void *ctx`` | user context passed as first argument | - +----------------------------------------------------------+---------------------------------------+ - | ``void* malloc(void *ctx, size_t size)`` | allocate a memory block | - +----------------------------------------------------------+---------------------------------------+ - | ``void* realloc(void *ctx, void *ptr, size_t new_size)`` | allocate or resize a memory block | - +----------------------------------------------------------+---------------------------------------+ - | ``void free(void *ctx, void *ptr)`` | free a memory block | - +----------------------------------------------------------+---------------------------------------+ - -.. c:type:: PyMemAllocatorDomain - - Enum used to identify an allocator domain. Domains: - - * :c:data:`PYMEM_DOMAIN_RAW`: functions :c:func:`PyMem_RawMalloc`, - :c:func:`PyMem_RawRealloc` and :c:func:`PyMem_RawFree` - * :c:data:`PYMEM_DOMAIN_MEM`: functions :c:func:`PyMem_Malloc`, - :c:func:`PyMem_Realloc` and :c:func:`PyMem_Free` - * :c:data:`PYMEM_DOMAIN_OBJ`: functions :c:func:`PyObject_Malloc`, - :c:func:`PyObject_Realloc` and :c:func:`PyObject_Free` - - -.. c:function:: void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) - - Get the memory block allocator of the specified domain. - - -.. c:function:: void PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) - - Set the memory block allocator of the specified domain. - - The new allocator must return a distinct non-NULL pointer when requesting - zero bytes. - - For the :c:data:`PYMEM_DOMAIN_RAW` domain, the allocator must be - thread-safe: the :term:`GIL ` is not held when the - allocator is called. - - If the new allocator is not a hook (does not call the previous allocator), - the :c:func:`PyMem_SetupDebugHooks` function must be called to reinstall the - debug hooks on top on the new allocator. - - -.. c:function:: void PyMem_SetupDebugHooks(void) - - Setup hooks to detect bugs in the following Python memory allocator - functions: - - - :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawRealloc`, - :c:func:`PyMem_RawFree` - - :c:func:`PyMem_Malloc`, :c:func:`PyMem_Realloc`, :c:func:`PyMem_Free` - - :c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc`, - :c:func:`PyObject_Free` - - Newly allocated memory is filled with the byte ``0xCB``, freed memory is - filled with the byte ``0xDB``. Additionnal checks: - - - detect API violations, ex: :c:func:`PyObject_Free` called on a buffer - allocated by :c:func:`PyMem_Malloc` - - detect write before the start of the buffer (buffer underflow) - - detect write after the end of the buffer (buffer overflow) - - The function does nothing if Python is not compiled is debug mode. - - -Customize PyObject Arena Allocator -================================== - -Python has a *pymalloc* allocator for allocations smaller than 512 bytes. This -allocator is optimized for small objects with a short lifetime. It uses memory -mappings called "arenas" with a fixed size of 256 KB. It falls back to -:c:func:`PyMem_Malloc` and :c:func:`PyMem_Realloc` for allocations larger than -512 bytes. *pymalloc* is the default allocator used by -:c:func:`PyObject_Malloc`. - -The default arena allocator uses the following functions: - -* :c:func:`VirtualAlloc` and :c:func:`VirtualFree` on Windows, -* :c:func:`mmap` and :c:func:`munmap` if available, -* :c:func:`malloc` and :c:func:`free` otherwise. - -.. versionadded:: 3.4 - -.. c:type:: PyObjectArenaAllocator - - Structure used to describe an arena allocator. The structure has - three fields: - - +--------------------------------------------------+---------------------------------------+ - | Field | Meaning | - +==================================================+=======================================+ - | ``void *ctx`` | user context passed as first argument | - +--------------------------------------------------+---------------------------------------+ - | ``void* alloc(void *ctx, size_t size)`` | allocate an arena of size bytes | - +--------------------------------------------------+---------------------------------------+ - | ``void free(void *ctx, size_t size, void *ptr)`` | free an arena | - +--------------------------------------------------+---------------------------------------+ - -.. c:function:: PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator) - - Get the arena allocator. - -.. c:function:: PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator) - - Set the arena allocator. - - .. _memoryexamples: Examples @@ -338,7 +169,7 @@ if (buf == NULL) return PyErr_NoMemory(); /* ...Do some I/O operation involving buf... */ - res = PyBytes_FromString(buf); + res = PyString_FromString(buf); PyMem_Free(buf); /* allocated with PyMem_Malloc */ return res; @@ -350,7 +181,7 @@ if (buf == NULL) return PyErr_NoMemory(); /* ...Do some I/O operation involving buf... */ - res = PyBytes_FromString(buf); + res = PyString_FromString(buf); PyMem_Del(buf); /* allocated with PyMem_New */ return res; diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/module.rst --- a/Doc/c-api/module.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/module.rst Fri Feb 01 23:12:09 2013 +0100 @@ -35,20 +35,13 @@ single: __name__ (module attribute) single: __doc__ (module attribute) single: __file__ (module attribute) - single: __package__ (module attribute) - single: __loader__ (module attribute) Return a new module object with the :attr:`__name__` attribute set to *name*. - The module's :attr:`__name__`, :attr:`__doc__`, :attr:`__package__`, and - :attr:`__loader__` attributes are filled in (all but :attr:`__name__` are set - to ``None``); the caller is responsible for providing a :attr:`__file__` - attribute. + Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in; + the caller is responsible for providing a :attr:`__file__` attribute. .. versionadded:: 3.3 - .. versionchanged:: 3.4 - :attr:`__package__` and :attr:`__loader__` are set to ``None``. - .. c:function:: PyObject* PyModule_New(const char *name) @@ -129,7 +122,7 @@ :c:func:`PyState_AddModule` beforehand. In case the corresponding module object is not found or has not been attached to the interpreter state yet, it returns NULL. -.. c:function:: int PyState_AddModule(PyObject *module, PyModuleDef *def) +.. c:function:: int PyState_AddModule(PyModuleDef *def, PyObject *module) Attaches the module object passed to the function to the interpreter state. This allows the module object to be accessible via @@ -137,7 +130,7 @@ .. versionadded:: 3.3 -.. c:function:: int PyState_RemoveModule(PyModuleDef *def) +.. c:function:: int PyState_RemoveModule(PyModuleDef *def, PyObject *module) Removes the module object created from *def* from the interpreter state. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/object.rst --- a/Doc/c-api/object.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/object.rst Fri Feb 01 23:12:09 2013 +0100 @@ -240,7 +240,7 @@ of the Python expression ``callable_object(*args)``. -.. c:function:: PyObject* PyObject_CallFunction(PyObject *callable, const char *format, ...) +.. c:function:: PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...) Call a callable Python object *callable*, with a variable number of C arguments. The C arguments are described using a :c:func:`Py_BuildValue` style format @@ -250,11 +250,8 @@ pass :c:type:`PyObject \*` args, :c:func:`PyObject_CallFunctionObjArgs` is a faster alternative. - .. versionchanged:: 3.4 - The type of *format* was changed from ``char *``. - -.. c:function:: PyObject* PyObject_CallMethod(PyObject *o, const char *method, const char *format, ...) +.. c:function:: PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...) Call the method named *method* of object *o* with a variable number of C arguments. The C arguments are described by a :c:func:`Py_BuildValue` format @@ -264,9 +261,6 @@ Note that if you only pass :c:type:`PyObject \*` args, :c:func:`PyObject_CallMethodObjArgs` is a faster alternative. - .. versionchanged:: 3.4 - The types of *method* and *format* were changed from ``char *``. - .. c:function:: PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/stable.rst --- a/Doc/c-api/stable.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/stable.rst Fri Feb 01 23:12:09 2013 +0100 @@ -2,9 +2,9 @@ .. _stable: -*********************************** -Stable Application Binary Interface -*********************************** +********************************** +Stable Appliction Binary Interface +********************************** Traditionally, the C API of Python will change with every release. Most changes will be source-compatible, typically by only adding API, @@ -23,15 +23,13 @@ Since Python 3.2, a subset of the API has been declared to guarantee a stable ABI. Extension modules wishing to use this API need to define -``Py_LIMITED_API``. A number of interpreter details then become hidden +Py_LIMITED_API. A number of interpreter details then become hidden from the extension module; in return, a module is built that works -on any 3.x version (x>=2) without recompilation. - -In some cases, the stable ABI needs to be extended with new functions. -Extension modules wishing to use these new APIs need to set -``Py_LIMITED_API`` to the ``PY_VERSION_HEX`` value (see -:ref:`apiabiversion`) of the minimum Python version they want to -support (e.g. ``0x03030000`` for Python 3.3). Such modules will work +on any 3.x version (x>=2) without recompilation. In some cases, the +stable ABI needs to be extended with new functions. Extensions modules +wishing to use these new APIs need to set Py_LIMITED_API to the +PY_VERSION_HEX value of the minimum Python version they want to +support (e.g. 0x03030000 for Python 3.3). Such modules will work on all subsequent Python releases, but fail to load (because of missing symbols) on the older releases. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/unicode.rst Fri Feb 01 23:12:09 2013 +0100 @@ -439,8 +439,6 @@ .. % Similar comments apply to the %ll width modifier and .. % PY_FORMAT_LONG_LONG. - .. tabularcolumns:: |l|l|L| - +-------------------+---------------------+--------------------------------+ | Format Characters | Type | Comment | +===================+=====================+================================+ @@ -526,23 +524,12 @@ The `"%lld"` and `"%llu"` format specifiers are only available when :const:`HAVE_LONG_LONG` is defined. - .. note:: - The width formatter unit is number of characters rather than bytes. - The precision formatter unit is number of bytes for ``"%s"`` and - ``"%V"`` (if the ``PyObject*`` argument is NULL), and a number of - characters for ``"%A"``, ``"%U"``, ``"%S"``, ``"%R"`` and ``"%V"`` - (if the ``PyObject*`` argument is not NULL). - .. versionchanged:: 3.2 Support for ``"%lld"`` and ``"%llu"`` added. .. versionchanged:: 3.3 Support for ``"%li"``, ``"%lli"`` and ``"%zi"`` added. - .. versionchanged:: 3.4 - Support width and precision formatter for ``"%s"``, ``"%A"``, ``"%U"``, - ``"%V"``, ``"%S"``, ``"%R"`` added. - .. c:function:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/c-api/veryhigh.rst --- a/Doc/c-api/veryhigh.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/c-api/veryhigh.rst Fri Feb 01 23:12:09 2013 +0100 @@ -144,29 +144,6 @@ (:func:`sys.getfilesystemencoding`). Returns ``0`` at EOF. -.. c:var:: int (*PyOS_InputHook)(void) - - Can be set to point to a function with the prototype - ``int func(void)``. The function will be called when Python's - interpreter prompt is about to become idle and wait for user input - from the terminal. The return value is ignored. Overriding this - hook can be used to integrate the interpreter's prompt with other - event loops, as done in the :file:`Modules/_tkinter.c` in the - Python source code. - - -.. c:var:: char* (*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *) - - Can be set to point to a function with the prototype - ``char *func(FILE *stdin, FILE *stdout, char *prompt)``, - overriding the default function used to read a single line of input - at the interpreter's prompt. The function is expected to output - the string *prompt* if it's not *NULL*, and then read a line of - input from the provided standard input file, returning the - resulting string. For example, The :mod:`readline` module sets - this hook to provide line-editing and tab-completion features. - - .. c:function:: struct _node* PyParser_SimpleParseString(const char *str, int start) This is a simplified interface to @@ -361,3 +338,4 @@ This bit can be set in *flags* to cause division operator ``/`` to be interpreted as "true division" according to :pep:`238`. + diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/data/refcounts.dat --- a/Doc/data/refcounts.dat Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/data/refcounts.dat Fri Feb 01 23:12:09 2013 +0100 @@ -210,7 +210,7 @@ PyDict_DelItemString:int::: PyDict_DelItemString:PyObject*:p:0: -PyDict_DelItemString:const char*:key:: +PyDict_DelItemString:char*:key:: PyDict_GetItem:PyObject*::0:0 PyDict_GetItem:PyObject*:p:0: @@ -218,12 +218,7 @@ PyDict_GetItemString:PyObject*::0: PyDict_GetItemString:PyObject*:p:0: -PyDict_GetItemString:const char*:key:: - -PyDict_SetDefault:PyObject*::0: -PyDict_SetDefault:PyObject*:p:0: -PyDict_SetDefault:PyObject*:key:0:conditionally +1 if inserted into the dict -PyDict_SetDefault:PyObject*:default:0:conditionally +1 if inserted into the dict +PyDict_GetItemString:char*:key:: PyDict_Items:PyObject*::+1: PyDict_Items:PyObject*:p:0: @@ -249,7 +244,7 @@ PyDict_SetItemString:int::: PyDict_SetItemString:PyObject*:p:0: -PyDict_SetItemString:const char*:key:: +PyDict_SetItemString:char*:key:: PyDict_SetItemString:PyObject*:val:+1: PyDict_Size:int::: @@ -282,13 +277,13 @@ PyErr_GivenExceptionMatches:PyObject*:exc:0: PyErr_NewException:PyObject*::+1: -PyErr_NewException:const char*:name:: +PyErr_NewException:char*:name:: PyErr_NewException:PyObject*:base:0: PyErr_NewException:PyObject*:dict:0: PyErr_NewExceptionWithDoc:PyObject*::+1: -PyErr_NewExceptionWithDoc:const char*:name:: -PyErr_NewExceptionWithDoc:const char*:doc:: +PyErr_NewExceptionWithDoc:char*:name:: +PyErr_NewExceptionWithDoc:char*:doc:: PyErr_NewExceptionWithDoc:PyObject*:base:0: PyErr_NewExceptionWithDoc:PyObject*:dict:0: @@ -315,21 +310,21 @@ PyErr_SetExcFromWindowsErrWithFilename:PyObject*::null: PyErr_SetExcFromWindowsErrWithFilename:PyObject*:type:0: PyErr_SetExcFromWindowsErrWithFilename:int:ierr:: -PyErr_SetExcFromWindowsErrWithFilename:const char*:filename:: +PyErr_SetExcFromWindowsErrWithFilename:char*:filename:: PyErr_SetFromErrno:PyObject*::null: PyErr_SetFromErrno:PyObject*:type:0: PyErr_SetFromErrnoWithFilename:PyObject*::null: PyErr_SetFromErrnoWithFilename:PyObject*:type:0: -PyErr_SetFromErrnoWithFilename:const char*:filename:: +PyErr_SetFromErrnoWithFilename:char*:filename:: PyErr_SetFromWindowsErr:PyObject*::null: PyErr_SetFromWindowsErr:int:ierr:: PyErr_SetFromWindowsErrWithFilename:PyObject*::null: PyErr_SetFromWindowsErrWithFilename:int:ierr:: -PyErr_SetFromWindowsErrWithFilename:const char*:filename:: +PyErr_SetFromWindowsErrWithFilename:char*:filename:: PyErr_SetInterrupt:void::: @@ -342,11 +337,11 @@ PyErr_SetString:void::: PyErr_SetString:PyObject*:type:+1: -PyErr_SetString:const char*:message:: +PyErr_SetString:char*:message:: PyErr_Format:PyObject*::null: PyErr_Format:PyObject*:exception:+1: -PyErr_Format:const char*:format:: +PyErr_Format:char*:format:: PyErr_Format::...:: PyErr_WarnEx:int::: @@ -391,22 +386,22 @@ PyFile_FromFile:PyObject*::+1: PyFile_FromFile:FILE*:fp:: -PyFile_FromFile:const char*:name:: -PyFile_FromFile:const char*:mode:: +PyFile_FromFile:char*:name:: +PyFile_FromFile:char*:mode:: PyFile_FromFile:int(*:close):: PyFile_FromFileEx:PyObject*::+1: PyFile_FromFileEx:FILE*:fp:: -PyFile_FromFileEx:const char*:name:: -PyFile_FromFileEx:const char*:mode:: +PyFile_FromFileEx:char*:name:: +PyFile_FromFileEx:char*:mode:: PyFile_FromFileEx:int(*:close):: PyFile_FromFileEx:int:buffering:: -PyFile_FromFileEx:const char*:encoding:: -PyFile_FromFileEx:const char*:newline:: +PyFile_FromFileEx:char*:encoding:: +PyFile_FromFileEx:char*:newline:: PyFile_FromString:PyObject*::+1: -PyFile_FromString:const char*:name:: -PyFile_FromString:const char*:mode:: +PyFile_FromString:char*:name:: +PyFile_FromString:char*:mode:: PyFile_GetLine:PyObject*::+1: PyFile_GetLine:PyObject*:p:: @@ -487,23 +482,23 @@ PyGen_New:PyFrameObject*:frame:0: Py_InitModule:PyObject*::0: -Py_InitModule:const char*:name:: +Py_InitModule:char*:name:: Py_InitModule:PyMethodDef[]:methods:: Py_InitModule3:PyObject*::0: -Py_InitModule3:const char*:name:: +Py_InitModule3:char*:name:: Py_InitModule3:PyMethodDef[]:methods:: -Py_InitModule3:const char*:doc:: +Py_InitModule3:char*:doc:: Py_InitModule4:PyObject*::0: -Py_InitModule4:const char*:name:: +Py_InitModule4:char*:name:: Py_InitModule4:PyMethodDef[]:methods:: -Py_InitModule4:const char*:doc:: +Py_InitModule4:char*:doc:: Py_InitModule4:PyObject*:self:: Py_InitModule4:int:apiver::usually provided by Py_InitModule or Py_InitModule3 PyImport_AddModule:PyObject*::0:reference borrowed from sys.modules -PyImport_AddModule:const char*:name:: +PyImport_AddModule:char*:name:: PyImport_Cleanup:void::: @@ -527,16 +522,16 @@ PyImport_ImportFrozenModule:char*::: PyImport_ImportModule:PyObject*::+1: -PyImport_ImportModule:const char*:name:: +PyImport_ImportModule:char*:name:: PyImport_ImportModuleEx:PyObject*::+1: -PyImport_ImportModuleEx:const char*:name:: +PyImport_ImportModuleEx:char*:name:: PyImport_ImportModuleEx:PyObject*:globals:0:??? PyImport_ImportModuleEx:PyObject*:locals:0:??? PyImport_ImportModuleEx:PyObject*:fromlist:0:??? PyImport_ImportModuleLevel:PyObject*::+1: -PyImport_ImportModuleLevel:const char*:name:: +PyImport_ImportModuleLevel:char*:name:: PyImport_ImportModuleLevel:PyObject*:globals:0:??? PyImport_ImportModuleLevel:PyObject*:locals:0:??? PyImport_ImportModuleLevel:PyObject*:fromlist:0:??? @@ -697,7 +692,7 @@ PyMapping_DelItemString:int::: PyMapping_DelItemString:PyObject*:o:0: -PyMapping_DelItemString:const char*:key:: +PyMapping_DelItemString:char*:key:: PyMapping_GetItemString:PyObject*::+1: PyMapping_GetItemString:PyObject*:o:0: @@ -767,10 +762,10 @@ PyModule_GetDict:PyObject*::0: PyModule_GetDict::PyObject* module:0: -PyModule_GetFilename:const char*::: +PyModule_GetFilename:char*::: PyModule_GetFilename:PyObject*:module:0: -PyModule_GetName:const char*::: +PyModule_GetName:char*::: PyModule_GetName:PyObject*:module:0: PyModule_New:PyObject*::+1: @@ -917,7 +912,7 @@ PyObject_CallFunction:PyObject*::+1: PyObject_CallFunction:PyObject*:callable_object:0: -PyObject_CallFunction:const char*:format:: +PyObject_CallFunction:char*:format:: PyObject_CallFunction::...:: PyObject_CallFunctionObjArgs:PyObject*::+1: @@ -926,13 +921,13 @@ PyObject_CallMethod:PyObject*::+1: PyObject_CallMethod:PyObject*:o:0: -PyObject_CallMethod:const char*:m:: -PyObject_CallMethod:const char*:format:: +PyObject_CallMethod:char*:m:: +PyObject_CallMethod:char*:format:: PyObject_CallMethod::...:: PyObject_CallMethodObjArgs:PyObject*::+1: PyObject_CallMethodObjArgs:PyObject*:o:0: -PyObject_CallMethodObjArgs:PyObject*:name:0: +PyObject_CallMethodObjArgs:char*:name:: PyObject_CallMethodObjArgs::...:: PyObject_CallObject:PyObject*::+1: @@ -954,7 +949,7 @@ PyObject_DelAttrString:int::: PyObject_DelAttrString:PyObject*:o:0: -PyObject_DelAttrString:const char*:attr_name:: +PyObject_DelAttrString:char*:attr_name:: PyObject_DelItem:int::: PyObject_DelItem:PyObject*:o:0: @@ -969,7 +964,7 @@ PyObject_GetAttrString:PyObject*::+1: PyObject_GetAttrString:PyObject*:o:0: -PyObject_GetAttrString:const char*:attr_name:: +PyObject_GetAttrString:char*:attr_name:: PyObject_GetItem:PyObject*::+1: PyObject_GetItem:PyObject*:o:0: @@ -984,7 +979,7 @@ PyObject_HasAttrString:int::: PyObject_HasAttrString:PyObject*:o:0: -PyObject_HasAttrString:const char*:attr_name:0: +PyObject_HasAttrString:char*:attr_name:0: PyObject_Hash:int::: PyObject_Hash:PyObject*:o:0: @@ -1034,7 +1029,7 @@ PyObject_SetAttrString:int::: PyObject_SetAttrString:PyObject*:o:0: -PyObject_SetAttrString:const char*:attr_name:: +PyObject_SetAttrString:char*:attr_name:: PyObject_SetAttrString:PyObject*:v:+1: PyObject_SetItem:int::: @@ -1053,27 +1048,27 @@ PyParser_SimpleParseFile:struct _node*::: PyParser_SimpleParseFile:FILE*:fp:: -PyParser_SimpleParseFile:const char*:filename:: +PyParser_SimpleParseFile:char*:filename:: PyParser_SimpleParseFile:int:start:: PyParser_SimpleParseString:struct _node*::: -PyParser_SimpleParseString:const char*:str:: +PyParser_SimpleParseString:char*:str:: PyParser_SimpleParseString:int:start:: PyRun_AnyFile:int::: PyRun_AnyFile:FILE*:fp:: -PyRun_AnyFile:const char*:filename:: +PyRun_AnyFile:char*:filename:: PyRun_File:PyObject*::+1:??? -- same as eval_code2() PyRun_File:FILE*:fp:: -PyRun_File:const char*:filename:: +PyRun_File:char*:filename:: PyRun_File:int:start:: PyRun_File:PyObject*:globals:0: PyRun_File:PyObject*:locals:0: PyRun_FileEx:PyObject*::+1:??? -- same as eval_code2() PyRun_FileEx:FILE*:fp:: -PyRun_FileEx:const char*:filename:: +PyRun_FileEx:char*:filename:: PyRun_FileEx:int:start:: PyRun_FileEx:PyObject*:globals:0: PyRun_FileEx:PyObject*:locals:0: @@ -1081,7 +1076,7 @@ PyRun_FileFlags:PyObject*::+1:??? -- same as eval_code2() PyRun_FileFlags:FILE*:fp:: -PyRun_FileFlags:const char*:filename:: +PyRun_FileFlags:char*:filename:: PyRun_FileFlags:int:start:: PyRun_FileFlags:PyObject*:globals:0: PyRun_FileFlags:PyObject*:locals:0: @@ -1089,7 +1084,7 @@ PyRun_FileExFlags:PyObject*::+1:??? -- same as eval_code2() PyRun_FileExFlags:FILE*:fp:: -PyRun_FileExFlags:const char*:filename:: +PyRun_FileExFlags:char*:filename:: PyRun_FileExFlags:int:start:: PyRun_FileExFlags:PyObject*:globals:0: PyRun_FileExFlags:PyObject*:locals:0: @@ -1098,27 +1093,27 @@ PyRun_InteractiveLoop:int::: PyRun_InteractiveLoop:FILE*:fp:: -PyRun_InteractiveLoop:const char*:filename:: +PyRun_InteractiveLoop:char*:filename:: PyRun_InteractiveOne:int::: PyRun_InteractiveOne:FILE*:fp:: -PyRun_InteractiveOne:const char*:filename:: +PyRun_InteractiveOne:char*:filename:: PyRun_SimpleFile:int::: PyRun_SimpleFile:FILE*:fp:: -PyRun_SimpleFile:const char*:filename:: +PyRun_SimpleFile:char*:filename:: PyRun_SimpleString:int::: -PyRun_SimpleString:const char*:command:: +PyRun_SimpleString:char*:command:: PyRun_String:PyObject*::+1:??? -- same as eval_code2() -PyRun_String:const char*:str:: +PyRun_String:char*:str:: PyRun_String:int:start:: PyRun_String:PyObject*:globals:0: PyRun_String:PyObject*:locals:0: PyRun_StringFlags:PyObject*::+1:??? -- same as eval_code2() -PyRun_StringFlags:const char*:str:: +PyRun_StringFlags:char*:str:: PyRun_StringFlags:int:start:: PyRun_StringFlags:PyObject*:globals:0: PyRun_StringFlags:PyObject*:locals:0: @@ -1234,7 +1229,7 @@ PySlice_New:PyObject*:stop:0: PySlice_New:PyObject*:step:0: -PyString_AS_STRING:const char*::: +PyString_AS_STRING:char*::: PyString_AS_STRING:PyObject*:string:0: PyString_AsDecodedObject:PyObject*::+1: @@ -1247,7 +1242,7 @@ PyString_AsEncodedObject:const char*:encoding:: PyString_AsEncodedObject:const char*:errors:: -PyString_AsString:const char*::: +PyString_AsString:char*::: PyString_AsString:PyObject*:string:0: PyString_AsStringAndSize:int::: @@ -1315,13 +1310,13 @@ PyString_AsEncodedString:const char*:errors:: PySys_AddWarnOption:void::: -PySys_AddWarnOption:const char*:s:: +PySys_AddWarnOption:char*:s:: PySys_AddXOption:void::: PySys_AddXOption:const wchar_t*:s:: PySys_GetObject:PyObject*::0: -PySys_GetObject:const char*:name:: +PySys_GetObject:char*:name:: PySys_GetXOptions:PyObject*::0: @@ -1330,16 +1325,16 @@ PySys_SetArgv:char**:argv:: PySys_SetObject:int::: -PySys_SetObject:const char*:name:: +PySys_SetObject:char*:name:: PySys_SetObject:PyObject*:v:+1: PySys_ResetWarnOptions:void::: PySys_WriteStdout:void::: -PySys_WriteStdout:const char*:format:: +PySys_WriteStdout:char*:format:: PySys_WriteStderr:void::: -PySys_WriteStderr:const char*:format:: +PySys_WriteStderr:char*:format:: PyThreadState_Clear:void::: PyThreadState_Clear:PyThreadState*:tstate:: @@ -1719,16 +1714,16 @@ Py_AtExit:void (*)():func:: Py_BuildValue:PyObject*::+1: -Py_BuildValue:const char*:format:: +Py_BuildValue:char*:format:: Py_CompileString:PyObject*::+1: -Py_CompileString:const char*:str:: -Py_CompileString:const char*:filename:: +Py_CompileString:char*:str:: +Py_CompileString:char*:filename:: Py_CompileString:int:start:: Py_CompileStringFlags:PyObject*::+1: -Py_CompileStringFlags:const char*:str:: -Py_CompileStringFlags:const char*:filename:: +Py_CompileStringFlags:char*:str:: +Py_CompileStringFlags:char*:filename:: Py_CompileStringFlags:int:start:: Py_CompileStringFlags:PyCompilerFlags*:flags:: @@ -1742,33 +1737,33 @@ Py_Exit:int:status:: Py_FatalError:void::: -Py_FatalError:const char*:message:: +Py_FatalError:char*:message:: Py_FdIsInteractive:int::: Py_FdIsInteractive:FILE*:fp:: -Py_FdIsInteractive:const char*:filename:: +Py_FdIsInteractive:char*:filename:: Py_Finalize:void::: -Py_GetBuildInfoconst:const char*::: +Py_GetBuildInfoconst:char*::: -Py_GetCompilerconst:const char*::: +Py_GetCompilerconst:char*::: -Py_GetCopyrightconst:const char*::: +Py_GetCopyrightconst:char*::: -Py_GetExecPrefix:const char*::: +Py_GetExecPrefix:char*::: -Py_GetPath:const char*::: +Py_GetPath:char*::: -Py_GetPlatformconst:const char*::: +Py_GetPlatformconst:char*::: -Py_GetPrefix:const char*::: +Py_GetPrefix:char*::: -Py_GetProgramFullPath:const char*::: +Py_GetProgramFullPath:char*::: -Py_GetProgramName:const char*::: +Py_GetProgramName:char*::: -Py_GetVersionconst:const char*::: +Py_GetVersionconst:char*::: Py_INCREF:void::: Py_INCREF:PyObject*:o:+1: @@ -1780,7 +1775,7 @@ Py_NewInterpreter:PyThreadState*::: Py_SetProgramName:void::: -Py_SetProgramName:const char*:name:: +Py_SetProgramName:char*:name:: Py_XDECREF:void::: Py_XDECREF:PyObject*:o:-1:if o is not NULL @@ -1789,14 +1784,14 @@ Py_XINCREF:PyObject*:o:+1:if o is not NULL _PyImport_FindExtension:PyObject*::0:??? see PyImport_AddModule -_PyImport_FindExtension:const char*::: -_PyImport_FindExtension:const char*::: +_PyImport_FindExtension:char*::: +_PyImport_FindExtension:char*::: _PyImport_Fini:void::: _PyImport_FixupExtension:PyObject*:::??? -_PyImport_FixupExtension:const char*::: -_PyImport_FixupExtension:const char*::: +_PyImport_FixupExtension:char*::: +_PyImport_FixupExtension:char*::: _PyImport_Init:void::: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/distutils/apiref.rst Fri Feb 01 23:12:09 2013 +0100 @@ -26,8 +26,6 @@ The setup function takes a large number of arguments. These are laid out in the following table. - .. tabularcolumns:: |l|L|L| - +--------------------+--------------------------------+-------------------------------------------------------------+ | argument name | value | type | +====================+================================+=============================================================+ @@ -50,10 +48,7 @@ +--------------------+--------------------------------+-------------------------------------------------------------+ | *maintainer* | The name of the current | a string | | | maintainer, if different from | | - | | the author. Note that if | | - | | the maintainer is provided, | | - | | distutils will use it as the | | - | | author in :file:`PKG-INFO` | | + | | the author | | +--------------------+--------------------------------+-------------------------------------------------------------+ | *maintainer_email* | The email address of the | a string | | | current maintainer, if | | @@ -127,8 +122,6 @@ *stop_after* tells :func:`setup` when to stop processing; possible values: - .. tabularcolumns:: |l|L| - +---------------+---------------------------------------------+ | value | description | +===============+=============================================+ @@ -169,8 +162,6 @@ 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| - +------------------------+--------------------------------+---------------------------+ | argument name | value | type | +========================+================================+===========================+ @@ -1568,8 +1559,6 @@ The options are all boolean, and affect the values returned by :meth:`readline` - .. tabularcolumns:: |l|L|l| - +------------------+--------------------------------+---------+ | option name | description | default | +==================+================================+=========+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/distutils/index.rst --- a/Doc/distutils/index.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/distutils/index.rst Fri Feb 01 23:12:09 2013 +0100 @@ -22,6 +22,7 @@ sourcedist.rst builtdist.rst packageindex.rst + uploading.rst examples.rst extending.rst commandref.rst diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/distutils/packageindex.rst --- a/Doc/distutils/packageindex.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/distutils/packageindex.rst Fri Feb 01 23:12:09 2013 +0100 @@ -1,33 +1,12 @@ -.. index:: - single: Python Package Index (PyPI) - single: PyPI; (see Python Package Index (PyPI)) - .. _package-index: -******************************* -The Python Package Index (PyPI) -******************************* +********************************** +Registering with the Package Index +********************************** -The `Python Package Index (PyPI)`_ holds :ref:`meta-data ` -describing distributions packaged with distutils, as well as package data like -distribution files if the package author wishes. - -Distutils exposes two commands for submitting package data to PyPI: the -:ref:`register ` command for submitting meta-data to PyPI -and the :ref:`upload ` command for submitting distribution -files. Both commands read configuration data from a special file called the -:ref:`.pypirc file `. PyPI :ref:`displays a home page -` for each package created from the ``long_description`` -submitted by the :command:`register` command. - - -.. _package-register: - -Registering Packages -==================== - -The distutils command :command:`register` is used to submit your distribution's -meta-data to the index. It is invoked as follows:: +The Python Package Index (PyPI) holds meta-data describing distributions +packaged with distutils. The distutils command :command:`register` is used to +submit your distribution's meta-data to the index. It is invoked as follows:: python setup.py register @@ -69,52 +48,6 @@ versions to display and hide. -.. _package-upload: - -Uploading Packages -================== - -The distutils command :command:`upload` pushes the distribution files to PyPI. - -The command is invoked immediately after building one or more distribution -files. For example, the command :: - - python setup.py sdist bdist_wininst upload - -will cause the source distribution and the Windows installer to be uploaded to -PyPI. Note that these will be uploaded even if they are built using an earlier -invocation of :file:`setup.py`, but that only distributions named on the command -line for the invocation including the :command:`upload` command are uploaded. - -The :command:`upload` command uses the username, password, and repository URL -from the :file:`$HOME/.pypirc` file (see section :ref:`pypirc` for more on this -file). If a :command:`register` command was previously called in the same command, -and if the password was entered in the prompt, :command:`upload` will reuse the -entered password. This is useful if you do not want to store a clear text -password in the :file:`$HOME/.pypirc` file. - -You can specify another PyPI server with the ``--repository=url`` option:: - - python setup.py sdist bdist_wininst upload -r http://example.com/pypi - -See section :ref:`pypirc` for more on defining several servers. - -You can use the ``--sign`` option to tell :command:`upload` to sign each -uploaded file using GPG (GNU Privacy Guard). The :program:`gpg` program must -be available for execution on the system :envvar:`PATH`. You can also specify -which key to use for signing using the ``--identity=name`` option. - -Other :command:`upload` options include ``--repository=url`` or -``--repository=section`` where *url* is the url of the server and -*section* the name of the section in :file:`$HOME/.pypirc`, and -``--show-response`` (which displays the full response text from the PyPI -server for help in debugging upload problems). - - -.. index:: - single: .pypirc file - single: Python Package Index (PyPI); .pypirc file - .. _pypirc: The .pypirc file @@ -169,45 +102,3 @@ may also be used:: python setup.py register -r other - - -.. _package-display: - -PyPI package display -==================== - -The ``long_description`` field plays a special role at PyPI. It is used by -the server to display a home page for the registered package. - -If you use the `reStructuredText `_ -syntax for this field, PyPI will parse it and display an HTML output for -the package home page. - -The ``long_description`` field can be attached to a text file located -in the package:: - - from distutils.core import setup - - with open('README.txt') as file: - long_description = file.read() - - setup(name='Distutils', - long_description=long_description) - -In that case, :file:`README.txt` is a regular reStructuredText text file located -in the root of the package besides :file:`setup.py`. - -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:: - - $ python setup.py --long-description | rst2html.py > output.html - -:mod:`docutils` will display a warning if there's something wrong with your -syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw`` -to ``rst2html.py`` in the command above), being able to run the command above -without warnings does not guarantee that PyPI will convert the content -successfully. - - -.. _Python Package Index (PyPI): http://pypi.python.org/ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/distutils/setupscript.rst --- a/Doc/distutils/setupscript.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/distutils/setupscript.rst Fri Feb 01 23:12:09 2013 +0100 @@ -601,8 +601,7 @@ It is recommended that versions take the form *major.minor[.patch[.sub]]*. (3) - Either the author or the maintainer must be identified. If maintainer is - provided, distutils lists it as the author in :file:`PKG-INFO`. + Either the author or the maintainer must be identified. (4) These fields should not be used if your package is to be compatible with Python @@ -610,9 +609,8 @@ `_. (5) - The ``long_description`` field is used by PyPI when you are - :ref:`registering ` a package, to - :ref:`build its home page `. + The ``long_description`` field is used by PyPI when you are registering a + package, to build its home page. (6) The ``license`` field is a text indicating the license covering the diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/distutils/uploading.rst --- a/Doc/distutils/uploading.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/distutils/uploading.rst Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,80 @@ -:orphan: +.. _package-upload: *************************************** Uploading Packages to the Package Index *************************************** -The contents of this page have moved to the section :ref:`package-index`. +The Python Package Index (PyPI) not only stores the package info, but also the +package data if the author of the package wishes to. The distutils command +:command:`upload` pushes the distribution files to PyPI. + +The command is invoked immediately after building one or more distribution +files. For example, the command :: + + python setup.py sdist bdist_wininst upload + +will cause the source distribution and the Windows installer to be uploaded to +PyPI. Note that these will be uploaded even if they are built using an earlier +invocation of :file:`setup.py`, but that only distributions named on the command +line for the invocation including the :command:`upload` command are uploaded. + +The :command:`upload` command uses the username, password, and repository URL +from the :file:`$HOME/.pypirc` file (see section :ref:`pypirc` for more on this +file). If a :command:`register` command was previously called in the same command, +and if the password was entered in the prompt, :command:`upload` will reuse the +entered password. This is useful if you do not want to store a clear text +password in the :file:`$HOME/.pypirc` file. + +You can specify another PyPI server with the ``--repository=url`` option:: + + python setup.py sdist bdist_wininst upload -r http://example.com/pypi + +See section :ref:`pypirc` for more on defining several servers. + +You can use the ``--sign`` option to tell :command:`upload` to sign each +uploaded file using GPG (GNU Privacy Guard). The :program:`gpg` program must +be available for execution on the system :envvar:`PATH`. You can also specify +which key to use for signing using the ``--identity=name`` option. + +Other :command:`upload` options include ``--repository=url`` or +``--repository=section`` where *url* is the url of the server and +*section* the name of the section in :file:`$HOME/.pypirc`, and +``--show-response`` (which displays the full response text from the PyPI +server for help in debugging upload problems). + +PyPI package display +==================== + +The ``long_description`` field plays a special role at PyPI. It is used by +the server to display a home page for the registered package. + +If you use the `reStructuredText `_ +syntax for this field, PyPI will parse it and display an HTML output for +the package home page. + +The ``long_description`` field can be attached to a text file located +in the package:: + + from distutils.core import setup + + with open('README.txt') as file: + long_description = file.read() + + setup(name='Distutils', + long_description=long_description) + +In that case, :file:`README.txt` is a regular reStructuredText text file located +in the root of the package besides :file:`setup.py`. + +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:: + + $ python setup.py --long-description | rst2html.py > output.html + +:mod:`docutils` will display a warning if there's something wrong with your +syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw`` +to ``rst2html.py`` in the command above), being able to run the command above +without warnings does not guarantee that PyPI will convert the content +successfully. + diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/extending/embedding.rst --- a/Doc/extending/embedding.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/extending/embedding.rst Fri Feb 01 23:12:09 2013 +0100 @@ -138,9 +138,7 @@ in ``argv[2]``. Its integer arguments are the other values of the ``argv`` array. If you :ref:`compile and link ` this program (let's call the finished executable :program:`call`), and use it to execute a Python -script, such as: - -.. code-block:: python +script, such as:: def multiply(a,b): print("Will compute", a, "times", b) @@ -240,9 +238,7 @@ These two lines initialize the ``numargs`` variable, and make the :func:`emb.numargs` function accessible to the embedded Python interpreter. -With these extensions, the Python script can do things like - -.. code-block:: python +With these extensions, the Python script can do things like :: import emb print("Number of arguments", emb.numargs()) @@ -285,14 +281,14 @@ * ``pythonX.Y-config --cflags`` will give you the recommended flags when compiling:: - $ /opt/bin/python3.4-config --cflags - -I/opt/include/python3.4m -I/opt/include/python3.4m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes + $ /opt/bin/python3.2-config --cflags + -I/opt/include/python3.2m -I/opt/include/python3.2m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes * ``pythonX.Y-config --ldflags`` will give you the recommended flags when linking:: - $ /opt/bin/python3.4-config --ldflags - -L/opt/lib/python3.4/config-3.4m -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic + $ /opt/bin/python3.2-config --ldflags + -I/opt/lib/python3.2/config-3.2m -lpthread -ldl -lutil -lm -lpython3.2m -Xlinker -export-dynamic .. note:: To avoid confusion between several Python installations (and especially @@ -307,13 +303,9 @@ to find its location) and compilation options. In this case, the :mod:`sysconfig` module is a useful tool to programmatically extract the configuration values that you will want to -combine together. For example: - -.. code-block:: python +combine together:: >>> import sysconfig - >>> sysconfig.get_config_var('LIBS') - '-lpthread -ldl -lutil' >>> sysconfig.get_config_var('LINKFORSHARED') '-Xlinker -export-dynamic' diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/extending/newtypes.rst --- a/Doc/extending/newtypes.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/extending/newtypes.rst Fri Feb 01 23:12:09 2013 +0100 @@ -288,13 +288,13 @@ self = (Noddy *)type->tp_alloc(type, 0); if (self != NULL) { - self->first = PyUnicode_FromString(""); + self->first = PyString_FromString(""); if (self->first == NULL) { Py_DECREF(self); return NULL; } - self->last = PyUnicode_FromString(""); + self->last = PyString_FromString(""); if (self->last == NULL) { Py_DECREF(self); return NULL; @@ -540,9 +540,9 @@ return -1; } - if (! PyUnicode_Check(value)) { + if (! PyString_Check(value)) { PyErr_SetString(PyExc_TypeError, - "The first attribute value must be a str"); + "The first attribute value must be a string"); return -1; } @@ -1005,8 +1005,8 @@ static PyObject * newdatatype_repr(newdatatypeobject * obj) { - return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:\%d}}", - obj->obj_UnderlyingDatatypePtr->size); + return PyString_FromFormat("Repr-ified_newdatatype{{size:\%d}}", + obj->obj_UnderlyingDatatypePtr->size); } If no :attr:`tp_repr` handler is specified, the interpreter will supply a @@ -1025,8 +1025,8 @@ static PyObject * newdatatype_str(newdatatypeobject * obj) { - return PyUnicode_FromFormat("Stringified_newdatatype{{size:\%d}}", - obj->obj_UnderlyingDatatypePtr->size); + return PyString_FromFormat("Stringified_newdatatype{{size:\%d}}", + obj->obj_UnderlyingDatatypePtr->size); } @@ -1233,7 +1233,7 @@ Here is a sample implementation, for a datatype that is considered equal if the size of an internal pointer is equal:: - static PyObject * + static int newdatatype_richcmp(PyObject *obj1, PyObject *obj2, int op) { PyObject *result; @@ -1342,10 +1342,11 @@ if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) { return NULL; } - result = PyUnicode_FromFormat( + result = PyString_FromFormat( "Returning -- value: [\%d] arg1: [\%s] arg2: [\%s] arg3: [\%s]\n", obj->obj_UnderlyingDatatypePtr->size, arg1, arg2, arg3); + printf("\%s", PyString_AS_STRING(result)); return result; } diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/design.rst --- a/Doc/faq/design.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/design.rst Fri Feb 01 23:12:09 2013 +0100 @@ -862,8 +862,8 @@ When you have a literal value for a list, tuple, or dictionary spread across multiple lines, it's easier to add more elements because you don't have to -remember to add a comma to the previous line. The lines can also be reordered -without creating a syntax error. +remember to add a comma to the previous line. The lines can also be sorted in +your editor without creating a syntax error. Accidentally omitting the comma can lead to errors that are hard to diagnose. For example:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/extending.rst --- a/Doc/faq/extending.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/extending.rst Fri Feb 01 23:12:09 2013 +0100 @@ -2,9 +2,7 @@ Extending/Embedding FAQ ======================= -.. only:: html - - .. contents:: +.. contents:: .. highlight:: c @@ -84,20 +82,18 @@ index. Lists have similar functions, :c:func:`PyListSize` and :c:func:`PyList_GetItem`. -For bytes, :c:func:`PyBytes_Size` returns its length and -:c:func:`PyBytes_AsStringAndSize` provides a pointer to its value and its -length. Note that Python bytes objects may contain null bytes so C's -:c:func:`strlen` should not be used. +For strings, :c:func:`PyString_Size` returns its length and +:c:func:`PyString_AsString` a pointer to its value. Note that Python strings may +contain null bytes so C's :c:func:`strlen` should not be used. To test the type of an object, first make sure it isn't *NULL*, and then use -:c:func:`PyBytes_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc. +:c:func:`PyString_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc. There is also a high-level API to Python objects which is provided by the so-called 'abstract' interface -- read ``Include/abstract.h`` for further details. It allows interfacing with any kind of Python sequence using calls -like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well -as many other useful protocols such as numbers (:c:func:`PyNumber_Index` et. -al.) and mappings in the PyMapping APIs. +like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well as +many other useful protocols. How do I use Py_BuildValue() to create a tuple of arbitrary length? diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/general.rst --- a/Doc/faq/general.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/general.rst Fri Feb 01 23:12:09 2013 +0100 @@ -4,10 +4,7 @@ General Python FAQ ================== -.. only:: html - - .. contents:: - +.. contents:: General Information =================== diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/gui.rst --- a/Doc/faq/gui.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/gui.rst Fri Feb 01 23:12:09 2013 +0100 @@ -4,9 +4,7 @@ Graphic User Interface FAQ ========================== -.. only:: html - - .. contents:: +.. contents:: .. XXX need review for Python 3. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/library.rst --- a/Doc/faq/library.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/library.rst Fri Feb 01 23:12:09 2013 +0100 @@ -4,9 +4,7 @@ Library and Extension FAQ ========================= -.. only:: html - - .. contents:: +.. contents:: General Library Questions ========================= diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/programming.rst --- a/Doc/faq/programming.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/programming.rst Fri Feb 01 23:12:09 2013 +0100 @@ -4,9 +4,7 @@ Programming FAQ =============== -.. only:: html - - .. contents:: +.. contents:: General Questions ================= @@ -214,9 +212,9 @@ Assume you use a for loop to define a few different lambdas (or even plain functions), e.g.:: - >>> squares = [] - >>> for x in range(5): - ... squares.append(lambda: x**2) + squares = [] + for x in range(5): + squares.append(lambda: x**2) This gives you a list that contains 5 lambdas that calculate ``x**2``. You might expect that, when called, they would return, respectively, ``0``, ``1``, @@ -241,9 +239,9 @@ In order to avoid this, you need to save the values in variables local to the lambdas, so that they don't rely on the value of the global ``x``:: - >>> squares = [] - >>> for x in range(5): - ... squares.append(lambda n=x: n**2) + squares = [] + for x in range(5): + squares.append(lambda n=x: n**2) Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed when the lambda is defined so that it has the same value that ``x`` had at @@ -592,11 +590,11 @@ Since the comma is not an operator, but a separator between expressions the above is evaluated as if you had entered:: - ("a" in "b"), "a" + >>> ("a" in "b"), "a" not:: - "a" in ("b", "a") + >>> "a" in ("b", "a") The same is true of the various assignment operators (``=``, ``+=`` etc). They are not truly operators but syntactic delimiters in assignment statements. @@ -744,7 +742,6 @@ unicode data, try using a :class:`io.StringIO` object or the :mod:`array` module:: - >>> import io >>> s = "Hello, world" >>> sio = io.StringIO(s) >>> sio.getvalue() @@ -762,7 +759,7 @@ array('u', 'Hello, world') >>> a[0] = 'y' >>> print(a) - array('u', 'yello, world') + array('u', 'yello world') >>> a.tounicode() 'yello, world' @@ -1061,7 +1058,7 @@ You probably tried to make a multidimensional array like this:: - >>> A = [[None] * 2] * 3 + A = [[None] * 2] * 3 This looks correct if you print it:: @@ -1093,7 +1090,7 @@ A = [[None] * w for i in range(h)] Or, you can use an extension that provides a matrix datatype; `Numeric Python -`_ is the best known. +`_ is the best known. How do I apply a method to a sequence of objects? @@ -1104,92 +1101,6 @@ result = [obj.method() for obj in mylist] -Why does a_tuple[i] += ['item'] raise an exception when the addition works? ---------------------------------------------------------------------------- - -This is because of a combination of the fact that augmented assignment -operators are *assignment* operators, and the difference between mutable and -immutable objects in Python. - -This discussion applies in general when augmented assignment operators are -applied to elements of a tuple that point to mutable objects, but we'll use -a ``list`` and ``+=`` as our exemplar. - -If you wrote:: - - >>> a_tuple = (1, 2) - >>> a_tuple[0] += 1 - Traceback (most recent call last): - ... - TypeError: 'tuple' object does not support item assignment - -The reason for the exception should be immediately clear: ``1`` is added to the -object ``a_tuple[0]`` points to (``1``), producing the result object, ``2``, -but when we attempt to assign the result of the computation, ``2``, to element -``0`` of the tuple, we get an error because we can't change what an element of -a tuple points to. - -Under the covers, what this augmented assignment statement is doing is -approximately this:: - - >>> result = a_tuple[0] + 1 - >>> a_tuple[0] = result - Traceback (most recent call last): - ... - TypeError: 'tuple' object does not support item assignment - -It is the assignment part of the operation that produces the error, since a -tuple is immutable. - -When you write something like:: - - >>> a_tuple = (['foo'], 'bar') - >>> a_tuple[0] += ['item'] - Traceback (most recent call last): - ... - TypeError: 'tuple' object does not support item assignment - -The exception is a bit more surprising, and even more surprising is the fact -that even though there was an error, the append worked:: - - >>> a_tuple[0] - ['foo', 'item'] - -To see why this happens, you need to know that (a) if an object implements an -``__iadd__`` magic method, it gets called when the ``+=`` augmented assignment -is executed, and its return value is what gets used in the assignment statement; -and (b) for lists, ``__iadd__`` is equivalent to calling ``extend`` on the list -and returning the list. That's why we say that for lists, ``+=`` is a -"shorthand" for ``list.extend``:: - - >>> a_list = [] - >>> a_list += [1] - >>> a_list - [1] - -This is equivalent to:: - - >>> result = a_list.__iadd__([1]) - >>> a_list = result - -The object pointed to by a_list has been mutated, and the pointer to the -mutated object is assigned back to ``a_list``. The end result of the -assignment is a no-op, since it is a pointer to the same object that ``a_list`` -was previously pointing to, but the assignment still happens. - -Thus, in our tuple example what is happening is equivalent to:: - - >>> result = a_tuple[0].__iadd__(['item']) - >>> a_tuple[0] = result - Traceback (most recent call last): - ... - TypeError: 'tuple' object does not support item assignment - -The ``__iadd__`` succeeds, and thus the list is extended, but even though -``result`` points to the same object that ``a_tuple[0]`` already points to, -that final assignment still results in an error, because tuples are immutable. - - Dictionaries ============ @@ -1616,13 +1527,13 @@ (permissions, free space, etc...) to write the compiled module back to the directory. -Running Python on a top level script is not considered an import and no -``.pyc`` will be created. For example, if you have a top-level module -``foo.py`` that imports another module ``xyz.py``, when you run ``foo``, -``xyz.pyc`` will be created since ``xyz`` is imported, but no ``foo.pyc`` file -will be created since ``foo.py`` isn't being imported. +Running Python on a top level script is not considered an import and no ``.pyc`` +will be created. For example, if you have a top-level module ``abc.py`` that +imports another module ``xyz.py``, when you run abc, ``xyz.pyc`` will be created +since xyz is imported, but no ``abc.pyc`` file will be created since ``abc.py`` +isn't being imported. -If you need to create ``foo.pyc`` -- that is, to create a ``.pyc`` file for a module +If you need to create abc.pyc -- that is, to create a .pyc file for a module that is not imported -- you can, using the :mod:`py_compile` and :mod:`compileall` modules. @@ -1630,9 +1541,9 @@ the ``compile()`` function in that module interactively:: >>> import py_compile - >>> py_compile.compile('foo.py') # doctest: +SKIP + >>> py_compile.compile('abc.py') -This will write the ``.pyc`` to the same location as ``foo.py`` (or you can +This will write the ``.pyc`` to the same location as ``abc.py`` (or you can override that with the optional parameter ``cfile``). You can also automatically compile all files in a directory or directories using @@ -1739,12 +1650,12 @@ For reasons of efficiency as well as consistency, Python only reads the module file on the first time a module is imported. If it didn't, in a program consisting of many modules where each one imports the same basic module, the -basic module would be parsed and re-parsed many times. To force re-reading of a +basic module would be parsed and re-parsed many times. To force rereading of a changed module, do this:: - import importlib + import imp import modname - importlib.reload(modname) + imp.reload(modname) Warning: this technique is not 100% fool-proof. In particular, modules containing statements like :: @@ -1756,10 +1667,10 @@ updated to use the new class definition. This can result in the following paradoxical behaviour: - >>> import importlib + >>> import imp >>> import cls >>> c = cls.C() # Create an instance of C - >>> importlib.reload(cls) + >>> imp.reload(cls) >>> isinstance(c, cls.C) # isinstance is false?!? False diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/faq/windows.rst --- a/Doc/faq/windows.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/faq/windows.rst Fri Feb 01 23:12:09 2013 +0100 @@ -6,9 +6,7 @@ Python on Windows FAQ ===================== -.. only:: html - - .. contents:: +.. contents:: .. XXX need review for Python 3. XXX need review for Windows Vista/Seven? diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/glossary.rst --- a/Doc/glossary.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/glossary.rst Fri Feb 01 23:12:09 2013 +0100 @@ -78,14 +78,6 @@ Benevolent Dictator For Life, a.k.a. `Guido van Rossum `_, Python's creator. - bytes-like object - An object that supports the :ref:`bufferobjects`, like :class:`bytes`, - :class:`bytearray` or :class:`memoryview`. Bytes-like objects can - be used for various operations that expect binary data, such as - compression, saving to a binary file or sending over a socket. - Some operations need the binary data to be mutable, in which case - not all bytes-like objects can apply. - bytecode Python source code is compiled into bytecode, the internal representation of a Python program in the CPython interpreter. The bytecode is also @@ -252,16 +244,6 @@ the execution of the body. See also :term:`parameter`, :term:`method`, and the :ref:`function` section. - function annotation - An arbitrary metadata value associated with a function parameter or return - value. Its syntax is explained in section :ref:`function`. Annotations - may be accessed via the :attr:`__annotations__` special attribute of a - function object. - - Python itself does not assign any particular meaning to function - annotations. They are intended to be interpreted by third-party libraries - or tools. See :pep:`3107`, which describes some of their potential uses. - __future__ A pseudo-module which programmers can use to enable new language features which are not compatible with the current interpreter. @@ -302,15 +284,6 @@ >>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81 285 - generic function - A function composed of multiple functions implementing the same operation - for different types. Which implementation should be used during a call is - determined by the dispatch algorithm. - - See also the :term:`single dispatch` glossary entry, the - :func:`functools.singledispatch` decorator, and :pep:`443`. - - GIL See :term:`global interpreter lock`. @@ -347,8 +320,7 @@ All of Python's immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Objects which are instances of user-defined classes are hashable by default; they all - compare unequal (except with themselves), and their hash value is their - :func:`id`. + compare unequal, and their hash value is their :func:`id`. IDLE An Integrated Development Environment for Python. IDLE is a basic editor @@ -754,10 +726,6 @@ mapping rather than a sequence because the lookups use arbitrary :term:`immutable` keys rather than integers. - single dispatch - A form of :term:`generic function` dispatch where the implementation is - chosen based on the type of a single argument. - slice An object usually containing a portion of a :term:`sequence`. A slice is created using the subscript notation, ``[]`` with colons between numbers diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/advocacy.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Doc/howto/advocacy.rst Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,355 @@ +************************* + Python Advocacy HOWTO +************************* + +:Author: A.M. Kuchling +:Release: 0.03 + + +.. topic:: Abstract + + It's usually difficult to get your management to accept open source software, + and Python is no exception to this rule. This document discusses reasons to use + Python, strategies for winning acceptance, facts and arguments you can use, and + cases where you *shouldn't* try to use Python. + + +Reasons to Use Python +===================== + +There are several reasons to incorporate a scripting language into your +development process, and this section will discuss them, and why Python has some +properties that make it a particularly good choice. + + +Programmability +--------------- + +Programs are often organized in a modular fashion. Lower-level operations are +grouped together, and called by higher-level functions, which may in turn be +used as basic operations by still further upper levels. + +For example, the lowest level might define a very low-level set of functions for +accessing a hash table. The next level might use hash tables to store the +headers of a mail message, mapping a header name like ``Date`` to a value such +as ``Tue, 13 May 1997 20:00:54 -0400``. A yet higher level may operate on +message objects, without knowing or caring that message headers are stored in a +hash table, and so forth. + +Often, the lowest levels do very simple things; they implement a data structure +such as a binary tree or hash table, or they perform some simple computation, +such as converting a date string to a number. The higher levels then contain +logic connecting these primitive operations. Using the approach, the primitives +can be seen as basic building blocks which are then glued together to produce +the complete product. + +Why is this design approach relevant to Python? Because Python is well suited +to functioning as such a glue language. A common approach is to write a Python +module that implements the lower level operations; for the sake of speed, the +implementation might be in C, Java, or even Fortran. Once the primitives are +available to Python programs, the logic underlying higher level operations is +written in the form of Python code. The high-level logic is then more +understandable, and easier to modify. + +John Ousterhout wrote a paper that explains this idea at greater length, +entitled "Scripting: Higher Level Programming for the 21st Century". I +recommend that you read this paper; see the references for the URL. Ousterhout +is the inventor of the Tcl language, and therefore argues that Tcl should be +used for this purpose; he only briefly refers to other languages such as Python, +Perl, and Lisp/Scheme, but in reality, Ousterhout's argument applies to +scripting languages in general, since you could equally write extensions for any +of the languages mentioned above. + + +Prototyping +----------- + +In *The Mythical Man-Month*, Fredrick Brooks suggests the following rule when +planning software projects: "Plan to throw one away; you will anyway." Brooks +is saying that the first attempt at a software design often turns out to be +wrong; unless the problem is very simple or you're an extremely good designer, +you'll find that new requirements and features become apparent once development +has actually started. If these new requirements can't be cleanly incorporated +into the program's structure, you're presented with two unpleasant choices: +hammer the new features into the program somehow, or scrap everything and write +a new version of the program, taking the new features into account from the +beginning. + +Python provides you with a good environment for quickly developing an initial +prototype. That lets you get the overall program structure and logic right, and +you can fine-tune small details in the fast development cycle that Python +provides. Once you're satisfied with the GUI interface or program output, you +can translate the Python code into C++, Fortran, Java, or some other compiled +language. + +Prototyping means you have to be careful not to use too many Python features +that are hard to implement in your other language. Using ``eval()``, or regular +expressions, or the :mod:`pickle` module, means that you're going to need C or +Java libraries for formula evaluation, regular expressions, and serialization, +for example. But it's not hard to avoid such tricky code, and in the end the +translation usually isn't very difficult. The resulting code can be rapidly +debugged, because any serious logical errors will have been removed from the +prototype, leaving only more minor slip-ups in the translation to track down. + +This strategy builds on the earlier discussion of programmability. Using Python +as glue to connect lower-level components has obvious relevance for constructing +prototype systems. In this way Python can help you with development, even if +end users never come in contact with Python code at all. If the performance of +the Python version is adequate and corporate politics allow it, you may not need +to do a translation into C or Java, but it can still be faster to develop a +prototype and then translate it, instead of attempting to produce the final +version immediately. + +One example of this development strategy is Microsoft Merchant Server. Version +1.0 was written in pure Python, by a company that subsequently was purchased by +Microsoft. Version 2.0 began to translate the code into C++, shipping with some +C++code and some Python code. Version 3.0 didn't contain any Python at all; all +the code had been translated into C++. Even though the product doesn't contain +a Python interpreter, the Python language has still served a useful purpose by +speeding up development. + +This is a very common use for Python. Past conference papers have also +described this approach for developing high-level numerical algorithms; see +David M. Beazley and Peter S. Lomdahl's paper "Feeding a Large-scale Physics +Application to Python" in the references for a good example. If an algorithm's +basic operations are things like "Take the inverse of this 4000x4000 matrix", +and are implemented in some lower-level language, then Python has almost no +additional performance cost; the extra time required for Python to evaluate an +expression like ``m.invert()`` is dwarfed by the cost of the actual computation. +It's particularly good for applications where seemingly endless tweaking is +required to get things right. GUI interfaces and Web sites are prime examples. + +The Python code is also shorter and faster to write (once you're familiar with +Python), so it's easier to throw it away if you decide your approach was wrong; +if you'd spent two weeks working on it instead of just two hours, you might +waste time trying to patch up what you've got out of a natural reluctance to +admit that those two weeks were wasted. Truthfully, those two weeks haven't +been wasted, since you've learnt something about the problem and the technology +you're using to solve it, but it's human nature to view this as a failure of +some sort. + + +Simplicity and Ease of Understanding +------------------------------------ + +Python is definitely *not* a toy language that's only usable for small tasks. +The language features are general and powerful enough to enable it to be used +for many different purposes. It's useful at the small end, for 10- or 20-line +scripts, but it also scales up to larger systems that contain thousands of lines +of code. + +However, this expressiveness doesn't come at the cost of an obscure or tricky +syntax. While Python has some dark corners that can lead to obscure code, there +are relatively few such corners, and proper design can isolate their use to only +a few classes or modules. It's certainly possible to write confusing code by +using too many features with too little concern for clarity, but most Python +code can look a lot like a slightly-formalized version of human-understandable +pseudocode. + +In *The New Hacker's Dictionary*, Eric S. Raymond gives the following definition +for "compact": + +.. epigraph:: + + Compact *adj.* Of a design, describes the valuable property that it can all be + apprehended at once in one's head. This generally means the thing created from + the design can be used with greater facility and fewer errors than an equivalent + tool that is not compact. Compactness does not imply triviality or lack of + power; for example, C is compact and FORTRAN is not, but C is more powerful than + FORTRAN. Designs become non-compact through accreting features and cruft that + don't merge cleanly into the overall design scheme (thus, some fans of Classic C + maintain that ANSI C is no longer compact). + + (From http://www.catb.org/~esr/jargon/html/C/compact.html) + +In this sense of the word, Python is quite compact, because the language has +just a few ideas, which are used in lots of places. Take namespaces, for +example. Import a module with ``import math``, and you create a new namespace +called ``math``. Classes are also namespaces that share many of the properties +of modules, and have a few of their own; for example, you can create instances +of a class. Instances? They're yet another namespace. Namespaces are currently +implemented as Python dictionaries, so they have the same methods as the +standard dictionary data type: .keys() returns all the keys, and so forth. + +This simplicity arises from Python's development history. The language syntax +derives from different sources; ABC, a relatively obscure teaching language, is +one primary influence, and Modula-3 is another. (For more information about ABC +and Modula-3, consult their respective Web sites at http://www.cwi.nl/~steven/abc/ +and http://www.m3.org.) Other features have come from C, Icon, +Algol-68, and even Perl. Python hasn't really innovated very much, but instead +has tried to keep the language small and easy to learn, building on ideas that +have been tried in other languages and found useful. + +Simplicity is a virtue that should not be underestimated. It lets you learn the +language more quickly, and then rapidly write code -- code that often works the +first time you run it. + + +Java Integration +---------------- + +If you're working with Java, Jython (http://www.jython.org/) is definitely worth +your attention. Jython is a re-implementation of Python in Java that compiles +Python code into Java bytecodes. The resulting environment has very tight, +almost seamless, integration with Java. It's trivial to access Java classes +from Python, and you can write Python classes that subclass Java classes. +Jython can be used for prototyping Java applications in much the same way +CPython is used, and it can also be used for test suites for Java code, or +embedded in a Java application to add scripting capabilities. + + +Arguments and Rebuttals +======================= + +Let's say that you've decided upon Python as the best choice for your +application. How can you convince your management, or your fellow developers, +to use Python? This section lists some common arguments against using Python, +and provides some possible rebuttals. + +**Python is freely available software that doesn't cost anything. How good can +it be?** + +Very good, indeed. These days Linux and Apache, two other pieces of open source +software, are becoming more respected as alternatives to commercial software, +but Python hasn't had all the publicity. + +Python has been around for several years, with many users and developers. +Accordingly, the interpreter has been used by many people, and has gotten most +of the bugs shaken out of it. While bugs are still discovered at intervals, +they're usually either quite obscure (they'd have to be, for no one to have run +into them before) or they involve interfaces to external libraries. The +internals of the language itself are quite stable. + +Having the source code should be viewed as making the software available for +peer review; people can examine the code, suggest (and implement) improvements, +and track down bugs. To find out more about the idea of open source code, along +with arguments and case studies supporting it, go to http://www.opensource.org. + +**Who's going to support it?** + +Python has a sizable community of developers, and the number is still growing. +The Internet community surrounding the language is an active one, and is worth +being considered another one of Python's advantages. Most questions posted to +the comp.lang.python newsgroup are quickly answered by someone. + +Should you need to dig into the source code, you'll find it's clear and +well-organized, so it's not very difficult to write extensions and track down +bugs yourself. If you'd prefer to pay for support, there are companies and +individuals who offer commercial support for Python. + +**Who uses Python for serious work?** + +Lots of people; one interesting thing about Python is the surprising diversity +of applications that it's been used for. People are using Python to: + +* Run Web sites + +* Write GUI interfaces + +* Control number-crunching code on supercomputers + +* Make a commercial application scriptable by embedding the Python interpreter + inside it + +* Process large XML data sets + +* Build test suites for C or Java code + +Whatever your application domain is, there's probably someone who's used Python +for something similar. Yet, despite being useable for such high-end +applications, Python's still simple enough to use for little jobs. + +See http://wiki.python.org/moin/OrganizationsUsingPython for a list of some of +the organizations that use Python. + +**What are the restrictions on Python's use?** + +They're practically nonexistent. Consult :ref:`history-and-license` for the full +language, but it boils down to three conditions: + +* You have to leave the copyright notice on the software; if you don't include + the source code in a product, you have to put the copyright notice in the + supporting documentation. + +* Don't claim that the institutions that have developed Python endorse your + product in any way. + +* If something goes wrong, you can't sue for damages. Practically all software + licenses contain this condition. + +Notice that you don't have to provide source code for anything that contains +Python or is built with it. Also, the Python interpreter and accompanying +documentation can be modified and redistributed in any way you like, and you +don't have to pay anyone any licensing fees at all. + +**Why should we use an obscure language like Python instead of well-known +language X?** + +I hope this HOWTO, and the documents listed in the final section, will help +convince you that Python isn't obscure, and has a healthily growing user base. +One word of advice: always present Python's positive advantages, instead of +concentrating on language X's failings. People want to know why a solution is +good, rather than why all the other solutions are bad. So instead of attacking +a competing solution on various grounds, simply show how Python's virtues can +help. + + +Useful Resources +================ + +http://www.pythonology.com/success + The Python Success Stories are a collection of stories from successful users of + Python, with the emphasis on business and corporate users. + +.. http://www.fsbassociates.com/books/pythonchpt1.htm + The first chapter of \emph{Internet Programming with Python} also + examines some of the reasons for using Python. The book is well worth + buying, but the publishers have made the first chapter available on + the Web. + +http://www.tcl.tk/doc/scripting.html + John Ousterhout's white paper on scripting is a good argument for the utility of + scripting languages, though naturally enough, he emphasizes Tcl, the language he + developed. Most of the arguments would apply to any scripting language. + +http://www.python.org/workshops/1997-10/proceedings/beazley.html + The authors, David M. Beazley and Peter S. Lomdahl, describe their use of + Python at Los Alamos National Laboratory. It's another good example of how + Python can help get real work done. This quotation from the paper has been + echoed by many people: + + .. epigraph:: + + Originally developed as a large monolithic application for massively parallel + processing systems, we have used Python to transform our application into a + flexible, highly modular, and extremely powerful system for performing + simulation, data analysis, and visualization. In addition, we describe how + Python has solved a number of important problems related to the development, + debugging, deployment, and maintenance of scientific software. + +http://pythonjournal.cognizor.com/pyj1/Everitt-Feit_interview98-V1.html + This interview with Andy Feit, discussing Infoseek's use of Python, can be used + to show that choosing Python didn't introduce any difficulties into a company's + development process, and provided some substantial benefits. + +.. http://www.python.org/psa/Commercial.html + Robin Friedrich wrote this document on how to support Python's use in + commercial projects. + +http://www.python.org/workshops/1997-10/proceedings/stein.ps + For the 6th Python conference, Greg Stein presented a paper that traced Python's + adoption and usage at a startup called eShop, and later at Microsoft. + +http://www.opensource.org + Management may be doubtful of the reliability and usefulness of software that + wasn't written commercially. This site presents arguments that show how open + source software can have considerable advantages over closed-source software. + +http://www.faqs.org/docs/Linux-mini/Advocacy.html + The Linux Advocacy mini-HOWTO was the inspiration for this document, and is also + well worth reading for general suggestions on winning acceptance for a new + technology, such as Linux or Python. In general, you won't make much progress + by simply attacking existing systems and complaining about their inadequacies; + this often ends up looking like unfocused whining. It's much better to point + out some of the many areas where Python is an improvement over other systems. + diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/argparse.rst --- a/Doc/howto/argparse.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/argparse.rst Fri Feb 01 23:12:09 2013 +0100 @@ -11,7 +11,7 @@ .. note:: - There are two other modules that fulfill the same task, namely + There's two other modules that fulfill the same task, namely :mod:`getopt` (an equivalent for :c:func:`getopt` from the C language) and the deprecated :mod:`optparse`. Note also that :mod:`argparse` is based on :mod:`optparse`, @@ -468,7 +468,7 @@ print(answer) We have introduced another action, "count", -to count the number of occurrences of a specific optional arguments: +to count the number of occurences of a specific optional arguments: .. code-block:: sh @@ -668,8 +668,8 @@ So far, we have been working with two methods of an :class:`argparse.ArgumentParser` instance. Let's introduce a third one, :meth:`add_mutually_exclusive_group`. It allows for us to specify options that -conflict with each other. Let's also change the rest of the program so that -the new functionality makes more sense: +conflict with each other. Let's also change the rest of the program make the +new functionality makes more sense: we'll introduce the ``--quiet`` option, which will be the opposite of the ``--verbose`` one:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/cporting.rst Fri Feb 01 23:12:09 2013 +0100 @@ -100,6 +100,25 @@ used in Python 2 was removed. In the C-API, ``PyInt_*`` functions are replaced by their ``PyLong_*`` equivalents. +The best course of action here is using the ``PyInt_*`` functions aliased to +``PyLong_*`` found in :file:`intobject.h`. The abstract ``PyNumber_*`` APIs +can also be used in some cases. :: + + #include "Python.h" + #include "intobject.h" + + static PyObject * + add_ints(PyObject *self, PyObject *args) { + int one, two; + PyObject *result; + + if (!PyArg_ParseTuple(args, "ii:add_ints", &one, &two)) + return NULL; + + return PyInt_FromLong(one + two); + } + + Module initialization and state =============================== diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/curses.rst --- a/Doc/howto/curses.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/curses.rst Fri Feb 01 23:12:09 2013 +0100 @@ -5,43 +5,39 @@ ********************************** :Author: A.M. Kuchling, Eric S. Raymond -:Release: 2.04 +:Release: 2.03 .. topic:: Abstract - This document describes how to use the :mod:`curses` extension - module to control text-mode displays. + This document describes how to write text-mode programs with Python 2.x, using + the :mod:`curses` extension module to control the display. What is curses? =============== The curses library supplies a terminal-independent screen-painting and -keyboard-handling facility for text-based terminals; such terminals -include VT100s, the Linux console, and the simulated terminal provided -by various programs. Display terminals support various control codes -to perform common operations such as moving the cursor, scrolling the -screen, and erasing areas. Different terminals use widely differing -codes, and often have their own minor quirks. +keyboard-handling facility for text-based terminals; such terminals include +VT100s, the Linux console, and the simulated terminal provided by X11 programs +such as xterm and rxvt. Display terminals support various control codes to +perform common operations such as moving the cursor, scrolling the screen, and +erasing areas. Different terminals use widely differing codes, and often have +their own minor quirks. -In a world of graphical displays, one might ask "why bother"? It's -true that character-cell display terminals are an obsolete technology, -but there are niches in which being able to do fancy things with them -are still valuable. One niche is on small-footprint or embedded -Unixes that don't run an X server. Another is tools such as OS -installers and kernel configurators that may have to run before any -graphical support is available. +In a world of X displays, one might ask "why bother"? It's true that +character-cell display terminals are an obsolete technology, but there are +niches in which being able to do fancy things with them are still valuable. One +is on small-footprint or embedded Unixes that don't carry an X server. Another +is for tools like OS installers and kernel configurators that may have to run +before X is available. -The curses library provides fairly basic functionality, providing the -programmer with an abstraction of a display containing multiple -non-overlapping windows of text. The contents of a window can be -changed in various ways---adding text, erasing it, changing its -appearance---and the curses library will figure out what control codes -need to be sent to the terminal to produce the right output. curses -doesn't provide many user-interface concepts such as buttons, checkboxes, -or dialogs; if you need such features, consider a user interface library such as -`Urwid `_. +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 +will automagically figure out what control codes need to be sent to the terminal +to produce the right output. The curses library was originally written for BSD Unix; the later System V versions of Unix from AT&T added many enhancements and new functions. BSD curses @@ -53,13 +49,10 @@ versions of curses carried by some proprietary Unixes may not support everything, though. -The Windows version of Python doesn't include the :mod:`curses` -module. A ported version called `UniCurses -`_ is available. You could -also try `the Console module `_ -written by Fredrik Lundh, which doesn't -use the same API as curses but provides cursor-addressable text output -and full support for mouse and keyboard input. +No one has made a Windows port of the curses module. On a Windows platform, try +the Console module written by Fredrik Lundh. The Console module provides +cursor-addressable text output, plus full support for mouse and keyboard input, +and is available from http://effbot.org/zone/console-index.htm. The Python curses module @@ -68,12 +61,11 @@ Thy Python module is a fairly simple wrapper over the C functions provided by curses; if you're already familiar with curses programming in C, it's really easy to transfer that knowledge to Python. The biggest difference is that the -Python interface makes things simpler by merging different C functions such as -:c:func:`addstr`, :c:func:`mvaddstr`, and :c:func:`mvwaddstr` into a single -:meth:`~curses.window.addstr` method. You'll see this covered in more -detail later. +Python interface makes things simpler, by merging different C functions such as +:func:`addstr`, :func:`mvaddstr`, :func:`mvwaddstr`, into a single +:meth:`addstr` method. You'll see this covered in more detail later. -This HOWTO is an introduction to writing text-mode programs with curses +This HOWTO is simply an introduction to writing text-mode programs with curses and Python. It doesn't attempt to be a complete guide to the curses API; for that, see the Python library guide's section on ncurses, and the C manual pages for ncurses. It will, however, give you the basic ideas. @@ -82,27 +74,25 @@ Starting and ending a curses application ======================================== -Before doing anything, curses must be initialized. This is done by -calling the :func:`~curses.initscr` function, which will determine the -terminal type, send any required setup codes to the terminal, and -create various internal data structures. If successful, -:func:`initscr` returns a window object representing the entire -screen; this is usually called ``stdscr`` after the name of the +Before doing anything, curses must be initialized. This is done by calling the +:func:`initscr` function, which will determine the terminal type, send any +required setup codes to the terminal, and create various internal data +structures. If successful, :func:`initscr` returns a window object representing +the entire screen; this is usually called ``stdscr``, after the name of the corresponding C variable. :: import curses stdscr = curses.initscr() -Usually curses applications turn off automatic echoing of keys to the -screen, in order to be able to read keys and only display them under -certain circumstances. This requires calling the -:func:`~curses.noecho` function. :: +Usually curses applications turn off automatic echoing of keys to the screen, in +order to be able to read keys and only display them under certain circumstances. +This requires calling the :func:`noecho` function. :: curses.noecho() -Applications will also commonly need to react to keys instantly, -without requiring the Enter key to be pressed; this is called cbreak -mode, as opposed to the usual buffered input mode. :: +Applications will also commonly need to react to keys instantly, without +requiring the Enter key to be pressed; this is called cbreak mode, as opposed to +the usual buffered input mode. :: curses.cbreak() @@ -113,14 +103,12 @@ :const:`curses.KEY_LEFT`. To get curses to do the job, you'll have to enable keypad mode. :: - stdscr.keypad(True) + stdscr.keypad(1) Terminating a curses application is much easier than starting one. You'll need -to call:: +to call :: - curses.nocbreak() - stdscr.keypad(False) - curses.echo() + curses.nocbreak(); stdscr.keypad(0); curses.echo() to reverse the curses-friendly terminal settings. Then call the :func:`endwin` function to restore the terminal to its original operating mode. :: @@ -134,147 +122,102 @@ you type them, for example, which makes using the shell difficult. In Python you can avoid these complications and make debugging much easier by -importing the :func:`curses.wrapper` function and using it like this:: - - from curses import wrapper - - def main(stdscr): - # Clear screen - stdscr.clear() - - # This raises ZeroDivisionError when i == 10. - for i in range(0, 10): - v = i-10 - stdscr.addstr(i, 0, '10 divided by {} is {}'.format(v, 10/v)) - - stdscr.refresh() - stdscr.getkey() - - wrapper(main) - -The :func:`wrapper` function takes a callable object and does the -initializations described above, also initializing colors if color -support is present. :func:`wrapper` then runs your provided callable. -Once the callable returns, :func:`wrapper` will restore the original -state of the terminal. The callable is called inside a -:keyword:`try`...\ :keyword:`except` that catches exceptions, restores -the state of the terminal, and then re-raises the exception. Therefore -your terminal won't be left in a funny state on exception and you'll be -able to read the exception's message and traceback. +importing the module :mod:`curses.wrapper`. It supplies a :func:`wrapper` +function that takes a callable. It does the initializations described above, +and also initializes colors if color support is present. It then runs your +provided callable and finally deinitializes appropriately. The callable is +called inside a try-catch clause which catches exceptions, performs curses +deinitialization, and then passes the exception upwards. Thus, your terminal +won't be left in a funny state on exception. Windows and Pads ================ Windows are the basic abstraction in curses. A window object represents a -rectangular area of the screen, and supports methods to display text, +rectangular area of the screen, and supports various methods to display text, erase it, allow the user to input strings, and so forth. -The ``stdscr`` object returned by the :func:`initscr` function is a -window object that covers the entire screen. Many programs may need -only this single window, but you might wish to divide the screen into -smaller windows, in order to redraw or clear them separately. The -:func:`~curses.newwin` function creates a new window of a given size, -returning the new window object. :: +The ``stdscr`` object returned by the :func:`initscr` function is a window +object that covers the entire screen. Many programs may need only this single +window, but you might wish to divide the screen into smaller windows, in order +to redraw or clear them separately. The :func:`newwin` function creates a new +window of a given size, returning the new window object. :: begin_x = 20 ; begin_y = 7 height = 5 ; width = 40 win = curses.newwin(height, width, begin_y, begin_x) -Note that the coordinate system used in curses is unusual. -Coordinates are always passed in the order *y,x*, and the top-left -corner of a window is coordinate (0,0). This breaks the normal -convention for handling coordinates where the *x* coordinate comes -first. This is an unfortunate difference from most other computer -applications, but it's been part of curses since it was first written, -and it's too late to change things now. +A word about the coordinate system used in curses: coordinates are always passed +in the order *y,x*, and the top-left corner of a window is coordinate (0,0). +This breaks a common convention for handling coordinates, where the *x* +coordinate usually comes first. This is an unfortunate difference from most +other computer applications, but it's been part of curses since it was first +written, and it's too late to change things now. -Your application can determine the size of the screen by using the -:data:`curses.LINES` and :data:`curses.COLS` variables to obtain the *y* and -*x* sizes. Legal coordinates will then extend from ``(0,0)`` to -``(curses.LINES - 1, curses.COLS - 1)``. +When you call a method to display or erase text, the effect doesn't immediately +show up on the display. This is because curses was originally written with slow +300-baud terminal connections in mind; with these terminals, minimizing the time +required to redraw the screen is very important. This lets curses accumulate +changes to the screen, and display them in the most efficient manner. For +example, if your program displays some characters in a window, and then clears +the window, there's no need to send the original characters because they'd never +be visible. -When you call a method to display or erase text, the effect doesn't -immediately show up on the display. Instead you must call the -:meth:`~curses.window.refresh` method of window objects to update the -screen. - -This is because curses was originally written with slow 300-baud -terminal connections in mind; with these terminals, minimizing the -time required to redraw the screen was very important. Instead curses -accumulates changes to the screen and displays them in the most -efficient manner when you call :meth:`refresh`. For example, if your -program displays some text in a window and then clears the window, -there's no need to send the original text because they're never -visible. - -In practice, explicitly telling curses to redraw a window doesn't +Accordingly, curses requires that you explicitly tell it to redraw windows, +using the :func:`refresh` method of window objects. In practice, this doesn't really complicate programming with curses much. Most programs go into a flurry of activity, and then pause waiting for a keypress or some other action on the part of the user. All you have to do is to be sure that the screen has been -redrawn before pausing to wait for user input, by first calling -``stdscr.refresh()`` or the :meth:`refresh` method of some other relevant +redrawn before pausing to wait for user input, by simply calling +``stdscr.refresh()`` or the :func:`refresh` method of some other relevant window. A pad is a special case of a window; it can be larger than the actual display -screen, and only a portion of the pad displayed at a time. Creating a pad +screen, and only a portion of it displayed at a time. Creating a pad simply requires the pad's height and width, while refreshing a pad requires giving the coordinates of the on-screen area where a subsection of the pad will be -displayed. :: +displayed. :: pad = curses.newpad(100, 100) - # These loops fill the pad with letters; addch() is + # These loops fill the pad with letters; this is # explained in the next section - for y in range(0, 99): - for x in range(0, 99): - pad.addch(y,x, ord('a') + (x*x+y*y) % 26 ) + for y in range(0, 100): + for x in range(0, 100): + try: pad.addch(y,x, ord('a') + (x*x+y*y) % 26 ) + except curses.error: pass - # Displays a section of the pad in the middle of the screen. - # (0,0) : coordinate of upper-left corner of pad area to display. - # (5,5) : coordinate of upper-left corner of window area to be filled - # with pad content. - # (20, 75) : coordinate of lower-right corner of window area to be - # : filled with pad content. + # Displays a section of the pad in the middle of the screen pad.refresh( 0,0, 5,5, 20,75) -The :meth:`refresh` call displays a section of the pad in the rectangle +The :func:`refresh` call displays a section of the pad in the rectangle extending from coordinate (5,5) to coordinate (20,75) on the screen; the upper left corner of the displayed section is coordinate (0,0) on the pad. Beyond that difference, pads are exactly like ordinary windows and support the same methods. -If you have multiple windows and pads on screen there is a more -efficient way to update the screen and prevent annoying screen flicker -as each part of the screen gets updated. :meth:`refresh` actually -does two things: - -1) Calls the :meth:`~curses.window.noutrefresh` method of each window - to update an underlying data structure representing the desired - state of the screen. -2) Calls the function :func:`~curses.doupdate` function to change the - physical screen to match the desired state recorded in the data structure. - -Instead you can call :meth:`noutrefresh` on a number of windows to -update the data structure, and then call :func:`doupdate` to update -the screen. +If you have multiple windows and pads on screen there is a more efficient way to +go, which will prevent annoying screen flicker at refresh time. Use the +:meth:`noutrefresh` method of each window to update the data structure +representing the desired state of the screen; then change the physical screen to +match the desired state in one go with the function :func:`doupdate`. The +normal :meth:`refresh` method calls :func:`doupdate` as its last act. Displaying Text =============== -From a C programmer's point of view, curses may sometimes look like a -twisty maze of functions, all subtly different. For example, -:c:func:`addstr` displays a string at the current cursor location in -the ``stdscr`` window, while :c:func:`mvaddstr` moves to a given y,x -coordinate first before displaying the string. :c:func:`waddstr` is just -like :func:`addstr`, but allows specifying a window to use instead of -using ``stdscr`` by default. :c:func:`mvwaddstr` allows specifying both -a window and a coordinate. +From a C programmer's point of view, curses may sometimes look like a twisty +maze of functions, all subtly different. For example, :func:`addstr` displays a +string at the current cursor location in the ``stdscr`` window, while +:func:`mvaddstr` moves to a given y,x coordinate first before displaying the +string. :func:`waddstr` is just like :func:`addstr`, but allows specifying a +window to use, instead of using ``stdscr`` by default. :func:`mvwaddstr` follows +similarly. -Fortunately the Python interface hides all these details. ``stdscr`` -is a window object like any other, and methods such as :meth:`addstr` -accept multiple argument forms. Usually there are four different -forms. +Fortunately the Python interface hides all these details; ``stdscr`` is a window +object like any other, and methods like :func:`addstr` accept multiple argument +forms. Usually there are four different forms. +---------------------------------+-----------------------------------------------+ | Form | Description | @@ -293,26 +236,17 @@ | | display *str* or *ch*, using attribute *attr* | +---------------------------------+-----------------------------------------------+ -Attributes allow displaying text in highlighted forms such as boldface, +Attributes allow displaying text in highlighted forms, such as in boldface, underline, reverse code, or in color. They'll be explained in more detail in the next subsection. - -The :meth:`~curses.window.addstr` method takes a Python string or -bytestring as the value to be displayed. The contents of bytestrings -are sent to the terminal as-is. Strings are encoded to bytes using -the value of the window's :attr:`encoding` attribute; this defaults to -the default system encoding as returned by -:func:`locale.getpreferredencoding`. - -The :meth:`~curses.window.addch` methods take a character, which can be -either a string of length 1, a bytestring of length 1, or an integer. - -Constants are provided for extension characters; these constants are -integers greater than 255. For example, :const:`ACS_PLMINUS` is a +/- -symbol, and :const:`ACS_ULCORNER` is the upper left corner of a box -(handy for drawing borders). You can also use the appropriate Unicode -character. +The :func:`addstr` function takes a Python string as the value to be displayed, +while the :func:`addch` functions take a character, which can be either a Python +string of length 1 or an integer. If it's a string, you're limited to +displaying characters between 0 and 255. SVr4 curses provides constants for +extension characters; these constants are integers greater than 255. For +example, :const:`ACS_PLMINUS` is a +/- symbol, and :const:`ACS_ULCORNER` is the +upper left corner of a box (handy for drawing borders). Windows remember where the cursor was left after the last operation, so if you leave out the *y,x* coordinates, the string or character will be displayed @@ -322,11 +256,10 @@ won't be distracting; it can be confusing to have the cursor blinking at some apparently random location. -If your application doesn't need a blinking cursor at all, you can -call ``curs_set(False)`` to make it invisible. For compatibility -with older curses versions, there's a ``leaveok(bool)`` function -that's a synonym for :func:`curs_set`. When *bool* is true, the -curses library will attempt to suppress the flashing cursor, and you +If your application doesn't need a blinking cursor at all, you can call +``curs_set(0)`` to make it invisible. Equivalently, and for compatibility with +older curses versions, there's a ``leaveok(bool)`` function. When *bool* is +true, the curses library will attempt to suppress the flashing cursor, and you won't need to worry about leaving it in odd locations. @@ -334,16 +267,15 @@ -------------------- Characters can be displayed in different ways. Status lines in a text-based -application are commonly shown in reverse video, or a text viewer may need to +application are commonly shown in reverse video; a text viewer may need to highlight certain words. curses supports this by allowing you to specify an attribute for each cell on the screen. -An attribute is an integer, each bit representing a different -attribute. You can try to display text with multiple attribute bits -set, but curses doesn't guarantee that all the possible combinations -are available, or that they're all visually distinct. That depends on -the ability of the terminal being used, so it's safest to stick to the -most commonly available attributes, listed here. +An attribute is an integer, each bit representing a different attribute. You can +try to display text with multiple attribute bits set, but curses doesn't +guarantee that all the possible combinations are available, or that they're all +visually distinct. That depends on the ability of the terminal being used, so +it's safest to stick to the most commonly available attributes, listed here. +----------------------+--------------------------------------+ | Attribute | Description | @@ -374,7 +306,7 @@ To use color, you must call the :func:`start_color` function soon after calling :func:`initscr`, to initialize the default color set (the -:func:`curses.wrapper` function does this automatically). Once that's +:func:`curses.wrapper.wrapper` function does this automatically). Once that's done, the :func:`has_colors` function returns TRUE if the terminal in use can actually display color. (Note: curses uses the American spelling 'color', instead of the Canadian/British spelling 'colour'. If you're used to the @@ -393,16 +325,15 @@ stdscr.refresh() As I said before, a color pair consists of a foreground and background color. +:func:`start_color` initializes 8 basic colors when it activates color mode. +They are: 0:black, 1:red, 2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and +7:white. The curses module defines named constants for each of these colors: +:const:`curses.COLOR_BLACK`, :const:`curses.COLOR_RED`, and so forth. + The ``init_pair(n, f, b)`` function changes the definition of color pair *n*, to foreground color f and background color b. Color pair 0 is hard-wired to white on black, and cannot be changed. -Colors are numbered, and :func:`start_color` initializes 8 basic -colors when it activates color mode. They are: 0:black, 1:red, -2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and 7:white. The :mod:`curses` -module defines named constants for each of these colors: -:const:`curses.COLOR_BLACK`, :const:`curses.COLOR_RED`, and so forth. - Let's put all this together. To change color 1 to red text on a white background, you would call:: @@ -419,130 +350,87 @@ blue or any other color you like. Unfortunately, the Linux console doesn't support this, so I'm unable to try it out, and can't provide any examples. You can check if your terminal can do this by calling :func:`can_change_color`, -which returns True if the capability is there. If you're lucky enough to have +which returns TRUE if the capability is there. If you're lucky enough to have such a talented terminal, consult your system's man pages for more information. User Input ========== -The C curses library offers only very simple input mechanisms. Python's -:mod:`curses` module adds a basic text-input widget. (Other libraries -such as `Urwid `_ have more extensive -collections of widgets.) +The curses library itself offers only very simple input mechanisms. Python's +support adds a text-input widget that makes up some of the lack. -There are two methods for getting input from a window: +The most common way to get input to a window is to use its :meth:`getch` method. +:meth:`getch` pauses and waits for the user to hit a key, displaying it if +:func:`echo` has been called earlier. You can optionally specify a coordinate +to which the cursor should be moved before pausing. -* :meth:`~curses.window.getch` refreshes the screen and then waits for - the user to hit a key, displaying the key if :func:`echo` has been - called earlier. You can optionally specify a coordinate to which - the cursor should be moved before pausing. - -* :meth:`~curses.window.getkey` does the same thing but converts the - integer to a string. Individual characters are returned as - 1-character strings, and special keys such as function keys return - longer strings containing a key name such as ``KEY_UP`` or ``^G``. - -It's possible to not wait for the user using the -:meth:`~curses.window.nodelay` window method. After ``nodelay(True)``, -:meth:`getch` and :meth:`getkey` for the window become -non-blocking. To signal that no input is ready, :meth:`getch` returns -``curses.ERR`` (a value of -1) and :meth:`getkey` raises an exception. -There's also a :func:`~curses.halfdelay` function, which can be used to (in -effect) set a timer on each :meth:`getch`; if no input becomes -available within a specified delay (measured in tenths of a second), -curses raises an exception. +It's possible to change this behavior with the method :meth:`nodelay`. After +``nodelay(1)``, :meth:`getch` for the window becomes non-blocking and returns +``curses.ERR`` (a value of -1) when no input is ready. There's also a +:func:`halfdelay` function, which can be used to (in effect) set a timer on each +:meth:`getch`; if no input becomes available within a specified +delay (measured in tenths of a second), curses raises an exception. The :meth:`getch` method returns an integer; if it's between 0 and 255, it represents the ASCII code of the key pressed. Values greater than 255 are special keys such as Page Up, Home, or the cursor keys. You can compare the value returned to constants such as :const:`curses.KEY_PPAGE`, -:const:`curses.KEY_HOME`, or :const:`curses.KEY_LEFT`. The main loop of -your program may look something like this:: +:const:`curses.KEY_HOME`, or :const:`curses.KEY_LEFT`. Usually the main loop of +your program will look something like this:: while True: c = stdscr.getch() - if c == ord('p'): - PrintDocument() - elif c == ord('q'): - break # Exit the while loop - elif c == curses.KEY_HOME: - x = y = 0 + if c == ord('p'): PrintDocument() + elif c == ord('q'): break # Exit the while() + elif c == curses.KEY_HOME: x = y = 0 The :mod:`curses.ascii` module supplies ASCII class membership functions that -take either integer or 1-character string arguments; these may be useful in -writing more readable tests for such loops. It also supplies +take either integer or 1-character-string arguments; these may be useful in +writing more readable tests for your command interpreters. It also supplies conversion functions that take either integer or 1-character-string arguments and return the same type. For example, :func:`curses.ascii.ctrl` returns the control character corresponding to its argument. -There's also a method to retrieve an entire string, -:meth:`~curses.window.getstr`. It isn't used very often, because its -functionality is quite limited; the only editing keys available are -the backspace key and the Enter key, which terminates the string. It -can optionally be limited to a fixed number of characters. :: +There's also a method to retrieve an entire string, :const:`getstr()`. It isn't +used very often, because its functionality is quite limited; the only editing +keys available are the backspace key and the Enter key, which terminates the +string. It can optionally be limited to a fixed number of characters. :: curses.echo() # Enable echoing of characters # Get a 15-character string, with the cursor on the top line s = stdscr.getstr(0,0, 15) -The :mod:`curses.textpad` module supplies a text box that supports an -Emacs-like set of keybindings. Various methods of the -:class:`~curses.textpad.Textbox` class support editing with input -validation and gathering the edit results either with or without -trailing spaces. Here's an example:: - - import curses - from curses.textpad import Textbox, rectangle - - def main(stdscr): - stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)") - - editwin = curses.newwin(5,30, 2,1) - rectangle(stdscr, 1,0, 1+5+1, 1+30+1) - stdscr.refresh() - - box = Textbox(editwin) - - # Let the user edit until Ctrl-G is struck. - box.edit() - - # Get resulting contents - message = box.gather() - -See the library documentation on :mod:`curses.textpad` for more details. +The Python :mod:`curses.textpad` module supplies something better. With it, you +can turn a window into a text box that supports an Emacs-like set of +keybindings. Various methods of :class:`Textbox` class support editing with +input validation and gathering the edit results either with or without trailing +spaces. See the library documentation on :mod:`curses.textpad` for the +details. For More Information ==================== -This HOWTO doesn't cover some advanced topics, such as reading the -contents of the screen or capturing mouse events from an xterm -instance, but the Python library page for the :mod:`curses` module is now -reasonably complete. You should browse it next. +This HOWTO didn't cover some advanced topics, such as screen-scraping or +capturing mouse events from an xterm instance. But the Python library page for +the curses modules is now pretty complete. You should browse it next. -If you're in doubt about the detailed behavior of the curses -functions, consult the manual pages for your curses implementation, -whether it's ncurses or a proprietary Unix vendor's. The manual pages -will document any quirks, and provide complete lists of all the -functions, attributes, and :const:`ACS_\*` characters available to -you. +If you're in doubt about the detailed behavior of any of the ncurses entry +points, consult the manual pages for your curses implementation, whether it's +ncurses or a proprietary Unix vendor's. The manual pages will document any +quirks, and provide complete lists of all the functions, attributes, and +:const:`ACS_\*` characters available to you. -Because the curses API is so large, some functions aren't supported in -the Python interface. Often this isn't because they're difficult to -implement, but because no one has needed them yet. Also, Python -doesn't yet support the menu library associated with ncurses. -Patches adding support for these would be welcome; see -`the Python Developer's Guide `_ to -learn more about submitting patches to Python. +Because the curses API is so large, some functions aren't supported in the +Python interface, not because they're difficult to implement, but because no one +has needed them yet. Feel free to add them and then submit a patch. Also, we +don't yet have support for the menu library associated with +ncurses; feel free to add that. -* `Writing Programs with NCURSES `_: - a lengthy tutorial for C programmers. -* `The ncurses man page `_ -* `The ncurses FAQ `_ -* `"Use curses... don't swear" `_: - video of a PyCon 2013 talk on controlling terminals using curses or Urwid. -* `"Console Applications with Urwid" `_: - video of a PyCon CA 2012 talk demonstrating some applications written using - Urwid. +If you write an interesting little program, feel free to contribute it as +another demo. We can always use more of them! + +The ncurses FAQ: http://invisible-island.net/ncurses/ncurses.faq.html + diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/descriptor.rst --- a/Doc/howto/descriptor.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/descriptor.rst Fri Feb 01 23:12:09 2013 +0100 @@ -210,36 +210,25 @@ self.fget = fget self.fset = fset self.fdel = fdel - if doc is None and fget is not None: - doc = fget.__doc__ self.__doc__ = doc def __get__(self, obj, objtype=None): if obj is None: return self if self.fget is None: - raise AttributeError("unreadable attribute") + raise AttributeError, "unreadable attribute" return self.fget(obj) def __set__(self, obj, value): if self.fset is None: - raise AttributeError("can't set attribute") + raise AttributeError, "can't set attribute" self.fset(obj, value) def __delete__(self, obj): if self.fdel is None: - raise AttributeError("can't delete attribute") + raise AttributeError, "can't delete attribute" self.fdel(obj) - def getter(self, fget): - return type(self)(fget, self.fset, self.fdel, self.__doc__) - - def setter(self, fset): - return type(self)(self.fget, fset, self.fdel, self.__doc__) - - def deleter(self, fdel): - return type(self)(self.fget, self.fset, fdel, self.__doc__) - The :func:`property` builtin helps whenever a user interface has granted attribute access and then subsequent changes require the intervention of a method. @@ -401,7 +390,7 @@ :func:`dict.fromkeys` creates a new dictionary from a list of keys. The pure Python equivalent is:: - class Dict(object): + class Dict: . . . def fromkeys(klass, iterable, value=None): "Emulate dict_fromkeys() in Objects/dictobject.c" diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/functional.rst --- a/Doc/howto/functional.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/functional.rst Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,7 @@ ******************************** :Author: A. M. Kuchling -:Release: 0.32 +:Release: 0.31 In this document, we'll take a tour of Python's features suitable for implementing programs in a functional style. After an introduction to the @@ -15,9 +15,9 @@ Introduction ============ -This section explains the basic concept of functional programming; if -you're just interested in learning about Python language features, -skip to the next section on :ref:`functional-howto-iterators`. +This section explains the basic concept of functional programming; if you're +just interested in learning about Python language features, skip to the next +section. Programming languages support decomposing problems in several different ways: @@ -173,8 +173,6 @@ a few functions specialized for the current task. -.. _functional-howto-iterators: - Iterators ========= @@ -481,10 +479,13 @@ You could equally write ``for i in generate_ints(5)``, or ``a,b,c = generate_ints(3)``. -Inside a generator function, ``return value`` is semantically equivalent to -``raise StopIteration(value)``. If no value is returned or the bottom of the -function is reached, the procession of values ends and the generator cannot -return any further values. +Inside a generator function, the ``return`` statement can only be used without a +value, and signals the end of the procession of values; after executing a +``return`` the generator cannot return any further values. ``return`` with a +value, such as ``return 5``, is a syntax error inside a generator function. The +end of the generator's results can also be indicated by raising +:exc:`StopIteration` manually, or by just letting the flow of execution fall off +the bottom of the function. You could achieve the effect of generators manually by writing your own class and storing all the local variables of the generator as instance variables. For @@ -672,7 +673,7 @@ :func:`sorted(iterable, key=None, reverse=False) ` collects all the elements of the iterable into a list, sorts the list, and returns the sorted -result. The *key* and *reverse* arguments are passed through to the +result. The *key*, and *reverse* arguments are passed through to the constructed list's :meth:`~list.sort` method. :: >>> import random @@ -838,8 +839,7 @@ predicate. :func:`itertools.filterfalse(predicate, iter) ` is the -opposite of :func:`filter`, returning all elements for which the predicate -returns false:: +opposite, returning all elements for which the predicate returns false:: itertools.filterfalse(is_even, itertools.count()) => 1, 3, 5, 7, 9, 11, 13, 15, ... @@ -867,77 +867,6 @@ itertools.dropwhile(is_even, itertools.count()) => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... -:func:`itertools.compress(data, selectors) ` takes two -iterators and returns only those elements of *data* for which the corresponding -element of *selectors* is true, stopping whenever either one is exhausted:: - - itertools.compress([1,2,3,4,5], [True, True, False, False, True]) => - 1, 2, 5 - - -Combinatoric functions ----------------------- - -The :func:`itertools.combinations(iterable, r) ` -returns an iterator giving all possible *r*-tuple combinations of the -elements contained in *iterable*. :: - - itertools.combinations([1, 2, 3, 4, 5], 2) => - (1, 2), (1, 3), (1, 4), (1, 5), - (2, 3), (2, 4), (2, 5), - (3, 4), (3, 5), - (4, 5) - - itertools.combinations([1, 2, 3, 4, 5], 3) => - (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), - (2, 3, 4), (2, 3, 5), (2, 4, 5), - (3, 4, 5) - -The elements within each tuple remain in the same order as -*iterable* returned them. For example, the number 1 is always before -2, 3, 4, or 5 in the examples above. A similar function, -:func:`itertools.permutations(iterable, r=None) `, -removes this constraint on the order, returning all possible -arrangements of length *r*:: - - itertools.permutations([1, 2, 3, 4, 5], 2) => - (1, 2), (1, 3), (1, 4), (1, 5), - (2, 1), (2, 3), (2, 4), (2, 5), - (3, 1), (3, 2), (3, 4), (3, 5), - (4, 1), (4, 2), (4, 3), (4, 5), - (5, 1), (5, 2), (5, 3), (5, 4) - - itertools.permutations([1, 2, 3, 4, 5]) => - (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), - ... - (5, 4, 3, 2, 1) - -If you don't supply a value for *r* the length of the iterable is used, -meaning that all the elements are permuted. - -Note that these functions produce all of the possible combinations by -position and don't require that the contents of *iterable* are unique:: - - itertools.permutations('aba', 3) => - ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), - ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a') - -The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a' -strings came from different positions. - -The :func:`itertools.combinations_with_replacement(iterable, r) ` -function relaxes a different constraint: elements can be repeated -within a single tuple. Conceptually an element is selected for the -first position of each tuple and then is replaced before the second -element is selected. :: - - itertools.combinations_with_replacement([1, 2, 3, 4, 5], 2) => - (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), - (2, 2), (2, 3), (2, 4), (2, 5), - (3, 3), (3, 4), (3, 5), - (4, 4), (4, 5), - (5, 5) - Grouping elements ----------------- @@ -1060,17 +989,6 @@ for i in [1,2,3]: product *= i -A related function is `itertools.accumulate(iterable, func=operator.add) - 1, 3, 6, 10, 15 - - itertools.accumulate([1,2,3,4,5], operator.mul) => - 1, 2, 6, 24, 120 - The operator module ------------------- @@ -1244,6 +1162,51 @@ .. comment + Topics to place + ----------------------------- + + XXX os.walk() + + XXX Need a large example. + + But will an example add much? I'll post a first draft and see + what the comments say. + +.. comment + + Original outline: + Introduction + Idea of FP + Programs built out of functions + Functions are strictly input-output, no internal state + Opposed to OO programming, where objects have state + + Why FP? + Formal provability + Assignment is difficult to reason about + Not very relevant to Python + Modularity + Small functions that do one thing + Debuggability: + Easy to test due to lack of state + Easy to verify output from intermediate steps + Composability + You assemble a toolbox of functions that can be mixed + + Tackling a problem + Need a significant example + + Iterators + Generators + The itertools module + List comprehensions + Small functions and the lambda statement + Built-in functions + map + filter + +.. comment + Handy little function for printing part of an iterator -- used while writing this document. @@ -1254,3 +1217,5 @@ sys.stdout.write(str(elem)) sys.stdout.write(', ') print(elem[-1]) + + diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/index.rst --- a/Doc/howto/index.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/index.rst Fri Feb 01 23:12:09 2013 +0100 @@ -13,6 +13,7 @@ .. toctree:: :maxdepth: 1 + advocacy.rst pyporting.rst cporting.rst curses.rst diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/logging-cookbook.rst Fri Feb 01 23:12:09 2013 +0100 @@ -524,31 +524,69 @@ the keys of the dict-like object. If you need a different method, e.g. if you want to prepend or append the contextual information to the message string, you just need to subclass :class:`LoggerAdapter` and override :meth:`process` -to do what you need. Here is a simple example:: +to do what you need. Here's an example script which uses this class, which +also illustrates what dict-like behaviour is needed from an arbitrary +'dict-like' object for use in the constructor:: - class CustomAdapter(logging.LoggerAdapter): - """ - This example adapter expects the passed in dict-like object to have a - 'connid' key, whose value in brackets is prepended to the log message. - """ - def process(self, msg, kwargs): - return '[%s] %s' % (self.extra['connid'], msg), kwargs + import logging -which you can use like this:: + class ConnInfo: + """ + An example class which shows how an arbitrary class can be used as + the 'extra' context information repository passed to a LoggerAdapter. + """ - logger = logging.getLogger(__name__) - adapter = CustomAdapter(logger, {'connid': some_conn_id}) + def __getitem__(self, name): + """ + To allow this instance to look like a dict. + """ + from random import choice + if name == 'ip': + result = choice(['127.0.0.1', '192.168.0.1']) + elif name == 'user': + result = choice(['jim', 'fred', 'sheila']) + else: + result = self.__dict__.get(name, '?') + return result -Then any events that you log to the adapter will have the value of -``some_conn_id`` prepended to the log messages. + def __iter__(self): + """ + To allow iteration over keys, which will be merged into + the LogRecord dict before formatting and output. + """ + keys = ['ip', 'user'] + keys.extend(self.__dict__.keys()) + return keys.__iter__() -Using objects other than dicts to pass contextual information -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if __name__ == '__main__': + from random import choice + levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL) + a1 = logging.LoggerAdapter(logging.getLogger('a.b.c'), + { 'ip' : '123.231.231.123', 'user' : 'sheila' }) + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)-15s %(name)-5s %(levelname)-8s IP: %(ip)-15s User: %(user)-8s %(message)s') + a1.debug('A debug message') + a1.info('An info message with %s', 'some parameters') + a2 = logging.LoggerAdapter(logging.getLogger('d.e.f'), ConnInfo()) + for x in range(10): + lvl = choice(levels) + lvlname = logging.getLevelName(lvl) + a2.log(lvl, 'A message at %s level with %d %s', lvlname, 2, 'parameters') -You don't need to pass an actual dict to a :class:`LoggerAdapter` - you could -pass an instance of a class which implements ``__getitem__`` and ``__iter__`` so -that it looks like a dict to logging. This would be useful if you want to -generate values dynamically (whereas the values in a dict would be constant). +When this script is run, the output should look something like this:: + + 2008-01-18 14:49:54,023 a.b.c DEBUG IP: 123.231.231.123 User: sheila A debug message + 2008-01-18 14:49:54,023 a.b.c INFO IP: 123.231.231.123 User: sheila An info message with some parameters + 2008-01-18 14:49:54,023 d.e.f CRITICAL IP: 192.168.0.1 User: jim A message at CRITICAL level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f INFO IP: 192.168.0.1 User: jim A message at INFO level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f ERROR IP: 127.0.0.1 User: fred A message at ERROR level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f ERROR IP: 127.0.0.1 User: sheila A message at ERROR level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: jim A message at WARNING level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f INFO IP: 192.168.0.1 User: fred A message at INFO level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters + 2008-01-18 14:49:54,033 d.e.f WARNING IP: 127.0.0.1 User: jim A message at WARNING level with 2 parameters .. _filters-contextual: @@ -996,7 +1034,7 @@ call ``str()`` on that object to get the actual format string. Consider the following two classes:: - class BraceMessage: + class BraceMessage(object): def __init__(self, fmt, *args, **kwargs): self.fmt = fmt self.args = args @@ -1005,7 +1043,7 @@ def __str__(self): return self.fmt.format(*self.args, **self.kwargs) - class DollarMessage: + class DollarMessage(object): def __init__(self, fmt, **kwargs): self.fmt = fmt self.kwargs = kwargs @@ -1056,40 +1094,6 @@ string. That's because the __ notation is just syntax sugar for a constructor call to one of the XXXMessage classes. -If you prefer, you can use a :class:`LoggerAdapter` to achieve a similar effect -to the above, as in the following example:: - - import logging - - class Message(object): - def __init__(self, fmt, args): - self.fmt = fmt - self.args = args - - def __str__(self): - return self.fmt.format(*self.args) - - class StyleAdapter(logging.LoggerAdapter): - def __init__(self, logger, extra=None): - super(StyleAdapter, self).__init__(logger, extra or {}) - - def log(self, level, msg, *args, **kwargs): - if self.isEnabledFor(level): - msg, kwargs = self.process(msg, kwargs) - self.logger._log(level, Message(msg, args), (), **kwargs) - - logger = StyleAdapter(logging.getLogger(__name__)) - - def main(): - logger.debug('Hello, {}', 'world!') - - if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG) - main() - -The above script should log the message ``Hello, world!`` when run with -Python 3.2 or later. - .. currentmodule:: logging @@ -1366,7 +1370,7 @@ import random import time - class MyHandler: + class MyHandler(object): """ A simple handler for logging events. It runs in the listener process and dispatches events to loggers based on the name in the received record, @@ -1593,7 +1597,7 @@ 'ASCII section\ufeffUnicode section' - The Unicode code point U+FEFF, when encoded using UTF-8, will be + The Unicode code point ``'\feff'``, when encoded using UTF-8, will be encoded as a UTF-8 BOM -- the byte-string ``b'\xef\xbb\xbf'``. #. Replace the ASCII section with whatever placeholders you like, but make sure @@ -1609,85 +1613,3 @@ RFC 5424-compliant messages. If you don't, logging may not complain, but your messages will not be RFC 5424-compliant, and your syslog daemon may complain. - -Implementing structured logging -------------------------------- - -Although most logging messages are intended for reading by humans, and thus not -readily machine-parseable, there might be cirumstances where you want to output -messages in a structured format which *is* capable of being parsed by a program -(without needing complex regular expressions to parse the log message). This is -straightforward to achieve using the logging package. There are a number of -ways in which this could be achieved, but the following is a simple approach -which uses JSON to serialise the event in a machine-parseable manner:: - - import json - import logging - - class StructuredMessage(object): - def __init__(self, message, **kwargs): - self.message = message - self.kwargs = kwargs - - def __str__(self): - return '%s >>> %s' % (self.message, json.dumps(self.kwargs)) - - _ = StructuredMessage # optional, to improve readability - - logging.basicConfig(level=logging.INFO, format='%(message)s') - logging.info(_('message 1', foo='bar', bar='baz', num=123, fnum=123.456)) - -If the above script is run, it prints:: - - message 1 >>> {"fnum": 123.456, "num": 123, "bar": "baz", "foo": "bar"} - -Note that the order of items might be different according to the version of -Python used. - -If you need more specialised processing, you can use a custom JSON encoder, -as in the following complete example:: - - from __future__ import unicode_literals - - import json - import logging - - # This next bit is to ensure the script runs unchanged on 2.x and 3.x - try: - unicode - except NameError: - unicode = str - - class Encoder(json.JSONEncoder): - def default(self, o): - if isinstance(o, set): - return tuple(o) - elif isinstance(o, unicode): - return o.encode('unicode_escape').decode('ascii') - return super(Encoder, self).default(o) - - class StructuredMessage(object): - def __init__(self, message, **kwargs): - self.message = message - self.kwargs = kwargs - - def __str__(self): - s = Encoder().encode(self.kwargs) - return '%s >>> %s' % (self.message, s) - - _ = StructuredMessage # optional, to improve readability - - def main(): - logging.basicConfig(level=logging.INFO, format='%(message)s') - logging.info(_('message 1', set_value=set([1, 2, 3]), snowman='\u2603')) - - if __name__ == '__main__': - main() - -When the above script is run, it prints:: - - message 1 >>> {"snowman": "\u2603", "set_value": [1, 2, 3]} - -Note that the order of items might be different according to the version of -Python used. - diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/logging.rst --- a/Doc/howto/logging.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/logging.rst Fri Feb 01 23:12:09 2013 +0100 @@ -63,8 +63,6 @@ they are used to track. The standard levels and their applicability are described below (in increasing order of severity): -.. tabularcolumns:: |l|L| - +--------------+---------------------------------------------+ | Level | When it's used | +==============+=============================================+ @@ -332,9 +330,6 @@ to output. * Formatters specify the layout of log records in the final output. -Log event information is passed between loggers, handlers, filters and -formatters in a :class:`LogRecord` instance. - Logging is performed by calling methods on instances of the :class:`Logger` class (hereafter called :dfn:`loggers`). Each instance has a name, and they are conceptually arranged in a namespace hierarchy using dots (periods) as @@ -379,13 +374,6 @@ *format* keyword argument. For all options regarding how a format string is constructed, see :ref:`formatter-objects`. -Logging Flow -^^^^^^^^^^^^ - -The flow of log event information in loggers and handlers is illustrated in the -following diagram. - -.. image:: logging_flow.png Loggers ^^^^^^^ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/logging_flow.png Binary file Doc/howto/logging_flow.png has changed diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/pyporting.rst --- a/Doc/howto/pyporting.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/pyporting.rst Fri Feb 01 23:12:09 2013 +0100 @@ -21,21 +21,21 @@ Choosing a Strategy =================== -When a project chooses to support both Python 2 & 3, +When a project makes the decision that it's time to support both Python 2 & 3, a decision needs to be made as to how to go about accomplishing that goal. The chosen strategy will depend on how large the project's existing -codebase is and how much divergence you want from your current Python 2 codebase -(e.g., changing your code to work simultaneously with Python 2 and 3). +codebase is and how much divergence you want from your Python 2 codebase from +your Python 3 one (e.g., starting a new version with Python 3). + +If your project is brand-new or does not have a large codebase, then you may +want to consider writing/porting :ref:`all of your code for Python 3 +and use 3to2 ` to port your code for Python 2. If you would prefer to maintain a codebase which is semantically **and** syntactically compatible with Python 2 & 3 simultaneously, you can write :ref:`use_same_source`. While this tends to lead to somewhat non-idiomatic code, it does mean you keep a rapid development process for you, the developer. -If your project is brand-new or does not have a large codebase, then you may -want to consider writing/porting :ref:`all of your code for Python 3 -and use 3to2 ` to port your code for Python 2. - Finally, you do have the option of :ref:`using 2to3 ` to translate Python 2 code into Python 3 code (with some manual help). This can take the form of branching your code and using 2to3 to start a Python 3 branch. You can @@ -55,10 +55,10 @@ consider. One is make sure you have a robust test suite. You need to make sure everything -continues to work, just like when you support a new minor/feature release of -Python. This means making sure your test suite is thorough and is ported -properly between Python 2 & 3. You will also most likely want to use something -like tox_ to automate testing between both a Python 2 and Python 3 interpreter. +continues to work, just like when you support a new minor version of Python. +This means making sure your test suite is thorough and is ported properly +between Python 2 & 3. You will also most likely want to use something like tox_ +to automate testing between both a Python 2 and Python 3 VM. Two, once your project has Python 3 support, make sure to add the proper classifier on the Cheeseshop_ (PyPI_). To have your project listed as Python 3 @@ -98,8 +98,7 @@ Four, read all the approaches. Just because some bit of advice applies to one approach more than another doesn't mean that some advice doesn't apply to other -strategies. This is especially true of whether you decide to use 2to3 or be -source-compatible; tips for one approach almost always apply to the other. +strategies. Five, drop support for older Python versions if possible. `Python 2.5`_ introduced a lot of useful syntax and libraries which have become idiomatic @@ -109,14 +108,6 @@ of Python which you believe can be your minimum support version and work from there. -Six, target the newest version of Python 3 that you can. Beyond just the usual -bugfixes, compatibility has continued to improve between Python 2 and 3 as time -has passed. This is especially true for Python 3.3 where the ``u`` prefix for -strings is allowed, making source-compatible Python code easier. - -Seven, make sure to look at the `Other Resources`_ for tips from other people -which may help you out. - .. _tox: http://codespeak.net/tox/ .. _Cheeseshop: @@ -178,8 +169,8 @@ prefer this approach compared to using :ref:`use_same_source` or simply keeping a separate Python 3 codebase. -Below are the typical steps taken by a project which tries to support -Python 2 & 3 while keeping the code directly executable by Python 2. +Below are the typical steps taken by a project which uses a 2to3-based approach +to supporting Python 2 & 3. Support Python 2.7 @@ -224,9 +215,7 @@ you use this future statement or not, you **must** make sure you know exactly which Python 2 strings you want to be bytes, and which are to be strings. This means you should, **at minimum** mark all strings that are meant to be text -strings with a ``u`` prefix if you do not use this future statement. Python 3.3 -allows strings to continue to have the ``u`` prefix (it's a no-op in that case) -to make it easier for code to be source-compatible between Python 2 & 3. +strings with a ``u`` prefix if you do not use this future statement. Bytes literals @@ -237,15 +226,6 @@ what is and is not a Python 3 string. When you run 2to3 on code, all Python 2 strings become Python 3 strings **unless** they are prefixed with ``b``. -This point cannot be stressed enough: make sure you know what all of your string -literals in Python 2 are meant to become in Python 3. Any string literal that -should be treated as bytes should have the ``b`` prefix. Any string literal -that should be Unicode/text in Python 2 should either have the ``u`` literal -(supported, but ignored, in Python 3.3 and later) or you should have -``from __future__ import unicode_literals`` at the top of the file. But the key -point is you should know how Python 3 will treat everyone one of your string -literals and you should mark them as appropriate. - There are some differences between byte literals in Python 2 and those in Python 3 thanks to the bytes type just being an alias to ``str`` in Python 2. Probably the biggest "gotcha" is that indexing results in different values. In @@ -284,16 +264,6 @@ than Python 2.5, use the __future__ statement. -Mark all Unicode strings with a ``u`` prefix -''''''''''''''''''''''''''''''''''''''''''''' - -While Python 2.6 has a ``__future__`` statement to automatically cause Python 2 -to treat all string literals as Unicode, Python 2.5 does not have that shortcut. -This means you should go through and mark all string literals with a ``u`` -prefix to turn them explicitly into Unicode strings where appropriate. That -leaves all unmarked string literals to be considered byte literals in Python 3. - - Handle Common "Gotchas" ----------------------- @@ -738,7 +708,6 @@ * http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/ * http://lucumr.pocoo.org/2010/2/11/porting-to-python-3-a-guide/ * http://wiki.python.org/moin/PortingPythonToPy3k -* https://wiki.ubuntu.com/Python/3 If you feel there is something missing from this document that should be added, please email the python-porting_ mailing list. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/sockets.rst --- a/Doc/howto/sockets.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/sockets.rst Fri Feb 01 23:12:09 2013 +0100 @@ -19,6 +19,12 @@ Sockets ======= +Sockets are used nearly everywhere, but are one of the most severely +misunderstood technologies around. This is a 10,000 foot overview of sockets. +It's not really a tutorial - you'll still have work to do in getting things +working. It doesn't cover the fine points (and there are a lot of them), but I +hope it will give you enough background to begin using them decently. + I'm only going to talk about INET (i.e. IPv4) sockets, but they account for at least 99% of the sockets in use. And I'll only talk about STREAM (i.e. TCP) sockets - unless you really know what you're doing (in which case this HOWTO isn't for you!), you'll get @@ -78,11 +84,9 @@ serversocket.listen(5) A couple things to notice: we used ``socket.gethostname()`` so that the socket -would be visible to the outside world. If we had used ``s.bind(('localhost', -80))`` or ``s.bind(('127.0.0.1', 80))`` we would still have a "server" socket, -but one that was only visible within the same machine. ``s.bind(('', 80))`` -specifies that the socket is reachable by any address the machine happens to -have. +would be visible to the outside world. If we had used ``s.bind(('', 80))`` or +``s.bind(('localhost', 80))`` or ``s.bind(('127.0.0.1', 80))`` we would still +have a "server" socket, but one that was only visible within the same machine. A second thing to note: low number ports are usually reserved for "well known" services (HTTP, SNMP etc). If you're playing around, use a nice high number (4 diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/sorting.rst --- a/Doc/howto/sorting.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/sorting.rst Fri Feb 01 23:12:09 2013 +0100 @@ -225,7 +225,7 @@ def cmp_to_key(mycmp): 'Convert a cmp= function into a key= function' - class K: + class K(object): def __init__(self, obj, *args): self.obj = obj def __lt__(self, other): diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/unicode.rst --- a/Doc/howto/unicode.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/unicode.rst Fri Feb 01 23:12:09 2013 +0100 @@ -28,15 +28,15 @@ as 'naïve' and 'café', and some publications have house styles which require spellings such as 'coöperate'.) -For a while people just wrote programs that didn't display accents. -In the mid-1980s an Apple II BASIC program written by a French speaker -might have lines like these:: +For a while people just wrote programs that didn't display accents. I remember +looking at Apple ][ BASIC programs, published in French-language publications in +the mid-1980s, that had lines like these:: PRINT "FICHIER EST COMPLETE." PRINT "CARACTERE NON ACCEPTE." -Those messages should contain accents (completé, caractère, accepté), -and they just look wrong to someone who can read French. +Those messages should contain accents, and they just look wrong to someone who +can read French. In the 1980s, almost all personal computers were 8-bit, meaning that bytes could hold values ranging from 0 to 255. ASCII codes only went up to 127, so some @@ -44,7 +44,7 @@ machines had different codes, however, which led to problems exchanging files. 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 +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 @@ -62,19 +62,16 @@ 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 through 1,114,111 ( -``0x10FFFF`` in base 16). +Unicode specification uses a wider range of codes, 0 through 1,114,111 (0x10ffff +in base 16). There's a related ISO standard, ISO 10646. Unicode and ISO 10646 were originally separate efforts, but the specifications were merged with the 1.1 revision of Unicode. -(This discussion of Unicode's history is highly simplified. The -precise historical details aren't necessary for understanding how to -use Unicode effectively, but if you're curious, consult the Unicode -consortium site listed in the References or -the `Wikipedia entry for Unicode `_ -for more information.) +(This discussion of Unicode's history is highly simplified. I don't think the +average Python programmer needs to worry about the historical details; consult +the Unicode consortium site listed in the References for more information.) Definitions @@ -90,11 +87,9 @@ The Unicode standard describes how characters are represented by **code points**. A code point is an integer value, usually denoted in base 16. In the -standard, a code point is written using the notation ``U+12CA`` to mean the -character with value ``0x12ca`` (4,810 decimal). The Unicode standard contains -a lot of tables listing characters and their corresponding code points: - -.. code-block:: none +standard, a code point is written using the notation U+12ca to mean the +character with value 0x12ca (4,810 decimal). The Unicode standard contains a lot +of tables listing characters and their corresponding code points:: 0061 'a'; LATIN SMALL LETTER A 0062 'b'; LATIN SMALL LETTER B @@ -103,7 +98,7 @@ 007B '{'; LEFT CURLY BRACKET Strictly, these definitions imply that it's meaningless to say 'this is -character ``U+12CA``'. ``U+12CA`` is a code point, which represents some particular +character U+12ca'. U+12ca is a code point, which represents some particular character; in this case, it represents the character 'ETHIOPIC SYLLABLE WI'. In informal contexts, this distinction between code points and characters will sometimes be forgotten. @@ -120,15 +115,13 @@ --------- To summarize the previous section: a Unicode string is a sequence of code -points, which are numbers from 0 through ``0x10FFFF`` (1,114,111 decimal). This +points, which are numbers from 0 through 0x10ffff (1,114,111 decimal). This sequence needs to be represented as a set of bytes (meaning, values from 0 through 255) in memory. The rules for translating a Unicode string into a sequence of bytes are called an **encoding**. The first encoding you might think of is an array of 32-bit integers. In this -representation, the string "Python" would look like this: - -.. code-block:: none +representation, the string "Python" would look like this:: P y t h o n 0x50 00 00 00 79 00 00 00 74 00 00 00 68 00 00 00 6f 00 00 00 6e 00 00 00 @@ -140,10 +133,10 @@ 1. It's not portable; different processors order the bytes differently. 2. It's very wasteful of space. In most texts, the majority of the code points - are less than 127, or less than 255, so a lot of space is occupied by ``0x00`` + are less than 127, or less than 255, so a lot of space is occupied by zero bytes. The above string takes 24 bytes compared to the 6 bytes needed for an ASCII representation. Increased RAM usage doesn't matter too much (desktop - computers have gigabytes of RAM, and strings aren't usually that large), but + computers have megabytes of RAM, and strings aren't usually that large), but expanding our usage of disk and network bandwidth by a factor of 4 is intolerable. @@ -182,12 +175,14 @@ UTF-8 is one of the most commonly used encodings. UTF stands for "Unicode Transformation Format", and the '8' means that 8-bit numbers are used in the -encoding. (There are also a UTF-16 and UTF-32 encodings, but they are less -frequently used than UTF-8.) UTF-8 uses the following rules: +encoding. (There's also a UTF-16 encoding, but it's less frequently used than +UTF-8.) UTF-8 uses the following rules: -1. If the code point is < 128, it's represented by the corresponding byte value. -2. If the code point is >= 128, it's turned into a sequence of two, three, or - four bytes, where each byte of the sequence is between 128 and 255. +1. If the code point is <128, it's represented by the corresponding byte value. +2. If the code point is between 128 and 0x7ff, it's turned into two byte values + between 128 and 255. +3. Code points >0x7ff are turned into three- or four-byte sequences, where each + byte of the sequence is between 128 and 255. UTF-8 has several convenient properties: @@ -197,8 +192,8 @@ processed by C functions such as ``strcpy()`` and sent through protocols that can't handle zero bytes. 3. A string of ASCII text is also valid UTF-8 text. -4. UTF-8 is fairly compact; the majority of commonly used characters can be - represented with one or two bytes. +4. UTF-8 is fairly compact; the majority of code points are turned into two + bytes, and values less than 128 occupy only a single byte. 5. If bytes are corrupted or lost, it's possible to determine the start of the next UTF-8-encoded code point and resynchronize. It's also unlikely that random 8-bit data will look like valid UTF-8. @@ -208,23 +203,25 @@ References ---------- -The `Unicode Consortium site `_ has character charts, a +The Unicode Consortium site at has character charts, a glossary, and PDF versions of the Unicode specification. Be prepared for some -difficult reading. `A chronology `_ of the -origin and development of Unicode is also available on the site. +difficult reading. is a chronology of the +origin and development of Unicode. -To help understand the standard, Jukka Korpela has written `an introductory -guide `_ to reading the -Unicode character tables. +To help understand the standard, Jukka Korpela has written an introductory guide +to reading the Unicode character tables, available at +. -Another `good introductory article `_ -was written by Joel Spolsky. -If this introduction didn't make things clear to you, you should try -reading this alternate article before continuing. +Another good introductory article was written by Joel Spolsky +. +If this introduction didn't make things clear to you, you should try reading this +alternate article before continuing. -Wikipedia entries are often helpful; see the entries for "`character encoding -`_" and `UTF-8 -`_, for example. +.. Jason Orendorff XXX http://www.jorendorff.com/articles/unicode/ is broken + +Wikipedia entries are often helpful; see the entries for "character encoding" + and UTF-8 +, for example. Python's Unicode Support @@ -236,35 +233,12 @@ The String Type --------------- -Since Python 3.0, the language features a :class:`str` type that contain Unicode +Since Python 3.0, the language features a ``str`` type that contain Unicode characters, meaning any string created using ``"unicode rocks!"``, ``'unicode rocks!'``, or the triple-quoted string syntax is stored as Unicode. -The default encoding for Python source code is UTF-8, so you can simply -include a Unicode character in a string literal:: - - try: - with open('/tmp/input.txt', 'r') as f: - ... - except IOError: - # 'File not found' error message. - print("Fichier non trouvé") - -You can use a different encoding from UTF-8 by putting a specially-formatted -comment as the first or second line of the source code:: - - # -*- coding: -*- - -Side note: Python 3 also supports using Unicode characters in identifiers:: - - répertoire = "/tmp/records.log" - with open(répertoire, "w") as f: - f.write("test\n") - -If you can't enter a particular character in your editor or want to -keep the source code ASCII-only for some reason, you can also use -escape sequences in string literals. (Depending on your system, -you may see the actual capital-delta glyph instead of a \u escape.) :: +To insert a Unicode character that is not part ASCII, e.g., any letters with +accents, one can use escape sequences in their string literals as such:: >>> "\N{GREEK CAPITAL LETTER DELTA}" # Using the character name '\u0394' @@ -273,16 +247,15 @@ >>> "\U00000394" # Using a 32-bit hex value '\u0394' -In addition, one can create a string using the :func:`~bytes.decode` method of -:class:`bytes`. This method takes an *encoding* argument, such as ``UTF-8``, -and optionally an *errors* argument. +In addition, one can create a string using the :func:`decode` method of +:class:`bytes`. This method takes an encoding, such as UTF-8, and, optionally, +an *errors* argument. The *errors* argument specifies the response when the input string can't be converted according to the encoding's rules. Legal values for this argument are -``'strict'`` (raise a :exc:`UnicodeDecodeError` exception), ``'replace'`` (use -``U+FFFD``, ``REPLACEMENT CHARACTER``), or ``'ignore'`` (just leave the -character out of the Unicode result). -The following examples show the differences:: +'strict' (raise a :exc:`UnicodeDecodeError` exception), 'replace' (use U+FFFD, +'REPLACEMENT CHARACTER'), or 'ignore' (just leave the character out of the +Unicode result). The following examples show the differences:: >>> b'\x80abc'.decode("utf-8", "strict") #doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): @@ -300,8 +273,8 @@ Encodings are specified as strings containing the encoding's name. Python 3.2 comes with roughly 100 different encodings; see the Python Library Reference at :ref:`standard-encodings` for a list. Some encodings have multiple names; for -example, ``'latin-1'``, ``'iso_8859_1'`` and ``'8859``' are all synonyms for -the same encoding. +example, 'latin-1', 'iso_8859_1' and '8859' are all synonyms for the same +encoding. One-character Unicode strings can also be created with the :func:`chr` built-in function, which takes integers and returns a Unicode string of length 1 @@ -317,18 +290,13 @@ Converting to Bytes ------------------- -The opposite method of :meth:`bytes.decode` is :meth:`str.encode`, -which returns a :class:`bytes` representation of the Unicode string, encoded in the -requested *encoding*. - -The *errors* parameter is the same as the parameter of the -:meth:`~bytes.decode` method but supports a few more possible handlers. As well as -``'strict'``, ``'ignore'``, and ``'replace'`` (which in this case -inserts a question mark instead of the unencodable character), there is -also ``'xmlcharrefreplace'`` (inserts an XML character reference) and -``backslashreplace`` (inserts a ``\uNNNN`` escape sequence). - -The following example shows the different results:: +Another important str method is ``.encode([encoding], [errors='strict'])``, +which returns a ``bytes`` representation of the Unicode string, encoded in the +requested encoding. The ``errors`` parameter is the same as the parameter of +the :meth:`decode` method, with one additional possibility; as well as 'strict', +'ignore', and 'replace' (which in this case inserts a question mark instead of +the unencodable character), you can also pass 'xmlcharrefreplace' which uses +XML's character references. The following example shows the different results:: >>> u = chr(40960) + 'abcd' + chr(1972) >>> u.encode('utf-8') @@ -344,15 +312,14 @@ b'?abcd?' >>> u.encode('ascii', 'xmlcharrefreplace') b'ꀀabcd޴' - >>> u.encode('ascii', 'backslashreplace') - b'\\ua000abcd\\u07b4' -The low-level routines for registering and accessing the available -encodings are found in the :mod:`codecs` module. Implementing new -encodings also requires understanding the :mod:`codecs` module. -However, the encoding and decoding functions returned by this module -are usually more low-level than is comfortable, and writing new encodings -is a specialized task, so the module won't be covered in this HOWTO. +The low-level routines for registering and accessing the available encodings are +found in the :mod:`codecs` module. However, the encoding and decoding functions +returned by this module are usually more low-level than is comfortable, so I'm +not going to describe the :mod:`codecs` module here. If you need to implement a +completely new encoding, you'll need to learn about the :mod:`codecs` module +interfaces, but implementing encodings is a specialized task that also won't be +covered here. Consult the Python documentation to learn more about this module. Unicode Literals in Python Source Code @@ -398,14 +365,14 @@ ``coding: name`` or ``coding=name`` in the comment. If you don't include such a comment, the default encoding used will be UTF-8 as -already mentioned. See also :pep:`263` for more information. +already mentioned. Unicode Properties ------------------ The Unicode specification includes a database of information about code points. -For each defined code point, the information includes the character's +For each code point that's defined, the information includes the character's name, its category, the numeric value if applicable (Unicode has characters representing the Roman numerals and fractions such as one-third and four-fifths). There are also properties related to the code point's use in @@ -425,9 +392,7 @@ # Get numeric value of second character print(unicodedata.numeric(u[1])) -When run, this prints: - -.. code-block:: none +When run, this prints:: 0 00e9 Ll LATIN SMALL LETTER E WITH ACUTE 1 0bf2 No TAMIL NUMBER ONE THOUSAND @@ -442,61 +407,25 @@ from the above output, ``'Ll'`` means 'Letter, lowercase', ``'No'`` means "Number, other", ``'Mn'`` is "Mark, nonspacing", and ``'So'`` is "Symbol, other". See -`the General Category Values section of the Unicode Character Database documentation `_ for a + for a list of category codes. - -Unicode Regular Expressions ---------------------------- - -The regular expressions supported by the :mod:`re` module can be provided -either as bytes or strings. Some of the special character sequences such as -``\d`` and ``\w`` have different meanings depending on whether -the pattern is supplied as bytes or a string. For example, -``\d`` will match the characters ``[0-9]`` in bytes but -in strings will match any character that's in the ``'Nd'`` category. - -The string in this example has the number 57 written in both Thai and -Arabic numerals:: - - import re - p = re.compile('\d+') - - s = "Over \u0e55\u0e57 57 flavours" - m = p.search(s) - print(repr(m.group())) - -When executed, ``\d+`` will match the Thai numerals and print them -out. If you supply the :const:`re.ASCII` flag to -:func:`~re.compile`, ``\d+`` will match the substring "57" instead. - -Similarly, ``\w`` matches a wide variety of Unicode characters but -only ``[a-zA-Z0-9_]`` in bytes or if :const:`re.ASCII` is supplied, -and ``\s`` will match either Unicode whitespace characters or -``[ \t\n\r\f\v]``. - - References ---------- -.. comment should these be mentioned earlier, e.g. at the start of the "introduction to Unicode" first section? - -Some good alternative discussions of Python's Unicode support are: - -* `Processing Text Files in Python 3 `_, by Nick Coghlan. -* `Pragmatic Unicode `_, a PyCon 2012 presentation by Ned Batchelder. - -The :class:`str` type is described in the Python library reference at +The ``str`` type is described in the Python library reference at :ref:`textseq`. The documentation for the :mod:`unicodedata` module. The documentation for the :mod:`codecs` module. -Marc-André Lemburg gave `a presentation titled "Python and Unicode" (PDF slides) `_ at -EuroPython 2002. The slides are an excellent overview of the design -of Python 2's Unicode features (where the Unicode string type is -called ``unicode`` and literals start with ``u``). +Marc-André Lemburg gave a presentation at EuroPython 2002 titled "Python and +Unicode". A PDF version of his slides is available at +, and is an +excellent overview of the design of Python's Unicode features (based on Python +2, where the Unicode string type is called ``unicode`` and literals start with +``u``). Reading and Writing Unicode Data @@ -514,16 +443,16 @@ Unicode data is usually converted to a particular encoding before it gets written to disk or sent over a socket. It's possible to do all the work -yourself: open a file, read an 8-bit bytes object from it, and convert the string -with ``bytes.decode(encoding)``. However, the manual approach is not recommended. +yourself: open a file, read an 8-bit byte string from it, and convert the string +with ``str(bytes, encoding)``. However, the manual approach is not recommended. One problem is the multi-byte nature of encodings; one Unicode character can be represented by several bytes. If you want to read the file in arbitrary-sized -chunks (say, 1024 or 4096 bytes), you need to write error-handling code to catch the case +chunks (say, 1K or 4K), you need to write error-handling code to catch the case where only part of the bytes encoding a single Unicode character are read at the end of a chunk. One solution would be to read the entire file into memory and then perform the decoding, but that prevents you from working with files that -are extremely large; if you need to read a 2 GiB file, you need 2 GiB of RAM. +are extremely large; if you need to read a 2Gb file, you need 2Gb of RAM. (More, really, since for at least a moment you'd need to have both the encoded string and its Unicode version in memory.) @@ -531,9 +460,9 @@ of partial coding sequences. The work of implementing this has already been done for you: the built-in :func:`open` function can return a file-like object that assumes the file's contents are in a specified encoding and accepts Unicode -parameters for methods such as :meth:`read` and :meth:`write`. This works through +parameters for methods such as ``.read()`` and ``.write()``. This works through :func:`open`\'s *encoding* and *errors* parameters which are interpreted just -like those in :meth:`str.encode` and :meth:`bytes.decode`. +like those in string objects' :meth:`encode` and :meth:`decode` methods. Reading Unicode from a file is therefore simple:: @@ -549,7 +478,7 @@ f.seek(0) print(repr(f.readline()[:1])) -The Unicode character ``U+FEFF`` is used as a byte-order mark (BOM), and is often +The Unicode character U+FEFF is used as a byte-order mark (BOM), and is often written as the first character of a file in order to assist with autodetection of the file's byte ordering. Some encodings, such as UTF-16, expect a BOM to be present at the start of a file; when such an encoding is used, the BOM will be @@ -575,7 +504,7 @@ Windows, Python uses the name "mbcs" to refer to whatever the currently configured encoding is. On Unix systems, there will only be a filesystem encoding if you've set the ``LANG`` or ``LC_CTYPE`` environment variables; if -you haven't, the default encoding is UTF-8. +you haven't, the default encoding is ASCII. The :func:`sys.getfilesystemencoding` function returns the encoding to use on your current system, in case you want to do the encoding manually, but there's @@ -590,13 +519,13 @@ Functions in the :mod:`os` module such as :func:`os.stat` will also accept Unicode filenames. -The :func:`os.listdir` function returns filenames and raises an issue: should it return -the Unicode version of filenames, or should it return bytes containing +Function :func:`os.listdir`, which returns filenames, raises an issue: should it return +the Unicode version of filenames, or should it return byte strings containing the encoded versions? :func:`os.listdir` will do both, depending on whether you -provided the directory path as bytes or a Unicode string. If you pass a +provided the directory path as a byte string or a Unicode string. If you pass a Unicode string as the path, filenames will be decoded using the filesystem's encoding and a list of Unicode strings will be returned, while passing a byte -path will return the filenames as bytes. For example, +path will return the byte string versions of the filenames. For example, assuming the default filesystem encoding is UTF-8, running the following program:: @@ -611,13 +540,13 @@ will produce the following output:: amk:~$ python t.py - [b'filename\xe4\x94\x80abc', ...] - ['filename\u4500abc', ...] + [b'.svn', b'filename\xe4\x94\x80abc', ...] + ['.svn', 'filename\u4500abc', ...] The first list contains UTF-8-encoded filenames, and the second list contains the Unicode versions. -Note that on most occasions, the Unicode APIs should be used. The bytes APIs +Note that in most occasions, the Unicode APIs should be used. The bytes APIs should only be used on systems where undecodable file names can be present, i.e. Unix systems. @@ -630,13 +559,13 @@ The most important tip is: - Software should only work with Unicode strings internally, decoding the input - data as soon as possible and encoding the output only at the end. + Software should only work with Unicode strings internally, converting to a + particular encoding on output. If you attempt to write processing functions that accept both Unicode and byte strings, you will find your program vulnerable to bugs wherever you combine the -two different kinds of strings. There is no automatic encoding or decoding: if -you do e.g. ``str + bytes``, a :exc:`TypeError` will be raised. +two different kinds of strings. There is no automatic encoding or decoding if +you do e.g. ``str + bytes``, a :exc:`TypeError` is raised for this expression. When using data coming from a web browser or some other untrusted source, a common technique is to check for illegal characters in a string before using the @@ -648,69 +577,68 @@ clever way to hide malicious text in the encoded bytestream. -Converting Between File Encodings -''''''''''''''''''''''''''''''''' - -The :class:`~codecs.StreamRecoder` class can transparently convert between -encodings, taking a stream that returns data in encoding #1 -and behaving like a stream returning data in encoding #2. - -For example, if you have an input file *f* that's in Latin-1, you -can wrap it with a :class:`StreamRecoder` to return bytes encoded in UTF-8:: - - new_f = codecs.StreamRecoder(f, - # en/decoder: used by read() to encode its results and - # by write() to decode its input. - codecs.getencoder('utf-8'), codecs.getdecoder('utf-8'), - - # reader/writer: used to read and write to the stream. - codecs.getreader('latin-1'), codecs.getwriter('latin-1') ) - - -Files in an Unknown Encoding -'''''''''''''''''''''''''''' - -What can you do if you need to make a change to a file, but don't know -the file's encoding? If you know the encoding is ASCII-compatible and -only want to examine or modify the ASCII parts, you can open the file -with the ``surrogateescape`` error handler:: - - with open(fname, 'r', encoding="ascii", errors="surrogateescape") as f: - data = f.read() - - # make changes to the string 'data' - - with open(fname + '.new', 'w', - encoding="ascii", errors="surrogateescape") as f: - f.write(data) - -The ``surrogateescape`` error handler will decode any non-ASCII bytes -as code points in the Unicode Private Use Area ranging from U+DC80 to -U+DCFF. These private code points will then be turned back into the -same bytes when the ``surrogateescape`` error handler is used when -encoding the data and writing it back out. - - References ---------- -One section of `Mastering Python 3 Input/Output `_, a PyCon 2010 talk by David Beazley, discusses text processing and binary data handling. - -The `PDF slides for Marc-André Lemburg's presentation "Writing Unicode-aware Applications in Python" `_ -discuss questions of character encodings as well as how to internationalize +The PDF slides for Marc-André Lemburg's presentation "Writing Unicode-aware +Applications in Python" are available at + +and discuss questions of character encodings as well as how to internationalize and localize an application. These slides cover Python 2.x only. -`The Guts of Unicode in Python `_ is a PyCon 2013 talk by Benjamin Peterson that discusses the internal Unicode representation in Python 3.3. - Acknowledgements ================ -The initial draft of this document was written by Andrew Kuchling. -It has since been revised further by Alexander Belopolsky, Georg Brandl, -Andrew Kuchling, and Ezio Melotti. +Thanks to the following people who have noted errors or offered suggestions on +this article: Nicholas Bastin, Marius Gedminas, Kent Johnson, Ken Krugler, +Marc-André Lemburg, Martin von Löwis, Chad Whitacre. -Thanks to the following people who have noted errors or offered -suggestions on this article: Éric Araujo, Nicholas Bastin, Nick -Coghlan, Marius Gedminas, Kent Johnson, Ken Krugler, Marc-André -Lemburg, Martin von Löwis, Terry J. Reedy, Chad Whitacre. +.. comment + Revision History + + Version 1.0: posted August 5 2005. + + Version 1.01: posted August 7 2005. Corrects factual and markup errors; adds + several links. + + Version 1.02: posted August 16 2005. Corrects factual errors. + + Version 1.1: Feb-Nov 2008. Updates the document with respect to Python 3 changes. + + Version 1.11: posted June 20 2010. Notes that Python 3.x is not covered, + and that the HOWTO only covers 2.x. + +.. comment Describe Python 3.x support (new section? new document?) +.. comment Additional topic: building Python w/ UCS2 or UCS4 support +.. comment Describe use of codecs.StreamRecoder and StreamReaderWriter + +.. comment + Original outline: + + - [ ] Unicode introduction + - [ ] ASCII + - [ ] Terms + - [ ] Character + - [ ] Code point + - [ ] Encodings + - [ ] Common encodings: ASCII, Latin-1, UTF-8 + - [ ] Unicode Python type + - [ ] Writing unicode literals + - [ ] Obscurity: -U switch + - [ ] Built-ins + - [ ] unichr() + - [ ] ord() + - [ ] unicode() constructor + - [ ] Unicode type + - [ ] encode(), decode() methods + - [ ] Unicodedata module for character properties + - [ ] I/O + - [ ] Reading/writing Unicode data into files + - [ ] Byte-order marks + - [ ] Unicode filenames + - [ ] Writing Unicode programs + - [ ] Do everything in Unicode + - [ ] Declaring source code encodings (PEP 263) + - [ ] Other issues + - [ ] Building Python (UCS2, UCS4) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/howto/urllib2.rst Fri Feb 01 23:12:09 2013 +0100 @@ -504,10 +504,9 @@ In the above example we only supplied our ``HTTPBasicAuthHandler`` to ``build_opener``. By default openers have the handlers for normal situations - -- ``ProxyHandler`` (if a proxy setting such as an :envvar:`http_proxy` - environment variable is set), ``UnknownHandler``, ``HTTPHandler``, + -- ``ProxyHandler``, ``UnknownHandler``, ``HTTPHandler``, ``HTTPDefaultErrorHandler``, ``HTTPRedirectHandler``, ``FTPHandler``, - ``FileHandler``, ``DataHandler``, ``HTTPErrorProcessor``. + ``FileHandler``, ``HTTPErrorProcessor``. ``top_level_url`` is in fact *either* a full URL (including the 'http:' scheme component and the hostname and optionally the port number) @@ -522,11 +521,10 @@ ======= **urllib** will auto-detect your proxy settings and use those. This is through -the ``ProxyHandler``, which is part of the normal handler chain when a proxy -setting is detected. Normally that's a good thing, but there are occasions -when it may not be helpful [#]_. One way to do this is to setup our own -``ProxyHandler``, with no proxies defined. This is done using similar steps to -setting up a `Basic Authentication`_ handler : :: +the ``ProxyHandler`` which is part of the normal handler chain. Normally that's +a good thing, but there are occasions when it may not be helpful [#]_. One way +to do this is to setup our own ``ProxyHandler``, with no proxies defined. This +is done using similar steps to setting up a `Basic Authentication`_ handler : :: >>> proxy_support = urllib.request.ProxyHandler({}) >>> opener = urllib.request.build_opener(proxy_support) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/install/index.rst --- a/Doc/install/index.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/install/index.rst Fri Feb 01 23:12:09 2013 +0100 @@ -189,7 +189,7 @@ to keep the source tree pristine, you can change the build directory with the :option:`--build-base` option. For example:: - python setup.py build --build-base=/path/to/pybuild/foo-1.0 + python setup.py build --build-base=/tmp/pybuild/foo-1.0 (Or you could do this permanently with a directive in your system or personal Distutils configuration file; see section :ref:`inst-config-files`.) Normally, this @@ -235,8 +235,6 @@ Unix-based), it also depends on whether the module distribution being installed is pure Python or contains extensions ("non-pure"): -.. tabularcolumns:: |l|l|l|l| - +-----------------+-----------------------------------------------------+--------------------------------------------------+-------+ | Platform | Standard installation location | Default value | Notes | +=================+=====================================================+==================================================+=======+ @@ -645,11 +643,6 @@ the Distutils are the only ones you can use.) See section :ref:`inst-config-files` for details. -.. note:: When a :ref:`virtual environment ` is activated, any options - that change the installation path will be ignored from all distutils configuration - files to prevent inadvertently installing projects outside of the virtual - environment. - .. XXX need some Windows examples---when would custom installation schemes be needed on those platforms? diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/2to3.rst --- a/Doc/library/2to3.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/2to3.rst Fri Feb 01 23:12:09 2013 +0100 @@ -264,7 +264,8 @@ .. 2to3fixer:: long - Renames :class:`long` to :class:`int`. + Strips the ``L`` prefix on long literals and renames :class:`long` to + :class:`int`. .. 2to3fixer:: map diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/_dummy_thread.rst --- a/Doc/library/_dummy_thread.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/_dummy_thread.rst Fri Feb 01 23:12:09 2013 +0100 @@ -17,7 +17,7 @@ try: import _thread except ImportError: - import _dummy_thread as _thread + import dummy_thread as _thread Be careful to not use this module where deadlock might occur from a thread being created that blocks waiting for another thread to be created. This often occurs diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/_thread.rst --- a/Doc/library/_thread.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/_thread.rst Fri Feb 01 23:12:09 2013 +0100 @@ -93,15 +93,15 @@ Return the thread stack size used when creating new threads. The optional *size* argument specifies the stack size to be used for subsequently created threads, and must be 0 (use platform or configured default) or a positive - integer value of at least 32,768 (32 KiB). If changing the thread stack size is + integer value of at least 32,768 (32kB). If changing the thread stack size is unsupported, a :exc:`RuntimeError` is raised. If the specified stack size is - invalid, a :exc:`ValueError` is raised and the stack size is unmodified. 32 KiB + invalid, a :exc:`ValueError` is raised and the stack size is unmodified. 32kB is currently the minimum supported stack size value to guarantee sufficient stack space for the interpreter itself. Note that some platforms may have particular restrictions on values for the stack size, such as requiring a - minimum stack size > 32 KiB or requiring allocation in multiples of the system + minimum stack size > 32kB or requiring allocation in multiples of the system memory page size - platform documentation should be referred to for more - information (4 KiB pages are common; using multiples of 4096 for the stack size is + information (4kB pages are common; using multiples of 4096 for the stack size is the suggested approach in the absence of more specific information). Availability: Windows, systems with POSIX threads. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/abc.rst --- a/Doc/library/abc.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/abc.rst Fri Feb 01 23:12:09 2013 +0100 @@ -58,10 +58,6 @@ .. versionchanged:: 3.3 Returns the registered subclass, to allow usage as a class decorator. - .. versionchanged:: 3.4 - To detect calls to :meth:`register`, you can use the - :func:`get_cache_token` function. - You can also override this method in an abstract base class: .. method:: __subclasshook__(subclass) @@ -312,19 +308,6 @@ :func:`abstractmethod`, making this decorator redundant. -The :mod:`abc` module also provides the following functions: - -.. function:: get_cache_token() - - Returns the current abstract base class cache token. - - The token is an opaque integer identifying the current version of the - abstract base class cache for virtual subclasses. This number changes - with every call to :meth:`ABCMeta.register` on any ABC. - - .. versionadded:: 3.4 - - .. rubric:: Footnotes .. [#] C++ programmers should note that Python's virtual base class diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/aifc.rst --- a/Doc/library/aifc.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/aifc.rst Fri Feb 01 23:12:09 2013 +0100 @@ -96,9 +96,7 @@ .. method:: aifc.getparams() - Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth, - framerate, nframes, comptype, compname)``, equivalent to output of the - :meth:`get\*` methods. + Return a tuple consisting of all of the above values in the above order. .. method:: aifc.getmarkers() diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/argparse.rst --- a/Doc/library/argparse.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/argparse.rst Fri Feb 01 23:12:09 2013 +0100 @@ -137,136 +137,40 @@ argument_default=None, conflict_handler='error', \ add_help=True) - Create a new :class:`ArgumentParser` object. All parameters should be passed - as keyword arguments. Each parameter has its own more detailed description - below, but in short they are: + Create a new :class:`ArgumentParser` object. Each parameter has its own more + detailed description below, but in short they are: - * prog_ - The name of the program (default: ``sys.argv[0]``) + * description_ - Text to display before the argument help. - * usage_ - The string describing the program usage (default: generated from - arguments added to parser) + * epilog_ - Text to display after the argument help. - * description_ - Text to display before the argument help (default: none) + * add_help_ - Add a -h/--help option to the parser. (default: ``True``) - * epilog_ - Text to display after the argument help (default: none) + * argument_default_ - Set the global default value for arguments. + (default: ``None``) * parents_ - A list of :class:`ArgumentParser` objects whose arguments should - also be included + also be included. - * formatter_class_ - A class for customizing the help output - - * prefix_chars_ - The set of characters that prefix optional arguments + * prefix_chars_ - The set of characters that prefix optional arguments. (default: '-') * fromfile_prefix_chars_ - The set of characters that prefix files from - which additional arguments should be read (default: ``None``) + which additional arguments should be read. (default: ``None``) - * argument_default_ - The global default value for arguments - (default: ``None``) + * formatter_class_ - A class for customizing the help output. - * conflict_handler_ - The strategy for resolving conflicting optionals - (usually unnecessary) + * conflict_handler_ - Usually unnecessary, defines strategy for resolving + conflicting optionals. - * add_help_ - Add a -h/--help option to the parser (default: ``True``) + * prog_ - The name of the program (default: + ``sys.argv[0]``) + + * usage_ - The string describing the program usage (default: generated) The following sections describe how each of these are used. -prog -^^^^ - -By default, :class:`ArgumentParser` objects uses ``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 -``myprogram.py`` with the following code:: - - import argparse - parser = argparse.ArgumentParser() - parser.add_argument('--foo', help='foo help') - 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):: - - $ python myprogram.py --help - usage: myprogram.py [-h] [--foo FOO] - - optional arguments: - -h, --help show this help message and exit - --foo FOO foo help - $ cd .. - $ python subdir\myprogram.py --help - usage: myprogram.py [-h] [--foo FOO] - - optional arguments: - -h, --help show this help message and exit - --foo FOO foo help - -To change this default behavior, another value can be supplied using the -``prog=`` argument to :class:`ArgumentParser`:: - - >>> parser = argparse.ArgumentParser(prog='myprogram') - >>> parser.print_help() - usage: myprogram [-h] - - optional arguments: - -h, --help show this help message and exit - -Note that the program name, whether determined from ``sys.argv[0]`` or from the -``prog=`` argument, is available to help messages using the ``%(prog)s`` format -specifier. - -:: - - >>> parser = argparse.ArgumentParser(prog='myprogram') - >>> parser.add_argument('--foo', help='foo of the %(prog)s program') - >>> parser.print_help() - usage: myprogram [-h] [--foo FOO] - - optional arguments: - -h, --help show this help message and exit - --foo FOO foo of the myprogram program - - -usage -^^^^^ - -By default, :class:`ArgumentParser` calculates the usage message from the -arguments it contains:: - - >>> parser = argparse.ArgumentParser(prog='PROG') - >>> parser.add_argument('--foo', nargs='?', help='foo help') - >>> parser.add_argument('bar', nargs='+', help='bar help') - >>> parser.print_help() - usage: PROG [-h] [--foo [FOO]] bar [bar ...] - - positional arguments: - bar bar help - - optional arguments: - -h, --help show this help message and exit - --foo [FOO] foo help - -The default message can be overridden with the ``usage=`` keyword argument:: - - >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]') - >>> parser.add_argument('--foo', nargs='?', help='foo help') - >>> parser.add_argument('bar', nargs='+', help='bar help') - >>> parser.print_help() - usage: PROG [options] - - positional arguments: - bar bar help - - optional arguments: - -h, --help show this help message and exit - --foo [FOO] foo help - -The ``%(prog)s`` format specifier is available to fill in the program name in -your usage messages. - - description ^^^^^^^^^^^ @@ -314,6 +218,122 @@ argument to :class:`ArgumentParser`. +add_help +^^^^^^^^ + +By default, ArgumentParser objects add an option which simply displays +the parser's help message. For example, consider a file named +``myprogram.py`` containing the following code:: + + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('--foo', help='foo help') + args = parser.parse_args() + +If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser +help will be printed:: + + $ python myprogram.py --help + usage: myprogram.py [-h] [--foo FOO] + + optional arguments: + -h, --help show this help message and exit + --foo FOO foo help + +Occasionally, it may be useful to disable the addition of this help option. +This can be achieved by passing ``False`` as the ``add_help=`` argument to +:class:`ArgumentParser`:: + + >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False) + >>> parser.add_argument('--foo', help='foo help') + >>> parser.print_help() + usage: PROG [--foo FOO] + + optional arguments: + --foo FOO foo help + +The help option is typically ``-h/--help``. The exception to this is +if the ``prefix_chars=`` is specified and does not include ``-``, in +which case ``-h`` and ``--help`` are not valid options. In +this case, the first character in ``prefix_chars`` is used to prefix +the help options:: + + >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/') + >>> parser.print_help() + usage: PROG [+h] + + optional arguments: + +h, ++help show this help message and exit + + +prefix_chars +^^^^^^^^^^^^ + +Most command-line options will use ``-`` as the prefix, e.g. ``-f/--foo``. +Parsers that need to support different or additional prefix +characters, e.g. for options +like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument +to the ArgumentParser constructor:: + + >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+') + >>> parser.add_argument('+f') + >>> parser.add_argument('++bar') + >>> parser.parse_args('+f X ++bar Y'.split()) + Namespace(bar='Y', f='X') + +The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of +characters that does not include ``-`` will cause ``-f/--foo`` options to be +disallowed. + + +fromfile_prefix_chars +^^^^^^^^^^^^^^^^^^^^^ + +Sometimes, for example when dealing with a particularly long argument lists, it +may make sense to keep the list of arguments in a file rather than typing it out +at the command line. If the ``fromfile_prefix_chars=`` argument is given to the +:class:`ArgumentParser` constructor, then arguments that start with any of the +specified characters will be treated as files, and will be replaced by the +arguments they contain. For example:: + + >>> with open('args.txt', 'w') as fp: + ... fp.write('-f\nbar') + >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@') + >>> parser.add_argument('-f') + >>> parser.parse_args(['-f', 'foo', '@args.txt']) + Namespace(f='bar') + +Arguments read from a file must by default be one per line (but see also +:meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they +were in the same place as the original file referencing argument on the command +line. So in the example above, the expression ``['-f', 'foo', '@args.txt']`` +is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. + +The ``fromfile_prefix_chars=`` argument defaults to ``None``, meaning that +arguments will never be treated as file references. + + +argument_default +^^^^^^^^^^^^^^^^ + +Generally, argument defaults are specified either by passing a default to +:meth:`~ArgumentParser.add_argument` or by calling the +:meth:`~ArgumentParser.set_defaults` methods with a specific set of name-value +pairs. Sometimes however, it may be useful to specify a single parser-wide +default for arguments. This can be accomplished by passing the +``argument_default=`` keyword argument to :class:`ArgumentParser`. For example, +to globally suppress attribute creation on :meth:`~ArgumentParser.parse_args` +calls, we supply ``argument_default=SUPPRESS``:: + + >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) + >>> parser.add_argument('--foo') + >>> parser.add_argument('bar', nargs='?') + >>> parser.parse_args(['--foo', '1', 'BAR']) + Namespace(bar='BAR', foo='1') + >>> parser.parse_args([]) + Namespace() + + parents ^^^^^^^ @@ -451,74 +471,6 @@ --foo int -prefix_chars -^^^^^^^^^^^^ - -Most command-line options will use ``-`` as the prefix, e.g. ``-f/--foo``. -Parsers that need to support different or additional prefix -characters, e.g. for options -like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument -to the ArgumentParser constructor:: - - >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+') - >>> parser.add_argument('+f') - >>> parser.add_argument('++bar') - >>> parser.parse_args('+f X ++bar Y'.split()) - Namespace(bar='Y', f='X') - -The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of -characters that does not include ``-`` will cause ``-f/--foo`` options to be -disallowed. - - -fromfile_prefix_chars -^^^^^^^^^^^^^^^^^^^^^ - -Sometimes, for example when dealing with a particularly long argument lists, it -may make sense to keep the list of arguments in a file rather than typing it out -at the command line. If the ``fromfile_prefix_chars=`` argument is given to the -:class:`ArgumentParser` constructor, then arguments that start with any of the -specified characters will be treated as files, and will be replaced by the -arguments they contain. For example:: - - >>> with open('args.txt', 'w') as fp: - ... fp.write('-f\nbar') - >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@') - >>> parser.add_argument('-f') - >>> parser.parse_args(['-f', 'foo', '@args.txt']) - Namespace(f='bar') - -Arguments read from a file must by default be one per line (but see also -:meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they -were in the same place as the original file referencing argument on the command -line. So in the example above, the expression ``['-f', 'foo', '@args.txt']`` -is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. - -The ``fromfile_prefix_chars=`` argument defaults to ``None``, meaning that -arguments will never be treated as file references. - - -argument_default -^^^^^^^^^^^^^^^^ - -Generally, argument defaults are specified either by passing a default to -:meth:`~ArgumentParser.add_argument` or by calling the -:meth:`~ArgumentParser.set_defaults` methods with a specific set of name-value -pairs. Sometimes however, it may be useful to specify a single parser-wide -default for arguments. This can be accomplished by passing the -``argument_default=`` keyword argument to :class:`ArgumentParser`. For example, -to globally suppress attribute creation on :meth:`~ArgumentParser.parse_args` -calls, we supply ``argument_default=SUPPRESS``:: - - >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) - >>> parser.add_argument('--foo') - >>> parser.add_argument('bar', nargs='?') - >>> parser.parse_args(['--foo', '1', 'BAR']) - Namespace(bar='BAR', foo='1') - >>> parser.parse_args([]) - Namespace() - - conflict_handler ^^^^^^^^^^^^^^^^ @@ -556,20 +508,22 @@ string was overridden. -add_help -^^^^^^^^ +prog +^^^^ -By default, ArgumentParser objects add an option which simply displays -the parser's help message. For example, consider a file named -``myprogram.py`` containing the following code:: +By default, :class:`ArgumentParser` objects uses ``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 +``myprogram.py`` with the following code:: import argparse parser = argparse.ArgumentParser() parser.add_argument('--foo', help='foo help') args = parser.parse_args() -If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser -help will be printed:: +The help for this program will display ``myprogram.py`` as the program name +(regardless of where the program was invoked from):: $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] @@ -577,31 +531,76 @@ optional arguments: -h, --help show this help message and exit --foo FOO foo help - -Occasionally, it may be useful to disable the addition of this help option. -This can be achieved by passing ``False`` as the ``add_help=`` argument to -:class:`ArgumentParser`:: - - >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False) - >>> parser.add_argument('--foo', help='foo help') - >>> parser.print_help() - usage: PROG [--foo FOO] + $ cd .. + $ python subdir\myprogram.py --help + usage: myprogram.py [-h] [--foo FOO] optional arguments: - --foo FOO foo help + -h, --help show this help message and exit + --foo FOO foo help -The help option is typically ``-h/--help``. The exception to this is -if the ``prefix_chars=`` is specified and does not include ``-``, in -which case ``-h`` and ``--help`` are not valid options. In -this case, the first character in ``prefix_chars`` is used to prefix -the help options:: +To change this default behavior, another value can be supplied using the +``prog=`` argument to :class:`ArgumentParser`:: - >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/') + >>> parser = argparse.ArgumentParser(prog='myprogram') >>> parser.print_help() - usage: PROG [-h] + usage: myprogram [-h] optional arguments: - -h, --help show this help message and exit + -h, --help show this help message and exit + +Note that the program name, whether determined from ``sys.argv[0]`` or from the +``prog=`` argument, is available to help messages using the ``%(prog)s`` format +specifier. + +:: + + >>> parser = argparse.ArgumentParser(prog='myprogram') + >>> parser.add_argument('--foo', help='foo of the %(prog)s program') + >>> parser.print_help() + usage: myprogram [-h] [--foo FOO] + + optional arguments: + -h, --help show this help message and exit + --foo FOO foo of the myprogram program + + +usage +^^^^^ + +By default, :class:`ArgumentParser` calculates the usage message from the +arguments it contains:: + + >>> parser = argparse.ArgumentParser(prog='PROG') + >>> parser.add_argument('--foo', nargs='?', help='foo help') + >>> parser.add_argument('bar', nargs='+', help='bar help') + >>> parser.print_help() + usage: PROG [-h] [--foo [FOO]] bar [bar ...] + + positional arguments: + bar bar help + + optional arguments: + -h, --help show this help message and exit + --foo [FOO] foo help + +The default message can be overridden with the ``usage=`` keyword argument:: + + >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]') + >>> parser.add_argument('--foo', nargs='?', help='foo help') + >>> parser.add_argument('bar', nargs='+', help='bar help') + >>> parser.print_help() + usage: PROG [options] + + positional arguments: + bar bar help + + optional arguments: + -h, --help show this help message and exit + --foo [FOO] foo help + +The ``%(prog)s`` format specifier is available to fill in the program name in +your usage messages. The add_argument() method diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/array.rst --- a/Doc/library/array.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/array.rst Fri Feb 01 23:12:09 2013 +0100 @@ -73,8 +73,8 @@ .. class:: array(typecode[, initializer]) A new array whose items are restricted by *typecode*, and initialized - from the optional *initializer* value, which must be a list, a - :term:`bytes-like object`, or iterable over elements of the + from the optional *initializer* value, which must be a list, object + supporting the buffer interface, or iterable over elements of the appropriate type. If given a list or string, the initializer is passed to the new array's @@ -91,7 +91,7 @@ concatenation, and multiplication. When using slice assignment, the assigned value must be an array object with the same type code; in all other cases, :exc:`TypeError` is raised. Array objects also implement the buffer interface, -and may be used wherever :term:`bytes-like object`\ s are supported. +and may be used wherever buffer objects are supported. The following data items and methods are also supported: @@ -271,7 +271,9 @@ Packing and unpacking of External Data Representation (XDR) data as used in some remote procedure call systems. - `The Numerical Python Documentation `_ + `The Numerical Python Manual `_ The Numeric Python extension (NumPy) defines another array type; see - http://www.numpy.org/ for further information about Numerical Python. + http://numpy.sourceforge.net/ for further information about Numerical Python. + (A PDF version of the NumPy manual is available at + http://numpy.sourceforge.net/numdoc/numdoc.pdf). diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/asyncore.rst --- a/Doc/library/asyncore.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/asyncore.rst Fri Feb 01 23:12:09 2013 +0100 @@ -184,7 +184,7 @@ Most of these are nearly identical to their socket partners. - .. method:: create_socket(family=socket.AF_INET, type=socket.SOCK_STREAM) + .. method:: create_socket(family=socket.AF_INET, type=socket.SOCK_STREAM, cloexec=None) This is identical to the creation of a normal socket, and will use the same options for creation. Refer to the :mod:`socket` documentation for @@ -193,6 +193,9 @@ .. versionchanged:: 3.3 *family* and *type* arguments can be omitted. + .. versionchanged:: 3.4 + *cloexec* parameter was added. + .. method:: connect(address) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/atexit.rst --- a/Doc/library/atexit.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/atexit.rst Fri Feb 01 23:12:09 2013 +0100 @@ -68,7 +68,7 @@ making an explicit call into this module at termination. :: try: - with open("counterfile") as infile: + with open("/tmp/counter") as infile: _count = int(infile.read()) except FileNotFoundError: _count = 0 @@ -78,7 +78,7 @@ _count = _count + n def savecounter(): - with open("counterfile", "w") as outfile: + with open("/tmp/counter", "w") as outfile: outfile.write("%d" % _count) import atexit diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/audioop.rst --- a/Doc/library/audioop.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/audioop.rst Fri Feb 01 23:12:09 2013 +0100 @@ -36,7 +36,7 @@ Return a fragment which is the addition of the two samples passed as parameters. *width* is the sample width in bytes, either ``1``, ``2`` or ``4``. Both - fragments should have the same length. Samples are truncated in case of overflow. + fragments should have the same length. .. function:: adpcm2lin(adpcmfragment, width, state) @@ -67,7 +67,7 @@ .. function:: bias(fragment, width, bias) Return a fragment that is the original fragment with a bias added to each - sample. Samples wrap around in case of overflow. + sample. .. function:: cross(fragment, width) @@ -175,7 +175,7 @@ .. function:: mul(fragment, width, factor) Return a fragment that has all samples in the original fragment multiplied by - the floating-point value *factor*. Samples are truncated in case of overflow. + the floating-point value *factor*. Overflow is silently ignored. .. function:: ratecv(fragment, width, nchannels, inrate, outrate, state[, weightA[, weightB]]) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/base64.rst --- a/Doc/library/base64.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/base64.rst Fri Feb 01 23:12:09 2013 +0100 @@ -103,7 +103,7 @@ digit 0 is always mapped to the letter O). For security purposes the default is ``None``, so that 0 and 1 are not allowed in the input. - The decoded byte string is returned. A :exc:`binascii.Error` is raised if *s* were + The decoded byte string is returned. A :exc:`TypeError` is raised if *s* were incorrectly padded or if there are non-alphabet characters present in the string. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/binascii.rst --- a/Doc/library/binascii.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/binascii.rst Fri Feb 01 23:12:09 2013 +0100 @@ -21,9 +21,8 @@ .. note:: ``a2b_*`` functions accept Unicode strings containing only ASCII characters. - Other functions only accept :term:`bytes-like object`\ s (such as - :class:`bytes`, :class:`bytearray` and other objects that support the buffer - protocol). + Other functions only accept bytes and bytes-compatible objects (such as + bytearray objects and other objects implementing the buffer API). .. versionchanged:: 3.3 ASCII-only unicode strings are now accepted by the ``a2b_*`` functions. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/cgi.rst --- a/Doc/library/cgi.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/cgi.rst Fri Feb 01 23:12:09 2013 +0100 @@ -79,7 +79,7 @@ instead, with code like this:: import cgitb - cgitb.enable(display=0, logdir="/path/to/logdir") + cgitb.enable(display=0, logdir="/tmp") It's very helpful to use this feature during script development. The reports produced by :mod:`cgitb` provide information that can save you a lot of time in diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/codecs.rst --- a/Doc/library/codecs.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/codecs.rst Fri Feb 01 23:12:09 2013 +0100 @@ -78,11 +78,7 @@ reference (for encoding only) * ``'backslashreplace'``: replace with backslashed escape sequences (for encoding only) - * ``'surrogateescape'``: on decoding, replace with code points in the Unicode - Private Use Area ranging from U+DC80 to U+DCFF. These private code - points will then be turned back into the same bytes when the - ``surrogateescape`` error handler is used when encoding the data. - (See :pep:`383` for more.) + * ``'surrogateescape'``: replace with surrogate U+DCxx, see :pep:`383` as well as any other error handling name defined via :func:`register_error`. @@ -319,8 +315,6 @@ providing the *errors* string argument. The following string values are defined and implemented by all standard Python codecs: -.. tabularcolumns:: |l|L| - +-------------------------+-----------------------------------------------+ | Value | Meaning | +=========================+===============================================+ @@ -694,7 +688,7 @@ Read one line from the input stream and return the decoded data. *size*, if given, is passed as size argument to the stream's - :meth:`read` method. + :meth:`readline` method. If *keepends* is false line-endings will be stripped from the lines returned. @@ -932,8 +926,6 @@ * an IBM PC code page, which is ASCII compatible -.. tabularcolumns:: |l|p{0.3\linewidth}|p{0.3\linewidth}| - +-----------------+--------------------------------+--------------------------------+ | Codec | Aliases | Languages | +=================+================================+================================+ @@ -1146,21 +1138,7 @@ | utf_8_sig | | all languages | +-----------------+--------------------------------+--------------------------------+ -Python Specific Encodings -------------------------- - -A number of predefined codecs are specific to Python, so their codec names have -no meaning outside Python. These are listed in the tables below based on the -expected input and output types (note that while text encodings are the most -common use case for codecs, the underlying codec infrastructure supports -arbitrary data transforms rather than just text encodings). For asymmetric -codecs, the stated purpose describes the encoding direction. - -The following codecs provide :class:`str` to :class:`bytes` encoding and -:term:`bytes-like object` to :class:`str` decoding, similar to the Unicode text -encodings. - -.. tabularcolumns:: |l|p{0.3\linewidth}|p{0.3\linewidth}| +.. XXX fix here, should be in above table +--------------------+---------+---------------------------+ | Codec | Aliases | Purpose | @@ -1202,57 +1180,43 @@ | | | .. deprecated:: 3.3 | +--------------------+---------+---------------------------+ -The following codecs provide :term:`bytes-like object` to :class:`bytes` -mappings. +The following codecs provide bytes-to-bytes mappings. ++--------------------+---------------------------+---------------------------+ +| Codec | Aliases | Purpose | ++====================+===========================+===========================+ +| base64_codec | base64, base-64 | Convert operand to MIME | +| | | base64 | ++--------------------+---------------------------+---------------------------+ +| bz2_codec | bz2 | Compress the operand | +| | | using bz2 | ++--------------------+---------------------------+---------------------------+ +| hex_codec | hex | Convert operand to | +| | | hexadecimal | +| | | representation, with two | +| | | digits per byte | ++--------------------+---------------------------+---------------------------+ +| quopri_codec | quopri, quoted-printable, | Convert operand to MIME | +| | quotedprintable | quoted printable | ++--------------------+---------------------------+---------------------------+ +| uu_codec | uu | Convert the operand using | +| | | uuencode | ++--------------------+---------------------------+---------------------------+ +| zlib_codec | zip, zlib | Compress the operand | +| | | using gzip | ++--------------------+---------------------------+---------------------------+ -.. tabularcolumns:: |l|L|L| +The following codecs provide string-to-string mappings. -+----------------------+---------------------------+------------------------------+ -| Codec | Purpose | Encoder/decoder | -+======================+===========================+==============================+ -| base64_codec [#b64]_ | Convert operand to MIME | :meth:`base64.b64encode`, | -| | base64 (the result always | :meth:`base64.b64decode` | -| | includes a trailing | | -| | ``'\n'``) | | -+----------------------+---------------------------+------------------------------+ -| bz2_codec | Compress the operand | :meth:`bz2.compress`, | -| | using bz2 | :meth:`bz2.decompress` | -+----------------------+---------------------------+------------------------------+ -| hex_codec | Convert operand to | :meth:`base64.b16encode`, | -| | hexadecimal | :meth:`base64.b16decode` | -| | representation, with two | | -| | digits per byte | | -+----------------------+---------------------------+------------------------------+ -| quopri_codec | Convert operand to MIME | :meth:`quopri.encodestring`, | -| | quoted printable | :meth:`quopri.decodestring` | -+----------------------+---------------------------+------------------------------+ -| uu_codec | Convert the operand using | :meth:`uu.encode`, | -| | uuencode | :meth:`uu.decode` | -+----------------------+---------------------------+------------------------------+ -| zlib_codec | Compress the operand | :meth:`zlib.compress`, | -| | using gzip | :meth:`zlib.decompress` | -+----------------------+---------------------------+------------------------------+ - -.. [#b64] Rather than accepting any :term:`bytes-like object`, - ``'base64_codec'`` accepts only :class:`bytes` and :class:`bytearray` for - encoding and only :class:`bytes`, :class:`bytearray`, and ASCII-only - instances of :class:`str` for decoding - - -The following codecs provide :class:`str` to :class:`str` mappings. - -.. tabularcolumns:: |l|L| - -+--------------------+---------------------------+ -| Codec | Purpose | -+====================+===========================+ -| rot_13 | Returns the Caesar-cypher | -| | encryption of the operand | -+--------------------+---------------------------+ ++--------------------+---------------------------+---------------------------+ +| Codec | Aliases | Purpose | ++====================+===========================+===========================+ +| rot_13 | rot13 | Returns the Caesar-cypher | +| | | encryption of the operand | ++--------------------+---------------------------+---------------------------+ .. versionadded:: 3.2 - bytes-to-bytes and str-to-str codecs. + bytes-to-bytes and string-to-string codecs. :mod:`encodings.idna` --- Internationalized Domain Names in Applications diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/collections.abc.rst --- a/Doc/library/collections.abc.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/collections.abc.rst Fri Feb 01 23:12:09 2013 +0100 @@ -31,8 +31,6 @@ The collections module offers the following :term:`ABCs `: -.. tabularcolumns:: |l|L|L|L| - ========================= ===================== ====================== ==================================================== ABC Inherits from Abstract Methods Mixin Methods ========================= ===================== ====================== ==================================================== @@ -43,35 +41,29 @@ :class:`Sized` ``__len__`` :class:`Callable` ``__call__`` -:class:`Sequence` :class:`Sized`, ``__getitem__``, ``__contains__``, ``__iter__``, ``__reversed__``, - :class:`Iterable`, ``__len__`` ``index``, and ``count`` +:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``, ``__iter__``, ``__reversed__``, + :class:`Iterable`, ``index``, and ``count`` :class:`Container` -:class:`MutableSequence` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods and - ``__setitem__``, ``append``, ``reverse``, ``extend``, ``pop``, - ``__delitem__``, ``remove``, and ``__iadd__`` - ``__len__``, - ``insert`` +:class:`MutableSequence` :class:`Sequence` ``__setitem__``, Inherited :class:`Sequence` methods and + ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, + ``insert`` ``remove``, ``clear``, and ``__iadd__`` -:class:`Set` :class:`Sized`, ``__contains__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, - :class:`Iterable`, ``__iter__``, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``, - :class:`Container` ``__len__`` ``__sub__``, ``__xor__``, and ``isdisjoint`` +:class:`Set` :class:`Sized`, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, + :class:`Iterable`, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``, + :class:`Container` ``__sub__``, ``__xor__``, and ``isdisjoint`` -:class:`MutableSet` :class:`Set` ``__contains__``, Inherited :class:`Set` methods and - ``__iter__``, ``clear``, ``pop``, ``remove``, ``__ior__``, - ``__len__``, ``__iand__``, ``__ixor__``, and ``__isub__`` - ``add``, - ``discard`` +:class:`MutableSet` :class:`Set` ``add``, Inherited :class:`Set` methods and + ``discard`` ``clear``, ``pop``, ``remove``, ``__ior__``, + ``__iand__``, ``__ixor__``, and ``__isub__`` -:class:`Mapping` :class:`Sized`, ``__getitem__``, ``__contains__``, ``keys``, ``items``, ``values``, - :class:`Iterable`, ``__iter__``, ``get``, ``__eq__``, and ``__ne__`` - :class:`Container` ``__len__`` +:class:`Mapping` :class:`Sized`, ``__getitem__`` ``__contains__``, ``keys``, ``items``, ``values``, + :class:`Iterable`, ``get``, ``__eq__``, and ``__ne__`` + :class:`Container` -:class:`MutableMapping` :class:`Mapping` ``__getitem__``, Inherited :class:`Mapping` methods and - ``__setitem__``, ``pop``, ``popitem``, ``clear``, ``update``, - ``__delitem__``, and ``setdefault`` - ``__iter__``, - ``__len__`` +:class:`MutableMapping` :class:`Mapping` ``__setitem__``, Inherited :class:`Mapping` methods and + ``__delitem__`` ``pop``, ``popitem``, ``clear``, ``update``, + and ``setdefault`` :class:`MappingView` :class:`Sized` ``__len__`` @@ -128,7 +120,7 @@ particular functionality, for example:: size = None - if isinstance(myvar, collections.abc.Sized): + if isinstance(myvar, collections.Sized): size = len(myvar) Several of the ABCs are also useful as mixins that make it easier to develop @@ -136,9 +128,9 @@ the full :class:`Set` API, it only necessary to supply the three underlying abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`. The ABC supplies the remaining methods such as :meth:`__and__` and -:meth:`isdisjoint`:: +:meth:`isdisjoint` :: - class ListBasedSet(collections.abc.Set): + class ListBasedSet(collections.Set): ''' Alternate set implementation favoring space over speed and not requiring the set elements to be hashable. ''' def __init__(self, iterable): diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/collections.rst --- a/Doc/library/collections.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/collections.rst Fri Feb 01 23:12:09 2013 +0100 @@ -215,7 +215,7 @@ >>> # Find the ten most common words in Hamlet >>> import re - >>> words = re.findall(r'\w+', open('hamlet.txt').read().lower()) + >>> words = re.findall('\w+', open('hamlet.txt').read().lower()) >>> Counter(words).most_common(10) [('the', 1143), ('and', 966), ('to', 762), ('of', 669), ('i', 631), ('you', 554), ('a', 546), ('my', 514), ('hamlet', 471), ('in', 451)] diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/compileall.rst --- a/Doc/library/compileall.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/compileall.rst Fri Feb 01 23:12:09 2013 +0100 @@ -162,7 +162,7 @@ # Perform same compilation, excluding files in .svn directories. import re - compileall.compile_dir('Lib/', rx=re.compile(r'[/\\][.]svn'), force=True) + compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True) .. seealso:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/concurrency.rst --- a/Doc/library/concurrency.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/concurrency.rst Fri Feb 01 23:12:09 2013 +0100 @@ -8,7 +8,7 @@ execution of code. The appropriate choice of tool will depend on the task to be executed (CPU bound vs IO bound) and preferred style of development (event driven cooperative multitasking vs preemptive -multitasking). Here's an overview: +multitasking) Here's an overview: .. toctree:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/concurrent.futures.rst --- a/Doc/library/concurrent.futures.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/concurrent.futures.rst Fri Feb 01 23:12:09 2013 +0100 @@ -144,7 +144,7 @@ # We can use a with statement to ensure threads are cleaned up promptly with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: # Start the load operations and mark each future with its URL - future_to_url = {executor.submit(load_url, url, 60): url for url in URLS} + future_to_url = {executor.submit(load_url, url, 60):url for url in URLS} for future in concurrent.futures.as_completed(future_to_url): url = future_to_url[future] try: @@ -346,8 +346,6 @@ *return_when* indicates when this function should return. It must be one of the following constants: - .. tabularcolumns:: |l|L| - +-----------------------------+----------------------------------------+ | Constant | Description | +=============================+========================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/configparser.rst --- a/Doc/library/configparser.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/configparser.rst Fri Feb 01 23:12:09 2013 +0100 @@ -539,7 +539,7 @@ * *delimiters*, default value: ``('=', ':')`` Delimiters are substrings that delimit keys from values within a section. The - first occurrence of a delimiting substring on a line is considered a delimiter. + first occurence of a delimiting substring on a line is considered a delimiter. This means values (but not keys) can contain the delimiters. See also the *space_around_delimiters* argument to diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/contextlib.rst --- a/Doc/library/contextlib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/contextlib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -94,26 +94,6 @@ without needing to explicitly close ``page``. Even if an error occurs, ``page.close()`` will be called when the :keyword:`with` block is exited. -.. function:: ignored(*exceptions) - - Return a context manager that ignores the specified exceptions if they - occur in the body of a with-statement. - - For example:: - - from contextlib import ignored - - with ignored(OSError): - os.remove('somefile.tmp') - - This code is equivalent to:: - - try: - os.remove('somefile.tmp') - except OSError: - pass - - .. versionadded:: 3.4 .. class:: ContextDecorator() @@ -279,12 +259,11 @@ with ExitStack() as stack: files = [stack.enter_context(open(fname)) for fname in filenames] - # Hold onto the close method, but don't call it yet. close_files = stack.pop_all().close # If opening any file fails, all previously opened files will be # closed automatically. If all files are opened successfully, # they will remain open even after the with statement ends. - # close_files() can then be invoked explicitly to close them all. + # close_files() can then be invoked explicitly to close them all .. method:: close() @@ -382,7 +361,7 @@ from contextlib import contextmanager, ExitStack - class ResourceManager: + class ResourceManager(object): def __init__(self, acquire_resource, release_resource, check_resource_ok=None): self.acquire_resource = acquire_resource diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/ctypes.rst Fri Feb 01 23:12:09 2013 +0100 @@ -574,8 +574,8 @@ ValueError: too many initializers >>> -You can, however, build much more complicated structures. A structure can -itself contain other structures by using a structure as a field type. +You can, however, build much more complicated structures. Structures can itself +contain other structures by using a structure as a field type. Here is a RECT structure which contains two POINTs named *upperleft* and *lowerright*:: @@ -608,13 +608,6 @@ .. _ctypes-structureunion-alignment-byte-order: -.. warning:: - - :mod:`ctypes` does not support passing unions or structures with bit-fields - to functions by value. While this may work on 32-bit x86, it's not - guaranteed by the library to work in the general case. Unions and - structures with bit-fields should always be passed to functions by pointer. - Structure/union alignment and byte order ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -829,11 +822,6 @@ 3 >>> -In addition, if a function argument is explicitly declared to be a pointer type -(such as ``POINTER(c_int)``) in :attr:`argtypes`, an object of the pointed -type (``c_int`` in this case) can be passed to the function. ctypes will apply -the required :func:`byref` conversion in this case automatically. - To set a POINTER type field to ``NULL``, you can assign ``None``:: >>> bar.values = None @@ -1274,7 +1262,7 @@ like ``find_library("c")`` will fail and return ``None``. If wrapping a shared library with :mod:`ctypes`, it *may* be better to determine -the shared library name at development time, and hardcode that into the wrapper +the shared library name at development type, and hardcode that into the wrapper module instead of using :func:`find_library` to locate the library at runtime. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/curses.rst --- a/Doc/library/curses.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/curses.rst Fri Feb 01 23:12:09 2013 +0100 @@ -45,7 +45,7 @@ Tutorial material on using curses with Python, by Andrew Kuchling and Eric Raymond. - The :source:`Tools/demo/` directory in the Python source distribution contains + The :file:`Tools/demo/` directory in the Python source distribution contains some example programs using the curses bindings provided by this module. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/datatypes.rst --- a/Doc/library/datatypes.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/datatypes.rst Fri Feb 01 23:12:09 2013 +0100 @@ -30,4 +30,3 @@ copy.rst pprint.rst reprlib.rst - enum.rst diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/datetime.rst --- a/Doc/library/datetime.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/datetime.rst Fri Feb 01 23:12:09 2013 +0100 @@ -597,13 +597,6 @@ section :ref:`strftime-strptime-behavior`. -.. method:: date.__format__(format) - - Same as :meth:`.date.strftime`. This makes it possible to specify format - string for a :class:`.date` object when using :meth:`str.format`. - See section :ref:`strftime-strptime-behavior`. - - Example of counting days to an event:: >>> import time @@ -654,8 +647,6 @@ '11/03/02' >>> d.strftime("%A %d. %B %Y") 'Monday 11. March 2002' - >>> 'The {1} is {0:%d}, the {2} is {0:%B}.'.format(d, "day", "month") - 'The day is 11, the month is March.' .. _datetime-datetime: @@ -1163,13 +1154,6 @@ string. See section :ref:`strftime-strptime-behavior`. -.. method:: datetime.__format__(format) - - Same as :meth:`.datetime.strftime`. This makes it possible to specify format - string for a :class:`.datetime` object when using :meth:`str.format`. - See section :ref:`strftime-strptime-behavior`. - - Examples of working with datetime objects: .. doctest:: @@ -1214,8 +1198,6 @@ >>> # Formatting datetime >>> dt.strftime("%A, %d. %B %Y %I:%M%p") 'Tuesday, 21. November 2006 04:30PM' - >>> 'The {1} is {0:%d}, the {2} is {0:%B}, the {3} is {0:%I:%M%p}.'.format(dt, "day", "month", "time") - 'The day is 21, the month is November, the time is 04:30PM.' Using datetime with tzinfo: @@ -1403,13 +1385,6 @@ See section :ref:`strftime-strptime-behavior`. -.. method:: time.__format__(format) - - Same as :meth:`.time.strftime`. This makes it possible to specify format string - for a :class:`.time` object when using :meth:`str.format`. - See section :ref:`strftime-strptime-behavior`. - - .. method:: time.utcoffset() If :attr:`tzinfo` is ``None``, returns ``None``, else returns @@ -1456,8 +1431,6 @@ 'Europe/Prague' >>> t.strftime("%H:%M:%S %Z") '12:10:30 Europe/Prague' - >>> 'The {} is {:%H:%M}.'.format("time", t) - 'The time is 12:10.' .. _datetime-tzinfo: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/dis.rst --- a/Doc/library/dis.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/dis.rst Fri Feb 01 23:12:09 2013 +0100 @@ -26,8 +26,7 @@ def myfunc(alist): return len(alist) -the following command can be used to display the disassembly of -:func:`myfunc`:: +the following command can be used to get the disassembly of :func:`myfunc`:: >>> dis.dis(myfunc) 2 0 LOAD_GLOBAL 0 (len) @@ -37,62 +36,8 @@ (The "2" is a line number). -Bytecode analysis ------------------ +The :mod:`dis` module defines the following functions and constants: -The bytecode analysis API allows pieces of Python code to be wrapped in a -:class:`Bytecode` object that provides easy access to details of the -compiled code. - -.. class:: Bytecode - - The bytecode operations of a piece of code - - This is a convenient wrapper around many of the functions listed below. - Instantiate it with a function, method, string of code, or a code object - (as returned by :func:`compile`). - - Iterating over this yields the bytecode operations as :class:`Instruction` - instances. - - .. data:: codeobj - - The compiled code object. - - .. method:: display_code(*, file=None) - - Print a formatted view of the bytecode operations, like :func:`dis`. - - .. method:: info() - - Return a formatted multi-line string with detailed information about the - code object, like :func:`code_info`. - - .. method:: show_info(*, file=None) - - Print the information about the code object as returned by :meth:`info`. - - .. versionadded:: 3.4 - -Example:: - - >>> bytecode = dis.Bytecode(myfunc) - >>> for instr in bytecode: - ... print(instr.opname) - ... - LOAD_GLOBAL - LOAD_FAST - CALL_FUNCTION - RETURN_VALUE - - -Analysis functions ------------------- - -The :mod:`dis` module also defines the following analysis functions that -convert the input directly to the desired output. They can be useful if -only a single operation is being performed, so the intermediate analysis -object isn't useful: .. function:: code_info(x) @@ -106,21 +51,17 @@ .. versionadded:: 3.2 -.. function:: show_code(x, *, file=None) +.. function:: show_code(x) Print detailed code object information for the supplied function, method, source code string or code object to stdout. - This is a convenient shorthand for ``print(code_info(x), file=file)``, - intended for interactive exploration at the interpreter prompt. + This is a convenient shorthand for ``print(code_info(x))``, intended for + interactive exploration at the interpreter prompt. .. versionadded:: 3.2 - .. versionchanged:: 3.4 - Added ``file`` parameter - - -.. function:: dis(x=None, *, file=None) +.. function:: dis(x=None) Disassemble the *x* object. *x* can denote either a module, a class, a method, a function, a code object, a string of source code or a byte sequence @@ -131,28 +72,16 @@ disassembled. If no object is provided, this function disassembles the last traceback. - The disassembly is written as text to the supplied ``file`` argument if - provided and to ``sys.stdout`` otherwise. - .. versionchanged:: 3.4 - Added ``file`` parameter - - -.. function:: distb(tb=None, *, file=None) +.. function:: distb(tb=None) Disassemble the top-of-stack function of a traceback, using the last traceback if none was passed. The instruction causing the exception is indicated. - The disassembly is written as text to the supplied ``file`` argument if - provided and to ``sys.stdout`` otherwise. - .. versionchanged:: 3.4 - Added ``file`` parameter - - -.. function:: disassemble(code, lasti=-1, *, file=None) - disco(code, lasti=-1, *, file=None) +.. function:: disassemble(code, lasti=-1) + disco(code, lasti=-1) Disassemble a code object, indicating the last instruction if *lasti* was provided. The output is divided in the following columns: @@ -168,26 +97,6 @@ The parameter interpretation recognizes local and global variable names, constant values, branch targets, and compare operators. - The disassembly is written as text to the supplied ``file`` argument if - provided and to ``sys.stdout`` otherwise. - - .. versionchanged:: 3.4 - Added ``file`` parameter - - -.. function:: get_instructions(x, *, line_offset=0) - - Return an iterator over the instructions in the supplied function, method, - source code string or code object. - - The iterator generates a series of :class:`Instruction` named tuples - giving the details of each operation in the supplied code. - - The given *line_offset* is added to the ``starts_line`` attribute of any - instructions that start a new line. - - .. versionadded:: 3.4 - .. function:: findlinestarts(code) @@ -201,61 +110,62 @@ Detect all offsets in the code object *code* which are jump targets, and return a list of these offsets. + +.. data:: opname + + Sequence of operation names, indexable using the bytecode. + + +.. data:: opmap + + Dictionary mapping operation names to bytecodes. + + +.. data:: cmp_op + + Sequence of all compare operation names. + + +.. data:: hasconst + + Sequence of bytecodes that have a constant parameter. + + +.. data:: hasfree + + Sequence of bytecodes that access a free variable. + + +.. data:: hasname + + Sequence of bytecodes that access an attribute by name. + + +.. data:: hasjrel + + Sequence of bytecodes that have a relative jump target. + + +.. data:: hasjabs + + Sequence of bytecodes that have an absolute jump target. + + +.. data:: haslocal + + Sequence of bytecodes that access a local variable. + + +.. data:: hascompare + + Sequence of bytecodes of Boolean operations. + + .. _bytecodes: Python Bytecode Instructions ---------------------------- -The :func:`get_instructions` function and :class:`Bytecode` class provide -details of bytecode instructions as :class:`Instruction` instances: - -.. class:: Instruction - - Details for a bytecode operation - - .. data:: opcode - - numeric code for operation, corresponding to the opcode values listed - below and the bytecode values in the :ref:`opcode_collections`. - - - .. data:: opname - - human readable name for operation - - - .. data:: arg - - numeric argument to operation (if any), otherwise None - - - .. data:: argval - - resolved arg value (if known), otherwise same as arg - - - .. data:: argrepr - - human readable description of operation argument - - - .. data:: offset - - start index of operation within bytecode sequence - - - .. data:: starts_line - - line started by this opcode (if any), otherwise None - - - .. data:: is_jump_target - - True if other code jumps to here, otherwise False - - .. versionadded:: 3.4 - - The Python compiler currently generates the following bytecode instructions. @@ -596,6 +506,12 @@ .. XXX explain the WHY stuff! +.. opcode:: STORE_LOCALS + + Pops TOS from the stack and stores it as the current frame's ``f_locals``. + This is used in class construction. + + All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last. @@ -806,13 +722,6 @@ Pushes a reference to the object the cell contains on the stack. -.. opcode:: LOAD_CLASSDEREF (i) - - Much like :opcode:`LOAD_DEREF` but first checks the locals dictionary before - consulting the cell. This is used for loading free variables in class - bodies. - - .. opcode:: STORE_DEREF (i) Stores TOS into the cell contained in slot *i* of the cell and free variable @@ -904,62 +813,3 @@ which don't take arguments ``< HAVE_ARGUMENT`` and those which do ``>= HAVE_ARGUMENT``. -.. _opcode_collections: - -Opcode collections ------------------- - -These collections are provided for automatic introspection of bytecode -instructions: - -.. data:: opname - - Sequence of operation names, indexable using the bytecode. - - -.. data:: opmap - - Dictionary mapping operation names to bytecodes. - - -.. data:: cmp_op - - Sequence of all compare operation names. - - -.. data:: hasconst - - Sequence of bytecodes that have a constant parameter. - - -.. data:: hasfree - - Sequence of bytecodes that access a free variable (note that 'free' in - this context refers to names in the current scope that are referenced by - inner scopes or names in outer scopes that are referenced from this scope. - It does *not* include references to global or builtin scopes). - - -.. data:: hasname - - Sequence of bytecodes that access an attribute by name. - - -.. data:: hasjrel - - Sequence of bytecodes that have a relative jump target. - - -.. data:: hasjabs - - Sequence of bytecodes that have an absolute jump target. - - -.. data:: haslocal - - Sequence of bytecodes that access a local variable. - - -.. data:: hascompare - - Sequence of bytecodes of Boolean operations. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/doctest.rst --- a/Doc/library/doctest.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/doctest.rst Fri Feb 01 23:12:09 2013 +0100 @@ -495,10 +495,7 @@ A number of option flags control various aspects of doctest's behavior. Symbolic names for the flags are supplied as module constants, which can be or'ed together and passed to various functions. The names can also be used in -:ref:`doctest directives `, and may be passed to the -doctest command line interface via the ``-o`` option. - -.. versionadded:: 3.4 the ``-o`` command line option +:ref:`doctest directives `. The first group of options define test semantics, controlling aspects of how doctest decides whether actual output matches an example's expected output: @@ -643,9 +640,6 @@ 1. This flag may be useful during debugging, since examples after the first failure won't even produce debugging output. - The doctest command line accepts the option ``-f`` as a shorthand for ``-o - FAIL_FAST``. - .. versionadded:: 3.4 diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/email.mime.rst --- a/Doc/library/email.mime.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/email.mime.rst Fri Feb 01 23:12:09 2013 +0100 @@ -116,7 +116,7 @@ this data can be decoded by the standard Python module :mod:`sndhdr`, then the subtype will be automatically included in the :mailheader:`Content-Type` header. Otherwise you can explicitly specify the audio subtype via the *_subtype* - argument. If the minor type could not be guessed and *_subtype* was not given, + parameter. If the minor type could not be guessed and *_subtype* was not given, then :exc:`TypeError` is raised. Optional *_encoder* is a callable (i.e. function) which will perform the actual @@ -142,7 +142,7 @@ this data can be decoded by the standard Python module :mod:`imghdr`, then the subtype will be automatically included in the :mailheader:`Content-Type` header. Otherwise you can explicitly specify the image subtype via the *_subtype* - argument. If the minor type could not be guessed and *_subtype* was not given, + parameter. If the minor type could not be guessed and *_subtype* was not given, then :exc:`TypeError` is raised. Optional *_encoder* is a callable (i.e. function) which will perform the actual @@ -183,17 +183,7 @@ :class:`MIMEText` class is used to create MIME objects of major type :mimetype:`text`. *_text* is the string for the payload. *_subtype* is the minor type and defaults to :mimetype:`plain`. *_charset* is the character - set of the text and is passed as an argument to the + set of the text and is passed as a parameter to the :class:`~email.mime.nonmultipart.MIMENonMultipart` constructor; it defaults to ``us-ascii`` if the string contains only ``ascii`` codepoints, and ``utf-8`` otherwise. - - Unless the *_charset* argument is explicitly set to ``None``, the - MIMEText object created will have both a :mailheader:`Content-Type` header - with a ``charset`` parameter, and a :mailheader:`Content-Transfer-Endcoding` - header. This means that a subsequent ``set_payload`` call will not result - in an encoded payload, even if a charset is passed in the ``set_payload`` - command. You can "reset" this behavior by deleting the - ``Content-Transfer-Encoding`` header, after which a ``set_payload`` call - will automatically encode the new payload (and add a new - :mailheader:`Content-Transfer-Encoding` header). diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/email.policy.rst --- a/Doc/library/email.policy.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/email.policy.rst Fri Feb 01 23:12:09 2013 +0100 @@ -139,8 +139,6 @@ Controls the type of Content Transfer Encodings that may be or are required to be used. The possible values are: - .. tabularcolumns:: |l|L| - ======== =============================================================== ``7bit`` all data must be "7 bit clean" (ASCII-only). This means that where necessary data will be encoded using either @@ -329,7 +327,7 @@ each resulting line to the ``max_line_length``. If ``cte_type`` is ``7bit``, non-ascii binary data is CTE encoded using the ``unknown-8bit`` charset. Otherwise the original source header is used, with its existing - line breaks and any (RFC invalid) binary data it may contain. + line breaks and and any (RFC invalid) binary data it may contain. .. note:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/enum.rst --- a/Doc/library/enum.rst Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,593 +0,0 @@ -:mod:`enum` --- Support for enumerations -======================================== - -.. module:: enum - :synopsis: Implementation of an enumeration class. - -.. :moduleauthor:: Ethan Furman -.. :sectionauthor:: Barry Warsaw , -.. :sectionauthor:: Eli Bendersky , -.. :sectionauthor:: Ethan Furman - -**Source code:** :source:`Lib/enum.py` - ----------------- - -An enumeration is a set of symbolic names (members) bound to unique, constant -values. Within an enumeration, the members can be compared by identity, and -the enumeration itself can be iterated over. - -This module defines two enumeration classes that can be used to define unique -sets of names and values: :class:`Enum` and :class:`IntEnum`. It also defines -one decorator, :func:`unique`, that ensures only unique member values are -present in an enumeration. - - -Creating an Enum ----------------- - -Enumerations are created using the :keyword:`class` syntax, which makes them -easy to read and write. An alternative creation method is described in -`Functional API`_. To define an enumeration, subclass :class:`Enum` as -follows:: - - >>> from enum import Enum - >>> class Color(Enum): - ... red = 1 - ... green = 2 - ... blue = 3 - -**A note on nomenclature**: we call :class:`Color` an *enumeration* (or *enum*) -and :attr:`Color.red`, :attr:`Color.green` are *enumeration members* (or -*enum members*). Enumeration members also have *values* (the value of -:attr:`Color.red` is ``1``, etc.) - -Enumeration members have human readable string representations:: - - >>> print(Color.red) - Color.red - -...while their ``repr`` has more information:: - - >>> print(repr(Color.red)) - - -The *type* of an enumeration member is the enumeration it belongs to:: - - >>> type(Color.red) - - >>> isinstance(Color.green, Color) - True - >>> - -Enum members also have a property that contains just their item name:: - - >>> print(Color.red.name) - red - -Enumerations support iteration, in definition order:: - - >>> class Shake(Enum): - ... vanilla = 7 - ... chocolate = 4 - ... cookies = 9 - ... mint = 3 - ... - >>> for shake in Shake: - ... print(shake) - ... - Shake.vanilla - Shake.chocolate - Shake.cookies - Shake.mint - -Enumeration members are hashable, so they can be used in dictionaries and sets:: - - >>> apples = {} - >>> apples[Color.red] = 'red delicious' - >>> apples[Color.green] = 'granny smith' - >>> apples == {Color.red: 'red delicious', Color.green: 'granny smith'} - True - - -Programmatic access to enumeration members and their attributes ---------------------------------------------------------------- - -Sometimes it's useful to access members in enumerations programmatically (i.e. -situations where ``Color.red`` won't do because the exact color is not known -at program-writing time). ``Enum`` allows such access:: - - >>> Color(1) - - >>> Color(3) - - -If you want to access enum members by *name*, use item access:: - - >>> Color['red'] - - >>> Color['green'] - - -If have an enum member and need its :attr:`name` or :attr:`value`:: - - >>> member = Color.red - >>> member.name - 'red' - >>> member.value - 1 - - -Duplicating enum members and values ------------------------------------ - -Having two enum members with the same name is invalid:: - - >>> class Shape(Enum): - ... square = 2 - ... square = 3 - ... - Traceback (most recent call last): - ... - TypeError: Attempted to reuse key: 'square' - -However, two enum members are allowed to have the same value. Given two members -A and B with the same value (and A defined first), B is an alias to A. By-value -lookup of the value of A and B will return A. By-name lookup of B will also -return A:: - - >>> class Shape(Enum): - ... square = 2 - ... diamond = 1 - ... circle = 3 - ... alias_for_square = 2 - ... - >>> Shape.square - - >>> Shape.alias_for_square - - >>> Shape(2) - - - -Ensuring unique enumeration values -================================== - -By default, enumerations allow multiple names as aliases for the same value. -When this behavior isn't desired, the following decorator can be used to -ensure each value is used only once in the enumeration: - -.. decorator:: unique - -A :keyword:`class` decorator specifically for enumerations. It searches an -enumeration's :attr:`__members__` gathering any aliases it finds; if any are -found :exc:`ValueError` is raised with the details:: - - >>> from enum import Enum, unique - >>> @unique - ... class Mistake(Enum): - ... one = 1 - ... two = 2 - ... three = 3 - ... four = 3 - Traceback (most recent call last): - ... - ValueError: duplicate values found in : four -> three - - -Iteration -========= - -Iterating over the members of an enum does not provide the aliases:: - - >>> list(Shape) - [, , ] - -The special attribute ``__members__`` is an ordered dictionary mapping names -to members. It includes all names defined in the enumeration, including the -aliases:: - - >>> for name, member in Shape.__members__.items(): - ... name, member - ... - ('square', ) - ('diamond', ) - ('circle', ) - ('alias_for_square', ) - -The ``__members__`` attribute can be used for detailed programmatic access to -the enumeration members. For example, finding all the aliases:: - - >>> [name for name, member in Shape.__members__.items() if member.name != name] - ['alias_for_square'] - - -Comparisons ------------ - -Enumeration members are compared by identity:: - - >>> Color.red is Color.red - True - >>> Color.red is Color.blue - False - >>> Color.red is not Color.blue - True - -Ordered comparisons between enumeration values are *not* supported. Enum -members are not integers (but see `IntEnum`_ below):: - - >>> Color.red < Color.blue - Traceback (most recent call last): - File "", line 1, in - TypeError: unorderable types: Color() < Color() - -Equality comparisons are defined though:: - - >>> Color.blue == Color.red - False - >>> Color.blue != Color.red - True - >>> Color.blue == Color.blue - True - -Comparisons against non-enumeration values will always compare not equal -(again, class:`IntEnum` was explicitly designed to behave differently, see -below):: - - >>> Color.blue == 2 - False - - -Allowed members and attributes of enumerations ----------------------------------------------- - -The examples above use integers for enumeration values. Using integers is -short and handy (and provided by default by the `Functional API`_), but not -strictly enforced. In the vast majority of use-cases, one doesn't care what -the actual value of an enumeration is. But if the value *is* important, -enumerations can have arbitrary values. - -Enumerations are Python classes, and can have methods and special methods as -usual. If we have this enumeration:: - - >>> class Mood(Enum): - ... funky = 1 - ... happy = 3 - ... - ... def describe(self): - ... # self is the member here - ... return self.name, self.value - ... - ... def __str__(self): - ... return 'my custom str! {0}'.format(self.value) - ... - ... @classmethod - ... def favorite_mood(cls): - ... # cls here is the enumeration - ... return cls.happy - -Then:: - - >>> Mood.favorite_mood() - - >>> Mood.happy.describe() - ('happy', 3) - >>> str(Mood.funky) - 'my custom str! 1' - -The rules for what is allowed are as follows: _sunder_ names (starting and -ending with a single underscore) are reserved by enum and cannot be used; -all other attributes defined within an enumeration will become members of this -enumeration, with the exception of *__dunder__* names and descriptors (methods -are also descriptors). - -Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__` then -whatever value(s) were given to the enum member will be passed into those -methods. See `Planet`_ for an example. - - -Restricted subclassing of enumerations --------------------------------------- - -Subclassing an enumeration is allowed only if the enumeration does not define -any members. So this is forbidden:: - - >>> class MoreColor(Color): - ... pink = 17 - Traceback (most recent call last): - ... - TypeError: Cannot extend enumerations - -But this is allowed:: - - >>> class Foo(Enum): - ... def some_behavior(self): - ... pass - ... - >>> class Bar(Foo): - ... happy = 1 - ... sad = 2 - ... - -Allowing subclassing of enums that define members would lead to a violation of -some important invariants of types and instances. On the other hand, it makes -sense to allow sharing some common behavior between a group of enumerations. -(See `OrderedEnum`_ for an example.) - - -Pickling --------- - -Enumerations can be pickled and unpickled:: - - >>> from test.test_enum import Fruit - >>> from pickle import dumps, loads - >>> Fruit.tomato is loads(dumps(Fruit.tomato)) - True - -The usual restrictions for pickling apply: picklable enums must be defined in -the top level of a module, since unpickling requires them to be importable -from that module. - -.. warning:: - - In order to support the singleton nature of enumeration members, pickle - protocol version 2 or higher must be used. - - -Functional API --------------- - -The :class:`Enum` class is callable, providing the following functional API:: - - >>> Animal = Enum('Animal', 'ant bee cat dog') - >>> Animal - - >>> Animal.ant - - >>> Animal.ant.value - 1 - >>> list(Animal) - [, , , ] - -The semantics of this API resemble :class:`namedtuple`. The first argument -of the call to :class:`Enum` is the name of the enumeration. - -The second argument is the *source* of enumeration member names. It can be a -whitespace-separated string of names, a sequence of names, a sequence of -2-tuples with key/value pairs, or a mapping (e.g. dictionary) of names to -values. The last two options enable assigning arbitrary values to -enumerations; the others auto-assign increasing integers starting with 1. A -new class derived from :class:`Enum` is returned. In other words, the above -assignment to :class:`Animal` is equivalent to:: - - >>> class Animals(Enum): - ... ant = 1 - ... bee = 2 - ... cat = 3 - ... dog = 4 - -The reason for defaulting to ``1`` as the starting number and not ``0`` is -that ``0`` is ``False`` in a boolean sense, but enum members all evaluate -to ``True``. - -Pickling enums created with the functional API can be tricky as frame stack -implementation details are used to try and figure out which module the -enumeration is being created in (e.g. it will fail if you use a utility -function in separate module, and also may not work on IronPython or Jython). -The solution is to specify the module name explicitly as follows:: - - >>> Animals = Enum('Animals', 'ant bee cat dog', module=__name__) - -Derived Enumerations -==================== - -IntEnum -------- - -A variation of :class:`Enum` is provided which is also a subclass of -:class:`int`. Members of an :class:`IntEnum` can be compared to integers; -by extension, integer enumerations of different types can also be compared -to each other:: - - >>> from enum import IntEnum - >>> class Shape(IntEnum): - ... circle = 1 - ... square = 2 - ... - >>> class Request(IntEnum): - ... post = 1 - ... get = 2 - ... - >>> Shape == 1 - False - >>> Shape.circle == 1 - True - >>> Shape.circle == Request.post - True - -However, they still can't be compared to standard :class:`Enum` enumerations:: - - >>> class Shape(IntEnum): - ... circle = 1 - ... square = 2 - ... - >>> class Color(Enum): - ... red = 1 - ... green = 2 - ... - >>> Shape.circle == Color.red - False - -:class:`IntEnum` values behave like integers in other ways you'd expect:: - - >>> int(Shape.circle) - 1 - >>> ['a', 'b', 'c'][Shape.circle] - 'b' - >>> [i for i in range(Shape.square)] - [0, 1] - -For the vast majority of code, :class:`Enum` is strongly recommended, -since :class:`IntEnum` breaks some semantic promises of an enumeration (by -being comparable to integers, and thus by transitivity to other -unrelated enumerations). It should be used only in special cases where -there's no other choice; for example, when integer constants are -replaced with enumerations and backwards compatibility is required with code -that still expects integers. - - -Others ------- - -While :class:`IntEnum` is part of the :mod:`enum` module, it would be very -simple to implement independently:: - - class IntEnum(int, Enum): - pass - -This demonstrates how similar derived enumerations can be defined; for example -a :class:`StrEnum` that mixes in :class:`str` instead of :class:`int`. - -Some rules: - -1. When subclassing :class:`Enum`, mix-in types must appear before - :class:`Enum` itself in the sequence of bases, as in the :class:`IntEnum` - example above. -2. While :class:`Enum` can have members of any type, once you mix in an - additional type, all the members must have values of that type, e.g. - :class:`int` above. This restriction does not apply to mix-ins which only - add methods and don't specify another data type such as :class:`int` or - :class:`str`. -3. When another data type is mixed in, the :attr:`value` attribute is *not the - same* as the enum member itself, although it is equivalant and will compare - equal. - - -Interesting examples -==================== - -While :class:`Enum` and :class:`IntEnum` are expected to cover the majority of -use-cases, they cannot cover them all. Here are recipes for some different -types of enumerations that can be used directly, or as examples for creating -one's own. - - -AutoNumber ----------- - -Avoids having to specify the value for each enumeration member:: - - >>> class AutoNumber(Enum): - ... def __new__(cls): - ... value = len(cls.__members__) + 1 - ... obj = object.__new__(cls) - ... obj._value = value - ... return obj - ... - >>> class Color(AutoNumber): - ... red = () - ... green = () - ... blue = () - ... - >>> Color.green.value == 2 - True - - -OrderedEnum ------------ - -An ordered enumeration that is not based on :class:`IntEnum` and so maintains -the normal :class:`Enum` invariants (such as not being comparable to other -enumerations):: - - >>> class OrderedEnum(Enum): - ... def __ge__(self, other): - ... if self.__class__ is other.__class__: - ... return self._value >= other._value - ... return NotImplemented - ... def __gt__(self, other): - ... if self.__class__ is other.__class__: - ... return self._value > other._value - ... return NotImplemented - ... def __le__(self, other): - ... if self.__class__ is other.__class__: - ... return self._value <= other._value - ... return NotImplemented - ... def __lt__(self, other): - ... if self.__class__ is other.__class__: - ... return self._value < other._value - ... return NotImplemented - ... - >>> class Grade(OrderedEnum): - ... A = 5 - ... B = 4 - ... C = 3 - ... D = 2 - ... F = 1 - ... - >>> Grade.C < Grade.A - True - - -DuplicateFreeEnum ------------------ - -Raises an error if a duplicate member name is found instead of creating an -alias:: - - >>> class DuplicateFreeEnum(Enum): - ... def __init__(self, *args): - ... cls = self.__class__ - ... if any(self.value == e.value for e in cls): - ... a = self.name - ... e = cls(self.value).name - ... raise ValueError( - ... "aliases not allowed in DuplicateFreeEnum: %r --> %r" - ... % (a, e)) - ... - >>> class Color(DuplicateFreeEnum): - ... red = 1 - ... green = 2 - ... blue = 3 - ... grene = 2 - Traceback (most recent call last): - ... - ValueError: aliases not allowed in DuplicateFreeEnum: 'grene' --> 'green' - -.. note:: - - This is a useful example for subclassing Enum to add or change other - behaviors as well as disallowing aliases. If the only change desired is - no aliases allowed the :func:`unique` decorator can be used instead. - - -Planet ------- - -If :meth:`__new__` or :meth:`__init__` is defined the value of the enum member -will be passed to those methods:: - - >>> class Planet(Enum): - ... MERCURY = (3.303e+23, 2.4397e6) - ... VENUS = (4.869e+24, 6.0518e6) - ... EARTH = (5.976e+24, 6.37814e6) - ... MARS = (6.421e+23, 3.3972e6) - ... JUPITER = (1.9e+27, 7.1492e7) - ... SATURN = (5.688e+26, 6.0268e7) - ... URANUS = (8.686e+25, 2.5559e7) - ... NEPTUNE = (1.024e+26, 2.4746e7) - ... def __init__(self, mass, radius): - ... self.mass = mass # in kilograms - ... self.radius = radius # in meters - ... @property - ... def surface_gravity(self): - ... # universal gravitational constant (m3 kg-1 s-2) - ... G = 6.67300E-11 - ... return G * self.mass / (self.radius * self.radius) - ... - >>> Planet.EARTH.value - (5.976e+24, 6378140.0) - >>> Planet.EARTH.surface_gravity - 9.802652743337129 diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/filecmp.rst --- a/Doc/library/filecmp.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/filecmp.rst Fri Feb 01 23:12:09 2013 +0100 @@ -27,10 +27,6 @@ Note that no external programs are called from this function, giving it portability and efficiency. - This function uses a cache for past comparisons and the results, - with a cache invalidation mechanism relying on stale signatures - or by explicitly calling :func:`clear_cache`. - .. function:: cmpfiles(dir1, dir2, common, shallow=True) @@ -52,15 +48,6 @@ one of the three returned lists. -.. function:: clear_cache() - - .. versionadded:: 3.4 - - Clear the filecmp cache. This may be useful if a file is compared so quickly - after it is modified that it is within the mtime resolution of - the underlying filesystem. - - .. _dircmp-objects: The :class:`dircmp` class @@ -69,8 +56,8 @@ .. class:: dircmp(a, b, ignore=None, hide=None) Construct a new directory comparison object, to compare the directories *a* - and *b*. *ignore* is a list of names to ignore, and defaults to - :attr:`filecmp.DEFAULT_IGNORES`. *hide* is a list of names to hide, and + and *b*. *ignore* is a list of names to ignore, and defaults to + :attr:`filecmp.DEFAULT_IGNORES`. *hide* is a list of names to hide, and defaults to ``[os.curdir, os.pardir]``. The :class:`dircmp` class compares files by doing *shallow* comparisons @@ -78,15 +65,18 @@ The :class:`dircmp` class provides the following methods: + .. method:: report() Print (to :data:`sys.stdout`) a comparison between *a* and *b*. + .. method:: report_partial_closure() Print a comparison between *a* and *b* and common immediate subdirectories. + .. method:: report_full_closure() Print a comparison between *a* and *b* and common subdirectories @@ -143,7 +133,7 @@ .. attribute:: common_files - Files in both *a* and *b*. + Files in both *a* and *b* .. attribute:: common_funny diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/functions.rst --- a/Doc/library/functions.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/functions.rst Fri Feb 01 23:12:09 2013 +0100 @@ -324,7 +324,7 @@ '__initializing__', '__loader__', '__name__', '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', 'unpack', 'unpack_from'] - >>> class Shape: + >>> class Shape(object): ... def __dir__(self): ... return ['area', 'perimeter', 'location'] >>> s = Shape() @@ -587,16 +587,11 @@ .. function:: hash(object) - Return the hash value of the object (if it has one). Hash values are - integers. They are used to quickly compare dictionary keys during a - dictionary lookup. Numeric values that compare equal have the same hash - value (even if they are of different types, as is the case for 1 and 1.0). + Return the hash value of the object (if it has one). Hash values are integers. + They are used to quickly compare dictionary keys during a dictionary lookup. + Numeric values that compare equal have the same hash value (even if they are of + different types, as is the case for 1 and 1.0). - .. note:: - - For object's with custom :meth:`__hash__` methods, note that :func:`hash` - truncates the return value based on the bit width of the host machine. - See :meth:`__hash__` for details. .. function:: help([object]) @@ -670,12 +665,6 @@ The integer type is described in :ref:`typesnumeric`. - .. versionchanged:: 3.4 - If *base* is not an instance of :class:`int` and the *base* object has a - :meth:`base.__index__ ` method, that method is called - to obtain an integer for the base. Previous versions used - :meth:`base.__int__ ` instead of :meth:`base.__index__ - `. .. function:: isinstance(object, classinfo) @@ -758,22 +747,19 @@ already arranged into argument tuples, see :func:`itertools.starmap`\. -.. function:: max(iterable, *[, default, key]) +.. function:: max(iterable, *[, key]) max(arg1, arg2, *args[, key]) Return the largest item in an iterable or the largest of two or more arguments. - If one positional argument is provided, it should be an :term:`iterable`. - The largest item in the iterable is returned. If two or more positional - arguments are provided, the smallest of the positional arguments is - returned. + If one positional argument is provided, *iterable* must be a non-empty + iterable (such as a non-empty string, tuple or list). The largest item + in the iterable is returned. If two or more positional arguments are + provided, the largest of the positional arguments is returned. - There are two optional keyword-only arguments. The *key* argument specifies - a one-argument ordering function like that used for :meth:`list.sort`. The - *default* argument specifies an object to return if the provided iterable is - empty. If the iterable is empty and *default* is not provided, a - :exc:`ValueError` is raised. + The optional keyword-only *key* argument specifies a one-argument ordering + function like that used for :meth:`list.sort`. If multiple items are maximal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools @@ -789,22 +775,19 @@ :ref:`typememoryview` for more information. -.. function:: min(iterable, *[, default, key]) +.. function:: min(iterable, *[, key]) min(arg1, arg2, *args[, key]) Return the smallest item in an iterable or the smallest of two or more arguments. - If one positional argument is provided, it should be an :term:`iterable`. - The smallest item in the iterable is returned. If two or more positional - arguments are provided, the smallest of the positional arguments is - returned. + If one positional argument is provided, *iterable* must be a non-empty + iterable (such as a non-empty string, tuple or list). The smallest item + in the iterable is returned. If two or more positional arguments are + provided, the smallest of the positional arguments is returned. - There are two optional keyword-only arguments. The *key* argument specifies - a one-argument ordering function like that used for :meth:`list.sort`. The - *default* argument specifies an object to return if the provided iterable is - empty. If the iterable is empty and *default* is not provided, a - :exc:`ValueError` is raised. + The optional keyword-only *key* argument specifies a one-argument ordering + function like that used for :meth:`list.sort`. If multiple items are minimal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools @@ -840,7 +823,7 @@ .. index:: single: file object; open() built-in function -.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None, cloexec=None) Open *file* and return a corresponding :term:`file object`. If the file cannot be opened, an :exc:`OSError` is raised. @@ -864,7 +847,7 @@ ========= =============================================================== Character Meaning - ========= =============================================================== + --------- --------------------------------------------------------------- ``'r'`` open for reading (default) ``'w'`` open for writing, truncating the file first ``'x'`` open for exclusive creation, failing if the file already exists @@ -897,8 +880,8 @@ *buffering* is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size - in bytes of a fixed-size chunk buffer. When no *buffering* argument is - given, the default buffering policy works as follows: + of a fixed-size chunk buffer. When no *buffering* argument is given, the + default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block @@ -916,36 +899,16 @@ 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. - A variety of standard error handlers are available, though any - error handling name that has been registered with - :func:`codecs.register_error` is also valid. The standard names - are: - - * ``'strict'`` to raise a :exc:`ValueError` exception if there is - an encoding error. The default value of ``None`` has the same - effect. - - * ``'ignore'`` ignores errors. Note that ignoring encoding errors - can lead to data loss. - - * ``'replace'`` causes a replacement marker (such as ``'?'``) to be inserted - where there is malformed data. - - * ``'surrogateescape'`` will represent any incorrect bytes as code - points in the Unicode Private Use Area ranging from U+DC80 to - U+DCFF. These private code points will then be turned back into - the same bytes when the ``surrogateescape`` error handler is used - when writing data. This is useful for processing files in an - unknown encoding. - - * ``'xmlcharrefreplace'`` is only supported when writing to a file. - Characters not supported by the encoding are replaced with the - appropriate XML character reference ``&#nnn;``. - - * ``'backslashreplace'`` (also only supported when writing) - replaces unsupported characters with Python's backslashed escape - sequences. + 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.) + ``'replace'`` causes a replacement marker (such as ``'?'``) to be inserted + where there is malformed data. When writing, ``'xmlcharrefreplace'`` + (replace with the appropriate XML character reference) or + ``'backslashreplace'`` (replace with backslashed escape sequences) can be + used. Any other error handling name that has been registered with + :func:`codecs.register_error` is also valid. .. index:: single: universal newlines; open() built-in function @@ -979,6 +942,10 @@ :mod:`os.open` as *opener* results in functionality similar to passing ``None``). + If *cloexec* is ``True``, set the :ref:`close-on-exec flag ` on + the newly created file descriptor. *cloexec* is ignored if *file* is an + integer file descriptor. + The following example uses the :ref:`dir_fd ` parameter of the :func:`os.open` function to open a file relative to a given directory:: @@ -996,6 +963,9 @@ The *opener* parameter was added. The ``'x'`` mode was added. + .. versionchanged:: 3.4 + The *cloexec* parameter was added. + The type of :term:`file object` returned by the :func:`open` function depends on the mode. When :func:`open` is used to open a file in a text mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of @@ -1396,18 +1366,14 @@ .. function:: vars([object]) - Return the :attr:`__dict__` attribute for a module, class, instance, - or any other object with a :attr:`__dict__` attribute. + Without an argument, act like :func:`locals`. - Objects such as modules and instances have an updateable :attr:`__dict__` - attribute; however, other objects may have write restrictions on their - :attr:`__dict__` attributes (for example, classes use a - dictproxy to prevent direct dictionary updates). + With a module, class or class instance object as argument (or anything else that + has a :attr:`__dict__` attribute), return that attribute. - Without an argument, :func:`vars` acts like :func:`locals`. Note, the - locals dictionary is only useful for reads since updates to the locals - dictionary are ignored. - + .. note:: + The returned dictionary should not be modified: + the effects on the corresponding symbol table are undefined. [#]_ .. function:: zip(*iterables) @@ -1526,3 +1492,7 @@ .. [#] Note that the parser only accepts the Unix-style end of line convention. If you are reading the code from a file, make sure to use newline conversion mode to convert Windows or Mac-style newlines. + +.. [#] In the current implementation, local variable bindings cannot normally be + affected this way, but variables retrieved from other scopes (such as modules) + can be. This may change. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/functools.rst --- a/Doc/library/functools.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/functools.rst Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,6 @@ .. moduleauthor:: Peter Harris .. moduleauthor:: Raymond Hettinger .. moduleauthor:: Nick Coghlan -.. moduleauthor:: Åukasz Langa .. sectionauthor:: Peter Harris **Source code:** :source:`Lib/functools.py` @@ -80,7 +79,7 @@ Example of an LRU cache for static web content:: - @lru_cache(maxsize=32) + @lru_cache(maxsize=20) def get_pep(num): 'Retrieve text of a Python Enhancement Proposal' resource = 'http://www.python.org/dev/peps/pep-%04d/' % num @@ -94,8 +93,8 @@ ... pep = get_pep(n) ... print(n, len(pep)) - >>> get_pep.cache_info() - CacheInfo(hits=3, misses=8, maxsize=32, currsize=8) + >>> print(get_pep.cache_info()) + CacheInfo(hits=3, misses=8, maxsize=20, currsize=8) Example of efficiently computing `Fibonacci numbers `_ @@ -109,10 +108,10 @@ return n return fib(n-1) + fib(n-2) - >>> [fib(n) for n in range(16)] + >>> print([fib(n) for n in range(16)]) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610] - >>> fib.cache_info() + >>> print(fib.cache_info()) CacheInfo(hits=28, misses=16, maxsize=None, currsize=16) .. versionadded:: 3.2 @@ -187,111 +186,6 @@ *sequence* contains only one item, the first item is returned. -.. decorator:: singledispatch(default) - - Transforms a function into a :term:`single-dispatch ` :term:`generic function`. - - To define a generic function, decorate it with the ``@singledispatch`` - decorator. Note that the dispatch happens on the type of the first argument, - create your function accordingly:: - - >>> from functools import singledispatch - >>> @singledispatch - ... def fun(arg, verbose=False): - ... if verbose: - ... print("Let me just say,", end=" ") - ... print(arg) - - To add overloaded implementations to the function, use the :func:`register` - attribute of the generic function. It is a decorator, taking a type - parameter and decorating a function implementing the operation for that - type:: - - >>> @fun.register(int) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Strength in numbers, eh?", end=" ") - ... print(arg) - ... - >>> @fun.register(list) - ... def _(arg, verbose=False): - ... if verbose: - ... print("Enumerate this:") - ... for i, elem in enumerate(arg): - ... print(i, elem) - - To enable registering lambdas and pre-existing functions, the - :func:`register` attribute can be used in a functional form:: - - >>> def nothing(arg, verbose=False): - ... print("Nothing.") - ... - >>> fun.register(type(None), nothing) - - The :func:`register` attribute returns the undecorated function which - enables decorator stacking, pickling, as well as creating unit tests for - each variant independently:: - - >>> @fun.register(float) - ... @fun.register(Decimal) - ... def fun_num(arg, verbose=False): - ... if verbose: - ... print("Half of your number:", end=" ") - ... print(arg / 2) - ... - >>> fun_num is fun - False - - When called, the generic function dispatches on the type of the first - argument:: - - >>> fun("Hello, world.") - Hello, world. - >>> fun("test.", verbose=True) - Let me just say, test. - >>> fun(42, verbose=True) - Strength in numbers, eh? 42 - >>> fun(['spam', 'spam', 'eggs', 'spam'], verbose=True) - Enumerate this: - 0 spam - 1 spam - 2 eggs - 3 spam - >>> fun(None) - Nothing. - >>> fun(1.23) - 0.615 - - Where there is no registered implementation for a specific type, its - method resolution order is used to find a more generic implementation. - The original function decorated with ``@singledispatch`` is registered - for the base ``object`` type, which means it is used if no better - implementation is found. - - To check which implementation will the generic function choose for - a given type, use the ``dispatch()`` attribute:: - - >>> fun.dispatch(float) - - >>> fun.dispatch(dict) # note: default implementation - - - To access all registered implementations, use the read-only ``registry`` - attribute:: - - >>> fun.registry.keys() - dict_keys([, , , - , , - ]) - >>> fun.registry[float] - - >>> fun.registry[object] - - - .. versionadded:: 3.4 - - .. function:: update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES) Update a *wrapper* function to look like the *wrapped* function. The optional @@ -306,8 +200,8 @@ To allow access to the original function for introspection and other purposes (e.g. bypassing a caching decorator such as :func:`lru_cache`), this function - automatically adds a ``__wrapped__`` attribute to the wrapper that refers to - the function being wrapped. + automatically adds a __wrapped__ attribute to the wrapper that refers to + the original function. The main intended use for this function is in :term:`decorator` functions which wrap the decorated function and return the wrapper. If the wrapper function is @@ -330,11 +224,6 @@ .. versionchanged:: 3.2 Missing attributes no longer trigger an :exc:`AttributeError`. - .. versionchanged:: 3.4 - The ``__wrapped__`` attribute now always refers to the wrapped - function, even if that function defined a ``__wrapped__`` attribute. - (see :issue:`17482`) - .. decorator:: wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/glob.rst --- a/Doc/library/glob.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/glob.rst Fri Feb 01 23:12:09 2013 +0100 @@ -16,10 +16,8 @@ ``*``, ``?``, and character ranges expressed with ``[]`` will be correctly matched. This is done by using the :func:`os.listdir` and :func:`fnmatch.fnmatch` functions in concert, and not by actually invoking a -subshell. Note that unlike :func:`fnmatch.fnmatch`, :mod:`glob` treats -filenames beginning with a dot (``.``) as special cases. (For tilde and shell -variable expansion, use :func:`os.path.expanduser` and -:func:`os.path.expandvars`.) +subshell. (For tilde and shell variable expansion, use +:func:`os.path.expanduser` and :func:`os.path.expandvars`.) For a literal match, wrap the meta-characters in brackets. For example, ``'[?]'`` matches the character ``'?'``. @@ -53,15 +51,6 @@ >>> glob.glob('?.gif') ['1.gif'] -If the directory contains files starting with ``.`` they won't be matched by -default. For example, consider a directory containing :file:`card.gif` and -:file:`.card.gif`:: - - >>> import glob - >>> glob.glob('*.gif') - ['card.gif'] - >>> glob.glob('.c*') - ['.card.gif'] .. seealso:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/hashlib.rst --- a/Doc/library/hashlib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/hashlib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -32,9 +32,9 @@ There is one constructor method named for each type of :dfn:`hash`. All return a hash object with the same simple interface. For example: use :func:`sha1` to -create a SHA1 hash object. You can now feed this object with :term:`bytes-like -object`\ s (normally :class:`bytes`) using the :meth:`update` method. -At any point you can ask it for the :dfn:`digest` of the +create a SHA1 hash object. You can now feed this object with objects conforming +to the buffer interface (normally :class:`bytes` objects) using the +:meth:`update` method. At any point you can ask it for the :dfn:`digest` of the concatenation of the data fed to it so far using the :meth:`digest` or :meth:`hexdigest` methods. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/heapq.rst --- a/Doc/library/heapq.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/heapq.rst Fri Feb 01 23:12:09 2013 +0100 @@ -246,7 +246,7 @@ the sort is going on, provided that the inserted items are not "better" than the last 0'th element you extracted. This is especially useful in simulation contexts, where the tree holds all incoming events, and the "win" condition -means the smallest scheduled time. When an event schedules other events for +means the smallest scheduled time. When an event schedule other events for execution, they are scheduled into the future, so they can easily go into the heap. So, a heap is a good structure for implementing schedulers (this is what I used for my MIDI sequencer :-). diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/hmac.rst --- a/Doc/library/hmac.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/hmac.rst Fri Feb 01 23:12:09 2013 +0100 @@ -16,26 +16,20 @@ .. function:: new(key, msg=None, digestmod=None) - Return a new hmac object. *key* is a bytes or bytearray object giving the - secret key. If *msg* is present, the method call ``update(msg)`` is made. - *digestmod* is the digest constructor or module for the HMAC object to use. - It defaults to the :func:`hashlib.md5` constructor. + Return a new hmac object. *key* is a bytes object giving the secret key. If + *msg* is present, the method call ``update(msg)`` is made. *digestmod* is + the digest constructor or module for the HMAC object to use. It defaults to + the :func:`hashlib.md5` constructor. - .. versionchanged:: 3.4 - Parameter *key* can be a bytes or bytearray object. Parameter *msg* can - be of any type supported by :mod:`hashlib`. An HMAC object has the following methods: .. method:: HMAC.update(msg) - Update the hmac object with *msg*. Repeated calls are equivalent to a - single call with the concatenation of all the arguments: + Update the hmac object with the bytes object *msg*. Repeated calls are + equivalent to a single call with the concatenation of all the arguments: ``m.update(a); m.update(b)`` is equivalent to ``m.update(a + b)``. - .. versionchanged:: 3.4 - Parameter *msg* can be of any type supported by :mod:`hashlib`. - .. method:: HMAC.digest() @@ -80,7 +74,8 @@ timing analysis by avoiding content-based short circuiting behaviour, making it appropriate for cryptography. *a* and *b* must both be of the same type: either :class:`str` (ASCII only, as e.g. returned by - :meth:`HMAC.hexdigest`), or a :term:`bytes-like object`. + :meth:`HMAC.hexdigest`), or any type that supports the buffer protocol + (e.g. :class:`bytes`). .. note:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/http.client.rst --- a/Doc/library/http.client.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/http.client.rst Fri Feb 01 23:12:09 2013 +0100 @@ -27,7 +27,7 @@ The module provides the following classes: -.. class:: HTTPConnection(host, port=None[, timeout], \ +.. class:: HTTPConnection(host, port=None[, strict][, timeout], \ source_address=None) An :class:`HTTPConnection` instance represents one transaction with an HTTP @@ -51,13 +51,13 @@ .. versionchanged:: 3.2 *source_address* was added. - .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9-style "Simple Responses" are - not supported. + .. versionchanged:: 3.2 + The *strict* parameter is deprecated. HTTP 0.9-style "Simple Responses" + are not supported anymore. .. class:: HTTPSConnection(host, port=None, key_file=None, \ - cert_file=None[, timeout], \ + cert_file=None[, strict][, timeout], \ source_address=None, *, context=None, \ check_hostname=None) @@ -89,19 +89,19 @@ This class now supports HTTPS virtual hosts if possible (that is, if :data:`ssl.HAS_SNI` is true). - .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9-style "Simple Responses" are - not supported anymore. + .. versionchanged:: 3.2 + The *strict* parameter is deprecated. HTTP 0.9-style "Simple Responses" + are not supported anymore. -.. class:: HTTPResponse(sock, debuglevel=0, method=None, url=None) +.. class:: HTTPResponse(sock, debuglevel=0[, strict], method=None, url=None) Class whose instances are returned upon successful connection. Not instantiated directly by user. - .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9 style "Simple Responses" are - not supported anymore. + .. versionchanged:: 3.2 + The *strict* parameter is deprecated. HTTP 0.9-style "Simple Responses" + are not supported anymore. The following exceptions are raised as appropriate: @@ -633,24 +633,6 @@ b'Redirecting to http://bugs.python.org/issue12524' >>> conn.close() -Client side ``HTTP PUT`` requests are very similar to ``POST`` requests. The -difference lies only the server side where HTTP server will allow resources to -be created via ``PUT`` request. It should be noted that custom HTTP methods -+are also handled in :class:`urllib.request.Request` by sending the appropriate -+method attribute.Here is an example session that shows how to do ``PUT`` -request using http.client:: - - >>> # This creates an HTTP message - >>> # with the content of BODY as the enclosed representation - >>> # for the resource http://localhost:8080/foobar - ... - >>> import http.client - >>> BODY = "***filecontents***" - >>> conn = http.client.HTTPConnection("localhost", 8080) - >>> conn.request("PUT", "/file", BODY) - >>> response = conn.getresponse() - >>> print(resp.status, response.reason) - 200, OK .. _httpmessage-objects: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/http.cookiejar.rst --- a/Doc/library/http.cookiejar.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/http.cookiejar.rst Fri Feb 01 23:12:09 2013 +0100 @@ -154,15 +154,9 @@ The *request* object (usually a :class:`urllib.request..Request` instance) must support the methods :meth:`get_full_url`, :meth:`get_host`, - :meth:`get_type`, :meth:`unverifiable`, :meth:`has_header`, - :meth:`get_header`, :meth:`header_items`, :meth:`add_unredirected_header` - and :attr:`origin_req_host` attribute as documented by - :mod:`urllib.request`. - - .. versionchanged:: 3.3 - - *request* object needs :attr:`origin_req_host` attribute. Dependency on a - deprecated method :meth:`get_origin_req_host` has been removed. + :meth:`get_type`, :meth:`unverifiable`, :meth:`get_origin_req_host`, + :meth:`has_header`, :meth:`get_header`, :meth:`header_items`, and + :meth:`add_unredirected_header`, as documented by :mod:`urllib.request`. .. method:: CookieJar.extract_cookies(response, request) @@ -180,15 +174,11 @@ The *request* object (usually a :class:`urllib.request.Request` instance) must support the methods :meth:`get_full_url`, :meth:`get_host`, - :meth:`unverifiable`, and :attr:`origin_req_host` attribute, as documented - by :mod:`urllib.request`. The request is used to set default values for + :meth:`unverifiable`, and :meth:`get_origin_req_host`, as documented by + :mod:`urllib.request`. The request is used to set default values for cookie-attributes as well as for checking that the cookie is allowed to be set. - .. versionchanged:: 3.3 - - *request* object needs :attr:`origin_req_host` attribute. Dependency on a - deprecated method :meth:`get_origin_req_host` has been removed. .. method:: CookieJar.set_policy(policy) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/http.server.rst --- a/Doc/library/http.server.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/http.server.rst Fri Feb 01 23:12:09 2013 +0100 @@ -170,19 +170,15 @@ .. versionadded:: 3.2 - .. method:: send_error(code, message=None, explain=None) + .. method:: send_error(code, message=None) Sends and logs a complete error reply to the client. The numeric *code* - specifies the HTTP error code, with *message* as optional, more specific - text, usually referring to short message response. The *explain* - argument can be used to send a detailed information about the error in - response content body. A complete set of headers is sent, followed by - text composed using the :attr:`error_message_format` class variable. + specifies the HTTP error code, with *message* as optional, more specific text. A + complete set of headers is sent, followed by text composed using the + :attr:`error_message_format` class variable. .. versionchanged:: 3.4 The error response includes a Content-Length header. - Added the *explain* argument. - .. method:: send_response(code, message=None) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/idle.rst --- a/Doc/library/idle.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/idle.rst Fri Feb 01 23:12:09 2013 +0100 @@ -39,8 +39,8 @@ File menu (Shell and Editor) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -New file - Create a new file editing window +New window + Create a new editing window Open... Open an existing file diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/imaplib.rst --- a/Doc/library/imaplib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/imaplib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -185,10 +185,9 @@ data = authobject(response) - It will be called to process server continuation responses; the *response* - argument it is passed will be ``bytes``. It should return ``bytes`` *data* - that will be base64 encoded and sent to the server. It should return - ``None`` if the client abort response ``*`` should be sent instead. + It will be called to process server continuation responses. It should return + ``data`` that will be encoded and sent to server. It should return ``None`` if + the client abort response ``*`` should be sent instead. .. method:: IMAP4.check() diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/imghdr.rst --- a/Doc/library/imghdr.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/imghdr.rst Fri Feb 01 23:12:09 2013 +0100 @@ -65,6 +65,6 @@ Example:: >>> import imghdr - >>> imghdr.what('bass.gif') + >>> imghdr.what('/tmp/bass.gif') 'gif' diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/imp.rst --- a/Doc/library/imp.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/imp.rst Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,5 @@ -:mod:`imp` --- Access the :ref:`import ` internals -================================================================ - -.. deprecated:: 3.4 - The :mod:`imp` package is pending deprecation in favor of :mod:`importlib`. +:mod:`imp` --- Access the :keyword:`import` internals +===================================================== .. module:: imp :synopsis: Access the implementation of the import statement. @@ -21,9 +18,6 @@ Return the magic string value used to recognize byte-compiled code files (:file:`.pyc` files). (This value may be different for each Python version.) - .. deprecated:: 3.4 - Use :attr:`importlib.util.MAGIC_NUMBER` instead. - .. function:: get_suffixes() @@ -103,10 +97,8 @@ using a :keyword:`try` ... :keyword:`finally` statement. .. deprecated:: 3.3 - If previously used in conjunction with :func:`imp.find_module` then - call ``load_module()`` on the returned loader. If you wish to load a - module from a specific file, then use one of the file-based loaders found - in :mod:`importlib.machinery`. + Unneeded as loaders should be used to load modules and + :func:`find_module` is deprecated. .. function:: new_module(name) @@ -114,9 +106,6 @@ Return a new empty module object called *name*. This object is *not* inserted in ``sys.modules``. - .. deprecated:: 3.4 - Use :class:`types.ModuleType` instead. - .. function:: reload(module) @@ -165,7 +154,7 @@ cache = {} It is legal though generally not very useful to reload built-in or dynamically - loaded modules, except for :mod:`sys`, :mod:`__main__` and :mod:`builtins`. + loaded modules, except for :mod:`sys`, :mod:`__main__` and :mod:`__builtin__`. In many cases, however, extension modules are not designed to be initialized more than once, and may fail in arbitrary ways when reloaded. @@ -179,9 +168,6 @@ the class does not affect the method definitions of the instances --- they continue to use the old class definition. The same is true for derived classes. - .. deprecated:: 3.4 - Use :func:`importlib.reload` instead. - The following functions are conveniences for handling :pep:`3147` byte-compiled file paths. @@ -207,9 +193,6 @@ If :attr:`sys.implementation.cache_tag` is ``None``, then :exc:`NotImplementedError` is raised. - .. deprecated:: 3.4 - Use :func:`importlib.util.cache_from_source` instead. - .. function:: source_from_cache(path) @@ -225,17 +208,14 @@ Raise :exc:`NotImplementedError` when :attr:`sys.implementation.cache_tag` is not defined. - .. deprecated:: 3.4 - Use :func:`importlib.util.source_from_cache` instead. - .. function:: get_tag() Return the :pep:`3147` magic tag string matching this version of Python's magic number, as returned by :func:`get_magic`. - .. deprecated:: 3.4 - Use :attr:`sys.implementation.cache_tag` directly starting + .. note:: + You may use :attr:`sys.implementation.cache_tag` directly starting in Python 3.3. @@ -263,8 +243,6 @@ the most part. A global import lock is kept for some critical tasks, such as initializing the per-module locks. -.. deprecated:: 3.4 - .. function:: acquire_lock() @@ -283,8 +261,6 @@ the most part. A global import lock is kept for some critical tasks, such as initializing the per-module locks. -.. deprecated:: 3.4 - .. function:: release_lock() @@ -296,8 +272,6 @@ the most part. A global import lock is kept for some critical tasks, such as initializing the per-module locks. -.. deprecated:: 3.4 - The following constants with integer values, defined in this module, are used to indicate the search result of :func:`find_module`. @@ -352,20 +326,16 @@ with an existing directory or empty string raises :exc:`ImportError`. Otherwise, a :class:`NullImporter` instance is returned. - Instances have only one method: + Python adds instances of this type to ``sys.path_importer_cache`` for any path + entries that are not directories and are not handled by any other path hooks on + ``sys.path_hooks``. Instances have only one method: + .. method:: NullImporter.find_module(fullname [, path]) This method always returns ``None``, indicating that the requested module could not be found. - .. versionchanged:: 3.3 - ``None`` is inserted into ``sys.path_importer_cache`` instead of an - instance of :class:`NullImporter`. - - .. deprecated:: 3.4 - Insert ``None`` into ``sys.path_importer_cache`` instead. - .. _examples-imp: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/importlib.rst --- a/Doc/library/importlib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/importlib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -90,7 +90,7 @@ Find the loader for a module, optionally within the specified *path*. If the module is in :attr:`sys.modules`, then ``sys.modules[name].__loader__`` is - returned (unless the loader would be ``None`` or is not set, in which case + returned (unless the loader would be ``None``, in which case :exc:`ValueError` is raised). Otherwise a search using :attr:`sys.meta_path` is done. ``None`` is returned if no loader is found. @@ -99,89 +99,16 @@ will need to import all parent packages of the submodule and use the correct argument to *path*. - .. versionadded:: 3.3 - - .. versionchanged:: 3.4 - If ``__loader__`` is not set, raise :exc:`ValueError`, just like when the - attribute is set to ``None``. - .. function:: invalidate_caches() Invalidate the internal caches of finders stored at :data:`sys.meta_path`. If a finder implements ``invalidate_caches()`` then it - will be called to perform the invalidation. This function should be called - if any modules are created/installed while your program is running to - guarantee all finders will notice the new module's existence. + will be called to perform the invalidation. This function may be needed if + some modules are installed while your program is running and you expect the + program to notice the changes. .. versionadded:: 3.3 -.. function:: reload(module) - - Reload a previously imported *module*. The argument must be a module object, - so it must have been successfully imported before. This is useful if you - have edited the module source file using an external editor and want to try - out the new version without leaving the Python interpreter. The return value - is the module object (the same as the *module* argument). - - When :func:`.reload` is executed: - - * Python modules' code is recompiled and the module-level code re-executed, - defining a new set of objects which are bound to names in the module's - dictionary by reusing the :term:`loader` which originally loaded the - module. The ``init`` function of extension modules is not called a second - time. - - * As with all other objects in Python the old objects are only reclaimed - after their reference counts drop to zero. - - * The names in the module namespace are updated to point to any new or - changed objects. - - * Other references to the old objects (such as names external to the module) are - not rebound to refer to the new objects and must be updated in each namespace - where they occur if that is desired. - - There are a number of other caveats: - - If a module is syntactically correct but its initialization fails, the first - :keyword:`import` statement for it does not bind its name locally, but does - store a (partially initialized) module object in ``sys.modules``. To reload - the module you must first :keyword:`import` it again (this will bind the name - to the partially initialized module object) before you can :func:`reload` it. - - When a module is reloaded, its dictionary (containing the module's global - variables) is retained. Redefinitions of names will override the old - definitions, so this is generally not a problem. If the new version of a - module does not define a name that was defined by the old version, the old - definition remains. This feature can be used to the module's advantage if it - maintains a global table or cache of objects --- with a :keyword:`try` - statement it can test for the table's presence and skip its initialization if - desired:: - - try: - cache - except NameError: - cache = {} - - It is legal though generally not very useful to reload built-in or - dynamically loaded modules (this is not true for e.g. :mod:`sys`, - :mod:`__main__`, :mod:`__builtin__` and other key modules where reloading is - frowned upon). In many cases, however, extension modules are not designed to - be initialized more than once, and may fail in arbitrary ways when reloaded. - - If a module imports objects from another module using :keyword:`from` ... - :keyword:`import` ..., calling :func:`reload` for the other module does not - redefine the objects imported from it --- one way around this is to - re-execute the :keyword:`from` statement, another is to use :keyword:`import` - and qualified names (*module.name*) instead. - - If a module instantiates instances of a class, reloading the module that - defines the class does not affect the method definitions of the instances --- - they continue to use the old class definition. The same is true for derived - classes. - - .. versionadded:: 3.4 - :mod:`importlib.abc` -- Abstract base classes related to import --------------------------------------------------------------- @@ -220,10 +147,6 @@ module. Originally specified in :pep:`302`, this method was meant for use in :data:`sys.meta_path` and in the path-based import subsystem. - .. versionchanged:: 3.4 - Returns ``None`` when called instead of raising - :exc:`NotImplementedError`. - .. class:: MetaPathFinder @@ -240,19 +163,12 @@ will be the value of :attr:`__path__` from the parent package. If a loader cannot be found, ``None`` is returned. - .. versionchanged:: 3.4 - Returns ``None`` when called instead of raising - :exc:`NotImplementedError`. - .. method:: invalidate_caches() An optional method which, when called, should invalidate any internal cache used by the finder. Used by :func:`importlib.invalidate_caches` when invalidating the caches of all finders on :data:`sys.meta_path`. - .. versionchanged:: 3.4 - Returns ``None`` when called instead of ``NotImplemented``. - .. class:: PathEntryFinder @@ -260,11 +176,11 @@ it bears some similarities to :class:`MetaPathFinder`, ``PathEntryFinder`` is meant for use only within the path-based import subsystem provided by :class:`PathFinder`. This ABC is a subclass of :class:`Finder` for - compatibility reasons only. + compatibility. .. versionadded:: 3.3 - .. method:: find_loader(fullname) + .. method:: find_loader(fullname): An abstract method for finding a :term:`loader` for the specified module. Returns a 2-tuple of ``(loader, portion)`` where ``portion`` @@ -272,14 +188,11 @@ package. The loader may be ``None`` while specifying ``portion`` to signify the contribution of the file system locations to a namespace package. An empty list can be used for ``portion`` to signify the loader - is not part of a namespace package. If ``loader`` is ``None`` and - ``portion`` is the empty list then no loader or location for a namespace - package were found (i.e. failure to find anything for the module). + is not part of a package. If ``loader`` is ``None`` and ``portion`` is + the empty list then no loader or location for a namespace package were + found (i.e. failure to find anything for the module). - .. versionchanged:: 3.4 - Returns ``(None, [])`` instead of raising :exc:`NotImplementedError`. - - .. method:: find_module(fullname) + .. method:: find_module(fullname): A concrete implementation of :meth:`Finder.find_module` which is equivalent to ``self.find_loader(fullname)[0]``. @@ -309,11 +222,12 @@ from the import. If the loader inserted a module and the load fails, it must be removed by the loader from :data:`sys.modules`; modules already in :data:`sys.modules` before the loader began execution should be left - alone (see :func:`importlib.util.module_to_load`). + alone. The :func:`importlib.util.module_for_loader` decorator handles + all of these details. The loader should set several attributes on the module. (Note that some of these attributes can change when a module is - reloaded; see :meth:`init_module_attrs`): + reloaded.) - :attr:`__name__` The name of the module. @@ -322,10 +236,6 @@ The path to where the module data is stored (not set for built-in modules). - - :attr:`__cached__` - The path to where a compiled version of the module is/should be - stored (not set when the attribute would be inappropriate). - - :attr:`__path__` A list of strings specifying the search path within a package. This attribute is not set on modules. @@ -333,39 +243,20 @@ - :attr:`__package__` The parent package for the module/package. If the module is top-level then it has a value of the empty string. The - :func:`importlib.util.module_for_loader` decorator can handle the - details for :attr:`__package__`. + :func:`importlib.util.set_package` decorator can handle the details + for :attr:`__package__`. - :attr:`__loader__` - The loader used to load the module. The - :func:`importlib.util.module_for_loader` decorator can handle the - details for :attr:`__package__`. - - .. versionchanged:: 3.4 - Raise :exc:`ImportError` when called instead of - :exc:`NotImplementedError`. + The loader used to load the module. + (This is not set by the built-in import machinery, + but it should be set whenever a :term:`loader` is used.) .. method:: module_repr(module) - An optional method which when implemented calculates and returns the - given module's repr, as a string. The module type's default repr() will - use the result of this method as appropriate. + An abstract method which when implemented calculates and returns the + given module's repr, as a string. - .. versionadded:: 3.3 - - .. versionchanged:: 3.4 - Made optional instead of an abstractmethod. - - .. method:: init_module_attrs(module) - - Set the :attr:`__loader__` attribute on the module. - - Subclasses overriding this method should set whatever appropriate - attributes it can, getting the module's name from :attr:`__name__` when - needed. All values should also be overridden so that reloading works as - expected. - - .. versionadded:: 3.4 + .. versionadded: 3.3 .. class:: ResourceLoader @@ -384,9 +275,6 @@ be found. The *path* is expected to be constructed using a module's :attr:`__file__` attribute or an item from a package's :attr:`__path__`. - .. versionchanged:: 3.4 - Raises :exc:`IOError` instead of :exc:`NotImplementedError`. - .. class:: InspectLoader @@ -395,21 +283,14 @@ .. method:: get_code(fullname) - Return the code object for a module. - ``None`` should be returned if the module does not have a code object + An abstract method to return the :class:`code` object for a module. + ``None`` is returned if the module does not have a code object (e.g. built-in module). :exc:`ImportError` is raised if loader cannot find the requested module. - .. note:: - While the method has a default implementation, it is suggested that - it be overridden if possible for performance. - .. index:: single: universal newlines; importlib.abc.InspectLoader.get_source method - .. versionchanged:: 3.4 - No longer abstract and a concrete implementation is provided. - .. method:: get_source(fullname) An abstract method to return the source of a module. It is returned as @@ -418,41 +299,12 @@ if no source is available (e.g. a built-in module). Raises :exc:`ImportError` if the loader cannot find the module specified. - .. versionchanged:: 3.4 - Raises :exc:`ImportError` instead of :exc:`NotImplementedError`. - .. method:: is_package(fullname) An abstract method to return a true value if the module is a package, a false value otherwise. :exc:`ImportError` is raised if the :term:`loader` cannot find the module. - .. versionchanged:: 3.4 - Raises :exc:`ImportError` instead of :exc:`NotImplementedError`. - - .. method:: source_to_code(data, path='') - - Create a code object from Python source. - - The *data* argument can be whatever the :func:`compile` function - supports (i.e. string or bytes). The *path* argument should be - the "path" to where the source code originated from, which can be an - abstract concept (e.g. location in a zip file). - - .. versionadded:: 3.4 - - .. method:: init_module_attrs(module) - - Set the :attr:`__package__` attribute and :attr:`__path__` attribute to - the empty list if appropriate along with what - :meth:`importlib.abc.Loader.init_module_attrs` sets. - - .. versionadded:: 3.4 - - .. method:: load_module(fullname) - - Implementation of :meth:`Loader.load_module`. - .. class:: ExecutionLoader @@ -470,23 +322,11 @@ the source file, regardless of whether a bytecode was used to load the module. - .. versionchanged:: 3.4 - Raises :exc:`ImportError` instead of :exc:`NotImplementedError`. - - .. method:: init_module_attrs(module) - - Set :attr:`__file__` and if initializing a package then set - :attr:`__path__` to ``[os.path.dirname(__file__)]`` along with - all attributes set by - :meth:`importlib.abc.InspectLoader.init_module_attrs`. - - .. versionadded:: 3.4 - .. class:: FileLoader(fullname, path) An abstract base class which inherits from :class:`ResourceLoader` and - :class:`ExecutionLoader`, providing concrete implementations of + :class:`ExecutionLoader`, providing concreate implementations of :meth:`ResourceLoader.get_data` and :meth:`ExecutionLoader.get_filename`. The *fullname* argument is a fully resolved name of the module the loader is @@ -512,7 +352,7 @@ .. method:: get_data(path) - Reads *path* as a binary file and returns the bytes from it. + Returns the open, binary file for *path*. .. class:: SourceLoader @@ -524,7 +364,8 @@ * :meth:`ResourceLoader.get_data` * :meth:`ExecutionLoader.get_filename` Should only return the path to the source file; sourceless - loading is not supported. + loading is not supported (see :class:`SourcelessLoader` if that + functionality is required) The abstract methods defined by this class are to add optional bytecode file support. Not implementing these optional methods (or causing them to @@ -545,13 +386,10 @@ - ``'size'`` (optional): the size in bytes of the source code. Any other keys in the dictionary are ignored, to allow for future - extensions. If the path cannot be handled, :exc:`IOError` is raised. + extensions. .. versionadded:: 3.3 - .. versionchanged:: 3.4 - Raise :exc:`IOError` instead of :exc:`NotImplementedError`. - .. method:: path_mtime(path) Optional abstract method which returns the modification time for the @@ -560,10 +398,7 @@ .. deprecated:: 3.3 This method is deprecated in favour of :meth:`path_stats`. You don't have to implement it, but it is still available for compatibility - purposes. Raise :exc:`IOError` if the path cannot be handled. - - .. versionchanged:: 3.4 - Raise :exc:`IOError` instead of :exc:`NotImplementedError`. + purposes. .. method:: set_data(path, data) @@ -572,11 +407,18 @@ automatically. When writing to the path fails because the path is read-only - (:attr:`errno.EACCES`/:exc:`PermissionError`), do not propagate the - exception. + (:attr:`errno.EACCES`), do not propagate the exception. - .. versionchanged:: 3.4 - No longer raises :exc:`NotImplementedError` when called. + .. method:: source_to_code(data, path) + + Create a code object from Python source. + + The *data* argument can be whatever the :func:`compile` function + supports (i.e. string or bytes). The *path* argument should be + the "path" to where the source code originated from, which can be an + abstract concept (e.g. location in a zip file). + + .. versionadded:: 3.4 .. method:: get_code(fullname) @@ -598,14 +440,6 @@ ``__init__`` when the file extension is removed **and** the module name itself does not end in ``__init__``. - .. method:: init_module_attr(module) - - Set :attr:`__cached__` using :func:`imp.cache_from_source`. Other - attributes set by - :meth:`importlib.abc.ExecutionLoader.init_module_attrs`. - - .. versionadded:: 3.4 - :mod:`importlib.machinery` -- Importers and path hooks ------------------------------------------------------ @@ -709,8 +543,8 @@ specified by *fullname* on :data:`sys.path` or, if defined, on *path*. For each path entry that is searched, :data:`sys.path_importer_cache` is checked. If a non-false object is - found then it is used as the :term:`path entry finder` to look for the - module being searched for. If no entry is found in + found then it is used as the :term:`finder` to look for the module + being searched for. If no entry is found in :data:`sys.path_importer_cache`, then :data:`sys.path_hooks` is searched for a finder for the path entry and, if found, is stored in :data:`sys.path_importer_cache` along with being queried about the @@ -733,8 +567,6 @@ The *loader_details* argument is a variable number of 2-item tuples each containing a loader and a sequence of file suffixes the loader recognizes. - The loaders are expected to be callables which accept two arguments of - the module's name and the path to the file found. The finder will cache the directory contents as necessary, making stat calls for each module search to verify the cache is not outdated. Because cache @@ -752,7 +584,7 @@ The path the finder will search in. - .. method:: find_loader(fullname) + .. method:: find_module(fullname) Attempt to find the loader to handle *fullname* within :attr:`path`. @@ -880,51 +712,6 @@ This module contains the various objects that help in the construction of an :term:`importer`. -.. attribute:: MAGIC_NUMBER - - The bytes which represent the bytecode version number. If you need help with - loading/writing bytecode then consider :class:`importlib.abc.SourceLoader`. - - .. versionadded:: 3.4 - -.. function:: cache_from_source(path, debug_override=None) - - Return the :pep:`3147` path to the byte-compiled file associated with the - source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return - value would be ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2. - The ``cpython-32`` string comes from the current magic tag (see - :func:`get_tag`; if :attr:`sys.implementation.cache_tag` is not defined then - :exc:`NotImplementedError` will be raised). The returned path will end in - ``.pyc`` when ``__debug__`` is True or ``.pyo`` for an optimized Python - (i.e. ``__debug__`` is False). By passing in True or False for - *debug_override* you can override the system's value for ``__debug__`` for - extension selection. - - *path* need not exist. - - .. versionadded:: 3.4 - - -.. function:: source_from_cache(path) - - Given the *path* to a :pep:`3147` file name, return the associated source code - file path. For example, if *path* is - ``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be - ``/foo/bar/baz.py``. *path* need not exist, however if it does not conform - to :pep:`3147` format, a ``ValueError`` is raised. If - :attr:`sys.implementation.cache_tag` is not defined, - :exc:`NotImplementedError` is raised. - - .. versionadded:: 3.4 - -.. function:: decode_source(source_bytes) - - Decode the given bytes representing source code and return it as a string - with universal newlines (as required by - :meth:`importlib.abc.InspectLoader.get_source`). - - .. versionadded:: 3.4 - .. function:: resolve_name(name, package) Resolve a relative module name to an absolute one. @@ -941,23 +728,9 @@ .. versionadded:: 3.3 -.. function:: module_to_load(name, *, reset_name=True) - - Returns a :term:`context manager` which provides the module to load. The - module will either come from :attr:`sys.modules` in the case of reloading or - a fresh module if loading a new module. Proper cleanup of - :attr:`sys.modules` occurs if the module was new and an exception was - raised. - - If **reset_name** is true and the module requested is being reloaded then - the module's :attr:`__name__` attribute will - be reset to **name**, else it will be left untouched. - - .. versionadded:: 3.4 - .. decorator:: module_for_loader - A :term:`decorator` for :meth:`importlib.abc.Loader.load_module` + A :term:`decorator` for a :term:`loader` method, to handle selecting the proper module object to load with. The decorated method is expected to have a call signature taking two positional arguments @@ -968,54 +741,55 @@ The decorated method will take in the **name** of the module to be loaded as expected for a :term:`loader`. If the module is not found in - :data:`sys.modules` then a new one is constructed. Regardless of where the - module came from, :attr:`__loader__` set to **self** and :attr:`__package__` - is set based on what :meth:`importlib.abc.InspectLoader.is_package` returns - (if available). These attributes are set unconditionally to support - reloading. + :data:`sys.modules` then a new one is constructed with its + :attr:`__name__` attribute set to **name**, :attr:`__loader__` set to + **self**, and :attr:`__package__` set if + :meth:`importlib.abc.InspectLoader.is_package` is defined for **self** and + does not raise :exc:`ImportError` for **name**. If a new module is not + needed then the module found in :data:`sys.modules` will be passed into the + method. If an exception is raised by the decorated method and a module was added to :data:`sys.modules` it will be removed to prevent a partially initialized module from being in left in :data:`sys.modules`. If the module was already in :data:`sys.modules` then it is left alone. + Use of this decorator handles all the details of which module object a + loader should initialize as specified by :pep:`302` as best as possible. + .. versionchanged:: 3.3 :attr:`__loader__` and :attr:`__package__` are automatically set (when possible). - .. versionchanged:: 3.4 - Set :attr:`__name__`, :attr:`__loader__` :attr:`__package__` - unconditionally to support reloading. - - .. deprecated:: 3.4 - For the benefit of :term:`loader` subclasses, please use - :func:`module_to_load` and - :meth:`importlib.abc.Loader.init_module_attrs` instead. - .. decorator:: set_loader - A :term:`decorator` for :meth:`importlib.abc.Loader.load_module` - to set the :attr:`__loader__` - attribute on the returned module. If the attribute is already set the - decorator does nothing. It is assumed that the first positional argument to - the wrapped method (i.e. ``self``) is what :attr:`__loader__` should be set - to. + A :term:`decorator` for a :term:`loader` method, + to set the :attr:`__loader__` + attribute on loaded modules. If the attribute is already set the decorator + does nothing. It is assumed that the first positional argument to the + wrapped method (i.e. ``self``) is what :attr:`__loader__` should be set to. .. note:: - As this decorator sets :attr:`__loader__` after loading the module, it is - recommended to use :meth:`importlib.abc.Loader.init_module_attrs` instead - when appropriate. - .. versionchanged:: 3.4 - Set ``__loader__`` if set to ``None``, as if the attribute does not - exist. + It is recommended that :func:`module_for_loader` be used over this + decorator as it subsumes this functionality. + .. decorator:: set_package - A :term:`decorator` for :meth:`importlib.abc.Loader.load_module` to set the :attr:`__package__` attribute on the returned module. If :attr:`__package__` - is set and has a value other than ``None`` it will not be changed. + A :term:`decorator` for a :term:`loader` to set the :attr:`__package__` + attribute on the module returned by the loader. If :attr:`__package__` is + set and has a value other than ``None`` it will not be changed. + Note that the module returned by the loader is what has the attribute + set on and not the module found in :data:`sys.modules`. + + Reliance on this decorator is discouraged when it is possible to set + :attr:`__package__` before importing. By + setting it beforehand the code for the module is executed with the + attribute set and thus can be used by global level code during + initialization. .. note:: - As this decorator sets :attr:`__package__` after loading the module, it is - recommended to use :meth:`importlib.abc.Loader.init_module_attrs` instead - when appropriate. + + It is recommended that :func:`module_for_loader` be used over this + decorator as it subsumes this functionality. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/inspect.rst --- a/Doc/library/inspect.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/inspect.rst Fri Feb 01 23:12:09 2013 +0100 @@ -520,8 +520,6 @@ Describes how argument values are bound to the parameter. Possible values (accessible via :class:`Parameter`, like ``Parameter.KEYWORD_ONLY``): - .. tabularcolumns:: |l|L| - +------------------------+----------------------------------------------+ | Name | Meaning | +========================+==============================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/io.rst --- a/Doc/library/io.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/io.rst Fri Feb 01 23:12:09 2013 +0100 @@ -110,7 +110,7 @@ :func:`os.stat`) if possible. -.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, cloexec=None) This is an alias for the builtin :func:`open` function. @@ -187,8 +187,6 @@ The following table summarizes the ABCs provided by the :mod:`io` module: -.. tabularcolumns:: |l|l|L|L| - ========================= ================== ======================== ================================================== ABC Inherits Stub Methods Mixin Methods and Properties ========================= ================== ======================== ================================================== @@ -298,9 +296,6 @@ to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds *hint*. - Note that it's already possible to iterate on file objects using ``for - line in file: ...`` without calling ``file.readlines()``. - .. method:: seek(offset, whence=SEEK_SET) Change the stream position to the given byte *offset*. *offset* is @@ -492,7 +487,7 @@ Raw File I/O ^^^^^^^^^^^^ -.. class:: FileIO(name, mode='r', closefd=True, opener=None) +.. class:: FileIO(name, mode='r', closefd=True, opener=None, cloexec=None) :class:`FileIO` represents an OS-level file containing bytes data. It implements the :class:`RawIOBase` interface (and therefore the @@ -522,6 +517,10 @@ :mod:`os.open` as *opener* results in functionality similar to passing ``None``). + If *cloexec* is ``True``, set the :ref:`close-on-exec flag ` on + the newly created file descriptor. *cloexec* is ignored if *name* is an + integer file descriptor. + See the :func:`open` built-in function for examples on using the *opener* parameter. @@ -529,6 +528,9 @@ The *opener* parameter was added. The ``'x'`` mode was added. + .. versionchanged:: 3.4 + The *cloexec* parameter was added. + In addition to the attributes and methods from :class:`IOBase` and :class:`RawIOBase`, :class:`FileIO` provides the following data attributes: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/ipaddress.rst Fri Feb 01 23:12:09 2013 +0100 @@ -393,7 +393,7 @@ .. attribute:: is_link_local These attributes are true for the network as a whole if they are true - for both the network address and the broadcast address + true for both the network address and the broadcast address .. attribute:: network_address @@ -452,7 +452,7 @@ .. method:: overlaps(other) ``True`` if this network is partly or wholly contained in *other* or - *other* is wholly contained in this network. + or *other* is wholly contained in this network. .. method:: address_exclude(network) @@ -582,7 +582,7 @@ .. attribute:: is_site_local These attribute is true for the network as a whole if it is true - for both the network address and the broadcast address + true for both the network address and the broadcast address Operators diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/itertools.rst --- a/Doc/library/itertools.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/itertools.rst Fri Feb 01 23:12:09 2013 +0100 @@ -278,7 +278,7 @@ .. function:: count(start=0, step=1) - Make an iterator that returns evenly spaced values starting with number *start*. Often + Make an iterator that returns evenly spaced values starting with *n*. Often used as an argument to :func:`map` to generate consecutive data points. Also, used with :func:`zip` to add sequence numbers. Equivalent to:: @@ -705,9 +705,9 @@ next(b, None) return zip(a, b) - def grouper(iterable, n, fillvalue=None): + def grouper(n, iterable, fillvalue=None): "Collect data into fixed-length chunks or blocks" - # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx" + # grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" args = [iter(iterable)] * n return zip_longest(*args, fillvalue=fillvalue) @@ -762,7 +762,7 @@ """ Call a function repeatedly until an exception is raised. Converts a call-until-exception interface to an iterator interface. - Like builtins.iter(func, sentinel) but uses an exception instead + Like __builtin__.iter(func, sentinel) but uses an exception instead of a sentinel to end the loop. Examples: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/json.rst --- a/Doc/library/json.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/json.rst Fri Feb 01 23:12:09 2013 +0100 @@ -82,7 +82,6 @@ ... def default(self, obj): ... if isinstance(obj, complex): ... return [obj.real, obj.imag] - ... # Let the base class default method raise the TypeError ... return json.JSONEncoder.default(self, obj) ... >>> json.dumps(2 + 1j, cls=ComplexEncoder) @@ -102,7 +101,7 @@ "json": "obj" } $ echo '{1.2:3.4}' | python -mjson.tool - Expecting property name enclosed in double quotes: line 1 column 2 (char 1) + Expecting property name enclosed in double quotes: line 1 column 1 (char 1) .. highlight:: python3 @@ -123,8 +122,7 @@ sort_keys=False, **kw) Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting - :term:`file-like object`) using this :ref:`conversion table - `. + :term:`file-like object`). If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not of a basic type (:class:`str`, :class:`int`, :class:`float`, :class:`bool`, @@ -181,9 +179,8 @@ indent=None, separators=None, default=None, \ sort_keys=False, **kw) - Serialize *obj* to a JSON formatted :class:`str` using this :ref:`conversion - table `. The arguments have the same meaning as in - :func:`dump`. + Serialize *obj* to a JSON formatted :class:`str`. The arguments have the + same meaning as in :func:`dump`. .. note:: @@ -195,7 +192,7 @@ Keys in key/value pairs of JSON are always of the type :class:`str`. When a dictionary is converted into JSON, all the keys of the dictionary are - coerced to strings. As a result of this, if a dictionary is converted + coerced to strings. As a result of this, if a dictionary is convered into JSON and then back into a dictionary, the dictionary may not equal the original one. That is, ``loads(dumps(x)) != x`` if x has non-string keys. @@ -203,8 +200,7 @@ .. function:: load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) Deserialize *fp* (a ``.read()``-supporting :term:`file-like object` - containing a JSON document) to a Python object using this :ref:`conversion - table `. + containing a JSON document) to a Python object. *object_hook* is an optional function that will be called with the result of any object literal decoded (a :class:`dict`). The return value of @@ -249,7 +245,7 @@ .. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) Deserialize *s* (a :class:`str` instance containing a JSON document) to a - Python object using this :ref:`conversion table `. + Python object. The other arguments have the same meaning as in :func:`load`, except *encoding* which is ignored and deprecated. @@ -264,8 +260,6 @@ Performs the following translations in decoding by default: - .. _json-to-py-table: - +---------------+-------------------+ | JSON | Python | +===============+===================+ @@ -347,8 +341,6 @@ Supports the following objects and types by default: - .. _py-to-json-table: - +-------------------+---------------+ | Python | JSON | +===================+===============+ @@ -434,7 +426,6 @@ pass else: return list(iterable) - # Let the base class default method raise the TypeError return json.JSONEncoder.default(self, o) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/locale.rst --- a/Doc/library/locale.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/locale.rst Fri Feb 01 23:12:09 2013 +0100 @@ -55,8 +55,6 @@ Returns the database of the local conventions as a dictionary. This dictionary has the following strings as keys: - .. tabularcolumns:: |l|l|L| - +----------------------+-------------------------------------+--------------------------------+ | Category | Key | Meaning | +======================+=====================================+================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/logging.handlers.rst Fri Feb 01 23:12:09 2013 +0100 @@ -296,7 +296,7 @@ timed intervals. -.. class:: TimedRotatingFileHandler(filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False, atTime=None) +.. class:: TimedRotatingFileHandler(filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False) Returns a new instance of the :class:`TimedRotatingFileHandler` class. The specified file is opened and used as the stream for logging. On rotating it also @@ -317,15 +317,11 @@ +----------------+-----------------------+ | ``'D'`` | Days | +----------------+-----------------------+ - | ``'W0'-'W6'`` | Weekday (0=Monday) | + | ``'W'`` | Week day (0=Monday) | +----------------+-----------------------+ | ``'midnight'`` | Roll over at midnight | +----------------+-----------------------+ - When using weekday-based rotation, specify 'W0' for Monday, 'W1' for - Tuesday, and so on up to 'W6' for Sunday. In this case, the value passed for - *interval* isn't used. - The system will save old log files by appending extensions to the filename. The extensions are date-and-time based, using the strftime format ``%Y-%m-%d_%H-%M-%S`` or a leading portion thereof, depending on the @@ -346,12 +342,6 @@ If *delay* is true, then file opening is deferred until the first call to :meth:`emit`. - If *atTime* is not ``None``, it must be a ``datetime.time`` instance which - specifies the time of day when rollover occurs, for the cases where rollover - is set to happen "at midnight" or "on a particular weekday". - - .. versionchanged:: 3.4 - *atTime* parameter was added. .. method:: doRollover() diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/logging.rst --- a/Doc/library/logging.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/logging.rst Fri Feb 01 23:12:09 2013 +0100 @@ -70,25 +70,16 @@ .. attribute:: Logger.propagate - If this evaluates to true, events logged to this logger will be passed to the - handlers of higher level (ancestor) loggers, in addition to any handlers - attached to this logger. Messages are passed directly to the ancestor - loggers' handlers - neither the level nor filters of the ancestor loggers in - question are considered. + If this evaluates to true, logging messages are passed by this logger and by + its child loggers to the handlers of higher level (ancestor) loggers. + Messages are passed directly to the ancestor loggers' handlers - neither the + level nor filters of the ancestor loggers in question are considered. If this evaluates to false, logging messages are not passed to the handlers of ancestor loggers. The constructor sets this attribute to ``True``. - .. note:: If you attach a handler to a logger *and* one or more of its - ancestors, it may emit the same record multiple times. In general, you - should not need to attach a handler to more than one logger - if you just - attach it to the appropriate logger which is highest in the logger - hierarchy, then it will see all events logged by all descendant loggers, - provided that their propagate setting is left set to ``True``. A common - scenario is to attach handlers only to the root logger, and to let - propagation take care of the rest. .. method:: Logger.setLevel(lvl) @@ -264,10 +255,7 @@ .. method:: Logger.filter(record) Applies this logger's filters to the record and returns a true value if the - record is to be processed. The filters are consulted in turn, until one of - them returns a false value. If none of them return a false value, the record - will be processed (passed to handlers). If one returns a false value, no - further processing of the record occurs. + record is to be processed. .. method:: Logger.addHandler(hdlr) @@ -376,10 +364,7 @@ .. method:: Handler.filter(record) Applies this handler's filters to the record and returns a true value if the - record is to be processed. The filters are consulted in turn, until one of - them returns a false value. If none of them return a false value, the record - will be emitted. If one returns a false value, the handler will not emit the - record. + record is to be processed. .. method:: Handler.flush() @@ -562,12 +547,12 @@ yes. If deemed appropriate, the record may be modified in-place by this method. -Note that filters attached to handlers are consulted before an event is +Note that filters attached to handlers are consulted whenever an event is emitted by the handler, whereas filters attached to loggers are consulted -whenever an event is logged (using :meth:`debug`, :meth:`info`, -etc.), before sending an event to handlers. This means that events which have -been generated by descendant loggers will not be filtered by a logger's filter -setting, unless the filter has also been applied to those descendant loggers. +whenever an event is logged to the handler (using :meth:`debug`, :meth:`info`, +etc.) This means that events which have been generated by descendant loggers +will not be filtered by a logger's filter setting, unless the filter has also +been applied to those descendant loggers. You don't actually need to subclass ``Filter``: you can pass any instance which has a ``filter`` method with the same semantics. @@ -611,9 +596,7 @@ record. :param name: The name of the logger used to log the event represented by - this LogRecord. Note that this name will always have this - value, even though it may be emitted by a handler attached to - a different (ancestor) logger. + this LogRecord. :param level: The numeric level of the logging event (one of DEBUG, INFO etc.) Note that this is converted to *two* attributes of the LogRecord: ``levelno`` for the numeric value and ``levelname`` for the @@ -1037,8 +1020,6 @@ The following keyword arguments are supported. - .. tabularcolumns:: |l|L| - +--------------+---------------------------------------------+ | Format | Description | +==============+=============================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/lzma.rst --- a/Doc/library/lzma.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/lzma.rst Fri Feb 01 23:12:09 2013 +0100 @@ -158,7 +158,7 @@ In addition to being more CPU-intensive, compression with higher presets also requires much more memory (and produces output that needs more memory to decompress). With preset ``9`` for example, the overhead for an - :class:`LZMACompressor` object can be as high as 800 MiB. For this reason, + :class:`LZMACompressor` object can be as high as 800MiB. For this reason, it is generally best to stick with the default preset. The *filters* argument (if provided) should be a filter chain specifier. @@ -302,8 +302,8 @@ * ``preset``: A compression preset to use as a source of default values for options that are not specified explicitly. - * ``dict_size``: Dictionary size in bytes. This should be between 4 KiB and - 1.5 GiB (inclusive). + * ``dict_size``: Dictionary size in bytes. This should be between 4KiB and + 1.5GiB (inclusive). * ``lc``: Number of literal context bits. * ``lp``: Number of literal position bits. The sum ``lc + lp`` must be at most 4. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/mailcap.rst --- a/Doc/library/mailcap.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/mailcap.rst Fri Feb 01 23:12:09 2013 +0100 @@ -71,6 +71,6 @@ >>> import mailcap >>> d=mailcap.getcaps() - >>> mailcap.findmatch(d, 'video/mpeg', filename='tmp1223') - ('xmpeg tmp1223', {'view': 'xmpeg %s'}) + >>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223') + ('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'}) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/marshal.rst --- a/Doc/library/marshal.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/marshal.rst Fri Feb 01 23:12:09 2013 +0100 @@ -40,11 +40,10 @@ point numbers, complex numbers, strings, bytes, bytearrays, tuples, lists, sets, frozensets, dictionaries, and code objects, where it should be understood that tuples, lists, sets, frozensets and dictionaries are only supported as long as -the values contained therein are themselves supported. +the values contained therein are themselves supported; and recursive lists, sets +and dictionaries should not be written (they will cause infinite loops). The singletons :const:`None`, :const:`Ellipsis` and :exc:`StopIteration` can also be marshalled and unmarshalled. -For format *version* lower than 3, recursive lists, sets and dictionaries cannot -be written (see below). There are functions that read/write files as well as functions operating on strings. @@ -104,9 +103,7 @@ Indicates the format that the module uses. Version 0 is the historical format, version 1 shares interned strings and version 2 uses a binary format - for floating point numbers. - Version 3 adds support for object instancing and recursion. - The current version is 3. + for floating point numbers. The current version is 2. .. rubric:: Footnotes diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/math.rst --- a/Doc/library/math.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/math.rst Fri Feb 01 23:12:09 2013 +0100 @@ -4,9 +4,6 @@ .. module:: math :synopsis: Mathematical functions (sin() etc.). -.. testsetup:: - - from math import fsum This module is always available. It provides access to the mathematical functions defined by the C standard. @@ -80,6 +77,8 @@ .. function:: fsum(iterable) +.. testsetup:: + >>> from math import fsum Return an accurate floating point sum of values in the iterable. Avoids loss of precision by tracking multiple intermediate partial sums:: @@ -215,10 +214,6 @@ ``x`` is negative, and ``y`` is not an integer then ``pow(x, y)`` is undefined, and raises :exc:`ValueError`. - Unlike the built-in ``**`` operator, :func:`math.pow` converts both - its arguments to type :class:`float`. Use ``**`` or the built-in - :func:`pow` function for computing exact integer powers. - .. function:: sqrt(x) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/mmap.rst --- a/Doc/library/mmap.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/mmap.rst Fri Feb 01 23:12:09 2013 +0100 @@ -106,19 +106,19 @@ with open("hello.txt", "r+b") as f: # memory-map the file, size 0 means whole file - mm = mmap.mmap(f.fileno(), 0) + map = mmap.mmap(f.fileno(), 0) # read content via standard file methods - print(mm.readline()) # prints b"Hello Python!\n" + print(map.readline()) # prints b"Hello Python!\n" # read content via slice notation - print(mm[:5]) # prints b"Hello" + print(map[:5]) # prints b"Hello" # update content using slice notation; # note that new content must have same size - mm[6:] = b" world!\n" + map[6:] = b" world!\n" # ... and read again using standard file methods - mm.seek(0) - print(mm.readline()) # prints b"Hello world!\n" + map.seek(0) + print(map.readline()) # prints b"Hello world!\n" # close the map - mm.close() + map.close() :class:`mmap` can also be used as a context manager in a :keyword:`with` @@ -126,8 +126,8 @@ import mmap - with mmap.mmap(-1, 13) as mm: - mm.write("Hello world!") + with mmap.mmap(-1, 13) as map: + map.write("Hello world!") .. versionadded:: 3.2 Context manager support. @@ -139,16 +139,16 @@ import mmap import os - mm = mmap.mmap(-1, 13) - mm.write(b"Hello world!") + map = mmap.mmap(-1, 13) + map.write(b"Hello world!") pid = os.fork() if pid == 0: # In a child process - mm.seek(0) - print(mm.readline()) + map.seek(0) + print(map.readline()) - mm.close() + map.close() Memory-mapped file objects support the following methods: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/multiprocessing.rst --- a/Doc/library/multiprocessing.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/multiprocessing.rst Fri Feb 01 23:12:09 2013 +0100 @@ -284,9 +284,6 @@ print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]" -Note that the methods of a pool should only ever be used by the -process which created it. - Reference --------- @@ -446,7 +443,7 @@ cause other processes to deadlock. Note that the :meth:`start`, :meth:`join`, :meth:`is_alive`, - :meth:`terminate` and :attr:`exitcode` methods should only be called by + :meth:`terminate` and :attr:`exit_code` methods should only be called by the process that created the process object. Example usage of some of the methods of :class:`Process`: @@ -518,24 +515,6 @@ the :mod:`multiprocessing` namespace so you need to import them from :mod:`queue`. -.. note:: - - When an object is put on a queue, the object is pickled and a - background thread later flushes the pickled data to an underlying - pipe. This has some consequences which are a little surprising, - but should not cause any practical difficulties -- if they really - bother you then you can instead use a queue created with a - :ref:`manager `. - - (1) After putting an object on an empty queue there may be an - infinitesimal delay before the queue's :meth:`~Queue.empty` - method returns :const:`False` and :meth:`~Queue.get_nowait` can - return without raising :exc:`Queue.Empty`. - - (2) If multiple processes are enqueuing objects, it is possible for - the objects to be received at the other end out-of-order. - However, objects enqueued by the same process will always be in - the expected order with respect to each other. .. warning:: @@ -629,6 +608,7 @@ :exc:`queue.Empty` exception (*timeout* is ignored in that case). .. method:: get_nowait() + get_no_wait() Equivalent to ``get(False)``. @@ -659,13 +639,6 @@ the background thread from being joined automatically when the process exits -- see :meth:`join_thread`. - A better name for this method might be - ``allow_exit_without_flush()``. It is likely to cause enqueued - data to lost, and you almost certainly will not need to use it. - It is really only there if you need the current process to exit - immediately without waiting to flush enqueued data to the - underlying pipe, and you don't care about lost data. - .. class:: SimpleQueue() @@ -730,9 +703,6 @@ Return the number of CPUs in the system. May raise :exc:`NotImplementedError`. - .. seealso:: - :func:`os.cpu_count` - .. function:: current_process() Return the :class:`Process` object corresponding to the current process. @@ -831,7 +801,8 @@ .. method:: send_bytes(buffer[, offset[, size]]) - Send byte data from a :term:`bytes-like object` as a complete message. + Send byte data from an object supporting the buffer interface as a + complete message. If *offset* is given then data is read from that position in *buffer*. If *size* is given then that many bytes will be read from buffer. Very large @@ -862,7 +833,7 @@ :exc:`EOFError` if there is nothing left to receive and the other end was closed. - *buffer* must be a writable :term:`bytes-like object`. If + *buffer* must be an object satisfying the writable buffer interface. If *offset* is given then the message will be written into the buffer from that position. Offset must be a non-negative integer less than the length of *buffer* (in bytes). @@ -1674,13 +1645,10 @@ callbacks and has a parallel map implementation. *processes* is the number of worker processes to use. If *processes* is - ``None`` then the number returned by :func:`os.cpu_count` is used. If + ``None`` then the number returned by :func:`cpu_count` is used. If *initializer* is not ``None`` then each worker process will call ``initializer(*initargs)`` when it starts. - Note that the methods of the pool object should only be called by - the process which created the pool. - .. versionadded:: 3.2 *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 @@ -1881,7 +1849,7 @@ then a welcome message is sent to the other end of the connection. Otherwise :exc:`~multiprocessing.AuthenticationError` is raised. -.. function:: answer_challenge(connection, authkey) +.. function:: answerChallenge(connection, authkey) Receive a message, calculate the digest of the message using *authkey* as the key, and then send the digest back. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/nntplib.rst --- a/Doc/library/nntplib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/nntplib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -46,7 +46,7 @@ headers, and that you have right to post on the particular newsgroup):: >>> s = nntplib.NNTP('news.gmane.org') - >>> f = open('article.txt', 'rb') + >>> f = open('/tmp/article.txt', 'rb') >>> s.post(f) '240 Article posted successfully.' >>> s.quit() diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/numbers.rst --- a/Doc/library/numbers.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/numbers.rst Fri Feb 01 23:12:09 2013 +0100 @@ -71,10 +71,10 @@ .. class:: Integral - Subtypes :class:`Rational` and adds a conversion to :class:`int`. Provides - defaults for :func:`float`, :attr:`~Rational.numerator`, and - :attr:`~Rational.denominator`. Adds abstract methods for ``**`` and - bit-string operations: ``<<``, ``>>``, ``&``, ``^``, ``|``, ``~``. + Subtypes :class:`Rational` and adds a conversion to :class:`int`. + Provides defaults for :func:`float`, :attr:`~Rational.numerator`, and + :attr:`~Rational.denominator`, and bit-string operations: ``<<``, + ``>>``, ``&``, ``^``, ``|``, ``~``. Notes for type implementors diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/operator.rst --- a/Doc/library/operator.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/operator.rst Fri Feb 01 23:12:09 2013 +0100 @@ -11,9 +11,6 @@ import operator from operator import itemgetter, iadd -**Source code:** :source:`Lib/operator.py` - --------------- The :mod:`operator` module exports a set of efficient functions corresponding to the intrinsic operators of Python. For example, ``operator.add(x, y)`` is @@ -252,22 +249,13 @@ expect a function argument. -.. function:: attrgetter(attr) - attrgetter(*attrs) +.. function:: attrgetter(attr[, args...]) - Return a callable object that fetches *attr* from its operand. - If more than one attribute is requested, returns a tuple of attributes. - The attribute names can also contain dots. For example: - - * After ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. - - * After ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns - ``(b.name, b.date)``. - - * After ``f = attrgetter('name.first', 'name.last')``, the call ``f(b)`` - returns ``(r.name.first, r.name.last)``. - - Equivalent to:: + Return a callable object that fetches *attr* from its operand. If more than one + attribute is requested, returns a tuple of attributes. After, + ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After, + ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name, + b.date)``. Equivalent to:: def attrgetter(*items): if any(not isinstance(item, str) for item in items): @@ -287,19 +275,14 @@ return obj -.. function:: itemgetter(item) - itemgetter(*items) + The attribute names can also contain dots; after ``f = attrgetter('date.month')``, + the call ``f(b)`` returns ``b.date.month``. + +.. function:: itemgetter(item[, args...]) Return a callable object that fetches *item* from its operand using the operand's :meth:`__getitem__` method. If multiple items are specified, - returns a tuple of lookup values. For example: - - * After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``. - - * After ``g = itemgetter(2, 5, 3)``, the call ``g(r)`` returns - ``(r[2], r[5], r[3])``. - - Equivalent to:: + returns a tuple of lookup values. Equivalent to:: def itemgetter(*items): if len(items) == 1: @@ -338,14 +321,9 @@ Return a callable object that calls the method *name* on its operand. If additional arguments and/or keyword arguments are given, they will be given - to the method as well. For example: - - * After ``f = methodcaller('name')``, the call ``f(b)`` returns ``b.name()``. - - * After ``f = methodcaller('name', 'foo', bar=1)``, the call ``f(b)`` - returns ``b.name('foo', bar=1)``. - - Equivalent to:: + to the method as well. After ``f = methodcaller('name')``, the call ``f(b)`` + returns ``b.name()``. After ``f = methodcaller('name', 'foo', bar=1)``, the + call ``f(b)`` returns ``b.name('foo', bar=1)``. Equivalent to:: def methodcaller(name, *args, **kwargs): def caller(obj): diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/optparse.rst --- a/Doc/library/optparse.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/optparse.rst Fri Feb 01 23:12:09 2013 +0100 @@ -171,10 +171,10 @@ For example, consider this hypothetical command-line:: - prog -v --report report.txt foo bar + prog -v --report /tmp/report.txt foo bar ``-v`` and ``--report`` are both options. Assuming that ``--report`` -takes one argument, ``report.txt`` is an option argument. ``foo`` and +takes one argument, ``/tmp/report.txt`` is an option argument. ``foo`` and ``bar`` are positional arguments. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/os.path.rst --- a/Doc/library/os.path.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/os.path.rst Fri Feb 01 23:12:09 2013 +0100 @@ -218,11 +218,13 @@ .. function:: normpath(path) - Normalize a pathname by collapsing redundant separators and up-level - references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all - become ``A/B``. This string manipulation may change the meaning of a path - that contains symbolic links. On Windows, it converts forward slashes to - backward slashes. To normalize case, use :func:`normcase`. + Normalize a pathname. This collapses redundant separators and up-level + references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all become + ``A/B``. + + It does not normalize the case (use :func:`normcase` for that). On Windows, it + converts forward slashes to backward slashes. It should be understood that this + may change the meaning of the path if it contains symbolic links! .. function:: realpath(path) @@ -233,10 +235,8 @@ .. function:: relpath(path, start=None) - Return a relative filepath to *path* either from the current directory or - from an optional *start* directory. This is a path computation: the - filesystem is not accessed to confirm the existence or nature of *path* or - *start*. + Return a relative filepath to *path* either from the current directory or from + an optional *start* point. *start* defaults to :attr:`os.curdir`. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/os.rst --- a/Doc/library/os.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/os.rst Fri Feb 01 23:12:09 2013 +0100 @@ -683,19 +683,27 @@ if it is connected to a terminal; else return :const:`None`. -.. function:: dup(fd) - - Return a duplicate of file descriptor *fd*. +.. function:: dup(fd, cloexec=None) + + Return a duplicate of file descriptor *fd*. If *cloexec* is ``True``, set + the :ref:`close-on-exec flag `. Availability: Unix, Windows. - -.. function:: dup2(fd, fd2) + .. versionchanged:: 3.4 + *cloexec* parameter was added. + + +.. function:: dup2(fd, fd2, cloexec=None) Duplicate file descriptor *fd* to *fd2*, closing the latter first if necessary. + If *cloexec* is ``True``, set the :ref:`close-on-exec flag ` on *fd2*. Availability: Unix, Windows. + .. versionchanged:: 3.4 + *cloexec* parameter was added. + .. function:: fchmod(fd, mode) @@ -843,7 +851,7 @@ :data:`os.SEEK_HOLE` or :data:`os.SEEK_DATA`. -.. function:: open(file, flags, mode=0o777, *, dir_fd=None) +.. function:: open(file, flags, mode=0o777, *, dir_fd=None, cloexec=None) Open the file *file* and set various flags according to *flags* and possibly its mode according to *mode*. When computing *mode*, the current umask value @@ -851,14 +859,19 @@ For a description of the flag and mode values, see the C run-time documentation; flag constants (like :const:`O_RDONLY` and :const:`O_WRONLY`) are defined in - the :mod:`os` module. In particular, on Windows adding + this module too (see :ref:`open-constants`). In particular, on Windows adding :const:`O_BINARY` is needed to open files in binary mode. This function can support :ref:`paths relative to directory descriptors - ` with the *dir_fd* parameter. + `. + + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. Availability: Unix, Windows. + .. versionchanged:: 3.4 + *cloexec* parameter was added. + .. note:: This function is intended for low-level I/O. For normal usage, use the @@ -869,6 +882,233 @@ .. versionadded:: 3.3 The *dir_fd* argument. + +.. function:: openpty(cloexec=None) + + .. index:: module: pty + + Open a new pseudo-terminal pair. If *cloexec* is ``True``, set + the :ref:`close-on-exec flag `. Return a pair of file descriptors + ``(master, slave)`` for the pty and the tty, respectively. For a (slightly) + more portable approach, use the :mod:`pty` module. + + Availability: some flavors of Unix. + + .. versionchanged:: 3.4 + *cloexec* parameter was added. + + +.. function:: pipe(cloexec=None) + + Create a pipe. If *cloexec* is ``True``, set the :ref:`close-on-exec flag + `. Return a pair of file descriptors ``(r, w)`` usable for reading + and writing, respectively. + + Availability: Unix, Windows. + + .. versionchanged:: 3.4 + *cloexec* parameter was added. + + +.. function:: pipe2(flags) + + Create a pipe with *flags* set atomically. + *flags* can be constructed by ORing together one or more of these values: + :data:`O_NONBLOCK`, :data:`O_CLOEXEC`. + Return a pair of file descriptors ``(r, w)`` usable for reading and writing, + respectively. + + Availability: some flavors of Unix. + + .. versionadded:: 3.3 + + +.. function:: posix_fallocate(fd, offset, len) + + Ensures that enough disk space is allocated for the file specified by *fd* + starting from *offset* and continuing for *len* bytes. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. function:: posix_fadvise(fd, offset, len, advice) + + Announces an intention to access data in a specific pattern thus allowing + the kernel to make optimizations. + The advice applies to the region of the file specified by *fd* starting at + *offset* and continuing for *len* bytes. + *advice* is one of :data:`POSIX_FADV_NORMAL`, :data:`POSIX_FADV_SEQUENTIAL`, + :data:`POSIX_FADV_RANDOM`, :data:`POSIX_FADV_NOREUSE`, + :data:`POSIX_FADV_WILLNEED` or :data:`POSIX_FADV_DONTNEED`. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. data:: POSIX_FADV_NORMAL + POSIX_FADV_SEQUENTIAL + POSIX_FADV_RANDOM + POSIX_FADV_NOREUSE + POSIX_FADV_WILLNEED + POSIX_FADV_DONTNEED + + Flags that can be used in *advice* in :func:`posix_fadvise` that specify + the access pattern that is likely to be used. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. function:: pread(fd, buffersize, offset) + + Read from a file descriptor, *fd*, at a position of *offset*. It will read up + to *buffersize* number of bytes. The file offset remains unchanged. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. function:: pwrite(fd, string, offset) + + Write *string* to a file descriptor, *fd*, from *offset*, leaving the file + offset unchanged. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. function:: read(fd, n) + + Read at most *n* bytes from file descriptor *fd*. Return a bytestring containing the + bytes read. If the end of the file referred to by *fd* has been reached, an + empty bytes object is returned. + + Availability: Unix, Windows. + + .. note:: + + This function is intended for low-level I/O and must be applied to a file + descriptor as returned by :func:`os.open` or :func:`pipe`. To read a + "file object" returned by the built-in function :func:`open` or by + :func:`popen` or :func:`fdopen`, or :data:`sys.stdin`, use its + :meth:`~file.read` or :meth:`~file.readline` methods. + + +.. function:: sendfile(out, in, offset, nbytes) + sendfile(out, in, offset, nbytes, headers=None, trailers=None, flags=0) + + Copy *nbytes* bytes from file descriptor *in* to file descriptor *out* + starting at *offset*. + Return the number of bytes sent. When EOF is reached return 0. + + The first function notation is supported by all platforms that define + :func:`sendfile`. + + On Linux, if *offset* is given as ``None``, the bytes are read from the + current position of *in* and the position of *in* is updated. + + The second case may be used on Mac OS X and FreeBSD where *headers* and + *trailers* are arbitrary sequences of buffers that are written before and + after the data from *in* is written. It returns the same as the first case. + + On Mac OS X and FreeBSD, a value of 0 for *nbytes* specifies to send until + the end of *in* is reached. + + On Solaris, *out* may be the file descriptor of a regular file or the file + descriptor of a socket. On all other platforms, *out* must be the file + descriptor of an open socket. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. data:: SF_NODISKIO + SF_MNOWAIT + SF_SYNC + + Parameters to the :func:`sendfile` function, if the implementation supports + them. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. function:: readv(fd, buffers) + + Read from a file descriptor into a number of writable buffers. *buffers* is + an arbitrary sequence of writable buffers. Returns the total number of bytes + read. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. function:: tcgetpgrp(fd) + + Return the process group associated with the terminal given by *fd* (an open + file descriptor as returned by :func:`os.open`). + + Availability: Unix. + + +.. function:: tcsetpgrp(fd, pg) + + Set the process group associated with the terminal given by *fd* (an open file + descriptor as returned by :func:`os.open`) to *pg*. + + Availability: Unix. + + +.. function:: ttyname(fd) + + Return a string which specifies the terminal device associated with + file descriptor *fd*. If *fd* is not associated with a terminal device, an + exception is raised. + + Availability: Unix. + + +.. function:: write(fd, str) + + Write the bytestring in *str* to file descriptor *fd*. Return the number of + bytes actually written. + + Availability: Unix, Windows. + + .. note:: + + This function is intended for low-level I/O and must be applied to a file + descriptor as returned by :func:`os.open` or :func:`pipe`. To write a "file + object" returned by the built-in function :func:`open` or by :func:`popen` or + :func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its + :meth:`~file.write` method. + + +.. function:: writev(fd, buffers) + + Write the contents of *buffers* to file descriptor *fd*, where *buffers* + is an arbitrary sequence of buffers. + Returns the total number of bytes written. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. _open-constants: + +``open()`` flag constants +~~~~~~~~~~~~~~~~~~~~~~~~~ + The following constants are options for the *flags* parameter to the :func:`~os.open` function. They can be combined using the bitwise OR operator ``|``. Some of them are not available on all platforms. For descriptions of @@ -918,220 +1158,20 @@ O_DIRECTORY O_NOFOLLOW O_NOATIME - O_PATH These constants are GNU extensions and not present if they are not defined by the C library. -.. function:: openpty() - - .. index:: module: pty - - Open a new pseudo-terminal pair. Return a pair of file descriptors ``(master, - slave)`` for the pty and the tty, respectively. For a (slightly) more portable - approach, use the :mod:`pty` module. - - Availability: some flavors of Unix. - - -.. function:: pipe() - - Create a pipe. Return a pair of file descriptors ``(r, w)`` usable for reading - and writing, respectively. - - Availability: Unix, Windows. - - -.. function:: pipe2(flags) - - Create a pipe with *flags* set atomically. - *flags* can be constructed by ORing together one or more of these values: - :data:`O_NONBLOCK`, :data:`O_CLOEXEC`. - Return a pair of file descriptors ``(r, w)`` usable for reading and writing, - respectively. - - Availability: some flavors of Unix. - - .. versionadded:: 3.3 - - -.. function:: posix_fallocate(fd, offset, len) - - Ensures that enough disk space is allocated for the file specified by *fd* - starting from *offset* and continuing for *len* bytes. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. function:: posix_fadvise(fd, offset, len, advice) - - Announces an intention to access data in a specific pattern thus allowing - the kernel to make optimizations. - The advice applies to the region of the file specified by *fd* starting at - *offset* and continuing for *len* bytes. - *advice* is one of :data:`POSIX_FADV_NORMAL`, :data:`POSIX_FADV_SEQUENTIAL`, - :data:`POSIX_FADV_RANDOM`, :data:`POSIX_FADV_NOREUSE`, - :data:`POSIX_FADV_WILLNEED` or :data:`POSIX_FADV_DONTNEED`. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. data:: POSIX_FADV_NORMAL - POSIX_FADV_SEQUENTIAL - POSIX_FADV_RANDOM - POSIX_FADV_NOREUSE - POSIX_FADV_WILLNEED - POSIX_FADV_DONTNEED - - Flags that can be used in *advice* in :func:`posix_fadvise` that specify - the access pattern that is likely to be used. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. function:: pread(fd, buffersize, offset) - - Read from a file descriptor, *fd*, at a position of *offset*. It will read up - to *buffersize* number of bytes. The file offset remains unchanged. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. function:: pwrite(fd, string, offset) - - Write *string* to a file descriptor, *fd*, from *offset*, leaving the file - offset unchanged. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. function:: read(fd, n) - - Read at most *n* bytes from file descriptor *fd*. Return a bytestring containing the - bytes read. If the end of the file referred to by *fd* has been reached, an - empty bytes object is returned. - - Availability: Unix, Windows. - - .. note:: - - This function is intended for low-level I/O and must be applied to a file - descriptor as returned by :func:`os.open` or :func:`pipe`. To read a - "file object" returned by the built-in function :func:`open` or by - :func:`popen` or :func:`fdopen`, or :data:`sys.stdin`, use its - :meth:`~file.read` or :meth:`~file.readline` methods. - - -.. function:: sendfile(out, in, offset, nbytes) - sendfile(out, in, offset, nbytes, headers=None, trailers=None, flags=0) - - Copy *nbytes* bytes from file descriptor *in* to file descriptor *out* - starting at *offset*. - Return the number of bytes sent. When EOF is reached return 0. - - The first function notation is supported by all platforms that define - :func:`sendfile`. - - On Linux, if *offset* is given as ``None``, the bytes are read from the - current position of *in* and the position of *in* is updated. - - The second case may be used on Mac OS X and FreeBSD where *headers* and - *trailers* are arbitrary sequences of buffers that are written before and - after the data from *in* is written. It returns the same as the first case. - - On Mac OS X and FreeBSD, a value of 0 for *nbytes* specifies to send until - the end of *in* is reached. - - All platforms support sockets as *out* file descriptor, and some platforms - allow other types (e.g. regular file, pipe) as well. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. data:: SF_NODISKIO - SF_MNOWAIT - SF_SYNC - - Parameters to the :func:`sendfile` function, if the implementation supports - them. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. function:: readv(fd, buffers) - - Read from a file descriptor into a number of writable buffers. *buffers* is - an arbitrary sequence of writable buffers. Returns the total number of bytes - read. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. function:: tcgetpgrp(fd) - - Return the process group associated with the terminal given by *fd* (an open - file descriptor as returned by :func:`os.open`). - - Availability: Unix. - - -.. function:: tcsetpgrp(fd, pg) - - Set the process group associated with the terminal given by *fd* (an open file - descriptor as returned by :func:`os.open`) to *pg*. - - Availability: Unix. - - -.. function:: ttyname(fd) - - Return a string which specifies the terminal device associated with - file descriptor *fd*. If *fd* is not associated with a terminal device, an - exception is raised. - - Availability: Unix. - - -.. function:: write(fd, str) - - Write the bytestring in *str* to file descriptor *fd*. Return the number of - bytes actually written. - - Availability: Unix, Windows. - - .. note:: - - This function is intended for low-level I/O and must be applied to a file - descriptor as returned by :func:`os.open` or :func:`pipe`. To write a "file - object" returned by the built-in function :func:`open` or by :func:`popen` or - :func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its - :meth:`~file.write` method. - - -.. function:: writev(fd, buffers) - - Write the contents of *buffers* to file descriptor *fd*, where *buffers* - is an arbitrary sequence of buffers. - Returns the total number of bytes written. - - Availability: Unix. +.. data:: RTLD_LAZY + RTLD_NOW + RTLD_GLOBAL + RTLD_LOCAL + RTLD_NODELETE + RTLD_NOLOAD + RTLD_DEEPBIND + + See the Unix manual page :manpage:`dlopen(3)`. .. versionadded:: 3.3 @@ -1173,6 +1213,51 @@ Height of the terminal window in characters. +.. _cloexec: + +Close-on-exec flag +~~~~~~~~~~~~~~~~~~ + +A file descriptor has a close-on-exec flag which indicates if the file +descriptor will be inherited or not. + +On UNIX, the file descriptor will be closed on the execution of child processes +if the close-on-exec flag is set, the file descriptor is inherited by child +processes if the flag is cleared. + +On Windows, the file descriptor cannot be inherited if the close-on-exec flag is +set, the file descriptor is inherited by child processes if the flag is cleared +and if :c:func:`CreateProcess` is called with the *bInheritHandles* parameter +set to ``TRUE`` (when :class:`subprocess.Popen` is created with +``close_fds=False`` for example). + +Example of functions having the *cloexec* parameter: :func:`open`, +:func:`os.pipe`, :func:`socket.socket`. The default value of the *cloexec* +parameter is :func:`sys.getdefaultcloexec`, it is ``False`` at startup. It +can be set to ``True`` using :func:`sys.setdefaultcloexec`, by setting the +:envvar:`PYTHONCLOEXEC` environment variable, and using :option:`-e` command +line option. + + +.. function:: get_cloexec(fd) + + Get close-on-exe flag of the specified file descriptor. Return a :class:`bool`. + + Availability: Windows, Linux, FreeBSD, NetBSD, OpenBSD, Mac OS X, Solaris. + + .. versionadded:: 3.4 + +.. function:: set_cloexec(fd, cloexec=True) + + Set or clear close-on-exe flag on the specified file descriptor. + + Availability: Windows, Linux, FreeBSD, NetBSD, OpenBSD, Mac OS X, Solaris. + + .. versionadded:: 3.4 + + + + .. _os-file-dir: Files and Directories @@ -2005,10 +2090,9 @@ Create a symbolic link pointing to *source* named *link_name*. On Windows, a symlink represents either a file or a directory, and does not - morph to the target dynamically. If the target is present, the type of the - symlink will be created to match. Otherwise, the symlink will be created - as a directory if *target_is_directory* is ``True`` or a file symlink (the - default) otherwise. On non-Window platforms, *target_is_directory* is ignored. + morph to the target dynamically. If *target_is_directory* is set to ``True``, + the symlink will be created as a directory symlink, otherwise as a file symlink + (the default). On non-Window platforms, *target_is_directory* is ignored. Symbolic link support was introduced in Windows 6.0 (Vista). :func:`symlink` will raise a :exc:`NotImplementedError` on Windows versions earlier than 6.0. @@ -2024,7 +2108,6 @@ to the administrator level. Either obtaining the privilege or running your application as an administrator are ways to successfully create symlinks. - :exc:`OSError` is raised when the function is called by an unprivileged user. @@ -2312,7 +2395,7 @@ .. data:: XATTR_SIZE_MAX The maximum size the value of an extended attribute can be. Currently, this - is 64 KiB on Linux. + is 64 kilobytes on Linux. .. data:: XATTR_CREATE @@ -3029,7 +3112,7 @@ .. versionadded:: 3.3 -The following scheduling policies are exposed if they are supported by the +The following scheduling policies are exposed if they are a supported by the operating system. .. data:: SCHED_OTHER @@ -3138,6 +3221,10 @@ Return the set of CPUs the process with PID *pid* (or the current process if zero) is restricted to. + .. seealso:: + :func:`multiprocessing.cpu_count` returns the number of CPUs in the + system. + .. _os-path: @@ -3175,13 +3262,6 @@ Availability: Unix. -.. function:: cpu_count() - - Return the number of CPUs in the system. Returns None if undetermined. - - .. versionadded:: 3.4 - - .. function:: getloadavg() Return the number of processes in the system run queue averaged over the last @@ -3279,19 +3359,6 @@ The file path of the null device. For example: ``'/dev/null'`` for POSIX, ``'nul'`` for Windows. Also available via :mod:`os.path`. -.. data:: RTLD_LAZY - RTLD_NOW - RTLD_GLOBAL - RTLD_LOCAL - RTLD_NODELETE - RTLD_NOLOAD - RTLD_DEEPBIND - - Flags for use with the :func:`~sys.setdlopenflags` and - :func:`~sys.getdlopenflags` functions. See the Unix manual page - :manpage:`dlopen(3)` for what the different flags mean. - - .. versionadded:: 3.3 .. _os-miscfunc: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/pipes.rst --- a/Doc/library/pipes.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/pipes.rst Fri Feb 01 23:12:09 2013 +0100 @@ -26,12 +26,12 @@ Example:: >>> import pipes - >>> t = pipes.Template() + >>> t=pipes.Template() >>> t.append('tr a-z A-Z', '--') - >>> f = t.open('pipefile', 'w') + >>> f=t.open('/tmp/1', 'w') >>> f.write('hello world') >>> f.close() - >>> open('pipefile').read() + >>> open('/tmp/1').read() 'HELLO WORLD' diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/plistlib.rst --- a/Doc/library/plistlib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/plistlib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -47,8 +47,8 @@ .. function:: readPlist(pathOrFile) - Read a plist file. *pathOrFile* may either be a file name or a (readable and - binary) file object. Return the unpacked root object (which usually is a + Read a plist file. *pathOrFile* may either be a file name or a (readable) + file object. Return the unpacked root object (which usually is a dictionary). The XML data is parsed using the Expat parser from :mod:`xml.parsers.expat` @@ -59,7 +59,7 @@ .. function:: writePlist(rootObject, pathOrFile) Write *rootObject* to a plist file. *pathOrFile* may either be a file name - or a (writable and binary) file object. + or a (writable) file object. A :exc:`TypeError` will be raised if the object is of an unsupported type or a container that contains objects of unsupported types. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/posix.rst --- a/Doc/library/posix.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/posix.rst Fri Feb 01 23:12:09 2013 +0100 @@ -37,7 +37,7 @@ .. sectionauthor:: Steve Clift Several operating systems (including AIX, HP-UX, Irix and Solaris) provide -support for files that are larger than 2 GiB from a C programming model where +support for files that are larger than 2 GB from a C programming model where :c:type:`int` and :c:type:`long` are 32-bit values. This is typically accomplished by defining the relevant size and offset types as 64-bit values. Such files are sometimes referred to as :dfn:`large files`. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/pprint.rst --- a/Doc/library/pprint.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/pprint.rst Fri Feb 01 23:12:09 2013 +0100 @@ -14,8 +14,8 @@ Python data structures in a form which can be used as input to the interpreter. If the formatted structures include objects which are not fundamental Python types, the representation may not be loadable. This may be the case if objects -such as files, sockets or classes are included, as well as many other -objects which are not representable as Python literals. +such as files, sockets, classes, or instances are included, as well as many +other built-in objects which are not representable as Python constants. The formatted representation keeps objects on a single line if it can, and breaks them onto multiple lines if they don't fit within the allowed width. @@ -65,7 +65,7 @@ ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) -The :mod:`pprint` module also provides several shortcut functions: +The :class:`PrettyPrinter` class supports several derivative functions: .. function:: pformat(object, indent=1, width=80, depth=None) @@ -193,141 +193,101 @@ ------- To demonstrate several uses of the :func:`pprint` function and its parameters, -let's fetch information about a project from `PyPI `_:: +let's fetch information about a project from PyPI:: >>> import json >>> import pprint >>> from urllib.request import urlopen - >>> with urlopen('http://pypi.python.org/pypi/Twisted/json') as url: + >>> with urlopen('http://pypi.python.org/pypi/configparser/json') as url: ... http_info = url.info() ... raw_data = url.read().decode(http_info.get_content_charset()) >>> project_info = json.loads(raw_data) + >>> result = {'headers': http_info.items(), 'body': project_info} In its basic form, :func:`pprint` shows the whole object:: - >>> pprint.pprint(project_info) - {'info': {'_pypi_hidden': False, - '_pypi_ordering': 125, - 'author': 'Glyph Lefkowitz', - 'author_email': 'glyph@twistedmatrix.com', - 'bugtrack_url': '', - 'cheesecake_code_kwalitee_id': None, - 'cheesecake_documentation_id': None, - 'cheesecake_installability_id': None, - 'classifiers': ['Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 2 :: Only'], - 'description': 'An extensible framework for Python programming, ' - 'with special focus\r\n' - 'on event-based network programming and ' - 'multiprotocol integration.', - 'docs_url': '', - 'download_url': 'UNKNOWN', - 'home_page': 'http://twistedmatrix.com/', - 'keywords': '', - 'license': 'MIT', - 'maintainer': '', - 'maintainer_email': '', - 'name': 'Twisted', - 'package_url': 'http://pypi.python.org/pypi/Twisted', - 'platform': 'UNKNOWN', - 'release_url': 'http://pypi.python.org/pypi/Twisted/12.3.0', - 'requires_python': None, - 'stable_version': None, - 'summary': 'An asynchronous networking framework written in Python', - 'version': '12.3.0'}, - 'urls': [{'comment_text': '', - 'downloads': 71844, - 'filename': 'Twisted-12.3.0.tar.bz2', - 'has_sig': False, - 'md5_digest': '6e289825f3bf5591cfd670874cc0862d', - 'packagetype': 'sdist', - 'python_version': 'source', - 'size': 2615733, - 'upload_time': '2012-12-26T12:47:03', - 'url': 'https://pypi.python.org/packages/source/T/Twisted/Twisted-12.3.0.tar.bz2'}, - {'comment_text': '', - 'downloads': 5224, - 'filename': 'Twisted-12.3.0.win32-py2.7.msi', - 'has_sig': False, - 'md5_digest': '6b778f5201b622a5519a2aca1a2fe512', - 'packagetype': 'bdist_msi', - 'python_version': '2.7', - 'size': 2916352, - 'upload_time': '2012-12-26T12:48:15', - 'url': 'https://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.3.0.win32-py2.7.msi'}]} + >>> pprint.pprint(result) + {'body': {'info': {'_pypi_hidden': False, + '_pypi_ordering': 12, + 'classifiers': ['Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules'], + 'download_url': 'UNKNOWN', + 'home_page': 'http://docs.python.org/py3k/library/configparser.html', + 'keywords': 'configparser ini parsing conf cfg configuration file', + 'license': 'MIT', + 'name': 'configparser', + 'package_url': 'http://pypi.python.org/pypi/configparser', + 'platform': 'any', + 'release_url': 'http://pypi.python.org/pypi/configparser/3.2.0r3', + 'requires_python': None, + 'stable_version': None, + 'summary': 'This library brings the updated configparser from Python 3.2+ to Python 2.6-2.7.', + 'version': '3.2.0r3'}, + 'urls': [{'comment_text': '', + 'downloads': 47, + 'filename': 'configparser-3.2.0r3.tar.gz', + 'has_sig': False, + 'md5_digest': '8500fd87c61ac0de328fc996fce69b96', + 'packagetype': 'sdist', + 'python_version': 'source', + 'size': 32281, + 'upload_time': '2011-05-10T16:28:50', + 'url': 'http://pypi.python.org/packages/source/c/configparser/configparser-3.2.0r3.tar.gz'}]}, + 'headers': [('Date', 'Sat, 14 May 2011 12:48:52 GMT'), + ('Server', 'Apache/2.2.16 (Debian)'), + ('Content-Disposition', 'inline'), + ('Connection', 'close'), + ('Transfer-Encoding', 'chunked'), + ('Content-Type', 'application/json; charset="UTF-8"')]} The result can be limited to a certain *depth* (ellipsis is used for deeper contents):: - >>> pprint.pprint(project_info, depth=2) - {'info': {'_pypi_hidden': False, - '_pypi_ordering': 125, - 'author': 'Glyph Lefkowitz', - 'author_email': 'glyph@twistedmatrix.com', - 'bugtrack_url': '', - 'cheesecake_code_kwalitee_id': None, - 'cheesecake_documentation_id': None, - 'cheesecake_installability_id': None, - 'classifiers': [...], - 'description': 'An extensible framework for Python programming, ' - 'with special focus\r\n' - 'on event-based network programming and ' - 'multiprotocol integration.', - 'docs_url': '', - 'download_url': 'UNKNOWN', - 'home_page': 'http://twistedmatrix.com/', - 'keywords': '', - 'license': 'MIT', - 'maintainer': '', - 'maintainer_email': '', - 'name': 'Twisted', - 'package_url': 'http://pypi.python.org/pypi/Twisted', - 'platform': 'UNKNOWN', - 'release_url': 'http://pypi.python.org/pypi/Twisted/12.3.0', - 'requires_python': None, - 'stable_version': None, - 'summary': 'An asynchronous networking framework written in Python', - 'version': '12.3.0'}, - 'urls': [{...}, {...}]} + >>> pprint.pprint(result, depth=3) + {'body': {'info': {'_pypi_hidden': False, + '_pypi_ordering': 12, + 'classifiers': [...], + 'download_url': 'UNKNOWN', + 'home_page': 'http://docs.python.org/py3k/library/configparser.html', + 'keywords': 'configparser ini parsing conf cfg configuration file', + 'license': 'MIT', + 'name': 'configparser', + 'package_url': 'http://pypi.python.org/pypi/configparser', + 'platform': 'any', + 'release_url': 'http://pypi.python.org/pypi/configparser/3.2.0r3', + 'requires_python': None, + 'stable_version': None, + 'summary': 'This library brings the updated configparser from Python 3.2+ to Python 2.6-2.7.', + 'version': '3.2.0r3'}, + 'urls': [{...}]}, + 'headers': [('Date', 'Sat, 14 May 2011 12:48:52 GMT'), + ('Server', 'Apache/2.2.16 (Debian)'), + ('Content-Disposition', 'inline'), + ('Connection', 'close'), + ('Transfer-Encoding', 'chunked'), + ('Content-Type', 'application/json; charset="UTF-8"')]} -Additionally, maximum character *width* can be suggested. If a long object -cannot be split, the specified width will be exceeded:: +Additionally, maximum *width* can be suggested. If a long object cannot be +split, the specified width will be exceeded:: - >>> pprint.pprint(project_info, depth=2, width=50) - {'info': {'_pypi_hidden': False, - '_pypi_ordering': 125, - 'author': 'Glyph Lefkowitz', - 'author_email': 'glyph@twistedmatrix.com', - 'bugtrack_url': '', - 'cheesecake_code_kwalitee_id': None, - 'cheesecake_documentation_id': None, - 'cheesecake_installability_id': None, - 'classifiers': [...], - 'description': 'An extensible ' - 'framework for ' - 'Python programming, ' - 'with special ' - 'focus\r\n' - 'on event-based ' - 'network programming ' - 'and multiprotocol ' - 'integration.', - 'docs_url': '', - 'download_url': 'UNKNOWN', - 'home_page': 'http://twistedmatrix.com/', - 'keywords': '', - 'license': 'MIT', - 'maintainer': '', - 'maintainer_email': '', - 'name': 'Twisted', - 'package_url': 'http://pypi.python.org/pypi/Twisted', - 'platform': 'UNKNOWN', - 'release_url': 'http://pypi.python.org/pypi/Twisted/12.3.0', - 'requires_python': None, - 'stable_version': None, - 'summary': 'An asynchronous ' - 'networking framework ' - 'written in Python', - 'version': '12.3.0'}, - 'urls': [{...}, {...}]} + >>> pprint.pprint(result['headers'], width=30) + [('Date', + 'Sat, 14 May 2011 12:48:52 GMT'), + ('Server', + 'Apache/2.2.16 (Debian)'), + ('Content-Disposition', + 'inline'), + ('Connection', 'close'), + ('Transfer-Encoding', + 'chunked'), + ('Content-Type', + 'application/json; charset="UTF-8"')] diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/profile.rst --- a/Doc/library/profile.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/profile.rst Fri Feb 01 23:12:09 2013 +0100 @@ -4,6 +4,11 @@ The Python Profilers ******************** +.. sectionauthor:: James Roskind + +.. module:: profile + :synopsis: Python source profiler. + **Source code:** :source:`Lib/profile.py` and :source:`Lib/pstats.py` -------------- @@ -17,13 +22,14 @@ single: deterministic profiling single: profiling, deterministic -:mod:`cProfile` and :mod:`profile` provide :dfn:`deterministic profiling` of -Python programs. A :dfn:`profile` is a set of statistics that describes how -often and for how long various parts of the program executed. These statistics -can be formatted into reports via the :mod:`pstats` module. +A :dfn:`profiler` is a program that describes the run time performance of a +program, providing a variety of statistics. This documentation describes the +profiler functionality provided in the modules :mod:`cProfile`, :mod:`profile` +and :mod:`pstats`. This profiler provides :dfn:`deterministic profiling` of +Python programs. It also provides a series of report generation tools to allow +users to rapidly examine the results of a profile operation. -The Python standard library provides two different implementations of the same -profiling interface: +The Python standard library provides two different profilers: 1. :mod:`cProfile` is recommended for most users; it's a C extension with reasonable overhead that makes it suitable for profiling long-running @@ -31,9 +37,14 @@ Czotter. 2. :mod:`profile`, a pure Python module whose interface is imitated by - :mod:`cProfile`, but which adds significant overhead to profiled programs. - If you're trying to extend the profiler in some way, the task might be easier - with this module. + :mod:`cProfile`. Adds significant overhead to profiled programs. If you're + trying to extend the profiler in some way, the task might be easier with this + module. + +The :mod:`profile` and :mod:`cProfile` modules export the same interface, so +they are mostly interchangeable; :mod:`cProfile` has a much lower overhead but +is newer and might not be available on all systems. :mod:`cProfile` is really a +compatibility layer on top of the internal :mod:`_lsprof` module. .. note:: @@ -54,94 +65,57 @@ provides a very brief overview, and allows a user to rapidly perform profiling on an existing application. -To profile a function that takes a single argument, you can do:: +To profile an application with a main entry point of :func:`foo`, you would add +the following to your module:: import cProfile - import re - cProfile.run('re.compile("foo|bar")') + cProfile.run('foo()') (Use :mod:`profile` instead of :mod:`cProfile` if the latter is not available on your system.) -The above action would run :func:`re.compile` and print profile results like -the following:: - - 197 function calls (192 primitive calls) in 0.002 seconds - - Ordered by: standard name - - ncalls tottime percall cumtime percall filename:lineno(function) - 1 0.000 0.000 0.001 0.001 :1() - 1 0.000 0.000 0.001 0.001 re.py:212(compile) - 1 0.000 0.000 0.001 0.001 re.py:268(_compile) - 1 0.000 0.000 0.000 0.000 sre_compile.py:172(_compile_charset) - 1 0.000 0.000 0.000 0.000 sre_compile.py:201(_optimize_charset) - 4 0.000 0.000 0.000 0.000 sre_compile.py:25(_identityfunction) - 3/1 0.000 0.000 0.000 0.000 sre_compile.py:33(_compile) - -The first line indicates that 197 calls were monitored. Of those calls, 192 -were :dfn:`primitive`, meaning that the call was not induced via recursion. The -next line: ``Ordered by: standard name``, indicates that the text string in the -far right column was used to sort the output. The column headings include: - -ncalls - for the number of calls, - -tottime - for the total time spent in the given function (and excluding time made in - calls to sub-functions) - -percall - is the quotient of ``tottime`` divided by ``ncalls`` - -cumtime - is the cumulative time spent in this and all subfunctions (from invocation - till exit). This figure is accurate *even* for recursive functions. - -percall - is the quotient of ``cumtime`` divided by primitive calls - -filename:lineno(function) - provides the respective data of each function - -When there are two numbers in the first column (for example ``3/1``), it means -that the function recursed. The second value is the number of primitive calls -and the former is the total number of calls. Note that when the function does -not recurse, these two values are the same, and only the single figure is -printed. - -Instead of printing the output at the end of the profile run, you can save the -results to a file by specifying a filename to the :func:`run` function:: +The above action would cause :func:`foo` to be run, and a series of informative +lines (the profile) to be printed. The above approach is most useful when +working with the interpreter. If you would like to save the results of a +profile into a file for later examination, you can supply a file name as the +second argument to the :func:`run` function:: import cProfile - import re - cProfile.run('re.compile("foo|bar")', 'restats') + cProfile.run('foo()', 'fooprof') -The :class:`pstats.Stats` class reads profile results from a file and formats -them in various ways. - -The file :mod:`cProfile` can also be invoked as a script to profile another +The file :file:`cProfile.py` can also be invoked as a script to profile another script. For example:: - python -m cProfile [-o output_file] [-s sort_order] myscript.py + python -m cProfile myscript.py -``-o`` writes the profile results to a file instead of to stdout +:file:`cProfile.py` accepts two optional arguments on the command line:: -``-s`` specifies one of the :func:`~pstats.Stats.sort_stats` sort values to sort -the output by. This only applies when ``-o`` is not supplied. + cProfile.py [-o output_file] [-s sort_order] -The :mod:`pstats` module's :class:`~pstats.Stats` class has a variety of methods -for manipulating and printing the data saved into a profile results file:: +``-s`` only applies to standard output (``-o`` is not supplied). +Look in the :class:`Stats` documentation for valid sort values. + +When you wish to review the profile, you should use the methods in the +:mod:`pstats` module. Typically you would load the statistics data as follows:: import pstats - p = pstats.Stats('restats') + p = pstats.Stats('fooprof') + +The class :class:`Stats` (the above code just created an instance of this class) +has a variety of methods for manipulating and printing the data that was just +read into ``p``. When you ran :func:`cProfile.run` above, what was printed was +the result of three method calls:: + p.strip_dirs().sort_stats(-1).print_stats() -The :meth:`~pstats.Stats.strip_dirs` method removed the extraneous path from all -the module names. The :meth:`~pstats.Stats.sort_stats` method sorted all the -entries according to the standard module/line/name string that is printed. The -:meth:`~pstats.Stats.print_stats` method printed out all the statistics. You -might try the following sort calls:: +The first method removed the extraneous path from all the module names. The +second method sorted all the entries according to the standard module/line/name +string that is printed. The third method printed out all the statistics. You +might try the following sort calls: + +.. (this is to comply with the semantics of the old profiler). + +:: p.sort_stats('name') p.print_stats() @@ -190,301 +164,12 @@ guess what the following functions do:: p.print_callees() - p.add('restats') + p.add('fooprof') Invoked as a script, the :mod:`pstats` module is a statistics browser for reading and examining profile dumps. It has a simple line-oriented interface (implemented using :mod:`cmd`) and interactive help. -:mod:`profile` and :mod:`cProfile` Module Reference -======================================================= - -.. module:: cProfile -.. module:: profile - :synopsis: Python source profiler. - -Both the :mod:`profile` and :mod:`cProfile` modules provide the following -functions: - -.. function:: run(command, filename=None, sort=-1) - - This function takes a single argument that can be passed to the :func:`exec` - function, and an optional file name. In all cases this routine executes:: - - exec(command, __main__.__dict__, __main__.__dict__) - - and gathers profiling statistics from the execution. If no file name is - present, then this function automatically creates a :class:`~pstats.Stats` - instance and prints a simple profiling report. If the sort value is specified - it is passed to this :class:`~pstats.Stats` instance to control how the - results are sorted. - -.. function:: runctx(command, globals, locals, filename=None) - - This function is similar to :func:`run`, with added arguments to supply the - globals and locals dictionaries for the *command* string. This routine - executes:: - - exec(command, globals, locals) - - and gathers profiling statistics as in the :func:`run` function above. - -.. class:: Profile(timer=None, timeunit=0.0, subcalls=True, builtins=True) - - This class is normally only used if more precise control over profiling is - needed than what the :func:`cProfile.run` function provides. - - A custom timer can be supplied for measuring how long code takes to run via - the *timer* argument. This must be a function that returns a single number - representing the current time. If the number is an integer, the *timeunit* - specifies a multiplier that specifies the duration of each unit of time. For - example, if the timer returns times measured in thousands of seconds, the - time unit would be ``.001``. - - Directly using the :class:`Profile` class allows formatting profile results - without writing the profile data to a file:: - - import cProfile, pstats, io - pr = cProfile.Profile() - pr.enable() - ... do something ... - pr.disable() - s = io.StringIO() - ps = pstats.Stats(pr, stream=s) - ps.print_results() - - .. method:: enable() - - Start collecting profiling data. - - .. method:: disable() - - Stop collecting profiling data. - - .. method:: create_stats() - - Stop collecting profiling data and record the results internally - as the current profile. - - .. method:: print_stats(sort=-1) - - Create a :class:`~pstats.Stats` object based on the current - profile and print the results to stdout. - - .. method:: dump_stats(filename) - - Write the results of the current profile to *filename*. - - .. method:: run(cmd) - - Profile the cmd via :func:`exec`. - - .. method:: runctx(cmd, globals, locals) - - Profile the cmd via :func:`exec` with the specified global and - local environment. - - .. method:: runcall(func, *args, **kwargs) - - Profile ``func(*args, **kwargs)`` - -.. _profile-stats: - -The :class:`Stats` Class -======================== - -Analysis of the profiler data is done using the :class:`~pstats.Stats` class. - -.. module:: pstats - :synopsis: Statistics object for use with the profiler. - -.. class:: Stats(*filenames or profile, stream=sys.stdout) - - This class constructor creates an instance of a "statistics object" from a - *filename* (or list of filenames) or from a :class:`Profile` instance. Output - will be printed to the stream specified by *stream*. - - The file selected by the above constructor must have been created by the - corresponding version of :mod:`profile` or :mod:`cProfile`. To be specific, - there is *no* file compatibility guaranteed with future versions of this - profiler, and there is no compatibility with files produced by other - profilers. If several files are provided, all the statistics for identical - functions will be coalesced, so that an overall view of several processes can - be considered in a single report. If additional files need to be combined - with data in an existing :class:`~pstats.Stats` object, the - :meth:`~pstats.Stats.add` method can be used. - - Instead of reading the profile data from a file, a :class:`cProfile.Profile` - or :class:`profile.Profile` object can be used as the profile data source. - - :class:`Stats` objects have the following methods: - - .. method:: strip_dirs() - - This method for the :class:`Stats` class removes all leading path - information from file names. It is very useful in reducing the size of - the printout to fit within (close to) 80 columns. This method modifies - the object, and the stripped information is lost. After performing a - strip operation, the object is considered to have its entries in a - "random" order, as it was just after object initialization and loading. - If :meth:`~pstats.Stats.strip_dirs` causes two function names to be - indistinguishable (they are on the same line of the same filename, and - have the same function name), then the statistics for these two entries - are accumulated into a single entry. - - - .. method:: add(*filenames) - - This method of the :class:`Stats` class accumulates additional profiling - information into the current profiling object. Its arguments should refer - to filenames created by the corresponding version of :func:`profile.run` - or :func:`cProfile.run`. Statistics for identically named (re: file, line, - name) functions are automatically accumulated into single function - statistics. - - - .. method:: dump_stats(filename) - - Save the data loaded into the :class:`Stats` object to a file named - *filename*. The file is created if it does not exist, and is overwritten - if it already exists. This is equivalent to the method of the same name - on the :class:`profile.Profile` and :class:`cProfile.Profile` classes. - - - .. method:: sort_stats(*keys) - - This method modifies the :class:`Stats` object by sorting it according to - the supplied criteria. The argument is typically a string identifying the - basis of a sort (example: ``'time'`` or ``'name'``). - - When more than one key is provided, then additional keys are used as - secondary criteria when there is equality in all keys selected before - them. For example, ``sort_stats('name', 'file')`` will sort all the - entries according to their function name, and resolve all ties (identical - function names) by sorting by file name. - - Abbreviations can be used for any key names, as long as the abbreviation - is unambiguous. The following are the keys currently defined: - - +------------------+----------------------+ - | Valid Arg | Meaning | - +==================+======================+ - | ``'calls'`` | call count | - +------------------+----------------------+ - | ``'cumulative'`` | cumulative time | - +------------------+----------------------+ - | ``'cumtime'`` | cumulative time | - +------------------+----------------------+ - | ``'file'`` | file name | - +------------------+----------------------+ - | ``'filename'`` | file name | - +------------------+----------------------+ - | ``'module'`` | file name | - +------------------+----------------------+ - | ``'ncalls'`` | call count | - +------------------+----------------------+ - | ``'pcalls'`` | primitive call count | - +------------------+----------------------+ - | ``'line'`` | line number | - +------------------+----------------------+ - | ``'name'`` | function name | - +------------------+----------------------+ - | ``'nfl'`` | name/file/line | - +------------------+----------------------+ - | ``'stdname'`` | standard name | - +------------------+----------------------+ - | ``'time'`` | internal time | - +------------------+----------------------+ - | ``'tottime'`` | internal time | - +------------------+----------------------+ - - Note that all sorts on statistics are in descending order (placing most - time consuming items first), where as name, file, and line number searches - are in ascending order (alphabetical). The subtle distinction between - ``'nfl'`` and ``'stdname'`` is that the standard name is a sort of the - name as printed, which means that the embedded line numbers get compared - in an odd way. For example, lines 3, 20, and 40 would (if the file names - were the same) appear in the string order 20, 3 and 40. In contrast, - ``'nfl'`` does a numeric compare of the line numbers. In fact, - ``sort_stats('nfl')`` is the same as ``sort_stats('name', 'file', - 'line')``. - - For backward-compatibility reasons, the numeric arguments ``-1``, ``0``, - ``1``, and ``2`` are permitted. They are interpreted as ``'stdname'``, - ``'calls'``, ``'time'``, and ``'cumulative'`` respectively. If this old - style format (numeric) is used, only one sort key (the numeric key) will - be used, and additional arguments will be silently ignored. - - .. For compatibility with the old profiler. - - - .. method:: reverse_order() - - This method for the :class:`Stats` class reverses the ordering of the - basic list within the object. Note that by default ascending vs - descending order is properly selected based on the sort key of choice. - - .. This method is provided primarily for compatibility with the old - profiler. - - - .. method:: print_stats(*restrictions) - - This method for the :class:`Stats` class prints out a report as described - in the :func:`profile.run` definition. - - The order of the printing is based on the last - :meth:`~pstats.Stats.sort_stats` operation done on the object (subject to - caveats in :meth:`~pstats.Stats.add` and - :meth:`~pstats.Stats.strip_dirs`). - - The arguments provided (if any) can be used to limit the list down to the - significant entries. Initially, the list is taken to be the complete set - of profiled functions. Each restriction is either an integer (to select a - count of lines), or a decimal fraction between 0.0 and 1.0 inclusive (to - select a percentage of lines), or a regular expression (to pattern match - the standard name that is printed. If several restrictions are provided, - then they are applied sequentially. For example:: - - print_stats(.1, 'foo:') - - would first limit the printing to first 10% of list, and then only print - functions that were part of filename :file:`.\*foo:`. In contrast, the - command:: - - print_stats('foo:', .1) - - would limit the list to all functions having file names :file:`.\*foo:`, - and then proceed to only print the first 10% of them. - - - .. method:: print_callers(*restrictions) - - This method for the :class:`Stats` class prints a list of all functions - that called each function in the profiled database. The ordering is - identical to that provided by :meth:`~pstats.Stats.print_stats`, and the - definition of the restricting argument is also identical. Each caller is - reported on its own line. The format differs slightly depending on the - profiler that produced the stats: - - * With :mod:`profile`, a number is shown in parentheses after each caller - to show how many times this specific call was made. For convenience, a - second non-parenthesized number repeats the cumulative time spent in the - function at the right. - - * With :mod:`cProfile`, each caller is preceded by three numbers: the - number of times this specific call was made, and the total and - cumulative times spent in the current function while it was invoked by - this specific caller. - - - .. method:: print_callees(*restrictions) - - This method for the :class:`Stats` class prints a list of all function - that were called by the indicated function. Aside from this reversal of - direction of calls (re: called vs was called by), the arguments and - ordering are identical to the :meth:`~pstats.Stats.print_callers` method. - .. _deterministic-profiling: @@ -519,7 +204,296 @@ implementations. -.. _profile-limitations: +Reference Manual -- :mod:`profile` and :mod:`cProfile` +====================================================== + +.. module:: cProfile + :synopsis: Python profiler + + +The primary entry point for the profiler is the global function +:func:`profile.run` (resp. :func:`cProfile.run`). It is typically used to create +any profile information. The reports are formatted and printed using methods of +the class :class:`pstats.Stats`. The following is a description of all of these +standard entry points and functions. For a more in-depth view of some of the +code, consider reading the later section on Profiler Extensions, which includes +discussion of how to derive "better" profilers from the classes presented, or +reading the source code for these modules. + + +.. function:: run(command, filename=None, sort=-1) + + This function takes a single argument that can be passed to the :func:`exec` + function, and an optional file name. In all cases this routine attempts to + :func:`exec` its first argument, and gather profiling statistics from the + execution. If no file name is present, then this function automatically + prints a simple profiling report, sorted by the standard name string + (file/line/function-name) that is presented in each line. The following is a + typical output from such a call:: + + 2706 function calls (2004 primitive calls) in 4.504 CPU seconds + + Ordered by: standard name + + ncalls tottime percall cumtime percall filename:lineno(function) + 2 0.006 0.003 0.953 0.477 pobject.py:75(save_objects) + 43/3 0.533 0.012 0.749 0.250 pobject.py:99(evaluate) + ... + + The first line indicates that 2706 calls were monitored. Of those + calls, 2004 were :dfn:`primitive`. We define :dfn:`primitive` to + mean that the call was not induced via recursion. The next line: + ``Ordered by: standard name``, indicates that the text string in + the far right column was used to sort the output. The column + headings include: + + ncalls + for the number of calls, + + tottime + for the total time spent in the given function (and excluding time made in + calls to sub-functions), + + percall + is the quotient of ``tottime`` divided by ``ncalls`` + + cumtime + is the total time spent in this and all subfunctions (from invocation till + exit). This figure is accurate *even* for recursive functions. + + percall + is the quotient of ``cumtime`` divided by primitive calls + + filename:lineno(function) + provides the respective data of each function + + When there are two numbers in the first column (for example, + ``43/3``), then the latter is the number of primitive calls, and + the former is the actual number of calls. Note that when the + function does not recurse, these two values are the same, and only + the single figure is printed. + + If *sort* is given, it can be one of values allowed for *key* + parameter from :meth:`pstats.Stats.sort_stats`. + + +.. function:: runctx(command, globals, locals, filename=None) + + This function is similar to :func:`run`, with added arguments to supply the + globals and locals dictionaries for the *command* string. + + +Analysis of the profiler data is done using the :class:`pstats.Stats` class. + + +.. module:: pstats + :synopsis: Statistics object for use with the profiler. + + +.. class:: Stats(*filenames, stream=sys.stdout) + + This class constructor creates an instance of a "statistics object" + from a *filename* (or set of filenames). :class:`Stats` objects + are manipulated by methods, in order to print useful reports. You + may specify an alternate output stream by giving the keyword + argument, ``stream``. + + The file selected by the above constructor must have been created + by the corresponding version of :mod:`profile` or :mod:`cProfile`. + To be specific, there is *no* file compatibility guaranteed with + future versions of this profiler, and there is no compatibility + with files produced by other profilers. If several files are + provided, all the statistics for identical functions will be + coalesced, so that an overall view of several processes can be + considered in a single report. If additional files need to be + combined with data in an existing :class:`Stats` object, the + :meth:`add` method can be used. + + .. (such as the old system profiler). + + +.. _profile-stats: + +The :class:`Stats` Class +------------------------ + +:class:`Stats` objects have the following methods: + + +.. method:: Stats.strip_dirs() + + This method for the :class:`Stats` class removes all leading path + information from file names. It is very useful in reducing the + size of the printout to fit within (close to) 80 columns. This + method modifies the object, and the stripped information is lost. + After performing a strip operation, the object is considered to + have its entries in a "random" order, as it was just after object + initialization and loading. If :meth:`strip_dirs` causes two + function names to be indistinguishable (they are on the same line + of the same filename, and have the same function name), then the + statistics for these two entries are accumulated into a single + entry. + + +.. method:: Stats.add(*filenames) + + This method of the :class:`Stats` class accumulates additional profiling + information into the current profiling object. Its arguments should refer to + filenames created by the corresponding version of :func:`profile.run` or + :func:`cProfile.run`. Statistics for identically named (re: file, line, name) + functions are automatically accumulated into single function statistics. + + +.. method:: Stats.dump_stats(filename) + + Save the data loaded into the :class:`Stats` object to a file named + *filename*. The file is created if it does not exist, and is + overwritten if it already exists. This is equivalent to the method + of the same name on the :class:`profile.Profile` and + :class:`cProfile.Profile` classes. + + +.. method:: Stats.sort_stats(*keys) + + This method modifies the :class:`Stats` object by sorting it + according to the supplied criteria. The argument is typically a + string identifying the basis of a sort (example: ``'time'`` or + ``'name'``). + + When more than one key is provided, then additional keys are used + as secondary criteria when there is equality in all keys selected + before them. For example, ``sort_stats('name', 'file')`` will sort + all the entries according to their function name, and resolve all + ties (identical function names) by sorting by file name. + + Abbreviations can be used for any key names, as long as the abbreviation is + unambiguous. The following are the keys currently defined: + + +------------------+----------------------+ + | Valid Arg | Meaning | + +==================+======================+ + | ``'calls'`` | call count | + +------------------+----------------------+ + | ``'cumulative'`` | cumulative time | + +------------------+----------------------+ + | ``'cumtime'`` | cumulative time | + +------------------+----------------------+ + | ``'file'`` | file name | + +------------------+----------------------+ + | ``'filename'`` | file name | + +------------------+----------------------+ + | ``'module'`` | file name | + +------------------+----------------------+ + | ``'ncalls'`` | call count | + +------------------+----------------------+ + | ``'pcalls'`` | primitive call count | + +------------------+----------------------+ + | ``'line'`` | line number | + +------------------+----------------------+ + | ``'name'`` | function name | + +------------------+----------------------+ + | ``'nfl'`` | name/file/line | + +------------------+----------------------+ + | ``'stdname'`` | standard name | + +------------------+----------------------+ + | ``'time'`` | internal time | + +------------------+----------------------+ + | ``'tottime'`` | internal time | + +------------------+----------------------+ + + Note that all sorts on statistics are in descending order (placing + most time consuming items first), where as name, file, and line + number searches are in ascending order (alphabetical). The subtle + distinction between ``'nfl'`` and ``'stdname'`` is that the + standard name is a sort of the name as printed, which means that + the embedded line numbers get compared in an odd way. For example, + lines 3, 20, and 40 would (if the file names were the same) appear + in the string order 20, 3 and 40. In contrast, ``'nfl'`` does a + numeric compare of the line numbers. In fact, + ``sort_stats('nfl')`` is the same as ``sort_stats('name', 'file', + 'line')``. + + For backward-compatibility reasons, the numeric arguments ``-1``, + ``0``, ``1``, and ``2`` are permitted. They are interpreted as + ``'stdname'``, ``'calls'``, ``'time'``, and ``'cumulative'`` + respectively. If this old style format (numeric) is used, only one + sort key (the numeric key) will be used, and additional arguments + will be silently ignored. + + .. For compatibility with the old profiler, + + +.. method:: Stats.reverse_order() + + This method for the :class:`Stats` class reverses the ordering of + the basic list within the object. Note that by default ascending + vs descending order is properly selected based on the sort key of + choice. + + .. This method is provided primarily for compatibility with the old profiler. + + +.. method:: Stats.print_stats(*restrictions) + + This method for the :class:`Stats` class prints out a report as + described in the :func:`profile.run` definition. + + The order of the printing is based on the last :meth:`sort_stats` + operation done on the object (subject to caveats in :meth:`add` and + :meth:`strip_dirs`). + + The arguments provided (if any) can be used to limit the list down + to the significant entries. Initially, the list is taken to be the + complete set of profiled functions. Each restriction is either an + integer (to select a count of lines), or a decimal fraction between + 0.0 and 1.0 inclusive (to select a percentage of lines), or a + regular expression (to pattern match the standard name that is + printed; as of Python 1.5b1, this uses the Perl-style regular + expression syntax defined by the :mod:`re` module). If several + restrictions are provided, then they are applied sequentially. For + example:: + + print_stats(.1, 'foo:') + + would first limit the printing to first 10% of list, and then only print + functions that were part of filename :file:`.\*foo:`. In contrast, the + command:: + + print_stats('foo:', .1) + + would limit the list to all functions having file names :file:`.\*foo:`, and + then proceed to only print the first 10% of them. + + +.. method:: Stats.print_callers(*restrictions) + + This method for the :class:`Stats` class prints a list of all functions that + called each function in the profiled database. The ordering is identical to + that provided by :meth:`print_stats`, and the definition of the restricting + argument is also identical. Each caller is reported on its own line. The + format differs slightly depending on the profiler that produced the stats: + + * With :mod:`profile`, a number is shown in parentheses after each caller to + show how many times this specific call was made. For convenience, a second + non-parenthesized number repeats the cumulative time spent in the function + at the right. + + * With :mod:`cProfile`, each caller is preceded by three numbers: + the number of times this specific call was made, and the total + and cumulative times spent in the current function while it was + invoked by this specific caller. + + +.. method:: Stats.print_callees(*restrictions) + + This method for the :class:`Stats` class prints a list of all + function that were called by the indicated function. Aside from + this reversal of direction of calls (re: called vs was called by), + the arguments and ordering are identical to the + :meth:`print_callers` method. + + +.. _profile-limits: Limitations =========== @@ -562,7 +536,7 @@ handling time to compensate for the overhead of calling the time function, and socking away the results. By default, the constant is 0. The following procedure can be used to obtain a better constant for a given platform (see -:ref:`profile-limitations`). :: +discussion in section Limitations above). :: import profile pr = profile.Profile() @@ -572,8 +546,8 @@ The method executes the number of Python calls given by the argument, directly and again under the profiler, measuring the time for both. It then computes the hidden overhead per profiler event, and returns that as a float. For example, -on a 1.8Ghz Intel Core i5 running Mac OS X, and using Python's time.clock() as -the timer, the magical number is about 4.04e-6. +on an 800 MHz Pentium running Windows 2000, and using Python's time.clock() as +the timer, the magical number is about 12.5e-6. The object of this exercise is to get a fairly consistent result. If your computer is *very* fast, or your timer function has poor resolution, you might @@ -596,51 +570,54 @@ If you have a choice, you are better off choosing a smaller constant, and then your results will "less often" show up as negative in profile statistics. -.. _profile-timers: -Using a customer timer -====================== +.. _profiler-extensions: -If you want to change how current time is determined (for example, to force use -of wall-clock time or elapsed process time), pass the timing function you want -to the :class:`Profile` class constructor:: +Extensions --- Deriving Better Profilers +======================================== - pr = profile.Profile(your_time_func) +The :class:`Profile` class of both modules, :mod:`profile` and :mod:`cProfile`, +were written so that derived classes could be developed to extend the profiler. +The details are not described here, as doing this successfully requires an +expert understanding of how the :class:`Profile` class works internally. Study +the source code of the module carefully if you want to pursue this. -The resulting profiler will then call ``your_time_func``. Depending on whether -you are using :class:`profile.Profile` or :class:`cProfile.Profile`, -``your_time_func``'s return value will be interpreted differently: +If all you want to do is change how current time is determined (for example, to +force use of wall-clock time or elapsed process time), pass the timing function +you want to the :class:`Profile` class constructor:: + + pr = profile.Profile(your_time_func) + +The resulting profiler will then call :func:`your_time_func`. :class:`profile.Profile` - ``your_time_func`` should return a single number, or a list of numbers whose - sum is the current time (like what :func:`os.times` returns). If the - function returns a single time number, or the list of returned numbers has - length 2, then you will get an especially fast version of the dispatch - routine. + :func:`your_time_func` should return a single number, or a list of + numbers whose sum is the current time (like what :func:`os.times` + returns). If the function returns a single time number, or the + list of returned numbers has length 2, then you will get an + especially fast version of the dispatch routine. - Be warned that you should calibrate the profiler class for the timer function - that you choose (see :ref:`profile-calibration`). For most machines, a timer - that returns a lone integer value will provide the best results in terms of - low overhead during profiling. (:func:`os.times` is *pretty* bad, as it - returns a tuple of floating point values). If you want to substitute a - better timer in the cleanest fashion, derive a class and hardwire a - replacement dispatch method that best handles your timer call, along with the - appropriate calibration constant. + Be warned that you should calibrate the profiler class for the + timer function that you choose. For most machines, a timer that + returns a lone integer value will provide the best results in terms + of low overhead during profiling. (:func:`os.times` is *pretty* + bad, as it returns a tuple of floating point values). If you want + to substitute a better timer in the cleanest fashion, derive a + class and hardwire a replacement dispatch method that best handles + your timer call, along with the appropriate calibration constant. :class:`cProfile.Profile` - ``your_time_func`` should return a single number. If it returns integers, - you can also invoke the class constructor with a second argument specifying - the real duration of one unit of time. For example, if - ``your_integer_time_func`` returns times measured in thousands of seconds, - you would construct the :class:`Profile` instance as follows:: + :func:`your_time_func` should return a single number. If it + returns integers, you can also invoke the class constructor with a + second argument specifying the real duration of one unit of time. + For example, if :func:`your_integer_time_func` returns times + measured in thousands of seconds, you would construct the + :class:`Profile` instance as follows:: - pr = cProfile.Profile(your_integer_time_func, 0.001) + pr = profile.Profile(your_integer_time_func, 0.001) - As the :mod:`cProfile.Profile` class cannot be calibrated, custom timer - functions should be used with care and should be as fast as possible. For - the best results with a custom timer, it might be necessary to hard-code it - in the C source of the internal :mod:`_lsprof` module. - -Python 3.3 adds several new functions in :mod:`time` that can be used to make -precise measurements of process or wall-clock time. For example, see -:func:`time.perf_counter`. + As the :mod:`cProfile.Profile` class cannot be calibrated, custom + timer functions should be used with care and should be as fast as + possible. For the best results with a custom timer, it might be + necessary to hard-code it in the C source of the internal + :mod:`_lsprof` module. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/py_compile.rst --- a/Doc/library/py_compile.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/py_compile.rst Fri Feb 01 23:12:09 2013 +0100 @@ -28,7 +28,7 @@ .. function:: compile(file, cfile=None, dfile=None, doraise=False, optimize=-1) - Compile a source file to byte-code and write out the byte-code cache file. + 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 *cfile*, which defaults to the :PEP:`3147` path, ending in ``.pyc`` (``.pyo`` if optimization is enabled in the current interpreter). @@ -41,13 +41,6 @@ is raised. This function returns the path to byte-compiled file, i.e. whatever *cfile* value was used. - If the path that *cfile* becomes (either explicitly specified or computed) - is a symlink or non-regular file, :exc:`FileExistsError` will be raised. - This is to act as a warning that import will turn those paths into regular - files if it is allowed to write byte-compiled files to those paths. This is - a side-effect of import using file renaming to place the final byte-compiled - file into place to prevent concurrent file writing issues. - *optimize* controls the optimization level and is passed to the built-in :func:`compile` function. The default of ``-1`` selects the optimization level of the current interpreter. @@ -57,13 +50,6 @@ default was *file* + ``'c'`` (``'o'`` if optimization was enabled). Also added the *optimize* parameter. - .. versionchanged:: 3.4 - Changed code to use :mod:`importlib` for the byte-code cache file writing. - This means file creation/writing semantics now match what :mod:`importlib` - does, e.g. permissions, write-and-move semantics, etc. Also added the - caveat that :exc:`FileExistsError` is raised if *cfile* is a symlink or - non-regular file. - .. function:: main(args=None) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/pyexpat.rst --- a/Doc/library/pyexpat.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/pyexpat.rst Fri Feb 01 23:12:09 2013 +0100 @@ -14,13 +14,6 @@ references to these attributes should be marked using the :member: role. -.. warning:: - - The :mod:`pyexpat` module is not secure against maliciously - constructed data. If you need to parse untrusted or unauthenticated data see - :ref:`xml-vulnerabilities`. - - .. index:: single: Expat The :mod:`xml.parsers.expat` module is a Python interface to the Expat diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/readline.rst --- a/Doc/library/readline.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/readline.rst Fri Feb 01 23:12:09 2013 +0100 @@ -190,32 +190,28 @@ The following example demonstrates how to use the :mod:`readline` module's history reading and writing functions to automatically load and save a history -file named :file:`.python_history` from the user's home directory. The code -below would normally be executed automatically during interactive sessions -from the user's :envvar:`PYTHONSTARTUP` file. :: +file named :file:`.pyhist` from the user's home directory. The code below would +normally be executed automatically during interactive sessions from the user's +:envvar:`PYTHONSTARTUP` file. :: - import atexit import os import readline - - histfile = os.path.join(os.path.expanduser("~"), ".python_history") + histfile = os.path.join(os.path.expanduser("~"), ".pyhist") try: readline.read_history_file(histfile) except FileNotFoundError: pass - + import atexit atexit.register(readline.write_history_file, histfile) - -This code is actually automatically run when Python is run in -:ref:`interactive mode ` (see :ref:`rlcompleter-config`). + del os, histfile The following example extends the :class:`code.InteractiveConsole` class to support history save/restore. :: + import code + import readline import atexit - import code import os - import readline class HistoryConsole(code.InteractiveConsole): def __init__(self, locals=None, filename="", diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/resource.rst --- a/Doc/library/resource.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/resource.rst Fri Feb 01 23:12:09 2013 +0100 @@ -43,11 +43,6 @@ this module for those platforms. -.. data:: RLIM_INFINITY - - Constant used to represent the the limit for an unlimited resource. - - .. function:: getrlimit(resource) Returns a tuple ``(soft, hard)`` with the current soft and hard limits of @@ -59,20 +54,12 @@ Sets new limits of consumption of *resource*. The *limits* argument must be a tuple ``(soft, hard)`` of two integers describing the new limits. A value of - :data:`~resource.RLIM_INFINITY` can be used to request a limit that is - unlimited. + ``-1`` can be used to specify the maximum possible upper limit. Raises :exc:`ValueError` if an invalid resource is specified, if the new soft - limit exceeds the hard limit, or if a process tries to raise its hard limit. - Specifying a limit of :data:`~resource.RLIM_INFINITY` when the hard or - system limit for that resource is not unlimited will result in a - :exc:`ValueError`. A process with the effective UID of super-user can - request any valid limit value, including unlimited, but :exc:`ValueError` - will still be raised if the requested limit exceeds the system imposed - limit. - - ``setrlimit`` may also raise :exc:`error` if the underlying system call - fails. + limit exceeds the hard limit, or if a process tries to raise its hard limit + (unless the process has an effective UID of super-user). Can also raise + :exc:`error` if the underlying system call fails. These symbols define resources whose consumption can be controlled using the :func:`setrlimit` and :func:`getrlimit` functions described below. The values of diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/rlcompleter.rst --- a/Doc/library/rlcompleter.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/rlcompleter.rst Fri Feb 01 23:12:09 2013 +0100 @@ -27,10 +27,18 @@ readline.__name__ readline.parse_and_bind( >>> readline. -The :mod:`rlcompleter` module is designed for use with Python's -:ref:`interactive mode `. Unless Python is run with the -:option:`-S` option, the module is automatically imported and configured -(see :ref:`rlcompleter-config`). +The :mod:`rlcompleter` module is designed for use with Python's interactive +mode. A user can add the following lines to his or her initialization file +(identified by the :envvar:`PYTHONSTARTUP` environment variable) to get +automatic :kbd:`Tab` completion:: + + try: + import readline + except ImportError: + print("Module readline not available.") + else: + import rlcompleter + readline.parse_and_bind("tab: complete") On platforms without :mod:`readline`, the :class:`Completer` class defined by this module can still be used for custom purposes. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/sched.rst --- a/Doc/library/sched.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/sched.rst Fri Feb 01 23:12:09 2013 +0100 @@ -14,13 +14,12 @@ The :mod:`sched` module defines a class which implements a general purpose event scheduler: -.. class:: scheduler(timefunc=time.monotonic, delayfunc=time.sleep) +.. class:: scheduler(timefunc=time.time, delayfunc=time.sleep) The :class:`scheduler` class defines a generic interface to scheduling events. It needs two functions to actually deal with the "outside world" --- *timefunc* should be callable without arguments, and return a number (the "time", in any - units whatsoever). If time.monotonic is not available, the *timefunc* default - is time.time instead. The *delayfunc* function should be callable with one + units whatsoever). The *delayfunc* function should be callable with one argument, compatible with the output of *timefunc*, and should delay that many time units. *delayfunc* will also be called with the argument ``0`` after each event is run to allow other threads an opportunity to run in multi-threaded diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/select.rst --- a/Doc/library/select.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/select.rst Fri Feb 01 23:12:09 2013 +0100 @@ -25,7 +25,7 @@ Following :pep:`3151`, this class was made an alias of :exc:`OSError`. -.. function:: devpoll() +.. function:: devpoll(cloexec=None) (Only supported on Solaris and derivatives.) Returns a ``/dev/poll`` polling object; see section :ref:`devpoll-objects` below for the @@ -37,9 +37,14 @@ increases this value, :c:func:`devpoll` may return an incomplete list of active file descriptors. + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + .. versionadded:: 3.3 -.. function:: epoll(sizehint=-1, flags=0) + .. versionchanged:: 3.4 + *cloexec* parameter was added. + +.. function:: epoll(sizehint=-1, flags=0, cloexec=None) (Only supported on Linux 2.5.44 and newer.) Return an edge polling object, which can be used as Edge or Level Triggered interface for I/O @@ -49,11 +54,14 @@ :ref:`epoll-objects` below for the methods supported by epolling objects. They also support the :keyword:`with` statement. + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + .. versionchanged:: 3.3 Added the *flags* parameter. .. versionchanged:: 3.4 Support for the :keyword:`with` statement was added. + *cloexec* parameter was added. .. function:: poll() @@ -64,11 +72,16 @@ by polling objects. -.. function:: kqueue() +.. function:: kqueue(cloexec=None) (Only supported on BSD.) Returns a kernel queue object; see section :ref:`kqueue-objects` below for the methods supported by kqueue objects. + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + + .. versionchanged:: 3.4 + *cloexec* parameter was added. + .. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0) @@ -199,6 +212,13 @@ block until there is an event for this poll object. +.. method:: devpoll.fileno() + + Return the file descriptor number. + + .. versionadded:: 3.4 + + .. _epoll-objects: Edge and Level Trigger Polling (epoll) Objects diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/shelve.rst --- a/Doc/library/shelve.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/shelve.rst Fri Feb 01 23:12:09 2013 +0100 @@ -44,11 +44,8 @@ .. note:: Do not rely on the shelf being closed automatically; always call - :meth:`~Shelf.close` explicitly when you don't need it any more, or - use :func:`shelve.open` as a context manager:: - - with shelve.open('spam') as db: - db['eggs'] = 'eggs' + :meth:`close` explicitly when you don't need it any more, or use a + :keyword:`with` statement with :func:`contextlib.closing`. .. warning:: @@ -121,15 +118,10 @@ The *keyencoding* parameter is the encoding used to encode keys before they are used with the underlying dict. - :class:`Shelf` objects can also be used as context managers. - - .. versionchanged:: 3.2 - Added the *keyencoding* parameter; previously, keys were always encoded in + .. versionadded:: 3.2 + The *keyencoding* parameter; previously, keys were always encoded in UTF-8. - .. versionchanged:: 3.4 - Added context manager support. - .. class:: BsdDbShelf(dict, protocol=None, writeback=False, keyencoding='utf-8') diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/shutil.rst --- a/Doc/library/shutil.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/shutil.rst Fri Feb 01 23:12:09 2013 +0100 @@ -348,7 +348,7 @@ directories. For example, on Windows:: >>> shutil.which("python") - 'C:\\Python33\\python.EXE' + 'c:\\python33\\python.exe' .. versionadded:: 3.3 diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/site.rst --- a/Doc/library/site.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/site.rst Fri Feb 01 23:12:09 2013 +0100 @@ -111,23 +111,6 @@ :mod:`sitecustomize` and :mod:`usercustomize` is still attempted. -.. _rlcompleter-config: - -Readline configuration ----------------------- - -On systems that support :mod:`readline`, this module will also import and -configure the :mod:`rlcompleter` module, if Python is started in -:ref:`interactive mode ` and without the :option:`-S` option. -The default behavior is enable tab-completion and to use -:file:`~/.python_history` as the history save file. To disable it, override -the :data:`sys.__interactivehook__` attribute in your :mod:`sitecustomize` -or :mod:`usercustomize` module or your :envvar:`PYTHONSTARTUP` file. - - -Module contents ---------------- - .. data:: PREFIXES A list of prefixes for site-packages directories. @@ -170,7 +153,8 @@ Adds all the standard site-specific directories to the module search path. This function is called automatically when this module is imported, - unless the Python interpreter was started with the :option:`-S` flag. + unless the :program:`python` interpreter was started with the :option:`-S` + flag. .. versionchanged:: 3.3 This function used to be called unconditionnally. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/smtpd.rst --- a/Doc/library/smtpd.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/smtpd.rst Fri Feb 01 23:12:09 2013 +0100 @@ -27,8 +27,7 @@ ------------------ -.. class:: SMTPServer(localaddr, remoteaddr, data_size_limit=33554432, - map=None) +.. class:: SMTPServer(localaddr, remoteaddr, data_size_limit=33554432) Create a new :class:`SMTPServer` object, which binds to local address *localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. It @@ -39,8 +38,6 @@ accepted in a ``DATA`` command. A value of ``None`` or ``0`` means no limit. - A dictionary can be specified in *map* to avoid using a global socket map. - .. method:: process_message(peer, mailfrom, rcpttos, data) Raise :exc:`NotImplementedError` exception. Override this in subclasses to @@ -56,9 +53,6 @@ Override this in subclasses to use a custom :class:`SMTPChannel` for managing SMTP clients. - .. versionchanged:: 3.4 - The *map* argument was added. - DebuggingServer Objects ----------------------- @@ -96,20 +90,11 @@ SMTPChannel Objects ------------------- -.. class:: SMTPChannel(server, conn, addr, data_size_limit=33554432, - map=None)) +.. class:: SMTPChannel(server, conn, addr) Create a new :class:`SMTPChannel` object which manages the communication between the server and a single SMTP client. - *conn* and *addr* are as per the instance variables described below. - - *data_size_limit* specifies the maximum number of bytes that will be - accepted in a ``DATA`` command. A value of ``None`` or ``0`` means no - limit. - - A dictionary can be specified in *map* to avoid using a global socket map. - To use a custom SMTPChannel implementation you need to override the :attr:`SMTPServer.channel_class` of your :class:`SMTPServer`. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/smtplib.rst --- a/Doc/library/smtplib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/smtplib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -24,20 +24,17 @@ A :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, - *local_hostname* is used as the FQDN of the local host in the HELO/EHLO - command. Otherwise, the local hostname is found using - :func:`socket.getfqdn`. If the :meth:`connect` call returns anything other - than a success code, an :exc:`SMTPConnectError` is raised. The optional + host and port parameters are given, the SMTP :meth:`connect` method is called + with those parameters during initialization. An :exc:`SMTPConnectError` is + raised if the specified host doesn't respond correctly. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout - setting will be used). The optional source_address parameter allows to bind - to some specific source address in a machine with multiple network - interfaces, and/or to some specific source TCP port. It takes a 2-tuple - (host, port), for the socket to bind to as its source address before - connecting. If omitted (or if host or port are ``''`` and/or 0 respectively) - the OS default behavior will be used. + setting will be used). The optional source_address parameter allows to bind to some + specific source address in a machine with multiple network interfaces, + and/or to some specific source TCP port. It takes a 2-tuple (host, port), + for the socket to bind to as its source address before connecting. If + omitted (or if host or port are ``''`` and/or 0 respectively) the OS default + behavior will be used. For normal use, you should only require the initialization/connect, :meth:`sendmail`, and :meth:`~smtplib.quit` methods. @@ -60,21 +57,17 @@ .. versionchanged:: 3.3 source_address argument was added. -.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, \ - certfile=None [, timeout], context=None, \ - source_address=None) +.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout], context=None, source_address=None) A :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 - *port* is zero, the standard SMTP-over-SSL port (465) is used. The optional - arguments *local_hostname* and *source_address* have the same meaning as - they do in the :class:`SMTP` class. *keyfile* and *certfile* are also - optional, and can contain a PEM formatted private key and certificate chain - file for the SSL connection. *context* also optional, can contain a - SSLContext, and is an alternative to keyfile and certfile; If it is - specified both keyfile and certfile must be None. The optional *timeout* + *port* is zero, the standard SMTP-over-SSL port (465) is used. *keyfile* + and *certfile* are also optional, and can contain a PEM formatted private key + and certificate chain file for the SSL connection. *context* also optional, can contain + a SSLContext, and is an alternative to keyfile and certfile; If it is specified both + keyfile and certfile must be None. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). The optional source_address parameter allows to bind to some @@ -97,12 +90,12 @@ standard SMTP client. It's common to use Unix sockets for LMTP, so our :meth:`connect` method must support that as well as a regular host:port server. The optional arguments local_hostname and source_address have the - same meaning as they do in the :class:`SMTP` class. To specify a Unix - socket, you must use an absolute path for *host*, starting with a '/'. + same meaning as that of SMTP client. To specify a Unix socket, you must use + an absolute path for *host*, starting with a '/'. - Authentication is supported, using the regular SMTP mechanism. When using a - Unix socket, LMTP generally don't support or require any authentication, but - your mileage might vary. + Authentication is supported, using the regular SMTP mechanism. When using a Unix + socket, LMTP generally don't support or require any authentication, but your + mileage might vary. A nice selection of exceptions is defined as well: @@ -110,8 +103,7 @@ .. exception:: SMTPException - Subclass of :exc:`OSError` that is the base exception class for all - the other excpetions provided by this module. + Base exception class for all exceptions raised by this module. .. exception:: SMTPServerDisconnected @@ -190,6 +182,15 @@ for connection and for all messages sent to and received from the server. +.. method:: SMTP.connect(host='localhost', port=0) + + Connect to a host on a given port. The defaults are to connect to the local + host at the standard SMTP port (25). If the hostname ends with a colon (``':'``) + followed by a number, that suffix will be stripped off and the number + interpreted as the port number to use. This method is automatically invoked by + the constructor if a host is specified during instantiation. + + .. method:: SMTP.docmd(cmd, args='') Send a command *cmd* to the server. The optional argument *args* is simply @@ -206,17 +207,6 @@ :exc:`SMTPServerDisconnected` will be raised. -.. method:: SMTP.connect(host='localhost', port=0) - - Connect to a host on a given port. The defaults are to connect to the local - host at the standard SMTP port (25). If the hostname ends with a colon (``':'``) - followed by a number, that suffix will be stripped off and the number - interpreted as the port number to use. This method is automatically invoked by - the constructor if a host is specified during instantiation. Returns a - 2-tuple of the response code and message sent by the server in its - connection response. - - .. method:: SMTP.helo(name='') Identify yourself to the SMTP server using ``HELO``. The hostname argument diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/socket.rst --- a/Doc/library/socket.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/socket.rst Fri Feb 01 23:12:09 2013 +0100 @@ -18,7 +18,7 @@ The Python interface is a straightforward transliteration of the Unix system call and library interface for sockets to Python's object-oriented style: the -:func:`.socket` function returns a :dfn:`socket object` whose methods implement +:func:`socket` function returns a :dfn:`socket object` whose methods implement the various socket system calls. Parameter types are somewhat higher-level than in the C interface: as with :meth:`read` and :meth:`write` operations on Python files, buffer allocation on receive operations is automatic, and buffer length @@ -107,8 +107,8 @@ .. versionadded:: 3.3 -- Certain other address families (:const:`AF_BLUETOOTH`, :const:`AF_PACKET`, - :const:`AF_CAN`) support specific representations. +- Certain other address families (:const:`AF_BLUETOOTH`, :const:`AF_PACKET`) + support specific representations. .. XXX document them! @@ -191,7 +191,7 @@ AF_INET6 These constants represent the address (and protocol) families, used for the - first argument to :func:`.socket`. If the :const:`AF_UNIX` constant is not + first argument to :func:`socket`. If the :const:`AF_UNIX` constant is not defined then this protocol is unsupported. More constants may be available depending on the system. @@ -203,7 +203,7 @@ SOCK_SEQPACKET These constants represent the socket types, used for the second argument to - :func:`.socket`. More constants may be available depending on the system. + :func:`socket`. More constants may be available depending on the system. (Only :const:`SOCK_STREAM` and :const:`SOCK_DGRAM` appear to be generally useful.) @@ -257,16 +257,6 @@ .. versionadded:: 3.3 -.. data:: CAN_BCM - CAN_BCM_* - - CAN_BCM, in the CAN protocol family, is the broadcast manager (BCM) protocol. - Broadcast manager constants, documented in the Linux documentation, are also - defined in the socket module. - - Availability: Linux >= 2.6.25. - - .. versionadded:: 3.4 .. data:: AF_RDS PF_RDS @@ -293,11 +283,6 @@ TIPC related constants, matching the ones exported by the C socket API. See the TIPC documentation for more information. -.. data:: AF_LINK - - Availability: BSD, OSX. - - .. versionadded:: 3.4 .. data:: has_ipv6 @@ -353,7 +338,7 @@ ``(family, type, proto, canonname, sockaddr)`` In these tuples, *family*, *type*, *proto* are all integers and are - meant to be passed to the :func:`.socket` function. *canonname* will be + meant to be passed to the :func:`socket` function. *canonname* will be a string representing the canonical name of the *host* if :const:`AI_CANONNAME` is part of the *flags* argument; else *canonname* will be empty. *sockaddr* is a tuple describing a socket address, whose @@ -440,7 +425,7 @@ .. function:: getprotobyname(protocolname) Translate an Internet protocol name (for example, ``'icmp'``) to a constant - suitable for passing as the (optional) third argument to the :func:`.socket` + suitable for passing as the (optional) third argument to the :func:`socket` function. This is usually only needed for sockets opened in "raw" mode (:const:`SOCK_RAW`); for the normal socket modes, the correct protocol is chosen automatically if the protocol is omitted or zero. @@ -460,48 +445,63 @@ ``'udp'``, otherwise any protocol will match. -.. function:: socket([family[, type[, proto]]]) +.. function:: socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None, cloexec=None) Create a new socket using the given address family, socket type and protocol number. The address family should be :const:`AF_INET` (the default), :const:`AF_INET6`, :const:`AF_UNIX`, :const:`AF_CAN` or :const:`AF_RDS`. The socket type should be :const:`SOCK_STREAM` (the default), :const:`SOCK_DGRAM`, :const:`SOCK_RAW` or perhaps one of the other ``SOCK_`` - constants. The protocol number is usually zero and may be omitted or in the - case where the address family is :const:`AF_CAN` the protocol should be one - of :const:`CAN_RAW` or :const:`CAN_BCM`. + constants. The protocol number is usually zero and may be omitted in that + case or :const:`CAN_RAW` in case the address family is :const:`AF_CAN`. + + If *cloexec* is ``True``, set the :ref:`close-on-exec flag ` on + the newly created file descriptor. *cloexec* is ignored when *fileno* is + used. .. versionchanged:: 3.3 The AF_CAN family was added. The AF_RDS family was added. - .. versionchanged:: 3.4 - The CAN_BCM protocol was added. + .. versionchanged:: 3.4 + *cloexec* parameter was added. -.. function:: socketpair([family[, type[, proto]]]) + +.. function:: socketpair(family=AF_INET, type=SOCK_STREAM, proto=0, cloexec=None) Build a pair of connected socket objects using the given address family, socket type, and protocol number. Address family, socket type, and protocol number are - as for the :func:`.socket` function above. The default family is :const:`AF_UNIX` + as for the :func:`socket` function above. The default family is :const:`AF_UNIX` if defined on the platform; otherwise, the default is :const:`AF_INET`. + + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + Availability: Unix. .. versionchanged:: 3.2 The returned socket objects now support the whole socket API, rather than a subset. + .. versionchanged:: 3.4 + *cloexec* parameter was added. -.. function:: fromfd(fd, family, type[, proto]) + +.. function:: fromfd(fd, family, type, proto=0, cloexec=None) Duplicate the file descriptor *fd* (an integer as returned by a file object's :meth:`fileno` method) and build a socket object from the result. Address - family, socket type and protocol number are as for the :func:`.socket` function + family, socket type and protocol number are as for the :func:`socket` function above. The file descriptor should refer to a socket, but this is not checked --- subsequent operations on the object may fail if the file descriptor is invalid. This function is rarely needed, but can be used to get or set socket options on a socket passed to a program as standard input or output (such as a server started by the Unix inet daemon). The socket is assumed to be in blocking mode. + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + + .. versionchanged:: 3.4 + *cloexec* parameter was added. + .. function:: ntohl(x) @@ -723,13 +723,18 @@ correspond to Unix system calls applicable to sockets. -.. method:: socket.accept() +.. method:: socket.accept(cloexec=None) Accept a connection. The socket must be bound to an address and listening for connections. The return value is a pair ``(conn, address)`` where *conn* is a *new* socket object usable to send and receive data on the connection, and *address* is the address bound to the socket on the other end of the connection. + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + + .. versionchanged:: 3.4 + *cloexec* parameter was added. + .. method:: socket.bind(address) @@ -775,6 +780,16 @@ .. versionadded:: 3.2 +.. method:: socket.dup(cloexec=None) + + Duplicate the socket. + + If *cloexec* is ``True``, set the :ref:`close-on-exec flag `. + + .. versionchanged:: 3.4 + *cloexec* parameter was added. + + .. method:: socket.fileno() Return the socket's file descriptor (a small integer). This is useful with @@ -1210,10 +1225,10 @@ Here are four minimal example programs using the TCP/IP protocol: a server that echoes all data that it receives back (servicing only one client), and a client -using it. Note that a server must perform the sequence :func:`.socket`, +using it. Note that a server must perform the sequence :func:`socket`, :meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly repeating the :meth:`~socket.accept` to service more than one client), while a -client only needs the sequence :func:`.socket`, :meth:`~socket.connect`. Also +client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on the socket it is listening on but on the new socket returned by :meth:`~socket.accept`. @@ -1349,16 +1364,7 @@ s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) The last example shows how to use the socket interface to communicate to a CAN -network using the raw socket protocol. To use CAN with the broadcast -manager protocol instead, open a socket with:: - - socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM) - -After binding (:const:`CAN_RAW`) or connecting (:const:`CAN_BCM`) the socket, you -can use the :meth:`socket.send`, and the :meth:`socket.recv` operations (and -their counterparts) on the socket object as usual. - -This example might require special priviledge:: +network. This example might require special priviledge:: import socket import struct diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/socketserver.rst Fri Feb 01 23:12:09 2013 +0100 @@ -166,7 +166,7 @@ .. method:: BaseServer.service_actions() - This is called in the :meth:`serve_forever` loop. This method can be + This is called in the :meth:`serve_forever` loop. This method is can be overridden by subclasses or mixin classes to perform actions specific to a given service, such as cleanup actions. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/sqlite3.rst Fri Feb 01 23:12:09 2013 +0100 @@ -18,10 +18,10 @@ To use the module, you must first create a :class:`Connection` object that represents the database. Here the data will be stored in the -:file:`example.db` file:: +:file:`/tmp/example` file:: import sqlite3 - conn = sqlite3.connect('example.db') + conn = sqlite3.connect('/tmp/example') You can also supply the special name ``:memory:`` to create a database in RAM. @@ -159,7 +159,7 @@ first blank for the column name: the column name would simply be "x". -.. function:: connect(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements, uri]) +.. function:: connect(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements]) Opens a connection to the SQLite database file *database*. You can use ``":memory:"`` to open a database connection to a database that resides in RAM @@ -195,18 +195,6 @@ for the connection, you can set the *cached_statements* parameter. The currently implemented default is to cache 100 statements. - If *uri* is true, *database* is interpreted as a URI. This allows you - to specify options. For example, to open a database in read-only mode - you can use:: - - db = sqlite3.connect('file:path/to/database?mode=ro', uri=True) - - More information about this feature, including a list of recognized options, can - be found in the `SQLite URI documentation `_. - - .. versionchanged:: 3.4 - Added the *uri* parameter. - .. function:: register_converter(typename, callable) @@ -842,10 +830,6 @@ .. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py -If a timestamp stored in SQLite has a fractional part longer than 6 -numbers, its value will be truncated to microsecond precision by the -timestamp converter. - .. _sqlite3-controlling-transactions: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/ssl.rst --- a/Doc/library/ssl.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/ssl.rst Fri Feb 01 23:12:09 2013 +0100 @@ -26,8 +26,7 @@ Some behavior may be platform dependent, since calls are made to the operating system socket APIs. The installed version of OpenSSL may also - cause variations in behavior. For example, TLSv1.1 and TLSv1.2 come with - openssl version 1.0.1. + cause variations in behavior. This section documents the objects and functions in the ``ssl`` module; for more general information about TLS, SSL, and certificates, the reader is referred to @@ -178,16 +177,14 @@ .. table:: - ======================== ========= ========= ========== ========= =========== =========== - *client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1** **TLSv1.1** **TLSv1.2** - ------------------------ --------- --------- ---------- --------- ----------- ----------- - *SSLv2* yes no yes no no no - *SSLv3* no yes yes no no no - *SSLv23* yes no yes no no no - *TLSv1* no no yes yes no no - *TLSv1.1* no no yes no yes no - *TLSv1.2* no no yes no no yes - ======================== ========= ========= ========== ========= =========== =========== + ======================== ========= ========= ========== ========= + *client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1** + ------------------------ --------- --------- ---------- --------- + *SSLv2* yes no yes no + *SSLv3* no yes yes no + *SSLv23* yes no yes no + *TLSv1* no no yes yes + ======================== ========= ========= ========== ========= .. note:: @@ -343,37 +340,6 @@ Given a certificate as an ASCII PEM string, returns a DER-encoded sequence of bytes for that same certificate. -.. function:: get_default_verify_paths() - - Returns a named tuple with paths to OpenSSL's default cafile and capath. - The paths are the same as used by - :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:`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 - - .. versionadded:: 3.4 - -.. function:: enum_cert_store(store_name, cert_type='certificate') - - Retrieve certificates from Windows' system cert store. *store_name* may be - one of ``CA``, ``ROOT`` or ``MY``. Windows may provide additional cert - stores, too. *cert_type* is either ``certificate`` for X.509 certificates - or ``crl`` for X.509 certificate revocation lists. - - The function returns a list of (bytes, encoding_type) tuples. The - encoding_type flag can be interpreted with :const:`X509_ASN_ENCODING` or - :const:`PKCS_7_ASN_ENCODING`. - - Availability: Windows. - - .. versionadded:: 3.4 - Constants ^^^^^^^^^ @@ -435,25 +401,9 @@ .. data:: PROTOCOL_TLSv1 - Selects TLS version 1.0 as the channel encryption protocol. - -.. data:: PROTOCOL_TLSv1_1 - - - Selects TLS version 1.1 as the channel encryption protocol. - Available only with openssl version 1.0.1+. - - .. versionadded:: 3.4 - -.. data:: PROTOCOL_TLSv1_2 - - - Selects TLS version 1.2 as the channel encryption protocol. This is the most + Selects TLS version 1 as the channel encryption protocol. This is the most modern version, and probably the best choice for maximum protection, if both sides can speak it. - Available only with openssl version 1.0.1+. - - .. versionadded:: 3.4 .. data:: OP_ALL @@ -487,22 +437,6 @@ .. versionadded:: 3.2 -.. data:: OP_NO_TLSv1_1 - - Prevents a TLSv1.1 connection. This option is only applicable in conjunction - with :const:`PROTOCOL_SSLv23`. It prevents the peers from choosing TLSv1.1 as - the protocol version. Available only with openssl version 1.0.1+. - - .. versionadded:: 3.4 - -.. data:: OP_NO_TLSv1_2 - - Prevents a TLSv1.2 connection. This option is only applicable in conjunction - with :const:`PROTOCOL_SSLv23`. It prevents the peers from choosing TLSv1.2 as - the protocol version. Available only with openssl version 1.0.1+. - - .. versionadded:: 3.4 - .. data:: OP_CIPHER_SERVER_PREFERENCE Use the server's cipher ordering preference, rather than the client's. @@ -612,15 +546,6 @@ .. versionadded:: 3.4 -.. data:: X509_ASN_ENCODING - PKCS_7_ASN_ENCODING - - Encoding flags for :func:`enum_cert_store`. - - Availability: Windows. - - .. versionadded:: 3.4 - SSL Sockets ----------- @@ -661,7 +586,7 @@ If there is no certificate for the peer on the other end of the connection, returns ``None``. - If the ``binary_form`` parameter is :const:`False`, and a certificate was + If the parameter ``binary_form`` is :const:`False`, and a certificate was received from the peer, this method returns a :class:`dict` instance. If the certificate was not validated, the dict is empty. If the certificate was validated, it returns a dict with several keys, amongst them ``subject`` @@ -701,16 +626,10 @@ If the ``binary_form`` parameter is :const:`True`, and a certificate was provided, this method returns the DER-encoded form of the entire certificate as a sequence of bytes, or :const:`None` if the peer did not provide a - certificate. Whether the peer provides a certificate depends on the SSL - socket's role: - - * for a client SSL socket, the server will always provide a certificate, - regardless of whether validation was required; - - * for a server SSL socket, the client will only provide a certificate - when requested by the server; therefore :meth:`getpeercert` will return - :const:`None` if you used :const:`CERT_NONE` (rather than - :const:`CERT_OPTIONAL` or :const:`CERT_REQUIRED`). + certificate. This return value is independent of validation; if validation + was required (:const:`CERT_OPTIONAL` or :const:`CERT_REQUIRED`), it will have + been validated, but if :const:`CERT_NONE` was used to establish the + connection, the certificate, if present, will not have been validated. .. versionchanged:: 3.2 The returned dictionary includes additional items such as ``issuer`` @@ -791,19 +710,6 @@ :class:`SSLContext` objects have the following methods and attributes: -.. method:: SSLContext.cert_store_stats() - - Get statistics about quantities of loaded X.509 certificates, count of - X.509 certificates flagged as CA certificates and certificate revocation - lists as dictionary. - - Example for a context with one CA cert and one other cert:: - - >>> context.cert_store_stats() - {'crl': 0, 'x509_ca': 1, 'x509': 2} - - .. versionadded:: 3.4 - .. method:: SSLContext.load_cert_chain(certfile, keyfile=None, password=None) Load a private key and the corresponding certificate. The *certfile* @@ -850,17 +756,6 @@ following an `OpenSSL specific layout `_. -.. method:: SSLContext.get_ca_certs(binary_form=False) - - Get a list of loaded "certification authority" (CA) certificates. If the - ``binary_form`` parameter is :const:`False` each list - entry is a dict like the output of :meth:`SSLSocket.getpeercert`. Otherwise - the method returns a list of DER-encoded certificates. The returned list - does not contain certificates from *capath* unless a certificate was - requested and loaded by a SSL connection. - - ..versionadded:: 3.4 - .. method:: SSLContext.set_default_verify_paths() Load a set of default "certification authority" (CA) certificates from @@ -885,7 +780,7 @@ .. method:: SSLContext.set_npn_protocols(protocols) - Specify which protocols the socket should advertise during the SSL/TLS + Specify which protocols the socket should avertise during the SSL/TLS handshake. It should be a list of strings, like ``['http/1.1', 'spdy/2']``, ordered by preference. The selection of a protocol will happen during the handshake, and will play out according to the `NPN draft specification @@ -912,7 +807,6 @@ The callback function, *server_name_callback*, will be called with three arguments; the first being the :class:`ssl.SSLSocket`, the second is a string that represents the server name that the client is intending to communicate - (or :const:`None` if the TLS Client Hello does not contain a server name) and the third argument is the original :class:`SSLContext`. The server name argument is the IDNA decoded server name. @@ -930,7 +824,7 @@ will not contain return meaningful values nor can they be called safely. The *server_name_callback* function must return ``None`` to allow the - TLS negotiation to continue. If a TLS failure is required, a constant + the TLS negotiation to continue. If a TLS failure is required, a constant :const:`ALERT_DESCRIPTION_* ` can be returned. Other return values will result in a TLS fatal error with :const:`ALERT_DESCRIPTION_INTERNAL_ERROR`. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/stat.rst --- a/Doc/library/stat.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/stat.rst Fri Feb 01 23:12:09 2013 +0100 @@ -6,8 +6,7 @@ os.lstat() and os.fstat(). .. sectionauthor:: Skip Montanaro -**Source code:** :source:`Modules/_stat.c` - :source:`Lib/stat.py` +**Source code:** :source:`Lib/stat.py` -------------- @@ -16,9 +15,6 @@ exist). For complete details about the :c:func:`stat`, :c:func:`fstat` and :c:func:`lstat` calls, consult the documentation for your system. -.. versionchanged:: 3.4 - The stat module is backed by a C implementation. - The :mod:`stat` module defines the following functions to test for specific file types: @@ -57,24 +53,6 @@ Return non-zero if the mode is from a socket. -.. function:: S_ISDOOR(mode) - - Return non-zero if the mode is from a door. - - .. versionadded:: 3.4 - -.. function:: S_ISPORT(mode) - - Return non-zero if the mode is from an event port. - - .. versionadded:: 3.4 - -.. function:: S_ISWHT(mode) - - Return non-zero if the mode is from a whiteout. - - .. versionadded:: 3.4 - Two additional functions are defined for more general manipulation of the file's mode: @@ -135,10 +113,6 @@ .. versionadded:: 3.3 - .. versionchanged:: 3.4 - The function supports :data:`S_IFDOOR`, :data:`S_IFPORT` and - :data:`S_IFWHT`. - All the variables below are simply symbolic indexes into the 10-tuple returned by :func:`os.stat`, :func:`os.fstat` or :func:`os.lstat`. @@ -236,29 +210,6 @@ FIFO. -.. data:: S_IFDOOR - - Door. - - .. versionadded:: 3.4 - -.. data:: S_IFPORT - - Event port. - - .. versionadded:: 3.4 - -.. data:: S_IFWHT - - Whiteout. - - .. versionadded:: 3.4 - -.. note:: - - :data:`S_IFDOOR`, :data:`S_IFPORT` or :data:`S_IFWHT` are defined as - 0 when the platform does not have support for the file types. - The following flags can also be used in the *mode* argument of :func:`os.chmod`: .. data:: S_ISUID diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/stdtypes.rst Fri Feb 01 23:12:09 2013 +0100 @@ -519,8 +519,9 @@ >>> int.from_bytes([255, 0, 0], byteorder='big') 16711680 - The argument *bytes* must either be a :term:`bytes-like object` or an - iterable producing bytes. + The argument *bytes* must either support the buffer protocol or be an + iterable producing bytes. :class:`bytes` and :class:`bytearray` are + examples of built-in objects that support the buffer protocol. The *byteorder* argument determines the byte order used to represent the integer. If *byteorder* is ``"big"``, the most significant byte is at the @@ -871,11 +872,11 @@ +--------------------------+--------------------------------+----------+ | ``max(s)`` | largest item of *s* | | +--------------------------+--------------------------------+----------+ -| ``s.index(x[, i[, j]])`` | index of the first occurrence | \(8) | +| ``s.index(x[, i[, j]])`` | index of the first occurence | \(8) | | | of *x* in *s* (at or after | | | | index *i* and before index *j*)| | +--------------------------+--------------------------------+----------+ -| ``s.count(x)`` | total number of occurrences of | | +| ``s.count(x)`` | total number of occurences of | | | | *x* in *s* | | +--------------------------+--------------------------------+----------+ @@ -1252,7 +1253,7 @@ the formula ``r[i] = start + step*i``, but the constraints are ``i >= 0`` and ``r[i] > stop``. - A range object will be empty if ``r[0]`` does not meet the value + A range object will be empty if ``r[0]`` does not meant the value constraint. Ranges do support negative indices, but these are interpreted as indexing from the end of the sequence determined by the positive indices. @@ -1416,9 +1417,10 @@ single: bytes; str (built-in class) If at least one of *encoding* or *errors* is given, *object* should be a - :term:`bytes-like object` (e.g. :class:`bytes` or :class:`bytearray`). In - this case, if *object* is a :class:`bytes` (or :class:`bytearray`) object, - then ``str(bytes, encoding, errors)`` is equivalent to + :class:`bytes` or :class:`bytearray` object, or more generally any object + that supports the :ref:`buffer protocol `. In this case, if + *object* is a :class:`bytes` (or :class:`bytearray`) object, then + ``str(bytes, encoding, errors)`` is equivalent to :meth:`bytes.decode(encoding, errors) `. Otherwise, the bytes object underlying the buffer object is obtained before calling :meth:`bytes.decode`. See :ref:`binaryseq` and @@ -1524,23 +1526,11 @@ .. method:: str.expandtabs([tabsize]) - Return a copy of the string where all tab characters are replaced by one or - more spaces, depending on the current column and the given tab size. Tab - positions occur every *tabsize* characters (default is 8, giving tab - positions at columns 0, 8, 16 and so on). To expand the string, the current - column is set to zero and the string is examined character by character. If - the character is a tab (``\t``), one or more space characters are inserted - in the result until the current column is equal to the next tab position. - (The tab character itself is not copied.) If the character is a newline - (``\n``) or return (``\r``), it is copied and the current column is reset to - zero. Any other character is copied unchanged and the current column is - incremented by one regardless of how the character is represented when - printed. - - >>> '01\t012\t0123\t01234'.expandtabs() - '01 012 0123 01234' - >>> '01\t012\t0123\t01234'.expandtabs(4) - '01 012 0123 01234' + Return a copy of the string where all tab characters are replaced by zero or + more spaces, depending on the current column and the given tab size. The + column number is reset to zero after each newline occurring in the string. + If *tabsize* is not given, a tab size of ``8`` characters is assumed. This + doesn't understand other non-printing characters or escape sequences. .. method:: str.find(sub[, start[, end]]) @@ -1637,8 +1627,6 @@ Return true if the string is a valid identifier according to the language definition, section :ref:`identifiers`. - Use :func:`keyword.iskeyword` to test for reserved identifiers such as - :keyword:`def` and :keyword:`class`. .. method:: str.islower() @@ -2649,7 +2637,7 @@ >>> z.nbytes 48 - Cast 1D/unsigned char to 2D/unsigned long:: + Cast 1D/unsigned char to to 2D/unsigned long:: >>> buf = struct.pack("L"*6, *list(range(6))) >>> x = memoryview(buf) @@ -2821,10 +2809,9 @@ frozenset([iterable]) Return a new set or frozenset object whose elements are taken from - *iterable*. The elements of a set must be :term:`hashable`. To - represent sets of sets, the inner sets must be :class:`frozenset` - objects. If *iterable* is not specified, a new empty set is - returned. + *iterable*. The elements of a set must be hashable. To represent sets of + sets, the inner sets must be :class:`frozenset` objects. If *iterable* is + not specified, a new empty set is returned. Instances of :class:`set` and :class:`frozenset` provide the following operations: @@ -2909,8 +2896,8 @@ based on their members. For example, ``set('abc') == frozenset('abc')`` returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``. - The subset and equality comparisons do not generalize to a total ordering - function. For example, any two nonempty disjoint sets are not equal and are not + The subset and equality comparisons do not generalize to a complete ordering + function. For example, any two disjoint sets are not equal and are not subsets of each other, so *all* of the following return ``False``: ``ab``. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/string.rst --- a/Doc/library/string.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/string.rst Fri Feb 01 23:12:09 2013 +0100 @@ -432,13 +432,12 @@ +=========+==========================================================+ | ``'e'`` | Exponent notation. Prints the number in scientific | | | notation using the letter 'e' to indicate the exponent. | - | | The default precision is ``6``. | +---------+----------------------------------------------------------+ | ``'E'`` | Exponent notation. Same as ``'e'`` except it uses an | | | upper case 'E' as the separator character. | +---------+----------------------------------------------------------+ | ``'f'`` | Fixed point. Displays the number as a fixed-point | - | | number. The default precision is ``6``. | + | | number. | +---------+----------------------------------------------------------+ | ``'F'`` | Fixed point. Same as ``'f'``, but converts ``nan`` to | | | ``NAN`` and ``inf`` to ``INF``. | @@ -465,7 +464,7 @@ | | the precision. | | | | | | A precision of ``0`` is treated as equivalent to a | - | | precision of ``1``. The default precision is ``6``. | + | | precision of ``1``. | +---------+----------------------------------------------------------+ | ``'G'`` | General format. Same as ``'g'`` except switches to | | | ``'E'`` if the number gets too large. The | @@ -689,7 +688,7 @@ This is the object passed to the constructor's *template* argument. In general, you shouldn't change it, but read-only access is not enforced. -Here is an example of how to use a Template:: +Here is an example of how to use a Template: >>> from string import Template >>> s = Template('$who likes $what') @@ -698,11 +697,11 @@ >>> d = dict(who='tim') >>> Template('Give $who $100').substitute(d) Traceback (most recent call last): - ... + [...] ValueError: Invalid placeholder in string: line 1, col 11 >>> Template('$who likes $what').substitute(d) Traceback (most recent call last): - ... + [...] KeyError: 'what' >>> Template('$who likes $what').safe_substitute(d) 'tim likes $what' diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/struct.rst --- a/Doc/library/struct.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/struct.rst Fri Feb 01 23:12:09 2013 +0100 @@ -66,19 +66,6 @@ format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``). -.. function:: iter_unpack(fmt, buffer) - - Iteratively unpack from the buffer *buffer* according to the format - string *fmt*. This function returns an iterator which will read - equally-sized chunks from the buffer until all its contents have been - consumed. The buffer's size in bytes must be a multiple of the amount - of data required by the format, as reflected by :func:`calcsize`. - - Each iteration yields a tuple as specified by the format string. - - .. versionadded:: 3.4 - - .. function:: calcsize(fmt) Return the size of the struct (and hence of the bytes object produced by @@ -401,13 +388,6 @@ (``len(buffer[offset:])`` must be at least :attr:`self.size`). - .. method:: iter_unpack(buffer) - - Identical to the :func:`iter_unpack` function, using the compiled format. - (``len(buffer)`` must be a multiple of :attr:`self.size`). - - .. versionadded:: 3.4 - .. attribute:: format The format string used to construct this Struct object. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/subprocess.rst Fri Feb 01 23:12:09 2013 +0100 @@ -116,9 +116,9 @@ *timeout* was added. -.. function:: check_output(args, *, input=None, stdin=None, stderr=None, shell=False, universal_newlines=False, timeout=None) +.. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False, timeout=None) - Run command with arguments and return its output. + Run command with arguments and return its output as a byte string. If the return code was non-zero it raises a :exc:`CalledProcessError`. The :exc:`CalledProcessError` object will have the return code in the @@ -129,21 +129,15 @@ in :ref:`frequently-used-arguments` (hence the use of keyword-only notation in the abbreviated signature). The full function signature is largely the same as that of the :class:`Popen` constructor - this functions passes all - supplied arguments other than *input* and *timeout* directly through to - that interface. In addition, *stdout* is not permitted as an argument, as - it is used internally to collect the output from the subprocess. + supplied arguments other than *timeout* directly through to that interface. + In addition, *stdout* is not permitted as an argument, as it is used + internally to collect the output from the subprocess. The *timeout* argument is passed to :meth:`Popen.wait`. If the timeout expires, the child process will be killed and then waited for again. The :exc:`TimeoutExpired` exception will be re-raised after the child process has terminated. - The *input* argument is passed to :meth:`Popen.communicate` and thus to the - subprocess's stdin. If used it must be a byte sequence, or a string if - ``universal_newlines=True``. When used, the internal :class:`Popen` object - is automatically created with ``stdin=PIPE``, and the *stdin* argument may - not be used as well. - Examples:: >>> subprocess.check_output(["echo", "Hello World!"]) @@ -152,10 +146,6 @@ >>> subprocess.check_output(["echo", "Hello World!"], universal_newlines=True) 'Hello World!\n' - >>> subprocess.check_output(["sed", "-e", "s/foo/bar/"], - ... input=b"when in the course of fooman events\n") - b'when in the course of barman events\n' - >>> subprocess.check_output("exit 1", shell=True) Traceback (most recent call last): ... @@ -177,6 +167,8 @@ ... shell=True) 'ls: non_existent_file: No such file or directory\n' + .. versionadded:: 3.1 + .. warning:: Invoking the system shell with ``shell=True`` can be a security hazard @@ -189,13 +181,9 @@ read in the current process, the child process may block if it generates enough output to the pipe to fill up the OS pipe buffer. - .. versionadded:: 3.1 - .. versionchanged:: 3.3 *timeout* was added. - .. versionchanged:: 3.4 - *input* was added. .. data:: DEVNULL @@ -300,12 +288,8 @@ .. index:: single: universal newlines; subprocess module - If *universal_newlines* is ``False`` the file objects *stdin*, *stdout* and - *stderr* will be opened as binary streams, and no line ending conversion is - done. - - If *universal_newlines* is ``True``, these file objects - will be opened as text streams in :term:`universal newlines` mode + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* and + *stderr* will be opened as text streams in :term:`universal newlines` mode using the encoding returned by :func:`locale.getpreferredencoding(False) `. For *stdin*, line ending characters ``'\n'`` in the input will be converted to the default line separator @@ -316,9 +300,11 @@ .. note:: - The newlines attribute of the file objects :attr:`Popen.stdin`, - :attr:`Popen.stdout` and :attr:`Popen.stderr` are not updated by - the :meth:`Popen.communicate` method. + The *universal_newlines* feature is supported only if Python is built + with universal newline support (the default). Also, the newlines + attribute of the file objects :attr:`Popen.stdin`, :attr:`Popen.stdout` + and :attr:`Popen.stderr` are not updated by the + :meth:`Popen.communicate` method. If *shell* is ``True``, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the @@ -372,7 +358,7 @@ functions. -.. class:: Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, \ +.. class:: Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, \ stderr=None, preexec_fn=None, close_fds=True, shell=False, \ cwd=None, env=None, universal_newlines=False, \ startupinfo=None, creationflags=0, restore_signals=True, \ @@ -444,20 +430,17 @@ untrusted input. See the warning under :ref:`frequently-used-arguments` for details. - *bufsize* will be supplied as the corresponding argument to the :meth:`io.open` - function when creating the stdin/stdout/stderr pipe file objects: - :const:`0` means unbuffered (read and write are one system call and can return short), - :const:`1` means line buffered, any other positive value means use a buffer of - approximately that size. A negative bufsize (the default) means - the system default of io.DEFAULT_BUFFER_SIZE will be used. + *bufsize*, if given, has the same meaning as the corresponding argument to the + built-in open() function: :const:`0` means unbuffered, :const:`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 :const:`0` (unbuffered). - .. versionchanged:: 3.2.4, 3.3.1 + .. note:: - *bufsize* now defaults to -1 to enable buffering by default to match the - behavior that most code expects. In 3.2.0 through 3.2.3 and 3.3.0 it - incorrectly defaulted to :const:`0` which was unbuffered and allowed - short reads. This was unintentional and did not match the behavior of - Python 2 as most code expected. + If you experience performance issues, it is recommended that you try to + enable buffering by setting *bufsize* to either -1 or a large enough + positive value (such as 4096). The *executable* argument specifies a replacement program to execute. It is very seldom needed. When ``shell=False``, *executable* replaces the @@ -551,8 +534,7 @@ If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* and *stderr* are opened as text streams in universal newlines mode, as - described above in :ref:`frequently-used-arguments`, otherwise they are - opened as binary streams. + described above in :ref:`frequently-used-arguments`. If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is passed to the underlying ``CreateProcess`` function. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/sys.rst --- a/Doc/library/sys.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/sys.rst Fri Feb 01 23:12:09 2013 +0100 @@ -307,8 +307,6 @@ programming language; see section 5.2.4.2.2 of the 1999 ISO/IEC C standard [C99]_, 'Characteristics of floating types', for details. - .. tabularcolumns:: |l|l|L| - +---------------------+----------------+--------------------------------------------------+ | attribute | float.h macro | explanation | +=====================+================+==================================================+ @@ -403,6 +401,16 @@ Use :func:`getswitchinterval` instead. +.. function:: getdefaultcloexec() + + Return the default value of the *cloexec* parameter: + see :ref:`close-on-exec flag `. + + .. seealso:: :func:`sys.setdefaultcloexec`. + + .. versionadded:: 3.4 + + .. function:: getdefaultencoding() Return the name of the current default string encoding used by the Unicode @@ -411,10 +419,9 @@ .. function:: getdlopenflags() - Return the current value of the flags that are used for - :c:func:`dlopen` calls. Symbolic names for the flag values can be - found in the :mod:`os` module (``RTLD_xxx`` constants, e.g. - :data:`os.RTLD_LAZY`). Availability: Unix. + Return the current value of the flags that are used for :c:func:`dlopen` calls. + The flag constants are defined in the :mod:`ctypes` and :mod:`DLFCN` modules. + Availability: Unix. .. function:: getfilesystemencoding() @@ -616,7 +623,29 @@ :term:`struct sequence` :data:`sys.version_info` may be used for a more human-friendly encoding of the same information. - More details of ``hexversion`` can be found at :ref:`apiabiversion` + The ``hexversion`` is a 32-bit number with the following layout: + + +-------------------------+------------------------------------------------+ + | Bits (big endian order) | Meaning | + +=========================+================================================+ + | :const:`1-8` | ``PY_MAJOR_VERSION`` (the ``2`` in | + | | ``2.1.0a3``) | + +-------------------------+------------------------------------------------+ + | :const:`9-16` | ``PY_MINOR_VERSION`` (the ``1`` in | + | | ``2.1.0a3``) | + +-------------------------+------------------------------------------------+ + | :const:`17-24` | ``PY_MICRO_VERSION`` (the ``0`` in | + | | ``2.1.0a3``) | + +-------------------------+------------------------------------------------+ + | :const:`25-28` | ``PY_RELEASE_LEVEL`` (``0xA`` for alpha, | + | | ``0xB`` for beta, ``0xC`` for release | + | | candidate and ``0xF`` for final) | + +-------------------------+------------------------------------------------+ + | :const:`29-32` | ``PY_RELEASE_SERIAL`` (the ``3`` in | + | | ``2.1.0a3``, zero for final releases) | + +-------------------------+------------------------------------------------+ + + Thus ``2.1.0a3`` is hexversion ``0x020100a3``. .. data:: implementation @@ -664,8 +693,6 @@ A :term:`struct sequence` that holds information about Python's internal representation of integers. The attributes are read only. - .. tabularcolumns:: |l|L| - +-------------------------+----------------------------------------------+ | Attribute | Explanation | +=========================+==============================================+ @@ -680,16 +707,6 @@ .. versionadded:: 3.1 -.. data:: __interactivehook__ - - When present, this function is automatically called (with no arguments) - when the interpreter is launched in :ref:`interactive mode `. - This is done after the :envvar:`PYTHONSTARTUP` file is read, so that you - can set this hook there. - - .. versionadded:: 3.4 - - .. function:: intern(string) Enter *string* in the table of "interned" strings and return the interned string @@ -758,8 +775,6 @@ This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. - However, replacing the dictionary will not necessarily work as expected and - deleting essential items from the dictionary may cause Python to fail. .. data:: path @@ -802,15 +817,12 @@ A dictionary acting as a cache for :term:`finder` objects. The keys are paths that have been passed to :data:`sys.path_hooks` and the values are the finders that are found. If a path is a valid file system path but no - finder is found on :data:`sys.path_hooks` then ``None`` is - stored. + explicit finder is found on :data:`sys.path_hooks` then ``None`` is + stored to represent the implicit default finder should be used. If the path + is not an existing path then :class:`imp.NullImporter` is set. Originally specified in :pep:`302`. - .. versionchanged:: 3.3 - ``None`` is stored instead of :class:`imp.NullImporter` when no finder - is found. - .. data:: platform @@ -901,13 +913,23 @@ :func:`setswitchinterval` instead. +.. function:: setdefaultcloexec(cloexec=True) + + Set the default value of the *cloexec* parameter: + see the :ref:`close-on-exec flag `. + + .. seealso:: :func:`sys.getdefaultcloexec`. + + .. versionadded:: 3.4 + + .. function:: setdlopenflags(n) Set the flags used by the interpreter for :c:func:`dlopen` calls, such as when the interpreter loads extension modules. Among other things, this will enable a lazy resolving of symbols when importing a module, if called as ``sys.setdlopenflags(0)``. To share symbols across extension modules, call as - ``sys.setdlopenflags(os.RTLD_GLOBAL)``. Symbolic names for the flag values + ``sys.setdlopenflags(os.RTLD_GLOBAL)``. Symbolic names for the flag modules can be found in the :mod:`os` module (``RTLD_xxx`` constants, e.g. :data:`os.RTLD_LAZY`). @@ -1109,8 +1131,6 @@ A :term:`struct sequence` holding information about the thread implementation. - .. tabularcolumns:: |l|p{0.7\linewidth}| - +------------------+---------------------------------------------------------+ | Attribute | Explanation | +==================+=========================================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/tarfile.rst Fri Feb 01 23:12:09 2013 +0100 @@ -669,11 +669,11 @@ * The POSIX.1-1988 ustar format (:const:`USTAR_FORMAT`). It supports filenames up to a length of at best 256 characters and linknames up to 100 characters. The - maximum file size is 8 GiB. This is an old and limited but widely + maximum file size is 8 gigabytes. This is an old and limited but widely supported format. * The GNU tar format (:const:`GNU_FORMAT`). It supports long filenames and - linknames, files bigger than 8 GiB and sparse files. It is the de facto + linknames, files bigger than 8 gigabytes and sparse files. It is the de facto standard on GNU/Linux systems. :mod:`tarfile` fully supports the GNU tar extensions for long names, sparse file support is read-only. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/tempfile.rst --- a/Doc/library/tempfile.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/tempfile.rst Fri Feb 01 23:12:09 2013 +0100 @@ -82,11 +82,9 @@ causes the file to roll over to an on-disk file regardless of its size. The returned object is a file-like object whose :attr:`_file` attribute - is either a :class:`BytesIO` or :class:`StringIO` object (depending on - whether binary or text *mode* was specified) or a true file - object, depending on whether :func:`rollover` has been called. This - file-like object can be used in a :keyword:`with` statement, just like - a normal file. + is either a :class:`StringIO` object or a true file object, depending on + whether :func:`rollover` has been called. This file-like object can be + used in a :keyword:`with` statement, just like a normal file. .. versionchanged:: 3.3 the truncate method now accepts a ``size`` argument. @@ -181,10 +179,11 @@ ``delete=False`` parameter:: >>> f = NamedTemporaryFile(delete=False) + >>> f + ', mode 'w+b' at 0x384698> >>> f.name - '/tmp/tmptjujjt' - >>> f.write(b"Hello World!\n") - 13 + '/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpG7V1Y0' + >>> f.write("Hello World!\n") >>> f.close() >>> os.unlink(f.name) >>> os.path.exists(f.name) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/test.rst --- a/Doc/library/test.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/test.rst Fri Feb 01 23:12:09 2013 +0100 @@ -362,29 +362,17 @@ New optional arguments *filters* and *quiet*. -.. function:: captured_stdin() - captured_stdout() - captured_stderr() +.. function:: captured_stdout() - A context managers that temporarily replaces the named stream with - :class:`io.StringIO` object. + A context manager that runs the :keyword:`with` statement body using + a :class:`StringIO.StringIO` object as sys.stdout. That object can be + retrieved using the ``as`` clause of the :keyword:`with` statement. - Example use with output streams:: + Example use:: - with captured_stdout() as stdout, captured_stderr() as stderr: + with captured_stdout() as s: print("hello") - print("error", file=sys.stderr) - assert stdout.getvalue() == "hello\n" - assert stderr.getvalue() == "error\n" - - Example use with input stream:: - - with captured_stdin() as stdin: - stdin.write('hello\n') - stdin.seek(0) - # call test code that consumes from sys.stdin - captured = input() - self.assertEqual(captured, "hello") + assert s.getvalue() == "hello\n" .. function:: temp_cwd(name='tempcwd', quiet=False, path=None) @@ -417,13 +405,6 @@ A decorator for running tests that require support for symbolic links. -.. function:: suppress_crash_popup() - - A context manager that disables Windows Error Reporting dialogs using - `SetErrorMode `_. - On other platforms it's a no-op. - - .. decorator:: anticipate_failure(condition) A decorator to conditionally mark tests with diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/threading.rst --- a/Doc/library/threading.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/threading.rst Fri Feb 01 23:12:09 2013 +0100 @@ -80,15 +80,15 @@ Return the thread stack size used when creating new threads. The optional *size* argument specifies the stack size to be used for subsequently created threads, and must be 0 (use platform or configured default) or a positive - integer value of at least 32,768 (32 KiB). If changing the thread stack size is + integer value of at least 32,768 (32kB). If changing the thread stack size is unsupported, a :exc:`RuntimeError` is raised. If the specified stack size is - invalid, a :exc:`ValueError` is raised and the stack size is unmodified. 32 KiB + invalid, a :exc:`ValueError` is raised and the stack size is unmodified. 32kB is currently the minimum supported stack size value to guarantee sufficient stack space for the interpreter itself. Note that some platforms may have particular restrictions on values for the stack size, such as requiring a - minimum stack size > 32 KiB or requiring allocation in multiples of the system + minimum stack size > 32kB or requiring allocation in multiples of the system memory page size - platform documentation should be referred to for more - information (4 KiB pages are common; using multiples of 4096 for the stack size is + information (4kB pages are common; using multiples of 4096 for the stack size is the suggested approach in the absence of more specific information). Availability: Windows, systems with POSIX threads. @@ -174,12 +174,6 @@ through the :attr:`~Thread.daemon` property or the *daemon* constructor argument. -.. note:: - Daemon threads are abruptly stopped at shutdown. Their resources (such - as open files, database transactions, etc.) may not be released properly. - If you want your threads to stop gracefully, make them non-daemonic and - use a suitable signalling mechanism such as an :class:`Event`. - There is a "main thread" object; this corresponds to the initial thread of control in the Python program. It is not a daemon thread. @@ -314,10 +308,10 @@ .. impl-detail:: - In CPython, due to the :term:`Global Interpreter Lock`, only one thread + Due to the :term:`Global Interpreter Lock`, in CPython only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). - If you want your application to make better use of the computational + If you want your application to make better of use of the computational resources of multi-core machines, you are advised to use :mod:`multiprocessing` or :class:`concurrent.futures.ProcessPoolExecutor`. However, threading is still an appropriate model if you want to run @@ -839,12 +833,10 @@ t.start() # after 30 seconds, "hello, world" will be printed -.. class:: Timer(interval, function, args=None, kwargs=None) +.. class:: Timer(interval, function, args=[], kwargs={}) Create a timer that will run *function* with arguments *args* and keyword arguments *kwargs*, after *interval* seconds have passed. - If *args* is None (the default) then an empty list will be used. - If *kwargs* is None (the default) then an empty dict will be used. .. versionchanged:: 3.3 changed from a factory function to a class. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/time.rst --- a/Doc/library/time.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/time.rst Fri Feb 01 23:12:09 2013 +0100 @@ -671,8 +671,8 @@ More object-oriented interface to dates and times. Module :mod:`locale` - Internationalization services. The locale setting affects the interpretation - of many format specifiers in :func:`strftime` and :func:`strptime`. + Internationalization services. The locale settings can affect the return values + for some of the functions in the :mod:`time` module. Module :mod:`calendar` General calendar-related functions. :func:`timegm` is the inverse of diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/tkinter.ttk.rst --- a/Doc/library/tkinter.ttk.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/tkinter.ttk.rst Fri Feb 01 23:12:09 2013 +0100 @@ -102,8 +102,6 @@ All the :mod:`ttk` Widgets accepts the following options: - .. tabularcolumns:: |l|L| - +-----------+--------------------------------------------------------------+ | Option | Description | +===========+==============================================================+ @@ -136,10 +134,8 @@ The following options are supported by widgets that are controlled by a scrollbar. - .. tabularcolumns:: |l|L| - +----------------+---------------------------------------------------------+ - | Option | Description | + | option | description | +================+=========================================================+ | xscrollcommand | Used to communicate with horizontal scrollbars. | | | | @@ -162,10 +158,11 @@ The following options are supported by labels, buttons and other button-like widgets. - .. tabularcolumns:: |l|p{0.7\linewidth}| +.. tabularcolumns:: |p{0.2\textwidth}|p{0.7\textwidth}| +.. +--------------+-----------------------------------------------------------+ - | Option | Description | + | option | description | +==============+===========================================================+ | text | Specifies a text string to be displayed inside the widget.| +--------------+-----------------------------------------------------------+ @@ -205,10 +202,8 @@ Compatibility Options ^^^^^^^^^^^^^^^^^^^^^ - .. tabularcolumns:: |l|L| - +--------+----------------------------------------------------------------+ - | Option | Description | + | option | description | +========+================================================================+ | state | May be set to "normal" or "disabled" to control the "disabled" | | | state bit. This is a write-only option: setting it changes the | @@ -221,10 +216,8 @@ The widget state is a bitmap of independent state flags. - .. tabularcolumns:: |l|L| - +------------+-------------------------------------------------------------+ - | Flag | Description | + | flag | description | +============+=============================================================+ | active | The mouse cursor is over the widget and pressing a mouse | | | button will cause some action to occur | @@ -308,10 +301,8 @@ This widget accepts the following specific options: - .. tabularcolumns:: |l|L| - +-----------------+--------------------------------------------------------+ - | Option | Description | + | option | description | +=================+========================================================+ | exportselection | Boolean value. If set, the widget selection is linked | | | to the Window Manager selection (which can be returned | @@ -389,10 +380,8 @@ This widget accepts the following specific options: - .. tabularcolumns:: |l|L| - +---------+----------------------------------------------------------------+ - | Option | Description | + | option | description | +=========+================================================================+ | height | If present and greater than zero, specifies the desired height | | | of the pane area (not including internal padding or tabs). | @@ -415,10 +404,8 @@ There are also specific options for tabs: - .. tabularcolumns:: |l|L| - +-----------+--------------------------------------------------------------+ - | Option | Description | + | option | description | +===========+==============================================================+ | state | Either "normal", "disabled" or "hidden". If "disabled", then | | | the tab is not selectable. If "hidden", then the tab is not | @@ -579,10 +566,8 @@ This widget accepts the following specific options: - .. tabularcolumns:: |l|L| - +----------+---------------------------------------------------------------+ - | Option | Description | + | option | description | +==========+===============================================================+ | orient | One of "horizontal" or "vertical". Specifies the orientation | | | of the progress bar. | @@ -650,10 +635,8 @@ This widget accepts the following specific option: - .. tabularcolumns:: |l|L| - +--------+----------------------------------------------------------------+ - | Option | Description | + | option | description | +========+================================================================+ | orient | One of "horizontal" or "vertical". Specifies the orientation of| | | the separator. | @@ -718,10 +701,11 @@ This widget accepts the following specific options: - .. tabularcolumns:: |l|p{0.7\linewidth}| +.. tabularcolumns:: |p{0.2\textwidth}|p{0.7\textwidth}| +.. +----------------+--------------------------------------------------------+ - | Option | Description | + | option | description | +================+========================================================+ | columns | A list of column identifiers, specifying the number of | | | columns and their names. | @@ -769,10 +753,8 @@ The following item options may be specified for items in the insert and item widget commands. - .. tabularcolumns:: |l|L| - +--------+---------------------------------------------------------------+ - | Option | Description | + | option | description | +========+===============================================================+ | text | The textual label to display for the item. | +--------+---------------------------------------------------------------+ @@ -797,10 +779,8 @@ The following options may be specified on tags: - .. tabularcolumns:: |l|L| - +------------+-----------------------------------------------------------+ - | Option | Description | + | option | description | +============+===========================================================+ | foreground | Specifies the text foreground color. | +------------+-----------------------------------------------------------+ @@ -842,10 +822,8 @@ The Treeview widget generates the following virtual events. - .. tabularcolumns:: |l|L| - +--------------------+--------------------------------------------------+ - | Event | Description | + | event | description | +====================+==================================================+ | <> | Generated whenever the selection changes. | +--------------------+--------------------------------------------------+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/trace.rst --- a/Doc/library/trace.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/trace.rst Fri Feb 01 23:12:09 2013 +0100 @@ -201,7 +201,7 @@ # run the new command using the given tracer tracer.run('main()') - # make a report, placing output in the current directory + # make a report, placing output in /tmp r = tracer.results() - r.write_results(show_missing=True, coverdir=".") + r.write_results(show_missing=True, coverdir="/tmp") diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/turtle.rst --- a/Doc/library/turtle.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/turtle.rst Fri Feb 01 23:12:09 2013 +0100 @@ -2301,11 +2301,9 @@ The demo scripts are: -.. tabularcolumns:: |l|L|L| - +----------------+------------------------------+-----------------------+ | Name | Description | Features | -+================+==============================+=======================+ ++----------------+------------------------------+-----------------------+ | bytedesign | complex classical | :func:`tracer`, delay,| | | turtle graphics pattern | :func:`update` | +----------------+------------------------------+-----------------------+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/types.rst --- a/Doc/library/types.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/types.rst Fri Feb 01 23:12:09 2013 +0100 @@ -107,35 +107,9 @@ C".) -.. class:: ModuleType(name, doc=None) +.. data:: ModuleType - The type of :term:`modules `. Constructor takes the name of the - module to be created and optionally its :term:`docstring`. - - .. attribute:: __doc__ - - The :term:`docstring` of the module. Defaults to ``None``. - - .. attribute:: __loader__ - - The :term:`loader` which loaded the module. Defaults to ``None``. - - .. versionchanged:: 3.4 - Defaults to ``None``. Previously the attribute was optional. - - .. attribute:: __name__ - - The name of the module. - - .. attribute:: __package__ - - Which :term:`package` a module belongs to. If the module is top-level - (i.e. not a part of any specific package) then the attribute should be set - to ``''``, else it should be set to the name of the package (which can be - :attr:`__name__` if the module is a package itself). Defaults to ``None``. - - .. versionchanged:: 3.4 - Defaults to ``None``. Previously the attribute was optional. + The type of modules. .. data:: TracebackType @@ -238,8 +212,6 @@ keys = sorted(self.__dict__) items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys) return "{}({})".format(type(self).__name__, ", ".join(items)) - def __eq__(self, other): - return self.__dict__ == other.__dict__ ``SimpleNamespace`` may be useful as a replacement for ``class NS: pass``. However, for a structured record type use :func:`~collections.namedtuple` diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/unicodedata.rst Fri Feb 01 23:12:09 2013 +0100 @@ -166,6 +166,6 @@ .. rubric:: Footnotes -.. [#] http://www.unicode.org/Public/6.2.0/ucd/NameAliases.txt +.. [#] http://www.unicode.org/Public/6.1.0/ucd/NameAliases.txt -.. [#] http://www.unicode.org/Public/6.2.0/ucd/NamedSequences.txt +.. [#] http://www.unicode.org/Public/6.1.0/ucd/NamedSequences.txt diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/unittest.mock-examples.rst --- a/Doc/library/unittest.mock-examples.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/unittest.mock-examples.rst Fri Feb 01 23:12:09 2013 +0100 @@ -45,7 +45,7 @@ This example tests that calling `ProductionClass().method` results in a call to the `something` method: - >>> class ProductionClass: + >>> class ProductionClass(object): ... def method(self): ... self.something(1, 2, 3) ... def something(self, a, b, c): @@ -69,7 +69,7 @@ The simple `ProductionClass` below has a `closer` method. If it is called with an object then it calls `close` on it. - >>> class ProductionClass: + >>> class ProductionClass(object): ... def closer(self, something): ... something.close() ... @@ -277,20 +277,6 @@ ... AttributeError: object has no attribute 'old_method' -Using a specification also enables a smarter matching of calls made to the -mock, regardless of whether some parameters were passed as positional or -named arguments:: - - >>> def f(a, b, c): pass - ... - >>> mock = Mock(spec=f) - >>> mock(1, 2, 3) - - >>> mock.assert_called_with(a=1, b=2, c=3) - -If you want this smarter matching to also work with method calls on the mock, -you can use :ref:`auto-speccing `. - If you want a stronger form of specification that prevents the setting of arbitrary attributes as well as the getting of them then you can use `spec_set` instead of `spec`. @@ -338,11 +324,11 @@ ... >>> test() -If you are patching a module (including :mod:`builtins`) then use `patch` +If you are patching a module (including `__builtin__`) then use `patch` instead of `patch.object`: - >>> mock = MagicMock(return_value=sentinel.file_handle) - >>> with patch('builtins.open', mock): + >>> mock = MagicMock(return_value = sentinel.file_handle) + >>> with patch('__builtin__.open', mock): ... handle = open('filename', 'r') ... >>> mock.assert_called_with('filename', 'r') @@ -412,7 +398,7 @@ Where you use `patch` to create a mock for you, you can get a reference to the mock using the "as" form of the with statement: - >>> class ProductionClass: + >>> class ProductionClass(object): ... def method(self): ... pass ... @@ -432,14 +418,14 @@ .. _further-examples: Further Examples ----------------- +================ Here are some more examples for some slightly more advanced scenarios. Mocking chained calls -~~~~~~~~~~~~~~~~~~~~~ +--------------------- Mocking chained calls is actually straightforward with mock once you understand the :attr:`~Mock.return_value` attribute. When a mock is called for @@ -460,7 +446,7 @@ So, suppose we have some code that looks a little bit like this: - >>> class Something: + >>> class Something(object): ... def __init__(self): ... self.backend = BackendProvider() ... def method(self): @@ -510,7 +496,7 @@ Partial mocking -~~~~~~~~~~~~~~~ +--------------- In some tests I wanted to mock out a call to `datetime.date.today() `_ to return @@ -554,7 +540,7 @@ Mocking a Generator Method -~~~~~~~~~~~~~~~~~~~~~~~~~~ +-------------------------- A Python generator is a function or method that uses the `yield statement `_ to @@ -568,7 +554,7 @@ Here's an example class with an "iter" method implemented as a generator: - >>> class Foo: + >>> class Foo(object): ... def iter(self): ... for i in [1, 2, 3]: ... yield i @@ -596,7 +582,7 @@ Applying the same patch to every test method -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-------------------------------------------- If you want several patches in place for multiple test methods the obvious way is to apply the patch decorators to every method. This can feel like unnecessary @@ -656,7 +642,7 @@ Mocking Unbound Methods -~~~~~~~~~~~~~~~~~~~~~~~ +----------------------- Whilst writing tests today I needed to patch an *unbound method* (patching the method on the class rather than on the instance). I needed self to be passed @@ -678,7 +664,7 @@ It will have `self` passed in as the first argument, which is exactly what I wanted: - >>> class Foo: + >>> class Foo(object): ... def foo(self): ... pass ... @@ -695,7 +681,7 @@ Checking multiple calls with mock -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +--------------------------------- mock has a nice API for making assertions about how your mock objects are used. @@ -737,7 +723,7 @@ Coping with mutable arguments -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +----------------------------- Another situation is rare, but can bite you, is when your mock is called with mutable arguments. `call_args` and `call_args_list` store *references* to the @@ -853,7 +839,7 @@ Nesting Patches -~~~~~~~~~~~~~~~ +--------------- Using patch as a context manager is nice, but if you do multiple patches you can end up with nested with statements indenting further and further to the @@ -901,7 +887,7 @@ Mocking a dictionary with MagicMock -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +----------------------------------- You may want to mock a dictionary, or other container object, recording all access to it whilst having it still behave like a dictionary. @@ -976,7 +962,7 @@ Mock subclasses and their attributes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +------------------------------------ There are various reasons why you might want to subclass `Mock`. One reason might be to add helper methods. Here's a silly example: @@ -1039,7 +1025,7 @@ Mocking imports with patch.dict -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +------------------------------- One situation where mocking can be hard is where you have a local import inside a function. These are harder to mock because they aren't using an object from @@ -1102,7 +1088,7 @@ Tracking order of calls and less verbose call assertions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-------------------------------------------------------- The :class:`Mock` class allows you to track the *order* of method calls on your mock objects through the :attr:`~Mock.method_calls` attribute. This @@ -1182,7 +1168,7 @@ More complex argument matching -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +------------------------------ Using the same basic concept as :data:`ANY` we can implement matchers to do more complex assertions on objects used as arguments to mocks. @@ -1197,7 +1183,7 @@ You can see in this example how a 'standard' call to `assert_called_with` isn't sufficient: - >>> class Foo: + >>> class Foo(object): ... def __init__(self, a, b): ... self.a, self.b = a, b ... @@ -1224,7 +1210,7 @@ And a matcher object that can use comparison functions like this for its equality operation would look something like this: - >>> class Matcher: + >>> class Matcher(object): ... def __init__(self, compare, some_obj): ... self.compare = compare ... self.some_obj = some_obj diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/unittest.mock.rst Fri Feb 01 23:12:09 2013 +0100 @@ -264,6 +264,7 @@ >>> mock.method.assert_called_with(1, 2, 3, test='wow') + .. method:: assert_called_once_with(*args, **kwargs) Assert that the mock was called exactly once and with the specified @@ -467,7 +468,7 @@ mock and unless the function returns the :data:`DEFAULT` singleton the call to the mock will then return whatever the function returns. If the function returns :data:`DEFAULT` then the mock will return its normal - value (from the :attr:`return_value`). + value (from the :attr:`return_value`. An example of a mock that raises an exception (to test exception handling of an API): @@ -684,27 +685,6 @@ ... KeyError -A callable mock which was created with a *spec* (or a *spec_set*) will -introspect the specification object's signature when matching calls to -the mock. Therefore, it can match the actual call's arguments regardless -of whether they were passed positionally or by name:: - - >>> def f(a, b, c): pass - ... - >>> mock = Mock(spec=f) - >>> mock(1, 2, c=3) - - >>> mock.assert_called_with(1, 2, 3) - >>> mock.assert_called_with(a=1, b=2, c=3) - -This applies to :meth:`~Mock.assert_called_with`, -:meth:`~Mock.assert_called_once_with`, :meth:`~Mock.assert_has_calls` and -:meth:`~Mock.assert_any_call`. When :ref:`auto-speccing`, it will also -apply to method calls on the mock object. - - .. versionchanged:: 3.4 - Added signature introspection on specced and autospecced mock objects. - .. class:: PropertyMock(*args, **kwargs) @@ -715,7 +695,7 @@ Fetching a `PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock with the value being set. - >>> class Foo: + >>> class Foo(object): ... @property ... def foo(self): ... return 'something' @@ -887,25 +867,6 @@ AttributeError: f -Mock names and the name attribute -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Since "name" is an argument to the :class:`Mock` constructor, if you want your -mock object to have a "name" attribute you can't just pass it in at creation -time. There are two alternatives. One option is to use -:meth:`~Mock.configure_mock`:: - - >>> mock = MagicMock() - >>> mock.configure_mock(name='my_name') - >>> mock.name - 'my_name' - -A simpler option is to simply set the "name" attribute after mock creation:: - - >>> mock = MagicMock() - >>> mock.name = "foo" - - Attaching Mocks as Attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -965,7 +926,7 @@ The patchers ------------- +============ The patch decorators are used for patching objects only within the scope of the function they decorate. They automatically handle the unpatching for you, @@ -974,7 +935,7 @@ patch -~~~~~ +----- .. note:: @@ -1027,7 +988,7 @@ you pass in `create=True`, and the attribute doesn't exist, patch will create the attribute for you when the patched function is called, and delete it again afterwards. This is useful for writing tests against - attributes that your production code creates at runtime. It is off by + attributes that your production code creates at runtime. It is off by by default because it can be dangerous. With it switched on you can write passing tests against APIs that don't actually exist! @@ -1070,7 +1031,7 @@ To configure return values on methods of *instances* on the patched class you must do this on the `return_value`. For example: - >>> class Class: + >>> class Class(object): ... def method(self): ... pass ... @@ -1147,7 +1108,7 @@ patch.object -~~~~~~~~~~~~ +------------ .. function:: patch.object(target, attribute, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) @@ -1183,7 +1144,7 @@ patch.dict -~~~~~~~~~~ +---------- .. function:: patch.dict(in_dict, values=(), clear=False, **kwargs) @@ -1243,7 +1204,7 @@ magic methods `__getitem__`, `__setitem__`, `__delitem__` and either `__iter__` or `__contains__`. - >>> class Container: + >>> class Container(object): ... def __init__(self): ... self.values = {} ... def __getitem__(self, name): @@ -1266,7 +1227,7 @@ patch.multiple -~~~~~~~~~~~~~~ +-------------- .. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) @@ -1330,7 +1291,7 @@ .. _start-and-stop: patch methods: start and stop -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +----------------------------- All the patchers have `start` and `stop` methods. These make it simpler to do patching in `setUp` methods or where you want to do multiple patches without @@ -1403,7 +1364,7 @@ TEST_PREFIX -~~~~~~~~~~~ +----------- All of the patchers can be used as class decorators. When used in this way they wrap every test method on the class. The patchers recognise methods that @@ -1417,7 +1378,7 @@ >>> value = 3 >>> >>> @patch('__main__.value', 'not three') - ... class Thing: + ... class Thing(object): ... def foo_one(self): ... print value ... def foo_two(self): @@ -1433,7 +1394,7 @@ Nesting Patch Decorators -~~~~~~~~~~~~~~~~~~~~~~~~ +------------------------ If you want to perform multiple patches then you can simply stack up the decorators. @@ -1462,7 +1423,7 @@ .. _where-to-patch: Where to patch -~~~~~~~~~~~~~~ +-------------- `patch` works by (temporarily) changing the object that a *name* points to with another one. There can be many names pointing to any individual object, so @@ -1504,7 +1465,7 @@ Patching Descriptors and Proxy Objects -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-------------------------------------- Both patch_ and patch.object_ correctly patch and restore descriptors: class methods, static methods and properties. You should patch these on the *class* @@ -1514,12 +1475,12 @@ MagicMock and magic method support ----------------------------------- +================================== .. _magic-methods: Mocking Magic Methods -~~~~~~~~~~~~~~~~~~~~~ +--------------------- :class:`Mock` supports mocking the Python protocol methods, also known as "magic methods". This allows mock objects to replace containers or other @@ -1605,7 +1566,7 @@ Magic Mock -~~~~~~~~~~ +---------- There are two `MagicMock` variants: `MagicMock` and `NonCallableMagicMock`. @@ -1734,10 +1695,10 @@ Helpers -------- +======= sentinel -~~~~~~~~ +-------- .. data:: sentinel @@ -1765,7 +1726,7 @@ DEFAULT -~~~~~~~ +------- .. data:: DEFAULT @@ -1775,8 +1736,9 @@ functions to indicate that the normal return value should be used. + call -~~~~ +---- .. function:: call(*args, **kwargs) @@ -1865,7 +1827,7 @@ create_autospec -~~~~~~~~~~~~~~~ +--------------- .. function:: create_autospec(spec, spec_set=False, instance=False, **kwargs) @@ -1892,7 +1854,7 @@ ANY -~~~ +--- .. data:: ANY @@ -1923,7 +1885,7 @@ FILTER_DIR -~~~~~~~~~~ +---------- .. data:: FILTER_DIR @@ -1978,7 +1940,7 @@ mock_open -~~~~~~~~~ +--------- .. function:: mock_open(mock=None, read_data=None) @@ -1989,12 +1951,8 @@ default) then a `MagicMock` will be created for you, with the API limited to methods or attributes available on standard file handles. - `read_data` is a string for the `read`, `readline`, and `readlines` methods - of the file handle to return. Calls to those methods will take data from - `read_data` until it is depleted. The mock of these methods is pretty - simplistic. If you need more control over the data that you are feeding to - the tested code you will need to customize this mock for yourself. - `read_data` is an empty string by default. + `read_data` is a string for the `read` method of the file handle to return. + This is an empty string by default. Using `open` as a context manager is a great way to ensure your file handles are closed properly and is becoming common:: @@ -2036,7 +1994,7 @@ .. _auto-speccing: Autospeccing -~~~~~~~~~~~~ +------------ Autospeccing is based on the existing `spec` feature of mock. It limits the api of mocks to the api of an original object (the spec), but it is recursive @@ -2180,7 +2138,7 @@ `autospec` can't know about any dynamically created attributes and restricts the api to visible attributes. - >>> class Something: + >>> class Something(object): ... def __init__(self): ... self.a = 33 ... @@ -2223,7 +2181,7 @@ .. code-block:: python - class Something: + class Something(object): a = 33 This brings up another issue. It is relatively common to provide a default @@ -2234,7 +2192,7 @@ `autospec` doesn't use a spec for members that are set to `None`. These will just be ordinary mocks (well - `MagicMocks`): - >>> class Something: + >>> class Something(object): ... member = None ... >>> mock = create_autospec(Something) @@ -2249,7 +2207,7 @@ the spec. Thankfully `patch` supports this - you can simply pass the alternative object as the `autospec` argument: - >>> class Something: + >>> class Something(object): ... def __init__(self): ... self.a = 33 ... diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/unittest.rst --- a/Doc/library/unittest.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/unittest.rst Fri Feb 01 23:12:09 2013 +0100 @@ -11,14 +11,17 @@ (If you are already familiar with the basic concepts of testing, you might want to skip to :ref:`the list of assert methods `.) -The :mod:`unittest` unit testing framework was originally inspired by JUnit -and has a similar flavor as major unit testing frameworks in other -languages. It supports test automation, sharing of setup and shutdown code -for tests, aggregation of tests into collections, and independence of the -tests from the reporting framework. - -To achieve this, :mod:`unittest` supports some important concepts in an -object-oriented way: +The Python unit testing framework, sometimes referred to as "PyUnit," is a +Python language version of JUnit, by Kent Beck and Erich Gamma. JUnit is, in +turn, a Java version of Kent's Smalltalk testing framework. Each is the de +facto standard unit testing framework for its respective language. + +:mod:`unittest` supports test automation, sharing of setup and shutdown code for +tests, aggregation of tests into collections, and independence of the tests from +the reporting framework. The :mod:`unittest` module provides classes that make +it easy to support these qualities for a set of tests. + +To achieve this, :mod:`unittest` supports some important concepts: test fixture A :dfn:`test fixture` represents the preparation needed to perform one or more @@ -27,7 +30,7 @@ process. test case - A :dfn:`test case` is the individual unit of testing. It checks for a specific + A :dfn:`test case` is the smallest unit of testing. It checks for a specific response to a particular set of inputs. :mod:`unittest` provides a base class, :class:`TestCase`, which may be used to create new test cases. @@ -41,12 +44,43 @@ a textual interface, or return a special value to indicate the results of executing the tests. +The test case and test fixture concepts are supported through the +:class:`TestCase` and :class:`FunctionTestCase` classes; the former should be +used when creating new tests, and the latter can be used when integrating +existing test code with a :mod:`unittest`\ -driven framework. When building test +fixtures using :class:`TestCase`, the :meth:`~TestCase.setUp` and +:meth:`~TestCase.tearDown` methods can be overridden to provide initialization +and cleanup for the fixture. With :class:`FunctionTestCase`, existing functions +can be passed to the constructor for these purposes. When the test is run, the +fixture initialization is run first; if it succeeds, the cleanup method is run +after the test has been executed, regardless of the outcome of the test. Each +instance of the :class:`TestCase` will only be used to run a single test method, +so a new fixture is created for each test. + +Test suites are implemented by the :class:`TestSuite` class. This class allows +individual tests and test suites to be aggregated; when the suite is executed, +all tests added directly to the suite and in "child" test suites are run. + +A test runner is an object that provides a single method, +:meth:`~TestRunner.run`, which accepts a :class:`TestCase` or :class:`TestSuite` +object as a parameter, and returns a result object. The class +:class:`TestResult` is provided for use as the result object. :mod:`unittest` +provides the :class:`TextTestRunner` as an example test runner which reports +test results on the standard error stream by default. Alternate runners can be +implemented for other environments (such as graphical environments) without any +need to derive from a specific class. + .. seealso:: Module :mod:`doctest` Another test-support module with a very different flavor. + `unittest2: A backport of new unittest features for Python 2.4-2.6 `_ + Many new features were added to unittest in Python 2.7, including test + discovery. unittest2 allows you to use these features with earlier + versions of Python. + `Simple Smalltalk Testing: With Patterns `_ Kent Beck's original paper on testing frameworks using the pattern shared by :mod:`unittest`. @@ -55,7 +89,7 @@ Third-party unittest frameworks with a lighter-weight syntax for writing tests. For example, ``assert func(10) == 42``. - `The Python Testing Tools Taxonomy `_ + `The Python Testing Tools Taxonomy `_ An extensive list of Python testing tools including functional testing frameworks and mock object libraries. @@ -139,8 +173,15 @@ OK -Passing the ``-v`` option to your test script will instruct :func:`unittest.main` -to enable a higher level of verbosity, and produce the following output:: +Instead of :func:`unittest.main`, there are other ways to run the tests with a +finer level of control, less terse output, and no requirement to be run from the +command line. For example, the last two lines may be replaced with:: + + suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions) + unittest.TextTestRunner(verbosity=2).run(suite) + +Running the revised script from the interpreter or another script produces the +following output:: test_choice (__main__.TestSequenceFunctions) ... ok test_sample (__main__.TestSequenceFunctions) ... ok @@ -263,15 +304,15 @@ Verbose output -.. cmdoption:: -s, --start-directory directory +.. cmdoption:: -s directory Directory to start discovery (``.`` default) -.. cmdoption:: -p, --pattern pattern +.. cmdoption:: -p pattern Pattern to match test files (``test*.py`` default) -.. cmdoption:: -t, --top-level-directory directory +.. cmdoption:: -t directory Top level directory of project (defaults to start directory) @@ -318,30 +359,45 @@ To make your own test cases you must write subclasses of :class:`TestCase` or use :class:`FunctionTestCase`. +An instance of a :class:`TestCase`\ -derived class is an object that can +completely run a single test method, together with optional set-up and tidy-up +code. + The testing code of a :class:`TestCase` instance should be entirely self contained, such that it can be run either in isolation or in arbitrary combination with any number of other test cases. -The simplest :class:`TestCase` subclass will simply implement a test method -(i.e. a method whose name starts with ``test``) in order to perform specific -testing code:: +The simplest :class:`TestCase` subclass will simply override the +:meth:`~TestCase.runTest` method in order to perform specific testing code:: import unittest class DefaultWidgetSizeTestCase(unittest.TestCase): - def test_default_widget_size(self): + def runTest(self): widget = Widget('The widget') - self.assertEqual(widget.size(), (50, 50)) + self.assertEqual(widget.size(), (50, 50), 'incorrect default size') Note that in order to test something, we use one of the :meth:`assert\*` methods provided by the :class:`TestCase` base class. If the test fails, an exception will be raised, and :mod:`unittest` will identify the test case as a -:dfn:`failure`. Any other exceptions will be treated as :dfn:`errors`. - -Tests can be numerous, and their set-up can be repetitive. Luckily, we -can factor out set-up code by implementing a method called -:meth:`~TestCase.setUp`, which the testing framework will automatically -call for every single test we run:: +:dfn:`failure`. Any other exceptions will be treated as :dfn:`errors`. This +helps you identify where the problem is: :dfn:`failures` are caused by incorrect +results - a 5 where you expected a 6. :dfn:`Errors` are caused by incorrect +code - e.g., a :exc:`TypeError` caused by an incorrect function call. + +The way to run a test case will be described later. For now, note that to +construct an instance of such a test case, we call its constructor without +arguments:: + + testCase = DefaultWidgetSizeTestCase() + +Now, such test cases can be numerous, and their set-up can be repetitive. In +the above case, constructing a :class:`Widget` in each of 100 Widget test case +subclasses would mean unsightly duplication. + +Luckily, we can factor out such set-up code by implementing a method called +:meth:`~TestCase.setUp`, which the testing framework will automatically call for +us when we run the test:: import unittest @@ -349,26 +405,23 @@ def setUp(self): self.widget = Widget('The widget') - def test_default_widget_size(self): + class DefaultWidgetSizeTestCase(SimpleWidgetTestCase): + def runTest(self): self.assertEqual(self.widget.size(), (50,50), 'incorrect default size') - def test_widget_resize(self): + class WidgetResizeTestCase(SimpleWidgetTestCase): + def runTest(self): self.widget.resize(100,150) self.assertEqual(self.widget.size(), (100,150), 'wrong size after resize') -.. note:: - The order in which the various tests will be run is determined - by sorting the test method names with respect to the built-in - ordering for strings. - If the :meth:`~TestCase.setUp` method raises an exception while the test is -running, the framework will consider the test to have suffered an error, and -the test method will not be executed. +running, the framework will consider the test to have suffered an error, and the +:meth:`~TestCase.runTest` method will not be executed. Similarly, we can provide a :meth:`~TestCase.tearDown` method that tidies up -after the test method has been run:: +after the :meth:`~TestCase.runTest` method has been run:: import unittest @@ -378,20 +431,59 @@ def tearDown(self): self.widget.dispose() - -If :meth:`~TestCase.setUp` succeeded, :meth:`~TestCase.tearDown` will be -run whether the test method succeeded or not. + self.widget = None + +If :meth:`~TestCase.setUp` succeeded, the :meth:`~TestCase.tearDown` method will +be run whether :meth:`~TestCase.runTest` succeeded or not. Such a working environment for the testing code is called a :dfn:`fixture`. +Often, many small test cases will use the same fixture. In this case, we would +end up subclassing :class:`SimpleWidgetTestCase` into many small one-method +classes such as :class:`DefaultWidgetSizeTestCase`. This is time-consuming and +discouraging, so in the same vein as JUnit, :mod:`unittest` provides a simpler +mechanism:: + + import unittest + + class WidgetTestCase(unittest.TestCase): + def setUp(self): + self.widget = Widget('The widget') + + def tearDown(self): + self.widget.dispose() + self.widget = None + + def test_default_size(self): + self.assertEqual(self.widget.size(), (50,50), + 'incorrect default size') + + def test_resize(self): + self.widget.resize(100,150) + self.assertEqual(self.widget.size(), (100,150), + 'wrong size after resize') + +Here we have not provided a :meth:`~TestCase.runTest` method, but have instead +provided two different test methods. Class instances will now each run one of +the :meth:`test_\*` methods, with ``self.widget`` created and destroyed +separately for each instance. When creating an instance we must specify the +test method it is to run. We do this by passing the method name in the +constructor:: + + defaultSizeTestCase = WidgetTestCase('test_default_size') + resizeTestCase = WidgetTestCase('test_resize') + Test case instances are grouped together according to the features they test. :mod:`unittest` provides a mechanism for this: the :dfn:`test suite`, -represented by :mod:`unittest`'s :class:`TestSuite` class. In most cases, -calling :func:`unittest.main` will do the right thing and collect all the -module's test cases for you, and then execute them. - -However, should you want to customize the building of your test suite, -you can do it yourself:: +represented by :mod:`unittest`'s :class:`TestSuite` class:: + + widgetTestSuite = unittest.TestSuite() + widgetTestSuite.addTest(WidgetTestCase('test_default_size')) + widgetTestSuite.addTest(WidgetTestCase('test_resize')) + +For the ease of running tests, as we will see later, it is a good idea to +provide in each test module a callable object that returns a pre-built test +suite:: def suite(): suite = unittest.TestSuite() @@ -399,6 +491,37 @@ suite.addTest(WidgetTestCase('test_resize')) return suite +or even:: + + def suite(): + tests = ['test_default_size', 'test_resize'] + + return unittest.TestSuite(map(WidgetTestCase, tests)) + +Since it is a common pattern to create a :class:`TestCase` subclass with many +similarly named test functions, :mod:`unittest` provides a :class:`TestLoader` +class that can be used to automate the process of creating a test suite and +populating it with individual tests. For example, :: + + suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase) + +will create a test suite that will run ``WidgetTestCase.test_default_size()`` and +``WidgetTestCase.test_resize``. :class:`TestLoader` uses the ``'test'`` method +name prefix to identify test methods automatically. + +Note that the order in which the various test cases will be run is +determined by sorting the test function names with respect to the +built-in ordering for strings. + +Often it is desirable to group suites of test cases together, so as to run tests +for the whole system at once. This is easy, since :class:`TestSuite` instances +can be added to a :class:`TestSuite` just as :class:`TestCase` instances can be +added to a :class:`TestSuite`:: + + suite1 = module1.TheTestSuite() + suite2 = module2.TheTestSuite() + alltests = unittest.TestSuite([suite1, suite2]) + You can place the definitions of test cases and test suites in the same modules as the code they are to test (such as :file:`widget.py`), but there are several advantages to placing the test code in a separate module, such as @@ -441,13 +564,23 @@ assert something.name is not None # ... -one can create an equivalent test case instance as follows, with optional -set-up and tear-down methods:: +one can create an equivalent test case instance as follows:: + + testcase = unittest.FunctionTestCase(testSomething) + +If there are additional set-up and tear-down methods that should be called as +part of the test case's operation, they can also be provided like so:: testcase = unittest.FunctionTestCase(testSomething, setUp=makeSomethingDB, tearDown=deleteSomethingDB) +To make migrating existing test suites easier, :mod:`unittest` supports tests +raising :exc:`AssertionError` to indicate test failure. However, it is +recommended that you use the explicit :meth:`TestCase.fail\*` and +:meth:`TestCase.assert\*` methods instead, as future versions of :mod:`unittest` +may treat :exc:`AssertionError` differently. + .. note:: Even though :class:`FunctionTestCase` can be used to quickly convert an @@ -476,7 +609,7 @@ Skipping a test is simply a matter of using the :func:`skip` :term:`decorator` or one of its conditional variants. -Basic skipping looks like this:: +Basic skipping looks like this: :: class MyTestCase(unittest.TestCase): @@ -495,7 +628,7 @@ # windows specific testing code pass -This is the output of running the example above in verbose mode:: +This is the output of running the example above in verbose mode: :: test_format (__main__.MyTestCase) ... skipped 'not supported in this library version' test_nothing (__main__.MyTestCase) ... skipped 'demonstrating skipping' @@ -506,7 +639,7 @@ OK (skipped=3) -Classes can be skipped just like methods:: +Classes can be skipped just like methods: :: @unittest.skip("showing class skipping") class MySkippedTestCase(unittest.TestCase): @@ -525,12 +658,12 @@ It's easy to roll your own skipping decorators by making a decorator that calls :func:`skip` on the test when it wants it to be skipped. This decorator skips -the test unless the passed object has a certain attribute:: +the test unless the passed object has a certain attribute: :: def skipUnlessHasattr(obj, attr): if hasattr(obj, attr): return lambda func: func - return unittest.skip("{!r} doesn't have {!r}".format(obj, attr)) + return unittest.skip("{0!r} doesn't have {1!r}".format(obj, attr)) The following decorators implement test skipping and expected failures: @@ -552,79 +685,10 @@ Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure. -.. exception:: SkipTest(reason) - - This exception is raised to skip a test. - - Usually you can use :meth:`TestCase.skipTest` or one of the skipping - decorators instead of raising this directly. - Skipped tests will not have :meth:`setUp` or :meth:`tearDown` run around them. Skipped classes will not have :meth:`setUpClass` or :meth:`tearDownClass` run. -.. _subtests: - -Distinguishing test iterations using subtests ---------------------------------------------- - -.. versionadded:: 3.4 - -When some of your tests differ only by a some very small differences, for -instance some parameters, unittest allows you to distinguish them inside -the body of a test method using the :meth:`~TestCase.subTest` context manager. - -For example, the following test:: - - class NumbersTest(unittest.TestCase): - - def test_even(self): - """ - Test that numbers between 0 and 5 are all even. - """ - for i in range(0, 6): - with self.subTest(i=i): - self.assertEqual(i % 2, 0) - -will produce the following output:: - - ====================================================================== - FAIL: test_even (__main__.NumbersTest) (i=1) - ---------------------------------------------------------------------- - Traceback (most recent call last): - File "subtests.py", line 32, in test_even - self.assertEqual(i % 2, 0) - AssertionError: 1 != 0 - - ====================================================================== - FAIL: test_even (__main__.NumbersTest) (i=3) - ---------------------------------------------------------------------- - Traceback (most recent call last): - File "subtests.py", line 32, in test_even - self.assertEqual(i % 2, 0) - AssertionError: 1 != 0 - - ====================================================================== - FAIL: test_even (__main__.NumbersTest) (i=5) - ---------------------------------------------------------------------- - Traceback (most recent call last): - File "subtests.py", line 32, in test_even - self.assertEqual(i % 2, 0) - AssertionError: 1 != 0 - -Without using a subtest, execution would stop after the first failure, -and the error would be less easy to diagnose because the value of ``i`` -wouldn't be displayed:: - - ====================================================================== - FAIL: test_even (__main__.NumbersTest) - ---------------------------------------------------------------------- - Traceback (most recent call last): - File "subtests.py", line 32, in test_even - self.assertEqual(i % 2, 0) - AssertionError: 1 != 0 - - .. _unittest-contents: Classes and functions @@ -640,24 +704,32 @@ .. class:: TestCase(methodName='runTest') - Instances of the :class:`TestCase` class represent the logical test units + Instances of the :class:`TestCase` class represent the smallest testable units in the :mod:`unittest` universe. This class is intended to be used as a base class, with specific tests being implemented by concrete subclasses. This class implements the interface needed by the test runner to allow it to drive the - tests, and methods that the test code can use to check for and report various + test, and methods that the test code can use to check for and report various kinds of failure. - Each instance of :class:`TestCase` will run a single base method: the method - named *methodName*. However, the standard implementation of the default - *methodName*, ``runTest()``, will run every method starting with ``test`` - as an individual test, and count successes and failures accordingly. - Therefore, in most uses of :class:`TestCase`, you will neither change - the *methodName* nor reimplement the default ``runTest()`` method. + Each instance of :class:`TestCase` will run a single test method: the method + named *methodName*. If you remember, we had an earlier example that went + something like this:: + + def suite(): + suite = unittest.TestSuite() + suite.addTest(WidgetTestCase('test_default_size')) + suite.addTest(WidgetTestCase('test_resize')) + return suite + + Here, we create two instances of :class:`WidgetTestCase`, each of which runs a + single test. .. versionchanged:: 3.2 - :class:`TestCase` can be instantiated successfully without providing a - *methodName*. This makes it easier to experiment with :class:`TestCase` - from the interactive interpreter. + :class:`TestCase` can be instantiated successfully without providing a method + name. This makes it easier to experiment with :class:`TestCase` from the + interactive interpreter. + + *methodName* defaults to :meth:`runTest`. :class:`TestCase` instances provide three groups of methods: one group used to run the test, another used by the test implementation to check conditions @@ -666,6 +738,7 @@ Methods in the first group (running the test) are: + .. method:: setUp() Method called to prepare the test fixture. This is called immediately @@ -717,11 +790,10 @@ .. method:: run(result=None) - Run the test, collecting the result into the :class:`TestResult` object - passed as *result*. If *result* is omitted or ``None``, a temporary - result object is created (by calling the :meth:`defaultTestResult` - method) and used. The result object is returned to :meth:`run`'s - caller. + Run the test, collecting the result into the test result object passed as + *result*. If *result* is omitted or ``None``, a temporary result + object is created (by calling the :meth:`defaultTestResult` method) and + used. The result object is returned to :meth:`run`'s caller. The same effect may be had by simply calling the :class:`TestCase` instance. @@ -738,21 +810,6 @@ .. versionadded:: 3.1 - .. method:: subTest(msg=None, **params) - - Return a context manager which executes the enclosed code block as a - subtest. *msg* and *params* are optional, arbitrary values which are - displayed whenever a subtest fails, allowing you to identify them - clearly. - - A test case can contain any number of subtest declarations, and - they can be arbitrarily nested. - - See :ref:`subtests` for more information. - - .. versionadded:: 3.4 - - .. method:: debug() Run the test without collecting the result. This allows exceptions raised @@ -950,7 +1007,7 @@ a regular expression object or a string containing a regular expression suitable for use by :func:`re.search`. Examples:: - self.assertRaisesRegex(ValueError, "invalid literal for.*XYZ'$", + self.assertRaisesRegex(ValueError, 'invalid literal for.*XYZ$', int, 'XYZ') or:: @@ -1577,9 +1634,7 @@ directory must be specified separately. If importing a module fails, for example due to a syntax error, then this - will be recorded as a single error and discovery will continue. If the - import failure is due to :exc:`SkipTest` being raised, it will be recorded - as a skip instead of an error. + will be recorded as a single error and discovery will continue. If a test package name (directory with :file:`__init__.py`) matches the pattern then the package will be checked for a ``load_tests`` @@ -1598,15 +1653,6 @@ .. versionadded:: 3.2 - .. versionchanged:: 3.4 - Modules that raise :exc:`SkipTest` on import are recorded as skips, - not errors. - - .. versionchanged:: 3.4 - Paths are sorted before being imported to ensure execution order for a - given test suite is the same even if the underlying file system's ordering - is not dependent on file name like in ext3/4. - The following attributes of a :class:`TestLoader` can be configured either by subclassing or assignment on an instance: @@ -1817,22 +1863,6 @@ :attr:`unexpectedSuccesses` attribute. - .. method:: addSubTest(test, subtest, outcome) - - Called when a subtest finishes. *test* is the test case - corresponding to the test method. *subtest* is a custom - :class:`TestCase` instance describing the subtest. - - If *outcome* is :const:`None`, the subtest succeeded. Otherwise, - it failed with an exception where *outcome* is a tuple of the form - returned by :func:`sys.exc_info`: ``(type, value, traceback)``. - - The default implementation does nothing when the outcome is a - success, and records subtest failures as normal failures. - - .. versionadded:: 3.4 - - .. class:: TextTestResult(stream, descriptions, verbosity) A concrete implementation of :class:`TestResult` used by the @@ -1850,8 +1880,7 @@ instead of repeatedly creating new instances. -.. class:: TextTestRunner(stream=None, descriptions=True, verbosity=1, failfast=False, \ - buffer=False, resultclass=None, warnings=None) +.. class:: TextTestRunner(stream=None, descriptions=True, verbosity=1, runnerclass=None, warnings=None) A basic test runner implementation that outputs results to a stream. If *stream* is ``None``, the default, :data:`sys.stderr` is used as the output stream. This class @@ -1942,10 +1971,6 @@ The *verbosity*, *failfast*, *catchbreak*, *buffer* and *warnings* parameters were added. - .. versionchanged:: 3.4 - The *defaultTest* parameter was changed to also accept an iterable of - test names. - load_tests Protocol ################### @@ -1986,10 +2011,10 @@ .. note:: - The default pattern is ``'test*.py'``. This matches all Python files - that start with ``'test'`` but *won't* match any test directories. - - A pattern like ``'test*'`` will match test packages as well as + The default pattern is 'test*.py'. This matches all Python files + that start with 'test' but *won't* match any test directories. + + A pattern like 'test*' will match test packages as well as modules. If the package :file:`__init__.py` defines ``load_tests`` then it will be @@ -2074,7 +2099,7 @@ If an exception is raised during a ``setUpClass`` then the tests in the class are not run and the ``tearDownClass`` is not run. Skipped classes will not have ``setUpClass`` or ``tearDownClass`` run. If the exception is a -:exc:`SkipTest` exception then the class will be reported as having been skipped +``SkipTest`` exception then the class will be reported as having been skipped instead of as an error. @@ -2091,7 +2116,7 @@ If an exception is raised in a ``setUpModule`` then none of the tests in the module will be run and the ``tearDownModule`` will not be run. If the exception is a -:exc:`SkipTest` exception then the module will be reported as having been skipped +``SkipTest`` exception then the module will be reported as having been skipped instead of as an error. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/urllib.parse.rst --- a/Doc/library/urllib.parse.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/urllib.parse.rst Fri Feb 01 23:12:09 2013 +0100 @@ -69,7 +69,7 @@ >>> urlparse('//www.cwi.nl:80/%7Eguido/Python.html') ParseResult(scheme='', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html', params='', query='', fragment='') - >>> urlparse('www.cwi.nl/%7Eguido/Python.html') + >>> urlparse('www.cwi.nl:80/%7Eguido/Python.html') ParseResult(scheme='', netloc='', path='www.cwi.nl:80/%7Eguido/Python.html', params='', query='', fragment='') >>> urlparse('help/Python.html') diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/urllib.request.rst Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,7 @@ The :mod:`urllib.request` module defines the following functions: -.. function:: urlopen(url, data=None[, timeout], *, cafile=None, capath=None, cadefault=False) +.. function:: urlopen(url, data=None[, timeout], *, cafile=None, capath=None, cadefault=True) Open the URL *url*, which can be either a string or a :class:`Request` object. @@ -63,34 +63,24 @@ an HTTPS request will not do any verification of the server's certificate. - For http and https urls, this function returns a - :class:`http.client.HTTPResponse` object which has the following - :ref:`httpresponse-objects` methods. + This function returns a file-like object that works as a :term:`context manager`, + with two additional methods from the :mod:`urllib.response` module - For ftp, file, and data urls and requests explicity handled by legacy - :class:`URLopener` and :class:`FancyURLopener` classes, this function - returns a :class:`urllib.response.addinfourl` object which can work as - :term:`context manager` and has methods such as - - * :meth:`~urllib.response.addinfourl.geturl` --- return the URL of the resource retrieved, + * :meth:`geturl` --- return the URL of the resource retrieved, commonly used to determine if a redirect was followed - * :meth:`~urllib.response.addinfourl.info` --- return the meta-information of the page, such as headers, + * :meth:`info` --- return the meta-information of the page, such as headers, in the form of an :func:`email.message_from_string` instance (see `Quick Reference to HTTP Headers `_) - * :meth:`~urllib.response.addinfourl.getcode` -- return the HTTP status code of the response. - Raises :exc:`URLError` on errors. Note that ``None`` may be returned if no handler handles the request (though the default installed global :class:`OpenerDirector` uses :class:`UnknownHandler` to ensure this never happens). - In addition, if proxy settings are detected (for example, when a ``*_proxy`` - environment variable like :envvar:`http_proxy` is set), - :class:`ProxyHandler` is default installed and makes sure the requests are - handled through the proxy. + In addition, default installed :class:`ProxyHandler` makes sure the requests + are handled through the proxy when they are set. The legacy ``urllib.urlopen`` function from Python 2.6 and earlier has been discontinued; :func:`urllib.request.urlopen` corresponds to the old @@ -128,10 +118,10 @@ subclasses of :class:`BaseHandler` (in which case it must be possible to call the constructor without any parameters). Instances of the following classes will be in front of the *handler*\s, unless the *handler*\s contain them, - instances of them or subclasses of them: :class:`ProxyHandler` (if proxy - settings are detected), :class:`UnknownHandler`, :class:`HTTPHandler`, - :class:`HTTPDefaultErrorHandler`, :class:`HTTPRedirectHandler`, - :class:`FTPHandler`, :class:`FileHandler`, :class:`HTTPErrorProcessor`. + instances of them or subclasses of them: :class:`ProxyHandler`, + :class:`UnknownHandler`, :class:`HTTPHandler`, :class:`HTTPDefaultErrorHandler`, + :class:`HTTPRedirectHandler`, :class:`FTPHandler`, :class:`FileHandler`, + :class:`HTTPErrorProcessor`, :class:`DataHandler`. If the Python installation has SSL support (i.e., if the :mod:`ssl` module can be imported), :class:`HTTPSHandler` will also be added. @@ -256,12 +246,12 @@ .. class:: ProxyHandler(proxies=None) Cause requests to go through a proxy. If *proxies* is given, it must be a - dictionary mapping protocol names to URLs of proxies. The default is to read - the list of proxies from the environment variables - :envvar:`_proxy`. If no proxy environment variables are set, then - in a Windows environment proxy settings are obtained from the registry's - Internet Settings section, and in a Mac OS X environment proxy information - is retrieved from the OS X System Configuration Framework. + dictionary mapping protocol names to URLs of proxies. The default is to read the + list of proxies from the environment variables :envvar:`_proxy`. + If no proxy environment variables are set, in a Windows environment, proxy + settings are obtained from the registry's Internet Settings section and in a + Mac OS X environment, proxy information is retrieved from the OS X System + Configuration Framework. To disable autodetected proxy pass an empty dictionary. @@ -396,12 +386,6 @@ The original URL passed to the constructor. - .. versionchanged:: 3.4 - - Request.full_url is a property with setter, getter and a deleter. Getting - :attr:`~Request.full_url` returns the original request URL with the - fragment, if it was present. - .. attribute:: Request.type The URI scheme. @@ -488,10 +472,6 @@ Return the URL given in the constructor. - .. versionchanged:: 3.4 - - Returns :attr:`Request.full_url` - .. method:: Request.set_proxy(host, type) @@ -500,6 +480,54 @@ URL given in the constructor. +.. method:: Request.add_data(data) + + Set the :class:`Request` data to *data*. This is ignored by all handlers except + HTTP handlers --- and there it should be a byte string, and will change the + request to be ``POST`` rather than ``GET``. Deprecated in 3.3, use + :attr:`Request.data`. + + .. deprecated:: 3.3 + + +.. method:: Request.has_data() + + Return whether the instance has a non-\ ``None`` data. Deprecated in 3.3, + use :attr:`Request.data`. + + .. deprecated:: 3.3 + + +.. method:: Request.get_data() + + Return the instance's data. Deprecated in 3.3, use :attr:`Request.data`. + + .. deprecated:: 3.3 + + +.. method:: Request.get_type() + + Return the type of the URL --- also known as the scheme. Deprecated in 3.3, + use :attr:`Request.type`. + + .. deprecated:: 3.3 + + +.. method:: Request.get_host() + + Return the host to which a connection will be made. Deprecated in 3.3, use + :attr:`Request.host`. + + .. deprecated:: 3.3 + + +.. method:: Request.get_selector() + + Return the selector --- the part of the URL that is sent to the server. + Deprecated in 3.3, use :attr:`Request.selector`. + + .. deprecated:: 3.3 + .. method:: Request.get_header(header_name, default=None) Return the value of the given header. If the header is not present, return @@ -510,10 +538,26 @@ Return a list of tuples (header_name, header_value) of the Request headers. -.. versionchanged:: 3.4 - Request methods add_data, has_data, get_data, get_type, get_host, - get_selector, get_origin_req_host and is_unverifiable deprecated since 3.3 - have been removed. + +.. method:: Request.set_proxy(host, type) + +.. method:: Request.get_origin_req_host() + + Return the request-host of the origin transaction, as defined by + :rfc:`2965`. See the documentation for the :class:`Request` constructor. + Deprecated in 3.3, use :attr:`Request.origin_req_host`. + + .. deprecated:: 3.3 + + +.. method:: Request.is_unverifiable() + + Return whether the request is unverifiable, as defined by RFC 2965. See the + documentation for the :class:`Request` constructor. Deprecated in 3.3, use + :attr:`Request.unverifiable`. + + .. deprecated:: 3.3 + .. _opener-director-objects: @@ -1089,15 +1133,6 @@ data = sys.stdin.read() print('Content-type: text-plain\n\nGot Data: "%s"' % data) -Here is an example of doing a ``PUT`` request using :class:`Request`:: - - import urllib.request - DATA=b'some data' - req = urllib.request.Request(url='http://localhost:8080', data=DATA,method='PUT') - f = urllib.request.urlopen(req) - print(f.status) - print(f.reason) - Use of Basic HTTP Authentication:: import urllib.request @@ -1254,8 +1289,6 @@ .. class:: URLopener(proxies=None, **x509) - .. deprecated:: 3.3 - Base class for opening and reading URLs. Unless you need to support opening objects using schemes other than :file:`http:`, :file:`ftp:`, or :file:`file:`, you probably want to use :class:`FancyURLopener`. @@ -1325,8 +1358,6 @@ .. class:: FancyURLopener(...) - .. deprecated:: 3.3 - :class:`FancyURLopener` subclasses :class:`URLopener` providing default handling for the following HTTP response codes: 301, 302, 303, 307 and 401. For the 30x response codes listed above, the :mailheader:`Location` header is used to fetch diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/urllib.robotparser.rst --- a/Doc/library/urllib.robotparser.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/urllib.robotparser.rst Fri Feb 01 23:12:09 2013 +0100 @@ -19,10 +19,10 @@ structure of :file:`robots.txt` files, see http://www.robotstxt.org/orig.html. -.. class:: RobotFileParser(url='') +.. class:: RobotFileParser() - This class provides methods to read, parse and answer questions about the - :file:`robots.txt` file at *url*. + This class provides a set of methods to read, parse and answer questions + about a single :file:`robots.txt` file. .. method:: set_url(url) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/venv.rst --- a/Doc/library/venv.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/venv.rst Fri Feb 01 23:12:09 2013 +0100 @@ -11,7 +11,7 @@ .. versionadded:: 3.3 -**Source code:** :source:`Lib/venv` +**Source code:** :source:`Lib/venv.py` -------------- @@ -57,10 +57,6 @@ :attr:`sys.exec_prefix` is the same as :attr:`sys.base_exec_prefix` (they all point to a non-venv Python installation). - When a venv is active, any options that change the installation path will be - ignored from all distutils configuration files to prevent projects being - inadvertently installed outside of the virtual environment. - API --- @@ -124,13 +120,11 @@ :meth:`create_configuration`, :meth:`setup_python`, :meth:`setup_scripts` and :meth:`post_setup` can be overridden. - .. method:: ensure_directories(env_dir) + .. method:: create_directories(env_dir) Creates the environment directory and all necessary directories, and returns a context object. This is just a holder for attributes (such as - paths), for use by the other methods. The directories are allowed to - exist already, as long as either ``clear`` or ``upgrade`` were - specified to allow operating on an existing environment directory. + paths), for use by the other methods. .. method:: create_configuration(context) @@ -139,10 +133,7 @@ .. method:: setup_python(context) Creates a copy of the Python executable (and, under Windows, DLLs) in - the environment. On a POSIX system, if a specific executable - ``python3.x`` was used, symlinks to ``python`` and ``python3`` will be - created pointing to that executable, unless files with those names - already exist. + the environment. .. method:: setup_scripts(context) @@ -179,8 +170,6 @@ * ``__VENV_PYTHON__`` is replaced with the absolute path of the environment's executable. - The directories are allowed to exist (for when an existing environment - is being upgraded). There is also a module-level convenience function: @@ -188,224 +177,3 @@ Create an :class:`EnvBuilder` with the given keyword arguments, and call its :meth:`~EnvBuilder.create` method with the *env_dir* argument. - -An example of extending ``EnvBuilder`` --------------------------------------- - -The following script shows how to extend :class:`EnvBuilder` by implementing a -subclass which installs setuptools and pip into a created venv:: - - import os - import os.path - from subprocess import Popen, PIPE - import sys - from threading import Thread - from urllib.parse import urlparse - from urllib.request import urlretrieve - import venv - - class ExtendedEnvBuilder(venv.EnvBuilder): - """ - This builder installs setuptools and pip so that you can pip or - easy_install other packages into the created environment. - - :param nodist: If True, setuptools and pip are not installed into the - created environment. - :param nopip: If True, pip is not installed into the created - environment. - :param progress: If setuptools or pip are installed, the progress of the - installation can be monitored by passing a progress - callable. If specified, it is called with two - arguments: a string indicating some progress, and a - context indicating where the string is coming from. - The context argument can have one of three values: - 'main', indicating that it is called from virtualize() - itself, and 'stdout' and 'stderr', which are obtained - by reading lines from the output streams of a subprocess - which is used to install the app. - - If a callable is not specified, default progress - information is output to sys.stderr. - """ - - def __init__(self, *args, **kwargs): - self.nodist = kwargs.pop('nodist', False) - self.nopip = kwargs.pop('nopip', False) - self.progress = kwargs.pop('progress', None) - self.verbose = kwargs.pop('verbose', False) - super().__init__(*args, **kwargs) - - def post_setup(self, context): - """ - Set up any packages which need to be pre-installed into the - environment being created. - - :param context: The information for the environment creation request - being processed. - """ - os.environ['VIRTUAL_ENV'] = context.env_dir - if not self.nodist: - self.install_setuptools(context) - # Can't install pip without setuptools - if not self.nopip and not self.nodist: - self.install_pip(context) - - def reader(self, stream, context): - """ - Read lines from a subprocess' output stream and either pass to a progress - callable (if specified) or write progress information to sys.stderr. - """ - progress = self.progress - while True: - s = stream.readline() - if not s: - break - if progress is not None: - progress(s, context) - else: - if not self.verbose: - sys.stderr.write('.') - else: - sys.stderr.write(s.decode('utf-8')) - sys.stderr.flush() - stream.close() - - def install_script(self, context, name, url): - _, _, path, _, _, _ = urlparse(url) - fn = os.path.split(path)[-1] - binpath = context.bin_path - distpath = os.path.join(binpath, fn) - # Download script into the env's binaries folder - urlretrieve(url, distpath) - progress = self.progress - if self.verbose: - term = '\n' - else: - term = '' - if progress is not None: - progress('Installing %s ...%s' % (name, term), 'main') - else: - sys.stderr.write('Installing %s ...%s' % (name, term)) - sys.stderr.flush() - # Install in the env - args = [context.env_exe, fn] - p = Popen(args, stdout=PIPE, stderr=PIPE, cwd=binpath) - t1 = Thread(target=self.reader, args=(p.stdout, 'stdout')) - t1.start() - t2 = Thread(target=self.reader, args=(p.stderr, 'stderr')) - t2.start() - p.wait() - t1.join() - t2.join() - if progress is not None: - progress('done.', 'main') - else: - sys.stderr.write('done.\n') - # Clean up - no longer needed - os.unlink(distpath) - - def install_setuptools(self, context): - """ - Install setuptools in the environment. - - :param context: The information for the environment creation request - being processed. - """ - url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py' - self.install_script(context, 'setuptools', url) - # clear up the setuptools archive which gets downloaded - pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz') - files = filter(pred, os.listdir(context.bin_path)) - for f in files: - f = os.path.join(context.bin_path, f) - os.unlink(f) - - def install_pip(self, context): - """ - Install pip in the environment. - - :param context: The information for the environment creation request - being processed. - """ - url = 'https://raw.github.com/pypa/pip/master/contrib/get-pip.py' - self.install_script(context, 'pip', url) - - def main(args=None): - compatible = True - if sys.version_info < (3, 3): - compatible = False - elif not hasattr(sys, 'base_prefix'): - compatible = False - if not compatible: - raise ValueError('This script is only for use with ' - 'Python 3.3 or later') - else: - import argparse - - parser = argparse.ArgumentParser(prog=__name__, - description='Creates virtual Python ' - 'environments in one or ' - 'more target ' - 'directories.') - parser.add_argument('dirs', metavar='ENV_DIR', nargs='+', - help='A directory to create the environment in.') - parser.add_argument('--no-setuptools', default=False, - action='store_true', dest='nodist', - help="Don't install setuptools or pip in the " - "virtual environment.") - parser.add_argument('--no-pip', default=False, - action='store_true', dest='nopip', - help="Don't install pip in the virtual " - "environment.") - parser.add_argument('--system-site-packages', default=False, - action='store_true', dest='system_site', - help='Give the virtual environment access to the ' - 'system site-packages dir.') - if os.name == 'nt': - use_symlinks = False - else: - use_symlinks = True - parser.add_argument('--symlinks', default=use_symlinks, - action='store_true', dest='symlinks', - help='Try to use symlinks rather than copies, ' - 'when symlinks are not the default for ' - 'the platform.') - parser.add_argument('--clear', default=False, action='store_true', - dest='clear', help='Delete the contents of the ' - 'environment directory if it ' - 'already exists, before ' - 'environment creation.') - parser.add_argument('--upgrade', default=False, action='store_true', - dest='upgrade', help='Upgrade the environment ' - 'directory to use this version ' - 'of Python, assuming Python ' - 'has been upgraded in-place.') - parser.add_argument('--verbose', default=False, action='store_true', - dest='verbose', help='Display the output ' - 'from the scripts which ' - 'install setuptools and pip.') - options = parser.parse_args(args) - if options.upgrade and options.clear: - raise ValueError('you cannot supply --upgrade and --clear together.') - builder = ExtendedEnvBuilder(system_site_packages=options.system_site, - clear=options.clear, - symlinks=options.symlinks, - upgrade=options.upgrade, - nodist=options.nodist, - nopip=options.nopip, - verbose=options.verbose) - for d in options.dirs: - builder.create(d) - - if __name__ == '__main__': - rc = 1 - try: - main() - rc = 0 - except Exception as e: - print('Error: %s' % e, file=sys.stderr) - sys.exit(rc) - - -This script is also available for download `online -`_. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/warnings.rst --- a/Doc/library/warnings.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/warnings.rst Fri Feb 01 23:12:09 2013 +0100 @@ -54,8 +54,6 @@ This categorization is useful to be able to filter out groups of warnings. The following warnings category classes are currently defined: -.. tabularcolumns:: |l|p{0.6\linewidth}| - +----------------------------------+-----------------------------------------------+ | Class | Description | +==================================+===============================================+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/wave.rst --- a/Doc/library/wave.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/wave.rst Fri Feb 01 23:12:09 2013 +0100 @@ -98,9 +98,8 @@ .. method:: Wave_read.getparams() - Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth, - framerate, nframes, comptype, compname)``, equivalent to output of the - :meth:`get\*` methods. + Returns a tuple ``(nchannels, sampwidth, framerate, nframes, comptype, + compname)``, equivalent to output of the :meth:`get\*` methods. .. method:: Wave_read.readframes(n) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/weakref.rst --- a/Doc/library/weakref.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/weakref.rst Fri Feb 01 23:12:09 2013 +0100 @@ -51,15 +51,10 @@ but keeps weak references to its elements, just like a :class:`WeakKeyDictionary` does. -:class:`finalize` provides a straight forward way to register a -cleanup function to be called when an object is garbage collected. -This is simpler to use than setting up a callback function on a raw -weak reference. - -Most programs should find that using one of these weak container types -or :class:`finalize` is all they need -- it's not usually necessary to -create your own weak references directly. The low-level machinery is -exposed by the :mod:`weakref` module for the benefit of advanced uses. +Most programs should find that using one of these weak container types is all +they need -- it's not usually necessary to create your own weak references +directly. The low-level machinery used by the weak dictionary implementations +is exposed by the :mod:`weakref` module for the benefit of advanced uses. Not all objects can be weakly referenced; those objects which can include class instances, functions written in Python (but not in C), instance methods, sets, @@ -116,24 +111,6 @@ This is a subclassable type rather than a factory function. - .. attribute:: __callback__ - - This read-only attribute returns the callback currently associated to the - weakref. If there is no callback or if the referent of the weakref is - no longer alive then this attribute will have value ``None``. - - .. note:: - - Like :meth:`__del__` methods, weak reference callbacks can be - called during interpreter shutdown when module globals have been - overwritten with :const:`None`. This can make writing robust - weak reference callbacks a challenge. Callbacks registered - using :class:`finalize` do not have to worry about this issue - because they will not be run after module teardown has begun. - - .. versionchanged:: 3.4 - Added the :attr:`__callback__` attribute. - .. function:: proxy(object[, callback]) @@ -243,66 +220,6 @@ .. versionadded:: 3.4 -.. class:: finalize(obj, func, *args, **kwargs) - - Return a callable finalizer object which will be called when *obj* - is garbage collected. A finalizer is *alive* until it is called - (either explicitly or at garbage collection), and after that it is - *dead*. Calling a live finalizer returns the result of evaluating - ``func(*arg, **kwargs)``, whereas calling a dead finalizer returns - :const:`None`. - - Exceptions raised by finalizer callbacks during garbage collection - will be shown on the standard error output, but cannot be - propagated. They are handled in the same way as exceptions raised - from an object's :meth:`__del__` method or a weak reference's - callback. - - When the program exits, each remaining live finalizer is called - unless its :attr:`atexit` attribute has been set to false. They - are called in reverse order of creation. - - A finalizer will never invoke its callback during the later part of - the interpreter shutdown when module globals are liable to have - been replaced by :const:`None`. - - .. method:: __call__() - - If *self* is alive then mark it as dead and return the result of - calling ``func(*args, **kwargs)``. If *self* is dead then return - :const:`None`. - - .. method:: detach() - - If *self* is alive then mark it as dead and return the tuple - ``(obj, func, args, kwargs)``. If *self* is dead then return - :const:`None`. - - .. method:: peek() - - If *self* is alive then return the tuple ``(obj, func, args, - kwargs)``. If *self* is dead then return :const:`None`. - - .. attribute:: alive - - Property which is true if the finalizer is alive, false otherwise. - - .. attribute:: atexit - - A writable boolean property which by default is true. When the - program exits, it calls all remaining live finalizers for which - :attr:`.atexit` is true. They are called in reverse order of - creation. - - .. note:: - - It is important to ensure that *func*, *args* and *kwargs* do - not own any references to *obj*, either directly or indirectly, - since otherwise *obj* will never be garbage collected. In - particular, *func* should not be a bound method of *obj*. - - .. versionadded:: 3.4 - .. data:: ReferenceType @@ -344,9 +261,8 @@ Weak Reference Objects ---------------------- -Weak reference objects have no methods and no attributes besides -:attr:`ref.__callback__`. A weak reference object allows the referent to be -obtained, if it still exists, by calling it: +Weak reference objects have no attributes or methods, but do allow the referent +to be obtained, if it still exists, by calling it: >>> import weakref >>> class Object: @@ -439,134 +355,3 @@ def id2obj(oid): return _id2obj_dict[oid] - -.. _finalize-examples: - -Finalizer Objects ------------------ - -Often one uses :class:`finalize` to register a callback without -bothering to keep the returned finalizer object. For instance - - >>> import weakref - >>> class Object: - ... pass - ... - >>> kenny = Object() - >>> weakref.finalize(kenny, print, "You killed Kenny!") #doctest:+ELLIPSIS - - >>> del kenny - You killed Kenny! - -The finalizer can be called directly as well. However the finalizer -will invoke the callback at most once. - - >>> def callback(x, y, z): - ... print("CALLBACK") - ... return x + y + z - ... - >>> obj = Object() - >>> f = weakref.finalize(obj, callback, 1, 2, z=3) - >>> assert f.alive - >>> assert f() == 6 - CALLBACK - >>> assert not f.alive - >>> f() # callback not called because finalizer dead - >>> del obj # callback not called because finalizer dead - -You can unregister a finalizer using its :meth:`~finalize.detach` -method. This kills the finalizer and returns the arguments passed to -the constructor when it was created. - - >>> obj = Object() - >>> f = weakref.finalize(obj, callback, 1, 2, z=3) - >>> f.detach() #doctest:+ELLIPSIS - (<__main__.Object object ...>, , (1, 2), {'z': 3}) - >>> newobj, func, args, kwargs = _ - >>> assert not f.alive - >>> assert newobj is obj - >>> assert func(*args, **kwargs) == 6 - CALLBACK - -Unless you set the :attr:`~finalize.atexit` attribute to -:const:`False`, a finalizer will be called when the program exit if it -is still alive. For instance - - >>> obj = Object() - >>> weakref.finalize(obj, print, "obj dead or exiting") #doctest:+ELLIPSIS - - >>> exit() #doctest:+SKIP - obj dead or exiting - - -Comparing finalizers with :meth:`__del__` methods -------------------------------------------------- - -Suppose we want to create a class whose instances represent temporary -directories. The directories should be deleted with their contents -when the first of the following events occurs: - -* the object is garbage collected, -* the object's :meth:`remove` method is called, or -* the program exits. - -We might try to implement the class using a :meth:`__del__` method as -follows:: - - class TempDir: - def __init__(self): - self.name = tempfile.mkdtemp() - - def remove(self): - if self.name is not None: - shutil.rmtree(self.name) - self.name = None - - @property - def removed(self): - return self.name is None - - def __del__(self): - self.remove() - -This solution has a couple of serious problems: - -* There is no guarantee that the object will be garbage collected - before the program exists, so the directory might be left. This is - because reference cycles containing an object with a :meth:`__del__` - method can never be collected. And even if the :class:`TempDir` - object is not itself part of a reference cycle, it may still be kept - alive by some unkown uncollectable reference cycle. - -* The :meth:`__del__` method may be called at shutdown after the - :mod:`shutil` module has been cleaned up, in which case - :attr:`shutil.rmtree` will have been replaced by :const:`None`. - This will cause the :meth:`__del__` method to fail and the directory - will not be removed. - -Using finalizers we can avoid these problems:: - - class TempDir: - def __init__(self): - self.name = tempfile.mkdtemp() - self._finalizer = weakref.finalize(self, shutil.rmtree, self.name) - - def remove(self): - self._finalizer() - - @property - def removed(self): - return not self._finalizer.alive - -Defined like this, even if a :class:`TempDir` object is part of a -reference cycle, that reference cycle can still be garbage collected. -If the object never gets garbage collected the finalizer will still be -called at exit. - -.. note:: - - If you create a finalizer object in a daemonic thread just as the - the program exits then there is the possibility that the finalizer - does not get called at exit. However, in a daemonic thread - :func:`atexit.register`, ``try: ... finally: ...`` and ``with: ...`` - do not guarantee that cleanup occurs either. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xml.dom.minidom.rst --- a/Doc/library/xml.dom.minidom.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xml.dom.minidom.rst Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,8 @@ -:mod:`xml.dom.minidom` --- Minimal DOM implementation -===================================================== +:mod:`xml.dom.minidom` --- Lightweight DOM implementation +========================================================= .. module:: xml.dom.minidom - :synopsis: Minimal Document Object Model (DOM) implementation. + :synopsis: Lightweight Document Object Model (DOM) implementation. .. moduleauthor:: Paul Prescod .. sectionauthor:: Paul Prescod .. sectionauthor:: Martin v. Löwis @@ -11,19 +11,17 @@ -------------- -:mod:`xml.dom.minidom` is a minimal implementation of the Document Object -Model interface, with an API similar to that in other languages. It is intended -to be simpler than the full DOM and also significantly smaller. Users who are -not already proficient with the DOM should consider using the -:mod:`xml.etree.ElementTree` module for their XML processing instead +:mod:`xml.dom.minidom` is a light-weight implementation of the Document Object +Model interface. It is intended to be simpler than the full DOM and also +significantly smaller. +.. note:: -.. warning:: - - The :mod:`xml.dom.minidom` module is not secure against - maliciously constructed data. If you need to parse untrusted or - unauthenticated data see :ref:`xml-vulnerabilities`. - + The :mod:`xml.dom.minidom` module provides an implementation of the W3C-DOM, + with an API similar to that in other programming languages. Users who are + unfamiliar with the W3C-DOM interface or who would like to write less code + for processing XML files should consider using the + :mod:`xml.etree.ElementTree` module instead. DOM applications typically start by parsing some XML into a DOM. With :mod:`xml.dom.minidom`, this is done through the parse functions:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xml.dom.pulldom.rst --- a/Doc/library/xml.dom.pulldom.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xml.dom.pulldom.rst Fri Feb 01 23:12:09 2013 +0100 @@ -17,14 +17,6 @@ responsible for explicitly pulling events from the stream, looping over those events until either processing is finished or an error condition occurs. - -.. warning:: - - The :mod:`xml.dom.pulldom` module is not secure against - maliciously constructed data. If you need to parse untrusted or - unauthenticated data see :ref:`xml-vulnerabilities`. - - Example:: from xml.dom import pulldom diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xml.dom.rst --- a/Doc/library/xml.dom.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xml.dom.rst Fri Feb 01 23:12:09 2013 +0100 @@ -357,7 +357,7 @@ Add a new child node to this node at the end of the list of children, returning *newChild*. If the node was already in - the tree, it is removed first. + in the tree, it is removed first. .. method:: Node.insertBefore(newChild, refChild) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xml.etree.elementtree.rst Fri Feb 01 23:12:09 2013 +0100 @@ -12,13 +12,6 @@ This module will use a fast implementation whenever available. The :mod:`xml.etree.cElementTree` module is deprecated. - -.. warning:: - - The :mod:`xml.etree.ElementTree` module is not secure against - maliciously constructed data. If you need to parse untrusted or - unauthenticated data see :ref:`xml-vulnerabilities`. - Tutorial -------- @@ -105,38 +98,6 @@ >>> root[0][1].text '2008' -Incremental parsing -^^^^^^^^^^^^^^^^^^^ - -It's possible to parse XML incrementally (i.e. not the whole document at once). -The most powerful tool for doing this is :class:`IncrementalParser`. It does -not require a blocking read to obtain the XML data, and is instead fed with -data incrementally with :meth:`IncrementalParser.data_received` calls. To get -the parsed XML elements, call :meth:`IncrementalParser.events`. Here's an -example:: - - >>> incparser = ET.IncrementalParser(['start', 'end']) - >>> incparser.data_received('sometext') - >>> list(incparser.events()) - [('start', )] - >>> incparser.data_received(' more text') - >>> for event, elem in incparser.events(): - ... print(event) - ... print(elem.tag, 'text=', elem.text) - ... - end - mytag text= sometext more text - -The obvious use case is applications that operate in an asynchronous fashion -where the XML data is being received from a socket or read incrementally from -some storage device. In such cases, blocking reads are unacceptable. - -Because it's so flexible, :class:`IncrementalParser` can be inconvenient -to use for simpler use-cases. If you don't mind your application blocking on -reading XML data but would still like to have incremental parsing capabilities, -take a look at :func:`iterparse`. It can be useful when you're reading a large -XML document and don't want to hold it wholly in memory. - Finding interesting elements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -310,8 +271,6 @@ Supported XPath syntax ^^^^^^^^^^^^^^^^^^^^^^ -.. tabularcolumns:: |l|L| - +-----------------------+------------------------------------------------------+ | Syntax | Meaning | +=======================+======================================================+ @@ -411,7 +370,7 @@ Parses an XML section into an element tree incrementally, and reports what's going on to the user. *source* is a filename or :term:`file object` - containing XML data. *events* is a sequence of events to report back. The + containing XML data. *events* is a list of events to report back. The supported events are the strings ``"start"``, ``"end"``, ``"start-ns"`` and ``"end-ns"`` (the "ns" events are used to get detailed namespace information). If *events* is omitted, only ``"end"`` events are reported. @@ -419,11 +378,6 @@ :class:`XMLParser` parser is used. Returns an :term:`iterator` providing ``(event, elem)`` pairs. - Note that while :func:`iterparse` builds the tree incrementally, it issues - blocking reads on *source* (or the file it names). As such, it's unsuitable - for asynchronous applications where blocking reads can't be made. For fully - asynchronous parsing, see :class:`IncrementalParser`. - .. note:: :func:`iterparse` only guarantees that it has seen the ">" @@ -434,6 +388,7 @@ If you need a fully populated element, look for "end" events instead. + .. function:: parse(source, parser=None) Parses an XML section into an element tree. *source* is a filename or file @@ -869,49 +824,6 @@ :class:`QName` instances are opaque. -IncrementalParser Objects -^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. class:: IncrementalParser(events=None, parser=None) - - An incremental, event-driven parser suitable for non-blocking applications. - *events* is a sequence of events to report back. The supported events are - the strings ``"start"``, ``"end"``, ``"start-ns"`` and ``"end-ns"`` (the "ns" - events are used to get detailed namespace information). If *events* is - omitted, only ``"end"`` events are reported. *parser* is an optional - parser instance. If not given, the standard :class:`XMLParser` parser is - used. - - .. method:: data_received(data) - - Feed the given bytes data to the incremental parser. - - .. method:: eof_received() - - Signal the incremental parser that the data stream is terminated. - - .. method:: events() - - Iterate over the events which have been encountered in the data fed - to the parser. This method yields ``(event, elem)`` pairs, where - *event* is a string representing the type of event (e.g. ``"end"``) - and *elem* is the encountered :class:`Element` object. Events - provided in a previous call to :meth:`events` will not be yielded - again. - - .. note:: - - :class:`IncrementalParser` only guarantees that it has seen the ">" - character of a starting tag when it emits a "start" event, so the - attributes are defined, but the contents of the text and tail attributes - are undefined at that point. The same applies to the element children; - they may or may not be present. - - If you need a fully populated element, look for "end" events instead. - - .. versionadded:: 3.4 - - .. _elementtree-treebuilder-objects: TreeBuilder Objects diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xml.rst --- a/Doc/library/xml.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xml.rst Fri Feb 01 23:12:09 2013 +0100 @@ -3,21 +3,8 @@ XML Processing Modules ====================== -.. module:: xml - :synopsis: Package containing XML processing modules -.. sectionauthor:: Christian Heimes -.. sectionauthor:: Georg Brandl - - Python's interfaces for processing XML are grouped in the ``xml`` package. -.. warning:: - - The XML modules are not secure against erroneous or maliciously - constructed data. If you need to parse untrusted or unauthenticated data see - :ref:`xml-vulnerabilities`. - - It is important to note that modules in the :mod:`xml` package require that there be at least one SAX-compliant XML parser available. The Expat parser is included with Python, so the :mod:`xml.parsers.expat` module will always be @@ -40,94 +27,3 @@ * :mod:`xml.sax`: SAX2 base classes and convenience functions * :mod:`xml.parsers.expat`: the Expat parser binding - - -.. _xml-vulnerabilities: - -XML vulnerabilities -=================== - -The XML processing modules are not secure against maliciously constructed data. -An attacker can abuse vulnerabilities for e.g. denial of service attacks, to -access local files, to generate network connections to other machines, or -to or circumvent firewalls. The attacks on XML abuse unfamiliar features -like inline `DTD`_ (document type definition) with entities. - - -========================= ======== ========= ========= ======== ========= -kind sax etree minidom pulldom xmlrpc -========================= ======== ========= ========= ======== ========= -billion laughs **True** **True** **True** **True** **True** -quadratic blowup **True** **True** **True** **True** **True** -external entity expansion **True** False (1) False (2) **True** False (3) -DTD retrieval **True** False False **True** False -decompression bomb False False False False **True** -========================= ======== ========= ========= ======== ========= - -1. :mod:`xml.etree.ElementTree` doesn't expand external entities and raises a - ParserError when an entity occurs. -2. :mod:`xml.dom.minidom` doesn't expand external entities and simply returns - the unexpanded entity verbatim. -3. :mod:`xmlrpclib` doesn't expand external entities and omits them. - - -billion laughs / exponential entity expansion - The `Billion Laughs`_ attack -- also known as exponential entity expansion -- - uses multiple levels of nested entities. Each entity refers to another entity - several times, the final entity definition contains a small string. Eventually - the small string is expanded to several gigabytes. The exponential expansion - consumes lots of CPU time, too. - -quadratic blowup entity expansion - A quadratic blowup attack is similar to a `Billion Laughs`_ attack; it abuses - entity expansion, too. Instead of nested entities it repeats one large entity - with a couple of thousand chars over and over again. The attack isn't as - efficient as the exponential case but it avoids triggering countermeasures of - parsers against heavily nested entities. - -external entity expansion - Entity declarations can contain more than just text for replacement. They can - also point to external resources by public identifiers or system identifiers. - System identifiers are standard URIs or can refer to local files. The XML - parser retrieves the resource with e.g. HTTP or FTP requests and embeds the - content into the XML document. - -DTD retrieval - Some XML libraries like Python's mod:'xml.dom.pulldom' retrieve document type - definitions from remote or local locations. The feature has similar - implications as the external entity expansion issue. - -decompression bomb - The issue of decompression bombs (aka `ZIP bomb`_) apply to all XML libraries - that can parse compressed XML stream like gzipped HTTP streams or LZMA-ed - files. For an attacker it can reduce the amount of transmitted data by three - magnitudes or more. - -The documentation of `defusedxml`_ on PyPI has further information about -all known attack vectors with examples and references. - -defused packages ----------------- - -`defusedxml`_ is a pure Python package with modified subclasses of all stdlib -XML parsers that prevent any potentially malicious operation. The courses of -action are recommended for any server code that parses untrusted XML data. The -package also ships with example exploits and an extended documentation on more -XML exploits like xpath injection. - -`defusedexpat`_ provides a modified libexpat and patched replacment -:mod:`pyexpat` extension module with countermeasures against entity expansion -DoS attacks. Defusedexpat still allows a sane and configurable amount of entity -expansions. The modifications will be merged into future releases of Python. - -The workarounds and modifications are not included in patch releases as they -break backward compatibility. After all inline DTD and entity expansion are -well-definied XML features. - - -.. _defusedxml: https://pypi.python.org/pypi/defusedxml/ -.. _defusedexpat: https://pypi.python.org/pypi/defusedexpat/ -.. _Billion Laughs: http://en.wikipedia.org/wiki/Billion_laughs -.. _ZIP bomb: http://en.wikipedia.org/wiki/Zip_bomb -.. _DTD: http://en.wikipedia.org/wiki/Document_Type_Definition - diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xml.sax.rst --- a/Doc/library/xml.sax.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xml.sax.rst Fri Feb 01 23:12:09 2013 +0100 @@ -13,14 +13,6 @@ SAX exceptions and the convenience functions which will be most used by users of the SAX API. - -.. warning:: - - The :mod:`xml.sax` module is not secure against maliciously - constructed data. If you need to parse untrusted or unauthenticated data see - :ref:`xml-vulnerabilities`. - - The convenience functions are: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xmlrpc.client.rst --- a/Doc/library/xmlrpc.client.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xmlrpc.client.rst Fri Feb 01 23:12:09 2013 +0100 @@ -21,13 +21,6 @@ between conformable Python objects and XML on the wire. -.. warning:: - - The :mod:`xmlrpc.client` module is not secure against maliciously - constructed data. If you need to parse untrusted or unauthenticated data see - :ref:`xml-vulnerabilities`. - - .. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, \ allow_none=False, use_datetime=False, \ use_builtin_types=False) @@ -72,8 +65,6 @@ (e.g. that can be marshalled through XML), include the following (and except where noted, they are unmarshalled as the same Python type): - .. tabularcolumns:: |l|L| - +---------------------------------+---------------------------------------------+ | Name | Meaning | +=================================+=============================================+ @@ -435,7 +426,7 @@ is a :term:`generator`; iterating over this generator yields the individual results. -A usage example of this class follows. The server code:: +A usage example of this class follows. The server code :: from xmlrpc.server import SimpleXMLRPCServer @@ -449,7 +440,7 @@ return x*y def divide(x, y): - return x // y + return x/y # A simple server with simple arithmetic functions server = SimpleXMLRPCServer(("localhost", 8000)) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/xmlrpc.server.rst --- a/Doc/library/xmlrpc.server.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/xmlrpc.server.rst Fri Feb 01 23:12:09 2013 +0100 @@ -16,13 +16,6 @@ :class:`CGIXMLRPCRequestHandler`. -.. warning:: - - The :mod:`xmlrpc.client` module is not secure against maliciously - constructed data. If you need to parse untrusted or unauthenticated data see - :ref:`xml-vulnerabilities`. - - .. class:: SimpleXMLRPCServer(addr, requestHandler=SimpleXMLRPCRequestHandler,\ logRequests=True, allow_none=False, encoding=None,\ bind_and_activate=True, use_builtin_types=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/zipfile.rst Fri Feb 01 23:12:09 2013 +0100 @@ -18,7 +18,7 @@ This module does not currently handle multi-disk ZIP files. It can handle ZIP files that use the ZIP64 extensions -(that is ZIP files that are more than 4 GiB in size). It supports +(that is ZIP files that are more than 4 GByte in size). It supports decryption of encrypted files in ZIP archives, but it currently cannot create an encrypted file. Decryption is extremely slow as it is implemented in native Python rather than C. @@ -144,11 +144,11 @@ and should be :const:`ZIP_STORED`, :const:`ZIP_DEFLATED`, :const:`ZIP_BZIP2` or :const:`ZIP_LZMA`; unrecognized values will cause :exc:`RuntimeError` to be raised. If :const:`ZIP_DEFLATED`, - :const:`ZIP_BZIP2` or :const:`ZIP_LZMA` is specified but the corresponding module + :const:`ZIP_BZIP2` or :const:`ZIP_LZMA` is specified but the corresponded module (:mod:`zlib`, :mod:`bz2` or :mod:`lzma`) is not available, :exc:`RuntimeError` is also raised. The default is :const:`ZIP_STORED`. If *allowZip64* is ``True`` zipfile will create ZIP files that use the ZIP64 extensions when - the zipfile is larger than 2 GiB. If it is false (the default) :mod:`zipfile` + the zipfile is larger than 2 GB. If it is false (the default) :mod:`zipfile` will raise an exception when the ZIP file would require ZIP64 extensions. ZIP64 extensions are disabled by default because the default :program:`zip` and :program:`unzip` commands on Unix (the InfoZIP utilities) don't support @@ -242,16 +242,6 @@ to extract to. *member* can be a filename or a :class:`ZipInfo` object. *pwd* is the password used for encrypted files. - .. note:: - - If a member filename is an absolute path, a drive/UNC sharepoint and - leading (back)slashes will be stripped, e.g.: ``///foo/bar`` becomes - ``foo/bar`` on Unix, and ``C:\foo\bar`` becomes ``foo\bar`` on Windows. - And all ``".."`` components in a member filename will be removed, e.g.: - ``../../foo../../ba..r`` becomes ``foo../ba..r``. On Windows illegal - characters (``:``, ``<``, ``>``, ``|``, ``"``, ``?``, and ``*``) - replaced by underscore (``_``). - .. method:: ZipFile.extractall(path=None, members=None, pwd=None) @@ -265,8 +255,7 @@ Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of *path*, e.g. members that have absolute filenames starting with ``"/"`` or filenames with two - dots ``".."``. This module attempts to prevent that. - See :meth:`extract` note. + dots ``".."``. .. method:: ZipFile.printdir() diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/library/zipimport.rst --- a/Doc/library/zipimport.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/library/zipimport.rst Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,7 @@ also allows an item of :data:`sys.path` to be a string naming a ZIP file archive. The ZIP archive can contain a subdirectory structure to support package imports, and a path within the archive can be specified to only import from a -subdirectory. For example, the path :file:`example.zip/lib/` would only +subdirectory. For example, the path :file:`/tmp/example.zip/lib/` would only import from the :file:`lib/` subdirectory within the archive. Any files may be present in the ZIP archive, but only files :file:`.py` and @@ -147,8 +147,8 @@ Here is an example that imports a module from a ZIP archive - note that the :mod:`zipimport` module is not explicitly used. :: - $ unzip -l example.zip - Archive: example.zip + $ unzip -l /tmp/example.zip + Archive: /tmp/example.zip Length Date Time Name -------- ---- ---- ---- 8467 11-26-02 22:30 jwzthreading.py @@ -157,8 +157,8 @@ $ ./python Python 2.3 (#1, Aug 1 2003, 19:54:32) >>> import sys - >>> sys.path.insert(0, 'example.zip') # Add .zip file to front of path + >>> sys.path.insert(0, '/tmp/example.zip') # Add .zip file to front of path >>> import jwzthreading >>> jwzthreading.__file__ - 'example.zip/jwzthreading.py' + '/tmp/example.zip/jwzthreading.py' diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/license.rst --- a/Doc/license.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/license.rst Fri Feb 01 23:12:09 2013 +0100 @@ -120,12 +120,8 @@ +----------------+--------------+------------+------------+-----------------+ | 3.2.3 | 3.2.2 | 2012 | PSF | yes | +----------------+--------------+------------+------------+-----------------+ -| 3.2.4 | 3.2.3 | 2013 | PSF | yes | -+----------------+--------------+------------+------------+-----------------+ | 3.3.0 | 3.2 | 2012 | PSF | yes | +----------------+--------------+------------+------------+-----------------+ -| 3.3.1 | 3.3.0 | 2013 | PSF | yes | -+----------------+--------------+------------+------------+-----------------+ | 3.4.0 | 3.3.0 | 2014 | PSF | yes | +----------------+--------------+------------+------------+-----------------+ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/make.bat --- a/Doc/make.bat Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/make.bat Fri Feb 01 23:12:09 2013 +0100 @@ -2,7 +2,7 @@ setlocal set SVNROOT=http://svn.python.org/projects -if "%PYTHON%" EQU "" set PYTHON=py -2 +if "%PYTHON%" EQU "" set PYTHON=..\pcbuild\python if "%HTMLHELP%" EQU "" set HTMLHELP=%ProgramFiles%\HTML Help Workshop\hhc.exe if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/sphinxext/patchlevel.py`) do set DISTVERSION=%%v diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/reference/compound_stmts.rst --- a/Doc/reference/compound_stmts.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/reference/compound_stmts.rst Fri Feb 01 23:12:09 2013 +0100 @@ -493,15 +493,14 @@ value, all following parameters up until the "``*``" must also have a default value --- this is a syntactic restriction that is not expressed by the grammar. -**Default parameter values are evaluated from left to right when the function -definition is executed.** This means that the expression is evaluated once, when -the function is defined, and that the same "pre-computed" value is used for each -call. This is especially important to understand when a default parameter is a -mutable object, such as a list or a dictionary: if the function modifies the -object (e.g. by appending an item to a list), the default value is in effect -modified. This is generally not what was intended. A way around this is to use -``None`` as the default, and explicitly test for it in the body of the function, -e.g.:: +**Default parameter values are evaluated when the function definition is +executed.** This means that the expression is evaluated once, when the function +is defined, and that the same "pre-computed" value is used for each call. This +is especially important to understand when a default parameter is a mutable +object, such as a list or a dictionary: if the function modifies the object +(e.g. by appending an item to a list), the default value is in effect modified. +This is generally not what was intended. A way around this is to use ``None`` +as the default, and explicitly test for it in the body of the function, e.g.:: def whats_on_the_telly(penguin=None): if penguin is None: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/reference/datamodel.rst Fri Feb 01 23:12:09 2013 +0100 @@ -448,8 +448,6 @@ Special attributes: - .. tabularcolumns:: |l|L|l| - +-------------------------+-------------------------------+-----------+ | Attribute | Meaning | | +=========================+===============================+===========+ @@ -1264,21 +1262,10 @@ Called by built-in function :func:`hash` and for operations on members of hashed collections including :class:`set`, :class:`frozenset`, and - :class:`dict`. :meth:`__hash__` should return an integer. The only - required property is that objects which compare equal have the same hash - value; it is advised to somehow mix together (e.g. using exclusive or) the - hash values for the components of the object that also play a part in - comparison of objects. - - .. note:: - - :func:`hash` truncates the value returned from an object's custom - :meth:`__hash__` method to the size of a :c:type:`Py_ssize_t`. This is - typically 8 bytes on 64-bit builds and 4 bytes on 32-bit builds. If an - object's :meth:`__hash__` must interoperate on builds of different bit - sizes, be sure to check the width on all supported builds. An easy way - to do this is with - ``python -c "import sys; print(sys.hash_info.width)"`` + :class:`dict`. :meth:`__hash__` should return an integer. The only required + property is that objects which compare equal have the same hash value; it is + advised to somehow mix together (e.g. using exclusive or) the hash values for + the components of the object that also play a part in comparison of objects. If a class does not define an :meth:`__eq__` method it should not define a :meth:`__hash__` operation either; if it defines :meth:`__eq__` but not diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/reference/expressions.rst Fri Feb 01 23:12:09 2013 +0100 @@ -84,13 +84,14 @@ definition begins with two or more underscore characters and does not end in two or more underscores, it is considered a :dfn:`private name` of that class. Private names are transformed to a longer form before code is generated for -them. The transformation inserts the class name, with leading underscores -removed and a single underscore inserted, in front of the name. For example, -the identifier ``__spam`` occurring in a class named ``Ham`` will be transformed -to ``_Ham__spam``. This transformation is independent of the syntactical -context in which the identifier is used. If the transformed name is extremely -long (longer than 255 characters), implementation defined truncation may happen. -If the class name consists only of underscores, no transformation is done. +them. The transformation inserts the class name in front of the name, with +leading underscores removed, and a single underscore inserted in front of the +class name. For example, the identifier ``__spam`` occurring in a class named +``Ham`` will be transformed to ``_Ham__spam``. This transformation is +independent of the syntactical context in which the identifier is used. If the +transformed name is extremely long (longer than 255 characters), implementation +defined truncation may happen. If the class name consists only of underscores, +no transformation is done. .. _atom-literals: @@ -1334,7 +1335,7 @@ | :keyword:`not` ``x`` | Boolean NOT | +-----------------------------------------------+-------------------------------------+ | :keyword:`in`, :keyword:`not in`, | Comparisons, including membership | -| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests | +| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | | ``<=``, ``>``, ``>=``, ``!=``, ``==`` | | +-----------------------------------------------+-------------------------------------+ | ``|`` | Bitwise OR | diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/reference/import.rst --- a/Doc/reference/import.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/reference/import.rst Fri Feb 01 23:12:09 2013 +0100 @@ -353,11 +353,7 @@ * The loader may set the ``__file__`` attribute of the module. If set, this attribute's value must be a string. The loader may opt to leave ``__file__`` unset if it has no semantic meaning (e.g. a module loaded from - a database). If ``__file__`` is set, it may also be appropriate to set the - ``__cached__`` attribute which is the path to any compiled version of the - code (e.g. byte-compiled file). The file does not need to exist to set this - attribute; the path can simply point to whether the compiled file would - exist (see :pep:`3147`). + a database). * The loader may set the ``__name__`` attribute of the module. While not required, setting this attribute is highly recommended so that the @@ -373,18 +369,16 @@ * The ``__loader__`` attribute must be set to the loader object that loaded the module. This is mostly for introspection and reloading, but can be used for additional loader-specific functionality, for example getting - data associated with a loader. If the attribute is missing or set to ``None`` - then the import machinery will automatically set it **after** the module has - been imported. + data associated with a loader. - * The module's ``__package__`` attribute must be set. Its value must be a + * The module's ``__package__`` attribute should be set. Its value must be a string, but it can be the same value as its ``__name__``. If the attribute is set to ``None`` or is missing, the import system will fill it in with a - more appropriate value **after** the module has been imported. - When the module is a package, its ``__package__`` value should be set to its - ``__name__``. When the module is not a package, ``__package__`` should be - set to the empty string for top-level modules, or for submodules, to the - parent package's name. See :pep:`366` for further details. + more appropriate value. When the module is a package, its ``__package__`` + value should be set to its ``__name__``. When the module is not a package, + ``__package__`` should be set to the empty string for top-level modules, or + for submodules, to the parent package's name. See :pep:`366` for further + details. This attribute is used instead of ``__name__`` to calculate explicit relative imports for main modules, as defined in :pep:`366`. @@ -427,8 +421,8 @@ * If the module has a ``__file__`` attribute, this is used as part of the module's repr. - * If the module has no ``__file__`` but does have a ``__loader__`` that is not - ``None``, then the loader's repr is used as part of the module's repr. + * If the module has no ``__file__`` but does have a ``__loader__``, then the + loader's repr is used as part of the module's repr. * Otherwise, just use the module's ``__name__`` in the repr. @@ -691,7 +685,8 @@ :pep:`338` defines executing modules as scripts. -.. rubric:: Footnotes +Footnotes +========= .. [#fnmo] See :class:`types.ModuleType`. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/reference/simple_stmts.rst --- a/Doc/reference/simple_stmts.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/reference/simple_stmts.rst Fri Feb 01 23:12:09 2013 +0100 @@ -737,6 +737,22 @@ to avoid accidentally exporting items that are not part of the API (such as library modules which were imported and used within the module). +The :keyword:`from` form with ``*`` may only occur in a module scope. +Attempting to use it in class or function definitions will raise a +:exc:`SyntaxError`. + +.. index:: single: __all__ (optional module attribute) + +The *public names* defined by a module are determined by checking the module's +namespace for a variable named ``__all__``; if defined, it must be a sequence +of strings which are names defined or imported by that module. The names +given in ``__all__`` are all considered public and are required to exist. If +``__all__`` is not defined, the set of public names includes all names found +in the module's namespace which do not begin with an underscore character +(``'_'``). ``__all__`` should contain the entire public API. It is intended +to avoid accidentally exporting items that are not part of the API (such as +library modules which were imported and used within the module). + The :keyword:`from` form with ``*`` may only occur in a module scope. The wild card form of import --- ``import *`` --- is only allowed at the module level. Attempting to use it in class or function definitions will raise a diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tools/sphinxext/susp-ignored.csv --- a/Doc/tools/sphinxext/susp-ignored.csv Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tools/sphinxext/susp-ignored.csv Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,9 @@ c-api/arg,,:ref,"PyArg_ParseTuple(args, ""O|O:ref"", &object, &callback)" c-api/list,,:high,list[low:high] +c-api/list,,:high,list[low:high] = itemlist c-api/sequence,,:i2,del o[i1:i2] c-api/sequence,,:i2,o[i1:i2] +c-api/sequence,,:i2,o[i1:i2] = v c-api/unicode,,:end,str[start:end] c-api/unicode,,:start,unicode[start:start+length] distutils/examples,267,`,This is the description of the ``foobar`` package. @@ -15,7 +17,9 @@ faq/programming,,::,for x in sequence[::-1]: faq/programming,,:reduce,"print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y," faq/programming,,:reduce,"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro," -faq/windows,,:bd8afb90ebf2,"Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32" +faq/windows,229,:EOF,@setlocal enableextensions & python -x %~f0 %* & goto :EOF +faq/windows,393,:REG,.py :REG_SZ: c:\\python.exe -u %s %s +howto/cporting,,:add,"if (!PyArg_ParseTuple(args, ""ii:add_ints"", &one, &two))" howto/cporting,,:encode,"if (!PyArg_ParseTuple(args, ""O:encode_object"", &myobj))" howto/cporting,,:say,"if (!PyArg_ParseTuple(args, ""U:say_hello"", &name))" howto/curses,,:black,"They are: 0:black, 1:red, 2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and" @@ -30,6 +34,8 @@ howto/ipaddress,,::,>>> ipaddress.ip_address('2001:DB8::1') howto/ipaddress,,:db8,IPv6Address('2001:db8::1') howto/ipaddress,,::,IPv6Address('2001:db8::1') +howto/ipaddress,,:db8,IPv6Address('2001:db8::1') +howto/ipaddress,,::,IPv6Address('2001:db8::1') howto/ipaddress,,::,IPv6Address('::1') howto/ipaddress,,:db8,>>> ipaddress.ip_network('2001:db8::0/96') howto/ipaddress,,::,>>> ipaddress.ip_network('2001:db8::0/96') @@ -37,27 +43,31 @@ howto/ipaddress,,::,IPv6Network('2001:db8::/96') howto/ipaddress,,:db8,IPv6Network('2001:db8::/128') howto/ipaddress,,::,IPv6Network('2001:db8::/128') +howto/ipaddress,,:db8,>>> ipaddress.ip_network('2001:db8::1/96') +howto/ipaddress,,::,>>> ipaddress.ip_network('2001:db8::1/96') howto/ipaddress,,:db8,IPv6Interface('2001:db8::1/96') howto/ipaddress,,::,IPv6Interface('2001:db8::1/96') howto/ipaddress,,:db8,>>> addr6 = ipaddress.ip_address('2001:db8::1') howto/ipaddress,,::,>>> addr6 = ipaddress.ip_address('2001:db8::1') howto/ipaddress,,:db8,>>> host6 = ipaddress.ip_interface('2001:db8::1/96') howto/ipaddress,,::,>>> host6 = ipaddress.ip_interface('2001:db8::1/96') +howto/ipaddress,,:db8,IPv6Network('2001:db8::/96') +howto/ipaddress,,::,IPv6Network('2001:db8::/96') +howto/ipaddress,,:db8,>>> net6 = ipaddress.ip_network('2001:db8::0/96') +howto/ipaddress,,::,>>> net6 = ipaddress.ip_network('2001:db8::0/96') howto/ipaddress,,:db8,>>> net6 = ipaddress.ip_network('2001:db8::0/96') howto/ipaddress,,::,>>> net6 = ipaddress.ip_network('2001:db8::0/96') howto/ipaddress,,:ffff,IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') howto/ipaddress,,::,IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') howto/ipaddress,,::,IPv6Address('::ffff:ffff') howto/ipaddress,,:ffff,IPv6Address('::ffff:ffff') +howto/ipaddress,,::,IPv6Address('2001::1') +howto/ipaddress,,::,IPv6Address('2001::ffff:ffff') +howto/ipaddress,,:ffff,IPv6Address('2001::ffff:ffff') +howto/ipaddress,,:db8,'2001:db8::' +howto/ipaddress,,::,'2001:db8::' howto/ipaddress,,:db8,'2001:db8::/96' howto/ipaddress,,::,'2001:db8::/96' -howto/ipaddress,,:db8,>>> ipaddress.ip_interface('2001:db8::1/96') -howto/ipaddress,,::,>>> ipaddress.ip_interface('2001:db8::1/96') -howto/ipaddress,,:db8,'2001:db8::1' -howto/ipaddress,,::,'2001:db8::1' -howto/ipaddress,,:db8,IPv6Address('2001:db8::ffff:ffff') -howto/ipaddress,,::,IPv6Address('2001:db8::ffff:ffff') -howto/ipaddress,,:ffff,IPv6Address('2001:db8::ffff:ffff') howto/logging,,:And,"WARNING:And this, too" howto/logging,,:And,"WARNING:root:And this, too" howto/logging,,:Doing,INFO:root:Doing something @@ -85,15 +95,18 @@ howto/regex,,::, howto/regex,,:foo,(?:foo) howto/urllib2,,:example,"for example ""joe@password:example.com""" +howto/webservers,,.. image:,.. image:: http.png library/audioop,,:ipos,"# factor = audioop.findfactor(in_test[ipos*2:ipos*2+len(out_test)]," library/bisect,32,:hi,all(val >= x for val in a[i:hi]) library/bisect,42,:hi,all(val > x for val in a[i:hi]) -library/concurrent.futures,,:url,"future_to_url = {executor.submit(load_url, url, 60):url for url in URLS}" library/configparser,,:home,my_dir: ${Common:home_dir}/twosheds library/configparser,,:option,${section:option} library/configparser,,:path,python_dir: ${Frameworks:path}/Python/Versions/${Frameworks:Python} library/configparser,,:Python,python_dir: ${Frameworks:path}/Python/Versions/${Frameworks:Python} +library/configparser,,`,# Set the optional `raw` argument of get() to True if you wish to disable library/configparser,,:system,path: ${Common:system_dir}/Library/Frameworks/ +library/configparser,,`,# The optional `fallback` argument can be used to provide a fallback value +library/configparser,,`,# The optional `vars` argument is a dict with members that will take library/datetime,,:MM, library/datetime,,:SS, library/decimal,,:optional,"trailneg:optional trailing minus indicator" @@ -102,13 +115,15 @@ library/difflib,,:i1, library/difflib,,:i2, library/difflib,,:j2, +library/dis,,:TOS, +library/dis,,`,TOS = `TOS` library/doctest,,`,``factorial`` from the ``example`` module: library/doctest,,`,The ``example`` module library/doctest,,`,Using ``factorial`` -library/exceptions,,:err,err.object[err.start:err.end] library/functions,,:step,a[start:stop:step] library/functions,,:stop,"a[start:stop, i]" library/functions,,:stop,a[start:stop:step] +library/hotshot,,:lineno,"ncalls tottime percall cumtime percall filename:lineno(function)" library/http.client,,:port,host:port library/http.cookies,,`,!#$%&'*+-.^_`|~: library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS" @@ -124,6 +139,24 @@ library/ipaddress,,::,>>> ipaddress.IPv6Address('2001:db8::1000') library/ipaddress,,:db8,IPv6Address('2001:db8::1000') library/ipaddress,,::,IPv6Address('2001:db8::1000') +library/ipaddress,,:db8,>>> ipaddress.IPv6Interface('2001:db8::1000/96') +library/ipaddress,,::,>>> ipaddress.IPv6Interface('2001:db8::1000/96') +library/ipaddress,,:db8,IPv6Interface('2001:db8::1000/96') +library/ipaddress,,::,IPv6Interface('2001:db8::1000/96') +library/ipaddress,,:db8,>>> ipaddress.IPv6Interface('2001:db8::1000/96').network +library/ipaddress,,::,>>> ipaddress.IPv6Interface('2001:db8::1000/96').network +library/ipaddress,,:db8,IPv6Network('2001:db8::/96') +library/ipaddress,,::,IPv6Network('2001:db8::/96') +library/ipaddress,,:db8,>>> ipaddress.IPv6Network('2001:db8::/96') +library/ipaddress,,::,>>> ipaddress.IPv6Network('2001:db8::/96') +library/ipaddress,,:db8,IPv6Network('2001:db8::/96') +library/ipaddress,,::,IPv6Network('2001:db8::/96') +library/ipaddress,,:db8,>>> ipaddress.IPv6Network('2001:db8::/96').netmask +library/ipaddress,,::,>>> ipaddress.IPv6Network('2001:db8::/96').netmask +library/ipaddress,,:ffff,IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') +library/ipaddress,,::,IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') +library/ipaddress,,:db8,">>> ipaddress.IPv6Network('2001:db8::1000/96', strict=False)" +library/ipaddress,,::,">>> ipaddress.IPv6Network('2001:db8::1000/96', strict=False)" library/ipaddress,,::,"""::abc:7:def""" library/ipaddress,,:def,"""::abc:7:def""" library/ipaddress,,::,::FFFF/96 @@ -131,20 +164,41 @@ library/ipaddress,,::,2001::/32 library/ipaddress,,::,>>> str(ipaddress.IPv6Address('::1')) library/ipaddress,,::,'::1' +library/ipaddress,,::,>>> int(ipaddress.IPv6Address('::1')) library/ipaddress,,:ff00,ffff:ff00:: library/ipaddress,,:db00,2001:db00::0/24 library/ipaddress,,::,2001:db00::0/24 library/ipaddress,,:db00,2001:db00::0/ffff:ff00:: library/ipaddress,,::,2001:db00::0/ffff:ff00:: +library/ipaddress,,:ff00,2001:db00::0/ffff:ff00:: library/itertools,,:step,elements from seq[start:stop:step] library/itertools,,:stop,elements from seq[start:stop:step] library/linecache,,:sys,"sys:x:3:3:sys:/dev:/bin/sh" +library/logging,,:And, +library/logging,,:Doing,INFO:root:Doing something +library/logging,,:Finished,INFO:root:Finished +library/logging,,:logger,severity:logger name:message +library/logging,,:Look,WARNING:root:Look before you leap! +library/logging,,:message,severity:logger name:message +library/logging,,:package1, +library/logging,,:package2, +library/logging,,:port,host:port +library/logging,,:root, +library/logging,,:So,INFO:root:So should this +library/logging,,:So,INFO:So should this +library/logging,,:Started,INFO:root:Started +library/logging,,:This, +library/logging,,:Watch,WARNING:root:Watch out! library/logging.handlers,,:port,host:port library/mmap,,:i2,obj[i1:i2] library/multiprocessing,,`,# Add more tasks using `put()` library/multiprocessing,,`,# A test file for the `multiprocessing` package library/multiprocessing,,`,# A test of `multiprocessing.Pool` class library/multiprocessing,,`,# `BaseManager`. +library/multiprocessing,,`,`Cluster` is a subclass of `SyncManager` so it allows creation of +library/multiprocessing,,`,# create server for a `HostManager` object +library/multiprocessing,,`,# Depends on `multiprocessing` package -- tested with `processing-0.60` +library/multiprocessing,,`,`hostname` gives the name of the host. If hostname is not library/multiprocessing,,`,# in the original order then consider using `Pool.map()` or library/multiprocessing,,`,">>> l._callmethod('__getitem__', (20,)) # equiv to `l[20]`" library/multiprocessing,,`,">>> l._callmethod('__getslice__', (2, 7)) # equiv to `l[2:7]`" @@ -155,28 +209,45 @@ library/multiprocessing,,`,# register the Foo class; make `f()` and `g()` accessible via proxy library/multiprocessing,,`,# register the Foo class; make `g()` and `_h()` accessible via proxy library/multiprocessing,,`,# register the generator function baz; use `GeneratorProxy` to make proxies +library/multiprocessing,,`,`slots` is used to specify the number of slots for processes on library/nntplib,,:bytes,:bytes +library/nntplib,,:bytes,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']" library/nntplib,,:lines,:lines +library/nntplib,,:lines,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']" library/optparse,,:len,"del parser.rargs[:len(value)]" library/os.path,,:foo,c:foo +library/parser,,`,"""Make a function that raises an argument to the exponent `exp`.""" library/pdb,,:lineno,filename:lineno +library/pdb,,:lineno,[filename:lineno | bpnumber [bpnumber ...]] library/pickle,,:memory,"conn = sqlite3.connect("":memory:"")" library/posix,,`,"CFLAGS=""`getconf LFS_CFLAGS`"" OPT=""-g -O2 $CFLAGS""" -library/pprint,,::,"'Programming Language :: Python :: 2 :: Only']," -library/pprint,,::,"'Programming Language :: Python :: 2.6'," -library/pprint,,::,"'Programming Language :: Python :: 2.7'," +library/pprint,209,::,"'classifiers': ['Development Status :: 4 - Beta'," +library/pprint,209,::,"'Intended Audience :: Developers'," +library/pprint,209,::,"'License :: OSI Approved :: MIT License'," +library/pprint,209,::,"'Natural Language :: English'," +library/pprint,209,::,"'Operating System :: OS Independent'," +library/pprint,209,::,"'Programming Language :: Python'," +library/pprint,209,::,"'Programming Language :: Python :: 2'," +library/pprint,209,::,"'Programming Language :: Python :: 2.6'," +library/pprint,209,::,"'Programming Language :: Python :: 2.7'," +library/pprint,209,::,"'Topic :: Software Development :: Libraries'," +library/pprint,209,::,"'Topic :: Software Development :: Libraries :: Python Modules']," library/profile,,:lineno,filename:lineno(function) +library/profile,,:lineno,ncalls tottime percall cumtime percall filename:lineno(function) +library/profile,,:lineno,"(sort by filename:lineno)," library/pyexpat,,:elem1, library/pyexpat,,:py,"xmlns:py = ""http://www.python.org/ns/"">" +library/repr,,`,"return `obj`" +library/smtplib,,:port,"as well as a regular host:port server." library/smtplib,,:port,method must support that as well as a regular host:port library/socket,,::,"(10, 1, 6, '', ('2001:888:2000:d::a2', 80, 0, 0))]" library/socket,,::,'5aef:2b::8' library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])" library/socket,,:len,fds.fromstring(cmsg_data[:len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) library/sqlite3,,:age,"cur.execute(""select * from people where name_last=:who and age=:age"", {""who"": who, ""age"": age})" +library/sqlite3,,:age,"select name_last, age from people where name_last=:who and age=:age" library/sqlite3,,:memory, library/sqlite3,,:who,"cur.execute(""select * from people where name_last=:who and age=:age"", {""who"": who, ""age"": age})" -library/sqlite3,,:path,"db = sqlite3.connect('file:path/to/database?mode=ro', uri=True)" library/ssl,,:My,"Organizational Unit Name (eg, section) []:My Group" library/ssl,,:My,"Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc." library/ssl,,:myserver,"Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com" @@ -191,6 +262,7 @@ library/stdtypes,,:len,s[len(s):len(s)] library/stdtypes,,::,>>> y = m[::2] library/stdtypes,,::,>>> z = y[::-2] +library/string,,:end,s[start:end] library/subprocess,,`,"output=`dmesg | grep hda`" library/subprocess,,`,"output=`mycmd myarg`" library/tarfile,,:bz2, @@ -202,14 +274,12 @@ library/time,,:mm, library/time,,:ss, library/turtle,,::,Example:: +library/urllib2,,:password,"""joe:password@python.org""" +library/urllib,,:port,:port library/urllib.request,,:close,Connection:close library/urllib.request,,:lang,"xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">\n\n\n" library/urllib.request,,:password,"""joe:password@python.org""" library/uuid,,:uuid,urn:uuid:12345678-1234-5678-1234-567812345678 -library/venv,,:param,":param nodist: If True, Distribute is not installed into the created" -library/venv,,:param,":param nopip: If True, pip is not installed into the created" -library/venv,,:param,":param progress: If Distribute or pip are installed, the progress of the" -library/venv,,:param,:param context: The information for the environment creation request library/xmlrpc.client,,:pass,http://user:pass@host:port/path library/xmlrpc.client,,:pass,user:pass library/xmlrpc.client,,:port,http://user:pass@host:port/path @@ -220,7 +290,16 @@ license,,`,* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY license,,`,THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND license,,:zooko,mailto:zooko@zooko.com +reference/datamodel,,:max, +reference/datamodel,,:step,a[i:j:step] +reference/expressions,,:datum,{key:datum...} +reference/expressions,,`,`expressions...` reference/expressions,,:index,x[index:index] +reference/grammar,,:output,#diagram:output +reference/grammar,,:rules,#diagram:rules +reference/grammar,,`,'`' testlist1 '`' +reference/grammar,,:token,#diagram:token +reference/lexical_analysis,,`,", : . ` = ;" reference/lexical_analysis,,`,$ ? ` reference/lexical_analysis,,:fileencoding,# vim:fileencoding= tutorial/datastructures,,:value,It is also possible to delete a key:value @@ -268,17 +347,25 @@ whatsnew/3.2,,:cafe,>>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/') whatsnew/3.2,,:deaf,"netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]'," whatsnew/3.2,,:deaf,>>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/') +whatsnew/3.2,,:directory,... ${buildout:directory}/downloads/dist whatsnew/3.2,,:directory,${buildout:directory}/downloads/dist whatsnew/3.2,,::,"$ export PYTHONWARNINGS='ignore::RuntimeWarning::,once::UnicodeWarning::'" whatsnew/3.2,,:feed,"netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]'," whatsnew/3.2,,:feed,>>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/') whatsnew/3.2,,:gz,">>> with tarfile.open(name='myarchive.tar.gz', mode='w:gz') as tf:" +whatsnew/3.2,,:location,... zope9-location = ${zope9:location} whatsnew/3.2,,:location,zope9-location = ${zope9:location} +whatsnew/3.2,,:prefix,... zope-conf = ${custom:prefix}/etc/zope.conf whatsnew/3.2,,:prefix,zope-conf = ${custom:prefix}/etc/zope.conf -whatsnew/changelog,,:platform,:platform: -whatsnew/changelog,,:password,: Unquote before b64encoding user:password during Basic -whatsnew/changelog,,:close,Connection:close header. -whatsnew/changelog,,:PythonCmd,"With Tk < 8.5 _tkinter.c:PythonCmd() raised UnicodeDecodeError, caused" -whatsnew/changelog,,:close,: Connection:close header is sent by requests using URLOpener -whatsnew/changelog,,::,": Fix FTP tests for IPv6, bind to ""::1"" instead of ""localhost""." -whatsnew/changelog,,:test,: test_subprocess:test_leaking_fds_on_error no longer gives a +whatsnew/news,,:platform,:platform: +whatsnew/news,,:password,: Unquote before b64encoding user:password during Basic +whatsnew/news,,:close,Connection:close header. +whatsnew/news,,:PythonCmd,"With Tk < 8.5 _tkinter.c:PythonCmd() raised UnicodeDecodeError, caused" +whatsnew/news,,:close,: Connection:close header is sent by requests using URLOpener +whatsnew/news,,::,": Fix FTP tests for IPv6, bind to ""::1"" instead of ""localhost""." +whatsnew/news,,:test,: test_subprocess:test_leaking_fds_on_error no longer gives a +whatsnew/news,,:test,: Fix test_posix:test_getgroups failure under Solaris. Patch +whatsnew/news,,:Olimit,Drop -OPT:Olimit compiler option. +whatsnew/news,,:MAXYEAR,timedelta from date or datetime falls outside of the MINYEAR:MAXYEAR range. +whatsnew/news,,:bz2,with mode 'r' or 'r:bz2' and a fileobj argument that contained no data or +whatsnew/news,,:db2,: Add configure option --with-dbmliborder=db1:db2:... to specify diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tools/sphinxext/suspicious.py --- a/Doc/tools/sphinxext/suspicious.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tools/sphinxext/suspicious.py Fri Feb 01 23:12:09 2013 +0100 @@ -68,10 +68,6 @@ # None -> don't care self.issue = issue # the markup fragment that triggered this rule self.line = line # text of the container element (single line only) - self.used = False - - def __repr__(self): - return '{0.docname},,{0.issue},{0.line}'.format(self) @@ -111,12 +107,6 @@ doctree.walk(visitor) def finish(self): - unused_rules = [rule for rule in self.rules if not rule.used] - if unused_rules: - self.warn('Found %s/%s unused rules:' % - (len(unused_rules), len(self.rules))) - for rule in unused_rules: - self.info(repr(rule)) return def check_issue(self, line, lineno, issue): @@ -141,7 +131,6 @@ if (rule.lineno is not None) and \ abs(rule.lineno - lineno) > 5: continue # if it came this far, the rule matched - rule.used = True return True return False diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tutorial/inputoutput.rst --- a/Doc/tutorial/inputoutput.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tutorial/inputoutput.rst Fri Feb 01 23:12:09 2013 +0100 @@ -213,6 +213,10 @@ >>> print('The value of PI is approximately %5.3f.' % math.pi) The value of PI is approximately 3.142. +Since :meth:`str.format` is quite new, a lot of Python code still uses the ``%`` +operator. However, because this old style of formatting will eventually be +removed from the language, :meth:`str.format` should generally be used. + More information can be found in the :ref:`old-string-formatting` section. @@ -230,12 +234,12 @@ :: - >>> f = open('workfile', 'w') + >>> f = open('/tmp/workfile', 'w') .. XXX str(f) is >>> print(f) - + The first argument is a string containing the filename. The second argument is another string containing a few characters describing the way in which the file @@ -296,8 +300,18 @@ >>> f.readline() '' -For reading lines from a file, you can loop over the file object. This is memory -efficient, fast, and leads to simple code:: +``f.readlines()`` returns a list containing all the lines of data in the file. +If given an optional parameter *sizehint*, it reads that many bytes from the +file and enough more to complete a line, and returns the lines from that. This +is often used to allow efficient reading of a large file by lines, but without +having to load the entire file in memory. Only complete lines will be returned. +:: + + >>> f.readlines() + ['This is the first line of the file.\n', 'Second line of the file\n'] + +An alternative approach to reading lines is to loop over the file object. This is +memory efficient, fast, and leads to simpler code:: >>> for line in f: ... print(line, end='') @@ -305,8 +319,9 @@ This is the first line of the file. Second line of the file -If you want to read all the lines of a file in a list you can also use -``list(f)`` or ``f.readlines()``. +The alternative approach is simpler but does not provide as fine-grained +control. Since the two approaches manage line buffering differently, they +should not be mixed. ``f.write(string)`` writes the contents of *string* to the file, returning the number of characters written. :: @@ -331,7 +346,7 @@ the reference point. *from_what* can be omitted and defaults to 0, using the beginning of the file as the reference point. :: - >>> f = open('workfile', 'rb+') + >>> f = open('/tmp/workfile', 'rb+') >>> f.write(b'0123456789abcdef') 16 >>> f.seek(5) # Go to the 6th byte in the file @@ -362,7 +377,7 @@ suite finishes, even if an exception is raised on the way. It is also much shorter than writing equivalent :keyword:`try`\ -\ :keyword:`finally` blocks:: - >>> with open('workfile', 'r') as f: + >>> with open('/tmp/workfile', 'r') as f: ... read_data = f.read() >>> f.closed True diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tutorial/interactive.rst --- a/Doc/tutorial/interactive.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tutorial/interactive.rst Fri Feb 01 23:12:09 2013 +0100 @@ -7,27 +7,140 @@ Some versions of the Python interpreter support editing of the current input line and history substitution, similar to facilities found in the Korn shell and the GNU Bash shell. This is implemented using the `GNU Readline`_ library, -which supports various styles of editing. This library has its own -documentation which we won't duplicate here. +which supports Emacs-style and vi-style editing. This library has its own +documentation which I won't duplicate here; however, the basics are easily +explained. The interactive editing and history described here are optionally +available in the Unix and Cygwin versions of the interpreter. + +This chapter does *not* document the editing facilities of Mark Hammond's +PythonWin package or the Tk-based environment, IDLE, distributed with Python. +The command line history recall which operates within DOS boxes on NT and some +other DOS and Windows flavors is yet another beast. + + +.. _tut-lineediting: + +Line Editing +============ + +If supported, input line editing is active whenever the interpreter prints a +primary or secondary prompt. The current line can be edited using the +conventional Emacs control characters. The most important of these are: +:kbd:`C-A` (Control-A) moves the cursor to the beginning of the line, :kbd:`C-E` +to the end, :kbd:`C-B` moves it one position to the left, :kbd:`C-F` to the +right. Backspace erases the character to the left of the cursor, :kbd:`C-D` the +character to its right. :kbd:`C-K` kills (erases) the rest of the line to the +right of the cursor, :kbd:`C-Y` yanks back the last killed string. +:kbd:`C-underscore` undoes the last change you made; it can be repeated for +cumulative effect. + + +.. _tut-history: + +History Substitution +==================== + +History substitution works as follows. All non-empty input lines issued are +saved in a history buffer, and when a new prompt is given you are positioned on +a new line at the bottom of this buffer. :kbd:`C-P` moves one line up (back) in +the history buffer, :kbd:`C-N` moves one down. Any line in the history buffer +can be edited; an asterisk appears in front of the prompt to mark a line as +modified. Pressing the :kbd:`Return` key passes the current line to the +interpreter. :kbd:`C-R` starts an incremental reverse search; :kbd:`C-S` starts +a forward search. .. _tut-keybindings: -Tab Completion and History Editing -================================== +Key Bindings +============ -Completion of variable and module names is -:ref:`automatically enabled ` at interpreter startup so -that the :kbd:`Tab` key invokes the completion function; it looks at -Python statement names, the current local variables, and the available -module names. For dotted expressions such as ``string.a``, it will evaluate -the expression up to the final ``'.'`` and then suggest completions from -the attributes of the resulting object. Note that this may execute -application-defined code if an object with a :meth:`__getattr__` method -is part of the expression. The default configuration also saves your -history into a file named :file:`.python_history` in your user directory. -The history will be available again during the next interactive interpreter -session. +The key bindings and some other parameters of the Readline library can be +customized by placing commands in an initialization file called +:file:`~/.inputrc`. Key bindings have the form :: + + key-name: function-name + +or :: + + "string": function-name + +and options can be set with :: + + set option-name value + +For example:: + + # I prefer vi-style editing: + set editing-mode vi + + # Edit using a single line: + set horizontal-scroll-mode On + + # Rebind some keys: + Meta-h: backward-kill-word + "\C-u": universal-argument + "\C-x\C-r": re-read-init-file + +Note that the default binding for :kbd:`Tab` in Python is to insert a :kbd:`Tab` +character instead of Readline's default filename completion function. If you +insist, you can override this by putting :: + + Tab: complete + +in your :file:`~/.inputrc`. (Of course, this makes it harder to type indented +continuation lines if you're accustomed to using :kbd:`Tab` for that purpose.) + +.. index:: + module: rlcompleter + module: readline + +Automatic completion of variable and module names is optionally available. To +enable it in the interpreter's interactive mode, add the following to your +startup file: [#]_ :: + + import rlcompleter, readline + readline.parse_and_bind('tab: complete') + +This binds the :kbd:`Tab` key to the completion function, so hitting the +:kbd:`Tab` key twice suggests completions; it looks at Python statement names, +the current local variables, and the available module names. For dotted +expressions such as ``string.a``, it will evaluate the expression up to the +final ``'.'`` and then suggest completions from the attributes of the resulting +object. Note that this may execute application-defined code if an object with a +:meth:`__getattr__` method is part of the expression. + +A more capable startup file might look like this example. Note that this +deletes the names it creates once they are no longer needed; this is done since +the startup file is executed in the same namespace as the interactive commands, +and removing the names avoids creating side effects in the interactive +environment. You may find it convenient to keep some of the imported modules, +such as :mod:`os`, which turn out to be needed in most sessions with the +interpreter. :: + + # Add auto-completion and a stored history file of commands to your Python + # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is + # bound to the Esc key by default (you can change it - see readline docs). + # + # Store the file in ~/.pystartup, and set an environment variable to point + # to it: "export PYTHONSTARTUP=~/.pystartup" in bash. + + import atexit + import os + import readline + import rlcompleter + + historyPath = os.path.expanduser("~/.pyhistory") + + def save_history(historyPath=historyPath): + import readline + readline.write_history_file(historyPath) + + if os.path.exists(historyPath): + readline.read_history_file(historyPath) + + atexit.register(save_history) + del os, atexit, readline, rlcompleter, save_history, historyPath .. _tut-commentary: @@ -49,6 +162,14 @@ bpython_. +.. rubric:: Footnotes + +.. [#] Python will execute the contents of a file identified by the + :envvar:`PYTHONSTARTUP` environment variable when you start an interactive + interpreter. To customize Python even for non-interactive mode, see + :ref:`tut-customize`. + + .. _GNU Readline: http://tiswww.case.edu/php/chet/readline/rltop.html .. _IPython: http://ipython.scipy.org/ .. _bpython: http://www.bpython-interpreter.org/ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tutorial/introduction.rst --- a/Doc/tutorial/introduction.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tutorial/introduction.rst Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,7 @@ ********************************** In the following examples, input and output are distinguished by the presence or -absence of prompts (:term:`>>>` and :term:`...`): to repeat the example, you must type +absence of prompts (``>>>`` and ``...``): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin with a prompt are output from the interpreter. Note that a secondary prompt on a line by itself in an example means you must type a blank line; this is used to @@ -22,9 +22,9 @@ Some examples:: # this is the first comment - spam = 1 # and this is the second comment - # ... and now a third! - text = "# This is not a comment because it's inside quotes." + SPAM = 1 # and this is the second comment + # ... and now a third! + STRING = "# This is not a comment." .. _tut-calculator: @@ -44,53 +44,55 @@ The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is straightforward: the operators ``+``, ``-``, ``*`` and ``/`` work just like in most other languages -(for example, Pascal or C); parentheses (``()``) can be used for grouping. -For example:: +(for example, Pascal or C); parentheses can be used for grouping. For example:: - >>> 2 + 2 + >>> 2+2 4 - >>> 50 - 5*6 - 20 - >>> (50 - 5*6) / 4 + >>> # This is a comment + ... 2+2 + 4 + >>> 2+2 # and a comment on the same line as code + 4 + >>> (50-5*6)/4 5.0 - >>> 8 / 5 # division always returns a floating point number + >>> 8/5 # Fractions aren't lost when dividing integers 1.6 -The integer numbers (e.g. ``2``, ``4``, ``20``) have type :class:`int`, -the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type -:class:`float`. We will see more about numberic types later in the tutorial. +Note: You might not see exactly the same result; floating point results can +differ from one machine to another. We will say more later about controlling +the appearance of floating point output. See also :ref:`tut-fp-issues` for a +full discussion of some of the subtleties of floating point numbers and their +representations. -Division (``/``) always returns a float. To do :term:`floor division` and -get an integer result (discarding any fractional result) you can use the ``//`` -operator; to calculate the remainder you can use ``%``:: +To do integer division and get an integer result, +discarding any fractional result, there is another operator, ``//``:: - >>> 17 / 3 # classic division returns a float - 5.666666666666667 - >>> - >>> 17 // 3 # floor division discards the fractional part - 5 - >>> 17 % 3 # the % operator returns the remainder of the division + >>> # Integer division returns the floor: + ... 7//3 2 - >>> 5 * 3 + 2 # result * divisor + remainder - 17 + >>> 7//-3 + -3 -With Python is possible to use the ``**`` operator to calculate powers [#]_:: - - >>> 5 ** 2 # 5 squared - 25 - >>> 2 ** 7 # 2 to the power of 7 - 128 - -The equal sign (``=``) is used to assign a value to a variable. Afterwards, no +The equal sign (``'='``) is used to assign a value to a variable. Afterwards, no result is displayed before the next interactive prompt:: >>> width = 20 - >>> height = 5 * 9 + >>> height = 5*9 >>> width * height 900 -If a variable is not "defined" (assigned a value), trying to use it will -give you an error:: +A value can be assigned to several variables simultaneously:: + + >>> x = y = z = 0 # Zero x, y and z + >>> x + 0 + >>> y + 0 + >>> z + 0 + +Variables must be "defined" (assigned a value) before they can be used, or an +error will occur:: >>> n # try to access an undefined variable Traceback (most recent call last): @@ -105,6 +107,49 @@ >>> 7.0 / 2 3.5 +Complex numbers are also supported; imaginary numbers are written with a suffix +of ``j`` or ``J``. Complex numbers with a nonzero real component are written as +``(real+imagj)``, or can be created with the ``complex(real, imag)`` function. +:: + + >>> 1j * 1J + (-1+0j) + >>> 1j * complex(0, 1) + (-1+0j) + >>> 3+1j*3 + (3+3j) + >>> (3+1j)*3 + (9+3j) + >>> (1+2j)/(1+1j) + (1.5+0.5j) + +Complex numbers are always represented as two floating point numbers, the real +and imaginary part. To extract these parts from a complex number *z*, use +``z.real`` and ``z.imag``. :: + + >>> a=1.5+0.5j + >>> a.real + 1.5 + >>> a.imag + 0.5 + +The conversion functions to floating point and integer (:func:`float`, +:func:`int`) don't work for complex numbers --- there is not one correct way to +convert a complex number to a real number. Use ``abs(z)`` to get its magnitude +(as a float) or ``z.real`` to get its real part:: + + >>> a=3.0+4.0j + >>> float(a) + Traceback (most recent call last): + File "", line 1, in ? + TypeError: can't convert complex to float; use abs(z) + >>> a.real + 3.0 + >>> a.imag + 4.0 + >>> abs(a) # sqrt(a.real**2 + a.imag**2) + 5.0 + In interactive mode, the last printed expression is assigned to the variable ``_``. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example:: @@ -122,28 +167,20 @@ assign a value to it --- you would create an independent local variable with the same name masking the built-in variable with its magic behavior. -In addition to :class:`int` and :class:`float`, Python supports other types of -numbers, such as :class:`~decimal.Decimal` and :class:`~fractions.Fraction`. -Python also has built-in support for :ref:`complex numbers `, -and uses the ``j`` or ``J`` suffix to indicate the imaginary part -(e.g. ``3+5j``). - .. _tut-strings: Strings ------- -Besides numbers, Python can also manipulate strings, which can be expressed -in several ways. They can be enclosed in single quotes (``'...'``) or -double quotes (``"..."``) with the same result [#]_. ``\`` can be used -to escape quotes:: +Besides numbers, Python can also manipulate strings, which can be expressed in +several ways. They can be enclosed in single quotes or double quotes:: - >>> 'spam eggs' # single quotes + >>> 'spam eggs' 'spam eggs' - >>> 'doesn\'t' # use \' to escape the single quote... + >>> 'doesn\'t' "doesn't" - >>> "doesn't" # ...or use double quotes instead + >>> "doesn't" "doesn't" >>> '"Yes," he said.' '"Yes," he said.' @@ -152,40 +189,38 @@ >>> '"Isn\'t," she said.' '"Isn\'t," she said.' -In the interactive interpreter, the output string is enclosed in quotes and -special characters are escaped with backslashes. While this might sometimes -look different from the input (the enclosing quotes could change), the two -strings are equivalent. The string is enclosed in double quotes if -the string contains a single quote and no double quotes, otherwise it is -enclosed in single quotes. The :func:`print` function produces a more -readable output, by omitting the enclosing quotes and by printing escaped -and special characters:: +The interpreter prints the result of string operations in the same way as they +are typed for input: inside quotes, and with quotes and other funny characters +escaped by backslashes, to show the precise value. The string is enclosed in +double quotes if the string contains a single quote and no double quotes, else +it's enclosed in single quotes. The :func:`print` function produces a more +readable output for such input strings. - >>> '"Isn\'t," she said.' - '"Isn\'t," she said.' - >>> print('"Isn\'t," she said.') - "Isn't," she said. - >>> s = 'First line.\nSecond line.' # \n means newline - >>> s # without print(), \n is included in the output - 'First line.\nSecond line.' - >>> print(s) # with print(), \n produces a new line - First line. - Second line. +String literals can span multiple lines in several ways. Continuation lines can +be used, with a backslash as the last character on the line indicating that the +next line is a logical continuation of the line:: -If you don't want characters prefaced by ``\`` to be interpreted as -special characters, you can use *raw strings* by adding an ``r`` before -the first quote:: + hello = "This is a rather long string containing\n\ + several lines of text just as you would do in C.\n\ + Note that whitespace at the beginning of the line is\ + significant." - >>> print('C:\some\name') # here \n means newline! - C:\some - ame - >>> print(r'C:\some\name') # note the r before the quote - C:\some\name + print(hello) -String literals can span multiple lines. One way is using triple-quotes: -``"""..."""`` or ``'''...'''``. End of lines are automatically -included in the string, but it's possible to prevent this by adding a ``\`` at -the end of the line. The following example:: +Note that newlines still need to be embedded in the string using ``\n`` -- the +newline following the trailing backslash is discarded. This example would print +the following: + +.. code-block:: text + + This is a rather long string containing + several lines of text just as you would do in C. + Note that whitespace at the beginning of the line is significant. + +Or, strings can be surrounded in a pair of matching triple-quotes: ``"""`` or +``'''``. End of lines do not need to be escaped when using triple-quotes, but +they will be included in the string. So the following uses one escape to +avoid an unwanted initial blank line. :: print("""\ Usage: thingy [OPTIONS] @@ -193,7 +228,7 @@ -H hostname Hostname to connect to """) -produces the following output (note that the initial newline is not included): +produces the following output: .. code-block:: text @@ -201,100 +236,143 @@ -h Display this usage message -H hostname Hostname to connect to +If we make the string literal a "raw" string, ``\n`` sequences are not converted +to newlines, but the backslash at the end of the line, and the newline character +in the source, are both included in the string as data. Thus, the example:: + + hello = r"This is a rather long string containing\n\ + several lines of text much as you would do in C." + + print(hello) + +would print: + +.. code-block:: text + + This is a rather long string containing\n\ + several lines of text much as you would do in C. + Strings can be concatenated (glued together) with the ``+`` operator, and repeated with ``*``:: - >>> # 3 times 'un', followed by 'ium' - >>> 3 * 'un' + 'ium' - 'unununium' + >>> word = 'Help' + 'A' + >>> word + 'HelpA' + >>> '<' + word*5 + '>' + '' -Two or more *string literals* (i.e. the ones enclosed between quotes) next -to each other are automatically concatenated. :: +Two string literals next to each other are automatically concatenated; the first +line above could also have been written ``word = 'Help' 'A'``; this only works +with two literals, not with arbitrary string expressions:: - >>> 'Py' 'thon' - 'Python' - -This only works with two literals though, not with variables or expressions:: - - >>> prefix = 'Py' - >>> prefix 'thon' # can't concatenate a variable and a string literal - ... - SyntaxError: invalid syntax - >>> ('un' * 3) 'ium' - ... + >>> 'str' 'ing' # <- This is ok + 'string' + >>> 'str'.strip() + 'ing' # <- This is ok + 'string' + >>> 'str'.strip() 'ing' # <- This is invalid + File "", line 1, in ? + 'str'.strip() 'ing' + ^ SyntaxError: invalid syntax -If you want to concatenate variables or a variable and a literal, use ``+``:: +Strings can be subscripted (indexed); like in C, the first character of a string +has subscript (index) 0. There is no separate character type; a character is +simply a string of size one. As in the Icon programming language, substrings +can be specified with the *slice notation*: two indices separated by a colon. +:: - >>> prefix + 'thon' - 'Python' - -This feature is particularly useful when you want to break long strings:: - - >>> text = ('Put several strings within parentheses ' - 'to have them joined together.') - >>> text - 'Put several strings within parentheses to have them joined together.' - -Strings can be *indexed* (subscripted), with the first character having index 0. -There is no separate character type; a character is simply a string of size -one:: - - >>> word = 'Python' - >>> word[0] # character in position 0 - 'P' - >>> word[5] # character in position 5 - 'n' - -Indices may also be negative numbers, to start counting from the right:: - - >>> word[-1] # last character - 'n' - >>> word[-2] # second-last character - 'o' - >>> word[-6] - 'P' - -Note that since -0 is the same as 0, negative indices start from -1. - -In addition to indexing, *slicing* is also supported. While indexing is used -to obtain individual characters, *slicing* allows you to obtain substring:: - - >>> word[0:2] # characters from position 0 (included) to 2 (excluded) - 'Py' - >>> word[2:5] # characters from position 2 (included) to 5 (excluded) - 'tho' - -Note how the start is always included, and the end always excluded. This -makes sure that ``s[:i] + s[i:]`` is always equal to ``s``:: - - >>> word[:2] + word[2:] - 'Python' - >>> word[:4] + word[4:] - 'Python' + >>> word[4] + 'A' + >>> word[0:2] + 'He' + >>> word[2:4] + 'lp' Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced. :: - >>> word[:2] # character from the beginning to position 2 (excluded) - 'Py' - >>> word[4:] # characters from position 4 (included) to the end - 'on' - >>> word[-2:] # characters from the second-last (included) to the end - 'on' + >>> word[:2] # The first two characters + 'He' + >>> word[2:] # Everything except the first two characters + 'lpA' + +Unlike a C string, Python strings cannot be changed. Assigning to an indexed +position in the string results in an error:: + + >>> word[0] = 'x' + Traceback (most recent call last): + File "", line 1, in ? + TypeError: 'str' object does not support item assignment + >>> word[:1] = 'Splat' + Traceback (most recent call last): + File "", line 1, in ? + TypeError: 'str' object does not support slice assignment + +However, creating a new string with the combined content is easy and efficient:: + + >>> 'x' + word[1:] + 'xelpA' + >>> 'Splat' + word[4] + 'SplatA' + +Here's a useful invariant of slice operations: ``s[:i] + s[i:]`` equals ``s``. +:: + + >>> word[:2] + word[2:] + 'HelpA' + >>> word[:3] + word[3:] + 'HelpA' + +Degenerate slice indices are handled gracefully: an index that is too large is +replaced by the string size, an upper bound smaller than the lower bound returns +an empty string. :: + + >>> word[1:100] + 'elpA' + >>> word[10:] + '' + >>> word[2:1] + '' + +Indices may be negative numbers, to start counting from the right. For example:: + + >>> word[-1] # The last character + 'A' + >>> word[-2] # The last-but-one character + 'p' + >>> word[-2:] # The last two characters + 'pA' + >>> word[:-2] # Everything except the last two characters + 'Hel' + +But note that -0 is really the same as 0, so it does not count from the right! +:: + + >>> word[-0] # (since -0 equals 0) + 'H' + +Out-of-range negative slice indices are truncated, but don't try this for +single-element (non-slice) indices:: + + >>> word[-100:] + 'HelpA' + >>> word[-10] # error + Traceback (most recent call last): + File "", line 1, in ? + IndexError: string index out of range One way to remember how slices work is to think of the indices as pointing *between* characters, with the left edge of the first character numbered 0. Then the right edge of the last character of a string of *n* characters has index *n*, for example:: - +---+---+---+---+---+---+ - | P | y | t | h | o | n | - +---+---+---+---+---+---+ - 0 1 2 3 4 5 6 - -6 -5 -4 -3 -2 -1 + +---+---+---+---+---+ + | H | e | l | p | A | + +---+---+---+---+---+ + 0 1 2 3 4 5 + -5 -4 -3 -2 -1 -The first row of numbers gives the position of the indices 0...6 in the string; +The first row of numbers gives the position of the indices 0...5 in the string; the second row gives the corresponding negative indices. The slice from *i* to *j* consists of all characters between the edges labeled *i* and *j*, respectively. @@ -303,38 +381,6 @@ indices, if both are within bounds. For example, the length of ``word[1:3]`` is 2. -Attempting to use a index that is too large will result in an error:: - - >>> word[42] # the word only has 7 characters - Traceback (most recent call last): - File "", line 1, in - IndexError: string index out of range - -However, out of range slice indexes are handled gracefully when used for -slicing:: - - >>> word[4:42] - 'on' - >>> word[42:] - '' - -Python strings cannot be changed --- they are :term:`immutable`. -Therefore, assigning to an indexed position in the string results in an error:: - - >>> word[0] = 'J' - ... - TypeError: 'str' object does not support item assignment - >>> word[2:] = 'py' - ... - TypeError: 'str' object does not support item assignment - -If you need a different string, you should create a new one:: - - >>> 'J' + word[1:] - 'Jython' - >>> word[:2] + 'py' - 'Pypy' - The built-in function :func:`len` returns the length of a string:: >>> s = 'supercalifragilisticexpialidocious' @@ -361,6 +407,51 @@ the left operand of the ``%`` operator are described in more detail here. +.. _tut-unicodestrings: + +About Unicode +------------- + +.. sectionauthor:: Marc-André Lemburg + + +Starting with Python 3.0 all strings support Unicode (see +http://www.unicode.org/). + +Unicode has the advantage of providing one ordinal for every character in every +script used in modern and ancient texts. Previously, there were only 256 +possible ordinals for script characters. Texts were typically bound to a code +page which mapped the ordinals to script characters. This lead to very much +confusion especially with respect to internationalization (usually written as +``i18n`` --- ``'i'`` + 18 characters + ``'n'``) of software. Unicode solves +these problems by defining one code page for all scripts. + +If you want to include special characters in a string, +you can do so by using the Python *Unicode-Escape* encoding. The following +example shows how:: + + >>> 'Hello\u0020World !' + 'Hello World !' + +The escape sequence ``\u0020`` indicates to insert the Unicode character with +the ordinal value 0x0020 (the space character) at the given position. + +Other characters are interpreted by using their respective ordinal values +directly as Unicode ordinals. If you have literal strings in the standard +Latin-1 encoding that is used in many Western countries, you will find it +convenient that the lower 256 characters of Unicode are the same as the 256 +characters of Latin-1. + +Apart from these standard encodings, Python provides a whole set of other ways +of creating Unicode strings on the basis of a known encoding. + +To convert a string into a sequence of bytes using a specific encoding, +string objects provide an :func:`encode` method that takes one argument, the +name of the encoding. Lowercase names for encodings are preferred. :: + + >>> "Äpfel".encode('utf-8') + b'\xc3\x84pfel' + .. _tut-lists: Lists @@ -368,89 +459,97 @@ Python knows a number of *compound* data types, used to group together other values. The most versatile is the *list*, which can be written as a list of -comma-separated values (items) between square brackets. Lists might contain -items of different types, but usually the items all have the same type. :: +comma-separated values (items) between square brackets. List items need not all +have the same type. :: - >>> squares = [1, 2, 4, 9, 16, 25] - >>> squares - [1, 2, 4, 9, 16, 25] + >>> a = ['spam', 'eggs', 100, 1234] + >>> a + ['spam', 'eggs', 100, 1234] -Like strings (and all other built-in :term:`sequence` type), lists can be -indexed and sliced:: +Like string indices, list indices start at 0, and lists can be sliced, +concatenated and so on:: - >>> squares[0] # indexing returns the item - 1 - >>> squares[-1] - 25 - >>> squares[-3:] # slicing returns a new list - [9, 16, 25] + >>> a[0] + 'spam' + >>> a[3] + 1234 + >>> a[-2] + 100 + >>> a[1:-1] + ['eggs', 100] + >>> a[:2] + ['bacon', 2*2] + ['spam', 'eggs', 'bacon', 4] + >>> 3*a[:3] + ['Boo!'] + ['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!'] All slice operations return a new list containing the requested elements. This -means that the following slice returns a new (shallow) copy of the list:: +means that the following slice returns a shallow copy of the list *a*:: - >>> squares[:] - [1, 2, 4, 9, 16, 25] + >>> a[:] + ['spam', 'eggs', 100, 1234] -Lists also supports operations like concatenation:: +Unlike strings, which are *immutable*, it is possible to change individual +elements of a list:: - >>> squares + [36, 49, 64, 81, 100] - [1, 2, 4, 9, 16, 25, 36, 49, 64, 81, 100] - -Unlike strings, which are :term:`immutable`, lists are a :term:`mutable` -type, i.e. it is possible to change their content:: - - >>> cubes = [1, 8, 27, 65, 125] # something's wrong here - >>> 4 ** 3 # the cube of 4 is 64, not 65! - 64 - >>> cubes[3] = 64 # replace the wrong value - >>> cubes - [1, 8, 27, 64, 125] - -You can also add new items at the end of the list, by using -the :meth:`~list.append` *method* (we will see more about methods later):: - - >>> cubes.append(216) # add the cube of 6 - >>> cubes.append(7 ** 3) # and the cube of 7 - >>> cubes - [1, 8, 27, 64, 125, 216, 343] + >>> a + ['spam', 'eggs', 100, 1234] + >>> a[2] = a[2] + 23 + >>> a + ['spam', 'eggs', 123, 1234] Assignment to slices is also possible, and this can even change the size of the list or clear it entirely:: - >>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - >>> letters - ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - >>> # replace some values - >>> letters[2:5] = ['C', 'D', 'E'] - >>> letters - ['a', 'b', 'C', 'D', 'E', 'f', 'g'] - >>> # now remove them - >>> letters[2:5] = [] - >>> letters - ['a', 'b', 'f', 'g'] - >>> # clear the list by replacing all the elements with an empty list - >>> letters[:] = [] - >>> letters + >>> # Replace some items: + ... a[0:2] = [1, 12] + >>> a + [1, 12, 123, 1234] + >>> # Remove some: + ... a[0:2] = [] + >>> a + [123, 1234] + >>> # Insert some: + ... a[1:1] = ['bletch', 'xyzzy'] + >>> a + [123, 'bletch', 'xyzzy', 1234] + >>> # Insert (a copy of) itself at the beginning + >>> a[:0] = a + >>> a + [123, 'bletch', 'xyzzy', 1234, 123, 'bletch', 'xyzzy', 1234] + >>> # Clear the list: replace all items with an empty list + >>> a[:] = [] + >>> a [] The built-in function :func:`len` also applies to lists:: - >>> letters = ['a', 'b', 'c', 'd'] - >>> len(letters) + >>> a = ['a', 'b', 'c', 'd'] + >>> len(a) 4 It is possible to nest lists (create lists containing other lists), for example:: - >>> a = ['a', 'b', 'c'] - >>> n = [1, 2, 3] - >>> x = [a, n] - >>> x - [['a', 'b', 'c'], [1, 2, 3]] - >>> x[0] - ['a', 'b', 'c'] - >>> x[0][1] - 'b' + >>> q = [2, 3] + >>> p = [1, q, 4] + >>> len(p) + 3 + >>> p[1] + [2, 3] + >>> p[1][0] + 2 + +You can add something to the end of the list:: + + >>> p[1].append('xtra') + >>> p + [1, [2, 3, 'xtra'], 4] + >>> q + [2, 3, 'xtra'] + +Note that in the last example, ``p[1]`` and ``q`` really refer to the same +object! We'll come back to *object semantics* later. + .. _tut-firststeps: @@ -501,19 +600,19 @@ guess when you have typed the last line). Note that each line within a basic block must be indented by the same amount. -* The :func:`print` function writes the value of the argument(s) it is given. - It differs from just writing the expression you want to write (as we did - earlier in the calculator examples) in the way it handles multiple arguments, - floating point quantities, and strings. Strings are printed without quotes, - and a space is inserted between items, so you can format things nicely, like - this:: +* The :func:`print` function writes the value of the expression(s) it is + given. It differs from just writing the expression you want to write (as we did + earlier in the calculator examples) in the way it handles multiple + expressions, floating point quantities, + and strings. Strings are printed without quotes, and a space is inserted + between items, so you can format things nicely, like this:: >>> i = 256*256 >>> print('The value of i is', i) The value of i is 65536 - The keyword argument *end* can be used to avoid the newline after the output, - or end the output with a different string:: + The keyword *end* can be used to avoid the newline after the output, or end + the output with a different string:: >>> a, b = 0, 1 >>> while b < 1000: @@ -521,15 +620,3 @@ ... a, b = b, a+b ... 1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987, - - -.. rubric:: Footnotes - -.. [#] Since ``**`` has higher precedence than ``-``, ``-3**2`` will be - interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this - and get ``9``, you can use ``(-3)**2``. - -.. [#] Unlike other languages, special characters such as ``\n`` have the - same meaning with both single (``'...'``) and double (``"..."``) quotes. - The only difference between the two is that within single quotes you don't - need to escape ``"`` (but you have to escape ``\'``) and vice versa. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tutorial/modules.rst --- a/Doc/tutorial/modules.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tutorial/modules.rst Fri Feb 01 23:12:09 2013 +0100 @@ -72,8 +72,7 @@ A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only -the *first* time the module name is encountered in an import statement. [#]_ -(They are also run if the file is executed as a script.) +the *first* time the module is imported somewhere. [#]_ Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can @@ -550,6 +549,6 @@ .. rubric:: Footnotes .. [#] In fact function definitions are also 'statements' that are 'executed'; the - execution of a module-level function definition enters the function name in - the module's global symbol table. + execution of a module-level function enters the function name in the module's + global symbol table. diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/tutorial/stdlib.rst --- a/Doc/tutorial/stdlib.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/tutorial/stdlib.rst Fri Feb 01 23:12:09 2013 +0100 @@ -281,10 +281,8 @@ def test_average(self): self.assertEqual(average([20, 30, 70]), 40.0) self.assertEqual(round(average([1, 5, 7]), 1), 4.3) - with self.assertRaises(ZeroDivisionError): - average([]) - with self.assertRaises(TypeError): - average(20, 30, 70) + self.assertRaises(ZeroDivisionError, average, []) + self.assertRaises(TypeError, average, 20, 30, 70) unittest.main() # Calling from the command line invokes all tests diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/using/cmdline.rst --- a/Doc/using/cmdline.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/using/cmdline.rst Fri Feb 01 23:12:09 2013 +0100 @@ -147,12 +147,7 @@ If no interface option is given, :option:`-i` is implied, ``sys.argv[0]`` is an empty string (``""``) and the current directory will be added to the -start of :data:`sys.path`. Also, tab-completion and history editing is -automatically enabled, if available on your platform (see -:ref:`rlcompleter-config`). - -.. versionchanged:: 3.4 - Automatic enabling of tab-completion and history editing. +start of :data:`sys.path`. .. seealso:: :ref:`tut-invoking` @@ -196,6 +191,14 @@ options). See also :envvar:`PYTHONDEBUG`. +.. cmdoption:: -e + + Set the default value of the *cloexec* parameter to ``True``: see the + :ref:`close-on-exec flag `. + + .. versionadded:: 3.4 + + .. cmdoption:: -E Ignore all :envvar:`PYTHON*` environment variables, e.g. @@ -274,8 +277,8 @@ .. cmdoption:: -u - Force the binary layer of the stdout and stderr streams (which is - available as their ``buffer`` attribute) to be unbuffered. The text I/O + Force the binary layer of the stdin, stdout and stderr streams (which is + available as their ``buffer`` attribute) to be unbuffered. The text I/O layer will still be line-buffered if writing to the console, or block-buffered if redirected to a non-interactive file. @@ -363,24 +366,13 @@ .. cmdoption:: -X Reserved for various implementation-specific options. CPython currently - defines two possible values: - - * ``-X faulthandler`` to enable :mod:`faulthandler`; - * ``-X showrefcount`` to enable the output of the total reference count - and memory blocks (only works on debug builds); - - It also allows to pass arbitrary values and retrieve them through the - :data:`sys._xoptions` dictionary. + defines just one, you can use ``-X faulthander`` to enable + :data:`faulthandler`. It also allows to pass arbitrary values and retrieve + them through the :data:`sys._xoptions` dictionary. .. versionchanged:: 3.2 It is now allowed to pass :option:`-X` with CPython. - .. versionadded:: 3.3 - The ``-X faulthandler`` option. - - .. versionadded:: 3.4 - The ``-X showrefcount`` option. - Options you shouldn't use ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -443,7 +435,7 @@ is executed in the same namespace where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session. You can also change the prompts :data:`sys.ps1` and - :data:`sys.ps2` and the hook :data:`sys.__interactivehook__` in this file. + :data:`sys.ps2` in this file. .. envvar:: PYTHONY2K @@ -575,6 +567,17 @@ Python traceback. This is equivalent to :option:`-X` ``faulthandler`` option. + .. versionadded:: 3.3 + +.. envvar:: PYTHONCLOEXEC + + If this is set, set the default value of the *cloexec* parameter to + ``True``: see the :ref:`close-on-exec flag `. This is equivalent to + :option:`-e` option. + + .. versionadded:: 3.4 + + Debug-mode variables ~~~~~~~~~~~~~~~~~~~~ diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/using/mac.rst --- a/Doc/using/mac.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/using/mac.rst Fri Feb 01 23:12:09 2013 +0100 @@ -17,15 +17,14 @@ Getting and Installing MacPython ================================ -Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple. If you wish, you -are invited to install the most recent version of Python 3 from the Python -website (http://www.python.org). A current "universal binary" build of Python, -which runs natively on the Mac's new Intel and legacy PPC CPU's, is available -there. +Mac OS X 10.5 comes with Python 2.5.1 pre-installed by Apple. If you wish, you +are invited to install the most recent version of Python from the Python website +(http://www.python.org). A current "universal binary" build of Python, which +runs natively on the Mac's new Intel and legacy PPC CPU's, is available there. What you get after installing is a number of things: -* A :file:`MacPython 3.4` folder in your :file:`Applications` folder. In here +* A :file:`MacPython 2.5` folder in your :file:`Applications` folder. In here you find IDLE, the development environment that is a standard part of official Python distributions; PythonLauncher, which handles double-clicking Python scripts from the Finder; and the "Build Applet" tool, which allows you to @@ -93,7 +92,7 @@ anything that has a GUI) need to be run in a special way. Use :program:`pythonw` instead of :program:`python` to start such scripts. -With Python 3.4, you can use either :program:`python` or :program:`pythonw`. +With Python 2.5, you can use either :program:`python` or :program:`pythonw`. Configuration @@ -126,11 +125,13 @@ There are several methods to install additional Python packages: +* http://pythonmac.org/packages/ contains selected compiled packages for Python + 2.5, 2.4, and 2.3. + * Packages can be installed via the standard Python distutils mode (``python setup.py install``). -* Many packages can also be installed via the :program:`setuptools` extension - or :program:`pip` wrapper, see http://www.pip-installer.org/. +* Many packages can also be installed via the :program:`setuptools` extension. GUI Programming on the Mac @@ -158,7 +159,7 @@ Distributing Python Applications on the Mac =========================================== -The "Build Applet" tool that is placed in the MacPython 3.4 folder is fine for +The "Build Applet" tool that is placed in the MacPython 2.5 folder is fine for packaging small Python scripts on your own machine to run as a standard Mac application. This tool, however, is not robust enough to distribute Python applications to other users. @@ -168,6 +169,20 @@ at http://undefined.org/python/#py2app. +Application Scripting +===================== + +Python can also be used to script other Mac applications via Apple's Open +Scripting Architecture (OSA); see http://appscript.sourceforge.net. Appscript is +a high-level, user-friendly Apple event bridge that allows you to control +scriptable Mac OS X applications using ordinary Python scripts. Appscript makes +Python a serious alternative to Apple's own *AppleScript* language for +automating your Mac. A related package, *PyOSA*, is an OSA language component +for the Python scripting language, allowing Python code to be executed by any +OSA-enabled application (Script Editor, Mail, iTunes, etc.). PyOSA makes Python +a full peer to AppleScript. + + Other Resources =============== diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/using/unix.rst --- a/Doc/using/unix.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/using/unix.rst Fri Feb 01 23:12:09 2013 +0100 @@ -28,7 +28,7 @@ http://www.debian.org/doc/manuals/maint-guide/first.en.html for Debian users - http://en.opensuse.org/Portal:Packaging + http://linuxmafia.com/pub/linux/suse-linux-internals/chapter35.html for OpenSuse users http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html for Fedora users diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/whatsnew/3.2.rst --- a/Doc/whatsnew/3.2.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/whatsnew/3.2.rst Fri Feb 01 23:12:09 2013 +0100 @@ -368,9 +368,9 @@ module:: >>> import sysconfig - >>> sysconfig.get_config_var('SOABI') # find the version tag + >>> sysconfig.get_config_var('SOABI') # find the version tag 'cpython-32mu' - >>> sysconfig.get_config_var('EXT_SUFFIX') # find the full filename extension + >>> sysconfig.get_config_var('SO') # find the full filename extension '.cpython-32mu.so' .. seealso:: diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/whatsnew/3.3.rst --- a/Doc/whatsnew/3.3.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/whatsnew/3.3.rst Fri Feb 01 23:12:09 2013 +0100 @@ -1208,8 +1208,6 @@ The minimum set of controls implemented by all ``policy`` objects are: - .. tabularcolumns:: |l|L| - =============== ======================================================= max_line_length The maximum length, excluding the linesep character(s), individual lines may have when a ``Message`` is @@ -1261,8 +1259,6 @@ The new policies are instances of :class:`~email.policy.EmailPolicy`, and add the following additional controls: - .. tabularcolumns:: |l|L| - =============== ======================================================= refold_source Controls whether or not headers parsed by a :mod:`~email.parser` are refolded by the @@ -2017,7 +2013,7 @@ -------- :class:`tempfile.SpooledTemporaryFile`\'s -:meth:`~tempfile.SpooledTemporaryFile.truncate` method now accepts +:meth:`~tempfile.SpooledTemporaryFile.trucate` method now accepts a ``size`` parameter. (Contributed by Ryan Kelly in :issue:`9957`.) diff -r 35c88c53cf64 -r ecc10f0afb76 Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst Fri Jul 26 23:14:22 2013 -0700 +++ b/Doc/whatsnew/3.4.rst Fri Feb 01 23:12:09 2013 +0100 @@ -81,7 +81,7 @@ Summary -- Release highlights ============================= -.. This section singles out the most important changes in Python 3.4. +.. This section singles out the most important changes in Python 3.3. Brevity is key. New syntax features: @@ -90,7 +90,7 @@ New library modules: -* :mod:`enum`: Implementation of the :pep:`435`. +* None yet. New built-in features: @@ -98,12 +98,11 @@ Implementation improvements: -* A more efficient :mod:`marshal` format . +* None yet. Significantly Improved Library Modules: * SHA-3 (Keccak) support for :mod:`hashlib`. -* TLSv1.1 and TLSv1.2 support for :mod:`ssl`. Security improvements: @@ -112,11 +111,21 @@ Please read on for a comprehensive list of user-facing changes. -PEP 445: Add new APIs to customize Python memory allocators -=========================================================== +.. PEP-sized items next. -The :pep:`445` adds new Application Programming Interfaces (API) to customize -Python memory allocators. +.. _pep-4XX: + +.. PEP 4XX: Example PEP +.. ==================== + + +.. (Implemented by Foo Bar.) + +.. .. seealso:: + + :pep:`4XX` - Example PEP + PEP written by Example Author + @@ -127,9 +136,6 @@ * Unicode database updated to UCD version 6.2. -* :func:`min` and :func:`max` now accept a *default* argument that can be used - to specify the value they return if the iterable they are evaluating has no - elements. Contributed by Julian Berman in :issue:`18111`. New Modules @@ -144,83 +150,12 @@ Improved Modules ================ - -dis ---- - -The :mod:`dis` module is now built around an :class:`Instruction` class that -provides details of individual bytecode operations and a -:func:`get_instructions` iterator that emits the Instruction stream for a -given piece of Python code. The various display tools in the :mod:`dis` -module have been updated to be based on these new components. - -The new :class:`dis.Bytecode` class provides an object-oriented API for -inspecting bytecode, both in human-readable form and for iterating over -instructions. - -(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in :issue:`11816`) - doctest ------- -Added :data:`~doctest.FAIL_FAST` flag to halt test running as soon as the first -failure is detected. (Contributed by R. David Murray and Daniel Urban in -:issue:`16522`.) +Added ``FAIL_FAST`` flag to halt test running as soon as the first failure is +detected. (Contributed by R. David Murray and Daniel Urban in :issue:`16522`.) -Updated the doctest command line interface to use :mod:`argparse`, and added -``-o`` and ``-f`` options to the interface. ``-o`` allows doctest options to -be specified on the command line, and ``-f`` is a shorthand for ``-o -FAIL_FAST`` (to parallel the similar option supported by the :mod:`unittest` -CLI). (Contributed by R. David Murray in :issue:`11390`.) - -aifc ----- - -The :meth:`~aifc.getparams` method now returns a namedtuple rather than a -plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.) - - -functools ---------- - -New :func:`functools.singledispatch` decorator: see the :pep:`443`. - -smtplib -------- - -:exc:`~smtplib.SMTPException` is now a subclass of :exc:`OSError`, which allows -both socket level errors and SMTP protocol level errors to be caught in one -try/except statement by code that only cares whether or not an error occurred. -(:issue:`2118`). - -ssl ---- - -TLSv1.1 and TLSv1.2 support (Contributed by Michele Orrù and Antoine Pitrou -in :issue:`16692`) - -New diagnostic functions :func:`~ssl.get_default_verify_paths`, -:meth:`~ssl.SSLContext.cert_store_stats` and -:meth:`~ssl.SSLContext.get_ca_certs` - -Add :func:`ssl.enum_cert_store` to retrieve certificates and CRL from Windows' -cert store. - -(Contributed by Christian Heimes in :issue:`18143`, :issue:`18147` and -:issue:`17134`) - -wave ----- - -The :meth:`~wave.getparams` method now returns a namedtuple rather than a -plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.) - -stat ---- - -The stat module is now backed by a C implementation in :mod:`_stat`. A C -implementation is required as most of the values aren't standardized and -platform-dependent. (Contributed by Christian Heimes in :issue:`11016`.) Optimizations ============= @@ -250,17 +185,7 @@ Deprecated Python modules, functions and methods ------------------------------------------------ -* :meth:`difflib.SequenceMatcher.isbjunk` and - :meth:`difflib.SequenceMatcher.isbpopular` were removed: use ``x in sm.bjunk`` and - ``x in sm.bpopular``, where *sm* is a :class:`~difflib.SequenceMatcher` object. - -* :func:`importlib.util.module_for_loader` is pending deprecation. Using - :func:`importlib.util.module_to_load` and - :meth:`importlib.abc.Loader.init_module_attrs` allows subclasses of a loader - to more easily customize module loading. - -* The :mod:`imp` module is pending deprecation. To keep compatibility with - Python 2/3 code bases, the module's removal is currently not scheduled. +* None yet. Deprecated functions and types of the C API @@ -281,52 +206,4 @@ This section lists previously described changes and other bugfixes that may require changes to your code. -* The ABCs defined in :mod:`importlib.abc` now either raise the appropriate - exception or return a default value instead of raising - :exc:`NotImplementedError` blindly. This will only affect code calling - :func:`super` and falling through all the way to the ABCs. For compatibility, - catch both :exc:`NotImplementedError` or the appropriate exception as needed. - -* The module type now initializes the :attr:`__package__` and :attr:`__loader__` - attributes to ``None`` by default. To determine if these attributes were set - in a backwards-compatible fashion, use e.g. - ``getattr(module, '__loader__', None) is not None``. - -* :meth:`importlib.util.module_for_loader` now sets ``__loader__`` and - ``__package__`` unconditionally to properly support reloading. If this is not - desired then you will need to set these attributes manually. You can use - :func:`importlib.util.module_to_load` for module management. - -* Import now resets relevant attributes (e.g. ``__name__``, ``__loader__``, - ``__package__``, ``__file__``, ``__cached__``) unconditionally when reloading. - -* Frozen packages no longer set ``__path__`` to a list containg the package name - but an empty list instead. Determing if a module is a package should be done - using ``hasattr(module, '__path__')``. - -* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg** - argument is not set. Previously only ``NULL`` was returned with no exception - set. - -* :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path - it would write to is a symlink or a non-regular file. This is to act as a - warning that import will overwrite those files with a regular file regardless - of what type of file path they were originally. - -* :meth:`importlib.abc.SourceLoader.get_source` no longer raises - :exc:`ImportError` when the source code being loaded triggers a - :exc:`SyntaxError` or :exc:`UnicodeDecodeError`. As :exc:`ImportError` is - meant to be raised only when source code cannot be found but it should, it was - felt to be over-reaching/overloading of that meaning when the source code is - found but improperly structured. If you were catching ImportError before and - wish to continue to ignore syntax or decoding issues, catch all three - exceptions now. - -* :func:`functools.update_wrapper` and :func:`functools.wraps` now correctly - set the ``__wrapped__`` attribute even if the wrapped function had a - wrapped attribute set. This means ``__wrapped__`` attributes now correctly - link a stack of decorated functions rather than every ``__wrapped__`` - attribute in the chain referring to the innermost function. Introspection - libraries that assumed the previous behaviour was intentional will need to - be updated to walk the chain of ``__wrapped__`` attributes to find the - innermost function. +* Nothing yet. diff -r 35c88c53cf64 -r ecc10f0afb76 Include/Python-ast.h --- a/Include/Python-ast.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/Python-ast.h Fri Feb 01 23:12:09 2013 +0100 @@ -42,25 +42,25 @@ enum _mod_kind {Module_kind=1, Interactive_kind=2, Expression_kind=3, Suite_kind=4}; struct _mod { - enum _mod_kind kind; - union { - struct { - asdl_seq *body; - } Module; - - struct { - asdl_seq *body; - } Interactive; - - struct { - expr_ty body; - } Expression; - - struct { - asdl_seq *body; - } Suite; - - } v; + enum _mod_kind kind; + union { + struct { + asdl_seq *body; + } Module; + + struct { + asdl_seq *body; + } Interactive; + + struct { + expr_ty body; + } Expression; + + struct { + asdl_seq *body; + } Suite; + + } v; }; enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3, @@ -70,111 +70,111 @@ ImportFrom_kind=15, Global_kind=16, Nonlocal_kind=17, Expr_kind=18, Pass_kind=19, Break_kind=20, Continue_kind=21}; struct _stmt { - enum _stmt_kind kind; - union { - struct { - identifier name; - arguments_ty args; - asdl_seq *body; - asdl_seq *decorator_list; - expr_ty returns; - } FunctionDef; - - struct { - identifier name; - asdl_seq *bases; - asdl_seq *keywords; - expr_ty starargs; - expr_ty kwargs; - asdl_seq *body; - asdl_seq *decorator_list; - } ClassDef; - - struct { - expr_ty value; - } Return; - - struct { - asdl_seq *targets; - } Delete; - - struct { - asdl_seq *targets; - expr_ty value; - } Assign; - - struct { - expr_ty target; - operator_ty op; - expr_ty value; - } AugAssign; - - struct { - expr_ty target; - expr_ty iter; - asdl_seq *body; - asdl_seq *orelse; - } For; - - struct { - expr_ty test; - asdl_seq *body; - asdl_seq *orelse; - } While; - - struct { - expr_ty test; - asdl_seq *body; - asdl_seq *orelse; - } If; - - struct { - asdl_seq *items; - asdl_seq *body; - } With; - - struct { - expr_ty exc; - expr_ty cause; - } Raise; - - struct { - asdl_seq *body; - asdl_seq *handlers; - asdl_seq *orelse; - asdl_seq *finalbody; - } Try; - - struct { - expr_ty test; - expr_ty msg; - } Assert; - - struct { - asdl_seq *names; - } Import; - - struct { - identifier module; - asdl_seq *names; - int level; - } ImportFrom; - - struct { - asdl_seq *names; - } Global; - - struct { - asdl_seq *names; - } Nonlocal; - - struct { - expr_ty value; - } Expr; - - } v; - int lineno; - int col_offset; + enum _stmt_kind kind; + union { + struct { + identifier name; + arguments_ty args; + asdl_seq *body; + asdl_seq *decorator_list; + expr_ty returns; + } FunctionDef; + + struct { + identifier name; + asdl_seq *bases; + asdl_seq *keywords; + expr_ty starargs; + expr_ty kwargs; + asdl_seq *body; + asdl_seq *decorator_list; + } ClassDef; + + struct { + expr_ty value; + } Return; + + struct { + asdl_seq *targets; + } Delete; + + struct { + asdl_seq *targets; + expr_ty value; + } Assign; + + struct { + expr_ty target; + operator_ty op; + expr_ty value; + } AugAssign; + + struct { + expr_ty target; + expr_ty iter; + asdl_seq *body; + asdl_seq *orelse; + } For; + + struct { + expr_ty test; + asdl_seq *body; + asdl_seq *orelse; + } While; + + struct { + expr_ty test; + asdl_seq *body; + asdl_seq *orelse; + } If; + + struct { + asdl_seq *items; + asdl_seq *body; + } With; + + struct { + expr_ty exc; + expr_ty cause; + } Raise; + + struct { + asdl_seq *body; + asdl_seq *handlers; + asdl_seq *orelse; + asdl_seq *finalbody; + } Try; + + struct { + expr_ty test; + expr_ty msg; + } Assert; + + struct { + asdl_seq *names; + } Import; + + struct { + identifier module; + asdl_seq *names; + int level; + } ImportFrom; + + struct { + asdl_seq *names; + } Global; + + struct { + asdl_seq *names; + } Nonlocal; + + struct { + expr_ty value; + } Expr; + + } v; + int lineno; + int col_offset; }; enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4, @@ -186,211 +186,211 @@ Subscript_kind=22, Starred_kind=23, Name_kind=24, List_kind=25, Tuple_kind=26}; struct _expr { - enum _expr_kind kind; - union { - struct { - boolop_ty op; - asdl_seq *values; - } BoolOp; - - struct { - expr_ty left; - operator_ty op; - expr_ty right; - } BinOp; - - struct { - unaryop_ty op; - expr_ty operand; - } UnaryOp; - - struct { - arguments_ty args; - expr_ty body; - } Lambda; - - struct { - expr_ty test; - expr_ty body; - expr_ty orelse; - } IfExp; - - struct { - asdl_seq *keys; - asdl_seq *values; - } Dict; - - struct { - asdl_seq *elts; - } Set; - - struct { - expr_ty elt; - asdl_seq *generators; - } ListComp; - - struct { - expr_ty elt; - asdl_seq *generators; - } SetComp; - - struct { - expr_ty key; - expr_ty value; - asdl_seq *generators; - } DictComp; - - struct { - expr_ty elt; - asdl_seq *generators; - } GeneratorExp; - - struct { - expr_ty value; - } Yield; - - struct { - expr_ty value; - } YieldFrom; - - struct { - expr_ty left; - asdl_int_seq *ops; - asdl_seq *comparators; - } Compare; - - struct { - expr_ty func; - asdl_seq *args; - asdl_seq *keywords; - expr_ty starargs; - expr_ty kwargs; - } Call; - - struct { - object n; - } Num; - - struct { - string s; - } Str; - - struct { - bytes s; - } Bytes; - - struct { - singleton value; - } NameConstant; - - struct { - expr_ty value; - identifier attr; - expr_context_ty ctx; - } Attribute; - - struct { - expr_ty value; - slice_ty slice; - expr_context_ty ctx; - } Subscript; - - struct { - expr_ty value; - expr_context_ty ctx; - } Starred; - - struct { - identifier id; - expr_context_ty ctx; - } Name; - - struct { - asdl_seq *elts; - expr_context_ty ctx; - } List; - - struct { - asdl_seq *elts; - expr_context_ty ctx; - } Tuple; - - } v; - int lineno; - int col_offset; + enum _expr_kind kind; + union { + struct { + boolop_ty op; + asdl_seq *values; + } BoolOp; + + struct { + expr_ty left; + operator_ty op; + expr_ty right; + } BinOp; + + struct { + unaryop_ty op; + expr_ty operand; + } UnaryOp; + + struct { + arguments_ty args; + expr_ty body; + } Lambda; + + struct { + expr_ty test; + expr_ty body; + expr_ty orelse; + } IfExp; + + struct { + asdl_seq *keys; + asdl_seq *values; + } Dict; + + struct { + asdl_seq *elts; + } Set; + + struct { + expr_ty elt; + asdl_seq *generators; + } ListComp; + + struct { + expr_ty elt; + asdl_seq *generators; + } SetComp; + + struct { + expr_ty key; + expr_ty value; + asdl_seq *generators; + } DictComp; + + struct { + expr_ty elt; + asdl_seq *generators; + } GeneratorExp; + + struct { + expr_ty value; + } Yield; + + struct { + expr_ty value; + } YieldFrom; + + struct { + expr_ty left; + asdl_int_seq *ops; + asdl_seq *comparators; + } Compare; + + struct { + expr_ty func; + asdl_seq *args; + asdl_seq *keywords; + expr_ty starargs; + expr_ty kwargs; + } Call; + + struct { + object n; + } Num; + + struct { + string s; + } Str; + + struct { + bytes s; + } Bytes; + + struct { + singleton value; + } NameConstant; + + struct { + expr_ty value; + identifier attr; + expr_context_ty ctx; + } Attribute; + + struct { + expr_ty value; + slice_ty slice; + expr_context_ty ctx; + } Subscript; + + struct { + expr_ty value; + expr_context_ty ctx; + } Starred; + + struct { + identifier id; + expr_context_ty ctx; + } Name; + + struct { + asdl_seq *elts; + expr_context_ty ctx; + } List; + + struct { + asdl_seq *elts; + expr_context_ty ctx; + } Tuple; + + } v; + int lineno; + int col_offset; }; enum _slice_kind {Slice_kind=1, ExtSlice_kind=2, Index_kind=3}; struct _slice { - enum _slice_kind kind; - union { - struct { - expr_ty lower; - expr_ty upper; - expr_ty step; - } Slice; - - struct { - asdl_seq *dims; - } ExtSlice; - - struct { - expr_ty value; - } Index; - - } v; + enum _slice_kind kind; + union { + struct { + expr_ty lower; + expr_ty upper; + expr_ty step; + } Slice; + + struct { + asdl_seq *dims; + } ExtSlice; + + struct { + expr_ty value; + } Index; + + } v; }; struct _comprehension { - expr_ty target; - expr_ty iter; - asdl_seq *ifs; + expr_ty target; + expr_ty iter; + asdl_seq *ifs; }; enum _excepthandler_kind {ExceptHandler_kind=1}; struct _excepthandler { - enum _excepthandler_kind kind; - union { - struct { - expr_ty type; - identifier name; - asdl_seq *body; - } ExceptHandler; - - } v; - int lineno; - int col_offset; + enum _excepthandler_kind kind; + union { + struct { + expr_ty type; + identifier name; + asdl_seq *body; + } ExceptHandler; + + } v; + int lineno; + int col_offset; }; struct _arguments { - asdl_seq *args; - arg_ty vararg; - asdl_seq *kwonlyargs; - asdl_seq *kw_defaults; - arg_ty kwarg; - asdl_seq *defaults; + asdl_seq *args; + identifier vararg; + expr_ty varargannotation; + asdl_seq *kwonlyargs; + identifier kwarg; + expr_ty kwargannotation; + asdl_seq *defaults; + asdl_seq *kw_defaults; }; struct _arg { - identifier arg; - expr_ty annotation; - int lineno; - int col_offset; + identifier arg; + expr_ty annotation; }; struct _keyword { - identifier arg; - expr_ty value; + identifier arg; + expr_ty value; }; struct _alias { - identifier name; - identifier asname; + identifier name; + identifier asname; }; struct _withitem { - expr_ty context_expr; - expr_ty optional_vars; + expr_ty context_expr; + expr_ty optional_vars; }; @@ -550,10 +550,11 @@ excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int col_offset, PyArena *arena); -#define arguments(a0, a1, a2, a3, a4, a5, a6) _Py_arguments(a0, a1, a2, a3, a4, a5, a6) -arguments_ty _Py_arguments(asdl_seq * args, arg_ty vararg, asdl_seq * - kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, - asdl_seq * defaults, PyArena *arena); +#define arguments(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_arguments(a0, a1, a2, a3, a4, a5, a6, a7, a8) +arguments_ty _Py_arguments(asdl_seq * args, identifier vararg, expr_ty + varargannotation, asdl_seq * kwonlyargs, identifier + kwarg, expr_ty kwargannotation, asdl_seq * defaults, + asdl_seq * kw_defaults, PyArena *arena); #define arg(a0, a1, a2) _Py_arg(a0, a1, a2) arg_ty _Py_arg(identifier arg, expr_ty annotation, PyArena *arena); #define keyword(a0, a1, a2) _Py_keyword(a0, a1, a2) diff -r 35c88c53cf64 -r ecc10f0afb76 Include/abstract.h --- a/Include/abstract.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/abstract.h Fri Feb 01 23:12:09 2013 +0100 @@ -284,7 +284,7 @@ */ PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object, - const char *format, ...); + char *format, ...); /* Call a callable Python object, callable_object, with a @@ -296,9 +296,8 @@ */ - PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, - const char *method, - const char *format, ...); + PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *method, + char *format, ...); /* Call the method named m of object o with a variable number of @@ -309,9 +308,8 @@ Python expression: o.method(args). */ - PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *o, - _Py_Identifier *method, - const char *format, ...); + PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *o, _Py_Identifier *method, + char *format, ...); /* Like PyObject_CallMethod, but expect a _Py_Identifier* as the @@ -319,16 +317,13 @@ */ PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, - const char *format, - ...); + char *format, ...); PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o, - const char *name, - const char *format, - ...); + char *name, + char *format, ...); PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, - const char *format, - ...); + char *format, ...); PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, ...); @@ -344,10 +339,11 @@ PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o, PyObject *method, ...); - PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(PyObject *o, + PyAPI_FUNC(PyObject *) _PyObject_CallMethodObjIdArgs(PyObject *o, struct _Py_Identifier *method, ...); + /* Call the method named m of object o with a variable number of C arguments. The C arguments are provided as PyObject * diff -r 35c88c53cf64 -r ecc10f0afb76 Include/dictobject.h --- a/Include/dictobject.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/dictobject.h Fri Feb 01 23:12:09 2013 +0100 @@ -53,8 +53,6 @@ PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key); -PyAPI_FUNC(PyObject *) PyDict_SetDefault( - PyObject *mp, PyObject *key, PyObject *defaultobj); PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); diff -r 35c88c53cf64 -r ecc10f0afb76 Include/fileutils.h --- a/Include/fileutils.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/fileutils.h Fri Feb 01 23:12:09 2013 +0100 @@ -1,10 +1,14 @@ #ifndef Py_FILEUTILS_H #define Py_FILEUTILS_H +#include "Python.h" + #ifdef __cplusplus extern "C" { #endif +PyAPI_DATA(int) Py_DefaultCloexec; + PyAPI_FUNC(PyObject *) _Py_device_encoding(int); PyAPI_FUNC(wchar_t *) _Py_char2wchar( @@ -27,6 +31,14 @@ struct stat *statbuf); #endif +PyAPI_FUNC(int) _Py_open( + const char *pathname, + int flags); + +PyAPI_FUNC(int) _Py_open_cloexec( + const char *pathname, + int flags); + PyAPI_FUNC(FILE *) _Py_wfopen( const wchar_t *path, const wchar_t *mode); @@ -53,6 +65,37 @@ wchar_t *buf, size_t size); +#ifdef MS_WINDOWS +PyAPI_FUNC(Py_intptr_t) _Py_get_osfhandle( + int fd, + int raise); + +PyAPI_FUNC(int) _Py_open_osfhandle( + Py_intptr_t handle, + int flags, + int raise); + +PyAPI_FUNC(int) _Py_get_cloexec_handle(Py_intptr_t handle); + +PyAPI_FUNC(int) _Py_set_cloexec_handle( + Py_intptr_t handle, + int cloexec, + int *atomic_flag_works); +#endif + +PyAPI_FUNC(int) _Py_get_cloexec(int fd); + +PyAPI_FUNC(int) _Py_set_cloexec( + int fd, + int cloexec, + int *atomic_flag_works); + +PyAPI_FUNC(void) _Py_try_set_cloexec(int fd, int cloexec); + +PyAPI_FUNC(void) _Py_try_set_default_cloexec(int fd); + +PyAPI_FUNC(int) _Py_cloexec_converter(PyObject* arg, void* addr); + #ifdef __cplusplus } #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Include/import.h --- a/Include/import.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/import.h Fri Feb 01 23:12:09 2013 +0100 @@ -113,15 +113,15 @@ #ifndef Py_LIMITED_API struct _frozen { - const char *name; /* ASCII encoded string */ - const unsigned char *code; + char *name; /* ASCII encoded string */ + unsigned char *code; int size; }; /* Embedding apps may change this pointer to point to their favorite collection of frozen modules: */ -PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules; +PyAPI_DATA(struct _frozen *) PyImport_FrozenModules; #endif #ifdef __cplusplus diff -r 35c88c53cf64 -r ecc10f0afb76 Include/longobject.h --- a/Include/longobject.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/longobject.h Fri Feb 01 23:12:09 2013 +0100 @@ -52,19 +52,6 @@ #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)" #endif /* SIZEOF_PID_T */ -#if SIZEOF_VOID_P == SIZEOF_INT -# define _Py_PARSE_INTPTR "i" -# define _Py_PARSE_UINTPTR "I" -#elif SIZEOF_VOID_P == SIZEOF_LONG -# define _Py_PARSE_INTPTR "l" -# define _Py_PARSE_UINTPTR "k" -#elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG -# define _Py_PARSE_INTPTR "L" -# define _Py_PARSE_UINTPTR "K" -#else -# error "void* different in size from int, long and long long" -#endif /* SIZEOF_VOID_P */ - /* Used by Python/mystrtoul.c. */ #ifndef Py_LIMITED_API PyAPI_DATA(unsigned char) _PyLong_DigitValue[256]; diff -r 35c88c53cf64 -r ecc10f0afb76 Include/marshal.h --- a/Include/marshal.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/marshal.h Fri Feb 01 23:12:09 2013 +0100 @@ -7,7 +7,7 @@ extern "C" { #endif -#define Py_MARSHAL_VERSION 3 +#define Py_MARSHAL_VERSION 2 PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int); PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int); diff -r 35c88c53cf64 -r ecc10f0afb76 Include/modsupport.h --- a/Include/modsupport.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/modsupport.h Fri Feb 01 23:12:09 2013 +0100 @@ -26,7 +26,7 @@ /* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */ #if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...); -PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...); +PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3); PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, const char *, char **, ...); PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *); diff -r 35c88c53cf64 -r ecc10f0afb76 Include/object.h --- a/Include/object.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/object.h Fri Feb 01 23:12:09 2013 +0100 @@ -680,6 +680,12 @@ complications in the deallocation function. (This is actually a decision that's up to the implementer of each new type so if you want, you can count such references to the type object.) + +*** WARNING*** The Py_DECREF macro must have a side-effect-free argument +since it may evaluate its argument multiple times. (The alternative +would be to mace it a proper function or assign it to a global temporary +variable first, both of which are slower; and in a multi-threaded +environment the global variable trick is not safe.) */ /* First define a pile of simple helper macros, one set per special @@ -758,16 +764,15 @@ #define Py_INCREF(op) ( \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ - ((PyObject *)(op))->ob_refcnt++) + ((PyObject*)(op))->ob_refcnt++) #define Py_DECREF(op) \ do { \ - PyObject *_py_decref_tmp = (PyObject *)(op); \ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ - --(_py_decref_tmp)->ob_refcnt != 0) \ - _Py_CHECK_REFCNT(_py_decref_tmp) \ + --((PyObject*)(op))->ob_refcnt != 0) \ + _Py_CHECK_REFCNT(op) \ else \ - _Py_Dealloc(_py_decref_tmp); \ + _Py_Dealloc((PyObject *)(op)); \ } while (0) /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear @@ -806,27 +811,16 @@ */ #define Py_CLEAR(op) \ do { \ - PyObject *_py_tmp = (PyObject *)(op); \ - if (_py_tmp != NULL) { \ + if (op) { \ + PyObject *_py_tmp = (PyObject *)(op); \ (op) = NULL; \ Py_DECREF(_py_tmp); \ } \ } while (0) /* Macros to use in case the object pointer may be NULL: */ -#define Py_XINCREF(op) \ - do { \ - PyObject *_py_xincref_tmp = (PyObject *)(op); \ - if (_py_xincref_tmp != NULL) \ - Py_INCREF(_py_xincref_tmp); \ - } while (0) - -#define Py_XDECREF(op) \ - do { \ - PyObject *_py_xdecref_tmp = (PyObject *)(op); \ - if (_py_xdecref_tmp != NULL) \ - Py_DECREF(_py_xdecref_tmp); \ - } while (0) +#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0) +#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0) /* These are provided as conveniences to Python runtime embedders, so that diff -r 35c88c53cf64 -r ecc10f0afb76 Include/objimpl.h --- a/Include/objimpl.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/objimpl.h Fri Feb 01 23:12:09 2013 +0100 @@ -94,9 +94,9 @@ the object gets initialized via PyObject_{Init, InitVar} after obtaining the raw memory. */ -PyAPI_FUNC(void *) PyObject_Malloc(size_t size); -PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size); -PyAPI_FUNC(void) PyObject_Free(void *ptr); +PyAPI_FUNC(void *) PyObject_Malloc(size_t); +PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t); +PyAPI_FUNC(void) PyObject_Free(void *); /* This function returns the number of allocated memory blocks, regardless of size */ PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void); @@ -106,15 +106,41 @@ #ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyObject_DebugMallocStats(FILE *out); #endif /* #ifndef Py_LIMITED_API */ -#endif +#ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */ +PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes); +PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes); +PyAPI_FUNC(void) _PyObject_DebugFree(void *p); +PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p); +PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p); +PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes); +PyAPI_FUNC(void *) _PyObject_DebugReallocApi(char api, void *p, size_t nbytes); +PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p); +PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p); +PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes); +PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes); +PyAPI_FUNC(void) _PyMem_DebugFree(void *p); +#define PyObject_MALLOC _PyObject_DebugMalloc +#define PyObject_Malloc _PyObject_DebugMalloc +#define PyObject_REALLOC _PyObject_DebugRealloc +#define PyObject_Realloc _PyObject_DebugRealloc +#define PyObject_FREE _PyObject_DebugFree +#define PyObject_Free _PyObject_DebugFree -/* Macros */ +#else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */ #define PyObject_MALLOC PyObject_Malloc #define PyObject_REALLOC PyObject_Realloc #define PyObject_FREE PyObject_Free +#endif + +#else /* ! WITH_PYMALLOC */ +#define PyObject_MALLOC PyMem_MALLOC +#define PyObject_REALLOC PyMem_REALLOC +#define PyObject_FREE PyMem_FREE + +#endif /* WITH_PYMALLOC */ + #define PyObject_Del PyObject_Free -#define PyObject_DEL PyObject_Free - +#define PyObject_DEL PyObject_FREE /* * Generic object allocator interface @@ -198,26 +224,6 @@ constructor you would start directly with PyObject_Init/InitVar */ -#ifndef Py_LIMITED_API -typedef struct { - /* user context passed as the first argument to the 2 functions */ - void *ctx; - - /* allocate an arena of size bytes */ - void* (*alloc) (void *ctx, size_t size); - - /* free an arena */ - void (*free) (void *ctx, void *ptr, size_t size); -} PyObjectArenaAllocator; - -/* Get the arena allocator. */ -PyAPI_FUNC(void) PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator); - -/* Set the arena allocator. */ -PyAPI_FUNC(void) PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator); -#endif - - /* * Garbage Collection Support * ========================== @@ -226,10 +232,6 @@ /* C equivalent of gc.collect(). */ PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void); -#ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void); -#endif - /* Test if a type has a GC head */ #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC) diff -r 35c88c53cf64 -r ecc10f0afb76 Include/opcode.h --- a/Include/opcode.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/opcode.h Fri Feb 01 23:12:09 2013 +0100 @@ -49,6 +49,7 @@ #define BINARY_OR 66 #define INPLACE_POWER 67 #define GET_ITER 68 +#define STORE_LOCALS 69 #define PRINT_EXPR 70 #define LOAD_BUILD_CLASS 71 #define YIELD_FROM 72 @@ -139,7 +140,6 @@ #define SET_ADD 146 #define MAP_ADD 147 -#define LOAD_CLASSDEREF 148 /* EXCEPT_HANDLER is a special, implicit block type which is created when entering an except handler. It is not an opcode but we define it here diff -r 35c88c53cf64 -r ecc10f0afb76 Include/pyexpat.h --- a/Include/pyexpat.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/pyexpat.h Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,7 @@ #define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.0" #define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI" -struct PyExpat_CAPI +struct PyExpat_CAPI { char* magic; /* set to PyExpat_CAPI_MAGIC */ int size; /* set to sizeof(struct PyExpat_CAPI) */ @@ -45,9 +45,6 @@ void (*SetUserData)(XML_Parser parser, void *userData); void (*SetStartDoctypeDeclHandler)(XML_Parser parser, XML_StartDoctypeDeclHandler start); - enum XML_Status (*SetEncoding)(XML_Parser parser, const XML_Char *encoding); - int (*DefaultUnknownEncodingHandler)( - void *encodingHandlerData, const XML_Char *name, XML_Encoding *info); /* always add new stuff to the end! */ }; diff -r 35c88c53cf64 -r ecc10f0afb76 Include/pymacro.h --- a/Include/pymacro.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/pymacro.h Fri Feb 01 23:12:09 2013 +0100 @@ -33,7 +33,7 @@ Requires at GCC 3.1+ */ #if (defined(__GNUC__) && !defined(__STRICT_ANSI__) && \ - (((__GNUC__ == 3) && (__GNU_MINOR__ >= 1)) || (__GNUC__ >= 4))) + ((__GNUC__ == 3) && (__GNU_MINOR__ >= 1)) || (__GNUC__ >= 4)) /* Two gcc extensions. &a[0] degrades to a pointer: a different type from an array */ #define Py_ARRAY_LENGTH(array) \ diff -r 35c88c53cf64 -r ecc10f0afb76 Include/pymem.h --- a/Include/pymem.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/pymem.h Fri Feb 01 23:12:09 2013 +0100 @@ -11,11 +11,6 @@ extern "C" { #endif -PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size); -PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size); -PyAPI_FUNC(void) PyMem_RawFree(void *ptr); - - /* BEWARE: Each interface exports both functions and macros. Extension modules should @@ -54,14 +49,21 @@ performed on failure (no exception is set, no warning is printed, etc). */ -PyAPI_FUNC(void *) PyMem_Malloc(size_t size); -PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size); -PyAPI_FUNC(void) PyMem_Free(void *ptr); +PyAPI_FUNC(void *) PyMem_Malloc(size_t); +PyAPI_FUNC(void *) PyMem_Realloc(void *, size_t); +PyAPI_FUNC(void) PyMem_Free(void *); -PyAPI_FUNC(char *) _PyMem_RawStrdup(const char *str); -PyAPI_FUNC(char *) _PyMem_Strdup(const char *str); +/* Starting from Python 1.6, the wrappers Py_{Malloc,Realloc,Free} are + no longer supported. They used to call PyErr_NoMemory() on failure. */ /* Macros. */ +#ifdef PYMALLOC_DEBUG +/* Redirect all memory operations to Python's debugging allocator. */ +#define PyMem_MALLOC _PyMem_DebugMalloc +#define PyMem_REALLOC _PyMem_DebugRealloc +#define PyMem_FREE _PyMem_DebugFree + +#else /* ! PYMALLOC_DEBUG */ /* PyMem_MALLOC(0) means malloc(1). Some systems would return NULL for malloc(0), which would be treated as an error. Some platforms @@ -69,9 +71,13 @@ pymalloc. To solve these problems, allocate an extra byte. */ /* Returns NULL to indicate error if a negative size or size larger than Py_ssize_t can represent is supplied. Helps prevents security holes. */ -#define PyMem_MALLOC(n) PyMem_Malloc(n) -#define PyMem_REALLOC(p, n) PyMem_Realloc(p, n) -#define PyMem_FREE(p) PyMem_Free(p) +#define PyMem_MALLOC(n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \ + : malloc((n) ? (n) : 1)) +#define PyMem_REALLOC(p, n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \ + : realloc((p), (n) ? (n) : 1)) +#define PyMem_FREE free + +#endif /* PYMALLOC_DEBUG */ /* * Type-oriented memory interface @@ -109,69 +115,6 @@ #define PyMem_Del PyMem_Free #define PyMem_DEL PyMem_FREE -#ifndef Py_LIMITED_API -typedef enum { - /* PyMem_RawMalloc(), PyMem_RawRealloc() and PyMem_RawFree() */ - PYMEM_DOMAIN_RAW, - - /* PyMem_Malloc(), PyMem_Realloc() and PyMem_Free() */ - PYMEM_DOMAIN_MEM, - - /* PyObject_Malloc(), PyObject_Realloc() and PyObject_Free() */ - PYMEM_DOMAIN_OBJ -} PyMemAllocatorDomain; - -typedef struct { - /* user context passed as the first argument to the 3 functions */ - void *ctx; - - /* allocate a memory block */ - void* (*malloc) (void *ctx, size_t size); - - /* allocate or resize a memory block */ - void* (*realloc) (void *ctx, void *ptr, size_t new_size); - - /* release a memory block */ - void (*free) (void *ctx, void *ptr); -} PyMemAllocator; - -/* Get the memory block allocator of the specified domain. */ -PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain, - PyMemAllocator *allocator); - -/* Set the memory block allocator of the specified domain. - - The new allocator must return a distinct non-NULL pointer when requesting - zero bytes. - - For the PYMEM_DOMAIN_RAW domain, the allocator must be thread-safe: the GIL - is not held when the allocator is called. - - If the new allocator is not a hook (don't call the previous allocator), the - PyMem_SetupDebugHooks() function must be called to reinstall the debug hooks - on top on the new allocator. */ -PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain, - PyMemAllocator *allocator); - -/* Setup hooks to detect bugs in the following Python memory allocator - functions: - - - PyMem_RawMalloc(), PyMem_RawRealloc(), PyMem_RawFree() - - PyMem_Malloc(), PyMem_Realloc(), PyMem_Free() - - PyObject_Malloc(), PyObject_Realloc() and PyObject_Free() - - Newly allocated memory is filled with the byte 0xCB, freed memory is filled - with the byte 0xDB. Additionnal checks: - - - detect API violations, ex: PyObject_Free() called on a buffer allocated - by PyMem_Malloc() - - detect write before the start of the buffer (buffer underflow) - - detect write after the end of the buffer (buffer overflow) - - The function does nothing if Python is not compiled is debug mode. */ -PyAPI_FUNC(void) PyMem_SetupDebugHooks(void); -#endif - #ifdef __cplusplus } #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Include/pyport.h --- a/Include/pyport.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/pyport.h Fri Feb 01 23:12:09 2013 +0100 @@ -219,6 +219,10 @@ /* Smallest negative value of type Py_ssize_t. */ #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1) +#if SIZEOF_PID_T > SIZEOF_LONG +# error "Python doesn't support sizeof(pid_t) > sizeof(long)" +#endif + /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf * format to convert an argument with the width of a size_t or Py_ssize_t. * C99 introduced "z" for this purpose, but not all platforms support that; @@ -263,7 +267,7 @@ */ #ifdef HAVE_LONG_LONG # ifndef PY_FORMAT_LONG_LONG -# ifdef MS_WINDOWS +# if defined(MS_WIN64) || defined(MS_WINDOWS) # define PY_FORMAT_LONG_LONG "I64" # else # error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG" @@ -393,15 +397,9 @@ #include #endif -#ifndef S_IFMT +#if defined(PYCC_VACPP) /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */ -#define S_IFMT 0170000 -#endif - -#ifndef S_IFLNK -/* Windows doesn't define S_IFLNK but posixmodule.c maps - * IO_REPARSE_TAG_SYMLINK to S_IFLNK */ -# define S_IFLNK 0120000 +#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG) #endif #ifndef S_ISREG @@ -412,9 +410,6 @@ #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) #endif -#ifndef S_ISCHR -#define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR) -#endif #ifdef __cplusplus /* Move this down here since some C++ #include's don't like to be included @@ -837,6 +832,15 @@ #endif /* + * Add PyArg_ParseTuple format where available. + */ +#ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE +#define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2))) +#else +#define Py_FORMAT_PARSETUPLE(func,p1,p2) +#endif + +/* * Specify alignment on compilers that support it. */ #if defined(__GNUC__) && __GNUC__ >= 3 @@ -877,7 +881,7 @@ /* * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is * detected by configure and defined in pyconfig.h. The code in pyconfig.h - * also takes care of Apple's universal builds. + * also also takes care of Apple's universal builds. */ #ifdef WORDS_BIGENDIAN diff -r 35c88c53cf64 -r ecc10f0afb76 Include/pystate.h --- a/Include/pystate.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/pystate.h Fri Feb 01 23:12:09 2013 +0100 @@ -69,7 +69,6 @@ typedef struct _ts { /* See Python/ceval.c for comments explaining most fields */ - struct _ts *prev; struct _ts *next; PyInterpreterState *interp; @@ -140,7 +139,6 @@ PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *); PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); -PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate); #ifdef WITH_THREAD PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); PyAPI_FUNC(void) _PyGILState_Reinit(void); @@ -214,11 +212,6 @@ */ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void); -/* Helper/diagnostic function - return 1 if the current thread - * currently holds the GIL, 0 otherwise - */ -PyAPI_FUNC(int) PyGILState_Check(void); - #endif /* #ifdef WITH_THREAD */ /* The implementation of sys._current_frames() Returns a dict mapping diff -r 35c88c53cf64 -r ecc10f0afb76 Include/pythonrun.h --- a/Include/pythonrun.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/pythonrun.h Fri Feb 01 23:12:09 2013 +0100 @@ -197,7 +197,7 @@ PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod); PyAPI_FUNC(void) _PyImportHooks_Init(void); PyAPI_FUNC(int) _PyFrame_Init(void); -PyAPI_FUNC(int) _PyFloat_Init(void); +PyAPI_FUNC(void) _PyFloat_Init(void); PyAPI_FUNC(int) PyByteArray_Init(void); PyAPI_FUNC(void) _PyRandom_Init(void); #endif @@ -217,10 +217,8 @@ PyAPI_FUNC(void) PyByteArray_Fini(void); PyAPI_FUNC(void) PyFloat_Fini(void); PyAPI_FUNC(void) PyOS_FiniInterrupts(void); -PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); PyAPI_FUNC(void) _PyGC_Fini(void); PyAPI_FUNC(void) PySlice_Fini(void); -PyAPI_FUNC(void) _PyType_Fini(void); PyAPI_DATA(PyThreadState *) _Py_Finalizing; #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Include/structseq.h --- a/Include/structseq.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/structseq.h Fri Feb 01 23:12:09 2013 +0100 @@ -24,8 +24,6 @@ #ifndef Py_LIMITED_API PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc); -PyAPI_FUNC(int) PyStructSequence_InitType2(PyTypeObject *type, - PyStructSequence_Desc *desc); #endif PyAPI_FUNC(PyTypeObject*) PyStructSequence_NewType(PyStructSequence_Desc *desc); diff -r 35c88c53cf64 -r ecc10f0afb76 Include/symtable.h --- a/Include/symtable.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/symtable.h Fri Feb 01 23:12:09 2013 +0100 @@ -53,9 +53,6 @@ unsigned ste_varkeywords : 1; /* true if block has varkeywords */ unsigned ste_returns_value : 1; /* true if namespace uses return with an argument */ - unsigned ste_needs_class_closure : 1; /* for class scopes, true if a - closure over __class__ - should be created */ int ste_lineno; /* first line of block */ int ste_col_offset; /* offset of first line of block */ int ste_opt_lineno; /* lineno of last exec or import * */ diff -r 35c88c53cf64 -r ecc10f0afb76 Include/sysmodule.h --- a/Include/sysmodule.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/sysmodule.h Fri Feb 01 23:12:09 2013 +0100 @@ -20,6 +20,10 @@ PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...); PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...); +#ifndef Py_LIMITED_API +PyAPI_DATA(PyObject *) _PySys_TraceFunc, *_PySys_ProfileFunc; +#endif + PyAPI_FUNC(void) PySys_ResetWarnOptions(void); PyAPI_FUNC(void) PySys_AddWarnOption(const wchar_t *); PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *); diff -r 35c88c53cf64 -r ecc10f0afb76 Include/unicodeobject.h --- a/Include/unicodeobject.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/unicodeobject.h Fri Feb 01 23:12:09 2013 +0100 @@ -898,28 +898,22 @@ Py_UCS4 maxchar; Py_ssize_t size; Py_ssize_t pos; - - /* minimum number of allocated characters (default: 0) */ + /* minimum length of the buffer when overallocation is enabled, + see _PyUnicodeWriter_Init() */ Py_ssize_t min_length; - - /* minimum character (default: 127, ASCII) */ - Py_UCS4 min_char; - - /* If non-zero, overallocate the buffer by 25% (default: 0). */ unsigned char overallocate; - /* If readonly is 1, buffer is a shared string (cannot be modified) and size is set to 0. */ unsigned char readonly; } _PyUnicodeWriter ; /* Initialize a Unicode writer. - * - * By default, the minimum buffer size is 0 character and overallocation is - * disabled. Set min_length, min_char and overallocate attributes to control - * the allocation of the buffer. */ + + If min_length is greater than zero, _PyUnicodeWriter_Prepare() + overallocates the buffer and min_length is the minimum length in characters + of the buffer. */ PyAPI_FUNC(void) -_PyUnicodeWriter_Init(_PyUnicodeWriter *writer); +_PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length); /* Prepare the buffer to write 'length' characters with the specified maximum character. @@ -939,13 +933,6 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, Py_ssize_t length, Py_UCS4 maxchar); -/* Append a Unicode character. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) -_PyUnicodeWriter_WriteChar(_PyUnicodeWriter *writer, - Py_UCS4 ch - ); - /* Append a Unicode string. Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) @@ -953,15 +940,6 @@ PyObject *str /* Unicode string */ ); -/* Append a substring of a Unicode string. - Return 0 on success, raise an exception and return -1 on error. */ -PyAPI_FUNC(int) -_PyUnicodeWriter_WriteSubstring(_PyUnicodeWriter *writer, - PyObject *str, /* Unicode string */ - Py_ssize_t start, - Py_ssize_t end - ); - /* Append a latin1-encoded byte string. Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) @@ -970,7 +948,7 @@ Py_ssize_t len /* length in bytes */ ); -/* Get the value of the writer as an Unicode string. Clear the +/* Get the value of the write as an Unicode string. Clear the buffer of the writer. Raise an exception and return NULL on error. */ PyAPI_FUNC(PyObject *) diff -r 35c88c53cf64 -r ecc10f0afb76 Include/warnings.h --- a/Include/warnings.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Include/warnings.h Fri Feb 01 23:12:09 2013 +0100 @@ -25,12 +25,6 @@ const char *module, /* UTF-8 encoded string */ PyObject *registry); -PyAPI_FUNC(int) -PyErr_WarnExplicitFormat(PyObject *category, - const char *filename, int lineno, - const char *module, PyObject *registry, - const char *format, ...); - /* DEPRECATED: Use PyErr_WarnEx() instead. */ #ifndef Py_LIMITED_API #define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1) diff -r 35c88c53cf64 -r ecc10f0afb76 LICENSE --- a/LICENSE Fri Jul 26 23:14:22 2013 -0700 +++ b/LICENSE Fri Feb 01 23:12:09 2013 +0100 @@ -74,9 +74,7 @@ 3.2.1 3.2 2011 PSF yes 3.2.2 3.2.1 2011 PSF yes 3.2.3 3.2.2 2012 PSF yes - 3.2.4 3.2.3 2013 PSF yes 3.3.0 3.2 2012 PSF yes - 3.3.1 3.3.0 2013 PSF yes 3.4.0 3.3.0 2014 PSF yes Footnotes: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/_pyio.py --- a/Lib/_pyio.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/_pyio.py Fri Feb 01 23:12:09 2013 +0100 @@ -32,7 +32,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, - newline=None, closefd=True, opener=None): + newline=None, closefd=True, opener=None, cloexec=None): r"""Open file and return a stream. Raise OSError upon failure. @@ -135,6 +135,8 @@ descriptor (passing os.open as *opener* results in functionality similar to passing None). + If cloexec is True, set the close-on-exec flag. + open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode ('w', @@ -191,7 +193,7 @@ (writing and "w" or "") + (appending and "a" or "") + (updating and "+" or ""), - closefd, opener=opener) + closefd, opener=opener, cloexec=cloexec) line_buffering = False if buffering == 1 or buffering < 0 and raw.isatty(): buffering = -1 @@ -303,7 +305,7 @@ def seek(self, pos, whence=0): """Change stream position. - Change the stream position to byte offset pos. Argument pos is + Change the stream position to byte offset offset. offset is interpreted relative to the position indicated by whence. Values for whence are ints: @@ -2054,6 +2056,7 @@ if not isinstance(initial_value, str): raise TypeError("initial_value must be str or None, not {0}" .format(type(initial_value).__name__)) + initial_value = str(initial_value) self.write(initial_value) self.seek(0) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/_strptime.py --- a/Lib/_strptime.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/_strptime.py Fri Feb 01 23:12:09 2013 +0100 @@ -21,7 +21,7 @@ timezone as datetime_timezone) try: from _thread import allocate_lock as _thread_allocate_lock -except ImportError: +except: from _dummy_thread import allocate_lock as _thread_allocate_lock __all__ = [] @@ -326,7 +326,7 @@ bad_directive = "%" del err raise ValueError("'%s' is a bad directive in format '%s'" % - (bad_directive, format)) from None + (bad_directive, format)) # IndexError only occurs when the format string is "%" except IndexError: raise ValueError("stray %% in format '%s'" % format) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/abc.py --- a/Lib/abc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/abc.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,6 @@ from _weakrefset import WeakSet - def abstractmethod(funcobj): """A decorator indicating abstract methods. @@ -125,8 +124,6 @@ # A global counter that is incremented each time a class is # registered as a virtual subclass of anything. It forces the # negative cache to be cleared before its next use. - # Note: this counter is private. Use `abc.get_cache_token()` for - # external code. _abc_invalidation_counter = 0 def __new__(mcls, name, bases, namespace): @@ -230,19 +227,8 @@ cls._abc_negative_cache.add(subclass) return False - class ABC(metaclass=ABCMeta): """Helper class that provides a standard way to create an ABC using inheritance. """ pass - - -def get_cache_token(): - """Returns the current ABC cache token. - - The token is an opaque integer identifying the current version of - the ABC cache for virtual subclasses. This number changes with - every call to ``register()`` on any ABC. - """ - return ABCMeta._abc_invalidation_counter diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/aifc.py --- a/Lib/aifc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/aifc.py Fri Feb 01 23:12:09 2013 +0100 @@ -69,7 +69,7 @@ getcomptype() -- returns compression type ('NONE' for AIFF files) getcompname() -- returns human-readable version of compression type ('not compressed' for AIFF files) - getparams() -- returns a namedtuple consisting of all of the + getparams() -- returns a tuple consisting of all of the above in the above order getmarkers() -- get the list of marks in the audio file or None if there are no marks @@ -252,11 +252,6 @@ _write_ulong(f, lomant) from chunk import Chunk -from collections import namedtuple - -_aifc_params = namedtuple('_aifc_params', - 'nchannels sampwidth framerate nframes comptype compname') - class Aifc_read: # Variables used in this class: @@ -383,9 +378,9 @@ ## return self._version def getparams(self): - return _aifc_params(self.getnchannels(), self.getsampwidth(), - self.getframerate(), self.getnframes(), - self.getcomptype(), self.getcompname()) + return self.getnchannels(), self.getsampwidth(), \ + self.getframerate(), self.getnframes(), \ + self.getcomptype(), self.getcompname() def getmarkers(self): if len(self._markers) == 0: @@ -663,8 +658,8 @@ def getparams(self): if not self._nchannels or not self._sampwidth or not self._framerate: raise Error('not all parameters set') - return _aifc_params(self._nchannels, self._sampwidth, self._framerate, - self._nframes, self._comptype, self._compname) + return self._nchannels, self._sampwidth, self._framerate, \ + self._nframes, self._comptype, self._compname def setmark(self, id, pos, name): if id <= 0: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/argparse.py --- a/Lib/argparse.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/argparse.py Fri Feb 01 23:12:09 2013 +0100 @@ -1141,7 +1141,7 @@ - bufsize -- The file's desired buffer size. Accepts the same values as the builtin open() function. - encoding -- The file's encoding. Accepts the same values as the - builtin open() function. + the builtin open() function. - errors -- A string indicating how encoding and decoding errors are to be handled. Accepts the same value as the builtin open() function. """ @@ -2010,13 +2010,16 @@ # replace arguments referencing files with the file content else: try: - with open(arg_string[1:]) as args_file: + args_file = open(arg_string[1:]) + try: arg_strings = [] for arg_line in args_file.read().splitlines(): for arg in self.convert_arg_line_to_args(arg_line): arg_strings.append(arg) arg_strings = self._read_args_from_files(arg_strings) new_arg_strings.extend(arg_strings) + finally: + args_file.close() except OSError: err = _sys.exc_info()[1] self.error(str(err)) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/asyncore.py --- a/Lib/asyncore.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/asyncore.py Fri Feb 01 23:12:09 2013 +0100 @@ -284,9 +284,9 @@ del map[fd] self._fileno = None - def create_socket(self, family=socket.AF_INET, type=socket.SOCK_STREAM): + def create_socket(self, family=socket.AF_INET, type=socket.SOCK_STREAM, cloexec=None): self.family_and_type = family, type - sock = socket.socket(family, type) + sock = socket.socket(family, type, cloexec=cloexec) sock.setblocking(0) self.set_socket(sock) @@ -397,12 +397,11 @@ self.accepting = False self.connecting = False self.del_channel() - if self.socket is not None: - try: - self.socket.close() - except OSError as why: - if why.args[0] not in (ENOTCONN, EBADF): - raise + try: + self.socket.close() + except OSError as why: + if why.args[0] not in (ENOTCONN, EBADF): + raise # cheap inheritance, used to pass all other attribute # references to the underlying socket object. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/base64.py --- a/Lib/base64.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/base64.py Fri Feb 01 23:12:09 2013 +0100 @@ -138,10 +138,21 @@ # Base32 encoding/decoding must be done in Python -_b32alphabet = b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567' -_b32tab = [bytes([i]) for i in _b32alphabet] -_b32tab2 = [a + b for a in _b32tab for b in _b32tab] -_b32rev = {v: k for k, v in enumerate(_b32alphabet)} +_b32alphabet = { + 0: b'A', 9: b'J', 18: b'S', 27: b'3', + 1: b'B', 10: b'K', 19: b'T', 28: b'4', + 2: b'C', 11: b'L', 20: b'U', 29: b'5', + 3: b'D', 12: b'M', 21: b'V', 30: b'6', + 4: b'E', 13: b'N', 22: b'W', 31: b'7', + 5: b'F', 14: b'O', 23: b'X', + 6: b'G', 15: b'P', 24: b'Y', + 7: b'H', 16: b'Q', 25: b'Z', + 8: b'I', 17: b'R', 26: b'2', + } + +_b32tab = [v[0] for k, v in sorted(_b32alphabet.items())] +_b32rev = dict([(v[0], k) for k, v in _b32alphabet.items()]) + def b32encode(s): """Encode a byte string using Base32. @@ -150,30 +161,41 @@ """ if not isinstance(s, bytes_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) - leftover = len(s) % 5 + quanta, leftover = divmod(len(s), 5) # Pad the last quantum with zero bits if necessary if leftover: s = s + bytes(5 - leftover) # Don't use += ! - encoded = bytearray() - from_bytes = int.from_bytes - b32tab2 = _b32tab2 - for i in range(0, len(s), 5): - c = from_bytes(s[i: i + 5], 'big') - encoded += (b32tab2[c >> 30] + # bits 1 - 10 - b32tab2[(c >> 20) & 0x3ff] + # bits 11 - 20 - b32tab2[(c >> 10) & 0x3ff] + # bits 21 - 30 - b32tab2[c & 0x3ff] # bits 31 - 40 - ) + quanta += 1 + encoded = bytes() + for i in range(quanta): + # c1 and c2 are 16 bits wide, c3 is 8 bits wide. The intent of this + # code is to process the 40 bits in units of 5 bits. So we take the 1 + # leftover bit of c1 and tack it onto c2. Then we take the 2 leftover + # bits of c2 and tack them onto c3. The shifts and masks are intended + # to give us values of exactly 5 bits in width. + c1, c2, c3 = struct.unpack('!HHB', s[i*5:(i+1)*5]) + c2 += (c1 & 1) << 16 # 17 bits wide + c3 += (c2 & 3) << 8 # 10 bits wide + encoded += bytes([_b32tab[c1 >> 11], # bits 1 - 5 + _b32tab[(c1 >> 6) & 0x1f], # bits 6 - 10 + _b32tab[(c1 >> 1) & 0x1f], # bits 11 - 15 + _b32tab[c2 >> 12], # bits 16 - 20 (1 - 5) + _b32tab[(c2 >> 7) & 0x1f], # bits 21 - 25 (6 - 10) + _b32tab[(c2 >> 2) & 0x1f], # bits 26 - 30 (11 - 15) + _b32tab[c3 >> 5], # bits 31 - 35 (1 - 5) + _b32tab[c3 & 0x1f], # bits 36 - 40 (1 - 5) + ]) # Adjust for any leftover partial quanta if leftover == 1: - encoded[-6:] = b'======' + return encoded[:-6] + b'======' elif leftover == 2: - encoded[-4:] = b'====' + return encoded[:-4] + b'====' elif leftover == 3: - encoded[-3:] = b'===' + return encoded[:-3] + b'===' elif leftover == 4: - encoded[-1:] = b'=' - return bytes(encoded) + return encoded[:-1] + b'=' + return encoded + def b32decode(s, casefold=False, map01=None): """Decode a Base32 encoded byte string. @@ -195,7 +217,8 @@ characters present in the input. """ s = _bytes_from_decode_data(s) - if len(s) % 8: + quanta, leftover = divmod(len(s), 8) + if leftover: raise binascii.Error('Incorrect padding') # Handle section 2.4 zero and one mapping. The flag map01 will be either # False, or the character to map the digit 1 (one) to. It should be @@ -209,36 +232,42 @@ # Strip off pad characters from the right. We need to count the pad # characters because this will tell us how many null bytes to remove from # the end of the decoded string. - l = len(s) - s = s.rstrip(b'=') - padchars = l - len(s) + padchars = 0 + mo = re.search(b'(?P[=]*)$', s) + if mo: + padchars = len(mo.group('pad')) + if padchars > 0: + s = s[:-padchars] # Now decode the full quanta - decoded = bytearray() - b32rev = _b32rev - for i in range(0, len(s), 8): - quanta = s[i: i + 8] - acc = 0 - try: - for c in quanta: - acc = (acc << 5) + b32rev[c] - except KeyError: - raise binascii.Error('Non-base32 digit found') from None - decoded += acc.to_bytes(5, 'big') + parts = [] + acc = 0 + shift = 35 + for c in s: + val = _b32rev.get(c) + if val is None: + raise TypeError('Non-base32 digit found') + acc += _b32rev[c] << shift + shift -= 5 + if shift < 0: + parts.append(binascii.unhexlify(bytes('%010x' % acc, "ascii"))) + acc = 0 + shift = 35 # Process the last, partial quanta - if padchars: - acc <<= 5 * padchars - last = acc.to_bytes(5, 'big') - if padchars == 1: - decoded[-5:] = last[:-1] - elif padchars == 3: - decoded[-5:] = last[:-2] - elif padchars == 4: - decoded[-5:] = last[:-3] - elif padchars == 6: - decoded[-5:] = last[:-4] - else: - raise binascii.Error('Incorrect padding') - return bytes(decoded) + last = binascii.unhexlify(bytes('%010x' % acc, "ascii")) + if padchars == 0: + last = b'' # No characters + elif padchars == 1: + last = last[:-1] + elif padchars == 3: + last = last[:-2] + elif padchars == 4: + last = last[:-3] + elif padchars == 6: + last = last[:-4] + else: + raise binascii.Error('Incorrect padding') + parts.append(last) + return b''.join(parts) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/cProfile.py --- a/Lib/cProfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/cProfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,20 +7,54 @@ __all__ = ["run", "runctx", "Profile"] import _lsprof -import profile as _pyprofile # ____________________________________________________________ # Simple interface def run(statement, filename=None, sort=-1): - return _pyprofile._Utils(Profile).run(statement, filename, sort) + """Run statement under profiler optionally saving results in filename + + This function takes a single argument that can be passed to the + "exec" statement, and an optional file name. In all cases this + routine attempts to "exec" its first argument and gather profiling + statistics from the execution. If no file name is present, then this + function automatically prints a simple profiling report, sorted by the + standard name string (file/line/function-name) that is presented in + each line. + """ + prof = Profile() + result = None + try: + try: + prof = prof.run(statement) + except SystemExit: + pass + finally: + if filename is not None: + prof.dump_stats(filename) + else: + result = prof.print_stats(sort) + return result def runctx(statement, globals, locals, filename=None, sort=-1): - return _pyprofile._Utils(Profile).runctx(statement, globals, locals, - filename, sort) + """Run statement under profiler, supplying your own globals and locals, + optionally saving results in filename. -run.__doc__ = _pyprofile.run.__doc__ -runctx.__doc__ = _pyprofile.runctx.__doc__ + statement and filename have the same semantics as profile.run + """ + prof = Profile() + result = None + try: + try: + prof = prof.runctx(statement, globals, locals) + except SystemExit: + pass + finally: + if filename is not None: + prof.dump_stats(filename) + else: + result = prof.print_stats(sort) + return result # ____________________________________________________________ @@ -43,9 +77,10 @@ def dump_stats(self, file): import marshal - with open(file, 'wb') as f: - self.create_stats() - marshal.dump(self.stats, f) + f = open(file, 'wb') + self.create_stats() + marshal.dump(self.stats, f) + f.close() def create_stats(self): self.disable() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/cgi.py --- a/Lib/cgi.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/cgi.py Fri Feb 01 23:12:09 2013 +0100 @@ -223,17 +223,17 @@ """ import http.client - boundary = b"" + boundary = "" if 'boundary' in pdict: boundary = pdict['boundary'] if not valid_boundary(boundary): raise ValueError('Invalid boundary in multipart form: %r' % (boundary,)) - nextpart = b"--" + boundary - lastpart = b"--" + boundary + b"--" + nextpart = "--" + boundary + lastpart = "--" + boundary + "--" partdict = {} - terminator = b"" + terminator = "" while terminator != lastpart: bytes = -1 @@ -252,7 +252,7 @@ raise ValueError('Maximum content length exceeded') data = fp.read(bytes) else: - data = b"" + data = "" # Read lines until end of part. lines = [] while 1: @@ -260,7 +260,7 @@ if not line: terminator = lastpart # End outer loop break - if line.startswith(b"--"): + if line.startswith("--"): terminator = line.rstrip() if terminator in (nextpart, lastpart): break @@ -272,12 +272,12 @@ if lines: # Strip final line terminator line = lines[-1] - if line[-2:] == b"\r\n": + if line[-2:] == "\r\n": line = line[:-2] - elif line[-1:] == b"\n": + elif line[-1:] == "\n": line = line[:-1] lines[-1] = line - data = b"".join(lines) + data = "".join(lines) line = headers['content-disposition'] if not line: continue @@ -699,7 +699,7 @@ self.encoding, self.errors) self.bytes_read += part.bytes_read self.list.append(part) - if part.done or self.bytes_read >= self.length > 0: + if self.bytes_read >= self.length: break self.skip_lines() @@ -786,9 +786,6 @@ if not line: self.done = -1 break - if delim == b"\r": - line = delim + line - delim = b"" if line.startswith(b"--") and last_line_lfend: strippedline = line.rstrip() if strippedline == next_boundary: @@ -805,12 +802,6 @@ delim = b"\n" line = line[:-1] last_line_lfend = True - elif line.endswith(b"\r"): - # We may interrupt \r\n sequences if they span the 2**16 - # byte boundary - delim = b"\r" - line = line[:-1] - last_line_lfend = False else: delim = b"" last_line_lfend = False diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/codecs.py --- a/Lib/codecs.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/codecs.py Fri Feb 01 23:12:09 2013 +0100 @@ -105,7 +105,6 @@ Python will use the official U+FFFD REPLACEMENT CHARACTER for the builtin Unicode codecs on decoding and '?' on encoding. - 'surrogateescape' - replace with private codepoints U+DCnn. 'xmlcharrefreplace' - Replace with the appropriate XML character reference (only for encoding). 'backslashreplace' - Replace with backslashed escape sequences diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/collections/__init__.py --- a/Lib/collections/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/collections/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -12,7 +12,7 @@ from keyword import iskeyword as _iskeyword import sys as _sys import heapq as _heapq -from _weakref import proxy as _proxy +from weakref import proxy as _proxy from itertools import repeat as _repeat, chain as _chain, starmap as _starmap from reprlib import recursive_repr as _recursive_repr @@ -199,10 +199,13 @@ def __reduce__(self): 'Return state information for pickling' + items = [[k, self[k]] for k in self] inst_dict = vars(self).copy() for k in vars(OrderedDict()): inst_dict.pop(k, None) - return self.__class__, (), inst_dict or None, None, iter(self.items()) + if inst_dict: + return (self.__class__, (items,), inst_dict) + return self.__class__, (items,) def copy(self): 'od.copy() -> a shallow copy of od' @@ -233,7 +236,7 @@ ### namedtuple ################################################################################ -_class_template = """\ +_class_template = '''\ from builtins import property as _property, tuple as _tuple from operator import itemgetter as _itemgetter from collections import OrderedDict @@ -257,6 +260,16 @@ raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result)) return result + def __repr__(self): + 'Return a nicely formatted representation string' + return self.__class__.__name__ + '({repr_fmt})' % self + + def _asdict(self): + 'Return a new OrderedDict which maps field names to their values' + return OrderedDict(zip(self._fields, self)) + + __dict__ = property(_asdict) + def _replace(_self, **kwds): 'Return a new {typename} object replacing specified fields with new values' result = _self._make(map(kwds.pop, {field_names!r}, _self)) @@ -264,31 +277,12 @@ raise ValueError('Got unexpected field names: %r' % list(kwds)) return result - def __repr__(self): - 'Return a nicely formatted representation string' - return self.__class__.__name__ + '({repr_fmt})' % self - - @property - def __dict__(self): - 'A new OrderedDict mapping field names to their values' - return OrderedDict(zip(self._fields, self)) - - def _asdict(self): - '''Return a new OrderedDict which maps field names to their values. - This method is obsolete. Use vars(nt) or nt.__dict__ instead. - ''' - return self.__dict__ - def __getnewargs__(self): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) - def __getstate__(self): - 'Exclude the OrderedDict from pickling' - return None - {field_defs} -""" +''' _repr_template = '{name}=%r' @@ -328,19 +322,24 @@ if rename: seen = set() for index, name in enumerate(field_names): - if (not name.isidentifier() + if (not all(c.isalnum() or c=='_' for c in name) or _iskeyword(name) + or not name + or name[0].isdigit() or name.startswith('_') or name in seen): field_names[index] = '_%d' % index seen.add(name) for name in [typename] + field_names: - if not name.isidentifier(): - raise ValueError('Type names and field names must be valid ' - 'identifiers: %r' % name) + if not all(c.isalnum() or c=='_' for c in name): + raise ValueError('Type names and field names can only contain ' + 'alphanumeric characters and underscores: %r' % name) if _iskeyword(name): raise ValueError('Type names and field names cannot be a ' 'keyword: %r' % name) + if name[0].isdigit(): + raise ValueError('Type names and field names cannot start with ' + 'a number: %r' % name) seen = set() for name in field_names: if name.startswith('_') and not rename: @@ -365,7 +364,10 @@ # Execute the template string in a temporary namespace and support # tracing utilities by setting a value for frame.f_globals['__name__'] namespace = dict(__name__='namedtuple_%s' % typename) - exec(class_definition, namespace) + try: + exec(class_definition, namespace) + except SyntaxError as e: + raise SyntaxError(e.msg + ':\n\n' + class_definition) result = namespace[typename] result._source = class_definition if verbose: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/collections/abc.py --- a/Lib/collections/abc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/collections/abc.py Fri Feb 01 23:12:09 2013 +0100 @@ -90,7 +90,6 @@ @abstractmethod def __next__(self): - 'Return the next item from the iterator. When exhausted, raise StopIteration' raise StopIteration def __iter__(self): @@ -231,7 +230,6 @@ return self._from_iterable(value for value in other if value in self) def isdisjoint(self, other): - 'Return True if two sets have a null intersection.' for value in other: if value in self: return False @@ -294,16 +292,6 @@ class MutableSet(Set): - """A mutable set is a finite, iterable container. - - This class provides concrete generic implementations of all - methods except for __contains__, __iter__, __len__, - add(), and discard(). - - To override the comparisons (presumably for speed, as the - semantics are fixed), all you have to do is redefine __le__ and - then the other operations will automatically follow suit. - """ __slots__ = () @@ -382,20 +370,11 @@ __slots__ = () - """A Mapping is a generic container for associating key/value - pairs. - - This class provides concrete generic implementations of all - methods except for __getitem__, __iter__, and __len__. - - """ - @abstractmethod def __getitem__(self, key): raise KeyError def get(self, key, default=None): - 'D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.' try: return self[key] except KeyError: @@ -410,15 +389,12 @@ return True def keys(self): - "D.keys() -> a set-like object providing a view on D's keys" return KeysView(self) def items(self): - "D.items() -> a set-like object providing a view on D's items" return ItemsView(self) def values(self): - "D.values() -> an object providing a view on D's values" return ValuesView(self) def __eq__(self, other): @@ -500,15 +476,6 @@ __slots__ = () - """A MutableMapping is a generic container for associating - key/value pairs. - - This class provides concrete generic implementations of all - methods except for __getitem__, __setitem__, __delitem__, - __iter__, and __len__. - - """ - @abstractmethod def __setitem__(self, key, value): raise KeyError @@ -520,9 +487,6 @@ __marker = object() def pop(self, key, default=__marker): - '''D.pop(k[,d]) -> v, remove specified key and return the corresponding value. - If key is not found, d is returned if given, otherwise KeyError is raised. - ''' try: value = self[key] except KeyError: @@ -534,9 +498,6 @@ return value def popitem(self): - '''D.popitem() -> (k, v), remove and return some (key, value) pair - as a 2-tuple; but raise KeyError if D is empty. - ''' try: key = next(iter(self)) except StopIteration: @@ -546,7 +507,6 @@ return key, value def clear(self): - 'D.clear() -> None. Remove all items from D.' try: while True: self.popitem() @@ -554,11 +514,6 @@ pass def update(*args, **kwds): - ''' D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. - If E present and has a .keys() method, does: for k in E: D[k] = E[k] - If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v - In either case, this is followed by: for k, v in F.items(): D[k] = v - ''' if len(args) > 2: raise TypeError("update() takes at most 2 positional " "arguments ({} given)".format(len(args))) @@ -580,7 +535,6 @@ self[key] = value def setdefault(self, key, default=None): - 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' try: return self[key] except KeyError: @@ -628,16 +582,12 @@ yield self[i] def index(self, value): - '''S.index(value) -> integer -- return first index of value. - Raises ValueError if the value is not present. - ''' for i, v in enumerate(self): if v == value: return i raise ValueError def count(self, value): - 'S.count(value) -> integer -- return number of occurrences of value' return sum(1 for v in self if v == value) Sequence.register(tuple) @@ -662,13 +612,6 @@ __slots__ = () - """All the operations on a read-write sequence. - - Concrete subclasses must provide __new__ or __init__, - __getitem__, __setitem__, __delitem__, __len__, and insert(). - - """ - @abstractmethod def __setitem__(self, index, value): raise IndexError @@ -679,15 +622,12 @@ @abstractmethod def insert(self, index, value): - 'S.insert(index, value) -- insert value before index' raise IndexError def append(self, value): - 'S.append(value) -- append value to the end of the sequence' self.insert(len(self), value) def clear(self): - 'S.clear() -> None -- remove all items from S' try: while True: self.pop() @@ -695,28 +635,20 @@ pass def reverse(self): - 'S.reverse() -- reverse *IN PLACE*' n = len(self) for i in range(n//2): self[i], self[n-i-1] = self[n-i-1], self[i] def extend(self, values): - 'S.extend(iterable) -- extend sequence by appending elements from the iterable' for v in values: self.append(v) def pop(self, index=-1): - '''S.pop([index]) -> item -- remove and return item at index (default last). - Raise IndexError if list is empty or index is out of range. - ''' v = self[index] del self[index] return v def remove(self, value): - '''S.remove(value) -- remove first occurrence of value. - Raise ValueError if the value is not present. - ''' del self[self.index(value)] def __iadd__(self, values): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/compileall.py --- a/Lib/compileall.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/compileall.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,7 +13,7 @@ import os import sys import errno -import importlib.util +import imp import py_compile import struct @@ -91,18 +91,17 @@ cfile = fullname + ('c' if __debug__ else 'o') else: if optimize >= 0: - cfile = importlib.util.cache_from_source( - fullname, debug_override=not optimize) + cfile = imp.cache_from_source(fullname, + debug_override=not optimize) else: - cfile = importlib.util.cache_from_source(fullname) + cfile = imp.cache_from_source(fullname) cache_dir = os.path.dirname(cfile) head, tail = name[:-3], name[-3:] if tail == '.py': if not force: try: mtime = int(os.stat(fullname).st_mtime) - expect = struct.pack('<4sl', importlib.util.MAGIC_NUMBER, - mtime) + expect = struct.pack('<4sl', imp.get_magic(), mtime) with open(cfile, 'rb') as chandle: actual = chandle.read(8) if expect == actual: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/concurrent/futures/_base.py --- a/Lib/concurrent/futures/_base.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/concurrent/futures/_base.py Fri Feb 01 23:12:09 2013 +0100 @@ -331,7 +331,7 @@ return True def cancelled(self): - """Return True if the future was cancelled.""" + """Return True if the future has cancelled.""" with self._condition: return self._state in [CANCELLED, CANCELLED_AND_NOTIFIED] @@ -517,7 +517,7 @@ """Returns a iterator equivalent to map(fn, iter). Args: - fn: A callable that will take as many arguments as there are + fn: A callable that will take take as many arguments as there are passed iterables. timeout: The maximum number of seconds to wait. If None, then there is no limit on the wait time. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/concurrent/futures/process.py --- a/Lib/concurrent/futures/process.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/concurrent/futures/process.py Fri Feb 01 23:12:09 2013 +0100 @@ -331,7 +331,7 @@ _check_system_limits() if max_workers is None: - self._max_workers = os.cpu_count() or 1 + self._max_workers = multiprocessing.cpu_count() else: self._max_workers = max_workers diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/configparser.py --- a/Lib/configparser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/configparser.py Fri Feb 01 23:12:09 2013 +0100 @@ -191,7 +191,7 @@ def __init__(self, section, source=None, lineno=None): msg = [repr(section), " already exists"] if source is not None: - message = ["While reading from ", repr(source)] + message = ["While reading from ", source] if lineno is not None: message.append(" [line {0:2d}]".format(lineno)) message.append(": section ") @@ -217,7 +217,7 @@ msg = [repr(option), " in section ", repr(section), " already exists"] if source is not None: - message = ["While reading from ", repr(source)] + message = ["While reading from ", source] if lineno is not None: message.append(" [line {0:2d}]".format(lineno)) message.append(": option ") @@ -456,7 +456,7 @@ tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax if '$' in tmp_value: raise ValueError("invalid interpolation syntax in %r at " - "position %d" % (value, tmp_value.find('$'))) + "position %d" % (value, tmp_value.find('%'))) return value def _interpolate_some(self, parser, option, accum, rest, section, map, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/contextlib.py --- a/Lib/contextlib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/contextlib.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,7 +4,7 @@ from collections import deque from functools import wraps -__all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack", "ignored"] +__all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack"] class ContextDecorator(object): @@ -140,18 +140,6 @@ def __exit__(self, *exc_info): self.thing.close() -@contextmanager -def ignored(*exceptions): - """Context manager to ignore specifed exceptions - - with ignored(OSError): - os.remove(somefile) - - """ - try: - yield - except exceptions: - pass # Inspired by discussions on http://bugs.python.org/issue13585 class ExitStack(object): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/csv.py --- a/Lib/csv.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/csv.py Fri Feb 01 23:12:09 2013 +0100 @@ -264,9 +264,8 @@ # if we see an extra quote between delimiters, we've got a # double quoted format - dq_regexp = re.compile( - r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \ - {'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE) + dq_regexp = re.compile(r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \ + {'delim':delim, 'quote':quotechar}, re.MULTILINE) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/__init__.py --- a/Lib/ctypes/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -34,15 +34,17 @@ FUNCFLAG_USE_ERRNO as _FUNCFLAG_USE_ERRNO, \ FUNCFLAG_USE_LASTERROR as _FUNCFLAG_USE_LASTERROR -# WINOLEAPI -> HRESULT -# WINOLEAPI_(type) -# -# STDMETHODCALLTYPE -# -# STDMETHOD(name) -# STDMETHOD_(type, name) -# -# STDAPICALLTYPE +""" +WINOLEAPI -> HRESULT +WINOLEAPI_(type) + +STDMETHODCALLTYPE + +STDMETHOD(name) +STDMETHOD_(type, name) + +STDAPICALLTYPE +""" def create_string_buffer(init, size=None): """create_string_buffer(aBytes) -> character array diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/test/__init__.py --- a/Lib/ctypes/test/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/test/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -37,7 +37,7 @@ def find_package_modules(package, mask): import fnmatch - if (package.__loader__ is not None and + if (hasattr(package, "__loader__") and hasattr(package.__loader__, '_files')): path = package.__name__.replace(".", os.path.sep) mask = os.path.join(path, mask) @@ -62,7 +62,7 @@ continue try: mod = __import__(modname, globals(), locals(), ['*']) - except (ResourceDenied, unittest.SkipTest) as detail: + except ResourceDenied as detail: skipped.append(modname) if verbosity > 1: print("Skipped %s: %s" % (modname, detail), file=sys.stderr) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/test/test_internals.py --- a/Lib/ctypes/test/test_internals.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/test/test_internals.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,14 +5,17 @@ # XXX This test must be reviewed for correctness!!! -# ctypes' types are container types. -# -# They have an internal memory block, which only consists of some bytes, -# but it has to keep references to other objects as well. This is not -# really needed for trivial C types like int or char, but it is important -# for aggregate types like strings or pointers in particular. -# -# What about pointers? +""" +ctypes' types are container types. + +They have an internal memory block, which only consists of some bytes, +but it has to keep references to other objects as well. This is not +really needed for trivial C types like int or char, but it is important +for aggregate types like strings or pointers in particular. + +What about pointers? + +""" class ObjectsTestCase(unittest.TestCase): def assertSame(self, a, b): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/test/test_macholib.py --- a/Lib/ctypes/test/test_macholib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/test/test_macholib.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,33 +3,35 @@ import unittest # Bob Ippolito: -# -# Ok.. the code to find the filename for __getattr__ should look -# something like: -# -# import os -# from macholib.dyld import dyld_find -# -# def find_lib(name): -# possible = ['lib'+name+'.dylib', name+'.dylib', -# name+'.framework/'+name] -# for dylib in possible: -# try: -# return os.path.realpath(dyld_find(dylib)) -# except ValueError: -# pass -# raise ValueError, "%s not found" % (name,) -# -# It'll have output like this: -# -# >>> find_lib('pthread') -# '/usr/lib/libSystem.B.dylib' -# >>> find_lib('z') -# '/usr/lib/libz.1.dylib' -# >>> find_lib('IOKit') -# '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit' -# -# -bob +""" +Ok.. the code to find the filename for __getattr__ should look +something like: + +import os +from macholib.dyld import dyld_find + +def find_lib(name): + possible = ['lib'+name+'.dylib', name+'.dylib', + name+'.framework/'+name] + for dylib in possible: + try: + return os.path.realpath(dyld_find(dylib)) + except ValueError: + pass + raise ValueError, "%s not found" % (name,) + +It'll have output like this: + + >>> find_lib('pthread') +'/usr/lib/libSystem.B.dylib' + >>> find_lib('z') +'/usr/lib/libz.1.dylib' + >>> find_lib('IOKit') +'/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit' + +-bob + +""" from ctypes.macholib.dyld import dyld_find diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/test/test_returnfuncptrs.py --- a/Lib/ctypes/test/test_returnfuncptrs.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/test/test_returnfuncptrs.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,5 @@ import unittest from ctypes import * -import os import _ctypes_test @@ -34,34 +33,5 @@ self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) self.assertRaises(TypeError, strchr, b"abcdef") - def test_from_dll(self): - dll = CDLL(_ctypes_test.__file__) - # _CFuncPtr instances are now callable with a tuple argument - # which denotes a function name and a dll: - strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(("my_strchr", dll)) - self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") - self.assertEqual(strchr(b"abcdef", b"x"), None) - self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) - self.assertRaises(TypeError, strchr, b"abcdef") - - # Issue 6083: Reference counting bug - def test_from_dll_refcount(self): - class BadSequence(tuple): - def __getitem__(self, key): - if key == 0: - return "my_strchr" - if key == 1: - return CDLL(_ctypes_test.__file__) - raise IndexError - - # _CFuncPtr instances are now callable with a tuple argument - # which denotes a function name and a dll: - strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)( - BadSequence(("my_strchr", CDLL(_ctypes_test.__file__)))) - self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") - self.assertEqual(strchr(b"abcdef", b"x"), None) - self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) - self.assertRaises(TypeError, strchr, b"abcdef") - if __name__ == "__main__": unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/test/test_win32.py --- a/Lib/ctypes/test/test_win32.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/test/test_win32.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,6 @@ from ctypes import * from ctypes.test import is_resource_enabled import unittest, sys -from test import support import _ctypes_test @@ -61,9 +60,7 @@ def test_COMError(self): from _ctypes import COMError - if support.HAVE_DOCSTRINGS: - self.assertEqual(COMError.__doc__, - "Raised when a COM method call failed.") + self.assertEqual(COMError.__doc__, "Raised when a COM method call failed.") ex = COMError(-1, "text", ("details",)) self.assertEqual(ex.hresult, -1) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/test/test_wintypes.py --- a/Lib/ctypes/test/test_wintypes.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -import sys -import unittest - -if not sys.platform.startswith('win'): - raise unittest.SkipTest('Windows-only test') - -from ctypes import * -from ctypes import wintypes - -class WinTypesTest(unittest.TestCase): - def test_variant_bool(self): - # reads 16-bits from memory, anything non-zero is True - for true_value in (1, 32767, 32768, 65535, 65537): - true = POINTER(c_int16)(c_int16(true_value)) - value = cast(true, POINTER(wintypes.VARIANT_BOOL)) - self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)') - - vb = wintypes.VARIANT_BOOL() - self.assertIs(vb.value, False) - vb.value = True - self.assertIs(vb.value, True) - vb.value = true_value - self.assertIs(vb.value, True) - - for false_value in (0, 65536, 262144, 2**33): - false = POINTER(c_int16)(c_int16(false_value)) - value = cast(false, POINTER(wintypes.VARIANT_BOOL)) - self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)') - - # allow any bool conversion on assignment to value - for set_value in (65536, 262144, 2**33): - vb = wintypes.VARIANT_BOOL() - vb.value = set_value - self.assertIs(vb.value, True) - - vb = wintypes.VARIANT_BOOL() - vb.value = [2, 3] - self.assertIs(vb.value, True) - vb.value = [] - self.assertIs(vb.value, False) - -if __name__ == "__main__": - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ctypes/util.py --- a/Lib/ctypes/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ctypes/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -92,7 +92,7 @@ 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 + '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name try: f = os.popen(cmd) try: @@ -102,8 +102,9 @@ finally: try: os.unlink(ccout) - except FileNotFoundError: - pass + except OSError as e: + if e.errno != errno.ENOENT: + raise if rv == 10: raise OSError('gcc or cc command not found') res = re.search(expr, trace) @@ -165,35 +166,6 @@ res.sort(key=_num_version) return res[-1] - elif sys.platform == "sunos5": - - def _findLib_crle(name, is64): - if not os.path.exists('/usr/bin/crle'): - return None - - if is64: - cmd = 'env LC_ALL=C /usr/bin/crle -64 2>/dev/null' - else: - cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null' - - for line in os.popen(cmd).readlines(): - line = line.strip() - if line.startswith('Default Library Path (ELF):'): - paths = line.split()[4] - - if not paths: - return None - - for dir in paths.split(":"): - libfile = os.path.join(dir, "lib%s.so" % name) - if os.path.exists(libfile): - return libfile - - return None - - def find_library(name, is64 = False): - return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name)) - else: def _findSoname_ldconfig(name): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/datetime.py --- a/Lib/datetime.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/datetime.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,19 @@ -"""Concrete date/time and related types. +"""Concrete date/time and related types -- prototype implemented in Python. -See http://www.iana.org/time-zones/repository/tz-link.html for -time zone and DST data sources. +See http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage + +See also http://dir.yahoo.com/Reference/calendars/ + +For a primer on DST, including many current DST rules, see +http://webexhibits.org/daylightsaving/ + +For more about DST than you ever wanted to know, see +ftp://elsie.nci.nih.gov/pub/ + +Sources for time zone and DST data: http://www.twinsun.com/tz/tz-link.htm + +This was originally copied from the sandbox of the CPython CVS repository. +Thanks to Tim Peters for suggesting using it. """ import time as _time @@ -1917,203 +1929,203 @@ timezone.min = timezone._create(timezone._minoffset) timezone.max = timezone._create(timezone._maxoffset) _EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc) +""" +Some time zone algebra. For a datetime x, let + x.n = x stripped of its timezone -- its naive time. + x.o = x.utcoffset(), and assuming that doesn't raise an exception or + return None + x.d = x.dst(), and assuming that doesn't raise an exception or + return None + x.s = x's standard offset, x.o - x.d -# Some time zone algebra. For a datetime x, let -# x.n = x stripped of its timezone -- its naive time. -# x.o = x.utcoffset(), and assuming that doesn't raise an exception or -# return None -# x.d = x.dst(), and assuming that doesn't raise an exception or -# return None -# x.s = x's standard offset, x.o - x.d -# -# Now some derived rules, where k is a duration (timedelta). -# -# 1. x.o = x.s + x.d -# This follows from the definition of x.s. -# -# 2. If x and y have the same tzinfo member, x.s = y.s. -# This is actually a requirement, an assumption we need to make about -# sane tzinfo classes. -# -# 3. The naive UTC time corresponding to x is x.n - x.o. -# This is again a requirement for a sane tzinfo class. -# -# 4. (x+k).s = x.s -# This follows from #2, and that datimetimetz+timedelta preserves tzinfo. -# -# 5. (x+k).n = x.n + k -# Again follows from how arithmetic is defined. -# -# Now we can explain tz.fromutc(x). Let's assume it's an interesting case -# (meaning that the various tzinfo methods exist, and don't blow up or return -# None when called). -# -# The function wants to return a datetime y with timezone tz, equivalent to x. -# x is already in UTC. -# -# By #3, we want -# -# y.n - y.o = x.n [1] -# -# The algorithm starts by attaching tz to x.n, and calling that y. So -# x.n = y.n at the start. Then it wants to add a duration k to y, so that [1] -# becomes true; in effect, we want to solve [2] for k: -# -# (y+k).n - (y+k).o = x.n [2] -# -# By #1, this is the same as -# -# (y+k).n - ((y+k).s + (y+k).d) = x.n [3] -# -# By #5, (y+k).n = y.n + k, which equals x.n + k because x.n=y.n at the start. -# Substituting that into [3], -# -# x.n + k - (y+k).s - (y+k).d = x.n; the x.n terms cancel, leaving -# k - (y+k).s - (y+k).d = 0; rearranging, -# k = (y+k).s - (y+k).d; by #4, (y+k).s == y.s, so -# k = y.s - (y+k).d -# -# On the RHS, (y+k).d can't be computed directly, but y.s can be, and we -# approximate k by ignoring the (y+k).d term at first. Note that k can't be -# very large, since all offset-returning methods return a duration of magnitude -# less than 24 hours. For that reason, if y is firmly in std time, (y+k).d must -# be 0, so ignoring it has no consequence then. -# -# In any case, the new value is -# -# z = y + y.s [4] -# -# It's helpful to step back at look at [4] from a higher level: it's simply -# mapping from UTC to tz's standard time. -# -# At this point, if -# -# z.n - z.o = x.n [5] -# -# we have an equivalent time, and are almost done. The insecurity here is -# at the start of daylight time. Picture US Eastern for concreteness. The wall -# time jumps from 1:59 to 3:00, and wall hours of the form 2:MM don't make good -# sense then. The docs ask that an Eastern tzinfo class consider such a time to -# be EDT (because it's "after 2"), which is a redundant spelling of 1:MM EST -# on the day DST starts. We want to return the 1:MM EST spelling because that's -# the only spelling that makes sense on the local wall clock. -# -# In fact, if [5] holds at this point, we do have the standard-time spelling, -# but that takes a bit of proof. We first prove a stronger result. What's the -# difference between the LHS and RHS of [5]? Let -# -# diff = x.n - (z.n - z.o) [6] -# -# Now -# z.n = by [4] -# (y + y.s).n = by #5 -# y.n + y.s = since y.n = x.n -# x.n + y.s = since z and y are have the same tzinfo member, -# y.s = z.s by #2 -# x.n + z.s -# -# Plugging that back into [6] gives -# -# diff = -# x.n - ((x.n + z.s) - z.o) = expanding -# x.n - x.n - z.s + z.o = cancelling -# - z.s + z.o = by #2 -# z.d -# -# So diff = z.d. -# -# If [5] is true now, diff = 0, so z.d = 0 too, and we have the standard-time -# spelling we wanted in the endcase described above. We're done. Contrarily, -# if z.d = 0, then we have a UTC equivalent, and are also done. -# -# If [5] is not true now, diff = z.d != 0, and z.d is the offset we need to -# add to z (in effect, z is in tz's standard time, and we need to shift the -# local clock into tz's daylight time). -# -# Let -# -# z' = z + z.d = z + diff [7] -# -# and we can again ask whether -# -# z'.n - z'.o = x.n [8] -# -# If so, we're done. If not, the tzinfo class is insane, according to the -# assumptions we've made. This also requires a bit of proof. As before, let's -# compute the difference between the LHS and RHS of [8] (and skipping some of -# the justifications for the kinds of substitutions we've done several times -# already): -# -# diff' = x.n - (z'.n - z'.o) = replacing z'.n via [7] -# x.n - (z.n + diff - z'.o) = replacing diff via [6] -# x.n - (z.n + x.n - (z.n - z.o) - z'.o) = -# x.n - z.n - x.n + z.n - z.o + z'.o = cancel x.n -# - z.n + z.n - z.o + z'.o = cancel z.n -# - z.o + z'.o = #1 twice -# -z.s - z.d + z'.s + z'.d = z and z' have same tzinfo -# z'.d - z.d -# -# So z' is UTC-equivalent to x iff z'.d = z.d at this point. If they are equal, -# we've found the UTC-equivalent so are done. In fact, we stop with [7] and -# return z', not bothering to compute z'.d. -# -# How could z.d and z'd differ? z' = z + z.d [7], so merely moving z' by -# a dst() offset, and starting *from* a time already in DST (we know z.d != 0), -# would have to change the result dst() returns: we start in DST, and moving -# a little further into it takes us out of DST. -# -# There isn't a sane case where this can happen. The closest it gets is at -# the end of DST, where there's an hour in UTC with no spelling in a hybrid -# tzinfo class. In US Eastern, that's 5:MM UTC = 0:MM EST = 1:MM EDT. During -# that hour, on an Eastern clock 1:MM is taken as being in standard time (6:MM -# UTC) because the docs insist on that, but 0:MM is taken as being in daylight -# time (4:MM UTC). There is no local time mapping to 5:MM UTC. The local -# clock jumps from 1:59 back to 1:00 again, and repeats the 1:MM hour in -# standard time. Since that's what the local clock *does*, we want to map both -# UTC hours 5:MM and 6:MM to 1:MM Eastern. The result is ambiguous -# in local time, but so it goes -- it's the way the local clock works. -# -# When x = 5:MM UTC is the input to this algorithm, x.o=0, y.o=-5 and y.d=0, -# so z=0:MM. z.d=60 (minutes) then, so [5] doesn't hold and we keep going. -# z' = z + z.d = 1:MM then, and z'.d=0, and z'.d - z.d = -60 != 0 so [8] -# (correctly) concludes that z' is not UTC-equivalent to x. -# -# Because we know z.d said z was in daylight time (else [5] would have held and -# we would have stopped then), and we know z.d != z'.d (else [8] would have held -# and we have stopped then), and there are only 2 possible values dst() can -# return in Eastern, it follows that z'.d must be 0 (which it is in the example, -# but the reasoning doesn't depend on the example -- it depends on there being -# two possible dst() outcomes, one zero and the other non-zero). Therefore -# z' must be in standard time, and is the spelling we want in this case. -# -# Note again that z' is not UTC-equivalent as far as the hybrid tzinfo class is -# concerned (because it takes z' as being in standard time rather than the -# daylight time we intend here), but returning it gives the real-life "local -# clock repeats an hour" behavior when mapping the "unspellable" UTC hour into -# tz. -# -# When the input is 6:MM, z=1:MM and z.d=0, and we stop at once, again with -# the 1:MM standard time spelling we want. -# -# So how can this break? One of the assumptions must be violated. Two -# possibilities: -# -# 1) [2] effectively says that y.s is invariant across all y belong to a given -# time zone. This isn't true if, for political reasons or continental drift, -# a region decides to change its base offset from UTC. -# -# 2) There may be versions of "double daylight" time where the tail end of -# the analysis gives up a step too early. I haven't thought about that -# enough to say. -# -# In any case, it's clear that the default fromutc() is strong enough to handle -# "almost all" time zones: so long as the standard offset is invariant, it -# doesn't matter if daylight time transition points change from year to year, or -# if daylight time is skipped in some years; it doesn't matter how large or -# small dst() may get within its bounds; and it doesn't even matter if some -# perverse time zone returns a negative dst()). So a breaking case must be -# pretty bizarre, and a tzinfo subclass can override fromutc() if it is. +Now some derived rules, where k is a duration (timedelta). +1. x.o = x.s + x.d + This follows from the definition of x.s. + +2. If x and y have the same tzinfo member, x.s = y.s. + This is actually a requirement, an assumption we need to make about + sane tzinfo classes. + +3. The naive UTC time corresponding to x is x.n - x.o. + This is again a requirement for a sane tzinfo class. + +4. (x+k).s = x.s + This follows from #2, and that datimetimetz+timedelta preserves tzinfo. + +5. (x+k).n = x.n + k + Again follows from how arithmetic is defined. + +Now we can explain tz.fromutc(x). Let's assume it's an interesting case +(meaning that the various tzinfo methods exist, and don't blow up or return +None when called). + +The function wants to return a datetime y with timezone tz, equivalent to x. +x is already in UTC. + +By #3, we want + + y.n - y.o = x.n [1] + +The algorithm starts by attaching tz to x.n, and calling that y. So +x.n = y.n at the start. Then it wants to add a duration k to y, so that [1] +becomes true; in effect, we want to solve [2] for k: + + (y+k).n - (y+k).o = x.n [2] + +By #1, this is the same as + + (y+k).n - ((y+k).s + (y+k).d) = x.n [3] + +By #5, (y+k).n = y.n + k, which equals x.n + k because x.n=y.n at the start. +Substituting that into [3], + + x.n + k - (y+k).s - (y+k).d = x.n; the x.n terms cancel, leaving + k - (y+k).s - (y+k).d = 0; rearranging, + k = (y+k).s - (y+k).d; by #4, (y+k).s == y.s, so + k = y.s - (y+k).d + +On the RHS, (y+k).d can't be computed directly, but y.s can be, and we +approximate k by ignoring the (y+k).d term at first. Note that k can't be +very large, since all offset-returning methods return a duration of magnitude +less than 24 hours. For that reason, if y is firmly in std time, (y+k).d must +be 0, so ignoring it has no consequence then. + +In any case, the new value is + + z = y + y.s [4] + +It's helpful to step back at look at [4] from a higher level: it's simply +mapping from UTC to tz's standard time. + +At this point, if + + z.n - z.o = x.n [5] + +we have an equivalent time, and are almost done. The insecurity here is +at the start of daylight time. Picture US Eastern for concreteness. The wall +time jumps from 1:59 to 3:00, and wall hours of the form 2:MM don't make good +sense then. The docs ask that an Eastern tzinfo class consider such a time to +be EDT (because it's "after 2"), which is a redundant spelling of 1:MM EST +on the day DST starts. We want to return the 1:MM EST spelling because that's +the only spelling that makes sense on the local wall clock. + +In fact, if [5] holds at this point, we do have the standard-time spelling, +but that takes a bit of proof. We first prove a stronger result. What's the +difference between the LHS and RHS of [5]? Let + + diff = x.n - (z.n - z.o) [6] + +Now + z.n = by [4] + (y + y.s).n = by #5 + y.n + y.s = since y.n = x.n + x.n + y.s = since z and y are have the same tzinfo member, + y.s = z.s by #2 + x.n + z.s + +Plugging that back into [6] gives + + diff = + x.n - ((x.n + z.s) - z.o) = expanding + x.n - x.n - z.s + z.o = cancelling + - z.s + z.o = by #2 + z.d + +So diff = z.d. + +If [5] is true now, diff = 0, so z.d = 0 too, and we have the standard-time +spelling we wanted in the endcase described above. We're done. Contrarily, +if z.d = 0, then we have a UTC equivalent, and are also done. + +If [5] is not true now, diff = z.d != 0, and z.d is the offset we need to +add to z (in effect, z is in tz's standard time, and we need to shift the +local clock into tz's daylight time). + +Let + + z' = z + z.d = z + diff [7] + +and we can again ask whether + + z'.n - z'.o = x.n [8] + +If so, we're done. If not, the tzinfo class is insane, according to the +assumptions we've made. This also requires a bit of proof. As before, let's +compute the difference between the LHS and RHS of [8] (and skipping some of +the justifications for the kinds of substitutions we've done several times +already): + + diff' = x.n - (z'.n - z'.o) = replacing z'.n via [7] + x.n - (z.n + diff - z'.o) = replacing diff via [6] + x.n - (z.n + x.n - (z.n - z.o) - z'.o) = + x.n - z.n - x.n + z.n - z.o + z'.o = cancel x.n + - z.n + z.n - z.o + z'.o = cancel z.n + - z.o + z'.o = #1 twice + -z.s - z.d + z'.s + z'.d = z and z' have same tzinfo + z'.d - z.d + +So z' is UTC-equivalent to x iff z'.d = z.d at this point. If they are equal, +we've found the UTC-equivalent so are done. In fact, we stop with [7] and +return z', not bothering to compute z'.d. + +How could z.d and z'd differ? z' = z + z.d [7], so merely moving z' by +a dst() offset, and starting *from* a time already in DST (we know z.d != 0), +would have to change the result dst() returns: we start in DST, and moving +a little further into it takes us out of DST. + +There isn't a sane case where this can happen. The closest it gets is at +the end of DST, where there's an hour in UTC with no spelling in a hybrid +tzinfo class. In US Eastern, that's 5:MM UTC = 0:MM EST = 1:MM EDT. During +that hour, on an Eastern clock 1:MM is taken as being in standard time (6:MM +UTC) because the docs insist on that, but 0:MM is taken as being in daylight +time (4:MM UTC). There is no local time mapping to 5:MM UTC. The local +clock jumps from 1:59 back to 1:00 again, and repeats the 1:MM hour in +standard time. Since that's what the local clock *does*, we want to map both +UTC hours 5:MM and 6:MM to 1:MM Eastern. The result is ambiguous +in local time, but so it goes -- it's the way the local clock works. + +When x = 5:MM UTC is the input to this algorithm, x.o=0, y.o=-5 and y.d=0, +so z=0:MM. z.d=60 (minutes) then, so [5] doesn't hold and we keep going. +z' = z + z.d = 1:MM then, and z'.d=0, and z'.d - z.d = -60 != 0 so [8] +(correctly) concludes that z' is not UTC-equivalent to x. + +Because we know z.d said z was in daylight time (else [5] would have held and +we would have stopped then), and we know z.d != z'.d (else [8] would have held +and we have stopped then), and there are only 2 possible values dst() can +return in Eastern, it follows that z'.d must be 0 (which it is in the example, +but the reasoning doesn't depend on the example -- it depends on there being +two possible dst() outcomes, one zero and the other non-zero). Therefore +z' must be in standard time, and is the spelling we want in this case. + +Note again that z' is not UTC-equivalent as far as the hybrid tzinfo class is +concerned (because it takes z' as being in standard time rather than the +daylight time we intend here), but returning it gives the real-life "local +clock repeats an hour" behavior when mapping the "unspellable" UTC hour into +tz. + +When the input is 6:MM, z=1:MM and z.d=0, and we stop at once, again with +the 1:MM standard time spelling we want. + +So how can this break? One of the assumptions must be violated. Two +possibilities: + +1) [2] effectively says that y.s is invariant across all y belong to a given + time zone. This isn't true if, for political reasons or continental drift, + a region decides to change its base offset from UTC. + +2) There may be versions of "double daylight" time where the tail end of + the analysis gives up a step too early. I haven't thought about that + enough to say. + +In any case, it's clear that the default fromutc() is strong enough to handle +"almost all" time zones: so long as the standard offset is invariant, it +doesn't matter if daylight time transition points change from year to year, or +if daylight time is skipped in some years; it doesn't matter how large or +small dst() may get within its bounds; and it doesn't even matter if some +perverse time zone returns a negative dst()). So a breaking case must be +pretty bizarre, and a tzinfo subclass can override fromutc() if it is. +""" try: from _datetime import * except ImportError: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/dbm/__init__.py --- a/Lib/dbm/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/dbm/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -44,11 +44,6 @@ error = (error, OSError) -try: - from dbm import ndbm -except ImportError: - ndbm = None - def open(file, flag='r', mode=0o666): """Open or create database at path given by *file*. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/decimal.py --- a/Lib/decimal.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/decimal.py Fri Feb 01 23:12:09 2013 +0100 @@ -6138,7 +6138,7 @@ (?:\.(?P0|(?!0)\d+))? (?P[eEfFgGn%])? \Z -""", re.VERBOSE|re.DOTALL) +""", re.VERBOSE) del re diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/difflib.py --- a/Lib/difflib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/difflib.py Fri Feb 01 23:12:09 2013 +0100 @@ -336,6 +336,20 @@ for elt in popular: # ditto; as fast for 1% deletion del b2j[elt] + def isbjunk(self, item): + "Deprecated; use 'item in SequenceMatcher().bjunk'." + warnings.warn("'SequenceMatcher().isbjunk(item)' is deprecated;\n" + "use 'item in SMinstance.bjunk' instead.", + DeprecationWarning, 2) + return item in self.bjunk + + def isbpopular(self, item): + "Deprecated; use 'item in SequenceMatcher().bpopular'." + warnings.warn("'SequenceMatcher().isbpopular(item)' is deprecated;\n" + "use 'item in SMinstance.bpopular' instead.", + DeprecationWarning, 2) + return item in self.bpopular + def find_longest_match(self, alo, ahi, blo, bhi): """Find longest matching block in a[alo:ahi] and b[blo:bhi]. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/dis.py --- a/Lib/dis.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/dis.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,14 +2,12 @@ import sys import types -import collections from opcode import * from opcode import __all__ as _opcodes_all __all__ = ["code_info", "dis", "disassemble", "distb", "disco", - "findlinestarts", "findlabels", "show_code", - "get_instructions", "Instruction", "Bytecode"] + _opcodes_all + "findlinestarts", "findlabels", "show_code"] + _opcodes_all del _opcodes_all _have_code = (types.MethodType, types.FunctionType, types.CodeType, type) @@ -27,7 +25,7 @@ c = compile(source, name, 'exec') return c -def dis(x=None, *, file=None): +def dis(x=None): """Disassemble classes, methods, functions, or code. With no argument, disassemble the last traceback. @@ -44,23 +42,23 @@ items = sorted(x.__dict__.items()) for name, x1 in items: if isinstance(x1, _have_code): - print("Disassembly of %s:" % name, file=file) + print("Disassembly of %s:" % name) try: dis(x1) except TypeError as msg: - print("Sorry:", msg, file=file) - print(file=file) + print("Sorry:", msg) + print() elif hasattr(x, 'co_code'): # Code object - disassemble(x, file=file) + disassemble(x) elif isinstance(x, (bytes, bytearray)): # Raw bytecode - _disassemble_bytes(x, file=file) + _disassemble_bytes(x) elif isinstance(x, str): # Source code - _disassemble_str(x, file=file) + _disassemble_str(x) else: raise TypeError("don't know how to disassemble %s objects" % type(x).__name__) -def distb(tb=None, *, file=None): +def distb(tb=None): """Disassemble a traceback (default: last traceback).""" if tb is None: try: @@ -68,7 +66,7 @@ except AttributeError: raise RuntimeError("no last traceback to disassemble") while tb.tb_next: tb = tb.tb_next - disassemble(tb.tb_frame.f_code, tb.tb_lasti, file=file) + disassemble(tb.tb_frame.f_code, tb.tb_lasti) # The inspect module interrogates this dictionary to build its # list of CO_* constants. It is also used by pretty_flags to @@ -97,22 +95,19 @@ names.append(hex(flags)) return ", ".join(names) -def _get_code_object(x): - """Helper to handle methods, functions, strings and raw code objects""" +def code_info(x): + """Formatted details of methods, functions, or code.""" if hasattr(x, '__func__'): # Method x = x.__func__ if hasattr(x, '__code__'): # Function x = x.__code__ if isinstance(x, str): # Source code - x = _try_compile(x, "") + x = _try_compile(x, "") if hasattr(x, 'co_code'): # Code object - return x - raise TypeError("don't know how to disassemble %s objects" % - type(x).__name__) - -def code_info(x): - """Formatted details of methods, functions, or code.""" - return _format_code_info(_get_code_object(x)) + return _format_code_info(x) + else: + raise TypeError("don't know how to disassemble %s objects" % + type(x).__name__) def _format_code_info(co): lines = [] @@ -145,196 +140,106 @@ lines.append("%4d: %s" % i_n) return "\n".join(lines) -def show_code(co, *, file=None): +def show_code(co): """Print details of methods, functions, or code to stdout.""" - print(code_info(co), file=file) + print(code_info(co)) -_Instruction = collections.namedtuple("_Instruction", - "opname opcode arg argval argrepr offset starts_line is_jump_target") +def disassemble(co, lasti=-1): + """Disassemble a code object.""" + code = co.co_code + labels = findlabels(code) + linestarts = dict(findlinestarts(co)) + n = len(code) + i = 0 + extended_arg = 0 + free = None + while i < n: + op = code[i] + if i in linestarts: + if i > 0: + print() + print("%3d" % linestarts[i], end=' ') + else: + print(' ', end=' ') -class Instruction(_Instruction): - """Details for a bytecode operation + if i == lasti: print('-->', end=' ') + else: print(' ', end=' ') + if i in labels: print('>>', end=' ') + else: print(' ', end=' ') + print(repr(i).rjust(4), end=' ') + print(opname[op].ljust(20), end=' ') + i = i+1 + if op >= HAVE_ARGUMENT: + oparg = code[i] + code[i+1]*256 + extended_arg + extended_arg = 0 + i = i+2 + if op == EXTENDED_ARG: + extended_arg = oparg*65536 + print(repr(oparg).rjust(5), end=' ') + if op in hasconst: + print('(' + repr(co.co_consts[oparg]) + ')', end=' ') + elif op in hasname: + print('(' + co.co_names[oparg] + ')', end=' ') + elif op in hasjrel: + print('(to ' + repr(i + oparg) + ')', end=' ') + elif op in haslocal: + print('(' + co.co_varnames[oparg] + ')', end=' ') + elif op in hascompare: + print('(' + cmp_op[oparg] + ')', end=' ') + elif op in hasfree: + if free is None: + free = co.co_cellvars + co.co_freevars + print('(' + free[oparg] + ')', end=' ') + elif op in hasnargs: + print('(%d positional, %d keyword pair)' + % (code[i-2], code[i-1]), end=' ') + print() - Defined fields: - opname - human readable name for operation - opcode - numeric code for operation - arg - numeric argument to operation (if any), otherwise None - argval - resolved arg value (if known), otherwise same as arg - argrepr - human readable description of operation argument - offset - start index of operation within bytecode sequence - starts_line - line started by this opcode (if any), otherwise None - is_jump_target - True if other code jumps to here, otherwise False - """ - - def _disassemble(self, lineno_width=3, mark_as_current=False): - """Format instruction details for inclusion in disassembly output - - *lineno_width* sets the width of the line number field (0 omits it) - *mark_as_current* inserts a '-->' marker arrow as part of the line - """ - fields = [] - # Column: Source code line number - if lineno_width: - if self.starts_line is not None: - lineno_fmt = "%%%dd" % lineno_width - fields.append(lineno_fmt % self.starts_line) - else: - fields.append(' ' * lineno_width) - # Column: Current instruction indicator - if mark_as_current: - fields.append('-->') - else: - fields.append(' ') - # Column: Jump target marker - if self.is_jump_target: - fields.append('>>') - else: - fields.append(' ') - # Column: Instruction offset from start of code sequence - fields.append(repr(self.offset).rjust(4)) - # Column: Opcode name - fields.append(self.opname.ljust(20)) - # Column: Opcode argument - if self.arg is not None: - fields.append(repr(self.arg).rjust(5)) - # Column: Opcode argument details - if self.argrepr: - fields.append('(' + self.argrepr + ')') - return ' '.join(fields) - - -def get_instructions(x, *, line_offset=0): - """Iterator for the opcodes in methods, functions or code - - Generates a series of Instruction named tuples giving the details of - each operations in the supplied code. - - The given line offset is added to the 'starts_line' attribute of any - instructions that start a new line. - """ - co = _get_code_object(x) - cell_names = co.co_cellvars + co.co_freevars - linestarts = dict(findlinestarts(co)) - return _get_instructions_bytes(co.co_code, co.co_varnames, co.co_names, - co.co_consts, cell_names, linestarts, - line_offset) - -def _get_const_info(const_index, const_list): - """Helper to get optional details about const references - - Returns the dereferenced constant and its repr if the constant - list is defined. - Otherwise returns the constant index and its repr(). - """ - argval = const_index - if const_list is not None: - argval = const_list[const_index] - return argval, repr(argval) - -def _get_name_info(name_index, name_list): - """Helper to get optional details about named references - - Returns the dereferenced name as both value and repr if the name - list is defined. - Otherwise returns the name index and its repr(). - """ - argval = name_index - if name_list is not None: - argval = name_list[name_index] - argrepr = argval - else: - argrepr = repr(argval) - return argval, argrepr - - -def _get_instructions_bytes(code, varnames=None, names=None, constants=None, - cells=None, linestarts=None, line_offset=0): - """Iterate over the instructions in a bytecode string. - - Generates a sequence of Instruction namedtuples giving the details of each - opcode. Additional information about the code's runtime environment - (e.g. variable names, constants) can be specified using optional - arguments. - - """ +def _disassemble_bytes(code, lasti=-1, varnames=None, names=None, + constants=None): labels = findlabels(code) - extended_arg = 0 - starts_line = None - free = None - # enumerate() is not an option, since we sometimes process - # multiple elements on a single pass through the loop n = len(code) i = 0 while i < n: op = code[i] - offset = i - if linestarts is not None: - starts_line = linestarts.get(i, None) - if starts_line is not None: - starts_line += line_offset - is_jump_target = i in labels + if i == lasti: print('-->', end=' ') + else: print(' ', end=' ') + if i in labels: print('>>', end=' ') + else: print(' ', end=' ') + print(repr(i).rjust(4), end=' ') + print(opname[op].ljust(15), end=' ') i = i+1 - arg = None - argval = None - argrepr = '' if op >= HAVE_ARGUMENT: - arg = code[i] + code[i+1]*256 + extended_arg - extended_arg = 0 + oparg = code[i] + code[i+1]*256 i = i+2 - if op == EXTENDED_ARG: - extended_arg = arg*65536 - # Set argval to the dereferenced value of the argument when - # availabe, and argrepr to the string representation of argval. - # _disassemble_bytes needs the string repr of the - # raw name index for LOAD_GLOBAL, LOAD_CONST, etc. - argval = arg + print(repr(oparg).rjust(5), end=' ') if op in hasconst: - argval, argrepr = _get_const_info(arg, constants) + if constants: + print('(' + repr(constants[oparg]) + ')', end=' ') + else: + print('(%d)'%oparg, end=' ') elif op in hasname: - argval, argrepr = _get_name_info(arg, names) + if names is not None: + print('(' + names[oparg] + ')', end=' ') + else: + print('(%d)'%oparg, end=' ') elif op in hasjrel: - argval = i + arg - argrepr = "to " + repr(argval) + print('(to ' + repr(i + oparg) + ')', end=' ') elif op in haslocal: - argval, argrepr = _get_name_info(arg, varnames) + if varnames: + print('(' + varnames[oparg] + ')', end=' ') + else: + print('(%d)' % oparg, end=' ') elif op in hascompare: - argval = cmp_op[arg] - argrepr = argval - elif op in hasfree: - argval, argrepr = _get_name_info(arg, cells) + print('(' + cmp_op[oparg] + ')', end=' ') elif op in hasnargs: - argrepr = "%d positional, %d keyword pair" % (code[i-2], code[i-1]) - yield Instruction(opname[op], op, - arg, argval, argrepr, - offset, starts_line, is_jump_target) + print('(%d positional, %d keyword pair)' + % (code[i-2], code[i-1]), end=' ') + print() -def disassemble(co, lasti=-1, *, file=None): - """Disassemble a code object.""" - cell_names = co.co_cellvars + co.co_freevars - linestarts = dict(findlinestarts(co)) - _disassemble_bytes(co.co_code, lasti, co.co_varnames, co.co_names, - co.co_consts, cell_names, linestarts, file=file) - -def _disassemble_bytes(code, lasti=-1, varnames=None, names=None, - constants=None, cells=None, linestarts=None, - *, file=None): - # Omit the line number column entirely if we have no line number info - show_lineno = linestarts is not None - # TODO?: Adjust width upwards if max(linestarts.values()) >= 1000? - lineno_width = 3 if show_lineno else 0 - for instr in _get_instructions_bytes(code, varnames, names, - constants, cells, linestarts): - new_source_line = (show_lineno and - instr.starts_line is not None and - instr.offset > 0) - if new_source_line: - print(file=file) - is_current_instr = instr.offset == lasti - print(instr._disassemble(lineno_width, is_current_instr), file=file) - -def _disassemble_str(source, *, file=None): +def _disassemble_str(source): """Compile the source string, then disassemble the code object.""" - disassemble(_try_compile(source, ''), file=file) + disassemble(_try_compile(source, '')) disco = disassemble # XXX For backwards compatibility @@ -345,21 +250,19 @@ """ labels = [] - # enumerate() is not an option, since we sometimes process - # multiple elements on a single pass through the loop n = len(code) i = 0 while i < n: op = code[i] i = i+1 if op >= HAVE_ARGUMENT: - arg = code[i] + code[i+1]*256 + oparg = code[i] + code[i+1]*256 i = i+2 label = -1 if op in hasjrel: - label = i+arg + label = i+oparg elif op in hasjabs: - label = arg + label = oparg if label >= 0: if label not in labels: labels.append(label) @@ -387,50 +290,6 @@ if lineno != lastlineno: yield (addr, lineno) -class Bytecode: - """The bytecode operations of a piece of code - - Instantiate this with a function, method, string of code, or a code object - (as returned by compile()). - - Iterating over this yields the bytecode operations as Instruction instances. - """ - def __init__(self, x): - self.codeobj = _get_code_object(x) - self.cell_names = self.codeobj.co_cellvars + self.codeobj.co_freevars - self.linestarts = dict(findlinestarts(self.codeobj)) - self.line_offset = 0 - self.original_object = x - - def __iter__(self): - co = self.codeobj - return _get_instructions_bytes(co.co_code, co.co_varnames, co.co_names, - co.co_consts, self.cell_names, - self.linestarts, self.line_offset) - - def __repr__(self): - return "{}({!r})".format(self.__class__.__name__, self.original_object) - - def info(self): - """Return formatted information about the code object.""" - return _format_code_info(self.codeobj) - - def show_info(self, *, file=None): - """Print the information about the code object as returned by info().""" - print(self.info(), file=file) - - def display_code(self, *, file=None): - """Print a formatted view of the bytecode operations. - """ - co = self.codeobj - return _disassemble_bytes(co.co_code, varnames=co.co_varnames, - names=co.co_names, constants=co.co_consts, - cells=self.cell_names, - linestarts=self.linestarts, - file=file - ) - - def _test(): """Simple test program to disassemble a file.""" if sys.argv[1:]: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/command/build_ext.py --- a/Lib/distutils/command/build_ext.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/command/build_ext.py Fri Feb 01 23:12:09 2013 +0100 @@ -666,10 +666,10 @@ from distutils.sysconfig import get_config_var ext_path = ext_name.split('.') # extensions in debug_mode are named 'module_d.pyd' under windows - ext_suffix = get_config_var('EXT_SUFFIX') + so_ext = get_config_var('SO') if os.name == 'nt' and self.debug: - return os.path.join(*ext_path) + '_d' + ext_suffix - return os.path.join(*ext_path) + ext_suffix + return os.path.join(*ext_path) + '_d' + so_ext + return os.path.join(*ext_path) + so_ext def get_export_symbols(self, ext): """Return the list of symbols that a shared extension has to diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/command/build_py.py --- a/Lib/distutils/command/build_py.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/command/build_py.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,7 @@ Implements the Distutils 'build_py' command.""" import os -import importlib.util +import imp import sys from glob import glob @@ -312,11 +312,11 @@ outputs.append(filename) if include_bytecode: if self.compile: - outputs.append(importlib.util.cache_from_source( - filename, debug_override=True)) + outputs.append(imp.cache_from_source(filename, + debug_override=True)) if self.optimize > 0: - outputs.append(importlib.util.cache_from_source( - filename, debug_override=False)) + outputs.append(imp.cache_from_source(filename, + debug_override=False)) outputs += [ os.path.join(build_dir, filename) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/command/install.py --- a/Lib/distutils/command/install.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/command/install.py Fri Feb 01 23:12:09 2013 +0100 @@ -263,8 +263,8 @@ if self.user and (self.prefix or self.exec_prefix or self.home or self.install_base or self.install_platbase): - raise DistutilsOptionError("can't combine user with prefix, " - "exec_prefix/home, or install_(plat)base") + raise DistutilsOptionError("can't combine user with with prefix/" + "exec_prefix/home or install_(plat)base") # Next, stuff that's wrong (or dubious) only on certain platforms. if os.name != "posix": diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/command/install_lib.py --- a/Lib/distutils/command/install_lib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/command/install_lib.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,7 +4,7 @@ (install all Python modules).""" import os -import importlib.util +import imp import sys from distutils.core import Command @@ -165,10 +165,10 @@ if ext != PYTHON_SOURCE_EXTENSION: continue if self.compile: - bytecode_files.append(importlib.util.cache_from_source( + bytecode_files.append(imp.cache_from_source( py_file, debug_override=True)) if self.optimize > 0: - bytecode_files.append(importlib.util.cache_from_source( + bytecode_files.append(imp.cache_from_source( py_file, debug_override=False)) return bytecode_files diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/config.py --- a/Lib/distutils/config.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/config.py Fri Feb 01 23:12:09 2013 +0100 @@ -21,7 +21,7 @@ class PyPIRCCommand(Command): """Base command that knows how to handle the .pypirc file """ - DEFAULT_REPOSITORY = 'https://pypi.python.org/pypi' + DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi' DEFAULT_REALM = 'pypi' repository = None realm = None @@ -83,15 +83,6 @@ current[key] = config.get(server, key) else: current[key] = default - - # work around people having "repository" for the "pypi" - # section of their config set to the HTTP (rather than - # HTTPS) URL - if (server == 'pypi' and - repository in (self.DEFAULT_REPOSITORY, 'pypi')): - current['repository'] = self.DEFAULT_REPOSITORY - return current - if (current['server'] == repository or current['repository'] == repository): return current diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/dist.py --- a/Lib/distutils/dist.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/dist.py Fri Feb 01 23:12:09 2013 +0100 @@ -343,18 +343,6 @@ def parse_config_files(self, filenames=None): from configparser import ConfigParser - # Ignore install directory options if we have a venv - if sys.prefix != sys.base_prefix: - ignore_options = [ - 'install-base', 'install-platbase', 'install-lib', - 'install-platlib', 'install-purelib', 'install-headers', - 'install-scripts', 'install-data', 'prefix', 'exec-prefix', - 'home', 'user', 'root'] - else: - ignore_options = [] - - ignore_options = frozenset(ignore_options) - if filenames is None: filenames = self.find_config_files() @@ -371,7 +359,7 @@ opt_dict = self.get_option_dict(section) for opt in options: - if opt != '__name__' and opt not in ignore_options: + if opt != '__name__': val = parser.get(section,opt) opt = opt.replace('-', '_') opt_dict[opt] = (filename, val) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/sysconfig.py Fri Feb 01 23:12:09 2013 +0100 @@ -24,11 +24,7 @@ # Path to the base directory of the project. On Windows the binary may # live in project/PCBuild9. If we're dealing with an x64 Windows build, # it'll live in project/PCbuild/amd64. -# set for cross builds -if "_PYTHON_PROJECT_BASE" in os.environ: - project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"]) -else: - project_base = os.path.dirname(os.path.abspath(sys.executable)) +project_base = os.path.dirname(os.path.abspath(sys.executable)) if os.name == "nt" and "pcbuild" in project_base[-8:].lower(): project_base = os.path.abspath(os.path.join(project_base, os.path.pardir)) # PC/VS7.1 @@ -102,7 +98,7 @@ # the build directory may not be the source directory, we # must use "srcdir" from the makefile to find the "Include" # directory. - base = _sys_home or project_base + base = _sys_home or os.path.dirname(os.path.abspath(sys.executable)) if plat_specific: return base if _sys_home: @@ -184,19 +180,13 @@ _osx_support.customize_compiler(_config_vars) _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' - (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \ + (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', - 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') + 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS') + newcc = None if 'CC' in os.environ: - newcc = os.environ['CC'] - if (sys.platform == 'darwin' - and 'LDSHARED' not in os.environ - and ldshared.startswith(cc)): - # On OS X, if CC is overridden, use that as the default - # command for LDSHARED as well - ldshared = newcc + ldshared[len(cc):] - cc = newcc + cc = os.environ['CC'] if 'CXX' in os.environ: cxx = os.environ['CXX'] if 'LDSHARED' in os.environ: @@ -231,7 +221,7 @@ linker_exe=cc, archiver=archiver) - compiler.shared_lib_extension = shlib_suffix + compiler.shared_lib_extension = so_ext def get_config_h_filename(): @@ -254,7 +244,8 @@ def get_makefile_filename(): """Return full pathname of installed Makefile from the Python build.""" if python_build: - return os.path.join(_sys_home or project_base, "Makefile") + return os.path.join(_sys_home or os.path.dirname(sys.executable), + "Makefile") lib_dir = get_python_lib(plat_specific=0, standard_lib=1) config_file = 'config-{}{}'.format(get_python_version(), build_flags) return os.path.join(lib_dir, config_file, 'Makefile') @@ -485,7 +476,7 @@ # XXX hmmm.. a normal install puts include files here g['INCLUDEPY'] = get_python_inc(plat_specific=0) - g['EXT_SUFFIX'] = '.pyd' + g['SO'] = '.pyd' g['EXE'] = ".exe" g['VERSION'] = get_python_version().replace(".", "") g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable)) @@ -540,7 +531,7 @@ # testing, for example, we might be running a non-installed python # from a different directory. if python_build and os.name == "posix": - base = project_base + base = os.path.dirname(os.path.abspath(sys.executable)) if (not os.path.isabs(_config_vars['srcdir']) and base != os.getcwd()): # srcdir is relative and we are not in the same directory diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_bdist_dumb.py --- a/Lib/distutils/tests/test_bdist_dumb.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_bdist_dumb.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,7 @@ """Tests for distutils.command.bdist_dumb.""" import os +import imp import sys import zipfile import unittest @@ -85,9 +86,9 @@ fp.close() contents = sorted(os.path.basename(fn) for fn in contents) - wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py'] - if not sys.dont_write_bytecode: - wanted.append('foo.%s.pyc' % sys.implementation.cache_tag) + wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], + 'foo.%s.pyc' % imp.get_tag(), + 'foo.py'] self.assertEqual(contents, sorted(wanted)) def test_suite(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_build_ext.py --- a/Lib/distutils/tests/test_build_ext.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_build_ext.py Fri Feb 01 23:12:09 2013 +0100 @@ -73,9 +73,8 @@ self.assertEqual(xx.foo(2, 5), 7) self.assertEqual(xx.foo(13,15), 28) self.assertEqual(xx.new().demo(), None) - if support.HAVE_DOCSTRINGS: - doc = 'This is a template module just for instruction.' - self.assertEqual(xx.__doc__, doc) + doc = 'This is a template module just for instruction.' + self.assertEqual(xx.__doc__, doc) self.assertTrue(isinstance(xx.Null(), xx.Null)) self.assertTrue(isinstance(xx.Str(), xx.Str)) @@ -318,8 +317,8 @@ finally: os.chdir(old_wd) self.assertTrue(os.path.exists(so_file)) - ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') - self.assertTrue(so_file.endswith(ext_suffix)) + so_ext = sysconfig.get_config_var('SO') + self.assertTrue(so_file.endswith(so_ext)) so_dir = os.path.dirname(so_file) self.assertEqual(so_dir, other_tmp_dir) @@ -328,7 +327,7 @@ cmd.run() so_file = cmd.get_outputs()[0] self.assertTrue(os.path.exists(so_file)) - self.assertTrue(so_file.endswith(ext_suffix)) + self.assertTrue(so_file.endswith(so_ext)) so_dir = os.path.dirname(so_file) self.assertEqual(so_dir, cmd.build_lib) @@ -355,7 +354,7 @@ self.assertEqual(lastdir, 'bar') def test_ext_fullpath(self): - ext = sysconfig.get_config_var('EXT_SUFFIX') + ext = sysconfig.get_config_vars()['SO'] # building lxml.etree inplace #etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c') #etree_ext = Extension('lxml.etree', [etree_c]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_build_py.py --- a/Lib/distutils/tests/test_build_py.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_build_py.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,7 @@ import os import sys +import imp import unittest from distutils.command.build_py import build_py @@ -62,8 +63,7 @@ self.assertFalse(os.path.exists(pycache_dir)) else: pyc_files = os.listdir(pycache_dir) - self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag, - pyc_files) + self.assertIn("__init__.%s.pyc" % imp.get_tag(), pyc_files) def test_empty_package_dir(self): # See bugs #1668596/#1720897 @@ -102,8 +102,7 @@ found = os.listdir(cmd.build_lib) self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py']) found = os.listdir(os.path.join(cmd.build_lib, '__pycache__')) - self.assertEqual(found, - ['boiledeggs.%s.pyc' % sys.implementation.cache_tag]) + self.assertEqual(found, ['boiledeggs.%s.pyc' % imp.get_tag()]) @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled') def test_byte_compile_optimized(self): @@ -120,8 +119,7 @@ found = os.listdir(cmd.build_lib) self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py']) found = os.listdir(os.path.join(cmd.build_lib, '__pycache__')) - self.assertEqual(sorted(found), - ['boiledeggs.%s.pyo' % sys.implementation.cache_tag]) + self.assertEqual(sorted(found), ['boiledeggs.%s.pyo' % imp.get_tag()]) def test_dont_write_bytecode(self): # makes sure byte_compile is not used diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_config.py --- a/Lib/distutils/tests/test_config.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_config.py Fri Feb 01 23:12:09 2013 +0100 @@ -87,7 +87,7 @@ config = list(sorted(config.items())) waited = [('password', 'secret'), ('realm', 'pypi'), - ('repository', 'https://pypi.python.org/pypi'), + ('repository', 'http://pypi.python.org/pypi'), ('server', 'server1'), ('username', 'me')] self.assertEqual(config, waited) @@ -96,7 +96,7 @@ config = cmd._read_pypirc() config = list(sorted(config.items())) waited = [('password', 'secret'), ('realm', 'pypi'), - ('repository', 'https://pypi.python.org/pypi'), + ('repository', 'http://pypi.python.org/pypi'), ('server', 'server-login'), ('username', 'tarek')] self.assertEqual(config, waited) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_dist.py --- a/Lib/distutils/tests/test_dist.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_dist.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,8 +6,6 @@ import warnings import textwrap -from unittest import mock - from distutils.dist import Distribution, fix_help_options from distutils.cmd import Command @@ -20,7 +18,7 @@ user_options = [ ("sample-option=", "S", "help text"), - ] + ] def initialize_options(self): self.sample_option = None @@ -79,64 +77,6 @@ self.assertIsInstance(cmd, test_dist) self.assertEqual(cmd.sample_option, "sometext") - def test_venv_install_options(self): - sys.argv.append("install") - self.addCleanup(os.unlink, TESTFN) - - fakepath = '/somedir' - - with open(TESTFN, "w") as f: - print(("[install]\n" - "install-base = {0}\n" - "install-platbase = {0}\n" - "install-lib = {0}\n" - "install-platlib = {0}\n" - "install-purelib = {0}\n" - "install-headers = {0}\n" - "install-scripts = {0}\n" - "install-data = {0}\n" - "prefix = {0}\n" - "exec-prefix = {0}\n" - "home = {0}\n" - "user = {0}\n" - "root = {0}").format(fakepath), file=f) - - # Base case: Not in a Virtual Environment - with mock.patch.multiple(sys, prefix='/a', base_prefix='/a') as values: - d = self.create_distribution([TESTFN]) - - option_tuple = (TESTFN, fakepath) - - result_dict = { - 'install_base': option_tuple, - 'install_platbase': option_tuple, - 'install_lib': option_tuple, - 'install_platlib': option_tuple, - 'install_purelib': option_tuple, - 'install_headers': option_tuple, - 'install_scripts': option_tuple, - 'install_data': option_tuple, - 'prefix': option_tuple, - 'exec_prefix': option_tuple, - 'home': option_tuple, - 'user': option_tuple, - 'root': option_tuple, - } - - self.assertEqual( - sorted(d.command_options.get('install').keys()), - sorted(result_dict.keys())) - - for (key, value) in d.command_options.get('install').items(): - self.assertEqual(value, result_dict[key]) - - # Test case: In a Virtual Environment - with mock.patch.multiple(sys, prefix='/a', base_prefix='/b') as values: - d = self.create_distribution([TESTFN]) - - for key in result_dict.keys(): - self.assertNotIn(key, d.command_options.get('install', {})) - def test_command_packages_configfile(self): sys.argv.append("build") self.addCleanup(os.unlink, TESTFN) @@ -364,7 +304,7 @@ os.environ['HOME'] = temp_dir files = dist.find_config_files() self.assertIn(user_filename, files, - '%r not found in %r' % (user_filename, files)) + '%r not found in %r' % (user_filename, files)) finally: os.remove(user_filename) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_install.py --- a/Lib/distutils/tests/test_install.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_install.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,7 @@ """Tests for distutils.command.install.""" import os +import imp import sys import unittest import site @@ -22,7 +23,7 @@ def _make_ext_name(modname): if os.name == 'nt' and sys.executable.endswith('_d.exe'): modname += '_d' - return modname + sysconfig.get_config_var('EXT_SUFFIX') + return modname + sysconfig.get_config_var('SO') class InstallTestCase(support.TempdirManager, @@ -164,7 +165,7 @@ cmd.home = 'home' self.assertRaises(DistutilsOptionError, cmd.finalize_options) - # can't combine user with prefix/exec_prefix/home or + # can't combine user with with prefix/exec_prefix/home or # install_(plat)base cmd.prefix = None cmd.user = 'user' @@ -192,8 +193,7 @@ f.close() found = [os.path.basename(line) for line in content.splitlines()] - expected = ['hello.py', 'hello.%s.pyc' % sys.implementation.cache_tag, - 'sayhi', + expected = ['hello.py', 'hello.%s.pyc' % imp.get_tag(), 'sayhi', 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]] self.assertEqual(found, expected) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_install_lib.py --- a/Lib/distutils/tests/test_install_lib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_install_lib.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ """Tests for distutils.command.install_data.""" import sys import os -import importlib.util +import imp import unittest from distutils.command.install_lib import install_lib @@ -44,10 +44,8 @@ f = os.path.join(project_dir, 'foo.py') self.write_file(f, '# python file') cmd.byte_compile([f]) - pyc_file = importlib.util.cache_from_source('foo.py', - debug_override=True) - pyo_file = importlib.util.cache_from_source('foo.py', - debug_override=False) + pyc_file = imp.cache_from_source('foo.py', debug_override=True) + pyo_file = imp.cache_from_source('foo.py', debug_override=False) self.assertTrue(os.path.exists(pyc_file)) self.assertTrue(os.path.exists(pyo_file)) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_unixccompiler.py --- a/Lib/distutils/tests/test_unixccompiler.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_unixccompiler.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,7 @@ """Tests for distutils.unixccompiler.""" -import os import sys import unittest -from test.support import EnvironmentVarGuard, run_unittest +from test.support import run_unittest from distutils import sysconfig from distutils.unixccompiler import UnixCCompiler @@ -95,6 +94,7 @@ sysconfig.get_config_var = gcv self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo') + # non-GCC GNULD sys.platform = 'bar' def gcv(v): @@ -115,38 +115,6 @@ sysconfig.get_config_var = gcv self.assertEqual(self.cc.rpath_foo(), '-R/foo') - @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X') - def test_osx_cc_overrides_ldshared(self): - # Issue #18080: - # ensure that setting CC env variable also changes default linker - def gcv(v): - if v == 'LDSHARED': - return 'gcc-4.2 -bundle -undefined dynamic_lookup ' - return 'gcc-4.2' - sysconfig.get_config_var = gcv - with EnvironmentVarGuard() as env: - env['CC'] = 'my_cc' - del env['LDSHARED'] - sysconfig.customize_compiler(self.cc) - self.assertEqual(self.cc.linker_so[0], 'my_cc') - - @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X') - def test_osx_explict_ldshared(self): - # Issue #18080: - # ensure that setting CC env variable does not change - # explicit LDSHARED setting for linker - def gcv(v): - if v == 'LDSHARED': - return 'gcc-4.2 -bundle -undefined dynamic_lookup ' - return 'gcc-4.2' - sysconfig.get_config_var = gcv - with EnvironmentVarGuard() as env: - env['CC'] = 'my_cc' - env['LDSHARED'] = 'my_ld -bundle -dynamic' - sysconfig.customize_compiler(self.cc) - self.assertEqual(self.cc.linker_so[0], 'my_ld') - - def test_suite(): return unittest.makeSuite(UnixCCompilerTestCase) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/tests/test_upload.py --- a/Lib/distutils/tests/test_upload.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/tests/test_upload.py Fri Feb 01 23:12:09 2013 +0100 @@ -72,12 +72,12 @@ def setUp(self): super(uploadTestCase, self).setUp() - if hasattr(httpclient, 'HTTPSConnection'): - self.addCleanup(setattr, httpclient, 'HTTPSConnection', - httpclient.HTTPSConnection) - else: - self.addCleanup(delattr, httpclient, 'HTTPSConnection') - self.conn = httpclient.HTTPSConnection = FakeConnection() + self.old_class = httpclient.HTTPConnection + self.conn = httpclient.HTTPConnection = FakeConnection() + + def tearDown(self): + httpclient.HTTPConnection = self.old_class + super(uploadTestCase, self).tearDown() def test_finalize_options(self): @@ -88,7 +88,7 @@ cmd.finalize_options() for attr, waited in (('username', 'me'), ('password', 'secret'), ('realm', 'pypi'), - ('repository', 'https://pypi.python.org/pypi')): + ('repository', 'http://pypi.python.org/pypi')): self.assertEqual(getattr(cmd, attr), waited) def test_saved_password(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/distutils/util.py --- a/Lib/distutils/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/distutils/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,7 @@ import os import re -import importlib.util +import imp import sys import string from distutils.errors import DistutilsPlatformError @@ -453,10 +453,9 @@ # cfile - byte-compiled file # dfile - purported source filename (same as 'file' by default) if optimize >= 0: - cfile = importlib.util.cache_from_source( - file, debug_override=not optimize) + cfile = imp.cache_from_source(file, debug_override=not optimize) else: - cfile = importlib.util.cache_from_source(file) + cfile = imp.cache_from_source(file) dfile = file if prefix: if file[:len(prefix)] != prefix: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/doctest.py --- a/Lib/doctest.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/doctest.py Fri Feb 01 23:12:09 2013 +0100 @@ -93,7 +93,6 @@ ] import __future__ -import argparse import difflib import inspect import linecache @@ -216,7 +215,7 @@ if module_relative: package = _normalize_module(package, 3) filename = _module_relative_path(package, filename) - if getattr(package, '__loader__', None) is not None: + if hasattr(package, '__loader__'): if hasattr(package.__loader__, 'get_data'): file_contents = package.__loader__.get_data(filename) file_contents = file_contents.decode(encoding) @@ -2709,30 +2708,13 @@ def _test(): - parser = argparse.ArgumentParser(description="doctest runner") - parser.add_argument('-v', '--verbose', action='store_true', default=False, - help='print very verbose output for all tests') - parser.add_argument('-o', '--option', action='append', - choices=OPTIONFLAGS_BY_NAME.keys(), default=[], - help=('specify a doctest option flag to apply' - ' to the test run; may be specified more' - ' than once to apply multiple options')) - parser.add_argument('-f', '--fail-fast', action='store_true', - help=('stop running tests after first failure (this' - ' is a shorthand for -o FAIL_FAST, and is' - ' in addition to any other -o options)')) - parser.add_argument('file', nargs='+', - help='file containing the tests to run') - args = parser.parse_args() - testfiles = args.file - # Verbose used to be handled by the "inspect argv" magic in DocTestRunner, - # but since we are using argparse we are passing it manually now. - verbose = args.verbose - options = 0 - for option in args.option: - options |= OPTIONFLAGS_BY_NAME[option] - if args.fail_fast: - options |= FAIL_FAST + testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-'] + if not testfiles: + name = os.path.basename(sys.argv[0]) + if '__loader__' in globals(): # python -m + name, _ = os.path.splitext(name) + print("usage: {0} [-v] file ...".format(name)) + return 2 for filename in testfiles: if filename.endswith(".py"): # It is a module -- insert its dir into sys.path and try to @@ -2742,10 +2724,9 @@ sys.path.insert(0, dirname) m = __import__(filename[:-3]) del sys.path[0] - failures, _ = testmod(m, verbose=verbose, optionflags=options) + failures, _ = testmod(m) else: - failures, _ = testfile(filename, module_relative=False, - verbose=verbose, optionflags=options) + failures, _ = testfile(filename, module_relative=False) if failures: return 1 return 0 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/_encoded_words.py --- a/Lib/email/_encoded_words.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/_encoded_words.py Fri Feb 01 23:12:09 2013 +0100 @@ -14,7 +14,7 @@ # cte (Content Transfer Encoding) is either 'q' or 'b' (ignoring case). In # theory other letters could be used for other encodings, but in practice this # (almost?) never happens. There could be a public API for adding entries -# to the CTE tables, but YAGNI for now. 'q' is Quoted Printable, 'b' is +# to to the CTE tables, but YAGNI for now. 'q' is Quoted Printable, 'b' is # Base64. The meaning of encoded_string should be obvious. 'lang' is optional # as indicated by the brackets (they are not part of the syntax) but is almost # never encountered in practice. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/_header_value_parser.py --- a/Lib/email/_header_value_parser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/_header_value_parser.py Fri Feb 01 23:12:09 2013 +0100 @@ -69,7 +69,6 @@ import re import urllib # For urllib.parse.unquote -from string import hexdigits from collections import namedtuple, OrderedDict from email import _encoded_words as _ew from email import errors @@ -392,6 +391,10 @@ token_type = 'unstructured' def _fold(self, folded): + if any(x.token_type=='encoded-word' for x in self): + return self._fold_encoded(folded) + # Here we can have either a pure ASCII string that may or may not + # have surrogateescape encoded bytes, or a unicode string. last_ew = None for part in self.parts: tstr = str(part) @@ -1314,22 +1317,24 @@ # Parser # -# Parse strings according to RFC822/2047/2822/5322 rules. -# -# This is a stateless parser. Each get_XXX function accepts a string and -# returns either a Terminal or a TokenList representing the RFC object named -# by the method and a string containing the remaining unparsed characters -# from the input. Thus a parser method consumes the next syntactic construct -# of a given type and returns a token representing the construct plus the -# unparsed remainder of the input string. -# -# For example, if the first element of a structured header is a 'phrase', -# then: -# -# phrase, value = get_phrase(value) -# -# returns the complete phrase from the start of the string value, plus any -# characters left in the string after the phrase is removed. +"""Parse strings according to RFC822/2047/2822/5322 rules. + +This is a stateless parser. Each get_XXX function accepts a string and +returns either a Terminal or a TokenList representing the RFC object named +by the method and a string containing the remaining unparsed characters +from the input. Thus a parser method consumes the next syntactic construct +of a given type and returns a token representing the construct plus the +unparsed remainder of the input string. + +For example, if the first element of a structured header is a 'phrase', +then: + + phrase, value = get_phrase(value) + +returns the complete phrase from the start of the string value, plus any +characters left in the string after the phrase is removed. + +""" _wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split _non_atom_end_matcher = re.compile(r"[^{}]+".format( @@ -1383,6 +1388,35 @@ pos = pos + 1 return ''.join(vchars), ''.join([fragment[pos:]] + remainder), had_qp +def _decode_ew_run(value): + """ Decode a run of RFC2047 encoded words. + + _decode_ew_run(value) -> (text, value, defects) + + Scans the supplied value for a run of tokens that look like they are RFC + 2047 encoded words, decodes those words into text according to RFC 2047 + rules (whitespace between encoded words is discarded), and returns the text + and the remaining value (including any leading whitespace on the remaining + value), as well as a list of any defects encountered while decoding. The + input value may not have any leading whitespace. + + """ + res = [] + defects = [] + last_ws = '' + while value: + try: + tok, ws, value = _wsp_splitter(value, 1) + except ValueError: + tok, ws, value = value, '', '' + if not (tok.startswith('=?') and tok.endswith('?=')): + return ''.join(res), last_ws + tok + ws + value, defects + text, charset, lang, new_defects = _ew.decode(tok) + res.append(text) + defects.extend(new_defects) + last_ws = ws + return ''.join(res), last_ws, defects + def get_fws(value): """FWS = 1*WSP @@ -1408,8 +1442,7 @@ raise errors.HeaderParseError( "expected encoded word but found {}".format(value)) remstr = ''.join(remainder) - if len(remstr) > 1 and remstr[0] in hexdigits and remstr[1] in hexdigits: - # The ? after the CTE was followed by an encoded word escape (=XX). + if remstr[:2].isdigit(): rest, *remainder = remstr.split('?=', 1) tok = tok + '?=' + rest if len(tok.split()) > 1: @@ -1457,8 +1490,8 @@ """ # XXX: but what about bare CR and LF? They might signal the start or - # end of an encoded word. YAGNI for now, since our current parsers - # will never send us strings with bare CR or LF. + # end of an encoded word. YAGNI for now, since out current parsers + # will never send us strings with bard CR or LF. unstructured = UnstructuredTokenList() while value: @@ -1470,8 +1503,6 @@ try: token, value = get_encoded_word(value) except errors.HeaderParseError: - # XXX: Need to figure out how to register defects when - # appropriate here. pass else: have_ws = True @@ -1624,7 +1655,6 @@ def get_atom(value): """atom = [CFWS] 1*atext [CFWS] - An atom could be an rfc2047 encoded word. """ atom = Atom() if value and value[0] in CFWS_LEADER: @@ -1633,15 +1663,7 @@ if value and value[0] in ATOM_ENDS: raise errors.HeaderParseError( "expected atom but found '{}'".format(value)) - if value.startswith('=?'): - try: - token, value = get_encoded_word(value) - except errors.HeaderParseError: - # XXX: need to figure out how to register defects when - # appropriate here. - token, value = get_atext(value) - else: - token, value = get_atext(value) + token, value = get_atext(value) atom.append(token) if value and value[0] in CFWS_LEADER: token, value = get_cfws(value) @@ -1670,22 +1692,12 @@ def get_dot_atom(value): """ dot-atom = [CFWS] dot-atom-text [CFWS] - Any place we can have a dot atom, we could instead have an rfc2047 encoded - word. """ dot_atom = DotAtom() if value[0] in CFWS_LEADER: token, value = get_cfws(value) dot_atom.append(token) - if value.startswith('=?'): - try: - token, value = get_encoded_word(value) - except errors.HeaderParseError: - # XXX: need to figure out how to register defects when - # appropriate here. - token, value = get_dot_atom_text(value) - else: - token, value = get_dot_atom_text(value) + token, value = get_dot_atom_text(value) dot_atom.append(token) if value and value[0] in CFWS_LEADER: token, value = get_cfws(value) @@ -1851,7 +1863,7 @@ """ dtext = / obs-dtext obs-dtext = obs-NO-WS-CTL / quoted-pair - We allow anything except the excluded characters, but if we find any + We allow anything except the excluded characters, but but if we find any ASCII other than the RFC defined printable ASCII an NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/charset.py --- a/Lib/email/charset.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/charset.py Fri Feb 01 23:12:09 2013 +0100 @@ -194,7 +194,7 @@ header encoding. Charset.SHORTEST is not allowed for body_encoding. - output_charset: Some character sets must be converted before they can be + output_charset: Some character sets must be converted before the can be used in email headers or bodies. If the input_charset is one of them, this attribute will contain the name of the charset output will be converted to. Otherwise, it will @@ -392,19 +392,6 @@ string = string.encode(self.output_charset) return email.base64mime.body_encode(string) elif self.body_encoding is QP: - # quopromime.body_encode takes a string, but operates on it as if - # it were a list of byte codes. For a (minimal) history on why - # this is so, see changeset 0cf700464177. To correctly encode a - # character set, then, we must turn it into pseudo bytes via the - # latin1 charset, which will encode any byte as a single code point - # between 0 and 255, which is what body_encode is expecting. - # - # Note that this clause doesn't handle the case of a _payload that - # is already bytes. It never did, and the semantics of _payload - # being bytes has never been nailed down, so fixing that is a - # longer term TODO. - if isinstance(string, str): - string = string.encode(self.output_charset).decode('latin1') return email.quoprimime.body_encode(string) else: if isinstance(string, str): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/encoders.py --- a/Lib/email/encoders.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/encoders.py Fri Feb 01 23:12:09 2013 +0100 @@ -20,7 +20,7 @@ def _qencode(s): enc = _encodestring(s, quotetabs=True) # Must encode spaces, which quopri.encodestring() doesn't do - return enc.replace(b' ', b'=20') + return enc.replace(' ', '=20') def encode_base64(msg): @@ -41,12 +41,8 @@ Also, add an appropriate Content-Transfer-Encoding header. """ orig = msg.get_payload() - if isinstance(orig, str): - # If it is a string, the model data may have binary data encoded in via - # surrogateescape. Convert back to bytes so we can CTE encode it. - orig = orig.encode('ascii', 'surrogateescape') encdata = _qencode(orig) - msg.set_payload(encdata.decode('ascii', 'surrogateescape')) + msg.set_payload(encdata) msg['Content-Transfer-Encoding'] = 'quoted-printable' @@ -66,25 +62,17 @@ else: orig.decode('ascii') except UnicodeError: + # iso-2022-* is non-ASCII but still 7-bit charset = msg.get_charset() output_cset = charset and charset.output_charset - # iso-2022-* is non-ASCII but encodes to a 7-bit representation if output_cset and output_cset.lower().startswith('iso-2022-'): msg['Content-Transfer-Encoding'] = '7bit' else: msg['Content-Transfer-Encoding'] = '8bit' else: msg['Content-Transfer-Encoding'] = '7bit' - if not isinstance(orig, str): - msg.set_payload(orig.decode('ascii', 'surrogateescape')) def encode_noop(msg): """Do nothing.""" - # Well, not quite *nothing*: in Python3 we have to turn bytes into a string - # in our internal surrogateescaped form in order to keep the model - # consistent. - orig = msg.get_payload() - if not isinstance(orig, str): - msg.set_payload(orig.decode('ascii', 'surrogateescape')) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/feedparser.py --- a/Lib/email/feedparser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/feedparser.py Fri Feb 01 23:12:09 2013 +0100 @@ -98,15 +98,24 @@ """Push some new data into this object.""" # Handle any previous leftovers data, self._partial = self._partial + data, '' - # Crack into lines, but preserve the linesep characters on the end of each - parts = data.splitlines(True) - # If the last element of the list does not end in a newline, then treat - # it as a partial line. We only check for '\n' here because a line - # ending with '\r' might be a line that was split in the middle of a - # '\r\n' sequence (see bugs 1555570 and 1721862). - if parts and not parts[-1].endswith('\n'): - self._partial = parts.pop() - self.pushlines(parts) + # Crack into lines, but preserve the newlines on the end of each + parts = NLCRE_crack.split(data) + # The *ahem* interesting behaviour of re.split when supplied grouping + # parentheses is that the last element of the resulting list is the + # data after the final RE. In the case of a NL/CR terminated string, + # this is the empty string. + self._partial = parts.pop() + #GAN 29Mar09 bugs 1555570, 1721862 Confusion at 8K boundary ending with \r: + # is there a \n to follow later? + if not self._partial and parts and parts[-1].endswith('\r'): + self._partial = parts.pop(-2)+parts.pop() + # parts is a list of strings, alternating between the line contents + # and the eol character(s). Gather up a list of lines after + # re-attaching the newlines. + lines = [] + for i in range(len(parts) // 2): + lines.append(parts[i*2] + parts[i*2+1]) + self.pushlines(lines) def pushlines(self, lines): # Reverse and insert at the front of the lines. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/generator.py --- a/Lib/email/generator.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/generator.py Fri Feb 01 23:12:09 2013 +0100 @@ -146,19 +146,6 @@ # BytesGenerator overrides this to encode strings to bytes. return s - def _write_lines(self, lines): - # We have to transform the line endings. - if not lines: - return - lines = lines.splitlines(True) - for line in lines[:-1]: - self.write(line.rstrip('\r\n')) - self.write(self._NL) - laststripped = lines[-1].rstrip('\r\n') - self.write(laststripped) - if len(lines[-1]) != len(laststripped): - self.write(self._NL) - def _write(self, msg): # We can't write the headers yet because of the following scenario: # say a multipart message includes the boundary string somewhere in @@ -230,7 +217,7 @@ payload = msg.get_payload() if self._mangle_from_: payload = fcre.sub('>From ', payload) - self._write_lines(payload) + self.write(payload) # Default body handler _writeBody = _handle_text @@ -269,8 +256,7 @@ preamble = fcre.sub('>From ', msg.preamble) else: preamble = msg.preamble - self._write_lines(preamble) - self.write(self._NL) + self.write(preamble + self._NL) # dash-boundary transport-padding CRLF self.write('--' + boundary + self._NL) # body-part @@ -292,7 +278,7 @@ epilogue = fcre.sub('>From ', msg.epilogue) else: epilogue = msg.epilogue - self._write_lines(epilogue) + self.write(epilogue) def _handle_multipart_signed(self, msg): # The contents of signed parts has to stay unmodified in order to keep @@ -416,13 +402,10 @@ if _has_surrogates(msg._payload) and not self.policy.cte_type=='7bit': if self._mangle_from_: msg._payload = fcre.sub(">From ", msg._payload) - self._write_lines(msg._payload) + self.write(msg._payload) else: super(BytesGenerator,self)._handle_text(msg) - # Default body handler - _writeBody = _handle_text - @classmethod def _compile_re(cls, s, flags): return re.compile(s.encode('ascii'), flags) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/mime/text.py --- a/Lib/email/mime/text.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/mime/text.py Fri Feb 01 23:12:09 2013 +0100 @@ -26,7 +26,7 @@ Content-Transfer-Encoding header will also be set. """ - # If no _charset was specified, check to see if there are non-ascii + # If no _charset was specified, check to see see if there are non-ascii # characters present. If not, use 'us-ascii', otherwise use utf-8. # XXX: This can be removed once #7304 is fixed. if _charset is None: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/parser.py --- a/Lib/email/parser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/parser.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,13 +4,12 @@ """A parser of RFC 2822 and MIME email messages.""" -__all__ = ['Parser', 'HeaderParser', 'BytesParser', 'BytesHeaderParser', - 'FeedParser', 'BytesFeedParser'] +__all__ = ['Parser', 'HeaderParser', 'BytesParser', 'BytesHeaderParser'] import warnings from io import StringIO, TextIOWrapper -from email.feedparser import FeedParser, BytesFeedParser +from email.feedparser import FeedParser from email.message import Message from email._policybase import compat32 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/policy.py --- a/Lib/email/policy.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/policy.py Fri Feb 01 23:12:09 2013 +0100 @@ -23,7 +23,7 @@ """+ PROVISIONAL - The API extensions enabled by this policy are currently provisional. + The API extensions enabled by this this policy are currently provisional. Refer to the documentation for details. This policy adds new header parsing and folding algorithms. Instead of @@ -173,7 +173,7 @@ lines = value.splitlines() refold = (self.refold_source == 'all' or self.refold_source == 'long' and - (lines and len(lines[0])+len(name)+2 > maxlen or + (len(lines[0])+len(name)+2 > maxlen or any(len(x) > maxlen for x in lines[1:]))) if refold or refold_binary and _has_surrogates(value): return self.header_factory(name, ''.join(lines)).fold(policy=self) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/quoprimime.py --- a/Lib/email/quoprimime.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/quoprimime.py Fri Feb 01 23:12:09 2013 +0100 @@ -319,4 +319,4 @@ the high level email.header class for that functionality. """ s = s.replace('_', ' ') - return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, flags=re.ASCII) + return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, re.ASCII) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/email/utils.py --- a/Lib/email/utils.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/email/utils.py Fri Feb 01 23:12:09 2013 +0100 @@ -54,16 +54,10 @@ specialsre = re.compile(r'[][\\()<>@,:;".]') escapesre = re.compile(r'[\\"]') -def _has_surrogates(s): - """Return True if s contains surrogate-escaped binary data.""" - # This check is based on the fact that unless there are surrogates, utf8 - # (Python's default encoding) can encode any string. This is the fastest - # way to check for surrogates, see issue 11454 for timings. - try: - s.encode() - return False - except UnicodeEncodeError: - return True +# How to figure out if we are processing strings that come from a byte +# source with undecodable characters. +_has_surrogates = re.compile( + '([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search # How to deal with a string containing bytes before handing it to the # application through the 'normal' interface. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/encodings/cp037.py --- a/Lib/encodings/cp037.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/encodings/cp037.py Fri Feb 01 23:12:09 2013 +0100 @@ -301,6 +301,7 @@ '\xd9' # 0xFD -> LATIN CAPITAL LETTER U WITH GRAVE '\xda' # 0xFE -> LATIN CAPITAL LETTER U WITH ACUTE '\x9f' # 0xFF -> CONTROL + '\ufffe' ## Widen to UCS2 for optimization ) ### Encoding table diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/encodings/cp500.py --- a/Lib/encodings/cp500.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/encodings/cp500.py Fri Feb 01 23:12:09 2013 +0100 @@ -301,6 +301,7 @@ '\xd9' # 0xFD -> LATIN CAPITAL LETTER U WITH GRAVE '\xda' # 0xFE -> LATIN CAPITAL LETTER U WITH ACUTE '\x9f' # 0xFF -> CONTROL + '\ufffe' ## Widen to UCS2 for optimization ) ### Encoding table diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/encodings/iso8859_1.py --- a/Lib/encodings/iso8859_1.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/encodings/iso8859_1.py Fri Feb 01 23:12:09 2013 +0100 @@ -301,6 +301,7 @@ '\xfd' # 0xFD -> LATIN SMALL LETTER Y WITH ACUTE '\xfe' # 0xFE -> LATIN SMALL LETTER THORN (Icelandic) '\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS + '\ufffe' ## Widen to UCS2 for optimization ) ### Encoding table diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/enum.py --- a/Lib/enum.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,481 +0,0 @@ -import sys -from collections import OrderedDict -from types import MappingProxyType - -__all__ = ['Enum', 'IntEnum', 'unique'] - - -class _RouteClassAttributeToGetattr: - """Route attribute access on a class to __getattr__. - - This is a descriptor, used to define attributes that act differently when - accessed through an instance and through a class. Instance access remains - normal, but access to an attribute through a class will be routed to the - class's __getattr__ method; this is done by raising AttributeError. - - """ - def __init__(self, fget=None): - self.fget = fget - - def __get__(self, instance, ownerclass=None): - if instance is None: - raise AttributeError() - return self.fget(instance) - - def __set__(self, instance, value): - raise AttributeError("can't set attribute") - - def __delete__(self, instance): - raise AttributeError("can't delete attribute") - - -def _is_dunder(name): - """Returns True if a __dunder__ name, False otherwise.""" - return (name[:2] == name[-2:] == '__' and - name[2:3] != '_' and - name[-3:-2] != '_') - - -def _is_sunder(name): - """Returns True if a _sunder_ name, False otherwise.""" - return (name[0] == name[-1] == '_' and - name[1:2] != '_' and - name[-2:-1] != '_') - - -def _make_class_unpicklable(cls): - """Make the given class un-picklable.""" - def _break_on_call_reduce(self): - raise TypeError('%r cannot be pickled' % self) - cls.__reduce__ = _break_on_call_reduce - cls.__module__ = '' - - -class _EnumDict(dict): - """Keeps track of definition order of the enum items. - - EnumMeta will use the names found in self._member_names as the - enumeration member names. - - """ - def __init__(self): - super().__init__() - self._member_names = [] - - def __setitem__(self, key, value): - """Changes anything not dundered or that doesn't have __get__. - - If a descriptor is added with the same name as an enum member, the name - is removed from _member_names (this may leave a hole in the numerical - sequence of values). - - If an enum member name is used twice, an error is raised; duplicate - values are not checked for. - - Single underscore (sunder) names are reserved. - - """ - if _is_sunder(key): - raise ValueError('_names_ are reserved for future Enum use') - elif _is_dunder(key) or hasattr(value, '__get__'): - if key in self._member_names: - # overwriting an enum with a method? then remove the name from - # _member_names or it will become an enum anyway when the class - # is created - self._member_names.remove(key) - else: - if key in self._member_names: - raise TypeError('Attempted to reuse key: %r' % key) - self._member_names.append(key) - super().__setitem__(key, value) - - -# Dummy value for Enum as EnumMeta explicity checks for it, but of course until -# EnumMeta finishes running the first time the Enum class doesn't exist. This -# is also why there are checks in EnumMeta like `if Enum is not None` -Enum = None - - -class EnumMeta(type): - """Metaclass for Enum""" - @classmethod - def __prepare__(metacls, cls, bases): - return _EnumDict() - - def __new__(metacls, cls, bases, classdict): - # an Enum class is final once enumeration items have been defined; it - # cannot be mixed with other types (int, float, etc.) if it has an - # inherited __new__ unless a new __new__ is defined (or the resulting - # class will fail). - member_type, first_enum = metacls._get_mixins_(bases) - __new__, save_new, use_args = metacls._find_new_(classdict, member_type, - first_enum) - - # save enum items into separate mapping so they don't get baked into - # the new class - members = {k: classdict[k] for k in classdict._member_names} - for name in classdict._member_names: - del classdict[name] - - # check for illegal enum names (any others?) - invalid_names = set(members) & {'mro', } - if invalid_names: - raise ValueError('Invalid enum member name: {0}'.format( - ','.join(invalid_names))) - - # create our new Enum type - enum_class = super().__new__(metacls, cls, bases, classdict) - enum_class._member_names_ = [] # names in definition order - enum_class._member_map_ = OrderedDict() # name->value map - - # Reverse value->name map for hashable values. - enum_class._value2member_map_ = {} - - # check for a __getnewargs__, and if not present sabotage - # pickling, since it won't work anyway - if (member_type is not object and - member_type.__dict__.get('__getnewargs__') is None - ): - _make_class_unpicklable(enum_class) - - # instantiate them, checking for duplicates as we go - # we instantiate first instead of checking for duplicates first in case - # a custom __new__ is doing something funky with the values -- such as - # auto-numbering ;) - for member_name in classdict._member_names: - value = members[member_name] - if not isinstance(value, tuple): - args = (value, ) - else: - args = value - if member_type is tuple: # special case for tuple enums - args = (args, ) # wrap it one more time - if not use_args: - enum_member = __new__(enum_class) - if not hasattr(enum_member, '_value_'): - enum_member._value_ = value - else: - enum_member = __new__(enum_class, *args) - if not hasattr(enum_member, '_value_'): - enum_member._value_ = member_type(*args) - value = enum_member._value_ - enum_member._member_type_ = member_type - enum_member._name_ = member_name - enum_member.__init__(*args) - # If another member with the same value was already defined, the - # new member becomes an alias to the existing one. - for name, canonical_member in enum_class._member_map_.items(): - if canonical_member.value == enum_member._value_: - enum_member = canonical_member - break - else: - # Aliases don't appear in member names (only in __members__). - enum_class._member_names_.append(member_name) - enum_class._member_map_[member_name] = enum_member - try: - # This may fail if value is not hashable. We can't add the value - # to the map, and by-value lookups for this value will be - # linear. - enum_class._value2member_map_[value] = enum_member - except TypeError: - pass - - # double check that repr and friends are not the mixin's or various - # things break (such as pickle) - for name in ('__repr__', '__str__', '__getnewargs__'): - class_method = getattr(enum_class, name) - obj_method = getattr(member_type, name, None) - enum_method = getattr(first_enum, name, None) - if obj_method is not None and obj_method is class_method: - setattr(enum_class, name, enum_method) - - # replace any other __new__ with our own (as long as Enum is not None, - # anyway) -- again, this is to support pickle - if Enum is not None: - # if the user defined their own __new__, save it before it gets - # clobbered in case they subclass later - if save_new: - enum_class.__new_member__ = __new__ - enum_class.__new__ = Enum.__new__ - return enum_class - - def __call__(cls, value, names=None, *, module=None, type=None): - """Either returns an existing member, or creates a new enum class. - - This method is used both when an enum class is given a value to match - to an enumeration member (i.e. Color(3)) and for the functional API - (i.e. Color = Enum('Color', names='red green blue')). - - When used for the functional API: `module`, if set, will be stored in - the new class' __module__ attribute; `type`, if set, will be mixed in - as the first base class. - - Note: if `module` is not set this routine will attempt to discover the - calling module by walking the frame stack; if this is unsuccessful - the resulting class will not be pickleable. - - """ - if names is None: # simple value lookup - return cls.__new__(cls, value) - # otherwise, functional API: we're creating a new Enum type - return cls._create_(value, names, module=module, type=type) - - def __contains__(cls, member): - return isinstance(member, cls) and member.name in cls._member_map_ - - def __dir__(self): - return ['__class__', '__doc__', '__members__'] + self._member_names_ - - @property - def __members__(cls): - """Returns a mapping of member name->value. - - This mapping lists all enum members, including aliases. Note that this - is a read-only view of the internal mapping. - - """ - return MappingProxyType(cls._member_map_) - - def __getattr__(cls, name): - """Return the enum member matching `name` - - We use __getattr__ instead of descriptors or inserting into the enum - class' __dict__ in order to support `name` and `value` being both - properties for enum members (which live in the class' __dict__) and - enum members themselves. - - """ - if _is_dunder(name): - raise AttributeError(name) - try: - return cls._member_map_[name] - except KeyError: - raise AttributeError(name) from None - - def __getitem__(cls, name): - return cls._member_map_[name] - - def __iter__(cls): - return (cls._member_map_[name] for name in cls._member_names_) - - def __len__(cls): - return len(cls._member_names_) - - def __repr__(cls): - return "" % cls.__name__ - - def _create_(cls, class_name, names=None, *, module=None, type=None): - """Convenience method to create a new Enum class. - - `names` can be: - - * A string containing member names, separated either with spaces or - commas. Values are auto-numbered from 1. - * An iterable of member names. Values are auto-numbered from 1. - * An iterable of (member name, value) pairs. - * A mapping of member name -> value. - - """ - metacls = cls.__class__ - bases = (cls, ) if type is None else (type, cls) - classdict = metacls.__prepare__(class_name, bases) - - # special processing needed for names? - if isinstance(names, str): - names = names.replace(',', ' ').split() - if isinstance(names, (tuple, list)) and isinstance(names[0], str): - names = [(e, i) for (i, e) in enumerate(names, 1)] - - # Here, names is either an iterable of (name, value) or a mapping. - for item in names: - if isinstance(item, str): - member_name, member_value = item, names[item] - else: - member_name, member_value = item - classdict[member_name] = member_value - enum_class = metacls.__new__(metacls, class_name, bases, classdict) - - # TODO: replace the frame hack if a blessed way to know the calling - # module is ever developed - if module is None: - try: - module = sys._getframe(2).f_globals['__name__'] - except (AttributeError, ValueError) as exc: - pass - if module is None: - _make_class_unpicklable(enum_class) - else: - enum_class.__module__ = module - - return enum_class - - @staticmethod - def _get_mixins_(bases): - """Returns the type for creating enum members, and the first inherited - enum class. - - bases: the tuple of bases that was given to __new__ - - """ - if not bases: - return object, Enum - - # double check that we are not subclassing a class with existing - # enumeration members; while we're at it, see if any other data - # type has been mixed in so we can use the correct __new__ - member_type = first_enum = None - for base in bases: - if (base is not Enum and - issubclass(base, Enum) and - base._member_names_): - raise TypeError("Cannot extend enumerations") - # base is now the last base in bases - if not issubclass(base, Enum): - raise TypeError("new enumerations must be created as " - "`ClassName([mixin_type,] enum_type)`") - - # get correct mix-in type (either mix-in type of Enum subclass, or - # first base if last base is Enum) - if not issubclass(bases[0], Enum): - member_type = bases[0] # first data type - first_enum = bases[-1] # enum type - else: - for base in bases[0].__mro__: - # most common: (IntEnum, int, Enum, object) - # possible: (, , - # , , - # ) - if issubclass(base, Enum): - if first_enum is None: - first_enum = base - else: - if member_type is None: - member_type = base - - return member_type, first_enum - - @staticmethod - def _find_new_(classdict, member_type, first_enum): - """Returns the __new__ to be used for creating the enum members. - - classdict: the class dictionary given to __new__ - member_type: the data type whose __new__ will be used by default - first_enum: enumeration to check for an overriding __new__ - - """ - # now find the correct __new__, checking to see of one was defined - # by the user; also check earlier enum classes in case a __new__ was - # saved as __new_member__ - __new__ = classdict.get('__new__', None) - - # should __new__ be saved as __new_member__ later? - save_new = __new__ is not None - - if __new__ is None: - # check all possibles for __new_member__ before falling back to - # __new__ - for method in ('__new_member__', '__new__'): - for possible in (member_type, first_enum): - target = getattr(possible, method, None) - if target not in { - None, - None.__new__, - object.__new__, - Enum.__new__, - }: - __new__ = target - break - if __new__ is not None: - break - else: - __new__ = object.__new__ - - # if a non-object.__new__ is used then whatever value/tuple was - # assigned to the enum member name will be passed to __new__ and to the - # new enum member's __init__ - if __new__ is object.__new__: - use_args = False - else: - use_args = True - - return __new__, save_new, use_args - - -class Enum(metaclass=EnumMeta): - """Generic enumeration. - - Derive from this class to define new enumerations. - - """ - def __new__(cls, value): - # all enum instances are actually created during class construction - # without calling this method; this method is called by the metaclass' - # __call__ (i.e. Color(3) ), and by pickle - if type(value) is cls: - # For lookups like Color(Color.red) - return value - # by-value search for a matching enum member - # see if it's in the reverse mapping (for hashable values) - try: - if value in cls._value2member_map_: - return cls._value2member_map_[value] - except TypeError: - # not there, now do long search -- O(n) behavior - for member in cls._member_map_.values(): - if member.value == value: - return member - raise ValueError("%s is not a valid %s" % (value, cls.__name__)) - - def __repr__(self): - return "<%s.%s: %r>" % ( - self.__class__.__name__, self._name_, self._value_) - - def __str__(self): - return "%s.%s" % (self.__class__.__name__, self._name_) - - def __dir__(self): - return (['__class__', '__doc__', 'name', 'value']) - - def __eq__(self, other): - if type(other) is self.__class__: - return self is other - return NotImplemented - - def __getnewargs__(self): - return (self._value_, ) - - def __hash__(self): - return hash(self._name_) - - # _RouteClassAttributeToGetattr is used to provide access to the `name` - # and `value` properties of enum members while keeping some measure of - # protection from modification, while still allowing for an enumeration - # to have members named `name` and `value`. This works because enumeration - # members are not set directly on the enum class -- __getattr__ is - # used to look them up. - - @_RouteClassAttributeToGetattr - def name(self): - return self._name_ - - @_RouteClassAttributeToGetattr - def value(self): - return self._value_ - - -class IntEnum(int, Enum): - """Enum where members are also (and must be) ints""" - - -def unique(enumeration): - """Class decorator for enumerations ensuring unique member values.""" - duplicates = [] - for name, member in enumeration.__members__.items(): - if name != member.name: - duplicates.append((name, member.name)) - if duplicates: - alias_details = ', '.join( - ["%s -> %s" % (alias, name) for (alias, name) in duplicates]) - raise ValueError('duplicate values found in %r: %s' % - (enumeration, alias_details)) - return enumeration diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/filecmp.py --- a/Lib/filecmp.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/filecmp.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,6 @@ Functions: cmp(f1, f2, shallow=True) -> int cmpfiles(a, b, common) -> ([], [], []) - clear_cache() """ @@ -14,7 +13,7 @@ import stat from itertools import filterfalse -__all__ = ['clear_cache', 'cmp', 'dircmp', 'cmpfiles', 'DEFAULT_IGNORES'] +__all__ = ['cmp', 'dircmp', 'cmpfiles', 'DEFAULT_IGNORES'] _cache = {} BUFSIZE = 8*1024 @@ -22,9 +21,6 @@ DEFAULT_IGNORES = [ 'RCS', 'CVS', 'tags', '.git', '.hg', '.bzr', '_darcs', '__pycache__'] -def clear_cache(): - """Clear the filecmp cache.""" - _cache.clear() def cmp(f1, f2, shallow=True): """Compare two files. @@ -43,8 +39,7 @@ True if the files are the same, False otherwise. This function uses a cache for past comparisons and the results, - with a cache invalidation mechanism relying on stale signatures - or by explicitly calling clear_cache(). + with a cache invalidation mechanism relying on stale signatures. """ @@ -61,7 +56,7 @@ if outcome is None: outcome = _do_cmp(f1, f2) if len(_cache) > 100: # limit the maximum size of the cache - clear_cache() + _cache.clear() _cache[f1, f2, s1, s2] = outcome return outcome diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/fileinput.py --- a/Lib/fileinput.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/fileinput.py Fri Feb 01 23:12:09 2013 +0100 @@ -90,11 +90,13 @@ def input(files=None, inplace=False, backup="", bufsize=0, mode="r", openhook=None): - """Return an instance of the FileInput class, which can be iterated. + """input(files=None, inplace=False, backup="", bufsize=0, \ +mode="r", openhook=None) - The parameters are passed to the constructor of the FileInput class. - The returned instance, in addition to being an iterator, - keeps global state for the functions of this module,. + Create an instance of the FileInput class. The instance will be used + as global state for the functions of this module, and is also returned + to use during iteration. The parameters to this function will be passed + along to the constructor of the FileInput class. """ global _state if _state and _state._file: @@ -181,7 +183,7 @@ return _state.isstdin() class FileInput: - """FileInput([files[, inplace[, backup[, bufsize, [, mode[, openhook]]]]]]) + """class FileInput([files[, inplace[, backup[, mode[, openhook]]]]]) Class FileInput is the implementation of the module; its methods filename(), lineno(), fileline(), isfirstline(), isstdin(), fileno(), diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/fnmatch.py --- a/Lib/fnmatch.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/fnmatch.py Fri Feb 01 23:12:09 2013 +0100 @@ -35,7 +35,7 @@ pat = os.path.normcase(pat) return fnmatchcase(name, pat) -@functools.lru_cache(maxsize=256, typed=True) +@functools.lru_cache(maxsize=250, typed=True) def _compile_pattern(pat): if isinstance(pat, bytes): pat_str = str(pat, 'ISO-8859-1') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ftplib.py --- a/Lib/ftplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ftplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -39,10 +39,9 @@ import os import sys import socket -import warnings from socket import _GLOBAL_DEFAULT_TIMEOUT -__all__ = ["FTP", "Netrc"] +__all__ = ["FTP","Netrc"] # Magic number from MSG_OOB = 0x1 # Process data out of band @@ -134,7 +133,6 @@ '''Connect to host. Arguments are: - host: hostname to connect to (string, default previous host) - port: port to connect to (integer, default previous port) - - timeout: the timeout to set against the ftp socket(s) - source_address: a 2-tuple (host, port) for the socket to bind to as its source address before connecting. ''' @@ -185,8 +183,7 @@ # Internal: send one line to the server, appending CRLF def putline(self, line): line = line + CRLF - if self.debugging > 1: - print('*put*', self.sanitize(line)) + if self.debugging > 1: print('*put*', self.sanitize(line)) self.sock.sendall(line.encode(self.encoding)) # Internal: send one command to the server (through putline()) @@ -200,12 +197,9 @@ line = self.file.readline() if self.debugging > 1: print('*get*', self.sanitize(line)) - if not line: - raise EOFError - if line[-2:] == CRLF: - line = line[:-2] - elif line[-1:] in CRLF: - line = line[:-1] + if not line: raise EOFError + if line[-2:] == CRLF: line = line[:-2] + elif line[-1:] in CRLF: line = line[:-1] return line # Internal: get a response from the server, which may possibly @@ -228,8 +222,7 @@ # Raise various errors if the response indicates an error def getresp(self): resp = self.getmultiline() - if self.debugging: - print('*resp*', self.sanitize(resp)) + if self.debugging: print('*resp*', self.sanitize(resp)) self.lastresp = resp[:3] c = resp[:1] if c in {'1', '2', '3'}: @@ -253,8 +246,7 @@ IP and Synch; that doesn't seem to work with the servers I've tried. Instead, just send the ABOR command as OOB data.''' line = b'ABOR' + B_CRLF - if self.debugging > 1: - print('*put urgent*', self.sanitize(line)) + if self.debugging > 1: print('*put urgent*', self.sanitize(line)) self.sock.sendall(line, MSG_OOB) resp = self.getmultiline() if resp[:3] not in {'426', '225', '226'}: @@ -395,12 +387,9 @@ def login(self, user = '', passwd = '', acct = ''): '''Login, default anonymous.''' - if not user: - user = 'anonymous' - if not passwd: - passwd = '' - if not acct: - acct = '' + if not user: user = 'anonymous' + if not passwd: passwd = '' + if not acct: acct = '' if user == 'anonymous' and passwd in {'', '-'}: # If there is no anonymous ftp password specified # then we'll just use anonymous@ @@ -411,10 +400,8 @@ # host or country. passwd = passwd + 'anonymous@' resp = self.sendcmd('USER ' + user) - if resp[0] == '3': - resp = self.sendcmd('PASS ' + passwd) - if resp[0] == '3': - resp = self.sendcmd('ACCT ' + acct) + if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd) + if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct) if resp[0] != '2': raise error_reply(resp) return resp @@ -440,9 +427,6 @@ if not data: break callback(data) - # shutdown ssl layer - if _SSLSocket is not None and isinstance(conn, _SSLSocket): - conn.unwrap() return self.voidresp() def retrlines(self, cmd, callback = None): @@ -457,15 +441,13 @@ Returns: The response code. """ - if callback is None: - callback = print_line + if callback is None: callback = print_line resp = self.sendcmd('TYPE A') with self.transfercmd(cmd) as conn, \ conn.makefile('r', encoding=self.encoding) as fp: while 1: line = fp.readline() - if self.debugging > 2: - print('*retr*', repr(line)) + if self.debugging > 2: print('*retr*', repr(line)) if not line: break if line[-2:] == CRLF: @@ -473,9 +455,6 @@ elif line[-1:] == '\n': line = line[:-1] callback(line) - # shutdown ssl layer - if _SSLSocket is not None and isinstance(conn, _SSLSocket): - conn.unwrap() return self.voidresp() def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None): @@ -487,7 +466,7 @@ blocksize: The maximum data size to read from fp and send over the connection at once. [default: 8192] callback: An optional single parameter callable that is called on - each block of data after it is sent. [default: None] + on each block of data after it is sent. [default: None] rest: Passed to transfercmd(). [default: None] Returns: @@ -497,14 +476,9 @@ with self.transfercmd(cmd, rest) as conn: while 1: buf = fp.read(blocksize) - if not buf: - break + if not buf: break conn.sendall(buf) - if callback: - callback(buf) - # shutdown ssl layer - if _SSLSocket is not None and isinstance(conn, _SSLSocket): - conn.unwrap() + if callback: callback(buf) return self.voidresp() def storlines(self, cmd, fp, callback=None): @@ -514,7 +488,7 @@ cmd: A STOR command. fp: A file-like object with a readline() method. callback: An optional single parameter callable that is called on - each line after it is sent. [default: None] + on each line after it is sent. [default: None] Returns: The response code. @@ -523,17 +497,12 @@ with self.transfercmd(cmd) as conn: while 1: buf = fp.readline() - if not buf: - break + if not buf: break if buf[-2:] != B_CRLF: if buf[-1] in B_CRLF: buf = buf[:-1] buf = buf + B_CRLF conn.sendall(buf) - if callback: - callback(buf) - # shutdown ssl layer - if _SSLSocket is not None and isinstance(conn, _SSLSocket): - conn.unwrap() + if callback: callback(buf) return self.voidresp() def acct(self, password): @@ -668,10 +637,8 @@ try: import ssl except ImportError: - _SSLSocket = None + pass else: - _SSLSocket = ssl.SSLSocket - class FTP_TLS(FTP): '''A FTP subclass which adds TLS support to FTP as described in RFC-4217. @@ -786,6 +753,69 @@ ssl_version=self.ssl_version) return conn, size + def retrbinary(self, cmd, callback, blocksize=8192, rest=None): + self.voidcmd('TYPE I') + with self.transfercmd(cmd, rest) as conn: + while 1: + data = conn.recv(blocksize) + if not data: + break + callback(data) + # shutdown ssl layer + if isinstance(conn, ssl.SSLSocket): + conn.unwrap() + return self.voidresp() + + def retrlines(self, cmd, callback = None): + if callback is None: callback = print_line + resp = self.sendcmd('TYPE A') + conn = self.transfercmd(cmd) + fp = conn.makefile('r', encoding=self.encoding) + with fp, conn: + while 1: + line = fp.readline() + if self.debugging > 2: print('*retr*', repr(line)) + if not line: + break + if line[-2:] == CRLF: + line = line[:-2] + elif line[-1:] == '\n': + line = line[:-1] + callback(line) + # shutdown ssl layer + if isinstance(conn, ssl.SSLSocket): + conn.unwrap() + return self.voidresp() + + def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None): + self.voidcmd('TYPE I') + with self.transfercmd(cmd, rest) as conn: + while 1: + buf = fp.read(blocksize) + if not buf: break + conn.sendall(buf) + if callback: callback(buf) + # shutdown ssl layer + if isinstance(conn, ssl.SSLSocket): + conn.unwrap() + return self.voidresp() + + def storlines(self, cmd, fp, callback=None): + self.voidcmd('TYPE A') + with self.transfercmd(cmd) as conn: + while 1: + buf = fp.readline() + if not buf: break + if buf[-2:] != B_CRLF: + if buf[-1] in B_CRLF: buf = buf[:-1] + buf = buf + B_CRLF + conn.sendall(buf) + if callback: callback(buf) + # shutdown ssl layer + if isinstance(conn, ssl.SSLSocket): + conn.unwrap() + return self.voidresp() + def abort(self): # overridden as we can't pass MSG_OOB flag to sendall() line = b'ABOR' + B_CRLF @@ -893,8 +923,7 @@ def ftpcp(source, sourcename, target, targetname = '', type = 'I'): '''Copy file from one FTP-instance to another.''' - if not targetname: - targetname = sourcename + if not targetname: targetname = sourcename type = 'TYPE ' + type source.voidcmd(type) target.voidcmd(type) @@ -904,11 +933,9 @@ # transfer request. # So: STOR before RETR, because here the target is a "user". treply = target.sendcmd('STOR ' + targetname) - if treply[:3] not in {'125', '150'}: - raise error_proto # RFC 959 + if treply[:3] not in {'125', '150'}: raise error_proto # RFC 959 sreply = source.sendcmd('RETR ' + sourcename) - if sreply[:3] not in {'125', '150'}: - raise error_proto # RFC 959 + if sreply[:3] not in {'125', '150'}: raise error_proto # RFC 959 source.voidresp() target.voidresp() @@ -926,8 +953,6 @@ __defacct = None def __init__(self, filename=None): - warnings.warn("This class is deprecated, use the netrc module instead", - DeprecationWarning, 2) if filename is None: if "HOME" in os.environ: filename = os.path.join(os.environ["HOME"], @@ -940,8 +965,7 @@ in_macro = 0 while 1: line = fp.readline() - if not line: - break + if not line: break if in_macro and line.strip(): macro_lines.append(line) continue diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/functools.py --- a/Lib/functools.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/functools.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,31 +3,23 @@ # Python module wrapper for _functools C module # to allow utilities written in Python to be added # to the functools module. -# Written by Nick Coghlan , -# Raymond Hettinger , -# and Åukasz Langa . -# Copyright (C) 2006-2013 Python Software Foundation. +# Written by Nick Coghlan +# and Raymond Hettinger +# Copyright (C) 2006-2010 Python Software Foundation. # See C source code for _functools credits/copyright __all__ = ['update_wrapper', 'wraps', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', - 'total_ordering', 'cmp_to_key', 'lru_cache', 'reduce', 'partial', - 'singledispatch'] + 'total_ordering', 'cmp_to_key', 'lru_cache', 'reduce', 'partial'] try: from _functools import reduce except ImportError: pass -from abc import get_cache_token from collections import namedtuple -from types import MappingProxyType -from weakref import WeakKeyDictionary try: - from _thread import RLock + from _thread import allocate_lock as Lock except: - class RLock: - 'Dummy reentrant lock for builds without threads' - def __enter__(self): pass - def __exit__(self, exctype, excinst, exctb): pass + from _dummy_thread import allocate_lock as Lock ################################################################################ @@ -55,6 +47,7 @@ are updated with the corresponding attribute from the wrapped function (defaults to functools.WRAPPER_UPDATES) """ + wrapper.__wrapped__ = wrapped for attr in assigned: try: value = getattr(wrapped, attr) @@ -64,9 +57,6 @@ setattr(wrapper, attr, value) for attr in updated: getattr(wrapper, attr).update(getattr(wrapped, attr, {})) - # Issue #17482: set __wrapped__ last so we don't inadvertently copy it - # from the wrapped function when updating __dict__ - wrapper.__wrapped__ = wrapped # Return the wrapper so this can be used as a decorator via partial() return wrapper @@ -179,12 +169,6 @@ _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) class _HashedSeq(list): - """ This class guarantees that hash() will be called no more than once - per element. This is important because the lru_cache() will hash - the key multiple times on a cache miss. - - """ - __slots__ = 'hashvalue' def __init__(self, tup, hash=hash): @@ -198,16 +182,7 @@ kwd_mark = (object(),), fasttypes = {int, str, frozenset, type(None)}, sorted=sorted, tuple=tuple, type=type, len=len): - """Make a cache key from optionally typed positional and keyword arguments - - The key is constructed in a way that is flat as possible rather than - as a nested structure that would take more memory. - - If there is only a single argument and its data type is known to cache - its hash value, then that argument is returned without a wrapper. This - saves space and improves lookup speed. - - """ + 'Make a cache key from optionally typed positional and keyword arguments' key = args if kwds: sorted_items = sorted(kwds.items()) @@ -253,18 +228,19 @@ PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields def decorating_function(user_function): + cache = {} - hits = misses = 0 + hits = misses = currsize = 0 full = False cache_get = cache.get # bound method to lookup a key or return None - lock = RLock() # because linkedlist updates aren't threadsafe + lock = Lock() # because linkedlist updates aren't threadsafe root = [] # root of the circular doubly linked list root[:] = [root, root, None, None] # initialize by pointing to self if maxsize == 0: def wrapper(*args, **kwds): - # No caching -- just a statistics update after a successful call + # no caching, just a statistics update after a successful call nonlocal misses result = user_function(*args, **kwds) misses += 1 @@ -273,8 +249,8 @@ elif maxsize is None: def wrapper(*args, **kwds): - # Simple caching without ordering or size limit - nonlocal hits, misses + # simple caching without ordering or size limit + nonlocal hits, misses, currsize key = make_key(args, kwds, typed) result = cache_get(key, sentinel) if result is not sentinel: @@ -283,19 +259,20 @@ result = user_function(*args, **kwds) cache[key] = result misses += 1 + currsize += 1 return result else: def wrapper(*args, **kwds): - # Size limited caching that tracks accesses by recency - nonlocal root, hits, misses, full + # size limited caching that tracks accesses by recency + nonlocal root, hits, misses, currsize, full key = make_key(args, kwds, typed) with lock: link = cache_get(key) if link is not None: - # Move the link to the front of the circular queue - link_prev, link_next, _key, result = link + # move the link to the front of the circular queue + link_prev, link_next, key, result = link link_prev[NEXT] = link_next link_next[PREV] = link_prev last = root[PREV] @@ -307,53 +284,42 @@ result = user_function(*args, **kwds) with lock: if key in cache: - # Getting here means that this same key was added to the - # cache while the lock was released. Since the link + # getting here means that this same key was added to the + # cache while the lock was released. since the link # update is already done, we need only return the # computed result and update the count of misses. pass elif full: - # Use the old root to store the new key and result. - oldroot = root - oldroot[KEY] = key - oldroot[RESULT] = result - # Empty the oldest link and make it the new root. - # Keep a reference to the old key and old result to - # prevent their ref counts from going to zero during the - # update. That will prevent potentially arbitrary object - # clean-up code (i.e. __del__) from running while we're - # still adjusting the links. - root = oldroot[NEXT] - oldkey = root[KEY] - oldresult = root[RESULT] + # use root to store the new key and result + root[KEY] = key + root[RESULT] = result + cache[key] = root + # empty the oldest link and make it the new root + root = root[NEXT] + del cache[root[KEY]] root[KEY] = root[RESULT] = None - # Now update the cache dictionary. - del cache[oldkey] - # Save the potentially reentrant cache[key] assignment - # for last, after the root and links have been put in - # a consistent state. - cache[key] = oldroot else: - # Put result in a new link at the front of the queue. + # put result in a new link at the front of the queue last = root[PREV] link = [last, root, key, result] - last[NEXT] = root[PREV] = cache[key] = link - full = (len(cache) >= maxsize) + cache[key] = last[NEXT] = root[PREV] = link + currsize += 1 + full = (currsize == maxsize) misses += 1 return result def cache_info(): """Report cache statistics""" with lock: - return _CacheInfo(hits, misses, maxsize, len(cache)) + return _CacheInfo(hits, misses, maxsize, currsize) def cache_clear(): """Clear the cache and cache statistics""" - nonlocal hits, misses, full + nonlocal hits, misses, currsize, full with lock: cache.clear() root[:] = [root, root, None, None] - hits = misses = 0 + hits = misses = currsize = 0 full = False wrapper.cache_info = cache_info @@ -361,210 +327,3 @@ return update_wrapper(wrapper, user_function) return decorating_function - - -################################################################################ -### singledispatch() - single-dispatch generic function decorator -################################################################################ - -def _c3_merge(sequences): - """Merges MROs in *sequences* to a single MRO using the C3 algorithm. - - Adapted from http://www.python.org/download/releases/2.3/mro/. - - """ - result = [] - while True: - sequences = [s for s in sequences if s] # purge empty sequences - if not sequences: - return result - for s1 in sequences: # find merge candidates among seq heads - candidate = s1[0] - for s2 in sequences: - if candidate in s2[1:]: - candidate = None - break # reject the current head, it appears later - else: - break - if not candidate: - raise RuntimeError("Inconsistent hierarchy") - result.append(candidate) - # remove the chosen candidate - for seq in sequences: - if seq[0] == candidate: - del seq[0] - -def _c3_mro(cls, abcs=None): - """Computes the method resolution order using extended C3 linearization. - - If no *abcs* are given, the algorithm works exactly like the built-in C3 - linearization used for method resolution. - - If given, *abcs* is a list of abstract base classes that should be inserted - into the resulting MRO. Unrelated ABCs are ignored and don't end up in the - result. The algorithm inserts ABCs where their functionality is introduced, - i.e. issubclass(cls, abc) returns True for the class itself but returns - False for all its direct base classes. Implicit ABCs for a given class - (either registered or inferred from the presence of a special method like - __len__) are inserted directly after the last ABC explicitly listed in the - MRO of said class. If two implicit ABCs end up next to each other in the - resulting MRO, their ordering depends on the order of types in *abcs*. - - """ - for i, base in enumerate(reversed(cls.__bases__)): - if hasattr(base, '__abstractmethods__'): - boundary = len(cls.__bases__) - i - break # Bases up to the last explicit ABC are considered first. - else: - boundary = 0 - abcs = list(abcs) if abcs else [] - explicit_bases = list(cls.__bases__[:boundary]) - abstract_bases = [] - other_bases = list(cls.__bases__[boundary:]) - for base in abcs: - if issubclass(cls, base) and not any( - issubclass(b, base) for b in cls.__bases__ - ): - # If *cls* is the class that introduces behaviour described by - # an ABC *base*, insert said ABC to its MRO. - abstract_bases.append(base) - for base in abstract_bases: - abcs.remove(base) - explicit_c3_mros = [_c3_mro(base, abcs=abcs) for base in explicit_bases] - abstract_c3_mros = [_c3_mro(base, abcs=abcs) for base in abstract_bases] - other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases] - return _c3_merge( - [[cls]] + - explicit_c3_mros + abstract_c3_mros + other_c3_mros + - [explicit_bases] + [abstract_bases] + [other_bases] - ) - -def _compose_mro(cls, types): - """Calculates the method resolution order for a given class *cls*. - - Includes relevant abstract base classes (with their respective bases) from - the *types* iterable. Uses a modified C3 linearization algorithm. - - """ - bases = set(cls.__mro__) - # Remove entries which are already present in the __mro__ or unrelated. - def is_related(typ): - return (typ not in bases and hasattr(typ, '__mro__') - and issubclass(cls, typ)) - types = [n for n in types if is_related(n)] - # Remove entries which are strict bases of other entries (they will end up - # in the MRO anyway. - def is_strict_base(typ): - for other in types: - if typ != other and typ in other.__mro__: - return True - return False - types = [n for n in types if not is_strict_base(n)] - # Subclasses of the ABCs in *types* which are also implemented by - # *cls* can be used to stabilize ABC ordering. - type_set = set(types) - mro = [] - for typ in types: - found = [] - for sub in typ.__subclasses__(): - if sub not in bases and issubclass(cls, sub): - found.append([s for s in sub.__mro__ if s in type_set]) - if not found: - mro.append(typ) - continue - # Favor subclasses with the biggest number of useful bases - found.sort(key=len, reverse=True) - for sub in found: - for subcls in sub: - if subcls not in mro: - mro.append(subcls) - return _c3_mro(cls, abcs=mro) - -def _find_impl(cls, registry): - """Returns the best matching implementation from *registry* for type *cls*. - - Where there is no registered implementation for a specific type, its method - resolution order is used to find a more generic implementation. - - Note: if *registry* does not contain an implementation for the base - *object* type, this function may return None. - - """ - mro = _compose_mro(cls, registry.keys()) - match = None - for t in mro: - if match is not None: - # If *match* is an implicit ABC but there is another unrelated, - # equally matching implicit ABC, refuse the temptation to guess. - if (t in registry and t not in cls.__mro__ - and match not in cls.__mro__ - and not issubclass(match, t)): - raise RuntimeError("Ambiguous dispatch: {} or {}".format( - match, t)) - break - if t in registry: - match = t - return registry.get(match) - -def singledispatch(func): - """Single-dispatch generic function decorator. - - Transforms a function into a generic function, which can have different - behaviours depending upon the type of its first argument. The decorated - function acts as the default implementation, and additional - implementations can be registered using the register() attribute of the - generic function. - - """ - registry = {} - dispatch_cache = WeakKeyDictionary() - cache_token = None - - def dispatch(cls): - """generic_func.dispatch(cls) -> - - Runs the dispatch algorithm to return the best available implementation - for the given *cls* registered on *generic_func*. - - """ - nonlocal cache_token - if cache_token is not None: - current_token = get_cache_token() - if cache_token != current_token: - dispatch_cache.clear() - cache_token = current_token - try: - impl = dispatch_cache[cls] - except KeyError: - try: - impl = registry[cls] - except KeyError: - impl = _find_impl(cls, registry) - dispatch_cache[cls] = impl - return impl - - def register(cls, func=None): - """generic_func.register(cls, func) -> func - - Registers a new implementation for the given *cls* on a *generic_func*. - - """ - nonlocal cache_token - if func is None: - return lambda f: register(cls, f) - registry[cls] = func - if cache_token is None and hasattr(cls, '__abstractmethods__'): - cache_token = get_cache_token() - dispatch_cache.clear() - return func - - def wrapper(*args, **kw): - return dispatch(args[0].__class__)(*args, **kw) - - registry[object] = func - wrapper.register = register - wrapper.dispatch = dispatch - wrapper.registry = MappingProxyType(registry) - wrapper._clear_cache = dispatch_cache.clear - update_wrapper(wrapper, func) - return wrapper diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/getpass.py --- a/Lib/getpass.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/getpass.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,11 +15,7 @@ # Guido van Rossum (Windows support and cleanup) # Gregory P. Smith (tty support & GetPassWarning) -import contextlib -import io -import os -import sys -import warnings +import os, sys, warnings __all__ = ["getpass","getuser","GetPassWarning"] @@ -42,57 +38,52 @@ Always restores terminal settings before returning. """ - passwd = None - with contextlib.ExitStack() as stack: + fd = None + tty = None + try: + # Always try reading and writing directly on the tty first. + fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY) + tty = os.fdopen(fd, 'w+', 1) + input = tty + if not stream: + stream = tty + except OSError as e: + # If that fails, see if stdin can be controlled. try: - # Always try reading and writing directly on the tty first. - fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY) - tty = io.FileIO(fd, 'w+') - stack.enter_context(tty) - input = io.TextIOWrapper(tty) - stack.enter_context(input) - if not stream: - stream = input - except OSError as e: - # If that fails, see if stdin can be controlled. - stack.close() + fd = sys.stdin.fileno() + except (AttributeError, ValueError): + passwd = fallback_getpass(prompt, stream) + input = sys.stdin + if not stream: + stream = sys.stderr + + if fd is not None: + passwd = None + try: + old = termios.tcgetattr(fd) # a copy to save + new = old[:] + new[3] &= ~termios.ECHO # 3 == 'lflags' + tcsetattr_flags = termios.TCSAFLUSH + if hasattr(termios, 'TCSASOFT'): + tcsetattr_flags |= termios.TCSASOFT try: - fd = sys.stdin.fileno() - except (AttributeError, ValueError): - fd = None - passwd = fallback_getpass(prompt, stream) - input = sys.stdin - if not stream: - stream = sys.stderr + termios.tcsetattr(fd, tcsetattr_flags, new) + passwd = _raw_input(prompt, stream, input=input) + finally: + termios.tcsetattr(fd, tcsetattr_flags, old) + stream.flush() # issue7208 + except termios.error: + if passwd is not None: + # _raw_input succeeded. The final tcsetattr failed. Reraise + # instead of leaving the terminal in an unknown state. + raise + # We can't control the tty or stdin. Give up and use normal IO. + # fallback_getpass() raises an appropriate warning. + del input, tty # clean up unused file objects before blocking + passwd = fallback_getpass(prompt, stream) - if fd is not None: - try: - old = termios.tcgetattr(fd) # a copy to save - new = old[:] - new[3] &= ~termios.ECHO # 3 == 'lflags' - tcsetattr_flags = termios.TCSAFLUSH - if hasattr(termios, 'TCSASOFT'): - tcsetattr_flags |= termios.TCSASOFT - try: - termios.tcsetattr(fd, tcsetattr_flags, new) - passwd = _raw_input(prompt, stream, input=input) - finally: - termios.tcsetattr(fd, tcsetattr_flags, old) - stream.flush() # issue7208 - except termios.error: - if passwd is not None: - # _raw_input succeeded. The final tcsetattr failed. Reraise - # instead of leaving the terminal in an unknown state. - raise - # We can't control the tty or stdin. Give up and use normal IO. - # fallback_getpass() raises an appropriate warning. - if stream is not input: - # clean up unused file objects before blocking - stack.close() - passwd = fallback_getpass(prompt, stream) - - stream.write('\n') - return passwd + stream.write('\n') + return passwd def win_getpass(prompt='Password: ', stream=None): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/glob.py --- a/Lib/glob.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/glob.py Fri Feb 01 23:12:09 2013 +0100 @@ -9,10 +9,7 @@ def glob(pathname): """Return a list of paths matching a pathname pattern. - The pattern may contain simple shell-style wildcards a la - fnmatch. However, unlike fnmatch, filenames starting with a - dot are special cases that are not matched by '*' and '?' - patterns. + The pattern may contain simple shell-style wildcards a la fnmatch. """ return list(iglob(pathname)) @@ -20,10 +17,7 @@ def iglob(pathname): """Return an iterator which yields the paths matching a pathname pattern. - The pattern may contain simple shell-style wildcards a la - fnmatch. However, unlike fnmatch, filenames starting with a - dot are special cases that are not matched by '*' and '?' - patterns. + The pattern may contain simple shell-style wildcards a la fnmatch. """ if not has_magic(pathname): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/gzip.py --- a/Lib/gzip.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/gzip.py Fri Feb 01 23:12:09 2013 +0100 @@ -65,6 +65,9 @@ # or unsigned. output.write(struct.pack(" self.extrasize: - if not self._read(readsize): - if size > self.extrasize: - size = self.extrasize - break - readsize = min(self.max_read_chunk, readsize * 2) + try: + while size > self.extrasize: + self._read(readsize) + readsize = min(self.max_read_chunk, readsize * 2) + except EOFError: + if size > self.extrasize: + size = self.extrasize offset = self.offset - self.extrastart chunk = self.extrabuf[offset: offset + size] @@ -384,9 +385,12 @@ if self.extrasize <= 0 and self.fileobj is None: return b'' - # For certain input data, a single call to _read() may not return - # any data. In this case, retry until we get some data or reach EOF. - while self.extrasize <= 0 and self._read(): + try: + # For certain input data, a single call to _read() may not return + # any data. In this case, retry until we get some data or reach EOF. + while self.extrasize <= 0: + self._read() + except EOFError: pass if size < 0 or size > self.extrasize: size = self.extrasize @@ -409,9 +413,12 @@ if self.extrasize == 0: if self.fileobj is None: return b'' - # Ensure that we don't return b"" if we haven't reached EOF. - # 1024 is the same buffering heuristic used in read() - while self.extrasize == 0 and self._read(max(n, 1024)): + try: + # Ensure that we don't return b"" if we haven't reached EOF. + while self.extrasize == 0: + # 1024 is the same buffering heuristic used in read() + self._read(max(n, 1024)) + except EOFError: pass offset = self.offset - self.extrastart remaining = self.extrasize @@ -424,14 +431,13 @@ def _read(self, size=1024): if self.fileobj is None: - return False + raise EOFError("Reached EOF") if self._new_member: # If the _new_member flag is set, we have to # jump to the next member, if there is one. self._init_read() - if not self._read_gzip_header(): - return False + self._read_gzip_header() self.decompress = zlib.decompressobj(-zlib.MAX_WBITS) self._new_member = False @@ -448,7 +454,7 @@ self.fileobj.prepend(self.decompress.unused_data, True) self._read_eof() self._add_read_data( uncompress ) - return False + raise EOFError('Reached EOF') uncompress = self.decompress.decompress(buf) self._add_read_data( uncompress ) @@ -464,7 +470,6 @@ # a new member on the next call self._read_eof() self._new_member = True - return True def _add_read_data(self, data): self.crc = zlib.crc32(data, self.crc) & 0xffffffff @@ -479,7 +484,8 @@ # We check the that the computed CRC and size of the # uncompressed data matches the stored values. Note that the size # stored is the true file size mod 2**32. - crc32, isize = struct.unpack(" Largest of the nsmallest + for elem in it: + if elem < los: + insort(result, elem) + pop() + los = result[-1] return result - _heapify_max(result) - _heappushpop = _heappushpop_max - for elem in it: - _heappushpop(result, elem) - result.sort() - return result + # An alternative approach manifests the whole iterable in memory but + # saves comparisons by heapifying all at once. Also, saves time + # over bisect.insort() which has O(n) data movement time for every + # insertion. Finding the n smallest of an m length iterable requires + # O(m) + O(n log m) comparisons. + h = list(iterable) + heapify(h) + return list(map(heappop, repeat(h, min(n, len(h))))) # 'heap' is a heap at all indices >= startpos, except possibly for pos. pos # is the index of a leaf with a possibly out-of-order value. Restore the @@ -304,42 +306,6 @@ heap[pos] = newitem _siftdown(heap, startpos, pos) -def _siftdown_max(heap, startpos, pos): - 'Maxheap variant of _siftdown' - newitem = heap[pos] - # Follow the path to the root, moving parents down until finding a place - # newitem fits. - while pos > startpos: - parentpos = (pos - 1) >> 1 - parent = heap[parentpos] - if parent < newitem: - heap[pos] = parent - pos = parentpos - continue - break - heap[pos] = newitem - -def _siftup_max(heap, pos): - 'Maxheap variant of _siftup' - endpos = len(heap) - startpos = pos - newitem = heap[pos] - # Bubble up the larger child until hitting a leaf. - childpos = 2*pos + 1 # leftmost child position - while childpos < endpos: - # Set childpos to index of larger child. - rightpos = childpos + 1 - if rightpos < endpos and not heap[rightpos] < heap[childpos]: - childpos = rightpos - # Move the larger child up. - heap[pos] = heap[childpos] - pos = childpos - childpos = 2*pos + 1 - # The leaf at pos is empty now. Put newitem there, and bubble it up - # to its final resting place (by sifting its parents down). - heap[pos] = newitem - _siftdown_max(heap, startpos, pos) - # If available, use C implementation try: from _heapq import * diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/hmac.py --- a/Lib/hmac.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/hmac.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,7 +4,7 @@ """ import warnings as _warnings -from _operator import _compare_digest as compare_digest +from operator import _compare_digest as compare_digest trans_5C = bytes((x ^ 0x5C) for x in range(256)) trans_36 = bytes((x ^ 0x36) for x in range(256)) @@ -31,11 +31,11 @@ A hashlib constructor returning a new hash object. Defaults to hashlib.md5. - Note: key and msg must be a bytes or bytearray objects. + Note: key and msg must be bytes objects. """ - if not isinstance(key, (bytes, bytearray)): - raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__) + if not isinstance(key, bytes): + raise TypeError("key: expected bytes, but got %r" % type(key).__name__) if digestmod is None: import hashlib @@ -75,6 +75,8 @@ def update(self, msg): """Update this hashing object with the string msg. """ + if not isinstance(msg, bytes): + raise TypeError("expected bytes, but got %r" % type(msg).__name__) self.inner.update(msg) def copy(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/html/__init__.py --- a/Lib/html/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/html/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,11 @@ General functions for HTML manipulation. """ + +_escape_map = {ord('&'): '&', ord('<'): '<', ord('>'): '>'} +_escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>', + ord('"'): '"', ord('\''): '''} + # NB: this is a candidate for a bytes/string polymorphic interface def escape(s, quote=True): @@ -11,10 +16,6 @@ characters, both double quote (") and single quote (') characters are also translated. """ - s = s.replace("&", "&") # Must be done first! - s = s.replace("<", "<") - s = s.replace(">", ">") if quote: - s = s.replace('"', """) - s = s.replace('\'', "'") - return s + return s.translate(_escape_map_full) + return s.translate(_escape_map) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/html/parser.py --- a/Lib/html/parser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/html/parser.py Fri Feb 01 23:12:09 2013 +0100 @@ -12,8 +12,6 @@ import re import warnings -__all__ = ['HTMLParser'] - # Regular expressions used for parsing interesting_normal = re.compile('[&<]') @@ -251,7 +249,6 @@ if self.strict: self.error("EOF in middle of entity or char ref") else: - k = match.end() if k <= i: k = n i = self.updatepos(i, i + 1) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/http/client.py --- a/Lib/http/client.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/http/client.py Fri Feb 01 23:12:09 2013 +0100 @@ -267,6 +267,8 @@ return email.parser.Parser(_class=_class).parsestr(hstring) +_strict_sentinel = object() + class HTTPResponse(io.RawIOBase): # See RFC 2616 sec 19.6 and RFC 1945 sec 6 for details. @@ -276,7 +278,7 @@ # text following RFC 2047. The basic status line parsing only # accepts iso-8859-1. - def __init__(self, sock, debuglevel=0, method=None, url=None): + def __init__(self, sock, debuglevel=0, strict=_strict_sentinel, method=None, url=None): # If the response includes a content-length header, we need to # make sure that the client doesn't read more than the # specified number of bytes. If it does, it will block until @@ -286,6 +288,10 @@ # clients unless they know what they are doing. self.fp = sock.makefile("rb") self.debuglevel = debuglevel + if strict is not _strict_sentinel: + warnings.warn("the 'strict' argument isn't supported anymore; " + "http.client now always assumes HTTP/1.x compliant servers.", + DeprecationWarning, 2) self._method = method # The HTTPResponse object is returned via urllib. The clients @@ -326,7 +332,7 @@ # empty version will cause next test to fail. version = "" if not version.startswith("HTTP/"): - self._close_conn() + self.close() raise BadStatusLine(line) # The status code is a three-digit number @@ -448,25 +454,22 @@ # otherwise, assume it will close return True - def _close_conn(self): - fp = self.fp - self.fp = None - fp.close() - def close(self): - super().close() # set "closed" flag if self.fp: - self._close_conn() + self.fp.close() + self.fp = None # These implementations are for the benefit of io.BufferedReader. # XXX This class should probably be revised to act more like # the "raw stream" that BufferedReader expects. + @property + def closed(self): + return self.isclosed() + def flush(self): - super().flush() - if self.fp: - self.fp.flush() + self.fp.flush() def readable(self): return True @@ -474,7 +477,6 @@ # End of "raw stream" methods def isclosed(self): - """True if the connection is closed.""" # NOTE: it is possible that we will not ever call self.close(). This # case occurs when will_close is TRUE, length is None, and we # read up to the last byte, but NOT past it. @@ -488,7 +490,7 @@ return b"" if self._method == "HEAD": - self._close_conn() + self.close() return b"" if amt is not None: @@ -505,13 +507,9 @@ if self.length is None: s = self.fp.read() else: - try: - s = self._safe_read(self.length) - except IncompleteRead: - self._close_conn() - raise + s = self._safe_read(self.length) self.length = 0 - self._close_conn() # we read everything + self.close() # we read everything return s def readinto(self, b): @@ -519,7 +517,7 @@ return 0 if self._method == "HEAD": - self._close_conn() + self.close() return 0 if self.chunked: @@ -534,14 +532,13 @@ # connection, and the user is reading more bytes than will be provided # (for example, reading in 1k chunks) n = self.fp.readinto(b) - if not n: - # Ideally, we would raise IncompleteRead if the content-length - # wasn't satisfied, but it might break compatibility. - self._close_conn() - elif self.length is not None: + if self.length is not None: self.length -= n if not self.length: - self._close_conn() + self.close() + else: + if not n: + self.close() return n def _read_next_chunk_size(self): @@ -557,7 +554,7 @@ except ValueError: # close the connection as protocol synchronisation is # probably lost - self._close_conn() + self.close() raise def _read_and_discard_trailer(self): @@ -595,7 +592,7 @@ self._read_and_discard_trailer() # we read everything; close the "file" - self._close_conn() + self.close() return b''.join(value) @@ -636,7 +633,7 @@ self._read_and_discard_trailer() # we read everything; close the "file" - self._close_conn() + self.close() return total_bytes @@ -731,8 +728,12 @@ # as a reasonable estimate of the maximum MSS. mss = 16384 - def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, - source_address=None): + def __init__(self, host, port=None, strict=_strict_sentinel, + timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None): + if strict is not _strict_sentinel: + warnings.warn("the 'strict' argument isn't supported anymore; " + "http.client now always assumes HTTP/1.x compliant servers.", + DeprecationWarning, 2) self.timeout = timeout self.source_address = source_address self.sock = None @@ -864,7 +865,7 @@ if encode: datablock = datablock.encode("iso-8859-1") self.sock.sendall(datablock) - return + try: self.sock.sendall(data) except TypeError: @@ -1167,10 +1168,9 @@ # XXX Should key_file and cert_file be deprecated in favour of context? def __init__(self, host, port=None, key_file=None, cert_file=None, - timeout=socket._GLOBAL_DEFAULT_TIMEOUT, - source_address=None, *, context=None, - check_hostname=None): - super(HTTPSConnection, self).__init__(host, port, timeout, + strict=_strict_sentinel, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, + source_address=None, *, context=None, check_hostname=None): + super(HTTPSConnection, self).__init__(host, port, strict, timeout, source_address) self.key_file = key_file self.cert_file = cert_file diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/http/cookiejar.py --- a/Lib/http/cookiejar.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/http/cookiejar.py Fri Feb 01 23:12:09 2013 +0100 @@ -704,7 +704,7 @@ """ req_host = request_host(request) - if not domain_match(req_host, reach(request.origin_req_host)): + if not domain_match(req_host, reach(request.get_origin_req_host())): return True else: return False @@ -1761,8 +1761,11 @@ if self.filename is not None: filename = self.filename else: raise ValueError(MISSING_FILENAME_TEXT) - with open(filename) as f: + f = open(filename) + try: self._really_load(f, filename, ignore_discard, ignore_expires) + finally: + f.close() def revert(self, filename=None, ignore_discard=False, ignore_expires=False): @@ -1853,12 +1856,15 @@ if self.filename is not None: filename = self.filename else: raise ValueError(MISSING_FILENAME_TEXT) - with open(filename, "w") as f: + f = open(filename, "w") + try: # There really isn't an LWP Cookies 2.0 format, but this indicates # that there is extra information in here (domain_dot and # port_spec) while still being compatible with libwww-perl, I hope. f.write("#LWP-Cookies-2.0\n") f.write(self.as_lwp_str(ignore_discard, ignore_expires)) + finally: + f.close() def _really_load(self, f, filename, ignore_discard, ignore_expires): magic = f.readline() @@ -2049,7 +2055,8 @@ if self.filename is not None: filename = self.filename else: raise ValueError(MISSING_FILENAME_TEXT) - with open(filename, "w") as f: + f = open(filename, "w") + try: f.write(self.header) now = time.time() for cookie in self: @@ -2078,3 +2085,5 @@ "\t".join([cookie.domain, initial_dot, cookie.path, secure, expires, name, value])+ "\n") + finally: + f.close() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/http/server.py --- a/Lib/http/server.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/http/server.py Fri Feb 01 23:12:09 2013 +0100 @@ -401,17 +401,12 @@ while not self.close_connection: self.handle_one_request() - def send_error(self, code, message=None, explain=None): + def send_error(self, code, message=None): """Send and log an error reply. - Arguments are - * code: an HTTP error code - 3 digits - * message: a simple optional 1 line reason phrase. - *( HTAB / SP / VCHAR / %x80-FF ) - defaults to short entry matching the response code - * explain: a detailed message defaults to the long entry - matching the response code. + Arguments are the error code, and a detailed message. + The detailed message defaults to the short entry matching the + response code. This sends an error response (so it must be called before any output has been generated), logs the error, and finally sends @@ -425,12 +420,11 @@ shortmsg, longmsg = '???', '???' if message is None: message = shortmsg - if explain is None: - explain = longmsg + explain = longmsg self.log_error("code %d, message %s", code, message) # using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201) content = (self.error_message_format % - {'code': code, 'message': _quote_html(message), 'explain': _quote_html(explain)}) + {'code': code, 'message': _quote_html(message), 'explain': explain}) body = content.encode('UTF-8', 'replace') self.send_response(code, message) self.send_header("Content-Type", self.error_content_type) @@ -1131,8 +1125,8 @@ os.setuid(nobody) except OSError: pass - os.dup2(self.rfile.fileno(), 0) - os.dup2(self.wfile.fileno(), 1) + os.dup2(self.rfile.fileno(), 0, cloexec=False) + os.dup2(self.wfile.fileno(), 1, cloexec=False) os.execve(scriptfile, args, env) except: self.server.handle_error(self.request, self.client_address) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/Bindings.py --- a/Lib/idlelib/Bindings.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/Bindings.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,7 +15,7 @@ menudefs = [ # underscore prefixes character to underscore ('file', [ - ('_New File', '<>'), + ('_New Window', '<>'), ('_Open...', '<>'), ('Open _Module...', '<>'), ('Class _Browser', '<>'), @@ -98,10 +98,6 @@ # menu del menudefs[-1][1][0:2] - # Remove the 'Configure' entry from the options menu, it is in the - # application menu as 'Preferences' - del menudefs[-2][1][0:2] - default_keydefs = idleConf.GetCurrentKeySet() del sys diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/CallTips.py Fri Feb 01 23:12:09 2013 +0100 @@ -264,6 +264,4 @@ print("%d of %d tests failed" % (num_fail, num_tests)) if __name__ == '__main__': - #main() - from unittest import main - main('idlelib.idle_test.test_calltips', verbosity=2, exit=False) + main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/ColorDelegator.py --- a/Lib/idlelib/ColorDelegator.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/ColorDelegator.py Fri Feb 01 23:12:09 2013 +0100 @@ -51,10 +51,6 @@ self.config_colors() self.bind("<>", self.toggle_colorize_event) self.notify_range("1.0", "end") - else: - # No delegate - stop any colorizing - self.stop_colorizing = True - self.allow_colorizing = False def config_colors(self): for tag, cnf in self.tagdefs.items(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/Delegator.py --- a/Lib/idlelib/Delegator.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/Delegator.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,12 +4,12 @@ def __init__(self, delegate=None): self.delegate = delegate - self.__cache = set() + self.__cache = {} def __getattr__(self, name): attr = getattr(self.delegate, name) # May raise AttributeError setattr(self, name, attr) - self.__cache.add(name) + self.__cache[name] = attr return attr def resetcache(self): @@ -20,6 +20,14 @@ pass self.__cache.clear() + def cachereport(self): + keys = list(self.__cache.keys()) + keys.sort() + print(keys) + def setdelegate(self, delegate): self.resetcache() self.delegate = delegate + + def getdelegate(self): + return self.delegate diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/EditorWindow.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,5 @@ +import imp import importlib -import importlib.abc import os import re import string @@ -35,6 +35,34 @@ release += '%s%s' % (level[0], serial) return release +def _find_module(fullname, path=None): + """Version of imp.find_module() that handles hierarchical module names""" + + file = None + for tgt in fullname.split('.'): + if file is not None: + file.close() # close intermediate files + (file, filename, descr) = imp.find_module(tgt, path) + if descr[2] == imp.PY_SOURCE: + break # find but not load the source file + module = imp.load_module(tgt, file, filename, descr) + try: + path = module.__path__ + except AttributeError: + raise ImportError('No source for module ' + module.__name__) + if descr[2] != imp.PY_SOURCE: + # If all of the above fails and didn't raise an exception,fallback + # to a straight import which can find __init__.py in a package. + m = __import__(fullname) + try: + filename = m.__file__ + except AttributeError: + pass + else: + file = None + descr = os.path.splitext(filename)[1], None, imp.PY_SOURCE + return file, filename, descr + class HelpDialog(object): @@ -288,10 +316,11 @@ self.good_load = True is_py_src = self.ispythonsource(filename) self.set_indentation_params(is_py_src) + if is_py_src: + self.color = color = self.ColorDelegator() + per.insertfilter(color) else: io.set_filename(filename) - self.good_load = True - self.ResetColorizer() self.saved_change_hook() self.update_recent_files_list() @@ -312,36 +341,6 @@ self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror - self._highlight_workaround() # Fix selection tags on Windows - - def _highlight_workaround(self): - # On Windows, Tk removes painting of the selection - # tags which is different behavior than on Linux and Mac. - # See issue14146 for more information. - if not sys.platform.startswith('win'): - return - - text = self.text - text.event_add("<>", "") - text.event_add("<>", "") - def highlight_fix(focus): - sel_range = text.tag_ranges("sel") - if sel_range: - if focus == 'out': - HILITE_CONFIG = idleConf.GetHighlight( - idleConf.CurrentTheme(), 'hilite') - text.tag_config("sel_fix", HILITE_CONFIG) - text.tag_raise("sel_fix") - text.tag_add("sel_fix", *sel_range) - elif focus == 'in': - text.tag_remove("sel_fix", "1.0", "end") - - text.bind("<>", - lambda ev: highlight_fix("out")) - text.bind("<>", - lambda ev: highlight_fix("in")) - - def _filename_to_unicode(self, filename): """convert filename to unicode in order to display it in Tk""" if isinstance(filename, str) or not filename: @@ -435,6 +434,7 @@ ] if macosxSupport.runningAsOSXApp(): + del menu_specs[-3] menu_specs[-2] = ("windows", "_Window") @@ -479,12 +479,7 @@ if iswin: self.text.config(cursor="arrow") - for item in self.rmenu_specs: - try: - label, eventname, verify_state = item - except ValueError: # see issue1207589 - continue - + for label, eventname, verify_state in self.rmenu_specs: if verify_state is None: continue state = getattr(self, verify_state)() @@ -502,8 +497,7 @@ def make_rmenu(self): rmenu = Menu(self.text, tearoff=0) - for item in self.rmenu_specs: - label, eventname = item[0], item[1] + for label, eventname, _ in self.rmenu_specs: if label is not None: def command(text=self.text, eventname=eventname): text.event_generate(eventname) @@ -659,29 +653,20 @@ return # XXX Ought to insert current file's directory in front of path try: - loader = importlib.find_loader(name) - except (ValueError, ImportError) as msg: + (f, file, (suffix, mode, type)) = _find_module(name) + except (NameError, ImportError) as msg: tkMessageBox.showerror("Import error", str(msg), parent=self.text) return - if loader is None: - tkMessageBox.showerror("Import error", "module not found", - parent=self.text) + if type != imp.PY_SOURCE: + tkMessageBox.showerror("Unsupported type", + "%s is not a source module" % name, parent=self.text) return - if not isinstance(loader, importlib.abc.SourceLoader): - tkMessageBox.showerror("Import error", "not a source-based module", - parent=self.text) - return - try: - file_path = loader.get_filename(name) - except AttributeError: - tkMessageBox.showerror("Import error", - "loader does not support get_filename", - parent=self.text) - return + if f: + f.close() if self.flist: - self.flist.open(file_path) + self.flist.open(file) else: - self.io.loadfile(file_path) + self.io.loadfile(file) def open_class_browser(self, event=None): filename = self.io.filename @@ -821,11 +806,7 @@ menuEventDict[menu[0]][prepstr(item[0])[1]] = item[1] for menubarItem in self.menudict: menu = self.menudict[menubarItem] - end = menu.index(END) - if end is None: - # Skip empty menus - continue - end += 1 + end = menu.index(END) + 1 for index in range(0, end): if menu.type(index) == 'command': accel = menu.entrycget(index, 'accelerator') @@ -1452,7 +1433,6 @@ def tabify_region_event(self, event): head, tail, chars, lines = self.get_region() tabwidth = self._asktabwidth() - if tabwidth is None: return for pos in range(len(lines)): line = lines[pos] if line: @@ -1464,7 +1444,6 @@ def untabify_region_event(self, event): head, tail, chars, lines = self.get_region() tabwidth = self._asktabwidth() - if tabwidth is None: return for pos in range(len(lines)): lines[pos] = lines[pos].expandtabs(tabwidth) self.set_region(head, tail, chars, lines) @@ -1558,7 +1537,7 @@ parent=self.text, initialvalue=self.indentwidth, minvalue=2, - maxvalue=16) + maxvalue=16) or self.tabwidth # Guess indentwidth from text content. # Return guessed indentwidth. This should not be believed unless diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/GrepDialog.py --- a/Lib/idlelib/GrepDialog.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/GrepDialog.py Fri Feb 01 23:12:09 2013 +0100 @@ -81,24 +81,36 @@ hits = 0 for fn in list: try: - with open(fn, errors='replace') as f: - for lineno, line in enumerate(f, 1): - if line[-1:] == '\n': - line = line[:-1] - if prog.search(line): - sys.stdout.write("%s: %s: %s\n" % - (fn, lineno, line)) - hits += 1 + f = open(fn, errors='replace') except OSError as msg: print(msg) - print(("Hits found: %s\n" - "(Hint: right-click to open locations.)" - % hits) if hits else "No hits.") + continue + lineno = 0 + while 1: + block = f.readlines(100000) + if not block: + break + for line in block: + lineno = lineno + 1 + if line[-1:] == '\n': + line = line[:-1] + if prog.search(line): + sys.stdout.write("%s: %s: %s\n" % (fn, lineno, line)) + hits = hits + 1 + if hits: + if hits == 1: + s = "" + else: + s = "s" + print("Found", hits, "hit%s." % s) + print("(Hint: right-click to open locations.)") + else: + print("No hits.") def findfiles(self, dir, base, rec): try: names = os.listdir(dir or os.curdir) - except OSerror as msg: + except OSError as msg: print(msg) return [] list = [] @@ -119,9 +131,3 @@ if self.top: self.top.grab_release() self.top.withdraw() - -if __name__ == "__main__": - # A human test is a bit tricky since EditorWindow() imports this module. - # Hence Idle must be restarted after editing this file for a live test. - import unittest - unittest.main('idlelib.idle_test.test_grep', verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/MultiCall.py --- a/Lib/idlelib/MultiCall.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/MultiCall.py Fri Feb 01 23:12:09 2013 +0100 @@ -170,9 +170,8 @@ break ishandlerrunning[:] = [] # Call all functions in doafterhandler and remove them from list - for f in doafterhandler: - f() - doafterhandler[:] = [] + while doafterhandler: + doafterhandler.pop()() if r: return r return handler diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/NEWS.txt --- a/Lib/idlelib/NEWS.txt Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/NEWS.txt Fri Feb 01 23:12:09 2013 +0100 @@ -1,13 +1,8 @@ What's New in IDLE 3.4.0? ========================= -- Issue #17390: Display Python version on Idle title bar. - Initial patch by Edmond Burnett. - - Issue #5066: Update IDLE docs. Patch by Todd Rovito. -- Issue #17625: Close the replace dialog after it is used. - - Issue #16226: Fix IDLE Path Browser crash. (Patch by Roger Serwy) @@ -18,8 +13,6 @@ What's New in IDLE 3.3.0? ========================= -- Issue #17625: Close the replace dialog after it is used. - - Issue #7163: Propagate return value of sys.stdout.write. - Issue #15318: Prevent writing to sys.stdin. @@ -876,3 +869,7 @@ Refer to HISTORY.txt for additional information on earlier releases. -------------------------------------------------------------------- + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/PathBrowser.py --- a/Lib/idlelib/PathBrowser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/PathBrowser.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,6 @@ import os import sys +import imp import importlib.machinery from idlelib.TreeWidget import TreeItem @@ -94,5 +95,4 @@ mainloop() if __name__ == "__main__": - from unittest import main - main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False) + main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/PyShell.py Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,6 @@ import linecache from code import InteractiveInterpreter -from platform import python_version try: from tkinter import * @@ -45,55 +44,35 @@ # internal warnings to the console. ScriptBinding.check_syntax() will # temporarily redirect the stream to the shell window to display warnings when # checking user's code. -warning_stream = sys.__stderr__ # None, at least on Windows, if no console. -import warnings - -def idle_formatwarning(message, category, filename, lineno, line=None): - """Format warnings the IDLE way.""" - - s = "\nWarning (from warnings module):\n" - s += ' File \"%s\", line %s\n' % (filename, lineno) - if line is None: - line = linecache.getline(filename, lineno) - line = line.strip() - if line: - s += " %s\n" % line - s += "%s: %s\n" % (category.__name__, message) - return s - -def idle_showwarning( - message, category, filename, lineno, file=None, line=None): - """Show Idle-format warning (after replacing warnings.showwarning). - - The differences are the formatter called, the file=None replacement, - which can be None, the capture of the consequence AttributeError, - and the output of a hard-coded prompt. - """ - if file is None: - file = warning_stream - try: - file.write(idle_formatwarning( - message, category, filename, lineno, line=line)) - file.write(">>> ") - except (AttributeError, OSError): - pass # if file (probably __stderr__) is invalid, skip warning. - -_warnings_showwarning = None - -def capture_warnings(capture): - "Replace warning.showwarning with idle_showwarning, or reverse." - - global _warnings_showwarning - if capture: - if _warnings_showwarning is None: - _warnings_showwarning = warnings.showwarning - warnings.showwarning = idle_showwarning - else: - if _warnings_showwarning is not None: - warnings.showwarning = _warnings_showwarning - _warnings_showwarning = None - -capture_warnings(True) +global warning_stream +warning_stream = sys.__stderr__ +try: + import warnings +except ImportError: + pass +else: + def idle_showwarning(message, category, filename, lineno, + file=None, line=None): + if file is None: + file = warning_stream + try: + file.write(warnings.formatwarning(message, category, filename, + lineno, line=line)) + except OSError: + pass ## file (probably __stderr__) is invalid, warning dropped. + warnings.showwarning = idle_showwarning + def idle_formatwarning(message, category, filename, lineno, line=None): + """Format warnings the IDLE way""" + s = "\nWarning (from warnings module):\n" + s += ' File \"%s\", line %s\n' % (filename, lineno) + if line is None: + line = linecache.getline(filename, lineno) + line = line.strip() + if line: + s += " %s\n" % line + s += "%s: %s\n>>> " % (category.__name__, message) + return s + warnings.formatwarning = idle_formatwarning def extended_linecache_checkcache(filename=None, orig_checkcache=linecache.checkcache): @@ -131,13 +110,12 @@ self.breakpointPath = os.path.join(idleConf.GetUserCfgDir(), 'breakpoints.lst') # whenever a file is changed, restore breakpoints + if self.io.filename: self.restore_file_breaks() def filename_changed_hook(old_hook=self.io.filename_change_hook, self=self): self.restore_file_breaks() old_hook() self.io.set_filename_change_hook(filename_changed_hook) - if self.io.filename: - self.restore_file_breaks() rmenu_specs = [ ("Cut", "<>", "rmenu_check_cut"), @@ -254,9 +232,6 @@ def restore_file_breaks(self): self.text.update() # this enables setting "BREAK" tags to be visible - if self.io is None: - # can happen if IDLE closes due to the .update() call - return filename = self.io.filename if filename is None: return @@ -387,7 +362,6 @@ self.port = PORT self.original_compiler_flags = self.compile.compiler.flags - _afterid = None rpcclt = None rpcsubproc = None @@ -443,8 +417,10 @@ except socket.timeout as err: self.display_no_subprocess_error() return None - self.rpcclt.register("console", self.tkconsole) - self.rpcclt.register("stdin", self.tkconsole.stdin) + # Can't regiter self.tkconsole.stdin, since run.py wants to + # call non-TextIO methods on it (such as getvar) + # XXX should be renamed to "console" + self.rpcclt.register("stdin", self.tkconsole) self.rpcclt.register("stdout", self.tkconsole.stdout) self.rpcclt.register("stderr", self.tkconsole.stderr) self.rpcclt.register("flist", self.tkconsole.flist) @@ -479,7 +455,6 @@ self.display_no_subprocess_error() return None self.transfer_path(with_cwd=with_cwd) - console.stop_readline() # annotate restart in shell window and mark it console.text.delete("iomark", "end-1c") if was_executing: @@ -507,8 +482,6 @@ threading.Thread(target=self.__request_interrupt).start() def kill_subprocess(self): - if self._afterid is not None: - self.tkconsole.text.after_cancel(self._afterid) try: self.rpcclt.listening_sock.close() except AttributeError: # no socket @@ -584,8 +557,8 @@ pass # Reschedule myself if not self.tkconsole.closing: - self._afterid = self.tkconsole.text.after( - self.tkconsole.pollinterval, self.poll_subprocess) + self.tkconsole.text.after(self.tkconsole.pollinterval, + self.poll_subprocess) debugger = None @@ -828,7 +801,7 @@ class PyShell(OutputWindow): - shell_title = "Python " + python_version() + " Shell" + shell_title = "Python Shell" # Override classes ColorDelegator = ModifiedColorDelegator @@ -845,6 +818,7 @@ ] if macosxSupport.runningAsOSXApp(): + del menu_specs[-3] menu_specs[-2] = ("windows", "_Window") @@ -880,6 +854,8 @@ text.bind("<>", self.open_stack_viewer) text.bind("<>", self.toggle_debugger) text.bind("<>", self.toggle_jit_stack_viewer) + self.color = color = self.ColorDelegator() + self.per.insertfilter(color) if use_subprocess: text.bind("<>", self.view_restart_mark) text.bind("<>", self.restart_shell) @@ -888,10 +864,10 @@ self.save_stderr = sys.stderr self.save_stdin = sys.stdin from idlelib import IOBinding - self.stdin = PseudoInputFile(self, "stdin", IOBinding.encoding) - self.stdout = PseudoOutputFile(self, "stdout", IOBinding.encoding) - self.stderr = PseudoOutputFile(self, "stderr", IOBinding.encoding) - self.console = PseudoOutputFile(self, "console", IOBinding.encoding) + self.stdin = PseudoInputFile(self) + self.stdout = PseudoFile(self, "stdout", IOBinding.encoding) + self.stderr = PseudoFile(self, "stderr", IOBinding.encoding) + self.console = PseudoFile(self, "console", IOBinding.encoding) if not use_subprocess: sys.stdout = self.stdout sys.stderr = self.stderr @@ -917,7 +893,6 @@ canceled = False endoffile = False closing = False - _stop_readline_flag = False def set_warning_stream(self, stream): global warning_stream @@ -993,9 +968,14 @@ parent=self.text) if response is False: return "cancel" - self.stop_readline() + if self.reading: + self.top.quit() self.canceled = True self.closing = True + # Wait for poll_subprocess() rescheduling to stop + self.text.after(2 * self.pollinterval, self.close2) + + def close2(self): return EditorWindow.close(self) def _close(self): @@ -1047,12 +1027,6 @@ tkinter._default_root = None # 03Jan04 KBK What's this? return True - def stop_readline(self): - if not self.reading: # no nested mainloop to exit. - return - self._stop_readline_flag = True - self.top.quit() - def readline(self): save = self.reading try: @@ -1060,9 +1034,6 @@ self.top.mainloop() # nested mainloop() finally: self.reading = save - if self._stop_readline_flag: - self._stop_readline_flag = False - return "" line = self.text.get("iomark", "end-1c") if len(line) == 0: # may be EOF if we quit our mainloop with Ctrl-C line = "\n" @@ -1307,85 +1278,36 @@ return 'disabled' return super().rmenu_check_paste() -class PseudoFile(io.TextIOBase): +class PseudoFile(object): def __init__(self, shell, tags, encoding=None): self.shell = shell self.tags = tags - self._encoding = encoding + self.encoding = encoding - @property - def encoding(self): - return self._encoding + def write(self, s): + if not isinstance(s, str): + raise TypeError('must be str, not ' + type(s).__name__) + return self.shell.write(s, self.tags) - @property - def name(self): - return '<%s>' % self.tags + def writelines(self, lines): + for line in lines: + self.write(line) + + def flush(self): + pass def isatty(self): return True - -class PseudoOutputFile(PseudoFile): - - def writable(self): - return True +class PseudoInputFile(object): + def __init__(self, shell): + self.readline = shell.readline + self.isatty = shell.isatty def write(self, s): - if self.closed: - raise ValueError("write to closed file") - if not isinstance(s, str): - raise TypeError('must be str, not ' + type(s).__name__) - return self.shell.write(s, self.tags) - - -class PseudoInputFile(PseudoFile): - - def __init__(self, shell, tags, encoding=None): - PseudoFile.__init__(self, shell, tags, encoding) - self._line_buffer = '' - - def readable(self): - return True - - def read(self, size=-1): - if self.closed: - raise ValueError("read from closed file") - if size is None: - size = -1 - elif not isinstance(size, int): - raise TypeError('must be int, not ' + type(size).__name__) - result = self._line_buffer - self._line_buffer = '' - if size < 0: - while True: - line = self.shell.readline() - if not line: break - result += line - else: - while len(result) < size: - line = self.shell.readline() - if not line: break - result += line - self._line_buffer = result[size:] - result = result[:size] - return result - - def readline(self, size=-1): - if self.closed: - raise ValueError("read from closed file") - if size is None: - size = -1 - elif not isinstance(size, int): - raise TypeError('must be int, not ' + type(size).__name__) - line = self._line_buffer or self.shell.readline() - if size < 0: - size = len(line) - self._line_buffer = line[size:] - return line[:size] - - def close(self): - self.shell.close() + raise io.UnsupportedOperation("not writable") + writelines = write usage_msg = """\ @@ -1445,9 +1367,8 @@ def main(): global flist, root, use_subprocess - capture_warnings(True) use_subprocess = True - enable_shell = False + enable_shell = True enable_edit = False debug = False cmd = None @@ -1468,6 +1389,7 @@ enable_shell = True if o == '-e': enable_edit = True + enable_shell = False if o == '-h': sys.stdout.write(usage_msg) sys.exit() @@ -1520,7 +1442,6 @@ edit_start = idleConf.GetOption('main', 'General', 'editor-on-startup', type='bool') enable_edit = enable_edit or edit_start - enable_shell = enable_shell or not enable_edit # start editor and/or shell windows: root = Tk(className="Idle") @@ -1580,10 +1501,7 @@ while flist.inversedict: # keep IDLE running while files are open. root.mainloop() root.destroy() - capture_warnings(False) if __name__ == "__main__": sys.modules['PyShell'] = sys.modules['__main__'] main() - -capture_warnings(False) # Make sure turned off; see issue 18081 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/ReplaceDialog.py --- a/Lib/idlelib/ReplaceDialog.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/ReplaceDialog.py Fri Feb 01 23:12:09 2013 +0100 @@ -123,7 +123,6 @@ text.undo_block_stop() if first and last: self.show_hit(first, last) - self.close() def do_find(self, ok=0): if not self.engine.getprog(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/RstripExtension.py --- a/Lib/idlelib/RstripExtension.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/RstripExtension.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,9 +1,13 @@ 'Provides "Strip trailing whitespace" under the "Format" menu.' +__author__ = "Roger D. Serwy " + class RstripExtension: menudefs = [ - ('format', [None, ('Strip trailing whitespace', '<>'), ] ), ] + ('format', [None, + ('Strip trailing whitespace', '<>'), + ]),] def __init__(self, editwin): self.editwin = editwin @@ -16,18 +20,10 @@ undo.undo_block_start() - end_line = int(float(text.index('end'))) + end_line = int(float(text.index('end'))) + 1 for cur in range(1, end_line): - txt = text.get('%i.0' % cur, '%i.end' % cur) - raw = len(txt) + txt = text.get('%i.0' % cur, '%i.0 lineend' % cur) cut = len(txt.rstrip()) - # Since text.delete() marks file as changed, even if not, - # only call it when needed to actually delete something. - if cut < raw: - text.delete('%i.%i' % (cur, cut), '%i.end' % cur) + text.delete('%i.%i' % (cur, cut), '%i.0 lineend' % cur) undo.undo_block_stop() - -if __name__ == "__main__": - import unittest - unittest.main('idlelib.idle_test.test_rstrip', verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/SearchDialog.py --- a/Lib/idlelib/SearchDialog.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/SearchDialog.py Fri Feb 01 23:12:09 2013 +0100 @@ -24,12 +24,13 @@ def create_widgets(self): f = SearchDialogBase.create_widgets(self) - self.make_button("Find Next", self.default_command, 1) + self.make_button("Find", self.default_command, 1) def default_command(self, event=None): if not self.engine.getprog(): return - self.find_again(self.text) + if self.find_again(self.text): + self.close() def find_again(self, text): if not self.engine.getpat(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/TreeWidget.py --- a/Lib/idlelib/TreeWidget.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/TreeWidget.py Fri Feb 01 23:12:09 2013 +0100 @@ -16,6 +16,7 @@ import os from tkinter import * +import imp from idlelib import ZoomHeight from idlelib.configHandler import idleConf diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/aboutDialog.py --- a/Lib/idlelib/aboutDialog.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/aboutDialog.py Fri Feb 01 23:12:09 2013 +0100 @@ -66,7 +66,12 @@ labelPythonVer = Label(frameBg, text='Python version: ' + \ sys.version.split()[0], fg=self.fg, bg=self.bg) labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0) - tkVer = self.tk.call('info', 'patchlevel') + # handle weird tk version num in windoze python >= 1.6 (?!?) + tkVer = repr(TkVersion).split('.') + tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:] + if tkVer[len(tkVer)-1] == '': + tkVer[len(tkVer)-1] = '0' + tkVer = '.'.join(tkVer) labelTkVer = Label(frameBg, text='Tk version: '+ tkVer, fg=self.fg, bg=self.bg) labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/configHandler.py Fri Feb 01 23:12:09 2013 +0100 @@ -37,7 +37,7 @@ cfgFile - string, fully specified configuration file name """ self.file=cfgFile - ConfigParser.__init__(self, defaults=cfgDefaults, strict=False) + ConfigParser.__init__(self,defaults=cfgDefaults) def Get(self, section, option, type=None, default=None, raw=False): """ diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/configSectionNameDialog.py --- a/Lib/idlelib/configSectionNameDialog.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/configSectionNameDialog.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,106 +1,97 @@ """ Dialog that allows user to specify a new config file section name. Used to get new highlight theme and keybinding set names. -The 'return value' for the dialog, used two placed in configDialog.py, -is the .result attribute set in the Ok and Cancel methods. """ from tkinter import * import tkinter.messagebox as tkMessageBox class GetCfgSectionNameDialog(Toplevel): - def __init__(self, parent, title, message, used_names): + def __init__(self,parent,title,message,usedNames): """ message - string, informational message to display - used_names - string collection, names already in use for validity check + usedNames - list, list of names already in use for validity check """ Toplevel.__init__(self, parent) self.configure(borderwidth=5) - self.resizable(height=FALSE, width=FALSE) + self.resizable(height=FALSE,width=FALSE) self.title(title) self.transient(parent) self.grab_set() self.protocol("WM_DELETE_WINDOW", self.Cancel) self.parent = parent - self.message = message - self.used_names = used_names - self.create_widgets() - self.withdraw() #hide while setting geometry + self.message=message + self.usedNames=usedNames + self.result='' + self.CreateWidgets() + self.withdraw() #hide while setting geometry self.update_idletasks() #needs to be done here so that the winfo_reqwidth is valid self.messageInfo.config(width=self.frameMain.winfo_reqwidth()) - self.geometry( - "+%d+%d" % ( - parent.winfo_rootx() + - (parent.winfo_width()/2 - self.winfo_reqwidth()/2), - parent.winfo_rooty() + - (parent.winfo_height()/2 - self.winfo_reqheight()/2) - ) ) #centre dialog over parent - self.deiconify() #geometry set, unhide + self.geometry("+%d+%d" % + ((parent.winfo_rootx()+((parent.winfo_width()/2) + -(self.winfo_reqwidth()/2)), + parent.winfo_rooty()+((parent.winfo_height()/2) + -(self.winfo_reqheight()/2)) )) ) #centre dialog over parent + self.deiconify() #geometry set, unhide self.wait_window() - def create_widgets(self): - self.name = StringVar(self.parent) - self.fontSize = StringVar(self.parent) - self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN) - self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH) - self.messageInfo = Message(self.frameMain, anchor=W, justify=LEFT, - padx=5, pady=5, text=self.message) #,aspect=200) - entryName = Entry(self.frameMain, textvariable=self.name, width=30) + def CreateWidgets(self): + self.name=StringVar(self) + self.fontSize=StringVar(self) + self.frameMain = Frame(self,borderwidth=2,relief=SUNKEN) + self.frameMain.pack(side=TOP,expand=TRUE,fill=BOTH) + self.messageInfo=Message(self.frameMain,anchor=W,justify=LEFT,padx=5,pady=5, + text=self.message)#,aspect=200) + entryName=Entry(self.frameMain,textvariable=self.name,width=30) entryName.focus_set() - self.messageInfo.pack(padx=5, pady=5) #, expand=TRUE, fill=BOTH) - entryName.pack(padx=5, pady=5) + self.messageInfo.pack(padx=5,pady=5)#,expand=TRUE,fill=BOTH) + entryName.pack(padx=5,pady=5) + frameButtons=Frame(self) + frameButtons.pack(side=BOTTOM,fill=X) + self.buttonOk = Button(frameButtons,text='Ok', + width=8,command=self.Ok) + self.buttonOk.grid(row=0,column=0,padx=5,pady=5) + self.buttonCancel = Button(frameButtons,text='Cancel', + width=8,command=self.Cancel) + self.buttonCancel.grid(row=0,column=1,padx=5,pady=5) - frameButtons = Frame(self, pady=2) - frameButtons.pack(side=BOTTOM) - self.buttonOk = Button(frameButtons, text='Ok', - width=8, command=self.Ok) - self.buttonOk.pack(side=LEFT, padx=5) - self.buttonCancel = Button(frameButtons, text='Cancel', - width=8, command=self.Cancel) - self.buttonCancel.pack(side=RIGHT, padx=5) - - def name_ok(self): - ''' After stripping entered name, check that it is a sensible - ConfigParser file section name. Return it if it is, '' if not. - ''' - name = self.name.get().strip() + def NameOk(self): + #simple validity check for a sensible + #ConfigParser file section name + nameOk=1 + name=self.name.get() + name.strip() if not name: #no name specified tkMessageBox.showerror(title='Name Error', message='No name specified.', parent=self) + nameOk=0 elif len(name)>30: #name too long tkMessageBox.showerror(title='Name Error', message='Name too long. It should be no more than '+ '30 characters.', parent=self) - name = '' - elif name in self.used_names: + nameOk=0 + elif name in self.usedNames: tkMessageBox.showerror(title='Name Error', message='This name is already in use.', parent=self) - name = '' - return name + nameOk=0 + return nameOk def Ok(self, event=None): - name = self.name_ok() - if name: - self.result = name + if self.NameOk(): + self.result=self.name.get().strip() self.destroy() def Cancel(self, event=None): - self.result = '' + self.result='' self.destroy() if __name__ == '__main__': - import unittest - unittest.main('idlelib.idle_test.test_config_name', verbosity=2, exit=False) - - # also human test the dialog - root = Tk() + #test the dialog + root=Tk() def run(): + keySeq='' dlg=GetCfgSectionNameDialog(root,'Get Name', - "After the text entered with [Ok] is stripped, , " - "'abc', or more that 30 chars are errors. " - "Close with a valid entry (printed), [Cancel], or [X]", - {'abc'}) + 'The information here should need to be word wrapped. Test.') print(dlg.result) - Message(root, text='').pack() # will be needed for oher dialog tests - Button(root, text='Click to begin dialog test', command=run).pack() + Button(root,text='Dialog',command=run).pack() root.mainloop() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/extend.txt --- a/Lib/idlelib/extend.txt Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/extend.txt Fri Feb 01 23:12:09 2013 +0100 @@ -54,7 +54,7 @@ implement. (They are also not required to create keybindings, but in that case there must be empty bindings in cofig-extensions.def) -Here is a complete example: +Here is a complete example example: class ZoomHeight: @@ -72,7 +72,7 @@ "...Do what you want here..." The final piece of the puzzle is the file "config-extensions.def", which is -used to configure the loading of extensions and to establish key (or, more +used to to configure the loading of extensions and to establish key (or, more generally, event) bindings to the virtual events defined in the extensions. See the comments at the top of config-extensions.def for information. It's diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/help.txt --- a/Lib/idlelib/help.txt Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/help.txt Fri Feb 01 23:12:09 2013 +0100 @@ -21,7 +21,7 @@ File Menu (Shell and Editor): - New File -- Create a new file editing window + New Window -- Create a new editing window Open... -- Open an existing file Open Module... -- Open an existing module (searches sys.path) Recent Files... -- Open a list of recent files @@ -277,7 +277,8 @@ Python Shell window: Control-c interrupts executing command. - Control-d sends end-of-file; closes window if typed at >>> prompt. + Control-d sends end-of-file; closes window if typed at >>> prompt + (this is Control-z on Windows). Alt-/ expand word is also useful to reduce typing. Command history: @@ -339,7 +340,7 @@ script name is -, no script is executed but an interactive Python session is started; the arguments are still available in sys.argv. -Running without a subprocess: (DEPRECATED in Python 3.4 see Issue 16123) +Running without a subprocess: (DEPRECATED in Python 3.5 see Issue 16123) If IDLE is started with the -n command line switch it will run in a single process and will not create the subprocess which runs the RPC diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/README.txt --- a/Lib/idlelib/idle_test/README.txt Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -README FOR IDLE TESTS IN IDLELIB.IDLE_TEST - - -1. Test Files - -The idle directory, idlelib, has over 60 xyz.py files. The idle_test -subdirectory should contain a test_xyy.py for each. (For test modules, make -'xyz' lower case, and possibly shorten it.) Each file should start with the -something like the following template, with the blanks after after '.' and 'as', -and before and after '_' filled in. ---- -import unittest -from test.support import requires -import idlelib. as - -class _Test(unittest.TestCase): - - def test_(self): - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=2) ---- -Idle tests are run with unittest; do not use regrtest's test_main. - -Once test_xyy is written, the following should go at the end of xyy.py, -with xyz (lowercased) added after 'test_'. ---- -if __name__ == "__main__": - from test import support; support.use_resources = ['gui'] - import unittest - unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False) ---- - - -2. Gui Tests - -Gui tests need 'requires' and 'use_resources' from test.support -(test.test_support in 2.7). A test is a gui test if it creates a Tk root or -master object either directly or indirectly by instantiating a tkinter or -idle class. For the benefit of buildbot machines that do not have a graphics -screen, gui tests must be 'guarded' by "requires('gui')" in a setUp -function or method. This will typically be setUpClass. ---- - @classmethod - def setUpClass(cls): - requires('gui') ---- -All gui objects must be destroyed by the end of the test, perhaps in a tearDown -function. - -Support.requires('gui') returns true if it is either called in a main module -(which never happens on buildbots) or if use_resources contains 'gui'. -Use_resources is set by test.regrtest but not by unittest. So when running -tests in another module with unittest, we set it ourselves, as in the xyz.py -template above. - -Since non-gui tests always run, but gui tests only sometimes, tests of non-gui -operations should best avoid needing a gui. Methods that make incidental use of -tkinter variables and messageboxes can do this by using the mock classes in -idle_test/mock_tk.py. - - -3. Running Tests - -Assume that xyz.py and test_xyz.py end with the "if __name__" statements given -above. In Idle, pressing F5 in an editor window with either loaded will run all -tests in the test_xyz file with the version of Python running Idle. The test -report and any tracebacks will appear in the Shell window. The options in these -"if __name__" statements are appropriate for developers running (as opposed to -importing) either of the files during development: verbosity=2 lists all test -methods in the file; exit=False avoids a spurious sys.exit traceback that would -otherwise occur when running in Idle. The following command lines also run -all test methods, including gui tests, in test_xyz.py. (The exceptions are that -idlelib and idlelib.idle start Idle and idlelib.PyShell should (issue 18330).) - -python -m idlelib.xyz # With the capitalization of the xyz module -python -m idlelib.idle_test.test_xyz - -To run all idle_test/test_*.py tests, either interactively -('>>>', with unittest imported) or from a command line, use one of the -following. (Notes: unittest does not run gui tests; in 2.7, 'test ' (with the -space) is 'test.regrtest '; where present, -v and -ugui can be omitted.) - ->>> unittest.main('idlelib.idle_test', verbosity=2, exit=False) -python -m unittest -v idlelib.idle_test -python -m test -v -ugui test_idle -python -m test.test_idle - -The idle tests are 'discovered' by idlelib.idle_test.__init__.load_tests, -which is also imported into test.test_idle. Normally, neither file should be -changed when working on individual test modules. The third command runs runs -unittest indirectly through regrtest. The same happens when the entire test -suite is run with 'python -m test'. So that command must work for buildbots -to stay green. Idle tests must not disturb the environment in a way that -makes other tests fail (issue 18081). - -To run an individual Testcase or test method, extend the dotted name given to -unittest on the command line. (But gui tests will not this way.) - -python -m unittest -v idlelib.idle_test.text_xyz.Test_case.test_meth diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/__init__.py --- a/Lib/idlelib/idle_test/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -from os.path import dirname - -def load_tests(loader, standard_tests, pattern): - this_dir = dirname(__file__) - top_dir = dirname(dirname(this_dir)) - package_tests = loader.discover(start_dir=this_dir, pattern='test*.py', - top_level_dir=top_dir) - standard_tests.addTests(package_tests) - return standard_tests diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/mock_idle.py --- a/Lib/idlelib/idle_test/mock_idle.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -'''Mock classes that imitate idlelib modules or classes. - -Attributes and methods will be added as needed for tests. -''' - -from idlelib.idle_test.mock_tk import Text - -class Editor: - '''Minimally imitate EditorWindow.EditorWindow class. - ''' - def __init__(self, flist=None, filename=None, key=None, root=None): - self.text = Text() - self.undo = UndoDelegator() - - def get_selection_indices(self): - first = self.text.index('1.0') - last = self.text.index('end') - return first, last - -class UndoDelegator: - '''Minimally imitate UndoDelegator,UndoDelegator class. - ''' - # A real undo block is only needed for user interaction. - def undo_block_start(*args): - pass - def undo_block_stop(*args): - pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/mock_tk.py --- a/Lib/idlelib/idle_test/mock_tk.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,279 +0,0 @@ -"""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 typically -required in spite of what the doc strings say. -""" - -class Var: - "Use for String/Int/BooleanVar: incomplete" - def __init__(self, master=None, value=None, name=None): - self.master = master - self.value = value - self.name = name - def set(self, value): - self.value = value - def get(self): - return self.value - -class Mbox_func: - """Generic mock for messagebox functions, which all have the same signature. - - Instead of displaying a message box, the mock's call method saves the - arguments as instance attributes, which test functions can then examime. - """ - def __init__(self): - self.result = None # The return for all show funcs - def __call__(self, title, message, *args, **kwds): - # Save all args for possible examination by tester - self.title = title - self.message = message - self.args = args - self.kwds = kwds - return self.result # Set by tester for ask functions - -class Mbox: - """Mock for tkinter.messagebox with an Mbox_func for each function. - - This module was 'tkMessageBox' in 2.x; hence the 'import as' in 3.x. - Example usage in test_module.py for testing functios in module.py: - --- -from idlelib.idle_test.mock_tk import Mbox -import module - -orig_mbox = module.tkMessageBox -showerror = Mbox.showerror # example, for attribute access in test methods - -class Test(unittest.TestCase): - - @classmethod - def setUpClass(cls): - module.tkMessageBox = Mbox - - @classmethod - def tearDownClass(cls): - module.tkMessageBox = orig_mbox - --- - For 'ask' functions, set func.result return value before calling the method - that uses the message function. When tkMessageBox functions are the - only gui alls in a method, this replacement makes the method gui-free, - """ - askokcancel = Mbox_func() # True or False - askquestion = Mbox_func() # 'yes' or 'no' - askretrycancel = Mbox_func() # True or False - askyesno = Mbox_func() # True or False - askyesnocancel = Mbox_func() # True, False, or None - showerror = Mbox_func() # None - showinfo = Mbox_func() # None - showwarning = Mbox_func() # None - -from _tkinter import TclError - -class Text: - """A semi-functional non-gui replacement for tkinter.Text text editors. - - The mock's data model is that a text is a list of \n-terminated lines. - The mock adds an empty string at the beginning of the list so that the - index of actual lines start at 1, as with Tk. The methods never see this. - Tk initializes files with a terminal \n that cannot be deleted. It is - invisible in the sense that one cannot move the cursor beyond it. - - This class is only tested (and valid) with strings of ascii chars. - For testing, we are not concerned with Tk Text's treatment of, - for instance, 0-width characters or character + accent. - """ - def __init__(self, master=None, cnf={}, **kw): - '''Initialize mock, non-gui, text-only Text widget. - - At present, all args are ignored. Almost all affect visual behavior. - There are just a few Text-only options that affect text behavior. - ''' - self.data = ['', '\n'] - - def index(self, index): - "Return string version of index decoded according to current text." - return "%s.%s" % self._decode(index, endflag=1) - - def _decode(self, index, endflag=0): - """Return a (line, char) tuple of int indexes into self.data. - - This implements .index without converting the result back to a string. - The result is contrained by the number of lines and linelengths of - self.data. For many indexes, the result is initally (1, 0). - - The input index may have any of several possible forms: - * line.char float: converted to 'line.char' string; - * 'line.char' string, where line and char are decimal integers; - * 'line.char lineend', where lineend='lineend' (and char is ignored); - * 'line.end', where end='end' (same as above); - * 'insert', the positions before terminal \n; - * 'end', whose meaning depends on the endflag passed to ._endex. - * 'sel.first' or 'sel.last', where sel is a tag -- not implemented. - """ - if isinstance(index, (float, bytes)): - index = str(index) - try: - index=index.lower() - except AttributeError: - raise TclError('bad text index "%s"' % index) from None - - lastline = len(self.data) - 1 # same as number of text lines - if index == 'insert': - return lastline, len(self.data[lastline]) - 1 - elif index == 'end': - return self._endex(endflag) - - line, char = index.split('.') - line = int(line) - - # Out of bounds line becomes first or last ('end') index - if line < 1: - return 1, 0 - elif line > lastline: - return self._endex(endflag) - - linelength = len(self.data[line]) -1 # position before/at \n - if char.endswith(' lineend') or char == 'end': - return line, linelength - # Tk requires that ignored chars before ' lineend' be valid int - - # Out of bounds char becomes first or last index of line - char = int(char) - if char < 0: - char = 0 - elif char > linelength: - char = linelength - return line, char - - def _endex(self, endflag): - '''Return position for 'end' or line overflow corresponding to endflag. - - -1: position before terminal \n; for .insert(), .delete - 0: position after terminal \n; for .get, .delete index 1 - 1: same viewed as begininning of non-existent next line (for .index) - ''' - n = len(self.data) - if endflag == 1: - return n, 0 - else: - n -= 1 - return n, len(self.data[n]) + endflag - - - def insert(self, index, chars): - "Insert chars before the character at index." - - if not chars: # ''.splitlines() is [], not [''] - return - chars = chars.splitlines(True) - if chars[-1][-1] == '\n': - chars.append('') - line, char = self._decode(index, -1) - before = self.data[line][:char] - after = self.data[line][char:] - self.data[line] = before + chars[0] - self.data[line+1:line+1] = chars[1:] - self.data[line+len(chars)-1] += after - - - def get(self, index1, index2=None): - "Return slice from index1 to index2 (default is 'index1+1')." - - startline, startchar = self._decode(index1) - if index2 is None: - endline, endchar = startline, startchar+1 - else: - endline, endchar = self._decode(index2) - - if startline == endline: - return self.data[startline][startchar:endchar] - else: - lines = [self.data[startline][startchar:]] - for i in range(startline+1, endline): - lines.append(self.data[i]) - lines.append(self.data[endline][:endchar]) - return ''.join(lines) - - - def delete(self, index1, index2=None): - '''Delete slice from index1 to index2 (default is 'index1+1'). - - Adjust default index2 ('index+1) for line ends. - Do not delete the terminal \n at the very end of self.data ([-1][-1]). - ''' - startline, startchar = self._decode(index1, -1) - if index2 is None: - if startchar < len(self.data[startline])-1: - # not deleting \n - endline, endchar = startline, startchar+1 - elif startline < len(self.data) - 1: - # deleting non-terminal \n, convert 'index1+1 to start of next line - endline, endchar = startline+1, 0 - else: - # do not delete terminal \n if index1 == 'insert' - return - else: - endline, endchar = self._decode(index2, -1) - # restricting end position to insert position excludes terminal \n - - if startline == endline and startchar < endchar: - self.data[startline] = self.data[startline][:startchar] + \ - self.data[startline][endchar:] - elif startline < endline: - self.data[startline] = self.data[startline][:startchar] + \ - self.data[endline][endchar:] - startline += 1 - for i in range(startline, endline+1): - del self.data[startline] - - def compare(self, index1, op, index2): - line1, char1 = self._decode(index1) - line2, char2 = self._decode(index2) - if op == '<': - return line1 < line2 or line1 == line2 and char1 < char2 - elif op == '<=': - return line1 < line2 or line1 == line2 and char1 <= char2 - elif op == '>': - return line1 > line2 or line1 == line2 and char1 > char2 - elif op == '>=': - return line1 > line2 or line1 == line2 and char1 >= char2 - elif op == '==': - return line1 == line2 and char1 == char2 - elif op == '!=': - return line1 != line2 or char1 != char2 - else: - raise TclError('''bad comparison operator "%s":''' - '''must be <, <=, ==, >=, >, or !=''' % op) - - # The following Text methods normally do something and return None. - # Whether doing nothing is sufficient for a test will depend on the test. - - def mark_set(self, name, index): - "Set mark *name* before the character at index." - pass - - def mark_unset(self, *markNames): - "Delete all marks in markNames." - - def tag_remove(self, tagName, index1, index2=None): - "Remove tag tagName from all characters between index1 and index2." - pass - - # The following Text methods affect the graphics screen and return None. - # Doing nothing should always be sufficient for tests. - - def scan_dragto(self, x, y): - "Adjust the view of the text according to scan_mark" - - def scan_mark(self, x, y): - "Remember the current X, Y coordinates." - - def see(self, index): - "Scroll screen to make the character at INDEX is visible." - pass - - # The following is a Misc method inheritet by Text. - # It should properly go in a Misc mock, but is included here for now. - - def bind(sequence=None, func=None, add=None): - "Bind to this widget at event sequence a call to function func." - pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_calltips.py --- a/Lib/idlelib/idle_test/test_calltips.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -import unittest -import idlelib.CallTips as ct - -class Test_get_entity(unittest.TestCase): - def test_bad_entity(self): - self.assertIsNone(ct.get_entity('1/0')) - def test_good_entity(self): - self.assertIs(ct.get_entity('int'), int) - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_config_name.py --- a/Lib/idlelib/idle_test/test_config_name.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -"""Unit tests for idlelib.configSectionNameDialog""" -import unittest -from idlelib.idle_test.mock_tk import Var, Mbox -from idlelib import configSectionNameDialog as name_dialog_module - -name_dialog = name_dialog_module.GetCfgSectionNameDialog - -class Dummy_name_dialog: - # Mock for testing the following methods of name_dialog - name_ok = name_dialog.name_ok - Ok = name_dialog.Ok - Cancel = name_dialog.Cancel - # Attributes, constant or variable, needed for tests - used_names = ['used'] - name = Var() - result = None - destroyed = False - def destroy(self): - self.destroyed = True - -# name_ok calls Mbox.showerror if name is not ok -orig_mbox = name_dialog_module.tkMessageBox -showerror = Mbox.showerror - -class TestConfigName(unittest.TestCase): - dialog = Dummy_name_dialog() - - @classmethod - def setUpClass(cls): - name_dialog_module.tkMessageBox = Mbox - - @classmethod - def tearDownClass(cls): - name_dialog_module.tkMessageBox = orig_mbox - - def test_blank_name(self): - self.dialog.name.set(' ') - self.assertEqual(self.dialog.name_ok(), '') - self.assertEqual(showerror.title, 'Name Error') - self.assertIn('No', showerror.message) - - def test_used_name(self): - self.dialog.name.set('used') - self.assertEqual(self.dialog.name_ok(), '') - self.assertEqual(showerror.title, 'Name Error') - self.assertIn('use', showerror.message) - - def test_long_name(self): - self.dialog.name.set('good'*8) - self.assertEqual(self.dialog.name_ok(), '') - self.assertEqual(showerror.title, 'Name Error') - self.assertIn('too long', showerror.message) - - def test_good_name(self): - self.dialog.name.set(' good ') - showerror.title = 'No Error' # should not be called - self.assertEqual(self.dialog.name_ok(), 'good') - self.assertEqual(showerror.title, 'No Error') - - def test_ok(self): - self.dialog.destroyed = False - self.dialog.name.set('good') - self.dialog.Ok() - self.assertEqual(self.dialog.result, 'good') - self.assertTrue(self.dialog.destroyed) - - def test_cancel(self): - self.dialog.destroyed = False - self.dialog.Cancel() - self.assertEqual(self.dialog.result, '') - self.assertTrue(self.dialog.destroyed) - - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_delegator.py --- a/Lib/idlelib/idle_test/test_delegator.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -import unittest -from idlelib.Delegator import Delegator - -class DelegatorTest(unittest.TestCase): - - def test_mydel(self): - # test a simple use scenario - - # initialize - mydel = Delegator(int) - self.assertIs(mydel.delegate, int) - self.assertEqual(mydel._Delegator__cache, set()) - - # add an attribute: - self.assertRaises(AttributeError, mydel.__getattr__, 'xyz') - bl = mydel.bit_length - self.assertIs(bl, int.bit_length) - self.assertIs(mydel.__dict__['bit_length'], int.bit_length) - self.assertEqual(mydel._Delegator__cache, {'bit_length'}) - - # add a second attribute - mydel.numerator - self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'}) - - # delete the second (which, however, leaves it in the name cache) - del mydel.numerator - self.assertNotIn('numerator', mydel.__dict__) - self.assertIn('numerator', mydel._Delegator__cache) - - # reset by calling .setdelegate, which calls .resetcache - mydel.setdelegate(float) - self.assertIs(mydel.delegate, float) - self.assertNotIn('bit_length', mydel.__dict__) - self.assertEqual(mydel._Delegator__cache, set()) - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=2) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_grep.py --- a/Lib/idlelib/idle_test/test_grep.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -""" !Changing this line will break Test_findfile.test_found! -Non-gui unit tests for idlelib.GrepDialog methods. -dummy_command calls grep_it calls findfiles. -An exception raised in one method will fail callers. -Otherwise, tests are mostly independent. -*** Currently only test grep_it. -""" -import unittest -from test.support import captured_stdout -from idlelib.idle_test.mock_tk import Var -from idlelib.GrepDialog import GrepDialog -import re - -class Dummy_searchengine: - '''GrepDialog.__init__ calls parent SearchDiabolBase which attaches the - passed in SearchEngine instance as attribute 'engine'. Only a few of the - many possible self.engine.x attributes are needed here. - ''' - def getpat(self): - return self._pat - -searchengine = Dummy_searchengine() - -class Dummy_grep: - # Methods tested - #default_command = GrepDialog.default_command - grep_it = GrepDialog.grep_it - findfiles = GrepDialog.findfiles - # Other stuff needed - recvar = Var(False) - engine = searchengine - def close(self): # gui method - pass - -grep = Dummy_grep() - -class FindfilesTest(unittest.TestCase): - # findfiles is really a function, not a method, could be iterator - # test that filename return filename - # test that idlelib has many .py files - # test that recursive flag adds idle_test .py files - pass - -class Grep_itTest(unittest.TestCase): - # Test captured reports with 0 and some hits. - # Should test file names, but Windows reports have mixed / and \ separators - # from incomplete replacement, so 'later'. - - def report(self, pat): - grep.engine._pat = pat - with captured_stdout() as s: - grep.grep_it(re.compile(pat), __file__) - lines = s.getvalue().split('\n') - lines.pop() # remove bogus '' after last \n - return lines - - def test_unfound(self): - pat = 'xyz*'*7 - lines = self.report(pat) - self.assertEqual(len(lines), 2) - self.assertIn(pat, lines[0]) - self.assertEqual(lines[1], 'No hits.') - - def test_found(self): - - pat = '""" !Changing this line will break Test_findfile.test_found!' - lines = self.report(pat) - self.assertEqual(len(lines), 5) - self.assertIn(pat, lines[0]) - self.assertIn('py: 1:', lines[1]) # line number 1 - self.assertIn('2', lines[3]) # hits found 2 - self.assertTrue(lines[4].startswith('(Hint:')) - -class Default_commandTest(unittest.TestCase): - # To write this, mode OutputWindow import to top of GrepDialog - # so it can be replaced by captured_stdout in class setup/teardown. - pass - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_pathbrowser.py --- a/Lib/idlelib/idle_test/test_pathbrowser.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -import unittest -import idlelib.PathBrowser as PathBrowser - -class PathBrowserTest(unittest.TestCase): - - def test_DirBrowserTreeItem(self): - # Issue16226 - make sure that getting a sublist works - d = PathBrowser.DirBrowserTreeItem('') - d.GetSubList() - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_rstrip.py --- a/Lib/idlelib/idle_test/test_rstrip.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -import unittest -import idlelib.RstripExtension as rs -from idlelib.idle_test.mock_idle import Editor - -class rstripTest(unittest.TestCase): - - def test_rstrip_line(self): - editor = Editor() - text = editor.text - do_rstrip = rs.RstripExtension(editor).do_rstrip - - do_rstrip() - self.assertEqual(text.get('1.0', 'insert'), '') - text.insert('1.0', ' ') - do_rstrip() - self.assertEqual(text.get('1.0', 'insert'), '') - text.insert('1.0', ' \n') - do_rstrip() - self.assertEqual(text.get('1.0', 'insert'), '\n') - - def test_rstrip_multiple(self): - editor = Editor() - # Uncomment following to verify that test passes with real widgets. -## from idlelib.EditorWindow import EditorWindow as Editor -## from tkinter import Tk -## editor = Editor(root=Tk()) - text = editor.text - do_rstrip = rs.RstripExtension(editor).do_rstrip - - original = ( - "Line with an ending tab \n" - "Line ending in 5 spaces \n" - "Linewithnospaces\n" - " indented line\n" - " indented line with trailing space \n" - " ") - stripped = ( - "Line with an ending tab\n" - "Line ending in 5 spaces\n" - "Linewithnospaces\n" - " indented line\n" - " indented line with trailing space\n") - - text.insert('1.0', original) - do_rstrip() - self.assertEqual(text.get('1.0', 'insert'), stripped) - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_text.py --- a/Lib/idlelib/idle_test/test_text.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,230 +0,0 @@ -# Test mock_tk.Text class against tkinter.Text class by running same tests with both. -import unittest -from test.support import requires - -from _tkinter import TclError -import tkinter as tk - -class TextTest(object): - - hw = 'hello\nworld' # usual initial insert after initialization - hwn = hw+'\n' # \n present at initialization, before insert - - Text = None - def setUp(self): - self.text = self.Text() - - def test_init(self): - self.assertEqual(self.text.get('1.0'), '\n') - self.assertEqual(self.text.get('end'), '') - - def test_index_empty(self): - index = self.text.index - - for dex in (-1.0, 0.3, '1.-1', '1.0', '1.0 lineend', '1.end', '1.33', - 'insert'): - self.assertEqual(index(dex), '1.0') - - for dex in 'end', 2.0, '2.1', '33.44': - self.assertEqual(index(dex), '2.0') - - def test_index_data(self): - index = self.text.index - self.text.insert('1.0', self.hw) - - for dex in -1.0, 0.3, '1.-1', '1.0': - self.assertEqual(index(dex), '1.0') - - for dex in '1.0 lineend', '1.end', '1.33': - self.assertEqual(index(dex), '1.5') - - for dex in 'end', '33.44': - self.assertEqual(index(dex), '3.0') - - def test_get(self): - get = self.text.get - Equal = self.assertEqual - self.text.insert('1.0', self.hw) - - Equal(get('end'), '') - Equal(get('end', 'end'), '') - Equal(get('1.0'), 'h') - Equal(get('1.0', '1.1'), 'h') - Equal(get('1.0', '1.3'), 'hel') - Equal(get('1.1', '1.3'), 'el') - Equal(get('1.0', '1.0 lineend'), 'hello') - Equal(get('1.0', '1.10'), 'hello') - Equal(get('1.0 lineend'), '\n') - Equal(get('1.1', '2.3'), 'ello\nwor') - Equal(get('1.0', '2.5'), self.hw) - Equal(get('1.0', 'end'), self.hwn) - Equal(get('0.0', '5.0'), self.hwn) - - def test_insert(self): - insert = self.text.insert - get = self.text.get - Equal = self.assertEqual - - insert('1.0', self.hw) - Equal(get('1.0', 'end'), self.hwn) - - insert('1.0', '') # nothing - Equal(get('1.0', 'end'), self.hwn) - - insert('1.0', '*') - Equal(get('1.0', 'end'), '*hello\nworld\n') - - insert('1.0 lineend', '*') - Equal(get('1.0', 'end'), '*hello*\nworld\n') - - insert('2.3', '*') - Equal(get('1.0', 'end'), '*hello*\nwor*ld\n') - - insert('end', 'x') - Equal(get('1.0', 'end'), '*hello*\nwor*ldx\n') - - insert('1.4', 'x\n') - Equal(get('1.0', 'end'), '*helx\nlo*\nwor*ldx\n') - - def test_no_delete(self): - # if index1 == 'insert' or 'end' or >= end, there is no deletion - delete = self.text.delete - get = self.text.get - Equal = self.assertEqual - self.text.insert('1.0', self.hw) - - delete('insert') - Equal(get('1.0', 'end'), self.hwn) - - delete('end') - Equal(get('1.0', 'end'), self.hwn) - - delete('insert', 'end') - Equal(get('1.0', 'end'), self.hwn) - - delete('insert', '5.5') - Equal(get('1.0', 'end'), self.hwn) - - delete('1.4', '1.0') - Equal(get('1.0', 'end'), self.hwn) - - delete('1.4', '1.4') - Equal(get('1.0', 'end'), self.hwn) - - def test_delete_char(self): - delete = self.text.delete - get = self.text.get - Equal = self.assertEqual - self.text.insert('1.0', self.hw) - - delete('1.0') - Equal(get('1.0', '1.end'), 'ello') - - delete('1.0', '1.1') - Equal(get('1.0', '1.end'), 'llo') - - # delete \n and combine 2 lines into 1 - delete('1.end') - Equal(get('1.0', '1.end'), 'lloworld') - - self.text.insert('1.3', '\n') - delete('1.10') - Equal(get('1.0', '1.end'), 'lloworld') - - self.text.insert('1.3', '\n') - delete('1.3', '2.0') - Equal(get('1.0', '1.end'), 'lloworld') - - def test_delete_slice(self): - delete = self.text.delete - get = self.text.get - Equal = self.assertEqual - self.text.insert('1.0', self.hw) - - delete('1.0', '1.0 lineend') - Equal(get('1.0', 'end'), '\nworld\n') - - delete('1.0', 'end') - Equal(get('1.0', 'end'), '\n') - - self.text.insert('1.0', self.hw) - delete('1.0', '2.0') - Equal(get('1.0', 'end'), 'world\n') - - delete('1.0', 'end') - Equal(get('1.0', 'end'), '\n') - - self.text.insert('1.0', self.hw) - delete('1.2', '2.3') - Equal(get('1.0', 'end'), 'held\n') - - def test_multiple_lines(self): # insert and delete - self.text.insert('1.0', 'hello') - - self.text.insert('1.3', '1\n2\n3\n4\n5') - self.assertEqual(self.text.get('1.0', 'end'), 'hel1\n2\n3\n4\n5lo\n') - - self.text.delete('1.3', '5.1') - self.assertEqual(self.text.get('1.0', 'end'), 'hello\n') - - def test_compare(self): - compare = self.text.compare - Equal = self.assertEqual - # need data so indexes not squished to 1,0 - self.text.insert('1.0', 'First\nSecond\nThird\n') - - self.assertRaises(TclError, compare, '2.2', 'op', '2.2') - - for op, less1, less0, equal, greater0, greater1 in ( - ('<', True, True, False, False, False), - ('<=', True, True, True, False, False), - ('>', False, False, False, True, True), - ('>=', False, False, True, True, True), - ('==', False, False, True, False, False), - ('!=', True, True, False, True, True), - ): - Equal(compare('1.1', op, '2.2'), less1, op) - Equal(compare('2.1', op, '2.2'), less0, op) - Equal(compare('2.2', op, '2.2'), equal, op) - Equal(compare('2.3', op, '2.2'), greater0, op) - Equal(compare('3.3', op, '2.2'), greater1, op) - - -class MockTextTest(TextTest, unittest.TestCase): - - @classmethod - def setUpClass(cls): - from idlelib.idle_test.mock_tk import Text - cls.Text = Text - - def test_decode(self): - # test endflags (-1, 0) not tested by test_index (which uses +1) - decode = self.text._decode - Equal = self.assertEqual - self.text.insert('1.0', self.hw) - - Equal(decode('end', -1), (2, 5)) - Equal(decode('3.1', -1), (2, 5)) - Equal(decode('end', 0), (2, 6)) - Equal(decode('3.1', 0), (2, 6)) - - -class TkTextTest(TextTest, unittest.TestCase): - - @classmethod - def setUpClass(cls): - requires('gui') - from tkinter import Tk, Text - cls.Text = Text - try: - cls.root = Tk() - except TclError as msg: - raise unittest.SkipTest('TclError: %s' % msg) - - @classmethod - def tearDownClass(cls): - cls.root.destroy() - - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/idle_test/test_warning.py --- a/Lib/idlelib/idle_test/test_warning.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -'''Test warnings replacement in PyShell.py and run.py. - -This file could be expanded to include traceback overrides -(in same two modules). If so, change name. -Revise if output destination changes (http://bugs.python.org/issue18318). -Make sure warnings module is left unaltered (http://bugs.python.org/issue18081). -''' - -import unittest -from test.support import captured_stderr - -import warnings -# Try to capture default showwarning before Idle modules are imported. -showwarning = warnings.showwarning -# But if we run this file within idle, we are in the middle of the run.main loop -# and default showwarnings has already been replaced. -running_in_idle = 'idle' in showwarning.__name__ - -from idlelib import run -from idlelib import PyShell as shell - -# The following was generated from PyShell.idle_formatwarning -# and checked as matching expectation. -idlemsg = ''' -Warning (from warnings module): - File "test_warning.py", line 99 - Line of code -UserWarning: Test -''' -shellmsg = idlemsg + ">>> " - -class RunWarnTest(unittest.TestCase): - - @unittest.skipIf(running_in_idle, "Does not work when run within Idle.") - def test_showwarnings(self): - self.assertIs(warnings.showwarning, showwarning) - run.capture_warnings(True) - self.assertIs(warnings.showwarning, run.idle_showwarning_subproc) - run.capture_warnings(False) - self.assertIs(warnings.showwarning, showwarning) - - def test_run_show(self): - with captured_stderr() as f: - run.idle_showwarning_subproc( - 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') - # The following uses .splitlines to erase line-ending differences - self.assertEqual(idlemsg.splitlines(), f.getvalue().splitlines()) - -class ShellWarnTest(unittest.TestCase): - - @unittest.skipIf(running_in_idle, "Does not work when run within Idle.") - def test_showwarnings(self): - self.assertIs(warnings.showwarning, showwarning) - shell.capture_warnings(True) - self.assertIs(warnings.showwarning, shell.idle_showwarning) - shell.capture_warnings(False) - self.assertIs(warnings.showwarning, showwarning) - - def test_idle_formatter(self): - # Will fail if format changed without regenerating idlemsg - s = shell.idle_formatwarning( - 'Test', UserWarning, 'test_warning.py', 99, 'Line of code') - self.assertEqual(idlemsg, s) - - def test_shell_show(self): - with captured_stderr() as f: - shell.idle_showwarning( - 'Test', UserWarning, 'test_warning.py', 99, f, 'Line of code') - self.assertEqual(shellmsg.splitlines(), f.getvalue().splitlines()) - - -if __name__ == '__main__': - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/rpc.py --- a/Lib/idlelib/rpc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/rpc.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,7 +2,7 @@ For security reasons, GvR requested that Idle's Python execution server process connect to the Idle process, which listens for the connection. Since Idle has -only one client per server, this was not a limitation. +has only one client per server, this was not a limitation. +---------------------------------+ +-------------+ | socketserver.BaseRequestHandler | | SocketIO | @@ -145,7 +145,7 @@ def exithook(self): "override for specific exit action" - os._exit(0) + os._exit() def debug(self, *args): if not self.debugging: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/run.py --- a/Lib/idlelib/run.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/run.py Fri Feb 01 23:12:09 2013 +0100 @@ -16,46 +16,33 @@ from idlelib import RemoteObjectBrowser from idlelib import StackViewer from idlelib import rpc -from idlelib import PyShell -from idlelib import IOBinding import __main__ LOCALHOST = '127.0.0.1' -import warnings +try: + import warnings +except ImportError: + pass +else: + def idle_formatwarning_subproc(message, category, filename, lineno, + line=None): + """Format warnings the IDLE way""" + s = "\nWarning (from warnings module):\n" + s += ' File \"%s\", line %s\n' % (filename, lineno) + if line is None: + line = linecache.getline(filename, lineno) + line = line.strip() + if line: + s += " %s\n" % line + s += "%s: %s\n" % (category.__name__, message) + return s + warnings.formatwarning = idle_formatwarning_subproc -def idle_showwarning_subproc( - message, category, filename, lineno, file=None, line=None): - """Show Idle-format warning after replacing warnings.showwarning. - The only difference is the formatter called. - """ - if file is None: - file = sys.stderr - try: - file.write(PyShell.idle_formatwarning( - message, category, filename, lineno, line)) - except IOError: - pass # the file (probably stderr) is invalid - this warning gets lost. +tcl = tkinter.Tcl() -_warnings_showwarning = None - -def capture_warnings(capture): - "Replace warning.showwarning with idle_showwarning_subproc, or reverse." - - global _warnings_showwarning - if capture: - if _warnings_showwarning is None: - _warnings_showwarning = warnings.showwarning - warnings.showwarning = idle_showwarning_subproc - else: - if _warnings_showwarning is not None: - warnings.showwarning = _warnings_showwarning - _warnings_showwarning = None - -capture_warnings(True) -tcl = tkinter.Tcl() def handle_tk_events(tcl=tcl): """Process any tk events that are ready to be dispatched if tkinter @@ -63,6 +50,7 @@ loaded.""" tcl.eval("update") + # Thread shared globals: Establish a queue between a subthread (which handles # the socket) and the main thread (which runs user code), plus global # completion, exit and interruptable (the main thread) flags: @@ -101,8 +89,6 @@ print("IDLE Subprocess: no IP port passed in sys.argv.", file=sys.__stderr__) return - - capture_warnings(True) sys.argv[:] = [""] sockthread = threading.Thread(target=manage_socket, name='SockThread', @@ -130,7 +116,6 @@ exit_now = True continue except SystemExit: - capture_warnings(False) raise except: type, value, tb = sys.exc_info() @@ -260,7 +245,6 @@ if no_exitfunc: import atexit atexit._clear() - capture_warnings(False) sys.exit(0) class MyRPCServer(rpc.RPCServer): @@ -293,29 +277,63 @@ quitting = True thread.interrupt_main() +class _RPCFile(io.TextIOBase): + """Wrapper class for the RPC proxy to typecheck arguments + that may not support pickling. The base class is there only + to support type tests; all implementations come from the remote + object.""" + + def __init__(self, rpc): + super.__setattr__(self, 'rpc', rpc) + + def __getattribute__(self, name): + # When accessing the 'rpc' attribute, or 'write', use ours + if name in ('rpc', 'write', 'writelines'): + return io.TextIOBase.__getattribute__(self, name) + # Else only look into the remote object only + return getattr(self.rpc, name) + + def __setattr__(self, name, value): + return setattr(self.rpc, name, value) + + @staticmethod + def _ensure_string(func): + def f(self, s): + if not isinstance(s, str): + raise TypeError('must be str, not ' + type(s).__name__) + return func(self, s) + return f + +class _RPCOutputFile(_RPCFile): + @_RPCFile._ensure_string + def write(self, s): + if not isinstance(s, str): + raise TypeError('must be str, not ' + type(s).__name__) + return self.rpc.write(s) + +class _RPCInputFile(_RPCFile): + @_RPCFile._ensure_string + def write(self, s): + raise io.UnsupportedOperation("not writable") + writelines = write + class MyHandler(rpc.RPCHandler): def handle(self): """Override base method""" executive = Executive(self) self.register("exec", executive) - self.console = self.get_remote_proxy("console") - sys.stdin = PyShell.PseudoInputFile(self.console, "stdin", - IOBinding.encoding) - sys.stdout = PyShell.PseudoOutputFile(self.console, "stdout", - IOBinding.encoding) - sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr", - IOBinding.encoding) - + self.console = self.get_remote_proxy("stdin") + sys.stdin = _RPCInputFile(self.console) + sys.stdout = _RPCOutputFile(self.get_remote_proxy("stdout")) + sys.stderr = _RPCOutputFile(self.get_remote_proxy("stderr")) sys.displayhook = rpc.displayhook # page help() text to shell. import pydoc # import must be done here to capture i/o binding pydoc.pager = pydoc.plainpager - - # Keep a reference to stdin so that it won't try to exit IDLE if - # sys.stdin gets changed from within IDLE's shell. See issue17838. - self._keep_stdin = sys.stdin - + from idlelib import IOBinding + sys.stdin.encoding = sys.stdout.encoding = \ + sys.stderr.encoding = IOBinding.encoding self.interp = self.get_remote_proxy("interp") rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05) @@ -353,10 +371,6 @@ exec(code, self.locals) finally: interruptable = False - except SystemExit: - # Scripts that raise SystemExit should just - # return to the interactive prompt - pass except: self.usr_exc_info = sys.exc_info() if quitting: @@ -400,5 +414,3 @@ sys.last_value = val item = StackViewer.StackTreeItem(flist, tb) return RemoteObjectBrowser.remote_object_tree_item(item) - -capture_warnings(False) # Make sure turned off; see issue 18081 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/idlelib/textView.py --- a/Lib/idlelib/textView.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/idlelib/textView.py Fri Feb 01 23:12:09 2013 +0100 @@ -80,8 +80,7 @@ root=Tk() root.title('textView test') filename = './textView.py' - with open(filename, 'r') as f: - text = f.read() + text = file(filename, 'r').read() btn1 = Button(root, text='view_text', command=lambda:view_text(root, 'view_text', text)) btn1.pack(side=LEFT) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/imaplib.py --- a/Lib/imaplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/imaplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -24,8 +24,6 @@ import binascii, errno, random, re, socket, subprocess, sys, time, calendar from datetime import datetime, timezone, timedelta -from io import DEFAULT_BUFFER_SIZE - try: import ssl HAVE_SSL = True @@ -354,10 +352,10 @@ data = authobject(response) - It will be called to process server continuation responses; the - response argument it is passed will be a bytes. It should return bytes - data that will be base64 encoded and sent to the server. It should - return None if the client abort response '*' should be sent instead. + It will be called to process server continuation responses. + It should return data that will be encoded and sent to server. + It should return None if the client abort response '*' should + be sent instead. """ mech = mechanism.upper() # XXX: shouldn't this code be removed, not commented out? @@ -540,9 +538,7 @@ def _CRAM_MD5_AUTH(self, challenge): """ Authobject to use with CRAM-MD5 authentication. """ import hmac - pwd = (self.password.encode('ASCII') if isinstance(self.password, str) - else self.password) - return self.user + " " + hmac.HMAC(pwd, challenge).hexdigest() + return self.user + " " + hmac.HMAC(self.password, challenge).hexdigest() def logout(self): @@ -1073,7 +1069,7 @@ # Protocol mandates all lines terminated by CRLF if not line.endswith(b'\r\n'): - raise self.abort('socket error: unterminated line: %r' % line) + raise self.abort('socket error: unterminated line') line = line[:-2] if __debug__: @@ -1246,7 +1242,6 @@ self.sock = None self.file = None self.process = subprocess.Popen(self.command, - bufsize=DEFAULT_BUFFER_SIZE, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, close_fds=True) self.writefile = self.process.stdin @@ -1300,16 +1295,14 @@ # so when it gets to the end of the 8-bit input # there's no partial 6-bit output. # - oup = b'' - if isinstance(inp, str): - inp = inp.encode('ASCII') + oup = '' while inp: if len(inp) > 48: t = inp[:48] inp = inp[48:] else: t = inp - inp = b'' + inp = '' e = binascii.b2a_base64(t) if e: oup = oup + e[:-1] @@ -1317,7 +1310,7 @@ def decode(self, inp): if not inp: - return b'' + return '' return binascii.a2b_base64(inp) Months = ' Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/imp.py --- a/Lib/imp.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/imp.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,29 +7,22 @@ """ # (Probably) need to stay in _imp from _imp import (lock_held, acquire_lock, release_lock, - get_frozen_object, is_frozen_package, + load_dynamic, get_frozen_object, is_frozen_package, init_builtin, init_frozen, is_builtin, is_frozen, _fix_co_filename) -try: - from _imp import load_dynamic -except ImportError: - # Platform doesn't support dynamic loading. - load_dynamic = None -from importlib._bootstrap import SourcelessFileLoader, _ERR_MSG +# Directly exposed by this module +from importlib._bootstrap import new_module +from importlib._bootstrap import cache_from_source, source_from_cache + +from importlib import _bootstrap from importlib import machinery -from importlib import util -import importlib import os import sys import tokenize -import types import warnings -warnings.warn("the imp module is deprecated in favour of importlib; " - "see the module's documentation for alternative uses", - PendingDeprecationWarning) # DEPRECATED SEARCH_ERROR = 0 @@ -44,23 +37,9 @@ IMP_HOOK = 9 -def new_module(name): - """**DEPRECATED** - - Create a new module. - - The module is not entered into sys.modules. - - """ - return types.ModuleType(name) - - def get_magic(): - """**DEPRECATED** - - Return the magic number for .pyc or .pyo files. - """ - return util.MAGIC_NUMBER + """Return the magic number for .pyc or .pyo files.""" + return _bootstrap._MAGIC_BYTES def get_tag(): @@ -68,40 +47,10 @@ return sys.implementation.cache_tag -def cache_from_source(path, debug_override=None): - """**DEPRECATED** - - Given the path to a .py file, return the path to its .pyc/.pyo file. - - The .py file does not need to exist; this simply returns the path to the - .pyc/.pyo file calculated as if the .py file were imported. The extension - will be .pyc unless sys.flags.optimize is non-zero, then it will be .pyo. - - If debug_override is not None, then it must be a boolean and is used in - place of sys.flags.optimize. - - If sys.implementation.cache_tag is None then NotImplementedError is raised. - - """ - return util.cache_from_source(path, debug_override) - - -def source_from_cache(path): - """**DEPRECATED** - - Given the path to a .pyc./.pyo file, return the path to its .py file. - - The .pyc/.pyo file does not need to exist; this simply returns the path to - the .py file calculated to correspond to the .pyc/.pyo file. If path does - not conform to PEP 3147 format, ValueError will be raised. If - sys.implementation.cache_tag is None then NotImplementedError is raised. - - """ - return util.source_from_cache(path) - - def get_suffixes(): - """**DEPRECATED**""" + warnings.warn('imp.get_suffixes() is deprecated; use the constants ' + 'defined on importlib.machinery instead', + DeprecationWarning, 2) extensions = [(s, 'rb', C_EXTENSION) for s in machinery.EXTENSION_SUFFIXES] source = [(s, 'U', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] bytecode = [(s, 'rb', PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES] @@ -111,11 +60,7 @@ class NullImporter: - """**DEPRECATED** - - Null import object. - - """ + """Null import object.""" def __init__(self, path): if path == '': @@ -151,37 +96,38 @@ return super().get_data(path) -class _LoadSourceCompatibility(_HackedGetData, machinery.SourceFileLoader): +class _LoadSourceCompatibility(_HackedGetData, _bootstrap.SourceFileLoader): """Compatibility support for implementing load_source().""" def load_source(name, pathname, file=None): - _LoadSourceCompatibility(name, pathname, file).load_module(name) - module = sys.modules[name] - # To allow reloading to potentially work, use a non-hacked loader which - # won't rely on a now-closed file object. - module.__loader__ = machinery.SourceFileLoader(name, pathname) - return module + msg = ('imp.load_source() is deprecated; use ' + 'importlib.machinery.SourceFileLoader(name, pathname).load_module()' + ' instead') + warnings.warn(msg, DeprecationWarning, 2) + return _LoadSourceCompatibility(name, pathname, file).load_module(name) -class _LoadCompiledCompatibility(_HackedGetData, SourcelessFileLoader): +class _LoadCompiledCompatibility(_HackedGetData, + _bootstrap.SourcelessFileLoader): """Compatibility support for implementing load_compiled().""" def load_compiled(name, pathname, file=None): - """**DEPRECATED**""" - _LoadCompiledCompatibility(name, pathname, file).load_module(name) - module = sys.modules[name] - # To allow reloading to potentially work, use a non-hacked loader which - # won't rely on a now-closed file object. - module.__loader__ = SourcelessFileLoader(name, pathname) - return module + msg = ('imp.load_compiled() is deprecated; use ' + 'importlib.machinery.SourcelessFileLoader(name, pathname).' + 'load_module() instead ') + warnings.warn(msg, DeprecationWarning, 2) + return _LoadCompiledCompatibility(name, pathname, file).load_module(name) def load_package(name, path): - """**DEPRECATED**""" + msg = ('imp.load_package() is deprecated; use either ' + 'importlib.machinery.SourceFileLoader() or ' + 'importlib.machinery.SourcelessFileLoader() instead') + warnings.warn(msg, DeprecationWarning, 2) if os.path.isdir(path): extensions = (machinery.SOURCE_SUFFIXES[:] + machinery.BYTECODE_SUFFIXES[:]) @@ -191,7 +137,7 @@ break else: raise ValueError('{!r} is not a package'.format(path)) - return machinery.SourceFileLoader(name, path).load_module(name) + return _bootstrap.SourceFileLoader(name, path).load_module(name) def load_module(name, file, filename, details): @@ -203,30 +149,28 @@ """ suffix, mode, type_ = details - if mode and (not mode.startswith(('r', 'U')) or '+' in mode): - raise ValueError('invalid file open mode {!r}'.format(mode)) - elif file is None and type_ in {PY_SOURCE, PY_COMPILED}: - msg = 'file object required for import (type code {})'.format(type_) - raise ValueError(msg) - elif type_ == PY_SOURCE: - return load_source(name, filename, file) - elif type_ == PY_COMPILED: - return load_compiled(name, filename, file) - elif type_ == C_EXTENSION and load_dynamic is not None: - if file is None: - with open(filename, 'rb') as opened_file: - return load_dynamic(name, filename, opened_file) + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + if mode and (not mode.startswith(('r', 'U')) or '+' in mode): + raise ValueError('invalid file open mode {!r}'.format(mode)) + elif file is None and type_ in {PY_SOURCE, PY_COMPILED, C_EXTENSION}: + msg = 'file object required for import (type code {})'.format(type_) + raise ValueError(msg) + elif type_ == PY_SOURCE: + return load_source(name, filename, file) + elif type_ == PY_COMPILED: + return load_compiled(name, filename, file) + elif type_ == C_EXTENSION: + return load_dynamic(name, filename, file) + elif type_ == PKG_DIRECTORY: + return load_package(name, filename) + elif type_ == C_BUILTIN: + return init_builtin(name) + elif type_ == PY_FROZEN: + return init_frozen(name) else: - return load_dynamic(name, filename, file) - elif type_ == PKG_DIRECTORY: - return load_package(name, filename) - elif type_ == C_BUILTIN: - return init_builtin(name) - elif type_ == PY_FROZEN: - return init_frozen(name) - else: - msg = "Don't know how to import {} (type code {})".format(name, type_) - raise ImportError(msg, name=name) + msg = "Don't know how to import {} (type code {})".format(name, type_) + raise ImportError(msg, name=name) def find_module(name, path=None): @@ -262,16 +206,18 @@ file_path = os.path.join(package_directory, package_file_name) if os.path.isfile(file_path): return None, package_directory, ('', '', PKG_DIRECTORY) - for suffix, mode, type_ in get_suffixes(): - file_name = name + suffix - file_path = os.path.join(entry, file_name) - if os.path.isfile(file_path): - break - else: - continue - break # Break out of outer loop when breaking out of inner loop. + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + for suffix, mode, type_ in get_suffixes(): + file_name = name + suffix + file_path = os.path.join(entry, file_name) + if os.path.isfile(file_path): + break + else: + continue + break # Break out of outer loop when breaking out of inner loop. else: - raise ImportError(_ERR_MSG.format(name), name=name) + raise ImportError(_bootstrap._ERR_MSG.format(name), name=name) encoding = None if mode == 'U': @@ -281,12 +227,31 @@ return file, file_path, (suffix, mode, type_) +_RELOADING = {} + def reload(module): - """**DEPRECATED** - - Reload the module and return it. + """Reload the module and return it. The module must have been successfully imported before. """ - return importlib.reload(module) + if not module or type(module) != type(sys): + raise TypeError("reload() argument must be module") + name = module.__name__ + if name not in sys.modules: + msg = "module {} not in sys.modules" + raise ImportError(msg.format(name), name=name) + if name in _RELOADING: + return _RELOADING[name] + _RELOADING[name] = module + try: + parent_name = name.rpartition('.')[0] + if parent_name and parent_name not in sys.modules: + msg = "parent {!r} not in sys.modules" + raise ImportError(msg.format(parentname), name=parent_name) + return module.__loader__.load_module(name) + finally: + try: + del _RELOADING[name] + except KeyError: + pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/importlib/__init__.py --- a/Lib/importlib/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/importlib/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,5 @@ """A pure Python implementation of import.""" -__all__ = ['__import__', 'import_module', 'invalidate_caches', 'reload'] +__all__ = ['__import__', 'import_module', 'invalidate_caches'] # Bootstrap help ##################################################### @@ -11,7 +11,6 @@ # initialised below if the frozen one is not available). import _imp # Just the builtin component, NOT the full Python module import sys -import types try: import _frozen_importlib as _bootstrap @@ -69,8 +68,6 @@ return loader except KeyError: pass - except AttributeError: - raise ValueError('{}.__loader__ is not set'.format(name)) return _bootstrap._find_module(name, path) @@ -91,34 +88,3 @@ break level += 1 return _bootstrap._gcd_import(name[level:], package, level) - - -_RELOADING = {} - - -def reload(module): - """Reload the module and return it. - - The module must have been successfully imported before. - - """ - if not module or not isinstance(module, types.ModuleType): - raise TypeError("reload() argument must be module") - name = module.__name__ - if name not in sys.modules: - msg = "module {} not in sys.modules" - raise ImportError(msg.format(name), name=name) - if name in _RELOADING: - return _RELOADING[name] - _RELOADING[name] = module - try: - parent_name = name.rpartition('.')[0] - if parent_name and parent_name not in sys.modules: - msg = "parent {!r} not in sys.modules" - raise ImportError(msg.format(parentname), name=parent_name) - return module.__loader__.load_module(name) - finally: - try: - del _RELOADING[name] - except KeyError: - pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/importlib/_bootstrap.py Fri Feb 01 23:12:09 2013 +0100 @@ -9,7 +9,7 @@ # # IMPORTANT: Whenever making changes to this module, be sure to run # a top-level make in order to get the frozen version of the module -# update. Not doing so will result in the Makefile to fail for +# update. Not doing so, will result in the Makefile to fail for # all others who don't have a ./python around to freeze the module # in the early stages of compilation. # @@ -20,6 +20,10 @@ # reference any injected objects! This includes not only global code but also # anything specified at the class level. +# XXX Make sure all public names have no single leading underscore and all +# others do. + + # Bootstrap-related code ###################################################### _CASE_INSENSITIVE_PLATFORMS = 'win', 'cygwin', 'darwin' @@ -37,32 +41,58 @@ return _relax_case +# TODO: Expose from marshal def _w_long(x): - """Convert a 32-bit integer to little-endian.""" - return (int(x) & 0xFFFFFFFF).to_bytes(4, 'little') + """Convert a 32-bit integer to little-endian. + XXX Temporary until marshal's long functions are exposed. + """ + x = int(x) + int_bytes = [] + int_bytes.append(x & 0xFF) + int_bytes.append((x >> 8) & 0xFF) + int_bytes.append((x >> 16) & 0xFF) + int_bytes.append((x >> 24) & 0xFF) + return bytearray(int_bytes) + + +# TODO: Expose from marshal def _r_long(int_bytes): - """Convert 4 bytes in little-endian to an integer.""" - return int.from_bytes(int_bytes, 'little') + """Convert 4 bytes in little-endian to an integer. + + XXX Temporary until marshal's long function are exposed. + + """ + x = int_bytes[0] + x |= int_bytes[1] << 8 + x |= int_bytes[2] << 16 + x |= int_bytes[3] << 24 + return x def _path_join(*path_parts): """Replacement for os.path.join().""" - return path_sep.join([part.rstrip(path_separators) - for part in path_parts if part]) + new_parts = [] + for part in path_parts: + if not part: + continue + new_parts.append(part) + if part[-1] not in path_separators: + new_parts.append(path_sep) + return ''.join(new_parts[:-1]) # Drop superfluous path separator. def _path_split(path): """Replacement for os.path.split().""" - if len(path_separators) == 1: - front, _, tail = path.rpartition(path_sep) - return front, tail for x in reversed(path): if x in path_separators: - front, tail = path.rsplit(x, maxsplit=1) - return front, tail - return '', path + sep = x + break + else: + sep = path_sep + front, _, tail = path.rpartition(sep) + return front, tail def _path_is_mode_type(path, mode): @@ -121,6 +151,15 @@ _code_type = type(_wrap.__code__) +def new_module(name): + """Create a new module. + + The module is not entered into sys.modules. + + """ + return type(_io)(name) + + # Module-level locking ######################################################## # A dict mapping module names to weakrefs of _ModuleLock instances @@ -175,7 +214,7 @@ self.count += 1 return True if self.has_deadlock(): - raise _DeadlockError('deadlock detected by %r' % self) + raise _DeadlockError("deadlock detected by %r" % self) if self.wakeup.acquire(False): self.waiters += 1 # Wait for a release() call @@ -188,7 +227,7 @@ tid = _thread.get_ident() with self.lock: if self.owner != tid: - raise RuntimeError('cannot release un-acquired lock') + raise RuntimeError("cannot release un-acquired lock") assert self.count > 0 self.count -= 1 if self.count == 0: @@ -198,7 +237,7 @@ self.wakeup.release() def __repr__(self): - return '_ModuleLock({!r}) at {}'.format(self.name, id(self)) + return "_ModuleLock({!r}) at {}".format(self.name, id(self)) class _DummyModuleLock: @@ -215,11 +254,11 @@ def release(self): if self.count == 0: - raise RuntimeError('cannot release un-acquired lock') + raise RuntimeError("cannot release un-acquired lock") self.count -= 1 def __repr__(self): - return '_DummyModuleLock({!r}) at {}'.format(self.name, id(self)) + return "_DummyModuleLock({!r}) at {}".format(self.name, id(self)) # The following two functions are for consumption by Python/import.c. @@ -276,106 +315,95 @@ # Finder/loader utility code ############################################### -# Magic word to reject .pyc files generated by other Python versions. -# It should change for each incompatible change to the bytecode. -# -# The value of CR and LF is incorporated so if you ever read or write -# a .pyc file in text mode the magic number will be wrong; also, the -# Apple MPW compiler swaps their values, botching string constants. -# -# The magic numbers must be spaced apart at least 2 values, as the -# -U interpeter flag will cause MAGIC+1 being used. They have been -# odd numbers for some time now. -# -# There were a variety of old schemes for setting the magic number. -# The current working scheme is to increment the previous value by -# 10. -# -# Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic -# number also includes a new "magic tag", i.e. a human readable string used -# to represent the magic number in __pycache__ directories. When you change -# the magic number, you must also set a new unique magic tag. Generally this -# can be named after the Python major version of the magic number bump, but -# it can really be anything, as long as it's different than anything else -# that's come before. The tags are included in the following table, starting -# with Python 3.2a0. -# -# Known values: -# Python 1.5: 20121 -# Python 1.5.1: 20121 -# Python 1.5.2: 20121 -# Python 1.6: 50428 -# Python 2.0: 50823 -# Python 2.0.1: 50823 -# Python 2.1: 60202 -# Python 2.1.1: 60202 -# Python 2.1.2: 60202 -# Python 2.2: 60717 -# Python 2.3a0: 62011 -# Python 2.3a0: 62021 -# Python 2.3a0: 62011 (!) -# Python 2.4a0: 62041 -# Python 2.4a3: 62051 -# Python 2.4b1: 62061 -# Python 2.5a0: 62071 -# Python 2.5a0: 62081 (ast-branch) -# Python 2.5a0: 62091 (with) -# Python 2.5a0: 62092 (changed WITH_CLEANUP opcode) -# Python 2.5b3: 62101 (fix wrong code: for x, in ...) -# Python 2.5b3: 62111 (fix wrong code: x += yield) -# Python 2.5c1: 62121 (fix wrong lnotab with for loops and -# storing constants that should have been removed) -# Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp) -# Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode) -# Python 2.6a1: 62161 (WITH_CLEANUP optimization) -# Python 2.7a0: 62171 (optimize list comprehensions/change LIST_APPEND) -# Python 2.7a0: 62181 (optimize conditional branches: -# introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) -# Python 2.7a0 62191 (introduce SETUP_WITH) -# Python 2.7a0 62201 (introduce BUILD_SET) -# Python 2.7a0 62211 (introduce MAP_ADD and SET_ADD) -# Python 3000: 3000 -# 3010 (removed UNARY_CONVERT) -# 3020 (added BUILD_SET) -# 3030 (added keyword-only parameters) -# 3040 (added signature annotations) -# 3050 (print becomes a function) -# 3060 (PEP 3115 metaclass syntax) -# 3061 (string literals become unicode) -# 3071 (PEP 3109 raise changes) -# 3081 (PEP 3137 make __file__ and __name__ unicode) -# 3091 (kill str8 interning) -# 3101 (merge from 2.6a0, see 62151) -# 3103 (__file__ points to source file) -# Python 3.0a4: 3111 (WITH_CLEANUP optimization). -# Python 3.0a5: 3131 (lexical exception stacking, including POP_EXCEPT) -# Python 3.1a0: 3141 (optimize list, set and dict comprehensions: -# change LIST_APPEND and SET_ADD, add MAP_ADD) -# Python 3.1a0: 3151 (optimize conditional branches: -# introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) -# Python 3.2a0: 3160 (add SETUP_WITH) -# tag: cpython-32 -# Python 3.2a1: 3170 (add DUP_TOP_TWO, remove DUP_TOPX and ROT_FOUR) -# tag: cpython-32 -# Python 3.2a2 3180 (add DELETE_DEREF) -# Python 3.3a0 3190 __class__ super closure changed -# Python 3.3a0 3200 (__qualname__ added) -# 3210 (added size modulo 2**32 to the pyc header) -# Python 3.3a1 3220 (changed PEP 380 implementation) -# Python 3.3a4 3230 (revert changes to implicit __class__ closure) -# Python 3.4a1 3250 (evaluate positional default arguments before -# keyword-only defaults) -# Python 3.4a1 3260 (add LOAD_CLASSDEREF; allow locals of class to override -# free vars) -# Python 3.4a1 3270 (various tweaks to the __class__ closure) -# Python 3.4a1 3280 (remove implicit class argument) -# -# MAGIC must change whenever the bytecode emitted by the compiler may no -# longer be understood by older implementations of the eval loop (usually -# due to the addition of new opcodes). +"""Magic word to reject .pyc files generated by other Python versions. +It should change for each incompatible change to the bytecode. -MAGIC_NUMBER = (3280).to_bytes(2, 'little') + b'\r\n' -_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c +The value of CR and LF is incorporated so if you ever read or write +a .pyc file in text mode the magic number will be wrong; also, the +Apple MPW compiler swaps their values, botching string constants. + +The magic numbers must be spaced apart at least 2 values, as the +-U interpeter flag will cause MAGIC+1 being used. They have been +odd numbers for some time now. + +There were a variety of old schemes for setting the magic number. +The current working scheme is to increment the previous value by +10. + +Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic +number also includes a new "magic tag", i.e. a human readable string used +to represent the magic number in __pycache__ directories. When you change +the magic number, you must also set a new unique magic tag. Generally this +can be named after the Python major version of the magic number bump, but +it can really be anything, as long as it's different than anything else +that's come before. The tags are included in the following table, starting +with Python 3.2a0. + +Known values: + Python 1.5: 20121 + Python 1.5.1: 20121 + Python 1.5.2: 20121 + Python 1.6: 50428 + Python 2.0: 50823 + Python 2.0.1: 50823 + Python 2.1: 60202 + Python 2.1.1: 60202 + Python 2.1.2: 60202 + Python 2.2: 60717 + Python 2.3a0: 62011 + Python 2.3a0: 62021 + Python 2.3a0: 62011 (!) + Python 2.4a0: 62041 + Python 2.4a3: 62051 + Python 2.4b1: 62061 + Python 2.5a0: 62071 + Python 2.5a0: 62081 (ast-branch) + Python 2.5a0: 62091 (with) + Python 2.5a0: 62092 (changed WITH_CLEANUP opcode) + Python 2.5b3: 62101 (fix wrong code: for x, in ...) + Python 2.5b3: 62111 (fix wrong code: x += yield) + Python 2.5c1: 62121 (fix wrong lnotab with for loops and + storing constants that should have been removed) + Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp) + Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode) + Python 2.6a1: 62161 (WITH_CLEANUP optimization) + Python 3000: 3000 + 3010 (removed UNARY_CONVERT) + 3020 (added BUILD_SET) + 3030 (added keyword-only parameters) + 3040 (added signature annotations) + 3050 (print becomes a function) + 3060 (PEP 3115 metaclass syntax) + 3061 (string literals become unicode) + 3071 (PEP 3109 raise changes) + 3081 (PEP 3137 make __file__ and __name__ unicode) + 3091 (kill str8 interning) + 3101 (merge from 2.6a0, see 62151) + 3103 (__file__ points to source file) + Python 3.0a4: 3111 (WITH_CLEANUP optimization). + Python 3.0a5: 3131 (lexical exception stacking, including POP_EXCEPT) + Python 3.1a0: 3141 (optimize list, set and dict comprehensions: + change LIST_APPEND and SET_ADD, add MAP_ADD) + Python 3.1a0: 3151 (optimize conditional branches: + introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) + Python 3.2a0: 3160 (add SETUP_WITH) + tag: cpython-32 + Python 3.2a1: 3170 (add DUP_TOP_TWO, remove DUP_TOPX and ROT_FOUR) + tag: cpython-32 + Python 3.2a2 3180 (add DELETE_DEREF) + Python 3.3a0 3190 __class__ super closure changed + Python 3.3a0 3200 (__qualname__ added) + 3210 (added size modulo 2**32 to the pyc header) + Python 3.3a1 3220 (changed PEP 380 implementation) + Python 3.3a4 3230 (revert changes to implicit __class__ closure) + +MAGIC must change whenever the bytecode emitted by the compiler may no +longer be understood by older implementations of the eval loop (usually +due to the addition of new opcodes). + +""" +_RAW_MAGIC_NUMBER = 3230 | ord('\r') << 16 | ord('\n') << 24 +_MAGIC_BYTES = bytes(_RAW_MAGIC_NUMBER >> n & 0xff for n in range(0, 25, 8)) _PYCACHE = '__pycache__' @@ -443,130 +471,26 @@ """ if len(bytecode_path) == 0: return None - rest, _, extension = bytecode_path.rpartition('.') - if not rest or extension.lower()[-3:-1] != 'py': + rest, _, extension = bytecode_path.rparition('.') + if not rest or extension.lower()[-3:-1] != '.py': return bytecode_path + try: source_path = source_from_cache(bytecode_path) except (NotImplementedError, ValueError): - source_path = bytecode_path[:-1] - return source_path if _path_isfile(source_path) else bytecode_path + source_path = bytcode_path[-1:] + return source_path if _path_isfile(source_stats) else bytecode_path -def _calc_mode(path): - """Calculate the mode permissions for a bytecode file.""" - try: - mode = _os.stat(path).st_mode - except OSError: - mode = 0o666 - # We always ensure write access so we can update cached files - # later even when the source files are read-only on Windows (#6074) - mode |= 0o200 - return mode - -def _verbose_message(message, *args, verbosity=1): +def _verbose_message(message, *args): """Print the message to stderr if -v/PYTHONVERBOSE is turned on.""" - if sys.flags.verbose >= verbosity: + if sys.flags.verbose: if not message.startswith(('#', 'import ')): message = '# ' + message print(message.format(*args), file=sys.stderr) -class _ManageReload: - - def __init__(self, name): - self._name = name - - def __enter__(self): - self._is_reload = self._name in sys.modules - - def __exit__(self, *args): - if any(arg is not None for arg in args) and not self._is_reload: - try: - del sys.modules[self._name] - except KeyError: - pass - - -# Written as a class only because contextlib is not available. -class _ModuleManager(_ManageReload): - - """Context manager which returns the module to be loaded. - - Does the proper unloading from sys.modules upon failure. - - """ - - def __init__(self, name, *, reset_name=True): - """Prepare the context manager. - - The reset_name argument specifies whether to unconditionally reset - the __name__ attribute if the module is found to be a reload. - """ - super().__init__(name) - self._reset_name = reset_name - - def __enter__(self): - super().__enter__() - self._module = sys.modules.get(self._name) - if not self._is_reload: - # This must be done before open() is called as the 'io' module - # implicitly imports 'locale' and would otherwise trigger an - # infinite loop. - self._module = type(_io)(self._name) - # This must be done before putting the module in sys.modules - # (otherwise an optimization shortcut in import.c becomes wrong) - self._module.__initializing__ = True - sys.modules[self._name] = self._module - elif self._reset_name: - try: - self._module.__name__ = self._name - except AttributeError: - pass - return self._module - - def __exit__(self, *args): - self._module.__initializing__ = False - del self._module - super().__exit__(*args) - - -def module_to_load(name, *, reset_name=True): - """Return a context manager which provides the module object to load. - - If reset_name is true, reset the module's __name__ to 'name'. - """ - # Hiding _ModuleManager behind a function for better naming. - return _ModuleManager(name, reset_name=reset_name) - - -def _init_package_attrs(loader, module): - """Set __package__ and __path__ based on what loader.is_package() says.""" - name = module.__name__ - try: - is_package = loader.is_package(name) - except ImportError: - pass - else: - if is_package: - module.__package__ = name - module.__path__ = [] - else: - module.__package__ = name.rpartition('.')[0] - - -def _init_file_attrs(loader, module): - """Set __file__ and __path__ based on loader.get_filename().""" - try: - module.__file__ = loader.get_filename(module.__name__) - except ImportError: - pass - else: - if module.__name__ == module.__package__: - module.__path__.append(_path_split(module.__file__)[0]) - - def set_package(fxn): """Set __package__ on the returned module.""" def set_package_wrapper(*args, **kwargs): @@ -584,13 +508,68 @@ """Set __loader__ on the returned module.""" def set_loader_wrapper(self, *args, **kwargs): module = fxn(self, *args, **kwargs) - if getattr(module, '__loader__', None) is None: + if not hasattr(module, '__loader__'): module.__loader__ = self return module _wrap(set_loader_wrapper, fxn) return set_loader_wrapper +def module_for_loader(fxn): + """Decorator to handle selecting the proper module for loaders. + + The decorated function is passed the module to use instead of the module + name. The module passed in to the function is either from sys.modules if + it already exists or is a new module. If the module is new, then __name__ + is set the first argument to the method, __loader__ is set to self, and + __package__ is set accordingly (if self.is_package() is defined) will be set + before it is passed to the decorated function (if self.is_package() does + not work for the module it will be set post-load). + + If an exception is raised and the decorator created the module it is + subsequently removed from sys.modules. + + The decorator assumes that the decorated function takes the module name as + the second argument. + + """ + def module_for_loader_wrapper(self, fullname, *args, **kwargs): + module = sys.modules.get(fullname) + is_reload = module is not None + if not is_reload: + # This must be done before open() is called as the 'io' module + # implicitly imports 'locale' and would otherwise trigger an + # infinite loop. + module = new_module(fullname) + # This must be done before putting the module in sys.modules + # (otherwise an optimization shortcut in import.c becomes wrong) + module.__initializing__ = True + sys.modules[fullname] = module + module.__loader__ = self + try: + is_package = self.is_package(fullname) + except (ImportError, AttributeError): + pass + else: + if is_package: + module.__package__ = fullname + else: + module.__package__ = fullname.rpartition('.')[0] + else: + module.__initializing__ = True + try: + # If __package__ was not set above, __import__() will do it later. + return fxn(self, module, *args, **kwargs) + except: + if not is_reload: + del sys.modules[fullname] + raise + finally: + module.__initializing__ = False + _wrap(module_for_loader_wrapper, fxn) + return module_for_loader_wrapper + + def _check_name(method): """Decorator to verify that the module being requested matches the one the loader can handle. @@ -603,7 +582,7 @@ if name is None: name = self.name elif self.name != name: - raise ImportError('loader cannot handle %s' % name, name=name) + raise ImportError("loader cannot handle %s" % name, name=name) return method(self, name, *args, **kwargs) _wrap(_check_name_wrapper, method) return _check_name_wrapper @@ -613,7 +592,7 @@ """Decorator to verify the named module is built-in.""" def _requires_builtin_wrapper(self, fullname): if fullname not in sys.builtin_module_names: - raise ImportError('{} is not a built-in module'.format(fullname), + raise ImportError("{} is not a built-in module".format(fullname), name=fullname) return fxn(self, fullname) _wrap(_requires_builtin_wrapper, fxn) @@ -624,7 +603,7 @@ """Decorator to verify the named module is frozen.""" def _requires_frozen_wrapper(self, fullname): if not _imp.is_frozen(fullname): - raise ImportError('{} is not a frozen module'.format(fullname), + raise ImportError("{} is not a frozen module".format(fullname), name=fullname) return fxn(self, fullname) _wrap(_requires_frozen_wrapper, fxn) @@ -639,7 +618,7 @@ # return None. loader, portions = self.find_loader(fullname) if loader is None and len(portions): - msg = 'Not importing directory {}: missing __init__' + msg = "Not importing directory {}: missing __init__" _warnings.warn(msg.format(portions[0]), ImportWarning) return loader @@ -660,22 +639,21 @@ exc_details['name'] = name else: # To prevent having to make all messages have a conditional name. - name = '' + name = 'bytecode' if path is not None: exc_details['path'] = path magic = data[:4] raw_timestamp = data[4:8] raw_size = data[8:12] - if magic != MAGIC_NUMBER: - message = 'bad magic number in {!r}: {!r}'.format(name, magic) - _verbose_message(message) - raise ImportError(message, **exc_details) + if magic != _MAGIC_BYTES: + msg = 'bad magic number in {!r}: {!r}'.format(name, magic) + raise ImportError(msg, **exc_details) elif len(raw_timestamp) != 4: - message = 'reached EOF while reading timestamp in {!r}'.format(name) + message = 'bad timestamp in {!r}'.format(name) _verbose_message(message) raise EOFError(message) elif len(raw_size) != 4: - message = 'reached EOF while reading size of source in {!r}'.format(name) + message = 'bad size in {!r}'.format(name) _verbose_message(message) raise EOFError(message) if source_stats is not None: @@ -694,7 +672,7 @@ pass else: if _r_long(raw_size) != source_size: - raise ImportError('bytecode is stale for {!r}'.format(name), + raise ImportError("bytecode is stale for {!r}".format(name), **exc_details) return data[12:] @@ -708,30 +686,9 @@ _imp._fix_co_filename(code, source_path) return code else: - raise ImportError('Non-code object in {!r}'.format(bytecode_path), + raise ImportError("Non-code object in {!r}".format(bytecode_path), name=name, path=bytecode_path) -def _code_to_bytecode(code, mtime=0, source_size=0): - """Compile a code object into bytecode for writing out to a byte-compiled - file.""" - data = bytearray(MAGIC_NUMBER) - data.extend(_w_long(mtime)) - data.extend(_w_long(source_size)) - data.extend(marshal.dumps(code)) - return data - - -def decode_source(source_bytes): - """Decode bytes representing source code and return the string. - - Universal newline support is used in the decoding. - """ - import tokenize # To avoid bootstrap issues. - source_bytes_readline = _io.BytesIO(source_bytes).readline - encoding = tokenize.detect_encoding(source_bytes_readline) - newline_decoder = _io.IncrementalNewlineDecoder(None, True) - return newline_decoder.decode(source_bytes.decode(encoding[0])) - # Loaders ##################################################################### @@ -746,7 +703,7 @@ @classmethod def module_repr(cls, module): - return ''.format(module.__name__) + return "".format(module.__name__) @classmethod def find_module(cls, fullname, path=None): @@ -765,8 +722,13 @@ @_requires_builtin def load_module(cls, fullname): """Load a built-in module.""" - with _ManageReload(fullname): + is_reload = fullname in sys.modules + try: return _call_with_frames_removed(_imp.init_builtin, fullname) + except: + if not is_reload and fullname in sys.modules: + del sys.modules[fullname] + raise @classmethod @_requires_builtin @@ -798,7 +760,7 @@ @classmethod def module_repr(cls, m): - return ''.format(m.__name__) + return "".format(m.__name__) @classmethod def find_module(cls, fullname, path=None): @@ -811,11 +773,16 @@ @_requires_frozen def load_module(cls, fullname): """Load a frozen module.""" - with _ManageReload(fullname): + is_reload = fullname in sys.modules + try: m = _call_with_frames_removed(_imp.init_frozen, fullname) # Let our own module_repr() method produce a suitable repr. del m.__file__ return m + except: + if not is_reload and fullname in sys.modules: + del sys.modules[fullname] + raise @classmethod @_requires_frozen @@ -842,11 +809,11 @@ """ REGISTRY_KEY = ( - 'Software\\Python\\PythonCore\\{sys_version}' - '\\Modules\\{fullname}') + "Software\\Python\\PythonCore\\{sys_version}" + "\\Modules\\{fullname}") REGISTRY_KEY_DEBUG = ( - 'Software\\Python\\PythonCore\\{sys_version}' - '\\Modules\\{fullname}\\Debug') + "Software\\Python\\PythonCore\\{sys_version}" + "\\Modules\\{fullname}\\Debug") DEBUG_BUILD = False # Changed in _setup() @classmethod @@ -866,7 +833,7 @@ sys_version=sys.version[:3]) try: with cls._open_registry(key) as hkey: - filepath = _winreg.QueryValue(hkey, '') + filepath = _winreg.QueryValue(hkey, "") except OSError: return None return filepath @@ -899,32 +866,28 @@ tail_name = fullname.rpartition('.')[2] return filename_base == '__init__' and tail_name != '__init__' - def init_module_attrs(self, module): - """Set various attributes on the module. - - ExecutionLoader.init_module_attrs() is used to set __loader__, - __package__, __file__, and optionally __path__. The __cached__ attribute - is set using imp.cache_from_source() and __file__. - """ - module.__loader__ = self # Loader - _init_package_attrs(self, module) # InspectLoader - _init_file_attrs(self, module) # ExecutionLoader - if hasattr(module, '__file__'): # SourceLoader + @module_for_loader + def _load_module(self, module, *, sourceless=False): + """Helper for load_module able to handle either source or sourceless + loading.""" + name = module.__name__ + code_object = self.get_code(name) + module.__file__ = self.get_filename(name) + if not sourceless: try: module.__cached__ = cache_from_source(module.__file__) except NotImplementedError: - pass - - def load_module(self, fullname): - """Load the specified module into sys.modules and return it.""" - with module_to_load(fullname) as module: - self.init_module_attrs(module) - code = self.get_code(fullname) - if code is None: - raise ImportError('cannot load module {!r} when get_code() ' - 'returns None'.format(fullname)) - _call_with_frames_removed(exec, code, module.__dict__) - return module + module.__cached__ = module.__file__ + else: + module.__cached__ = module.__file__ + module.__package__ = name + if self.is_package(name): + module.__path__ = [_path_split(module.__file__)[0]] + else: + module.__package__ = module.__package__.rpartition('.')[0] + module.__loader__ = self + _call_with_frames_removed(exec, code_object, module.__dict__) + return module class SourceLoader(_LoaderBasics): @@ -932,10 +895,8 @@ def path_mtime(self, path): """Optional method that returns the modification time (an int) for the specified path, where path is a str. - - Raises IOError when the path cannot be handled. """ - raise IOError + raise NotImplementedError def path_stats(self, path): """Optional method returning a metadata dict for the specified path @@ -946,7 +907,6 @@ - 'size' (optional) is the size in bytes of the source code. Implementing this method allows the loader to read bytecode files. - Raises IOError when the path cannot be handled. """ return {'mtime': self.path_mtime(path)} @@ -964,26 +924,40 @@ """Optional method which writes data (bytes) to a file path (a str). Implementing this method allows for the writing of bytecode files. + """ + raise NotImplementedError def get_source(self, fullname): """Concrete implementation of InspectLoader.get_source.""" + import tokenize path = self.get_filename(fullname) try: source_bytes = self.get_data(path) except OSError as exc: - raise ImportError('source not available through get_data()', + raise ImportError("source not available through get_data()", name=fullname) from exc - return decode_source(source_bytes) + readsource = _io.BytesIO(source_bytes).readline + try: + encoding = tokenize.detect_encoding(readsource) + except SyntaxError as exc: + raise ImportError("Failed to detect encoding", + name=fullname) from exc + newline_decoder = _io.IncrementalNewlineDecoder(None, True) + try: + return newline_decoder.decode(source_bytes.decode(encoding[0])) + except UnicodeDecodeError as exc: + raise ImportError("Failed to decode source file", + name=fullname) from exc - def source_to_code(self, data, path, *, _optimize=-1): + def source_to_code(self, data, path): """Return the code object compiled from source. The 'data' argument can be any object type that compile() supports. """ return _call_with_frames_removed(compile, data, path, 'exec', - dont_inherit=True, optimize=_optimize) + dont_inherit=True) def get_code(self, fullname): """Concrete implementation of InspectLoader.get_code. @@ -1001,7 +975,7 @@ else: try: st = self.path_stats(source_path) - except IOError: + except NotImplementedError: pass else: source_mtime = int(st['mtime']) @@ -1026,9 +1000,11 @@ code_object = self.source_to_code(source_bytes, source_path) _verbose_message('code object from {}', source_path) if (not sys.dont_write_bytecode and bytecode_path is not None and - source_mtime is not None): - data = _code_to_bytecode(code_object, source_mtime, - len(source_bytes)) + source_mtime is not None): + data = bytearray(_MAGIC_BYTES) + data.extend(_w_long(source_mtime)) + data.extend(_w_long(len(source_bytes))) + data.extend(marshal.dumps(code_object)) try: self._cache_bytecode(source_path, bytecode_path, data) _verbose_message('wrote {!r}', bytecode_path) @@ -1036,6 +1012,16 @@ pass return code_object + def load_module(self, fullname): + """Concrete implementation of Loader.load_module. + + Requires ExecutionLoader.get_filename and ResourceLoader.get_data to be + implemented to load source code. Use of bytecode is dictated by whether + get_code uses/writes bytecode. + + """ + return self._load_module(fullname) + class FileLoader: @@ -1077,7 +1063,13 @@ def _cache_bytecode(self, source_path, bytecode_path, data): # Adapt between the two APIs - mode = _calc_mode(source_path) + try: + mode = _os.stat(source_path).st_mode + except OSError: + mode = 0o666 + # We always ensure write access so we can update cached files + # later even when the source files are read-only on Windows (#6074) + mode |= 0o200 return self.set_data(bytecode_path, data, _mode=mode) def set_data(self, path, data, *, _mode=0o666): @@ -1113,9 +1105,8 @@ """Loader which handles sourceless file imports.""" - def init_module_attrs(self, module): - super().init_module_attrs(module) - module.__cached__ = module.__file__ + def load_module(self, fullname): + return self._load_module(fullname, sourceless=True) def get_code(self, fullname): path = self.get_filename(fullname) @@ -1149,13 +1140,18 @@ @set_loader def load_module(self, fullname): """Load an extension module.""" - with _ManageReload(fullname): + is_reload = fullname in sys.modules + try: module = _call_with_frames_removed(_imp.load_dynamic, fullname, self.path) _verbose_message('extension module loaded from {!r}', self.path) if self.is_package(fullname) and not hasattr(module, '__path__'): module.__path__ = [_path_split(self.path)[0]] return module + except: + if not is_reload and fullname in sys.modules: + del sys.modules[fullname] + raise def is_package(self, fullname): """Return True if the extension module is a package.""" @@ -1218,7 +1214,7 @@ return len(self._recalculate()) def __repr__(self): - return '_NamespacePath({!r})'.format(self._path) + return "_NamespacePath({!r})".format(self._path) def __contains__(self, item): return item in self._recalculate() @@ -1233,28 +1229,14 @@ @classmethod def module_repr(cls, module): - return ''.format(module.__name__) + return "".format(module.__name__) - def is_package(self, fullname): - return True - - def get_source(self, fullname): - return '' - - def get_code(self, fullname): - return compile('', '', 'exec', dont_inherit=True) - - def init_module_attrs(self, module): - module.__loader__ = self - module.__package__ = module.__name__ - - def load_module(self, fullname): + @module_for_loader + def load_module(self, module): """Load a namespace module.""" _verbose_message('namespace module loaded with path {!r}', self._path) - with module_to_load(fullname) as module: - self.init_module_attrs(module) - module.__path__ = self._path - return module + module.__path__ = self._path + return module # Finders ##################################################################### @@ -1359,12 +1341,12 @@ """ - def __init__(self, path, *loader_details): + def __init__(self, path, *details): """Initialize with the path to search on and a variable number of - 2-tuples containing the loader and the file suffixes the loader - recognizes.""" + 3-tuples containing the loader, file suffixes the loader recognizes, + and a boolean of whether the loader handles packages.""" loaders = [] - for loader, suffixes in loader_details: + for loader, suffixes in details: loaders.extend((suffix, loader) for suffix in suffixes) self._loaders = loaders # Base (directory) path @@ -1413,13 +1395,11 @@ is_namespace = True # Check for a file w/ a proper suffix exists. for suffix, loader in self._loaders: - full_path = _path_join(self.path, tail_module + suffix) - _verbose_message('trying {}'.format(full_path), verbosity=2) if cache_module + suffix in cache: + full_path = _path_join(self.path, tail_module + suffix) if _path_isfile(full_path): return (loader(fullname, full_path), []) if is_namespace: - _verbose_message('possible namespace for {}'.format(base_path)) return (None, [base_path]) return (None, []) @@ -1452,7 +1432,7 @@ lower_suffix_contents.add(new_name) self._path_cache = lower_suffix_contents if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS): - self._relaxed_path_cache = {fn.lower() for fn in contents} + self._relaxed_path_cache = set(fn.lower() for fn in contents) @classmethod def path_hook(cls, *loader_details): @@ -1467,13 +1447,13 @@ def path_hook_for_FileFinder(path): """Path hook for importlib.machinery.FileFinder.""" if not _path_isdir(path): - raise ImportError('only directories are supported', path=path) + raise ImportError("only directories are supported", path=path) return cls(path, *loader_details) return path_hook_for_FileFinder def __repr__(self): - return 'FileFinder({!r})'.format(self.path) + return "FileFinder({!r})".format(self.path) # Import itself ############################################################### @@ -1520,22 +1500,21 @@ def _sanity_check(name, package, level): """Verify arguments are "sane".""" if not isinstance(name, str): - raise TypeError('module name must be str, not {}'.format(type(name))) + raise TypeError("module name must be str, not {}".format(type(name))) if level < 0: raise ValueError('level must be >= 0') if package: if not isinstance(package, str): - raise TypeError('__package__ not set to a string') + raise TypeError("__package__ not set to a string") elif package not in sys.modules: - msg = ('Parent module {!r} not loaded, cannot perform relative ' - 'import') + msg = ("Parent module {!r} not loaded, cannot perform relative " + "import") raise SystemError(msg.format(package)) if not name and level == 0: - raise ValueError('Empty module name') + raise ValueError("Empty module name") -_ERR_MSG_PREFIX = 'No module named ' -_ERR_MSG = _ERR_MSG_PREFIX + '{!r}' +_ERR_MSG = 'No module named {!r}' def _find_and_load_unlocked(name, import_): path = None @@ -1555,7 +1534,11 @@ raise ImportError(msg, name=name) loader = _find_module(name, path) if loader is None: - raise ImportError(_ERR_MSG.format(name), name=name) + exc = ImportError(_ERR_MSG.format(name), name=name) + # TODO(brett): switch to a proper ModuleNotFound exception in Python + # 3.4. + exc._not_found = True + raise exc elif name not in sys.modules: # The parent import may have already imported this module. loader.load_module(name) @@ -1575,7 +1558,7 @@ except AttributeError: pass # Set loader if need be. - if getattr(module, '__loader__', None) is None: + if not hasattr(module, '__loader__'): try: module.__loader__ = loader except AttributeError: @@ -1614,8 +1597,8 @@ module = sys.modules[name] if module is None: _imp.release_lock() - message = ('import of {} halted; ' - 'None in sys.modules'.format(name)) + message = ("import of {} halted; " + "None in sys.modules".format(name)) raise ImportError(message, name=name) _lock_unlock_module(name) return module @@ -1645,7 +1628,9 @@ # Backwards-compatibility dictates we ignore failed # imports triggered by fromlist for modules that don't # exist. - if str(exc).startswith(_ERR_MSG_PREFIX): + # TODO(brett): In Python 3.4, have import raise + # ModuleNotFound and catch that. + if getattr(exc, '_not_found', False): if exc.name == from_name: continue raise @@ -1731,14 +1716,9 @@ else: BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES - module_type = type(sys) - for name, module in sys.modules.items(): - if isinstance(module, module_type): - if getattr(module, '__loader__', None) is None: - if name in sys.builtin_module_names: - module.__loader__ = BuiltinImporter - elif _imp.is_frozen(name): - module.__loader__ = FrozenImporter + for module in (_imp, sys): + if not hasattr(module, '__loader__'): + module.__loader__ = BuiltinImporter self_module = sys.modules[__name__] for builtin_name in ('_io', '_warnings', 'builtins', 'marshal'): @@ -1780,7 +1760,7 @@ setattr(self_module, '_thread', thread_module) setattr(self_module, '_weakref', weakref_module) setattr(self_module, 'path_sep', path_sep) - setattr(self_module, 'path_separators', ''.join(path_separators)) + setattr(self_module, 'path_separators', set(path_separators)) # Constants setattr(self_module, '_relax_case', _make_relax_case()) EXTENSION_SUFFIXES.extend(_imp.extension_suffixes()) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/importlib/abc.py --- a/Lib/importlib/abc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/importlib/abc.py Fri Feb 01 23:12:09 2013 +0100 @@ -8,6 +8,11 @@ raise _frozen_importlib = None import abc +import imp +import marshal +import sys +import tokenize +import warnings def _register(abstract_cls, *classes): @@ -32,8 +37,9 @@ def find_module(self, fullname, path=None): """An abstract method that should find a module. The fullname is a str and the optional path is a str or None. - Returns a Loader object or None. + Returns a Loader object. """ + raise NotImplementedError class MetaPathFinder(Finder): @@ -43,14 +49,16 @@ @abc.abstractmethod def find_module(self, fullname, path): """Abstract method which, when implemented, should find a module. - The fullname is a str and the path is a list of strings or None. - Returns a Loader object or None. + The fullname is a str and the path is a str or None. + Returns a Loader object. """ + raise NotImplementedError def invalidate_caches(self): """An optional method for clearing the finder's cache, if any. This method is used by importlib.invalidate_caches(). """ + return NotImplemented _register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter, machinery.PathFinder, machinery.WindowsRegistryFinder) @@ -62,14 +70,13 @@ @abc.abstractmethod def find_loader(self, fullname): - """Abstract method which, when implemented, returns a module loader or - a possible part of a namespace. + """Abstract method which, when implemented, returns a module loader. The fullname is a str. Returns a 2-tuple of (Loader, portion) where portion is a sequence of file system locations contributing to part of - a namespace package. The sequence may be empty and the loader may be + a namespace package. The sequence may be empty and the loader may be None. """ - return None, [] + raise NotImplementedError find_module = _bootstrap._find_module_shim @@ -77,40 +84,26 @@ """An optional method for clearing the finder's cache, if any. This method is used by PathFinder.invalidate_caches(). """ + return NotImplemented _register(PathEntryFinder, machinery.FileFinder) class Loader(metaclass=abc.ABCMeta): - """Abstract base class for import loaders. - - The optional method module_repr(module) may be defined to provide a - repr for a module when appropriate (see PEP 420). The __repr__() method on - the module type will use the method as appropriate. - - """ + """Abstract base class for import loaders.""" @abc.abstractmethod def load_module(self, fullname): """Abstract method which when implemented should load a module. - The fullname is a str. - - ImportError is raised on failure. - """ - raise ImportError - - def module_repr(self, module): - """Return a module's repr. - - Used by the module type when the method does not raise - NotImplementedError. - """ + The fullname is a str.""" raise NotImplementedError - def init_module_attrs(self, module): - """Set the module's __loader__ attribute.""" - module.__loader__ = self + @abc.abstractmethod + def module_repr(self, module): + """Abstract method which when implemented calculates and returns the + given module's repr.""" + raise NotImplementedError class ResourceLoader(Loader): @@ -126,7 +119,7 @@ def get_data(self, path): """Abstract method which when implemented should return the bytes for the specified path. The path must be a str.""" - raise IOError + raise NotImplementedError class InspectLoader(Loader): @@ -141,54 +134,23 @@ @abc.abstractmethod def is_package(self, fullname): """Abstract method which when implemented should return whether the - module is a package. The fullname is a str. Returns a bool. + module is a package. The fullname is a str. Returns a bool.""" + raise NotImplementedError - Raises ImportError is the module cannot be found. - """ - raise ImportError - + @abc.abstractmethod def get_code(self, fullname): - """Method which returns the code object for the module. - - The fullname is a str. Returns a types.CodeType if possible, else - returns None if a code object does not make sense - (e.g. built-in module). Raises ImportError if the module cannot be - found. - """ - source = self.get_source(fullname) - if source is None: - return None - return self.source_to_code(source) + """Abstract method which when implemented should return the code object + for the module. The fullname is a str. Returns a types.CodeType.""" + raise NotImplementedError @abc.abstractmethod def get_source(self, fullname): """Abstract method which should return the source code for the - module. The fullname is a str. Returns a str. - - Raises ImportError if the module cannot be found. - """ - raise ImportError - - def source_to_code(self, data, path=''): - """Compile 'data' into a code object. - - The 'data' argument can be anything that compile() can handle. The'path' - argument should be where the data was retrieved (when applicable).""" - return compile(data, path, 'exec', dont_inherit=True) - - def init_module_attrs(self, module): - """Initialize the __loader__ and __package__ attributes of the module. - - The name of the module is gleaned from module.__name__. The __package__ - attribute is set based on self.is_package(). - """ - super().init_module_attrs(module) - _bootstrap._init_package_attrs(self, module) - - load_module = _bootstrap._LoaderBasics.load_module + module. The fullname is a str. Returns a str.""" + raise NotImplementedError _register(InspectLoader, machinery.BuiltinImporter, machinery.FrozenImporter, - machinery.ExtensionFileLoader, _bootstrap.NamespaceLoader) + machinery.ExtensionFileLoader) class ExecutionLoader(InspectLoader): @@ -203,39 +165,8 @@ @abc.abstractmethod def get_filename(self, fullname): """Abstract method which should return the value that __file__ is to be - set to. - - Raises ImportError if the module cannot be found. - """ - raise ImportError - - def get_code(self, fullname): - """Method to return the code object for fullname. - - Should return None if not applicable (e.g. built-in module). - Raise ImportError if the module cannot be found. - """ - source = self.get_source(fullname) - if source is None: - return None - try: - path = self.get_filename(fullname) - except ImportError: - return self.source_to_code(source) - else: - return self.source_to_code(source, path) - - def init_module_attrs(self, module): - """Initialize the module's attributes. - - It is assumed that the module's name has been set on module.__name__. - It is also assumed that any path returned by self.get_filename() uses - (one of) the operating system's path separator(s) to separate filenames - from directories in order to set __path__ intelligently. - InspectLoader.init_module_attrs() sets __loader__ and __package__. - """ - super().init_module_attrs(module) - _bootstrap._init_file_attrs(self, module) + set to.""" + raise NotImplementedError class FileLoader(_bootstrap.FileLoader, ResourceLoader, ExecutionLoader): @@ -267,7 +198,7 @@ def path_mtime(self, path): """Return the (int) modification time for the path (str).""" if self.path_stats.__func__ is SourceLoader.path_stats: - raise IOError + raise NotImplementedError return int(self.path_stats(path)['mtime']) def path_stats(self, path): @@ -278,7 +209,7 @@ - 'size' (optional) is the size in bytes of the source code. """ if self.path_mtime.__func__ is SourceLoader.path_mtime: - raise IOError + raise NotImplementedError return {'mtime': self.path_mtime(path)} def set_data(self, path, data): @@ -289,6 +220,8 @@ Any needed intermediary directories are to be created. If for some reason the file cannot be written because of permissions, fail silently. + """ + raise NotImplementedError _register(SourceLoader, machinery.SourceFileLoader) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/importlib/util.py --- a/Lib/importlib/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/importlib/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,17 +1,10 @@ """Utility code for constructing importers, etc.""" -from ._bootstrap import MAGIC_NUMBER -from ._bootstrap import cache_from_source -from ._bootstrap import decode_source -from ._bootstrap import module_to_load +from ._bootstrap import module_for_loader from ._bootstrap import set_loader from ._bootstrap import set_package -from ._bootstrap import source_from_cache from ._bootstrap import _resolve_name -import functools -import warnings - def resolve_name(name, package): """Resolve a relative module name to an absolute one.""" @@ -26,44 +19,3 @@ break level += 1 return _resolve_name(name[level:], package, level) - - -def module_for_loader(fxn): - """Decorator to handle selecting the proper module for loaders. - - The decorated function is passed the module to use instead of the module - name. The module passed in to the function is either from sys.modules if - it already exists or is a new module. If the module is new, then __name__ - is set the first argument to the method, __loader__ is set to self, and - __package__ is set accordingly (if self.is_package() is defined) will be set - before it is passed to the decorated function (if self.is_package() does - not work for the module it will be set post-load). - - If an exception is raised and the decorator created the module it is - subsequently removed from sys.modules. - - The decorator assumes that the decorated function takes the module name as - the second argument. - - """ - warnings.warn('To make it easier for subclasses, please use ' - 'importlib.util.module_to_load() and ' - 'importlib.abc.Loader.init_module_attrs()', - PendingDeprecationWarning, stacklevel=2) - @functools.wraps(fxn) - def module_for_loader_wrapper(self, fullname, *args, **kwargs): - with module_to_load(fullname) as module: - module.__loader__ = self - try: - is_package = self.is_package(fullname) - except (ImportError, AttributeError): - pass - else: - if is_package: - module.__package__ = fullname - else: - module.__package__ = fullname.rpartition('.')[0] - # If __package__ was not set above, __import__() will do it later. - return fxn(self, module, *args, **kwargs) - - return module_for_loader_wrapper diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/inspect.py --- a/Lib/inspect.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/inspect.py Fri Feb 01 23:12:09 2013 +0100 @@ -31,6 +31,7 @@ __author__ = ('Ka-Ping Yee ', 'Yury Selivanov ') +import imp import importlib.machinery import itertools import linecache @@ -439,9 +440,6 @@ """Get the module name, suffix, mode, and module type for a given file.""" warnings.warn('inspect.getmoduleinfo() is deprecated', DeprecationWarning, 2) - with warnings.catch_warnings(): - warnings.simplefilter('ignore', PendingDeprecationWarning) - import imp filename = os.path.basename(path) suffixes = [(-len(suffix), suffix, mode, mtype) for suffix, mode, mtype in imp.get_suffixes()] @@ -478,7 +476,7 @@ if os.path.exists(filename): return filename # only return a non-existent filename if the module has a PEP 302 loader - if getattr(getmodule(object, filename), '__loader__', None) is not None: + if hasattr(getmodule(object, filename), '__loader__'): return filename # or it is in the linecache if filename in linecache.cache: @@ -552,7 +550,7 @@ file = getfile(object) sourcefile = getsourcefile(object) - if not sourcefile and file[:1] + file[-1:] != '<>': + if not sourcefile and file[0] + file[-1] != '<>': raise OSError('source code not available') file = sourcefile if sourcefile else file @@ -2030,19 +2028,19 @@ return self._bound_arguments_cls(self, arguments) - def bind(__bind_self, *args, **kwargs): + def bind(self, *args, **kwargs): '''Get a BoundArguments object, that maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. ''' - return __bind_self._bind(args, kwargs) + return self._bind(args, kwargs) - def bind_partial(__bind_self, *args, **kwargs): + def bind_partial(self, *args, **kwargs): '''Get a BoundArguments object, that partially maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. ''' - return __bind_self._bind(args, kwargs, partial=True) + return self._bind(args, kwargs, partial=True) def __str__(self): result = [] diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ipaddress.py --- a/Lib/ipaddress.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ipaddress.py Fri Feb 01 23:12:09 2013 +0100 @@ -723,7 +723,7 @@ other: An IPv4Network or IPv6Network object of the same type. Returns: - An iterator of the IPv(4|6)Network objects which is self + An iterator of the the IPv(4|6)Network objects which is self minus other. Raises: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/json/__init__.py --- a/Lib/json/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/json/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -96,7 +96,7 @@ "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool - Expecting property name enclosed in double quotes: line 1 column 3 (char 2) + Expecting property name enclosed in double quotes: line 1 column 2 (char 2) """ __version__ = '2.0.9' __all__ = [ diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/json/decoder.py --- a/Lib/json/decoder.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/json/decoder.py Fri Feb 01 23:12:09 2013 +0100 @@ -24,7 +24,7 @@ newline = '\n' lineno = doc.count(newline, 0, pos) + 1 if lineno == 1: - colno = pos + 1 + colno = pos else: colno = pos - doc.rindex(newline, 0, pos) return lineno, colno @@ -158,7 +158,7 @@ if nextchar == '}': if object_pairs_hook is not None: result = object_pairs_hook(pairs) - return result, end + 1 + return result, end pairs = {} if object_hook is not None: pairs = object_hook(pairs) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/json/encoder.py --- a/Lib/json/encoder.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/json/encoder.py Fri Feb 01 23:12:09 2013 +0100 @@ -166,7 +166,6 @@ pass else: return list(iterable) - # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) """ diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/json/tool.py --- a/Lib/json/tool.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/json/tool.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,7 +7,7 @@ "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool - Expecting property name enclosed in double quotes: line 1 column 3 (char 2) + Expecting property name enclosed in double quotes: line 1 column 2 (char 2) """ import sys diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/keyword.py --- a/Lib/keyword.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/keyword.py Fri Feb 01 23:12:09 2013 +0100 @@ -60,12 +60,6 @@ if len(args) > 1: optfile = args[1] else: optfile = "Lib/keyword.py" - # load the output skeleton from the target, taking care to preserve its - # newline convention. - with open(optfile, newline='') as fp: - format = fp.readlines() - nl = format[0][len(format[0].strip()):] if format else '\n' - # scan the source file for keywords with open(iptfile) as fp: strprog = re.compile('"([^"]+)"') @@ -74,21 +68,26 @@ if '{1, "' in line: match = strprog.search(line) if match: - lines.append(" '" + match.group(1) + "'," + nl) + lines.append(" '" + match.group(1) + "',\n") lines.sort() - # insert the lines of keywords into the skeleton + # load the output skeleton from the target + with open(optfile) as fp: + format = fp.readlines() + + # insert the lines of keywords try: - start = format.index("#--start keywords--" + nl) + 1 - end = format.index("#--end keywords--" + nl) + start = format.index("#--start keywords--\n") + 1 + end = format.index("#--end keywords--\n") format[start:end] = lines except ValueError: sys.stderr.write("target does not contain format markers\n") sys.exit(1) # write the output file - with open(optfile, 'w', newline='') as fp: - fp.writelines(format) + fp = open(optfile, 'w') + fp.write(''.join(format)) + fp.close() if __name__ == "__main__": main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/lib2to3/pgen2/grammar.py --- a/Lib/lib2to3/pgen2/grammar.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/lib2to3/pgen2/grammar.py Fri Feb 01 23:12:09 2013 +0100 @@ -20,7 +20,7 @@ class Grammar(object): - """Pgen parsing tables conversion class. + """Pgen parsing tables tables conversion class. Once initialized, this class supplies the grammar tables for the parsing engine implemented by parse.py. The parsing engine @@ -45,7 +45,7 @@ these two are each other's inverse. states -- a list of DFAs, where each DFA is a list of - states, each state is a list of arcs, and each + states, each state is is a list of arcs, and each arc is a (i, j) pair where i is a label and j is a state number. The DFA number is the index into this list. (This name is slightly confusing.) @@ -86,13 +86,15 @@ def dump(self, filename): """Dump the grammar tables to a pickle file.""" - with open(filename, "wb") as f: - pickle.dump(self.__dict__, f, 2) + f = open(filename, "wb") + pickle.dump(self.__dict__, f, 2) + f.close() def load(self, filename): """Load the grammar tables from a pickle file.""" - with open(filename, "rb") as f: - d = pickle.load(f) + f = open(filename, "rb") + d = pickle.load(f) + f.close() self.__dict__.update(d) def copy(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/logging/__init__.py --- a/Lib/logging/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/logging/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -123,22 +123,20 @@ DEBUG = 10 NOTSET = 0 -_levelToName = { - CRITICAL: 'CRITICAL', - ERROR: 'ERROR', - WARNING: 'WARNING', - INFO: 'INFO', - DEBUG: 'DEBUG', - NOTSET: 'NOTSET', -} -_nameToLevel = { - 'CRITICAL': CRITICAL, - 'ERROR': ERROR, - 'WARN': WARNING, - 'WARNING': WARNING, - 'INFO': INFO, - 'DEBUG': DEBUG, - 'NOTSET': NOTSET, +_levelNames = { + CRITICAL : 'CRITICAL', + ERROR : 'ERROR', + WARNING : 'WARNING', + INFO : 'INFO', + DEBUG : 'DEBUG', + NOTSET : 'NOTSET', + 'CRITICAL' : CRITICAL, + 'ERROR' : ERROR, + 'WARN' : WARNING, + 'WARNING' : WARNING, + 'INFO' : INFO, + 'DEBUG' : DEBUG, + 'NOTSET' : NOTSET, } def getLevelName(level): @@ -155,7 +153,7 @@ Otherwise, the string "Level %s" % level is returned. """ - return _levelToName.get(level, ("Level %s" % level)) + return _levelNames.get(level, ("Level %s" % level)) def addLevelName(level, levelName): """ @@ -165,8 +163,8 @@ """ _acquireLock() try: #unlikely to cause an exception, but you never know... - _levelToName[level] = levelName - _nameToLevel[levelName] = level + _levelNames[level] = levelName + _levelNames[levelName] = level finally: _releaseLock() @@ -174,9 +172,9 @@ if isinstance(level, int): rv = level elif str(level) == level: - if level not in _nameToLevel: + if level not in _levelNames: raise ValueError("Unknown level: %r" % level) - rv = _nameToLevel[level] + rv = _levelNames[level] else: raise TypeError("Level not an integer or a valid string: %r" % level) return rv diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/logging/config.py --- a/Lib/logging/config.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/logging/config.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,4 +1,4 @@ -# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -19,7 +19,7 @@ is based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. -Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! """ @@ -144,7 +144,7 @@ h = klass(*args) if "level" in section: level = section["level"] - h.setLevel(level) + h.setLevel(logging._levelNames[level]) if len(fmt): h.setFormatter(formatters[fmt]) if issubclass(klass, logging.handlers.MemoryHandler): @@ -175,8 +175,8 @@ logger.level = logging.NOTSET logger.handlers = [] logger.propagate = True - else: - logger.disabled = disable_existing + elif disable_existing: + logger.disabled = True def _install_loggers(cp, handlers, disable_existing): """Create and install loggers""" @@ -191,7 +191,7 @@ log = root if "level" in section: level = section["level"] - log.setLevel(level) + log.setLevel(logging._levelNames[level]) for h in root.handlers[:]: root.removeHandler(h) hlist = section["handlers"] @@ -237,7 +237,7 @@ existing.remove(qn) if "level" in section: level = section["level"] - logger.setLevel(level) + logger.setLevel(logging._levelNames[level]) for h in logger.handlers[:]: logger.removeHandler(h) logger.propagate = propagate @@ -564,29 +564,14 @@ # As handlers can refer to other handlers, sort the keys # to allow a deterministic order of configuration handlers = config.get('handlers', EMPTY_DICT) - deferred = [] for name in sorted(handlers): try: handler = self.configure_handler(handlers[name]) handler.name = name handlers[name] = handler except Exception as e: - if 'target not configured yet' in str(e): - deferred.append(name) - else: - raise ValueError('Unable to configure handler ' - '%r: %s' % (name, e)) - - # Now do any that were deferred - for name in deferred: - try: - handler = self.configure_handler(handlers[name]) - handler.name = name - handlers[name] = handler - except Exception as e: raise ValueError('Unable to configure handler ' '%r: %s' % (name, e)) - # Next, do loggers - they refer to handlers and filters #we don't want to lose the existing loggers, @@ -672,8 +657,7 @@ else: fmt = config.get('format', None) dfmt = config.get('datefmt', None) - style = config.get('style', '%') - result = logging.Formatter(fmt, dfmt, style) + result = logging.Formatter(fmt, dfmt) return result def configure_filter(self, config): @@ -695,7 +679,6 @@ def configure_handler(self, config): """Configure a handler from a dictionary.""" - config_copy = dict(config) # for restoring in case of error formatter = config.pop('formatter', None) if formatter: try: @@ -711,17 +694,12 @@ c = self.resolve(c) factory = c else: - cname = config.pop('class') - klass = self.resolve(cname) + klass = self.resolve(config.pop('class')) #Special case for handler which refers to another handler if issubclass(klass, logging.handlers.MemoryHandler) and\ 'target' in config: try: - th = self.config['handlers'][config['target']] - if not isinstance(th, logging.Handler): - config.update(config_copy) # restore for deferred cfg - raise TypeError('target not configured yet') - config['target'] = th + config['target'] = self.config['handlers'][config['target']] except Exception as e: raise ValueError('Unable to set target handler ' '%r: %s' % (config['target'], e)) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/logging/handlers.py --- a/Lib/logging/handlers.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/logging/handlers.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,4 +1,4 @@ -# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -18,7 +18,7 @@ Additional handlers for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python. -Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved. To use, simply 'import logging.handlers' and log away! """ @@ -196,12 +196,11 @@ If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted. """ - def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False, atTime=None): + def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False): BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay) self.when = when.upper() self.backupCount = backupCount self.utc = utc - self.atTime = atTime # Calculate the real rollover interval, which is just the number of # seconds between rollovers. Also set the filename suffix used when # a rollover occurs. Current 'when' events supported: @@ -271,22 +270,9 @@ currentHour = t[3] currentMinute = t[4] currentSecond = t[5] - currentDay = t[6] - # r is the number of seconds left between now and the next rotation - if self.atTime is None: - rotate_ts = _MIDNIGHT - else: - rotate_ts = ((self.atTime.hour * 60 + self.atTime.minute)*60 + - self.atTime.second) - - r = rotate_ts - ((currentHour * 60 + currentMinute) * 60 + - currentSecond) - if r < 0: - # Rotate time is before the current time (for example when - # self.rotateAt is 13:45 and it now 14:15), rotation is - # tomorrow. - r += _MIDNIGHT - currentDay = (currentDay + 1) % 7 + # r is the number of seconds left between now and midnight + r = _MIDNIGHT - ((currentHour * 60 + currentMinute) * 60 + + currentSecond) result = currentTime + r # If we are rolling over on a certain day, add in the number of days until # the next rollover, but offset by 1 since we just calculated the time @@ -304,7 +290,7 @@ # This is because the above time calculation takes us to midnight on this # day, i.e. the start of the next day. if self.when.startswith('W'): - day = currentDay # 0 is Monday + day = t[6] # 0 is Monday if day != self.dayOfWeek: if day < self.dayOfWeek: daysToWait = self.dayOfWeek - day @@ -452,8 +438,11 @@ try: # stat the file by path, checking for existence sres = os.stat(self.baseFilename) - except FileNotFoundError: - sres = None + except OSError as err: + if err.errno == errno.ENOENT: + sres = None + else: + raise # compare file system stat with that of our stream file handle if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino: if self.stream is not None: @@ -758,17 +747,13 @@ } def __init__(self, address=('localhost', SYSLOG_UDP_PORT), - facility=LOG_USER, socktype=None): + facility=LOG_USER, socktype=socket.SOCK_DGRAM): """ Initialize a handler. If address is specified as a string, a UNIX socket is used. To log to a local syslogd, "SysLogHandler(address="/dev/log")" can be used. - If facility is not specified, LOG_USER is used. If socktype is - specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific - socket type will be used. For Unix sockets, you can also specify a - socktype of None, in which case socket.SOCK_DGRAM will be used, falling - back to socket.SOCK_STREAM. + If facility is not specified, LOG_USER is used. """ logging.Handler.__init__(self) @@ -781,37 +766,18 @@ self._connect_unixsocket(address) else: self.unixsocket = False - if socktype is None: - socktype = socket.SOCK_DGRAM self.socket = socket.socket(socket.AF_INET, socktype) if socktype == socket.SOCK_STREAM: self.socket.connect(address) - self.socktype = socktype self.formatter = None def _connect_unixsocket(self, address): - use_socktype = self.socktype - if use_socktype is None: - use_socktype = socket.SOCK_DGRAM - self.socket = socket.socket(socket.AF_UNIX, use_socktype) + self.socket = socket.socket(socket.AF_UNIX, self.socktype) try: self.socket.connect(address) - # it worked, so set self.socktype to the used type - self.socktype = use_socktype except OSError: self.socket.close() - if self.socktype is not None: - # user didn't specify falling back, so fail - raise - use_socktype = socket.SOCK_STREAM - self.socket = socket.socket(socket.AF_UNIX, use_socktype) - try: - self.socket.connect(address) - # it worked, so set self.socktype to the used type - self.socktype = use_socktype - except OSError: - self.socket.close() - raise + raise def encodePriority(self, facility, priority): """ @@ -862,9 +828,10 @@ msg = self.ident + msg if self.append_nul: msg += '\000' - - # We need to convert record level to lowercase, maybe this will - # change in the future. + """ + We need to convert record level to lowercase, maybe this will + change in the future. + """ prio = '<%d>' % self.encodePriority(self.facility, self.mapPriority(record.levelname)) prio = prio.encode('utf-8') @@ -876,7 +843,6 @@ try: self.socket.send(msg) except OSError: - self.socket.close() self._connect_unixsocket(self.address) self.socket.send(msg) elif self.socktype == socket.SOCK_DGRAM: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/mailbox.py --- a/Lib/mailbox.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/mailbox.py Fri Feb 01 23:12:09 2013 +0100 @@ -334,8 +334,11 @@ # This overrides an inapplicable implementation in the superclass. try: self.remove(key) - except (KeyError, FileNotFoundError): + except KeyError: pass + except OSError as e: + if e.errno != errno.ENOENT: + raise def __setitem__(self, key, message): """Replace the keyed message; raise KeyError if it doesn't exist.""" @@ -363,11 +366,14 @@ def get_message(self, key): """Return a Message representation or raise a KeyError.""" subpath = self._lookup(key) - with open(os.path.join(self._path, subpath), 'rb') as f: + f = open(os.path.join(self._path, subpath), 'rb') + try: if self._factory: msg = self._factory(f) else: msg = MaildirMessage(f) + finally: + f.close() subdir, name = os.path.split(subpath) msg.set_subdir(subdir) if self.colon in name: @@ -377,8 +383,11 @@ def get_bytes(self, key): """Return a bytes representation or raise a KeyError.""" - with open(os.path.join(self._path, self._lookup(key)), 'rb') as f: + f = open(os.path.join(self._path, self._lookup(key)), 'rb') + try: return f.read().replace(linesep, b'\n') + finally: + f.close() def get_file(self, key): """Return a file-like representation or raise a KeyError.""" @@ -490,12 +499,16 @@ path = os.path.join(self._path, 'tmp', uniq) try: os.stat(path) - except FileNotFoundError: - Maildir._count += 1 - try: - return _create_carefully(path) - except FileExistsError: - pass + except OSError as e: + if e.errno == errno.ENOENT: + Maildir._count += 1 + try: + return _create_carefully(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + else: + raise # Fall through to here if stat succeeded or open raised EEXIST. raise ExternalClashError('Name clash prevented file creation: %s' % @@ -693,9 +706,12 @@ os.chmod(new_file.name, mode) try: os.rename(new_file.name, self._path) - except FileExistsError: - os.remove(self._path) - os.rename(new_file.name, self._path) + except OSError as e: + if e.errno == errno.EEXIST: + os.remove(self._path) + os.rename(new_file.name, self._path) + else: + raise self._file = open(self._path, 'rb+') self._toc = new_toc self._pending = False @@ -1017,7 +1033,7 @@ raise KeyError('No message with key: %s' % key) else: raise - with f: + try: if self._locked: _lock_file(f) try: @@ -1025,6 +1041,8 @@ finally: if self._locked: _unlock_file(f) + finally: + f.close() for name, key_list in self.get_sequences().items(): if key in key_list: msg.add_sequence(name) @@ -1042,7 +1060,7 @@ raise KeyError('No message with key: %s' % key) else: raise - with f: + try: if self._locked: _lock_file(f) try: @@ -1050,6 +1068,8 @@ finally: if self._locked: _unlock_file(f) + finally: + f.close() def get_file(self, key): """Return a file-like representation or raise a KeyError.""" @@ -2071,10 +2091,13 @@ else: os.rename(pre_lock.name, f.name + '.lock') dotlock_done = True - except FileExistsError: - os.remove(pre_lock.name) - raise ExternalClashError('dot lock unavailable: %s' % - f.name) + except OSError as e: + if e.errno == errno.EEXIST: + os.remove(pre_lock.name) + raise ExternalClashError('dot lock unavailable: %s' % + f.name) + else: + raise except: if fcntl: fcntl.lockf(f, fcntl.LOCK_UN) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/modulefinder.py --- a/Lib/modulefinder.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/modulefinder.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,16 +1,13 @@ """Find modules used by a script, using introspection.""" import dis +import imp import importlib.machinery import marshal import os import sys import types import struct -import warnings -with warnings.catch_warnings(): - warnings.simplefilter('ignore', PendingDeprecationWarning) - import imp # XXX Clean up once str8's cstor matches bytes. LOAD_CONST = bytes([dis.opname.index('LOAD_CONST')]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/msilib/__init__.py --- a/Lib/msilib/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/msilib/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -325,7 +325,7 @@ def add_file(self, file, src=None, version=None, language=None): """Add a file to the current component of the directory, starting a new one - if there is no current component. By default, the file name in the source + one if there is no current component. By default, the file name in the source and the file table will be identical. If the src file is specified, it is interpreted relative to the current directory. Optionally, a version and a language can be specified for the entry in the File table.""" diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/__init__.py --- a/Lib/multiprocessing/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -85,11 +85,30 @@ ''' Returns the number of CPUs in the system ''' - num = os.cpu_count() - if num is None: + if sys.platform == 'win32': + try: + num = int(os.environ['NUMBER_OF_PROCESSORS']) + except (ValueError, KeyError): + num = 0 + elif 'bsd' in sys.platform or sys.platform == 'darwin': + comm = '/sbin/sysctl -n hw.ncpu' + if sys.platform == 'darwin': + comm = '/usr' + comm + try: + with os.popen(comm) as p: + num = int(p.read()) + except ValueError: + num = 0 + else: + try: + num = os.sysconf('SC_NPROCESSORS_ONLN') + except (ValueError, OSError, AttributeError): + num = 0 + + if num >= 1: + return num + else: raise NotImplementedError('cannot determine number of cpus') - else: - return num def freeze_support(): ''' diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/connection.py Fri Feb 01 23:12:09 2013 +0100 @@ -12,6 +12,7 @@ import io import os import sys +import pickle import select import socket import struct @@ -201,7 +202,9 @@ """Send a (picklable) object""" self._check_closed() self._check_writable() - self._send_bytes(ForkingPickler.dumps(obj)) + buf = io.BytesIO() + ForkingPickler(buf, pickle.HIGHEST_PROTOCOL).dump(obj) + self._send_bytes(buf.getbuffer()) def recv_bytes(self, maxlength=None): """ @@ -246,7 +249,7 @@ self._check_closed() self._check_readable() buf = self._recv_bytes() - return ForkingPickler.loads(buf.getbuffer()) + return pickle.loads(buf.getbuffer()) def poll(self, timeout=0.0): """Whether there is any input available to be read""" @@ -363,10 +366,7 @@ def _send(self, buf, write=_write): remaining = len(buf) while True: - try: - n = write(self._handle, buf) - except InterruptedError: - continue + n = write(self._handle, buf) remaining -= n if remaining == 0: break @@ -377,10 +377,7 @@ handle = self._handle remaining = size while remaining > 0: - try: - chunk = read(handle, remaining) - except InterruptedError: - continue + chunk = read(handle, remaining) n = len(chunk) if n == 0: if remaining == size: @@ -532,7 +529,9 @@ _winapi.FILE_FLAG_FIRST_PIPE_INSTANCE, _winapi.PIPE_TYPE_MESSAGE | _winapi.PIPE_READMODE_MESSAGE | _winapi.PIPE_WAIT, - 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL + 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, + # default security descriptor: the handle cannot be inherited + _winapi.NULL ) h2 = _winapi.CreateFile( address, access, 0, _winapi.NULL, _winapi.OPEN_EXISTING, @@ -584,13 +583,7 @@ self._unlink = None def accept(self): - while True: - try: - s, self._last_accepted = self._socket.accept() - except InterruptedError: - pass - else: - break + s, self._last_accepted = self._socket.accept() s.setblocking(True) return Connection(s.detach()) @@ -874,7 +867,7 @@ if hasattr(select, 'poll'): def _poll(fds, timeout): if timeout is not None: - timeout = int(timeout * 1000) # timeout is in milliseconds + timeout = int(timeout) * 1000 # timeout is in milliseconds fd_map = {} pollster = select.poll() for fd in fds: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/forking.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,12 +7,9 @@ # Licensed to PSF under a Contributor Agreement. # -import io import os -import pickle import sys import signal -import errno from multiprocessing import util, process @@ -46,15 +43,6 @@ def register(cls, type, reduce): cls._extra_reducers[type] = reduce - @staticmethod - def dumps(obj): - buf = io.BytesIO() - ForkingPickler(buf, pickle.HIGHEST_PROTOCOL).dump(obj) - return buf.getbuffer() - - loads = pickle.loads - - def _reduce_method(m): if m.__self__ is None: return getattr, (m.__class__, m.__func__.__name__) @@ -121,17 +109,12 @@ def poll(self, flag=os.WNOHANG): if self.returncode is None: - while True: - try: - pid, sts = os.waitpid(self.pid, flag) - except OSError as e: - if e.errno == errno.EINTR: - continue - # Child process not yet created. See #1731717 - # e.errno == errno.ECHILD == 10 - return None - else: - break + try: + pid, sts = os.waitpid(self.pid, flag) + except OSError: + # Child process not yet created. See #1731717 + # e.errno == errno.ECHILD == 10 + return None if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) @@ -449,8 +432,7 @@ elif main_name != 'ipython': # Main modules not actually called __main__.py may # contain additional code that should still be executed - import importlib - import types + import imp if main_path is None: dirs = None @@ -461,17 +443,16 @@ assert main_name not in sys.modules, main_name sys.modules.pop('__mp_main__', None) - # We should not try to load __main__ - # since that would execute 'if __name__ == "__main__"' - # clauses, potentially causing a psuedo fork bomb. - loader = importlib.find_loader(main_name, path=dirs) - main_module = types.ModuleType(main_name) + file, path_name, etc = imp.find_module(main_name, dirs) try: - loader.init_module_attrs(main_module) - except AttributeError: # init_module_attrs is optional - pass - main_module.__name__ = '__mp_main__' - code = loader.get_code(main_name) - exec(code, main_module.__dict__) + # We should not do 'imp.load_module("__main__", ...)' + # since that would execute 'if __name__ == "__main__"' + # clauses, potentially causing a psuedo fork bomb. + main_module = imp.load_module( + '__mp_main__', file, path_name, etc + ) + finally: + if file: + file.close() sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/managers.py Fri Feb 01 23:12:09 2013 +0100 @@ -731,7 +731,6 @@ elif kind == '#PROXY': exposed, token = result proxytype = self._manager._registry[token.typeid][-1] - token.address = self._token.address proxy = proxytype( token, self._serializer, manager=self._manager, authkey=self._authkey, exposed=exposed diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/pool.py --- a/Lib/multiprocessing/pool.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/pool.py Fri Feb 01 23:12:09 2013 +0100 @@ -17,11 +17,9 @@ import queue import itertools import collections -import os import time -import traceback -from multiprocessing import Process, TimeoutError +from multiprocessing import Process, cpu_count, TimeoutError from multiprocessing.util import Finalize, debug # @@ -45,29 +43,6 @@ return list(itertools.starmap(args[0], args[1])) # -# Hack to embed stringification of remote traceback in local traceback -# - -class RemoteTraceback(Exception): - def __init__(self, tb): - self.tb = tb - def __str__(self): - return self.tb - -class ExceptionWithTraceback: - def __init__(self, exc, tb): - tb = traceback.format_exception(type(exc), exc, tb) - tb = ''.join(tb) - self.exc = exc - self.tb = '\n"""\n%s"""' % tb - def __reduce__(self): - return rebuild_exc, (self.exc, self.tb) - -def rebuild_exc(exc, tb): - exc.__cause__ = RemoteTraceback(tb) - return exc - -# # Code run by worker processes # @@ -115,7 +90,6 @@ try: result = (True, func(*args, **kwds)) except Exception as e: - e = ExceptionWithTraceback(e, e.__traceback__) result = (False, e) try: put((job, i, result)) @@ -148,7 +122,10 @@ self._initargs = initargs if processes is None: - processes = os.cpu_count() or 1 + try: + processes = cpu_count() + except NotImplementedError: + processes = 1 if processes < 1: raise ValueError("Number of processes must be at least 1") @@ -595,8 +572,6 @@ self._event.set() del self._cache[self._job] -AsyncResult = ApplyResult # create alias -- see #17805 - # # Class whose instances are returned by `Pool.map_async()` # diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/queues.py --- a/Lib/multiprocessing/queues.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/queues.py Fri Feb 01 23:12:09 2013 +0100 @@ -22,7 +22,7 @@ from multiprocessing.connection import Pipe from multiprocessing.synchronize import Lock, BoundedSemaphore, Semaphore, Condition from multiprocessing.util import debug, info, Finalize, register_after_fork -from multiprocessing.forking import assert_spawning, ForkingPickler +from multiprocessing.forking import assert_spawning # # Queue type using a pipe, buffer and thread @@ -69,8 +69,8 @@ self._joincancelled = False self._closed = False self._close = None - self._send_bytes = self._writer.send_bytes - self._recv_bytes = self._reader.recv_bytes + self._send = self._writer.send + self._recv = self._reader.recv self._poll = self._reader.poll def put(self, obj, block=True, timeout=None): @@ -89,9 +89,14 @@ def get(self, block=True, timeout=None): if block and timeout is None: - with self._rlock: - res = self._recv_bytes() - self._sem.release() + self._rlock.acquire() + try: + res = self._recv() + self._sem.release() + return res + finally: + self._rlock.release() + else: if block: deadline = time.time() + timeout @@ -104,12 +109,11 @@ raise Empty elif not self._poll(): raise Empty - res = self._recv_bytes() + res = self._recv() self._sem.release() + return res finally: self._rlock.release() - # unserialize the data after having released the lock - return ForkingPickler.loads(res) def qsize(self): # Raises NotImplementedError on Mac OSX because of broken sem_getvalue() @@ -154,7 +158,7 @@ self._buffer.clear() self._thread = threading.Thread( target=Queue._feed, - args=(self._buffer, self._notempty, self._send_bytes, + args=(self._buffer, self._notempty, self._send, self._wlock, self._writer.close, self._ignore_epipe), name='QueueFeederThread' ) @@ -206,7 +210,7 @@ notempty.release() @staticmethod - def _feed(buffer, notempty, send_bytes, writelock, close, ignore_epipe): + def _feed(buffer, notempty, send, writelock, close, ignore_epipe): debug('starting thread to feed data to pipe') from .util import is_exiting @@ -237,14 +241,16 @@ close() return - # serialize the data before acquiring the lock - obj = ForkingPickler.dumps(obj) if wacquire is None: - send_bytes(obj) + send(obj) + # Delete references to object. See issue16284 + del obj else: wacquire() try: - send_bytes(obj) + send(obj) + # Delete references to object. See issue16284 + del obj finally: wrelease() except IndexError: @@ -338,6 +344,7 @@ self._wlock = None else: self._wlock = Lock() + self._make_methods() def empty(self): return not self._poll() @@ -348,19 +355,29 @@ def __setstate__(self, state): (self._reader, self._writer, self._rlock, self._wlock) = state + self._make_methods() - def get(self): - with self._rlock: - res = self._reader.recv_bytes() - # unserialize the data after having released the lock - return ForkingPickler.loads(res) + def _make_methods(self): + recv = self._reader.recv + racquire, rrelease = self._rlock.acquire, self._rlock.release + def get(): + racquire() + try: + return recv() + finally: + rrelease() + self.get = get - def put(self, obj): - # serialize the data before acquiring the lock - obj = ForkingPickler.dumps(obj) if self._wlock is None: # writes to a message oriented win32 pipe are atomic - self._writer.send_bytes(obj) + self.put = self._writer.send else: - with self._wlock: - self._writer.send_bytes(obj) + send = self._writer.send + wacquire, wrelease = self._wlock.acquire, self._wlock.release + def put(obj): + wacquire() + try: + return send(obj) + finally: + wrelease() + self.put = put diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/synchronize.py --- a/Lib/multiprocessing/synchronize.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/synchronize.py Fri Feb 01 23:12:09 2013 +0100 @@ -199,7 +199,7 @@ num_waiters = (self._sleeping_count._semlock._get_value() - self._woken_count._semlock._get_value()) except Exception: - num_waiters = 'unknown' + num_waiters = 'unkown' return '' % (self._lock, num_waiters) def wait(self, timeout=None): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/multiprocessing/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -322,13 +322,10 @@ class ForkAwareThreadLock(object): def __init__(self): - self._reset() - register_after_fork(self, ForkAwareThreadLock._reset) - - def _reset(self): self._lock = threading.Lock() self.acquire = self._lock.acquire self.release = self._lock.release + register_after_fork(self, ForkAwareThreadLock.__init__) class ForkAwareLocal(threading.local): def __init__(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/opcode.py --- a/Lib/opcode.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/opcode.py Fri Feb 01 23:12:09 2013 +0100 @@ -84,6 +84,7 @@ def_op('BINARY_OR', 66) def_op('INPLACE_POWER', 67) def_op('GET_ITER', 68) +def_op('STORE_LOCALS', 69) def_op('PRINT_EXPR', 70) def_op('LOAD_BUILD_CLASS', 71) @@ -178,9 +179,6 @@ def_op('SET_ADD', 146) def_op('MAP_ADD', 147) -def_op('LOAD_CLASSDEREF', 148) -hasfree.append(148) - def_op('EXTENDED_ARG', 144) EXTENDED_ARG = 144 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/operator.py --- a/Lib/operator.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,412 +0,0 @@ -#!/usr/bin/env python3 -""" -Operator Interface - -This module exports a set of functions corresponding to the intrinsic -operators of Python. For example, operator.add(x, y) is equivalent -to the expression x+y. The function names are those used for special -methods; variants without leading and trailing '__' are also provided -for convenience. - -This is the pure Python implementation of the module. -""" - -__all__ = ['abs', 'add', 'and_', 'attrgetter', 'concat', 'contains', 'countOf', - 'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand', - 'iconcat', 'ifloordiv', 'ilshift', 'imod', 'imul', 'index', - 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift', 'is_', - 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le', - 'length_hint', 'lshift', 'lt', 'methodcaller', 'mod', 'mul', 'ne', - 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift', 'setitem', 'sub', - 'truediv', 'truth', 'xor'] - -from builtins import abs as _abs - - -# Comparison Operations *******************************************************# - -def lt(a, b): - "Same as a < b." - return a < b - -def le(a, b): - "Same as a <= b." - return a <= b - -def eq(a, b): - "Same as a == b." - return a == b - -def ne(a, b): - "Same as a != b." - return a != b - -def ge(a, b): - "Same as a >= b." - return a >= b - -def gt(a, b): - "Same as a > b." - return a > b - -# Logical Operations **********************************************************# - -def not_(a): - "Same as not a." - return not a - -def truth(a): - "Return True if a is true, False otherwise." - return True if a else False - -def is_(a, b): - "Same as a is b." - return a is b - -def is_not(a, b): - "Same as a is not b." - return a is not b - -# Mathematical/Bitwise Operations *********************************************# - -def abs(a): - "Same as abs(a)." - return _abs(a) - -def add(a, b): - "Same as a + b." - return a + b - -def and_(a, b): - "Same as a & b." - return a & b - -def floordiv(a, b): - "Same as a // b." - return a // b - -def index(a): - "Same as a.__index__()." - return a.__index__() - -def inv(a): - "Same as ~a." - return ~a -invert = inv - -def lshift(a, b): - "Same as a << b." - return a << b - -def mod(a, b): - "Same as a % b." - return a % b - -def mul(a, b): - "Same as a * b." - return a * b - -def neg(a): - "Same as -a." - return -a - -def or_(a, b): - "Same as a | b." - return a | b - -def pos(a): - "Same as +a." - return +a - -def pow(a, b): - "Same as a ** b." - return a ** b - -def rshift(a, b): - "Same as a >> b." - return a >> b - -def sub(a, b): - "Same as a - b." - return a - b - -def truediv(a, b): - "Same as a / b." - return a / b - -def xor(a, b): - "Same as a ^ b." - return a ^ b - -# Sequence Operations *********************************************************# - -def concat(a, b): - "Same as a + b, for a and b sequences." - if not hasattr(a, '__getitem__'): - msg = "'%s' object can't be concatenated" % type(a).__name__ - raise TypeError(msg) - return a + b - -def contains(a, b): - "Same as b in a (note reversed operands)." - return b in a - -def countOf(a, b): - "Return the number of times b occurs in a." - count = 0 - for i in a: - if i == b: - count += 1 - return count - -def delitem(a, b): - "Same as del a[b]." - del a[b] - -def getitem(a, b): - "Same as a[b]." - return a[b] - -def indexOf(a, b): - "Return the first index of b in a." - for i, j in enumerate(a): - if j == b: - return i - else: - raise ValueError('sequence.index(x): x not in sequence') - -def setitem(a, b, c): - "Same as a[b] = c." - a[b] = c - -def length_hint(obj, default=0): - """ - Return an estimate of the number of items in obj. - This is useful for presizing containers when building from an iterable. - - If the object supports len(), the result will be exact. Otherwise, it may - over- or under-estimate by an arbitrary amount. The result will be an - integer >= 0. - """ - if not isinstance(default, int): - msg = ("'%s' object cannot be interpreted as an integer" % - type(default).__name__) - raise TypeError(msg) - - try: - return len(obj) - except TypeError: - pass - - try: - hint = type(obj).__length_hint__ - except AttributeError: - return default - - try: - val = hint(obj) - except TypeError: - return default - if val is NotImplemented: - return default - if not isinstance(val, int): - msg = ('__length_hint__ must be integer, not %s' % - type(val).__name__) - raise TypeError(msg) - if val < 0: - msg = '__length_hint__() should return >= 0' - raise ValueError(msg) - return val - -# Generalized Lookup Objects **************************************************# - -class attrgetter: - """ - Return a callable object that fetches the given attribute(s) from its operand. - After f = attrgetter('name'), the call f(r) returns r.name. - After g = attrgetter('name', 'date'), the call g(r) returns (r.name, r.date). - After h = attrgetter('name.first', 'name.last'), the call h(r) returns - (r.name.first, r.name.last). - """ - def __init__(self, attr, *attrs): - if not attrs: - if not isinstance(attr, str): - raise TypeError('attribute name must be a string') - names = attr.split('.') - def func(obj): - for name in names: - obj = getattr(obj, name) - return obj - self._call = func - else: - getters = tuple(map(attrgetter, (attr,) + attrs)) - def func(obj): - return tuple(getter(obj) for getter in getters) - self._call = func - - def __call__(self, obj): - return self._call(obj) - -class itemgetter: - """ - Return a callable object that fetches the given item(s) from its operand. - After f = itemgetter(2), the call f(r) returns r[2]. - After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]) - """ - def __init__(self, item, *items): - if not items: - def func(obj): - return obj[item] - self._call = func - else: - items = (item,) + items - def func(obj): - return tuple(obj[i] for i in items) - self._call = func - - def __call__(self, obj): - return self._call(obj) - -class methodcaller: - """ - Return a callable object that calls the given method on its operand. - After f = methodcaller('name'), the call f(r) returns r.name(). - After g = methodcaller('name', 'date', foo=1), the call g(r) returns - r.name('date', foo=1). - """ - - def __init__(*args, **kwargs): - if len(args) < 2: - msg = "methodcaller needs at least one argument, the method name" - raise TypeError(msg) - self = args[0] - self._name = args[1] - self._args = args[2:] - self._kwargs = kwargs - - def __call__(self, obj): - return getattr(obj, self._name)(*self._args, **self._kwargs) - -# In-place Operations *********************************************************# - -def iadd(a, b): - "Same as a += b." - a += b - return a - -def iand(a, b): - "Same as a &= b." - a &= b - return a - -def iconcat(a, b): - "Same as a += b, for a and b sequences." - if not hasattr(a, '__getitem__'): - msg = "'%s' object can't be concatenated" % type(a).__name__ - raise TypeError(msg) - a += b - return a - -def ifloordiv(a, b): - "Same as a //= b." - a //= b - return a - -def ilshift(a, b): - "Same as a <<= b." - a <<= b - return a - -def imod(a, b): - "Same as a %= b." - a %= b - return a - -def imul(a, b): - "Same as a *= b." - a *= b - return a - -def ior(a, b): - "Same as a |= b." - a |= b - return a - -def ipow(a, b): - "Same as a **= b." - a **=b - return a - -def irshift(a, b): - "Same as a >>= b." - a >>= b - return a - -def isub(a, b): - "Same as a -= b." - a -= b - return a - -def itruediv(a, b): - "Same as a /= b." - a /= b - return a - -def ixor(a, b): - "Same as a ^= b." - a ^= b - return a - - -try: - from _operator import * -except ImportError: - pass -else: - from _operator import __doc__ - -# All of these "__func__ = func" assignments have to happen after importing -# from _operator to make sure they're set to the right function -__lt__ = lt -__le__ = le -__eq__ = eq -__ne__ = ne -__ge__ = ge -__gt__ = gt -__not__ = not_ -__abs__ = abs -__add__ = add -__and__ = and_ -__floordiv__ = floordiv -__index__ = index -__inv__ = inv -__invert__ = invert -__lshift__ = lshift -__mod__ = mod -__mul__ = mul -__neg__ = neg -__or__ = or_ -__pos__ = pos -__pow__ = pow -__rshift__ = rshift -__sub__ = sub -__truediv__ = truediv -__xor__ = xor -__concat__ = concat -__contains__ = contains -__delitem__ = delitem -__getitem__ = getitem -__setitem__ = setitem -__iadd__ = iadd -__iand__ = iand -__iconcat__ = iconcat -__ifloordiv__ = ifloordiv -__ilshift__ = ilshift -__imod__ = imod -__imul__ = imul -__ior__ = ior -__ipow__ = ipow -__irshift__ = irshift -__isub__ = isub -__itruediv__ = itruediv -__ixor__ = ixor diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/os.py --- a/Lib/os.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/os.py Fri Feb 01 23:12:09 2013 +0100 @@ -232,9 +232,10 @@ if head and tail and not path.exists(head): try: makedirs(head, mode, exist_ok) - except FileExistsError: + except OSError as e: # be happy if someone already created the path - pass + if e.errno != errno.EEXIST: + raise cdir = curdir if isinstance(tail, bytes): cdir = bytes(curdir, 'ASCII') @@ -644,11 +645,7 @@ self._data = data def __getitem__(self, key): - try: - value = self._data[self.encodekey(key)] - except KeyError: - # raise KeyError with the original key value - raise KeyError(key) + value = self._data[self.encodekey(key)] return self.decodevalue(value) def __setitem__(self, key, value): @@ -658,13 +655,9 @@ self._data[key] = value def __delitem__(self, key): - encodedkey = self.encodekey(key) - self.unsetenv(encodedkey) - try: - del self._data[encodedkey] - except KeyError: - # raise KeyError with the original key value - raise KeyError(key) + key = self.encodekey(key) + self.unsetenv(key) + del self._data[key] def __iter__(self): for key in self._data: @@ -691,16 +684,14 @@ except NameError: _putenv = lambda key, value: None else: - if "putenv" not in __all__: - __all__.append("putenv") + __all__.append("putenv") try: _unsetenv = unsetenv except NameError: _unsetenv = lambda key: _putenv(key, "") else: - if "unsetenv" not in __all__: - __all__.append("unsetenv") + __all__.append("unsetenv") def _createenviron(): if name == 'nt': @@ -885,10 +876,6 @@ otherwise return -SIG, where SIG is the signal that killed it. """ return _spawnvef(mode, file, args, env, execvpe) - - __all__.extend(["spawnv", "spawnve", "spawnvp", "spawnvpe"]) - - if _exists("spawnv"): # These aren't supplied by the basic Windows code # but can be easily implemented in Python @@ -914,7 +901,7 @@ return spawnve(mode, file, args[:-1], env) - __all__.extend(["spawnl", "spawnle"]) + __all__.extend(["spawnv", "spawnve", "spawnl", "spawnle",]) if _exists("spawnvp"): @@ -942,8 +929,7 @@ return spawnvpe(mode, file, args[:-1], env) - __all__.extend(["spawnlp", "spawnlpe"]) - + __all__.extend(["spawnvp", "spawnvpe", "spawnlp", "spawnlpe",]) import copyreg as _copyreg diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pickle.py --- a/Lib/pickle.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pickle.py Fri Feb 01 23:12:09 2013 +0100 @@ -26,10 +26,9 @@ from types import FunctionType, BuiltinFunctionType from copyreg import dispatch_table from copyreg import _extension_registry, _inverted_registry, _extension_cache -from itertools import islice +import marshal import sys -from sys import maxsize -from struct import pack, unpack +import struct import re import io import codecs @@ -59,6 +58,11 @@ # there are too many issues with that. DEFAULT_PROTOCOL = 3 +# Why use struct.pack() for pickling but marshal.loads() for +# unpickling? struct.pack() is 40% faster than marshal.dumps(), but +# marshal.loads() is twice as fast as struct.unpack()! +mloads = marshal.loads + class PickleError(Exception): """A common base class for the other pickling exceptions.""" pass @@ -227,7 +231,7 @@ raise PicklingError("Pickler.__init__() was not called by " "%s.__init__()" % (self.__class__.__name__,)) if self.proto >= 2: - self.write(PROTO + pack("= 2: - self.write(NEWTRUE if obj else NEWFALSE) + self.write(obj and NEWTRUE or NEWFALSE) else: - self.write(TRUE if obj else FALSE) + self.write(obj and TRUE or FALSE) dispatch[bool] = save_bool - def save_long(self, obj): + def save_long(self, obj, pack=struct.pack): if self.bin: # If the int is small enough to fit in a signed 4-byte 2's-comp # format, we can store it more efficiently than the general @@ -457,36 +461,39 @@ # First one- and two-byte unsigned ints: if obj >= 0: if obj <= 0xff: - self.write(BININT1 + pack(">8])) return # Next check for 4-byte signed ints: - if -0x80000000 <= obj <= 0x7fffffff: + high_bits = obj >> 31 # note that Python shift sign-extends + if high_bits == 0 or high_bits == -1: + # All high bits are copies of bit 2**31, so the value + # fits in a 4-byte signed int. self.write(BININT + pack("= 2: encoded = encode_long(obj) n = len(encoded) if n < 256: - self.write(LONG1 + pack("d', obj)) else: self.write(FLOAT + repr(obj).encode("ascii") + b'\n') dispatch[float] = save_float - def save_bytes(self, obj): + def save_bytes(self, obj, pack=struct.pack): if self.proto < 3: - if not obj: # bytes object is empty + if len(obj) == 0: self.save_reduce(bytes, (), obj=obj) else: self.save_reduce(codecs.encode, @@ -494,13 +501,13 @@ return n = len(obj) if n < 256: - self.write(SHORT_BINBYTES + pack("= 2: + if n <= 3 and proto >= 2: for element in obj: save(element) # Subtle. Same as in the big comment below. if id(obj) in memo: get = self.get(memo[id(obj)][0]) - self.write(POP * n + get) + write(POP * n + get) else: - self.write(_tuplesize2code[n]) + write(_tuplesize2code[n]) self.memoize(obj) return # proto 0 or proto 1 and tuple isn't empty, or proto > 1 and tuple # has more than 3 elements. - write = self.write write(MARK) for element in obj: save(element) @@ -551,23 +561,25 @@ # could have been done in the "for element" loop instead, but # recursive tuples are a rare thing. get = self.get(memo[id(obj)][0]) - if self.bin: + if proto: write(POP_MARK + get) else: # proto 0 -- POP_MARK not available write(POP * (n+1) + get) return # No recursion. - write(TUPLE) + self.write(TUPLE) self.memoize(obj) dispatch[tuple] = save_tuple def save_list(self, obj): + write = self.write + if self.bin: - self.write(EMPTY_LIST) + write(EMPTY_LIST) else: # proto 0 -- can't use EMPTY_LIST - self.write(MARK + LIST) + write(MARK + LIST) self.memoize(obj) self._batch_appends(obj) @@ -587,9 +599,17 @@ write(APPEND) return - it = iter(items) - while True: - tmp = list(islice(it, self._BATCHSIZE)) + items = iter(items) + r = range(self._BATCHSIZE) + while items is not None: + tmp = [] + for i in r: + try: + x = next(items) + tmp.append(x) + except StopIteration: + items = None + break n = len(tmp) if n > 1: write(MARK) @@ -600,14 +620,14 @@ save(tmp[0]) write(APPEND) # else tmp is empty, and we're done - if n < self._BATCHSIZE: - return def save_dict(self, obj): + write = self.write + if self.bin: - self.write(EMPTY_DICT) + write(EMPTY_DICT) else: # proto 0 -- can't use EMPTY_DICT - self.write(MARK + DICT) + write(MARK + DICT) self.memoize(obj) self._batch_setitems(obj.items()) @@ -628,9 +648,16 @@ write(SETITEM) return - it = iter(items) - while True: - tmp = list(islice(it, self._BATCHSIZE)) + items = iter(items) + r = range(self._BATCHSIZE) + while items is not None: + tmp = [] + for i in r: + try: + tmp.append(next(items)) + except StopIteration: + items = None + break n = len(tmp) if n > 1: write(MARK) @@ -644,10 +671,8 @@ save(v) write(SETITEM) # else tmp is empty, and we're done - if n < self._BATCHSIZE: - return - def save_global(self, obj, name=None): + def save_global(self, obj, name=None, pack=struct.pack): write = self.write memo = self.memo @@ -677,9 +702,9 @@ if code: assert code > 0 if code <= 0xff: - write(EXT1 + pack(">8])) else: write(EXT4 + pack("d', self.read(8))[0]) dispatch[BINFLOAT[0]] = load_binfloat def load_string(self): - data = self.readline()[:-1] - # Strip outermost quotes - if len(data) >= 2 and data[0] == data[-1] and data[0] in b'"\'': - data = data[1:-1] + orig = self.readline() + rep = orig[:-1] + for q in (b'"', b"'"): # double or single quote + if rep.startswith(q): + if not rep.endswith(q): + raise ValueError("insecure string pickle") + rep = rep[len(q):-len(q)] + break else: - raise UnpicklingError("the STRING opcode argument must be quoted") - self.append(codecs.escape_decode(data)[0] + raise ValueError("insecure string pickle: %r" % orig) + self.append(codecs.escape_decode(rep)[0] .decode(self.encoding, self.errors)) dispatch[STRING[0]] = load_string def load_binstring(self): # Deprecated BINSTRING uses signed 32-bit length - len, = unpack(' maxsize: - raise UnpicklingError("BINBYTES exceeds system's maximum size " - "of %d bytes" % maxsize) + raise UnpicklingError("BINBYTES exceeds system's maximum size of %d bytes" % maxsize); self.append(self.read(len)) dispatch[BINBYTES[0]] = load_binbytes @@ -932,24 +982,23 @@ self.append(str(self.readline()[:-1], 'raw-unicode-escape')) dispatch[UNICODE[0]] = load_unicode - def load_binunicode(self): + def load_binunicode(self, unpack=struct.unpack, maxsize=sys.maxsize): len, = unpack(' maxsize: - raise UnpicklingError("BINUNICODE exceeds system's maximum size " - "of %d bytes" % maxsize) + raise UnpicklingError("BINUNICODE exceeds system's maximum size of %d bytes" % maxsize); self.append(str(self.read(len), 'utf-8', 'surrogatepass')) dispatch[BINUNICODE[0]] = load_binunicode def load_short_binstring(self): - len = self.read(1)[0] - data = self.read(len) + len = ord(self.read(1)) + data = bytes(self.read(len)) value = str(data, self.encoding, self.errors) self.append(value) dispatch[SHORT_BINSTRING[0]] = load_short_binstring def load_short_binbytes(self): - len = self.read(1)[0] - self.append(self.read(len)) + len = ord(self.read(1)) + self.append(bytes(self.read(len))) dispatch[SHORT_BINBYTES[0]] = load_short_binbytes def load_tuple(self): @@ -988,9 +1037,12 @@ def load_dict(self): k = self.marker() + d = {} items = self.stack[k+1:] - d = {items[i]: items[i+1] - for i in range(0, len(items), 2)} + for i in range(0, len(items), 2): + key = items[i] + value = items[i+1] + d[key] = value self.stack[k:] = [d] dispatch[DICT[0]] = load_dict @@ -1042,17 +1094,17 @@ dispatch[GLOBAL[0]] = load_global def load_ext1(self): - code = self.read(1)[0] + code = ord(self.read(1)) self.get_extension(code) dispatch[EXT1[0]] = load_ext1 def load_ext2(self): - code, = unpack(' maxsize: raise ValueError("negative LONG_BINPUT argument") @@ -1156,14 +1208,8 @@ def load_appends(self): stack = self.stack mark = self.marker() - list_obj = stack[mark - 1] - items = stack[mark + 1:] - if isinstance(list_obj, list): - list_obj.extend(items) - else: - append = list_obj.append - for item in items: - append(item) + list = stack[mark - 1] + list.extend(stack[mark + 1:]) del stack[mark:] dispatch[APPENDS[0]] = load_appends @@ -1190,7 +1236,7 @@ state = stack.pop() inst = stack[-1] setstate = getattr(inst, "__setstate__", None) - if setstate is not None: + if setstate: setstate(state) return slotstate = None diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pickletools.py --- a/Lib/pickletools.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pickletools.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,7 +13,6 @@ import codecs import pickle import re -import sys __all__ = ['dis', 'genops', 'optimize'] @@ -34,118 +33,119 @@ # by a later GET. -# "A pickle" is a program for a virtual pickle machine (PM, but more accurately -# called an unpickling machine). It's a sequence of opcodes, interpreted by the -# PM, building an arbitrarily complex Python object. -# -# For the most part, the PM is very simple: there are no looping, testing, or -# conditional instructions, no arithmetic and no function calls. Opcodes are -# executed once each, from first to last, until a STOP opcode is reached. -# -# The PM has two data areas, "the stack" and "the memo". -# -# Many opcodes push Python objects onto the stack; e.g., INT pushes a Python -# integer object on the stack, whose value is gotten from a decimal string -# literal immediately following the INT opcode in the pickle bytestream. Other -# opcodes take Python objects off the stack. The result of unpickling is -# whatever object is left on the stack when the final STOP opcode is executed. -# -# The memo is simply an array of objects, or it can be implemented as a dict -# mapping little integers to objects. The memo serves as the PM's "long term -# memory", and the little integers indexing the memo are akin to variable -# names. Some opcodes pop a stack object into the memo at a given index, -# and others push a memo object at a given index onto the stack again. -# -# At heart, that's all the PM has. Subtleties arise for these reasons: -# -# + Object identity. Objects can be arbitrarily complex, and subobjects -# may be shared (for example, the list [a, a] refers to the same object a -# twice). It can be vital that unpickling recreate an isomorphic object -# graph, faithfully reproducing sharing. -# -# + Recursive objects. For example, after "L = []; L.append(L)", L is a -# list, and L[0] is the same list. This is related to the object identity -# point, and some sequences of pickle opcodes are subtle in order to -# get the right result in all cases. -# -# + Things pickle doesn't know everything about. Examples of things pickle -# does know everything about are Python's builtin scalar and container -# types, like ints and tuples. They generally have opcodes dedicated to -# them. For things like module references and instances of user-defined -# classes, pickle's knowledge is limited. Historically, many enhancements -# have been made to the pickle protocol in order to do a better (faster, -# and/or more compact) job on those. -# -# + Backward compatibility and micro-optimization. As explained below, -# pickle opcodes never go away, not even when better ways to do a thing -# get invented. The repertoire of the PM just keeps growing over time. -# For example, protocol 0 had two opcodes for building Python integers (INT -# and LONG), protocol 1 added three more for more-efficient pickling of short -# integers, and protocol 2 added two more for more-efficient pickling of -# long integers (before protocol 2, the only ways to pickle a Python long -# took time quadratic in the number of digits, for both pickling and -# unpickling). "Opcode bloat" isn't so much a subtlety as a source of -# wearying complication. -# -# -# Pickle protocols: -# -# For compatibility, the meaning of a pickle opcode never changes. Instead new -# pickle opcodes get added, and each version's unpickler can handle all the -# pickle opcodes in all protocol versions to date. So old pickles continue to -# be readable forever. The pickler can generally be told to restrict itself to -# the subset of opcodes available under previous protocol versions too, so that -# users can create pickles under the current version readable by older -# versions. However, a pickle does not contain its version number embedded -# within it. If an older unpickler tries to read a pickle using a later -# protocol, the result is most likely an exception due to seeing an unknown (in -# the older unpickler) opcode. -# -# The original pickle used what's now called "protocol 0", and what was called -# "text mode" before Python 2.3. The entire pickle bytestream is made up of -# printable 7-bit ASCII characters, plus the newline character, in protocol 0. -# That's why it was called text mode. Protocol 0 is small and elegant, but -# sometimes painfully inefficient. -# -# The second major set of additions is now called "protocol 1", and was called -# "binary mode" before Python 2.3. This added many opcodes with arguments -# consisting of arbitrary bytes, including NUL bytes and unprintable "high bit" -# bytes. Binary mode pickles can be substantially smaller than equivalent -# text mode pickles, and sometimes faster too; e.g., BININT represents a 4-byte -# int as 4 bytes following the opcode, which is cheaper to unpickle than the -# (perhaps) 11-character decimal string attached to INT. Protocol 1 also added -# a number of opcodes that operate on many stack elements at once (like APPENDS -# and SETITEMS), and "shortcut" opcodes (like EMPTY_DICT and EMPTY_TUPLE). -# -# The third major set of additions came in Python 2.3, and is called "protocol -# 2". This added: -# -# - A better way to pickle instances of new-style classes (NEWOBJ). -# -# - A way for a pickle to identify its protocol (PROTO). -# -# - Time- and space- efficient pickling of long ints (LONG{1,4}). -# -# - Shortcuts for small tuples (TUPLE{1,2,3}}. -# -# - Dedicated opcodes for bools (NEWTRUE, NEWFALSE). -# -# - The "extension registry", a vector of popular objects that can be pushed -# efficiently by index (EXT{1,2,4}). This is akin to the memo and GET, but -# the registry contents are predefined (there's nothing akin to the memo's -# PUT). -# -# Another independent change with Python 2.3 is the abandonment of any -# pretense that it might be safe to load pickles received from untrusted -# parties -- no sufficient security analysis has been done to guarantee -# this and there isn't a use case that warrants the expense of such an -# analysis. -# -# To this end, all tests for __safe_for_unpickling__ or for -# copyreg.safe_constructors are removed from the unpickling code. -# References to these variables in the descriptions below are to be seen -# as describing unpickling in Python 2.2 and before. +""" +"A pickle" is a program for a virtual pickle machine (PM, but more accurately +called an unpickling machine). It's a sequence of opcodes, interpreted by the +PM, building an arbitrarily complex Python object. +For the most part, the PM is very simple: there are no looping, testing, or +conditional instructions, no arithmetic and no function calls. Opcodes are +executed once each, from first to last, until a STOP opcode is reached. + +The PM has two data areas, "the stack" and "the memo". + +Many opcodes push Python objects onto the stack; e.g., INT pushes a Python +integer object on the stack, whose value is gotten from a decimal string +literal immediately following the INT opcode in the pickle bytestream. Other +opcodes take Python objects off the stack. The result of unpickling is +whatever object is left on the stack when the final STOP opcode is executed. + +The memo is simply an array of objects, or it can be implemented as a dict +mapping little integers to objects. The memo serves as the PM's "long term +memory", and the little integers indexing the memo are akin to variable +names. Some opcodes pop a stack object into the memo at a given index, +and others push a memo object at a given index onto the stack again. + +At heart, that's all the PM has. Subtleties arise for these reasons: + ++ Object identity. Objects can be arbitrarily complex, and subobjects + may be shared (for example, the list [a, a] refers to the same object a + twice). It can be vital that unpickling recreate an isomorphic object + graph, faithfully reproducing sharing. + ++ Recursive objects. For example, after "L = []; L.append(L)", L is a + list, and L[0] is the same list. This is related to the object identity + point, and some sequences of pickle opcodes are subtle in order to + get the right result in all cases. + ++ Things pickle doesn't know everything about. Examples of things pickle + does know everything about are Python's builtin scalar and container + types, like ints and tuples. They generally have opcodes dedicated to + them. For things like module references and instances of user-defined + classes, pickle's knowledge is limited. Historically, many enhancements + have been made to the pickle protocol in order to do a better (faster, + and/or more compact) job on those. + ++ Backward compatibility and micro-optimization. As explained below, + pickle opcodes never go away, not even when better ways to do a thing + get invented. The repertoire of the PM just keeps growing over time. + For example, protocol 0 had two opcodes for building Python integers (INT + and LONG), protocol 1 added three more for more-efficient pickling of short + integers, and protocol 2 added two more for more-efficient pickling of + long integers (before protocol 2, the only ways to pickle a Python long + took time quadratic in the number of digits, for both pickling and + unpickling). "Opcode bloat" isn't so much a subtlety as a source of + wearying complication. + + +Pickle protocols: + +For compatibility, the meaning of a pickle opcode never changes. Instead new +pickle opcodes get added, and each version's unpickler can handle all the +pickle opcodes in all protocol versions to date. So old pickles continue to +be readable forever. The pickler can generally be told to restrict itself to +the subset of opcodes available under previous protocol versions too, so that +users can create pickles under the current version readable by older +versions. However, a pickle does not contain its version number embedded +within it. If an older unpickler tries to read a pickle using a later +protocol, the result is most likely an exception due to seeing an unknown (in +the older unpickler) opcode. + +The original pickle used what's now called "protocol 0", and what was called +"text mode" before Python 2.3. The entire pickle bytestream is made up of +printable 7-bit ASCII characters, plus the newline character, in protocol 0. +That's why it was called text mode. Protocol 0 is small and elegant, but +sometimes painfully inefficient. + +The second major set of additions is now called "protocol 1", and was called +"binary mode" before Python 2.3. This added many opcodes with arguments +consisting of arbitrary bytes, including NUL bytes and unprintable "high bit" +bytes. Binary mode pickles can be substantially smaller than equivalent +text mode pickles, and sometimes faster too; e.g., BININT represents a 4-byte +int as 4 bytes following the opcode, which is cheaper to unpickle than the +(perhaps) 11-character decimal string attached to INT. Protocol 1 also added +a number of opcodes that operate on many stack elements at once (like APPENDS +and SETITEMS), and "shortcut" opcodes (like EMPTY_DICT and EMPTY_TUPLE). + +The third major set of additions came in Python 2.3, and is called "protocol +2". This added: + +- A better way to pickle instances of new-style classes (NEWOBJ). + +- A way for a pickle to identify its protocol (PROTO). + +- Time- and space- efficient pickling of long ints (LONG{1,4}). + +- Shortcuts for small tuples (TUPLE{1,2,3}}. + +- Dedicated opcodes for bools (NEWTRUE, NEWFALSE). + +- The "extension registry", a vector of popular objects that can be pushed + efficiently by index (EXT{1,2,4}). This is akin to the memo and GET, but + the registry contents are predefined (there's nothing akin to the memo's + PUT). + +Another independent change with Python 2.3 is the abandonment of any +pretense that it might be safe to load pickles received from untrusted +parties -- no sufficient security analysis has been done to guarantee +this and there isn't a use case that warrants the expense of such an +analysis. + +To this end, all tests for __safe_for_unpickling__ or for +copyreg.safe_constructors are removed from the unpickling code. +References to these variables in the descriptions below are to be seen +as describing unpickling in Python 2.2 and before. +""" # Meta-rule: Descriptions are stored in instances of descriptor objects, # with plain constructors. No meta-language is defined from which @@ -165,9 +165,8 @@ # Represents the number of bytes consumed by a two-argument opcode where # the first argument gives the number of bytes in the second argument. -TAKEN_FROM_ARGUMENT1 = -2 # num bytes is 1-byte unsigned int -TAKEN_FROM_ARGUMENT4 = -3 # num bytes is 4-byte signed little-endian int -TAKEN_FROM_ARGUMENT4U = -4 # num bytes is 4-byte unsigned little-endian int +TAKEN_FROM_ARGUMENT1 = -2 # num bytes is 1-byte unsigned int +TAKEN_FROM_ARGUMENT4 = -3 # num bytes is 4-byte signed little-endian int class ArgumentDescriptor(object): __slots__ = ( @@ -195,8 +194,7 @@ assert isinstance(n, int) and (n >= 0 or n in (UP_TO_NEWLINE, TAKEN_FROM_ARGUMENT1, - TAKEN_FROM_ARGUMENT4, - TAKEN_FROM_ARGUMENT4U)) + TAKEN_FROM_ARGUMENT4)) self.n = n self.reader = reader @@ -267,27 +265,6 @@ doc="Four-byte signed integer, little-endian, 2's complement.") -def read_uint4(f): - r""" - >>> import io - >>> read_uint4(io.BytesIO(b'\xff\x00\x00\x00')) - 255 - >>> read_uint4(io.BytesIO(b'\x00\x00\x00\x80')) == 2**31 - True - """ - - data = f.read(4) - if len(data) == 4: - return _unpack(">> import io @@ -444,67 +421,6 @@ """) -def read_bytes1(f): - r""" - >>> import io - >>> read_bytes1(io.BytesIO(b"\x00")) - b'' - >>> read_bytes1(io.BytesIO(b"\x03abcdef")) - b'abc' - """ - - n = read_uint1(f) - assert n >= 0 - data = f.read(n) - if len(data) == n: - return data - raise ValueError("expected %d bytes in a bytes1, but only %d remain" % - (n, len(data))) - -bytes1 = ArgumentDescriptor( - name="bytes1", - n=TAKEN_FROM_ARGUMENT1, - reader=read_bytes1, - doc="""A counted bytes string. - - The first argument is a 1-byte unsigned int giving the number - of bytes, and the second argument is that many bytes. - """) - - -def read_bytes4(f): - r""" - >>> import io - >>> read_bytes4(io.BytesIO(b"\x00\x00\x00\x00abc")) - b'' - >>> read_bytes4(io.BytesIO(b"\x03\x00\x00\x00abcdef")) - b'abc' - >>> read_bytes4(io.BytesIO(b"\x00\x00\x00\x03abcdef")) - Traceback (most recent call last): - ... - ValueError: expected 50331648 bytes in a bytes4, but only 6 remain - """ - - n = read_uint4(f) - if n > sys.maxsize: - raise ValueError("bytes4 byte count > sys.maxsize: %d" % n) - data = f.read(n) - if len(data) == n: - return data - raise ValueError("expected %d bytes in a bytes4, but only %d remain" % - (n, len(data))) - -bytes4 = ArgumentDescriptor( - name="bytes4", - n=TAKEN_FROM_ARGUMENT4U, - reader=read_bytes4, - doc="""A counted bytes string. - - The first argument is a 4-byte little-endian unsigned int giving - the number of bytes, and the second argument is that many bytes. - """) - - def read_unicodestringnl(f): r""" >>> import io @@ -548,9 +464,9 @@ ValueError: expected 7 bytes in a unicodestring4, but only 6 remain """ - n = read_uint4(f) - if n > sys.maxsize: - raise ValueError("unicodestring4 byte count > sys.maxsize: %d" % n) + n = read_int4(f) + if n < 0: + raise ValueError("unicodestring4 byte count < 0: %d" % n) data = f.read(n) if len(data) == n: return str(data, 'utf-8', 'surrogatepass') @@ -559,7 +475,7 @@ unicodestring4 = ArgumentDescriptor( name="unicodestring4", - n=TAKEN_FROM_ARGUMENT4U, + n=TAKEN_FROM_ARGUMENT4, reader=read_unicodestring4, doc="""A counted Unicode string. @@ -956,7 +872,7 @@ assert isinstance(x, StackObject) self.stack_after = stack_after - assert isinstance(proto, int) and 0 <= proto <= pickle.HIGHEST_PROTOCOL + assert isinstance(proto, int) and 0 <= proto <= 3 self.proto = proto assert isinstance(doc, str) @@ -1122,28 +1038,28 @@ I(name='BINBYTES', code='B', - arg=bytes4, + arg=string4, stack_before=[], stack_after=[pybytes], proto=3, doc="""Push a Python bytes object. - There are two arguments: the first is a 4-byte little-endian unsigned int - giving the number of bytes, and the second is that many bytes, which are - taken literally as the bytes content. + There are two arguments: the first is a 4-byte little-endian signed int + giving the number of bytes in the string, and the second is that many + bytes, which are taken literally as the bytes content. """), I(name='SHORT_BINBYTES', code='C', - arg=bytes1, + arg=string1, stack_before=[], stack_after=[pybytes], proto=3, - doc="""Push a Python bytes object. + doc="""Push a Python string object. There are two arguments: the first is a 1-byte unsigned int giving - the number of bytes, and the second is that many bytes, which are taken - literally as the string content. + the number of bytes in the string, and the second is that many bytes, + which are taken literally as the string content. """), # Ways to spell None. @@ -1202,7 +1118,7 @@ proto=1, doc="""Push a Python Unicode string object. - There are two arguments: the first is a 4-byte little-endian unsigned int + There are two arguments: the first is a 4-byte little-endian signed int giving the number of bytes in the string. The second is that many bytes, and is the UTF-8 encoding of the Unicode string. """), @@ -1506,13 +1422,13 @@ I(name='LONG_BINGET', code='j', - arg=uint4, + arg=int4, stack_before=[], stack_after=[anyobject], proto=1, doc="""Read an object from the memo and push it on the stack. - The index of the memo object to push is given by the 4-byte unsigned + The index of the memo object to push is given by the 4-byte signed little-endian integer following. """), @@ -1543,14 +1459,14 @@ I(name='LONG_BINPUT', code='r', - arg=uint4, + arg=int4, stack_before=[], stack_after=[], proto=1, doc="""Store the stack top into the memo. The stack is not popped. The index of the memo location to write into is given by the 4-byte - unsigned little-endian integer following. + signed little-endian integer following. """), # Access the extension registry (predefined objects). Akin to the GET diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pkgutil.py --- a/Lib/pkgutil.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pkgutil.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,13 +1,12 @@ """Utilities to support packages.""" -from functools import singledispatch as simplegeneric +import os +import sys import importlib -import importlib.util -import os +import imp import os.path -import sys +from warnings import warn from types import ModuleType -import warnings __all__ = [ 'get_importer', 'iter_importers', 'get_loader', 'find_loader', @@ -21,13 +20,53 @@ import marshal magic = stream.read(4) - if magic != importlib.util.MAGIC_NUMBER: + if magic != imp.get_magic(): return None stream.read(8) # Skip timestamp and size return marshal.load(stream) +def simplegeneric(func): + """Make a trivial single-dispatch generic function""" + registry = {} + def wrapper(*args, **kw): + ob = args[0] + try: + cls = ob.__class__ + except AttributeError: + cls = type(ob) + try: + mro = cls.__mro__ + except AttributeError: + try: + class cls(cls, object): + pass + mro = cls.__mro__[1:] + except TypeError: + mro = object, # must be an ExtensionClass or some such :( + for t in mro: + if t in registry: + return registry[t](*args, **kw) + else: + return func(*args, **kw) + try: + wrapper.__name__ = func.__name__ + except (TypeError, AttributeError): + pass # Python 2.3 doesn't allow functions to be renamed + + def register(typ, func=None): + if func is None: + return lambda f: register(typ, f) + registry[typ] = func + return func + + wrapper.__dict__ = func.__dict__ + wrapper.__doc__ = func.__doc__ + wrapper.register = register + return wrapper + + def walk_packages(path=None, prefix='', onerror=None): """Yields (module_loader, name, ispkg) for all modules recursively on path, or, if path is None, all accessible modules. @@ -109,12 +148,13 @@ yield i, name, ispkg -@simplegeneric +#@simplegeneric def iter_importer_modules(importer, prefix=''): if not hasattr(importer, 'iter_modules'): return [] return importer.iter_modules(prefix) +iter_importer_modules = simplegeneric(iter_importer_modules) # Implement a file walker for the normal importlib path hook def _iter_file_finder_modules(importer, prefix=''): @@ -160,13 +200,6 @@ iter_importer_modules.register( importlib.machinery.FileFinder, _iter_file_finder_modules) - -def _import_imp(): - global imp - with warnings.catch_warnings(): - warnings.simplefilter('ignore', PendingDeprecationWarning) - imp = importlib.import_module('imp') - class ImpImporter: """PEP 302 Importer that wraps Python's "classic" import algorithm @@ -179,10 +212,8 @@ """ def __init__(self, path=None): - global imp - warnings.warn("This emulation is deprecated, use 'importlib' instead", + warn("This emulation is deprecated, use 'importlib' instead", DeprecationWarning) - _import_imp() self.path = path def find_module(self, fullname, path=None): @@ -247,9 +278,8 @@ code = source = None def __init__(self, fullname, file, filename, etc): - warnings.warn("This emulation is deprecated, use 'importlib' instead", - DeprecationWarning) - _import_imp() + warn("This emulation is deprecated, use 'importlib' instead", + DeprecationWarning) self.file = file self.filename = filename self.fullname = fullname @@ -319,8 +349,9 @@ self.file.close() elif mod_type==imp.PY_COMPILED: if os.path.exists(self.filename[:-1]): - with open(self.filename[:-1], 'r') as f: - self.source = f.read() + f = open(self.filename[:-1], 'r') + self.source = f.read() + f.close() elif mod_type==imp.PKG_DIRECTORY: self.source = self._get_delegate().get_source() return self.source @@ -419,8 +450,8 @@ if '.' in fullname: # Get the containing package's __path__ pkg_name = fullname.rpartition(".")[0] - pkg = importlib.import_module(pkg_name) - path = getattr(pkg, '__path__', None) + pkg = importlib.import_module(pkg) + path = getattr(sys.modules[pkg], '__path__', None) if path is None: return else: @@ -560,12 +591,12 @@ sys.stderr.write("Can't open %s: %s\n" % (pkgfile, msg)) else: - with f: - for line in f: - line = line.rstrip('\n') - if not line or line.startswith('#'): - continue - path.append(line) # Don't check for existence! + for line in f: + line = line.rstrip('\n') + if not line or line.startswith('#'): + continue + path.append(line) # Don't check for existence! + f.close() return path diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/plat-generic/regen --- a/Lib/plat-generic/regen Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/plat-generic/regen Fri Feb 01 23:12:09 2013 +0100 @@ -1,3 +1,3 @@ #! /bin/sh set -v -eval $PYTHON_FOR_BUILD ../../Tools/scripts/h2py.py -i "'(u_long)'" /usr/include/netinet/in.h +python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/platform.py --- a/Lib/platform.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/platform.py Fri Feb 01 23:12:09 2013 +0100 @@ -634,6 +634,62 @@ RegCloseKey(keyCurVer) return release,version,csd,ptype +def _mac_ver_lookup(selectors,default=None): + + from _gestalt import gestalt + l = [] + append = l.append + for selector in selectors: + try: + append(gestalt(selector)) + except (RuntimeError, OSError): + append(default) + return l + +def _bcd2str(bcd): + + return hex(bcd)[2:] + +def _mac_ver_gestalt(): + """ + Thanks to Mark R. Levinson for mailing documentation links and + code examples for this function. Documentation for the + gestalt() API is available online at: + + http://www.rgaros.nl/gestalt/ + """ + # Check whether the version info module is available + try: + import _gestalt + except ImportError: + return None + # Get the infos + sysv, sysa = _mac_ver_lookup(('sysv','sysa')) + # Decode the infos + if sysv: + major = (sysv & 0xFF00) >> 8 + minor = (sysv & 0x00F0) >> 4 + patch = (sysv & 0x000F) + + if (major, minor) >= (10, 4): + # the 'sysv' gestald cannot return patchlevels + # higher than 9. Apple introduced 3 new + # gestalt codes in 10.4 to deal with this + # issue (needed because patch levels can + # run higher than 9, such as 10.4.11) + major,minor,patch = _mac_ver_lookup(('sys1','sys2','sys3')) + release = '%i.%i.%i' %(major, minor, patch) + else: + release = '%s.%i.%i' % (_bcd2str(major),minor,patch) + + if sysa: + machine = {0x1: '68k', + 0x2: 'PowerPC', + 0xa: 'i386'}.get(sysa,'') + + versioninfo=('', '', '') + return release,versioninfo,machine + def _mac_ver_xml(): fn = '/System/Library/CoreServices/SystemVersion.plist' if not os.path.exists(fn): @@ -649,7 +705,7 @@ versioninfo=('', '', '') machine = os.uname().machine if machine in ('ppc', 'Power Macintosh'): - # Cannonical name + # for compatibility with the gestalt based code machine = 'PowerPC' return release,versioninfo,machine @@ -671,6 +727,12 @@ if info is not None: return info + # If that doesn't work for some reason fall back to reading the + # information using gestalt calls. + info = _mac_ver_gestalt() + if info is not None: + return info + # If that also doesn't work return the default values return release,versioninfo,machine diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/plistlib.py --- a/Lib/plistlib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/plistlib.py Fri Feb 01 23:12:09 2013 +0100 @@ -228,8 +228,8 @@ def writeData(self, data): self.beginElement("data") self.indentLevel -= 1 - maxlinelength = max(16, 76 - len(self.indent.replace(b"\t", b" " * 8) * - self.indentLevel)) + maxlinelength = 76 - len(self.indent.replace(b"\t", b" " * 8) * + self.indentLevel) for line in data.asBase64(maxlinelength).split(b"\n"): if line: self.writeln(line) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/posixpath.py --- a/Lib/posixpath.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/posixpath.py Fri Feb 01 23:12:09 2013 +0100 @@ -182,25 +182,18 @@ def ismount(path): """Test whether a path is a mount point""" + if islink(path): + # A symlink can never be a mount point + return False try: s1 = os.lstat(path) - except OSError: - # It doesn't exist -- so not a mount point. :-) - return False - else: - # A symlink can never be a mount point - if stat.S_ISLNK(s1.st_mode): - return False - - if isinstance(path, bytes): - parent = join(path, b'..') - else: - parent = join(path, '..') - try: + if isinstance(path, bytes): + parent = join(path, b'..') + else: + parent = join(path, '..') s2 = os.lstat(parent) except OSError: - return False - + return False # It doesn't exist -- so not a mount point :-) dev1 = s1.st_dev dev2 = s2.st_dev if dev1 != dev2: @@ -370,61 +363,51 @@ def realpath(filename): """Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path.""" - path, ok = _joinrealpath(filename[:0], filename, {}) - return abspath(path) - -# Join two paths, normalizing ang eliminating any symbolic links -# encountered in the second path. -def _joinrealpath(path, rest, seen): - if isinstance(path, bytes): + if isinstance(filename, bytes): sep = b'/' - curdir = b'.' - pardir = b'..' + empty = b'' else: sep = '/' - curdir = '.' - pardir = '..' + empty = '' + if isabs(filename): + bits = [sep] + filename.split(sep)[1:] + else: + bits = [empty] + filename.split(sep) - if isabs(rest): - rest = rest[1:] - path = sep + for i in range(2, len(bits)+1): + component = join(*bits[0:i]) + # Resolve symbolic links. + if islink(component): + resolved = _resolve_link(component) + if resolved is None: + # Infinite loop -- return original component + rest of the path + return abspath(join(*([component] + bits[i:]))) + else: + newpath = join(*([resolved] + bits[i:])) + return realpath(newpath) - while rest: - name, _, rest = rest.partition(sep) - if not name or name == curdir: - # current dir - continue - if name == pardir: - # parent dir - if path: - path, name = split(path) - if name == pardir: - path = join(path, pardir, pardir) - else: - path = pardir - continue - newpath = join(path, name) - if not islink(newpath): - path = newpath - continue - # Resolve the symbolic link - if newpath in seen: - # Already seen this path - path = seen[newpath] - if path is not None: - # use cached value - continue - # The symlink is not resolved, so we must have a symlink loop. - # Return already resolved part + rest of the path unchanged. - return join(newpath, rest), False - seen[newpath] = None # not resolved symlink - path, ok = _joinrealpath(path, os.readlink(newpath), seen) - if not ok: - return join(path, rest), False - seen[newpath] = path # resolved symlink + return abspath(filename) - return path, True +def _resolve_link(path): + """Internal helper function. Takes a path and follows symlinks + until we either arrive at something that isn't a symlink, or + encounter a path we've seen before (meaning that there's a loop). + """ + paths_seen = set() + while islink(path): + if path in paths_seen: + # Already seen this path, so we must have a symlink loop + return None + paths_seen.add(path) + # Resolve where the link points to + resolved = os.readlink(path) + if not isabs(resolved): + dir = dirname(path) + path = normpath(join(dir, resolved)) + else: + path = normpath(resolved) + return path supports_unicode_filenames = (sys.platform == 'darwin') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pprint.py --- a/Lib/pprint.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pprint.py Fri Feb 01 23:12:09 2013 +0100 @@ -34,7 +34,6 @@ """ -import re import sys as _sys from collections import OrderedDict as _OrderedDict from io import StringIO as _StringIO @@ -159,10 +158,13 @@ return rep = self._repr(object, context, level - 1) typ = _type(object) - max_width = self._width - 1 - indent - allowance - sepLines = _len(rep) > max_width + sepLines = _len(rep) > (self._width - 1 - indent - allowance) write = stream.write + if self._depth and level > self._depth: + write(rep) + return + if sepLines: r = getattr(typ, "__repr__", None) if issubclass(typ, dict): @@ -240,37 +242,6 @@ write(endchar) return - if issubclass(typ, str) and len(object) > 0 and r is str.__repr__: - def _str_parts(s): - """ - Return a list of string literals comprising the repr() - of the given string using literal concatenation. - """ - lines = s.splitlines(True) - for i, line in enumerate(lines): - rep = repr(line) - if _len(rep) <= max_width: - yield rep - else: - # A list of alternating (non-space, space) strings - parts = re.split(r'(\s+)', line) + [''] - current = '' - for i in range(0, len(parts), 2): - part = parts[i] + parts[i+1] - candidate = current + part - if len(repr(candidate)) > max_width: - if current: - yield repr(current) - current = part - else: - current = candidate - if current: - yield repr(current) - for i, rep in enumerate(_str_parts(object)): - if i > 0: - write('\n' + ' '*indent) - write(rep) - return write(rep) def _repr(self, object, context, level): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/profile.py --- a/Lib/profile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/profile.py Fri Feb 01 23:12:09 2013 +0100 @@ -40,40 +40,6 @@ # return i_count #itimes = integer_timer # replace with C coded timer returning integers -class _Utils: - """Support class for utility functions which are shared by - profile.py and cProfile.py modules. - Not supposed to be used directly. - """ - - def __init__(self, profiler): - self.profiler = profiler - - def run(self, statement, filename, sort): - prof = self.profiler() - try: - prof.run(statement) - except SystemExit: - pass - finally: - self._show(prof, filename, sort) - - def runctx(self, statement, globals, locals, filename, sort): - prof = self.profiler() - try: - prof.runctx(statement, globals, locals) - except SystemExit: - pass - finally: - self._show(prof, filename, sort) - - def _show(self, prof, filename, sort): - if filename is not None: - prof.dump_stats(filename) - else: - prof.print_stats(sort) - - #************************************************************************** # The following are the static member functions for the profiler class # Note that an instance of Profile() is *not* needed to call them. @@ -90,7 +56,15 @@ standard name string (file/line/function-name) that is presented in each line. """ - return _Utils(Profile).run(statement, filename, sort) + prof = Profile() + try: + prof = prof.run(statement) + except SystemExit: + pass + if filename is not None: + prof.dump_stats(filename) + else: + return prof.print_stats(sort) def runctx(statement, globals, locals, filename=None, sort=-1): """Run statement under profiler, supplying your own globals and locals, @@ -98,8 +72,16 @@ statement and filename have the same semantics as profile.run """ - return _Utils(Profile).runctx(statement, globals, locals, filename, sort) + prof = Profile() + try: + prof = prof.runctx(statement, globals, locals) + except SystemExit: + pass + if filename is not None: + prof.dump_stats(filename) + else: + return prof.print_stats(sort) class Profile: """Profiler class. @@ -391,9 +373,10 @@ print_stats() def dump_stats(self, file): - with open(file, 'wb') as f: - self.create_stats() - marshal.dump(self.stats, f) + f = open(file, 'wb') + self.create_stats() + marshal.dump(self.stats, f) + f.close() def create_stats(self): self.simulate_cmd_complete() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pstats.py --- a/Lib/pstats.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pstats.py Fri Feb 01 23:12:09 2013 +0100 @@ -93,8 +93,9 @@ self.stats = {} return elif isinstance(arg, str): - with open(arg, 'rb') as f: - self.stats = marshal.load(f) + f = open(arg, 'rb') + self.stats = marshal.load(f) + f.close() try: file_stats = os.stat(arg) arg = time.ctime(file_stats.st_mtime) + " " + arg @@ -148,8 +149,11 @@ def dump_stats(self, filename): """Write the profile data to a file we know how to load back.""" - with open(filename, 'wb') as f: + f = open(filename, 'wb') + try: marshal.dump(self.stats, f) + finally: + f.close() # list the tuple indices and directions for sorting, # along with some printable description diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pty.py --- a/Lib/pty.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pty.py Fri Feb 01 23:12:09 2013 +0100 @@ -47,7 +47,18 @@ return _open_terminal() def _open_terminal(): - """Open pty master and return (master_fd, tty_name).""" + """Open pty master and return (master_fd, tty_name). + SGI and generic BSD version, for when openpty() fails.""" + try: + import sgi + except ImportError: + pass + else: + try: + tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0) + except OSError as msg: + raise OSError(msg) + return master_fd, tty_name for x in 'pqrstuvwxyzPQRST': for y in '0123456789abcdef': pty_name = '/dev/pty' + x + y @@ -101,9 +112,9 @@ os.close(master_fd) # Slave becomes stdin/stdout/stderr of child. - os.dup2(slave_fd, STDIN_FILENO) - os.dup2(slave_fd, STDOUT_FILENO) - os.dup2(slave_fd, STDERR_FILENO) + os.dup2(slave_fd, STDIN_FILENO, cloexec=False) + os.dup2(slave_fd, STDOUT_FILENO, cloexec=False) + os.dup2(slave_fd, STDERR_FILENO, cloexec=False) if (slave_fd > STDERR_FILENO): os.close (slave_fd) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/py_compile.py --- a/Lib/py_compile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/py_compile.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,14 +3,17 @@ This module has intimate knowledge of the format of .pyc files. """ -import importlib._bootstrap -import importlib.machinery -import importlib.util +import builtins +import errno +import imp +import marshal import os -import os.path import sys +import tokenize import traceback +MAGIC = imp.get_magic() + __all__ = ["compile", "main", "PyCompileError"] @@ -62,6 +65,13 @@ return self.msg +def wr_long(f, x): + """Internal; write a 32-bit int to a file in little-endian order.""" + f.write(bytes([x & 0xff, + (x >> 8) & 0xff, + (x >> 16) & 0xff, + (x >> 24) & 0xff])) + def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1): """Byte-compile one Python source file to Python bytecode. @@ -97,31 +107,18 @@ See compileall.py for a script/module that uses this module to byte-compile all installed files (or all files in selected directories). - - Do note that FileExistsError is raised if cfile ends up pointing at a - non-regular file or symlink. Because the compilation uses a file renaming, - the resulting file would be regular and thus not the same type of file as - it was previously. """ - if cfile is None: - if optimize >= 0: - cfile = importlib.util.cache_from_source(file, - debug_override=not optimize) - else: - cfile = importlib.util.cache_from_source(file) - if os.path.islink(cfile): - msg = ('{} is a symlink and will be changed into a regular file if ' - 'import writes a byte-compiled file to it') - raise FileExistsError(msg.format(cfile)) - elif os.path.exists(cfile) and not os.path.isfile(cfile): - msg = ('{} is a non-regular file and will be changed into a regular ' - 'one if import writes a byte-compiled file to it') - raise FileExistsError(msg.format(cfile)) - loader = importlib.machinery.SourceFileLoader('', file) - source_bytes = loader.get_data(file) + with tokenize.open(file) as f: + try: + st = os.fstat(f.fileno()) + except AttributeError: + st = os.stat(file) + timestamp = int(st.st_mtime) + size = st.st_size & 0xFFFFFFFF + codestring = f.read() try: - code = loader.source_to_code(source_bytes, dfile or file, - _optimize=optimize) + codeobject = builtins.compile(codestring, dfile or file, 'exec', + optimize=optimize) except Exception as err: py_exc = PyCompileError(err.__class__, err, dfile or file) if doraise: @@ -129,20 +126,28 @@ else: sys.stderr.write(py_exc.msg + '\n') return + if cfile is None: + if optimize >= 0: + cfile = imp.cache_from_source(file, debug_override=not optimize) + else: + cfile = imp.cache_from_source(file) try: dirname = os.path.dirname(cfile) if dirname: os.makedirs(dirname) - except FileExistsError: - pass - source_stats = loader.path_stats(file) - bytecode = importlib._bootstrap._code_to_bytecode( - code, source_stats['mtime'], source_stats['size']) - mode = importlib._bootstrap._calc_mode(file) - importlib._bootstrap._write_atomic(cfile, bytecode, mode) + except OSError as error: + if error.errno != errno.EEXIST: + raise + with open(cfile, 'wb') as fc: + fc.write(b'\0\0\0\0') + wr_long(fc, timestamp) + wr_long(fc, size) + marshal.dump(codeobject, fc) + fc.flush() + fc.seek(0, 0) + fc.write(MAGIC) return cfile - def main(args=None): """Compile several source files. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pydoc.py --- a/Lib/pydoc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pydoc.py Fri Feb 01 23:12:09 2013 +0100 @@ -44,16 +44,16 @@ """ # Known bugs that can't be fixed here: -# - synopsis() cannot be prevented from clobbering existing -# loaded modules. +# - imp.load_module() cannot be prevented from clobbering existing +# loaded modules, so calling synopsis() on a binary module file +# changes the contents of any existing module with the same name. # - If the __file__ attribute on a module is a relative path and # the current directory is changed with os.chdir(), an incorrect # path will be displayed. import builtins -import importlib._bootstrap +import imp import importlib.machinery -import importlib.util import inspect import io import os @@ -132,10 +132,7 @@ return _re_stripid.sub(r'\1', text) def _is_some_method(obj): - return (inspect.isfunction(obj) or - inspect.ismethod(obj) or - inspect.isbuiltin(obj) or - inspect.ismethoddescriptor(obj)) + return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj) def allmethods(cl): methods = {} @@ -267,19 +264,20 @@ def importfile(path): """Import a Python source file or compiled file given its path.""" - magic = importlib.util.MAGIC_NUMBER + magic = imp.get_magic() with open(path, 'rb') as file: - is_bytecode = magic == file.read(len(magic)) - filename = os.path.basename(path) - name, ext = os.path.splitext(filename) - if is_bytecode: - loader = importlib._bootstrap.SourcelessFileLoader(name, path) - else: - loader = importlib._bootstrap.SourceFileLoader(name, path) - try: - return loader.load_module(name) - except: - raise ErrorDuringImport(path, sys.exc_info()) + if file.read(len(magic)) == magic: + kind = imp.PY_COMPILED + else: + kind = imp.PY_SOURCE + file.seek(0) + filename = os.path.basename(path) + name, ext = os.path.splitext(filename) + try: + module = imp.load_module(name, file, path, (ext, 'r', kind)) + except: + raise ErrorDuringImport(path, sys.exc_info()) + return module def safeimport(path, forceload=0, cache={}): """Import a module; handle errors; return None if the module isn't found. @@ -1428,8 +1426,9 @@ """Page through text by invoking a program on a temporary file.""" import tempfile filename = tempfile.mktemp() - with open(filename, 'w') as file: - file.write(text) + file = open(filename, 'w') + file.write(text) + file.close() try: os.system(cmd + ' "' + filename + '"') finally: @@ -1848,10 +1847,10 @@ Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". -To get a list of available modules, keywords, symbols, or topics, type -"modules", "keywords", "symbols", or "topics". Each module also comes -with a one-line summary of what it does; to list the modules whose name -or summary contain a given string such as "spam", type "modules spam". +To get a list of available modules, keywords, or topics, type "modules", +"keywords", or "topics". Each module also comes with a one-line summary +of what it does; to list the modules whose summaries contain a given word +such as "spam", type "modules spam". ''' % tuple([sys.version[:3]]*2)) def list(self, items, columns=4, width=80): @@ -1956,10 +1955,9 @@ def listmodules(self, key=''): if key: self.output.write(''' -Here is a list of modules whose name or summary contains '{}'. -If there are any, enter a module name to get more help. +Here is a list of matching modules. Enter any module name to get more help. -'''.format(key)) +''') apropos(key) else: self.output.write(''' @@ -1978,11 +1976,35 @@ self.list(modules.keys()) self.output.write(''' Enter any module name to get more help. Or, type "modules spam" to search -for modules whose name or summary contain the string "spam". +for modules whose descriptions contain the word "spam". ''') help = Helper() +class Scanner: + """A generic tree iterator.""" + def __init__(self, roots, children, descendp): + self.roots = roots[:] + self.state = [] + self.children = children + self.descendp = descendp + + def next(self): + if not self.state: + if not self.roots: + return None + root = self.roots.pop(0) + self.state = [(root, self.children(root))] + node, children = self.state[-1] + if not children: + self.state.pop() + return self.next() + child = children.pop(0) + if self.descendp(child): + self.state.append((child, self.children(child))) + return child + + class ModuleScanner: """An interruptible scanner that searches module synopses.""" diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/pydoc_data/topics.py --- a/Lib/pydoc_data/topics.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/pydoc_data/topics.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Autogenerated by Sphinx on Sat Mar 23 15:42:31 2013 +# Autogenerated by Sphinx on Sat Aug 25 12:12:45 2012 topics = {'assert': '\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\nto\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that ``__debug__`` and ``AssertionError``\nrefer to 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\n(command line option -O). The current code generator emits no code\nfor an assert statement when optimization is requested at compile\ntime. Note that it is unnecessary to include the source code for the\nexpression that failed in the error message; it will be displayed as\npart of the stack trace.\n\nAssignments to ``__debug__`` are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n', 'assignment': '\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 | "*" target\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, optionally enclosed in\nparentheses or square brackets, is recursively defined as 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 object\n must be an iterable with the same number of items as there are\n targets in the target list, and the items are assigned, from left to\n right, to the corresponding targets.\n\n * If the target list contains one target prefixed with an asterisk,\n called a "starred" target: The object must be a sequence with at\n least as many items as there are targets in the target list, minus\n one. The first items of the sequence are assigned, from left to\n right, to the targets before the starred target. The final items\n of the sequence are assigned to the targets after the starred\n target. A list of the remaining items in the sequence is then\n assigned to the starred target (the list can be empty).\n\n * Else: The object must be a sequence with the same number of items\n as there are targets in the target list, and the items are\n assigned, from 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`` or ``nonlocal``\n statement in the current code block: the name is bound to the\n object in the current local namespace.\n\n * Otherwise: the name is bound to the object in the global namespace\n or the outer namespace determined by ``nonlocal``, respectively.\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 square\n brackets: The object must be an iterable with the same number of\n 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\n always set as an instance attribute, creating it if necessary.\n Thus, the two occurrences of ``a.x`` do not necessarily refer to the\n same attribute: if the RHS expression refers to a class attribute,\n the 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 an integer. If it is negative, the sequence\'s\n length is added to it. The resulting value must be a nonnegative\n integer less than the sequence\'s length, and the sequence is asked\n to assign the assigned object to its item with that index. If the\n index is out of range, ``IndexError`` is raised (assignment to a\n subscripted sequence cannot add new items to a 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 For user-defined objects, the ``__setitem__()`` method is called\n with appropriate arguments.\n\n* If the target is a slicing: The primary expression in the reference\n is evaluated. It should yield a mutable sequence object (such as a\n list). The assigned object should be a sequence object of the same\n type. Next, the lower and upper bound expressions are evaluated,\n insofar they are present; defaults are zero and the sequence\'s\n length. The bounds should evaluate to integers. If either bound is\n negative, the sequence\'s length is added to it. The resulting\n bounds are clipped to lie between zero and the sequence\'s length,\n inclusive. Finally, the sequence object is asked to replace the\n slice with the items of the assigned sequence. The length of the\n slice may be different from the length of the assigned sequence,\n thus changing the length of the target sequence, if the object\n 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\nSee also:\n\n **PEP 3132** - Extended Iterable Unpacking\n The specification for the ``*target`` feature.\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\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is 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': '\nIdentifiers (Names)\n*******************\n\nAn identifier occurring as an atom is a name. See section\n*Identifiers and keywords* for lexical definition and section *Naming\nand binding* for documentation 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 in front of the name, with leading underscores removed, and\na single underscore inserted in front of the class name. For example,\nthe identifier ``__spam`` occurring in a class named ``Ham`` will be\ntransformed to ``_Ham__spam``. This transformation is independent of\nthe syntactical context in which the identifier is used. If the\ntransformed name is extremely long (longer than 255 characters),\nimplementation defined truncation may happen. If the class name\nconsists only of underscores, no transformation is done.\n', @@ -16,14 +16,14 @@ 'booleans': '\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. User-defined objects can customize their truth value by\nproviding a ``__bool__()`` method.\n\nThe operator ``not`` yields ``True`` if its argument is false,\n``False`` otherwise.\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\nvalue is returned; otherwise, *y* is evaluated and the resulting value\nis returned.\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\ninvent a value anyway, it does not bother to return a value of the\nsame type as its argument, so e.g., ``not \'foo\'`` yields ``False``,\nnot ``\'\'``.)\n', 'break': '\nThe ``break`` statement\n***********************\n\n break_stmt ::= "break"\n\n``break`` may only occur syntactically nested in a ``for`` or\n``while`` loop, but not nested in a function or class definition\nwithin that loop.\n\nIt terminates the nearest enclosing loop, skipping the optional\n``else`` clause 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\n``finally`` clause, that ``finally`` clause is executed before really\nleaving the loop.\n', 'callable-types': '\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': '\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 [","] | comprehension] ")"\n argument_list ::= positional_arguments ["," keyword_arguments]\n ["," "*" expression] ["," keyword_arguments]\n ["," "**" expression]\n | keyword_arguments ["," "*" expression]\n ["," keyword_arguments] ["," "**" 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 all objects having a\n``__call__()`` method are callable). All argument expressions are\nevaluated before the call is attempted. Please refer to section\n*Function definitions* for the syntax 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\n``TypeError`` exception is raised. Otherwise, the list of filled\nslots is used as the 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\nparse their 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\nformal parameter 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,\n``expression`` must evaluate to an iterable. Elements from this\niterable are treated as if they were additional positional arguments;\nif there are positional arguments *x1*, ..., *xN*, and ``expression``\nevaluates to a sequence *y1*, ..., *yM*, this is equivalent to a call\nwith M+N positional 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 "", 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``\nsyntax to be used in the same call, so in practice this confusion does\nnot arise.\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,\na ``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.\n\nA call always returns some value, possibly ``None``, unless it raises\nan exception. 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\n the 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\n the same as if that method was called.\n', + 'calls': '\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 [","] | comprehension] ")"\n argument_list ::= positional_arguments ["," keyword_arguments]\n ["," "*" expression] ["," keyword_arguments]\n ["," "**" expression]\n | keyword_arguments ["," "*" expression]\n ["," keyword_arguments] ["," "**" 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 all objects having a\n``__call__()`` method are callable). All argument expressions are\nevaluated before the call is attempted. Please refer to section\n*Function definitions* for the syntax 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\n``TypeError`` exception is raised. Otherwise, the list of filled\nslots is used as the 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\nparse their 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\nformal parameter 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,\n``expression`` must evaluate to an iterable. Elements from this\niterable are treated as if they were additional positional arguments;\nif there are positional arguments *x1*, ..., *xN*, and ``expression``\nevaluates to a sequence *y1*, ..., *yM*, this is equivalent to a call\nwith M+N positional 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 "", 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``\nsyntax to be used in the same call, so in practice this confusion does\nnot arise.\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,\na ``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.\n\nA call always returns some value, possibly ``None``, unless it raises\nan exception. 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\n the 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\n the same as if that method was called.\n', 'class': '\nClass definitions\n*****************\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n 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 function\n body is transformed into the function\'s ``__doc__`` attribute and\n 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': '\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\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found 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``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n 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, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``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 they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another. When cross-type\ncomparison is not supported, the comparison method returns\n``NotImplemented``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in 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\n== z`` is produced while iterating over ``y``. If an exception is\nraised during 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\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', - 'compound': '\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\ncontrol flow constructs. ``try`` specifies exception handlers and/or\ncleanup code for a group of statements, while the ``with`` statement\nallows the execution of initialization and finalization code around a\nblock of code. Function and class definitions are also syntactically\ncompound 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()`` calls 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 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\na ``DEDENT``. Also note that optional continuation clauses always\nbegin with 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\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n\n\nThe ``for`` statement\n=====================\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (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 (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in 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``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (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" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\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\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that 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\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception it is re-raised at the end of\nthe ``finally`` clause. If the ``finally`` clause raises another\nexception, the saved exception is set as the context of the new\nexception. If the ``finally`` clause executes a ``return`` or\n``break`` statement, the saved exception is discarded:\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\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n\n\nThe ``with`` statement\n======================\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\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor 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\n be 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,\n three ``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\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` 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\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)* ["," "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\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 *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 up until the "``*``" must also have a default value ---\nthis is a syntactic restriction 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\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\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\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n 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 function\n body is transformed into the function\'s ``__doc__`` attribute and\n 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': '\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\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found 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``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n 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, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``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 they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another, but comparisons of\n``float`` and ``Decimal`` are not supported to avoid the inevitable\nconfusion arising from representation issues such as ``float(\'1.1\')``\nbeing inexactly represented and therefore not exactly equal to\n``Decimal(\'1.1\')`` which is. When cross-type comparison is not\nsupported, the comparison method returns ``NotImplemented``. This can\ncreate the illusion of non-transitivity between supported cross-type\ncomparisons and unsupported comparisons. For example, ``Decimal(2) ==\n2`` and ``2 == float(2)`` but ``Decimal(2) != float(2)``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in 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\n== z`` is produced while iterating over ``y``. If an exception is\nraised during 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\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', + 'compound': '\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\ncontrol flow constructs. ``try`` specifies exception handlers and/or\ncleanup code for a group of statements, while the ``with`` statement\nallows the execution of initialization and finalization code around a\nblock of code. Function and class definitions are also syntactically\ncompound 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()`` calls 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 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\na ``DEDENT``. Also note that optional continuation clauses always\nbegin with 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\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n\n\nThe ``for`` statement\n=====================\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (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 (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in 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``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (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" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\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\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that 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\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception or ``break`` statement, it is\nre-raised at the end of the ``finally`` clause. If the ``finally``\nclause raises another exception the saved exception is set as the\ncontext of the new exception; if the ``finally`` clause executes a\n``return`` statement, the saved exception is discarded:\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\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n\n\nThe ``with`` statement\n======================\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\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor 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\n be 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,\n three ``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\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` 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\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\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 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 up until the "``*``" must also have a default value ---\nthis is a syntactic restriction 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\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\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\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n 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 function\n body is transformed into the function\'s ``__doc__`` attribute and\n 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': '\nWith Statement Context Managers\n*******************************\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\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 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n', 'continue': '\nThe ``continue`` statement\n**************************\n\n continue_stmt ::= "continue"\n\n``continue`` may only occur syntactically nested in a ``for`` or\n``while`` loop, but not nested in a function or class definition or\n``finally`` clause within that loop. It continues with the next cycle\nof the nearest 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': '\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," this means\nthat the operator implementation for built-in types works that way:\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 other\n is converted to floating point;\n\n* otherwise, both must be integers and no conversion is necessary.\n\nSome additional rules apply for certain operators (e.g., a string left\nargument to the \'%\' operator). Extensions must define their own\nconversion behavior.\n', - 'customization': '\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\n an 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 when the instance is created. 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,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``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,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__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\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled 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.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n 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 ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n 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\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n 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 ``str(object)`` and the built-in functions ``format()``\n and ``print()`` to compute the "informal" or nicely printable\n string representation of an object. The return value must be a\n *string* object.\n\n This method differs from ``object.__repr__()`` in that there is no\n expectation that ``__str__()`` return a valid Python expression: a\n more convenient or concise representation can be used.\n\n The default implementation defined by the built-in type ``object``\n calls ``object.__repr__()``.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``str.format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a 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 These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n 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\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and 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\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n 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.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n A class that overrides ``__eq__()`` and does not define\n ``__hash__()`` will have its ``__hash__()`` implicitly set to\n ``None``. When the ``__hash__()`` method of a class is ``None``,\n instances of the class will raise an appropriate ``TypeError`` when\n a program attempts to retrieve their hash value, and will also be\n correctly identified as unhashable when checking ``isinstance(obj,\n collections.Hashable``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``.\n\n If a class that does not override ``__eq__()`` wishes to suppress\n hash support, it should include ``__hash__ = None`` in the class\n definition. A class which defines its own ``__hash__()`` that\n explicitly raises a ``TypeError`` would be incorrectly identified\n as hashable by an ``isinstance(obj, collections.Hashable)`` call.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n', + 'customization': '\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\n an 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 when the instance is created. 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,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``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,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__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\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled 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.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n 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 ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n 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\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n 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 function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to 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.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a 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 These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n 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\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and 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\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n 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.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n', 'debugger': '\n``pdb`` --- The Python Debugger\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\nreading the source. The extension interface uses the modules ``bdb``\nand ``cmd``.\n\nThe debugger\'s prompt is ``(Pdb)``. Typical usage to run a program\nunder control of the debugger is:\n\n >>> import pdb\n >>> import mymodule\n >>> pdb.run(\'mymodule.test()\')\n > (0)?()\n (Pdb) continue\n > (1)?()\n (Pdb) continue\n NameError: \'spam\'\n > (1)?()\n (Pdb)\n\nChanged in version 3.3: Tab-completion via the ``readline`` module is\navailable for commands and command arguments, e.g. the current global\nand local names are offered as arguments of the ``print`` command.\n\n``pdb.py`` can also be invoked as a script to debug other scripts.\nFor example:\n\n python3 -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 3.2: ``pdb.py`` now accepts a ``-c`` option that\nexecutes commands as if given in a ``.pdbrc`` file, see *Debugger\nCommands*.\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 ``continue`` 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 "", 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=None, locals=None)\n\n Execute the *statement* (given as a string or a code object) under\n debugger control. The debugger prompt appears before any code is\n executed; you can set breakpoints and type ``continue``, or you can\n step through the statement using ``step`` or ``next`` (all these\n commands are explained below). The optional *globals* and *locals*\n arguments specify the environment in which the code is executed; by\n default the dictionary of the module ``__main__`` is used. (See\n the explanation of the built-in ``exec()`` or ``eval()``\n functions.)\n\npdb.runeval(expression, globals=None, locals=None)\n\n Evaluate the *expression* (given as a string or a code object)\n under debugger control. When ``runeval()`` returns, it returns the\n value of the expression. Otherwise this function is similar to\n ``run()``.\n\npdb.runcall(function, *args, **kwds)\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=None)\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\ninstantiating the ``Pdb`` class and calling the method of the same\nname. If you want to access further features, you have to do this\nyourself:\n\nclass class pdb.Pdb(completekey=\'tab\', stdin=None, stdout=None, skip=None, nosigint=False)\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 By default, Pdb sets a handler for the SIGINT signal (which is sent\n when the user presses Ctrl-C on the console) when you give a\n ``continue`` command. This allows you to break into the debugger\n again by pressing Ctrl-C. If you want Pdb not to touch the SIGINT\n handler, set *nosigint* tot true.\n\n Example call to enable tracing with *skip*:\n\n import pdb; pdb.Pdb(skip=[\'django.*\']).set_trace()\n\n New in version 3.1: The *skip* argument.\n\n New in version 3.2: The *nosigint* argument. Previously, a SIGINT\n handler was never set by Pdb.\n\n run(statement, globals=None, locals=None)\n runeval(expression, globals=None, locals=None)\n runcall(function, *args, **kwds)\n set_trace()\n\n See the documentation for the functions explained above.\n\n\nDebugger Commands\n=================\n\nThe commands recognized by the debugger are listed below. Most\ncommands can be abbreviated to one or two letters as indicated; e.g.\n``h(elp)`` means that either ``h`` or ``help`` can be used to enter\nthe help command (but not ``he`` or ``hel``, nor ``H`` or ``Help`` or\n``HELP``). Arguments to commands must be separated by whitespace\n(spaces or tabs). Optional arguments are enclosed in square brackets\n(``[]``) in the command syntax; the square brackets must not be typed.\nAlternatives in the command syntax are separated by a vertical bar\n(``|``).\n\nEntering a blank line repeats the last command entered. Exception: if\nthe last command was a ``list`` command, the next 11 lines are listed.\n\nCommands that the debugger doesn\'t recognize are assumed to be Python\nstatements and are executed in the context of the program being\ndebugged. Python statements can also be prefixed with an exclamation\npoint (``!``). This is a powerful way to inspect the program being\ndebugged; it is even possible to change a variable or call a function.\nWhen an exception occurs in such a statement, the exception name is\nprinted but the debugger\'s state is not changed.\n\nThe debugger supports *aliases*. Aliases can have parameters which\nallows one a certain level of adaptability to the context under\nexamination.\n\nMultiple commands may be entered on a single line, separated by\n``;;``. (A single ``;`` is not used as it is the separator for\nmultiple commands in a line that is passed to the Python parser.) No\nintelligence is applied to separating the commands; the input is split\nat the first ``;;`` pair, even if it is in the middle of a quoted\nstring.\n\nIf a file ``.pdbrc`` exists in the user\'s home directory or in the\ncurrent directory, it is read in and executed as if it had been typed\nat the debugger prompt. This is particularly useful for aliases. If\nboth files exist, the one in the home directory is read first and\naliases defined there can be overridden by the local file.\n\nChanged in version 3.2: ``.pdbrc`` can now contain commands that\ncontinue debugging, such as ``continue`` or ``next``. Previously,\nthese commands had no effect.\n\nh(elp) [command]\n\n Without argument, print the list of available commands. With a\n *command* as argument, print help about that command. ``help pdb``\n displays the full documentation (the docstring of the ``pdb``\n module). Since the *command* argument must be an identifier,\n ``help exec`` must be entered to get help on the ``!`` command.\n\nw(here)\n\n Print a stack trace, with the most recent frame at the bottom. An\n arrow indicates the current frame, which determines the context of\n most commands.\n\nd(own) [count]\n\n Move the current frame *count* (default one) levels down in the\n stack trace (to a newer frame).\n\nu(p) [count]\n\n Move the current frame *count* (default one) levels up in the stack\n trace (to an older frame).\n\nb(reak) [([filename:]lineno | function) [, condition]]\n\n With a *lineno* argument, set a break there in the current file.\n With a *function* argument, set a break at the first executable\n statement within that function. The line number may be prefixed\n with a filename and a colon, to specify a breakpoint in another\n file (probably one that hasn\'t been loaded yet). The file is\n searched on ``sys.path``. Note that each breakpoint is assigned a\n number to which all the other breakpoint commands refer.\n\n If a second argument is present, it is an expression which must\n evaluate to true before the breakpoint is honored.\n\n Without argument, list all breaks, including for each breakpoint,\n the number of times that breakpoint has been hit, the current\n ignore count, and the associated condition if any.\n\ntbreak [([filename:]lineno | function) [, condition]]\n\n Temporary breakpoint, which is removed automatically when it is\n first hit. The arguments are the same as for ``break``.\n\ncl(ear) [filename:lineno | bpnumber [bpnumber ...]]\n\n With a *filename:lineno* argument, clear all the breakpoints at\n this line. With a space separated list of breakpoint numbers, clear\n those breakpoints. Without argument, clear all breaks (but first\n ask confirmation).\n\ndisable [bpnumber [bpnumber ...]]\n\n Disable the breakpoints given as a space separated list of\n breakpoint numbers. Disabling a breakpoint means it cannot cause\n the program to stop execution, but unlike clearing a breakpoint, it\n remains in the list of breakpoints and can be (re-)enabled.\n\nenable [bpnumber [bpnumber ...]]\n\n Enable the breakpoints specified.\n\nignore bpnumber [count]\n\n Set the ignore count for the given breakpoint number. If count is\n omitted, the ignore count is set to 0. A breakpoint becomes active\n when the ignore count is zero. When non-zero, the count is\n decremented each time the breakpoint is reached and the breakpoint\n is not disabled and any associated condition evaluates to true.\n\ncondition bpnumber [condition]\n\n Set a new *condition* for the breakpoint, an expression which must\n evaluate to true before the breakpoint is honored. If *condition*\n is absent, any existing condition is removed; i.e., the breakpoint\n is made unconditional.\n\ncommands [bpnumber]\n\n Specify a list of commands for breakpoint number *bpnumber*. The\n commands themselves appear on the following lines. Type a line\n containing just ``end`` to terminate the commands. An example:\n\n (Pdb) commands 1\n (com) print some_variable\n (com) end\n (Pdb)\n\n To remove all commands from a breakpoint, type commands and follow\n it immediately with ``end``; that is, give no commands.\n\n With no *bpnumber* argument, commands refers to the last breakpoint\n set.\n\n You can use breakpoint commands to start your program up again.\n Simply use the continue command, or step, or any other command that\n resumes execution.\n\n Specifying any command resuming execution (currently continue,\n step, next, return, jump, quit and their abbreviations) terminates\n the command list (as if that command was immediately followed by\n end). This is because any time you resume execution (even with a\n simple next or step), you may encounter another breakpoint--which\n could have its own command list, leading to ambiguities about which\n list to execute.\n\n If you use the \'silent\' command in the command list, the usual\n message about stopping at a breakpoint is not printed. This may be\n desirable for breakpoints that are to print a specific message and\n then continue. If none of the other commands print anything, you\n see no sign that the breakpoint was reached.\n\ns(tep)\n\n Execute the current line, stop at the first possible occasion\n (either in a function that is called or on the next line in the\n current function).\n\nn(ext)\n\n Continue execution until the next line in the current function is\n reached or it returns. (The difference between ``next`` and\n ``step`` is that ``step`` stops inside a called function, while\n ``next`` executes called functions at (nearly) full speed, only\n stopping at the next line in the current function.)\n\nunt(il) [lineno]\n\n Without argument, continue execution until the line with a number\n greater than the current one is reached.\n\n With a line number, continue execution until a line with a number\n greater or equal to that is reached. In both cases, also stop when\n the current frame returns.\n\n Changed in version 3.2: Allow giving an explicit line number.\n\nr(eturn)\n\n Continue execution until the current function returns.\n\nc(ont(inue))\n\n Continue execution, only stop when a breakpoint is encountered.\n\nj(ump) lineno\n\n Set the next line that will be executed. Only available in the\n bottom-most frame. This lets you jump back and execute code again,\n or jump forward to skip code that you don\'t want to run.\n\n It should be noted that not all jumps are allowed -- for instance\n it is not possible to jump into the middle of a ``for`` loop or out\n of a ``finally`` clause.\n\nl(ist) [first[, last]]\n\n List source code for the current file. Without arguments, list 11\n lines around the current line or continue the previous listing.\n With ``.`` as argument, list 11 lines around the current line.\n With one argument, list 11 lines around at that line. With two\n arguments, list the given range; if the second argument is less\n than the first, it is interpreted as a count.\n\n The current line in the current frame is indicated by ``->``. If\n an exception is being debugged, the line where the exception was\n originally raised or propagated is indicated by ``>>``, if it\n differs from the current line.\n\n New in version 3.2: The ``>>`` marker.\n\nll | longlist\n\n List all source code for the current function or frame.\n Interesting lines are marked as for ``list``.\n\n New in version 3.2.\n\na(rgs)\n\n Print the argument list of the current function.\n\np(rint) expression\n\n Evaluate the *expression* in the current context and print its\n value.\n\npp expression\n\n Like the ``print`` command, except the value of the expression is\n pretty-printed using the ``pprint`` module.\n\nwhatis expression\n\n Print the type of the *expression*.\n\nsource expression\n\n Try to get source code for the given object and display it.\n\n New in version 3.2.\n\ndisplay [expression]\n\n Display the value of the expression if it changed, each time\n execution stops in the current frame.\n\n Without expression, list all display expressions for the current\n frame.\n\n New in version 3.2.\n\nundisplay [expression]\n\n Do not display the expression any more in the current frame.\n Without expression, clear all display expressions for the current\n frame.\n\n New in version 3.2.\n\ninteract\n\n Start an interative interpreter (using the ``code`` module) whose\n global namespace contains all the (global and local) names found in\n the current scope.\n\n New in version 3.2.\n\nalias [name [command]]\n\n Create an alias called *name* that executes *command*. The command\n must *not* be enclosed in quotes. Replaceable parameters can be\n indicated by ``%1``, ``%2``, and so on, while ``%*`` is replaced by\n all the parameters. If no command is given, the current alias for\n *name* is shown. If no arguments are given, all aliases are listed.\n\n Aliases may be nested and can contain anything that can be legally\n typed at the pdb prompt. Note that internal pdb commands *can* be\n overridden by aliases. Such a command is then hidden until the\n alias is removed. Aliasing is recursively applied to the first\n word of the command line; all other words in the line are left\n alone.\n\n As an example, here are two useful aliases (especially when placed\n in the ``.pdbrc`` file):\n\n # Print instance variables (usage "pi classInst")\n alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k])\n # Print instance variables in self\n alias ps pi self\n\nunalias name\n\n Delete the specified alias.\n\n! statement\n\n Execute the (one-line) *statement* in the context of the current\n stack frame. The exclamation point can be omitted unless the first\n word of the statement resembles a debugger command. To set a\n global variable, you can prefix the assignment command with a\n ``global`` statement on the same line, e.g.:\n\n (Pdb) global list_options; list_options = [\'-l\']\n (Pdb)\n\nrun [args ...]\nrestart [args ...]\n\n Restart the debugged Python program. If an argument is supplied,\n it is split with ``shlex`` and the result is used as the new\n ``sys.argv``. History, breakpoints, actions and debugger options\n are preserved. ``restart`` is an alias for ``run``.\n\nq(uit)\n\n Quit from the debugger. The program being executed is aborted.\n\n-[ Footnotes ]-\n\n[1] Whether a frame is considered to originate in a certain module is\n determined by the ``__name__`` in the frame globals.\n', 'del': '\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\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\nChanged in version 3.2: Previously it was illegal to delete a name\nfrom the local namespace if it occurs as a free variable in a nested\nblock.\n', 'dict': '\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', @@ -34,15 +34,15 @@ 'exprlists': '\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': '\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 are always interpreted using\nradix 10. For example, ``077e010`` is legal, and denotes the same\nnumber as ``77e10``. The allowed range of floating point literals is\nimplementation-dependent. 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': '\nThe ``for`` statement\n*********************\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (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 (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in 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``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (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': '\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 ::= +\n conversion ::= "r" | "s" | "a"\n format_spec ::= \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\nis preceded by a colon ``\':\'``. These specify a non-default format\nfor the replacement 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\nany number of index or attribute expressions. An expression of the\nform ``\'.name\'`` selects the named attribute using ``getattr()``,\nwhile an expression of the form ``\'[index]\'`` does an index lookup\nusing ``__getitem__()``.\n\nChanged in version 3.1: 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\n``__format__()`` method of the value itself. However, in some cases\nit is desirable to force a type to be formatted as a string,\noverriding its own definition of formatting. By converting the value\nto a string before calling ``__format__()``, the normal formatting\nlogic is bypassed.\n\nThree conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, ``\'!r\'`` which calls ``repr()`` and ``\'!a\'``\nwhich calls ``ascii()``.\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 "More {!a}" # Calls ascii() 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 can contain only a field\nname; conversion flags and format specifications are not allowed. The\nreplacement fields within the format_spec are substituted before the\n*format_spec* string is interpreted. This allows the formatting of a\nvalue 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-\nempty format 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 ::= \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\nThe *fill* character can be any character other than \'{\' or \'}\'. The\npresence of a fill character is signaled by the character following\nit, which must be one of the alignment options. If the second\ncharacter of *format_spec* is not a valid alignment option, then it is\nassumed that both the fill character and the alignment option are\nabsent.\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. |\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 causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective ``\'0b\'``, ``\'0o\'``, or\n``\'0x\'`` to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for ``\'g\'`` and ``\'G\'``\nconversions, trailing zeros are not removed from the result.\n\nThe ``\',\'`` option signals the use of a comma for a thousands\nseparator. For a locale aware separator, use the ``\'n\'`` integer\npresentation type instead.\n\nChanged in version 3.1: Added the ``\',\'`` option (see also **PEP\n378**).\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\nPreceding the *width* field by a zero (``\'0\'``) character enables\nsign-aware zero-padding for numeric types. This is equivalent to a\n*fill* character of ``\'0\'`` with an *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\npoint for a floating point value formatted with ``\'g\'`` or ``\'G\'``.\nFor non-number types the field indicates the maximum field size - in\nother words, how many characters will be used from the field content.\nThe *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 |\n | | the current locale setting to insert the appropriate |\n | | number 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``\'n\'`` and None). When doing so, ``float()`` is used to convert the\ninteger to 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 +-----------+------------------------------------------------------------+\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 +-----------+------------------------------------------------------------+\n | ``\'F\'`` | Fixed point. Same as ``\'f\'``, but converts ``nan`` to |\n | | ``NAN`` and ``inf`` to ``INF``. |\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 |\n | | ``p-1`` would have exponent ``exp``. Then if ``-4 <= exp |\n | | < p``, the number is formatted with presentation type |\n | | ``\'f\'`` and precision ``p-1-exp``. Otherwise, the number |\n | | is formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1``. In both cases insignificant trailing zeros are |\n | | removed from the significand, and the decimal point is |\n | | also removed if there are no remaining digits following |\n | | it. Positive and negative infinity, positive and negative |\n | | zero, and nans, are formatted as ``inf``, ``-inf``, ``0``, |\n | | ``-0`` and ``nan`` respectively, regardless of the |\n | | precision. A precision of ``0`` is treated as equivalent |\n | | to a precision of ``1``. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets too large. The representations of |\n | | infinity and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'g\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number 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 | Similar to ``\'g\'``, except with at least one digit past |\n | | the decimal point and a default precision of 12. This is |\n | | intended to match ``str()``, except you can add the other |\n | | format modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the new format syntax and comparison\nwith the old ``%``-formatting.\n\nIn most of the cases the syntax is similar to the old\n``%``-formatting, with the addition of the ``{}`` and with ``:`` used\ninstead of ``%``. For example, ``\'%03.2f\'`` can be translated to\n``\'{: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\') # 3.1+ 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:\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\nbases:\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\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\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): #doctest: +NORMALIZE_WHITESPACE\n ... for base in \'dXob\':\n ... print(\'{0:{width}{base}}\'.format(num, base=base, width=width), end=\' \')\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': '\nFunction definitions\n********************\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)* ["," "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\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 *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 up until the "``*``" must also have a default value ---\nthis is a syntactic restriction 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\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\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\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n', + 'formatstrings': '\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 ::= +\n conversion ::= "r" | "s" | "a"\n format_spec ::= \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\nis preceded by a colon ``\':\'``. These specify a non-default format\nfor the replacement 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\nany number of index or attribute expressions. An expression of the\nform ``\'.name\'`` selects the named attribute using ``getattr()``,\nwhile an expression of the form ``\'[index]\'`` does an index lookup\nusing ``__getitem__()``.\n\nChanged in version 3.1: 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\n``__format__()`` method of the value itself. However, in some cases\nit is desirable to force a type to be formatted as a string,\noverriding its own definition of formatting. By converting the value\nto a string before calling ``__format__()``, the normal formatting\nlogic is bypassed.\n\nThree conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, ``\'!r\'`` which calls ``repr()`` and ``\'!a\'``\nwhich calls ``ascii()``.\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 "More {!a}" # Calls ascii() 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 can contain only a field\nname; conversion flags and format specifications are not allowed. The\nreplacement fields within the format_spec are substituted before the\n*format_spec* string is interpreted. This allows the formatting of a\nvalue 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-\nempty format 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 ::= \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\nThe *fill* character can be any character other than \'{\' or \'}\'. The\npresence of a fill character is signaled by the character following\nit, which must be one of the alignment options. If the second\ncharacter of *format_spec* is not a valid alignment option, then it is\nassumed that both the fill character and the alignment option are\nabsent.\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. |\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 causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective ``\'0b\'``, ``\'0o\'``, or\n``\'0x\'`` to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for ``\'g\'`` and ``\'G\'``\nconversions, trailing zeros are not removed from the result.\n\nThe ``\',\'`` option signals the use of a comma for a thousands\nseparator. For a locale aware separator, use the ``\'n\'`` integer\npresentation type instead.\n\nChanged in version 3.1: Added the ``\',\'`` option (see also **PEP\n378**).\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\nPreceding the *width* field by a zero (``\'0\'``) character enables\nsign-aware zero-padding for numeric types. This is equivalent to a\n*fill* character of ``\'0\'`` with an *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\npoint for a floating point value formatted with ``\'g\'`` or ``\'G\'``.\nFor non-number types the field indicates the maximum field size - in\nother words, how many characters will be used from the field content.\nThe *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 |\n | | the current locale setting to insert the appropriate |\n | | number 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``\'n\'`` and None). When doing so, ``float()`` is used to convert the\ninteger to 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 +-----------+------------------------------------------------------------+\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 +-----------+------------------------------------------------------------+\n | ``\'F\'`` | Fixed point. Same as ``\'f\'``, but converts ``nan`` to |\n | | ``NAN`` and ``inf`` to ``INF``. |\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 |\n | | ``p-1`` would have exponent ``exp``. Then if ``-4 <= exp |\n | | < p``, the number is formatted with presentation type |\n | | ``\'f\'`` and precision ``p-1-exp``. Otherwise, the number |\n | | is formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1``. In both cases insignificant trailing zeros are |\n | | removed from the significand, and the decimal point is |\n | | also removed if there are no remaining digits following |\n | | it. Positive and negative infinity, positive and negative |\n | | zero, and nans, are formatted as ``inf``, ``-inf``, ``0``, |\n | | ``-0`` and ``nan`` respectively, regardless of the |\n | | precision. A precision of ``0`` is treated as equivalent |\n | | to a precision of ``1``. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets too large. The representations of |\n | | infinity and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'g\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number 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 | Similar to ``\'g\'``, except with at least one digit past |\n | | the decimal point and a default precision of 12. This is |\n | | intended to match ``str()``, except you can add the other |\n | | format modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the new format syntax and comparison\nwith the old ``%``-formatting.\n\nIn most of the cases the syntax is similar to the old\n``%``-formatting, with the addition of the ``{}`` and with ``:`` used\ninstead of ``%``. For example, ``\'%03.2f\'`` can be translated to\n``\'{: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\') # 3.1+ 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:\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\nbases:\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\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\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), end=\' \')\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': '\nFunction definitions\n********************\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\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 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 up until the "``*``" must also have a default value ---\nthis is a syntactic restriction 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\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\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\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n', 'global': '\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\ncode block 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.\nIt applies only to code parsed at the same time as the ``global``\nstatement. In particular, a ``global`` statement contained in a string\nor code object supplied to the built-in ``exec()`` function does not\naffect the code block *containing* the function call, and code\ncontained in such a string is unaffected by ``global`` statements in\nthe code containing the function call. The same applies to the\n``eval()`` and ``compile()`` functions.\n', 'id-classes': '\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\n the last evaluation; it is stored in the ``builtins`` 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\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of ``__*__`` names, in any context, that does\n not follow explicitly documented use, is subject to breakage\n without 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': '\nIdentifiers and keywords\n************************\n\nIdentifiers (also referred to as *names*) are described by the\nfollowing lexical definitions.\n\nThe syntax of identifiers in Python is based on the Unicode standard\nannex UAX-31, with elaboration and changes as defined below; see also\n**PEP 3131** for further details.\n\nWithin the ASCII range (U+0001..U+007F), the valid characters for\nidentifiers are the same as in Python 2.x: the uppercase and lowercase\nletters ``A`` through ``Z``, the underscore ``_`` and, except for the\nfirst character, the digits ``0`` through ``9``.\n\nPython 3.0 introduces additional characters from outside the ASCII\nrange (see **PEP 3131**). For these characters, the classification\nuses the version of the Unicode Character Database as included in the\n``unicodedata`` module.\n\nIdentifiers are unlimited in length. Case is significant.\n\n identifier ::= xid_start xid_continue*\n id_start ::= \n id_continue ::= \n xid_start ::= \n xid_continue ::= \n\nThe Unicode category codes mentioned above stand for:\n\n* *Lu* - uppercase letters\n\n* *Ll* - lowercase letters\n\n* *Lt* - titlecase letters\n\n* *Lm* - modifier letters\n\n* *Lo* - other letters\n\n* *Nl* - letter numbers\n\n* *Mn* - nonspacing marks\n\n* *Mc* - spacing combining marks\n\n* *Nd* - decimal numbers\n\n* *Pc* - connector punctuations\n\n* *Other_ID_Start* - explicit list of characters in PropList.txt to\n support backwards compatibility\n\n* *Other_ID_Continue* - likewise\n\nAll identifiers are converted into the normal form NFKC while parsing;\ncomparison of identifiers is based on NFKC.\n\nA non-normative HTML file listing all valid identifier characters for\nUnicode 4.1 can be found at http://www.dcl.hpi.uni-\npotsdam.de/home/loewis/table-3131.html.\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 False class finally is return\n None continue for lambda try\n True def from nonlocal while\n and del global not with\n as elif if or yield\n assert else import pass\n break except in raise\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\n the last evaluation; it is stored in the ``builtins`` 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\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of ``__*__`` names, in any context, that does\n not follow explicitly documented use, is subject to breakage\n without 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': '\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': '\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': '\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\nThe basic import statement (no ``from`` clause) is executed in two\nsteps:\n\n1. find a module, loading and initializing it if necessary\n\n2. define a name or names in the local namespace for the scope where\n the ``import`` statement occurs.\n\nWhen the statement contains multiple clauses (separated by commas) the\ntwo steps are carried out separately for each clause, just as though\nthe clauses had been separated out into individiual import statements.\n\nThe details of the first step, finding and loading modules is\ndescribed in greater detail in the section on the *import system*,\nwhich also describes the various types of packages and modules that\ncan be imported, as well as all the hooks that can be used to\ncustomize the import system. Note that failures in this step may\nindicate either that the module could not be located, *or* that an\nerror occurred while initializing the module, which includes execution\nof the module\'s code.\n\nIf the requested module is retrieved successfully, it will be made\navailable in the local namespace in one of three ways:\n\n* If the module name is followed by ``as``, then the name following\n ``as`` is bound directly to the imported module.\n\n* If no other name is specified, and the module being imported is a\n top level module, the module\'s name is bound in the local namespace\n as a reference to the imported module\n\n* If the module being imported is *not* a top level module, then the\n name of the top level package that contains the module is bound in\n the local namespace as a reference to the top level package. The\n imported module must be accessed using its full qualified name\n rather than directly\n\nThe ``from`` form uses a slightly more complex process:\n\n1. find the module specified in the ``from`` clause loading and\n initializing it if necessary;\n\n2. for each of the identifiers specified in the ``import`` clauses:\n\n 1. check if the imported module has an attribute by that name\n\n 2. if not, attempt to import a submodule with that name and then\n check the imported module again for that attribute\n\n 3. if the attribute is not found, ``ImportError`` is raised.\n\n 4. otherwise, a reference to that value is bound in the local\n namespace, using the name in the ``as`` clause if it is present,\n otherwise using the attribute name\n\nExamples:\n\n import foo # foo imported and bound locally\n import foo.bar.baz # foo.bar.baz imported, foo bound locally\n import foo.bar.baz as fbb # foo.bar.baz imported and bound as fbb\n from foo.bar import baz # foo.bar.baz imported and bound as baz\n from foo import attr # foo imported and foo.attr bound as attr\n\nIf the list of identifiers is replaced by a star (``\'*\'``), all public\nnames defined in the module are bound in the local namespace for the\nscope where the ``import`` statement occurs.\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named ``__all__``; if defined, it\nmust be a sequence of strings which are names defined or imported by\nthat module. The names given in ``__all__`` are all considered public\nand are required to exist. If ``__all__`` is not defined, the set of\npublic names includes all names found in the module\'s namespace which\ndo not begin with an underscore character (``\'_\'``). ``__all__``\nshould contain the entire public API. It is intended to avoid\naccidentally exporting items that are not part of the API (such as\nlibrary modules which were imported and used within the module).\n\nThe ``from`` form with ``*`` may only occur in a module scope.\nAttempting to use it in class or function definitions will raise a\n``SyntaxError``.\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named ``__all__``; if defined, it\nmust be a sequence of strings which are names defined or imported by\nthat module. The names given in ``__all__`` are all considered public\nand are required to exist. If ``__all__`` is not defined, the set of\npublic names includes all names found in the module\'s namespace which\ndo not begin with an underscore character (``\'_\'``). ``__all__``\nshould contain the entire public API. It is intended to avoid\naccidentally exporting items that are not part of the API (such as\nlibrary modules which were imported and used within the module).\n\nThe ``from`` form with ``*`` may only occur in a module scope. The\nwild card form of import --- ``import *`` --- is only allowed at the\nmodule level. Attempting to use it in class or function definitions\nwill 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``\nyou can 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\nwill end up importing ``pkg.mod``. If you execute ``from ..subpkg2\nimport mod`` from within ``pkg.subpkg1`` you will import\n``pkg.subpkg2.mod``. The specification for relative imports is\ncontained 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 3.0 are ``absolute_import``,\n``division``, ``generators``, ``unicode_literals``,\n``print_function``, ``nested_scopes`` and ``with_statement``. They\nare all redundant because they are always enabled, and only kept for\nbackwards compatibility.\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\nwill be 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 calls to the built-in functions ``exec()`` and\n``compile()`` that occur in a module ``M`` containing a future\nstatement will, by default, use the new syntax or semantics associated\nwith the future statement. This can be controlled by optional\narguments to ``compile()`` --- see the documentation of that function\nfor 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': '\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\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found 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``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n 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, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``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 they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another. When cross-type\ncomparison is not supported, the comparison method returns\n``NotImplemented``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in 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\n== z`` is produced while iterating over ``y``. If an exception is\nraised during 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\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', + 'in': '\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\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found 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``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n 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, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``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 they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another, but comparisons of\n``float`` and ``Decimal`` are not supported to avoid the inevitable\nconfusion arising from representation issues such as ``float(\'1.1\')``\nbeing inexactly represented and therefore not exactly equal to\n``Decimal(\'1.1\')`` which is. When cross-type comparison is not\nsupported, the comparison method returns ``NotImplemented``. This can\ncreate the illusion of non-transitivity between supported cross-type\ncomparisons and unsupported comparisons. For example, ``Decimal(2) ==\n2`` and ``2 == float(2)`` but ``Decimal(2) != float(2)``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in 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\n== z`` is produced while iterating over ``y``. If an exception is\nraised during 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\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', 'integers': '\nInteger literals\n****************\n\nInteger literals are described by the following lexical definitions:\n\n integer ::= decimalinteger | octinteger | hexinteger | bininteger\n decimalinteger ::= nonzerodigit digit* | "0"+\n nonzerodigit ::= "1"..."9"\n digit ::= "0"..."9"\n octinteger ::= "0" ("o" | "O") octdigit+\n hexinteger ::= "0" ("x" | "X") hexdigit+\n bininteger ::= "0" ("b" | "B") bindigit+\n octdigit ::= "0"..."7"\n hexdigit ::= digit | "a"..."f" | "A"..."F"\n bindigit ::= "0" | "1"\n\nThere is no limit for the length of integer literals apart from what\ncan be stored in available memory.\n\nNote that leading zeros in a non-zero decimal number are not allowed.\nThis is for disambiguation with C-style octal literals, which Python\nused before version 3.0.\n\nSome examples of integer literals:\n\n 7 2147483647 0o177 0b100110111\n 3 79228162514264337593543950336 0o377 0x100000000\n 79228162514264337593543950336 0xdeadbeef\n', 'lambda': '\nLambdas\n*******\n\n lambda_form ::= "lambda" [parameter_list]: expression\n lambda_form_nocond ::= "lambda" [parameter_list]: expression_nocond\n\nLambda forms (lambda expressions) have the same syntactic position as\nexpressions. They are a shorthand to create anonymous functions; the\nexpression ``lambda arguments: expression`` yields a function object.\nThe unnamed object behaves like a function object defined with\n\n def (arguments):\n return expression\n\nSee section *Function definitions* for the syntax of parameter lists.\nNote that functions created with lambda forms cannot contain\nstatements or annotations.\n', 'lists': '\nList displays\n*************\n\nA list display is a possibly empty series of expressions enclosed in\nsquare brackets:\n\n list_display ::= "[" [expression_list | comprehension] "]"\n\nA list display yields a new list object, the contents being specified\nby either a list of expressions or a comprehension. When a comma-\nseparated list of expressions is supplied, its elements are evaluated\nfrom left to right and placed into the list object in that order.\nWhen a comprehension is supplied, the list is constructed from the\nelements resulting from the comprehension.\n', @@ -51,7 +51,7 @@ 'numbers': "\nNumeric literals\n****************\n\nThere are three types of numeric literals: integers, floating point\nnumbers, and imaginary numbers. There are no complex literals\n(complex numbers can be formed by adding a real number and an\nimaginary 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\nthe literal ``1``.\n", 'numeric-types': "\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.__truediv__(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 (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n 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.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(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 (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand's type is a subclass of the left operand's\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand's\n non-reflected method. This behavior allows subclasses to\n override their ancestors' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(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\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n 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.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n", 'objects': '\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.\n\n**CPython implementation detail:** For CPython, ``id(x)`` is the\nmemory address where ``x`` is stored.\n\nAn object\'s type determines the operations that the object supports\n(e.g., "does it have a length?") and also defines the possible values\nfor objects of that type. The ``type()`` function returns an object\'s\ntype (which is an object itself). Like its identity, an object\'s\n*type* is also unchangeable. [1]\n\nThe *value* of some objects can change. Objects whose value can\nchange are said to be *mutable*; objects whose value is unchangeable\nonce they are created are called *immutable*. (The value of an\nimmutable container object that contains a reference to a mutable\nobject can change when the latter\'s value is changed; however the\ncontainer 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 and the \'``with``\' statement provide\nconvenient ways 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 =\n1``, ``a`` and ``b`` may or may not refer to the same object with the\nvalue one, depending on the implementation, but after ``c = []; d =\n[]``, ``c`` and ``d`` are guaranteed to refer to two different,\nunique, newly created empty lists. (Note that ``c = d = []`` assigns\nthe same object to both ``c`` and ``d``.)\n', - 'operator-summary': '\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\nfrom 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| | [5] |\n+-------------------------------------------------+---------------------------------------+\n| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |\n+-------------------------------------------------+---------------------------------------+\n| ``**`` | Exponentiation [6] |\n+-------------------------------------------------+---------------------------------------+\n| ``x[index]``, ``x[index:index]``, | Subscription, slicing, call, |\n| ``x(arguments...)``, ``x.attribute`` | attribute reference |\n+-------------------------------------------------+---------------------------------------+\n| ``(expressions...)``, ``[expressions...]``, | Binding or tuple display, list |\n| ``{key: value...}``, ``{expressions...}`` | display, dictionary display, set |\n| | display |\n+-------------------------------------------------+---------------------------------------+\n\n-[ Footnotes ]-\n\n[1] While ``abs(x%y) < abs(y)`` is true mathematically, for floats it\n 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``,\n which is numerically exactly equal to ``1e100``. The function\n ``math.fmod()`` returns a result whose sign matches the sign of\n the first argument instead, and so returns ``-1e-100`` in this\n case. Which approach is more appropriate depends on the\n application.\n\n[2] If x is very close to an exact integer multiple of y, it\'s\n possible for ``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\n close to ``x``.\n\n[3] While comparisons between strings make sense at the byte level,\n they may be counter-intuitive to users. For example, the strings\n ``"\\u00C7"`` and ``"\\u0327\\u0043"`` compare differently, even\n 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[4] Due to automatic garbage-collection, free lists, and the dynamic\n nature of descriptors, you may notice seemingly unusual behaviour\n in certain uses of the ``is`` operator, like those involving\n comparisons between instance methods, or constants. Check their\n documentation for more info.\n\n[5] The ``%`` operator is also used for string formatting; the same\n precedence applies.\n\n[6] The power operator ``**`` binds less tightly than an arithmetic or\n bitwise unary operator on its right, that is, ``2**-1`` is\n ``0.5``.\n', + 'operator-summary': '\nSummary\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\nfrom 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| | [5] |\n+-------------------------------------------------+---------------------------------------+\n| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |\n+-------------------------------------------------+---------------------------------------+\n| ``**`` | Exponentiation [6] |\n+-------------------------------------------------+---------------------------------------+\n| ``x[index]``, ``x[index:index]``, | Subscription, slicing, call, |\n| ``x(arguments...)``, ``x.attribute`` | attribute reference |\n+-------------------------------------------------+---------------------------------------+\n| ``(expressions...)``, ``[expressions...]``, | Binding or tuple display, list |\n| ``{key:datum...}``, ``{expressions...}`` | display, dictionary display, set |\n| | display |\n+-------------------------------------------------+---------------------------------------+\n\n-[ Footnotes ]-\n\n[1] While ``abs(x%y) < abs(y)`` is true mathematically, for floats it\n 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``,\n which is numerically exactly equal to ``1e100``. The function\n ``math.fmod()`` returns a result whose sign matches the sign of\n the first argument instead, and so returns ``-1e-100`` in this\n case. Which approach is more appropriate depends on the\n application.\n\n[2] If x is very close to an exact integer multiple of y, it\'s\n possible for ``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\n close to ``x``.\n\n[3] While comparisons between strings make sense at the byte level,\n they may be counter-intuitive to users. For example, the strings\n ``"\\u00C7"`` and ``"\\u0327\\u0043"`` compare differently, even\n 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[4] Due to automatic garbage-collection, free lists, and the dynamic\n nature of descriptors, you may notice seemingly unusual behaviour\n in certain uses of the ``is`` operator, like those involving\n comparisons between instance methods, or constants. Check their\n documentation for more info.\n\n[5] The ``%`` operator is also used for string formatting; the same\n precedence applies.\n\n[6] The power operator ``**`` binds less tightly than an arithmetic or\n bitwise unary operator on its right, that is, ``2**-1`` is\n ``0.5``.\n', 'pass': '\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': '\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, and the result is of that type.\n\nFor int operands, the result has the same type as the operands unless\nthe second argument is negative; in that case, all arguments are\nconverted to float and a float result is delivered. For example,\n``10**2`` returns ``100``, but ``10**-2`` returns ``0.01``.\n\nRaising ``0.0`` to a negative power results in a\n``ZeroDivisionError``. Raising a negative number to a fractional power\nresults in a ``complex`` number. (In earlier versions it raised a\n``ValueError``.)\n', 'raise': '\nThe ``raise`` statement\n***********************\n\n raise_stmt ::= "raise" [expression ["from" 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 ``RuntimeError`` exception is raised indicating\nthat this is an error.\n\nOtherwise, ``raise`` evaluates the first expression as the exception\nobject. It must be either a subclass or an instance of\n``BaseException``. If it is a class, the exception instance will be\nobtained when needed by instantiating the class with no arguments.\n\nThe *type* of the exception is the exception instance\'s class, the\n*value* is the instance itself.\n\nA traceback object is normally created automatically when an exception\nis raised and attached to it as the ``__traceback__`` attribute, which\nis writable. You can create an exception and set your own traceback in\none step using the ``with_traceback()`` exception method (which\nreturns the same exception instance, with its traceback set to its\nargument), like so:\n\n raise Exception("foo occurred").with_traceback(tracebackobj)\n\nThe ``from`` clause is used for exception chaining: if given, the\nsecond *expression* must be another exception class or instance, which\nwill then be attached to the raised exception as the ``__cause__``\nattribute (which is writable). If the raised exception is not\nhandled, both exceptions will be printed:\n\n >>> try:\n ... print(1 / 0)\n ... except Exception as exc:\n ... raise RuntimeError("Something bad happened") from exc\n ...\n Traceback (most recent call last):\n File "", line 2, in \n ZeroDivisionError: int division or modulo by zero\n\n The above exception was the direct cause of the following exception:\n\n Traceback (most recent call last):\n File "", line 4, in \n RuntimeError: Something bad happened\n\nA similar mechanism works implicitly if an exception is raised inside\nan exception handler: the previous exception is then attached as the\nnew exception\'s ``__context__`` attribute:\n\n >>> try:\n ... print(1 / 0)\n ... except:\n ... raise RuntimeError("Something bad happened")\n ...\n Traceback (most recent call last):\n File "", line 2, in \n ZeroDivisionError: int division or modulo by zero\n\n During handling of the above exception, another exception occurred:\n\n Traceback (most recent call last):\n File "", line 4, in \n RuntimeError: Something bad happened\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information about handling exceptions is in section\n*The try statement*.\n', @@ -60,18 +60,18 @@ 'shifting': '\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 integers as arguments. 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)``.\n\nNote: In the current implementation, the right-hand operand is required to\n be at most ``sys.maxsize``. If the right-hand operand is larger\n than ``sys.maxsize`` an ``OverflowError`` exception is raised.\n', 'slicings': '\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\nslicing:\n\n slicing ::= primary "[" slice_list "]"\n slice_list ::= slice_item ("," slice_item)* [","]\n slice_item ::= expression | proper_slice\n proper_slice ::= [lower_bound] ":" [upper_bound] [ ":" [stride] ]\n lower_bound ::= expression\n upper_bound ::= expression\n stride ::= expression\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).\n\nThe semantics for a slicing are as follows. The primary must evaluate\nto a mapping object, and it is indexed (using the same\n``__getitem__()`` method as normal subscription) with a key that is\nconstructed 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 a proper slice is a\nslice object (see section *The standard type hierarchy*) whose\n``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': '\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\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\nclass.__name__\n\n The name of the class or type.\n\nclass.__qualname__\n\n The *qualified name* of the class or type.\n\n New in version 3.3.\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 class keeps a list of weak references to its immediate\n subclasses. This method returns a list of all those references\n still alive. Example:\n\n >>> int.__subclasses__()\n []\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found in\n 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 being\n one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt"\n (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n', - 'specialnames': '\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\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``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\n an 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 when the instance is created. 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,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``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,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__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\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled 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.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n 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 ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n 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\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n 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 ``str(object)`` and the built-in functions ``format()``\n and ``print()`` to compute the "informal" or nicely printable\n string representation of an object. The return value must be a\n *string* object.\n\n This method differs from ``object.__repr__()`` in that there is no\n expectation that ``__str__()`` return a valid Python expression: a\n more convenient or concise representation can be used.\n\n The default implementation defined by the built-in type ``object``\n calls ``object.__repr__()``.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``str.format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a 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 These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n 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\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and 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\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n 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.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n A class that overrides ``__eq__()`` and does not define\n ``__hash__()`` will have its ``__hash__()`` implicitly set to\n ``None``. When the ``__hash__()`` method of a class is ``None``,\n instances of the class will raise an appropriate ``TypeError`` when\n a program attempts to retrieve their hash value, and will also be\n correctly identified as unhashable when checking ``isinstance(obj,\n collections.Hashable``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``.\n\n If a class that does not override ``__eq__()`` wishes to suppress\n hash support, it should include ``__hash__ = None`` in the class\n definition. A class which defines its own ``__hash__()`` that\n explicitly raises a ``TypeError`` would be incorrectly identified\n as hashable by an ``isinstance(obj, collections.Hashable)`` call.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\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``)\nfor class 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.\n This method should return the (computed) attribute value or raise\n an ``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\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not 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 over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\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 call the base class method with the same name, for example,\n ``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\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\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\n ``AttributeError`` 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,\nit is 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.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the 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 an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``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\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the 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__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented 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 classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__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 class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\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* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a 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 instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n 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 ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n 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\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\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\nin order 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\n in 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``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through 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\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\nNote: Slicing is done exclusively with the following three methods. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n 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.__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__()``\n 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 ``keys()``.\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\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\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\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\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.__truediv__(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 (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n 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.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(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 (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(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\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n 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.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\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 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \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\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen 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 "", line 1, in \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, 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\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n 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\n not supported, which is why the reflected method is not called.\n', - 'string-methods': '\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see ``str.format()``,\n*Format String Syntax* and *String Formatting*) and the other based on\nC ``printf`` style formatting that handles a narrower range of types\nand is slightly harder to use correctly, but is often faster for the\ncases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the ``re`` module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\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\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.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n 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 Changed in version 3.1: 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\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n 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\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\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. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\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. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\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. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\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\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\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. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\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\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\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the 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\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\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\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\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\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*\n is 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\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\nstr.rsplit(sep=None, maxsplit=-1)\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\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\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\nstr.split(sep=None, maxsplit=-1)\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*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an 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\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 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 For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n\', \'de fg\\r\',\n \'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\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\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\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\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\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an 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\n be ``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 The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\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', - 'strings': '\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= \n longstringchar ::= \n stringescapeseq ::= "\\" \n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= \n longbyteschar ::= \n bytesescapeseq ::= "\\" \n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the ``stringprefix`` or\n``bytesprefix`` and the rest of the literal. The source character set\nis defined by the encoding declaration; it is UTF-8 if no encoding\ndeclaration is given in the source file; see section *Encoding\ndeclarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes (``\'``) or double quotes (``"``). They can also be\nenclosed in matching groups of three single or double quotes (these\nare generally referred to as *triple-quoted strings*). The backslash\n(``\\``) character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with ``\'b\'`` or ``\'B\'``; they\nproduce an instance of the ``bytes`` type instead of the ``str`` type.\nThey may only contain ASCII characters; bytes with a numeric value of\n128 or greater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix unicode strings with a\n``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter ``\'r\'`` or ``\'R\'``; such strings are called *raw strings* and\ntreat backslashes as literal characters. As a result, in string\nliterals, ``\'\\U\'`` and ``\'\\u\'`` escapes in raw strings are not treated\nspecially. Given that Python 2.x\'s raw unicode literals behave\ndifferently than Python 3.x\'s the ``\'ur\'`` syntax is not supported.\n\n New in version 3.3: The ``\'rb\'`` prefix of raw bytes literals has\n been added as a synonym of ``\'br\'``.\n\n New in version 3.3: Support for the unicode legacy literal\n (``u\'value\'``) was reintroduced to simplify the maintenance of dual\n Python 2.x and 3.x codebases. See **PEP 414** for more information.\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`` | Backslash and 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| ``\\r`` | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| ``\\t`` | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| ``\\v`` | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| ``\\ooo`` | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| ``\\xhh`` | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\N{name}`` | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the byte\n with the given value. In a string literal, these escapes denote a\n Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Exactly four hex digits are\n required.\n\n6. Any Unicode character can be encoded this way. Exactly eight hex\n digits are required.\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 only recognized in string\nliterals fall into the category of unrecognized escapes for bytes\nliterals.\n\nEven in a raw string, string quotes can be escaped with a backslash,\nbut the backslash remains in the string; for example, ``r"\\""`` is a\nvalid string literal consisting of two characters: a backslash and a\ndouble quote; ``r"\\"`` is not a valid string literal (even a raw\nstring cannot end in an odd number of backslashes). Specifically, *a\nraw string cannot end in a single backslash* (since the backslash\nwould escape the following quote character). Note also that a single\nbackslash followed by a newline is interpreted as those two characters\nas part of the string, *not* as a line continuation.\n', + 'specialnames': '\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\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``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\n an 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 when the instance is created. 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,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``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,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__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\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled 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.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n 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 ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n 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\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n 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 function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to 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.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a 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 These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n 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\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and 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\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n 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.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\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``)\nfor class 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.\n This method should return the (computed) attribute value or raise\n an ``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\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not 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 over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\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 call the base class method with the same name, for example,\n ``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\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\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\n ``AttributeError`` 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,\nit is 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.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the 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 an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``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\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the 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__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented 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 classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__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 class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\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* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a 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 instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n 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 ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n 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\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\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\nin order 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\n in 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``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through 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\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\nNote: Slicing is done exclusively with the following three methods. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n 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.__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__()``\n 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 ``keys()``.\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\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\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\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\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.__truediv__(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 (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n 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.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(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 (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(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\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n 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.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\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 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \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\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen 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 "", line 1, in \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, 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\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n 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\n not supported, which is why the reflected method is not called.\n', + 'string-methods': '\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see ``str.format()``,\n*Format String Syntax* and *String Formatting*) and the other based on\nC ``printf`` style formatting that handles a narrower range of types\nand is slightly harder to use correctly, but is often faster for the\ncases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the ``re`` module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\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\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.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n 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 Changed in version 3.1: 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\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n 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\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\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. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\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. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\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. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\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\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\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. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\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\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\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the 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\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\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\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\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\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*\n is 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\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\nstr.rsplit(sep=None, maxsplit=-1)\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\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\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\nstr.split(sep=None, maxsplit=-1)\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*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an 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\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 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 For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n\', \'de fg\\r\',\n \'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\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\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\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\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\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an 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\n be ``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 The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\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', + 'strings': '\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= \n longstringchar ::= \n stringescapeseq ::= "\\" \n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= \n longbyteschar ::= \n bytesescapeseq ::= "\\" \n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the ``stringprefix`` or\n``bytesprefix`` and the rest of the literal. The source character set\nis defined by the encoding declaration; it is UTF-8 if no encoding\ndeclaration is given in the source file; see section *Encoding\ndeclarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes (``\'``) or double quotes (``"``). They can also be\nenclosed in matching groups of three single or double quotes (these\nare generally referred to as *triple-quoted strings*). The backslash\n(``\\``) character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with ``\'b\'`` or ``\'B\'``; they\nproduce an instance of the ``bytes`` type instead of the ``str`` type.\nThey may only contain ASCII characters; bytes with a numeric value of\n128 or greater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix unicode strings with a\n``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter ``\'r\'`` or ``\'R\'``; such strings are called *raw strings* and\ntreat backslashes as literal characters. As a result, in string\nliterals, ``\'\\U\'`` and ``\'\\u\'`` escapes in raw strings are not treated\nspecially. Given that Python 2.x\'s raw unicode literals behave\ndifferently than Python 3.x\'s the ``\'ur\'`` syntax is not supported.\n\n New in version 3.3: The ``\'rb\'`` prefix of raw bytes literals has\n been added as a synonym of ``\'br\'``.\n\n New in version 3.3: Support for the unicode legacy literal\n (``u\'value\'``) was reintroduced to simplify the maintenance of dual\n Python 2.x and 3.x codebases. See **PEP 414** for more information.\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`` | Backslash and 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| ``\\r`` | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| ``\\t`` | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| ``\\v`` | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| ``\\ooo`` | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| ``\\xhh`` | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\N{name}`` | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the byte\n with the given value. In a string literal, these escapes denote a\n Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Exactly four hex digits are\n required.\n\n6. 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). Exactly eight hex digits are required.\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 only recognized in string\nliterals fall into the category of unrecognized escapes for bytes\nliterals.\n\nEven in a raw string, string quotes can be escaped with a backslash,\nbut the backslash remains in the string; for example, ``r"\\""`` is a\nvalid string literal consisting of two characters: a backslash and a\ndouble quote; ``r"\\"`` is not a valid string literal (even a raw\nstring cannot end in an odd number of backslashes). Specifically, *a\nraw string cannot end in a single backslash* (since the backslash\nwould escape the following quote character). Note also that a single\nbackslash followed by a newline is interpreted as those two characters\nas part of the string, *not* as a line continuation.\n', 'subscriptions': '\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 that supports subscription,\ne.g. a list or dictionary. User-defined objects can support\nsubscription by defining a ``__getitem__()`` method.\n\nFor built-in objects, there are two types of objects that support\nsubscription:\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\nan integer or a slice (as discussed in the following section).\n\nThe formal syntax makes no special provision for negative indices in\nsequences; however, built-in sequences all provide a ``__getitem__()``\nmethod that interprets negative indices by adding the length of the\nsequence to the index (so that ``x[-1]`` selects the last item of\n``x``). The resulting value must be a nonnegative integer less than\nthe number of items in the sequence, and the subscription selects the\nitem whose index is that value (counting from zero). Since the support\nfor negative indices and slicing occurs in the object\'s\n``__getitem__()`` method, subclasses overriding this method will need\nto explicitly add that support.\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', 'truth': "\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``, ``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 ``__bool__()`` 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,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", - 'try': '\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" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\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\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that 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\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception it is re-raised at the end of\nthe ``finally`` clause. If the ``finally`` clause raises another\nexception, the saved exception is set as the context of the new\nexception. If the ``finally`` clause executes a ``return`` or\n``break`` statement, the saved exception is discarded:\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\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', - 'types': '\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.), although such additions\nwill often be provided via the standard library instead.\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``.\n It is used to signify the absence of a value in many situations,\n e.g., 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 literal ``...`` or the\n built-in name ``Ellipsis``. 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 two types of integers:\n\n Integers (``int``)\n\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 (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, 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.\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 is\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`` (``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\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is 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*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *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 A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\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 Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'``) and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\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\n a mutable sequence type, as does the ``collections`` module.\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\n immutable and *hashable*, it can be used again as an element of\n another 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\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``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\n ``1.0``) 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.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\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__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\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 | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | 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__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\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 Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\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 or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__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 ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n 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 ``iterator__next__()`` method will cause the\n function to execute until it provides a value using the\n ``yield`` statement. When the function executes a ``return``\n statement or falls off the end, a ``StopIteration`` exception is\n raised and the iterator will have reached the end of the set of\n 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\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined 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 Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n 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\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\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__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n 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, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n 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\n instead 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\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\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\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n 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\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of 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\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string 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_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n 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 the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if 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 slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\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', + 'try': '\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" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\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\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that 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\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception or ``break`` statement, it is\nre-raised at the end of the ``finally`` clause. If the ``finally``\nclause raises another exception the saved exception is set as the\ncontext of the new exception; if the ``finally`` clause executes a\n``return`` statement, the saved exception is discarded:\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\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', + 'types': '\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.), although such additions\nwill often be provided via the standard library instead.\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``.\n It is used to signify the absence of a value in many situations,\n e.g., 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 literal ``...`` or the\n built-in name ``Ellipsis``. 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 two types of integers:\n\n Integers (``int``)\n\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 (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, 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.\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 is\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`` (``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\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is 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*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *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 A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\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 Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'`` and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\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\n a mutable sequence type, as does the ``collections`` module.\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\n immutable and *hashable*, it can be used again as an element of\n another 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\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``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\n ``1.0``) 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.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\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__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\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 | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | 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__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\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 Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\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 or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__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 ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n 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\n the end, a ``StopIteration`` exception is raised and the\n iterator will have reached the end of the set of values to be\n 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\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined 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 Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n 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\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\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__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n 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, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n 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\n instead 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\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\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\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n 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\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of 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\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string 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_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n 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 the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if 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 slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\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': '\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': '\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``\nmodule.)\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\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict(**kwarg)\nclass class dict(mapping, **kwarg)\nclass 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 *iterator*\n object. Each item in the iterable must itself be an iterator 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 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__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n 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 See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\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\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\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 classmethod 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 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``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\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 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 values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` 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\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n 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,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` 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\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.abc.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\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 >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', - 'typesmethods': '\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as ``append()`` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\n\nIf you access a method (a function defined in a class namespace)\nthrough an instance, you get a special object: a *bound method* (also\ncalled *instance method*) object. When called, it will add the\n``self`` argument to the argument list. Bound methods have two\nspecial read-only attributes: ``m.__self__`` is the object on which\nthe method operates, and ``m.__func__`` is the function implementing\nthe method. Calling ``m(arg-1, arg-2, ..., arg-n)`` is completely\nequivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,\narg-n)``.\n\nLike function objects, bound method objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object (``meth.__func__``), setting method\nattributes on bound methods is disallowed. Attempting to set an\nattribute on a method results in an ``AttributeError`` being raised.\nIn order to set a method attribute, you need to explicitly set it on\nthe 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 "", line 1, in \n AttributeError: \'method\' object has no attribute \'whoami\'\n >>> c.method.__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', + 'typesmapping': '\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``\nmodule.)\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\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict([arg])\n\n Return a new dictionary initialized from an optional positional\n argument or from a set of keyword arguments. If no arguments are\n given, return a new empty dictionary. If the positional argument\n *arg* is a mapping object, return a dictionary mapping the same\n keys to the same values as does the mapping object. Otherwise the\n positional argument must be a sequence, a container that supports\n iteration, or an iterator object. The elements of the argument\n must each also be of one of those kinds, and each must in turn\n contain exactly two objects. The first is used as a key in the new\n dictionary, and the second as the key\'s value. If a given key is\n seen more than once, the last value associated with it is retained\n in the new dictionary.\n\n If keyword arguments are given, the keywords themselves with their\n associated values are added as items to the dictionary. If a key\n is specified both in the positional argument and as a keyword\n argument, the value associated with the keyword is retained in the\n dictionary. For example, these all return a dictionary equal to\n ``{"one": 1, "two": 2}``:\n\n * ``dict(one=1, two=2)``\n\n * ``dict({\'one\': 1, \'two\': 2})``\n\n * ``dict(zip((\'one\', \'two\'), (1, 2)))``\n\n * ``dict([[\'two\', 2], [\'one\', 1]])``\n\n The first example only works for keys that are valid Python\n identifiers; the others work with any valid keys.\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__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n 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 See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\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\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\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 classmethod 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 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``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\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 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 values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` 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\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n 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,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` 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\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.abc.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\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 >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', + 'typesmethods': "\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as ``append()`` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\n\nIf you access a method (a function defined in a class namespace)\nthrough an instance, you get a special object: a *bound method* (also\ncalled *instance method*) object. When called, it will add the\n``self`` argument to the argument list. Bound methods have two\nspecial read-only attributes: ``m.__self__`` is the object on which\nthe method operates, and ``m.__func__`` is the function implementing\nthe method. Calling ``m(arg-1, arg-2, ..., arg-n)`` is completely\nequivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,\narg-n)``.\n\nLike function objects, bound method objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object (``meth.__func__``), setting method\nattributes on bound methods is disallowed. Attempting to set a method\nattribute results in a ``TypeError`` being raised. In order to set a\nmethod attribute, you need to explicitly set it on the underlying\nfunction object:\n\n class C:\n def method(self):\n pass\n\n c = C()\n c.method.__func__.whoami = 'my name is c'\n\nSee *The standard type hierarchy* for more information.\n", 'typesmodules': "\nModules\n*******\n\nThe only special operation on a module is attribute access:\n``m.name``, where *m* is a module and *name* accesses a name defined\nin *m*'s symbol table. Module attributes can be assigned to. (Note\nthat the ``import`` statement is not, strictly speaking, an operation\non a module object; ``import foo`` does not require a module object\nnamed *foo* to exist, rather it requires an (external) *definition*\nfor a module named *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\nwrite ``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but\nyou can't write ``m.__dict__ = {}``). Modifying ``__dict__`` directly\nis not recommended.\n\nModules built into the interpreter are written like this: ````. If loaded from a file, they are written as\n````.\n", - 'typesseq': '\nSequence Types --- ``list``, ``tuple``, ``range``\n*************************************************\n\nThere are three basic sequence types: lists, tuples, and range\nobjects. Additional sequence types tailored for processing of *binary\ndata* and *text strings* are described in dedicated sections.\n\n\nCommon Sequence Operations\n==========================\n\nThe operations in the following table are supported by most sequence\ntypes, both mutable and immutable. The ``collections.abc.Sequence``\nABC is provided to make it easier to correctly implement these\noperations on custom sequence types.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type, *n*, *i*, *j* and *k* are\nintegers and *x* is an arbitrary object that meets any type and value\nrestrictions imposed by *s*.\n\nThe ``in`` and ``not in`` operations have the same priorities as the\ncomparison operations. The ``+`` (concatenation) and ``*``\n(repetition) operations have the same priority as the corresponding\nnumeric operations.\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)(7) |\n+----------------------------+----------------------------------+------------+\n| ``s * n`` or ``n * s`` | *n* shallow copies of *s* | (2)(7) |\n| | concatenated | |\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[, i[, j]])`` | index of the first occurence of | (8) |\n| | *x* in *s* (at or after index | |\n| | *i* and before index *j*) | |\n+----------------------------+----------------------------------+------------+\n| ``s.count(x)`` | total number of occurences of | |\n| | *x* in *s* | |\n+----------------------------+----------------------------------+------------+\n\nSequences of the same type also support comparisons. In particular,\ntuples and lists are compared lexicographically by comparing\ncorresponding elements. This means that to compare equal, every\nelement must compare equal and the two sequences must be of the same\ntype and have the same length. (For full details see *Comparisons* in\nthe language reference.)\n\nNotes:\n\n1. While the ``in`` and ``not in`` operations are used only for simple\n containment testing in the general case, some specialised sequences\n (such as ``str``, ``bytes`` and ``bytearray``) also use them for\n subsequence testing:\n\n >>> "gg" in "eggs"\n True\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 also that the copies\n are shallow; nested structures are not copied. This often haunts\n 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 (pointers\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\n3. If *i* or *j* is negative, the index is relative to the end of the\n 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\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n 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``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable sequences always results in a new object.\n This means that building up a sequence by repeated concatenation\n will have a quadratic runtime cost in the total sequence length.\n To get a linear runtime cost, you must switch to one of the\n alternatives below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end or else write to a ``io.StringIO``\n instance and retrieve its value when complete\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()`` or ``io.BytesIO``, or you can do in-place\n concatenation with a ``bytearray`` object. ``bytearray`` objects\n are mutable and have an efficient overallocation mechanism\n\n * if concatenating ``tuple`` objects, extend a ``list`` instead\n\n * for other types, investigate the relevant class documentation\n\n7. Some sequence types (such as ``range``) only support item sequences\n that follow specific patterns, and hence don\'t support sequence\n concatenation or repetition.\n\n8. ``index`` raises ``ValueError`` when *x* is not found in *s*. When\n supported, the additional arguments to the index method allow\n efficient searching of subsections of the sequence. Passing the\n extra arguments is roughly equivalent to using ``s[i:j].index(x)``,\n only without copying any data and with the returned index being\n relative to the start of the sequence rather than the start of the\n slice.\n\n\nImmutable Sequence Types\n========================\n\nThe only operation that immutable sequence types generally implement\nthat is not also implemented by mutable sequence types is support for\nthe ``hash()`` built-in.\n\nThis support allows immutable sequences, such as ``tuple`` instances,\nto be used as ``dict`` keys and stored in ``set`` and ``frozenset``\ninstances.\n\nAttempting to hash an immutable sequence that contains unhashable\nvalues will result in ``TypeError``.\n\n\nMutable Sequence Types\n======================\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\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)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don\'t support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nLists\n=====\n\nLists are mutable sequences, typically used to store collections of\nhomogeneous items (where the precise degree of similarity will vary by\napplication).\n\nclass class list([iterable])\n\n Lists may be constructed in several ways:\n\n * Using a pair of square brackets to denote the empty list: ``[]``\n\n * Using square brackets, separating items with commas: ``[a]``,\n ``[a, b, c]``\n\n * Using a list comprehension: ``[x for x in iterable]``\n\n * Using the type constructor: ``list()`` or ``list(iterable)``\n\n The constructor builds a list whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a list, a copy is made and\n returned, similar to ``iterable[:]``. For example, ``list(\'abc\')``\n returns ``[\'a\', \'b\', \'c\']`` and ``list( (1, 2, 3) )`` returns ``[1,\n 2, 3]``. If no argument is given, the constructor creates a new\n empty list, ``[]``.\n\n Many other operations also produce lists, including the\n ``sorted()`` built-in.\n\n Lists implement all of the *common* and *mutable* sequence\n operations. Lists also provide the following additional method:\n\n sort(*, key=None, reverse=None)\n\n This method sorts the list in place, using only ``<``\n comparisons between items. Exceptions are not suppressed - if\n any comparison operations fail, the entire sort operation will\n fail (and the list will likely be left in a partially modified\n state).\n\n *key* specifies a function of one argument that is used to\n extract a comparison key from each list element (for example,\n ``key=str.lower``). The key corresponding to each item in the\n list is calculated once and then used for the entire sorting\n process. The default value of ``None`` means that list items are\n sorted directly without calculating a separate key value.\n\n The ``functools.cmp_to_key()`` utility is available to convert a\n 2.x style *cmp* function to a *key* function.\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 This method modifies the sequence in place for economy of space\n when sorting a large sequence. To remind users that it operates\n by side effect, it does not return the sorted sequence (use\n ``sorted()`` to explicitly request a new sorted list instance).\n\n The ``sort()`` method is guaranteed to be stable. A sort is\n stable if it guarantees not to change the relative order of\n elements that compare equal --- this is helpful for sorting in\n multiple passes (for example, sort by department, then by salary\n grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can\n detect that the list has been mutated during a sort.\n\n\nTuples\n======\n\nTuples are immutable sequences, typically used to store collections of\nheterogeneous data (such as the 2-tuples produced by the\n``enumerate()`` built-in). Tuples are also used for cases where an\nimmutable sequence of homogeneous data is needed (such as allowing\nstorage in a ``set`` or ``dict`` instance).\n\nclass class tuple([iterable])\n\n Tuples may be constructed in a number of ways:\n\n * Using a pair of parentheses to denote the empty tuple: ``()``\n\n * Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)``\n\n * Separating items with commas: ``a, b, c`` or ``(a, b, c)``\n\n * Using the ``tuple()`` built-in: ``tuple()`` or\n ``tuple(iterable)``\n\n The constructor builds a tuple whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a tuple, it is returned\n unchanged. For example, ``tuple(\'abc\')`` returns ``(\'a\', \'b\',\n \'c\')`` and ``tuple( [1, 2, 3] )`` returns ``(1, 2, 3)``. If no\n argument is given, the constructor creates a new empty tuple,\n ``()``.\n\n Note that it is actually the comma which makes a tuple, not the\n parentheses. The parentheses are optional, except in the empty\n tuple case, or when they are needed to avoid syntactic ambiguity.\n For example, ``f(a, b, c)`` is a function call with three\n arguments, while ``f((a, b, c))`` is a function call with a 3-tuple\n as the sole argument.\n\n Tuples implement all of the *common* sequence operations.\n\nFor heterogeneous collections of data where access by name is clearer\nthan access by index, ``collections.namedtuple()`` may be a more\nappropriate choice than a simple tuple object.\n\n\nRanges\n======\n\nThe ``range`` type represents an immutable sequence of numbers and is\ncommonly used for looping a specific number of times in ``for`` loops.\n\nclass class range(stop)\nclass class range(start, stop[, step])\n\n The arguments to the range constructor must be integers (either\n built-in ``int`` or any object that implements the ``__index__``\n special method). If the *step* argument is omitted, it defaults to\n ``1``. If the *start* argument is omitted, it defaults to ``0``. If\n *step* is zero, ``ValueError`` is raised.\n\n For a positive *step*, the contents of a range ``r`` are determined\n by the formula ``r[i] = start + step*i`` where ``i >= 0`` and\n ``r[i] < stop``.\n\n For a negative *step*, the contents of the range are still\n determined by the formula ``r[i] = start + step*i``, but the\n constraints are ``i >= 0`` and ``r[i] > stop``.\n\n A range object will be empty if ``r[0]`` does not meet the value\n constraint. Ranges do support negative indices, but these are\n interpreted as indexing from the end of the sequence determined by\n the positive indices.\n\n Ranges containing absolute values larger than ``sys.maxsize`` are\n permitted but some features (such as ``len()``) may raise\n ``OverflowError``.\n\n Range examples:\n\n >>> list(range(10))\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n >>> list(range(1, 11))\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n >>> list(range(0, 30, 5))\n [0, 5, 10, 15, 20, 25]\n >>> list(range(0, 10, 3))\n [0, 3, 6, 9]\n >>> list(range(0, -10, -1))\n [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n >>> list(range(0))\n []\n >>> list(range(1, 0))\n []\n\n Ranges implement all of the *common* sequence operations except\n concatenation and repetition (due to the fact that range objects\n can only represent sequences that follow a strict pattern and\n repetition and concatenation will usually violate that pattern).\n\nThe advantage of the ``range`` type over a regular ``list`` or\n``tuple`` is that a ``range`` object will always take the same (small)\namount of memory, no matter the size of the range it represents (as it\nonly stores the ``start``, ``stop`` and ``step`` values, calculating\nindividual items and subranges as needed).\n\nRange objects implement the ``collections.Sequence`` ABC, and provide\nfeatures such as containment tests, element index lookup, slicing and\nsupport for negative indices (see *Sequence Types --- list, tuple,\nrange*):\n\n>>> r = range(0, 20, 2)\n>>> r\nrange(0, 20, 2)\n>>> 11 in r\nFalse\n>>> 10 in r\nTrue\n>>> r.index(10)\n5\n>>> r[5]\n10\n>>> r[:5]\nrange(0, 10, 2)\n>>> r[-1]\n18\n\nTesting range objects for equality with ``==`` and ``!=`` compares\nthem as sequences. That is, two range objects are considered equal if\nthey represent the same sequence of values. (Note that two range\nobjects that compare equal might have different ``start``, ``stop``\nand ``step`` attributes, for example ``range(0) == range(2, 1, 3)`` or\n``range(0, 3, 2) == range(0, 4, 2)``.)\n\nChanged in version 3.2: Implement the Sequence ABC. Support slicing\nand negative indices. Test ``int`` objects for membership in constant\ntime instead of iterating through all items.\n\nChanged in version 3.3: Define \'==\' and \'!=\' to compare range objects\nbased on the sequence of values they define (instead of comparing\nbased on object identity).\n\nNew in version 3.3: The ``start``, ``stop`` and ``step`` attributes.\n', + 'typesseq': '\nSequence Types --- ``list``, ``tuple``, ``range``\n*************************************************\n\nThere are three basic sequence types: lists, tuples, and range\nobjects. Additional sequence types tailored for processing of *binary\ndata* and *text strings* are described in dedicated sections.\n\n\nCommon Sequence Operations\n==========================\n\nThe operations in the following table are supported by most sequence\ntypes, both mutable and immutable. The ``collections.abc.Sequence``\nABC is provided to make it easier to correctly implement these\noperations on custom sequence types.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type, *n*, *i*, *j* and *k* are\nintegers and *x* is an arbitrary object that meets any type and value\nrestrictions imposed by *s*.\n\nThe ``in`` and ``not in`` operations have the same priorities as the\ncomparison operations. The ``+`` (concatenation) and ``*``\n(repetition) operations have the same priority as the corresponding\nnumeric operations.\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)(7) |\n+----------------------------+----------------------------------+------------+\n| ``s * n`` or ``n * s`` | *n* shallow copies of *s* | (2)(7) |\n| | concatenated | |\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[, i[, j]])`` | index of the first occurence of | (8) |\n| | *x* in *s* (at or after index | |\n| | *i* and before index *j*) | |\n+----------------------------+----------------------------------+------------+\n| ``s.count(x)`` | total number of occurences of | |\n| | *x* in *s* | |\n+----------------------------+----------------------------------+------------+\n\nSequences of the same type also support comparisons. In particular,\ntuples and lists are compared lexicographically by comparing\ncorresponding elements. This means that to compare equal, every\nelement must compare equal and the two sequences must be of the same\ntype and have the same length. (For full details see *Comparisons* in\nthe language reference.)\n\nNotes:\n\n1. While the ``in`` and ``not in`` operations are used only for simple\n containment testing in the general case, some specialised sequences\n (such as ``str``, ``bytes`` and ``bytearray``) also use them for\n subsequence testing:\n\n >>> "gg" in "eggs"\n True\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 also that the copies\n are shallow; nested structures are not copied. This often haunts\n 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 (pointers\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\n3. If *i* or *j* is negative, the index is relative to the end of the\n 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\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n 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``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable sequences always results in a new object.\n This means that building up a sequence by repeated concatenation\n will have a quadratic runtime cost in the total sequence length.\n To get a linear runtime cost, you must switch to one of the\n alternatives below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end or else write to a ``io.StringIO``\n instance and retrieve its value when complete\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()`` or ``io.BytesIO``, or you can do in-place\n concatenation with a ``bytearray`` object. ``bytearray`` objects\n are mutable and have an efficient overallocation mechanism\n\n * if concatenating ``tuple`` objects, extend a ``list`` instead\n\n * for other types, investigate the relevant class documentation\n\n7. Some sequence types (such as ``range``) only support item sequences\n that follow specific patterns, and hence don\'t support sequence\n concatenation or repetition.\n\n8. ``index`` raises ``ValueError`` when *x* is not found in *s*. When\n supported, the additional arguments to the index method allow\n efficient searching of subsections of the sequence. Passing the\n extra arguments is roughly equivalent to using ``s[i:j].index(x)``,\n only without copying any data and with the returned index being\n relative to the start of the sequence rather than the start of the\n slice.\n\n\nImmutable Sequence Types\n========================\n\nThe only operation that immutable sequence types generally implement\nthat is not also implemented by mutable sequence types is support for\nthe ``hash()`` built-in.\n\nThis support allows immutable sequences, such as ``tuple`` instances,\nto be used as ``dict`` keys and stored in ``set`` and ``frozenset``\ninstances.\n\nAttempting to hash an immutable sequence that contains unhashable\nvalues will result in ``TypeError``.\n\n\nMutable Sequence Types\n======================\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\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)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don\'t support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nLists\n=====\n\nLists are mutable sequences, typically used to store collections of\nhomogeneous items (where the precise degree of similarity will vary by\napplication).\n\nclass class list([iterable])\n\n Lists may be constructed in several ways:\n\n * Using a pair of square brackets to denote the empty list: ``[]``\n\n * Using square brackets, separating items with commas: ``[a]``,\n ``[a, b, c]``\n\n * Using a list comprehension: ``[x for x in iterable]``\n\n * Using the type constructor: ``list()`` or ``list(iterable)``\n\n The constructor builds a list whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a list, a copy is made and\n returned, similar to ``iterable[:]``. For example, ``list(\'abc\')``\n returns ``[\'a\', \'b\', \'c\']`` and ``list( (1, 2, 3) )`` returns ``[1,\n 2, 3]``. If no argument is given, the constructor creates a new\n empty list, ``[]``.\n\n Many other operations also produce lists, including the\n ``sorted()`` built-in.\n\n Lists implement all of the *common* and *mutable* sequence\n operations. Lists also provide the following additional method:\n\n sort(*, key=None, reverse=None)\n\n This method sorts the list in place, using only ``<``\n comparisons between items. Exceptions are not suppressed - if\n any comparison operations fail, the entire sort operation will\n fail (and the list will likely be left in a partially modified\n state).\n\n *key* specifies a function of one argument that is used to\n extract a comparison key from each list element (for example,\n ``key=str.lower``). The key corresponding to each item in the\n list is calculated once and then used for the entire sorting\n process. The default value of ``None`` means that list items are\n sorted directly without calculating a separate key value.\n\n The ``functools.cmp_to_key()`` utility is available to convert a\n 2.x style *cmp* function to a *key* function.\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 This method modifies the sequence in place for economy of space\n when sorting a large sequence. To remind users that it operates\n by side effect, it does not return the sorted sequence (use\n ``sorted()`` to explicitly request a new sorted list instance).\n\n The ``sort()`` method is guaranteed to be stable. A sort is\n stable if it guarantees not to change the relative order of\n elements that compare equal --- this is helpful for sorting in\n multiple passes (for example, sort by department, then by salary\n grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can\n detect that the list has been mutated during a sort.\n\n\nTuples\n======\n\nTuples are immutable sequences, typically used to store collections of\nheterogeneous data (such as the 2-tuples produced by the\n``enumerate()`` built-in). Tuples are also used for cases where an\nimmutable sequence of homogeneous data is needed (such as allowing\nstorage in a ``set`` or ``dict`` instance).\n\nclass class tuple([iterable])\n\n Tuples may be constructed in a number of ways:\n\n * Using a pair of parentheses to denote the empty tuple: ``()``\n\n * Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)``\n\n * Separating items with commas: ``a, b, c`` or ``(a, b, c)``\n\n * Using the ``tuple()`` built-in: ``tuple()`` or\n ``tuple(iterable)``\n\n The constructor builds a tuple whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a tuple, it is returned\n unchanged. For example, ``tuple(\'abc\')`` returns ``(\'a\', \'b\',\n \'c\')`` and ``tuple( [1, 2, 3] )`` returns ``(1, 2, 3)``. If no\n argument is given, the constructor creates a new empty tuple,\n ``()``.\n\n Note that it is actually the comma which makes a tuple, not the\n parentheses. The parentheses are optional, except in the empty\n tuple case, or when they are needed to avoid syntactic ambiguity.\n For example, ``f(a, b, c)`` is a function call with three\n arguments, while ``f((a, b, c))`` is a function call with a 3-tuple\n as the sole argument.\n\n Tuples implement all of the *common* sequence operations.\n\nFor heterogeneous collections of data where access by name is clearer\nthan access by index, ``collections.namedtuple()`` may be a more\nappropriate choice than a simple tuple object.\n\n\nRanges\n======\n\nThe ``range`` type represents an immutable sequence of numbers and is\ncommonly used for looping a specific number of times in ``for`` loops.\n\nclass class range([start], stop[, step])\n\n The arguments to the range constructor must be integers (either\n built-in ``int`` or any object that implements the ``__index__``\n special method). If the *step* argument is omitted, it defaults to\n ``1``. If the *start* argument is omitted, it defaults to ``0``. If\n *step* is zero, ``ValueError`` is raised.\n\n For a positive *step*, the contents of a range ``r`` are determined\n by the formula ``r[i] = start + step*i`` where ``i >= 0`` and\n ``r[i] < stop``.\n\n For a negative *step*, the contents of the range are still\n determined by the formula ``r[i] = start + step*i``, but the\n constraints are ``i >= 0`` and ``r[i] > stop``.\n\n A range object will be empty if ``r[0]`` does not meant the value\n constraint. Ranges do support negative indices, but these are\n interpreted as indexing from the end of the sequence determined by\n the positive indices.\n\n Ranges containing absolute values larger than ``sys.maxsize`` are\n permitted but some features (such as ``len()``) may raise\n ``OverflowError``.\n\n Range examples:\n\n >>> list(range(10))\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n >>> list(range(1, 11))\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n >>> list(range(0, 30, 5))\n [0, 5, 10, 15, 20, 25]\n >>> list(range(0, 10, 3))\n [0, 3, 6, 9]\n >>> list(range(0, -10, -1))\n [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n >>> list(range(0))\n []\n >>> list(range(1, 0))\n []\n\n Ranges implement all of the *common* sequence operations except\n concatenation and repetition (due to the fact that range objects\n can only represent sequences that follow a strict pattern and\n repetition and concatenation will usually violate that pattern).\n\nThe advantage of the ``range`` type over a regular ``list`` or\n``tuple`` is that a ``range`` object will always take the same (small)\namount of memory, no matter the size of the range it represents (as it\nonly stores the ``start``, ``stop`` and ``step`` values, calculating\nindividual items and subranges as needed).\n\nRange objects implement the ``collections.Sequence`` ABC, and provide\nfeatures such as containment tests, element index lookup, slicing and\nsupport for negative indices (see *Sequence Types --- list, tuple,\nrange*):\n\n>>> r = range(0, 20, 2)\n>>> r\nrange(0, 20, 2)\n>>> 11 in r\nFalse\n>>> 10 in r\nTrue\n>>> r.index(10)\n5\n>>> r[5]\n10\n>>> r[:5]\nrange(0, 10, 2)\n>>> r[-1]\n18\n\nTesting range objects for equality with ``==`` and ``!=`` compares\nthem as sequences. That is, two range objects are considered equal if\nthey represent the same sequence of values. (Note that two range\nobjects that compare equal might have different ``start``, ``stop``\nand ``step`` attributes, for example ``range(0) == range(2, 1, 3)`` or\n``range(0, 3, 2) == range(0, 4, 2)``.)\n\nChanged in version 3.2: Implement the Sequence ABC. Support slicing\nand negative indices. Test ``int`` objects for membership in constant\ntime instead of iterating through all items.\n\nChanged in version 3.3: Define \'==\' and \'!=\' to compare range objects\nbased on the sequence of values they define (instead of comparing\nbased on object identity).\n\nNew in version 3.3: The ``start``, ``stop`` and ``step`` attributes.\n', 'typesseq-mutable': "\nMutable Sequence Types\n**********************\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\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)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don't support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n", 'unary': '\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\ninteger argument. The bitwise inversion of ``x`` is defined as\n``-(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': '\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\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n', diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/random.py --- a/Lib/random.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/random.py Fri Feb 01 23:12:09 2013 +0100 @@ -151,9 +151,6 @@ ## -------------------- pickle support ------------------- - # Issue 17489: Since __reduce__ was defined to fix #759889 this is no - # longer called; we leave it here because it has been here since random was - # rewritten back in 2001 and why risk breaking something. def __getstate__(self): # for pickle return self.getstate() @@ -435,25 +432,27 @@ if kappa <= 1e-6: return TWOPI * random() - s = 0.5 / kappa - r = s + _sqrt(1.0 + s * s) + a = 1.0 + _sqrt(1.0 + 4.0 * kappa * kappa) + b = (a - _sqrt(2.0 * a))/(2.0 * kappa) + r = (1.0 + b * b)/(2.0 * b) while 1: u1 = random() + z = _cos(_pi * u1) + f = (1.0 + r * z)/(r + z) + c = kappa * (r - f) - d = z / (r + z) u2 = random() - if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d): + + if u2 < c * (2.0 - c) or u2 <= c * _exp(1.0 - c): break - q = 1.0 / r - f = (q + z) / (1.0 + q * z) u3 = random() if u3 > 0.5: - theta = (mu + _acos(f)) % TWOPI + theta = (mu % TWOPI) + _acos(f) else: - theta = (mu - _acos(f)) % TWOPI + theta = (mu % TWOPI) - _acos(f) return theta diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/re.py --- a/Lib/re.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/re.py Fri Feb 01 23:12:09 2013 +0100 @@ -215,8 +215,8 @@ def purge(): "Clear the regular expression caches" - _cache.clear() - _cache_repl.clear() + _compile.cache_clear() + _compile_repl.cache_clear() def template(pattern, flags=0): "Compile a template pattern, returning a pattern object" @@ -259,18 +259,11 @@ # -------------------------------------------------------------------- # internals -_cache = {} -_cache_repl = {} - _pattern_type = type(sre_compile.compile("", 0)) -_MAXCACHE = 512 +@functools.lru_cache(maxsize=500, typed=True) def _compile(pattern, flags): # internal: compile pattern - try: - return _cache[type(pattern), pattern, flags] - except KeyError: - pass if isinstance(pattern, _pattern_type): if flags: raise ValueError( @@ -278,23 +271,12 @@ return pattern if not sre_compile.isstring(pattern): raise TypeError("first argument must be string or compiled pattern") - p = sre_compile.compile(pattern, flags) - if len(_cache) >= _MAXCACHE: - _cache.clear() - _cache[type(pattern), pattern, flags] = p - return p + return sre_compile.compile(pattern, flags) +@functools.lru_cache(maxsize=500) def _compile_repl(repl, pattern): # internal: compile replacement pattern - try: - return _cache_repl[repl, pattern] - except KeyError: - pass - p = sre_parse.parse_template(repl, pattern) - if len(_cache_repl) >= _MAXCACHE: - _cache_repl.clear() - _cache_repl[repl, pattern] = p - return p + return sre_parse.parse_template(repl, pattern) def _expand(pattern, match, template): # internal: match.expand implementation hook diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/runpy.py --- a/Lib/runpy.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/runpy.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,7 +13,7 @@ import os import sys import importlib.machinery # importlib first so we can test #15386 via -m -import types +import imp from pkgutil import read_code, get_loader, get_importer __all__ = [ @@ -24,7 +24,7 @@ """Temporarily replace a module in sys.modules with an empty namespace""" def __init__(self, mod_name): self.mod_name = mod_name - self.module = types.ModuleType(mod_name) + self.module = imp.new_module(mod_name) self._saved_module = [] def __enter__(self): @@ -223,12 +223,7 @@ run_name = "" pkg_name = run_name.rpartition(".")[0] importer = get_importer(path_name) - # Trying to avoid importing imp so as to not consume the deprecation warning. - is_NullImporter = False - if type(importer).__module__ == 'imp': - if type(importer).__name__ == 'NullImporter': - is_NullImporter = True - if isinstance(importer, type(None)) or is_NullImporter: + if isinstance(importer, (type(None), imp.NullImporter)): # Not a valid sys.path entry, so run the code directly # execfile() doesn't help as we want to allow compiled files code, mod_loader = _get_code_from_file(run_name, path_name) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sched.py --- a/Lib/sched.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sched.py Fri Feb 01 23:12:09 2013 +0100 @@ -164,4 +164,4 @@ # the actual order they would be retrieved. with self._lock: events = self._queue[:] - return list(map(heapq.heappop, [events]*len(events))) + return map(heapq.heappop, [events]*len(events)) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/shutil.py --- a/Lib/shutil.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/shutil.py Fri Feb 01 23:12:09 2013 +0100 @@ -140,13 +140,7 @@ """ - try: - names = os.listxattr(src, follow_symlinks=follow_symlinks) - except OSError as e: - if e.errno not in (errno.ENOTSUP, errno.ENODATA): - raise - return - for name in names: + for name in os.listxattr(src, follow_symlinks=follow_symlinks): try: value = os.getxattr(src, name, follow_symlinks=follow_symlinks) os.setxattr(dst, name, value, follow_symlinks=follow_symlinks) @@ -1082,19 +1076,12 @@ return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn)) - # If we're given a path with a directory part, look it up directly rather - # than referring to PATH directories. This includes checking relative to the - # current directory, e.g. ./script - if os.path.dirname(cmd): - if _access_check(cmd, mode): - return cmd - return None + # Short circuit. If we're given a full path which matches the mode + # and it exists, we're done here. + if _access_check(cmd, mode): + return cmd - if path is None: - path = os.environ.get("PATH", os.defpath) - if not path: - return None - path = path.split(os.pathsep) + path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep) if sys.platform == "win32": # The current directory takes precedence on Windows. @@ -1105,12 +1092,10 @@ pathext = os.environ.get("PATHEXT", "").split(os.pathsep) # See if the given file matches any of the expected path extensions. # This will allow us to short circuit when given "python.exe". + matches = [cmd for ext in pathext if cmd.lower().endswith(ext.lower())] # If it does match, only test that one, otherwise we have to try # others. - if any(cmd.lower().endswith(ext.lower()) for ext in pathext): - files = [cmd] - else: - files = [cmd + ext for ext in pathext] + files = [cmd] if matches else [cmd + ext.lower() for ext in pathext] else: # On other platforms you don't have things like PATHEXT to tell you # what file suffixes are executable, so just pass on cmd as-is. @@ -1118,9 +1103,9 @@ seen = set() for dir in path: - normdir = os.path.normcase(dir) - if not normdir in seen: - seen.add(normdir) + dir = os.path.normcase(dir) + if not dir in seen: + seen.add(dir) for thefile in files: name = os.path.join(dir, thefile) if _access_check(name, mode): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/site.py --- a/Lib/site.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/site.py Fri Feb 01 23:12:09 2013 +0100 @@ -58,14 +58,11 @@ because bar.pth comes alphabetically before foo.pth; and spam is omitted because it is not mentioned in either path configuration file. -The readline module is also automatically configured to enable -completion for systems that support it. This can be overriden in -sitecustomize, usercustomize or PYTHONSTARTUP. - -After these operations, an attempt is made to import a module +After these path manipulations, an attempt is made to import a module named sitecustomize, which can perform arbitrary additional site-specific customizations. If this import fails with an ImportError exception, it is silently ignored. + """ import sys @@ -149,7 +146,7 @@ and add that to known_paths, or execute it if it starts with 'import '. """ if known_paths is None: - known_paths = _init_pathinfo() + _init_pathinfo() reset = 1 else: reset = 0 @@ -353,7 +350,12 @@ # Shells like IDLE catch the SystemExit, but listen when their # stdin wrapper is closed. try: - sys.stdin.close() + fd = -1 + if hasattr(sys.stdin, "fileno"): + fd = sys.stdin.fileno() + if fd != 0: + # Don't close stdin if it wraps fd 0 + sys.stdin.close() except: pass raise SystemExit(code) @@ -382,8 +384,9 @@ for filename in self.__files: filename = os.path.join(dir, filename) try: - with open(filename, "r") as fp: - data = fp.read() + fp = open(filename, "r") + data = fp.read() + fp.close() break except OSError: pass @@ -455,48 +458,6 @@ def sethelper(): builtins.help = _Helper() -def enablerlcompleter(): - """Enable default readline configuration on interactive prompts, by - registering a sys.__interactivehook__. - - If the readline module can be imported, the hook will set the Tab key - as completion key and register ~/.python_history as history file. - This can be overriden in the sitecustomize or usercustomize module, - or in a PYTHONSTARTUP file. - """ - def register_readline(): - import atexit - try: - import readline - import rlcompleter - except ImportError: - return - - # Reading the initialization (config) file may not be enough to set a - # completion key, so we set one first and then read the file - if 'libedit' in getattr(readline, '__doc__', ''): - readline.parse_and_bind('bind ^I rl_complete') - else: - readline.parse_and_bind('tab: complete') - - try: - readline.read_init_file() - except OSError: - # An OSError here could have many causes, but the most likely one - # is that there's no .inputrc file (or .editrc file in the case of - # Mac OS X + libedit) in the expected location. In that case, we - # want to ignore the exception. - pass - - history = os.path.join(os.path.expanduser('~'), '.python_history') - try: - readline.read_history_file(history) - except IOError: - pass - atexit.register(readline.write_history_file, history) - - sys.__interactivehook__ = register_readline - def aliasmbcs(): """On Windows, some default encodings are not provided by Python, while they are always available as "mbcs" in each locale. Make @@ -616,7 +577,6 @@ setquit() setcopyright() sethelper() - enablerlcompleter() aliasmbcs() execsitecustomize() if ENABLE_USER_SITE: @@ -644,16 +604,14 @@ """ args = sys.argv[1:] if not args: - user_base = getuserbase() - user_site = getusersitepackages() print("sys.path = [") for dir in sys.path: print(" %r," % (dir,)) print("]") - print("USER_BASE: %r (%s)" % (user_base, - "exists" if os.path.isdir(user_base) else "doesn't exist")) - print("USER_SITE: %r (%s)" % (user_site, - "exists" if os.path.isdir(user_site) else "doesn't exist")) + print("USER_BASE: %r (%s)" % (USER_BASE, + "exists" if os.path.isdir(USER_BASE) else "doesn't exist")) + print("USER_SITE: %r (%s)" % (USER_SITE, + "exists" if os.path.isdir(USER_SITE) else "doesn't exist")) print("ENABLE_USER_SITE: %r" % ENABLE_USER_SITE) sys.exit(0) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/smtpd.py --- a/Lib/smtpd.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/smtpd.py Fri Feb 01 23:12:09 2013 +0100 @@ -121,9 +121,8 @@ }) max_command_size_limit = max(command_size_limits.values()) - def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT, - map=None): - asynchat.async_chat.__init__(self, conn, map=map) + def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT): + asynchat.async_chat.__init__(self, conn) self.smtp_server = server self.conn = conn self.addr = addr @@ -577,11 +576,11 @@ channel_class = SMTPChannel def __init__(self, localaddr, remoteaddr, - data_size_limit=DATA_SIZE_DEFAULT, map=None): + data_size_limit=DATA_SIZE_DEFAULT): self._localaddr = localaddr self._remoteaddr = remoteaddr self.data_size_limit = data_size_limit - asyncore.dispatcher.__init__(self, map=map) + asyncore.dispatcher.__init__(self) try: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) # try to re-use a server port if possible @@ -598,8 +597,7 @@ def handle_accepted(self, conn, addr): print('Incoming connection from %s' % repr(addr), file=DEBUGSTREAM) - channel = self.channel_class(self, conn, addr, self.data_size_limit, - self._map) + channel = self.channel_class(self, conn, addr, self.data_size_limit) # API for "doing something useful with the message" def process_message(self, peer, mailfrom, rcpttos, data): @@ -852,7 +850,8 @@ nobody = pwd.getpwnam('nobody')[2] try: os.setuid(nobody) - except PermissionError: + except OSError as e: + if e.errno != errno.EPERM: raise print('Cannot setuid "nobody"; try running with -n option.', file=sys.stderr) sys.exit(1) try: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/smtplib.py --- a/Lib/smtplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/smtplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -66,7 +66,7 @@ OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I) # Exception classes used by this module. -class SMTPException(OSError): +class SMTPException(Exception): """Base class for all exceptions raised by this module.""" class SMTPServerDisconnected(SMTPException): @@ -221,15 +221,13 @@ If specified, `host' is the name of the remote host to which to connect. If specified, `port' specifies the port to which to connect. - By default, smtplib.SMTP_PORT is used. If a host is specified the - connect method is called, and if it returns anything other than a - success code an SMTPConnectError is raised. If specified, - `local_hostname` is used as the FQDN of the local host in the HELO/EHLO - command. Otherwise, the local hostname is found using - socket.getfqdn(). The `source_address` parameter takes a 2-tuple (host, - port) for the socket to bind to as its source address before - connecting. If the host is '' and port is 0, the OS default behavior - will be used. + By default, smtplib.SMTP_PORT is used. An SMTPConnectError is raised + if the specified `host' doesn't respond correctly. If specified, + `local_hostname` is used as the FQDN of the local host. By default, + the local hostname is found using socket.getfqdn(). The + `source_address` parameter takes a 2-tuple (host, port) for the socket + to bind to as its source address before connecting. If the host is '' + and port is 0, the OS default behavior will be used. """ self.timeout = timeout @@ -753,10 +751,7 @@ esmtp_opts.append(option) (code, resp) = self.mail(from_addr, esmtp_opts) if code != 250: - if code == 421: - self.close() - else: - self.rset() + self.rset() raise SMTPSenderRefused(code, resp, from_addr) senderrs = {} if isinstance(to_addrs, str): @@ -765,19 +760,13 @@ (code, resp) = self.rcpt(each, rcpt_options) if (code != 250) and (code != 251): senderrs[each] = (code, resp) - if code == 421: - self.close() - raise SMTPRecipientsRefused(senderrs) if len(senderrs) == len(to_addrs): # the server refused all our recipients self.rset() raise SMTPRecipientsRefused(senderrs) (code, resp) = self.data(msg) if code != 250: - if code == 421: - self.close() - else: - self.rset() + self.rset() raise SMTPDataError(code, resp) #if we got here then somebody got our mail return senderrs @@ -853,17 +842,15 @@ if _have_ssl: class SMTP_SSL(SMTP): - """ This is a subclass derived from SMTP that connects over an SSL - encrypted socket (to use this class you need a socket module that was - compiled with SSL support). If host is not specified, '' (the local - host) is used. If port is omitted, the standard SMTP-over-SSL port - (465) is used. local_hostname and source_address have the same meaning - as they do in the SMTP class. keyfile and certfile are also optional - - they can contain a PEM formatted private key and certificate chain file - for the SSL connection. context also optional, can contain a - SSLContext, and is an alternative to keyfile and certfile; If it is - specified both keyfile and certfile must be None. - + """ This is a subclass derived from SMTP that connects over an SSL encrypted + socket (to use this class you need a socket module that was compiled with SSL + support). If host is not specified, '' (the local host) is used. If port is + omitted, the standard SMTP-over-SSL port (465) is used. The optional + source_address takes a two-tuple (host,port) for socket to bind to. keyfile and certfile + are also optional - they can contain a PEM formatted private key and + certificate chain file for the SSL connection. context also optional, can contain + a SSLContext, and is an alternative to keyfile and certfile; If it is specified both + keyfile and certfile must be None. """ default_port = SMTP_SSL_PORT @@ -906,11 +893,10 @@ """LMTP - Local Mail Transfer Protocol The LMTP protocol, which is very similar to ESMTP, is heavily based - on the standard SMTP client. It's common to use Unix sockets for - LMTP, so our connect() method must support that as well as a regular - host:port server. local_hostname and source_address have the same - meaning as they do in the SMTP class. To specify a Unix socket, - you must use an absolute path as the host, starting with a '/'. + on the standard SMTP client. It's common to use Unix sockets for LMTP, + so our connect() method must support that as well as a regular + host:port server. To specify a Unix socket, you must use an absolute + path as the host, starting with a '/'. Authentication is supported, using the regular SMTP mechanism. When using a Unix socket, LMTP generally don't support or require any diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sndhdr.py --- a/Lib/sndhdr.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sndhdr.py Fri Feb 01 23:12:09 2013 +0100 @@ -137,17 +137,14 @@ def test_wav(h, f): - import wave # 'RIFF' 'WAVE' 'fmt ' if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ': return None - f.seek(0) - try: - w = wave.openfp(f, 'r') - except (EOFError, wave.Error): - return None - return ('wav', w.getframerate(), w.getnchannels(), - w.getnframes(), 8*w.getsampwidth()) + style = get_short_le(h[20:22]) + nchannels = get_short_le(h[22:24]) + rate = get_long_le(h[24:28]) + sample_bits = get_short_le(h[34:36]) + return 'wav', rate, nchannels, -1, sample_bits tests.append(test_wav) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/socket.py --- a/Lib/socket.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/socket.py Fri Feb 01 23:12:09 2013 +0100 @@ -90,8 +90,8 @@ __slots__ = ["__weakref__", "_io_refs", "_closed"] - def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None): - _socket.socket.__init__(self, family, type, proto, fileno) + def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None, cloexec=None): + _socket.socket.__init__(self, family, type, proto, fileno, cloexec) self._io_refs = 0 self._closed = False @@ -103,55 +103,37 @@ self.close() def __repr__(self): - """Wrap __repr__() to reveal the real class name and socket - address(es). - """ - closed = getattr(self, '_closed', False) - s = "<%s.%s%s fd=%i, family=%i, type=%i, proto=%i" \ - % (self.__class__.__module__, - self.__class__.__name__, - " [closed]" if closed else "", - self.fileno(), - self.family, - self.type, - self.proto) - if not closed: - try: - laddr = self.getsockname() - if laddr: - s += ", laddr=%s" % str(laddr) - except error: - pass - try: - raddr = self.getpeername() - if raddr: - s += ", raddr=%s" % str(raddr) - except error: - pass - s += '>' + """Wrap __repr__() to reveal the real class name.""" + s = _socket.socket.__repr__(self) + if s.startswith(" socket object + Duplicate the socket. If cloexec is True, set the close-on-exec flag. Return a new socket object connected to the same system resource. """ - fd = dup(self.fileno()) + fd = dup(self.fileno(), cloexec=cloexec) sock = self.__class__(self.family, self.type, self.proto, fileno=fd) sock.settimeout(self.gettimeout()) return sock - def accept(self): + def accept(self, cloexec=None): """accept() -> (socket object, address info) Wait for an incoming connection. Return a new socket representing the connection, and the address of the client. For IP sockets, the address info is a pair (hostaddr, port). """ - fd, addr = self._accept() + fd, addr = self._accept(cloexec=cloexec) sock = socket(self.family, self.type, self.proto, fileno=fd) # Issue #7995: if no default timeout is set and the listening # socket had a (non-zero) timeout, force the new socket in blocking @@ -229,13 +211,14 @@ self._closed = True return super().detach() -def fromfd(fd, family, type, proto=0): +def fromfd(fd, family, type, proto=0, cloexec=None): """ fromfd(fd, family, type[, proto]) -> socket object Create a socket object from a duplicate of the given file descriptor. The remaining arguments are the same as for socket(). + If cloexec is True, set the close-on-exec flag. """ - nfd = dup(fd) + nfd = dup(fd, cloexec=cloexec) return socket(family, type, proto, nfd) if hasattr(_socket.socket, "share"): @@ -249,7 +232,7 @@ if hasattr(_socket, "socketpair"): - def socketpair(family=None, type=SOCK_STREAM, proto=0): + def socketpair(family=None, type=SOCK_STREAM, proto=0, cloexec=None): """socketpair([family[, type[, proto]]]) -> (socket object, socket object) Create a pair of socket objects from the sockets returned by the platform @@ -262,7 +245,7 @@ family = AF_UNIX except NameError: family = AF_INET - a, b = _socket.socketpair(family, type, proto) + a, b = _socket.socketpair(family, type, proto, cloexec=cloexec) a = socket(family, type, proto, a.detach()) b = socket(family, type, proto, b.detach()) return a, b diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sqlite3/dbapi2.py --- a/Lib/sqlite3/dbapi2.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sqlite3/dbapi2.py Fri Feb 01 23:12:09 2013 +0100 @@ -67,7 +67,7 @@ timepart_full = timepart.split(b".") hours, minutes, seconds = map(int, timepart_full[0].split(b":")) if len(timepart_full) == 2: - microseconds = int('{:0<6.6}'.format(timepart_full[1].decode())) + microseconds = int(timepart_full[1]) else: microseconds = 0 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sqlite3/test/dbapi.py --- a/Lib/sqlite3/test/dbapi.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sqlite3/test/dbapi.py Fri Feb 01 23:12:09 2013 +0100 @@ -28,9 +28,6 @@ except ImportError: threading = None -from test.support import TESTFN, unlink - - class ModuleTests(unittest.TestCase): def CheckAPILevel(self): self.assertEqual(sqlite.apilevel, "2.0", @@ -166,21 +163,6 @@ with self.assertRaises(AttributeError): self.cx.in_transaction = True - def CheckOpenUri(self): - if sqlite.sqlite_version_info < (3, 7, 7): - with self.assertRaises(sqlite.NotSupportedError): - sqlite.connect(':memory:', uri=True) - return - self.addCleanup(unlink, TESTFN) - with sqlite.connect(TESTFN) as cx: - cx.execute('create table test(id integer)') - with sqlite.connect('file:' + TESTFN, uri=True) as cx: - cx.execute('insert into test(id) values(0)') - with sqlite.connect('file:' + TESTFN + '?mode=ro', uri=True) as cx: - with self.assertRaises(sqlite.OperationalError): - cx.execute('insert into test(id) values(1)') - - class CursorTests(unittest.TestCase): def setUp(self): self.cx = sqlite.connect(":memory:") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sqlite3/test/hooks.py --- a/Lib/sqlite3/test/hooks.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sqlite3/test/hooks.py Fri Feb 01 23:12:09 2013 +0100 @@ -76,25 +76,6 @@ except sqlite.OperationalError as e: self.assertEqual(e.args[0].lower(), "no such collation sequence: mycoll") - def CheckCollationReturnsLargeInteger(self): - def mycoll(x, y): - # reverse order - return -((x > y) - (x < y)) * 2**32 - con = sqlite.connect(":memory:") - con.create_collation("mycoll", mycoll) - sql = """ - select x from ( - select 'a' as x - union - select 'b' as x - union - select 'c' as x - ) order by x collate mycoll - """ - result = con.execute(sql).fetchall() - self.assertEqual(result, [('c',), ('b',), ('a',)], - msg="the expected order was not returned") - def CheckCollationRegisterTwice(self): """ Register two different collation functions under the same name. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sqlite3/test/regression.py Fri Feb 01 23:12:09 2013 +0100 @@ -302,32 +302,6 @@ cur.executemany("insert into b (baz) values (?)", ((i,) for i in foo())) - def CheckConvertTimestampMicrosecondPadding(self): - """ - http://bugs.python.org/issue14720 - - The microsecond parsing of convert_timestamp() should pad with zeros, - since the microsecond string "456" actually represents "456000". - """ - - con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) - cur = con.cursor() - cur.execute("CREATE TABLE t (x TIMESTAMP)") - - # Microseconds should be 456000 - cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')") - - # Microseconds should be truncated to 123456 - cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')") - - cur.execute("SELECT * FROM t") - values = [x[0] for x in cur.fetchall()] - - self.assertEqual(values, [ - datetime.datetime(2012, 4, 4, 15, 6, 0, 456000), - datetime.datetime(2012, 4, 4, 15, 6, 0, 123456), - ]) - def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sqlite3/test/userfunctions.py --- a/Lib/sqlite3/test/userfunctions.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sqlite3/test/userfunctions.py Fri Feb 01 23:12:09 2013 +0100 @@ -375,15 +375,14 @@ val = cur.fetchone()[0] self.assertEqual(val, 60) +def authorizer_cb(action, arg1, arg2, dbname, source): + if action != sqlite.SQLITE_SELECT: + return sqlite.SQLITE_DENY + if arg2 == 'c2' or arg1 == 't2': + return sqlite.SQLITE_DENY + return sqlite.SQLITE_OK + class AuthorizerTests(unittest.TestCase): - @staticmethod - def authorizer_cb(action, arg1, arg2, dbname, source): - if action != sqlite.SQLITE_SELECT: - return sqlite.SQLITE_DENY - if arg2 == 'c2' or arg1 == 't2': - return sqlite.SQLITE_DENY - return sqlite.SQLITE_OK - def setUp(self): self.con = sqlite.connect(":memory:") self.con.executescript(""" @@ -396,12 +395,12 @@ # For our security test: self.con.execute("select c2 from t2") - self.con.set_authorizer(self.authorizer_cb) + self.con.set_authorizer(authorizer_cb) def tearDown(self): pass - def test_table_access(self): + def CheckTableAccess(self): try: self.con.execute("select * from t2") except sqlite.DatabaseError as e: @@ -410,7 +409,7 @@ return self.fail("should have raised an exception due to missing privileges") - def test_column_access(self): + def CheckColumnAccess(self): try: self.con.execute("select c2 from t1") except sqlite.DatabaseError as e: @@ -419,46 +418,11 @@ return self.fail("should have raised an exception due to missing privileges") -class AuthorizerRaiseExceptionTests(AuthorizerTests): - @staticmethod - def authorizer_cb(action, arg1, arg2, dbname, source): - if action != sqlite.SQLITE_SELECT: - raise ValueError - if arg2 == 'c2' or arg1 == 't2': - raise ValueError - return sqlite.SQLITE_OK - -class AuthorizerIllegalTypeTests(AuthorizerTests): - @staticmethod - def authorizer_cb(action, arg1, arg2, dbname, source): - if action != sqlite.SQLITE_SELECT: - return 0.0 - if arg2 == 'c2' or arg1 == 't2': - return 0.0 - return sqlite.SQLITE_OK - -class AuthorizerLargeIntegerTests(AuthorizerTests): - @staticmethod - def authorizer_cb(action, arg1, arg2, dbname, source): - if action != sqlite.SQLITE_SELECT: - return 2**32 - if arg2 == 'c2' or arg1 == 't2': - return 2**32 - return sqlite.SQLITE_OK - - def suite(): function_suite = unittest.makeSuite(FunctionTests, "Check") aggregate_suite = unittest.makeSuite(AggregateTests, "Check") - authorizer_suite = unittest.makeSuite(AuthorizerTests) - return unittest.TestSuite(( - function_suite, - aggregate_suite, - authorizer_suite, - unittest.makeSuite(AuthorizerRaiseExceptionTests), - unittest.makeSuite(AuthorizerIllegalTypeTests), - unittest.makeSuite(AuthorizerLargeIntegerTests), - )) + authorizer_suite = unittest.makeSuite(AuthorizerTests, "Check") + return unittest.TestSuite((function_suite, aggregate_suite, authorizer_suite)) def test(): runner = unittest.TextTestRunner() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sre_compile.py --- a/Lib/sre_compile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sre_compile.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,7 +13,6 @@ import _sre, sys import sre_parse from sre_constants import * -from _sre import MAXREPEAT assert _sre.MAGIC == MAGIC, "SRE module mismatch" @@ -65,6 +64,13 @@ elif op in REPEATING_CODES: if flags & SRE_FLAG_TEMPLATE: raise error("internal: unsupported template operator") + emit(OPCODES[REPEAT]) + skip = _len(code); emit(0) + emit(av[0]) + emit(av[1]) + _compile(code, av[2], flags) + emit(OPCODES[SUCCESS]) + code[skip] = _len(code) - skip elif _simple(av) and op is not REPEAT: if op is MAX_REPEAT: emit(OPCODES[REPEAT_ONE]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sre_constants.py --- a/Lib/sre_constants.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sre_constants.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,7 +15,9 @@ MAGIC = 20031017 -from _sre import MAXREPEAT +# max code word in this release + +MAXREPEAT = 65535 # SRE standard exception (access as sre.error) # should this really be here? @@ -217,7 +219,8 @@ if __name__ == "__main__": def dump(f, d, prefix): - items = sorted(d.items(), key=lambda a: a[1]) + items = d.items() + items.sort(key=lambda a: a[1]) for k, v in items: f.write("#define %s_%s %s\n" % (prefix, k.upper(), v)) f = open("sre_constants.h", "w") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sre_parse.py --- a/Lib/sre_parse.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sre_parse.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,7 +15,6 @@ import sys from sre_constants import * -from _sre import MAXREPEAT SPECIAL_CHARS = ".\\[{()*+?^$|" REPEAT_CHARS = "*+?{" @@ -225,25 +224,13 @@ def seek(self, index): self.index, self.next = index -# The following three functions are not used in this module anymore, but we keep -# them here (with DeprecationWarnings) for backwards compatibility. - def isident(char): - import warnings - warnings.warn('sre_parse.isident() will be removed in 3.5', - DeprecationWarning, stacklevel=2) return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_" def isdigit(char): - import warnings - warnings.warn('sre_parse.isdigit() will be removed in 3.5', - DeprecationWarning, stacklevel=2) return "0" <= char <= "9" def isname(name): - import warnings - warnings.warn('sre_parse.isname() will be removed in 3.5', - DeprecationWarning, stacklevel=2) # check that group name is a valid string if not isident(name[0]): return False @@ -550,14 +537,10 @@ continue if lo: min = int(lo) - if min >= MAXREPEAT: - raise OverflowError("the repetition number is too large") if hi: max = int(hi) - if max >= MAXREPEAT: - raise OverflowError("the repetition number is too large") - if max < min: - raise error("bad repeat interval") + if max < min: + raise error("bad repeat interval") else: raise error("not supported") # figure out which item to repeat @@ -599,8 +582,8 @@ group = 1 if not name: raise error("missing group name") - if not name.isidentifier(): - raise error("bad character in group name %r" % name) + if not isname(name): + raise error("bad character in group name") elif sourcematch("="): # named backreference name = "" @@ -613,9 +596,8 @@ name = name + char if not name: raise error("missing group name") - if not name.isidentifier(): - raise error("bad character in backref group name " - "%r" % name) + if not isname(name): + raise error("bad character in group name") gid = state.groupdict.get(name) if gid is None: raise error("unknown group name") @@ -668,7 +650,7 @@ group = 2 if not condname: raise error("missing group name") - if condname.isidentifier(): + if isname(condname): condgroup = state.groupdict.get(condname) if condgroup is None: raise error("unknown group name") @@ -805,7 +787,7 @@ if index < 0: raise error("negative group number") except ValueError: - if not name.isidentifier(): + if not isname(name): raise error("bad character in group name") try: index = pattern.groupindex[name] diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/ssl.py --- a/Lib/ssl.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/ssl.py Fri Feb 01 23:12:09 2013 +0100 @@ -52,8 +52,6 @@ PROTOCOL_SSLv3 PROTOCOL_SSLv23 PROTOCOL_TLSv1 -PROTOCOL_TLSv1_1 -PROTOCOL_TLSv1_2 The following constants identify various SSL alert message descriptions as per http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6 @@ -89,9 +87,6 @@ import textwrap import re -import sys -import os -import collections import _ssl # if we can't import it, let the error propagate @@ -115,7 +110,8 @@ from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN -from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1 +from _ssl import (PROTOCOL_SSLv3, PROTOCOL_SSLv23, + PROTOCOL_TLSv1) from _ssl import _OPENSSL_API_VERSION @@ -132,17 +128,6 @@ else: _PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2" -try: - from _ssl import PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2 -except ImportError: - pass -else: - _PROTOCOL_NAMES[PROTOCOL_TLSv1_1] = "TLSv1.1" - _PROTOCOL_NAMES[PROTOCOL_TLSv1_2] = "TLSv1.2" - -if sys.platform == "win32": - from _ssl import enum_cert_store, X509_ASN_ENCODING, PKCS_7_ASN_ENCODING - from socket import getnameinfo as _getnameinfo from socket import socket, AF_INET, SOCK_STREAM, create_connection import base64 # for DER-to-PEM translation @@ -166,16 +151,9 @@ pass -def _dnsname_to_pat(dn, max_wildcards=1): +def _dnsname_to_pat(dn): pats = [] for frag in dn.split(r'.'): - if frag.count('*') > max_wildcards: - # Issue #17980: avoid denials of service by refusing more - # than one wildcard per fragment. A survery of established - # policy among SSL implementations showed it to be a - # reasonable choice. - raise CertificateError( - "too many wildcards in certificate DNS name: " + repr(dn)) if frag == '*': # When '*' is a fragment by itself, it matches a non-empty dotless # fragment. @@ -228,24 +206,6 @@ "subjectAltName fields were found") -DefaultVerifyPaths = collections.namedtuple("DefaultVerifyPaths", - "cafile capath openssl_cafile_env openssl_cafile openssl_capath_env " - "openssl_capath") - -def get_default_verify_paths(): - """Return paths to default cafile and capath. - """ - parts = _ssl.get_default_verify_paths() - - # environment vars shadow paths - cafile = os.environ.get(parts[0], parts[1]) - capath = os.environ.get(parts[2], parts[3]) - - return DefaultVerifyPaths(cafile if os.path.isfile(cafile) else None, - capath if os.path.isdir(capath) else None, - *parts) - - class SSLContext(_SSLContext): """An SSLContext holds various SSL-related configuration options and data, such as certificates and possibly a private key.""" @@ -330,6 +290,7 @@ self.server_hostname = server_hostname self.do_handshake_on_connect = do_handshake_on_connect self.suppress_ragged_eofs = suppress_ragged_eofs + connected = False if sock is not None: socket.__init__(self, family=sock.family, @@ -337,22 +298,20 @@ proto=sock.proto, fileno=sock.fileno()) self.settimeout(sock.gettimeout()) + # see if it's connected + try: + sock.getpeername() + except OSError as e: + if e.errno != errno.ENOTCONN: + raise + else: + connected = True sock.detach() elif fileno is not None: socket.__init__(self, fileno=fileno) else: socket.__init__(self, family=family, type=type, proto=proto) - # See if we are connected - try: - self.getpeername() - except OSError as e: - if e.errno != errno.ENOTCONN: - raise - connected = False - else: - connected = True - self._closed = False self._sslobj = None self._connected = connected @@ -371,7 +330,6 @@ except OSError as x: self.close() raise x - @property def context(self): return self._context @@ -389,21 +347,11 @@ # raise an exception here if you wish to check for spurious closes pass - def _check_connected(self): - if not self._connected: - # getpeername() will raise ENOTCONN if the socket is really - # not connected; note that we can be connected even without - # _connected being set, e.g. if connect() first returned - # EAGAIN. - self.getpeername() - def read(self, len=0, buffer=None): """Read up to LEN bytes and return them. Return zero-length string on EOF.""" self._checkClosed() - if not self._sslobj: - raise ValueError("Read on closed or unwrapped SSL socket.") try: if buffer is not None: v = self._sslobj.read(len, buffer) @@ -424,8 +372,6 @@ number of bytes of DATA actually transmitted.""" self._checkClosed() - if not self._sslobj: - raise ValueError("Write on closed or unwrapped SSL socket.") return self._sslobj.write(data) def getpeercert(self, binary_form=False): @@ -435,7 +381,6 @@ certificate was provided, but not validated.""" self._checkClosed() - self._check_connected() return self._sslobj.peer_certificate(binary_form) def selected_npn_protocol(self): @@ -466,17 +411,18 @@ raise ValueError( "non-zero flags not allowed in calls to send() on %s" % self.__class__) - try: - v = self._sslobj.write(data) - except SSLError as x: - if x.args[0] == SSL_ERROR_WANT_READ: - return 0 - elif x.args[0] == SSL_ERROR_WANT_WRITE: - return 0 + while True: + try: + v = self._sslobj.write(data) + except SSLError as x: + if x.args[0] == SSL_ERROR_WANT_READ: + return 0 + elif x.args[0] == SSL_ERROR_WANT_WRITE: + return 0 + else: + raise else: - raise - else: - return v + return v else: return socket.send(self, data, flags) @@ -584,11 +530,12 @@ def _real_close(self): self._sslobj = None + # self._closed = True socket._real_close(self) def do_handshake(self, block=False): """Perform a TLS/SSL handshake.""" - self._check_connected() + timeout = self.gettimeout() try: if timeout == 0.0 and block: @@ -612,9 +559,9 @@ rc = None socket.connect(self, addr) if not rc: - self._connected = True if self.do_handshake_on_connect: self.do_handshake() + self._connected = True return rc except OSError: self._sslobj = None diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/stat.py --- a/Lib/stat.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/stat.py Fri Feb 01 23:12:09 2013 +0100 @@ -147,9 +147,3 @@ else: perm.append("-") return "".join(perm) - -# If available, use C implementation -try: - from _stat import * -except ImportError: - pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/struct.py --- a/Lib/struct.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/struct.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,6 @@ __all__ = [ # Functions 'calcsize', 'pack', 'pack_into', 'unpack', 'unpack_from', - 'iter_unpack', # Classes 'Struct', diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/subprocess.py --- a/Lib/subprocess.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/subprocess.py Fri Feb 01 23:12:09 2013 +0100 @@ -25,7 +25,7 @@ =========================== This module defines one class called Popen: -class Popen(args, bufsize=-1, executable=None, +class Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, @@ -56,12 +56,12 @@ way: The list2cmdline is designed for applications using the same rules as the MS C runtime. -bufsize will be supplied as the corresponding argument to the io.open() -function when creating the stdin/stdout/stderr pipe file objects: -0 means unbuffered (read & write are one system call and can return short), -1 means line buffered, any other positive value means use a buffer of -approximately that size. A negative bufsize, the default, means the system -default of io.DEFAULT_BUFFER_SIZE will be used. +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. @@ -104,16 +104,14 @@ If env is not None, it defines the environment variables for the new process. -If universal_newlines is false, the file objects stdin, stdout and stderr -are opened as binary files, and no line ending conversion is done. - 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 old Macintosh convention or '\r\n', the Windows convention. All of these external representations -are seen as '\n' by the Python program. Also, the newlines attribute -of the file objects stdout, stdin and stderr are not updated by the -communicate() method. +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 @@ -168,7 +166,7 @@ '/bin/ls' check_output(*popenargs, **kwargs): - Run command with arguments and return its output. + 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 @@ -178,9 +176,6 @@ >>> output = subprocess.check_output(["ls", "-l", "/dev/null"]) - There is an additional optional argument, "input", allowing you to - pass a string to the subprocess's stdin. If you use this argument - you may not also use the Popen constructor's "stdin" argument. Exceptions ---------- @@ -405,7 +400,6 @@ import select _has_poll = hasattr(select, 'poll') import _posixsubprocess - _create_pipe = _posixsubprocess.cloexec_pipe # When select or poll has indicated that the file is writable, # we can write up to _PIPE_BUF bytes without risk of blocking. @@ -550,7 +544,7 @@ def check_output(*popenargs, timeout=None, **kwargs): - r"""Run command with arguments and return its output. + r"""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 @@ -568,32 +562,12 @@ ... "ls -l non_existent_file ; exit 0"], ... stderr=STDOUT) b'ls: non_existent_file: No such file or directory\n' - - There is an additional optional argument, "input", allowing you to - pass a string to the subprocess's stdin. If you use this argument - you may not also use the Popen constructor's "stdin" argument, as - it too will be used internally. Example: - - >>> check_output(["sed", "-e", "s/foo/bar/"], - ... input=b"when in the course of fooman events\n") - b'when in the course of barman events\n' - - If universal_newlines=True is passed, the return value will be a - string rather than bytes. """ if 'stdout' in kwargs: raise ValueError('stdout argument not allowed, it will be overridden.') - if 'input' in kwargs: - if 'stdin' in kwargs: - raise ValueError('stdin and input arguments may not both be used.') - inputdata = kwargs['input'] - del kwargs['input'] - kwargs['stdin'] = PIPE - else: - inputdata = None with Popen(*popenargs, stdout=PIPE, **kwargs) as process: try: - output, unused_err = process.communicate(inputdata, timeout=timeout) + output, unused_err = process.communicate(timeout=timeout) except TimeoutExpired: process.kill() output, unused_err = process.communicate() @@ -732,7 +706,7 @@ class Popen(object): - def __init__(self, args, bufsize=-1, executable=None, + def __init__(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS, shell=False, cwd=None, env=None, universal_newlines=False, @@ -746,7 +720,7 @@ self._input = None self._communication_started = False if bufsize is None: - bufsize = -1 # Restore default + bufsize = 0 # Restore default if not isinstance(bufsize, int): raise TypeError("bufsize must be an integer") @@ -831,7 +805,6 @@ if universal_newlines: self.stderr = io.TextIOWrapper(self.stderr) - self._closed_child_pipe_fds = False try: self._execute_child(args, executable, preexec_fn, close_fds, pass_fds, cwd, env, @@ -848,21 +821,19 @@ except OSError: pass # Ignore EBADF or other errors. - if not self._closed_child_pipe_fds: - to_close = [] - if stdin == PIPE: - to_close.append(p2cread) - if stdout == PIPE: - to_close.append(c2pwrite) - if stderr == PIPE: - to_close.append(errwrite) - if hasattr(self, '_devnull'): - to_close.append(self._devnull) - for fd in to_close: - try: - os.close(fd) - except OSError: - pass + # Make sure the child pipes are closed as well. + to_close = [] + if stdin == PIPE: + to_close.append(p2cread) + if stdout == PIPE: + to_close.append(c2pwrite) + if stderr == PIPE: + to_close.append(errwrite) + for fd in to_close: + try: + os.close(fd) + except OSError: + pass raise @@ -1258,7 +1229,7 @@ if stdin is None: pass elif stdin == PIPE: - p2cread, p2cwrite = _create_pipe() + p2cread, p2cwrite = os.pipe(cloexec=True) elif stdin == DEVNULL: p2cread = self._get_devnull() elif isinstance(stdin, int): @@ -1270,7 +1241,7 @@ if stdout is None: pass elif stdout == PIPE: - c2pread, c2pwrite = _create_pipe() + c2pread, c2pwrite = os.pipe(cloexec=True) elif stdout == DEVNULL: c2pwrite = self._get_devnull() elif isinstance(stdout, int): @@ -1282,7 +1253,7 @@ if stderr is None: pass elif stderr == PIPE: - errread, errwrite = _create_pipe() + errread, errwrite = os.pipe(cloexec=True) elif stderr == STDOUT: errwrite = c2pwrite elif stderr == DEVNULL: @@ -1334,7 +1305,7 @@ # For transferring possible exec failure from child to parent. # Data format: "exception name:hex errno:description" # Pickle is not used; it is complex and involves memory allocation. - errpipe_read, errpipe_write = _create_pipe() + errpipe_read, errpipe_write = os.pipe(cloexec=True) try: try: # We must avoid complex work that could involve @@ -1356,6 +1327,9 @@ os.path.join(os.fsencode(dir), executable) for dir in os.get_exec_path(env)) fds_to_keep = set(pass_fds) + # Clear close-on-exec flag on kept file descriptors + for fd in fds_to_keep: + os.set_cloexec(fd, False) fds_to_keep.add(errpipe_write) self.pid = _posixsubprocess.fork_exec( args, executable_list, @@ -1369,18 +1343,14 @@ # be sure the FD is closed no matter what os.close(errpipe_write) - # self._devnull is not always defined. - devnull_fd = getattr(self, '_devnull', None) - if p2cread != -1 and p2cwrite != -1 and p2cread != devnull_fd: + if p2cread != -1 and p2cwrite != -1: os.close(p2cread) - if c2pwrite != -1 and c2pread != -1 and c2pwrite != devnull_fd: + if c2pwrite != -1 and c2pread != -1: os.close(c2pwrite) - if errwrite != -1 and errread != -1 and errwrite != devnull_fd: + if errwrite != -1 and errread != -1: os.close(errwrite) - if devnull_fd is not None: - os.close(devnull_fd) - # Prevent a double close of these fds from __init__ on error. - self._closed_child_pipe_fds = True + if hasattr(self, '_devnull'): + os.close(self._devnull) # Wait for exec to fail or succeed; possibly raising an # exception (limited in size) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/symbol.py --- a/Lib/symbol.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/symbol.py Fri Feb 01 23:12:09 2013 +0100 @@ -91,7 +91,6 @@ comp_if = 334 encoding_decl = 335 yield_expr = 336 -yield_arg = 337 #--end constants-- sym_name = {} @@ -100,12 +99,12 @@ sym_name[_value] = _name -def _main(): +def main(): import sys import token if len(sys.argv) == 1: sys.argv = sys.argv + ["Include/graminit.h", "Lib/symbol.py"] - token._main() + token.main() if __name__ == "__main__": - _main() + main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/symtable.py --- a/Lib/symtable.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/symtable.py Fri Feb 01 23:12:09 2013 +0100 @@ -235,8 +235,7 @@ if __name__ == "__main__": import os, sys - with open(sys.argv[0]) as f: - src = f.read() + src = open(sys.argv[0]).read() mod = symtable(src, os.path.split(sys.argv[0])[1], "exec") for ident in mod.get_identifiers(): info = mod.lookup(ident) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/sysconfig.py --- a/Lib/sysconfig.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/sysconfig.py Fri Feb 01 23:12:09 2013 +0100 @@ -383,8 +383,8 @@ # get_platform() succeeds. name = '_sysconfigdata' if 'darwin' in sys.platform: - import types - module = types.ModuleType(name) + import imp + module = imp.new_module(name) module.build_time_vars = vars sys.modules[name] = module @@ -416,7 +416,7 @@ vars['LIBDEST'] = get_path('stdlib') vars['BINLIBDEST'] = get_path('platstdlib') vars['INCLUDEPY'] = get_path('include') - vars['EXT_SUFFIX'] = '.pyd' + vars['SO'] = '.pyd' vars['EXE'] = '.exe' vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable)) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/tarfile.py --- a/Lib/tarfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/tarfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -2397,18 +2397,16 @@ # Fix for SF #1100429: Under rare circumstances it can # happen that getmembers() is called during iteration, # which will cause TarIter to stop prematurely. - - if self.index == 0 and self.tarfile.firstmember is not None: - tarinfo = self.tarfile.next() - elif self.index < len(self.tarfile.members): - tarinfo = self.tarfile.members[self.index] - elif not self.tarfile._loaded: + if not self.tarfile._loaded: tarinfo = self.tarfile.next() if not tarinfo: self.tarfile._loaded = True raise StopIteration else: - raise StopIteration + try: + tarinfo = self.tarfile.members[self.index] + except IndexError: + raise StopIteration self.index += 1 return tarinfo diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/tempfile.py --- a/Lib/tempfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/tempfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -31,37 +31,15 @@ import sys as _sys import io as _io import os as _os -import errno as _errno from random import Random as _Random try: - import fcntl as _fcntl -except ImportError: - def _set_cloexec(fd): - pass -else: - def _set_cloexec(fd): - try: - flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0) - except OSError: - pass - else: - # flags read successfully, modify - flags |= _fcntl.FD_CLOEXEC - _fcntl.fcntl(fd, _fcntl.F_SETFD, flags) - - -try: import _thread except ImportError: import _dummy_thread as _thread _allocate_lock = _thread.allocate_lock _text_openflags = _os.O_RDWR | _os.O_CREAT | _os.O_EXCL -if hasattr(_os, 'O_CLOEXEC'): - _text_openflags |= _os.O_CLOEXEC -if hasattr(_os, 'O_NOINHERIT'): - _text_openflags |= _os.O_NOINHERIT if hasattr(_os, 'O_NOFOLLOW'): _text_openflags |= _os.O_NOFOLLOW @@ -90,8 +68,8 @@ # Fallback. All we need is something that raises OSError if the # file doesn't exist. def _stat(fn): - f = open(fn) - f.close() + fd = _os.open(fn, _os.O_RDONLY) + os.close(fd) def _exists(fn): try: @@ -174,22 +152,17 @@ filename = _os.path.join(dir, name) try: fd = _os.open(filename, _bin_openflags, 0o600) - try: - try: - with _io.open(fd, 'wb', closefd=False) as fp: - fp.write(b'blat') - finally: - _os.close(fd) - finally: - _os.unlink(filename) + fp = _io.open(fd, 'wb') + fp.write(b'blat') + fp.close() + _os.unlink(filename) + del fp, fd return dir except FileExistsError: pass except OSError: break # no point trying more names in this directory - raise FileNotFoundError(_errno.ENOENT, - "No usable temporary directory found in %s" % - dirlist) + raise FileNotFoundError("No usable temporary directory found in %s" % dirlist) _name_sequence = None @@ -216,14 +189,12 @@ name = next(names) file = _os.path.join(dir, pre + name + suf) try: - fd = _os.open(file, flags, 0o600) - _set_cloexec(fd) + fd = _os.open(file, flags, 0o600, cloexec=True) return (fd, _os.path.abspath(file)) except FileExistsError: continue # try again - raise FileExistsError(_errno.EEXIST, - "No usable temporary file name found") + raise FileExistsError("No usable temporary file name found") # User visible interfaces. @@ -310,8 +281,7 @@ except FileExistsError: continue # try again - raise FileExistsError(_errno.EEXIST, - "No usable temporary directory name found") + raise FileExistsError("No usable temporary directory name found") def mktemp(suffix="", prefix=template, dir=None): """User-callable function to return a unique temporary file name. The @@ -340,8 +310,7 @@ if not _exists(file): return file - raise FileExistsError(_errno.EEXIST, - "No usable temporary filename found") + raise FileExistsError("No usable temporary filename found") class _TemporaryFileWrapper: @@ -481,8 +450,8 @@ raise class SpooledTemporaryFile: - """Temporary file wrapper, specialized to switch from BytesIO - or StringIO to a real file when it exceeds a certain size or + """Temporary file wrapper, specialized to switch from + StringIO to a real file when it exceeds a certain size or when a fileno is needed. """ _rolled = False @@ -548,12 +517,7 @@ @property def encoding(self): - try: - return self._file.encoding - except AttributeError: - if 'b' in self._TemporaryFileArgs['mode']: - raise - return self._TemporaryFileArgs['encoding'] + return self._file.encoding def fileno(self): self.rollover() @@ -567,26 +531,18 @@ @property def mode(self): - try: - return self._file.mode - except AttributeError: - return self._TemporaryFileArgs['mode'] + return self._file.mode @property def name(self): - try: - return self._file.name - except AttributeError: - return None + return self._file.name @property def newlines(self): - try: - return self._file.newlines - except AttributeError: - if 'b' in self._TemporaryFileArgs['mode']: - raise - return self._TemporaryFileArgs['newline'] + return self._file.newlines + + def next(self): + return self._file.next def read(self, *args): return self._file.read(*args) @@ -627,6 +583,9 @@ self._check(file) return rv + def xreadlines(self, *args): + return self._file.xreadlines(*args) + class TemporaryDirectory(object): """Create and return a temporary directory. This has the same diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/__main__.py --- a/Lib/test/__main__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/__main__.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,3 +1,13 @@ -from test import regrtest +from test import regrtest, support -regrtest.main_in_temp_cwd() + +TEMPDIR, TESTCWD = regrtest._make_temp_dir_for_build(regrtest.TEMPDIR) +regrtest.TEMPDIR = TEMPDIR +regrtest.TESTCWD = TESTCWD + +# Run the tests in a context manager that temporary changes the CWD to a +# temporary and writable directory. If it's not possible to create or +# change the CWD, the original CWD will be used. The original CWD is +# available from support.SAVEDCWD. +with support.temp_cwd(TESTCWD, quiet=True): + regrtest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/badsyntax_future10.py --- a/Lib/test/badsyntax_future10.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -from __future__ import absolute_import -"spam, bar, blah" -from __future__ import print_function diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/bytecode_helper.py --- a/Lib/test/bytecode_helper.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -"""bytecode_helper - support tools for testing correct bytecode generation""" - -import unittest -import dis -import io - -_UNSPECIFIED = object() - -class BytecodeTestCase(unittest.TestCase): - """Custom assertion methods for inspecting bytecode.""" - - def get_disassembly_as_string(self, co): - s = io.StringIO() - dis.dis(co, file=s) - return s.getvalue() - - def assertInstructionMatches(self, instr, expected, *, line_offset=0): - # Deliberately test opname first, since that gives a more - # meaningful error message than testing opcode - self.assertEqual(instr.opname, expected.opname) - self.assertEqual(instr.opcode, expected.opcode) - self.assertEqual(instr.arg, expected.arg) - self.assertEqual(instr.argval, expected.argval) - self.assertEqual(instr.argrepr, expected.argrepr) - self.assertEqual(instr.offset, expected.offset) - if expected.starts_line is None: - self.assertIsNone(instr.starts_line) - else: - self.assertEqual(instr.starts_line, - expected.starts_line + line_offset) - self.assertEqual(instr.is_jump_target, expected.is_jump_target) - - - def assertBytecodeExactlyMatches(self, x, expected, *, line_offset=0): - """Throws AssertionError if any discrepancy is found in bytecode - - *x* is the object to be introspected - *expected* is a list of dis.Instruction objects - - Set *line_offset* as appropriate to adjust for the location of the - object to be disassembled within the test file. If the expected list - assumes the first line is line 1, then an appropriate offset would be - ``1 - f.__code__.co_firstlineno``. - """ - actual = dis.get_instructions(x, line_offset=line_offset) - self.assertEqual(list(actual), expected) - - def assertInBytecode(self, x, opname, argval=_UNSPECIFIED): - """Returns instr if op is found, otherwise throws AssertionError""" - for instr in dis.get_instructions(x): - if instr.opname == opname: - if argval is _UNSPECIFIED or instr.argval == argval: - return instr - disassembly = self.get_disassembly_as_string(x) - if argval is _UNSPECIFIED: - msg = '%s not found in bytecode:\n%s' % (opname, disassembly) - else: - msg = '(%s,%r) not found in bytecode:\n%s' - msg = msg % (opname, argval, disassembly) - self.fail(msg) - - def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED): - """Throws AssertionError if op is found""" - for instr in dis.get_instructions(x): - if instr.opname == opname: - disassembly = self.get_disassembly_as_string(co) - if opargval is _UNSPECIFIED: - msg = '%s occurs in bytecode:\n%s' % (opname, disassembly) - elif instr.argval == argval: - msg = '(%s,%r) occurs in bytecode:\n%s' - msg = msg % (opname, argval, disassembly) - self.fail(msg) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/json_tests/test_decode.py --- a/Lib/test/json_tests/test_decode.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/json_tests/test_decode.py Fri Feb 01 23:12:09 2013 +0100 @@ -25,22 +25,16 @@ p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4), ("qrt", 5), ("pad", 6), ("hoy", 7)] self.assertEqual(self.loads(s), eval(s)) - self.assertEqual(self.loads(s, object_pairs_hook=lambda x: x), p) + self.assertEqual(self.loads(s, object_pairs_hook = lambda x: x), p) self.assertEqual(self.json.load(StringIO(s), object_pairs_hook=lambda x: x), p) - od = self.loads(s, object_pairs_hook=OrderedDict) + od = self.loads(s, object_pairs_hook = OrderedDict) self.assertEqual(od, OrderedDict(p)) self.assertEqual(type(od), OrderedDict) # the object_pairs_hook takes priority over the object_hook - self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict, - object_hook=lambda x: None), + self.assertEqual(self.loads(s, object_pairs_hook = OrderedDict, + object_hook = lambda x: None), OrderedDict(p)) - # check that empty objects literals work (see #17368) - self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict), - OrderedDict()) - self.assertEqual(self.loads('{"empty": {}}', - object_pairs_hook=OrderedDict), - OrderedDict([('empty', OrderedDict())])) def test_decoder_optimizations(self): # Several optimizations were made that skip over calls to diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/json_tests/test_fail.py --- a/Lib/test/json_tests/test_fail.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/json_tests/test_fail.py Fri Feb 01 23:12:09 2013 +0100 @@ -125,8 +125,8 @@ ] for data, msg, idx in test_cases: self.assertRaisesRegex(ValueError, - r'^{0}: line 1 column {1} \(char {2}\)'.format( - re.escape(msg), idx + 1, idx), + r'^{0}: line 1 column {1} \(char {1}\)'.format( + re.escape(msg), idx), self.loads, data) def test_unexpected_data(self): @@ -155,8 +155,8 @@ ] for data, msg, idx in test_cases: self.assertRaisesRegex(ValueError, - r'^{0}: line 1 column {1} \(char {2}\)'.format( - re.escape(msg), idx + 1, idx), + r'^{0}: line 1 column {1} \(char {1}\)'.format( + re.escape(msg), idx), self.loads, data) def test_extra_data(self): @@ -173,22 +173,10 @@ for data, msg, idx in test_cases: self.assertRaisesRegex(ValueError, r'^{0}: line 1 column {1} - line 1 column {2}' - r' \(char {3} - {4}\)'.format( - re.escape(msg), idx + 1, len(data) + 1, idx, len(data)), + r' \(char {1} - {2}\)'.format( + re.escape(msg), idx, len(data)), self.loads, data) - def test_linecol(self): - test_cases = [ - ('!', 1, 1, 0), - (' !', 1, 2, 1), - ('\n!', 2, 1, 1), - ('\n \n\n !', 4, 6, 10), - ] - for data, line, col, idx in test_cases: - self.assertRaisesRegex(ValueError, - r'^Expecting value: line {0} column {1}' - r' \(char {2}\)$'.format(line, col, idx), - self.loads, data) class TestPyFail(TestFail, PyTest): pass class TestCFail(TestFail, CTest): pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/leakers/test_gestalt.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/leakers/test_gestalt.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,14 @@ +import sys + +if sys.platform != 'darwin': + raise ValueError("This test only leaks on Mac OS X") + +def leak(): + # taken from platform._mac_ver_lookup() + from gestalt import gestalt + import MacOS + + try: + gestalt('sysu') + except MacOS.Error: + pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/mock_socket.py --- a/Lib/test/mock_socket.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/mock_socket.py Fri Feb 01 23:12:09 2013 +0100 @@ -102,7 +102,7 @@ pass -def socket(family=None, type=None, proto=None): +def socket(family=None, type=None, proto=None, cloexec=None): return MockSocket() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/pickletester.py --- a/Lib/test/pickletester.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/pickletester.py Fri Feb 01 23:12:09 2013 +0100 @@ -578,10 +578,10 @@ i = C() i.attr = i for proto in protocols: - s = self.dumps(i, proto) + s = self.dumps(i, 2) x = self.loads(s) self.assertEqual(dir(x), dir(i)) - self.assertIs(x.attr, x) + self.assertTrue(x.attr is x) def test_recursive_multi(self): l = [] @@ -601,6 +601,22 @@ self.assertRaises(KeyError, self.loads, b'g0\np0') self.assertEqual(self.loads(b'((Kdtp0\nh\x00l.))'), [(100,), (100,)]) + def test_insecure_strings(self): + # XXX Some of these tests are temporarily disabled + insecure = [b"abc", b"2 + 2", # not quoted + ## b"'abc' + 'def'", # not a single quoted string + b"'abc", # quote is not closed + b"'abc\"", # open quote and close quote don't match + b"'abc' ?", # junk after close quote + b"'\\'", # trailing backslash + # some tests of the quoting rules + ## b"'abc\"\''", + ## b"'\\\\a\'\'\'\\\'\\\\\''", + ] + for b in insecure: + buf = b"S" + b + b"\012p0\012." + self.assertRaises(ValueError, self.loads, buf) + def test_unicode(self): endcases = ['', '<\\u>', '<\\\u1234>', '<\n>', '<\\>', '<\\\U00012345>', @@ -622,13 +638,13 @@ def test_bytes(self): for proto in protocols: for s in b'', b'xyz', b'xyz'*100: - p = self.dumps(s, proto) + p = self.dumps(s) self.assertEqual(self.loads(p), s) for s in [bytes([i]) for i in range(256)]: - p = self.dumps(s, proto) + p = self.dumps(s) self.assertEqual(self.loads(p), s) for s in [bytes([i, i]) for i in range(256)]: - p = self.dumps(s, proto) + p = self.dumps(s) self.assertEqual(self.loads(p), s) def test_ints(self): @@ -1190,58 +1206,6 @@ dumped = b'\x80\x03X\x01\x00\x00\x00ar\xff\xff\xff\xff.' self.assertRaises(ValueError, self.loads, dumped) - def test_badly_escaped_string(self): - self.assertRaises(ValueError, self.loads, b"S'\\'\n.") - - def test_badly_quoted_string(self): - # Issue #17710 - badpickles = [b"S'\n.", - b'S"\n.', - b'S\' \n.', - b'S" \n.', - b'S\'"\n.', - b'S"\'\n.', - b"S' ' \n.", - b'S" " \n.', - b"S ''\n.", - b'S ""\n.', - b'S \n.', - b'S\n.', - b'S.'] - for p in badpickles: - self.assertRaises(pickle.UnpicklingError, self.loads, p) - - def test_correctly_quoted_string(self): - goodpickles = [(b"S''\n.", ''), - (b'S""\n.', ''), - (b'S"\\n"\n.', '\n'), - (b"S'\\n'\n.", '\n')] - for p, expected in goodpickles: - self.assertEqual(self.loads(p), expected) - - def _check_pickling_with_opcode(self, obj, opcode, proto): - pickled = self.dumps(obj, proto) - self.assertTrue(opcode_in_pickle(opcode, pickled)) - unpickled = self.loads(pickled) - self.assertEqual(obj, unpickled) - - def test_appends_on_non_lists(self): - # Issue #17720 - obj = REX_six([1, 2, 3]) - for proto in protocols: - if proto == 0: - self._check_pickling_with_opcode(obj, pickle.APPEND, proto) - else: - self._check_pickling_with_opcode(obj, pickle.APPENDS, proto) - - def test_setitems_on_non_dicts(self): - obj = REX_seven({1: -1, 2: -2, 3: -3}) - for proto in protocols: - if proto == 0: - self._check_pickling_with_opcode(obj, pickle.SETITEM, proto) - else: - self._check_pickling_with_opcode(obj, pickle.SETITEMS, proto) - class BigmemPickleTests(unittest.TestCase): @@ -1327,18 +1291,18 @@ # Test classes for reduce_ex class REX_one(object): - """No __reduce_ex__ here, but inheriting it from object""" _reduce_called = 0 def __reduce__(self): self._reduce_called = 1 return REX_one, () + # No __reduce_ex__ here, but inheriting it from object class REX_two(object): - """No __reduce__ here, but inheriting it from object""" _proto = None def __reduce_ex__(self, proto): self._proto = proto return REX_two, () + # No __reduce__ here, but inheriting it from object class REX_three(object): _proto = None @@ -1349,45 +1313,18 @@ raise TestFailed("This __reduce__ shouldn't be called") class REX_four(object): - """Calling base class method should succeed""" _proto = None def __reduce_ex__(self, proto): self._proto = proto return object.__reduce_ex__(self, proto) + # Calling base class method should succeed class REX_five(object): - """This one used to fail with infinite recursion""" _reduce_called = 0 def __reduce__(self): self._reduce_called = 1 return object.__reduce__(self) - -class REX_six(object): - """This class is used to check the 4th argument (list iterator) of the reduce - protocol. - """ - def __init__(self, items=None): - self.items = items if items is not None else [] - def __eq__(self, other): - return type(self) is type(other) and self.items == self.items - def append(self, item): - self.items.append(item) - def __reduce__(self): - return type(self), (), None, iter(self.items), None - -class REX_seven(object): - """This class is used to check the 5th argument (dict iterator) of the reduce - protocol. - """ - def __init__(self, table=None): - self.table = table if table is not None else {} - def __eq__(self, other): - return type(self) is type(other) and self.table == self.table - def __setitem__(self, key, value): - self.table[key] = value - def __reduce__(self): - return type(self), (), None, None, iter(self.table.items()) - + # This one used to fail with infinite recursion # Test classes for newobj diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/regrtest.py Fri Feb 01 23:12:09 2013 +0100 @@ -127,7 +127,6 @@ import faulthandler import io import json -import locale import logging import os import platform @@ -201,14 +200,7 @@ RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui') -# When tests are run from the Python build directory, it is best practice -# to keep the test files in a subfolder. This eases the cleanup of leftover -# files using the "make distclean" command. -if sysconfig.is_python_build(): - TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build') -else: - TEMPDIR = tempfile.gettempdir() -TEMPDIR = os.path.abspath(TEMPDIR) +TEMPDIR = os.path.abspath(tempfile.gettempdir()) class _ArgParser(argparse.ArgumentParser): @@ -428,7 +420,6 @@ elif o in ('-r', '--randomize'): randomize = True elif o == '--randseed': - randomize = True random_seed = int(a) elif o in ('-f', '--fromfile'): fromfile = a @@ -509,8 +500,12 @@ elif o in ('-j', '--multiprocess'): use_mp = int(a) if use_mp <= 0: - # Use all cores + extras for tests that like to sleep - use_mp = 2 + (os.cpu_count() or 1) + try: + import multiprocessing + # Use all cores + extras for tests that like to sleep + use_mp = 2 + multiprocessing.cpu_count() + except (ImportError, NotImplementedError): + use_mp = 3 if use_mp == 1: use_mp = None elif o == '--header': @@ -533,13 +528,13 @@ # join it with the saved CWD so it ends up where the user expects. testdir = os.path.join(support.SAVEDCWD, a) elif o == '--timeout': - if hasattr(faulthandler, 'dump_traceback_later'): + if hasattr(faulthandler, 'dump_tracebacks_later'): timeout = float(a) if timeout <= 0: timeout = None else: print("Warning: The timeout option requires " - "faulthandler.dump_traceback_later") + "faulthandler.dump_tracebacks_later") timeout = None elif o == '--wait': input("Press any key to continue...") @@ -698,8 +693,7 @@ output = Queue() pending = MultiprocessTests(tests) opt_args = support.args_from_interpreter_flags() - base_cmd = [sys.executable] + opt_args - base_cmd += ['-X', 'faulthandler', '-m', 'test.regrtest'] + base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest'] def work(): # A worker thread. try: @@ -970,7 +964,7 @@ support.use_resources = use_resources use_timeout = (timeout is not None) if use_timeout: - faulthandler.dump_traceback_later(timeout, exit=True) + faulthandler.dump_tracebacks_later(timeout, exit=True) try: support.match_tests = match_tests if failfast: @@ -1010,7 +1004,7 @@ return result finally: if use_timeout: - faulthandler.cancel_dump_traceback_later() + faulthandler.cancel_dump_tracebacks_later() cleanup_test_droppings(test, verbose) runtest.stringio = None @@ -1060,7 +1054,7 @@ 'sys.warnoptions', 'threading._dangling', 'multiprocessing.process._dangling', 'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES', - 'support.TESTFN', 'locale', 'warnings.showwarning', + 'support.TESTFN', 'sys_getdefaultcloexec', ) def get_sys_argv(self): @@ -1113,6 +1107,11 @@ def restore_sys_gettrace(self, trace_fxn): sys.settrace(trace_fxn) + def get_sys_getdefaultcloexec(self): + return sys.getdefaultcloexec() + def restore_sys_getdefaultcloexec(self, trace_fxn): + sys.setdefaultcloexec(trace_fxn) + def get___import__(self): return builtins.__import__ def restore___import__(self, import_): @@ -1229,25 +1228,6 @@ elif os.path.isdir(support.TESTFN): shutil.rmtree(support.TESTFN) - _lc = [getattr(locale, lc) for lc in dir(locale) - if lc.startswith('LC_')] - def get_locale(self): - pairings = [] - for lc in self._lc: - try: - pairings.append((lc, locale.setlocale(lc, None))) - except (TypeError, ValueError): - continue - return pairings - def restore_locale(self, saved): - for lc, setting in saved: - locale.setlocale(lc, setting) - - def get_warnings_showwarning(self): - return warnings.showwarning - def restore_warnings_showwarning(self, fxn): - warnings.showwarning = fxn - def resource_info(self): for name in self.resources: method_suffix = name.replace('.', '_') @@ -1568,9 +1548,13 @@ initial_indent=blanks, subsequent_indent=blanks)) -def main_in_temp_cwd(): - """Run main() in a temporary working directory.""" +def _make_temp_dir_for_build(TEMPDIR): + # When tests are run from the Python build directory, it is best practice + # to keep the test files in a subfolder. It eases the cleanup of leftover + # files using command "make distclean". if sysconfig.is_python_build(): + TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build') + TEMPDIR = os.path.abspath(TEMPDIR) try: os.mkdir(TEMPDIR) except FileExistsError: @@ -1579,16 +1563,10 @@ # Define a writable temp dir that will be used as cwd while running # the tests. The name of the dir includes the pid to allow parallel # testing (see the -j option). - test_cwd = 'test_python_{}'.format(os.getpid()) - test_cwd = os.path.join(TEMPDIR, test_cwd) + TESTCWD = 'test_python_{}'.format(os.getpid()) - # Run the tests in a context manager that temporarily changes the CWD to a - # temporary and writable directory. If it's not possible to create or - # change the CWD, the original CWD will be used. The original CWD is - # available from support.SAVEDCWD. - with support.temp_cwd(test_cwd, quiet=True): - main() - + TESTCWD = os.path.join(TEMPDIR, TESTCWD) + return TEMPDIR, TESTCWD if __name__ == '__main__': # Remove regrtest.py's own directory from the module search path. Despite @@ -1612,4 +1590,11 @@ # sanity check assert __file__ == os.path.abspath(sys.argv[0]) - main_in_temp_cwd() + TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR) + + # Run the tests in a context manager that temporary changes the CWD to a + # temporary and writable directory. If it's not possible to create or + # change the CWD, the original CWD will be used. The original CWD is + # available from support.SAVEDCWD. + with support.temp_cwd(TESTCWD, quiet=True): + main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/script_helper.py --- a/Lib/test/script_helper.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/script_helper.py Fri Feb 01 23:12:09 2013 +0100 @@ -12,12 +12,12 @@ import shutil import zipfile -from importlib.util import source_from_cache +from imp import source_from_cache from test.support import make_legacy_pyc, strip_python_stderr # Executing the interpreter in a subprocess def _assert_python(expected_success, *args, **env_vars): - cmd_line = [sys.executable, '-X', 'faulthandler'] + cmd_line = [sys.executable] if not env_vars: cmd_line.append('-E') # Need to preserve the original environment, for in-place testing of diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/ssl_servers.py --- a/Lib/test/ssl_servers.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/ssl_servers.py Fri Feb 01 23:12:09 2013 +0100 @@ -147,11 +147,9 @@ self.server.shutdown() -def make_https_server(case, *, context=None, certfile=CERTFILE, - host=HOST, handler_class=None): - if context is None: - context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - # We assume the certfile contains both private key and certificate +def make_https_server(case, certfile=CERTFILE, host=HOST, handler_class=None): + # we assume the certfile contains both private key and certificate + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.load_cert_chain(certfile) server = HTTPSServerThread(context, host, handler_class) flag = threading.Event() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/string_tests.py --- a/Lib/test/string_tests.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/string_tests.py Fri Feb 01 23:12:09 2013 +0100 @@ -714,6 +714,27 @@ self.checkraises(TypeError, 'hello', 'capitalize', 42) + def test_lower(self): + self.checkequal('hello', 'HeLLo', 'lower') + self.checkequal('hello', 'hello', 'lower') + self.checkraises(TypeError, 'hello', 'lower', 42) + + def test_upper(self): + self.checkequal('HELLO', 'HeLLo', 'upper') + self.checkequal('HELLO', 'HELLO', 'upper') + self.checkraises(TypeError, 'hello', 'upper', 42) + + def test_expandtabs(self): + self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') + self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) + self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4) + self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4) + self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') + self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) + self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4) + + self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42) + def test_additional_split(self): self.checkequal(['this', 'is', 'the', 'split', 'function'], 'this is the split function', 'split') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/support.py --- a/Lib/test/support.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/support.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,10 +15,10 @@ import warnings import unittest import importlib -import importlib.util import collections.abc import re import subprocess +import imp import time import sysconfig import fnmatch @@ -43,11 +43,6 @@ zlib = None try: - import gzip -except ImportError: - gzip = None - -try: import bz2 except ImportError: bz2 = None @@ -76,7 +71,7 @@ "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", "skip_unless_xattr", "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", "failfast", "anticipate_failure", "run_with_tz", - "requires_gzip", "requires_bz2", "requires_lzma", "suppress_crash_popup", + "requires_bz2", "requires_lzma" ] class Error(Exception): @@ -296,20 +291,25 @@ def unlink(filename): try: _unlink(filename) - except (FileNotFoundError, NotADirectoryError): - pass + except OSError as error: + # The filename need not exist. + if error.errno not in (errno.ENOENT, errno.ENOTDIR): + raise def rmdir(dirname): try: _rmdir(dirname) - except FileNotFoundError: - pass + except OSError as error: + # The directory need not exist. + if error.errno != errno.ENOENT: + raise def rmtree(path): try: _rmtree(path) - except FileNotFoundError: - pass + except OSError as error: + if error.errno != errno.ENOENT: + raise def make_legacy_pyc(source): """Move a PEP 3147 pyc/pyo file to its legacy pyc/pyo location. @@ -321,7 +321,7 @@ does not need to exist, however the PEP 3147 pyc file must exist. :return: The file system path to the legacy pyc file. """ - pyc_file = importlib.util.cache_from_source(source) + pyc_file = imp.cache_from_source(source) up_one = os.path.dirname(os.path.abspath(source)) legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o')) os.rename(pyc_file, legacy_pyc) @@ -340,8 +340,8 @@ # combinations of PEP 3147 and legacy pyc and pyo files. unlink(source + 'c') unlink(source + 'o') - unlink(importlib.util.cache_from_source(source, debug_override=True)) - unlink(importlib.util.cache_from_source(source, debug_override=False)) + unlink(imp.cache_from_source(source, debug_override=True)) + unlink(imp.cache_from_source(source, debug_override=False)) # On some platforms, should not run gui test even if it is allowed # in `use_resources'. @@ -580,12 +580,10 @@ IPV6_ENABLED = _is_ipv6_enabled() -# A constant likely larger than the underlying OS pipe buffer size, to -# make writes blocking. -# Windows limit seems to be around 512 B, and many Unix kernels have a -# 64 KiB pipe buffer size or 16 * PAGE_SIZE: take a few megs to be sure. -# (see issue #17835 for a discussion of this number). -PIPE_MAX_SIZE = 4 *1024 * 1024 + 1 +# A constant likely larger than the underlying OS pipe buffer size. +# Windows limit seems to be around 512B, and most Unix kernels have a 64K pipe +# buffer size: take 1M to be sure. +PIPE_MAX_SIZE = 1024 * 1024 # decorator for skipping tests on non-IEEE 754 platforms @@ -595,8 +593,6 @@ requires_zlib = unittest.skipUnless(zlib, 'requires zlib') -requires_gzip = unittest.skipUnless(gzip, 'requires gzip') - requires_bz2 = unittest.skipUnless(bz2, 'requires bz2') requires_lzma = unittest.skipUnless(lzma, 'requires lzma') @@ -1186,31 +1182,16 @@ def captured_stdout(): """Capture the output of sys.stdout: - with captured_stdout() as stdout: + with captured_stdout() as s: print("hello") - self.assertEqual(stdout.getvalue(), "hello\n") + self.assertEqual(s.getvalue(), "hello") """ return captured_output("stdout") def captured_stderr(): - """Capture the output of sys.stderr: - - with captured_stderr() as stderr: - print("hello", file=sys.stderr) - self.assertEqual(stderr.getvalue(), "hello\n") - """ return captured_output("stderr") def captured_stdin(): - """Capture the input to sys.stdin: - - with captured_stdin() as stdin: - stdin.write('hello\n') - stdin.seek(0) - # call test code that consumes from sys.stdin - captured = input() - self.assertEqual(captured, "hello") - """ return captured_output("stdin") @@ -1614,16 +1595,6 @@ _filter_suite(suite, case_pred) _run_suite(suite) -#======================================================================= -# Check for the presence of docstrings. - -HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or - sys.platform == 'win32' or - sysconfig.get_config_var('WITH_DOC_STRINGS')) - -requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS, - "test requires docstrings") - #======================================================================= # doctest driver. @@ -1931,30 +1902,6 @@ msg = "no non-broken extended attribute support" return test if ok else unittest.skip(msg)(test) - -if sys.platform.startswith('win'): - @contextlib.contextmanager - def suppress_crash_popup(): - """Disable Windows Error Reporting dialogs using SetErrorMode.""" - # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621%28v=vs.85%29.aspx - # GetErrorMode is not available on Windows XP and Windows Server 2003, - # but SetErrorMode returns the previous value, so we can use that - import ctypes - k32 = ctypes.windll.kernel32 - SEM_NOGPFAULTERRORBOX = 0x02 - old_error_mode = k32.SetErrorMode(SEM_NOGPFAULTERRORBOX) - k32.SetErrorMode(old_error_mode | SEM_NOGPFAULTERRORBOX) - try: - yield - finally: - k32.SetErrorMode(old_error_mode) -else: - # this is a no-op for other platforms - @contextlib.contextmanager - def suppress_crash_popup(): - yield - - def patch(test_instance, object_to_patch, attr_name, new_value): """Override 'object_to_patch'.'attr_name' with 'new_value'. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test___all__.py --- a/Lib/test/test___all__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test___all__.py Fri Feb 01 23:12:09 2013 +0100 @@ -29,20 +29,17 @@ if not hasattr(sys.modules[modname], "__all__"): raise NoAll(modname) names = {} - with self.subTest(module=modname): - try: - exec("from %s import *" % modname, names) - except Exception as e: - # Include the module name in the exception string - self.fail("__all__ failure in {}: {}: {}".format( - modname, e.__class__.__name__, e)) - if "__builtins__" in names: - del names["__builtins__"] - keys = set(names) - all_list = sys.modules[modname].__all__ - all_set = set(all_list) - self.assertCountEqual(all_set, all_list, "in module {}".format(modname)) - self.assertEqual(keys, all_set, "in module {}".format(modname)) + try: + exec("from %s import *" % modname, names) + except Exception as e: + # Include the module name in the exception string + self.fail("__all__ failure in {}: {}: {}".format( + modname, e.__class__.__name__, e)) + if "__builtins__" in names: + del names["__builtins__"] + keys = set(names) + all = set(sys.modules[modname].__all__) + self.assertEqual(keys, all) def walk_modules(self, basedir, modpath): for fn in sorted(os.listdir(basedir)): @@ -113,5 +110,8 @@ print('Following modules failed to be imported:', failed_imports) +def test_main(): + support.run_unittest(AllTest) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_abc.py --- a/Lib/test/test_abc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_abc.py Fri Feb 01 23:12:09 2013 +0100 @@ -329,10 +329,7 @@ b = B() self.assertFalse(isinstance(b, A)) self.assertFalse(isinstance(b, (A,))) - token_old = abc.get_cache_token() A.register(B) - token_new = abc.get_cache_token() - self.assertNotEqual(token_old, token_new) self.assertTrue(isinstance(b, A)) self.assertTrue(isinstance(b, (A,))) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_aifc.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,6 @@ import os import io import struct -import pickle import aifc @@ -32,7 +31,6 @@ def test_params(self): f = self.f = aifc.open(self.sndfilepath) - params = f.getparams() self.assertEqual(f.getfp().name, self.sndfilepath) self.assertEqual(f.getnchannels(), 2) self.assertEqual(f.getsampwidth(), 2) @@ -45,36 +43,6 @@ (2, 2, 48000, 14400, b'NONE', b'not compressed'), ) - params = f.getparams() - self.assertEqual(params.nchannels, 2) - self.assertEqual(params.sampwidth, 2) - self.assertEqual(params.framerate, 48000) - self.assertEqual(params.nframes, 14400) - self.assertEqual(params.comptype, b'NONE') - self.assertEqual(params.compname, b'not compressed') - - def test_params_added(self): - f = self.f = aifc.open(TESTFN, 'wb') - f.aiff() - f.setparams((1, 1, 1, 1, b'NONE', b'')) - f.close() - - f = self.f = aifc.open(TESTFN, 'rb') - params = f.getparams() - self.assertEqual(params.nchannels, f.getnchannels()) - self.assertEqual(params.sampwidth, f.getsampwidth()) - self.assertEqual(params.framerate, f.getframerate()) - self.assertEqual(params.nframes, f.getnframes()) - self.assertEqual(params.comptype, f.getcomptype()) - self.assertEqual(params.compname, f.getcompname()) - - def test_getparams_picklable(self): - self.f = aifc.open(self.sndfilepath) - params = self.f.getparams() - dump = pickle.dumps(params) - self.assertEqual(pickle.loads(dump), params) - self.f.close() - def test_context_manager(self): with open(self.sndfilepath, 'rb') as testfile: with aifc.open(testfile) as f: @@ -363,14 +331,12 @@ def test_write_aiff_by_extension(self): sampwidth = 2 - filename = TESTFN + '.aiff' - fout = self.fout = aifc.open(filename, 'wb') - self.addCleanup(unlink, filename) + fout = self.fout = aifc.open(TESTFN + '.aiff', 'wb') fout.setparams((1, sampwidth, 1, 1, b'ULAW', b'')) frames = b'\x00' * fout.getnchannels() * sampwidth fout.writeframes(frames) fout.close() - f = self.f = aifc.open(filename, 'rb') + f = self.f = aifc.open(TESTFN + '.aiff', 'rb') self.assertEqual(f.getcomptype(), b'NONE') f.close() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_array.py --- a/Lib/test/test_array.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_array.py Fri Feb 01 23:12:09 2013 +0100 @@ -24,9 +24,6 @@ except struct.error: have_long_long = False -sizeof_wchar = array.array('u').itemsize - - class ArraySubclass(array.array): pass @@ -1043,6 +1040,16 @@ minitemsize = 2 def test_unicode(self): + try: + import ctypes + sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) + except ImportError: + import sys + if sys.platform == 'win32': + sizeof_wchar = 2 + else: + sizeof_wchar = 4 + self.assertRaises(TypeError, array.array, 'b', 'foo') a = array.array('u', '\xa0\xc2\u1234') @@ -1062,18 +1069,6 @@ self.assertRaises(TypeError, a.fromunicode) - def test_issue17223(self): - # this used to crash - if sizeof_wchar == 4: - # U+FFFFFFFF is an invalid code point in Unicode 6.0 - invalid_str = b'\xff\xff\xff\xff' - else: - # PyUnicode_FromUnicode() cannot fail with 16-bit wchar_t - self.skipTest("specific to 32-bit wchar_t") - a = array.array('u', invalid_str) - self.assertRaises(ValueError, a.tounicode) - self.assertRaises(ValueError, str, a) - class NumberTest(BaseTest): def test_extslice(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ast.py Fri Feb 01 23:12:09 2013 +0100 @@ -180,36 +180,20 @@ class AST_Tests(unittest.TestCase): - def _assertTrueorder(self, ast_node, parent_pos, reverse_check = False): - def should_reverse_check(parent, child): - # In some situations, the children of nodes occur before - # their parents, for example in a.b.c, a occurs before b - # but a is a child of b. - if isinstance(parent, ast.Call): - if parent.func == child: - return True - if isinstance(parent, (ast.Attribute, ast.Subscript)): - return True - return False - + def _assertTrueorder(self, ast_node, parent_pos): if not isinstance(ast_node, ast.AST) or ast_node._fields is None: return if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)): node_pos = (ast_node.lineno, ast_node.col_offset) - if reverse_check: - self.assertTrue(node_pos <= parent_pos) - else: - self.assertTrue(node_pos >= parent_pos) + self.assertTrue(node_pos >= parent_pos) parent_pos = (ast_node.lineno, ast_node.col_offset) for name in ast_node._fields: value = getattr(ast_node, name) if isinstance(value, list): for child in value: - self._assertTrueorder(child, parent_pos, - should_reverse_check(ast_node, child)) + self._assertTrueorder(child, parent_pos) elif value is not None: - self._assertTrueorder(value, parent_pos, - should_reverse_check(ast_node, value)) + self._assertTrueorder(value, parent_pos) def test_AST_objects(self): x = ast.AST() @@ -278,14 +262,14 @@ def test_arguments(self): x = ast.arguments() - self.assertEqual(x._fields, ('args', 'vararg', - 'kwonlyargs', 'kw_defaults', - 'kwarg', 'defaults')) + self.assertEqual(x._fields, ('args', 'vararg', 'varargannotation', + 'kwonlyargs', 'kwarg', 'kwargannotation', + 'defaults', 'kw_defaults')) with self.assertRaises(AttributeError): x.vararg - x = ast.arguments(*range(1, 7)) + x = ast.arguments(*range(1, 9)) self.assertEqual(x.vararg, 2) def test_field_attr_writable(self): @@ -455,7 +439,7 @@ "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), " "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, " "col_offset=11)], keywords=[], starargs=None, kwargs=None, " - "lineno=1, col_offset=4), lineno=1, col_offset=0)])" + "lineno=1, col_offset=0), lineno=1, col_offset=0)])" ) def test_copy_location(self): @@ -476,7 +460,7 @@ "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), " "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, " "col_offset=6)], keywords=[], starargs=None, kwargs=None, " - "lineno=1, col_offset=5), lineno=1, col_offset=0), " + "lineno=1, col_offset=0), lineno=1, col_offset=0), " "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, " "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], " "keywords=[], starargs=None, kwargs=None, lineno=1, " @@ -576,8 +560,8 @@ self.mod(m, "must have Load context", "eval") def _check_arguments(self, fac, check): - def arguments(args=None, vararg=None, - kwonlyargs=None, kwarg=None, + def arguments(args=None, vararg=None, varargannotation=None, + kwonlyargs=None, kwarg=None, kwargannotation=None, defaults=None, kw_defaults=None): if args is None: args = [] @@ -587,12 +571,20 @@ defaults = [] if kw_defaults is None: kw_defaults = [] - args = ast.arguments(args, vararg, kwonlyargs, kw_defaults, - kwarg, defaults) + args = ast.arguments(args, vararg, varargannotation, kwonlyargs, + kwarg, kwargannotation, defaults, kw_defaults) return fac(args) args = [ast.arg("x", ast.Name("x", ast.Store()))] check(arguments(args=args), "must have Load context") + check(arguments(varargannotation=ast.Num(3)), + "varargannotation but no vararg") + check(arguments(varargannotation=ast.Name("x", ast.Store()), vararg="x"), + "must have Load context") check(arguments(kwonlyargs=args), "must have Load context") + check(arguments(kwargannotation=ast.Num(42)), + "kwargannotation but no kwarg") + check(arguments(kwargannotation=ast.Name("x", ast.Store()), + kwarg="x"), "must have Load context") check(arguments(defaults=[ast.Num(3)]), "more positional defaults than args") check(arguments(kw_defaults=[ast.Num(4)]), @@ -607,7 +599,7 @@ "must have Load context") def test_funcdef(self): - a = ast.arguments([], None, [], [], None, []) + a = ast.arguments([], None, None, [], None, None, [], []) f = ast.FunctionDef("x", a, [], [], None) self.stmt(f, "empty body on FunctionDef") f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())], @@ -778,7 +770,7 @@ self.expr(u, "must have Load context") def test_lambda(self): - a = ast.arguments([], None, [], [], None, []) + a = ast.arguments([], None, None, [], None, None, [], []) self.expr(ast.Lambda(a, ast.Name("x", ast.Store())), "must have Load context") def fac(args): @@ -947,10 +939,13 @@ fn = os.path.join(stdlib, module) with open(fn, "r", encoding="utf-8") as fp: source = fp.read() - mod = ast.parse(source, fn) + mod = ast.parse(source) compile(mod, fn, "exec") +def test_main(): + support.run_unittest(AST_Tests, ASTHelpers_Test, ASTValidatorTests) + def main(): if __name__ != '__main__': return @@ -963,20 +958,20 @@ print("]") print("main()") raise SystemExit - unittest.main() + test_main() #### EVERYTHING BELOW IS GENERATED ##### exec_results = [ ('Module', [('Expr', (1, 0), ('NameConstant', (1, 0), None))]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, []), [('Pass', (1, 9))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', None)], None, [], [], None, []), [('Pass', (1, 10))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', None)], None, [], [], None, [('Num', (1, 8), 0)]), [('Pass', (1, 12))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], ('arg', (1, 7), 'args', None), [], [], None, []), [('Pass', (1, 14))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], ('arg', (1, 8), 'kwargs', None), []), [('Pass', (1, 17))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', None), ('arg', (1, 9), 'b', None), ('arg', (1, 14), 'c', None), ('arg', (1, 22), 'd', None), ('arg', (1, 28), 'e', None)], ('arg', (1, 35), 'args', None), [], [], ('arg', (1, 43), 'kwargs', None), [('Num', (1, 11), 1), ('NameConstant', (1, 16), None), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])]), [('Pass', (1, 52))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Pass', (1, 9))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], None, None, [], None, None, [], []), [('Pass', (1, 10))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], None, None, [], None, None, [('Num', (1, 8), 0)], []), [('Pass', (1, 12))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], 'args', None, [], None, None, [], []), [('Pass', (1, 14))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], 'kwargs', None, [], []), [('Pass', (1, 17))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None), ('arg', 'b', None), ('arg', 'c', None), ('arg', 'd', None), ('arg', 'e', None)], 'args', None, [], 'kwargs', None, [('Num', (1, 11), 1), ('NameConstant', (1, 16), None), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])], []), [('Pass', (1, 52))], [], None)]), ('Module', [('ClassDef', (1, 0), 'C', [], [], None, None, [('Pass', (1, 8))], [])]), ('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [], None, None, [('Pass', (1, 17))], [])]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, []), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]), ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]), @@ -985,7 +980,7 @@ ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), ('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('Name', (1, 10), 'y', ('Store',)))], [('Pass', (1, 13))])]), ('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('Name', (1, 10), 'y', ('Store',))), ('withitem', ('Name', (1, 13), 'z', ('Load',)), ('Name', (1, 18), 'q', ('Store',)))], [('Pass', (1, 21))])]), -('Module', [('Raise', (1, 0), ('Call', (1, 15), ('Name', (1, 6), 'Exception', ('Load',)), [('Str', (1, 16), 'string')], [], None, None), None)]), +('Module', [('Raise', (1, 0), ('Call', (1, 6), ('Name', (1, 6), 'Exception', ('Load',)), [('Str', (1, 16), 'string')], [], None, None), None)]), ('Module', [('Try', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [], [])]), ('Module', [('Try', (1, 0), [('Pass', (2, 2))], [], [], [('Pass', (4, 2))])]), ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), @@ -1014,7 +1009,7 @@ ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])), ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))), ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), -('Expression', ('Lambda', (1, 0), ('arguments', [], None, [], [], None, []), ('NameConstant', (1, 7), None))), +('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, [], None, None, [], []), ('NameConstant', (1, 7), None))), ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), ('Expression', ('Dict', (1, 0), [], [])), ('Expression', ('Set', (1, 0), [('NameConstant', (1, 1), None)])), @@ -1022,17 +1017,17 @@ ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])), -('Expression', ('Call', (1, 1), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), +('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), ('Expression', ('Num', (1, 0), 10)), ('Expression', ('Str', (1, 0), 'string')), -('Expression', ('Attribute', (1, 2), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))), -('Expression', ('Subscript', (1, 2), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), +('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))), +('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), ('Expression', ('Name', (1, 0), 'v', ('Load',))), ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), ('Expression', ('List', (1, 0), [], ('Load',))), ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))), ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), ('Expression', ('Tuple', (1, 0), [], ('Load',))), -('Expression', ('Call', (1, 7), ('Attribute', (1, 6), ('Attribute', (1, 4), ('Attribute', (1, 2), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 12), ('Attribute', (1, 10), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), +('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), ] main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_asynchat.py --- a/Lib/test/test_asynchat.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_asynchat.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,7 +15,6 @@ HOST = support.HOST SERVER_QUIT = b'QUIT\n' -TIMEOUT = 3.0 if threading: class echo_server(threading.Thread): @@ -124,9 +123,7 @@ c.push(b"I'm not dead yet!" + term) c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) @@ -157,9 +154,7 @@ c.push(data) c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, [data[:termlen]]) @@ -179,9 +174,7 @@ c.push(data) c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, []) self.assertEqual(c.buffer, data) @@ -193,9 +186,7 @@ p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8) c.push_with_producer(p) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) @@ -205,9 +196,7 @@ data = b"hello world\nI'm not dead yet!\n" c.push_with_producer(data+SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) @@ -218,9 +207,7 @@ c.push(b"hello world\n\nI'm not dead yet!\n") c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, [b"hello world", b"", b"I'm not dead yet!"]) @@ -239,9 +226,7 @@ # where the server echoes all of its data before we can check that it # got any down below. s.start_resend_event.set() - s.join(timeout=TIMEOUT) - if s.is_alive(): - self.fail("join() timed out") + s.join() self.assertEqual(c.contents, []) # the server might have been able to send a byte or two back, but this @@ -283,5 +268,9 @@ self.assertEqual(f.pop(), (0, None)) +def test_main(verbose=None): + support.run_unittest(TestAsynchat, TestAsynchat_WithPoll, + TestHelperFunctions, TestFifo) + if __name__ == "__main__": - unittest.main() + test_main(verbose=True) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_asyncore.py Fri Feb 01 23:12:09 2013 +0100 @@ -20,7 +20,7 @@ threading = None HOST = support.HOST -TIMEOUT = 3 + HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX') class dummysocket: @@ -397,10 +397,7 @@ self.assertEqual(cap.getvalue(), data*2) finally: - t.join(timeout=TIMEOUT) - if t.is_alive(): - self.fail("join() timed out") - + t.join() class DispatcherWithSendTests_UsePoll(DispatcherWithSendTests): @@ -742,7 +739,8 @@ def test_create_socket(self): s = asyncore.dispatcher() - s.create_socket(self.family) + # disable cloexec to avoid SOCK_CLOEXEC flag in the type attribute + s.create_socket(self.family, cloexec=False) self.assertEqual(s.socket.family, self.family) SOCK_NONBLOCK = getattr(socket, 'SOCK_NONBLOCK', 0) self.assertEqual(s.socket.type, socket.SOCK_STREAM | SOCK_NONBLOCK) @@ -792,11 +790,7 @@ t = threading.Thread(target=lambda: asyncore.loop(timeout=0.1, count=500)) t.start() - def cleanup(): - t.join(timeout=TIMEOUT) - if t.is_alive(): - self.fail("join() timed out") - self.addCleanup(cleanup) + self.addCleanup(t.join) s = socket.socket(self.family, socket.SOCK_STREAM) s.settimeout(.2) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_audioop.py --- a/Lib/test/test_audioop.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_audioop.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,21 +1,25 @@ import audioop -import sys import unittest from test.support import run_unittest -def pack(width, data): - return b''.join(v.to_bytes(width, sys.byteorder, signed=True) for v in data) +endian = 'big' if audioop.getsample(b'\0\1', 2, 0) == 1 else 'little' -packs = {w: (lambda *data, width=w: pack(width, data)) for w in (1, 2, 4)} -maxvalues = {w: (1 << (8 * w - 1)) - 1 for w in (1, 2, 4)} -minvalues = {w: -1 << (8 * w - 1) for w in (1, 2, 4)} +def gendata1(): + return b'\0\1\2' -datas = { - 1: b'\x00\x12\x45\xbb\x7f\x80\xff', - 2: packs[2](0, 0x1234, 0x4567, -0x4567, 0x7fff, -0x8000, -1), - 4: packs[4](0, 0x12345678, 0x456789ab, -0x456789ab, - 0x7fffffff, -0x80000000, -1), -} +def gendata2(): + if endian == 'big': + return b'\0\0\0\1\0\2' + else: + return b'\0\0\1\0\2\0' + +def gendata4(): + if endian == 'big': + return b'\0\0\0\0\0\0\0\1\0\0\0\2' + else: + return b'\0\0\0\0\1\0\0\0\2\0\0\0' + +data = [gendata1(), gendata2(), gendata4()] INVALID_DATA = [ (b'abc', 0), @@ -27,320 +31,171 @@ class TestAudioop(unittest.TestCase): def test_max(self): - for w in 1, 2, 4: - self.assertEqual(audioop.max(b'', w), 0) - p = packs[w] - self.assertEqual(audioop.max(p(5), w), 5) - self.assertEqual(audioop.max(p(5, -8, -1), w), 8) - self.assertEqual(audioop.max(p(maxvalues[w]), w), maxvalues[w]) - self.assertEqual(audioop.max(p(minvalues[w]), w), -minvalues[w]) - self.assertEqual(audioop.max(datas[w], w), -minvalues[w]) + self.assertEqual(audioop.max(data[0], 1), 2) + self.assertEqual(audioop.max(data[1], 2), 2) + self.assertEqual(audioop.max(data[2], 4), 2) def test_minmax(self): - for w in 1, 2, 4: - self.assertEqual(audioop.minmax(b'', w), - (0x7fffffff, -0x80000000)) - p = packs[w] - self.assertEqual(audioop.minmax(p(5), w), (5, 5)) - self.assertEqual(audioop.minmax(p(5, -8, -1), w), (-8, 5)) - self.assertEqual(audioop.minmax(p(maxvalues[w]), w), - (maxvalues[w], maxvalues[w])) - self.assertEqual(audioop.minmax(p(minvalues[w]), w), - (minvalues[w], minvalues[w])) - self.assertEqual(audioop.minmax(datas[w], w), - (minvalues[w], maxvalues[w])) + self.assertEqual(audioop.minmax(data[0], 1), (0, 2)) + self.assertEqual(audioop.minmax(data[1], 2), (0, 2)) + self.assertEqual(audioop.minmax(data[2], 4), (0, 2)) def test_maxpp(self): - for w in 1, 2, 4: - self.assertEqual(audioop.maxpp(b'', w), 0) - self.assertEqual(audioop.maxpp(packs[w](*range(100)), w), 0) - self.assertEqual(audioop.maxpp(packs[w](9, 10, 5, 5, 0, 1), w), 10) - self.assertEqual(audioop.maxpp(datas[w], w), - maxvalues[w] - minvalues[w]) + self.assertEqual(audioop.maxpp(data[0], 1), 0) + self.assertEqual(audioop.maxpp(data[1], 2), 0) + self.assertEqual(audioop.maxpp(data[2], 4), 0) def test_avg(self): - for w in 1, 2, 4: - self.assertEqual(audioop.avg(b'', w), 0) - p = packs[w] - self.assertEqual(audioop.avg(p(5), w), 5) - self .assertEqual(audioop.avg(p(5, 8), w), 6) - self.assertEqual(audioop.avg(p(5, -8), w), -2) - self.assertEqual(audioop.avg(p(maxvalues[w], maxvalues[w]), w), - maxvalues[w]) - self.assertEqual(audioop.avg(p(minvalues[w], minvalues[w]), w), - minvalues[w]) - self.assertEqual(audioop.avg(packs[4](0x50000000, 0x70000000), 4), - 0x60000000) - self.assertEqual(audioop.avg(packs[4](-0x50000000, -0x70000000), 4), - -0x60000000) + self.assertEqual(audioop.avg(data[0], 1), 1) + self.assertEqual(audioop.avg(data[1], 2), 1) + self.assertEqual(audioop.avg(data[2], 4), 1) def test_avgpp(self): - for w in 1, 2, 4: - self.assertEqual(audioop.avgpp(b'', w), 0) - self.assertEqual(audioop.avgpp(packs[w](*range(100)), w), 0) - self.assertEqual(audioop.avgpp(packs[w](9, 10, 5, 5, 0, 1), w), 10) - self.assertEqual(audioop.avgpp(datas[1], 1), 196) - self.assertEqual(audioop.avgpp(datas[2], 2), 50534) - self.assertEqual(audioop.avgpp(datas[4], 4), 3311897002) + self.assertEqual(audioop.avgpp(data[0], 1), 0) + self.assertEqual(audioop.avgpp(data[1], 2), 0) + self.assertEqual(audioop.avgpp(data[2], 4), 0) def test_rms(self): - for w in 1, 2, 4: - self.assertEqual(audioop.rms(b'', w), 0) - p = packs[w] - self.assertEqual(audioop.rms(p(*range(100)), w), 57) - self.assertAlmostEqual(audioop.rms(p(maxvalues[w]) * 5, w), - maxvalues[w], delta=1) - self.assertAlmostEqual(audioop.rms(p(minvalues[w]) * 5, w), - -minvalues[w], delta=1) - self.assertEqual(audioop.rms(datas[1], 1), 77) - self.assertEqual(audioop.rms(datas[2], 2), 20001) - self.assertEqual(audioop.rms(datas[4], 4), 1310854152) + self.assertEqual(audioop.rms(data[0], 1), 1) + self.assertEqual(audioop.rms(data[1], 2), 1) + self.assertEqual(audioop.rms(data[2], 4), 1) def test_cross(self): - for w in 1, 2, 4: - self.assertEqual(audioop.cross(b'', w), -1) - p = packs[w] - self.assertEqual(audioop.cross(p(0, 1, 2), w), 0) - self.assertEqual(audioop.cross(p(1, 2, -3, -4), w), 1) - self.assertEqual(audioop.cross(p(-1, -2, 3, 4), w), 1) - self.assertEqual(audioop.cross(p(0, minvalues[w]), w), 1) - self.assertEqual(audioop.cross(p(minvalues[w], maxvalues[w]), w), 1) + self.assertEqual(audioop.cross(data[0], 1), 0) + self.assertEqual(audioop.cross(data[1], 2), 0) + self.assertEqual(audioop.cross(data[2], 4), 0) def test_add(self): - for w in 1, 2, 4: - self.assertEqual(audioop.add(b'', b'', w), b'') - self.assertEqual(audioop.add(datas[w], b'\0' * len(datas[w]), w), - datas[w]) - self.assertEqual(audioop.add(datas[1], datas[1], 1), - b'\x00\x24\x7f\x80\x7f\x80\xfe') - self.assertEqual(audioop.add(datas[2], datas[2], 2), - packs[2](0, 0x2468, 0x7fff, -0x8000, 0x7fff, -0x8000, -2)) - self.assertEqual(audioop.add(datas[4], datas[4], 4), - packs[4](0, 0x2468acf0, 0x7fffffff, -0x80000000, - 0x7fffffff, -0x80000000, -2)) + data2 = [] + for d in data: + str = bytearray(len(d)) + for i,b in enumerate(d): + str[i] = 2*b + data2.append(str) + self.assertEqual(audioop.add(data[0], data[0], 1), data2[0]) + self.assertEqual(audioop.add(data[1], data[1], 2), data2[1]) + self.assertEqual(audioop.add(data[2], data[2], 4), data2[2]) def test_bias(self): - for w in 1, 2, 4: - for bias in 0, 1, -1, 127, -128, 0x7fffffff, -0x80000000: - self.assertEqual(audioop.bias(b'', w, bias), b'') - self.assertEqual(audioop.bias(datas[1], 1, 1), - b'\x01\x13\x46\xbc\x80\x81\x00') - self.assertEqual(audioop.bias(datas[1], 1, -1), - b'\xff\x11\x44\xba\x7e\x7f\xfe') - self.assertEqual(audioop.bias(datas[1], 1, 0x7fffffff), - b'\xff\x11\x44\xba\x7e\x7f\xfe') - self.assertEqual(audioop.bias(datas[1], 1, -0x80000000), - datas[1]) - self.assertEqual(audioop.bias(datas[2], 2, 1), - packs[2](1, 0x1235, 0x4568, -0x4566, -0x8000, -0x7fff, 0)) - self.assertEqual(audioop.bias(datas[2], 2, -1), - packs[2](-1, 0x1233, 0x4566, -0x4568, 0x7ffe, 0x7fff, -2)) - self.assertEqual(audioop.bias(datas[2], 2, 0x7fffffff), - packs[2](-1, 0x1233, 0x4566, -0x4568, 0x7ffe, 0x7fff, -2)) - self.assertEqual(audioop.bias(datas[2], 2, -0x80000000), - datas[2]) - self.assertEqual(audioop.bias(datas[4], 4, 1), - packs[4](1, 0x12345679, 0x456789ac, -0x456789aa, - -0x80000000, -0x7fffffff, 0)) - self.assertEqual(audioop.bias(datas[4], 4, -1), - packs[4](-1, 0x12345677, 0x456789aa, -0x456789ac, - 0x7ffffffe, 0x7fffffff, -2)) - self.assertEqual(audioop.bias(datas[4], 4, 0x7fffffff), - packs[4](0x7fffffff, -0x6dcba989, -0x3a987656, 0x3a987654, - -2, -1, 0x7ffffffe)) - self.assertEqual(audioop.bias(datas[4], 4, -0x80000000), - packs[4](-0x80000000, -0x6dcba988, -0x3a987655, 0x3a987655, - -1, 0, 0x7fffffff)) + # Note: this test assumes that avg() works + d1 = audioop.bias(data[0], 1, 100) + d2 = audioop.bias(data[1], 2, 100) + d4 = audioop.bias(data[2], 4, 100) + self.assertEqual(audioop.avg(d1, 1), 101) + self.assertEqual(audioop.avg(d2, 2), 101) + self.assertEqual(audioop.avg(d4, 4), 101) def test_lin2lin(self): - for w in 1, 2, 4: - self.assertEqual(audioop.lin2lin(datas[w], w, w), datas[w]) - - self.assertEqual(audioop.lin2lin(datas[1], 1, 2), - packs[2](0, 0x1200, 0x4500, -0x4500, 0x7f00, -0x8000, -0x100)) - self.assertEqual(audioop.lin2lin(datas[1], 1, 4), - packs[4](0, 0x12000000, 0x45000000, -0x45000000, - 0x7f000000, -0x80000000, -0x1000000)) - self.assertEqual(audioop.lin2lin(datas[2], 2, 1), - b'\x00\x12\x45\xba\x7f\x80\xff') - self.assertEqual(audioop.lin2lin(datas[2], 2, 4), - packs[4](0, 0x12340000, 0x45670000, -0x45670000, - 0x7fff0000, -0x80000000, -0x10000)) - self.assertEqual(audioop.lin2lin(datas[4], 4, 1), - b'\x00\x12\x45\xba\x7f\x80\xff') - self.assertEqual(audioop.lin2lin(datas[4], 4, 2), - packs[2](0, 0x1234, 0x4567, -0x4568, 0x7fff, -0x8000, -1)) + # too simple: we test only the size + for d1 in data: + for d2 in data: + got = len(d1)//3 + wtd = len(d2)//3 + self.assertEqual(len(audioop.lin2lin(d1, got, wtd)), len(d2)) def test_adpcm2lin(self): - self.assertEqual(audioop.adpcm2lin(b'\x07\x7f\x7f', 1, None), - (b'\x00\x00\x00\xff\x00\xff', (-179, 40))) - self.assertEqual(audioop.adpcm2lin(b'\x07\x7f\x7f', 2, None), - (packs[2](0, 0xb, 0x29, -0x16, 0x72, -0xb3), (-179, 40))) - self.assertEqual(audioop.adpcm2lin(b'\x07\x7f\x7f', 4, None), - (packs[4](0, 0xb0000, 0x290000, -0x160000, 0x720000, - -0xb30000), (-179, 40))) - # Very cursory test - for w in 1, 2, 4: - self.assertEqual(audioop.adpcm2lin(b'\0' * 5, w, None), - (b'\0' * w * 10, (0, 0))) + self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0' * 4, (0,0))) + self.assertEqual(audioop.adpcm2lin(b'\0\0', 2, None), (b'\0' * 8, (0,0))) + self.assertEqual(audioop.adpcm2lin(b'\0\0', 4, None), (b'\0' * 16, (0,0))) def test_lin2adpcm(self): - self.assertEqual(audioop.lin2adpcm(datas[1], 1, None), - (b'\x07\x7f\x7f', (-221, 39))) - self.assertEqual(audioop.lin2adpcm(datas[2], 2, None), - (b'\x07\x7f\x7f', (31, 39))) - self.assertEqual(audioop.lin2adpcm(datas[4], 4, None), - (b'\x07\x7f\x7f', (31, 39))) - # Very cursory test - for w in 1, 2, 4: - self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None), - (b'\0' * 5, (0, 0))) + self.assertEqual(audioop.lin2adpcm(b'\0\0\0\0', 1, None), (b'\0\0', (0,0))) def test_lin2alaw(self): - self.assertEqual(audioop.lin2alaw(datas[1], 1), - b'\xd5\x87\xa4\x24\xaa\x2a\x5a') - self.assertEqual(audioop.lin2alaw(datas[2], 2), - b'\xd5\x87\xa4\x24\xaa\x2a\x55') - self.assertEqual(audioop.lin2alaw(datas[4], 4), - b'\xd5\x87\xa4\x24\xaa\x2a\x55') + self.assertEqual(audioop.lin2alaw(data[0], 1), b'\xd5\xc5\xf5') + self.assertEqual(audioop.lin2alaw(data[1], 2), b'\xd5\xd5\xd5') + self.assertEqual(audioop.lin2alaw(data[2], 4), b'\xd5\xd5\xd5') def test_alaw2lin(self): - encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\ - b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff' - src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106, - 688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106] - for w in 1, 2, 4: - self.assertEqual(audioop.alaw2lin(encoded, w), - packs[w](*(x << (w * 8) >> 13 for x in src))) - - encoded = bytes(range(256)) - for w in 2, 4: - decoded = audioop.alaw2lin(encoded, w) - self.assertEqual(audioop.lin2alaw(decoded, w), encoded) + # Cursory + d = audioop.lin2alaw(data[0], 1) + self.assertEqual(audioop.alaw2lin(d, 1), data[0]) + if endian == 'big': + self.assertEqual(audioop.alaw2lin(d, 2), + b'\x00\x08\x01\x08\x02\x10') + self.assertEqual(audioop.alaw2lin(d, 4), + b'\x00\x08\x00\x00\x01\x08\x00\x00\x02\x10\x00\x00') + else: + self.assertEqual(audioop.alaw2lin(d, 2), + b'\x08\x00\x08\x01\x10\x02') + self.assertEqual(audioop.alaw2lin(d, 4), + b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02') def test_lin2ulaw(self): - self.assertEqual(audioop.lin2ulaw(datas[1], 1), - b'\xff\xad\x8e\x0e\x80\x00\x67') - self.assertEqual(audioop.lin2ulaw(datas[2], 2), - b'\xff\xad\x8e\x0e\x80\x00\x7e') - self.assertEqual(audioop.lin2ulaw(datas[4], 4), - b'\xff\xad\x8e\x0e\x80\x00\x7e') + self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb') + self.assertEqual(audioop.lin2ulaw(data[1], 2), b'\xff\xff\xff') + self.assertEqual(audioop.lin2ulaw(data[2], 4), b'\xff\xff\xff') def test_ulaw2lin(self): - encoded = b'\x00\x0e\x28\x3f\x57\x6a\x76\x7c\x7e\x7f'\ - b'\x80\x8e\xa8\xbf\xd7\xea\xf6\xfc\xfe\xff' - src = [-8031, -4447, -1471, -495, -163, -53, -18, -6, -2, 0, - 8031, 4447, 1471, 495, 163, 53, 18, 6, 2, 0] - for w in 1, 2, 4: - self.assertEqual(audioop.ulaw2lin(encoded, w), - packs[w](*(x << (w * 8) >> 14 for x in src))) - - # Current u-law implementation has two codes fo 0: 0x7f and 0xff. - encoded = bytes(range(127)) + bytes(range(128, 256)) - for w in 2, 4: - decoded = audioop.ulaw2lin(encoded, w) - self.assertEqual(audioop.lin2ulaw(decoded, w), encoded) + # Cursory + d = audioop.lin2ulaw(data[0], 1) + self.assertEqual(audioop.ulaw2lin(d, 1), data[0]) + if endian == 'big': + self.assertEqual(audioop.ulaw2lin(d, 2), + b'\x00\x00\x01\x04\x02\x0c') + self.assertEqual(audioop.ulaw2lin(d, 4), + b'\x00\x00\x00\x00\x01\x04\x00\x00\x02\x0c\x00\x00') + else: + self.assertEqual(audioop.ulaw2lin(d, 2), + b'\x00\x00\x04\x01\x0c\x02') + self.assertEqual(audioop.ulaw2lin(d, 4), + b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02') def test_mul(self): - for w in 1, 2, 4: - self.assertEqual(audioop.mul(b'', w, 2), b'') - self.assertEqual(audioop.mul(datas[w], w, 0), - b'\0' * len(datas[w])) - self.assertEqual(audioop.mul(datas[w], w, 1), - datas[w]) - self.assertEqual(audioop.mul(datas[1], 1, 2), - b'\x00\x24\x7f\x80\x7f\x80\xfe') - self.assertEqual(audioop.mul(datas[2], 2, 2), - packs[2](0, 0x2468, 0x7fff, -0x8000, 0x7fff, -0x8000, -2)) - self.assertEqual(audioop.mul(datas[4], 4, 2), - packs[4](0, 0x2468acf0, 0x7fffffff, -0x80000000, - 0x7fffffff, -0x80000000, -2)) + data2 = [] + for d in data: + str = bytearray(len(d)) + for i,b in enumerate(d): + str[i] = 2*b + data2.append(str) + self.assertEqual(audioop.mul(data[0], 1, 2), data2[0]) + self.assertEqual(audioop.mul(data[1],2, 2), data2[1]) + self.assertEqual(audioop.mul(data[2], 4, 2), data2[2]) def test_ratecv(self): - for w in 1, 2, 4: - self.assertEqual(audioop.ratecv(b'', w, 1, 8000, 8000, None), - (b'', (-1, ((0, 0),)))) - self.assertEqual(audioop.ratecv(b'', w, 5, 8000, 8000, None), - (b'', (-1, ((0, 0),) * 5))) - self.assertEqual(audioop.ratecv(b'', w, 1, 8000, 16000, None), - (b'', (-2, ((0, 0),)))) - self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None)[0], - datas[w]) state = None - d1, state = audioop.ratecv(b'\x00\x01\x02', 1, 1, 8000, 16000, state) - d2, state = audioop.ratecv(b'\x00\x01\x02', 1, 1, 8000, 16000, state) + d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state) + d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state) self.assertEqual(d1 + d2, b'\000\000\001\001\002\001\000\000\001\001\002') - for w in 1, 2, 4: - d0, state0 = audioop.ratecv(datas[w], w, 1, 8000, 16000, None) - d, state = b'', None - for i in range(0, len(datas[w]), w): - d1, state = audioop.ratecv(datas[w][i:i + w], w, 1, - 8000, 16000, state) - d += d1 - self.assertEqual(d, d0) - self.assertEqual(state, state0) - def test_reverse(self): - for w in 1, 2, 4: - self.assertEqual(audioop.reverse(b'', w), b'') - self.assertEqual(audioop.reverse(packs[w](0, 1, 2), w), - packs[w](2, 1, 0)) + self.assertEqual(audioop.reverse(data[0], 1), b'\2\1\0') def test_tomono(self): - for w in 1, 2, 4: - data1 = datas[w] - data2 = bytearray(2 * len(data1)) - for k in range(w): - data2[k::2*w] = data1[k::w] - self.assertEqual(audioop.tomono(data2, w, 1, 0), data1) - self.assertEqual(audioop.tomono(data2, w, 0, 1), b'\0' * len(data1)) - for k in range(w): - data2[k+w::2*w] = data1[k::w] - self.assertEqual(audioop.tomono(data2, w, 0.5, 0.5), data1) + data2 = bytearray() + for d in data[0]: + data2.append(d) + data2.append(d) + self.assertEqual(audioop.tomono(data2, 1, 0.5, 0.5), data[0]) def test_tostereo(self): - for w in 1, 2, 4: - data1 = datas[w] - data2 = bytearray(2 * len(data1)) - for k in range(w): - data2[k::2*w] = data1[k::w] - self.assertEqual(audioop.tostereo(data1, w, 1, 0), data2) - self.assertEqual(audioop.tostereo(data1, w, 0, 0), b'\0' * len(data2)) - for k in range(w): - data2[k+w::2*w] = data1[k::w] - self.assertEqual(audioop.tostereo(data1, w, 1, 1), data2) + data2 = bytearray() + for d in data[0]: + data2.append(d) + data2.append(d) + self.assertEqual(audioop.tostereo(data[0], 1, 1, 1), data2) def test_findfactor(self): - self.assertEqual(audioop.findfactor(datas[2], datas[2]), 1.0) - self.assertEqual(audioop.findfactor(b'\0' * len(datas[2]), datas[2]), - 0.0) + self.assertEqual(audioop.findfactor(data[1], data[1]), 1.0) def test_findfit(self): - self.assertEqual(audioop.findfit(datas[2], datas[2]), (0, 1.0)) - self.assertEqual(audioop.findfit(datas[2], packs[2](1, 2, 0)), - (1, 8038.8)) - self.assertEqual(audioop.findfit(datas[2][:-2] * 5 + datas[2], datas[2]), - (30, 1.0)) + self.assertEqual(audioop.findfit(data[1], data[1]), (0, 1.0)) def test_findmax(self): - self.assertEqual(audioop.findmax(datas[2], 1), 5) + self.assertEqual(audioop.findmax(data[1], 1), 2) def test_getsample(self): - for w in 1, 2, 4: - data = packs[w](0, 1, -1, maxvalues[w], minvalues[w]) - self.assertEqual(audioop.getsample(data, w, 0), 0) - self.assertEqual(audioop.getsample(data, w, 1), 1) - self.assertEqual(audioop.getsample(data, w, 2), -1) - self.assertEqual(audioop.getsample(data, w, 3), maxvalues[w]) - self.assertEqual(audioop.getsample(data, w, 4), minvalues[w]) + for i in range(3): + self.assertEqual(audioop.getsample(data[0], 1, i), i) + self.assertEqual(audioop.getsample(data[1], 2, i), i) + self.assertEqual(audioop.getsample(data[2], 4, i), i) def test_negativelen(self): # from issue 3306, previously it segfaulted self.assertRaises(audioop.error, - audioop.findmax, bytes(range(256)), -2392392) + audioop.findmax, ''.join(chr(x) for x in range(256)), -2392392) def test_issue7673(self): state = None @@ -367,9 +222,9 @@ self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state) def test_wrongsize(self): - data = b'abcdefgh' + data = b'abc' state = None - for size in (-1, 0, 3, 5, 1024): + for size in (-1, 3, 5): self.assertRaises(audioop.error, audioop.ulaw2lin, data, size) self.assertRaises(audioop.error, audioop.alaw2lin, data, size) self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_base64.py --- a/Lib/test/test_base64.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_base64.py Fri Feb 01 23:12:09 2013 +0100 @@ -22,8 +22,6 @@ b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") - # Non-bytes - eq(base64.encodebytes(bytearray(b'abc')), b'YWJj\n') self.assertRaises(TypeError, base64.encodebytes, "") def test_decodebytes(self): @@ -39,13 +37,11 @@ b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"0123456789!@#0^&*();:<>,. []{}") eq(base64.decodebytes(b''), b'') - # Non-bytes - eq(base64.decodebytes(bytearray(b'YWJj\n')), b'abc') self.assertRaises(TypeError, base64.decodebytes, "") def test_encode(self): eq = self.assertEqual - from io import BytesIO, StringIO + from io import BytesIO infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz' b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' b'0123456789!@#0^&*();:<>,. []{}') @@ -55,21 +51,13 @@ b'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE' b'RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT' b'Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n') - # Non-binary files - self.assertRaises(TypeError, base64.encode, StringIO('abc'), BytesIO()) - self.assertRaises(TypeError, base64.encode, BytesIO(b'abc'), StringIO()) - self.assertRaises(TypeError, base64.encode, StringIO('abc'), StringIO()) def test_decode(self): - from io import BytesIO, StringIO + from io import BytesIO infp = BytesIO(b'd3d3LnB5dGhvbi5vcmc=') outfp = BytesIO() base64.decode(infp, outfp) self.assertEqual(outfp.getvalue(), b'www.python.org') - # Non-binary files - self.assertRaises(TypeError, base64.encode, StringIO('YWJj\n'), BytesIO()) - self.assertRaises(TypeError, base64.encode, BytesIO(b'YWJj\n'), StringIO()) - self.assertRaises(TypeError, base64.encode, StringIO('YWJj\n'), StringIO()) class BaseXYTestCase(unittest.TestCase): @@ -90,10 +78,6 @@ b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") # Test with arbitrary alternative characters eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'*$'), b'01a*b$cd') - # Non-bytes - eq(base64.b64encode(bytearray(b'abcd')), b'YWJjZA==') - eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=bytearray(b'*$')), - b'01a*b$cd') # Check if passing a str object raises an error self.assertRaises(TypeError, base64.b64encode, "") self.assertRaises(TypeError, base64.b64encode, b"", altchars="") @@ -109,14 +93,11 @@ b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") - # Non-bytes - eq(base64.standard_b64encode(bytearray(b'abcd')), b'YWJjZA==') # Check if passing a str object raises an error self.assertRaises(TypeError, base64.standard_b64encode, "") + self.assertRaises(TypeError, base64.standard_b64encode, b"", altchars="") # Test with 'URL safe' alternative characters eq(base64.urlsafe_b64encode(b'\xd3V\xbeo\xf7\x1d'), b'01a-b_cd') - # Non-bytes - eq(base64.urlsafe_b64encode(bytearray(b'\xd3V\xbeo\xf7\x1d')), b'01a-b_cd') # Check if passing a str object raises an error self.assertRaises(TypeError, base64.urlsafe_b64encode, "") @@ -140,8 +121,6 @@ for data, res in tests.items(): eq(base64.b64decode(data), res) eq(base64.b64decode(data.decode('ascii')), res) - # Non-bytes - eq(base64.b64decode(bytearray(b"YWJj")), b"abc") # Test with arbitrary alternative characters tests_altchars = {(b'01a*b$cd', b'*$'): b'\xd3V\xbeo\xf7\x1d', @@ -159,8 +138,6 @@ for data, res in tests.items(): eq(base64.standard_b64decode(data), res) eq(base64.standard_b64decode(data.decode('ascii')), res) - # Non-bytes - eq(base64.standard_b64decode(bytearray(b"YWJj")), b"abc") # Test with 'URL safe' alternative characters tests_urlsafe = {b'01a-b_cd': b'\xd3V\xbeo\xf7\x1d', @@ -169,8 +146,6 @@ for data, res in tests_urlsafe.items(): eq(base64.urlsafe_b64decode(data), res) eq(base64.urlsafe_b64decode(data.decode('ascii')), res) - # Non-bytes - eq(base64.urlsafe_b64decode(bytearray(b'01a-b_cd')), b'\xd3V\xbeo\xf7\x1d') def test_b64decode_padding_error(self): self.assertRaises(binascii.Error, base64.b64decode, b'abc') @@ -204,8 +179,6 @@ eq(base64.b32encode(b'abc'), b'MFRGG===') eq(base64.b32encode(b'abcd'), b'MFRGGZA=') eq(base64.b32encode(b'abcde'), b'MFRGGZDF') - # Non-bytes - eq(base64.b32encode(bytearray(b'abcd')), b'MFRGGZA=') self.assertRaises(TypeError, base64.b32encode, "") def test_b32decode(self): @@ -221,8 +194,6 @@ for data, res in tests.items(): eq(base64.b32decode(data), res) eq(base64.b32decode(data.decode('ascii')), res) - # Non-bytes - eq(base64.b32decode(bytearray(b'MFRGG===')), b'abc') def test_b32decode_casefold(self): eq = self.assertEqual @@ -244,8 +215,8 @@ eq(base64.b32decode(data, True), res) eq(base64.b32decode(data.decode('ascii'), True), res) - self.assertRaises(binascii.Error, base64.b32decode, b'me======') - self.assertRaises(binascii.Error, base64.b32decode, 'me======') + self.assertRaises(TypeError, base64.b32decode, b'me======') + self.assertRaises(TypeError, base64.b32decode, 'me======') # Mapping zero and one eq(base64.b32decode(b'MLO23456'), b'b\xdd\xad\xf3\xbe') @@ -262,11 +233,9 @@ eq(base64.b32decode(data_str, map01=map01), res) eq(base64.b32decode(data, map01=map01_str), res) eq(base64.b32decode(data_str, map01=map01_str), res) - self.assertRaises(binascii.Error, base64.b32decode, data) - self.assertRaises(binascii.Error, base64.b32decode, data_str) def test_b32decode_error(self): - for data in [b'abc', b'ABCDEF==', b'==ABCDEF']: + for data in [b'abc', b'ABCDEF==']: with self.assertRaises(binascii.Error): base64.b32decode(data) with self.assertRaises(binascii.Error): @@ -276,8 +245,6 @@ eq = self.assertEqual eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF') eq(base64.b16encode(b'\x00'), b'00') - # Non-bytes - eq(base64.b16encode(bytearray(b'\x01\x02\xab\xcd\xef')), b'0102ABCDEF') self.assertRaises(TypeError, base64.b16encode, "") def test_b16decode(self): @@ -292,8 +259,6 @@ # Case fold eq(base64.b16decode(b'0102abcdef', True), b'\x01\x02\xab\xcd\xef') eq(base64.b16decode('0102abcdef', True), b'\x01\x02\xab\xcd\xef') - # Non-bytes - eq(base64.b16decode(bytearray(b"0102ABCDEF")), b'\x01\x02\xab\xcd\xef') def test_decode_nonascii_str(self): decode_funcs = (base64.b64decode, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_bisect.py --- a/Lib/test/test_bisect.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_bisect.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,7 +7,7 @@ c_bisect = support.import_fresh_module('bisect', fresh=['_bisect']) class Range(object): - """A trivial range()-like object that has an insert() method.""" + """A trivial range()-like object without any integer width limitations.""" def __init__(self, start, stop): self.start = start self.stop = stop @@ -120,10 +120,10 @@ def test_negative_lo(self): # Issue 3301 mod = self.module - self.assertRaises(ValueError, mod.bisect_left, [1, 2, 3], 5, -1, 3) - self.assertRaises(ValueError, mod.bisect_right, [1, 2, 3], 5, -1, 3) - self.assertRaises(ValueError, mod.insort_left, [1, 2, 3], 5, -1, 3) - self.assertRaises(ValueError, mod.insort_right, [1, 2, 3], 5, -1, 3) + self.assertRaises(ValueError, mod.bisect_left, [1, 2, 3], 5, -1, 3), + self.assertRaises(ValueError, mod.bisect_right, [1, 2, 3], 5, -1, 3), + self.assertRaises(ValueError, mod.insort_left, [1, 2, 3], 5, -1, 3), + self.assertRaises(ValueError, mod.insort_right, [1, 2, 3], 5, -1, 3), def test_large_range(self): # Issue 13496 diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_buffer.py --- a/Lib/test/test_buffer.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_buffer.py Fri Feb 01 23:12:09 2013 +0100 @@ -4283,5 +4283,9 @@ self.assertRaises(BufferError, memoryview, x) +def test_main(): + support.run_unittest(TestBufferProtocol) + + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_builtin.py Fri Feb 01 23:12:09 2013 +0100 @@ -180,7 +180,6 @@ self.assertRaises(TypeError, all) # No args self.assertRaises(TypeError, all, [2, 4, 6], []) # Too many args self.assertEqual(all([]), True) # Empty iterator - self.assertEqual(all([0, TestFailingBool()]), False)# Short-circuit S = [50, 60] self.assertEqual(all(x > 42 for x in S), True) S = [50, 40, 60] @@ -190,12 +189,11 @@ self.assertEqual(any([None, None, None]), False) self.assertEqual(any([None, 4, None]), True) self.assertRaises(RuntimeError, any, [None, TestFailingBool(), 6]) - self.assertRaises(RuntimeError, any, TestFailingIter()) + self.assertRaises(RuntimeError, all, TestFailingIter()) self.assertRaises(TypeError, any, 10) # Non-iterable self.assertRaises(TypeError, any) # No args self.assertRaises(TypeError, any, [2, 4, 6], []) # Too many args self.assertEqual(any([]), False) # Empty iterator - self.assertEqual(any([1, TestFailingBool()]), True) # Short-circuit S = [40, 60, 30] self.assertEqual(any(x > 42 for x in S), True) S = [10, 20, 30] @@ -584,10 +582,7 @@ raise frozendict_error("frozendict is readonly") # read-only builtins - if isinstance(__builtins__, types.ModuleType): - frozen_builtins = frozendict(__builtins__.__dict__) - else: - frozen_builtins = frozendict(__builtins__) + frozen_builtins = frozendict(__builtins__) code = compile("__builtins__['superglobal']=2; print(superglobal)", "test", "exec") self.assertRaises(frozendict_error, exec, code, {'__builtins__': frozen_builtins}) @@ -847,19 +842,8 @@ self.assertEqual(max(1, 2.0, 3), 3) self.assertEqual(max(1.0, 2, 3), 3) - self.assertRaises(TypeError, max) - self.assertRaises(TypeError, max, 42) - self.assertRaises(ValueError, max, ()) - class BadSeq: - def __getitem__(self, index): - raise ValueError - self.assertRaises(ValueError, max, BadSeq()) - for stmt in ( "max(key=int)", # no args - "max(default=None)", - "max(1, 2, default=None)", # require container for default - "max(default=None, key=int)", "max(1, key=int)", # single arg not iterable "max(1, 2, keystone=int)", # wrong keyword "max(1, 2, key=int, abc=int)", # two many keywords @@ -876,13 +860,6 @@ self.assertEqual(max((1,2), key=neg), 1) # two elem iterable self.assertEqual(max(1, 2, key=neg), 1) # two elems - self.assertEqual(max((), default=None), None) # zero elem iterable - self.assertEqual(max((1,), default=None), 1) # one elem iterable - self.assertEqual(max((1,2), default=None), 2) # two elem iterable - - self.assertEqual(max((), default=1, key=neg), 1) - self.assertEqual(max((1, 2), default=3, key=neg), 1) - data = [random.randrange(200) for i in range(100)] keys = dict((elem, random.randrange(50)) for elem in data) f = keys.__getitem__ @@ -909,9 +886,6 @@ for stmt in ( "min(key=int)", # no args - "min(default=None)", - "min(1, 2, default=None)", # require container for default - "min(default=None, key=int)", "min(1, key=int)", # single arg not iterable "min(1, 2, keystone=int)", # wrong keyword "min(1, 2, key=int, abc=int)", # two many keywords @@ -928,13 +902,6 @@ self.assertEqual(min((1,2), key=neg), 2) # two elem iterable self.assertEqual(min(1, 2, key=neg), 2) # two elems - self.assertEqual(min((), default=None), None) # zero elem iterable - self.assertEqual(min((1,), default=None), 1) # one elem iterable - self.assertEqual(min((1,2), default=None), 1) # two elem iterable - - self.assertEqual(min((), default=1, key=neg), 1) - self.assertEqual(min((1, 2), default=1, key=neg), 2) - data = [random.randrange(200) for i in range(100)] keys = dict((elem, random.randrange(50)) for elem in data) f = keys.__getitem__ @@ -976,29 +943,24 @@ def write_testfile(self): # NB the first 4 lines are also used to test input, below fp = open(TESTFN, 'w') - try: + self.addCleanup(unlink, TESTFN) + with fp: fp.write('1+1\n') fp.write('The quick brown fox jumps over the lazy dog') fp.write('.\n') fp.write('Dear John\n') fp.write('XXX'*100) fp.write('YYY'*100) - finally: - fp.close() def test_open(self): self.write_testfile() - fp = open(TESTFN, 'r') - try: + with open(TESTFN, 'r') as fp: self.assertEqual(fp.readline(4), '1+1\n') self.assertEqual(fp.readline(), 'The quick brown fox jumps over the lazy dog.\n') self.assertEqual(fp.readline(4), 'Dear') self.assertEqual(fp.readline(100), ' John\n') self.assertEqual(fp.read(300), 'XXX'*100) self.assertEqual(fp.read(1000), 'YYY'*100) - finally: - fp.close() - unlink(TESTFN) def test_open_default_encoding(self): old_environ = dict(os.environ) @@ -1012,16 +974,29 @@ self.write_testfile() current_locale_encoding = locale.getpreferredencoding(False) - fp = open(TESTFN, 'w') - try: + with open(TESTFN, 'w') as fp: self.assertEqual(fp.encoding, current_locale_encoding) - finally: - fp.close() - unlink(TESTFN) finally: os.environ.clear() os.environ.update(old_environ) + @unittest.skipUnless(hasattr(os, "get_cloexec"), "need os.get_cloexec()") + def test_open_cloexec(self): + self.write_testfile() + old_cloexec = sys.getdefaultcloexec() + try: + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + fileobj = open(TESTFN) + else: + fileobj = open(TESTFN, cloexec=cloexec) + with fileobj: + self.assertEqual(os.get_cloexec(fileobj.fileno()), cloexec) + finally: + sys.setdefaultcloexec(old_cloexec) + def test_ord(self): self.assertEqual(ord(' '), 32) self.assertEqual(ord('A'), 65) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_bytes.py Fri Feb 01 23:12:09 2013 +0100 @@ -700,7 +700,9 @@ type2test = bytes def test_buffer_is_readonly(self): - fd = os.dup(sys.stdin.fileno()) + # On Windows, setting HANDLE_FLAG_INHERIT flag on a standard stream + # fails with ERROR_INVALID_PARAMETER (87) + fd = os.dup(sys.stdin.fileno(), cloexec=False) with open(fd, "rb", buffering=0) as f: self.assertRaises(TypeError, f.readinto, b"") @@ -1172,7 +1174,6 @@ self.assertEqual(bytes(b"abc") < b"ab", False) self.assertEqual(bytes(b"abc") <= b"ab", False) - @test.support.requires_docstrings def test_doc(self): self.assertIsNotNone(bytearray.__doc__) self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_bz2.py --- a/Lib/test/test_bz2.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_bz2.py Fri Feb 01 23:12:09 2013 +0100 @@ -569,19 +569,6 @@ bz2f.seek(-150, 1) self.assertEqual(bz2f.read(), self.TEXT[500-150:]) - def test_read_truncated(self): - # Drop the eos_magic field (6 bytes) and CRC (4 bytes). - truncated = self.DATA[:-10] - with BZ2File(BytesIO(truncated)) as f: - self.assertRaises(EOFError, f.read) - with BZ2File(BytesIO(truncated)) as f: - self.assertEqual(f.read(len(self.TEXT)), self.TEXT) - self.assertRaises(EOFError, f.read, 1) - # Incomplete 4-byte file header, and block header of at least 146 bits. - for i in range(22): - with BZ2File(BytesIO(truncated[:i])) as f: - self.assertRaises(EOFError, f.read, 1) - class BZ2CompressorTest(BaseTest): def testCompress(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_calendar.py --- a/Lib/test/test_calendar.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_calendar.py Fri Feb 01 23:12:09 2013 +0100 @@ -457,21 +457,11 @@ # (it is still not thread-safe though) old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: - cal = calendar.LocaleTextCalendar(locale='') - local_weekday = cal.formatweekday(1, 10) - local_month = cal.formatmonthname(2010, 10, 10) + calendar.LocaleTextCalendar(locale='').formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test - raise unittest.SkipTest('cannot set the system default locale') - self.assertIsInstance(local_weekday, str) - self.assertIsInstance(local_month, str) - self.assertEqual(len(local_weekday), 10) - self.assertGreaterEqual(len(local_month), 10) - cal = calendar.LocaleHTMLCalendar(locale='') - local_weekday = cal.formatweekday(1) - local_month = cal.formatmonthname(2010, 10) - self.assertIsInstance(local_weekday, str) - self.assertIsInstance(local_month, str) + return + calendar.LocaleHTMLCalendar(locale='').formatmonthname(2010, 10) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_capi.py Fri Feb 01 23:12:09 2013 +0100 @@ -44,12 +44,11 @@ @unittest.skipUnless(threading, 'Threading required for this test.') def test_no_FatalError_infinite_loop(self): - with support.suppress_crash_popup(): - p = subprocess.Popen([sys.executable, "-c", - 'import _testcapi;' - '_testcapi.crash_no_current_thread()'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p = subprocess.Popen([sys.executable, "-c", + 'import _testcapi;' + '_testcapi.crash_no_current_thread()'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) (out, err) = p.communicate() self.assertEqual(out, b'') # This used to cause an infinite loop. @@ -194,6 +193,7 @@ self.pendingcalls_wait(l, n) def test_subinterps(self): + # XXX this test leaks in refleak runs import builtins r, w = os.pipe() code = """if 1: @@ -327,34 +327,9 @@ self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords, (), {}, b'', [42]) -@unittest.skipUnless(threading, 'Threading required for this test.') -class TestThreadState(unittest.TestCase): - - @support.reap_threads - def test_thread_state(self): - # some extra thread-state tests driven via _testcapi - def target(): - idents = [] - - def callback(): - idents.append(threading.get_ident()) - - _testcapi._test_thread_state(callback) - a = b = callback - time.sleep(1) - # Check our main thread is in the list exactly 3 times. - self.assertEqual(idents.count(threading.get_ident()), 3, - "Couldn't find main thread correctly in the list") - - target() - t = threading.Thread(target=target) - t.start() - t.join() - - def test_main(): - support.run_unittest(CAPITest, TestPendingCalls, Test6012, - EmbeddingTest, SkipitemTest, TestThreadState) + support.run_unittest(CAPITest, TestPendingCalls, + Test6012, EmbeddingTest, SkipitemTest) for name in dir(_testcapi): if name.startswith('test_'): @@ -363,5 +338,31 @@ print("internal", name) test() + # some extra thread-state tests driven via _testcapi + def TestThreadState(): + if support.verbose: + print("auto-thread-state") + + idents = [] + + def callback(): + idents.append(threading.get_ident()) + + _testcapi._test_thread_state(callback) + a = b = callback + time.sleep(1) + # Check our main thread is in the list exactly 3 times. + if idents.count(threading.get_ident()) != 3: + raise support.TestFailed( + "Couldn't find main thread correctly in the list") + + if threading: + import time + TestThreadState() + t = threading.Thread(target=TestThreadState) + t.start() + t.join() + + if __name__ == "__main__": test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_cgi.py --- a/Lib/test/test_cgi.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_cgi.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,6 @@ import tempfile import unittest import warnings -from collections import namedtuple from io import StringIO, BytesIO class HackedSysModule: @@ -120,23 +119,6 @@ class CgiTests(unittest.TestCase): - def test_parse_multipart(self): - fp = BytesIO(POSTDATA.encode('latin1')) - env = {'boundary': BOUNDARY.encode('latin1'), - 'CONTENT-LENGTH': '558'} - result = cgi.parse_multipart(fp, env) - expected = {'submit': [b' Add '], 'id': [b'1234'], - 'file': [b'Testing 123.\n'], 'title': [b'']} - self.assertEqual(result, expected) - - def test_fieldstorage_properties(self): - fs = cgi.FieldStorage() - self.assertFalse(fs) - self.assertIn("FieldStorage", repr(fs)) - self.assertEqual(list(fs), list(fs.keys())) - fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue')) - self.assertTrue(fs) - def test_escape(self): # cgi.escape() is deprecated. with warnings.catch_warnings(): @@ -256,50 +238,6 @@ got = getattr(fs.list[x], k) self.assertEqual(got, exp) - def test_fieldstorage_multipart_maxline(self): - # Issue #18167 - maxline = 1 << 16 - self.maxDiff = None - def check(content): - data = """---123 -Content-Disposition: form-data; name="upload"; filename="fake.txt" -Content-Type: text/plain - -%s ----123-- -""".replace('\n', '\r\n') % content - environ = { - 'CONTENT_LENGTH': str(len(data)), - 'CONTENT_TYPE': 'multipart/form-data; boundary=-123', - 'REQUEST_METHOD': 'POST', - } - self.assertEqual(gen_result(data, environ), - {'upload': content.encode('latin1')}) - check('x' * (maxline - 1)) - check('x' * (maxline - 1) + '\r') - check('x' * (maxline - 1) + '\r' + 'y' * (maxline - 1)) - - def test_fieldstorage_multipart_w3c(self): - # Test basic FieldStorage multipart parsing (W3C sample) - env = { - 'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY_W3), - 'CONTENT_LENGTH': str(len(POSTDATA_W3))} - fp = BytesIO(POSTDATA_W3.encode('latin-1')) - fs = cgi.FieldStorage(fp, environ=env, encoding="latin-1") - self.assertEqual(len(fs.list), 2) - self.assertEqual(fs.list[0].name, 'submit-name') - self.assertEqual(fs.list[0].value, 'Larry') - self.assertEqual(fs.list[1].name, 'files') - files = fs.list[1].value - self.assertEqual(len(files), 2) - expect = [{'name': None, 'filename': 'file1.txt', 'value': b'... contents of file1.txt ...'}, - {'name': None, 'filename': 'file2.gif', 'value': b'...contents of file2.gif...'}] - for x in range(len(files)): - for k, exp in expect[x].items(): - got = getattr(files[x], k) - self.assertEqual(got, exp) - _qs_result = { 'key1': 'value1', 'key2': ['value2x', 'value2y'], @@ -449,31 +387,6 @@ -----------------------------721837373350705526688164684 """ -# http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4 -BOUNDARY_W3 = "AaB03x" -POSTDATA_W3 = """--AaB03x -Content-Disposition: form-data; name="submit-name" - -Larry ---AaB03x -Content-Disposition: form-data; name="files" -Content-Type: multipart/mixed; boundary=BbC04y - ---BbC04y -Content-Disposition: file; filename="file1.txt" -Content-Type: text/plain - -... contents of file1.txt ... ---BbC04y -Content-Disposition: file; filename="file2.gif" -Content-Type: image/gif -Content-Transfer-Encoding: binary - -...contents of file2.gif... ---BbC04y-- ---AaB03x-- -""" - def test_main(): run_unittest(CgiTests) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_cmd_line.py Fri Feb 01 23:12:09 2013 +0100 @@ -41,10 +41,8 @@ def test_version(self): version = ('Python %d.%d' % sys.version_info[:2]).encode("ascii") - for switch in '-V', '--version': - rc, out, err = assert_python_ok(switch) - self.assertFalse(err.startswith(version)) - self.assertTrue(out.startswith(version)) + rc, out, err = assert_python_ok('-V') + self.assertTrue(err.startswith(version)) def test_verbose(self): # -v causes imports to write to stderr. If the write to @@ -56,49 +54,14 @@ self.assertNotIn(b'stack overflow', err) def test_xoptions(self): - def get_xoptions(*args): - # use subprocess module directly because test.script_helper adds - # "-X faulthandler" to the command line - args = (sys.executable, '-E') + args - args += ('-c', 'import sys; print(sys._xoptions)') - out = subprocess.check_output(args) - opts = eval(out.splitlines()[0]) - return opts - - opts = get_xoptions() + rc, out, err = assert_python_ok('-c', 'import sys; print(sys._xoptions)') + opts = eval(out.splitlines()[0]) self.assertEqual(opts, {}) - - opts = get_xoptions('-Xa', '-Xb=c,d=e') + rc, out, err = assert_python_ok( + '-Xa', '-Xb=c,d=e', '-c', 'import sys; print(sys._xoptions)') + opts = eval(out.splitlines()[0]) self.assertEqual(opts, {'a': True, 'b': 'c,d=e'}) - def test_showrefcount(self): - def run_python(*args): - # this is similar to assert_python_ok but doesn't strip - # the refcount from stderr. It can be replaced once - # assert_python_ok stops doing that. - cmd = [sys.executable] - cmd.extend(args) - PIPE = subprocess.PIPE - p = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE) - out, err = p.communicate() - p.stdout.close() - p.stderr.close() - rc = p.returncode - self.assertEqual(rc, 0) - return rc, out, err - code = 'import sys; print(sys._xoptions)' - # normally the refcount is hidden - rc, out, err = run_python('-c', code) - self.assertEqual(out.rstrip(), b'{}') - self.assertEqual(err, b'') - # "-X showrefcount" shows the refcount, but only in debug builds - rc, out, err = run_python('-X', 'showrefcount', '-c', code) - self.assertEqual(out.rstrip(), b"{'showrefcount': True}") - if hasattr(sys, 'gettotalrefcount'): # debug build - self.assertRegex(err, br'^\[\d+ refs, \d+ blocks\]') - else: - self.assertEqual(err, b'') - def test_run_module(self): # Test expected operation of the '-m' switch # Switch needs an argument @@ -107,9 +70,9 @@ assert_python_failure('-m', 'fnord43520xyz') # Check the runpy module also gives an error for # a nonexistent module - assert_python_failure('-m', 'runpy', 'fnord43520xyz') + assert_python_failure('-m', 'runpy', 'fnord43520xyz'), # All good if module is located and run successfully - assert_python_ok('-m', 'timeit', '-n', '1') + assert_python_ok('-m', 'timeit', '-n', '1'), def test_run_module_bug1764407(self): # -m and -i need to play well together diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_codeccallbacks.py --- a/Lib/test/test_codeccallbacks.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_codeccallbacks.py Fri Feb 01 23:12:09 2013 +0100 @@ -271,12 +271,12 @@ self.assertEqual( b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1"), - "\u3042[<92><117><51>]xxx" + "\u3042[<92><117><51><120>]xx" ) self.assertEqual( b"\\u3042\u3xx".decode("unicode-escape", "test.handler1"), - "\u3042[<92><117><51>]xx" + "\u3042[<92><117><51><120><120>]" ) self.assertEqual( @@ -875,6 +875,8 @@ with self.assertRaises(TypeError): data.decode(encoding, "test.replacing") +def test_main(): + test.support.run_unittest(CodecCallbackTest) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_codecs.py Fri Feb 01 23:12:09 2013 +0100 @@ -21,11 +21,6 @@ else: SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar) -def coding_checker(self, coder): - def check(input, expect): - self.assertEqual(coder(input), (expect, len(input))) - return check - class Queue(object): """ queue: write bytes at one end, read bytes from the other end @@ -930,55 +925,7 @@ class EscapeDecodeTest(unittest.TestCase): def test_empty(self): - self.assertEqual(codecs.escape_decode(b""), (b"", 0)) - - def test_raw(self): - decode = codecs.escape_decode - for b in range(256): - b = bytes([b]) - if b != b'\\': - self.assertEqual(decode(b + b'0'), (b + b'0', 2)) - - def test_escape(self): - decode = codecs.escape_decode - check = coding_checker(self, decode) - check(b"[\\\n]", b"[]") - check(br'[\"]', b'["]') - check(br"[\']", b"[']") - check(br"[\\]", br"[\]") - check(br"[\a]", b"[\x07]") - check(br"[\b]", b"[\x08]") - check(br"[\t]", b"[\x09]") - check(br"[\n]", b"[\x0a]") - check(br"[\v]", b"[\x0b]") - check(br"[\f]", b"[\x0c]") - check(br"[\r]", b"[\x0d]") - check(br"[\7]", b"[\x07]") - check(br"[\8]", br"[\8]") - check(br"[\78]", b"[\x078]") - check(br"[\41]", b"[!]") - check(br"[\418]", b"[!8]") - check(br"[\101]", b"[A]") - check(br"[\1010]", b"[A0]") - check(br"[\501]", b"[A]") - check(br"[\x41]", b"[A]") - check(br"[\X41]", br"[\X41]") - check(br"[\x410]", b"[A0]") - for b in range(256): - if b not in b'\n"\'\\abtnvfr01234567x': - b = bytes([b]) - check(b'\\' + b, b'\\' + b) - - def test_errors(self): - decode = codecs.escape_decode - self.assertRaises(ValueError, decode, br"\x") - self.assertRaises(ValueError, decode, br"[\x]") - self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6)) - self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6)) - self.assertRaises(ValueError, decode, br"\x0") - self.assertRaises(ValueError, decode, br"[\x0]") - self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8)) - self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8)) + self.assertEqual(codecs.escape_decode(""), (b"", 0)) class RecodingTest(unittest.TestCase): def test_recoding(self): @@ -2018,135 +1965,6 @@ self.assertRaises(UnicodeDecodeError, codecs.raw_unicode_escape_decode, br"\U00110000") self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10)) - -class UnicodeEscapeTest(unittest.TestCase): - def test_empty(self): - self.assertEqual(codecs.unicode_escape_encode(""), (b"", 0)) - self.assertEqual(codecs.unicode_escape_decode(b""), ("", 0)) - - def test_raw_encode(self): - encode = codecs.unicode_escape_encode - for b in range(32, 127): - if b != b'\\'[0]: - self.assertEqual(encode(chr(b)), (bytes([b]), 1)) - - def test_raw_decode(self): - decode = codecs.unicode_escape_decode - for b in range(256): - if b != b'\\'[0]: - self.assertEqual(decode(bytes([b]) + b'0'), (chr(b) + '0', 2)) - - def test_escape_encode(self): - encode = codecs.unicode_escape_encode - check = coding_checker(self, encode) - check('\t', br'\t') - check('\n', br'\n') - check('\r', br'\r') - check('\\', br'\\') - for b in range(32): - if chr(b) not in '\t\n\r': - check(chr(b), ('\\x%02x' % b).encode()) - for b in range(127, 256): - check(chr(b), ('\\x%02x' % b).encode()) - check('\u20ac', br'\u20ac') - check('\U0001d120', br'\U0001d120') - - def test_escape_decode(self): - decode = codecs.unicode_escape_decode - check = coding_checker(self, decode) - check(b"[\\\n]", "[]") - check(br'[\"]', '["]') - check(br"[\']", "[']") - check(br"[\\]", r"[\]") - check(br"[\a]", "[\x07]") - check(br"[\b]", "[\x08]") - check(br"[\t]", "[\x09]") - check(br"[\n]", "[\x0a]") - check(br"[\v]", "[\x0b]") - check(br"[\f]", "[\x0c]") - check(br"[\r]", "[\x0d]") - check(br"[\7]", "[\x07]") - check(br"[\8]", r"[\8]") - check(br"[\78]", "[\x078]") - check(br"[\41]", "[!]") - check(br"[\418]", "[!8]") - check(br"[\101]", "[A]") - check(br"[\1010]", "[A0]") - check(br"[\x41]", "[A]") - check(br"[\x410]", "[A0]") - check(br"\u20ac", "\u20ac") - check(br"\U0001d120", "\U0001d120") - for b in range(256): - if b not in b'\n"\'\\abtnvfr01234567xuUN': - check(b'\\' + bytes([b]), '\\' + chr(b)) - - def test_decode_errors(self): - decode = codecs.unicode_escape_decode - for c, d in (b'x', 2), (b'u', 4), (b'U', 4): - for i in range(d): - self.assertRaises(UnicodeDecodeError, decode, - b"\\" + c + b"0"*i) - self.assertRaises(UnicodeDecodeError, decode, - b"[\\" + c + b"0"*i + b"]") - data = b"[\\" + c + b"0"*i + b"]\\" + c + b"0"*i - self.assertEqual(decode(data, "ignore"), ("[]", len(data))) - self.assertEqual(decode(data, "replace"), - ("[\ufffd]\ufffd", len(data))) - self.assertRaises(UnicodeDecodeError, decode, br"\U00110000") - self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10)) - self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10)) - - -class RawUnicodeEscapeTest(unittest.TestCase): - def test_empty(self): - self.assertEqual(codecs.raw_unicode_escape_encode(""), (b"", 0)) - self.assertEqual(codecs.raw_unicode_escape_decode(b""), ("", 0)) - - def test_raw_encode(self): - encode = codecs.raw_unicode_escape_encode - for b in range(256): - self.assertEqual(encode(chr(b)), (bytes([b]), 1)) - - def test_raw_decode(self): - decode = codecs.raw_unicode_escape_decode - for b in range(256): - self.assertEqual(decode(bytes([b]) + b'0'), (chr(b) + '0', 2)) - - def test_escape_encode(self): - encode = codecs.raw_unicode_escape_encode - check = coding_checker(self, encode) - for b in range(256): - if b not in b'uU': - check('\\' + chr(b), b'\\' + bytes([b])) - check('\u20ac', br'\u20ac') - check('\U0001d120', br'\U0001d120') - - def test_escape_decode(self): - decode = codecs.raw_unicode_escape_decode - check = coding_checker(self, decode) - for b in range(256): - if b not in b'uU': - check(b'\\' + bytes([b]), '\\' + chr(b)) - check(br"\u20ac", "\u20ac") - check(br"\U0001d120", "\U0001d120") - - def test_decode_errors(self): - decode = codecs.raw_unicode_escape_decode - for c, d in (b'u', 4), (b'U', 4): - for i in range(d): - self.assertRaises(UnicodeDecodeError, decode, - b"\\" + c + b"0"*i) - self.assertRaises(UnicodeDecodeError, decode, - b"[\\" + c + b"0"*i + b"]") - data = b"[\\" + c + b"0"*i + b"]\\" + c + b"0"*i - self.assertEqual(decode(data, "ignore"), ("[]", len(data))) - self.assertEqual(decode(data, "replace"), - ("[\ufffd]\ufffd", len(data))) - self.assertRaises(UnicodeDecodeError, decode, br"\U00110000") - self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10)) - self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10)) - - class SurrogateEscapeTest(unittest.TestCase): def test_utf8(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_coding.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_coding.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,65 @@ +import test.support, unittest +from test.support import TESTFN, unlink, unload +import importlib, os, sys + +class CodingTest(unittest.TestCase): + def test_bad_coding(self): + module_name = 'bad_coding' + self.verify_bad_module(module_name) + + def test_bad_coding2(self): + module_name = 'bad_coding2' + self.verify_bad_module(module_name) + + def verify_bad_module(self, module_name): + self.assertRaises(SyntaxError, __import__, 'test.' + module_name) + + path = os.path.dirname(__file__) + filename = os.path.join(path, module_name + '.py') + with open(filename, "rb") as fp: + bytes = fp.read() + self.assertRaises(SyntaxError, compile, bytes, filename, 'exec') + + def test_exec_valid_coding(self): + d = {} + exec('# coding: cp949\na = 5\n', d) + self.assertEqual(d['a'], 5) + + def test_file_parse(self): + # issue1134: all encodings outside latin-1 and utf-8 fail on + # multiline strings and long lines (>512 columns) + unload(TESTFN) + sys.path.insert(0, os.curdir) + filename = TESTFN + ".py" + f = open(filename, "w") + try: + f.write("# -*- coding: cp1252 -*-\n") + f.write("'''A short string\n") + f.write("'''\n") + f.write("'A very long string %s'\n" % ("X" * 1000)) + f.close() + + importlib.invalidate_caches() + __import__(TESTFN) + finally: + f.close() + unlink(filename) + unlink(filename + "c") + unload(TESTFN) + del sys.path[0] + + def test_error_from_string(self): + # See http://bugs.python.org/issue6289 + input = "# coding: ascii\n\N{SNOWMAN}".encode('utf-8') + with self.assertRaises(SyntaxError) as c: + compile(input, "", "exec") + expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ + "ordinal not in range(128)" + self.assertTrue(c.exception.args[0].startswith(expected)) + + +def test_main(): + test.support.run_unittest(CodingTest) + +if __name__ == "__main__": + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_collections.py --- a/Lib/test/test_collections.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_collections.py Fri Feb 01 23:12:09 2013 +0100 @@ -305,7 +305,6 @@ q = loads(dumps(p, protocol)) self.assertEqual(p, q) self.assertEqual(p._fields, q._fields) - self.assertNotIn(b'OrderedDict', dumps(p, protocol)) def test_copy(self): p = TestNT(x=10, y=20, z=30) @@ -918,26 +917,23 @@ words = Counter('which witch had which witches wrist watch'.split()) update_test = Counter() update_test.update(words) - for label, dup in [ - ('words.copy()', words.copy()), - ('copy.copy(words)', copy.copy(words)), - ('copy.deepcopy(words)', copy.deepcopy(words)), - ('pickle.loads(pickle.dumps(words, 0))', - pickle.loads(pickle.dumps(words, 0))), - ('pickle.loads(pickle.dumps(words, 1))', - pickle.loads(pickle.dumps(words, 1))), - ('pickle.loads(pickle.dumps(words, 2))', - pickle.loads(pickle.dumps(words, 2))), - ('pickle.loads(pickle.dumps(words, -1))', - pickle.loads(pickle.dumps(words, -1))), - ('eval(repr(words))', eval(repr(words))), - ('update_test', update_test), - ('Counter(words)', Counter(words)), - ]: - with self.subTest(label=label): - msg = "\ncopy: %s\nwords: %s" % (dup, words) - self.assertIsNot(dup, words, msg) - self.assertEqual(dup, words) + for i, dup in enumerate([ + words.copy(), + copy.copy(words), + copy.deepcopy(words), + pickle.loads(pickle.dumps(words, 0)), + pickle.loads(pickle.dumps(words, 1)), + pickle.loads(pickle.dumps(words, 2)), + pickle.loads(pickle.dumps(words, -1)), + eval(repr(words)), + update_test, + Counter(words), + ]): + msg = (i, dup, words) + self.assertTrue(dup is not words) + self.assertEqual(dup, words) + self.assertEqual(len(dup), len(words)) + self.assertEqual(type(dup), type(words)) def test_copy_subclass(self): class MyCounter(Counter): @@ -1216,28 +1212,24 @@ od = OrderedDict(pairs) update_test = OrderedDict() update_test.update(od) - for label, dup in [ - ('od.copy()', od.copy()), - ('copy.copy(od)', copy.copy(od)), - ('copy.deepcopy(od)', copy.deepcopy(od)), - ('pickle.loads(pickle.dumps(od, 0))', - pickle.loads(pickle.dumps(od, 0))), - ('pickle.loads(pickle.dumps(od, 1))', - pickle.loads(pickle.dumps(od, 1))), - ('pickle.loads(pickle.dumps(od, 2))', - pickle.loads(pickle.dumps(od, 2))), - ('pickle.loads(pickle.dumps(od, 3))', - pickle.loads(pickle.dumps(od, 3))), - ('pickle.loads(pickle.dumps(od, -1))', - pickle.loads(pickle.dumps(od, -1))), - ('eval(repr(od))', eval(repr(od))), - ('update_test', update_test), - ('OrderedDict(od)', OrderedDict(od)), - ]: - with self.subTest(label=label): - msg = "\ncopy: %s\nod: %s" % (dup, od) - self.assertIsNot(dup, od, msg) - self.assertEqual(dup, od) + for i, dup in enumerate([ + od.copy(), + copy.copy(od), + copy.deepcopy(od), + pickle.loads(pickle.dumps(od, 0)), + pickle.loads(pickle.dumps(od, 1)), + pickle.loads(pickle.dumps(od, 2)), + pickle.loads(pickle.dumps(od, 3)), + pickle.loads(pickle.dumps(od, -1)), + eval(repr(od)), + update_test, + OrderedDict(od), + ]): + self.assertTrue(dup is not od) + self.assertEqual(dup, od) + self.assertEqual(list(dup.items()), list(od.items())) + self.assertEqual(len(dup), len(od)) + self.assertEqual(type(dup), type(od)) def test_yaml_linkage(self): # Verify that __reduce__ is setup in a way that supports PyYAML's dump() feature. @@ -1252,18 +1244,9 @@ # do not save instance dictionary if not needed pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] od = OrderedDict(pairs) - self.assertIsNone(od.__reduce__()[2]) + self.assertEqual(len(od.__reduce__()), 2) od.x = 10 - self.assertIsNotNone(od.__reduce__()[2]) - - def test_pickle_recursive(self): - od = OrderedDict() - od[1] = od - for proto in range(-1, pickle.HIGHEST_PROTOCOL + 1): - dup = pickle.loads(pickle.dumps(od, proto)) - self.assertIsNot(dup, od) - self.assertEqual(list(dup.keys()), [1]) - self.assertIs(dup[1], dup) + self.assertEqual(len(od.__reduce__()), 3) def test_repr(self): od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_compileall.py --- a/Lib/test/test_compileall.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_compileall.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,12 +1,11 @@ import sys import compileall -import importlib.util +import imp import os import py_compile import shutil import struct import subprocess -import sys import tempfile import time import unittest @@ -19,11 +18,11 @@ def setUp(self): self.directory = tempfile.mkdtemp() self.source_path = os.path.join(self.directory, '_test.py') - self.bc_path = importlib.util.cache_from_source(self.source_path) + self.bc_path = imp.cache_from_source(self.source_path) with open(self.source_path, 'w') as file: file.write('x = 123\n') self.source_path2 = os.path.join(self.directory, '_test2.py') - self.bc_path2 = importlib.util.cache_from_source(self.source_path2) + self.bc_path2 = imp.cache_from_source(self.source_path2) shutil.copyfile(self.source_path, self.source_path2) self.subdirectory = os.path.join(self.directory, '_subdir') os.mkdir(self.subdirectory) @@ -37,7 +36,7 @@ with open(self.bc_path, 'rb') as file: data = file.read(8) mtime = int(os.stat(self.source_path).st_mtime) - compare = struct.pack('<4sl', importlib.util.MAGIC_NUMBER, mtime) + compare = struct.pack('<4sl', imp.get_magic(), mtime) return data, compare def recreation_check(self, metadata): @@ -58,8 +57,7 @@ def test_mtime(self): # Test a change in mtime leads to a new .pyc. - self.recreation_check(struct.pack('<4sl', importlib.util.MAGIC_NUMBER, - 1)) + self.recreation_check(struct.pack('<4sl', imp.get_magic(), 1)) def test_magic_number(self): # Test a change in mtime leads to a new .pyc. @@ -99,14 +97,14 @@ # interpreter's creates the correct file names optimize = 1 if __debug__ else 0 compileall.compile_dir(self.directory, quiet=True, optimize=optimize) - cached = importlib.util.cache_from_source(self.source_path, - debug_override=not optimize) + cached = imp.cache_from_source(self.source_path, + debug_override=not optimize) self.assertTrue(os.path.isfile(cached)) - cached2 = importlib.util.cache_from_source(self.source_path2, - debug_override=not optimize) + cached2 = imp.cache_from_source(self.source_path2, + debug_override=not optimize) self.assertTrue(os.path.isfile(cached2)) - cached3 = importlib.util.cache_from_source(self.source_path3, - debug_override=not optimize) + cached3 = imp.cache_from_source(self.source_path3, + debug_override=not optimize) self.assertTrue(os.path.isfile(cached3)) @@ -154,12 +152,10 @@ return rc, out, err def assertCompiled(self, fn): - path = importlib.util.cache_from_source(fn) - self.assertTrue(os.path.exists(path)) + self.assertTrue(os.path.exists(imp.cache_from_source(fn))) def assertNotCompiled(self, fn): - path = importlib.util.cache_from_source(fn) - self.assertFalse(os.path.exists(path)) + self.assertFalse(os.path.exists(imp.cache_from_source(fn))) def setUp(self): self.addCleanup(self._cleanup) @@ -194,8 +190,8 @@ ['-m', 'compileall', '-q', self.pkgdir])) # Verify the __pycache__ directory contents. self.assertTrue(os.path.exists(self.pkgdir_cachedir)) - expected = sorted(base.format(sys.implementation.cache_tag, ext) - for base in ('__init__.{}.{}', 'bar.{}.{}')) + expected = sorted(base.format(imp.get_tag(), ext) for base in + ('__init__.{}.{}', 'bar.{}.{}')) self.assertEqual(sorted(os.listdir(self.pkgdir_cachedir)), expected) # Make sure there are no .pyc files in the source directory. self.assertFalse([fn for fn in os.listdir(self.pkgdir) @@ -228,7 +224,7 @@ def test_force(self): self.assertRunOK('-q', self.pkgdir) - pycpath = importlib.util.cache_from_source(self.barfn) + pycpath = imp.cache_from_source(self.barfn) # set atime/mtime backward to avoid file timestamp resolution issues os.utime(pycpath, (time.time()-60,)*2) mtime = os.stat(pycpath).st_mtime @@ -292,7 +288,7 @@ bazfn = script_helper.make_script(self.pkgdir, 'baz', 'raise Exception') self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir) fn = script_helper.make_script(self.pkgdir, 'bing', 'import baz') - pyc = importlib.util.cache_from_source(bazfn) + pyc = imp.cache_from_source(bazfn) os.rename(pyc, os.path.join(self.pkgdir, 'baz.pyc')) os.remove(bazfn) rc, out, err = script_helper.assert_python_failure(fn) @@ -303,7 +299,7 @@ '-i', os.path.join(self.directory, 'nosuchfile'), self.pkgdir) self.assertRegex(out, b'rror.*nosuchfile') self.assertNotRegex(err, b'Traceback') - self.assertFalse(os.path.exists(importlib.util.cache_from_source( + self.assertFalse(os.path.exists(imp.cache_from_source( self.pkgdir_cachedir))) def test_include_file_with_arg(self): @@ -360,5 +356,13 @@ self.assertRegex(out, b"Can't list 'badfilename'") +def test_main(): + support.run_unittest( + CommandLineTests, + CompileallTests, + EncodingTest, + ) + + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_configparser.py --- a/Lib/test/test_configparser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_configparser.py Fri Feb 01 23:12:09 2013 +0100 @@ -626,15 +626,15 @@ oops{equals}this won't """.format(equals=self.delimiters[0])), source='') e = cm.exception - self.assertEqual(str(e), "While reading from '' " - "[line 5]: section 'Foo' already exists") + self.assertEqual(str(e), "While reading from [line 5]: " + "section 'Foo' already exists") self.assertEqual(e.args, ("Foo", '', 5)) with self.assertRaises(configparser.DuplicateOptionError) as cm: cf.read_dict({'Bar': {'opt': 'val', 'OPT': 'is really `opt`'}}) e = cm.exception - self.assertEqual(str(e), "While reading from '': option " - "'opt' in section 'Bar' already exists") + self.assertEqual(str(e), "While reading from : option 'opt' " + "in section 'Bar' already exists") self.assertEqual(e.args, ("Bar", "opt", "", None)) def test_write(self): @@ -1419,18 +1419,13 @@ class ReadFileTestCase(unittest.TestCase): def test_file(self): - file_paths = [support.findfile("cfgparser.1")] - try: - file_paths.append(file_paths[0].encode('utf8')) - except UnicodeEncodeError: - pass # unfortunately we can't test bytes on this path - for file_path in file_paths: - parser = configparser.ConfigParser() - with open(file_path) as f: - parser.read_file(f) - self.assertIn("Foo Bar", parser) - self.assertIn("foo", parser["Foo Bar"]) - self.assertEqual(parser["Foo Bar"]["foo"], "newbar") + file_path = support.findfile("cfgparser.1") + parser = configparser.ConfigParser() + with open(file_path) as f: + parser.read_file(f) + self.assertIn("Foo Bar", parser) + self.assertIn("foo", parser["Foo Bar"]) + self.assertEqual(parser["Foo Bar"]["foo"], "newbar") def test_iterable(self): lines = textwrap.dedent(""" @@ -1452,53 +1447,6 @@ self.assertIn("foo", parser["Foo Bar"]) self.assertEqual(parser["Foo Bar"]["foo"], "newbar") - def test_source_as_bytes(self): - """Issue #18260.""" - lines = textwrap.dedent(""" - [badbad] - [badbad]""").strip().split('\n') - parser = configparser.ConfigParser() - with self.assertRaises(configparser.DuplicateSectionError) as dse: - parser.read_file(lines, source=b"badbad") - self.assertEqual( - str(dse.exception), - "While reading from b'badbad' [line 2]: section 'badbad' " - "already exists" - ) - lines = textwrap.dedent(""" - [badbad] - bad = bad - bad = bad""").strip().split('\n') - parser = configparser.ConfigParser() - with self.assertRaises(configparser.DuplicateOptionError) as dse: - parser.read_file(lines, source=b"badbad") - self.assertEqual( - str(dse.exception), - "While reading from b'badbad' [line 3]: option 'bad' in section " - "'badbad' already exists" - ) - lines = textwrap.dedent(""" - [badbad] - = bad""").strip().split('\n') - parser = configparser.ConfigParser() - with self.assertRaises(configparser.ParsingError) as dse: - parser.read_file(lines, source=b"badbad") - self.assertEqual( - str(dse.exception), - "Source contains parsing errors: b'badbad'\n\t[line 2]: '= bad'" - ) - lines = textwrap.dedent(""" - [badbad - bad = bad""").strip().split('\n') - parser = configparser.ConfigParser() - with self.assertRaises(configparser.MissingSectionHeaderError) as dse: - parser.read_file(lines, source=b"badbad") - self.assertEqual( - str(dse.exception), - "File contains no section headers.\nfile: b'badbad', line: 1\n" - "'[badbad'" - ) - class CoverageOneHundredTestCase(unittest.TestCase): """Covers edge cases in the codebase.""" diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_contextlib.py --- a/Lib/test/test_contextlib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_contextlib.py Fri Feb 01 23:12:09 2013 +0100 @@ -594,28 +594,10 @@ stack.push(cm) self.assertIs(stack._exit_callbacks[-1], cm) -class TestIgnored(unittest.TestCase): - def test_no_exception(self): - - with ignored(ValueError): - self.assertEqual(pow(2, 5), 32) - - def test_exact_exception(self): - - with ignored(TypeError): - len(5) - - def test_multiple_exception_args(self): - - with ignored(ZeroDivisionError, TypeError): - len(5) - - def test_exception_hierarchy(self): - - with ignored(LookupError): - 'Hello'[50] - +# This is needed to make the test actually run under regrtest.py! +def test_main(): + support.run_unittest(__name__) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_cprofile.py --- a/Lib/test/test_cprofile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_cprofile.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,11 +6,9 @@ # rip off all interesting stuff from test_profile import cProfile from test.test_profile import ProfileTest, regenerate_expected_output -from test.profilee import testfunc class CProfileTest(ProfileTest): profilerclass = cProfile.Profile - profilermodule = cProfile expected_max_output = "{built-in method max}" def get_expected_output(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_crypt.py --- a/Lib/test/test_crypt.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_crypt.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,11 @@ from test import support import unittest -crypt = support.import_module('crypt') +def setUpModule(): + # this import will raise unittest.SkipTest if _crypt doesn't exist, + # so it has to be done in setUpModule for test discovery to work + global crypt + crypt = support.import_module('crypt') class CryptTestCase(unittest.TestCase): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_csv.py --- a/Lib/test/test_csv.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_csv.py Fri Feb 01 23:12:09 2013 +0100 @@ -308,15 +308,6 @@ for i, row in enumerate(csv.reader(fileobj)): self.assertEqual(row, rows[i]) - def test_roundtrip_escaped_unquoted_newlines(self): - with TemporaryFile("w+", newline='') as fileobj: - writer = csv.writer(fileobj,quoting=csv.QUOTE_NONE,escapechar="\\") - rows = [['a\nb','b'],['c','x\r\nd']] - writer.writerows(rows) - fileobj.seek(0) - for i, row in enumerate(csv.reader(fileobj,quoting=csv.QUOTE_NONE,escapechar="\\")): - self.assertEqual(row,rows[i]) - class TestDialectRegistry(unittest.TestCase): def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) @@ -805,7 +796,7 @@ 'Tommy''s Place':'Blue Island':'IL':'12/28/02':'Blue Sunday/White Crow' 'Stonecutters ''Seafood'' and Chop House':'Lemont':'IL':'12/19/02':'Week Back' """ - header1 = '''\ + header = '''\ "venue","city","state","date","performers" ''' sample3 = '''\ @@ -824,35 +815,10 @@ sample6 = "a|b|c\r\nd|e|f\r\n" sample7 = "'a'|'b'|'c'\r\n'd'|e|f\r\n" -# Issue 18155: Use a delimiter that is a special char to regex: - - header2 = '''\ -"venue"+"city"+"state"+"date"+"performers" -''' - sample8 = """\ -Harry's+ Arlington Heights+ IL+ 2/1/03+ Kimi Hayes -Shark City+ Glendale Heights+ IL+ 12/28/02+ Prezence -Tommy's Place+ Blue Island+ IL+ 12/28/02+ Blue Sunday/White Crow -Stonecutters Seafood and Chop House+ Lemont+ IL+ 12/19/02+ Week Back -""" - sample9 = """\ -'Harry''s'+ Arlington Heights'+ 'IL'+ '2/1/03'+ 'Kimi Hayes' -'Shark City'+ Glendale Heights'+' IL'+ '12/28/02'+ 'Prezence' -'Tommy''s Place'+ Blue Island'+ 'IL'+ '12/28/02'+ 'Blue Sunday/White Crow' -'Stonecutters ''Seafood'' and Chop House'+ 'Lemont'+ 'IL'+ '12/19/02'+ 'Week Back' -""" - def test_has_header(self): sniffer = csv.Sniffer() self.assertEqual(sniffer.has_header(self.sample1), False) - self.assertEqual(sniffer.has_header(self.header1 + self.sample1), - True) - - def test_has_header_regex_special_delimiter(self): - sniffer = csv.Sniffer() - self.assertEqual(sniffer.has_header(self.sample8), False) - self.assertEqual(sniffer.has_header(self.header2 + self.sample8), - True) + self.assertEqual(sniffer.has_header(self.header+self.sample1), True) def test_sniff(self): sniffer = csv.Sniffer() @@ -886,24 +852,13 @@ dialect = sniffer.sniff(self.sample7) self.assertEqual(dialect.delimiter, "|") self.assertEqual(dialect.quotechar, "'") - dialect = sniffer.sniff(self.sample8) - self.assertEqual(dialect.delimiter, '+') - dialect = sniffer.sniff(self.sample9) - self.assertEqual(dialect.delimiter, '+') - self.assertEqual(dialect.quotechar, "'") def test_doublequote(self): sniffer = csv.Sniffer() - dialect = sniffer.sniff(self.header1) - self.assertFalse(dialect.doublequote) - dialect = sniffer.sniff(self.header2) + dialect = sniffer.sniff(self.header) self.assertFalse(dialect.doublequote) dialect = sniffer.sniff(self.sample2) self.assertTrue(dialect.doublequote) - dialect = sniffer.sniff(self.sample8) - self.assertFalse(dialect.doublequote) - dialect = sniffer.sniff(self.sample9) - self.assertTrue(dialect.doublequote) if not hasattr(sys, "gettotalrefcount"): if support.verbose: print("*** skipping leakage tests ***") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ctypes.py --- a/Lib/test/test_ctypes.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ctypes.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,16 +1,16 @@ import unittest -from test.support import import_module +from test.support import run_unittest, import_module # Skip tests if _ctypes module was not built. import_module('_ctypes') import ctypes.test -def load_tests(*args): +def test_main(): skipped, testcases = ctypes.test.get_tests(ctypes.test, "test_*.py", verbosity=0) suites = [unittest.makeSuite(t) for t in testcases] - return unittest.TestSuite(suites) + run_unittest(unittest.TestSuite(suites)) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_curses.py --- a/Lib/test/test_curses.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_curses.py Fri Feb 01 23:12:09 2013 +0100 @@ -252,26 +252,6 @@ except curses.panel.error: pass -def test_userptr_memory_leak(stdscr): - w = curses.newwin(10, 10) - p = curses.panel.new_panel(w) - obj = object() - nrefs = sys.getrefcount(obj) - for i in range(100): - p.set_userptr(obj) - - p.set_userptr(None) - if sys.getrefcount(obj) != nrefs: - raise RuntimeError("set_userptr leaked references") - -def test_userptr_segfault(stdscr): - panel = curses.panel.new_panel(stdscr) - class A: - def __del__(self): - panel.set_userptr(None) - panel.set_userptr(A()) - panel.set_userptr(None) - def test_resize_term(stdscr): if hasattr(curses, 'resizeterm'): lines, cols = curses.LINES, curses.COLS @@ -337,8 +317,6 @@ module_funcs(stdscr) window_funcs(stdscr) test_userptr_without_set(stdscr) - test_userptr_memory_leak(stdscr) - test_userptr_segfault(stdscr) test_resize_term(stdscr) test_issue6243(stdscr) test_unget_wch(stdscr) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dbm.py --- a/Lib/test/test_dbm.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dbm.py Fri Feb 01 23:12:09 2013 +0100 @@ -9,11 +9,6 @@ # Skip tests if dbm module doesn't exist. dbm = test.support.import_module('dbm') -try: - from dbm import ndbm -except ImportError: - ndbm = None - _fname = test.support.TESTFN # @@ -39,7 +34,7 @@ test.support.unlink(f) -class AnyDBMTestCase: +class AnyDBMTestCase(unittest.TestCase): _dict = {'0': b'', 'a': b'Python:', 'b': b'Programming', @@ -124,6 +119,10 @@ class WhichDBTestCase(unittest.TestCase): + # Actual test methods are added to namespace after class definition. + def __init__(self, *args): + unittest.TestCase.__init__(self, *args) + def test_whichdb(self): for module in dbm_iterator(): # Check whether whichdb correctly guesses module name @@ -135,7 +134,7 @@ delete_files() f = module.open(_fname, 'c') f.close() - self.assertEqual(name, self.dbm.whichdb(_fname)) + self.assertEqual(name, dbm.whichdb(_fname)) # Now add a key f = module.open(_fname, 'w') f[b"1"] = b"1" @@ -144,15 +143,7 @@ # and read it self.assertTrue(f[b"1"] == b"1") f.close() - self.assertEqual(name, self.dbm.whichdb(_fname)) - - @unittest.skipUnless(ndbm, reason='Test requires ndbm') - def test_whichdb_ndbm(self): - # Issue 17198: check that ndbm which is referenced in whichdb is defined - db_file = '{}_ndbm.db'.format(_fname) - with open(db_file, 'w'): - self.addCleanup(test.support.unlink, db_file) - self.assertIsNone(self.dbm.whichdb(db_file[:-3])) + self.assertEqual(name, dbm.whichdb(_fname)) def tearDown(self): delete_files() @@ -162,7 +153,6 @@ self.filename = test.support.TESTFN self.d = dbm.open(self.filename, 'c') self.d.close() - self.dbm = test.support.import_fresh_module('dbm') def test_keys(self): self.d = dbm.open(self.filename, 'c') @@ -179,16 +169,12 @@ self.d.close() -def load_tests(loader, tests, pattern): - classes = [] +def test_main(): + classes = [WhichDBTestCase] for mod in dbm_iterator(): - classes.append(type("TestCase-" + mod.__name__, - (AnyDBMTestCase, unittest.TestCase), + classes.append(type("TestCase-" + mod.__name__, (AnyDBMTestCase,), {'module': mod})) - suites = [unittest.makeSuite(c) for c in classes] - - tests.addTests(suites) - return tests + test.support.run_unittest(*classes) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dbm_dumb.py --- a/Lib/test/test_dbm_dumb.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dbm_dumb.py Fri Feb 01 23:12:09 2013 +0100 @@ -29,6 +29,9 @@ '\u00fc'.encode('utf-8') : b'!', } + def __init__(self, *args): + unittest.TestCase.__init__(self, *args) + def test_dumbdbm_creation(self): f = dumbdbm.open(_fname, 'c') self.assertEqual(list(f.keys()), []) @@ -192,6 +195,11 @@ def setUp(self): _delete_files() +def test_main(): + try: + support.run_unittest(DumbDBMTestCase) + finally: + _delete_files() if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dbm_gnu.py --- a/Lib/test/test_dbm_gnu.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dbm_gnu.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,7 +2,7 @@ gdbm = support.import_module("dbm.gnu") #skip if not supported import unittest import os -from test.support import verbose, TESTFN, unlink +from test.support import verbose, TESTFN, run_unittest, unlink filename = TESTFN @@ -81,5 +81,8 @@ self.assertTrue(size1 > size2 >= size0) +def test_main(): + run_unittest(TestGdbm) + if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dbm_ndbm.py --- a/Lib/test/test_dbm_ndbm.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dbm_ndbm.py Fri Feb 01 23:12:09 2013 +0100 @@ -36,5 +36,8 @@ except error: self.fail() +def test_main(): + support.run_unittest(DbmTestCase) + if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_decimal.py Fri Feb 01 23:12:09 2013 +0100 @@ -290,6 +290,7 @@ global skip_expected if skip_expected: raise unittest.SkipTest + return with open(file) as f: for line in f: line = line.replace('\r\n', '').replace('\n', '') @@ -1020,10 +1021,6 @@ ('/=10', '-45.6', '-/////45.6'), ('/=+10', '45.6', '+/////45.6'), ('/= 10', '45.6', ' /////45.6'), - ('\x00=10', '-inf', '-\x00Infinity'), - ('\x00^16', '-inf', '\x00\x00\x00-Infinity\x00\x00\x00\x00'), - ('\x00>10', '1.2345', '\x00\x00\x00\x001.2345'), - ('\x00<10', '1.2345', '1.2345\x00\x00\x00\x00'), # thousands separator (',', '1234567', '1,234,567'), @@ -4495,7 +4492,7 @@ x = Decimal(2**578) ** Decimal("-0.5") def test_py_immutability_operations(self): - # Do operations and check that it didn't change internal objects. + # Do operations and check that it didn't change change internal objects. Decimal = P.Decimal DefaultContext = P.DefaultContext setcontext = P.setcontext @@ -4974,16 +4971,22 @@ def test_c_format(self): # Restricted input Decimal = C.Decimal + InvalidOperation = C.InvalidOperation + Rounded = C.Rounded + localcontext = C.localcontext HAVE_CONFIG_64 = (C.MAX_PREC > 425000000) self.assertRaises(TypeError, Decimal(1).__format__, "=10.10", [], 9) self.assertRaises(TypeError, Decimal(1).__format__, "=10.10", 9) self.assertRaises(TypeError, Decimal(1).__format__, []) - self.assertRaises(ValueError, Decimal(1).__format__, "<>=10.10") - maxsize = 2**63-1 if HAVE_CONFIG_64 else 2**31-1 - self.assertRaises(ValueError, Decimal("1.23456789").__format__, - "=%d.1" % maxsize) + with localcontext() as c: + c.traps[InvalidOperation] = True + c.traps[Rounded] = True + self.assertRaises(ValueError, Decimal(1).__format__, "<>=10.10") + maxsize = 2**63-1 if HAVE_CONFIG_64 else 2**31-1 + self.assertRaises(InvalidOperation, Decimal("1.23456789").__format__, + "=%d.1" % maxsize) def test_c_integral(self): Decimal = C.Decimal @@ -5372,19 +5375,6 @@ x = (1, (0, 1), "N") self.assertEqual(str(Decimal(x)), '-sNaN1') - def test_sizeof(self): - Decimal = C.Decimal - HAVE_CONFIG_64 = (C.MAX_PREC > 425000000) - - self.assertGreater(Decimal(0).__sizeof__(), 0) - if HAVE_CONFIG_64: - x = Decimal(10**(19*24)).__sizeof__() - y = Decimal(10**(19*25)).__sizeof__() - self.assertEqual(y, x+8) - else: - x = Decimal(10**(9*24)).__sizeof__() - y = Decimal(10**(9*25)).__sizeof__() - self.assertEqual(y, x+4) all_tests = [ CExplicitConstructionTest, PyExplicitConstructionTest, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_deque.py --- a/Lib/test/test_deque.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_deque.py Fri Feb 01 23:12:09 2013 +0100 @@ -536,15 +536,15 @@ @support.cpython_only def test_sizeof(self): - BLOCKLEN = 64 + BLOCKLEN = 62 basesize = support.calcobjsize('2P4nlP') blocksize = struct.calcsize('2P%dP' % BLOCKLEN) self.assertEqual(object.__sizeof__(deque()), basesize) check = self.check_sizeof check(deque(), basesize + blocksize) check(deque('a'), basesize + blocksize) - check(deque('a' * (BLOCKLEN - 1)), basesize + blocksize) - check(deque('a' * BLOCKLEN), basesize + 2 * blocksize) + check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize) check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize) class TestVariousIteratorArgs(unittest.TestCase): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_descr.py --- a/Lib/test/test_descr.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_descr.py Fri Feb 01 23:12:09 2013 +0100 @@ -1789,7 +1789,6 @@ ("__trunc__", int, zero, set(), {}), ("__ceil__", math.ceil, zero, set(), {}), ("__dir__", dir, empty_seq, set(), {}), - ("__round__", round, zero, set(), {}), ] class Checker(object): @@ -2250,9 +2249,7 @@ minstance = M("m") minstance.b = 2 minstance.a = 1 - default_attributes = ['__name__', '__doc__', '__package__', - '__loader__'] - names = [x for x in dir(minstance) if x not in default_attributes] + names = [x for x in dir(minstance) if x not in ["__name__", "__doc__"]] self.assertEqual(names, ['a', 'b']) class M2(M): @@ -4000,20 +3997,6 @@ C.__name__ = 'D.E' self.assertEqual((C.__module__, C.__name__), (mod, 'D.E')) - def test_evil_type_name(self): - # A badly placed Py_DECREF in type_set_name led to arbitrary code - # execution while the type structure was not in a sane state, and a - # possible segmentation fault as a result. See bug #16447. - class Nasty(str): - def __del__(self): - C.__name__ = "other" - - class C: - pass - - C.__name__ = Nasty("abc") - C.__name__ = "normal" - def test_subclass_right_op(self): # Testing correct dispatch of subclass overloading __r__... diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_descrtut.py --- a/Lib/test/test_descrtut.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_descrtut.py Fri Feb 01 23:12:09 2013 +0100 @@ -319,7 +319,7 @@ ... return self.__set(inst, value) Now let's define a class with an attribute x defined by a pair of methods, -getx() and setx(): +getx() and and setx(): >>> class C(object): ... diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dictcomps.py --- a/Lib/test/test_dictcomps.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dictcomps.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,88 +1,54 @@ -import unittest -from test import support +doctests = """ -# For scope testing. -g = "Global variable" + >>> k = "old value" + >>> { k: None for k in range(10) } + {0: None, 1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None} + >>> k + 'old value' + >>> { k: k+10 for k in range(10) } + {0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17, 8: 18, 9: 19} -class DictComprehensionTest(unittest.TestCase): + >>> g = "Global variable" + >>> { k: g for k in range(10) } + {0: 'Global variable', 1: 'Global variable', 2: 'Global variable', 3: 'Global variable', 4: 'Global variable', 5: 'Global variable', 6: 'Global variable', 7: 'Global variable', 8: 'Global variable', 9: 'Global variable'} - def test_basics(self): - expected = {0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17, - 8: 18, 9: 19} - actual = {k: k + 10 for k in range(10)} - self.assertEqual(actual, expected) + >>> { k: v for k in range(10) for v in range(10) if k == v } + {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9} - expected = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9} - actual = {k: v for k in range(10) for v in range(10) if k == v} - self.assertEqual(actual, expected) + >>> { k: v for v in range(10) for k in range(v*9, v*10) } + {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, 55: 6, 56: 6, 57: 6, 58: 6, 59: 6, 63: 7, 64: 7, 65: 7, 66: 7, 67: 7, 68: 7, 69: 7, 72: 8, 73: 8, 74: 8, 75: 8, 76: 8, 77: 8, 78: 8, 79: 8, 81: 9, 82: 9, 83: 9, 84: 9, 85: 9, 86: 9, 87: 9, 88: 9, 89: 9} - def test_scope_isolation(self): - k = "Local Variable" + >>> { x: y for y, x in ((1, 2), (3, 4)) } = 5 # doctest: +IGNORE_EXCEPTION_DETAIL + Traceback (most recent call last): + ... + SyntaxError: ... - expected = {0: None, 1: None, 2: None, 3: None, 4: None, 5: None, - 6: None, 7: None, 8: None, 9: None} - actual = {k: None for k in range(10)} - self.assertEqual(actual, expected) - self.assertEqual(k, "Local Variable") + >>> { x: y for y, x in ((1, 2), (3, 4)) } += 5 # doctest: +IGNORE_EXCEPTION_DETAIL + Traceback (most recent call last): + ... + SyntaxError: ... - expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, - 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, - 55: 6, 56: 6, 57: 6, 58: 6, 59: 6, 63: 7, 64: 7, 65: 7, - 66: 7, 67: 7, 68: 7, 69: 7, 72: 8, 73: 8, 74: 8, 75: 8, - 76: 8, 77: 8, 78: 8, 79: 8, 81: 9, 82: 9, 83: 9, 84: 9, - 85: 9, 86: 9, 87: 9, 88: 9, 89: 9} - actual = {k: v for v in range(10) for k in range(v * 9, v * 10)} - self.assertEqual(k, "Local Variable") - self.assertEqual(actual, expected) +""" - def test_scope_isolation_from_global(self): - expected = {0: None, 1: None, 2: None, 3: None, 4: None, 5: None, - 6: None, 7: None, 8: None, 9: None} - actual = {g: None for g in range(10)} - self.assertEqual(actual, expected) - self.assertEqual(g, "Global variable") +__test__ = {'doctests' : doctests} - expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, - 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, - 55: 6, 56: 6, 57: 6, 58: 6, 59: 6, 63: 7, 64: 7, 65: 7, - 66: 7, 67: 7, 68: 7, 69: 7, 72: 8, 73: 8, 74: 8, 75: 8, - 76: 8, 77: 8, 78: 8, 79: 8, 81: 9, 82: 9, 83: 9, 84: 9, - 85: 9, 86: 9, 87: 9, 88: 9, 89: 9} - actual = {g: v for v in range(10) for g in range(v * 9, v * 10)} - self.assertEqual(g, "Global variable") - self.assertEqual(actual, expected) +def test_main(verbose=None): + import sys + from test import support + from test import test_dictcomps + support.run_doctest(test_dictcomps, verbose) - def test_global_visibility(self): - expected = {0: 'Global variable', 1: 'Global variable', - 2: 'Global variable', 3: 'Global variable', - 4: 'Global variable', 5: 'Global variable', - 6: 'Global variable', 7: 'Global variable', - 8: 'Global variable', 9: 'Global variable'} - actual = {k: g for k in range(10)} - self.assertEqual(actual, expected) - - def test_local_visibility(self): - v = "Local variable" - expected = {0: 'Local variable', 1: 'Local variable', - 2: 'Local variable', 3: 'Local variable', - 4: 'Local variable', 5: 'Local variable', - 6: 'Local variable', 7: 'Local variable', - 8: 'Local variable', 9: 'Local variable'} - actual = {k: v for k in range(10)} - self.assertEqual(actual, expected) - self.assertEqual(v, "Local variable") - - def test_illegal_assignment(self): - with self.assertRaisesRegex(SyntaxError, "can't assign"): - compile("{x: y for y, x in ((1, 2), (3, 4))} = 5", "", - "exec") - - with self.assertRaisesRegex(SyntaxError, "can't assign"): - compile("{x: y for y, x in ((1, 2), (3, 4))} += 5", "", - "exec") - + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in range(len(counts)): + support.run_doctest(test_dictcomps, verbose) + gc.collect() + counts[i] = sys.gettotalrefcount() + print(counts) if __name__ == "__main__": - unittest.main() + test_main(verbose=True) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dictviews.py --- a/Lib/test/test_dictviews.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dictviews.py Fri Feb 01 23:12:09 2013 +0100 @@ -179,11 +179,6 @@ self.assertTrue(de.items().isdisjoint(de.items())) self.assertTrue(de.items().isdisjoint([1])) - def test_recursive_repr(self): - d = {} - d[42] = d.values() - self.assertRaises(RuntimeError, repr, d) - def test_main(): support.run_unittest(DictSetTest) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_dis.py --- a/Lib/test/test_dis.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_dis.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,13 +1,11 @@ # Minimal tests for dis module from test.support import run_unittest, captured_stdout -from test.bytecode_helper import BytecodeTestCase import difflib import unittest import sys import dis import io -import types class _C: def __init__(self, x): @@ -24,12 +22,12 @@ """ % (_C.__init__.__code__.co_firstlineno + 1,) dis_c_instance_method_bytes = """\ - 0 LOAD_FAST 1 (1) - 3 LOAD_CONST 1 (1) - 6 COMPARE_OP 2 (==) - 9 LOAD_FAST 0 (0) - 12 STORE_ATTR 0 (0) - 15 LOAD_CONST 0 (0) + 0 LOAD_FAST 1 (1) + 3 LOAD_CONST 1 (1) + 6 COMPARE_OP 2 (==) + 9 LOAD_FAST 0 (0) + 12 STORE_ATTR 0 (0) + 15 LOAD_CONST 0 (0) 18 RETURN_VALUE """ @@ -50,11 +48,11 @@ dis_f_co_code = """\ - 0 LOAD_GLOBAL 0 (0) - 3 LOAD_FAST 0 (0) - 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) + 0 LOAD_GLOBAL 0 (0) + 3 LOAD_FAST 0 (0) + 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 9 POP_TOP - 10 LOAD_CONST 1 (1) + 10 LOAD_CONST 1 (1) 13 RETURN_VALUE """ @@ -300,16 +298,29 @@ Argument count: 1 Kw-only arguments: 0 Number of locals: 1 -Stack size: 3 +Stack size: 4 Flags: OPTIMIZED, NEWLOCALS, NOFREE Constants: 0: %r -Names: - 0: _format_code_info - 1: _get_code_object + 1: '__func__' + 2: '__code__' + 3: '' + 4: 'co_code' + 5: "don't know how to disassemble %%s objects" +%sNames: + 0: hasattr + 1: __func__ + 2: __code__ + 3: isinstance + 4: str + 5: _try_compile + 6: _format_code_info + 7: TypeError + 8: type + 9: __name__ Variable names: - 0: x""" % (('Formatted details of methods, functions, or code.',) - if sys.flags.optimize < 2 else (None,)) + 0: x""" % (('Formatted details of methods, functions, or code.', ' 6: None\n') + if sys.flags.optimize < 2 else (None, '')) @staticmethod def tricky(x, y, z=True, *args, c, d, e=[], **kwds): @@ -373,7 +384,7 @@ code_info_expr_str = """\ Name: -Filename: +Filename: Argument count: 0 Kw-only arguments: 0 Number of locals: 0 @@ -386,7 +397,7 @@ code_info_simple_stmt_str = """\ Name: -Filename: +Filename: Argument count: 0 Kw-only arguments: 0 Number of locals: 0 @@ -400,7 +411,7 @@ code_info_compound_stmt_str = """\ Name: -Filename: +Filename: Argument count: 0 Kw-only arguments: 0 Number of locals: 0 @@ -434,9 +445,6 @@ with captured_stdout() as output: dis.show_code(x) self.assertRegex(output.getvalue(), expected+"\n") - output = io.StringIO() - dis.show_code(x, file=output) - self.assertRegex(output.getvalue(), expected) def test_code_info_object(self): self.assertRaises(TypeError, dis.code_info, object()) @@ -445,289 +453,8 @@ self.assertEqual(dis.pretty_flags(0), '0x0') -# Fodder for instruction introspection tests -# Editing any of these may require recalculating the expected output -def outer(a=1, b=2): - def f(c=3, d=4): - def inner(e=5, f=6): - print(a, b, c, d, e, f) - print(a, b, c, d) - return inner - print(a, b, '', 1, [], {}, "Hello world!") - return f - -def jumpy(): - # This won't actually run (but that's OK, we only disassemble it) - for i in range(10): - print(i) - if i < 4: - continue - if i > 6: - break - else: - print("I can haz else clause?") - while i: - print(i) - i -= 1 - if i > 6: - continue - if i < 4: - break - else: - print("Who let lolcatz into this test suite?") - try: - 1 / 0 - except ZeroDivisionError: - print("Here we go, here we go, here we go...") - else: - with i as dodgy: - print("Never reach this") - finally: - print("OK, now we're done") - -# End fodder for opinfo generation tests -expected_outer_offset = 1 - outer.__code__.co_firstlineno -expected_jumpy_offset = 1 - jumpy.__code__.co_firstlineno -code_object_f = outer.__code__.co_consts[3] -code_object_inner = code_object_f.co_consts[3] - -# The following lines are useful to regenerate the expected results after -# either the fodder is modified or the bytecode generation changes -# After regeneration, update the references to code_object_f and -# code_object_inner before rerunning the tests - -#_instructions = dis.get_instructions(outer, line_offset=expected_outer_offset) -#print('expected_opinfo_outer = [\n ', - #',\n '.join(map(str, _instructions)), ',\n]', sep='') -#_instructions = dis.get_instructions(outer(), line_offset=expected_outer_offset) -#print('expected_opinfo_f = [\n ', - #',\n '.join(map(str, _instructions)), ',\n]', sep='') -#_instructions = dis.get_instructions(outer()(), line_offset=expected_outer_offset) -#print('expected_opinfo_inner = [\n ', - #',\n '.join(map(str, _instructions)), ',\n]', sep='') -#_instructions = dis.get_instructions(jumpy, line_offset=expected_jumpy_offset) -#print('expected_opinfo_jumpy = [\n ', - #',\n '.join(map(str, _instructions)), ',\n]', sep='') - - -Instruction = dis.Instruction -expected_opinfo_outer = [ - Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=3, argrepr='3', offset=0, starts_line=2, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=3, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='b', argrepr='b', offset=9, starts_line=None, is_jump_target=False), - Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', offset=12, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_f, argrepr=repr(code_object_f), offset=15, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer..f', argrepr="'outer..f'", offset=18, starts_line=None, is_jump_target=False), - Instruction(opname='MAKE_CLOSURE', opcode=134, arg=2, argval=2, argrepr='', offset=21, starts_line=None, is_jump_target=False), - Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', offset=24, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=27, starts_line=7, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', offset=30, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', offset=33, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval='', argrepr="''", offset=36, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval=1, argrepr='1', offset=39, starts_line=None, is_jump_target=False), - Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=42, starts_line=None, is_jump_target=False), - Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offset=45, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval='Hello world!', argrepr="'Hello world!'", offset=48, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=7, argval=7, argrepr='7 positional, 0 keyword pair', offset=51, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=54, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=55, starts_line=8, is_jump_target=False), - Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=58, starts_line=None, is_jump_target=False), -] - -expected_opinfo_f = [ - Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=5, argrepr='5', offset=0, starts_line=3, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=6, argrepr='6', offset=3, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CLOSURE', opcode=135, arg=2, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CLOSURE', opcode=135, arg=3, argval='b', argrepr='b', offset=9, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='c', argrepr='c', offset=12, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='d', argrepr='d', offset=15, starts_line=None, is_jump_target=False), - Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=18, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=21, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer..f..inner', argrepr="'outer..f..inner'", offset=24, starts_line=None, is_jump_target=False), - Instruction(opname='MAKE_CLOSURE', opcode=134, arg=2, argval=2, argrepr='', offset=27, starts_line=None, is_jump_target=False), - Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=30, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=33, starts_line=5, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=2, argval='a', argrepr='a', offset=36, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=3, argval='b', argrepr='b', offset=39, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='c', argrepr='c', offset=42, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='d', argrepr='d', offset=45, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='4 positional, 0 keyword pair', offset=48, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=51, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=52, starts_line=6, is_jump_target=False), - Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=55, starts_line=None, is_jump_target=False), -] - -expected_opinfo_inner = [ - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=0, starts_line=4, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', offset=3, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', offset=6, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=2, argval='c', argrepr='c', offset=9, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_DEREF', opcode=136, arg=3, argval='d', argrepr='d', offset=12, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', offset=15, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', offset=18, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=6, argval=6, argrepr='6 positional, 0 keyword pair', offset=21, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=24, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=25, starts_line=None, is_jump_target=False), - Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=28, starts_line=None, is_jump_target=False), -] - -expected_opinfo_jumpy = [ - Instruction(opname='SETUP_LOOP', opcode=120, arg=74, argval=77, argrepr='to 77', offset=0, starts_line=3, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='range', argrepr='range', offset=3, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=10, argrepr='10', offset=6, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=9, starts_line=None, is_jump_target=False), - Instruction(opname='GET_ITER', opcode=68, arg=None, argval=None, argrepr='', offset=12, starts_line=None, is_jump_target=False), - Instruction(opname='FOR_ITER', opcode=93, arg=50, argval=66, argrepr='to 66', offset=13, starts_line=None, is_jump_target=True), - Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=16, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=19, starts_line=4, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=22, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=25, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=28, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=29, starts_line=5, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=32, starts_line=None, is_jump_target=False), - Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=35, starts_line=None, is_jump_target=False), - Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=47, argval=47, argrepr='', offset=38, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=13, argval=13, argrepr='', offset=41, starts_line=6, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=0, argval=47, argrepr='to 47', offset=44, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=47, starts_line=7, is_jump_target=True), - Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=50, starts_line=None, is_jump_target=False), - Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=53, starts_line=None, is_jump_target=False), - Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=13, argval=13, argrepr='', offset=56, starts_line=None, is_jump_target=False), - Instruction(opname='BREAK_LOOP', opcode=80, arg=None, argval=None, argrepr='', offset=59, starts_line=8, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=13, argval=13, argrepr='', offset=60, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=13, argval=13, argrepr='', offset=63, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=66, starts_line=None, is_jump_target=True), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=67, starts_line=10, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=70, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=73, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=76, starts_line=None, is_jump_target=False), - Instruction(opname='SETUP_LOOP', opcode=120, arg=74, argval=154, argrepr='to 154', offset=77, starts_line=11, is_jump_target=True), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=80, starts_line=None, is_jump_target=True), - Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=143, argval=143, argrepr='', offset=83, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=86, starts_line=12, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=89, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=92, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=95, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=96, starts_line=13, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=99, starts_line=None, is_jump_target=False), - Instruction(opname='INPLACE_SUBTRACT', opcode=56, arg=None, argval=None, argrepr='', offset=102, starts_line=None, is_jump_target=False), - Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=103, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=106, starts_line=14, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=109, starts_line=None, is_jump_target=False), - Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=112, starts_line=None, is_jump_target=False), - Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=124, argval=124, argrepr='', offset=115, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=80, argval=80, argrepr='', offset=118, starts_line=15, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=0, argval=124, argrepr='to 124', offset=121, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=124, starts_line=16, is_jump_target=True), - Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=127, starts_line=None, is_jump_target=False), - Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=130, starts_line=None, is_jump_target=False), - Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=80, argval=80, argrepr='', offset=133, starts_line=None, is_jump_target=False), - Instruction(opname='BREAK_LOOP', opcode=80, arg=None, argval=None, argrepr='', offset=136, starts_line=17, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=80, argval=80, argrepr='', offset=137, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=80, argval=80, argrepr='', offset=140, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=143, starts_line=None, is_jump_target=True), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=144, starts_line=19, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=147, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=150, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=153, starts_line=None, is_jump_target=False), - Instruction(opname='SETUP_FINALLY', opcode=122, arg=72, argval=229, argrepr='to 229', offset=154, starts_line=20, is_jump_target=True), - Instruction(opname='SETUP_EXCEPT', opcode=121, arg=12, argval=172, argrepr='to 172', offset=157, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=160, starts_line=21, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=163, starts_line=None, is_jump_target=False), - Instruction(opname='BINARY_TRUE_DIVIDE', opcode=27, arg=None, argval=None, argrepr='', offset=166, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=167, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=168, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=28, argval=200, argrepr='to 200', offset=169, starts_line=None, is_jump_target=False), - Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=172, starts_line=22, is_jump_target=True), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=173, starts_line=None, is_jump_target=False), - Instruction(opname='COMPARE_OP', opcode=107, arg=10, argval='exception match', argrepr='exception match', offset=176, starts_line=None, is_jump_target=False), - Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=199, argval=199, argrepr='', offset=179, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=182, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=183, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=185, starts_line=23, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=188, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=191, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=194, starts_line=None, is_jump_target=False), - Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=195, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=26, argval=225, argrepr='to 225', offset=196, starts_line=None, is_jump_target=False), - Instruction(opname='END_FINALLY', opcode=88, arg=None, argval=None, argrepr='', offset=199, starts_line=None, is_jump_target=True), - Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=200, starts_line=25, is_jump_target=True), - Instruction(opname='SETUP_WITH', opcode=143, arg=17, argval=223, argrepr='to 223', offset=203, starts_line=None, is_jump_target=False), - Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=206, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=209, starts_line=26, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=212, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=215, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=219, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=220, starts_line=None, is_jump_target=False), - Instruction(opname='WITH_CLEANUP', opcode=81, arg=None, argval=None, argrepr='', offset=223, starts_line=None, is_jump_target=True), - Instruction(opname='END_FINALLY', opcode=88, arg=None, argval=None, argrepr='', offset=224, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=225, starts_line=None, is_jump_target=True), - Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=226, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=229, starts_line=28, is_jump_target=True), - Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=232, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='1 positional, 0 keyword pair', offset=235, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=238, starts_line=None, is_jump_target=False), - Instruction(opname='END_FINALLY', opcode=88, arg=None, argval=None, argrepr='', offset=239, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=240, starts_line=None, is_jump_target=False), - Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=243, starts_line=None, is_jump_target=False), -] - -class InstructionTests(BytecodeTestCase): - def test_outer(self): - self.assertBytecodeExactlyMatches(outer, expected_opinfo_outer, - line_offset=expected_outer_offset) - - def test_nested(self): - with captured_stdout(): - f = outer() - self.assertBytecodeExactlyMatches(f, expected_opinfo_f, - line_offset=expected_outer_offset) - - def test_doubly_nested(self): - with captured_stdout(): - inner = outer()() - self.assertBytecodeExactlyMatches(inner, expected_opinfo_inner, - line_offset=expected_outer_offset) - - def test_jumpy(self): - self.assertBytecodeExactlyMatches(jumpy, expected_opinfo_jumpy, - line_offset=expected_jumpy_offset) - -class BytecodeTests(unittest.TestCase): - def test_instantiation(self): - # Test with function, method, code string and code object - for obj in [_f, _C(1).__init__, "a=1", _f.__code__]: - b = dis.Bytecode(obj) - self.assertIsInstance(b.codeobj, types.CodeType) - - self.assertRaises(TypeError, dis.Bytecode, object()) - - def test_iteration(self): - b = dis.Bytecode(_f) - for instr in b: - self.assertIsInstance(instr, dis.Instruction) - - assert len(list(b)) > 0 # Iterating should yield at least 1 instruction - - def test_info(self): - self.maxDiff = 1000 - for x, expected in CodeInfoTests.test_pairs: - b = dis.Bytecode(x) - self.assertRegex(b.info(), expected) - - def test_display_code(self): - b = dis.Bytecode(_f) - output = io.StringIO() - b.display_code(file=output) - result = [line.rstrip() for line in output.getvalue().splitlines()] - self.assertEqual(result, dis_f.splitlines()) - - def test_main(): - run_unittest(DisTests, CodeInfoTests, InstructionTests, BytecodeTests) + run_unittest(DisTests, CodeInfoTests) if __name__ == "__main__": test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_doctest.py Fri Feb 01 23:12:09 2013 +0100 @@ -2596,240 +2596,6 @@ TestResults(failed=1, attempted=1) """ -def test_CLI(): r""" -The doctest module can be used to run doctests against an arbitrary file. -These tests test this CLI functionality. - -We'll use the support module's script_helpers for this, and write a test files -to a temp dir to run the command against. Due to a current limitation in -script_helpers, though, we need a little utility function to turn the returned -output into something we can doctest against: - - >>> def normalize(s): - ... return '\n'.join(s.decode().splitlines()) - -Note: we also pass TERM='' to all the assert_python calls to avoid a bug -in the readline library that is triggered in these tests because we are -running them in a new python process. See: - - http://lists.gnu.org/archive/html/bug-readline/2013-06/msg00000.html - -With those preliminaries out of the way, we'll start with a file with two -simple tests and no errors. We'll run both the unadorned doctest command, and -the verbose version, and then check the output: - - >>> from test import script_helper - >>> with script_helper.temp_dir() as tmpdir: - ... fn = os.path.join(tmpdir, 'myfile.doc') - ... with open(fn, 'w') as f: - ... _ = f.write('This is a very simple test file.\n') - ... _ = f.write(' >>> 1 + 1\n') - ... _ = f.write(' 2\n') - ... _ = f.write(' >>> "a"\n') - ... _ = f.write(" 'a'\n") - ... _ = f.write('\n') - ... _ = f.write('And that is it.\n') - ... rc1, out1, err1 = script_helper.assert_python_ok( - ... '-m', 'doctest', fn, TERM='') - ... rc2, out2, err2 = script_helper.assert_python_ok( - ... '-m', 'doctest', '-v', fn, TERM='') - -With no arguments and passing tests, we should get no output: - - >>> rc1, out1, err1 - (0, b'', b'') - -With the verbose flag, we should see the test output, but no error output: - - >>> rc2, err2 - (0, b'') - >>> print(normalize(out2)) - Trying: - 1 + 1 - Expecting: - 2 - ok - Trying: - "a" - Expecting: - 'a' - ok - 1 items passed all tests: - 2 tests in myfile.doc - 2 tests in 1 items. - 2 passed and 0 failed. - Test passed. - -Now we'll write a couple files, one with three tests, the other a python module -with two tests, both of the files having "errors" in the tests that can be made -non-errors by applying the appropriate doctest options to the run (ELLIPSIS in -the first file, NORMALIZE_WHITESPACE in the second). This combination will -allow to thoroughly test the -f and -o flags, as well as the doctest command's -ability to process more than one file on the command line and, since the second -file ends in '.py', its handling of python module files (as opposed to straight -text files). - - >>> from test import script_helper - >>> with script_helper.temp_dir() as tmpdir: - ... fn = os.path.join(tmpdir, 'myfile.doc') - ... with open(fn, 'w') as f: - ... _ = f.write('This is another simple test file.\n') - ... _ = f.write(' >>> 1 + 1\n') - ... _ = f.write(' 2\n') - ... _ = f.write(' >>> "abcdef"\n') - ... _ = f.write(" 'a...f'\n") - ... _ = f.write(' >>> "ajkml"\n') - ... _ = f.write(" 'a...l'\n") - ... _ = f.write('\n') - ... _ = f.write('And that is it.\n') - ... fn2 = os.path.join(tmpdir, 'myfile2.py') - ... with open(fn2, 'w') as f: - ... _ = f.write('def test_func():\n') - ... _ = f.write(' \"\"\"\n') - ... _ = f.write(' This is simple python test function.\n') - ... _ = f.write(' >>> 1 + 1\n') - ... _ = f.write(' 2\n') - ... _ = f.write(' >>> "abc def"\n') - ... _ = f.write(" 'abc def'\n") - ... _ = f.write("\n") - ... _ = f.write(' \"\"\"\n') - ... import shutil - ... rc1, out1, err1 = script_helper.assert_python_failure( - ... '-m', 'doctest', fn, fn2, TERM='') - ... rc2, out2, err2 = script_helper.assert_python_ok( - ... '-m', 'doctest', '-o', 'ELLIPSIS', fn, TERM='') - ... rc3, out3, err3 = script_helper.assert_python_ok( - ... '-m', 'doctest', '-o', 'ELLIPSIS', - ... '-o', 'NORMALIZE_WHITESPACE', fn, fn2, TERM='') - ... rc4, out4, err4 = script_helper.assert_python_failure( - ... '-m', 'doctest', '-f', fn, fn2, TERM='') - ... rc5, out5, err5 = script_helper.assert_python_ok( - ... '-m', 'doctest', '-v', '-o', 'ELLIPSIS', - ... '-o', 'NORMALIZE_WHITESPACE', fn, fn2, TERM='') - -Our first test run will show the errors from the first file (doctest stops if a -file has errors). Note that doctest test-run error output appears on stdout, -not stderr: - - >>> rc1, err1 - (1, b'') - >>> print(normalize(out1)) # doctest: +ELLIPSIS - ********************************************************************** - File "...myfile.doc", line 4, in myfile.doc - Failed example: - "abcdef" - Expected: - 'a...f' - Got: - 'abcdef' - ********************************************************************** - File "...myfile.doc", line 6, in myfile.doc - Failed example: - "ajkml" - Expected: - 'a...l' - Got: - 'ajkml' - ********************************************************************** - 1 items had failures: - 2 of 3 in myfile.doc - ***Test Failed*** 2 failures. - -With -o ELLIPSIS specified, the second run, against just the first file, should -produce no errors, and with -o NORMALIZE_WHITESPACE also specified, neither -should the third, which ran against both files: - - >>> rc2, out2, err2 - (0, b'', b'') - >>> rc3, out3, err3 - (0, b'', b'') - -The fourth run uses FAIL_FAST, so we should see only one error: - - >>> rc4, err4 - (1, b'') - >>> print(normalize(out4)) # doctest: +ELLIPSIS - ********************************************************************** - File "...myfile.doc", line 4, in myfile.doc - Failed example: - "abcdef" - Expected: - 'a...f' - Got: - 'abcdef' - ********************************************************************** - 1 items had failures: - 1 of 2 in myfile.doc - ***Test Failed*** 1 failures. - -The fifth test uses verbose with the two options, so we should get verbose -success output for the tests in both files: - - >>> rc5, err5 - (0, b'') - >>> print(normalize(out5)) - Trying: - 1 + 1 - Expecting: - 2 - ok - Trying: - "abcdef" - Expecting: - 'a...f' - ok - Trying: - "ajkml" - Expecting: - 'a...l' - ok - 1 items passed all tests: - 3 tests in myfile.doc - 3 tests in 1 items. - 3 passed and 0 failed. - Test passed. - Trying: - 1 + 1 - Expecting: - 2 - ok - Trying: - "abc def" - Expecting: - 'abc def' - ok - 1 items had no tests: - myfile2 - 1 items passed all tests: - 2 tests in myfile2.test_func - 2 tests in 2 items. - 2 passed and 0 failed. - Test passed. - -We should also check some typical error cases. - -Invalid file name: - - >>> rc, out, err = script_helper.assert_python_failure( - ... '-m', 'doctest', 'nosuchfile', TERM='') - >>> rc, out - (1, b'') - >>> print(normalize(err)) # doctest: +ELLIPSIS - Traceback (most recent call last): - ... - FileNotFoundError: [Errno ...] No such file or directory: 'nosuchfile' - -Invalid doctest option: - - >>> rc, out, err = script_helper.assert_python_failure( - ... '-m', 'doctest', '-o', 'nosuchoption', TERM='') - >>> rc, out - (2, b'') - >>> print(normalize(err)) # doctest: +ELLIPSIS - usage...invalid...nosuchoption... - -""" - ###################################################################### ## Main ###################################################################### diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_email/test__encoded_words.py --- a/Lib/test/test_email/test__encoded_words.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_email/test__encoded_words.py Fri Feb 01 23:12:09 2013 +0100 @@ -75,7 +75,7 @@ def test_non_trivial_q(self): self._test('=?latin-1?q?=20F=fcr=20Elise=20?=', ' Für Elise ', 'latin-1') - def test_q_escaped_bytes_preserved(self): + def test_q_escpaed_bytes_preserved(self): self._test(b'=?us-ascii?q?=20\xACfoo?='.decode('us-ascii', 'surrogateescape'), ' \uDCACfoo', @@ -122,11 +122,6 @@ # XXX Should this be a new Defect instead? defects = [errors.CharsetError]) - def test_q_nonascii(self): - self._test('=?utf-8?q?=C3=89ric?=', - 'Éric', - charset='utf-8') - class TestEncodeQ(TestEmailBase): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_email/test__header_value_parser.py --- a/Lib/test/test_email/test__header_value_parser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_email/test__header_value_parser.py Fri Feb 01 23:12:09 2013 +0100 @@ -170,15 +170,6 @@ [], '') - def test_get_encoded_word_quopri_utf_escape_follows_cte(self): - # Issue 18044 - self._test_get_x(parser.get_encoded_word, - '=?utf-8?q?=C3=89ric?=', - 'Éric', - 'Éric', - [], - '') - # get_unstructured def _get_unst(self, value): @@ -808,13 +799,9 @@ self.assertEqual(atom[2].comments, ['bar']) def test_get_atom_atom_ends_at_noncfws(self): - self._test_get_x(parser.get_atom, + atom = self._test_get_x(parser.get_atom, 'bob fred', 'bob ', 'bob ', [], 'fred') - def test_get_atom_rfc2047_atom(self): - self._test_get_x(parser.get_atom, - '=?utf-8?q?=20bob?=', ' bob', ' bob', [], '') - # get_dot_atom_text def test_get_dot_atom_text(self): @@ -889,10 +876,6 @@ with self.assertRaises(errors.HeaderParseError): parser.get_dot_atom(' (foo) bar.bang. foo') - def test_get_dot_atom_rfc2047_atom(self): - self._test_get_x(parser.get_dot_atom, - '=?utf-8?q?=20bob?=', ' bob', ' bob', [], '') - # get_word (if this were black box we'd repeat all the qs/atom tests) def test_get_word_atom_yields_atom(self): @@ -2164,22 +2147,6 @@ self.assertEqual(address[0].token_type, 'mailbox') - def test_get_address_rfc2047_display_name(self): - address = self._test_get_x(parser.get_address, - '=?utf-8?q?=C3=89ric?= ', - 'Éric ', - 'Éric ', - [], - '') - self.assertEqual(address.token_type, 'address') - self.assertEqual(len(address.mailboxes), 1) - self.assertEqual(address.mailboxes, - address.all_mailboxes) - self.assertEqual(address.mailboxes[0].display_name, - 'Éric') - self.assertEqual(address[0].token_type, - 'mailbox') - def test_get_address_empty_group(self): address = self._test_get_x(parser.get_address, 'Monty Python:;', diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_email/test_email.py --- a/Lib/test/test_email/test_email.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_email/test_email.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,10 +2,14 @@ # Contact: email-sig@python.org # email package unit tests +import os import re +import sys import time import base64 +import difflib import unittest +import warnings import textwrap from io import StringIO, BytesIO @@ -33,13 +37,9 @@ from email import base64mime from email import quoprimime -from test.support import unlink +from test.support import run_unittest, unlink from test.test_email import openfile, TestEmailBase -# These imports are documented to work, but we are testing them using a -# different path, so we import them here just to make sure they are importable. -from email.parser import FeedParser, BytesFeedParser - NL = '\n' EMPTYSTRING = '' SPACE = ' ' @@ -388,7 +388,6 @@ def test_del_param_on_nonexistent_header(self): msg = Message() - # Deleting param on empty msg should not raise exception. msg.del_param('filename', 'content-disposition') def test_del_nonexistent_param(self): @@ -396,7 +395,7 @@ msg.add_header('Content-Type', 'text/plain', charset='utf-8') existing_header = msg['Content-Type'] msg.del_param('foobar', header='Content-Type') - self.assertEqual(msg['Content-Type'], existing_header) + self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"') def test_set_type(self): eq = self.assertEqual @@ -678,27 +677,6 @@ msg = MIMEText('文', _charset='euc-jp') eq(msg['content-transfer-encoding'], '7bit') - def test_qp_encode_latin1(self): - msg = MIMEText('\xe1\xf6\n', 'text', 'ISO-8859-1') - self.assertEqual(str(msg), textwrap.dedent("""\ - MIME-Version: 1.0 - Content-Type: text/text; charset="iso-8859-1" - Content-Transfer-Encoding: quoted-printable - - =E1=F6 - """)) - - def test_qp_encode_non_latin1(self): - # Issue 16948 - msg = MIMEText('\u017c\n', 'text', 'ISO-8859-2') - self.assertEqual(str(msg), textwrap.dedent("""\ - MIME-Version: 1.0 - Content-Type: text/text; charset="iso-8859-2" - Content-Transfer-Encoding: quoted-printable - - =BF - """)) - # Test long header wrapping class TestLongHeaders(TestEmailBase): @@ -1441,68 +1419,6 @@ eq(msg.get_payload().strip(), '+vv8/f7/') eq(msg.get_payload(decode=True), bytesdata) - def test_binary_body_with_encode_7or8bit(self): - # Issue 17171. - bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff' - msg = MIMEApplication(bytesdata, _encoder=encoders.encode_7or8bit) - # Treated as a string, this will be invalid code points. - self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata)) - self.assertEqual(msg.get_payload(decode=True), bytesdata) - self.assertEqual(msg['Content-Transfer-Encoding'], '8bit') - s = BytesIO() - g = BytesGenerator(s) - g.flatten(msg) - wireform = s.getvalue() - msg2 = email.message_from_bytes(wireform) - self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata)) - self.assertEqual(msg2.get_payload(decode=True), bytesdata) - self.assertEqual(msg2['Content-Transfer-Encoding'], '8bit') - - def test_binary_body_with_encode_noop(self): - # Issue 16564: This does not produce an RFC valid message, since to be - # valid it should have a CTE of binary. But the below works in - # Python2, and is documented as working this way. - bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff' - msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop) - # Treated as a string, this will be invalid code points. - self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata)) - self.assertEqual(msg.get_payload(decode=True), bytesdata) - s = BytesIO() - g = BytesGenerator(s) - g.flatten(msg) - wireform = s.getvalue() - msg2 = email.message_from_bytes(wireform) - self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata)) - self.assertEqual(msg2.get_payload(decode=True), bytesdata) - - def test_binary_body_with_encode_quopri(self): - # Issue 14360. - bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff ' - msg = MIMEApplication(bytesdata, _encoder=encoders.encode_quopri) - self.assertEqual(msg.get_payload(), '=FA=FB=FC=FD=FE=FF=20') - self.assertEqual(msg.get_payload(decode=True), bytesdata) - self.assertEqual(msg['Content-Transfer-Encoding'], 'quoted-printable') - s = BytesIO() - g = BytesGenerator(s) - g.flatten(msg) - wireform = s.getvalue() - msg2 = email.message_from_bytes(wireform) - self.assertEqual(msg.get_payload(), '=FA=FB=FC=FD=FE=FF=20') - self.assertEqual(msg2.get_payload(decode=True), bytesdata) - self.assertEqual(msg2['Content-Transfer-Encoding'], 'quoted-printable') - - def test_binary_body_with_encode_base64(self): - bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff' - msg = MIMEApplication(bytesdata, _encoder=encoders.encode_base64) - self.assertEqual(msg.get_payload(), '+vv8/f7/\n') - self.assertEqual(msg.get_payload(decode=True), bytesdata) - s = BytesIO() - g = BytesGenerator(s) - g.flatten(msg) - wireform = s.getvalue() - msg2 = email.message_from_bytes(wireform) - self.assertEqual(msg.get_payload(), '+vv8/f7/\n') - self.assertEqual(msg2.get_payload(decode=True), bytesdata) # Test the basic MIMEText class @@ -2266,6 +2182,7 @@ eq(subpart['subject'], subject) def test_bad_multipart(self): + eq = self.assertEqual msg1 = Message() msg1['Subject'] = 'subpart 1' msg2 = Message() @@ -3140,40 +3057,6 @@ email.utils.make_msgid(domain='testdomain-string')[-19:], '@testdomain-string>') - def test_Generator_linend(self): - # Issue 14645. - with openfile('msg_26.txt', newline='\n') as f: - msgtxt = f.read() - msgtxt_nl = msgtxt.replace('\r\n', '\n') - msg = email.message_from_string(msgtxt) - s = StringIO() - g = email.generator.Generator(s) - g.flatten(msg) - self.assertEqual(s.getvalue(), msgtxt_nl) - - def test_BytesGenerator_linend(self): - # Issue 14645. - with openfile('msg_26.txt', newline='\n') as f: - msgtxt = f.read() - msgtxt_nl = msgtxt.replace('\r\n', '\n') - msg = email.message_from_string(msgtxt_nl) - s = BytesIO() - g = email.generator.BytesGenerator(s) - g.flatten(msg, linesep='\r\n') - self.assertEqual(s.getvalue().decode('ascii'), msgtxt) - - def test_BytesGenerator_linend_with_non_ascii(self): - # Issue 14645. - with openfile('msg_26.txt', 'rb') as f: - msgtxt = f.read() - msgtxt = msgtxt.replace(b'with attachment', b'fo\xf6') - msgtxt_nl = msgtxt.replace(b'\r\n', b'\n') - msg = email.message_from_bytes(msgtxt_nl) - s = BytesIO() - g = email.generator.BytesGenerator(s) - g.flatten(msg, linesep='\r\n') - self.assertEqual(s.getvalue(), msgtxt) - # Test the iterator/generators class TestIterators(TestEmailBase): @@ -4048,10 +3931,6 @@ def test_header_decode_non_ascii(self): self._test_header_decode('hello=C7there', 'hello\xc7there') - def test_header_decode_re_bug_18380(self): - # Issue 18380: Call re.sub with a positional argument for flags in the wrong position - self.assertEqual(quoprimime.header_decode('=30' * 257), '0' * 257) - def _test_decode(self, encoded, expected_decoded, eol=None): if eol is None: decoded = quoprimime.decode(encoded) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_email/test_headerregistry.py --- a/Lib/test/test_email/test_headerregistry.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_email/test_headerregistry.py Fri Feb 01 23:12:09 2013 +0100 @@ -123,49 +123,12 @@ # self.assertEqual(h, value) # self.assertDefectsEqual(h.defects, [errors.ObsoleteHeaderDefect]) + def test_RFC2047_value_decoded(self): + value = '=?utf-8?q?this_is_a_test?=' + h = self.make_header('subject', value) + self.assertEqual(h, 'this is a test') -@parameterize -class TestUnstructuredHeader(TestHeaderBase): - def string_as_value(self, - source, - decoded, - *args): - l = len(args) - defects = args[0] if l>0 else [] - header = 'Subject:' + (' ' if source else '') - folded = header + (args[1] if l>1 else source) + '\n' - h = self.make_header('Subject', source) - self.assertEqual(h, decoded) - self.assertDefectsEqual(h.defects, defects) - self.assertEqual(h.fold(policy=policy.default), folded) - - string_params = { - - 'rfc2047_simple_quopri': ( - '=?utf-8?q?this_is_a_test?=', - 'this is a test', - [], - 'this is a test'), - - 'rfc2047_gb2312_base64': ( - '=?gb2312?b?1eLKx9bQzsSy4srUo6E=?=', - '\u8fd9\u662f\u4e2d\u6587\u6d4b\u8bd5\uff01', - [], - '=?utf-8?b?6L+Z5piv5Lit5paH5rWL6K+V77yB?='), - - 'rfc2047_simple_nonascii_quopri': ( - '=?utf-8?q?=C3=89ric?=', - 'Éric'), - - 'rfc2047_quopri_with_regular_text': ( - 'The =?utf-8?q?=C3=89ric=2C?= Himself', - 'The Éric, Himself'), - - } - - -@parameterize class TestDateHeader(TestHeaderBase): datestring = 'Sun, 23 Sep 2001 20:10:55 -0700' @@ -707,7 +670,7 @@ ), # XXX: I would say this one should default to ascii/en for the - # "encoded" segment, since the first segment is not encoded and is + # "encoded" segment, since the the first segment is not encoded and is # in double quotes, making the value a valid non-encoded string. The # old parser decodes this just like the previous case, which may be the # better Postel rule, but could equally result in borking headers that @@ -1123,26 +1086,6 @@ 'example.com', None), - 'rfc2047_atom_is_decoded': - ('=?utf-8?q?=C3=89ric?= ', - [], - 'Éric ', - 'Éric', - 'foo@example.com', - 'foo', - 'example.com', - None), - - 'rfc2047_atom_in_phrase_is_decoded': - ('The =?utf-8?q?=C3=89ric=2C?= Himself ', - [], - '"The Éric, Himself" ', - 'The Éric, Himself', - 'foo@example.com', - 'foo', - 'example.com', - None), - } # XXX: Need many more examples, and in particular some with names in diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_email/test_inversion.py --- a/Lib/test/test_email/test_inversion.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -"""Test the parser and generator are inverses. - -Note that this is only strictly true if we are parsing RFC valid messages and -producing RFC valid messages. -""" - -import io -import unittest -from email import policy, message_from_bytes -from email.generator import BytesGenerator -from test.test_email import TestEmailBase, parameterize - -# This is like textwrap.dedent for bytes, except that it uses \r\n for the line -# separators on the rebuilt string. -def dedent(bstr): - lines = bstr.splitlines() - if not lines[0].strip(): - raise ValueError("First line must contain text") - stripamt = len(lines[0]) - len(lines[0].lstrip()) - return b'\r\n'.join( - [x[stripamt:] if len(x)>=stripamt else b'' - for x in lines]) - - -@parameterize -class TestInversion(TestEmailBase, unittest.TestCase): - - def msg_as_input(self, msg): - m = message_from_bytes(msg, policy=policy.SMTP) - b = io.BytesIO() - g = BytesGenerator(b) - g.flatten(m) - self.assertEqual(b.getvalue(), msg) - - # XXX: spaces are not preserved correctly here yet in the general case. - msg_params = { - 'header_with_one_space_body': (dedent(b"""\ - From: abc@xyz.com - X-Status:\x20 - Subject: test - - foo - """),), - - } - - -if __name__ == '__main__': - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_email/test_utils.py --- a/Lib/test/test_email/test_utils.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_email/test_utils.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,7 +4,6 @@ import time import unittest import sys -import os.path class DateTimeTests(unittest.TestCase): @@ -124,9 +123,6 @@ # XXX: Need a more robust test for Olson's tzdata @unittest.skipIf(sys.platform.startswith('win'), "Windows does not use Olson's TZ database") - @unittest.skipUnless(os.path.exists('/usr/share/zoneinfo') or - os.path.exists('/usr/lib/zoneinfo'), - "Can't find the Olson's TZ database") @test.support.run_with_tz('Europe/Kiev') def test_variable_tzname(self): t0 = datetime.datetime(1984, 1, 1, tzinfo=datetime.timezone.utc) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_enum.py --- a/Lib/test/test_enum.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,989 +0,0 @@ -import enum -import unittest -from collections import OrderedDict -from pickle import dumps, loads, PicklingError -from enum import Enum, IntEnum, unique - -# for pickle tests -try: - class Stooges(Enum): - LARRY = 1 - CURLY = 2 - MOE = 3 -except Exception as exc: - Stooges = exc - -try: - class IntStooges(int, Enum): - LARRY = 1 - CURLY = 2 - MOE = 3 -except Exception as exc: - IntStooges = exc - -try: - class FloatStooges(float, Enum): - LARRY = 1.39 - CURLY = 2.72 - MOE = 3.142596 -except Exception as exc: - FloatStooges = exc - -# for pickle test and subclass tests -try: - class StrEnum(str, Enum): - 'accepts only string values' - class Name(StrEnum): - BDFL = 'Guido van Rossum' - FLUFL = 'Barry Warsaw' -except Exception as exc: - Name = exc - -try: - Question = Enum('Question', 'who what when where why', module=__name__) -except Exception as exc: - Question = exc - -try: - Answer = Enum('Answer', 'him this then there because') -except Exception as exc: - Answer = exc - -# for doctests -try: - class Fruit(Enum): - tomato = 1 - banana = 2 - cherry = 3 -except Exception: - pass - -class TestEnum(unittest.TestCase): - def setUp(self): - class Season(Enum): - SPRING = 1 - SUMMER = 2 - AUTUMN = 3 - WINTER = 4 - self.Season = Season - - def test_enum_in_enum_out(self): - Season = self.Season - self.assertIs(Season(Season.WINTER), Season.WINTER) - - def test_enum_value(self): - Season = self.Season - self.assertEqual(Season.SPRING.value, 1) - - def test_intenum_value(self): - self.assertEqual(IntStooges.CURLY.value, 2) - - def test_dir_on_class(self): - Season = self.Season - self.assertEqual( - set(dir(Season)), - set(['__class__', '__doc__', '__members__', - 'SPRING', 'SUMMER', 'AUTUMN', 'WINTER']), - ) - - def test_dir_on_item(self): - Season = self.Season - self.assertEqual( - set(dir(Season.WINTER)), - set(['__class__', '__doc__', 'name', 'value']), - ) - - def test_enum(self): - Season = self.Season - lst = list(Season) - self.assertEqual(len(lst), len(Season)) - self.assertEqual(len(Season), 4, Season) - self.assertEqual( - [Season.SPRING, Season.SUMMER, Season.AUTUMN, Season.WINTER], lst) - - for i, season in enumerate('SPRING SUMMER AUTUMN WINTER'.split(), 1): - e = Season(i) - self.assertEqual(e, getattr(Season, season)) - self.assertEqual(e.value, i) - self.assertNotEqual(e, i) - self.assertEqual(e.name, season) - self.assertIn(e, Season) - self.assertIs(type(e), Season) - self.assertIsInstance(e, Season) - self.assertEqual(str(e), 'Season.' + season) - self.assertEqual( - repr(e), - ''.format(season, i), - ) - - def test_value_name(self): - Season = self.Season - self.assertEqual(Season.SPRING.name, 'SPRING') - self.assertEqual(Season.SPRING.value, 1) - with self.assertRaises(AttributeError): - Season.SPRING.name = 'invierno' - with self.assertRaises(AttributeError): - Season.SPRING.value = 2 - - def test_invalid_names(self): - with self.assertRaises(ValueError): - class Wrong(Enum): - mro = 9 - with self.assertRaises(ValueError): - class Wrong(Enum): - _create_= 11 - with self.assertRaises(ValueError): - class Wrong(Enum): - _get_mixins_ = 9 - with self.assertRaises(ValueError): - class Wrong(Enum): - _find_new_ = 1 - with self.assertRaises(ValueError): - class Wrong(Enum): - _any_name_ = 9 - - def test_contains(self): - Season = self.Season - self.assertIn(Season.AUTUMN, Season) - self.assertNotIn(3, Season) - - val = Season(3) - self.assertIn(val, Season) - - class OtherEnum(Enum): - one = 1; two = 2 - self.assertNotIn(OtherEnum.two, Season) - - def test_comparisons(self): - Season = self.Season - with self.assertRaises(TypeError): - Season.SPRING < Season.WINTER - with self.assertRaises(TypeError): - Season.SPRING > 4 - - self.assertNotEqual(Season.SPRING, 1) - - class Part(Enum): - SPRING = 1 - CLIP = 2 - BARREL = 3 - - self.assertNotEqual(Season.SPRING, Part.SPRING) - with self.assertRaises(TypeError): - Season.SPRING < Part.CLIP - - def test_enum_duplicates(self): - class Season(Enum): - SPRING = 1 - SUMMER = 2 - AUTUMN = FALL = 3 - WINTER = 4 - ANOTHER_SPRING = 1 - lst = list(Season) - self.assertEqual( - lst, - [Season.SPRING, Season.SUMMER, - Season.AUTUMN, Season.WINTER, - ]) - self.assertIs(Season.FALL, Season.AUTUMN) - self.assertEqual(Season.FALL.value, 3) - self.assertEqual(Season.AUTUMN.value, 3) - self.assertIs(Season(3), Season.AUTUMN) - self.assertIs(Season(1), Season.SPRING) - self.assertEqual(Season.FALL.name, 'AUTUMN') - self.assertEqual( - [k for k,v in Season.__members__.items() if v.name != k], - ['FALL', 'ANOTHER_SPRING'], - ) - - def test_enum_with_value_name(self): - class Huh(Enum): - name = 1 - value = 2 - self.assertEqual( - list(Huh), - [Huh.name, Huh.value], - ) - self.assertIs(type(Huh.name), Huh) - self.assertEqual(Huh.name.name, 'name') - self.assertEqual(Huh.name.value, 1) - def test_hash(self): - Season = self.Season - dates = {} - dates[Season.WINTER] = '1225' - dates[Season.SPRING] = '0315' - dates[Season.SUMMER] = '0704' - dates[Season.AUTUMN] = '1031' - self.assertEqual(dates[Season.AUTUMN], '1031') - - def test_intenum_from_scratch(self): - class phy(int, Enum): - pi = 3 - tau = 2 * pi - self.assertTrue(phy.pi < phy.tau) - - def test_intenum_inherited(self): - class IntEnum(int, Enum): - pass - class phy(IntEnum): - pi = 3 - tau = 2 * pi - self.assertTrue(phy.pi < phy.tau) - - def test_floatenum_from_scratch(self): - class phy(float, Enum): - pi = 3.141596 - tau = 2 * pi - self.assertTrue(phy.pi < phy.tau) - - def test_floatenum_inherited(self): - class FloatEnum(float, Enum): - pass - class phy(FloatEnum): - pi = 3.141596 - tau = 2 * pi - self.assertTrue(phy.pi < phy.tau) - - def test_strenum_from_scratch(self): - class phy(str, Enum): - pi = 'Pi' - tau = 'Tau' - self.assertTrue(phy.pi < phy.tau) - - def test_strenum_inherited(self): - class StrEnum(str, Enum): - pass - class phy(StrEnum): - pi = 'Pi' - tau = 'Tau' - self.assertTrue(phy.pi < phy.tau) - - - def test_intenum(self): - class WeekDay(IntEnum): - SUNDAY = 1 - MONDAY = 2 - TUESDAY = 3 - WEDNESDAY = 4 - THURSDAY = 5 - FRIDAY = 6 - SATURDAY = 7 - - self.assertEqual(['a', 'b', 'c'][WeekDay.MONDAY], 'c') - self.assertEqual([i for i in range(WeekDay.TUESDAY)], [0, 1, 2]) - - lst = list(WeekDay) - self.assertEqual(len(lst), len(WeekDay)) - self.assertEqual(len(WeekDay), 7) - target = 'SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY' - target = target.split() - for i, weekday in enumerate(target, 1): - e = WeekDay(i) - self.assertEqual(e, i) - self.assertEqual(int(e), i) - self.assertEqual(e.name, weekday) - self.assertIn(e, WeekDay) - self.assertEqual(lst.index(e)+1, i) - self.assertTrue(0 < e < 8) - self.assertIs(type(e), WeekDay) - self.assertIsInstance(e, int) - self.assertIsInstance(e, Enum) - - def test_intenum_duplicates(self): - class WeekDay(IntEnum): - SUNDAY = 1 - MONDAY = 2 - TUESDAY = TEUSDAY = 3 - WEDNESDAY = 4 - THURSDAY = 5 - FRIDAY = 6 - SATURDAY = 7 - self.assertIs(WeekDay.TEUSDAY, WeekDay.TUESDAY) - self.assertEqual(WeekDay(3).name, 'TUESDAY') - self.assertEqual([k for k,v in WeekDay.__members__.items() - if v.name != k], ['TEUSDAY', ]) - - def test_pickle_enum(self): - if isinstance(Stooges, Exception): - raise Stooges - self.assertIs(Stooges.CURLY, loads(dumps(Stooges.CURLY))) - self.assertIs(Stooges, loads(dumps(Stooges))) - - def test_pickle_int(self): - if isinstance(IntStooges, Exception): - raise IntStooges - self.assertIs(IntStooges.CURLY, loads(dumps(IntStooges.CURLY))) - self.assertIs(IntStooges, loads(dumps(IntStooges))) - - def test_pickle_float(self): - if isinstance(FloatStooges, Exception): - raise FloatStooges - self.assertIs(FloatStooges.CURLY, loads(dumps(FloatStooges.CURLY))) - self.assertIs(FloatStooges, loads(dumps(FloatStooges))) - - def test_pickle_enum_function(self): - if isinstance(Answer, Exception): - raise Answer - self.assertIs(Answer.him, loads(dumps(Answer.him))) - self.assertIs(Answer, loads(dumps(Answer))) - - def test_pickle_enum_function_with_module(self): - if isinstance(Question, Exception): - raise Question - self.assertIs(Question.who, loads(dumps(Question.who))) - self.assertIs(Question, loads(dumps(Question))) - - def test_exploding_pickle(self): - BadPickle = Enum('BadPickle', 'dill sweet bread-n-butter') - enum._make_class_unpicklable(BadPickle) - globals()['BadPickle'] = BadPickle - with self.assertRaises(TypeError): - dumps(BadPickle.dill) - with self.assertRaises(PicklingError): - dumps(BadPickle) - - def test_string_enum(self): - class SkillLevel(str, Enum): - master = 'what is the sound of one hand clapping?' - journeyman = 'why did the chicken cross the road?' - apprentice = 'knock, knock!' - self.assertEqual(SkillLevel.apprentice, 'knock, knock!') - - def test_getattr_getitem(self): - class Period(Enum): - morning = 1 - noon = 2 - evening = 3 - night = 4 - self.assertIs(Period(2), Period.noon) - self.assertIs(getattr(Period, 'night'), Period.night) - self.assertIs(Period['morning'], Period.morning) - - def test_getattr_dunder(self): - Season = self.Season - self.assertTrue(getattr(Season, '__eq__')) - - def test_iteration_order(self): - class Season(Enum): - SUMMER = 2 - WINTER = 4 - AUTUMN = 3 - SPRING = 1 - self.assertEqual( - list(Season), - [Season.SUMMER, Season.WINTER, Season.AUTUMN, Season.SPRING], - ) - - def test_programatic_function_string(self): - SummerMonth = Enum('SummerMonth', 'june july august') - lst = list(SummerMonth) - self.assertEqual(len(lst), len(SummerMonth)) - self.assertEqual(len(SummerMonth), 3, SummerMonth) - self.assertEqual( - [SummerMonth.june, SummerMonth.july, SummerMonth.august], - lst, - ) - for i, month in enumerate('june july august'.split(), 1): - e = SummerMonth(i) - self.assertEqual(int(e.value), i) - self.assertNotEqual(e, i) - self.assertEqual(e.name, month) - self.assertIn(e, SummerMonth) - self.assertIs(type(e), SummerMonth) - - def test_programatic_function_string_list(self): - SummerMonth = Enum('SummerMonth', ['june', 'july', 'august']) - lst = list(SummerMonth) - self.assertEqual(len(lst), len(SummerMonth)) - self.assertEqual(len(SummerMonth), 3, SummerMonth) - self.assertEqual( - [SummerMonth.june, SummerMonth.july, SummerMonth.august], - lst, - ) - for i, month in enumerate('june july august'.split(), 1): - e = SummerMonth(i) - self.assertEqual(int(e.value), i) - self.assertNotEqual(e, i) - self.assertEqual(e.name, month) - self.assertIn(e, SummerMonth) - self.assertIs(type(e), SummerMonth) - - def test_programatic_function_iterable(self): - SummerMonth = Enum( - 'SummerMonth', - (('june', 1), ('july', 2), ('august', 3)) - ) - lst = list(SummerMonth) - self.assertEqual(len(lst), len(SummerMonth)) - self.assertEqual(len(SummerMonth), 3, SummerMonth) - self.assertEqual( - [SummerMonth.june, SummerMonth.july, SummerMonth.august], - lst, - ) - for i, month in enumerate('june july august'.split(), 1): - e = SummerMonth(i) - self.assertEqual(int(e.value), i) - self.assertNotEqual(e, i) - self.assertEqual(e.name, month) - self.assertIn(e, SummerMonth) - self.assertIs(type(e), SummerMonth) - - def test_programatic_function_from_dict(self): - SummerMonth = Enum( - 'SummerMonth', - OrderedDict((('june', 1), ('july', 2), ('august', 3))) - ) - lst = list(SummerMonth) - self.assertEqual(len(lst), len(SummerMonth)) - self.assertEqual(len(SummerMonth), 3, SummerMonth) - self.assertEqual( - [SummerMonth.june, SummerMonth.july, SummerMonth.august], - lst, - ) - for i, month in enumerate('june july august'.split(), 1): - e = SummerMonth(i) - self.assertEqual(int(e.value), i) - self.assertNotEqual(e, i) - self.assertEqual(e.name, month) - self.assertIn(e, SummerMonth) - self.assertIs(type(e), SummerMonth) - - def test_programatic_function_type(self): - SummerMonth = Enum('SummerMonth', 'june july august', type=int) - lst = list(SummerMonth) - self.assertEqual(len(lst), len(SummerMonth)) - self.assertEqual(len(SummerMonth), 3, SummerMonth) - self.assertEqual( - [SummerMonth.june, SummerMonth.july, SummerMonth.august], - lst, - ) - for i, month in enumerate('june july august'.split(), 1): - e = SummerMonth(i) - self.assertEqual(e, i) - self.assertEqual(e.name, month) - self.assertIn(e, SummerMonth) - self.assertIs(type(e), SummerMonth) - - def test_programatic_function_type_from_subclass(self): - SummerMonth = IntEnum('SummerMonth', 'june july august') - lst = list(SummerMonth) - self.assertEqual(len(lst), len(SummerMonth)) - self.assertEqual(len(SummerMonth), 3, SummerMonth) - self.assertEqual( - [SummerMonth.june, SummerMonth.july, SummerMonth.august], - lst, - ) - for i, month in enumerate('june july august'.split(), 1): - e = SummerMonth(i) - self.assertEqual(e, i) - self.assertEqual(e.name, month) - self.assertIn(e, SummerMonth) - self.assertIs(type(e), SummerMonth) - - def test_subclassing(self): - if isinstance(Name, Exception): - raise Name - self.assertEqual(Name.BDFL, 'Guido van Rossum') - self.assertTrue(Name.BDFL, Name('Guido van Rossum')) - self.assertIs(Name.BDFL, getattr(Name, 'BDFL')) - self.assertIs(Name.BDFL, loads(dumps(Name.BDFL))) - - def test_extending(self): - class Color(Enum): - red = 1 - green = 2 - blue = 3 - with self.assertRaises(TypeError): - class MoreColor(Color): - cyan = 4 - magenta = 5 - yellow = 6 - - def test_exclude_methods(self): - class whatever(Enum): - this = 'that' - these = 'those' - def really(self): - return 'no, not %s' % self.value - self.assertIsNot(type(whatever.really), whatever) - self.assertEqual(whatever.this.really(), 'no, not that') - - def test_overwrite_enums(self): - class Why(Enum): - question = 1 - answer = 2 - propisition = 3 - def question(self): - print(42) - self.assertIsNot(type(Why.question), Why) - self.assertNotIn(Why.question, Why._member_names_) - self.assertNotIn(Why.question, Why) - - def test_wrong_inheritance_order(self): - with self.assertRaises(TypeError): - class Wrong(Enum, str): - NotHere = 'error before this point' - - def test_intenum_transitivity(self): - class number(IntEnum): - one = 1 - two = 2 - three = 3 - class numero(IntEnum): - uno = 1 - dos = 2 - tres = 3 - self.assertEqual(number.one, numero.uno) - self.assertEqual(number.two, numero.dos) - self.assertEqual(number.three, numero.tres) - - def test_wrong_enum_in_call(self): - class Monochrome(Enum): - black = 0 - white = 1 - class Gender(Enum): - male = 0 - female = 1 - self.assertRaises(ValueError, Monochrome, Gender.male) - - def test_wrong_enum_in_mixed_call(self): - class Monochrome(IntEnum): - black = 0 - white = 1 - class Gender(Enum): - male = 0 - female = 1 - self.assertRaises(ValueError, Monochrome, Gender.male) - - def test_mixed_enum_in_call_1(self): - class Monochrome(IntEnum): - black = 0 - white = 1 - class Gender(IntEnum): - male = 0 - female = 1 - self.assertIs(Monochrome(Gender.female), Monochrome.white) - - def test_mixed_enum_in_call_2(self): - class Monochrome(Enum): - black = 0 - white = 1 - class Gender(IntEnum): - male = 0 - female = 1 - self.assertIs(Monochrome(Gender.male), Monochrome.black) - - def test_flufl_enum(self): - class Fluflnum(Enum): - def __int__(self): - return int(self.value) - class MailManOptions(Fluflnum): - option1 = 1 - option2 = 2 - option3 = 3 - self.assertEqual(int(MailManOptions.option1), 1) - - def test_no_such_enum_member(self): - class Color(Enum): - red = 1 - green = 2 - blue = 3 - with self.assertRaises(ValueError): - Color(4) - with self.assertRaises(KeyError): - Color['chartreuse'] - - def test_new_repr(self): - class Color(Enum): - red = 1 - green = 2 - blue = 3 - def __repr__(self): - return "don't you just love shades of %s?" % self.name - self.assertEqual( - repr(Color.blue), - "don't you just love shades of blue?", - ) - - def test_inherited_repr(self): - class MyEnum(Enum): - def __repr__(self): - return "My name is %s." % self.name - class MyIntEnum(int, MyEnum): - this = 1 - that = 2 - theother = 3 - self.assertEqual(repr(MyIntEnum.that), "My name is that.") - - def test_multiple_mixin_mro(self): - class auto_enum(type(Enum)): - def __new__(metacls, cls, bases, classdict): - temp = type(classdict)() - names = set(classdict._member_names) - i = 0 - for k in classdict._member_names: - v = classdict[k] - if v is Ellipsis: - v = i - else: - i = v - i += 1 - temp[k] = v - for k, v in classdict.items(): - if k not in names: - temp[k] = v - return super(auto_enum, metacls).__new__( - metacls, cls, bases, temp) - - class AutoNumberedEnum(Enum, metaclass=auto_enum): - pass - - class AutoIntEnum(IntEnum, metaclass=auto_enum): - pass - - class TestAutoNumber(AutoNumberedEnum): - a = ... - b = 3 - c = ... - - class TestAutoInt(AutoIntEnum): - a = ... - b = 3 - c = ... - - def test_subclasses_with_getnewargs(self): - class NamedInt(int): - def __new__(cls, *args): - _args = args - name, *args = args - if len(args) == 0: - raise TypeError("name and value must be specified") - self = int.__new__(cls, *args) - self._intname = name - self._args = _args - return self - def __getnewargs__(self): - return self._args - @property - def __name__(self): - return self._intname - def __repr__(self): - # repr() is updated to include the name and type info - return "{}({!r}, {})".format(type(self).__name__, - self.__name__, - int.__repr__(self)) - def __str__(self): - # str() is unchanged, even if it relies on the repr() fallback - base = int - base_str = base.__str__ - if base_str.__objclass__ is object: - return base.__repr__(self) - return base_str(self) - # for simplicity, we only define one operator that - # propagates expressions - def __add__(self, other): - temp = int(self) + int( other) - if isinstance(self, NamedInt) and isinstance(other, NamedInt): - return NamedInt( - '({0} + {1})'.format(self.__name__, other.__name__), - temp ) - else: - return temp - - class NEI(NamedInt, Enum): - x = ('the-x', 1) - y = ('the-y', 2) - - - self.assertIs(NEI.__new__, Enum.__new__) - self.assertEqual(repr(NEI.x + NEI.y), "NamedInt('(the-x + the-y)', 3)") - globals()['NamedInt'] = NamedInt - globals()['NEI'] = NEI - NI5 = NamedInt('test', 5) - self.assertEqual(NI5, 5) - self.assertEqual(loads(dumps(NI5)), 5) - self.assertEqual(NEI.y.value, 2) - self.assertIs(loads(dumps(NEI.y)), NEI.y) - - def test_subclasses_without_getnewargs(self): - class NamedInt(int): - def __new__(cls, *args): - _args = args - name, *args = args - if len(args) == 0: - raise TypeError("name and value must be specified") - self = int.__new__(cls, *args) - self._intname = name - self._args = _args - return self - @property - def __name__(self): - return self._intname - def __repr__(self): - # repr() is updated to include the name and type info - return "{}({!r}, {})".format(type(self).__name__, - self.__name__, - int.__repr__(self)) - def __str__(self): - # str() is unchanged, even if it relies on the repr() fallback - base = int - base_str = base.__str__ - if base_str.__objclass__ is object: - return base.__repr__(self) - return base_str(self) - # for simplicity, we only define one operator that - # propagates expressions - def __add__(self, other): - temp = int(self) + int( other) - if isinstance(self, NamedInt) and isinstance(other, NamedInt): - return NamedInt( - '({0} + {1})'.format(self.__name__, other.__name__), - temp ) - else: - return temp - - class NEI(NamedInt, Enum): - x = ('the-x', 1) - y = ('the-y', 2) - - self.assertIs(NEI.__new__, Enum.__new__) - self.assertEqual(repr(NEI.x + NEI.y), "NamedInt('(the-x + the-y)', 3)") - globals()['NamedInt'] = NamedInt - globals()['NEI'] = NEI - NI5 = NamedInt('test', 5) - self.assertEqual(NI5, 5) - self.assertEqual(NEI.y.value, 2) - with self.assertRaises(TypeError): - dumps(NEI.x) - with self.assertRaises(PicklingError): - dumps(NEI) - - def test_tuple_subclass(self): - class SomeTuple(tuple, Enum): - first = (1, 'for the money') - second = (2, 'for the show') - third = (3, 'for the music') - self.assertIs(type(SomeTuple.first), SomeTuple) - self.assertIsInstance(SomeTuple.second, tuple) - self.assertEqual(SomeTuple.third, (3, 'for the music')) - globals()['SomeTuple'] = SomeTuple - self.assertIs(loads(dumps(SomeTuple.first)), SomeTuple.first) - - def test_duplicate_values_give_unique_enum_items(self): - class AutoNumber(Enum): - first = () - second = () - third = () - def __new__(cls): - value = len(cls.__members__) + 1 - obj = object.__new__(cls) - obj._value_ = value - return obj - def __int__(self): - return int(self._value_) - self.assertEqual( - list(AutoNumber), - [AutoNumber.first, AutoNumber.second, AutoNumber.third], - ) - self.assertEqual(int(AutoNumber.second), 2) - self.assertEqual(AutoNumber.third.value, 3) - self.assertIs(AutoNumber(1), AutoNumber.first) - - def test_inherited_new_from_enhanced_enum(self): - class AutoNumber(Enum): - def __new__(cls): - value = len(cls.__members__) + 1 - obj = object.__new__(cls) - obj._value_ = value - return obj - def __int__(self): - return int(self._value_) - class Color(AutoNumber): - red = () - green = () - blue = () - self.assertEqual(list(Color), [Color.red, Color.green, Color.blue]) - self.assertEqual(list(map(int, Color)), [1, 2, 3]) - - def test_inherited_new_from_mixed_enum(self): - class AutoNumber(IntEnum): - def __new__(cls): - value = len(cls.__members__) + 1 - obj = int.__new__(cls, value) - obj._value_ = value - return obj - class Color(AutoNumber): - red = () - green = () - blue = () - self.assertEqual(list(Color), [Color.red, Color.green, Color.blue]) - self.assertEqual(list(map(int, Color)), [1, 2, 3]) - - def test_ordered_mixin(self): - class OrderedEnum(Enum): - def __ge__(self, other): - if self.__class__ is other.__class__: - return self._value_ >= other._value_ - return NotImplemented - def __gt__(self, other): - if self.__class__ is other.__class__: - return self._value_ > other._value_ - return NotImplemented - def __le__(self, other): - if self.__class__ is other.__class__: - return self._value_ <= other._value_ - return NotImplemented - def __lt__(self, other): - if self.__class__ is other.__class__: - return self._value_ < other._value_ - return NotImplemented - class Grade(OrderedEnum): - A = 5 - B = 4 - C = 3 - D = 2 - F = 1 - self.assertGreater(Grade.A, Grade.B) - self.assertLessEqual(Grade.F, Grade.C) - self.assertLess(Grade.D, Grade.A) - self.assertGreaterEqual(Grade.B, Grade.B) - - def test_extending2(self): - class Shade(Enum): - def shade(self): - print(self.name) - class Color(Shade): - red = 1 - green = 2 - blue = 3 - with self.assertRaises(TypeError): - class MoreColor(Color): - cyan = 4 - magenta = 5 - yellow = 6 - - def test_extending3(self): - class Shade(Enum): - def shade(self): - return self.name - class Color(Shade): - def hex(self): - return '%s hexlified!' % self.value - class MoreColor(Color): - cyan = 4 - magenta = 5 - yellow = 6 - self.assertEqual(MoreColor.magenta.hex(), '5 hexlified!') - - - def test_no_duplicates(self): - class UniqueEnum(Enum): - def __init__(self, *args): - cls = self.__class__ - if any(self.value == e.value for e in cls): - a = self.name - e = cls(self.value).name - raise ValueError( - "aliases not allowed in UniqueEnum: %r --> %r" - % (a, e) - ) - class Color(UniqueEnum): - red = 1 - green = 2 - blue = 3 - with self.assertRaises(ValueError): - class Color(UniqueEnum): - red = 1 - green = 2 - blue = 3 - grene = 2 - - def test_init(self): - class Planet(Enum): - MERCURY = (3.303e+23, 2.4397e6) - VENUS = (4.869e+24, 6.0518e6) - EARTH = (5.976e+24, 6.37814e6) - MARS = (6.421e+23, 3.3972e6) - JUPITER = (1.9e+27, 7.1492e7) - SATURN = (5.688e+26, 6.0268e7) - URANUS = (8.686e+25, 2.5559e7) - NEPTUNE = (1.024e+26, 2.4746e7) - def __init__(self, mass, radius): - self.mass = mass # in kilograms - self.radius = radius # in meters - @property - def surface_gravity(self): - # universal gravitational constant (m3 kg-1 s-2) - G = 6.67300E-11 - return G * self.mass / (self.radius * self.radius) - self.assertEqual(round(Planet.EARTH.surface_gravity, 2), 9.80) - self.assertEqual(Planet.EARTH.value, (5.976e+24, 6.37814e6)) - - def test_nonhash_value(self): - class AutoNumberInAList(Enum): - def __new__(cls): - value = [len(cls.__members__) + 1] - obj = object.__new__(cls) - obj._value_ = value - return obj - class ColorInAList(AutoNumberInAList): - red = () - green = () - blue = () - self.assertEqual(list(ColorInAList), [ColorInAList.red, ColorInAList.green, ColorInAList.blue]) - self.assertEqual(ColorInAList.red.value, [1]) - self.assertEqual(ColorInAList([1]), ColorInAList.red) - - def test_conflicting_types_resolved_in_new(self): - class LabelledIntEnum(int, Enum): - def __new__(cls, *args): - value, label = args - obj = int.__new__(cls, value) - obj.label = label - obj._value_ = value - return obj - - class LabelledList(LabelledIntEnum): - unprocessed = (1, "Unprocessed") - payment_complete = (2, "Payment Complete") - - self.assertEqual(list(LabelledList), [LabelledList.unprocessed, LabelledList.payment_complete]) - self.assertEqual(LabelledList.unprocessed, 1) - self.assertEqual(LabelledList(1), LabelledList.unprocessed) - - -class TestUnique(unittest.TestCase): - - def test_unique_clean(self): - @unique - class Clean(Enum): - one = 1 - two = 'dos' - tres = 4.0 - @unique - class Cleaner(IntEnum): - single = 1 - double = 2 - triple = 3 - - def test_unique_dirty(self): - with self.assertRaisesRegex(ValueError, 'tres.*one'): - @unique - class Dirty(Enum): - one = 1 - two = 'dos' - tres = 1 - with self.assertRaisesRegex( - ValueError, - 'double.*single.*turkey.*triple', - ): - @unique - class Dirtier(IntEnum): - single = 1 - double = 1 - triple = 3 - turkey = 3 - - -if __name__ == '__main__': - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_epoll.py --- a/Lib/test/test_epoll.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_epoll.py Fri Feb 01 23:12:09 2013 +0100 @@ -80,7 +80,7 @@ self.assertRaises(OSError, select.epoll, flags=12356) def test_badcreate(self): - self.assertRaises(TypeError, select.epoll, 1, 2, 3) + self.assertRaises(TypeError, select.epoll, 1, 2, 3, 4) self.assertRaises(TypeError, select.epoll, 'foo') self.assertRaises(TypeError, select.epoll, None) self.assertRaises(TypeError, select.epoll, ()) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_exceptions.py Fri Feb 01 23:12:09 2013 +0100 @@ -953,5 +953,8 @@ self.assertEqual(str(arg), str(exc)) +def test_main(): + run_unittest(ExceptionTests, ImportErrorTests) + if __name__ == '__main__': unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_faulthandler.py Fri Feb 01 23:12:09 2013 +0100 @@ -101,14 +101,11 @@ header=re.escape(header)) if other_regex: regex += '|' + other_regex - with support.suppress_crash_popup(): - output, exitcode = self.get_output(code, filename) + output, exitcode = self.get_output(code, filename) output = '\n'.join(output) self.assertRegex(output, regex) self.assertNotEqual(exitcode, 0) - @unittest.skipIf(sys.platform.startswith('aix'), - "the first page of memory is a mapped read-only on AIX") def test_read_null(self): self.check_fatal_error(""" import faulthandler @@ -208,20 +205,20 @@ import faulthandler output = open({filename}, 'wb') faulthandler.enable(output) -faulthandler._sigsegv() +faulthandler._read_null() """.strip().format(filename=repr(filename)), 4, - 'Segmentation fault', + '(?:Segmentation fault|Bus error|Illegal instruction)', filename=filename) def test_enable_single_thread(self): self.check_fatal_error(""" import faulthandler faulthandler.enable(all_threads=False) -faulthandler._sigsegv() +faulthandler._read_null() """.strip(), 3, - 'Segmentation fault', + '(?:Segmentation fault|Bus error|Illegal instruction)', all_threads=False) def test_disable(self): @@ -229,11 +226,10 @@ import faulthandler faulthandler.enable() faulthandler.disable() -faulthandler._sigsegv() +faulthandler._read_null() """.strip() not_expected = 'Fatal Python error' - with support.suppress_crash_popup(): - stderr, exitcode = self.get_output(code) + stderr, exitcode = self.get_output(code) stder = '\n'.join(stderr) self.assertTrue(not_expected not in stderr, "%r is present in %r" % (not_expected, stderr)) @@ -264,11 +260,9 @@ def test_disabled_by_default(self): # By default, the module should be disabled code = "import faulthandler; print(faulthandler.is_enabled())" - args = (sys.executable, '-E', '-c', code) - # use subprocess module directly because test.script_helper adds - # "-X faulthandler" to the command line - stdout = subprocess.check_output(args) - self.assertEqual(stdout.rstrip(), b"False") + rc, stdout, stderr = assert_python_ok("-c", code) + stdout = (stdout + stderr).strip() + self.assertEqual(stdout, b"False") def test_sys_xoptions(self): # Test python -X faulthandler @@ -592,5 +586,8 @@ self.check_register(chain=True) +def test_main(): + support.run_unittest(FaultHandlerTests) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_fcntl.py --- a/Lib/test/test_fcntl.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_fcntl.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,5 @@ """Test program for the fcntl C module. """ -import platform import os import struct import sys @@ -91,9 +90,6 @@ self.assertRaises(OverflowError, fcntl.fcntl, F(_testcapi.INT_MIN - 1), fcntl.F_SETFL, os.O_NONBLOCK) - @unittest.skipIf( - platform.machine().startswith('arm') and platform.system() == 'Linux', - "ARM Linux returns EINVAL for F_NOTIFY DN_MULTISHOT") def test_fcntl_64_bit(self): # Issue #1309352: fcntl shouldn't fail when the third arg fits in a # C 'long' but not in a C 'int'. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_file.py --- a/Lib/test/test_file.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_file.py Fri Feb 01 23:12:09 2013 +0100 @@ -10,7 +10,7 @@ from test.support import TESTFN, run_unittest from collections import UserList -class AutoFileTests: +class AutoFileTests(unittest.TestCase): # file tests for which a test file is automatically set up def setUp(self): @@ -128,14 +128,14 @@ def testReadWhenWriting(self): self.assertRaises(OSError, self.f.read) -class CAutoFileTests(AutoFileTests, unittest.TestCase): +class CAutoFileTests(AutoFileTests): open = io.open -class PyAutoFileTests(AutoFileTests, unittest.TestCase): +class PyAutoFileTests(AutoFileTests): open = staticmethod(pyio.open) -class OtherFileTests: +class OtherFileTests(unittest.TestCase): def testModeStrings(self): # check invalid mode strings @@ -148,6 +148,16 @@ f.close() self.fail('%r is an invalid file mode' % mode) + def testStdin(self): + # This causes the interpreter to exit on OSF1 v5.1. + if sys.platform != 'osf1V5': + self.assertRaises((OSError, ValueError), sys.stdin.seek, -1) + else: + print(( + ' Skipping sys.stdin.seek(-1), it may crash the interpreter.' + ' Test manually.'), file=sys.__stdout__) + self.assertRaises((OSError, ValueError), sys.stdin.truncate) + def testBadModeArgument(self): # verify that we get a sensible error message for bad mode argument bad_mode = "qwerty" @@ -312,18 +322,22 @@ finally: os.unlink(TESTFN) -class COtherFileTests(OtherFileTests, unittest.TestCase): +class COtherFileTests(OtherFileTests): open = io.open -class PyOtherFileTests(OtherFileTests, unittest.TestCase): +class PyOtherFileTests(OtherFileTests): open = staticmethod(pyio.open) -def tearDownModule(): +def test_main(): # Historically, these tests have been sloppy about removing TESTFN. # So get rid of it no matter what. - if os.path.exists(TESTFN): - os.unlink(TESTFN) + try: + run_unittest(CAutoFileTests, PyAutoFileTests, + COtherFileTests, PyOtherFileTests) + finally: + if os.path.exists(TESTFN): + os.unlink(TESTFN) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_filecmp.py --- a/Lib/test/test_filecmp.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_filecmp.py Fri Feb 01 23:12:09 2013 +0100 @@ -39,13 +39,6 @@ self.assertFalse(filecmp.cmp(self.name, self.dir), "File and directory compare as equal") - def test_cache_clear(self): - first_compare = filecmp.cmp(self.name, self.name_same, shallow=False) - second_compare = filecmp.cmp(self.name, self.name_diff, shallow=False) - filecmp.clear_cache() - self.assertTrue(len(filecmp._cache) == 0, - "Cache not cleared after calling clear_cache") - class DirCompareTestCase(unittest.TestCase): def setUp(self): tmpdir = tempfile.gettempdir() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_fileinput.py --- a/Lib/test/test_fileinput.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_fileinput.py Fri Feb 01 23:12:09 2013 +0100 @@ -835,6 +835,22 @@ self.assertIs(kwargs.pop('encoding'), encoding) self.assertFalse(kwargs) +def test_main(): + run_unittest( + BufferSizesTests, + FileInputTests, + Test_fileinput_input, + Test_fileinput_close, + Test_fileinput_nextfile, + Test_fileinput_filename, + Test_fileinput_lineno, + Test_fileinput_filelineno, + Test_fileinput_fileno, + Test_fileinput_isfirstline, + Test_fileinput_isstdin, + Test_hook_compressed, + Test_hook_encoded, + ) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_fork1.py --- a/Lib/test/test_fork1.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_fork1.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ """This test checks for correct fork() behavior. """ -import _imp as imp +import imp import os import signal import sys diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_format.py --- a/Lib/test/test_format.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_format.py Fri Feb 01 23:12:09 2013 +0100 @@ -14,10 +14,10 @@ def testformat(formatstr, args, output=None, limit=None, overflowok=False): if verbose: if output: - print("{!a} % {!a} =? {!a} ...".format(formatstr, args, output), - end=' ') + print("%r %% %r =? %r ..." %\ + (formatstr, args, output), end=' ') else: - print("{!a} % {!a} works? ...".format(formatstr, args), end=' ') + print("%r %% %r works? ..." % (formatstr, args), end=' ') try: result = formatstr % args except OverflowError: @@ -324,30 +324,10 @@ self.assertIs("{0:1s}".format(text), text) self.assertIs("{0:5s}".format(text), text) - self.assertIs(text % (), text) - self.assertIs(text.format(), text) - def test_main(): support.run_unittest(FormatTest) - def test_precision(self): - INT_MAX = 2147483647 - - f = 1.2 - self.assertEqual(format(f, ".0f"), "1") - self.assertEqual(format(f, ".3f"), "1.200") - with self.assertRaises(ValueError) as cm: - format(f, ".%sf" % (INT_MAX + 1)) - self.assertEqual(str(cm.exception), "precision too big") - - c = complex(f) - self.assertEqual(format(f, ".0f"), "1") - self.assertEqual(format(f, ".3f"), "1.200") - with self.assertRaises(ValueError) as cm: - format(f, ".%sf" % (INT_MAX + 1)) - self.assertEqual(str(cm.exception), "precision too big") - if __name__ == "__main__": unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_frozen.py --- a/Lib/test/test_frozen.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_frozen.py Fri Feb 01 23:12:09 2013 +0100 @@ -36,7 +36,7 @@ else: expect.add('spam') self.assertEqual(set(dir(__phello__)), expect) - self.assertEqual(__phello__.__path__, []) + self.assertEqual(__phello__.__path__, [__phello__.__name__]) self.assertEqual(stdout.getvalue(), 'Hello world!\n') with captured_stdout() as stdout: @@ -72,6 +72,8 @@ del sys.modules['__phello__'] del sys.modules['__phello__.spam'] +def test_main(): + run_unittest(FrozenTests) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ftplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -21,7 +21,6 @@ from test.support import HOST threading = support.import_module('threading') -TIMEOUT = 3 # the dummy data returned by server over the data channel when # RETR, LIST, NLST, MLSD commands are issued RETR_DATA = 'abcde12345\r\n' * 1000 @@ -126,7 +125,7 @@ addr = list(map(int, arg.split(','))) ip = '%d.%d.%d.%d' %tuple(addr[:4]) port = (addr[4] * 256) + addr[5] - s = socket.create_connection((ip, port), timeout=TIMEOUT) + s = socket.create_connection((ip, port), timeout=2) self.dtp = self.dtp_handler(s, baseclass=self) self.push('200 active data connection established') @@ -134,7 +133,7 @@ with socket.socket() as sock: sock.bind((self.socket.getsockname()[0], 0)) sock.listen(5) - sock.settimeout(TIMEOUT) + sock.settimeout(10) ip, port = sock.getsockname()[:2] ip = ip.replace('.', ','); p1 = port / 256; p2 = port % 256 self.push('227 entering passive mode (%s,%d,%d)' %(ip, p1, p2)) @@ -144,7 +143,7 @@ def cmd_eprt(self, arg): af, ip, port = arg.split(arg[0])[1:-1] port = int(port) - s = socket.create_connection((ip, port), timeout=TIMEOUT) + s = socket.create_connection((ip, port), timeout=2) self.dtp = self.dtp_handler(s, baseclass=self) self.push('200 active data connection established') @@ -152,7 +151,7 @@ with socket.socket(socket.AF_INET6) as sock: sock.bind((self.socket.getsockname()[0], 0)) sock.listen(5) - sock.settimeout(TIMEOUT) + sock.settimeout(10) port = sock.getsockname()[1] self.push('229 entering extended passive mode (|||%d|)' %port) conn, addr = sock.accept() @@ -455,7 +454,7 @@ def setUp(self): self.server = DummyFTPServer((HOST, 0)) self.server.start() - self.client = ftplib.FTP(timeout=TIMEOUT) + self.client = ftplib.FTP(timeout=2) self.client.connect(self.server.host, self.server.port) def tearDown(self): @@ -589,11 +588,6 @@ self.client.storlines('stor foo', f, callback=lambda x: flag.append(None)) self.assertTrue(flag) - f = io.StringIO(RETR_DATA.replace('\r\n', '\n')) - # storlines() expects a binary file, not a text file - with support.check_warnings(('', BytesWarning), quiet=True): - self.assertRaises(TypeError, self.client.storlines, 'stor foo', f) - def test_nlst(self): self.client.nlst() self.assertEqual(self.client.nlst(), NLST_DATA.split('\r\n')[:-1]) @@ -669,7 +663,7 @@ def test_makepasv(self): host, port = self.client.makepasv() - conn = socket.create_connection((host, port), timeout=TIMEOUT) + conn = socket.create_connection((host, port), 10) conn.close() # IPv4 is in use, just make sure send_epsv has not been used self.assertEqual(self.server.handler_instance.last_received_cmd, 'pasv') @@ -687,7 +681,7 @@ return True # base test - with ftplib.FTP(timeout=TIMEOUT) as self.client: + with ftplib.FTP(timeout=2) as self.client: self.client.connect(self.server.host, self.server.port) self.client.sendcmd('noop') self.assertTrue(is_client_connected()) @@ -695,7 +689,7 @@ self.assertFalse(is_client_connected()) # QUIT sent inside the with block - with ftplib.FTP(timeout=TIMEOUT) as self.client: + with ftplib.FTP(timeout=2) as self.client: self.client.connect(self.server.host, self.server.port) self.client.sendcmd('noop') self.client.quit() @@ -705,7 +699,7 @@ # force a wrong response code to be sent on QUIT: error_perm # is expected and the connection is supposed to be closed try: - with ftplib.FTP(timeout=TIMEOUT) as self.client: + with ftplib.FTP(timeout=2) as self.client: self.client.connect(self.server.host, self.server.port) self.client.sendcmd('noop') self.server.handler_instance.next_response = '550 error on quit' @@ -761,7 +755,7 @@ def setUp(self): self.server = DummyFTPServer(('::1', 0), af=socket.AF_INET6) self.server.start() - self.client = ftplib.FTP(timeout=TIMEOUT) + self.client = ftplib.FTP() self.client.connect(self.server.host, self.server.port) def tearDown(self): @@ -778,7 +772,7 @@ def test_makepasv(self): host, port = self.client.makepasv() - conn = socket.create_connection((host, port), timeout=TIMEOUT) + conn = socket.create_connection((host, port), 10) conn.close() self.assertEqual(self.server.handler_instance.last_received_cmd, 'epsv') @@ -804,7 +798,7 @@ def setUp(self): self.server = DummyTLS_FTPServer((HOST, 0)) self.server.start() - self.client = ftplib.FTP_TLS(timeout=TIMEOUT) + self.client = ftplib.FTP_TLS(timeout=2) self.client.connect(self.server.host, self.server.port) # enable TLS self.client.auth() @@ -817,7 +811,7 @@ def setUp(self): self.server = DummyTLS_FTPServer((HOST, 0)) self.server.start() - self.client = ftplib.FTP_TLS(timeout=TIMEOUT) + self.client = ftplib.FTP_TLS(timeout=2) self.client.connect(self.server.host, self.server.port) def tearDown(self): @@ -877,7 +871,7 @@ self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE, keyfile=CERTFILE, context=ctx) - self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT) + self.client = ftplib.FTP_TLS(context=ctx, timeout=2) self.client.connect(self.server.host, self.server.port) self.assertNotIsInstance(self.client.sock, ssl.SSLSocket) self.client.auth() @@ -991,19 +985,8 @@ ftp.close() -class TestNetrcDeprecation(TestCase): - - def test_deprecation(self): - with support.temp_cwd(), support.EnvironmentVarGuard() as env: - env['HOME'] = os.getcwd() - open('.netrc', 'w').close() - with self.assertWarns(DeprecationWarning): - ftplib.Netrc() - - - def test_main(): - tests = [TestFTPClass, TestTimeouts, TestNetrcDeprecation] + tests = [TestFTPClass, TestTimeouts] if support.IPV6_ENABLED: tests.append(TestIPv6Environment) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_functools.py --- a/Lib/test/test_functools.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_functools.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,31 +1,48 @@ import collections -from itertools import permutations +import sys +import unittest +from test import support +from weakref import proxy import pickle from random import choice -import sys -from test import support -import unittest -from weakref import proxy import functools +original_functools = functools py_functools = support.import_fresh_module('functools', blocked=['_functools']) c_functools = support.import_fresh_module('functools', fresh=['_functools']) -decimal = support.import_fresh_module('decimal', fresh=['_decimal']) +class BaseTest(unittest.TestCase): + """Base class required for testing C and Py implementations.""" + + def setUp(self): + + # The module must be explicitly set so that the proper + # interaction between the c module and the python module + # can be controlled. + self.partial = self.module.partial + super(BaseTest, self).setUp() + +class BaseTestC(BaseTest): + module = c_functools + +class BaseTestPy(BaseTest): + module = py_functools + +PythonPartial = py_functools.partial def capture(*args, **kw): """capture all positional and keyword arguments""" return args, kw - def signature(part): """ return the signature of a partial object """ return (part.func, part.args, part.keywords, part.__dict__) +class TestPartial(object): -class TestPartial: + partial = functools.partial def test_basic_examples(self): p = self.partial(capture, 1, 2, a=10, b=20) @@ -144,18 +161,12 @@ join = self.partial(''.join) self.assertEqual(join(data), '0123456789') - -@unittest.skipUnless(c_functools, 'requires the C _functools module') -class TestPartialC(TestPartial, unittest.TestCase): - if c_functools: - partial = c_functools.partial - def test_repr(self): args = (object(), object()) args_repr = ', '.join(repr(a) for a in args) kwargs = {'a': object(), 'b': object()} kwargs_repr = ', '.join("%s=%r" % (k, v) for k, v in kwargs.items()) - if self.partial is c_functools.partial: + if self.partial is functools.partial: name = 'functools.partial' else: name = self.partial.__name__ @@ -182,40 +193,30 @@ f_copy = pickle.loads(pickle.dumps(f)) self.assertEqual(signature(f), signature(f_copy)) - # Issue 6083: Reference counting bug - def test_setstate_refcount(self): - class BadSequence: - def __len__(self): - return 4 - def __getitem__(self, key): - if key == 0: - return max - elif key == 1: - return tuple(range(1000000)) - elif key in (2, 3): - return {} - raise IndexError +class TestPartialC(BaseTestC, TestPartial): + pass - f = self.partial(object) - self.assertRaisesRegex(SystemError, - "new style getargs format but argument is not a tuple", - f.__setstate__, BadSequence()) +class TestPartialPy(BaseTestPy, TestPartial): + def test_pickle(self): + raise unittest.SkipTest("Python implementation of partial isn't picklable") -class TestPartialPy(TestPartial, unittest.TestCase): - partial = staticmethod(py_functools.partial) + def test_repr(self): + raise unittest.SkipTest("Python implementation of partial uses own repr") +class TestPartialCSubclass(BaseTestC, TestPartial): -if c_functools: class PartialSubclass(c_functools.partial): pass + partial = staticmethod(PartialSubclass) -@unittest.skipUnless(c_functools, 'requires the C _functools module') -class TestPartialCSubclass(TestPartialC): - if c_functools: - partial = PartialSubclass +class TestPartialPySubclass(TestPartialPy): + class PartialSubclass(c_functools.partial): + pass + + partial = staticmethod(PartialSubclass) class TestUpdateWrapper(unittest.TestCase): @@ -224,26 +225,19 @@ updated=functools.WRAPPER_UPDATES): # Check attributes were assigned for name in assigned: - self.assertIs(getattr(wrapper, name), getattr(wrapped, name)) + self.assertTrue(getattr(wrapper, name) is getattr(wrapped, name)) # Check attributes were updated for name in updated: wrapper_attr = getattr(wrapper, name) wrapped_attr = getattr(wrapped, name) for key in wrapped_attr: - if name == "__dict__" and key == "__wrapped__": - # __wrapped__ is overwritten by the update code - continue - self.assertIs(wrapped_attr[key], wrapper_attr[key]) - # Check __wrapped__ - self.assertIs(wrapper.__wrapped__, wrapped) - + self.assertTrue(wrapped_attr[key] is wrapper_attr[key]) def _default_update(self): def f(a:'This is a new annotation'): """This is a test""" pass f.attr = 'This is also a test' - f.__wrapped__ = "This is a bald faced lie" def wrapper(b:'This is the prior annotation'): pass functools.update_wrapper(wrapper, f) @@ -318,7 +312,6 @@ with self.assertRaises(AttributeError): functools.update_wrapper(wrapper, f, assign, update) - @support.requires_docstrings @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -O2 and above") def test_builtin_update(self): @@ -330,7 +323,6 @@ self.assertTrue(wrapper.__doc__.startswith('max(')) self.assertEqual(wrapper.__annotations__, {}) - class TestWraps(TestUpdateWrapper): def _default_update(self): @@ -338,15 +330,14 @@ """This is a test""" pass f.attr = 'This is also a test' - f.__wrapped__ = "This is still a bald faced lie" @functools.wraps(f) def wrapper(): pass + self.check_wrapper(wrapper, f) return wrapper, f def test_default_update(self): wrapper, f = self._default_update() - self.check_wrapper(wrapper, f) self.assertEqual(wrapper.__name__, 'f') self.assertEqual(wrapper.__qualname__, f.__qualname__) self.assertEqual(wrapper.attr, 'This is also a test') @@ -392,7 +383,6 @@ self.assertEqual(wrapper.attr, 'This is a different test') self.assertEqual(wrapper.dict_attr, f.dict_attr) - class TestReduce(unittest.TestCase): func = functools.reduce @@ -473,8 +463,7 @@ d = {"one": 1, "two": 2, "three": 3} self.assertEqual(self.func(add, d), "".join(d.keys())) - -class TestCmpToKey: +class TestCmpToKey(object): def test_cmp_to_key(self): def cmp1(x, y): @@ -505,7 +494,7 @@ with self.assertRaises(TypeError): key = self.cmp_to_key() # too few args with self.assertRaises(TypeError): - key = self.cmp_to_key(cmp1, None) # too many args + key = self.module.cmp_to_key(cmp1, None) # too many args key = self.cmp_to_key(cmp1) with self.assertRaises(TypeError): key() # too few args @@ -556,17 +545,12 @@ self.assertRaises(TypeError, hash, k) self.assertNotIsInstance(k, collections.Hashable) +class TestCmpToKeyC(BaseTestC, TestCmpToKey): + cmp_to_key = c_functools.cmp_to_key -@unittest.skipUnless(c_functools, 'requires the C _functools module') -class TestCmpToKeyC(TestCmpToKey, unittest.TestCase): - if c_functools: - cmp_to_key = c_functools.cmp_to_key - - -class TestCmpToKeyPy(TestCmpToKey, unittest.TestCase): +class TestCmpToKeyPy(BaseTestPy, TestCmpToKey): cmp_to_key = staticmethod(py_functools.cmp_to_key) - class TestTotalOrdering(unittest.TestCase): def test_total_ordering_lt(self): @@ -667,7 +651,6 @@ with self.assertRaises(TypeError): TestTO(8) <= () - class TestLRU(unittest.TestCase): def test_lru(self): @@ -835,510 +818,12 @@ self.assertEqual(fib.cache_info(), functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)) - def test_need_for_rlock(self): - # This will deadlock on an LRU cache that uses a regular lock - - @functools.lru_cache(maxsize=10) - def test_func(x): - 'Used to demonstrate a reentrant lru_cache call within a single thread' - return x - - class DoubleEq: - 'Demonstrate a reentrant lru_cache call within a single thread' - def __init__(self, x): - self.x = x - def __hash__(self): - return self.x - def __eq__(self, other): - if self.x == 2: - test_func(DoubleEq(1)) - return self.x == other.x - - test_func(DoubleEq(1)) # Load the cache - test_func(DoubleEq(2)) # Load the cache - self.assertEqual(test_func(DoubleEq(2)), # Trigger a re-entrant __eq__ call - DoubleEq(2)) # Verify the correct return value - - -class TestSingleDispatch(unittest.TestCase): - def test_simple_overloads(self): - @functools.singledispatch - def g(obj): - return "base" - def g_int(i): - return "integer" - g.register(int, g_int) - self.assertEqual(g("str"), "base") - self.assertEqual(g(1), "integer") - self.assertEqual(g([1,2,3]), "base") - - def test_mro(self): - @functools.singledispatch - def g(obj): - return "base" - class A: - pass - class C(A): - pass - class B(A): - pass - class D(C, B): - pass - def g_A(a): - return "A" - def g_B(b): - return "B" - g.register(A, g_A) - g.register(B, g_B) - self.assertEqual(g(A()), "A") - self.assertEqual(g(B()), "B") - self.assertEqual(g(C()), "A") - self.assertEqual(g(D()), "B") - - def test_register_decorator(self): - @functools.singledispatch - def g(obj): - return "base" - @g.register(int) - def g_int(i): - return "int %s" % (i,) - self.assertEqual(g(""), "base") - self.assertEqual(g(12), "int 12") - self.assertIs(g.dispatch(int), g_int) - self.assertIs(g.dispatch(object), g.dispatch(str)) - # Note: in the assert above this is not g. - # @singledispatch returns the wrapper. - - def test_wrapping_attributes(self): - @functools.singledispatch - def g(obj): - "Simple test" - return "Test" - self.assertEqual(g.__name__, "g") - self.assertEqual(g.__doc__, "Simple test") - - @unittest.skipUnless(decimal, 'requires _decimal') - @support.cpython_only - def test_c_classes(self): - @functools.singledispatch - def g(obj): - return "base" - @g.register(decimal.DecimalException) - def _(obj): - return obj.args - subn = decimal.Subnormal("Exponent < Emin") - rnd = decimal.Rounded("Number got rounded") - self.assertEqual(g(subn), ("Exponent < Emin",)) - self.assertEqual(g(rnd), ("Number got rounded",)) - @g.register(decimal.Subnormal) - def _(obj): - return "Too small to care." - self.assertEqual(g(subn), "Too small to care.") - self.assertEqual(g(rnd), ("Number got rounded",)) - - def test_compose_mro(self): - # None of the examples in this test depend on haystack ordering. - c = collections - mro = functools._compose_mro - bases = [c.Sequence, c.MutableMapping, c.Mapping, c.Set] - for haystack in permutations(bases): - m = mro(dict, haystack) - self.assertEqual(m, [dict, c.MutableMapping, c.Mapping, c.Sized, - c.Iterable, c.Container, object]) - bases = [c.Container, c.Mapping, c.MutableMapping, c.OrderedDict] - for haystack in permutations(bases): - m = mro(c.ChainMap, haystack) - self.assertEqual(m, [c.ChainMap, c.MutableMapping, c.Mapping, - c.Sized, c.Iterable, c.Container, object]) - - # If there's a generic function with implementations registered for - # both Sized and Container, passing a defaultdict to it results in an - # ambiguous dispatch which will cause a RuntimeError (see - # test_mro_conflicts). - bases = [c.Container, c.Sized, str] - for haystack in permutations(bases): - m = mro(c.defaultdict, [c.Sized, c.Container, str]) - self.assertEqual(m, [c.defaultdict, dict, c.Sized, c.Container, - object]) - - # MutableSequence below is registered directly on D. In other words, it - # preceeds MutableMapping which means single dispatch will always - # choose MutableSequence here. - class D(c.defaultdict): - pass - c.MutableSequence.register(D) - bases = [c.MutableSequence, c.MutableMapping] - for haystack in permutations(bases): - m = mro(D, bases) - self.assertEqual(m, [D, c.MutableSequence, c.Sequence, - c.defaultdict, dict, c.MutableMapping, - c.Mapping, c.Sized, c.Iterable, c.Container, - object]) - - # Container and Callable are registered on different base classes and - # a generic function supporting both should always pick the Callable - # implementation if a C instance is passed. - class C(c.defaultdict): - def __call__(self): - pass - bases = [c.Sized, c.Callable, c.Container, c.Mapping] - for haystack in permutations(bases): - m = mro(C, haystack) - self.assertEqual(m, [C, c.Callable, c.defaultdict, dict, c.Mapping, - c.Sized, c.Iterable, c.Container, object]) - - def test_register_abc(self): - c = collections - d = {"a": "b"} - l = [1, 2, 3] - s = {object(), None} - f = frozenset(s) - t = (1, 2, 3) - @functools.singledispatch - def g(obj): - return "base" - self.assertEqual(g(d), "base") - self.assertEqual(g(l), "base") - self.assertEqual(g(s), "base") - self.assertEqual(g(f), "base") - self.assertEqual(g(t), "base") - g.register(c.Sized, lambda obj: "sized") - self.assertEqual(g(d), "sized") - self.assertEqual(g(l), "sized") - self.assertEqual(g(s), "sized") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sized") - g.register(c.MutableMapping, lambda obj: "mutablemapping") - self.assertEqual(g(d), "mutablemapping") - self.assertEqual(g(l), "sized") - self.assertEqual(g(s), "sized") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sized") - g.register(c.ChainMap, lambda obj: "chainmap") - self.assertEqual(g(d), "mutablemapping") # irrelevant ABCs registered - self.assertEqual(g(l), "sized") - self.assertEqual(g(s), "sized") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sized") - g.register(c.MutableSequence, lambda obj: "mutablesequence") - self.assertEqual(g(d), "mutablemapping") - self.assertEqual(g(l), "mutablesequence") - self.assertEqual(g(s), "sized") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sized") - g.register(c.MutableSet, lambda obj: "mutableset") - self.assertEqual(g(d), "mutablemapping") - self.assertEqual(g(l), "mutablesequence") - self.assertEqual(g(s), "mutableset") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sized") - g.register(c.Mapping, lambda obj: "mapping") - self.assertEqual(g(d), "mutablemapping") # not specific enough - self.assertEqual(g(l), "mutablesequence") - self.assertEqual(g(s), "mutableset") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sized") - g.register(c.Sequence, lambda obj: "sequence") - self.assertEqual(g(d), "mutablemapping") - self.assertEqual(g(l), "mutablesequence") - self.assertEqual(g(s), "mutableset") - self.assertEqual(g(f), "sized") - self.assertEqual(g(t), "sequence") - g.register(c.Set, lambda obj: "set") - self.assertEqual(g(d), "mutablemapping") - self.assertEqual(g(l), "mutablesequence") - self.assertEqual(g(s), "mutableset") - self.assertEqual(g(f), "set") - self.assertEqual(g(t), "sequence") - g.register(dict, lambda obj: "dict") - self.assertEqual(g(d), "dict") - self.assertEqual(g(l), "mutablesequence") - self.assertEqual(g(s), "mutableset") - self.assertEqual(g(f), "set") - self.assertEqual(g(t), "sequence") - g.register(list, lambda obj: "list") - self.assertEqual(g(d), "dict") - self.assertEqual(g(l), "list") - self.assertEqual(g(s), "mutableset") - self.assertEqual(g(f), "set") - self.assertEqual(g(t), "sequence") - g.register(set, lambda obj: "concrete-set") - self.assertEqual(g(d), "dict") - self.assertEqual(g(l), "list") - self.assertEqual(g(s), "concrete-set") - self.assertEqual(g(f), "set") - self.assertEqual(g(t), "sequence") - g.register(frozenset, lambda obj: "frozen-set") - self.assertEqual(g(d), "dict") - self.assertEqual(g(l), "list") - self.assertEqual(g(s), "concrete-set") - self.assertEqual(g(f), "frozen-set") - self.assertEqual(g(t), "sequence") - g.register(tuple, lambda obj: "tuple") - self.assertEqual(g(d), "dict") - self.assertEqual(g(l), "list") - self.assertEqual(g(s), "concrete-set") - self.assertEqual(g(f), "frozen-set") - self.assertEqual(g(t), "tuple") - - def test_c3_abc(self): - c = collections - mro = functools._c3_mro - class A(object): - pass - class B(A): - def __len__(self): - return 0 # implies Sized - @c.Container.register - class C(object): - pass - class D(object): - pass # unrelated - class X(D, C, B): - def __call__(self): - pass # implies Callable - expected = [X, c.Callable, D, C, c.Container, B, c.Sized, A, object] - for abcs in permutations([c.Sized, c.Callable, c.Container]): - self.assertEqual(mro(X, abcs=abcs), expected) - # unrelated ABCs don't appear in the resulting MRO - many_abcs = [c.Mapping, c.Sized, c.Callable, c.Container, c.Iterable] - self.assertEqual(mro(X, abcs=many_abcs), expected) - - def test_mro_conflicts(self): - c = collections - @functools.singledispatch - def g(arg): - return "base" - class O(c.Sized): - def __len__(self): - return 0 - o = O() - self.assertEqual(g(o), "base") - g.register(c.Iterable, lambda arg: "iterable") - g.register(c.Container, lambda arg: "container") - g.register(c.Sized, lambda arg: "sized") - g.register(c.Set, lambda arg: "set") - self.assertEqual(g(o), "sized") - c.Iterable.register(O) - self.assertEqual(g(o), "sized") # because it's explicitly in __mro__ - c.Container.register(O) - self.assertEqual(g(o), "sized") # see above: Sized is in __mro__ - c.Set.register(O) - self.assertEqual(g(o), "set") # because c.Set is a subclass of - # c.Sized and c.Container - class P: - pass - p = P() - self.assertEqual(g(p), "base") - c.Iterable.register(P) - self.assertEqual(g(p), "iterable") - c.Container.register(P) - with self.assertRaises(RuntimeError) as re_one: - g(p) - self.assertIn( - str(re_one.exception), - (("Ambiguous dispatch: " - "or "), - ("Ambiguous dispatch: " - "or ")), - ) - class Q(c.Sized): - def __len__(self): - return 0 - q = Q() - self.assertEqual(g(q), "sized") - c.Iterable.register(Q) - self.assertEqual(g(q), "sized") # because it's explicitly in __mro__ - c.Set.register(Q) - self.assertEqual(g(q), "set") # because c.Set is a subclass of - # c.Sized and c.Iterable - @functools.singledispatch - def h(arg): - return "base" - @h.register(c.Sized) - def _(arg): - return "sized" - @h.register(c.Container) - def _(arg): - return "container" - # Even though Sized and Container are explicit bases of MutableMapping, - # this ABC is implicitly registered on defaultdict which makes all of - # MutableMapping's bases implicit as well from defaultdict's - # perspective. - with self.assertRaises(RuntimeError) as re_two: - h(c.defaultdict(lambda: 0)) - self.assertIn( - str(re_two.exception), - (("Ambiguous dispatch: " - "or "), - ("Ambiguous dispatch: " - "or ")), - ) - class R(c.defaultdict): - pass - c.MutableSequence.register(R) - @functools.singledispatch - def i(arg): - return "base" - @i.register(c.MutableMapping) - def _(arg): - return "mapping" - @i.register(c.MutableSequence) - def _(arg): - return "sequence" - r = R() - self.assertEqual(i(r), "sequence") - class S: - pass - class T(S, c.Sized): - def __len__(self): - return 0 - t = T() - self.assertEqual(h(t), "sized") - c.Container.register(T) - self.assertEqual(h(t), "sized") # because it's explicitly in the MRO - class U: - def __len__(self): - return 0 - u = U() - self.assertEqual(h(u), "sized") # implicit Sized subclass inferred - # from the existence of __len__() - c.Container.register(U) - # There is no preference for registered versus inferred ABCs. - with self.assertRaises(RuntimeError) as re_three: - h(u) - self.assertIn( - str(re_three.exception), - (("Ambiguous dispatch: " - "or "), - ("Ambiguous dispatch: " - "or ")), - ) - class V(c.Sized, S): - def __len__(self): - return 0 - @functools.singledispatch - def j(arg): - return "base" - @j.register(S) - def _(arg): - return "s" - @j.register(c.Container) - def _(arg): - return "container" - v = V() - self.assertEqual(j(v), "s") - c.Container.register(V) - self.assertEqual(j(v), "container") # because it ends up right after - # Sized in the MRO - - def test_cache_invalidation(self): - from collections import UserDict - class TracingDict(UserDict): - def __init__(self, *args, **kwargs): - super(TracingDict, self).__init__(*args, **kwargs) - self.set_ops = [] - self.get_ops = [] - def __getitem__(self, key): - result = self.data[key] - self.get_ops.append(key) - return result - def __setitem__(self, key, value): - self.set_ops.append(key) - self.data[key] = value - def clear(self): - self.data.clear() - _orig_wkd = functools.WeakKeyDictionary - td = TracingDict() - functools.WeakKeyDictionary = lambda: td - c = collections - @functools.singledispatch - def g(arg): - return "base" - d = {} - l = [] - self.assertEqual(len(td), 0) - self.assertEqual(g(d), "base") - self.assertEqual(len(td), 1) - self.assertEqual(td.get_ops, []) - self.assertEqual(td.set_ops, [dict]) - self.assertEqual(td.data[dict], g.registry[object]) - self.assertEqual(g(l), "base") - self.assertEqual(len(td), 2) - self.assertEqual(td.get_ops, []) - self.assertEqual(td.set_ops, [dict, list]) - self.assertEqual(td.data[dict], g.registry[object]) - self.assertEqual(td.data[list], g.registry[object]) - self.assertEqual(td.data[dict], td.data[list]) - self.assertEqual(g(l), "base") - self.assertEqual(g(d), "base") - self.assertEqual(td.get_ops, [list, dict]) - self.assertEqual(td.set_ops, [dict, list]) - g.register(list, lambda arg: "list") - self.assertEqual(td.get_ops, [list, dict]) - self.assertEqual(len(td), 0) - self.assertEqual(g(d), "base") - self.assertEqual(len(td), 1) - self.assertEqual(td.get_ops, [list, dict]) - self.assertEqual(td.set_ops, [dict, list, dict]) - self.assertEqual(td.data[dict], - functools._find_impl(dict, g.registry)) - self.assertEqual(g(l), "list") - self.assertEqual(len(td), 2) - self.assertEqual(td.get_ops, [list, dict]) - self.assertEqual(td.set_ops, [dict, list, dict, list]) - self.assertEqual(td.data[list], - functools._find_impl(list, g.registry)) - class X: - pass - c.MutableMapping.register(X) # Will not invalidate the cache, - # not using ABCs yet. - self.assertEqual(g(d), "base") - self.assertEqual(g(l), "list") - self.assertEqual(td.get_ops, [list, dict, dict, list]) - self.assertEqual(td.set_ops, [dict, list, dict, list]) - g.register(c.Sized, lambda arg: "sized") - self.assertEqual(len(td), 0) - self.assertEqual(g(d), "sized") - self.assertEqual(len(td), 1) - self.assertEqual(td.get_ops, [list, dict, dict, list]) - self.assertEqual(td.set_ops, [dict, list, dict, list, dict]) - self.assertEqual(g(l), "list") - self.assertEqual(len(td), 2) - self.assertEqual(td.get_ops, [list, dict, dict, list]) - self.assertEqual(td.set_ops, [dict, list, dict, list, dict, list]) - self.assertEqual(g(l), "list") - self.assertEqual(g(d), "sized") - self.assertEqual(td.get_ops, [list, dict, dict, list, list, dict]) - self.assertEqual(td.set_ops, [dict, list, dict, list, dict, list]) - g.dispatch(list) - g.dispatch(dict) - self.assertEqual(td.get_ops, [list, dict, dict, list, list, dict, - list, dict]) - self.assertEqual(td.set_ops, [dict, list, dict, list, dict, list]) - c.MutableSet.register(X) # Will invalidate the cache. - self.assertEqual(len(td), 2) # Stale cache. - self.assertEqual(g(l), "list") - self.assertEqual(len(td), 1) - g.register(c.MutableMapping, lambda arg: "mutablemapping") - self.assertEqual(len(td), 0) - self.assertEqual(g(d), "mutablemapping") - self.assertEqual(len(td), 1) - self.assertEqual(g(l), "list") - self.assertEqual(len(td), 2) - g.register(dict, lambda arg: "dict") - self.assertEqual(g(d), "dict") - self.assertEqual(g(l), "list") - g._clear_cache() - self.assertEqual(len(td), 0) - functools.WeakKeyDictionary = _orig_wkd - - def test_main(verbose=None): test_classes = ( TestPartialC, TestPartialPy, TestPartialCSubclass, + TestPartialPySubclass, TestUpdateWrapper, TestTotalOrdering, TestCmpToKeyC, @@ -1346,7 +831,6 @@ TestWraps, TestReduce, TestLRU, - TestSingleDispatch, ) support.run_unittest(*test_classes) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_future.py --- a/Lib/test/test_future.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_future.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,18 +13,18 @@ class FutureTest(unittest.TestCase): def test_future1(self): - with support.CleanImport('future_test1'): - from test import future_test1 - self.assertEqual(future_test1.result, 6) + support.unload('future_test1') + from test import future_test1 + self.assertEqual(future_test1.result, 6) def test_future2(self): - with support.CleanImport('future_test2'): - from test import future_test2 - self.assertEqual(future_test2.result, 6) + support.unload('future_test2') + from test import future_test2 + self.assertEqual(future_test2.result, 6) def test_future3(self): - with support.CleanImport('test_future3'): - from test import test_future3 + support.unload('test_future3') + from test import test_future3 def test_badfuture3(self): try: @@ -82,14 +82,6 @@ else: self.fail("expected exception didn't occur") - def test_badfuture10(self): - try: - from test import badsyntax_future10 - except SyntaxError as msg: - self.assertEqual(get_error_location(msg), ("badsyntax_future10", '3')) - else: - self.fail("expected exception didn't occur") - def test_parserhack(self): # test that the parser.c::future_hack function works as expected # Note: although this test must pass, it's not testing the original @@ -111,8 +103,8 @@ self.fail("syntax error didn't occur") def test_multiple_features(self): - with support.CleanImport("test.test_future5"): - from test import test_future5 + support.unload("test.test_future5") + from test import test_future5 def test_unicode_literals_exec(self): scope = {} @@ -120,6 +112,8 @@ self.assertIsInstance(scope["x"], str) +def test_main(): + support.run_unittest(FutureTest) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_future3.py --- a/Lib/test/test_future3.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_future3.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,7 @@ from __future__ import division import unittest +from test import support x = 2 def nester(): @@ -22,5 +23,8 @@ def test_nested_scopes(self): self.assertEqual(nester(), 3) +def test_main(): + support.run_unittest(TestFuture) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_future4.py --- a/Lib/test/test_future4.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_future4.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,10 @@ from __future__ import unicode_literals import unittest +from test import support + +def test_main(): + pass if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_future5.py --- a/Lib/test/test_future5.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_future5.py Fri Feb 01 23:12:09 2013 +0100 @@ -17,5 +17,5 @@ self.assertEqual(s.getvalue(), "foo\n") -if __name__ == '__main__': - unittest.main() +def test_main(): + support.run_unittest(TestMultipleFeatures) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_gc.py --- a/Lib/test/test_gc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_gc.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,6 @@ import unittest from test.support import (verbose, refcount_test, run_unittest, strip_python_stderr) -from test.script_helper import assert_python_ok, make_script, temp_dir - import sys import time import gc @@ -612,40 +610,6 @@ stderr = run_command(code % "gc.DEBUG_SAVEALL") self.assertNotIn(b"uncollectable objects at shutdown", stderr) - def test_gc_main_module_at_shutdown(self): - # Create a reference cycle through the __main__ module and check - # it gets collected at interpreter shutdown. - code = """if 1: - import weakref - class C: - def __del__(self): - print('__del__ called') - l = [C()] - l.append(l) - """ - rc, out, err = assert_python_ok('-c', code) - self.assertEqual(out.strip(), b'__del__ called') - - def test_gc_ordinary_module_at_shutdown(self): - # Same as above, but with a non-__main__ module. - with temp_dir() as script_dir: - module = """if 1: - import weakref - class C: - def __del__(self): - print('__del__ called') - l = [C()] - l.append(l) - """ - code = """if 1: - import sys - sys.path.insert(0, %r) - import gctest - """ % (script_dir,) - make_script(script_dir, 'gctest', module) - rc, out, err = assert_python_ok('-c', code) - self.assertEqual(out.strip(), b'__del__ called') - def test_get_stats(self): stats = gc.get_stats() self.assertEqual(len(stats), 3) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_gdb.py --- a/Lib/test/test_gdb.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_gdb.py Fri Feb 01 23:12:09 2013 +0100 @@ -145,33 +145,29 @@ # Use "args" to invoke gdb, capturing stdout, stderr: out, err = run_gdb(*args, PYTHONHASHSEED='0') - errlines = err.splitlines() - unexpected_errlines = [] - - # Ignore some benign messages on stderr. - ignore_patterns = ( - 'Function "%s" not defined.' % breakpoint, - "warning: no loadable sections found in added symbol-file" - " system-supplied DSO", - "warning: Unable to find libthread_db matching" - " inferior's thread library, thread debugging will" - " not be available.", - "warning: Cannot initialize thread debugging" - " library: Debugger service failed", - 'warning: Could not load shared library symbols for ' - 'linux-vdso.so', - 'warning: Could not load shared library symbols for ' - 'linux-gate.so', - 'Do you need "set solib-search-path" or ' - '"set sysroot"?', - 'warning: Source file is more recent than executable.', - ) - for line in errlines: - if not line.startswith(ignore_patterns): - unexpected_errlines.append(line) + # Ignore some noise on stderr due to the pending breakpoint: + err = err.replace('Function "%s" not defined.\n' % breakpoint, '') + # Ignore some other noise on stderr (http://bugs.python.org/issue8600) + err = err.replace("warning: Unable to find libthread_db matching" + " inferior's thread library, thread debugging will" + " not be available.\n", + '') + err = err.replace("warning: Cannot initialize thread debugging" + " library: Debugger service failed\n", + '') + err = err.replace('warning: Could not load shared library symbols for ' + 'linux-vdso.so.1.\n' + 'Do you need "set solib-search-path" or ' + '"set sysroot"?\n', + '') + err = err.replace('warning: Could not load shared library symbols for ' + 'linux-gate.so.1.\n' + 'Do you need "set solib-search-path" or ' + '"set sysroot"?\n', + '') # Ensure no unexpected error messages: - self.assertEqual(unexpected_errlines, []) + self.assertEqual(err, '') return out def get_gdb_repr(self, source, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_generators.py --- a/Lib/test/test_generators.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_generators.py Fri Feb 01 23:12:09 2013 +0100 @@ -383,8 +383,7 @@ >>> [s for s in dir(i) if not s.startswith('_')] ['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw'] ->>> from test.support import HAVE_DOCSTRINGS ->>> print(i.__next__.__doc__ if HAVE_DOCSTRINGS else 'x.__next__() <==> next(x)') +>>> print(i.__next__.__doc__) x.__next__() <==> next(x) >>> iter(i) is i True diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_genexps.py --- a/Lib/test/test_genexps.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_genexps.py Fri Feb 01 23:12:09 2013 +0100 @@ -221,8 +221,7 @@ >>> set(attr for attr in dir(g) if not attr.startswith('__')) >= expected True - >>> from test.support import HAVE_DOCSTRINGS - >>> print(g.__next__.__doc__ if HAVE_DOCSTRINGS else 'x.__next__() <==> next(x)') + >>> print(g.__next__.__doc__) x.__next__() <==> next(x) >>> import types >>> isinstance(g, types.GeneratorType) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_getargs2.py --- a/Lib/test/test_getargs2.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_getargs2.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,40 +1,38 @@ import unittest from test import support from _testcapi import getargs_keywords, getargs_keyword_only -try: - from _testcapi import getargs_L, getargs_K -except ImportError: - getargs_L = None # PY_LONG_LONG not available -# > How about the following counterproposal. This also changes some of -# > the other format codes to be a little more regular. -# > -# > Code C type Range check -# > -# > b unsigned char 0..UCHAR_MAX -# > h signed short SHRT_MIN..SHRT_MAX -# > B unsigned char none ** -# > H unsigned short none ** -# > k * unsigned long none -# > I * unsigned int 0..UINT_MAX -# -# -# > i int INT_MIN..INT_MAX -# > l long LONG_MIN..LONG_MAX -# -# > K * unsigned long long none -# > L long long LLONG_MIN..LLONG_MAX -# -# > Notes: -# > -# > * New format codes. -# > -# > ** Changed from previous "range-and-a-half" to "none"; the -# > range-and-a-half checking wasn't particularly useful. -# -# Plus a C API or two, e.g. PyInt_AsLongMask() -> -# unsigned long and PyInt_AsLongLongMask() -> unsigned -# long long (if that exists). +""" +> How about the following counterproposal. This also changes some of +> the other format codes to be a little more regular. +> +> Code C type Range check +> +> b unsigned char 0..UCHAR_MAX +> h signed short SHRT_MIN..SHRT_MAX +> B unsigned char none ** +> H unsigned short none ** +> k * unsigned long none +> I * unsigned int 0..UINT_MAX + + +> i int INT_MIN..INT_MAX +> l long LONG_MIN..LONG_MAX + +> K * unsigned long long none +> L long long LLONG_MIN..LLONG_MAX + +> Notes: +> +> * New format codes. +> +> ** Changed from previous "range-and-a-half" to "none"; the +> range-and-a-half checking wasn't particularly useful. + +Plus a C API or two, e.g. PyInt_AsLongMask() -> +unsigned long and PyInt_AsLongLongMask() -> unsigned +long long (if that exists). +""" LARGE = 0x7FFFFFFF VERY_LARGE = 0xFF0000121212121212121242 @@ -186,7 +184,6 @@ self.assertRaises(OverflowError, getargs_n, VERY_LARGE) -@unittest.skipIf(getargs_L is None, 'PY_LONG_LONG is not available') class LongLong_TestCase(unittest.TestCase): def test_L(self): from _testcapi import getargs_L @@ -539,5 +536,24 @@ self.assertIsNone(getargs_Z_hash(None)) +def test_main(): + tests = [ + Signed_TestCase, + Unsigned_TestCase, + Boolean_TestCase, + Tuple_TestCase, + Keywords_TestCase, + KeywordOnly_TestCase, + Bytes_TestCase, + Unicode_TestCase, + ] + try: + from _testcapi import getargs_L, getargs_K + except ImportError: + pass # PY_LONG_LONG not available + else: + tests.append(LongLong_TestCase) + support.run_unittest(*tests) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_getpass.py --- a/Lib/test/test_getpass.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -import getpass -import os -import unittest -from io import BytesIO, StringIO -from unittest import mock -from test import support - -try: - import termios -except ImportError: - termios = None -try: - import pwd -except ImportError: - pwd = None - -@mock.patch('os.environ') -class GetpassGetuserTest(unittest.TestCase): - - def test_username_takes_username_from_env(self, environ): - expected_name = 'some_name' - environ.get.return_value = expected_name - self.assertEqual(expected_name, getpass.getuser()) - - def test_username_priorities_of_env_values(self, environ): - environ.get.return_value = None - try: - getpass.getuser() - except ImportError: # in case there's no pwd module - pass - self.assertEqual( - environ.get.call_args_list, - [mock.call(x) for x in ('LOGNAME', 'USER', 'LNAME', 'USERNAME')]) - - def test_username_falls_back_to_pwd(self, environ): - expected_name = 'some_name' - environ.get.return_value = None - if pwd: - with mock.patch('os.getuid') as uid, \ - mock.patch('pwd.getpwuid') as getpw: - uid.return_value = 42 - getpw.return_value = [expected_name] - self.assertEqual(expected_name, - getpass.getuser()) - getpw.assert_called_once_with(42) - else: - self.assertRaises(ImportError, getpass.getuser) - - -class GetpassRawinputTest(unittest.TestCase): - - def test_flushes_stream_after_prompt(self): - # see issue 1703 - stream = mock.Mock(spec=StringIO) - input = StringIO('input_string') - getpass._raw_input('some_prompt', stream, input=input) - stream.flush.assert_called_once_with() - - def test_uses_stderr_as_default(self): - input = StringIO('input_string') - prompt = 'some_prompt' - with mock.patch('sys.stderr') as stderr: - getpass._raw_input(prompt, input=input) - stderr.write.assert_called_once_with(prompt) - - @mock.patch('sys.stdin') - def test_uses_stdin_as_default_input(self, mock_input): - mock_input.readline.return_value = 'input_string' - getpass._raw_input(stream=StringIO()) - mock_input.readline.assert_called_once_with() - - def test_raises_on_empty_input(self): - input = StringIO('') - self.assertRaises(EOFError, getpass._raw_input, input=input) - - def test_trims_trailing_newline(self): - input = StringIO('test\n') - self.assertEqual('test', getpass._raw_input(input=input)) - - -# Some of these tests are a bit white-box. The functional requirement is that -# the password input be taken directly from the tty, and that it not be echoed -# on the screen, unless we are falling back to stderr/stdin. - -# Some of these might run on platforms without termios, but play it safe. -@unittest.skipUnless(termios, 'tests require system with termios') -class UnixGetpassTest(unittest.TestCase): - - def test_uses_tty_directly(self): - with mock.patch('os.open') as open, \ - mock.patch('io.FileIO') as fileio, \ - mock.patch('io.TextIOWrapper') as textio: - # By setting open's return value to None the implementation will - # skip code we don't care about in this test. We can mock this out - # fully if an alternate implementation works differently. - open.return_value = None - getpass.unix_getpass() - open.assert_called_once_with('/dev/tty', - os.O_RDWR | os.O_NOCTTY) - fileio.assert_called_once_with(open.return_value, 'w+') - textio.assert_called_once_with(fileio.return_value) - - def test_resets_termios(self): - with mock.patch('os.open') as open, \ - mock.patch('io.FileIO'), \ - mock.patch('io.TextIOWrapper'), \ - mock.patch('termios.tcgetattr') as tcgetattr, \ - mock.patch('termios.tcsetattr') as tcsetattr: - open.return_value = 3 - fake_attrs = [255, 255, 255, 255, 255] - tcgetattr.return_value = list(fake_attrs) - getpass.unix_getpass() - tcsetattr.assert_called_with(3, mock.ANY, fake_attrs) - - def test_falls_back_to_fallback_if_termios_raises(self): - with mock.patch('os.open') as open, \ - mock.patch('io.FileIO') as fileio, \ - mock.patch('io.TextIOWrapper') as textio, \ - mock.patch('termios.tcgetattr'), \ - mock.patch('termios.tcsetattr') as tcsetattr, \ - mock.patch('getpass.fallback_getpass') as fallback: - open.return_value = 3 - fileio.return_value = BytesIO() - tcsetattr.side_effect = termios.error - getpass.unix_getpass() - fallback.assert_called_once_with('Password: ', - textio.return_value) - - def test_flushes_stream_after_input(self): - # issue 7208 - with mock.patch('os.open') as open, \ - mock.patch('io.FileIO'), \ - mock.patch('io.TextIOWrapper'), \ - mock.patch('termios.tcgetattr'), \ - mock.patch('termios.tcsetattr'): - open.return_value = 3 - mock_stream = mock.Mock(spec=StringIO) - getpass.unix_getpass(stream=mock_stream) - mock_stream.flush.assert_called_with() - - def test_falls_back_to_stdin(self): - with mock.patch('os.open') as os_open, \ - mock.patch('sys.stdin', spec=StringIO) as stdin: - os_open.side_effect = IOError - stdin.fileno.side_effect = AttributeError - with support.captured_stderr() as stderr: - with self.assertWarns(getpass.GetPassWarning): - getpass.unix_getpass() - stdin.readline.assert_called_once_with() - self.assertIn('Warning', stderr.getvalue()) - self.assertIn('Password:', stderr.getvalue()) - - -if __name__ == "__main__": - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_gzip.py --- a/Lib/test/test_gzip.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_gzip.py Fri Feb 01 23:12:09 2013 +0100 @@ -389,27 +389,6 @@ datac = gzip.compress(data) self.assertEqual(gzip.decompress(datac), data) - def test_read_truncated(self): - data = data1*50 - # Drop the CRC (4 bytes) and file size (4 bytes). - truncated = gzip.compress(data)[:-8] - with gzip.GzipFile(fileobj=io.BytesIO(truncated)) as f: - self.assertRaises(EOFError, f.read) - with gzip.GzipFile(fileobj=io.BytesIO(truncated)) as f: - self.assertEqual(f.read(len(data)), data) - self.assertRaises(EOFError, f.read, 1) - # Incomplete 10-byte header. - for i in range(2, 10): - with gzip.GzipFile(fileobj=io.BytesIO(truncated[:i])) as f: - self.assertRaises(EOFError, f.read, 1) - - def test_read_with_extra(self): - # Gzip data with an extra field - gzdata = (b'\x1f\x8b\x08\x04\xb2\x17cQ\x02\xff' - b'\x05\x00Extra' - b'\x0bI-.\x01\x002\xd1Mx\x04\x00\x00\x00') - with gzip.GzipFile(fileobj=io.BytesIO(gzdata)) as f: - self.assertEqual(f.read(), b'Test') class TestOpen(BaseTest): def test_binary_modes(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_hash.py --- a/Lib/test/test_hash.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_hash.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,6 +7,7 @@ import os import sys import unittest +from test import support from test.script_helper import assert_python_ok from collections import Hashable @@ -132,7 +133,7 @@ for obj in self.hashes_to_check: self.assertEqual(hash(obj), _default_hash(obj)) -class HashRandomizationTests: +class HashRandomizationTests(unittest.TestCase): # Each subclass should define a field "repr_", containing the repr() of # an object to be tested @@ -189,22 +190,19 @@ h = -1024014457 self.assertEqual(self.get_hash(self.repr_, seed=42), h) -class StrHashRandomizationTests(StringlikeHashRandomizationTests, - unittest.TestCase): +class StrHashRandomizationTests(StringlikeHashRandomizationTests): repr_ = repr('abc') def test_empty_string(self): self.assertEqual(hash(""), 0) -class BytesHashRandomizationTests(StringlikeHashRandomizationTests, - unittest.TestCase): +class BytesHashRandomizationTests(StringlikeHashRandomizationTests): repr_ = repr(b'abc') def test_empty_string(self): self.assertEqual(hash(b""), 0) -class MemoryviewHashRandomizationTests(StringlikeHashRandomizationTests, - unittest.TestCase): +class MemoryviewHashRandomizationTests(StringlikeHashRandomizationTests): repr_ = "memoryview(b'abc')" def test_empty_string(self): @@ -214,15 +212,27 @@ def get_hash_command(self, repr_): return 'import datetime; print(hash(%s))' % repr_ -class DatetimeDateTests(DatetimeTests, unittest.TestCase): +class DatetimeDateTests(DatetimeTests): repr_ = repr(datetime.date(1066, 10, 14)) -class DatetimeDatetimeTests(DatetimeTests, unittest.TestCase): +class DatetimeDatetimeTests(DatetimeTests): repr_ = repr(datetime.datetime(1, 2, 3, 4, 5, 6, 7)) -class DatetimeTimeTests(DatetimeTests, unittest.TestCase): +class DatetimeTimeTests(DatetimeTests): repr_ = repr(datetime.time(0)) +def test_main(): + support.run_unittest(HashEqualityTestCase, + HashInheritanceTestCase, + HashBuiltinsTestCase, + StrHashRandomizationTests, + BytesHashRandomizationTests, + MemoryviewHashRandomizationTests, + DatetimeDateTests, + DatetimeDatetimeTests, + DatetimeTimeTests) + + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_hashlib.py --- a/Lib/test/test_hashlib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_hashlib.py Fri Feb 01 23:12:09 2013 +0100 @@ -494,6 +494,8 @@ self.assertEqual(expected_hash, hasher.hexdigest()) +def test_main(): + support.run_unittest(HashLibTestCase) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_heapq.py --- a/Lib/test/test_heapq.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_heapq.py Fri Feb 01 23:12:09 2013 +0100 @@ -319,16 +319,6 @@ return chain(map(lambda x:x, R(Ig(G(seqn))))) -class SideEffectLT: - def __init__(self, value, heap): - self.value = value - self.heap = heap - - def __lt__(self, other): - self.heap[:] = [] - return self.value < other.value - - class TestErrorHandling: def test_non_sequence(self): @@ -379,22 +369,6 @@ self.assertRaises(TypeError, f, 2, N(s)) self.assertRaises(ZeroDivisionError, f, 2, E(s)) - # Issue #17278: the heap may change size while it's being walked. - - def test_heappush_mutating_heap(self): - heap = [] - heap.extend(SideEffectLT(i, heap) for i in range(200)) - # Python version raises IndexError, C version RuntimeError - with self.assertRaises((IndexError, RuntimeError)): - self.module.heappush(heap, SideEffectLT(5, heap)) - - def test_heappop_mutating_heap(self): - heap = [] - heap.extend(SideEffectLT(i, heap) for i in range(200)) - # Python version raises IndexError, C version RuntimeError - with self.assertRaises((IndexError, RuntimeError)): - self.module.heappop(heap) - class TestErrorHandlingPython(TestErrorHandling, TestCase): module = py_heapq diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_hmac.py --- a/Lib/test/test_hmac.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_hmac.py Fri Feb 01 23:12:09 2013 +0100 @@ -253,20 +253,6 @@ except: self.fail("Constructor call with text argument raised exception.") - def test_with_bytearray(self): - try: - h = hmac.HMAC(bytearray(b"key"), bytearray(b"hash this!")) - self.assertEqual(h.hexdigest(), '34325b639da4cfd95735b381e28cb864') - except: - self.fail("Constructor call with bytearray arguments raised exception.") - - def test_with_memoryview_msg(self): - try: - h = hmac.HMAC(b"key", memoryview(b"hash this!")) - self.assertEqual(h.hexdigest(), '34325b639da4cfd95735b381e28cb864') - except: - self.fail("Constructor call with memoryview msg raised exception.") - def test_withmodule(self): # Constructor call with text and digest module. try: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_htmlparser.py --- a/Lib/test/test_htmlparser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_htmlparser.py Fri Feb 01 23:12:09 2013 +0100 @@ -535,20 +535,6 @@ ] self._run_check(html, expected) - def test_EOF_in_charref(self): - # see #17802 - # This test checks that the UnboundLocalError reported in the issue - # is not raised, however I'm not sure the returned values are correct. - # Maybe HTMLParser should use self.unescape for these - data = [ - ('a&', [('data', 'a&')]), - ('a&b', [('data', 'ab')]), - ('a&b ', [('data', 'a'), ('entityref', 'b'), ('data', ' ')]), - ('a&b;', [('data', 'a'), ('entityref', 'b')]), - ] - for html, expected in data: - self._run_check(html, expected) - def test_unescape_function(self): p = self.get_collector() self.assertEqual(p.unescape('&#bad;'),'&#bad;') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_httplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -166,9 +166,6 @@ resp.begin() self.assertEqual(resp.read(), b"Text") self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" sock = FakeSocket(body) @@ -190,9 +187,6 @@ self.assertFalse(resp.isclosed()) self.assertEqual(resp.read(2), b'xt') self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) def test_partial_readintos(self): # if we have a length, the system knows when to close itself @@ -210,9 +204,6 @@ self.assertEqual(n, 2) self.assertEqual(bytes(b), b'xt') self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) def test_partial_reads_no_content_length(self): # when no length is present, the socket should be gracefully closed when @@ -226,9 +217,6 @@ self.assertEqual(resp.read(2), b'xt') self.assertEqual(resp.read(1), b'') self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) def test_partial_readintos_no_content_length(self): # when no length is present, the socket should be gracefully closed when @@ -249,41 +237,6 @@ self.assertEqual(n, 0) self.assertTrue(resp.isclosed()) - def test_partial_reads_incomplete_body(self): - # if the server shuts down the connection before the whole - # content-length is delivered, the socket is gracefully closed - body = "HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\nText" - sock = FakeSocket(body) - resp = client.HTTPResponse(sock) - resp.begin() - self.assertEqual(resp.read(2), b'Te') - self.assertFalse(resp.isclosed()) - self.assertEqual(resp.read(2), b'xt') - self.assertEqual(resp.read(1), b'') - self.assertTrue(resp.isclosed()) - - def test_partial_readintos_incomplete_body(self): - # if the server shuts down the connection before the whole - # content-length is delivered, the socket is gracefully closed - body = "HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\nText" - sock = FakeSocket(body) - resp = client.HTTPResponse(sock) - resp.begin() - b = bytearray(2) - n = resp.readinto(b) - self.assertEqual(n, 2) - self.assertEqual(bytes(b), b'Te') - self.assertFalse(resp.isclosed()) - n = resp.readinto(b) - self.assertEqual(n, 2) - self.assertEqual(bytes(b), b'xt') - n = resp.readinto(b) - self.assertEqual(n, 0) - self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) - def test_host_port(self): # Check invalid host_port @@ -373,27 +326,6 @@ conn.send(io.BytesIO(expected)) self.assertEqual(expected, sock.data) - def test_send_updating_file(self): - def data(): - yield 'data' - yield None - yield 'data_two' - - class UpdatingFile(): - mode = 'r' - d = data() - def read(self, blocksize=-1): - return self.d.__next__() - - expected = b'data' - - conn = client.HTTPConnection('example.com') - sock = FakeSocket("") - conn.sock = sock - conn.send(UpdatingFile()) - self.assertEqual(sock.data, expected) - - def test_send_iter(self): expected = b'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \ b'Accept-Encoding: identity\r\nContent-Length: 11\r\n' \ @@ -531,9 +463,6 @@ self.assertEqual(resp.status, 200) self.assertEqual(resp.reason, 'OK') self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) def test_readinto_chunked_head(self): chunked_start = ( @@ -554,9 +483,6 @@ self.assertEqual(resp.status, 200) self.assertEqual(resp.reason, 'OK') self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) def test_negative_content_length(self): sock = FakeSocket( @@ -564,7 +490,7 @@ resp = client.HTTPResponse(sock, method="GET") resp.begin() self.assertEqual(resp.read(), b'Hello\r\n') - self.assertTrue(resp.isclosed()) + resp.close() def test_incomplete_read(self): sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n') @@ -578,9 +504,10 @@ "IncompleteRead(7 bytes read, 3 more expected)") self.assertEqual(str(i), "IncompleteRead(7 bytes read, 3 more expected)") - self.assertTrue(resp.isclosed()) else: self.fail('IncompleteRead expected') + finally: + resp.close() def test_epipe(self): sock = EPipeSocket( @@ -632,9 +559,6 @@ resp.begin() self.assertEqual(resp.read(), b'') self.assertTrue(resp.isclosed()) - self.assertFalse(resp.closed) - resp.close() - self.assertTrue(resp.closed) def test_delayed_ack_opt(self): # Test that Nagle/delayed_ack optimistaion works correctly. @@ -748,7 +672,7 @@ def make_server(self, certfile): from test.ssl_servers import make_https_server - return make_https_server(self, certfile=certfile) + return make_https_server(self, certfile) def test_attributes(self): # simple test to check it's storing the timeout diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_httpservers.py Fri Feb 01 23:12:09 2013 +0100 @@ -95,10 +95,6 @@ def do_NOTFOUND(self): self.send_error(404) - def do_EXPLAINERROR(self): - self.send_error(999, "Short Message", - "This is a long \n explaination") - def do_CUSTOM(self): self.send_response(999) self.send_header('Content-Type', 'text/html') @@ -210,12 +206,6 @@ res = self.con.getresponse() self.assertEqual(res.status, 999) - def test_return_explain_error(self): - self.con.request('EXPLAINERROR', '/') - res = self.con.getresponse() - self.assertEqual(res.status, 999) - self.assertTrue(int(res.getheader('Content-Length'))) - def test_latin1_header(self): self.con.request('LATINONEHEADER', '/', headers={ 'X-Special-Incoming': 'Ärger mit Unicode' @@ -361,7 +351,8 @@ self.pythonexe.encode('utf-8') except UnicodeEncodeError: self.tearDown() - self.skipTest("Python executable path is not encodable to utf-8") + raise self.skipTest( + "Python executable path is not encodable to utf-8") self.file1_path = os.path.join(self.cgi_dir, 'file1.py') with open(self.file1_path, 'w', encoding='utf-8') as file1: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_idle.py --- a/Lib/test/test_idle.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -# Skip test if _tkinter or _thread wasn't built or idlelib was deleted. -from test.support import import_module -import_module('tkinter') -import_module('threading') # imported by PyShell, imports _thread -idletest = import_module('idlelib.idle_test') - -# Without test_main present, regrtest.runtest_inner (line1219) calls -# unittest.TestLoader().loadTestsFromModule(this_module) which calls -# load_tests() if it finds it. (Unittest.main does the same.) -load_tests = idletest.load_tests - -if __name__ == '__main__': - # Until unittest supports resources, we emulate regrtest's -ugui - # so loaded tests run the same as if textually present here. - # If any Idle test ever needs another resource, add it to the list. - from test import support - support.use_resources = ['gui'] # use_resources is initially None - import unittest - unittest.main(verbosity=2, exit=False) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_imaplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -94,25 +94,14 @@ class SimpleIMAPHandler(socketserver.StreamRequestHandler): timeout = 1 - continuation = None - capabilities = '' def _send(self, message): if verbose: print("SENT: %r" % message.strip()) self.wfile.write(message) - def _send_line(self, message): - self._send(message + b'\r\n') - - def _send_textline(self, message): - self._send_line(message.encode('ASCII')) - - def _send_tagged(self, tag, code, message): - self._send_textline(' '.join((tag, code, message))) - def handle(self): # Send a welcome message. - self._send_textline('* OK IMAP4rev1') + self._send(b'* OK IMAP4rev1\r\n') while 1: # Gather up input until we receive a line terminator or we timeout. # Accumulate read(1) because it's simpler to handle the differences @@ -132,33 +121,19 @@ break if verbose: print('GOT: %r' % line.strip()) - if self.continuation: - try: - self.continuation.send(line) - except StopIteration: - self.continuation = None - continue - splitline = line.decode('ASCII').split() - tag = splitline[0] - cmd = splitline[1] + splitline = line.split() + tag = splitline[0].decode('ASCII') + cmd = splitline[1].decode('ASCII') args = splitline[2:] if hasattr(self, 'cmd_'+cmd): - continuation = getattr(self, 'cmd_'+cmd)(tag, args) - if continuation: - self.continuation = continuation - next(continuation) + getattr(self, 'cmd_'+cmd)(tag, args) else: - self._send_tagged(tag, 'BAD', cmd + ' unknown') + self._send('{} BAD {} unknown\r\n'.format(tag, cmd).encode('ASCII')) def cmd_CAPABILITY(self, tag, args): - caps = 'IMAP4rev1 ' + self.capabilities if self.capabilities else 'IMAP4rev1' - self._send_textline('* CAPABILITY ' + caps) - self._send_tagged(tag, 'OK', 'CAPABILITY completed') - - def cmd_LOGOUT(self, tag, args): - self._send_textline('* BYE IMAP4ref1 Server logging out') - self._send_tagged(tag, 'OK', 'LOGOUT completed') + self._send(b'* CAPABILITY IMAP4rev1\r\n') + self._send('{} OK CAPABILITY completed\r\n'.format(tag).encode('ASCII')) class BaseThreadedNetworkedTests(unittest.TestCase): @@ -208,16 +183,6 @@ finally: self.reap_server(server, thread) - @contextmanager - def reaped_pair(self, hdlr): - server, thread = self.make_server((support.HOST, 0), hdlr) - client = self.imap_class(*server.server_address) - try: - yield server, client - finally: - client.logout() - self.reap_server(server, thread) - @reap_threads def test_connect(self): with self.reaped_server(SimpleIMAPHandler) as server: @@ -243,86 +208,12 @@ def cmd_CAPABILITY(self, tag, args): self._send(b'* CAPABILITY IMAP4rev1 AUTH\n') - self._send_tagged(tag, 'OK', 'CAPABILITY completed') + self._send('{} OK CAPABILITY completed\r\n'.format(tag).encode('ASCII')) with self.reaped_server(BadNewlineHandler) as server: self.assertRaises(imaplib.IMAP4.abort, self.imap_class, *server.server_address) - @reap_threads - def test_bad_auth_name(self): - - class MyServer(SimpleIMAPHandler): - - def cmd_AUTHENTICATE(self, tag, args): - self._send_tagged(tag, 'NO', 'unrecognized authentication ' - 'type {}'.format(args[0])) - - with self.reaped_pair(MyServer) as (server, client): - with self.assertRaises(imaplib.IMAP4.error): - client.authenticate('METHOD', lambda: 1) - - @reap_threads - def test_invalid_authentication(self): - - class MyServer(SimpleIMAPHandler): - - def cmd_AUTHENTICATE(self, tag, args): - self._send_textline('+') - self.response = yield - self._send_tagged(tag, 'NO', '[AUTHENTICATIONFAILED] invalid') - - with self.reaped_pair(MyServer) as (server, client): - with self.assertRaises(imaplib.IMAP4.error): - code, data = client.authenticate('MYAUTH', lambda x: b'fake') - - @reap_threads - def test_valid_authentication(self): - - class MyServer(SimpleIMAPHandler): - - def cmd_AUTHENTICATE(self, tag, args): - self._send_textline('+') - self.server.response = yield - self._send_tagged(tag, 'OK', 'FAKEAUTH successful') - - with self.reaped_pair(MyServer) as (server, client): - code, data = client.authenticate('MYAUTH', lambda x: b'fake') - self.assertEqual(code, 'OK') - self.assertEqual(server.response, - b'ZmFrZQ==\r\n') #b64 encoded 'fake' - - with self.reaped_pair(MyServer) as (server, client): - code, data = client.authenticate('MYAUTH', lambda x: 'fake') - self.assertEqual(code, 'OK') - self.assertEqual(server.response, - b'ZmFrZQ==\r\n') #b64 encoded 'fake' - - @reap_threads - def test_login_cram_md5(self): - - class AuthHandler(SimpleIMAPHandler): - - capabilities = 'LOGINDISABLED AUTH=CRAM-MD5' - - def cmd_AUTHENTICATE(self, tag, args): - self._send_textline('+ PDE4OTYuNjk3MTcwOTUyQHBvc3RvZmZpY2Uucm' - 'VzdG9uLm1jaS5uZXQ=') - r = yield - if r == b'dGltIGYxY2E2YmU0NjRiOWVmYTFjY2E2ZmZkNmNmMmQ5ZjMy\r\n': - self._send_tagged(tag, 'OK', 'CRAM-MD5 successful') - else: - self._send_tagged(tag, 'NO', 'No access') - - with self.reaped_pair(AuthHandler) as (server, client): - self.assertTrue('AUTH=CRAM-MD5' in client.capabilities) - ret, data = client.login_cram_md5("tim", "tanstaaftanstaaf") - self.assertEqual(ret, "OK") - - with self.reaped_pair(AuthHandler) as (server, client): - self.assertTrue('AUTH=CRAM-MD5' in client.capabilities) - ret, data = client.login_cram_md5("tim", b"tanstaaftanstaaf") - self.assertEqual(ret, "OK") class ThreadedNetworkedTests(BaseThreadedNetworkedTests): @@ -444,7 +335,7 @@ keyfile=CERTFILE, ssl_context=self.create_ssl_context()) -def load_tests(*args): +def test_main(): tests = [TestImaplib] if support.is_resource_enabled('network'): @@ -459,9 +350,9 @@ RemoteIMAPTest, RemoteIMAP_SSLTest, RemoteIMAP_STARTTLSTest, ]) - return unittest.TestSuite([unittest.makeSuite(test) for test in tests]) + support.run_unittest(*tests) if __name__ == "__main__": support.use_resources = ['network'] - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_imp.py --- a/Lib/test/test_imp.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_imp.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,4 @@ -try: - import _thread -except ImportError: - _thread = None +import imp import importlib import os import os.path @@ -10,20 +7,7 @@ from test import support import unittest import warnings -with warnings.catch_warnings(): - warnings.simplefilter('ignore', PendingDeprecationWarning) - import imp - -def requires_load_dynamic(meth): - """Decorator to skip a test if not running under CPython or lacking - imp.load_dynamic().""" - meth = support.cpython_only(meth) - return unittest.skipIf(not hasattr(imp, 'load_dynamic'), - 'imp.load_dynamic() required')(meth) - - -@unittest.skipIf(_thread is None, '_thread module is required') class LockTests(unittest.TestCase): """Very basic test of import lock functions.""" @@ -178,10 +162,8 @@ with warnings.catch_warnings(): warnings.simplefilter('ignore') - if not sys.dont_write_bytecode: - mod = imp.load_compiled( - temp_mod_name, - imp.cache_from_source(temp_mod_name + '.py')) + mod = imp.load_compiled( + temp_mod_name, imp.cache_from_source(temp_mod_name + '.py')) self.assertEqual(mod.a, 1) if not os.path.exists(test_package_name): @@ -223,7 +205,7 @@ self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv) - @requires_load_dynamic + @support.cpython_only def test_issue15828_load_extensions(self): # Issue 15828 picked up that the adapter between the old imp API # and importlib couldn't handle C extensions @@ -235,7 +217,6 @@ mod = imp.load_module(example, *x) self.assertEqual(mod.__name__, example) - @requires_load_dynamic def test_issue16421_multiple_modules_in_one_dll(self): # Issue 16421: loading several modules from the same compiled file fails m = '_testimportmultiple' @@ -250,7 +231,6 @@ with self.assertRaises(ImportError): imp.load_dynamic('nonexistent', pathname) - @requires_load_dynamic def test_load_dynamic_ImportError_path(self): # Issue #1559549 added `name` and `path` attributes to ImportError # in order to provide better detail. Issue #10854 implemented those @@ -262,30 +242,6 @@ self.assertIn(path, err.exception.path) self.assertEqual(name, err.exception.name) - @requires_load_dynamic - def test_load_module_extension_file_is_None(self): - # When loading an extension module and the file is None, open one - # on the behalf of imp.load_dynamic(). - # Issue #15902 - name = '_testimportmultiple' - found = imp.find_module(name) - if found[0] is not None: - found[0].close() - if found[2][2] != imp.C_EXTENSION: - return - imp.load_module(name, None, *found[1:]) - - @unittest.skipIf(sys.dont_write_bytecode, - "test meaningful only when writing bytecode") - def test_bug7732(self): - source = support.TESTFN + '.py' - os.mkdir(source) - try: - self.assertRaisesRegex(ImportError, '^No module', - imp.find_module, support.TESTFN, ["."]) - finally: - os.rmdir(source) - class ReloadTests(unittest.TestCase): @@ -466,5 +422,20 @@ os.rmdir(name) +def test_main(): + tests = [ + ImportTests, + PEP3147Tests, + ReloadTests, + NullImporterTests, + ] + try: + import _thread + except ImportError: + pass + else: + tests.append(LockTests) + support.run_unittest(*tests) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_import.py --- a/Lib/test/test_import.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_import.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,7 @@ # We import importlib *ASAP* in order to test #15386 import importlib -import importlib.util -from importlib._bootstrap import _get_sourcefile import builtins +import imp from test.test_importlib.import_ import util as importlib_util import marshal import os @@ -12,7 +11,6 @@ import stat import sys import unittest -import unittest.mock as mock import textwrap import errno import shutil @@ -26,10 +24,6 @@ from test import script_helper -skip_if_dont_write_bytecode = unittest.skipIf( - sys.dont_write_bytecode, - "test meaningful only when writing bytecode") - def remove_files(name): for f in (name + ".py", name + ".pyc", @@ -45,7 +39,6 @@ # sets up a temporary directory and removes it # creates the module file # temporarily clears the module from sys.modules (if any) - # reverts or removes the module when cleaning up name = name or "spam" with script_helper.temp_dir() as tempdir: path = script_helper.make_script(tempdir, name, source) @@ -57,8 +50,6 @@ finally: if old_module is not None: sys.modules[name] = old_module - elif name in sys.modules: - del sys.modules[name] class ImportTests(unittest.TestCase): @@ -70,6 +61,8 @@ def tearDown(self): unload(TESTFN) + setUp = tearDown + def test_case_sensitivity(self): # Brief digression to test that import is case-sensitive: if we got # this far, we know for sure that "random" exists. @@ -127,6 +120,15 @@ finally: del sys.path[0] + def test_bug7732(self): + source = TESTFN + '.py' + os.mkdir(source) + try: + self.assertRaisesRegex(ImportError, '^No module', + imp.find_module, TESTFN, ["."]) + finally: + os.rmdir(source) + def test_module_with_large_stack(self, module='longlist'): # Regression test for http://bugs.python.org/issue561858. filename = module + '.py' @@ -213,7 +215,7 @@ with open(source, "w") as f: f.write("a = 10\nb=20//0\n") - self.assertRaises(ZeroDivisionError, importlib.reload, mod) + self.assertRaises(ZeroDivisionError, imp.reload, mod) # But we still expect the module to be in sys.modules. mod = sys.modules.get(TESTFN) self.assertIsNot(mod, None, "expected module to be in sys.modules") @@ -228,7 +230,6 @@ remove_files(TESTFN) unload(TESTFN) - @skip_if_dont_write_bytecode def test_file_to_source(self): # check if __file__ points to the source file where available source = TESTFN + ".py" @@ -279,7 +280,7 @@ import sys class C: def __del__(self): - import importlib + import imp sys.argv.insert(0, C()) """)) script_helper.assert_python_ok(testfn) @@ -290,7 +291,7 @@ sys.path.insert(0, os.curdir) try: source = TESTFN + ".py" - compiled = importlib.util.cache_from_source(source) + compiled = imp.cache_from_source(source) with open(source, 'w') as f: pass try: @@ -314,23 +315,7 @@ except ImportError: self.fail("fromlist must allow bogus names") - @cpython_only - def test_delete_builtins_import(self): - args = ["-c", "del __builtins__.__import__; import os"] - popen = script_helper.spawn_python(*args) - stdout, stderr = popen.communicate() - self.assertIn(b"ImportError", stdout) - def test_from_import_message_for_nonexistent_module(self): - with self.assertRaisesRegexp(ImportError, "^No module named 'bogus'"): - from bogus import foo - - def test_from_import_message_for_existing_module(self): - with self.assertRaisesRegexp(ImportError, "^cannot import name 'bogus'"): - from re import bogus - - -@skip_if_dont_write_bytecode class FilePermissionTests(unittest.TestCase): # tests for file mode on cached .pyc/.pyo files @@ -339,7 +324,7 @@ def test_creation_mode(self): mask = 0o022 with temp_umask(mask), _ready_to_import() as (name, path): - cached_path = importlib.util.cache_from_source(path) + cached_path = imp.cache_from_source(path) module = __import__(name) if not os.path.exists(cached_path): self.fail("__import__ did not result in creation of " @@ -357,7 +342,7 @@ # permissions of .pyc should match those of .py, regardless of mask mode = 0o600 with temp_umask(0o022), _ready_to_import() as (name, path): - cached_path = importlib.util.cache_from_source(path) + cached_path = imp.cache_from_source(path) os.chmod(path, mode) __import__(name) if not os.path.exists(cached_path): @@ -372,7 +357,7 @@ def test_cached_readonly(self): mode = 0o400 with temp_umask(0o022), _ready_to_import() as (name, path): - cached_path = importlib.util.cache_from_source(path) + cached_path = imp.cache_from_source(path) os.chmod(path, mode) __import__(name) if not os.path.exists(cached_path): @@ -412,7 +397,7 @@ bytecode_only = path + "c" else: bytecode_only = path + "o" - os.rename(importlib.util.cache_from_source(path), bytecode_only) + os.rename(imp.cache_from_source(path), bytecode_only) m = __import__(name) self.assertEqual(m.x, 'rewritten') @@ -434,7 +419,7 @@ """ dir_name = os.path.abspath(TESTFN) file_name = os.path.join(dir_name, module_name) + os.extsep + "py" - compiled_name = importlib.util.cache_from_source(file_name) + compiled_name = imp.cache_from_source(file_name) def setUp(self): self.sys_path = sys.path[:] @@ -495,7 +480,7 @@ header = f.read(12) code = marshal.load(f) constants = list(code.co_consts) - foreign_code = importlib.import_module.__code__ + foreign_code = test_main.__code__ pos = constants.index(1) constants[pos] = foreign_code code = type(code)(code.co_argcount, code.co_kwonlyargcount, @@ -637,7 +622,7 @@ class PycacheTests(unittest.TestCase): # Test the various PEP 3147 related behaviors. - tag = sys.implementation.cache_tag + tag = imp.get_tag() def _clean(self): forget(TESTFN) @@ -657,7 +642,6 @@ del sys.path[0] self._clean() - @skip_if_dont_write_bytecode def test_import_pyc_path(self): self.assertFalse(os.path.exists('__pycache__')) __import__(TESTFN) @@ -670,7 +654,6 @@ "test meaningful only on posix systems") @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0, "due to varying filesystem permission semantics (issue #11956)") - @skip_if_dont_write_bytecode def test_unwritable_directory(self): # When the umask causes the new __pycache__ directory to be # unwritable, the import still succeeds but no .pyc file is written. @@ -680,18 +663,16 @@ self.assertFalse(os.path.exists(os.path.join( '__pycache__', '{}.{}.pyc'.format(TESTFN, self.tag)))) - @skip_if_dont_write_bytecode def test_missing_source(self): # With PEP 3147 cache layout, removing the source but leaving the pyc # file does not satisfy the import. __import__(TESTFN) - pyc_file = importlib.util.cache_from_source(self.source) + pyc_file = imp.cache_from_source(self.source) self.assertTrue(os.path.exists(pyc_file)) os.remove(self.source) forget(TESTFN) self.assertRaises(ImportError, __import__, TESTFN) - @skip_if_dont_write_bytecode def test_missing_source_legacy(self): # Like test_missing_source() except that for backward compatibility, # when the pyc file lives where the py file would have been (and named @@ -710,10 +691,9 @@ def test___cached__(self): # Modules now also have an __cached__ that points to the pyc file. m = __import__(TESTFN) - pyc_file = importlib.util.cache_from_source(TESTFN + '.py') + pyc_file = imp.cache_from_source(TESTFN + '.py') self.assertEqual(m.__cached__, os.path.join(os.curdir, pyc_file)) - @skip_if_dont_write_bytecode def test___cached___legacy_pyc(self): # Like test___cached__() except that for backward compatibility, # when the pyc file lives where the py file would have been (and named @@ -729,7 +709,6 @@ self.assertEqual(m.__cached__, os.path.join(os.curdir, os.path.relpath(pyc_file))) - @skip_if_dont_write_bytecode def test_package___cached__(self): # Like test___cached__ but for packages. def cleanup(): @@ -745,10 +724,10 @@ pass importlib.invalidate_caches() m = __import__('pep3147.foo') - init_pyc = importlib.util.cache_from_source( + init_pyc = imp.cache_from_source( os.path.join('pep3147', '__init__.py')) self.assertEqual(m.__cached__, os.path.join(os.curdir, init_pyc)) - foo_pyc = importlib.util.cache_from_source(os.path.join('pep3147', 'foo.py')) + foo_pyc = imp.cache_from_source(os.path.join('pep3147', 'foo.py')) self.assertEqual(sys.modules['pep3147.foo'].__cached__, os.path.join(os.curdir, foo_pyc)) @@ -772,10 +751,10 @@ unload('pep3147') importlib.invalidate_caches() m = __import__('pep3147.foo') - init_pyc = importlib.util.cache_from_source( + init_pyc = imp.cache_from_source( os.path.join('pep3147', '__init__.py')) self.assertEqual(m.__cached__, os.path.join(os.curdir, init_pyc)) - foo_pyc = importlib.util.cache_from_source(os.path.join('pep3147', 'foo.py')) + foo_pyc = imp.cache_from_source(os.path.join('pep3147', 'foo.py')) self.assertEqual(sys.modules['pep3147.foo'].__cached__, os.path.join(os.curdir, foo_pyc)) @@ -859,40 +838,7 @@ from importlib import machinery mod = sys.modules['_frozen_importlib'] self.assertIs(machinery.FileFinder, mod.FileFinder) - - -@cpython_only -class GetSourcefileTests(unittest.TestCase): - - """Test importlib._bootstrap._get_sourcefile() as used by the C API. - - Because of the peculiarities of the need of this function, the tests are - knowingly whitebox tests. - - """ - - def test_get_sourcefile(self): - # Given a valid bytecode path, return the path to the corresponding - # source file if it exists. - with mock.patch('importlib._bootstrap._path_isfile') as _path_isfile: - _path_isfile.return_value = True; - path = TESTFN + '.pyc' - expect = TESTFN + '.py' - self.assertEqual(_get_sourcefile(path), expect) - - def test_get_sourcefile_no_source(self): - # Given a valid bytecode path without a corresponding source path, - # return the original bytecode path. - with mock.patch('importlib._bootstrap._path_isfile') as _path_isfile: - _path_isfile.return_value = False; - path = TESTFN + '.pyc' - self.assertEqual(_get_sourcefile(path), path) - - def test_get_sourcefile_bad_ext(self): - # Given a path with an invalid bytecode extension, return the - # bytecode path passed as the argument. - path = TESTFN + '.bad_ext' - self.assertEqual(_get_sourcefile(path), path) + self.assertIs(imp.new_module, mod.new_module) class ImportTracebackTests(unittest.TestCase): @@ -1055,6 +1001,16 @@ importlib.SourceLoader.load_module = old_load_module +def test_main(verbose=None): + run_unittest(ImportTests, PycacheTests, FilePermissionTests, + PycRewritingTests, PathsTests, RelativeImportTests, + OverridingImportBuiltinTests, + ImportlibBootstrapTests, + TestSymbolicallyLinkedPackage, + ImportTracebackTests) + + if __name__ == '__main__': # Test needs to be a package, so we can do relative imports. - unittest.main() + from test.test_import import test_main + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importhooks.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_importhooks.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,250 @@ +import sys +import imp +import os +import unittest +from test import support + + +test_src = """\ +def get_name(): + return __name__ +def get_file(): + return __file__ +""" + +absimp = "import sub\n" +relimp = "from . import sub\n" +deeprelimp = "from .... import sub\n" +futimp = "from __future__ import absolute_import\n" + +reload_src = test_src+"""\ +reloaded = True +""" + +test_co = compile(test_src, "", "exec") +reload_co = compile(reload_src, "", "exec") + +test2_oldabs_co = compile(absimp + test_src, "", "exec") +test2_newabs_co = compile(futimp + absimp + test_src, "", "exec") +test2_newrel_co = compile(relimp + test_src, "", "exec") +test2_deeprel_co = compile(deeprelimp + test_src, "", "exec") +test2_futrel_co = compile(futimp + relimp + test_src, "", "exec") + +test_path = "!!!_test_!!!" + + +class TestImporter: + + modules = { + "hooktestmodule": (False, test_co), + "hooktestpackage": (True, test_co), + "hooktestpackage.sub": (True, test_co), + "hooktestpackage.sub.subber": (True, test_co), + "hooktestpackage.oldabs": (False, test2_oldabs_co), + "hooktestpackage.newabs": (False, test2_newabs_co), + "hooktestpackage.newrel": (False, test2_newrel_co), + "hooktestpackage.sub.subber.subest": (True, test2_deeprel_co), + "hooktestpackage.futrel": (False, test2_futrel_co), + "sub": (False, test_co), + "reloadmodule": (False, test_co), + } + + def __init__(self, path=test_path): + if path != test_path: + # if our class is on sys.path_hooks, we must raise + # ImportError for any path item that we can't handle. + raise ImportError + self.path = path + + def _get__path__(self): + raise NotImplementedError + + def find_module(self, fullname, path=None): + if fullname in self.modules: + return self + else: + return None + + def load_module(self, fullname): + ispkg, code = self.modules[fullname] + mod = sys.modules.setdefault(fullname,imp.new_module(fullname)) + mod.__file__ = "<%s>" % self.__class__.__name__ + mod.__loader__ = self + if ispkg: + mod.__path__ = self._get__path__() + exec(code, mod.__dict__) + return mod + + +class MetaImporter(TestImporter): + def _get__path__(self): + return [] + +class PathImporter(TestImporter): + def _get__path__(self): + return [self.path] + + +class ImportBlocker: + """Place an ImportBlocker instance on sys.meta_path and you + can be sure the modules you specified can't be imported, even + if it's a builtin.""" + def __init__(self, *namestoblock): + self.namestoblock = dict.fromkeys(namestoblock) + def find_module(self, fullname, path=None): + if fullname in self.namestoblock: + return self + return None + def load_module(self, fullname): + raise ImportError("I dare you") + + +class ImpWrapper: + + def __init__(self, path=None): + if path is not None and not os.path.isdir(path): + raise ImportError + self.path = path + + def find_module(self, fullname, path=None): + subname = fullname.split(".")[-1] + if subname != fullname and self.path is None: + return None + if self.path is None: + path = None + else: + path = [self.path] + try: + file, filename, stuff = imp.find_module(subname, path) + except ImportError: + return None + return ImpLoader(file, filename, stuff) + + +class ImpLoader: + + def __init__(self, file, filename, stuff): + self.file = file + self.filename = filename + self.stuff = stuff + + def load_module(self, fullname): + mod = imp.load_module(fullname, self.file, self.filename, self.stuff) + if self.file: + self.file.close() + mod.__loader__ = self # for introspection + return mod + + +class ImportHooksBaseTestCase(unittest.TestCase): + + def setUp(self): + self.path = sys.path[:] + self.meta_path = sys.meta_path[:] + self.path_hooks = sys.path_hooks[:] + sys.path_importer_cache.clear() + self.modules_before = support.modules_setup() + + def tearDown(self): + sys.path[:] = self.path + sys.meta_path[:] = self.meta_path + sys.path_hooks[:] = self.path_hooks + sys.path_importer_cache.clear() + support.modules_cleanup(*self.modules_before) + + +class ImportHooksTestCase(ImportHooksBaseTestCase): + + def doTestImports(self, importer=None): + import hooktestmodule + import hooktestpackage + import hooktestpackage.sub + import hooktestpackage.sub.subber + self.assertEqual(hooktestmodule.get_name(), + "hooktestmodule") + self.assertEqual(hooktestpackage.get_name(), + "hooktestpackage") + self.assertEqual(hooktestpackage.sub.get_name(), + "hooktestpackage.sub") + self.assertEqual(hooktestpackage.sub.subber.get_name(), + "hooktestpackage.sub.subber") + if importer: + self.assertEqual(hooktestmodule.__loader__, importer) + self.assertEqual(hooktestpackage.__loader__, importer) + self.assertEqual(hooktestpackage.sub.__loader__, importer) + self.assertEqual(hooktestpackage.sub.subber.__loader__, importer) + + TestImporter.modules['reloadmodule'] = (False, test_co) + import reloadmodule + self.assertFalse(hasattr(reloadmodule,'reloaded')) + + import hooktestpackage.newrel + self.assertEqual(hooktestpackage.newrel.get_name(), + "hooktestpackage.newrel") + self.assertEqual(hooktestpackage.newrel.sub, + hooktestpackage.sub) + + import hooktestpackage.sub.subber.subest as subest + self.assertEqual(subest.get_name(), + "hooktestpackage.sub.subber.subest") + self.assertEqual(subest.sub, + hooktestpackage.sub) + + import hooktestpackage.futrel + self.assertEqual(hooktestpackage.futrel.get_name(), + "hooktestpackage.futrel") + self.assertEqual(hooktestpackage.futrel.sub, + hooktestpackage.sub) + + import sub + self.assertEqual(sub.get_name(), "sub") + + import hooktestpackage.oldabs + self.assertEqual(hooktestpackage.oldabs.get_name(), + "hooktestpackage.oldabs") + self.assertEqual(hooktestpackage.oldabs.sub, sub) + + import hooktestpackage.newabs + self.assertEqual(hooktestpackage.newabs.get_name(), + "hooktestpackage.newabs") + self.assertEqual(hooktestpackage.newabs.sub, sub) + + def testMetaPath(self): + i = MetaImporter() + sys.meta_path.append(i) + self.doTestImports(i) + + def testPathHook(self): + sys.path_hooks.insert(0, PathImporter) + sys.path.append(test_path) + self.doTestImports() + + def testBlocker(self): + mname = "exceptions" # an arbitrary harmless builtin module + support.unload(mname) + sys.meta_path.append(ImportBlocker(mname)) + self.assertRaises(ImportError, __import__, mname) + + def testImpWrapper(self): + i = ImpWrapper() + sys.meta_path.append(i) + sys.path_hooks.insert(0, ImpWrapper) + mnames = ( + "colorsys", "urllib.parse", "distutils.core", "sys", + ) + for mname in mnames: + parent = mname.split(".")[0] + for n in list(sys.modules): + if n.startswith(parent): + del sys.modules[n] + for mname in mnames: + m = __import__(mname, globals(), locals(), ["__dummy__"]) + # to make sure we actually handled the import + self.assertTrue(hasattr(m, "__loader__")) + + +def test_main(): + support.run_unittest(ImportHooksTestCase) + +if __name__ == "__main__": + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/extension/test_case_sensitivity.py --- a/Lib/test/test_importlib/extension/test_case_sensitivity.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,9 +1,8 @@ +import imp import sys from test import support import unittest - from importlib import _bootstrap -from importlib import machinery from .. import util from . import util as ext_util @@ -15,9 +14,9 @@ good_name = ext_util.NAME bad_name = good_name.upper() assert good_name != bad_name - finder = machinery.FileFinder(ext_util.PATH, - (machinery.ExtensionFileLoader, - machinery.EXTENSION_SUFFIXES)) + finder = _bootstrap.FileFinder(ext_util.PATH, + (_bootstrap.ExtensionFileLoader, + _bootstrap.EXTENSION_SUFFIXES)) return finder.find_module(bad_name) def test_case_sensitive(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/extension/test_path_hook.py --- a/Lib/test/test_importlib/extension/test_path_hook.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/extension/test_path_hook.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,7 @@ from . import util import collections +import imp import sys import unittest diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/extension/util.py --- a/Lib/test/test_importlib/extension/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/extension/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,3 +1,4 @@ +import imp from importlib import machinery import os import sys diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/frozen/test_loader.py --- a/Lib/test/test_importlib/frozen/test_loader.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/frozen/test_loader.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,11 +1,9 @@ +from importlib import machinery +import imp +import unittest from .. import abc from .. import util - -from importlib import machinery -import unittest from test.support import captured_stdout -import types - class LoaderTests(abc.LoaderTests): @@ -26,7 +24,7 @@ module = machinery.FrozenImporter.load_module('__phello__') check = {'__name__': '__phello__', '__package__': '__phello__', - '__path__': [], + '__path__': ['__phello__'], '__loader__': machinery.FrozenImporter, } for attr, value in check.items(): @@ -87,7 +85,7 @@ name = '__hello__' with captured_stdout() as stdout: code = machinery.FrozenImporter.get_code(name) - mod = types.ModuleType(name) + mod = imp.new_module(name) exec(code, mod.__dict__) self.assertTrue(hasattr(mod, 'initialized')) self.assertEqual(stdout.getvalue(), 'Hello world!\n') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/import_/test___loader__.py --- a/Lib/test/test_importlib/import_/test___loader__.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -import sys -import types -import unittest - -from .. import util -from . import util as import_util - - -class LoaderMock: - - def find_module(self, fullname, path=None): - return self - - def load_module(self, fullname): - sys.modules[fullname] = self.module - return self.module - - -class LoaderAttributeTests(unittest.TestCase): - - def test___loader___missing(self): - module = types.ModuleType('blah') - try: - del module.__loader__ - except AttributeError: - pass - loader = LoaderMock() - loader.module = module - with util.uncache('blah'), util.import_state(meta_path=[loader]): - module = import_util.import_('blah') - self.assertEqual(loader, module.__loader__) - - def test___loader___is_None(self): - module = types.ModuleType('blah') - module.__loader__ = None - loader = LoaderMock() - loader.module = module - with util.uncache('blah'), util.import_state(meta_path=[loader]): - returned_module = import_util.import_('blah') - self.assertEqual(loader, module.__loader__) - - -if __name__ == '__main__': - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/import_/test_api.py --- a/Lib/test/test_importlib/import_/test_api.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/import_/test_api.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ from .. import util as importlib_test_util from . import util +import imp import sys -import types import unittest @@ -37,7 +37,7 @@ def test_nonexistent_fromlist_entry(self): # If something in fromlist doesn't exist, that's okay. # issue15715 - mod = types.ModuleType('fine') + mod = imp.new_module('fine') mod.__path__ = ['XXX'] with importlib_test_util.import_state(meta_path=[BadLoaderFinder]): with importlib_test_util.uncache('fine'): @@ -48,7 +48,7 @@ # If something in fromlist triggers an exception not related to not # existing, let that exception propagate. # issue15316 - mod = types.ModuleType('fine') + mod = imp.new_module('fine') mod.__path__ = ['XXX'] with importlib_test_util.import_state(meta_path=[BadLoaderFinder]): with importlib_test_util.uncache('fine'): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/import_/test_fromlist.py --- a/Lib/test/test_importlib/import_/test_fromlist.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/import_/test_fromlist.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,7 @@ """Test that the semantics relating to the 'fromlist' argument are correct.""" from .. import util from . import util as import_util +import imp import unittest class ReturnValue(unittest.TestCase): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/source/test_abc_loader.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_importlib/source/test_abc_loader.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,410 @@ +import importlib +from importlib import abc + +from .. import abc as testing_abc +from .. import util +from . import util as source_util + +import imp +import inspect +import io +import marshal +import os +import sys +import types +import unittest +import warnings + + +class SourceOnlyLoaderMock(abc.SourceLoader): + + # Globals that should be defined for all modules. + source = (b"_ = '::'.join([__name__, __file__, __cached__, __package__, " + b"repr(__loader__)])") + + def __init__(self, path): + self.path = path + + def get_data(self, path): + assert self.path == path + return self.source + + def get_filename(self, fullname): + return self.path + + def module_repr(self, module): + return '' + + +class SourceLoaderMock(SourceOnlyLoaderMock): + + source_mtime = 1 + + def __init__(self, path, magic=imp.get_magic()): + super().__init__(path) + self.bytecode_path = imp.cache_from_source(self.path) + self.source_size = len(self.source) + data = bytearray(magic) + data.extend(importlib._w_long(self.source_mtime)) + data.extend(importlib._w_long(self.source_size)) + code_object = compile(self.source, self.path, 'exec', + dont_inherit=True) + data.extend(marshal.dumps(code_object)) + self.bytecode = bytes(data) + self.written = {} + + def get_data(self, path): + if path == self.path: + return super().get_data(path) + elif path == self.bytecode_path: + return self.bytecode + else: + raise OSError + + def path_stats(self, path): + assert path == self.path + return {'mtime': self.source_mtime, 'size': self.source_size} + + def set_data(self, path, data): + self.written[path] = bytes(data) + return path == self.bytecode_path + + +def raise_ImportError(*args, **kwargs): + raise ImportError + + +class SourceLoaderTestHarness(unittest.TestCase): + + def setUp(self, *, is_package=True, **kwargs): + self.package = 'pkg' + if is_package: + self.path = os.path.join(self.package, '__init__.py') + self.name = self.package + else: + module_name = 'mod' + self.path = os.path.join(self.package, '.'.join(['mod', 'py'])) + self.name = '.'.join([self.package, module_name]) + self.cached = imp.cache_from_source(self.path) + self.loader = self.loader_mock(self.path, **kwargs) + + def verify_module(self, module): + self.assertEqual(module.__name__, self.name) + self.assertEqual(module.__file__, self.path) + self.assertEqual(module.__cached__, self.cached) + self.assertEqual(module.__package__, self.package) + self.assertEqual(module.__loader__, self.loader) + values = module._.split('::') + self.assertEqual(values[0], self.name) + self.assertEqual(values[1], self.path) + self.assertEqual(values[2], self.cached) + self.assertEqual(values[3], self.package) + self.assertEqual(values[4], repr(self.loader)) + + def verify_code(self, code_object): + module = imp.new_module(self.name) + module.__file__ = self.path + module.__cached__ = self.cached + module.__package__ = self.package + module.__loader__ = self.loader + module.__path__ = [] + exec(code_object, module.__dict__) + self.verify_module(module) + + +class SourceOnlyLoaderTests(SourceLoaderTestHarness): + + """Test importlib.abc.SourceLoader for source-only loading. + + Reload testing is subsumed by the tests for + importlib.util.module_for_loader. + + """ + + loader_mock = SourceOnlyLoaderMock + + def test_get_source(self): + # Verify the source code is returned as a string. + # If an OSError is raised by get_data then raise ImportError. + expected_source = self.loader.source.decode('utf-8') + self.assertEqual(self.loader.get_source(self.name), expected_source) + def raise_OSError(path): + raise OSError + self.loader.get_data = raise_OSError + with self.assertRaises(ImportError) as cm: + self.loader.get_source(self.name) + self.assertEqual(cm.exception.name, self.name) + + def test_is_package(self): + # Properly detect when loading a package. + self.setUp(is_package=False) + self.assertFalse(self.loader.is_package(self.name)) + self.setUp(is_package=True) + self.assertTrue(self.loader.is_package(self.name)) + self.assertFalse(self.loader.is_package(self.name + '.__init__')) + + def test_get_code(self): + # Verify the code object is created. + code_object = self.loader.get_code(self.name) + self.verify_code(code_object) + + def test_source_to_code(self): + # Verify the compiled code object. + code = self.loader.source_to_code(self.loader.source, self.path) + self.verify_code(code) + + def test_load_module(self): + # Loading a module should set __name__, __loader__, __package__, + # __path__ (for packages), __file__, and __cached__. + # The module should also be put into sys.modules. + with util.uncache(self.name): + module = self.loader.load_module(self.name) + self.verify_module(module) + self.assertEqual(module.__path__, [os.path.dirname(self.path)]) + self.assertIn(self.name, sys.modules) + + def test_package_settings(self): + # __package__ needs to be set, while __path__ is set on if the module + # is a package. + # Testing the values for a package are covered by test_load_module. + self.setUp(is_package=False) + with util.uncache(self.name): + module = self.loader.load_module(self.name) + self.verify_module(module) + self.assertTrue(not hasattr(module, '__path__')) + + def test_get_source_encoding(self): + # Source is considered encoded in UTF-8 by default unless otherwise + # specified by an encoding line. + source = "_ = 'ü'" + self.loader.source = source.encode('utf-8') + returned_source = self.loader.get_source(self.name) + self.assertEqual(returned_source, source) + source = "# coding: latin-1\n_ = ü" + self.loader.source = source.encode('latin-1') + returned_source = self.loader.get_source(self.name) + self.assertEqual(returned_source, source) + + +@unittest.skipIf(sys.dont_write_bytecode, "sys.dont_write_bytecode is true") +class SourceLoaderBytecodeTests(SourceLoaderTestHarness): + + """Test importlib.abc.SourceLoader's use of bytecode. + + Source-only testing handled by SourceOnlyLoaderTests. + + """ + + loader_mock = SourceLoaderMock + + def verify_code(self, code_object, *, bytecode_written=False): + super().verify_code(code_object) + if bytecode_written: + self.assertIn(self.cached, self.loader.written) + data = bytearray(imp.get_magic()) + data.extend(importlib._w_long(self.loader.source_mtime)) + data.extend(importlib._w_long(self.loader.source_size)) + data.extend(marshal.dumps(code_object)) + self.assertEqual(self.loader.written[self.cached], bytes(data)) + + def test_code_with_everything(self): + # When everything should work. + code_object = self.loader.get_code(self.name) + self.verify_code(code_object) + + def test_no_bytecode(self): + # If no bytecode exists then move on to the source. + self.loader.bytecode_path = "" + # Sanity check + with self.assertRaises(OSError): + bytecode_path = imp.cache_from_source(self.path) + self.loader.get_data(bytecode_path) + code_object = self.loader.get_code(self.name) + self.verify_code(code_object, bytecode_written=True) + + def test_code_bad_timestamp(self): + # Bytecode is only used when the timestamp matches the source EXACTLY. + for source_mtime in (0, 2): + assert source_mtime != self.loader.source_mtime + original = self.loader.source_mtime + self.loader.source_mtime = source_mtime + # If bytecode is used then EOFError would be raised by marshal. + self.loader.bytecode = self.loader.bytecode[8:] + code_object = self.loader.get_code(self.name) + self.verify_code(code_object, bytecode_written=True) + self.loader.source_mtime = original + + def test_code_bad_magic(self): + # Skip over bytecode with a bad magic number. + self.setUp(magic=b'0000') + # If bytecode is used then EOFError would be raised by marshal. + self.loader.bytecode = self.loader.bytecode[8:] + code_object = self.loader.get_code(self.name) + self.verify_code(code_object, bytecode_written=True) + + def test_dont_write_bytecode(self): + # Bytecode is not written if sys.dont_write_bytecode is true. + # Can assume it is false already thanks to the skipIf class decorator. + try: + sys.dont_write_bytecode = True + self.loader.bytecode_path = "" + code_object = self.loader.get_code(self.name) + self.assertNotIn(self.cached, self.loader.written) + finally: + sys.dont_write_bytecode = False + + def test_no_set_data(self): + # If set_data is not defined, one can still read bytecode. + self.setUp(magic=b'0000') + original_set_data = self.loader.__class__.set_data + try: + del self.loader.__class__.set_data + code_object = self.loader.get_code(self.name) + self.verify_code(code_object) + finally: + self.loader.__class__.set_data = original_set_data + + def test_set_data_raises_exceptions(self): + # Raising NotImplementedError or OSError is okay for set_data. + def raise_exception(exc): + def closure(*args, **kwargs): + raise exc + return closure + + self.setUp(magic=b'0000') + self.loader.set_data = raise_exception(NotImplementedError) + code_object = self.loader.get_code(self.name) + self.verify_code(code_object) + + +class SourceLoaderGetSourceTests(unittest.TestCase): + + """Tests for importlib.abc.SourceLoader.get_source().""" + + def test_default_encoding(self): + # Should have no problems with UTF-8 text. + name = 'mod' + mock = SourceOnlyLoaderMock('mod.file') + source = 'x = "ü"' + mock.source = source.encode('utf-8') + returned_source = mock.get_source(name) + self.assertEqual(returned_source, source) + + def test_decoded_source(self): + # Decoding should work. + name = 'mod' + mock = SourceOnlyLoaderMock("mod.file") + source = "# coding: Latin-1\nx='ü'" + assert source.encode('latin-1') != source.encode('utf-8') + mock.source = source.encode('latin-1') + returned_source = mock.get_source(name) + self.assertEqual(returned_source, source) + + def test_universal_newlines(self): + # PEP 302 says universal newlines should be used. + name = 'mod' + mock = SourceOnlyLoaderMock('mod.file') + source = "x = 42\r\ny = -13\r\n" + mock.source = source.encode('utf-8') + expect = io.IncrementalNewlineDecoder(None, True).decode(source) + self.assertEqual(mock.get_source(name), expect) + + +class AbstractMethodImplTests(unittest.TestCase): + + """Test the concrete abstractmethod implementations.""" + + class MetaPathFinder(abc.MetaPathFinder): + def find_module(self, fullname, path): + super().find_module(fullname, path) + + class PathEntryFinder(abc.PathEntryFinder): + def find_module(self, _): + super().find_module(_) + + def find_loader(self, _): + super().find_loader(_) + + class Finder(abc.Finder): + def find_module(self, fullname, path): + super().find_module(fullname, path) + + class Loader(abc.Loader): + def load_module(self, fullname): + super().load_module(fullname) + + def module_repr(self, module): + super().module_repr(module) + + class ResourceLoader(Loader, abc.ResourceLoader): + def get_data(self, _): + super().get_data(_) + + class InspectLoader(Loader, abc.InspectLoader): + def is_package(self, _): + super().is_package(_) + + def get_code(self, _): + super().get_code(_) + + def get_source(self, _): + super().get_source(_) + + class ExecutionLoader(InspectLoader, abc.ExecutionLoader): + def get_filename(self, _): + super().get_filename(_) + + class SourceLoader(ResourceLoader, ExecutionLoader, abc.SourceLoader): + pass + + def raises_NotImplementedError(self, ins, *args): + for method_name in args: + method = getattr(ins, method_name) + arg_count = len(inspect.getfullargspec(method)[0]) - 1 + args = [''] * arg_count + try: + method(*args) + except NotImplementedError: + pass + else: + msg = "{}.{} did not raise NotImplementedError" + self.fail(msg.format(ins.__class__.__name__, method_name)) + + def test_Loader(self): + self.raises_NotImplementedError(self.Loader(), 'load_module') + + # XXX misplaced; should be somewhere else + def test_Finder(self): + self.raises_NotImplementedError(self.Finder(), 'find_module') + + def test_ResourceLoader(self): + self.raises_NotImplementedError(self.ResourceLoader(), 'load_module', + 'get_data') + + def test_InspectLoader(self): + self.raises_NotImplementedError(self.InspectLoader(), 'load_module', + 'is_package', 'get_code', 'get_source') + + def test_ExecutionLoader(self): + self.raises_NotImplementedError(self.ExecutionLoader(), 'load_module', + 'is_package', 'get_code', 'get_source', + 'get_filename') + + def test_SourceLoader(self): + ins = self.SourceLoader() + # Required abstractmethods. + self.raises_NotImplementedError(ins, 'get_filename', 'get_data') + # Optional abstractmethods. + self.raises_NotImplementedError(ins, 'path_stats', 'set_data') + + +def test_main(): + from test.support import run_unittest + run_unittest(SourceOnlyLoaderTests, + SourceLoaderBytecodeTests, + SourceLoaderGetSourceTests, + AbstractMethodImplTests) + + +if __name__ == '__main__': + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/source/test_case_sensitivity.py --- a/Lib/test/test_importlib/source/test_case_sensitivity.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/source/test_case_sensitivity.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,9 +1,9 @@ """Test case-sensitivity (PEP 235).""" +from importlib import _bootstrap +from importlib import machinery from .. import util from . import util as source_util - -from importlib import _bootstrap -from importlib import machinery +import imp import os import sys from test import support as test_support diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/source/test_file_loader.py --- a/Lib/test/test_importlib/source/test_file_loader.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/source/test_file_loader.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,22 +1,21 @@ from importlib import machinery import importlib import importlib.abc -import importlib.util from .. import abc from .. import util from . import util as source_util import errno +import imp import marshal import os import py_compile import shutil import stat import sys -import types import unittest -from test.support import make_legacy_pyc, unload +from test.support import make_legacy_pyc class SimpleTest(unittest.TestCase): @@ -27,13 +26,23 @@ """ def test_load_module_API(self): - class Tester(importlib.abc.FileLoader): - def get_source(self, _): return 'attr = 42' - def is_package(self, _): return False + # If fullname is not specified that assume self.name is desired. + class TesterMixin(importlib.abc.Loader): + def load_module(self, fullname): return fullname + def module_repr(self, module): return '' - loader = Tester('blah', 'blah.py') - self.addCleanup(unload, 'blah') - module = loader.load_module() # Should not raise an exception. + class Tester(importlib.abc.FileLoader, TesterMixin): + def get_code(self, _): pass + def get_source(self, _): pass + def is_package(self, _): pass + + name = 'mod_name' + loader = Tester(name, 'some_path') + self.assertEqual(name, loader.load_module()) + self.assertEqual(name, loader.load_module(None)) + self.assertEqual(name, loader.load_module(name)) + with self.assertRaises(ImportError): + loader.load_module(loader.name + 'XXX') def test_get_filename_API(self): # If fullname is not set then assume self.path is desired. @@ -113,7 +122,7 @@ value = '' name = '_temp' with source_util.create_modules(name) as mapping: - orig_module = types.ModuleType(name) + orig_module = imp.new_module(name) for attr in attributes: setattr(orig_module, attr, value) with open(mapping[name], 'w') as file: @@ -145,20 +154,19 @@ loader = machinery.SourceFileLoader('_temp', file_path) mod = loader.load_module('_temp') self.assertEqual(file_path, mod.__file__) - self.assertEqual(importlib.util.cache_from_source(file_path), + self.assertEqual(imp.cache_from_source(file_path), mod.__cached__) finally: os.unlink(file_path) - pycache = os.path.dirname(importlib.util.cache_from_source(file_path)) - if os.path.exists(pycache): - shutil.rmtree(pycache) + pycache = os.path.dirname(imp.cache_from_source(file_path)) + shutil.rmtree(pycache) def test_timestamp_overflow(self): # When a modification timestamp is larger than 2**32, it should be # truncated rather than raise an OverflowError. with source_util.create_modules('_temp') as mapping: source = mapping['_temp'] - compiled = importlib.util.cache_from_source(source) + compiled = imp.cache_from_source(source) with open(source, 'w') as f: f.write("x = 5") try: @@ -195,7 +203,7 @@ pass py_compile.compile(mapping[name]) if not del_source: - bytecode_path = importlib.util.cache_from_source(mapping[name]) + bytecode_path = imp.cache_from_source(mapping[name]) else: os.unlink(mapping[name]) bytecode_path = make_legacy_pyc(mapping[name]) @@ -323,8 +331,7 @@ def test(name, mapping, bytecode_path): self.import_(mapping[name], name) with open(bytecode_path, 'rb') as bytecode_file: - self.assertEqual(bytecode_file.read(4), - importlib.util.MAGIC_NUMBER) + self.assertEqual(bytecode_file.read(4), imp.get_magic()) self._test_bad_magic(test) @@ -374,7 +381,7 @@ zeros = b'\x00\x00\x00\x00' with source_util.create_modules('_temp') as mapping: py_compile.compile(mapping['_temp']) - bytecode_path = importlib.util.cache_from_source(mapping['_temp']) + bytecode_path = imp.cache_from_source(mapping['_temp']) with open(bytecode_path, 'r+b') as bytecode_file: bytecode_file.seek(4) bytecode_file.write(zeros) @@ -392,7 +399,7 @@ with source_util.create_modules('_temp') as mapping: # Create bytecode that will need to be re-created. py_compile.compile(mapping['_temp']) - bytecode_path = importlib.util.cache_from_source(mapping['_temp']) + bytecode_path = imp.cache_from_source(mapping['_temp']) with open(bytecode_path, 'r+b') as bytecode_file: bytecode_file.seek(0) bytecode_file.write(b'\x00\x00\x00\x00') @@ -465,6 +472,13 @@ self._test_non_code_marshal(del_source=True) +def test_main(): + from test.support import run_unittest + run_unittest(SimpleTest, + SourceLoaderBadBytecodeTest, + SourcelessLoaderBadBytecodeTest + ) + if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/source/test_finder.py --- a/Lib/test/test_importlib/source/test_finder.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/source/test_finder.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,6 +3,7 @@ from importlib import machinery import errno +import imp import os import py_compile import stat diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/source/test_path_hook.py --- a/Lib/test/test_importlib/source/test_path_hook.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/source/test_path_hook.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,7 @@ from . import util as source_util from importlib import machinery +import imp import unittest diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/source/util.py --- a/Lib/test/test_importlib/source/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/source/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,7 @@ import contextlib import errno import functools +import imp import os import os.path import sys diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/test_abc.py --- a/Lib/test/test_importlib/test_abc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/test_abc.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,22 +1,9 @@ -import importlib -import importlib.util from importlib import abc from importlib import machinery +import inspect +import unittest -import contextlib -import inspect -import io -import marshal -import os -import sys -from test import support -import types -import unittest -from unittest import mock -from . import util - -##### Inheritance ############################################################## class InheritanceTests: """Test that the specified class is a subclass/superclass of the expected @@ -85,745 +72,16 @@ subclasses = [machinery.SourceFileLoader] -##### Default return values #################################################### -class MetaPathFinderSubclass(abc.MetaPathFinder): - - def find_module(self, fullname, path): - return super().find_module(fullname, path) - - -class MetaPathFinderDefaultsTests(unittest.TestCase): - - ins = MetaPathFinderSubclass() - - def test_find_module(self): - # Default should return None. - self.assertIsNone(self.ins.find_module('something', None)) - - def test_invalidate_caches(self): - # Calling the method is a no-op. - self.ins.invalidate_caches() - - -class PathEntryFinderSubclass(abc.PathEntryFinder): - - def find_loader(self, fullname): - return super().find_loader(fullname) - - -class PathEntryFinderDefaultsTests(unittest.TestCase): - - ins = PathEntryFinderSubclass() - - def test_find_loader(self): - self.assertEqual((None, []), self.ins.find_loader('something')) - - def find_module(self): - self.assertEqual(None, self.ins.find_module('something')) - - def test_invalidate_caches(self): - # Should be a no-op. - self.ins.invalidate_caches() - - -class LoaderSubclass(abc.Loader): - - def load_module(self, fullname): - return super().load_module(fullname) - - -class LoaderDefaultsTests(unittest.TestCase): - - ins = LoaderSubclass() - - def test_load_module(self): - with self.assertRaises(ImportError): - self.ins.load_module('something') - - def test_module_repr(self): - mod = types.ModuleType('blah') - with self.assertRaises(NotImplementedError): - self.ins.module_repr(mod) - original_repr = repr(mod) - mod.__loader__ = self.ins - # Should still return a proper repr. - self.assertTrue(repr(mod)) - - -class ResourceLoaderSubclass(LoaderSubclass, abc.ResourceLoader): - - def get_data(self, path): - return super().get_data(path) - - -class ResourceLoaderDefaultsTests(unittest.TestCase): - - ins = ResourceLoaderSubclass() - - def test_get_data(self): - with self.assertRaises(IOError): - self.ins.get_data('/some/path') - - -class InspectLoaderSubclass(LoaderSubclass, abc.InspectLoader): - - def is_package(self, fullname): - return super().is_package(fullname) - - def get_source(self, fullname): - return super().get_source(fullname) - - -class InspectLoaderDefaultsTests(unittest.TestCase): - - ins = InspectLoaderSubclass() - - def test_is_package(self): - with self.assertRaises(ImportError): - self.ins.is_package('blah') - - def test_get_source(self): - with self.assertRaises(ImportError): - self.ins.get_source('blah') - - -class ExecutionLoaderSubclass(InspectLoaderSubclass, abc.ExecutionLoader): - - def get_filename(self, fullname): - return super().get_filename(fullname) - - -class ExecutionLoaderDefaultsTests(unittest.TestCase): - - ins = ExecutionLoaderSubclass() - - def test_get_filename(self): - with self.assertRaises(ImportError): - self.ins.get_filename('blah') - -##### Loader concrete methods ################################################## -class LoaderConcreteMethodTests(unittest.TestCase): - - def test_init_module_attrs(self): - loader = LoaderSubclass() - module = types.ModuleType('blah') - loader.init_module_attrs(module) - self.assertEqual(module.__loader__, loader) - - -##### InspectLoader concrete methods ########################################### -class InspectLoaderSourceToCodeTests(unittest.TestCase): - - def source_to_module(self, data, path=None): - """Help with source_to_code() tests.""" - module = types.ModuleType('blah') - loader = InspectLoaderSubclass() - if path is None: - code = loader.source_to_code(data) - else: - code = loader.source_to_code(data, path) - exec(code, module.__dict__) - return module - - def test_source_to_code_source(self): - # Since compile() can handle strings, so should source_to_code(). - source = 'attr = 42' - module = self.source_to_module(source) - self.assertTrue(hasattr(module, 'attr')) - self.assertEqual(module.attr, 42) - - def test_source_to_code_bytes(self): - # Since compile() can handle bytes, so should source_to_code(). - source = b'attr = 42' - module = self.source_to_module(source) - self.assertTrue(hasattr(module, 'attr')) - self.assertEqual(module.attr, 42) - - def test_source_to_code_path(self): - # Specifying a path should set it for the code object. - path = 'path/to/somewhere' - loader = InspectLoaderSubclass() - code = loader.source_to_code('', path) - self.assertEqual(code.co_filename, path) - - def test_source_to_code_no_path(self): - # Not setting a path should still work and be set to since that - # is a pre-existing practice as a default to compile(). - loader = InspectLoaderSubclass() - code = loader.source_to_code('') - self.assertEqual(code.co_filename, '') - - -class InspectLoaderGetCodeTests(unittest.TestCase): - - def test_get_code(self): - # Test success. - module = types.ModuleType('blah') - with mock.patch.object(InspectLoaderSubclass, 'get_source') as mocked: - mocked.return_value = 'attr = 42' - loader = InspectLoaderSubclass() - code = loader.get_code('blah') - exec(code, module.__dict__) - self.assertEqual(module.attr, 42) - - def test_get_code_source_is_None(self): - # If get_source() is None then this should be None. - with mock.patch.object(InspectLoaderSubclass, 'get_source') as mocked: - mocked.return_value = None - loader = InspectLoaderSubclass() - code = loader.get_code('blah') - self.assertIsNone(code) - - def test_get_code_source_not_found(self): - # If there is no source then there is no code object. - loader = InspectLoaderSubclass() - with self.assertRaises(ImportError): - loader.get_code('blah') - - -class InspectLoaderInitModuleTests(unittest.TestCase): - - @staticmethod - def mock_is_package(return_value): - return mock.patch.object(InspectLoaderSubclass, 'is_package', - return_value=return_value) - - def init_module_attrs(self, name): - loader = InspectLoaderSubclass() - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertEqual(module.__loader__, loader) - return module - - def test_package(self): - # If a package, then __package__ == __name__, __path__ == [] - with self.mock_is_package(True): - name = 'blah' - module = self.init_module_attrs(name) - self.assertEqual(module.__package__, name) - self.assertEqual(module.__path__, []) - - def test_toplevel(self): - # If a module is top-level, __package__ == '' - with self.mock_is_package(False): - name = 'blah' - module = self.init_module_attrs(name) - self.assertEqual(module.__package__, '') - - def test_submodule(self): - # If a module is contained within a package then set __package__ to the - # package name. - with self.mock_is_package(False): - name = 'pkg.mod' - module = self.init_module_attrs(name) - self.assertEqual(module.__package__, 'pkg') - - def test_is_package_ImportError(self): - # If is_package() raises ImportError, __package__ should be None and - # __path__ should not be set. - with self.mock_is_package(False) as mocked_method: - mocked_method.side_effect = ImportError - name = 'mod' - module = self.init_module_attrs(name) - self.assertIsNone(module.__package__) - self.assertFalse(hasattr(module, '__path__')) - - -class InspectLoaderLoadModuleTests(unittest.TestCase): - - """Test InspectLoader.load_module().""" - - module_name = 'blah' - - def setUp(self): - support.unload(self.module_name) - self.addCleanup(support.unload, self.module_name) - - def mock_get_code(self): - return mock.patch.object(InspectLoaderSubclass, 'get_code') - - def test_get_code_ImportError(self): - # If get_code() raises ImportError, it should propagate. - with self.mock_get_code() as mocked_get_code: - mocked_get_code.side_effect = ImportError - with self.assertRaises(ImportError): - loader = InspectLoaderSubclass() - loader.load_module(self.module_name) - - def test_get_code_None(self): - # If get_code() returns None, raise ImportError. - with self.mock_get_code() as mocked_get_code: - mocked_get_code.return_value = None - with self.assertRaises(ImportError): - loader = InspectLoaderSubclass() - loader.load_module(self.module_name) - - def test_module_returned(self): - # The loaded module should be returned. - code = compile('attr = 42', '', 'exec') - with self.mock_get_code() as mocked_get_code: - mocked_get_code.return_value = code - loader = InspectLoaderSubclass() - module = loader.load_module(self.module_name) - self.assertEqual(module, sys.modules[self.module_name]) - - -##### ExecutionLoader concrete methods ######################################### -class ExecutionLoaderGetCodeTests(unittest.TestCase): - - def mock_methods(self, *, get_source=False, get_filename=False): - source_mock_context, filename_mock_context = None, None - if get_source: - source_mock_context = mock.patch.object(ExecutionLoaderSubclass, - 'get_source') - if get_filename: - filename_mock_context = mock.patch.object(ExecutionLoaderSubclass, - 'get_filename') - return source_mock_context, filename_mock_context - - def test_get_code(self): - path = 'blah.py' - source_mock_context, filename_mock_context = self.mock_methods( - get_source=True, get_filename=True) - with source_mock_context as source_mock, filename_mock_context as name_mock: - source_mock.return_value = 'attr = 42' - name_mock.return_value = path - loader = ExecutionLoaderSubclass() - code = loader.get_code('blah') - self.assertEqual(code.co_filename, path) - module = types.ModuleType('blah') - exec(code, module.__dict__) - self.assertEqual(module.attr, 42) - - def test_get_code_source_is_None(self): - # If get_source() is None then this should be None. - source_mock_context, _ = self.mock_methods(get_source=True) - with source_mock_context as mocked: - mocked.return_value = None - loader = ExecutionLoaderSubclass() - code = loader.get_code('blah') - self.assertIsNone(code) - - def test_get_code_source_not_found(self): - # If there is no source then there is no code object. - loader = ExecutionLoaderSubclass() - with self.assertRaises(ImportError): - loader.get_code('blah') - - def test_get_code_no_path(self): - # If get_filename() raises ImportError then simply skip setting the path - # on the code object. - source_mock_context, filename_mock_context = self.mock_methods( - get_source=True, get_filename=True) - with source_mock_context as source_mock, filename_mock_context as name_mock: - source_mock.return_value = 'attr = 42' - name_mock.side_effect = ImportError - loader = ExecutionLoaderSubclass() - code = loader.get_code('blah') - self.assertEqual(code.co_filename, '') - module = types.ModuleType('blah') - exec(code, module.__dict__) - self.assertEqual(module.attr, 42) - - -class ExecutionLoaderInitModuleTests(unittest.TestCase): - - @staticmethod - @contextlib.contextmanager - def mock_methods(is_package, filename): - is_package_manager = InspectLoaderInitModuleTests.mock_is_package(is_package) - get_filename_manager = mock.patch.object(ExecutionLoaderSubclass, - 'get_filename', return_value=filename) - with is_package_manager as mock_is_package: - with get_filename_manager as mock_get_filename: - yield {'is_package': mock_is_package, - 'get_filename': mock_get_filename} - - def test_toplevel(self): - # Verify __loader__, __file__, and __package__; no __path__. - name = 'blah' - path = os.path.join('some', 'path', '{}.py'.format(name)) - with self.mock_methods(False, path): - loader = ExecutionLoaderSubclass() - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertIs(module.__loader__, loader) - self.assertEqual(module.__file__, path) - self.assertEqual(module.__package__, '') - self.assertFalse(hasattr(module, '__path__')) - - def test_package(self): - # Verify __loader__, __file__, __package__, and __path__. - name = 'pkg' - path = os.path.join('some', 'pkg', '__init__.py') - with self.mock_methods(True, path): - loader = ExecutionLoaderSubclass() - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertIs(module.__loader__, loader) - self.assertEqual(module.__file__, path) - self.assertEqual(module.__package__, 'pkg') - self.assertEqual(module.__path__, [os.path.dirname(path)]) - - def test_submodule(self): - # Verify __package__ and not __path__; test_toplevel() takes care of - # other attributes. - name = 'pkg.submodule' - path = os.path.join('some', 'pkg', 'submodule.py') - with self.mock_methods(False, path): - loader = ExecutionLoaderSubclass() - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertEqual(module.__package__, 'pkg') - self.assertEqual(module.__file__, path) - self.assertFalse(hasattr(module, '__path__')) - - def test_get_filename_ImportError(self): - # If get_filename() raises ImportError, don't set __file__. - name = 'blah' - path = 'blah.py' - with self.mock_methods(False, path) as mocked_methods: - mocked_methods['get_filename'].side_effect = ImportError - loader = ExecutionLoaderSubclass() - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertFalse(hasattr(module, '__file__')) - - -##### SourceLoader concrete methods ############################################ -class SourceOnlyLoaderMock(abc.SourceLoader): - - # Globals that should be defined for all modules. - source = (b"_ = '::'.join([__name__, __file__, __cached__, __package__, " - b"repr(__loader__)])") - - def __init__(self, path): - self.path = path - - def get_data(self, path): - if path != self.path: - raise IOError - return self.source - - def get_filename(self, fullname): - return self.path - - def module_repr(self, module): - return '' - - -class SourceLoaderMock(SourceOnlyLoaderMock): - - source_mtime = 1 - - def __init__(self, path, magic=importlib.util.MAGIC_NUMBER): - super().__init__(path) - self.bytecode_path = importlib.util.cache_from_source(self.path) - self.source_size = len(self.source) - data = bytearray(magic) - data.extend(importlib._w_long(self.source_mtime)) - data.extend(importlib._w_long(self.source_size)) - code_object = compile(self.source, self.path, 'exec', - dont_inherit=True) - data.extend(marshal.dumps(code_object)) - self.bytecode = bytes(data) - self.written = {} - - def get_data(self, path): - if path == self.path: - return super().get_data(path) - elif path == self.bytecode_path: - return self.bytecode - else: - raise OSError - - def path_stats(self, path): - if path != self.path: - raise IOError - return {'mtime': self.source_mtime, 'size': self.source_size} - - def set_data(self, path, data): - self.written[path] = bytes(data) - return path == self.bytecode_path - - -class SourceLoaderTestHarness(unittest.TestCase): - - def setUp(self, *, is_package=True, **kwargs): - self.package = 'pkg' - if is_package: - self.path = os.path.join(self.package, '__init__.py') - self.name = self.package - else: - module_name = 'mod' - self.path = os.path.join(self.package, '.'.join(['mod', 'py'])) - self.name = '.'.join([self.package, module_name]) - self.cached = importlib.util.cache_from_source(self.path) - self.loader = self.loader_mock(self.path, **kwargs) - - def verify_module(self, module): - self.assertEqual(module.__name__, self.name) - self.assertEqual(module.__file__, self.path) - self.assertEqual(module.__cached__, self.cached) - self.assertEqual(module.__package__, self.package) - self.assertEqual(module.__loader__, self.loader) - values = module._.split('::') - self.assertEqual(values[0], self.name) - self.assertEqual(values[1], self.path) - self.assertEqual(values[2], self.cached) - self.assertEqual(values[3], self.package) - self.assertEqual(values[4], repr(self.loader)) - - def verify_code(self, code_object): - module = types.ModuleType(self.name) - module.__file__ = self.path - module.__cached__ = self.cached - module.__package__ = self.package - module.__loader__ = self.loader - module.__path__ = [] - exec(code_object, module.__dict__) - self.verify_module(module) - - -class SourceOnlyLoaderTests(SourceLoaderTestHarness): - - """Test importlib.abc.SourceLoader for source-only loading. - - Reload testing is subsumed by the tests for - importlib.util.module_for_loader. - - """ - - loader_mock = SourceOnlyLoaderMock - - def test_get_source(self): - # Verify the source code is returned as a string. - # If an OSError is raised by get_data then raise ImportError. - expected_source = self.loader.source.decode('utf-8') - self.assertEqual(self.loader.get_source(self.name), expected_source) - def raise_OSError(path): - raise OSError - self.loader.get_data = raise_OSError - with self.assertRaises(ImportError) as cm: - self.loader.get_source(self.name) - self.assertEqual(cm.exception.name, self.name) - - def test_is_package(self): - # Properly detect when loading a package. - self.setUp(is_package=False) - self.assertFalse(self.loader.is_package(self.name)) - self.setUp(is_package=True) - self.assertTrue(self.loader.is_package(self.name)) - self.assertFalse(self.loader.is_package(self.name + '.__init__')) - - def test_get_code(self): - # Verify the code object is created. - code_object = self.loader.get_code(self.name) - self.verify_code(code_object) - - def test_source_to_code(self): - # Verify the compiled code object. - code = self.loader.source_to_code(self.loader.source, self.path) - self.verify_code(code) - - def test_load_module(self): - # Loading a module should set __name__, __loader__, __package__, - # __path__ (for packages), __file__, and __cached__. - # The module should also be put into sys.modules. - with util.uncache(self.name): - module = self.loader.load_module(self.name) - self.verify_module(module) - self.assertEqual(module.__path__, [os.path.dirname(self.path)]) - self.assertIn(self.name, sys.modules) - - def test_package_settings(self): - # __package__ needs to be set, while __path__ is set on if the module - # is a package. - # Testing the values for a package are covered by test_load_module. - self.setUp(is_package=False) - with util.uncache(self.name): - module = self.loader.load_module(self.name) - self.verify_module(module) - self.assertTrue(not hasattr(module, '__path__')) - - def test_get_source_encoding(self): - # Source is considered encoded in UTF-8 by default unless otherwise - # specified by an encoding line. - source = "_ = 'ü'" - self.loader.source = source.encode('utf-8') - returned_source = self.loader.get_source(self.name) - self.assertEqual(returned_source, source) - source = "# coding: latin-1\n_ = ü" - self.loader.source = source.encode('latin-1') - returned_source = self.loader.get_source(self.name) - self.assertEqual(returned_source, source) - - -@unittest.skipIf(sys.dont_write_bytecode, "sys.dont_write_bytecode is true") -class SourceLoaderBytecodeTests(SourceLoaderTestHarness): - - """Test importlib.abc.SourceLoader's use of bytecode. - - Source-only testing handled by SourceOnlyLoaderTests. - - """ - - loader_mock = SourceLoaderMock - - def verify_code(self, code_object, *, bytecode_written=False): - super().verify_code(code_object) - if bytecode_written: - self.assertIn(self.cached, self.loader.written) - data = bytearray(importlib.util.MAGIC_NUMBER) - data.extend(importlib._w_long(self.loader.source_mtime)) - data.extend(importlib._w_long(self.loader.source_size)) - data.extend(marshal.dumps(code_object)) - self.assertEqual(self.loader.written[self.cached], bytes(data)) - - def test_code_with_everything(self): - # When everything should work. - code_object = self.loader.get_code(self.name) - self.verify_code(code_object) - - def test_no_bytecode(self): - # If no bytecode exists then move on to the source. - self.loader.bytecode_path = "" - # Sanity check - with self.assertRaises(OSError): - bytecode_path = importlib.util.cache_from_source(self.path) - self.loader.get_data(bytecode_path) - code_object = self.loader.get_code(self.name) - self.verify_code(code_object, bytecode_written=True) - - def test_code_bad_timestamp(self): - # Bytecode is only used when the timestamp matches the source EXACTLY. - for source_mtime in (0, 2): - assert source_mtime != self.loader.source_mtime - original = self.loader.source_mtime - self.loader.source_mtime = source_mtime - # If bytecode is used then EOFError would be raised by marshal. - self.loader.bytecode = self.loader.bytecode[8:] - code_object = self.loader.get_code(self.name) - self.verify_code(code_object, bytecode_written=True) - self.loader.source_mtime = original - - def test_code_bad_magic(self): - # Skip over bytecode with a bad magic number. - self.setUp(magic=b'0000') - # If bytecode is used then EOFError would be raised by marshal. - self.loader.bytecode = self.loader.bytecode[8:] - code_object = self.loader.get_code(self.name) - self.verify_code(code_object, bytecode_written=True) - - def test_dont_write_bytecode(self): - # Bytecode is not written if sys.dont_write_bytecode is true. - # Can assume it is false already thanks to the skipIf class decorator. - try: - sys.dont_write_bytecode = True - self.loader.bytecode_path = "" - code_object = self.loader.get_code(self.name) - self.assertNotIn(self.cached, self.loader.written) - finally: - sys.dont_write_bytecode = False - - def test_no_set_data(self): - # If set_data is not defined, one can still read bytecode. - self.setUp(magic=b'0000') - original_set_data = self.loader.__class__.set_data - try: - del self.loader.__class__.set_data - code_object = self.loader.get_code(self.name) - self.verify_code(code_object) - finally: - self.loader.__class__.set_data = original_set_data - - def test_set_data_raises_exceptions(self): - # Raising NotImplementedError or OSError is okay for set_data. - def raise_exception(exc): - def closure(*args, **kwargs): - raise exc - return closure - - self.setUp(magic=b'0000') - self.loader.set_data = raise_exception(NotImplementedError) - code_object = self.loader.get_code(self.name) - self.verify_code(code_object) - - -class SourceLoaderGetSourceTests(unittest.TestCase): - - """Tests for importlib.abc.SourceLoader.get_source().""" - - def test_default_encoding(self): - # Should have no problems with UTF-8 text. - name = 'mod' - mock = SourceOnlyLoaderMock('mod.file') - source = 'x = "ü"' - mock.source = source.encode('utf-8') - returned_source = mock.get_source(name) - self.assertEqual(returned_source, source) - - def test_decoded_source(self): - # Decoding should work. - name = 'mod' - mock = SourceOnlyLoaderMock("mod.file") - source = "# coding: Latin-1\nx='ü'" - assert source.encode('latin-1') != source.encode('utf-8') - mock.source = source.encode('latin-1') - returned_source = mock.get_source(name) - self.assertEqual(returned_source, source) - - def test_universal_newlines(self): - # PEP 302 says universal newlines should be used. - name = 'mod' - mock = SourceOnlyLoaderMock('mod.file') - source = "x = 42\r\ny = -13\r\n" - mock.source = source.encode('utf-8') - expect = io.IncrementalNewlineDecoder(None, True).decode(source) - self.assertEqual(mock.get_source(name), expect) - - -class SourceLoaderInitModuleAttrTests(unittest.TestCase): - - """Tests for importlib.abc.SourceLoader.init_module_attrs().""" - - def test_init_module_attrs(self): - # If __file__ set, __cached__ == importlib.util.cached_from_source(__file__). - name = 'blah' - path = 'blah.py' - loader = SourceOnlyLoaderMock(path) - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertEqual(module.__loader__, loader) - self.assertEqual(module.__package__, '') - self.assertEqual(module.__file__, path) - self.assertEqual(module.__cached__, importlib.util.cache_from_source(path)) - - @mock.patch('importlib._bootstrap.cache_from_source') - def test_cache_from_source_NotImplementedError(self, mock_cache_from_source): - # If importlib.util.cache_from_source() raises NotImplementedError don't set - # __cached__. - mock_cache_from_source.side_effect = NotImplementedError - name = 'blah' - path = 'blah.py' - loader = SourceOnlyLoaderMock(path) - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertEqual(module.__file__, path) - self.assertFalse(hasattr(module, '__cached__')) - - def test_no_get_filename(self): - # No __file__, no __cached__. - with mock.patch.object(SourceOnlyLoaderMock, 'get_filename') as mocked: - mocked.side_effect = ImportError - name = 'blah' - loader = SourceOnlyLoaderMock('blah.py') - module = types.ModuleType(name) - loader.init_module_attrs(module) - self.assertFalse(hasattr(module, '__file__')) - self.assertFalse(hasattr(module, '__cached__')) - +def test_main(): + from test.support import run_unittest + classes = [] + for class_ in globals().values(): + if (inspect.isclass(class_) and + issubclass(class_, unittest.TestCase) and + issubclass(class_, InheritanceTests)): + classes.append(class_) + run_unittest(*classes) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/test_api.py --- a/Lib/test/test_importlib/test_api.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/test_api.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,11 +1,9 @@ from . import util - +import imp import importlib -from importlib import _bootstrap from importlib import machinery import sys from test import support -import types import unittest @@ -99,7 +97,7 @@ # If a module with __loader__ is in sys.modules, then return it. name = 'some_mod' with util.uncache(name): - module = types.ModuleType(name) + module = imp.new_module(name) loader = 'a loader!' module.__loader__ = loader sys.modules[name] = module @@ -110,26 +108,12 @@ # If sys.modules[name].__loader__ is None, raise ValueError. name = 'some_mod' with util.uncache(name): - module = types.ModuleType(name) + module = imp.new_module(name) module.__loader__ = None sys.modules[name] = module with self.assertRaises(ValueError): importlib.find_loader(name) - def test_sys_modules_loader_is_not_set(self): - # Should raise ValueError - # Issue #17099 - name = 'some_mod' - with util.uncache(name): - module = types.ModuleType(name) - try: - del module.__loader__ - except AttributeError: - pass - sys.modules[name] = module - with self.assertRaises(ValueError): - importlib.find_loader(name) - def test_success(self): # Return the loader found on sys.meta_path. name = 'some_mod' @@ -151,18 +135,6 @@ self.assertIsNone(importlib.find_loader('nevergoingtofindthismodule')) -class ReloadTests(unittest.TestCase): - - """Test module reloading for builtin and extension modules.""" - - def test_reload_modules(self): - for mod in ('tokenize', 'time', 'marshal'): - with self.subTest(module=mod): - with support.CleanImport(mod): - module = importlib.import_module(mod) - importlib.reload(module) - - class InvalidateCacheTests(unittest.TestCase): def test_method_called(self): @@ -189,7 +161,7 @@ def test_method_lacking(self): # There should be no issues if the method is not defined. key = 'gobbledeegook' - sys.path_importer_cache[key] = None + sys.path_importer_cache[key] = imp.NullImporter('abc') self.addCleanup(lambda: sys.path_importer_cache.__delitem__(key)) importlib.invalidate_caches() # Shouldn't trigger an exception. @@ -203,19 +175,13 @@ machinery.FrozenImporter)) -class StartupTests(unittest.TestCase): - - def test_everyone_has___loader__(self): - # Issue #17098: all modules should have __loader__ defined. - for name, module in sys.modules.items(): - if isinstance(module, types.ModuleType): - self.assertTrue(hasattr(module, '__loader__'), - '{!r} lacks a __loader__ attribute'.format(name)) - if importlib.machinery.BuiltinImporter.find_module(name): - self.assertIsNot(module.__loader__, None) - elif importlib.machinery.FrozenImporter.find_module(name): - self.assertIsNot(module.__loader__, None) +def test_main(): + from test.support import run_unittest + run_unittest(ImportModuleTests, + FindLoaderTests, + InvalidateCacheTests, + FrozenImportlibTests) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/test_util.py --- a/Lib/test/test_importlib/test_util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/test_util.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,121 +1,23 @@ from importlib import util from . import util as test_util - -import os +import imp import sys -from test import support import types import unittest -import warnings - - -class DecodeSourceBytesTests(unittest.TestCase): - - source = "string ='ü'" - - def test_ut8_default(self): - source_bytes = self.source.encode('utf-8') - self.assertEqual(util.decode_source(source_bytes), self.source) - - def test_specified_encoding(self): - source = '# coding=latin-1\n' + self.source - source_bytes = source.encode('latin-1') - assert source_bytes != source.encode('utf-8') - self.assertEqual(util.decode_source(source_bytes), source) - - def test_universal_newlines(self): - source = '\r\n'.join([self.source, self.source]) - source_bytes = source.encode('utf-8') - self.assertEqual(util.decode_source(source_bytes), - '\n'.join([self.source, self.source])) - - -class ModuleToLoadTests(unittest.TestCase): - - module_name = 'ModuleManagerTest_module' - - def setUp(self): - support.unload(self.module_name) - self.addCleanup(support.unload, self.module_name) - - def test_new_module(self): - # Test a new module is created, inserted into sys.modules, has - # __initializing__ set to True after entering the context manager, - # and __initializing__ set to False after exiting. - with util.module_to_load(self.module_name) as module: - self.assertIn(self.module_name, sys.modules) - self.assertIs(sys.modules[self.module_name], module) - self.assertTrue(module.__initializing__) - self.assertFalse(module.__initializing__) - - def test_new_module_failed(self): - # Test the module is removed from sys.modules. - try: - with util.module_to_load(self.module_name) as module: - self.assertIn(self.module_name, sys.modules) - raise exception - except Exception: - self.assertNotIn(self.module_name, sys.modules) - else: - self.fail('importlib.util.module_to_load swallowed an exception') - - def test_reload(self): - # Test that the same module is in sys.modules. - created_module = types.ModuleType(self.module_name) - sys.modules[self.module_name] = created_module - with util.module_to_load(self.module_name) as module: - self.assertIs(module, created_module) - - def test_reload_failed(self): - # Test that the module was left in sys.modules. - created_module = types.ModuleType(self.module_name) - sys.modules[self.module_name] = created_module - try: - with util.module_to_load(self.module_name) as module: - raise Exception - except Exception: - self.assertIn(self.module_name, sys.modules) - else: - self.fail('importlib.util.module_to_load swallowed an exception') - - def test_reset_name(self): - # If reset_name is true then module.__name__ = name, else leave it be. - odd_name = 'not your typical name' - created_module = types.ModuleType(self.module_name) - created_module.__name__ = odd_name - sys.modules[self.module_name] = created_module - with util.module_to_load(self.module_name) as module: - self.assertEqual(module.__name__, self.module_name) - created_module.__name__ = odd_name - with util.module_to_load(self.module_name, reset_name=False) as module: - self.assertEqual(module.__name__, odd_name) class ModuleForLoaderTests(unittest.TestCase): """Tests for importlib.util.module_for_loader.""" - @staticmethod - def module_for_loader(func): - with warnings.catch_warnings(): - warnings.simplefilter('ignore', PendingDeprecationWarning) - return util.module_for_loader(func) - - def test_warning(self): - # Should raise a PendingDeprecationWarning when used. - with warnings.catch_warnings(): - warnings.simplefilter('error', PendingDeprecationWarning) - with self.assertRaises(PendingDeprecationWarning): - func = util.module_for_loader(lambda x: x) - def return_module(self, name): - fxn = self.module_for_loader(lambda self, module: module) + fxn = util.module_for_loader(lambda self, module: module) return fxn(self, name) def raise_exception(self, name): def to_wrap(self, module): raise ImportError - fxn = self.module_for_loader(to_wrap) + fxn = util.module_for_loader(to_wrap) try: fxn(self, name) except ImportError: @@ -133,23 +35,12 @@ def test_reload(self): # Test that a module is reused if already in sys.modules. - class FakeLoader: - def is_package(self, name): - return True - @self.module_for_loader - def load_module(self, module): - return module name = 'a.b.c' - module = types.ModuleType('a.b.c') - module.__loader__ = 42 - module.__package__ = 42 + module = imp.new_module('a.b.c') with test_util.uncache(name): sys.modules[name] = module - loader = FakeLoader() - returned_module = loader.load_module(name) + returned_module = self.return_module(name) self.assertIs(returned_module, sys.modules[name]) - self.assertEqual(module.__loader__, loader) - self.assertEqual(module.__package__, name) def test_new_module_failure(self): # Test that a module is removed from sys.modules if added but an @@ -162,7 +53,7 @@ def test_reload_failure(self): # Test that a failure on reload leaves the module in-place. name = 'a.b.c' - module = types.ModuleType(name) + module = imp.new_module(name) with test_util.uncache(name): sys.modules[name] = module self.raise_exception(name) @@ -170,7 +61,7 @@ def test_decorator_attrs(self): def fxn(self, module): pass - wrapped = self.module_for_loader(fxn) + wrapped = util.module_for_loader(fxn) self.assertEqual(wrapped.__name__, fxn.__name__) self.assertEqual(wrapped.__qualname__, fxn.__qualname__) @@ -196,7 +87,7 @@ self._pkg = is_package def is_package(self, name): return self._pkg - @self.module_for_loader + @util.module_for_loader def load_module(self, module): return module @@ -233,26 +124,26 @@ def test_top_level(self): # __package__ should be set to the empty string if a top-level module. # Implicitly tests when package is set to None. - module = types.ModuleType('module') + module = imp.new_module('module') module.__package__ = None self.verify(module, '') def test_package(self): # Test setting __package__ for a package. - module = types.ModuleType('pkg') + module = imp.new_module('pkg') module.__path__ = [''] module.__package__ = None self.verify(module, 'pkg') def test_submodule(self): # Test __package__ for a module in a package. - module = types.ModuleType('pkg.mod') + module = imp.new_module('pkg.mod') module.__package__ = None self.verify(module, 'pkg') def test_setting_if_missing(self): # __package__ should be set if it is missing. - module = types.ModuleType('mod') + module = imp.new_module('mod') if hasattr(module, '__package__'): delattr(module, '__package__') self.verify(module, '') @@ -260,7 +151,7 @@ def test_leaving_alone(self): # If __package__ is set and not None then leave it alone. for value in (True, False): - module = types.ModuleType('mod') + module = imp.new_module('mod') module.__package__ = value self.verify(module, value) @@ -271,37 +162,6 @@ self.assertEqual(wrapped.__qualname__, fxn.__qualname__) -class SetLoaderTests(unittest.TestCase): - - """Tests importlib.util.set_loader().""" - - class DummyLoader: - @util.set_loader - def load_module(self, module): - return self.module - - def test_no_attribute(self): - loader = self.DummyLoader() - loader.module = types.ModuleType('blah') - try: - del loader.module.__loader__ - except AttributeError: - pass - self.assertEqual(loader, loader.load_module('blah').__loader__) - - def test_attribute_is_None(self): - loader = self.DummyLoader() - loader.module = types.ModuleType('blah') - loader.module.__loader__ = None - self.assertEqual(loader, loader.load_module('blah').__loader__) - - def test_not_reset(self): - loader = self.DummyLoader() - loader.module = types.ModuleType('blah') - loader.module.__loader__ = 42 - self.assertEqual(42, loader.load_module('blah').__loader__) - - class ResolveNameTests(unittest.TestCase): """Tests importlib.util.resolve_name().""" @@ -335,131 +195,14 @@ util.resolve_name('..bacon', 'spam') -class MagicNumberTests(unittest.TestCase): - - def test_length(self): - # Should be 4 bytes. - self.assertEqual(len(util.MAGIC_NUMBER), 4) - - def test_incorporates_rn(self): - # The magic number uses \r\n to come out wrong when splitting on lines. - self.assertTrue(util.MAGIC_NUMBER.endswith(b'\r\n')) - - -class PEP3147Tests(unittest.TestCase): - """Tests of PEP 3147-related functions: - cache_from_source and source_from_cache. - - """ - - tag = sys.implementation.cache_tag - - @unittest.skipUnless(sys.implementation.cache_tag is not None, - 'requires sys.implementation.cache_tag not be None') - def test_cache_from_source(self): - # Given the path to a .py file, return the path to its PEP 3147 - # defined .pyc file (i.e. under __pycache__). - path = os.path.join('foo', 'bar', 'baz', 'qux.py') - expect = os.path.join('foo', 'bar', 'baz', '__pycache__', - 'qux.{}.pyc'.format(self.tag)) - self.assertEqual(util.cache_from_source(path, True), expect) - - def test_cache_from_source_no_cache_tag(self): - # No cache tag means NotImplementedError. - with support.swap_attr(sys.implementation, 'cache_tag', None): - with self.assertRaises(NotImplementedError): - util.cache_from_source('whatever.py') - - def test_cache_from_source_no_dot(self): - # Directory with a dot, filename without dot. - path = os.path.join('foo.bar', 'file') - expect = os.path.join('foo.bar', '__pycache__', - 'file{}.pyc'.format(self.tag)) - self.assertEqual(util.cache_from_source(path, True), expect) - - def test_cache_from_source_optimized(self): - # Given the path to a .py file, return the path to its PEP 3147 - # defined .pyo file (i.e. under __pycache__). - path = os.path.join('foo', 'bar', 'baz', 'qux.py') - expect = os.path.join('foo', 'bar', 'baz', '__pycache__', - 'qux.{}.pyo'.format(self.tag)) - self.assertEqual(util.cache_from_source(path, False), expect) - - def test_cache_from_source_cwd(self): - path = 'foo.py' - expect = os.path.join('__pycache__', 'foo.{}.pyc'.format(self.tag)) - self.assertEqual(util.cache_from_source(path, True), expect) - - def test_cache_from_source_override(self): - # When debug_override is not None, it can be any true-ish or false-ish - # value. - path = os.path.join('foo', 'bar', 'baz.py') - partial_expect = os.path.join('foo', 'bar', '__pycache__', - 'baz.{}.py'.format(self.tag)) - self.assertEqual(util.cache_from_source(path, []), partial_expect + 'o') - self.assertEqual(util.cache_from_source(path, [17]), - partial_expect + 'c') - # However if the bool-ishness can't be determined, the exception - # propagates. - class Bearish: - def __bool__(self): raise RuntimeError - with self.assertRaises(RuntimeError): - util.cache_from_source('/foo/bar/baz.py', Bearish()) - - @unittest.skipUnless(os.sep == '\\' and os.altsep == '/', - 'test meaningful only where os.altsep is defined') - def test_sep_altsep_and_sep_cache_from_source(self): - # Windows path and PEP 3147 where sep is right of altsep. - self.assertEqual( - util.cache_from_source('\\foo\\bar\\baz/qux.py', True), - '\\foo\\bar\\baz\\__pycache__\\qux.{}.pyc'.format(self.tag)) - - @unittest.skipUnless(sys.implementation.cache_tag is not None, - 'requires sys.implementation.cache_tag to not be ' - 'None') - def test_source_from_cache(self): - # Given the path to a PEP 3147 defined .pyc file, return the path to - # its source. This tests the good path. - path = os.path.join('foo', 'bar', 'baz', '__pycache__', - 'qux.{}.pyc'.format(self.tag)) - expect = os.path.join('foo', 'bar', 'baz', 'qux.py') - self.assertEqual(util.source_from_cache(path), expect) - - def test_source_from_cache_no_cache_tag(self): - # If sys.implementation.cache_tag is None, raise NotImplementedError. - path = os.path.join('blah', '__pycache__', 'whatever.pyc') - with support.swap_attr(sys.implementation, 'cache_tag', None): - with self.assertRaises(NotImplementedError): - util.source_from_cache(path) - - def test_source_from_cache_bad_path(self): - # When the path to a pyc file is not in PEP 3147 format, a ValueError - # is raised. - self.assertRaises( - ValueError, util.source_from_cache, '/foo/bar/bazqux.pyc') - - def test_source_from_cache_no_slash(self): - # No slashes at all in path -> ValueError - self.assertRaises( - ValueError, util.source_from_cache, 'foo.cpython-32.pyc') - - def test_source_from_cache_too_few_dots(self): - # Too few dots in final path component -> ValueError - self.assertRaises( - ValueError, util.source_from_cache, '__pycache__/foo.pyc') - - def test_source_from_cache_too_many_dots(self): - # Too many dots in final path component -> ValueError - self.assertRaises( - ValueError, util.source_from_cache, - '__pycache__/foo.cpython-32.foo.pyc') - - def test_source_from_cache_no__pycache__(self): - # Another problem with the path -> ValueError - self.assertRaises( - ValueError, util.source_from_cache, - '/foo/bar/foo.cpython-32.foo.pyc') +def test_main(): + from test import support + support.run_unittest( + ModuleForLoaderTests, + SetPackageTests, + ResolveNameTests + ) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_importlib/util.py --- a/Lib/test/test_importlib/util.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_importlib/util.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,9 +1,9 @@ from contextlib import contextmanager +import imp import os.path from test import support import unittest import sys -import types CASE_INSENSITIVE_FS = True @@ -98,7 +98,7 @@ package = name.rsplit('.', 1)[0] else: package = import_name - module = types.ModuleType(import_name) + module = imp.new_module(import_name) module.__loader__ = self module.__file__ = '' module.__package__ = package diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_index.py --- a/Lib/test/test_index.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_index.py Fri Feb 01 23:12:09 2013 +0100 @@ -56,7 +56,7 @@ self.assertRaises(TypeError, slice(self.n).indices, 0) -class SeqTestCase: +class SeqTestCase(unittest.TestCase): # This test case isn't run directly. It just defines common tests # to the different sequence types below def setUp(self): @@ -126,7 +126,7 @@ self.assertRaises(TypeError, sliceobj, self.n, self) -class ListTestCase(SeqTestCase, unittest.TestCase): +class ListTestCase(SeqTestCase): seq = [0,10,20,30,40,50] def test_setdelitem(self): @@ -182,19 +182,19 @@ return self._list[index] -class TupleTestCase(SeqTestCase, unittest.TestCase): +class TupleTestCase(SeqTestCase): seq = (0,10,20,30,40,50) -class ByteArrayTestCase(SeqTestCase, unittest.TestCase): +class ByteArrayTestCase(SeqTestCase): seq = bytearray(b"this is a test") -class BytesTestCase(SeqTestCase, unittest.TestCase): +class BytesTestCase(SeqTestCase): seq = b"this is a test" -class StringTestCase(SeqTestCase, unittest.TestCase): +class StringTestCase(SeqTestCase): seq = "this is a test" -class NewSeqTestCase(SeqTestCase, unittest.TestCase): +class NewSeqTestCase(SeqTestCase): seq = NewSeq((0,10,20,30,40,50)) @@ -237,5 +237,18 @@ self.assertRaises(OverflowError, lambda: "a" * self.neg) +def test_main(): + support.run_unittest( + BaseTestCase, + ListTestCase, + TupleTestCase, + BytesTestCase, + ByteArrayTestCase, + StringTestCase, + NewSeqTestCase, + RangeTestCase, + OverflowTestCase, + ) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_inspect.py Fri Feb 01 23:12:09 2013 +0100 @@ -416,12 +416,6 @@ finally: del linecache.cache[co.co_filename] - def test_findsource_without_filename(self): - for fname in ['', '']: - co = compile('x=1', fname, "exec") - self.assertRaises(IOError, inspect.findsource, co) - self.assertRaises(IOError, inspect.getsource, co) - class TestNoEOL(GetSourceBase): def __init__(self, *args, **kwargs): self.tempdir = TESTFN + '_dir' @@ -2247,16 +2241,6 @@ with self.assertRaisesRegex(TypeError, "parameter is positional only"): self.call(test, a_po=1, b_po=2) - def test_signature_bind_with_self_arg(self): - # Issue #17071: one of the parameters is named "self - def test(a, self, b): - pass - sig = inspect.signature(test) - ba = sig.bind(1, 2, 3) - self.assertEqual(ba.args, (1, 2, 3)) - ba = sig.bind(1, self=2, b=3) - self.assertEqual(ba.args, (1, 2, 3)) - class TestBoundArguments(unittest.TestCase): def test_signature_bound_arguments_unhashable(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_int.py --- a/Lib/test/test_int.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_int.py Fri Feb 01 23:12:09 2013 +0100 @@ -260,23 +260,6 @@ with self.assertRaises(TypeError): int('0', 5.0) - def test_int_base_indexable(self): - class MyIndexable(object): - def __init__(self, value): - self.value = value - def __index__(self): - return self.value - - # Check out of range bases. - for base in 2**100, -2**100, 1, 37: - with self.assertRaises(ValueError): - int('43', base) - - # Check in-range bases. - self.assertEqual(int('101', base=MyIndexable(2)), 5) - self.assertEqual(int('101', base=MyIndexable(10)), 101) - self.assertEqual(int('101', base=MyIndexable(36)), 1 + 36**2) - def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including # subclasses of the explicitly documented accepted types. @@ -354,12 +337,6 @@ return 42 self.assertEqual(int(JustTrunc()), 42) - class ExceptionalTrunc(base): - def __trunc__(self): - 1 / 0 - with self.assertRaises(ZeroDivisionError): - int(ExceptionalTrunc()) - for trunc_result_base in (object, Classic): class Integral(trunc_result_base): def __int__(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_io.py --- a/Lib/test/test_io.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_io.py Fri Feb 01 23:12:09 2013 +0100 @@ -1080,12 +1080,6 @@ support.gc_collect() self.assertTrue(wr() is None, wr) - def test_args_error(self): - # Issue #17275 - with self.assertRaisesRegex(TypeError, "BufferedReader"): - self.tp(io.BytesIO(), 1024, 1024, 1024) - - class PyBufferedReaderTest(BufferedReaderTest): tp = pyio.BufferedReader @@ -1377,11 +1371,6 @@ with self.open(support.TESTFN, "rb") as f: self.assertEqual(f.read(), b"123xxx") - def test_args_error(self): - # Issue #17275 - with self.assertRaisesRegex(TypeError, "BufferedWriter"): - self.tp(io.BytesIO(), 1024, 1024, 1024) - class PyBufferedWriterTest(BufferedWriterTest): tp = pyio.BufferedWriter @@ -1734,7 +1723,6 @@ # You can't construct a BufferedRandom over a non-seekable stream. test_unseekable = None - class CBufferedRandomTest(BufferedRandomTest, SizeofTest): tp = io.BufferedRandom @@ -1752,12 +1740,6 @@ CBufferedReaderTest.test_garbage_collection(self) CBufferedWriterTest.test_garbage_collection(self) - def test_args_error(self): - # Issue #17275 - with self.assertRaisesRegex(TypeError, "BufferedRandom"): - self.tp(io.BytesIO(), 1024, 1024, 1024) - - class PyBufferedRandomTest(BufferedRandomTest): tp = pyio.BufferedRandom @@ -2568,30 +2550,6 @@ txt.write('5') self.assertEqual(b''.join(raw._write_stack), b'123\n45') - def test_read_nonbytes(self): - # Issue #17106 - # Crash when underlying read() returns non-bytes - t = self.TextIOWrapper(self.StringIO('a')) - self.assertRaises(TypeError, t.read, 1) - t = self.TextIOWrapper(self.StringIO('a')) - self.assertRaises(TypeError, t.readline) - t = self.TextIOWrapper(self.StringIO('a')) - self.assertRaises(TypeError, t.read) - - def test_illegal_decoder(self): - # Issue #17106 - # Crash when decoder returns non-string - t = self.TextIOWrapper(self.BytesIO(b'aaaaaa'), newline='\n', - encoding='quopri_codec') - self.assertRaises(TypeError, t.read, 1) - t = self.TextIOWrapper(self.BytesIO(b'aaaaaa'), newline='\n', - encoding='quopri_codec') - self.assertRaises(TypeError, t.readline) - t = self.TextIOWrapper(self.BytesIO(b'aaaaaa'), newline='\n', - encoding='quopri_codec') - self.assertRaises(TypeError, t.read) - - class CTextIOWrapperTest(TextIOWrapperTest): def test_initialization(self): @@ -3027,15 +2985,6 @@ class CMiscIOTest(MiscIOTest): io = io - def test_readinto_buffer_overflow(self): - # Issue #18025 - class BadReader(self.io.BufferedIOBase): - def read(self, n=-1): - return b'x' * 10**6 - bufio = BadReader() - b = bytearray(2) - self.assertRaises(ValueError, bufio.readinto, b) - class PyMiscIOTest(MiscIOTest): io = pyio @@ -3070,18 +3019,15 @@ try: wio = self.io.open(w, **fdopen_kwargs) t.start() + signal.alarm(1) # Fill the pipe enough that the write will be blocking. # It will be interrupted by the timer armed above. Since the # other thread has read one byte, the low-level write will # return with a successful (partial) result rather than an EINTR. # The buffered IO layer must check for pending signal # handlers, which in this case will invoke alarm_interrupt(). - signal.alarm(1) - try: - self.assertRaises(ZeroDivisionError, - wio.write, item * (support.PIPE_MAX_SIZE // len(item) + 1)) - finally: - signal.alarm(0) + self.assertRaises(ZeroDivisionError, + wio.write, item * (support.PIPE_MAX_SIZE // len(item))) t.join() # We got one byte, get another one and check that it isn't a # repeat of the first one. @@ -3180,7 +3126,7 @@ select = support.import_module("select") # A quantity that exceeds the buffer size of an anonymous pipe's # write end. - N = support.PIPE_MAX_SIZE + N = 1024 * 1024 r, w = os.pipe() fdopen_kwargs["closefd"] = False # We need a separate thread to read from the pipe and allow the @@ -3246,7 +3192,7 @@ test_reentrant_write_text = None -def load_tests(*args): +def test_main(): tests = (CIOTest, PyIOTest, CBufferedReaderTest, PyBufferedReaderTest, CBufferedWriterTest, PyBufferedWriterTest, @@ -3279,8 +3225,7 @@ for name, obj in py_io_ns.items(): setattr(test, name, obj) - suite = unittest.TestSuite([unittest.makeSuite(test) for test in tests]) - return suite + support.run_unittest(*tests) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ioctl.py --- a/Lib/test/test_ioctl.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ioctl.py Fri Feb 01 23:12:09 2013 +0100 @@ -86,6 +86,8 @@ os.close(mfd) os.close(sfd) +def test_main(): + run_unittest(IoctlTests) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_isinstance.py --- a/Lib/test/test_isinstance.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_isinstance.py Fri Feb 01 23:12:09 2013 +0100 @@ -15,7 +15,7 @@ # (leading to an "undetected error" in the debug build). Set up is, # isinstance(inst, cls) where: # - # - cls isn't a type, or a tuple + # - cls isn't a a type, or a tuple # - cls has a __bases__ attribute # - inst has a __class__ attribute # - inst.__class__ as no __bases__ attribute diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_iterlen.py --- a/Lib/test/test_iterlen.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_iterlen.py Fri Feb 01 23:12:09 2013 +0100 @@ -50,7 +50,7 @@ n = 10 -class TestInvariantWithoutMutations: +class TestInvariantWithoutMutations(unittest.TestCase): def test_invariant(self): it = self.it @@ -77,64 +77,64 @@ ## ------- Concrete Type Tests ------- -class TestRepeat(TestInvariantWithoutMutations, unittest.TestCase): +class TestRepeat(TestInvariantWithoutMutations): def setUp(self): self.it = repeat(None, n) -class TestXrange(TestInvariantWithoutMutations, unittest.TestCase): +class TestXrange(TestInvariantWithoutMutations): def setUp(self): self.it = iter(range(n)) -class TestXrangeCustomReversed(TestInvariantWithoutMutations, unittest.TestCase): +class TestXrangeCustomReversed(TestInvariantWithoutMutations): def setUp(self): self.it = reversed(range(n)) -class TestTuple(TestInvariantWithoutMutations, unittest.TestCase): +class TestTuple(TestInvariantWithoutMutations): def setUp(self): self.it = iter(tuple(range(n))) ## ------- Types that should not be mutated during iteration ------- -class TestDeque(TestTemporarilyImmutable, unittest.TestCase): +class TestDeque(TestTemporarilyImmutable): def setUp(self): d = deque(range(n)) self.it = iter(d) self.mutate = d.pop -class TestDequeReversed(TestTemporarilyImmutable, unittest.TestCase): +class TestDequeReversed(TestTemporarilyImmutable): def setUp(self): d = deque(range(n)) self.it = reversed(d) self.mutate = d.pop -class TestDictKeys(TestTemporarilyImmutable, unittest.TestCase): +class TestDictKeys(TestTemporarilyImmutable): def setUp(self): d = dict.fromkeys(range(n)) self.it = iter(d) self.mutate = d.popitem -class TestDictItems(TestTemporarilyImmutable, unittest.TestCase): +class TestDictItems(TestTemporarilyImmutable): def setUp(self): d = dict.fromkeys(range(n)) self.it = iter(d.items()) self.mutate = d.popitem -class TestDictValues(TestTemporarilyImmutable, unittest.TestCase): +class TestDictValues(TestTemporarilyImmutable): def setUp(self): d = dict.fromkeys(range(n)) self.it = iter(d.values()) self.mutate = d.popitem -class TestSet(TestTemporarilyImmutable, unittest.TestCase): +class TestSet(TestTemporarilyImmutable): def setUp(self): d = set(range(n)) @@ -143,7 +143,7 @@ ## ------- Types that can mutate during iteration ------- -class TestList(TestInvariantWithoutMutations, unittest.TestCase): +class TestList(TestInvariantWithoutMutations): def setUp(self): self.it = iter(range(n)) @@ -163,7 +163,7 @@ self.assertEqual(length_hint(it), 0) -class TestListReversed(TestInvariantWithoutMutations, unittest.TestCase): +class TestListReversed(TestInvariantWithoutMutations): def setUp(self): self.it = reversed(range(n)) @@ -225,5 +225,23 @@ self.assertEqual(list(NoneLengthHint()), list(range(10))) +def test_main(): + unittests = [ + TestRepeat, + TestXrange, + TestXrangeCustomReversed, + TestTuple, + TestDeque, + TestDequeReversed, + TestDictKeys, + TestDictItems, + TestDictValues, + TestSet, + TestList, + TestListReversed, + TestLengthHintExceptions, + ] + support.run_unittest(*unittests) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_itertools.py --- a/Lib/test/test_itertools.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_itertools.py Fri Feb 01 23:12:09 2013 +0100 @@ -1267,12 +1267,6 @@ self.pickletest(a, compare=ans) self.pickletest(b, compare=ans) - # Issue 13454: Crash when deleting backward iterator from tee() - def test_tee_del_backward(self): - forward, backward = tee(repeat(None, 20000000)) - any(forward) # exhaust the iterator - del backward - def test_StopIteration(self): self.assertRaises(StopIteration, next, zip()) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_keyword.py --- a/Lib/test/test_keyword.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -import keyword -import unittest -from test import support -import filecmp -import os -import sys -import subprocess -import shutil -import textwrap - -KEYWORD_FILE = support.findfile('keyword.py') -GRAMMAR_FILE = os.path.join(os.path.split(__file__)[0], - '..', '..', 'Python', 'graminit.c') -TEST_PY_FILE = 'keyword_test.py' -GRAMMAR_TEST_FILE = 'graminit_test.c' -PY_FILE_WITHOUT_KEYWORDS = 'minimal_keyword.py' -NONEXISTENT_FILE = 'not_here.txt' - - -class Test_iskeyword(unittest.TestCase): - def test_true_is_a_keyword(self): - self.assertTrue(keyword.iskeyword('True')) - - def test_uppercase_true_is_not_a_keyword(self): - self.assertFalse(keyword.iskeyword('TRUE')) - - def test_none_value_is_not_a_keyword(self): - self.assertFalse(keyword.iskeyword(None)) - - # This is probably an accident of the current implementation, but should be - # preserved for backward compatibility. - def test_changing_the_kwlist_does_not_affect_iskeyword(self): - oldlist = keyword.kwlist - self.addCleanup(setattr, keyword, 'kwlist', oldlist) - keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice'] - self.assertFalse(keyword.iskeyword('eggs')) - - -class TestKeywordGeneration(unittest.TestCase): - - def _copy_file_without_generated_keywords(self, source_file, dest_file): - with open(source_file, 'rb') as fp: - lines = fp.readlines() - nl = lines[0][len(lines[0].strip()):] - with open(dest_file, 'wb') as fp: - fp.writelines(lines[:lines.index(b"#--start keywords--" + nl) + 1]) - fp.writelines(lines[lines.index(b"#--end keywords--" + nl):]) - - def _generate_keywords(self, grammar_file, target_keyword_py_file): - proc = subprocess.Popen([sys.executable, - KEYWORD_FILE, - grammar_file, - target_keyword_py_file], stderr=subprocess.PIPE) - stderr = proc.communicate()[1] - return proc.returncode, stderr - - @unittest.skipIf(not os.path.exists(GRAMMAR_FILE), - 'test only works from source build directory') - def test_real_grammar_and_keyword_file(self): - self._copy_file_without_generated_keywords(KEYWORD_FILE, TEST_PY_FILE) - self.addCleanup(support.unlink, TEST_PY_FILE) - self.assertFalse(filecmp.cmp(KEYWORD_FILE, TEST_PY_FILE)) - self.assertEqual((0, b''), self._generate_keywords(GRAMMAR_FILE, - TEST_PY_FILE)) - self.assertTrue(filecmp.cmp(KEYWORD_FILE, TEST_PY_FILE)) - - def test_grammar(self): - self._copy_file_without_generated_keywords(KEYWORD_FILE, TEST_PY_FILE) - self.addCleanup(support.unlink, TEST_PY_FILE) - with open(GRAMMAR_TEST_FILE, 'w') as fp: - # Some of these are probably implementation accidents. - fp.writelines(textwrap.dedent("""\ - {2, 1}, - {11, "encoding_decl", 0, 2, states_79, - "\000\000\040\000\000\000\000\000\000\000\000\000" - "\000\000\000\000\000\000\000\000\000"}, - {1, "jello"}, - {326, 0}, - {1, "turnip"}, - \t{1, "This one is tab indented" - {278, 0}, - {1, "crazy but legal" - "also legal" {1, " - {1, "continue"}, - {1, "lemon"}, - {1, "tomato"}, - {1, "wigii"}, - {1, 'no good'} - {283, 0}, - {1, "too many spaces"}""")) - self.addCleanup(support.unlink, GRAMMAR_TEST_FILE) - self._generate_keywords(GRAMMAR_TEST_FILE, TEST_PY_FILE) - expected = [ - " 'This one is tab indented',", - " 'also legal',", - " 'continue',", - " 'crazy but legal',", - " 'jello',", - " 'lemon',", - " 'tomato',", - " 'turnip',", - " 'wigii',", - ] - with open(TEST_PY_FILE) as fp: - lines = fp.read().splitlines() - start = lines.index("#--start keywords--") + 1 - end = lines.index("#--end keywords--") - actual = lines[start:end] - self.assertEqual(actual, expected) - - def test_empty_grammar_results_in_no_keywords(self): - self._copy_file_without_generated_keywords(KEYWORD_FILE, - PY_FILE_WITHOUT_KEYWORDS) - self.addCleanup(support.unlink, PY_FILE_WITHOUT_KEYWORDS) - shutil.copyfile(KEYWORD_FILE, TEST_PY_FILE) - self.addCleanup(support.unlink, TEST_PY_FILE) - self.assertEqual((0, b''), self._generate_keywords(os.devnull, - TEST_PY_FILE)) - self.assertTrue(filecmp.cmp(TEST_PY_FILE, PY_FILE_WITHOUT_KEYWORDS)) - - def test_keywords_py_without_markers_produces_error(self): - rc, stderr = self._generate_keywords(os.devnull, os.devnull) - self.assertNotEqual(rc, 0) - self.assertRegex(stderr, b'does not contain format markers') - - def test_missing_grammar_file_produces_error(self): - rc, stderr = self._generate_keywords(NONEXISTENT_FILE, KEYWORD_FILE) - self.assertNotEqual(rc, 0) - self.assertRegex(stderr, b'(?ms)' + NONEXISTENT_FILE.encode()) - - def test_missing_keywords_py_file_produces_error(self): - rc, stderr = self._generate_keywords(os.devnull, NONEXISTENT_FILE) - self.assertNotEqual(rc, 0) - self.assertRegex(stderr, b'(?ms)' + NONEXISTENT_FILE.encode()) - - -if __name__ == "__main__": - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_keywordonlyarg.py --- a/Lib/test/test_keywordonlyarg.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_keywordonlyarg.py Fri Feb 01 23:12:09 2013 +0100 @@ -176,18 +176,6 @@ return __a self.assertEqual(X().f(), 42) - def test_default_evaluation_order(self): - # See issue 16967 - a = 42 - with self.assertRaises(NameError) as err: - def f(v=a, x=b, *, y=c, z=d): - pass - self.assertEqual(str(err.exception), "name 'b' is not defined") - with self.assertRaises(NameError) as err: - f = lambda v=a, x=b, *, y=c, z=d: None - self.assertEqual(str(err.exception), "name 'b' is not defined") - - def test_main(): run_unittest(KeywordOnlyArgTestCase) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_kqueue.py --- a/Lib/test/test_kqueue.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_kqueue.py Fri Feb 01 23:12:09 2013 +0100 @@ -101,6 +101,11 @@ pass # FreeBSD doesn't raise an exception here server, addr = serverSocket.accept() + if sys.platform.startswith("darwin"): + flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE + else: + flags = 0 + kq = select.kqueue() kq2 = select.kqueue.fromfd(kq.fileno()) @@ -122,10 +127,11 @@ kq2.control([ev], 0) events = kq.control(None, 4, 1) - events = set((e.ident, e.filter) for e in events) - self.assertEqual(events, set([ - (client.fileno(), select.KQ_FILTER_WRITE), - (server.fileno(), select.KQ_FILTER_WRITE)])) + events = [(e.ident, e.filter, e.flags) for e in events] + events.sort() + self.assertEqual(events, [ + (client.fileno(), select.KQ_FILTER_WRITE, flags), + (server.fileno(), select.KQ_FILTER_WRITE, flags)]) client.send(b"Hello!") server.send(b"world!!!") @@ -139,12 +145,14 @@ else: self.fail('timeout waiting for event notifications') - events = set((e.ident, e.filter) for e in events) - self.assertEqual(events, set([ - (client.fileno(), select.KQ_FILTER_WRITE), - (client.fileno(), select.KQ_FILTER_READ), - (server.fileno(), select.KQ_FILTER_WRITE), - (server.fileno(), select.KQ_FILTER_READ)])) + events = [(e.ident, e.filter, e.flags) for e in events] + events.sort() + + self.assertEqual(events, [ + (client.fileno(), select.KQ_FILTER_WRITE, flags), + (client.fileno(), select.KQ_FILTER_READ, flags), + (server.fileno(), select.KQ_FILTER_WRITE, flags), + (server.fileno(), select.KQ_FILTER_READ, flags)]) # Remove completely client, and server read part ev = select.kevent(client.fileno(), @@ -161,9 +169,10 @@ kq.control([ev], 0, 0) events = kq.control([], 4, 0.99) - events = set((e.ident, e.filter) for e in events) - self.assertEqual(events, set([ - (server.fileno(), select.KQ_FILTER_WRITE)])) + events = [(e.ident, e.filter, e.flags) for e in events] + events.sort() + self.assertEqual(events, [ + (server.fileno(), select.KQ_FILTER_WRITE, flags)]) client.close() server.close() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_largefile.py --- a/Lib/test/test_largefile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_largefile.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,50 +5,55 @@ import stat import sys import unittest -from test.support import TESTFN, requires, unlink +from test.support import run_unittest, TESTFN, verbose, requires, \ + unlink import io # C implementation of io import _pyio as pyio # Python implementation of io -# size of file to create (>2GB; 2GB == 2147483648 bytes) +try: + import signal + # The default handler for SIGXFSZ is to abort the process. + # By ignoring it, system calls exceeding the file size resource + # limit will raise OSError instead of crashing the interpreter. + oldhandler = signal.signal(signal.SIGXFSZ, signal.SIG_IGN) +except (ImportError, AttributeError): + pass + +# create >2GB file (2GB = 2147483648 bytes) size = 2500000000 -class LargeFileTest: - """Test that each file function works as expected for large - (i.e. > 2GB) files. + +class LargeFileTest(unittest.TestCase): + """Test that each file function works as expected for a large + (i.e. > 2GB, do we have to check > 4GB) files. + + NOTE: the order of execution of the test methods is important! test_seek + must run first to create the test file. File cleanup must also be handled + outside the test instances because of this. + """ - def setUp(self): - if os.path.exists(TESTFN): - mode = 'r+b' - else: - mode = 'w+b' - - with self.open(TESTFN, mode) as f: - current_size = os.fstat(f.fileno())[stat.ST_SIZE] - if current_size == size+1: - return - - if current_size == 0: - f.write(b'z') - + def test_seek(self): + if verbose: + print('create large file via seek (may be sparse file) ...') + with self.open(TESTFN, 'wb') as f: + f.write(b'z') f.seek(0) f.seek(size) f.write(b'a') f.flush() + if verbose: + print('check file size with os.fstat') self.assertEqual(os.fstat(f.fileno())[stat.ST_SIZE], size+1) - @classmethod - def tearDownClass(cls): - with cls.open(TESTFN, 'wb'): - pass - if not os.stat(TESTFN)[stat.ST_SIZE] == 0: - raise cls.failureException('File was not truncated by opening ' - 'with mode "wb"') - def test_osstat(self): + if verbose: + print('check file size with os.stat') self.assertEqual(os.stat(TESTFN)[stat.ST_SIZE], size+1) def test_seek_read(self): + if verbose: + print('play around with seek() and read() with the built largefile') with self.open(TESTFN, 'rb') as f: self.assertEqual(f.tell(), 0) self.assertEqual(f.read(1), b'z') @@ -80,6 +85,8 @@ self.assertEqual(f.tell(), 1) def test_lseek(self): + if verbose: + print('play around with os.lseek() with the built largefile') with self.open(TESTFN, 'rb') as f: self.assertEqual(os.lseek(f.fileno(), 0, 0), 0) self.assertEqual(os.lseek(f.fileno(), 42, 0), 42) @@ -93,10 +100,13 @@ self.assertEqual(f.read(1), b'a') def test_truncate(self): + if verbose: + print('try truncate') with self.open(TESTFN, 'r+b') as f: + # this is already decided before start running the test suite + # but we do it anyway for extra protection if not hasattr(f, 'truncate'): - raise unittest.SkipTest("open().truncate() not available " - "on this system") + raise unittest.SkipTest("open().truncate() not available on this system") f.seek(0, 2) # else we've lost track of the true size self.assertEqual(f.tell(), size+1) @@ -131,16 +141,8 @@ f.seek(pos) self.assertTrue(f.seekable()) -def setUpModule(): - try: - import signal - # The default handler for SIGXFSZ is to abort the process. - # By ignoring it, system calls exceeding the file size resource - # limit will raise OSError instead of crashing the interpreter. - signal.signal(signal.SIGXFSZ, signal.SIG_IGN) - except (ImportError, AttributeError): - pass +def test_main(): # On Windows and Mac OSX this test comsumes large resources; It # takes a long time to build the >2GB file and takes >2GB of disk # space therefore the resource must be enabled to run this test. @@ -156,25 +158,35 @@ try: # 2**31 == 2147483648 f.seek(2147483649) - # Seeking is not enough of a test: you must write and flush, too! + # Seeking is not enough of a test: you must write and + # flush, too! f.write(b'x') f.flush() except (OSError, OverflowError): - raise unittest.SkipTest("filesystem does not have " - "largefile support") - finally: f.close() unlink(TESTFN) - - -class CLargeFileTest(LargeFileTest, unittest.TestCase): - open = staticmethod(io.open) - -class PyLargeFileTest(LargeFileTest, unittest.TestCase): - open = staticmethod(pyio.open) - -def tearDownModule(): - unlink(TESTFN) + raise unittest.SkipTest("filesystem does not have largefile support") + else: + f.close() + suite = unittest.TestSuite() + for _open, prefix in [(io.open, 'C'), (pyio.open, 'Py')]: + class TestCase(LargeFileTest): + pass + TestCase.open = staticmethod(_open) + TestCase.__name__ = prefix + LargeFileTest.__name__ + suite.addTest(TestCase('test_seek')) + suite.addTest(TestCase('test_osstat')) + suite.addTest(TestCase('test_seek_read')) + suite.addTest(TestCase('test_lseek')) + with _open(TESTFN, 'wb') as f: + if hasattr(f, 'truncate'): + suite.addTest(TestCase('test_truncate')) + suite.addTest(TestCase('test_seekable')) + unlink(TESTFN) + try: + run_unittest(suite) + finally: + unlink(TESTFN) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_locale.py --- a/Lib/test/test_locale.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_locale.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,50 +1,52 @@ -from test.support import verbose +from test.support import run_unittest, verbose import unittest import locale import sys import codecs +enUS_locale = None + +def get_enUS_locale(): + global enUS_locale + if sys.platform == 'darwin': + import os + tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US") + if int(os.uname().release.split('.')[0]) < 10: + # The locale test work fine on OSX 10.6, I (ronaldoussoren) + # haven't had time yet to verify if tests work on OSX 10.5 + # (10.4 is known to be bad) + raise unittest.SkipTest("Locale support on MacOSX is minimal") + elif sys.platform.startswith("win"): + tlocs = ("En", "English") + else: + tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US.US-ASCII", "en_US") + oldlocale = locale.setlocale(locale.LC_NUMERIC) + for tloc in tlocs: + try: + locale.setlocale(locale.LC_NUMERIC, tloc) + except locale.Error: + continue + break + else: + raise unittest.SkipTest( + "Test locale not supported (tried %s)" % (', '.join(tlocs))) + enUS_locale = tloc + locale.setlocale(locale.LC_NUMERIC, oldlocale) + + class BaseLocalizedTest(unittest.TestCase): # # Base class for tests using a real locale # - @classmethod - def setUpClass(cls): - if sys.platform == 'darwin': - import os - tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US") - if int(os.uname().release.split('.')[0]) < 10: - # The locale test work fine on OSX 10.6, I (ronaldoussoren) - # haven't had time yet to verify if tests work on OSX 10.5 - # (10.4 is known to be bad) - raise unittest.SkipTest("Locale support on MacOSX is minimal") - elif sys.platform.startswith("win"): - tlocs = ("En", "English") - else: - tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", - "en_US.US-ASCII", "en_US") - try: - oldlocale = locale.setlocale(locale.LC_NUMERIC) - for tloc in tlocs: - try: - locale.setlocale(locale.LC_NUMERIC, tloc) - except locale.Error: - continue - break - else: - raise unittest.SkipTest("Test locale not supported " - "(tried %s)" % (', '.join(tlocs))) - cls.enUS_locale = tloc - finally: - locale.setlocale(locale.LC_NUMERIC, oldlocale) + def setUp(self): + self.oldlocale = locale.setlocale(self.locale_type) + locale.setlocale(self.locale_type, enUS_locale) + if verbose: + print("testing with \"%s\"..." % enUS_locale, end=' ') - def setUp(self): - oldlocale = locale.setlocale(self.locale_type) - self.addCleanup(locale.setlocale, self.locale_type, oldlocale) - locale.setlocale(self.locale_type, self.enUS_locale) - if verbose: - print("testing with %r..." % self.enUS_locale, end=' ', flush=True) + def tearDown(self): + locale.setlocale(self.locale_type, self.oldlocale) class BaseCookedTest(unittest.TestCase): @@ -413,5 +415,25 @@ locale.setlocale(locale.LC_ALL, (b'not', b'valid')) +def test_main(): + tests = [ + TestMiscellaneous, + TestFormatPatternArg, + TestLocaleFormatString, + TestEnUSNumberFormatting, + TestCNumberFormatting, + TestFrFRNumberFormatting, + TestCollation + ] + # SkipTest can't be raised inside unittests, handle it manually instead + try: + get_enUS_locale() + except unittest.SkipTest as e: + if verbose: + print("Some tests will be disabled: %s" % e) + else: + tests += [TestNumberFormatting, TestEnUSCollation] + run_unittest(*tests) + if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_logging.py --- a/Lib/test/test_logging.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_logging.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -18,7 +18,7 @@ """Test harness for the logging module. Run all tests. -Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved. """ import logging @@ -94,8 +94,7 @@ self.saved_handlers = logging._handlers.copy() self.saved_handler_list = logging._handlerList[:] self.saved_loggers = saved_loggers = logger_dict.copy() - self.saved_name_to_level = logging._nameToLevel.copy() - self.saved_level_to_name = logging._levelToName.copy() + self.saved_level_names = logging._levelNames.copy() self.logger_states = logger_states = {} for name in saved_loggers: logger_states[name] = getattr(saved_loggers[name], @@ -137,10 +136,8 @@ self.root_logger.setLevel(self.original_logging_level) logging._acquireLock() try: - logging._levelToName.clear() - logging._levelToName.update(self.saved_level_to_name) - logging._nameToLevel.clear() - logging._nameToLevel.update(self.saved_name_to_level) + logging._levelNames.clear() + logging._levelNames.update(self.saved_level_names) logging._handlers.clear() logging._handlers.update(self.saved_handlers) logging._handlerList[:] = self.saved_handler_list @@ -659,6 +656,41 @@ # -- if it proves to be of wider utility than just test_logging if threading: + class TestSMTPChannel(smtpd.SMTPChannel): + """ + This derived class has had to be created because smtpd does not + support use of custom channel maps, although they are allowed by + asyncore's design. Issue #11959 has been raised to address this, + and if resolved satisfactorily, some of this code can be removed. + """ + def __init__(self, server, conn, addr, sockmap): + asynchat.async_chat.__init__(self, conn, sockmap) + self.smtp_server = server + self.conn = conn + self.addr = addr + self.data_size_limit = None + self.received_lines = [] + self.smtp_state = self.COMMAND + self.seen_greeting = '' + self.mailfrom = None + self.rcpttos = [] + self.received_data = '' + self.fqdn = socket.getfqdn() + self.num_bytes = 0 + try: + self.peer = conn.getpeername() + except OSError as err: + # a race condition may occur if the other end is closing + # before we can get the peername + self.close() + if err.args[0] != errno.ENOTCONN: + raise + return + self.push('220 %s %s' % (self.fqdn, smtpd.__version__)) + self.set_terminator(b'\r\n') + self.extended_smtp = False + + class TestSMTPServer(smtpd.SMTPServer): """ This class implements a test SMTP server. @@ -679,14 +711,37 @@ :func:`asyncore.loop`. This avoids changing the :mod:`asyncore` module's global state. """ + channel_class = TestSMTPChannel def __init__(self, addr, handler, poll_interval, sockmap): - smtpd.SMTPServer.__init__(self, addr, None, map=sockmap) - self.port = self.socket.getsockname()[1] + self._localaddr = addr + self._remoteaddr = None + self.data_size_limit = None + self.sockmap = sockmap + asyncore.dispatcher.__init__(self, map=sockmap) + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setblocking(0) + self.set_socket(sock, map=sockmap) + # try to re-use a server port if possible + self.set_reuse_addr() + self.bind(addr) + self.port = sock.getsockname()[1] + self.listen(5) + except: + self.close() + raise self._handler = handler self._thread = None self.poll_interval = poll_interval + def handle_accepted(self, conn, addr): + """ + Redefined only because the base class does not pass in a + map, forcing use of a global in :mod:`asyncore`. + """ + channel = self.channel_class(self, conn, addr, self.sockmap) + def process_message(self, peer, mailfrom, rcpttos, data): """ Delegates to the handler passed in to the server's constructor. @@ -717,7 +772,7 @@ :func:`asyncore.loop`. """ try: - asyncore.loop(poll_interval, map=self._map) + asyncore.loop(poll_interval, map=self.sockmap) except OSError: # On FreeBSD 8, closing the server repeatably # raises this error. We swallow it if the @@ -1206,30 +1261,9 @@ datefmt= """ - disable_test = """ - [loggers] - keys=root - - [handlers] - keys=screen - - [formatters] - keys= - - [logger_root] - level=DEBUG - handlers=screen - - [handler_screen] - level=DEBUG - class=StreamHandler - args=(sys.stdout,) - formatter= - """ - - def apply_config(self, conf, **kwargs): + def apply_config(self, conf): file = io.StringIO(textwrap.dedent(conf)) - logging.config.fileConfig(file, **kwargs) + logging.config.fileConfig(file) def test_config0_ok(self): # A simple config file which overrides the default settings. @@ -1351,15 +1385,6 @@ # Original logger output is empty. self.assert_log_lines([]) - def test_logger_disabling(self): - self.apply_config(self.disable_test) - logger = logging.getLogger('foo') - self.assertFalse(logger.disabled) - self.apply_config(self.disable_test) - self.assertTrue(logger.disabled) - self.apply_config(self.disable_test, disable_existing_loggers=False) - self.assertFalse(logger.disabled) - @unittest.skipUnless(threading, 'Threading required for this test.') class SocketHandlerTest(BaseTest): @@ -2390,37 +2415,6 @@ }, } - out_of_order = { - "version": 1, - "formatters": { - "mySimpleFormatter": { - "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s", - "style": "$" - } - }, - "handlers": { - "fileGlobal": { - "class": "logging.StreamHandler", - "level": "DEBUG", - "formatter": "mySimpleFormatter" - }, - "bufferGlobal": { - "class": "logging.handlers.MemoryHandler", - "capacity": 5, - "formatter": "mySimpleFormatter", - "target": "fileGlobal", - "level": "DEBUG" - } - }, - "loggers": { - "mymodule": { - "level": "DEBUG", - "handlers": ["bufferGlobal"], - "propagate": "true" - } - } - } - def apply_config(self, conf): logging.config.dictConfig(conf) @@ -2793,13 +2787,6 @@ ('ERROR', '2'), ], pat=r"^[\w.]+ -> (\w+): (\d+)$") - def test_out_of_order(self): - self.apply_config(self.out_of_order) - handler = logging.getLogger('mymodule').handlers[0] - self.assertIsInstance(handler.target, logging.Handler) - self.assertIsInstance(handler.formatter._style, - logging.StringTemplateStyle) - def test_baseconfig(self): d = { 'atuple': (1, 2, 3), @@ -3409,12 +3396,6 @@ self.assertEqual(logging.root.level, self.original_logging_level) def test_filename(self): - - def cleanup(h1, h2, fn): - h1.close() - h2.close() - os.remove(fn) - logging.basicConfig(filename='test.log') self.assertEqual(len(logging.root.handlers), 1) @@ -3422,23 +3403,17 @@ self.assertIsInstance(handler, logging.FileHandler) expected = logging.FileHandler('test.log', 'a') + self.addCleanup(expected.close) self.assertEqual(handler.stream.mode, expected.stream.mode) self.assertEqual(handler.stream.name, expected.stream.name) - self.addCleanup(cleanup, handler, expected, 'test.log') def test_filemode(self): - - def cleanup(h1, h2, fn): - h1.close() - h2.close() - os.remove(fn) - logging.basicConfig(filename='test.log', filemode='wb') handler = logging.root.handlers[0] expected = logging.FileHandler('test.log', 'wb') + self.addCleanup(expected.close) self.assertEqual(handler.stream.mode, expected.stream.mode) - self.addCleanup(cleanup, handler, expected, 'test.log') def test_stream(self): stream = io.StringIO() @@ -3894,63 +3869,6 @@ assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler, self.fn, 'W7', delay=True) - def test_compute_rollover_daily_attime(self): - currentTime = 0 - atTime = datetime.time(12, 0, 0) - rh = logging.handlers.TimedRotatingFileHandler( - self.fn, when='MIDNIGHT', interval=1, backupCount=0, utc=True, - atTime=atTime) - try: - actual = rh.computeRollover(currentTime) - self.assertEqual(actual, currentTime + 12 * 60 * 60) - - actual = rh.computeRollover(currentTime + 13 * 60 * 60) - self.assertEqual(actual, currentTime + 36 * 60 * 60) - finally: - rh.close() - - #@unittest.skipIf(True, 'Temporarily skipped while failures investigated.') - def test_compute_rollover_weekly_attime(self): - currentTime = int(time.time()) - today = currentTime - currentTime % 86400 - - atTime = datetime.time(12, 0, 0) - - wday = time.gmtime(today).tm_wday - for day in range(7): - rh = logging.handlers.TimedRotatingFileHandler( - self.fn, when='W%d' % day, interval=1, backupCount=0, utc=True, - atTime=atTime) - try: - if wday > day: - # The rollover day has already passed this week, so we - # go over into next week - expected = (7 - wday + day) - else: - expected = (day - wday) - # At this point expected is in days from now, convert to seconds - expected *= 24 * 60 * 60 - # Add in the rollover time - expected += 12 * 60 * 60 - # Add in adjustment for today - expected += today - actual = rh.computeRollover(today) - if actual != expected: - print('failed in timezone: %d' % time.timezone) - print('local vars: %s' % locals()) - self.assertEqual(actual, expected) - if day == wday: - # goes into following week - expected += 7 * 24 * 60 * 60 - actual = rh.computeRollover(today + 13 * 60 * 60) - if actual != expected: - print('failed in timezone: %d' % time.timezone) - print('local vars: %s' % locals()) - self.assertEqual(actual, expected) - finally: - rh.close() - - def secs(**kw): return datetime.timedelta(**kw) // datetime.timedelta(seconds=1) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_long.py --- a/Lib/test/test_long.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_long.py Fri Feb 01 23:12:09 2013 +0100 @@ -1086,7 +1086,7 @@ self.assertRaises(OverflowError, (256).to_bytes, 1, 'big', signed=True) self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=False) self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=True) - self.assertRaises(OverflowError, (-1).to_bytes, 2, 'big', signed=False) + self.assertRaises(OverflowError, (-1).to_bytes, 2, 'big', signed=False), self.assertRaises(OverflowError, (-1).to_bytes, 2, 'little', signed=False) self.assertEqual((0).to_bytes(0, 'big'), b'') self.assertEqual((1).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x01') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_lzma.py --- a/Lib/test/test_lzma.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_lzma.py Fri Feb 01 23:12:09 2013 +0100 @@ -669,20 +669,6 @@ with LZMAFile(BytesIO(COMPRESSED_XZ[:128])) as f: self.assertRaises(EOFError, f.read) - def test_read_truncated(self): - # Drop stream footer: CRC (4 bytes), index size (4 bytes), - # flags (2 bytes) and magic number (2 bytes). - truncated = COMPRESSED_XZ[:-12] - with LZMAFile(BytesIO(truncated)) as f: - self.assertRaises(EOFError, f.read) - with LZMAFile(BytesIO(truncated)) as f: - self.assertEqual(f.read(len(INPUT)), INPUT) - self.assertRaises(EOFError, f.read, 1) - # Incomplete 12-byte header. - for i in range(12): - with LZMAFile(BytesIO(truncated[:i])) as f: - self.assertRaises(EOFError, f.read, 1) - def test_read_bad_args(self): f = LZMAFile(BytesIO(COMPRESSED_XZ)) f.close() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_mailbox.py Fri Feb 01 23:12:09 2013 +0100 @@ -43,9 +43,9 @@ def _delete_recursively(self, target): # Delete a file or delete a directory recursively if os.path.isdir(target): - support.rmtree(target) + shutil.rmtree(target) elif os.path.exists(target): - support.unlink(target) + os.remove(target) class TestMailbox(TestBase): @@ -2112,9 +2112,9 @@ # create a new maildir mailbox to work with: self._dir = support.TESTFN if os.path.isdir(self._dir): - support.rmtree(self._dir) + shutil.rmtree(self._dir) elif os.path.isfile(self._dir): - support.unlink(self._dir) + os.unlink(self._dir) os.mkdir(self._dir) os.mkdir(os.path.join(self._dir, "cur")) os.mkdir(os.path.join(self._dir, "tmp")) @@ -2124,10 +2124,10 @@ def tearDown(self): list(map(os.unlink, self._msgfiles)) - support.rmdir(os.path.join(self._dir, "cur")) - support.rmdir(os.path.join(self._dir, "tmp")) - support.rmdir(os.path.join(self._dir, "new")) - support.rmdir(self._dir) + os.rmdir(os.path.join(self._dir, "cur")) + os.rmdir(os.path.join(self._dir, "tmp")) + os.rmdir(os.path.join(self._dir, "new")) + os.rmdir(self._dir) def createMessage(self, dir, mbox=False): t = int(time.time() % 1000000) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_marshal.py --- a/Lib/test/test_marshal.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_marshal.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,7 +2,6 @@ from test import support import array -import io import marshal import sys import unittest @@ -24,13 +23,37 @@ class IntTestCase(unittest.TestCase, HelperMixin): def test_ints(self): - # Test a range of Python ints larger than the machine word size. - n = sys.maxsize ** 2 + # Test the full range of Python ints. + n = sys.maxsize while n: for expected in (-n, n): self.helper(expected) n = n >> 1 + def test_int64(self): + # Simulate int marshaling on a 64-bit box. This is most interesting if + # we're running the test on a 32-bit box, of course. + + def to_little_endian_string(value, nbytes): + b = bytearray() + for i in range(nbytes): + b.append(value & 0xff) + value >>= 8 + return b + + maxint64 = (1 << 63) - 1 + minint64 = -maxint64-1 + + for base in maxint64, minint64, -maxint64, -(minint64 >> 1): + while base: + s = b'I' + to_little_endian_string(base, 8) + got = marshal.loads(s) + self.assertEqual(base, got) + if base == -1: # a fixed-point for shifting right 1 + base = 0 + else: + base >>= 1 + def test_bool(self): for b in (True, False): self.helper(b) @@ -177,14 +200,10 @@ except Exception: pass - def test_loads_2x_code(self): + def test_loads_recursion(self): s = b'c' + (b'X' * 4*4) + b'{' * 2**20 self.assertRaises(ValueError, marshal.loads, s) - def test_loads_recursion(self): - s = b'c' + (b'X' * 4*5) + b'{' * 2**20 - self.assertRaises(ValueError, marshal.loads, s) - def test_recursion_limit(self): # Create a deeply nested structure. head = last = [] @@ -260,194 +279,16 @@ unicode_string = 'T' self.assertRaises(TypeError, marshal.loads, unicode_string) - def test_bad_reader(self): - class BadReader(io.BytesIO): - def read(self, n=-1): - b = super().read(n) - if n is not None and n > 4: - b += b' ' * 10**6 - return b - for value in (1.0, 1j, b'0123456789', '0123456789'): - self.assertRaises(ValueError, marshal.load, - BadReader(marshal.dumps(value))) - - def _test_eof(self): - data = marshal.dumps(("hello", "dolly", None)) - for i in range(len(data)): - self.assertRaises(EOFError, marshal.loads, data[0: i]) - -LARGE_SIZE = 2**31 -pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4 - -class NullWriter: - def write(self, s): - pass - -@unittest.skipIf(LARGE_SIZE > sys.maxsize, "test cannot run on 32-bit systems") -class LargeValuesTestCase(unittest.TestCase): - def check_unmarshallable(self, data): - self.assertRaises(ValueError, marshal.dump, data, NullWriter()) - - @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False) - def test_bytes(self, size): - self.check_unmarshallable(b'x' * size) - - @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False) - def test_str(self, size): - self.check_unmarshallable('x' * size) - - @support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False) - def test_tuple(self, size): - self.check_unmarshallable((None,) * size) - - @support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False) - def test_list(self, size): - self.check_unmarshallable([None] * size) - - @support.bigmemtest(size=LARGE_SIZE, - memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1), - dry_run=False) - def test_set(self, size): - self.check_unmarshallable(set(range(size))) - - @support.bigmemtest(size=LARGE_SIZE, - memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1), - dry_run=False) - def test_frozenset(self, size): - self.check_unmarshallable(frozenset(range(size))) - - @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False) - def test_bytearray(self, size): - self.check_unmarshallable(bytearray(size)) - -def CollectObjectIDs(ids, obj): - """Collect object ids seen in a structure""" - if id(obj) in ids: - return - ids.add(id(obj)) - if isinstance(obj, (list, tuple, set, frozenset)): - for e in obj: - CollectObjectIDs(ids, e) - elif isinstance(obj, dict): - for k, v in obj.items(): - CollectObjectIDs(ids, k) - CollectObjectIDs(ids, v) - return len(ids) - -class InstancingTestCase(unittest.TestCase, HelperMixin): - intobj = 123321 - floatobj = 1.2345 - strobj = "abcde"*3 - dictobj = {"hello":floatobj, "goodbye":floatobj, floatobj:"hello"} - - def helper3(self, rsample, recursive=False, simple=False): - #we have two instances - sample = (rsample, rsample) - - n0 = CollectObjectIDs(set(), sample) - - s3 = marshal.dumps(sample, 3) - n3 = CollectObjectIDs(set(), marshal.loads(s3)) - - #same number of instances generated - self.assertEqual(n3, n0) - - if not recursive: - #can compare with version 2 - s2 = marshal.dumps(sample, 2) - n2 = CollectObjectIDs(set(), marshal.loads(s2)) - #old format generated more instances - self.assertGreater(n2, n0) - - #if complex objects are in there, old format is larger - if not simple: - self.assertGreater(len(s2), len(s3)) - else: - self.assertGreaterEqual(len(s2), len(s3)) - - def testInt(self): - self.helper(self.intobj) - self.helper3(self.intobj, simple=True) - - def testFloat(self): - self.helper(self.floatobj) - self.helper3(self.floatobj) - - def testStr(self): - self.helper(self.strobj) - self.helper3(self.strobj) - - def testDict(self): - self.helper(self.dictobj) - self.helper3(self.dictobj) - - def testModule(self): - with open(__file__, "rb") as f: - code = f.read() - if __file__.endswith(".py"): - code = compile(code, __file__, "exec") - self.helper(code) - self.helper3(code) - - def testRecursion(self): - d = dict(self.dictobj) - d["self"] = d - self.helper3(d, recursive=True) - l = [self.dictobj] - l.append(l) - self.helper3(l, recursive=True) - -class CompatibilityTestCase(unittest.TestCase): - def _test(self, version): - with open(__file__, "rb") as f: - code = f.read() - if __file__.endswith(".py"): - code = compile(code, __file__, "exec") - data = marshal.dumps(code, version) - marshal.loads(data) - - def test0To3(self): - self._test(0) - - def test1To3(self): - self._test(1) - - def test2To3(self): - self._test(2) - - def test3To3(self): - self._test(3) - -class InterningTestCase(unittest.TestCase, HelperMixin): - strobj = "this is an interned string" - strobj = sys.intern(strobj) - - def testIntern(self): - s = marshal.loads(marshal.dumps(self.strobj)) - self.assertEqual(s, self.strobj) - self.assertEqual(id(s), id(self.strobj)) - s2 = sys.intern(s) - self.assertEqual(id(s2), id(s)) - - def testNoIntern(self): - s = marshal.loads(marshal.dumps(self.strobj, 2)) - self.assertEqual(s, self.strobj) - self.assertNotEqual(id(s), id(self.strobj)) - s2 = sys.intern(s) - self.assertNotEqual(id(s2), id(s)) - def test_main(): support.run_unittest(IntTestCase, - FloatTestCase, - StringTestCase, - CodeTestCase, - ContainerTestCase, - ExceptionTestCase, - BufferTestCase, - BugsTestCase, - LargeValuesTestCase, - ) + FloatTestCase, + StringTestCase, + CodeTestCase, + ContainerTestCase, + ExceptionTestCase, + BufferTestCase, + BugsTestCase) if __name__ == "__main__": test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_memoryio.py --- a/Lib/test/test_memoryio.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_memoryio.py Fri Feb 01 23:12:09 2013 +0100 @@ -379,8 +379,8 @@ self.assertEqual(obj.__class__, obj2.__class__) self.assertEqual(obj.foo, obj2.foo) self.assertEqual(obj.tell(), obj2.tell()) - obj2.close() - self.assertRaises(ValueError, pickle.dumps, obj2, proto) + obj.close() + self.assertRaises(ValueError, pickle.dumps, obj, proto) del __main__.PickleTestMemIO diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_mmap.py --- a/Lib/test/test_mmap.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_mmap.py Fri Feb 01 23:12:09 2013 +0100 @@ -721,13 +721,6 @@ def test_large_filesize(self): with self._make_test_file(0x17FFFFFFF, b" ") as f: - if sys.maxsize < 0x180000000: - # On 32 bit platforms the file is larger than sys.maxsize so - # mapping the whole file should fail -- Issue #16743 - with self.assertRaises(OverflowError): - mmap.mmap(f.fileno(), 0x180000000, access=mmap.ACCESS_READ) - with self.assertRaises(ValueError): - mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) with mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ) as m: self.assertEqual(m.size(), 0x180000000) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_module.py --- a/Lib/test/test_module.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_module.py Fri Feb 01 23:12:09 2013 +0100 @@ -33,10 +33,7 @@ foo = ModuleType("foo") self.assertEqual(foo.__name__, "foo") self.assertEqual(foo.__doc__, None) - self.assertIs(foo.__loader__, None) - self.assertIs(foo.__package__, None) - self.assertEqual(foo.__dict__, {"__name__": "foo", "__doc__": None, - "__loader__": None, "__package__": None}) + self.assertEqual(foo.__dict__, {"__name__": "foo", "__doc__": None}) def test_ascii_docstring(self): # ASCII docstring @@ -44,8 +41,7 @@ self.assertEqual(foo.__name__, "foo") self.assertEqual(foo.__doc__, "foodoc") self.assertEqual(foo.__dict__, - {"__name__": "foo", "__doc__": "foodoc", - "__loader__": None, "__package__": None}) + {"__name__": "foo", "__doc__": "foodoc"}) def test_unicode_docstring(self): # Unicode docstring @@ -53,8 +49,7 @@ self.assertEqual(foo.__name__, "foo") self.assertEqual(foo.__doc__, "foodoc\u1234") self.assertEqual(foo.__dict__, - {"__name__": "foo", "__doc__": "foodoc\u1234", - "__loader__": None, "__package__": None}) + {"__name__": "foo", "__doc__": "foodoc\u1234"}) def test_reinit(self): # Reinitialization should not replace the __dict__ @@ -66,8 +61,7 @@ self.assertEqual(foo.__doc__, "foodoc") self.assertEqual(foo.bar, 42) self.assertEqual(foo.__dict__, - {"__name__": "foo", "__doc__": "foodoc", "bar": 42, - "__loader__": None, "__package__": None}) + {"__name__": "foo", "__doc__": "foodoc", "bar": 42}) self.assertTrue(foo.__dict__ is d) @unittest.expectedFailure @@ -116,19 +110,13 @@ m.__file__ = '/tmp/foo.py' self.assertEqual(repr(m), "") - def test_module_repr_with_loader_as_None(self): - m = ModuleType('foo') - assert m.__loader__ is None - self.assertEqual(repr(m), "") - def test_module_repr_with_bare_loader_but_no_name(self): m = ModuleType('foo') del m.__name__ # Yes, a class not an instance. m.__loader__ = BareLoader - loader_repr = repr(BareLoader) self.assertEqual( - repr(m), "".format(loader_repr)) + repr(m), ")>") def test_module_repr_with_full_loader_but_no_name(self): # m.__loader__.module_repr() will fail because the module has no @@ -138,17 +126,15 @@ del m.__name__ # Yes, a class not an instance. m.__loader__ = FullLoader - loader_repr = repr(FullLoader) self.assertEqual( - repr(m), "".format(loader_repr)) + repr(m), ")>") def test_module_repr_with_bare_loader(self): m = ModuleType('foo') # Yes, a class not an instance. m.__loader__ = BareLoader - module_repr = repr(BareLoader) self.assertEqual( - repr(m), "".format(module_repr)) + repr(m), ")>") def test_module_repr_with_full_loader(self): m = ModuleType('foo') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_multibytecodec.py Fri Feb 01 23:12:09 2013 +0100 @@ -176,28 +176,57 @@ support.unlink(TESTFN) class Test_StreamWriter(unittest.TestCase): - def test_gb18030(self): - s= io.BytesIO() - c = codecs.getwriter('gb18030')(s) - c.write('123') - self.assertEqual(s.getvalue(), b'123') - c.write('\U00012345') - self.assertEqual(s.getvalue(), b'123\x907\x959') - c.write('\uac00\u00ac') - self.assertEqual(s.getvalue(), - b'123\x907\x959\x827\xcf5\x810\x851') + if len('\U00012345') == 2: # UCS2 + def test_gb18030(self): + s= io.BytesIO() + c = codecs.getwriter('gb18030')(s) + c.write('123') + self.assertEqual(s.getvalue(), b'123') + c.write('\U00012345') + self.assertEqual(s.getvalue(), b'123\x907\x959') + c.write('\U00012345'[0]) + self.assertEqual(s.getvalue(), b'123\x907\x959') + c.write('\U00012345'[1] + '\U00012345' + '\uac00\u00ac') + self.assertEqual(s.getvalue(), + b'123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851') + c.write('\U00012345'[0]) + self.assertEqual(s.getvalue(), + b'123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851') + self.assertRaises(UnicodeError, c.reset) + self.assertEqual(s.getvalue(), + b'123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851') - def test_utf_8(self): - s= io.BytesIO() - c = codecs.getwriter('utf-8')(s) - c.write('123') - self.assertEqual(s.getvalue(), b'123') - c.write('\U00012345') - self.assertEqual(s.getvalue(), b'123\xf0\x92\x8d\x85') - c.write('\uac00\u00ac') - self.assertEqual(s.getvalue(), - b'123\xf0\x92\x8d\x85' - b'\xea\xb0\x80\xc2\xac') + def test_utf_8(self): + s= io.BytesIO() + c = codecs.getwriter('utf-8')(s) + c.write('123') + self.assertEqual(s.getvalue(), b'123') + c.write('\U00012345') + self.assertEqual(s.getvalue(), b'123\xf0\x92\x8d\x85') + + # Python utf-8 codec can't buffer surrogate pairs yet. + if 0: + c.write('\U00012345'[0]) + self.assertEqual(s.getvalue(), b'123\xf0\x92\x8d\x85') + c.write('\U00012345'[1] + '\U00012345' + '\uac00\u00ac') + self.assertEqual(s.getvalue(), + b'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85' + b'\xea\xb0\x80\xc2\xac') + c.write('\U00012345'[0]) + self.assertEqual(s.getvalue(), + b'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85' + b'\xea\xb0\x80\xc2\xac') + c.reset() + self.assertEqual(s.getvalue(), + b'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85' + b'\xea\xb0\x80\xc2\xac\xed\xa0\x88') + c.write('\U00012345'[1]) + self.assertEqual(s.getvalue(), + b'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85' + b'\xea\xb0\x80\xc2\xac\xed\xa0\x88\xed\xbd\x85') + + else: # UCS4 + pass def test_streamwriter_strwrite(self): s = io.BytesIO() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_multiprocessing.py Fri Feb 01 23:12:09 2013 +0100 @@ -699,13 +699,6 @@ for p in workers: p.join() - def test_timeout(self): - q = multiprocessing.Queue() - start = time.time() - self.assertRaises(pyqueue.Empty, q.get, True, 0.2) - delta = time.time() - start - self.assertGreaterEqual(delta, 0.19) - # # # @@ -1755,37 +1748,9 @@ with multiprocessing.Pool(2) as p: r = p.map_async(sqr, L) self.assertEqual(r.get(), expected) + print(p._state) self.assertRaises(ValueError, p.map_async, sqr, L) - @classmethod - def _test_traceback(cls): - raise RuntimeError(123) # some comment - - def test_traceback(self): - # We want ensure that the traceback from the child process is - # contained in the traceback raised in the main process. - if self.TYPE == 'processes': - with self.Pool(1) as p: - try: - p.apply(self._test_traceback) - except Exception as e: - exc = e - else: - raise AssertionError('expected RuntimeError') - self.assertIs(type(exc), RuntimeError) - self.assertEqual(exc.args, (123,)) - cause = exc.__cause__ - self.assertIs(type(cause), multiprocessing.pool.RemoteTraceback) - self.assertIn('raise RuntimeError(123) # some comment', cause.tb) - - with test.support.captured_stderr() as f1: - try: - raise exc - except RuntimeError: - sys.excepthook(*sys.exc_info()) - self.assertIn('raise RuntimeError(123) # some comment', - f1.getvalue()) - def raising(): raise KeyError("key") @@ -2404,7 +2369,7 @@ c.close() l.close() -class _TestPoll(BaseTestCase): +class _TestPoll(unittest.TestCase): ALLOWED_TYPES = ('processes', 'threads') @@ -2904,38 +2869,6 @@ # assert self.__handled # -# Check that Process.join() retries if os.waitpid() fails with EINTR -# - -class _TestPollEintr(BaseTestCase): - - ALLOWED_TYPES = ('processes',) - - @classmethod - def _killer(cls, pid): - time.sleep(0.5) - os.kill(pid, signal.SIGUSR1) - - @unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1') - def test_poll_eintr(self): - got_signal = [False] - def record(*args): - got_signal[0] = True - pid = os.getpid() - oldhandler = signal.signal(signal.SIGUSR1, record) - try: - killer = self.Process(target=self._killer, args=(pid,)) - killer.start() - p = self.Process(target=time.sleep, args=(1,)) - p.start() - p.join() - self.assertTrue(got_signal[0]) - self.assertEqual(p.exitcode, 0) - killer.join() - finally: - signal.signal(signal.SIGUSR1, oldhandler) - -# # Test to verify handle verification, see issue 3321 # @@ -3034,13 +2967,7 @@ @classmethod def tearDownClass(cls): - # only the manager process should be returned by active_children() - # but this can take a bit on slow machines, so wait a few seconds - # if there are other children too (see #17395) - t = 0.01 - while len(multiprocessing.active_children()) > 1 and t < 5: - time.sleep(t) - t *= 2 + multiprocessing.active_children() # discard dead process objs gc.collect() # do garbage collection if cls.manager._number_of_objects() != 0: # This is not really an error since some tests do not @@ -3485,122 +3412,46 @@ self.assertEqual('', err.decode('ascii')) # -# Issue #17555: ForkAwareThreadLock # - -class TestForkAwareThreadLock(unittest.TestCase): - # We recurisvely start processes. Issue #17555 meant that the - # after fork registry would get duplicate entries for the same - # lock. The size of the registry at generation n was ~2**n. - - @classmethod - def child(cls, n, conn): - if n > 1: - p = multiprocessing.Process(target=cls.child, args=(n-1, conn)) - p.start() - p.join() - else: - conn.send(len(util._afterfork_registry)) - conn.close() - - def test_lock(self): - r, w = multiprocessing.Pipe(False) - l = util.ForkAwareThreadLock() - old_size = len(util._afterfork_registry) - p = multiprocessing.Process(target=self.child, args=(5, w)) - p.start() - new_size = r.recv() - p.join() - self.assertLessEqual(new_size, old_size) - # -# Issue #17097: EINTR should be ignored by recv(), send(), accept() etc + +testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, + TestStdinBadfiledescriptor, TestWait, TestInvalidFamily, + TestFlags, TestTimeouts, TestNoForkBomb] + # - -class TestIgnoreEINTR(unittest.TestCase): - - @classmethod - def _test_ignore(cls, conn): - def handler(signum, frame): - pass - signal.signal(signal.SIGUSR1, handler) - conn.send('ready') - x = conn.recv() - conn.send(x) - conn.send_bytes(b'x'*(1024*1024)) # sending 1 MB should block - - @unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1') - def test_ignore(self): - conn, child_conn = multiprocessing.Pipe() - try: - p = multiprocessing.Process(target=self._test_ignore, - args=(child_conn,)) - p.daemon = True - p.start() - child_conn.close() - self.assertEqual(conn.recv(), 'ready') - time.sleep(0.1) - os.kill(p.pid, signal.SIGUSR1) - time.sleep(0.1) - conn.send(1234) - self.assertEqual(conn.recv(), 1234) - time.sleep(0.1) - os.kill(p.pid, signal.SIGUSR1) - self.assertEqual(conn.recv_bytes(), b'x'*(1024*1024)) - time.sleep(0.1) - p.join() - finally: - conn.close() - - @classmethod - def _test_ignore_listener(cls, conn): - def handler(signum, frame): - pass - signal.signal(signal.SIGUSR1, handler) - l = multiprocessing.connection.Listener() - conn.send(l.address) - a = l.accept() - a.send('welcome') - - @unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1') - def test_ignore_listener(self): - conn, child_conn = multiprocessing.Pipe() - try: - p = multiprocessing.Process(target=self._test_ignore_listener, - args=(child_conn,)) - p.daemon = True - p.start() - child_conn.close() - address = conn.recv() - time.sleep(0.1) - os.kill(p.pid, signal.SIGUSR1) - time.sleep(0.1) - client = multiprocessing.connection.Client(address) - self.assertEqual(client.recv(), 'welcome') - p.join() - finally: - conn.close() - # # -# - -def setUpModule(): + +def test_main(run=None): if sys.platform.startswith("linux"): try: lock = multiprocessing.RLock() except OSError: - raise unittest.SkipTest("OSError raises on RLock creation, " - "see issue 3111!") + raise unittest.SkipTest("OSError raises on RLock creation, see issue 3111!") + check_enough_semaphores() + + if run is None: + from test.support import run_unittest as run + util.get_temp_dir() # creates temp directory for use by all processes + multiprocessing.get_logger().setLevel(LOG_LEVEL) - -def tearDownModule(): - # pause a bit so we don't get warning about dangling threads/processes - time.sleep(0.5) - + testcases = ( + sorted(testcases_processes.values(), key=lambda tc:tc.__name__) + + sorted(testcases_threads.values(), key=lambda tc:tc.__name__) + + sorted(testcases_manager.values(), key=lambda tc:tc.__name__) + + testcases_other + ) + + loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase + suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases) + run(suite) + +def main(): + test_main(unittest.TextTestRunner(verbosity=2).run) if __name__ == '__main__': - unittest.main() + main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_namespace_pkgs.py --- a/Lib/test/test_namespace_pkgs.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_namespace_pkgs.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,11 +1,7 @@ +import sys import contextlib -from importlib._bootstrap import NamespaceLoader -import importlib.abc -import importlib.machinery +import unittest import os -import sys -import types -import unittest from test.test_importlib import util from test.support import run_unittest @@ -290,24 +286,9 @@ self.assertEqual(a_test.attr, 'in module') -class ABCTests(unittest.TestCase): - - def setUp(self): - self.loader = NamespaceLoader('foo', ['pkg'], - importlib.machinery.PathFinder) - - def test_is_package(self): - self.assertTrue(self.loader.is_package('foo')) - - def test_get_code(self): - self.assertTrue(isinstance(self.loader.get_code('foo'), types.CodeType)) - - def test_get_source(self): - self.assertEqual(self.loader.get_source('foo'), '') - - def test_abc_isinstance(self): - self.assertTrue(isinstance(self.loader, importlib.abc.InspectLoader)) +def test_main(): + run_unittest(*NamespacePackageTest.__subclasses__()) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_openpty.py --- a/Lib/test/test_openpty.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_openpty.py Fri Feb 01 23:12:09 2013 +0100 @@ -10,8 +10,6 @@ class OpenptyTest(unittest.TestCase): def test(self): master, slave = os.openpty() - self.addCleanup(os.close, master) - self.addCleanup(os.close, slave) if not os.isatty(slave): self.fail("Slave-end of pty is not a terminal.") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_operator.py --- a/Lib/test/test_operator.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_operator.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,10 +1,8 @@ +import operator import unittest from test import support -py_operator = support.import_fresh_module('operator', blocked=['_operator']) -c_operator = support.import_fresh_module('operator', fresh=['_operator']) - class Seq1: def __init__(self, lst): self.lst = lst @@ -34,9 +32,8 @@ return other * self.lst -class OperatorTestCase: +class OperatorTestCase(unittest.TestCase): def test_lt(self): - operator = self.module self.assertRaises(TypeError, operator.lt) self.assertRaises(TypeError, operator.lt, 1j, 2j) self.assertFalse(operator.lt(1, 0)) @@ -47,7 +44,6 @@ self.assertTrue(operator.lt(1, 2.0)) def test_le(self): - operator = self.module self.assertRaises(TypeError, operator.le) self.assertRaises(TypeError, operator.le, 1j, 2j) self.assertFalse(operator.le(1, 0)) @@ -58,7 +54,6 @@ self.assertTrue(operator.le(1, 2.0)) def test_eq(self): - operator = self.module class C(object): def __eq__(self, other): raise SyntaxError @@ -72,7 +67,6 @@ self.assertFalse(operator.eq(1, 2.0)) def test_ne(self): - operator = self.module class C(object): def __ne__(self, other): raise SyntaxError @@ -86,7 +80,6 @@ self.assertTrue(operator.ne(1, 2.0)) def test_ge(self): - operator = self.module self.assertRaises(TypeError, operator.ge) self.assertRaises(TypeError, operator.ge, 1j, 2j) self.assertTrue(operator.ge(1, 0)) @@ -97,7 +90,6 @@ self.assertFalse(operator.ge(1, 2.0)) def test_gt(self): - operator = self.module self.assertRaises(TypeError, operator.gt) self.assertRaises(TypeError, operator.gt, 1j, 2j) self.assertTrue(operator.gt(1, 0)) @@ -108,26 +100,22 @@ self.assertFalse(operator.gt(1, 2.0)) def test_abs(self): - operator = self.module self.assertRaises(TypeError, operator.abs) self.assertRaises(TypeError, operator.abs, None) self.assertEqual(operator.abs(-1), 1) self.assertEqual(operator.abs(1), 1) def test_add(self): - operator = self.module self.assertRaises(TypeError, operator.add) self.assertRaises(TypeError, operator.add, None, None) self.assertTrue(operator.add(3, 4) == 7) def test_bitwise_and(self): - operator = self.module self.assertRaises(TypeError, operator.and_) self.assertRaises(TypeError, operator.and_, None, None) self.assertTrue(operator.and_(0xf, 0xa) == 0xa) def test_concat(self): - operator = self.module self.assertRaises(TypeError, operator.concat) self.assertRaises(TypeError, operator.concat, None, None) self.assertTrue(operator.concat('py', 'thon') == 'python') @@ -137,14 +125,12 @@ self.assertRaises(TypeError, operator.concat, 13, 29) def test_countOf(self): - operator = self.module self.assertRaises(TypeError, operator.countOf) self.assertRaises(TypeError, operator.countOf, None, None) self.assertTrue(operator.countOf([1, 2, 1, 3, 1, 4], 3) == 1) self.assertTrue(operator.countOf([1, 2, 1, 3, 1, 4], 5) == 0) def test_delitem(self): - operator = self.module a = [4, 3, 2, 1] self.assertRaises(TypeError, operator.delitem, a) self.assertRaises(TypeError, operator.delitem, a, None) @@ -152,39 +138,33 @@ self.assertTrue(a == [4, 2, 1]) def test_floordiv(self): - operator = self.module self.assertRaises(TypeError, operator.floordiv, 5) self.assertRaises(TypeError, operator.floordiv, None, None) self.assertTrue(operator.floordiv(5, 2) == 2) def test_truediv(self): - operator = self.module self.assertRaises(TypeError, operator.truediv, 5) self.assertRaises(TypeError, operator.truediv, None, None) self.assertTrue(operator.truediv(5, 2) == 2.5) def test_getitem(self): - operator = self.module a = range(10) self.assertRaises(TypeError, operator.getitem) self.assertRaises(TypeError, operator.getitem, a, None) self.assertTrue(operator.getitem(a, 2) == 2) def test_indexOf(self): - operator = self.module self.assertRaises(TypeError, operator.indexOf) self.assertRaises(TypeError, operator.indexOf, None, None) self.assertTrue(operator.indexOf([4, 3, 2, 1], 3) == 1) self.assertRaises(ValueError, operator.indexOf, [4, 3, 2, 1], 0) def test_invert(self): - operator = self.module self.assertRaises(TypeError, operator.invert) self.assertRaises(TypeError, operator.invert, None) self.assertEqual(operator.inv(4), -5) def test_lshift(self): - operator = self.module self.assertRaises(TypeError, operator.lshift) self.assertRaises(TypeError, operator.lshift, None, 42) self.assertTrue(operator.lshift(5, 1) == 10) @@ -192,19 +172,16 @@ self.assertRaises(ValueError, operator.lshift, 2, -1) def test_mod(self): - operator = self.module self.assertRaises(TypeError, operator.mod) self.assertRaises(TypeError, operator.mod, None, 42) self.assertTrue(operator.mod(5, 2) == 1) def test_mul(self): - operator = self.module self.assertRaises(TypeError, operator.mul) self.assertRaises(TypeError, operator.mul, None, None) self.assertTrue(operator.mul(5, 2) == 10) def test_neg(self): - operator = self.module self.assertRaises(TypeError, operator.neg) self.assertRaises(TypeError, operator.neg, None) self.assertEqual(operator.neg(5), -5) @@ -213,13 +190,11 @@ self.assertEqual(operator.neg(-0), 0) def test_bitwise_or(self): - operator = self.module self.assertRaises(TypeError, operator.or_) self.assertRaises(TypeError, operator.or_, None, None) self.assertTrue(operator.or_(0xa, 0x5) == 0xf) def test_pos(self): - operator = self.module self.assertRaises(TypeError, operator.pos) self.assertRaises(TypeError, operator.pos, None) self.assertEqual(operator.pos(5), 5) @@ -228,15 +203,14 @@ self.assertEqual(operator.pos(-0), 0) def test_pow(self): - operator = self.module self.assertRaises(TypeError, operator.pow) self.assertRaises(TypeError, operator.pow, None, None) self.assertEqual(operator.pow(3,5), 3**5) + self.assertEqual(operator.__pow__(3,5), 3**5) self.assertRaises(TypeError, operator.pow, 1) self.assertRaises(TypeError, operator.pow, 1, 2, 3) def test_rshift(self): - operator = self.module self.assertRaises(TypeError, operator.rshift) self.assertRaises(TypeError, operator.rshift, None, 42) self.assertTrue(operator.rshift(5, 1) == 2) @@ -244,14 +218,12 @@ self.assertRaises(ValueError, operator.rshift, 2, -1) def test_contains(self): - operator = self.module self.assertRaises(TypeError, operator.contains) self.assertRaises(TypeError, operator.contains, None, None) self.assertTrue(operator.contains(range(4), 2)) self.assertFalse(operator.contains(range(4), 5)) def test_setitem(self): - operator = self.module a = list(range(3)) self.assertRaises(TypeError, operator.setitem, a) self.assertRaises(TypeError, operator.setitem, a, None, None) @@ -260,13 +232,11 @@ self.assertRaises(IndexError, operator.setitem, a, 4, 2) def test_sub(self): - operator = self.module self.assertRaises(TypeError, operator.sub) self.assertRaises(TypeError, operator.sub, None, None) self.assertTrue(operator.sub(5, 2) == 3) def test_truth(self): - operator = self.module class C(object): def __bool__(self): raise SyntaxError @@ -278,13 +248,11 @@ self.assertFalse(operator.truth([])) def test_bitwise_xor(self): - operator = self.module self.assertRaises(TypeError, operator.xor) self.assertRaises(TypeError, operator.xor, None, None) self.assertTrue(operator.xor(0xb, 0xc) == 0x7) def test_is(self): - operator = self.module a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_) @@ -292,7 +260,6 @@ self.assertFalse(operator.is_(a,c)) def test_is_not(self): - operator = self.module a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_not) @@ -300,7 +267,6 @@ self.assertTrue(operator.is_not(a,c)) def test_attrgetter(self): - operator = self.module class A: pass a = A() @@ -350,7 +316,6 @@ self.assertEqual(f(a), ('arthur', 'thomas', 'johnson')) def test_itemgetter(self): - operator = self.module a = 'ABCDE' f = operator.itemgetter(2) self.assertEqual(f(a), 'C') @@ -385,15 +350,12 @@ self.assertRaises(TypeError, operator.itemgetter(2, 'x', 5), data) def test_methodcaller(self): - operator = self.module self.assertRaises(TypeError, operator.methodcaller) class A: def foo(self, *args, **kwds): return args[0] + args[1] def bar(self, f=42): return f - def baz(*args, **kwds): - return kwds['name'], kwds['self'] a = A() f = operator.methodcaller('foo') self.assertRaises(IndexError, f, a) @@ -404,11 +366,8 @@ self.assertRaises(TypeError, f, a, a) f = operator.methodcaller('bar', f=5) self.assertEqual(f(a), 5) - f = operator.methodcaller('baz', name='spam', self='eggs') - self.assertEqual(f(a), ('spam', 'eggs')) def test_inplace(self): - operator = self.module class C(object): def __iadd__ (self, other): return "iadd" def __iand__ (self, other): return "iand" @@ -437,9 +396,21 @@ self.assertEqual(operator.itruediv (c, 5), "itruediv") self.assertEqual(operator.ixor (c, 5), "ixor") self.assertEqual(operator.iconcat (c, c), "iadd") + self.assertEqual(operator.__iadd__ (c, 5), "iadd") + self.assertEqual(operator.__iand__ (c, 5), "iand") + self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv") + self.assertEqual(operator.__ilshift__ (c, 5), "ilshift") + self.assertEqual(operator.__imod__ (c, 5), "imod") + self.assertEqual(operator.__imul__ (c, 5), "imul") + self.assertEqual(operator.__ior__ (c, 5), "ior") + self.assertEqual(operator.__ipow__ (c, 5), "ipow") + self.assertEqual(operator.__irshift__ (c, 5), "irshift") + self.assertEqual(operator.__isub__ (c, 5), "isub") + self.assertEqual(operator.__itruediv__ (c, 5), "itruediv") + self.assertEqual(operator.__ixor__ (c, 5), "ixor") + self.assertEqual(operator.__iconcat__ (c, c), "iadd") def test_length_hint(self): - operator = self.module class X(object): def __init__(self, value): self.value = value @@ -463,22 +434,24 @@ with self.assertRaises(LookupError): operator.length_hint(X(LookupError)) - def test_dunder_is_original(self): - operator = self.module - names = [name for name in dir(operator) if not name.startswith('_')] - for name in names: - orig = getattr(operator, name) - dunder = getattr(operator, '__' + name.strip('_') + '__', None) - if dunder: - self.assertIs(dunder, orig) +def test_main(verbose=None): + import sys + test_classes = ( + OperatorTestCase, + ) -class PyOperatorTestCase(OperatorTestCase, unittest.TestCase): - module = py_operator + support.run_unittest(*test_classes) -@unittest.skipUnless(c_operator, 'requires _operator') -class COperatorTestCase(OperatorTestCase, unittest.TestCase): - module = c_operator + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in range(len(counts)): + support.run_unittest(*test_classes) + gc.collect() + counts[i] = sys.gettotalrefcount() + print(counts) if __name__ == "__main__": - unittest.main() + test_main(verbose=True) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_optparse.py --- a/Lib/test/test_optparse.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_optparse.py Fri Feb 01 23:12:09 2013 +0100 @@ -730,7 +730,7 @@ def test_short_and_long_option_split(self): self.assertParseOK(["-a", "xyz", "--foo", "bar"], {'a': 'xyz', 'boo': None, 'foo': ["bar"]}, - []) + []), def test_short_option_split_long_option_append(self): self.assertParseOK(["--foo=bar", "-b", "123", "--foo", "baz"], @@ -740,15 +740,15 @@ def test_short_option_split_one_positional_arg(self): self.assertParseOK(["-a", "foo", "bar"], {'a': "foo", 'boo': None, 'foo': None}, - ["bar"]) + ["bar"]), def test_short_option_consumes_separator(self): self.assertParseOK(["-a", "--", "foo", "bar"], {'a': "--", 'boo': None, 'foo': None}, - ["foo", "bar"]) + ["foo", "bar"]), self.assertParseOK(["-a", "--", "--foo", "bar"], {'a': "--", 'boo': None, 'foo': ["bar"]}, - []) + []), def test_short_option_joined_and_separator(self): self.assertParseOK(["-ab", "--", "--foo", "bar"], diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_os.py --- a/Lib/test/test_os.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_os.py Fri Feb 01 23:12:09 2013 +0100 @@ -49,9 +49,6 @@ else: USING_LINUXTHREADS = False -# Issue #14110: Some tests fail on FreeBSD if the user is in the wheel group. -HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0 - # Tests creating TESTFN class FileTests(unittest.TestCase): def setUp(self): @@ -632,18 +629,6 @@ key = 'key=' self.assertRaises(OSError, os.environ.__delitem__, key) - def test_key_type(self): - missing = 'missingkey' - self.assertNotIn(missing, os.environ) - - with self.assertRaises(KeyError) as cm: - os.environ[missing] - self.assertIs(cm.exception.args[0], missing) - - with self.assertRaises(KeyError) as cm: - del os.environ[missing] - self.assertIs(cm.exception.args[0], missing) - class WalkTests(unittest.TestCase): """Tests for os.walk().""" @@ -686,8 +671,13 @@ f.write("I'm " + path + " and proud of it. Blame test_os.\n") f.close() if support.can_symlink(): - os.symlink(os.path.abspath(t2_path), link_path) - os.symlink('broken', broken_link_path, True) + if os.name == 'nt': + def symlink_to_dir(src, dest): + os.symlink(src, dest, True) + else: + symlink_to_dir = os.symlink + symlink_to_dir(os.path.abspath(t2_path), link_path) + symlink_to_dir('broken', broken_link_path) sub2_tree = (sub2_path, ["link"], ["broken_link", "tmp3"]) else: sub2_tree = (sub2_path, [], ["tmp3"]) @@ -1250,7 +1240,7 @@ if hasattr(os, 'setgid'): def test_setgid(self): - if os.getuid() != 0 and not HAVE_WHEEL_GROUP: + if os.getuid() != 0: self.assertRaises(OSError, os.setgid, 0) self.assertRaises(OverflowError, os.setgid, 1<<32) @@ -1262,7 +1252,7 @@ if hasattr(os, 'setegid'): def test_setegid(self): - if os.getuid() != 0 and not HAVE_WHEEL_GROUP: + if os.getuid() != 0: self.assertRaises(OSError, os.setegid, 0) self.assertRaises(OverflowError, os.setegid, 1<<32) @@ -1282,7 +1272,7 @@ if hasattr(os, 'setregid'): def test_setregid(self): - if os.getuid() != 0 and not HAVE_WHEEL_GROUP: + if os.getuid() != 0: self.assertRaises(OSError, os.setregid, 0, 0) self.assertRaises(OverflowError, os.setregid, 1<<32, 0) self.assertRaises(OverflowError, os.setregid, 0, 1<<32) @@ -1511,7 +1501,7 @@ os.remove(self.missing_link) def test_directory_link(self): - os.symlink(self.dirlink_target, self.dirlink) + os.symlink(self.dirlink_target, self.dirlink, True) self.assertTrue(os.path.exists(self.dirlink)) self.assertTrue(os.path.isdir(self.dirlink)) self.assertTrue(os.path.islink(self.dirlink)) @@ -1605,38 +1595,6 @@ shutil.rmtree(level1) -@support.skip_unless_symlink -class NonLocalSymlinkTests(unittest.TestCase): - - def setUp(self): - """ - Create this structure: - - base - \___ some_dir - """ - os.makedirs('base/some_dir') - - def tearDown(self): - shutil.rmtree('base') - - def test_directory_link_nonlocal(self): - """ - The symlink target should resolve relative to the link, not relative - to the current directory. - - Then, link base/some_link -> base/some_dir and ensure that some_link - is resolved as a directory. - - In issue13772, it was discovered that directory detection failed if - the symlink target was not specified relative to the current - directory, which was a defect in the implementation. - """ - src = os.path.join('base', 'some_link') - os.symlink('some_dir', src) - assert os.path.isdir(src) - - class FSEncodingTests(unittest.TestCase): def test_nop(self): self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff') @@ -2243,14 +2201,112 @@ else: self.fail("No exception thrown by {}".format(func)) -class CPUCountTests(unittest.TestCase): - def test_cpu_count(self): - cpus = os.cpu_count() - if cpus is not None: - self.assertIsInstance(cpus, int) - self.assertGreater(cpus, 0) - else: - self.skipTest("Could not determine the number of CPUs") + +@unittest.skipUnless(hasattr(os, 'get_cloexec'), "need os.get_cloexec()") +class CloexecTests(unittest.TestCase): + def setUp(self): + self.old_cloexec = sys.getdefaultcloexec() + + def tearDown(self): + sys.setdefaultcloexec(self.old_cloexec) + + def create_testfile(self): + fileobj = open(support.TESTFN, 'xb') + self.addCleanup(support.unlink, support.TESTFN) + fileobj.close() + + def test_get_cloexec(self): + self.create_testfile() + + for cloexec in (False, True): + fd = os.open(support.TESTFN, os.O_RDONLY, cloexec=cloexec) + self.assertEqual(os.get_cloexec(fd), cloexec) + os.close(fd) + + def test_set_cloexec(self): + self.create_testfile() + + for cloexec in (False, True): + fd = os.open(support.TESTFN, os.O_RDONLY, cloexec=not cloexec) + os.set_cloexec(fd, cloexec) + self.assertEqual(os.get_cloexec(fd), cloexec) + os.close(fd) + + def test_open(self): + self.create_testfile() + + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + fd = os.open(support.TESTFN, os.O_RDONLY) + else: + fd = os.open(support.TESTFN, os.O_RDONLY, cloexec=cloexec) + self.assertEqual(os.get_cloexec(fd), cloexec) + os.close(fd) + + @unittest.skipUnless(hasattr(os, 'pipe'), "need os.pipe()") + def test_pipe_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + rfd, wfd = os.pipe() + else: + rfd, wfd = os.pipe(cloexec=cloexec) + self.assertEqual(os.get_cloexec(rfd), cloexec) + self.assertEqual(os.get_cloexec(wfd), cloexec) + os.close(rfd) + os.close(wfd) + + @unittest.skipUnless(hasattr(os, 'dup'), "need os.dup()") + def test_dup_cloexec(self): + self.create_testfile() + + for cloexec in (False, True): + for set_default in (False, True): + fd1 = os.open(support.TESTFN, os.O_RDONLY, + cloexec=not cloexec) + if set_default: + sys.setdefaultcloexec(cloexec) + fd2 = os.dup(fd1) + else: + fd2 = os.dup(fd1, cloexec=cloexec) + self.assertEqual(os.get_cloexec(fd2), cloexec) + os.close(fd1) + os.close(fd2) + + @unittest.skipUnless(hasattr(os, 'dup2'), "need os.dup2()") + def test_dup2_cloexec(self): + self.create_testfile() + + for cloexec in (False, True): + for set_default in (False, True): + fd1 = os.open(support.TESTFN, os.O_RDONLY, cloexec=not cloexec) + fd2 = os.open(support.TESTFN, os.O_RDONLY, cloexec=not cloexec) + if set_default: + sys.setdefaultcloexec(cloexec) + os.dup2(fd1, fd2) + else: + os.dup2(fd1, fd2, cloexec=cloexec) + self.assertEqual(os.get_cloexec(fd2), cloexec) + os.close(fd1) + os.close(fd2) + + @unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()") + def test_openpty_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + master_fd, slave_fd = os.openpty() + else: + master_fd, slave_fd = os.openpty(cloexec=cloexec) + self.assertEqual(os.get_cloexec(master_fd), cloexec) + self.assertEqual(os.get_cloexec(slave_fd), cloexec) + os.close(master_fd) + os.close(slave_fd) + @support.reap_threads def test_main(): @@ -2270,7 +2326,6 @@ Pep383Tests, Win32KillTests, Win32SymlinkTests, - NonLocalSymlinkTests, FSEncodingTests, DeviceEncodingTests, PidTests, @@ -2283,7 +2338,7 @@ TermsizeTests, OSErrorTests, RemoveDirsTests, - CPUCountTests, + CloexecTests, ) if __name__ == "__main__": diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_osx_env.py --- a/Lib/test/test_osx_env.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_osx_env.py Fri Feb 01 23:12:09 2013 +0100 @@ -8,9 +8,6 @@ import sysconfig import unittest -@unittest.skipUnless(sys.platform == 'darwin' and - sysconfig.get_config_var('WITH_NEXT_FRAMEWORK'), - 'unnecessary on this platform') class OSXEnvironmentVariableTestCase(unittest.TestCase): def _check_sys(self, ev, cond, sv, val = sys.executable + 'dummy'): with EnvironmentVarGuard() as evg: @@ -30,5 +27,9 @@ def test_pythonexecutable_sets_sys_executable(self): self._check_sys('PYTHONEXECUTABLE', '==', 'sys.executable') +def test_main(): + if sys.platform == 'darwin' and sysconfig.get_config_var('WITH_NEXT_FRAMEWORK'): + run_unittest(OSXEnvironmentVariableTestCase) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_parser.py --- a/Lib/test/test_parser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_parser.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,7 +4,6 @@ import operator import struct from test import support -from test.script_helper import assert_python_failure # # First, we test that we can generate trees from valid source fragments, @@ -612,11 +611,10 @@ def test_trigger_memory_error(self): e = self._nested_expression(100) - rc, out, err = assert_python_failure('-c', e) - # parsing the expression will result in an error message - # followed by a MemoryError (see #11963) - self.assertIn(b's_push: parser stack overflow', err) - self.assertIn(b'MemoryError', err) + print("Expecting 's_push: parser stack overflow' in next line", + file=sys.stderr) + sys.stderr.flush() + self.assertRaises(MemoryError, parser.expr, e) class STObjectTestCase(unittest.TestCase): """Test operations on ST objects themselves""" diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pdb.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,9 +1,8 @@ # A test suite for pdb; not very comprehensive at the moment. -import doctest +import imp import pdb import sys -import types import unittest import subprocess import textwrap @@ -464,7 +463,7 @@ # Module for testing skipping of module that makes a callback -mod = types.ModuleType('module_to_skip') +mod = imp.new_module('module_to_skip') exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__) @@ -702,11 +701,11 @@ support.unlink(support.TESTFN) -def load_tests(*args): +def test_main(): from test import test_pdb - suites = [unittest.makeSuite(PdbTestCase), doctest.DocTestSuite(test_pdb)] - return unittest.TestSuite(suites) + support.run_doctest(test_pdb, verbosity=True) + support.run_unittest(PdbTestCase) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_peepholer.py --- a/Lib/test/test_peepholer.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_peepholer.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,28 +5,44 @@ import unittest from math import copysign -from test.bytecode_helper import BytecodeTestCase +def disassemble(func): + f = StringIO() + tmp = sys.stdout + sys.stdout = f + try: + dis.dis(func) + finally: + sys.stdout = tmp + result = f.getvalue() + f.close() + return result -class TestTranforms(BytecodeTestCase): +def dis_single(line): + return disassemble(compile(line, '', 'single')) + + +class TestTranforms(unittest.TestCase): def test_unot(self): # UNARY_NOT POP_JUMP_IF_FALSE --> POP_JUMP_IF_TRUE' def unot(x): if not x == 2: del x - self.assertNotInBytecode(unot, 'UNARY_NOT') - self.assertNotInBytecode(unot, 'POP_JUMP_IF_FALSE') - self.assertInBytecode(unot, 'POP_JUMP_IF_TRUE') + asm = disassemble(unot) + for elem in ('UNARY_NOT', 'POP_JUMP_IF_FALSE'): + self.assertNotIn(elem, asm) + for elem in ('POP_JUMP_IF_TRUE',): + self.assertIn(elem, asm) def test_elim_inversion_of_is_or_in(self): - for line, cmp_op in ( - ('not a is b', 'is not',), - ('not a in b', 'not in',), - ('not a is not b', 'is',), - ('not a not in b', 'in',), + for line, elem in ( + ('not a is b', '(is not)',), + ('not a in b', '(not in)',), + ('not a is not b', '(is)',), + ('not a not in b', '(in)',), ): - code = compile(line, '', 'single') - self.assertInBytecode(code, 'COMPARE_OP', cmp_op) + asm = dis_single(line) + self.assertIn(elem, asm) def test_global_as_constant(self): # LOAD_GLOBAL None/True/False --> LOAD_CONST None/True/False @@ -40,14 +56,17 @@ def h(x): False return x - for func, elem in ((f, None), (g, True), (h, False)): - self.assertNotInBytecode(func, 'LOAD_GLOBAL') - self.assertInBytecode(func, 'LOAD_CONST', elem) + for func, name in ((f, 'None'), (g, 'True'), (h, 'False')): + asm = disassemble(func) + for elem in ('LOAD_GLOBAL',): + self.assertNotIn(elem, asm) + for elem in ('LOAD_CONST', '('+name+')'): + self.assertIn(elem, asm) def f(): 'Adding a docstring made this test fail in Py2.5.0' return None - self.assertNotInBytecode(f, 'LOAD_GLOBAL') - self.assertInBytecode(f, 'LOAD_CONST', None) + self.assertIn('LOAD_CONST', disassemble(f)) + self.assertNotIn('LOAD_GLOBAL', disassemble(f)) def test_while_one(self): # Skip over: LOAD_CONST trueconst POP_JUMP_IF_FALSE xx @@ -55,10 +74,11 @@ while 1: pass return list + asm = disassemble(f) for elem in ('LOAD_CONST', 'POP_JUMP_IF_FALSE'): - self.assertNotInBytecode(f, elem) + self.assertNotIn(elem, asm) for elem in ('JUMP_ABSOLUTE',): - self.assertInBytecode(f, elem) + self.assertIn(elem, asm) def test_pack_unpack(self): for line, elem in ( @@ -66,30 +86,28 @@ ('a, b = a, b', 'ROT_TWO',), ('a, b, c = a, b, c', 'ROT_THREE',), ): - code = compile(line,'','single') - self.assertInBytecode(code, elem) - self.assertNotInBytecode(code, 'BUILD_TUPLE') - self.assertNotInBytecode(code, 'UNPACK_TUPLE') + asm = dis_single(line) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_TUPLE', asm) + self.assertNotIn('UNPACK_TUPLE', asm) def test_folding_of_tuples_of_constants(self): for line, elem in ( - ('a = 1,2,3', (1, 2, 3)), - ('("a","b","c")', ('a', 'b', 'c')), - ('a,b,c = 1,2,3', (1, 2, 3)), - ('(None, 1, None)', (None, 1, None)), - ('((1, 2), 3, 4)', ((1, 2), 3, 4)), + ('a = 1,2,3', '((1, 2, 3))'), + ('("a","b","c")', "(('a', 'b', 'c'))"), + ('a,b,c = 1,2,3', '((1, 2, 3))'), + ('(None, 1, None)', '((None, 1, None))'), + ('((1, 2), 3, 4)', '(((1, 2), 3, 4))'), ): - code = compile(line,'','single') - self.assertInBytecode(code, 'LOAD_CONST', elem) - self.assertNotInBytecode(code, 'BUILD_TUPLE') + asm = dis_single(line) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_TUPLE', asm) # Long tuples should be folded too. - code = compile(repr(tuple(range(10000))),'','single') - self.assertNotInBytecode(code, 'BUILD_TUPLE') + asm = dis_single(repr(tuple(range(10000)))) # One LOAD_CONST for the tuple, one for the None return value - load_consts = [instr for instr in dis.get_instructions(code) - if instr.opname == 'LOAD_CONST'] - self.assertEqual(len(load_consts), 2) + self.assertEqual(asm.count('LOAD_CONST'), 2) + self.assertNotIn('BUILD_TUPLE', asm) # Bug 1053819: Tuple of constants misidentified when presented with: # . . . opcode_with_arg 100 unary_opcode BUILD_TUPLE 1 . . . @@ -111,14 +129,14 @@ def test_folding_of_lists_of_constants(self): for line, elem in ( # in/not in constants with BUILD_LIST should be folded to a tuple: - ('a in [1,2,3]', (1, 2, 3)), - ('a not in ["a","b","c"]', ('a', 'b', 'c')), - ('a in [None, 1, None]', (None, 1, None)), - ('a not in [(1, 2), 3, 4]', ((1, 2), 3, 4)), + ('a in [1,2,3]', '(1, 2, 3)'), + ('a not in ["a","b","c"]', "(('a', 'b', 'c'))"), + ('a in [None, 1, None]', '((None, 1, None))'), + ('a not in [(1, 2), 3, 4]', '(((1, 2), 3, 4))'), ): - code = compile(line, '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', elem) - self.assertNotInBytecode(code, 'BUILD_LIST') + asm = dis_single(line) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_LIST', asm) def test_folding_of_sets_of_constants(self): for line, elem in ( @@ -129,9 +147,18 @@ ('a not in {(1, 2), 3, 4}', frozenset({(1, 2), 3, 4})), ('a in {1, 2, 3, 3, 2, 1}', frozenset({1, 2, 3})), ): - code = compile(line, '', 'single') - self.assertNotInBytecode(code, 'BUILD_SET') - self.assertInBytecode(code, 'LOAD_CONST', elem) + asm = dis_single(line) + self.assertNotIn('BUILD_SET', asm) + + # Verify that the frozenset 'elem' is in the disassembly + # The ordering of the elements in repr( frozenset ) isn't + # guaranteed, so we jump through some hoops to ensure that we have + # the frozenset we expect: + self.assertIn('frozenset', asm) + # Extract the frozenset literal from the disassembly: + m = re.match(r'.*(frozenset\({.*}\)).*', asm, re.DOTALL) + self.assertTrue(m) + self.assertEqual(eval(m.group(1)), elem) # Ensure that the resulting code actually works: def f(a): @@ -149,103 +176,98 @@ def test_folding_of_binops_on_constants(self): for line, elem in ( - ('a = 2+3+4', 9), # chained fold - ('"@"*4', '@@@@'), # check string ops - ('a="abc" + "def"', 'abcdef'), # check string ops - ('a = 3**4', 81), # binary power - ('a = 3*4', 12), # binary multiply - ('a = 13//4', 3), # binary floor divide - ('a = 14%4', 2), # binary modulo - ('a = 2+3', 5), # binary add - ('a = 13-4', 9), # binary subtract - ('a = (12,13)[1]', 13), # binary subscr - ('a = 13 << 2', 52), # binary lshift - ('a = 13 >> 2', 3), # binary rshift - ('a = 13 & 7', 5), # binary and - ('a = 13 ^ 7', 10), # binary xor - ('a = 13 | 7', 15), # binary or + ('a = 2+3+4', '(9)'), # chained fold + ('"@"*4', "('@@@@')"), # check string ops + ('a="abc" + "def"', "('abcdef')"), # check string ops + ('a = 3**4', '(81)'), # binary power + ('a = 3*4', '(12)'), # binary multiply + ('a = 13//4', '(3)'), # binary floor divide + ('a = 14%4', '(2)'), # binary modulo + ('a = 2+3', '(5)'), # binary add + ('a = 13-4', '(9)'), # binary subtract + ('a = (12,13)[1]', '(13)'), # binary subscr + ('a = 13 << 2', '(52)'), # binary lshift + ('a = 13 >> 2', '(3)'), # binary rshift + ('a = 13 & 7', '(5)'), # binary and + ('a = 13 ^ 7', '(10)'), # binary xor + ('a = 13 | 7', '(15)'), # binary or ): - code = compile(line, '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', elem) - for instr in dis.get_instructions(code): - self.assertFalse(instr.opname.startswith('BINARY_')) + asm = dis_single(line) + self.assertIn(elem, asm, asm) + self.assertNotIn('BINARY_', asm) # Verify that unfoldables are skipped - code = compile('a=2+"b"', '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', 2) - self.assertInBytecode(code, 'LOAD_CONST', 'b') + asm = dis_single('a=2+"b"') + self.assertIn('(2)', asm) + self.assertIn("('b')", asm) # Verify that large sequences do not result from folding - code = compile('a="x"*1000', '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', 1000) + asm = dis_single('a="x"*1000') + self.assertIn('(1000)', asm) def test_binary_subscr_on_unicode(self): # valid code get optimized - code = compile('"foo"[0]', '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', 'f') - self.assertNotInBytecode(code, 'BINARY_SUBSCR') - code = compile('"\u0061\uffff"[1]', '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', '\uffff') - self.assertNotInBytecode(code,'BINARY_SUBSCR') - - # With PEP 393, non-BMP char get optimized - code = compile('"\U00012345"[0]', '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', '\U00012345') - self.assertNotInBytecode(code, 'BINARY_SUBSCR') + asm = dis_single('"foo"[0]') + self.assertIn("('f')", asm) + self.assertNotIn('BINARY_SUBSCR', asm) + asm = dis_single('"\u0061\uffff"[1]') + self.assertIn("('\\uffff')", asm) + self.assertNotIn('BINARY_SUBSCR', asm) + asm = dis_single('"\U00012345abcdef"[3]') + self.assertIn("('c')", asm) + self.assertNotIn('BINARY_SUBSCR', asm) # invalid code doesn't get optimized # out of range - code = compile('"fuu"[10]', '', 'single') - self.assertInBytecode(code, 'BINARY_SUBSCR') + asm = dis_single('"fuu"[10]') + self.assertIn('BINARY_SUBSCR', asm) def test_folding_of_unaryops_on_constants(self): for line, elem in ( - ('-0.5', -0.5), # unary negative - ('-0.0', -0.0), # -0.0 - ('-(1.0-1.0)', -0.0), # -0.0 after folding - ('-0', 0), # -0 - ('~-2', 1), # unary invert - ('+1', 1), # unary positive + ('-0.5', '(-0.5)'), # unary negative + ('-0.0', '(-0.0)'), # -0.0 + ('-(1.0-1.0)','(-0.0)'), # -0.0 after folding + ('-0', '(0)'), # -0 + ('~-2', '(1)'), # unary invert + ('+1', '(1)'), # unary positive ): - code = compile(line, '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', elem) - for instr in dis.get_instructions(code): - self.assertFalse(instr.opname.startswith('UNARY_')) + asm = dis_single(line) + self.assertIn(elem, asm, asm) + self.assertNotIn('UNARY_', asm) # Check that -0.0 works after marshaling def negzero(): return -(1.0-1.0) - for instr in dis.get_instructions(code): - self.assertFalse(instr.opname.startswith('UNARY_')) + self.assertNotIn('UNARY_', disassemble(negzero)) + self.assertTrue(copysign(1.0, negzero()) < 0) # Verify that unfoldables are skipped - for line, elem, opname in ( - ('-"abc"', 'abc', 'UNARY_NEGATIVE'), - ('~"abc"', 'abc', 'UNARY_INVERT'), + for line, elem in ( + ('-"abc"', "('abc')"), # unary negative + ('~"abc"', "('abc')"), # unary invert ): - code = compile(line, '', 'single') - self.assertInBytecode(code, 'LOAD_CONST', elem) - self.assertInBytecode(code, opname) + asm = dis_single(line) + self.assertIn(elem, asm, asm) + self.assertIn('UNARY_', asm) def test_elim_extra_return(self): # RETURN LOAD_CONST None RETURN --> RETURN def f(x): return x - self.assertNotInBytecode(f, 'LOAD_CONST', None) - returns = [instr for instr in dis.get_instructions(f) - if instr.opname == 'RETURN_VALUE'] - self.assertEqual(len(returns), 1) + asm = disassemble(f) + self.assertNotIn('LOAD_CONST', asm) + self.assertNotIn('(None)', asm) + self.assertEqual(asm.split().count('RETURN_VALUE'), 1) def test_elim_jump_to_return(self): # JUMP_FORWARD to RETURN --> RETURN def f(cond, true_value, false_value): return true_value if cond else false_value - self.assertNotInBytecode(f, 'JUMP_FORWARD') - self.assertNotInBytecode(f, 'JUMP_ABSOLUTE') - returns = [instr for instr in dis.get_instructions(f) - if instr.opname == 'RETURN_VALUE'] - self.assertEqual(len(returns), 2) + asm = disassemble(f) + self.assertNotIn('JUMP_FORWARD', asm) + self.assertNotIn('JUMP_ABSOLUTE', asm) + self.assertEqual(asm.split().count('RETURN_VALUE'), 2) def test_elim_jump_after_return1(self): # Eliminate dead code: jumps immediately after returns can't be reached @@ -258,53 +280,48 @@ if cond1: return 4 return 5 return 6 - self.assertNotInBytecode(f, 'JUMP_FORWARD') - self.assertNotInBytecode(f, 'JUMP_ABSOLUTE') - returns = [instr for instr in dis.get_instructions(f) - if instr.opname == 'RETURN_VALUE'] - self.assertEqual(len(returns), 6) + asm = disassemble(f) + self.assertNotIn('JUMP_FORWARD', asm) + self.assertNotIn('JUMP_ABSOLUTE', asm) + self.assertEqual(asm.split().count('RETURN_VALUE'), 6) def test_elim_jump_after_return2(self): # Eliminate dead code: jumps immediately after returns can't be reached def f(cond1, cond2): while 1: if cond1: return 4 - self.assertNotInBytecode(f, 'JUMP_FORWARD') + asm = disassemble(f) + self.assertNotIn('JUMP_FORWARD', asm) # There should be one jump for the while loop. - returns = [instr for instr in dis.get_instructions(f) - if instr.opname == 'JUMP_ABSOLUTE'] - self.assertEqual(len(returns), 1) - returns = [instr for instr in dis.get_instructions(f) - if instr.opname == 'RETURN_VALUE'] - self.assertEqual(len(returns), 2) + self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1) + self.assertEqual(asm.split().count('RETURN_VALUE'), 2) def test_make_function_doesnt_bail(self): def f(): def g()->1+1: pass return g - self.assertNotInBytecode(f, 'BINARY_ADD') + asm = disassemble(f) + self.assertNotIn('BINARY_ADD', asm) def test_constant_folding(self): # Issue #11244: aggressive constant folding. exprs = [ - '3 * -5', - '-3 * 5', - '2 * (3 * 4)', - '(2 * 3) * 4', - '(-1, 2, 3)', - '(1, -2, 3)', - '(1, 2, -3)', - '(1, 2, -3) * 6', - 'lambda x: x in {(3 * -5) + (-1 - 6), (1, -2, 3) * 2, None}', + "3 * -5", + "-3 * 5", + "2 * (3 * 4)", + "(2 * 3) * 4", + "(-1, 2, 3)", + "(1, -2, 3)", + "(1, 2, -3)", + "(1, 2, -3) * 6", + "lambda x: x in {(3 * -5) + (-1 - 6), (1, -2, 3) * 2, None}", ] for e in exprs: - code = compile(e, '', 'single') - for instr in dis.get_instructions(code): - self.assertFalse(instr.opname.startswith('UNARY_')) - self.assertFalse(instr.opname.startswith('BINARY_')) - self.assertFalse(instr.opname.startswith('BUILD_')) - + asm = dis_single(e) + self.assertNotIn('UNARY_', asm, e) + self.assertNotIn('BINARY_', asm, e) + self.assertNotIn('BUILD_', asm, e) class TestBuglets(unittest.TestCase): @@ -326,7 +343,7 @@ support.run_unittest(*test_classes) # verify reference counting - if verbose and hasattr(sys, 'gettotalrefcount'): + if verbose and hasattr(sys, "gettotalrefcount"): import gc counts = [None] * 5 for i in range(len(counts)): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pep263.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_pep263.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,62 @@ +# -*- coding: koi8-r -*- + +import unittest +from test import support + +class PEP263Test(unittest.TestCase): + + def test_pep263(self): + self.assertEqual( + "ðÉÔÏÎ".encode("utf-8"), + b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' + ) + self.assertEqual( + "\ð".encode("utf-8"), + b'\\\xd0\x9f' + ) + + def test_compilestring(self): + # see #1882 + c = compile(b"\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec") + d = {} + exec(c, d) + self.assertEqual(d['u'], '\xf3') + + def test_issue2301(self): + try: + compile(b"# coding: cp932\nprint '\x94\x4e'", "dummy", "exec") + except SyntaxError as v: + self.assertEqual(v.text, "print '\u5e74'\n") + else: + self.fail() + + def test_issue4626(self): + c = compile("# coding=latin-1\n\u00c6 = '\u00c6'", "dummy", "exec") + d = {} + exec(c, d) + self.assertEqual(d['\xc6'], '\xc6') + + def test_issue3297(self): + c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec") + d = {} + exec(c, d) + self.assertEqual(d['a'], d['b']) + self.assertEqual(len(d['a']), len(d['b'])) + self.assertEqual(ascii(d['a']), ascii(d['b'])) + + def test_issue7820(self): + # Ensure that check_bom() restores all bytes in the right order if + # check_bom() fails in pydebug mode: a buffer starts with the first + # byte of a valid BOM, but next bytes are different + + # one byte in common with the UTF-16-LE BOM + self.assertRaises(SyntaxError, eval, b'\xff\x20') + + # two bytes in common with the UTF-8 BOM + self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20') + +def test_main(): + support.run_unittest(PEP263Test) + +if __name__=="__main__": + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pep352.py --- a/Lib/test/test_pep352.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pep352.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,7 @@ import unittest import builtins import warnings +from test.support import run_unittest import os from platform import system as platform_system @@ -179,6 +180,8 @@ # Catching a string is bad. self.catch_fails("spam") +def test_main(): + run_unittest(ExceptionClassTests, UsageTests) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pickle.py --- a/Lib/test/test_pickle.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pickle.py Fri Feb 01 23:12:09 2013 +0100 @@ -115,15 +115,6 @@ pickler_class = _pickle.Pickler unpickler_class = _pickle.Unpickler - def test_issue18339(self): - unpickler = self.unpickler_class(io.BytesIO()) - with self.assertRaises(TypeError): - unpickler.memo = object - # used to cause a segfault - with self.assertRaises(ValueError): - unpickler.memo = {-1: None} - unpickler.memo = {1: None} - class CDispatchTableTests(AbstractDispatchTableTests): pickler_class = pickle.Pickler def get_dispatch_table(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pkgimport.py --- a/Lib/test/test_pkgimport.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pkgimport.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,7 @@ import tempfile import unittest -from importlib.util import cache_from_source +from imp import cache_from_source from test.support import run_unittest, create_empty_file class TestImport(unittest.TestCase): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pkgutil.py --- a/Lib/test/test_pkgutil.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pkgutil.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,12 +1,11 @@ from test.support import run_unittest, unload, check_warnings import unittest import sys -import importlib +import imp import pkgutil import os import os.path import tempfile -import types import shutil import zipfile @@ -105,7 +104,7 @@ class MyTestLoader(object): def load_module(self, fullname): # Create an empty module - mod = sys.modules.setdefault(fullname, types.ModuleType(fullname)) + mod = sys.modules.setdefault(fullname, imp.new_module(fullname)) mod.__file__ = "<%s>" % self.__class__.__name__ mod.__loader__ = self # Make it a package @@ -188,44 +187,6 @@ del sys.modules['foo.bar'] del sys.modules['foo.baz'] - - # Another awful testing hack to be cleaned up once the test_runpy - # helpers are factored out to a common location - def test_iter_importers(self): - iter_importers = pkgutil.iter_importers - get_importer = pkgutil.get_importer - - pkgname = 'spam' - modname = 'eggs' - dirname = self.create_init(pkgname) - pathitem = os.path.join(dirname, pkgname) - fullname = '{}.{}'.format(pkgname, modname) - try: - self.create_submodule(dirname, pkgname, modname, 0) - - importlib.import_module(fullname) - - importers = list(iter_importers(fullname)) - expected_importer = get_importer(pathitem) - for finder in importers: - self.assertIsInstance(finder, importlib.machinery.FileFinder) - self.assertEqual(finder, expected_importer) - self.assertIsInstance(finder.find_module(fullname), - importlib.machinery.SourceFileLoader) - self.assertIsNone(finder.find_module(pkgname)) - - with self.assertRaises(ImportError): - list(iter_importers('invalid.module')) - - with self.assertRaises(ImportError): - list(iter_importers('.spam')) - finally: - shutil.rmtree(dirname) - del sys.path[0] - del sys.modules['spam'] - del sys.modules['spam.eggs'] - - def test_mixed_namespace(self): pkgname = 'foo' dirname_0 = self.create_init(pkgname) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_plistlib.py Fri Feb 01 23:12:09 2013 +0100 @@ -141,18 +141,6 @@ data2 = plistlib.writePlistToBytes(pl2) self.assertEqual(data, data2) - def test_indentation_array(self): - data = [[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]] - self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data) - - def test_indentation_dict(self): - data = {'1': {'2': {'3': {'4': {'5': {'6': {'7': {'8': {'9': plistlib.Data(b'aaaaaa')}}}}}}}}} - self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data) - - def test_indentation_dict_mix(self): - data = {'1': {'2': [{'3': [[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]}]}} - self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data) - def test_appleformatting(self): pl = plistlib.readPlistFromBytes(TESTDATA) data = plistlib.writePlistToBytes(pl) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_posix.py Fri Feb 01 23:12:09 2013 +0100 @@ -404,44 +404,22 @@ else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) - def _test_all_chown_common(self, chown_func, first_param, stat_func): + def _test_all_chown_common(self, chown_func, first_param): """Common code for chown, fchown and lchown tests.""" - def check_stat(uid, gid): - if stat_func is not None: - stat = stat_func(first_param) - self.assertEqual(stat.st_uid, uid) - self.assertEqual(stat.st_gid, gid) - uid = os.getuid() - gid = os.getgid() # test a successful chown call - chown_func(first_param, uid, gid) - check_stat(uid, gid) - chown_func(first_param, -1, gid) - check_stat(uid, gid) - chown_func(first_param, uid, -1) - check_stat(uid, gid) + chown_func(first_param, os.getuid(), os.getgid()) - if uid == 0: - # Try an amusingly large uid/gid to make sure we handle - # large unsigned values. (chown lets you use any - # uid/gid you like, even if they aren't defined.) - # - # This problem keeps coming up: - # http://bugs.python.org/issue1747858 - # http://bugs.python.org/issue4591 - # http://bugs.python.org/issue15301 - # Hopefully the fix in 4591 fixes it for good! - # - # This part of the test only runs when run as root. - # Only scary people run their tests as root. - - big_value = 2**31 - chown_func(first_param, big_value, big_value) - check_stat(big_value, big_value) - chown_func(first_param, -1, -1) - check_stat(big_value, big_value) - chown_func(first_param, uid, gid) - check_stat(uid, gid) + if os.getuid() == 0: + try: + # Many linux distros have a nfsnobody user as MAX_UID-2 + # that makes a good test case for signedness issues. + # http://bugs.python.org/issue1747858 + # This part of the test only runs when run as root. + # Only scary people run their tests as root. + ent = pwd.getpwnam('nfsnobody') + chown_func(first_param, ent.pw_uid, ent.pw_gid) + except KeyError: + pass elif platform.system() in ('HP-UX', 'SunOS'): # HP-UX and Solaris can allow a non-root user to chown() to root # (issue #5113) @@ -449,19 +427,8 @@ "behavior") else: # non-root cannot chown to root, raises OSError - self.assertRaises(OSError, chown_func, first_param, 0, 0) - check_stat(uid, gid) - self.assertRaises(OSError, chown_func, first_param, 0, -1) - check_stat(uid, gid) - if 0 not in os.getgroups(): - self.assertRaises(OSError, chown_func, first_param, -1, 0) - check_stat(uid, gid) - # test illegal types - for t in str, float: - self.assertRaises(TypeError, chown_func, first_param, t(uid), gid) - check_stat(uid, gid) - self.assertRaises(TypeError, chown_func, first_param, uid, t(gid)) - check_stat(uid, gid) + self.assertRaises(OSError, chown_func, + first_param, 0, 0) @unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()") def test_chown(self): @@ -471,8 +438,7 @@ # re-create the file support.create_empty_file(support.TESTFN) - self._test_all_chown_common(posix.chown, support.TESTFN, - getattr(posix, 'stat', None)) + self._test_all_chown_common(posix.chown, support.TESTFN) @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()") def test_fchown(self): @@ -482,8 +448,7 @@ test_file = open(support.TESTFN, 'w') try: fd = test_file.fileno() - self._test_all_chown_common(posix.fchown, fd, - getattr(posix, 'fstat', None)) + self._test_all_chown_common(posix.fchown, fd) finally: test_file.close() @@ -492,8 +457,7 @@ os.unlink(support.TESTFN) # create a symlink os.symlink(_DUMMY_SYMLINK, support.TESTFN) - self._test_all_chown_common(posix.lchown, support.TESTFN, - getattr(posix, 'lstat', None)) + self._test_all_chown_common(posix.lchown, support.TESTFN) def test_chdir(self): if hasattr(posix, 'chdir'): @@ -718,13 +682,6 @@ if ret is not None or not groups: raise unittest.SkipTest("need working 'id -G'") - # Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups() - if sys.platform == 'darwin': - import sysconfig - dt = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') or '10.0' - if float(dt) < 10.6: - raise unittest.SkipTest("getgroups(2) is broken prior to 10.6") - # 'id -G' and 'os.getgroups()' should return the same # groups, ignoring order and duplicates. # #10822 - it is implementation defined whether posix.getgroups() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_posixpath.py Fri Feb 01 23:12:09 2013 +0100 @@ -261,8 +261,7 @@ # expanduser should fall back to using the password database del env['HOME'] home = pwd.getpwuid(os.getuid()).pw_dir - # $HOME can end with a trailing /, so strip it (see #17809) - self.assertEqual(posixpath.expanduser("~"), home.rstrip("/")) + self.assertEqual(posixpath.expanduser("~"), home) def test_normpath(self): self.assertEqual(posixpath.normpath(""), ".") @@ -284,26 +283,6 @@ self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"), b"/foo/bar") - @skip_if_ABSTFN_contains_backslash - def test_realpath_curdir(self): - self.assertEqual(realpath('.'), os.getcwd()) - self.assertEqual(realpath('./.'), os.getcwd()) - self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd()) - - self.assertEqual(realpath(b'.'), os.getcwdb()) - self.assertEqual(realpath(b'./.'), os.getcwdb()) - self.assertEqual(realpath(b'/'.join([b'.'] * 100)), os.getcwdb()) - - @skip_if_ABSTFN_contains_backslash - def test_realpath_pardir(self): - self.assertEqual(realpath('..'), dirname(os.getcwd())) - self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd()))) - self.assertEqual(realpath('/'.join(['..'] * 100)), '/') - - self.assertEqual(realpath(b'..'), dirname(os.getcwdb())) - self.assertEqual(realpath(b'../..'), dirname(dirname(os.getcwdb()))) - self.assertEqual(realpath(b'/'.join([b'..'] * 100)), b'/') - @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash @@ -341,22 +320,6 @@ self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1") self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2") - self.assertEqual(realpath(ABSTFN+"1/x"), ABSTFN+"1/x") - self.assertEqual(realpath(ABSTFN+"1/.."), dirname(ABSTFN)) - self.assertEqual(realpath(ABSTFN+"1/../x"), dirname(ABSTFN) + "/x") - os.symlink(ABSTFN+"x", ABSTFN+"y") - self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "y"), - ABSTFN + "y") - self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "1"), - ABSTFN + "1") - - os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a") - self.assertEqual(realpath(ABSTFN+"a"), ABSTFN+"a/b") - - os.symlink("../" + basename(dirname(ABSTFN)) + "/" + - basename(ABSTFN) + "c", ABSTFN+"c") - self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c") - # Test using relative path as well. os.chdir(dirname(ABSTFN)) self.assertEqual(realpath(basename(ABSTFN)), ABSTFN) @@ -365,46 +328,6 @@ support.unlink(ABSTFN) support.unlink(ABSTFN+"1") support.unlink(ABSTFN+"2") - support.unlink(ABSTFN+"y") - support.unlink(ABSTFN+"c") - support.unlink(ABSTFN+"a") - - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") - @skip_if_ABSTFN_contains_backslash - def test_realpath_repeated_indirect_symlinks(self): - # Issue #6975. - try: - os.mkdir(ABSTFN) - os.symlink('../' + basename(ABSTFN), ABSTFN + '/self') - os.symlink('self/self/self', ABSTFN + '/link') - self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN) - finally: - support.unlink(ABSTFN + '/self') - support.unlink(ABSTFN + '/link') - safe_rmdir(ABSTFN) - - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") - @skip_if_ABSTFN_contains_backslash - def test_realpath_deep_recursion(self): - depth = 10 - old_path = abspath('.') - try: - os.mkdir(ABSTFN) - for i in range(depth): - os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1)) - os.symlink('.', ABSTFN + '/0') - self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN) - - # Test using relative path as well. - os.chdir(ABSTFN) - self.assertEqual(realpath('%d' % depth), ABSTFN) - finally: - os.chdir(old_path) - for i in range(depth + 1): - support.unlink(ABSTFN + '/%d' % i) - safe_rmdir(ABSTFN) @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pprint.py --- a/Lib/test/test_pprint.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pprint.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import pprint import test.support import unittest @@ -477,42 +475,6 @@ self.assertEqual(pprint.pformat(dict.fromkeys(keys, 0)), '{%r: 0, %r: 0}' % tuple(sorted(keys, key=id))) - def test_str_wrap(self): - # pprint tries to wrap strings intelligently - fox = 'the quick brown fox jumped over a lazy dog' - self.assertEqual(pprint.pformat(fox, width=20), """\ -'the quick brown ' -'fox jumped over ' -'a lazy dog'""") - self.assertEqual(pprint.pformat({'a': 1, 'b': fox, 'c': 2}, - width=26), """\ -{'a': 1, - 'b': 'the quick brown ' - 'fox jumped over ' - 'a lazy dog', - 'c': 2}""") - # With some special characters - # - \n always triggers a new line in the pprint - # - \t and \n are escaped - # - non-ASCII is allowed - # - an apostrophe doesn't disrupt the pprint - special = "Portons dix bons \"whiskys\"\nà l'avocat goujat\t qui fumait au zoo" - self.assertEqual(pprint.pformat(special, width=20), """\ -'Portons dix bons ' -'"whiskys"\\n' -"à l'avocat " -'goujat\\t qui ' -'fumait au zoo'""") - # An unwrappable string is formatted as its repr - unwrappable = "x" * 100 - self.assertEqual(pprint.pformat(unwrappable, width=80), repr(unwrappable)) - self.assertEqual(pprint.pformat(''), "''") - # Check that the pprint is a usable repr - special *= 10 - for width in range(3, 40): - formatted = pprint.pformat(special, width=width) - self.assertEqual(eval("(" + formatted + ")"), special) - class DottedPrettyPrinter(pprint.PrettyPrinter): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_print.py --- a/Lib/test/test_print.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_print.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,55 +1,62 @@ +"""Test correct operation of the print function. +""" + +# In 2.6, this gives us the behavior we want. In 3.0, it has +# no function, but it still must parse correctly. +from __future__ import print_function + import unittest -from io import StringIO +from test import support -from test import support +try: + # 3.x + from io import StringIO +except ImportError: + # 2.x + from StringIO import StringIO NotDefined = object() # A dispatch table all 8 combinations of providing -# sep, end, and file. +# sep, end, and file # I use this machinery so that I'm not just passing default -# values to print, I'm either passing or not passing in the -# arguments. +# values to print, I'm either passing or not passing in the +# arguments dispatch = { (False, False, False): - lambda args, sep, end, file: print(*args), + lambda args, sep, end, file: print(*args), (False, False, True): - lambda args, sep, end, file: print(file=file, *args), + lambda args, sep, end, file: print(file=file, *args), (False, True, False): - lambda args, sep, end, file: print(end=end, *args), + lambda args, sep, end, file: print(end=end, *args), (False, True, True): - lambda args, sep, end, file: print(end=end, file=file, *args), + lambda args, sep, end, file: print(end=end, file=file, *args), (True, False, False): - lambda args, sep, end, file: print(sep=sep, *args), + lambda args, sep, end, file: print(sep=sep, *args), (True, False, True): - lambda args, sep, end, file: print(sep=sep, file=file, *args), + lambda args, sep, end, file: print(sep=sep, file=file, *args), (True, True, False): - lambda args, sep, end, file: print(sep=sep, end=end, *args), + lambda args, sep, end, file: print(sep=sep, end=end, *args), (True, True, True): - lambda args, sep, end, file: print(sep=sep, end=end, file=file, *args), -} - + lambda args, sep, end, file: print(sep=sep, end=end, file=file, *args), + } # Class used to test __str__ and print class ClassWith__str__: def __init__(self, x): self.x = x - def __str__(self): return self.x +class TestPrint(unittest.TestCase): + def check(self, expected, args, + sep=NotDefined, end=NotDefined, file=NotDefined): + # Capture sys.stdout in a StringIO. Call print with args, + # and with sep, end, and file, if they're defined. Result + # must match expected. -class TestPrint(unittest.TestCase): - """Test correct operation of the print function.""" - - def check(self, expected, args, - sep=NotDefined, end=NotDefined, file=NotDefined): - # Capture sys.stdout in a StringIO. Call print with args, - # and with sep, end, and file, if they're defined. Result - # must match expected. - - # Look up the actual function to call, based on if sep, end, - # and file are defined. + # Look up the actual function to call, based on if sep, end, and file + # are defined fn = dispatch[(sep is not NotDefined, end is not NotDefined, file is not NotDefined)] @@ -62,7 +69,7 @@ def test_print(self): def x(expected, args, sep=NotDefined, end=NotDefined): # Run the test 2 ways: not using file, and using - # file directed to a StringIO. + # file directed to a StringIO self.check(expected, args, sep=sep, end=end) @@ -94,6 +101,11 @@ x('*\n', (ClassWith__str__('*'),)) x('abc 1\n', (ClassWith__str__('abc'), 1)) +# # 2.x unicode tests +# x(u'1 2\n', ('1', u'2')) +# x(u'u\1234\n', (u'u\1234',)) +# x(u' abc 1\n', (' ', ClassWith__str__(u'abc'), 1)) + # errors self.assertRaises(TypeError, print, '', sep=3) self.assertRaises(TypeError, print, '', end=3) @@ -101,14 +113,12 @@ def test_print_flush(self): # operation of the flush flag - class filelike: + class filelike(): def __init__(self): self.written = '' self.flushed = 0 - def write(self, str): self.written += str - def flush(self): self.flushed += 1 @@ -120,13 +130,15 @@ self.assertEqual(f.flushed, 2) # ensure exceptions from flush are passed through - class noflush: + class noflush(): def write(self, str): pass - def flush(self): raise RuntimeError self.assertRaises(RuntimeError, print, 1, file=noflush(), flush=True) +def test_main(): + support.run_unittest(TestPrint) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_profile.py --- a/Lib/test/test_profile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_profile.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,11 +3,9 @@ import sys import pstats import unittest -import os from difflib import unified_diff from io import StringIO -from test.support import TESTFN, run_unittest, unlink -from contextlib import contextmanager +from test.support import run_unittest import profile from test.profilee import testfunc, timer @@ -16,13 +14,9 @@ class ProfileTest(unittest.TestCase): profilerclass = profile.Profile - profilermodule = profile methodnames = ['print_stats', 'print_callers', 'print_callees'] expected_max_output = ':0(max)' - def tearDown(self): - unlink(TESTFN) - def get_expected_output(self): return _ProfileOutput @@ -80,19 +74,6 @@ self.assertIn(self.expected_max_output, res, "Profiling {0!r} didn't report max:\n{1}".format(stmt, res)) - def test_run(self): - with silent(): - self.profilermodule.run("int('1')") - self.profilermodule.run("int('1')", filename=TESTFN) - self.assertTrue(os.path.exists(TESTFN)) - - def test_runctx(self): - with silent(): - self.profilermodule.runctx("testfunc()", globals(), locals()) - self.profilermodule.runctx("testfunc()", globals(), locals(), - filename=TESTFN) - self.assertTrue(os.path.exists(TESTFN)) - def regenerate_expected_output(filename, cls): filename = filename.rstrip('co') @@ -114,14 +95,6 @@ method, results[i+1])) f.write('\nif __name__ == "__main__":\n main()\n') -@contextmanager -def silent(): - stdout = sys.stdout - try: - sys.stdout = StringIO() - yield - finally: - sys.stdout = stdout def test_main(): run_unittest(ProfileTest) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_property.py --- a/Lib/test/test_property.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_property.py Fri Feb 01 23:12:09 2013 +0100 @@ -186,7 +186,7 @@ Foo.spam.__doc__, "spam wrapped in property subclass") - @unittest.skipIf(sys.flags.optimize >= 2, + @unittest.skipIf(sys.flags.optimize <= 2, "Docstrings are omitted with -O2 and above") def test_property_setter_copies_getter_docstring(self): class Foo(object): @@ -219,7 +219,7 @@ FooSub.spam.__doc__, "spam wrapped in property subclass") - @unittest.skipIf(sys.flags.optimize >= 2, + @unittest.skipIf(sys.flags.optimize <= 2, "Docstrings are omitted with -O2 and above") def test_property_new_getter_new_docstring(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pwd.py --- a/Lib/test/test_pwd.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pwd.py Fri Feb 01 23:12:09 2013 +0100 @@ -49,9 +49,7 @@ def test_errors(self): self.assertRaises(TypeError, pwd.getpwuid) - self.assertRaises(TypeError, pwd.getpwuid, 3.14) self.assertRaises(TypeError, pwd.getpwnam) - self.assertRaises(TypeError, pwd.getpwnam, 42) self.assertRaises(TypeError, pwd.getpwall, 42) # try to get some errors @@ -95,13 +93,6 @@ self.assertNotIn(fakeuid, byuids) self.assertRaises(KeyError, pwd.getpwuid, fakeuid) - # -1 shouldn't be a valid uid because it has a special meaning in many - # uid-related functions - self.assertRaises(KeyError, pwd.getpwuid, -1) - # should be out of uid_t range - self.assertRaises(KeyError, pwd.getpwuid, 2**128) - self.assertRaises(KeyError, pwd.getpwuid, -2**128) - def test_main(): support.run_unittest(PwdTest) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_py_compile.py --- a/Lib/test/test_py_compile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_py_compile.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,7 @@ -import importlib.util +import imp import os import py_compile import shutil -import stat import tempfile import unittest @@ -14,7 +13,7 @@ self.directory = tempfile.mkdtemp() self.source_path = os.path.join(self.directory, '_test.py') self.pyc_path = self.source_path + 'c' - self.cache_path = importlib.util.cache_from_source(self.source_path) + self.cache_path = imp.cache_from_source(self.source_path) self.cwd_drive = os.path.splitdrive(os.getcwd())[0] # In these tests we compute relative paths. When using Windows, the # current working directory path and the 'self.source_path' might be @@ -36,26 +35,6 @@ self.assertTrue(os.path.exists(self.pyc_path)) self.assertFalse(os.path.exists(self.cache_path)) - def test_do_not_overwrite_symlinks(self): - # In the face of a cfile argument being a symlink, bail out. - # Issue #17222 - try: - os.symlink(self.pyc_path + '.actual', self.pyc_path) - except (NotImplementedError, OSError): - self.skipTest('need to be able to create a symlink for a file') - else: - assert os.path.islink(self.pyc_path) - with self.assertRaises(FileExistsError): - py_compile.compile(self.source_path, self.pyc_path) - - @unittest.skipIf(not os.path.exists(os.devnull) or os.path.isfile(os.devnull), - 'requires os.devnull and for it to be a non-regular file') - def test_do_not_overwrite_nonregular_files(self): - # In the face of a cfile argument being a non-regular file, bail out. - # Issue #17222 - with self.assertRaises(FileExistsError): - py_compile.compile(self.source_path, os.devnull) - def test_cache_path(self): py_compile.compile(self.source_path) self.assertTrue(os.path.exists(self.cache_path)) @@ -75,20 +54,8 @@ self.assertTrue(os.path.exists(self.pyc_path)) self.assertFalse(os.path.exists(self.cache_path)) - @unittest.skipIf(os.name == 'nt', - 'cannot control directory permissions on Windows') - def test_exceptions_propagate(self): - # Make sure that exceptions raised thanks to issues with writing - # bytecode. - # http://bugs.python.org/issue17244 - mode = os.stat(self.directory) - os.chmod(self.directory, stat.S_IREAD) - try: - with self.assertRaises(IOError): - py_compile.compile(self.source_path, self.pyc_path) - finally: - os.chmod(self.directory, mode.st_mode) - +def test_main(): + support.run_unittest(PyCompileTests) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pyclbr.py --- a/Lib/test/test_pyclbr.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pyclbr.py Fri Feb 01 23:12:09 2013 +0100 @@ -158,7 +158,7 @@ cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator cm('cgi', ignore=('log',)) # set with = in module cm('pickle') - cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module + cm('aifc', ignore=('openfp',)) # set with = in module cm('sre_parse', ignore=('dump',)) # from sre_constants import * cm('pdb') cm('pydoc') diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pydoc.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,12 +1,10 @@ import os import sys import builtins -import contextlib import difflib import inspect import pydoc import keyword -import pkgutil import re import string import test.support @@ -19,8 +17,7 @@ from test.script_helper import assert_python_ok from test.support import ( TESTFN, rmtree, - reap_children, reap_threads, captured_output, captured_stdout, - captured_stderr, unlink + reap_children, reap_threads, captured_output, captured_stdout, unlink ) from test import pydoc_mod @@ -29,13 +26,9 @@ except ImportError: threading = None -if test.support.HAVE_DOCSTRINGS: - expected_data_docstrings = ( - 'dictionary for instance variables (if defined)', - 'list of weak references to the object (if defined)', - ) * 2 -else: - expected_data_docstrings = ('', '', '', '') +# Just in case sys.modules["test"] has the optional attribute __loader__. +if hasattr(pydoc_mod, "__loader__"): + del pydoc_mod.__loader__ expected_text_pattern = """ NAME @@ -57,16 +50,20 @@ | ---------------------------------------------------------------------- | Data descriptors defined here: |\x20\x20 - | __dict__%s + | __dict__ + | dictionary for instance variables (if defined) |\x20\x20 - | __weakref__%s + | __weakref__ + | list of weak references to the object (if defined) \x20\x20\x20\x20 class B(builtins.object) | Data descriptors defined here: |\x20\x20 - | __dict__%s + | __dict__ + | dictionary for instance variables (if defined) |\x20\x20 - | __weakref__%s + | __weakref__ + | list of weak references to the object (if defined) |\x20\x20 | ---------------------------------------------------------------------- | Data and other attributes defined here: @@ -98,9 +95,6 @@ %s """.strip() -expected_text_data_docstrings = tuple('\n | ' + s if s else '' - for s in expected_data_docstrings) - expected_html_pattern = """ @@ -140,10 +134,10 @@
Data descriptors defined here:
__dict__
-
%s
+
dictionary for instance variables (if defined)
__weakref__
-
%s
+
list of weak references to the object (if defined)

@@ -154,10 +148,10 @@
     Data descriptors defined here:
__dict__
-
%s
+
dictionary for instance variables (if defined)
__weakref__
-
%s
+
list of weak references to the object (if defined)

Data and other attributes defined here:
@@ -199,8 +193,6 @@
Nobody
""".strip() # ' <- emacs turd -expected_html_data_docstrings = tuple(s.replace(' ', ' ') - for s in expected_data_docstrings) # output pattern for missing module missing_pattern = "no Python documentation found for '%s'" @@ -258,29 +250,6 @@ return title -class PydocBaseTest(unittest.TestCase): - - def _restricted_walk_packages(self, walk_packages, path=None): - """ - A version of pkgutil.walk_packages() that will restrict itself to - a given path. - """ - default_path = path or [os.path.dirname(__file__)] - def wrapper(path=None, prefix='', onerror=None): - return walk_packages(path or default_path, prefix, onerror) - return wrapper - - @contextlib.contextmanager - def restrict_walk_packages(self, path=None): - walk_packages = pkgutil.walk_packages - pkgutil.walk_packages = self._restricted_walk_packages(walk_packages, - path) - try: - yield - finally: - pkgutil.walk_packages = walk_packages - - class PydocDocTest(unittest.TestCase): @unittest.skipIf(sys.flags.optimize >= 2, @@ -295,9 +264,7 @@ mod_url = nturl2path.pathname2url(mod_file) else: mod_url = mod_file - expected_html = expected_html_pattern % ( - (mod_url, mod_file, doc_loc) + - expected_html_data_docstrings) + expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc) if result != expected_html: print_diffs(expected_html, result) self.fail("outputs are not equal, see diff above") @@ -308,10 +275,8 @@ 'trace function introduces __locals__ unexpectedly') def test_text_doc(self): result, doc_loc = get_pydoc_text(pydoc_mod) - expected_text = expected_text_pattern % ( - (doc_loc,) + - expected_text_data_docstrings + - (inspect.getabsfile(pydoc_mod),)) + expected_text = expected_text_pattern % \ + (doc_loc, inspect.getabsfile(pydoc_mod)) if result != expected_text: print_diffs(expected_text, result) self.fail("outputs are not equal, see diff above") @@ -387,10 +352,8 @@ captured_output('stderr') as err: helper.help(module) result = buf.getvalue().strip() - expected_text = expected_help_pattern % ( - (doc_loc,) + - expected_text_data_docstrings + - (inspect.getabsfile(pydoc_mod),)) + expected_text = expected_help_pattern % \ + (doc_loc, inspect.getabsfile(pydoc_mod)) self.assertEqual('', output.getvalue()) self.assertEqual('', err.getvalue()) self.assertEqual(expected_text, result) @@ -417,57 +380,8 @@ synopsis = pydoc.synopsis(TESTFN, {}) self.assertEqual(synopsis, 'line 1: h\xe9') - def test_splitdoc_with_description(self): - example_string = "I Am A Doc\n\n\nHere is my description" - self.assertEqual(pydoc.splitdoc(example_string), - ('I Am A Doc', '\nHere is my description')) - def test_is_object_or_method(self): - doc = pydoc.Doc() - # Bound Method - self.assertTrue(pydoc._is_some_method(doc.fail)) - # Method Descriptor - self.assertTrue(pydoc._is_some_method(int.__add__)) - # String - self.assertFalse(pydoc._is_some_method("I am not a method")) - - def test_is_package_when_not_package(self): - with test.support.temp_cwd() as test_dir: - self.assertFalse(pydoc.ispackage(test_dir)) - - def test_is_package_when_is_package(self): - with test.support.temp_cwd() as test_dir: - init_path = os.path.join(test_dir, '__init__.py') - open(init_path, 'w').close() - self.assertTrue(pydoc.ispackage(test_dir)) - os.remove(init_path) - - def test_allmethods(self): - # issue 17476: allmethods was no longer returning unbound methods. - # This test is a bit fragile in the face of changes to object and type, - # but I can't think of a better way to do it without duplicating the - # logic of the function under test. - - class TestClass(object): - def method_returning_true(self): - return True - - # What we expect to get back: everything on object... - expected = dict(vars(object)) - # ...plus our unbound method... - expected['method_returning_true'] = TestClass.method_returning_true - # ...but not the non-methods on object. - del expected['__doc__'] - del expected['__class__'] - # inspect resolves descriptors on type into methods, but vars doesn't, - # so we need to update __subclasshook__. - expected['__subclasshook__'] = TestClass.__subclasshook__ - - methods = pydoc.allmethods(TestClass) - self.assertDictEqual(methods, expected) - - -class PydocImportTest(PydocBaseTest): +class PydocImportTest(unittest.TestCase): def setUp(self): self.test_dir = os.mkdir(TESTFN) @@ -501,19 +415,8 @@ badsyntax = os.path.join(pkgdir, "__init__") + os.extsep + "py" with open(badsyntax, 'w') as f: f.write("invalid python syntax = $1\n") - with self.restrict_walk_packages(path=[TESTFN]): - with captured_stdout() as out: - with captured_stderr() as err: - pydoc.apropos('xyzzy') - # No result, no error - self.assertEqual(out.getvalue(), '') - self.assertEqual(err.getvalue(), '') - # The package name is still matched - with captured_stdout() as out: - with captured_stderr() as err: - pydoc.apropos('syntaxerr') - self.assertEqual(out.getvalue().strip(), 'syntaxerr') - self.assertEqual(err.getvalue(), '') + result = run_pydoc('zqwykjv', '-k', PYTHONPATH=TESTFN) + self.assertEqual(b'', result) def test_apropos_with_unreadable_dir(self): # Issue 7367 - pydoc -k failed when unreadable dir on path @@ -522,13 +425,8 @@ self.addCleanup(os.rmdir, self.unreadable_dir) # Note, on Windows the directory appears to be still # readable so this is not really testing the issue there - with self.restrict_walk_packages(path=[TESTFN]): - with captured_stdout() as out: - with captured_stderr() as err: - pydoc.apropos('SOMEKEY') - # No result, no error - self.assertEqual(out.getvalue(), '') - self.assertEqual(err.getvalue(), '') + result = run_pydoc('zqwykjv', '-k', PYTHONPATH=TESTFN) + self.assertEqual(b'', result) class TestDescriptions(unittest.TestCase): @@ -590,7 +488,7 @@ self.assertEqual(serverthread.error, None) -class PydocUrlHandlerTest(PydocBaseTest): +class PydocUrlHandlerTest(unittest.TestCase): """Tests for pydoc._url_handler""" def test_content_type_err(self): @@ -617,19 +515,18 @@ ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"), ] - with self.restrict_walk_packages(): - for url, title in requests: - text = pydoc._url_handler(url, "text/html") - result = get_html_title(text) - self.assertEqual(result, title, text) - - path = string.__file__ - title = "Pydoc: getfile " + path - url = "getfile?key=" + path + for url, title in requests: text = pydoc._url_handler(url, "text/html") result = get_html_title(text) self.assertEqual(result, title) + path = string.__file__ + title = "Pydoc: getfile " + path + url = "getfile?key=" + path + text = pydoc._url_handler(url, "text/html") + result = get_html_title(text) + self.assertEqual(result, title) + class TestHelper(unittest.TestCase): def test_keywords(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_pyexpat.py --- a/Lib/test/test_pyexpat.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_pyexpat.py Fri Feb 01 23:12:09 2013 +0100 @@ -52,7 +52,6 @@ &external_entity; &skipped_entity; -\xb5 ''' @@ -196,13 +195,13 @@ "End element: 'sub2'", "External entity ref: (None, 'entity.file', None)", ('Skipped entity', ('skipped_entity', 0)), - "Character data: '\xb5'", "End element: 'root'", ] for operation, expected_operation in zip(operations, expected_operations): self.assertEqual(operation, expected_operation) - def test_parse_bytes(self): + def test_unicode(self): + # Try the parse again, this time producing Unicode output out = self.Outputter() parser = expat.ParserCreate(namespace_separator='!') self._hookup_callbacks(parser, out) @@ -214,16 +213,6 @@ # Issue #6697. self.assertRaises(AttributeError, getattr, parser, '\uD800') - def test_parse_str(self): - out = self.Outputter() - parser = expat.ParserCreate(namespace_separator='!') - self._hookup_callbacks(parser, out) - - parser.Parse(data.decode('iso-8859-1'), 1) - - operations = out.out - self._verify_parse_output(operations) - def test_parse_file(self): # Try parsing a file out = self.Outputter() @@ -280,7 +269,7 @@ L.append(name) p.StartElementHandler = collector p.EndElementHandler = collector - p.Parse(b" ", 1) + p.Parse(" ", 1) tag = L[0] self.assertEqual(len(L), 6) for entry in L: @@ -296,7 +285,7 @@ def ExternalEntityRefHandler(self, context, base, sysId, pubId): external_parser = self.parser.ExternalEntityParserCreate("") - self.parser_result = external_parser.Parse(b"", 1) + self.parser_result = external_parser.Parse("", 1) return 1 parser = expat.ParserCreate(namespace_separator='!') @@ -347,7 +336,7 @@ def test_buffering_enabled(self): # Make sure buffering is turned on self.assertTrue(self.parser.buffer_text) - self.parser.Parse(b"
123", 1) + self.parser.Parse("123", 1) self.assertEqual(self.stuff, ['123'], "buffered text not properly collapsed") @@ -355,39 +344,39 @@ # XXX This test exposes more detail of Expat's text chunking than we # XXX like, but it tests what we need to concisely. self.setHandlers(["StartElementHandler"]) - self.parser.Parse(b"12\n34\n5", 1) + self.parser.Parse("12\n34\n5", 1) self.assertEqual(self.stuff, ["", "1", "", "2", "\n", "3", "", "4\n5"], "buffering control not reacting as expected") def test2(self): - self.parser.Parse(b"1<2> \n 3", 1) + self.parser.Parse("1<2> \n 3", 1) self.assertEqual(self.stuff, ["1<2> \n 3"], "buffered text not properly collapsed") def test3(self): self.setHandlers(["StartElementHandler"]) - self.parser.Parse(b"123", 1) + self.parser.Parse("123", 1) self.assertEqual(self.stuff, ["", "1", "", "2", "", "3"], "buffered text not properly split") def test4(self): self.setHandlers(["StartElementHandler", "EndElementHandler"]) self.parser.CharacterDataHandler = None - self.parser.Parse(b"123", 1) + self.parser.Parse("123", 1) self.assertEqual(self.stuff, ["", "", "", "", "", ""]) def test5(self): self.setHandlers(["StartElementHandler", "EndElementHandler"]) - self.parser.Parse(b"123", 1) + self.parser.Parse("123", 1) self.assertEqual(self.stuff, ["", "1", "", "", "2", "", "", "3", ""]) def test6(self): self.setHandlers(["CommentHandler", "EndElementHandler", "StartElementHandler"]) - self.parser.Parse(b"12345 ", 1) + self.parser.Parse("12345 ", 1) self.assertEqual(self.stuff, ["", "1", "", "", "2", "", "", "345", ""], "buffered text not properly split") @@ -395,7 +384,7 @@ def test7(self): self.setHandlers(["CommentHandler", "EndElementHandler", "StartElementHandler"]) - self.parser.Parse(b"12345 ", 1) + self.parser.Parse("12345 ", 1) self.assertEqual(self.stuff, ["", "1", "", "", "2", "", "", "3", "", "4", "", "5", ""], @@ -411,7 +400,7 @@ parser = expat.ParserCreate() parser.StartElementHandler = self.StartElementHandler try: - parser.Parse(b"", 1) + parser.Parse("", 1) self.fail() except RuntimeError as e: self.assertEqual(e.args[0], 'a', @@ -447,7 +436,7 @@ self.expected_list = [('s', 0, 1, 0), ('s', 5, 2, 1), ('s', 11, 3, 2), ('e', 15, 3, 6), ('e', 17, 4, 1), ('e', 22, 5, 0)] - xml = b'\n \n \n \n' + xml = '\n \n \n \n' self.parser.Parse(xml, 1) @@ -468,7 +457,7 @@ parser = expat.ParserCreate() parser.CharacterDataHandler = handler - self.assertRaises(Exception, parser.Parse, xml.encode('iso8859')) + self.assertRaises(Exception, parser.Parse, xml) class ChardataBufferTest(unittest.TestCase): """ @@ -491,8 +480,8 @@ self.assertRaises(ValueError, f, 0) def test_unchanged_size(self): - xml1 = b"" + b'a' * 512 - xml2 = b'a'*512 + b'' + xml1 = ("%s" % ('a' * 512)) + xml2 = 'a'*512 + '' parser = expat.ParserCreate() parser.CharacterDataHandler = self.counting_handler parser.buffer_size = 512 @@ -514,9 +503,9 @@ def test_disabling_buffer(self): - xml1 = b"" + b'a' * 512 - xml2 = b'b' * 1024 - xml3 = b'c' * 1024 + b''; + xml1 = "%s" % ('a' * 512) + xml2 = ('b' * 1024) + xml3 = "%s" % ('c' * 1024) parser = expat.ParserCreate() parser.CharacterDataHandler = self.counting_handler parser.buffer_text = 1 @@ -543,11 +532,16 @@ parser.Parse(xml3, 1) self.assertEqual(self.n, 12) + + + def make_document(self, bytes): + return ("" + bytes * 'a' + '') + def counting_handler(self, text): self.n += 1 def small_buffer_test(self, buffer_len): - xml = b"" + b'a' * buffer_len + b'' + xml = "%s" % ('a' * buffer_len) parser = expat.ParserCreate() parser.CharacterDataHandler = self.counting_handler parser.buffer_size = 1024 @@ -558,8 +552,8 @@ return self.n def test_change_size_1(self): - xml1 = b"" + b'a' * 1024 - xml2 = b'aaa' + b'a' * 1025 + b'' + xml1 = "%s" % ('a' * 1024) + xml2 = "aaa%s" % ('a' * 1025) parser = expat.ParserCreate() parser.CharacterDataHandler = self.counting_handler parser.buffer_text = 1 @@ -574,8 +568,8 @@ self.assertEqual(self.n, 2) def test_change_size_2(self): - xml1 = b"a" + b'a' * 1023 - xml2 = b'aaa' + b'a' * 1025 + b'' + xml1 = "a%s" % ('a' * 1023) + xml2 = "aaa%s" % ('a' * 1025) parser = expat.ParserCreate() parser.CharacterDataHandler = self.counting_handler parser.buffer_text = 1 @@ -591,7 +585,7 @@ class MalformedInputTest(unittest.TestCase): def test1(self): - xml = b"\0\r\n" + xml = "\0\r\n" parser = expat.ParserCreate() try: parser.Parse(xml, True) @@ -600,8 +594,7 @@ self.assertEqual(str(e), 'unclosed token: line 2, column 0') def test2(self): - # \xc2\x85 is UTF-8 encoded U+0085 (NEXT LINE) - xml = b"\r\n" + xml = "\r\n" parser = expat.ParserCreate() try: parser.Parse(xml, True) @@ -616,7 +609,7 @@ errors.messages[errors.codes[errors.XML_ERROR_SYNTAX]]) def test_expaterror(self): - xml = b'<' + xml = '<' parser = expat.ParserCreate() try: parser.Parse(xml, True) @@ -645,7 +638,7 @@ parser.UseForeignDTD(True) parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS) parser.ExternalEntityRefHandler = resolve_entity - parser.Parse(b"") + parser.Parse("") self.assertEqual(handler_call_args, [(None, None)]) # test UseForeignDTD() is equal to UseForeignDTD(True) @@ -655,7 +648,7 @@ parser.UseForeignDTD() parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS) parser.ExternalEntityRefHandler = resolve_entity - parser.Parse(b"") + parser.Parse("") self.assertEqual(handler_call_args, [(None, None)]) def test_ignore_use_foreign_dtd(self): @@ -674,7 +667,7 @@ parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS) parser.ExternalEntityRefHandler = resolve_entity parser.Parse( - b"") + "") self.assertEqual(handler_call_args, [("bar", "baz")]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_queue.py --- a/Lib/test/test_queue.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_queue.py Fri Feb 01 23:12:09 2013 +0100 @@ -46,9 +46,6 @@ class BlockingTestMixin: - def tearDown(self): - self.t = None - def do_blocking_test(self, block_func, block_args, trigger_func, trigger_args): self.t = _TriggerThread(trigger_func, trigger_args) self.t.start() @@ -263,7 +260,7 @@ raise FailingQueueException("You Lose") return queue.Queue._get(self) -class FailingQueueTest(BlockingTestMixin, unittest.TestCase): +class FailingQueueTest(unittest.TestCase, BlockingTestMixin): def failing_queue_test(self, q): if q.qsize(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_random.py --- a/Lib/test/test_random.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_random.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,16 +1,14 @@ #!/usr/bin/env python3 import unittest -import unittest.mock import random import time import pickle import warnings -from functools import partial from math import log, exp, pi, fsum, sin from test import support -class TestBasicOps: +class TestBasicOps(unittest.TestCase): # Superclass with tests common to all generators. # Subclasses must arrange for self.gen to retrieve the Random instance # to be tested. @@ -48,16 +46,6 @@ self.assertRaises(TypeError, self.gen.seed, 1, 2, 3, 4) self.assertRaises(TypeError, type(self.gen), []) - @unittest.mock.patch('random._urandom') # os.urandom - def test_seed_when_randomness_source_not_found(self, urandom_mock): - # Random.seed() uses time.time() when an operating system specific - # randomness source is not found. To test this on machines were it - # exists, run the above test, test_seedargs(), again after mocking - # os.urandom() so that it raises the exception expected when the - # randomness source is not available. - urandom_mock.side_effect = NotImplementedError - self.test_seedargs() - def test_shuffle(self): shuffle = self.gen.shuffle lst = [] @@ -73,6 +61,7 @@ for (seq, shuffled_seq) in zip(seqs, shuffled_seqs): self.assertEqual(len(seq), len(shuffled_seq)) self.assertEqual(set(seq), set(shuffled_seq)) + # The above tests all would pass if the shuffle was a # no-op. The following non-deterministic test covers that. It # asserts that the shuffled sequence of 1000 distinct elements @@ -109,8 +98,6 @@ self.assertEqual(len(uniq), k) self.assertTrue(uniq <= set(population)) self.assertEqual(self.gen.sample([], 0), []) # test edge case N==k==0 - # Exception raised if size of sample exceeds that of population - self.assertRaises(ValueError, self.gen.sample, population, N+1) def test_sample_distribution(self): # For the entire allowable range of 0 <= k <= N, validate that @@ -188,15 +175,7 @@ k = sum(randrange(6755399441055744) % 3 == 2 for i in range(n)) self.assertTrue(0.30 < k/n < .37, (k/n)) -try: - random.SystemRandom().random() -except NotImplementedError: - SystemRandom_available = False -else: - SystemRandom_available = True - -@unittest.skipUnless(SystemRandom_available, "random.SystemRandom not available") -class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase): +class SystemRandom_TestBasicOps(TestBasicOps): gen = random.SystemRandom() def test_autoseed(self): @@ -251,25 +230,6 @@ self.assertEqual(set(range(start,stop)), set([self.gen.randrange(start,stop) for i in range(100)])) - def test_randrange_nonunit_step(self): - rint = self.gen.randrange(0, 10, 2) - self.assertIn(rint, (0, 2, 4, 6, 8)) - rint = self.gen.randrange(0, 2, 2) - self.assertEqual(rint, 0) - - def test_randrange_errors(self): - raises = partial(self.assertRaises, ValueError, self.gen.randrange) - # Empty range - raises(3, 3) - raises(-721) - raises(0, 100, -12) - # Non-integer start/stop - raises(3.14159) - raises(0, 2.71828) - # Zero and non-integer step - raises(0, 42, 0) - raises(0, 42, 3.14159) - def test_genrandbits(self): # Verify ranges for k in range(1, 1000): @@ -312,7 +272,7 @@ self.assertTrue(2**k > n > 2**(k-1)) # note the stronger assertion -class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase): +class MersenneTwister_TestBasicOps(TestBasicOps): gen = random.Random() def test_guaranteed_stable(self): @@ -339,16 +299,6 @@ # Last element s/b an int also self.assertRaises(TypeError, self.gen.setstate, (2, (0,)*624+('a',), None)) - # Little trick to make "tuple(x % (2**32) for x in internalstate)" - # raise ValueError. I cannot think of a simple way to achieve this, so - # I am opting for using a generator as the middle argument of setstate - # which attempts to cast a NaN to integer. - state_values = self.gen.getstate()[1] - state_values = list(state_values) - state_values[-1] = float('nan') - state = (int(x) for x in state_values) - self.assertRaises(TypeError, self.gen.setstate, (2, state, None)) - def test_referenceImplementation(self): # Compare the python implementation with results from the original # code. Create 2000 53-bit precision random floats. Compare only @@ -488,38 +438,6 @@ self.assertEqual(k, numbits) # note the stronger assertion self.assertTrue(2**k > n > 2**(k-1)) # note the stronger assertion - @unittest.mock.patch('random.Random.random') - def test_randbelow_overriden_random(self, random_mock): - # Random._randbelow() can only use random() when the built-in one - # has been overridden but no new getrandbits() method was supplied. - random_mock.side_effect = random.SystemRandom().random - maxsize = 1<= maxsize) - self.gen._randbelow(maxsize+1, maxsize = maxsize) - self.gen._randbelow(5640, maxsize = maxsize) - - # This might be going too far to test a single line, but because of our - # noble aim of achieving 100% test coverage we need to write a case in - # which the following line in Random._randbelow() gets executed: - # - # rem = maxsize % n - # limit = (maxsize - rem) / maxsize - # r = random() - # while r >= limit: - # r = random() # <== *This line* <==< - # - # Therefore, to guarantee that the while loop is executed at least - # once, we need to mock random() so that it returns a number greater - # than 'limit' the first time it gets called. - - n = 42 - epsilon = 0.01 - limit = (maxsize - (maxsize % n)) / maxsize - random_mock.side_effect = [limit + epsilon, limit - epsilon] - self.gen._randbelow(n, maxsize = maxsize) - def test_randrange_bug_1590891(self): start = 1000000000000 stop = -100000000000000000000 @@ -555,7 +473,6 @@ g.random = x[:].pop; g.paretovariate(1.0) g.random = x[:].pop; g.expovariate(1.0) g.random = x[:].pop; g.weibullvariate(1.0, 1.0) - g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0) g.random = x[:].pop; g.normalvariate(0.0, 1.0) g.random = x[:].pop; g.gauss(0.0, 1.0) g.random = x[:].pop; g.lognormvariate(0.0, 1.0) @@ -576,7 +493,6 @@ (g.uniform, (1.0,10.0), (10.0+1.0)/2, (10.0-1.0)**2/12), (g.triangular, (0.0, 1.0, 1.0/3.0), 4.0/9.0, 7.0/9.0/18.0), (g.expovariate, (1.5,), 1/1.5, 1/1.5**2), - (g.vonmisesvariate, (1.23, 0), pi, pi**2/3), (g.paretovariate, (5.0,), 5.0/(5.0-1), 5.0/((5.0-1)**2*(5.0-2))), (g.weibullvariate, (1.0, 3.0), gamma(1+1/3.0), @@ -593,150 +509,8 @@ s1 += e s2 += (e - mu) ** 2 N = len(y) - self.assertAlmostEqual(s1/N, mu, places=2, - msg='%s%r' % (variate.__name__, args)) - self.assertAlmostEqual(s2/(N-1), sigmasqrd, places=2, - msg='%s%r' % (variate.__name__, args)) - - def test_constant(self): - g = random.Random() - N = 100 - for variate, args, expected in [ - (g.uniform, (10.0, 10.0), 10.0), - (g.triangular, (10.0, 10.0), 10.0), - #(g.triangular, (10.0, 10.0, 10.0), 10.0), - (g.expovariate, (float('inf'),), 0.0), - (g.vonmisesvariate, (3.0, float('inf')), 3.0), - (g.gauss, (10.0, 0.0), 10.0), - (g.lognormvariate, (0.0, 0.0), 1.0), - (g.lognormvariate, (-float('inf'), 0.0), 0.0), - (g.normalvariate, (10.0, 0.0), 10.0), - (g.paretovariate, (float('inf'),), 1.0), - (g.weibullvariate, (10.0, float('inf')), 10.0), - (g.weibullvariate, (0.0, 10.0), 0.0), - ]: - for i in range(N): - self.assertEqual(variate(*args), expected) - - def test_von_mises_range(self): - # Issue 17149: von mises variates were not consistently in the - # range [0, 2*PI]. - g = random.Random() - N = 100 - for mu in 0.0, 0.1, 3.1, 6.2: - for kappa in 0.0, 2.3, 500.0: - for _ in range(N): - sample = g.vonmisesvariate(mu, kappa) - self.assertTrue( - 0 <= sample <= random.TWOPI, - msg=("vonmisesvariate({}, {}) produced a result {} out" - " of range [0, 2*pi]").format(mu, kappa, sample)) - - def test_von_mises_large_kappa(self): - # Issue #17141: vonmisesvariate() was hang for large kappas - random.vonmisesvariate(0, 1e15) - random.vonmisesvariate(0, 1e100) - - def test_gammavariate_errors(self): - # Both alpha and beta must be > 0.0 - self.assertRaises(ValueError, random.gammavariate, -1, 3) - self.assertRaises(ValueError, random.gammavariate, 0, 2) - self.assertRaises(ValueError, random.gammavariate, 2, 0) - self.assertRaises(ValueError, random.gammavariate, 1, -3) - - @unittest.mock.patch('random.Random.random') - def test_gammavariate_full_code_coverage(self, random_mock): - # There are three different possibilities in the current implementation - # of random.gammavariate(), depending on the value of 'alpha'. What we - # are going to do here is to fix the values returned by random() to - # generate test cases that provide 100% line coverage of the method. - - # #1: alpha > 1.0: we want the first random number to be outside the - # [1e-7, .9999999] range, so that the continue statement executes - # once. The values of u1 and u2 will be 0.5 and 0.3, respectively. - random_mock.side_effect = [1e-8, 0.5, 0.3] - returned_value = random.gammavariate(1.1, 2.3) - self.assertAlmostEqual(returned_value, 2.53) - - # #2: alpha == 1: first random number less than 1e-7 to that the body - # of the while loop executes once. Then random.random() returns 0.45, - # which causes while to stop looping and the algorithm to terminate. - random_mock.side_effect = [1e-8, 0.45] - returned_value = random.gammavariate(1.0, 3.14) - self.assertAlmostEqual(returned_value, 2.507314166123803) - - # #3: 0 < alpha < 1. This is the most complex region of code to cover, - # as there are multiple if-else statements. Let's take a look at the - # source code, and determine the values that we need accordingly: - # - # while 1: - # u = random() - # b = (_e + alpha)/_e - # p = b*u - # if p <= 1.0: # <=== (A) - # x = p ** (1.0/alpha) - # else: # <=== (B) - # x = -_log((b-p)/alpha) - # u1 = random() - # if p > 1.0: # <=== (C) - # if u1 <= x ** (alpha - 1.0): # <=== (D) - # break - # elif u1 <= _exp(-x): # <=== (E) - # break - # return x * beta - # - # First, we want (A) to be True. For that we need that: - # b*random() <= 1.0 - # r1 = random() <= 1.0 / b - # - # We now get to the second if-else branch, and here, since p <= 1.0, - # (C) is False and we take the elif branch, (E). For it to be True, - # so that the break is executed, we need that: - # r2 = random() <= _exp(-x) - # r2 <= _exp(-(p ** (1.0/alpha))) - # r2 <= _exp(-((b*r1) ** (1.0/alpha))) - - _e = random._e - _exp = random._exp - _log = random._log - alpha = 0.35 - beta = 1.45 - b = (_e + alpha)/_e - epsilon = 0.01 - - r1 = 0.8859296441566 # 1.0 / b - r2 = 0.3678794411714 # _exp(-((b*r1) ** (1.0/alpha))) - - # These four "random" values result in the following trace: - # (A) True, (E) False --> [next iteration of while] - # (A) True, (E) True --> [while loop breaks] - random_mock.side_effect = [r1, r2 + epsilon, r1, r2] - returned_value = random.gammavariate(alpha, beta) - self.assertAlmostEqual(returned_value, 1.4499999999997544) - - # Let's now make (A) be False. If this is the case, when we get to the - # second if-else 'p' is greater than 1, so (C) evaluates to True. We - # now encounter a second if statement, (D), which in order to execute - # must satisfy the following condition: - # r2 <= x ** (alpha - 1.0) - # r2 <= (-_log((b-p)/alpha)) ** (alpha - 1.0) - # r2 <= (-_log((b-(b*r1))/alpha)) ** (alpha - 1.0) - r1 = 0.8959296441566 # (1.0 / b) + epsilon -- so that (A) is False - r2 = 0.9445400408898141 - - # And these four values result in the following trace: - # (B) and (C) True, (D) False --> [next iteration of while] - # (B) and (C) True, (D) True [while loop breaks] - random_mock.side_effect = [r1, r2 + epsilon, r1, r2] - returned_value = random.gammavariate(alpha, beta) - self.assertAlmostEqual(returned_value, 1.5830349561760781) - - @unittest.mock.patch('random.Random.gammavariate') - def test_betavariate_return_zero(self, gammavariate_mock): - # betavariate() returns zero when the Gamma distribution - # that it uses internally returns this same value. - gammavariate_mock.return_value = 0.0 - self.assertEqual(0.0, random.betavariate(2.71828, 3.14159)) + self.assertAlmostEqual(s1/N, mu, places=2) + self.assertAlmostEqual(s2/(N-1), sigmasqrd, places=2) class TestModule(unittest.TestCase): def testMagicConstants(self): @@ -757,5 +531,28 @@ Subclass(newarg=1) +def test_main(verbose=None): + testclasses = [MersenneTwister_TestBasicOps, + TestDistributions, + TestModule] + + try: + random.SystemRandom().random() + except NotImplementedError: + pass + else: + testclasses.append(SystemRandom_TestBasicOps) + + support.run_unittest(*testclasses) + + # verify reference counting + import sys + if verbose and hasattr(sys, "gettotalrefcount"): + counts = [None] * 5 + for i in range(len(counts)): + support.run_unittest(*testclasses) + counts[i] = sys.gettotalrefcount() + print(counts) + if __name__ == "__main__": - unittest.main() + test_main(verbose=True) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_re.py --- a/Lib/test/test_re.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_re.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,9 +1,7 @@ -from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G, \ - cpython_only +from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G import io import re from re import Scanner -import sre_constants import sys import string import traceback @@ -181,10 +179,6 @@ self.assertRaises(re.error, re.compile, '(?(a))') self.assertRaises(re.error, re.compile, '(?(1a))') self.assertRaises(re.error, re.compile, '(?(a.))') - # New valid/invalid identifiers in Python 3 - re.compile('(?P<µ>x)(?P=µ)(?(µ)y)') - re.compile('(?P<ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢>x)(?P=ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢)(?(ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢)y)') - self.assertRaises(re.error, re.compile, '(?P<©>x)') def test_symbolic_refs(self): self.assertRaises(re.error, re.sub, '(?Px)', '\gx)|(?Py)', '\g', 'xx') self.assertRaises(re.error, re.sub, '(?Px)|(?Py)', '\\2', 'xx') self.assertRaises(re.error, re.sub, '(?Px)', '\g<-1>', 'xx') - # New valid/invalid identifiers in Python 3 - self.assertEqual(re.sub('(?P<µ>x)', r'\g<µ>', 'xx'), 'xx') - self.assertEqual(re.sub('(?P<ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢>x)', r'\g<ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢>', 'xx'), 'xx') - self.assertRaises(re.error, re.sub, '(?Px)', r'\g<©>', 'xx') def test_re_subn(self): self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2)) @@ -609,7 +599,6 @@ self.assertIsNotNone(re.match(r"[\U%08x]" % i, chr(i))) self.assertIsNotNone(re.match(r"[\U%08x0]" % i, chr(i)+"0")) self.assertIsNotNone(re.match(r"[\U%08xz]" % i, chr(i)+"z")) - self.assertIsNotNone(re.match(r"[\U0001d49c-\U0001d4b5]", "\U0001d49e")) self.assertRaises(re.error, re.match, r"[\911]", "") self.assertRaises(re.error, re.match, r"[\x1z]", "") self.assertRaises(re.error, re.match, r"[\u123z]", "") @@ -691,15 +680,6 @@ self.assertEqual(re.match('(x)*y', 50000*'x'+'y').group(1), 'x') self.assertEqual(re.match('(x)*?y', 50000*'x'+'y').group(1), 'x') - def test_unlimited_zero_width_repeat(self): - # Issue #9669 - self.assertIsNone(re.match(r'(?:a?)*y', 'z')) - self.assertIsNone(re.match(r'(?:a?)+y', 'z')) - self.assertIsNone(re.match(r'(?:a?){2,}y', 'z')) - self.assertIsNone(re.match(r'(?:a?)*?y', 'z')) - self.assertIsNone(re.match(r'(?:a?)+?y', 'z')) - self.assertIsNone(re.match(r'(?:a?){2,}?y', 'z')) - def test_scanner(self): def s_ident(scanner, token): return token def s_operator(scanner, token): return "op%s" % token @@ -1000,47 +980,6 @@ self.assertEqual(re.findall(r"(?i)(a)\1", "aa \u0100"), ['a']) self.assertEqual(re.match(r"(?s).{1,3}", "\u0100\u0100").span(), (0, 2)) - def test_repeat_minmax_overflow(self): - # Issue #13169 - string = "x" * 100000 - self.assertEqual(re.match(r".{65535}", string).span(), (0, 65535)) - self.assertEqual(re.match(r".{,65535}", string).span(), (0, 65535)) - self.assertEqual(re.match(r".{65535,}?", string).span(), (0, 65535)) - self.assertEqual(re.match(r".{65536}", string).span(), (0, 65536)) - self.assertEqual(re.match(r".{,65536}", string).span(), (0, 65536)) - self.assertEqual(re.match(r".{65536,}?", string).span(), (0, 65536)) - # 2**128 should be big enough to overflow both SRE_CODE and Py_ssize_t. - self.assertRaises(OverflowError, re.compile, r".{%d}" % 2**128) - self.assertRaises(OverflowError, re.compile, r".{,%d}" % 2**128) - self.assertRaises(OverflowError, re.compile, r".{%d,}?" % 2**128) - self.assertRaises(OverflowError, re.compile, r".{%d,%d}" % (2**129, 2**128)) - - @cpython_only - def test_repeat_minmax_overflow_maxrepeat(self): - try: - from _sre import MAXREPEAT - except ImportError: - self.skipTest('requires _sre.MAXREPEAT constant') - string = "x" * 100000 - self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string)) - self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(), - (0, 100000)) - self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string)) - self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT) - self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT) - self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT) - - def test_backref_group_name_in_exception(self): - # Issue 17341: Poor error message when compiling invalid regex - with self.assertRaisesRegex(sre_constants.error, ''): - re.compile('(?P=)') - - def test_group_name_in_exception(self): - # Issue 17341: Poor error message when compiling invalid regex - with self.assertRaisesRegex(sre_constants.error, '\?foo'): - re.compile('(?P)') - - def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_reprlib.py --- a/Lib/test/test_reprlib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_reprlib.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,11 +3,11 @@ Nick Mathewson """ +import imp import sys import os import shutil import importlib -import importlib.util import unittest from test.support import run_unittest, create_empty_file, verbose @@ -241,8 +241,7 @@ source_path_len += 2 * (len(self.longname) + 1) # a path separator + `module_name` + ".py" source_path_len += len(module_name) + 1 + len(".py") - cached_path_len = (source_path_len + - len(importlib.util.cache_from_source("x.py")) - len("x.py")) + cached_path_len = source_path_len + len(imp.cache_from_source("x.py")) - len("x.py") if os.name == 'nt' and cached_path_len >= 258: # Under Windows, the max path len is 260 including C's terminating # NUL character. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_resource.py --- a/Lib/test/test_resource.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_resource.py Fri Feb 01 23:12:09 2013 +0100 @@ -107,23 +107,6 @@ except (ValueError, AttributeError): pass - # Issue 6083: Reference counting bug - def test_setrusage_refcount(self): - try: - limits = resource.getrlimit(resource.RLIMIT_CPU) - except AttributeError: - pass - else: - class BadSequence: - def __len__(self): - return 2 - def __getitem__(self, key): - if key in (0, 1): - return len(tuple(range(1000000))) - raise IndexError - - resource.setrlimit(resource.RLIMIT_CPU, BadSequence()) - def test_main(verbose=None): support.run_unittest(ResourceTest) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_robotparser.py --- a/Lib/test/test_robotparser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_robotparser.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,10 +6,7 @@ from test import support class RobotTestCase(unittest.TestCase): - def __init__(self, index=None, parser=None, url=None, good=None, agent=None): - # workaround to make unittest discovery work (see #17066) - if not isinstance(index, int): - return + def __init__(self, index, parser, url, good, agent): unittest.TestCase.__init__(self) if good: self.str = "RobotTest(%d, good, %s)" % (index, url) @@ -234,18 +231,6 @@ RobotTest(15, doc, good, bad) -# 16. Empty query (issue #17403). Normalizing the url first. -doc = """ -User-agent: * -Allow: /some/path? -Disallow: /another/path? -""" - -good = ['/some/path?'] -bad = ['/another/path?'] - -RobotTest(16, doc, good, bad) - class NetworkTestCase(unittest.TestCase): @@ -284,11 +269,10 @@ self.assertTrue( parser.can_fetch("*", "http://www.python.org/robots.txt")) -def load_tests(loader, suite, pattern): - suite = unittest.makeSuite(NetworkTestCase) - suite.addTest(tests) - return suite +def test_main(): + support.run_unittest(NetworkTestCase) + support.run_unittest(tests) if __name__=='__main__': - support.use_resources = ['network'] - unittest.main() + support.verbose = 1 + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_runpy.py --- a/Lib/test/test_runpy.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_runpy.py Fri Feb 01 23:12:09 2013 +0100 @@ -258,13 +258,12 @@ importlib.invalidate_caches() __import__(mod_name) os.remove(mod_fname) - if not sys.dont_write_bytecode: - make_legacy_pyc(mod_fname) - unload(mod_name) # In case loader caches paths - importlib.invalidate_caches() - if verbose > 1: print("Running from compiled:", mod_name) - self._fix_ns_for_legacy_pyc(expected_ns, alter_sys) - self.check_code_execution(create_ns, expected_ns) + make_legacy_pyc(mod_fname) + unload(mod_name) # In case loader caches paths + importlib.invalidate_caches() + if verbose > 1: print("Running from compiled:", mod_name) + self._fix_ns_for_legacy_pyc(expected_ns, alter_sys) + self.check_code_execution(create_ns, expected_ns) finally: self._del_pkg(pkg_dir, depth, mod_name) if verbose > 1: print("Module executed successfully") @@ -294,13 +293,12 @@ importlib.invalidate_caches() __import__(mod_name) os.remove(mod_fname) - if not sys.dont_write_bytecode: - make_legacy_pyc(mod_fname) - unload(mod_name) # In case loader caches paths - if verbose > 1: print("Running from compiled:", pkg_name) - importlib.invalidate_caches() - self._fix_ns_for_legacy_pyc(expected_ns, alter_sys) - self.check_code_execution(create_ns, expected_ns) + make_legacy_pyc(mod_fname) + unload(mod_name) # In case loader caches paths + if verbose > 1: print("Running from compiled:", pkg_name) + importlib.invalidate_caches() + self._fix_ns_for_legacy_pyc(expected_ns, alter_sys) + self.check_code_execution(create_ns, expected_ns) finally: self._del_pkg(pkg_dir, depth, pkg_name) if verbose > 1: print("Package executed successfully") @@ -353,17 +351,16 @@ importlib.invalidate_caches() __import__(mod_name) os.remove(mod_fname) - if not sys.dont_write_bytecode: - make_legacy_pyc(mod_fname) - unload(mod_name) # In case the loader caches paths - if verbose > 1: print("Running from compiled:", mod_name) - importlib.invalidate_caches() - d2 = run_module(mod_name, run_name=run_name) # Read from bytecode - self.assertEqual(d2["__name__"], expected_name) - self.assertEqual(d2["__package__"], pkg_name) - self.assertIn("sibling", d2) - self.assertIn("nephew", d2) - del d2 # Ensure __loader__ entry doesn't keep file open + make_legacy_pyc(mod_fname) + unload(mod_name) # In case the loader caches paths + if verbose > 1: print("Running from compiled:", mod_name) + importlib.invalidate_caches() + d2 = run_module(mod_name, run_name=run_name) # Read from bytecode + self.assertEqual(d2["__name__"], expected_name) + self.assertEqual(d2["__package__"], pkg_name) + self.assertIn("sibling", d2) + self.assertIn("nephew", d2) + del d2 # Ensure __loader__ entry doesn't keep file open finally: self._del_pkg(pkg_dir, depth, mod_name) if verbose > 1: print("Module executed successfully") @@ -516,10 +513,9 @@ script_name = self._make_test_script(script_dir, mod_name) compiled_name = py_compile.compile(script_name, doraise=True) os.remove(script_name) - if not sys.dont_write_bytecode: - legacy_pyc = make_legacy_pyc(script_name) - self._check_script(script_dir, "", legacy_pyc, - script_dir) + legacy_pyc = make_legacy_pyc(script_name) + self._check_script(script_dir, "", legacy_pyc, + script_dir) def test_directory_error(self): with temp_dir() as script_dir: @@ -575,5 +571,12 @@ self.assertEqual(result['s'], "non-ASCII: h\xe9") +def test_main(): + run_unittest( + ExecutionLayerTestCase, + RunModuleTestCase, + RunPathTestCase + ) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sax.py --- a/Lib/test/test_sax.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sax.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,23 +3,19 @@ from xml.sax import make_parser, ContentHandler, \ SAXException, SAXReaderNotAvailable, SAXParseException -import unittest try: make_parser() except SAXReaderNotAvailable: # don't try to test this module if we cannot create a parser - raise unittest.SkipTest("no XML parsers available") + raise ImportError("no XML parsers available") from xml.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \ XMLFilterBase from xml.sax.expatreader import create_parser from xml.sax.handler import feature_namespaces from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl -from io import BytesIO, StringIO -import codecs -import os.path -import shutil -from test import support +from io import StringIO from test.support import findfile, run_unittest +import unittest TEST_XMLFILE = findfile("test.xml", subdir="xmltestdata") TEST_XMLFILE_OUT = findfile("test.xml.out", subdir="xmltestdata") @@ -29,18 +25,6 @@ except UnicodeEncodeError: raise unittest.SkipTest("filename is not encodable to utf8") -supports_nonascii_filenames = True -if not os.path.supports_unicode_filenames: - try: - support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING) - except (UnicodeError, TypeError): - # Either the file system encoding is None, or the file name - # cannot be encoded in the file system encoding. - supports_nonascii_filenames = False -requires_nonascii_filenames = unittest.skipUnless( - supports_nonascii_filenames, - 'Requires non-ascii filenames support') - ns_uri = "http://www.python.org/xml-ns/saxtest/" class XmlTestBase(unittest.TestCase): @@ -174,29 +158,31 @@ # ===== XMLGenerator -class XmlgenTest: +start = '\n' + +class XmlgenTest(unittest.TestCase): def test_xmlgen_basic(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() gen.startElement("doc", {}) gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml("")) + self.assertEqual(result.getvalue(), start + "") def test_xmlgen_basic_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() gen.startElement("doc", {}) gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml("")) + self.assertEqual(result.getvalue(), start + "") def test_xmlgen_content(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -205,10 +191,10 @@ gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml("huhei")) + self.assertEqual(result.getvalue(), start + "huhei") def test_xmlgen_content_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() @@ -217,10 +203,10 @@ gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml("huhei")) + self.assertEqual(result.getvalue(), start + "huhei") def test_xmlgen_pi(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -229,11 +215,10 @@ gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), - self.xml("")) + self.assertEqual(result.getvalue(), start + "") def test_xmlgen_content_escape(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -243,10 +228,10 @@ gen.endDocument() self.assertEqual(result.getvalue(), - self.xml("<huhei&")) + start + "<huhei&") def test_xmlgen_attr_escape(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -260,43 +245,13 @@ gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml( - "" - "" - "")) - - def test_xmlgen_encoding(self): - encodings = ('iso-8859-15', 'utf-8', 'utf-8-sig', - 'utf-16', 'utf-16be', 'utf-16le', - 'utf-32', 'utf-32be', 'utf-32le') - for encoding in encodings: - result = self.ioclass() - gen = XMLGenerator(result, encoding=encoding) - - gen.startDocument() - gen.startElement("doc", {"a": '\u20ac'}) - gen.characters("\u20ac") - gen.endElement("doc") - gen.endDocument() - - self.assertEqual(result.getvalue(), - self.xml('\u20ac', encoding=encoding)) - - def test_xmlgen_unencodable(self): - result = self.ioclass() - gen = XMLGenerator(result, encoding='ascii') - - gen.startDocument() - gen.startElement("doc", {"a": '\u20ac'}) - gen.characters("\u20ac") - gen.endElement("doc") - gen.endDocument() - - self.assertEqual(result.getvalue(), - self.xml('', encoding='ascii')) + self.assertEqual(result.getvalue(), start + + ("" + "" + "")) def test_xmlgen_ignorable(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -305,10 +260,10 @@ gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml(" ")) + self.assertEqual(result.getvalue(), start + " ") def test_xmlgen_ignorable_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() @@ -317,28 +272,10 @@ gen.endElement("doc") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml(" ")) - - def test_xmlgen_encoding_bytes(self): - encodings = ('iso-8859-15', 'utf-8', 'utf-8-sig', - 'utf-16', 'utf-16be', 'utf-16le', - 'utf-32', 'utf-32be', 'utf-32le') - for encoding in encodings: - result = self.ioclass() - gen = XMLGenerator(result, encoding=encoding) - - gen.startDocument() - gen.startElement("doc", {"a": '\u20ac'}) - gen.characters("\u20ac".encode(encoding)) - gen.ignorableWhitespace(" ".encode(encoding)) - gen.endElement("doc") - gen.endDocument() - - self.assertEqual(result.getvalue(), - self.xml('\u20ac ', encoding=encoding)) + self.assertEqual(result.getvalue(), start + " ") def test_xmlgen_ns(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -351,12 +288,12 @@ gen.endPrefixMapping("ns1") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml( - '' % + self.assertEqual(result.getvalue(), start + \ + ('' % ns_uri)) def test_xmlgen_ns_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() @@ -369,12 +306,12 @@ gen.endPrefixMapping("ns1") gen.endDocument() - self.assertEqual(result.getvalue(), self.xml( - '' % + self.assertEqual(result.getvalue(), start + \ + ('' % ns_uri)) def test_1463026_1(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -382,10 +319,10 @@ gen.endElementNS((None, 'a'), 'a') gen.endDocument() - self.assertEqual(result.getvalue(), self.xml('')) + self.assertEqual(result.getvalue(), start+'') def test_1463026_1_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() @@ -393,10 +330,10 @@ gen.endElementNS((None, 'a'), 'a') gen.endDocument() - self.assertEqual(result.getvalue(), self.xml('')) + self.assertEqual(result.getvalue(), start+'') def test_1463026_2(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -406,10 +343,10 @@ gen.endPrefixMapping(None) gen.endDocument() - self.assertEqual(result.getvalue(), self.xml('')) + self.assertEqual(result.getvalue(), start+'') def test_1463026_2_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() @@ -419,10 +356,10 @@ gen.endPrefixMapping(None) gen.endDocument() - self.assertEqual(result.getvalue(), self.xml('')) + self.assertEqual(result.getvalue(), start+'') def test_1463026_3(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -433,10 +370,10 @@ gen.endDocument() self.assertEqual(result.getvalue(), - self.xml('')) + start+'') def test_1463026_3_empty(self): - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result, short_empty_elements=True) gen.startDocument() @@ -447,7 +384,7 @@ gen.endDocument() self.assertEqual(result.getvalue(), - self.xml('')) + start+'') def test_5027_1(self): # The xml prefix (as in xml:lang below) is reserved and bound by @@ -464,13 +401,13 @@ parser = make_parser() parser.setFeature(feature_namespaces, True) - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) parser.setContentHandler(gen) parser.parse(test_xml) self.assertEqual(result.getvalue(), - self.xml( + start + ( '' 'Hello' '')) @@ -483,7 +420,7 @@ # # This test demonstrates the bug by direct manipulation of the # XMLGenerator. - result = self.ioclass() + result = StringIO() gen = XMLGenerator(result) gen.startDocument() @@ -498,104 +435,15 @@ gen.endDocument() self.assertEqual(result.getvalue(), - self.xml( + start + ( '' 'Hello' '')) - def test_no_close_file(self): - result = self.ioclass() - def func(out): - gen = XMLGenerator(out) - gen.startDocument() - gen.startElement("doc", {}) - func(result) - self.assertFalse(result.closed) - - def test_xmlgen_fragment(self): - result = self.ioclass() - gen = XMLGenerator(result) - - # Don't call gen.startDocument() - gen.startElement("foo", {"a": "1.0"}) - gen.characters("Hello") - gen.endElement("foo") - gen.startElement("bar", {"b": "2.0"}) - gen.endElement("bar") - # Don't call gen.endDocument() - - self.assertEqual(result.getvalue(), - self.xml('Hello')[len(self.xml('')):]) - -class StringXmlgenTest(XmlgenTest, unittest.TestCase): - ioclass = StringIO - - def xml(self, doc, encoding='iso-8859-1'): - return '\n%s' % (encoding, doc) - - test_xmlgen_unencodable = None - -class BytesXmlgenTest(XmlgenTest, unittest.TestCase): - ioclass = BytesIO - - def xml(self, doc, encoding='iso-8859-1'): - return ('\n%s' % - (encoding, doc)).encode(encoding, 'xmlcharrefreplace') - -class WriterXmlgenTest(BytesXmlgenTest): - class ioclass(list): - write = list.append - closed = False - - def seekable(self): - return True - - def tell(self): - # return 0 at start and not 0 after start - return len(self) - - def getvalue(self): - return b''.join(self) - -class StreamWriterXmlgenTest(XmlgenTest, unittest.TestCase): - def ioclass(self): - raw = BytesIO() - writer = codecs.getwriter('ascii')(raw, 'xmlcharrefreplace') - writer.getvalue = raw.getvalue - return writer - - def xml(self, doc, encoding='iso-8859-1'): - return ('\n%s' % - (encoding, doc)).encode('ascii', 'xmlcharrefreplace') - -class StreamReaderWriterXmlgenTest(XmlgenTest, unittest.TestCase): - fname = support.TESTFN + '-codecs' - - def ioclass(self): - writer = codecs.open(self.fname, 'w', encoding='ascii', - errors='xmlcharrefreplace', buffering=0) - def cleanup(): - writer.close() - support.unlink(self.fname) - self.addCleanup(cleanup) - def getvalue(): - # Windows will not let use reopen without first closing - writer.close() - with open(writer.name, 'rb') as f: - return f.read() - writer.getvalue = getvalue - return writer - - def xml(self, doc, encoding='iso-8859-1'): - return ('\n%s' % - (encoding, doc)).encode('ascii', 'xmlcharrefreplace') - -start = b'\n' - class XMLFilterBaseTest(unittest.TestCase): def test_filter_basic(self): - result = BytesIO() + result = StringIO() gen = XMLGenerator(result) filter = XMLFilterBase() filter.setContentHandler(gen) @@ -607,7 +455,7 @@ filter.endElement("doc") filter.endDocument() - self.assertEqual(result.getvalue(), start + b"content ") + self.assertEqual(result.getvalue(), start + "content ") # =========================================================================== # @@ -615,7 +463,7 @@ # # =========================================================================== -with open(TEST_XMLFILE_OUT, 'rb') as f: +with open(TEST_XMLFILE_OUT) as f: xml_test_out = f.read() class ExpatReaderTest(XmlTestBase): @@ -624,30 +472,15 @@ def test_expat_file(self): parser = create_parser() - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) - with open(TEST_XMLFILE, 'rb') as f: + with open(TEST_XMLFILE) as f: parser.parse(f) self.assertEqual(result.getvalue(), xml_test_out) - @requires_nonascii_filenames - def test_expat_file_nonascii(self): - fname = support.TESTFN_UNICODE - shutil.copyfile(TEST_XMLFILE, fname) - self.addCleanup(support.unlink, fname) - - parser = create_parser() - result = BytesIO() - xmlgen = XMLGenerator(result) - - parser.setContentHandler(xmlgen) - parser.parse(open(fname)) - - self.assertEqual(result.getvalue(), xml_test_out) - # ===== DTDHandler support class TestDTDHandler: @@ -684,13 +517,13 @@ def resolveEntity(self, publicId, systemId): inpsrc = InputSource() - inpsrc.setByteStream(BytesIO(b"")) + inpsrc.setByteStream(StringIO("")) return inpsrc def test_expat_entityresolver(self): parser = create_parser() parser.setEntityResolver(self.TestEntityResolver()) - result = BytesIO() + result = StringIO() parser.setContentHandler(XMLGenerator(result)) parser.feed('") + "") # ===== Attributes support @@ -769,7 +602,7 @@ def test_expat_inpsource_filename(self): parser = create_parser() - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) @@ -779,7 +612,7 @@ def test_expat_inpsource_sysid(self): parser = create_parser() - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) @@ -787,29 +620,14 @@ self.assertEqual(result.getvalue(), xml_test_out) - @requires_nonascii_filenames - def test_expat_inpsource_sysid_nonascii(self): - fname = support.TESTFN_UNICODE - shutil.copyfile(TEST_XMLFILE, fname) - self.addCleanup(support.unlink, fname) - - parser = create_parser() - result = BytesIO() - xmlgen = XMLGenerator(result) - - parser.setContentHandler(xmlgen) - parser.parse(InputSource(fname)) - - self.assertEqual(result.getvalue(), xml_test_out) - def test_expat_inpsource_stream(self): parser = create_parser() - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) inpsrc = InputSource() - with open(TEST_XMLFILE, 'rb') as f: + with open(TEST_XMLFILE) as f: inpsrc.setByteStream(f) parser.parse(inpsrc) @@ -818,7 +636,7 @@ # ===== IncrementalParser support def test_expat_incremental(self): - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) @@ -827,10 +645,10 @@ parser.feed("") parser.close() - self.assertEqual(result.getvalue(), start + b"") + self.assertEqual(result.getvalue(), start + "") def test_expat_incremental_reset(self): - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) @@ -838,7 +656,7 @@ parser.feed("") parser.feed("text") - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser.setContentHandler(xmlgen) parser.reset() @@ -848,12 +666,12 @@ parser.feed("") parser.close() - self.assertEqual(result.getvalue(), start + b"text") + self.assertEqual(result.getvalue(), start + "text") # ===== Locator support def test_expat_locator_noinfo(self): - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) @@ -867,7 +685,7 @@ self.assertEqual(parser.getLineNumber(), 1) def test_expat_locator_withinfo(self): - result = BytesIO() + result = StringIO() xmlgen = XMLGenerator(result) parser = create_parser() parser.setContentHandler(xmlgen) @@ -876,21 +694,6 @@ self.assertEqual(parser.getSystemId(), TEST_XMLFILE) self.assertEqual(parser.getPublicId(), None) - @requires_nonascii_filenames - def test_expat_locator_withinfo_nonascii(self): - fname = support.TESTFN_UNICODE - shutil.copyfile(TEST_XMLFILE, fname) - self.addCleanup(support.unlink, fname) - - result = BytesIO() - xmlgen = XMLGenerator(result) - parser = create_parser() - parser.setContentHandler(xmlgen) - parser.parse(fname) - - self.assertEqual(parser.getSystemId(), fname) - self.assertEqual(parser.getPublicId(), None) - # =========================================================================== # @@ -903,7 +706,7 @@ parser = create_parser() parser.setContentHandler(ContentHandler()) # do nothing source = InputSource() - source.setByteStream(BytesIO(b"")) #ill-formed + source.setByteStream(StringIO("")) #ill-formed name = "a file name" source.setSystemId(name) try: @@ -994,11 +797,7 @@ def test_main(): run_unittest(MakeParserTest, SaxutilsTest, - StringXmlgenTest, - BytesXmlgenTest, - WriterXmlgenTest, - StreamWriterXmlgenTest, - StreamReaderWriterXmlgenTest, + XmlgenTest, ExpatReaderTest, ErrorReportingTest, XmlReaderTest) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sched.py --- a/Lib/test/test_sched.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sched.py Fri Feb 01 23:12:09 2013 +0100 @@ -172,7 +172,7 @@ e3 = scheduler.enterabs(now + 0.03, 1, fun) # queue property is supposed to return an order list of # upcoming events - self.assertEqual(scheduler.queue, [e1, e2, e3, e4, e5]) + self.assertEqual(list(scheduler.queue), [e1, e2, e3, e4, e5]) def test_args_kwargs(self): flag = [] @@ -197,5 +197,8 @@ self.assertEqual(l, []) +def test_main(): + support.run_unittest(TestCase) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_scope.py --- a/Lib/test/test_scope.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_scope.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,4 @@ import unittest -import weakref - from test.support import check_syntax_error, cpython_only, run_unittest @@ -715,46 +713,6 @@ def b(): global a - def testClassNamespaceOverridesClosure(self): - # See #17853. - x = 42 - class X: - locals()["x"] = 43 - y = x - self.assertEqual(X.y, 43) - class X: - locals()["x"] = 43 - del x - self.assertFalse(hasattr(X, "x")) - self.assertEqual(x, 42) - - @cpython_only - def testCellLeak(self): - # Issue 17927. - # - # The issue was that if self was part of a cycle involving the - # frame of a method call, *and* the method contained a nested - # function referencing self, thereby forcing 'self' into a - # cell, setting self to None would not be enough to break the - # frame -- the frame had another reference to the instance, - # which could not be cleared by the code running in the frame - # (though it will be cleared when the frame is collected). - # Without the lambda, setting self to None is enough to break - # the cycle. - class Tester: - def dig(self): - if 0: - lambda: self - try: - 1/0 - except Exception as exc: - self.exc = exc - self = None # Break the cycle - tester = Tester() - tester.dig() - ref = weakref.ref(tester) - del tester - self.assertIsNone(ref()) def test_main(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_select.py --- a/Lib/test/test_select.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_select.py Fri Feb 01 23:12:09 2013 +0100 @@ -75,8 +75,56 @@ a[:] = [F()] * 10 self.assertEqual(select.select([], a, []), ([], a[:5], [])) + +@unittest.skipUnless(hasattr(os, 'get_cloexec'), "need os.get_cloexec()") +class CloexecTests(unittest.TestCase): + def setUp(self): + self.old_cloexec = sys.getdefaultcloexec() + + def tearDown(self): + sys.setdefaultcloexec(self.old_cloexec) + + @unittest.skipUnless(hasattr(select, 'devpoll'), "need select.devpoll()") + def test_devpoll_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + devpoll = select.devpoll() + else: + devpoll = select.devpoll(cloexec=cloexec) + self.assertEqual(os.get_cloexec(devpoll.fileno()), + cloexec) + devpoll = None + + @unittest.skipUnless(hasattr(select, 'epoll'), "need select.epoll()") + def test_epoll_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + epoll = select.epoll() + else: + epoll = select.epoll(cloexec=cloexec) + with epoll: + self.assertEqual(os.get_cloexec(epoll.fileno()), + cloexec) + + @unittest.skipUnless(hasattr(select, 'kqueue'), "need select.kqueue()") + def test_kqueue_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + kqueue = select.kqueue() + else: + kqueue = select.kqueue(cloexec=cloexec) + self.assertEqual(os.get_cloexec(kqueue.fileno()), + cloexec) + + def test_main(): - support.run_unittest(SelectTestCase) + support.run_unittest(SelectTestCase, CloexecTests) support.reap_children() if __name__ == "__main__": diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_set.py --- a/Lib/test/test_set.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_set.py Fri Feb 01 23:12:09 2013 +0100 @@ -37,7 +37,7 @@ self.hash_count += 1 return int.__hash__(self) -class TestJointOps: +class TestJointOps(unittest.TestCase): # Tests common to both set and frozenset def setUp(self): @@ -361,7 +361,7 @@ gc.collect() self.assertTrue(ref() is None, "Cycle was not collected") -class TestSet(TestJointOps, unittest.TestCase): +class TestSet(TestJointOps): thetype = set basetype = set @@ -647,7 +647,7 @@ 'SF bug #1486663 -- this used to erroneously raise a TypeError' SetSubclassWithKeywordArgs(newarg=1) -class TestFrozenSet(TestJointOps, unittest.TestCase): +class TestFrozenSet(TestJointOps): thetype = frozenset basetype = frozenset @@ -748,7 +748,7 @@ #============================================================================== -class TestBasicOps: +class TestBasicOps(unittest.TestCase): def test_repr(self): if self.repr is not None: @@ -858,7 +858,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsEmpty(TestBasicOps, unittest.TestCase): +class TestBasicOpsEmpty(TestBasicOps): def setUp(self): self.case = "empty set" self.values = [] @@ -869,7 +869,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsSingleton(TestBasicOps, unittest.TestCase): +class TestBasicOpsSingleton(TestBasicOps): def setUp(self): self.case = "unit set (number)" self.values = [3] @@ -886,7 +886,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsTuple(TestBasicOps, unittest.TestCase): +class TestBasicOpsTuple(TestBasicOps): def setUp(self): self.case = "unit set (tuple)" self.values = [(0, "zero")] @@ -903,7 +903,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsTriple(TestBasicOps, unittest.TestCase): +class TestBasicOpsTriple(TestBasicOps): def setUp(self): self.case = "triple set" self.values = [0, "zero", operator.add] @@ -914,7 +914,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsString(TestBasicOps, unittest.TestCase): +class TestBasicOpsString(TestBasicOps): def setUp(self): self.case = "string set" self.values = ["a", "b", "c"] @@ -927,7 +927,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsBytes(TestBasicOps, unittest.TestCase): +class TestBasicOpsBytes(TestBasicOps): def setUp(self): self.case = "string set" self.values = [b"a", b"b", b"c"] @@ -940,7 +940,7 @@ #------------------------------------------------------------------------------ -class TestBasicOpsMixedStringBytes(TestBasicOps, unittest.TestCase): +class TestBasicOpsMixedStringBytes(TestBasicOps): def setUp(self): self._warning_filters = support.check_warnings() self._warning_filters.__enter__() @@ -1239,7 +1239,7 @@ #============================================================================== -class TestSubsets: +class TestSubsets(unittest.TestCase): case2method = {"<=": "issubset", ">=": "issuperset", @@ -1277,7 +1277,7 @@ self.assertEqual(result, expected) #------------------------------------------------------------------------------ -class TestSubsetEqualEmpty(TestSubsets, unittest.TestCase): +class TestSubsetEqualEmpty(TestSubsets): left = set() right = set() name = "both empty" @@ -1285,7 +1285,7 @@ #------------------------------------------------------------------------------ -class TestSubsetEqualNonEmpty(TestSubsets, unittest.TestCase): +class TestSubsetEqualNonEmpty(TestSubsets): left = set([1, 2]) right = set([1, 2]) name = "equal pair" @@ -1293,7 +1293,7 @@ #------------------------------------------------------------------------------ -class TestSubsetEmptyNonEmpty(TestSubsets, unittest.TestCase): +class TestSubsetEmptyNonEmpty(TestSubsets): left = set() right = set([1, 2]) name = "one empty, one non-empty" @@ -1301,7 +1301,7 @@ #------------------------------------------------------------------------------ -class TestSubsetPartial(TestSubsets, unittest.TestCase): +class TestSubsetPartial(TestSubsets): left = set([1]) right = set([1, 2]) name = "one a non-empty proper subset of other" @@ -1309,7 +1309,7 @@ #------------------------------------------------------------------------------ -class TestSubsetNonOverlap(TestSubsets, unittest.TestCase): +class TestSubsetNonOverlap(TestSubsets): left = set([1]) right = set([2]) name = "neither empty, neither contains" @@ -1317,7 +1317,7 @@ #============================================================================== -class TestOnlySetsInBinaryOps: +class TestOnlySetsInBinaryOps(unittest.TestCase): def test_eq_ne(self): # Unlike the others, this is testing that == and != *are* allowed. @@ -1433,7 +1433,7 @@ #------------------------------------------------------------------------------ -class TestOnlySetsNumeric(TestOnlySetsInBinaryOps, unittest.TestCase): +class TestOnlySetsNumeric(TestOnlySetsInBinaryOps): def setUp(self): self.set = set((1, 2, 3)) self.other = 19 @@ -1441,7 +1441,7 @@ #------------------------------------------------------------------------------ -class TestOnlySetsDict(TestOnlySetsInBinaryOps, unittest.TestCase): +class TestOnlySetsDict(TestOnlySetsInBinaryOps): def setUp(self): self.set = set((1, 2, 3)) self.other = {1:2, 3:4} @@ -1449,7 +1449,7 @@ #------------------------------------------------------------------------------ -class TestOnlySetsOperator(TestOnlySetsInBinaryOps, unittest.TestCase): +class TestOnlySetsOperator(TestOnlySetsInBinaryOps): def setUp(self): self.set = set((1, 2, 3)) self.other = operator.add @@ -1457,7 +1457,7 @@ #------------------------------------------------------------------------------ -class TestOnlySetsTuple(TestOnlySetsInBinaryOps, unittest.TestCase): +class TestOnlySetsTuple(TestOnlySetsInBinaryOps): def setUp(self): self.set = set((1, 2, 3)) self.other = (2, 4, 6) @@ -1465,7 +1465,7 @@ #------------------------------------------------------------------------------ -class TestOnlySetsString(TestOnlySetsInBinaryOps, unittest.TestCase): +class TestOnlySetsString(TestOnlySetsInBinaryOps): def setUp(self): self.set = set((1, 2, 3)) self.other = 'abc' @@ -1473,7 +1473,7 @@ #------------------------------------------------------------------------------ -class TestOnlySetsGenerator(TestOnlySetsInBinaryOps, unittest.TestCase): +class TestOnlySetsGenerator(TestOnlySetsInBinaryOps): def setUp(self): def gen(): for i in range(0, 10, 2): @@ -1484,7 +1484,7 @@ #============================================================================== -class TestCopying: +class TestCopying(unittest.TestCase): def test_copy(self): dup = self.set.copy() @@ -1505,31 +1505,31 @@ #------------------------------------------------------------------------------ -class TestCopyingEmpty(TestCopying, unittest.TestCase): +class TestCopyingEmpty(TestCopying): def setUp(self): self.set = set() #------------------------------------------------------------------------------ -class TestCopyingSingleton(TestCopying, unittest.TestCase): +class TestCopyingSingleton(TestCopying): def setUp(self): self.set = set(["hello"]) #------------------------------------------------------------------------------ -class TestCopyingTriple(TestCopying, unittest.TestCase): +class TestCopyingTriple(TestCopying): def setUp(self): self.set = set(["zero", 0, None]) #------------------------------------------------------------------------------ -class TestCopyingTuple(TestCopying, unittest.TestCase): +class TestCopyingTuple(TestCopying): def setUp(self): self.set = set([(1, 2)]) #------------------------------------------------------------------------------ -class TestCopyingNested(TestCopying, unittest.TestCase): +class TestCopyingNested(TestCopying): def setUp(self): self.set = set([((1, 2), (3, 4))]) @@ -1835,5 +1835,58 @@ #============================================================================== +def test_main(verbose=None): + test_classes = ( + TestSet, + TestSetSubclass, + TestSetSubclassWithKeywordArgs, + TestFrozenSet, + TestFrozenSetSubclass, + TestSetOfSets, + TestExceptionPropagation, + TestBasicOpsEmpty, + TestBasicOpsSingleton, + TestBasicOpsTuple, + TestBasicOpsTriple, + TestBasicOpsString, + TestBasicOpsBytes, + TestBasicOpsMixedStringBytes, + TestBinaryOps, + TestUpdateOps, + TestMutate, + TestSubsetEqualEmpty, + TestSubsetEqualNonEmpty, + TestSubsetEmptyNonEmpty, + TestSubsetPartial, + TestSubsetNonOverlap, + TestOnlySetsNumeric, + TestOnlySetsDict, + TestOnlySetsOperator, + TestOnlySetsTuple, + TestOnlySetsString, + TestOnlySetsGenerator, + TestCopyingEmpty, + TestCopyingSingleton, + TestCopyingTriple, + TestCopyingTuple, + TestCopyingNested, + TestIdentities, + TestVariousIteratorArgs, + TestGraphs, + TestWeirdBugs, + ) + + support.run_unittest(*test_classes) + + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in range(len(counts)): + support.run_unittest(*test_classes) + gc.collect() + counts[i] = sys.gettotalrefcount() + print(counts) + if __name__ == "__main__": - unittest.main() + test_main(verbose=True) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_shlex.py --- a/Lib/test/test_shlex.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_shlex.py Fri Feb 01 23:12:09 2013 +0100 @@ -189,6 +189,7 @@ self.assertEqual(shlex.quote("test%s'name'" % u), "'test%s'\"'\"'name'\"'\"''" % u) + # Allow this test to be used with old shlex.py if not getattr(shlex, "split", None): for methname in dir(ShlexTest): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_shutil.py Fri Feb 01 23:12:09 2013 +0100 @@ -450,17 +450,6 @@ self.assertIn('user.bar', os.listxattr(dst)) finally: os.setxattr = orig_setxattr - # the source filesystem not supporting xattrs should be ok, too. - def _raise_on_src(fname, *, follow_symlinks=True): - if fname == src: - raise OSError(errno.ENOTSUP, 'Operation not supported') - return orig_listxattr(fname, follow_symlinks=follow_symlinks) - try: - orig_listxattr = os.listxattr - os.listxattr = _raise_on_src - shutil._copyxattr(src, dst) - finally: - os.listxattr = orig_listxattr # test that shutil.copystat copies xattrs src = os.path.join(tmp_dir, 'the_original') @@ -1291,13 +1280,12 @@ class TestWhich(unittest.TestCase): def setUp(self): - self.temp_dir = tempfile.mkdtemp(prefix="Tmp") + self.temp_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.temp_dir, True) # Give the temp_file an ".exe" suffix for all. # It's needed on Windows and not harmful on other platforms. self.temp_file = tempfile.NamedTemporaryFile(dir=self.temp_dir, - prefix="Tmp", - suffix=".Exe") + suffix=".exe") os.chmod(self.temp_file.name, stat.S_IXUSR) self.addCleanup(self.temp_file.close) self.dir, self.file = os.path.split(self.temp_file.name) @@ -1307,52 +1295,27 @@ rv = shutil.which(self.file, path=self.dir) self.assertEqual(rv, self.temp_file.name) - def test_absolute_cmd(self): + def test_full_path_short_circuit(self): # When given the fully qualified path to an executable that exists, # it should be returned. rv = shutil.which(self.temp_file.name, path=self.temp_dir) - self.assertEqual(rv, self.temp_file.name) + self.assertEqual(self.temp_file.name, rv) - def test_relative_cmd(self): - # When given the relative path with a directory part to an executable - # that exists, it should be returned. - base_dir, tail_dir = os.path.split(self.dir) - relpath = os.path.join(tail_dir, self.file) - with support.temp_cwd(path=base_dir): - rv = shutil.which(relpath, path=self.temp_dir) - self.assertEqual(rv, relpath) - # But it shouldn't be searched in PATH directories (issue #16957). - with support.temp_cwd(path=self.dir): - rv = shutil.which(relpath, path=base_dir) - self.assertIsNone(rv) - - def test_cwd(self): - # Issue #16957 - base_dir = os.path.dirname(self.dir) - with support.temp_cwd(path=self.dir): - rv = shutil.which(self.file, path=base_dir) - if sys.platform == "win32": - # Windows: current directory implicitly on PATH - self.assertEqual(rv, os.path.join(os.curdir, self.file)) - else: - # Other platforms: shouldn't match in the current directory. - self.assertIsNone(rv) - - @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0, - 'non-root user required') def test_non_matching_mode(self): # Set the file read-only and ask for writeable files. os.chmod(self.temp_file.name, stat.S_IREAD) - if os.access(self.temp_file.name, os.W_OK): - self.skipTest("can't set the file read-only") rv = shutil.which(self.file, path=self.dir, mode=os.W_OK) self.assertIsNone(rv) - def test_relative_path(self): + def test_relative(self): + old_cwd = os.getcwd() base_dir, tail_dir = os.path.split(self.dir) - with support.temp_cwd(path=base_dir): + os.chdir(base_dir) + try: rv = shutil.which(self.file, path=tail_dir) self.assertEqual(rv, os.path.join(tail_dir, self.file)) + finally: + os.chdir(old_cwd) def test_nonexistent_file(self): # Return None when no matching executable file is found on the path. @@ -1364,28 +1327,8 @@ def test_pathext_checking(self): # Ask for the file without the ".exe" extension, then ensure that # it gets found properly with the extension. - rv = shutil.which(self.file[:-4], path=self.dir) - self.assertEqual(rv, self.temp_file.name[:-4] + ".EXE") - - def test_environ_path(self): - with support.EnvironmentVarGuard() as env: - env['PATH'] = self.dir - rv = shutil.which(self.file) - self.assertEqual(rv, self.temp_file.name) - - def test_empty_path(self): - base_dir = os.path.dirname(self.dir) - with support.temp_cwd(path=self.dir), \ - support.EnvironmentVarGuard() as env: - env['PATH'] = self.dir - rv = shutil.which(self.file, path='') - self.assertIsNone(rv) - - def test_empty_path_no_PATH(self): - with support.EnvironmentVarGuard() as env: - env.pop('PATH', None) - rv = shutil.which(self.file) - self.assertIsNone(rv) + rv = shutil.which(self.temp_file.name[:-4], path=self.dir) + self.assertEqual(self.temp_file.name, rv) class TestMove(unittest.TestCase): @@ -1584,7 +1527,7 @@ self._delete = True def test_w_source_open_fails(self): - def _open(filename, mode='r'): + def _open(filename, mode='r', cloexec=None): if filename == 'srcfile': raise OSError('Cannot open "srcfile"') assert 0 # shouldn't reach here. @@ -1597,7 +1540,7 @@ srcfile = self.Faux() - def _open(filename, mode='r'): + def _open(filename, mode='r', cloexec=None): if filename == 'srcfile': return srcfile if filename == 'destfile': @@ -1617,7 +1560,7 @@ srcfile = self.Faux() destfile = self.Faux(True) - def _open(filename, mode='r'): + def _open(filename, mode='r', cloexec=None): if filename == 'srcfile': return srcfile if filename == 'destfile': @@ -1639,7 +1582,7 @@ srcfile = self.Faux(True) destfile = self.Faux() - def _open(filename, mode='r'): + def _open(filename, mode='r', cloexec=None): if filename == 'srcfile': return srcfile if filename == 'destfile': @@ -1719,5 +1662,9 @@ self.assertEqual(expected, actual) +def test_main(): + support.run_unittest(TestShutil, TestMove, TestCopyFile, + TermsizeTests, TestWhich) + if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_signal.py --- a/Lib/test/test_signal.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_signal.py Fri Feb 01 23:12:09 2013 +0100 @@ -219,13 +219,6 @@ signal.signal(7, handler) -class WakeupFDTests(unittest.TestCase): - - def test_invalid_fd(self): - fd = support.make_bad_fd() - self.assertRaises(ValueError, signal.set_wakeup_fd, fd) - - @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class WakeupSignalTests(unittest.TestCase): def check_wakeup(self, test_body, *signals, ordered=True): @@ -702,10 +695,6 @@ @unittest.skipUnless(hasattr(signal, 'sigwaitinfo'), 'need signal.sigwaitinfo()') - # Issue #18238: sigwaitinfo() can be interrupted on Linux (raises - # InterruptedError), but not on AIX - @unittest.skipIf(sys.platform.startswith("aix"), - 'signal.sigwaitinfo() cannot be interrupted on AIX') def test_sigwaitinfo_interrupted(self): self.wait_helper(signal.SIGUSR1, ''' def test(signum): @@ -872,8 +861,8 @@ def test_main(): try: support.run_unittest(PosixTests, InterProcessSignalTests, - WakeupFDTests, WakeupSignalTests, - SiginterruptTest, ItimerTest, WindowsSignalTests, + WakeupSignalTests, SiginterruptTest, + ItimerTest, WindowsSignalTests, PendingSignalsTests) finally: support.reap_children() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_site.py --- a/Lib/test/test_site.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_site.py Fri Feb 01 23:12:09 2013 +0100 @@ -401,6 +401,8 @@ else: self.fail("sitecustomize not imported automatically") +def test_main(): + run_unittest(HelperFunctionsTests, ImportSideEffectTests) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_smtplib.py Fri Feb 01 23:12:09 2013 +0100 @@ -586,12 +586,8 @@ # Simulated SMTP channel & server class SimSMTPChannel(smtpd.SMTPChannel): + # For testing failures in QUIT when using the context manager API. quit_response = None - mail_response = None - rcpt_response = None - data_response = None - rcpt_count = 0 - rset_count = 0 def __init__(self, extra_features, *args, **kw): self._extrafeatures = ''.join( @@ -606,8 +602,6 @@ '250-DELIVERBY\r\n') resp = resp + self._extrafeatures + '250 HELP' self.push(resp) - self.seen_greeting = arg - self.extended_smtp = True def smtp_VRFY(self, arg): # For max compatibility smtplib should be sending the raw address. @@ -646,50 +640,30 @@ self.push('550 No access for you!') def smtp_QUIT(self, arg): + # args is ignored if self.quit_response is None: super(SimSMTPChannel, self).smtp_QUIT(arg) else: self.push(self.quit_response) self.close_when_done() - def smtp_MAIL(self, arg): - if self.mail_response is None: - super().smtp_MAIL(arg) - else: - self.push(self.mail_response) - - def smtp_RCPT(self, arg): - if self.rcpt_response is None: - super().smtp_RCPT(arg) - return - self.rcpt_count += 1 - self.push(self.rcpt_response[self.rcpt_count-1]) - - def smtp_RSET(self, arg): - self.rset_count += 1 - super().smtp_RSET(arg) - - def smtp_DATA(self, arg): - if self.data_response is None: - super().smtp_DATA(arg) - else: - self.push(self.data_response) - def handle_error(self): raise class SimSMTPServer(smtpd.SMTPServer): - channel_class = SimSMTPChannel + # For testing failures in QUIT when using the context manager API. + quit_response = None def __init__(self, *args, **kw): self._extra_features = [] smtpd.SMTPServer.__init__(self, *args, **kw) def handle_accepted(self, conn, addr): - self._SMTPchannel = self.channel_class( + self._SMTPchannel = SimSMTPChannel( self._extra_features, self, conn, addr) + self._SMTPchannel.quit_response = self.quit_response def process_message(self, peer, mailfrom, rcpttos, data): pass @@ -829,51 +803,18 @@ self.assertRaises(smtplib.SMTPServerDisconnected, smtp.send, b'foo') def test_with_statement_QUIT_failure(self): + self.serv.quit_response = '421 QUIT FAILED' with self.assertRaises(smtplib.SMTPResponseException) as error: with smtplib.SMTP(HOST, self.port) as smtp: smtp.noop() - self.serv._SMTPchannel.quit_response = '421 QUIT FAILED' self.assertEqual(error.exception.smtp_code, 421) self.assertEqual(error.exception.smtp_error, b'QUIT FAILED') + # We don't need to clean up self.serv.quit_response because a new + # server is always instantiated in the setUp(). #TODO: add tests for correct AUTH method fallback now that the #test infrastructure can support it. - # Issue 5713: make sure close, not rset, is called if we get a 421 error - def test_421_from_mail_cmd(self): - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) - smtp.noop() - self.serv._SMTPchannel.mail_response = '421 closing connection' - with self.assertRaises(smtplib.SMTPSenderRefused): - smtp.sendmail('John', 'Sally', 'test message') - self.assertIsNone(smtp.sock) - self.assertEqual(self.serv._SMTPchannel.rset_count, 0) - - def test_421_from_rcpt_cmd(self): - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) - smtp.noop() - self.serv._SMTPchannel.rcpt_response = ['250 accepted', '421 closing'] - with self.assertRaises(smtplib.SMTPRecipientsRefused) as r: - smtp.sendmail('John', ['Sally', 'Frank', 'George'], 'test message') - self.assertIsNone(smtp.sock) - self.assertEqual(self.serv._SMTPchannel.rset_count, 0) - self.assertDictEqual(r.exception.args[0], {'Frank': (421, b'closing')}) - - def test_421_from_data_cmd(self): - class MySimSMTPChannel(SimSMTPChannel): - def found_terminator(self): - if self.smtp_state == self.DATA: - self.push('421 closing') - else: - super().found_terminator() - self.serv.channel_class = MySimSMTPChannel - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) - smtp.noop() - with self.assertRaises(smtplib.SMTPDataError): - smtp.sendmail('John@foo.org', ['Sally@foo.org'], 'test message') - self.assertIsNone(smtp.sock) - self.assertEqual(self.serv._SMTPchannel.rcpt_count, 0) - @support.reap_threads def test_main(verbose=None): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sndhdr.py --- a/Lib/test/test_sndhdr.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sndhdr.py Fri Feb 01 23:12:09 2013 +0100 @@ -12,7 +12,7 @@ ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.voc', ('voc', 0, 1, -1, 8)), - ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), + ('sndhdr.wav', ('wav', 44100, 2, -1, 16)), ): filename = findfile(filename, subdir="sndhdrdata") what = sndhdr.what(filename) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_socket.py --- a/Lib/test/test_socket.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_socket.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,7 @@ import unittest from test import support +from unittest.case import _ExpectedFailure import errno import io @@ -23,10 +24,6 @@ import pickle import struct try: - import fcntl -except ImportError: - fcntl = False -try: import multiprocessing except ImportError: multiprocessing = False @@ -120,36 +117,6 @@ interface = 'vcan0' bufsize = 128 - """The CAN frame structure is defined in : - - struct can_frame { - canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ - __u8 can_dlc; /* data length code: 0 .. 8 */ - __u8 data[8] __attribute__((aligned(8))); - }; - """ - can_frame_fmt = "=IB3x8s" - can_frame_size = struct.calcsize(can_frame_fmt) - - """The Broadcast Management Command frame structure is defined - in : - - struct bcm_msg_head { - __u32 opcode; - __u32 flags; - __u32 count; - struct timeval ival1, ival2; - canid_t can_id; - __u32 nframes; - struct can_frame frames[0]; - } - - `bcm_msg_head` must be 8 bytes aligned because of the `frames` member (see - `struct can_frame` definition). Must use native not standard types for packing. - """ - bcm_cmd_msg_fmt = "@3I4l2I" - bcm_cmd_msg_fmt += "x" * (struct.calcsize(bcm_cmd_msg_fmt) % 8) - def setUp(self): self.s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) self.addCleanup(self.s.close) @@ -271,6 +238,9 @@ raise TypeError("test_func must be a callable function") try: test_func() + except _ExpectedFailure: + # We deliberately ignore expected failures + pass except BaseException as e: self.queue.put(e) finally: @@ -652,17 +622,8 @@ def test_repr(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - with s: - self.assertIn('fd=%i' % s.fileno(), repr(s)) - self.assertIn('family=%i' % socket.AF_INET, repr(s)) - self.assertIn('type=%i' % socket.SOCK_STREAM, repr(s)) - self.assertIn('proto=0', repr(s)) - self.assertNotIn('raddr', repr(s)) - s.bind(('127.0.0.1', 0)) - self.assertIn('laddr', repr(s)) - self.assertIn(str(s.getsockname()), repr(s)) - self.assertIn('[closed]', repr(s)) - self.assertNotIn('laddr', repr(s)) + self.addCleanup(s.close) + self.assertTrue(repr(s).startswith(": + + struct can_frame { + canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ + __u8 can_dlc; /* data length code: 0 .. 8 */ + __u8 data[8] __attribute__((aligned(8))); + }; + """ + can_frame_fmt = "=IB3x8s" + def __init__(self, methodName='runTest'): ThreadedCANSocketTest.__init__(self, methodName=methodName) @@ -1441,46 +1386,6 @@ self.cf2 = self.build_can_frame(0x12, b'\x99\x22\x33') self.cli.send(self.cf2) - @unittest.skipUnless(hasattr(socket, "CAN_BCM"), - 'socket.CAN_BCM required for this test.') - def _testBCM(self): - cf, addr = self.cli.recvfrom(self.bufsize) - self.assertEqual(self.cf, cf) - can_id, can_dlc, data = self.dissect_can_frame(cf) - self.assertEqual(self.can_id, can_id) - self.assertEqual(self.data, data) - - @unittest.skipUnless(hasattr(socket, "CAN_BCM"), - 'socket.CAN_BCM required for this test.') - def testBCM(self): - bcm = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM) - self.addCleanup(bcm.close) - bcm.connect((self.interface,)) - self.can_id = 0x123 - self.data = bytes([0xc0, 0xff, 0xee]) - self.cf = self.build_can_frame(self.can_id, self.data) - opcode = socket.CAN_BCM_TX_SEND - flags = 0 - count = 0 - ival1_seconds = ival1_usec = ival2_seconds = ival2_usec = 0 - bcm_can_id = 0x0222 - nframes = 1 - assert len(self.cf) == 16 - header = struct.pack(self.bcm_cmd_msg_fmt, - opcode, - flags, - count, - ival1_seconds, - ival1_usec, - ival2_seconds, - ival2_usec, - bcm_can_id, - nframes, - ) - header_plus_frame = header + self.cf - bytes_sent = bcm.send(header_plus_frame) - self.assertEqual(bytes_sent, len(header_plus_frame)) - @unittest.skipUnless(HAVE_SOCKET_RDS, 'RDS sockets required for this test.') class BasicRDSTest(unittest.TestCase): @@ -2622,7 +2527,8 @@ def _testFDPassCMSG_LEN(self): self.createAndSendFDs(1) - @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") + # Issue #12958: The following test has problems on Mac OS X + @support.anticipate_failure(sys.platform == "darwin") @requireAttrs(socket, "CMSG_SPACE") def testFDPassSeparate(self): # Pass two FDs in two separate arrays. Arrays may be combined @@ -2632,7 +2538,7 @@ maxcmsgs=2) @testFDPassSeparate.client_skip - @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") + @support.anticipate_failure(sys.platform == "darwin") def _testFDPassSeparate(self): fd0, fd1 = self.newFDs(2) self.assertEqual( @@ -2644,7 +2550,8 @@ array.array("i", [fd1]))]), len(MSG)) - @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") + # Issue #12958: The following test has problems on Mac OS X + @support.anticipate_failure(sys.platform == "darwin") @requireAttrs(socket, "CMSG_SPACE") def testFDPassSeparateMinSpace(self): # Pass two FDs in two separate arrays, receiving them into the @@ -2656,7 +2563,7 @@ maxcmsgs=2, ignoreflags=socket.MSG_CTRUNC) @testFDPassSeparateMinSpace.client_skip - @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") + @support.anticipate_failure(sys.platform == "darwin") def _testFDPassSeparateMinSpace(self): fd0, fd1 = self.newFDs(2) self.assertEqual( @@ -3312,11 +3219,7 @@ class SendrecvmsgUDP6TestBase(SendrecvmsgDgramFlagsBase, SendrecvmsgConnectionlessBase, ThreadedSocketTestMixin, UDP6TestBase): - - def checkRecvmsgAddress(self, addr1, addr2): - # Called to compare the received address with the address of - # the peer, ignoring scope ID - self.assertEqual(addr1[:-1], addr2[:-1]) + pass @requireAttrs(socket.socket, "sendmsg") @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') @@ -4748,16 +4651,69 @@ self.assertRaises(OSError, sock.sendall, b'foo') -@unittest.skipUnless(hasattr(socket, "SOCK_CLOEXEC"), - "SOCK_CLOEXEC not defined") -@unittest.skipUnless(fcntl, "module fcntl not available") -class CloexecConstantTest(unittest.TestCase): +@unittest.skipUnless(hasattr(os, 'get_cloexec'), "need os.get_cloexec()") +class CloexecTest(unittest.TestCase): + def setUp(self): + self.old_cloexec = sys.getdefaultcloexec() + + def tearDown(self): + sys.setdefaultcloexec(self.old_cloexec) + + @unittest.skipUnless(hasattr(socket, "SOCK_CLOEXEC"), + "SOCK_CLOEXEC not defined") @support.requires_linux_version(2, 6, 28) def test_SOCK_CLOEXEC(self): with socket.socket(socket.AF_INET, socket.SOCK_STREAM | socket.SOCK_CLOEXEC) as s: self.assertTrue(s.type & socket.SOCK_CLOEXEC) - self.assertTrue(fcntl.fcntl(s, fcntl.F_GETFD) & fcntl.FD_CLOEXEC) + self.assertTrue(os.get_cloexec(sock.fileno())) + + def test_socket_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + sock = socket.socket() + else: + sock = socket.socket(cloexec=cloexec) + with sock: + self.assertEqual(os.get_cloexec(sock.fileno()), cloexec) + + def test_dup_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + sock = socket.socket(cloexec=not cloexec) + if set_default: + sys.setdefaultcloexec(cloexec) + newsock = sock.dup() + else: + newsock = sock.dup(cloexec=cloexec) + sock.close() + self.assertEqual(os.get_cloexec(newsock.fileno()), cloexec) + newsock.close() + + def test_socket_set_cloexec(self): + sock = socket.socket(cloexec=False) + with sock: + # On Windows, fileno() returns an handle, not a file descriptor. + # Check if it is accepted. + os.set_cloexec(sock.fileno()) + self.assertEqual(os.get_cloexec(sock.fileno()), True) + + @unittest.skipUnless(hasattr(socket, "socketpair"), + "need socket.socketpair()") + def test_socketpair_cloexec(self): + for cloexec in (False, True): + for set_default in (False, True): + if set_default: + sys.setdefaultcloexec(cloexec) + s1, s2 = socket.socketpair() + else: + s1, s2 = socket.socketpair(cloexec=cloexec) + self.assertEqual(os.get_cloexec(s1.fileno()), cloexec) + self.assertEqual(os.get_cloexec(s2.fileno()), cloexec) + s1.close() + s2.close() @unittest.skipUnless(hasattr(socket, "SOCK_NONBLOCK"), @@ -4926,7 +4882,7 @@ NetworkConnectionAttributesTest, NetworkConnectionBehaviourTest, ContextManagersTest, - CloexecConstantTest, + CloexecTest, NonblockConstantTest ]) if hasattr(socket, "socketpair"): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_socketserver.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,8 +2,8 @@ Test suite for socketserver. """ -import _imp as imp import contextlib +import imp import os import select import signal diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_source_encoding.py --- a/Lib/test/test_source_encoding.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -# -*- coding: koi8-r -*- - -import unittest -from test.support import TESTFN, unlink, unload -import importlib -import os -import sys - -class SourceEncodingTest(unittest.TestCase): - - def test_pep263(self): - self.assertEqual( - "ðÉÔÏÎ".encode("utf-8"), - b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' - ) - self.assertEqual( - "\ð".encode("utf-8"), - b'\\\xd0\x9f' - ) - - def test_compilestring(self): - # see #1882 - c = compile(b"\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec") - d = {} - exec(c, d) - self.assertEqual(d['u'], '\xf3') - - def test_issue2301(self): - try: - compile(b"# coding: cp932\nprint '\x94\x4e'", "dummy", "exec") - except SyntaxError as v: - self.assertEqual(v.text, "print '\u5e74'\n") - else: - self.fail() - - def test_issue4626(self): - c = compile("# coding=latin-1\n\u00c6 = '\u00c6'", "dummy", "exec") - d = {} - exec(c, d) - self.assertEqual(d['\xc6'], '\xc6') - - def test_issue3297(self): - c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec") - d = {} - exec(c, d) - self.assertEqual(d['a'], d['b']) - self.assertEqual(len(d['a']), len(d['b'])) - self.assertEqual(ascii(d['a']), ascii(d['b'])) - - def test_issue7820(self): - # Ensure that check_bom() restores all bytes in the right order if - # check_bom() fails in pydebug mode: a buffer starts with the first - # byte of a valid BOM, but next bytes are different - - # one byte in common with the UTF-16-LE BOM - self.assertRaises(SyntaxError, eval, b'\xff\x20') - - # two bytes in common with the UTF-8 BOM - self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20') - - def test_error_message(self): - compile(b'# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec') - compile(b'\xef\xbb\xbf\n', 'dummy', 'exec') - compile(b'\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec') - with self.assertRaisesRegex(SyntaxError, 'fake'): - compile(b'# -*- coding: fake -*-\n', 'dummy', 'exec') - with self.assertRaisesRegex(SyntaxError, 'iso-8859-15'): - compile(b'\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', - 'dummy', 'exec') - with self.assertRaisesRegex(SyntaxError, 'BOM'): - compile(b'\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', - 'dummy', 'exec') - with self.assertRaisesRegex(SyntaxError, 'fake'): - compile(b'\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec') - with self.assertRaisesRegex(SyntaxError, 'BOM'): - compile(b'\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec') - - def test_bad_coding(self): - module_name = 'bad_coding' - self.verify_bad_module(module_name) - - def test_bad_coding2(self): - module_name = 'bad_coding2' - self.verify_bad_module(module_name) - - def verify_bad_module(self, module_name): - self.assertRaises(SyntaxError, __import__, 'test.' + module_name) - - path = os.path.dirname(__file__) - filename = os.path.join(path, module_name + '.py') - with open(filename, "rb") as fp: - bytes = fp.read() - self.assertRaises(SyntaxError, compile, bytes, filename, 'exec') - - def test_exec_valid_coding(self): - d = {} - exec(b'# coding: cp949\na = "\xaa\xa7"\n', d) - self.assertEqual(d['a'], '\u3047') - - def test_file_parse(self): - # issue1134: all encodings outside latin-1 and utf-8 fail on - # multiline strings and long lines (>512 columns) - unload(TESTFN) - filename = TESTFN + ".py" - f = open(filename, "w", encoding="cp1252") - sys.path.insert(0, os.curdir) - try: - with f: - f.write("# -*- coding: cp1252 -*-\n") - f.write("'''A short string\n") - f.write("'''\n") - f.write("'A very long string %s'\n" % ("X" * 1000)) - - importlib.invalidate_caches() - __import__(TESTFN) - finally: - del sys.path[0] - unlink(filename) - unlink(filename + "c") - unlink(filename + "o") - unload(TESTFN) - - def test_error_from_string(self): - # See http://bugs.python.org/issue6289 - input = "# coding: ascii\n\N{SNOWMAN}".encode('utf-8') - with self.assertRaises(SyntaxError) as c: - compile(input, "", "exec") - expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ - "ordinal not in range(128)" - self.assertTrue(c.exception.args[0].startswith(expected), - msg=c.exception.args[0]) - - -if __name__ == "__main__": - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sqlite.py --- a/Lib/test/test_sqlite.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sqlite.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,22 +3,21 @@ # Skip test if _sqlite3 module not installed test.support.import_module('_sqlite3') -import unittest import sqlite3 from sqlite3.test import (dbapi, types, userfunctions, factory, transactions, hooks, regression, dump) -def load_tests(*args): +def test_main(): if test.support.verbose: print("test_sqlite: testing with version", "{!r}, sqlite_version {!r}".format(sqlite3.version, sqlite3.sqlite_version)) - return unittest.TestSuite([dbapi.suite(), types.suite(), + test.support.run_unittest(dbapi.suite(), types.suite(), userfunctions.suite(), factory.suite(), transactions.suite(), hooks.suite(), regression.suite(), - dump.suite()]) + dump.suite()) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ssl.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,6 @@ import socket import select import time -import datetime import gc import os import errno @@ -18,11 +17,16 @@ import weakref import platform import functools -from unittest import mock ssl = support.import_module("ssl") -PROTOCOLS = sorted(ssl._PROTOCOL_NAMES) +PROTOCOLS = [ + ssl.PROTOCOL_SSLv3, + ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1 +] +if hasattr(ssl, 'PROTOCOL_SSLv2'): + PROTOCOLS.append(ssl.PROTOCOL_SSLv2) + HOST = support.HOST data_file = lambda name: os.path.join(os.path.dirname(__file__), name) @@ -74,19 +78,6 @@ # 0.9.7h or higher return ssl.OPENSSL_VERSION_INFO >= (0, 9, 7, 8, 15) -def asn1time(cert_time): - # Some versions of OpenSSL ignore seconds, see #18207 - # 0.9.8.i - if ssl._OPENSSL_API_VERSION == (0, 9, 8, 9, 15): - fmt = "%b %d %H:%M:%S %Y GMT" - dt = datetime.datetime.strptime(cert_time, fmt) - dt = dt.replace(second=0) - cert_time = dt.strftime(fmt) - # %d adds leading zero but ASN1_TIME_print() uses leading space - if cert_time[4] == "0": - cert_time = cert_time[:4] + " " + cert_time[5:] - - return cert_time # Issue #9415: Ubuntu hijacks their OpenSSL and forcefully disables SSLv2 def skip_if_broken_ubuntu_ssl(func): @@ -110,6 +101,10 @@ class BasicSocketTests(unittest.TestCase): def test_constants(self): + #ssl.PROTOCOL_SSLv2 + ssl.PROTOCOL_SSLv23 + ssl.PROTOCOL_SSLv3 + ssl.PROTOCOL_TLSv1 ssl.CERT_NONE ssl.CERT_OPTIONAL ssl.CERT_REQUIRED @@ -156,8 +151,8 @@ (('commonName', 'localhost'),)) ) # Note the next three asserts will fail if the keys are regenerated - self.assertEqual(p['notAfter'], asn1time('Oct 5 23:01:56 2020 GMT')) - self.assertEqual(p['notBefore'], asn1time('Oct 8 23:01:56 2010 GMT')) + self.assertEqual(p['notAfter'], 'Oct 5 23:01:56 2020 GMT') + self.assertEqual(p['notBefore'], 'Oct 8 23:01:56 2010 GMT') self.assertEqual(p['serialNumber'], 'D7C7381919AFC24E') self.assertEqual(p['subject'], ((('countryName', 'XY'),), @@ -363,17 +358,6 @@ self.assertRaises(ValueError, ssl.match_hostname, None, 'example.com') self.assertRaises(ValueError, ssl.match_hostname, {}, 'example.com') - # Issue #17980: avoid denials of service by refusing more than one - # wildcard per fragment. - cert = {'subject': ((('commonName', 'a*b.com'),),)} - ok(cert, 'axxb.com') - cert = {'subject': ((('commonName', 'a*b.co*'),),)} - ok(cert, 'axxb.com') - cert = {'subject': ((('commonName', 'a*b*.com'),),)} - with self.assertRaises(ssl.CertificateError) as cm: - ssl.match_hostname(cert, 'axxbxxc.com') - self.assertIn("too many wildcards", str(cm.exception)) - def test_server_side(self): # server_hostname doesn't work for server sockets ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) @@ -408,48 +392,15 @@ support.gc_collect() self.assertIn(r, str(cm.warning.args[0])) - def test_get_default_verify_paths(self): - paths = ssl.get_default_verify_paths() - self.assertEqual(len(paths), 6) - self.assertIsInstance(paths, ssl.DefaultVerifyPaths) - - with support.EnvironmentVarGuard() as env: - env["SSL_CERT_DIR"] = CAPATH - env["SSL_CERT_FILE"] = CERTFILE - paths = ssl.get_default_verify_paths() - self.assertEqual(paths.cafile, CERTFILE) - self.assertEqual(paths.capath, CAPATH) - - - @unittest.skipUnless(sys.platform == "win32", "Windows specific") - def test_enum_cert_store(self): - self.assertEqual(ssl.X509_ASN_ENCODING, 1) - self.assertEqual(ssl.PKCS_7_ASN_ENCODING, 0x00010000) - - self.assertEqual(ssl.enum_cert_store("CA"), - ssl.enum_cert_store("CA", "certificate")) - ssl.enum_cert_store("CA", "crl") - self.assertEqual(ssl.enum_cert_store("ROOT"), - ssl.enum_cert_store("ROOT", "certificate")) - ssl.enum_cert_store("ROOT", "crl") - - self.assertRaises(TypeError, ssl.enum_cert_store) - self.assertRaises(WindowsError, ssl.enum_cert_store, "") - self.assertRaises(ValueError, ssl.enum_cert_store, "CA", "wrong") - - ca = ssl.enum_cert_store("CA") - self.assertIsInstance(ca, list) - self.assertIsInstance(ca[0], tuple) - self.assertEqual(len(ca[0]), 2) - self.assertIsInstance(ca[0][0], bytes) - self.assertIsInstance(ca[0][1], int) - class ContextTests(unittest.TestCase): @skip_if_broken_ubuntu_ssl def test_constructor(self): - for protocol in PROTOCOLS: - ssl.SSLContext(protocol) + if hasattr(ssl, 'PROTOCOL_SSLv2'): + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv2) + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv3) + ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) self.assertRaises(TypeError, ssl.SSLContext) self.assertRaises(ValueError, ssl.SSLContext, -1) self.assertRaises(ValueError, ssl.SSLContext, 42) @@ -680,47 +631,6 @@ gc.collect() self.assertIs(wr(), None) - def test_cert_store_stats(self): - ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) - self.assertEqual(ctx.cert_store_stats(), - {'x509_ca': 0, 'crl': 0, 'x509': 0}) - ctx.load_cert_chain(CERTFILE) - self.assertEqual(ctx.cert_store_stats(), - {'x509_ca': 0, 'crl': 0, 'x509': 0}) - ctx.load_verify_locations(CERTFILE) - self.assertEqual(ctx.cert_store_stats(), - {'x509_ca': 0, 'crl': 0, 'x509': 1}) - ctx.load_verify_locations(SVN_PYTHON_ORG_ROOT_CERT) - self.assertEqual(ctx.cert_store_stats(), - {'x509_ca': 1, 'crl': 0, 'x509': 2}) - - def test_get_ca_certs(self): - ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) - self.assertEqual(ctx.get_ca_certs(), []) - # CERTFILE is not flagged as X509v3 Basic Constraints: CA:TRUE - ctx.load_verify_locations(CERTFILE) - self.assertEqual(ctx.get_ca_certs(), []) - # but SVN_PYTHON_ORG_ROOT_CERT is a CA cert - ctx.load_verify_locations(SVN_PYTHON_ORG_ROOT_CERT) - self.assertEqual(ctx.get_ca_certs(), - [{'issuer': ((('organizationName', 'Root CA'),), - (('organizationalUnitName', 'http://www.cacert.org'),), - (('commonName', 'CA Cert Signing Authority'),), - (('emailAddress', 'support@cacert.org'),)), - 'notAfter': asn1time('Mar 29 12:29:49 2033 GMT'), - 'notBefore': asn1time('Mar 30 12:29:49 2003 GMT'), - 'serialNumber': '00', - 'subject': ((('organizationName', 'Root CA'),), - (('organizationalUnitName', 'http://www.cacert.org'),), - (('commonName', 'CA Cert Signing Authority'),), - (('emailAddress', 'support@cacert.org'),)), - 'version': 3}]) - - with open(SVN_PYTHON_ORG_ROOT_CERT) as f: - pem = f.read() - der = ssl.PEM_cert_to_DER_cert(pem) - self.assertEqual(ctx.get_ca_certs(True), [der]) - class SSLErrorTests(unittest.TestCase): @@ -1036,22 +946,6 @@ finally: s.close() - def test_get_ca_certs_capath(self): - # capath certs are loaded on request - with support.transient_internet("svn.python.org"): - ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - ctx.verify_mode = ssl.CERT_REQUIRED - ctx.load_verify_locations(capath=CAPATH) - self.assertEqual(ctx.get_ca_certs(), []) - s = ctx.wrap_socket(socket.socket(socket.AF_INET)) - s.connect(("svn.python.org", 443)) - try: - cert = s.getpeercert() - self.assertTrue(cert) - finally: - s.close() - self.assertEqual(len(ctx.get_ca_certs()), 1) - try: import threading @@ -1085,11 +979,7 @@ self.sslconn = self.server.context.wrap_socket( self.sock, server_side=True) self.server.selected_protocols.append(self.sslconn.selected_npn_protocol()) - except (ssl.SSLError, ConnectionResetError) as e: - # We treat ConnectionResetError as though it were an - # SSLError - OpenSSL on Ubuntu abruptly closes the - # connection when asked to use an unsupported protocol. - # + except ssl.SSLError as e: # XXX Various errors can have happened here, for example # a mismatching protocol version, an invalid certificate, # or a low-level bug. This should be made more discriminating. @@ -1466,15 +1356,12 @@ client_context.options = ssl.OP_ALL | client_options server_context = ssl.SSLContext(server_protocol) server_context.options = ssl.OP_ALL | server_options - - # NOTE: we must enable "ALL" ciphers on the client, otherwise an - # SSLv23 client will send an SSLv3 hello (rather than SSLv2) - # starting from OpenSSL 1.0.0 (see issue #8322). - if client_context.protocol == ssl.PROTOCOL_SSLv23: - client_context.set_ciphers("ALL") - for ctx in (client_context, server_context): ctx.verify_mode = certsreqs + # NOTE: we must enable "ALL" ciphers, otherwise an SSLv23 client + # will send an SSLv3 hello (rather than SSLv2) starting from + # OpenSSL 1.0.0 (see issue #8322). + ctx.set_ciphers("ALL") ctx.load_cert_chain(CERTFILE) ctx.load_verify_locations(CERTFILE) try: @@ -1504,11 +1391,10 @@ if support.verbose: sys.stdout.write("\n") for protocol in PROTOCOLS: - with self.subTest(protocol=ssl._PROTOCOL_NAMES[protocol]): - context = ssl.SSLContext(protocol) - context.load_cert_chain(CERTFILE) - server_params_test(context, context, - chatty=True, connectionchatty=True) + context = ssl.SSLContext(protocol) + context.load_cert_chain(CERTFILE) + server_params_test(context, context, + chatty=True, connectionchatty=True) def test_getpeercert(self): if support.verbose: @@ -1691,49 +1577,6 @@ try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv23, False, client_options=ssl.OP_NO_TLSv1) - @skip_if_broken_ubuntu_ssl - @unittest.skipUnless(hasattr(ssl, "PROTOCOL_TLSv1_1"), - "TLS version 1.1 not supported.") - def test_protocol_tlsv1_1(self): - """Connecting to a TLSv1.1 server with various client options. - Testing against older TLS versions.""" - if support.verbose: - sys.stdout.write("\n") - try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_1, True) - if hasattr(ssl, 'PROTOCOL_SSLv2'): - try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_SSLv2, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_SSLv3, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_SSLv23, False, - client_options=ssl.OP_NO_TLSv1_1) - - try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1_1, True) - try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_1, False) - - - @skip_if_broken_ubuntu_ssl - @unittest.skipUnless(hasattr(ssl, "PROTOCOL_TLSv1_2"), - "TLS version 1.2 not supported.") - def test_protocol_tlsv1_2(self): - """Connecting to a TLSv1.2 server with various client options. - Testing against older TLS versions.""" - if support.verbose: - sys.stdout.write("\n") - try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_2, True, - server_options=ssl.OP_NO_SSLv3|ssl.OP_NO_SSLv2, - client_options=ssl.OP_NO_SSLv3|ssl.OP_NO_SSLv2,) - if hasattr(ssl, 'PROTOCOL_SSLv2'): - try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_SSLv2, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_SSLv3, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_SSLv23, False, - client_options=ssl.OP_NO_TLSv1_2) - - try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1_2, True) - try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False) - try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False) - def test_starttls(self): """Switching from clear text to encrypted and back again.""" msgs = (b"msg 1", b"MSG 2", b"STARTTLS", b"MSG 3", b"msg 4", b"ENDTLS", b"msg 5", b"msg 6") @@ -1794,7 +1637,7 @@ def test_socketserver(self): """Using a SocketServer to create and manage SSL connections.""" - server = make_https_server(self, certfile=CERTFILE) + server = make_https_server(self, CERTFILE) # try to connect if support.verbose: sys.stdout.write('\n') @@ -2050,20 +1893,6 @@ self.assertIsInstance(remote, ssl.SSLSocket) self.assertEqual(peer, client_addr) - def test_getpeercert_enotconn(self): - context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - with context.wrap_socket(socket.socket()) as sock: - with self.assertRaises(OSError) as cm: - sock.getpeercert() - self.assertEqual(cm.exception.errno, errno.ENOTCONN) - - def test_do_handshake_enotconn(self): - context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - with context.wrap_socket(socket.socket()) as sock: - with self.assertRaises(OSError) as cm: - sock.do_handshake() - self.assertEqual(cm.exception.errno, errno.ENOTCONN) - def test_default_ciphers(self): context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) try: @@ -2229,8 +2058,7 @@ def servername_cb(ssl_sock, server_name, initial_context): calls.append((server_name, initial_context)) - if server_name is not None: - ssl_sock.context = other_context + ssl_sock.context = other_context server_context.set_servername_callback(servername_cb) stats = server_params_test(client_context, server_context, @@ -2242,14 +2070,6 @@ # CERTFILE4 was selected self.check_common_name(stats, 'fakehostname') - calls = [] - # The callback is called with server_name=None - stats = server_params_test(client_context, server_context, - chatty=True, - sni_name=None) - self.assertEqual(calls, [(None, server_context)]) - self.check_common_name(stats, 'localhost') - # Check disabling the callback calls = [] server_context.set_servername_callback(None) @@ -2311,21 +2131,6 @@ self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR') self.assertIn("TypeError", stderr.getvalue()) - def test_read_write_after_close_raises_valuerror(self): - context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - context.verify_mode = ssl.CERT_REQUIRED - context.load_verify_locations(CERTFILE) - context.load_cert_chain(CERTFILE) - server = ThreadedEchoServer(context=context, chatty=False) - - with server: - s = context.wrap_socket(socket.socket()) - s.connect((HOST, server.port)) - s.close() - - self.assertRaises(ValueError, s.read, 1024) - self.assertRaises(ValueError, s.write, b'hello') - def test_main(verbose=False): if support.verbose: @@ -2345,11 +2150,6 @@ (ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO)) print(" under %s" % plat) print(" HAS_SNI = %r" % ssl.HAS_SNI) - print(" OP_ALL = 0x%8x" % ssl.OP_ALL) - try: - print(" OP_NO_TLSv1_1 = 0x%8x" % ssl.OP_NO_TLSv1_1) - except AttributeError: - pass for filename in [ CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, BYTES_CERTFILE, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_startfile.py --- a/Lib/test/test_startfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_startfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,7 @@ # # A possible improvement would be to have empty.vbs do something that # we can detect here, to make sure that not only the os.startfile() -# call succeeded, but also the script actually has run. +# call succeeded, but also the the script actually has run. import unittest from test import support diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_stat.py --- a/Lib/test/test_stat.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_stat.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,56 +1,14 @@ import unittest import os -from test.support import TESTFN, import_fresh_module +import stat +from test.support import TESTFN, run_unittest -c_stat = import_fresh_module('stat', fresh=['_stat']) -py_stat = import_fresh_module('stat', blocked=['_stat']) -class TestFilemode: - statmod = None +def get_mode(fname=TESTFN): + return stat.filemode(os.lstat(fname).st_mode) - file_flags = {'SF_APPEND', 'SF_ARCHIVED', 'SF_IMMUTABLE', 'SF_NOUNLINK', - 'SF_SNAPSHOT', 'UF_APPEND', 'UF_COMPRESSED', 'UF_HIDDEN', - 'UF_IMMUTABLE', 'UF_NODUMP', 'UF_NOUNLINK', 'UF_OPAQUE'} - formats = {'S_IFBLK', 'S_IFCHR', 'S_IFDIR', 'S_IFIFO', 'S_IFLNK', - 'S_IFREG', 'S_IFSOCK'} - - format_funcs = {'S_ISBLK', 'S_ISCHR', 'S_ISDIR', 'S_ISFIFO', 'S_ISLNK', - 'S_ISREG', 'S_ISSOCK'} - - stat_struct = { - 'ST_MODE': 0, - 'ST_INO': 1, - 'ST_DEV': 2, - 'ST_NLINK': 3, - 'ST_UID': 4, - 'ST_GID': 5, - 'ST_SIZE': 6, - 'ST_ATIME': 7, - 'ST_MTIME': 8, - 'ST_CTIME': 9} - - # permission bit value are defined by POSIX - permission_bits = { - 'S_ISUID': 0o4000, - 'S_ISGID': 0o2000, - 'S_ENFMT': 0o2000, - 'S_ISVTX': 0o1000, - 'S_IRWXU': 0o700, - 'S_IRUSR': 0o400, - 'S_IREAD': 0o400, - 'S_IWUSR': 0o200, - 'S_IWRITE': 0o200, - 'S_IXUSR': 0o100, - 'S_IEXEC': 0o100, - 'S_IRWXG': 0o070, - 'S_IRGRP': 0o040, - 'S_IWGRP': 0o020, - 'S_IXGRP': 0o010, - 'S_IRWXO': 0o007, - 'S_IROTH': 0o004, - 'S_IWOTH': 0o002, - 'S_IXOTH': 0o001} +class TestFilemode(unittest.TestCase): def setUp(self): try: @@ -62,78 +20,29 @@ pass tearDown = setUp - def get_mode(self, fname=TESTFN, lstat=True): - if lstat: - st_mode = os.lstat(fname).st_mode - else: - st_mode = os.stat(fname).st_mode - modestr = self.statmod.filemode(st_mode) - return st_mode, modestr - - def assertS_IS(self, name, mode): - # test format, lstrip is for S_IFIFO - fmt = getattr(self.statmod, "S_IF" + name.lstrip("F")) - self.assertEqual(self.statmod.S_IFMT(mode), fmt) - # test that just one function returns true - testname = "S_IS" + name - for funcname in self.format_funcs: - func = getattr(self.statmod, funcname, None) - if func is None: - if funcname == testname: - raise ValueError(funcname) - continue - if funcname == testname: - self.assertTrue(func(mode)) - else: - self.assertFalse(func(mode)) - def test_mode(self): with open(TESTFN, 'w'): pass if os.name == 'posix': os.chmod(TESTFN, 0o700) - st_mode, modestr = self.get_mode() - self.assertEqual(modestr, '-rwx------') - self.assertS_IS("REG", st_mode) - self.assertEqual(self.statmod.S_IMODE(st_mode), - self.statmod.S_IRWXU) - + self.assertEqual(get_mode(), '-rwx------') os.chmod(TESTFN, 0o070) - st_mode, modestr = self.get_mode() - self.assertEqual(modestr, '----rwx---') - self.assertS_IS("REG", st_mode) - self.assertEqual(self.statmod.S_IMODE(st_mode), - self.statmod.S_IRWXG) - + self.assertEqual(get_mode(), '----rwx---') os.chmod(TESTFN, 0o007) - st_mode, modestr = self.get_mode() - self.assertEqual(modestr, '-------rwx') - self.assertS_IS("REG", st_mode) - self.assertEqual(self.statmod.S_IMODE(st_mode), - self.statmod.S_IRWXO) - + self.assertEqual(get_mode(), '-------rwx') os.chmod(TESTFN, 0o444) - st_mode, modestr = self.get_mode() - self.assertS_IS("REG", st_mode) - self.assertEqual(modestr, '-r--r--r--') - self.assertEqual(self.statmod.S_IMODE(st_mode), 0o444) + self.assertEqual(get_mode(), '-r--r--r--') else: os.chmod(TESTFN, 0o700) - st_mode, modestr = self.get_mode() - self.assertEqual(modestr[:3], '-rw') - self.assertS_IS("REG", st_mode) - self.assertEqual(self.statmod.S_IFMT(st_mode), - self.statmod.S_IFREG) + self.assertEqual(get_mode()[:3], '-rw') def test_directory(self): os.mkdir(TESTFN) os.chmod(TESTFN, 0o700) - st_mode, modestr = self.get_mode() - self.assertS_IS("DIR", st_mode) if os.name == 'posix': - self.assertEqual(modestr, 'drwx------') + self.assertEqual(get_mode(), 'drwx------') else: - self.assertEqual(modestr[0], 'd') + self.assertEqual(get_mode()[0], 'd') @unittest.skipUnless(hasattr(os, 'symlink'), 'os.symlink not available') def test_link(self): @@ -142,61 +51,16 @@ except (OSError, NotImplementedError) as err: raise unittest.SkipTest(str(err)) else: - st_mode, modestr = self.get_mode() - self.assertEqual(modestr[0], 'l') - self.assertS_IS("LNK", st_mode) + self.assertEqual(get_mode()[0], 'l') @unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available') def test_fifo(self): os.mkfifo(TESTFN, 0o700) - st_mode, modestr = self.get_mode() - self.assertEqual(modestr, 'prwx------') - self.assertS_IS("FIFO", st_mode) + self.assertEqual(get_mode(), 'prwx------') - @unittest.skipUnless(os.name == 'posix', 'requires Posix') - def test_devices(self): - if os.path.exists(os.devnull): - st_mode, modestr = self.get_mode(os.devnull, lstat=False) - self.assertEqual(modestr[0], 'c') - self.assertS_IS("CHR", st_mode) - # Linux block devices, BSD has no block devices anymore - for blockdev in ("/dev/sda", "/dev/hda"): - if os.path.exists(blockdev): - st_mode, modestr = self.get_mode(blockdev, lstat=False) - self.assertEqual(modestr[0], 'b') - self.assertS_IS("BLK", st_mode) - break - def test_module_attributes(self): - for key, value in self.stat_struct.items(): - modvalue = getattr(self.statmod, key) - self.assertEqual(value, modvalue, key) - for key, value in self.permission_bits.items(): - modvalue = getattr(self.statmod, key) - self.assertEqual(value, modvalue, key) - for key in self.file_flags: - modvalue = getattr(self.statmod, key) - self.assertIsInstance(modvalue, int) - for key in self.formats: - modvalue = getattr(self.statmod, key) - self.assertIsInstance(modvalue, int) - for key in self.format_funcs: - func = getattr(self.statmod, key) - self.assertTrue(callable(func)) - self.assertEqual(func(0), 0) - - -class TestFilemodeCStat(TestFilemode, unittest.TestCase): - statmod = c_stat - - formats = TestFilemode.formats | {'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'} - format_funcs = TestFilemode.format_funcs | {'S_ISDOOR', 'S_ISPORT', - 'S_ISWHT'} - - -class TestFilemodePyStat(TestFilemode, unittest.TestCase): - statmod = py_stat - +def test_main(): + run_unittest(TestFilemode) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_strftime.py --- a/Lib/test/test_strftime.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_strftime.py Fri Feb 01 23:12:09 2013 +0100 @@ -176,6 +176,8 @@ (e[0], e[2])) print(" Expected %s, but got %s" % (e[1], result)) +def test_main(): + support.run_unittest(StrftimeTest) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_strlit.py --- a/Lib/test/test_strlit.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_strlit.py Fri Feb 01 23:12:09 2013 +0100 @@ -50,10 +50,6 @@ assert ord(f) == 0x1881 g = r'\u1881' assert list(map(ord, g)) == [92, 117, 49, 56, 56, 49] -h = '\U0001d120' -assert ord(h) == 0x1d120 -i = r'\U0001d120' -assert list(map(ord, i)) == [92, 85, 48, 48, 48, 49, 100, 49, 50, 48] """ @@ -86,24 +82,6 @@ self.assertEqual(eval(""" '\x81' """), chr(0x81)) self.assertEqual(eval(r""" '\u1881' """), chr(0x1881)) self.assertEqual(eval(""" '\u1881' """), chr(0x1881)) - self.assertEqual(eval(r""" '\U0001d120' """), chr(0x1d120)) - self.assertEqual(eval(""" '\U0001d120' """), chr(0x1d120)) - - def test_eval_str_incomplete(self): - self.assertRaises(SyntaxError, eval, r""" '\x' """) - self.assertRaises(SyntaxError, eval, r""" '\x0' """) - self.assertRaises(SyntaxError, eval, r""" '\u' """) - self.assertRaises(SyntaxError, eval, r""" '\u0' """) - self.assertRaises(SyntaxError, eval, r""" '\u00' """) - self.assertRaises(SyntaxError, eval, r""" '\u000' """) - self.assertRaises(SyntaxError, eval, r""" '\U' """) - self.assertRaises(SyntaxError, eval, r""" '\U0' """) - self.assertRaises(SyntaxError, eval, r""" '\U00' """) - self.assertRaises(SyntaxError, eval, r""" '\U000' """) - self.assertRaises(SyntaxError, eval, r""" '\U0000' """) - self.assertRaises(SyntaxError, eval, r""" '\U00000' """) - self.assertRaises(SyntaxError, eval, r""" '\U000000' """) - self.assertRaises(SyntaxError, eval, r""" '\U0000000' """) def test_eval_str_raw(self): self.assertEqual(eval(""" r'x' """), 'x') @@ -113,8 +91,6 @@ self.assertEqual(eval(""" r'\x81' """), chr(0x81)) self.assertEqual(eval(r""" r'\u1881' """), '\\' + 'u1881') self.assertEqual(eval(""" r'\u1881' """), chr(0x1881)) - self.assertEqual(eval(r""" r'\U0001d120' """), '\\' + 'U0001d120') - self.assertEqual(eval(""" r'\U0001d120' """), chr(0x1d120)) def test_eval_bytes_normal(self): self.assertEqual(eval(""" b'x' """), b'x') @@ -124,12 +100,6 @@ self.assertRaises(SyntaxError, eval, """ b'\x81' """) self.assertEqual(eval(r""" b'\u1881' """), b'\\' + b'u1881') self.assertRaises(SyntaxError, eval, """ b'\u1881' """) - self.assertEqual(eval(r""" b'\U0001d120' """), b'\\' + b'U0001d120') - self.assertRaises(SyntaxError, eval, """ b'\U0001d120' """) - - def test_eval_bytes_incomplete(self): - self.assertRaises(SyntaxError, eval, r""" b'\x' """) - self.assertRaises(SyntaxError, eval, r""" b'\x0' """) def test_eval_bytes_raw(self): self.assertEqual(eval(""" br'x' """), b'x') @@ -146,10 +116,6 @@ self.assertEqual(eval(r""" rb'\u1881' """), b"\\" + b"u1881") self.assertRaises(SyntaxError, eval, """ br'\u1881' """) self.assertRaises(SyntaxError, eval, """ rb'\u1881' """) - self.assertEqual(eval(r""" br'\U0001d120' """), b"\\" + b"U0001d120") - self.assertEqual(eval(r""" rb'\U0001d120' """), b"\\" + b"U0001d120") - self.assertRaises(SyntaxError, eval, """ br'\U0001d120' """) - self.assertRaises(SyntaxError, eval, """ rb'\U0001d120' """) self.assertRaises(SyntaxError, eval, """ bb'' """) self.assertRaises(SyntaxError, eval, """ rr'' """) self.assertRaises(SyntaxError, eval, """ brr'' """) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_strptime.py --- a/Lib/test/test_strptime.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_strptime.py Fri Feb 01 23:12:09 2013 +0100 @@ -218,12 +218,6 @@ else: self.fail("'%s' did not raise ValueError" % bad_format) - def test_strptime_exception_context(self): - # check that this doesn't chain exceptions needlessly (see #17572) - with self.assertRaises(ValueError) as e: - _strptime._strptime_time('', '%D') - self.assertIs(e.exception.__suppress_context__, True) - def test_unconverteddata(self): # Check ValueError is raised when there is unconverted data self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_struct.py --- a/Lib/test/test_struct.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_struct.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,4 @@ -from collections import abc import array -import operator import unittest import struct import sys @@ -8,6 +6,7 @@ from test import support ISBIGENDIAN = sys.byteorder == "big" +IS32BIT = sys.maxsize == 0x7fffffff integer_codes = 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'n', 'N' byteorders = '', '@', '=', '<', '>', '!' @@ -537,6 +536,10 @@ hugecount2 = '{}b{}H'.format(sys.maxsize//2, sys.maxsize//2) self.assertRaises(struct.error, struct.calcsize, hugecount2) + if IS32BIT: + def test_crasher(self): + self.assertRaises(MemoryError, struct.pack, "357913941b", "a") + def test_trailing_counter(self): store = array.array('b', b' '*100) @@ -573,7 +576,7 @@ # The size of 'PyStructObject' totalsize = support.calcobjsize('2n3P') # The size taken up by the 'formatcode' dynamic array - totalsize += struct.calcsize('P3n0P') * (number_of_codes + 1) + totalsize += struct.calcsize('P2n0P') * (number_of_codes + 1) support.check_sizeof(self, struct.Struct(format_str), totalsize) @support.cpython_only @@ -584,84 +587,14 @@ self.check_sizeof('B' * 1234, 1234) self.check_sizeof('fd', 2) self.check_sizeof('xxxxxxxxxxxxxx', 0) - self.check_sizeof('100H', 1) + self.check_sizeof('100H', 100) self.check_sizeof('187s', 1) self.check_sizeof('20p', 1) self.check_sizeof('0s', 1) self.check_sizeof('0c', 0) - -class UnpackIteratorTest(unittest.TestCase): - """ - Tests for iterative unpacking (struct.Struct.iter_unpack). - """ - - def test_construct(self): - def _check_iterator(it): - self.assertIsInstance(it, abc.Iterator) - self.assertIsInstance(it, abc.Iterable) - s = struct.Struct('>ibcp') - it = s.iter_unpack(b"") - _check_iterator(it) - it = s.iter_unpack(b"1234567") - _check_iterator(it) - # Wrong bytes length - with self.assertRaises(struct.error): - s.iter_unpack(b"123456") - with self.assertRaises(struct.error): - s.iter_unpack(b"12345678") - # Zero-length struct - s = struct.Struct('>') - with self.assertRaises(struct.error): - s.iter_unpack(b"") - with self.assertRaises(struct.error): - s.iter_unpack(b"12") - - def test_iterate(self): - s = struct.Struct('>IB') - b = bytes(range(1, 16)) - it = s.iter_unpack(b) - self.assertEqual(next(it), (0x01020304, 5)) - self.assertEqual(next(it), (0x06070809, 10)) - self.assertEqual(next(it), (0x0b0c0d0e, 15)) - self.assertRaises(StopIteration, next, it) - self.assertRaises(StopIteration, next, it) - - def test_arbitrary_buffer(self): - s = struct.Struct('>IB') - b = bytes(range(1, 11)) - it = s.iter_unpack(memoryview(b)) - self.assertEqual(next(it), (0x01020304, 5)) - self.assertEqual(next(it), (0x06070809, 10)) - self.assertRaises(StopIteration, next, it) - self.assertRaises(StopIteration, next, it) - - def test_length_hint(self): - lh = operator.length_hint - s = struct.Struct('>IB') - b = bytes(range(1, 16)) - it = s.iter_unpack(b) - self.assertEqual(lh(it), 3) - next(it) - self.assertEqual(lh(it), 2) - next(it) - self.assertEqual(lh(it), 1) - next(it) - self.assertEqual(lh(it), 0) - self.assertRaises(StopIteration, next, it) - self.assertEqual(lh(it), 0) - - def test_module_func(self): - # Sanity check for the global struct.iter_unpack() - it = struct.iter_unpack('>IB', bytes(range(1, 11))) - self.assertEqual(next(it), (0x01020304, 5)) - self.assertEqual(next(it), (0x06070809, 10)) - self.assertRaises(StopIteration, next, it) - self.assertRaises(StopIteration, next, it) - - def test_main(): - support.run_unittest(__name__) + support.run_unittest(StructTest) if __name__ == '__main__': test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_subprocess.py Fri Feb 01 23:12:09 2013 +0100 @@ -82,34 +82,6 @@ class ProcessTestCase(BaseTestCase): - def test_io_buffered_by_default(self): - p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - try: - self.assertIsInstance(p.stdin, io.BufferedIOBase) - self.assertIsInstance(p.stdout, io.BufferedIOBase) - self.assertIsInstance(p.stderr, io.BufferedIOBase) - finally: - p.stdin.close() - p.stdout.close() - p.stderr.close() - p.wait() - - def test_io_unbuffered_works(self): - p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, bufsize=0) - try: - self.assertIsInstance(p.stdin, io.RawIOBase) - self.assertIsInstance(p.stdout, io.RawIOBase) - self.assertIsInstance(p.stderr, io.RawIOBase) - finally: - p.stdin.close() - p.stdout.close() - p.stderr.close() - p.wait() - def test_call_seq(self): # call() function with sequence argument rc = subprocess.call([sys.executable, "-c", @@ -158,28 +130,8 @@ stderr=subprocess.STDOUT) self.assertIn(b'BDFL', output) - def test_check_output_stdin_arg(self): - # check_output() can be called with stdin set to a file - tf = tempfile.TemporaryFile() - self.addCleanup(tf.close) - tf.write(b'pear') - tf.seek(0) - output = subprocess.check_output( - [sys.executable, "-c", - "import sys; sys.stdout.write(sys.stdin.read().upper())"], - stdin=tf) - self.assertIn(b'PEAR', output) - - def test_check_output_input_arg(self): - # check_output() can be called with input set to a string - output = subprocess.check_output( - [sys.executable, "-c", - "import sys; sys.stdout.write(sys.stdin.read().upper())"], - input=b'pear') - self.assertIn(b'PEAR', output) - def test_check_output_stdout_arg(self): - # check_output() refuses to accept 'stdout' argument + # check_output() function stderr redirected to stdout with self.assertRaises(ValueError) as c: output = subprocess.check_output( [sys.executable, "-c", "print('will not be run')"], @@ -187,20 +139,6 @@ self.fail("Expected ValueError when stdout arg supplied.") self.assertIn('stdout', c.exception.args[0]) - def test_check_output_stdin_with_input_arg(self): - # check_output() refuses to accept 'stdin' with 'input' - tf = tempfile.TemporaryFile() - self.addCleanup(tf.close) - tf.write(b'pear') - tf.seek(0) - with self.assertRaises(ValueError) as c: - output = subprocess.check_output( - [sys.executable, "-c", "print('will not be run')"], - stdin=tf, input=b'hare') - self.fail("Expected ValueError when stdin and input args supplied.") - self.assertIn('stdin', c.exception.args[0]) - self.assertIn('input', c.exception.args[0]) - def test_check_output_timeout(self): # check_output() function with timeout arg with self.assertRaises(subprocess.TimeoutExpired) as c: @@ -246,27 +184,16 @@ self.assertEqual(p.stdin, None) def test_stdout_none(self): - # .stdout is None when not redirected, and the child's stdout will - # be inherited from the parent. In order to test this we run a - # subprocess in a subprocess: - # this_test - # \-- subprocess created by this test (parent) - # \-- subprocess created by the parent subprocess (child) - # The parent doesn't specify stdout, so the child will use the - # parent's stdout. This test checks that the message printed by the - # child goes to the parent stdout. The parent also checks that the - # child's stdout is None. See #11963. - code = ('import sys; from subprocess import Popen, PIPE;' - 'p = Popen([sys.executable, "-c", "print(\'test_stdout_none\')"],' - ' stdin=PIPE, stderr=PIPE);' - 'p.wait(); assert p.stdout is None;') - p = subprocess.Popen([sys.executable, "-c", code], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - self.addCleanup(p.stdout.close) + # .stdout is None when not redirected + p = subprocess.Popen([sys.executable, "-c", + 'print(" this bit of output is from a ' + 'test of stdout in a different ' + 'process ...")'], + stdin=subprocess.PIPE, stderr=subprocess.PIPE) + self.addCleanup(p.stdin.close) self.addCleanup(p.stderr.close) - out, err = p.communicate() - self.assertEqual(p.returncode, 0, err) - self.assertEqual(out.rstrip(), b'test_stdout_none') + p.wait() + self.assertEqual(p.stdout, None) def test_stderr_none(self): # .stderr is None when not redirected @@ -544,22 +471,9 @@ def test_stdout_filedes_of_stdout(self): # stdout is set to 1 (#1531862). - # To avoid printing the text on stdout, we do something similar to - # test_stdout_none (see above). The parent subprocess calls the child - # subprocess passing stdout=1, and this test uses stdout=PIPE in - # order to capture and check the output of the parent. See #11963. - code = ('import sys, subprocess; ' - 'rc = subprocess.call([sys.executable, "-c", ' - ' "import os, sys; sys.exit(os.write(sys.stdout.fileno(), ' - 'b\'test with stdout=1\'))"], stdout=1); ' - 'assert rc == 18') - p = subprocess.Popen([sys.executable, "-c", code], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - self.addCleanup(p.stdout.close) - self.addCleanup(p.stderr.close) - out, err = p.communicate() - self.assertEqual(p.returncode, 0, err) - self.assertEqual(out.rstrip(), b'test with stdout=1') + cmd = r"import sys, os; sys.exit(os.write(sys.stdout.fileno(), b'.\n'))" + rc = subprocess.call([sys.executable, "-c", cmd], stdout=1) + self.assertEqual(rc, 2) def test_stdout_devnull(self): p = subprocess.Popen([sys.executable, "-c", @@ -982,10 +896,10 @@ def test_wait_timeout(self): p = subprocess.Popen([sys.executable, - "-c", "import time; time.sleep(0.3)"]) + "-c", "import time; time.sleep(0.1)"]) with self.assertRaises(subprocess.TimeoutExpired) as c: - p.wait(timeout=0.0001) - self.assertIn("0.0001", str(c.exception)) # For coverage of __str__. + p.wait(timeout=0.01) + self.assertIn("0.01", str(c.exception)) # For coverage of __str__. # Some heavily loaded buildbots (sparc Debian 3.x) require this much # time to start. self.assertEqual(p.wait(timeout=3), 0) @@ -1296,8 +1210,7 @@ self.stderr.fileno()), msg="At least one fd was closed early.") finally: - for fd in devzero_fds: - os.close(fd) + map(os.close, devzero_fds) @unittest.skipIf(not os.path.exists("/dev/zero"), "/dev/zero required.") def test_preexec_errpipe_does_not_double_close_pipes(self): @@ -1525,7 +1438,7 @@ self.assertEqual((out, err), (b'apple', b'orange')) finally: for b, a in zip(newfds, fds): - os.dup2(b, a) + os.dup2(b, a, cloexec=False) for b in newfds: os.close(b) @@ -1585,7 +1498,7 @@ finally: # restore the original fd's underneath sys.stdin, etc. for std, saved in enumerate(saved_fds): - os.dup2(saved, std) + os.dup2(saved, std, cloexec=False) os.close(saved) for fd in temp_fds: @@ -1637,7 +1550,7 @@ err = support.strip_python_stderr(os.read(stderr_no, 1024)) finally: for std, saved in enumerate(saved_fds): - os.dup2(saved, std) + os.dup2(saved, std, cloexec=False) os.close(saved) self.assertEqual(out, b"got STDIN") @@ -1798,14 +1711,14 @@ def test_close_fds(self): fd_status = support.findfile("fd_status.py", subdir="subprocessdata") - fds = os.pipe() + fds = os.pipe(cloexec=False) self.addCleanup(os.close, fds[0]) self.addCleanup(os.close, fds[1]) open_fds = set(fds) # add a bunch more fds for _ in range(9): - fd = os.open("/dev/null", os.O_RDONLY) + fd = os.open("/dev/null", os.O_RDONLY, cloexec=False) self.addCleanup(os.close, fd) open_fds.add(fd) @@ -1847,33 +1760,34 @@ def test_pass_fds(self): fd_status = support.findfile("fd_status.py", subdir="subprocessdata") - open_fds = set() + for cloexec in (False, True): + open_fds = set() - for x in range(5): - fds = os.pipe() - self.addCleanup(os.close, fds[0]) - self.addCleanup(os.close, fds[1]) - open_fds.update(fds) + for x in range(5): + fds = os.pipe(cloexec=cloexec) + self.addCleanup(os.close, fds[0]) + self.addCleanup(os.close, fds[1]) + open_fds.update(fds) - for fd in open_fds: - p = subprocess.Popen([sys.executable, fd_status], - stdout=subprocess.PIPE, close_fds=True, - pass_fds=(fd, )) - output, ignored = p.communicate() + for fd in open_fds: + p = subprocess.Popen([sys.executable, fd_status], + stdout=subprocess.PIPE, close_fds=True, + pass_fds=(fd, )) + output, ignored = p.communicate() - remaining_fds = set(map(int, output.split(b','))) - to_be_closed = open_fds - {fd} + remaining_fds = set(map(int, output.split(b','))) + to_be_closed = open_fds - {fd} - self.assertIn(fd, remaining_fds, "fd to be passed not passed") - self.assertFalse(remaining_fds & to_be_closed, - "fd to be closed passed") + self.assertIn(fd, remaining_fds, "fd to be passed not passed") + self.assertFalse(remaining_fds & to_be_closed, + "fd to be closed passed") - # pass_fds overrides close_fds with a warning. - with self.assertWarns(RuntimeWarning) as context: - self.assertFalse(subprocess.call( - [sys.executable, "-c", "import sys; sys.exit(0)"], - close_fds=False, pass_fds=(fd, ))) - self.assertIn('overriding close_fds', str(context.warning)) + # pass_fds overrides close_fds with a warning. + with self.assertWarns(RuntimeWarning) as context: + self.assertFalse(subprocess.call( + [sys.executable, "-c", "import sys; sys.exit(0)"], + close_fds=False, pass_fds=(fd, ))) + self.assertIn('overriding close_fds', str(context.warning)) def test_stdout_stdin_are_single_inout_fd(self): with io.open(os.devnull, "r+") as inout: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sundry.py --- a/Lib/test/test_sundry.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sundry.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,8 +6,8 @@ class TestUntestedModules(unittest.TestCase): def test_untested_modules_can_be_imported(self): - untested = ('bdb', 'encodings', 'formatter', 'imghdr', - 'macurl2path', 'nturl2path', 'tabnanny') + untested = ('bdb', 'encodings', 'formatter', 'getpass', 'imghdr', + 'keyword', 'macurl2path', 'nturl2path', 'tabnanny') with support.check_warnings(quiet=True): for name in untested: try: @@ -54,5 +54,8 @@ print("skipping tty") +def test_main(): + support.run_unittest(TestUntestedModules) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_super.py --- a/Lib/test/test_super.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_super.py Fri Feb 01 23:12:09 2013 +0100 @@ -44,11 +44,6 @@ class TestSuper(unittest.TestCase): - def tearDown(self): - # This fixes the damage that test_various___class___pathologies does. - nonlocal __class__ - __class__ = TestSuper - def test_basics_working(self): self.assertEqual(D().f(), 'ABCD') @@ -86,7 +81,8 @@ self.assertEqual(E().f(), 'AE') - def test_various___class___pathologies(self): + @unittest.expectedFailure + def test___class___set(self): # See issue #12370 class X(A): def f(self): @@ -95,31 +91,6 @@ x = X() self.assertEqual(x.f(), 'A') self.assertEqual(x.__class__, 413) - class X: - x = __class__ - def f(): - __class__ - self.assertIs(X.x, type(self)) - with self.assertRaises(NameError) as e: - exec("""class X: - __class__ - def f(): - __class__""", globals(), {}) - self.assertIs(type(e.exception), NameError) # Not UnboundLocalError - class X: - global __class__ - __class__ = 42 - def f(): - __class__ - self.assertEqual(globals()["__class__"], 42) - del globals()["__class__"] - self.assertNotIn("__class__", X.__dict__) - class X: - nonlocal __class__ - __class__ = 42 - def f(): - __class__ - self.assertEqual(__class__, 42) def test___class___instancemethod(self): # See issue #14857 @@ -159,19 +130,6 @@ super() self.assertRaises(RuntimeError, X().f) - def test_cell_as_self(self): - class X: - def meth(self): - super() - - def f(): - k = X() - def g(): - return k - return g - c = f().__closure__[0] - self.assertRaises(TypeError, X.meth, c) - def test_main(): support.run_unittest(TestSuper) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_support.py --- a/Lib/test/test_support.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_support.py Fri Feb 01 23:12:09 2013 +0100 @@ -130,22 +130,19 @@ self.assertNotIn("bar", sys.path) def test_captured_stdout(self): - with support.captured_stdout() as stdout: + with support.captured_stdout() as s: print("hello") - self.assertEqual(stdout.getvalue(), "hello\n") + self.assertEqual(s.getvalue(), "hello\n") def test_captured_stderr(self): - with support.captured_stderr() as stderr: + with support.captured_stderr() as s: print("hello", file=sys.stderr) - self.assertEqual(stderr.getvalue(), "hello\n") + self.assertEqual(s.getvalue(), "hello\n") def test_captured_stdin(self): - with support.captured_stdin() as stdin: - stdin.write('hello\n') - stdin.seek(0) - # call test code that consumes from sys.stdin - captured = input() - self.assertEqual(captured, "hello") + with support.captured_stdin() as s: + print("hello", file=sys.stdin) + self.assertEqual(s.getvalue(), "hello\n") def test_gc_collect(self): support.gc_collect() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sys.py --- a/Lib/test/test_sys.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sys.py Fri Feb 01 23:12:09 2013 +0100 @@ -8,6 +8,7 @@ import codecs import gc import sysconfig +from test.script_helper import assert_python_ok # count the number of test runs, used to create unique # strings to intern in test_intern() @@ -239,6 +240,9 @@ def test_recursionlimit_fatalerror(self): # A fatal error occurs if a second recursion limit is hit when recovering # from a first one. + if os.name == "nt": + raise unittest.SkipTest( + "under Windows, test would generate a spurious crash dialog") code = textwrap.dedent(""" import sys @@ -250,15 +254,14 @@ sys.setrecursionlimit(%d) f()""") - with test.support.suppress_crash_popup(): - for i in (50, 1000): - sub = subprocess.Popen([sys.executable, '-c', code % i], - stderr=subprocess.PIPE) - err = sub.communicate()[1] - self.assertTrue(sub.returncode, sub.returncode) - self.assertIn( - b"Fatal Python error: Cannot recover from stack overflow", - err) + for i in (50, 1000): + sub = subprocess.Popen([sys.executable, '-c', code % i], + stderr=subprocess.PIPE) + err = sub.communicate()[1] + self.assertTrue(sub.returncode, sub.returncode) + self.assertTrue( + b"Fatal Python error: Cannot recover from stack overflow" in err, + err) def test_getwindowsversion(self): # Raise SkipTest if sys doesn't have getwindowsversion attribute @@ -606,7 +609,6 @@ def test_debugmallocstats(self): # Test sys._debugmallocstats() - from test.script_helper import assert_python_ok args = ['-c', 'import sys; sys._debugmallocstats()'] ret, out, err = assert_python_ok(*args) self.assertIn(b"free PyDictObjects", err) @@ -640,6 +642,35 @@ c = sys.getallocatedblocks() self.assertIn(c, range(b - 50, b + 50)) + def test_getdefaultcloexec_cmdline(self): + code = 'import sys; print(sys.getdefaultcloexec())' + + ok, stdout, stderr = assert_python_ok('-c', code) + self.assertEqual(stdout.rstrip(), b'False') + + ok, stdout, stderr = assert_python_ok('-c', code, PYTHONCLOEXEC='1') + self.assertEqual(stdout.rstrip(), b'True') + + ok, stdout, stderr = assert_python_ok('-E', '-c', code, PYTHONCLOEXEC='1') + self.assertEqual(stdout.rstrip(), b'False') + + ok, stdout, stderr = assert_python_ok('-e', '-c', code) + self.assertEqual(stdout.rstrip(), b'True') + + def test_setdefaultcloexec(self): + self.assertRaises(TypeError, sys.setdefaultcloexec) + self.assertRaises(TypeError, sys.setdefaultcloexec, 1, 2) + + old_cloexec = sys.getdefaultcloexec() + try: + sys.setdefaultcloexec(True) + self.assertEqual(sys.getdefaultcloexec(), True) + + sys.setdefaultcloexec(False) + self.assertEqual(sys.getdefaultcloexec(), False) + finally: + sys.setdefaultcloexec(old_cloexec) + class SizeofTest(unittest.TestCase): @@ -735,13 +766,13 @@ class C(object): pass check(C.__dict__, size('P')) # BaseException - check(BaseException(), size('5Pb')) + check(BaseException(), size('5Pi')) # UnicodeEncodeError - check(UnicodeEncodeError("", "", 0, 0, ""), size('5Pb 2P2nP')) + check(UnicodeEncodeError("", "", 0, 0, ""), size('5Pi 2P2nP')) # UnicodeDecodeError - check(UnicodeDecodeError("", b"", 0, 0, ""), size('5Pb 2P2nP')) + check(UnicodeDecodeError("", b"", 0, 0, ""), size('5Pi 2P2nP')) # UnicodeTranslateError - check(UnicodeTranslateError("", 0, 1, ""), size('5Pb 2P2nP')) + check(UnicodeTranslateError("", 0, 1, ""), size('5Pi 2P2nP')) # ellipses check(Ellipsis, size('')) # EncodingMap @@ -883,7 +914,7 @@ samples = ['1'*100, '\xff'*50, '\u0100'*40, '\uffff'*100, '\U00010000'*30, '\U0010ffff'*100] - asciifields = "nnbP" + asciifields = "nniP" compactfields = asciifields + "nPn" unicodefields = compactfields + "P" for s in samples: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_sys_settrace.py --- a/Lib/test/test_sys_settrace.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_sys_settrace.py Fri Feb 01 23:12:09 2013 +0100 @@ -458,29 +458,6 @@ self.fail("exception not propagated") - def test_exception_arguments(self): - def f(): - x = 0 - # this should raise an error - x.no_such_attr - def g(frame, event, arg): - if (event == 'exception'): - type, exception, trace = arg - self.assertIsInstance(exception, Exception) - return g - - existing = sys.gettrace() - try: - sys.settrace(g) - try: - f() - except AttributeError: - # this is expected - pass - finally: - sys.settrace(existing) - - # 'Jump' tests: assigning to frame.f_lineno within a trace function # moves the execution position - it's how debuggers implement a Jump # command (aka. "Set next statement"). diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_tarfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,7 +2,9 @@ import os import io import shutil +import io from hashlib import md5 +import errno import unittest import tarfile @@ -12,7 +14,8 @@ # Check for our compression modules. try: import gzip -except ImportError: + gzip.GzipFile +except (ImportError, AttributeError): gzip = None try: import bz2 @@ -37,55 +40,25 @@ md5_sparse = "a54fbc4ca4f4399a90e1b27164012fc6" -class TarTest: +class ReadTest(unittest.TestCase): + tarname = tarname - suffix = '' - open = io.FileIO - - @property - def mode(self): - return self.prefix + self.suffix - -@support.requires_gzip -class GzipTest: - tarname = gzipname - suffix = 'gz' - open = gzip.GzipFile if gzip else None - -@support.requires_bz2 -class Bz2Test: - tarname = bz2name - suffix = 'bz2' - open = bz2.BZ2File if bz2 else None - -@support.requires_lzma -class LzmaTest: - tarname = xzname - suffix = 'xz' - open = lzma.LZMAFile if lzma else None - - -class ReadTest(TarTest): - - prefix = "r:" + mode = "r:" def setUp(self): - self.tar = tarfile.open(self.tarname, mode=self.mode, - encoding="iso8859-1") + self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1") def tearDown(self): self.tar.close() -class UstarReadTest(ReadTest, unittest.TestCase): +class UstarReadTest(ReadTest): def test_fileobj_regular_file(self): tarinfo = self.tar.getmember("ustar/regtype") with self.tar.extractfile(tarinfo) as fobj: data = fobj.read() - self.assertEqual(len(data), tarinfo.size, - "regular file extraction failed") - self.assertEqual(md5sum(data), md5_regtype, + self.assertTrue((len(data), md5sum(data)) == (tarinfo.size, md5_regtype), "regular file extraction failed") def test_fileobj_readlines(self): @@ -97,13 +70,12 @@ with self.tar.extractfile(tarinfo) as fobj: fobj2 = io.TextIOWrapper(fobj) lines2 = fobj2.readlines() - self.assertEqual(lines1, lines2, + self.assertTrue(lines1 == lines2, "fileobj.readlines() failed") - self.assertEqual(len(lines2), 114, + self.assertTrue(len(lines2) == 114, "fileobj.readlines() failed") - self.assertEqual(lines2[83], - "I will gladly admit that Python is not the fastest " - "running scripting language.\n", + self.assertTrue(lines2[83] == + "I will gladly admit that Python is not the fastest running scripting language.\n", "fileobj.readlines() failed") def test_fileobj_iter(self): @@ -113,8 +85,8 @@ lines1 = fobj1.readlines() with self.tar.extractfile(tarinfo) as fobj2: lines2 = list(io.TextIOWrapper(fobj2)) - self.assertEqual(lines1, lines2, - "fileobj.__iter__() failed") + self.assertTrue(lines1 == lines2, + "fileobj.__iter__() failed") def test_fileobj_seek(self): self.tar.extract("ustar/regtype", TEMPDIR) @@ -138,12 +110,12 @@ self.assertEqual(2048, fobj.tell(), "seek() to positive relative position failed") s = fobj.read(10) - self.assertEqual(s, data[2048:2058], + self.assertTrue(s == data[2048:2058], "read() after seek failed") fobj.seek(0, 2) self.assertEqual(tarinfo.size, fobj.tell(), "seek() to file's end failed") - self.assertEqual(fobj.read(), b"", + self.assertTrue(fobj.read() == b"", "read() at file's end did not return empty string") fobj.seek(-tarinfo.size, 2) self.assertEqual(0, fobj.tell(), @@ -152,13 +124,13 @@ s1 = fobj.readlines() fobj.seek(512) s2 = fobj.readlines() - self.assertEqual(s1, s2, + self.assertTrue(s1 == s2, "readlines() after seek failed") fobj.seek(0) self.assertEqual(len(fobj.readline()), fobj.tell(), "tell() after readline() failed") fobj.seek(512) - self.assertEqual(len(fobj.readline()) + 512, fobj.tell(), + self.assertTrue(len(fobj.readline()) + 512 == fobj.tell(), "tell() after seek() and readline() failed") fobj.seek(0) line = fobj.readline() @@ -182,36 +154,24 @@ # test link members each point to a regular member whose data is # supposed to be exported. def _test_fileobj_link(self, lnktype, regtype): - with self.tar.extractfile(lnktype) as a, \ - self.tar.extractfile(regtype) as b: + with self.tar.extractfile(lnktype) as a, self.tar.extractfile(regtype) as b: self.assertEqual(a.name, b.name) def test_fileobj_link1(self): self._test_fileobj_link("ustar/lnktype", "ustar/regtype") def test_fileobj_link2(self): - self._test_fileobj_link("./ustar/linktest2/lnktype", - "ustar/linktest1/regtype") + self._test_fileobj_link("./ustar/linktest2/lnktype", "ustar/linktest1/regtype") def test_fileobj_symlink1(self): self._test_fileobj_link("ustar/symtype", "ustar/regtype") def test_fileobj_symlink2(self): - self._test_fileobj_link("./ustar/linktest2/symtype", - "ustar/linktest1/regtype") + self._test_fileobj_link("./ustar/linktest2/symtype", "ustar/linktest1/regtype") def test_issue14160(self): self._test_fileobj_link("symtype2", "ustar/regtype") -class GzipUstarReadTest(GzipTest, UstarReadTest): - pass - -class Bz2UstarReadTest(Bz2Test, UstarReadTest): - pass - -class LzmaUstarReadTest(LzmaTest, UstarReadTest): - pass - class CommonReadTest(ReadTest): @@ -243,24 +203,37 @@ def test_ignore_zeros(self): # Test TarFile's ignore_zeros option. + if self.mode.endswith(":gz"): + _open = gzip.GzipFile + elif self.mode.endswith(":bz2"): + _open = bz2.BZ2File + elif self.mode.endswith(":xz"): + _open = lzma.LZMAFile + else: + _open = io.FileIO + for char in (b'\0', b'a'): # Test if EOFHeaderError ('\0') and InvalidHeaderError ('a') # are ignored correctly. - with self.open(tmpname, "w") as fobj: + with _open(tmpname, "w") as fobj: fobj.write(char * 1024) fobj.write(tarfile.TarInfo("foo").tobuf()) tar = tarfile.open(tmpname, mode="r", ignore_zeros=True) try: self.assertListEqual(tar.getnames(), ["foo"], - "ignore_zeros=True should have skipped the %r-blocks" % - char) + "ignore_zeros=True should have skipped the %r-blocks" % char) finally: tar.close() -class MiscReadTestBase(CommonReadTest): +class MiscReadTest(CommonReadTest): + def test_no_name_argument(self): + if self.mode.endswith(("bz2", "xz")): + # BZ2File and LZMAFile have no name attribute. + self.skipTest("no name attribute") + with open(self.tarname, "rb") as fobj: tar = tarfile.open(fileobj=fobj, mode=self.mode) self.assertEqual(tar.name, os.path.abspath(fobj.name)) @@ -296,7 +269,16 @@ tar.close() # Open the testtar and seek to the offset of the second member. - with self.open(self.tarname) as fobj: + if self.mode.endswith(":gz"): + _open = gzip.GzipFile + elif self.mode.endswith(":bz2"): + _open = bz2.BZ2File + elif self.mode.endswith(":xz"): + _open = lzma.LZMAFile + else: + _open = io.FileIO + + with _open(self.tarname) as fobj: fobj.seek(offset) # Test if the tarfile starts with the second member. @@ -312,6 +294,8 @@ def test_fail_comp(self): # For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file. + if self.mode == "r:": + return self.assertRaises(tarfile.ReadError, tarfile.open, tarname, self.mode) with open(tarname, "rb") as fobj: self.assertRaises(tarfile.ReadError, tarfile.open, @@ -322,7 +306,7 @@ # Old V7 tars create directory members using an AREGTYPE # header with a "/" appended to the filename field. tarinfo = self.tar.getmember("misc/dirtype-old-v7") - self.assertEqual(tarinfo.type, tarfile.DIRTYPE, + self.assertTrue(tarinfo.type == tarfile.DIRTYPE, "v7 dirtype failed") def test_xstar_type(self): @@ -336,15 +320,15 @@ def test_check_members(self): for tarinfo in self.tar: - self.assertEqual(int(tarinfo.mtime), 0o7606136617, + self.assertTrue(int(tarinfo.mtime) == 0o7606136617, "wrong mtime for %s" % tarinfo.name) if not tarinfo.name.startswith("ustar/"): continue - self.assertEqual(tarinfo.uname, "tarfile", + self.assertTrue(tarinfo.uname == "tarfile", "wrong uname for %s" % tarinfo.name) def test_find_members(self): - self.assertEqual(self.tar.getmembers()[-1].name, "misc/eof", + self.assertTrue(self.tar.getmembers()[-1].name == "misc/eof", "could not find all members") @unittest.skipUnless(hasattr(os, "link"), @@ -381,8 +365,7 @@ path = os.path.join(DIR, tarinfo.name) if sys.platform != "win32": # Win32 has no support for fine grained permissions. - self.assertEqual(tarinfo.mode & 0o777, - os.stat(path).st_mode & 0o777) + self.assertEqual(tarinfo.mode & 0o777, os.stat(path).st_mode & 0o777) def format_mtime(mtime): if isinstance(mtime, float): return "{} ({})".format(mtime, mtime.hex()) @@ -432,36 +415,10 @@ finally: support.unlink(empty) - def test_parallel_iteration(self): - # Issue #16601: Restarting iteration over tarfile continued - # from where it left off. - with tarfile.open(self.tarname) as tar: - for m1, m2 in zip(tar, tar): - self.assertEqual(m1.offset, m2.offset) - self.assertEqual(m1.get_info(), m2.get_info()) -class MiscReadTest(MiscReadTestBase, unittest.TestCase): - test_fail_comp = None +class StreamReadTest(CommonReadTest): -class GzipMiscReadTest(GzipTest, MiscReadTestBase, unittest.TestCase): - def test_non_existent_targz_file(self): - # Test for issue11513: prevent non-existent gzipped tarfiles raising - # multiple exceptions. - with self.assertRaisesRegex(FileNotFoundError, "xxx"): - tarfile.open("xxx", self.mode) - -class Bz2MiscReadTest(Bz2Test, MiscReadTestBase, unittest.TestCase): - def test_no_name_argument(self): - self.skipTest("BZ2File have no name attribute") - -class LzmaMiscReadTest(LzmaTest, MiscReadTestBase, unittest.TestCase): - def test_no_name_argument(self): - self.skipTest("LZMAFile have no name attribute") - - -class StreamReadTest(CommonReadTest, unittest.TestCase): - - prefix="r|" + mode="r|" def test_read_through(self): # Issue #11224: A poorly designed _FileInFile.read() method @@ -474,8 +431,7 @@ try: buf = fobj.read(512) except tarfile.StreamError: - self.fail("simple read-through using " - "TarFile.extractfile() failed") + self.fail("simple read-through using TarFile.extractfile() failed") if not buf: break @@ -483,9 +439,7 @@ tarinfo = self.tar.next() # get "regtype" (can't use getmember) with self.tar.extractfile(tarinfo) as fobj: data = fobj.read() - self.assertEqual(len(data), tarinfo.size, - "regular file extraction failed") - self.assertEqual(md5sum(data), md5_regtype, + self.assertTrue((len(data), md5sum(data)) == (tarinfo.size, md5_regtype), "regular file extraction failed") def test_provoke_stream_error(self): @@ -503,34 +457,24 @@ t2 = tar2.next() if t1 is None: break - self.assertIsNotNone(t2, "stream.next() failed.") + self.assertTrue(t2 is not None, "stream.next() failed.") if t2.islnk() or t2.issym(): - with self.assertRaises(tarfile.StreamError): - tar2.extractfile(t2) + self.assertRaises(tarfile.StreamError, tar2.extractfile, t2) continue v1 = tar1.extractfile(t1) v2 = tar2.extractfile(t2) if v1 is None: continue - self.assertIsNotNone(v2, "stream.extractfile() failed") - self.assertEqual(v1.read(), v2.read(), - "stream extraction failed") + self.assertTrue(v2 is not None, "stream.extractfile() failed") + self.assertEqual(v1.read(), v2.read(), "stream extraction failed") finally: tar1.close() -class GzipStreamReadTest(GzipTest, StreamReadTest): - pass -class Bz2StreamReadTest(Bz2Test, StreamReadTest): - pass +class DetectReadTest(unittest.TestCase): -class LzmaStreamReadTest(LzmaTest, StreamReadTest): - pass - - -class DetectReadTest(TarTest, unittest.TestCase): def _testfunc_file(self, name, mode): try: tar = tarfile.open(name, mode) @@ -549,20 +493,47 @@ tar.close() def _test_modes(self, testfunc): - if self.suffix: - with self.assertRaises(tarfile.ReadError): - tarfile.open(tarname, mode="r:" + self.suffix) - with self.assertRaises(tarfile.ReadError): - tarfile.open(tarname, mode="r|" + self.suffix) - with self.assertRaises(tarfile.ReadError): - tarfile.open(self.tarname, mode="r:") - with self.assertRaises(tarfile.ReadError): - tarfile.open(self.tarname, mode="r|") - testfunc(self.tarname, "r") - testfunc(self.tarname, "r:" + self.suffix) - testfunc(self.tarname, "r:*") - testfunc(self.tarname, "r|" + self.suffix) - testfunc(self.tarname, "r|*") + testfunc(tarname, "r") + testfunc(tarname, "r:") + testfunc(tarname, "r:*") + testfunc(tarname, "r|") + testfunc(tarname, "r|*") + + if gzip: + self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:gz") + self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|gz") + self.assertRaises(tarfile.ReadError, tarfile.open, gzipname, mode="r:") + self.assertRaises(tarfile.ReadError, tarfile.open, gzipname, mode="r|") + + testfunc(gzipname, "r") + testfunc(gzipname, "r:*") + testfunc(gzipname, "r:gz") + testfunc(gzipname, "r|*") + testfunc(gzipname, "r|gz") + + if bz2: + self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:bz2") + self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|bz2") + self.assertRaises(tarfile.ReadError, tarfile.open, bz2name, mode="r:") + self.assertRaises(tarfile.ReadError, tarfile.open, bz2name, mode="r|") + + testfunc(bz2name, "r") + testfunc(bz2name, "r:*") + testfunc(bz2name, "r:bz2") + testfunc(bz2name, "r|*") + testfunc(bz2name, "r|bz2") + + if lzma: + self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:xz") + self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|xz") + self.assertRaises(tarfile.ReadError, tarfile.open, xzname, mode="r:") + self.assertRaises(tarfile.ReadError, tarfile.open, xzname, mode="r|") + + testfunc(xzname, "r") + testfunc(xzname, "r:*") + testfunc(xzname, "r:xz") + testfunc(xzname, "r|*") + testfunc(xzname, "r|xz") def test_detect_file(self): self._test_modes(self._testfunc_file) @@ -570,15 +541,14 @@ def test_detect_fileobj(self): self._test_modes(self._testfunc_fileobj) -class GzipDetectReadTest(GzipTest, DetectReadTest): - pass - -class Bz2DetectReadTest(Bz2Test, DetectReadTest): def test_detect_stream_bz2(self): # Originally, tarfile's stream detection looked for the string # "BZh91" at the start of the file. This is incorrect because # the '9' represents the blocksize (900kB). If the file was # compressed using another blocksize autodetection fails. + if not bz2: + return + with open(tarname, "rb") as fobj: data = fobj.read() @@ -588,17 +558,13 @@ self._testfunc_file(tmpname, "r|*") -class LzmaDetectReadTest(LzmaTest, DetectReadTest): - pass - -class MemberReadTest(ReadTest, unittest.TestCase): +class MemberReadTest(ReadTest): def _test_member(self, tarinfo, chksum=None, **kwargs): if chksum is not None: - with self.tar.extractfile(tarinfo) as f: - self.assertEqual(md5sum(f.read()), chksum, - "wrong md5sum for %s" % tarinfo.name) + self.assertTrue(md5sum(self.tar.extractfile(tarinfo).read()) == chksum, + "wrong md5sum for %s" % tarinfo.name) kwargs["mtime"] = 0o7606136617 kwargs["uid"] = 1000 @@ -608,7 +574,7 @@ kwargs["uname"] = "tarfile" kwargs["gname"] = "tarfile" for k, v in kwargs.items(): - self.assertEqual(getattr(tarinfo, k), v, + self.assertTrue(getattr(tarinfo, k) == v, "wrong value in %s field of %s" % (k, tarinfo.name)) def test_find_regtype(self): @@ -668,8 +634,7 @@ self._test_member(tarinfo, size=86016, chksum=md5_sparse) def test_find_umlauts(self): - tarinfo = self.tar.getmember("ustar/umlauts-" - "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") + tarinfo = self.tar.getmember("ustar/umlauts-\xc4\xd6\xdc\xe4\xf6\xfc\xdf") self._test_member(tarinfo, size=7011, chksum=md5_regtype) def test_find_ustar_longname(self): @@ -682,14 +647,12 @@ def test_find_pax_umlauts(self): self.tar.close() - self.tar = tarfile.open(self.tarname, mode=self.mode, - encoding="iso8859-1") - tarinfo = self.tar.getmember("pax/umlauts-" - "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") + self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1") + tarinfo = self.tar.getmember("pax/umlauts-\xc4\xd6\xdc\xe4\xf6\xfc\xdf") self._test_member(tarinfo, size=7011, chksum=md5_regtype) -class LongnameTest: +class LongnameTest(ReadTest): def test_read_longname(self): # Test reading of longname (bug #1471427). @@ -698,8 +661,7 @@ tarinfo = self.tar.getmember(longname) except KeyError: self.fail("longname not found") - self.assertNotEqual(tarinfo.type, tarfile.DIRTYPE, - "read longname as dirtype") + self.assertTrue(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype") def test_read_longlink(self): longname = self.subdir + "/" + "123/" * 125 + "longname" @@ -708,7 +670,7 @@ tarinfo = self.tar.getmember(longlink) except KeyError: self.fail("longlink not found") - self.assertEqual(tarinfo.linkname, longname, "linkname wrong") + self.assertTrue(tarinfo.linkname == longname, "linkname wrong") def test_truncated_longname(self): longname = self.subdir + "/" + "123/" * 125 + "longname" @@ -716,8 +678,7 @@ offset = tarinfo.offset self.tar.fileobj.seek(offset) fobj = io.BytesIO(self.tar.fileobj.read(3 * 512)) - with self.assertRaises(tarfile.ReadError): - tarfile.open(name="foo.tar", fileobj=fobj) + self.assertRaises(tarfile.ReadError, tarfile.open, name="foo.tar", fileobj=fobj) def test_header_offset(self): # Test if the start offset of the TarInfo object includes @@ -726,12 +687,11 @@ offset = self.tar.getmember(longname).offset with open(tarname, "rb") as fobj: fobj.seek(offset) - tarinfo = tarfile.TarInfo.frombuf(fobj.read(512), - "iso8859-1", "strict") + tarinfo = tarfile.TarInfo.frombuf(fobj.read(512), "iso8859-1", "strict") self.assertEqual(tarinfo.type, self.longnametype) -class GNUReadTest(LongnameTest, ReadTest, unittest.TestCase): +class GNUReadTest(LongnameTest): subdir = "gnu" longnametype = tarfile.GNUTYPE_LONGNAME @@ -753,7 +713,7 @@ if self._fs_supports_holes(): s = os.stat(filename) - self.assertLess(s.st_blocks * 512, s.st_size) + self.assertTrue(s.st_blocks * 512 < s.st_size) def test_sparse_file_old(self): self._test_sparse_file("gnu/sparse") @@ -785,7 +745,7 @@ return False -class PaxReadTest(LongnameTest, ReadTest, unittest.TestCase): +class PaxReadTest(LongnameTest): subdir = "pax" longnametype = tarfile.XHDTYPE @@ -796,20 +756,17 @@ tarinfo = tar.getmember("pax/regtype1") self.assertEqual(tarinfo.uname, "foo") self.assertEqual(tarinfo.gname, "bar") - self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), - "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") + self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") tarinfo = tar.getmember("pax/regtype2") self.assertEqual(tarinfo.uname, "") self.assertEqual(tarinfo.gname, "bar") - self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), - "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") + self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") tarinfo = tar.getmember("pax/regtype3") self.assertEqual(tarinfo.uname, "tarfile") self.assertEqual(tarinfo.gname, "tarfile") - self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), - "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") + self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), "\xc4\xd6\xdc\xe4\xf6\xfc\xdf") finally: tar.close() @@ -829,7 +786,7 @@ tar.close() -class WriteTestBase(TarTest): +class WriteTestBase(unittest.TestCase): # Put all write tests in here that are supposed to be tested # in all possible mode combinations. @@ -838,12 +795,12 @@ tar = tarfile.open(fileobj=fobj, mode=self.mode) tar.addfile(tarfile.TarInfo("foo")) tar.close() - self.assertFalse(fobj.closed, "external fileobjs must never closed") + self.assertTrue(fobj.closed is False, "external fileobjs must never closed") -class WriteTest(WriteTestBase, unittest.TestCase): +class WriteTest(WriteTestBase): - prefix = "w:" + mode = "w:" def test_100_char_name(self): # The name field in a tar header stores strings of at most 100 chars. @@ -860,7 +817,7 @@ tar = tarfile.open(tmpname) try: - self.assertEqual(tar.getnames()[0], name, + self.assertTrue(tar.getnames()[0] == name, "failed to store 100 char filename") finally: tar.close() @@ -875,7 +832,7 @@ tar.add(path) finally: tar.close() - self.assertGreater(os.path.getsize(tmpname), 0, + self.assertTrue(os.path.getsize(tmpname) > 0, "tarfile is empty") # The test_*_size tests test for bug #1167128. @@ -908,26 +865,25 @@ finally: os.rmdir(path) - @unittest.skipUnless(hasattr(os, "link"), - "Missing hardlink implementation") def test_link_size(self): - link = os.path.join(TEMPDIR, "link") - target = os.path.join(TEMPDIR, "link_target") - with open(target, "wb") as fobj: - fobj.write(b"aaa") - os.link(target, link) - try: - tar = tarfile.open(tmpname, self.mode) + if hasattr(os, "link"): + link = os.path.join(TEMPDIR, "link") + target = os.path.join(TEMPDIR, "link_target") + with open(target, "wb") as fobj: + fobj.write(b"aaa") + os.link(target, link) try: - # Record the link target in the inodes list. - tar.gettarinfo(target) - tarinfo = tar.gettarinfo(link) - self.assertEqual(tarinfo.size, 0) + tar = tarfile.open(tmpname, self.mode) + try: + # Record the link target in the inodes list. + tar.gettarinfo(target) + tarinfo = tar.gettarinfo(link) + self.assertEqual(tarinfo.size, 0) + finally: + tar.close() finally: - tar.close() - finally: - os.remove(target) - os.remove(link) + os.remove(target) + os.remove(link) @support.skip_unless_symlink def test_symlink_size(self): @@ -948,18 +904,15 @@ dstname = os.path.abspath(tmpname) tar = tarfile.open(tmpname, self.mode) try: - self.assertEqual(tar.name, dstname, - "archive name must be absolute") + self.assertTrue(tar.name == dstname, "archive name must be absolute") tar.add(dstname) - self.assertEqual(tar.getnames(), [], - "added the archive to itself") + self.assertTrue(tar.getnames() == [], "added the archive to itself") cwd = os.getcwd() os.chdir(TEMPDIR) tar.add(dstname) os.chdir(cwd) - self.assertEqual(tar.getnames(), [], - "added the archive to itself") + self.assertTrue(tar.getnames() == [], "added the archive to itself") finally: tar.close() @@ -1126,49 +1079,48 @@ tar = tarfile.open(tmpname, "r") try: for t in tar: - if t.name != ".": - self.assertTrue(t.name.startswith("./"), t.name) + self.assertTrue(t.name == "." or t.name.startswith("./")) finally: tar.close() finally: os.chdir(cwd) -class GzipWriteTest(GzipTest, WriteTest): - pass -class Bz2WriteTest(Bz2Test, WriteTest): - pass +class StreamWriteTest(WriteTestBase): -class LzmaWriteTest(LzmaTest, WriteTest): - pass - - -class StreamWriteTest(WriteTestBase, unittest.TestCase): - - prefix = "w|" - decompressor = None + mode = "w|" def test_stream_padding(self): # Test for bug #1543303. tar = tarfile.open(tmpname, self.mode) tar.close() - if self.decompressor: - dec = self.decompressor() + + if self.mode.endswith("gz"): + with gzip.GzipFile(tmpname) as fobj: + data = fobj.read() + elif self.mode.endswith("bz2"): + dec = bz2.BZ2Decompressor() with open(tmpname, "rb") as fobj: data = fobj.read() data = dec.decompress(data) - self.assertFalse(dec.unused_data, "found trailing data") + self.assertTrue(len(dec.unused_data) == 0, + "found trailing data") + elif self.mode.endswith("xz"): + with lzma.LZMAFile(tmpname) as fobj: + data = fobj.read() else: - with self.open(tmpname) as fobj: + with open(tmpname, "rb") as fobj: data = fobj.read() - self.assertEqual(data.count(b"\0"), tarfile.RECORDSIZE, - "incorrect zero padding") - @unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"), - "Missing umask implementation") + self.assertTrue(data.count(b"\0") == tarfile.RECORDSIZE, + "incorrect zero padding") + def test_file_mode(self): # Test for issue #8464: Create files with correct # permissions. + if sys.platform == "win32" or not hasattr(os, "umask"): + return + if os.path.exists(tmpname): os.remove(tmpname) @@ -1181,22 +1133,15 @@ finally: os.umask(original_umask) -class GzipStreamWriteTest(GzipTest, StreamWriteTest): - pass - -class Bz2StreamWriteTest(Bz2Test, StreamWriteTest): - decompressor = bz2.BZ2Decompressor if bz2 else None - -class LzmaStreamWriteTest(LzmaTest, StreamWriteTest): - decompressor = lzma.LZMADecompressor if lzma else None - class GNUWriteTest(unittest.TestCase): # This testcase checks for correct creation of GNU Longname # and Longlink extended headers (cp. bug #812325). def _length(self, s): - blocks = len(s) // 512 + 1 + blocks, remainder = divmod(len(s) + 1, 512) + if remainder: + blocks += 1 return blocks * 512 def _calc_size(self, name, link=None): @@ -1226,7 +1171,7 @@ v1 = self._calc_size(name, link) v2 = tar.offset - self.assertEqual(v1, v2, "GNU longname/longlink creation failed") + self.assertTrue(v1 == v2, "GNU longname/longlink creation failed") finally: tar.close() @@ -1273,7 +1218,6 @@ ("longlnk/" * 127) + "longlink_") -@unittest.skipUnless(hasattr(os, "link"), "Missing hardlink implementation") class HardlinkTest(unittest.TestCase): # Test the creation of LNKTYPE (hardlink) members in an archive. @@ -1298,18 +1242,18 @@ # The same name will be added as a REGTYPE every # time regardless of st_nlink. tarinfo = self.tar.gettarinfo(self.foo) - self.assertEqual(tarinfo.type, tarfile.REGTYPE, + self.assertTrue(tarinfo.type == tarfile.REGTYPE, "add file as regular failed") def test_add_hardlink(self): tarinfo = self.tar.gettarinfo(self.bar) - self.assertEqual(tarinfo.type, tarfile.LNKTYPE, + self.assertTrue(tarinfo.type == tarfile.LNKTYPE, "add file as hardlink failed") def test_dereference_hardlink(self): self.tar.dereference = True tarinfo = self.tar.gettarinfo(self.bar) - self.assertEqual(tarinfo.type, tarfile.REGTYPE, + self.assertTrue(tarinfo.type == tarfile.REGTYPE, "dereferencing hardlink failed") @@ -1332,10 +1276,10 @@ try: if link: l = tar.getmembers()[0].linkname - self.assertEqual(link, l, "PAX longlink creation failed") + self.assertTrue(link == l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name - self.assertEqual(name, n, "PAX longname creation failed") + self.assertTrue(name == n, "PAX longname creation failed") finally: tar.close() @@ -1361,8 +1305,8 @@ self.assertEqual(tar.getmembers()[0].pax_headers, pax_headers) # Test if all the fields are strings. for key, val in tar.pax_headers.items(): - self.assertIsNot(type(key), bytes) - self.assertIsNot(type(val), bytes) + self.assertTrue(type(key) is not bytes) + self.assertTrue(type(val) is not bytes) if key in tarfile.PAX_NUMBER_FIELDS: try: tarfile.PAX_NUMBER_FIELDS[key](val) @@ -1376,8 +1320,7 @@ # TarInfo. pax_headers = {"path": "foo", "uid": "123"} - tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, - encoding="iso8859-1") + tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") try: t = tarfile.TarInfo() t.name = "\xe4\xf6\xfc" # non-ASCII @@ -1411,8 +1354,7 @@ self._test_unicode_filename("utf-8") def _test_unicode_filename(self, encoding): - tar = tarfile.open(tmpname, "w", format=self.format, - encoding=encoding, errors="strict") + tar = tarfile.open(tmpname, "w", format=self.format, encoding=encoding, errors="strict") try: name = "\xe4\xf6\xfc" tar.addfile(tarfile.TarInfo(name)) @@ -1426,8 +1368,11 @@ tar.close() def test_unicode_filename_error(self): - tar = tarfile.open(tmpname, "w", format=self.format, - encoding="ascii", errors="strict") + if self.format == tarfile.PAX_FORMAT: + # PAX_FORMAT ignores encoding in write mode. + return + + tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") try: tarinfo = tarfile.TarInfo() @@ -1441,14 +1386,13 @@ tar.close() def test_unicode_argument(self): - tar = tarfile.open(tarname, "r", - encoding="iso8859-1", errors="strict") + tar = tarfile.open(tarname, "r", encoding="iso8859-1", errors="strict") try: for t in tar: - self.assertIs(type(t.name), str) - self.assertIs(type(t.linkname), str) - self.assertIs(type(t.uname), str) - self.assertIs(type(t.gname), str) + self.assertTrue(type(t.name) is str) + self.assertTrue(type(t.linkname) is str) + self.assertTrue(type(t.uname) is str) + self.assertTrue(type(t.gname) is str) finally: tar.close() @@ -1457,8 +1401,7 @@ t.uname = "\xe4\xf6\xfc" t.gname = "\xe4\xf6\xfc" - tar = tarfile.open(tmpname, mode="w", format=self.format, - encoding="iso8859-1") + tar = tarfile.open(tmpname, mode="w", format=self.format, encoding="iso8859-1") try: tar.addfile(t) finally: @@ -1487,11 +1430,9 @@ def test_bad_pax_header(self): # Test for issue #8633. GNU tar <= 1.23 creates raw binary fields # without a hdrcharset=BINARY header. - for encoding, name in ( - ("utf-8", "pax/bad-pax-\udce4\udcf6\udcfc"), + for encoding, name in (("utf-8", "pax/bad-pax-\udce4\udcf6\udcfc"), ("iso8859-1", "pax/bad-pax-\xe4\xf6\xfc"),): - with tarfile.open(tarname, encoding=encoding, - errors="surrogateescape") as tar: + with tarfile.open(tarname, encoding=encoding, errors="surrogateescape") as tar: try: t = tar.getmember(name) except KeyError: @@ -1502,23 +1443,18 @@ format = tarfile.PAX_FORMAT - # PAX_FORMAT ignores encoding in write mode. - test_unicode_filename_error = None - def test_binary_header(self): # Test a POSIX.1-2008 compatible header with a hdrcharset=BINARY field. - for encoding, name in ( - ("utf-8", "pax/hdrcharset-\udce4\udcf6\udcfc"), + for encoding, name in (("utf-8", "pax/hdrcharset-\udce4\udcf6\udcfc"), ("iso8859-1", "pax/hdrcharset-\xe4\xf6\xfc"),): - with tarfile.open(tarname, encoding=encoding, - errors="surrogateescape") as tar: + with tarfile.open(tarname, encoding=encoding, errors="surrogateescape") as tar: try: t = tar.getmember(name) except KeyError: self.fail("unable to read POSIX.1-2008 binary header") -class AppendTestBase: +class AppendTest(unittest.TestCase): # Test append mode (cp. patch #1652681). def setUp(self): @@ -1526,6 +1462,10 @@ if os.path.exists(self.tarname): os.remove(self.tarname) + def _add_testfile(self, fileobj=None): + with tarfile.open(self.tarname, "a", fileobj=fileobj) as tar: + tar.addfile(tarfile.TarInfo("bar")) + def _create_testtar(self, mode="w:"): with tarfile.open(tarname, encoding="iso8859-1") as src: t = src.getmember("ustar/regtype") @@ -1534,17 +1474,6 @@ with tarfile.open(self.tarname, mode) as tar: tar.addfile(t, f) - def test_append_compressed(self): - self._create_testtar("w:" + self.suffix) - self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a") - -class AppendTest(AppendTestBase, unittest.TestCase): - test_append_compressed = None - - def _add_testfile(self, fileobj=None): - with tarfile.open(self.tarname, "a", fileobj=fileobj) as tar: - tar.addfile(tarfile.TarInfo("bar")) - def _test(self, names=["bar"], fileobj=None): with tarfile.open(self.tarname, fileobj=fileobj) as tar: self.assertEqual(tar.getnames(), names) @@ -1578,6 +1507,24 @@ self._add_testfile() self._test(names=["foo", "bar"]) + def test_append_gz(self): + if gzip is None: + return + self._create_testtar("w:gz") + self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a") + + def test_append_bz2(self): + if bz2 is None: + return + self._create_testtar("w:bz2") + self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a") + + def test_append_lzma(self): + if lzma is None: + self.skipTest("lzma module not available") + self._create_testtar("w:xz") + self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a") + # Append mode is supposed to fail if the tarfile to append to # does not end with a zero block. def _test_error(self, data): @@ -1602,15 +1549,6 @@ def test_invalid(self): self._test_error(b"a" * 512) -class GzipAppendTest(GzipTest, AppendTestBase, unittest.TestCase): - pass - -class Bz2AppendTest(Bz2Test, AppendTestBase, unittest.TestCase): - pass - -class LzmaAppendTest(LzmaTest, AppendTestBase, unittest.TestCase): - pass - class LimitsTest(unittest.TestCase): @@ -1674,54 +1612,36 @@ class MiscTest(unittest.TestCase): def test_char_fields(self): - self.assertEqual(tarfile.stn("foo", 8, "ascii", "strict"), - b"foo\0\0\0\0\0") - self.assertEqual(tarfile.stn("foobar", 3, "ascii", "strict"), - b"foo") - self.assertEqual(tarfile.nts(b"foo\0\0\0\0\0", "ascii", "strict"), - "foo") - self.assertEqual(tarfile.nts(b"foo\0bar\0", "ascii", "strict"), - "foo") + self.assertEqual(tarfile.stn("foo", 8, "ascii", "strict"), b"foo\0\0\0\0\0") + self.assertEqual(tarfile.stn("foobar", 3, "ascii", "strict"), b"foo") + self.assertEqual(tarfile.nts(b"foo\0\0\0\0\0", "ascii", "strict"), "foo") + self.assertEqual(tarfile.nts(b"foo\0bar\0", "ascii", "strict"), "foo") def test_read_number_fields(self): # Issue 13158: Test if GNU tar specific base-256 number fields # are decoded correctly. self.assertEqual(tarfile.nti(b"0000001\x00"), 1) self.assertEqual(tarfile.nti(b"7777777\x00"), 0o7777777) - self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\x00\x20\x00\x00"), - 0o10000000) - self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\xff\xff\xff\xff"), - 0xffffffff) - self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\xff"), - -1) - self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\x9c"), - -100) - self.assertEqual(tarfile.nti(b"\xff\x00\x00\x00\x00\x00\x00\x00"), - -0x100000000000000) + self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\x00\x20\x00\x00"), 0o10000000) + self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\xff\xff\xff\xff"), 0xffffffff) + self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\xff"), -1) + self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\x9c"), -100) + self.assertEqual(tarfile.nti(b"\xff\x00\x00\x00\x00\x00\x00\x00"), -0x100000000000000) def test_write_number_fields(self): self.assertEqual(tarfile.itn(1), b"0000001\x00") self.assertEqual(tarfile.itn(0o7777777), b"7777777\x00") - self.assertEqual(tarfile.itn(0o10000000), - b"\x80\x00\x00\x00\x00\x20\x00\x00") - self.assertEqual(tarfile.itn(0xffffffff), - b"\x80\x00\x00\x00\xff\xff\xff\xff") - self.assertEqual(tarfile.itn(-1), - b"\xff\xff\xff\xff\xff\xff\xff\xff") - self.assertEqual(tarfile.itn(-100), - b"\xff\xff\xff\xff\xff\xff\xff\x9c") - self.assertEqual(tarfile.itn(-0x100000000000000), - b"\xff\x00\x00\x00\x00\x00\x00\x00") + self.assertEqual(tarfile.itn(0o10000000), b"\x80\x00\x00\x00\x00\x20\x00\x00") + self.assertEqual(tarfile.itn(0xffffffff), b"\x80\x00\x00\x00\xff\xff\xff\xff") + self.assertEqual(tarfile.itn(-1), b"\xff\xff\xff\xff\xff\xff\xff\xff") + self.assertEqual(tarfile.itn(-100), b"\xff\xff\xff\xff\xff\xff\xff\x9c") + self.assertEqual(tarfile.itn(-0x100000000000000), b"\xff\x00\x00\x00\x00\x00\x00\x00") def test_number_field_limits(self): - with self.assertRaises(ValueError): - tarfile.itn(-1, 8, tarfile.USTAR_FORMAT) - with self.assertRaises(ValueError): - tarfile.itn(0o10000000, 8, tarfile.USTAR_FORMAT) - with self.assertRaises(ValueError): - tarfile.itn(-0x10000000001, 6, tarfile.GNU_FORMAT) - with self.assertRaises(ValueError): - tarfile.itn(0x10000000000, 6, tarfile.GNU_FORMAT) + self.assertRaises(ValueError, tarfile.itn, -1, 8, tarfile.USTAR_FORMAT) + self.assertRaises(ValueError, tarfile.itn, 0o10000000, 8, tarfile.USTAR_FORMAT) + self.assertRaises(ValueError, tarfile.itn, -0x10000000001, 6, tarfile.GNU_FORMAT) + self.assertRaises(ValueError, tarfile.itn, 0x10000000000, 6, tarfile.GNU_FORMAT) class ContextManagerTest(unittest.TestCase): @@ -1782,19 +1702,19 @@ self.assertTrue(tar.closed, "context manager failed") -@unittest.skipIf(hasattr(os, "link"), "requires os.link to be missing") -class LinkEmulationTest(ReadTest, unittest.TestCase): +class LinkEmulationTest(ReadTest): # Test for issue #8741 regression. On platforms that do not support - # symbolic or hard links tarfile tries to extract these types of members - # as the regular files they point to. + # symbolic or hard links tarfile tries to extract these types of members as + # the regular files they point to. def _test_link_extraction(self, name): self.tar.extract(name, TEMPDIR) - with open(os.path.join(TEMPDIR, name), "rb") as f: - data = f.read() + data = open(os.path.join(TEMPDIR, name), "rb").read() self.assertEqual(md5sum(data), md5_regtype) - # See issues #1578269, #8879, and #17689 for some history on these skips + # When 8879 gets fixed, this will need to change. Currently on Windows + # we have os.path.islink but no os.link, so these tests fail without the + # following skip until link is completed. @unittest.skipIf(hasattr(os.path, "islink"), "Skip emulation - has os.path.islink but not os.link") def test_hardlink_extraction1(self): @@ -1816,7 +1736,44 @@ self._test_link_extraction("./ustar/linktest2/symtype") -class Bz2PartialReadTest(Bz2Test, unittest.TestCase): +class GzipMiscReadTest(MiscReadTest): + tarname = gzipname + mode = "r:gz" + + def test_non_existent_targz_file(self): + # Test for issue11513: prevent non-existent gzipped tarfiles raising + # multiple exceptions. + with self.assertRaisesRegex(OSError, "xxx") as ex: + tarfile.open("xxx", self.mode) + self.assertEqual(ex.exception.errno, errno.ENOENT) + +class GzipUstarReadTest(UstarReadTest): + tarname = gzipname + mode = "r:gz" +class GzipStreamReadTest(StreamReadTest): + tarname = gzipname + mode = "r|gz" +class GzipWriteTest(WriteTest): + mode = "w:gz" +class GzipStreamWriteTest(StreamWriteTest): + mode = "w|gz" + + +class Bz2MiscReadTest(MiscReadTest): + tarname = bz2name + mode = "r:bz2" +class Bz2UstarReadTest(UstarReadTest): + tarname = bz2name + mode = "r:bz2" +class Bz2StreamReadTest(StreamReadTest): + tarname = bz2name + mode = "r|bz2" +class Bz2WriteTest(WriteTest): + mode = "w:bz2" +class Bz2StreamWriteTest(StreamWriteTest): + mode = "w|bz2" + +class Bz2PartialReadTest(unittest.TestCase): # Issue5068: The _BZ2Proxy.read() method loops forever # on an empty or partial bzipped file. @@ -1825,8 +1782,7 @@ hit_eof = False def read(self, n): if self.hit_eof: - raise AssertionError("infinite loop detected in " - "tarfile.open()") + raise AssertionError("infinite loop detected in tarfile.open()") self.hit_eof = self.tell() == len(self.getvalue()) return super(MyBytesIO, self).read(n) def seek(self, *args): @@ -1847,23 +1803,102 @@ self._test_partial_input("r:bz2") -def setUpModule(): +class LzmaMiscReadTest(MiscReadTest): + tarname = xzname + mode = "r:xz" +class LzmaUstarReadTest(UstarReadTest): + tarname = xzname + mode = "r:xz" +class LzmaStreamReadTest(StreamReadTest): + tarname = xzname + mode = "r|xz" +class LzmaWriteTest(WriteTest): + mode = "w:xz" +class LzmaStreamWriteTest(StreamWriteTest): + mode = "w|xz" + + +def test_main(): support.unlink(TEMPDIR) os.makedirs(TEMPDIR) + tests = [ + UstarReadTest, + MiscReadTest, + StreamReadTest, + DetectReadTest, + MemberReadTest, + GNUReadTest, + PaxReadTest, + WriteTest, + StreamWriteTest, + GNUWriteTest, + PaxWriteTest, + UstarUnicodeTest, + GNUUnicodeTest, + PAXUnicodeTest, + AppendTest, + LimitsTest, + MiscTest, + ContextManagerTest, + ] + + if hasattr(os, "link"): + tests.append(HardlinkTest) + else: + tests.append(LinkEmulationTest) + with open(tarname, "rb") as fobj: data = fobj.read() - # Create compressed tarfiles. - for c in GzipTest, Bz2Test, LzmaTest: - if c.open: - support.unlink(c.tarname) - with c.open(c.tarname, "wb") as tar: - tar.write(data) + if gzip: + # Create testtar.tar.gz and add gzip-specific tests. + support.unlink(gzipname) + with gzip.open(gzipname, "wb") as tar: + tar.write(data) -def tearDownModule(): - if os.path.exists(TEMPDIR): - shutil.rmtree(TEMPDIR) + tests += [ + GzipMiscReadTest, + GzipUstarReadTest, + GzipStreamReadTest, + GzipWriteTest, + GzipStreamWriteTest, + ] + + if bz2: + # Create testtar.tar.bz2 and add bz2-specific tests. + support.unlink(bz2name) + with bz2.BZ2File(bz2name, "wb") as tar: + tar.write(data) + + tests += [ + Bz2MiscReadTest, + Bz2UstarReadTest, + Bz2StreamReadTest, + Bz2WriteTest, + Bz2StreamWriteTest, + Bz2PartialReadTest, + ] + + if lzma: + # Create testtar.tar.xz and add lzma-specific tests. + support.unlink(xzname) + with lzma.LZMAFile(xzname, "w") as tar: + tar.write(data) + + tests += [ + LzmaMiscReadTest, + LzmaUstarReadTest, + LzmaStreamReadTest, + LzmaWriteTest, + LzmaStreamWriteTest, + ] + + try: + support.run_unittest(*tests) + finally: + if os.path.exists(TEMPDIR): + shutil.rmtree(TEMPDIR) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_tcl.py Fri Feb 01 23:12:09 2013 +0100 @@ -8,9 +8,6 @@ # Skip this test if the _tkinter module wasn't built. _tkinter = support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - from tkinter import Tcl from _tkinter import TclError @@ -154,86 +151,6 @@ # exit code must be zero self.assertEqual(f.close(), None) - def test_passing_values(self): - def passValue(value): - return self.interp.call('set', '_', value) - - self.assertEqual(passValue(True), True) - self.assertEqual(passValue(False), False) - self.assertEqual(passValue('string'), 'string') - self.assertEqual(passValue('string\u20ac'), 'string\u20ac') - for i in (0, 1, -1, 2**31-1, -2**31): - self.assertEqual(passValue(i), i) - for f in (0.0, 1.0, -1.0, 1/3, - sys.float_info.min, sys.float_info.max, - -sys.float_info.min, -sys.float_info.max): - self.assertEqual(passValue(f), f) - for f in float('nan'), float('inf'), -float('inf'): - if f != f: # NaN - self.assertNotEqual(passValue(f), f) - else: - self.assertEqual(passValue(f), f) - self.assertEqual(passValue((1, '2', (3.4,))), (1, '2', (3.4,))) - - def test_splitlist(self): - splitlist = self.interp.tk.splitlist - call = self.interp.tk.call - self.assertRaises(TypeError, splitlist) - self.assertRaises(TypeError, splitlist, 'a', 'b') - self.assertRaises(TypeError, splitlist, 2) - testcases = [ - ('2', ('2',)), - ('', ()), - ('{}', ('',)), - ('""', ('',)), - ('a\n b\t\r c\n ', ('a', 'b', 'c')), - (b'a\n b\t\r c\n ', ('a', 'b', 'c')), - ('a \u20ac', ('a', '\u20ac')), - (b'a \xe2\x82\xac', ('a', '\u20ac')), - ('a {b c}', ('a', 'b c')), - (r'a b\ c', ('a', 'b c')), - (('a', 'b c'), ('a', 'b c')), - ('a 2', ('a', '2')), - (('a', 2), ('a', 2)), - ('a 3.4', ('a', '3.4')), - (('a', 3.4), ('a', 3.4)), - ((), ()), - (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))), - ] - for arg, res in testcases: - self.assertEqual(splitlist(arg), res, msg=arg) - self.assertRaises(TclError, splitlist, '{') - - def test_split(self): - split = self.interp.tk.split - call = self.interp.tk.call - self.assertRaises(TypeError, split) - self.assertRaises(TypeError, split, 'a', 'b') - self.assertRaises(TypeError, split, 2) - testcases = [ - ('2', '2'), - ('', ''), - ('{}', ''), - ('""', ''), - ('{', '{'), - ('a\n b\t\r c\n ', ('a', 'b', 'c')), - (b'a\n b\t\r c\n ', ('a', 'b', 'c')), - ('a \u20ac', ('a', '\u20ac')), - (b'a \xe2\x82\xac', ('a', '\u20ac')), - ('a {b c}', ('a', ('b', 'c'))), - (r'a b\ c', ('a', ('b', 'c'))), - (('a', b'b c'), ('a', ('b', 'c'))), - (('a', 'b c'), ('a', ('b', 'c'))), - ('a 2', ('a', '2')), - (('a', 2), ('a', 2)), - ('a 3.4', ('a', '3.4')), - (('a', 3.4), ('a', 3.4)), - (('a', (2, 3.4)), ('a', (2, 3.4))), - ((), ()), - (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))), - ] - for arg, res in testcases: - self.assertEqual(split(arg), res, msg=arg) def test_main(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_tempfile.py --- a/Lib/test/test_tempfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_tempfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,5 @@ # tempfile.py unit tests. import tempfile -import errno -import io import os import signal import sys @@ -199,44 +197,7 @@ # paths in this list. -# We test _get_default_tempdir some more by testing gettempdir. - -class TestGetDefaultTempdir(BaseTestCase): - """Test _get_default_tempdir().""" - - def test_no_files_left_behind(self): - # use a private empty directory - with tempfile.TemporaryDirectory() as our_temp_directory: - # force _get_default_tempdir() to consider our empty directory - def our_candidate_list(): - return [our_temp_directory] - - with support.swap_attr(tempfile, "_candidate_tempdir_list", - our_candidate_list): - # verify our directory is empty after _get_default_tempdir() - tempfile._get_default_tempdir() - self.assertEqual(os.listdir(our_temp_directory), []) - - def raise_OSError(*args, **kwargs): - raise OSError() - - with support.swap_attr(io, "open", raise_OSError): - # test again with failing io.open() - with self.assertRaises(FileNotFoundError): - tempfile._get_default_tempdir() - self.assertEqual(os.listdir(our_temp_directory), []) - - open = io.open - def bad_writer(*args, **kwargs): - fp = open(*args, **kwargs) - fp.write = raise_OSError - return fp - - with support.swap_attr(io, "open", bad_writer): - # test again with failing write() - with self.assertRaises(FileNotFoundError): - tempfile._get_default_tempdir() - self.assertEqual(os.listdir(our_temp_directory), []) +# We test _get_default_tempdir by testing gettempdir. class TestGetCandidateNames(BaseTestCase): @@ -784,26 +745,6 @@ seek(0, 0) self.assertEqual(read(70), b'a'*35 + b'b'*35) - def test_properties(self): - f = tempfile.SpooledTemporaryFile(max_size=10) - f.write(b'x' * 10) - self.assertFalse(f._rolled) - self.assertEqual(f.mode, 'w+b') - self.assertIsNone(f.name) - with self.assertRaises(AttributeError): - f.newlines - with self.assertRaises(AttributeError): - f.encoding - - f.write(b'x') - self.assertTrue(f._rolled) - self.assertEqual(f.mode, 'rb+') - self.assertIsNotNone(f.name) - with self.assertRaises(AttributeError): - f.newlines - with self.assertRaises(AttributeError): - f.encoding - def test_text_mode(self): # Creating a SpooledTemporaryFile with a text mode should produce # a file object reading and writing (Unicode) text strings. @@ -814,12 +755,6 @@ f.write("def\n") f.seek(0) self.assertEqual(f.read(), "abc\ndef\n") - self.assertFalse(f._rolled) - self.assertEqual(f.mode, 'w+') - self.assertIsNone(f.name) - self.assertIsNone(f.newlines) - self.assertIsNone(f.encoding) - f.write("xyzzy\n") f.seek(0) self.assertEqual(f.read(), "abc\ndef\nxyzzy\n") @@ -827,11 +762,6 @@ f.write("foo\x1abar\n") f.seek(0) self.assertEqual(f.read(), "abc\ndef\nxyzzy\nfoo\x1abar\n") - self.assertTrue(f._rolled) - self.assertEqual(f.mode, 'w+') - self.assertIsNotNone(f.name) - self.assertEqual(f.newlines, os.linesep) - self.assertIsNotNone(f.encoding) def test_text_newline_and_encoding(self): f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10, @@ -840,19 +770,11 @@ f.seek(0) self.assertEqual(f.read(), "\u039B\r\n") self.assertFalse(f._rolled) - self.assertEqual(f.mode, 'w+') - self.assertIsNone(f.name) - self.assertIsNone(f.newlines) - self.assertIsNone(f.encoding) f.write("\u039B" * 20 + "\r\n") f.seek(0) self.assertEqual(f.read(), "\u039B\r\n" + ("\u039B" * 20) + "\r\n") self.assertTrue(f._rolled) - self.assertEqual(f.mode, 'w+') - self.assertIsNotNone(f.name) - self.assertIsNotNone(f.newlines) - self.assertEqual(f.encoding, 'utf-8') def test_context_manager_before_rollover(self): # A SpooledTemporaryFile can be used as a context manager @@ -1002,9 +924,8 @@ # (noted as part of Issue #10188) with tempfile.TemporaryDirectory() as nonexistent: pass - with self.assertRaises(FileNotFoundError) as cm: + with self.assertRaises(OSError): tempfile.TemporaryDirectory(dir=nonexistent) - self.assertEqual(cm.exception.errno, errno.ENOENT) def test_explicit_cleanup(self): # A TemporaryDirectory is deleted when cleaned up diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_threaded_import.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,8 +5,8 @@ # complains several times about module random having no attribute # randrange, and then Python hangs. -import _imp as imp import os +import imp import importlib import sys import time diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_threading.py --- a/Lib/test/test_threading.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_threading.py Fri Feb 01 23:12:09 2013 +0100 @@ -451,8 +451,7 @@ # #12316 and #11870), and fork() from a worker thread is known to trigger # problems with some operating systems (issue #3863): skip problematic tests # on platforms known to behave badly. - platforms_to_skip = ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5', - 'hp-ux11') + platforms_to_skip = ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5') def _run_and_join(self, script): script = """if 1: @@ -728,31 +727,6 @@ for t in threads: t.join() - @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") - def test_clear_threads_states_after_fork(self): - # Issue #17094: check that threads states are cleared after fork() - - # start a bunch of threads - threads = [] - for i in range(16): - t = threading.Thread(target=lambda : time.sleep(0.3)) - threads.append(t) - t.start() - - pid = os.fork() - if pid == 0: - # check that threads states have been cleared - if len(sys._current_frames()) == 1: - os._exit(0) - else: - os._exit(1) - else: - _, status = os.waitpid(pid, 0) - self.assertEqual(0, status) - - for t in threads: - t.join() - class ThreadingExceptionTests(BaseTestCase): # A RuntimeError should be raised if Thread.start() is called @@ -812,32 +786,6 @@ self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode()) self.assertEqual(data, expected_output) -class TimerTests(BaseTestCase): - - def setUp(self): - BaseTestCase.setUp(self) - self.callback_args = [] - self.callback_event = threading.Event() - - def test_init_immutable_default_args(self): - # Issue 17435: constructor defaults were mutable objects, they could be - # mutated via the object attributes and affect other Timer objects. - timer1 = threading.Timer(0.01, self._callback_spy) - timer1.start() - self.callback_event.wait() - timer1.args.append("blah") - timer1.kwargs["foo"] = "bar" - self.callback_event.clear() - timer2 = threading.Timer(0.01, self._callback_spy) - timer2.start() - self.callback_event.wait() - self.assertEqual(len(self.callback_args), 2) - self.assertEqual(self.callback_args, [((), {}), ((), {})]) - - def _callback_spy(self, *args, **kwargs): - self.callback_args.append((args[:], kwargs.copy())) - self.callback_event.set() - class LockTests(lock_tests.LockTests): locktype = staticmethod(threading.Lock) @@ -867,5 +815,16 @@ class BarrierTests(lock_tests.BarrierTests): barriertype = staticmethod(threading.Barrier) + +def test_main(): + test.support.run_unittest(LockTests, PyRLockTests, CRLockTests, EventTests, + ConditionAsRLockTests, ConditionTests, + SemaphoreTests, BoundedSemaphoreTests, + ThreadTests, + ThreadJoinOnShutdown, + ThreadingExceptionTests, + BarrierTests, + ) + if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_time.py --- a/Lib/test/test_time.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_time.py Fri Feb 01 23:12:09 2013 +0100 @@ -193,12 +193,6 @@ self.assertRaises(TypeError, time.strptime, b'2009', "%Y") self.assertRaises(TypeError, time.strptime, '2009', b'%Y') - def test_strptime_exception_context(self): - # check that this doesn't chain exceptions needlessly (see #17572) - with self.assertRaises(ValueError) as e: - time.strptime('', '%D') - self.assertIs(e.exception.__suppress_context__, True) - def test_asctime(self): time.asctime(time.gmtime(self.t)) @@ -368,11 +362,11 @@ 'need time.monotonic') def test_monotonic(self): t1 = time.monotonic() - time.sleep(0.5) + time.sleep(0.1) t2 = time.monotonic() dt = t2 - t1 self.assertGreater(t2, t1) - self.assertAlmostEqual(dt, 0.5, delta=0.2) + self.assertAlmostEqual(dt, 0.1, delta=0.2) info = time.get_clock_info('monotonic') self.assertTrue(info.monotonic) @@ -465,6 +459,10 @@ time.strftime("%B", (2009,2,1,0,0,0,0,0,0)) +class _BaseYearTest(unittest.TestCase): + def yearstr(self, y): + raise NotImplementedError() + class _TestAsctimeYear: _format = '%d' @@ -522,7 +520,7 @@ del skip_if_not_supported -class _Test4dYear: +class _Test4dYear(_BaseYearTest): _format = '%d' def test_year(self, fmt=None, func=None): @@ -555,10 +553,10 @@ self.assertRaises(OverflowError, self.yearstr, TIME_MINYEAR - 1) -class TestAsctime4dyear(_TestAsctimeYear, _Test4dYear, unittest.TestCase): +class TestAsctime4dyear(_TestAsctimeYear, _Test4dYear): pass -class TestStrftime4dyear(_TestStrftimeYear, _Test4dYear, unittest.TestCase): +class TestStrftime4dyear(_TestStrftimeYear, _Test4dYear): pass @@ -675,6 +673,13 @@ self.assertIs(lt.tm_gmtoff, None) self.assertIs(lt.tm_zone, None) +def test_main(): + support.run_unittest( + TimeTestCase, + TestLocale, + TestAsctime4dyear, + TestStrftime4dyear, + TestPytime) if __name__ == "__main__": - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_tk.py --- a/Lib/test/test_tk.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_tk.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,9 +2,6 @@ # Skip test if _tkinter wasn't built. support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - # Skip test if tk cannot be initialized. from tkinter.test.support import check_tk_availability check_tk_availability() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_trace.py --- a/Lib/test/test_trace.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_trace.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,4 @@ import os -import io import sys from test.support import (run_unittest, TESTFN, rmtree, unlink, captured_stdout) @@ -362,51 +361,6 @@ self.assertTrue(ignore.names(jn('bar', 'baz.py'), 'baz')) -class TestDeprecatedMethods(unittest.TestCase): - - def test_deprecated_usage(self): - sio = io.StringIO() - with self.assertWarns(DeprecationWarning): - trace.usage(sio) - self.assertIn('Usage:', sio.getvalue()) - - def test_deprecated_Ignore(self): - with self.assertWarns(DeprecationWarning): - trace.Ignore() - - def test_deprecated_modname(self): - with self.assertWarns(DeprecationWarning): - self.assertEqual("spam", trace.modname("spam")) - - def test_deprecated_fullmodname(self): - with self.assertWarns(DeprecationWarning): - self.assertEqual("spam", trace.fullmodname("spam")) - - def test_deprecated_find_lines_from_code(self): - with self.assertWarns(DeprecationWarning): - def foo(): - pass - trace.find_lines_from_code(foo.__code__, ["eggs"]) - - def test_deprecated_find_lines(self): - with self.assertWarns(DeprecationWarning): - def foo(): - pass - trace.find_lines(foo.__code__, ["eggs"]) - - def test_deprecated_find_strings(self): - with open(TESTFN, 'w') as fd: - self.addCleanup(unlink, TESTFN) - with self.assertWarns(DeprecationWarning): - trace.find_strings(fd.name) - - def test_deprecated_find_executable_linenos(self): - with open(TESTFN, 'w') as fd: - self.addCleanup(unlink, TESTFN) - with self.assertWarns(DeprecationWarning): - trace.find_executable_linenos(fd.name) - - def test_main(): run_unittest(__name__) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_traceback.py --- a/Lib/test/test_traceback.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_traceback.py Fri Feb 01 23:12:09 2013 +0100 @@ -160,26 +160,11 @@ file_ = StringIO() traceback_print(tb, file_) python_fmt = file_.getvalue() - # Call all _tb and _exc functions - with captured_output("stderr") as tbstderr: - traceback.print_tb(tb) - tbfile = StringIO() - traceback.print_tb(tb, file=tbfile) - with captured_output("stderr") as excstderr: - traceback.print_exc() - excfmt = traceback.format_exc() - excfile = StringIO() - traceback.print_exc(file=excfile) else: raise Error("unable to create test traceback string") # Make sure that Python and the traceback module format the same thing self.assertEqual(traceback_fmt, python_fmt) - # Now verify the _tb func output - self.assertEqual(tbstderr.getvalue(), tbfile.getvalue()) - # Now verify the _exc func output - self.assertEqual(excstderr.getvalue(), excfile.getvalue()) - self.assertEqual(excfmt, excfile.getvalue()) # Make sure that the traceback is properly indented. tb_lines = python_fmt.splitlines() @@ -189,19 +174,6 @@ self.assertTrue(location.startswith(' File')) self.assertTrue(source_line.startswith(' raise')) - def test_stack_format(self): - # Verify _stack functions. Note we have to use _getframe(1) to - # compare them without this frame appearing in the output - with captured_output("stderr") as ststderr: - traceback.print_stack(sys._getframe(1)) - stfile = StringIO() - traceback.print_stack(sys._getframe(1), file=stfile) - self.assertEqual(ststderr.getvalue(), stfile.getvalue()) - - stfmt = traceback.format_stack(sys._getframe(1)) - - self.assertEqual(ststderr.getvalue(), "".join(stfmt)) - cause_message = ( "\nThe above exception was the direct cause " diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ttk_guionly.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,9 +5,6 @@ # Skip this test if _tkinter wasn't built. support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - # Skip test if tk cannot be initialized. from tkinter.test.support import check_tk_availability check_tk_availability() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ttk_textonly.py --- a/Lib/test/test_ttk_textonly.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ttk_textonly.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,9 +4,6 @@ # Skip this test if _tkinter does not exist. support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - from tkinter.test import runtktests def test_main(): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_types.py --- a/Lib/test/test_types.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_types.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,7 +2,6 @@ from test.support import run_unittest, run_with_locale import collections -import pickle import locale import sys import types @@ -1078,19 +1077,9 @@ ns2 = types.SimpleNamespace() ns2.x = "spam" ns2._y = 5 - name = "namespace" - self.assertEqual(repr(ns1), "{name}(w=3, x=1, y=2)".format(name=name)) - self.assertEqual(repr(ns2), "{name}(_y=5, x='spam')".format(name=name)) - - def test_equal(self): - ns1 = types.SimpleNamespace(x=1) - ns2 = types.SimpleNamespace() - ns2.x = 1 - - self.assertEqual(types.SimpleNamespace(), types.SimpleNamespace()) - self.assertEqual(ns1, ns2) - self.assertNotEqual(ns2, types.SimpleNamespace()) + self.assertEqual(repr(ns1), "namespace(w=3, x=1, y=2)") + self.assertEqual(repr(ns2), "namespace(_y=5, x='spam')") def test_nested(self): ns1 = types.SimpleNamespace(a=1, b=2) @@ -1128,12 +1117,11 @@ ns1.spam = ns1 ns2.spam = ns3 ns3.spam = ns2 - name = "namespace" - repr1 = "{name}(c='cookie', spam={name}(...))".format(name=name) - repr2 = "{name}(spam={name}(spam={name}(...), x=1))".format(name=name) - self.assertEqual(repr(ns1), repr1) - self.assertEqual(repr(ns2), repr2) + self.assertEqual(repr(ns1), + "namespace(c='cookie', spam=namespace(...))") + self.assertEqual(repr(ns2), + "namespace(spam=namespace(spam=namespace(...), x=1))") def test_as_dict(self): ns = types.SimpleNamespace(spam='spamspamspam') @@ -1156,19 +1144,6 @@ self.assertIs(type(spam), Spam) self.assertEqual(vars(spam), {'ham': 8, 'eggs': 9}) - def test_pickle(self): - ns = types.SimpleNamespace(breakfast="spam", lunch="spam") - - for protocol in range(pickle.HIGHEST_PROTOCOL + 1): - pname = "protocol {}".format(protocol) - try: - ns_pickled = pickle.dumps(ns, protocol) - except TypeError as e: - raise TypeError(pname) from e - ns_roundtrip = pickle.loads(ns_pickled) - - self.assertEqual(ns, ns_roundtrip, pname) - def test_main(): run_unittest(TypesTests, MappingProxyTests, ClassCreationTests, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_ucn.py --- a/Lib/test/test_ucn.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_ucn.py Fri Feb 01 23:12:09 2013 +0100 @@ -9,7 +9,6 @@ import unittest import unicodedata -import _testcapi from test import support from http.client import HTTPException @@ -216,21 +215,6 @@ str, b"\\NSPACE", 'unicode-escape', 'strict' ) - @unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX, - "needs UINT_MAX < SIZE_MAX") - @support.bigmemtest(size=_testcapi.UINT_MAX + 1, - memuse=2 + 1, dry_run=False) - def test_issue16335(self, size): - # very very long bogus character name - x = b'\\N{SPACE' + b'x' * (_testcapi.UINT_MAX + 1) + b'}' - self.assertEqual(len(x), len(b'\\N{SPACE}') + - (_testcapi.UINT_MAX + 1)) - self.assertRaisesRegex(UnicodeError, - 'unknown Unicode character name', - x.decode, 'unicode-escape' - ) - - def test_main(): support.run_unittest(UnicodeNamesTest) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_unicode.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,7 +7,6 @@ """#" import _string import codecs -import itertools import struct import sys import unittest @@ -32,16 +31,6 @@ return None codecs.register(search_function) -def duplicate_string(text): - """ - Try to get a fresh clone of the specified text: - new object with a reference count of 1. - - This is a best-effort: latin1 single letters and the empty - string ('') are singletons and cannot be cloned. - """ - return text.encode().decode() - class UnicodeTest(string_tests.CommonTest, string_tests.MixinStrUnicodeUserStringTest, string_tests.MixinStrUnicodeTest, @@ -663,15 +652,6 @@ self.assertEqual('ß'.swapcase(), 'SS') self.assertEqual('\u1fd2'.swapcase(), '\u0399\u0308\u0300') - def test_center(self): - string_tests.CommonTest.test_center(self) - self.assertEqual('x'.center(2, '\U0010FFFF'), - 'x\U0010FFFF') - self.assertEqual('x'.center(3, '\U0010FFFF'), - '\U0010FFFFx\U0010FFFF') - self.assertEqual('x'.center(4, '\U0010FFFF'), - '\U0010FFFFx\U0010FFFF\U0010FFFF') - def test_contains(self): # Testing Unicode contains method self.assertIn('a', 'abdb') @@ -703,17 +683,6 @@ self.assertRaises(TypeError, "abc".__contains__) - def test_issue18183(self): - '\U00010000\U00100000'.lower() - '\U00010000\U00100000'.casefold() - '\U00010000\U00100000'.upper() - '\U00010000\U00100000'.capitalize() - '\U00010000\U00100000'.title() - '\U00010000\U00100000'.swapcase() - '\U00100000'.center(3, '\U00010000') - '\U00100000'.ljust(3, '\U00010000') - '\U00100000'.rjust(3, '\U00010000') - def test_format(self): self.assertEqual(''.format(), '') self.assertEqual('a'.format(), 'a') @@ -912,7 +881,7 @@ self.assertRaises(ValueError, "{0".format) self.assertRaises(IndexError, "{0.}".format) self.assertRaises(ValueError, "{0.}".format, 0) - self.assertRaises(ValueError, "{0[}".format) + self.assertRaises(IndexError, "{0[}".format) self.assertRaises(ValueError, "{0[}".format, []) self.assertRaises(KeyError, "{0]}".format) self.assertRaises(ValueError, "{0.[]}".format, 0) @@ -963,16 +932,6 @@ self.assertEqual("{0:.0s}".format("ABC\u0410\u0411\u0412"), '') - self.assertEqual("{[{}]}".format({"{}": 5}), "5") - self.assertEqual("{[{}]}".format({"{}" : "a"}), "a") - self.assertEqual("{[{]}".format({"{" : "a"}), "a") - self.assertEqual("{[}]}".format({"}" : "a"}), "a") - self.assertEqual("{[[]}".format({"[" : "a"}), "a") - self.assertEqual("{[!]}".format({"!" : "a"}), "a") - self.assertRaises(ValueError, "{a{}b}".format, 42) - self.assertRaises(ValueError, "{a{b}".format, 42) - self.assertRaises(ValueError, "{[}".format, 42) - def test_format_map(self): self.assertEqual(''.format_map({}), '') self.assertEqual('a'.format_map({}), 'a') @@ -2037,13 +1996,9 @@ for arg in args) return _PyUnicode_FromFormat(format, *cargs) - def check_format(expected, format, *args): - text = PyUnicode_FromFormat(format, *args) - self.assertEqual(expected, text) - # ascii format, non-ascii argument - check_format('ascii\x7f=unicode\xe9', - b'ascii\x7f=%U', 'unicode\xe9') + text = PyUnicode_FromFormat(b'ascii\x7f=%U', 'unicode\xe9') + self.assertEqual(text, 'ascii\x7f=unicode\xe9') # non-ascii format, ascii argument: ensure that PyUnicode_FromFormatV() # raises an error @@ -2053,205 +2008,83 @@ PyUnicode_FromFormat, b'unicode\xe9=%s', 'ascii') # test "%c" - check_format('\uabcd', - b'%c', c_int(0xabcd)) - check_format('\U0010ffff', - b'%c', c_int(0x10ffff)) - with self.assertRaises(OverflowError): - PyUnicode_FromFormat(b'%c', c_int(0x110000)) - # Issue #18183 - check_format('\U00010000\U00100000', - b'%c%c', c_int(0x10000), c_int(0x100000)) + self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0xabcd)), '\uabcd') + self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0x10ffff)), '\U0010ffff') # test "%" - check_format('%', - b'%') - check_format('%', - b'%%') - check_format('%s', - b'%%s') - check_format('[%]', - b'[%%]') - check_format('%abc', - b'%%%s', b'abc') - - # truncated string - check_format('abc', - b'%.3s', b'abcdef') - check_format('abc[\ufffd', - b'%.5s', 'abc[\u20ac]'.encode('utf8')) - check_format("'\\u20acABC'", - b'%A', '\u20acABC') - check_format("'\\u20", - b'%.5A', '\u20acABCDEF') - check_format("'\u20acABC'", - b'%R', '\u20acABC') - check_format("'\u20acA", - b'%.3R', '\u20acABCDEF') - check_format('\u20acAB', - b'%.3S', '\u20acABCDEF') - check_format('\u20acAB', - b'%.3U', '\u20acABCDEF') - check_format('\u20acAB', - b'%.3V', '\u20acABCDEF', None) - check_format('abc[\ufffd', - b'%.5V', None, 'abc[\u20ac]'.encode('utf8')) - - # following tests comes from #7330 - # test width modifier and precision modifier with %S - check_format("repr= abc", - b'repr=%5S', 'abc') - check_format("repr=ab", - b'repr=%.2S', 'abc') - check_format("repr= ab", - b'repr=%5.2S', 'abc') - - # test width modifier and precision modifier with %R - check_format("repr= 'abc'", - b'repr=%8R', 'abc') - check_format("repr='ab", - b'repr=%.3R', 'abc') - check_format("repr= 'ab", - b'repr=%5.3R', 'abc') - - # test width modifier and precision modifier with %A - check_format("repr= 'abc'", - b'repr=%8A', 'abc') - check_format("repr='ab", - b'repr=%.3A', 'abc') - check_format("repr= 'ab", - b'repr=%5.3A', 'abc') - - # test width modifier and precision modifier with %s - check_format("repr= abc", - b'repr=%5s', b'abc') - check_format("repr=ab", - b'repr=%.2s', b'abc') - check_format("repr= ab", - b'repr=%5.2s', b'abc') - - # test width modifier and precision modifier with %U - check_format("repr= abc", - b'repr=%5U', 'abc') - check_format("repr=ab", - b'repr=%.2U', 'abc') - check_format("repr= ab", - b'repr=%5.2U', 'abc') - - # test width modifier and precision modifier with %V - check_format("repr= abc", - b'repr=%5V', 'abc', b'123') - check_format("repr=ab", - b'repr=%.2V', 'abc', b'123') - check_format("repr= ab", - b'repr=%5.2V', 'abc', b'123') - check_format("repr= 123", - b'repr=%5V', None, b'123') - check_format("repr=12", - b'repr=%.2V', None, b'123') - check_format("repr= 12", - b'repr=%5.2V', None, b'123') + self.assertEqual(PyUnicode_FromFormat(b'%'), '%') + self.assertEqual(PyUnicode_FromFormat(b'%%'), '%') + self.assertEqual(PyUnicode_FromFormat(b'%%s'), '%s') + self.assertEqual(PyUnicode_FromFormat(b'[%%]'), '[%]') + self.assertEqual(PyUnicode_FromFormat(b'%%%s', b'abc'), '%abc') # test integer formats (%i, %d, %u) - check_format('010', - b'%03i', c_int(10)) - check_format('0010', - b'%0.4i', c_int(10)) - check_format('-123', - b'%i', c_int(-123)) - check_format('-123', - b'%li', c_long(-123)) - check_format('-123', - b'%lli', c_longlong(-123)) - check_format('-123', - b'%zi', c_ssize_t(-123)) + self.assertEqual(PyUnicode_FromFormat(b'%03i', c_int(10)), '010') + self.assertEqual(PyUnicode_FromFormat(b'%0.4i', c_int(10)), '0010') + self.assertEqual(PyUnicode_FromFormat(b'%i', c_int(-123)), '-123') + self.assertEqual(PyUnicode_FromFormat(b'%li', c_long(-123)), '-123') + self.assertEqual(PyUnicode_FromFormat(b'%lli', c_longlong(-123)), '-123') + self.assertEqual(PyUnicode_FromFormat(b'%zi', c_ssize_t(-123)), '-123') - check_format('-123', - b'%d', c_int(-123)) - check_format('-123', - b'%ld', c_long(-123)) - check_format('-123', - b'%lld', c_longlong(-123)) - check_format('-123', - b'%zd', c_ssize_t(-123)) + self.assertEqual(PyUnicode_FromFormat(b'%d', c_int(-123)), '-123') + self.assertEqual(PyUnicode_FromFormat(b'%ld', c_long(-123)), '-123') + self.assertEqual(PyUnicode_FromFormat(b'%lld', c_longlong(-123)), '-123') + self.assertEqual(PyUnicode_FromFormat(b'%zd', c_ssize_t(-123)), '-123') - check_format('123', - b'%u', c_uint(123)) - check_format('123', - b'%lu', c_ulong(123)) - check_format('123', - b'%llu', c_ulonglong(123)) - check_format('123', - b'%zu', c_size_t(123)) + self.assertEqual(PyUnicode_FromFormat(b'%u', c_uint(123)), '123') + self.assertEqual(PyUnicode_FromFormat(b'%lu', c_ulong(123)), '123') + self.assertEqual(PyUnicode_FromFormat(b'%llu', c_ulonglong(123)), '123') + self.assertEqual(PyUnicode_FromFormat(b'%zu', c_size_t(123)), '123') # test long output min_longlong = -(2 ** (8 * sizeof(c_longlong) - 1)) max_longlong = -min_longlong - 1 - check_format(str(min_longlong), - b'%lld', c_longlong(min_longlong)) - check_format(str(max_longlong), - b'%lld', c_longlong(max_longlong)) + self.assertEqual(PyUnicode_FromFormat(b'%lld', c_longlong(min_longlong)), str(min_longlong)) + self.assertEqual(PyUnicode_FromFormat(b'%lld', c_longlong(max_longlong)), str(max_longlong)) max_ulonglong = 2 ** (8 * sizeof(c_ulonglong)) - 1 - check_format(str(max_ulonglong), - b'%llu', c_ulonglong(max_ulonglong)) + self.assertEqual(PyUnicode_FromFormat(b'%llu', c_ulonglong(max_ulonglong)), str(max_ulonglong)) PyUnicode_FromFormat(b'%p', c_void_p(-1)) # test padding (width and/or precision) - check_format('123'.rjust(10, '0'), - b'%010i', c_int(123)) - check_format('123'.rjust(100), - b'%100i', c_int(123)) - check_format('123'.rjust(100, '0'), - b'%.100i', c_int(123)) - check_format('123'.rjust(80, '0').rjust(100), - b'%100.80i', c_int(123)) + self.assertEqual(PyUnicode_FromFormat(b'%010i', c_int(123)), '123'.rjust(10, '0')) + self.assertEqual(PyUnicode_FromFormat(b'%100i', c_int(123)), '123'.rjust(100)) + self.assertEqual(PyUnicode_FromFormat(b'%.100i', c_int(123)), '123'.rjust(100, '0')) + self.assertEqual(PyUnicode_FromFormat(b'%100.80i', c_int(123)), '123'.rjust(80, '0').rjust(100)) - check_format('123'.rjust(10, '0'), - b'%010u', c_uint(123)) - check_format('123'.rjust(100), - b'%100u', c_uint(123)) - check_format('123'.rjust(100, '0'), - b'%.100u', c_uint(123)) - check_format('123'.rjust(80, '0').rjust(100), - b'%100.80u', c_uint(123)) + self.assertEqual(PyUnicode_FromFormat(b'%010u', c_uint(123)), '123'.rjust(10, '0')) + self.assertEqual(PyUnicode_FromFormat(b'%100u', c_uint(123)), '123'.rjust(100)) + self.assertEqual(PyUnicode_FromFormat(b'%.100u', c_uint(123)), '123'.rjust(100, '0')) + self.assertEqual(PyUnicode_FromFormat(b'%100.80u', c_uint(123)), '123'.rjust(80, '0').rjust(100)) - check_format('123'.rjust(10, '0'), - b'%010x', c_int(0x123)) - check_format('123'.rjust(100), - b'%100x', c_int(0x123)) - check_format('123'.rjust(100, '0'), - b'%.100x', c_int(0x123)) - check_format('123'.rjust(80, '0').rjust(100), - b'%100.80x', c_int(0x123)) + self.assertEqual(PyUnicode_FromFormat(b'%010x', c_int(0x123)), '123'.rjust(10, '0')) + self.assertEqual(PyUnicode_FromFormat(b'%100x', c_int(0x123)), '123'.rjust(100)) + self.assertEqual(PyUnicode_FromFormat(b'%.100x', c_int(0x123)), '123'.rjust(100, '0')) + self.assertEqual(PyUnicode_FromFormat(b'%100.80x', c_int(0x123)), '123'.rjust(80, '0').rjust(100)) # test %A - check_format(r"%A:'abc\xe9\uabcd\U0010ffff'", - b'%%A:%A', 'abc\xe9\uabcd\U0010ffff') + text = PyUnicode_FromFormat(b'%%A:%A', 'abc\xe9\uabcd\U0010ffff') + self.assertEqual(text, r"%A:'abc\xe9\uabcd\U0010ffff'") # test %V - check_format('repr=abc', - b'repr=%V', 'abc', b'xyz') + text = PyUnicode_FromFormat(b'repr=%V', 'abc', b'xyz') + self.assertEqual(text, 'repr=abc') # Test string decode from parameter of %s using utf-8. # b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of # '\u4eba\u6c11' - check_format('repr=\u4eba\u6c11', - b'repr=%V', None, b'\xe4\xba\xba\xe6\xb0\x91') + text = PyUnicode_FromFormat(b'repr=%V', None, b'\xe4\xba\xba\xe6\xb0\x91') + self.assertEqual(text, 'repr=\u4eba\u6c11') #Test replace error handler. - check_format('repr=abc\ufffd', - b'repr=%V', None, b'abc\xff') + text = PyUnicode_FromFormat(b'repr=%V', None, b'abc\xff') + self.assertEqual(text, 'repr=abc\ufffd') # not supported: copy the raw format string. these tests are just here # to check for crashs and should not be considered as specifications - check_format('%s', - b'%1%s', b'abc') - check_format('%1abc', - b'%1abc') - check_format('%+i', - b'%+i', c_int(10)) - check_format('%.%s', - b'%.%s', b'abc') + self.assertEqual(PyUnicode_FromFormat(b'%1%s', b'abc'), '%s') + self.assertEqual(PyUnicode_FromFormat(b'%1abc'), '%1abc') + self.assertEqual(PyUnicode_FromFormat(b'%+i', c_int(10)), '%+i') + self.assertEqual(PyUnicode_FromFormat(b'%.%s', b'abc'), '%.%s') # Test PyUnicode_AsWideChar() def test_aswidechar(self): @@ -2358,97 +2191,6 @@ self.assertEqual(args[0], text) self.assertEqual(len(args), 1) - def test_resize(self): - for length in range(1, 100, 7): - # generate a fresh string (refcount=1) - text = 'a' * length + 'b' - - with support.check_warnings(('unicode_internal codec has been ' - 'deprecated', DeprecationWarning)): - # fill wstr internal field - abc = text.encode('unicode_internal') - self.assertEqual(abc.decode('unicode_internal'), text) - - # resize text: wstr field must be cleared and then recomputed - text += 'c' - abcdef = text.encode('unicode_internal') - self.assertNotEqual(abc, abcdef) - self.assertEqual(abcdef.decode('unicode_internal'), text) - - def test_compare(self): - # Issue #17615 - N = 10 - ascii = 'a' * N - ascii2 = 'z' * N - latin = '\x80' * N - latin2 = '\xff' * N - bmp = '\u0100' * N - bmp2 = '\uffff' * N - astral = '\U00100000' * N - astral2 = '\U0010ffff' * N - strings = ( - ascii, ascii2, - latin, latin2, - bmp, bmp2, - astral, astral2) - for text1, text2 in itertools.combinations(strings, 2): - equal = (text1 is text2) - self.assertEqual(text1 == text2, equal) - self.assertEqual(text1 != text2, not equal) - - if equal: - self.assertTrue(text1 <= text2) - self.assertTrue(text1 >= text2) - - # text1 is text2: duplicate strings to skip the "str1 == str2" - # optimization in unicode_compare_eq() and really compare - # character per character - copy1 = duplicate_string(text1) - copy2 = duplicate_string(text2) - self.assertIsNot(copy1, copy2) - - self.assertTrue(copy1 == copy2) - self.assertFalse(copy1 != copy2) - - self.assertTrue(copy1 <= copy2) - self.assertTrue(copy2 >= copy2) - - self.assertTrue(ascii < ascii2) - self.assertTrue(ascii < latin) - self.assertTrue(ascii < bmp) - self.assertTrue(ascii < astral) - self.assertFalse(ascii >= ascii2) - self.assertFalse(ascii >= latin) - self.assertFalse(ascii >= bmp) - self.assertFalse(ascii >= astral) - - self.assertFalse(latin < ascii) - self.assertTrue(latin < latin2) - self.assertTrue(latin < bmp) - self.assertTrue(latin < astral) - self.assertTrue(latin >= ascii) - self.assertFalse(latin >= latin2) - self.assertFalse(latin >= bmp) - self.assertFalse(latin >= astral) - - self.assertFalse(bmp < ascii) - self.assertFalse(bmp < latin) - self.assertTrue(bmp < bmp2) - self.assertTrue(bmp < astral) - self.assertTrue(bmp >= ascii) - self.assertTrue(bmp >= latin) - self.assertFalse(bmp >= bmp2) - self.assertFalse(bmp >= astral) - - self.assertFalse(astral < ascii) - self.assertFalse(astral < latin) - self.assertFalse(astral < bmp2) - self.assertTrue(astral < astral2) - self.assertTrue(astral >= ascii) - self.assertTrue(astral >= latin) - self.assertTrue(astral >= bmp2) - self.assertFalse(astral >= astral2) - class StringModuleTest(unittest.TestCase): def test_formatter_parser(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_univnewlines.py --- a/Lib/test/test_univnewlines.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_univnewlines.py Fri Feb 01 23:12:09 2013 +0100 @@ -30,13 +30,7 @@ DATA_MIXED = "\n".join(DATA_TEMPLATE) + "\r" DATA_SPLIT = [x + "\n" for x in DATA_TEMPLATE] -class CTest: - open = io.open - -class PyTest: - open = staticmethod(pyio.open) - -class TestGenericUnivNewlines: +class TestGenericUnivNewlines(unittest.TestCase): # use a class variable DATA to define the data to write to the file # and a class variable NEWLINE to set the expected newlines value READMODE = 'r' @@ -91,14 +85,10 @@ class TestCRNewlines(TestGenericUnivNewlines): NEWLINE = '\r' DATA = DATA_CR -class CTestCRNewlines(CTest, TestCRNewlines, unittest.TestCase): pass -class PyTestCRNewlines(PyTest, TestCRNewlines, unittest.TestCase): pass class TestLFNewlines(TestGenericUnivNewlines): NEWLINE = '\n' DATA = DATA_LF -class CTestLFNewlines(CTest, TestLFNewlines, unittest.TestCase): pass -class PyTestLFNewlines(PyTest, TestLFNewlines, unittest.TestCase): pass class TestCRLFNewlines(TestGenericUnivNewlines): NEWLINE = '\r\n' @@ -110,14 +100,29 @@ data = fp.readline() pos = fp.tell() self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) -class CTestCRLFNewlines(CTest, TestCRLFNewlines, unittest.TestCase): pass -class PyTestCRLFNewlines(PyTest, TestCRLFNewlines, unittest.TestCase): pass class TestMixedNewlines(TestGenericUnivNewlines): NEWLINE = ('\r', '\n') DATA = DATA_MIXED -class CTestMixedNewlines(CTest, TestMixedNewlines, unittest.TestCase): pass -class PyTestMixedNewlines(PyTest, TestMixedNewlines, unittest.TestCase): pass + + +def test_main(): + base_tests = (TestCRNewlines, + TestLFNewlines, + TestCRLFNewlines, + TestMixedNewlines) + tests = [] + # Test the C and Python implementations. + for test in base_tests: + class CTest(test): + open = io.open + CTest.__name__ = "C" + test.__name__ + class PyTest(test): + open = staticmethod(pyio.open) + PyTest.__name__ = "Py" + test.__name__ + tests.append(CTest) + tests.append(PyTest) + support.run_unittest(*tests) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_urllib.py Fri Feb 01 23:12:09 2013 +0100 @@ -11,12 +11,10 @@ import os import sys import tempfile -from nturl2path import url2pathname, pathname2url from base64 import b64encode import collections - def hexescape(char): """Escape char as RFC 2396 specifies""" hex_repr = hex(ord(char))[2:].upper() @@ -26,18 +24,13 @@ # Shortcut for testing FancyURLopener _urlopener = None - - def urlopen(url, data=None, proxies=None): """urlopen(url [, data]) -> open file-like object""" global _urlopener if proxies is not None: opener = urllib.request.FancyURLopener(proxies=proxies) elif not _urlopener: - with support.check_warnings( - ('FancyURLopener style of invoking requests is deprecated.', - DeprecationWarning)): - opener = urllib.request.FancyURLopener() + opener = urllib.request.FancyURLopener() _urlopener = opener else: opener = _urlopener @@ -1278,16 +1271,14 @@ class DummyURLopener(urllib.request.URLopener): def open_spam(self, url): return url - with support.check_warnings( - ('DummyURLopener style of invoking requests is deprecated.', - DeprecationWarning)): - self.assertEqual(DummyURLopener().open( - 'spam://example/ /'),'//example/%20/') - # test the safe characters are not quoted by urlopen - self.assertEqual(DummyURLopener().open( - "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"), - "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/") + self.assertEqual(DummyURLopener().open( + 'spam://example/ /'),'//example/%20/') + + # test the safe characters are not quoted by urlopen + self.assertEqual(DummyURLopener().open( + "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"), + "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/") # Just commented them out. # Can't really tell why keep failing in windows and sparc. @@ -1367,7 +1358,6 @@ # self.assertEqual(ftp.ftp.sock.gettimeout(), 30) # ftp.close() - class RequestTests(unittest.TestCase): """Unit tests for urllib.request.Request.""" @@ -1392,60 +1382,25 @@ self.assertEqual(request.get_method(), 'HEAD') -class URL2PathNameTests(unittest.TestCase): +def test_main(): + support.run_unittest( + urlopen_FileTests, + urlopen_HttpTests, + urlopen_DataTests, + urlretrieve_FileTests, + urlretrieve_HttpTests, + ProxyTests, + QuotingTests, + UnquotingTests, + urlencode_Tests, + Pathname_Tests, + Utility_Tests, + URLopener_Tests, + #FTPWrapperTests, + RequestTests, + ) - def test_converting_drive_letter(self): - self.assertEqual(url2pathname("///C|"), 'C:') - self.assertEqual(url2pathname("///C:"), 'C:') - self.assertEqual(url2pathname("///C|/"), 'C:\\') - def test_converting_when_no_drive_letter(self): - # cannot end a raw string in \ - self.assertEqual(url2pathname("///C/test/"), r'\\\C\test' '\\') - self.assertEqual(url2pathname("////C/test/"), r'\\C\test' '\\') - - def test_simple_compare(self): - self.assertEqual(url2pathname("///C|/foo/bar/spam.foo"), - r'C:\foo\bar\spam.foo') - - def test_non_ascii_drive_letter(self): - self.assertRaises(IOError, url2pathname, "///\u00e8|/") - - def test_roundtrip_url2pathname(self): - list_of_paths = ['C:', - r'\\\C\test\\', - r'C:\foo\bar\spam.foo' - ] - for path in list_of_paths: - self.assertEqual(url2pathname(pathname2url(path)), path) - -class PathName2URLTests(unittest.TestCase): - - def test_converting_drive_letter(self): - self.assertEqual(pathname2url("C:"), '///C:') - self.assertEqual(pathname2url("C:\\"), '///C:') - - def test_converting_when_no_drive_letter(self): - self.assertEqual(pathname2url(r"\\\folder\test" "\\"), - '/////folder/test/') - self.assertEqual(pathname2url(r"\\folder\test" "\\"), - '////folder/test/') - self.assertEqual(pathname2url(r"\folder\test" "\\"), - '/folder/test/') - - def test_simple_compare(self): - self.assertEqual(pathname2url(r'C:\foo\bar\spam.foo'), - "///C:/foo/bar/spam.foo" ) - - def test_long_drive_letter(self): - self.assertRaises(IOError, pathname2url, "XX:\\") - - def test_roundtrip_pathname2url(self): - list_of_paths = ['///C:', - '/////folder/test/', - '///C:/foo/bar/spam.foo'] - for path in list_of_paths: - self.assertEqual(pathname2url(url2pathname(path)), path) if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_urllib2.py Fri Feb 01 23:12:09 2013 +0100 @@ -11,7 +11,6 @@ # The proxy bypass method imported below has logic specific to the OSX # proxy config data structure but is testable on all platforms. from urllib.request import Request, OpenerDirector, _proxy_bypass_macosx_sysconf -from urllib.parse import urlparse import urllib.error # XXX @@ -51,7 +50,7 @@ f = urllib.request.urlopen(file_url) - f.read() + buf = f.read() f.close() def test_parse_http_list(self): @@ -65,170 +64,193 @@ for string, list in tests: self.assertEqual(urllib.request.parse_http_list(string), list) - def test_URLError_reasonstr(self): - err = urllib.error.URLError('reason') - self.assertIn(err.reason, str(err)) -class RequestHdrsTests(unittest.TestCase): +def test_request_headers_dict(): + """ + The Request.headers dictionary is not a documented interface. It should + stay that way, because the complete set of headers are only accessible + through the .get_header(), .has_header(), .header_items() interface. + However, .headers pre-dates those methods, and so real code will be using + the dictionary. - def test_request_headers_dict(self): - """ - The Request.headers dictionary is not a documented interface. It - should stay that way, because the complete set of headers are only - accessible through the .get_header(), .has_header(), .header_items() - interface. However, .headers pre-dates those methods, and so real code - will be using the dictionary. + The introduction in 2.4 of those methods was a mistake for the same reason: + code that previously saw all (urllib2 user)-provided headers in .headers + now sees only a subset (and the function interface is ugly and incomplete). + A better change would have been to replace .headers dict with a dict + subclass (or UserDict.DictMixin instance?) that preserved the .headers + interface and also provided access to the "unredirected" headers. It's + probably too late to fix that, though. - The introduction in 2.4 of those methods was a mistake for the same - reason: code that previously saw all (urllib2 user)-provided headers in - .headers now sees only a subset. - """ - url = "http://example.com" - self.assertEqual(Request(url, - headers={"Spam-eggs": "blah"} - ).headers["Spam-eggs"], "blah") - self.assertEqual(Request(url, - headers={"spam-EggS": "blah"} - ).headers["Spam-eggs"], "blah") + Check .capitalize() case normalization: - def test_request_headers_methods(self): - """ - Note the case normalization of header names here, to - .capitalize()-case. This should be preserved for - backwards-compatibility. (In the HTTP case, normalization to - .title()-case is done by urllib2 before sending headers to - http.client). + >>> url = "http://example.com" + >>> Request(url, headers={"Spam-eggs": "blah"}).headers["Spam-eggs"] + 'blah' + >>> Request(url, headers={"spam-EggS": "blah"}).headers["Spam-eggs"] + 'blah' - Note that e.g. r.has_header("spam-EggS") is currently False, and - r.get_header("spam-EggS") returns None, but that could be changed in - future. + Currently, Request(url, "Spam-eggs").headers["Spam-Eggs"] raises KeyError, + but that could be changed in future. - Method r.remove_header should remove items both from r.headers and - r.unredirected_hdrs dictionaries - """ - url = "http://example.com" - req = Request(url, headers={"Spam-eggs": "blah"}) - self.assertTrue(req.has_header("Spam-eggs")) - self.assertEqual(req.header_items(), [('Spam-eggs', 'blah')]) + """ - req.add_header("Foo-Bar", "baz") - self.assertEqual(sorted(req.header_items()), - [('Foo-bar', 'baz'), ('Spam-eggs', 'blah')]) - self.assertFalse(req.has_header("Not-there")) - self.assertIsNone(req.get_header("Not-there")) - self.assertEqual(req.get_header("Not-there", "default"), "default") +def test_request_headers_methods(): + """ + Note the case normalization of header names here, to .capitalize()-case. + This should be preserved for backwards-compatibility. (In the HTTP case, + normalization to .title()-case is done by urllib2 before sending headers to + http.client). - req.remove_header("Spam-eggs") - self.assertFalse(req.has_header("Spam-eggs")) + >>> url = "http://example.com" + >>> r = Request(url, headers={"Spam-eggs": "blah"}) + >>> r.has_header("Spam-eggs") + True + >>> r.header_items() + [('Spam-eggs', 'blah')] + >>> r.add_header("Foo-Bar", "baz") + >>> items = sorted(r.header_items()) + >>> items + [('Foo-bar', 'baz'), ('Spam-eggs', 'blah')] - req.add_unredirected_header("Unredirected-spam", "Eggs") - self.assertTrue(req.has_header("Unredirected-spam")) + Note that e.g. r.has_header("spam-EggS") is currently False, and + r.get_header("spam-EggS") returns None, but that could be changed in + future. - req.remove_header("Unredirected-spam") - self.assertFalse(req.has_header("Unredirected-spam")) + >>> r.has_header("Not-there") + False + >>> print(r.get_header("Not-there")) + None + >>> r.get_header("Not-there", "default") + 'default' + Method r.remove_header should remove items both from r.headers and + r.unredirected_hdrs dictionaries - def test_password_manager(self): - mgr = urllib.request.HTTPPasswordMgr() - add = mgr.add_password - find_user_pass = mgr.find_user_password - add("Some Realm", "http://example.com/", "joe", "password") - add("Some Realm", "http://example.com/ni", "ni", "ni") - add("c", "http://example.com/foo", "foo", "ni") - add("c", "http://example.com/bar", "bar", "nini") - add("b", "http://example.com/", "first", "blah") - add("b", "http://example.com/", "second", "spam") - add("a", "http://example.com", "1", "a") - add("Some Realm", "http://c.example.com:3128", "3", "c") - add("Some Realm", "d.example.com", "4", "d") - add("Some Realm", "e.example.com:3128", "5", "e") + >>> r.remove_header("Spam-eggs") + >>> r.has_header("Spam-eggs") + False + >>> r.add_unredirected_header("Unredirected-spam", "Eggs") + >>> r.has_header("Unredirected-spam") + True + >>> r.remove_header("Unredirected-spam") + >>> r.has_header("Unredirected-spam") + False - self.assertEqual(find_user_pass("Some Realm", "example.com"), - ('joe', 'password')) + """ - #self.assertEqual(find_user_pass("Some Realm", "http://example.com/ni"), - # ('ni', 'ni')) - self.assertEqual(find_user_pass("Some Realm", "http://example.com"), - ('joe', 'password')) - self.assertEqual(find_user_pass("Some Realm", "http://example.com/"), - ('joe', 'password')) - self.assertEqual( - find_user_pass("Some Realm", "http://example.com/spam"), - ('joe', 'password')) - self.assertEqual( - find_user_pass("Some Realm", "http://example.com/spam/spam"), - ('joe', 'password')) - self.assertEqual(find_user_pass("c", "http://example.com/foo"), - ('foo', 'ni')) - self.assertEqual(find_user_pass("c", "http://example.com/bar"), - ('bar', 'nini')) - self.assertEqual(find_user_pass("b", "http://example.com/"), - ('second', 'spam')) +def test_password_manager(self): + """ + >>> mgr = urllib.request.HTTPPasswordMgr() + >>> add = mgr.add_password + >>> add("Some Realm", "http://example.com/", "joe", "password") + >>> add("Some Realm", "http://example.com/ni", "ni", "ni") + >>> add("c", "http://example.com/foo", "foo", "ni") + >>> add("c", "http://example.com/bar", "bar", "nini") + >>> add("b", "http://example.com/", "first", "blah") + >>> add("b", "http://example.com/", "second", "spam") + >>> add("a", "http://example.com", "1", "a") + >>> add("Some Realm", "http://c.example.com:3128", "3", "c") + >>> add("Some Realm", "d.example.com", "4", "d") + >>> add("Some Realm", "e.example.com:3128", "5", "e") - # No special relationship between a.example.com and example.com: + >>> mgr.find_user_password("Some Realm", "example.com") + ('joe', 'password') + >>> mgr.find_user_password("Some Realm", "http://example.com") + ('joe', 'password') + >>> mgr.find_user_password("Some Realm", "http://example.com/") + ('joe', 'password') + >>> mgr.find_user_password("Some Realm", "http://example.com/spam") + ('joe', 'password') + >>> mgr.find_user_password("Some Realm", "http://example.com/spam/spam") + ('joe', 'password') + >>> mgr.find_user_password("c", "http://example.com/foo") + ('foo', 'ni') + >>> mgr.find_user_password("c", "http://example.com/bar") + ('bar', 'nini') - self.assertEqual(find_user_pass("a", "http://example.com/"), - ('1', 'a')) - self.assertEqual(find_user_pass("a", "http://a.example.com/"), - (None, None)) + Actually, this is really undefined ATM +## Currently, we use the highest-level path where more than one match: - # Ports: +## >>> mgr.find_user_password("Some Realm", "http://example.com/ni") +## ('joe', 'password') - self.assertEqual(find_user_pass("Some Realm", "c.example.com"), - (None, None)) - self.assertEqual(find_user_pass("Some Realm", "c.example.com:3128"), - ('3', 'c')) - self.assertEqual( - find_user_pass("Some Realm", "http://c.example.com:3128"), - ('3', 'c')) - self.assertEqual(find_user_pass("Some Realm", "d.example.com"), - ('4', 'd')) - self.assertEqual(find_user_pass("Some Realm", "e.example.com:3128"), - ('5', 'e')) + Use latest add_password() in case of conflict: - def test_password_manager_default_port(self): - """ - The point to note here is that we can't guess the default port if - there's no scheme. This applies to both add_password and - find_user_password. - """ - mgr = urllib.request.HTTPPasswordMgr() - add = mgr.add_password - find_user_pass = mgr.find_user_password - add("f", "http://g.example.com:80", "10", "j") - add("g", "http://h.example.com", "11", "k") - add("h", "i.example.com:80", "12", "l") - add("i", "j.example.com", "13", "m") - self.assertEqual(find_user_pass("f", "g.example.com:100"), - (None, None)) - self.assertEqual(find_user_pass("f", "g.example.com:80"), - ('10', 'j')) - self.assertEqual(find_user_pass("f", "g.example.com"), - (None, None)) - self.assertEqual(find_user_pass("f", "http://g.example.com:100"), - (None, None)) - self.assertEqual(find_user_pass("f", "http://g.example.com:80"), - ('10', 'j')) - self.assertEqual(find_user_pass("f", "http://g.example.com"), - ('10', 'j')) - self.assertEqual(find_user_pass("g", "h.example.com"), ('11', 'k')) - self.assertEqual(find_user_pass("g", "h.example.com:80"), ('11', 'k')) - self.assertEqual(find_user_pass("g", "http://h.example.com:80"), - ('11', 'k')) - self.assertEqual(find_user_pass("h", "i.example.com"), (None, None)) - self.assertEqual(find_user_pass("h", "i.example.com:80"), ('12', 'l')) - self.assertEqual(find_user_pass("h", "http://i.example.com:80"), - ('12', 'l')) - self.assertEqual(find_user_pass("i", "j.example.com"), ('13', 'm')) - self.assertEqual(find_user_pass("i", "j.example.com:80"), - (None, None)) - self.assertEqual(find_user_pass("i", "http://j.example.com"), - ('13', 'm')) - self.assertEqual(find_user_pass("i", "http://j.example.com:80"), - (None, None)) + >>> mgr.find_user_password("b", "http://example.com/") + ('second', 'spam') + No special relationship between a.example.com and example.com: + + >>> mgr.find_user_password("a", "http://example.com/") + ('1', 'a') + >>> mgr.find_user_password("a", "http://a.example.com/") + (None, None) + + Ports: + + >>> mgr.find_user_password("Some Realm", "c.example.com") + (None, None) + >>> mgr.find_user_password("Some Realm", "c.example.com:3128") + ('3', 'c') + >>> mgr.find_user_password("Some Realm", "http://c.example.com:3128") + ('3', 'c') + >>> mgr.find_user_password("Some Realm", "d.example.com") + ('4', 'd') + >>> mgr.find_user_password("Some Realm", "e.example.com:3128") + ('5', 'e') + + """ + pass + + +def test_password_manager_default_port(self): + """ + >>> mgr = urllib.request.HTTPPasswordMgr() + >>> add = mgr.add_password + + The point to note here is that we can't guess the default port if there's + no scheme. This applies to both add_password and find_user_password. + + >>> add("f", "http://g.example.com:80", "10", "j") + >>> add("g", "http://h.example.com", "11", "k") + >>> add("h", "i.example.com:80", "12", "l") + >>> add("i", "j.example.com", "13", "m") + >>> mgr.find_user_password("f", "g.example.com:100") + (None, None) + >>> mgr.find_user_password("f", "g.example.com:80") + ('10', 'j') + >>> mgr.find_user_password("f", "g.example.com") + (None, None) + >>> mgr.find_user_password("f", "http://g.example.com:100") + (None, None) + >>> mgr.find_user_password("f", "http://g.example.com:80") + ('10', 'j') + >>> mgr.find_user_password("f", "http://g.example.com") + ('10', 'j') + >>> mgr.find_user_password("g", "h.example.com") + ('11', 'k') + >>> mgr.find_user_password("g", "h.example.com:80") + ('11', 'k') + >>> mgr.find_user_password("g", "http://h.example.com:80") + ('11', 'k') + >>> mgr.find_user_password("h", "i.example.com") + (None, None) + >>> mgr.find_user_password("h", "i.example.com:80") + ('12', 'l') + >>> mgr.find_user_password("h", "http://i.example.com:80") + ('12', 'l') + >>> mgr.find_user_password("i", "j.example.com") + ('13', 'm') + >>> mgr.find_user_password("i", "j.example.com:80") + (None, None) + >>> mgr.find_user_password("i", "http://j.example.com") + ('13', 'm') + >>> mgr.find_user_password("i", "http://j.example.com:80") + (None, None) + + """ class MockOpener: addheaders = [] @@ -321,6 +343,7 @@ if body: self.data = body if self.raise_on_endheaders: + import socket raise OSError() def getresponse(self): return MockHTTPResponse(MockFile(), {}, 200, "OK") @@ -422,6 +445,7 @@ self.requests = [] def http_open(self, req): import email, http.client, copy + from io import StringIO self.requests.append(copy.deepcopy(req)) if self._count == 0: self._count = self._count + 1 @@ -481,7 +505,7 @@ [("do_open", "return self"), ("proxy_open", "return self")], [("redirect_request", "return self")], ] - add_ordered_mock_handlers(o, meth_spec) + handlers = add_ordered_mock_handlers(o, meth_spec) o.add_handler(urllib.request.UnknownHandler()) for scheme in "do", "proxy", "redirect": self.assertRaises(URLError, o.open, scheme+"://example.com/") @@ -525,7 +549,7 @@ handlers.append(h) o.add_handler(h) - o.open("http://example.com/") + r = o.open("http://example.com/") # handlers called in reverse order, thanks to their sort order self.assertEqual(o.calls[0][0], handlers[1]) self.assertEqual(o.calls[1][0], handlers[0]) @@ -560,7 +584,7 @@ def __eq__(self, other): return True req = Request("http://example.com/") - o.open(req) + r = o.open(req) assert len(o.calls) == 2 calls = [(handlers[0], "http_open", (req,)), (handlers[2], "http_error_302", @@ -583,7 +607,7 @@ handlers = add_ordered_mock_handlers(o, meth_spec) req = Request("http://example.com/") - o.open(req) + r = o.open(req) # processor methods are called on *all* handlers that define them, # not just the first handler that handles the request calls = [ @@ -606,6 +630,27 @@ self.assertTrue(args[1] is None or isinstance(args[1], MockResponse)) + def test_method_deprecations(self): + req = Request("http://www.example.com") + + with self.assertWarns(DeprecationWarning): + req.add_data("data") + with self.assertWarns(DeprecationWarning): + req.get_data() + with self.assertWarns(DeprecationWarning): + req.has_data() + with self.assertWarns(DeprecationWarning): + req.get_host() + with self.assertWarns(DeprecationWarning): + req.get_selector() + with self.assertWarns(DeprecationWarning): + req.is_unverifiable() + with self.assertWarns(DeprecationWarning): + req.get_origin_req_host() + with self.assertWarns(DeprecationWarning): + req.get_type() + + def sanepathname2url(path): try: path.encode("utf-8") @@ -640,7 +685,7 @@ import ftplib data = "rheum rhaponicum" h = NullFTPHandler(data) - h.parent = MockOpener() + o = h.parent = MockOpener() for url, host, port, user, passwd, type_, dirs, filename, mimetype in [ ("ftp://localhost/foo/bar/baz.html", @@ -883,7 +928,7 @@ # break anything. Previously, a double slash directly after the host # could cause incorrect parsing. h = urllib.request.AbstractHTTPHandler() - h.parent = MockOpener() + o = h.parent = MockOpener() data = b"" ds_urls = [ @@ -905,42 +950,12 @@ p_ds_req = h.do_request_(ds_req) self.assertEqual(p_ds_req.unredirected_hdrs["Host"],"example.com") - def test_full_url_setter(self): - # Checks to ensure that components are set correctly after setting the - # full_url of a Request object - - urls = [ - 'http://example.com?foo=bar#baz', - 'http://example.com?foo=bar&spam=eggs#bash', - 'http://example.com', - ] - - # testing a reusable request instance, but the url parameter is - # required, so just use a dummy one to instantiate - r = Request('http://example.com') - for url in urls: - r.full_url = url - parsed = urlparse(url) - - self.assertEqual(r.get_full_url(), url) - # full_url setter uses splittag to split into components. - # splittag sets the fragment as None while urlparse sets it to '' - self.assertEqual(r.fragment or '', parsed.fragment) - self.assertEqual(urlparse(r.get_full_url()).query, parsed.query) - - def test_full_url_deleter(self): - r = Request('http://www.example.com') - del r.full_url - self.assertIsNone(r.full_url) - self.assertIsNone(r.fragment) - self.assertEqual(r.selector, '') - def test_fixpath_in_weirdurls(self): # Issue4493: urllib2 to supply '/' when to urls where path does not # start with'/' h = urllib.request.AbstractHTTPHandler() - h.parent = MockOpener() + o = h.parent = MockOpener() weird_url = 'http://www.python.org?getspam' req = Request(weird_url) @@ -983,7 +998,7 @@ def test_cookies(self): cj = MockCookieJar() h = urllib.request.HTTPCookieProcessor(cj) - h.parent = MockOpener() + o = h.parent = MockOpener() req = Request("http://example.com/") r = MockResponse(200, "OK", {}, "") @@ -1140,7 +1155,7 @@ req = Request("http://acme.example.com/") self.assertEqual(req.host, "acme.example.com") - o.open(req) + r = o.open(req) self.assertEqual(req.host, "proxy.example.com:3128") self.assertEqual([(handlers[0], "http_open")], @@ -1153,11 +1168,11 @@ o.add_handler(ph) req = Request("http://www.perl.org/") self.assertEqual(req.host, "www.perl.org") - o.open(req) + r = o.open(req) self.assertEqual(req.host, "proxy.example.com") req = Request("http://www.python.org") self.assertEqual(req.host, "www.python.org") - o.open(req) + r = o.open(req) self.assertEqual(req.host, "www.python.org") del os.environ['no_proxy'] @@ -1168,7 +1183,7 @@ o.add_handler(ph) req = Request("http://www.python.org") self.assertEqual(req.host, "www.python.org") - o.open(req) + r = o.open(req) self.assertEqual(req.host, "www.python.org") del os.environ['no_proxy'] @@ -1184,7 +1199,7 @@ req = Request("https://www.example.com/") self.assertEqual(req.host, "www.example.com") - o.open(req) + r = o.open(req) self.assertEqual(req.host, "proxy.example.com:3128") self.assertEqual([(handlers[0], "https_open")], [tup[0:2] for tup in o.calls]) @@ -1200,7 +1215,7 @@ req.add_header("User-Agent","Grail") self.assertEqual(req.host, "www.example.com") self.assertIsNone(req._tunnel_host) - o.open(req) + r = o.open(req) # Verify Proxy-Authorization gets tunneled to request. # httpsconn req_headers do not have the Proxy-Authorization header but # the req will have. @@ -1366,7 +1381,7 @@ self.assertEqual(user, password_manager.user) self.assertEqual(password, password_manager.password) - opener.open(request_url) + r = opener.open(request_url) # should have asked the password manager for the username/password self.assertEqual(password_manager.target_realm, realm) @@ -1386,17 +1401,13 @@ # handle the HTTP auth error password_manager.user = password_manager.password = None http_handler.reset() - opener.open(request_url) + r = opener.open(request_url) self.assertEqual(len(http_handler.requests), 1) self.assertFalse(http_handler.requests[0].has_header(auth_header)) class MiscTests(unittest.TestCase): - def opener_has_handler(self, opener, handler_class): - self.assertTrue(any(h.__class__ == handler_class - for h in opener.handlers)) - def test_build_opener(self): class MyHTTPHandler(urllib.request.HTTPHandler): pass class FooHandler(urllib.request.BaseHandler): @@ -1434,8 +1445,6 @@ self.opener_has_handler(o, MyHTTPHandler) self.opener_has_handler(o, MyOtherHTTPHandler) - @unittest.skipUnless(support.is_resource_enabled('network'), - 'test requires network access') def test_issue16464(self): opener = urllib.request.build_opener() request = urllib.request.Request("http://www.python.org/~jeremy/") @@ -1449,21 +1458,10 @@ self.assertEqual(b"1234567890", request.data) self.assertEqual("10", request.get_header("Content-length")) - def test_HTTPError_interface(self): - """ - Issue 13211 reveals that HTTPError didn't implement the URLError - interface even though HTTPError is a subclass of URLError. - """ - msg = 'something bad happened' - url = code = fp = None - hdrs = 'Content-Length: 42' - err = urllib.error.HTTPError(url, code, msg, hdrs, fp) - self.assertTrue(hasattr(err, 'reason')) - self.assertEqual(err.reason, 'something bad happened') - self.assertTrue(hasattr(err, 'headers')) - self.assertEqual(err.headers, 'Content-Length: 42') - expected_errmsg = 'HTTP Error %s: %s' % (err.code, err.msg) - self.assertEqual(str(err), expected_errmsg) + + def opener_has_handler(self, opener, handler_class): + self.assertTrue(any(h.__class__ == handler_class + for h in opener.handlers)) class RequestTests(unittest.TestCase): @@ -1488,20 +1486,11 @@ # if we change data we need to remove content-length header # (cause it's most probably calculated for previous value) def test_setting_data_should_remove_content_length(self): - self.assertNotIn("Content-length", self.get.unredirected_hdrs) + self.assertFalse("Content-length" in self.get.unredirected_hdrs) self.get.add_unredirected_header("Content-length", 42) self.assertEqual(42, self.get.unredirected_hdrs["Content-length"]) self.get.data = "spam" - self.assertNotIn("Content-length", self.get.unredirected_hdrs) - - # issue 17485 same for deleting data. - def test_deleting_data_should_remove_content_length(self): - self.assertNotIn("Content-length", self.get.unredirected_hdrs) - self.get.data = 'foo' - self.get.add_unredirected_header("Content-length", 3) - self.assertEqual(3, self.get.unredirected_hdrs["Content-length"]) - del self.get.data - self.assertNotIn("Content-length", self.get.unredirected_hdrs) + self.assertFalse("Content-length" in self.get.unredirected_hdrs) def test_get_full_url(self): self.assertEqual("http://www.python.org/~jeremy/", @@ -1544,13 +1533,22 @@ req = Request(url) self.assertEqual(req.get_full_url(), url) - def test_url_fullurl_get_full_url(self): - urls = ['http://docs.python.org', - 'http://docs.python.org/library/urllib2.html#OK', - 'http://www.python.org/?qs=query#fragment=true' ] - for url in urls: - req = Request(url) - self.assertEqual(req.get_full_url(), req.full_url) +def test_HTTPError_interface(): + """ + Issue 13211 reveals that HTTPError didn't implement the URLError + interface even though HTTPError is a subclass of URLError. + + >>> msg = 'something bad happened' + >>> url = code = fp = None + >>> hdrs = 'Content-Length: 42' + >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) + >>> assert hasattr(err, 'reason') + >>> err.reason + 'something bad happened' + >>> assert hasattr(err, 'headers') + >>> err.headers + 'Content-Length: 42' + """ def test_main(verbose=None): from test import test_urllib2 @@ -1560,8 +1558,7 @@ OpenerDirectorTests, HandlerTests, MiscTests, - RequestTests, - RequestHdrsTests) + RequestTests) support.run_unittest(*tests) if __name__ == "__main__": diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_urllib2_localnet.py --- a/Lib/test/test_urllib2_localnet.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_urllib2_localnet.py Fri Feb 01 23:12:09 2013 +0100 @@ -9,10 +9,7 @@ import hashlib from test import support threading = support.import_module('threading') -try: - import ssl -except ImportError: - ssl = None + here = os.path.dirname(__file__) # Self-signed cert file for 'localhost' @@ -20,7 +17,6 @@ # Self-signed cert file for 'fakehostname' CERT_fakehostname = os.path.join(here, 'keycert2.pem') - # Loopback http server infrastructure class LoopbackHttpServer(http.server.HTTPServer): @@ -357,15 +353,12 @@ def setUp(self): super(TestUrlopen, self).setUp() # Ignore proxies for localhost tests. - self.old_environ = os.environ.copy() os.environ['NO_PROXY'] = '*' self.server = None def tearDown(self): if self.server is not None: self.server.stop() - os.environ.clear() - os.environ.update(self.old_environ) super(TestUrlopen, self).tearDown() def urlopen(self, url, data=None, **kwargs): @@ -393,14 +386,14 @@ handler.port = port return handler - def start_https_server(self, responses=None, **kwargs): + def start_https_server(self, responses=None, certfile=CERT_localhost): if not hasattr(urllib.request, 'HTTPSHandler'): self.skipTest('ssl support required') from test.ssl_servers import make_https_server if responses is None: responses = [(200, [], b"we care a bit")] handler = GetRequestHandler(responses) - server = make_https_server(self, handler_class=handler, **kwargs) + server = make_https_server(self, certfile=certfile, handler_class=handler) handler.port = server.port return handler @@ -490,21 +483,6 @@ self.urlopen("https://localhost:%s/bizarre" % handler.port, cadefault=True) - def test_https_sni(self): - if ssl is None: - self.skipTest("ssl module required") - if not ssl.HAS_SNI: - self.skipTest("SNI support required in OpenSSL") - sni_name = None - def cb_sni(ssl_sock, server_name, initial_context): - nonlocal sni_name - sni_name = server_name - context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) - context.set_servername_callback(cb_sni) - handler = self.start_https_server(context=context, certfile=CERT_localhost) - self.urlopen("https://localhost:%s" % handler.port) - self.assertEqual(sni_name, "localhost") - def test_sending_headers(self): handler = self.start_server() req = urllib.request.Request("http://localhost:%s/" % handler.port, @@ -546,11 +524,6 @@ def test_bad_address(self): # Make sure proper exception is raised when connecting to a bogus # address. - - # as indicated by the comment below, this might fail with some ISP, - # so we run the test only when -unetwork/-uall is specified to - # mitigate the problem a bit (see #17564) - support.requires('network') self.assertRaises(OSError, # Given that both VeriSign and various ISPs have in # the past or are presently hijacking various invalid diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_urllib2net.py --- a/Lib/test/test_urllib2net.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_urllib2net.py Fri Feb 01 23:12:09 2013 +0100 @@ -164,14 +164,6 @@ self.assertEqual(res.geturl(), "http://docs.python.org/2/glossary.html#glossary") - def test_redirect_url_withfrag(self): - redirect_url_with_frag = "http://bitly.com/urllibredirecttest" - with support.transient_internet(redirect_url_with_frag): - req = urllib.request.Request(redirect_url_with_frag) - res = urllib.request.urlopen(req) - self.assertEqual(res.geturl(), - "http://docs.python.org/3.4/glossary.html#term-global-interpreter-lock") - def test_custom_headers(self): url = "http://www.example.com" with support.transient_internet(url): @@ -338,6 +330,35 @@ self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60) +@unittest.skipUnless(ssl, "requires SSL support") +class HTTPSTests(unittest.TestCase): + + def test_sni(self): + self.skipTest("test disabled - test server needed") + # Checks that Server Name Indication works, if supported by the + # OpenSSL linked to. + # The ssl module itself doesn't have server-side support for SNI, + # so we rely on a third-party test site. + expect_sni = ssl.HAS_SNI + with support.transient_internet("XXX"): + u = urllib.request.urlopen("XXX") + contents = u.readall() + if expect_sni: + self.assertIn(b"Great", contents) + self.assertNotIn(b"Unfortunately", contents) + else: + self.assertNotIn(b"Great", contents) + self.assertIn(b"Unfortunately", contents) + + +def test_main(): + support.requires("network") + support.run_unittest(AuthTests, + HTTPSTests, + OtherNetworkTests, + CloseSocketTest, + TimeoutTest, + ) + if __name__ == "__main__": - support.requires("network") - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_urllibnet.py --- a/Lib/test/test_urllibnet.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_urllibnet.py Fri Feb 01 23:12:09 2013 +0100 @@ -116,10 +116,7 @@ bogus_domain = "sadflkjsasf.i.nvali.d" try: socket.gethostbyname(bogus_domain) - except OSError: - # socket.gaierror is too narrow, since getaddrinfo() may also - # fail with EAI_SYSTEM and ETIMEDOUT (seen on Ubuntu 13.04), - # i.e. Python's TimeoutError. + except socket.gaierror: pass else: # This happens with some overzealous DNS providers such as OpenDNS diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_urlparse.py Fri Feb 01 23:12:09 2013 +0100 @@ -847,14 +847,6 @@ self.assertEqual(p1.path, '863-1234') self.assertEqual(p1.params, 'phone-context=+1-914-555') - def test_unwrap(self): - url = urllib.parse.unwrap('') - self.assertEqual(url, 'type://host/path') - - def test_Quoter_repr(self): - quoter = urllib.parse.Quoter(urllib.parse._ALWAYS_SAFE) - self.assertIn('Quoter', repr(quoter)) - def test_main(): support.run_unittest(UrlParseTestCase) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_uuid.py --- a/Lib/test/test_uuid.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_uuid.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,6 @@ -import unittest +from unittest import TestCase +from test import support import builtins -import os import uuid def importable(name): @@ -10,7 +10,7 @@ except: return False -class TestUUID(unittest.TestCase): +class TestUUID(TestCase): last_node = None source2node = {} @@ -310,22 +310,24 @@ else: TestUUID.last_node = node - @unittest.skipUnless(os.name == 'posix', 'requires Posix') def test_ifconfig_getnode(self): - node = uuid._ifconfig_getnode() - if node is not None: - self.check_node(node, 'ifconfig') + import sys + import os + if os.name == 'posix': + node = uuid._ifconfig_getnode() + if node is not None: + self.check_node(node, 'ifconfig') - @unittest.skipUnless(os.name == 'nt', 'requires Windows') def test_ipconfig_getnode(self): - node = uuid._ipconfig_getnode() - if node is not None: - self.check_node(node, 'ipconfig') + import os + if os.name == 'nt': + node = uuid._ipconfig_getnode() + if node is not None: + self.check_node(node, 'ipconfig') - @unittest.skipUnless(importable('win32wnet'), 'requires win32wnet') - @unittest.skipUnless(importable('netbios'), 'requires netbios') def test_netbios_getnode(self): - self.check_node(uuid._netbios_getnode(), 'netbios') + if importable('win32wnet') and importable('netbios'): + self.check_node(uuid._netbios_getnode(), 'netbios') def test_random_getnode(self): node = uuid._random_getnode() @@ -333,20 +335,22 @@ self.assertTrue(node & 0x010000000000) self.assertTrue(node < (1 << 48)) - @unittest.skipUnless(os.name == 'posix', 'requires Posix') - @unittest.skipUnless(importable('ctypes'), 'requires ctypes') def test_unixdll_getnode(self): - try: # Issues 1481, 3581: _uuid_generate_time() might be None. - self.check_node(uuid._unixdll_getnode(), 'unixdll') - except TypeError: - pass + import sys + import os + if importable('ctypes') and os.name == 'posix': + try: # Issues 1481, 3581: _uuid_generate_time() might be None. + self.check_node(uuid._unixdll_getnode(), 'unixdll') + except TypeError: + pass - @unittest.skipUnless(os.name == 'nt', 'requires Windows') - @unittest.skipUnless(importable('ctypes'), 'requires ctypes') def test_windll_getnode(self): - self.check_node(uuid._windll_getnode(), 'windll') + import os + if importable('ctypes') and os.name == 'nt': + self.check_node(uuid._windll_getnode(), 'windll') def test_getnode(self): + import sys node1 = uuid.getnode() self.check_node(node1, "getnode1") @@ -356,8 +360,13 @@ self.assertEqual(node1, node2) - @unittest.skipUnless(importable('ctypes'), 'requires ctypes') def test_uuid1(self): + # uuid1 requires ctypes. + try: + import ctypes + except ImportError: + return + equal = self.assertEqual # Make sure uuid1() generates UUIDs that are actually version 1. @@ -410,8 +419,13 @@ equal(u, uuid.UUID(v)) equal(str(u), v) - @unittest.skipUnless(importable('ctypes'), 'requires ctypes') def test_uuid4(self): + # uuid4 requires ctypes. + try: + import ctypes + except ImportError: + return + equal = self.assertEqual # Make sure uuid4() generates UUIDs that are actually version 4. @@ -443,8 +457,12 @@ equal(u, uuid.UUID(v)) equal(str(u), v) - @unittest.skipUnless(os.name == 'posix', 'requires Posix') def testIssue8621(self): + import os + import sys + if os.name != 'posix': + return + # On at least some versions of OSX uuid.uuid4 generates # the same sequence of UUIDs in the parent and any # children started using fork. @@ -458,7 +476,6 @@ else: os.close(fds[1]) - self.addCleanup(os.close, fds[0]) parent_value = uuid.uuid4().hex os.waitpid(pid, 0) child_value = os.read(fds[0], 100).decode('latin-1') @@ -466,5 +483,11 @@ self.assertNotEqual(parent_value, child_value) + + + +def test_main(): + support.run_unittest(TestUUID) + if __name__ == '__main__': - unittest.main() + test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_venv.py --- a/Lib/test/test_venv.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_venv.py Fri Feb 01 23:12:09 2013 +0100 @@ -23,10 +23,12 @@ self.env_dir = os.path.realpath(tempfile.mkdtemp()) if os.name == 'nt': self.bindir = 'Scripts' + self.pydocname = 'pydoc.py' self.lib = ('Lib',) self.include = 'Include' else: self.bindir = 'bin' + self.pydocname = 'pydoc' self.lib = ('lib', 'python%s' % sys.version[:3]) self.include = 'include' if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in os.environ: @@ -76,6 +78,8 @@ executable = sys.executable path = os.path.dirname(executable) self.assertIn('home = %s' % path, data) + data = self.get_text_file_contents(self.bindir, self.pydocname) + self.assertTrue(data.startswith('#!%s%s' % (self.env_dir, os.sep))) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_wait4.py --- a/Lib/test/test_wait4.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_wait4.py Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,6 @@ import os import time -import sys from test.fork_wait import ForkWait from test.support import run_unittest, reap_children, get_attribute @@ -14,15 +13,10 @@ class Wait4Test(ForkWait): def wait_impl(self, cpid): - option = os.WNOHANG - if sys.platform.startswith('aix'): - # Issue #11185: wait4 is broken on AIX and will always return 0 - # with WNOHANG. - option = 0 for i in range(10): # wait4() shouldn't hang, but some of the buildbots seem to hang # in the forking tests. This is an attempt to fix the problem. - spid, status, rusage = os.wait4(cpid, option) + spid, status, rusage = os.wait4(cpid, os.WNOHANG) if spid == cpid: break time.sleep(1.0) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_wave.py --- a/Lib/test/test_wave.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_wave.py Fri Feb 01 23:12:09 2013 +0100 @@ -58,22 +58,6 @@ output = b'\0' * nframes * nchannels * sampwidth self.f.writeframes(output) - def test_getparams(self): - self.f = wave.open(TESTFN, 'wb') - self.f.setnchannels(nchannels) - self.f.setsampwidth(sampwidth) - self.f.setframerate(framerate) - self.f.close() - - self.f = wave.open(TESTFN, 'rb') - params = self.f.getparams() - self.assertEqual(params.nchannels, self.f.getnchannels()) - self.assertEqual(params.nframes, self.f.getnframes()) - self.assertEqual(params.sampwidth, self.f.getsampwidth()) - self.assertEqual(params.framerate, self.f.getframerate()) - self.assertEqual(params.comptype, self.f.getcomptype()) - self.assertEqual(params.compname, self.f.getcompname()) - def test_main(): run_unittest(TestWave) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_weakref.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,15 +7,11 @@ import contextlib import copy -from test import support, script_helper +from test import support # Used in ReferencesTestCase.test_ref_created_during_del() . ref_from_del = None -# Used by FinalizeTestCase as a global that may be replaced by None -# when the interpreter shuts down. -_global_var = 'foobar' - class C: def method(self): pass @@ -806,30 +802,6 @@ del root gc.collect() - def test_callback_attribute(self): - x = Object(1) - callback = lambda ref: None - ref1 = weakref.ref(x, callback) - self.assertIs(ref1.__callback__, callback) - - ref2 = weakref.ref(x) - self.assertIsNone(ref2.__callback__) - - def test_callback_attribute_after_deletion(self): - x = Object(1) - ref = weakref.ref(x, self.callback) - self.assertIsNotNone(ref.__callback__) - del x - support.gc_collect() - self.assertIsNone(ref.__callback__) - - def test_set_callback_attribute(self): - x = Object(1) - callback = lambda ref: None - ref1 = weakref.ref(x, callback) - with self.assertRaises(AttributeError): - ref1.__callback__ = lambda ref: None - class SubclassableWeakrefTestCase(TestBase): @@ -1555,151 +1527,6 @@ def _reference(self): return self.__ref.copy() - -class FinalizeTestCase(unittest.TestCase): - - class A: - pass - - def _collect_if_necessary(self): - # we create no ref-cycles so in CPython no gc should be needed - if sys.implementation.name != 'cpython': - support.gc_collect() - - def test_finalize(self): - def add(x,y,z): - res.append(x + y + z) - return x + y + z - - a = self.A() - - res = [] - f = weakref.finalize(a, add, 67, 43, z=89) - self.assertEqual(f.alive, True) - self.assertEqual(f.peek(), (a, add, (67,43), {'z':89})) - self.assertEqual(f(), 199) - self.assertEqual(f(), None) - self.assertEqual(f(), None) - self.assertEqual(f.peek(), None) - self.assertEqual(f.detach(), None) - self.assertEqual(f.alive, False) - self.assertEqual(res, [199]) - - res = [] - f = weakref.finalize(a, add, 67, 43, 89) - self.assertEqual(f.peek(), (a, add, (67,43,89), {})) - self.assertEqual(f.detach(), (a, add, (67,43,89), {})) - self.assertEqual(f(), None) - self.assertEqual(f(), None) - self.assertEqual(f.peek(), None) - self.assertEqual(f.detach(), None) - self.assertEqual(f.alive, False) - self.assertEqual(res, []) - - res = [] - f = weakref.finalize(a, add, x=67, y=43, z=89) - del a - self._collect_if_necessary() - self.assertEqual(f(), None) - self.assertEqual(f(), None) - self.assertEqual(f.peek(), None) - self.assertEqual(f.detach(), None) - self.assertEqual(f.alive, False) - self.assertEqual(res, [199]) - - def test_order(self): - a = self.A() - res = [] - - f1 = weakref.finalize(a, res.append, 'f1') - f2 = weakref.finalize(a, res.append, 'f2') - f3 = weakref.finalize(a, res.append, 'f3') - f4 = weakref.finalize(a, res.append, 'f4') - f5 = weakref.finalize(a, res.append, 'f5') - - # make sure finalizers can keep themselves alive - del f1, f4 - - self.assertTrue(f2.alive) - self.assertTrue(f3.alive) - self.assertTrue(f5.alive) - - self.assertTrue(f5.detach()) - self.assertFalse(f5.alive) - - f5() # nothing because previously unregistered - res.append('A') - f3() # => res.append('f3') - self.assertFalse(f3.alive) - res.append('B') - f3() # nothing because previously called - res.append('C') - del a - self._collect_if_necessary() - # => res.append('f4') - # => res.append('f2') - # => res.append('f1') - self.assertFalse(f2.alive) - res.append('D') - f2() # nothing because previously called by gc - - expected = ['A', 'f3', 'B', 'C', 'f4', 'f2', 'f1', 'D'] - self.assertEqual(res, expected) - - def test_all_freed(self): - # we want a weakrefable subclass of weakref.finalize - class MyFinalizer(weakref.finalize): - pass - - a = self.A() - res = [] - def callback(): - res.append(123) - f = MyFinalizer(a, callback) - - wr_callback = weakref.ref(callback) - wr_f = weakref.ref(f) - del callback, f - - self.assertIsNotNone(wr_callback()) - self.assertIsNotNone(wr_f()) - - del a - self._collect_if_necessary() - - self.assertIsNone(wr_callback()) - self.assertIsNone(wr_f()) - self.assertEqual(res, [123]) - - @classmethod - def run_in_child(cls): - def error(): - # Create an atexit finalizer from inside a finalizer called - # at exit. This should be the next to be run. - g1 = weakref.finalize(cls, print, 'g1') - print('f3 error') - 1/0 - - # cls should stay alive till atexit callbacks run - f1 = weakref.finalize(cls, print, 'f1', _global_var) - f2 = weakref.finalize(cls, print, 'f2', _global_var) - f3 = weakref.finalize(cls, error) - f4 = weakref.finalize(cls, print, 'f4', _global_var) - - assert f1.atexit == True - f2.atexit = False - assert f3.atexit == True - assert f4.atexit == True - - def test_atexit(self): - prog = ('from test.test_weakref import FinalizeTestCase;'+ - 'FinalizeTestCase.run_in_child()') - rc, out, err = script_helper.assert_python_ok('-c', prog) - out = out.decode('ascii').splitlines() - self.assertEqual(out, ['f4 foobar', 'f3 error', 'g1', 'f1 foobar']) - self.assertTrue(b'ZeroDivisionError' in err) - - libreftest = """ Doctest for examples in the library reference: weakref.rst >>> import weakref @@ -1793,7 +1620,6 @@ WeakValueDictionaryTestCase, WeakKeyDictionaryTestCase, SubclassableWeakrefTestCase, - FinalizeTestCase, ) support.run_doctest(sys.modules[__name__]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_weakset.py --- a/Lib/test/test_weakset.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_weakset.py Fri Feb 01 23:12:09 2013 +0100 @@ -340,12 +340,6 @@ self.assertFalse(self.s == WeakSet([Foo])) self.assertFalse(self.s == 1) - def test_ne(self): - self.assertTrue(self.s != set(self.items)) - s1 = WeakSet() - s2 = WeakSet() - self.assertFalse(s1 != s2) - def test_weak_destroy_while_iterating(self): # Issue #7105: iterators shouldn't crash when a key is implicitly removed # Create new items to be sure no-one else holds a reference diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_winreg.py Fri Feb 01 23:12:09 2013 +0100 @@ -28,12 +28,9 @@ # tests are only valid up until 6.1 HAS_REFLECTION = True if WIN_VER < (6, 1) else False -# Use a per-process key to prevent concurrent test runs (buildbot!) from -# stomping on each other. -test_key_base = "Python Test Key [%d] - Delete Me" % (os.getpid(),) -test_key_name = "SOFTWARE\\" + test_key_base +test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me" # On OS'es that support reflection we should test with a reflected key -test_reflect_key_name = "SOFTWARE\\Classes\\" + test_key_base +test_reflect_key_name = "SOFTWARE\\Classes\\Python Test Key - Delete Me" test_data = [ ("Int Value", 45, REG_DWORD), @@ -457,9 +454,6 @@ DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, KEY_WOW64_32KEY, 0) - def test_exception_numbers(self): - with self.assertRaises(FileNotFoundError) as ctx: - QueryValue(HKEY_CLASSES_ROOT, 'some_value_that_does_not_exist') def test_main(): support.run_unittest(LocalWinregTests, RemoteWinregTests, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_xml_dom_minicompat.py --- a/Lib/test/test_xml_dom_minicompat.py Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -# Tests for xml.dom.minicompat - -import pickle -import unittest - -import xml.dom -from xml.dom.minicompat import * - - -class EmptyNodeListTestCase(unittest.TestCase): - """Tests for the EmptyNodeList class.""" - - def test_emptynodelist_item(self): - # Test item access on an EmptyNodeList. - node_list = EmptyNodeList() - - self.assertIsNone(node_list.item(0)) - self.assertIsNone(node_list.item(-1)) # invalid item - - with self.assertRaises(IndexError): - node_list[0] - with self.assertRaises(IndexError): - node_list[-1] - - def test_emptynodelist_length(self): - node_list = EmptyNodeList() - # Reading - self.assertEqual(node_list.length, 0) - # Writing - with self.assertRaises(xml.dom.NoModificationAllowedErr): - node_list.length = 111 - - def test_emptynodelist___add__(self): - node_list = EmptyNodeList() + NodeList() - self.assertEqual(node_list, NodeList()) - - def test_emptynodelist___radd__(self): - node_list = [1,2] + EmptyNodeList() - self.assertEqual(node_list, [1,2]) - - -class NodeListTestCase(unittest.TestCase): - """Tests for the NodeList class.""" - - def test_nodelist_item(self): - # Test items access on a NodeList. - # First, use an empty NodeList. - node_list = NodeList() - - self.assertIsNone(node_list.item(0)) - self.assertIsNone(node_list.item(-1)) - - with self.assertRaises(IndexError): - node_list[0] - with self.assertRaises(IndexError): - node_list[-1] - - # Now, use a NodeList with items. - node_list.append(111) - node_list.append(999) - - self.assertEqual(node_list.item(0), 111) - self.assertIsNone(node_list.item(-1)) # invalid item - - self.assertEqual(node_list[0], 111) - self.assertEqual(node_list[-1], 999) - - def test_nodelist_length(self): - node_list = NodeList([1, 2]) - # Reading - self.assertEqual(node_list.length, 2) - # Writing - with self.assertRaises(xml.dom.NoModificationAllowedErr): - node_list.length = 111 - - def test_nodelist___add__(self): - node_list = NodeList([3, 4]) + [1, 2] - self.assertEqual(node_list, NodeList([3, 4, 1, 2])) - - def test_nodelist___radd__(self): - node_list = [1, 2] + NodeList([3, 4]) - self.assertEqual(node_list, NodeList([1, 2, 3, 4])) - - def test_nodelist_pickle_roundtrip(self): - # Test pickling and unpickling of a NodeList. - - # Empty NodeList. - node_list = NodeList() - pickled = pickle.dumps(node_list) - unpickled = pickle.loads(pickled) - self.assertEqual(unpickled, node_list) - - # Non-empty NodeList. - node_list.append(1) - node_list.append(2) - pickled = pickle.dumps(node_list) - unpickled = pickle.loads(pickled) - self.assertEqual(unpickled, node_list) - -if __name__ == '__main__': - unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_xml_etree.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,22 +1,30 @@ +# xml.etree test. This file contains enough tests to make sure that +# all included components work as they should. +# Large parts are extracted from the upstream test suite. +# +# PLEASE write all new tests using the standard unittest infrastructure and +# not doctest. +# # IMPORTANT: the same tests are run from "test_xml_etree_c" in order # to ensure consistency between the C implementation and the Python # implementation. # # For this purpose, the module-level "ET" symbol is temporarily # monkey-patched when running the "test_xml_etree_c" test suite. +# Don't re-import "xml.etree.ElementTree" module in the docstring, +# except if the test is specific to the Python implementation. import html import io import operator import pickle import sys -import types import unittest import weakref from itertools import product from test import support -from test.support import TESTFN, findfile, import_fresh_module, gc_collect +from test.support import TESTFN, findfile, unlink, import_fresh_module, gc_collect # pyET is the pure-Python implementation. # @@ -79,27 +87,21 @@ """ -ENTITY_XML = """\ - -%user-entities; -]> -&entity; -""" - - -class ModuleTest(unittest.TestCase): - # TODO: this should be removed once we get rid of the global module vars - - def test_sanity(self): - # Import sanity. - - from xml.etree import ElementTree - from xml.etree import ElementInclude - from xml.etree import ElementPath - +def sanity(): + """ + Import sanity. + + >>> from xml.etree import ElementTree + >>> from xml.etree import ElementInclude + >>> from xml.etree import ElementPath + """ + +def check_method(method): + if not hasattr(method, '__call__'): + print(method, "not callable") def serialize(elem, to_string=True, encoding='unicode', **options): + import io if encoding != 'unicode': file = io.BytesIO() else: @@ -112,9 +114,68 @@ file.seek(0) return file +def summarize(elem): + if elem.tag == ET.Comment: + return "" + return elem.tag + def summarize_list(seq): - return [elem.tag for elem in seq] - + return [summarize(elem) for elem in seq] + +def normalize_crlf(tree): + for elem in tree.iter(): + if elem.text: + elem.text = elem.text.replace("\r\n", "\n") + if elem.tail: + elem.tail = elem.tail.replace("\r\n", "\n") + +def normalize_exception(func, *args, **kwargs): + # Ignore the exception __module__ + try: + func(*args, **kwargs) + except Exception as err: + print("Traceback (most recent call last):") + print("{}: {}".format(err.__class__.__name__, err)) + +def check_string(string): + len(string) + for char in string: + if len(char) != 1: + print("expected one-character string, got %r" % char) + new_string = string + "" + new_string = string + " " + string[:0] + +def check_mapping(mapping): + len(mapping) + keys = mapping.keys() + items = mapping.items() + for key in keys: + item = mapping[key] + mapping["key"] = "value" + if mapping["key"] != "value": + print("expected value string, got %r" % mapping["key"]) + +def check_element(element): + if not ET.iselement(element): + print("not an element") + if not hasattr(element, "tag"): + print("no tag member") + if not hasattr(element, "attrib"): + print("no attrib member") + if not hasattr(element, "text"): + print("no text member") + if not hasattr(element, "tail"): + print("no tail member") + + check_string(element.tag) + check_mapping(element.attrib) + if element.text is not None: + check_string(element.text) + if element.tail is not None: + check_string(element.tail) + for elem in element: + check_element(elem) class ElementTestCase: @classmethod @@ -151,790 +212,1531 @@ # -------------------------------------------------------------------- # element tree tests +def interface(): + """ + Test element tree interface. + + >>> element = ET.Element("tag") + >>> check_element(element) + >>> tree = ET.ElementTree(element) + >>> check_element(tree.getroot()) + + >>> element = ET.Element("t\\xe4g", key="value") + >>> tree = ET.ElementTree(element) + >>> repr(element) # doctest: +ELLIPSIS + "" + >>> element = ET.Element("tag", key="value") + + Make sure all standard element methods exist. + + >>> check_method(element.append) + >>> check_method(element.extend) + >>> check_method(element.insert) + >>> check_method(element.remove) + >>> check_method(element.getchildren) + >>> check_method(element.find) + >>> check_method(element.iterfind) + >>> check_method(element.findall) + >>> check_method(element.findtext) + >>> check_method(element.clear) + >>> check_method(element.get) + >>> check_method(element.set) + >>> check_method(element.keys) + >>> check_method(element.items) + >>> check_method(element.iter) + >>> check_method(element.itertext) + >>> check_method(element.getiterator) + + These methods return an iterable. See bug 6472. + + >>> check_method(element.iterfind("tag").__next__) + >>> check_method(element.iterfind("*").__next__) + >>> check_method(tree.iterfind("tag").__next__) + >>> check_method(tree.iterfind("*").__next__) + + These aliases are provided: + + >>> assert ET.XML == ET.fromstring + >>> assert ET.PI == ET.ProcessingInstruction + >>> assert ET.XMLParser == ET.XMLTreeBuilder + """ + +def simpleops(): + """ + Basic method sanity checks. + + >>> elem = ET.XML("") + >>> serialize(elem) + '' + >>> e = ET.Element("tag2") + >>> elem.append(e) + >>> serialize(elem) + '' + >>> elem.remove(e) + >>> serialize(elem) + '' + >>> elem.insert(0, e) + >>> serialize(elem) + '' + >>> elem.remove(e) + >>> elem.extend([e]) + >>> serialize(elem) + '' + >>> elem.remove(e) + + >>> element = ET.Element("tag", key="value") + >>> serialize(element) # 1 + '' + >>> subelement = ET.Element("subtag") + >>> element.append(subelement) + >>> serialize(element) # 2 + '' + >>> element.insert(0, subelement) + >>> serialize(element) # 3 + '' + >>> element.remove(subelement) + >>> serialize(element) # 4 + '' + >>> element.remove(subelement) + >>> serialize(element) # 5 + '' + >>> element.remove(subelement) + Traceback (most recent call last): + ValueError: list.remove(x): x not in list + >>> serialize(element) # 6 + '' + >>> element[0:0] = [subelement, subelement, subelement] + >>> serialize(element[1]) + '' + >>> element[1:9] == [element[1], element[2]] + True + >>> element[:9:2] == [element[0], element[2]] + True + >>> del element[1:2] + >>> serialize(element) + '' + """ + +def cdata(): + """ + Test CDATA handling (etc). + + >>> serialize(ET.XML("hello")) + 'hello' + >>> serialize(ET.XML("hello")) + 'hello' + >>> serialize(ET.XML("")) + 'hello' + """ + +def file_init(): + """ + >>> import io + + >>> stringfile = io.BytesIO(SAMPLE_XML.encode("utf-8")) + >>> tree = ET.ElementTree(file=stringfile) + >>> tree.find("tag").tag + 'tag' + >>> tree.find("section/tag").tag + 'tag' + + >>> tree = ET.ElementTree(file=SIMPLE_XMLFILE) + >>> tree.find("element").tag + 'element' + >>> tree.find("element/../empty-element").tag + 'empty-element' + """ + +def path_cache(): + """ + Check that the path cache behaves sanely. + + >>> from xml.etree import ElementPath + + >>> elem = ET.XML(SAMPLE_XML) + >>> for i in range(10): ET.ElementTree(elem).find('./'+str(i)) + >>> cache_len_10 = len(ElementPath._cache) + >>> for i in range(10): ET.ElementTree(elem).find('./'+str(i)) + >>> len(ElementPath._cache) == cache_len_10 + True + >>> for i in range(20): ET.ElementTree(elem).find('./'+str(i)) + >>> len(ElementPath._cache) > cache_len_10 + True + >>> for i in range(600): ET.ElementTree(elem).find('./'+str(i)) + >>> len(ElementPath._cache) < 500 + True + """ + +def copy(): + """ + Test copy handling (etc). + + >>> import copy + >>> e1 = ET.XML("hello") + >>> e2 = copy.copy(e1) + >>> e3 = copy.deepcopy(e1) + >>> e1.find("foo").tag = "bar" + >>> serialize(e1) + 'hello' + >>> serialize(e2) + 'hello' + >>> serialize(e3) + 'hello' + + """ + +def attrib(): + """ + Test attribute handling. + + >>> elem = ET.Element("tag") + >>> elem.get("key") # 1.1 + >>> elem.get("key", "default") # 1.2 + 'default' + >>> elem.set("key", "value") + >>> elem.get("key") # 1.3 + 'value' + + >>> elem = ET.Element("tag", key="value") + >>> elem.get("key") # 2.1 + 'value' + >>> elem.attrib # 2.2 + {'key': 'value'} + + >>> attrib = {"key": "value"} + >>> elem = ET.Element("tag", attrib) + >>> attrib.clear() # check for aliasing issues + >>> elem.get("key") # 3.1 + 'value' + >>> elem.attrib # 3.2 + {'key': 'value'} + + >>> attrib = {"key": "value"} + >>> elem = ET.Element("tag", **attrib) + >>> attrib.clear() # check for aliasing issues + >>> elem.get("key") # 4.1 + 'value' + >>> elem.attrib # 4.2 + {'key': 'value'} + + >>> elem = ET.Element("tag", {"key": "other"}, key="value") + >>> elem.get("key") # 5.1 + 'value' + >>> elem.attrib # 5.2 + {'key': 'value'} + + >>> elem = ET.Element('test') + >>> elem.text = "aa" + >>> elem.set('testa', 'testval') + >>> elem.set('testb', 'test2') + >>> ET.tostring(elem) + b'aa' + >>> sorted(elem.keys()) + ['testa', 'testb'] + >>> sorted(elem.items()) + [('testa', 'testval'), ('testb', 'test2')] + >>> elem.attrib['testb'] + 'test2' + >>> elem.attrib['testb'] = 'test1' + >>> elem.attrib['testc'] = 'test2' + >>> ET.tostring(elem) + b'aa' + """ + +def makeelement(): + """ + Test makeelement handling. + + >>> elem = ET.Element("tag") + >>> attrib = {"key": "value"} + >>> subelem = elem.makeelement("subtag", attrib) + >>> if subelem.attrib is attrib: + ... print("attrib aliasing") + >>> elem.append(subelem) + >>> serialize(elem) + '' + + >>> elem.clear() + >>> serialize(elem) + '' + >>> elem.append(subelem) + >>> serialize(elem) + '' + >>> elem.extend([subelem, subelem]) + >>> serialize(elem) + '' + >>> elem[:] = [subelem] + >>> serialize(elem) + '' + >>> elem[:] = tuple([subelem]) + >>> serialize(elem) + '' + + """ + +def parsefile(): + """ + Test parsing from file. + + >>> tree = ET.parse(SIMPLE_XMLFILE) + >>> normalize_crlf(tree) + >>> tree.write(sys.stdout, encoding='unicode') + + text + texttail + + + >>> tree = ET.parse(SIMPLE_NS_XMLFILE) + >>> normalize_crlf(tree) + >>> tree.write(sys.stdout, encoding='unicode') + + text + texttail + + + + >>> with open(SIMPLE_XMLFILE) as f: + ... data = f.read() + + >>> parser = ET.XMLParser() + >>> parser.version # doctest: +ELLIPSIS + 'Expat ...' + >>> parser.feed(data) + >>> print(serialize(parser.close())) + + text + texttail + + + + >>> parser = ET.XMLTreeBuilder() # 1.2 compatibility + >>> parser.feed(data) + >>> print(serialize(parser.close())) + + text + texttail + + + + >>> target = ET.TreeBuilder() + >>> parser = ET.XMLParser(target=target) + >>> parser.feed(data) + >>> print(serialize(parser.close())) + + text + texttail + + + """ + +def parseliteral(): + """ + >>> element = ET.XML("text") + >>> ET.ElementTree(element).write(sys.stdout, encoding='unicode') + text + >>> element = ET.fromstring("text") + >>> ET.ElementTree(element).write(sys.stdout, encoding='unicode') + text + >>> sequence = ["", "text"] + >>> element = ET.fromstringlist(sequence) + >>> ET.tostring(element) + b'text' + >>> b"".join(ET.tostringlist(element)) + b'text' + >>> ET.tostring(element, "ascii") + b"\\ntext" + >>> _, ids = ET.XMLID("text") + >>> len(ids) + 0 + >>> _, ids = ET.XMLID("text") + >>> len(ids) + 1 + >>> ids["body"].tag + 'body' + """ + +def iterparse(): + """ + Test iterparse interface. + + >>> iterparse = ET.iterparse + + >>> context = iterparse(SIMPLE_XMLFILE) + >>> action, elem = next(context) + >>> print(action, elem.tag) + end element + >>> for action, elem in context: + ... print(action, elem.tag) + end element + end empty-element + end root + >>> context.root.tag + 'root' + + >>> context = iterparse(SIMPLE_NS_XMLFILE) + >>> for action, elem in context: + ... print(action, elem.tag) + end {namespace}element + end {namespace}element + end {namespace}empty-element + end {namespace}root + + >>> events = () + >>> context = iterparse(SIMPLE_XMLFILE, events) + >>> for action, elem in context: + ... print(action, elem.tag) + + >>> events = () + >>> context = iterparse(SIMPLE_XMLFILE, events=events) + >>> for action, elem in context: + ... print(action, elem.tag) + + >>> events = ("start", "end") + >>> context = iterparse(SIMPLE_XMLFILE, events) + >>> for action, elem in context: + ... print(action, elem.tag) + start root + start element + end element + start element + end element + start empty-element + end empty-element + end root + + >>> events = ("start", "end", "start-ns", "end-ns") + >>> context = iterparse(SIMPLE_NS_XMLFILE, events) + >>> for action, elem in context: + ... if action in ("start", "end"): + ... print(action, elem.tag) + ... else: + ... print(action, elem) + start-ns ('', 'namespace') + start {namespace}root + start {namespace}element + end {namespace}element + start {namespace}element + end {namespace}element + start {namespace}empty-element + end {namespace}empty-element + end {namespace}root + end-ns None + + >>> events = ("start", "end", "bogus") + >>> with open(SIMPLE_XMLFILE, "rb") as f: + ... iterparse(f, events) + Traceback (most recent call last): + ValueError: unknown event 'bogus' + + >>> import io + + >>> source = io.BytesIO( + ... b"\\n" + ... b"text\\n") + >>> events = ("start-ns",) + >>> context = iterparse(source, events) + >>> for action, elem in context: + ... print(action, elem) + start-ns ('', 'http://\\xe9ffbot.org/ns') + start-ns ('cl\\xe9', 'http://effbot.org/ns') + + >>> source = io.StringIO("junk") + >>> try: + ... for action, elem in iterparse(source): + ... print(action, elem.tag) + ... except ET.ParseError as v: + ... print(v) + end document + junk after document element: line 1, column 12 + """ + +def writefile(): + """ + >>> elem = ET.Element("tag") + >>> elem.text = "text" + >>> serialize(elem) + 'text' + >>> ET.SubElement(elem, "subtag").text = "subtext" + >>> serialize(elem) + 'textsubtext' + + Test tag suppression + >>> elem.tag = None + >>> serialize(elem) + 'textsubtext' + >>> elem.insert(0, ET.Comment("comment")) + >>> serialize(elem) # assumes 1.3 + 'textsubtext' + >>> elem[0] = ET.PI("key", "value") + >>> serialize(elem) + 'textsubtext' + """ + +def custom_builder(): + """ + Test parser w. custom builder. + + >>> with open(SIMPLE_XMLFILE) as f: + ... data = f.read() + >>> class Builder: + ... def start(self, tag, attrib): + ... print("start", tag) + ... def end(self, tag): + ... print("end", tag) + ... def data(self, text): + ... pass + >>> builder = Builder() + >>> parser = ET.XMLParser(target=builder) + >>> parser.feed(data) + start root + start element + end element + start element + end element + start empty-element + end empty-element + end root + + >>> with open(SIMPLE_NS_XMLFILE) as f: + ... data = f.read() + >>> class Builder: + ... def start(self, tag, attrib): + ... print("start", tag) + ... def end(self, tag): + ... print("end", tag) + ... def data(self, text): + ... pass + ... def pi(self, target, data): + ... print("pi", target, repr(data)) + ... def comment(self, data): + ... print("comment", repr(data)) + >>> builder = Builder() + >>> parser = ET.XMLParser(target=builder) + >>> parser.feed(data) + pi pi 'data' + comment ' comment ' + start {namespace}root + start {namespace}element + end {namespace}element + start {namespace}element + end {namespace}element + start {namespace}empty-element + end {namespace}empty-element + end {namespace}root + + """ + +def getchildren(): + """ + Test Element.getchildren() + + >>> with open(SIMPLE_XMLFILE, "rb") as f: + ... tree = ET.parse(f) + >>> for elem in tree.getroot().iter(): + ... summarize_list(elem.getchildren()) + ['element', 'element', 'empty-element'] + [] + [] + [] + >>> for elem in tree.getiterator(): + ... summarize_list(elem.getchildren()) + ['element', 'element', 'empty-element'] + [] + [] + [] + + >>> elem = ET.XML(SAMPLE_XML) + >>> len(elem.getchildren()) + 3 + >>> len(elem[2].getchildren()) + 1 + >>> elem[:] == elem.getchildren() + True + >>> child1 = elem[0] + >>> child2 = elem[2] + >>> del elem[1:2] + >>> len(elem.getchildren()) + 2 + >>> child1 == elem[0] + True + >>> child2 == elem[1] + True + >>> elem[0:2] = [child2, child1] + >>> child2 == elem[0] + True + >>> child1 == elem[1] + True + >>> child1 == elem[0] + False + >>> elem.clear() + >>> elem.getchildren() + [] + """ + +def writestring(): + """ + >>> elem = ET.XML("text") + >>> ET.tostring(elem) + b'text' + >>> elem = ET.fromstring("text") + >>> ET.tostring(elem) + b'text' + """ + +def check_encoding(encoding): + """ + >>> check_encoding("ascii") + >>> check_encoding("us-ascii") + >>> check_encoding("iso-8859-1") + >>> check_encoding("iso-8859-15") + >>> check_encoding("cp437") + >>> check_encoding("mac-roman") + """ + ET.XML("" % encoding) + +def methods(): + r""" + Test serialization methods. + + >>> e = ET.XML("") + >>> e.tail = "\n" + >>> serialize(e) + '\n' + >>> serialize(e, method=None) + '\n' + >>> serialize(e, method="xml") + '\n' + >>> serialize(e, method="html") + '\n' + >>> serialize(e, method="text") + '1 < 2\n' + """ + +ENTITY_XML = """\ + +%user-entities; +]> +&entity; +""" + +def entity(): + """ + Test entity handling. + + 1) good entities + + >>> e = ET.XML("test") + >>> serialize(e, encoding="us-ascii") + b'test' + >>> serialize(e) + 'test' + + 2) bad entities + + >>> normalize_exception(ET.XML, "&entity;") + Traceback (most recent call last): + ParseError: undefined entity: line 1, column 10 + + >>> normalize_exception(ET.XML, ENTITY_XML) + Traceback (most recent call last): + ParseError: undefined entity &entity;: line 5, column 10 + + 3) custom entity + + >>> parser = ET.XMLParser() + >>> parser.entity["entity"] = "text" + >>> parser.feed(ENTITY_XML) + >>> root = parser.close() + >>> serialize(root) + 'text' + """ + +def namespace(): + """ + Test namespace issues. + + 1) xml namespace + + >>> elem = ET.XML("") + >>> serialize(elem) # 1.1 + '' + + 2) other "well-known" namespaces + + >>> elem = ET.XML("") + >>> serialize(elem) # 2.1 + '' + + >>> elem = ET.XML("") + >>> serialize(elem) # 2.2 + '' + + >>> elem = ET.XML("") + >>> serialize(elem) # 2.3 + '' + + 3) unknown namespaces + >>> elem = ET.XML(SAMPLE_XML_NS) + >>> print(serialize(elem)) + + text + + + subtext + + + """ + +def qname(): + """ + Test QName handling. + + 1) decorated tags + + >>> elem = ET.Element("{uri}tag") + >>> serialize(elem) # 1.1 + '' + >>> elem = ET.Element(ET.QName("{uri}tag")) + >>> serialize(elem) # 1.2 + '' + >>> elem = ET.Element(ET.QName("uri", "tag")) + >>> serialize(elem) # 1.3 + '' + >>> elem = ET.Element(ET.QName("uri", "tag")) + >>> subelem = ET.SubElement(elem, ET.QName("uri", "tag1")) + >>> subelem = ET.SubElement(elem, ET.QName("uri", "tag2")) + >>> serialize(elem) # 1.4 + '' + + 2) decorated attributes + + >>> elem.clear() + >>> elem.attrib["{uri}key"] = "value" + >>> serialize(elem) # 2.1 + '' + + >>> elem.clear() + >>> elem.attrib[ET.QName("{uri}key")] = "value" + >>> serialize(elem) # 2.2 + '' + + 3) decorated values are not converted by default, but the + QName wrapper can be used for values + + >>> elem.clear() + >>> elem.attrib["{uri}key"] = "{uri}value" + >>> serialize(elem) # 3.1 + '' + + >>> elem.clear() + >>> elem.attrib["{uri}key"] = ET.QName("{uri}value") + >>> serialize(elem) # 3.2 + '' + + >>> elem.clear() + >>> subelem = ET.Element("tag") + >>> subelem.attrib["{uri1}key"] = ET.QName("{uri2}value") + >>> elem.append(subelem) + >>> elem.append(subelem) + >>> serialize(elem) # 3.3 + '' + + 4) Direct QName tests + + >>> str(ET.QName('ns', 'tag')) + '{ns}tag' + >>> str(ET.QName('{ns}tag')) + '{ns}tag' + >>> q1 = ET.QName('ns', 'tag') + >>> q2 = ET.QName('ns', 'tag') + >>> q1 == q2 + True + >>> q2 = ET.QName('ns', 'other-tag') + >>> q1 == q2 + False + >>> q1 == 'ns:tag' + False + >>> q1 == '{ns}tag' + True + """ + +def doctype_public(): + """ + Test PUBLIC doctype. + + >>> elem = ET.XML('' + ... 'text') + + """ + +def xpath_tokenizer(p): + """ + Test the XPath tokenizer. + + >>> # tests from the xml specification + >>> xpath_tokenizer("*") + ['*'] + >>> xpath_tokenizer("text()") + ['text', '()'] + >>> xpath_tokenizer("@name") + ['@', 'name'] + >>> xpath_tokenizer("@*") + ['@', '*'] + >>> xpath_tokenizer("para[1]") + ['para', '[', '1', ']'] + >>> xpath_tokenizer("para[last()]") + ['para', '[', 'last', '()', ']'] + >>> xpath_tokenizer("*/para") + ['*', '/', 'para'] + >>> xpath_tokenizer("/doc/chapter[5]/section[2]") + ['/', 'doc', '/', 'chapter', '[', '5', ']', '/', 'section', '[', '2', ']'] + >>> xpath_tokenizer("chapter//para") + ['chapter', '//', 'para'] + >>> xpath_tokenizer("//para") + ['//', 'para'] + >>> xpath_tokenizer("//olist/item") + ['//', 'olist', '/', 'item'] + >>> xpath_tokenizer(".") + ['.'] + >>> xpath_tokenizer(".//para") + ['.', '//', 'para'] + >>> xpath_tokenizer("..") + ['..'] + >>> xpath_tokenizer("../@lang") + ['..', '/', '@', 'lang'] + >>> xpath_tokenizer("chapter[title]") + ['chapter', '[', 'title', ']'] + >>> xpath_tokenizer("employee[@secretary and @assistant]") + ['employee', '[', '@', 'secretary', '', 'and', '', '@', 'assistant', ']'] + + >>> # additional tests + >>> xpath_tokenizer("{http://spam}egg") + ['{http://spam}egg'] + >>> xpath_tokenizer("./spam.egg") + ['.', '/', 'spam.egg'] + >>> xpath_tokenizer(".//{http://spam}egg") + ['.', '//', '{http://spam}egg'] + """ + from xml.etree import ElementPath + out = [] + for op, tag in ElementPath.xpath_tokenizer(p): + out.append(op or tag) + return out + +def processinginstruction(): + """ + Test ProcessingInstruction directly + + >>> ET.tostring(ET.ProcessingInstruction('test', 'instruction')) + b'' + >>> ET.tostring(ET.PI('test', 'instruction')) + b'' + + Issue #2746 + + >>> ET.tostring(ET.PI('test', '')) + b'?>' + >>> ET.tostring(ET.PI('test', '\xe3'), 'latin-1') + b"\\n\\xe3?>" + """ + +# +# xinclude tests (samples from appendix C of the xinclude specification) + +XINCLUDE = {} + +XINCLUDE["C1.xml"] = """\ + + +

120 Mz is adequate for an average home user.

+ + +""" + +XINCLUDE["disclaimer.xml"] = """\ + + +

The opinions represented herein represent those of the individual + and should not be interpreted as official policy endorsed by this + organization.

+
+""" + +XINCLUDE["C2.xml"] = """\ + + +

This document has been accessed + times.

+
+""" + +XINCLUDE["count.txt"] = "324387" + +XINCLUDE["C2b.xml"] = """\ + + +

This document has been accessed + times.

+
+""" + +XINCLUDE["C3.xml"] = """\ + + +

The following is the source of the "data.xml" resource:

+ +
+""" + +XINCLUDE["data.xml"] = """\ + + + + +""" + +XINCLUDE["C5.xml"] = """\ + +
+""" + +XINCLUDE["default.xml"] = """\ + + +

Example.

+ +
+""".format(html.escape(SIMPLE_XMLFILE, True)) + + +def xinclude_loader(href, parse="xml", encoding=None): + try: + data = XINCLUDE[href] + except KeyError: + raise OSError("resource not found") + if parse == "xml": + data = ET.XML(data) + return data + +def xinclude(): + r""" + Basic inclusion example (XInclude C.1) + + >>> from xml.etree import ElementInclude + + >>> document = xinclude_loader("C1.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print(serialize(document)) # C1 + +

120 Mz is adequate for an average home user.

+ +

The opinions represented herein represent those of the individual + and should not be interpreted as official policy endorsed by this + organization.

+
+
+ + Textual inclusion example (XInclude C.2) + + >>> document = xinclude_loader("C2.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print(serialize(document)) # C2 + +

This document has been accessed + 324387 times.

+
+ + Textual inclusion after sibling element (based on modified XInclude C.2) + + >>> document = xinclude_loader("C2b.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print(serialize(document)) # C2b + +

This document has been accessed + 324387 times.

+
+ + Textual inclusion of XML example (XInclude C.3) + + >>> document = xinclude_loader("C3.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print(serialize(document)) # C3 + +

The following is the source of the "data.xml" resource:

+ <?xml version='1.0'?> + <data> + <item><![CDATA[Brooks & Shields]]></item> + </data> + +
+ + Fallback example (XInclude C.5) + Note! Fallback support is not yet implemented + + >>> document = xinclude_loader("C5.xml") + >>> ElementInclude.include(document, xinclude_loader) + Traceback (most recent call last): + OSError: resource not found + >>> # print(serialize(document)) # C5 + """ + + +# +# badly formatted xi:include tags + +XINCLUDE_BAD = {} + +XINCLUDE_BAD["B1.xml"] = """\ + + +

120 Mz is adequate for an average home user.

+ +
+""" + +XINCLUDE_BAD["B2.xml"] = """\ + +
+ +
+""" + +def xinclude_failures(): + r""" + Test failure to locate included XML file. + + >>> from xml.etree import ElementInclude + + >>> def none_loader(href, parser, encoding=None): + ... return None + + >>> document = ET.XML(XINCLUDE["C1.xml"]) + >>> ElementInclude.include(document, loader=none_loader) + Traceback (most recent call last): + xml.etree.ElementInclude.FatalIncludeError: cannot load 'disclaimer.xml' as 'xml' + + Test failure to locate included text file. + + >>> document = ET.XML(XINCLUDE["C2.xml"]) + >>> ElementInclude.include(document, loader=none_loader) + Traceback (most recent call last): + xml.etree.ElementInclude.FatalIncludeError: cannot load 'count.txt' as 'text' + + Test bad parse type. + + >>> document = ET.XML(XINCLUDE_BAD["B1.xml"]) + >>> ElementInclude.include(document, loader=none_loader) + Traceback (most recent call last): + xml.etree.ElementInclude.FatalIncludeError: unknown parse type in xi:include tag ('BAD_TYPE') + + Test xi:fallback outside xi:include. + + >>> document = ET.XML(XINCLUDE_BAD["B2.xml"]) + >>> ElementInclude.include(document, loader=none_loader) + Traceback (most recent call last): + xml.etree.ElementInclude.FatalIncludeError: xi:fallback tag must be child of xi:include ('{http://www.w3.org/2001/XInclude}fallback') + """ + +# -------------------------------------------------------------------- +# reported bugs + +def bug_xmltoolkit21(): + """ + + marshaller gives obscure errors for non-string values + + >>> elem = ET.Element(123) + >>> serialize(elem) # tag + Traceback (most recent call last): + TypeError: cannot serialize 123 (type int) + >>> elem = ET.Element("elem") + >>> elem.text = 123 + >>> serialize(elem) # text + Traceback (most recent call last): + TypeError: cannot serialize 123 (type int) + >>> elem = ET.Element("elem") + >>> elem.tail = 123 + >>> serialize(elem) # tail + Traceback (most recent call last): + TypeError: cannot serialize 123 (type int) + >>> elem = ET.Element("elem") + >>> elem.set(123, "123") + >>> serialize(elem) # attribute key + Traceback (most recent call last): + TypeError: cannot serialize 123 (type int) + >>> elem = ET.Element("elem") + >>> elem.set("123", 123) + >>> serialize(elem) # attribute value + Traceback (most recent call last): + TypeError: cannot serialize 123 (type int) + + """ + +def bug_xmltoolkit25(): + """ + + typo in ElementTree.findtext + + >>> elem = ET.XML(SAMPLE_XML) + >>> tree = ET.ElementTree(elem) + >>> tree.findtext("tag") + 'text' + >>> tree.findtext("section/tag") + 'subtext' + + """ + +def bug_xmltoolkit28(): + """ + + .//tag causes exceptions + + >>> tree = ET.XML("
") + >>> summarize_list(tree.findall(".//thead")) + [] + >>> summarize_list(tree.findall(".//tbody")) + ['tbody'] + + """ + +def bug_xmltoolkitX1(): + """ + + dump() doesn't flush the output buffer + + >>> tree = ET.XML("
") + >>> ET.dump(tree); print("tail") +
+ tail + + """ + +def bug_xmltoolkit39(): + """ + + non-ascii element and attribute names doesn't work + + >>> tree = ET.XML(b"") + >>> ET.tostring(tree, "utf-8") + b'' + + >>> tree = ET.XML(b"") + >>> tree.attrib + {'\\xe4ttr': 'v\\xe4lue'} + >>> ET.tostring(tree, "utf-8") + b'' + + >>> tree = ET.XML(b"text") + >>> ET.tostring(tree, "utf-8") + b'text' + + >>> tree = ET.Element("t\u00e4g") + >>> ET.tostring(tree, "utf-8") + b'' + + >>> tree = ET.Element("tag") + >>> tree.set("\u00e4ttr", "v\u00e4lue") + >>> ET.tostring(tree, "utf-8") + b'' + + """ + +def bug_xmltoolkit54(): + """ + + problems handling internally defined entities + + >>> e = ET.XML("]>&ldots;") + >>> serialize(e, encoding="us-ascii") + b'' + >>> serialize(e) + '\u8230' + + """ + +def bug_xmltoolkit55(): + """ + + make sure we're reporting the first error, not the last + + >>> normalize_exception(ET.XML, b"&ldots;&ndots;&rdots;") + Traceback (most recent call last): + ParseError: undefined entity &ldots;: line 1, column 36 + + """ + +class ExceptionFile: + def read(self, x): + raise OSError + +def xmltoolkit60(): + """ + + Handle crash in stream source. + >>> tree = ET.parse(ExceptionFile()) + Traceback (most recent call last): + OSError + + """ + +XMLTOOLKIT62_DOC = """ + + + +A new cultivar of Begonia plant named ‘BCT9801BEG’. + +""" + + +def xmltoolkit62(): + """ + + Don't crash when using custom entities. + + >>> xmltoolkit62() + 'A new cultivar of Begonia plant named \u2018BCT9801BEG\u2019.' + + """ + ENTITIES = {'rsquo': '\u2019', 'lsquo': '\u2018'} + parser = ET.XMLTreeBuilder() + parser.entity.update(ENTITIES) + parser.feed(XMLTOOLKIT62_DOC) + t = parser.close() + return t.find('.//paragraph').text + +def xmltoolkit63(): + """ + + Check reference leak. + >>> xmltoolkit63() + >>> count = sys.getrefcount(None) + >>> for i in range(1000): + ... xmltoolkit63() + >>> sys.getrefcount(None) - count + 0 + + """ + tree = ET.TreeBuilder() + tree.start("tag", {}) + tree.data("text") + tree.end("tag") + +# -------------------------------------------------------------------- + + +def bug_200708_newline(): + r""" + + Preserve newlines in attributes. + + >>> e = ET.Element('SomeTag', text="def _f():\n return 3\n") + >>> ET.tostring(e) + b'' + >>> ET.XML(ET.tostring(e)).get("text") + 'def _f():\n return 3\n' + >>> ET.tostring(ET.XML(ET.tostring(e))) + b'' + + """ + +def bug_200708_close(): + """ + + Test default builder. + >>> parser = ET.XMLParser() # default + >>> parser.feed("some text") + >>> summarize(parser.close()) + 'element' + + Test custom builder. + >>> class EchoTarget: + ... def close(self): + ... return ET.Element("element") # simulate root + >>> parser = ET.XMLParser(EchoTarget()) + >>> parser.feed("some text") + >>> summarize(parser.close()) + 'element' + + """ + +def bug_200709_default_namespace(): + """ + + >>> e = ET.Element("{default}elem") + >>> s = ET.SubElement(e, "{default}elem") + >>> serialize(e, default_namespace="default") # 1 + '' + + >>> e = ET.Element("{default}elem") + >>> s = ET.SubElement(e, "{default}elem") + >>> s = ET.SubElement(e, "{not-default}elem") + >>> serialize(e, default_namespace="default") # 2 + '' + + >>> e = ET.Element("{default}elem") + >>> s = ET.SubElement(e, "{default}elem") + >>> s = ET.SubElement(e, "elem") # unprefixed name + >>> serialize(e, default_namespace="default") # 3 + Traceback (most recent call last): + ValueError: cannot use non-qualified names with default_namespace option + + """ + +def bug_200709_register_namespace(): + """ + + >>> ET.tostring(ET.Element("{http://namespace.invalid/does/not/exist/}title")) + b'' + >>> ET.register_namespace("foo", "http://namespace.invalid/does/not/exist/") + >>> ET.tostring(ET.Element("{http://namespace.invalid/does/not/exist/}title")) + b'' + + And the Dublin Core namespace is in the default list: + + >>> ET.tostring(ET.Element("{http://purl.org/dc/elements/1.1/}title")) + b'' + + """ + +def bug_200709_element_comment(): + """ + + Not sure if this can be fixed, really (since the serializer needs + ET.Comment, not cET.comment). + + >>> a = ET.Element('a') + >>> a.append(ET.Comment('foo')) + >>> a[0].tag == ET.Comment + True + + >>> a = ET.Element('a') + >>> a.append(ET.PI('foo')) + >>> a[0].tag == ET.PI + True + + """ + +def bug_200709_element_insert(): + """ + + >>> a = ET.Element('a') + >>> b = ET.SubElement(a, 'b') + >>> c = ET.SubElement(a, 'c') + >>> d = ET.Element('d') + >>> a.insert(0, d) + >>> summarize_list(a) + ['d', 'b', 'c'] + >>> a.insert(-1, d) + >>> summarize_list(a) + ['d', 'b', 'd', 'c'] + + """ + +def bug_200709_iter_comment(): + """ + + >>> a = ET.Element('a') + >>> b = ET.SubElement(a, 'b') + >>> comment_b = ET.Comment("TEST-b") + >>> b.append(comment_b) + >>> summarize_list(a.iter(ET.Comment)) + [''] + + """ + +# -------------------------------------------------------------------- +# reported on bugs.python.org + +def bug_1534630(): + """ + + >>> bob = ET.TreeBuilder() + >>> e = bob.data("data") + >>> e = bob.start("tag", {}) + >>> e = bob.end("tag") + >>> e = bob.close() + >>> serialize(e) + '' + + """ + +def check_issue6233(): + """ + + >>> e = ET.XML(b"t\\xc3\\xa3g") + >>> ET.tostring(e, 'ascii') + b"\\ntãg" + >>> e = ET.XML(b"t\\xe3g") + >>> ET.tostring(e, 'ascii') + b"\\ntãg" + + """ + +def check_issue3151(): + """ + + >>> e = ET.XML('') + >>> e.tag + '{${stuff}}localname' + >>> t = ET.ElementTree(e) + >>> ET.tostring(e) + b'' + + """ + +def check_issue6565(): + """ + + >>> elem = ET.XML("") + >>> summarize_list(elem) + ['tag'] + >>> newelem = ET.XML(SAMPLE_XML) + >>> elem[:] = newelem[:] + >>> summarize_list(elem) + ['tag', 'tag', 'section'] + + """ + +def check_issue10777(): + """ + Registering a namespace twice caused a "dictionary changed size during + iteration" bug. + + >>> ET.register_namespace('test10777', 'http://myuri/') + >>> ET.register_namespace('test10777', 'http://myuri/') + """ + +# -------------------------------------------------------------------- + + +class BasicElementTest(ElementTestCase, unittest.TestCase): + def test_augmentation_type_errors(self): + e = ET.Element('joe') + self.assertRaises(TypeError, e.append, 'b') + self.assertRaises(TypeError, e.extend, [ET.Element('bar'), 'foo']) + self.assertRaises(TypeError, e.insert, 0, 'foo') + + def test_cyclic_gc(self): + class Dummy: + pass + + # Test the shortest cycle: d->element->d + d = Dummy() + d.dummyref = ET.Element('joe', attr=d) + wref = weakref.ref(d) + del d + gc_collect() + self.assertIsNone(wref()) + + # A longer cycle: d->e->e2->d + e = ET.Element('joe') + d = Dummy() + d.dummyref = e + wref = weakref.ref(d) + e2 = ET.SubElement(e, 'foo', attr=d) + del d, e, e2 + gc_collect() + self.assertIsNone(wref()) + + # A cycle between Element objects as children of one another + # e1->e2->e3->e1 + e1 = ET.Element('e1') + e2 = ET.Element('e2') + e3 = ET.Element('e3') + e1.append(e2) + e2.append(e2) + e3.append(e1) + wref = weakref.ref(e1) + del e1, e2, e3 + gc_collect() + self.assertIsNone(wref()) + + def test_weakref(self): + flag = False + def wref_cb(w): + nonlocal flag + flag = True + e = ET.Element('e') + wref = weakref.ref(e, wref_cb) + self.assertEqual(wref().tag, 'e') + del e + self.assertEqual(flag, True) + self.assertEqual(wref(), None) + + def test_get_keyword_args(self): + e1 = ET.Element('foo' , x=1, y=2, z=3) + self.assertEqual(e1.get('x', default=7), 1) + self.assertEqual(e1.get('w', default=7), 7) + + def test_pickle(self): + # issue #16076: the C implementation wasn't pickleable. + for dumper, loader in product(self.modules, repeat=2): + e = dumper.Element('foo', bar=42) + e.text = "text goes here" + e.tail = "opposite of head" + dumper.SubElement(e, 'child').append(dumper.Element('grandchild')) + e.append(dumper.Element('child')) + e.findall('.//grandchild')[0].set('attr', 'other value') + + e2 = self.pickleRoundTrip(e, 'xml.etree.ElementTree', + dumper, loader) + + self.assertEqual(e2.tag, 'foo') + self.assertEqual(e2.attrib['bar'], 42) + self.assertEqual(len(e2), 2) + self.assertEqualElements(e, e2) + class ElementTreeTest(unittest.TestCase): - - def serialize_check(self, elem, expected): - self.assertEqual(serialize(elem), expected) - - def test_interface(self): - # Test element tree interface. - - def check_string(string): - len(string) - for char in string: - self.assertEqual(len(char), 1, - msg="expected one-character string, got %r" % char) - new_string = string + "" - new_string = string + " " - string[:0] - - def check_mapping(mapping): - len(mapping) - keys = mapping.keys() - items = mapping.items() - for key in keys: - item = mapping[key] - mapping["key"] = "value" - self.assertEqual(mapping["key"], "value", - msg="expected value string, got %r" % mapping["key"]) - - def check_element(element): - self.assertTrue(ET.iselement(element), msg="not an element") - self.assertTrue(hasattr(element, "tag"), msg="no tag member") - self.assertTrue(hasattr(element, "attrib"), msg="no attrib member") - self.assertTrue(hasattr(element, "text"), msg="no text member") - self.assertTrue(hasattr(element, "tail"), msg="no tail member") - - check_string(element.tag) - check_mapping(element.attrib) - if element.text is not None: - check_string(element.text) - if element.tail is not None: - check_string(element.tail) - for elem in element: - check_element(elem) - - element = ET.Element("tag") - check_element(element) - tree = ET.ElementTree(element) - check_element(tree.getroot()) - element = ET.Element("t\xe4g", key="value") - tree = ET.ElementTree(element) - self.assertRegex(repr(element), r"^$") - element = ET.Element("tag", key="value") - - # Make sure all standard element methods exist. - - def check_method(method): - self.assertTrue(hasattr(method, '__call__'), - msg="%s not callable" % method) - - check_method(element.append) - check_method(element.extend) - check_method(element.insert) - check_method(element.remove) - check_method(element.getchildren) - check_method(element.find) - check_method(element.iterfind) - check_method(element.findall) - check_method(element.findtext) - check_method(element.clear) - check_method(element.get) - check_method(element.set) - check_method(element.keys) - check_method(element.items) - check_method(element.iter) - check_method(element.itertext) - check_method(element.getiterator) - - # These methods return an iterable. See bug 6472. - - def check_iter(it): - check_method(it.__next__) - - check_iter(element.iterfind("tag")) - check_iter(element.iterfind("*")) - check_iter(tree.iterfind("tag")) - check_iter(tree.iterfind("*")) - - # These aliases are provided: - - self.assertEqual(ET.XML, ET.fromstring) - self.assertEqual(ET.PI, ET.ProcessingInstruction) - - def test_simpleops(self): - # Basic method sanity checks. - - elem = ET.XML("") - self.serialize_check(elem, '') - e = ET.Element("tag2") - elem.append(e) - self.serialize_check(elem, '') - elem.remove(e) - self.serialize_check(elem, '') - elem.insert(0, e) - self.serialize_check(elem, '') - elem.remove(e) - elem.extend([e]) - self.serialize_check(elem, '') - elem.remove(e) - - element = ET.Element("tag", key="value") - self.serialize_check(element, '') # 1 - subelement = ET.Element("subtag") - element.append(subelement) - self.serialize_check(element, '') # 2 - element.insert(0, subelement) - self.serialize_check(element, - '') # 3 - element.remove(subelement) - self.serialize_check(element, '') # 4 - element.remove(subelement) - self.serialize_check(element, '') # 5 - with self.assertRaises(ValueError) as cm: - element.remove(subelement) - self.assertEqual(str(cm.exception), 'list.remove(x): x not in list') - self.serialize_check(element, '') # 6 - element[0:0] = [subelement, subelement, subelement] - self.serialize_check(element[1], '') - self.assertEqual(element[1:9], [element[1], element[2]]) - self.assertEqual(element[:9:2], [element[0], element[2]]) - del element[1:2] - self.serialize_check(element, - '') - - def test_cdata(self): - # Test CDATA handling (etc). - - self.serialize_check(ET.XML("hello"), - 'hello') - self.serialize_check(ET.XML("hello"), - 'hello') - self.serialize_check(ET.XML(""), - 'hello') - - def test_file_init(self): - stringfile = io.BytesIO(SAMPLE_XML.encode("utf-8")) - tree = ET.ElementTree(file=stringfile) - self.assertEqual(tree.find("tag").tag, 'tag') - self.assertEqual(tree.find("section/tag").tag, 'tag') - - tree = ET.ElementTree(file=SIMPLE_XMLFILE) - self.assertEqual(tree.find("element").tag, 'element') - self.assertEqual(tree.find("element/../empty-element").tag, - 'empty-element') - - def test_path_cache(self): - # Check that the path cache behaves sanely. - - from xml.etree import ElementPath - - elem = ET.XML(SAMPLE_XML) - for i in range(10): ET.ElementTree(elem).find('./'+str(i)) - cache_len_10 = len(ElementPath._cache) - for i in range(10): ET.ElementTree(elem).find('./'+str(i)) - self.assertEqual(len(ElementPath._cache), cache_len_10) - for i in range(20): ET.ElementTree(elem).find('./'+str(i)) - self.assertGreater(len(ElementPath._cache), cache_len_10) - for i in range(600): ET.ElementTree(elem).find('./'+str(i)) - self.assertLess(len(ElementPath._cache), 500) - - def test_copy(self): - # Test copy handling (etc). - - import copy - e1 = ET.XML("hello") - e2 = copy.copy(e1) - e3 = copy.deepcopy(e1) - e1.find("foo").tag = "bar" - self.serialize_check(e1, 'hello') - self.serialize_check(e2, 'hello') - self.serialize_check(e3, 'hello') - - def test_attrib(self): - # Test attribute handling. - - elem = ET.Element("tag") - elem.get("key") # 1.1 - self.assertEqual(elem.get("key", "default"), 'default') # 1.2 - - elem.set("key", "value") - self.assertEqual(elem.get("key"), 'value') # 1.3 - - elem = ET.Element("tag", key="value") - self.assertEqual(elem.get("key"), 'value') # 2.1 - self.assertEqual(elem.attrib, {'key': 'value'}) # 2.2 - - attrib = {"key": "value"} - elem = ET.Element("tag", attrib) - attrib.clear() # check for aliasing issues - self.assertEqual(elem.get("key"), 'value') # 3.1 - self.assertEqual(elem.attrib, {'key': 'value'}) # 3.2 - - attrib = {"key": "value"} - elem = ET.Element("tag", **attrib) - attrib.clear() # check for aliasing issues - self.assertEqual(elem.get("key"), 'value') # 4.1 - self.assertEqual(elem.attrib, {'key': 'value'}) # 4.2 - - elem = ET.Element("tag", {"key": "other"}, key="value") - self.assertEqual(elem.get("key"), 'value') # 5.1 - self.assertEqual(elem.attrib, {'key': 'value'}) # 5.2 - - elem = ET.Element('test') - elem.text = "aa" - elem.set('testa', 'testval') - elem.set('testb', 'test2') - self.assertEqual(ET.tostring(elem), - b'aa') - self.assertEqual(sorted(elem.keys()), ['testa', 'testb']) - self.assertEqual(sorted(elem.items()), - [('testa', 'testval'), ('testb', 'test2')]) - self.assertEqual(elem.attrib['testb'], 'test2') - elem.attrib['testb'] = 'test1' - elem.attrib['testc'] = 'test2' - self.assertEqual(ET.tostring(elem), - b'aa') - - def test_makeelement(self): - # Test makeelement handling. - - elem = ET.Element("tag") - attrib = {"key": "value"} - subelem = elem.makeelement("subtag", attrib) - self.assertIsNot(subelem.attrib, attrib, msg="attrib aliasing") - elem.append(subelem) - self.serialize_check(elem, '') - - elem.clear() - self.serialize_check(elem, '') - elem.append(subelem) - self.serialize_check(elem, '') - elem.extend([subelem, subelem]) - self.serialize_check(elem, - '') - elem[:] = [subelem] - self.serialize_check(elem, '') - elem[:] = tuple([subelem]) - self.serialize_check(elem, '') - - def test_parsefile(self): - # Test parsing from file. - - tree = ET.parse(SIMPLE_XMLFILE) - stream = io.StringIO() - tree.write(stream, encoding='unicode') - self.assertEqual(stream.getvalue(), - '\n' - ' text\n' - ' texttail\n' - ' \n' - '') - tree = ET.parse(SIMPLE_NS_XMLFILE) - stream = io.StringIO() - tree.write(stream, encoding='unicode') - self.assertEqual(stream.getvalue(), - '\n' - ' text\n' - ' texttail\n' - ' \n' - '') - - with open(SIMPLE_XMLFILE) as f: - data = f.read() - - parser = ET.XMLParser() - self.assertRegex(parser.version, r'^Expat ') - parser.feed(data) - self.serialize_check(parser.close(), - '\n' - ' text\n' - ' texttail\n' - ' \n' - '') - - target = ET.TreeBuilder() - parser = ET.XMLParser(target=target) - parser.feed(data) - self.serialize_check(parser.close(), - '\n' - ' text\n' - ' texttail\n' - ' \n' - '') - - def test_parseliteral(self): - element = ET.XML("text") - self.assertEqual(ET.tostring(element, encoding='unicode'), - 'text') - element = ET.fromstring("text") - self.assertEqual(ET.tostring(element, encoding='unicode'), - 'text') - sequence = ["", "text"] - element = ET.fromstringlist(sequence) - self.assertEqual(ET.tostring(element), - b'text') - self.assertEqual(b"".join(ET.tostringlist(element)), - b'text') - self.assertEqual(ET.tostring(element, "ascii"), - b"\n" - b"text") - _, ids = ET.XMLID("text") - self.assertEqual(len(ids), 0) - _, ids = ET.XMLID("text") - self.assertEqual(len(ids), 1) - self.assertEqual(ids["body"].tag, 'body') - - def test_iterparse(self): - # Test iterparse interface. - - iterparse = ET.iterparse - - context = iterparse(SIMPLE_XMLFILE) - action, elem = next(context) - self.assertEqual((action, elem.tag), ('end', 'element')) - self.assertEqual([(action, elem.tag) for action, elem in context], [ - ('end', 'element'), - ('end', 'empty-element'), - ('end', 'root'), - ]) - self.assertEqual(context.root.tag, 'root') - - context = iterparse(SIMPLE_NS_XMLFILE) - self.assertEqual([(action, elem.tag) for action, elem in context], [ - ('end', '{namespace}element'), - ('end', '{namespace}element'), - ('end', '{namespace}empty-element'), - ('end', '{namespace}root'), - ]) - - events = () - context = iterparse(SIMPLE_XMLFILE, events) - self.assertEqual([(action, elem.tag) for action, elem in context], []) - - events = () - context = iterparse(SIMPLE_XMLFILE, events=events) - self.assertEqual([(action, elem.tag) for action, elem in context], []) - - events = ("start", "end") - context = iterparse(SIMPLE_XMLFILE, events) - self.assertEqual([(action, elem.tag) for action, elem in context], [ - ('start', 'root'), - ('start', 'element'), - ('end', 'element'), - ('start', 'element'), - ('end', 'element'), - ('start', 'empty-element'), - ('end', 'empty-element'), - ('end', 'root'), - ]) - - events = ("start", "end", "start-ns", "end-ns") - context = iterparse(SIMPLE_NS_XMLFILE, events) - self.assertEqual([(action, elem.tag) if action in ("start", "end") - else (action, elem) - for action, elem in context], [ - ('start-ns', ('', 'namespace')), - ('start', '{namespace}root'), - ('start', '{namespace}element'), - ('end', '{namespace}element'), - ('start', '{namespace}element'), - ('end', '{namespace}element'), - ('start', '{namespace}empty-element'), - ('end', '{namespace}empty-element'), - ('end', '{namespace}root'), - ('end-ns', None), - ]) - - events = ("start", "end", "bogus") - with self.assertRaises(ValueError) as cm: - with open(SIMPLE_XMLFILE, "rb") as f: - iterparse(f, events) - self.assertEqual(str(cm.exception), "unknown event 'bogus'") - - source = io.BytesIO( - b"\n" - b"text\n") - events = ("start-ns",) - context = iterparse(source, events) - self.assertEqual([(action, elem) for action, elem in context], [ - ('start-ns', ('', 'http://\xe9ffbot.org/ns')), - ('start-ns', ('cl\xe9', 'http://effbot.org/ns')), - ]) - - source = io.StringIO("junk") - it = iterparse(source) - action, elem = next(it) - self.assertEqual((action, elem.tag), ('end', 'document')) - with self.assertRaises(ET.ParseError) as cm: - next(it) - self.assertEqual(str(cm.exception), - 'junk after document element: line 1, column 12') - - def test_writefile(self): - elem = ET.Element("tag") - elem.text = "text" - self.serialize_check(elem, 'text') - ET.SubElement(elem, "subtag").text = "subtext" - self.serialize_check(elem, 'textsubtext') - - # Test tag suppression - elem.tag = None - self.serialize_check(elem, 'textsubtext') - elem.insert(0, ET.Comment("comment")) - self.serialize_check(elem, - 'textsubtext') # assumes 1.3 - - elem[0] = ET.PI("key", "value") - self.serialize_check(elem, 'textsubtext') - - def test_custom_builder(self): - # Test parser w. custom builder. - - with open(SIMPLE_XMLFILE) as f: - data = f.read() - class Builder(list): - def start(self, tag, attrib): - self.append(("start", tag)) - def end(self, tag): - self.append(("end", tag)) - def data(self, text): - pass - builder = Builder() - parser = ET.XMLParser(target=builder) - parser.feed(data) - self.assertEqual(builder, [ - ('start', 'root'), - ('start', 'element'), - ('end', 'element'), - ('start', 'element'), - ('end', 'element'), - ('start', 'empty-element'), - ('end', 'empty-element'), - ('end', 'root'), - ]) - - with open(SIMPLE_NS_XMLFILE) as f: - data = f.read() - class Builder(list): - def start(self, tag, attrib): - self.append(("start", tag)) - def end(self, tag): - self.append(("end", tag)) - def data(self, text): - pass - def pi(self, target, data): - self.append(("pi", target, data)) - def comment(self, data): - self.append(("comment", data)) - builder = Builder() - parser = ET.XMLParser(target=builder) - parser.feed(data) - self.assertEqual(builder, [ - ('pi', 'pi', 'data'), - ('comment', ' comment '), - ('start', '{namespace}root'), - ('start', '{namespace}element'), - ('end', '{namespace}element'), - ('start', '{namespace}element'), - ('end', '{namespace}element'), - ('start', '{namespace}empty-element'), - ('end', '{namespace}empty-element'), - ('end', '{namespace}root'), - ]) - - - def test_getchildren(self): - # Test Element.getchildren() - - with open(SIMPLE_XMLFILE, "rb") as f: - tree = ET.parse(f) - self.assertEqual([summarize_list(elem.getchildren()) - for elem in tree.getroot().iter()], [ - ['element', 'element', 'empty-element'], - [], - [], - [], - ]) - self.assertEqual([summarize_list(elem.getchildren()) - for elem in tree.getiterator()], [ - ['element', 'element', 'empty-element'], - [], - [], - [], - ]) - - elem = ET.XML(SAMPLE_XML) - self.assertEqual(len(elem.getchildren()), 3) - self.assertEqual(len(elem[2].getchildren()), 1) - self.assertEqual(elem[:], elem.getchildren()) - child1 = elem[0] - child2 = elem[2] - del elem[1:2] - self.assertEqual(len(elem.getchildren()), 2) - self.assertEqual(child1, elem[0]) - self.assertEqual(child2, elem[1]) - elem[0:2] = [child2, child1] - self.assertEqual(child2, elem[0]) - self.assertEqual(child1, elem[1]) - self.assertNotEqual(child1, elem[0]) - elem.clear() - self.assertEqual(elem.getchildren(), []) - - def test_writestring(self): - elem = ET.XML("text") - self.assertEqual(ET.tostring(elem), b'text') - elem = ET.fromstring("text") - self.assertEqual(ET.tostring(elem), b'text') - - def test_encoding(self): - def check(encoding, body=''): - xml = ("%s" % - (encoding, body)) - self.assertEqual(ET.XML(xml.encode(encoding)).text, body) - self.assertEqual(ET.XML(xml).text, body) - check("ascii", 'a') - check("us-ascii", 'a') - check("iso-8859-1", '\xbd') - check("iso-8859-15", '\u20ac') - check("cp437", '\u221a') - check("mac-roman", '\u02da') - - def xml(encoding): - return "" % encoding - def bxml(encoding): - return xml(encoding).encode(encoding) - supported_encodings = [ - 'ascii', 'utf-8', 'utf-8-sig', 'utf-16', 'utf-16be', 'utf-16le', - 'iso8859-1', 'iso8859-2', 'iso8859-3', 'iso8859-4', 'iso8859-5', - 'iso8859-6', 'iso8859-7', 'iso8859-8', 'iso8859-9', 'iso8859-10', - 'iso8859-13', 'iso8859-14', 'iso8859-15', 'iso8859-16', - 'cp437', 'cp720', 'cp737', 'cp775', 'cp850', 'cp852', - 'cp855', 'cp856', 'cp857', 'cp858', 'cp860', 'cp861', 'cp862', - 'cp863', 'cp865', 'cp866', 'cp869', 'cp874', 'cp1006', 'cp1250', - 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', 'cp1256', - 'cp1257', 'cp1258', - 'mac-cyrillic', 'mac-greek', 'mac-iceland', 'mac-latin2', - 'mac-roman', 'mac-turkish', - 'iso2022-jp', 'iso2022-jp-1', 'iso2022-jp-2', 'iso2022-jp-2004', - 'iso2022-jp-3', 'iso2022-jp-ext', - 'koi8-r', 'koi8-u', - 'hz', 'ptcp154', - ] - for encoding in supported_encodings: - self.assertEqual(ET.tostring(ET.XML(bxml(encoding))), b'') - - unsupported_ascii_compatible_encodings = [ - 'big5', 'big5hkscs', - 'cp932', 'cp949', 'cp950', - 'euc-jp', 'euc-jis-2004', 'euc-jisx0213', 'euc-kr', - 'gb2312', 'gbk', 'gb18030', - 'iso2022-kr', 'johab', - 'shift-jis', 'shift-jis-2004', 'shift-jisx0213', - 'utf-7', - ] - for encoding in unsupported_ascii_compatible_encodings: - self.assertRaises(ValueError, ET.XML, bxml(encoding)) - - unsupported_ascii_incompatible_encodings = [ - 'cp037', 'cp424', 'cp500', 'cp864', 'cp875', 'cp1026', 'cp1140', - 'utf_32', 'utf_32_be', 'utf_32_le', - ] - for encoding in unsupported_ascii_incompatible_encodings: - self.assertRaises(ET.ParseError, ET.XML, bxml(encoding)) - - self.assertRaises(ValueError, ET.XML, xml('undefined').encode('ascii')) - self.assertRaises(LookupError, ET.XML, xml('xxx').encode('ascii')) - - def test_methods(self): - # Test serialization methods. - - e = ET.XML("") - e.tail = "\n" - self.assertEqual(serialize(e), - '\n') - self.assertEqual(serialize(e, method=None), - '\n') - self.assertEqual(serialize(e, method="xml"), - '\n') - self.assertEqual(serialize(e, method="html"), - '\n') - self.assertEqual(serialize(e, method="text"), '1 < 2\n') - - def test_issue18347(self): - e = ET.XML('text') - self.assertEqual(serialize(e), - 'text') - self.assertEqual(serialize(e, method="html"), - 'text') - - def test_entity(self): - # Test entity handling. - - # 1) good entities - - e = ET.XML("test") - self.assertEqual(serialize(e, encoding="us-ascii"), - b'test') - self.serialize_check(e, 'test') - - # 2) bad entities - - with self.assertRaises(ET.ParseError) as cm: - ET.XML("&entity;") - self.assertEqual(str(cm.exception), - 'undefined entity: line 1, column 10') - - with self.assertRaises(ET.ParseError) as cm: - ET.XML(ENTITY_XML) - self.assertEqual(str(cm.exception), - 'undefined entity &entity;: line 5, column 10') - - # 3) custom entity - - parser = ET.XMLParser() - parser.entity["entity"] = "text" - parser.feed(ENTITY_XML) - root = parser.close() - self.serialize_check(root, 'text') - - def test_namespace(self): - # Test namespace issues. - - # 1) xml namespace - - elem = ET.XML("") - self.serialize_check(elem, '') # 1.1 - - # 2) other "well-known" namespaces - - elem = ET.XML("") - self.serialize_check(elem, - '') # 2.1 - - elem = ET.XML("") - self.serialize_check(elem, - '') # 2.2 - - elem = ET.XML("") - self.serialize_check(elem, - '') # 2.3 - - # 3) unknown namespaces - elem = ET.XML(SAMPLE_XML_NS) - self.serialize_check(elem, - '\n' - ' text\n' - ' \n' - ' \n' - ' subtext\n' - ' \n' - '') - - def test_qname(self): - # Test QName handling. - - # 1) decorated tags - - elem = ET.Element("{uri}tag") - self.serialize_check(elem, '') # 1.1 - elem = ET.Element(ET.QName("{uri}tag")) - self.serialize_check(elem, '') # 1.2 - elem = ET.Element(ET.QName("uri", "tag")) - self.serialize_check(elem, '') # 1.3 - elem = ET.Element(ET.QName("uri", "tag")) - subelem = ET.SubElement(elem, ET.QName("uri", "tag1")) - subelem = ET.SubElement(elem, ET.QName("uri", "tag2")) - self.serialize_check(elem, - '') # 1.4 - - # 2) decorated attributes - - elem.clear() - elem.attrib["{uri}key"] = "value" - self.serialize_check(elem, - '') # 2.1 - - elem.clear() - elem.attrib[ET.QName("{uri}key")] = "value" - self.serialize_check(elem, - '') # 2.2 - - # 3) decorated values are not converted by default, but the - # QName wrapper can be used for values - - elem.clear() - elem.attrib["{uri}key"] = "{uri}value" - self.serialize_check(elem, - '') # 3.1 - - elem.clear() - elem.attrib["{uri}key"] = ET.QName("{uri}value") - self.serialize_check(elem, - '') # 3.2 - - elem.clear() - subelem = ET.Element("tag") - subelem.attrib["{uri1}key"] = ET.QName("{uri2}value") - elem.append(subelem) - elem.append(subelem) - self.serialize_check(elem, - '' - '' - '' - '') # 3.3 - - # 4) Direct QName tests - - self.assertEqual(str(ET.QName('ns', 'tag')), '{ns}tag') - self.assertEqual(str(ET.QName('{ns}tag')), '{ns}tag') - q1 = ET.QName('ns', 'tag') - q2 = ET.QName('ns', 'tag') - self.assertEqual(q1, q2) - q2 = ET.QName('ns', 'other-tag') - self.assertNotEqual(q1, q2) - self.assertNotEqual(q1, 'ns:tag') - self.assertEqual(q1, '{ns}tag') - - def test_doctype_public(self): - # Test PUBLIC doctype. - - elem = ET.XML('' - 'text') - - def test_xpath_tokenizer(self): - # Test the XPath tokenizer. - from xml.etree import ElementPath - def check(p, expected): - self.assertEqual([op or tag - for op, tag in ElementPath.xpath_tokenizer(p)], - expected) - - # tests from the xml specification - check("*", ['*']) - check("text()", ['text', '()']) - check("@name", ['@', 'name']) - check("@*", ['@', '*']) - check("para[1]", ['para', '[', '1', ']']) - check("para[last()]", ['para', '[', 'last', '()', ']']) - check("*/para", ['*', '/', 'para']) - check("/doc/chapter[5]/section[2]", - ['/', 'doc', '/', 'chapter', '[', '5', ']', - '/', 'section', '[', '2', ']']) - check("chapter//para", ['chapter', '//', 'para']) - check("//para", ['//', 'para']) - check("//olist/item", ['//', 'olist', '/', 'item']) - check(".", ['.']) - check(".//para", ['.', '//', 'para']) - check("..", ['..']) - check("../@lang", ['..', '/', '@', 'lang']) - check("chapter[title]", ['chapter', '[', 'title', ']']) - check("employee[@secretary and @assistant]", ['employee', - '[', '@', 'secretary', '', 'and', '', '@', 'assistant', ']']) - - # additional tests - check("{http://spam}egg", ['{http://spam}egg']) - check("./spam.egg", ['.', '/', 'spam.egg']) - check(".//{http://spam}egg", ['.', '//', '{http://spam}egg']) - - def test_processinginstruction(self): - # Test ProcessingInstruction directly - - self.assertEqual(ET.tostring(ET.ProcessingInstruction('test', 'instruction')), - b'') - self.assertEqual(ET.tostring(ET.PI('test', 'instruction')), - b'') - - # Issue #2746 - - self.assertEqual(ET.tostring(ET.PI('test', '')), - b'?>') - self.assertEqual(ET.tostring(ET.PI('test', '\xe3'), 'latin-1'), - b"\n" - b"\xe3?>") + def test_istype(self): + self.assertIsInstance(ET.ParseError, type) + self.assertIsInstance(ET.QName, type) + self.assertIsInstance(ET.ElementTree, type) + self.assertIsInstance(ET.Element, type) + self.assertIsInstance(ET.TreeBuilder, type) + self.assertIsInstance(ET.XMLParser, type) + + def test_Element_subclass_trivial(self): + class MyElement(ET.Element): + pass + + mye = MyElement('foo') + self.assertIsInstance(mye, ET.Element) + self.assertIsInstance(mye, MyElement) + self.assertEqual(mye.tag, 'foo') + + # test that attribute assignment works (issue 14849) + mye.text = "joe" + self.assertEqual(mye.text, "joe") + + def test_Element_subclass_constructor(self): + class MyElement(ET.Element): + def __init__(self, tag, attrib={}, **extra): + super(MyElement, self).__init__(tag + '__', attrib, **extra) + + mye = MyElement('foo', {'a': 1, 'b': 2}, c=3, d=4) + self.assertEqual(mye.tag, 'foo__') + self.assertEqual(sorted(mye.items()), + [('a', 1), ('b', 2), ('c', 3), ('d', 4)]) + + def test_Element_subclass_new_method(self): + class MyElement(ET.Element): + def newmethod(self): + return self.tag + + mye = MyElement('joe') + self.assertEqual(mye.newmethod(), 'joe') def test_html_empty_elems_serialization(self): # issue 15970 @@ -950,795 +1752,6 @@ self.assertEqual(serialized, expected) -class IncrementalParserTest(unittest.TestCase): - - def _feed(self, parser, data, chunk_size=None): - if chunk_size is None: - parser.data_received(data) - else: - for i in range(0, len(data), chunk_size): - parser.data_received(data[i:i+chunk_size]) - - def assert_event_tags(self, parser, expected): - events = parser.events() - self.assertEqual([(action, elem.tag) for action, elem in events], - expected) - - def test_simple_xml(self): - for chunk_size in (None, 1, 5): - with self.subTest(chunk_size=chunk_size): - parser = ET.IncrementalParser() - self.assert_event_tags(parser, []) - self._feed(parser, "\n", chunk_size) - self.assert_event_tags(parser, []) - self._feed(parser, - "\n text\n", chunk_size) - self.assert_event_tags(parser, [('end', 'element')]) - self._feed(parser, "texttail\n", chunk_size) - self._feed(parser, "\n", chunk_size) - self.assert_event_tags(parser, [ - ('end', 'element'), - ('end', 'empty-element'), - ]) - self._feed(parser, "\n", chunk_size) - self.assert_event_tags(parser, [('end', 'root')]) - # Receiving EOF sets the `root` attribute - self.assertIs(parser.root, None) - parser.eof_received() - self.assertEqual(parser.root.tag, 'root') - - def test_data_received_while_iterating(self): - parser = ET.IncrementalParser() - it = parser.events() - self._feed(parser, "\n text\n") - action, elem = next(it) - self.assertEqual((action, elem.tag), ('end', 'element')) - self._feed(parser, "\n") - action, elem = next(it) - self.assertEqual((action, elem.tag), ('end', 'root')) - with self.assertRaises(StopIteration): - next(it) - - def test_simple_xml_with_ns(self): - parser = ET.IncrementalParser() - self.assert_event_tags(parser, []) - self._feed(parser, "\n") - self.assert_event_tags(parser, []) - self._feed(parser, "\n") - self.assert_event_tags(parser, []) - self._feed(parser, "text\n") - self.assert_event_tags(parser, [('end', '{namespace}element')]) - self._feed(parser, "texttail\n") - self._feed(parser, "\n") - self.assert_event_tags(parser, [ - ('end', '{namespace}element'), - ('end', '{namespace}empty-element'), - ]) - self._feed(parser, "\n") - self.assert_event_tags(parser, [('end', '{namespace}root')]) - # Receiving EOF sets the `root` attribute - self.assertIs(parser.root, None) - parser.eof_received() - self.assertEqual(parser.root.tag, '{namespace}root') - - def test_ns_events(self): - parser = ET.IncrementalParser(events=('start-ns', 'end-ns')) - self._feed(parser, "\n") - self._feed(parser, "\n") - self.assertEqual( - list(parser.events()), - [('start-ns', ('', 'namespace'))]) - self._feed(parser, "text\n") - self._feed(parser, "texttail\n") - self._feed(parser, "\n") - self._feed(parser, "\n") - self.assertEqual(list(parser.events()), [('end-ns', None)]) - parser.eof_received() - - def test_events(self): - parser = ET.IncrementalParser(events=()) - self._feed(parser, "\n") - self.assert_event_tags(parser, []) - - parser = ET.IncrementalParser(events=('start', 'end')) - self._feed(parser, "\n") - self.assert_event_tags(parser, []) - self._feed(parser, "\n") - self.assert_event_tags(parser, [('start', 'root')]) - self._feed(parser, "text\n") - self.assert_event_tags(parser, [('end', 'element')]) - self._feed(parser, - "texttail\n") - self.assert_event_tags(parser, [ - ('start', '{foo}element'), - ('start', '{foo}empty-element'), - ('end', '{foo}empty-element'), - ('end', '{foo}element'), - ]) - self._feed(parser, "") - parser.eof_received() - self.assertIs(parser.root, None) - self.assert_event_tags(parser, [('end', 'root')]) - self.assertEqual(parser.root.tag, 'root') - - parser = ET.IncrementalParser(events=('start',)) - self._feed(parser, "\n") - self.assert_event_tags(parser, []) - self._feed(parser, "\n") - self.assert_event_tags(parser, [('start', 'root')]) - self._feed(parser, "text\n") - self.assert_event_tags(parser, []) - self._feed(parser, - "texttail\n") - self.assert_event_tags(parser, [ - ('start', '{foo}element'), - ('start', '{foo}empty-element'), - ]) - self._feed(parser, "") - parser.eof_received() - self.assertEqual(parser.root.tag, 'root') - - def test_events_sequence(self): - # Test that events can be some sequence that's not just a tuple or list - eventset = {'end', 'start'} - parser = ET.IncrementalParser(events=eventset) - self._feed(parser, "bar") - self.assert_event_tags(parser, [('start', 'foo'), ('end', 'foo')]) - - class DummyIter: - def __init__(self): - self.events = iter(['start', 'end', 'start-ns']) - def __iter__(self): - return self - def __next__(self): - return next(self.events) - - parser = ET.IncrementalParser(events=DummyIter()) - self._feed(parser, "bar") - self.assert_event_tags(parser, [('start', 'foo'), ('end', 'foo')]) - - - def test_unknown_event(self): - with self.assertRaises(ValueError): - ET.IncrementalParser(events=('start', 'end', 'bogus')) - - -# -# xinclude tests (samples from appendix C of the xinclude specification) - -XINCLUDE = {} - -XINCLUDE["C1.xml"] = """\ - - -

120 Mz is adequate for an average home user.

- -
-""" - -XINCLUDE["disclaimer.xml"] = """\ - - -

The opinions represented herein represent those of the individual - and should not be interpreted as official policy endorsed by this - organization.

-
-""" - -XINCLUDE["C2.xml"] = """\ - - -

This document has been accessed - times.

-
-""" - -XINCLUDE["count.txt"] = "324387" - -XINCLUDE["C2b.xml"] = """\ - - -

This document has been accessed - times.

-
-""" - -XINCLUDE["C3.xml"] = """\ - - -

The following is the source of the "data.xml" resource:

- -
-""" - -XINCLUDE["data.xml"] = """\ - - - - -""" - -XINCLUDE["C5.xml"] = """\ - -
- - - - Report error - - - -
-""" - -XINCLUDE["default.xml"] = """\ - - -

Example.

- -
-""".format(html.escape(SIMPLE_XMLFILE, True)) - -# -# badly formatted xi:include tags - -XINCLUDE_BAD = {} - -XINCLUDE_BAD["B1.xml"] = """\ - - -

120 Mz is adequate for an average home user.

- -
-""" - -XINCLUDE_BAD["B2.xml"] = """\ - -
- -
-""" - -class XIncludeTest(unittest.TestCase): - - def xinclude_loader(self, href, parse="xml", encoding=None): - try: - data = XINCLUDE[href] - except KeyError: - raise OSError("resource not found") - if parse == "xml": - data = ET.XML(data) - return data - - def none_loader(self, href, parser, encoding=None): - return None - - def _my_loader(self, href, parse): - # Used to avoid a test-dependency problem where the default loader - # of ElementInclude uses the pyET parser for cET tests. - if parse == 'xml': - with open(href, 'rb') as f: - return ET.parse(f).getroot() - else: - return None - - def test_xinclude_default(self): - from xml.etree import ElementInclude - doc = self.xinclude_loader('default.xml') - ElementInclude.include(doc, self._my_loader) - self.assertEqual(serialize(doc), - '\n' - '

Example.

\n' - ' \n' - ' text\n' - ' texttail\n' - ' \n' - '\n' - '
') - - def test_xinclude(self): - from xml.etree import ElementInclude - - # Basic inclusion example (XInclude C.1) - document = self.xinclude_loader("C1.xml") - ElementInclude.include(document, self.xinclude_loader) - self.assertEqual(serialize(document), - '\n' - '

120 Mz is adequate for an average home user.

\n' - ' \n' - '

The opinions represented herein represent those of the individual\n' - ' and should not be interpreted as official policy endorsed by this\n' - ' organization.

\n' - '
\n' - '
') # C1 - - # Textual inclusion example (XInclude C.2) - document = self.xinclude_loader("C2.xml") - ElementInclude.include(document, self.xinclude_loader) - self.assertEqual(serialize(document), - '\n' - '

This document has been accessed\n' - ' 324387 times.

\n' - '
') # C2 - - # Textual inclusion after sibling element (based on modified XInclude C.2) - document = self.xinclude_loader("C2b.xml") - ElementInclude.include(document, self.xinclude_loader) - self.assertEqual(serialize(document), - '\n' - '

This document has been accessed\n' - ' 324387 times.

\n' - '
') # C2b - - # Textual inclusion of XML example (XInclude C.3) - document = self.xinclude_loader("C3.xml") - ElementInclude.include(document, self.xinclude_loader) - self.assertEqual(serialize(document), - '\n' - '

The following is the source of the "data.xml" resource:

\n' - " <?xml version='1.0'?>\n" - '<data>\n' - ' <item><![CDATA[Brooks & Shields]]></item>\n' - '</data>\n' - '\n' - '
') # C3 - - # Fallback example (XInclude C.5) - # Note! Fallback support is not yet implemented - document = self.xinclude_loader("C5.xml") - with self.assertRaises(OSError) as cm: - ElementInclude.include(document, self.xinclude_loader) - self.assertEqual(str(cm.exception), 'resource not found') - self.assertEqual(serialize(document), - '
\n' - ' \n' - ' \n' - ' \n' - ' Report error\n' - ' \n' - ' \n' - ' \n' - '
') # C5 - - def test_xinclude_failures(self): - from xml.etree import ElementInclude - - # Test failure to locate included XML file. - document = ET.XML(XINCLUDE["C1.xml"]) - with self.assertRaises(ElementInclude.FatalIncludeError) as cm: - ElementInclude.include(document, loader=self.none_loader) - self.assertEqual(str(cm.exception), - "cannot load 'disclaimer.xml' as 'xml'") - - # Test failure to locate included text file. - document = ET.XML(XINCLUDE["C2.xml"]) - with self.assertRaises(ElementInclude.FatalIncludeError) as cm: - ElementInclude.include(document, loader=self.none_loader) - self.assertEqual(str(cm.exception), - "cannot load 'count.txt' as 'text'") - - # Test bad parse type. - document = ET.XML(XINCLUDE_BAD["B1.xml"]) - with self.assertRaises(ElementInclude.FatalIncludeError) as cm: - ElementInclude.include(document, loader=self.none_loader) - self.assertEqual(str(cm.exception), - "unknown parse type in xi:include tag ('BAD_TYPE')") - - # Test xi:fallback outside xi:include. - document = ET.XML(XINCLUDE_BAD["B2.xml"]) - with self.assertRaises(ElementInclude.FatalIncludeError) as cm: - ElementInclude.include(document, loader=self.none_loader) - self.assertEqual(str(cm.exception), - "xi:fallback tag must be child of xi:include " - "('{http://www.w3.org/2001/XInclude}fallback')") - -# -------------------------------------------------------------------- -# reported bugs - -class BugsTest(unittest.TestCase): - - def test_bug_xmltoolkit21(self): - # marshaller gives obscure errors for non-string values - - def check(elem): - with self.assertRaises(TypeError) as cm: - serialize(elem) - self.assertEqual(str(cm.exception), - 'cannot serialize 123 (type int)') - - elem = ET.Element(123) - check(elem) # tag - - elem = ET.Element("elem") - elem.text = 123 - check(elem) # text - - elem = ET.Element("elem") - elem.tail = 123 - check(elem) # tail - - elem = ET.Element("elem") - elem.set(123, "123") - check(elem) # attribute key - - elem = ET.Element("elem") - elem.set("123", 123) - check(elem) # attribute value - - def test_bug_xmltoolkit25(self): - # typo in ElementTree.findtext - - elem = ET.XML(SAMPLE_XML) - tree = ET.ElementTree(elem) - self.assertEqual(tree.findtext("tag"), 'text') - self.assertEqual(tree.findtext("section/tag"), 'subtext') - - def test_bug_xmltoolkit28(self): - # .//tag causes exceptions - - tree = ET.XML("
") - self.assertEqual(summarize_list(tree.findall(".//thead")), []) - self.assertEqual(summarize_list(tree.findall(".//tbody")), ['tbody']) - - def test_bug_xmltoolkitX1(self): - # dump() doesn't flush the output buffer - - tree = ET.XML("
") - with support.captured_stdout() as stdout: - ET.dump(tree) - self.assertEqual(stdout.getvalue(), '
\n') - - def test_bug_xmltoolkit39(self): - # non-ascii element and attribute names doesn't work - - tree = ET.XML(b"") - self.assertEqual(ET.tostring(tree, "utf-8"), b'') - - tree = ET.XML(b"" - b"") - self.assertEqual(tree.attrib, {'\xe4ttr': 'v\xe4lue'}) - self.assertEqual(ET.tostring(tree, "utf-8"), - b'') - - tree = ET.XML(b"" - b'text') - self.assertEqual(ET.tostring(tree, "utf-8"), - b'text') - - tree = ET.Element("t\u00e4g") - self.assertEqual(ET.tostring(tree, "utf-8"), b'') - - tree = ET.Element("tag") - tree.set("\u00e4ttr", "v\u00e4lue") - self.assertEqual(ET.tostring(tree, "utf-8"), - b'') - - def test_bug_xmltoolkit54(self): - # problems handling internally defined entities - - e = ET.XML("]>" - '&ldots;') - self.assertEqual(serialize(e, encoding="us-ascii"), - b'') - self.assertEqual(serialize(e), '\u8230') - - def test_bug_xmltoolkit55(self): - # make sure we're reporting the first error, not the last - - with self.assertRaises(ET.ParseError) as cm: - ET.XML(b"" - b'&ldots;&ndots;&rdots;') - self.assertEqual(str(cm.exception), - 'undefined entity &ldots;: line 1, column 36') - - def test_bug_xmltoolkit60(self): - # Handle crash in stream source. - - class ExceptionFile: - def read(self, x): - raise OSError - - self.assertRaises(OSError, ET.parse, ExceptionFile()) - - def test_bug_xmltoolkit62(self): - # Don't crash when using custom entities. - - ENTITIES = {'rsquo': '\u2019', 'lsquo': '\u2018'} - parser = ET.XMLParser() - parser.entity.update(ENTITIES) - parser.feed(""" - - - -A new cultivar of Begonia plant named ‘BCT9801BEG’. - -""") - t = parser.close() - self.assertEqual(t.find('.//paragraph').text, - 'A new cultivar of Begonia plant named \u2018BCT9801BEG\u2019.') - - def test_bug_xmltoolkit63(self): - # Check reference leak. - def xmltoolkit63(): - tree = ET.TreeBuilder() - tree.start("tag", {}) - tree.data("text") - tree.end("tag") - - xmltoolkit63() - count = sys.getrefcount(None) - for i in range(1000): - xmltoolkit63() - self.assertEqual(sys.getrefcount(None), count) - - def test_bug_200708_newline(self): - # Preserve newlines in attributes. - - e = ET.Element('SomeTag', text="def _f():\n return 3\n") - self.assertEqual(ET.tostring(e), - b'') - self.assertEqual(ET.XML(ET.tostring(e)).get("text"), - 'def _f():\n return 3\n') - self.assertEqual(ET.tostring(ET.XML(ET.tostring(e))), - b'') - - def test_bug_200708_close(self): - # Test default builder. - parser = ET.XMLParser() # default - parser.feed("some text") - self.assertEqual(parser.close().tag, 'element') - - # Test custom builder. - class EchoTarget: - def close(self): - return ET.Element("element") # simulate root - parser = ET.XMLParser(EchoTarget()) - parser.feed("some text") - self.assertEqual(parser.close().tag, 'element') - - def test_bug_200709_default_namespace(self): - e = ET.Element("{default}elem") - s = ET.SubElement(e, "{default}elem") - self.assertEqual(serialize(e, default_namespace="default"), # 1 - '') - - e = ET.Element("{default}elem") - s = ET.SubElement(e, "{default}elem") - s = ET.SubElement(e, "{not-default}elem") - self.assertEqual(serialize(e, default_namespace="default"), # 2 - '' - '' - '' - '') - - e = ET.Element("{default}elem") - s = ET.SubElement(e, "{default}elem") - s = ET.SubElement(e, "elem") # unprefixed name - with self.assertRaises(ValueError) as cm: - serialize(e, default_namespace="default") # 3 - self.assertEqual(str(cm.exception), - 'cannot use non-qualified names with default_namespace option') - - def test_bug_200709_register_namespace(self): - e = ET.Element("{http://namespace.invalid/does/not/exist/}title") - self.assertEqual(ET.tostring(e), - b'') - ET.register_namespace("foo", "http://namespace.invalid/does/not/exist/") - e = ET.Element("{http://namespace.invalid/does/not/exist/}title") - self.assertEqual(ET.tostring(e), - b'') - - # And the Dublin Core namespace is in the default list: - - e = ET.Element("{http://purl.org/dc/elements/1.1/}title") - self.assertEqual(ET.tostring(e), - b'') - - def test_bug_200709_element_comment(self): - # Not sure if this can be fixed, really (since the serializer needs - # ET.Comment, not cET.comment). - - a = ET.Element('a') - a.append(ET.Comment('foo')) - self.assertEqual(a[0].tag, ET.Comment) - - a = ET.Element('a') - a.append(ET.PI('foo')) - self.assertEqual(a[0].tag, ET.PI) - - def test_bug_200709_element_insert(self): - a = ET.Element('a') - b = ET.SubElement(a, 'b') - c = ET.SubElement(a, 'c') - d = ET.Element('d') - a.insert(0, d) - self.assertEqual(summarize_list(a), ['d', 'b', 'c']) - a.insert(-1, d) - self.assertEqual(summarize_list(a), ['d', 'b', 'd', 'c']) - - def test_bug_200709_iter_comment(self): - a = ET.Element('a') - b = ET.SubElement(a, 'b') - comment_b = ET.Comment("TEST-b") - b.append(comment_b) - self.assertEqual(summarize_list(a.iter(ET.Comment)), [ET.Comment]) - - # -------------------------------------------------------------------- - # reported on bugs.python.org - - def test_bug_1534630(self): - bob = ET.TreeBuilder() - e = bob.data("data") - e = bob.start("tag", {}) - e = bob.end("tag") - e = bob.close() - self.assertEqual(serialize(e), '') - - def test_issue6233(self): - e = ET.XML(b"" - b't\xc3\xa3g') - self.assertEqual(ET.tostring(e, 'ascii'), - b"\n" - b'tãg') - e = ET.XML(b"" - b't\xe3g') - self.assertEqual(ET.tostring(e, 'ascii'), - b"\n" - b'tãg') - - def test_issue3151(self): - e = ET.XML('') - self.assertEqual(e.tag, '{${stuff}}localname') - t = ET.ElementTree(e) - self.assertEqual(ET.tostring(e), b'') - - def test_issue6565(self): - elem = ET.XML("") - self.assertEqual(summarize_list(elem), ['tag']) - newelem = ET.XML(SAMPLE_XML) - elem[:] = newelem[:] - self.assertEqual(summarize_list(elem), ['tag', 'tag', 'section']) - - def test_issue10777(self): - # Registering a namespace twice caused a "dictionary changed size during - # iteration" bug. - - ET.register_namespace('test10777', 'http://myuri/') - ET.register_namespace('test10777', 'http://myuri/') - - -# -------------------------------------------------------------------- - - -class BasicElementTest(ElementTestCase, unittest.TestCase): - def test_augmentation_type_errors(self): - e = ET.Element('joe') - self.assertRaises(TypeError, e.append, 'b') - self.assertRaises(TypeError, e.extend, [ET.Element('bar'), 'foo']) - self.assertRaises(TypeError, e.insert, 0, 'foo') - - def test_cyclic_gc(self): - class Dummy: - pass - - # Test the shortest cycle: d->element->d - d = Dummy() - d.dummyref = ET.Element('joe', attr=d) - wref = weakref.ref(d) - del d - gc_collect() - self.assertIsNone(wref()) - - # A longer cycle: d->e->e2->d - e = ET.Element('joe') - d = Dummy() - d.dummyref = e - wref = weakref.ref(d) - e2 = ET.SubElement(e, 'foo', attr=d) - del d, e, e2 - gc_collect() - self.assertIsNone(wref()) - - # A cycle between Element objects as children of one another - # e1->e2->e3->e1 - e1 = ET.Element('e1') - e2 = ET.Element('e2') - e3 = ET.Element('e3') - e1.append(e2) - e2.append(e2) - e3.append(e1) - wref = weakref.ref(e1) - del e1, e2, e3 - gc_collect() - self.assertIsNone(wref()) - - def test_weakref(self): - flag = False - def wref_cb(w): - nonlocal flag - flag = True - e = ET.Element('e') - wref = weakref.ref(e, wref_cb) - self.assertEqual(wref().tag, 'e') - del e - self.assertEqual(flag, True) - self.assertEqual(wref(), None) - - def test_get_keyword_args(self): - e1 = ET.Element('foo' , x=1, y=2, z=3) - self.assertEqual(e1.get('x', default=7), 1) - self.assertEqual(e1.get('w', default=7), 7) - - def test_pickle(self): - # issue #16076: the C implementation wasn't pickleable. - for dumper, loader in product(self.modules, repeat=2): - e = dumper.Element('foo', bar=42) - e.text = "text goes here" - e.tail = "opposite of head" - dumper.SubElement(e, 'child').append(dumper.Element('grandchild')) - e.append(dumper.Element('child')) - e.findall('.//grandchild')[0].set('attr', 'other value') - - e2 = self.pickleRoundTrip(e, 'xml.etree.ElementTree', - dumper, loader) - - self.assertEqual(e2.tag, 'foo') - self.assertEqual(e2.attrib['bar'], 42) - self.assertEqual(len(e2), 2) - self.assertEqualElements(e, e2) - - -class ElementTreeTypeTest(unittest.TestCase): - def test_istype(self): - self.assertIsInstance(ET.ParseError, type) - self.assertIsInstance(ET.QName, type) - self.assertIsInstance(ET.ElementTree, type) - self.assertIsInstance(ET.Element, type) - self.assertIsInstance(ET.TreeBuilder, type) - self.assertIsInstance(ET.XMLParser, type) - - def test_Element_subclass_trivial(self): - class MyElement(ET.Element): - pass - - mye = MyElement('foo') - self.assertIsInstance(mye, ET.Element) - self.assertIsInstance(mye, MyElement) - self.assertEqual(mye.tag, 'foo') - - # test that attribute assignment works (issue 14849) - mye.text = "joe" - self.assertEqual(mye.text, "joe") - - def test_Element_subclass_constructor(self): - class MyElement(ET.Element): - def __init__(self, tag, attrib={}, **extra): - super(MyElement, self).__init__(tag + '__', attrib, **extra) - - mye = MyElement('foo', {'a': 1, 'b': 2}, c=3, d=4) - self.assertEqual(mye.tag, 'foo__') - self.assertEqual(sorted(mye.items()), - [('a', 1), ('b', 2), ('c', 3), ('d', 4)]) - - def test_Element_subclass_new_method(self): - class MyElement(ET.Element): - def newmethod(self): - return self.tag - - mye = MyElement('joe') - self.assertEqual(mye.newmethod(), 'joe') - - class ElementFindTest(unittest.TestCase): def test_find_simple(self): e = ET.XML(SAMPLE_XML) @@ -1763,28 +1776,6 @@ # Issue #16922 self.assertEqual(ET.XML('').findtext('empty'), '') - def test_find_xpath(self): - LINEAR_XML = ''' - - - - - - ''' - e = ET.XML(LINEAR_XML) - - # Test for numeric indexing and last() - self.assertEqual(e.find('./tag[1]').attrib['class'], 'a') - self.assertEqual(e.find('./tag[2]').attrib['class'], 'b') - self.assertEqual(e.find('./tag[last()]').attrib['class'], 'd') - self.assertEqual(e.find('./tag[last()-1]').attrib['class'], 'c') - self.assertEqual(e.find('./tag[last()-2]').attrib['class'], 'b') - - self.assertRaisesRegex(SyntaxError, 'XPath', e.find, './tag[0]') - self.assertRaisesRegex(SyntaxError, 'XPath', e.find, './tag[-1]') - self.assertRaisesRegex(SyntaxError, 'XPath', e.find, './tag[last()-0]') - self.assertRaisesRegex(SyntaxError, 'XPath', e.find, './tag[last()+1]') - def test_findall(self): e = ET.XML(SAMPLE_XML) e[2] = ET.XML(SAMPLE_SECTION) @@ -1873,12 +1864,6 @@ sourcefile = serialize(doc, to_string=False) self.assertEqual(next(ET.iterparse(sourcefile))[0], 'end') - # With an explitit parser too (issue #9708) - sourcefile = serialize(doc, to_string=False) - parser = ET.XMLParser(target=ET.TreeBuilder()) - self.assertEqual(next(ET.iterparse(sourcefile, parser=parser))[0], - 'end') - tree = ET.ElementTree(None) self.assertRaises(AttributeError, tree.iter) @@ -1978,12 +1963,6 @@ parser.feed(self.sample1) self.assertIsNone(parser.close()) - def test_treebuilder_elementfactory_none(self): - parser = ET.XMLParser(target=ET.TreeBuilder(element_factory=None)) - parser.feed(self.sample1) - e = parser.close() - self._check_sample1_element(e) - def test_subclass(self): class MyTreeBuilder(ET.TreeBuilder): def foobar(self, x): @@ -2030,7 +2009,7 @@ # Mimick SimpleTAL's behaviour (issue #16089): both versions of # TreeBuilder should be able to cope with a subclass of the # pure Python Element class. - base = ET._Element_Py + base = ET._Element # Not from a C extension self.assertEqual(base.__module__, 'xml.etree.ElementTree') # Force some multiple inheritance with a C class to make things @@ -2057,14 +2036,37 @@ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd')) +class XincludeTest(unittest.TestCase): + def _my_loader(self, href, parse): + # Used to avoid a test-dependency problem where the default loader + # of ElementInclude uses the pyET parser for cET tests. + if parse == 'xml': + with open(href, 'rb') as f: + return ET.parse(f).getroot() + else: + return None + + def test_xinclude_default(self): + from xml.etree import ElementInclude + doc = xinclude_loader('default.xml') + ElementInclude.include(doc, self._my_loader) + s = serialize(doc) + self.assertEqual(s.strip(), ''' +

Example.

+ + text + texttail + + +
''') + + class XMLParserTest(unittest.TestCase): - sample1 = b'22' - sample2 = (b'' - b'text') - sample3 = ('\n' - '$\xa3\u20ac\U0001017b') + sample1 = '22' + sample2 = ('' + 'text') def _check_sample_element(self, e): self.assertEqual(e.tag, 'file') @@ -2079,9 +2081,7 @@ self._check_sample_element(parser.close()) # Now as keyword args. - parser2 = ET.XMLParser(encoding='utf-8', - html=[{}], - target=ET.TreeBuilder()) + parser2 = ET.XMLParser(encoding='utf-8', html=[{}], target=ET.TreeBuilder()) parser2.feed(self.sample1) self._check_sample_element(parser2.close()) @@ -2100,21 +2100,12 @@ _doctype = (name, pubid, system) parser = MyParserWithDoctype() - with self.assertWarns(DeprecationWarning): - parser.feed(self.sample2) + parser.feed(self.sample2) parser.close() self.assertEqual(_doctype, ('html', '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd')) - def test_parse_string(self): - parser = ET.XMLParser(target=ET.TreeBuilder()) - parser.feed(self.sample3) - e = parser.close() - self.assertEqual(e.tag, 'money') - self.assertEqual(e.attrib['value'], '$\xa3\u20ac\U0001017b') - self.assertEqual(e.text, '$\xa3\u20ac\U0001017b') - class NamespaceParseTest(unittest.TestCase): def test_find_with_namespace(self): @@ -2203,7 +2194,7 @@ class IOTest(unittest.TestCase): def tearDown(self): - support.unlink(TESTFN) + unlink(TESTFN) def test_encoding(self): # Test encoding issues. @@ -2466,11 +2457,8 @@ # Test that the C accelerator was not imported for pyET def test_correct_import_pyET(self): - # The type of methods defined in Python code is types.FunctionType, - # while the type of methods defined inside _elementtree is - # - self.assertIsInstance(pyET.Element.__init__, types.FunctionType) - self.assertIsInstance(pyET.XMLParser.__init__, types.FunctionType) + self.assertEqual(pyET.Element.__module__, 'xml.etree.ElementTree') + self.assertEqual(pyET.SubElement.__module__, 'xml.etree.ElementTree') # -------------------------------------------------------------------- @@ -2528,20 +2516,15 @@ ET = module test_classes = [ - ModuleTest, ElementSlicingTest, BasicElementTest, - ElementTreeTest, - IncrementalParserTest, IOTest, ParseErrorTest, - XIncludeTest, - ElementTreeTypeTest, + XincludeTest, + ElementTreeTest, ElementFindTest, ElementIterTest, TreeBuilderTest, - XMLParserTest, - BugsTest, ] # These tests will only run for the pure-Python version that doesn't import @@ -2556,6 +2539,7 @@ # XXX the C module should give the same warnings as the Python module with CleanContext(quiet=(pyET is not ET)): support.run_unittest(*test_classes) + support.run_doctest(sys.modules[__name__], verbosity=True) finally: # don't interfere with subsequent tests ET = pyET = None diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_xml_etree_c.py --- a/Lib/test/test_xml_etree_c.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_xml_etree_c.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,13 +2,10 @@ import sys, struct from test import support from test.support import import_fresh_module -import types import unittest -cET = import_fresh_module('xml.etree.ElementTree', - fresh=['_elementtree']) -cET_alias = import_fresh_module('xml.etree.cElementTree', - fresh=['_elementtree', 'xml.etree']) +cET = import_fresh_module('xml.etree.ElementTree', fresh=['_elementtree']) +cET_alias = import_fresh_module('xml.etree.cElementTree', fresh=['_elementtree', 'xml.etree']) class MiscTests(unittest.TestCase): @@ -34,22 +31,14 @@ @unittest.skipUnless(cET, 'requires _elementtree') -@support.cpython_only class TestAcceleratorImported(unittest.TestCase): # Test that the C accelerator was imported, as expected def test_correct_import_cET(self): - # SubElement is a function so it retains _elementtree as its module. self.assertEqual(cET.SubElement.__module__, '_elementtree') def test_correct_import_cET_alias(self): self.assertEqual(cET_alias.SubElement.__module__, '_elementtree') - def test_parser_comes_from_C(self): - # The type of methods defined in Python code is types.FunctionType, - # while the type of methods defined inside _elementtree is - # - self.assertNotIsInstance(cET.Element.__init__, types.FunctionType) - @unittest.skipUnless(cET, 'requires _elementtree') @support.cpython_only diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_xmlrpc.py Fri Feb 01 23:12:09 2013 +0100 @@ -14,10 +14,6 @@ from test import support try: - import gzip -except ImportError: - gzip = None -try: import threading except ImportError: threading = None @@ -789,7 +785,6 @@ #A test case that verifies that gzip encoding works in both directions #(for a request and the response) -@unittest.skipIf(gzip is None, 'requires gzip') class GzipServerTestCase(BaseServerTestCase): #a request handler that supports keep-alive and logs requests into a #class variable @@ -1081,13 +1076,23 @@ @support.reap_threads def test_main(): - support.run_unittest(XMLRPCTestCase, HelperTestCase, DateTimeTestCase, - BinaryTestCase, FaultTestCase, UseBuiltinTypesTestCase, - SimpleServerTestCase, KeepaliveServerTestCase1, - KeepaliveServerTestCase2, GzipServerTestCase, - MultiPathServerTestCase, ServerProxyTestCase, FailingServerTestCase, - CGIHandlerTestCase) + xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase, + BinaryTestCase, FaultTestCase] + xmlrpc_tests.append(UseBuiltinTypesTestCase) + xmlrpc_tests.append(SimpleServerTestCase) + xmlrpc_tests.append(KeepaliveServerTestCase1) + xmlrpc_tests.append(KeepaliveServerTestCase2) + try: + import gzip + xmlrpc_tests.append(GzipServerTestCase) + except ImportError: + pass #gzip not supported in this build + xmlrpc_tests.append(MultiPathServerTestCase) + xmlrpc_tests.append(ServerProxyTestCase) + xmlrpc_tests.append(FailingServerTestCase) + xmlrpc_tests.append(CGIHandlerTestCase) + support.run_unittest(*xmlrpc_tests) if __name__ == "__main__": test_main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/test/test_zipfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ import io import os import sys -import importlib.util +import imp import time import shutil import struct @@ -10,11 +10,10 @@ from tempfile import TemporaryFile -from random import randint, random, getrandbits +from random import randint, random +from unittest import skipUnless -from test.support import (TESTFN, findfile, unlink, - requires_zlib, requires_bz2, requires_lzma, - captured_stdout) +from test.support import TESTFN, run_unittest, findfile, unlink, requires_zlib, requires_bz2, requires_lzma TESTFN2 = TESTFN + "2" TESTFNDIR = TESTFN + "d" @@ -23,27 +22,17 @@ SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'), ('ziptest2dir/_ziptest2', 'qawsedrftg'), - ('ziptest2dir/ziptest3dir/_ziptest3', 'azsxdcfvgb'), + ('/ziptest2dir/ziptest3dir/_ziptest3', 'azsxdcfvgb'), ('ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3', '6y7u8i9o0p')] -def get_files(test): - yield TESTFN2 - with TemporaryFile() as f: - yield f - test.assertFalse(f.closed) - with io.BytesIO() as f: - yield f - test.assertFalse(f.closed) -class AbstractTestsWithSourceFile: - @classmethod - def setUpClass(cls): - cls.line_gen = [bytes("Zipfile test line %d. random float: %f\n" % - (i, random()), "ascii") - for i in range(FIXEDTEST_SIZE)] - cls.data = b''.join(cls.line_gen) +class TestsWithSourceFile(unittest.TestCase): + def setUp(self): + self.line_gen = (bytes("Zipfile test line %d. random float: %f" % + (i, random()), "ascii") + for i in range(FIXEDTEST_SIZE)) + self.data = b'\n'.join(self.line_gen) + b'\n' - def setUp(self): # Make a source file with some lines with open(TESTFN, "wb") as fp: fp.write(self.data) @@ -106,10 +95,12 @@ # Check that testzip doesn't raise an exception zipfp.testzip() + if not isinstance(f, str): + f.close() - def test_basic(self): - for f in get_files(self): - self.zip_test(f, self.compression) + def test_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_STORED) def zip_open_test(self, f, compression): self.make_test_archive(f, compression) @@ -134,10 +125,30 @@ self.assertEqual(b''.join(zipdata1), self.data) self.assertEqual(b''.join(zipdata2), self.data) + if not isinstance(f, str): + f.close() - def test_open(self): - for f in get_files(self): - self.zip_open_test(f, self.compression) + def test_open_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_open_test(f, zipfile.ZIP_STORED) + + def test_open_via_zip_info(self): + # Create the ZIP archive + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: + zipfp.writestr("name", "foo") + zipfp.writestr("name", "bar") + + with zipfile.ZipFile(TESTFN2, "r") as zipfp: + infos = zipfp.infolist() + data = b"" + for info in infos: + with zipfp.open(info) as zipopen: + data += zipopen.read() + self.assertTrue(data == b"foobar" or data == b"barfoo") + data = b"" + for info in infos: + data += zipfp.read(info) + self.assertTrue(data == b"foobar" or data == b"barfoo") def zip_random_open_test(self, f, compression): self.make_test_archive(f, compression) @@ -153,17 +164,36 @@ zipdata1.append(read_data) self.assertEqual(b''.join(zipdata1), self.data) + if not isinstance(f, str): + f.close() - def test_random_open(self): - for f in get_files(self): - self.zip_random_open_test(f, self.compression) + def test_random_open_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_random_open_test(f, zipfile.ZIP_STORED) + + def test_univeral_readaheads(self): + f = io.BytesIO() + + data = b'a\r\n' * 16 * 1024 + zipfp = zipfile.ZipFile(f, 'w', zipfile.ZIP_STORED) + zipfp.writestr(TESTFN, data) + zipfp.close() + + data2 = b'' + zipfp = zipfile.ZipFile(f, 'r') + with zipfp.open(TESTFN, 'rU') as zipopen: + for line in zipopen: + data2 += line + zipfp.close() + + self.assertEqual(data, data2.replace(b'\n', b'\r\n')) def zip_readline_read_test(self, f, compression): self.make_test_archive(f, compression) # Read the ZIP archive - with zipfile.ZipFile(f, "r") as zipfp, \ - zipfp.open(TESTFN) as zipopen: + zipfp = zipfile.ZipFile(f, "r") + with zipfp.open(TESTFN) as zipopen: data = b'' while True: read = zipopen.readline() @@ -177,11 +207,9 @@ data += read self.assertEqual(data, self.data) - - def test_readline_read(self): - # Issue #7610: calls to readline() interleaved with calls to read(). - for f in get_files(self): - self.zip_readline_read_test(f, self.compression) + zipfp.close() + if not isinstance(f, str): + f.close() def zip_readline_test(self, f, compression): self.make_test_archive(f, compression) @@ -191,11 +219,9 @@ with zipfp.open(TESTFN) as zipopen: for line in self.line_gen: linedata = zipopen.readline() - self.assertEqual(linedata, line) - - def test_readline(self): - for f in get_files(self): - self.zip_readline_test(f, self.compression) + self.assertEqual(linedata, line + '\n') + if not isinstance(f, str): + f.close() def zip_readlines_test(self, f, compression): self.make_test_archive(f, compression) @@ -205,11 +231,9 @@ with zipfp.open(TESTFN) as zipopen: ziplines = zipopen.readlines() for line, zipline in zip(self.line_gen, ziplines): - self.assertEqual(zipline, line) - - def test_readlines(self): - for f in get_files(self): - self.zip_readlines_test(f, self.compression) + self.assertEqual(zipline, line + '\n') + if not isinstance(f, str): + f.close() def zip_iterlines_test(self, f, compression): self.make_test_archive(f, compression) @@ -218,64 +242,173 @@ with zipfile.ZipFile(f, "r") as zipfp: with zipfp.open(TESTFN) as zipopen: for line, zipline in zip(self.line_gen, zipopen): - self.assertEqual(zipline, line) + self.assertEqual(zipline, line + '\n') + if not isinstance(f, str): + f.close() - def test_iterlines(self): - for f in get_files(self): - self.zip_iterlines_test(f, self.compression) + def test_readline_read_stored(self): + # Issue #7610: calls to readline() interleaved with calls to read(). + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_read_test(f, zipfile.ZIP_STORED) + def test_readline_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_test(f, zipfile.ZIP_STORED) + + def test_readlines_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readlines_test(f, zipfile.ZIP_STORED) + + def test_iterlines_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_iterlines_test(f, zipfile.ZIP_STORED) + + @requires_zlib + def test_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_DEFLATED) + + + @requires_zlib + def test_open_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_open_test(f, zipfile.ZIP_DEFLATED) + + @requires_zlib + def test_random_open_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_random_open_test(f, zipfile.ZIP_DEFLATED) + + @requires_zlib + def test_readline_read_deflated(self): + # Issue #7610: calls to readline() interleaved with calls to read(). + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_read_test(f, zipfile.ZIP_DEFLATED) + + @requires_zlib + def test_readline_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_test(f, zipfile.ZIP_DEFLATED) + + @requires_zlib + def test_readlines_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readlines_test(f, zipfile.ZIP_DEFLATED) + + @requires_zlib + def test_iterlines_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_iterlines_test(f, zipfile.ZIP_DEFLATED) + + @requires_zlib def test_low_compression(self): """Check for cases where compressed data is larger than original.""" # Create the ZIP archive - with zipfile.ZipFile(TESTFN2, "w", self.compression) as zipfp: + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED) as zipfp: zipfp.writestr("strfile", '12') # Get an open object for strfile - with zipfile.ZipFile(TESTFN2, "r", self.compression) as zipfp: + with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_DEFLATED) as zipfp: with zipfp.open("strfile") as openobj: self.assertEqual(openobj.read(1), b'1') self.assertEqual(openobj.read(1), b'2') - def test_writestr_compression(self): - zipfp = zipfile.ZipFile(TESTFN2, "w") - zipfp.writestr("b.txt", "hello world", compress_type=self.compression) - info = zipfp.getinfo('b.txt') - self.assertEqual(info.compress_type, self.compression) + @requires_bz2 + def test_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_BZIP2) - def test_read_return_size(self): - # Issue #9837: ZipExtFile.read() shouldn't return more bytes - # than requested. - for test_size in (1, 4095, 4096, 4097, 16384): - file_size = test_size + 1 - junk = getrandbits(8 * file_size).to_bytes(file_size, 'little') - with zipfile.ZipFile(io.BytesIO(), "w", self.compression) as zipf: - zipf.writestr('foo', junk) - with zipf.open('foo', 'r') as fp: - buf = fp.read(test_size) - self.assertEqual(len(buf), test_size) + @requires_bz2 + def test_open_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_open_test(f, zipfile.ZIP_BZIP2) - def tearDown(self): - unlink(TESTFN) - unlink(TESTFN2) + @requires_bz2 + def test_random_open_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_random_open_test(f, zipfile.ZIP_BZIP2) + @requires_bz2 + def test_readline_read_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_read_test(f, zipfile.ZIP_BZIP2) -class StoredTestsWithSourceFile(AbstractTestsWithSourceFile, - unittest.TestCase): - compression = zipfile.ZIP_STORED - test_low_compression = None + @requires_bz2 + def test_readline_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_test(f, zipfile.ZIP_BZIP2) - def zip_test_writestr_permissions(self, f, compression): - # Make sure that writestr creates files with mode 0600, - # when it is passed a name rather than a ZipInfo instance. + @requires_bz2 + def test_readlines_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readlines_test(f, zipfile.ZIP_BZIP2) - self.make_test_archive(f, compression) - with zipfile.ZipFile(f, "r") as zipfp: - zinfo = zipfp.getinfo('strfile') - self.assertEqual(zinfo.external_attr, 0o600 << 16) + @requires_bz2 + def test_iterlines_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_iterlines_test(f, zipfile.ZIP_BZIP2) - def test_writestr_permissions(self): - for f in get_files(self): - self.zip_test_writestr_permissions(f, zipfile.ZIP_STORED) + @requires_bz2 + def test_low_compression_bzip2(self): + """Check for cases where compressed data is larger than original.""" + # Create the ZIP archive + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_BZIP2) as zipfp: + zipfp.writestr("strfile", '12') + + # Get an open object for strfile + with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_BZIP2) as zipfp: + with zipfp.open("strfile") as openobj: + self.assertEqual(openobj.read(1), b'1') + self.assertEqual(openobj.read(1), b'2') + + @requires_lzma + def test_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_open_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_open_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_random_open_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_random_open_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_readline_read_lzma(self): + # Issue #7610: calls to readline() interleaved with calls to read(). + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_read_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_readline_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readline_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_readlines_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_readlines_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_iterlines_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_iterlines_test(f, zipfile.ZIP_LZMA) + + @requires_lzma + def test_low_compression_lzma(self): + """Check for cases where compressed data is larger than original.""" + # Create the ZIP archive + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_LZMA) as zipfp: + zipfp.writestr("strfile", '12') + + # Get an open object for strfile + with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_LZMA) as zipfp: + with zipfp.open("strfile") as openobj: + self.assertEqual(openobj.read(1), b'1') + self.assertEqual(openobj.read(1), b'2') def test_absolute_arcnames(self): with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: @@ -335,26 +468,7 @@ with open(TESTFN, "rb") as f: self.assertEqual(zipfp.read(TESTFN), f.read()) - def test_write_to_readonly(self): - """Check that trying to call write() on a readonly ZipFile object - raises a RuntimeError.""" - with zipfile.ZipFile(TESTFN2, mode="w") as zipfp: - zipfp.writestr("somefile.txt", "bogus") - - with zipfile.ZipFile(TESTFN2, mode="r") as zipfp: - self.assertRaises(RuntimeError, zipfp.write, TESTFN) - - def test_add_file_before_1980(self): - # Set atime and mtime to 1970-01-01 - os.utime(TESTFN, (0, 0)) - with zipfile.ZipFile(TESTFN2, "w") as zipfp: - self.assertRaises(ValueError, zipfp.write, TESTFN) - -@requires_zlib -class DeflateTestsWithSourceFile(AbstractTestsWithSourceFile, - unittest.TestCase): - compression = zipfile.ZIP_DEFLATED - + @requires_zlib def test_per_file_compression(self): """Check that files within a Zip archive can have different compression options.""" @@ -366,35 +480,195 @@ self.assertEqual(sinfo.compress_type, zipfile.ZIP_STORED) self.assertEqual(dinfo.compress_type, zipfile.ZIP_DEFLATED) -@requires_bz2 -class Bzip2TestsWithSourceFile(AbstractTestsWithSourceFile, - unittest.TestCase): - compression = zipfile.ZIP_BZIP2 + def test_write_to_readonly(self): + """Check that trying to call write() on a readonly ZipFile object + raises a RuntimeError.""" + with zipfile.ZipFile(TESTFN2, mode="w") as zipfp: + zipfp.writestr("somefile.txt", "bogus") -@requires_lzma -class LzmaTestsWithSourceFile(AbstractTestsWithSourceFile, - unittest.TestCase): - compression = zipfile.ZIP_LZMA + with zipfile.ZipFile(TESTFN2, mode="r") as zipfp: + self.assertRaises(RuntimeError, zipfp.write, TESTFN) + def test_extract(self): + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: + for fpath, fdata in SMALL_TEST_DATA: + zipfp.writestr(fpath, fdata) -class AbstractTestZip64InSmallFiles: + with zipfile.ZipFile(TESTFN2, "r") as zipfp: + for fpath, fdata in SMALL_TEST_DATA: + writtenfile = zipfp.extract(fpath) + + # make sure it was written to the right place + if os.path.isabs(fpath): + correctfile = os.path.join(os.getcwd(), fpath[1:]) + else: + correctfile = os.path.join(os.getcwd(), fpath) + correctfile = os.path.normpath(correctfile) + + self.assertEqual(writtenfile, correctfile) + + # make sure correct data is in correct file + with open(writtenfile, "rb") as f: + self.assertEqual(fdata.encode(), f.read()) + + os.remove(writtenfile) + + # remove the test file subdirectories + shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir')) + + def test_extract_all(self): + with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: + for fpath, fdata in SMALL_TEST_DATA: + zipfp.writestr(fpath, fdata) + + with zipfile.ZipFile(TESTFN2, "r") as zipfp: + zipfp.extractall() + for fpath, fdata in SMALL_TEST_DATA: + if os.path.isabs(fpath): + outfile = os.path.join(os.getcwd(), fpath[1:]) + else: + outfile = os.path.join(os.getcwd(), fpath) + + with open(outfile, "rb") as f: + self.assertEqual(fdata.encode(), f.read()) + + os.remove(outfile) + + # remove the test file subdirectories + shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir')) + + def test_writestr_compression_stored(self): + zipfp = zipfile.ZipFile(TESTFN2, "w") + zipfp.writestr("a.txt", "hello world", compress_type=zipfile.ZIP_STORED) + info = zipfp.getinfo('a.txt') + self.assertEqual(info.compress_type, zipfile.ZIP_STORED) + + @requires_zlib + def test_writestr_compression_deflated(self): + zipfp = zipfile.ZipFile(TESTFN2, "w") + zipfp.writestr("b.txt", "hello world", compress_type=zipfile.ZIP_DEFLATED) + info = zipfp.getinfo('b.txt') + self.assertEqual(info.compress_type, zipfile.ZIP_DEFLATED) + + @requires_bz2 + def test_writestr_compression_bzip2(self): + zipfp = zipfile.ZipFile(TESTFN2, "w") + zipfp.writestr("b.txt", "hello world", compress_type=zipfile.ZIP_BZIP2) + info = zipfp.getinfo('b.txt') + self.assertEqual(info.compress_type, zipfile.ZIP_BZIP2) + + @requires_lzma + def test_writestr_compression_lzma(self): + zipfp = zipfile.ZipFile(TESTFN2, "w") + zipfp.writestr("b.txt", "hello world", compress_type=zipfile.ZIP_LZMA) + info = zipfp.getinfo('b.txt') + self.assertEqual(info.compress_type, zipfile.ZIP_LZMA) + + def zip_test_writestr_permissions(self, f, compression): + # Make sure that writestr creates files with mode 0600, + # when it is passed a name rather than a ZipInfo instance. + + self.make_test_archive(f, compression) + with zipfile.ZipFile(f, "r") as zipfp: + zinfo = zipfp.getinfo('strfile') + self.assertEqual(zinfo.external_attr, 0o600 << 16) + if not isinstance(f, str): + f.close() + + def test_writestr_permissions(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test_writestr_permissions(f, zipfile.ZIP_STORED) + + def test_writestr_extended_local_header_issue1202(self): + with zipfile.ZipFile(TESTFN2, 'w') as orig_zip: + for data in 'abcdefghijklmnop': + zinfo = zipfile.ZipInfo(data) + zinfo.flag_bits |= 0x08 # Include an extended local header. + orig_zip.writestr(zinfo, data) + + def test_close(self): + """Check that the zipfile is closed after the 'with' block.""" + with zipfile.ZipFile(TESTFN2, "w") as zipfp: + for fpath, fdata in SMALL_TEST_DATA: + zipfp.writestr(fpath, fdata) + self.assertTrue(zipfp.fp is not None, 'zipfp is not open') + self.assertTrue(zipfp.fp is None, 'zipfp is not closed') + + with zipfile.ZipFile(TESTFN2, "r") as zipfp: + self.assertTrue(zipfp.fp is not None, 'zipfp is not open') + self.assertTrue(zipfp.fp is None, 'zipfp is not closed') + + def test_close_on_exception(self): + """Check that the zipfile is closed if an exception is raised in the + 'with' block.""" + with zipfile.ZipFile(TESTFN2, "w") as zipfp: + for fpath, fdata in SMALL_TEST_DATA: + zipfp.writestr(fpath, fdata) + + try: + with zipfile.ZipFile(TESTFN2, "r") as zipfp2: + raise zipfile.BadZipFile() + except zipfile.BadZipFile: + self.assertTrue(zipfp2.fp is None, 'zipfp is not closed') + + def test_add_file_before_1980(self): + # Set atime and mtime to 1970-01-01 + os.utime(TESTFN, (0, 0)) + with zipfile.ZipFile(TESTFN2, "w") as zipfp: + self.assertRaises(ValueError, zipfp.write, TESTFN) + + + + + + + + @requires_zlib + def test_unicode_filenames(self): + # bug #10801 + fname = findfile('zip_cp437_header.zip') + with zipfile.ZipFile(fname) as zipfp: + for name in zipfp.namelist(): + zipfp.open(name).close() + + def tearDown(self): + unlink(TESTFN) + unlink(TESTFN2) + + +class TestZip64InSmallFiles(unittest.TestCase): # These tests test the ZIP64 functionality without using large files, # see test_zipfile64 for proper tests. - @classmethod - def setUpClass(cls): - line_gen = (bytes("Test of zipfile line %d." % i, "ascii") - for i in range(0, FIXEDTEST_SIZE)) - cls.data = b'\n'.join(line_gen) - def setUp(self): self._limit = zipfile.ZIP64_LIMIT zipfile.ZIP64_LIMIT = 5 + line_gen = (bytes("Test of zipfile line %d." % i, "ascii") + for i in range(0, FIXEDTEST_SIZE)) + self.data = b'\n'.join(line_gen) + # Make a source file with some lines with open(TESTFN, "wb") as fp: fp.write(self.data) + def large_file_exception_test(self, f, compression): + with zipfile.ZipFile(f, "w", compression) as zipfp: + self.assertRaises(zipfile.LargeZipFile, + zipfp.write, TESTFN, "another.name") + + def large_file_exception_test2(self, f, compression): + with zipfile.ZipFile(f, "w", compression) as zipfp: + self.assertRaises(zipfile.LargeZipFile, + zipfp.writestr, "another.name", self.data) + if not isinstance(f, str): + f.close() + + def test_large_file_exception(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.large_file_exception_test(f, zipfile.ZIP_STORED) + self.large_file_exception_test2(f, zipfile.ZIP_STORED) + def zip_test(self, f, compression): # Create the ZIP archive with zipfile.ZipFile(f, "w", compression, allowZip64=True) as zipfp: @@ -451,35 +725,27 @@ # Check that testzip doesn't raise an exception zipfp.testzip() + if not isinstance(f, str): + f.close() - def test_basic(self): - for f in get_files(self): - self.zip_test(f, self.compression) + def test_stored(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_STORED) - def tearDown(self): - zipfile.ZIP64_LIMIT = self._limit - unlink(TESTFN) - unlink(TESTFN2) + @requires_zlib + def test_deflated(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_DEFLATED) + @requires_bz2 + def test_bzip2(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_BZIP2) -class StoredTestZip64InSmallFiles(AbstractTestZip64InSmallFiles, - unittest.TestCase): - compression = zipfile.ZIP_STORED - - def large_file_exception_test(self, f, compression): - with zipfile.ZipFile(f, "w", compression) as zipfp: - self.assertRaises(zipfile.LargeZipFile, - zipfp.write, TESTFN, "another.name") - - def large_file_exception_test2(self, f, compression): - with zipfile.ZipFile(f, "w", compression) as zipfp: - self.assertRaises(zipfile.LargeZipFile, - zipfp.writestr, "another.name", self.data) - - def test_large_file_exception(self): - for f in get_files(self): - self.large_file_exception_test(f, zipfile.ZIP_STORED) - self.large_file_exception_test2(f, zipfile.ZIP_STORED) + @requires_lzma + def test_lzma(self): + for f in (TESTFN2, TemporaryFile(), io.BytesIO()): + self.zip_test(f, zipfile.ZIP_LZMA) def test_absolute_arcnames(self): with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, @@ -489,27 +755,13 @@ with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) as zipfp: self.assertEqual(zipfp.namelist(), ["absolute"]) -@requires_zlib -class DeflateTestZip64InSmallFiles(AbstractTestZip64InSmallFiles, - unittest.TestCase): - compression = zipfile.ZIP_DEFLATED - -@requires_bz2 -class Bzip2TestZip64InSmallFiles(AbstractTestZip64InSmallFiles, - unittest.TestCase): - compression = zipfile.ZIP_BZIP2 - -@requires_lzma -class LzmaTestZip64InSmallFiles(AbstractTestZip64InSmallFiles, - unittest.TestCase): - compression = zipfile.ZIP_LZMA + def tearDown(self): + zipfile.ZIP64_LIMIT = self._limit + unlink(TESTFN) + unlink(TESTFN2) class PyZipFileTests(unittest.TestCase): - def assertCompiledIn(self, name, namelist): - if name + 'o' not in namelist: - self.assertIn(name + 'c', namelist) - def test_write_pyfile(self): with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp: fn = __file__ @@ -518,7 +770,7 @@ if os.altsep is not None: path_split.extend(fn.split(os.altsep)) if '__pycache__' in path_split: - fn = importlib.util.source_from_cache(fn) + fn = imp.source_from_cache(fn) else: fn = fn[:-1] @@ -526,7 +778,8 @@ bn = os.path.basename(fn) self.assertNotIn(bn, zipfp.namelist()) - self.assertCompiledIn(bn, zipfp.namelist()) + self.assertTrue(bn + 'o' in zipfp.namelist() or + bn + 'c' in zipfp.namelist()) with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp: fn = __file__ @@ -537,7 +790,8 @@ bn = "%s/%s" % ("testpackage", os.path.basename(fn)) self.assertNotIn(bn, zipfp.namelist()) - self.assertCompiledIn(bn, zipfp.namelist()) + self.assertTrue(bn + 'o' in zipfp.namelist() or + bn + 'c' in zipfp.namelist()) def test_write_python_package(self): import email @@ -549,8 +803,10 @@ # Check for a couple of modules at different levels of the # hierarchy names = zipfp.namelist() - self.assertCompiledIn('email/__init__.py', names) - self.assertCompiledIn('email/mime/text.py', names) + self.assertTrue('email/__init__.pyo' in names or + 'email/__init__.pyc' in names) + self.assertTrue('email/mime/text.pyo' in names or + 'email/mime/text.pyc' in names) def test_write_with_optimization(self): import email @@ -584,8 +840,8 @@ zipfp.writepy(TESTFN2) names = zipfp.namelist() - self.assertCompiledIn('mod1.py', names) - self.assertCompiledIn('mod2.py', names) + self.assertTrue('mod1.pyc' in names or 'mod1.pyo' in names) + self.assertTrue('mod2.pyc' in names or 'mod2.pyo' in names) self.assertNotIn('mod2.txt', names) finally: @@ -598,242 +854,50 @@ self.assertRaises(RuntimeError, zipfp.writepy, TESTFN) os.remove(TESTFN) - def test_write_pyfile_bad_syntax(self): - os.mkdir(TESTFN2) - try: - with open(os.path.join(TESTFN2, "mod1.py"), "w") as fp: - fp.write("Bad syntax in python file\n") - - with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp: - # syntax errors are printed to stdout - with captured_stdout() as s: - zipfp.writepy(os.path.join(TESTFN2, "mod1.py")) - - self.assertIn("SyntaxError", s.getvalue()) - - # as it will not have compiled the python file, it will - # include the .py file not .pyc or .pyo - names = zipfp.namelist() - self.assertIn('mod1.py', names) - self.assertNotIn('mod1.pyc', names) - self.assertNotIn('mod1.pyo', names) - - finally: - shutil.rmtree(TESTFN2) - - -class ExtractTests(unittest.TestCase): - def test_extract(self): - with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: - for fpath, fdata in SMALL_TEST_DATA: - zipfp.writestr(fpath, fdata) - - with zipfile.ZipFile(TESTFN2, "r") as zipfp: - for fpath, fdata in SMALL_TEST_DATA: - writtenfile = zipfp.extract(fpath) - - # make sure it was written to the right place - correctfile = os.path.join(os.getcwd(), fpath) - correctfile = os.path.normpath(correctfile) - - self.assertEqual(writtenfile, correctfile) - - # make sure correct data is in correct file - with open(writtenfile, "rb") as f: - self.assertEqual(fdata.encode(), f.read()) - - os.remove(writtenfile) - - # remove the test file subdirectories - shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir')) - - def test_extract_all(self): - with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: - for fpath, fdata in SMALL_TEST_DATA: - zipfp.writestr(fpath, fdata) - - with zipfile.ZipFile(TESTFN2, "r") as zipfp: - zipfp.extractall() - for fpath, fdata in SMALL_TEST_DATA: - outfile = os.path.join(os.getcwd(), fpath) - - with open(outfile, "rb") as f: - self.assertEqual(fdata.encode(), f.read()) - - os.remove(outfile) - - # remove the test file subdirectories - shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir')) - - def check_file(self, filename, content): - self.assertTrue(os.path.isfile(filename)) - with open(filename, 'rb') as f: - self.assertEqual(f.read(), content) - - def test_sanitize_windows_name(self): - san = zipfile.ZipFile._sanitize_windows_name - # Passing pathsep in allows this test to work regardless of platform. - self.assertEqual(san(r',,?,C:,foo,bar/z', ','), r'_,C_,foo,bar/z') - self.assertEqual(san(r'a\b,ce|f"g?h*i', ','), r'a\b,c_d_e_f_g_h_i') - self.assertEqual(san('../../foo../../ba..r', '/'), r'foo/ba..r') - - def test_extract_hackers_arcnames_common_cases(self): - common_hacknames = [ - ('../foo/bar', 'foo/bar'), - ('foo/../bar', 'foo/bar'), - ('foo/../../bar', 'foo/bar'), - ('foo/bar/..', 'foo/bar'), - ('./../foo/bar', 'foo/bar'), - ('/foo/bar', 'foo/bar'), - ('/foo/../bar', 'foo/bar'), - ('/foo/../../bar', 'foo/bar'), - ] - self._test_extract_hackers_arcnames(common_hacknames) - - @unittest.skipIf(os.path.sep != '\\', 'Requires \\ as path separator.') - def test_extract_hackers_arcnames_windows_only(self): - """Test combination of path fixing and windows name sanitization.""" - windows_hacknames = [ - (r'..\foo\bar', 'foo/bar'), - (r'..\/foo\/bar', 'foo/bar'), - (r'foo/\..\/bar', 'foo/bar'), - (r'foo\/../\bar', 'foo/bar'), - (r'C:foo/bar', 'foo/bar'), - (r'C:/foo/bar', 'foo/bar'), - (r'C://foo/bar', 'foo/bar'), - (r'C:\foo\bar', 'foo/bar'), - (r'//conky/mountpoint/foo/bar', 'foo/bar'), - (r'\\conky\mountpoint\foo\bar', 'foo/bar'), - (r'///conky/mountpoint/foo/bar', 'conky/mountpoint/foo/bar'), - (r'\\\conky\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'), - (r'//conky//mountpoint/foo/bar', 'conky/mountpoint/foo/bar'), - (r'\\conky\\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'), - (r'//?/C:/foo/bar', 'foo/bar'), - (r'\\?\C:\foo\bar', 'foo/bar'), - (r'C:/../C:/foo/bar', 'C_/foo/bar'), - (r'a:b\ce|f"g?h*i', 'b/c_d_e_f_g_h_i'), - ('../../foo../../ba..r', 'foo/ba..r'), - ] - self._test_extract_hackers_arcnames(windows_hacknames) - - @unittest.skipIf(os.path.sep != '/', r'Requires / as path separator.') - def test_extract_hackers_arcnames_posix_only(self): - posix_hacknames = [ - ('//foo/bar', 'foo/bar'), - ('../../foo../../ba..r', 'foo../ba..r'), - (r'foo/..\bar', r'foo/..\bar'), - ] - self._test_extract_hackers_arcnames(posix_hacknames) - - def _test_extract_hackers_arcnames(self, hacknames): - for arcname, fixedname in hacknames: - content = b'foobar' + arcname.encode() - with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_STORED) as zipfp: - zinfo = zipfile.ZipInfo() - # preserve backslashes - zinfo.filename = arcname - zinfo.external_attr = 0o600 << 16 - zipfp.writestr(zinfo, content) - - arcname = arcname.replace(os.sep, "/") - targetpath = os.path.join('target', 'subdir', 'subsub') - correctfile = os.path.join(targetpath, *fixedname.split('/')) - - with zipfile.ZipFile(TESTFN2, 'r') as zipfp: - writtenfile = zipfp.extract(arcname, targetpath) - self.assertEqual(writtenfile, correctfile, - msg='extract %r: %r != %r' % - (arcname, writtenfile, correctfile)) - self.check_file(correctfile, content) - shutil.rmtree('target') - - with zipfile.ZipFile(TESTFN2, 'r') as zipfp: - zipfp.extractall(targetpath) - self.check_file(correctfile, content) - shutil.rmtree('target') - - correctfile = os.path.join(os.getcwd(), *fixedname.split('/')) - - with zipfile.ZipFile(TESTFN2, 'r') as zipfp: - writtenfile = zipfp.extract(arcname) - self.assertEqual(writtenfile, correctfile, - msg="extract %r" % arcname) - self.check_file(correctfile, content) - shutil.rmtree(fixedname.split('/')[0]) - - with zipfile.ZipFile(TESTFN2, 'r') as zipfp: - zipfp.extractall() - self.check_file(correctfile, content) - shutil.rmtree(fixedname.split('/')[0]) - - os.remove(TESTFN2) - class OtherTests(unittest.TestCase): - def test_open_via_zip_info(self): - # Create the ZIP archive - with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: - zipfp.writestr("name", "foo") - zipfp.writestr("name", "bar") - - with zipfile.ZipFile(TESTFN2, "r") as zipfp: - infos = zipfp.infolist() - data = b"" - for info in infos: - with zipfp.open(info) as zipopen: - data += zipopen.read() - self.assertIn(data, {b"foobar", b"barfoo"}) - data = b"" - for info in infos: - data += zipfp.read(info) - self.assertIn(data, {b"foobar", b"barfoo"}) - - def test_universal_readaheads(self): - f = io.BytesIO() - - data = b'a\r\n' * 16 * 1024 - with zipfile.ZipFile(f, 'w', zipfile.ZIP_STORED) as zipfp: - zipfp.writestr(TESTFN, data) - - data2 = b'' - with zipfile.ZipFile(f, 'r') as zipfp, \ - zipfp.open(TESTFN, 'rU') as zipopen: - for line in zipopen: - data2 += line - - self.assertEqual(data, data2.replace(b'\n', b'\r\n')) - - def test_writestr_extended_local_header_issue1202(self): - with zipfile.ZipFile(TESTFN2, 'w') as orig_zip: - for data in 'abcdefghijklmnop': - zinfo = zipfile.ZipInfo(data) - zinfo.flag_bits |= 0x08 # Include an extended local header. - orig_zip.writestr(zinfo, data) - - def test_close(self): - """Check that the zipfile is closed after the 'with' block.""" - with zipfile.ZipFile(TESTFN2, "w") as zipfp: - for fpath, fdata in SMALL_TEST_DATA: - zipfp.writestr(fpath, fdata) - self.assertIsNotNone(zipfp.fp, 'zipfp is not open') - self.assertIsNone(zipfp.fp, 'zipfp is not closed') - - with zipfile.ZipFile(TESTFN2, "r") as zipfp: - self.assertIsNotNone(zipfp.fp, 'zipfp is not open') - self.assertIsNone(zipfp.fp, 'zipfp is not closed') - - def test_close_on_exception(self): - """Check that the zipfile is closed if an exception is raised in the - 'with' block.""" - with zipfile.ZipFile(TESTFN2, "w") as zipfp: - for fpath, fdata in SMALL_TEST_DATA: - zipfp.writestr(fpath, fdata) - - try: - with zipfile.ZipFile(TESTFN2, "r") as zipfp2: - raise zipfile.BadZipFile() - except zipfile.BadZipFile: - self.assertIsNone(zipfp2.fp, 'zipfp is not closed') + zips_with_bad_crc = { + zipfile.ZIP_STORED: ( + b'PK\003\004\024\0\0\0\0\0 \213\212;:r' + b'\253\377\f\0\0\0\f\0\0\0\005\0\0\000af' + b'ilehello,AworldP' + b'K\001\002\024\003\024\0\0\0\0\0 \213\212;:' + b'r\253\377\f\0\0\0\f\0\0\0\005\0\0\0\0' + b'\0\0\0\0\0\0\0\200\001\0\0\0\000afi' + b'lePK\005\006\0\0\0\0\001\0\001\0003\000' + b'\0\0/\0\0\0\0\0'), + zipfile.ZIP_DEFLATED: ( + b'PK\x03\x04\x14\x00\x00\x00\x08\x00n}\x0c=FA' + b'KE\x10\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' + b'ile\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\xc9\xa0' + b'=\x13\x00PK\x01\x02\x14\x03\x14\x00\x00\x00\x08\x00n' + b'}\x0c=FAKE\x10\x00\x00\x00n\x00\x00\x00\x05' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x00' + b'\x00afilePK\x05\x06\x00\x00\x00\x00\x01\x00' + b'\x01\x003\x00\x00\x003\x00\x00\x00\x00\x00'), + zipfile.ZIP_BZIP2: ( + b'PK\x03\x04\x14\x03\x00\x00\x0c\x00nu\x0c=FA' + b'KE8\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' + b'ileBZh91AY&SY\xd4\xa8\xca' + b'\x7f\x00\x00\x0f\x11\x80@\x00\x06D\x90\x80 \x00 \xa5' + b'P\xd9!\x03\x03\x13\x13\x13\x89\xa9\xa9\xc2u5:\x9f' + b'\x8b\xb9"\x9c(HjTe?\x80PK\x01\x02\x14' + b'\x03\x14\x03\x00\x00\x0c\x00nu\x0c=FAKE8' + b'\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00 \x80\x80\x81\x00\x00\x00\x00afilePK' + b'\x05\x06\x00\x00\x00\x00\x01\x00\x01\x003\x00\x00\x00[\x00' + b'\x00\x00\x00\x00'), + zipfile.ZIP_LZMA: ( + b'PK\x03\x04\x14\x03\x00\x00\x0e\x00nu\x0c=FA' + b'KE\x1b\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' + b'ile\t\x04\x05\x00]\x00\x00\x00\x04\x004\x19I' + b'\xee\x8d\xe9\x17\x89:3`\tq!.8\x00PK' + b'\x01\x02\x14\x03\x14\x03\x00\x00\x0e\x00nu\x0c=FA' + b'KE\x1b\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00 \x80\x80\x81\x00\x00\x00\x00afil' + b'ePK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x003\x00\x00' + b'\x00>\x00\x00\x00\x00\x00'), + } def test_unsupported_version(self): # File has an extract_version of 120 @@ -842,19 +906,10 @@ b'\x00!p\xa1@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x00\x00xPK\x05\x06' b'\x00\x00\x00\x00\x01\x00\x01\x00/\x00\x00\x00\x1f\x00\x00\x00\x00\x00') - self.assertRaises(NotImplementedError, zipfile.ZipFile, io.BytesIO(data), 'r') - @requires_zlib - def test_read_unicode_filenames(self): - # bug #10801 - fname = findfile('zip_cp437_header.zip') - with zipfile.ZipFile(fname) as zipfp: - for name in zipfp.namelist(): - zipfp.open(name).close() - - def test_write_unicode_filenames(self): + def test_unicode_filenames(self): with zipfile.ZipFile(TESTFN, "w") as zf: zf.writestr("foo.txt", "Test for unicode filename") zf.writestr("\xf6.txt", "Test for unicode filename") @@ -902,30 +957,20 @@ # - passing a filename with open(TESTFN, "w") as fp: fp.write("this is not a legal zip file\n") - self.assertFalse(zipfile.is_zipfile(TESTFN)) + chk = zipfile.is_zipfile(TESTFN) + self.assertFalse(chk) # - passing a file object with open(TESTFN, "rb") as fp: - self.assertFalse(zipfile.is_zipfile(fp)) + chk = zipfile.is_zipfile(fp) + self.assertTrue(not chk) # - passing a file-like object fp = io.BytesIO() fp.write(b"this is not a legal zip file\n") - self.assertFalse(zipfile.is_zipfile(fp)) + chk = zipfile.is_zipfile(fp) + self.assertTrue(not chk) fp.seek(0, 0) - self.assertFalse(zipfile.is_zipfile(fp)) - - def test_damaged_zipfile(self): - """Check that zipfiles with missing bytes at the end raise BadZipFile.""" - # - Create a valid zip file - fp = io.BytesIO() - with zipfile.ZipFile(fp, mode="w") as zipf: - zipf.writestr("foo.txt", b"O, for a Muse of Fire!") - zipfiledata = fp.getvalue() - - # - Now create copies of it missing the last N bytes and make sure - # a BadZipFile exception is raised when we try to open it - for N in range(len(zipfiledata)): - fp = io.BytesIO(zipfiledata[:N]) - self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, fp) + chk = zipfile.is_zipfile(fp) + self.assertTrue(not chk) def test_is_zip_valid_file(self): """Check that is_zipfile() correctly identifies zip files.""" @@ -933,18 +978,22 @@ with zipfile.ZipFile(TESTFN, mode="w") as zipf: zipf.writestr("foo.txt", b"O, for a Muse of Fire!") - self.assertTrue(zipfile.is_zipfile(TESTFN)) + chk = zipfile.is_zipfile(TESTFN) + self.assertTrue(chk) # - passing a file object with open(TESTFN, "rb") as fp: - self.assertTrue(zipfile.is_zipfile(fp)) + chk = zipfile.is_zipfile(fp) + self.assertTrue(chk) fp.seek(0, 0) zip_contents = fp.read() # - passing a file-like object fp = io.BytesIO() fp.write(zip_contents) - self.assertTrue(zipfile.is_zipfile(fp)) + chk = zipfile.is_zipfile(fp) + self.assertTrue(chk) fp.seek(0, 0) - self.assertTrue(zipfile.is_zipfile(fp)) + chk = zipfile.is_zipfile(fp) + self.assertTrue(chk) def test_non_existent_file_raises_OSError(self): # make sure we don't raise an AttributeError when a partially-constructed @@ -1125,6 +1174,93 @@ with zipfile.ZipFile(TESTFN, "r") as zipf: self.assertEqual(zipf.comment, b"this is a comment") + def check_testzip_with_bad_crc(self, compression): + """Tests that files with bad CRCs return their name from testzip.""" + zipdata = self.zips_with_bad_crc[compression] + + with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: + # testzip returns the name of the first corrupt file, or None + self.assertEqual('afile', zipf.testzip()) + + def test_testzip_with_bad_crc_stored(self): + self.check_testzip_with_bad_crc(zipfile.ZIP_STORED) + + @requires_zlib + def test_testzip_with_bad_crc_deflated(self): + self.check_testzip_with_bad_crc(zipfile.ZIP_DEFLATED) + + @requires_bz2 + def test_testzip_with_bad_crc_bzip2(self): + self.check_testzip_with_bad_crc(zipfile.ZIP_BZIP2) + + @requires_lzma + def test_testzip_with_bad_crc_lzma(self): + self.check_testzip_with_bad_crc(zipfile.ZIP_LZMA) + + def check_read_with_bad_crc(self, compression): + """Tests that files with bad CRCs raise a BadZipFile exception when read.""" + zipdata = self.zips_with_bad_crc[compression] + + # Using ZipFile.read() + with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: + self.assertRaises(zipfile.BadZipFile, zipf.read, 'afile') + + # Using ZipExtFile.read() + with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: + with zipf.open('afile', 'r') as corrupt_file: + self.assertRaises(zipfile.BadZipFile, corrupt_file.read) + + # Same with small reads (in order to exercise the buffering logic) + with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: + with zipf.open('afile', 'r') as corrupt_file: + corrupt_file.MIN_READ_SIZE = 2 + with self.assertRaises(zipfile.BadZipFile): + while corrupt_file.read(2): + pass + + def test_read_with_bad_crc_stored(self): + self.check_read_with_bad_crc(zipfile.ZIP_STORED) + + @requires_zlib + def test_read_with_bad_crc_deflated(self): + self.check_read_with_bad_crc(zipfile.ZIP_DEFLATED) + + @requires_bz2 + def test_read_with_bad_crc_bzip2(self): + self.check_read_with_bad_crc(zipfile.ZIP_BZIP2) + + @requires_lzma + def test_read_with_bad_crc_lzma(self): + self.check_read_with_bad_crc(zipfile.ZIP_LZMA) + + def check_read_return_size(self, compression): + # Issue #9837: ZipExtFile.read() shouldn't return more bytes + # than requested. + for test_size in (1, 4095, 4096, 4097, 16384): + file_size = test_size + 1 + junk = b''.join(struct.pack('B', randint(0, 255)) + for x in range(file_size)) + with zipfile.ZipFile(io.BytesIO(), "w", compression) as zipf: + zipf.writestr('foo', junk) + with zipf.open('foo', 'r') as fp: + buf = fp.read(test_size) + self.assertEqual(len(buf), test_size) + + def test_read_return_size_stored(self): + self.check_read_return_size(zipfile.ZIP_STORED) + + @requires_zlib + def test_read_return_size_deflated(self): + self.check_read_return_size(zipfile.ZIP_DEFLATED) + + @requires_bz2 + def test_read_return_size_bzip2(self): + self.check_read_return_size(zipfile.ZIP_BZIP2) + + @requires_lzma + def test_read_return_size_lzma(self): + self.check_read_return_size(zipfile.ZIP_LZMA) + def test_empty_zipfile(self): # Check that creating a file in 'w' or 'a' mode and closing without # adding any files to the archives creates a valid empty ZIP file @@ -1159,93 +1295,6 @@ unlink(TESTFN2) -class AbstractBadCrcTests: - def test_testzip_with_bad_crc(self): - """Tests that files with bad CRCs return their name from testzip.""" - zipdata = self.zip_with_bad_crc - - with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: - # testzip returns the name of the first corrupt file, or None - self.assertEqual('afile', zipf.testzip()) - - def test_read_with_bad_crc(self): - """Tests that files with bad CRCs raise a BadZipFile exception when read.""" - zipdata = self.zip_with_bad_crc - - # Using ZipFile.read() - with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: - self.assertRaises(zipfile.BadZipFile, zipf.read, 'afile') - - # Using ZipExtFile.read() - with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: - with zipf.open('afile', 'r') as corrupt_file: - self.assertRaises(zipfile.BadZipFile, corrupt_file.read) - - # Same with small reads (in order to exercise the buffering logic) - with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: - with zipf.open('afile', 'r') as corrupt_file: - corrupt_file.MIN_READ_SIZE = 2 - with self.assertRaises(zipfile.BadZipFile): - while corrupt_file.read(2): - pass - - -class StoredBadCrcTests(AbstractBadCrcTests, unittest.TestCase): - compression = zipfile.ZIP_STORED - zip_with_bad_crc = ( - b'PK\003\004\024\0\0\0\0\0 \213\212;:r' - b'\253\377\f\0\0\0\f\0\0\0\005\0\0\000af' - b'ilehello,AworldP' - b'K\001\002\024\003\024\0\0\0\0\0 \213\212;:' - b'r\253\377\f\0\0\0\f\0\0\0\005\0\0\0\0' - b'\0\0\0\0\0\0\0\200\001\0\0\0\000afi' - b'lePK\005\006\0\0\0\0\001\0\001\0003\000' - b'\0\0/\0\0\0\0\0') - -@requires_zlib -class DeflateBadCrcTests(AbstractBadCrcTests, unittest.TestCase): - compression = zipfile.ZIP_DEFLATED - zip_with_bad_crc = ( - b'PK\x03\x04\x14\x00\x00\x00\x08\x00n}\x0c=FA' - b'KE\x10\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' - b'ile\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\xc9\xa0' - b'=\x13\x00PK\x01\x02\x14\x03\x14\x00\x00\x00\x08\x00n' - b'}\x0c=FAKE\x10\x00\x00\x00n\x00\x00\x00\x05' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x00' - b'\x00afilePK\x05\x06\x00\x00\x00\x00\x01\x00' - b'\x01\x003\x00\x00\x003\x00\x00\x00\x00\x00') - -@requires_bz2 -class Bzip2BadCrcTests(AbstractBadCrcTests, unittest.TestCase): - compression = zipfile.ZIP_BZIP2 - zip_with_bad_crc = ( - b'PK\x03\x04\x14\x03\x00\x00\x0c\x00nu\x0c=FA' - b'KE8\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' - b'ileBZh91AY&SY\xd4\xa8\xca' - b'\x7f\x00\x00\x0f\x11\x80@\x00\x06D\x90\x80 \x00 \xa5' - b'P\xd9!\x03\x03\x13\x13\x13\x89\xa9\xa9\xc2u5:\x9f' - b'\x8b\xb9"\x9c(HjTe?\x80PK\x01\x02\x14' - b'\x03\x14\x03\x00\x00\x0c\x00nu\x0c=FAKE8' - b'\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00 \x80\x80\x81\x00\x00\x00\x00afilePK' - b'\x05\x06\x00\x00\x00\x00\x01\x00\x01\x003\x00\x00\x00[\x00' - b'\x00\x00\x00\x00') - -@requires_lzma -class LzmaBadCrcTests(AbstractBadCrcTests, unittest.TestCase): - compression = zipfile.ZIP_LZMA - zip_with_bad_crc = ( - b'PK\x03\x04\x14\x03\x00\x00\x0e\x00nu\x0c=FA' - b'KE\x1b\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' - b'ile\t\x04\x05\x00]\x00\x00\x00\x04\x004\x19I' - b'\xee\x8d\xe9\x17\x89:3`\tq!.8\x00PK' - b'\x01\x02\x14\x03\x14\x03\x00\x00\x0e\x00nu\x0c=FA' - b'KE\x1b\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00 \x80\x80\x81\x00\x00\x00\x00afil' - b'ePK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x003\x00\x00' - b'\x00>\x00\x00\x00\x00\x00') - - class DecryptionTests(unittest.TestCase): """Check that ZIP decryption works. Since the library does not support encryption at the moment, we use a pre-generated encrypted @@ -1311,14 +1360,13 @@ self.assertRaises(TypeError, self.zip.open, "test.txt", pwd="python") self.assertRaises(TypeError, self.zip.extract, "test.txt", pwd="python") -class AbstractTestsWithRandomBinaryFiles: - @classmethod - def setUpClass(cls): + +class TestsWithRandomBinaryFiles(unittest.TestCase): + def setUp(self): datacount = randint(16, 64)*1024 + randint(1, 1024) - cls.data = b''.join(struct.pack('", "exec") raise_src = 'def do_raise(): raise TypeError\n' def make_pyc(co, mtime, size): @@ -34,8 +27,7 @@ mtime = int(mtime) else: mtime = int(-0x100000000 + int(mtime)) - pyc = (importlib.util.MAGIC_NUMBER + - struct.pack(" float - repeat(string, string) -> list - default_timer() -> float - +The baseline overhead differs between Python versions! Also, to +fairly compare older Python versions to Python 2.3, you may want to +use python -O for the older versions to avoid timing SET_LINENO +instructions. """ import gc import sys import time -import itertools +try: + import itertools +except ImportError: + # Must be an older Python version (see timeit() below) + itertools = None -__all__ = ["Timer", "timeit", "repeat", "default_timer"] +__all__ = ["Timer"] dummy_src_name = "" default_number = 1000000 @@ -171,7 +180,10 @@ to one million. The main statement, the setup statement and the timer function to be used are passed to the constructor. """ - it = itertools.repeat(None, number) + if itertools: + it = itertools.repeat(None, number) + else: + it = [None] * number gcold = gc.isenabled() gc.disable() try: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/tkinter/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -3113,7 +3113,7 @@ def peer_create(self, newPathName, cnf={}, **kw): # new in Tk 8.5 """Creates a peer text widget with the given newPathName, and any optional standard configuration options. By default the peer will - have the same start and end line as the parent widget, but + have the same start and and end line as the parent widget, but these can be overriden with the standard configuration options.""" self.tk.call(self._w, 'peer', 'create', newPathName, *self._options(cnf, kw)) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/tkinter/test/test_ttk/test_widgets.py --- a/Lib/tkinter/test/test_ttk/test_widgets.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/tkinter/test/test_ttk/test_widgets.py Fri Feb 01 23:12:09 2013 +0100 @@ -947,7 +947,7 @@ anchor=1) # XXX skipping for now; should be fixed to work with newer ttk - @unittest.skip("skipping pending resolution of Issue #10734") + @unittest.skip def test_heading_callback(self): def simulate_heading_click(x, y): support.simulate_mouse_click(self.tv, x, y) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/tkinter/tix.py --- a/Lib/tkinter/tix.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/tkinter/tix.py Fri Feb 01 23:12:09 2013 +0100 @@ -1901,39 +1901,38 @@ self.tk.call(self, 'set', x, y, *args) def size_column(self, index, **kw): - """Queries or sets the size of the column given by - INDEX. INDEX may be any non-negative - integer that gives the position of a given column. + """Queries or sets the size of the column given by + INDEX. INDEX may be any non-negative + integer that gives the position of a given column. INDEX can also be the string "default"; in this case, this command queries or sets the default size of all columns. - When no option-value pair is given, this command returns a tuple - containing the current size setting of the given column. When - option-value pairs are given, the corresponding options of the + When no option-value pair is given, this command returns a tuple + containing the current size setting of the given column. When + option-value pairs are given, the corresponding options of the size setting of the given column are changed. Options may be one - of the follwing: + of the follwing: pad0 pixels Specifies the paddings to the left of a column. pad1 pixels - Specifies the paddings to the right of a column. + Specifies the paddings to the right of a column. size val - Specifies the width of a column. Val may be: - "auto" -- the width of the column is set to the - width of the widest cell in the column; - a valid Tk screen distance unit; - or a real number following by the word chars + Specifies the width of a column . + Val may be: "auto" -- the width of the column is set the + the widest cell in the column; a valid Tk screen distance + unit; or a real number following by the word chars (e.g. 3.4chars) that sets the width of the column to the given number of characters.""" return self.tk.split(self.tk.call(self._w, 'size', 'column', index, *self._options({}, kw))) def size_row(self, index, **kw): - """Queries or sets the size of the row given by - INDEX. INDEX may be any non-negative - integer that gives the position of a given row . + """Queries or sets the size of the row given by + INDEX. INDEX may be any non-negative + integer that gives the position of a given row . INDEX can also be the string "default"; in this case, this command queries or sets the default size of all rows. - When no option-value pair is given, this command returns a list con- - taining the current size setting of the given row . When option-value + When no option-value pair is given, this command returns a list con- + taining the current size setting of the given row . When option-value pairs are given, the corresponding options of the size setting of the given row are changed. Options may be one of the follwing: pad0 pixels @@ -1941,11 +1940,10 @@ pad1 pixels Specifies the paddings to the bottom of a row. size val - Specifies the height of a row. Val may be: - "auto" -- the height of the row is set to the - height of the highest cell in the row; - a valid Tk screen distance unit; - or a real number following by the word chars + Specifies the height of a row. + Val may be: "auto" -- the height of the row is set the + the highest cell in the row; a valid Tk screen distance + unit; or a real number following by the word chars (e.g. 3.4chars) that sets the height of the row to the given number of characters.""" return self.tk.split(self.tk.call( diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/trace.py --- a/Lib/trace.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/trace.py Fri Feb 01 23:12:09 2013 +0100 @@ -58,7 +58,6 @@ import gc import dis import pickle -from warnings import warn as _warn try: from time import monotonic as _time except ImportError: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/traceback.py --- a/Lib/traceback.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/traceback.py Fri Feb 01 23:12:09 2013 +0100 @@ -2,31 +2,26 @@ import linecache import sys -import operator __all__ = ['extract_stack', 'extract_tb', 'format_exception', 'format_exception_only', 'format_list', 'format_stack', 'format_tb', 'print_exc', 'format_exc', 'print_exception', 'print_last', 'print_stack', 'print_tb'] -# -# Formatting and printing lists of traceback lines. -# +def _print(file, str='', terminator='\n'): + file.write(str+terminator) -def _format_list_iter(extracted_list): - for filename, lineno, name, line in extracted_list: - item = ' File "{}", line {}, in {}\n'.format(filename, lineno, name) - if line: - item = item + ' {}\n'.format(line.strip()) - yield item def print_list(extracted_list, file=None): """Print the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file.""" if file is None: file = sys.stderr - for item in _format_list_iter(extracted_list): - print(item, file=file, end="") + for filename, lineno, name, line in extracted_list: + _print(file, + ' File "%s", line %d, in %s' % (filename,lineno,name)) + if line: + _print(file, ' %s' % line.strip()) def format_list(extracted_list): """Format a list of traceback entry tuples for printing. @@ -38,44 +33,14 @@ the strings may contain internal newlines as well, for those items whose source text line is not None. """ - return list(_format_list_iter(extracted_list)) + list = [] + for filename, lineno, name, line in extracted_list: + item = ' File "%s", line %d, in %s\n' % (filename,lineno,name) + if line: + item = item + ' %s\n' % line.strip() + list.append(item) + return list -# -# Printing and Extracting Tracebacks. -# - -# extractor takes curr and needs to return a tuple of: -# - Frame object -# - Line number -# - Next item (same type as curr) -# In practice, curr is either a traceback or a frame. -def _extract_tb_or_stack_iter(curr, limit, extractor): - if limit is None: - limit = getattr(sys, 'tracebacklimit', None) - - n = 0 - while curr is not None and (limit is None or n < limit): - f, lineno, next_item = extractor(curr) - co = f.f_code - filename = co.co_filename - name = co.co_name - - linecache.checkcache(filename) - line = linecache.getline(filename, lineno, f.f_globals) - - if line: - line = line.strip() - else: - line = None - - yield (filename, lineno, name, line) - curr = next_item - n += 1 - -def _extract_tb_iter(tb, limit): - return _extract_tb_or_stack_iter( - tb, limit, - operator.attrgetter("tb_frame", "tb_lineno", "tb_next")) def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. @@ -85,11 +50,29 @@ 'file' should be an open file or file-like object with a write() method. """ - print_list(extract_tb(tb, limit=limit), file=file) + if file is None: + file = sys.stderr + if limit is None: + if hasattr(sys, 'tracebacklimit'): + limit = sys.tracebacklimit + n = 0 + while tb is not None and (limit is None or n < limit): + f = tb.tb_frame + lineno = tb.tb_lineno + co = f.f_code + filename = co.co_filename + name = co.co_name + _print(file, + ' File "%s", line %d, in %s' % (filename, lineno, name)) + linecache.checkcache(filename) + line = linecache.getline(filename, lineno, f.f_globals) + if line: _print(file, ' ' + line.strip()) + tb = tb.tb_next + n = n+1 def format_tb(tb, limit=None): - """A shorthand for 'format_list(extract_tb(tb, limit)).""" - return format_list(extract_tb(tb, limit=limit)) + """A shorthand for 'format_list(extract_stack(f, limit)).""" + return format_list(extract_tb(tb, limit)) def extract_tb(tb, limit=None): """Return list of up to limit pre-processed entries from traceback. @@ -102,11 +85,26 @@ leading and trailing whitespace stripped; if the source is not available it is None. """ - return list(_extract_tb_iter(tb, limit=limit)) + if limit is None: + if hasattr(sys, 'tracebacklimit'): + limit = sys.tracebacklimit + list = [] + n = 0 + while tb is not None and (limit is None or n < limit): + f = tb.tb_frame + lineno = tb.tb_lineno + co = f.f_code + filename = co.co_filename + name = co.co_name + linecache.checkcache(filename) + line = linecache.getline(filename, lineno, f.f_globals) + if line: line = line.strip() + else: line = None + list.append((filename, lineno, name, line)) + tb = tb.tb_next + n = n+1 + return list -# -# Exception formatting and output. -# _cause_message = ( "\nThe above exception was the direct cause " @@ -136,21 +134,6 @@ for it in its: yield from it -def _format_exception_iter(etype, value, tb, limit, chain): - if chain: - values = _iter_chain(value, tb) - else: - values = [(value, tb)] - - for value, tb in values: - if isinstance(value, str): - # This is a cause/context message line - yield value + '\n' - continue - if tb: - yield 'Traceback (most recent call last):\n' - yield from _format_list_iter(_extract_tb_iter(tb, limit=limit)) - yield from _format_exception_only_iter(type(value), value) def print_exception(etype, value, tb, limit=None, file=None, chain=True): """Print exception up to 'limit' stack trace entries from 'tb' to 'file'. @@ -165,8 +148,20 @@ """ if file is None: file = sys.stderr - for line in _format_exception_iter(etype, value, tb, limit, chain): - print(line, file=file, end="") + if chain: + values = _iter_chain(value, tb) + else: + values = [(value, tb)] + for value, tb in values: + if isinstance(value, str): + _print(file, value) + continue + if tb: + _print(file, 'Traceback (most recent call last):') + print_tb(tb, limit, file) + lines = format_exception_only(type(value), value) + for line in lines: + _print(file, line, '') def format_exception(etype, value, tb, limit=None, chain=True): """Format a stack trace and the exception information. @@ -177,7 +172,20 @@ these lines are concatenated and printed, exactly the same text is printed as does print_exception(). """ - return list(_format_exception_iter(etype, value, tb, limit, chain)) + list = [] + if chain: + values = _iter_chain(value, tb) + else: + values = [(value, tb)] + for value, tb in values: + if isinstance(value, str): + list.append(value + '\n') + continue + if tb: + list.append('Traceback (most recent call last):\n') + list.extend(format_tb(tb, limit)) + list.extend(format_exception_only(type(value), value)) + return list def format_exception_only(etype, value): """Format the exception part of a traceback. @@ -195,14 +203,10 @@ string in the list. """ - return list(_format_exception_only_iter(etype, value)) - -def _format_exception_only_iter(etype, value): # Gracefully handle (the way Python 2.4 and earlier did) the case of # being called with (None, None). if etype is None: - yield _format_final_exc_line(etype, value) - return + return [_format_final_exc_line(etype, value)] stype = etype.__name__ smod = etype.__module__ @@ -210,26 +214,26 @@ stype = smod + '.' + stype if not issubclass(etype, SyntaxError): - yield _format_final_exc_line(stype, value) - return + return [_format_final_exc_line(stype, value)] # It was a syntax error; show exactly where the problem was found. + lines = [] filename = value.filename or "" lineno = str(value.lineno) or '?' - yield ' File "{}", line {}\n'.format(filename, lineno) - + lines.append(' File "%s", line %s\n' % (filename, lineno)) badline = value.text offset = value.offset if badline is not None: - yield ' {}\n'.format(badline.strip()) + lines.append(' %s\n' % badline.strip()) if offset is not None: caretspace = badline.rstrip('\n')[:offset].lstrip() # non-space whitespace (likes tabs) must be kept for alignment caretspace = ((c.isspace() and c or ' ') for c in caretspace) # only three spaces to account for offset1 == pos 0 - yield ' {}^\n'.format(''.join(caretspace)) + lines.append(' %s^\n' % ''.join(caretspace)) msg = value.msg or "" - yield "{}: {}\n".format(stype, msg) + lines.append("%s: %s\n" % (stype, msg)) + return lines def _format_final_exc_line(etype, value): valuestr = _some_str(value) @@ -245,34 +249,38 @@ except: return '' % type(value).__name__ + def print_exc(limit=None, file=None, chain=True): """Shorthand for 'print_exception(*sys.exc_info(), limit, file)'.""" - print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) + if file is None: + file = sys.stderr + try: + etype, value, tb = sys.exc_info() + print_exception(etype, value, tb, limit, file, chain) + finally: + etype = value = tb = None + def format_exc(limit=None, chain=True): """Like print_exc() but return a string.""" - return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain)) + try: + etype, value, tb = sys.exc_info() + return ''.join( + format_exception(etype, value, tb, limit, chain)) + finally: + etype = value = tb = None + def print_last(limit=None, file=None, chain=True): """This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.""" if not hasattr(sys, "last_type"): raise ValueError("no last exception") + if file is None: + file = sys.stderr print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file, chain) -# -# Printing and Extracting Stacks. -# - -def _extract_stack_iter(f, limit=None): - return _extract_tb_or_stack_iter( - f, limit, lambda f: (f, f.f_lineno, f.f_back)) - -def _get_stack(f): - if f is None: - f = sys._getframe().f_back.f_back - return f def print_stack(f=None, limit=None, file=None): """Print a stack trace from its invocation point. @@ -281,11 +289,21 @@ stack frame at which to start. The optional 'limit' and 'file' arguments have the same meaning as for print_exception(). """ - print_list(extract_stack(_get_stack(f), limit=limit), file=file) + if f is None: + try: + raise ZeroDivisionError + except ZeroDivisionError: + f = sys.exc_info()[2].tb_frame.f_back + print_list(extract_stack(f, limit), file) def format_stack(f=None, limit=None): """Shorthand for 'format_list(extract_stack(f, limit))'.""" - return format_list(extract_stack(_get_stack(f), limit=limit)) + if f is None: + try: + raise ZeroDivisionError + except ZeroDivisionError: + f = sys.exc_info()[2].tb_frame.f_back + return format_list(extract_stack(f, limit)) def extract_stack(f=None, limit=None): """Extract the raw traceback from the current stack frame. @@ -296,6 +314,27 @@ line number, function name, text), and the entries are in order from oldest to newest stack frame. """ - stack = list(_extract_stack_iter(_get_stack(f), limit=limit)) - stack.reverse() - return stack + if f is None: + try: + raise ZeroDivisionError + except ZeroDivisionError: + f = sys.exc_info()[2].tb_frame.f_back + if limit is None: + if hasattr(sys, 'tracebacklimit'): + limit = sys.tracebacklimit + list = [] + n = 0 + while f is not None and (limit is None or n < limit): + lineno = f.f_lineno + co = f.f_code + filename = co.co_filename + name = co.co_name + linecache.checkcache(filename) + line = linecache.getline(filename, lineno, f.f_globals) + if line: line = line.strip() + else: line = None + list.append((filename, lineno, name, line)) + f = f.f_back + n = n+1 + list.reverse() + return list diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/turtle.py --- a/Lib/turtle.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/turtle.py Fri Feb 01 23:12:09 2013 +0100 @@ -856,8 +856,8 @@ class Terminator (Exception): """Will be raised in TurtleScreen.update, if _RUNNING becomes False. - This stops execution of a turtle graphics script. - Main purpose: use in the Demo-Viewer turtle.Demo.py. + Thus stops execution of turtle graphics script. Main purpose: use in + in the Demo-Viewer turtle.Demo.py. """ pass @@ -3843,18 +3843,18 @@ key = "Turtle."+methodname docsdict[key] = eval(key).__doc__ - with open("%s.py" % filename,"w") as f: - keys = sorted([x for x in docsdict.keys() - if x.split('.')[1] not in _alias_list]) - f.write('docsdict = {\n\n') - for key in keys[:-1]: - f.write('%s :\n' % repr(key)) - f.write(' """%s\n""",\n\n' % docsdict[key]) - key = keys[-1] + f = open("%s.py" % filename,"w") + keys = sorted([x for x in docsdict.keys() + if x.split('.')[1] not in _alias_list]) + f.write('docsdict = {\n\n') + for key in keys[:-1]: f.write('%s :\n' % repr(key)) - f.write(' """%s\n"""\n\n' % docsdict[key]) - f.write("}\n") - f.close() + f.write(' """%s\n""",\n\n' % docsdict[key]) + key = keys[-1] + f.write('%s :\n' % repr(key)) + f.write(' """%s\n"""\n\n' % docsdict[key]) + f.write("}\n") + f.close() def read_docstrings(lang): """Read in docstrings from lang-specific docstring dictionary. diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/turtledemo/__main__.py --- a/Lib/turtledemo/__main__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/turtledemo/__main__.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,7 @@ from idlelib.Percolator import Percolator from idlelib.ColorDelegator import ColorDelegator from idlelib.textView import view_file # TextViewer -from importlib import reload +from imp import reload import turtle import time diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/case.py --- a/Lib/unittest/case.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/case.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,7 +7,6 @@ import re import warnings import collections -import contextlib from . import result from .util import (strclass, safe_repr, _count_diff_all_purpose, @@ -23,15 +22,21 @@ """ Raise this exception in a test to skip it. - Usually you can use TestCase.skipTest() or one of the skipping decorators + Usually you can use TestResult.skip() or one of the skipping decorators instead of raising this directly. """ -class _ShouldStop(Exception): +class _ExpectedFailure(Exception): """ - The test should stop. + Raise this when a test is expected to fail. + + This is an implementation detail. """ + def __init__(self, exc_info): + super(_ExpectedFailure, self).__init__() + self.exc_info = exc_info + class _UnexpectedSuccess(Exception): """ The test was supposed to fail, but it didn't! @@ -39,40 +44,13 @@ class _Outcome(object): - def __init__(self, result=None): - self.expecting_failure = False - self.result = result - self.result_supports_subtests = hasattr(result, "addSubTest") + def __init__(self): self.success = True - self.skipped = [] + self.skipped = None + self.unexpectedSuccess = None self.expectedFailure = None self.errors = [] - - @contextlib.contextmanager - def testPartExecutor(self, test_case, isTest=False): - old_success = self.success - self.success = True - try: - yield - except KeyboardInterrupt: - raise - except SkipTest as e: - self.success = False - self.skipped.append((test_case, str(e))) - except _ShouldStop: - pass - except: - exc_info = sys.exc_info() - if self.expecting_failure: - self.expectedFailure = exc_info - else: - self.success = False - self.errors.append((test_case, exc_info)) - else: - if self.result_supports_subtests and self.success: - self.errors.append((test_case, None)) - finally: - self.success = self.success and old_success + self.failures = [] def _id(obj): @@ -110,9 +88,16 @@ return skip(reason) return _id -def expectedFailure(test_item): - test_item.__unittest_expecting_failure__ = True - return test_item + +def expectedFailure(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + try: + func(*args, **kwargs) + except Exception: + raise _ExpectedFailure(sys.exc_info()) + raise _UnexpectedSuccess + return wrapper class _AssertRaisesBaseContext(object): @@ -252,23 +237,24 @@ should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run. + """ - When subclassing TestCase, you can set these attributes: - * failureException: determines which exception will be raised when - the instance's assertion methods fail; test methods raising this - exception will be deemed to have 'failed' rather than 'errored'. - * longMessage: determines whether long messages (including repr of - objects used in assert methods) will be printed on failure in *addition* - to any explicit message passed. - * maxDiff: sets the maximum length of a diff in failure messages - by assert methods using difflib. It is looked up as an instance - attribute so can be configured by individual tests if required. - """ + # This attribute determines which exception will be raised when + # the instance's assertion methods fail; test methods raising this + # exception will be deemed to have 'failed' rather than 'errored' failureException = AssertionError + # This attribute determines whether long messages (including repr of + # objects used in assert methods) will be printed on failure in *addition* + # to any explicit message passed. + longMessage = True + # This attribute sets the maximum length of a diff in failure messages + # by assert methods using difflib. It is looked up as an instance attribute + # so can be configured by individual tests if required. + maxDiff = 80*8 # If a string is longer than _diffThreshold, use normal comparison instead @@ -285,7 +271,7 @@ not have a method with the specified name. """ self._testMethodName = methodName - self._outcome = None + self._outcomeForDoCleanups = None self._testMethodDoc = 'No test' try: testMethod = getattr(self, methodName) @@ -298,7 +284,6 @@ else: self._testMethodDoc = testMethod.__doc__ self._cleanups = [] - self._subtest = None # Map types to custom assertEqual functions that will compare # instances of said type in more detail to generate a more useful @@ -386,80 +371,44 @@ return "<%s testMethod=%s>" % \ (strclass(self.__class__), self._testMethodName) - def _addSkip(self, result, test_case, reason): + def _addSkip(self, result, reason): addSkip = getattr(result, 'addSkip', None) if addSkip is not None: - addSkip(test_case, reason) + addSkip(self, reason) else: warnings.warn("TestResult has no addSkip method, skips not reported", RuntimeWarning, 2) - result.addSuccess(test_case) + result.addSuccess(self) - @contextlib.contextmanager - def subTest(self, msg=None, **params): - """Return a context manager that will return the enclosed block - of code in a subtest identified by the optional message and - keyword parameters. A failure in the subtest marks the test - case as failed but resumes execution at the end of the enclosed - block, allowing further test code to be executed. - """ - if not self._outcome.result_supports_subtests: - yield - return - parent = self._subtest - if parent is None: - params_map = collections.ChainMap(params) - else: - params_map = parent.params.new_child(params) - self._subtest = _SubTest(self, msg, params_map) + def _executeTestPart(self, function, outcome, isTest=False): try: - with self._outcome.testPartExecutor(self._subtest, isTest=True): - yield - if not self._outcome.success: - result = self._outcome.result - if result is not None and result.failfast: - raise _ShouldStop - elif self._outcome.expectedFailure: - # If the test is expecting a failure, we really want to - # stop now and register the expected failure. - raise _ShouldStop - finally: - self._subtest = parent - - def _feedErrorsToResult(self, result, errors): - for test, exc_info in errors: - if isinstance(test, _SubTest): - result.addSubTest(test.test_case, test, exc_info) - elif exc_info is not None: - if issubclass(exc_info[0], self.failureException): - result.addFailure(test, exc_info) - else: - result.addError(test, exc_info) - - def _addExpectedFailure(self, result, exc_info): - try: - addExpectedFailure = result.addExpectedFailure - except AttributeError: - warnings.warn("TestResult has no addExpectedFailure method, reporting as passes", - RuntimeWarning) - result.addSuccess(self) - else: - addExpectedFailure(self, exc_info) - - def _addUnexpectedSuccess(self, result): - try: - addUnexpectedSuccess = result.addUnexpectedSuccess - except AttributeError: - warnings.warn("TestResult has no addUnexpectedSuccess method, reporting as failure", - RuntimeWarning) - # We need to pass an actual exception and traceback to addFailure, - # otherwise the legacy result can choke. - try: - raise _UnexpectedSuccess from None - except _UnexpectedSuccess: - result.addFailure(self, sys.exc_info()) - else: - addUnexpectedSuccess(self) + function() + except KeyboardInterrupt: + raise + except SkipTest as e: + outcome.success = False + outcome.skipped = str(e) + except _UnexpectedSuccess: + exc_info = sys.exc_info() + outcome.success = False + if isTest: + outcome.unexpectedSuccess = exc_info + else: + outcome.errors.append(exc_info) + except _ExpectedFailure: + outcome.success = False + exc_info = sys.exc_info() + if isTest: + outcome.expectedFailure = exc_info + else: + outcome.errors.append(exc_info) + except self.failureException: + outcome.success = False + outcome.failures.append(sys.exc_info()) + exc_info = sys.exc_info() + except: + outcome.success = False + outcome.errors.append(sys.exc_info()) def run(self, result=None): orig_result = result @@ -478,38 +427,46 @@ try: skip_why = (getattr(self.__class__, '__unittest_skip_why__', '') or getattr(testMethod, '__unittest_skip_why__', '')) - self._addSkip(result, self, skip_why) + self._addSkip(result, skip_why) finally: result.stopTest(self) return - expecting_failure = getattr(testMethod, - "__unittest_expecting_failure__", False) try: - outcome = _Outcome(result) - self._outcome = outcome + outcome = _Outcome() + self._outcomeForDoCleanups = outcome - with outcome.testPartExecutor(self): - self.setUp() + self._executeTestPart(self.setUp, outcome) if outcome.success: - outcome.expecting_failure = expecting_failure - with outcome.testPartExecutor(self, isTest=True): - testMethod() - outcome.expecting_failure = False - with outcome.testPartExecutor(self): - self.tearDown() + self._executeTestPart(testMethod, outcome, isTest=True) + self._executeTestPart(self.tearDown, outcome) self.doCleanups() - for test, reason in outcome.skipped: - self._addSkip(result, test, reason) - self._feedErrorsToResult(result, outcome.errors) if outcome.success: - if expecting_failure: - if outcome.expectedFailure: - self._addExpectedFailure(result, outcome.expectedFailure) + result.addSuccess(self) + else: + if outcome.skipped is not None: + self._addSkip(result, outcome.skipped) + for exc_info in outcome.errors: + result.addError(self, exc_info) + for exc_info in outcome.failures: + result.addFailure(self, exc_info) + if outcome.unexpectedSuccess is not None: + addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None) + if addUnexpectedSuccess is not None: + addUnexpectedSuccess(self) else: - self._addUnexpectedSuccess(result) - else: - result.addSuccess(self) + warnings.warn("TestResult has no addUnexpectedSuccess method, reporting as failures", + RuntimeWarning) + result.addFailure(self, outcome.unexpectedSuccess) + + if outcome.expectedFailure is not None: + addExpectedFailure = getattr(result, 'addExpectedFailure', None) + if addExpectedFailure is not None: + addExpectedFailure(self, outcome.expectedFailure) + else: + warnings.warn("TestResult has no addExpectedFailure method, reporting as passes", + RuntimeWarning) + result.addSuccess(self) return result finally: result.stopTest(self) @@ -521,11 +478,11 @@ def doCleanups(self): """Execute all cleanup functions. Normally called for you after tearDown.""" - outcome = self._outcome or _Outcome() + outcome = self._outcomeForDoCleanups or _Outcome() while self._cleanups: function, args, kwargs = self._cleanups.pop() - with outcome.testPartExecutor(self): - function(*args, **kwargs) + part = lambda: function(*args, **kwargs) + self._executeTestPart(part, outcome) # return this for backwards compatibility # even though we no longer us it internally @@ -1256,39 +1213,3 @@ return self._description doc = self._testFunc.__doc__ return doc and doc.split("\n")[0].strip() or None - - -class _SubTest(TestCase): - - def __init__(self, test_case, message, params): - super().__init__() - self._message = message - self.test_case = test_case - self.params = params - self.failureException = test_case.failureException - - def runTest(self): - raise NotImplementedError("subtests cannot be run directly") - - def _subDescription(self): - parts = [] - if self._message: - parts.append("[{}]".format(self._message)) - if self.params: - params_desc = ', '.join( - "{}={!r}".format(k, v) - for (k, v) in sorted(self.params.items())) - parts.append("({})".format(params_desc)) - return " ".join(parts) or '()' - - def id(self): - return "{} {}".format(self.test_case.id(), self._subDescription()) - - def shortDescription(self): - """Returns a one-line description of the subtest, or None if no - description has been provided. - """ - return self.test_case.shortDescription() - - def __str__(self): - return "{} {}".format(self.test_case, self._subDescription()) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/loader.py --- a/Lib/unittest/loader.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/loader.py Fri Feb 01 23:12:09 2013 +0100 @@ -34,14 +34,6 @@ TestClass = type(classname, (case.TestCase,), attrs) return suiteClass((TestClass(methodname),)) -def _make_skipped_test(methodname, exception, suiteClass): - @case.skip(str(exception)) - def testSkipped(self): - pass - attrs = {methodname: testSkipped} - TestClass = type("ModuleSkipped", (case.TestCase,), attrs) - return suiteClass((TestClass(methodname),)) - def _jython_aware_splitext(path): if path.lower().endswith('$py.class'): return path[:-9] @@ -119,7 +111,7 @@ elif (isinstance(obj, types.FunctionType) and isinstance(parent, type) and issubclass(parent, case.TestCase)): - name = parts[-1] + name = obj.__name__ inst = parent(name) # static methods follow a different path if not isinstance(getattr(inst, name), types.FunctionType): @@ -177,9 +169,6 @@ The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover(). - - Paths are sorted before being imported to ensure reproducible execution - order even on filesystems with non-alphabetical ordering like ext3/4. """ set_implicit_top = False if top_level_dir is None and self._top_level_dir is not None: @@ -256,7 +245,7 @@ def _find_tests(self, start_dir, pattern): """Used by discovery. Yields test suites it loads.""" - paths = sorted(os.listdir(start_dir)) + paths = os.listdir(start_dir) for path in paths: full_path = os.path.join(start_dir, path) @@ -270,8 +259,6 @@ name = self._get_name_from_path(full_path) try: module = self._get_module_from_name(name) - except case.SkipTest as e: - yield _make_skipped_test(name, e, self.suiteClass) except: yield _make_failed_import_test(name, self.suiteClass) else: diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/main.py --- a/Lib/unittest/main.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/main.py Fri Feb 01 23:12:09 2013 +0100 @@ -164,10 +164,7 @@ # to support python -m unittest ... self.module = None else: - if isinstance(self.defaultTest, str): - self.testNames = (self.defaultTest,) - else: - self.testNames = list(self.defaultTest) + self.testNames = (self.defaultTest,) self.createTests() def createTests(self): @@ -178,7 +175,6 @@ self.module) def _getOptParser(self): - import optparse parser = optparse.OptionParser() parser.prog = self.progName parser.add_option('-v', '--verbose', dest='verbose', default=False, @@ -223,10 +219,7 @@ parser.add_option('-t', '--top-level-directory', dest='top', default=None, help='Top level directory of project (defaults to start directory)') - def _do_discovery(self, argv, Loader=None): - if Loader is None: - Loader = lambda: self.testLoader - + def _do_discovery(self, argv, Loader=loader.TestLoader): # handle command line args for test discovery self.progName = '%s discover' % self.progName parser = self._getOptParser() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/mock.py Fri Feb 01 23:12:09 2013 +0100 @@ -27,7 +27,7 @@ import inspect import pprint import sys -from functools import wraps, partial +from functools import wraps BaseExceptions = (BaseException,) @@ -66,45 +66,55 @@ ) -def _get_signature_object(func, as_instance, eat_self): - """ - Given an arbitrary, possibly callable object, try to create a suitable - signature object. - Return a (reduced func, signature) tuple, or None. - """ - if isinstance(func, type) and not as_instance: - # If it's a type and should be modelled as a type, use __init__. +def _getsignature(func, skipfirst, instance=False): + if isinstance(func, type) and not instance: try: func = func.__init__ except AttributeError: - return None - # Skip the `self` argument in __init__ - eat_self = True + return + skipfirst = True elif not isinstance(func, FunctionTypes): - # If we really want to model an instance of the passed type, - # __call__ should be looked up, not __init__. + # for classes where instance is True we end up here too try: func = func.__call__ except AttributeError: - return None - if eat_self: - sig_func = partial(func, None) - else: - sig_func = func + return + try: - return func, inspect.signature(sig_func) - except ValueError: - # Certain callable types are not supported by inspect.signature() - return None + argspec = inspect.getfullargspec(func) + except TypeError: + # C function / method, possibly inherited object().__init__ + return + + regargs, varargs, varkw, defaults, kwonly, kwonlydef, ann = argspec + + + # instance methods and classmethods need to lose the self argument + if getattr(func, '__self__', None) is not None: + regargs = regargs[1:] + if skipfirst: + # this condition and the above one are never both True - why? + regargs = regargs[1:] + + signature = inspect.formatargspec( + regargs, varargs, varkw, defaults, + kwonly, kwonlydef, ann, formatvalue=lambda value: "") + return signature[1:-1], func def _check_signature(func, mock, skipfirst, instance=False): - sig = _get_signature_object(func, instance, skipfirst) - if sig is None: + if not _callable(func): return - func, sig = sig - def checksig(_mock_self, *args, **kwargs): - sig.bind(*args, **kwargs) + + result = _getsignature(func, skipfirst, instance) + if result is None: + return + signature, func = result + + # can't use self because "self" is common as an argument name + # unfortunately even not in the first place + src = "lambda _mock_self, %s: None" % signature + checksig = eval(src, {}) _copy_func_details(func, checksig) type(mock)._mock_check_sig = checksig @@ -156,12 +166,15 @@ return skipfirst = isinstance(original, type) - result = _get_signature_object(original, instance, skipfirst) + result = _getsignature(original, skipfirst, instance) if result is None: + # was a C function (e.g. object().__init__ ) that can't be mocked return - func, sig = result - def checksig(*args, **kwargs): - sig.bind(*args, **kwargs) + + signature, func = result + + src = "lambda %s: None" % signature + checksig = eval(src, {}) _copy_func_details(func, checksig) name = original.__name__ @@ -355,7 +368,7 @@ def __init__( self, spec=None, wraps=None, name=None, spec_set=None, parent=None, _spec_state=None, _new_name='', _new_parent=None, - _spec_as_instance=False, _eat_self=None, **kwargs + **kwargs ): if _new_parent is None: _new_parent = parent @@ -369,10 +382,8 @@ if spec_set is not None: spec = spec_set spec_set = True - if _eat_self is None: - _eat_self = parent is not None - - self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self) + + self._mock_add_spec(spec, spec_set) __dict__['_mock_children'] = {} __dict__['_mock_wraps'] = wraps @@ -417,26 +428,20 @@ self._mock_add_spec(spec, spec_set) - def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False, - _eat_self=False): + def _mock_add_spec(self, spec, spec_set): _spec_class = None - _spec_signature = None if spec is not None and not _is_list(spec): if isinstance(spec, type): _spec_class = spec else: _spec_class = _get_class(spec) - res = _get_signature_object(spec, - _spec_as_instance, _eat_self) - _spec_signature = res and res[1] spec = dir(spec) __dict__ = self.__dict__ __dict__['_spec_class'] = _spec_class __dict__['_spec_set'] = spec_set - __dict__['_spec_signature'] = _spec_signature __dict__['_mock_methods'] = spec @@ -690,6 +695,7 @@ self._mock_children[name] = _deleted + def _format_mock_call_signature(self, args, kwargs): name = self._mock_name or 'mock' return _format_call_signature(name, args, kwargs) @@ -705,28 +711,6 @@ return message % (expected_string, actual_string) - def _call_matcher(self, _call): - """ - Given a call (or simply a (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. - """ - sig = self._spec_signature - if sig is not None: - if len(_call) == 2: - name = '' - args, kwargs = _call - else: - name, args, kwargs = _call - try: - return name, sig.bind(*args, **kwargs) - except TypeError as e: - return e.with_traceback(None) - else: - return _call - - def assert_called_with(_mock_self, *args, **kwargs): """assert that the mock was called with the specified arguments. @@ -737,14 +721,9 @@ expected = self._format_mock_call_signature(args, kwargs) raise AssertionError('Expected call: %s\nNot called' % (expected,)) - def _error_message(): + if self.call_args != (args, kwargs): msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None - raise AssertionError(_error_message()) from cause + raise AssertionError(msg) def assert_called_once_with(_mock_self, *args, **kwargs): @@ -768,21 +747,18 @@ If `any_order` is True then the calls can be in any order, but they must all appear in `mock_calls`.""" - expected = [self._call_matcher(c) for c in calls] - cause = expected if isinstance(expected, Exception) else None - all_calls = _CallList(self._call_matcher(c) for c in self.mock_calls) if not any_order: - if expected not in all_calls: + if calls not in self.mock_calls: raise AssertionError( 'Calls not found.\nExpected: %r\n' 'Actual: %r' % (calls, self.mock_calls) - ) from cause + ) return - all_calls = list(all_calls) + all_calls = list(self.mock_calls) not_found = [] - for kall in expected: + for kall in calls: try: all_calls.remove(kall) except ValueError: @@ -790,7 +766,7 @@ if not_found: raise AssertionError( '%r not all found in call list' % (tuple(not_found),) - ) from cause + ) def assert_any_call(self, *args, **kwargs): @@ -799,14 +775,12 @@ The assert passes if the mock has *ever* been called, unlike `assert_called_with` and `assert_called_once_with` that only pass if the call is the most recent one.""" - expected = self._call_matcher((args, kwargs)) - actual = [self._call_matcher(c) for c in self.call_args_list] - if expected not in actual: - cause = expected if isinstance(expected, Exception) else None + kall = call(*args, **kwargs) + if kall not in self.call_args_list: expected_string = self._format_mock_call_signature(args, kwargs) raise AssertionError( '%s call not found' % expected_string - ) from cause + ) def _get_child_mock(self, **kw): @@ -876,12 +850,11 @@ self = _mock_self self.called = True self.call_count += 1 + self.call_args = _Call((args, kwargs), two=True) + self.call_args_list.append(_Call((args, kwargs), two=True)) + _new_name = self._mock_new_name _new_parent = self._mock_new_parent - - _call = _Call((args, kwargs), two=True) - self.call_args = _call - self.call_args_list.append(_call) self.mock_calls.append(_Call(('', args, kwargs))) seen = set() @@ -931,11 +904,11 @@ result = next(effect) if _is_exception(result): raise result - if result is DEFAULT: - result = self.return_value return result ret_val = effect(*args, **kwargs) + if ret_val is DEFAULT: + ret_val = self.return_value if (self._mock_wraps is not None and self._mock_return_value is DEFAULT): @@ -975,6 +948,9 @@ the next value from the iterable. If any of the members of the iterable are exceptions they will be raised instead of returned. + If `side_effect` is an iterable then each call to the mock will return + the next value from the iterable. + * `return_value`: The value returned when the mock is called. By default this is a new Mock (created on first access). See the `return_value` attribute. @@ -1441,7 +1417,7 @@ you pass in `create=True`, and the attribute doesn't exist, patch will create the attribute for you when the patched function is called, and delete it again afterwards. This is useful for writing tests against - attributes that your production code creates at runtime. It is off by + attributes that your production code creates at runtime. It is off by by default because it can be dangerous. With it switched on you can write passing tests against APIs that don't actually exist! @@ -2055,8 +2031,6 @@ elif spec is None: # None we mock with a normal mock without a spec _kwargs = {} - if _kwargs and instance: - _kwargs['_spec_as_instance'] = True _kwargs.update(kwargs) @@ -2123,12 +2097,10 @@ if isinstance(spec, FunctionTypes): parent = mock.mock + new = MagicMock(parent=parent, name=entry, _new_name=entry, + _new_parent=parent, **kwargs) + mock._mock_children[entry] = new skipfirst = _must_skip(spec, entry, is_type) - kwargs['_eat_self'] = skipfirst - new = MagicMock(parent=parent, name=entry, _new_name=entry, - _new_parent=parent, - **kwargs) - mock._mock_children[entry] = new _check_signature(original, new, skipfirst=skipfirst) # so functions created with _set_signature become instance attributes, @@ -2142,10 +2114,6 @@ def _must_skip(spec, entry, is_type): - """ - Return whether we should skip the first argument on spec's `entry` - attribute. - """ if not isinstance(spec, type): if entry in getattr(spec, '__dict__', {}): # instance attribute - shouldn't skip @@ -2158,12 +2126,7 @@ continue if isinstance(result, (staticmethod, classmethod)): return False - elif isinstance(getattr(result, '__get__', None), MethodWrapperTypes): - # Normal method => skip if looked up on type - # (if looked up on instance, self is already skipped) - return is_type - else: - return False + return is_type # shouldn't get here unless function is a dynamically provided attribute # XXXX untested behaviour @@ -2197,31 +2160,9 @@ type(ANY.__eq__), ) -MethodWrapperTypes = ( - type(ANY.__eq__.__get__), -) - file_spec = None -def _iterate_read_data(read_data): - # Helper for mock_open: - # Retrieve lines from read_data via a generator so that separate calls to - # readline, read, and readlines are properly interleaved - data_as_list = ['{}\n'.format(l) for l in read_data.split('\n')] - - if data_as_list[-1] == '\n': - # If the last line ended in a newline, the list comprehension will have an - # extra entry that's just a newline. Remove this. - data_as_list = data_as_list[:-1] - else: - # If there wasn't an extra newline by itself, then the file being - # emulated doesn't have a newline to end the last line remove the - # newline that our naive format() added - data_as_list[-1] = data_as_list[-1][:-1] - - for line in data_as_list: - yield line def mock_open(mock=None, read_data=''): """ @@ -2232,27 +2173,9 @@ default) then a `MagicMock` will be created for you, with the API limited to methods or attributes available on standard file handles. - `read_data` is a string for the `read` methoddline`, and `readlines` of the - file handle to return. This is an empty string by default. + `read_data` is a string for the `read` method of the file handle to return. + This is an empty string by default. """ - def _readlines_side_effect(*args, **kwargs): - if handle.readlines.return_value is not None: - return handle.readlines.return_value - return list(_data) - - def _read_side_effect(*args, **kwargs): - if handle.read.return_value is not None: - return handle.read.return_value - return ''.join(_data) - - def _readline_side_effect(): - if handle.readline.return_value is not None: - while True: - yield handle.readline.return_value - for line in _data: - yield line - - global file_spec if file_spec is None: import _io @@ -2262,18 +2185,9 @@ mock = MagicMock(name='open', spec=open) handle = MagicMock(spec=file_spec) + handle.write.return_value = None handle.__enter__.return_value = handle - - _data = _iterate_read_data(read_data) - - handle.write.return_value = None - handle.read.return_value = None - handle.readline.return_value = None - handle.readlines.return_value = None - - handle.read.side_effect = _read_side_effect - handle.readline.side_effect = _readline_side_effect() - handle.readlines.side_effect = _readlines_side_effect + handle.read.return_value = read_data mock.return_value = handle return mock diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/result.py --- a/Lib/unittest/result.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/result.py Fri Feb 01 23:12:09 2013 +0100 @@ -121,22 +121,6 @@ self.failures.append((test, self._exc_info_to_string(err, test))) self._mirrorOutput = True - @failfast - def addSubTest(self, test, subtest, err): - """Called at the end of a subtest. - 'err' is None if the subtest ended successfully, otherwise it's a - tuple of values as returned by sys.exc_info(). - """ - # By default, we don't do anything with successful subtests, but - # more sophisticated test results might want to record them. - if err is not None: - if issubclass(err[0], test.failureException): - errors = self.failures - else: - errors = self.errors - errors.append((subtest, self._exc_info_to_string(err, test))) - self._mirrorOutput = True - def addSuccess(self, test): "Called when a test has completed successfully" pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/signals.py --- a/Lib/unittest/signals.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/signals.py Fri Feb 01 23:12:09 2013 +0100 @@ -9,20 +9,6 @@ class _InterruptHandler(object): def __init__(self, default_handler): self.called = False - self.original_handler = default_handler - if isinstance(default_handler, int): - if default_handler == signal.SIG_DFL: - # Pretend it's signal.default_int_handler instead. - default_handler = signal.default_int_handler - elif default_handler == signal.SIG_IGN: - # Not quite the same thing as SIG_IGN, but the closest we - # can make it: do nothing. - def default_handler(unused_signum, unused_frame): - pass - else: - raise TypeError("expected SIGINT signal handler to be " - "signal.SIG_IGN, signal.SIG_DFL, or a " - "callable object") self.default_handler = default_handler def __call__(self, signum, frame): @@ -68,4 +54,4 @@ global _interrupt_handler if _interrupt_handler is not None: - signal.signal(signal.SIGINT, _interrupt_handler.original_handler) + signal.signal(signal.SIGINT, _interrupt_handler.default_handler) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/support.py --- a/Lib/unittest/test/support.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/support.py Fri Feb 01 23:12:09 2013 +0100 @@ -41,7 +41,7 @@ self.fail("Problem hashing %s and %s: %s" % (obj_1, obj_2, e)) -class _BaseLoggingResult(unittest.TestResult): +class LoggingResult(unittest.TestResult): def __init__(self, log): self._events = log super().__init__() @@ -52,7 +52,7 @@ def startTestRun(self): self._events.append('startTestRun') - super().startTestRun() + super(LoggingResult, self).startTestRun() def stopTest(self, test): self._events.append('stopTest') @@ -60,7 +60,7 @@ def stopTestRun(self): self._events.append('stopTestRun') - super().stopTestRun() + super(LoggingResult, self).stopTestRun() def addFailure(self, *args): self._events.append('addFailure') @@ -68,7 +68,7 @@ def addSuccess(self, *args): self._events.append('addSuccess') - super().addSuccess(*args) + super(LoggingResult, self).addSuccess(*args) def addError(self, *args): self._events.append('addError') @@ -76,39 +76,15 @@ def addSkip(self, *args): self._events.append('addSkip') - super().addSkip(*args) + super(LoggingResult, self).addSkip(*args) def addExpectedFailure(self, *args): self._events.append('addExpectedFailure') - super().addExpectedFailure(*args) + super(LoggingResult, self).addExpectedFailure(*args) def addUnexpectedSuccess(self, *args): self._events.append('addUnexpectedSuccess') - super().addUnexpectedSuccess(*args) - - -class LegacyLoggingResult(_BaseLoggingResult): - """ - A legacy TestResult implementation, without an addSubTest method, - which records its method calls. - """ - - @property - def addSubTest(self): - raise AttributeError - - -class LoggingResult(_BaseLoggingResult): - """ - A TestResult implementation which records its method calls. - """ - - def addSubTest(self, test, subtest, err): - if err is None: - self._events.append('addSubTestSuccess') - else: - self._events.append('addSubTestFailure') - super().addSubTest(test, subtest, err) + super(LoggingResult, self).addUnexpectedSuccess(*args) class ResultWithNoStartTestRunStopTestRun(object): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_break.py --- a/Lib/unittest/test/test_break.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_break.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,12 +13,9 @@ @unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 " "if threads have been used") class TestBreak(unittest.TestCase): - int_handler = None def setUp(self): self._default_handler = signal.getsignal(signal.SIGINT) - if self.int_handler is not None: - signal.signal(signal.SIGINT, self.int_handler) def tearDown(self): signal.signal(signal.SIGINT, self._default_handler) @@ -75,10 +72,6 @@ def testSecondInterrupt(self): - # Can't use skipIf decorator because the signal handler may have - # been changed after defining this method. - if signal.getsignal(signal.SIGINT) == signal.SIG_IGN: - self.skipTest("test requires SIGINT to not be ignored") result = unittest.TestResult() unittest.installHandler() unittest.registerResult(result) @@ -128,10 +121,6 @@ def testHandlerReplacedButCalled(self): - # Can't use skipIf decorator because the signal handler may have - # been changed after defining this method. - if signal.getsignal(signal.SIGINT) == signal.SIG_IGN: - self.skipTest("test requires SIGINT to not be ignored") # If our handler has been replaced (is no longer installed) but is # called by the *new* handler, then it isn't safe to delay the # SIGINT and we should immediately delegate to the default handler @@ -261,24 +250,3 @@ test() self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler) - -@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill") -@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows") -@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 " - "if threads have been used") -class TestBreakDefaultIntHandler(TestBreak): - int_handler = signal.default_int_handler - -@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill") -@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows") -@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 " - "if threads have been used") -class TestBreakSignalIgnored(TestBreak): - int_handler = signal.SIG_IGN - -@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill") -@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows") -@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 " - "if threads have been used") -class TestBreakSignalDefault(TestBreak): - int_handler = signal.SIG_DFL diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_case.py --- a/Lib/unittest/test/test_case.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_case.py Fri Feb 01 23:12:09 2013 +0100 @@ -13,7 +13,7 @@ import unittest from .support import ( - TestEquality, TestHashing, LoggingResult, LegacyLoggingResult, + TestEquality, TestHashing, LoggingResult, ResultWithNoStartTestRunStopTestRun ) @@ -297,98 +297,6 @@ Foo('test').run() - def _check_call_order__subtests(self, result, events, expected_events): - class Foo(Test.LoggingTestCase): - def test(self): - super(Foo, self).test() - for i in [1, 2, 3]: - with self.subTest(i=i): - if i == 1: - self.fail('failure') - for j in [2, 3]: - with self.subTest(j=j): - if i * j == 6: - raise RuntimeError('raised by Foo.test') - 1 / 0 - - # Order is the following: - # i=1 => subtest failure - # i=2, j=2 => subtest success - # i=2, j=3 => subtest error - # i=3, j=2 => subtest error - # i=3, j=3 => subtest success - # toplevel => error - Foo(events).run(result) - self.assertEqual(events, expected_events) - - def test_run_call_order__subtests(self): - events = [] - result = LoggingResult(events) - expected = ['startTest', 'setUp', 'test', 'tearDown', - 'addSubTestFailure', 'addSubTestSuccess', - 'addSubTestFailure', 'addSubTestFailure', - 'addSubTestSuccess', 'addError', 'stopTest'] - self._check_call_order__subtests(result, events, expected) - - def test_run_call_order__subtests_legacy(self): - # With a legacy result object (without a addSubTest method), - # text execution stops after the first subtest failure. - events = [] - result = LegacyLoggingResult(events) - expected = ['startTest', 'setUp', 'test', 'tearDown', - 'addFailure', 'stopTest'] - self._check_call_order__subtests(result, events, expected) - - def _check_call_order__subtests_success(self, result, events, expected_events): - class Foo(Test.LoggingTestCase): - def test(self): - super(Foo, self).test() - for i in [1, 2]: - with self.subTest(i=i): - for j in [2, 3]: - with self.subTest(j=j): - pass - - Foo(events).run(result) - self.assertEqual(events, expected_events) - - def test_run_call_order__subtests_success(self): - events = [] - result = LoggingResult(events) - # The 6 subtest successes are individually recorded, in addition - # to the whole test success. - expected = (['startTest', 'setUp', 'test', 'tearDown'] - + 6 * ['addSubTestSuccess'] - + ['addSuccess', 'stopTest']) - self._check_call_order__subtests_success(result, events, expected) - - def test_run_call_order__subtests_success_legacy(self): - # With a legacy result, only the whole test success is recorded. - events = [] - result = LegacyLoggingResult(events) - expected = ['startTest', 'setUp', 'test', 'tearDown', - 'addSuccess', 'stopTest'] - self._check_call_order__subtests_success(result, events, expected) - - def test_run_call_order__subtests_failfast(self): - events = [] - result = LoggingResult(events) - result.failfast = True - - class Foo(Test.LoggingTestCase): - def test(self): - super(Foo, self).test() - with self.subTest(i=1): - self.fail('failure') - with self.subTest(i=2): - self.fail('failure') - self.fail('failure') - - expected = ['startTest', 'setUp', 'test', 'tearDown', - 'addSubTestFailure', 'stopTest'] - Foo(events).run(result) - self.assertEqual(events, expected) - # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_discovery.py --- a/Lib/unittest/test/test_discovery.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_discovery.py Fri Feb 01 23:12:09 2013 +0100 @@ -46,9 +46,9 @@ def restore_isdir(): os.path.isdir = original_isdir - path_lists = [['test2.py', 'test1.py', 'not_a_test.py', 'test_dir', + path_lists = [['test1.py', 'test2.py', 'not_a_test.py', 'test_dir', 'test.foo', 'test-not-a-module.py', 'another_dir'], - ['test4.py', 'test3.py', ]] + ['test3.py', 'test4.py', ]] os.listdir = lambda path: path_lists.pop(0) self.addCleanup(restore_listdir) @@ -70,8 +70,6 @@ loader._top_level_dir = top_level suite = list(loader._find_tests(top_level, 'test*.py')) - # The test suites found should be sorted alphabetically for reliable - # execution order. expected = [name + ' module tests' for name in ('test1', 'test2')] expected.extend([('test_dir.%s' % name) + ' module tests' for name in @@ -134,7 +132,6 @@ # and directly from the test_directory2 package self.assertEqual(suite, ['load_tests', 'test_directory2' + ' module tests']) - # The test module paths should be sorted for reliable execution order self.assertEqual(Module.paths, ['test_directory', 'test_directory2']) # load_tests should have been called once with loader, tests and pattern @@ -187,9 +184,11 @@ self.assertEqual(_find_tests_args, [(start_dir, 'pattern')]) self.assertIn(top_level_dir, sys.path) - def setup_import_issue_tests(self, fakefile): + def test_discover_with_modules_that_fail_to_import(self): + loader = unittest.TestLoader() + listdir = os.listdir - os.listdir = lambda _: [fakefile] + os.listdir = lambda _: ['test_this_does_not_exist.py'] isfile = os.path.isfile os.path.isfile = lambda _: True orig_sys_path = sys.path[:] @@ -199,11 +198,6 @@ sys.path[:] = orig_sys_path self.addCleanup(restore) - def test_discover_with_modules_that_fail_to_import(self): - loader = unittest.TestLoader() - - self.setup_import_issue_tests('test_this_does_not_exist.py') - suite = loader.discover('.') self.assertIn(os.getcwd(), sys.path) self.assertEqual(suite.countTestCases(), 1) @@ -212,22 +206,6 @@ with self.assertRaises(ImportError): test.test_this_does_not_exist() - def test_discover_with_module_that_raises_SkipTest_on_import(self): - loader = unittest.TestLoader() - - def _get_module_from_name(name): - raise unittest.SkipTest('skipperoo') - loader._get_module_from_name = _get_module_from_name - - self.setup_import_issue_tests('test_skip_dummy.py') - - suite = loader.discover('.') - self.assertEqual(suite.countTestCases(), 1) - - result = unittest.TestResult() - suite.run(result) - self.assertEqual(len(result.skipped), 1) - def test_command_line_handling_parseArgs(self): program = TestableTestProgram() @@ -275,26 +253,12 @@ program = TestableTestProgram() program.usageExit = usageExit - program.testLoader = None with self.assertRaises(Stop): # too many args program._do_discovery(['one', 'two', 'three', 'four']) - def test_command_line_handling_do_discovery_uses_default_loader(self): - program = object.__new__(unittest.TestProgram) - - class Loader(object): - args = [] - def discover(self, start_dir, pattern, top_level_dir): - self.args.append((start_dir, pattern, top_level_dir)) - return 'tests' - - program.testLoader = Loader() - program._do_discovery(['-v']) - self.assertEqual(Loader.args, [('.', 'test*.py', None)]) - def test_command_line_handling_do_discovery_calls_loader(self): program = TestableTestProgram() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_loader.py --- a/Lib/unittest/test/test_loader.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_loader.py Fri Feb 01 23:12:09 2013 +0100 @@ -806,22 +806,6 @@ ref_suite = unittest.TestSuite([MyTestCase('test')]) self.assertEqual(list(suite), [ref_suite]) - # #14971: Make sure the dotted name resolution works even if the actual - # function doesn't have the same name as is used to find it. - def test_loadTestsFromName__function_with_different_name_than_method(self): - # lambdas have the name ''. - m = types.ModuleType('m') - class MyTestCase(unittest.TestCase): - test = lambda: 1 - m.testcase_1 = MyTestCase - - loader = unittest.TestLoader() - suite = loader.loadTestsFromNames(['testcase_1.test'], m) - self.assertIsInstance(suite, loader.suiteClass) - - ref_suite = unittest.TestSuite([MyTestCase('test')]) - self.assertEqual(list(suite), [ref_suite]) - # "The specifier name is a ``dotted name'' that may resolve ... to ... a # test method within a test case class" # diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_program.py --- a/Lib/unittest/test/test_program.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_program.py Fri Feb 01 23:12:09 2013 +0100 @@ -64,41 +64,6 @@ return self.suiteClass( [self.loadTestsFromTestCase(Test_TestProgram.FooBar)]) - def loadTestsFromNames(self, names, module): - return self.suiteClass( - [self.loadTestsFromTestCase(Test_TestProgram.FooBar)]) - - def test_defaultTest_with_string(self): - class FakeRunner(object): - def run(self, test): - self.test = test - return True - - old_argv = sys.argv - sys.argv = ['faketest'] - runner = FakeRunner() - program = unittest.TestProgram(testRunner=runner, exit=False, - defaultTest='unittest.test', - testLoader=self.FooBarLoader()) - sys.argv = old_argv - self.assertEqual(('unittest.test',), program.testNames) - - def test_defaultTest_with_iterable(self): - class FakeRunner(object): - def run(self, test): - self.test = test - return True - - old_argv = sys.argv - sys.argv = ['faketest'] - runner = FakeRunner() - program = unittest.TestProgram( - testRunner=runner, exit=False, - defaultTest=['unittest.test', 'unittest.test2'], - testLoader=self.FooBarLoader()) - sys.argv = old_argv - self.assertEqual(['unittest.test', 'unittest.test2'], - program.testNames) def test_NonExit(self): program = unittest.main(exit=False, diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_result.py --- a/Lib/unittest/test/test_result.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_result.py Fri Feb 01 23:12:09 2013 +0100 @@ -227,40 +227,6 @@ self.assertTrue(test_case is test) self.assertIsInstance(formatted_exc, str) - def test_addSubTest(self): - class Foo(unittest.TestCase): - def test_1(self): - nonlocal subtest - with self.subTest(foo=1): - subtest = self._subtest - try: - 1/0 - except ZeroDivisionError: - exc_info_tuple = sys.exc_info() - # Register an error by hand (to check the API) - result.addSubTest(test, subtest, exc_info_tuple) - # Now trigger a failure - self.fail("some recognizable failure") - - subtest = None - test = Foo('test_1') - result = unittest.TestResult() - - test.run(result) - - self.assertFalse(result.wasSuccessful()) - self.assertEqual(len(result.errors), 1) - self.assertEqual(len(result.failures), 1) - self.assertEqual(result.testsRun, 1) - self.assertEqual(result.shouldStop, False) - - test_case, formatted_exc = result.errors[0] - self.assertIs(test_case, subtest) - self.assertIn("ZeroDivisionError", formatted_exc) - test_case, formatted_exc = result.failures[0] - self.assertIs(test_case, subtest) - self.assertIn("some recognizable failure", formatted_exc) - def testGetDescriptionWithoutDocstring(self): result = unittest.TextTestResult(None, True, 1) self.assertEqual( @@ -268,37 +234,6 @@ 'testGetDescriptionWithoutDocstring (' + __name__ + '.Test_TestResult)') - def testGetSubTestDescriptionWithoutDocstring(self): - with self.subTest(foo=1, bar=2): - result = unittest.TextTestResult(None, True, 1) - self.assertEqual( - result.getDescription(self._subtest), - 'testGetSubTestDescriptionWithoutDocstring (' + __name__ + - '.Test_TestResult) (bar=2, foo=1)') - with self.subTest('some message'): - result = unittest.TextTestResult(None, True, 1) - self.assertEqual( - result.getDescription(self._subtest), - 'testGetSubTestDescriptionWithoutDocstring (' + __name__ + - '.Test_TestResult) [some message]') - - def testGetSubTestDescriptionWithoutDocstringAndParams(self): - with self.subTest(): - result = unittest.TextTestResult(None, True, 1) - self.assertEqual( - result.getDescription(self._subtest), - 'testGetSubTestDescriptionWithoutDocstringAndParams ' - '(' + __name__ + '.Test_TestResult) ()') - - def testGetNestedSubTestDescriptionWithoutDocstring(self): - with self.subTest(foo=1): - with self.subTest(bar=2): - result = unittest.TextTestResult(None, True, 1) - self.assertEqual( - result.getDescription(self._subtest), - 'testGetNestedSubTestDescriptionWithoutDocstring ' - '(' + __name__ + '.Test_TestResult) (bar=2, foo=1)') - @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -O2 and above") def testGetDescriptionWithOneLineDocstring(self): @@ -312,18 +247,6 @@ @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -O2 and above") - def testGetSubTestDescriptionWithOneLineDocstring(self): - """Tests getDescription() for a method with a docstring.""" - result = unittest.TextTestResult(None, True, 1) - with self.subTest(foo=1, bar=2): - self.assertEqual( - result.getDescription(self._subtest), - ('testGetSubTestDescriptionWithOneLineDocstring ' - '(' + __name__ + '.Test_TestResult) (bar=2, foo=1)\n' - 'Tests getDescription() for a method with a docstring.')) - - @unittest.skipIf(sys.flags.optimize >= 2, - "Docstrings are omitted with -O2 and above") def testGetDescriptionWithMultiLineDocstring(self): """Tests getDescription() for a method with a longer docstring. The second line of the docstring. @@ -336,21 +259,6 @@ 'Tests getDescription() for a method with a longer ' 'docstring.')) - @unittest.skipIf(sys.flags.optimize >= 2, - "Docstrings are omitted with -O2 and above") - def testGetSubTestDescriptionWithMultiLineDocstring(self): - """Tests getDescription() for a method with a longer docstring. - The second line of the docstring. - """ - result = unittest.TextTestResult(None, True, 1) - with self.subTest(foo=1, bar=2): - self.assertEqual( - result.getDescription(self._subtest), - ('testGetSubTestDescriptionWithMultiLineDocstring ' - '(' + __name__ + '.Test_TestResult) (bar=2, foo=1)\n' - 'Tests getDescription() for a method with a longer ' - 'docstring.')) - def testStackFrameTrimming(self): class Frame(object): class tb_frame(object): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_runner.py --- a/Lib/unittest/test/test_runner.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_runner.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,6 @@ import subprocess import unittest -from unittest.case import _Outcome from .support import LoggingResult, ResultWithNoStartTestRunStopTestRun @@ -43,8 +42,12 @@ def testNothing(self): pass + class MockOutcome(object): + success = True + errors = [] + test = TestableTest('testNothing') - outcome = test._outcome = _Outcome() + test._outcomeForDoCleanups = MockOutcome exc1 = Exception('foo') exc2 = Exception('bar') @@ -58,10 +61,9 @@ test.addCleanup(cleanup2) self.assertFalse(test.doCleanups()) - self.assertFalse(outcome.success) + self.assertFalse(MockOutcome.success) - ((_, (Type1, instance1, _)), - (_, (Type2, instance2, _))) = reversed(outcome.errors) + (Type1, instance1, _), (Type2, instance2, _) = reversed(MockOutcome.errors) self.assertEqual((Type1, instance1), (Exception, exc1)) self.assertEqual((Type2, instance2), (Exception, exc2)) @@ -137,18 +139,6 @@ class Test_TextTestRunner(unittest.TestCase): """Tests for TextTestRunner.""" - def setUp(self): - # clean the environment from pre-existing PYTHONWARNINGS to make - # test_warnings results consistent - self.pythonwarnings = os.environ.get('PYTHONWARNINGS') - if self.pythonwarnings: - del os.environ['PYTHONWARNINGS'] - - def tearDown(self): - # bring back pre-existing PYTHONWARNINGS if present - if self.pythonwarnings: - os.environ['PYTHONWARNINGS'] = self.pythonwarnings - def test_init(self): runner = unittest.TextTestRunner() self.assertFalse(runner.failfast) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/test_skipping.py --- a/Lib/unittest/test/test_skipping.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/test_skipping.py Fri Feb 01 23:12:09 2013 +0100 @@ -29,31 +29,6 @@ self.assertEqual(result.skipped, [(test, "testing")]) self.assertEqual(result.testsRun, 1) - def test_skipping_subtests(self): - class Foo(unittest.TestCase): - def test_skip_me(self): - with self.subTest(a=1): - with self.subTest(b=2): - self.skipTest("skip 1") - self.skipTest("skip 2") - self.skipTest("skip 3") - events = [] - result = LoggingResult(events) - test = Foo("test_skip_me") - test.run(result) - self.assertEqual(events, ['startTest', 'addSkip', 'addSkip', - 'addSkip', 'stopTest']) - self.assertEqual(len(result.skipped), 3) - subtest, msg = result.skipped[0] - self.assertEqual(msg, "skip 1") - self.assertIsInstance(subtest, unittest.TestCase) - self.assertIsNot(subtest, test) - subtest, msg = result.skipped[1] - self.assertEqual(msg, "skip 2") - self.assertIsInstance(subtest, unittest.TestCase) - self.assertIsNot(subtest, test) - self.assertEqual(result.skipped[2], (test, "skip 3")) - def test_skipping_decorators(self): op_table = ((unittest.skipUnless, False, True), (unittest.skipIf, True, False)) @@ -120,31 +95,6 @@ self.assertEqual(result.expectedFailures[0][0], test) self.assertTrue(result.wasSuccessful()) - def test_expected_failure_subtests(self): - # A failure in any subtest counts as the expected failure of the - # whole test. - class Foo(unittest.TestCase): - @unittest.expectedFailure - def test_die(self): - with self.subTest(): - # This one succeeds - pass - with self.subTest(): - self.fail("help me!") - with self.subTest(): - # This one doesn't get executed - self.fail("shouldn't come here") - events = [] - result = LoggingResult(events) - test = Foo("test_die") - test.run(result) - self.assertEqual(events, - ['startTest', 'addSubTestSuccess', - 'addExpectedFailure', 'stopTest']) - self.assertEqual(len(result.expectedFailures), 1) - self.assertIs(result.expectedFailures[0][0], test) - self.assertTrue(result.wasSuccessful()) - def test_unexpected_success(self): class Foo(unittest.TestCase): @unittest.expectedFailure @@ -160,30 +110,6 @@ self.assertEqual(result.unexpectedSuccesses, [test]) self.assertTrue(result.wasSuccessful()) - def test_unexpected_success_subtests(self): - # Success in all subtests counts as the unexpected success of - # the whole test. - class Foo(unittest.TestCase): - @unittest.expectedFailure - def test_die(self): - with self.subTest(): - # This one succeeds - pass - with self.subTest(): - # So does this one - pass - events = [] - result = LoggingResult(events) - test = Foo("test_die") - test.run(result) - self.assertEqual(events, - ['startTest', - 'addSubTestSuccess', 'addSubTestSuccess', - 'addUnexpectedSuccess', 'stopTest']) - self.assertFalse(result.failures) - self.assertEqual(result.unexpectedSuccesses, [test]) - self.assertTrue(result.wasSuccessful()) - def test_skip_doesnt_run_setup(self): class Foo(unittest.TestCase): wasSetUp = False diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/testmock/testhelpers.py --- a/Lib/unittest/test/testmock/testhelpers.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/testmock/testhelpers.py Fri Feb 01 23:12:09 2013 +0100 @@ -337,10 +337,9 @@ def test_basic(self): - mock = create_autospec(SomeClass) - self._check_someclass_mock(mock) - mock = create_autospec(SomeClass()) - self._check_someclass_mock(mock) + for spec in (SomeClass, SomeClass()): + mock = create_autospec(spec) + self._check_someclass_mock(mock) def test_create_autospec_return_value(self): @@ -577,10 +576,10 @@ def test_spec_inheritance_for_classes(self): class Foo(object): - def a(self, x): + def a(self): pass class Bar(object): - def f(self, y): + def f(self): pass class_mock = create_autospec(Foo) @@ -588,30 +587,26 @@ self.assertIsNot(class_mock, class_mock()) for this_mock in class_mock, class_mock(): - this_mock.a(x=5) - this_mock.a.assert_called_with(x=5) - this_mock.a.assert_called_with(5) - self.assertRaises(TypeError, this_mock.a, 'foo', 'bar') + this_mock.a() + this_mock.a.assert_called_with() + self.assertRaises(TypeError, this_mock.a, 'foo') self.assertRaises(AttributeError, getattr, this_mock, 'b') instance_mock = create_autospec(Foo()) - instance_mock.a(5) - instance_mock.a.assert_called_with(5) - instance_mock.a.assert_called_with(x=5) - self.assertRaises(TypeError, instance_mock.a, 'foo', 'bar') + instance_mock.a() + instance_mock.a.assert_called_with() + self.assertRaises(TypeError, instance_mock.a, 'foo') self.assertRaises(AttributeError, getattr, instance_mock, 'b') # The return value isn't isn't callable self.assertRaises(TypeError, instance_mock) - instance_mock.Bar.f(6) - instance_mock.Bar.f.assert_called_with(6) - instance_mock.Bar.f.assert_called_with(y=6) + instance_mock.Bar.f() + instance_mock.Bar.f.assert_called_with() self.assertRaises(AttributeError, getattr, instance_mock.Bar, 'g') - instance_mock.Bar().f(6) - instance_mock.Bar().f.assert_called_with(6) - instance_mock.Bar().f.assert_called_with(y=6) + instance_mock.Bar().f() + instance_mock.Bar().f.assert_called_with() self.assertRaises(AttributeError, getattr, instance_mock.Bar(), 'g') @@ -668,15 +663,12 @@ self.assertRaises(TypeError, mock) mock(1, 2) mock.assert_called_with(1, 2) - mock.assert_called_with(1, b=2) - mock.assert_called_with(a=1, b=2) f.f = f mock = create_autospec(f) self.assertRaises(TypeError, mock.f) mock.f(3, 4) mock.f.assert_called_with(3, 4) - mock.f.assert_called_with(a=3, b=4) def test_skip_attributeerrors(self): @@ -712,13 +704,9 @@ self.assertRaises(TypeError, mock) mock(1) mock.assert_called_once_with(1) - mock.assert_called_once_with(a=1) - self.assertRaises(AssertionError, mock.assert_called_once_with, 2) mock(4, 5) mock.assert_called_with(4, 5) - mock.assert_called_with(a=4, b=5) - self.assertRaises(AssertionError, mock.assert_called_with, a=5, b=4) def test_class_with_no_init(self): @@ -731,27 +719,24 @@ def test_signature_callable(self): class Callable(object): - def __init__(self, x, y): + def __init__(self): pass def __call__(self, a): pass mock = create_autospec(Callable) - mock(1, 2) - mock.assert_called_once_with(1, 2) - mock.assert_called_once_with(x=1, y=2) + mock() + mock.assert_called_once_with() self.assertRaises(TypeError, mock, 'a') - instance = mock(1, 2) + instance = mock() self.assertRaises(TypeError, instance) instance(a='a') - instance.assert_called_once_with('a') instance.assert_called_once_with(a='a') instance('a') instance.assert_called_with('a') - instance.assert_called_with(a='a') - mock = create_autospec(Callable(1, 2)) + mock = create_autospec(Callable()) mock(a='a') mock.assert_called_once_with(a='a') self.assertRaises(TypeError, mock) @@ -794,11 +779,7 @@ pass a = create_autospec(Foo) - a.f(10) - a.f.assert_called_with(10) - a.f.assert_called_with(self=10) a.f(self=10) - a.f.assert_called_with(10) a.f.assert_called_with(self=10) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/testmock/testmock.py Fri Feb 01 23:12:09 2013 +0100 @@ -25,18 +25,6 @@ __next__ = next -class Something(object): - def meth(self, a, b, c, d=None): - pass - - @classmethod - def cmeth(cls, a, b, c, d=None): - pass - - @staticmethod - def smeth(a, b, c, d=None): - pass - class MockTest(unittest.TestCase): @@ -285,43 +273,6 @@ mock.assert_called_with(1, 2, 3, a='fish', b='nothing') - def test_assert_called_with_function_spec(self): - def f(a, b, c, d=None): - pass - - mock = Mock(spec=f) - - mock(1, b=2, c=3) - mock.assert_called_with(1, 2, 3) - mock.assert_called_with(a=1, b=2, c=3) - self.assertRaises(AssertionError, mock.assert_called_with, - 1, b=3, c=2) - # Expected call doesn't match the spec's signature - with self.assertRaises(AssertionError) as cm: - mock.assert_called_with(e=8) - self.assertIsInstance(cm.exception.__cause__, TypeError) - - - def test_assert_called_with_method_spec(self): - def _check(mock): - mock(1, b=2, c=3) - mock.assert_called_with(1, 2, 3) - mock.assert_called_with(a=1, b=2, c=3) - self.assertRaises(AssertionError, mock.assert_called_with, - 1, b=3, c=2) - - mock = Mock(spec=Something().meth) - _check(mock) - mock = Mock(spec=Something.cmeth) - _check(mock) - mock = Mock(spec=Something().cmeth) - _check(mock) - mock = Mock(spec=Something.smeth) - _check(mock) - mock = Mock(spec=Something().smeth) - _check(mock) - - def test_assert_called_once_with(self): mock = Mock() mock() @@ -346,29 +297,6 @@ ) - def test_assert_called_once_with_function_spec(self): - def f(a, b, c, d=None): - pass - - mock = Mock(spec=f) - - mock(1, b=2, c=3) - mock.assert_called_once_with(1, 2, 3) - mock.assert_called_once_with(a=1, b=2, c=3) - self.assertRaises(AssertionError, mock.assert_called_once_with, - 1, b=3, c=2) - # Expected call doesn't match the spec's signature - with self.assertRaises(AssertionError) as cm: - mock.assert_called_once_with(e=8) - self.assertIsInstance(cm.exception.__cause__, TypeError) - # Mock called more than once => always fails - mock(4, 5, 6) - self.assertRaises(AssertionError, mock.assert_called_once_with, - 1, 2, 3) - self.assertRaises(AssertionError, mock.assert_called_once_with, - 4, 5, 6) - - def test_attribute_access_returns_mocks(self): mock = Mock() something = mock.something @@ -978,10 +906,6 @@ self.assertRaises(StopIteration, mock) self.assertIs(mock.side_effect, this_iter) - def test_side_effect_iterator_default(self): - mock = Mock(return_value=2) - mock.side_effect = iter([1, DEFAULT]) - self.assertEqual([mock(), mock()], [1, 2]) def test_assert_has_calls_any_order(self): mock = Mock() @@ -1067,39 +991,6 @@ ) - def test_assert_has_calls_with_function_spec(self): - def f(a, b, c, d=None): - pass - - mock = Mock(spec=f) - - mock(1, b=2, c=3) - mock(4, 5, c=6, d=7) - mock(10, 11, c=12) - calls = [ - ('', (1, 2, 3), {}), - ('', (4, 5, 6), {'d': 7}), - ((10, 11, 12), {}), - ] - mock.assert_has_calls(calls) - mock.assert_has_calls(calls, any_order=True) - mock.assert_has_calls(calls[1:]) - mock.assert_has_calls(calls[1:], any_order=True) - mock.assert_has_calls(calls[:-1]) - mock.assert_has_calls(calls[:-1], any_order=True) - # Reversed order - calls = list(reversed(calls)) - with self.assertRaises(AssertionError): - mock.assert_has_calls(calls) - mock.assert_has_calls(calls, any_order=True) - with self.assertRaises(AssertionError): - mock.assert_has_calls(calls[1:]) - mock.assert_has_calls(calls[1:], any_order=True) - with self.assertRaises(AssertionError): - mock.assert_has_calls(calls[:-1]) - mock.assert_has_calls(calls[:-1], any_order=True) - - def test_assert_any_call(self): mock = Mock() mock(1, 2) @@ -1126,26 +1017,6 @@ ) - def test_assert_any_call_with_function_spec(self): - def f(a, b, c, d=None): - pass - - mock = Mock(spec=f) - - mock(1, b=2, c=3) - mock(4, 5, c=6, d=7) - mock.assert_any_call(1, 2, 3) - mock.assert_any_call(a=1, b=2, c=3) - mock.assert_any_call(4, 5, 6, 7) - mock.assert_any_call(a=4, b=5, c=6, d=7) - self.assertRaises(AssertionError, mock.assert_any_call, - 1, b=3, c=2) - # Expected call doesn't match the spec's signature - with self.assertRaises(AssertionError) as cm: - mock.assert_any_call(e=8) - self.assertIsInstance(cm.exception.__cause__, TypeError) - - def test_mock_calls_create_autospec(self): def f(a, b): pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/unittest/test/testmock/testwith.py --- a/Lib/unittest/test/testmock/testwith.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/unittest/test/testmock/testwith.py Fri Feb 01 23:12:09 2013 +0100 @@ -172,88 +172,5 @@ self.assertEqual(result, 'foo') - def test_readline_data(self): - # Check that readline will return all the lines from the fake file - mock = mock_open(read_data='foo\nbar\nbaz\n') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - line1 = h.readline() - line2 = h.readline() - line3 = h.readline() - self.assertEqual(line1, 'foo\n') - self.assertEqual(line2, 'bar\n') - self.assertEqual(line3, 'baz\n') - - # Check that we properly emulate a file that doesn't end in a newline - mock = mock_open(read_data='foo') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - result = h.readline() - self.assertEqual(result, 'foo') - - - def test_readlines_data(self): - # Test that emulating a file that ends in a newline character works - mock = mock_open(read_data='foo\nbar\nbaz\n') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - result = h.readlines() - self.assertEqual(result, ['foo\n', 'bar\n', 'baz\n']) - - # Test that files without a final newline will also be correctly - # emulated - mock = mock_open(read_data='foo\nbar\nbaz') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - result = h.readlines() - - self.assertEqual(result, ['foo\n', 'bar\n', 'baz']) - - - def test_mock_open_read_with_argument(self): - # At one point calling read with an argument was broken - # for mocks returned by mock_open - some_data = 'foo\nbar\nbaz' - mock = mock_open(read_data=some_data) - self.assertEqual(mock().read(10), some_data) - - - def test_interleaved_reads(self): - # Test that calling read, readline, and readlines pulls data - # sequentially from the data we preload with - mock = mock_open(read_data='foo\nbar\nbaz\n') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - line1 = h.readline() - rest = h.readlines() - self.assertEqual(line1, 'foo\n') - self.assertEqual(rest, ['bar\n', 'baz\n']) - - mock = mock_open(read_data='foo\nbar\nbaz\n') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - line1 = h.readline() - rest = h.read() - self.assertEqual(line1, 'foo\n') - self.assertEqual(rest, 'bar\nbaz\n') - - - def test_overriding_return_values(self): - mock = mock_open(read_data='foo') - handle = mock() - - handle.read.return_value = 'bar' - handle.readline.return_value = 'bar' - handle.readlines.return_value = ['bar'] - - self.assertEqual(handle.read(), 'bar') - self.assertEqual(handle.readline(), 'bar') - self.assertEqual(handle.readlines(), ['bar']) - - # call repeatedly to check that a StopIteration is not propagated - self.assertEqual(handle.readline(), 'bar') - self.assertEqual(handle.readline(), 'bar') - - if __name__ == '__main__': unittest.main() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/urllib/parse.py Fri Feb 01 23:12:09 2013 +0100 @@ -27,7 +27,6 @@ test_urlparse.py provides a good indicator of parsing behavior. """ -import re import sys import collections @@ -471,10 +470,6 @@ defrag = url return _coerce_result(DefragResult(defrag, frag)) -_hexdig = '0123456789ABCDEFabcdef' -_hextobyte = {(a + b).encode(): bytes([int(a + b, 16)]) - for a in _hexdig for b in _hexdig} - def unquote_to_bytes(string): """unquote_to_bytes('abc%20def') -> b'abc def'.""" # Note: strings are encoded as UTF-8. This is only an issue if it contains @@ -485,21 +480,16 @@ return b'' if isinstance(string, str): string = string.encode('utf-8') - bits = string.split(b'%') - if len(bits) == 1: + res = string.split(b'%') + if len(res) == 1: return string - res = [bits[0]] - append = res.append - for item in bits[1:]: + string = res[0] + for item in res[1:]: try: - append(_hextobyte[item[:2]]) - append(item[2:]) - except KeyError: - append(b'%') - append(item) - return b''.join(res) - -_asciire = re.compile('([\x00-\x7f]+)') + string += bytes([int(item[:2], 16)]) + item[2:] + except ValueError: + string += b'%' + item + return string def unquote(string, encoding='utf-8', errors='replace'): """Replace %xx escapes by their single-character equivalent. The optional @@ -511,20 +501,39 @@ unquote('abc%20def') -> 'abc def'. """ - if '%' not in string: - string.split + if string == '': + return string + res = string.split('%') + if len(res) == 1: return string if encoding is None: encoding = 'utf-8' if errors is None: errors = 'replace' - bits = _asciire.split(string) - res = [bits[0]] - append = res.append - for i in range(1, len(bits), 2): - append(unquote_to_bytes(bits[i]).decode(encoding, errors)) - append(bits[i + 1]) - return ''.join(res) + # pct_sequence: contiguous sequence of percent-encoded bytes, decoded + pct_sequence = b'' + string = res[0] + for item in res[1:]: + try: + if not item: + raise ValueError + pct_sequence += bytes.fromhex(item[:2]) + rest = item[2:] + if not rest: + # This segment was just a single percent-encoded character. + # May be part of a sequence of code units, so delay decoding. + # (Stored in pct_sequence). + continue + except ValueError: + rest = '%' + item + # Encountered non-percent-encoded characters. Flush the current + # pct_sequence. + string += pct_sequence.decode(encoding, errors) + rest + pct_sequence = b'' + if pct_sequence: + # Flush the final pct_sequence + string += pct_sequence.decode(encoding, errors) + return string def parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace'): @@ -846,6 +855,7 @@ """splittype('type:opaquestring') --> 'type', 'opaquestring'.""" global _typeprog if _typeprog is None: + import re _typeprog = re.compile('^([^/:]+):') match = _typeprog.match(url) @@ -859,6 +869,7 @@ """splithost('//host[:port]/path') --> 'host[:port]', '/path'.""" global _hostprog if _hostprog is None: + import re _hostprog = re.compile('^//([^/?]*)(.*)$') match = _hostprog.match(url) @@ -875,6 +886,7 @@ """splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.""" global _userprog if _userprog is None: + import re _userprog = re.compile('^(.*)@(.*)$') match = _userprog.match(host) @@ -886,6 +898,7 @@ """splitpasswd('user:passwd') -> 'user', 'passwd'.""" global _passwdprog if _passwdprog is None: + import re _passwdprog = re.compile('^([^:]*):(.*)$',re.S) match = _passwdprog.match(user) @@ -898,6 +911,7 @@ """splitport('host:port') --> 'host', 'port'.""" global _portprog if _portprog is None: + import re _portprog = re.compile('^(.*):([0-9]+)$') match = _portprog.match(host) @@ -912,6 +926,7 @@ Return None if ':' but not a valid number.""" global _nportprog if _nportprog is None: + import re _nportprog = re.compile('^(.*):(.*)$') match = _nportprog.match(host) @@ -930,6 +945,7 @@ """splitquery('/path?query') --> '/path', 'query'.""" global _queryprog if _queryprog is None: + import re _queryprog = re.compile('^(.*)\?([^?]*)$') match = _queryprog.match(url) @@ -941,6 +957,7 @@ """splittag('/path#tag') --> '/path', 'tag'.""" global _tagprog if _tagprog is None: + import re _tagprog = re.compile('^(.*)#([^#]*)$') match = _tagprog.match(url) @@ -958,6 +975,7 @@ """splitvalue('attr=value') --> 'attr', 'value'.""" global _valueprog if _valueprog is None: + import re _valueprog = re.compile('^([^=]*)=(.*)$') match = _valueprog.match(attr) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/urllib/request.py --- a/Lib/urllib/request.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/urllib/request.py Fri Feb 01 23:12:09 2013 +0100 @@ -143,12 +143,16 @@ raise ValueError('SSL support not available') context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.options |= ssl.OP_NO_SSLv2 - context.verify_mode = ssl.CERT_REQUIRED - if cafile or capath: - context.load_verify_locations(cafile, capath) + if cafile or capath or cadefault: + context.verify_mode = ssl.CERT_REQUIRED + if cafile or capath: + context.load_verify_locations(cafile, capath) + else: + context.set_default_verify_paths() + check_hostname = True else: - context.set_default_verify_paths() - https_handler = HTTPSHandler(context=context, check_hostname=True) + check_hostname = False + https_handler = HTTPSHandler(context=context, check_hostname=check_hostname) opener = build_opener(https_handler) elif _opener is None: _opener = opener = build_opener() @@ -259,7 +263,9 @@ def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None): - self.full_url = url + # unwrap('') --> 'type://host/path' + self.full_url = unwrap(url) + self.full_url, self.fragment = splittag(self.full_url) self.headers = {} self.unredirected_hdrs = {} self._data = None @@ -272,26 +278,8 @@ self.origin_req_host = origin_req_host self.unverifiable = unverifiable self.method = method - - @property - def full_url(self): - if self.fragment: - return '{}#{}'.format(self._full_url, self.fragment) - return self._full_url - - @full_url.setter - def full_url(self, url): - # unwrap('') --> 'type://host/path' - self._full_url = unwrap(url) - self._full_url, self.fragment = splittag(self._full_url) self._parse() - @full_url.deleter - def full_url(self): - self._full_url = None - self.fragment = None - self.selector = '' - @property def data(self): return self._data @@ -308,12 +296,12 @@ @data.deleter def data(self): - self.data = None + self._data = None def _parse(self): - self.type, rest = splittype(self._full_url) + self.type, rest = splittype(self.full_url) if self.type is None: - raise ValueError("unknown url type: %r" % self.full_url) + raise ValueError("unknown url type: %s" % self.full_url) self.host, self.selector = splithost(rest) if self.host: self.host = unquote(self.host) @@ -328,7 +316,54 @@ return "GET" def get_full_url(self): - return self.full_url + if self.fragment: + return '%s#%s' % (self.full_url, self.fragment) + else: + return self.full_url + + # Begin deprecated methods + + def add_data(self, data): + msg = "Request.add_data method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + self.data = data + + def has_data(self): + msg = "Request.has_data method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.data is not None + + def get_data(self): + msg = "Request.get_data method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.data + + def get_type(self): + msg = "Request.get_type method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.type + + def get_host(self): + msg = "Request.get_host method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.host + + def get_selector(self): + msg = "Request.get_selector method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.selector + + def is_unverifiable(self): + msg = "Request.is_unverifiable method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.unverifiable + + def get_origin_req_host(self): + msg = "Request.get_origin_req_host method is deprecated." + warnings.warn(msg, DeprecationWarning, stacklevel=1) + return self.origin_req_host + + # End deprecated methods def set_proxy(self, host, type): if self.type == 'https' and not self._tunnel_host: @@ -2259,10 +2294,7 @@ """Return the IP addresses of the current host.""" global _thishost if _thishost is None: - try: - _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2]) - except socket.gaierror: - _thishost = tuple(socket.gethostbyname_ex('localhost')[2]) + _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2]) return _thishost _ftperrors = None @@ -2306,8 +2338,8 @@ self.ftp = ftplib.FTP() self.ftp.connect(self.host, self.port, self.timeout) self.ftp.login(self.user, self.passwd) - _target = '/'.join(self.dirs) - self.ftp.cwd(_target) + for dir in self.dirs: + self.ftp.cwd(dir) def retrfile(self, file, type): import ftplib @@ -2327,7 +2359,7 @@ conn, retrlen = self.ftp.ntransfercmd(cmd) except ftplib.error_perm as reason: if str(reason)[:3] != '550': - raise URLError('ftp error: %r' % reason).with_traceback( + raise URLError('ftp error: %d' % reason).with_traceback( sys.exc_info()[2]) if not conn: # Set transfer mode to ASCII! @@ -2339,7 +2371,7 @@ try: self.ftp.cwd(file) except ftplib.error_perm as reason: - raise URLError('ftp error: %r' % reason) from reason + raise URLError('ftp error: %d' % reason) from reason finally: self.ftp.cwd(pwd) cmd = 'LIST ' + file diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/urllib/robotparser.py --- a/Lib/urllib/robotparser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/urllib/robotparser.py Fri Feb 01 23:12:09 2013 +0100 @@ -157,7 +157,6 @@ if path == '' and not allowance: # an empty value means allow all allowance = True - path = urllib.parse.urlunparse(urllib.parse.urlparse(path)) self.path = urllib.parse.quote(path) self.allowance = allowance diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/uuid.py --- a/Lib/uuid.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/uuid.py Fri Feb 01 23:12:09 2013 +0100 @@ -406,7 +406,7 @@ if win32wnet.Netbios(ncb) != 0: continue status._unpack() - bytes = status.adapter_address + bytes = map(ord, status.adapter_address) return ((bytes[0]<<40) + (bytes[1]<<32) + (bytes[2]<<24) + (bytes[3]<<16) + (bytes[4]<<8) + bytes[5]) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/__init__.py --- a/Lib/venv/__init__.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/venv/__init__.py Fri Feb 01 23:12:09 2013 +0100 @@ -37,10 +37,15 @@ import threading except ImportError: threading = None -import types logger = logging.getLogger(__name__) +class Context: + """ + Holds information about a current venv creation/upgrade request. + """ + pass + class EnvBuilder: """ @@ -111,7 +116,7 @@ if os.path.exists(env_dir) and self.clear: self.clear_directory(env_dir) - context = types.SimpleNamespace() + context = Context() context.env_dir = env_dir context.env_name = os.path.split(env_dir)[1] context.prompt = '(%s) ' % context.env_name diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/scripts/nt/Activate.ps1 --- a/Lib/venv/scripts/nt/Activate.ps1 Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/venv/scripts/nt/Activate.ps1 Fri Feb 01 23:12:09 2013 +0100 @@ -1,40 +1,25 @@ -function global:deactivate ([switch]$NonDestructive) { - # Revert to original values - if (Test-Path function:_OLD_VIRTUAL_PROMPT) { - copy-item function:_OLD_VIRTUAL_PROMPT function:prompt - remove-item function:_OLD_VIRTUAL_PROMPT - } +$env:VIRTUAL_ENV="__VENV_DIR__" - if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) { - copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME - remove-item env:_OLD_VIRTUAL_PYTHONHOME - } - - if (Test-Path env:_OLD_VIRTUAL_PATH) { - copy-item env:_OLD_VIRTUAL_PATH env:PATH - remove-item env:_OLD_VIRTUAL_PATH - } - - if (Test-Path env:VIRTUAL_ENV) { - remove-item env:VIRTUAL_ENV - } - - if (!$NonDestructive) { - # Self destruct! - remove-item function:deactivate - } +# Revert to original values +if (Test-Path function:_OLD_VIRTUAL_PROMPT) { + copy-item function:_OLD_VIRTUAL_PROMPT function:prompt + remove-item function:_OLD_VIRTUAL_PROMPT } -deactivate -nondestructive - -$env:VIRTUAL_ENV="__VENV_DIR__" +if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) { + copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME + remove-item env:_OLD_VIRTUAL_PYTHONHOME +} + +if (Test-Path env:_OLD_VIRTUAL_PATH) { + copy-item env:_OLD_VIRTUAL_PATH env:PATH + remove-item env:_OLD_VIRTUAL_PATH +} # Set the prompt to include the env name -# Make sure _OLD_VIRTUAL_PROMPT is global -function global:_OLD_VIRTUAL_PROMPT {""} copy-item function:prompt function:_OLD_VIRTUAL_PROMPT -function global:prompt { - Write-Host -NoNewline -ForegroundColor Green '__VENV_NAME__' +function prompt { + Write-Host -NoNewline -ForegroundColor Green '[__VENV_NAME__]' _OLD_VIRTUAL_PROMPT } diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/scripts/nt/Deactivate.ps1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/venv/scripts/nt/Deactivate.ps1 Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,19 @@ +# Revert to original values +if (Test-Path function:_OLD_VIRTUAL_PROMPT) { + copy-item function:_OLD_VIRTUAL_PROMPT function:prompt + remove-item function:_OLD_VIRTUAL_PROMPT +} + +if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) { + copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME + remove-item env:_OLD_VIRTUAL_PYTHONHOME +} + +if (Test-Path env:_OLD_VIRTUAL_PATH) { + copy-item env:_OLD_VIRTUAL_PATH env:PATH + remove-item env:_OLD_VIRTUAL_PATH +} + +if (Test-Path env:VIRTUAL_ENV) { + remove-item env:VIRTUAL_ENV +} diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/scripts/nt/activate.bat --- a/Lib/venv/scripts/nt/activate.bat Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/venv/scripts/nt/activate.bat Fri Feb 01 23:12:09 2013 +0100 @@ -1,32 +1,31 @@ @echo off -set "VIRTUAL_ENV=__VENV_DIR__" +set VIRTUAL_ENV=__VENV_DIR__ if not defined PROMPT ( - set "PROMPT=$P$G" + set PROMPT=$P$G ) if defined _OLD_VIRTUAL_PROMPT ( - set "PROMPT=%_OLD_VIRTUAL_PROMPT%" + set PROMPT=%_OLD_VIRTUAL_PROMPT% ) if defined _OLD_VIRTUAL_PYTHONHOME ( - set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%" + set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME% ) -set "_OLD_VIRTUAL_PROMPT=%PROMPT%" -set "PROMPT=__VENV_NAME__%PROMPT%" +set _OLD_VIRTUAL_PROMPT=%PROMPT% +set PROMPT=__VENV_NAME__%PROMPT% if defined PYTHONHOME ( - set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%" - set PYTHONHOME= + set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME% + set PYTHONHOME= ) -if defined _OLD_VIRTUAL_PATH ( - set "PATH=%_OLD_VIRTUAL_PATH%" -) else ( - set "_OLD_VIRTUAL_PATH=%PATH%" -) +if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%; goto SKIPPATH -set "PATH=%VIRTUAL_ENV%\__VENV_BIN_NAME__;%PATH%" +set _OLD_VIRTUAL_PATH=%PATH% + +:SKIPPATH +set PATH=%VIRTUAL_ENV%\__VENV_BIN_NAME__;%PATH% :END diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/scripts/nt/deactivate.bat --- a/Lib/venv/scripts/nt/deactivate.bat Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/venv/scripts/nt/deactivate.bat Fri Feb 01 23:12:09 2013 +0100 @@ -1,21 +1,17 @@ @echo off if defined _OLD_VIRTUAL_PROMPT ( - set "PROMPT=%_OLD_VIRTUAL_PROMPT%" + set PROMPT=%_OLD_VIRTUAL_PROMPT% ) set _OLD_VIRTUAL_PROMPT= if defined _OLD_VIRTUAL_PYTHONHOME ( - set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%" - set _OLD_VIRTUAL_PYTHONHOME= + set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME% + set _OLD_VIRTUAL_PYTHONHOME= ) -if defined _OLD_VIRTUAL_PATH ( - set "PATH=%_OLD_VIRTUAL_PATH%" -) +if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH% set _OLD_VIRTUAL_PATH= -set VIRTUAL_ENV= - :END diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/scripts/nt/pydoc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/venv/scripts/nt/pydoc.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,4 @@ +#!__VENV_PYTHON__ +if __name__ == '__main__': + import sys, pydoc + sys.exit(pydoc.cli()) diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/venv/scripts/posix/pydoc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/venv/scripts/posix/pydoc Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,5 @@ +#!__VENV_PYTHON__ +if __name__ == '__main__': + import sys, pydoc + sys.exit(pydoc.cli()) + diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/wave.py --- a/Lib/wave.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/wave.py Fri Feb 01 23:12:09 2013 +0100 @@ -18,7 +18,7 @@ getcomptype() -- returns compression type ('NONE' for linear samples) getcompname() -- returns human-readable version of compression type ('not compressed' linear samples) - getparams() -- returns a namedtuple consisting of all of the + getparams() -- returns a tuple consisting of all of the above in the above order getmarkers() -- returns None (for compatibility with the aifc module) @@ -82,13 +82,14 @@ _array_fmts = None, 'b', 'h', None, 'l' +# Determine endian-ness import struct -import sys +if struct.pack("h", 1) == b"\000\001": + big_endian = 1 +else: + big_endian = 0 + from chunk import Chunk -from collections import namedtuple - -_result = namedtuple('params', - 'nchannels sampwidth framerate nframes comptype compname') class Wave_read: """Variables used in this class: @@ -205,9 +206,9 @@ return self._compname def getparams(self): - return _result(self.getnchannels(), self.getsampwidth(), - self.getframerate(), self.getnframes(), - self.getcomptype(), self.getcompname()) + return self.getnchannels(), self.getsampwidth(), \ + self.getframerate(), self.getnframes(), \ + self.getcomptype(), self.getcompname() def getmarkers(self): return None @@ -230,7 +231,7 @@ self._data_seek_needed = 0 if nframes == 0: return b'' - if self._sampwidth > 1 and sys.byteorder == 'big': + if self._sampwidth > 1 and big_endian: # unfortunately the fromfile() method does not take # something that only looks like a file object, so # we have to reach into the innards of the chunk object @@ -397,8 +398,8 @@ def getparams(self): if not self._nchannels or not self._sampwidth or not self._framerate: raise Error('not all parameters set') - return _result(self._nchannels, self._sampwidth, self._framerate, - self._nframes, self._comptype, self._compname) + return self._nchannels, self._sampwidth, self._framerate, \ + self._nframes, self._comptype, self._compname def setmark(self, id, pos, name): raise Error('setmark() not supported') @@ -417,7 +418,7 @@ nframes = len(data) // (self._sampwidth * self._nchannels) if self._convert: data = self._convert(data) - if self._sampwidth > 1 and sys.byteorder == 'big': + if self._sampwidth > 1 and big_endian: import array data = array.array(_array_fmts[self._sampwidth], data) data.byteswap() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/weakref.py --- a/Lib/weakref.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/weakref.py Fri Feb 01 23:12:09 2013 +0100 @@ -21,15 +21,13 @@ from _weakrefset import WeakSet, _IterationGuard import collections # Import after _weakref to avoid circular import. -import sys -import itertools ProxyTypes = (ProxyType, CallableProxyType) __all__ = ["ref", "proxy", "getweakrefcount", "getweakrefs", "WeakKeyDictionary", "ReferenceType", "ProxyType", "CallableProxyType", "ProxyTypes", "WeakValueDictionary", - "WeakSet", "WeakMethod", "finalize"] + "WeakSet", "WeakMethod"] class WeakMethod(ref): @@ -438,140 +436,3 @@ d[ref(key, self._remove)] = value if len(kwargs): self.update(kwargs) - - -class finalize: - """Class for finalization of weakrefable objects - - finalize(obj, func, *args, **kwargs) returns a callable finalizer - object which will be called when obj is garbage collected. The - first time the finalizer is called it evaluates func(*arg, **kwargs) - and returns the result. After this the finalizer is dead, and - calling it just returns None. - - When the program exits any remaining finalizers for which the - atexit attribute is true will be run in reverse order of creation. - By default atexit is true. - """ - - # Finalizer objects don't have any state of their own. They are - # just used as keys to lookup _Info objects in the registry. This - # ensures that they cannot be part of a ref-cycle. - - __slots__ = () - _registry = {} - _shutdown = False - _index_iter = itertools.count() - _dirty = False - _registered_with_atexit = False - - class _Info: - __slots__ = ("weakref", "func", "args", "kwargs", "atexit", "index") - - def __init__(self, obj, func, *args, **kwargs): - if not self._registered_with_atexit: - # We may register the exit function more than once because - # of a thread race, but that is harmless - import atexit - atexit.register(self._exitfunc) - finalize._registered_with_atexit = True - info = self._Info() - info.weakref = ref(obj, self) - info.func = func - info.args = args - info.kwargs = kwargs or None - info.atexit = True - info.index = next(self._index_iter) - self._registry[self] = info - finalize._dirty = True - - def __call__(self, _=None): - """If alive then mark as dead and return func(*args, **kwargs); - otherwise return None""" - info = self._registry.pop(self, None) - if info and not self._shutdown: - return info.func(*info.args, **(info.kwargs or {})) - - def detach(self): - """If alive then mark as dead and return (obj, func, args, kwargs); - otherwise return None""" - info = self._registry.get(self) - obj = info and info.weakref() - if obj is not None and self._registry.pop(self, None): - return (obj, info.func, info.args, info.kwargs or {}) - - def peek(self): - """If alive then return (obj, func, args, kwargs); - otherwise return None""" - info = self._registry.get(self) - obj = info and info.weakref() - if obj is not None: - return (obj, info.func, info.args, info.kwargs or {}) - - @property - def alive(self): - """Whether finalizer is alive""" - return self in self._registry - - @property - def atexit(self): - """Whether finalizer should be called at exit""" - info = self._registry.get(self) - return bool(info) and info.atexit - - @atexit.setter - def atexit(self, value): - info = self._registry.get(self) - if info: - info.atexit = bool(value) - - def __repr__(self): - info = self._registry.get(self) - obj = info and info.weakref() - if obj is None: - return '<%s object at %#x; dead>' % (type(self).__name__, id(self)) - else: - return '<%s object at %#x; for %r at %#x>' % \ - (type(self).__name__, id(self), type(obj).__name__, id(obj)) - - @classmethod - def _select_for_exit(cls): - # Return live finalizers marked for exit, oldest first - L = [(f,i) for (f,i) in cls._registry.items() if i.atexit] - L.sort(key=lambda item:item[1].index) - return [f for (f,i) in L] - - @classmethod - def _exitfunc(cls): - # At shutdown invoke finalizers for which atexit is true. - # This is called once all other non-daemonic threads have been - # joined. - reenable_gc = False - try: - if cls._registry: - import gc - if gc.isenabled(): - reenable_gc = True - gc.disable() - pending = None - while True: - if pending is None or finalize._dirty: - pending = cls._select_for_exit() - finalize._dirty = False - if not pending: - break - f = pending.pop() - try: - # gc is disabled, so (assuming no daemonic - # threads) the following is the only line in - # this function which might trigger creation - # of a new finalizer - f() - except Exception: - sys.excepthook(*sys.exc_info()) - assert f not in cls._registry - finally: - # prevent any more finalizers from executing during shutdown - finalize._shutdown = True - if reenable_gc: - gc.enable() diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/webbrowser.py --- a/Lib/webbrowser.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/webbrowser.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,6 @@ import io import os import shlex -import shutil import sys import stat import subprocess @@ -84,7 +83,7 @@ """ cmd = browser.split()[0] - if not shutil.which(cmd): + if not _iscommand(cmd): return [None, None] name = os.path.basename(cmd) try: @@ -103,6 +102,38 @@ return [None, None] +if sys.platform[:3] == "win": + def _isexecutable(cmd): + cmd = cmd.lower() + if os.path.isfile(cmd) and cmd.endswith((".exe", ".bat")): + return True + for ext in ".exe", ".bat": + if os.path.isfile(cmd + ext): + return True + return False +else: + def _isexecutable(cmd): + if os.path.isfile(cmd): + mode = os.stat(cmd)[stat.ST_MODE] + if mode & stat.S_IXUSR or mode & stat.S_IXGRP or mode & stat.S_IXOTH: + return True + return False + +def _iscommand(cmd): + """Return True if cmd is executable or can be found on the executable + search path.""" + if _isexecutable(cmd): + return True + path = os.environ.get("PATH") + if not path: + return False + for d in path.split(os.pathsep): + exe = os.path.join(d, cmd) + if _isexecutable(exe): + return True + return False + + # General parent classes class BaseBrowser(object): @@ -422,62 +453,58 @@ def register_X_browsers(): # use xdg-open if around - if shutil.which("xdg-open"): + if _iscommand("xdg-open"): register("xdg-open", None, BackgroundBrowser("xdg-open")) # The default GNOME3 browser - if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"): + if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gvfs-open"): register("gvfs-open", None, BackgroundBrowser("gvfs-open")) # The default GNOME browser - if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gnome-open"): + if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gnome-open"): register("gnome-open", None, BackgroundBrowser("gnome-open")) # The default KDE browser - if "KDE_FULL_SESSION" in os.environ and shutil.which("kfmclient"): + if "KDE_FULL_SESSION" in os.environ and _iscommand("kfmclient"): register("kfmclient", Konqueror, Konqueror("kfmclient")) - if shutil.which("x-www-browser"): - register("x-www-browser", None, BackgroundBrowser("x-www-browser")) - # The Mozilla/Netscape browsers for browser in ("mozilla-firefox", "firefox", "mozilla-firebird", "firebird", - "iceweasel", "iceape", "seamonkey", "mozilla", "netscape"): - if shutil.which(browser): + if _iscommand(browser): register(browser, None, Mozilla(browser)) # Konqueror/kfm, the KDE browser. - if shutil.which("kfm"): + if _iscommand("kfm"): register("kfm", Konqueror, Konqueror("kfm")) - elif shutil.which("konqueror"): + elif _iscommand("konqueror"): register("konqueror", Konqueror, Konqueror("konqueror")) # Gnome's Galeon and Epiphany for browser in ("galeon", "epiphany"): - if shutil.which(browser): + if _iscommand(browser): register(browser, None, Galeon(browser)) # Skipstone, another Gtk/Mozilla based browser - if shutil.which("skipstone"): + if _iscommand("skipstone"): register("skipstone", None, BackgroundBrowser("skipstone")) # Google Chrome/Chromium browsers for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"): - if shutil.which(browser): + if _iscommand(browser): register(browser, None, Chrome(browser)) # Opera, quite popular - if shutil.which("opera"): + if _iscommand("opera"): register("opera", None, Opera("opera")) # Next, Mosaic -- old but still in use. - if shutil.which("mosaic"): + if _iscommand("mosaic"): register("mosaic", None, BackgroundBrowser("mosaic")) # Grail, the Python browser. Does anybody still use it? - if shutil.which("grail"): + if _iscommand("grail"): register("grail", Grail, None) # Prefer X browsers if present @@ -486,18 +513,16 @@ # Also try console browsers if os.environ.get("TERM"): - if shutil.which("www-browser"): - register("www-browser", None, GenericBrowser("www-browser")) # The Links/elinks browsers - if shutil.which("links"): + if _iscommand("links"): register("links", None, GenericBrowser("links")) - if shutil.which("elinks"): + if _iscommand("elinks"): register("elinks", None, Elinks("elinks")) # The Lynx browser , - if shutil.which("lynx"): + if _iscommand("lynx"): register("lynx", None, GenericBrowser("lynx")) # The w3m browser - if shutil.which("w3m"): + if _iscommand("w3m"): register("w3m", None, GenericBrowser("w3m")) # @@ -527,7 +552,7 @@ "Internet Explorer\\IEXPLORE.EXE") for browser in ("firefox", "firebird", "seamonkey", "mozilla", "netscape", "opera", iexplore): - if shutil.which(browser): + if _iscommand(browser): register(browser, None, BackgroundBrowser(browser)) # diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/xml/dom/expatbuilder.py --- a/Lib/xml/dom/expatbuilder.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/xml/dom/expatbuilder.py Fri Feb 01 23:12:09 2013 +0100 @@ -905,8 +905,11 @@ builder = ExpatBuilder() if isinstance(file, str): - with open(file, 'rb') as fp: + fp = open(file, 'rb') + try: result = builder.parseFile(fp) + finally: + fp.close() else: result = builder.parseFile(file) return result @@ -936,8 +939,11 @@ builder = FragmentBuilder(context) if isinstance(file, str): - with open(file, 'rb') as fp: + fp = open(file, 'rb') + try: result = builder.parseFile(fp) + finally: + fp.close() else: result = builder.parseFile(file) return result diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/xml/dom/minidom.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,5 @@ -"""Simple implementation of the Level 1 DOM. - -Namespaces and other minor Level 2 features are also supported. +"""\ +minidom.py -- a lightweight DOM implementation. parse("foo.xml") diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/xml/etree/ElementPath.py --- a/Lib/xml/etree/ElementPath.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/xml/etree/ElementPath.py Fri Feb 01 23:12:09 2013 +0100 @@ -174,7 +174,7 @@ if elem.get(key) == value: yield elem return select - if signature == "-" and not re.match("\-?\d+$", predicate[0]): + if signature == "-" and not re.match("\d+$", predicate[0]): # [tag] tag = predicate[0] def select(context, result): @@ -182,7 +182,7 @@ if elem.find(tag) is not None: yield elem return select - if signature == "-='" and not re.match("\-?\d+$", predicate[0]): + if signature == "-='" and not re.match("\d+$", predicate[0]): # [tag='value'] tag = predicate[0] value = predicate[-1] @@ -196,10 +196,7 @@ if signature == "-" or signature == "-()" or signature == "-()-": # [index] or [last()] or [last()-index] if signature == "-": - # [index] index = int(predicate[0]) - 1 - if index < 0: - raise SyntaxError("XPath position >= 1 expected") else: if predicate[0] != "last": raise SyntaxError("unsupported function") @@ -208,8 +205,6 @@ index = int(predicate[2]) - 1 except ValueError: raise SyntaxError("unsupported expression") - if index > -2: - raise SyntaxError("XPath offset from last() must be negative") else: index = -1 def select(context, result): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/xml/etree/ElementTree.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,47 +1,28 @@ -"""Lightweight XML support for Python. - - XML is an inherently hierarchical data format, and the most natural way to - represent it is with a tree. This module has two classes for this purpose: - - 1. ElementTree represents the whole XML document as a tree and - - 2. Element represents a single node in this tree. - - Interactions with the whole document (reading and writing to/from files) are - usually done on the ElementTree level. Interactions with a single XML element - and its sub-elements are done on the Element level. - - Element is a flexible container object designed to store hierarchical data - structures in memory. It can be described as a cross between a list and a - dictionary. Each Element has a number of properties associated with it: - - 'tag' - a string containing the element's name. - - 'attributes' - a Python dictionary storing the element's attributes. - - 'text' - a string containing the element's text content. - - 'tail' - an optional string containing text after the element's end tag. - - And a number of child elements stored in a Python sequence. - - To create an element instance, use the Element constructor, - or the SubElement factory function. - - You can also use the ElementTree class to wrap an element structure - and convert it to and from XML. - -""" - -#--------------------------------------------------------------------- -# Licensed to PSF under a Contributor Agreement. -# See http://www.python.org/psf/license for licensing details. # # ElementTree +# $Id: ElementTree.py 3440 2008-07-18 14:45:01Z fredrik $ +# +# light-weight XML support for Python 2.3 and later. +# +# history (since 1.2.6): +# 2005-11-12 fl added tostringlist/fromstringlist helpers +# 2006-07-05 fl merged in selected changes from the 1.3 sandbox +# 2006-07-05 fl removed support for 2.1 and earlier +# 2007-06-21 fl added deprecation/future warnings +# 2007-08-25 fl added doctype hook, added parser version attribute etc +# 2007-08-26 fl added new serializer code (better namespace handling, etc) +# 2007-08-27 fl warn for broken /tag searches on tree level +# 2007-09-02 fl added html/text methods to serializer (experimental) +# 2007-09-05 fl added method argument to tostring/tostringlist +# 2007-09-06 fl improved error handling +# 2007-09-13 fl added itertext, iterfind; assorted cleanups +# 2007-12-15 fl added C14N hooks, copy method (experimental) +# # Copyright (c) 1999-2008 by Fredrik Lundh. All rights reserved. # # fredrik@pythonware.com # http://www.pythonware.com +# # -------------------------------------------------------------------- # The ElementTree toolkit is # @@ -70,6 +51,9 @@ # OF THIS SOFTWARE. # -------------------------------------------------------------------- +# Licensed to PSF under a Contributor Agreement. +# See http://www.python.org/psf/license for licensing details. + __all__ = [ # public symbols "Comment", @@ -85,12 +69,34 @@ "TreeBuilder", "VERSION", "XML", "XMLID", - "XMLParser", + "XMLParser", "XMLTreeBuilder", "register_namespace", ] VERSION = "1.3.0" +## +# The Element type is a flexible container object, designed to +# store hierarchical data structures in memory. The type can be +# described as a cross between a list and a dictionary. +#

+# Each element has a number of properties associated with it: +#

    +#
  • a tag. This is a string identifying what kind of data +# this element represents (the element type, in other words).
  • +#
  • a number of attributes, stored in a Python dictionary.
  • +#
  • a text string.
  • +#
  • an optional tail string.
  • +#
  • a number of child elements, stored in a Python sequence
  • +#
+# +# To create an element instance, use the {@link #Element} constructor +# or the {@link #SubElement} factory function. +#

+# The {@link #ElementTree} class can be used to wrap an element +# structure, and convert it from and to XML. +## + import sys import re import warnings @@ -100,68 +106,81 @@ from . import ElementPath +## +# Parser error. This is a subclass of SyntaxError. +#

+# In addition to the exception value, an exception instance contains a +# specific exception code in the code attribute, and the line and +# column of the error in the position attribute. + class ParseError(SyntaxError): - """An error when parsing an XML document. - - In addition to its exception value, a ParseError contains - two extra attributes: - 'code' - the specific exception code - 'position' - the line and column of the error - - """ pass # -------------------------------------------------------------------- +## +# Checks if an object appears to be a valid element object. +# +# @param An element instance. +# @return A true value if this is an element object. +# @defreturn flag def iselement(element): - """Return True if *element* appears to be an Element.""" + # FIXME: not sure about this; + # isinstance(element, Element) or look for tag/attrib/text attributes return hasattr(element, 'tag') +## +# Element class. This class defines the Element interface, and +# provides a reference implementation of this interface. +#

+# The element name, attribute names, and attribute values can be +# either ASCII strings (ordinary Python strings containing only 7-bit +# ASCII characters) or Unicode strings. +# +# @param tag The element name. +# @param attrib An optional dictionary, containing element attributes. +# @param **extra Additional attributes, given as keyword arguments. +# @see Element +# @see SubElement +# @see Comment +# @see ProcessingInstruction class Element: - """An XML element. + # text...tail - This class is the reference implementation of the Element interface. - - An element's length is its number of subelements. That means if you - you want to check if an element is truly empty, you should check BOTH - its length AND its text attribute. - - The element tag, attribute names, and attribute values can be either - bytes or strings. - - *tag* is the element name. *attrib* is an optional dictionary containing - element attributes. *extra* are additional element attributes given as - keyword arguments. - - Example form: - text...tail - - """ + ## + # (Attribute) Element tag. tag = None - """The element's name.""" + + ## + # (Attribute) Element attribute dictionary. Where possible, use + # {@link #Element.get}, + # {@link #Element.set}, + # {@link #Element.keys}, and + # {@link #Element.items} to access + # element attributes. attrib = None - """Dictionary of the element's attributes.""" + + ## + # (Attribute) Text before first subelement. This is either a + # string or the value None. Note that if there was no text, this + # attribute may be either None or an empty string, depending on + # the parser. text = None - """ - Text before first subelement. This is either a string or the value None. - Note that if there is no text, this attribute may be either - None or the empty string, depending on the parser. - """ + ## + # (Attribute) Text after this element's end tag, but before the + # next sibling element's start tag. This is either a string or + # the value None. Note that if there was no text, this attribute + # may be either None or an empty string, depending on the parser. - tail = None - """ - Text after this element's end tag, but before the next sibling element's - start tag. This is either a string or the value None. Note that if there - was no text, this attribute may be either None or an empty string, - depending on the parser. + tail = None # text after end tag, if any - """ + # constructor def __init__(self, tag, attrib={}, **extra): if not isinstance(attrib, dict): @@ -176,30 +195,36 @@ def __repr__(self): return "" % (repr(self.tag), id(self)) + ## + # Creates a new element object of the same type as this element. + # + # @param tag Element tag. + # @param attrib Element attributes, given as a dictionary. + # @return A new element instance. + def makeelement(self, tag, attrib): - """Create a new element with the same type. - - *tag* is a string containing the element name. - *attrib* is a dictionary containing the element attributes. - - Do not call this method, use the SubElement factory function instead. - - """ return self.__class__(tag, attrib) + ## + # (Experimental) Copies the current element. This creates a + # shallow copy; subelements will be shared with the original tree. + # + # @return A new element instance. + def copy(self): - """Return copy of current element. - - This creates a shallow copy. Subelements will be shared with the - original tree. - - """ elem = self.makeelement(self.tag, self.attrib) elem.text = self.text elem.tail = self.tail elem[:] = self return elem + ## + # Returns the number of subelements. Note that this only counts + # full elements; to check if there's any content in an element, you + # have to check both the length and the text attribute. + # + # @return The number of subelements. + def __len__(self): return len(self._children) @@ -211,9 +236,23 @@ ) return len(self._children) != 0 # emulate old behaviour, for now + ## + # Returns the given subelement, by index. + # + # @param index What subelement to return. + # @return The given subelement. + # @exception IndexError If the given element does not exist. + def __getitem__(self, index): return self._children[index] + ## + # Replaces the given subelement, by index. + # + # @param index What subelement to replace. + # @param element The new element value. + # @exception IndexError If the given element does not exist. + def __setitem__(self, index, element): # if isinstance(index, slice): # for elt in element: @@ -222,62 +261,76 @@ # assert iselement(element) self._children[index] = element + ## + # Deletes the given subelement, by index. + # + # @param index What subelement to delete. + # @exception IndexError If the given element does not exist. + def __delitem__(self, index): del self._children[index] - def append(self, subelement): - """Add *subelement* to the end of this element. + ## + # Adds a subelement to the end of this element. In document order, + # the new element will appear after the last existing subelement (or + # directly after the text, if it's the first subelement), but before + # the end tag for this element. + # + # @param element The element to add. - The new element will appear in document order after the last existing - subelement (or directly after the text, if it's the first subelement), - but before the end tag for this element. + def append(self, element): + self._assert_is_element(element) + self._children.append(element) - """ - self._assert_is_element(subelement) - self._children.append(subelement) + ## + # Appends subelements from a sequence. + # + # @param elements A sequence object with zero or more elements. + # @since 1.3 def extend(self, elements): - """Append subelements from a sequence. - - *elements* is a sequence with zero or more elements. - - """ for element in elements: self._assert_is_element(element) self._children.extend(elements) - def insert(self, index, subelement): - """Insert *subelement* at position *index*.""" - self._assert_is_element(subelement) - self._children.insert(index, subelement) + ## + # Inserts a subelement at the given position in this element. + # + # @param index Where to insert the new subelement. + + def insert(self, index, element): + self._assert_is_element(element) + self._children.insert(index, element) def _assert_is_element(self, e): # Need to refer to the actual Python implementation, not the # shadowing C implementation. - if not isinstance(e, _Element_Py): + if not isinstance(e, _Element): raise TypeError('expected an Element, not %s' % type(e).__name__) - def remove(self, subelement): - """Remove matching subelement. + ## + # Removes a matching subelement. Unlike the find methods, + # this method compares elements based on identity, not on tag + # value or contents. To remove subelements by other means, the + # easiest way is often to use a list comprehension to select what + # elements to keep, and use slice assignment to update the parent + # element. + # + # @param element What element to remove. + # @exception ValueError If a matching element could not be found. - Unlike the find methods, this method compares elements based on - identity, NOT ON tag value or contents. To remove subelements by - other means, the easiest way is to use a list comprehension to - select what elements to keep, and then use slice assignment to update - the parent element. + def remove(self, element): + # assert iselement(element) + self._children.remove(element) - ValueError is raised if a matching element could not be found. - - """ - # assert iselement(element) - self._children.remove(subelement) + ## + # (Deprecated) Returns all subelements. The elements are returned + # in document order. + # + # @return A list of subelements. + # @defreturn list of Element instances def getchildren(self): - """(Deprecated) Return all subelements. - - Elements are returned in document order. - - """ warnings.warn( "This method will be removed in future versions. " "Use 'list(elem)' or iteration over elem instead.", @@ -285,122 +338,124 @@ ) return self._children + ## + # Finds the first matching subelement, by tag name or path. + # + # @param path What element to look for. + # @keyparam namespaces Optional namespace prefix map. + # @return The first matching element, or None if no element was found. + # @defreturn Element or None + def find(self, path, namespaces=None): - """Find first matching element by tag name or path. - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return the first matching element, or None if no element was found. - - """ return ElementPath.find(self, path, namespaces) + ## + # Finds text for the first matching subelement, by tag name or path. + # + # @param path What element to look for. + # @param default What to return if the element was not found. + # @keyparam namespaces Optional namespace prefix map. + # @return The text content of the first matching element, or the + # default value no element was found. Note that if the element + # is found, but has no text content, this method returns an + # empty string. + # @defreturn string + def findtext(self, path, default=None, namespaces=None): - """Find text for first matching element by tag name or path. - - *path* is a string having either an element tag or an XPath, - *default* is the value to return if the element was not found, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return text content of first matching element, or default value if - none was found. Note that if an element is found having no text - content, the empty string is returned. - - """ return ElementPath.findtext(self, path, default, namespaces) + ## + # Finds all matching subelements, by tag name or path. + # + # @param path What element to look for. + # @keyparam namespaces Optional namespace prefix map. + # @return A list or other sequence containing all matching elements, + # in document order. + # @defreturn list of Element instances + def findall(self, path, namespaces=None): - """Find all matching subelements by tag name or path. - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Returns list containing all matching elements in document order. - - """ return ElementPath.findall(self, path, namespaces) + ## + # Finds all matching subelements, by tag name or path. + # + # @param path What element to look for. + # @keyparam namespaces Optional namespace prefix map. + # @return An iterator or sequence containing all matching elements, + # in document order. + # @defreturn a generated sequence of Element instances + def iterfind(self, path, namespaces=None): - """Find all matching subelements by tag name or path. - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return an iterable yielding all matching elements in document order. - - """ return ElementPath.iterfind(self, path, namespaces) + ## + # Resets an element. This function removes all subelements, clears + # all attributes, and sets the text and tail attributes + # to None. + def clear(self): - """Reset element. - - This function removes all subelements, clears all attributes, and sets - the text and tail attributes to None. - - """ self.attrib.clear() self._children = [] self.text = self.tail = None + ## + # Gets an element attribute. Equivalent to attrib.get, but + # some implementations may handle this a bit more efficiently. + # + # @param key What attribute to look for. + # @param default What to return if the attribute was not found. + # @return The attribute value, or the default value, if the + # attribute was not found. + # @defreturn string or None + def get(self, key, default=None): - """Get element attribute. - - Equivalent to attrib.get, but some implementations may handle this a - bit more efficiently. *key* is what attribute to look for, and - *default* is what to return if the attribute was not found. - - Returns a string containing the attribute value, or the default if - attribute was not found. - - """ return self.attrib.get(key, default) + ## + # Sets an element attribute. Equivalent to attrib[key] = value, + # but some implementations may handle this a bit more efficiently. + # + # @param key What attribute to set. + # @param value The attribute value. + def set(self, key, value): - """Set element attribute. - - Equivalent to attrib[key] = value, but some implementations may handle - this a bit more efficiently. *key* is what attribute to set, and - *value* is the attribute value to set it to. - - """ self.attrib[key] = value + ## + # Gets a list of attribute names. The names are returned in an + # arbitrary order (just like for an ordinary Python dictionary). + # Equivalent to attrib.keys(). + # + # @return A list of element attribute names. + # @defreturn list of strings + def keys(self): - """Get list of attribute names. - - Names are returned in an arbitrary order, just like an ordinary - Python dict. Equivalent to attrib.keys() - - """ return self.attrib.keys() + ## + # Gets element attributes, as a sequence. The attributes are + # returned in an arbitrary order. Equivalent to attrib.items(). + # + # @return A list of (name, value) tuples for all attributes. + # @defreturn list of (string, string) tuples + def items(self): - """Get element attributes as a sequence. - - The attributes are returned in arbitrary order. Equivalent to - attrib.items(). - - Return a list of (name, value) tuples. - - """ return self.attrib.items() + ## + # Creates a tree iterator. The iterator loops over this element + # and all subelements, in document order, and returns all elements + # with a matching tag. + #

+ # If the tree structure is modified during iteration, new or removed + # elements may or may not be included. To get a stable set, use the + # list() function on the iterator, and loop over the resulting list. + # + # @param tag What tags to look for (default is to return all elements). + # @return An iterator containing all the matching elements. + # @defreturn iterator + def iter(self, tag=None): - """Create tree iterator. - - The iterator loops over the element and all subelements in document - order, returning all elements with a matching tag. - - If the tree structure is modified during iteration, new or removed - elements may or may not be included. To get a stable set, use the - list() function on the iterator, and loop over the resulting list. - - *tag* is what tags to look for (default is to return all elements) - - Return an iterator containing all the matching elements. - - """ if tag == "*": tag = None if tag is None or self.tag == tag: @@ -418,13 +473,15 @@ ) return list(self.iter(tag)) + ## + # Creates a text iterator. The iterator loops over this element + # and all subelements, in document order, and returns all inner + # text. + # + # @return An iterator containing all inner text. + # @defreturn iterator + def itertext(self): - """Create text iterator. - - The iterator loops over the element and all subelements in document - order, returning all inner text. - - """ tag = self.tag if not isinstance(tag, str) and tag is not None: return @@ -435,50 +492,58 @@ if e.tail: yield e.tail +# compatibility +_Element = _ElementInterface = Element + +## +# Subelement factory. This function creates an element instance, and +# appends it to an existing element. +#

+# The element name, attribute names, and attribute values can be +# either 8-bit ASCII strings or Unicode strings. +# +# @param parent The parent element. +# @param tag The subelement name. +# @param attrib An optional dictionary, containing element attributes. +# @param **extra Additional attributes, given as keyword arguments. +# @return An element instance. +# @defreturn Element def SubElement(parent, tag, attrib={}, **extra): - """Subelement factory which creates an element instance, and appends it - to an existing parent. - - The element tag, attribute names, and attribute values can be either - bytes or Unicode strings. - - *parent* is the parent element, *tag* is the subelements name, *attrib* is - an optional directory containing element attributes, *extra* are - additional attributes given as keyword arguments. - - """ attrib = attrib.copy() attrib.update(extra) element = parent.makeelement(tag, attrib) parent.append(element) return element +## +# Comment element factory. This factory function creates a special +# element that will be serialized as an XML comment by the standard +# serializer. +#

+# The comment string can be either an 8-bit ASCII string or a Unicode +# string. +# +# @param text A string containing the comment string. +# @return An element instance, representing a comment. +# @defreturn Element def Comment(text=None): - """Comment element factory. - - This function creates a special element which the standard serializer - serializes as an XML comment. - - *text* is a string containing the comment string. - - """ element = Element(Comment) element.text = text return element +## +# PI element factory. This factory function creates a special element +# that will be serialized as an XML processing instruction by the standard +# serializer. +# +# @param target A string containing the PI target. +# @param text A string containing the PI contents, if any. +# @return An element instance, representing a PI. +# @defreturn Element def ProcessingInstruction(target, text=None): - """Processing Instruction element factory. - - This function creates a special element which the standard serializer - serializes as an XML comment. - - *target* is a string containing the processing instruction, *text* is a - string containing the processing instruction contents, if any. - - """ element = Element(ProcessingInstruction) element.text = target if text: @@ -487,21 +552,17 @@ PI = ProcessingInstruction +## +# QName wrapper. This can be used to wrap a QName attribute value, in +# order to get proper namespace handling on output. +# +# @param text A string containing the QName value, in the form {uri}local, +# or, if the tag argument is given, the URI part of a QName. +# @param tag Optional tag. If given, the first argument is interpreted as +# an URI, and this argument is interpreted as a local name. +# @return An opaque object, representing the QName. class QName: - """Qualified name wrapper. - - This class can be used to wrap a QName attribute value in order to get - proper namespace handing on output. - - *text_or_uri* is a string containing the QName value either in the form - {uri}local, or if the tag argument is given, the URI part of a QName. - - *tag* is an optional argument which if given, will make the first - argument (text_or_uri) be interpreted as a URI, and this argument (tag) - be interpreted as a local name. - - """ def __init__(self, text_or_uri, tag=None): if tag: text_or_uri = "{%s}%s" % (text_or_uri, tag) @@ -539,65 +600,63 @@ # -------------------------------------------------------------------- +## +# ElementTree wrapper class. This class represents an entire element +# hierarchy, and adds some extra support for serialization to and from +# standard XML. +# +# @param element Optional root element. +# @keyparam file Optional file handle or file name. If given, the +# tree is initialized with the contents of this XML file. class ElementTree: - """An XML element hierarchy. - This class also provides support for serialization to and from - standard XML. - - *element* is an optional root element node, - *file* is an optional file handle or file name of an XML file whose - contents will be used to initialize the tree with. - - """ def __init__(self, element=None, file=None): # assert element is None or iselement(element) self._root = element # first node if file: self.parse(file) + ## + # Gets the root element for this tree. + # + # @return An element instance. + # @defreturn Element + def getroot(self): - """Return root element of this tree.""" return self._root + ## + # Replaces the root element for this tree. This discards the + # current contents of the tree, and replaces it with the given + # element. Use with care. + # + # @param element An element instance. + def _setroot(self, element): - """Replace root element of this tree. - - This will discard the current contents of the tree and replace it - with the given element. Use with care! - - """ # assert iselement(element) self._root = element + ## + # Loads an external XML document into this element tree. + # + # @param source A file name or file object. If a file object is + # given, it only has to implement a read(n) method. + # @keyparam parser An optional parser instance. If not given, the + # standard {@link XMLParser} parser is used. + # @return The document root element. + # @defreturn Element + # @exception ParseError If the parser fails to parse the document. + def parse(self, source, parser=None): - """Load external XML document into element tree. - - *source* is a file name or file object, *parser* is an optional parser - instance that defaults to XMLParser. - - ParseError is raised if the parser fails to parse the document. - - Returns the root element of the given source document. - - """ close_source = False if not hasattr(source, "read"): source = open(source, "rb") close_source = True try: - if parser is None: - # If no parser was specified, create a default XMLParser - parser = XMLParser() - if hasattr(parser, '_parse_whole'): - # The default XMLParser, when it comes from an accelerator, - # can define an internal _parse_whole API for efficiency. - # It can be used to parse the whole source without feeding - # it with chunks. - self._root = parser._parse_whole(source) - return self._root - while True: + if not parser: + parser = XMLParser(target=TreeBuilder()) + while 1: data = source.read(65536) if not data: break @@ -608,15 +667,15 @@ if close_source: source.close() + ## + # Creates a tree iterator for the root element. The iterator loops + # over all elements in this tree, in document order. + # + # @param tag What tags to look for (default is to return all elements) + # @return An iterator. + # @defreturn iterator + def iter(self, tag=None): - """Create and return tree iterator for the root element. - - The iterator loops over all elements in this tree, in document order. - - *tag* is a string with the tag name to iterate over - (default is to return all elements). - - """ # assert self._root is not None return self._root.iter(tag) @@ -630,17 +689,16 @@ ) return list(self.iter(tag)) + ## + # Finds the first toplevel element with given tag. + # Same as getroot().find(path). + # + # @param path What element to look for. + # @keyparam namespaces Optional namespace prefix map. + # @return The first matching element, or None if no element was found. + # @defreturn Element or None + def find(self, path, namespaces=None): - """Find first matching element by tag name or path. - - Same as getroot().find(path), which is Element.find() - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return the first matching element, or None if no element was found. - - """ # assert self._root is not None if path[:1] == "/": path = "." + path @@ -652,17 +710,20 @@ ) return self._root.find(path, namespaces) + ## + # Finds the element text for the first toplevel element with given + # tag. Same as getroot().findtext(path). + # + # @param path What toplevel element to look for. + # @param default What to return if the element was not found. + # @keyparam namespaces Optional namespace prefix map. + # @return The text content of the first matching element, or the + # default value no element was found. Note that if the element + # is found, but has no text content, this method returns an + # empty string. + # @defreturn string + def findtext(self, path, default=None, namespaces=None): - """Find first matching element by tag name or path. - - Same as getroot().findtext(path), which is Element.findtext() - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return the first matching element, or None if no element was found. - - """ # assert self._root is not None if path[:1] == "/": path = "." + path @@ -674,17 +735,17 @@ ) return self._root.findtext(path, default, namespaces) + ## + # Finds all toplevel elements with the given tag. + # Same as getroot().findall(path). + # + # @param path What element to look for. + # @keyparam namespaces Optional namespace prefix map. + # @return A list or iterator containing all matching elements, + # in document order. + # @defreturn list of Element instances + def findall(self, path, namespaces=None): - """Find all matching subelements by tag name or path. - - Same as getroot().findall(path), which is Element.findall(). - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return list containing all matching elements in document order. - - """ # assert self._root is not None if path[:1] == "/": path = "." + path @@ -696,17 +757,17 @@ ) return self._root.findall(path, namespaces) + ## + # Finds all matching subelements, by tag name or path. + # Same as getroot().iterfind(path). + # + # @param path What element to look for. + # @keyparam namespaces Optional namespace prefix map. + # @return An iterator or sequence containing all matching elements, + # in document order. + # @defreturn a generated sequence of Element instances + def iterfind(self, path, namespaces=None): - """Find all matching subelements by tag name or path. - - Same as getroot().iterfind(path), which is element.iterfind() - - *path* is a string having either an element tag or an XPath, - *namespaces* is an optional mapping from namespace prefix to full name. - - Return an iterable yielding all matching elements in document order. - - """ # assert self._root is not None if path[:1] == "/": path = "." + path @@ -724,27 +785,18 @@ default_namespace=None, method=None, *, short_empty_elements=True): - """Write element tree to a file as XML. - - Arguments: - *file_or_filename* -- file name or a file object opened for writing - - *encoding* -- the output encoding (default: US-ASCII) - - *xml_declaration* -- bool indicating if an XML declaration should be - added to the output. If None, an XML declaration - is added if encoding IS NOT either of: - US-ASCII, UTF-8, or Unicode - - *default_namespace* -- sets the default XML namespace (for "xmlns") - - *method* -- either "xml" (default), "html, "text", or "c14n" - - *short_empty_elements* -- controls the formatting of elements - that contain no content. If True (default) - they are emitted as a single self-closed - tag, otherwise they are emitted as a pair - of start/end tags + """Write the element tree to a file, as XML. 'file_or_filename' is a + file name or a file object opened for writing. + 'encoding' is the output encoding (default is US-ASCII). + 'xml_declaration' controls if an XML declaration should be added + to the output. Use False for never, True for always, None for only + if not US-ASCII or UTF-8 or Unicode (default is None). + 'default_namespace' sets the default XML namespace (for "xmlns"). + 'method' is either "xml" (default), "html", "text" or "c14n". + The keyword-only 'short_empty_elements' parameter controls the + formatting of elements that contain no content. If True (default), + they are emitted as a single self-closed tag, otherwise they are + emitted as a pair of start/end tags. """ if not method: @@ -992,15 +1044,15 @@ # FIXME: handle boolean attributes write(" %s=\"%s\"" % (qnames[k], v)) write(">") - ltag = tag.lower() + tag = tag.lower() if text: - if ltag == "script" or ltag == "style": + if tag == "script" or tag == "style": write(text) else: write(_escape_cdata(text)) for e in elem: _serialize_html(write, e, qnames, None) - if ltag not in HTML_EMPTY: + if tag not in HTML_EMPTY: write("") if elem.tail: write(_escape_cdata(elem.tail)) @@ -1019,19 +1071,18 @@ # "c14n": _serialize_c14n, } +## +# Registers a namespace prefix. The registry is global, and any +# existing mapping for either the given prefix or the namespace URI +# will be removed. +# +# @param prefix Namespace prefix. +# @param uri Namespace uri. Tags and attributes in this namespace +# will be serialized with the given prefix, if at all possible. +# @exception ValueError If the prefix is reserved, or is otherwise +# invalid. def register_namespace(prefix, uri): - """Register a namespace prefix. - - The registry is global, and any existing mapping for either the - given prefix or the namespace URI will be removed. - - *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and - attributes in this namespace will be serialized with prefix if possible. - - ValueError is raised if prefix is reserved or is invalid. - - """ if re.match("ns\d+$", prefix): raise ValueError("Prefix format reserved for internal use") for k, v in list(_namespace_map.items()): @@ -1107,27 +1158,42 @@ # -------------------------------------------------------------------- +## +# Generates a string representation of an XML element, including all +# subelements. If encoding is "unicode", the return type is a string; +# otherwise it is a bytes array. +# +# @param element An Element instance. +# @keyparam encoding Optional output encoding (default is US-ASCII). +# Use "unicode" to return a Unicode string. +# @keyparam method Optional output method ("xml", "html", "text" or +# "c14n"; default is "xml"). +# @return An (optionally) encoded string containing the XML data. +# @defreturn string + def tostring(element, encoding=None, method=None, *, short_empty_elements=True): - """Generate string representation of XML element. - - All subelements are included. If encoding is "unicode", a string - is returned. Otherwise a bytestring is returned. - - *element* is an Element instance, *encoding* is an optional output - encoding defaulting to US-ASCII, *method* is an optional output which can - be one of "xml" (default), "html", "text" or "c14n". - - Returns an (optionally) encoded string containing the XML data. - - """ stream = io.StringIO() if encoding == 'unicode' else io.BytesIO() ElementTree(element).write(stream, encoding, method=method, short_empty_elements=short_empty_elements) return stream.getvalue() +## +# Generates a string representation of an XML element, including all +# subelements. +# +# @param element An Element instance. +# @keyparam encoding Optional output encoding (default is US-ASCII). +# Use "unicode" to return a Unicode string. +# @keyparam method Optional output method ("xml", "html", "text" or +# "c14n"; default is "xml"). +# @return A sequence object containing the XML data. +# @defreturn sequence +# @since 1.3 + class _ListDataStream(io.BufferedIOBase): - """An auxiliary stream accumulating into a list reference.""" + """ An auxiliary stream accumulating into a list reference + """ def __init__(self, lst): self.lst = lst @@ -1151,17 +1217,16 @@ short_empty_elements=short_empty_elements) return lst +## +# Writes an element tree or element structure to sys.stdout. This +# function should be used for debugging only. +#

+# The exact output format is implementation dependent. In this +# version, it's written as an ordinary XML file. +# +# @param elem An element tree or an individual element. def dump(elem): - """Write element tree or element structure to sys.stdout. - - This function should be used for debugging only. - - *elem* is either an ElementTree, or a single Element. The exact output - format is implementation dependent. In this version, it's written as an - ordinary XML file. - - """ # debugging if not isinstance(elem, ElementTree): elem = ElementTree(elem) @@ -1173,151 +1238,144 @@ # -------------------------------------------------------------------- # parsing +## +# Parses an XML document into an element tree. +# +# @param source A filename or file object containing XML data. +# @param parser An optional parser instance. If not given, the +# standard {@link XMLParser} parser is used. +# @return An ElementTree instance def parse(source, parser=None): - """Parse XML document into element tree. - - *source* is a filename or file object containing XML data, - *parser* is an optional parser instance defaulting to XMLParser. - - Return an ElementTree instance. - - """ tree = ElementTree() tree.parse(source, parser) return tree +## +# Parses an XML document into an element tree incrementally, and reports +# what's going on to the user. +# +# @param source A filename or file object containing XML data. +# @param events A list of events to report back. If omitted, only "end" +# events are reported. +# @param parser An optional parser instance. If not given, the +# standard {@link XMLParser} parser is used. +# @return A (event, elem) iterator. def iterparse(source, events=None, parser=None): - """Incrementally parse XML document into ElementTree. - - This class also reports what's going on to the user based on the - *events* it is initialized with. The supported events are the strings - "start", "end", "start-ns" and "end-ns" (the "ns" events are used to get - detailed namespace information). If *events* is omitted, only - "end" events are reported. - - *source* is a filename or file object containing XML data, *events* is - a list of events to report back, *parser* is an optional parser instance. - - Returns an iterator providing (event, elem) pairs. - - """ close_source = False if not hasattr(source, "read"): source = open(source, "rb") close_source = True + if not parser: + parser = XMLParser(target=TreeBuilder()) return _IterParseIterator(source, events, parser, close_source) +class _IterParseIterator: -class IncrementalParser: - - def __init__(self, events=None, parser=None): - # _elementtree.c expects a list, not a deque - self._events_queue = [] + def __init__(self, source, events, parser, close_source=False): + self._file = source + self._close_file = close_source + self._events = [] self._index = 0 + self._error = None self.root = self._root = None - if not parser: - parser = XMLParser(target=TreeBuilder()) self._parser = parser # wire up the parser for event reporting + parser = self._parser._parser + append = self._events.append if events is None: - events = ("end",) - self._parser._setevents(self._events_queue, events) - - def data_received(self, data): - if self._parser is None: - raise ValueError("data_received() called after end of stream") - if data: - try: - self._parser.feed(data) - except SyntaxError as exc: - self._events_queue.append(exc) - - def eof_received(self): - self._root = self._parser.close() - self._parser = None - if self._index >= len(self._events_queue): - self.root = self._root - - def events(self): - events = self._events_queue - while True: - index = self._index - try: - event = events[self._index] - # Avoid retaining references to past events - events[self._index] = None - except IndexError: - break - index += 1 - # Compact the list in a O(1) amortized fashion - if index * 2 >= len(events): - events[:index] = [] - self._index = 0 + events = ["end"] + for event in events: + if event == "start": + try: + parser.ordered_attributes = 1 + parser.specified_attributes = 1 + def handler(tag, attrib_in, event=event, append=append, + start=self._parser._start_list): + append((event, start(tag, attrib_in))) + parser.StartElementHandler = handler + except AttributeError: + def handler(tag, attrib_in, event=event, append=append, + start=self._parser._start): + append((event, start(tag, attrib_in))) + parser.StartElementHandler = handler + elif event == "end": + def handler(tag, event=event, append=append, + end=self._parser._end): + append((event, end(tag))) + parser.EndElementHandler = handler + elif event == "start-ns": + def handler(prefix, uri, event=event, append=append): + append((event, (prefix or "", uri or ""))) + parser.StartNamespaceDeclHandler = handler + elif event == "end-ns": + def handler(prefix, event=event, append=append): + append((event, None)) + parser.EndNamespaceDeclHandler = handler else: - self._index = index - if isinstance(event, Exception): - raise event - else: - yield event - if self._parser is None: - self.root = self._root - - -class _IterParseIterator(IncrementalParser): - - def __init__(self, source, events, parser, close_source=False): - IncrementalParser.__init__(self, events, parser) - self._file = source - self._close_file = close_source + raise ValueError("unknown event %r" % event) def __next__(self): while 1: - for event in self.events(): - return event + try: + item = self._events[self._index] + self._index += 1 + return item + except IndexError: + pass + if self._error: + e = self._error + self._error = None + raise e if self._parser is None: + self.root = self._root if self._close_file: self._file.close() raise StopIteration # load event buffer + del self._events[:] + self._index = 0 data = self._file.read(16384) if data: - self.data_received(data) + try: + self._parser.feed(data) + except SyntaxError as exc: + self._error = exc else: - self.eof_received() + self._root = self._parser.close() + self._parser = None def __iter__(self): return self +## +# Parses an XML document from a string constant. This function can +# be used to embed "XML literals" in Python code. +# +# @param source A string containing XML data. +# @param parser An optional parser instance. If not given, the +# standard {@link XMLParser} parser is used. +# @return An Element instance. +# @defreturn Element def XML(text, parser=None): - """Parse XML document from string constant. - - This function can be used to embed "XML Literals" in Python code. - - *text* is a string containing XML data, *parser* is an - optional parser instance, defaulting to the standard XMLParser. - - Returns an Element instance. - - """ if not parser: parser = XMLParser(target=TreeBuilder()) parser.feed(text) return parser.close() +## +# Parses an XML document from a string constant, and also returns +# a dictionary which maps from element id:s to elements. +# +# @param source A string containing XML data. +# @param parser An optional parser instance. If not given, the +# standard {@link XMLParser} parser is used. +# @return A tuple containing an Element instance and a dictionary. +# @defreturn (Element, dictionary) def XMLID(text, parser=None): - """Parse XML document from string constant for its IDs. - - *text* is a string containing XML data, *parser* is an - optional parser instance, defaulting to the standard XMLParser. - - Returns an (Element, dict) tuple, in which the - dict maps element id:s to elements. - - """ if not parser: parser = XMLParser(target=TreeBuilder()) parser.feed(text) @@ -1329,18 +1387,27 @@ ids[id] = elem return tree, ids -# Parse XML document from string constant. Alias for XML(). +## +# Parses an XML document from a string constant. Same as {@link #XML}. +# +# @def fromstring(text) +# @param source A string containing XML data. +# @return An Element instance. +# @defreturn Element + fromstring = XML +## +# Parses an XML document from a sequence of string fragments. +# +# @param sequence A list or other sequence containing XML data fragments. +# @param parser An optional parser instance. If not given, the +# standard {@link XMLParser} parser is used. +# @return An Element instance. +# @defreturn Element +# @since 1.3 + def fromstringlist(sequence, parser=None): - """Parse XML document from sequence of string fragments. - - *sequence* is a list of other sequence, *parser* is an optional parser - instance, defaulting to the standard XMLParser. - - Returns an Element instance. - - """ if not parser: parser = XMLParser(target=TreeBuilder()) for text in sequence: @@ -1349,20 +1416,19 @@ # -------------------------------------------------------------------- +## +# Generic element structure builder. This builder converts a sequence +# of {@link #TreeBuilder.start}, {@link #TreeBuilder.data}, and {@link +# #TreeBuilder.end} method calls to a well-formed element structure. +#

+# You can use this class to build an element structure using a custom XML +# parser, or a parser for some other XML-like format. +# +# @param element_factory Optional element factory. This factory +# is called to create new Element instances, as necessary. class TreeBuilder: - """Generic element structure builder. - This builder converts a sequence of start, data, and end method - calls to a well-formed element structure. - - You can use this class to build an element structure using a custom XML - parser, or a parser for some other XML-like format. - - *element_factory* is an optional element factory which is called - to create new Element instances, as necessary. - - """ def __init__(self, element_factory=None): self._data = [] # data collector self._elem = [] # element stack @@ -1372,8 +1438,14 @@ element_factory = Element self._factory = element_factory + ## + # Flushes the builder buffers, and returns the toplevel document + # element. + # + # @return An Element instance. + # @defreturn Element + def close(self): - """Flush builder buffers and return toplevel document Element.""" assert len(self._elem) == 0, "missing end tags" assert self._last is not None, "missing toplevel element" return self._last @@ -1390,17 +1462,24 @@ self._last.text = text self._data = [] + ## + # Adds text to the current element. + # + # @param data A string. This should be either an 8-bit string + # containing ASCII text, or a Unicode string. + def data(self, data): - """Add text to current element.""" self._data.append(data) + ## + # Opens a new element. + # + # @param tag The element name. + # @param attrib A dictionary containing element attributes. + # @return The opened element. + # @defreturn Element + def start(self, tag, attrs): - """Open new element and return it. - - *tag* is the element name, *attrs* is a dict containing element - attributes. - - """ self._flush() self._last = elem = self._factory(tag, attrs) if self._elem: @@ -1409,12 +1488,14 @@ self._tail = 0 return elem + ## + # Closes the current element. + # + # @param tag The element name. + # @return The closed element. + # @defreturn Element + def end(self, tag): - """Close and return current Element. - - *tag* is the element name. - - """ self._flush() self._last = self._elem.pop() assert self._last.tag == tag,\ @@ -1423,18 +1504,20 @@ self._tail = 1 return self._last +## +# Element structure builder for XML source data, based on the +# expat parser. +# +# @keyparam target Target object. If omitted, the builder uses an +# instance of the standard {@link #TreeBuilder} class. +# @keyparam html Predefine HTML entities. This flag is not supported +# by the current implementation. +# @keyparam encoding Optional encoding. If given, the value overrides +# the encoding specified in the XML file. +# @see #ElementTree +# @see #TreeBuilder -# also see ElementTree and TreeBuilder class XMLParser: - """Element structure builder for XML source data based on the expat parser. - - *html* are predefined HTML entities (not supported currently), - *target* is an optional target object which defaults to an instance of the - standard TreeBuilder class, *encoding* is an optional encoding string - which if given, overrides the encoding specified in the XML file: - http://www.iana.org/assignments/character-sets - - """ def __init__(self, html=0, target=None, encoding=None): try: @@ -1487,39 +1570,6 @@ except AttributeError: pass # unknown - def _setevents(self, events_queue, events_to_report): - # Internal API for IncrementalParser - # events_to_report: a list of events to report during parsing (same as - # the *events* of IncrementalParser's constructor. - # events_queue: a list of actual parsing events that will be populated - # by the underlying parser. - # - parser = self._parser - append = events_queue.append - for event_name in events_to_report: - if event_name == "start": - parser.ordered_attributes = 1 - parser.specified_attributes = 1 - def handler(tag, attrib_in, event=event_name, append=append, - start=self._start_list): - append((event, start(tag, attrib_in))) - parser.StartElementHandler = handler - elif event_name == "end": - def handler(tag, event=event_name, append=append, - end=self._end): - append((event, end(tag))) - parser.EndElementHandler = handler - elif event_name == "start-ns": - def handler(prefix, uri, event=event_name, append=append): - append((event, (prefix or "", uri or ""))) - parser.StartNamespaceDeclHandler = handler - elif event_name == "end-ns": - def handler(prefix, event=event_name, append=append): - append((event, None)) - parser.EndNamespaceDeclHandler = handler - else: - raise ValueError("unknown event %r" % event_name) - def _raiseerror(self, value): err = ParseError(value) err.code = value.code @@ -1609,13 +1659,15 @@ self.doctype(name, pubid, system[1:-1]) self._doctype = None + ## + # (Deprecated) Handles a doctype declaration. + # + # @param name Doctype name. + # @param pubid Public identifier. + # @param system System identifier. + def doctype(self, name, pubid, system): - """(Deprecated) Handle doctype declaration - - *name* is the Doctype name, *pubid* is the public identifier, - and *system* is the system identifier. - - """ + """This method of XMLParser is deprecated.""" warnings.warn( "This method of XMLParser is deprecated. Define doctype() " "method on the TreeBuilder target.", @@ -1625,15 +1677,24 @@ # sentinel, if doctype is redefined in a subclass __doctype = doctype + ## + # Feeds data to the parser. + # + # @param data Encoded data. + def feed(self, data): - """Feed encoded data to parser.""" try: self.parser.Parse(data, 0) except self._error as v: self._raiseerror(v) + ## + # Finishes feeding data to the parser. + # + # @return An element structure. + # @defreturn Element + def close(self): - """Finish feeding data to parser and return element structure.""" try: self.parser.Parse("", 1) # end of data except self._error as v: @@ -1652,12 +1713,90 @@ # Import the C accelerators try: - # Element is going to be shadowed by the C implementation. We need to keep - # the Python version of it accessible for some "creative" by external code - # (see tests) - _Element_Py = Element - # Element, SubElement, ParseError, TreeBuilder, XMLParser from _elementtree import * except ImportError: pass +else: + # Overwrite 'ElementTree.parse' and 'iterparse' to use the C XMLParser + + class ElementTree(ElementTree): + def parse(self, source, parser=None): + close_source = False + if not hasattr(source, 'read'): + source = open(source, 'rb') + close_source = True + try: + if parser is not None: + while True: + data = source.read(65536) + if not data: + break + parser.feed(data) + self._root = parser.close() + else: + parser = XMLParser() + self._root = parser._parse(source) + return self._root + finally: + if close_source: + source.close() + + class iterparse: + root = None + def __init__(self, file, events=None): + self._close_file = False + if not hasattr(file, 'read'): + file = open(file, 'rb') + self._close_file = True + self._file = file + self._events = [] + self._index = 0 + self._error = None + self.root = self._root = None + b = TreeBuilder() + self._parser = XMLParser(b) + self._parser._setevents(self._events, events) + + def __next__(self): + while True: + try: + item = self._events[self._index] + self._index += 1 + return item + except IndexError: + pass + if self._error: + e = self._error + self._error = None + raise e + if self._parser is None: + self.root = self._root + if self._close_file: + self._file.close() + raise StopIteration + # load event buffer + del self._events[:] + self._index = 0 + data = self._file.read(16384) + if data: + try: + self._parser.feed(data) + except SyntaxError as exc: + self._error = exc + else: + self._root = self._parser.close() + self._parser = None + + def __iter__(self): + return self + +# compatibility +XMLTreeBuilder = XMLParser + +# workaround circular import. +try: + from ElementC14N import _serialize_c14n + _serialize["c14n"] = _serialize_c14n +except ImportError: + pass diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/xml/sax/saxutils.py --- a/Lib/xml/sax/saxutils.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/xml/sax/saxutils.py Fri Feb 01 23:12:09 2013 +0100 @@ -4,11 +4,18 @@ """ import os, urllib.parse, urllib.request -import io -import codecs from . import handler from . import xmlreader +# See whether the xmlcharrefreplace error handler is +# supported +try: + from codecs import xmlcharrefreplace_errors + _error_handling = "xmlcharrefreplace" + del xmlcharrefreplace_errors +except ImportError: + _error_handling = "strict" + def __dict_replace(s, d): """Replace substrings of a string using a dictionary.""" for key, value in d.items(): @@ -69,54 +76,14 @@ return data -def _gettextwriter(out, encoding): - if out is None: - import sys - return sys.stdout - - if isinstance(out, io.TextIOBase): - # use a text writer as is - return out - - if isinstance(out, (codecs.StreamWriter, codecs.StreamReaderWriter)): - # use a codecs stream writer as is - return out - - # wrap a binary writer with TextIOWrapper - if isinstance(out, io.RawIOBase): - # Keep the original file open when the TextIOWrapper is - # destroyed - class _wrapper: - __class__ = out.__class__ - def __getattr__(self, name): - return getattr(out, name) - buffer = _wrapper() - buffer.close = lambda: None - else: - # This is to handle passed objects that aren't in the - # IOBase hierarchy, but just have a write method - buffer = io.BufferedIOBase() - buffer.writable = lambda: True - buffer.write = out.write - try: - # TextIOWrapper uses this methods to determine - # if BOM (for UTF-16, etc) should be added - buffer.seekable = out.seekable - buffer.tell = out.tell - except AttributeError: - pass - return io.TextIOWrapper(buffer, encoding=encoding, - errors='xmlcharrefreplace', - newline='\n', - write_through=True) - class XMLGenerator(handler.ContentHandler): def __init__(self, out=None, encoding="iso-8859-1", short_empty_elements=False): + if out is None: + import sys + out = sys.stdout handler.ContentHandler.__init__(self) - out = _gettextwriter(out, encoding) - self._write = out.write - self._flush = out.flush + self._out = out self._ns_contexts = [{}] # contains uri -> prefix dicts self._current_context = self._ns_contexts[-1] self._undeclared_ns_maps = [] @@ -124,6 +91,12 @@ self._short_empty_elements = short_empty_elements self._pending_start_element = False + def _write(self, text): + if isinstance(text, str): + self._out.write(text) + else: + self._out.write(text.encode(self._encoding, _error_handling)) + def _qname(self, name): """Builds a qualified name from a (ns_url, localname) pair""" if name[0]: @@ -152,9 +125,6 @@ self._write('\n' % self._encoding) - def endDocument(self): - self._flush() - def startPrefixMapping(self, prefix, uri): self._ns_contexts.append(self._current_context.copy()) self._current_context[uri] = prefix @@ -187,9 +157,9 @@ for prefix, uri in self._undeclared_ns_maps: if prefix: - self._write(' xmlns:%s="%s"' % (prefix, uri)) + self._out.write(' xmlns:%s="%s"' % (prefix, uri)) else: - self._write(' xmlns="%s"' % uri) + self._out.write(' xmlns="%s"' % uri) self._undeclared_ns_maps = [] for (name, value) in attrs.items(): @@ -209,15 +179,11 @@ def characters(self, content): if content: self._finish_pending_start_element() - if not isinstance(content, str): - content = str(content, self._encoding) self._write(escape(content)) def ignorableWhitespace(self, content): if content: self._finish_pending_start_element() - if not isinstance(content, str): - content = str(content, self._encoding) self._write(content) def processingInstruction(self, target, data): diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/xmlrpc/server.py --- a/Lib/xmlrpc/server.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/xmlrpc/server.py Fri Feb 01 23:12:09 2013 +0100 @@ -587,10 +587,8 @@ # [Bug #1222790] If possible, set close-on-exec flag; if a # method spawns a subprocess, the subprocess shouldn't have # the listening socket open. - if fcntl is not None and hasattr(fcntl, 'FD_CLOEXEC'): - flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD) - flags |= fcntl.FD_CLOEXEC - fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags) + if hasattr(os, 'set_cloexec'): + os.set_cloexec(self.fileno()) class MultiPathXMLRPCServer(SimpleXMLRPCServer): """Multipath XML-RPC Server diff -r 35c88c53cf64 -r ecc10f0afb76 Lib/zipfile.py --- a/Lib/zipfile.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Lib/zipfile.py Fri Feb 01 23:12:09 2013 +0100 @@ -6,7 +6,7 @@ import io import os import re -import importlib.util +import imp import sys import time import stat @@ -196,8 +196,6 @@ return endrec data = fpin.read(sizeEndCentDir64Locator) - if len(data) != sizeEndCentDir64Locator: - return endrec sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data) if sig != stringEndArchive64Locator: return endrec @@ -208,8 +206,6 @@ # Assume no 'zip64 extensible data' fpin.seek(offset - sizeEndCentDir64Locator - sizeEndCentDir64, 2) data = fpin.read(sizeEndCentDir64) - if len(data) != sizeEndCentDir64: - return endrec sig, sz, create_version, read_version, disk_num, disk_dir, \ dircount, dircount2, dirsize, diroffset = \ struct.unpack(structEndArchive64, data) @@ -245,9 +241,7 @@ except OSError: return None data = fpin.read() - if (len(data) == sizeEndCentDir and - data[0:4] == stringEndArchive and - data[-2:] == b"\000\000"): + if data[0:4] == stringEndArchive and data[-2:] == b"\000\000": # the signature is correct and there's no comment, unpack structure endrec = struct.unpack(structEndArchive, data) endrec=list(endrec) @@ -271,9 +265,6 @@ if start >= 0: # found the magic number; attempt to unpack and interpret recData = data[start:start+sizeEndCentDir] - if len(recData) != sizeEndCentDir: - # Zip file is corrupted. - return None endrec = list(struct.unpack(structEndArchive, recData)) commentSize = endrec[_ECD_COMMENT_SIZE] #as claimed by the zip file comment = data[start+sizeEndCentDir:start+sizeEndCentDir+commentSize] @@ -285,7 +276,7 @@ endrec) # Unable to find a valid end of central directory structure - return None + return class ZipInfo (object): @@ -883,7 +874,6 @@ """ fp = None # Set here since __del__ checks it - _windows_illegal_name_trans_table = None def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False): """Open the ZIP file with mode read "r", write "w" or append "a".""" @@ -988,11 +978,9 @@ total = 0 while total < size_cd: centdir = fp.read(sizeCentralDir) - if len(centdir) != sizeCentralDir: - raise BadZipFile("Truncated central directory") + if centdir[0:4] != stringCentralDir: + raise BadZipFile("Bad magic number for central directory") centdir = struct.unpack(structCentralDir, centdir) - if centdir[_CD_SIGNATURE] != stringCentralDir: - raise BadZipFile("Bad magic number for central directory") if self.debug > 2: print(centdir) filename = fp.read(centdir[_CD_FILENAME_LENGTH]) @@ -1135,12 +1123,10 @@ # Skip the file header: fheader = zef_file.read(sizeFileHeader) - if len(fheader) != sizeFileHeader: - raise BadZipFile("Truncated file header") - fheader = struct.unpack(structFileHeader, fheader) - if fheader[_FH_SIGNATURE] != stringFileHeader: + if fheader[0:4] != stringFileHeader: raise BadZipFile("Bad magic number for file header") + fheader = struct.unpack(structFileHeader, fheader) fname = zef_file.read(fheader[_FH_FILENAME_LENGTH]) if fheader[_FH_EXTRA_FIELD_LENGTH]: zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH]) @@ -1224,42 +1210,23 @@ for zipinfo in members: self.extract(zipinfo, path, pwd) - @classmethod - def _sanitize_windows_name(cls, arcname, pathsep): - """Replace bad characters and remove trailing dots from parts.""" - table = cls._windows_illegal_name_trans_table - if not table: - illegal = ':<>|"?*' - table = str.maketrans(illegal, '_' * len(illegal)) - cls._windows_illegal_name_trans_table = table - arcname = arcname.translate(table) - # remove trailing dots - arcname = (x.rstrip('.') for x in arcname.split(pathsep)) - # rejoin, removing empty parts. - arcname = pathsep.join(x for x in arcname if x) - return arcname - def _extract_member(self, member, targetpath, pwd): """Extract the ZipInfo object 'member' to a physical file on the path targetpath. """ # build the destination pathname, replacing # forward slashes to platform specific separators. - arcname = member.filename.replace('/', os.path.sep) + # Strip trailing path separator, unless it represents the root. + if (targetpath[-1:] in (os.path.sep, os.path.altsep) + and len(os.path.splitdrive(targetpath)[1]) > 1): + targetpath = targetpath[:-1] - if os.path.altsep: - arcname = arcname.replace(os.path.altsep, os.path.sep) - # interpret absolute pathname as relative, remove drive letter or - # UNC path, redundant separators, "." and ".." components. - arcname = os.path.splitdrive(arcname)[1] - invalid_path_parts = ('', os.path.curdir, os.path.pardir) - arcname = os.path.sep.join(x for x in arcname.split(os.path.sep) - if x not in invalid_path_parts) - if os.path.sep == '\\': - # filter illegal characters on Windows - arcname = self._sanitize_windows_name(arcname, os.path.sep) + # don't include leading "/" from file name if present + if member.filename[0] == '/': + targetpath = os.path.join(targetpath, member.filename[1:]) + else: + targetpath = os.path.join(targetpath, member.filename) - targetpath = os.path.join(targetpath, arcname) targetpath = os.path.normpath(targetpath) # Create all upper directories if necessary. @@ -1637,7 +1604,7 @@ print("Compiling", file) try: py_compile.compile(file, doraise=True, optimize=optimize) - except py_compile.PyCompileError as err: + except py_compile.PyCompileError as error: print(err.msg) return False return True @@ -1645,8 +1612,8 @@ file_py = pathname + ".py" file_pyc = pathname + ".pyc" file_pyo = pathname + ".pyo" - pycache_pyc = importlib.util.cache_from_source(file_py, True) - pycache_pyo = importlib.util.cache_from_source(file_py, False) + pycache_pyc = imp.cache_from_source(file_py, True) + pycache_pyo = imp.cache_from_source(file_py, False) if self._optimize == -1: # legacy mode: use whatever file is present if (os.path.isfile(file_pyo) and diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/BuildScript/build-installer.py Fri Feb 01 23:12:09 2013 +0100 @@ -192,8 +192,7 @@ LT_10_5 = bool(DEPTARGET < '10.5') - if getVersionTuple() >= (3, 3): - result.extend([ + result.extend([ dict( name="XZ 5.0.3", url="http://tukaani.org/xz/xz-5.0.3.tar.gz", @@ -202,9 +201,6 @@ '--disable-dependency-tracking', ] ), - ]) - - result.extend([ dict( name="NCurses 5.9", url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz", diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/BuildScript/scripts/postflight.documentation --- a/Mac/BuildScript/scripts/postflight.documentation Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/BuildScript/scripts/postflight.documentation Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,7 @@ # make share/doc link in framework for command line users if [ -d "${SHARE_DIR}" ]; then - mkdir -m 775 -p "${SHARE_DOCDIR}" + mkdir -p "${SHARE_DOCDIR}" # make relative link to html doc directory ln -fhs "${SHARE_DOCDIR_TO_FWK}/${FWK_DOCDIR_SUBPATH}" "${SHARE_DOCDIR}/html" fi diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/IDLE/IDLE.app/Contents/Info.plist --- a/Mac/IDLE/IDLE.app/Contents/Info.plist Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/IDLE/IDLE.app/Contents/Info.plist Fri Feb 01 23:12:09 2013 +0100 @@ -53,7 +53,5 @@ ???? CFBundleVersion %version% - NSHighResolutionCapable - diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/FileSettings.h --- a/Mac/PythonLauncher/FileSettings.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/FileSettings.h Fri Feb 01 23:12:09 2013 +0100 @@ -45,13 +45,18 @@ + (id)getFactorySettingsForFileType: (NSString *)filetype; + (id)newSettingsForFileType: (NSString *)filetype; +//- (id)init; - (id)initForFileType: (NSString *)filetype; - (id)initForFSDefaultFileType: (NSString *)filetype; - (id)initForDefaultFileType: (NSString *)filetype; +//- (id)initWithFileSettings: (FileSettings *)source; - (void)updateFromSource: (id )source; - (NSString *)commandLineForScript: (NSString *)script; +//- (void)applyFactorySettingsForFileType: (NSString *)filetype; +//- (void)saveDefaults; +//- (void)applyUserDefaults: (NSString *)filetype; - (void)applyValuesFromDict: (NSDictionary *)dict; - (void)reset; - (NSArray *) interpreters; diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/FileSettings.m --- a/Mac/PythonLauncher/FileSettings.m Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/FileSettings.m Fri Feb 01 23:12:09 2013 +0100 @@ -14,7 +14,7 @@ { static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc; FileSettings **curdefault; - + if ([filetype isEqualToString: @"Python Script"]) { curdefault = &fsdefault_py; } else if ([filetype isEqualToString: @"Python GUI Script"]) { @@ -36,7 +36,7 @@ { static FileSettings *default_py, *default_pyw, *default_pyc; FileSettings **curdefault; - + if ([filetype isEqualToString: @"Python Script"]) { curdefault = &default_py; } else if ([filetype isEqualToString: @"Python GUI Script"]) { @@ -57,7 +57,7 @@ + (id)newSettingsForFileType: (NSString *)filetype { FileSettings *cur; - + cur = [FileSettings new]; [cur initForFileType: filetype]; return [cur retain]; @@ -67,7 +67,7 @@ { self = [super init]; if (!self) return self; - + interpreter = [source->interpreter retain]; honourhashbang = source->honourhashbang; debug = source->debug; @@ -81,30 +81,36 @@ with_terminal = source->with_terminal; prefskey = source->prefskey; if (prefskey) [prefskey retain]; - + return self; } - (id)initForFileType: (NSString *)filetype { FileSettings *defaults; - + defaults = [FileSettings getDefaultsForFileType: filetype]; self = [self initWithFileSettings: defaults]; origsource = [defaults retain]; return self; } +//- (id)init +//{ +// self = [self initForFileType: @"Python Script"]; +// return self; +//} + - (id)initForFSDefaultFileType: (NSString *)filetype { int i; NSString *filename; NSDictionary *dict; static NSDictionary *factorySettings; - + self = [super init]; if (!self) return self; - + if (factorySettings == NULL) { NSBundle *bdl = [NSBundle mainBundle]; NSString *path = [ bdl pathForResource: @"factorySettings" @@ -143,18 +149,18 @@ { NSUserDefaults *defaults; NSDictionary *dict; - + defaults = [NSUserDefaults standardUserDefaults]; dict = [defaults dictionaryForKey: filetype]; if (!dict) return; [self applyValuesFromDict: dict]; } - + - (id)initForDefaultFileType: (NSString *)filetype { FileSettings *fsdefaults; - + fsdefaults = [FileSettings getFactorySettingsForFileType: filetype]; self = [self initWithFileSettings: fsdefaults]; if (!self) return self; @@ -214,7 +220,7 @@ - (void)applyValuesFromDict: (NSDictionary *)dict { id value; - + value = [dict objectForKey: @"interpreter"]; if (value) interpreter = [value retain]; value = [dict objectForKey: @"honourhashbang"]; @@ -241,12 +247,12 @@ - (NSString*)_replaceSingleQuotes: (NSString*)string { - /* Replace all single-quotes by '"'"', that way shellquoting will - * be correct when the result value is delimited using single quotes. - */ - NSArray* components = [string componentsSeparatedByString:@"'"]; + /* Replace all single-quotes by '"'"', that way shellquoting will + * be correct when the result value is delimited using single quotes. + */ + NSArray* components = [string componentsSeparatedByString:@"'"]; - return [components componentsJoinedByString:@"'\"'\"'"]; + return [components componentsJoinedByString:@"'\"'\"'"]; } - (NSString *)commandLineForScript: (NSString *)script @@ -259,7 +265,7 @@ script_dir = [script substringToIndex: [script length]-[[script lastPathComponent] length]]; - + if (honourhashbang && (fp=fopen([script fileSystemRepresentation], "r")) && fgets(hashbangbuf, sizeof(hashbangbuf), fp) && @@ -272,7 +278,7 @@ } if (!cur_interp) cur_interp = interpreter; - + return [NSString stringWithFormat: @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s", [self _replaceSingleQuotes:script_dir], @@ -291,7 +297,7 @@ - (NSArray *) interpreters { return interpreters;}; -// FileSettingsSource protocol +// FileSettingsSource protocol - (NSString *) interpreter { return interpreter;}; - (BOOL) honourhashbang { return honourhashbang; }; - (BOOL) debug { return debug;}; diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/MyAppDelegate.m --- a/Mac/PythonLauncher/MyAppDelegate.m Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/MyAppDelegate.m Fri Feb 01 23:12:09 2013 +0100 @@ -33,7 +33,7 @@ - (BOOL)shouldShowUI { - // if this call comes before applicationDidFinishLaunching: we + // if this call comes before applicationDidFinishLaunching: we // should terminate immedeately after starting the script. if (!initial_action_done) should_terminate = YES; @@ -62,7 +62,7 @@ static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL}; NSString **ext_p; int i; - + if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"]) return; ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]]; @@ -92,5 +92,5 @@ } } } - + @end diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/MyDocument.m --- a/Mac/PythonLauncher/MyDocument.m Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/MyDocument.m Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,7 @@ { self = [super init]; if (self) { - + // Add your subclass-specific initialization here. // If an error occurs here, send a [self dealloc] message and return nil. script = [@".py" retain]; @@ -37,17 +37,20 @@ { NSApplication *app = [NSApplication sharedApplication]; [super close]; - if ([(MyAppDelegate*)[app delegate] shouldTerminate]) + if ([[app delegate] shouldTerminate]) [app terminate: self]; } - (void)load_defaults { +// if (settings) [settings release]; settings = [FileSettings newSettingsForFileType: filetype]; } - (void)update_display { +// [[self window] setTitle: script]; + [interpreter setStringValue: [settings interpreter]]; [honourhashbang setState: [settings honourhashbang]]; [debug setState: [settings debug]]; @@ -59,7 +62,7 @@ [others setStringValue: [settings others]]; [scriptargs setStringValue: [settings scriptargs]]; [with_terminal setState: [settings with_terminal]]; - + [commandline setStringValue: [settings commandLineForScript: script]]; } @@ -72,8 +75,8 @@ { const char *cmdline; int sts; - - cmdline = [[settings commandLineForScript: script] UTF8String]; + + cmdline = [[settings commandLineForScript: script] cString]; if ([settings with_terminal]) { sts = doscript(cmdline); } else { @@ -104,13 +107,14 @@ { // Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead. BOOL show_ui; - - // ask the app delegate whether we should show the UI or not. - show_ui = [(MyAppDelegate*)[[NSApplication sharedApplication] delegate] shouldShowUI]; + + // ask the app delegate whether we should show the UI or not. + show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI]; [script release]; script = [fileName retain]; [filetype release]; filetype = [type retain]; +// if (settings) [settings release]; settings = [FileSettings newSettingsForFileType: filetype]; if (show_ui) { [self update_display]; @@ -148,7 +152,7 @@ [self update_display]; } -// FileSettingsSource protocol +// FileSettingsSource protocol - (NSString *) interpreter { return [interpreter stringValue];}; - (BOOL) honourhashbang { return [honourhashbang state];}; - (BOOL) debug { return [debug state];}; diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/PreferencesWindowController.m --- a/Mac/PythonLauncher/PreferencesWindowController.m Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/PreferencesWindowController.m Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,7 @@ + getPreferencesWindow { static PreferencesWindowController *_singleton; - + if (!_singleton) _singleton = [[PreferencesWindowController alloc] init]; [_singleton showWindow: _singleton]; @@ -21,13 +21,15 @@ - (void)load_defaults { NSString *title = [filetype titleOfSelectedItem]; - + settings = [FileSettings getDefaultsForFileType: title]; } - (void)update_display { - [interpreter reloadData]; +// [[self window] setTitle: script]; + + [interpreter reloadData]; [interpreter setStringValue: [settings interpreter]]; [honourhashbang setState: [settings honourhashbang]]; [debug setState: [settings debug]]; @@ -39,6 +41,7 @@ [others setStringValue: [settings others]]; [with_terminal setState: [settings with_terminal]]; // Not scriptargs, it isn't for preferences + [commandline setStringValue: [settings commandLineForScript: @""]]; } @@ -72,7 +75,7 @@ [self update_display]; } -// FileSettingsSource protocol +// FileSettingsSource protocol - (NSString *) interpreter { return [interpreter stringValue];}; - (BOOL) honourhashbang { return [honourhashbang state]; }; - (BOOL) debug { return [debug state];}; diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/doscript.h --- a/Mac/PythonLauncher/doscript.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/doscript.h Fri Feb 01 23:12:09 2013 +0100 @@ -9,4 +9,4 @@ #include -extern int doscript(const char *command); +extern int doscript(const char *command); \ No newline at end of file diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/doscript.m --- a/Mac/PythonLauncher/doscript.m Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/doscript.m Fri Feb 01 23:12:09 2013 +0100 @@ -11,49 +11,49 @@ #import #import "doscript.h" -extern int +extern int doscript(const char *command) { - char *bundleID = "com.apple.Terminal"; - AppleEvent evt, res; - AEDesc desc; - OSStatus err; + char *bundleID = "com.apple.Terminal"; + AppleEvent evt, res; + AEDesc desc; + OSStatus err; - [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"]; + [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"]; - // Build event - err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript, - typeApplicationBundleID, - bundleID, strlen(bundleID), - kAutoGenerateReturnID, - kAnyTransactionID, - &evt, NULL, - "'----':utf8(@)", strlen(command), - command); - if (err) { - NSLog(@"AEBuildAppleEvent failed: %ld\n", (long)err); - return err; - } + // Build event + err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript, + typeApplicationBundleID, + bundleID, strlen(bundleID), + kAutoGenerateReturnID, + kAnyTransactionID, + &evt, NULL, + "'----':utf8(@)", strlen(command), + command); + if (err) { + NSLog(@"AEBuildAppleEvent failed: %d\n", err); + return err; + } - // Send event and check for any Apple Event Manager errors - err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout); - AEDisposeDesc(&evt); - if (err) { - NSLog(@"AESendMessage failed: %ld\n", (long)err); - return err; - } - // Check for any application errors - err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc); - AEDisposeDesc(&res); - if (!err) { - AEGetDescData(&desc, &err, sizeof(err)); - NSLog(@"Terminal returned an error: %ld", (long)err); - AEDisposeDesc(&desc); - } else if (err == errAEDescNotFound) { - err = noErr; - } else { - NSLog(@"AEGetPArmDesc returned an error: %ld", (long)err); - } + // Send event and check for any Apple Event Manager errors + err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout); + AEDisposeDesc(&evt); + if (err) { + NSLog(@"AESendMessage failed: %d\n", err); + return err; + } + // Check for any application errors + err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc); + AEDisposeDesc(&res); + if (!err) { + AEGetDescData(&desc, &err, sizeof(err)); + NSLog(@"Terminal returned an error: %d", err); + AEDisposeDesc(&desc); + } else if (err == errAEDescNotFound) { + err = noErr; + } else { + NSLog(@"AEGetPArmDesc returned an error: %d", err); + } - return err; + return err; } diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/PythonLauncher/main.m --- a/Mac/PythonLauncher/main.m Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/PythonLauncher/main.m Fri Feb 01 23:12:09 2013 +0100 @@ -11,7 +11,7 @@ int main(int argc, const char *argv[]) { - char *home = getenv("HOME"); - if (home) chdir(home); + char *home = getenv("HOME"); + if (home) chdir(home); return NSApplicationMain(argc, argv); } diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/README --- a/Mac/README Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/README Fri Feb 01 23:12:09 2013 +0100 @@ -37,7 +37,7 @@ * ``--enable-universalsdk[=PATH]`` - Create a universal binary build of Python. This can be used with both + Create a universal binary build of of Python. This can be used with both regular and framework builds. The optional argument specifies which OS X SDK should be used to perform the diff -r 35c88c53cf64 -r ecc10f0afb76 Mac/Resources/app/Info.plist.in --- a/Mac/Resources/app/Info.plist.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Mac/Resources/app/Info.plist.in Fri Feb 01 23:12:09 2013 +0100 @@ -56,7 +56,5 @@ NSHumanReadableCopyright (c) 2013 Python Software Foundation. - NSHighResolutionCapable - diff -r 35c88c53cf64 -r ecc10f0afb76 Makefile.pre.in --- a/Makefile.pre.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Makefile.pre.in Fri Feb 01 23:12:09 2013 +0100 @@ -97,9 +97,6 @@ # Machine-dependent subdirectories MACHDEP= @MACHDEP@ -# Multiarch directory (may be empty) -MULTIARCH= @MULTIARCH@ - # Install prefix for architecture-independent files prefix= @prefix@ @@ -125,8 +122,7 @@ CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(LDVERSION) # Symbols used for using shared libraries -SHLIB_SUFFIX= @SHLIB_SUFFIX@ -EXT_SUFFIX= @EXT_SUFFIX@ +SO= @SO@ LDSHARED= @LDSHARED@ $(PY_LDFLAGS) BLDSHARED= @BLDSHARED@ $(PY_LDFLAGS) LDCXXSHARED= @LDCXXSHARED@ @@ -204,8 +200,7 @@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ -BUILD_GNU_TYPE= @build@ -HOST_GNU_TYPE= @host@ +HOST_GNU_TYPE= @host@ # The task to run while instrument when building the profile-opt target PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck @@ -439,7 +434,7 @@ # Default target all: build_all -build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed python-config +build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed # Compile a binary with gcc profile guided optimization. profile-opt: @@ -640,24 +635,11 @@ Modules/_testembed.o: $(srcdir)/Modules/_testembed.c $(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Modules/_testembed.c -Modules/posixmodule.o: $(srcdir)/Modules/posixmodule.c $(srcdir)/Modules/posixmodule.h - -Modules/grpmodule.o: $(srcdir)/Modules/grpmodule.c $(srcdir)/Modules/posixmodule.h - -Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h - -Modules/signalmodule.o: $(srcdir)/Modules/signalmodule.c $(srcdir)/Modules/posixmodule.h - Python/dynload_shlib.o: $(srcdir)/Python/dynload_shlib.c Makefile $(CC) -c $(PY_CORE_CFLAGS) \ -DSOABI='"$(SOABI)"' \ -o $@ $(srcdir)/Python/dynload_shlib.c -Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile - $(CC) -c $(PY_CORE_CFLAGS) \ - -DSHLIB_EXT='"$(EXT_SUFFIX)"' \ - -o $@ $(srcdir)/Python/dynload_hpux.c - Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(CC) -c $(PY_CORE_CFLAGS) \ -DABIFLAGS='"$(ABIFLAGS)"' \ @@ -726,7 +708,6 @@ $(srcdir)/Objects/stringlib/find_max_char.h \ $(srcdir)/Objects/stringlib/localeutil.h \ $(srcdir)/Objects/stringlib/partition.h \ - $(srcdir)/Objects/stringlib/replace.h \ $(srcdir)/Objects/stringlib/split.h \ $(srcdir)/Objects/stringlib/ucs1lib.h \ $(srcdir)/Objects/stringlib/ucs2lib.h \ @@ -901,10 +882,10 @@ $(TESTRUNNER) $(QUICKTESTOPTS) -install: altinstall bininstall maninstall +install: altinstall bininstall altinstall: @FRAMEWORKALTINSTALLFIRST@ altbininstall libinstall inclinstall libainstall \ - sharedinstall oldsharedinstall altmaninstall @FRAMEWORKALTINSTALLLAST@ + sharedinstall oldsharedinstall maninstall @FRAMEWORKALTINSTALLLAST@ # Install shared libraries enabled by Setup DESTDIRS= $(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED) @@ -945,7 +926,7 @@ fi; \ (cd $(DESTDIR)$(BINDIR); $(LN) python$(LDVERSION)$(EXE) python$(VERSION)$(EXE)); \ fi - if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \ + if test -f $(LDLIBRARY); then \ if test -n "$(DLLLIBRARY)" ; then \ $(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \ else \ @@ -985,8 +966,8 @@ -rm -f $(DESTDIR)$(BINDIR)/pyvenv (cd $(DESTDIR)$(BINDIR); $(LN) -s pyvenv-$(VERSION) pyvenv) -# Install the versioned manual page -altmaninstall: +# Install the manual page +maninstall: @for i in $(MANDIR) $(MANDIR)/man1; \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -998,11 +979,6 @@ $(INSTALL_DATA) $(srcdir)/Misc/python.man \ $(DESTDIR)$(MANDIR)/man1/python$(VERSION).1 -# Install the unversioned manual page -maninstall: altmaninstall - -rm -f $(DESTDIR)$(MANDIR)/man1/python3.1 - (cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python$(VERSION).1 python3.1) - # Install the library PLATDIR= plat-$(MACHDEP) EXTRAPLATDIR= @EXTRAPLATDIR@ @@ -1143,21 +1119,12 @@ export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \ export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \ export EXE; EXE="$(BUILDEXE)"; \ - if [ -n "$(MULTIARCH)" ]; then export MULTIARCH; MULTIARCH=$(MULTIARCH); fi; \ - export PYTHON_FOR_BUILD; \ - if [ "$(BUILD_GNU_TYPE)" = "$(HOST_GNU_TYPE)" ]; then \ - PYTHON_FOR_BUILD="$(BUILDPYTHON)"; \ - else \ - PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)"; \ - fi; \ cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen -python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh +python-config: $(srcdir)/Misc/python-config.in # Substitution happens here, as the completely-expanded BINDIR # is not available in configure - sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py - # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR} - sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config + sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config # Install the include files INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY) @@ -1195,7 +1162,7 @@ done @if test -d $(LIBRARY); then :; else \ if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \ - if test "$(SHLIB_SUFFIX)" = .dll; then \ + if test "$(SO)" = .dll; then \ $(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \ else \ $(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \ @@ -1215,8 +1182,8 @@ $(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc $(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup $(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh - $(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py $(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config + rm python-config @if [ -s Modules/python.exp -a \ "`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \ echo; echo "Installing support files for building shared extension modules on AIX:"; \ @@ -1287,12 +1254,12 @@ # Install a number of symlinks to keep software that expects a normal unix # install (which includes python-config) happy. frameworkinstallmaclib: - $(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(LDVERSION).a" - $(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(LDVERSION).dylib" - $(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(VERSION).a" - $(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(VERSION).dylib" - $(LN) -fs "../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib" - $(LN) -fs "../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/libpython$(VERSION).dylib" + ln -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(LDVERSION).a" + ln -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(LDVERSION).dylib" + ln -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(VERSION).a" + ln -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/python$(VERSION)/config-$(LDVERSION)/libpython$(VERSION).dylib" + ln -fs "../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib" + ln -fs "../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/libpython$(VERSION).dylib" # This installs the IDE, the Launcher and other apps into /Applications frameworkinstallapps: @@ -1403,7 +1370,6 @@ config.cache config.log pyconfig.h Modules/config.c -rm -rf build platform -rm -rf $(PYTHONFRAMEWORKDIR) - -rm -f python-config.py python-config # Make things extra clean, before making a distribution: # remove all generated files, even Makefile[.pre] @@ -1416,11 +1382,11 @@ Modules/Setup Modules/Setup.local Modules/Setup.config \ Modules/ld_so_aix Modules/python.exp Misc/python.pc -rm -f python*-gdb.py - find $(srcdir)/[a-zA-Z]* '(' -name '*.fdc' -o -name '*~' \ - -o -name '[@,#]*' -o -name '*.old' \ - -o -name '*.orig' -o -name '*.rej' \ - -o -name '*.bak' ')' \ - -exec rm -f {} ';' + find $(srcdir) '(' -name '*.fdc' -o -name '*~' \ + -o -name '[@,#]*' -o -name '*.old' \ + -o -name '*.orig' -o -name '*.rej' \ + -o -name '*.bak' ')' \ + -exec rm -f {} ';' # Check for smelly exported symbols (not starting with Py/_Py) smelly: all @@ -1475,7 +1441,7 @@ .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools .PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean -.PHONY: smelly funny patchcheck touch altmaninstall +.PHONY: smelly funny patchcheck touch .PHONY: gdbhooks # IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/ACKS --- a/Misc/ACKS Fri Jul 26 23:14:22 2013 -0700 +++ b/Misc/ACKS Fri Feb 01 23:12:09 2013 +0100 @@ -41,13 +41,10 @@ Ross Andrus Juancarlo Añez Jérémy Anger -Ankur Ankan Jon Anglin Heidi Annexstad -Ramchandra Apte Éric Araujo Alicia Arlen -Jeffrey Armstrong Jason Asbahr David Ascher Chris AtLee @@ -56,7 +53,6 @@ Donovan Baarda Arne Babenhauserheide Attila Babo -Matt Bachmann Marcin Bachry Alfonso Baciero Dwayne Bailey @@ -66,7 +62,6 @@ Jeff Balogh Manuel Balsera Matt Bandy -Dmi Baranov Michael J. Barber Daniel Barclay Nicolas Bareil @@ -119,7 +114,6 @@ David Binger Dominic Binks Philippe Biondi -Michael Birtwell Stuart Bishop Roy Bixler Daniel Black @@ -139,7 +133,6 @@ Forest Bond Gregory Bond Matias Bordese -Jonas Borgström Jurjen Bos Peter Bosch Dan Boswell @@ -153,10 +146,8 @@ Georg Brandl Christopher Brannon Terrence Brannon -Sven Brauch Erik Bray Brian Brazil -Demian Brecht Dave Brennan Tom Bridgman Anthony Briggs @@ -173,15 +164,12 @@ Francisco Martín Brugué Ian Bruntlett Floris Bruynooghe -Matt Bryant Stan Bubrouski Erik de Bueger Jan-Hein Bührman -Lars Buitinck Dick Bulterman Bill Bumgarner Jimmy Burgett -Edmond Burnett Tommy Burnette Roger Burnham Alastair Burt @@ -197,7 +185,6 @@ Mike Carlton Pierre Carrier Terry Carroll -Edward Catmur Lorenzo M. Catucci Donn Cave Charles Cazabon @@ -214,12 +201,10 @@ Brad Chapman Greg Chapman Mitch Chapman -Yogesh Chaudhari David Chaum Nicolas Chauvat Jerry Chen Michael Chermside -Ingrid Cheung Albert Chin-A-Young Adal Chiriliuc Matt Chisholm @@ -249,7 +234,6 @@ Christophe Combelles Geremy Condra Denver Coneybeare -Phil Connell Juan José Conti Matt Conway David M. Cooke @@ -338,7 +322,6 @@ Walter Dörwald Hans Eckardt Rodolpho Eckhardt -David Edelsohn John Edmonds Grant Edwards John Ehresman @@ -348,12 +331,10 @@ Julien Élie Lance Ellinghaus Daniel Ellis -Phil Elson David Ely Jeff Epler Jeff McNeil Tom Epperly -Gökcen Eraslan Stoffel Erasmus Jürgen A. Erhard Michael Ernst @@ -378,7 +359,6 @@ Troy J. Farrell Mark Favas Boris Feld -Thomas Fenzl Niels Ferguson Sebastian Fernandez Florian Festi @@ -444,7 +424,6 @@ Michael Gilfix Yannick Gingras Matt Giuca -Wim Glenn Michael Goderbauer Christoph Gohlke Tim Golden @@ -464,7 +443,6 @@ Dag Gruneau Filip GruszczyÅ„ski Thomas Guettler -Anuj Gupta Michael Guravage Lars Gustäbel Thomas Güttler @@ -475,7 +453,6 @@ Rasmus Hahn Peter Haight Václav Haisman -Zbigniew Halas Walker Hale IV Bob Halley Jesse Hallio @@ -501,7 +478,6 @@ Rycharde Hawkes Ben Hayden Jochen Hayek -Henrik Heimbuerger Christian Heimes Thomas Heller Malte Helmert @@ -514,7 +490,6 @@ Ivan Herman Jürgen Hermann Gary Herron -Ernie Hershey Thomas Herve Bernhard Herzog Magnus L. Hetland @@ -580,7 +555,6 @@ Adam Jackson Ben Jackson Paul Jackson -Manuel Jacob David Jacobs Kevin Jacobs Kjetil Jacobsen @@ -590,7 +564,6 @@ Bill Janssen Thomas Jarosch Juhana Jauhiainen -Rajagopalasarma Jayakrishnan Zbigniew JÄ™drzejewski-Szmek Julien Jehannet Drew Jenkins @@ -605,7 +578,6 @@ Fredrik Johansson Gregory K. Johnson Kent Johnson -Michael Johnson Simon Johnston Matt Joiner Thomas Jollans @@ -622,7 +594,6 @@ Sijin Joseph Andreas Jung Tattoo Mabonzo K. -Sarah K. Bohuslav Kabrda Alexey Kachayev Bob Kahn @@ -668,11 +639,9 @@ Lenny Kneler Pat Knight Jeff Knupp -Kubilay Kocak Greg Kochanski Damon Kohler Marko Kohtala -Vajrasky Kok Guido Kollerie Jacek Konieczny Марк Коренберг @@ -702,7 +671,6 @@ Erno Kuusela Ross Lagerwall Cameron Laird -David Lam Thomas Lamb Jean-Baptiste "Jiba" Lamy Ronan Lamy @@ -738,12 +706,10 @@ Tshepang Lekhonkhobe Marc-André Lemburg John Lenton -Kostyantyn Leschenko Benno Leslie Christopher Tur Lesniewski-Laas Alain Leufroy Mark Levinson -Mark Levitt William Lewis Akira Li Xuanji Li @@ -767,7 +733,6 @@ Anne Lord Tom Loredo Justin Love -Ned Jackson Lovely Jason Lowe Tony Lownds Ray Loyzaga @@ -786,11 +751,9 @@ Tim MacKenzie Nick Maclaren Don MacMillen -Tomasz Maćkowiak Steve Majewski Grzegorz Makarewicz David Malcolm -Greg Malcolm Ken Manheimer Vladimir Marangozov Colin Marc @@ -811,7 +774,6 @@ Graham Matthews Dieter Maurer Daniel May -Madison May Lucas Maystre Arnaud Mazin Rebecca McCreary @@ -819,9 +781,7 @@ Chris McDonough Greg McFarlane Alan McIntyre -Jessica McKellar Michael McLay -Brendan McLoughlin Mark Mc Mahon Gordon McMillan Andrew McNamara @@ -841,10 +801,8 @@ Alexis Métaireau Steven Miale Trent Mick -Jason Michalski Franck Michea Tom Middleton -Thomas Miedema Stan Mihai Stefan Mihaila Aristotelis Mikropoulos @@ -866,16 +824,13 @@ Peter Moody Paul Moore Ross Moore -Ben Morgan Derek Morr James A Morrison -Martin Morrison Derek McTavish Mounce Alessandro Moura Pablo Mouzo Mher Movsisyan Ruslan Mstoi -Valentina Mukhamedzhanova Michael Mulich Sape Mullender Sjoerd Mullender @@ -884,7 +839,6 @@ Louis Munro R. David Murray Matti Mäki -Jörg Müller Dale Nagata John Nagle Takahiro Nakayama @@ -919,9 +873,7 @@ Kevin O'Connor Tim O'Malley Zooko O'Whielacronx -Aaron Oakley James Oakley -Elena Oat Jon Oberheide Pascal Oberndoerfer Jeffrey Ollie @@ -953,7 +905,6 @@ Alexandre Parenteau Dan Parisien William Park -Heikki Partanen Harri Pasanen Gaël Pasgrimaud Ashish Nitin Patil @@ -962,7 +913,6 @@ Justin Peel Marcel van der Peijl Berker Peksag -Andreas Pelme Steven Pemberton Bo Peng Santiago Peresón @@ -975,7 +925,6 @@ Benjamin Peterson Joe Peterson Chris Petrilli -Roumen Petrov Bjorn Pettersen Justin D. Pettit Ronny Pfannschmidt @@ -989,7 +938,6 @@ Martijn Pieters Anand B. Pillai François Pinard -Tom Pinckney Zach Pincus Michael Piotrowski Antoine Pitrou @@ -998,7 +946,6 @@ Remi Pointel Ariel Poliak Guilherme Polo -Illia Polosukhin Michael Pomraning Iustin Pop Claudiu Popa @@ -1016,13 +963,10 @@ Pierre Quentel Brian Quinlan Anders Qvist -Thomas Rachel -Ram Rachum Jérôme Radix Burton Radons Jeff Ramnani Brodie Rao -Senko Rasic Antti Rasinen Sridhar Ratnakumar Ysj Ray @@ -1054,7 +998,6 @@ Jean-Claude Rimbault Vlad Riscutia Wes Rishel -Daniel Riti Juan M. Bello Rivas Davide Rizzo Anthony Roach @@ -1107,7 +1050,6 @@ Adrian Sampson James Sanders Ilya Sandler -Rafael Santos Mark Sapiro Ty Sarna Hugh Sasse @@ -1163,7 +1105,6 @@ Joel Shprentz Itamar Shtull-Trauring Yue Shuaijie -Terrel Shumway Eric Siegerman Paul Sijben SilentGhost @@ -1172,7 +1113,6 @@ Ionel Simionescu Kirill Simonov Nathan Paul Simons -Guilherme Simões Adam Simpkins Ravi Sinha Janne Sinkkonen @@ -1181,7 +1121,6 @@ J. Sipprell Kragen Sitaker Michael Sloan -Nick Sloan Václav Å milauer Christopher Smith Eric V. Smith @@ -1234,9 +1173,7 @@ Paul Swartz Thenault Sylvain Péter Szabó -Amir Szekely Arfrever Frehtes Taifersar Arahesis -Hideaki Takahashi Neil Tallim Geoff Talvola Musashi Tamura @@ -1247,11 +1184,8 @@ Monty Taylor Anatoly Techtonik Mikhail Terekhov -Victor Terrón Richard M. Tew Tobias Thelen -Févry Thibault -Lowe Thiderman Nicolas M. Thiéry James Thomas Robin Thomas @@ -1281,7 +1215,6 @@ Matthias Troffaes Tom Tromey John Tromp -Diane Trout Jason Trowbridge Brent Tubbs Anthony Tuininga @@ -1304,7 +1237,6 @@ Andrew Vant Atul Varma Dmitry Vasiliev -Sebastian Ortiz Vasquez Alexandre Vassalotti Nadeem Vawda Frank Vercruesse @@ -1314,7 +1246,6 @@ Al Vezza Jacques A. Vidrine John Viega -Dino Viehland Kannan Vijayan Kurt Vile Norman Vine @@ -1330,10 +1261,8 @@ Larry Wall Kevin Walzer Rodrigo Steinmuller Wanderley -Ke Wang Greg Ward Zachary Ware -Jonas Wagner Barry Warsaw Steve Waterbury Bob Watson @@ -1342,7 +1271,6 @@ Henrik Weber Corran Webster Glyn Webster -Phil Webster Stefan Wehr Zack Weinberg Bob Weiner @@ -1366,7 +1294,6 @@ Sue Williams Steven Willis Frank Willison -Geoff Wilson Greg V. Wilson J Derek Wilson Paul Winkler @@ -1389,7 +1316,6 @@ Gordon Worley Darren Worrall Thomas Wouters -Daniel Wozniak Heiko Wundram Doug Wyatt Robert Xiao @@ -1402,7 +1328,6 @@ Danny Yoo Rory Yorke George Yoshida -Kazuhiro Yoshida Masazumi Yoshikawa Arnaud Ysmal Bernard Yue @@ -1410,9 +1335,7 @@ Milan Zamazal Artur Zaprzala Mike Zarnstorff -Yury V. Zaytsev Siebren van der Zee -Nickolai Zeldovich Yuxiao Zeng Uwe Zessin Cheng Zhang diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/HISTORY --- a/Misc/HISTORY Fri Jul 26 23:14:22 2013 -0700 +++ b/Misc/HISTORY Fri Feb 01 23:12:09 2013 +0100 @@ -778,7 +778,7 @@ - Issue #14626: Large refactoring of functions / parameters in the os module. Many functions now support "dir_fd" and "follow_symlinks" parameters; - some also support accepting an open file descriptor in place of a path + some also support accepting an open file descriptor in place of of a path string. Added os.support_* collections as LBYL helpers. Removed many functions only previously seen in 3.3 alpha releases (often starting with "f" or "l", or ending with "at"). Originally suggested by Serhiy Storchaka; @@ -1412,7 +1412,7 @@ - Issue #14399: zipfile now recognizes that the archive has been modified even if only the comment is changed. In addition, the TypeError that results from - trying to set a non-binary value as a comment is now raised at the time + trying to set a non-binary value as a comment is now now raised at the time the comment is set rather than at the time the zipfile is written. - trace.CoverageResults.is_ignored_filename() now ignores any name that starts @@ -3052,7 +3052,7 @@ check or set the MACOSX_DEPLOYMENT_TARGET environment variable for the interpreter process. This could cause failures in non-Distutils subprocesses and was unreliable since tests or user programs could modify the interpreter - environment after Distutils set it. Instead, have Distutils set the + environment after Distutils set it. Instead, have Distutils set the the deployment target only in the environment of each build subprocess. It is still possible to globally override the default by setting MACOSX_DEPLOYMENT_TARGET before launching the interpreter; its value must be diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/NEWS --- a/Misc/NEWS Fri Jul 26 23:14:22 2013 -0700 +++ b/Misc/NEWS Fri Feb 01 23:12:09 2013 +0100 @@ -5,793 +5,12 @@ What's New in Python 3.4.0 Alpha 1? =================================== -*Relase date: 2014-XX-XX* +*Relase date: XX-XXX-2014* Core and Builtins ----------------- -- Issue #18552: Check return value of PyArena_AddPyObject() in - obj2ast_object(). - -- Issue #18560: Fix potential NULL pointer dereference in sum(). - -- Issue #18520: Add a new PyStructSequence_InitType2() function, same than - PyStructSequence_InitType() except that it has a return value (0 on success, - -1 on error). - -- Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0], - prefix and exec_prefix if the operation system does not obey MAXPATHLEN. - -- Issue #18408: Fix many various bugs in code handling errors, especially - on memory allocation failure (MemoryError). - -- Issue #18344: Fix potential ref-leaks in _bufferedreader_read_all(). - -- Issue #18342: Use the repr of a module name when an import fails when using - ``from ... import ...``. - -- Issue #17872: Fix a segfault in marshal.load() when input stream returns - more bytes than requested. - -- Issue #18338: `python --version` now prints version string to stdout, and - not to stderr. Patch by Berker Peksag and Michael Dickens. - -- Issue #18426: Fix NULL pointer dereference in C extension import when - PyModule_GetDef() returns an error. - -- Issue #17206: On Windows, increase the stack size from 2 MB to 4.2 MB to fix - a stack overflow in the marshal module (fix a crash in test_marshal). - Patch written by Jeremy Kloth. - -- Issue #3329: Implement the PEP 445: Add new APIs to customize Python memory - allocators. - -- Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the - tstate is first removed from TLS and then deallocated. - -- Issue #13483: Use VirtualAlloc in obmalloc on Windows. - -- Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise - OverflowError when an argument of %c format is out of range. - -- Issue #18111: The min() and max() functions now support a default argument - to be returned instead of raising a ValueError on an empty sequence. - (Contributed by Julian Berman.) - -- Issue #18137: Detect integer overflow on precision in float.__format__() - and complex.__format__(). - -- Issue #18183: Fix various unicode operations on strings with large unicode - codepoints. - -- Issue #18180: Fix ref leak in _PyImport_GetDynLoadWindows(). - -- Issue #18038: SyntaxError raised during compilation sources with illegal - encoding now always contains an encoding name. - -- Issue #17931: Resolve confusion on Windows between pids and process - handles. - -- Tweak the exception message when the magic number or size value in a bytecode - file is truncated. - -- Issue #17932: Fix an integer overflow issue on Windows 64-bit in iterators: - change the C type of seqiterobject.it_index from long to Py_ssize_t. - -- Issue #18065: Don't set __path__ to the package name for frozen packages. - -- Issue #18088: When reloading a module, unconditionally reset all relevant - attributes on the module (e.g. __name__, __loader__, __package__, __file__, - __cached__). - -- Issue #17937: Try harder to collect cyclic garbage at shutdown. - -- Issue #12370: Prevent class bodies from interfering with the __class__ - closure. - -- Issue #17644: Fix a crash in str.format when curly braces are used in square - brackets. - -- Issue #17237: Fix crash in the ASCII decoder on m68k. - -- Issue #17927: Frame objects kept arguments alive if they had been - copied into a cell, even if the cell was cleared. - -- Issue #1545463: At shutdown, defer finalization of codec modules so - that stderr remains usable. - -- Issue #7330: Implement width and precision (ex: "%5.3s") for the format - string of PyUnicode_FromFormat() function, original patch written by Ysj Ray. - -- Issue #1545463: Global variables caught in reference cycles are now - garbage-collected at shutdown. - -- Issue #17094: Clear stale thread states after fork(). Note that this - is a potentially disruptive change since it may release some system - resources which would otherwise remain perpetually alive (e.g. database - connections kept in thread-local storage). - -- Issue #17408: Avoid using an obsolete instance of the copyreg module when - the interpreter is shutdown and then started again. - -- Issue #5845: Enable tab-completion in the interactive interpreter by - default, thanks to a new sys.__interactivehook__. - -- Issue #17115,17116: Module initialization now includes setting __package__ and - __loader__ attributes to None. - -- Issue #17853: Ensure locals of a class that shadow free variables always win - over the closures. - -- Issue #17863: In the interactive console, don't loop forever if the encoding - can't be fetched from stdin. - -- Issue #17867: Raise an ImportError if __import__ is not found in __builtins__. - -- Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3, - such as was shipped with Centos 5 and Mac OS X 10.4. - -- Issue #17413: sys.settrace callbacks were being passed a string instead of an - exception instance for the 'value' element of the arg tuple if the exception - originated from C code; now an exception instance is always provided. - -- Issue #17782: Fix undefined behaviour on platforms where - ``struct timespec``'s "tv_nsec" member is not a C long. - -- Issue #17722: When looking up __round__, resolve descriptors. - -- Issue #16061: Speed up str.replace() for replacing 1-character strings. - -- Issue #17715: Fix segmentation fault from raising an exception in a __trunc__ - method. - -- Issue #17643: Add __callback__ attribute to weakref.ref. - -- Issue #16447: Fixed potential segmentation fault when setting __name__ on a - class. - -- Issue #17669: Fix crash involving finalization of generators using yield from. - -- Issue #14439: Python now prints the traceback on runpy failure at startup. - - -- Issue #17469: Fix _Py_GetAllocatedBlocks() and sys.getallocatedblocks() - when running on valgrind. - -- Issue #17619: Make input() check for Ctrl-C correctly on Windows. - -- Issue #17357: Add missing verbosity messages for -v/-vv that were lost during - the importlib transition. - -- Issue #17610: Don't rely on non-standard behavior of the C qsort() function. - -- Issue #17323: The "[X refs, Y blocks]" printed by debug builds has been - disabled by default. It can be re-enabled with the `-X showrefcount` option. - -Library -------- - -- Issue #18561: Skip name in ctypes' _build_callargs() if name is NULL. - -- Issue #18559: Fix NULL pointer dereference error in _pickle module - -- Issue #18556: Check the return type of PyUnicode_AsWideChar() in ctype's - U_set(). - -- Issue #17818: aifc.getparams now returns a namedtuple. - -- Issue #18549: Eliminate dead code in socket_ntohl() - -- Issue #18530: Remove additional stat call from posixpath.ismount. - Patch by Alex Gaynor. - -- Issue #18514: Fix unreachable Py_DECREF() call in PyCData_FromBaseObj() - -- Issue #9177: Calling read() or write() now raises ValueError, not - AttributeError, on a closed SSL socket. Patch by Senko Rasic. - -- Issue #18513: Fix behaviour of cmath.rect w.r.t. signed zeros on OS X 10.8 + - gcc. - -- Issue #18479: Changed venv Activate.ps1 to make deactivate a function, and - removed Deactivate.ps1. - -- Issue #18480: Add missing call to PyType_Ready to the _elementtree extension. - -- Issue #17778: Fix test discovery for test_multiprocessing. (Patch by - Zachary Ware.) - -- Issue #18393: The private module _gestalt and private functions - platform._mac_ver_gestalt, platform._mac_ver_lookup and - platform._bcd2str have been removed. This does not affect the public - interface of the platform module. - -- Issue #17482: functools.update_wrapper (and functools.wraps) now set the - __wrapped__ attribute correctly even if the underlying function has a - __wrapped__ attribute set. - -- Issue #18431: The new email header parser now decodes RFC2047 encoded words - in structured headers. - -- Issue #18432: The sched module's queue method was incorrectly returning - an iterator instead of a list. - -- Issue #18044: The new email header parser was mis-parsing encoded words where - an encoded character immediately followed the '?' that follows the CTE - character, resulting in a decoding failure. They are now decoded correctly. - -- Issue #18101: Tcl.split() now process strings nested in a tuple as it - do with byte strings. - -- Issue #18116: getpass was always getting an error when testing /dev/tty, - and thus was always falling back to stdin. It also leaked an open file - when it did so. Both of these issues are now fixed. - -- Issue #17198: Fix a NameError in the dbm module. Patch by Valentina - Mukhamedzhanova. - -- Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form. - -- Issue #18020: improve html.escape speed by an order of magnitude. - Patch by Matt Bryant. - -- Issue #18347: ElementTree's html serializer now preserves the case of - closing tags. - -- Issue #17261: Ensure multiprocessing's proxies use proper address. - -- Issue #18343: faulthandler.register() now keeps the previous signal handler - when the function is called twice, so faulthandler.unregister() restores - correctly the original signal handler. - -- Issue #17097: Make multiprocessing ignore EINTR. - -- Issue #18339: Negative ints keys in unpickler.memo dict no longer cause a - segfault inside the _pickle C extension. - -- Issue 18240: The HMAC module is no longer restricted to bytes and accepts - any bytes-like object, e.g. memoryview. Original patch by Jonas Borgström. - -- Issue #18224: Removed pydoc script from created venv, as it causes problems - on Windows and adds no value over and above python -m pydoc ... - -- Issue #18155: The csv module now correctly handles csv files that use - a delimter character that has a special meaning in regexes, instead of - throwing an exception. - -- Issue #14360: encode_quopri can now be successfully used as an encoder - when constructing a MIMEApplication object. - -- Issue #11390: Add -o and -f command line options to the doctest CLI to - specify doctest options (and convert it to using argparse). - -- Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input - string in longer than 2 gigabytes, and ssl.SSLContext.load_cert_chain() - raises a ValueError if the password is longer than 2 gigabytes. The ssl - module does not support partial write. - -- Issue #11016: Add C implementation of the stat module as _stat. - -- Issue #18248: Fix libffi build on AIX. - -- Issue #18259: Declare sethostname in socketmodule.c for AIX - -- Issue #18147: Add diagnostic functions to ssl.SSLContext(). get_ca_list() - lists all loaded CA certificates and cert_store_stats() returns amount of - loaded X.509 certs, X.509 CA certs and CRLs. - -- Issue #18167: cgi.FieldStorage no longer fails to handle multipart/form-data - when \r\n appears at end of 65535 bytes without other newlines. - -- Issue #18076: Introduce importlib.util.decode_source(). - -- importlib.abc.SourceLoader.get_source() no longer changes SyntaxError or - UnicodeDecodeError into ImportError. - -- Issue #18058, 18057: Make the namespace package loader meet the - importlib.abc.InspectLoader ABC, allowing for namespace packages to work with - runpy. - -- Issue #17177: The imp module is pending deprecation. - -- subprocess: Prevent a possible double close of parent pipe fds when the - subprocess exec runs into an error. Prevent a regular multi-close of the - /dev/null fd when any of stdin, stdout and stderr was set to DEVNULL. - -- Issue #18194: Introduce importlib.util.cache_from_source() and - source_from_cache() while documenting the equivalent functions in imp as - deprecated. - -- Issue #17907: Document imp.new_module() as deprecated in favour of - types.ModuleType. - -- Issue #18192: Introduce importlib.util.MAGIC_NUMBER and document as deprecated - imp.get_magic(). - -- Issue #18149: Add filecmp.clear_cache() to manually clear the filecmp cache. - Patch by Mark Levitt - -- Issue #18193: Add importlib.reload(). - -- Issue #18157: Stop using imp.load_module() in pydoc. - -- Issue #16102: Make uuid._netbios_getnode() work again on Python 3. - -- Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store. - -- Issue #18143: Implement ssl.get_default_verify_paths() in order to debug - the default locations for cafile and capath. - -- Issue #17314: Move multiprocessing.forking over to importlib. - -- Issue #11959: SMTPServer and SMTPChannel now take an optional map, use of - which avoids affecting global state. - -- Issue #18109: os.uname() now decodes fields from the locale encoding, and - socket.gethostname() now decodes the hostname from the locale encoding, - instead of using the UTF-8 encoding in strict mode. - -- Issue #18089: Implement importlib.abc.InspectLoader.load_module. - -- Issue #18088: Introduce importlib.abc.Loader.init_module_attrs for setting - module attributes. Leads to the pending deprecation of - importlib.util.module_for_loader. - -- Issue #17403: urllib.parse.robotparser normalizes the urls before adding to - ruleline. This helps in handling certain types invalid urls in a conservative - manner. Patch contributed by Mher Movsisyan. - -- Issue #18070: Have importlib.util.module_for_loader() set attributes - unconditionally in order to properly support reloading. - -- Added importlib.util.module_to_load to return a context manager to provide the - proper module object to load. - -- Issue #18025: Fixed a segfault in io.BufferedIOBase.readinto() when raw - stream's read() returns more bytes than requested. - -- Issue #18011: base64.b32decode() now raises a binascii.Error if there are - non-alphabet characters present in the input string to conform a docstring. - Updated the module documentation. - -- Issue #18072: Implement importlib.abc.InspectLoader.get_code() and - importlib.abc.ExecutionLoader.get_code(). - -- Issue #8240: Set the SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER flag on SSL - sockets. - -- Issue #17269: Workaround for socket.getaddrinfo crash on MacOS X - with port None or "0" and flags AI_NUMERICSERV. - -- Issue #16986: ElementTree now correctly parses a string input not only when - an internal XML encoding is UTF-8 or US-ASCII. - -- Issue #17996: socket module now exposes AF_LINK constant on BSD and OSX. - -- Issue #17900: Allowed pickling of recursive OrderedDicts. Decreased pickled - size and pickling time. - -- Issue #17914: Add os.cpu_count(). Patch by Yogesh Chaudhari, based on an - initial patch by Trent Nelson. - -- Issue #17812: Fixed quadratic complexity of base64.b32encode(). - Optimize base64.b32encode() and base64.b32decode() (speed up to 3x). - -- Issue #17980: Fix possible abuse of ssl.match_hostname() for denial of - service using certificates with many wildcards (CVE-2013-2099). - -- Issue #15758: Fix FileIO.readall() so it no longer has O(n**2) complexity. - -- Issue #14596: The struct.Struct() objects now use more compact implementation. - -- Issue #17981: Closed socket on error in SysLogHandler. - -- Issue #17964: Fix os.sysconf(): the return type of the C sysconf() function - is long, not int. - -- Fix typos in the multiprocessing module. - -- Issue #17754: Make ctypes.util.find_library() independent of the locale. - -- Issue #17968: Fix memory leak in os.listxattr(). - -- Issue #17606: Fixed support of encoded byte strings in the XMLGenerator - characters() and ignorableWhitespace() methods. Original patch by Sebastian - Ortiz Vasquez. - -- Issue #17732: Ignore distutils.cfg options pertaining to install paths if a - virtual environment is active. - -- Issue #17915: Fix interoperability of xml.sax with file objects returned by - codecs.open(). - -- Issue #16601: Restarting iteration over tarfile no more continues from where - it left off. Patch by Michael Birtwell. - -- Issue #17289: The readline module now plays nicer with external modules - or applications changing the rl_completer_word_break_characters global - variable. Initial patch by Bradley Froehle. - -- Issue #12181: select module: Fix struct kevent definition on OpenBSD 64-bit - platforms. Patch by Federico Schwindt. - -- Issue #11816: multiple improvements to the dis module: get_instructions - generator, ability to redirect output to a file, Bytecode and Instruction - abstractions. Patch by Nick Coghlan, Ryan Kelly and Thomas Kluyver. - -- Issue #13831: Embed stringification of remote traceback in local - traceback raised when pool task raises an exception. - -- Issue #15528: Add weakref.finalize to support finalization using - weakref callbacks. - -- Issue #14173: Avoid crashing when reading a signal handler during - interpreter shutdown. - -- Issue #15902: Fix imp.load_module() accepting None as a file when loading an - extension module. - -- Issue #13721: SSLSocket.getpeercert() and SSLSocket.do_handshake() now - raise an OSError with ENOTCONN, instead of an AttributeError, when the - SSLSocket is not connected. - -- Issue #14679: add an __all__ (that contains only HTMLParser) to html.parser. - -- Issue #17802: Fix an UnboundLocalError in html.parser. Initial tests by - Thomas Barlow. - -- Issue #17358: Modules loaded by imp.load_source() and load_compiled() (and by - extention load_module()) now have a better chance of working when reloaded. - -- Issue #17804: New function ``struct.iter_unpack`` allows for streaming - struct unpacking. - -- Issue #17830: When keyword.py is used to update a keyword file, it now - preserves the line endings of the original file. - -- Issue #17272: Making the urllib.request's Request.full_url a descriptor. - Fixes bugs with assignment to full_url. Patch by Demian Brecht. - -- Issue #17353: Plistlib emitted empty data tags with deeply nested datastructures - -- Issue #11714: Use 'with' statements to assure a Semaphore releases a - condition variable. Original patch by Thomas Rachel. - -- Issue #16624: `subprocess.check_output` now accepts an `input` argument, - allowing the subprocess's stdin to be provided as a (byte) string. - Patch by Zack Weinberg. - -- Issue #17795: Reverted backwards-incompatible change in SysLogHandler with - Unix domain sockets. - -- Issue #16694: Add a pure Python implementation of the operator module. - Patch by Zachary Ware. - -- Issue #11182: remove the unused and undocumented pydoc.Scanner class. - Patch by Martin Morrison. - -- Issue #17741: Add ElementTree.IncrementalParser, an event-driven parser - for non-blocking applications. - -- Issue #17555: Fix ForkAwareThreadLock so that size of after fork - registry does not grow exponentially with generation of process. - -- Issue #17707: multiprocessing.Queue's get() method does not block for short - timeouts. - -- Isuse #17720: Fix the Python implementation of pickle.Unpickler to correctly - process the APPENDS opcode when it is used on non-list objects. - -- Issue #17012: shutil.which() no longer fallbacks to the PATH environment - variable if empty path argument is specified. Patch by Serhiy Storchaka. - -- Issue #17710: Fix pickle raising a SystemError on bogus input. - -- Issue #17341: Include the invalid name in the error messages from re about - invalid group names. - -- Issue #17702: os.environ now raises KeyError with the original environment - variable name (str on UNIX), instead of using the encoded name (bytes on - UNIX). - -- Issue #16163: Make the importlib based version of pkgutil.iter_importers - work for submodules. Initial patch by Berker Peksag. - -- Issue #16804: Fix a bug in the 'site' module that caused running - 'python -S -m site' to incorrectly throw an exception. - -- Issue #15480: Remove the deprecated and unused TYPE_INT64 code from marshal. - Initial patch by Daniel Riti. - -- Issue #2118: SMTPException is now a subclass of IOError. - -- Issue #17016: Get rid of possible pointer wraparounds and integer overflows - in the re module. Patch by Nickolai Zeldovich. - -- Issue #16658: add missing return to HTTPConnection.send() - Patch by Jeff Knupp. - -- Issue #9556: Allowed specifying a time-of-day for a TimedRotatingFileHandler - to rotate. - -- Issue #14971: unittest test discovery no longer gets confused when a function - has a different __name__ than its name in the TestCase class dictionary. - -- Issue #17487: The wave getparams method now returns a namedtuple rather than - a plain tuple. - -- Issue #17675: socket repr() provides local and remote addresses (if any). - Patch by Giampaolo Rodola' - -- Issue #17093: Make the ABCs in importlib.abc provide default values or raise - reasonable exceptions for their methods to make them more amenable to super() - calls. - -- Issue #17566: Make importlib.abc.Loader.module_repr() optional instead of an - abstractmethod and raising NotImplementedError so as to be ignored by default. - -- Issue #17678: Remove the use of deprecated method in http/cookiejar.py. - Changing the usage of get_origin_req_host() to origin_req_host. - -- Issue #17666: Fix reading gzip files with an extra field. - -- Issue #16475: Support object instancing, recursion and interned strings - in marshal - -- Issue #17502: Process DEFAULT values in mock side_effect that returns iterator. - -- Issue #16795: On the ast.arguments object, unify vararg with varargannotation - and kwarg and kwargannotation. Change the column offset of ast.Attribute to be - at the attribute name. - -- Issue #17434: Properly raise a SyntaxError when a string occurs between future - imports. - -- Issue #17117: Import and @importlib.util.set_loader now set __loader__ when - it has a value of None or the attribute doesn't exist. - -- Issue #17032: The "global" in the "NameError: global name 'x' is not defined" - error message has been removed. Patch by Ram Rachum. - -- Issue #18080: When building a C extension module on OS X, if the compiler - is overriden with the CC environment variable, use the new compiler as - the default for linking if LDSHARED is not also overriden. This restores - Distutils behavior introduced in 3.2.3 and inadvertently dropped in 3.3.0. - -- Issue #18113: Fixed a refcount leak in the curses.panel module's - set_userptr() method. Reported by Atsuo Ishimoto. - -- Implement PEP 443 "Single-dispatch generic functions". - -- Implement PEP 435 "Adding an Enum type to the Python standard library". - -Tests ------ - -- Issue #17944: test_zipfile now discoverable and uses subclassing to - generate tests for different compression types. Fixed a bug with skipping - some tests due to use of exhausted iterators. - -- Issue #18266: test_largefile now works with unittest test discovery and - supports running only selected tests. Patch by Zachary Ware. - -- Issue #17767: test_locale now works with unittest test discovery. - Original patch by Zachary Ware. - -- Issue #18375: Assume --randomize when --randseed is used for running the - testsuite. - -- Issue #11185: Fix test_wait4 under AIX. Patch by Sébastien Sablé. - -- Issue #18207: Fix test_ssl for some versions of OpenSSL that ignore seconds - in ASN1_TIME fields. - -- Issue #18094: test_uuid no more reports skipped tests as passed. - -- Issue #17992: Add timeouts to asyncore and asynchat tests so that they won't - accidentally hang. - -- Issue #17833: Fix test_gdb failures seen on machines where debug symbols - for glibc are available (seen on PPC64 Linux). - -- Issue #7855: Add tests for ctypes/winreg for issues found in IronPython. - Initial patch by Dino Viehland. - -- Issue #11078: test___all__ now checks for duplicates in __all__. - Initial patch by R. David Murray. - -- Issue #17712: Fix test_gdb failures on Ubuntu 13.04. - -- Issue #17835: Fix test_io when the default OS pipe buffer size is larger - than one million bytes. - -- Issue #17065: Use process-unique key for winreg tests to avoid failures if - test is run multiple times in parallel (eg: on a buildbot host). - -- Issue #12820: add tests for the xml.dom.minicompat module. - Patch by John Chandler and Phil Connell. - -- Issue #17691: test_univnewlines now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17790: test_set now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17789: test_random now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17779: test_osx_env now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17766: test_iterlen now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17690: test_time now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17692: test_sqlite now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #11995: test_pydoc doesn't import all sys.path modules anymore. - -Documentation -------------- - -- Issue #18440: Clarify that `hash()` can truncate the value returned from an - object's custom `__hash__()` method. - -- Issue #17844: Add links to encoders and decoders for bytes-to-bytes codecs. - -- Issue #14097: improve the "introduction" page of the tutorial. - -- Issue #17977: The documentation for the cadefault argument's default value - in urllib.request.urlopen() is fixed to match the code. - -- Issue #15940: Specify effect of locale on time functions. - -- Issue #6696: add documentation for the Profile objects, and improve - profile/cProfile docs. Patch by Tom Pinckney. - -C-API ------ - -- Issue #18351: Fix various issues in a function in importlib provided to help - PyImport_ExecCodeModuleWithPathnames() (and thus by extension PyImport_ExecCodeModule() and PyImport_ExecCodeModuleEx()). - -- Issue #9369: The types of `char*` arguments of PyObject_CallFunction() and - PyObject_CallMethod() now changed to `const char*`. Based on patches by - Jörg Müller and Lars Buitinck. - -- Issue #17206: Py_CLEAR(), Py_DECREF(), Py_XINCREF() and Py_XDECREF() now - expand their arguments once instead of multiple times. Patch written by Illia - Polosukhin. - -- Issue #17522: Add the PyGILState_Check() API. - -- Issue #17327: Add PyDict_SetDefault. - -IDLE ----- - -- Issue #18279: Format - Strip trailing whitespace no longer marks a file as - changed when it has not been changed. This fix followed the addition of a - test file originally written by Phil Webster (the issue's main goal). - -- Issue #7136: In the Idle File menu, "New Window" is renamed "New File". - Patch by Tal Einat, Roget Serwy, and Todd Rovito. - -- Remove dead imports of imp. - -- Issue #18196: Avoid displaying spurious SystemExit tracebacks. - -- Issue #5492: Avoid traceback when exiting IDLE caused by a race condition. - -- Issue #17511: Keep IDLE find dialog open after clicking "Find Next". - Original patch by Sarah K. - -- Issue #18055: Move IDLE off of imp and on to importlib. - -- Issue #15392: Create a unittest framework for IDLE. - Initial patch by Rajagopalasarma Jayakrishnan. - See Lib/idlelib/idle_test/README.txt for how to run Idle tests. - -- Issue #14146: Highlight source line while debugging on Windows. - -- Issue #17838: Allow sys.stdin to be reassigned. - -- Issue #13495: Avoid loading the color delegator twice in IDLE. - -- Issue #17798: Allow IDLE to edit new files when specified on command line. - -- Issue #14735: Update IDLE docs to omit "Control-z on Windows". - -- Issue #17532: Always include Options menu for IDLE on OS X. - Patch by Guilherme Simões. - -Build ------ - -- Issue #17845: Clarified the message printed when some module are not built. - -- Issue #18256: Compilation fix for recent AIX releases. Patch by - David Edelsohn. - -- Issue #17547: In configure, explicitly pass -Wformat for the benefit for GCC - 4.8. - -- Issue #15172: Document NASM 2.10+ as requirement for building OpenSSL 1.0.1 - on Windows. - -Tools/Demos ------------ - -- Issue #18439: Make patchcheck work on Windows for ACKS, NEWS. - -- Issue #18448: Fix a typo in Tools/demo/eiffel.py. - -- Issue #18457: Fixed saving of formulas and complex numbers in - Tools/demo/ss1.py. - -- Issue #18449: Make Tools/demo/ss1.py work again on Python 3. Patch by - Févry Thibault. - -- Issue #12990: The "Python Launcher" on OSX could not launch python scripts - that have paths that include wide characters. - -What's New in Python 3.3.1 release candidate 1? -=============================================== - -*Release date: 24-Mar-2013* - -Core and Builtins ------------------ - -- Issue #17328: Fix possible refleak in dict.setdefault. - -- Issue #17275: Corrected class name in init error messages of the C version of - BufferedWriter and BufferedRandom. - -- Issue #7963: Fixed misleading error message that issued when object is - called without arguments. - -- Issue #8745: Small speed up zipimport on Windows. Patch by Catalin Iacob. - -- Issue #5308: Raise ValueError when marshalling too large object (a sequence - with size >= 2**31), instead of producing illegal marshal data. - -- Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError - and a full traceback including line number. - -- Issue #16967: In function definition, evaluate positional defaults before - keyword-only defaults. - -- Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) - in the interpreter. - -- Issue #17137: When an Unicode string is resized, the internal wide character - string (wstr) format is now cleared. - -- Issue #17043: The unicode-internal decoder no longer read past the end of - input buffer. - -- Issue #17098: All modules now have __loader__ set even if they pre-exist the - bootstrapping of importlib. - -- Issue #16979: Fix error handling bugs in the unicode-escape-decode decoder. - -- Issue #16772: The base argument to the int constructor no longer accepts - floats, or other non-integer objects with an __int__ method. Objects - with an __index__ method are now accepted. - -- Issue #10156: In the interpreter's initialization phase, unicode globals - are now initialized dynamically as needed. - -- Issue #16980: Fix processing of escaped non-ascii bytes in the - unicode-escape-decode decoder. - -- Issue #16975: Fix error handling bug in the escape-decode bytes decoder. - -- Issue #14850: Now a charmap decoder treats U+FFFE as "undefined mapping" +- Issue #14850: Now a chamap decoder treates U+FFFE as "undefined mapping" in any mapping, not only in a string. - Issue #16730: importlib.machinery.FileFinder now no longers raises an @@ -805,6 +24,8 @@ - Issue #11461: Fix the incremental UTF-16 decoder. Original patch by Amaury Forgeot d'Arc. +- Issue #16881: Fix Py_ARRAY_LENGTH macro for GCC < 3.1. + - Issue #16856: Fix a segmentation fault from calling repr() on a dict with a key whose repr raise an exception. @@ -813,7 +34,7 @@ - Issue #16761: Calling int() with base argument only now raises TypeError. - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py - when retrieving a REG_DWORD value. This corrects functions like + when retreiving a REG_DWORD value. This corrects functions like winreg.QueryValueEx that may have been returning truncated values. - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg @@ -826,6 +47,11 @@ - Issue #16772: The int() constructor's second argument (base) no longer accepts non integer values. Consistent with the behavior in Python 2. +- Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx + function (PyCFunction_New func is still present for backward compatibility). + +- Issue #16672: Improve performance tracing performance + - Issue #14470: Remove w9xpopen support per PEP 11. - Issue #9856: Replace deprecation warning with raising TypeError @@ -869,6 +95,8 @@ - Issue #16514: Fix regression causing a traceback when sys.path[0] is None (actually, any non-string or non-bytes type). +- Issue #16505: Remove unused Py_TPFLAGS_INT_SUBCLASS. + - Issue #16306: Fix multiple error messages when unknown command line parameters where passed to the interpreter. Patch by Hieu Nguyen. @@ -920,6 +148,11 @@ - Issue #10189: Improve the error reporting of SyntaxErrors related to global and nonlocal statements. +- Issue #16086: PyTypeObject.tp_flags and PyType_Spec.flags are now unsigned + (unsigned long and unsigned int) to avoid an undefined behaviour with + Py_TPFLAGS_TYPE_SUBCLASS ((1 << 31). PyType_GetFlags() result type is + now unsigned too (unsigned long, instead of long). + - Fix segfaults on setting __qualname__ on builtin types and attempting to delete it on any type. @@ -932,12 +165,21 @@ - Issue #16271: Fix strange bugs that resulted from __qualname__ appearing in a class's __dict__ and on type. +- Issue #16197: Update winreg docstrings and documentation to match code. + Patch by Zachary Ware. + +- Issue #16241: Document -X faulthandler command line option. + Patch by Marek Å uppa. + - Issue #12805: Make bytes.join and bytearray.join faster when the separator is empty. Patch by Serhiy Storchaka. - Issue #6074: Ensure cached bytecode files can always be updated by the user that created them, even when the source file is read-only. +- Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified + endianness detection and handling. + - Issue #15958: bytes.join and bytearray.join now accept arbitrary buffer objects. @@ -975,308 +217,9 @@ - Issue #15111: __import__ should propagate ImportError when raised as a side-effect of a module triggered from using fromlist. -- Issue #15022: Add pickle and comparison support to types.SimpleNamespace. - Library ------- -- Issue #15596: Faster pickling of unicode strings. - -- Issue #17572: Avoid chained exceptions while passing bad directives to - time.strptime(). Initial patch by Claudiu Popa. - -- Issue #17435: threading.Timer's __init__ method no longer uses mutable - default values for the args and kwargs parameters. - -- Issue #17526: fix an IndexError raised while passing code without filename to - inspect.findsource(). Initial patch by Tyler Doyle. - -- Issue #17540: Added style to formatter configuration by dict. - -- Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial - patch by Michele Orrù. - -- Issue #17025: multiprocessing: Reduce Queue and SimpleQueue contention. - -- Issue #17536: Add to webbrowser's browser list: www-browser, x-www-browser, - iceweasel, iceape. - -- Issue #17150: pprint now uses line continuations to wrap long string - literals. - -- Issue #17488: Change the subprocess.Popen bufsize parameter default value - from unbuffered (0) to buffering (-1) to match the behavior existing code - expects and match the behavior of the subprocess module in Python 2 to avoid - introducing hard to track down bugs. - -- Issue #17521: Corrected non-enabling of logger following two calls to - fileConfig(). - -- Issue #17508: Corrected MemoryHandler configuration in dictConfig() where - the target handler wasn't configured first. - -- Issue #17209: curses.window.get_wch() now handles correctly KeyboardInterrupt - (CTRL+c). - -- Issue #5713: smtplib now handles 421 (closing connection) error codes when - sending mail by closing the socket and reporting the 421 error code via the - exception appropriate to the command that received the error response. - -- Issue #16997: unittest.TestCase now provides a subTest() context manager - to procedurally generate, in an easy way, small test instances. - -- Issue #17485: Also delete the Request Content-Length header if the data - attribute is deleted. (Follow on to issue 16464). - -- Issue #15927: CVS now correctly parses escaped newlines and carriage - when parsing with quoting turned off. - -- Issue #17467: add readline and readlines support to mock_open in - unittest.mock. - -- Issue #17192: Update the ctypes module's libffi to v3.0.13. This - specifically addresses a stack misalignment issue on x86 and issues on - some more recent platforms. - -- Issue #8862: Fixed curses cleanup when getkey is interrputed by a signal. - -- Issue #17443: imaplib.IMAP4_stream was using the default unbuffered IO - in subprocess, but the imap code assumes buffered IO. In Python2 this - worked by accident. IMAP4_stream now explicitly uses buffered IO. - -- Issue #17476: Fixed regression relative to Python2 in undocumented pydoc - 'allmethods'; it was missing unbound methods on the class. - -- Issue #17474: Remove the deprecated methods of Request class. - -- Issue #16709: unittest discover order is no-longer filesystem specific. Patch - by Jeff Ramnani. - -- Use the HTTPS PyPI url for upload, overriding any plain HTTP URL in pypirc. - -- Issue #5024: sndhdr.whichhdr now returns the frame count for WAV files - rather than -1. - -- Issue #17460: Remove the strict argument of HTTPConnection and removing the - DeprecationWarning being issued from 3.2 onwards. - -- Issue #16880: Do not assume _imp.load_dynamic() is defined in the imp module. - -- Issue #16389: Fixed a performance regression relative to Python 3.1 in the - caching of compiled regular expressions. - -- Added missing FeedParser and BytesFeedParser to email.parser.__all__. - -- Issue #17431: Fix missing import of BytesFeedParser in email.parser. - -- Issue #12921: http.server's send_error takes an explain argument to send more - information in response. Patch contributed by Karl. - -- Issue #17414: Add timeit, repeat, and default_timer to timeit.__all__. - -- Issue #1285086: Get rid of the refcounting hack and speed up - urllib.parse.unquote() and urllib.parse.unquote_to_bytes(). - -- Issue #17099: Have importlib.find_loader() raise ValueError when __loader__ - is not set, harmonizing with what happens when the attribute is set to None. - -- Expose the O_PATH constant in the os module if it is available. - -- Issue #17368: Fix an off-by-one error in the Python JSON decoder that caused - a failure while decoding empty object literals when object_pairs_hook was - specified. - -- Issue #17385: Fix quadratic behavior in threading.Condition. The FIFO - queue now uses a deque instead of a list. - -- Issue #15806: Add contextlib.ignored(). This creates a context manager - to ignore specified exceptions, replacing the "except Exc: pass" idiom. - -- Issue #14645: The email generator classes now produce output using the - specified linesep throughout. Previously if the prolog, epilog, or - body were stored with a different linesep, that linesep was used. This - fix corrects an RFC non-compliance issue with smtplib.send_message. - -- Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when - the list is being resized concurrently. - -- Issue #16962: Use getdents64 instead of the obsolete getdents syscall - in the subprocess module on Linux. - -- Issue #16935: unittest now counts the module as skipped if it raises SkipTest, - instead of counting it as an error. Patch by Zachary Ware. - -- Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR. - -- Issue #17223: array module: Fix a crasher when converting an array containing - invalid characters (outside range [U+0000; U+10ffff]) to Unicode: - repr(array), str(array) and array.tounicode(). Patch written by Manuel Jacob. - -- Issue #17197: profile/cProfile modules refactored so that code of run() and - runctx() utility functions is not duplicated in both modules. - -- Issue #14720: sqlite3: Convert datetime microseconds correctly. - Patch by Lowe Thiderman. - -- Issue #15132: Allow a list for the defaultTest argument of - unittest.TestProgram. Patch by Jyrki Pulliainen. - -- Issue #17225: JSON decoder now counts columns in the first line starting - with 1, as in other lines. - -- Issue #6623: Added explicit DeprecationWarning for ftplib.netrc, which has - been deprecated and undocumented for a long time. - -- Issue #13700: Fix byte/string handling in imaplib authentication when an - authobject is specified. - -- Issue #13153: Tkinter functions now raise TclError instead of ValueError when - a string argument contains non-BMP character. - -- Issue #9669: Protect re against infinite loops on zero-width matching in - non-greedy repeat. Patch by Matthew Barnett. - -- Issue #13169: The maximal repetition number in a regular expression has been - increased from 65534 to 2147483647 (on 32-bit platform) or 4294967294 (on - 64-bit). - -- Issue #17143: Fix a missing import in the trace module. Initial patch by - Berker Peksag. - -- Issue #15220: email.feedparser's line splitting algorithm is now simpler and - faster. - -- Issue #16743: Fix mmap overflow check on 32 bit Windows. - -- Issue #16996: webbrowser module now uses shutil.which() to find a - web-browser on the executable search path. - -- Issue #16800: tempfile.gettempdir() no longer left temporary files when - the disk is full. Original patch by Amir Szekely. - -- Issue #17192: Import libffi-3.0.12. - -- Issue #16564: Fixed regression relative to Python2 in the operation of - email.encoders.encode_7or8bit when used with binary data. - -- Issue #17052: unittest discovery should use self.testLoader. - -- Issue #4591: Uid and gid values larger than 2**31 are supported now. - -- Issue #17141: random.vonmisesvariate() no more hangs for large kappas. - -- Issue #17149: Fix random.vonmisesvariate to always return results in - [0, 2*math.pi]. - -- Issue #1470548: XMLGenerator now works with binary output streams. - -- Issue #6975: os.path.realpath() now correctly resolves multiple nested - symlinks on POSIX platforms. - -- Issue #13773: sqlite3.connect() gets a new `uri` parameter to pass the - filename as a URI, allowing to pass custom options. - -- Issue #16564: Fixed regression relative to Python2 in the operation of - email.encoders.encode_noop when used with binary data. - -- Issue #10355: In SpooledTemporaryFile class mode, name, encoding and - newlines properties now work for unrolled files. Obsoleted and never - working on Python 3 xreadline method now removed. - -- Issue #16686: Fixed a lot of bugs in audioop module. Fixed crashes in - avgpp(), maxpp() and ratecv(). Fixed an integer overflow in add(), bias(), - and ratecv(). reverse(), lin2lin() and ratecv() no more lose precision for - 32-bit samples. max() and rms() no more returns a negative result and - various other functions now work correctly with 32-bit sample -0x80000000. - -- Issue #17073: Fix some integer overflows in sqlite3 module. - -- Issue #16723: httplib.HTTPResponse no longer marked closed when the connection - is automatically closed. - -- Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by - Brian Thorne. - -- Issue #16948: Fix quoted printable body encoding for non-latin1 character - sets in the email package. - -- Issue #16811: Fix folding of headers with no value in the provisional email - policies. - -- Issue #17132: Update symbol for "yield from" grammar changes. - -- Issue #17076: Make copying of xattrs more permissive of missing FS support. - Patch by Thomas Wouters. - -- Issue #17089: Expat parser now correctly works with string input not only when - an internal XML encoding is UTF-8 or US-ASCII. It now accepts bytes and - strings larger than 2 GiB. - -- Issue #6083: Fix multiple segmentation faults occured when PyArg_ParseTuple - parses nested mutating sequence. - -- Issue #5289: Fix ctypes.util.find_library on Solaris. - -- Issue #17106: Fix a segmentation fault in io.TextIOWrapper when an underlying - stream or a decoder produces data of an unexpected type (i.e. when - io.TextIOWrapper initialized with text stream or use bytes-to-bytes codec). - -- Issue #17015: When it has a spec, a Mock object now inspects its signature - when matching calls, so that arguments can be matched positionally or - by name. - -- Issue #15633: httplib.HTTPResponse is now mark closed when the server - sends less than the advertised Content-Length. - -- Issue #12268: The io module file object write methods no longer abort early - when one of its write system calls is interrupted (EINTR). - -- Issue #6972: The zipfile module no longer overwrites files outside of - its destination path when extracting malicious zip files. - -- Issue #4844: ZipFile now raises BadZipFile when opens a ZIP file with an - incomplete "End of Central Directory" record. Original patch by Guilherme - Polo and Alan McIntyre. - -- Issue #17071: Signature.bind() now works when one of the keyword arguments - is named ``self``. - -- Issue #12004: Fix an internal error in PyZipFile when writing an invalid - Python file. Patch by Ben Morgan. - -- Have py_compile use importlib as much as possible to avoid code duplication. - Code now raises FileExistsError if the file path to be used for the - byte-compiled file is a symlink or non-regular file as a warning that import - will not keep the file path type if it writes to that path. - -- Issue #180022: Have site.addpackage() consider already known paths even when - none are explicitly passed in. Bug report and fix by Kirill. - -- Issue #1602133: on Mac OS X a shared library build (``--enable-shared``) - now fills the ``os.environ`` variable correctly. - -- Issue #15505: `unittest.installHandler` no longer assumes SIGINT handler is - set to a callable object. - -- Issue #13454: Fix a crash when deleting an iterator created by itertools.tee() - if all other iterators were very advanced before. - -- Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries - and bytes data. Patch by Jonas Wagner. - -- Issue #16957: shutil.which() no longer searches a bare file name in the - current directory on Unix and no longer searches a relative file path with - a directory part in PATH directories. Patch by Thomas Kluyver. - -- Issue #1159051: GzipFile now raises EOFError when reading a corrupted file - with truncated header or footer. - -- Issue #16993: shutil.which() now preserves the case of the path and extension - on Windows. - -- Issue #16992: On Windows in signal.set_wakeup_fd, validate the file - descriptor argument. - - Issue #16422: For compatibility with the Python version, the C version of decimal now uses strings instead of integers for rounding mode constants. @@ -1286,11 +229,16 @@ - Issue #9720: zipfile now writes correct local headers for files larger than 4 GiB. +- Issue #5066: Update IDLE docs. Patch by Todd Rovito. + - Issue #16955: Fix the poll() method for multiprocessing's socket connections on Windows. - SSLContext.load_dh_params() now properly closes the input file. +- Issue #16829: IDLE printing no longer fails if there are spaces or other + special characters in the file path. + - Issue #15031: Refactor some .pyc management code to cut down on code duplication. Thanks to Ronan Lamy for the report and taking an initial stab at the problem. @@ -1307,6 +255,8 @@ failing if the connection used a row factory (such as sqlite3.Row) that produced unsortable objects. (Regression was introduced by fix for 9750). +- Issue #16491: IDLE now prints chained exception tracebacks. + - fcntl: add F_DUPFD_CLOEXEC constant, available on Linux 2.6.24+. - Issue #15972: Fix error messages when os functions expecting a file name or @@ -1343,6 +293,8 @@ clears previous values stored in the default section. Same goes for ``parser.update({'DEFAULT': {}})``. +- Issue #16819: IDLE method completion now correctly works for bytes literals. + - Issue #9586: Redefine SEM_FAILED on MacOSX to keep compiler happy. - Issue #16787: Increase asyncore and asynchat default output buffers size, to @@ -1366,11 +318,20 @@ - Issue #16641: Default values of sched.scheduler.enter() are no longer modifiable. +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by + Roger Serwy. + - Issue #16618: Make glob.glob match consistently across strings and bytes regarding leading dots. Patch by Serhiy Storchaka. - Issue #16788: Add samestat to Lib/ntpath.py +- Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for + localhost tests. + +- Issue #16511: Use default IDLE width and height if config param is not valid. + Patch Serhiy Storchaka. + - Issue #16713: Parsing of 'tel' urls using urlparse separates params from path. @@ -1448,6 +409,9 @@ list() calls aren't added to filter(), map(), and zip() which are directly passed enumerate(). +- Issue #16549: Make json.tool work again on Python 3 and add tests. + Initial patch by Berker Peksag and Serhiy Storchaka. + - Issue #12848: The pure Python pickle implementation now treats object lengths as unsigned 32-bit integers, like the C implementation does. Patch by Serhiy Storchaka. @@ -1466,7 +430,7 @@ - Issue #16522: added FAIL_FAST flag to doctest. -- Issue #15627: Add the importlib.abc.InspectLoader.source_to_code() method. +- Issue #15627: Add the importlib.abc.SourceLoader.source_to_code() method. - Issue #16408: Fix file descriptors not being closed in error conditions in the zipfile module. Patch by Serhiy Storchaka. @@ -1530,6 +494,9 @@ - Issue #16284: Prevent keeping unnecessary references to worker functions in concurrent.futures ThreadPoolExecutor. +- Issue #1207589: Add Cut/Copy/Paste items to IDLE right click Context Menu + Patch by Todd Rovito. + - Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on. Patch by Serhiy Storchaka. @@ -1606,6 +573,9 @@ - Issue #15417: Add support for csh and fish in venv activation scripts. +- Issue #16123: IDLE - deprecate running without a subprocess. + Patch by Roger Serwy. + - Issue #14377: ElementTree.write and some of the module-level functions have a new parameter - *short_empty_elements*. It controls how elements with no contents are emitted. @@ -1657,6 +627,9 @@ `io.BytesIO` and `io.StringIO` objects now raise ValueError when the object has been closed. Patch by Alessandro Moura. +- Issue #16126: PyErr_Format format mismatch in _testcapimodule.c. + Patch by Serhiy Storchaka. + - Issue #15447: Use `subprocess.DEVNULL` in webbrowser, instead of opening `os.devnull` explicitly and leaving it open. @@ -1672,137 +645,23 @@ - Issue #15906: Fix a regression in argparse caused by the preceding change, when ``action='append'``, ``type='str'`` and ``default=[]``. +Extension Modules +----------------- + - Issue #16113: Added sha3 module based on the Keccak reference implementation 3.2. The `hashlib` module has four additional hash algorithms: `sha3_224`, `sha3_256`, `sha3_384` and `sha3_512`. As part of the patch some common code was moved from _hashopenssl.c to hashlib.h. -- ctypes.call_commethod was removed, since its only usage was in the defunct - samples directory. - -- Issue #16692: Added TLSv1.1 and TLSv1.2 support for the ssl modules. - -- Issue #16832: add abc.get_cache_token() to expose cache validity checking - support in ABCMeta. - -IDLE ----- - -- Issue #17585: Fixed IDLE regression. Now closes when using exit() or quit(). - -- Issue #17657: Show full Tk version in IDLE's about dialog. - Patch by Todd Rovito. - -- Issue #17613: Prevent traceback when removing syntax colorizer in IDLE. - -- Issue #1207589: Backwards-compatibility patch for right-click menu in IDLE. - -- Issue #16887: IDLE now accepts Cancel in tabify/untabify dialog box. - -- Issue #17625: In IDLE, close the replace dialog after it is used. - -- Issue #14254: IDLE now handles readline correctly across shell restarts. - -- Issue #17614: IDLE no longer raises exception when quickly closing a file. - -- Issue #6698: IDLE now opens just an editor window when configured to do so. - -- Issue #8900: Using keyboard shortcuts in IDLE to open a file no longer - raises an exception. - -- Issue #6649: Fixed missing exit status in IDLE. Patch by Guilherme Polo. - -- Issue #17114: IDLE now uses non-strict config parser. - -- Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase - interface and support all mandatory methods and properties. - -- Issue #5066: Update IDLE docs. Patch by Todd Rovito. - -- Issue #16829: IDLE printing no longer fails if there are spaces or other - special characters in the file path. - -- Issue #16491: IDLE now prints chained exception tracebacks. - -- Issue #16819: IDLE method completion now correctly works for bytes literals. - -- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by - Roger Serwy. - -- Issue #16511: Use default IDLE width and height if config param is not valid. - Patch Serhiy Storchaka. - -- Issue #1207589: Add Cut/Copy/Paste items to IDLE right click Context Menu - Patch by Todd Rovito. - -- Issue #16123: IDLE - deprecate running without a subprocess. - Patch by Roger Serwy. - Tests ----- -- Issue #17448: test_sax now skips if there are no xml parsers available - instead of raising an ImportError. - -- Issue #11420: make test suite pass with -B/DONTWRITEBYTECODE set. - Initial patch by Thomas Wouters. - -- Issue #10652: make tcl/tk tests run after __all__ test, patch by - Zachary Ware. - -- Issue #11963: remove human verification from test_parser and test_subprocess. - -- Issue #11732: add a new suppress_crash_popup() context manager to test.support - that disables crash popups on Windows and use it in test_faulthandler and - test_capi. - -- Issue #13898: test_ssl no longer prints a spurious stack trace on Ubuntu. - -- Issue #17283: Share code between `__main__.py` and `regrtest.py` in - `Lib/test`. - -- Issue #17249: convert a test in test_capi to use unittest and reap threads. - -- Issue #17107: Test client-side SNI support in urllib.request thanks to - the new server-side SNI support in the ssl module. Initial patch by - Daniel Black. - -- Issue #17041: Fix testing when Python is configured with the - --without-doc-strings. - - Issue #16923: Fix ResourceWarnings in test_ssl. - Issue #15539: Added regression tests for Tools/scripts/pindent.py. - Issue #16836: Enable IPv6 support even if IPv6 is disabled on the build host. -- Issue #17479: test_io now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17066: test_robotparser now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17334: test_index now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17333: test_imaplib now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17082: test_dbm* now work with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17079: test_ctypes now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17304: test_hash now works with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17303: test_future* now work with unittest test discovery. - Patch by Zachary Ware. - -- Issue #17163: test_file now works with unittest test discovery. - Patch by Zachary Ware. - - Issue #16925: test_configparser now works with unittest test discovery. Patch by Zachary Ware. @@ -1843,9 +702,6 @@ - Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize options. -- Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for - localhost tests. - - Issue #16664: Add regression tests for glob's behaviour concerning entries starting with a ".". Patch by Sebastian Kreft. @@ -1861,9 +717,6 @@ - Issue #16115: Add some tests for the executable argument to subprocess.Popen(). Initial patch by Kushal Das. -- Issue #16126: PyErr_Format format mismatch in _testcapimodule.c. - Patch by Serhiy Storchaka. - - Issue #15304: Fix warning message when `os.chdir()` fails inside `test.support.temp_cwd()`. Patch by Chris Jerdonek. @@ -1873,48 +726,9 @@ - Issue #15557: Added a test suite for the webbrowser module, thanks to Anton Barkovsky. -- Issue #16698: Skip posix test_getgroups when built with OS X - deployment target prior to 10.6. - Build ----- -- Issue #17591: Use lowercase filenames when including Windows header files. - Patch by Roumen Petrov. - -- Issue #17550: Fix the --enable-profiling configure switch. - -- Issue #17425: Build with openssl 1.0.1d on Windows. - -- Issue #16754: Fix the incorrect shared library extension on linux. Introduce - two makefile macros SHLIB_SUFFIX and EXT_SUFFIX. SO now has the value of - SHLIB_SUFFIX again (as in 2.x and 3.1). The SO macro is removed in 3.4. - -- Issue #5033: Fix building of the sqlite3 extension module when the - SQLite library version has "beta" in it. Patch by Andreas Pelme. - -- Issue #17228: Fix building without pymalloc. - -- Issue #3718: Use AC_ARG_VAR to set MACHDEP in configure.ac. - -- Issue #16235: Implement python-config as a shell script. - -- Issue #16769: Remove outdated Visual Studio projects. - -- Issue #17031: Fix running regen in cross builds. - -- Issue #3754: fix typo in pthread AC_CACHE_VAL. - -- Issue #15484: Fix _PYTHON_PROJECT_BASE for srcdir != builddir builds; - use _PYTHON_PROJECT_BASE in distutils/sysconfig.py. - -- Drop support for Windows 2000. - -- Issue #17029: Let h2py search the multiarch system include directory. - -- Issue #16953: Fix socket module compilation on platforms with - HAVE_BROKEN_POLL. Patch by Jeffrey Armstrong. - - Issue #16320: Remove redundant Makefile dependencies for strings and bytes. - Cross compiling needs host and build settings. configure no longer @@ -1942,60 +756,9 @@ - Issue #15819: Make sure we can build Python out-of-tree from a read-only source directory. (Somewhat related to issue #9860.) -- Issue #15587: Enable Tk high-resolution text rendering on Macs with - Retina displays. Applies to Tkinter apps, such as IDLE, on OS X - framework builds linked with Cocoa Tk 8.5. - -- Issue #17161: make install now also installs a python3 man page. - -C-API ------ - -- Issue #16881: Fix Py_ARRAY_LENGTH macro for GCC < 3.1. - -- Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx - function (PyCFunction_New func is still present for backward compatibility). - -- Issue #16505: Remove unused Py_TPFLAGS_INT_SUBCLASS. - -- Issue #16086: PyTypeObject.tp_flags and PyType_Spec.flags are now unsigned - (unsigned long and unsigned int) to avoid an undefined behaviour with - Py_TPFLAGS_TYPE_SUBCLASS ((1 << 31). PyType_GetFlags() result type is - now unsigned too (unsigned long, instead of long). - -- Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified - endianness detection and handling. - Documentation ------------- -- Issue #15940: Specify effect of locale on time functions. - -- Issue 17538: Document XML vulnerabilties - -- Issue #16642: sched.scheduler timefunc initial default is time.monotonic. - Patch by Ramchandra Apte - -- Issue #17047: remove doubled words in docs and docstrings - reported by Serhiy Storchaka and Matthew Barnett. - -- Issue #15465: Document the versioning macros in the C API docs rather than - the standard library docs. Patch by Kushal Das. - -- Issue #16406: Combine the pages for uploading and registering to PyPI. - -- Issue #16403: Document how distutils uses the maintainer field in - PKG-INFO. Patch by Jyrki Pulliainen. - -- Issue #16695: Document how glob handles filenames starting with a - dot. Initial patch by Jyrki Pulliainen. - -- Issue #8890: Stop advertising an insecure practice by replacing uses - of the /tmp directory with better alternatives in the documentation. - Patch by Geoff Wilson. - -- Issue #17203: add long option names to unittest discovery docs. - - Issue #13094: add "Why do lambdas defined in a loop with different values all return the same result?" programming FAQ. @@ -2024,15 +787,9 @@ - Issue #15677: Document that zlib and gzip accept a compression level of 0 to mean 'no compression'. Patch by Brian Brazil. -- Issue #16197: Update winreg docstrings and documentation to match code. - Patch by Zachary Ware. - - Issue #8040: added a version switcher to the documentation. Patch by Yury Selivanov. -- Issue #16241: Document -X faulthandler command line option. - Patch by Marek Å uppa. - - Additional comments and some style changes in the concurrent.futures URL retrieval example @@ -2056,20 +813,9 @@ - Issue #11964: Document a change in v3.2 to the behavior of the indent parameter of json encoding operations. -- Issue #15116: Remove references to appscript as it is no longer being - supported. - Tools/Demos ----------- -- Issue #15239: Make mkstringprep.py work again on Python 3. - -- Issue #17028: Allowed Python arguments to be supplied to the Windows - launcher. - -- Issue #17156: pygettext.py now uses an encoding of source file and correctly - writes and escapes non-ascii characters. - - Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py. Now pindent.py works with a "with" statement. pindent.py no longer produces improper indentation. pindent.py now works with continued lines broken after @@ -2088,9 +834,6 @@ - Issue #15378: Fix Tools/unicode/comparecodecs.py. Patch by Serhiy Storchaka. -- Issue #16549: Make json.tool work again on Python 3 and add tests. - Initial patch by Berker Peksag and Serhiy Storchaka. - - Issue #13301: use ast.literal_eval() instead of eval() in Tools/i18n/msgfmt.py Patch by Serhiy Storchaka. @@ -2181,9 +924,6 @@ Library ------- -- Issue #17158: Add 'symbols' to help() welcome message; clarify - 'modules spam' messages. - - Issue #15847: Fix a regression in argparse, which did not accept tuples as argument lists anymore. @@ -2259,8 +999,6 @@ Library ------- -- Issue #13248: removed deprecated and undocumented difflib.isbjunk, isbpopular. - - Issue #13370: Ensure that ctypes works on Mac OS X when Python is compiled using the clang compiler. @@ -2305,24 +1043,28 @@ - Issue #15646: Prevent equivalent of a fork bomb when using `multiprocessing` on Windows without the ``if __name__ == '__main__'`` idiom. -IDLE ----- - - Issue #15678: Fix IDLE menus when started from OS X command line (3.3.0b2 regression). +C API +----- + +Extension Modules +----------------- + +Tools/Demos +----------- + Documentation ------------- -- Touched up the Python 2 to 3 porting guide. - - Issue #14674: Add a discussion of the `json` module's standard compliance. Patch by Chris Rebert. - Create a 'Concurrent Execution' section in the docs, and split up the 'Optional Operating System Services' section to use a more user-centric classification scheme (splitting them across the new CE section, IPC and text - processing). Operating system limitations can be reflected with the Sphinx + processing). Operating system limitatons can be reflected with the Sphinx ``:platform:`` tag, it doesn't make sense as part of the Table of Contents. - Issue #4966: Bring the sequence docs up to date for the Py3k transition and @@ -2477,6 +1219,9 @@ - Issue #15546: Fix handling of pathological input data in the peek() and read1() methods of the BZ2File, GzipFile and LZMAFile classes. +- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog + ended with ``\``. Patch by Roger Serwy. + - Issue #12655: Instead of requiring a custom type, `os.sched_getaffinity()` and `os.sched_setaffinity()` now use regular sets of integers to represent the CPUs a process is restricted to. @@ -2501,6 +1246,8 @@ - Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path. +- Issue #15041: Update "see also" list in tkinter documentation. + - Issue #15413: `os.times()` had disappeared under Windows. - Issue #15402: An issue in the struct module that caused `sys.getsizeof()` to @@ -2627,12 +1374,6 @@ - Issue #15194: Update libffi to the 3.0.11 release. -IDLE ----- - -- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog - ended with ``\``. Patch by Roger Serwy. - Tools/Demos ----------- @@ -2652,8 +1393,6 @@ Documentation ------------- -- Issue #15041: Update "see also" list in tkinter documentation. - - Issue #15444: Use proper spelling for non-ASCII contributor names. Patch by Serhiy Storchaka. @@ -2725,8 +1464,6 @@ - Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. -- Issue #16256: OS X installer now sets correct permissions for doc directory. - - Issue #15431: Add _freeze_importlib project to regenerate importlib.h on Windows. Patch by Kristján Valur Jónsson. @@ -2762,9 +1499,14 @@ - Issue #11626: Add _SizeT functions to stable ABI. +- Issue #15146: Add PyType_FromSpecWithBases. Patch by Robin Schreiber. + - Issue #15142: Fix reference leak when deallocating instances of types created using PyType_FromSpec(). +- Issue #15042: Add PyState_AddModule and PyState_RemoveModule. Add version + guard for Py_LIMITED_API additions. Patch by Robin Schreiber. + - Issue #10053: Don't close FDs when FileIO.__init__ fails. Loosely based on the work by Hirokazu Yamamoto. @@ -2792,6 +1534,9 @@ Library ------- +- Issue #9803: Don't close IDLE on saving if breakpoint is open. + Patch by Roger Serwy. + - Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog. @@ -2810,8 +1555,14 @@ - Issue #15514: Correct __sizeof__ support for cpu_set. Patch by Serhiy Storchaka. +- Issue #15187: Bugfix: remove temporary directories test_shutil was leaving + behind. + - Issue #15177: Added dir_fd parameter to os.fwalk(). +- Issue #15176: Clarified behavior, documentation, and implementation + of os.listdir(). + - Issue #15061: Re-implemented hmac.compare_digest() in C to prevent further timing analysis and to support all buffer protocol aware objects as well as ASCII only str instances safely. @@ -2862,7 +1613,7 @@ - Issue #14626: Large refactoring of functions / parameters in the os module. Many functions now support "dir_fd" and "follow_symlinks" parameters; - some also support accepting an open file descriptor in place of a path + some also support accepting an open file descriptor in place of of a path string. Added os.support_* collections as LBYL helpers. Removed many functions only previously seen in 3.3 alpha releases (often starting with "f" or "l", or ending with "at"). Originally suggested by Serhiy Storchaka; @@ -2911,6 +1662,10 @@ - Issue #15006: Allow equality comparison between naive and aware time or datetime objects. +- Issue #14982: Document that pkgutil's iteration functions require the + non-standard iter_modules() method to be defined by an importer (something + the importlib importers do not define). + - Issue #15036: Mailbox no longer throws an error if a flush is done between operations when removing or changing multiple items in mbox, MMDF, or Babyl mailboxes. @@ -2978,6 +1733,9 @@ - Issue #14969: Better handling of exception chaining in contextlib.ExitStack +- Issue #14962: Update text coloring in IDLE shell window after changing + options. Patch by Roger Serwy. + - Issue #14963: Convert contextlib.ExitStack.__exit__ to use an iterative algorithm (Patch by Alon Horev) @@ -2990,11 +1748,6 @@ C-API ----- -- Issue #15146: Add PyType_FromSpecWithBases. Patch by Robin Schreiber. - -- Issue #15042: Add PyState_AddModule and PyState_RemoveModule. Add version - guard for Py_LIMITED_API additions. Patch by Robin Schreiber. - - Issue #13783: Inadvertent additions to the public C API in the PEP 380 implementation have either been removed or marked as private interfaces. @@ -3003,25 +1756,9 @@ - Issue #15000: Support the "unique" x32 architecture in _posixsubprocess.c. -IDLE ----- - -- Issue #9803: Don't close IDLE on saving if breakpoint is open. - Patch by Roger Serwy. - -- Issue #14962: Update text coloring in IDLE shell window after changing - options. Patch by Roger Serwy. - Documentation ------------- -- Issue #15176: Clarified behavior, documentation, and implementation - of os.listdir(). - -- Issue #14982: Document that pkgutil's iteration functions require the - non-standard iter_modules() method to be defined by an importer (something - the importlib importers do not define). - - Issue #15081: Document PyState_FindModule. Patch by Robin Schreiber. @@ -3030,9 +1767,6 @@ Tests ----- -- Issue #15187: Bugfix: remove temporary directories test_shutil was leaving - behind. - - Issue #14769: test_capi now has SkipitemTest, which cleverly checks for "parity" between PyArg_ParseTuple() and the Python/getargs.c static function skipitem() for all possible "format units". @@ -3121,18 +1855,34 @@ - Issue #14700: Fix two broken and undefined-behaviour-inducing overflow checks in old-style string formatting. +- Issue #14705: The PyArg_Parse() family of functions now support the 'p' format + unit, which accepts a "boolean predicate" argument. It converts any Python + value into an integer--0 if it is "false", and 1 otherwise. + Library ------- - Issue #14690: Use monotonic clock instead of system clock in the sched, subprocess and trace modules. +- Issue #14958: Change IDLE systax highlighting to recognize all string and + byte literals supported in Python 3.3. + +- Issue #10997: Prevent a duplicate entry in IDLE's "Recent Files" menu. + - Issue #14443: Tell rpmbuild to use the correct version of Python in bdist_rpm. Initial patch by Ross Lagerwall. +- Issue #14929: Stop Idle 3.x from closing on Unicode decode errors when + grepping. Patch by Roger Serwy. + - Issue #12515: email now registers a defect if it gets to EOF while parsing a MIME part without seeing the closing MIME boundary. +- Issue #12510: Attempting to get invalid tooltip no longer closes Idle. + Other tooltipss have been corrected or improved and the number of tests + has been tripled. Original patch by Roger Serwy. + - Issue #1672568: email now always decodes base64 payloads, adding padding and ignoring non-base64-alphabet characters if needed, and registering defects for any such problems. @@ -3166,6 +1916,9 @@ - Issue #14548: Make multiprocessing finalizers check pid before running to cope with possibility of gc running just after fork. +- Issue #14863: Update the documentation of os.fdopen() to reflect the + fact that it's only a thin wrapper around open() anymore. + - Issue #14036: Add an additional check to validate that port in urlparse does not go in illegal range and returns None. @@ -3292,21 +2045,6 @@ - Issue #14127 and #10148: shutil.copystat now preserves exact mtime and atime on filesystems providing nanosecond resolution. -IDLE ----- - -- Issue #14958: Change IDLE systax highlighting to recognize all string and - byte literals supported in Python 3.3. - -- Issue #10997: Prevent a duplicate entry in IDLE's "Recent Files" menu. - -- Issue #14929: Stop IDLE 3.x from closing on Unicode decode errors when - grepping. Patch by Roger Serwy. - -- Issue #12510: Attempting to get invalid tooltip no longer closes IDLE. - Other tooltipss have been corrected or improved and the number of tests - has been tripled. Original patch by Roger Serwy. - Tools/Demos ----------- @@ -3325,19 +2063,9 @@ - Issue #13210: Windows build now uses VS2010, ported from VS2008. -C-API ------ - -- Issue #14705: The PyArg_Parse() family of functions now support the 'p' format - unit, which accepts a "boolean predicate" argument. It converts any Python - value into an integer--0 if it is "false", and 1 otherwise. - Documentation ------------- -- Issue #14863: Update the documentation of os.fdopen() to reflect the - fact that it's only a thin wrapper around open() anymore. - - Issue #14588: The language reference now accurately documents the Python 3 class definition process. Patch by Nick Coghlan. @@ -3386,6 +2114,9 @@ - Issue #14339: Speed improvements to bin, oct and hex functions. Patch by Serhiy Storchaka. +- Issue #14098: New functions PyErr_GetExcInfo and PyErr_SetExcInfo. + Patch by Stefan Behnel. + - Issue #14385: It is now possible to use a custom type for the __builtins__ namespace, instead of a dict. It can be used for sandboxing for example. Raise also a NameError instead of ImportError if __build_class__ name if not @@ -3516,7 +2247,7 @@ - Issue #14399: zipfile now recognizes that the archive has been modified even if only the comment is changed. In addition, the TypeError that results from - trying to set a non-binary value as a comment is now raised at the time + trying to set a non-binary value as a comment is now now raised at the time the comment is set rather than at the time the zipfile is written. - trace.CoverageResults.is_ignored_filename() now ignores any name that starts @@ -3535,6 +2266,12 @@ - Don't Py_DECREF NULL variable in io.IncrementalNewlineDecoder. +- Issue #8515: Set __file__ when run file in IDLE. + Initial patch by Bruce Frederiksen. + +- Issue #14496: Fix wrong name in idlelib/tabbedpages.py. + Patch by Popa Claudiu. + - Issue #3033: Add displayof parameter to tkinter font. Patch by Guilherme Polo. - Issue #14482: Raise a ValueError, not a NameError, when trying to create @@ -3570,15 +2307,6 @@ - Issue #14355: Regrtest now supports the standard unittest test loading, and will use it if a test file contains no `test_main` method. -IDLE ----- - -- Issue #8515: Set __file__ when run file in IDLE. - Initial patch by Bruce Frederiksen. - -- Issue #14496: Fix wrong name in idlelib/tabbedpages.py. - Patch by Popa Claudiu. - Tools / Demos ------------- @@ -3588,12 +2316,6 @@ - Issue #13165: stringbench is now available in the Tools/stringbench folder. It used to live in its own SVN project. -C-API ------ - -- Issue #14098: New functions PyErr_GetExcInfo and PyErr_SetExcInfo. - Patch by Stefan Behnel. - What's New in Python 3.3.0 Alpha 2? =================================== @@ -3645,9 +2367,16 @@ - Issue #5136: deprecate old, unused functions from tkinter. +- Issue #14409: IDLE now properly executes commands in the Shell window + when it cannot read the normal config files on startup and + has to use the built-in default key bindings. + There was previously a bug in one of the defaults. + - Issue #14416: syslog now defines the LOG_ODELAY and LOG_AUTHPRIV constants if they are defined in . +- IDLE can be launched as python -m idlelib + - Issue #14295: Add unittest.mock - Issue #7652: Add --with-system-libmpdec option to configure for linking @@ -3673,6 +2402,9 @@ up the decimal module. Performance gains of the new C implementation are between 10x and 100x, depending on the application. +- Issue #3573: IDLE hangs when passing invalid command line args + (directory(ies) instead of file(s)) (Patch by Guilherme Polo) + - Issue #14269: SMTPD now conforms to the RFC and requires a HELO command before MAIL, RCPT, or DATA. @@ -3704,6 +2436,8 @@ denial of service due to hash collisions. Patch by David Malcolm with some modifications by the expat project. +- Issue #14200: Idle shell crash on printing non-BMP unicode character. + - Issue #12818: format address no longer needlessly \ escapes ()s in names when the name ends up being quoted. @@ -3719,6 +2453,8 @@ - Issue #989712: Support using Tk without a mainloop. +- Issue #5219: Prevent event handler cascade in IDLE. + - Issue #3835: Refuse to use unthreaded Tcl in threaded Python. - Issue #2843: Add new Tk API to Tkinter. @@ -3947,6 +2683,10 @@ on POSIX systems supporting anonymous memory mappings. Patch by Charles-François Natali. +- Issue #13452: PyUnicode_EncodeDecimal() doesn't support error handlers + different than "strict" anymore. The caller was unable to compute the + size of the output buffer: it depends on the error handler. + - PEP 3155 / issue #13448: Qualified name for classes and functions. - Issue #13436: Fix a bogus error message when an AST object was passed @@ -4037,6 +2777,10 @@ - PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy. +- Issue #13560: Add PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize() + and PyUnicode_EncodeLocale() functions to the C API to decode/encode from/to + the current locale encoding. + - Add internal API for static strings (_Py_identifier et al.). - Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described @@ -4282,11 +3026,17 @@ PyUnicode_AsUTF8String() and PyUnicode_AsEncodedString(unicode, "utf-8", NULL). +- Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats. + - Issue #10829: Refactor PyUnicode_FromFormat(), use the same function to parse the format string in the 3 steps, fix crashs on invalid format strings. - Issue #13007: whichdb should recognize gdbm 1.9 magic numbers. +- Issue #11246: Fix PyUnicode_FromFormat("%V") to decode the byte string from + UTF-8 (with replace error handler) instead of ISO-8859-1 (in strict mode). + Patch written by Ray Allen. + - Issue #11286: Raise a ValueError from calling PyMemoryView_FromBuffer with a buffer struct having a NULL data pointer. @@ -4296,6 +3046,9 @@ - Issue #11828: startswith and endswith now accept None as slice index. Patch by Torsten Becker. +- Issue #10830: Fix PyUnicode_FromFormatV("%c") for non-BMP characters on + narrow build. + - Issue #11168: Remove filename debug variable from PyEval_EvalFrameEx(). It encoded the Unicode filename to UTF-8, but the encoding fails on undecodable filename (on surrogate characters) which raises an unexpected @@ -4337,9 +3090,15 @@ are dead or dying. Moreover, the implementation is now O(1) rather than O(n). +- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode. + Patch by Mikhail Novikov. + - Issue #11841: Fix comparison bug with 'rc' versions in packaging.version. Patch by Filip GruszczyÅ„ski. +- Issue #13447: Add a test file to host regression tests for bugs in the + scripts found in the Tools directory. + - Issue #6884: Fix long-standing bugs with MANIFEST.in parsing in distutils on Windows. Also fixed in packaging. @@ -4395,6 +3154,9 @@ authenticating (since the result may change, according to RFC 4643). Patch by Hynek Schlawack. +- Issue #13989: Document that GzipFile does not support text mode, and give a + more helpful error message when opened with an invalid mode string. + - Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building Distutils-based packages with C extension modules may fail because Apple has removed gcc-4.2, the version used to build python.org @@ -4411,6 +3173,10 @@ - Issue #13960: HTMLParser is now able to handle broken comments when strict=False. +- Issue #13921: Undocument and clean up sqlite3.OptimizedUnicode, + which is obsolete in Python 3.x. It's now aliased to str for + backwards compatibility. + - When '' is a path (e.g. in sys.path), make sure __file__ uses the current working directory instead of '' in importlib. @@ -4432,6 +3198,11 @@ - Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now. +- Issue #10881: Fix test_site failure with OS X framework builds. + +- Issue #964437: Make IDLE help window non-modal. + Patch by Guilherme Polo and Roger Serwy. + - Issue #13734: Add os.fwalk(), a directory walking function yielding file descriptors. @@ -4441,8 +3212,16 @@ - Issue #11805: package_data in setup.cfg should allow more than one value. +- Issue #13933: IDLE auto-complete did not work with some imported + module, like hashlib. (Patch by Roger Serwy) + +- Issue #13901: Prevent test_distutils failures on OS X with --enable-shared. + - Issue #13676: Handle strings with embedded zeros correctly in sqlite3. +- Issue #13506: Add '' to path for IDLE Shell when started and restarted with Restart Shell. + Original patches by Marco Scataglini and Roger Serwy. + - Issue #8828: Add new function os.replace(), for cross-platform renaming with overwriting. @@ -4463,6 +3242,12 @@ OSError if localtime() failed. time.clock() now raises a RuntimeError if the processor time used is not available or its value cannot be represented +- Issue #13862: Fix spurious failure in test_zlib due to runtime/compile time + minor versions not matching. + +- Issue #12804: Fix test_socket and test_urllib2net failures when running tests + on a system without internet access. + - Issue #13772: In os.symlink() under Windows, do not try to guess the link target's type (file or directory). The detection was buggy and made the call non-atomic (therefore prone to race conditions). @@ -4489,6 +3274,9 @@ - Issue #13642: Unquote before b64encoding user:password during Basic Authentication. Patch contributed by Joonas Kuorilehto. +- Issue #13726: Fix the ambiguous -S flag in regrtest. It is -o/--slow for slow + tests. + - Issue #12364: Fix a hang in concurrent.futures.ProcessPoolExecutor. The hang would occur when retrieving the result of a scheduled future after the executor had been shut down. @@ -4571,6 +3359,10 @@ - Issue #13591: A bug in importlib has been fixed that caused import_module to load a module twice. +- Issue #4625: If IDLE cannot write to its recent file or breakpoint files, + display a message popup and continue rather than crash. Original patch by + Roger Serwy. + - Issue #13449 sched.scheduler.run() method has a new "blocking" parameter which when set to False makes run() execute the scheduled events due to expire soonest (if any) and then return. Patch by Giampaolo Rodolà. @@ -4590,6 +3382,9 @@ - Issue #5905, #13560: time.strftime() is now using the current locale encoding, instead of UTF-8, if the wcsftime() function is not available. +- Issue #8641: Update IDLE 3 syntax coloring to recognize b".." and not u"..". + Patch by Tal Einat. + - Issue #13464: Add a readinto() method to http.client.HTTPResponse. Patch by Jon Kuhn. @@ -4701,6 +3496,9 @@ - Issue #10817: Fix urlretrieve function to raise ContentTooShortError even when reporthook is None. Patch by Jyrki Pulliainen. +- Issue #13296: Fix IDLE to clear compile __future__ flags on shell restart. + (Patch by Roger Serwy) + - Fix the xmlrpc.client user agent to return something similar to urllib.request user agent: "Python-xmlrpc/3.3". @@ -4803,6 +3601,10 @@ - Issue #13034: When decoding some SSL certificates, the subjectAltName extension could be unreported. +- Issue #9871: Prevent IDLE 3 crash when given byte stings + with invalid hex escape sequences, like b'\x0'. + (Original patch by Claudiu Popa.) + - Issue #12306: Expose the runtime version of the zlib C library as a constant, ZLIB_RUNTIME_VERSION, in the zlib module. Patch by Torsten Landschoff. @@ -4831,6 +3633,8 @@ - Issue #12878: Expose a __dict__ attribute on io.IOBase and its subclasses. +- Issue #12636: IDLE reads the coding cookie when executing a Python script. + - Issue #12494: On error, call(), check_call(), check_output() and getstatusoutput() functions of the subprocess module now kill the process, read its status (to avoid zombis) and close pipes. @@ -4900,6 +3704,9 @@ - Issue #10087: Fix the html output format of the calendar module. +- Issue #12540: Prevent zombie IDLE processes on Windows due to changes + in os.kill(). + - Issue #13121: add support for inplace math operators to collections.Counter. - Add support for unary plus and unary minus to collections.Counter. @@ -4945,9 +3752,15 @@ - Issue #12607: In subprocess, fix issue where if stdin, stdout or stderr is given as a low fd, it gets overwritten. +- Issue #12590: IDLE editor window now always displays the first line + when opening a long file. With Tk 8.5, the first line was hidden. + - Issue #12576: Fix urlopen behavior on sites which do not send (or obfuscates) Connection:close header. +- Issue #12102: Document that buffered files must be flushed before being used + with mmap. Patch by Steffen Daode Nurpmeso. + - Issue #12560: Build libpython.so on OpenBSD. Patch by Stefan Sperling. - Issue #1813: Fix codec lookup under Turkish locales. @@ -5074,7 +3887,7 @@ check or set the MACOSX_DEPLOYMENT_TARGET environment variable for the interpreter process. This could cause failures in non-Distutils subprocesses and was unreliable since tests or user programs could modify the interpreter - environment after Distutils set it. Instead, have Distutils set the + environment after Distutils set it. Instead, have Distutils set the the deployment target only in the environment of each build subprocess. It is still possible to globally override the default by setting MACOSX_DEPLOYMENT_TARGET before launching the interpreter; its value must be @@ -5246,6 +4059,9 @@ passing a ``context`` argument pointing to an ssl.SSLContext instance. Patch by Kasun Herath. +- Issue #11088: don't crash when using F5 to run a script in IDLE on MacOSX + with Tk 8.5. + - Issue #9516: Issue #9516: avoid errors in sysconfig when MACOSX_DEPLOYMENT_TARGET is set in shell. @@ -5265,6 +4081,10 @@ - Issue #9971: Write an optimized implementation of BufferedReader.readinto(). Patch by John O'Connor. +- Issue #1028: Tk returns invalid Unicode null in %A: UnicodeDecodeError. + With Tk < 8.5 _tkinter.c:PythonCmd() raised UnicodeDecodeError, caused + IDLE to exit. Converted to valid Unicode null in PythonCmd(). + - Issue #11799: urllib.request Authentication Handlers will raise a ValueError when presented with an unsupported Authentication Scheme. Patch contributed by Yuval Greenfield. @@ -5501,12 +4321,12 @@ - Issue #7639: Fix short file name generation in bdist_msi +- Issue #11659: Fix ResourceWarning in test_subprocess introduced by #11459. + Patch by Ben Hayden. + - Issue #11635: Don't use polling in worker threads and processes launched by concurrent.futures. -- Issue #5845: Automatically read readline configuration to enable completion - in interactive mode. - - Issue #6811: Allow importlib to change a code object's co_filename attribute to match the path to where the source code currently is, not where the code object originally came from. @@ -5556,6 +4376,8 @@ - Issue #10979: unittest stdout buffering now works with class and module setup and teardown. +- Issue #11577: fix ResourceWarning triggered by improved binhex test coverage + - Issue #11243: fix the parameter querying methods of Message to work if the headers contain un-encoded non-ASCII data. @@ -5588,6 +4410,9 @@ - Issue #11554: Fixed support for Japanese codecs; previously the body output encoding was not done if euc-jp or shift-jis was specified as the charset. +- Issue #11509: Significantly increase test coverage of fileinput. + Patch by Denver Coneybeare at PyCon 2011 Sprints. + - Issue #11407: `TestCase.run` returns the result object used or created. Contributed by Janathan Hartley. @@ -5710,6 +4535,11 @@ - Issue #9348: Raise an early error if argparse nargs and metavar don't match. +- Issue #8982: Improve the documentation for the argparse Namespace object. + +- Issue #9343: Document that argparse parent parsers must be configured before + their children. + - Issue #9026: Fix order of argparse sub-commands in help messages. - Issue #9347: Fix formatting for tuples in argparse type= error messages. @@ -5762,61 +4592,10 @@ - Issue #11495: OSF support is eliminated. It was deprecated in Python 3.2. + IDLE ---- -- Issue #14409: IDLE now properly executes commands in the Shell window - when it cannot read the normal config files on startup and - has to use the built-in default key bindings. - There was previously a bug in one of the defaults. - -- IDLE can be launched as python -m idlelib - -- Issue #3573: IDLE hangs when passing invalid command line args - (directory(ies) instead of file(s)) (Patch by Guilherme Polo) - -- Issue #14200: IDLE shell crash on printing non-BMP unicode character. - -- Issue #5219: Prevent event handler cascade in IDLE. - -- Issue #964437: Make IDLE help window non-modal. - Patch by Guilherme Polo and Roger Serwy. - -- Issue #13933: IDLE auto-complete did not work with some imported - module, like hashlib. (Patch by Roger Serwy) - -- Issue #13506: Add '' to path for IDLE Shell when started and restarted with Restart Shell. - Original patches by Marco Scataglini and Roger Serwy. - -- Issue #4625: If IDLE cannot write to its recent file or breakpoint files, - display a message popup and continue rather than crash. Original patch by - Roger Serwy. - -- Issue #8641: Update IDLE 3 syntax coloring to recognize b".." and not u"..". - Patch by Tal Einat. - -- Issue #13296: Fix IDLE to clear compile __future__ flags on shell restart. - (Patch by Roger Serwy) - -- Issue #9871: Prevent IDLE 3 crash when given byte stings - with invalid hex escape sequences, like b'\x0'. - (Original patch by Claudiu Popa.) - -- Issue #12636: IDLE reads the coding cookie when executing a Python script. - -- Issue #12540: Prevent zombie IDLE processes on Windows due to changes - in os.kill(). - -- Issue #12590: IDLE editor window now always displays the first line - when opening a long file. With Tk 8.5, the first line was hidden. - -- Issue #11088: don't crash when using F5 to run a script in IDLE on MacOSX - with Tk 8.5. - -- Issue #1028: Tk returns invalid Unicode null in %A: UnicodeDecodeError. - With Tk < 8.5 _tkinter.c:PythonCmd() raised UnicodeDecodeError, caused - IDLE to exit. Converted to valid Unicode null in PythonCmd(). - - Issue #11718: IDLE's open module dialog couldn't find the __init__.py file in a package. @@ -5912,33 +4691,6 @@ Tests ----- -- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode. - Patch by Mikhail Novikov. - -- Issue #13447: Add a test file to host regression tests for bugs in the - scripts found in the Tools directory. - -- Issue #10881: Fix test_site failure with OS X framework builds. - -- Issue #13901: Prevent test_distutils failures on OS X with --enable-shared. - -- Issue #13862: Fix spurious failure in test_zlib due to runtime/compile time - minor versions not matching. - -- Issue #12804: Fix test_socket and test_urllib2net failures when running tests - on a system without internet access. - -- Issue #13726: Fix the ambiguous -S flag in regrtest. It is -o/--slow for slow - tests. - -- Issue #11659: Fix ResourceWarning in test_subprocess introduced by #11459. - Patch by Ben Hayden. - -- Issue #11577: fix ResourceWarning triggered by improved binhex test coverage - -- Issue #11509: Significantly increase test coverage of fileinput. - Patch by Denver Coneybeare at PyCon 2011 Sprints. - - Issue #11689: Fix a variable scoping error in an sqlite3 test - Issue #13786: Remove unimplemented 'trace' long option from regrtest.py. @@ -6141,23 +4893,6 @@ C-API ----- -- Issue #13452: PyUnicode_EncodeDecimal() doesn't support error handlers - different than "strict" anymore. The caller was unable to compute the - size of the output buffer: it depends on the error handler. - -- Issue #13560: Add PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize() - and PyUnicode_EncodeLocale() functions to the C API to decode/encode from/to - the current locale encoding. - -- Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats. - -- Issue #11246: Fix PyUnicode_FromFormat("%V") to decode the byte string from - UTF-8 (with replace error handler) instead of ISO-8859-1 (in strict mode). - Patch written by Ray Allen. - -- Issue #10830: Fix PyUnicode_FromFormatV("%c") for non-BMP characters on - narrow build. - - Add PyObject_GenericGetDict and PyObject_GeneriSetDict. They are generic implementations for the getter and setter of a ``__dict__`` descriptor of C types. @@ -6183,21 +4918,6 @@ Documentation ------------- -- Issue #13989: Document that GzipFile does not support text mode, and give a - more helpful error message when opened with an invalid mode string. - -- Issue #13921: Undocument and clean up sqlite3.OptimizedUnicode, - which is obsolete in Python 3.x. It's now aliased to str for - backwards compatibility. - -- Issue #12102: Document that buffered files must be flushed before being used - with mmap. Patch by Steffen Daode Nurpmeso. - -- Issue #8982: Improve the documentation for the argparse Namespace object. - -- Issue #9343: Document that argparse parent parsers must be configured before - their children. - - Issue #13498: Clarify docs of os.makedirs()'s exist_ok argument. Done with great native-speaker help from R. David Murray. diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/README --- a/Misc/README Fri Jul 26 23:14:22 2013 -0700 +++ b/Misc/README Fri Feb 01 23:12:09 2013 +0100 @@ -27,3 +27,4 @@ TextMate A TextMate bundle for Python development valgrind-python.supp Valgrind suppression file, see README.valgrind vgrindefs Python configuration for vgrind (a generic pretty printer) +Vim Python development utilities for the Vim editor diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/coverity_model.c --- a/Misc/coverity_model.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -/* Coverity Scan model - * - * This is a modeling file for Coverity Scan. Modeling helps to avoid false - * positives. - * - * - A model file can't import any header files. - * - Therefore only some built-in primitives like int, char and void are - * available but not wchar_t, NULL etc. - * - Modeling doesn't need full structs and typedefs. Rudimentary structs - * and similar types are sufficient. - * - An uninitialized local pointer is not an error. It signifies that the - * variable could be either NULL or have some data. - * - * Coverity Scan doesn't pick up modifications automatically. The model file - * must be uploaded by an admin in the analysis settings of - * http://scan.coverity.com/projects/200 - */ - -/* dummy definitions, in most cases struct fields aren't required. */ - -#define NULL (void *)0 -#define assert(op) /* empty */ -typedef int sdigit; -typedef long Py_ssize_t; -typedef long long PY_LONG_LONG; -typedef unsigned short wchar_t; -typedef struct {} PyObject; -typedef struct {} grammar; -typedef struct {} DIR; -typedef struct {} RFILE; - -/* Python/pythonrun.c - * resourece leak false positive */ - -void Py_FatalError(const char *msg) { - __coverity_panic__(); -} - -/* Objects/longobject.c - * NEGATIVE_RETURNS false positive */ - -static PyObject *get_small_int(sdigit ival) -{ - /* Never returns NULL */ - PyObject *p; - assert(p != NULL); - return p; -} - -PyObject *PyLong_FromLong(long ival) -{ - PyObject *p; - int maybe; - - if ((ival >= -5) && (ival < 257 + 5)) { - p = get_small_int(ival); - assert(p != NULL); - return p; - } - if (maybe) - return p; - else - return NULL; -} - -PyObject *PyLong_FromLongLong(PY_LONG_LONG ival) -{ - return PyLong_FromLong((long)ival); -} - -PyObject *PyLong_FromSsize_t(Py_ssize_t ival) -{ - return PyLong_FromLong((long)ival); -} - -/* tainted sinks - * - * Coverity considers argv, environ, read() data etc as tained. - */ - -PyObject *PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename) -{ - __coverity_tainted_data_sink__(filename); - return NULL; -} - -/* Python/fileutils.c */ -wchar_t *_Py_char2wchar(const char* arg, size_t *size) -{ - wchar_t *w; - __coverity_tainted_data_sink__(arg); - __coverity_tainted_data_sink__(size); - return w; -} - -/* Parser/pgenmain.c */ -grammar *getgrammar(char *filename) -{ - grammar *g; - __coverity_tainted_data_sink__(filename); - return g; -} - -/* Python/marshal.c */ - -static Py_ssize_t r_string(char *s, Py_ssize_t n, RFILE *p) -{ - __coverity_tainted_string_argument__(s); - return 0; -} - -static long r_long(RFILE *p) -{ - long l; - unsigned char buffer[4]; - - r_string((char *)buffer, 4, p); - __coverity_tainted_string_sanitize_content__(buffer); - l = (long)buffer; - return l; -} - -/* Coverity doesn't understand that fdopendir() may take ownership of fd. */ - -DIR *fdopendir(int fd) { - DIR *d; - if (d) { - __coverity_close__(fd); - } - return d; -} - diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/python-config.in --- a/Misc/python-config.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Misc/python-config.in Fri Feb 01 23:12:09 2013 +0100 @@ -57,7 +57,7 @@ print(' '.join(libs)) elif opt == '--extension-suffix': - print(sysconfig.get_config_var('EXT_SUFFIX')) + print(sysconfig.get_config_var('SO')) elif opt == '--abiflags': print(sys.abiflags) diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/python-config.sh.in --- a/Misc/python-config.sh.in Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -#!/bin/sh - -exit_with_usage () -{ - echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir" - exit $1 -} - -if [ "$1" = "" ] ; then - exit_with_usage 1 -fi - -# Returns the actual prefix where this script was installed to. -installed_prefix () -{ - RESULT=$(dirname $(cd $(dirname "$1") && pwd -P)) - if which readlink >/dev/null 2>&1 ; then - RESULT=$(readlink -f "$RESULT") - fi - echo $RESULT -} - -prefix_build="@prefix@" -prefix_real=$(installed_prefix "$0") - -# Use sed to fix paths from their built to locations to their installed to locations. -prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#") -exec_prefix_build="@exec_prefix@" -exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#") -includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#") -libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#") -CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#") -VERSION="@VERSION@" -LIBM="@LIBM@" -LIBC="@LIBC@" -SYSLIBS="$LIBM $LIBC" -ABIFLAGS="@ABIFLAGS@" -LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}${ABIFLAGS}" -BASECFLAGS="@BASECFLAGS@" -LDLIBRARY="@LDLIBRARY@" -LINKFORSHARED="@LINKFORSHARED@" -OPT="@OPT@" -PY_ENABLE_SHARED="@PY_ENABLE_SHARED@" -LDVERSION="@LDVERSION@" -LIBDEST=${prefix}/lib/python${VERSION} -LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#") -SO="@SO@" -PYTHONFRAMEWORK="@PYTHONFRAMEWORK@" -INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" -PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" - -# Scan for --help or unknown argument. -for ARG in $* -do - case $ARG in - --help) - exit_with_usage 0 - ;; - --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir) - ;; - *) - exit_with_usage 1 - ;; - esac -done - -for ARG in "$@" -do - case "$ARG" in - --prefix) - echo "$prefix" - ;; - --exec-prefix) - echo "$exec_prefix" - ;; - --includes) - echo "$INCDIR $PLATINCDIR" - ;; - --cflags) - echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT" - ;; - --libs) - echo "$LIBS" - ;; - --ldflags) - LINKFORSHAREDUSED= - if [ -z "$PYTHONFRAMEWORK" ] ; then - LINKFORSHAREDUSED=$LINKFORSHARED - fi - LIBPLUSED= - if [ "$PY_ENABLE_SHARED" = "0" ] ; then - LIBPLUSED="-L$LIBPL" - fi - echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED" - ;; - --extension-suffix) - echo "$SO" - ;; - --abiflags) - echo "$ABIFLAGS" - ;; - --configdir) - echo "$LIBPL" - ;; -esac -done diff -r 35c88c53cf64 -r ecc10f0afb76 Misc/python.man --- a/Misc/python.man Fri Jul 26 23:14:22 2013 -0700 +++ b/Misc/python.man Fri Feb 01 23:12:09 2013 +0100 @@ -11,9 +11,6 @@ .B \-B ] [ -.B \-b -] -[ .B \-d ] [ @@ -26,14 +23,14 @@ .B \-i ] [ -.B \-m +.B \-m .I module-name ] +[ +.B \-q +] .br [ -.B \-q -] -[ .B \-O ] [ @@ -63,10 +60,6 @@ .B \-x ] [ -[ -.B \-X -.I option -] .B \-? ] .br @@ -112,10 +105,6 @@ .I .py[co] files on import. See also PYTHONDONTWRITEBYTECODE. .TP -.B \-b -Issue warnings about str(bytes_instance), str(bytearray_instance) -and comparing bytes/bytearray with str. (-bb: issue errors) -.TP .BI "\-c " command Specify the command to execute (see next section). This terminates the option list (following options are passed as @@ -172,8 +161,7 @@ is explicitly imported later. .TP .B \-u -Force the binary I/O layers of stdout and stderr to be unbuffered. -stdin is always buffered. +Force the binary I/O layers of stdin, stdout and stderr to be unbuffered. The text I/O layer will still be line-buffered. .\" Note that there is internal buffering in readlines() and .\" file-object iterators ("for line in sys.stdin") which is not @@ -255,9 +243,6 @@ field matches the line number, where zero matches all line numbers and is thus equivalent to an omitted line number. .TP -.BI "\-X " option -Set implementation specific option. -.TP .B \-x Skip the first line of the source. This is intended for a DOS specific hack only. Warning: the line numbers in error messages will diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/Setup.dist --- a/Modules/Setup.dist Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/Setup.dist Fri Feb 01 23:12:09 2013 +0100 @@ -113,11 +113,9 @@ _codecs _codecsmodule.c # access to the builtin codecs and codec registry _weakref _weakref.c # weak references _functools _functoolsmodule.c # Tools for working with functions and callable objects -_operator _operator.c # operator.add() and similar goodies +operator operator.c # operator.add() and similar goodies _collections _collectionsmodule.c # Container types itertools itertoolsmodule.c # Functions creating iterators for efficient looping -atexit atexitmodule.c # Register functions to be run at interpreter-shutdown -_stat _stat.c # stat.h interface # access to ISO C locale support _locale _localemodule.c # -lintl @@ -172,6 +170,7 @@ #_weakref _weakref.c # basic weak reference support #_testcapi _testcapimodule.c # Python C API test module #_random _randommodule.c # Random number generator +#atexit atexitmodule.c # Register functions to be run at interpreter-shutdown #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator #_pickle _pickle.c # pickle accelerator #_datetime _datetimemodule.c # datetime accelerator diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_bz2module.c --- a/Modules/_bz2module.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_bz2module.c Fri Feb 01 23:12:09 2013 +0100 @@ -36,6 +36,8 @@ #define RELEASE_LOCK(obj) #endif +#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) + typedef struct { PyObject_HEAD @@ -147,7 +149,7 @@ c->bzs.next_in = data; c->bzs.avail_in = 0; c->bzs.next_out = PyBytes_AS_STRING(result); - c->bzs.avail_out = SMALLCHUNK; + c->bzs.avail_out = PyBytes_GET_SIZE(result); for (;;) { char *this_out; int bzerror; @@ -155,7 +157,7 @@ /* On a 64-bit system, len might not fit in avail_in (an unsigned int). Do compression in chunks of no more than UINT_MAX bytes each. */ if (c->bzs.avail_in == 0 && len > 0) { - c->bzs.avail_in = (unsigned int)Py_MIN(len, UINT_MAX); + c->bzs.avail_in = MIN(len, UINT_MAX); len -= c->bzs.avail_in; } @@ -171,7 +173,7 @@ c->bzs.next_out = PyBytes_AS_STRING(result) + data_size; buffer_left = PyBytes_GET_SIZE(result) - data_size; } - c->bzs.avail_out = (unsigned int)Py_MIN(buffer_left, UINT_MAX); + c->bzs.avail_out = MIN(buffer_left, UINT_MAX); } Py_BEGIN_ALLOW_THREADS @@ -248,24 +250,6 @@ return result; } -static void* -BZ2_Malloc(void* ctx, int items, int size) -{ - if (items < 0 || size < 0) - return NULL; - if ((size_t)items > (size_t)PY_SSIZE_T_MAX / (size_t)size) - return NULL; - /* PyMem_Malloc() cannot be used: compress() and decompress() - release the GIL */ - return PyMem_RawMalloc(items * size); -} - -static void -BZ2_Free(void* ctx, void *ptr) -{ - PyMem_RawFree(ptr); -} - static int BZ2Compressor_init(BZ2Compressor *self, PyObject *args, PyObject *kwargs) { @@ -288,9 +272,6 @@ } #endif - self->bzs.opaque = NULL; - self->bzs.bzalloc = BZ2_Malloc; - self->bzs.bzfree = BZ2_Free; bzerror = BZ2_bzCompressInit(&self->bzs, compresslevel, 0, 0); if (catch_bz2_error(bzerror)) goto error; @@ -389,10 +370,10 @@ d->bzs.next_in = data; /* On a 64-bit system, len might not fit in avail_in (an unsigned int). Do decompression in chunks of no more than UINT_MAX bytes each. */ - d->bzs.avail_in = (unsigned int)Py_MIN(len, UINT_MAX); + d->bzs.avail_in = MIN(len, UINT_MAX); len -= d->bzs.avail_in; d->bzs.next_out = PyBytes_AS_STRING(result); - d->bzs.avail_out = SMALLCHUNK; + d->bzs.avail_out = PyBytes_GET_SIZE(result); for (;;) { char *this_out; int bzerror; @@ -418,7 +399,7 @@ if (d->bzs.avail_in == 0) { if (len == 0) break; - d->bzs.avail_in = (unsigned int)Py_MIN(len, UINT_MAX); + d->bzs.avail_in = MIN(len, UINT_MAX); len -= d->bzs.avail_in; } if (d->bzs.avail_out == 0) { @@ -429,7 +410,7 @@ d->bzs.next_out = PyBytes_AS_STRING(result) + data_size; buffer_left = PyBytes_GET_SIZE(result) - data_size; } - d->bzs.avail_out = (unsigned int)Py_MIN(buffer_left, UINT_MAX); + d->bzs.avail_out = MIN(buffer_left, UINT_MAX); } } if (data_size != PyBytes_GET_SIZE(result)) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_collectionsmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -3,29 +3,30 @@ /* collections module implementation of a deque() datatype Written and maintained by Raymond D. Hettinger - Copyright (c) 2004-2013 Python Software Foundation. + Copyright (c) 2004 Python Software Foundation. All rights reserved. */ /* The block length may be set to any number over 1. Larger numbers - * reduce the number of calls to the memory allocator, give faster - * indexing and rotation, and reduce the link::data overhead ratio. - * If the block length is a power-of-two, we also get faster - * division/modulo computations during indexing. + * reduce the number of calls to the memory allocator but take more + * memory. Ideally, BLOCKLEN should be set with an eye to the + * length of a cache line. */ -#define BLOCKLEN 64 +#define BLOCKLEN 62 #define CENTER ((BLOCKLEN - 1) / 2) /* A `dequeobject` is composed of a doubly-linked list of `block` nodes. + * This list is not circular (the leftmost block has leftlink==NULL, + * and the rightmost block has rightlink==NULL). A deque d's first + * element is at d.leftblock[leftindex] and its last element is at + * d.rightblock[rightindex]; note that, unlike as for Python slice + * indices, these indices are inclusive on both ends. By being inclusive + * on both ends, algorithms for left and right operations become + * symmetrical which simplifies the design. + * * The list of blocks is never empty, so d.leftblock and d.rightblock - * are never equal to NULL. The list is not circular. - * - * A deque d's first element is at d.leftblock[leftindex] - * and its last element is at d.rightblock[rightindex]. - * Unlike Python slice indices, these indices are inclusive - * on both ends. This makes the algorithms for left and - * right operations more symmetrical and simplifies the design. + * are never equal to NULL. * * The indices, d.leftindex and d.rightindex are always in the range * 0 <= index < BLOCKLEN. @@ -46,60 +47,42 @@ typedef struct BLOCK { struct BLOCK *leftlink; + struct BLOCK *rightlink; PyObject *data[BLOCKLEN]; - struct BLOCK *rightlink; } block; -/* For debug builds, add error checking to track the endpoints - * in the chain of links. The goal is to make sure that link - * assignments only take place at endpoints so that links already - * in use do not get overwritten. - * - * CHECK_END should happen before each assignment to a block's link field. - * MARK_END should happen whenever a link field becomes a new endpoint. - * This happens when new blocks are added or whenever an existing - * block is freed leaving another existing block as the new endpoint. - */ - -#ifndef NDEBUG -#define MARK_END(link) link = NULL; -#define CHECK_END(link) assert(link == NULL); -#define CHECK_NOT_END(link) assert(link != NULL); -#else -#define MARK_END(link) -#define CHECK_END(link) -#define CHECK_NOT_END(link) -#endif - -/* A simple freelisting scheme is used to minimize calls to the memory - allocator. It accomodates common use cases where new blocks are being - added at about the same rate as old blocks are being freed. - */ - #define MAXFREEBLOCKS 10 static Py_ssize_t numfreeblocks = 0; static block *freeblocks[MAXFREEBLOCKS]; static block * -newblock(Py_ssize_t len) { +newblock(block *leftlink, block *rightlink, Py_ssize_t len) { block *b; - /* To prevent len from overflowing PY_SSIZE_T_MAX, we refuse to - * allocate new blocks if the current len is nearing overflow. */ + /* To prevent len from overflowing PY_SSIZE_T_MAX on 64-bit machines, we + * refuse to allocate new blocks if the current len is dangerously + * close. There is some extra margin to prevent spurious arithmetic + * overflows at various places. The following check ensures that + * the blocks allocated to the deque, in the worst case, can only + * have PY_SSIZE_T_MAX-2 entries in total. + */ if (len >= PY_SSIZE_T_MAX - 2*BLOCKLEN) { PyErr_SetString(PyExc_OverflowError, "cannot add more blocks to the deque"); return NULL; } if (numfreeblocks) { - numfreeblocks--; - return freeblocks[numfreeblocks]; + numfreeblocks -= 1; + b = freeblocks[numfreeblocks]; + } else { + b = PyMem_Malloc(sizeof(block)); + if (b == NULL) { + PyErr_NoMemory(); + return NULL; + } } - b = PyMem_Malloc(sizeof(block)); - if (b != NULL) { - return b; - } - PyErr_NoMemory(); - return NULL; + b->leftlink = leftlink; + b->rightlink = rightlink; + return b; } static void @@ -114,13 +97,14 @@ } typedef struct { - PyObject_VAR_HEAD + PyObject_HEAD block *leftblock; block *rightblock; Py_ssize_t leftindex; /* in range(BLOCKLEN) */ Py_ssize_t rightindex; /* in range(BLOCKLEN) */ - long state; /* incremented whenever the indices move */ + Py_ssize_t len; Py_ssize_t maxlen; + long state; /* incremented whenever the indices move */ PyObject *weakreflist; /* List of weak references */ } dequeobject; @@ -134,9 +118,9 @@ */ #define TRIM(d, popfunction) \ - if (d->maxlen != -1 && Py_SIZE(d) > d->maxlen) { \ + if (d->maxlen != -1 && d->len > d->maxlen) { \ PyObject *rv = popfunction(d, NULL); \ - assert(rv != NULL && Py_SIZE(d) <= d->maxlen); \ + assert(rv != NULL && d->len <= d->maxlen); \ Py_DECREF(rv); \ } @@ -153,20 +137,18 @@ if (deque == NULL) return NULL; - b = newblock(0); + b = newblock(NULL, NULL, 0); if (b == NULL) { Py_DECREF(deque); return NULL; } - MARK_END(b->leftlink); - MARK_END(b->rightlink); assert(BLOCKLEN >= 2); deque->leftblock = b; deque->rightblock = b; deque->leftindex = CENTER + 1; deque->rightindex = CENTER; - Py_SIZE(deque) = 0; + deque->len = 0; deque->state = 0; deque->weakreflist = NULL; deque->maxlen = -1; @@ -180,17 +162,17 @@ PyObject *item; block *prevblock; - if (Py_SIZE(deque) == 0) { + if (deque->len == 0) { PyErr_SetString(PyExc_IndexError, "pop from an empty deque"); return NULL; } item = deque->rightblock->data[deque->rightindex]; deque->rightindex--; - Py_SIZE(deque)--; + deque->len--; deque->state++; if (deque->rightindex == -1) { - if (Py_SIZE(deque) == 0) { + if (deque->len == 0) { assert(deque->leftblock == deque->rightblock); assert(deque->leftindex == deque->rightindex+1); /* re-center instead of freeing a block */ @@ -200,8 +182,7 @@ prevblock = deque->rightblock->leftlink; assert(deque->leftblock != deque->rightblock); freeblock(deque->rightblock); - CHECK_NOT_END(prevblock); - MARK_END(prevblock->rightlink); + prevblock->rightlink = NULL; deque->rightblock = prevblock; deque->rightindex = BLOCKLEN - 1; } @@ -217,18 +198,18 @@ PyObject *item; block *prevblock; - if (Py_SIZE(deque) == 0) { + if (deque->len == 0) { PyErr_SetString(PyExc_IndexError, "pop from an empty deque"); return NULL; } assert(deque->leftblock != NULL); item = deque->leftblock->data[deque->leftindex]; deque->leftindex++; - Py_SIZE(deque)--; + deque->len--; deque->state++; if (deque->leftindex == BLOCKLEN) { - if (Py_SIZE(deque) == 0) { + if (deque->len == 0) { assert(deque->leftblock == deque->rightblock); assert(deque->leftindex == deque->rightindex+1); /* re-center instead of freeing a block */ @@ -238,8 +219,8 @@ assert(deque->leftblock != deque->rightblock); prevblock = deque->leftblock->rightlink; freeblock(deque->leftblock); - CHECK_NOT_END(prevblock); - MARK_END(prevblock->leftlink); + assert(prevblock != NULL); + prevblock->leftlink = NULL; deque->leftblock = prevblock; deque->leftindex = 0; } @@ -254,18 +235,16 @@ { deque->state++; if (deque->rightindex == BLOCKLEN-1) { - block *b = newblock(Py_SIZE(deque)); + block *b = newblock(deque->rightblock, NULL, deque->len); if (b == NULL) return NULL; - b->leftlink = deque->rightblock; - CHECK_END(deque->rightblock->rightlink); + assert(deque->rightblock->rightlink == NULL); deque->rightblock->rightlink = b; deque->rightblock = b; - MARK_END(b->rightlink); deque->rightindex = -1; } Py_INCREF(item); - Py_SIZE(deque)++; + deque->len++; deque->rightindex++; deque->rightblock->data[deque->rightindex] = item; TRIM(deque, deque_popleft); @@ -279,18 +258,16 @@ { deque->state++; if (deque->leftindex == 0) { - block *b = newblock(Py_SIZE(deque)); + block *b = newblock(NULL, deque->leftblock, deque->len); if (b == NULL) return NULL; - b->rightlink = deque->leftblock; - CHECK_END(deque->leftblock->leftlink); + assert(deque->leftblock->leftlink == NULL); deque->leftblock->leftlink = b; deque->leftblock = b; - MARK_END(b->leftlink); deque->leftindex = BLOCKLEN; } Py_INCREF(item); - Py_SIZE(deque)++; + deque->len++; deque->leftindex--; deque->leftblock->data[deque->leftindex] = item; TRIM(deque, deque_pop); @@ -332,14 +309,6 @@ return result; } - /* Space saving heuristic. Start filling from the left */ - if (Py_SIZE(deque) == 0) { - assert(deque->leftblock == deque->rightblock); - assert(deque->leftindex == deque->rightindex+1); - deque->leftindex = 1; - deque->rightindex = 0; - } - it = PyObject_GetIter(iterable); if (it == NULL) return NULL; @@ -350,20 +319,19 @@ while ((item = PyIter_Next(it)) != NULL) { deque->state++; if (deque->rightindex == BLOCKLEN-1) { - block *b = newblock(Py_SIZE(deque)); + block *b = newblock(deque->rightblock, NULL, + deque->len); if (b == NULL) { Py_DECREF(item); Py_DECREF(it); return NULL; } - b->leftlink = deque->rightblock; - CHECK_END(deque->rightblock->rightlink); + assert(deque->rightblock->rightlink == NULL); deque->rightblock->rightlink = b; deque->rightblock = b; - MARK_END(b->rightlink); deque->rightindex = -1; } - Py_SIZE(deque)++; + deque->len++; deque->rightindex++; deque->rightblock->data[deque->rightindex] = item; TRIM(deque, deque_popleft); @@ -393,14 +361,6 @@ return result; } - /* Space saving heuristic. Start filling from the right */ - if (Py_SIZE(deque) == 0) { - assert(deque->leftblock == deque->rightblock); - assert(deque->leftindex == deque->rightindex+1); - deque->leftindex = BLOCKLEN - 1; - deque->rightindex = BLOCKLEN - 2; - } - it = PyObject_GetIter(iterable); if (it == NULL) return NULL; @@ -411,20 +371,19 @@ while ((item = PyIter_Next(it)) != NULL) { deque->state++; if (deque->leftindex == 0) { - block *b = newblock(Py_SIZE(deque)); + block *b = newblock(NULL, deque->leftblock, + deque->len); if (b == NULL) { Py_DECREF(item); Py_DECREF(it); return NULL; } - b->rightlink = deque->leftblock; - CHECK_END(deque->leftblock->leftlink); + assert(deque->leftblock->leftlink == NULL); deque->leftblock->leftlink = b; deque->leftblock = b; - MARK_END(b->leftlink); deque->leftindex = BLOCKLEN; } - Py_SIZE(deque)++; + deque->len++; deque->leftindex--; deque->leftblock->data[deque->leftindex] = item; TRIM(deque, deque_pop); @@ -454,13 +413,9 @@ static int _deque_rotate(dequeobject *deque, Py_ssize_t n) { - block *b = NULL; - block *leftblock = deque->leftblock; - block *rightblock = deque->rightblock; - Py_ssize_t leftindex = deque->leftindex; - Py_ssize_t rightindex = deque->rightindex; - Py_ssize_t len=Py_SIZE(deque), halflen=len>>1; - int rv = -1; + Py_ssize_t i, len=deque->len, halflen=(len+1)>>1; + PyObject *item; + block *prevblock, *leftblock, *rightblock; if (len <= 1) return 0; @@ -471,108 +426,69 @@ else if (n < -halflen) n += len; } - assert(len > 1); - assert(-halflen <= n && n <= halflen); + assert(deque->len > 1); deque->state++; - while (n > 0) { - if (leftindex == 0) { + leftblock = deque->leftblock; + rightblock = deque->rightblock; + for (i=0 ; idata[deque->rightindex]; + assert (item != NULL); + deque->rightindex--; + if (deque->rightindex == -1) { + assert(rightblock != NULL); + prevblock = rightblock->leftlink; + assert(leftblock != rightblock); + freeblock(rightblock); + prevblock->rightlink = NULL; + deque->rightblock = rightblock = prevblock; + deque->rightindex = BLOCKLEN - 1; + } + if (deque->leftindex == 0) { + block *b = newblock(NULL, leftblock, deque->len); if (b == NULL) { - b = newblock(len); - if (b == NULL) - goto done; + deque->len--; + Py_DECREF(item); + return -1; } - b->rightlink = leftblock; - CHECK_END(leftblock->leftlink); + assert(leftblock->leftlink == NULL); leftblock->leftlink = b; - leftblock = b; - MARK_END(b->leftlink); - leftindex = BLOCKLEN; - b = NULL; + deque->leftblock = leftblock = b; + deque->leftindex = BLOCKLEN; } - assert(leftindex > 0); - { - PyObject **src, **dest; - Py_ssize_t m = n; - - if (m > rightindex + 1) - m = rightindex + 1; - if (m > leftindex) - m = leftindex; - assert (m > 0 && m <= len); - src = &rightblock->data[rightindex]; - dest = &leftblock->data[leftindex - 1]; - rightindex -= m; - leftindex -= m; - n -= m; - do { - *(dest--) = *(src--); - } while (--m); + deque->leftindex--; + leftblock->data[deque->leftindex] = item; + } + for (i=0 ; i>n ; i--) { + assert(leftblock != NULL); + item = leftblock->data[deque->leftindex]; + assert (item != NULL); + deque->leftindex++; + if (deque->leftindex == BLOCKLEN) { + assert(leftblock != rightblock); + prevblock = leftblock->rightlink; + freeblock(leftblock); + assert(prevblock != NULL); + prevblock->leftlink = NULL; + deque->leftblock = leftblock = prevblock; + deque->leftindex = 0; } - if (rightindex == -1) { - assert(leftblock != rightblock); - assert(b == NULL); - b = rightblock; - CHECK_NOT_END(rightblock->leftlink); - rightblock = rightblock->leftlink; - MARK_END(rightblock->rightlink); - rightindex = BLOCKLEN - 1; + if (deque->rightindex == BLOCKLEN-1) { + block *b = newblock(rightblock, NULL, deque->len); + if (b == NULL) { + deque->len--; + Py_DECREF(item); + return -1; + } + assert(rightblock->rightlink == NULL); + rightblock->rightlink = b; + deque->rightblock = rightblock = b; + deque->rightindex = -1; } + deque->rightindex++; + rightblock->data[deque->rightindex] = item; } - while (n < 0) { - if (rightindex == BLOCKLEN - 1) { - if (b == NULL) { - b = newblock(len); - if (b == NULL) - goto done; - } - b->leftlink = rightblock; - CHECK_END(rightblock->rightlink); - rightblock->rightlink = b; - rightblock = b; - MARK_END(b->rightlink); - rightindex = -1; - b = NULL; - } - assert (rightindex < BLOCKLEN - 1); - { - PyObject **src, **dest; - Py_ssize_t m = -n; - - if (m > BLOCKLEN - leftindex) - m = BLOCKLEN - leftindex; - if (m > BLOCKLEN - 1 - rightindex) - m = BLOCKLEN - 1 - rightindex; - assert (m > 0 && m <= len); - src = &leftblock->data[leftindex]; - dest = &rightblock->data[rightindex + 1]; - leftindex += m; - rightindex += m; - n += m; - do { - *(dest++) = *(src++); - } while (--m); - } - if (leftindex == BLOCKLEN) { - assert(leftblock != rightblock); - assert(b == NULL); - b = leftblock; - CHECK_NOT_END(leftblock->rightlink); - leftblock = leftblock->rightlink; - MARK_END(leftblock->leftlink); - leftindex = 0; - } - } - rv = 0; -done: - if (b != NULL) - freeblock(b); - deque->leftblock = leftblock; - deque->rightblock = rightblock; - deque->leftindex = leftindex; - deque->rightindex = rightindex; - - return rv; + return 0; } static PyObject * @@ -597,15 +513,13 @@ block *rightblock = deque->rightblock; Py_ssize_t leftindex = deque->leftindex; Py_ssize_t rightindex = deque->rightindex; - Py_ssize_t n = (Py_SIZE(deque))/2; + Py_ssize_t n = (deque->len)/2; Py_ssize_t i; PyObject *tmp; for (i=0 ; idata[leftindex]; @@ -615,6 +529,8 @@ /* Advance left block/index pair */ leftindex++; if (leftindex == BLOCKLEN) { + if (leftblock->rightlink == NULL) + break; leftblock = leftblock->rightlink; leftindex = 0; } @@ -622,6 +538,8 @@ /* Step backwards with the right block/index pair */ rightindex--; if (rightindex == -1) { + if (rightblock->leftlink == NULL) + break; rightblock = rightblock->leftlink; rightindex = BLOCKLEN - 1; } @@ -635,9 +553,9 @@ static PyObject * deque_count(dequeobject *deque, PyObject *v) { - block *b = deque->leftblock; - Py_ssize_t index = deque->leftindex; - Py_ssize_t n = Py_SIZE(deque); + block *leftblock = deque->leftblock; + Py_ssize_t leftindex = deque->leftindex; + Py_ssize_t n = deque->len; Py_ssize_t i; Py_ssize_t count = 0; PyObject *item; @@ -645,8 +563,7 @@ int cmp; for (i=0 ; idata[index]; + item = leftblock->data[leftindex]; cmp = PyObject_RichCompareBool(item, v, Py_EQ); if (cmp > 0) count++; @@ -660,10 +577,12 @@ } /* Advance left block/index pair */ - index++; - if (index == BLOCKLEN) { - b = b->rightlink; - index = 0; + leftindex++; + if (leftindex == BLOCKLEN) { + if (leftblock->rightlink == NULL) /* can occur when i==n-1 */ + break; + leftblock = leftblock->rightlink; + leftindex = 0; } } return PyLong_FromSsize_t(count); @@ -675,19 +594,19 @@ static Py_ssize_t deque_len(dequeobject *deque) { - return Py_SIZE(deque); + return deque->len; } static PyObject * deque_remove(dequeobject *deque, PyObject *value) { - Py_ssize_t i, n=Py_SIZE(deque); + Py_ssize_t i, n=deque->len; for (i=0 ; ileftblock->data[deque->leftindex]; int cmp = PyObject_RichCompareBool(item, value, Py_EQ); - if (Py_SIZE(deque) != n) { + if (deque->len != n) { PyErr_SetString(PyExc_IndexError, "deque mutated during remove()."); return NULL; @@ -718,14 +637,14 @@ { PyObject *item; - while (Py_SIZE(deque)) { + while (deque->len) { item = deque_pop(deque, NULL); assert (item != NULL); Py_DECREF(item); } assert(deque->leftblock == deque->rightblock && deque->leftindex - 1 == deque->rightindex && - Py_SIZE(deque) == 0); + deque->len == 0); } static PyObject * @@ -735,7 +654,7 @@ PyObject *item; Py_ssize_t n, index=i; - if (i < 0 || i >= Py_SIZE(deque)) { + if (i < 0 || i >= deque->len) { PyErr_SetString(PyExc_IndexError, "deque index out of range"); return NULL; @@ -744,19 +663,19 @@ if (i == 0) { i = deque->leftindex; b = deque->leftblock; - } else if (i == Py_SIZE(deque) - 1) { + } else if (i == deque->len - 1) { i = deque->rightindex; b = deque->rightblock; } else { i += deque->leftindex; n = i / BLOCKLEN; i %= BLOCKLEN; - if (index < (Py_SIZE(deque) >> 1)) { + if (index < (deque->len >> 1)) { b = deque->leftblock; while (n--) b = b->rightlink; } else { - n = (deque->leftindex + Py_SIZE(deque) - 1) / BLOCKLEN - n; + n = (deque->leftindex + deque->len - 1) / BLOCKLEN - n; b = deque->rightblock; while (n--) b = b->leftlink; @@ -779,7 +698,7 @@ { PyObject *item; - assert (i >= 0 && i < Py_SIZE(deque)); + assert (i >= 0 && i < deque->len); if (_deque_rotate(deque, -i) == -1) return -1; @@ -795,7 +714,7 @@ { PyObject *old_value; block *b; - Py_ssize_t n, len=Py_SIZE(deque), halflen=(len+1)>>1, index=i; + Py_ssize_t n, len=deque->len, halflen=(len+1)>>1, index=i; if (i < 0 || i >= len) { PyErr_SetString(PyExc_IndexError, @@ -858,17 +777,17 @@ Py_ssize_t index; Py_ssize_t indexlo = deque->leftindex; - for (b = deque->leftblock; b != deque->rightblock; b = b->rightlink) { - for (index = indexlo; index < BLOCKLEN ; index++) { + for (b = deque->leftblock; b != NULL; b = b->rightlink) { + const Py_ssize_t indexhi = b == deque->rightblock ? + deque->rightindex : + BLOCKLEN - 1; + + for (index = indexlo; index <= indexhi; ++index) { item = b->data[index]; Py_VISIT(item); } indexlo = 0; } - for (index = indexlo; index <= deque->rightindex; index++) { - item = b->data[index]; - Py_VISIT(item); - } return 0; } @@ -958,8 +877,8 @@ } /* Shortcuts */ - vs = Py_SIZE((dequeobject *)v); - ws = Py_SIZE((dequeobject *)w); + vs = ((dequeobject *)v)->len; + ws = ((dequeobject *)w)->len; if (op == Py_EQ) { if (v == w) Py_RETURN_TRUE; @@ -1060,8 +979,8 @@ Py_ssize_t blocks; res = sizeof(dequeobject); - blocks = (deque->leftindex + Py_SIZE(deque) + BLOCKLEN - 1) / BLOCKLEN; - assert(deque->leftindex + Py_SIZE(deque) - 1 == + blocks = (deque->leftindex + deque->len + BLOCKLEN - 1) / BLOCKLEN; + assert(deque->leftindex + deque->len - 1 == (blocks - 1) * BLOCKLEN + deque->rightindex); res += blocks * sizeof(block); return PyLong_FromSsize_t(res); @@ -1214,7 +1133,7 @@ Py_INCREF(deque); it->deque = deque; it->state = deque->state; - it->counter = Py_SIZE(deque); + it->counter = deque->len; PyObject_GC_Track(it); return (PyObject *)it; } @@ -1253,7 +1172,7 @@ it->index++; it->counter--; if (it->index == BLOCKLEN && it->counter > 0) { - CHECK_NOT_END(it->b->rightlink); + assert (it->b->rightlink != NULL); it->b = it->b->rightlink; it->index = 0; } @@ -1301,7 +1220,7 @@ static PyObject * dequeiter_reduce(dequeiterobject *it) { - return Py_BuildValue("O(On)", Py_TYPE(it), it->deque, Py_SIZE(it->deque) - it->counter); + return Py_BuildValue("O(On)", Py_TYPE(it), it->deque, it->deque->len - it->counter); } static PyMethodDef dequeiter_methods[] = { @@ -1370,7 +1289,7 @@ Py_INCREF(deque); it->deque = deque; it->state = deque->state; - it->counter = Py_SIZE(deque); + it->counter = deque->len; PyObject_GC_Track(it); return (PyObject *)it; } @@ -1395,7 +1314,7 @@ it->index--; it->counter--; if (it->index == -1 && it->counter > 0) { - CHECK_NOT_END(it->b->leftlink); + assert (it->b->leftlink != NULL); it->b = it->b->leftlink; it->index = BLOCKLEN - 1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_csv.c --- a/Modules/_csv.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_csv.c Fri Feb 01 23:12:09 2013 +0100 @@ -51,7 +51,7 @@ typedef enum { START_RECORD, START_FIELD, ESCAPED_CHAR, IN_FIELD, IN_QUOTED_FIELD, ESCAPE_IN_QUOTED_FIELD, QUOTE_IN_QUOTED_FIELD, - EAT_CRNL,AFTER_ESCAPED_CRNL + EAT_CRNL } ParserState; typedef enum { @@ -644,12 +644,6 @@ break; case ESCAPED_CHAR: - if (c == '\n' || c=='\r') { - if (parse_add_char(self, c) < 0) - return -1; - self->state = AFTER_ESCAPED_CRNL; - break; - } if (c == '\0') c = '\n'; if (parse_add_char(self, c) < 0) @@ -657,11 +651,6 @@ self->state = IN_FIELD; break; - case AFTER_ESCAPED_CRNL: - if (c == '\0') - break; - /*fallthru*/ - case IN_FIELD: /* in unquoted field */ if (c == '\n' || c == '\r' || c == '\0') { diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/_ctypes.c Fri Feb 01 23:12:09 2013 +0100 @@ -1326,7 +1326,7 @@ if (stgdict->format == NULL) goto error; stgdict->ndim = itemdict->ndim + 1; - stgdict->shape = PyMem_Malloc(sizeof(Py_ssize_t) * stgdict->ndim); + stgdict->shape = PyMem_Malloc(sizeof(Py_ssize_t *) * stgdict->ndim); if (stgdict->shape == NULL) goto error; stgdict->shape[0] = length; @@ -2671,8 +2671,8 @@ cmem->b_index = index; } else { /* copy contents of adr */ if (-1 == PyCData_MallocBuffer(cmem, dict)) { + return NULL; Py_DECREF(cmem); - return NULL; } memcpy(cmem->b_ptr, adr, dict->size); cmem->b_index = index; @@ -3188,37 +3188,23 @@ { char *name; int (* address)(void); - PyObject *ftuple; PyObject *dll; PyObject *obj; PyCFuncPtrObject *self; void *handle; PyObject *paramflags = NULL; - if (!PyArg_ParseTuple(args, "O|O", &ftuple, ¶mflags)) + if (!PyArg_ParseTuple(args, "(O&O)|O", _get_name, &name, &dll, ¶mflags)) return NULL; if (paramflags == Py_None) paramflags = NULL; - ftuple = PySequence_Tuple(ftuple); - if (!ftuple) - /* Here ftuple is a borrowed reference */ + obj = PyObject_GetAttrString(dll, "_handle"); + if (!obj) return NULL; - - if (!PyArg_ParseTuple(ftuple, "O&O", _get_name, &name, &dll)) { - Py_DECREF(ftuple); - return NULL; - } - - obj = PyObject_GetAttrString(dll, "_handle"); - if (!obj) { - Py_DECREF(ftuple); - return NULL; - } if (!PyLong_Check(obj)) { PyErr_SetString(PyExc_TypeError, "the _handle attribute of the second argument must be an integer"); - Py_DECREF(ftuple); Py_DECREF(obj); return NULL; } @@ -3227,7 +3213,6 @@ if (PyErr_Occurred()) { PyErr_SetString(PyExc_ValueError, "could not convert the _handle attribute to a pointer"); - Py_DECREF(ftuple); return NULL; } @@ -3242,7 +3227,6 @@ PyErr_Format(PyExc_AttributeError, "function ordinal %d not found", (WORD)(size_t)name); - Py_DECREF(ftuple); return NULL; } #else @@ -3256,12 +3240,9 @@ #else PyErr_SetString(PyExc_AttributeError, ctypes_dlerror()); #endif - Py_DECREF(ftuple); return NULL; } #endif - Py_INCREF(dll); /* for KeepRef */ - Py_DECREF(ftuple); if (!_validate_paramflags(type, paramflags)) return NULL; @@ -3274,6 +3255,7 @@ *(void **)self->b_ptr = address; + Py_INCREF((PyObject *)dll); /* for KeepRef */ if (-1 == KeepRef((CDataObject *)self, 0, dll)) { Py_DECREF((PyObject *)self); return NULL; @@ -3453,7 +3435,7 @@ Py_INCREF(v); return v; } - if (kwds && name && (v = PyDict_GetItem(kwds, name))) { + if (kwds && (v = PyDict_GetItem(kwds, name))) { ++*pindex; Py_INCREF(v); return v; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/callproc.c Fri Feb 01 23:12:09 2013 +0100 @@ -20,8 +20,8 @@ 2. After several checks, _build_callargs() is called which returns another tuple 'callargs'. This may be the same tuple as 'inargs', a slice of - 'inargs', or a completely fresh tuple, depending on several things (is it a - COM method?, are 'paramflags' available?). + 'inargs', or a completely fresh tuple, depending on several things (is is a + COM method, are 'paramflags' available). 3. _build_callargs also calculates bitarrays containing indexes into the callargs tuple, specifying how to build the return value(s) of @@ -70,10 +70,6 @@ #include #include "ctypes.h" -#ifdef HAVE_ALLOCA_H -/* AIX needs alloca.h for alloca() */ -#include -#endif #if defined(_DEBUG) || defined(__MINGW32__) /* Don't use structured exception handling on Windows if this is defined. @@ -401,11 +397,6 @@ { *pdw = ptrs->ExceptionRecord->ExceptionCode; *record = *ptrs->ExceptionRecord; - /* We don't want to catch breakpoint exceptions, they are used to attach - * a debugger to the process. - */ - if (*pdw == EXCEPTION_BREAKPOINT) - return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_EXECUTE_HANDLER; } #endif @@ -620,8 +611,6 @@ assert(dict->paramfunc); /* If it has an stgdict, it is a CDataObject */ carg = dict->paramfunc((CDataObject *)obj); - if (carg == NULL) - return -1; pa->ffi_type = carg->pffi_type; memcpy(&pa->value, &carg->value, sizeof(pa->value)); pa->keep = (PyObject *)carg; @@ -1107,7 +1096,9 @@ if (argtypes && argtype_count > i) { PyObject *v; converter = PyTuple_GET_ITEM(argtypes, i); - v = PyObject_CallFunctionObjArgs(converter, arg, NULL); + v = PyObject_CallFunctionObjArgs(converter, + arg, + NULL); if (v == NULL) { _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1); goto cleanup; @@ -1272,6 +1263,62 @@ return Py_None; } +/* obsolete, should be removed */ +/* Only used by sample code (in samples\Windows\COM.py) */ +static PyObject * +call_commethod(PyObject *self, PyObject *args) +{ + IUnknown *pIunk; + int index; + PyObject *arguments; + PPROC *lpVtbl; + PyObject *result; + CDataObject *pcom; + PyObject *argtypes = NULL; + + if (!PyArg_ParseTuple(args, + "OiO!|O!", + &pcom, &index, + &PyTuple_Type, &arguments, + &PyTuple_Type, &argtypes)) + return NULL; + + if (argtypes && (PyTuple_GET_SIZE(arguments) != PyTuple_GET_SIZE(argtypes))) { + PyErr_Format(PyExc_TypeError, + "Method takes %d arguments (%d given)", + PyTuple_GET_SIZE(argtypes), PyTuple_GET_SIZE(arguments)); + return NULL; + } + + if (!CDataObject_Check(pcom) || (pcom->b_size != sizeof(void *))) { + PyErr_Format(PyExc_TypeError, + "COM Pointer expected instead of %s instance", + Py_TYPE(pcom)->tp_name); + return NULL; + } + + if ((*(void **)(pcom->b_ptr)) == NULL) { + PyErr_SetString(PyExc_ValueError, + "The COM 'this' pointer is NULL"); + return NULL; + } + + pIunk = (IUnknown *)(*(void **)(pcom->b_ptr)); + lpVtbl = (PPROC *)(pIunk->lpVtbl); + + result = _ctypes_callproc(lpVtbl[index], + arguments, +#ifdef MS_WIN32 + pIunk, + NULL, +#endif + FUNCFLAG_HRESULT, /* flags */ + argtypes, /* self->argtypes */ + NULL, /* self->restype */ + NULL); /* checker */ + return result; +} + static char copy_com_pointer_doc[] = "CopyComPointer(src, dst) -> HRESULT value\n"; @@ -1433,9 +1480,9 @@ NULL, #endif FUNCFLAG_CDECL, /* flags */ - NULL, /* self->argtypes */ - NULL, /* self->restype */ - NULL); /* checker */ + NULL, /* self->argtypes */ + NULL, /* self->restype */ + NULL); /* checker */ return result; } @@ -1766,6 +1813,7 @@ {"FormatError", format_error, METH_VARARGS, format_error_doc}, {"LoadLibrary", load_library, METH_VARARGS, load_library_doc}, {"FreeLibrary", free_library, METH_VARARGS, free_library_doc}, + {"call_commethod", call_commethod, METH_VARARGS }, {"_check_HRESULT", check_hresult, METH_VARARGS}, #else {"dlopen", py_dl_open, METH_VARARGS, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/cfield.c --- a/Modules/_ctypes/cfield.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/cfield.c Fri Feb 01 23:12:09 2013 +0100 @@ -1260,11 +1260,7 @@ } else if (size < length-1) /* copy terminating NUL character if there is space */ size += 1; - - if (PyUnicode_AsWideChar(value, (wchar_t *)ptr, size) == -1) { - return NULL; - } - + PyUnicode_AsWideChar(value, (wchar_t *)ptr, size); return value; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi.diff --- a/Modules/_ctypes/libffi.diff Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi.diff Fri Feb 01 23:12:09 2013 +0100 @@ -1,19 +1,24 @@ -diff -r -N -u libffi.orig/autom4te.cache/output.0 libffi/autom4te.cache/output.0 -diff -r -N -u libffi.orig/configure libffi/configure ---- libffi.orig/configure 2013-03-17 15:37:50.000000000 -0700 -+++ libffi/configure 2013-03-18 15:11:39.611575163 -0700 -@@ -13368,6 +13368,10 @@ - fi +--- libffi.orig/configure.ac 2012-04-12 05:10:51.000000000 +0200 ++++ libffi/configure.ac 2012-06-26 15:42:42.477498938 +0200 +@@ -1,4 +1,7 @@ + dnl Process this with autoconf to create configure ++# ++# file from libffi - slightly patched for ctypes ++# + + AC_PREREQ(2.68) + +@@ -114,6 +117,9 @@ + i?86-*-solaris2.1[[0-9]]*) + TARGET=X86_64; TARGETDIR=x86 ;; - -+ i*86-*-nto-qnx*) ++ i*86-*-nto-qnx*) + TARGET=X86; TARGETDIR=x86 + ;; -+ - x86_64-*-darwin*) - TARGET=X86_DARWIN; TARGETDIR=x86 + i?86-*-*) + TARGET=X86_64; TARGETDIR=x86 ;; -@@ -13426,12 +13430,12 @@ +@@ -131,12 +137,12 @@ ;; mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*) @@ -27,85 +32,17 @@ + TARGET=MIPS_IRIX; TARGETDIR=mips ;; - powerpc*-*-linux* | powerpc-*-sysv*) -@@ -13491,7 +13495,7 @@ - as_fn_error $? "\"libffi has not been ported to $host.\"" "$LINENO" 5 - fi - -- if test x$TARGET = xMIPS; then -+ if expr x$TARGET : 'xMIPS' > /dev/null; then - MIPS_TRUE= - MIPS_FALSE='#' - else -@@ -14862,6 +14866,12 @@ - ac_config_files="$ac_config_files include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc" - - -+ac_config_links="$ac_config_links include/ffi_common.h:include/ffi_common.h" -+ -+ -+ac_config_files="$ac_config_files fficonfig.py" -+ -+ - cat >confcache <<\_ACEOF - # This file is a shell script that caches the results of configure - # tests run on this system so they can be shared between configure -@@ -16047,6 +16057,8 @@ - "testsuite/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;; - "man/Makefile") CONFIG_FILES="$CONFIG_FILES man/Makefile" ;; - "libffi.pc") CONFIG_FILES="$CONFIG_FILES libffi.pc" ;; -+ "include/ffi_common.h") CONFIG_LINKS="$CONFIG_LINKS include/ffi_common.h:include/ffi_common.h" ;; -+ "fficonfig.py") CONFIG_FILES="$CONFIG_FILES fficonfig.py" ;; - - *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; - esac -diff -r -N -u libffi.orig/configure.ac libffi/configure.ac ---- libffi.orig/configure.ac 2013-03-17 15:37:50.000000000 -0700 -+++ libffi/configure.ac 2013-03-18 15:11:11.392989136 -0700 -@@ -1,4 +1,7 @@ - dnl Process this with autoconf to create configure -+# -+# file from libffi - slightly patched for Python's ctypes -+# - - AC_PREREQ(2.68) - -@@ -146,6 +149,10 @@ - fi - ;; - -+ i*86-*-nto-qnx*) -+ TARGET=X86; TARGETDIR=x86 -+ ;; -+ - x86_64-*-darwin*) - TARGET=X86_DARWIN; TARGETDIR=x86 - ;; -@@ -204,12 +211,12 @@ - ;; - - mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*) -- TARGET=MIPS; TARGETDIR=mips -+ TARGET=MIPS_IRIX; TARGETDIR=mips - ;; - mips*-*-linux* | mips*-*-openbsd*) - # Support 128-bit long double for NewABI. - HAVE_LONG_DOUBLE='defined(__mips64)' -- TARGET=MIPS; TARGETDIR=mips -+ TARGET=MIPS_IRIX; TARGETDIR=mips - ;; - - powerpc*-*-linux* | powerpc-*-sysv*) -@@ -269,7 +276,7 @@ + moxie-*-*) +@@ -212,7 +218,7 @@ AC_MSG_ERROR(["libffi has not been ported to $host."]) fi -AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS) +AM_CONDITIONAL(MIPS,[expr x$TARGET : 'xMIPS' > /dev/null]) - AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN) AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC) AM_CONDITIONAL(X86, test x$TARGET = xX86) -@@ -567,4 +574,8 @@ + AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD) +@@ -499,4 +505,8 @@ AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc) @@ -135,7 +72,7 @@ + 'M32R': ['src/m32r/sysv.S', 'src/m32r/ffi.c'], + 'M68K': ['src/m68k/ffi.c', 'src/m68k/sysv.S'], + 'POWERPC': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S', 'src/powerpc/linux64.S', 'src/powerpc/linux64_closure.S'], -+ 'POWERPC_AIX': ['src/powerpc/ffi_darwin.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'], ++ 'POWERPC_AIX': ['src/powerpc/ffi.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'], + 'POWERPC_FREEBSD': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S'], + 'ARM': ['src/arm/sysv.S', 'src/arm/ffi.c'], + 'LIBFFI_CRIS': ['src/cris/sysv.S', 'src/cris/ffi.c'], @@ -167,3 +104,17 @@ #endif /* WIN32 */ #ifdef __OS2__ +diff -urN libffi-3.0.11/src/sparc/v8.S libffi/src/sparc/v8.S +--- libffi-3.0.11/src/sparc/v8.S 2012-04-12 04:46:06.000000000 +0200 ++++ libffi/src/sparc/v8.S 2011-03-13 05:15:04.000000000 +0100 +@@ -213,6 +213,10 @@ + be,a done1 + ldd [%fp-8], %i0 + ++ cmp %o0, FFI_TYPE_UINT64 ++ be,a done1 ++ ldd [%fp-8], %i0 ++ + ld [%fp-8], %i0 + done1: + jmp %i7+8 diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/.gitignore --- a/Modules/_ctypes/libffi/.gitignore Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -.libs -.deps -*.o -*.lo -.dirstamp -*.la -Makefile -config.log -config.status -*~ -fficonfig.h -include/ffi.h -include/ffitarget.h -libffi.pc -libtool -stamp-h1 -libffi*gz -autom4te.cache -libffi.xcodeproj/xcuserdata -libffi.xcodeproj/project.xcworkspace -ios/ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/.travis.yml --- a/Modules/_ctypes/libffi/.travis.yml Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -language: c -compiler: - - gcc - - clang - -before_script: sudo apt-get install dejagnu - -script: ./configure && make && make check diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/ChangeLog --- a/Modules/_ctypes/libffi/ChangeLog Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/ChangeLog Fri Feb 01 23:12:09 2013 +0100 @@ -1,439 +1,3 @@ -2013-03-17 Anthony Green - - * README: Update for 3.0.13. - * configure.ac: Ditto. - * configure: Rebuilt. - * doc/*: Update version. - -2013-03-17 Dave Korn - - * src/closures.c (is_emutramp_enabled - [!FFI_MMAP_EXEC_EMUTRAMP_PAX]): Move default definition outside - enclosing #if scope. - -2013-03-17 Anthony Green - - * configure.ac: Only modify toolexecdir in certain cases. - * configure: Rebuilt. - -2013-03-16 Gilles Talis - - * src/powerpc/ffi.c (ffi_prep_args_SYSV): Don't use - fparg_count,etc on __NO_FPRS__ targets. - -2013-03-16 Alan Hourihane - - * src/m68k/sysv.S (epilogue): Don't use extb instruction on - m680000 machines. - -2013-03-16 Alex Gaynor - - * src/x86/ffi.c (ffi_prep_cif_machdep): Always align stack. - -2013-03-13 Markos Chandras - - * configure.ac: Add support for Imagination Technologies Meta. - * Makefile.am: Likewise. - * README: Add Imagination Technologies Meta details. - * src/metag/ffi.c: New. - * src/metag/ffitarget.h: Likewise. - * src/metag/sysv.S: Likewise. - -2013-02-24 Andreas Schwab - - * doc/libffi.texi (Structures): Fix missing category argument of - @deftp. - -2013-02-11 Anthony Green - - * configure.ac: Update release number to 3.0.12. - * configure: Rebuilt. - * README: Update release info. - -2013-02-10 Anthony Green - - * README: Add Moxie. - * src/moxie/ffi.c: Created. - * src/moxie/eabi.S: Created. - * src/moxie/ffitarget.h: Created. - * Makefile.am (nodist_libffi_la_SOURCES): Add Moxie. - * Makefile.in: Rebuilt. - * configure.ac: Add Moxie. - * configure: Rebuilt. - * testsuite/libffi.call/huge_struct.c: Disable format string - warnings for moxie*-*-elf tests. - -2013-02-10 Anthony Green - - * Makefile.am (LTLDFLAGS): Fix reference. - * Makefile.in: Rebuilt. - -2013-02-10 Anthony Green - - * README: Update supported platforms. Update test results link. - -2013-02-09 Anthony Green - - * testsuite/libffi.call/negint.c: Remove forced -O2. - * testsuite/libffi.call/many2.c (foo): Remove GCCism. - * testsuite/libffi.call/ffitest.h: Add default PRIuPTR definition. - - * src/sparc/v8.S (ffi_closure_v8): Import ancient ulonglong - closure return type fix developed by Martin v. Löwis for cpython - fork. - -2013-02-08 Andreas Tobler - - * src/powerpc/ffi.c (ffi_prep_cif_machdep): Fix small struct - support. - * src/powerpc/sysv.S: Ditto. - -2013-02-08 Anthony Green - - * testsuite/libffi.call/cls_longdouble.c: Remove xfail for - arm*-*-*. - -2013-02-08 Anthony Green - - * src/sparc/ffi.c (ffi_prep_closure_loc): Fix cache flushing for GCC. - -2013-02-08 Matthias Klose - - * man/ffi_prep_cif.3: Clean up for debian linter. - -2013-02-08 Peter Bergner - - * src/powerpc/ffi.c (ffi_prep_args_SYSV): Account for FP args pushed - on the stack. - -2013-02-08 Anthony Green - - * Makefile.am (EXTRA_DIST): Add missing files. - * testsuite/Makefile.am (EXTRA_DIST): Ditto. - * Makefile.in: Rebuilt. - -2013-02-08 Anthony Green - - * configure.ac: Move sparc asm config checks to within functions - for compatibility with sun tools. - * configure: Rebuilt. - * src/sparc/ffi.c (ffi_prep_closure_loc): Flush cache on v9 - systems. - * src/sparc/v8.S (ffi_flush_icache): Implement a sparc v9 cache - flusher. - -2013-02-08 Nathan Rossi - - * src/microblaze/ffi.c (ffi_closure_call_SYSV): Fix handling of - small big-endian structures. - (ffi_prep_args): Ditto. - -2013-02-07 Anthony Green - - * src/sparc/v8.S (ffi_call_v8): Fix typo from last patch - (effectively hiding ffi_call_v8). - -2013-02-07 Anthony Green - - * configure.ac: Update bug reporting address. - * configure.in: Rebuild. - - * src/sparc/v8.S (ffi_flush_icache): Out-of-line cache flusher for - Sun compiler. - * src/sparc/ffi.c (ffi_call): Remove warning. - Call ffi_flush_icache for non-GCC builds. - (ffi_prep_closure_loc): Use ffi_flush_icache. - - * Makefile.am (EXTRA_DIST): Add libtool-ldflags. - * Makefile.in: Rebuilt. - * libtool-ldflags: New file. - -2013-02-07 Daniel Schepler - - * configure.ac: Correctly identify x32 systems as 64-bit. - * m4/libtool.m4: Remove libtool expr error. - * aclocal.m4, configure: Rebuilt. - -2013-02-07 Anthony Green - - * configure.ac: Fix GCC usage test. - * configure: Rebuilt. - * README: Mention LLVM/GCC x86_64 issue. - * testsuite/Makefile.in: Rebuilt. - -2013-02-07 Anthony Green - - * testsuite/libffi.call/cls_double_va.c (main): Replace // style - comments with /* */ for xlc compiler. - * testsuite/libffi.call/stret_large.c (main): Ditto. - * testsuite/libffi.call/stret_large2.c (main): Ditto. - * testsuite/libffi.call/nested_struct1.c (main): Ditto. - * testsuite/libffi.call/huge_struct.c (main): Ditto. - * testsuite/libffi.call/float_va.c (main): Ditto. - * testsuite/libffi.call/cls_struct_va1.c (main): Ditto. - * testsuite/libffi.call/cls_pointer_stack.c (main): Ditto. - * testsuite/libffi.call/cls_pointer.c (main): Ditto. - * testsuite/libffi.call/cls_longdouble_va.c (main): Ditto. - -2013-02-06 Anthony Green - - * man/ffi_prep_cif.3: Clean up for debian lintian checker. - -2013-02-06 Anthony Green - - * Makefile.am (pkgconfigdir): Add missing pkgconfig install bits. - * Makefile.in: Rebuild. - -2013-02-02 Mark H Weaver - - * src/x86/ffi64.c (ffi_call): Sign-extend integer arguments passed - via general purpose registers. - -2013-01-21 Nathan Rossi - - * README: Add MicroBlaze details. - * Makefile.am: Add MicroBlaze support. - * configure.ac: Likewise. - * src/microblaze/ffi.c: New. - * src/microblaze/ffitarget.h: Likewise. - * src/microblaze/sysv.S: Likewise. - -2013-01-21 Nathan Rossi - * testsuite/libffi.call/return_uc.c: Fixed issue. - -2013-01-21 Chris Zankel - - * README: Add Xtensa support. - * Makefile.am: Likewise. - * configure.ac: Likewise. - * Makefile.in Regenerate. - * configure: Likewise. - * src/prep_cif.c: Handle Xtensa. - * src/xtensa: New directory. - * src/xtensa/ffi.c: New file. - * src/xtensa/ffitarget.h: Ditto. - * src/xtensa/sysv.S: Ditto. - -2013-01-11 Anthony Green - - * src/powerpc/ffi_darwin.c (ffi_prep_args): Replace // style - comments with /* */ for xlc compiler. - * src/powerpc/aix.S (ffi_call_AIX): Ditto. - * testsuite/libffi.call/ffitest.h (allocate_mmap): Delete - deprecated inline function. - * testsuite/libffi.special/ffitestcxx.h: Ditto. - * README: Add update for AIX support. - -2013-01-11 Anthony Green - - * configure.ac: Robustify pc relative reloc check. - * m4/ax_cc_maxopt.m4: Don't -malign-double. This is an ABI - changing option for 32-bit x86. - * aclocal.m4, configure: Rebuilt. - * README: Update supported target list. - -2013-01-10 Anthony Green - - * README (tested): Add Compiler column to table. - -2013-01-10 Anthony Green - - * src/x86/ffi64.c (struct register_args): Make sse array and array - of unions for sunpro compiler compatibility. - -2013-01-10 Anthony Green - - * configure.ac: Test target platform size_t size. Handle both 32 - and 64-bit builds for x86_64-* and i?86-* targets (allowing for - CFLAG option to change default settings). - * configure, aclocal.m4: Rebuilt. - -2013-01-10 Anthony Green - - * testsuite/libffi.special/special.exp: Only run exception - handling tests when using GNU compiler. - - * m4/ax_compiler_vendor.m4: New file. - * configure.ac: Test for compiler vendor and don't use - AX_CFLAGS_WARN_ALL with the sun compiler. - * aclocal.m4, configure: Rebuilt. - -2013-01-10 Anthony Green - - * include/ffi_common.h: Don't use GCCisms to define types when - building with the SUNPRO compiler. - -2013-01-10 Anthony Green - - * configure.ac: Put local.exp in the right place. - * configure: Rebuilt. - - * src/x86/ffi.c: Update comment about regparm function attributes. - * src/x86/sysv.S (ffi_closure_SYSV): The SUNPRO compiler requires - that all function arguments be passed on the stack (no regparm - support). - -2013-01-08 Anthony Green - - * configure.ac: Generate local.exp. This sets CC_FOR_TARGET - when we are using the vendor compiler. - * testsuite/Makefile.am (EXTRA_DEJAGNU_SITE_CONFIG): Point to - ../local.exp. - * configure, testsuite/Makefile.in: Rebuilt. - - * testsuite/libffi.call/call.exp: Run tests with different - options, depending on whether or not we are using gcc or the - vendor compiler. - * testsuite/lib/libffi.exp (libffi-init): Set using_gcc based on - whether or not we are building/testing with gcc. - -2013-01-08 Anthony Green - - * configure.ac: Switch x86 solaris target to X86 by default. - * configure: Rebuilt. - -2013-01-08 Anthony Green - - * configure.ac: Fix test for read-only eh_frame. - * configure: Rebuilt. - -2013-01-08 Anthony Green - - * src/x86/sysv.S, src/x86/unix64.S: Only emit DWARF unwind info - when building with the GNU toolchain. - * testsuite/libffi.call/ffitest.h (CHECK): Fix for Solaris vendor - compiler. - -2013-01-07 Thorsten Glaser - - * testsuite/libffi.call/cls_uchar_va.c, - testsuite/libffi.call/cls_ushort_va.c, - testsuite/libffi.call/va_1.c: Testsuite fixes. - -2013-01-07 Thorsten Glaser - - * src/m68k/ffi.c (CIF_FLAGS_SINT8, CIF_FLAGS_SINT16): Define. - (ffi_prep_cif_machdep): Fix 8-bit and 16-bit signed calls. - * src/m68k/sysv.S (ffi_call_SYSV, ffi_closure_SYSV): Ditto. - -2013-01-04 Anthony Green - - * Makefile.am (AM_CFLAGS): Don't automatically add -fexceptions - and -Wall. This is set in the configure script after testing for - GCC. - * Makefile.in: Rebuilt. - -2013-01-02 rofl0r - - * src/powerpc/ffi.c (ffi_prep_cif_machdep): Fix build error on ppc - when long double == double. - -2013-01-02 Reini Urban - - * Makefile.am (libffi_la_LDFLAGS): Add -no-undefined to LDFLAGS - (required for shared libs on cygwin/mingw). - * Makefile.in: Rebuilt. - -2012-10-31 Alan Modra - - * src/powerpc/linux64_closure.S: Add new ABI support. - * src/powerpc/linux64.S: Likewise. - -2012-10-30 Magnus Granberg - Pavel Labushev - - * configure.ac: New options pax_emutramp - * configure, fficonfig.h.in: Regenerated - * src/closures.c: New function emutramp_enabled_check() and - checks. - -2012-10-30 Frederick Cheung - - * configure.ac: Enable FFI_MAP_EXEC_WRIT for Darwin 12 (mountain - lion) and future version. - * configure: Rebuild. - -2012-10-30 James Greenhalgh - Marcus Shawcroft - - * README: Add details of aarch64 port. - * src/aarch64/ffi.c: New. - * src/aarch64/ffitarget.h: Likewise. - * src/aarch64/sysv.S: Likewise. - * Makefile.am: Support aarch64. - * configure.ac: Support aarch64. - * Makefile.in, configure: Rebuilt. - -2012-10-30 James Greenhalgh - Marcus Shawcroft - - * testsuite/lib/libffi.exp: Add support for aarch64. - * testsuite/libffi.call/cls_struct_va1.c: New. - * testsuite/libffi.call/cls_uchar_va.c: Likewise. - * testsuite/libffi.call/cls_uint_va.c: Likewise. - * testsuite/libffi.call/cls_ulong_va.c: Likewise. - * testsuite/libffi.call/cls_ushort_va.c: Likewise. - * testsuite/libffi.call/nested_struct11.c: Likewise. - * testsuite/libffi.call/uninitialized.c: Likewise. - * testsuite/libffi.call/va_1.c: Likewise. - * testsuite/libffi.call/va_struct1.c: Likewise. - * testsuite/libffi.call/va_struct2.c: Likewise. - * testsuite/libffi.call/va_struct3.c: Likewise. - -2012-10-12 Walter Lee - - * Makefile.am: Add TILE-Gx/TILEPro support. - * configure.ac: Likewise. - * Makefile.in: Regenerate. - * configure: Likewise. - * src/prep_cif.c (ffi_prep_cif_core): Handle TILE-Gx/TILEPro. - * src/tile: New directory. - * src/tile/ffi.c: New file. - * src/tile/ffitarget.h: Ditto. - * src/tile/tile.S: Ditto. - -2012-10-12 Matthias Klose - - * generate-osx-source-and-headers.py: Normalize whitespace. - -2012-09-14 David Edelsohn - - * configure: Regenerated. - -2012-08-26 Andrew Pinski - - PR libffi/53014 - * src/mips/ffi.c (ffi_prep_closure_loc): Allow n32 with soft-float and n64 with - soft-float. - -2012-08-08 Uros Bizjak - - * src/s390/ffi.c (ffi_prep_closure_loc): Don't ASSERT ABI test, - just return FFI_BAD_ABI when things are wrong. - -2012-07-18 H.J. Lu - - PR libffi/53982 - PR libffi/53973 - * src/x86/ffitarget.h: Check __ILP32__ instead of __LP64__ for x32. - (FFI_SIZEOF_JAVA_RAW): Defined to 4 for x32. - -2012-05-16 H.J. Lu - - * configure: Regenerated. - -2012-05-05 Nicolas Lelong - - * libffi.xcodeproj/project.pbxproj: Fixes. - * README: Update for iOS builds. - -2012-04-23 Alexandre Keunecke I. de Mendonca - - * configure.ac: Add Blackfin/sysv support - * Makefile.am: Add Blackfin/sysv support - * src/bfin/ffi.c: Add Blackfin/sysv support - * src/bfin/ffitarget.h: Add Blackfin/sysv support - 2012-04-11 Anthony Green * Makefile.am (EXTRA_DIST): Add new script. @@ -463,15 +27,15 @@ * README: Update instructions on building iOS binary. * build-ios.sh: Delete. +2012-04-06 H.J. Lu + + * m4/libtool.m4 (_LT_ENABLE_LOCK): Support x32. + 2012-04-06 Anthony Green * src/x86/ffi64.c (UINT128): Define differently for Intel and GNU compilers, then use it. -2012-04-06 H.J. Lu - - * m4/libtool.m4 (_LT_ENABLE_LOCK): Support x32. - 2012-04-06 Anthony Green * testsuite/Makefile.am (EXTRA_DIST): Add missing test cases. @@ -484,14 +48,6 @@ in CNAME. * src/x86/ffi.c: Wrap Windows specific code in ifdefs. -2012-04-02 Peter Bergner - - * src/powerpc/ffi.c (ffi_prep_args_SYSV): Declare double_tmp. - Silence casting pointer to integer of different size warning. - Delete goto to previously deleted label. - (ffi_call): Silence possibly undefined warning. - (ffi_closure_helper_SYSV): Declare variable type. - 2012-04-02 Peter Rosin * src/x86/win32.S (ffi_call_win32): Sign/zero extend the return @@ -637,43 +193,6 @@ * testsuite/libffi.call/struct9.c: Likewise. * testsuite/libffi.call/testclosure.c: Likewise. -2012-03-21 Peter Rosin - - * testsuite/libffi.call/float_va.c (float_va_fn): Use %f when - printing doubles (%lf is for long doubles). - (main): Likewise. - -2012-03-21 Peter Rosin - - * testsuite/lib/target-libpath.exp [*-*-cygwin*, *-*-mingw*] - (set_ld_library_path_env_vars): Add the library search dir to PATH - (and save PATH for later). - (restore_ld_library_path_env_vars): Restore PATH. - -2012-03-21 Peter Rosin - - * testsuite/lib/target-libpath.exp [*-*-cygwin*, *-*-mingw*] - (set_ld_library_path_env_vars): Add the library search dir to PATH - (and save PATH for later). - (restore_ld_library_path_env_vars): Restore PATH. - -2012-03-20 Peter Rosin - - * testsuite/libffi.call/strlen2_win32.c (main): Remove bug. - * src/x86/win32.S [MSVC] (ffi_closure_SYSV): Make the 'stub' label - visible outside the PROC, so that ffi_closure_THISCALL can see it. - -2012-03-20 Peter Rosin - - * testsuite/libffi.call/strlen2_win32.c (main): Remove bug. - * src/x86/win32.S [MSVC] (ffi_closure_SYSV): Make the 'stub' label - visible outside the PROC, so that ffi_closure_THISCALL can see it. - -2012-03-19 Alan Hourihane - - * src/m68k/ffi.c: Add MINT support. - * src/m68k/sysv.S: Ditto. - 2012-03-06 Chung-Lin Tang * src/arm/ffi.c (ffi_call): Add __ARM_EABI__ guard around call to @@ -682,11 +201,43 @@ ffi_closure_VFP. * src/arm/sysv.S: Add __ARM_EABI__ guard around VFP code. +2012-03-21 Peter Rosin + + * testsuite/libffi.call/float_va.c (float_va_fn): Use %f when + printing doubles (%lf is for long doubles). + (main): Likewise. + +2012-03-21 Peter Rosin + + * testsuite/lib/target-libpath.exp [*-*-cygwin*, *-*-mingw*] + (set_ld_library_path_env_vars): Add the library search dir to PATH + (and save PATH for later). + (restore_ld_library_path_env_vars): Restore PATH. + +2012-03-20 Peter Rosin + + * testsuite/libffi.call/strlen2_win32.c (main): Remove bug. + * src/x86/win32.S [MSVC] (ffi_closure_SYSV): Make the 'stub' label + visible outside the PROC, so that ffi_closure_THISCALL can see it. + +2012-03-19 Alan Hourihane + + * src/m68k/ffi.c: Add MINT support. + * src/m68k/sysv.S: Ditto. + 2012-03-19 chennam * src/powerpc/ffi_darwin.c (ffi_prep_closure_loc): Fix AIX closure support. +2012-04-02 Peter Bergner + + * src/powerpc/ffi.c (ffi_prep_args_SYSV): Declare double_tmp. + Silence casting pointer to integer of different size warning. + Delete goto to previously deleted label. + (ffi_call): Silence possibly undefined warning. + (ffi_closure_helper_SYSV): Declare variable type. + 2012-03-13 Kaz Kojima * src/sh/ffi.c (ffi_prep_closure_loc): Don't ASSERT ABI test, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/ChangeLog.libffi --- a/Modules/_ctypes/libffi/ChangeLog.libffi Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/ChangeLog.libffi Fri Feb 01 23:12:09 2013 +0100 @@ -574,8 +574,8 @@ * Makefile.am, include/Makefile.am: Move headers to libffi_la_SOURCES for new automake. * Makefile.in, include/Makefile.in: Rebuilt. - - * testsuite/lib/wrapper.exp: Copied from gcc tree to allow for + + * testsuite/lib/wrapper.exp: Copied from gcc tree to allow for execution outside of gcc tree. * testsuite/lib/target-libpath.exp: Ditto. diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/Makefile.am --- a/Modules/_ctypes/libffi/Makefile.am Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/Makefile.am Fri Feb 01 23:12:09 2013 +0100 @@ -2,50 +2,40 @@ AUTOMAKE_OPTIONS = foreign subdir-objects -ACLOCAL_AMFLAGS = -I m4 - SUBDIRS = include testsuite man -EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj configure.host \ - src/aarch64/ffi.c src/aarch64/ffitarget.h src/aarch64/sysv.S \ - build-ios.sh src/alpha/ffi.c src/alpha/osf.S \ - src/alpha/ffitarget.h src/arm/ffi.c src/arm/sysv.S \ - src/arm/ffitarget.h src/avr32/ffi.c src/avr32/sysv.S \ - src/avr32/ffitarget.h src/cris/ffi.c src/cris/sysv.S \ - src/cris/ffitarget.h src/ia64/ffi.c src/ia64/ffitarget.h \ - src/ia64/ia64_flags.h src/ia64/unix.S src/mips/ffi.c \ - src/mips/n32.S src/mips/o32.S src/metag/ffi.c \ - src/metag/ffitarget.h src/metag/sysv.S src/moxie/ffi.c \ - src/moxie/ffitarget.h src/moxie/eabi.S src/mips/ffitarget.h \ - src/m32r/ffi.c src/m32r/sysv.S src/m32r/ffitarget.h \ - src/m68k/ffi.c src/m68k/sysv.S src/m68k/ffitarget.h \ - src/microblaze/ffi.c src/microblaze/sysv.S \ - src/microblaze/ffitarget.h src/powerpc/ffi.c \ - src/powerpc/sysv.S src/powerpc/linux64.S \ - src/powerpc/linux64_closure.S src/powerpc/ppc_closure.S \ - src/powerpc/asm.h src/powerpc/aix.S src/powerpc/darwin.S \ - src/powerpc/aix_closure.S src/powerpc/darwin_closure.S \ - src/powerpc/ffi_darwin.c src/powerpc/ffitarget.h \ - src/s390/ffi.c src/s390/sysv.S src/s390/ffitarget.h \ - src/sh/ffi.c src/sh/sysv.S src/sh/ffitarget.h src/sh64/ffi.c \ - src/sh64/sysv.S src/sh64/ffitarget.h src/sparc/v8.S \ - src/sparc/v9.S src/sparc/ffitarget.h src/sparc/ffi.c \ - src/x86/darwin64.S src/x86/ffi.c src/x86/sysv.S \ - src/x86/win32.S src/x86/darwin.S src/x86/win64.S \ - src/x86/freebsd.S src/x86/ffi64.c src/x86/unix64.S \ - src/x86/ffitarget.h src/pa/ffitarget.h src/pa/ffi.c \ - src/pa/linux.S src/pa/hpux32.S src/frv/ffi.c src/bfin/ffi.c \ - src/bfin/ffitarget.h src/bfin/sysv.S src/frv/eabi.S \ - src/frv/ffitarget.h src/dlmalloc.c src/tile/ffi.c \ - src/tile/ffitarget.h src/tile/tile.S libtool-version \ - src/xtensa/ffitarget.h src/xtensa/ffi.c src/xtensa/sysv.S \ - ChangeLog.libffi m4/libtool.m4 m4/lt~obsolete.m4 \ - m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 \ - m4/ltversion.m4 src/arm/gentramp.sh src/debug.c msvcc.sh \ - generate-ios-source-and-headers.py \ - generate-osx-source-and-headers.py \ - libffi.xcodeproj/project.pbxproj src/arm/trampoline.S \ - libtool-ldflags +EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj configure.host \ + src/alpha/ffi.c src/alpha/osf.S src/alpha/ffitarget.h \ + src/arm/ffi.c src/arm/sysv.S src/arm/ffitarget.h \ + src/avr32/ffi.c src/avr32/sysv.S src/avr32/ffitarget.h \ + src/cris/ffi.c src/cris/sysv.S src/cris/ffitarget.h \ + src/ia64/ffi.c src/ia64/ffitarget.h src/ia64/ia64_flags.h \ + src/ia64/unix.S src/mips/ffi.c src/mips/n32.S src/mips/o32.S \ + src/mips/ffitarget.h src/m32r/ffi.c src/m32r/sysv.S \ + src/m32r/ffitarget.h src/m68k/ffi.c src/m68k/sysv.S \ + src/m68k/ffitarget.h src/powerpc/ffi.c src/powerpc/sysv.S \ + src/powerpc/linux64.S src/powerpc/linux64_closure.S \ + src/powerpc/ppc_closure.S src/powerpc/asm.h src/powerpc/aix.S \ + src/powerpc/darwin.S src/powerpc/aix_closure.S \ + src/powerpc/darwin_closure.S src/powerpc/ffi_darwin.c \ + src/powerpc/ffitarget.h src/s390/ffi.c src/s390/sysv.S \ + src/s390/ffitarget.h src/sh/ffi.c src/sh/sysv.S \ + src/sh/ffitarget.h src/sh64/ffi.c src/sh64/sysv.S \ + src/sh64/ffitarget.h src/sparc/v8.S src/sparc/v9.S \ + src/sparc/ffitarget.h src/sparc/ffi.c src/x86/darwin64.S \ + src/x86/ffi.c src/x86/sysv.S src/x86/win32.S src/x86/darwin.S \ + src/x86/win64.S src/x86/freebsd.S src/x86/ffi64.c \ + src/x86/unix64.S src/x86/ffitarget.h src/pa/ffitarget.h \ + src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S src/frv/ffi.c \ + src/frv/eabi.S src/frv/ffitarget.h src/dlmalloc.c \ + src/moxie/ffi.c src/moxie/eabi.S libtool-version \ + ChangeLog.libffi m4/libtool.m4 m4/lt~obsolete.m4 \ + m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 \ + m4/ltversion.m4 src/arm/gentramp.sh src/debug.c \ + msvcc.sh generate-ios-source-and-headers.py \ + generate-osx-source-and-headers.py \ + libffi.xcodeproj/project.pbxproj \ + src/arm/trampoline.S info_TEXINFOS = doc/libffi.texi @@ -93,12 +83,11 @@ "RANLIB=$(RANLIB)" \ "DESTDIR=$(DESTDIR)" -# Subdir rules rely on $(FLAGS_TO_PASS) -FLAGS_TO_PASS = $(AM_MAKEFLAGS) - MAKEOVERRIDES= -toolexeclib_LTLIBRARIES = libffi.la +ACLOCAL_AMFLAGS=$(ACLOCAL_AMFLAGS) -I m4 + +lib_LTLIBRARIES = libffi.la noinst_LTLIBRARIES = libffi_convenience.la libffi_la_SOURCES = src/prep_cif.c src/types.c \ @@ -116,9 +105,6 @@ if MIPS nodist_libffi_la_SOURCES += src/mips/ffi.c src/mips/o32.S src/mips/n32.S endif -if BFIN -nodist_libffi_la_SOURCES += src/bfin/ffi.c src/bfin/sysv.S -endif if X86 nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/sysv.S endif @@ -149,12 +135,6 @@ if M68K nodist_libffi_la_SOURCES += src/m68k/ffi.c src/m68k/sysv.S endif -if MOXIE -nodist_libffi_la_SOURCES += src/moxie/ffi.c src/moxie/eabi.S -endif -if MICROBLAZE -nodist_libffi_la_SOURCES += src/microblaze/ffi.c src/microblaze/sysv.S -endif if POWERPC nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S endif @@ -167,9 +147,6 @@ if POWERPC_FREEBSD nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S endif -if AARCH64 -nodist_libffi_la_SOURCES += src/aarch64/sysv.S src/aarch64/ffi.c -endif if ARM nodist_libffi_la_SOURCES += src/arm/sysv.S src/arm/ffi.c if FFI_EXEC_TRAMPOLINE_TABLE @@ -185,6 +162,9 @@ if FRV nodist_libffi_la_SOURCES += src/frv/eabi.S src/frv/ffi.c endif +if MOXIE +nodist_libffi_la_SOURCES += src/moxie/eabi.S src/moxie/ffi.c +endif if S390 nodist_libffi_la_SOURCES += src/s390/sysv.S src/s390/ffi.c endif @@ -203,23 +183,23 @@ if PA_HPUX nodist_libffi_la_SOURCES += src/pa/hpux32.S src/pa/ffi.c endif -if TILE -nodist_libffi_la_SOURCES += src/tile/tile.S src/tile/ffi.c -endif -if XTENSA -nodist_libffi_la_SOURCES += src/xtensa/sysv.S src/xtensa/ffi.c -endif -if METAG -nodist_libffi_la_SOURCES += src/metag/sysv.S src/metag/ffi.c -endif libffi_convenience_la_SOURCES = $(libffi_la_SOURCES) nodist_libffi_convenience_la_SOURCES = $(nodist_libffi_la_SOURCES) -LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/libtool-ldflags $(LDFLAGS)) +AM_CFLAGS = -g +if FFI_DEBUG +# Build debug. Define FFI_DEBUG on the commandline so that, when building with +# MSVC, it can link against the debug CRT. +AM_CFLAGS += -DFFI_DEBUG +endif -libffi_la_LDFLAGS = -no-undefined -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LTLDFLAGS) $(AM_LTLDFLAGS) +libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LTLDFLAGS) $(AM_LTLDFLAGS) -AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src -AM_CCASFLAGS = $(AM_CPPFLAGS) +AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src -DFFI_BUILDING +AM_CCASFLAGS = $(AM_CPPFLAGS) -g +# No install-html or install-pdf support in automake yet +.PHONY: install-html install-pdf +install-html: +install-pdf: diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/Makefile.in --- a/Modules/_ctypes/libffi/Makefile.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/Makefile.in Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.12.2 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2012 Free Software Foundation, Inc. - +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -16,23 +17,6 @@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -54,59 +38,45 @@ target_triplet = @target@ @FFI_DEBUG_TRUE@am__append_1 = src/debug.c @MIPS_TRUE@am__append_2 = src/mips/ffi.c src/mips/o32.S src/mips/n32.S -@BFIN_TRUE@am__append_3 = src/bfin/ffi.c src/bfin/sysv.S -@X86_TRUE@am__append_4 = src/x86/ffi.c src/x86/sysv.S -@X86_FREEBSD_TRUE@am__append_5 = src/x86/ffi.c src/x86/freebsd.S -@X86_WIN32_TRUE@am__append_6 = src/x86/ffi.c src/x86/win32.S -@X86_WIN64_TRUE@am__append_7 = src/x86/ffi.c src/x86/win64.S -@X86_DARWIN_TRUE@am__append_8 = src/x86/ffi.c src/x86/darwin.S src/x86/ffi64.c src/x86/darwin64.S -@SPARC_TRUE@am__append_9 = src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S -@ALPHA_TRUE@am__append_10 = src/alpha/ffi.c src/alpha/osf.S -@IA64_TRUE@am__append_11 = src/ia64/ffi.c src/ia64/unix.S -@M32R_TRUE@am__append_12 = src/m32r/sysv.S src/m32r/ffi.c -@M68K_TRUE@am__append_13 = src/m68k/ffi.c src/m68k/sysv.S -@MOXIE_TRUE@am__append_14 = src/moxie/ffi.c src/moxie/eabi.S -@MICROBLAZE_TRUE@am__append_15 = src/microblaze/ffi.c src/microblaze/sysv.S -@POWERPC_TRUE@am__append_16 = src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S -@POWERPC_AIX_TRUE@am__append_17 = src/powerpc/ffi_darwin.c src/powerpc/aix.S src/powerpc/aix_closure.S -@POWERPC_DARWIN_TRUE@am__append_18 = src/powerpc/ffi_darwin.c src/powerpc/darwin.S src/powerpc/darwin_closure.S -@POWERPC_FREEBSD_TRUE@am__append_19 = src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S -@AARCH64_TRUE@am__append_20 = src/aarch64/sysv.S src/aarch64/ffi.c -@ARM_TRUE@am__append_21 = src/arm/sysv.S src/arm/ffi.c -@ARM_TRUE@@FFI_EXEC_TRAMPOLINE_TABLE_TRUE@am__append_22 = src/arm/trampoline.S -@AVR32_TRUE@am__append_23 = src/avr32/sysv.S src/avr32/ffi.c -@LIBFFI_CRIS_TRUE@am__append_24 = src/cris/sysv.S src/cris/ffi.c -@FRV_TRUE@am__append_25 = src/frv/eabi.S src/frv/ffi.c -@S390_TRUE@am__append_26 = src/s390/sysv.S src/s390/ffi.c -@X86_64_TRUE@am__append_27 = src/x86/ffi64.c src/x86/unix64.S src/x86/ffi.c src/x86/sysv.S -@SH_TRUE@am__append_28 = src/sh/sysv.S src/sh/ffi.c -@SH64_TRUE@am__append_29 = src/sh64/sysv.S src/sh64/ffi.c -@PA_LINUX_TRUE@am__append_30 = src/pa/linux.S src/pa/ffi.c -@PA_HPUX_TRUE@am__append_31 = src/pa/hpux32.S src/pa/ffi.c -@TILE_TRUE@am__append_32 = src/tile/tile.S src/tile/ffi.c -@XTENSA_TRUE@am__append_33 = src/xtensa/sysv.S src/xtensa/ffi.c -@METAG_TRUE@am__append_34 = src/metag/sysv.S src/metag/ffi.c +@X86_TRUE@am__append_3 = src/x86/ffi.c src/x86/sysv.S +@X86_FREEBSD_TRUE@am__append_4 = src/x86/ffi.c src/x86/freebsd.S +@X86_WIN32_TRUE@am__append_5 = src/x86/ffi.c src/x86/win32.S +@X86_WIN64_TRUE@am__append_6 = src/x86/ffi.c src/x86/win64.S +@X86_DARWIN_TRUE@am__append_7 = src/x86/ffi.c src/x86/darwin.S src/x86/ffi64.c src/x86/darwin64.S +@SPARC_TRUE@am__append_8 = src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S +@ALPHA_TRUE@am__append_9 = src/alpha/ffi.c src/alpha/osf.S +@IA64_TRUE@am__append_10 = src/ia64/ffi.c src/ia64/unix.S +@M32R_TRUE@am__append_11 = src/m32r/sysv.S src/m32r/ffi.c +@M68K_TRUE@am__append_12 = src/m68k/ffi.c src/m68k/sysv.S +@POWERPC_TRUE@am__append_13 = src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S +@POWERPC_AIX_TRUE@am__append_14 = src/powerpc/ffi_darwin.c src/powerpc/aix.S src/powerpc/aix_closure.S +@POWERPC_DARWIN_TRUE@am__append_15 = src/powerpc/ffi_darwin.c src/powerpc/darwin.S src/powerpc/darwin_closure.S +@POWERPC_FREEBSD_TRUE@am__append_16 = src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S +@ARM_TRUE@am__append_17 = src/arm/sysv.S src/arm/ffi.c +@ARM_TRUE@@FFI_EXEC_TRAMPOLINE_TABLE_TRUE@am__append_18 = src/arm/trampoline.S +@AVR32_TRUE@am__append_19 = src/avr32/sysv.S src/avr32/ffi.c +@LIBFFI_CRIS_TRUE@am__append_20 = src/cris/sysv.S src/cris/ffi.c +@FRV_TRUE@am__append_21 = src/frv/eabi.S src/frv/ffi.c +@MOXIE_TRUE@am__append_22 = src/moxie/eabi.S src/moxie/ffi.c +@S390_TRUE@am__append_23 = src/s390/sysv.S src/s390/ffi.c +@X86_64_TRUE@am__append_24 = src/x86/ffi64.c src/x86/unix64.S src/x86/ffi.c src/x86/sysv.S +@SH_TRUE@am__append_25 = src/sh/sysv.S src/sh/ffi.c +@SH64_TRUE@am__append_26 = src/sh64/sysv.S src/sh64/ffi.c +@PA_LINUX_TRUE@am__append_27 = src/pa/linux.S src/pa/ffi.c +@PA_HPUX_TRUE@am__append_28 = src/pa/hpux32.S src/pa/ffi.c +# Build debug. Define FFI_DEBUG on the commandline so that, when building with +# MSVC, it can link against the debug CRT. +@FFI_DEBUG_TRUE@am__append_29 = -DFFI_DEBUG subdir = . DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/doc/stamp-vti \ $(srcdir)/doc/version.texi $(srcdir)/fficonfig.h.in \ - $(srcdir)/libffi.pc.in $(top_srcdir)/configure ChangeLog \ - compile config.guess config.sub depcomp install-sh ltmain.sh \ - mdate-sh missing texinfo.tex + $(srcdir)/fficonfig.py.in $(srcdir)/libffi.pc.in \ + $(top_srcdir)/configure ChangeLog compile config.guess \ + config.sub depcomp install-sh ltmain.sh mdate-sh missing \ + texinfo.tex ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/asmcfi.m4 \ - $(top_srcdir)/m4/ax_append_flag.m4 \ - $(top_srcdir)/m4/ax_cc_maxopt.m4 \ - $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ - $(top_srcdir)/m4/ax_check_compile_flag.m4 \ - $(top_srcdir)/m4/ax_compiler_vendor.m4 \ - $(top_srcdir)/m4/ax_configure_args.m4 \ - $(top_srcdir)/m4/ax_enable_builddir.m4 \ - $(top_srcdir)/m4/ax_gcc_archflag.m4 \ - $(top_srcdir)/m4/ax_gcc_x86_cpuid.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -114,7 +84,7 @@ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = fficonfig.h -CONFIG_CLEAN_FILES = libffi.pc +CONFIG_CLEAN_FILES = libffi.pc fficonfig.py CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ @@ -143,9 +113,9 @@ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } -am__installdirs = "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(infodir)" \ +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(infodir)" \ "$(DESTDIR)$(pkgconfigdir)" -LTLIBRARIES = $(noinst_LTLIBRARIES) $(toolexeclib_LTLIBRARIES) +LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) libffi_la_LIBADD = am__dirstamp = $(am__leading_dot)dirstamp am_libffi_la_OBJECTS = src/prep_cif.lo src/types.lo src/raw_api.lo \ @@ -153,51 +123,44 @@ @FFI_DEBUG_TRUE@am__objects_1 = src/debug.lo @MIPS_TRUE@am__objects_2 = src/mips/ffi.lo src/mips/o32.lo \ @MIPS_TRUE@ src/mips/n32.lo -@BFIN_TRUE@am__objects_3 = src/bfin/ffi.lo src/bfin/sysv.lo -@X86_TRUE@am__objects_4 = src/x86/ffi.lo src/x86/sysv.lo -@X86_FREEBSD_TRUE@am__objects_5 = src/x86/ffi.lo src/x86/freebsd.lo -@X86_WIN32_TRUE@am__objects_6 = src/x86/ffi.lo src/x86/win32.lo -@X86_WIN64_TRUE@am__objects_7 = src/x86/ffi.lo src/x86/win64.lo -@X86_DARWIN_TRUE@am__objects_8 = src/x86/ffi.lo src/x86/darwin.lo \ +@X86_TRUE@am__objects_3 = src/x86/ffi.lo src/x86/sysv.lo +@X86_FREEBSD_TRUE@am__objects_4 = src/x86/ffi.lo src/x86/freebsd.lo +@X86_WIN32_TRUE@am__objects_5 = src/x86/ffi.lo src/x86/win32.lo +@X86_WIN64_TRUE@am__objects_6 = src/x86/ffi.lo src/x86/win64.lo +@X86_DARWIN_TRUE@am__objects_7 = src/x86/ffi.lo src/x86/darwin.lo \ @X86_DARWIN_TRUE@ src/x86/ffi64.lo src/x86/darwin64.lo -@SPARC_TRUE@am__objects_9 = src/sparc/ffi.lo src/sparc/v8.lo \ +@SPARC_TRUE@am__objects_8 = src/sparc/ffi.lo src/sparc/v8.lo \ @SPARC_TRUE@ src/sparc/v9.lo -@ALPHA_TRUE@am__objects_10 = src/alpha/ffi.lo src/alpha/osf.lo -@IA64_TRUE@am__objects_11 = src/ia64/ffi.lo src/ia64/unix.lo -@M32R_TRUE@am__objects_12 = src/m32r/sysv.lo src/m32r/ffi.lo -@M68K_TRUE@am__objects_13 = src/m68k/ffi.lo src/m68k/sysv.lo -@MOXIE_TRUE@am__objects_14 = src/moxie/ffi.lo src/moxie/eabi.lo -@MICROBLAZE_TRUE@am__objects_15 = src/microblaze/ffi.lo \ -@MICROBLAZE_TRUE@ src/microblaze/sysv.lo -@POWERPC_TRUE@am__objects_16 = src/powerpc/ffi.lo src/powerpc/sysv.lo \ +@ALPHA_TRUE@am__objects_9 = src/alpha/ffi.lo src/alpha/osf.lo +@IA64_TRUE@am__objects_10 = src/ia64/ffi.lo src/ia64/unix.lo +@M32R_TRUE@am__objects_11 = src/m32r/sysv.lo src/m32r/ffi.lo +@M68K_TRUE@am__objects_12 = src/m68k/ffi.lo src/m68k/sysv.lo +@POWERPC_TRUE@am__objects_13 = src/powerpc/ffi.lo src/powerpc/sysv.lo \ @POWERPC_TRUE@ src/powerpc/ppc_closure.lo \ @POWERPC_TRUE@ src/powerpc/linux64.lo \ @POWERPC_TRUE@ src/powerpc/linux64_closure.lo -@POWERPC_AIX_TRUE@am__objects_17 = src/powerpc/ffi_darwin.lo \ +@POWERPC_AIX_TRUE@am__objects_14 = src/powerpc/ffi_darwin.lo \ @POWERPC_AIX_TRUE@ src/powerpc/aix.lo \ @POWERPC_AIX_TRUE@ src/powerpc/aix_closure.lo -@POWERPC_DARWIN_TRUE@am__objects_18 = src/powerpc/ffi_darwin.lo \ +@POWERPC_DARWIN_TRUE@am__objects_15 = src/powerpc/ffi_darwin.lo \ @POWERPC_DARWIN_TRUE@ src/powerpc/darwin.lo \ @POWERPC_DARWIN_TRUE@ src/powerpc/darwin_closure.lo -@POWERPC_FREEBSD_TRUE@am__objects_19 = src/powerpc/ffi.lo \ +@POWERPC_FREEBSD_TRUE@am__objects_16 = src/powerpc/ffi.lo \ @POWERPC_FREEBSD_TRUE@ src/powerpc/sysv.lo \ @POWERPC_FREEBSD_TRUE@ src/powerpc/ppc_closure.lo -@AARCH64_TRUE@am__objects_20 = src/aarch64/sysv.lo src/aarch64/ffi.lo -@ARM_TRUE@am__objects_21 = src/arm/sysv.lo src/arm/ffi.lo -@ARM_TRUE@@FFI_EXEC_TRAMPOLINE_TABLE_TRUE@am__objects_22 = src/arm/trampoline.lo -@AVR32_TRUE@am__objects_23 = src/avr32/sysv.lo src/avr32/ffi.lo -@LIBFFI_CRIS_TRUE@am__objects_24 = src/cris/sysv.lo src/cris/ffi.lo -@FRV_TRUE@am__objects_25 = src/frv/eabi.lo src/frv/ffi.lo -@S390_TRUE@am__objects_26 = src/s390/sysv.lo src/s390/ffi.lo -@X86_64_TRUE@am__objects_27 = src/x86/ffi64.lo src/x86/unix64.lo \ +@ARM_TRUE@am__objects_17 = src/arm/sysv.lo src/arm/ffi.lo +@ARM_TRUE@@FFI_EXEC_TRAMPOLINE_TABLE_TRUE@am__objects_18 = src/arm/trampoline.lo +@AVR32_TRUE@am__objects_19 = src/avr32/sysv.lo src/avr32/ffi.lo +@LIBFFI_CRIS_TRUE@am__objects_20 = src/cris/sysv.lo src/cris/ffi.lo +@FRV_TRUE@am__objects_21 = src/frv/eabi.lo src/frv/ffi.lo +@MOXIE_TRUE@am__objects_22 = src/moxie/eabi.lo src/moxie/ffi.lo +@S390_TRUE@am__objects_23 = src/s390/sysv.lo src/s390/ffi.lo +@X86_64_TRUE@am__objects_24 = src/x86/ffi64.lo src/x86/unix64.lo \ @X86_64_TRUE@ src/x86/ffi.lo src/x86/sysv.lo -@SH_TRUE@am__objects_28 = src/sh/sysv.lo src/sh/ffi.lo -@SH64_TRUE@am__objects_29 = src/sh64/sysv.lo src/sh64/ffi.lo -@PA_LINUX_TRUE@am__objects_30 = src/pa/linux.lo src/pa/ffi.lo -@PA_HPUX_TRUE@am__objects_31 = src/pa/hpux32.lo src/pa/ffi.lo -@TILE_TRUE@am__objects_32 = src/tile/tile.lo src/tile/ffi.lo -@XTENSA_TRUE@am__objects_33 = src/xtensa/sysv.lo src/xtensa/ffi.lo -@METAG_TRUE@am__objects_34 = src/metag/sysv.lo src/metag/ffi.lo +@SH_TRUE@am__objects_25 = src/sh/sysv.lo src/sh/ffi.lo +@SH64_TRUE@am__objects_26 = src/sh64/sysv.lo src/sh64/ffi.lo +@PA_LINUX_TRUE@am__objects_27 = src/pa/linux.lo src/pa/ffi.lo +@PA_HPUX_TRUE@am__objects_28 = src/pa/hpux32.lo src/pa/ffi.lo nodist_libffi_la_OBJECTS = $(am__objects_1) $(am__objects_2) \ $(am__objects_3) $(am__objects_4) $(am__objects_5) \ $(am__objects_6) $(am__objects_7) $(am__objects_8) \ @@ -207,19 +170,17 @@ $(am__objects_18) $(am__objects_19) $(am__objects_20) \ $(am__objects_21) $(am__objects_22) $(am__objects_23) \ $(am__objects_24) $(am__objects_25) $(am__objects_26) \ - $(am__objects_27) $(am__objects_28) $(am__objects_29) \ - $(am__objects_30) $(am__objects_31) $(am__objects_32) \ - $(am__objects_33) $(am__objects_34) + $(am__objects_27) $(am__objects_28) libffi_la_OBJECTS = $(am_libffi_la_OBJECTS) \ $(nodist_libffi_la_OBJECTS) libffi_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libffi_la_LDFLAGS) $(LDFLAGS) -o $@ libffi_convenience_la_LIBADD = -am__objects_35 = src/prep_cif.lo src/types.lo src/raw_api.lo \ +am__objects_29 = src/prep_cif.lo src/types.lo src/raw_api.lo \ src/java_raw_api.lo src/closures.lo -am_libffi_convenience_la_OBJECTS = $(am__objects_35) -am__objects_36 = $(am__objects_1) $(am__objects_2) $(am__objects_3) \ +am_libffi_convenience_la_OBJECTS = $(am__objects_29) +am__objects_30 = $(am__objects_1) $(am__objects_2) $(am__objects_3) \ $(am__objects_4) $(am__objects_5) $(am__objects_6) \ $(am__objects_7) $(am__objects_8) $(am__objects_9) \ $(am__objects_10) $(am__objects_11) $(am__objects_12) \ @@ -228,10 +189,8 @@ $(am__objects_19) $(am__objects_20) $(am__objects_21) \ $(am__objects_22) $(am__objects_23) $(am__objects_24) \ $(am__objects_25) $(am__objects_26) $(am__objects_27) \ - $(am__objects_28) $(am__objects_29) $(am__objects_30) \ - $(am__objects_31) $(am__objects_32) $(am__objects_33) \ - $(am__objects_34) -nodist_libffi_convenience_la_OBJECTS = $(am__objects_36) + $(am__objects_28) +nodist_libffi_convenience_la_OBJECTS = $(am__objects_30) libffi_convenience_la_OBJECTS = $(am_libffi_convenience_la_OBJECTS) \ $(nodist_libffi_convenience_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ @@ -275,20 +234,14 @@ install-pdf-recursive install-ps-recursive install-recursive \ installcheck-recursive installdirs-recursive pdf-recursive \ ps-recursive uninstall-recursive -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac DATA = $(pkgconfig_DATA) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ - cscope distdir dist dist-all distcheck + distdir dist dist-all distcheck ETAGS = etags CTAGS = ctags -CSCOPE = cscope DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) @@ -299,7 +252,6 @@ && rm -rf "$(distdir)" \ || { sleep 5 && rm -rf "$(distdir)"; }; \ else :; fi -am__post_remove_distdir = $(am__remove_distdir) am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ @@ -327,7 +279,6 @@ reldir="$$dir2" DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best -DIST_TARGETS = dist-gzip distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -396,7 +347,6 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PRTDIAG = @PRTDIAG@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -417,7 +367,6 @@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ -ax_enable_builddir_sed = @ax_enable_builddir_sed@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ @@ -453,7 +402,6 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ -sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -466,48 +414,39 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign subdir-objects -ACLOCAL_AMFLAGS = -I m4 SUBDIRS = include testsuite man -EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj configure.host \ - src/aarch64/ffi.c src/aarch64/ffitarget.h src/aarch64/sysv.S \ - build-ios.sh src/alpha/ffi.c src/alpha/osf.S \ - src/alpha/ffitarget.h src/arm/ffi.c src/arm/sysv.S \ - src/arm/ffitarget.h src/avr32/ffi.c src/avr32/sysv.S \ - src/avr32/ffitarget.h src/cris/ffi.c src/cris/sysv.S \ - src/cris/ffitarget.h src/ia64/ffi.c src/ia64/ffitarget.h \ - src/ia64/ia64_flags.h src/ia64/unix.S src/mips/ffi.c \ - src/mips/n32.S src/mips/o32.S src/metag/ffi.c \ - src/metag/ffitarget.h src/metag/sysv.S src/moxie/ffi.c \ - src/moxie/ffitarget.h src/moxie/eabi.S src/mips/ffitarget.h \ - src/m32r/ffi.c src/m32r/sysv.S src/m32r/ffitarget.h \ - src/m68k/ffi.c src/m68k/sysv.S src/m68k/ffitarget.h \ - src/microblaze/ffi.c src/microblaze/sysv.S \ - src/microblaze/ffitarget.h src/powerpc/ffi.c \ - src/powerpc/sysv.S src/powerpc/linux64.S \ - src/powerpc/linux64_closure.S src/powerpc/ppc_closure.S \ - src/powerpc/asm.h src/powerpc/aix.S src/powerpc/darwin.S \ - src/powerpc/aix_closure.S src/powerpc/darwin_closure.S \ - src/powerpc/ffi_darwin.c src/powerpc/ffitarget.h \ - src/s390/ffi.c src/s390/sysv.S src/s390/ffitarget.h \ - src/sh/ffi.c src/sh/sysv.S src/sh/ffitarget.h src/sh64/ffi.c \ - src/sh64/sysv.S src/sh64/ffitarget.h src/sparc/v8.S \ - src/sparc/v9.S src/sparc/ffitarget.h src/sparc/ffi.c \ - src/x86/darwin64.S src/x86/ffi.c src/x86/sysv.S \ - src/x86/win32.S src/x86/darwin.S src/x86/win64.S \ - src/x86/freebsd.S src/x86/ffi64.c src/x86/unix64.S \ - src/x86/ffitarget.h src/pa/ffitarget.h src/pa/ffi.c \ - src/pa/linux.S src/pa/hpux32.S src/frv/ffi.c src/bfin/ffi.c \ - src/bfin/ffitarget.h src/bfin/sysv.S src/frv/eabi.S \ - src/frv/ffitarget.h src/dlmalloc.c src/tile/ffi.c \ - src/tile/ffitarget.h src/tile/tile.S libtool-version \ - src/xtensa/ffitarget.h src/xtensa/ffi.c src/xtensa/sysv.S \ - ChangeLog.libffi m4/libtool.m4 m4/lt~obsolete.m4 \ - m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 \ - m4/ltversion.m4 src/arm/gentramp.sh src/debug.c msvcc.sh \ - generate-ios-source-and-headers.py \ - generate-osx-source-and-headers.py \ - libffi.xcodeproj/project.pbxproj src/arm/trampoline.S \ - libtool-ldflags +EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj configure.host \ + src/alpha/ffi.c src/alpha/osf.S src/alpha/ffitarget.h \ + src/arm/ffi.c src/arm/sysv.S src/arm/ffitarget.h \ + src/avr32/ffi.c src/avr32/sysv.S src/avr32/ffitarget.h \ + src/cris/ffi.c src/cris/sysv.S src/cris/ffitarget.h \ + src/ia64/ffi.c src/ia64/ffitarget.h src/ia64/ia64_flags.h \ + src/ia64/unix.S src/mips/ffi.c src/mips/n32.S src/mips/o32.S \ + src/mips/ffitarget.h src/m32r/ffi.c src/m32r/sysv.S \ + src/m32r/ffitarget.h src/m68k/ffi.c src/m68k/sysv.S \ + src/m68k/ffitarget.h src/powerpc/ffi.c src/powerpc/sysv.S \ + src/powerpc/linux64.S src/powerpc/linux64_closure.S \ + src/powerpc/ppc_closure.S src/powerpc/asm.h src/powerpc/aix.S \ + src/powerpc/darwin.S src/powerpc/aix_closure.S \ + src/powerpc/darwin_closure.S src/powerpc/ffi_darwin.c \ + src/powerpc/ffitarget.h src/s390/ffi.c src/s390/sysv.S \ + src/s390/ffitarget.h src/sh/ffi.c src/sh/sysv.S \ + src/sh/ffitarget.h src/sh64/ffi.c src/sh64/sysv.S \ + src/sh64/ffitarget.h src/sparc/v8.S src/sparc/v9.S \ + src/sparc/ffitarget.h src/sparc/ffi.c src/x86/darwin64.S \ + src/x86/ffi.c src/x86/sysv.S src/x86/win32.S src/x86/darwin.S \ + src/x86/win64.S src/x86/freebsd.S src/x86/ffi64.c \ + src/x86/unix64.S src/x86/ffitarget.h src/pa/ffitarget.h \ + src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S src/frv/ffi.c \ + src/frv/eabi.S src/frv/ffitarget.h src/dlmalloc.c \ + src/moxie/ffi.c src/moxie/eabi.S libtool-version \ + ChangeLog.libffi m4/libtool.m4 m4/lt~obsolete.m4 \ + m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 \ + m4/ltversion.m4 src/arm/gentramp.sh src/debug.c \ + msvcc.sh generate-ios-source-and-headers.py \ + generate-osx-source-and-headers.py \ + libffi.xcodeproj/project.pbxproj \ + src/arm/trampoline.S info_TEXINFOS = doc/libffi.texi @@ -549,11 +488,9 @@ "RANLIB=$(RANLIB)" \ "DESTDIR=$(DESTDIR)" - -# Subdir rules rely on $(FLAGS_TO_PASS) -FLAGS_TO_PASS = $(AM_MAKEFLAGS) MAKEOVERRIDES = -toolexeclib_LTLIBRARIES = libffi.la +ACLOCAL_AMFLAGS = $(ACLOCAL_AMFLAGS) -I m4 +lib_LTLIBRARIES = libffi.la noinst_LTLIBRARIES = libffi_convenience.la libffi_la_SOURCES = src/prep_cif.c src/types.c \ src/raw_api.c src/java_raw_api.c src/closures.c @@ -569,15 +506,13 @@ $(am__append_18) $(am__append_19) $(am__append_20) \ $(am__append_21) $(am__append_22) $(am__append_23) \ $(am__append_24) $(am__append_25) $(am__append_26) \ - $(am__append_27) $(am__append_28) $(am__append_29) \ - $(am__append_30) $(am__append_31) $(am__append_32) \ - $(am__append_33) $(am__append_34) + $(am__append_27) $(am__append_28) libffi_convenience_la_SOURCES = $(libffi_la_SOURCES) nodist_libffi_convenience_la_SOURCES = $(nodist_libffi_la_SOURCES) -LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/libtool-ldflags $(LDFLAGS)) -libffi_la_LDFLAGS = -no-undefined -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LTLDFLAGS) $(AM_LTLDFLAGS) -AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src -AM_CCASFLAGS = $(AM_CPPFLAGS) +AM_CFLAGS = -g $(am__append_29) +libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LTLDFLAGS) $(AM_LTLDFLAGS) +AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src -DFFI_BUILDING +AM_CCASFLAGS = $(AM_CPPFLAGS) -g all: fficonfig.h $(MAKE) $(AM_MAKEFLAGS) all-recursive @@ -634,51 +569,48 @@ -rm -f fficonfig.h stamp-h1 libffi.pc: $(top_builddir)/config.status $(srcdir)/libffi.pc.in cd $(top_builddir) && $(SHELL) ./config.status $@ - -clean-noinstLTLIBRARIES: - -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) - @list='$(noinst_LTLIBRARIES)'; \ - locs=`for p in $$list; do echo $$p; done | \ - sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ - sort -u`; \ - test -z "$$locs" || { \ - echo rm -f $${locs}; \ - rm -f $${locs}; \ - } -install-toolexeclibLTLIBRARIES: $(toolexeclib_LTLIBRARIES) +fficonfig.py: $(top_builddir)/config.status $(srcdir)/fficonfig.py.in + cd $(top_builddir) && $(SHELL) ./config.status $@ +install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) - @list='$(toolexeclib_LTLIBRARIES)'; test -n "$(toolexeclibdir)" || list=; \ + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ list2=; for p in $$list; do \ if test -f $$p; then \ list2="$$list2 $$p"; \ else :; fi; \ done; \ test -z "$$list2" || { \ - echo " $(MKDIR_P) '$(DESTDIR)$(toolexeclibdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(toolexeclibdir)" || exit 1; \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(toolexeclibdir)'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(toolexeclibdir)"; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ } -uninstall-toolexeclibLTLIBRARIES: +uninstall-libLTLIBRARIES: @$(NORMAL_UNINSTALL) - @list='$(toolexeclib_LTLIBRARIES)'; test -n "$(toolexeclibdir)" || list=; \ + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ for p in $$list; do \ $(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(toolexeclibdir)/$$f'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(toolexeclibdir)/$$f"; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ done -clean-toolexeclibLTLIBRARIES: - -test -z "$(toolexeclib_LTLIBRARIES)" || rm -f $(toolexeclib_LTLIBRARIES) - @list='$(toolexeclib_LTLIBRARIES)'; \ - locs=`for p in $$list; do echo $$p; done | \ - sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ - sort -u`; \ - test -z "$$locs" || { \ - echo rm -f $${locs}; \ - rm -f $${locs}; \ - } +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done src/$(am__dirstamp): @$(MKDIR_P) src @: > src/$(am__dirstamp) @@ -703,16 +635,6 @@ src/mips/$(DEPDIR)/$(am__dirstamp) src/mips/n32.lo: src/mips/$(am__dirstamp) \ src/mips/$(DEPDIR)/$(am__dirstamp) -src/bfin/$(am__dirstamp): - @$(MKDIR_P) src/bfin - @: > src/bfin/$(am__dirstamp) -src/bfin/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/bfin/$(DEPDIR) - @: > src/bfin/$(DEPDIR)/$(am__dirstamp) -src/bfin/ffi.lo: src/bfin/$(am__dirstamp) \ - src/bfin/$(DEPDIR)/$(am__dirstamp) -src/bfin/sysv.lo: src/bfin/$(am__dirstamp) \ - src/bfin/$(DEPDIR)/$(am__dirstamp) src/x86/$(am__dirstamp): @$(MKDIR_P) src/x86 @: > src/x86/$(am__dirstamp) @@ -787,26 +709,6 @@ src/m68k/$(DEPDIR)/$(am__dirstamp) src/m68k/sysv.lo: src/m68k/$(am__dirstamp) \ src/m68k/$(DEPDIR)/$(am__dirstamp) -src/moxie/$(am__dirstamp): - @$(MKDIR_P) src/moxie - @: > src/moxie/$(am__dirstamp) -src/moxie/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/moxie/$(DEPDIR) - @: > src/moxie/$(DEPDIR)/$(am__dirstamp) -src/moxie/ffi.lo: src/moxie/$(am__dirstamp) \ - src/moxie/$(DEPDIR)/$(am__dirstamp) -src/moxie/eabi.lo: src/moxie/$(am__dirstamp) \ - src/moxie/$(DEPDIR)/$(am__dirstamp) -src/microblaze/$(am__dirstamp): - @$(MKDIR_P) src/microblaze - @: > src/microblaze/$(am__dirstamp) -src/microblaze/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/microblaze/$(DEPDIR) - @: > src/microblaze/$(DEPDIR)/$(am__dirstamp) -src/microblaze/ffi.lo: src/microblaze/$(am__dirstamp) \ - src/microblaze/$(DEPDIR)/$(am__dirstamp) -src/microblaze/sysv.lo: src/microblaze/$(am__dirstamp) \ - src/microblaze/$(DEPDIR)/$(am__dirstamp) src/powerpc/$(am__dirstamp): @$(MKDIR_P) src/powerpc @: > src/powerpc/$(am__dirstamp) @@ -833,16 +735,6 @@ src/powerpc/$(DEPDIR)/$(am__dirstamp) src/powerpc/darwin_closure.lo: src/powerpc/$(am__dirstamp) \ src/powerpc/$(DEPDIR)/$(am__dirstamp) -src/aarch64/$(am__dirstamp): - @$(MKDIR_P) src/aarch64 - @: > src/aarch64/$(am__dirstamp) -src/aarch64/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/aarch64/$(DEPDIR) - @: > src/aarch64/$(DEPDIR)/$(am__dirstamp) -src/aarch64/sysv.lo: src/aarch64/$(am__dirstamp) \ - src/aarch64/$(DEPDIR)/$(am__dirstamp) -src/aarch64/ffi.lo: src/aarch64/$(am__dirstamp) \ - src/aarch64/$(DEPDIR)/$(am__dirstamp) src/arm/$(am__dirstamp): @$(MKDIR_P) src/arm @: > src/arm/$(am__dirstamp) @@ -885,6 +777,16 @@ src/frv/$(DEPDIR)/$(am__dirstamp) src/frv/ffi.lo: src/frv/$(am__dirstamp) \ src/frv/$(DEPDIR)/$(am__dirstamp) +src/moxie/$(am__dirstamp): + @$(MKDIR_P) src/moxie + @: > src/moxie/$(am__dirstamp) +src/moxie/$(DEPDIR)/$(am__dirstamp): + @$(MKDIR_P) src/moxie/$(DEPDIR) + @: > src/moxie/$(DEPDIR)/$(am__dirstamp) +src/moxie/eabi.lo: src/moxie/$(am__dirstamp) \ + src/moxie/$(DEPDIR)/$(am__dirstamp) +src/moxie/ffi.lo: src/moxie/$(am__dirstamp) \ + src/moxie/$(DEPDIR)/$(am__dirstamp) src/s390/$(am__dirstamp): @$(MKDIR_P) src/s390 @: > src/s390/$(am__dirstamp) @@ -927,91 +829,131 @@ src/pa/ffi.lo: src/pa/$(am__dirstamp) src/pa/$(DEPDIR)/$(am__dirstamp) src/pa/hpux32.lo: src/pa/$(am__dirstamp) \ src/pa/$(DEPDIR)/$(am__dirstamp) -src/tile/$(am__dirstamp): - @$(MKDIR_P) src/tile - @: > src/tile/$(am__dirstamp) -src/tile/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/tile/$(DEPDIR) - @: > src/tile/$(DEPDIR)/$(am__dirstamp) -src/tile/tile.lo: src/tile/$(am__dirstamp) \ - src/tile/$(DEPDIR)/$(am__dirstamp) -src/tile/ffi.lo: src/tile/$(am__dirstamp) \ - src/tile/$(DEPDIR)/$(am__dirstamp) -src/xtensa/$(am__dirstamp): - @$(MKDIR_P) src/xtensa - @: > src/xtensa/$(am__dirstamp) -src/xtensa/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/xtensa/$(DEPDIR) - @: > src/xtensa/$(DEPDIR)/$(am__dirstamp) -src/xtensa/sysv.lo: src/xtensa/$(am__dirstamp) \ - src/xtensa/$(DEPDIR)/$(am__dirstamp) -src/xtensa/ffi.lo: src/xtensa/$(am__dirstamp) \ - src/xtensa/$(DEPDIR)/$(am__dirstamp) -src/metag/$(am__dirstamp): - @$(MKDIR_P) src/metag - @: > src/metag/$(am__dirstamp) -src/metag/$(DEPDIR)/$(am__dirstamp): - @$(MKDIR_P) src/metag/$(DEPDIR) - @: > src/metag/$(DEPDIR)/$(am__dirstamp) -src/metag/sysv.lo: src/metag/$(am__dirstamp) \ - src/metag/$(DEPDIR)/$(am__dirstamp) -src/metag/ffi.lo: src/metag/$(am__dirstamp) \ - src/metag/$(DEPDIR)/$(am__dirstamp) libffi.la: $(libffi_la_OBJECTS) $(libffi_la_DEPENDENCIES) $(EXTRA_libffi_la_DEPENDENCIES) - $(libffi_la_LINK) -rpath $(toolexeclibdir) $(libffi_la_OBJECTS) $(libffi_la_LIBADD) $(LIBS) + $(libffi_la_LINK) -rpath $(libdir) $(libffi_la_OBJECTS) $(libffi_la_LIBADD) $(LIBS) libffi_convenience.la: $(libffi_convenience_la_OBJECTS) $(libffi_convenience_la_DEPENDENCIES) $(EXTRA_libffi_convenience_la_DEPENDENCIES) $(LINK) $(libffi_convenience_la_OBJECTS) $(libffi_convenience_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) - -rm -f src/*.$(OBJEXT) - -rm -f src/*.lo - -rm -f src/aarch64/*.$(OBJEXT) - -rm -f src/aarch64/*.lo - -rm -f src/alpha/*.$(OBJEXT) - -rm -f src/alpha/*.lo - -rm -f src/arm/*.$(OBJEXT) - -rm -f src/arm/*.lo - -rm -f src/avr32/*.$(OBJEXT) - -rm -f src/avr32/*.lo - -rm -f src/bfin/*.$(OBJEXT) - -rm -f src/bfin/*.lo - -rm -f src/cris/*.$(OBJEXT) - -rm -f src/cris/*.lo - -rm -f src/frv/*.$(OBJEXT) - -rm -f src/frv/*.lo - -rm -f src/ia64/*.$(OBJEXT) - -rm -f src/ia64/*.lo - -rm -f src/m32r/*.$(OBJEXT) - -rm -f src/m32r/*.lo - -rm -f src/m68k/*.$(OBJEXT) - -rm -f src/m68k/*.lo - -rm -f src/metag/*.$(OBJEXT) - -rm -f src/metag/*.lo - -rm -f src/microblaze/*.$(OBJEXT) - -rm -f src/microblaze/*.lo - -rm -f src/mips/*.$(OBJEXT) - -rm -f src/mips/*.lo - -rm -f src/moxie/*.$(OBJEXT) - -rm -f src/moxie/*.lo - -rm -f src/pa/*.$(OBJEXT) - -rm -f src/pa/*.lo - -rm -f src/powerpc/*.$(OBJEXT) - -rm -f src/powerpc/*.lo - -rm -f src/s390/*.$(OBJEXT) - -rm -f src/s390/*.lo - -rm -f src/sh/*.$(OBJEXT) - -rm -f src/sh/*.lo - -rm -f src/sh64/*.$(OBJEXT) - -rm -f src/sh64/*.lo - -rm -f src/sparc/*.$(OBJEXT) - -rm -f src/sparc/*.lo - -rm -f src/tile/*.$(OBJEXT) - -rm -f src/tile/*.lo - -rm -f src/x86/*.$(OBJEXT) - -rm -f src/x86/*.lo - -rm -f src/xtensa/*.$(OBJEXT) - -rm -f src/xtensa/*.lo + -rm -f src/alpha/ffi.$(OBJEXT) + -rm -f src/alpha/ffi.lo + -rm -f src/alpha/osf.$(OBJEXT) + -rm -f src/alpha/osf.lo + -rm -f src/arm/ffi.$(OBJEXT) + -rm -f src/arm/ffi.lo + -rm -f src/arm/sysv.$(OBJEXT) + -rm -f src/arm/sysv.lo + -rm -f src/arm/trampoline.$(OBJEXT) + -rm -f src/arm/trampoline.lo + -rm -f src/avr32/ffi.$(OBJEXT) + -rm -f src/avr32/ffi.lo + -rm -f src/avr32/sysv.$(OBJEXT) + -rm -f src/avr32/sysv.lo + -rm -f src/closures.$(OBJEXT) + -rm -f src/closures.lo + -rm -f src/cris/ffi.$(OBJEXT) + -rm -f src/cris/ffi.lo + -rm -f src/cris/sysv.$(OBJEXT) + -rm -f src/cris/sysv.lo + -rm -f src/debug.$(OBJEXT) + -rm -f src/debug.lo + -rm -f src/frv/eabi.$(OBJEXT) + -rm -f src/frv/eabi.lo + -rm -f src/frv/ffi.$(OBJEXT) + -rm -f src/frv/ffi.lo + -rm -f src/ia64/ffi.$(OBJEXT) + -rm -f src/ia64/ffi.lo + -rm -f src/ia64/unix.$(OBJEXT) + -rm -f src/ia64/unix.lo + -rm -f src/java_raw_api.$(OBJEXT) + -rm -f src/java_raw_api.lo + -rm -f src/m32r/ffi.$(OBJEXT) + -rm -f src/m32r/ffi.lo + -rm -f src/m32r/sysv.$(OBJEXT) + -rm -f src/m32r/sysv.lo + -rm -f src/m68k/ffi.$(OBJEXT) + -rm -f src/m68k/ffi.lo + -rm -f src/m68k/sysv.$(OBJEXT) + -rm -f src/m68k/sysv.lo + -rm -f src/mips/ffi.$(OBJEXT) + -rm -f src/mips/ffi.lo + -rm -f src/mips/n32.$(OBJEXT) + -rm -f src/mips/n32.lo + -rm -f src/mips/o32.$(OBJEXT) + -rm -f src/mips/o32.lo + -rm -f src/moxie/eabi.$(OBJEXT) + -rm -f src/moxie/eabi.lo + -rm -f src/moxie/ffi.$(OBJEXT) + -rm -f src/moxie/ffi.lo + -rm -f src/pa/ffi.$(OBJEXT) + -rm -f src/pa/ffi.lo + -rm -f src/pa/hpux32.$(OBJEXT) + -rm -f src/pa/hpux32.lo + -rm -f src/pa/linux.$(OBJEXT) + -rm -f src/pa/linux.lo + -rm -f src/powerpc/aix.$(OBJEXT) + -rm -f src/powerpc/aix.lo + -rm -f src/powerpc/aix_closure.$(OBJEXT) + -rm -f src/powerpc/aix_closure.lo + -rm -f src/powerpc/darwin.$(OBJEXT) + -rm -f src/powerpc/darwin.lo + -rm -f src/powerpc/darwin_closure.$(OBJEXT) + -rm -f src/powerpc/darwin_closure.lo + -rm -f src/powerpc/ffi.$(OBJEXT) + -rm -f src/powerpc/ffi.lo + -rm -f src/powerpc/ffi_darwin.$(OBJEXT) + -rm -f src/powerpc/ffi_darwin.lo + -rm -f src/powerpc/linux64.$(OBJEXT) + -rm -f src/powerpc/linux64.lo + -rm -f src/powerpc/linux64_closure.$(OBJEXT) + -rm -f src/powerpc/linux64_closure.lo + -rm -f src/powerpc/ppc_closure.$(OBJEXT) + -rm -f src/powerpc/ppc_closure.lo + -rm -f src/powerpc/sysv.$(OBJEXT) + -rm -f src/powerpc/sysv.lo + -rm -f src/prep_cif.$(OBJEXT) + -rm -f src/prep_cif.lo + -rm -f src/raw_api.$(OBJEXT) + -rm -f src/raw_api.lo + -rm -f src/s390/ffi.$(OBJEXT) + -rm -f src/s390/ffi.lo + -rm -f src/s390/sysv.$(OBJEXT) + -rm -f src/s390/sysv.lo + -rm -f src/sh/ffi.$(OBJEXT) + -rm -f src/sh/ffi.lo + -rm -f src/sh/sysv.$(OBJEXT) + -rm -f src/sh/sysv.lo + -rm -f src/sh64/ffi.$(OBJEXT) + -rm -f src/sh64/ffi.lo + -rm -f src/sh64/sysv.$(OBJEXT) + -rm -f src/sh64/sysv.lo + -rm -f src/sparc/ffi.$(OBJEXT) + -rm -f src/sparc/ffi.lo + -rm -f src/sparc/v8.$(OBJEXT) + -rm -f src/sparc/v8.lo + -rm -f src/sparc/v9.$(OBJEXT) + -rm -f src/sparc/v9.lo + -rm -f src/types.$(OBJEXT) + -rm -f src/types.lo + -rm -f src/x86/darwin.$(OBJEXT) + -rm -f src/x86/darwin.lo + -rm -f src/x86/darwin64.$(OBJEXT) + -rm -f src/x86/darwin64.lo + -rm -f src/x86/ffi.$(OBJEXT) + -rm -f src/x86/ffi.lo + -rm -f src/x86/ffi64.$(OBJEXT) + -rm -f src/x86/ffi64.lo + -rm -f src/x86/freebsd.$(OBJEXT) + -rm -f src/x86/freebsd.lo + -rm -f src/x86/sysv.$(OBJEXT) + -rm -f src/x86/sysv.lo + -rm -f src/x86/unix64.$(OBJEXT) + -rm -f src/x86/unix64.lo + -rm -f src/x86/win32.$(OBJEXT) + -rm -f src/x86/win32.lo + -rm -f src/x86/win64.$(OBJEXT) + -rm -f src/x86/win64.lo distclean-compile: -rm -f *.tab.c @@ -1022,8 +964,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/prep_cif.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/raw_api.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/types.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/aarch64/$(DEPDIR)/ffi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/aarch64/$(DEPDIR)/sysv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/alpha/$(DEPDIR)/ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/alpha/$(DEPDIR)/osf.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/arm/$(DEPDIR)/ffi.Plo@am__quote@ @@ -1031,8 +971,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@src/arm/$(DEPDIR)/trampoline.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/avr32/$(DEPDIR)/ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/avr32/$(DEPDIR)/sysv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/bfin/$(DEPDIR)/ffi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/bfin/$(DEPDIR)/sysv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/cris/$(DEPDIR)/ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/cris/$(DEPDIR)/sysv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/frv/$(DEPDIR)/eabi.Plo@am__quote@ @@ -1043,10 +981,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@src/m32r/$(DEPDIR)/sysv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/m68k/$(DEPDIR)/ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/m68k/$(DEPDIR)/sysv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/metag/$(DEPDIR)/ffi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/metag/$(DEPDIR)/sysv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/microblaze/$(DEPDIR)/ffi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/microblaze/$(DEPDIR)/sysv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/mips/$(DEPDIR)/ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/mips/$(DEPDIR)/n32.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/mips/$(DEPDIR)/o32.Plo@am__quote@ @@ -1074,8 +1008,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@src/sparc/$(DEPDIR)/ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/sparc/$(DEPDIR)/v8.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/sparc/$(DEPDIR)/v9.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/tile/$(DEPDIR)/ffi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/tile/$(DEPDIR)/tile.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/x86/$(DEPDIR)/darwin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/x86/$(DEPDIR)/darwin64.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/x86/$(DEPDIR)/ffi.Plo@am__quote@ @@ -1085,8 +1017,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@src/x86/$(DEPDIR)/unix64.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/x86/$(DEPDIR)/win32.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/x86/$(DEPDIR)/win64.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/xtensa/$(DEPDIR)/ffi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/xtensa/$(DEPDIR)/sysv.Plo@am__quote@ .S.o: @am__fastdepCCAS_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -1142,18 +1072,14 @@ clean-libtool: -rm -rf .libs _libs -rm -rf src/.libs src/_libs - -rm -rf src/aarch64/.libs src/aarch64/_libs -rm -rf src/alpha/.libs src/alpha/_libs -rm -rf src/arm/.libs src/arm/_libs -rm -rf src/avr32/.libs src/avr32/_libs - -rm -rf src/bfin/.libs src/bfin/_libs -rm -rf src/cris/.libs src/cris/_libs -rm -rf src/frv/.libs src/frv/_libs -rm -rf src/ia64/.libs src/ia64/_libs -rm -rf src/m32r/.libs src/m32r/_libs -rm -rf src/m68k/.libs src/m68k/_libs - -rm -rf src/metag/.libs src/metag/_libs - -rm -rf src/microblaze/.libs src/microblaze/_libs -rm -rf src/mips/.libs src/mips/_libs -rm -rf src/moxie/.libs src/moxie/_libs -rm -rf src/pa/.libs src/pa/_libs @@ -1162,9 +1088,7 @@ -rm -rf src/sh/.libs src/sh/_libs -rm -rf src/sh64/.libs src/sh64/_libs -rm -rf src/sparc/.libs src/sparc/_libs - -rm -rf src/tile/.libs src/tile/_libs -rm -rf src/x86/.libs src/x86/_libs - -rm -rf src/xtensa/.libs src/xtensa/_libs distclean-libtool: -rm -f libtool config.lt @@ -1197,12 +1121,12 @@ doc/libffi.dvi: doc/libffi.texi $(srcdir)/doc/version.texi doc/$(am__dirstamp) TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \ MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I doc -I $(srcdir)/doc' \ - $(TEXI2DVI) --clean -o $@ `test -f 'doc/libffi.texi' || echo '$(srcdir)/'`doc/libffi.texi + $(TEXI2DVI) -o $@ `test -f 'doc/libffi.texi' || echo '$(srcdir)/'`doc/libffi.texi doc/libffi.pdf: doc/libffi.texi $(srcdir)/doc/version.texi doc/$(am__dirstamp) TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \ MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I doc -I $(srcdir)/doc' \ - $(TEXI2PDF) --clean -o $@ `test -f 'doc/libffi.texi' || echo '$(srcdir)/'`doc/libffi.texi + $(TEXI2PDF) -o $@ `test -f 'doc/libffi.texi' || echo '$(srcdir)/'`doc/libffi.texi doc/libffi.html: doc/libffi.texi $(srcdir)/doc/version.texi doc/$(am__dirstamp) rm -rf $(@:.html=.htp) @@ -1239,7 +1163,7 @@ @MAINTAINER_MODE_TRUE@ -rm -f $(srcdir)/doc/stamp-vti $(srcdir)/doc/version.texi .dvi.ps: TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \ - $(DVIPS) -o $@ $< + $(DVIPS) -o $@ $< uninstall-dvi-am: @$(NORMAL_UNINSTALL) @@ -1261,7 +1185,9 @@ uninstall-info-am: @$(PRE_UNINSTALL) - @if test -d '$(DESTDIR)$(infodir)' && $(am__can_run_installinfo); then \ + @if test -d '$(DESTDIR)$(infodir)' && \ + (install-info --version && \ + install-info --version 2>&1 | sed 1q | grep -i -v debian) >/dev/null 2>&1; then \ list='$(INFO_DEPS)'; \ for file in $$list; do \ relfile=`echo "$$file" | sed 's|^.*/||'`; \ @@ -1333,11 +1259,8 @@ done install-pkgconfigDATA: $(pkgconfig_DATA) @$(NORMAL_INSTALL) + test -z "$(pkgconfigdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(pkgconfigdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -1354,12 +1277,12 @@ dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir) # This directory's subdirectories are mostly independent; you can cd -# into them and run 'make' without going through this Makefile. -# To change the values of 'make' variables: instead of editing Makefiles, -# (1) if the variable is set in 'config.status', edit 'config.status' -# (which will cause the Makefiles to be regenerated when you run 'make'); -# (2) otherwise, pass the desired values on the 'make' command line. -$(RECURSIVE_TARGETS) $(RECURSIVE_CLEAN_TARGETS): +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): @fail= failcom='exit 1'; \ for f in x $$MAKEFLAGS; do \ case $$f in \ @@ -1369,11 +1292,7 @@ done; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ - case "$@" in \ - distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ - *) list='$(SUBDIRS)' ;; \ - esac; \ - for subdir in $$list; do \ + list='$(SUBDIRS)'; for subdir in $$list; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ dot_seen=yes; \ @@ -1387,6 +1306,37 @@ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" tags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ @@ -1395,10 +1345,6 @@ list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ done -cscopelist-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ - done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -1462,32 +1408,8 @@ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscope: cscope.files - test ! -s cscope.files \ - || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) - -clean-cscope: - -rm -f cscope.files - -cscope.files: clean-cscope cscopelist-recursive cscopelist - -cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS) $(LISP)'; \ - case "$(srcdir)" in \ - [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ - *) sdir=$(subdir)/$(srcdir) ;; \ - esac; \ - for i in $$list; do \ - if test -f "$$i"; then \ - echo "$(subdir)/$$i"; \ - else \ - echo "$$sdir/$$i"; \ - fi; \ - done >> $(top_builddir)/cscope.files - distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -rm -f cscope.out cscope.in.out cscope.po.out cscope.files distdir: $(DISTFILES) $(am__remove_distdir) @@ -1523,10 +1445,13 @@ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ - $(am__make_dryrun) \ - || test -d "$(distdir)/$$subdir" \ - || $(MKDIR_P) "$(distdir)/$$subdir" \ - || exit 1; \ + test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ @@ -1558,36 +1483,40 @@ || chmod -R a+r "$(distdir)" dist-gzip: distdir tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__post_remove_distdir) + $(am__remove_distdir) dist-bzip2: distdir tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 - $(am__post_remove_distdir) + $(am__remove_distdir) dist-lzip: distdir tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz - $(am__post_remove_distdir) + $(am__remove_distdir) + +dist-lzma: distdir + tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma + $(am__remove_distdir) dist-xz: distdir tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz - $(am__post_remove_distdir) + $(am__remove_distdir) dist-tarZ: distdir tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z - $(am__post_remove_distdir) + $(am__remove_distdir) dist-shar: distdir shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz - $(am__post_remove_distdir) + $(am__remove_distdir) dist-zip: distdir -rm -f $(distdir).zip zip -rq $(distdir).zip $(distdir) - $(am__post_remove_distdir) + $(am__remove_distdir) -dist dist-all: - $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' - $(am__post_remove_distdir) +dist dist-all: distdir + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__remove_distdir) # This target untars the dist file and tries a VPATH configuration. Then # it guarantees that the distribution is self-contained by making another @@ -1598,6 +1527,8 @@ GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ + *.tar.lzma*) \ + lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ *.tar.lz*) \ lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ *.tar.xz*) \ @@ -1609,7 +1540,7 @@ *.zip*) \ unzip $(distdir).zip ;;\ esac - chmod -R a-w $(distdir); chmod u+w $(distdir) + chmod -R a-w $(distdir); chmod a+w $(distdir) mkdir $(distdir)/_build mkdir $(distdir)/_inst chmod a-w $(distdir) @@ -1643,7 +1574,7 @@ && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ && cd "$$am__cwd" \ || exit 1 - $(am__post_remove_distdir) + $(am__remove_distdir) @(echo "$(distdir) archives ready for distribution: "; \ list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' @@ -1678,7 +1609,7 @@ all-am: Makefile $(INFO_DEPS) $(LTLIBRARIES) $(DATA) fficonfig.h installdirs: installdirs-recursive installdirs-am: - for dir in "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(infodir)" "$(DESTDIR)$(pkgconfigdir)"; do \ + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(infodir)" "$(DESTDIR)$(pkgconfigdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-recursive @@ -1710,16 +1641,12 @@ -rm -f doc/$(am__dirstamp) -rm -f src/$(DEPDIR)/$(am__dirstamp) -rm -f src/$(am__dirstamp) - -rm -f src/aarch64/$(DEPDIR)/$(am__dirstamp) - -rm -f src/aarch64/$(am__dirstamp) -rm -f src/alpha/$(DEPDIR)/$(am__dirstamp) -rm -f src/alpha/$(am__dirstamp) -rm -f src/arm/$(DEPDIR)/$(am__dirstamp) -rm -f src/arm/$(am__dirstamp) -rm -f src/avr32/$(DEPDIR)/$(am__dirstamp) -rm -f src/avr32/$(am__dirstamp) - -rm -f src/bfin/$(DEPDIR)/$(am__dirstamp) - -rm -f src/bfin/$(am__dirstamp) -rm -f src/cris/$(DEPDIR)/$(am__dirstamp) -rm -f src/cris/$(am__dirstamp) -rm -f src/frv/$(DEPDIR)/$(am__dirstamp) @@ -1730,10 +1657,6 @@ -rm -f src/m32r/$(am__dirstamp) -rm -f src/m68k/$(DEPDIR)/$(am__dirstamp) -rm -f src/m68k/$(am__dirstamp) - -rm -f src/metag/$(DEPDIR)/$(am__dirstamp) - -rm -f src/metag/$(am__dirstamp) - -rm -f src/microblaze/$(DEPDIR)/$(am__dirstamp) - -rm -f src/microblaze/$(am__dirstamp) -rm -f src/mips/$(DEPDIR)/$(am__dirstamp) -rm -f src/mips/$(am__dirstamp) -rm -f src/moxie/$(DEPDIR)/$(am__dirstamp) @@ -1750,25 +1673,20 @@ -rm -f src/sh64/$(am__dirstamp) -rm -f src/sparc/$(DEPDIR)/$(am__dirstamp) -rm -f src/sparc/$(am__dirstamp) - -rm -f src/tile/$(DEPDIR)/$(am__dirstamp) - -rm -f src/tile/$(am__dirstamp) -rm -f src/x86/$(DEPDIR)/$(am__dirstamp) -rm -f src/x86/$(am__dirstamp) - -rm -f src/xtensa/$(DEPDIR)/$(am__dirstamp) - -rm -f src/xtensa/$(am__dirstamp) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-recursive -clean-am: clean-aminfo clean-generic clean-libtool \ - clean-noinstLTLIBRARIES clean-toolexeclibLTLIBRARIES \ - mostlyclean-am +clean-am: clean-aminfo clean-generic clean-libLTLIBRARIES \ + clean-libtool clean-noinstLTLIBRARIES mostlyclean-am distclean: distclean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) - -rm -rf src/$(DEPDIR) src/aarch64/$(DEPDIR) src/alpha/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/bfin/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/metag/$(DEPDIR) src/microblaze/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/tile/$(DEPDIR) src/x86/$(DEPDIR) src/xtensa/$(DEPDIR) + -rm -rf src/$(DEPDIR) src/alpha/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/x86/$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-hdr distclean-libtool distclean-tags @@ -1791,11 +1709,8 @@ install-dvi-am: $(DVIS) @$(NORMAL_INSTALL) + test -z "$(dvidir)" || $(MKDIR_P) "$(DESTDIR)$(dvidir)" @list='$(DVIS)'; test -n "$(dvidir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(dvidir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(dvidir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -1804,17 +1719,12 @@ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(dvidir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(dvidir)" || exit $$?; \ done -install-exec-am: install-toolexeclibLTLIBRARIES - -install-html: install-html-recursive +install-exec-am: install-libLTLIBRARIES install-html-am: $(HTMLS) @$(NORMAL_INSTALL) + test -z "$(htmldir)" || $(MKDIR_P) "$(DESTDIR)$(htmldir)" @list='$(HTMLS)'; list2=; test -n "$(htmldir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(htmldir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(htmldir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p" || test -d "$$p"; then d=; else d="$(srcdir)/"; fi; \ $(am__strip_dir) \ @@ -1837,12 +1747,9 @@ install-info-am: $(INFO_DEPS) @$(NORMAL_INSTALL) + test -z "$(infodir)" || $(MKDIR_P) "$(DESTDIR)$(infodir)" @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ list='$(INFO_DEPS)'; test -n "$(infodir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(infodir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(infodir)" || exit 1; \ - fi; \ for file in $$list; do \ case $$file in \ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ @@ -1860,7 +1767,13 @@ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(infodir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(infodir)" || exit $$?; done @$(POST_INSTALL) - @if $(am__can_run_installinfo); then \ + @am__run_installinfo=yes; \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) am__run_installinfo=no;; \ + *) (install-info --version) >/dev/null 2>&1 \ + || am__run_installinfo=no;; \ + esac; \ + if test $$am__run_installinfo = yes; then \ list='$(INFO_DEPS)'; test -n "$(infodir)" || list=; \ for file in $$list; do \ relfile=`echo "$$file" | sed 's|^.*/||'`; \ @@ -1870,15 +1783,10 @@ else : ; fi install-man: -install-pdf: install-pdf-recursive - install-pdf-am: $(PDFS) @$(NORMAL_INSTALL) + test -z "$(pdfdir)" || $(MKDIR_P) "$(DESTDIR)$(pdfdir)" @list='$(PDFS)'; test -n "$(pdfdir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(pdfdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(pdfdir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -1890,11 +1798,8 @@ install-ps-am: $(PSS) @$(NORMAL_INSTALL) + test -z "$(psdir)" || $(MKDIR_P) "$(DESTDIR)$(psdir)" @list='$(PSS)'; test -n "$(psdir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(psdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(psdir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -1907,7 +1812,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(top_srcdir)/autom4te.cache - -rm -rf src/$(DEPDIR) src/aarch64/$(DEPDIR) src/alpha/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/bfin/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/metag/$(DEPDIR) src/microblaze/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/tile/$(DEPDIR) src/x86/$(DEPDIR) src/xtensa/$(DEPDIR) + -rm -rf src/$(DEPDIR) src/alpha/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/x86/$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-aminfo \ maintainer-clean-generic maintainer-clean-vti @@ -1926,39 +1831,41 @@ ps-am: $(PSS) uninstall-am: uninstall-dvi-am uninstall-html-am uninstall-info-am \ - uninstall-pdf-am uninstall-pkgconfigDATA uninstall-ps-am \ - uninstall-toolexeclibLTLIBRARIES + uninstall-libLTLIBRARIES uninstall-pdf-am \ + uninstall-pkgconfigDATA uninstall-ps-am .MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \ - cscopelist-recursive ctags-recursive install-am install-strip \ - tags-recursive + ctags-recursive install-am install-strip tags-recursive .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ all all-am am--refresh check check-am clean clean-aminfo \ - clean-cscope clean-generic clean-libtool \ - clean-noinstLTLIBRARIES clean-toolexeclibLTLIBRARIES cscope \ - cscopelist cscopelist-recursive ctags ctags-recursive dist \ - dist-all dist-bzip2 dist-gzip dist-info dist-lzip dist-shar \ + clean-generic clean-libLTLIBRARIES clean-libtool \ + clean-noinstLTLIBRARIES ctags ctags-recursive dist dist-all \ + dist-bzip2 dist-gzip dist-info dist-lzip dist-lzma dist-shar \ dist-tarZ dist-xz dist-zip distcheck distclean \ distclean-compile distclean-generic distclean-hdr \ distclean-libtool distclean-tags distcleancheck distdir \ distuninstallcheck dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-pkgconfigDATA install-ps \ - install-ps-am install-strip install-toolexeclibLTLIBRARIES \ + install-html-am install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-pkgconfigDATA install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs installdirs-am \ maintainer-clean maintainer-clean-aminfo \ maintainer-clean-generic maintainer-clean-vti mostlyclean \ mostlyclean-aminfo mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool mostlyclean-vti pdf pdf-am ps ps-am tags \ tags-recursive uninstall uninstall-am uninstall-dvi-am \ - uninstall-html-am uninstall-info-am uninstall-pdf-am \ - uninstall-pkgconfigDATA uninstall-ps-am \ - uninstall-toolexeclibLTLIBRARIES + uninstall-html-am uninstall-info-am uninstall-libLTLIBRARIES \ + uninstall-pdf-am uninstall-pkgconfigDATA uninstall-ps-am +# No install-html or install-pdf support in automake yet +.PHONY: install-html install-pdf +install-html: +install-pdf: + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/README --- a/Modules/_ctypes/libffi/README Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/README Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ Status ====== -libffi-3.0.13 was released on March 17, 2013. Check the libffi web +libffi-3.0.11 was released on April 11, 2012. Check the libffi web page for updates: . @@ -43,70 +43,54 @@ For specific configuration details and testing status, please refer to the wiki page here: - http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.13 + http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.11 At the time of release, the following basic configurations have been tested: -|-----------------+------------------+-------------------------| -| Architecture | Operating System | Compiler | -|-----------------+------------------+-------------------------| -| AArch64 | Linux | GCC | -| Alpha | Linux | GCC | -| Alpha | Tru64 | GCC | -| ARM | Linux | GCC | -| ARM | iOS | GCC | -| AVR32 | Linux | GCC | -| Blackfin | uClinux | GCC | -| HPPA | HPUX | GCC | -| IA-64 | Linux | GCC | -| M68K | FreeMiNT | GCC | -| M68K | Linux | GCC | -| M68K | RTEMS | GCC | -| Meta | Linux | GCC | -| MicroBlaze | Linux | GCC | -| MIPS | IRIX | GCC | -| MIPS | Linux | GCC | -| MIPS | RTEMS | GCC | -| MIPS64 | Linux | GCC | -| Moxie | Bare metal | GCC -| PowerPC 32-bit | AIX | IBM XL C | -| PowerPC 64-bit | AIX | IBM XL C | -| PowerPC | AMIGA | GCC | -| PowerPC | Linux | GCC | -| PowerPC | Mac OSX | GCC | -| PowerPC | FreeBSD | GCC | -| PowerPC 64-bit | FreeBSD | GCC | -| PowerPC 64-bit | Linux | GCC | -| S390 | Linux | GCC | -| S390X | Linux | GCC | -| SPARC | Linux | GCC | -| SPARC | Solaris | GCC | -| SPARC | Solaris | Oracle Solaris Studio C | -| SPARC64 | Linux | GCC | -| SPARC64 | FreeBSD | GCC | -| SPARC64 | Solaris | Oracle Solaris Studio C | -| TILE-Gx/TILEPro | Linux | GCC | -| X86 | FreeBSD | GCC | -| X86 | GNU HURD | GCC | -| X86 | Interix | GCC | -| X86 | kFreeBSD | GCC | -| X86 | Linux | GCC | -| X86 | Mac OSX | GCC | -| X86 | OpenBSD | GCC | -| X86 | OS/2 | GCC | -| X86 | Solaris | GCC | -| X86 | Solaris | Oracle Solaris Studio C | -| X86 | Windows/Cygwin | GCC | -| X86 | Windows/MingW | GCC | -| X86-64 | FreeBSD | GCC | -| X86-64 | Linux | GCC | -| X86-64 | Linux/x32 | GCC | -| X86-64 | OpenBSD | GCC | -| X86-64 | Solaris | Oracle Solaris Studio C | -| X86-64 | Windows/MingW | GCC | -| Xtensa | Linux | GCC | -|-----------------+------------------+-------------------------| +|--------------+------------------| +| Architecture | Operating System | +|--------------+------------------| +| Alpha | Linux | +| Alpha | Tru64 | +| ARM | Linux | +| ARM | iOS | +| AVR32 | Linux | +| HPPA | HPUX | +| IA-64 | Linux | +| M68K | FreeMiNT | +| M68K | RTEMS | +| MIPS | IRIX | +| MIPS | Linux | +| MIPS | RTEMS | +| MIPS64 | Linux | +| PowerPC | AMIGA | +| PowerPC | Linux | +| PowerPC | Mac OSX | +| PowerPC | FreeBSD | +| PowerPC64 | Linux | +| S390 | Linux | +| S390X | Linux | +| SPARC | Linux | +| SPARC | Solaris | +| SPARC64 | Linux | +| SPARC64 | FreeBSD | +| X86 | FreeBSD | +| X86 | Interix | +| X86 | kFreeBSD | +| X86 | Linux | +| X86 | Mac OSX | +| X86 | OpenBSD | +| X86 | OS/2 | +| X86 | Solaris | +| X86 | Windows/Cygwin | +| X86 | Windows/MingW | +| X86-64 | FreeBSD | +| X86-64 | Linux | +| X86-64 | Linux/x32 | +| X86-64 | OpenBSD | +| X86-64 | Windows/MingW | +|--------------+------------------| Please send additional platform test results to libffi-discuss@sourceware.org and feel free to update the wiki page @@ -145,12 +129,13 @@ that sets 'fix_srcfile_path' to a 'cygpath' command. ('cygpath' is not present in MingW, and is not required when using MingW-style paths.) -For iOS builds, the 'libffi.xcodeproj' Xcode project is available. +For iOS builds, run generate-ios-source-and-headers.py and then +libffi.xcodeproj should work. Configure has many other options. Use "configure --help" to see them all. Once configure has finished, type "make". Note that you must be using -GNU make. You can ftp GNU make from ftp.gnu.org:/pub/gnu/make . +GNU make. You can ftp GNU make from prep.ai.mit.edu:/pub/gnu. To ensure that libffi is working as advertised, type "make check". This will require that you have DejaGNU installed. @@ -163,39 +148,16 @@ See the ChangeLog files for details. -3.0.13 Mar-17-13 - Add Meta support. - Add missing Moxie bits. - Fix stack alignment bug on 32-bit x86. - Build fix for m68000 targets. - Build fix for soft-float Power targets. - Fix the install dir location for some platforms when building - with GCC (OS X, Solaris). - Fix Cygwin regression. - -3.0.12 Feb-11-13 - Add Moxie support. - Add AArch64 support. - Add Blackfin support. - Add TILE-Gx/TILEPro support. - Add MicroBlaze support. - Add Xtensa support. - Add support for PaX enabled kernels with MPROTECT. - Add support for native vendor compilers on - Solaris and AIX. - Work around LLVM/GCC interoperability issue on x86_64. - 3.0.11 Apr-11-12 - Lots of build fixes. - Add Amiga newer MacOS support. - Add support for variadic functions (ffi_prep_cif_var). + Add support for variadic functions (ffi_prep_cif_var). Add Linux/x32 support. Add thiscall, fastcall and MSVC cdecl support on Windows. - Add Amiga and newer MacOS support. + Add Amiga and newer MacOS support. Add m68k FreeMiNT support. Integration with iOS' xcode build tools. Fix Octeon and MC68881 support. Fix code pessimizations. + Lots of build fixes. 3.0.10 Aug-23-11 Add support for Apple's iOS. @@ -339,7 +301,7 @@ Authors & Credits ================= -libffi was originally written by Anthony Green . +libffi was originally written by Anthony Green . The developers of the GNU Compiler Collection project have made innumerable valuable contributions. See the ChangeLog file for @@ -354,19 +316,15 @@ Major processor architecture ports were contributed by the following developers: -aarch64 Marcus Shawcroft, James Greenhalgh alpha Richard Henderson arm Raffaele Sena -blackfin Alexandre Keunecke I. de Mendonca cris Simon Posnjak, Hans-Peter Nilsson frv Anthony Green ia64 Hans Boehm m32r Kazuhiro Inaoka m68k Andreas Schwab -microblaze Nathan Rossi mips Anthony Green, Casey Marshall mips64 David Daney -moxie Anthony Green pa Randolph Chung, Dave Anglin, Andreas Tobler powerpc Geoffrey Keating, Andreas Tobler, David Edelsohn, John Hornkvist @@ -375,10 +333,8 @@ sh Kaz Kojima sh64 Kaz Kojima sparc Anthony Green, Gordon Irlam -tile-gx/tilepro Walter Lee x86 Anthony Green, Jon Beniston x86-64 Bo Thorsen -xtensa Chris Zankel Jesper Skov and Andrew Haley both did more than their fair share of stepping through the code and tracking down bugs. diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/aclocal.m4 --- a/Modules/_ctypes/libffi/aclocal.m4 Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/aclocal.m4 Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,8 @@ -# generated automatically by aclocal 1.12.2 -*- Autoconf -*- +# generated automatically by aclocal 1.11.3 -*- Autoconf -*- -# Copyright (C) 1996-2012 Free Software Foundation, Inc. - +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, +# Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -13,11 +14,11 @@ m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, -[m4_warning([this file was generated for autoconf 2.69. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],, +[m4_warning([this file was generated for autoconf 2.68. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. -To do so, use the procedure documented by the package, typically 'autoreconf'.])]) +To do so, use the procedure documented by the package, typically `autoreconf'.])]) # ltdl.m4 - Configure ltdl for the target system. -*-Autoconf-*- # @@ -514,7 +515,7 @@ # at 6.2 and later dlopen does load deplibs. lt_cv_sys_dlopen_deplibs=yes ;; - netbsd*) + netbsd* | netbsdelf*-gnu) lt_cv_sys_dlopen_deplibs=yes ;; openbsd*) @@ -837,13 +838,14 @@ dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LTDL_DLSYM_USCORE], []) -# Copyright (C) 2002-2012 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 Free Software +# Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 8 +# serial 1 # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- @@ -851,10 +853,10 @@ # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], -[am__api_version='1.12' +[am__api_version='1.11' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.12.2], [], +m4_if([$1], [1.11.3], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -870,14 +872,14 @@ # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.12.2])dnl +[AM_AUTOMAKE_VERSION([1.11.3])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # Figure out how to run the assembler. -*- Autoconf -*- -# Copyright (C) 2001-2012 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -899,17 +901,17 @@ # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2012 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 2 +# serial 1 # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets -# $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to -# '$srcdir', '$srcdir/..', or '$srcdir/../..'. +# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to +# `$srcdir', `$srcdir/..', or `$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and @@ -928,7 +930,7 @@ # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually -# harmless because $srcdir is '.', but things will broke when you +# harmless because $srcdir is `.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, @@ -954,21 +956,22 @@ # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2012 Free Software Foundation, Inc. +# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 +# Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 10 +# serial 9 # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], -[AC_PREREQ([2.52])dnl - m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], - [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +[AC_PREREQ(2.52)dnl + ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl @@ -987,15 +990,16 @@ Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2012 Free Software Foundation, Inc. +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, +# 2010, 2011 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 17 +# serial 12 -# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be +# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing @@ -1005,7 +1009,7 @@ # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. -# NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". +# NAME is "CC", "CXX", "GCJ", or "OBJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was @@ -1018,13 +1022,12 @@ AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl -m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], - [$1], [CXX], [depcc="$CXX" am_compiler_list=], - [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], - [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], - [$1], [UPC], [depcc="$UPC" am_compiler_list=], - [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], - [depcc="$$1" am_compiler_list=]) +ifelse([$1], CC, [depcc="$CC" am_compiler_list=], + [$1], CXX, [depcc="$CXX" am_compiler_list=], + [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], UPC, [depcc="$UPC" am_compiler_list=], + [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], @@ -1032,8 +1035,8 @@ # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named 'D' -- because '-MD' means "put the output - # in D". + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're @@ -1073,16 +1076,16 @@ : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with - # Solaris 10 /bin/sh. - echo '/* dummy */' > sub/conftst$i.h + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - # We check with '-c' and '-o' for the sake of the "dashmstdout" + # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly - # handle '-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs. + # handle `-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in @@ -1091,8 +1094,8 @@ test "$am__universal" = false || continue ;; nosideeffect) - # After this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested. + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else @@ -1100,7 +1103,7 @@ fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok '-c -o', but also, the minuso test has + # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} @@ -1148,7 +1151,7 @@ # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. -# This macro is AC_REQUIREd in _AM_DEPENDENCIES. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl @@ -1158,13 +1161,9 @@ # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], -[AC_ARG_ENABLE([dependency-tracking], [dnl -AS_HELP_STRING( - [--enable-dependency-tracking], - [do not reject slow dependency extractors]) -AS_HELP_STRING( - [--disable-dependency-tracking], - [speeds up one-time build])]) +[AC_ARG_ENABLE(dependency-tracking, +[ --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' @@ -1179,13 +1178,14 @@ # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2012 Free Software Foundation, Inc. +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 6 +#serial 5 # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ @@ -1204,7 +1204,7 @@ # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named 'Makefile.in', but + # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. @@ -1216,19 +1216,21 @@ continue fi # Extract the definition of DEPDIR, am__include, and am__quote - # from the Makefile without running 'make'. + # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`AS_DIRNAME(["$file"])` @@ -1246,7 +1248,7 @@ # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking -# is enabled. FIXME. This creates each '.P' file that we will +# is enabled. FIXME. This creates each `.P' file that we will # need in order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], @@ -1256,13 +1258,14 @@ # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2012 Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2008, 2009 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 19 +# serial 16 # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. @@ -1308,41 +1311,31 @@ # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], -[AC_DIAGNOSE([obsolete], -[$0: two- and three-arguments forms are deprecated. For more info, see: -http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_INIT_AUTOMAKE-invocation]) -m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl +[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. -m4_if( - m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), - [ok:ok],, +m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, -[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) - AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl +[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) + AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl -AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) -AM_MISSING_PROG([AUTOCONF], [autoconf]) -AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) -AM_MISSING_PROG([AUTOHEADER], [autoheader]) -AM_MISSING_PROG([MAKEINFO], [makeinfo]) +AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) +AM_MISSING_PROG(AUTOCONF, autoconf) +AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) +AM_MISSING_PROG(AUTOHEADER, autoheader) +AM_MISSING_PROG(MAKEINFO, makeinfo) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl -AC_REQUIRE([AC_PROG_MKDIR_P])dnl -# For better backward compatibility. To be removed once Automake 1.9.x -# dies out for good. For more background, see: -# -# -AC_SUBST([mkdir_p], ['$(MKDIR_P)']) +AC_REQUIRE([AM_PROG_MKDIR_P])dnl # We need awk for the "check" target. The system "awk" is bad on # some platforms. AC_REQUIRE([AC_PROG_AWK])dnl @@ -1353,35 +1346,28 @@ [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], - [_AM_DEPENDENCIES([CC])], - [m4_define([AC_PROG_CC], - m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl + [_AM_DEPENDENCIES(CC)], + [define([AC_PROG_CC], + defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], - [_AM_DEPENDENCIES([CXX])], - [m4_define([AC_PROG_CXX], - m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl + [_AM_DEPENDENCIES(CXX)], + [define([AC_PROG_CXX], + defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], - [_AM_DEPENDENCIES([OBJC])], - [m4_define([AC_PROG_OBJC], - m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl -dnl Support for Objective C++ was only introduced in Autoconf 2.65, -dnl but we still cater to Autoconf 2.62. -m4_ifdef([AC_PROG_OBJCXX], -[AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], - [_AM_DEPENDENCIES([OBJCXX])], - [m4_define([AC_PROG_OBJCXX], - m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])])dnl + [_AM_DEPENDENCIES(OBJC)], + [define([AC_PROG_OBJC], + defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl ]) _AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl -dnl The 'parallel-tests' driver may need to know about EXEEXT, so add the -dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro +dnl The `parallel-tests' driver may need to know about EXEEXT, so add the +dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl ]) -dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not +dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], @@ -1409,13 +1395,14 @@ done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2012 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2005, 2008, 2011 Free Software Foundation, +# Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 8 +# serial 1 # AM_PROG_INSTALL_SH # ------------------ @@ -1430,9 +1417,9 @@ install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi -AC_SUBST([install_sh])]) +AC_SUBST(install_sh)]) -# Copyright (C) 2003-2012 Free Software Foundation, Inc. +# Copyright (C) 2003, 2005 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1456,19 +1443,20 @@ # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2012 Free Software Foundation, Inc. +# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008, +# 2011 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 7 +# serial 5 # AM_MAINTAINER_MODE([DEFAULT-MODE]) # ---------------------------------- # Control maintainer-specific portions of Makefiles. -# Default is to disable them, unless 'enable' is passed literally. -# For symmetry, 'disable' may be passed as well. Anyway, the user +# Default is to disable them, unless `enable' is passed literally. +# For symmetry, `disable' may be passed as well. Anyway, the user # can override the default with the --enable/--disable switch. AC_DEFUN([AM_MAINTAINER_MODE], [m4_case(m4_default([$1], [disable]), @@ -1479,11 +1467,10 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) dnl maintainer-mode's default is 'disable' unless 'enable' is passed AC_ARG_ENABLE([maintainer-mode], - [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode], - am_maintainer_other[ make rules and dependencies not useful - (and sometimes confusing) to the casual installer])], - [USE_MAINTAINER_MODE=$enableval], - [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) +[ --][am_maintainer_other][-maintainer-mode am_maintainer_other make rules and dependencies not useful + (and sometimes confusing) to the casual installer], + [USE_MAINTAINER_MODE=$enableval], + [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) AC_MSG_RESULT([$USE_MAINTAINER_MODE]) AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) MAINT=$MAINTAINER_MODE_TRUE @@ -1495,13 +1482,13 @@ # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2012 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 5 +# serial 4 # AM_MAKE_INCLUDE() # ----------------- @@ -1520,7 +1507,7 @@ _am_result=none # First try GNU make style include. echo "include confinc" > confmf -# Ignore all kinds of additional output from 'make'. +# Ignore all kinds of additional output from `make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include @@ -1545,7 +1532,8 @@ rm -f confinc confmf ]) -# Copyright (C) 1999-2012 Free Software Foundation, Inc. +# Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1581,13 +1569,14 @@ # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2012 Free Software Foundation, Inc. +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 7 +# serial 6 # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ @@ -1617,19 +1606,49 @@ am_missing_run="$MISSING --run " else am_missing_run= - AC_MSG_WARN(['missing' script is too old or missing]) + AC_MSG_WARN([`missing' script is too old or missing]) fi ]) -# Helper functions for option handling. -*- Autoconf -*- - -# Copyright (C) 2001-2012 Free Software Foundation, Inc. +# Copyright (C) 2003, 2004, 2005, 2006, 2011 Free Software Foundation, +# Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 6 +# serial 1 + +# AM_PROG_MKDIR_P +# --------------- +# Check for `mkdir -p'. +AC_DEFUN([AM_PROG_MKDIR_P], +[AC_PREREQ([2.60])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, +dnl while keeping a definition of mkdir_p for backward compatibility. +dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. +dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of +dnl Makefile.ins that do not define MKDIR_P, so we do our own +dnl adjustment using top_builddir (which is defined more often than +dnl MKDIR_P). +AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl +case $mkdir_p in + [[\\/$]]* | ?:[[\\/]]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac +]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 Free Software +# Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 5 # _AM_MANGLE_OPTION(NAME) # ----------------------- @@ -1640,7 +1659,7 @@ # -------------------- # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], -[m4_define(_AM_MANGLE_OPTION([$1]), [1])]) +[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) # _AM_SET_OPTIONS(OPTIONS) # ------------------------ @@ -1656,18 +1675,22 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2012 Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 +# Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 9 +# serial 5 # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -1678,40 +1701,32 @@ esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) - AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; + AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; esac -# Do 'set' in a subshell so we don't clobber the current shell's +# Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - am_has_slept=no - for am_try in 1 2; do - echo "timestamp, slept: $am_has_slept" > conftest.file - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$[*]" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - if test "$[*]" != "X $srcdir/configure conftest.file" \ - && test "$[*]" != "X conftest.file $srcdir/configure"; then + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken - alias in your environment]) - fi - if test "$[2]" = conftest.file || test $am_try -eq 2; then - break - fi - # Just in case. - sleep 1 - am_has_slept=yes - done + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + test "$[2]" = conftest.file ) then @@ -1721,55 +1736,39 @@ AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi -AC_MSG_RESULT([yes]) -# If we didn't sleep, we still need to ensure time stamps of config.status and -# generated files are strictly newer. -am_sleep_pid= -if grep 'slept: no' conftest.file >/dev/null 2>&1; then - ( sleep 1 ) & - am_sleep_pid=$! -fi -AC_CONFIG_COMMANDS_PRE( - [AC_MSG_CHECKING([that generated files are newer than configure]) - if test -n "$am_sleep_pid"; then - # Hide warnings about reused PIDs. - wait $am_sleep_pid 2>/dev/null - fi - AC_MSG_RESULT([done])]) -rm -f conftest.file -]) +AC_MSG_RESULT(yes)]) -# Copyright (C) 2001-2012 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 2 +# serial 1 # AM_PROG_INSTALL_STRIP # --------------------- -# One issue with vendor 'install' (even GNU) is that you can't +# One issue with vendor `install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we -# always use install-sh in "make install-strip", and initialize +# always use install-sh in `make install-strip', and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl -# Installed binaries are usually stripped using 'strip' when the user -# run "make install-strip". However 'strip' might not be the right +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right # tool to use in cross-compilation environments, therefore Automake -# will honor the 'STRIP' environment variable to overrule this program. -dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. +# will honor the `STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be `maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2012 Free Software Foundation, Inc. +# Copyright (C) 2006, 2008, 2010 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1790,18 +1789,18 @@ # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2012 Free Software Foundation, Inc. +# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 3 +# serial 2 # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. -# FORMAT should be one of 'v7', 'ustar', or 'pax'. +# FORMAT should be one of `v7', `ustar', or `pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory @@ -1824,7 +1823,7 @@ _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' _am_tools=${am_cv_prog_tar_$1-$_am_tools} # Do not fold the above two line into one, because Tru64 sh and -# Solaris sh will not grok spaces in the rhs of '-'. +# Solaris sh will not grok spaces in the rhs of `-'. for _am_tool in $_am_tools do case $_am_tool in diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/build-ios.sh --- a/Modules/_ctypes/libffi/build-ios.sh Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -#!/bin/sh - -PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/ -PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/ -SDK_IOS_VERSION="4.2" -MIN_IOS_VERSION="3.0" -OUTPUT_DIR="universal-ios" - -build_target () { - local platform=$1 - local sdk=$2 - local arch=$3 - local triple=$4 - local builddir=$5 - - mkdir -p "${builddir}" - pushd "${builddir}" - export CC="${platform}"/Developer/usr/bin/gcc-4.2 - export CFLAGS="-arch ${arch} -isysroot ${sdk} -miphoneos-version-min=${MIN_IOS_VERSION}" - ../configure --host=${triple} && make - popd -} - -# Build all targets -build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios -build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios -build_target "${PLATFORM_IOS_SIM}" "${PLATFORM_IOS_SIM}/Developer/SDKs/iPhoneSimulator${SDK_IOS_VERSION}.sdk/" i386 i386-apple-darwin10 i386-ios-sim - -# Create universal output directories -mkdir -p "${OUTPUT_DIR}" -mkdir -p "${OUTPUT_DIR}/include" -mkdir -p "${OUTPUT_DIR}/include/armv6" -mkdir -p "${OUTPUT_DIR}/include/armv7" -mkdir -p "${OUTPUT_DIR}/include/i386" - -# Create the universal binary -lipo -create armv6-ios/.libs/libffi.a armv7-ios/.libs/libffi.a i386-ios-sim/.libs/libffi.a -output "${OUTPUT_DIR}/libffi.a" - -# Copy in the headers -copy_headers () { - local src=$1 - local dest=$2 - - # Fix non-relative header reference - sed 's//"ffitarget.h"/' < "${src}/include/ffi.h" > "${dest}/ffi.h" - cp "${src}/include/ffitarget.h" "${dest}" -} - -copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6" -copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7" -copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386" - -# Create top-level header -( -cat << EOF -#ifdef __arm__ - #include - #ifdef _ARM_ARCH_6 - #include "include/armv6/ffi.h" - #elif _ARM_ARCH_7 - #include "include/armv7/ffi.h" - #endif -#elif defined(__i386__) - #include "include/i386/ffi.h" -#endif -EOF -) > "${OUTPUT_DIR}/ffi.h" diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/config.guess --- a/Modules/_ctypes/libffi/config.guess Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/config.guess Fri Feb 01 23:12:09 2013 +0100 @@ -2,13 +2,13 @@ # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -# 2011, 2012, 2013 Free Software Foundation, Inc. +# 2011 Free Software Foundation, Inc. -timestamp='2012-12-29' +timestamp='2011-06-03' # 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 -# the Free Software Foundation; either version 3 of the License, or +# 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 @@ -17,22 +17,26 @@ # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, see . +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, 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. This Exception is an additional permission under section 7 -# of the GNU General Public License, version 3 ("GPLv3"). +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner. Please send patches (context +# diff format) to and include a ChangeLog +# entry. # -# Originally written by Per Bothner. +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. # # 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 -# -# Please send patches with a ChangeLog entry to config-patches@gnu.org. - me=`echo "$0" | sed -e 's,.*/,,'` @@ -53,8 +57,8 @@ Originally written by Per Bothner. Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Free Software Foundation, Inc. +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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." @@ -141,7 +145,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward @@ -198,10 +202,6 @@ # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" exit ;; - *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} - exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} @@ -304,7 +304,7 @@ arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit ;; - arm*:riscos:*:*|arm*:RISCOS:*:*) + arm:riscos:*:*|arm:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) @@ -792,26 +792,21 @@ echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) - UNAME_PROCESSOR=`/usr/bin/uname -p` - case ${UNAME_PROCESSOR} in + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; amd64) echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; *) - echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; - *:MINGW64*:*) - echo ${UNAME_MACHINE}-pc-mingw64 - exit ;; *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; - i*:MSYS*:*) - echo ${UNAME_MACHINE}-pc-msys - exit ;; i*:windows32*:*) # uname -m includes "-pc" on this system. echo ${UNAME_MACHINE}-mingw32 @@ -866,13 +861,6 @@ i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; - aarch64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - aarch64_be:Linux:*:*) - UNAME_MACHINE=aarch64_be - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -907,16 +895,13 @@ echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; cris:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-gnu + echo cris-axis-linux-gnu exit ;; crisv32:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-gnu + echo crisv32-axis-linux-gnu exit ;; frv:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - hexagon:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo frv-unknown-linux-gnu exit ;; i*86:Linux:*:*) LIBC=gnu @@ -958,7 +943,7 @@ test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; or32:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo or32-unknown-linux-gnu exit ;; padre:Linux:*:*) echo sparc-unknown-linux-gnu @@ -999,7 +984,7 @@ echo ${UNAME_MACHINE}-dec-linux-gnu exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo x86_64-unknown-linux-gnu exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu @@ -1206,9 +1191,6 @@ BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; - x86_64:Haiku:*:*) - echo x86_64-unknown-haiku - exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; @@ -1264,7 +1246,7 @@ NEO-?:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk${UNAME_RELEASE} exit ;; - NSE-*:NONSTOP_KERNEL:*:*) + NSE-?:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; NSR-?:NONSTOP_KERNEL:*:*) @@ -1333,11 +1315,11 @@ i*86:AROS:*:*) echo ${UNAME_MACHINE}-pc-aros exit ;; - x86_64:VMkernel:*:*) - echo ${UNAME_MACHINE}-unknown-esx - exit ;; esac +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + eval $set_cc_for_build cat >$dummy.c <. +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, 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. This Exception is an additional permission under section 7 -# of the GNU General Public License, version 3 ("GPLv3"). +# the same distribution terms that you use for the rest of that program. -# Please send patches with a ChangeLog entry to config-patches@gnu.org. +# Please send patches to . Submit a context +# diff and a properly formatted GNU ChangeLog entry. # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. @@ -71,8 +76,8 @@ GNU config.sub ($timestamp) Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Free Software Foundation, Inc. +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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." @@ -120,17 +125,13 @@ maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ - linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ + linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | \ kopensolaris*-gnu* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; - android-linux) - os=-linux-android - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown - ;; *) basic_machine=`echo $1 | sed 's/-[^-]*$//'` if [ $basic_machine != $1 ] @@ -153,7 +154,7 @@ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray | -microblaze*) + -apple | -axis | -knuth | -cray | -microblaze) os= basic_machine=$1 ;; @@ -222,12 +223,6 @@ -isc*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; - -lynx*178) - os=-lynxos178 - ;; - -lynx*5) - os=-lynxos5 - ;; -lynx*) os=-lynxos ;; @@ -252,14 +247,11 @@ # Some are omitted here because they have special meanings below. 1750a | 580 \ | a29k \ - | aarch64 | aarch64_be \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ - | arc \ - | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ - | avr | avr32 \ - | be32 | be64 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | be32 | be64 \ | bfin \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ @@ -272,7 +264,7 @@ | le32 | le64 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ + | maxq | mb | microblaze | mcore | mep | metag \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -327,7 +319,8 @@ c6x) basic_machine=tic6x-unknown ;; - m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip) + m6811 | m68hc11 | m6812 | m68hc12 | picochip) + # Motorola 68HC11/12. basic_machine=$basic_machine-unknown os=-none ;; @@ -340,10 +333,7 @@ strongarm | thumb | xscale) basic_machine=arm-unknown ;; - xgate) - basic_machine=$basic_machine-unknown - os=-none - ;; + xscaleeb) basic_machine=armeb-unknown ;; @@ -366,7 +356,6 @@ # Recognize the basic CPU types with company name. 580-* \ | a29k-* \ - | aarch64-* | aarch64_be-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ @@ -388,8 +377,7 @@ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ - | microblaze-* | microblazeel-* \ + | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ @@ -731,6 +719,7 @@ i370-ibm* | ibm*) basic_machine=i370-ibm ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 @@ -788,13 +777,9 @@ basic_machine=ns32k-utek os=-sysv ;; - microblaze*) + microblaze) basic_machine=microblaze-xilinx ;; - mingw64) - basic_machine=x86_64-pc - os=-mingw64 - ;; mingw32) basic_machine=i386-pc os=-mingw32 @@ -831,10 +816,6 @@ ms1-*) basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; - msys) - basic_machine=i386-pc - os=-msys - ;; mvs) basic_machine=i370-ibm os=-mvs @@ -1023,11 +1004,7 @@ basic_machine=i586-unknown os=-pw32 ;; - rdos | rdos64) - basic_machine=x86_64-pc - os=-rdos - ;; - rdos32) + rdos) basic_machine=i386-pc os=-rdos ;; @@ -1360,15 +1337,15 @@ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -bitrig* | -openbsd* | -solidbsd* \ + | -openbsd* | -solidbsd* \ | -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* \ - | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ - | -linux-newlib* | -linux-musl* | -linux-uclibc* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-android* \ + | -linux-newlib* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ @@ -1551,9 +1528,6 @@ c4x-* | tic4x-*) os=-coff ;; - hexagon-*) - os=-elf - ;; tic54x-*) os=-coff ;; @@ -1581,6 +1555,9 @@ ;; m68000-sun) os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 ;; m68*-cisco) os=-aout diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/configure --- a/Modules/_ctypes/libffi/configure Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/configure Fri Feb 01 23:12:09 2013 +0100 @@ -1,11 +1,13 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for libffi 3.0.13. +# Generated by GNU Autoconf 2.68 for libffi 3.0.11. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -134,31 +136,6 @@ # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -192,8 +169,7 @@ else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -246,25 +222,21 @@ if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -367,14 +339,6 @@ } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -496,10 +460,6 @@ chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -534,16 +494,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' - fi -else - as_ln_s='cp -pR' + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -555,8 +515,28 @@ as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -590,8 +570,8 @@ # Identity of this package. PACKAGE_NAME='libffi' PACKAGE_TARNAME='libffi' -PACKAGE_VERSION='3.0.13' -PACKAGE_STRING='libffi 3.0.13' +PACKAGE_VERSION='3.0.11' +PACKAGE_STRING='libffi 3.0.11' PACKAGE_BUGREPORT='http://github.com/atgreen/libffi/issues' PACKAGE_URL='' @@ -647,10 +627,6 @@ sys_symbol_underscore HAVE_LONG_DOUBLE ALLOCA -XTENSA_FALSE -XTENSA_TRUE -TILE_FALSE -TILE_TRUE PA64_HPUX_FALSE PA64_HPUX_TRUE PA_HPUX_FALSE @@ -673,8 +649,6 @@ AVR32_TRUE ARM_FALSE ARM_TRUE -AARCH64_FALSE -AARCH64_TRUE POWERPC_FREEBSD_FALSE POWERPC_FREEBSD_TRUE POWERPC_DARWIN_FALSE @@ -685,10 +659,6 @@ POWERPC_TRUE MOXIE_FALSE MOXIE_TRUE -METAG_FALSE -METAG_TRUE -MICROBLAZE_FALSE -MICROBLAZE_TRUE M68K_FALSE M68K_TRUE M32R_FALSE @@ -709,8 +679,6 @@ X86_TRUE SPARC_FALSE SPARC_TRUE -BFIN_FALSE -BFIN_TRUE MIPS_FALSE MIPS_TRUE AM_LTLDFLAGS @@ -854,7 +822,6 @@ enable_portable_binary with_gcc_arch enable_maintainer_mode -enable_pax_emutramp enable_debug enable_structs enable_raw_api @@ -1322,6 +1289,8 @@ if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1407,7 +1376,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libffi 3.0.13 to adapt to many kinds of systems. +\`configure' configures libffi 3.0.11 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1478,7 +1447,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libffi 3.0.13:";; + short | recursive ) echo "Configuration of libffi 3.0.11:";; esac cat <<\_ACEOF @@ -1488,10 +1457,8 @@ --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-builddir disable automatic build in subdir of sources - --enable-dependency-tracking - do not reject slow dependency extractors - --disable-dependency-tracking - speeds up one-time build + --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors --enable-shared[=PKGS] build shared libraries [default=yes] --enable-static[=PKGS] build static libraries [default=yes] --enable-fast-install[=PKGS] @@ -1500,10 +1467,8 @@ --enable-portable-binary disable compiler optimizations that would produce unportable binaries - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer - --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC + --enable-maintainer-mode enable make rules and dependencies not useful + (and sometimes confusing) to the casual installer --enable-debug debugging mode --disable-structs omit code for struct support --disable-raw-api make the raw api unavailable @@ -1598,10 +1563,10 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libffi configure 3.0.13 -generated by GNU Autoconf 2.69 - -Copyright (C) 2012 Free Software Foundation, Inc. +libffi configure 3.0.11 +generated by GNU Autoconf 2.68 + +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1677,7 +1642,7 @@ test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - test -x conftest$ac_exeext + $as_test_x conftest$ac_exeext }; then : ac_retval=0 else @@ -1873,189 +1838,6 @@ } # ac_fn_c_check_func -# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES -# -------------------------------------------- -# Tries to find the compile-time value of EXPR in a program that includes -# INCLUDES, setting VAR accordingly. Returns whether the value could be -# computed -ac_fn_c_compute_int () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -static int test_array [1 - 2 * !(($2) >= 0)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_lo=0 ac_mid=0 - while :; do - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -static int test_array [1 - 2 * !(($2) <= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_hi=$ac_mid; break -else - as_fn_arith $ac_mid + 1 && ac_lo=$as_val - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -static int test_array [1 - 2 * !(($2) < 0)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_hi=-1 ac_mid=-1 - while :; do - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -static int test_array [1 - 2 * !(($2) >= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_lo=$ac_mid; break -else - as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - ac_lo= ac_hi= -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -int -main () -{ -static int test_array [1 - 2 * !(($2) <= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_hi=$ac_mid -else - as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in #(( -?*) eval "$3=\$ac_lo"; ac_retval=0 ;; -'') ac_retval=1 ;; -esac - else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$4 -static long int longval () { return $2; } -static unsigned long int ulongval () { return $2; } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (($2) < 0) - { - long int i = longval (); - if (i != ($2)) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ($2)) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - echo >>conftest.val; read $3 conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_lo=0 ac_mid=0 + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_hi=$ac_mid; break +else + as_fn_arith $ac_mid + 1 && ac_lo=$as_val + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_hi=-1 ac_mid=-1 + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_lo=$ac_mid; break +else + as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + ac_lo= ac_hi= +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_hi=$ac_mid +else + as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in #(( +?*) eval "$3=\$ac_lo"; ac_retval=0 ;; +'') ac_retval=1 ;; +esac + else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +static long int longval () { return $2; } +static unsigned long int ulongval () { return $2; } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (($2) < 0) + { + long int i = longval (); + if (i != ($2)) + return 1; + fprintf (f, "%ld", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ($2)) + return 1; + fprintf (f, "%lu", i); + } + /* Do not output a trailing newline, as this causes \r\n confusion + on some platforms. */ + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + echo >>conftest.val; read $3 config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libffi $as_me 3.0.13, which was -generated by GNU Autoconf 2.69. Invocation command line was +It was created by libffi $as_me 3.0.11, which was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2776,7 +2736,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ax_enable_builddir_sed="$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 @@ -2803,7 +2763,7 @@ ac_config_commands="$ac_config_commands buildir" -am__api_version='1.12' +am__api_version='1.11' # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or @@ -2842,7 +2802,7 @@ # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -2900,6 +2860,9 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 $as_echo_n "checking whether build environment is sane... " >&6; } +# Just in case +sleep 1 +echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -2910,40 +2873,32 @@ esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) - as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; -esac - -# Do 'set' in a subshell so we don't clobber the current shell's + as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; +esac + +# Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - am_has_slept=no - for am_try in 1 2; do - echo "timestamp, slept: $am_has_slept" > conftest.file - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - if test "$*" != "X $srcdir/configure conftest.file" \ - && test "$*" != "X conftest.file $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - as_fn_error $? "ls -t appears to fail. Make sure there is not a broken - alias in your environment" "$LINENO" 5 - fi - if test "$2" = conftest.file || test $am_try -eq 2; then - break - fi - # Just in case. - sleep 1 - am_has_slept=yes - done + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + rm -f conftest.file + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error $? "ls -t appears to fail. Make sure there is not a broken +alias in your environment" "$LINENO" 5 + fi + test "$2" = conftest.file ) then @@ -2955,16 +2910,6 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } -# If we didn't sleep, we still need to ensure time stamps of config.status and -# generated files are strictly newer. -am_sleep_pid= -if grep 'slept: no' conftest.file >/dev/null 2>&1; then - ( sleep 1 ) & - am_sleep_pid=$! -fi - -rm -f conftest.file - test "$program_prefix" != NONE && program_transform_name="s&^&$program_prefix&;$program_transform_name" # Use a double $ so make ignores it. @@ -2988,8 +2933,8 @@ am_missing_run="$MISSING --run " else am_missing_run= - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 -$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} fi if test x"${install_sh}" != xset; then @@ -3001,10 +2946,10 @@ esac fi -# Installed binaries are usually stripped using 'strip' when the user -# run "make install-strip". However 'strip' might not be the right +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right # tool to use in cross-compilation environments, therefore Automake -# will honor the 'STRIP' environment variable to overrule this program. +# will honor the `STRIP' environment variable to overrule this program. if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. @@ -3023,7 +2968,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3063,7 +3008,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3114,7 +3059,7 @@ test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do - as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ @@ -3143,6 +3088,12 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 $as_echo "$MKDIR_P" >&6; } +mkdir_p="$MKDIR_P" +case $mkdir_p in + [\\/$]* | ?:[\\/]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac + for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. @@ -3161,7 +3112,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3247,7 +3198,7 @@ # Define the identity of the package. PACKAGE='libffi' - VERSION='3.0.13' + VERSION='3.0.11' cat >>confdefs.h <<_ACEOF @@ -3275,12 +3226,6 @@ MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} -# For better backward compatibility. To be removed once Automake 1.9.x -# dies out for good. For more background, see: -# -# -mkdir_p='$(MKDIR_P)' - # We need awk for the "check" target. The system "awk" is bad on # some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used @@ -3326,7 +3271,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3366,7 +3311,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3419,7 +3364,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3460,7 +3405,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -3518,7 +3463,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3562,7 +3507,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -4008,7 +3953,8 @@ /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -4111,7 +4057,7 @@ _am_result=none # First try GNU make style include. echo "include confinc" > confmf -# Ignore all kinds of additional output from 'make'. +# Ignore all kinds of additional output from `make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include @@ -4167,8 +4113,8 @@ # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named 'D' -- because '-MD' means "put the output - # in D". + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're @@ -4203,16 +4149,16 @@ : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with - # Solaris 10 /bin/sh. - echo '/* dummy */' > sub/conftst$i.h + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - # We check with '-c' and '-o' for the sake of the "dashmstdout" + # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly - # handle '-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs. + # handle `-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in @@ -4221,8 +4167,8 @@ test "$am__universal" = false || continue ;; nosideeffect) - # After this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested. + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else @@ -4230,7 +4176,7 @@ fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok '-c -o', but also, the minuso test has + # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} @@ -4308,8 +4254,8 @@ # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named 'D' -- because '-MD' means "put the output - # in D". + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're @@ -4342,16 +4288,16 @@ : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with - # Solaris 10 /bin/sh. - echo '/* dummy */' > sub/conftst$i.h + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - # We check with '-c' and '-o' for the sake of the "dashmstdout" + # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly - # handle '-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs. + # handle `-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in @@ -4360,8 +4306,8 @@ test "$am__universal" = false || continue ;; nosideeffect) - # After this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested. + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else @@ -4369,7 +4315,7 @@ fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok '-c -o', but also, the minuso test has + # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} @@ -4665,7 +4611,7 @@ for ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_SED" || continue + { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in @@ -4741,7 +4687,7 @@ for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_GREP" || continue + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in @@ -4807,7 +4753,7 @@ for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -4874,7 +4820,7 @@ for ac_prog in fgrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_FGREP" || continue + { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue # Check for GNU ac_path_FGREP and select it if it is found. # Check for GNU $ac_path_FGREP case `"$ac_path_FGREP" --version 2>&1` in @@ -5130,7 +5076,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5174,7 +5120,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5363,8 +5309,7 @@ ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` - if test -n "$lt_cv_sys_max_cmd_len" && \ - test undefined != "$lt_cv_sys_max_cmd_len"; then + if test -n "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else @@ -5599,7 +5544,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5639,7 +5584,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OBJDUMP="objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5811,7 +5756,7 @@ lt_cv_deplibs_check_method=pass_all ;; -netbsd*) +netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' else @@ -5945,7 +5890,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5985,7 +5930,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6089,7 +6034,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6133,7 +6078,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_AR="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6258,7 +6203,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6298,7 +6243,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6357,7 +6302,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6397,7 +6342,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6905,14 +6850,7 @@ LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) - case `/usr/bin/file conftest.o` in - *x86-64*) - LD="${LD-ld} -m elf32_x86_64" - ;; - *) - LD="${LD-ld} -m elf_i386" - ;; - esac + LD="${LD-ld} -m elf_i386" ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" @@ -7053,7 +6991,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7093,7 +7031,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7173,7 +7111,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7213,7 +7151,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7265,7 +7203,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7305,7 +7243,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_NMEDIT="nmedit" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7357,7 +7295,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_LIPO="${ac_tool_prefix}lipo" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7397,7 +7335,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_LIPO="lipo" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7449,7 +7387,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OTOOL="${ac_tool_prefix}otool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7489,7 +7427,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OTOOL="otool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7541,7 +7479,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -7581,7 +7519,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OTOOL64="otool64" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -9219,6 +9157,9 @@ openbsd*) with_gnu_ld=no ;; + linux* | k*bsd*-gnu | gnu*) + link_all_deplibs=no + ;; esac ld_shlibs=yes @@ -9440,7 +9381,7 @@ fi ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -9617,6 +9558,7 @@ if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi + link_all_deplibs=no else # not using gcc if test "$host_cpu" = ia64; then @@ -10070,7 +10012,7 @@ link_all_deplibs=yes ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -11083,14 +11025,10 @@ # before this can be enabled. hardcode_into_libs=yes - # Add ABI-specific directories to the system library path. - sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" - # Append ld.so.conf contents to the search path if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` - sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" - + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on @@ -11102,6 +11040,18 @@ dynamic_linker='GNU/Linux ld.so' ;; +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + netbsd*) version_type=sunos need_lib_prefix=no @@ -12074,41 +12024,6 @@ -# Test for 64-bit build. -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5 -$as_echo_n "checking size of size_t... " >&6; } -if ${ac_cv_sizeof_size_t+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default"; then : - -else - if test "$ac_cv_type_size_t" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error 77 "cannot compute sizeof (size_t) -See \`config.log' for more details" "$LINENO" 5; } - else - ac_cv_sizeof_size_t=0 - fi -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5 -$as_echo "$ac_cv_sizeof_size_t" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t -_ACEOF - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler vendor" >&5 $as_echo_n "checking for C compiler vendor... " >&6; } if ${ax_cv_c_compiler_vendor+:} false; then : @@ -12172,7 +12087,7 @@ # Check whether --enable-portable-binary was given. if test "${enable_portable_binary+set}" = set; then : - enableval=$enable_portable_binary; acx_maxopt_portable=$enableval + enableval=$enable_portable_binary; acx_maxopt_portable=$withval else acx_maxopt_portable=no fi @@ -12433,8 +12348,41 @@ CFLAGS="-O3 -fomit-frame-pointer" # -malign-double for x86 systems - # LIBFFI -- DON'T DO THIS - CHANGES ABI - # AX_CHECK_COMPILE_FLAG(-malign-double, CFLAGS="$CFLAGS -malign-double") + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -malign-double" >&5 +$as_echo_n "checking whether C compiler accepts -malign-double... " >&6; } +if ${ax_cv_check_cflags___malign_double+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -malign-double" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ax_cv_check_cflags___malign_double=yes +else + ax_cv_check_cflags___malign_double=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS=$ax_check_save_flags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___malign_double" >&5 +$as_echo "$ax_cv_check_cflags___malign_double" >&6; } +if test x"$ax_cv_check_cflags___malign_double" = xyes; then : + CFLAGS="$CFLAGS -malign-double" +else + : +fi + # -fstrict-aliasing for gcc-2.95+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fstrict-aliasing" >&5 @@ -12538,7 +12486,7 @@ ax_gcc_arch="" if test "$cross_compiling" = no; then case $host_cpu in - i[3456]86*|x86_64*) # use cpuid codes + i[3456]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -12654,24 +12602,18 @@ case $ax_cv_gcc_x86_cpuid_1 in *5[48]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;; *5??:*:*:*) ax_gcc_arch=pentium ;; - *0?6[3456]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; - *0?6a?:*[01]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; - *0?6a?:*[234]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; - *0?6[9de]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;; - *0?6[78b]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; - *0?6f?:*:*:*|*1?66?:*:*:*) ax_gcc_arch="core2 pentium-m pentium3 pentiumpro" ;; - *1?6[7d]?:*:*:*) ax_gcc_arch="penryn core2 pentium-m pentium3 pentiumpro" ;; - *1?6[aef]?:*:*:*|*2?6[5cef]?:*:*:*) ax_gcc_arch="corei7 core2 pentium-m pentium3 pentiumpro" ;; - *1?6c?:*:*:*|*[23]?66?:*:*:*) ax_gcc_arch="atom core2 pentium-m pentium3 pentiumpro" ;; - *2?6[ad]?:*:*:*) ax_gcc_arch="corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; - *0?6??:*:*:*) ax_gcc_arch=pentiumpro ;; - *6??:*:*:*) ax_gcc_arch="core2 pentiumpro" ;; - ?000?f3[347]:*:*:*|?000?f41347:*:*:*|?000?f6?:*:*:*) + *6[3456]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; + *6a?:*[01]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; + *6a?:*[234]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; + *6[9d]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;; + *6[78b]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; + *6??:*:*:*) ax_gcc_arch=pentiumpro ;; + *f3[347]:*:*:*|*f41347:*:*:*) case $host_cpu in - x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;; - *) ax_gcc_arch="prescott pentium4 pentiumpro" ;; - esac ;; - ?000?f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";; + x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;; + *) ax_gcc_arch="prescott pentium4 pentiumpro" ;; + esac ;; + *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";; esac ;; *:68747541:*:*) # AMD case $ax_cv_gcc_x86_cpuid_1 in @@ -12743,13 +12685,10 @@ ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;; *) ax_gcc_arch="athlon-4 athlon k7" ;; esac ;; - ?00??f[4cef8b]?:*:*:*) ax_gcc_arch="athlon64 k8" ;; - ?00??f5?:*:*:*) ax_gcc_arch="opteron k8" ;; - ?00??f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;; - ?00??f??:*:*:*) ax_gcc_arch="k8" ;; - ?05??f??:*:*:*) ax_gcc_arch="btver1 amdfam10 k8" ;; - ?06??f??:*:*:*) ax_gcc_arch="bdver1 amdfam10 k8" ;; - *f??:*:*:*) ax_gcc_arch="amdfam10 k8" ;; + *f[4cef8b]?:*:*:*) ax_gcc_arch="athlon64 k8" ;; + *f5?:*:*:*) ax_gcc_arch="opteron k8" ;; + *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;; + *f??:*:*:*) ax_gcc_arch="k8" ;; esac ;; *:746e6543:*:*) # IDT case $ax_cv_gcc_x86_cpuid_1 in @@ -12787,7 +12726,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_PRTDIAG="$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 @@ -12982,31 +12921,6 @@ fi -# The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro -# compiler. -if test "$ax_cv_c_compiler_vendor" != "sun"; then - if ${CFLAGS+:} false; then : - case " $CFLAGS " in - *" "*) - { { $as_echo "$as_me:${as_lineno-$LINENO}: : CFLAGS already contains "; } >&5 - (: CFLAGS already contains ) 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } - ;; - *) - { { $as_echo "$as_me:${as_lineno-$LINENO}: : CFLAGS=\"\$CFLAGS \""; } >&5 - (: CFLAGS="$CFLAGS ") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } - CFLAGS="$CFLAGS " - ;; - esac -else - CFLAGS="" -fi - ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -13043,7 +12957,6 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cflags_warn_all" >&5 $as_echo "$ac_cv_cflags_warn_all" >&6; } - case ".$ac_cv_cflags_warn_all" in .ok|.ok,*) ;; .|.no|.no,*) ;; @@ -13078,15 +12991,8 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -fi - if test "x$GCC" = "xyes"; then CFLAGS="$CFLAGS -fexceptions" - touch local.exp -else - cat > local.exp <&5 $as_echo_n "checking for ANSI C header files... " >&6; } @@ -14045,20 +13859,23 @@ /* end confdefs.h. */ $ac_includes_default int -find_stack_direction (int *addr, int depth) -{ - int dir, dummy = 0; - if (! addr) - addr = &dummy; - *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; - dir = depth ? find_stack_direction (addr, depth - 1) : 0; - return dir + dummy; -} - -int -main (int argc, char **argv) -{ - return find_stack_direction (0, argc + !argv + 20) < 0; +find_stack_direction () +{ + static char *addr = 0; + auto char dummy; + if (addr == 0) + { + addr = &dummy; + return find_stack_direction (); + } + else + return (&dummy > addr) ? 1 : -1; +} + +int +main () +{ + return find_stack_direction () < 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : @@ -14472,11 +14289,11 @@ # Check if we have .register cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -int -main () -{ asm (".register %g2, #scratch"); +int +main () +{ + ; return 0; } @@ -14505,10 +14322,10 @@ $as_echo_n "(cached) " >&6 else - libffi_cv_as_x86_pcrel=no + libffi_cv_as_x86_pcrel=yes echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s - if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then - libffi_cv_as_x86_pcrel=yes + if $CC $CFLAGS -c conftest.s 2>&1 | $EGREP -i 'illegal|warning' > /dev/null; then + libffi_cv_as_x86_pcrel=no fi fi @@ -14530,11 +14347,11 @@ # Check if we have .ascii cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -int -main () -{ asm (".ascii \\"string\\""); +int +main () +{ + ; return 0; } @@ -14565,11 +14382,11 @@ # Check if we have .string cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -int -main () -{ asm (".string \\"string\\""); +int +main () +{ + ; return 0; } @@ -14591,17 +14408,6 @@ fi fi -# On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. -# Check whether --enable-pax_emutramp was given. -if test "${enable_pax_emutramp+set}" = set; then : - enableval=$enable_pax_emutramp; if test "$enable_pax_emutramp" = "yes"; then - -$as_echo "#define FFI_MMAP_EXEC_EMUTRAMP_PAX 1" >>confdefs.h - - fi -fi - - if test x$TARGET = xX86_WIN64; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _ prefix in compiled symbols" >&5 $as_echo_n "checking for _ prefix in compiled symbols... " >&6; } @@ -14657,6 +14463,7 @@ fi fi + FFI_EXEC_TRAMPOLINE_TABLE=0 case "$target" in *arm*-apple-darwin*) @@ -14665,7 +14472,7 @@ $as_echo "#define FFI_EXEC_TRAMPOLINE_TABLE 1" >>confdefs.h ;; - *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*) + *-apple-darwin1[10]* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*) $as_echo "#define FFI_MMAP_EXEC_WRIT 1" >>confdefs.h @@ -14713,12 +14520,11 @@ libffi_cv_ro_eh_frame=no echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c - if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then - objdump -h conftest.o > conftest.dump 2>&1 - libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1` - libffi_test_line=`expr $libffi_eh_frame_line + 1`p - sed -n $libffi_test_line conftest.dump > conftest.line - if grep READONLY conftest.line > /dev/null; then + if $CC $CFLAGS -S -fpic -fexceptions -o conftest.s conftest.c > /dev/null 2>&1; then + if grep '.section.*eh_frame.*"a"' conftest.s > /dev/null; then + libffi_cv_ro_eh_frame=yes + elif grep '.section.*eh_frame.*#alloc' conftest.c \ + | grep -v '#write' > /dev/null; then libffi_cv_ro_eh_frame=yes fi fi @@ -14804,14 +14610,6 @@ fi fi - if test "$enable_debug" = "yes"; then - FFI_DEBUG_TRUE= - FFI_DEBUG_FALSE='#' -else - FFI_DEBUG_TRUE='#' - FFI_DEBUG_FALSE= -fi - # Check whether --enable-raw-api was given. if test "${enable_raw_api+set}" = set; then : @@ -14835,7 +14633,7 @@ # These variables are only ever used when we cross-build to X86_WIN32. # And we only support this with GCC, so... -if test "x$GCC" = "xyes"; then +if test x"$GCC" != x"no"; then if test -n "$with_cross_host" && test x"$with_cross_host" != x"no"; then toolexecdir='$(exec_prefix)/$(target_alias)' @@ -14847,13 +14645,17 @@ multi_os_directory=`$CC -print-multi-os-directory` case $multi_os_directory in .) ;; # Avoid trailing /. - ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;; - esac - -else - toolexeclibdir='$(libdir)' -fi - + *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;; + esac + + +fi + +if test "${multilib}" = "yes"; then + multilib_arg="--enable-multilib" +else + multilib_arg= +fi ac_config_commands="$ac_config_commands include" @@ -14981,14 +14783,6 @@ LTLIBOBJS=$ac_ltlibobjs -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 -$as_echo_n "checking that generated files are newer than configure... " >&6; } - if test -n "$am_sleep_pid"; then - # Hide warnings about reused PIDs. - wait $am_sleep_pid 2>/dev/null - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 -$as_echo "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' @@ -15021,10 +14815,6 @@ as_fn_error $? "conditional \"MIPS\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${BFIN_TRUE}" && test -z "${BFIN_FALSE}"; then - as_fn_error $? "conditional \"BFIN\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi if test -z "${SPARC_TRUE}" && test -z "${SPARC_FALSE}"; then as_fn_error $? "conditional \"SPARC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 @@ -15065,14 +14855,6 @@ as_fn_error $? "conditional \"M68K\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${MICROBLAZE_TRUE}" && test -z "${MICROBLAZE_FALSE}"; then - as_fn_error $? "conditional \"MICROBLAZE\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${METAG_TRUE}" && test -z "${METAG_FALSE}"; then - as_fn_error $? "conditional \"METAG\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi if test -z "${MOXIE_TRUE}" && test -z "${MOXIE_FALSE}"; then as_fn_error $? "conditional \"MOXIE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 @@ -15093,10 +14875,6 @@ as_fn_error $? "conditional \"POWERPC_FREEBSD\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${AARCH64_TRUE}" && test -z "${AARCH64_FALSE}"; then - as_fn_error $? "conditional \"AARCH64\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi if test -z "${ARM_TRUE}" && test -z "${ARM_FALSE}"; then as_fn_error $? "conditional \"ARM\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 @@ -15141,14 +14919,6 @@ as_fn_error $? "conditional \"PA64_HPUX\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${TILE_TRUE}" && test -z "${TILE_FALSE}"; then - as_fn_error $? "conditional \"TILE\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi -if test -z "${XTENSA_TRUE}" && test -z "${XTENSA_FALSE}"; then - as_fn_error $? "conditional \"XTENSA\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi if test -z "${FFI_EXEC_TRAMPOLINE_TABLE_TRUE}" && test -z "${FFI_EXEC_TRAMPOLINE_TABLE_FALSE}"; then as_fn_error $? "conditional \"FFI_EXEC_TRAMPOLINE_TABLE\" was never defined. @@ -15158,10 +14928,6 @@ as_fn_error $? "conditional \"FFI_DEBUG\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${FFI_DEBUG_TRUE}" && test -z "${FFI_DEBUG_FALSE}"; then - as_fn_error $? "conditional \"FFI_DEBUG\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 @@ -15460,16 +15226,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' - fi -else - as_ln_s='cp -pR' + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -15529,16 +15295,28 @@ as_mkdir_p=false fi - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -15559,8 +15337,8 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libffi $as_me 3.0.13, which was -generated by GNU Autoconf 2.69. Invocation command line was +This file was extended by libffi $as_me 3.0.11, which was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -15629,11 +15407,11 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -libffi config.status 3.0.13 -configured by $0, generated by GNU Autoconf 2.69, +libffi config.status 3.0.11 +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -15724,7 +15502,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' @@ -16844,7 +16622,7 @@ # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named 'Makefile.in', but + # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. @@ -16878,19 +16656,21 @@ continue fi # Extract the definition of DEPDIR, am__include, and am__quote - # from the Makefile without running 'make'. + # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`$as_dirname -- "$file" || diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/configure.ac --- a/Modules/_ctypes/libffi/configure.ac Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/configure.ac Fri Feb 01 23:12:09 2013 +0100 @@ -1,11 +1,11 @@ dnl Process this with autoconf to create configure # -# file from libffi - slightly patched for Python's ctypes +# file from libffi - slightly patched for ctypes # AC_PREREQ(2.68) -AC_INIT([libffi], [3.0.13], [http://github.com/atgreen/libffi/issues]) +AC_INIT([libffi], [3.0.11], [http://github.com/atgreen/libffi/issues]) AC_CONFIG_HEADERS([fficonfig.h]) AC_CANONICAL_SYSTEM @@ -30,7 +30,7 @@ AC_PROG_CC CFLAGS=$save_CFLAGS m4_undefine([_AC_ARG_VAR_PRECIOUS]) -m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) +m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) AC_SUBST(CFLAGS) @@ -39,24 +39,10 @@ AC_PROG_LIBTOOL AC_CONFIG_MACRO_DIR([m4]) -# Test for 64-bit build. -AC_CHECK_SIZEOF([size_t]) - -AX_COMPILER_VENDOR AX_CC_MAXOPT -# The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro -# compiler. -if test "$ax_cv_c_compiler_vendor" != "sun"; then - AX_CFLAGS_WARN_ALL -fi - +AX_CFLAGS_WARN_ALL if test "x$GCC" = "xyes"; then CFLAGS="$CFLAGS -fexceptions" - touch local.exp -else - cat > local.exp < /dev/null]) -AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN) AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC) AM_CONDITIONAL(X86, test x$TARGET = xX86) AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD) @@ -288,14 +229,11 @@ AM_CONDITIONAL(IA64, test x$TARGET = xIA64) AM_CONDITIONAL(M32R, test x$TARGET = xM32R) AM_CONDITIONAL(M68K, test x$TARGET = xM68K) -AM_CONDITIONAL(MICROBLAZE, test x$TARGET = xMICROBLAZE) -AM_CONDITIONAL(METAG, test x$TARGET = xMETAG) AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE) AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC) AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX) AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN) AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD) -AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64) AM_CONDITIONAL(ARM, test x$TARGET = xARM) AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32) AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS) @@ -307,8 +245,6 @@ AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX) AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX) AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX) -AM_CONDITIONAL(TILE, test x$TARGET = xTILE) -AM_CONDITIONAL(XTENSA, test x$TARGET = xXTENSA) AC_HEADER_STDC AC_CHECK_FUNCS(memcpy) @@ -354,7 +290,7 @@ libffi_cv_as_register_pseudo_op, [ libffi_cv_as_register_pseudo_op=unknown # Check if we have .register - AC_TRY_COMPILE(,[asm (".register %g2, #scratch");], + AC_TRY_COMPILE([asm (".register %g2, #scratch");],, [libffi_cv_as_register_pseudo_op=yes], [libffi_cv_as_register_pseudo_op=no]) ]) @@ -367,10 +303,10 @@ if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then AC_CACHE_CHECK([assembler supports pc related relocs], libffi_cv_as_x86_pcrel, [ - libffi_cv_as_x86_pcrel=no + libffi_cv_as_x86_pcrel=yes echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s - if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then - libffi_cv_as_x86_pcrel=yes + if $CC $CFLAGS -c conftest.s 2>&1 | $EGREP -i 'illegal|warning' > /dev/null; then + libffi_cv_as_x86_pcrel=no fi ]) if test "x$libffi_cv_as_x86_pcrel" = xyes; then @@ -382,7 +318,7 @@ libffi_cv_as_ascii_pseudo_op, [ libffi_cv_as_ascii_pseudo_op=unknown # Check if we have .ascii - AC_TRY_COMPILE(,[asm (".ascii \\"string\\"");], + AC_TRY_COMPILE([asm (".ascii \\"string\\"");],, [libffi_cv_as_ascii_pseudo_op=yes], [libffi_cv_as_ascii_pseudo_op=no]) ]) @@ -395,7 +331,7 @@ libffi_cv_as_string_pseudo_op, [ libffi_cv_as_string_pseudo_op=unknown # Check if we have .string - AC_TRY_COMPILE(,[asm (".string \\"string\\"");], + AC_TRY_COMPILE([asm (".string \\"string\\"");],, [libffi_cv_as_string_pseudo_op=yes], [libffi_cv_as_string_pseudo_op=no]) ]) @@ -405,14 +341,6 @@ fi fi -# On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. -AC_ARG_ENABLE(pax_emutramp, - [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC], - if test "$enable_pax_emutramp" = "yes"; then - AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1, - [Define this if you want to enable pax emulated trampolines]) - fi) - if test x$TARGET = xX86_WIN64; then LT_SYS_SYMBOL_USCORE if test "x$sys_symbol_underscore" = xyes; then @@ -420,6 +348,7 @@ fi fi + FFI_EXEC_TRAMPOLINE_TABLE=0 case "$target" in *arm*-apple-darwin*) @@ -428,7 +357,7 @@ [Cannot use PROT_EXEC on this target, so, we revert to alternative means]) ;; - *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*) + *-apple-darwin1[[10]]* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*) AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1, [Cannot use malloc on this target, so, we revert to alternative means]) @@ -457,12 +386,11 @@ libffi_cv_ro_eh_frame, [ libffi_cv_ro_eh_frame=no echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c - if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then - objdump -h conftest.o > conftest.dump 2>&1 - libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1` - libffi_test_line=`expr $libffi_eh_frame_line + 1`p - sed -n $libffi_test_line conftest.dump > conftest.line - if grep READONLY conftest.line > /dev/null; then + if $CC $CFLAGS -S -fpic -fexceptions -o conftest.s conftest.c > /dev/null 2>&1; then + if grep '.section.*eh_frame.*"a"' conftest.s > /dev/null; then + libffi_cv_ro_eh_frame=yes + elif grep '.section.*eh_frame.*#alloc' conftest.c \ + | grep -v '#write' > /dev/null; then libffi_cv_ro_eh_frame=yes fi fi @@ -528,7 +456,6 @@ if test "$enable_structs" = "no"; then AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.]) fi) -AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes") AC_ARG_ENABLE(raw-api, [ --disable-raw-api make the raw api unavailable], @@ -544,7 +471,7 @@ # These variables are only ever used when we cross-build to X86_WIN32. # And we only support this with GCC, so... -if test "x$GCC" = "xyes"; then +if test x"$GCC" != x"no"; then if test -n "$with_cross_host" && test x"$with_cross_host" != x"no"; then toolexecdir='$(exec_prefix)/$(target_alias)' @@ -556,13 +483,17 @@ multi_os_directory=`$CC -print-multi-os-directory` case $multi_os_directory in .) ;; # Avoid trailing /. - ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;; + *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;; esac AC_SUBST(toolexecdir) + AC_SUBST(toolexeclibdir) +fi + +if test "${multilib}" = "yes"; then + multilib_arg="--enable-multilib" else - toolexeclibdir='$(libdir)' + multilib_arg= fi -AC_SUBST(toolexeclibdir) AC_CONFIG_COMMANDS(include, [test -d include || mkdir include]) AC_CONFIG_COMMANDS(src, [ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/doc/libffi.info Binary file Modules/_ctypes/libffi/doc/libffi.info has changed diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/doc/libffi.texi --- a/Modules/_ctypes/libffi/doc/libffi.texi Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/doc/libffi.texi Fri Feb 01 23:12:09 2013 +0100 @@ -360,7 +360,7 @@ new @code{ffi_type} object for it. @tindex ffi_type -@deftp {Data type} ffi_type +@deftp ffi_type The @code{ffi_type} has the following members: @table @code @item size_t size diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/doc/stamp-vti --- a/Modules/_ctypes/libffi/doc/stamp-vti Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/doc/stamp-vti Fri Feb 01 23:12:09 2013 +0100 @@ -1,4 +1,4 @@ -@set UPDATED 16 March 2013 -@set UPDATED-MONTH March 2013 -@set EDITION 3.0.13 -@set VERSION 3.0.13 +@set UPDATED 11 April 2012 +@set UPDATED-MONTH April 2012 +@set EDITION 3.0.11 +@set VERSION 3.0.11 diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/doc/version.texi --- a/Modules/_ctypes/libffi/doc/version.texi Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/doc/version.texi Fri Feb 01 23:12:09 2013 +0100 @@ -1,4 +1,4 @@ -@set UPDATED 16 March 2013 -@set UPDATED-MONTH March 2013 -@set EDITION 3.0.13 -@set VERSION 3.0.13 +@set UPDATED 11 April 2012 +@set UPDATED-MONTH April 2012 +@set EDITION 3.0.11 +@set VERSION 3.0.11 diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/fficonfig.h.in --- a/Modules/_ctypes/libffi/fficonfig.h.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/fficonfig.h.in Fri Feb 01 23:12:09 2013 +0100 @@ -20,9 +20,6 @@ /* Cannot use PROT_EXEC on this target, so, we revert to alternative means */ #undef FFI_EXEC_TRAMPOLINE_TABLE -/* Define this if you want to enable pax emulated trampolines */ -#undef FFI_MMAP_EXEC_EMUTRAMP_PAX - /* Cannot use malloc on this target, so, we revert to alternative means */ #undef FFI_MMAP_EXEC_WRIT diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/fficonfig.py.in --- a/Modules/_ctypes/libffi/fficonfig.py.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/fficonfig.py.in Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,7 @@ 'M32R': ['src/m32r/sysv.S', 'src/m32r/ffi.c'], 'M68K': ['src/m68k/ffi.c', 'src/m68k/sysv.S'], 'POWERPC': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S', 'src/powerpc/linux64.S', 'src/powerpc/linux64_closure.S'], - 'POWERPC_AIX': ['src/powerpc/ffi_darwin.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'], + 'POWERPC_AIX': ['src/powerpc/ffi.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'], 'POWERPC_FREEBSD': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S'], 'ARM': ['src/arm/sysv.S', 'src/arm/ffi.c'], 'LIBFFI_CRIS': ['src/cris/sysv.S', 'src/cris/ffi.c'], diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/include/Makefile.in --- a/Modules/_ctypes/libffi/include/Makefile.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/include/Makefile.in Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.12.2 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2012 Free Software Foundation, Inc. - +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -15,23 +16,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -53,35 +37,18 @@ target_triplet = @target@ subdir = include DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ - $(srcdir)/ffi.h.in + $(srcdir)/ffi.h.in $(srcdir)/ffi_common.h ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/asmcfi.m4 \ - $(top_srcdir)/m4/ax_append_flag.m4 \ - $(top_srcdir)/m4/ax_cc_maxopt.m4 \ - $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ - $(top_srcdir)/m4/ax_check_compile_flag.m4 \ - $(top_srcdir)/m4/ax_compiler_vendor.m4 \ - $(top_srcdir)/m4/ax_configure_args.m4 \ - $(top_srcdir)/m4/ax_enable_builddir.m4 \ - $(top_srcdir)/m4/ax_gcc_archflag.m4 \ - $(top_srcdir)/m4/ax_gcc_x86_cpuid.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/fficonfig.h CONFIG_CLEAN_FILES = ffi.h ffitarget.h -CONFIG_CLEAN_VPATH_FILES = +CONFIG_CLEAN_VPATH_FILES = ffi_common.h SOURCES = DIST_SOURCES = -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -178,7 +145,6 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PRTDIAG = @PRTDIAG@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -199,7 +165,6 @@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ -ax_enable_builddir_sed = @ax_enable_builddir_sed@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ @@ -235,7 +200,6 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ -sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -295,11 +259,8 @@ -rm -rf .libs _libs install-nodist_includesHEADERS: $(nodist_includes_HEADERS) @$(NORMAL_INSTALL) + test -z "$(includesdir)" || $(MKDIR_P) "$(DESTDIR)$(includesdir)" @list='$(nodist_includes_HEADERS)'; test -n "$(includesdir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(includesdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(includesdir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -364,20 +325,6 @@ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscopelist: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS) $(LISP)'; \ - case "$(srcdir)" in \ - [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ - *) sdir=$(subdir)/$(srcdir) ;; \ - esac; \ - for i in $$list; do \ - if test -f "$$i"; then \ - echo "$(subdir)/$$i"; \ - else \ - echo "$$sdir/$$i"; \ - fi; \ - done >> $(top_builddir)/cscope.files - distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags @@ -518,7 +465,7 @@ .MAKE: install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool cscopelist ctags distclean distclean-generic \ + clean-libtool ctags distclean distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/include/ffi_common.h --- a/Modules/_ctypes/libffi/include/ffi_common.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/include/ffi_common.h Fri Feb 01 23:12:09 2013 +0100 @@ -87,7 +87,7 @@ } extended_cif; /* Terse sized type definitions. */ -#if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C) +#if defined(_MSC_VER) || defined(__sgi) typedef unsigned char UINT8; typedef signed char SINT8; typedef unsigned short UINT16; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/libffi.xcodeproj/project.pbxproj --- a/Modules/_ctypes/libffi/libffi.xcodeproj/project.pbxproj Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/libffi.xcodeproj/project.pbxproj Fri Feb 01 23:12:09 2013 +0100 @@ -12,12 +12,17 @@ 6C43CBDE1534F76F00162364 /* trampoline.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBC01534F76F00162364 /* trampoline.S */; }; 6C43CBE61534F76F00162364 /* darwin.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBC91534F76F00162364 /* darwin.S */; }; 6C43CBE81534F76F00162364 /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBCB1534F76F00162364 /* ffi.c */; }; + 6C43CBE91534F76F00162364 /* ffi64.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBCC1534F76F00162364 /* ffi64.c */; }; 6C43CC1F1534F77800162364 /* darwin.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC051534F77800162364 /* darwin.S */; }; 6C43CC201534F77800162364 /* darwin64.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC061534F77800162364 /* darwin64.S */; }; 6C43CC211534F77800162364 /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC071534F77800162364 /* ffi.c */; }; 6C43CC221534F77800162364 /* ffi64.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC081534F77800162364 /* ffi64.c */; }; 6C43CC2F1534F7BE00162364 /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC281534F7BE00162364 /* closures.c */; }; 6C43CC301534F7BE00162364 /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC281534F7BE00162364 /* closures.c */; }; + 6C43CC311534F7BE00162364 /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC291534F7BE00162364 /* debug.c */; }; + 6C43CC321534F7BE00162364 /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC291534F7BE00162364 /* debug.c */; }; + 6C43CC331534F7BE00162364 /* dlmalloc.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2A1534F7BE00162364 /* dlmalloc.c */; }; + 6C43CC341534F7BE00162364 /* dlmalloc.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2A1534F7BE00162364 /* dlmalloc.c */; }; 6C43CC351534F7BE00162364 /* java_raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2B1534F7BE00162364 /* java_raw_api.c */; }; 6C43CC361534F7BE00162364 /* java_raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2B1534F7BE00162364 /* java_raw_api.c */; }; 6C43CC371534F7BE00162364 /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2C1534F7BE00162364 /* prep_cif.c */; }; @@ -56,11 +61,14 @@ 6C43CBC01534F76F00162364 /* trampoline.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = trampoline.S; sourceTree = ""; }; 6C43CBC91534F76F00162364 /* darwin.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin.S; sourceTree = ""; }; 6C43CBCB1534F76F00162364 /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = ""; }; + 6C43CBCC1534F76F00162364 /* ffi64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi64.c; sourceTree = ""; }; 6C43CC051534F77800162364 /* darwin.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin.S; sourceTree = ""; }; 6C43CC061534F77800162364 /* darwin64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin64.S; sourceTree = ""; }; 6C43CC071534F77800162364 /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = ""; }; 6C43CC081534F77800162364 /* ffi64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi64.c; sourceTree = ""; }; 6C43CC281534F7BE00162364 /* closures.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = closures.c; path = src/closures.c; sourceTree = SOURCE_ROOT; }; + 6C43CC291534F7BE00162364 /* debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = debug.c; path = src/debug.c; sourceTree = SOURCE_ROOT; }; + 6C43CC2A1534F7BE00162364 /* dlmalloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = dlmalloc.c; path = src/dlmalloc.c; sourceTree = SOURCE_ROOT; }; 6C43CC2B1534F7BE00162364 /* java_raw_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = java_raw_api.c; path = src/java_raw_api.c; sourceTree = SOURCE_ROOT; }; 6C43CC2C1534F7BE00162364 /* prep_cif.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = prep_cif.c; path = src/prep_cif.c; sourceTree = SOURCE_ROOT; }; 6C43CC2D1534F7BE00162364 /* raw_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = raw_api.c; path = src/raw_api.c; sourceTree = SOURCE_ROOT; }; @@ -141,6 +149,7 @@ children = ( 6C43CBC91534F76F00162364 /* darwin.S */, 6C43CBCB1534F76F00162364 /* ffi.c */, + 6C43CBCC1534F76F00162364 /* ffi64.c */, ); path = x86; sourceTree = ""; @@ -178,6 +187,8 @@ isa = PBXGroup; children = ( 6C43CC281534F7BE00162364 /* closures.c */, + 6C43CC291534F7BE00162364 /* debug.c */, + 6C43CC2A1534F7BE00162364 /* dlmalloc.c */, 6C43CC2B1534F7BE00162364 /* java_raw_api.c */, 6C43CC2C1534F7BE00162364 /* prep_cif.c */, 6C43CC2D1534F7BE00162364 /* raw_api.c */, @@ -401,6 +412,8 @@ 6C43CC211534F77800162364 /* ffi.c in Sources */, 6C43CC221534F77800162364 /* ffi64.c in Sources */, 6C43CC301534F7BE00162364 /* closures.c in Sources */, + 6C43CC321534F7BE00162364 /* debug.c in Sources */, + 6C43CC341534F7BE00162364 /* dlmalloc.c in Sources */, 6C43CC361534F7BE00162364 /* java_raw_api.c in Sources */, 6C43CC381534F7BE00162364 /* prep_cif.c in Sources */, 6C43CC3A1534F7BE00162364 /* raw_api.c in Sources */, @@ -417,7 +430,10 @@ 6C43CBDE1534F76F00162364 /* trampoline.S in Sources */, 6C43CBE61534F76F00162364 /* darwin.S in Sources */, 6C43CBE81534F76F00162364 /* ffi.c in Sources */, + 6C43CBE91534F76F00162364 /* ffi64.c in Sources */, 6C43CC2F1534F7BE00162364 /* closures.c in Sources */, + 6C43CC311534F7BE00162364 /* debug.c in Sources */, + 6C43CC331534F7BE00162364 /* dlmalloc.c in Sources */, 6C43CC351534F7BE00162364 /* java_raw_api.c in Sources */, 6C43CC371534F7BE00162364 /* prep_cif.c in Sources */, 6C43CC391534F7BE00162364 /* raw_api.c in Sources */, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/libtool-ldflags --- a/Modules/_ctypes/libffi/libtool-ldflags Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -#! /bin/sh - -# Script to translate LDFLAGS into a form suitable for use with libtool. - -# Copyright (C) 2005 Free Software Foundation, Inc. -# -# 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 -# 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., 51 Franklin Street, Fifth Floor, Boston, -# MA 02110-1301, USA. - -# Contributed by CodeSourcery, LLC. - -# This script is designed to be used from a Makefile that uses libtool -# to build libraries as follows: -# -# LTLDFLAGS = $(shell libtool-ldflags $(LDFLAGS)) -# -# Then, use (LTLDFLAGS) in place of $(LDFLAGS) in your link line. - -# The output of the script. This string is built up as we process the -# arguments. -result= -prev_arg= - -for arg -do - case $arg in - -f*|--*) - # Libtool does not ascribe any special meaning options - # that begin with -f or with a double-dash. So, it will - # think these options are linker options, and prefix them - # with "-Wl,". Then, the compiler driver will ignore the - # options. So, we prefix these options with -Xcompiler to - # make clear to libtool that they are in fact compiler - # options. - case $prev_arg in - -Xpreprocessor|-Xcompiler|-Xlinker) - # This option is already prefixed; don't prefix it again. - ;; - *) - result="$result -Xcompiler" - ;; - esac - ;; - *) - # We do not want to add -Xcompiler to other options because - # that would prevent libtool itself from recognizing them. - ;; - esac - prev_arg=$arg - - # If $(LDFLAGS) is (say): - # a "b'c d" e - # then the user expects that: - # $(LD) $(LDFLAGS) - # will pass three arguments to $(LD): - # 1) a - # 2) b'c d - # 3) e - # We must ensure, therefore, that the arguments are appropriately - # quoted so that using: - # libtool --mode=link ... $(LTLDFLAGS) - # will result in the same number of arguments being passed to - # libtool. In other words, when this script was invoked, the shell - # removed one level of quoting, present in $(LDFLAGS); we have to put - # it back. - - # Quote any embedded single quotes. - case $arg in - *"'"*) - # The following command creates the script: - # 1s,^X,,;s|'|'"'"'|g - # which removes a leading X, and then quotes and embedded single - # quotes. - sed_script="1s,^X,,;s|'|'\"'\"'|g" - # Add a leading "X" so that if $arg starts with a dash, - # the echo command will not try to interpret the argument - # as a command-line option. - arg="X$arg" - # Generate the quoted string. - quoted_arg=`echo "$arg" | sed -e "$sed_script"` - ;; - *) - quoted_arg=$arg - ;; - esac - # Surround the entire argument with single quotes. - quoted_arg="'"$quoted_arg"'" - - # Add it to the string. - result="$result $quoted_arg" -done - -# Output the string we have built up. -echo "$result" diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/libtool-version --- a/Modules/_ctypes/libffi/libtool-version Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/libtool-version Fri Feb 01 23:12:09 2013 +0100 @@ -26,4 +26,4 @@ # release, then set age to 0. # # CURRENT:REVISION:AGE -6:1:0 +6:0:0 diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/ltmain.sh --- a/Modules/_ctypes/libffi/ltmain.sh Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/ltmain.sh Fri Feb 01 23:12:09 2013 +0100 @@ -70,7 +70,7 @@ # compiler: $LTCC # compiler flags: $LTCFLAGS # linker: $LD (gnu? $with_gnu_ld) -# $progname: (GNU libtool) 2.4.2 +# $progname: (GNU libtool) 2.4.2 Debian-2.4.2-1ubuntu1 # automake: $automake_version # autoconf: $autoconf_version # @@ -80,7 +80,7 @@ PROGRAM=libtool PACKAGE=libtool -VERSION=2.4.2 +VERSION="2.4.2 Debian-2.4.2-1ubuntu1" TIMESTAMP="" package_revision=1.3337 @@ -6124,7 +6124,10 @@ case $pass in dlopen) libs="$dlfiles" ;; dlpreopen) libs="$dlprefiles" ;; - link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + link) + libs="$deplibs %DEPLIBS%" + test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" + ;; esac fi if test "$linkmode,$pass" = "lib,dlpreopen"; then @@ -6444,19 +6447,19 @@ # It is a libtool convenience library, so add in its objects. func_append convenience " $ladir/$objdir/$old_library" func_append old_convenience " $ladir/$objdir/$old_library" + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_preserve_dup_deps ; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done elif test "$linkmode" != prog && test "$linkmode" != lib; then func_fatal_error "\`$lib' is not a convenience library" fi - tmp_libs= - for deplib in $dependency_libs; do - deplibs="$deplib $deplibs" - if $opt_preserve_dup_deps ; then - case "$tmp_libs " in - *" $deplib "*) func_append specialdeplibs " $deplib" ;; - esac - fi - func_append tmp_libs " $deplib" - done continue fi # $pass = conv @@ -7349,6 +7352,9 @@ revision="$number_minor" lt_irix_increment=no ;; + *) + func_fatal_configuration "$modename: unknown library version type \`$version_type'" + ;; esac ;; no) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/m4/ax_cc_maxopt.m4 --- a/Modules/_ctypes/libffi/m4/ax_cc_maxopt.m4 Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/m4/ax_cc_maxopt.m4 Fri Feb 01 23:12:09 2013 +0100 @@ -55,7 +55,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 13 +#serial 12 AC_DEFUN([AX_CC_MAXOPT], [ @@ -64,7 +64,7 @@ AC_REQUIRE([AC_CANONICAL_HOST]) AC_ARG_ENABLE(portable-binary, [AS_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])], - acx_maxopt_portable=$enableval, acx_maxopt_portable=no) + acx_maxopt_portable=$withval, acx_maxopt_portable=no) # Try to determine "good" native compiler flags if none specified via CFLAGS if test "$ac_test_CFLAGS" != "set"; then @@ -141,8 +141,7 @@ CFLAGS="-O3 -fomit-frame-pointer" # -malign-double for x86 systems - # LIBFFI -- DON'T DO THIS - CHANGES ABI - # AX_CHECK_COMPILE_FLAG(-malign-double, CFLAGS="$CFLAGS -malign-double") + AX_CHECK_COMPILE_FLAG(-malign-double, CFLAGS="$CFLAGS -malign-double") # -fstrict-aliasing for gcc-2.95+ AX_CHECK_COMPILE_FLAG(-fstrict-aliasing, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/m4/ax_cflags_warn_all.m4 --- a/Modules/_ctypes/libffi/m4/ax_cflags_warn_all.m4 Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/m4/ax_cflags_warn_all.m4 Fri Feb 01 23:12:09 2013 +0100 @@ -58,7 +58,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 14 +#serial 13 AC_DEFUN([AX_FLAGS_WARN_ALL],[dnl AS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl @@ -84,7 +84,6 @@ FLAGS="$ac_save_[]FLAGS" ]) AS_VAR_POPDEF([FLAGS])dnl -AC_REQUIRE([AX_APPEND_FLAG]) case ".$VAR" in .ok|.ok,*) m4_ifvaln($3,$3) ;; .|.no|.no,*) m4_default($4,[m4_ifval($2,[AX_APPEND_FLAG([$2], [$1])])]) ;; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/m4/ax_gcc_archflag.m4 --- a/Modules/_ctypes/libffi/m4/ax_gcc_archflag.m4 Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/m4/ax_gcc_archflag.m4 Fri Feb 01 23:12:09 2013 +0100 @@ -36,7 +36,6 @@ # # Copyright (c) 2008 Steven G. Johnson # Copyright (c) 2008 Matteo Frigo -# Copyright (c) 2012 Tsukasa Oi # # 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 @@ -64,7 +63,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 11 +#serial 10 AC_DEFUN([AX_GCC_ARCHFLAG], [AC_REQUIRE([AC_PROG_CC]) @@ -85,7 +84,7 @@ ax_gcc_arch="" if test "$cross_compiling" = no; then case $host_cpu in - i[[3456]]86*|x86_64*) # use cpuid codes + i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones AX_GCC_X86_CPUID(0) AX_GCC_X86_CPUID(1) case $ax_cv_gcc_x86_cpuid_0 in @@ -93,24 +92,18 @@ case $ax_cv_gcc_x86_cpuid_1 in *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;; *5??:*:*:*) ax_gcc_arch=pentium ;; - *0?6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; - *0?6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; - *0?6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; - *0?6[[9de]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;; - *0?6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; - *0?6f?:*:*:*|*1?66?:*:*:*) ax_gcc_arch="core2 pentium-m pentium3 pentiumpro" ;; - *1?6[[7d]]?:*:*:*) ax_gcc_arch="penryn core2 pentium-m pentium3 pentiumpro" ;; - *1?6[[aef]]?:*:*:*|*2?6[[5cef]]?:*:*:*) ax_gcc_arch="corei7 core2 pentium-m pentium3 pentiumpro" ;; - *1?6c?:*:*:*|*[[23]]?66?:*:*:*) ax_gcc_arch="atom core2 pentium-m pentium3 pentiumpro" ;; - *2?6[[ad]]?:*:*:*) ax_gcc_arch="corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; - *0?6??:*:*:*) ax_gcc_arch=pentiumpro ;; - *6??:*:*:*) ax_gcc_arch="core2 pentiumpro" ;; - ?000?f3[[347]]:*:*:*|?000?f4[1347]:*:*:*|?000?f6?:*:*:*) + *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; + *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;; + *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; + *6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;; + *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;; + *6??:*:*:*) ax_gcc_arch=pentiumpro ;; + *f3[[347]]:*:*:*|*f4[1347]:*:*:*) case $host_cpu in - x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;; - *) ax_gcc_arch="prescott pentium4 pentiumpro" ;; - esac ;; - ?000?f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";; + x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;; + *) ax_gcc_arch="prescott pentium4 pentiumpro" ;; + esac ;; + *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";; esac ;; *:68747541:*:*) # AMD case $ax_cv_gcc_x86_cpuid_1 in @@ -128,13 +121,10 @@ ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;; *) ax_gcc_arch="athlon-4 athlon k7" ;; esac ;; - ?00??f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;; - ?00??f5?:*:*:*) ax_gcc_arch="opteron k8" ;; - ?00??f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;; - ?00??f??:*:*:*) ax_gcc_arch="k8" ;; - ?05??f??:*:*:*) ax_gcc_arch="btver1 amdfam10 k8" ;; - ?06??f??:*:*:*) ax_gcc_arch="bdver1 amdfam10 k8" ;; - *f??:*:*:*) ax_gcc_arch="amdfam10 k8" ;; + *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;; + *f5?:*:*:*) ax_gcc_arch="opteron k8" ;; + *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;; + *f??:*:*:*) ax_gcc_arch="k8" ;; esac ;; *:746e6543:*:*) # IDT case $ax_cv_gcc_x86_cpuid_1 in diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/m4/libtool.m4 --- a/Modules/_ctypes/libffi/m4/libtool.m4 Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/m4/libtool.m4 Fri Feb 01 23:12:09 2013 +0100 @@ -1324,14 +1324,7 @@ LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) - case `/usr/bin/file conftest.o` in - *x86-64*) - LD="${LD-ld} -m elf32_x86_64" - ;; - *) - LD="${LD-ld} -m elf_i386" - ;; - esac + LD="${LD-ld} -m elf_i386" ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" @@ -1695,8 +1688,7 @@ ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` - if test -n "$lt_cv_sys_max_cmd_len" && \ - test undefined != "$lt_cv_sys_max_cmd_len"; then + if test -n "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else @@ -2677,14 +2669,10 @@ # before this can be enabled. hardcode_into_libs=yes - # Add ABI-specific directories to the system library path. - sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" - # Append ld.so.conf contents to the search path if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` - sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" - + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on @@ -2696,6 +2684,18 @@ dynamic_linker='GNU/Linux ld.so' ;; +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + netbsd*) version_type=sunos need_lib_prefix=no @@ -3301,7 +3301,7 @@ lt_cv_deplibs_check_method=pass_all ;; -netbsd*) +netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else @@ -4113,7 +4113,7 @@ ;; esac ;; - netbsd*) + netbsd* | netbsdelf*-gnu) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -4590,6 +4590,9 @@ ;; esac ;; + linux* | k*bsd*-gnu | gnu*) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; @@ -4652,6 +4655,9 @@ openbsd*) with_gnu_ld=no ;; + linux* | k*bsd*-gnu | gnu*) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes @@ -4873,7 +4879,7 @@ fi ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -5050,6 +5056,7 @@ if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi + _LT_TAGVAR(link_all_deplibs, $1)=no else # not using gcc if test "$host_cpu" = ia64; then @@ -5354,7 +5361,7 @@ _LT_TAGVAR(link_all_deplibs, $1)=yes ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/man/Makefile.in --- a/Modules/_ctypes/libffi/man/Makefile.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/man/Makefile.in Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.12.2 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2012 Free Software Foundation, Inc. - +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,23 +15,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -53,19 +37,7 @@ subdir = man DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/asmcfi.m4 \ - $(top_srcdir)/m4/ax_append_flag.m4 \ - $(top_srcdir)/m4/ax_cc_maxopt.m4 \ - $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ - $(top_srcdir)/m4/ax_check_compile_flag.m4 \ - $(top_srcdir)/m4/ax_compiler_vendor.m4 \ - $(top_srcdir)/m4/ax_configure_args.m4 \ - $(top_srcdir)/m4/ax_enable_builddir.m4 \ - $(top_srcdir)/m4/ax_gcc_archflag.m4 \ - $(top_srcdir)/m4/ax_gcc_x86_cpuid.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -75,11 +47,6 @@ CONFIG_CLEAN_VPATH_FILES = SOURCES = DIST_SOURCES = -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -176,7 +143,6 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PRTDIAG = @PRTDIAG@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -197,7 +163,6 @@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ -ax_enable_builddir_sed = @ax_enable_builddir_sed@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ @@ -233,7 +198,6 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ -sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -289,18 +253,11 @@ -rm -rf .libs _libs install-man3: $(man_MANS) @$(NORMAL_INSTALL) - @list1=''; \ - list2='$(man_MANS)'; \ - test -n "$(man3dir)" \ - && test -n "`echo $$list1$$list2`" \ - || exit 0; \ - echo " $(MKDIR_P) '$(DESTDIR)$(man3dir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(man3dir)" || exit 1; \ - { for i in $$list1; do echo "$$i"; done; \ - if test -n "$$list2"; then \ - for i in $$list2; do echo "$$i"; done \ - | sed -n '/\.3[a-z]*$$/p'; \ - fi; \ + test -z "$(man3dir)" || $(MKDIR_P) "$(DESTDIR)$(man3dir)" + @list=''; test -n "$(man3dir)" || exit 0; \ + { for i in $$list; do echo "$$i"; done; \ + l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ + sed -n '/\.3[a-z]*$$/p'; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ @@ -336,8 +293,6 @@ ctags: CTAGS CTAGS: -cscope cscopelist: - distdir: $(DISTFILES) @list='$(MANS)'; if test -n "$$list"; then \ @@ -346,10 +301,10 @@ if test -f "$$d$$p"; then echo "$$d$$p"; else :; fi; done`; \ if test -n "$$list" && \ grep 'ab help2man is required to generate this page' $$list >/dev/null; then \ - echo "error: found man pages containing the 'missing help2man' replacement text:" >&2; \ + echo "error: found man pages containing the \`missing help2man' replacement text:" >&2; \ grep -l 'ab help2man is required to generate this page' $$list | sed 's/^/ /' >&2; \ echo " to fix them, install help2man, remove and regenerate the man pages;" >&2; \ - echo " typically 'make maintainer-clean' will remove them" >&2; \ + echo " typically \`make maintainer-clean' will remove them" >&2; \ exit 1; \ else :; fi; \ else :; fi diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/man/ffi_prep_cif.3 --- a/Modules/_ctypes/libffi/man/ffi_prep_cif.3 Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/man/ffi_prep_cif.3 Fri Feb 01 23:12:09 2013 +0100 @@ -61,8 +61,10 @@ .Nm FFI_BAD_ABI will be returned. Available ABIs are defined in -.Nm . +.Nm +. .Sh SEE ALSO .Xr ffi 3 , .Xr ffi_call 3 , .Xr ffi_prep_cif_var 3 + diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/aarch64/ffi.c --- a/Modules/_ctypes/libffi/src/aarch64/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1076 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -``Software''), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#include - -#include -#include - -#include - -/* Stack alignment requirement in bytes */ -#define AARCH64_STACK_ALIGN 16 - -#define N_X_ARG_REG 8 -#define N_V_ARG_REG 8 - -#define AARCH64_FFI_WITH_V (1 << AARCH64_FFI_WITH_V_BIT) - -union _d -{ - UINT64 d; - UINT32 s[2]; -}; - -struct call_context -{ - UINT64 x [AARCH64_N_XREG]; - struct - { - union _d d[2]; - } v [AARCH64_N_VREG]; -}; - -static void * -get_x_addr (struct call_context *context, unsigned n) -{ - return &context->x[n]; -} - -static void * -get_s_addr (struct call_context *context, unsigned n) -{ -#if defined __AARCH64EB__ - return &context->v[n].d[1].s[1]; -#else - return &context->v[n].d[0].s[0]; -#endif -} - -static void * -get_d_addr (struct call_context *context, unsigned n) -{ -#if defined __AARCH64EB__ - return &context->v[n].d[1]; -#else - return &context->v[n].d[0]; -#endif -} - -static void * -get_v_addr (struct call_context *context, unsigned n) -{ - return &context->v[n]; -} - -/* Return the memory location at which a basic type would reside - were it to have been stored in register n. */ - -static void * -get_basic_type_addr (unsigned short type, struct call_context *context, - unsigned n) -{ - switch (type) - { - case FFI_TYPE_FLOAT: - return get_s_addr (context, n); - case FFI_TYPE_DOUBLE: - return get_d_addr (context, n); - case FFI_TYPE_LONGDOUBLE: - return get_v_addr (context, n); - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT32: - case FFI_TYPE_INT: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - return get_x_addr (context, n); - default: - FFI_ASSERT (0); - return NULL; - } -} - -/* Return the alignment width for each of the basic types. */ - -static size_t -get_basic_type_alignment (unsigned short type) -{ - switch (type) - { - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - return sizeof (UINT64); - case FFI_TYPE_LONGDOUBLE: - return sizeof (long double); - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_INT: - case FFI_TYPE_SINT32: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - return sizeof (UINT64); - - default: - FFI_ASSERT (0); - return 0; - } -} - -/* Return the size in bytes for each of the basic types. */ - -static size_t -get_basic_type_size (unsigned short type) -{ - switch (type) - { - case FFI_TYPE_FLOAT: - return sizeof (UINT32); - case FFI_TYPE_DOUBLE: - return sizeof (UINT64); - case FFI_TYPE_LONGDOUBLE: - return sizeof (long double); - case FFI_TYPE_UINT8: - return sizeof (UINT8); - case FFI_TYPE_SINT8: - return sizeof (SINT8); - case FFI_TYPE_UINT16: - return sizeof (UINT16); - case FFI_TYPE_SINT16: - return sizeof (SINT16); - case FFI_TYPE_UINT32: - return sizeof (UINT32); - case FFI_TYPE_INT: - case FFI_TYPE_SINT32: - return sizeof (SINT32); - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - return sizeof (UINT64); - case FFI_TYPE_SINT64: - return sizeof (SINT64); - - default: - FFI_ASSERT (0); - return 0; - } -} - -extern void -ffi_call_SYSV (unsigned (*)(struct call_context *context, unsigned char *, - extended_cif *), - struct call_context *context, - extended_cif *, - unsigned, - void (*fn)(void)); - -extern void -ffi_closure_SYSV (ffi_closure *); - -/* Test for an FFI floating point representation. */ - -static unsigned -is_floating_type (unsigned short type) -{ - return (type == FFI_TYPE_FLOAT || type == FFI_TYPE_DOUBLE - || type == FFI_TYPE_LONGDOUBLE); -} - -/* Test for a homogeneous structure. */ - -static unsigned short -get_homogeneous_type (ffi_type *ty) -{ - if (ty->type == FFI_TYPE_STRUCT && ty->elements) - { - unsigned i; - unsigned short candidate_type - = get_homogeneous_type (ty->elements[0]); - for (i =1; ty->elements[i]; i++) - { - unsigned short iteration_type = 0; - /* If we have a nested struct, we must find its homogeneous type. - If that fits with our candidate type, we are still - homogeneous. */ - if (ty->elements[i]->type == FFI_TYPE_STRUCT - && ty->elements[i]->elements) - { - iteration_type = get_homogeneous_type (ty->elements[i]); - } - else - { - iteration_type = ty->elements[i]->type; - } - - /* If we are not homogeneous, return FFI_TYPE_STRUCT. */ - if (candidate_type != iteration_type) - return FFI_TYPE_STRUCT; - } - return candidate_type; - } - - /* Base case, we have no more levels of nesting, so we - are a basic type, and so, trivially homogeneous in that type. */ - return ty->type; -} - -/* Determine the number of elements within a STRUCT. - - Note, we must handle nested structs. - - If ty is not a STRUCT this function will return 0. */ - -static unsigned -element_count (ffi_type *ty) -{ - if (ty->type == FFI_TYPE_STRUCT && ty->elements) - { - unsigned n; - unsigned elems = 0; - for (n = 0; ty->elements[n]; n++) - { - if (ty->elements[n]->type == FFI_TYPE_STRUCT - && ty->elements[n]->elements) - elems += element_count (ty->elements[n]); - else - elems++; - } - return elems; - } - return 0; -} - -/* Test for a homogeneous floating point aggregate. - - A homogeneous floating point aggregate is a homogeneous aggregate of - a half- single- or double- precision floating point type with one - to four elements. Note that this includes nested structs of the - basic type. */ - -static int -is_hfa (ffi_type *ty) -{ - if (ty->type == FFI_TYPE_STRUCT - && ty->elements[0] - && is_floating_type (get_homogeneous_type (ty))) - { - unsigned n = element_count (ty); - return n >= 1 && n <= 4; - } - return 0; -} - -/* Test if an ffi_type is a candidate for passing in a register. - - This test does not check that sufficient registers of the - appropriate class are actually available, merely that IFF - sufficient registers are available then the argument will be passed - in register(s). - - Note that an ffi_type that is deemed to be a register candidate - will always be returned in registers. - - Returns 1 if a register candidate else 0. */ - -static int -is_register_candidate (ffi_type *ty) -{ - switch (ty->type) - { - case FFI_TYPE_VOID: - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - case FFI_TYPE_LONGDOUBLE: - case FFI_TYPE_UINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_UINT64: - case FFI_TYPE_POINTER: - case FFI_TYPE_SINT8: - case FFI_TYPE_SINT16: - case FFI_TYPE_SINT32: - case FFI_TYPE_INT: - case FFI_TYPE_SINT64: - return 1; - - case FFI_TYPE_STRUCT: - if (is_hfa (ty)) - { - return 1; - } - else if (ty->size > 16) - { - /* Too large. Will be replaced with a pointer to memory. The - pointer MAY be passed in a register, but the value will - not. This test specifically fails since the argument will - never be passed by value in registers. */ - return 0; - } - else - { - /* Might be passed in registers depending on the number of - registers required. */ - return (ty->size + 7) / 8 < N_X_ARG_REG; - } - break; - - default: - FFI_ASSERT (0); - break; - } - - return 0; -} - -/* Test if an ffi_type argument or result is a candidate for a vector - register. */ - -static int -is_v_register_candidate (ffi_type *ty) -{ - return is_floating_type (ty->type) - || (ty->type == FFI_TYPE_STRUCT && is_hfa (ty)); -} - -/* Representation of the procedure call argument marshalling - state. - - The terse state variable names match the names used in the AARCH64 - PCS. */ - -struct arg_state -{ - unsigned ngrn; /* Next general-purpose register number. */ - unsigned nsrn; /* Next vector register number. */ - unsigned nsaa; /* Next stack offset. */ -}; - -/* Initialize a procedure call argument marshalling state. */ -static void -arg_init (struct arg_state *state, unsigned call_frame_size) -{ - state->ngrn = 0; - state->nsrn = 0; - state->nsaa = 0; -} - -/* Return the number of available consecutive core argument - registers. */ - -static unsigned -available_x (struct arg_state *state) -{ - return N_X_ARG_REG - state->ngrn; -} - -/* Return the number of available consecutive vector argument - registers. */ - -static unsigned -available_v (struct arg_state *state) -{ - return N_V_ARG_REG - state->nsrn; -} - -static void * -allocate_to_x (struct call_context *context, struct arg_state *state) -{ - FFI_ASSERT (state->ngrn < N_X_ARG_REG) - return get_x_addr (context, (state->ngrn)++); -} - -static void * -allocate_to_s (struct call_context *context, struct arg_state *state) -{ - FFI_ASSERT (state->nsrn < N_V_ARG_REG) - return get_s_addr (context, (state->nsrn)++); -} - -static void * -allocate_to_d (struct call_context *context, struct arg_state *state) -{ - FFI_ASSERT (state->nsrn < N_V_ARG_REG) - return get_d_addr (context, (state->nsrn)++); -} - -static void * -allocate_to_v (struct call_context *context, struct arg_state *state) -{ - FFI_ASSERT (state->nsrn < N_V_ARG_REG) - return get_v_addr (context, (state->nsrn)++); -} - -/* Allocate an aligned slot on the stack and return a pointer to it. */ -static void * -allocate_to_stack (struct arg_state *state, void *stack, unsigned alignment, - unsigned size) -{ - void *allocation; - - /* Round up the NSAA to the larger of 8 or the natural - alignment of the argument's type. */ - state->nsaa = ALIGN (state->nsaa, alignment); - state->nsaa = ALIGN (state->nsaa, alignment); - state->nsaa = ALIGN (state->nsaa, 8); - - allocation = stack + state->nsaa; - - state->nsaa += size; - return allocation; -} - -static void -copy_basic_type (void *dest, void *source, unsigned short type) -{ - /* This is neccessary to ensure that basic types are copied - sign extended to 64-bits as libffi expects. */ - switch (type) - { - case FFI_TYPE_FLOAT: - *(float *) dest = *(float *) source; - break; - case FFI_TYPE_DOUBLE: - *(double *) dest = *(double *) source; - break; - case FFI_TYPE_LONGDOUBLE: - *(long double *) dest = *(long double *) source; - break; - case FFI_TYPE_UINT8: - *(ffi_arg *) dest = *(UINT8 *) source; - break; - case FFI_TYPE_SINT8: - *(ffi_sarg *) dest = *(SINT8 *) source; - break; - case FFI_TYPE_UINT16: - *(ffi_arg *) dest = *(UINT16 *) source; - break; - case FFI_TYPE_SINT16: - *(ffi_sarg *) dest = *(SINT16 *) source; - break; - case FFI_TYPE_UINT32: - *(ffi_arg *) dest = *(UINT32 *) source; - break; - case FFI_TYPE_INT: - case FFI_TYPE_SINT32: - *(ffi_sarg *) dest = *(SINT32 *) source; - break; - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - *(ffi_arg *) dest = *(UINT64 *) source; - break; - case FFI_TYPE_SINT64: - *(ffi_sarg *) dest = *(SINT64 *) source; - break; - - default: - FFI_ASSERT (0); - } -} - -static void -copy_hfa_to_reg_or_stack (void *memory, - ffi_type *ty, - struct call_context *context, - unsigned char *stack, - struct arg_state *state) -{ - unsigned elems = element_count (ty); - if (available_v (state) < elems) - { - /* There are insufficient V registers. Further V register allocations - are prevented, the NSAA is adjusted (by allocate_to_stack ()) - and the argument is copied to memory at the adjusted NSAA. */ - state->nsrn = N_V_ARG_REG; - memcpy (allocate_to_stack (state, stack, ty->alignment, ty->size), - memory, - ty->size); - } - else - { - int i; - unsigned short type = get_homogeneous_type (ty); - unsigned elems = element_count (ty); - for (i = 0; i < elems; i++) - { - void *reg = allocate_to_v (context, state); - copy_basic_type (reg, memory, type); - memory += get_basic_type_size (type); - } - } -} - -/* Either allocate an appropriate register for the argument type, or if - none are available, allocate a stack slot and return a pointer - to the allocated space. */ - -static void * -allocate_to_register_or_stack (struct call_context *context, - unsigned char *stack, - struct arg_state *state, - unsigned short type) -{ - size_t alignment = get_basic_type_alignment (type); - size_t size = alignment; - switch (type) - { - case FFI_TYPE_FLOAT: - /* This is the only case for which the allocated stack size - should not match the alignment of the type. */ - size = sizeof (UINT32); - /* Fall through. */ - case FFI_TYPE_DOUBLE: - if (state->nsrn < N_V_ARG_REG) - return allocate_to_d (context, state); - state->nsrn = N_V_ARG_REG; - break; - case FFI_TYPE_LONGDOUBLE: - if (state->nsrn < N_V_ARG_REG) - return allocate_to_v (context, state); - state->nsrn = N_V_ARG_REG; - break; - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT32: - case FFI_TYPE_INT: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - if (state->ngrn < N_X_ARG_REG) - return allocate_to_x (context, state); - state->ngrn = N_X_ARG_REG; - break; - default: - FFI_ASSERT (0); - } - - return allocate_to_stack (state, stack, alignment, size); -} - -/* Copy a value to an appropriate register, or if none are - available, to the stack. */ - -static void -copy_to_register_or_stack (struct call_context *context, - unsigned char *stack, - struct arg_state *state, - void *value, - unsigned short type) -{ - copy_basic_type ( - allocate_to_register_or_stack (context, stack, state, type), - value, - type); -} - -/* Marshall the arguments from FFI representation to procedure call - context and stack. */ - -static unsigned -aarch64_prep_args (struct call_context *context, unsigned char *stack, - extended_cif *ecif) -{ - int i; - struct arg_state state; - - arg_init (&state, ALIGN(ecif->cif->bytes, 16)); - - for (i = 0; i < ecif->cif->nargs; i++) - { - ffi_type *ty = ecif->cif->arg_types[i]; - switch (ty->type) - { - case FFI_TYPE_VOID: - FFI_ASSERT (0); - break; - - /* If the argument is a basic type the argument is allocated to an - appropriate register, or if none are available, to the stack. */ - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - case FFI_TYPE_LONGDOUBLE: - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_INT: - case FFI_TYPE_SINT32: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - copy_to_register_or_stack (context, stack, &state, - ecif->avalue[i], ty->type); - break; - - case FFI_TYPE_STRUCT: - if (is_hfa (ty)) - { - copy_hfa_to_reg_or_stack (ecif->avalue[i], ty, context, - stack, &state); - } - else if (ty->size > 16) - { - /* If the argument is a composite type that is larger than 16 - bytes, then the argument has been copied to memory, and - the argument is replaced by a pointer to the copy. */ - - copy_to_register_or_stack (context, stack, &state, - &(ecif->avalue[i]), FFI_TYPE_POINTER); - } - else if (available_x (&state) >= (ty->size + 7) / 8) - { - /* If the argument is a composite type and the size in - double-words is not more than the number of available - X registers, then the argument is copied into consecutive - X registers. */ - int j; - for (j = 0; j < (ty->size + 7) / 8; j++) - { - memcpy (allocate_to_x (context, &state), - &(((UINT64 *) ecif->avalue[i])[j]), - sizeof (UINT64)); - } - } - else - { - /* Otherwise, there are insufficient X registers. Further X - register allocations are prevented, the NSAA is adjusted - (by allocate_to_stack ()) and the argument is copied to - memory at the adjusted NSAA. */ - state.ngrn = N_X_ARG_REG; - - memcpy (allocate_to_stack (&state, stack, ty->alignment, - ty->size), ecif->avalue + i, ty->size); - } - break; - - default: - FFI_ASSERT (0); - break; - } - } - - return ecif->cif->aarch64_flags; -} - -ffi_status -ffi_prep_cif_machdep (ffi_cif *cif) -{ - /* Round the stack up to a multiple of the stack alignment requirement. */ - cif->bytes = - (cif->bytes + (AARCH64_STACK_ALIGN - 1)) & ~ (AARCH64_STACK_ALIGN - 1); - - /* Initialize our flags. We are interested if this CIF will touch a - vector register, if so we will enable context save and load to - those registers, otherwise not. This is intended to be friendly - to lazy float context switching in the kernel. */ - cif->aarch64_flags = 0; - - if (is_v_register_candidate (cif->rtype)) - { - cif->aarch64_flags |= AARCH64_FFI_WITH_V; - } - else - { - int i; - for (i = 0; i < cif->nargs; i++) - if (is_v_register_candidate (cif->arg_types[i])) - { - cif->aarch64_flags |= AARCH64_FFI_WITH_V; - break; - } - } - - return FFI_OK; -} - -/* Call a function with the provided arguments and capture the return - value. */ -void -ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) -{ - extended_cif ecif; - - ecif.cif = cif; - ecif.avalue = avalue; - ecif.rvalue = rvalue; - - switch (cif->abi) - { - case FFI_SYSV: - { - struct call_context context; - unsigned stack_bytes; - - /* Figure out the total amount of stack space we need, the - above call frame space needs to be 16 bytes aligned to - ensure correct alignment of the first object inserted in - that space hence the ALIGN applied to cif->bytes.*/ - stack_bytes = ALIGN(cif->bytes, 16); - - memset (&context, 0, sizeof (context)); - if (is_register_candidate (cif->rtype)) - { - ffi_call_SYSV (aarch64_prep_args, &context, &ecif, stack_bytes, fn); - switch (cif->rtype->type) - { - case FFI_TYPE_VOID: - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - case FFI_TYPE_LONGDOUBLE: - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT32: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_INT: - case FFI_TYPE_SINT64: - { - void *addr = get_basic_type_addr (cif->rtype->type, - &context, 0); - copy_basic_type (rvalue, addr, cif->rtype->type); - break; - } - - case FFI_TYPE_STRUCT: - if (is_hfa (cif->rtype)) - { - int j; - unsigned short type = get_homogeneous_type (cif->rtype); - unsigned elems = element_count (cif->rtype); - for (j = 0; j < elems; j++) - { - void *reg = get_basic_type_addr (type, &context, j); - copy_basic_type (rvalue, reg, type); - rvalue += get_basic_type_size (type); - } - } - else if ((cif->rtype->size + 7) / 8 < N_X_ARG_REG) - { - unsigned size = ALIGN (cif->rtype->size, sizeof (UINT64)); - memcpy (rvalue, get_x_addr (&context, 0), size); - } - else - { - FFI_ASSERT (0); - } - break; - - default: - FFI_ASSERT (0); - break; - } - } - else - { - memcpy (get_x_addr (&context, 8), &rvalue, sizeof (UINT64)); - ffi_call_SYSV (aarch64_prep_args, &context, &ecif, - stack_bytes, fn); - } - break; - } - - default: - FFI_ASSERT (0); - break; - } -} - -static unsigned char trampoline [] = -{ 0x70, 0x00, 0x00, 0x58, /* ldr x16, 1f */ - 0x91, 0x00, 0x00, 0x10, /* adr x17, 2f */ - 0x00, 0x02, 0x1f, 0xd6 /* br x16 */ -}; - -/* Build a trampoline. */ - -#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX,FLAGS) \ - ({unsigned char *__tramp = (unsigned char*)(TRAMP); \ - UINT64 __fun = (UINT64)(FUN); \ - UINT64 __ctx = (UINT64)(CTX); \ - UINT64 __flags = (UINT64)(FLAGS); \ - memcpy (__tramp, trampoline, sizeof (trampoline)); \ - memcpy (__tramp + 12, &__fun, sizeof (__fun)); \ - memcpy (__tramp + 20, &__ctx, sizeof (__ctx)); \ - memcpy (__tramp + 28, &__flags, sizeof (__flags)); \ - __clear_cache(__tramp, __tramp + FFI_TRAMPOLINE_SIZE); \ - }) - -ffi_status -ffi_prep_closure_loc (ffi_closure* closure, - ffi_cif* cif, - void (*fun)(ffi_cif*,void*,void**,void*), - void *user_data, - void *codeloc) -{ - if (cif->abi != FFI_SYSV) - return FFI_BAD_ABI; - - FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_SYSV, codeloc, - cif->aarch64_flags); - - closure->cif = cif; - closure->user_data = user_data; - closure->fun = fun; - - return FFI_OK; -} - -/* Primary handler to setup and invoke a function within a closure. - - A closure when invoked enters via the assembler wrapper - ffi_closure_SYSV(). The wrapper allocates a call context on the - stack, saves the interesting registers (from the perspective of - the calling convention) into the context then passes control to - ffi_closure_SYSV_inner() passing the saved context and a pointer to - the stack at the point ffi_closure_SYSV() was invoked. - - On the return path the assembler wrapper will reload call context - regsiters. - - ffi_closure_SYSV_inner() marshalls the call context into ffi value - desriptors, invokes the wrapped function, then marshalls the return - value back into the call context. */ - -void -ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context, - void *stack) -{ - ffi_cif *cif = closure->cif; - void **avalue = (void**) alloca (cif->nargs * sizeof (void*)); - void *rvalue = NULL; - int i; - struct arg_state state; - - arg_init (&state, ALIGN(cif->bytes, 16)); - - for (i = 0; i < cif->nargs; i++) - { - ffi_type *ty = cif->arg_types[i]; - - switch (ty->type) - { - case FFI_TYPE_VOID: - FFI_ASSERT (0); - break; - - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT32: - case FFI_TYPE_INT: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - case FFI_TYPE_LONGDOUBLE: - avalue[i] = allocate_to_register_or_stack (context, stack, - &state, ty->type); - break; - - case FFI_TYPE_STRUCT: - if (is_hfa (ty)) - { - unsigned n = element_count (ty); - if (available_v (&state) < n) - { - state.nsrn = N_V_ARG_REG; - avalue[i] = allocate_to_stack (&state, stack, ty->alignment, - ty->size); - } - else - { - switch (get_homogeneous_type (ty)) - { - case FFI_TYPE_FLOAT: - { - /* Eeek! We need a pointer to the structure, - however the homogeneous float elements are - being passed in individual S registers, - therefore the structure is not represented as - a contiguous sequence of bytes in our saved - register context. We need to fake up a copy - of the structure layed out in memory - correctly. The fake can be tossed once the - closure function has returned hence alloca() - is sufficient. */ - int j; - UINT32 *p = avalue[i] = alloca (ty->size); - for (j = 0; j < element_count (ty); j++) - memcpy (&p[j], - allocate_to_s (context, &state), - sizeof (*p)); - break; - } - - case FFI_TYPE_DOUBLE: - { - /* Eeek! We need a pointer to the structure, - however the homogeneous float elements are - being passed in individual S registers, - therefore the structure is not represented as - a contiguous sequence of bytes in our saved - register context. We need to fake up a copy - of the structure layed out in memory - correctly. The fake can be tossed once the - closure function has returned hence alloca() - is sufficient. */ - int j; - UINT64 *p = avalue[i] = alloca (ty->size); - for (j = 0; j < element_count (ty); j++) - memcpy (&p[j], - allocate_to_d (context, &state), - sizeof (*p)); - break; - } - - case FFI_TYPE_LONGDOUBLE: - memcpy (&avalue[i], - allocate_to_v (context, &state), - sizeof (*avalue)); - break; - - default: - FFI_ASSERT (0); - break; - } - } - } - else if (ty->size > 16) - { - /* Replace Composite type of size greater than 16 with a - pointer. */ - memcpy (&avalue[i], - allocate_to_register_or_stack (context, stack, - &state, FFI_TYPE_POINTER), - sizeof (avalue[i])); - } - else if (available_x (&state) >= (ty->size + 7) / 8) - { - avalue[i] = get_x_addr (context, state.ngrn); - state.ngrn += (ty->size + 7) / 8; - } - else - { - state.ngrn = N_X_ARG_REG; - - avalue[i] = allocate_to_stack (&state, stack, ty->alignment, - ty->size); - } - break; - - default: - FFI_ASSERT (0); - break; - } - } - - /* Figure out where the return value will be passed, either in - registers or in a memory block allocated by the caller and passed - in x8. */ - - if (is_register_candidate (cif->rtype)) - { - /* Register candidates are *always* returned in registers. */ - - /* Allocate a scratchpad for the return value, we will let the - callee scrible the result into the scratch pad then move the - contents into the appropriate return value location for the - call convention. */ - rvalue = alloca (cif->rtype->size); - (closure->fun) (cif, rvalue, avalue, closure->user_data); - - /* Copy the return value into the call context so that it is returned - as expected to our caller. */ - switch (cif->rtype->type) - { - case FFI_TYPE_VOID: - break; - - case FFI_TYPE_UINT8: - case FFI_TYPE_UINT16: - case FFI_TYPE_UINT32: - case FFI_TYPE_POINTER: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT8: - case FFI_TYPE_SINT16: - case FFI_TYPE_INT: - case FFI_TYPE_SINT32: - case FFI_TYPE_SINT64: - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - case FFI_TYPE_LONGDOUBLE: - { - void *addr = get_basic_type_addr (cif->rtype->type, context, 0); - copy_basic_type (addr, rvalue, cif->rtype->type); - break; - } - case FFI_TYPE_STRUCT: - if (is_hfa (cif->rtype)) - { - int i; - unsigned short type = get_homogeneous_type (cif->rtype); - unsigned elems = element_count (cif->rtype); - for (i = 0; i < elems; i++) - { - void *reg = get_basic_type_addr (type, context, i); - copy_basic_type (reg, rvalue, type); - rvalue += get_basic_type_size (type); - } - } - else if ((cif->rtype->size + 7) / 8 < N_X_ARG_REG) - { - unsigned size = ALIGN (cif->rtype->size, sizeof (UINT64)) ; - memcpy (get_x_addr (context, 0), rvalue, size); - } - else - { - FFI_ASSERT (0); - } - break; - default: - FFI_ASSERT (0); - break; - } - } - else - { - memcpy (&rvalue, get_x_addr (context, 8), sizeof (UINT64)); - (closure->fun) (cif, rvalue, avalue, closure->user_data); - } -} - diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/aarch64/ffitarget.h --- a/Modules/_ctypes/libffi/src/aarch64/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -``Software''), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -#ifndef LIBFFI_H -#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." -#endif - -#ifndef LIBFFI_ASM -typedef unsigned long ffi_arg; -typedef signed long ffi_sarg; - -typedef enum ffi_abi - { - FFI_FIRST_ABI = 0, - FFI_SYSV, - FFI_LAST_ABI, - FFI_DEFAULT_ABI = FFI_SYSV - } ffi_abi; -#endif - -/* ---- Definitions for closures ----------------------------------------- */ - -#define FFI_CLOSURES 1 -#define FFI_TRAMPOLINE_SIZE 36 -#define FFI_NATIVE_RAW_API 0 - -/* ---- Internal ---- */ - - -#define FFI_EXTRA_CIF_FIELDS unsigned aarch64_flags - -#define AARCH64_FFI_WITH_V_BIT 0 - -#define AARCH64_N_XREG 32 -#define AARCH64_N_VREG 32 -#define AARCH64_CALL_CONTEXT_SIZE (AARCH64_N_XREG * 8 + AARCH64_N_VREG * 16) - -#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/aarch64/sysv.S --- a/Modules/_ctypes/libffi/src/aarch64/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,307 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -``Software''), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#define LIBFFI_ASM -#include -#include - -#define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off -#define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off -#define cfi_restore(reg) .cfi_restore reg -#define cfi_def_cfa_register(reg) .cfi_def_cfa_register reg - - .text - .globl ffi_call_SYSV - .type ffi_call_SYSV, #function - -/* ffi_call_SYSV() - - Create a stack frame, setup an argument context, call the callee - and extract the result. - - The maximum required argument stack size is provided, - ffi_call_SYSV() allocates that stack space then calls the - prepare_fn to populate register context and stack. The - argument passing registers are loaded from the register - context and the callee called, on return the register passing - register are saved back to the context. Our caller will - extract the return value from the final state of the saved - register context. - - Prototype: - - extern unsigned - ffi_call_SYSV (void (*)(struct call_context *context, unsigned char *, - extended_cif *), - struct call_context *context, - extended_cif *, - unsigned required_stack_size, - void (*fn)(void)); - - Therefore on entry we have: - - x0 prepare_fn - x1 &context - x2 &ecif - x3 bytes - x4 fn - - This function uses the following stack frame layout: - - == - saved x30(lr) - x29(fp)-> saved x29(fp) - saved x24 - saved x23 - saved x22 - sp' -> saved x21 - ... - sp -> (constructed callee stack arguments) - == - - Voila! */ - -#define ffi_call_SYSV_FS (8 * 4) - - .cfi_startproc -ffi_call_SYSV: - stp x29, x30, [sp, #-16]! - cfi_adjust_cfa_offset (16) - cfi_rel_offset (x29, 0) - cfi_rel_offset (x30, 8) - - mov x29, sp - cfi_def_cfa_register (x29) - sub sp, sp, #ffi_call_SYSV_FS - - stp x21, x22, [sp, 0] - cfi_rel_offset (x21, 0 - ffi_call_SYSV_FS) - cfi_rel_offset (x22, 8 - ffi_call_SYSV_FS) - - stp x23, x24, [sp, 16] - cfi_rel_offset (x23, 16 - ffi_call_SYSV_FS) - cfi_rel_offset (x24, 24 - ffi_call_SYSV_FS) - - mov x21, x1 - mov x22, x2 - mov x24, x4 - - /* Allocate the stack space for the actual arguments, many - arguments will be passed in registers, but we assume - worst case and allocate sufficient stack for ALL of - the arguments. */ - sub sp, sp, x3 - - /* unsigned (*prepare_fn) (struct call_context *context, - unsigned char *stack, extended_cif *ecif); - */ - mov x23, x0 - mov x0, x1 - mov x1, sp - /* x2 already in place */ - blr x23 - - /* Preserve the flags returned. */ - mov x23, x0 - - /* Figure out if we should touch the vector registers. */ - tbz x23, #AARCH64_FFI_WITH_V_BIT, 1f - - /* Load the vector argument passing registers. */ - ldp q0, q1, [x21, #8*32 + 0] - ldp q2, q3, [x21, #8*32 + 32] - ldp q4, q5, [x21, #8*32 + 64] - ldp q6, q7, [x21, #8*32 + 96] -1: - /* Load the core argument passing registers. */ - ldp x0, x1, [x21, #0] - ldp x2, x3, [x21, #16] - ldp x4, x5, [x21, #32] - ldp x6, x7, [x21, #48] - - /* Don't forget x8 which may be holding the address of a return buffer. - */ - ldr x8, [x21, #8*8] - - blr x24 - - /* Save the core argument passing registers. */ - stp x0, x1, [x21, #0] - stp x2, x3, [x21, #16] - stp x4, x5, [x21, #32] - stp x6, x7, [x21, #48] - - /* Note nothing useful ever comes back in x8! */ - - /* Figure out if we should touch the vector registers. */ - tbz x23, #AARCH64_FFI_WITH_V_BIT, 1f - - /* Save the vector argument passing registers. */ - stp q0, q1, [x21, #8*32 + 0] - stp q2, q3, [x21, #8*32 + 32] - stp q4, q5, [x21, #8*32 + 64] - stp q6, q7, [x21, #8*32 + 96] -1: - /* All done, unwind our stack frame. */ - ldp x21, x22, [x29, # - ffi_call_SYSV_FS] - cfi_restore (x21) - cfi_restore (x22) - - ldp x23, x24, [x29, # - ffi_call_SYSV_FS + 16] - cfi_restore (x23) - cfi_restore (x24) - - mov sp, x29 - cfi_def_cfa_register (sp) - - ldp x29, x30, [sp], #16 - cfi_adjust_cfa_offset (-16) - cfi_restore (x29) - cfi_restore (x30) - - ret - - .cfi_endproc - .size ffi_call_SYSV, .-ffi_call_SYSV - -#define ffi_closure_SYSV_FS (8 * 2 + AARCH64_CALL_CONTEXT_SIZE) - -/* ffi_closure_SYSV - - Closure invocation glue. This is the low level code invoked directly by - the closure trampoline to setup and call a closure. - - On entry x17 points to a struct trampoline_data, x16 has been clobbered - all other registers are preserved. - - We allocate a call context and save the argument passing registers, - then invoked the generic C ffi_closure_SYSV_inner() function to do all - the real work, on return we load the result passing registers back from - the call context. - - On entry - - extern void - ffi_closure_SYSV (struct trampoline_data *); - - struct trampoline_data - { - UINT64 *ffi_closure; - UINT64 flags; - }; - - This function uses the following stack frame layout: - - == - saved x30(lr) - x29(fp)-> saved x29(fp) - saved x22 - saved x21 - ... - sp -> call_context - == - - Voila! */ - - .text - .globl ffi_closure_SYSV - .cfi_startproc -ffi_closure_SYSV: - stp x29, x30, [sp, #-16]! - cfi_adjust_cfa_offset (16) - cfi_rel_offset (x29, 0) - cfi_rel_offset (x30, 8) - - mov x29, sp - - sub sp, sp, #ffi_closure_SYSV_FS - cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) - - stp x21, x22, [x29, #-16] - cfi_rel_offset (x21, 0) - cfi_rel_offset (x22, 8) - - /* Load x21 with &call_context. */ - mov x21, sp - /* Preserve our struct trampoline_data * */ - mov x22, x17 - - /* Save the rest of the argument passing registers. */ - stp x0, x1, [x21, #0] - stp x2, x3, [x21, #16] - stp x4, x5, [x21, #32] - stp x6, x7, [x21, #48] - /* Don't forget we may have been given a result scratch pad address. - */ - str x8, [x21, #64] - - /* Figure out if we should touch the vector registers. */ - ldr x0, [x22, #8] - tbz x0, #AARCH64_FFI_WITH_V_BIT, 1f - - /* Save the argument passing vector registers. */ - stp q0, q1, [x21, #8*32 + 0] - stp q2, q3, [x21, #8*32 + 32] - stp q4, q5, [x21, #8*32 + 64] - stp q6, q7, [x21, #8*32 + 96] -1: - /* Load &ffi_closure.. */ - ldr x0, [x22, #0] - mov x1, x21 - /* Compute the location of the stack at the point that the - trampoline was called. */ - add x2, x29, #16 - - bl ffi_closure_SYSV_inner - - /* Figure out if we should touch the vector registers. */ - ldr x0, [x22, #8] - tbz x0, #AARCH64_FFI_WITH_V_BIT, 1f - - /* Load the result passing vector registers. */ - ldp q0, q1, [x21, #8*32 + 0] - ldp q2, q3, [x21, #8*32 + 32] - ldp q4, q5, [x21, #8*32 + 64] - ldp q6, q7, [x21, #8*32 + 96] -1: - /* Load the result passing core registers. */ - ldp x0, x1, [x21, #0] - ldp x2, x3, [x21, #16] - ldp x4, x5, [x21, #32] - ldp x6, x7, [x21, #48] - /* Note nothing usefull is returned in x8. */ - - /* We are done, unwind our frame. */ - ldp x21, x22, [x29, #-16] - cfi_restore (x21) - cfi_restore (x22) - - mov sp, x29 - cfi_adjust_cfa_offset (-ffi_closure_SYSV_FS) - - ldp x29, x30, [sp], #16 - cfi_adjust_cfa_offset (-16) - cfi_restore (x29) - cfi_restore (x30) - - ret - .cfi_endproc - .size ffi_closure_SYSV, .-ffi_closure_SYSV diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/bfin/ffi.c --- a/Modules/_ctypes/libffi/src/bfin/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/* ----------------------------------------------------------------------- - ffi.c - Copyright (c) 2012 Alexandre K. I. de Mendonca - - Blackfin Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ -#include -#include - -#include -#include - -/* Maximum number of GPRs available for argument passing. */ -#define MAX_GPRARGS 3 - -/* - * Return types - */ -#define FFIBFIN_RET_VOID 0 -#define FFIBFIN_RET_BYTE 1 -#define FFIBFIN_RET_HALFWORD 2 -#define FFIBFIN_RET_INT64 3 -#define FFIBFIN_RET_INT32 4 - -/*====================================================================*/ -/* PROTOTYPE * - /*====================================================================*/ -void ffi_prep_args(unsigned char *, extended_cif *); - -/*====================================================================*/ -/* Externals */ -/* (Assembly) */ -/*====================================================================*/ - -extern void ffi_call_SYSV(unsigned, extended_cif *, void(*)(unsigned char *, extended_cif *), unsigned, void *, void(*fn)(void)); - -/*====================================================================*/ -/* Implementation */ -/* */ -/*====================================================================*/ - - -/* - * This function calculates the return type (size) based on type. - */ - -ffi_status ffi_prep_cif_machdep(ffi_cif *cif) -{ - /* --------------------------------------* - * Return handling * - * --------------------------------------*/ - switch (cif->rtype->type) { - case FFI_TYPE_VOID: - cif->flags = FFIBFIN_RET_VOID; - break; - case FFI_TYPE_UINT16: - case FFI_TYPE_SINT16: - cif->flags = FFIBFIN_RET_HALFWORD; - break; - case FFI_TYPE_UINT8: - cif->flags = FFIBFIN_RET_BYTE; - break; - case FFI_TYPE_INT: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT32: - case FFI_TYPE_FLOAT: - case FFI_TYPE_POINTER: - case FFI_TYPE_SINT8: - cif->flags = FFIBFIN_RET_INT32; - break; - case FFI_TYPE_SINT64: - case FFI_TYPE_UINT64: - case FFI_TYPE_DOUBLE: - cif->flags = FFIBFIN_RET_INT64; - break; - case FFI_TYPE_STRUCT: - if (cif->rtype->size <= 4){ - cif->flags = FFIBFIN_RET_INT32; - }else if (cif->rtype->size == 8){ - cif->flags = FFIBFIN_RET_INT64; - }else{ - //it will return via a hidden pointer in P0 - cif->flags = FFIBFIN_RET_VOID; - } - break; - default: - FFI_ASSERT(0); - break; - } - return FFI_OK; -} - -/* - * This will prepare the arguments and will call the assembly routine - * cif = the call interface - * fn = the function to be called - * rvalue = the return value - * avalue = the arguments - */ -void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue) -{ - int ret_type = cif->flags; - extended_cif ecif; - ecif.cif = cif; - ecif.avalue = avalue; - ecif.rvalue = rvalue; - - switch (cif->abi) { - case FFI_SYSV: - ffi_call_SYSV(cif->bytes, &ecif, ffi_prep_args, ret_type, ecif.rvalue, fn); - break; - default: - FFI_ASSERT(0); - break; - } -} - - -/* -* This function prepares the parameters (copies them from the ecif to the stack) -* to call the function (ffi_prep_args is called by the assembly routine in file -* sysv.S, which also calls the actual function) -*/ -void ffi_prep_args(unsigned char *stack, extended_cif *ecif) -{ - register unsigned int i = 0; - void **p_argv; - unsigned char *argp; - ffi_type **p_arg; - argp = stack; - p_argv = ecif->avalue; - for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; - (i != 0); - i--, p_arg++) { - size_t z; - z = (*p_arg)->size; - if (z < sizeof(int)) { - z = sizeof(int); - switch ((*p_arg)->type) { - case FFI_TYPE_SINT8: { - signed char v = *(SINT8 *)(* p_argv); - signed int t = v; - *(signed int *) argp = t; - } - break; - case FFI_TYPE_UINT8: { - unsigned char v = *(UINT8 *)(* p_argv); - unsigned int t = v; - *(unsigned int *) argp = t; - } - break; - case FFI_TYPE_SINT16: - *(signed int *) argp = (signed int) * (SINT16 *)(* p_argv); - break; - case FFI_TYPE_UINT16: - *(unsigned int *) argp = (unsigned int) * (UINT16 *)(* p_argv); - break; - case FFI_TYPE_STRUCT: - memcpy(argp, *p_argv, (*p_arg)->size); - break; - default: - FFI_ASSERT(0); - break; - } - } else if (z == sizeof(int)) { - *(unsigned int *) argp = (unsigned int) * (UINT32 *)(* p_argv); - } else { - memcpy(argp, *p_argv, z); - } - p_argv++; - argp += z; - } -} - - - diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/bfin/ffitarget.h --- a/Modules/_ctypes/libffi/src/bfin/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* ----------------------------------------------------------------------- - ffitarget.h - Copyright (c) 2012 Alexandre K. I. de Mendonca - - Blackfin Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -#ifndef LIBFFI_ASM -typedef unsigned long ffi_arg; -typedef signed long ffi_sarg; - -typedef enum ffi_abi { - FFI_FIRST_ABI = 0, - FFI_SYSV, - FFI_LAST_ABI, - FFI_DEFAULT_ABI = FFI_SYSV -} ffi_abi; -#endif - -#endif - diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/bfin/sysv.S --- a/Modules/_ctypes/libffi/src/bfin/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -/* ----------------------------------------------------------------------- - sysv.S - Copyright (c) 2012 Alexandre K. I. de Mendonca - - Blackfin Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#define LIBFFI_ASM -#include -#include - -.text -.align 4 - - /* - There is a "feature" in the bfin toolchain that it puts a _ before funcion names - that's why the function here it's called _ffi_call_SYSV and not ffi_call_SYSV - */ - .global _ffi_call_SYSV; - .type _ffi_call_SYSV, STT_FUNC; - .func ffi_call_SYSV - - /* - cif->bytes = R0 (fp+8) - &ecif = R1 (fp+12) - ffi_prep_args = R2 (fp+16) - ret_type = stack (fp+20) - ecif.rvalue = stack (fp+24) - fn = stack (fp+28) - got (fp+32) - There is room for improvement here (we can use temporary registers - instead of saving the values in the memory) - REGS: - P5 => Stack pointer (function arguments) - R5 => cif->bytes - R4 => ret->type - - FP-20 = P3 - FP-16 = SP (parameters area) - FP-12 = SP (temp) - FP-08 = function return part 1 [R0] - FP-04 = function return part 2 [R1] - */ - -_ffi_call_SYSV: -.prologue: - LINK 20; - [FP-20] = P3; - [FP+8] = R0; - [FP+12] = R1; - [FP+16] = R2; - -.allocate_stack: - //alocate cif->bytes into the stack - R1 = [FP+8]; - R0 = SP; - R0 = R0 - R1; - R1 = 4; - R0 = R0 - R1; - [FP-12] = SP; - SP = R0; - [FP-16] = SP; - -.call_prep_args: - //get the addr of prep_args - P0 = [P3 + _ffi_prep_args@FUNCDESC_GOT17M4]; - P1 = [P0]; - P3 = [P0+4]; - R0 = [FP-16];//SP (parameter area) - R1 = [FP+12];//ecif - call (P1); - -.call_user_function: - //ajust SP so as to allow the user function access the parameters on the stack - SP = [FP-16]; //point to function parameters - R0 = [SP]; - R1 = [SP+4]; - R2 = [SP+8]; - //load user function address - P0 = FP; - P0 +=28; - P1 = [P0]; - P1 = [P1]; - P3 = [P0+4]; - /* - For functions returning aggregate values (struct) occupying more than 8 bytes, - the caller allocates the return value object on the stack and the address - of this object is passed to the callee as a hidden argument in register P0. - */ - P0 = [FP+24]; - - call (P1); - SP = [FP-12]; -.compute_return: - P2 = [FP-20]; - [FP-8] = R0; - [FP-4] = R1; - - R0 = [FP+20]; - R1 = R0 << 2; - - R0 = [P2+.rettable@GOT17M4]; - R0 = R1 + R0; - P2 = R0; - R1 = [P2]; - - P2 = [FP+-20]; - R0 = [P2+.rettable@GOT17M4]; - R0 = R1 + R0; - P2 = R0; - R0 = [FP-8]; - R1 = [FP-4]; - jump (P2); - -/* -#define FFIBFIN_RET_VOID 0 -#define FFIBFIN_RET_BYTE 1 -#define FFIBFIN_RET_HALFWORD 2 -#define FFIBFIN_RET_INT64 3 -#define FFIBFIN_RET_INT32 4 -*/ -.align 4 -.align 4 -.rettable: - .dd .epilogue - .rettable - .dd .rbyte - .rettable; - .dd .rhalfword - .rettable; - .dd .rint64 - .rettable; - .dd .rint32 - .rettable; - -.rbyte: - P0 = [FP+24]; - R0 = R0.B (Z); - [P0] = R0; - JUMP .epilogue -.rhalfword: - P0 = [FP+24]; - R0 = R0.L; - [P0] = R0; - JUMP .epilogue -.rint64: - P0 = [FP+24];// &rvalue - [P0] = R0; - [P0+4] = R1; - JUMP .epilogue -.rint32: - P0 = [FP+24]; - [P0] = R0; -.epilogue: - R0 = [FP+8]; - R1 = [FP+12]; - R2 = [FP+16]; - P3 = [FP-20]; - UNLINK; - RTS; - -.size _ffi_call_SYSV,.-_ffi_call_SYSV; -.endfunc diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/closures.c --- a/Modules/_ctypes/libffi/src/closures.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/closures.c Fri Feb 01 23:12:09 2013 +0100 @@ -172,25 +172,6 @@ #endif /* !FFI_MMAP_EXEC_SELINUX */ -/* On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. */ -#ifdef FFI_MMAP_EXEC_EMUTRAMP_PAX -#include - -static int emutramp_enabled = -1; - -static int -emutramp_enabled_check (void) -{ - if (getenv ("FFI_DISABLE_EMUTRAMP") == NULL) - return 1; - else - return 0; -} - -#define is_emutramp_enabled() (emutramp_enabled >= 0 ? emutramp_enabled \ - : (emutramp_enabled = emutramp_enabled_check ())) -#endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */ - #elif defined (__CYGWIN__) || defined(__INTERIX) #include @@ -200,10 +181,6 @@ #endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */ -#ifndef FFI_MMAP_EXEC_EMUTRAMP_PAX -#define is_emutramp_enabled() 0 -#endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */ - /* Declare all functions defined in dlmalloc.c as static. */ static void *dlmalloc(size_t); static void dlfree(void*); @@ -481,12 +458,6 @@ printf ("mapping in %zi\n", length); #endif - if (execfd == -1 && is_emutramp_enabled ()) - { - ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset); - return ptr; - } - if (execfd == -1 && !is_selinux_enabled ()) { ptr = mmap (start, length, prot | PROT_EXEC, flags, fd, offset); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/m68k/ffi.c --- a/Modules/_ctypes/libffi/src/m68k/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/m68k/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -123,8 +123,6 @@ #define CIF_FLAGS_POINTER 32 #define CIF_FLAGS_STRUCT1 64 #define CIF_FLAGS_STRUCT2 128 -#define CIF_FLAGS_SINT8 256 -#define CIF_FLAGS_SINT16 512 /* Perform machine dependent cif processing */ ffi_status @@ -202,14 +200,6 @@ cif->flags = CIF_FLAGS_DINT; break; - case FFI_TYPE_SINT16: - cif->flags = CIF_FLAGS_SINT16; - break; - - case FFI_TYPE_SINT8: - cif->flags = CIF_FLAGS_SINT8; - break; - default: cif->flags = CIF_FLAGS_INT; break; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/m68k/sysv.S --- a/Modules/_ctypes/libffi/src/m68k/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/m68k/sysv.S Fri Feb 01 23:12:09 2013 +0100 @@ -2,10 +2,9 @@ sysv.S - Copyright (c) 2012 Alan Hourihane Copyright (c) 1998, 2012 Andreas Schwab - Copyright (c) 2008 Red Hat, Inc. - Copyright (c) 2012 Thorsten Glaser - - m68k Foreign Function Interface + Copyright (c) 2008 Red Hat, Inc. + + m68k Foreign Function Interface Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -169,28 +168,8 @@ retstruct2: btst #7,%d2 - jbeq retsint8 + jbeq noretval move.w %d0,(%a1) - jbra epilogue - -retsint8: - btst #8,%d2 - jbeq retsint16 - | NOTE: On the mc68000, extb is not supported. 8->16, then 16->32. -#if !defined(__mc68020__) && !defined(__mc68030__) && !defined(__mc68040__) && !defined(__mc68060__) && !defined(__mcoldfire__) - ext.w %d0 - ext.l %d0 -#else - extb.l %d0 -#endif - move.l %d0,(%a1) - jbra epilogue - -retsint16: - btst #9,%d2 - jbeq noretval - ext.l %d0 - move.l %d0,(%a1) noretval: epilogue: @@ -222,10 +201,8 @@ lsr.l #1,%d0 jne 1f jcc .Lcls_epilogue - | CIF_FLAGS_INT move.l -12(%fp),%d0 .Lcls_epilogue: - | no CIF_FLAGS_* unlk %fp rts 1: @@ -233,7 +210,6 @@ lsr.l #2,%d0 jne 1f jcs .Lcls_ret_float - | CIF_FLAGS_DINT move.l (%a0)+,%d0 move.l (%a0),%d1 jra .Lcls_epilogue @@ -248,7 +224,6 @@ lsr.l #2,%d0 jne 1f jcs .Lcls_ret_ldouble - | CIF_FLAGS_DOUBLE #if defined(__MC68881__) || defined(__HAVE_68881__) fmove.d (%a0),%fp0 #else @@ -267,37 +242,17 @@ jra .Lcls_epilogue 1: lsr.l #2,%d0 - jne 1f + jne .Lcls_ret_struct2 jcs .Lcls_ret_struct1 - | CIF_FLAGS_POINTER move.l (%a0),%a0 move.l %a0,%d0 jra .Lcls_epilogue .Lcls_ret_struct1: move.b (%a0),%d0 jra .Lcls_epilogue -1: - lsr.l #2,%d0 - jne 1f - jcs .Lcls_ret_sint8 - | CIF_FLAGS_STRUCT2 +.Lcls_ret_struct2: move.w (%a0),%d0 jra .Lcls_epilogue -.Lcls_ret_sint8: - move.l (%a0),%d0 - | NOTE: On the mc68000, extb is not supported. 8->16, then 16->32. -#if !defined(__mc68020__) && !defined(__mc68030__) && !defined(__mc68040__) && !defined(__mc68060__) && !defined(__mcoldfire__) - ext.w %d0 - ext.l %d0 -#else - extb.l %d0 -#endif - jra .Lcls_epilogue -1: - | CIF_FLAGS_SINT16 - move.l (%a0),%d0 - ext.l %d0 - jra .Lcls_epilogue CFI_ENDPROC() .size CALLFUNC(ffi_closure_SYSV),.-CALLFUNC(ffi_closure_SYSV) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/metag/ffi.c --- a/Modules/_ctypes/libffi/src/metag/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,330 +0,0 @@ -/* ---------------------------------------------------------------------- - ffi.c - Copyright (c) 2013 Imagination Technologies - - Meta Foreign Function Interface - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - `Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED `AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL SIMON POSNJAK BE LIABLE FOR ANY CLAIM, DAMAGES OR - OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------ */ - -#include -#include - -#include - -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) - -/* - * ffi_prep_args is called by the assembly routine once stack space has been - * allocated for the function's arguments - */ - -unsigned int ffi_prep_args(char *stack, extended_cif *ecif) -{ - register unsigned int i; - register void **p_argv; - register char *argp; - register ffi_type **p_arg; - - argp = stack; - - /* Store return value */ - if ( ecif->cif->flags == FFI_TYPE_STRUCT ) { - argp -= 4; - *(void **) argp = ecif->rvalue; - } - - p_argv = ecif->avalue; - - /* point to next location */ - for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; (i != 0); i--, p_arg++, p_argv++) - { - size_t z; - - /* Move argp to address of argument */ - z = (*p_arg)->size; - argp -= z; - - /* Align if necessary */ - argp = (char *) ALIGN_DOWN(ALIGN_DOWN(argp, (*p_arg)->alignment), 4); - - if (z < sizeof(int)) { - z = sizeof(int); - switch ((*p_arg)->type) - { - case FFI_TYPE_SINT8: - *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv); - break; - case FFI_TYPE_UINT8: - *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv); - break; - case FFI_TYPE_SINT16: - *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv); - break; - case FFI_TYPE_UINT16: - *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv); - case FFI_TYPE_STRUCT: - memcpy(argp, *p_argv, (*p_arg)->size); - break; - default: - FFI_ASSERT(0); - } - } else if ( z == sizeof(int)) { - *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); - } else { - memcpy(argp, *p_argv, z); - } - } - - /* return the size of the arguments to be passed in registers, - padded to an 8 byte boundary to preserve stack alignment */ - return ALIGN(MIN(stack - argp, 6*4), 8); -} - -/* Perform machine dependent cif processing */ -ffi_status ffi_prep_cif_machdep(ffi_cif *cif) -{ - ffi_type **ptr; - unsigned i, bytes = 0; - - for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++) { - if ((*ptr)->size == 0) - return FFI_BAD_TYPEDEF; - - /* Perform a sanity check on the argument type, do this - check after the initialization. */ - FFI_ASSERT_VALID_TYPE(*ptr); - - /* Add any padding if necessary */ - if (((*ptr)->alignment - 1) & bytes) - bytes = ALIGN(bytes, (*ptr)->alignment); - - bytes += ALIGN((*ptr)->size, 4); - } - - /* Ensure arg space is aligned to an 8-byte boundary */ - bytes = ALIGN(bytes, 8); - - /* Make space for the return structure pointer */ - if (cif->rtype->type == FFI_TYPE_STRUCT) { - bytes += sizeof(void*); - - /* Ensure stack is aligned to an 8-byte boundary */ - bytes = ALIGN(bytes, 8); - } - - cif->bytes = bytes; - - /* Set the return type flag */ - switch (cif->rtype->type) { - case FFI_TYPE_VOID: - case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - cif->flags = (unsigned) cif->rtype->type; - break; - case FFI_TYPE_SINT64: - case FFI_TYPE_UINT64: - cif->flags = (unsigned) FFI_TYPE_SINT64; - break; - case FFI_TYPE_STRUCT: - /* Meta can store return values which are <= 64 bits */ - if (cif->rtype->size <= 4) - /* Returned to D0Re0 as 32-bit value */ - cif->flags = (unsigned)FFI_TYPE_INT; - else if ((cif->rtype->size > 4) && (cif->rtype->size <= 8)) - /* Returned valued is stored to D1Re0|R0Re0 */ - cif->flags = (unsigned)FFI_TYPE_DOUBLE; - else - /* value stored in memory */ - cif->flags = (unsigned)FFI_TYPE_STRUCT; - break; - default: - cif->flags = (unsigned)FFI_TYPE_INT; - break; - } - return FFI_OK; -} - -extern void ffi_call_SYSV(void (*fn)(void), extended_cif *, unsigned, unsigned, double *); - -/* - * Exported in API. Entry point - * cif -> ffi_cif object - * fn -> function pointer - * rvalue -> pointer to return value - * avalue -> vector of void * pointers pointing to memory locations holding the - * arguments - */ -void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) -{ - extended_cif ecif; - - int small_struct = (((cif->flags == FFI_TYPE_INT) || (cif->flags == FFI_TYPE_DOUBLE)) && (cif->rtype->type == FFI_TYPE_STRUCT)); - ecif.cif = cif; - ecif.avalue = avalue; - - double temp; - - /* - * If the return value is a struct and we don't have a return value address - * then we need to make one - */ - - if ((rvalue == NULL ) && (cif->flags == FFI_TYPE_STRUCT)) - ecif.rvalue = alloca(cif->rtype->size); - else if (small_struct) - ecif.rvalue = &temp; - else - ecif.rvalue = rvalue; - - switch (cif->abi) { - case FFI_SYSV: - ffi_call_SYSV(fn, &ecif, cif->bytes, cif->flags, ecif.rvalue); - break; - default: - FFI_ASSERT(0); - break; - } - - if (small_struct) - memcpy (rvalue, &temp, cif->rtype->size); -} - -/* private members */ - -static void ffi_prep_incoming_args_SYSV (char *, void **, void **, - ffi_cif*, float *); - -void ffi_closure_SYSV (ffi_closure *); - -/* Do NOT change that without changing the FFI_TRAMPOLINE_SIZE */ -extern unsigned int ffi_metag_trampoline[10]; /* 10 instructions */ - -/* end of private members */ - -/* - * __tramp: trampoline memory location - * __fun: assembly routine - * __ctx: memory location for wrapper - * - * At this point, tramp[0] == __ctx ! - */ -void ffi_init_trampoline(unsigned char *__tramp, unsigned int __fun, unsigned int __ctx) { - memcpy (__tramp, ffi_metag_trampoline, sizeof(ffi_metag_trampoline)); - *(unsigned int*) &__tramp[40] = __ctx; - *(unsigned int*) &__tramp[44] = __fun; - /* This will flush the instruction cache */ - __builtin_meta2_cachewd(&__tramp[0], 1); - __builtin_meta2_cachewd(&__tramp[47], 1); -} - - - -/* the cif must already be prepared */ - -ffi_status -ffi_prep_closure_loc (ffi_closure *closure, - ffi_cif* cif, - void (*fun)(ffi_cif*,void*,void**,void*), - void *user_data, - void *codeloc) -{ - void (*closure_func)(ffi_closure*) = NULL; - - if (cif->abi == FFI_SYSV) - closure_func = &ffi_closure_SYSV; - else - return FFI_BAD_ABI; - - ffi_init_trampoline( - (unsigned char*)&closure->tramp[0], - (unsigned int)closure_func, - (unsigned int)codeloc); - - closure->cif = cif; - closure->user_data = user_data; - closure->fun = fun; - - return FFI_OK; -} - - -/* This function is jumped to by the trampoline */ -unsigned int ffi_closure_SYSV_inner (closure, respp, args, vfp_args) - ffi_closure *closure; - void **respp; - void *args; - void *vfp_args; -{ - ffi_cif *cif; - void **arg_area; - - cif = closure->cif; - arg_area = (void**) alloca (cif->nargs * sizeof (void*)); - - /* - * This call will initialize ARG_AREA, such that each - * element in that array points to the corresponding - * value on the stack; and if the function returns - * a structure, it will re-set RESP to point to the - * structure return address. - */ - ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif, vfp_args); - - (closure->fun) ( cif, *respp, arg_area, closure->user_data); - - return cif->flags; -} - -static void ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, - void **avalue, ffi_cif *cif, - float *vfp_stack) -{ - register unsigned int i; - register void **p_argv; - register char *argp; - register ffi_type **p_arg; - - /* stack points to original arguments */ - argp = stack; - - /* Store return value */ - if ( cif->flags == FFI_TYPE_STRUCT ) { - argp -= 4; - *rvalue = *(void **) argp; - } - - p_argv = avalue; - - for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++) { - size_t z; - size_t alignment; - - alignment = (*p_arg)->alignment; - if (alignment < 4) - alignment = 4; - if ((alignment - 1) & (unsigned)argp) - argp = (char *) ALIGN(argp, alignment); - - z = (*p_arg)->size; - *p_argv = (void*) argp; - p_argv++; - argp -= z; - } - return; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/metag/ffitarget.h --- a/Modules/_ctypes/libffi/src/metag/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* -----------------------------------------------------------------*-C-*- - ffitarget.h - Copyright (c) 2013 Imagination Technologies Ltd. - Target configuration macros for Meta - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - - ----------------------------------------------------------------------- */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -#ifndef LIBFFI_H -#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." -#endif - -#ifndef LIBFFI_ASM -typedef unsigned long ffi_arg; -typedef signed long ffi_sarg; - -typedef enum ffi_abi { - FFI_FIRST_ABI = 0, - FFI_SYSV, - FFI_DEFAULT_ABI = FFI_SYSV, - FFI_LAST_ABI = FFI_DEFAULT_ABI + 1, -} ffi_abi; -#endif - -/* ---- Definitions for closures ----------------------------------------- */ - -#define FFI_CLOSURES 1 -#define FFI_TRAMPOLINE_SIZE 48 -#define FFI_NATIVE_RAW_API 0 - -#endif - diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/metag/sysv.S --- a/Modules/_ctypes/libffi/src/metag/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,311 +0,0 @@ -/* ----------------------------------------------------------------------- - sysv.S - Copyright (c) 2013 Imagination Technologies Ltd. - - Meta Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#define LIBFFI_ASM -#include -#include -#ifdef HAVE_MACHINE_ASM_H -#include -#else -#ifdef __USER_LABEL_PREFIX__ -#define CONCAT1(a, b) CONCAT2(a, b) -#define CONCAT2(a, b) a ## b - -/* Use the right prefix for global labels. */ -#define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x) -#else -#define CNAME(x) x -#endif -#define ENTRY(x) .globl CNAME(x); .type CNAME(x), %function; CNAME(x): -#endif - -#ifdef __ELF__ -#define LSYM(x) .x -#else -#define LSYM(x) x -#endif - -.macro call_reg x= - .text - .balign 4 - mov D1RtP, \x - swap D1RtP, PC -.endm - -! Save register arguments -.macro SAVE_ARGS - .text - .balign 4 - setl [A0StP++], D0Ar6, D1Ar5 - setl [A0StP++], D0Ar4, D1Ar3 - setl [A0StP++], D0Ar2, D1Ar1 -.endm - -! Save retrun, frame pointer and other regs -.macro SAVE_REGS regs= - .text - .balign 4 - setl [A0StP++], D0FrT, D1RtP - ! Needs to be a pair of regs - .ifnc "\regs","" - setl [A0StP++], \regs - .endif -.endm - -! Declare a global function -.macro METAG_FUNC_START name - .text - .balign 4 - ENTRY(\name) -.endm - -! Return registers from the stack. Reverse SAVE_REGS operation -.macro RET_REGS regs=, cond= - .ifnc "\regs", "" - getl \regs, [--A0StP] - .endif - getl D0FrT, D1RtP, [--A0StP] -.endm - -! Return arguments -.macro RET_ARGS - getl D0Ar2, D1Ar1, [--A0StP] - getl D0Ar4, D1Ar3, [--A0StP] - getl D0Ar6, D1Ar5, [--A0StP] -.endm - - - ! D1Ar1: fn - ! D0Ar2: &ecif - ! D1Ar3: cif->bytes - ! D0Ar4: fig->flags - ! D1Ar5: ecif.rvalue - - ! This assumes we are using GNU as -METAG_FUNC_START ffi_call_SYSV - ! Save argument registers - - SAVE_ARGS - - ! new frame - mov D0FrT, A0FrP - add A0FrP, A0StP, #0 - - ! Preserve the old frame pointer - SAVE_REGS "D1.5, D0.5" - - ! Make room for new args. cifs->bytes is the total space for input - ! and return arguments - - add A0StP, A0StP, D1Ar3 - - ! Preserve cifs->bytes & fn - mov D0.5, D1Ar3 - mov D1.5, D1Ar1 - - ! Place all of the ffi_prep_args in position - mov D1Ar1, A0StP - - ! Call ffi_prep_args(stack, &ecif) -#ifdef __PIC__ - callr D1RtP, CNAME(ffi_prep_args@PLT) -#else - callr D1RtP, CNAME(ffi_prep_args) -#endif - - ! Restore fn pointer - - ! The foreign stack should look like this - ! XXXXX XXXXXX <--- stack pointer - ! FnArgN rvalue - ! FnArgN+2 FnArgN+1 - ! FnArgN+4 FnArgN+3 - ! .... - ! - - ! A0StP now points to the first (or return) argument + 4 - - ! Preserve cif->bytes - getl D0Ar2, D1Ar1, [--A0StP] - getl D0Ar4, D1Ar3, [--A0StP] - getl D0Ar6, D1Ar5, [--A0StP] - - ! Place A0StP to the first argument again - add A0StP, A0StP, #24 ! That's because we loaded 6 regs x 4 byte each - - ! A0FrP points to the initial stack without the reserved space for the - ! cifs->bytes, whilst A0StP points to the stack after the space allocation - - ! fn was the first argument of ffi_call_SYSV. - ! The stack at this point looks like this: - ! - ! A0StP(on entry to _SYSV) -> Arg6 Arg5 | low - ! Arg4 Arg3 | - ! Arg2 Arg1 | - ! A0FrP ----> D0FrtP D1RtP | - ! D1.5 D0.5 | - ! A0StP(bf prep_args) -> FnArgn FnArgn-1 | - ! FnArgn-2FnArgn-3 | - ! ................ | <= cifs->bytes - ! FnArg4 FnArg3 | - ! A0StP (prv_A0StP+cifs->bytes) FnArg2 FnArg1 | high - ! - ! fn was in Arg1 so it's located in in A0FrP+#-0xC - ! - - ! D0Re0 contains the size of arguments stored in registers - sub A0StP, A0StP, D0Re0 - - ! Arg1 is the function pointer for the foreign call. This has been - ! preserved in D1.5 - - ! Time to call (fn). Arguments should be like this: - ! Arg1-Arg6 are loaded to regs - ! The rest of the arguments are stored in stack pointed by A0StP - - call_reg D1.5 - - ! Reset stack. - - mov A0StP, A0FrP - - ! Load Arg1 with the pointer to storage for the return type - ! This was stored in Arg5 - - getd D1Ar1, [A0FrP+#-20] - - ! Load D0Ar2 with the return type code. This was stored in Arg4 (flags) - - getd D0Ar2, [A0FrP+#-16] - - ! We are ready to start processing the return value - ! D0Re0 (and D1Re0) hold the return value - - ! If the return value is NULL, assume no return value - cmp D1Ar1, #0 - beq LSYM(Lepilogue) - - ! return INT - cmp D0Ar2, #FFI_TYPE_INT - ! Sadly, there is no setd{cc} instruction so we need to workaround that - bne .INT64 - setd [D1Ar1], D0Re0 - b LSYM(Lepilogue) - - ! return INT64 -.INT64: - cmp D0Ar2, #FFI_TYPE_SINT64 - setleq [D1Ar1], D0Re0, D1Re0 - - ! return DOUBLE - cmp D0Ar2, #FFI_TYPE_DOUBLE - setl [D1AR1++], D0Re0, D1Re0 - -LSYM(Lepilogue): - ! At this point, the stack pointer points right after the argument - ! saved area. We need to restore 4 regs, therefore we need to move - ! 16 bytes ahead. - add A0StP, A0StP, #16 - RET_REGS "D1.5, D0.5" - RET_ARGS - getd D0Re0, [A0StP] - mov A0FrP, D0FrT - swap D1RtP, PC - -.ffi_call_SYSV_end: - .size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV) - - -/* - (called by ffi_metag_trampoline) - void ffi_closure_SYSV (ffi_closure*) - - (called by ffi_closure_SYSV) - unsigned int FFI_HIDDEN - ffi_closure_SYSV_inner (closure,respp, args) - ffi_closure *closure; - void **respp; - void *args; -*/ - -METAG_FUNC_START ffi_closure_SYSV - ! We assume that D1Ar1 holds the address of the - ! ffi_closure struct. We will use that to fetch the - ! arguments. The stack pointer points to an empty space - ! and it is ready to store more data. - - ! D1Ar1 is ready - ! Allocate stack space for return value - add A0StP, A0StP, #8 - ! Store it to D0Ar2 - sub D0Ar2, A0StP, #8 - - sub D1Ar3, A0FrP, #4 - - ! D1Ar3 contains the address of the original D1Ar1 argument - ! We need to subtract #4 later on - - ! Preverve D0Ar2 - mov D0.5, D0Ar2 - -#ifdef __PIC__ - callr D1RtP, CNAME(ffi_closure_SYSV_inner@PLT) -#else - callr D1RtP, CNAME(ffi_closure_SYSV_inner) -#endif - - ! Check the return value and store it to D0.5 - cmp D0Re0, #FFI_TYPE_INT - beq .Lretint - cmp D0Re0, #FFI_TYPE_DOUBLE - beq .Lretdouble -.Lclosure_epilogue: - sub A0StP, A0StP, #8 - RET_REGS "D1.5, D0.5" - RET_ARGS - swap D1RtP, PC - -.Lretint: - setd [D0.5], D0Re0 - b .Lclosure_epilogue -.Lretdouble: - setl [D0.5++], D0Re0, D1Re0 - b .Lclosure_epilogue -.ffi_closure_SYSV_end: -.size CNAME(ffi_closure_SYSV),.ffi_closure_SYSV_end-CNAME(ffi_closure_SYSV) - - -ENTRY(ffi_metag_trampoline) - SAVE_ARGS - ! New frame - mov A0FrP, A0StP - SAVE_REGS "D1.5, D0.5" - mov D0.5, PC - ! Load D1Ar1 the value of ffi_metag_trampoline - getd D1Ar1, [D0.5 + #8] - ! Jump to ffi_closure_SYSV - getd PC, [D0.5 + #12] diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/microblaze/ffi.c --- a/Modules/_ctypes/libffi/src/microblaze/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,321 +0,0 @@ -/* ----------------------------------------------------------------------- - ffi.c - Copyright (c) 2012, 2013 Xilinx, Inc - - MicroBlaze Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#include -#include - -extern void ffi_call_SYSV(void (*)(void*, extended_cif*), extended_cif*, - unsigned int, unsigned int, unsigned int*, void (*fn)(void), - unsigned int, unsigned int); - -extern void ffi_closure_SYSV(void); - -#define WORD_SIZE sizeof(unsigned int) -#define ARGS_REGISTER_SIZE (WORD_SIZE * 6) -#define WORD_ALIGN(x) ALIGN(x, WORD_SIZE) - -/* ffi_prep_args is called by the assembly routine once stack space - has been allocated for the function's arguments */ -void ffi_prep_args(void* stack, extended_cif* ecif) -{ - unsigned int i; - ffi_type** p_arg; - void** p_argv; - void* stack_args_p = stack; - - p_argv = ecif->avalue; - - if (ecif == NULL || ecif->cif == NULL) { - return; /* no description to prepare */ - } - - if ((ecif->cif->rtype != NULL) && - (ecif->cif->rtype->type == FFI_TYPE_STRUCT)) - { - /* if return type is a struct which is referenced on the stack/reg5, - * by a pointer. Stored the return value pointer in r5. - */ - char* addr = stack_args_p; - memcpy(addr, &(ecif->rvalue), WORD_SIZE); - stack_args_p += WORD_SIZE; - } - - if (ecif->avalue == NULL) { - return; /* no arguments to prepare */ - } - - for (i = 0, p_arg = ecif->cif->arg_types; i < ecif->cif->nargs; - i++, p_arg++) - { - size_t size = (*p_arg)->size; - int type = (*p_arg)->type; - void* value = p_argv[i]; - char* addr = stack_args_p; - int aligned_size = WORD_ALIGN(size); - - /* force word alignment on the stack */ - stack_args_p += aligned_size; - - switch (type) - { - case FFI_TYPE_UINT8: - *(unsigned int *)addr = (unsigned int)*(UINT8*)(value); - break; - case FFI_TYPE_SINT8: - *(signed int *)addr = (signed int)*(SINT8*)(value); - break; - case FFI_TYPE_UINT16: - *(unsigned int *)addr = (unsigned int)*(UINT16*)(value); - break; - case FFI_TYPE_SINT16: - *(signed int *)addr = (signed int)*(SINT16*)(value); - break; - case FFI_TYPE_STRUCT: -#if __BIG_ENDIAN__ - /* - * MicroBlaze toolchain appears to emit: - * bsrli r5, r5, 8 (caller) - * ... - * - * ... - * bslli r5, r5, 8 (callee) - * - * For structs like "struct a { uint8_t a[3]; };", when passed - * by value. - * - * Structs like "struct b { uint16_t a; };" are also expected - * to be packed strangely in registers. - * - * This appears to be because the microblaze toolchain expects - * "struct b == uint16_t", which is only any issue for big - * endian. - * - * The following is a work around for big-endian only, for the - * above mentioned case, it will re-align the contents of a - * <= 3-byte struct value. - */ - if (size < WORD_SIZE) - { - memcpy (addr + (WORD_SIZE - size), value, size); - break; - } -#endif - case FFI_TYPE_SINT32: - case FFI_TYPE_UINT32: - case FFI_TYPE_FLOAT: - case FFI_TYPE_SINT64: - case FFI_TYPE_UINT64: - case FFI_TYPE_DOUBLE: - default: - memcpy(addr, value, aligned_size); - } - } -} - -ffi_status ffi_prep_cif_machdep(ffi_cif* cif) -{ - /* check ABI */ - switch (cif->abi) - { - case FFI_SYSV: - break; - default: - return FFI_BAD_ABI; - } - return FFI_OK; -} - -void ffi_call(ffi_cif* cif, void (*fn)(void), void* rvalue, void** avalue) -{ - extended_cif ecif; - ecif.cif = cif; - ecif.avalue = avalue; - - /* If the return value is a struct and we don't have a return */ - /* value address then we need to make one */ - if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT)) { - ecif.rvalue = alloca(cif->rtype->size); - } else { - ecif.rvalue = rvalue; - } - - switch (cif->abi) - { - case FFI_SYSV: - ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, cif->flags, - ecif.rvalue, fn, cif->rtype->type, cif->rtype->size); - break; - default: - FFI_ASSERT(0); - break; - } -} - -void ffi_closure_call_SYSV(void* register_args, void* stack_args, - ffi_closure* closure, void* rvalue, - unsigned int* rtype, unsigned int* rsize) -{ - /* prepare arguments for closure call */ - ffi_cif* cif = closure->cif; - ffi_type** arg_types = cif->arg_types; - - /* re-allocate data for the args. This needs to be done in order to keep - * multi-word objects (e.g. structs) in contigious memory. Callers are not - * required to store the value of args in the lower 6 words in the stack - * (although they are allocated in the stack). - */ - char* stackclone = alloca(cif->bytes); - void** avalue = alloca(cif->nargs * sizeof(void*)); - void* struct_rvalue = NULL; - char* ptr = stackclone; - int i; - - /* copy registers into stack clone */ - int registers_used = cif->bytes; - if (registers_used > ARGS_REGISTER_SIZE) { - registers_used = ARGS_REGISTER_SIZE; - } - memcpy(stackclone, register_args, registers_used); - - /* copy stack allocated args into stack clone */ - if (cif->bytes > ARGS_REGISTER_SIZE) { - int stack_used = cif->bytes - ARGS_REGISTER_SIZE; - memcpy(stackclone + ARGS_REGISTER_SIZE, stack_args, stack_used); - } - - /* preserve struct type return pointer passing */ - if ((cif->rtype != NULL) && (cif->rtype->type == FFI_TYPE_STRUCT)) { - struct_rvalue = *((void**)ptr); - ptr += WORD_SIZE; - } - - /* populate arg pointer list */ - for (i = 0; i < cif->nargs; i++) - { - switch (arg_types[i]->type) - { - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT8: -#ifdef __BIG_ENDIAN__ - avalue[i] = ptr + 3; -#else - avalue[i] = ptr; -#endif - break; - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT16: -#ifdef __BIG_ENDIAN__ - avalue[i] = ptr + 2; -#else - avalue[i] = ptr; -#endif - break; - case FFI_TYPE_STRUCT: -#if __BIG_ENDIAN__ - /* - * Work around strange ABI behaviour. - * (see info in ffi_prep_args) - */ - if (arg_types[i]->size < WORD_SIZE) - { - memcpy (ptr, ptr + (WORD_SIZE - arg_types[i]->size), arg_types[i]->size); - } -#endif - avalue[i] = (void*)ptr; - break; - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - case FFI_TYPE_DOUBLE: - avalue[i] = ptr; - break; - case FFI_TYPE_SINT32: - case FFI_TYPE_UINT32: - case FFI_TYPE_FLOAT: - default: - /* default 4-byte argument */ - avalue[i] = ptr; - break; - } - ptr += WORD_ALIGN(arg_types[i]->size); - } - - /* set the return type info passed back to the wrapper */ - *rsize = cif->rtype->size; - *rtype = cif->rtype->type; - if (struct_rvalue != NULL) { - closure->fun(cif, struct_rvalue, avalue, closure->user_data); - /* copy struct return pointer value into function return value */ - *((void**)rvalue) = struct_rvalue; - } else { - closure->fun(cif, rvalue, avalue, closure->user_data); - } -} - -ffi_status ffi_prep_closure_loc( - ffi_closure* closure, ffi_cif* cif, - void (*fun)(ffi_cif*, void*, void**, void*), - void* user_data, void* codeloc) -{ - unsigned long* tramp = (unsigned long*)&(closure->tramp[0]); - unsigned long cls = (unsigned long)codeloc; - unsigned long fn = 0; - unsigned long fn_closure_call_sysv = (unsigned long)ffi_closure_call_SYSV; - - closure->cif = cif; - closure->fun = fun; - closure->user_data = user_data; - - switch (cif->abi) - { - case FFI_SYSV: - fn = (unsigned long)ffi_closure_SYSV; - - /* load r11 (temp) with fn */ - /* imm fn(upper) */ - tramp[0] = 0xb0000000 | ((fn >> 16) & 0xffff); - /* addik r11, r0, fn(lower) */ - tramp[1] = 0x31600000 | (fn & 0xffff); - - /* load r12 (temp) with cls */ - /* imm cls(upper) */ - tramp[2] = 0xb0000000 | ((cls >> 16) & 0xffff); - /* addik r12, r0, cls(lower) */ - tramp[3] = 0x31800000 | (cls & 0xffff); - - /* load r3 (temp) with ffi_closure_call_SYSV */ - /* imm fn_closure_call_sysv(upper) */ - tramp[4] = 0xb0000000 | ((fn_closure_call_sysv >> 16) & 0xffff); - /* addik r3, r0, fn_closure_call_sysv(lower) */ - tramp[5] = 0x30600000 | (fn_closure_call_sysv & 0xffff); - /* branch/jump to address stored in r11 (fn) */ - tramp[6] = 0x98085800; /* bra r11 */ - - break; - default: - return FFI_BAD_ABI; - } - return FFI_OK; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/microblaze/ffitarget.h --- a/Modules/_ctypes/libffi/src/microblaze/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* ----------------------------------------------------------------------- - ffitarget.h - Copyright (c) 2012, 2013 Xilinx, Inc - - Target configuration macros for MicroBlaze. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -#ifndef LIBFFI_H -#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." -#endif - -#ifndef LIBFFI_ASM -typedef unsigned long ffi_arg; -typedef signed long ffi_sarg; - -typedef enum ffi_abi { - FFI_FIRST_ABI = 0, - FFI_SYSV, - FFI_LAST_ABI, - FFI_DEFAULT_ABI = FFI_SYSV -} ffi_abi; -#endif - -/* Definitions for closures */ - -#define FFI_CLOSURES 1 -#define FFI_NATIVE_RAW_API 0 - -#define FFI_TRAMPOLINE_SIZE (4*8) - -#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/microblaze/sysv.S --- a/Modules/_ctypes/libffi/src/microblaze/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,302 +0,0 @@ -/* ----------------------------------------------------------------------- - sysv.S - Copyright (c) 2012, 2013 Xilinx, Inc - - MicroBlaze Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#define LIBFFI_ASM -#include -#include - - /* - * arg[0] (r5) = ffi_prep_args, - * arg[1] (r6) = &ecif, - * arg[2] (r7) = cif->bytes, - * arg[3] (r8) = cif->flags, - * arg[4] (r9) = ecif.rvalue, - * arg[5] (r10) = fn - * arg[6] (sp[0]) = cif->rtype->type - * arg[7] (sp[4]) = cif->rtype->size - */ - .text - .globl ffi_call_SYSV - .type ffi_call_SYSV, @function -ffi_call_SYSV: - /* push callee saves */ - addik r1, r1, -20 - swi r19, r1, 0 /* Frame Pointer */ - swi r20, r1, 4 /* PIC register */ - swi r21, r1, 8 /* PIC register */ - swi r22, r1, 12 /* save for locals */ - swi r23, r1, 16 /* save for locals */ - - /* save the r5-r10 registers in the stack */ - addik r1, r1, -24 /* increment sp to store 6x 32-bit words */ - swi r5, r1, 0 - swi r6, r1, 4 - swi r7, r1, 8 - swi r8, r1, 12 - swi r9, r1, 16 - swi r10, r1, 20 - - /* save function pointer */ - addik r3, r5, 0 /* copy ffi_prep_args into r3 */ - addik r22, r1, 0 /* save sp for unallocated args into r22 (callee-saved) */ - addik r23, r10, 0 /* save function address into r23 (callee-saved) */ - - /* prepare stack with allocation for n (bytes = r7) args */ - rsub r1, r7, r1 /* subtract bytes from sp */ - - /* prep args for ffi_prep_args call */ - addik r5, r1, 0 /* store stack pointer into arg[0] */ - /* r6 still holds ecif for arg[1] */ - - /* Call ffi_prep_args(stack, &ecif). */ - addik r1, r1, -4 - swi r15, r1, 0 /* store the link register in the frame */ - brald r15, r3 - nop /* branch has delay slot */ - lwi r15, r1, 0 - addik r1, r1, 4 /* restore the link register from the frame */ - /* returns calling stack pointer location */ - - /* prepare args for fn call, prep_args populates them onto the stack */ - lwi r5, r1, 0 /* arg[0] */ - lwi r6, r1, 4 /* arg[1] */ - lwi r7, r1, 8 /* arg[2] */ - lwi r8, r1, 12 /* arg[3] */ - lwi r9, r1, 16 /* arg[4] */ - lwi r10, r1, 20 /* arg[5] */ - - /* call (fn) (...). */ - addik r1, r1, -4 - swi r15, r1, 0 /* store the link register in the frame */ - brald r15, r23 - nop /* branch has delay slot */ - lwi r15, r1, 0 - addik r1, r1, 4 /* restore the link register from the frame */ - - /* Remove the space we pushed for the args. */ - addik r1, r22, 0 /* restore old SP */ - - /* restore this functions parameters */ - lwi r5, r1, 0 /* arg[0] */ - lwi r6, r1, 4 /* arg[1] */ - lwi r7, r1, 8 /* arg[2] */ - lwi r8, r1, 12 /* arg[3] */ - lwi r9, r1, 16 /* arg[4] */ - lwi r10, r1, 20 /* arg[5] */ - addik r1, r1, 24 /* decrement sp to de-allocate 6x 32-bit words */ - - /* If the return value pointer is NULL, assume no return value. */ - beqi r9, ffi_call_SYSV_end - - lwi r22, r1, 48 /* get return type (20 for locals + 28 for arg[6]) */ - lwi r23, r1, 52 /* get return size (20 for locals + 32 for arg[7]) */ - - /* Check if return type is actually a struct, do nothing */ - rsubi r11, r22, FFI_TYPE_STRUCT - beqi r11, ffi_call_SYSV_end - - /* Return 8bit */ - rsubi r11, r23, 1 - beqi r11, ffi_call_SYSV_store8 - - /* Return 16bit */ - rsubi r11, r23, 2 - beqi r11, ffi_call_SYSV_store16 - - /* Return 32bit */ - rsubi r11, r23, 4 - beqi r11, ffi_call_SYSV_store32 - - /* Return 64bit */ - rsubi r11, r23, 8 - beqi r11, ffi_call_SYSV_store64 - - /* Didnt match anything */ - bri ffi_call_SYSV_end - -ffi_call_SYSV_store64: - swi r3, r9, 0 /* store word r3 into return value */ - swi r4, r9, 4 /* store word r4 into return value */ - bri ffi_call_SYSV_end - -ffi_call_SYSV_store32: - swi r3, r9, 0 /* store word r3 into return value */ - bri ffi_call_SYSV_end - -ffi_call_SYSV_store16: -#ifdef __BIG_ENDIAN__ - shi r3, r9, 2 /* store half-word r3 into return value */ -#else - shi r3, r9, 0 /* store half-word r3 into return value */ -#endif - bri ffi_call_SYSV_end - -ffi_call_SYSV_store8: -#ifdef __BIG_ENDIAN__ - sbi r3, r9, 3 /* store byte r3 into return value */ -#else - sbi r3, r9, 0 /* store byte r3 into return value */ -#endif - bri ffi_call_SYSV_end - -ffi_call_SYSV_end: - /* callee restores */ - lwi r19, r1, 0 /* frame pointer */ - lwi r20, r1, 4 /* PIC register */ - lwi r21, r1, 8 /* PIC register */ - lwi r22, r1, 12 - lwi r23, r1, 16 - addik r1, r1, 20 - - /* return from sub-routine (with delay slot) */ - rtsd r15, 8 - nop - - .size ffi_call_SYSV, . - ffi_call_SYSV - -/* ------------------------------------------------------------------------- */ - - /* - * args passed into this function, are passed down to the callee. - * this function is the target of the closure trampoline, as such r12 is - * a pointer to the closure object. - */ - .text - .globl ffi_closure_SYSV - .type ffi_closure_SYSV, @function -ffi_closure_SYSV: - /* push callee saves */ - addik r11, r1, 28 /* save stack args start location (excluding regs/link) */ - addik r1, r1, -12 - swi r19, r1, 0 /* Frame Pointer */ - swi r20, r1, 4 /* PIC register */ - swi r21, r1, 8 /* PIC register */ - - /* store register args on stack */ - addik r1, r1, -24 - swi r5, r1, 0 - swi r6, r1, 4 - swi r7, r1, 8 - swi r8, r1, 12 - swi r9, r1, 16 - swi r10, r1, 20 - - /* setup args */ - addik r5, r1, 0 /* register_args */ - addik r6, r11, 0 /* stack_args */ - addik r7, r12, 0 /* closure object */ - addik r1, r1, -8 /* allocate return value */ - addik r8, r1, 0 /* void* rvalue */ - addik r1, r1, -8 /* allocate for reutrn type/size values */ - addik r9, r1, 0 /* void* rtype */ - addik r10, r1, 4 /* void* rsize */ - - /* call the wrap_call function */ - addik r1, r1, -28 /* allocate args + link reg */ - swi r15, r1, 0 /* store the link register in the frame */ - brald r15, r3 - nop /* branch has delay slot */ - lwi r15, r1, 0 - addik r1, r1, 28 /* restore the link register from the frame */ - -ffi_closure_SYSV_prepare_return: - lwi r9, r1, 0 /* rtype */ - lwi r10, r1, 4 /* rsize */ - addik r1, r1, 8 /* de-allocate return info values */ - - /* Check if return type is actually a struct, store 4 bytes */ - rsubi r11, r9, FFI_TYPE_STRUCT - beqi r11, ffi_closure_SYSV_store32 - - /* Return 8bit */ - rsubi r11, r10, 1 - beqi r11, ffi_closure_SYSV_store8 - - /* Return 16bit */ - rsubi r11, r10, 2 - beqi r11, ffi_closure_SYSV_store16 - - /* Return 32bit */ - rsubi r11, r10, 4 - beqi r11, ffi_closure_SYSV_store32 - - /* Return 64bit */ - rsubi r11, r10, 8 - beqi r11, ffi_closure_SYSV_store64 - - /* Didnt match anything */ - bri ffi_closure_SYSV_end - -ffi_closure_SYSV_store64: - lwi r3, r1, 0 /* store word r3 into return value */ - lwi r4, r1, 4 /* store word r4 into return value */ - /* 64 bits == 2 words, no sign extend occurs */ - bri ffi_closure_SYSV_end - -ffi_closure_SYSV_store32: - lwi r3, r1, 0 /* store word r3 into return value */ - /* 32 bits == 1 word, no sign extend occurs */ - bri ffi_closure_SYSV_end - -ffi_closure_SYSV_store16: -#ifdef __BIG_ENDIAN__ - lhui r3, r1, 2 /* store half-word r3 into return value */ -#else - lhui r3, r1, 0 /* store half-word r3 into return value */ -#endif - rsubi r11, r9, FFI_TYPE_SINT16 - bnei r11, ffi_closure_SYSV_end - sext16 r3, r3 /* fix sign extend of sint8 */ - bri ffi_closure_SYSV_end - -ffi_closure_SYSV_store8: -#ifdef __BIG_ENDIAN__ - lbui r3, r1, 3 /* store byte r3 into return value */ -#else - lbui r3, r1, 0 /* store byte r3 into return value */ -#endif - rsubi r11, r9, FFI_TYPE_SINT8 - bnei r11, ffi_closure_SYSV_end - sext8 r3, r3 /* fix sign extend of sint8 */ - bri ffi_closure_SYSV_end - -ffi_closure_SYSV_end: - addik r1, r1, 8 /* de-allocate return value */ - - /* de-allocate stored args */ - addik r1, r1, 24 - - /* callee restores */ - lwi r19, r1, 0 /* frame pointer */ - lwi r20, r1, 4 /* PIC register */ - lwi r21, r1, 8 /* PIC register */ - addik r1, r1, 12 - - /* return from sub-routine (with delay slot) */ - rtsd r15, 8 - nop - - .size ffi_closure_SYSV, . - ffi_closure_SYSV diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/mips/ffi.c --- a/Modules/_ctypes/libffi/src/mips/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/mips/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -670,16 +670,9 @@ if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT) return FFI_BAD_ABI; fn = ffi_closure_O32; -#else -#if _MIPS_SIM ==_ABIN32 - if (cif->abi != FFI_N32 - && cif->abi != FFI_N32_SOFT_FLOAT) +#else /* FFI_MIPS_N32 */ + if (cif->abi != FFI_N32 && cif->abi != FFI_N64) return FFI_BAD_ABI; -#else - if (cif->abi != FFI_N64 - && cif->abi != FFI_N64_SOFT_FLOAT) - return FFI_BAD_ABI; -#endif fn = ffi_closure_N32; #endif /* FFI_MIPS_O32 */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/moxie/eabi.S --- a/Modules/_ctypes/libffi/src/moxie/eabi.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/moxie/eabi.S Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- - eabi.S - Copyright (c) 2012, 2013 Anthony Green + eabi.S - Copyright (c) 2004 Anthony Green - Moxie Assembly glue. + FR-V Assembly glue. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -34,68 +34,95 @@ .globl ffi_call_EABI .type ffi_call_EABI, @function - # $r0 : ffi_prep_args - # $r1 : &ecif - # $r2 : cif->bytes - # $r3 : fig->flags - # $r4 : ecif.rvalue - # $r5 : fn + # gr8 : ffi_prep_args + # gr9 : &ecif + # gr10: cif->bytes + # gr11: fig->flags + # gr12: ecif.rvalue + # gr13: fn -ffi_call_EABI: - push $sp, $r6 - push $sp, $r7 - push $sp, $r8 - dec $sp, 24 +ffi_call_EABI: + addi sp, #-80, sp + sti fp, @(sp, #24) + addi sp, #24, fp + movsg lr, gr5 - /* Store incoming args on stack. */ - sto.l 0($sp), $r0 /* ffi_prep_args */ - sto.l 4($sp), $r1 /* ecif */ - sto.l 8($sp), $r2 /* bytes */ - sto.l 12($sp), $r3 /* flags */ - sto.l 16($sp), $r4 /* &rvalue */ - sto.l 20($sp), $r5 /* fn */ + /* Make room for the new arguments. */ + /* subi sp, fp, gr10 */ + + /* Store return address and incoming args on stack. */ + sti gr5, @(fp, #8) + sti gr8, @(fp, #-4) + sti gr9, @(fp, #-8) + sti gr10, @(fp, #-12) + sti gr11, @(fp, #-16) + sti gr12, @(fp, #-20) + sti gr13, @(fp, #-24) + + sub sp, gr10, sp /* Call ffi_prep_args. */ - mov $r6, $r4 /* Save result buffer */ - mov $r7, $r5 /* Save the target fn */ - mov $r8, $r3 /* Save the flags */ - sub.l $sp, $r2 /* Allocate stack space */ - mov $r0, $sp /* We can stomp over $r0 */ - /* $r1 is already set up */ - jsra ffi_prep_args + ldi @(fp, #-4), gr4 + addi sp, #0, gr8 + ldi @(fp, #-8), gr9 +#ifdef __FRV_FDPIC__ + ldd @(gr4, gr0), gr14 + calll @(gr14, gr0) +#else + calll @(gr4, gr0) +#endif - /* Load register arguments. */ - ldo.l $r0, 0($sp) - ldo.l $r1, 4($sp) - ldo.l $r2, 8($sp) - ldo.l $r3, 12($sp) - ldo.l $r4, 16($sp) - ldo.l $r5, 20($sp) + /* ffi_prep_args returns the new stack pointer. */ + mov gr8, gr4 + + ldi @(sp, #0), gr8 + ldi @(sp, #4), gr9 + ldi @(sp, #8), gr10 + ldi @(sp, #12), gr11 + ldi @(sp, #16), gr12 + ldi @(sp, #20), gr13 + + /* Always copy the return value pointer into the hidden + parameter register. This is only strictly necessary + when we're returning an aggregate type, but it doesn't + hurt to do this all the time, and it saves a branch. */ + ldi @(fp, #-20), gr3 + + /* Use the ffi_prep_args return value for the new sp. */ + mov gr4, sp /* Call the target function. */ - jsr $r7 + ldi @(fp, -24), gr4 +#ifdef __FRV_FDPIC__ + ldd @(gr4, gr0), gr14 + calll @(gr14, gr0) +#else + calll @(gr4, gr0) +#endif - ldi.l $r7, 0xffffffff - cmp $r8, $r7 - beq retstruct + /* Store the result. */ + ldi @(fp, #-16), gr10 /* fig->flags */ + ldi @(fp, #-20), gr4 /* ecif.rvalue */ - ldi.l $r7, 4 - cmp $r8, $r7 - bgt ret2reg + /* Is the return value stored in two registers? */ + cmpi gr10, #8, icc0 + bne icc0, 0, .L2 + /* Yes, save them. */ + sti gr8, @(gr4, #0) + sti gr9, @(gr4, #4) + bra .L3 +.L2: + /* Is the return value a structure? */ + cmpi gr10, #-1, icc0 + beq icc0, 0, .L3 + /* No, save a 4 byte return value. */ + sti gr8, @(gr4, #0) +.L3: - st.l ($r6), $r0 - jmpa retdone - -ret2reg: - st.l ($r6), $r0 - sto.l 4($r6), $r1 - -retstruct: -retdone: - /* Return. */ - ldo.l $r6, -4($fp) - ldo.l $r7, -8($fp) - ldo.l $r8, -12($fp) - ret + /* Restore the stack, and return. */ + ldi @(fp, 8), gr5 + ld @(fp, gr0), fp + addi sp,#80,sp + jmpl @(gr5,gr0) .size ffi_call_EABI, .-ffi_call_EABI diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/moxie/ffi.c --- a/Modules/_ctypes/libffi/src/moxie/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/moxie/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- - ffi.c - Copyright (C) 2012, 2013 Anthony Green + ffi.c - Copyright (C) 2009 Anthony Green Moxie Foreign Function Interface @@ -43,12 +43,6 @@ p_argv = ecif->avalue; argp = stack; - if (ecif->cif->rtype->type == FFI_TYPE_STRUCT) - { - *(void **) argp = ecif->rvalue; - argp += 4; - } - for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; (i != 0); i--, p_arg++) @@ -62,6 +56,17 @@ z = sizeof(void*); *(void **) argp = *p_argv; } + /* if ((*p_arg)->type == FFI_TYPE_FLOAT) + { + if (count > 24) + { + // This is going on the stack. Turn it into a double. + *(double *) argp = (double) *(float*)(* p_argv); + z = sizeof(double); + } + else + *(void **) argp = *(void **)(* p_argv); + } */ else if (z < sizeof(int)) { z = sizeof(int); @@ -142,7 +147,8 @@ } else ecif.rvalue = rvalue; - + + switch (cif->abi) { case FFI_EABI: @@ -159,25 +165,19 @@ unsigned arg4, unsigned arg5, unsigned arg6) { /* This function is called by a trampoline. The trampoline stows a - pointer to the ffi_closure object in $r7. We must save this + pointer to the ffi_closure object in gr7. We must save this pointer in a place that will persist while we do our work. */ - register ffi_closure *creg __asm__ ("$r12"); + register ffi_closure *creg __asm__ ("gr7"); ffi_closure *closure = creg; /* Arguments that don't fit in registers are found on the stack at a fixed offset above the current frame pointer. */ - register char *frame_pointer __asm__ ("$fp"); - - /* Pointer to a struct return value. */ - void *struct_rvalue = (void *) arg1; - - /* 6 words reserved for register args + 3 words from jsr */ - char *stack_args = frame_pointer + 9*4; + register char *frame_pointer __asm__ ("fp"); + char *stack_args = frame_pointer + 16; /* Lay the register arguments down in a continuous chunk of memory. */ unsigned register_args[6] = { arg1, arg2, arg3, arg4, arg5, arg6 }; - char *register_args_ptr = (char *) register_args; ffi_cif *cif = closure->cif; ffi_type **arg_types = cif->arg_types; @@ -185,12 +185,6 @@ char *ptr = (char *) register_args; int i; - /* preserve struct type return pointer passing */ - if ((cif->rtype != NULL) && (cif->rtype->type == FFI_TYPE_STRUCT)) { - ptr += 4; - register_args_ptr = (char *)®ister_args[1]; - } - /* Find the address of each argument. */ for (i = 0; i < cif->nargs; i++) { @@ -207,7 +201,6 @@ case FFI_TYPE_SINT32: case FFI_TYPE_UINT32: case FFI_TYPE_FLOAT: - case FFI_TYPE_POINTER: avalue[i] = ptr; break; case FFI_TYPE_STRUCT: @@ -223,21 +216,30 @@ /* If we've handled more arguments than fit in registers, start looking at the those passed on the stack. */ - if (ptr == ®ister_args[6]) + if (ptr == ((char *)register_args + (6*4))) ptr = stack_args; } /* Invoke the closure. */ - if (cif->rtype && (cif->rtype->type == FFI_TYPE_STRUCT)) + if (cif->rtype->type == FFI_TYPE_STRUCT) { - (closure->fun) (cif, struct_rvalue, avalue, closure->user_data); + /* The caller allocates space for the return structure, and + passes a pointer to this space in gr3. Use this value directly + as the return value. */ + register void *return_struct_ptr __asm__("gr3"); + (closure->fun) (cif, return_struct_ptr, avalue, closure->user_data); } else { /* Allocate space for the return value and call the function. */ long long rvalue; (closure->fun) (cif, &rvalue, avalue, closure->user_data); - asm ("mov $r12, %0\n ld.l $r0, ($r12)\n ldo.l $r1, 4($r12)" : : "r" (&rvalue)); + + /* Functions return 4-byte or smaller results in gr8. 8-byte + values also use gr9. We fill the both, even for small return + values, just to avoid a branch. */ + asm ("ldi @(%0, #0), gr8" : : "r" (&rvalue)); + asm ("ldi @(%0, #0), gr9" : : "r" (&((int *) &rvalue)[1])); } } @@ -248,25 +250,27 @@ void *user_data, void *codeloc) { - unsigned short *tramp = (unsigned short *) &closure->tramp[0]; + unsigned int *tramp = (unsigned int *) &closure->tramp[0]; unsigned long fn = (long) ffi_closure_eabi; unsigned long cls = (long) codeloc; - - if (cif->abi != FFI_EABI) - return FFI_BAD_ABI; + int i; fn = (unsigned long) ffi_closure_eabi; - tramp[0] = 0x01e0; /* ldi.l $r7, .... */ - tramp[1] = cls >> 16; - tramp[2] = cls & 0xffff; - tramp[3] = 0x1a00; /* jmpa .... */ - tramp[4] = fn >> 16; - tramp[5] = fn & 0xffff; + tramp[0] = 0x8cfc0000 + (fn & 0xffff); /* setlos lo(fn), gr6 */ + tramp[1] = 0x8efc0000 + (cls & 0xffff); /* setlos lo(cls), gr7 */ + tramp[2] = 0x8cf80000 + (fn >> 16); /* sethi hi(fn), gr6 */ + tramp[3] = 0x8ef80000 + (cls >> 16); /* sethi hi(cls), gr7 */ + tramp[4] = 0x80300006; /* jmpl @(gr0, gr6) */ closure->cif = cif; closure->fun = fun; closure->user_data = user_data; + /* Cache flushing. */ + for (i = 0; i < FFI_TRAMPOLINE_SIZE; i++) + __asm__ volatile ("dcf @(%0,%1)\n\tici @(%2,%1)" :: "r" (tramp), "r" (i), + "r" (codeloc)); + return FFI_OK; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/moxie/ffitarget.h --- a/Modules/_ctypes/libffi/src/moxie/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* -----------------------------------------------------------------*-C-*- - ffitarget.h - Copyright (c) 2012, 2013 Anthony Green - Target configuration macros for Moxie - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - - ----------------------------------------------------------------------- */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -/* ---- System specific configurations ----------------------------------- */ - -#ifndef LIBFFI_ASM -typedef unsigned long ffi_arg; -typedef signed long ffi_sarg; - -typedef enum ffi_abi { - FFI_FIRST_ABI = 0, - FFI_EABI, - FFI_DEFAULT_ABI = FFI_EABI, - FFI_LAST_ABI = FFI_DEFAULT_ABI + 1 -} ffi_abi; -#endif - -/* ---- Definitions for closures ----------------------------------------- */ - -#define FFI_CLOSURES 1 -#define FFI_NATIVE_RAW_API 0 - -/* Trampolines are 12-bytes long. See ffi_prep_closure_loc. */ -#define FFI_TRAMPOLINE_SIZE (12) - -#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/powerpc/aix.S --- a/Modules/_ctypes/libffi/src/powerpc/aix.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/powerpc/aix.S Fri Feb 01 23:12:09 2013 +0100 @@ -137,7 +137,7 @@ mtcrf 0x40, r31 mtctr r0 /* Load all those argument registers. */ - /* We have set up a nice stack frame, just load it into registers. */ + // We have set up a nice stack frame, just load it into registers. ld r3, 40+(1*8)(r1) ld r4, 40+(2*8)(r1) ld r5, 40+(3*8)(r1) @@ -150,7 +150,7 @@ L1: /* Load all the FP registers. */ - bf 6,L2 /* 2f + 0x18 */ + bf 6,L2 // 2f + 0x18 lfd f1,-32-(13*8)(r28) lfd f2,-32-(12*8)(r28) lfd f3,-32-(11*8)(r28) @@ -239,7 +239,7 @@ mtcrf 0x40, r31 mtctr r0 /* Load all those argument registers. */ - /* We have set up a nice stack frame, just load it into registers. */ + // We have set up a nice stack frame, just load it into registers. lwz r3, 20+(1*4)(r1) lwz r4, 20+(2*4)(r1) lwz r5, 20+(3*4)(r1) @@ -252,7 +252,7 @@ L1: /* Load all the FP registers. */ - bf 6,L2 /* 2f + 0x18 */ + bf 6,L2 // 2f + 0x18 lfd f1,-16-(13*8)(r28) lfd f2,-16-(12*8)(r28) lfd f3,-16-(11*8)(r28) @@ -307,7 +307,7 @@ #endif .long 0 .byte 0,0,0,1,128,4,0,0 -/* END(ffi_call_AIX) */ +//END(ffi_call_AIX) .csect .text[PR] .align 2 @@ -325,4 +325,4 @@ blr .long 0 .byte 0,0,0,0,0,0,0,0 -/* END(ffi_call_DARWIN) */ +//END(ffi_call_DARWIN) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/powerpc/ffi.c --- a/Modules/_ctypes/libffi/src/powerpc/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/powerpc/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -48,11 +48,6 @@ FLAG_RETURNS_128BITS = 1 << (31-27), /* cr6 */ - FLAG_SYSV_SMST_R4 = 1 << (31-26), /* use r4 for FFI_SYSV 8 byte - structs. */ - FLAG_SYSV_SMST_R3 = 1 << (31-25), /* use r3 for FFI_SYSV 4 byte - structs. */ - FLAG_ARG_NEEDS_COPY = 1 << (31- 7), #ifndef __NO_FPRS__ FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */ @@ -146,14 +141,12 @@ } p_argv; size_t struct_copy_size; unsigned gprvalue; -#ifndef __NO_FPRS__ - double double_tmp; -#endif stacktop.c = (char *) stack + bytes; gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS; intarg_count = 0; #ifndef __NO_FPRS__ + double double_tmp; fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS; fparg_count = 0; copy_space.c = ((flags & FLAG_FP_ARGUMENTS) ? fpr_base.c : gpr_base.c); @@ -374,13 +367,7 @@ /* Check that we didn't overrun the stack... */ FFI_ASSERT (copy_space.c >= next_arg.c); FFI_ASSERT (gpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS); - /* The assert below is testing that the number of integer arguments agrees - with the number found in ffi_prep_cif_machdep(). However, intarg_count - is incremeneted whenever we place an FP arg on the stack, so account for - that before our assert test. */ #ifndef __NO_FPRS__ - if (fparg_count > NUM_FPR_ARG_REGISTERS) - intarg_count -= fparg_count - NUM_FPR_ARG_REGISTERS; FFI_ASSERT (fpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS); #endif @@ -677,11 +664,9 @@ switch (type) { #ifndef __NO_FPRS__ -#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE case FFI_TYPE_LONGDOUBLE: flags |= FLAG_RETURNS_128BITS; /* Fall through. */ -#endif case FFI_TYPE_DOUBLE: flags |= FLAG_RETURNS_64BITS; /* Fall through. */ @@ -699,35 +684,18 @@ break; case FFI_TYPE_STRUCT: - if (cif->abi == FFI_SYSV) - { - /* The final SYSV ABI says that structures smaller or equal 8 bytes - are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them - in memory. */ - - /* Treat structs with size <= 8 bytes. */ - if (size <= 8) - { - flags |= FLAG_RETURNS_SMST; - /* These structs are returned in r3. We pack the type and the - precalculated shift value (needed in the sysv.S) into flags. - The same applies for the structs returned in r3/r4. */ - if (size <= 4) - { - flags |= FLAG_SYSV_SMST_R3; - flags |= 8 * (4 - size) << 8; - break; - } - /* These structs are returned in r3 and r4. See above. */ - if (size <= 8) - { - flags |= FLAG_SYSV_SMST_R3 | FLAG_SYSV_SMST_R4; - flags |= 8 * (8 - size) << 8; - break; - } - } - } - + /* + * The final SYSV ABI says that structures smaller or equal 8 bytes + * are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them + * in memory. + * + * NOTE: The assembly code can safely assume that it just needs to + * store both r3 and r4 into a 8-byte word-aligned buffer, as + * we allocate a temporary buffer in ffi_call() if this flag is + * set. + */ + if (cif->abi == FFI_SYSV && size <= 8) + flags |= FLAG_RETURNS_SMST; intarg_count++; flags |= FLAG_RETVAL_REFERENCE; /* Fall through. */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c --- a/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c Fri Feb 01 23:12:09 2013 +0100 @@ -302,10 +302,10 @@ } /* Check that we didn't overrun the stack... */ - /* FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS); - FFI_ASSERT((unsigned *)fpr_base - <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS); - FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4); */ + //FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS); + //FFI_ASSERT((unsigned *)fpr_base + // <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS); + //FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4); } #if defined(POWERPC_DARWIN64) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/powerpc/linux64.S --- a/Modules/_ctypes/libffi/src/powerpc/linux64.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/powerpc/linux64.S Fri Feb 01 23:12:09 2013 +0100 @@ -30,25 +30,16 @@ #include #ifdef __powerpc64__ - .hidden ffi_call_LINUX64 - .globl ffi_call_LINUX64 + .hidden ffi_call_LINUX64, .ffi_call_LINUX64 + .globl ffi_call_LINUX64, .ffi_call_LINUX64 .section ".opd","aw" .align 3 ffi_call_LINUX64: -#ifdef _CALL_LINUX - .quad .L.ffi_call_LINUX64,.TOC.@tocbase,0 - .type ffi_call_LINUX64,@function - .text -.L.ffi_call_LINUX64: -#else - .hidden .ffi_call_LINUX64 - .globl .ffi_call_LINUX64 .quad .ffi_call_LINUX64,.TOC.@tocbase,0 .size ffi_call_LINUX64,24 .type .ffi_call_LINUX64,@function .text .ffi_call_LINUX64: -#endif .LFB1: mflr %r0 std %r28, -32(%r1) @@ -67,11 +58,7 @@ /* Call ffi_prep_args64. */ mr %r4, %r1 -#ifdef _CALL_LINUX - bl ffi_prep_args64 -#else bl .ffi_prep_args64 -#endif ld %r0, 0(%r29) ld %r2, 8(%r29) @@ -150,11 +137,7 @@ .LFE1: .long 0 .byte 0,12,0,1,128,4,0,0 -#ifdef _CALL_LINUX - .size ffi_call_LINUX64,.-.L.ffi_call_LINUX64 -#else .size .ffi_call_LINUX64,.-.ffi_call_LINUX64 -#endif .section .eh_frame,EH_FRAME_FLAGS,@progbits .Lframe1: diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/powerpc/linux64_closure.S --- a/Modules/_ctypes/libffi/src/powerpc/linux64_closure.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/powerpc/linux64_closure.S Fri Feb 01 23:12:09 2013 +0100 @@ -32,24 +32,16 @@ #ifdef __powerpc64__ FFI_HIDDEN (ffi_closure_LINUX64) - .globl ffi_closure_LINUX64 + FFI_HIDDEN (.ffi_closure_LINUX64) + .globl ffi_closure_LINUX64, .ffi_closure_LINUX64 .section ".opd","aw" .align 3 ffi_closure_LINUX64: -#ifdef _CALL_LINUX - .quad .L.ffi_closure_LINUX64,.TOC.@tocbase,0 - .type ffi_closure_LINUX64,@function - .text -.L.ffi_closure_LINUX64: -#else - FFI_HIDDEN (.ffi_closure_LINUX64) - .globl .ffi_closure_LINUX64 .quad .ffi_closure_LINUX64,.TOC.@tocbase,0 .size ffi_closure_LINUX64,24 .type .ffi_closure_LINUX64,@function .text .ffi_closure_LINUX64: -#endif .LFB1: # save general regs into parm save area std %r3, 48(%r1) @@ -99,11 +91,7 @@ addi %r6, %r1, 128 # make the call -#ifdef _CALL_LINUX - bl ffi_closure_helper_LINUX64 -#else bl .ffi_closure_helper_LINUX64 -#endif .Lret: # now r3 contains the return type @@ -206,11 +194,7 @@ .LFE1: .long 0 .byte 0,12,0,1,128,0,0,0 -#ifdef _CALL_LINUX - .size ffi_closure_LINUX64,.-.L.ffi_closure_LINUX64 -#else .size .ffi_closure_LINUX64,.-.ffi_closure_LINUX64 -#endif .section .eh_frame,EH_FRAME_FLAGS,@progbits .Lframe1: diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/powerpc/sysv.S --- a/Modules/_ctypes/libffi/src/powerpc/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/powerpc/sysv.S Fri Feb 01 23:12:09 2013 +0100 @@ -142,19 +142,14 @@ #endif L(small_struct_return_value): - extrwi %r6,%r31,2,19 /* number of bytes padding = shift/8 */ - mtcrf 0x02,%r31 /* copy flags to cr[24:27] (cr6) */ - extrwi %r5,%r31,5,19 /* r5 <- number of bits of padding */ - subfic %r6,%r6,4 /* r6 <- number of useful bytes in r3 */ - bf- 25,L(done_return_value) /* struct in r3 ? if not, done. */ -/* smst_one_register: */ - slw %r3,%r3,%r5 /* Left-justify value in r3 */ - mtxer %r6 /* move byte count to XER ... */ - stswx %r3,0,%r30 /* ... and store that many bytes */ - bf+ 26,L(done_return_value) /* struct in r3:r4 ? */ - add %r6,%r6,%r30 /* adjust pointer */ - stswi %r4,%r6,4 /* store last four bytes */ - b L(done_return_value) + /* + * The C code always allocates a properly-aligned 8-byte bounce + * buffer to make this assembly code very simple. Just write out + * r3 and r4 to the buffer to allow the C code to handle the rest. + */ + stw %r3, 0(%r30) + stw %r4, 4(%r30) + b L(done_return_value) .LFE1: END(ffi_call_SYSV) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/prep_cif.c --- a/Modules/_ctypes/libffi/src/prep_cif.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/prep_cif.c Fri Feb 01 23:12:09 2013 +0100 @@ -140,13 +140,6 @@ #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) #endif -#ifdef TILE - && (cif->rtype->size > 10 * FFI_SIZEOF_ARG) -#endif -#ifdef XTENSA - && (cif->rtype->size > 16) -#endif - ) bytes = STACK_ARG_SIZE(sizeof(void*)); #endif @@ -176,20 +169,6 @@ if (((*ptr)->alignment - 1) & bytes) bytes = ALIGN(bytes, (*ptr)->alignment); -#ifdef TILE - if (bytes < 10 * FFI_SIZEOF_ARG && - bytes + STACK_ARG_SIZE((*ptr)->size) > 10 * FFI_SIZEOF_ARG) - { - /* An argument is never split between the 10 parameter - registers and the stack. */ - bytes = 10 * FFI_SIZEOF_ARG; - } -#endif -#ifdef XTENSA - if (bytes <= 6*4 && bytes + STACK_ARG_SIZE((*ptr)->size) > 6*4) - bytes = 6*4; -#endif - bytes += STACK_ARG_SIZE((*ptr)->size); } #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/s390/ffi.c --- a/Modules/_ctypes/libffi/src/s390/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/s390/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -750,8 +750,7 @@ void *user_data, void *codeloc) { - if (cif->abi != FFI_SYSV) - return FFI_BAD_ABI; + FFI_ASSERT (cif->abi == FFI_SYSV); #ifndef __s390x__ *(short *)&closure->tramp [0] = 0x0d10; /* basr %r1,0 */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/sparc/ffi.c --- a/Modules/_ctypes/libffi/src/sparc/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/sparc/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- - ffi.c - Copyright (c) 2011, 2013 Anthony Green + ffi.c - Copyright (c) 2011 Anthony Green Copyright (c) 1996, 2003-2004, 2007-2008 Red Hat, Inc. SPARC Foreign Function Interface @@ -376,10 +376,6 @@ unsigned, unsigned *, void (*fn)(void)); #endif -#ifndef __GNUC__ -void ffi_flush_icache (void *, size_t); -#endif - void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) { extended_cif ecif; @@ -421,7 +417,7 @@ /* behind "call", so we alloc some executable space for it. */ /* l7 is used, we need to make sure v8.S doesn't use %l7. */ unsigned int *call_struct = NULL; - ffi_closure_alloc(32, (void **)&call_struct); + ffi_closure_alloc(32, &call_struct); if (call_struct) { unsigned long f = (unsigned long)fn; @@ -436,14 +432,10 @@ call_struct[5] = 0x01000000; /* nop */ call_struct[6] = 0x81c7e008; /* ret */ call_struct[7] = 0xbe100017; /* mov %l7, %i7 */ -#ifdef __GNUC__ asm volatile ("iflush %0; iflush %0+8; iflush %0+16; iflush %0+24" : : "r" (call_struct) : "memory"); /* SPARC v8 requires 5 instructions for flush to be visible */ asm volatile ("nop; nop; nop; nop; nop"); -#else - ffi_flush_icache (call_struct, 32); -#endif ffi_call_v8(ffi_prep_args_v8, &ecif, cif->bytes, cif->flags, rvalue, call_struct); ffi_closure_free(call_struct); @@ -521,7 +513,6 @@ closure->user_data = user_data; /* Flush the Icache. closure is 8 bytes aligned. */ -#ifdef __GNUC__ #ifdef SPARC64 asm volatile ("flush %0; flush %0+8" : : "r" (closure) : "memory"); #else @@ -529,9 +520,6 @@ /* SPARC v8 requires 5 instructions for flush to be visible */ asm volatile ("nop; nop; nop; nop; nop"); #endif -#else - ffi_flush_icache (closure, 16); -#endif return FFI_OK; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/sparc/v8.S --- a/Modules/_ctypes/libffi/src/sparc/v8.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/sparc/v8.S Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,5 @@ /* ----------------------------------------------------------------------- - v8.S - Copyright (c) 2013 The Written Word, Inc. - Copyright (c) 1996, 1997, 2003, 2004, 2008 Red Hat, Inc. + v8.S - Copyright (c) 1996, 1997, 2003, 2004, 2008 Red Hat, Inc. SPARC Foreign Function Interface @@ -32,39 +31,11 @@ #define STACKFRAME 96 /* Minimum stack framesize for SPARC */ #define ARGS (64+4) /* Offset of register area in frame */ -#ifndef __GNUC__ - .text - .align 8 -.globl ffi_flush_icache -.globl _ffi_flush_icache - -ffi_flush_icache: -_ffi_flush_icache: - add %o0, %o1, %o2 -#ifdef SPARC64 -1: flush %o0 -#else -1: iflush %o0 -#endif - add %o0, 8, %o0 - cmp %o0, %o2 - blt 1b - nop - nop - nop - nop - nop - retl - nop -.ffi_flush_icache_end: - .size ffi_flush_icache,.ffi_flush_icache_end-ffi_flush_icache -#endif - - .text +.text .align 8 .globl ffi_call_v8 .globl _ffi_call_v8 - + ffi_call_v8: _ffi_call_v8: .LLFB1: diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/tile/ffi.c --- a/Modules/_ctypes/libffi/src/tile/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,355 +0,0 @@ -/* ----------------------------------------------------------------------- - ffi.c - Copyright (c) 2012 Tilera Corp. - - TILE Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -/* The first 10 registers are used to pass arguments and return values. */ -#define NUM_ARG_REGS 10 - -/* Performs a raw function call with the given NUM_ARG_REGS register arguments - and the specified additional stack arguments (if any). */ -extern void ffi_call_tile(ffi_sarg reg_args[NUM_ARG_REGS], - const ffi_sarg *stack_args, - size_t stack_args_bytes, - void (*fnaddr)(void)) - FFI_HIDDEN; - -/* This handles the raw call from the closure stub, cleaning up the - parameters and delegating to ffi_closure_tile_inner. */ -extern void ffi_closure_tile(void) FFI_HIDDEN; - - -ffi_status -ffi_prep_cif_machdep(ffi_cif *cif) -{ - /* We always allocate room for all registers. Even if we don't - use them as parameters, they get returned in the same array - as struct return values so we need to make room. */ - if (cif->bytes < NUM_ARG_REGS * FFI_SIZEOF_ARG) - cif->bytes = NUM_ARG_REGS * FFI_SIZEOF_ARG; - - if (cif->rtype->size > NUM_ARG_REGS * FFI_SIZEOF_ARG) - cif->flags = FFI_TYPE_STRUCT; - else - cif->flags = FFI_TYPE_INT; - - /* Nothing to do. */ - return FFI_OK; -} - - -static long -assign_to_ffi_arg(ffi_sarg *out, void *in, const ffi_type *type, - int write_to_reg) -{ - switch (type->type) - { - case FFI_TYPE_SINT8: - *out = *(SINT8 *)in; - return 1; - - case FFI_TYPE_UINT8: - *out = *(UINT8 *)in; - return 1; - - case FFI_TYPE_SINT16: - *out = *(SINT16 *)in; - return 1; - - case FFI_TYPE_UINT16: - *out = *(UINT16 *)in; - return 1; - - case FFI_TYPE_SINT32: - case FFI_TYPE_UINT32: -#ifndef __LP64__ - case FFI_TYPE_POINTER: -#endif - /* Note that even unsigned 32-bit quantities are sign extended - on tilegx when stored in a register. */ - *out = *(SINT32 *)in; - return 1; - - case FFI_TYPE_FLOAT: -#ifdef __tilegx__ - if (write_to_reg) - { - /* Properly sign extend the value. */ - union { float f; SINT32 s32; } val; - val.f = *(float *)in; - *out = val.s32; - } - else -#endif - { - *(float *)out = *(float *)in; - } - return 1; - - case FFI_TYPE_SINT64: - case FFI_TYPE_UINT64: - case FFI_TYPE_DOUBLE: -#ifdef __LP64__ - case FFI_TYPE_POINTER: -#endif - *(UINT64 *)out = *(UINT64 *)in; - return sizeof(UINT64) / FFI_SIZEOF_ARG; - - case FFI_TYPE_STRUCT: - memcpy(out, in, type->size); - return (type->size + FFI_SIZEOF_ARG - 1) / FFI_SIZEOF_ARG; - - case FFI_TYPE_VOID: - /* Must be a return type. Nothing to do. */ - return 0; - - default: - FFI_ASSERT(0); - return -1; - } -} - - -void -ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) -{ - ffi_sarg * const arg_mem = alloca(cif->bytes); - ffi_sarg * const reg_args = arg_mem; - ffi_sarg * const stack_args = ®_args[NUM_ARG_REGS]; - ffi_sarg *argp = arg_mem; - ffi_type ** const arg_types = cif->arg_types; - const long num_args = cif->nargs; - long i; - - if (cif->flags == FFI_TYPE_STRUCT) - { - /* Pass a hidden pointer to the return value. We make sure there - is scratch space for the callee to store the return value even if - our caller doesn't care about it. */ - *argp++ = (intptr_t)(rvalue ? rvalue : alloca(cif->rtype->size)); - - /* No more work needed to return anything. */ - rvalue = NULL; - } - - for (i = 0; i < num_args; i++) - { - ffi_type *type = arg_types[i]; - void * const arg_in = avalue[i]; - ptrdiff_t arg_word = argp - arg_mem; - -#ifndef __tilegx__ - /* Doubleword-aligned values are always in an even-number register - pair, or doubleword-aligned stack slot if out of registers. */ - long align = arg_word & (type->alignment > FFI_SIZEOF_ARG); - argp += align; - arg_word += align; -#endif - - if (type->type == FFI_TYPE_STRUCT) - { - const size_t arg_size_in_words = - (type->size + FFI_SIZEOF_ARG - 1) / FFI_SIZEOF_ARG; - - if (arg_word < NUM_ARG_REGS && - arg_word + arg_size_in_words > NUM_ARG_REGS) - { - /* Args are not allowed to span registers and the stack. */ - argp = stack_args; - } - - memcpy(argp, arg_in, type->size); - argp += arg_size_in_words; - } - else - { - argp += assign_to_ffi_arg(argp, arg_in, arg_types[i], 1); - } - } - - /* Actually do the call. */ - ffi_call_tile(reg_args, stack_args, - cif->bytes - (NUM_ARG_REGS * FFI_SIZEOF_ARG), fn); - - if (rvalue != NULL) - assign_to_ffi_arg(rvalue, reg_args, cif->rtype, 0); -} - - -/* Template code for closure. */ -extern const UINT64 ffi_template_tramp_tile[] FFI_HIDDEN; - - -ffi_status -ffi_prep_closure_loc (ffi_closure *closure, - ffi_cif *cif, - void (*fun)(ffi_cif*, void*, void**, void*), - void *user_data, - void *codeloc) -{ -#ifdef __tilegx__ - /* TILE-Gx */ - SINT64 c; - SINT64 h; - int s; - UINT64 *out; - - if (cif->abi != FFI_UNIX) - return FFI_BAD_ABI; - - out = (UINT64 *)closure->tramp; - - c = (intptr_t)closure; - h = (intptr_t)ffi_closure_tile; - s = 0; - - /* Find the smallest shift count that doesn't lose information - (i.e. no need to explicitly insert high bits of the address that - are just the sign extension of the low bits). */ - while ((c >> s) != (SINT16)(c >> s) || (h >> s) != (SINT16)(h >> s)) - s += 16; - -#define OPS(a, b, shift) \ - (create_Imm16_X0((a) >> (shift)) | create_Imm16_X1((b) >> (shift))) - - /* Emit the moveli. */ - *out++ = ffi_template_tramp_tile[0] | OPS(c, h, s); - for (s -= 16; s >= 0; s -= 16) - *out++ = ffi_template_tramp_tile[1] | OPS(c, h, s); - -#undef OPS - - *out++ = ffi_template_tramp_tile[2]; - -#else - /* TILEPro */ - UINT64 *out; - intptr_t delta; - - if (cif->abi != FFI_UNIX) - return FFI_BAD_ABI; - - out = (UINT64 *)closure->tramp; - delta = (intptr_t)ffi_closure_tile - (intptr_t)codeloc; - - *out++ = ffi_template_tramp_tile[0] | create_JOffLong_X1(delta >> 3); -#endif - - closure->cif = cif; - closure->fun = fun; - closure->user_data = user_data; - - invalidate_icache(closure->tramp, (char *)out - closure->tramp, - getpagesize()); - - return FFI_OK; -} - - -/* This is called by the assembly wrapper for closures. This does - all of the work. On entry reg_args[0] holds the values the registers - had when the closure was invoked. On return reg_args[1] holds the register - values to be returned to the caller (many of which may be garbage). */ -void FFI_HIDDEN -ffi_closure_tile_inner(ffi_closure *closure, - ffi_sarg reg_args[2][NUM_ARG_REGS], - ffi_sarg *stack_args) -{ - ffi_cif * const cif = closure->cif; - void ** const avalue = alloca(cif->nargs * sizeof(void *)); - void *rvalue; - ffi_type ** const arg_types = cif->arg_types; - ffi_sarg * const reg_args_in = reg_args[0]; - ffi_sarg * const reg_args_out = reg_args[1]; - ffi_sarg * argp; - long i, arg_word, nargs = cif->nargs; - /* Use a union to guarantee proper alignment for double. */ - union { ffi_sarg arg[NUM_ARG_REGS]; double d; UINT64 u64; } closure_ret; - - /* Start out reading register arguments. */ - argp = reg_args_in; - - /* Copy the caller's structure return address to that the closure - returns the data directly to the caller. */ - if (cif->flags == FFI_TYPE_STRUCT) - { - /* Return by reference via hidden pointer. */ - rvalue = (void *)(intptr_t)*argp++; - arg_word = 1; - } - else - { - /* Return the value in registers. */ - rvalue = &closure_ret; - arg_word = 0; - } - - /* Grab the addresses of the arguments. */ - for (i = 0; i < nargs; i++) - { - ffi_type * const type = arg_types[i]; - const size_t arg_size_in_words = - (type->size + FFI_SIZEOF_ARG - 1) / FFI_SIZEOF_ARG; - -#ifndef __tilegx__ - /* Doubleword-aligned values are always in an even-number register - pair, or doubleword-aligned stack slot if out of registers. */ - long align = arg_word & (type->alignment > FFI_SIZEOF_ARG); - argp += align; - arg_word += align; -#endif - - if (arg_word == NUM_ARG_REGS || - (arg_word < NUM_ARG_REGS && - arg_word + arg_size_in_words > NUM_ARG_REGS)) - { - /* Switch to reading arguments from the stack. */ - argp = stack_args; - arg_word = NUM_ARG_REGS; - } - - avalue[i] = argp; - argp += arg_size_in_words; - arg_word += arg_size_in_words; - } - - /* Invoke the closure. */ - closure->fun(cif, rvalue, avalue, closure->user_data); - - if (cif->flags != FFI_TYPE_STRUCT) - { - /* Canonicalize for register representation. */ - assign_to_ffi_arg(reg_args_out, &closure_ret, cif->rtype, 1); - } -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/tile/ffitarget.h --- a/Modules/_ctypes/libffi/src/tile/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* -----------------------------------------------------------------*-C-*- - ffitarget.h - Copyright (c) 2012 Tilera Corp. - Target configuration macros for TILE. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -#ifndef LIBFFI_H -#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." -#endif - -#ifndef LIBFFI_ASM - -#include - -typedef uint_reg_t ffi_arg; -typedef int_reg_t ffi_sarg; - -typedef enum ffi_abi { - FFI_FIRST_ABI = 0, - FFI_UNIX, - FFI_LAST_ABI, - FFI_DEFAULT_ABI = FFI_UNIX -} ffi_abi; -#endif - -/* ---- Definitions for closures ----------------------------------------- */ -#define FFI_CLOSURES 1 - -#ifdef __tilegx__ -/* We always pass 8-byte values, even in -m32 mode. */ -# define FFI_SIZEOF_ARG 8 -# ifdef __LP64__ -# define FFI_TRAMPOLINE_SIZE (8 * 5) /* 5 bundles */ -# else -# define FFI_TRAMPOLINE_SIZE (8 * 3) /* 3 bundles */ -# endif -#else -# define FFI_SIZEOF_ARG 4 -# define FFI_TRAMPOLINE_SIZE 8 /* 1 bundle */ -#endif -#define FFI_NATIVE_RAW_API 0 - -#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/tile/tile.S --- a/Modules/_ctypes/libffi/src/tile/tile.S Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,360 +0,0 @@ -/* ----------------------------------------------------------------------- - tile.S - Copyright (c) 2011 Tilera Corp. - - Tilera TILEPro and TILE-Gx Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#define LIBFFI_ASM -#include -#include - -/* Number of bytes in a register. */ -#define REG_SIZE FFI_SIZEOF_ARG - -/* Number of bytes in stack linkage area for backtracing. - - A note about the ABI: on entry to a procedure, sp points to a stack - slot where it must spill the return address if it's not a leaf. - REG_SIZE bytes beyond that is a slot owned by the caller which - contains the sp value that the caller had when it was originally - entered (i.e. the caller's frame pointer). */ -#define LINKAGE_SIZE (2 * REG_SIZE) - -/* The first 10 registers are used to pass arguments and return values. */ -#define NUM_ARG_REGS 10 - -#ifdef __tilegx__ -#define SW st -#define LW ld -#define BGZT bgtzt -#else -#define SW sw -#define LW lw -#define BGZT bgzt -#endif - - -/* void ffi_call_tile (int_reg_t reg_args[NUM_ARG_REGS], - const int_reg_t *stack_args, - unsigned long stack_args_bytes, - void (*fnaddr)(void)); - - On entry, REG_ARGS contain the outgoing register values, - and STACK_ARGS containts STACK_ARG_BYTES of additional values - to be passed on the stack. If STACK_ARG_BYTES is zero, then - STACK_ARGS is ignored. - - When the invoked function returns, the values of r0-r9 are - blindly stored back into REG_ARGS for the caller to examine. */ - - .section .text.ffi_call_tile, "ax", @progbits - .align 8 - .globl ffi_call_tile - FFI_HIDDEN(ffi_call_tile) -ffi_call_tile: - -/* Incoming arguments. */ -#define REG_ARGS r0 -#define INCOMING_STACK_ARGS r1 -#define STACK_ARG_BYTES r2 -#define ORIG_FNADDR r3 - -/* Temporary values. */ -#define FRAME_SIZE r10 -#define TMP r11 -#define TMP2 r12 -#define OUTGOING_STACK_ARGS r13 -#define REG_ADDR_PTR r14 -#define RETURN_REG_ADDR r15 -#define FNADDR r16 - - .cfi_startproc - { - /* Save return address. */ - SW sp, lr - .cfi_offset lr, 0 - /* Prepare to spill incoming r52. */ - addi TMP, sp, -REG_SIZE - /* Increase frame size to have room to spill r52 and REG_ARGS. - The +7 is to round up mod 8. */ - addi FRAME_SIZE, STACK_ARG_BYTES, \ - REG_SIZE + REG_SIZE + LINKAGE_SIZE + 7 - } - { - /* Round stack frame size to a multiple of 8 to satisfy ABI. */ - andi FRAME_SIZE, FRAME_SIZE, -8 - /* Compute where to spill REG_ARGS value. */ - addi TMP2, sp, -(REG_SIZE * 2) - } - { - /* Spill incoming r52. */ - SW TMP, r52 - .cfi_offset r52, -REG_SIZE - /* Set up our frame pointer. */ - move r52, sp - .cfi_def_cfa_register r52 - /* Push stack frame. */ - sub sp, sp, FRAME_SIZE - } - { - /* Prepare to set up stack linkage. */ - addi TMP, sp, REG_SIZE - /* Prepare to memcpy stack args. */ - addi OUTGOING_STACK_ARGS, sp, LINKAGE_SIZE - /* Save REG_ARGS which we will need after we call the subroutine. */ - SW TMP2, REG_ARGS - } - { - /* Set up linkage info to hold incoming stack pointer. */ - SW TMP, r52 - } - { - /* Skip stack args memcpy if we don't have any stack args (common). */ - blezt STACK_ARG_BYTES, .Ldone_stack_args_memcpy - } - -.Lmemcpy_stack_args: - { - /* Load incoming argument from stack_args. */ - LW TMP, INCOMING_STACK_ARGS - addi INCOMING_STACK_ARGS, INCOMING_STACK_ARGS, REG_SIZE - } - { - /* Store stack argument into outgoing stack argument area. */ - SW OUTGOING_STACK_ARGS, TMP - addi OUTGOING_STACK_ARGS, OUTGOING_STACK_ARGS, REG_SIZE - addi STACK_ARG_BYTES, STACK_ARG_BYTES, -REG_SIZE - } - { - BGZT STACK_ARG_BYTES, .Lmemcpy_stack_args - } -.Ldone_stack_args_memcpy: - - { - /* Copy aside ORIG_FNADDR so we can overwrite its register. */ - move FNADDR, ORIG_FNADDR - /* Prepare to load argument registers. */ - addi REG_ADDR_PTR, r0, REG_SIZE - /* Load outgoing r0. */ - LW r0, r0 - } - - /* Load up argument registers from the REG_ARGS array. */ -#define LOAD_REG(REG, PTR) \ - { \ - LW REG, PTR ; \ - addi PTR, PTR, REG_SIZE \ - } - - LOAD_REG(r1, REG_ADDR_PTR) - LOAD_REG(r2, REG_ADDR_PTR) - LOAD_REG(r3, REG_ADDR_PTR) - LOAD_REG(r4, REG_ADDR_PTR) - LOAD_REG(r5, REG_ADDR_PTR) - LOAD_REG(r6, REG_ADDR_PTR) - LOAD_REG(r7, REG_ADDR_PTR) - LOAD_REG(r8, REG_ADDR_PTR) - LOAD_REG(r9, REG_ADDR_PTR) - - { - /* Call the subroutine. */ - jalr FNADDR - } - - { - /* Restore original lr. */ - LW lr, r52 - /* Prepare to recover ARGS, which we spilled earlier. */ - addi TMP, r52, -(2 * REG_SIZE) - } - { - /* Restore ARGS, so we can fill it in with the return regs r0-r9. */ - LW RETURN_REG_ADDR, TMP - /* Prepare to restore original r52. */ - addi TMP, r52, -REG_SIZE - } - - { - /* Pop stack frame. */ - move sp, r52 - /* Restore original r52. */ - LW r52, TMP - } - -#define STORE_REG(REG, PTR) \ - { \ - SW PTR, REG ; \ - addi PTR, PTR, REG_SIZE \ - } - - /* Return all register values by reference. */ - STORE_REG(r0, RETURN_REG_ADDR) - STORE_REG(r1, RETURN_REG_ADDR) - STORE_REG(r2, RETURN_REG_ADDR) - STORE_REG(r3, RETURN_REG_ADDR) - STORE_REG(r4, RETURN_REG_ADDR) - STORE_REG(r5, RETURN_REG_ADDR) - STORE_REG(r6, RETURN_REG_ADDR) - STORE_REG(r7, RETURN_REG_ADDR) - STORE_REG(r8, RETURN_REG_ADDR) - STORE_REG(r9, RETURN_REG_ADDR) - - { - jrp lr - } - - .cfi_endproc - .size ffi_call_tile, .-ffi_call_tile - -/* ffi_closure_tile(...) - - On entry, lr points to the closure plus 8 bytes, and r10 - contains the actual return address. - - This function simply dumps all register parameters into a stack array - and passes the closure, the registers array, and the stack arguments - to C code that does all of the actual closure processing. */ - - .section .text.ffi_closure_tile, "ax", @progbits - .align 8 - .globl ffi_closure_tile - FFI_HIDDEN(ffi_closure_tile) - - .cfi_startproc -/* Room to spill all NUM_ARG_REGS incoming registers, plus frame linkage. */ -#define CLOSURE_FRAME_SIZE (((NUM_ARG_REGS * REG_SIZE * 2 + LINKAGE_SIZE) + 7) & -8) -ffi_closure_tile: - { -#ifdef __tilegx__ - st sp, lr - .cfi_offset lr, 0 -#else - /* Save return address (in r10 due to closure stub wrapper). */ - SW sp, r10 - .cfi_return_column r10 - .cfi_offset r10, 0 -#endif - /* Compute address for stack frame linkage. */ - addli r10, sp, -(CLOSURE_FRAME_SIZE - REG_SIZE) - } - { - /* Save incoming stack pointer in linkage area. */ - SW r10, sp - .cfi_offset sp, -(CLOSURE_FRAME_SIZE - REG_SIZE) - /* Push a new stack frame. */ - addli sp, sp, -CLOSURE_FRAME_SIZE - .cfi_adjust_cfa_offset CLOSURE_FRAME_SIZE - } - - { - /* Create pointer to where to start spilling registers. */ - addi r10, sp, LINKAGE_SIZE - } - - /* Spill all the incoming registers. */ - STORE_REG(r0, r10) - STORE_REG(r1, r10) - STORE_REG(r2, r10) - STORE_REG(r3, r10) - STORE_REG(r4, r10) - STORE_REG(r5, r10) - STORE_REG(r6, r10) - STORE_REG(r7, r10) - STORE_REG(r8, r10) - { - /* Save r9. */ - SW r10, r9 -#ifdef __tilegx__ - /* Pointer to closure is passed in r11. */ - move r0, r11 -#else - /* Compute pointer to the closure object. Because the closure - starts with a "jal ffi_closure_tile", we can just take the - value of lr (a phony return address pointing into the closure) - and subtract 8. */ - addi r0, lr, -8 -#endif - /* Compute a pointer to the register arguments we just spilled. */ - addi r1, sp, LINKAGE_SIZE - } - { - /* Compute a pointer to the extra stack arguments (if any). */ - addli r2, sp, CLOSURE_FRAME_SIZE + LINKAGE_SIZE - /* Call C code to deal with all of the grotty details. */ - jal ffi_closure_tile_inner - } - { - addli r10, sp, CLOSURE_FRAME_SIZE - } - { - /* Restore the return address. */ - LW lr, r10 - /* Compute pointer to registers array. */ - addli r10, sp, LINKAGE_SIZE + (NUM_ARG_REGS * REG_SIZE) - } - /* Return all the register values, which C code may have set. */ - LOAD_REG(r0, r10) - LOAD_REG(r1, r10) - LOAD_REG(r2, r10) - LOAD_REG(r3, r10) - LOAD_REG(r4, r10) - LOAD_REG(r5, r10) - LOAD_REG(r6, r10) - LOAD_REG(r7, r10) - LOAD_REG(r8, r10) - LOAD_REG(r9, r10) - { - /* Pop the frame. */ - addli sp, sp, CLOSURE_FRAME_SIZE - jrp lr - } - - .cfi_endproc - .size ffi_closure_tile, . - ffi_closure_tile - - -/* What follows are code template instructions that get copied to the - closure trampoline by ffi_prep_closure_loc. The zeroed operands - get replaced by their proper values at runtime. */ - - .section .text.ffi_template_tramp_tile, "ax", @progbits - .align 8 - .globl ffi_template_tramp_tile - FFI_HIDDEN(ffi_template_tramp_tile) -ffi_template_tramp_tile: -#ifdef __tilegx__ - { - moveli r11, 0 /* backpatched to address of containing closure. */ - moveli r10, 0 /* backpatched to ffi_closure_tile. */ - } - /* Note: the following bundle gets generated multiple times - depending on the pointer value (esp. useful for -m32 mode). */ - { shl16insli r11, r11, 0 ; shl16insli r10, r10, 0 } - { info 2+8 /* for backtracer: -> pc in lr, frame size 0 */ ; jr r10 } -#else - /* 'jal .' yields a PC-relative offset of zero so we can OR in the - right offset at runtime. */ - { move r10, lr ; jal . /* ffi_closure_tile */ } -#endif - - .size ffi_template_tramp_tile, . - ffi_template_tramp_tile diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/x86/ffi.c --- a/Modules/_ctypes/libffi/src/x86/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/x86/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -315,7 +315,9 @@ cif->bytes += 4 * sizeof(ffi_arg); #endif +#ifdef X86_DARWIN cif->bytes = (cif->bytes + 15) & ~0xF; +#endif return FFI_OK; } @@ -422,7 +424,7 @@ /** private members **/ /* The following __attribute__((regparm(1))) decorations will have no effect - on MSVC or SUNPRO_C -- standard conventions apply. */ + on MSVC - standard cdecl convention applies. */ static void ffi_prep_incoming_args_SYSV (char *stack, void **ret, void** args, ffi_cif* cif); void FFI_HIDDEN ffi_closure_SYSV (ffi_closure *) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/x86/ffi64.c --- a/Modules/_ctypes/libffi/src/x86/ffi64.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/x86/ffi64.c Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,5 @@ /* ----------------------------------------------------------------------- - ffi64.c - Copyright (c) 2013 The Written Word, Inc. - Copyright (c) 2011 Anthony Green + ffi64.c - Copyright (c) 20011 Anthony Green Copyright (c) 2008, 2010 Red Hat, Inc. Copyright (c) 2002, 2007 Bo Thorsen @@ -38,29 +37,17 @@ #define MAX_GPR_REGS 6 #define MAX_SSE_REGS 8 -#if defined(__INTEL_COMPILER) +#ifdef __INTEL_COMPILER #define UINT128 __m128 #else -#if defined(__SUNPRO_C) -#include -#define UINT128 __m128i -#else #define UINT128 __int128_t #endif -#endif - -union big_int_union -{ - UINT32 i32; - UINT64 i64; - UINT128 i128; -}; struct register_args { /* Registers for argument passing. */ UINT64 gpr[MAX_GPR_REGS]; - union big_int_union sse[MAX_SSE_REGS]; + UINT128 sse[MAX_SSE_REGS]; }; extern void ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags, @@ -484,33 +471,16 @@ { case X86_64_INTEGER_CLASS: case X86_64_INTEGERSI_CLASS: - /* Sign-extend integer arguments passed in general - purpose registers, to cope with the fact that - LLVM incorrectly assumes that this will be done - (the x86-64 PS ABI does not specify this). */ - switch (arg_types[i]->type) - { - case FFI_TYPE_SINT8: - *(SINT64 *)®_args->gpr[gprcount] = (SINT64) *((SINT8 *) a); - break; - case FFI_TYPE_SINT16: - *(SINT64 *)®_args->gpr[gprcount] = (SINT64) *((SINT16 *) a); - break; - case FFI_TYPE_SINT32: - *(SINT64 *)®_args->gpr[gprcount] = (SINT64) *((SINT32 *) a); - break; - default: - reg_args->gpr[gprcount] = 0; - memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); - } + reg_args->gpr[gprcount] = 0; + memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); gprcount++; break; case X86_64_SSE_CLASS: case X86_64_SSEDF_CLASS: - reg_args->sse[ssecount++].i64 = *(UINT64 *) a; + reg_args->sse[ssecount++] = *(UINT64 *) a; break; case X86_64_SSESF_CLASS: - reg_args->sse[ssecount++].i32 = *(UINT32 *) a; + reg_args->sse[ssecount++] = *(UINT32 *) a; break; default: abort(); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/x86/ffitarget.h --- a/Modules/_ctypes/libffi/src/x86/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/x86/ffitarget.h Fri Feb 01 23:12:09 2013 +0100 @@ -61,9 +61,8 @@ typedef long long ffi_sarg; #endif #else -#if defined __x86_64__ && defined __ILP32__ +#if defined __x86_64__ && !defined __LP64__ #define FFI_SIZEOF_ARG 8 -#define FFI_SIZEOF_JAVA_RAW 4 typedef unsigned long long ffi_arg; typedef long long ffi_sarg; #else diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/x86/sysv.S --- a/Modules/_ctypes/libffi/src/x86/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/x86/sysv.S Fri Feb 01 23:12:09 2013 +0100 @@ -1,6 +1,5 @@ /* ----------------------------------------------------------------------- - sysv.S - Copyright (c) 2013 The Written Word, Inc. - - Copyright (c) 1996,1998,2001-2003,2005,2008,2010 Red Hat, Inc. + sysv.S - Copyright (c) 1996, 1998, 2001-2003, 2005, 2008, 2010 Red Hat, Inc. X86 Foreign Function Interface @@ -182,19 +181,9 @@ leal -24(%ebp), %edx movl %edx, -12(%ebp) /* resp */ leal 8(%ebp), %edx -#ifdef __SUNPRO_C - /* The SUNPRO compiler doesn't support GCC's regparm function - attribute, so we have to pass all three arguments to - ffi_closure_SYSV_inner on the stack. */ - movl %edx, 8(%esp) /* args = __builtin_dwarf_cfa () */ - leal -12(%ebp), %edx - movl %edx, 4(%esp) /* &resp */ - movl %eax, (%esp) /* closure */ -#else movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */ leal -12(%ebp), %edx movl %edx, (%esp) /* &resp */ -#endif #if defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE || !defined __PIC__ call ffi_closure_SYSV_inner #else @@ -339,9 +328,6 @@ .size ffi_closure_raw_SYSV, .-ffi_closure_raw_SYSV #endif -#if defined __GNUC__ -/* Only emit dwarf unwind info when building with GNU toolchain. */ - #if defined __PIC__ # if defined __sun__ && defined __svr4__ /* 32-bit Solaris 2/x86 uses datarel encoding for PIC. GNU ld before 2.22 @@ -474,7 +460,6 @@ .LEFDE3: #endif -#endif #endif /* ifndef __x86_64__ */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/x86/unix64.S --- a/Modules/_ctypes/libffi/src/x86/unix64.S Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/src/x86/unix64.S Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,6 @@ /* ----------------------------------------------------------------------- - unix64.S - Copyright (c) 2013 The Written Word, Inc. - - Copyright (c) 2008 Red Hat, Inc - - Copyright (c) 2002 Bo Thorsen + unix64.S - Copyright (c) 2002 Bo Thorsen + Copyright (c) 2008 Red Hat, Inc x86-64 Foreign Function Interface @@ -325,9 +324,6 @@ .LUW9: .size ffi_closure_unix64,.-ffi_closure_unix64 -#ifdef __GNUC__ -/* Only emit DWARF unwind info when building with the GNU toolchain. */ - #ifdef HAVE_AS_X86_64_UNWIND_SECTION_TYPE .section .eh_frame,"a",@unwind #else @@ -423,8 +419,6 @@ .align 8 .LEFDE3: -#endif /* __GNUC__ */ - #endif /* __x86_64__ */ #if defined __ELF__ && defined __linux__ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/xtensa/ffi.c --- a/Modules/_ctypes/libffi/src/xtensa/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,298 +0,0 @@ -/* ----------------------------------------------------------------------- - ffi.c - Copyright (c) 2013 Tensilica, Inc. - - XTENSA Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#include -#include - -/* - |----------------------------------------| - | | - on entry to ffi_call ----> |----------------------------------------| - | caller stack frame for registers a0-a3 | - |----------------------------------------| - | | - | additional arguments | - entry of the function ---> |----------------------------------------| - | copy of function arguments a2-a7 | - | - - - - - - - - - - - - - | - | | - - The area below the entry line becomes the new stack frame for the function. - -*/ - - -#define FFI_TYPE_STRUCT_REGS FFI_TYPE_LAST - - -extern void ffi_call_SYSV(void *rvalue, unsigned rsize, unsigned flags, - void(*fn)(void), unsigned nbytes, extended_cif*); -extern void ffi_closure_SYSV(void) FFI_HIDDEN; - -ffi_status ffi_prep_cif_machdep(ffi_cif *cif) -{ - switch(cif->rtype->type) { - case FFI_TYPE_SINT8: - case FFI_TYPE_UINT8: - case FFI_TYPE_SINT16: - case FFI_TYPE_UINT16: - cif->flags = cif->rtype->type; - break; - case FFI_TYPE_VOID: - case FFI_TYPE_FLOAT: - cif->flags = FFI_TYPE_UINT32; - break; - case FFI_TYPE_DOUBLE: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - cif->flags = FFI_TYPE_UINT64; // cif->rtype->type; - break; - case FFI_TYPE_STRUCT: - cif->flags = FFI_TYPE_STRUCT; //_REGS; - /* Up to 16 bytes are returned in registers */ - if (cif->rtype->size > 4 * 4) { - /* returned structure is referenced by a register; use 8 bytes - (including 4 bytes for potential additional alignment) */ - cif->flags = FFI_TYPE_STRUCT; - cif->bytes += 8; - } - break; - - default: - cif->flags = FFI_TYPE_UINT32; - break; - } - - /* Round the stack up to a full 4 register frame, just in case - (we use this size in movsp). This way, it's also a multiple of - 8 bytes for 64-bit arguments. */ - cif->bytes = ALIGN(cif->bytes, 16); - - return FFI_OK; -} - -void ffi_prep_args(extended_cif *ecif, unsigned char* stack) -{ - unsigned int i; - unsigned long *addr; - ffi_type **ptr; - - union { - void **v; - char **c; - signed char **sc; - unsigned char **uc; - signed short **ss; - unsigned short **us; - unsigned int **i; - long long **ll; - float **f; - double **d; - } p_argv; - - /* Verify that everything is aligned up properly */ - FFI_ASSERT (((unsigned long) stack & 0x7) == 0); - - p_argv.v = ecif->avalue; - addr = (unsigned long*)stack; - - /* structures with a size greater than 16 bytes are passed in memory */ - if (ecif->cif->rtype->type == FFI_TYPE_STRUCT && ecif->cif->rtype->size > 16) - { - *addr++ = (unsigned long)ecif->rvalue; - } - - for (i = ecif->cif->nargs, ptr = ecif->cif->arg_types; - i > 0; - i--, ptr++, p_argv.v++) - { - switch ((*ptr)->type) - { - case FFI_TYPE_SINT8: - *addr++ = **p_argv.sc; - break; - case FFI_TYPE_UINT8: - *addr++ = **p_argv.uc; - break; - case FFI_TYPE_SINT16: - *addr++ = **p_argv.ss; - break; - case FFI_TYPE_UINT16: - *addr++ = **p_argv.us; - break; - case FFI_TYPE_FLOAT: - case FFI_TYPE_INT: - case FFI_TYPE_UINT32: - case FFI_TYPE_SINT32: - case FFI_TYPE_POINTER: - *addr++ = **p_argv.i; - break; - case FFI_TYPE_DOUBLE: - case FFI_TYPE_UINT64: - case FFI_TYPE_SINT64: - if (((unsigned long)addr & 4) != 0) - addr++; - *(unsigned long long*)addr = **p_argv.ll; - addr += sizeof(unsigned long long) / sizeof (addr); - break; - - case FFI_TYPE_STRUCT: - { - unsigned long offs; - unsigned long size; - - if (((unsigned long)addr & 4) != 0 && (*ptr)->alignment > 4) - addr++; - - offs = (unsigned long) addr - (unsigned long) stack; - size = (*ptr)->size; - - /* Entire structure must fit the argument registers or referenced */ - if (offs < FFI_REGISTER_NARGS * 4 - && offs + size > FFI_REGISTER_NARGS * 4) - addr = (unsigned long*) (stack + FFI_REGISTER_NARGS * 4); - - memcpy((char*) addr, *p_argv.c, size); - addr += (size + 3) / 4; - break; - } - - default: - FFI_ASSERT(0); - } - } -} - - -void ffi_call(ffi_cif* cif, void(*fn)(void), void *rvalue, void **avalue) -{ - extended_cif ecif; - unsigned long rsize = cif->rtype->size; - int flags = cif->flags; - void *alloc = NULL; - - ecif.cif = cif; - ecif.avalue = avalue; - - /* Note that for structures that are returned in registers (size <= 16 bytes) - we allocate a temporary buffer and use memcpy to copy it to the final - destination. The reason is that the target address might be misaligned or - the length not a multiple of 4 bytes. Handling all those cases would be - very complex. */ - - if (flags == FFI_TYPE_STRUCT && (rsize <= 16 || rvalue == NULL)) - { - alloc = alloca(ALIGN(rsize, 4)); - ecif.rvalue = alloc; - } - else - { - ecif.rvalue = rvalue; - } - - if (cif->abi != FFI_SYSV) - FFI_ASSERT(0); - - ffi_call_SYSV (ecif.rvalue, rsize, cif->flags, fn, cif->bytes, &ecif); - - if (alloc != NULL && rvalue != NULL) - memcpy(rvalue, alloc, rsize); -} - -extern void ffi_trampoline(); -extern void ffi_cacheflush(void* start, void* end); - -ffi_status -ffi_prep_closure_loc (ffi_closure* closure, - ffi_cif* cif, - void (*fun)(ffi_cif*, void*, void**, void*), - void *user_data, - void *codeloc) -{ - /* copye trampoline to stack and patch 'ffi_closure_SYSV' pointer */ - memcpy(closure->tramp, ffi_trampoline, FFI_TRAMPOLINE_SIZE); - *(unsigned int*)(&closure->tramp[8]) = (unsigned int)ffi_closure_SYSV; - - // Do we have this function? - // __builtin___clear_cache(closer->tramp, closer->tramp + FFI_TRAMPOLINE_SIZE) - ffi_cacheflush(closure->tramp, closure->tramp + FFI_TRAMPOLINE_SIZE); - - closure->cif = cif; - closure->fun = fun; - closure->user_data = user_data; - return FFI_OK; -} - - -long FFI_HIDDEN -ffi_closure_SYSV_inner(ffi_closure *closure, void **values, void *rvalue) -{ - ffi_cif *cif; - ffi_type **arg_types; - void **avalue; - int i, areg; - - cif = closure->cif; - if (cif->abi != FFI_SYSV) - return FFI_BAD_ABI; - - areg = 0; - - int rtype = cif->rtype->type; - if (rtype == FFI_TYPE_STRUCT && cif->rtype->size > 4 * 4) - { - rvalue = *values; - areg++; - } - - cif = closure->cif; - arg_types = cif->arg_types; - avalue = alloca(cif->nargs * sizeof(void *)); - - for (i = 0; i < cif->nargs; i++) - { - if (arg_types[i]->alignment == 8 && (areg & 1) != 0) - areg++; - - // skip the entry 16,a1 framework, add 16 bytes (4 registers) - if (areg == FFI_REGISTER_NARGS) - areg += 4; - - if (arg_types[i]->type == FFI_TYPE_STRUCT) - { - int numregs = ((arg_types[i]->size + 3) & ~3) / 4; - if (areg < FFI_REGISTER_NARGS && areg + numregs > FFI_REGISTER_NARGS) - areg = FFI_REGISTER_NARGS + 4; - } - - avalue[i] = &values[areg]; - areg += (arg_types[i]->size + 3) / 4; - } - - (closure->fun)(cif, rvalue, avalue, closure->user_data); - - return rtype; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/xtensa/ffitarget.h --- a/Modules/_ctypes/libffi/src/xtensa/ffitarget.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* -----------------------------------------------------------------*-C-*- - ffitarget.h - Copyright (c) 2013 Tensilica, Inc. - Target configuration macros for XTENSA. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#ifndef LIBFFI_TARGET_H -#define LIBFFI_TARGET_H - -#ifndef LIBFFI_H -#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." -#endif - -#ifndef LIBFFI_ASM -typedef unsigned long ffi_arg; -typedef signed long ffi_sarg; - -typedef enum ffi_abi { - FFI_FIRST_ABI = 0, - FFI_SYSV, - FFI_LAST_ABI, - FFI_DEFAULT_ABI = FFI_SYSV -} ffi_abi; -#endif - -#define FFI_REGISTER_NARGS 6 - -/* ---- Definitions for closures ----------------------------------------- */ - -#define FFI_CLOSURES 1 -#define FFI_NATIVE_RAW_API 0 -#define FFI_TRAMPOLINE_SIZE 24 - -#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/src/xtensa/sysv.S --- a/Modules/_ctypes/libffi/src/xtensa/sysv.S Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,253 +0,0 @@ -/* ----------------------------------------------------------------------- - sysv.S - Copyright (c) 2013 Tensilica, Inc. - - XTENSA Foreign Function Interface - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - ``Software''), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - ----------------------------------------------------------------------- */ - -#define LIBFFI_ASM -#include -#include - -#define ENTRY(name) .text; .globl name; .type name,@function; .align 4; name: -#define END(name) .size name , . - name - -/* Assert that the table below is in sync with ffi.h. */ - -#if FFI_TYPE_UINT8 != 5 \ - || FFI_TYPE_SINT8 != 6 \ - || FFI_TYPE_UINT16 != 7 \ - || FFI_TYPE_SINT16 != 8 \ - || FFI_TYPE_UINT32 != 9 \ - || FFI_TYPE_SINT32 != 10 \ - || FFI_TYPE_UINT64 != 11 -#error "xtensa/sysv.S out of sync with ffi.h" -#endif - - -/* ffi_call_SYSV (rvalue, rbytes, flags, (*fnaddr)(), bytes, ecif) - void *rvalue; a2 - unsigned long rbytes; a3 - unsigned flags; a4 - void (*fnaddr)(); a5 - unsigned long bytes; a6 - extended_cif* ecif) a7 -*/ - -ENTRY(ffi_call_SYSV) - - entry a1, 32 # 32 byte frame for using call8 below - - mov a10, a7 # a10(->arg0): ecif - sub a11, a1, a6 # a11(->arg1): stack pointer - mov a7, a1 # fp - movsp a1, a11 # set new sp = old_sp - bytes - - movi a8, ffi_prep_args - callx8 a8 # ffi_prep_args(ecif, stack) - - # prepare to move stack pointer back up to 6 arguments - # note that 'bytes' is already aligned - - movi a10, 6*4 - sub a11, a6, a10 - movgez a6, a10, a11 - add a6, a1, a6 - - - # we can pass up to 6 arguments in registers - # for simplicity, just load 6 arguments - # (the stack size is at least 32 bytes, so no risk to cross boundaries) - - l32i a10, a1, 0 - l32i a11, a1, 4 - l32i a12, a1, 8 - l32i a13, a1, 12 - l32i a14, a1, 16 - l32i a15, a1, 20 - - # move stack pointer - - movsp a1, a6 - - callx8 a5 # (*fn)(args...) - - # Handle return value(s) - - beqz a2, .Lexit - - movi a5, FFI_TYPE_STRUCT - bne a4, a5, .Lstore - movi a5, 16 - blt a5, a3, .Lexit - - s32i a10, a2, 0 - blti a3, 5, .Lexit - addi a3, a3, -1 - s32i a11, a2, 4 - blti a3, 8, .Lexit - s32i a12, a2, 8 - blti a3, 12, .Lexit - s32i a13, a2, 12 - -.Lexit: retw - -.Lstore: - addi a4, a4, -FFI_TYPE_UINT8 - bgei a4, 7, .Lexit # should never happen - movi a6, store_calls - add a4, a4, a4 - addx4 a6, a4, a6 # store_table + idx * 8 - jx a6 - - .align 8 -store_calls: - # UINT8 - s8i a10, a2, 0 - retw - - # SINT8 - .align 8 - s8i a10, a2, 0 - retw - - # UINT16 - .align 8 - s16i a10, a2, 0 - retw - - # SINT16 - .align 8 - s16i a10, a2, 0 - retw - - # UINT32 - .align 8 - s32i a10, a2, 0 - retw - - # SINT32 - .align 8 - s32i a10, a2, 0 - retw - - # UINT64 - .align 8 - s32i a10, a2, 0 - s32i a11, a2, 4 - retw - -END(ffi_call_SYSV) - - -/* - * void ffi_cacheflush (unsigned long start, unsigned long end) - */ - -#define EXTRA_ARGS_SIZE 24 - -ENTRY(ffi_cacheflush) - - entry a1, 16 - -1: dhwbi a2, 0 - ihi a2, 0 - addi a2, a2, 4 - blt a2, a3, 1b - - retw - -END(ffi_cacheflush) - -/* ffi_trampoline is copied to the stack */ - -ENTRY(ffi_trampoline) - - entry a1, 16 + (FFI_REGISTER_NARGS * 4) + (4 * 4) # [ 0] - j 2f # [ 3] - .align 4 # [ 6] -1: .long 0 # [ 8] -2: l32r a15, 1b # [12] - _mov a14, a0 # [15] - callx0 a15 # [18] - # [21] -END(ffi_trampoline) - -/* - * ffi_closure() - * - * a0: closure + 21 - * a14: return address (a0) - */ - -ENTRY(ffi_closure_SYSV) - - /* intentionally omitting entry here */ - - # restore return address (a0) and move pointer to closure to a10 - addi a10, a0, -21 - mov a0, a14 - - # allow up to 4 arguments as return values - addi a11, a1, 4 * 4 - - # save up to 6 arguments to stack (allocated by entry below) - s32i a2, a11, 0 - s32i a3, a11, 4 - s32i a4, a11, 8 - s32i a5, a11, 12 - s32i a6, a11, 16 - s32i a7, a11, 20 - - movi a8, ffi_closure_SYSV_inner - mov a12, a1 - callx8 a8 # .._inner(*closure, **avalue, *rvalue) - - # load up to four return arguments - l32i a2, a1, 0 - l32i a3, a1, 4 - l32i a4, a1, 8 - l32i a5, a1, 12 - - # (sign-)extend return value - movi a11, FFI_TYPE_UINT8 - bne a10, a11, 1f - extui a2, a2, 0, 8 - retw - -1: movi a11, FFI_TYPE_SINT8 - bne a10, a11, 1f - sext a2, a2, 7 - retw - -1: movi a11, FFI_TYPE_UINT16 - bne a10, a11, 1f - extui a2, a2, 0, 16 - retw - -1: movi a11, FFI_TYPE_SINT16 - bne a10, a11, 1f - sext a2, a2, 15 - -1: retw - -END(ffi_closure_SYSV) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/stamp-h.in --- a/Modules/_ctypes/libffi/stamp-h.in Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -timestamp diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/Makefile.am --- a/Modules/_ctypes/libffi/testsuite/Makefile.am Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/Makefile.am Fri Feb 01 23:12:09 2013 +0100 @@ -13,82 +13,73 @@ AM_RUNTESTFLAGS = -EXTRA_DEJAGNU_SITE_CONFIG=../local.exp - CLEANFILES = *.exe core* *.log *.sum -EXTRA_DIST = config/default.exp libffi.call/cls_19byte.c \ -libffi.call/cls_align_longdouble_split.c \ -libffi.call/closure_loc_fn0.c libffi.call/cls_schar.c \ -libffi.call/closure_fn1.c libffi.call/many2_win32.c \ -libffi.call/return_ul.c libffi.call/cls_align_double.c \ -libffi.call/return_fl2.c libffi.call/cls_1_1byte.c \ -libffi.call/cls_64byte.c libffi.call/nested_struct7.c \ -libffi.call/cls_align_sint32.c libffi.call/nested_struct2.c \ -libffi.call/ffitest.h libffi.call/nested_struct4.c \ -libffi.call/cls_multi_ushort.c libffi.call/struct3.c \ -libffi.call/cls_3byte1.c libffi.call/cls_16byte.c \ -libffi.call/struct8.c libffi.call/nested_struct8.c \ -libffi.call/cls_multi_sshort.c libffi.call/cls_3byte2.c \ -libffi.call/fastthis2_win32.c libffi.call/cls_pointer.c \ -libffi.call/err_bad_typedef.c libffi.call/cls_4_1byte.c \ -libffi.call/cls_9byte2.c libffi.call/cls_multi_schar.c \ -libffi.call/stret_medium2.c libffi.call/cls_5_1_byte.c \ -libffi.call/call.exp libffi.call/cls_double.c \ -libffi.call/cls_align_sint16.c libffi.call/cls_uint.c \ -libffi.call/return_ll1.c libffi.call/nested_struct3.c \ -libffi.call/cls_20byte1.c libffi.call/closure_fn4.c \ -libffi.call/cls_uchar.c libffi.call/struct2.c libffi.call/cls_7byte.c \ -libffi.call/strlen.c libffi.call/many.c libffi.call/testclosure.c \ -libffi.call/return_fl.c libffi.call/struct5.c \ -libffi.call/cls_12byte.c libffi.call/cls_multi_sshortchar.c \ -libffi.call/cls_align_longdouble_split2.c libffi.call/return_dbl2.c \ -libffi.call/return_fl3.c libffi.call/stret_medium.c \ -libffi.call/nested_struct6.c libffi.call/closure_fn3.c \ -libffi.call/float3.c libffi.call/many2.c \ -libffi.call/closure_stdcall.c libffi.call/cls_align_uint16.c \ -libffi.call/cls_9byte1.c libffi.call/closure_fn6.c \ -libffi.call/cls_double_va.c libffi.call/cls_align_pointer.c \ -libffi.call/cls_align_longdouble.c libffi.call/closure_fn2.c \ -libffi.call/cls_sshort.c libffi.call/many_win32.c \ -libffi.call/nested_struct.c libffi.call/cls_20byte.c \ -libffi.call/cls_longdouble.c libffi.call/cls_multi_uchar.c \ -libffi.call/return_uc.c libffi.call/closure_thiscall.c \ -libffi.call/cls_18byte.c libffi.call/cls_8byte.c \ -libffi.call/promotion.c libffi.call/struct1_win32.c \ -libffi.call/return_dbl.c libffi.call/cls_24byte.c \ -libffi.call/struct4.c libffi.call/cls_6byte.c \ -libffi.call/cls_align_uint32.c libffi.call/float.c \ -libffi.call/float1.c libffi.call/float_va.c libffi.call/negint.c \ -libffi.call/return_dbl1.c libffi.call/cls_3_1byte.c \ -libffi.call/cls_align_float.c libffi.call/return_fl1.c \ -libffi.call/nested_struct10.c libffi.call/nested_struct5.c \ -libffi.call/fastthis1_win32.c libffi.call/cls_align_sint64.c \ -libffi.call/stret_large2.c libffi.call/return_sl.c \ -libffi.call/closure_fn0.c libffi.call/cls_5byte.c \ -libffi.call/cls_2byte.c libffi.call/float2.c \ -libffi.call/cls_dbls_struct.c libffi.call/cls_sint.c \ -libffi.call/stret_large.c libffi.call/cls_ulonglong.c \ -libffi.call/cls_ushort.c libffi.call/nested_struct1.c \ -libffi.call/err_bad_abi.c libffi.call/cls_longdouble_va.c \ -libffi.call/cls_float.c libffi.call/cls_pointer_stack.c \ -libffi.call/pyobjc-tc.c libffi.call/cls_multi_ushortchar.c \ -libffi.call/struct1.c libffi.call/nested_struct9.c \ -libffi.call/huge_struct.c libffi.call/problem1.c \ -libffi.call/float4.c libffi.call/fastthis3_win32.c \ -libffi.call/return_ldl.c libffi.call/strlen2_win32.c \ -libffi.call/closure_fn5.c libffi.call/struct2_win32.c \ -libffi.call/struct6.c libffi.call/return_ll.c libffi.call/struct9.c \ -libffi.call/return_sc.c libffi.call/struct7.c \ -libffi.call/cls_align_uint64.c libffi.call/cls_4byte.c \ -libffi.call/strlen_win32.c libffi.call/cls_6_1_byte.c \ -libffi.call/cls_7_1_byte.c libffi.special/unwindtest.cc \ -libffi.special/special.exp libffi.special/unwindtest_ffi_call.cc \ -libffi.special/ffitestcxx.h lib/wrapper.exp lib/target-libpath.exp \ -lib/libffi.exp libffi.call/cls_struct_va1.c \ -libffi.call/cls_uchar_va.c libffi.call/cls_uint_va.c \ -libffi.call/cls_ulong_va.c libffi.call/cls_ushort_va.c \ -libffi.call/nested_struct11.c libffi.call/uninitialized.c \ -libffi.call/va_1.c libffi.call/va_struct1.c libffi.call/va_struct2.c \ -libffi.call/va_struct3.c - +EXTRA_DIST = config/default.exp libffi.call/cls_19byte.c \ +libffi.call/cls_align_longdouble_split.c libffi.call/closure_loc_fn0.c \ +libffi.call/cls_schar.c libffi.call/closure_fn1.c \ +libffi.call/many2_win32.c libffi.call/return_ul.c \ +libffi.call/cls_align_double.c libffi.call/return_fl2.c \ +libffi.call/cls_1_1byte.c libffi.call/cls_64byte.c \ +libffi.call/nested_struct7.c libffi.call/cls_align_sint32.c \ +libffi.call/nested_struct2.c libffi.call/ffitest.h \ +libffi.call/nested_struct4.c libffi.call/cls_multi_ushort.c \ +libffi.call/struct3.c libffi.call/cls_3byte1.c \ +libffi.call/cls_16byte.c libffi.call/struct8.c \ +libffi.call/nested_struct8.c libffi.call/cls_multi_sshort.c \ +libffi.call/cls_3byte2.c libffi.call/fastthis2_win32.c \ +libffi.call/cls_pointer.c libffi.call/err_bad_typedef.c \ +libffi.call/cls_4_1byte.c libffi.call/cls_9byte2.c \ +libffi.call/cls_multi_schar.c libffi.call/stret_medium2.c \ +libffi.call/cls_5_1_byte.c libffi.call/call.exp \ +libffi.call/cls_double.c libffi.call/cls_align_sint16.c \ +libffi.call/cls_uint.c libffi.call/return_ll1.c \ +libffi.call/nested_struct3.c libffi.call/cls_20byte1.c \ +libffi.call/closure_fn4.c libffi.call/cls_uchar.c \ +libffi.call/struct2.c libffi.call/cls_7byte.c libffi.call/strlen.c \ +libffi.call/many.c libffi.call/testclosure.c libffi.call/return_fl.c \ +libffi.call/struct5.c libffi.call/cls_12byte.c \ +libffi.call/cls_multi_sshortchar.c \ +libffi.call/cls_align_longdouble_split2.c libffi.call/return_dbl2.c \ +libffi.call/return_fl3.c libffi.call/stret_medium.c \ +libffi.call/nested_struct6.c libffi.call/a.out \ +libffi.call/closure_fn3.c libffi.call/float3.c libffi.call/many2.c \ +libffi.call/closure_stdcall.c libffi.call/cls_align_uint16.c \ +libffi.call/cls_9byte1.c libffi.call/closure_fn6.c \ +libffi.call/cls_double_va.c libffi.call/cls_align_pointer.c \ +libffi.call/cls_align_longdouble.c libffi.call/closure_fn2.c \ +libffi.call/cls_sshort.c libffi.call/many_win32.c \ +libffi.call/nested_struct.c libffi.call/cls_20byte.c \ +libffi.call/cls_longdouble.c libffi.call/cls_multi_uchar.c \ +libffi.call/return_uc.c libffi.call/closure_thiscall.c \ +libffi.call/cls_18byte.c libffi.call/cls_8byte.c \ +libffi.call/promotion.c libffi.call/struct1_win32.c \ +libffi.call/return_dbl.c libffi.call/cls_24byte.c \ +libffi.call/struct4.c libffi.call/cls_6byte.c \ +libffi.call/cls_align_uint32.c libffi.call/float.c \ +libffi.call/float1.c libffi.call/float_va.c libffi.call/negint.c \ +libffi.call/return_dbl1.c libffi.call/cls_3_1byte.c \ +libffi.call/cls_align_float.c libffi.call/return_fl1.c \ +libffi.call/nested_struct10.c libffi.call/nested_struct5.c \ +libffi.call/fastthis1_win32.c libffi.call/cls_align_sint64.c \ +libffi.call/stret_large2.c libffi.call/return_sl.c \ +libffi.call/closure_fn0.c libffi.call/cls_5byte.c \ +libffi.call/cls_2byte.c libffi.call/float2.c \ +libffi.call/cls_dbls_struct.c libffi.call/cls_sint.c \ +libffi.call/stret_large.c libffi.call/cls_ulonglong.c \ +libffi.call/cls_ushort.c libffi.call/nested_struct1.c \ +libffi.call/err_bad_abi.c libffi.call/cls_longdouble_va.c \ +libffi.call/cls_float.c libffi.call/cls_pointer_stack.c \ +libffi.call/pyobjc-tc.c libffi.call/cls_multi_ushortchar.c \ +libffi.call/struct1.c libffi.call/nested_struct9.c \ +libffi.call/huge_struct.c libffi.call/problem1.c libffi.call/float4.c \ +libffi.call/fastthis3_win32.c libffi.call/return_ldl.c \ +libffi.call/strlen2_win32.c libffi.call/closure_fn5.c \ +libffi.call/struct2_win32.c libffi.call/struct6.c \ +libffi.call/return_ll.c libffi.call/struct9.c libffi.call/return_sc.c \ +libffi.call/struct7.c libffi.call/cls_align_uint64.c \ +libffi.call/cls_4byte.c libffi.call/strlen_win32.c \ +libffi.call/cls_6_1_byte.c libffi.call/cls_7_1_byte.c \ +libffi.special/unwindtest.cc libffi.special/special.exp \ +libffi.special/unwindtest_ffi_call.cc libffi.special/ffitestcxx.h \ +lib/wrapper.exp lib/target-libpath.exp lib/libffi.exp diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/Makefile.in --- a/Modules/_ctypes/libffi/testsuite/Makefile.in Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/Makefile.in Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.12.2 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2012 Free Software Foundation, Inc. - +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,23 +15,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -53,19 +37,7 @@ subdir = testsuite DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/asmcfi.m4 \ - $(top_srcdir)/m4/ax_append_flag.m4 \ - $(top_srcdir)/m4/ax_cc_maxopt.m4 \ - $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ - $(top_srcdir)/m4/ax_check_compile_flag.m4 \ - $(top_srcdir)/m4/ax_compiler_vendor.m4 \ - $(top_srcdir)/m4/ax_configure_args.m4 \ - $(top_srcdir)/m4/ax_enable_builddir.m4 \ - $(top_srcdir)/m4/ax_gcc_archflag.m4 \ - $(top_srcdir)/m4/ax_gcc_x86_cpuid.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -75,11 +47,6 @@ CONFIG_CLEAN_VPATH_FILES = SOURCES = DIST_SOURCES = -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac DEJATOOL = $(PACKAGE) RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -147,7 +114,6 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PRTDIAG = @PRTDIAG@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -168,7 +134,6 @@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ -ax_enable_builddir_sed = @ax_enable_builddir_sed@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ @@ -204,7 +169,6 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ -sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -227,82 +191,75 @@ echo $(top_srcdir)/../dejagnu/runtest ; \ else echo runtest; fi` -EXTRA_DEJAGNU_SITE_CONFIG = ../local.exp CLEANFILES = *.exe core* *.log *.sum -EXTRA_DIST = config/default.exp libffi.call/cls_19byte.c \ -libffi.call/cls_align_longdouble_split.c \ -libffi.call/closure_loc_fn0.c libffi.call/cls_schar.c \ -libffi.call/closure_fn1.c libffi.call/many2_win32.c \ -libffi.call/return_ul.c libffi.call/cls_align_double.c \ -libffi.call/return_fl2.c libffi.call/cls_1_1byte.c \ -libffi.call/cls_64byte.c libffi.call/nested_struct7.c \ -libffi.call/cls_align_sint32.c libffi.call/nested_struct2.c \ -libffi.call/ffitest.h libffi.call/nested_struct4.c \ -libffi.call/cls_multi_ushort.c libffi.call/struct3.c \ -libffi.call/cls_3byte1.c libffi.call/cls_16byte.c \ -libffi.call/struct8.c libffi.call/nested_struct8.c \ -libffi.call/cls_multi_sshort.c libffi.call/cls_3byte2.c \ -libffi.call/fastthis2_win32.c libffi.call/cls_pointer.c \ -libffi.call/err_bad_typedef.c libffi.call/cls_4_1byte.c \ -libffi.call/cls_9byte2.c libffi.call/cls_multi_schar.c \ -libffi.call/stret_medium2.c libffi.call/cls_5_1_byte.c \ -libffi.call/call.exp libffi.call/cls_double.c \ -libffi.call/cls_align_sint16.c libffi.call/cls_uint.c \ -libffi.call/return_ll1.c libffi.call/nested_struct3.c \ -libffi.call/cls_20byte1.c libffi.call/closure_fn4.c \ -libffi.call/cls_uchar.c libffi.call/struct2.c libffi.call/cls_7byte.c \ -libffi.call/strlen.c libffi.call/many.c libffi.call/testclosure.c \ -libffi.call/return_fl.c libffi.call/struct5.c \ -libffi.call/cls_12byte.c libffi.call/cls_multi_sshortchar.c \ -libffi.call/cls_align_longdouble_split2.c libffi.call/return_dbl2.c \ -libffi.call/return_fl3.c libffi.call/stret_medium.c \ -libffi.call/nested_struct6.c libffi.call/closure_fn3.c \ -libffi.call/float3.c libffi.call/many2.c \ -libffi.call/closure_stdcall.c libffi.call/cls_align_uint16.c \ -libffi.call/cls_9byte1.c libffi.call/closure_fn6.c \ -libffi.call/cls_double_va.c libffi.call/cls_align_pointer.c \ -libffi.call/cls_align_longdouble.c libffi.call/closure_fn2.c \ -libffi.call/cls_sshort.c libffi.call/many_win32.c \ -libffi.call/nested_struct.c libffi.call/cls_20byte.c \ -libffi.call/cls_longdouble.c libffi.call/cls_multi_uchar.c \ -libffi.call/return_uc.c libffi.call/closure_thiscall.c \ -libffi.call/cls_18byte.c libffi.call/cls_8byte.c \ -libffi.call/promotion.c libffi.call/struct1_win32.c \ -libffi.call/return_dbl.c libffi.call/cls_24byte.c \ -libffi.call/struct4.c libffi.call/cls_6byte.c \ -libffi.call/cls_align_uint32.c libffi.call/float.c \ -libffi.call/float1.c libffi.call/float_va.c libffi.call/negint.c \ -libffi.call/return_dbl1.c libffi.call/cls_3_1byte.c \ -libffi.call/cls_align_float.c libffi.call/return_fl1.c \ -libffi.call/nested_struct10.c libffi.call/nested_struct5.c \ -libffi.call/fastthis1_win32.c libffi.call/cls_align_sint64.c \ -libffi.call/stret_large2.c libffi.call/return_sl.c \ -libffi.call/closure_fn0.c libffi.call/cls_5byte.c \ -libffi.call/cls_2byte.c libffi.call/float2.c \ -libffi.call/cls_dbls_struct.c libffi.call/cls_sint.c \ -libffi.call/stret_large.c libffi.call/cls_ulonglong.c \ -libffi.call/cls_ushort.c libffi.call/nested_struct1.c \ -libffi.call/err_bad_abi.c libffi.call/cls_longdouble_va.c \ -libffi.call/cls_float.c libffi.call/cls_pointer_stack.c \ -libffi.call/pyobjc-tc.c libffi.call/cls_multi_ushortchar.c \ -libffi.call/struct1.c libffi.call/nested_struct9.c \ -libffi.call/huge_struct.c libffi.call/problem1.c \ -libffi.call/float4.c libffi.call/fastthis3_win32.c \ -libffi.call/return_ldl.c libffi.call/strlen2_win32.c \ -libffi.call/closure_fn5.c libffi.call/struct2_win32.c \ -libffi.call/struct6.c libffi.call/return_ll.c libffi.call/struct9.c \ -libffi.call/return_sc.c libffi.call/struct7.c \ -libffi.call/cls_align_uint64.c libffi.call/cls_4byte.c \ -libffi.call/strlen_win32.c libffi.call/cls_6_1_byte.c \ -libffi.call/cls_7_1_byte.c libffi.special/unwindtest.cc \ -libffi.special/special.exp libffi.special/unwindtest_ffi_call.cc \ -libffi.special/ffitestcxx.h lib/wrapper.exp lib/target-libpath.exp \ -lib/libffi.exp libffi.call/cls_struct_va1.c \ -libffi.call/cls_uchar_va.c libffi.call/cls_uint_va.c \ -libffi.call/cls_ulong_va.c libffi.call/cls_ushort_va.c \ -libffi.call/nested_struct11.c libffi.call/uninitialized.c \ -libffi.call/va_1.c libffi.call/va_struct1.c libffi.call/va_struct2.c \ -libffi.call/va_struct3.c +EXTRA_DIST = config/default.exp libffi.call/cls_19byte.c \ +libffi.call/cls_align_longdouble_split.c libffi.call/closure_loc_fn0.c \ +libffi.call/cls_schar.c libffi.call/closure_fn1.c \ +libffi.call/many2_win32.c libffi.call/return_ul.c \ +libffi.call/cls_align_double.c libffi.call/return_fl2.c \ +libffi.call/cls_1_1byte.c libffi.call/cls_64byte.c \ +libffi.call/nested_struct7.c libffi.call/cls_align_sint32.c \ +libffi.call/nested_struct2.c libffi.call/ffitest.h \ +libffi.call/nested_struct4.c libffi.call/cls_multi_ushort.c \ +libffi.call/struct3.c libffi.call/cls_3byte1.c \ +libffi.call/cls_16byte.c libffi.call/struct8.c \ +libffi.call/nested_struct8.c libffi.call/cls_multi_sshort.c \ +libffi.call/cls_3byte2.c libffi.call/fastthis2_win32.c \ +libffi.call/cls_pointer.c libffi.call/err_bad_typedef.c \ +libffi.call/cls_4_1byte.c libffi.call/cls_9byte2.c \ +libffi.call/cls_multi_schar.c libffi.call/stret_medium2.c \ +libffi.call/cls_5_1_byte.c libffi.call/call.exp \ +libffi.call/cls_double.c libffi.call/cls_align_sint16.c \ +libffi.call/cls_uint.c libffi.call/return_ll1.c \ +libffi.call/nested_struct3.c libffi.call/cls_20byte1.c \ +libffi.call/closure_fn4.c libffi.call/cls_uchar.c \ +libffi.call/struct2.c libffi.call/cls_7byte.c libffi.call/strlen.c \ +libffi.call/many.c libffi.call/testclosure.c libffi.call/return_fl.c \ +libffi.call/struct5.c libffi.call/cls_12byte.c \ +libffi.call/cls_multi_sshortchar.c \ +libffi.call/cls_align_longdouble_split2.c libffi.call/return_dbl2.c \ +libffi.call/return_fl3.c libffi.call/stret_medium.c \ +libffi.call/nested_struct6.c libffi.call/a.out \ +libffi.call/closure_fn3.c libffi.call/float3.c libffi.call/many2.c \ +libffi.call/closure_stdcall.c libffi.call/cls_align_uint16.c \ +libffi.call/cls_9byte1.c libffi.call/closure_fn6.c \ +libffi.call/cls_double_va.c libffi.call/cls_align_pointer.c \ +libffi.call/cls_align_longdouble.c libffi.call/closure_fn2.c \ +libffi.call/cls_sshort.c libffi.call/many_win32.c \ +libffi.call/nested_struct.c libffi.call/cls_20byte.c \ +libffi.call/cls_longdouble.c libffi.call/cls_multi_uchar.c \ +libffi.call/return_uc.c libffi.call/closure_thiscall.c \ +libffi.call/cls_18byte.c libffi.call/cls_8byte.c \ +libffi.call/promotion.c libffi.call/struct1_win32.c \ +libffi.call/return_dbl.c libffi.call/cls_24byte.c \ +libffi.call/struct4.c libffi.call/cls_6byte.c \ +libffi.call/cls_align_uint32.c libffi.call/float.c \ +libffi.call/float1.c libffi.call/float_va.c libffi.call/negint.c \ +libffi.call/return_dbl1.c libffi.call/cls_3_1byte.c \ +libffi.call/cls_align_float.c libffi.call/return_fl1.c \ +libffi.call/nested_struct10.c libffi.call/nested_struct5.c \ +libffi.call/fastthis1_win32.c libffi.call/cls_align_sint64.c \ +libffi.call/stret_large2.c libffi.call/return_sl.c \ +libffi.call/closure_fn0.c libffi.call/cls_5byte.c \ +libffi.call/cls_2byte.c libffi.call/float2.c \ +libffi.call/cls_dbls_struct.c libffi.call/cls_sint.c \ +libffi.call/stret_large.c libffi.call/cls_ulonglong.c \ +libffi.call/cls_ushort.c libffi.call/nested_struct1.c \ +libffi.call/err_bad_abi.c libffi.call/cls_longdouble_va.c \ +libffi.call/cls_float.c libffi.call/cls_pointer_stack.c \ +libffi.call/pyobjc-tc.c libffi.call/cls_multi_ushortchar.c \ +libffi.call/struct1.c libffi.call/nested_struct9.c \ +libffi.call/huge_struct.c libffi.call/problem1.c libffi.call/float4.c \ +libffi.call/fastthis3_win32.c libffi.call/return_ldl.c \ +libffi.call/strlen2_win32.c libffi.call/closure_fn5.c \ +libffi.call/struct2_win32.c libffi.call/struct6.c \ +libffi.call/return_ll.c libffi.call/struct9.c libffi.call/return_sc.c \ +libffi.call/struct7.c libffi.call/cls_align_uint64.c \ +libffi.call/cls_4byte.c libffi.call/strlen_win32.c \ +libffi.call/cls_6_1_byte.c libffi.call/cls_7_1_byte.c \ +libffi.special/unwindtest.cc libffi.special/special.exp \ +libffi.special/unwindtest_ffi_call.cc libffi.special/ffitestcxx.h \ +lib/wrapper.exp lib/target-libpath.exp lib/libffi.exp all: all-am @@ -349,8 +306,6 @@ ctags: CTAGS CTAGS: -cscope cscopelist: - check-DEJAGNU: site.exp srcdir='$(srcdir)'; export srcdir; \ @@ -361,11 +316,11 @@ if $$runtest $(AM_RUNTESTFLAGS) $(RUNTESTDEFAULTFLAGS) $(RUNTESTFLAGS); \ then :; else exit_status=1; fi; \ done; \ - else echo "WARNING: could not find 'runtest'" 1>&2; :;\ + else echo "WARNING: could not find \`runtest'" 1>&2; :;\ fi; \ exit $$exit_status site.exp: Makefile $(EXTRA_DEJAGNU_SITE_CONFIG) - @echo 'Making a new site.exp file ...' + @echo 'Making a new site.exp file...' @echo '## these variables are automatically generated by make ##' >site.tmp @echo '# Do not edit here. If you wish to override these values' >>site.tmp @echo '# edit the last section' >>site.tmp diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/lib/libffi.exp --- a/Modules/_ctypes/libffi/testsuite/lib/libffi.exp Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/lib/libffi.exp Fri Feb 01 23:12:09 2013 +0100 @@ -101,17 +101,9 @@ global tool_root_dir global ld_library_path - global using_gcc - set blddirffi [pwd]/.. verbose "libffi $blddirffi" - # Are we building with GCC? - set tmp [grep ../config.status "GCC='yes'"] - if { [string match $tmp "GCC='yes'"] } { - - set using_gcc "yes" - set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a] if {$gccdir != ""} { set gccdir [file dirname $gccdir] @@ -135,13 +127,6 @@ } } } - - } else { - - set using_gcc "no" - - } - # add the library path for libffi. append ld_library_path ":${blddirffi}/.libs" @@ -218,10 +203,6 @@ lappend options "libs= -lffi" - if { [string match "aarch64*-*-linux*" $target_triplet] } { - lappend options "libs= -lpthread" - } - verbose "options: $options" return [target_compile $source $dest $type $options] } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/a.out Binary file Modules/_ctypes/libffi/testsuite/libffi.call/a.out has changed diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/call.exp --- a/Modules/_ctypes/libffi/testsuite/libffi.call/call.exp Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/call.exp Fri Feb 01 23:12:09 2013 +0100 @@ -19,20 +19,11 @@ global srcdir subdir -if { [string match $using_gcc "yes"] } { - - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O0 -W -Wall" "" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O2" "" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O3" "" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-Os" "" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O2 -fomit-frame-pointer" "" - -} else { - - # Assume we are using the vendor compiler. - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "" "" - -} +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O0 -W -Wall" "" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O2" "" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O3" "" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-Os" "" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "-O2 -fomit-frame-pointer" "" dg-finish diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_double_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_double_va.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/cls_double_va.c Fri Feb 01 23:12:09 2013 +0100 @@ -45,9 +45,9 @@ args[2] = NULL; ffi_call(&cif, FFI_FN(printf), &res, args); - /* { dg-output "7.0" } */ + // { dg-output "7.0" } printf("res: %d\n", (int) res); - /* { dg-output "\nres: 4" } */ + // { dg-output "\nres: 4" } /* The call to cls_double_va_fn is static, so have to use a normal prep_cif */ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint, arg_types) == FFI_OK); @@ -55,9 +55,9 @@ CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK); res = ((int(*)(char*, double))(code))(format, doubleArg); - /* { dg-output "\n7.0" } */ + // { dg-output "\n7.0" } printf("res: %d\n", (int) res); - /* { dg-output "\nres: 4" } */ + // { dg-output "\nres: 4" } exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_longdouble.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_longdouble.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/cls_longdouble.c Fri Feb 01 23:12:09 2013 +0100 @@ -5,9 +5,7 @@ Originator: Blake Chaffin */ /* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */ -/* This test is known to PASS on armv7l-unknown-linux-gnueabihf, so I have - remove the xfail for arm*-*-* below, until we know more. */ -/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ +/* { dg-do run { xfail arm*-*-* strongarm*-*-* xscale*-*-* } } */ /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */ /* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_longdouble_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_longdouble_va.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/cls_longdouble_va.c Fri Feb 01 23:12:09 2013 +0100 @@ -45,9 +45,9 @@ args[2] = NULL; ffi_call(&cif, FFI_FN(printf), &res, args); - /* { dg-output "7.0" } */ + // { dg-output "7.0" } printf("res: %d\n", (int) res); - /* { dg-output "\nres: 4" } */ + // { dg-output "\nres: 4" } /* The call to cls_longdouble_va_fn is static, so have to use a normal prep_cif */ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint, @@ -56,9 +56,9 @@ CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL, code) == FFI_OK); res = ((int(*)(char*, long double))(code))(format, ldArg); - /* { dg-output "\n7.0" } */ + // { dg-output "\n7.0" } printf("res: %d\n", (int) res); - /* { dg-output "\nres: 4" } */ + // { dg-output "\nres: 4" } exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_pointer.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_pointer.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/cls_pointer.c Fri Feb 01 23:12:09 2013 +0100 @@ -35,7 +35,7 @@ void *code; ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); void* args[3]; - /* ffi_type cls_pointer_type; */ +// ffi_type cls_pointer_type; ffi_type* arg_types[3]; /* cls_pointer_type.size = sizeof(void*); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_pointer_stack.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_pointer_stack.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/cls_pointer_stack.c Fri Feb 01 23:12:09 2013 +0100 @@ -98,7 +98,7 @@ void *code; ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); void* args[3]; - /* ffi_type cls_pointer_type; */ +// ffi_type cls_pointer_type; ffi_type* arg_types[3]; /* cls_pointer_type.size = sizeof(void*); @@ -125,18 +125,18 @@ ffi_call(&cif, FFI_FN(cls_pointer_fn1), &res, args); printf("res: 0x%08x\n", (unsigned int) res); - /* { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" } */ - /* { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" } */ - /* { dg-output "\nres: 0x8bf258bd" } */ + // { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" } + // { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" } + // { dg-output "\nres: 0x8bf258bd" } CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK); res = (ffi_arg)(uintptr_t)((void*(*)(void*, void*))(code))(arg1, arg2); printf("res: 0x%08x\n", (unsigned int) res); - /* { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" } */ - /* { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" } */ - /* { dg-output "\nres: 0x8bf258bd" } */ + // { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" } + // { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" } + // { dg-output "\nres: 0x8bf258bd" } exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_struct_va1.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_struct_va1.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* Area: ffi_call, closure_call - Purpose: Test doubles passed in variable argument lists. - Limitations: none. - PR: none. - Originator: Blake Chaffin 6/6/2007 */ - -/* { dg-do run } */ -/* { dg-output "" { xfail avr32*-*-* } } */ -#include "ffitest.h" - -struct small_tag -{ - unsigned char a; - unsigned char b; -}; - -struct large_tag -{ - unsigned a; - unsigned b; - unsigned c; - unsigned d; - unsigned e; -}; - -static void -test_fn (ffi_cif* cif __UNUSED__, void* resp, - void** args, void* userdata __UNUSED__) -{ - int n = *(int*)args[0]; - struct small_tag s1 = * (struct small_tag *) args[1]; - struct large_tag l1 = * (struct large_tag *) args[2]; - struct small_tag s2 = * (struct small_tag *) args[3]; - - printf ("%d %d %d %d %d %d %d %d %d %d\n", n, s1.a, s1.b, - l1.a, l1.b, l1.c, l1.d, l1.e, - s2.a, s2.b); - * (int*) resp = 42; -} - -int -main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc (sizeof (ffi_closure), &code); - ffi_type* arg_types[5]; - - ffi_arg res = 0; - - ffi_type s_type; - ffi_type *s_type_elements[3]; - - ffi_type l_type; - ffi_type *l_type_elements[6]; - - struct small_tag s1; - struct small_tag s2; - struct large_tag l1; - - int si; - - s_type.size = 0; - s_type.alignment = 0; - s_type.type = FFI_TYPE_STRUCT; - s_type.elements = s_type_elements; - - s_type_elements[0] = &ffi_type_uchar; - s_type_elements[1] = &ffi_type_uchar; - s_type_elements[2] = NULL; - - l_type.size = 0; - l_type.alignment = 0; - l_type.type = FFI_TYPE_STRUCT; - l_type.elements = l_type_elements; - - l_type_elements[0] = &ffi_type_uint; - l_type_elements[1] = &ffi_type_uint; - l_type_elements[2] = &ffi_type_uint; - l_type_elements[3] = &ffi_type_uint; - l_type_elements[4] = &ffi_type_uint; - l_type_elements[5] = NULL; - - arg_types[0] = &ffi_type_sint; - arg_types[1] = &s_type; - arg_types[2] = &l_type; - arg_types[3] = &s_type; - arg_types[4] = NULL; - - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &ffi_type_sint, - arg_types) == FFI_OK); - - si = 4; - s1.a = 5; - s1.b = 6; - - s2.a = 20; - s2.b = 21; - - l1.a = 10; - l1.b = 11; - l1.c = 12; - l1.d = 13; - l1.e = 14; - - CHECK(ffi_prep_closure_loc(pcl, &cif, test_fn, NULL, code) == FFI_OK); - - res = ((int (*)(int, ...))(code))(si, s1, l1, s2); - /* { dg-output "4 5 6 10 11 12 13 14 20 21" } */ - printf("res: %d\n", (int) res); - /* { dg-output "\nres: 42" } */ - - exit(0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_uchar_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_uchar_va.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* Area: closure_call - Purpose: Test anonymous unsigned char argument. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -#include "ffitest.h" - -typedef unsigned char T; - -static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, - void* userdata __UNUSED__) - { - *(ffi_arg *)resp = *(T *)args[0]; - - printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]); - } - -typedef T (*cls_ret_T)(T, ...); - -int main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); - ffi_type * cl_arg_types[3]; - T res; - - cl_arg_types[0] = &ffi_type_uchar; - cl_arg_types[1] = &ffi_type_uchar; - cl_arg_types[2] = NULL; - - /* Initialize the cif */ - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, - &ffi_type_uchar, cl_arg_types) == FFI_OK); - - CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); - res = ((((cls_ret_T)code)(67, 4))); - /* { dg-output "67: 67 4" } */ - printf("res: %d\n", res); - /* { dg-output "\nres: 67" } */ - exit(0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_uint_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_uint_va.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* Area: closure_call - Purpose: Test anonymous unsigned int argument. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ - -#include "ffitest.h" - -typedef unsigned int T; - -static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, - void* userdata __UNUSED__) - { - *(T *)resp = *(T *)args[0]; - - printf("%d: %d %d\n", *(T *)resp, *(T *)args[0], *(T *)args[1]); - } - -typedef T (*cls_ret_T)(T, ...); - -int main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); - ffi_type * cl_arg_types[3]; - T res; - - cl_arg_types[0] = &ffi_type_uint; - cl_arg_types[1] = &ffi_type_uint; - cl_arg_types[2] = NULL; - - /* Initialize the cif */ - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, - &ffi_type_uint, cl_arg_types) == FFI_OK); - - CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); - res = ((((cls_ret_T)code)(67, 4))); - /* { dg-output "67: 67 4" } */ - printf("res: %d\n", res); - /* { dg-output "\nres: 67" } */ - exit(0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_ulong_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_ulong_va.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* Area: closure_call - Purpose: Test anonymous unsigned long argument. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ - -#include "ffitest.h" - -typedef unsigned long T; - -static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, - void* userdata __UNUSED__) - { - *(T *)resp = *(T *)args[0]; - - printf("%ld: %ld %ld\n", *(T *)resp, *(T *)args[0], *(T *)args[1]); - } - -typedef T (*cls_ret_T)(T, ...); - -int main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); - ffi_type * cl_arg_types[3]; - T res; - - cl_arg_types[0] = &ffi_type_ulong; - cl_arg_types[1] = &ffi_type_ulong; - cl_arg_types[2] = NULL; - - /* Initialize the cif */ - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, - &ffi_type_ulong, cl_arg_types) == FFI_OK); - - CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); - res = ((((cls_ret_T)code)(67, 4))); - /* { dg-output "67: 67 4" } */ - printf("res: %ld\n", res); - /* { dg-output "\nres: 67" } */ - exit(0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_ulonglong.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_ulonglong.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/cls_ulonglong.c Fri Feb 01 23:12:09 2013 +0100 @@ -11,7 +11,7 @@ static void cls_ret_ulonglong_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata __UNUSED__) { - *(unsigned long long *)resp= 0xfffffffffffffffLL ^ *(unsigned long long *)args[0]; + *(unsigned long long *)resp= *(unsigned long long *)args[0]; printf("%" PRIuLL ": %" PRIuLL "\n",*(unsigned long long *)args[0], *(unsigned long long *)(resp)); @@ -34,14 +34,14 @@ &ffi_type_uint64, cl_arg_types) == FFI_OK); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_ulonglong_fn, NULL, code) == FFI_OK); res = (*((cls_ret_ulonglong)code))(214LL); - /* { dg-output "214: 1152921504606846761" } */ + /* { dg-output "214: 214" } */ printf("res: %" PRIdLL "\n", res); - /* { dg-output "\nres: 1152921504606846761" } */ + /* { dg-output "\nres: 214" } */ res = (*((cls_ret_ulonglong)code))(9223372035854775808LL); - /* { dg-output "\n9223372035854775808: 8070450533247928831" } */ + /* { dg-output "\n9223372035854775808: 9223372035854775808" } */ printf("res: %" PRIdLL "\n", res); - /* { dg-output "\nres: 8070450533247928831" } */ + /* { dg-output "\nres: 9223372035854775808" } */ exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/cls_ushort_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/cls_ushort_va.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* Area: closure_call - Purpose: Test anonymous unsigned short argument. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -#include "ffitest.h" - -typedef unsigned short T; - -static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, - void* userdata __UNUSED__) - { - *(ffi_arg *)resp = *(T *)args[0]; - - printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]); - } - -typedef T (*cls_ret_T)(T, ...); - -int main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); - ffi_type * cl_arg_types[3]; - T res; - - cl_arg_types[0] = &ffi_type_ushort; - cl_arg_types[1] = &ffi_type_ushort; - cl_arg_types[2] = NULL; - - /* Initialize the cif */ - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, - &ffi_type_ushort, cl_arg_types) == FFI_OK); - - CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); - res = ((((cls_ret_T)code)(67, 4))); - /* { dg-output "67: 67 4" } */ - printf("res: %d\n", res); - /* { dg-output "\nres: 67" } */ - exit(0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/ffitest.h --- a/Modules/_ctypes/libffi/testsuite/libffi.call/ffitest.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/ffitest.h Fri Feb 01 23:12:09 2013 +0100 @@ -15,7 +15,7 @@ #define MAX_ARGS 256 -#define CHECK(x) !(x) ? (abort(), 1) : 0 +#define CHECK(x) !(x) ? abort() : 0 /* Define __UNUSED__ that also other compilers than gcc can run the tests. */ #undef __UNUSED__ @@ -127,6 +127,44 @@ #define PRId64 "I64d" #endif -#ifndef PRIuPTR -#define PRIuPTR "u" +#ifdef USING_MMAP +static inline void * +allocate_mmap (size_t size) +{ + void *page; +#if defined (HAVE_MMAP_DEV_ZERO) + static int dev_zero_fd = -1; #endif + +#ifdef HAVE_MMAP_DEV_ZERO + if (dev_zero_fd == -1) + { + dev_zero_fd = open ("/dev/zero", O_RDONLY); + if (dev_zero_fd == -1) + { + perror ("open /dev/zero: %m"); + exit (1); + } + } +#endif + + +#ifdef HAVE_MMAP_ANON + page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +#endif +#ifdef HAVE_MMAP_DEV_ZERO + page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE, dev_zero_fd, 0); +#endif + + if (page == (void *) MAP_FAILED) + { + perror ("virtual memory exhausted"); + exit (1); + } + + return page; +} + +#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/float_va.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/float_va.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/float_va.c Fri Feb 01 23:12:09 2013 +0100 @@ -56,9 +56,9 @@ * different. */ /* Call it statically and then via ffi */ resfp=float_va_fn(0,2.0); - /* { dg-output "0: 2.0 : total: 2.0" } */ + // { dg-output "0: 2.0 : total: 2.0" } printf("compiled: %.1f\n", resfp); - /* { dg-output "\ncompiled: 2.0" } */ + // { dg-output "\ncompiled: 2.0" } arg_types[0] = &ffi_type_uint; arg_types[1] = &ffi_type_double; @@ -71,16 +71,16 @@ values[0] = &firstarg; values[1] = &doubles[0]; ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values); - /* { dg-output "\n0: 2.0 : total: 2.0" } */ + // { dg-output "\n0: 2.0 : total: 2.0" } printf("ffi: %.1f\n", resfp); - /* { dg-output "\nffi: 2.0" } */ + // { dg-output "\nffi: 2.0" } /* Second test, float_va_fn(2,2.0,3.0,4.0), now with variadic params */ /* Call it statically and then via ffi */ resfp=float_va_fn(2,2.0,3.0,4.0); - /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */ + // { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } printf("compiled: %.1f\n", resfp); - /* { dg-output "\ncompiled: 11.0" } */ + // { dg-output "\ncompiled: 11.0" } arg_types[0] = &ffi_type_uint; arg_types[1] = &ffi_type_double; @@ -99,9 +99,9 @@ values[2] = &doubles[1]; values[3] = &doubles[2]; ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values); - /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */ + // { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } printf("ffi: %.1f\n", resfp); - /* { dg-output "\nffi: 11.0" } */ + // { dg-output "\nffi: 11.0" } exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/huge_struct.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/huge_struct.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/huge_struct.c Fri Feb 01 23:12:09 2013 +0100 @@ -8,7 +8,6 @@ /* { dg-excess-errors "" { target x86_64-*-mingw* x86_64-*-cygwin* } } */ /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */ -/* { dg-options -Wformat=0 { target moxie*-*-elf } } */ /* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */ #include "ffitest.h" @@ -296,7 +295,7 @@ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 50, &ret_struct_type, argTypes) == FFI_OK); ffi_call(&cif, FFI_FN(test_large_fn), &retVal, argValues); - /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } */ + // { dg-output "1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } printf("res: %" PRIu8 " %" PRId8 " %hu %hd %u %d %" PRIu64 " %" PRId64 " %.0f %.0f %.0Lf %#lx " "%" PRIu8 " %" PRId8 " %hu %hd %u %d %" PRIu64 " %" PRId64 " %.0f %.0f %.0Lf %#lx " "%" PRIu8 " %" PRId8 " %hu %hd %u %d %" PRIu64 " %" PRId64 " %.0f %.0f %.0Lf %#lx " @@ -309,7 +308,7 @@ retVal.ee, retVal.ff, retVal.gg, retVal.hh, retVal.ii, (unsigned long)retVal.jj, retVal.kk, retVal.ll, retVal.mm, retVal.nn, retVal.oo, retVal.pp, retVal.qq, retVal.rr, retVal.ss, retVal.tt, retVal.uu, (unsigned long)retVal.vv, retVal.ww, retVal.xx); - /* { dg-output "\nres: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } */ + // { dg-output "\nres: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } CHECK(ffi_prep_closure_loc(pcl, &cif, cls_large_fn, NULL, code) == FFI_OK); @@ -324,7 +323,7 @@ ui8, si8, ui16, si16, ui32, si32, ui64, si64, f, d, ld, p, ui8, si8, ui16, si16, ui32, si32, ui64, si64, f, d, ld, p, ui8, si8); - /* { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } */ + // { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2 3 4 5 6 7 8 9 10 11 0x12345678 1 2: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } printf("res: %" PRIu8 " %" PRId8 " %hu %hd %u %d %" PRIu64 " %" PRId64 " %.0f %.0f %.0Lf %#lx " "%" PRIu8 " %" PRId8 " %hu %hd %u %d %" PRIu64 " %" PRId64 " %.0f %.0f %.0Lf %#lx " "%" PRIu8 " %" PRId8 " %hu %hd %u %d %" PRIu64 " %" PRId64 " %.0f %.0f %.0Lf %#lx " @@ -337,7 +336,7 @@ retVal.ee, retVal.ff, retVal.gg, retVal.hh, retVal.ii, (unsigned long)retVal.jj, retVal.kk, retVal.ll, retVal.mm, retVal.nn, retVal.oo, retVal.pp, retVal.qq, retVal.rr, retVal.ss, retVal.tt, retVal.uu, (unsigned long)retVal.vv, retVal.ww, retVal.xx); - /* { dg-output "\nres: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } */ + // { dg-output "\nres: 2 3 4 5 6 7 8 9 10 11 12 0x12345679 3 4 5 6 7 8 9 10 11 12 13 0x1234567a 4 5 6 7 8 9 10 11 12 13 14 0x1234567b 5 6 7 8 9 10 11 12 13 14 15 0x1234567c 6 7" } return 0; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/many2.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/many2.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/many2.c Fri Feb 01 23:12:09 2013 +0100 @@ -12,10 +12,7 @@ typedef unsigned char u8; -#ifdef __GNUC__ -__attribute__((noinline)) -#endif -uint8_t +__attribute__((noinline)) uint8_t foo (uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, uint8_t g) { diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/negint.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/negint.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/negint.c Fri Feb 01 23:12:09 2013 +0100 @@ -5,6 +5,7 @@ Originator: From the original ffitest.c */ /* { dg-do run } */ +/* { dg-options -O2 } */ #include "ffitest.h" diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/nested_struct1.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/nested_struct1.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/nested_struct1.c Fri Feb 01 23:12:09 2013 +0100 @@ -156,6 +156,6 @@ CHECK( res_dbl.e.ii == (e_dbl.c + f_dbl.ii + g_dbl.e.ii)); CHECK( res_dbl.e.dd == (e_dbl.a + f_dbl.dd + g_dbl.e.dd)); CHECK( res_dbl.e.ff == (e_dbl.b + f_dbl.ff + g_dbl.e.ff)); - /* CHECK( 1 == 0); */ + // CHECK( 1 == 0); exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/nested_struct11.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/nested_struct11.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* Area: ffi_call, closure_call - Purpose: Check parameter passing with nested structs - of a single type. This tests the special cases - for homogenous floating-point aggregates in the - AArch64 PCS. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -#include "ffitest.h" - -typedef struct A { - float a_x; - float a_y; -} A; - -typedef struct B { - float b_x; - float b_y; -} B; - -typedef struct C { - A a; - B b; -} C; - -static C C_fn (int x, int y, int z, C source, int i, int j, int k) -{ - C result; - result.a.a_x = source.a.a_x; - result.a.a_y = source.a.a_y; - result.b.b_x = source.b.b_x; - result.b.b_y = source.b.b_y; - - printf ("%d, %d, %d, %d, %d, %d\n", x, y, z, i, j, k); - - printf ("%.1f, %.1f, %.1f, %.1f, " - "%.1f, %.1f, %.1f, %.1f\n", - source.a.a_x, source.a.a_y, - source.b.b_x, source.b.b_y, - result.a.a_x, result.a.a_y, - result.b.b_x, result.b.b_y); - - return result; -} - -int main (void) -{ - ffi_cif cif; - - ffi_type* struct_fields_source_a[3]; - ffi_type* struct_fields_source_b[3]; - ffi_type* struct_fields_source_c[3]; - ffi_type* arg_types[8]; - - ffi_type struct_type_a, struct_type_b, struct_type_c; - - struct A source_fld_a = {1.0, 2.0}; - struct B source_fld_b = {4.0, 8.0}; - int k = 1; - - struct C result; - struct C source = {source_fld_a, source_fld_b}; - - struct_type_a.size = 0; - struct_type_a.alignment = 0; - struct_type_a.type = FFI_TYPE_STRUCT; - struct_type_a.elements = struct_fields_source_a; - - struct_type_b.size = 0; - struct_type_b.alignment = 0; - struct_type_b.type = FFI_TYPE_STRUCT; - struct_type_b.elements = struct_fields_source_b; - - struct_type_c.size = 0; - struct_type_c.alignment = 0; - struct_type_c.type = FFI_TYPE_STRUCT; - struct_type_c.elements = struct_fields_source_c; - - struct_fields_source_a[0] = &ffi_type_float; - struct_fields_source_a[1] = &ffi_type_float; - struct_fields_source_a[2] = NULL; - - struct_fields_source_b[0] = &ffi_type_float; - struct_fields_source_b[1] = &ffi_type_float; - struct_fields_source_b[2] = NULL; - - struct_fields_source_c[0] = &struct_type_a; - struct_fields_source_c[1] = &struct_type_b; - struct_fields_source_c[2] = NULL; - - arg_types[0] = &ffi_type_sint32; - arg_types[1] = &ffi_type_sint32; - arg_types[2] = &ffi_type_sint32; - arg_types[3] = &struct_type_c; - arg_types[4] = &ffi_type_sint32; - arg_types[5] = &ffi_type_sint32; - arg_types[6] = &ffi_type_sint32; - arg_types[7] = NULL; - - void *args[7]; - args[0] = &k; - args[1] = &k; - args[2] = &k; - args[3] = &source; - args[4] = &k; - args[5] = &k; - args[6] = &k; - CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 7, &struct_type_c, - arg_types) == FFI_OK); - - ffi_call (&cif, FFI_FN (C_fn), &result, args); - /* { dg-output "1, 1, 1, 1, 1, 1\n" } */ - /* { dg-output "1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0" } */ - CHECK (result.a.a_x == source.a.a_x); - CHECK (result.a.a_y == source.a.a_y); - CHECK (result.b.b_x == source.b.b_x); - CHECK (result.b.b_y == source.b.b_y); - exit (0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/return_dbl.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/return_dbl.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/return_dbl.c Fri Feb 01 23:12:09 2013 +0100 @@ -9,7 +9,6 @@ static double return_dbl(double dbl) { - printf ("%f\n", dbl); return 2 * dbl; } int main (void) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/return_uc.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/return_uc.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/return_uc.c Fri Feb 01 23:12:09 2013 +0100 @@ -32,7 +32,7 @@ uc < (unsigned char) '\xff'; uc++) { ffi_call(&cif, FFI_FN(return_uc), &rint, values); - CHECK((unsigned char)rint == uc); + CHECK(rint == (signed int) uc); } exit(0); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/stret_large.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/stret_large.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/stret_large.c Fri Feb 01 23:12:09 2013 +0100 @@ -9,8 +9,8 @@ /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ #include "ffitest.h" -/* 13 FPRs: 104 bytes */ -/* 14 FPRs: 112 bytes */ +// 13 FPRs: 104 bytes +// 14 FPRs: 112 bytes typedef struct struct_108byte { double a; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/stret_large2.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/stret_large2.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.call/stret_large2.c Fri Feb 01 23:12:09 2013 +0100 @@ -9,8 +9,8 @@ /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ #include "ffitest.h" -/* 13 FPRs: 104 bytes */ -/* 14 FPRs: 112 bytes */ +// 13 FPRs: 104 bytes +// 14 FPRs: 112 bytes typedef struct struct_116byte { double a; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/uninitialized.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/uninitialized.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* { dg-do run } */ -#include "ffitest.h" - -typedef struct -{ - unsigned char uc; - double d; - unsigned int ui; -} test_structure_1; - -static test_structure_1 struct1(test_structure_1 ts) -{ - ts.uc++; - ts.d--; - ts.ui++; - - return ts; -} - -int main (void) -{ - ffi_cif cif; - ffi_type *args[MAX_ARGS]; - void *values[MAX_ARGS]; - ffi_type ts1_type; - ffi_type *ts1_type_elements[4]; - - memset(&cif, 1, sizeof(cif)); - ts1_type.size = 0; - ts1_type.alignment = 0; - ts1_type.type = FFI_TYPE_STRUCT; - ts1_type.elements = ts1_type_elements; - ts1_type_elements[0] = &ffi_type_uchar; - ts1_type_elements[1] = &ffi_type_double; - ts1_type_elements[2] = &ffi_type_uint; - ts1_type_elements[3] = NULL; - - test_structure_1 ts1_arg; - /* This is a hack to get a properly aligned result buffer */ - test_structure_1 *ts1_result = - (test_structure_1 *) malloc (sizeof(test_structure_1)); - - args[0] = &ts1_type; - values[0] = &ts1_arg; - - /* Initialize the cif */ - CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, - &ts1_type, args) == FFI_OK); - - ts1_arg.uc = '\x01'; - ts1_arg.d = 3.14159; - ts1_arg.ui = 555; - - ffi_call(&cif, FFI_FN(struct1), ts1_result, values); - - CHECK(ts1_result->ui == 556); - CHECK(ts1_result->d == 3.14159 - 1); - - free (ts1_result); - exit(0); -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/va_1.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/va_1.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,196 +0,0 @@ -/* Area: ffi_call - Purpose: Test passing struct in variable argument lists. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -/* { dg-output "" { xfail avr32*-*-* } } */ - -#include "ffitest.h" -#include - -struct small_tag -{ - unsigned char a; - unsigned char b; -}; - -struct large_tag -{ - unsigned a; - unsigned b; - unsigned c; - unsigned d; - unsigned e; -}; - -static int -test_fn (int n, ...) -{ - va_list ap; - struct small_tag s1; - struct small_tag s2; - struct large_tag l; - unsigned char uc; - signed char sc; - unsigned short us; - signed short ss; - unsigned int ui; - signed int si; - unsigned long ul; - signed long sl; - float f; - double d; - - va_start (ap, n); - s1 = va_arg (ap, struct small_tag); - l = va_arg (ap, struct large_tag); - s2 = va_arg (ap, struct small_tag); - - uc = va_arg (ap, unsigned); - sc = va_arg (ap, signed); - - us = va_arg (ap, unsigned); - ss = va_arg (ap, signed); - - ui = va_arg (ap, unsigned int); - si = va_arg (ap, signed int); - - ul = va_arg (ap, unsigned long); - sl = va_arg (ap, signed long); - - f = va_arg (ap, double); /* C standard promotes float->double - when anonymous */ - d = va_arg (ap, double); - - printf ("%u %u %u %u %u %u %u %u %u uc=%u sc=%d %u %d %u %d %lu %ld %f %f\n", - s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, - s2.a, s2.b, - uc, sc, - us, ss, - ui, si, - ul, sl, - f, d); - va_end (ap); - return n + 1; -} - -int -main (void) -{ - ffi_cif cif; - void* args[15]; - ffi_type* arg_types[15]; - - ffi_type s_type; - ffi_type *s_type_elements[3]; - - ffi_type l_type; - ffi_type *l_type_elements[6]; - - struct small_tag s1; - struct small_tag s2; - struct large_tag l1; - - int n; - int res; - - unsigned char uc; - signed char sc; - unsigned short us; - signed short ss; - unsigned int ui; - signed int si; - unsigned long ul; - signed long sl; - double d1; - double f1; - - s_type.size = 0; - s_type.alignment = 0; - s_type.type = FFI_TYPE_STRUCT; - s_type.elements = s_type_elements; - - s_type_elements[0] = &ffi_type_uchar; - s_type_elements[1] = &ffi_type_uchar; - s_type_elements[2] = NULL; - - l_type.size = 0; - l_type.alignment = 0; - l_type.type = FFI_TYPE_STRUCT; - l_type.elements = l_type_elements; - - l_type_elements[0] = &ffi_type_uint; - l_type_elements[1] = &ffi_type_uint; - l_type_elements[2] = &ffi_type_uint; - l_type_elements[3] = &ffi_type_uint; - l_type_elements[4] = &ffi_type_uint; - l_type_elements[5] = NULL; - - arg_types[0] = &ffi_type_sint; - arg_types[1] = &s_type; - arg_types[2] = &l_type; - arg_types[3] = &s_type; - arg_types[4] = &ffi_type_uchar; - arg_types[5] = &ffi_type_schar; - arg_types[6] = &ffi_type_ushort; - arg_types[7] = &ffi_type_sshort; - arg_types[8] = &ffi_type_uint; - arg_types[9] = &ffi_type_sint; - arg_types[10] = &ffi_type_ulong; - arg_types[11] = &ffi_type_slong; - arg_types[12] = &ffi_type_double; - arg_types[13] = &ffi_type_double; - arg_types[14] = NULL; - - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_OK); - - s1.a = 5; - s1.b = 6; - - l1.a = 10; - l1.b = 11; - l1.c = 12; - l1.d = 13; - l1.e = 14; - - s2.a = 7; - s2.b = 8; - - n = 41; - - uc = 9; - sc = 10; - us = 11; - ss = 12; - ui = 13; - si = 14; - ul = 15; - sl = 16; - f1 = 2.12; - d1 = 3.13; - - args[0] = &n; - args[1] = &s1; - args[2] = &l1; - args[3] = &s2; - args[4] = &uc; - args[5] = ≻ - args[6] = &us; - args[7] = &ss; - args[8] = &ui; - args[9] = &si; - args[10] = &ul; - args[11] = &sl; - args[12] = &f1; - args[13] = &d1; - args[14] = NULL; - - ffi_call(&cif, FFI_FN(test_fn), &res, args); - /* { dg-output "5 6 10 11 12 13 14 7 8 uc=9 sc=10 11 12 13 14 15 16 2.120000 3.130000" } */ - printf("res: %d\n", (int) res); - /* { dg-output "\nres: 42" } */ - - return 0; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/va_struct1.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/va_struct1.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* Area: ffi_call - Purpose: Test passing struct in variable argument lists. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -/* { dg-output "" { xfail avr32*-*-* } } */ - -#include "ffitest.h" -#include - -struct small_tag -{ - unsigned char a; - unsigned char b; -}; - -struct large_tag -{ - unsigned a; - unsigned b; - unsigned c; - unsigned d; - unsigned e; -}; - -static int -test_fn (int n, ...) -{ - va_list ap; - struct small_tag s1; - struct small_tag s2; - struct large_tag l; - - va_start (ap, n); - s1 = va_arg (ap, struct small_tag); - l = va_arg (ap, struct large_tag); - s2 = va_arg (ap, struct small_tag); - printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, - s2.a, s2.b); - va_end (ap); - return n + 1; -} - -int -main (void) -{ - ffi_cif cif; - void* args[5]; - ffi_type* arg_types[5]; - - ffi_type s_type; - ffi_type *s_type_elements[3]; - - ffi_type l_type; - ffi_type *l_type_elements[6]; - - struct small_tag s1; - struct small_tag s2; - struct large_tag l1; - - int n; - int res; - - s_type.size = 0; - s_type.alignment = 0; - s_type.type = FFI_TYPE_STRUCT; - s_type.elements = s_type_elements; - - s_type_elements[0] = &ffi_type_uchar; - s_type_elements[1] = &ffi_type_uchar; - s_type_elements[2] = NULL; - - l_type.size = 0; - l_type.alignment = 0; - l_type.type = FFI_TYPE_STRUCT; - l_type.elements = l_type_elements; - - l_type_elements[0] = &ffi_type_uint; - l_type_elements[1] = &ffi_type_uint; - l_type_elements[2] = &ffi_type_uint; - l_type_elements[3] = &ffi_type_uint; - l_type_elements[4] = &ffi_type_uint; - l_type_elements[5] = NULL; - - arg_types[0] = &ffi_type_sint; - arg_types[1] = &s_type; - arg_types[2] = &l_type; - arg_types[3] = &s_type; - arg_types[4] = NULL; - - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &ffi_type_sint, arg_types) == FFI_OK); - - s1.a = 5; - s1.b = 6; - - l1.a = 10; - l1.b = 11; - l1.c = 12; - l1.d = 13; - l1.e = 14; - - s2.a = 7; - s2.b = 8; - - n = 41; - - args[0] = &n; - args[1] = &s1; - args[2] = &l1; - args[3] = &s2; - args[4] = NULL; - - ffi_call(&cif, FFI_FN(test_fn), &res, args); - /* { dg-output "5 6 10 11 12 13 14 7 8" } */ - printf("res: %d\n", (int) res); - /* { dg-output "\nres: 42" } */ - - return 0; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/va_struct2.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/va_struct2.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* Area: ffi_call - Purpose: Test passing struct in variable argument lists. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -/* { dg-output "" { xfail avr32*-*-* } } */ - -#include "ffitest.h" -#include - -struct small_tag -{ - unsigned char a; - unsigned char b; -}; - -struct large_tag -{ - unsigned a; - unsigned b; - unsigned c; - unsigned d; - unsigned e; -}; - -static struct small_tag -test_fn (int n, ...) -{ - va_list ap; - struct small_tag s1; - struct small_tag s2; - struct large_tag l; - - va_start (ap, n); - s1 = va_arg (ap, struct small_tag); - l = va_arg (ap, struct large_tag); - s2 = va_arg (ap, struct small_tag); - printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, - s2.a, s2.b); - va_end (ap); - s1.a += s2.a; - s1.b += s2.b; - return s1; -} - -int -main (void) -{ - ffi_cif cif; - void* args[5]; - ffi_type* arg_types[5]; - - ffi_type s_type; - ffi_type *s_type_elements[3]; - - ffi_type l_type; - ffi_type *l_type_elements[6]; - - struct small_tag s1; - struct small_tag s2; - struct large_tag l1; - - int n; - struct small_tag res; - - s_type.size = 0; - s_type.alignment = 0; - s_type.type = FFI_TYPE_STRUCT; - s_type.elements = s_type_elements; - - s_type_elements[0] = &ffi_type_uchar; - s_type_elements[1] = &ffi_type_uchar; - s_type_elements[2] = NULL; - - l_type.size = 0; - l_type.alignment = 0; - l_type.type = FFI_TYPE_STRUCT; - l_type.elements = l_type_elements; - - l_type_elements[0] = &ffi_type_uint; - l_type_elements[1] = &ffi_type_uint; - l_type_elements[2] = &ffi_type_uint; - l_type_elements[3] = &ffi_type_uint; - l_type_elements[4] = &ffi_type_uint; - l_type_elements[5] = NULL; - - arg_types[0] = &ffi_type_sint; - arg_types[1] = &s_type; - arg_types[2] = &l_type; - arg_types[3] = &s_type; - arg_types[4] = NULL; - - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &s_type, arg_types) == FFI_OK); - - s1.a = 5; - s1.b = 6; - - l1.a = 10; - l1.b = 11; - l1.c = 12; - l1.d = 13; - l1.e = 14; - - s2.a = 7; - s2.b = 8; - - n = 41; - - args[0] = &n; - args[1] = &s1; - args[2] = &l1; - args[3] = &s2; - args[4] = NULL; - - ffi_call(&cif, FFI_FN(test_fn), &res, args); - /* { dg-output "5 6 10 11 12 13 14 7 8" } */ - printf("res: %d %d\n", res.a, res.b); - /* { dg-output "\nres: 12 14" } */ - - return 0; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.call/va_struct3.c --- a/Modules/_ctypes/libffi/testsuite/libffi.call/va_struct3.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -/* Area: ffi_call - Purpose: Test passing struct in variable argument lists. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -/* { dg-output "" { xfail avr32*-*-* } } */ - -#include "ffitest.h" -#include - -struct small_tag -{ - unsigned char a; - unsigned char b; -}; - -struct large_tag -{ - unsigned a; - unsigned b; - unsigned c; - unsigned d; - unsigned e; -}; - -static struct large_tag -test_fn (int n, ...) -{ - va_list ap; - struct small_tag s1; - struct small_tag s2; - struct large_tag l; - - va_start (ap, n); - s1 = va_arg (ap, struct small_tag); - l = va_arg (ap, struct large_tag); - s2 = va_arg (ap, struct small_tag); - printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, - s2.a, s2.b); - va_end (ap); - l.a += s1.a; - l.b += s1.b; - l.c += s2.a; - l.d += s2.b; - return l; -} - -int -main (void) -{ - ffi_cif cif; - void* args[5]; - ffi_type* arg_types[5]; - - ffi_type s_type; - ffi_type *s_type_elements[3]; - - ffi_type l_type; - ffi_type *l_type_elements[6]; - - struct small_tag s1; - struct small_tag s2; - struct large_tag l1; - - int n; - struct large_tag res; - - s_type.size = 0; - s_type.alignment = 0; - s_type.type = FFI_TYPE_STRUCT; - s_type.elements = s_type_elements; - - s_type_elements[0] = &ffi_type_uchar; - s_type_elements[1] = &ffi_type_uchar; - s_type_elements[2] = NULL; - - l_type.size = 0; - l_type.alignment = 0; - l_type.type = FFI_TYPE_STRUCT; - l_type.elements = l_type_elements; - - l_type_elements[0] = &ffi_type_uint; - l_type_elements[1] = &ffi_type_uint; - l_type_elements[2] = &ffi_type_uint; - l_type_elements[3] = &ffi_type_uint; - l_type_elements[4] = &ffi_type_uint; - l_type_elements[5] = NULL; - - arg_types[0] = &ffi_type_sint; - arg_types[1] = &s_type; - arg_types[2] = &l_type; - arg_types[3] = &s_type; - arg_types[4] = NULL; - - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &l_type, arg_types) == FFI_OK); - - s1.a = 5; - s1.b = 6; - - l1.a = 10; - l1.b = 11; - l1.c = 12; - l1.d = 13; - l1.e = 14; - - s2.a = 7; - s2.b = 8; - - n = 41; - - args[0] = &n; - args[1] = &s1; - args[2] = &l1; - args[3] = &s2; - args[4] = NULL; - - ffi_call(&cif, FFI_FN(test_fn), &res, args); - /* { dg-output "5 6 10 11 12 13 14 7 8" } */ - printf("res: %d %d %d %d %d\n", res.a, res.b, res.c, res.d, res.e); - /* { dg-output "\nres: 15 17 19 21 14" } */ - - return 0; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.special/ffitestcxx.h --- a/Modules/_ctypes/libffi/testsuite/libffi.special/ffitestcxx.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.special/ffitestcxx.h Fri Feb 01 23:12:09 2013 +0100 @@ -53,3 +53,44 @@ #define PRIuLL "llu" #endif +#ifdef USING_MMAP +static inline void * +allocate_mmap (size_t size) +{ + void *page; +#if defined (HAVE_MMAP_DEV_ZERO) + static int dev_zero_fd = -1; +#endif + +#ifdef HAVE_MMAP_DEV_ZERO + if (dev_zero_fd == -1) + { + dev_zero_fd = open ("/dev/zero", O_RDONLY); + if (dev_zero_fd == -1) + { + perror ("open /dev/zero: %m"); + exit (1); + } + } +#endif + + +#ifdef HAVE_MMAP_ANON + page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +#endif +#ifdef HAVE_MMAP_DEV_ZERO + page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE, dev_zero_fd, 0); +#endif + + if (page == (char *) MAP_FAILED) + { + perror ("virtual memory exhausted"); + exit (1); + } + + return page; +} + +#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.special/special.exp --- a/Modules/_ctypes/libffi/testsuite/libffi.special/special.exp Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.special/special.exp Fri Feb 01 23:12:09 2013 +0100 @@ -23,14 +23,10 @@ set cxx_options " -shared-libgcc -lstdc++" -if { [string match $using_gcc "yes"] } { - - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-O0 -W -Wall" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-O2" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-O3" - dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-Os" - -} +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-O0 -W -Wall" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-O2" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-O3" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] $cxx_options "-Os" dg-finish diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.special/unwindtest.cc --- a/Modules/_ctypes/libffi/testsuite/libffi.special/unwindtest.cc Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.special/unwindtest.cc Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,6 @@ Originator: Jeff Sturm */ /* { dg-do run } */ - #include "ffitestcxx.h" #if defined HAVE_STDINT_H diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc --- a/Modules/_ctypes/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc Fri Feb 01 23:12:09 2013 +0100 @@ -5,7 +5,6 @@ Originator: Andreas Tobler 20061213 */ /* { dg-do run } */ - #include "ffitestcxx.h" static int checking(int a __UNUSED__, short b __UNUSED__, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi/texinfo.tex --- a/Modules/_ctypes/libffi/texinfo.tex Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi/texinfo.tex Fri Feb 01 23:12:09 2013 +0100 @@ -1,18 +1,18 @@ % texinfo.tex -- TeX macros to handle Texinfo files. -% +% % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2012-06-05.14} -% -% Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995, -% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, -% 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. -% -% This texinfo.tex file is free software: you can redistribute it and/or +\def\texinfoversion{2005-07-05.19} +% +% Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995, +% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software +% Foundation, Inc. +% +% This texinfo.tex file 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 3 of the -% License, or (at your option) any later version. +% published by the Free Software Foundation; either version 2, or (at +% your option) any later version. % % This texinfo.tex file is distributed in the hope that it will be % useful, but WITHOUT ANY WARRANTY; without even the implied warranty @@ -20,7 +20,9 @@ % General Public License for more details. % % You should have received a copy of the GNU General Public License -% along with this program. If not, see . +% along with this texinfo.tex file; see the file COPYING. If not, write +% to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +% Boston, MA 02110-1301, USA. % % As a special exception, when this file is read by TeX when processing % a Texinfo source document, you may use the result without @@ -28,9 +30,9 @@ % % Please try the latest version of texinfo.tex before submitting bug % reports; you can get the latest version from: -% http://ftp.gnu.org/gnu/texinfo/ (the Texinfo release area), or -% http://ftpmirror.gnu.org/texinfo/ (same, via a mirror), or -% http://www.gnu.org/software/texinfo/ (the Texinfo home page) +% http://www.gnu.org/software/texinfo/ (the Texinfo home page), or +% ftp://tug.org/tex/texinfo.tex +% (and all CTAN mirrors, see http://www.ctan.org). % The texinfo.tex in any given distribution could well be out % of date, so if that's what you're using, please check. % @@ -65,6 +67,7 @@ \everyjob{\message{[Texinfo version \texinfoversion]}% \catcode`+=\active \catcode`\_=\active} +\message{Basics,} \chardef\other=12 % We never want plain's \outer definition of \+ in Texinfo. @@ -92,13 +95,10 @@ \let\ptexnewwrite\newwrite \let\ptexnoindent=\noindent \let\ptexplus=+ -\let\ptexraggedright=\raggedright \let\ptexrbrace=\} \let\ptexslash=\/ \let\ptexstar=\* \let\ptext=\t -\let\ptextop=\top -{\catcode`\'=\active \global\let\ptexquoteright'}% active in plain's math mode % If this character appears in an error message or help string, it % starts a new line in the output. @@ -116,11 +116,10 @@ % Set up fixed words for English if not already set. \ifx\putwordAppendix\undefined \gdef\putwordAppendix{Appendix}\fi \ifx\putwordChapter\undefined \gdef\putwordChapter{Chapter}\fi -\ifx\putworderror\undefined \gdef\putworderror{error}\fi \ifx\putwordfile\undefined \gdef\putwordfile{file}\fi \ifx\putwordin\undefined \gdef\putwordin{in}\fi -\ifx\putwordIndexIsEmpty\undefined \gdef\putwordIndexIsEmpty{(Index is empty)}\fi -\ifx\putwordIndexNonexistent\undefined \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi +\ifx\putwordIndexIsEmpty\undefined \gdef\putwordIndexIsEmpty{(Index is empty)}\fi +\ifx\putwordIndexNonexistent\undefined \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi \ifx\putwordInfo\undefined \gdef\putwordInfo{Info}\fi \ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi \ifx\putwordMethodon\undefined \gdef\putwordMethodon{Method on}\fi @@ -154,25 +153,28 @@ \ifx\putwordDefopt\undefined \gdef\putwordDefopt{User Option}\fi \ifx\putwordDeffunc\undefined \gdef\putwordDeffunc{Function}\fi -% Since the category of space is not known, we have to be careful. -\chardef\spacecat = 10 -\def\spaceisspace{\catcode`\ =\spacecat} - -% sometimes characters are active, so we need control sequences. -\chardef\ampChar = `\& +% In some macros, we cannot use the `\? notation---the left quote is +% in some cases the escape char. +\chardef\backChar = `\\ \chardef\colonChar = `\: \chardef\commaChar = `\, -\chardef\dashChar = `\- \chardef\dotChar = `\. \chardef\exclamChar= `\! -\chardef\hashChar = `\# -\chardef\lquoteChar= `\` +\chardef\plusChar = `\+ \chardef\questChar = `\? -\chardef\rquoteChar= `\' \chardef\semiChar = `\; -\chardef\slashChar = `\/ \chardef\underChar = `\_ +\chardef\spaceChar = `\ % +\chardef\spacecat = 10 +\def\spaceisspace{\catcode\spaceChar=\spacecat} + +{% for help with debugging. + % example usage: \expandafter\show\activebackslash + \catcode`\! = 0 \catcode`\\ = \active + !global!def!activebackslash{\} +} + % Ignore a token. % \def\gobble#1{} @@ -201,7 +203,36 @@ % that mark overfull boxes (in case you have decided % that the text looks ok even though it passes the margin). % -\def\finalout{\overfullrule=0pt } +\def\finalout{\overfullrule=0pt} + +% @| inserts a changebar to the left of the current line. It should +% surround any changed text. This approach does *not* work if the +% change spans more than two lines of output. To handle that, we would +% have adopt a much more difficult approach (putting marks into the main +% vertical list for the beginning and end of each change). +% +\def\|{% + % \vadjust can only be used in horizontal mode. + \leavevmode + % + % Append this vertical mode material after the current line in the output. + \vadjust{% + % We want to insert a rule with the height and depth of the current + % leading; that is exactly what \strutbox is supposed to record. + \vskip-\baselineskip + % + % \vadjust-items are inserted at the left edge of the type. So + % the \llap here moves out into the left-hand margin. + \llap{% + % + % For a thicker or thinner bar, change the `1pt'. + \vrule height\baselineskip width1pt + % + % This is the space between the bar and the text. + \hskip 12pt + }% + }% +} % Sometimes it is convenient to have everything in the transcript file % and nothing on the terminal. We don't just call \tracingall here, @@ -219,7 +250,7 @@ \tracingmacros2 \tracingrestores1 \showboxbreadth\maxdimen \showboxdepth\maxdimen - \ifx\eTeXversion\thisisundefined\else % etex gives us more logging + \ifx\eTeXversion\undefined\else % etex gives us more logging \tracingscantokens1 \tracingifs1 \tracinggroups1 @@ -230,13 +261,6 @@ \errorcontextlines16 }% -% @errormsg{MSG}. Do the index-like expansions on MSG, but if things -% aren't perfect, it's not the end of the world, being an error message, -% after all. -% -\def\errormsg{\begingroup \indexnofonts \doerrormsg} -\def\doerrormsg#1{\errmessage{#1}} - % add check for \lastpenalty to plain's definitions. If the last thing % we did was a \nobreak, we don't want to insert more space. % @@ -247,6 +271,7 @@ \def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount \removelastskip\penalty-200\bigskip\fi\fi} +% For @cropmarks command. % Do @cropmarks to get crop marks. % \newif\ifcropmarks @@ -260,50 +285,6 @@ \newdimen\cornerthick \cornerthick=.3pt \newdimen\topandbottommargin \topandbottommargin=.75in -% Output a mark which sets \thischapter, \thissection and \thiscolor. -% We dump everything together because we only have one kind of mark. -% This works because we only use \botmark / \topmark, not \firstmark. -% -% A mark contains a subexpression of the \ifcase ... \fi construct. -% \get*marks macros below extract the needed part using \ifcase. -% -% Another complication is to let the user choose whether \thischapter -% (\thissection) refers to the chapter (section) in effect at the top -% of a page, or that at the bottom of a page. The solution is -% described on page 260 of The TeXbook. It involves outputting two -% marks for the sectioning macros, one before the section break, and -% one after. I won't pretend I can describe this better than DEK... -\def\domark{% - \toks0=\expandafter{\lastchapterdefs}% - \toks2=\expandafter{\lastsectiondefs}% - \toks4=\expandafter{\prevchapterdefs}% - \toks6=\expandafter{\prevsectiondefs}% - \toks8=\expandafter{\lastcolordefs}% - \mark{% - \the\toks0 \the\toks2 - \noexpand\or \the\toks4 \the\toks6 - \noexpand\else \the\toks8 - }% -} -% \topmark doesn't work for the very first chapter (after the title -% page or the contents), so we use \firstmark there -- this gets us -% the mark with the chapter defs, unless the user sneaks in, e.g., -% @setcolor (or @url, or @link, etc.) between @contents and the very -% first @chapter. -\def\gettopheadingmarks{% - \ifcase0\topmark\fi - \ifx\thischapter\empty \ifcase0\firstmark\fi \fi -} -\def\getbottomheadingmarks{\ifcase1\botmark\fi} -\def\getcolormarks{\ifcase2\topmark\fi} - -% Avoid "undefined control sequence" errors. -\def\lastchapterdefs{} -\def\lastsectiondefs{} -\def\prevchapterdefs{} -\def\prevsectiondefs{} -\def\lastcolordefs{} - % Main output routine. \chardef\PAGE = 255 \output = {\onepageout{\pagecontents\PAGE}} @@ -321,9 +302,7 @@ % % Do this outside of the \shipout so @code etc. will be expanded in % the headline as they should be, not taken literally (outputting ''code). - \ifodd\pageno \getoddheadingmarks \else \getevenheadingmarks \fi \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}% - \ifodd\pageno \getoddfootingmarks \else \getevenfootingmarks \fi \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}% % {% @@ -332,13 +311,6 @@ % before the \shipout runs. % \indexdummies % don't expand commands in the output. - \normalturnoffactive % \ in index entries must not stay \, e.g., if - % the page break happens to be in the middle of an example. - % We don't want .vr (or whatever) entries like this: - % \entry{{\tt \indexbackslash }acronym}{32}{\code {\acronym}} - % "\acronym" won't work when it's read back in; - % it needs to be - % {\code {{\tt \backslashcurfont }acronym} \shipout\vbox{% % Do this early so pdf references go to the beginning of the page. \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi @@ -366,9 +338,9 @@ \pagebody{#1}% \ifdim\ht\footlinebox > 0pt % Only leave this space if the footline is nonempty. - % (We lessened \vsize for it in \oddfootingyyy.) + % (We lessened \vsize for it in \oddfootingxxx.) % The \baselineskip=24pt in plain's \makefootline has no effect. - \vskip 24pt + \vskip 2\baselineskip \unvbox\footlinebox \fi % @@ -402,7 +374,7 @@ % marginal hacks, juha@viisa.uucp (Juha Takala) \ifvoid\margin\else % marginal info is present \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi -\dimen@=\dp#1\relax \unvbox#1\relax +\dimen@=\dp#1 \unvbox#1 \ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi \ifr@ggedbottom \kern-\dimen@ \vfil \fi} } @@ -424,7 +396,7 @@ % \def\parsearg{\parseargusing{}} \def\parseargusing#1#2{% - \def\argtorun{#2}% + \def\next{#2}% \begingroup \obeylines \spaceisspace @@ -443,7 +415,7 @@ \def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm} \def\argremovec#1\c#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm} -% Each occurrence of `\^^M' or `\^^M' is replaced by a single space. +% Each occurence of `\^^M' or `\^^M' is replaced by a single space. % % \argremovec might leave us with trailing space, e.g., % @end itemize @c foo @@ -455,7 +427,8 @@ \def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{% \def\temp{#3}% \ifx\temp\empty - % Do not use \next, perhaps the caller of \parsearg uses it; reuse \temp: + % We cannot use \next here, as it holds the macro to run; + % thus we reuse \temp. \let\temp\finishparsearg \else \let\temp\argcheckspaces @@ -467,14 +440,14 @@ % If a _delimited_ argument is enclosed in braces, they get stripped; so % to get _exactly_ the rest of the line, we had to prevent such situation. % We prepended an \empty token at the very beginning and we expand it now, -% just before passing the control to \argtorun. -% (Similarly, we have to think about #3 of \argcheckspacesY above: it is +% just before passing the control to \next. +% (Similarily, we have to think about #3 of \argcheckspacesY above: it is % either the null string, or it ends with \^^M---thus there is no danger % that a pair of braces would be stripped. % % But first, we have to remove the trailing space token. % -\def\finishparsearg#1 \ArgTerm{\expandafter\argtorun\expandafter{#1}} +\def\finishparsearg#1 \ArgTerm{\expandafter\next\expandafter{#1}} % \parseargdef\foo{...} % is roughly equivalent to @@ -525,12 +498,12 @@ % used to check whether the current environment is the one expected. % % Non-false conditionals (@iftex, @ifset) don't fit into this, so they -% are not treated as environments; they don't open a group. (The +% are not treated as enviroments; they don't open a group. (The % implementation of @end takes care not to call \endgroup in this % special case.) -% At run-time, environments start with this: +% At runtime, environments start with this: \def\startenvironment#1{\begingroup\def\thisenv{#1}} % initialize \let\thisenv\empty @@ -548,7 +521,7 @@ \fi } -% Environment mismatch, #1 expected: +% Evironment mismatch, #1 expected: \def\badenverr{% \errhelp = \EMsimple \errmessage{This command can appear only \inenvironment\temp, @@ -556,7 +529,7 @@ } \def\inenvironment#1{% \ifx#1\empty - outside of any environment% + out of any environment% \else in environment \expandafter\string#1% \fi @@ -568,7 +541,7 @@ \parseargdef\end{% \if 1\csname iscond.#1\endcsname \else - % The general wording of \badenverr may not be ideal. + % The general wording of \badenverr may not be ideal, but... --kasal, 06nov03 \expandafter\checkenv\csname#1\endcsname \csname E#1\endcsname \endgroup @@ -578,6 +551,85 @@ \newhelp\EMsimple{Press RETURN to continue.} +%% Simple single-character @ commands + +% @@ prints an @ +% Kludge this until the fonts are right (grr). +\def\@{{\tt\char64}} + +% This is turned off because it was never documented +% and you can use @w{...} around a quote to suppress ligatures. +%% Define @` and @' to be the same as ` and ' +%% but suppressing ligatures. +%\def\`{{`}} +%\def\'{{'}} + +% Used to generate quoted braces. +\def\mylbrace {{\tt\char123}} +\def\myrbrace {{\tt\char125}} +\let\{=\mylbrace +\let\}=\myrbrace +\begingroup + % Definitions to produce \{ and \} commands for indices, + % and @{ and @} for the aux/toc files. + \catcode`\{ = \other \catcode`\} = \other + \catcode`\[ = 1 \catcode`\] = 2 + \catcode`\! = 0 \catcode`\\ = \other + !gdef!lbracecmd[\{]% + !gdef!rbracecmd[\}]% + !gdef!lbraceatcmd[@{]% + !gdef!rbraceatcmd[@}]% +!endgroup + +% @comma{} to avoid , parsing problems. +\let\comma = , + +% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent +% Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H. +\let\, = \c +\let\dotaccent = \. +\def\ringaccent#1{{\accent23 #1}} +\let\tieaccent = \t +\let\ubaraccent = \b +\let\udotaccent = \d + +% Other special characters: @questiondown @exclamdown @ordf @ordm +% Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss. +\def\questiondown{?`} +\def\exclamdown{!`} +\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}} +\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}} + +% Dotless i and dotless j, used for accents. +\def\imacro{i} +\def\jmacro{j} +\def\dotless#1{% + \def\temp{#1}% + \ifx\temp\imacro \ptexi + \else\ifx\temp\jmacro \j + \else \errmessage{@dotless can be used only with i or j}% + \fi\fi +} + +% The \TeX{} logo, as in plain, but resetting the spacing so that a +% period following counts as ending a sentence. (Idea found in latex.) +% +\edef\TeX{\TeX \spacefactor=1000 } + +% @LaTeX{} logo. Not quite the same results as the definition in +% latex.ltx, since we use a different font for the raised A; it's most +% convenient for us to use an explicitly smaller font, rather than using +% the \scriptstyle font (since we don't reset \scriptstyle and +% \scriptscriptstyle). +% +\def\LaTeX{% + L\kern-.36em + {\setbox0=\hbox{T}% + \vbox to \ht0{\hbox{\selectfonts\lllsize A}\vss}}% + \kern-.15em + \TeX +} + % Be sure we're in horizontal mode when doing a tie, since we make space % equivalent to this in @example-like environments. Otherwise, a space % at the beginning of a line will start with \penalty -- and @@ -609,7 +661,7 @@ \def\?{?\spacefactor=\endofsentencespacefactor\space} % @frenchspacing on|off says whether to put extra space after punctuation. -% +% \def\onword{on} \def\offword{off} % @@ -619,7 +671,7 @@ \else\ifx\temp\offword \plainnonfrenchspacing \else \errhelp = \EMsimple - \errmessage{Unknown @frenchspacing option `\temp', must be on|off}% + \errmessage{Unknown @frenchspacing option `\temp', must be on/off}% \fi\fi } @@ -701,6 +753,15 @@ \newdimen\mil \mil=0.001in +% Old definition--didn't work. +%\parseargdef\need{\par % +%% This method tries to make TeX break the page naturally +%% if the depth of the box does not fit. +%{\baselineskip=0pt% +%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak +%\prevdepth=-1000pt +%}} + \parseargdef\need{% % Ensure vertical mode, so we don't make a big box in the middle of a % paragraph. @@ -764,7 +825,7 @@ % @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current % paragraph. For more general purposes, use the \margin insertion -% class. WHICH is `l' or `r'. Not documented, written for gawk manual. +% class. WHICH is `l' or `r'. % \newskip\inmarginspacing \inmarginspacing=1cm \def\strutdepth{\dp\strutbox} @@ -811,51 +872,15 @@ \temp } -% @| inserts a changebar to the left of the current line. It should -% surround any changed text. This approach does *not* work if the -% change spans more than two lines of output. To handle that, we would -% have adopt a much more difficult approach (putting marks into the main -% vertical list for the beginning and end of each change). This command -% is not documented, not supported, and doesn't work. -% -\def\|{% - % \vadjust can only be used in horizontal mode. - \leavevmode - % - % Append this vertical mode material after the current line in the output. - \vadjust{% - % We want to insert a rule with the height and depth of the current - % leading; that is exactly what \strutbox is supposed to record. - \vskip-\baselineskip - % - % \vadjust-items are inserted at the left edge of the type. So - % the \llap here moves out into the left-hand margin. - \llap{% - % - % For a thicker or thinner bar, change the `1pt'. - \vrule height\baselineskip width1pt - % - % This is the space between the bar and the text. - \hskip 12pt - }% - }% -} - -% @include FILE -- \input text of FILE. +% @include file insert text of that file as input. % \def\include{\parseargusing\filenamecatcodes\includezzz} \def\includezzz#1{% \pushthisfilestack \def\thisfile{#1}% {% - \makevalueexpandable % we want to expand any @value in FILE. - \turnoffactive % and allow special characters in the expansion - \indexnofonts % Allow `@@' and other weird things in file names. - \wlog{texinfo.tex: doing @include of #1^^J}% - \edef\temp{\noexpand\input #1 }% - % - % This trickery is to read FILE outside of a group, in case it makes - % definitions, etc. + \makevalueexpandable + \def\temp{\input #1 }% \expandafter }\temp \popthisfilestack @@ -870,8 +895,6 @@ \catcode`>=\other \catcode`+=\other \catcode`-=\other - \catcode`\`=\other - \catcode`\'=\other } \def\pushthisfilestack{% @@ -887,7 +910,7 @@ \def\popthisfilestack{\errthisfilestackempty} \def\errthisfilestackempty{\errmessage{Internal error: the stack of filenames is empty.}} -% + \def\thisfile{} % @center line @@ -895,46 +918,36 @@ % \parseargdef\center{% \ifhmode - \let\centersub\centerH + \let\next\centerH \else - \let\centersub\centerV + \let\next\centerV \fi - \centersub{\hfil \ignorespaces#1\unskip \hfil}% - \let\centersub\relax % don't let the definition persist, just in case -} -\def\centerH#1{{% - \hfil\break - \advance\hsize by -\leftskip - \advance\hsize by -\rightskip - \line{#1}% - \break -}} -% -\newcount\centerpenalty -\def\centerV#1{% - % The idea here is the same as in \startdefun, \cartouche, etc.: if - % @center is the first thing after a section heading, we need to wipe - % out the negative parskip inserted by \sectionheading, but still - % prevent a page break here. - \centerpenalty = \lastpenalty - \ifnum\centerpenalty>10000 \vskip\parskip \fi - \ifnum\centerpenalty>9999 \penalty\centerpenalty \fi - \line{\kern\leftskip #1\kern\rightskip}% -} + \next{\hfil \ignorespaces#1\unskip \hfil}% +} +\def\centerH#1{% + {% + \hfil\break + \advance\hsize by -\leftskip + \advance\hsize by -\rightskip + \line{#1}% + \break + }% +} +\def\centerV#1{\line{\kern\leftskip #1\kern\rightskip}} % @sp n outputs n lines of vertical space -% + \parseargdef\sp{\vskip #1\baselineskip} % @comment ...line which is ignored... % @c is the same as @comment % @ignore ... @end ignore is another way to write a comment -% + \def\comment{\begingroup \catcode`\^^M=\other% \catcode`\@=\other \catcode`\{=\other \catcode`\}=\other% \commentxxx} {\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}} -% + \let\c=\comment % @paragraphindent NCHARS @@ -1027,6 +1040,86 @@ } +% @asis just yields its argument. Used with @table, for example. +% +\def\asis#1{#1} + +% @math outputs its argument in math mode. +% +% One complication: _ usually means subscripts, but it could also mean +% an actual _ character, as in @math{@var{some_variable} + 1}. So make +% _ active, and distinguish by seeing if the current family is \slfam, +% which is what @var uses. +{ + \catcode\underChar = \active + \gdef\mathunderscore{% + \catcode\underChar=\active + \def_{\ifnum\fam=\slfam \_\else\sb\fi}% + } +} +% Another complication: we want \\ (and @\) to output a \ character. +% FYI, plain.tex uses \\ as a temporary control sequence (why?), but +% this is not advertised and we don't care. Texinfo does not +% otherwise define @\. +% +% The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\. +\def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi} +% +\def\math{% + \tex + \mathunderscore + \let\\ = \mathbackslash + \mathactive + $\finishmath +} +\def\finishmath#1{#1$\endgroup} % Close the group opened by \tex. + +% Some active characters (such as <) are spaced differently in math. +% We have to reset their definitions in case the @math was an argument +% to a command which sets the catcodes (such as @item or @section). +% +{ + \catcode`^ = \active + \catcode`< = \active + \catcode`> = \active + \catcode`+ = \active + \gdef\mathactive{% + \let^ = \ptexhat + \let< = \ptexless + \let> = \ptexgtr + \let+ = \ptexplus + } +} + +% @bullet and @minus need the same treatment as @math, just above. +\def\bullet{$\ptexbullet$} +\def\minus{$-$} + +% @dots{} outputs an ellipsis using the current font. +% We do .5em per period so that it has the same spacing in a typewriter +% font as three actual period characters. +% +\def\dots{% + \leavevmode + \hbox to 1.5em{% + \hskip 0pt plus 0.25fil + .\hfil.\hfil.% + \hskip 0pt plus 0.5fil + }% +} + +% @enddots{} is an end-of-sentence ellipsis. +% +\def\enddots{% + \dots + \spacefactor=\endofsentencespacefactor +} + +% @comma{} is so commas can be inserted into text without messing up +% Texinfo's parsing. +% +\let\comma = , + % @refill is a no-op. \let\refill=\relax @@ -1091,8 +1184,9 @@ \newif\ifpdfmakepagedest % when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1 -% can be set). So we test for \relax and 0 as well as being undefined. -\ifx\pdfoutput\thisisundefined +% can be set). So we test for \relax and 0 as well as \undefined, +% borrowed from ifpdf.sty. +\ifx\pdfoutput\undefined \else \ifx\pdfoutput\relax \else @@ -1103,156 +1197,99 @@ \fi \fi -% PDF uses PostScript string constants for the names of xref targets, +% PDF uses PostScript string constants for the names of xref targets, to % for display in the outlines, and in other places. Thus, we have to % double any backslashes. Otherwise, a name like "\node" will be % interpreted as a newline (\n), followed by o, d, e. Not good. +% http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000654.html +% (and related messages, the final outcome is that it is up to the TeX +% user to double the backslashes and otherwise make the string valid, so +% that's we do). + +% double active backslashes. % -% See http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000654.html and -% related messages. The final outcome is that it is up to the TeX user -% to double the backslashes and otherwise make the string valid, so -% that's what we do. pdftex 1.30.0 (ca.2005) introduced a primitive to -% do this reliably, so we use it. - -% #1 is a control sequence in which to do the replacements, -% which we \xdef. -\def\txiescapepdf#1{% - \ifx\pdfescapestring\thisisundefined - % No primitive available; should we give a warning or log? - % Many times it won't matter. - \else - % The expandable \pdfescapestring primitive escapes parentheses, - % backslashes, and other special chars. - \xdef#1{\pdfescapestring{#1}}% - \fi -} - -\newhelp\nopdfimagehelp{Texinfo supports .png, .jpg, .jpeg, and .pdf images -with PDF output, and none of those formats could be found. (.eps cannot -be supported due to the design of the PDF format; use regular TeX (DVI -output) for that.)} +{\catcode`\@=0 \catcode`\\=\active + @gdef@activebackslash{@catcode`@\=@active @otherbackslash} + @gdef@activebackslashdouble{% + @catcode@backChar=@active + @let\=@doublebackslash} +} + +% To handle parens, we must adopt a different approach, since parens are +% not active characters. hyperref.dtx (which has the same problem as +% us) handles it with this amazing macro to replace tokens. I've +% tinkered with it a little for texinfo, but it's definitely from there. +% +% #1 is the tokens to replace. +% #2 is the replacement. +% #3 is the control sequence with the string. +% +\def\HyPsdSubst#1#2#3{% + \def\HyPsdReplace##1#1##2\END{% + ##1% + \ifx\\##2\\% + \else + #2% + \HyReturnAfterFi{% + \HyPsdReplace##2\END + }% + \fi + }% + \xdef#3{\expandafter\HyPsdReplace#3#1\END}% +} +\long\def\HyReturnAfterFi#1\fi{\fi#1} + +% #1 is a control sequence in which to do the replacements. +\def\backslashparens#1{% + \xdef#1{#1}% redefine it as its expansion; the definition is simply + % \lastnode when called from \setref -> \pdfmkdest. + \HyPsdSubst{(}{\backslashlparen}{#1}% + \HyPsdSubst{)}{\backslashrparen}{#1}% +} + +{\catcode\exclamChar = 0 \catcode\backChar = \other + !gdef!backslashlparen{\(}% + !gdef!backslashrparen{\)}% +} \ifpdf - % - % Color manipulation macros based on pdfcolor.tex, - % except using rgb instead of cmyk; the latter is said to render as a - % very dark gray on-screen and a very dark halftone in print, instead - % of actual black. - \def\rgbDarkRed{0.50 0.09 0.12} - \def\rgbBlack{0 0 0} - % - % k sets the color for filling (usual text, etc.); - % K sets the color for stroking (thin rules, e.g., normal _'s). - \def\pdfsetcolor#1{\pdfliteral{#1 rg #1 RG}} - % - % Set color, and create a mark which defines \thiscolor accordingly, - % so that \makeheadline knows which color to restore. - \def\setcolor#1{% - \xdef\lastcolordefs{\gdef\noexpand\thiscolor{#1}}% - \domark - \pdfsetcolor{#1}% - } - % - \def\maincolor{\rgbBlack} - \pdfsetcolor{\maincolor} - \edef\thiscolor{\maincolor} - \def\lastcolordefs{} - % - \def\makefootline{% - \baselineskip24pt - \line{\pdfsetcolor{\maincolor}\the\footline}% - } - % - \def\makeheadline{% - \vbox to 0pt{% - \vskip-22.5pt - \line{% - \vbox to8.5pt{}% - % Extract \thiscolor definition from the marks. - \getcolormarks - % Typeset the headline with \maincolor, then restore the color. - \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}% - }% - \vss - }% - \nointerlineskip - } - % - % - \pdfcatalog{/PageMode /UseOutlines} - % - % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto). + \input pdfcolor + \pdfcatalog{/PageMode /UseOutlines}% \def\dopdfimage#1#2#3{% - \def\pdfimagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}% - \def\pdfimageheight{#3}\setbox2 = \hbox{\ignorespaces #3}% - % - % pdftex (and the PDF format) support .pdf, .png, .jpg (among - % others). Let's try in that order, PDF first since if - % someone has a scalable image, presumably better to use that than a - % bitmap. - \let\pdfimgext=\empty - \begingroup - \openin 1 #1.pdf \ifeof 1 - \openin 1 #1.PDF \ifeof 1 - \openin 1 #1.png \ifeof 1 - \openin 1 #1.jpg \ifeof 1 - \openin 1 #1.jpeg \ifeof 1 - \openin 1 #1.JPG \ifeof 1 - \errhelp = \nopdfimagehelp - \errmessage{Could not find image file #1 for pdf}% - \else \gdef\pdfimgext{JPG}% - \fi - \else \gdef\pdfimgext{jpeg}% - \fi - \else \gdef\pdfimgext{jpg}% - \fi - \else \gdef\pdfimgext{png}% - \fi - \else \gdef\pdfimgext{PDF}% - \fi - \else \gdef\pdfimgext{pdf}% - \fi - \closein 1 - \endgroup - % - % without \immediate, ancient pdftex seg faults when the same image is + \def\imagewidth{#2}% + \def\imageheight{#3}% + % without \immediate, pdftex seg faults when the same image is % included twice. (Version 3.14159-pre-1.0-unofficial-20010704.) \ifnum\pdftexversion < 14 \immediate\pdfimage \else \immediate\pdfximage \fi - \ifdim \wd0 >0pt width \pdfimagewidth \fi - \ifdim \wd2 >0pt height \pdfimageheight \fi + \ifx\empty\imagewidth\else width \imagewidth \fi + \ifx\empty\imageheight\else height \imageheight \fi \ifnum\pdftexversion<13 - #1.\pdfimgext + #1.pdf% \else - {#1.\pdfimgext}% + {#1.pdf}% \fi \ifnum\pdftexversion < 14 \else \pdfrefximage \pdflastximage \fi} - % \def\pdfmkdest#1{{% % We have to set dummies so commands such as @code, and characters % such as \, aren't expanded when present in a section title. - \indexnofonts - \turnoffactive - \makevalueexpandable + \atdummies + \activebackslashdouble \def\pdfdestname{#1}% - \txiescapepdf\pdfdestname - \safewhatsit{\pdfdest name{\pdfdestname} xyz}% - }} + \backslashparens\pdfdestname + \pdfdest name{\pdfdestname} xyz% + }}% % % used to mark target names; must be expandable. - \def\pdfmkpgn#1{#1} - % - % by default, use a color that is dark enough to print on paper as - % nearly black, but still distinguishable for online viewing. - \def\urlcolor{\rgbDarkRed} - \def\linkcolor{\rgbDarkRed} - \def\endlink{\setcolor{\maincolor}\pdfendlink} - % + \def\pdfmkpgn#1{#1}% + % + \let\linkcolor = \Blue % was Cyan, but that seems light? + \def\endlink{\Black\pdfendlink} % Adding outlines to PDF; macros for calculating structure of outlines % come from Petr Olsak \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0% @@ -1272,24 +1309,29 @@ % page number. We could generate a destination for the section % text in the case where a section has no node, but it doesn't % seem worth the trouble, since most documents are normally structured. - \edef\pdfoutlinedest{#3}% + \def\pdfoutlinedest{#3}% \ifx\pdfoutlinedest\empty \def\pdfoutlinedest{#4}% \else - \txiescapepdf\pdfoutlinedest + % Doubled backslashes in the name. + {\activebackslashdouble \xdef\pdfoutlinedest{#3}% + \backslashparens\pdfoutlinedest}% \fi % - % Also escape PDF chars in the display string. - \edef\pdfoutlinetext{#1}% - \txiescapepdf\pdfoutlinetext + % Also double the backslashes in the display string. + {\activebackslashdouble \xdef\pdfoutlinetext{#1}% + \backslashparens\pdfoutlinetext}% % \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}% } % \def\pdfmakeoutlines{% \begingroup + % Thanh's hack / proper braces in bookmarks + \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace + \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace + % % Read toc silently, to get counts of subentries for \pdfoutline. - \def\partentry##1##2##3##4{}% ignore parts in the outlines \def\numchapentry##1##2##3##4{% \def\thischapnum{##2}% \def\thissecnum{0}% @@ -1343,63 +1385,35 @@ % Latin 2 (0xea) gets translated to a | character. Info from % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100. % - % TODO this right, we have to translate 8-bit characters to - % their "best" equivalent, based on the @documentencoding. Too - % much work for too little return. Just use the ASCII equivalents - % we use for the index sort strings. - % + % xx to do this right, we have to translate 8-bit characters to + % their "best" equivalent, based on the @documentencoding. Right + % now, I guess we'll just let the pdf reader have its way. \indexnofonts \setupdatafile - % We can have normal brace characters in the PDF outlines, unlike - % Texinfo index files. So set that up. - \def\{{\lbracecharliteral}% - \def\}{\rbracecharliteral}% - \catcode`\\=\active \otherbackslash - \input \tocreadfilename + \activebackslash + \input \jobname.toc \endgroup } - {\catcode`[=1 \catcode`]=2 - \catcode`{=\other \catcode`}=\other - \gdef\lbracecharliteral[{]% - \gdef\rbracecharliteral[}]% - ] % \def\skipspaces#1{\def\PP{#1}\def\D{|}% \ifx\PP\D\let\nextsp\relax \else\let\nextsp\skipspaces - \addtokens{\filename}{\PP}% - \advance\filenamelength by 1 + \ifx\p\space\else\addtokens{\filename}{\PP}% + \advance\filenamelength by 1 + \fi \fi \nextsp} - \def\getfilename#1{% - \filenamelength=0 - % If we don't expand the argument now, \skipspaces will get - % snagged on things like "@value{foo}". - \edef\temp{#1}% - \expandafter\skipspaces\temp|\relax - } + \def\getfilename#1{\filenamelength=0\expandafter\skipspaces#1|\relax} \ifnum\pdftexversion < 14 \let \startlink \pdfannotlink \else \let \startlink \pdfstartlink \fi - % make a live url in pdf output. \def\pdfurl#1{% \begingroup - % it seems we really need yet another set of dummies; have not - % tried to figure out what each command should do in the context - % of @url. for now, just make @/ a no-op, that's the only one - % people have actually reported a problem with. - % - \normalturnoffactive - \def\@{@}% - \let\/=\empty + \normalturnoffactive\def\@{@}% \makevalueexpandable - % do we want to go so far as to use \indexnofonts instead of just - % special-casing \var here? - \def\var##1{##1}% - % - \leavevmode\setcolor{\urlcolor}% + \leavevmode\Red \startlink attr{/Border [0 0 0]}% user{/Subtype /Link /A << /S /URI /URI (#1) >>}% \endgroup} @@ -1426,15 +1440,13 @@ {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0} \def\pdflink#1{% \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}} - \setcolor{\linkcolor}#1\endlink} + \linkcolor #1\endlink} \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st} \else - % non-pdf mode \let\pdfmkdest = \gobble \let\pdfurl = \gobble \let\endlink = \relax - \let\setcolor = \gobble - \let\pdfsetcolor = \gobble + \let\linkcolor = \relax \let\pdfmakeoutlines = \relax \fi % \ifx\pdfoutput @@ -1460,10 +1472,6 @@ \def\bf{\fam=\bffam \setfontstyle{bf}}\def\bfstylename{bf} \def\tt{\fam=\ttfam \setfontstyle{tt}} -% Unfortunately, we have to override this for titles and the like, since -% in those cases "rm" is bold. Sigh. -\def\rmisbold{\rm\def\curfontstyle{bf}} - % Texinfo sort of supports the sans serif font style, which plain TeX does not. % So we set up a \sf. \newfam\sffam @@ -1473,6 +1481,8 @@ % We don't need math for this font style. \def\ttsl{\setfontstyle{ttsl}} +% Default leading. +\newdimen\textleading \textleading = 13.2pt % Set the baselineskip to #1, and the lineskip and strut size % correspondingly. There is no deep meaning behind these magic numbers @@ -1482,13 +1492,8 @@ \def\strutheightpercent{.70833} \def\strutdepthpercent {.29167} % -% can get a sort of poor man's double spacing by redefining this. -\def\baselinefactor{1} -% -\newdimen\textleading \def\setleading#1{% - \dimen0 = #1\relax - \normalbaselineskip = \baselinefactor\dimen0 + \normalbaselineskip = #1\relax \normallineskip = \lineskipfactor\normalbaselineskip \normalbaselines \setbox\strutbox =\hbox{% @@ -1497,295 +1502,20 @@ }% } -% PDF CMaps. See also LaTeX's t1.cmap. -% -% do nothing with this by default. -\expandafter\let\csname cmapOT1\endcsname\gobble -\expandafter\let\csname cmapOT1IT\endcsname\gobble -\expandafter\let\csname cmapOT1TT\endcsname\gobble - -% if we are producing pdf, and we have \pdffontattr, then define cmaps. -% (\pdffontattr was introduced many years ago, but people still run -% older pdftex's; it's easy to conditionalize, so we do.) -\ifpdf \ifx\pdffontattr\thisisundefined \else - \begingroup - \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char. - \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap -%%DocumentNeededResources: ProcSet (CIDInit) -%%IncludeResource: ProcSet (CIDInit) -%%BeginResource: CMap (TeX-OT1-0) -%%Title: (TeX-OT1-0 TeX OT1 0) -%%Version: 1.000 -%%EndComments -/CIDInit /ProcSet findresource begin -12 dict begin -begincmap -/CIDSystemInfo -<< /Registry (TeX) -/Ordering (OT1) -/Supplement 0 ->> def -/CMapName /TeX-OT1-0 def -/CMapType 2 def -1 begincodespacerange -<00> <7F> -endcodespacerange -8 beginbfrange -<00> <01> <0393> -<09> <0A> <03A8> -<23> <26> <0023> -<28> <3B> <0028> -<3F> <5B> <003F> -<5D> <5E> <005D> -<61> <7A> <0061> -<7B> <7C> <2013> -endbfrange -40 beginbfchar -<02> <0398> -<03> <039B> -<04> <039E> -<05> <03A0> -<06> <03A3> -<07> <03D2> -<08> <03A6> -<0B> <00660066> -<0C> <00660069> -<0D> <0066006C> -<0E> <006600660069> -<0F> <00660066006C> -<10> <0131> -<11> <0237> -<12> <0060> -<13> <00B4> -<14> <02C7> -<15> <02D8> -<16> <00AF> -<17> <02DA> -<18> <00B8> -<19> <00DF> -<1A> <00E6> -<1B> <0153> -<1C> <00F8> -<1D> <00C6> -<1E> <0152> -<1F> <00D8> -<21> <0021> -<22> <201D> -<27> <2019> -<3C> <00A1> -<3D> <003D> -<3E> <00BF> -<5C> <201C> -<5F> <02D9> -<60> <2018> -<7D> <02DD> -<7E> <007E> -<7F> <00A8> -endbfchar -endcmap -CMapName currentdict /CMap defineresource pop -end -end -%%EndResource -%%EOF - }\endgroup - \expandafter\edef\csname cmapOT1\endcsname#1{% - \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}% - }% -% -% \cmapOT1IT - \begingroup - \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char. - \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap -%%DocumentNeededResources: ProcSet (CIDInit) -%%IncludeResource: ProcSet (CIDInit) -%%BeginResource: CMap (TeX-OT1IT-0) -%%Title: (TeX-OT1IT-0 TeX OT1IT 0) -%%Version: 1.000 -%%EndComments -/CIDInit /ProcSet findresource begin -12 dict begin -begincmap -/CIDSystemInfo -<< /Registry (TeX) -/Ordering (OT1IT) -/Supplement 0 ->> def -/CMapName /TeX-OT1IT-0 def -/CMapType 2 def -1 begincodespacerange -<00> <7F> -endcodespacerange -8 beginbfrange -<00> <01> <0393> -<09> <0A> <03A8> -<25> <26> <0025> -<28> <3B> <0028> -<3F> <5B> <003F> -<5D> <5E> <005D> -<61> <7A> <0061> -<7B> <7C> <2013> -endbfrange -42 beginbfchar -<02> <0398> -<03> <039B> -<04> <039E> -<05> <03A0> -<06> <03A3> -<07> <03D2> -<08> <03A6> -<0B> <00660066> -<0C> <00660069> -<0D> <0066006C> -<0E> <006600660069> -<0F> <00660066006C> -<10> <0131> -<11> <0237> -<12> <0060> -<13> <00B4> -<14> <02C7> -<15> <02D8> -<16> <00AF> -<17> <02DA> -<18> <00B8> -<19> <00DF> -<1A> <00E6> -<1B> <0153> -<1C> <00F8> -<1D> <00C6> -<1E> <0152> -<1F> <00D8> -<21> <0021> -<22> <201D> -<23> <0023> -<24> <00A3> -<27> <2019> -<3C> <00A1> -<3D> <003D> -<3E> <00BF> -<5C> <201C> -<5F> <02D9> -<60> <2018> -<7D> <02DD> -<7E> <007E> -<7F> <00A8> -endbfchar -endcmap -CMapName currentdict /CMap defineresource pop -end -end -%%EndResource -%%EOF - }\endgroup - \expandafter\edef\csname cmapOT1IT\endcsname#1{% - \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}% - }% -% -% \cmapOT1TT - \begingroup - \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char. - \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap -%%DocumentNeededResources: ProcSet (CIDInit) -%%IncludeResource: ProcSet (CIDInit) -%%BeginResource: CMap (TeX-OT1TT-0) -%%Title: (TeX-OT1TT-0 TeX OT1TT 0) -%%Version: 1.000 -%%EndComments -/CIDInit /ProcSet findresource begin -12 dict begin -begincmap -/CIDSystemInfo -<< /Registry (TeX) -/Ordering (OT1TT) -/Supplement 0 ->> def -/CMapName /TeX-OT1TT-0 def -/CMapType 2 def -1 begincodespacerange -<00> <7F> -endcodespacerange -5 beginbfrange -<00> <01> <0393> -<09> <0A> <03A8> -<21> <26> <0021> -<28> <5F> <0028> -<61> <7E> <0061> -endbfrange -32 beginbfchar -<02> <0398> -<03> <039B> -<04> <039E> -<05> <03A0> -<06> <03A3> -<07> <03D2> -<08> <03A6> -<0B> <2191> -<0C> <2193> -<0D> <0027> -<0E> <00A1> -<0F> <00BF> -<10> <0131> -<11> <0237> -<12> <0060> -<13> <00B4> -<14> <02C7> -<15> <02D8> -<16> <00AF> -<17> <02DA> -<18> <00B8> -<19> <00DF> -<1A> <00E6> -<1B> <0153> -<1C> <00F8> -<1D> <00C6> -<1E> <0152> -<1F> <00D8> -<20> <2423> -<27> <2019> -<60> <2018> -<7F> <00A8> -endbfchar -endcmap -CMapName currentdict /CMap defineresource pop -end -end -%%EndResource -%%EOF - }\endgroup - \expandafter\edef\csname cmapOT1TT\endcsname#1{% - \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}% - }% -\fi\fi - - -% Set the font macro #1 to the font named \fontprefix#2. -% #3 is the font's design size, #4 is a scale factor, #5 is the CMap -% encoding (only OT1, OT1IT and OT1TT are allowed, or empty to omit). -% Example: -% #1 = \textrm -% #2 = \rmshape -% #3 = 10 -% #4 = \mainmagstep -% #5 = OT1 -% -\def\setfont#1#2#3#4#5{% - \font#1=\fontprefix#2#3 scaled #4 - \csname cmap#5\endcsname#1% -} -% This is what gets called when #5 of \setfont is empty. -\let\cmap\gobble -% -% (end of cmaps) +% Set the font macro #1 to the font named #2, adding on the +% specified font prefix (normally `cm'). +% #3 is the font's design size, #4 is a scale factor +\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4} % Use cm as the default font prefix. % To specify the font prefix, you must define \fontprefix % before you read in texinfo.tex. -\ifx\fontprefix\thisisundefined +\ifx\fontprefix\undefined \def\fontprefix{cm} \fi % Support font families that don't use the same naming scheme as CM. \def\rmshape{r} -\def\rmbshape{bx} % where the normal face is bold +\def\rmbshape{bx} %where the normal face is bold \def\bfshape{b} \def\bxshape{bx} \def\ttshape{tt} @@ -1800,291 +1530,118 @@ \def\scshape{csc} \def\scbshape{csc} -% Definitions for a main text size of 11pt. (The default in Texinfo.) -% -\def\definetextfontsizexi{% % Text fonts (11.2pt, magstep1). \def\textnominalsize{11pt} \edef\mainmagstep{\magstephalf} -\setfont\textrm\rmshape{10}{\mainmagstep}{OT1} -\setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT} -\setfont\textbf\bfshape{10}{\mainmagstep}{OT1} -\setfont\textit\itshape{10}{\mainmagstep}{OT1IT} -\setfont\textsl\slshape{10}{\mainmagstep}{OT1} -\setfont\textsf\sfshape{10}{\mainmagstep}{OT1} -\setfont\textsc\scshape{10}{\mainmagstep}{OT1} -\setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT} +\setfont\textrm\rmshape{10}{\mainmagstep} +\setfont\texttt\ttshape{10}{\mainmagstep} +\setfont\textbf\bfshape{10}{\mainmagstep} +\setfont\textit\itshape{10}{\mainmagstep} +\setfont\textsl\slshape{10}{\mainmagstep} +\setfont\textsf\sfshape{10}{\mainmagstep} +\setfont\textsc\scshape{10}{\mainmagstep} +\setfont\textttsl\ttslshape{10}{\mainmagstep} \font\texti=cmmi10 scaled \mainmagstep \font\textsy=cmsy10 scaled \mainmagstep -\def\textecsize{1095} % A few fonts for @defun names and args. -\setfont\defbf\bfshape{10}{\magstep1}{OT1} -\setfont\deftt\ttshape{10}{\magstep1}{OT1TT} -\setfont\defttsl\ttslshape{10}{\magstep1}{OT1TT} +\setfont\defbf\bfshape{10}{\magstep1} +\setfont\deftt\ttshape{10}{\magstep1} +\setfont\defttsl\ttslshape{10}{\magstep1} \def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf} % Fonts for indices, footnotes, small examples (9pt). \def\smallnominalsize{9pt} -\setfont\smallrm\rmshape{9}{1000}{OT1} -\setfont\smalltt\ttshape{9}{1000}{OT1TT} -\setfont\smallbf\bfshape{10}{900}{OT1} -\setfont\smallit\itshape{9}{1000}{OT1IT} -\setfont\smallsl\slshape{9}{1000}{OT1} -\setfont\smallsf\sfshape{9}{1000}{OT1} -\setfont\smallsc\scshape{10}{900}{OT1} -\setfont\smallttsl\ttslshape{10}{900}{OT1TT} +\setfont\smallrm\rmshape{9}{1000} +\setfont\smalltt\ttshape{9}{1000} +\setfont\smallbf\bfshape{10}{900} +\setfont\smallit\itshape{9}{1000} +\setfont\smallsl\slshape{9}{1000} +\setfont\smallsf\sfshape{9}{1000} +\setfont\smallsc\scshape{10}{900} +\setfont\smallttsl\ttslshape{10}{900} \font\smalli=cmmi9 \font\smallsy=cmsy9 -\def\smallecsize{0900} % Fonts for small examples (8pt). \def\smallernominalsize{8pt} -\setfont\smallerrm\rmshape{8}{1000}{OT1} -\setfont\smallertt\ttshape{8}{1000}{OT1TT} -\setfont\smallerbf\bfshape{10}{800}{OT1} -\setfont\smallerit\itshape{8}{1000}{OT1IT} -\setfont\smallersl\slshape{8}{1000}{OT1} -\setfont\smallersf\sfshape{8}{1000}{OT1} -\setfont\smallersc\scshape{10}{800}{OT1} -\setfont\smallerttsl\ttslshape{10}{800}{OT1TT} +\setfont\smallerrm\rmshape{8}{1000} +\setfont\smallertt\ttshape{8}{1000} +\setfont\smallerbf\bfshape{10}{800} +\setfont\smallerit\itshape{8}{1000} +\setfont\smallersl\slshape{8}{1000} +\setfont\smallersf\sfshape{8}{1000} +\setfont\smallersc\scshape{10}{800} +\setfont\smallerttsl\ttslshape{10}{800} \font\smalleri=cmmi8 \font\smallersy=cmsy8 -\def\smallerecsize{0800} % Fonts for title page (20.4pt): \def\titlenominalsize{20pt} -\setfont\titlerm\rmbshape{12}{\magstep3}{OT1} -\setfont\titleit\itbshape{10}{\magstep4}{OT1IT} -\setfont\titlesl\slbshape{10}{\magstep4}{OT1} -\setfont\titlett\ttbshape{12}{\magstep3}{OT1TT} -\setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT} -\setfont\titlesf\sfbshape{17}{\magstep1}{OT1} +\setfont\titlerm\rmbshape{12}{\magstep3} +\setfont\titleit\itbshape{10}{\magstep4} +\setfont\titlesl\slbshape{10}{\magstep4} +\setfont\titlett\ttbshape{12}{\magstep3} +\setfont\titlettsl\ttslshape{10}{\magstep4} +\setfont\titlesf\sfbshape{17}{\magstep1} \let\titlebf=\titlerm -\setfont\titlesc\scbshape{10}{\magstep4}{OT1} +\setfont\titlesc\scbshape{10}{\magstep4} \font\titlei=cmmi12 scaled \magstep3 \font\titlesy=cmsy10 scaled \magstep4 -\def\titleecsize{2074} +\def\authorrm{\secrm} +\def\authortt{\sectt} % Chapter (and unnumbered) fonts (17.28pt). \def\chapnominalsize{17pt} -\setfont\chaprm\rmbshape{12}{\magstep2}{OT1} -\setfont\chapit\itbshape{10}{\magstep3}{OT1IT} -\setfont\chapsl\slbshape{10}{\magstep3}{OT1} -\setfont\chaptt\ttbshape{12}{\magstep2}{OT1TT} -\setfont\chapttsl\ttslshape{10}{\magstep3}{OT1TT} -\setfont\chapsf\sfbshape{17}{1000}{OT1} +\setfont\chaprm\rmbshape{12}{\magstep2} +\setfont\chapit\itbshape{10}{\magstep3} +\setfont\chapsl\slbshape{10}{\magstep3} +\setfont\chaptt\ttbshape{12}{\magstep2} +\setfont\chapttsl\ttslshape{10}{\magstep3} +\setfont\chapsf\sfbshape{17}{1000} \let\chapbf=\chaprm -\setfont\chapsc\scbshape{10}{\magstep3}{OT1} +\setfont\chapsc\scbshape{10}{\magstep3} \font\chapi=cmmi12 scaled \magstep2 \font\chapsy=cmsy10 scaled \magstep3 -\def\chapecsize{1728} % Section fonts (14.4pt). \def\secnominalsize{14pt} -\setfont\secrm\rmbshape{12}{\magstep1}{OT1} -\setfont\secit\itbshape{10}{\magstep2}{OT1IT} -\setfont\secsl\slbshape{10}{\magstep2}{OT1} -\setfont\sectt\ttbshape{12}{\magstep1}{OT1TT} -\setfont\secttsl\ttslshape{10}{\magstep2}{OT1TT} -\setfont\secsf\sfbshape{12}{\magstep1}{OT1} +\setfont\secrm\rmbshape{12}{\magstep1} +\setfont\secit\itbshape{10}{\magstep2} +\setfont\secsl\slbshape{10}{\magstep2} +\setfont\sectt\ttbshape{12}{\magstep1} +\setfont\secttsl\ttslshape{10}{\magstep2} +\setfont\secsf\sfbshape{12}{\magstep1} \let\secbf\secrm -\setfont\secsc\scbshape{10}{\magstep2}{OT1} +\setfont\secsc\scbshape{10}{\magstep2} \font\seci=cmmi12 scaled \magstep1 \font\secsy=cmsy10 scaled \magstep2 -\def\sececsize{1440} % Subsection fonts (13.15pt). \def\ssecnominalsize{13pt} -\setfont\ssecrm\rmbshape{12}{\magstephalf}{OT1} -\setfont\ssecit\itbshape{10}{1315}{OT1IT} -\setfont\ssecsl\slbshape{10}{1315}{OT1} -\setfont\ssectt\ttbshape{12}{\magstephalf}{OT1TT} -\setfont\ssecttsl\ttslshape{10}{1315}{OT1TT} -\setfont\ssecsf\sfbshape{12}{\magstephalf}{OT1} +\setfont\ssecrm\rmbshape{12}{\magstephalf} +\setfont\ssecit\itbshape{10}{1315} +\setfont\ssecsl\slbshape{10}{1315} +\setfont\ssectt\ttbshape{12}{\magstephalf} +\setfont\ssecttsl\ttslshape{10}{1315} +\setfont\ssecsf\sfbshape{12}{\magstephalf} \let\ssecbf\ssecrm -\setfont\ssecsc\scbshape{10}{1315}{OT1} +\setfont\ssecsc\scbshape{10}{1315} \font\sseci=cmmi12 scaled \magstephalf \font\ssecsy=cmsy10 scaled 1315 -\def\ssececsize{1200} % Reduced fonts for @acro in text (10pt). \def\reducednominalsize{10pt} -\setfont\reducedrm\rmshape{10}{1000}{OT1} -\setfont\reducedtt\ttshape{10}{1000}{OT1TT} -\setfont\reducedbf\bfshape{10}{1000}{OT1} -\setfont\reducedit\itshape{10}{1000}{OT1IT} -\setfont\reducedsl\slshape{10}{1000}{OT1} -\setfont\reducedsf\sfshape{10}{1000}{OT1} -\setfont\reducedsc\scshape{10}{1000}{OT1} -\setfont\reducedttsl\ttslshape{10}{1000}{OT1TT} +\setfont\reducedrm\rmshape{10}{1000} +\setfont\reducedtt\ttshape{10}{1000} +\setfont\reducedbf\bfshape{10}{1000} +\setfont\reducedit\itshape{10}{1000} +\setfont\reducedsl\slshape{10}{1000} +\setfont\reducedsf\sfshape{10}{1000} +\setfont\reducedsc\scshape{10}{1000} +\setfont\reducedttsl\ttslshape{10}{1000} \font\reducedi=cmmi10 \font\reducedsy=cmsy10 -\def\reducedecsize{1000} - -\textleading = 13.2pt % line spacing for 11pt CM -\textfonts % reset the current fonts -\rm -} % end of 11pt text font size definitions, \definetextfontsizexi - - -% Definitions to make the main text be 10pt Computer Modern, with -% section, chapter, etc., sizes following suit. This is for the GNU -% Press printing of the Emacs 22 manual. Maybe other manuals in the -% future. Used with @smallbook, which sets the leading to 12pt. -% -\def\definetextfontsizex{% -% Text fonts (10pt). -\def\textnominalsize{10pt} -\edef\mainmagstep{1000} -\setfont\textrm\rmshape{10}{\mainmagstep}{OT1} -\setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT} -\setfont\textbf\bfshape{10}{\mainmagstep}{OT1} -\setfont\textit\itshape{10}{\mainmagstep}{OT1IT} -\setfont\textsl\slshape{10}{\mainmagstep}{OT1} -\setfont\textsf\sfshape{10}{\mainmagstep}{OT1} -\setfont\textsc\scshape{10}{\mainmagstep}{OT1} -\setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT} -\font\texti=cmmi10 scaled \mainmagstep -\font\textsy=cmsy10 scaled \mainmagstep -\def\textecsize{1000} - -% A few fonts for @defun names and args. -\setfont\defbf\bfshape{10}{\magstephalf}{OT1} -\setfont\deftt\ttshape{10}{\magstephalf}{OT1TT} -\setfont\defttsl\ttslshape{10}{\magstephalf}{OT1TT} -\def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf} - -% Fonts for indices, footnotes, small examples (9pt). -\def\smallnominalsize{9pt} -\setfont\smallrm\rmshape{9}{1000}{OT1} -\setfont\smalltt\ttshape{9}{1000}{OT1TT} -\setfont\smallbf\bfshape{10}{900}{OT1} -\setfont\smallit\itshape{9}{1000}{OT1IT} -\setfont\smallsl\slshape{9}{1000}{OT1} -\setfont\smallsf\sfshape{9}{1000}{OT1} -\setfont\smallsc\scshape{10}{900}{OT1} -\setfont\smallttsl\ttslshape{10}{900}{OT1TT} -\font\smalli=cmmi9 -\font\smallsy=cmsy9 -\def\smallecsize{0900} - -% Fonts for small examples (8pt). -\def\smallernominalsize{8pt} -\setfont\smallerrm\rmshape{8}{1000}{OT1} -\setfont\smallertt\ttshape{8}{1000}{OT1TT} -\setfont\smallerbf\bfshape{10}{800}{OT1} -\setfont\smallerit\itshape{8}{1000}{OT1IT} -\setfont\smallersl\slshape{8}{1000}{OT1} -\setfont\smallersf\sfshape{8}{1000}{OT1} -\setfont\smallersc\scshape{10}{800}{OT1} -\setfont\smallerttsl\ttslshape{10}{800}{OT1TT} -\font\smalleri=cmmi8 -\font\smallersy=cmsy8 -\def\smallerecsize{0800} - -% Fonts for title page (20.4pt): -\def\titlenominalsize{20pt} -\setfont\titlerm\rmbshape{12}{\magstep3}{OT1} -\setfont\titleit\itbshape{10}{\magstep4}{OT1IT} -\setfont\titlesl\slbshape{10}{\magstep4}{OT1} -\setfont\titlett\ttbshape{12}{\magstep3}{OT1TT} -\setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT} -\setfont\titlesf\sfbshape{17}{\magstep1}{OT1} -\let\titlebf=\titlerm -\setfont\titlesc\scbshape{10}{\magstep4}{OT1} -\font\titlei=cmmi12 scaled \magstep3 -\font\titlesy=cmsy10 scaled \magstep4 -\def\titleecsize{2074} - -% Chapter fonts (14.4pt). -\def\chapnominalsize{14pt} -\setfont\chaprm\rmbshape{12}{\magstep1}{OT1} -\setfont\chapit\itbshape{10}{\magstep2}{OT1IT} -\setfont\chapsl\slbshape{10}{\magstep2}{OT1} -\setfont\chaptt\ttbshape{12}{\magstep1}{OT1TT} -\setfont\chapttsl\ttslshape{10}{\magstep2}{OT1TT} -\setfont\chapsf\sfbshape{12}{\magstep1}{OT1} -\let\chapbf\chaprm -\setfont\chapsc\scbshape{10}{\magstep2}{OT1} -\font\chapi=cmmi12 scaled \magstep1 -\font\chapsy=cmsy10 scaled \magstep2 -\def\chapecsize{1440} - -% Section fonts (12pt). -\def\secnominalsize{12pt} -\setfont\secrm\rmbshape{12}{1000}{OT1} -\setfont\secit\itbshape{10}{\magstep1}{OT1IT} -\setfont\secsl\slbshape{10}{\magstep1}{OT1} -\setfont\sectt\ttbshape{12}{1000}{OT1TT} -\setfont\secttsl\ttslshape{10}{\magstep1}{OT1TT} -\setfont\secsf\sfbshape{12}{1000}{OT1} -\let\secbf\secrm -\setfont\secsc\scbshape{10}{\magstep1}{OT1} -\font\seci=cmmi12 -\font\secsy=cmsy10 scaled \magstep1 -\def\sececsize{1200} - -% Subsection fonts (10pt). -\def\ssecnominalsize{10pt} -\setfont\ssecrm\rmbshape{10}{1000}{OT1} -\setfont\ssecit\itbshape{10}{1000}{OT1IT} -\setfont\ssecsl\slbshape{10}{1000}{OT1} -\setfont\ssectt\ttbshape{10}{1000}{OT1TT} -\setfont\ssecttsl\ttslshape{10}{1000}{OT1TT} -\setfont\ssecsf\sfbshape{10}{1000}{OT1} -\let\ssecbf\ssecrm -\setfont\ssecsc\scbshape{10}{1000}{OT1} -\font\sseci=cmmi10 -\font\ssecsy=cmsy10 -\def\ssececsize{1000} - -% Reduced fonts for @acro in text (9pt). -\def\reducednominalsize{9pt} -\setfont\reducedrm\rmshape{9}{1000}{OT1} -\setfont\reducedtt\ttshape{9}{1000}{OT1TT} -\setfont\reducedbf\bfshape{10}{900}{OT1} -\setfont\reducedit\itshape{9}{1000}{OT1IT} -\setfont\reducedsl\slshape{9}{1000}{OT1} -\setfont\reducedsf\sfshape{9}{1000}{OT1} -\setfont\reducedsc\scshape{10}{900}{OT1} -\setfont\reducedttsl\ttslshape{10}{900}{OT1TT} -\font\reducedi=cmmi9 -\font\reducedsy=cmsy9 -\def\reducedecsize{0900} - -\divide\parskip by 2 % reduce space between paragraphs -\textleading = 12pt % line spacing for 10pt CM -\textfonts % reset the current fonts -\rm -} % end of 10pt text font size definitions, \definetextfontsizex - - -% We provide the user-level command -% @fonttextsize 10 -% (or 11) to redefine the text font size. pt is assumed. -% -\def\xiword{11} -\def\xword{10} -\def\xwordpt{10pt} -% -\parseargdef\fonttextsize{% - \def\textsizearg{#1}% - %\wlog{doing @fonttextsize \textsizearg}% - % - % Set \globaldefs so that documents can use this inside @tex, since - % makeinfo 4.8 does not support it, but we need it nonetheless. - % - \begingroup \globaldefs=1 - \ifx\textsizearg\xword \definetextfontsizex - \else \ifx\textsizearg\xiword \definetextfontsizexi - \else - \errhelp=\EMsimple - \errmessage{@fonttextsize only supports `10' or `11', not `\textsizearg'} - \fi\fi - \endgroup -} - % In order for the font changes to affect most math symbols and letters, % we have to define the \textfont of the standard families. Since @@ -2124,8 +1681,8 @@ \let\tenttsl=\titlettsl \def\curfontsize{title}% \def\lsize{chap}\def\lllsize{subsec}% - \resetmathfonts \setleading{27pt}} -\def\titlefont#1{{\titlefonts\rmisbold #1}} + \resetmathfonts \setleading{25pt}} +\def\titlefont#1{{\titlefonts\rm #1}} \def\chapfonts{% \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc @@ -2176,16 +1733,6 @@ \def\lsize{smaller}\def\lllsize{smaller}% \resetmathfonts \setleading{9.5pt}} -% Fonts for short table of contents. -\setfont\shortcontrm\rmshape{12}{1000}{OT1} -\setfont\shortcontbf\bfshape{10}{\magstep1}{OT1} % no cmb12 -\setfont\shortcontsl\slshape{12}{1000}{OT1} -\setfont\shortconttt\ttshape{12}{1000}{OT1TT} - -% Define these just so they can be easily changed for other fonts. -\def\angleleft{$\langle$} -\def\angleright{$\rangle$} - % Set the fonts to use with the @small... environments. \let\smallexamplefonts = \smallfonts @@ -2199,215 +1746,53 @@ % % By the way, for comparison, here's what fits with @example (10pt): % 8.5x11=71 smallbook=60 a4=75 a5=58 +% +% I wish the USA used A4 paper. % --karl, 24jan03. + % Set up the default fonts, so we can use them for creating boxes. % -\definetextfontsizexi - - -\message{markup,} - -% Check if we are currently using a typewriter font. Since all the -% Computer Modern typewriter fonts have zero interword stretch (and -% shrink), and it is reasonable to expect all typewriter fonts to have -% this property, we can check that font parameter. -% -\def\ifmonospace{\ifdim\fontdimen3\font=0pt } - -% Markup style infrastructure. \defmarkupstylesetup\INITMACRO will -% define and register \INITMACRO to be called on markup style changes. -% \INITMACRO can check \currentmarkupstyle for the innermost -% style and the set of \ifmarkupSTYLE switches for all styles -% currently in effect. -\newif\ifmarkupvar -\newif\ifmarkupsamp -\newif\ifmarkupkey -%\newif\ifmarkupfile % @file == @samp. -%\newif\ifmarkupoption % @option == @samp. -\newif\ifmarkupcode -\newif\ifmarkupkbd -%\newif\ifmarkupenv % @env == @code. -%\newif\ifmarkupcommand % @command == @code. -\newif\ifmarkuptex % @tex (and part of @math, for now). -\newif\ifmarkupexample -\newif\ifmarkupverb -\newif\ifmarkupverbatim - -\let\currentmarkupstyle\empty - -\def\setupmarkupstyle#1{% - \csname markup#1true\endcsname - \def\currentmarkupstyle{#1}% - \markupstylesetup -} - -\let\markupstylesetup\empty - -\def\defmarkupstylesetup#1{% - \expandafter\def\expandafter\markupstylesetup - \expandafter{\markupstylesetup #1}% - \def#1% -} - -% Markup style setup for left and right quotes. -\defmarkupstylesetup\markupsetuplq{% - \expandafter\let\expandafter \temp - \csname markupsetuplq\currentmarkupstyle\endcsname - \ifx\temp\relax \markupsetuplqdefault \else \temp \fi -} - -\defmarkupstylesetup\markupsetuprq{% - \expandafter\let\expandafter \temp - \csname markupsetuprq\currentmarkupstyle\endcsname - \ifx\temp\relax \markupsetuprqdefault \else \temp \fi -} - -{ -\catcode`\'=\active -\catcode`\`=\active - -\gdef\markupsetuplqdefault{\let`\lq} -\gdef\markupsetuprqdefault{\let'\rq} - -\gdef\markupsetcodequoteleft{\let`\codequoteleft} -\gdef\markupsetcodequoteright{\let'\codequoteright} - -\gdef\markupsetnoligaturesquoteleft{\let`\noligaturesquoteleft} -} - -\let\markupsetuplqcode \markupsetcodequoteleft -\let\markupsetuprqcode \markupsetcodequoteright -% -\let\markupsetuplqexample \markupsetcodequoteleft -\let\markupsetuprqexample \markupsetcodequoteright -% -\let\markupsetuplqsamp \markupsetcodequoteleft -\let\markupsetuprqsamp \markupsetcodequoteright -% -\let\markupsetuplqverb \markupsetcodequoteleft -\let\markupsetuprqverb \markupsetcodequoteright -% -\let\markupsetuplqverbatim \markupsetcodequoteleft -\let\markupsetuprqverbatim \markupsetcodequoteright - -\let\markupsetuplqkbd \markupsetnoligaturesquoteleft - -% Allow an option to not use regular directed right quote/apostrophe -% (char 0x27), but instead the undirected quote from cmtt (char 0x0d). -% The undirected quote is ugly, so don't make it the default, but it -% works for pasting with more pdf viewers (at least evince), the -% lilypond developers report. xpdf does work with the regular 0x27. -% -\def\codequoteright{% - \expandafter\ifx\csname SETtxicodequoteundirected\endcsname\relax - \expandafter\ifx\csname SETcodequoteundirected\endcsname\relax - '% - \else \char'15 \fi - \else \char'15 \fi -} -% -% and a similar option for the left quote char vs. a grave accent. -% Modern fonts display ASCII 0x60 as a grave accent, so some people like -% the code environments to do likewise. -% -\def\codequoteleft{% - \expandafter\ifx\csname SETtxicodequotebacktick\endcsname\relax - \expandafter\ifx\csname SETcodequotebacktick\endcsname\relax - % [Knuth] pp. 380,381,391 - % \relax disables Spanish ligatures ?` and !` of \tt font. - \relax`% - \else \char'22 \fi - \else \char'22 \fi -} - -% Commands to set the quote options. -% -\parseargdef\codequoteundirected{% - \def\temp{#1}% - \ifx\temp\onword - \expandafter\let\csname SETtxicodequoteundirected\endcsname - = t% - \else\ifx\temp\offword - \expandafter\let\csname SETtxicodequoteundirected\endcsname - = \relax - \else - \errhelp = \EMsimple - \errmessage{Unknown @codequoteundirected value `\temp', must be on|off}% - \fi\fi -} -% -\parseargdef\codequotebacktick{% - \def\temp{#1}% - \ifx\temp\onword - \expandafter\let\csname SETtxicodequotebacktick\endcsname - = t% - \else\ifx\temp\offword - \expandafter\let\csname SETtxicodequotebacktick\endcsname - = \relax - \else - \errhelp = \EMsimple - \errmessage{Unknown @codequotebacktick value `\temp', must be on|off}% - \fi\fi -} - -% [Knuth] pp. 380,381,391, disable Spanish ligatures ?` and !` of \tt font. -\def\noligaturesquoteleft{\relax\lq} +\textfonts \rm + +% Define these so they can be easily changed for other fonts. +\def\angleleft{$\langle$} +\def\angleright{$\rangle$} % Count depth in font-changes, for error checks \newcount\fontdepth \fontdepth=0 -% Font commands. - -% #1 is the font command (\sl or \it), #2 is the text to slant. -% If we are in a monospaced environment, however, 1) always use \ttsl, -% and 2) do not add an italic correction. -\def\dosmartslant#1#2{% - \ifusingtt - {{\ttsl #2}\let\next=\relax}% - {\def\next{{#1#2}\futurelet\next\smartitaliccorrection}}% - \next -} -\def\smartslanted{\dosmartslant\sl} -\def\smartitalic{\dosmartslant\it} - -% Output an italic correction unless \next (presumed to be the following -% character) is such as not to need one. -\def\smartitaliccorrection{% - \ifx\next,% - \else\ifx\next-% - \else\ifx\next.% - \else\ptexslash - \fi\fi\fi - \aftersmartic -} - -% like \smartslanted except unconditionally uses \ttsl, and no ic. +% Fonts for short table of contents. +\setfont\shortcontrm\rmshape{12}{1000} +\setfont\shortcontbf\bfshape{10}{\magstep1} % no cmb12 +\setfont\shortcontsl\slshape{12}{1000} +\setfont\shortconttt\ttshape{12}{1000} + +%% Add scribe-like font environments, plus @l for inline lisp (usually sans +%% serif) and @ii for TeX italic + +% \smartitalic{ARG} outputs arg in italics, followed by an italic correction +% unless the following character is such as not to need one. +\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else + \ptexslash\fi\fi\fi} +\def\smartslanted#1{{\ifusingtt\ttsl\sl #1}\futurelet\next\smartitalicx} +\def\smartitalic#1{{\ifusingtt\ttsl\it #1}\futurelet\next\smartitalicx} + +% like \smartslanted except unconditionally uses \ttsl. % @var is set to this for defun arguments. -\def\ttslanted#1{{\ttsl #1}} - -% @cite is like \smartslanted except unconditionally use \sl. We never want +\def\ttslanted#1{{\ttsl #1}\futurelet\next\smartitalicx} + +% like \smartslanted except unconditionally use \sl. We never want % ttsl for book titles, do we? -\def\cite#1{{\sl #1}\futurelet\next\smartitaliccorrection} - -\def\aftersmartic{} -\def\var#1{% - \let\saveaftersmartic = \aftersmartic - \def\aftersmartic{\null\let\aftersmartic=\saveaftersmartic}% - \smartslanted{#1}% -} +\def\cite#1{{\sl #1}\futurelet\next\smartitalicx} \let\i=\smartitalic \let\slanted=\smartslanted +\let\var=\smartslanted \let\dfn=\smartslanted \let\emph=\smartitalic -% Explicit font changes: @r, @sc, undocumented @ii. -\def\r#1{{\rm #1}} % roman font -\def\sc#1{{\smallcaps#1}} % smallcaps font -\def\ii#1{{\it #1}} % italic font - -% @b, explicit bold. Also @strong. +% @b, explicit bold. \def\b#1{{\bf #1}} \let\strong=\b @@ -2439,35 +1824,21 @@ \catcode`@=\other \def\endofsentencespacefactor{3000}% default -% @t, explicit typewriter. \def\t#1{% {\tt \rawbackslash \plainfrenchspacing #1}% \null } - -% @samp. -\def\samp#1{{\setupmarkupstyle{samp}\lq\tclose{#1}\rq\null}} - -% definition of @key that produces a lozenge. Doesn't adjust to text size. -%\setfont\keyrm\rmshape{8}{1000}{OT1} -%\font\keysy=cmsy9 -%\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{% -% \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{% -% \vbox{\hrule\kern-0.4pt -% \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}% -% \kern-0.4pt\hrule}% -% \kern-.06em\raise0.4pt\hbox{\angleright}}}} - -% definition of @key with no lozenge. If the current font is already -% monospace, don't change it; that way, we respect @kbdinputstyle. But -% if it isn't monospace, then use \tt. -% -\def\key#1{{\setupmarkupstyle{key}% - \nohyphenation - \ifmonospace\else\tt\fi - #1}\null} - -% ctrl is no longer a Texinfo command. +\def\samp#1{`\tclose{#1}'\null} +\setfont\keyrm\rmshape{8}{1000} +\font\keysy=cmsy9 +\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{% + \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{% + \vbox{\hrule\kern-0.4pt + \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}% + \kern-0.4pt\hrule}% + \kern-.06em\raise0.4pt\hbox{\angleright}}}} +% The old definition, with no lozenge: +%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null} \def\ctrl #1{{\tt \rawbackslash \hat}#1} % @file, @option are the same as @samp. @@ -2494,7 +1865,7 @@ \plainfrenchspacing #1% }% - \null % reset spacefactor to 1000 + \null } % We *must* turn on hyphenation at `-' and `_' in @code. @@ -2507,14 +1878,11 @@ % and arrange explicitly to hyphenate at a dash. % -- rms. { - \catcode`\-=\active \catcode`\_=\active - \catcode`\'=\active \catcode`\`=\active - \global\let'=\rq \global\let`=\lq % default definitions + \catcode`\-=\active + \catcode`\_=\active % \global\def\code{\begingroup - \setupmarkupstyle{code}% - % The following should really be moved into \setupmarkupstyle handlers. - \catcode\dashChar=\active \catcode\underChar=\active + \catcode`\-=\active \catcode`\_=\active \ifallowcodebreaks \let-\codedash \let_\codeunder @@ -2526,8 +1894,6 @@ } } -\def\codex #1{\tclose{#1}\endgroup} - \def\realdash{-} \def\codedash{-\discretionary{}{}{}} \def\codeunder{% @@ -2541,12 +1907,13 @@ \discretionary{}{}{}}% {\_}% } +\def\codex #1{\tclose{#1}\endgroup} % An additional complication: the above will allow breaks after, e.g., % each of the four underscores in __typeof__. This is undesirable in % some manuals, especially if they don't have long identifiers in % general. @allowcodebreaks provides a way to control this. -% +% \newif\ifallowcodebreaks \allowcodebreakstrue \def\keywordtrue{true} @@ -2560,18 +1927,55 @@ \allowcodebreaksfalse \else \errhelp = \EMsimple - \errmessage{Unknown @allowcodebreaks option `\txiarg', must be true|false}% + \errmessage{Unknown @allowcodebreaks option `\txiarg'}% \fi\fi } +% @kbd is like @code, except that if the argument is just one @key command, +% then @kbd has no effect. + +% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always), +% `example' (@kbd uses ttsl only inside of @example and friends), +% or `code' (@kbd uses normal tty font always). +\parseargdef\kbdinputstyle{% + \def\txiarg{#1}% + \ifx\txiarg\worddistinct + \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}% + \else\ifx\txiarg\wordexample + \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}% + \else\ifx\txiarg\wordcode + \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}% + \else + \errhelp = \EMsimple + \errmessage{Unknown @kbdinputstyle option `\txiarg'}% + \fi\fi\fi +} +\def\worddistinct{distinct} +\def\wordexample{example} +\def\wordcode{code} + +% Default is `distinct.' +\kbdinputstyle distinct + +\def\xkey{\key} +\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}% +\ifx\one\xkey\ifx\threex\three \key{#2}% +\else{\tclose{\kbdfont\look}}\fi +\else{\tclose{\kbdfont\look}}\fi} + +% For @indicateurl, @env, @command quotes seem unnecessary, so use \code. +\let\indicateurl=\code +\let\env=\code +\let\command=\code + % @uref (abbreviation for `urlref') takes an optional (comma-separated) % second argument specifying the text to display and an optional third % arg as text to display instead of (rather than in addition to) the url -% itself. First (mandatory) arg is the url. -% (This \urefnobreak definition isn't used now, leaving it for a while -% for comparison.) -\def\urefnobreak#1{\dourefnobreak #1,,,\finish} -\def\dourefnobreak#1,#2,#3,#4\finish{\begingroup +% itself. First (mandatory) arg is the url. Perhaps eventually put in +% a hypertex \special here. +% +\def\uref#1{\douref #1,,,\finish} +\def\douref#1,#2,#3,#4\finish{\begingroup \unsepspaces \pdfurl{#1}% \setbox0 = \hbox{\ignorespaces #3}% @@ -2592,103 +1996,6 @@ \endlink \endgroup} -% This \urefbreak definition is the active one. -\def\urefbreak{\begingroup \urefcatcodes \dourefbreak} -\let\uref=\urefbreak -\def\dourefbreak#1{\urefbreakfinish #1,,,\finish} -\def\urefbreakfinish#1,#2,#3,#4\finish{% doesn't work in @example - \unsepspaces - \pdfurl{#1}% - \setbox0 = \hbox{\ignorespaces #3}% - \ifdim\wd0 > 0pt - \unhbox0 % third arg given, show only that - \else - \setbox0 = \hbox{\ignorespaces #2}% - \ifdim\wd0 > 0pt - \ifpdf - \unhbox0 % PDF: 2nd arg given, show only it - \else - \unhbox0\ (\urefcode{#1})% DVI: 2nd arg given, show both it and url - \fi - \else - \urefcode{#1}% only url given, so show it - \fi - \fi - \endlink -\endgroup} - -% Allow line breaks around only a few characters (only). -\def\urefcatcodes{% - \catcode\ampChar=\active \catcode\dotChar=\active - \catcode\hashChar=\active \catcode\questChar=\active - \catcode\slashChar=\active -} -{ - \urefcatcodes - % - \global\def\urefcode{\begingroup - \setupmarkupstyle{code}% - \urefcatcodes - \let&\urefcodeamp - \let.\urefcodedot - \let#\urefcodehash - \let?\urefcodequest - \let/\urefcodeslash - \codex - } - % - % By default, they are just regular characters. - \global\def&{\normalamp} - \global\def.{\normaldot} - \global\def#{\normalhash} - \global\def?{\normalquest} - \global\def/{\normalslash} -} - -% we put a little stretch before and after the breakable chars, to help -% line breaking of long url's. The unequal skips make look better in -% cmtt at least, especially for dots. -\def\urefprestretch{\urefprebreak \hskip0pt plus.13em } -\def\urefpoststretch{\urefpostbreak \hskip0pt plus.1em } -% -\def\urefcodeamp{\urefprestretch \&\urefpoststretch} -\def\urefcodedot{\urefprestretch .\urefpoststretch} -\def\urefcodehash{\urefprestretch \#\urefpoststretch} -\def\urefcodequest{\urefprestretch ?\urefpoststretch} -\def\urefcodeslash{\futurelet\next\urefcodeslashfinish} -{ - \catcode`\/=\active - \global\def\urefcodeslashfinish{% - \urefprestretch \slashChar - % Allow line break only after the final / in a sequence of - % slashes, to avoid line break between the slashes in http://. - \ifx\next/\else \urefpoststretch \fi - } -} - -% One more complication: by default we'll break after the special -% characters, but some people like to break before the special chars, so -% allow that. Also allow no breaking at all, for manual control. -% -\parseargdef\urefbreakstyle{% - \def\txiarg{#1}% - \ifx\txiarg\wordnone - \def\urefprebreak{\nobreak}\def\urefpostbreak{\nobreak} - \else\ifx\txiarg\wordbefore - \def\urefprebreak{\allowbreak}\def\urefpostbreak{\nobreak} - \else\ifx\txiarg\wordafter - \def\urefprebreak{\nobreak}\def\urefpostbreak{\allowbreak} - \else - \errhelp = \EMsimple - \errmessage{Unknown @urefbreakstyle setting `\txiarg'}% - \fi\fi\fi -} -\def\wordafter{after} -\def\wordbefore{before} -\def\wordnone{none} - -\urefbreakstyle after - % @url synonym for @uref, since that's how everyone uses it. % \let\url=\uref @@ -2710,65 +2017,34 @@ \let\email=\uref \fi -% @kbd is like @code, except that if the argument is just one @key command, -% then @kbd has no effect. -\def\kbd#1{{\setupmarkupstyle{kbd}\def\look{#1}\expandafter\kbdfoo\look??\par}} - -% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always), -% `example' (@kbd uses ttsl only inside of @example and friends), -% or `code' (@kbd uses normal tty font always). -\parseargdef\kbdinputstyle{% - \def\txiarg{#1}% - \ifx\txiarg\worddistinct - \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}% - \else\ifx\txiarg\wordexample - \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}% - \else\ifx\txiarg\wordcode - \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}% - \else - \errhelp = \EMsimple - \errmessage{Unknown @kbdinputstyle setting `\txiarg'}% - \fi\fi\fi -} -\def\worddistinct{distinct} -\def\wordexample{example} -\def\wordcode{code} - -% Default is `distinct'. -\kbdinputstyle distinct - -\def\xkey{\key} -\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}% -\ifx\one\xkey\ifx\threex\three \key{#2}% -\else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi -\else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi} - -% For @indicateurl, @env, @command quotes seem unnecessary, so use \code. -\let\indicateurl=\code -\let\env=\code -\let\command=\code - -% @clicksequence{File @click{} Open ...} -\def\clicksequence#1{\begingroup #1\endgroup} - -% @clickstyle @arrow (by default) -\parseargdef\clickstyle{\def\click{#1}} -\def\click{\arrow} +% Check if we are currently using a typewriter font. Since all the +% Computer Modern typewriter fonts have zero interword stretch (and +% shrink), and it is reasonable to expect all typewriter fonts to have +% this property, we can check that font parameter. +% +\def\ifmonospace{\ifdim\fontdimen3\font=0pt } % Typeset a dimension, e.g., `in' or `pt'. The only reason for the % argument is to make the input look right: @dmn{pt} instead of @dmn{}pt. % \def\dmn#1{\thinspace #1} +\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par} + % @l was never documented to mean ``switch to the Lisp font'', % and it is not used as such in any manual I can find. We need it for % Polish suppressed-l. --karl, 22sep96. %\def\l#1{{\li #1}\null} +% Explicit font changes: @r, @sc, undocumented @ii. +\def\r#1{{\rm #1}} % roman font +\def\sc#1{{\smallcaps#1}} % smallcaps font +\def\ii#1{{\it #1}} % italic font + % @acronym for "FBI", "NATO", and the like. % We print this one point size smaller, since it's intended for % all-uppercase. -% +% \def\acronym#1{\doacronym #1,,\finish} \def\doacronym#1,#2,#3\finish{% {\selectfonts\lsize #1}% @@ -2776,12 +2052,11 @@ \ifx\temp\empty \else \space ({\unsepspaces \ignorespaces \temp \unskip})% \fi - \null % reset \spacefactor=1000 } % @abbr for "Comput. J." and the like. % No font change, but don't do end-of-sentence spacing. -% +% \def\abbr#1{\doabbr #1,,\finish} \def\doabbr#1,#2,#3\finish{% {\plainfrenchspacing #1}% @@ -2789,254 +2064,7 @@ \ifx\temp\empty \else \space ({\unsepspaces \ignorespaces \temp \unskip})% \fi - \null % reset \spacefactor=1000 -} - -% @asis just yields its argument. Used with @table, for example. -% -\def\asis#1{#1} - -% @math outputs its argument in math mode. -% -% One complication: _ usually means subscripts, but it could also mean -% an actual _ character, as in @math{@var{some_variable} + 1}. So make -% _ active, and distinguish by seeing if the current family is \slfam, -% which is what @var uses. -{ - \catcode`\_ = \active - \gdef\mathunderscore{% - \catcode`\_=\active - \def_{\ifnum\fam=\slfam \_\else\sb\fi}% - } -} -% Another complication: we want \\ (and @\) to output a math (or tt) \. -% FYI, plain.tex uses \\ as a temporary control sequence (for no -% particular reason), but this is not advertised and we don't care. -% -% The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\. -\def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi} -% -\def\math{% - \tex - \mathunderscore - \let\\ = \mathbackslash - \mathactive - % make the texinfo accent commands work in math mode - \let\"=\ddot - \let\'=\acute - \let\==\bar - \let\^=\hat - \let\`=\grave - \let\u=\breve - \let\v=\check - \let\~=\tilde - \let\dotaccent=\dot - $\finishmath -} -\def\finishmath#1{#1$\endgroup} % Close the group opened by \tex. - -% Some active characters (such as <) are spaced differently in math. -% We have to reset their definitions in case the @math was an argument -% to a command which sets the catcodes (such as @item or @section). -% -{ - \catcode`^ = \active - \catcode`< = \active - \catcode`> = \active - \catcode`+ = \active - \catcode`' = \active - \gdef\mathactive{% - \let^ = \ptexhat - \let< = \ptexless - \let> = \ptexgtr - \let+ = \ptexplus - \let' = \ptexquoteright - } -} - -% @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}. -% Ignore unless FMTNAME == tex; then it is like @iftex and @tex, -% except specified as a normal braced arg, so no newlines to worry about. -% -\def\outfmtnametex{tex} -% -\long\def\inlinefmt#1{\doinlinefmt #1,\finish} -\long\def\doinlinefmt#1,#2,\finish{% - \def\inlinefmtname{#1}% - \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\fi -} -% For raw, must switch into @tex before parsing the argument, to avoid -% setting catcodes prematurely. Doing it this way means that, for -% example, @inlineraw{html, foo{bar} gets a parse error instead of being -% ignored. But this isn't important because if people want a literal -% *right* brace they would have to use a command anyway, so they may as -% well use a command to get a left brace too. We could re-use the -% delimiter character idea from \verb, but it seems like overkill. -% -\long\def\inlineraw{\tex \doinlineraw} -\long\def\doinlineraw#1{\doinlinerawtwo #1,\finish} -\def\doinlinerawtwo#1,#2,\finish{% - \def\inlinerawname{#1}% - \ifx\inlinerawname\outfmtnametex \ignorespaces #2\fi - \endgroup % close group opened by \tex. -} - - -\message{glyphs,} -% and logos. - -% @@ prints an @, as does @atchar{}. -\def\@{\char64 } -\let\atchar=\@ - -% @{ @} @lbracechar{} @rbracechar{} all generate brace characters. -% Unless we're in typewriter, use \ecfont because the CM text fonts do -% not have braces, and we don't want to switch into math. -\def\mylbrace{{\ifmonospace\else\ecfont\fi \char123}} -\def\myrbrace{{\ifmonospace\else\ecfont\fi \char125}} -\let\{=\mylbrace \let\lbracechar=\{ -\let\}=\myrbrace \let\rbracechar=\} -\begingroup - % Definitions to produce \{ and \} commands for indices, - % and @{ and @} for the aux/toc files. - \catcode`\{ = \other \catcode`\} = \other - \catcode`\[ = 1 \catcode`\] = 2 - \catcode`\! = 0 \catcode`\\ = \other - !gdef!lbracecmd[\{]% - !gdef!rbracecmd[\}]% - !gdef!lbraceatcmd[@{]% - !gdef!rbraceatcmd[@}]% -!endgroup - -% @comma{} to avoid , parsing problems. -\let\comma = , - -% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent -% Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H. -\let\, = \ptexc -\let\dotaccent = \ptexdot -\def\ringaccent#1{{\accent23 #1}} -\let\tieaccent = \ptext -\let\ubaraccent = \ptexb -\let\udotaccent = \d - -% Other special characters: @questiondown @exclamdown @ordf @ordm -% Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss. -\def\questiondown{?`} -\def\exclamdown{!`} -\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}} -\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}} - -% Dotless i and dotless j, used for accents. -\def\imacro{i} -\def\jmacro{j} -\def\dotless#1{% - \def\temp{#1}% - \ifx\temp\imacro \ifmmode\imath \else\ptexi \fi - \else\ifx\temp\jmacro \ifmmode\jmath \else\j \fi - \else \errmessage{@dotless can be used only with i or j}% - \fi\fi -} - -% The \TeX{} logo, as in plain, but resetting the spacing so that a -% period following counts as ending a sentence. (Idea found in latex.) -% -\edef\TeX{\TeX \spacefactor=1000 } - -% @LaTeX{} logo. Not quite the same results as the definition in -% latex.ltx, since we use a different font for the raised A; it's most -% convenient for us to use an explicitly smaller font, rather than using -% the \scriptstyle font (since we don't reset \scriptstyle and -% \scriptscriptstyle). -% -\def\LaTeX{% - L\kern-.36em - {\setbox0=\hbox{T}% - \vbox to \ht0{\hbox{% - \ifx\textnominalsize\xwordpt - % for 10pt running text, \lllsize (8pt) is too small for the A in LaTeX. - % Revert to plain's \scriptsize, which is 7pt. - \count255=\the\fam $\fam\count255 \scriptstyle A$% - \else - % For 11pt, we can use our lllsize. - \selectfonts\lllsize A% - \fi - }% - \vss - }}% - \kern-.15em - \TeX -} - -% Some math mode symbols. -\def\bullet{$\ptexbullet$} -\def\geq{\ifmmode \ge\else $\ge$\fi} -\def\leq{\ifmmode \le\else $\le$\fi} -\def\minus{\ifmmode -\else $-$\fi} - -% @dots{} outputs an ellipsis using the current font. -% We do .5em per period so that it has the same spacing in the cm -% typewriter fonts as three actual period characters; on the other hand, -% in other typewriter fonts three periods are wider than 1.5em. So do -% whichever is larger. -% -\def\dots{% - \leavevmode - \setbox0=\hbox{...}% get width of three periods - \ifdim\wd0 > 1.5em - \dimen0 = \wd0 - \else - \dimen0 = 1.5em - \fi - \hbox to \dimen0{% - \hskip 0pt plus.25fil - .\hskip 0pt plus1fil - .\hskip 0pt plus1fil - .\hskip 0pt plus.5fil - }% -} - -% @enddots{} is an end-of-sentence ellipsis. -% -\def\enddots{% - \dots - \spacefactor=\endofsentencespacefactor -} - -% @point{}, @result{}, @expansion{}, @print{}, @equiv{}. -% -% Since these characters are used in examples, they should be an even number of -% \tt widths. Each \tt character is 1en, so two makes it 1em. -% -\def\point{$\star$} -\def\arrow{\leavevmode\raise.05ex\hbox to 1em{\hfil$\rightarrow$\hfil}} -\def\result{\leavevmode\raise.05ex\hbox to 1em{\hfil$\Rightarrow$\hfil}} -\def\expansion{\leavevmode\hbox to 1em{\hfil$\mapsto$\hfil}} -\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}} -\def\equiv{\leavevmode\hbox to 1em{\hfil$\ptexequiv$\hfil}} - -% The @error{} command. -% Adapted from the TeXbook's \boxit. -% -\newbox\errorbox -% -{\tentt \global\dimen0 = 3em}% Width of the box. -\dimen2 = .55pt % Thickness of rules -% The text. (`r' is open on the right, `e' somewhat less so on the left.) -\setbox0 = \hbox{\kern-.75pt \reducedsf \putworderror\kern-1.5pt} -% -\setbox\errorbox=\hbox to \dimen0{\hfil - \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right. - \advance\hsize by -2\dimen2 % Rules. - \vbox{% - \hrule height\dimen2 - \hbox{\vrule width\dimen2 \kern3pt % Space to left of text. - \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below. - \kern3pt\vrule width\dimen2}% Space to right. - \hrule height\dimen2} - \hfil} -% -\def\error{\leavevmode\lower.7ex\copy\errorbox} +} % @pounds{} is a sterling sign, which Knuth put in the CM italic font. % @@ -3047,113 +2075,49 @@ % Theiling, which support regular, slanted, bold and bold slanted (and % "outlined" (blackboard board, sort of) versions, which we don't need). % It is available from http://www.ctan.org/tex-archive/fonts/eurosym. -% +% % Although only regular is the truly official Euro symbol, we ignore % that. The Euro is designed to be slightly taller than the regular % font height. -% +% % feymr - regular % feymo - slanted % feybr - bold % feybo - bold slanted -% +% % There is no good (free) typewriter version, to my knowledge. % A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide. % Hmm. -% +% % Also doesn't work in math. Do we need to do math with euro symbols? % Hope not. -% -% +% +% \def\euro{{\eurofont e}} \def\eurofont{% % We set the font at each command, rather than predefining it in % \textfonts and the other font-switching commands, so that % installations which never need the symbol don't have to have the % font installed. - % + % % There is only one designed size (nominal 10pt), so we always scale % that to the current nominal size. - % + % % By the way, simply using "at 1em" works for cmr10 and the like, but % does not work for cmbx10 and other extended/shrunken fonts. - % + % \def\eurosize{\csname\curfontsize nominalsize\endcsname}% % - \ifx\curfontstyle\bfstylename + \ifx\curfontstyle\bfstylename % bold: \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize - \else + \else % regular: \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize \fi \thiseurofont } -% Glyphs from the EC fonts. We don't use \let for the aliases, because -% sometimes we redefine the original macro, and the alias should reflect -% the redefinition. -% -% Use LaTeX names for the Icelandic letters. -\def\DH{{\ecfont \char"D0}} % Eth -\def\dh{{\ecfont \char"F0}} % eth -\def\TH{{\ecfont \char"DE}} % Thorn -\def\th{{\ecfont \char"FE}} % thorn -% -\def\guillemetleft{{\ecfont \char"13}} -\def\guillemotleft{\guillemetleft} -\def\guillemetright{{\ecfont \char"14}} -\def\guillemotright{\guillemetright} -\def\guilsinglleft{{\ecfont \char"0E}} -\def\guilsinglright{{\ecfont \char"0F}} -\def\quotedblbase{{\ecfont \char"12}} -\def\quotesinglbase{{\ecfont \char"0D}} -% -% This positioning is not perfect (see the ogonek LaTeX package), but -% we have the precomposed glyphs for the most common cases. We put the -% tests to use those glyphs in the single \ogonek macro so we have fewer -% dummy definitions to worry about for index entries, etc. -% -% ogonek is also used with other letters in Lithuanian (IOU), but using -% the precomposed glyphs for those is not so easy since they aren't in -% the same EC font. -\def\ogonek#1{{% - \def\temp{#1}% - \ifx\temp\macrocharA\Aogonek - \else\ifx\temp\macrochara\aogonek - \else\ifx\temp\macrocharE\Eogonek - \else\ifx\temp\macrochare\eogonek - \else - \ecfont \setbox0=\hbox{#1}% - \ifdim\ht0=1ex\accent"0C #1% - \else\ooalign{\unhbox0\crcr\hidewidth\char"0C \hidewidth}% - \fi - \fi\fi\fi\fi - }% -} -\def\Aogonek{{\ecfont \char"81}}\def\macrocharA{A} -\def\aogonek{{\ecfont \char"A1}}\def\macrochara{a} -\def\Eogonek{{\ecfont \char"86}}\def\macrocharE{E} -\def\eogonek{{\ecfont \char"A6}}\def\macrochare{e} -% -% Use the ec* fonts (cm-super in outline format) for non-CM glyphs. -\def\ecfont{% - % We can't distinguish serif/sans and italic/slanted, but this - % is used for crude hacks anyway (like adding French and German - % quotes to documents typeset with CM, where we lose kerning), so - % hopefully nobody will notice/care. - \edef\ecsize{\csname\curfontsize ecsize\endcsname}% - \edef\nominalsize{\csname\curfontsize nominalsize\endcsname}% - \ifx\curfontstyle\bfstylename - % bold: - \font\thisecfont = ecb\ifusingit{i}{x}\ecsize \space at \nominalsize - \else - % regular: - \font\thisecfont = ec\ifusingit{ti}{rm}\ecsize \space at \nominalsize - \fi - \thisecfont -} - % @registeredsymbol - R in a circle. The font for the R should really % be smaller yet, but lllsize is the best we can do for now. % Adapted from the plain.tex definition of \copyright. @@ -3164,24 +2128,14 @@ }$% } -% @textdegree - the normal degrees sign. -% -\def\textdegree{$^\circ$} - % Laurent Siebenmann reports \Orb undefined with: % Textures 1.7.7 (preloaded format=plain 93.10.14) (68K) 16 APR 2004 02:38 % so we'll define it if necessary. -% -\ifx\Orb\thisisundefined +% +\ifx\Orb\undefined \def\Orb{\mathhexbox20D} \fi -% Quotes. -\chardef\quotedblleft="5C -\chardef\quotedblright=`\" -\chardef\quoteleft=`\` -\chardef\quoteright=`\' - \message{page headings,} @@ -3200,9 +2154,8 @@ \newif\ifsetshortcontentsaftertitlepage \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue -\parseargdef\shorttitlepage{% - \begingroup \hbox{}\vskip 1.5in \chaprm \centerline{#1}% - \endgroup\page\hbox{}\page} +\parseargdef\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}% + \endgroup\page\hbox{}\page} \envdef\titlepage{% % Open one extra group, as we want to close it in the middle of \Etitlepage. @@ -3262,14 +2215,17 @@ \finishedtitlepagetrue } -% Macros to be used within @titlepage: +%%% Macros to be used within @titlepage: \let\subtitlerm=\tenrm \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines} +\def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines + \let\tt=\authortt} + \parseargdef\title{% \checkenv\titlepage - \leftline{\titlefonts\rmisbold #1} + \leftline{\titlefonts\rm #1} % print a rule at the page bottom also. \finishedtitlepagefalse \vskip4pt \hrule height 4pt width \hsize \vskip4pt @@ -3290,12 +2246,12 @@ \else \checkenv\titlepage \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi - {\secfonts\rmisbold \leftline{#1}}% + {\authorfont \leftline{#1}}% \fi } -% Set up page headings and footings. +%%% Set up page headings and footings. \let\thispage=\folio @@ -3343,39 +2299,12 @@ % % Leave some space for the footline. Hopefully ok to assume % @evenfooting will not be used by itself. - \global\advance\pageheight by -12pt - \global\advance\vsize by -12pt + \global\advance\pageheight by -\baselineskip + \global\advance\vsize by -\baselineskip } \parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}} -% @evenheadingmarks top \thischapter <- chapter at the top of a page -% @evenheadingmarks bottom \thischapter <- chapter at the bottom of a page -% -% The same set of arguments for: -% -% @oddheadingmarks -% @evenfootingmarks -% @oddfootingmarks -% @everyheadingmarks -% @everyfootingmarks - -\def\evenheadingmarks{\headingmarks{even}{heading}} -\def\oddheadingmarks{\headingmarks{odd}{heading}} -\def\evenfootingmarks{\headingmarks{even}{footing}} -\def\oddfootingmarks{\headingmarks{odd}{footing}} -\def\everyheadingmarks#1 {\headingmarks{even}{heading}{#1} - \headingmarks{odd}{heading}{#1} } -\def\everyfootingmarks#1 {\headingmarks{even}{footing}{#1} - \headingmarks{odd}{footing}{#1} } -% #1 = even/odd, #2 = heading/footing, #3 = top/bottom. -\def\headingmarks#1#2#3 {% - \expandafter\let\expandafter\temp \csname get#3headingmarks\endcsname - \global\expandafter\let\csname get#1#2marks\endcsname \temp -} - -\everyheadingmarks bottom -\everyfootingmarks bottom % @headings double turns headings on for double-sided printing. % @headings single turns headings on for single-sided printing. @@ -3389,14 +2318,10 @@ \def\headings #1 {\csname HEADINGS#1\endcsname} -\def\headingsoff{% non-global headings elimination - \evenheadline={\hfil}\evenfootline={\hfil}% - \oddheadline={\hfil}\oddfootline={\hfil}% -} - -\def\HEADINGSoff{{\globaldefs=1 \headingsoff}} % global setting -\HEADINGSoff % it's the default - +\def\HEADINGSoff{% +\global\evenheadline={\hfil} \global\evenfootline={\hfil} +\global\oddheadline={\hfil} \global\oddfootline={\hfil}} +\HEADINGSoff % When we turn headings on, set the page number to 1. % For double-sided printing, put current file name in lower left corner, % chapter name on inside top of right hand pages, document @@ -3447,7 +2372,7 @@ % This produces Day Month Year style of output. % Only define if not already defined, in case a txi-??.tex file has set % up a different format (e.g., txi-cs.tex does this). -\ifx\today\thisisundefined +\ifx\today\undefined \def\today{% \number\day\space \ifcase\month @@ -3508,7 +2433,7 @@ \begingroup \advance\leftskip by-\tableindent \advance\hsize by\tableindent - \advance\rightskip by0pt plus1fil\relax + \advance\rightskip by0pt plus1fil \leavevmode\unhbox0\par \endgroup % @@ -3522,7 +2447,7 @@ % cause the example and the item to crash together. So we use this % bizarre value of 10001 as a signal to \aboveenvbreak to insert % \parskip glue after all. Section titles are handled this way also. - % + % \penalty 10001 \endgroup \itemxneedsnegativevskipfalse @@ -3616,18 +2541,9 @@ \parindent=0pt \parskip=\smallskipamount \ifdim\parskip=0pt \parskip=2pt \fi - % - % Try typesetting the item mark that if the document erroneously says - % something like @itemize @samp (intending @table), there's an error - % right away at the @itemize. It's not the best error message in the - % world, but it's better than leaving it to the @item. This means if - % the user wants an empty mark, they have to say @w{} not just @w. \def\itemcontents{#1}% - \setbox0 = \hbox{\itemcontents}% - % % @itemize with no arg is equivalent to @itemize @bullet. \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi - % \let\item=\itemizeitem } @@ -3648,7 +2564,6 @@ \ifnum\lastpenalty<10000 \parskip=0in \fi \noindent \hbox to 0pt{\hss \itemcontents \kern\itemmargin}% - % \vadjust{\penalty 1200}}% not good to break after first line of item. \flushcr } @@ -3870,19 +2785,12 @@ % % @headitem starts a heading row, which we typeset in bold. % Assignments have to be global since we are inside the implicit group -% of an alignment entry. \everycr resets \everytab so we don't have to -% undo it ourselves. -\def\headitemfont{\b}% for people to use in the template row; not changeable -\def\headitem{% - \checkenv\multitable - \crcr - \global\everytab={\bf}% can't use \headitemfont since the parsing differs - \the\everytab % for the first item -}% +% of an alignment entry. Note that \everycr resets \everytab. +\def\headitem{\checkenv\multitable \crcr \global\everytab={\bf}\the\everytab}% % % A \tab used to include \hskip1sp. But then the space in a template % line is not enough. That is bad. So let's go back to just `&' until -% we again encounter the problem the 1sp was intended to solve. +% we encounter the problem it was intended to solve again. % --karl, nathan@acm.org, 20apr99. \def\tab{\checkenv\multitable &\the\everytab}% @@ -3994,18 +2902,18 @@ \setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip \global\advance\multitablelinespace by-\ht0 \fi -% Test to see if parskip is larger than space between lines of -% table. If not, do nothing. -% If so, set to same dimension as multitablelinespace. +%% Test to see if parskip is larger than space between lines of +%% table. If not, do nothing. +%% If so, set to same dimension as multitablelinespace. \ifdim\multitableparskip>\multitablelinespace \global\multitableparskip=\multitablelinespace -\global\advance\multitableparskip-7pt % to keep parskip somewhat smaller - % than skip between lines in the table. +\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller + %% than skip between lines in the table. \fi% \ifdim\multitableparskip=0pt \global\multitableparskip=\multitablelinespace -\global\advance\multitableparskip-7pt % to keep parskip somewhat smaller - % than skip between lines in the table. +\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller + %% than skip between lines in the table. \fi} @@ -4051,7 +2959,6 @@ \def\doignore#1{\begingroup % Scan in ``verbatim'' mode: - \obeylines \catcode`\@ = \other \catcode`\{ = \other \catcode`\} = \other @@ -4072,16 +2979,16 @@ \gdef\dodoignore#1{% % #1 contains the command name as a string, e.g., `ifinfo'. % - % Define a command to find the next `@end #1'. - \long\def\doignoretext##1^^M@end #1{% - \doignoretextyyy##1^^M@#1\_STOP_}% - % + % Define a command to find the next `@end #1', which must be on a line + % by itself. + \long\def\doignoretext##1^^M@end #1{\doignoretextyyy##1^^M@#1\_STOP_}% % And this command to find another #1 command, at the beginning of a % line. (Otherwise, we would consider a line `@c @ifset', for % example, to count as an @ifset for nesting.) \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}% % % And now expand that command. + \obeylines % \doignoretext ^^M% }% } @@ -4111,12 +3018,7 @@ } % Finish off ignored text. -{ \obeylines% - % Ignore anything after the last `@end #1'; this matters in verbatim - % environments, where otherwise the newline after an ignored conditional - % would result in a blank line in the output. - \gdef\enddoignore#1^^M{\endgroup\ignorespaces}% -} +\def\enddoignore{\endgroup\ignorespaces} % @set VAR sets the variable VAR to an empty value. @@ -4281,11 +3183,11 @@ \def\dosynindex#1#2#3{% % Only do \closeout if we haven't already done it, else we'll end up % closing the target index. - \expandafter \ifx\csname donesynindex#2\endcsname \relax + \expandafter \ifx\csname donesynindex#2\endcsname \undefined % The \closeout helps reduce unnecessary open files; the limit on the % Acorn RISC OS is a mere 16 files. \expandafter\closeout\csname#2indfile\endcsname - \expandafter\let\csname donesynindex#2\endcsname = 1 + \expandafter\let\csname\donesynindex#2\endcsname = 1 \fi % redefine \fooindfile: \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname @@ -4319,41 +3221,11 @@ \escapechar = `\\ % use backslash in output files. \def\@{@}% change to @@ when we switch to @ as escape char in index files. \def\ {\realbackslash\space }% - % - % Need these unexpandable (because we define \tt as a dummy) - % definitions when @{ or @} appear in index entry text. Also, more - % complicated, when \tex is in effect and \{ is a \delimiter again. - % We can't use \lbracecmd and \rbracecmd because texindex assumes - % braces and backslashes are used only as delimiters. Perhaps we - % should define @lbrace and @rbrace commands a la @comma. - \def\{{{\tt\char123}}% - \def\}{{\tt\char125}}% - % - % I don't entirely understand this, but when an index entry is - % generated from a macro call, the \endinput which \scanmacro inserts - % causes processing to be prematurely terminated. This is, - % apparently, because \indexsorttmp is fully expanded, and \endinput - % is an expandable command. The redefinition below makes \endinput - % disappear altogether for that purpose -- although logging shows that - % processing continues to some further point. On the other hand, it - % seems \endinput does not hurt in the printed index arg, since that - % is still getting written without apparent harm. - % - % Sample source (mac-idx3.tex, reported by Graham Percival to - % help-texinfo, 22may06): - % @macro funindex {WORD} - % @findex xyz - % @end macro - % ... - % @funindex commtest - % - % The above is not enough to reproduce the bug, but it gives the flavor. - % - % Sample whatsit resulting: - % .@write3{\entry{xyz}{@folio }{@code {xyz@endinput }}} - % - % So: - \let\endinput = \empty + % Need these in case \tex is in effect and \{ is a \delimiter again. + % But can't use \lbracecmd and \rbracecmd because texindex assumes + % braces and backslashes are used only as delimiters. + \let\{ = \mylbrace + \let\} = \myrbrace % % Do the redefinitions. \commondummies @@ -4372,7 +3244,6 @@ % % Do the redefinitions. \commondummies - \otherbackslash } % Called from \indexdummies and \atdummies. @@ -4380,7 +3251,7 @@ \def\commondummies{% % % \definedummyword defines \#1 as \string\#1\space, thus effectively - % preventing its expansion. This is used only for control words, + % preventing its expansion. This is used only for control% words, % not control letters, because the \space would be incorrect for % control characters, but is needed to separate the control word % from whatever follows. @@ -4399,28 +3270,23 @@ \commondummiesnofonts % \definedummyletter\_% - \definedummyletter\-% % % Non-English letters. \definedummyword\AA \definedummyword\AE - \definedummyword\DH \definedummyword\L + \definedummyword\OE \definedummyword\O - \definedummyword\OE - \definedummyword\TH \definedummyword\aa \definedummyword\ae - \definedummyword\dh + \definedummyword\l + \definedummyword\oe + \definedummyword\o + \definedummyword\ss \definedummyword\exclamdown - \definedummyword\l - \definedummyword\o - \definedummyword\oe + \definedummyword\questiondown \definedummyword\ordf \definedummyword\ordm - \definedummyword\questiondown - \definedummyword\ss - \definedummyword\th % % Although these internal commands shouldn't show up, sometimes they do. \definedummyword\bf @@ -4436,39 +3302,21 @@ \definedummyword\TeX % % Assorted special characters. - \definedummyword\arrow \definedummyword\bullet \definedummyword\comma \definedummyword\copyright \definedummyword\registeredsymbol \definedummyword\dots \definedummyword\enddots - \definedummyword\entrybreak \definedummyword\equiv \definedummyword\error \definedummyword\euro \definedummyword\expansion - \definedummyword\geq - \definedummyword\guillemetleft - \definedummyword\guillemetright - \definedummyword\guilsinglleft - \definedummyword\guilsinglright - \definedummyword\lbracechar - \definedummyword\leq \definedummyword\minus - \definedummyword\ogonek \definedummyword\pounds \definedummyword\point \definedummyword\print - \definedummyword\quotedblbase - \definedummyword\quotedblleft - \definedummyword\quotedblright - \definedummyword\quoteleft - \definedummyword\quoteright - \definedummyword\quotesinglbase - \definedummyword\rbracechar \definedummyword\result - \definedummyword\textdegree % % We want to disable all macros so that they are not expanded by \write. \macrolist @@ -4482,72 +3330,63 @@ % \commondummiesnofonts: common to \commondummies and \indexnofonts. % -\def\commondummiesnofonts{% - % Control letters and accents. - \definedummyletter\!% - \definedummyaccent\"% - \definedummyaccent\'% - \definedummyletter\*% - \definedummyaccent\,% - \definedummyletter\.% - \definedummyletter\/% - \definedummyletter\:% - \definedummyaccent\=% - \definedummyletter\?% - \definedummyaccent\^% - \definedummyaccent\`% - \definedummyaccent\~% - \definedummyword\u - \definedummyword\v - \definedummyword\H - \definedummyword\dotaccent - \definedummyword\ogonek - \definedummyword\ringaccent - \definedummyword\tieaccent - \definedummyword\ubaraccent - \definedummyword\udotaccent - \definedummyword\dotless - % - % Texinfo font commands. - \definedummyword\b - \definedummyword\i - \definedummyword\r - \definedummyword\sansserif - \definedummyword\sc - \definedummyword\slanted - \definedummyword\t - % - % Commands that take arguments. - \definedummyword\abbr - \definedummyword\acronym - \definedummyword\anchor - \definedummyword\cite - \definedummyword\code - \definedummyword\command - \definedummyword\dfn - \definedummyword\dmn - \definedummyword\email - \definedummyword\emph - \definedummyword\env - \definedummyword\file - \definedummyword\image - \definedummyword\indicateurl - \definedummyword\inforef - \definedummyword\kbd - \definedummyword\key - \definedummyword\math - \definedummyword\option - \definedummyword\pxref - \definedummyword\ref - \definedummyword\samp - \definedummyword\strong - \definedummyword\tie - \definedummyword\uref - \definedummyword\url - \definedummyword\var - \definedummyword\verb - \definedummyword\w - \definedummyword\xref +% Better have this without active chars. +{ + \catcode`\~=\other + \gdef\commondummiesnofonts{% + % Control letters and accents. + \definedummyletter\!% + \definedummyaccent\"% + \definedummyaccent\'% + \definedummyletter\*% + \definedummyaccent\,% + \definedummyletter\.% + \definedummyletter\/% + \definedummyletter\:% + \definedummyaccent\=% + \definedummyletter\?% + \definedummyaccent\^% + \definedummyaccent\`% + \definedummyaccent\~% + \definedummyword\u + \definedummyword\v + \definedummyword\H + \definedummyword\dotaccent + \definedummyword\ringaccent + \definedummyword\tieaccent + \definedummyword\ubaraccent + \definedummyword\udotaccent + \definedummyword\dotless + % + % Texinfo font commands. + \definedummyword\b + \definedummyword\i + \definedummyword\r + \definedummyword\sc + \definedummyword\t + % + % Commands that take arguments. + \definedummyword\acronym + \definedummyword\cite + \definedummyword\code + \definedummyword\command + \definedummyword\dfn + \definedummyword\emph + \definedummyword\env + \definedummyword\file + \definedummyword\kbd + \definedummyword\key + \definedummyword\math + \definedummyword\option + \definedummyword\samp + \definedummyword\strong + \definedummyword\tie + \definedummyword\uref + \definedummyword\url + \definedummyword\var + \definedummyword\verb + \definedummyword\w + } } % \indexnofonts is used when outputting the strings to sort the index @@ -4560,7 +3399,7 @@ \def\definedummyaccent##1{\let##1\asis}% % We can just ignore other control letters. \def\definedummyletter##1{\let##1\empty}% - % All control words become @asis by default; overrides below. + % Hopefully, all control words can become @asis. \let\definedummyword\definedummyaccent % \commondummiesnofonts @@ -4572,95 +3411,60 @@ % \def\ { }% \def\@{@}% + % how to handle braces? \def\_{\normalunderscore}% - \def\-{}% @- shouldn't affect sorting - % - % Unfortunately, texindex is not prepared to handle braces in the - % content at all. So for index sorting, we map @{ and @} to strings - % starting with |, since that ASCII character is between ASCII { and }. - \def\{{|a}% - \def\lbracechar{|a}% - % - \def\}{|b}% - \def\rbracechar{|b}% % % Non-English letters. \def\AA{AA}% \def\AE{AE}% - \def\DH{DZZ}% \def\L{L}% \def\OE{OE}% \def\O{O}% - \def\TH{ZZZ}% \def\aa{aa}% \def\ae{ae}% - \def\dh{dzz}% - \def\exclamdown{!}% \def\l{l}% \def\oe{oe}% + \def\o{o}% + \def\ss{ss}% + \def\exclamdown{!}% + \def\questiondown{?}% \def\ordf{a}% \def\ordm{o}% - \def\o{o}% - \def\questiondown{?}% - \def\ss{ss}% - \def\th{zzz}% % \def\LaTeX{LaTeX}% \def\TeX{TeX}% % % Assorted special characters. % (The following {} will end up in the sort string, but that's ok.) - \def\arrow{->}% \def\bullet{bullet}% \def\comma{,}% \def\copyright{copyright}% + \def\registeredsymbol{R}% \def\dots{...}% \def\enddots{...}% \def\equiv{==}% \def\error{error}% \def\euro{euro}% \def\expansion{==>}% - \def\geq{>=}% - \def\guillemetleft{<<}% - \def\guillemetright{>>}% - \def\guilsinglleft{<}% - \def\guilsinglright{>}% - \def\leq{<=}% \def\minus{-}% + \def\pounds{pounds}% \def\point{.}% - \def\pounds{pounds}% \def\print{-|}% - \def\quotedblbase{"}% - \def\quotedblleft{"}% - \def\quotedblright{"}% - \def\quoteleft{`}% - \def\quoteright{'}% - \def\quotesinglbase{,}% - \def\registeredsymbol{R}% \def\result{=>}% - \def\textdegree{o}% - % - \expandafter\ifx\csname SETtxiindexlquoteignore\endcsname\relax - \else \indexlquoteignore \fi % % We need to get rid of all macros, leaving only the arguments (if present). % Of course this is not nearly correct, but it is the best we can do for now. % makeinfo does not expand macros in the argument to @deffn, which ends up % writing an index entry, and texindex isn't prepared for an index sort entry % that starts with \. - % + % % Since macro invocations are followed by braces, we can just redefine them % to take a single TeX argument. The case of a macro invocation that % goes to end-of-line is not handled. - % + % \macrolist } -% Undocumented (for FSFS 2nd ed.): @set txiindexlquoteignore makes us -% ignore left quotes in the sort term. -{\catcode`\`=\active - \gdef\indexlquoteignore{\let`=\empty}} - \let\indexbackslash=0 %overridden during \printindex. \let\SETmarginindex=\relax % put index entries in margin (undocumented)? @@ -4686,7 +3490,11 @@ % \edef\writeto{\csname#1indfile\endcsname}% % - \safewhatsit\dosubindwrite + \ifvmode + \dosubindsanitize + \else + \dosubindwrite + \fi }% \fi } @@ -4723,13 +3531,13 @@ \temp } -% Take care of unwanted page breaks/skips around a whatsit: +% Take care of unwanted page breaks: % % If a skip is the last thing on the list now, preserve it % by backing up by \lastskip, doing the \write, then inserting % the skip again. Otherwise, the whatsit generated by the -% \write or \pdfdest will make \lastskip zero. The result is that -% sequences like this: +% \write will make \lastskip zero. The result is that sequences +% like this: % @end defun % @tindex whatever % @defun ... @@ -4753,30 +3561,25 @@ % \edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname} % -\newskip\whatsitskip -\newcount\whatsitpenalty -% % ..., ready, GO: % -\def\safewhatsit#1{\ifhmode - #1% - \else +\def\dosubindsanitize{% % \lastskip and \lastpenalty cannot both be nonzero simultaneously. - \whatsitskip = \lastskip + \skip0 = \lastskip \edef\lastskipmacro{\the\lastskip}% - \whatsitpenalty = \lastpenalty + \count255 = \lastpenalty % % If \lastskip is nonzero, that means the last item was a % skip. And since a skip is discardable, that means this - % -\whatsitskip glue we're inserting is preceded by a + % -\skip0 glue we're inserting is preceded by a % non-discardable item, therefore it is not a potential % breakpoint, therefore no \nobreak needed. \ifx\lastskipmacro\zeroskipmacro \else - \vskip-\whatsitskip + \vskip-\skip0 \fi % - #1% + \dosubindwrite % \ifx\lastskipmacro\zeroskipmacro % If \lastskip was zero, perhaps the last item was a penalty, and @@ -4784,19 +3587,20 @@ % to re-insert the same penalty (values >10000 are used for various % signals); since we just inserted a non-discardable item, any % following glue (such as a \parskip) would be a breakpoint. For example: + % % @deffn deffn-whatever % @vindex index-whatever % Description. % would allow a break between the index-whatever whatsit % and the "Description." paragraph. - \ifnum\whatsitpenalty>9999 \penalty\whatsitpenalty \fi + \ifnum\count255>9999 \penalty\count255 \fi \else % On the other hand, if we had a nonzero \lastskip, % this make-up glue would be preceded by a non-discardable item % (the whatsit from the \write), so we must insert a \nobreak. - \nobreak\vskip\whatsitskip + \nobreak\vskip\skip0 \fi -\fi} +} % The index entry written in the file actually looks like % \entry {sortstring}{page}{topic} @@ -4838,7 +3642,6 @@ % \smallfonts \rm \tolerance = 9500 - \plainfrenchspacing \everypar = {}% don't want the \kern\-parindent from indentation suppression. % % See if the index file exists and is nonempty. @@ -4912,9 +3715,10 @@ % % A straightforward implementation would start like this: % \def\entry#1#2{... -% But this freezes the catcodes in the argument, and can cause problems to +% But this frozes the catcodes in the argument, and can cause problems to % @code, which sets - active. This problem was fixed by a kludge--- % ``-'' was active throughout whole index, but this isn't really right. +% % The right solution is to prevent \entry from swallowing the whole text. % --kasal, 21nov03 \def\entry{% @@ -4951,17 +3755,10 @@ % columns. \vskip 0pt plus1pt % - % When reading the text of entry, convert explicit line breaks - % from @* into spaces. The user might give these in long section - % titles, for instance. - \def\*{\unskip\space\ignorespaces}% - \def\entrybreak{\hfil\break}% - % % Swallow the left brace of the text (first parameter): \afterassignment\doentry \let\temp = } -\def\entrybreak{\unskip\space\ignorespaces}% \def\doentry{% \bgroup % Instead of the swallowed brace. \noindent @@ -4974,8 +3771,11 @@ % The following is kludged to not output a line of dots in the index if % there are no page numbers. The next person who breaks this will be % cursed by a Unix daemon. - \setbox\boxA = \hbox{#1}% - \ifdim\wd\boxA = 0pt + \def\tempa{{\rm }}% + \def\tempb{#1}% + \edef\tempc{\tempa}% + \edef\tempd{\tempb}% + \ifx\tempc\tempd \ % \else % @@ -4999,9 +3799,9 @@ \endgroup } -% Like plain.tex's \dotfill, except uses up at least 1 em. +% Like \dotfill except takes at least 1 em. \def\indexdotfill{\cleaders - \hbox{$\mathsurround=0pt \mkern1.5mu.\mkern1.5mu$}\hskip 1em plus 1fill} + \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill} \def\primary #1{\line{#1\hfil}} @@ -5111,34 +3911,6 @@ % % All done with double columns. \def\enddoublecolumns{% - % The following penalty ensures that the page builder is exercised - % _before_ we change the output routine. This is necessary in the - % following situation: - % - % The last section of the index consists only of a single entry. - % Before this section, \pagetotal is less than \pagegoal, so no - % break occurs before the last section starts. However, the last - % section, consisting of \initial and the single \entry, does not - % fit on the page and has to be broken off. Without the following - % penalty the page builder will not be exercised until \eject - % below, and by that time we'll already have changed the output - % routine to the \balancecolumns version, so the next-to-last - % double-column page will be processed with \balancecolumns, which - % is wrong: The two columns will go to the main vertical list, with - % the broken-off section in the recent contributions. As soon as - % the output routine finishes, TeX starts reconsidering the page - % break. The two columns and the broken-off section both fit on the - % page, because the two columns now take up only half of the page - % goal. When TeX sees \eject from below which follows the final - % section, it invokes the new output routine that we've set after - % \balancecolumns below; \onepageout will try to fit the two columns - % and the final section into the vbox of \pageheight (see - % \pagebody), causing an overfull box. - % - % Note that glue won't work here, because glue does not exercise the - % page builder, unlike penalties (see The TeXbook, pp. 280-281). - \penalty0 - % \output = {% % Split the last of the double-column material. Leave it on the % current page, no automatic page break. @@ -5194,22 +3966,7 @@ \message{sectioning,} % Chapters, sections, etc. -% Let's start with @part. -\outer\parseargdef\part{\partzzz{#1}} -\def\partzzz#1{% - \chapoddpage - \null - \vskip.3\vsize % move it down on the page a bit - \begingroup - \noindent \titlefonts\rmisbold #1\par % the text - \let\lastnode=\empty % no node to associate with - \writetocentry{part}{#1}{}% but put it in the toc - \headingsoff % no headline or footline on the part page - \chapoddpage - \endgroup -} - -% \unnumberedno is an oxymoron. But we count the unnumbered +% \unnumberedno is an oxymoron, of course. But we count the unnumbered % sections so that we can refer to them unambiguously in the pdf % outlines by their "section number". We avoid collisions with chapter % numbers by starting them at 10000. (If a document ever has 10000 @@ -5263,15 +4020,11 @@ \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi} -% Each @chapter defines these (using marks) as the number+name, number -% and name of the chapter. Page headings and footings can use -% these. @section does likewise. +% Each @chapter defines this as the name of the chapter. +% page headings and footings can use it. @section does likewise. +% However, they are not reliable, because we don't use marks. \def\thischapter{} -\def\thischapternum{} -\def\thischaptername{} \def\thissection{} -\def\thissectionnum{} -\def\thissectionname{} \newcount\absseclevel % used to calculate proper heading level \newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count @@ -5288,8 +4041,8 @@ \chardef\maxseclevel = 3 % % A numbered section within an unnumbered changes to unnumbered too. -% To achieve this, remember the "biggest" unnum. sec. we are currently in: -\chardef\unnlevel = \maxseclevel +% To achive this, remember the "biggest" unnum. sec. we are currently in: +\chardef\unmlevel = \maxseclevel % % Trace whether the current chapter is an appendix or not: % \chapheadtype is "N" or "A", unnumbered chapters are ignored. @@ -5314,8 +4067,8 @@ % The heading type: \def\headtype{#1}% \if \headtype U% - \ifnum \absseclevel < \unnlevel - \chardef\unnlevel = \absseclevel + \ifnum \absseclevel < \unmlevel + \chardef\unmlevel = \absseclevel \fi \else % Check for appendix sections: @@ -5327,10 +4080,10 @@ \fi\fi \fi % Check for numbered within unnumbered: - \ifnum \absseclevel > \unnlevel + \ifnum \absseclevel > \unmlevel \def\headtype{U}% \else - \chardef\unnlevel = 3 + \chardef\unmlevel = 3 \fi \fi % Now print the heading: @@ -5384,9 +4137,7 @@ \gdef\chaplevelprefix{\the\chapno.}% \resetallfloatnos % - % \putwordChapter can contain complex things in translations. - \toks0=\expandafter{\putwordChapter}% - \message{\the\toks0 \space \the\chapno}% + \message{\putwordChapter\space \the\chapno}% % % Write the actual heading. \chapmacro{#1}{Ynumbered}{\the\chapno}% @@ -5397,17 +4148,15 @@ \global\let\subsubsection = \numberedsubsubsec } -\outer\parseargdef\appendix{\apphead0{#1}} % normally calls appendixzzz -% +\outer\parseargdef\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz \def\appendixzzz#1{% \global\secno=0 \global\subsecno=0 \global\subsubsecno=0 \global\advance\appendixno by 1 \gdef\chaplevelprefix{\appendixletter.}% \resetallfloatnos % - % \putwordAppendix can contain complex things in translations. - \toks0=\expandafter{\putwordAppendix}% - \message{\the\toks0 \space \appendixletter}% + \def\appendixnum{\putwordAppendix\space \appendixletter}% + \message{\appendixnum}% % \chapmacro{#1}{Yappendix}{\appendixletter}% % @@ -5416,8 +4165,7 @@ \global\let\subsubsection = \appendixsubsubsec } -% normally unnmhead0 calls unnumberedzzz: -\outer\parseargdef\unnumbered{\unnmhead0{#1}} +\outer\parseargdef\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz \def\unnumberedzzz#1{% \global\secno=0 \global\subsecno=0 \global\subsubsecno=0 \global\advance\unnumberedno by 1 @@ -5461,47 +4209,40 @@ \let\top\unnumbered % Sections. -% \outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz \def\seczzz#1{% \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1 \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}% } -% normally calls appendixsectionzzz: -\outer\parseargdef\appendixsection{\apphead1{#1}} +\outer\parseargdef\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz \def\appendixsectionzzz#1{% \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1 \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}% } \let\appendixsec\appendixsection -% normally calls unnumberedseczzz: -\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} +\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz \def\unnumberedseczzz#1{% \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1 \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}% } % Subsections. -% -% normally calls numberedsubseczzz: -\outer\parseargdef\numberedsubsec{\numhead2{#1}} +\outer\parseargdef\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz \def\numberedsubseczzz#1{% \global\subsubsecno=0 \global\advance\subsecno by 1 \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}% } -% normally calls appendixsubseczzz: -\outer\parseargdef\appendixsubsec{\apphead2{#1}} +\outer\parseargdef\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz \def\appendixsubseczzz#1{% \global\subsubsecno=0 \global\advance\subsecno by 1 \sectionheading{#1}{subsec}{Yappendix}% {\appendixletter.\the\secno.\the\subsecno}% } -% normally calls unnumberedsubseczzz: -\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} +\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz \def\unnumberedsubseczzz#1{% \global\subsubsecno=0 \global\advance\subsecno by 1 \sectionheading{#1}{subsec}{Ynothing}% @@ -5509,25 +4250,21 @@ } % Subsubsections. -% -% normally numberedsubsubseczzz: -\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} +\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz \def\numberedsubsubseczzz#1{% \global\advance\subsubsecno by 1 \sectionheading{#1}{subsubsec}{Ynumbered}% {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}% } -% normally appendixsubsubseczzz: -\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} +\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz \def\appendixsubsubseczzz#1{% \global\advance\subsubsecno by 1 \sectionheading{#1}{subsubsec}{Yappendix}% {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}% } -% normally unnumberedsubsubseczzz: -\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} +\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz \def\unnumberedsubsubseczzz#1{% \global\advance\subsubsecno by 1 \sectionheading{#1}{subsubsec}{Ynothing}% @@ -5551,6 +4288,7 @@ % 3) Likewise, headings look best if no \parindent is used, and % if justification is not attempted. Hence \raggedright. + \def\majorheading{% {\advance\chapheadingskip by 10pt \chapbreak }% \parsearg\chapheadingzzz @@ -5559,8 +4297,8 @@ \def\chapheading{\chapbreak \parsearg\chapheadingzzz} \def\chapheadingzzz#1{% {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\ptexraggedright - \rmisbold #1\hfill}}% + \parindent=0pt\raggedright + \rm #1\hfill}}% \bigskip \par\penalty 200\relax \suppressfirstparagraphindent } @@ -5577,28 +4315,17 @@ % (including whitespace, linebreaking, etc. around it), % given all the information in convenient, parsed form. -% Args are the skip and penalty (usually negative) +%%% Args are the skip and penalty (usually negative) \def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi} +%%% Define plain chapter starts, and page on/off switching for it % Parameter controlling skip before chapter headings (if needed) + \newskip\chapheadingskip -% Define plain chapter starts, and page on/off switching for it. \def\chapbreak{\dobreak \chapheadingskip {-4000}} \def\chappager{\par\vfill\supereject} -% Because \domark is called before \chapoddpage, the filler page will -% get the headings for the next chapter, which is wrong. But we don't -% care -- we just disable all headings on the filler page. -\def\chapoddpage{% - \chappager - \ifodd\pageno \else - \begingroup - \headingsoff - \null - \chappager - \endgroup - \fi -} +\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi} \def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname} @@ -5632,78 +4359,41 @@ \def\Yappendixkeyword{Yappendix} % \def\chapmacro#1#2#3{% - % Insert the first mark before the heading break (see notes for \domark). - \let\prevchapterdefs=\lastchapterdefs - \let\prevsectiondefs=\lastsectiondefs - \gdef\lastsectiondefs{\gdef\thissectionname{}\gdef\thissectionnum{}% - \gdef\thissection{}}% - % - \def\temptype{#2}% - \ifx\temptype\Ynothingkeyword - \gdef\lastchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}% - \gdef\thischapter{\thischaptername}}% - \else\ifx\temptype\Yomitfromtockeyword - \gdef\lastchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}% - \gdef\thischapter{}}% - \else\ifx\temptype\Yappendixkeyword - \toks0={#1}% - \xdef\lastchapterdefs{% - \gdef\noexpand\thischaptername{\the\toks0}% - \gdef\noexpand\thischapternum{\appendixletter}% - % \noexpand\putwordAppendix avoids expanding indigestible - % commands in some of the translations. - \gdef\noexpand\thischapter{\noexpand\putwordAppendix{} - \noexpand\thischapternum: - \noexpand\thischaptername}% - }% - \else - \toks0={#1}% - \xdef\lastchapterdefs{% - \gdef\noexpand\thischaptername{\the\toks0}% - \gdef\noexpand\thischapternum{\the\chapno}% - % \noexpand\putwordChapter avoids expanding indigestible - % commands in some of the translations. - \gdef\noexpand\thischapter{\noexpand\putwordChapter{} - \noexpand\thischapternum: - \noexpand\thischaptername}% - }% - \fi\fi\fi - % - % Output the mark. Pass it through \safewhatsit, to take care of - % the preceding space. - \safewhatsit\domark - % - % Insert the chapter heading break. \pchapsepmacro - % - % Now the second mark, after the heading break. No break points - % between here and the heading. - \let\prevchapterdefs=\lastchapterdefs - \let\prevsectiondefs=\lastsectiondefs - \domark - % {% - \chapfonts \rmisbold + \chapfonts \rm % - % Have to define \lastsection before calling \donoderef, because the + % Have to define \thissection before calling \donoderef, because the % xref code eventually uses it. On the other hand, it has to be called % after \pchapsepmacro, or the headline will change too soon. - \gdef\lastsection{#1}% + \gdef\thissection{#1}% + \gdef\thischaptername{#1}% % % Only insert the separating space if we have a chapter/appendix % number, and don't print the unnumbered ``number''. + \def\temptype{#2}% \ifx\temptype\Ynothingkeyword \setbox0 = \hbox{}% \def\toctype{unnchap}% + \gdef\thischapter{#1}% \else\ifx\temptype\Yomitfromtockeyword \setbox0 = \hbox{}% contents like unnumbered, but no toc entry \def\toctype{omit}% + \gdef\thischapter{}% \else\ifx\temptype\Yappendixkeyword \setbox0 = \hbox{\putwordAppendix{} #3\enspace}% \def\toctype{app}% + % We don't substitute the actual chapter name into \thischapter + % because we don't want its macros evaluated now. And we don't + % use \thissection because that changes with each section. + % + \xdef\thischapter{\putwordAppendix{} \appendixletter: + \noexpand\thischaptername}% \else \setbox0 = \hbox{#3\enspace}% \def\toctype{numchap}% + \xdef\thischapter{\putwordChapter{} \the\chapno: + \noexpand\thischaptername}% \fi\fi\fi % % Write the toc entry for this chapter. Must come before the @@ -5719,8 +4409,7 @@ \donoderef{#2}% % % Typeset the actual heading. - \nobreak % Avoid page breaks at the interline glue. - \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \ptexraggedright + \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright \hangindent=\wd0 \centerparametersmaybe \unhbox0 #1\par}% }% @@ -5744,8 +4433,8 @@ % \def\unnchfopen #1{% \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\ptexraggedright - \rmisbold #1\hfill}}\bigskip \par\nobreak + \parindent=0pt\raggedright + \rm #1\hfill}}\bigskip \par\nobreak } \def\chfopen #1#2{\chapoddpage {\chapfonts \vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}% @@ -5754,7 +4443,7 @@ \def\centerchfopen #1{% \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 \parindent=0pt - \hfill {\rmisbold #1}\hfill}}\bigskip \par\nobreak + \hfill {\rm #1}\hfill}}\bigskip \par\nobreak } \def\CHAPFopen{% \global\let\chapmacro=\chfopen @@ -5782,110 +4471,47 @@ % the section type for xrefs (Ynumbered, Ynothing, Yappendix), #4 is the % section number. % -\def\seckeyword{sec} -% \def\sectionheading#1#2#3#4{% {% - \checkenv{}% should not be in an environment. - % % Switch to the right set of fonts. - \csname #2fonts\endcsname \rmisbold - % - \def\sectionlevel{#2}% - \def\temptype{#3}% - % - % Insert first mark before the heading break (see notes for \domark). - \let\prevsectiondefs=\lastsectiondefs - \ifx\temptype\Ynothingkeyword - \ifx\sectionlevel\seckeyword - \gdef\lastsectiondefs{\gdef\thissectionname{#1}\gdef\thissectionnum{}% - \gdef\thissection{\thissectionname}}% - \fi - \else\ifx\temptype\Yomitfromtockeyword - % Don't redefine \thissection. - \else\ifx\temptype\Yappendixkeyword - \ifx\sectionlevel\seckeyword - \toks0={#1}% - \xdef\lastsectiondefs{% - \gdef\noexpand\thissectionname{\the\toks0}% - \gdef\noexpand\thissectionnum{#4}% - % \noexpand\putwordSection avoids expanding indigestible - % commands in some of the translations. - \gdef\noexpand\thissection{\noexpand\putwordSection{} - \noexpand\thissectionnum: - \noexpand\thissectionname}% - }% - \fi - \else - \ifx\sectionlevel\seckeyword - \toks0={#1}% - \xdef\lastsectiondefs{% - \gdef\noexpand\thissectionname{\the\toks0}% - \gdef\noexpand\thissectionnum{#4}% - % \noexpand\putwordSection avoids expanding indigestible - % commands in some of the translations. - \gdef\noexpand\thissection{\noexpand\putwordSection{} - \noexpand\thissectionnum: - \noexpand\thissectionname}% - }% - \fi - \fi\fi\fi - % - % Go into vertical mode. Usually we'll already be there, but we - % don't want the following whatsit to end up in a preceding paragraph - % if the document didn't happen to have a blank line. - \par - % - % Output the mark. Pass it through \safewhatsit, to take care of - % the preceding space. - \safewhatsit\domark + \csname #2fonts\endcsname \rm % % Insert space above the heading. \csname #2headingbreak\endcsname % - % Now the second mark, after the heading break. No break points - % between here and the heading. - \let\prevsectiondefs=\lastsectiondefs - \domark + % Only insert the space after the number if we have a section number. + \def\sectionlevel{#2}% + \def\temptype{#3}% % - % Only insert the space after the number if we have a section number. \ifx\temptype\Ynothingkeyword \setbox0 = \hbox{}% \def\toctype{unn}% - \gdef\lastsection{#1}% + \gdef\thissection{#1}% \else\ifx\temptype\Yomitfromtockeyword % for @headings -- no section number, don't include in toc, - % and don't redefine \lastsection. + % and don't redefine \thissection. \setbox0 = \hbox{}% \def\toctype{omit}% \let\sectionlevel=\empty \else\ifx\temptype\Yappendixkeyword \setbox0 = \hbox{#4\enspace}% \def\toctype{app}% - \gdef\lastsection{#1}% + \gdef\thissection{#1}% \else \setbox0 = \hbox{#4\enspace}% \def\toctype{num}% - \gdef\lastsection{#1}% + \gdef\thissection{#1}% \fi\fi\fi % - % Write the toc entry (before \donoderef). See comments in \chapmacro. + % Write the toc entry (before \donoderef). See comments in \chfplain. \writetocentry{\toctype\sectionlevel}{#1}{#4}% % % Write the node reference (= pdf destination for pdftex). - % Again, see comments in \chapmacro. + % Again, see comments in \chfplain. \donoderef{#3}% % - % Interline glue will be inserted when the vbox is completed. - % That glue will be a valid breakpoint for the page, since it'll be - % preceded by a whatsit (usually from the \donoderef, or from the - % \writetocentry if there was no node). We don't want to allow that - % break, since then the whatsits could end up on page n while the - % section is on page n+1, thus toc/etc. are wrong. Debian bug 276000. - \nobreak - % % Output the actual section heading. - \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \ptexraggedright + \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright \hangindent=\wd0 % zero if no section number \unhbox0 #1}% }% @@ -5899,15 +4525,15 @@ % % We'll almost certainly start a paragraph next, so don't let that % glue accumulate. (Not a breakpoint because it's preceded by a - % discardable item.) However, when a paragraph is not started next - % (\startdefun, \cartouche, \center, etc.), this needs to be wiped out - % or the negative glue will cause weirdly wrong output, typically - % obscuring the section heading with something else. + % discardable item.) \vskip-\parskip - % - % This is so the last item on the main vertical list is a known - % \penalty > 10000, so \startdefun, etc., can recognize the situation - % and do the needful. + % + % This is purely so the last item on the list is a known \penalty > + % 10000. This is so \startdefun can avoid allowing breakpoints after + % section headings. Otherwise, it would insert a valid breakpoint between: + % + % @section sec-whatever + % @deffn def-whatever \penalty 10001 } @@ -5946,7 +4572,7 @@ \edef\temp{% \write\tocfile{@#1entry{#2}{#3}{\lastnode}{\noexpand\folio}}}% \temp - }% + } \fi \fi % @@ -5963,7 +4589,7 @@ % These characters do not print properly in the Computer Modern roman % fonts, so we must take special care. This is more or less redundant % with the Texinfo input format setup at the end of this file. -% +% \def\activecatcodes{% \catcode`\"=\active \catcode`\$=\active @@ -5981,7 +4607,7 @@ \def\readtocfile{% \setupdatafile \activecatcodes - \input \tocreadfilename + \input \jobname.toc } \newskip\contentsrightmargin \contentsrightmargin=1in @@ -6000,6 +4626,7 @@ % % Don't need to put `Contents' or `Short Contents' in the headline. % It is abundantly clear what they are. + \def\thischapter{}% \chapmacro{#1}{Yomitfromtoc}{}% % \savepageno = \pageno @@ -6011,16 +4638,11 @@ \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi } -% redefined for the two-volume lispref. We always output on -% \jobname.toc even if this is redefined. -% -\def\tocreadfilename{\jobname.toc} % Normal (long) toc. -% \def\contents{% \startcontents{\putwordTOC}% - \openin 1 \tocreadfilename\space + \openin 1 \jobname.toc \ifeof 1 \else \readtocfile \fi @@ -6039,7 +4661,6 @@ \def\summarycontents{% \startcontents{\putwordShortTOC}% % - \let\partentry = \shortpartentry \let\numchapentry = \shortchapentry \let\appentry = \shortchapentry \let\unnchapentry = \shortunnchapentry @@ -6059,7 +4680,7 @@ \let\numsubsubsecentry = \numsecentry \let\appsubsubsecentry = \numsecentry \let\unnsubsubsecentry = \numsecentry - \openin 1 \tocreadfilename\space + \openin 1 \jobname.toc \ifeof 1 \else \readtocfile \fi @@ -6095,19 +4716,6 @@ % The last argument is the page number. % The arguments in between are the chapter number, section number, ... -% Parts, in the main contents. Replace the part number, which doesn't -% exist, with an empty box. Let's hope all the numbers have the same width. -% Also ignore the page number, which is conventionally not printed. -\def\numeralbox{\setbox0=\hbox{8}\hbox to \wd0{\hfil}} -\def\partentry#1#2#3#4{\dochapentry{\numeralbox\labelspace#1}{}} -% -% Parts, in the short toc. -\def\shortpartentry#1#2#3#4{% - \penalty-300 - \vskip.5\baselineskip plus.15\baselineskip minus.1\baselineskip - \shortchapentry{{\bf #1}}{\numeralbox}{}{}% -} - % Chapters, in the main contents. \def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}} % @@ -6197,12 +4805,45 @@ \message{environments,} % @foo ... @end foo. -% @tex ... @end tex escapes into raw TeX temporarily. +% @point{}, @result{}, @expansion{}, @print{}, @equiv{}. +% +% Since these characters are used in examples, it should be an even number of +% \tt widths. Each \tt character is 1en, so two makes it 1em. +% +\def\point{$\star$} +\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}} +\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}} +\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}} +\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}} + +% The @error{} command. +% Adapted from the TeXbook's \boxit. +% +\newbox\errorbox +% +{\tentt \global\dimen0 = 3em}% Width of the box. +\dimen2 = .55pt % Thickness of rules +% The text. (`r' is open on the right, `e' somewhat less so on the left.) +\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt} +% +\setbox\errorbox=\hbox to \dimen0{\hfil + \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right. + \advance\hsize by -2\dimen2 % Rules. + \vbox{% + \hrule height\dimen2 + \hbox{\vrule width\dimen2 \kern3pt % Space to left of text. + \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below. + \kern3pt\vrule width\dimen2}% Space to right. + \hrule height\dimen2} + \hfil} +% +\def\error{\leavevmode\lower.7ex\copy\errorbox} + +% @tex ... @end tex escapes into raw Tex temporarily. % One exception: @ is still an escape character, so that @end tex works. -% But \@ or @@ will get a plain @ character. +% But \@ or @@ will get a plain tex @ character. \envdef\tex{% - \setupmarkupstyle{tex}% \catcode `\\=0 \catcode `\{=1 \catcode `\}=2 \catcode `\$=3 \catcode `\&=4 \catcode `\#=6 \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie @@ -6212,14 +4853,8 @@ \catcode `\|=\other \catcode `\<=\other \catcode `\>=\other - \catcode`\`=\other - \catcode`\'=\other \escapechar=`\\ % - % ' is active in math mode (mathcode"8000). So reset it, and all our - % other math active characters (just in case), to plain's definitions. - \mathactive - % \let\b=\ptexb \let\bullet=\ptexbullet \let\c=\ptexc @@ -6237,7 +4872,6 @@ \let\/=\ptexslash \let\*=\ptexstar \let\t=\ptext - \expandafter \let\csname top\endcsname=\ptextop % outer \let\frenchspacing=\plainfrenchspacing % \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}% @@ -6323,12 +4957,6 @@ \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip % Flag to tell @lisp, etc., not to narrow margin. \let\nonarrowing = t% - % - % If this cartouche directly follows a sectioning command, we need the - % \parskip glue (backspaced over by default) or the cartouche can - % collide with the section heading. - \ifnum\lastpenalty>10000 \vskip\parskip \penalty\lastpenalty \fi - % \vbox\bgroup \baselineskip=0pt\parskip=0pt\lineskip=0pt \carttop @@ -6342,7 +4970,7 @@ \lineskip=\normlskip \parskip=\normpskip \vskip -\parskip - \comment % For explanation, see the end of def\group. + \comment % For explanation, see the end of \def\group. } \def\Ecartouche{% \ifhmode\par\fi @@ -6359,7 +4987,6 @@ % This macro is called at the beginning of all the @example variants, % inside a group. -\newdimen\nonfillparindent \def\nonfillstart{% \aboveenvbreak \hfuzz = 12pt % Don't be fussy @@ -6367,12 +4994,7 @@ \let\par = \lisppar % don't ignore blank lines \obeylines % each line of input is a line of output \parskip = 0pt - % Turn off paragraph indentation but redefine \indent to emulate - % the normal \indent. - \nonfillparindent=\parindent \parindent = 0pt - \let\indent\nonfillindent - % \emergencystretch = 0pt % don't try to avoid overfull boxes \ifx\nonarrowing\relax \advance \leftskip by \lispnarrowing @@ -6383,24 +5005,6 @@ \let\exdent=\nofillexdent } -\begingroup -\obeyspaces -% We want to swallow spaces (but not other tokens) after the fake -% @indent in our nonfill-environments, where spaces are normally -% active and set to @tie, resulting in them not being ignored after -% @indent. -\gdef\nonfillindent{\futurelet\temp\nonfillindentcheck}% -\gdef\nonfillindentcheck{% -\ifx\temp % -\expandafter\nonfillindentgobble% -\else% -\leavevmode\nonfillindentbox% -\fi% -}% -\endgroup -\def\nonfillindentgobble#1{\nonfillindent} -\def\nonfillindentbox{\hbox to \nonfillparindent{\hss}} - % If you want all examples etc. small: @set dispenvsize small. % If you want even small examples the full size: @set dispenvsize nosmall. % This affects the following displayed environments: @@ -6411,59 +5015,53 @@ \let\SETdispenvsize\relax \def\setnormaldispenv{% \ifx\SETdispenvsize\smallword - % end paragraph for sake of leading, in case document has no blank - % line. This is redundant with what happens in \aboveenvbreak, but - % we need to do it before changing the fonts, and it's inconvenient - % to change the fonts afterward. - \ifnum \lastpenalty=10000 \else \endgraf \fi \smallexamplefonts \rm \fi } \def\setsmalldispenv{% \ifx\SETdispenvsize\nosmallword \else - \ifnum \lastpenalty=10000 \else \endgraf \fi \smallexamplefonts \rm \fi } % We often define two environments, @foo and @smallfoo. -% Let's do it in one command. #1 is the env name, #2 the definition. -\def\makedispenvdef#1#2{% - \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}% - \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}% +% Let's do it by one command: +\def\makedispenv #1#2{ + \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2} + \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2} \expandafter\let\csname E#1\endcsname \afterenvbreak \expandafter\let\csname Esmall#1\endcsname \afterenvbreak } -% Define two environment synonyms (#1 and #2) for an environment. -\def\maketwodispenvdef#1#2#3{% - \makedispenvdef{#1}{#3}% - \makedispenvdef{#2}{#3}% -} -% -% @lisp: indented, narrowed, typewriter font; -% @example: same as @lisp. +% Define two synonyms: +\def\maketwodispenvs #1#2#3{ + \makedispenv{#1}{#3} + \makedispenv{#2}{#3} +} + +% @lisp: indented, narrowed, typewriter font; @example: same as @lisp. % % @smallexample and @smalllisp: use smaller fonts. % Originally contributed by Pavel@xerox. % -\maketwodispenvdef{lisp}{example}{% +\maketwodispenvs {lisp}{example}{% \nonfillstart - \tt\setupmarkupstyle{example}% + \tt \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special. - \gobble % eat return -} + \gobble % eat return +} + % @display/@smalldisplay: same as @lisp except keep current font. % -\makedispenvdef{display}{% +\makedispenv {display}{% \nonfillstart \gobble } % @format/@smallformat: same as @display except don't narrow margins. % -\makedispenvdef{format}{% +\makedispenv{format}{% \let\nonarrowing = t% \nonfillstart \gobble @@ -6482,44 +5080,18 @@ \envdef\flushright{% \let\nonarrowing = t% \nonfillstart - \advance\leftskip by 0pt plus 1fill\relax + \advance\leftskip by 0pt plus 1fill \gobble } \let\Eflushright = \afterenvbreak -% @raggedright does more-or-less normal line breaking but no right -% justification. From plain.tex. -\envdef\raggedright{% - \rightskip0pt plus2em \spaceskip.3333em \xspaceskip.5em\relax -} -\let\Eraggedright\par - -\envdef\raggedleft{% - \parindent=0pt \leftskip0pt plus2em - \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt - \hbadness=10000 % Last line will usually be underfull, so turn off - % badness reporting. -} -\let\Eraggedleft\par - -\envdef\raggedcenter{% - \parindent=0pt \rightskip0pt plus1em \leftskip0pt plus1em - \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt - \hbadness=10000 % Last line will usually be underfull, so turn off - % badness reporting. -} -\let\Eraggedcenter\par - - % @quotation does normal linebreaking (hence we can't use \nonfillstart) % and narrows the margins. We keep \parskip nonzero in general, since % we're doing normal filling. So, when using \aboveenvbreak and % \afterenvbreak, temporarily make \parskip 0. % -\makedispenvdef{quotation}{\quotationstart} -% -\def\quotationstart{% +\envdef\quotation{% {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip \parindent=0pt % @@ -6539,13 +5111,12 @@ % \def\Equotation{% \par - \ifx\quotationauthor\thisisundefined\else + \ifx\quotationauthor\undefined\else % indent a bit. \leftline{\kern 2\leftskip \sl ---\quotationauthor}% \fi {\parskip=0pt \afterenvbreak}% } -\def\Esmallquotation{\Equotation} % If we're given an argument, typeset it in bold with a colon after. \def\quotationlabel#1{% @@ -6570,16 +5141,18 @@ \do\ \do\\\do\{\do\}\do\$\do\&% \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~% \do\<\do\>\do\|\do\@\do+\do\"% - % Don't do the quotes -- if we do, @set txicodequoteundirected and - % @set txicodequotebacktick will not have effect on @verb and - % @verbatim, and ?` and !` ligatures won't get disabled. - %\do\`\do\'% } % % [Knuth] p. 380 \def\uncatcodespecials{% \def\do##1{\catcode`##1=\other}\dospecials} % +% [Knuth] pp. 380,381,391 +% Disable Spanish ligatures ?` and !` of \tt font +\begingroup + \catcode`\`=\active\gdef`{\relax\lq} +\endgroup +% % Setup for the @verb command. % % Eight spaces for a tab @@ -6591,7 +5164,7 @@ \def\setupverb{% \tt % easiest (and conventionally used) font for verbatim \def\par{\leavevmode\endgraf}% - \setupmarkupstyle{verb}% + \catcode`\`=\active \tabeightspaces % Respect line breaks, % print special symbols as themselves, and @@ -6602,46 +5175,35 @@ % Setup for the @verbatim environment % -% Real tab expansion. +% Real tab expansion \newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount % -% We typeset each line of the verbatim in an \hbox, so we can handle -% tabs. The \global is in case the verbatim line starts with an accent, -% or some other command that starts with a begin-group. Otherwise, the -% entire \verbbox would disappear at the corresponding end-group, before -% it is typeset. Meanwhile, we can't have nested verbatim commands -% (can we?), so the \global won't be overwriting itself. -\newbox\verbbox -\def\starttabbox{\global\setbox\verbbox=\hbox\bgroup} -% +\def\starttabbox{\setbox0=\hbox\bgroup} \begingroup \catcode`\^^I=\active \gdef\tabexpand{% \catcode`\^^I=\active \def^^I{\leavevmode\egroup - \dimen\verbbox=\wd\verbbox % the width so far, or since the previous tab - \divide\dimen\verbbox by\tabw - \multiply\dimen\verbbox by\tabw % compute previous multiple of \tabw - \advance\dimen\verbbox by\tabw % advance to next multiple of \tabw - \wd\verbbox=\dimen\verbbox \box\verbbox \starttabbox + \dimen0=\wd0 % the width so far, or since the previous tab + \divide\dimen0 by\tabw + \multiply\dimen0 by\tabw % compute previous multiple of \tabw + \advance\dimen0 by\tabw % advance to next multiple of \tabw + \wd0=\dimen0 \box0 \starttabbox }% } \endgroup - -% start the verbatim environment. \def\setupverbatim{% \let\nonarrowing = t% \nonfillstart - \tt % easiest (and conventionally used) font for verbatim - % The \leavevmode here is for blank lines. Otherwise, we would - % never \starttabox and the \egroup would end verbatim mode. - \def\par{\leavevmode\egroup\box\verbbox\endgraf}% + % Easiest (and conventionally used) font for verbatim + \tt + \def\par{\leavevmode\egroup\box0\endgraf}% + \catcode`\`=\active \tabexpand - \setupmarkupstyle{verbatim}% % Respect line breaks, % print special symbols as themselves, and - % make each space count. - % Must do in this order: + % make each space count + % must do in this order: \obeylines \uncatcodespecials \sepspaces \everypar{\starttabbox}% } @@ -6697,8 +5259,6 @@ {% \makevalueexpandable \setupverbatim - \indexnofonts % Allow `@@' and other weird things in file names. - \wlog{texinfo.tex: doing @verbatiminclude of #1^^J}% \input #1 \afterenvbreak }% @@ -6724,35 +5284,27 @@ \endgroup } - \message{defuns,} % @defun etc. \newskip\defbodyindent \defbodyindent=.4in \newskip\defargsindent \defargsindent=50pt \newskip\deflastargmargin \deflastargmargin=18pt -\newcount\defunpenalty % Start the processing of @deffn: \def\startdefun{% \ifnum\lastpenalty<10000 \medbreak - \defunpenalty=10003 % Will keep this @deffn together with the - % following @def command, see below. \else % If there are two @def commands in a row, we'll have a \nobreak, % which is there to keep the function description together with its % header. But if there's nothing but headers, we need to allow a % break somewhere. Check specifically for penalty 10002, inserted - % by \printdefunline, instead of 10000, since the sectioning + % by \defargscommonending, instead of 10000, since the sectioning % commands also insert a nobreak penalty, and we don't want to allow % a break between a section heading and a defun. - % - % As a further refinement, we avoid "club" headers by signalling - % with penalty of 10003 after the very first @deffn in the - % sequence (see above), and penalty of 10002 after any following - % @def command. - \ifnum\lastpenalty=10002 \penalty2000 \else \defunpenalty=10002 \fi + % + \ifnum\lastpenalty=10002 \penalty2000 \fi % % Similarly, after a section heading, do not allow a break. % But do insert the glue. @@ -6770,7 +5322,7 @@ % % As above, allow line break if we have multiple x headers in a row. % It's not a great place, though. - \ifnum\lastpenalty=10002 \penalty3000 \else \defunpenalty=10002 \fi + \ifnum\lastpenalty=10002 \penalty3000 \fi % % And now, it's time to reuse the body of the original defun: \expandafter\gobbledefun#1% @@ -6785,10 +5337,10 @@ #1#2 \endheader % common ending: \interlinepenalty = 10000 - \advance\rightskip by 0pt plus 1fil\relax + \advance\rightskip by 0pt plus 1fil \endgraf \nobreak\vskip -\parskip - \penalty\defunpenalty % signal to \startdefun and \dodefunx + \penalty 10002 % signal to \startdefun and \dodefunx % Some of the @defun-type tags do not enable magic parentheses, % rendering the following check redundant. But we don't optimize. \checkparencounts @@ -6798,7 +5350,7 @@ \def\Edefun{\endgraf\medbreak} % \makedefun{deffn} creates \deffn, \deffnx and \Edeffn; -% the only thing remaining is to define \deffnheader. +% the only thing remainnig is to define \deffnheader. % \def\makedefun#1{% \expandafter\let\csname E#1\endcsname = \Edefun @@ -6815,36 +5367,13 @@ \def\domakedefun#1#2#3{% \envdef#1{% \startdefun - \doingtypefnfalse % distinguish typed functions from all else \parseargusing\activeparens{\printdefunline#3}% }% \def#2{\dodefunx#1}% \def#3% } -\newif\ifdoingtypefn % doing typed function? -\newif\ifrettypeownline % typeset return type on its own line? - -% @deftypefnnewline on|off says whether the return type of typed functions -% are printed on their own line. This affects @deftypefn, @deftypefun, -% @deftypeop, and @deftypemethod. -% -\parseargdef\deftypefnnewline{% - \def\temp{#1}% - \ifx\temp\onword - \expandafter\let\csname SETtxideftypefnnl\endcsname - = \empty - \else\ifx\temp\offword - \expandafter\let\csname SETtxideftypefnnl\endcsname - = \relax - \else - \errhelp = \EMsimple - \errmessage{Unknown @txideftypefnnl value `\temp', - must be on|off}% - \fi\fi -} - -% Untyped functions: +%%% Untyped functions: % @deffn category name args \makedefun{deffn}{\deffngeneral{}} @@ -6863,7 +5392,7 @@ \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}% } -% Typed functions: +%%% Typed functions: % @deftypefn category type name args \makedefun{deftypefn}{\deftypefngeneral{}} @@ -6878,11 +5407,10 @@ % \def\deftypefngeneral#1#2 #3 #4 #5\endheader{% \dosubind{fn}{\code{#4}}{#1}% - \doingtypefntrue \defname{#2}{#3}{#4}\defunargs{#5\unskip}% } -% Typed variables: +%%% Typed variables: % @deftypevr category type var args \makedefun{deftypevr}{\deftypecvgeneral{}} @@ -6900,7 +5428,7 @@ \defname{#2}{#3}{#4}\defunargs{#5\unskip}% } -% Untyped variables: +%%% Untyped variables: % @defvr category var args \makedefun{defvr}#1 {\deftypevrheader{#1} {} } @@ -6911,8 +5439,7 @@ % \defcvof {category of}class var args \def\defcvof#1#2 {\deftypecvof{#1}#2 {} } -% Types: - +%%% Type: % @deftp category name args \makedefun{deftp}#1 #2 #3\endheader{% \doind{tp}{\code{#2}}% @@ -6940,49 +5467,25 @@ % We are followed by (but not passed) the arguments, if any. % \def\defname#1#2#3{% - \par % Get the values of \leftskip and \rightskip as they were outside the @def... \advance\leftskip by -\defbodyindent % - % Determine if we are typesetting the return type of a typed function - % on a line by itself. - \rettypeownlinefalse - \ifdoingtypefn % doing a typed function specifically? - % then check user option for putting return type on its own line: - \expandafter\ifx\csname SETtxideftypefnnl\endcsname\relax \else - \rettypeownlinetrue - \fi - \fi - % - % How we'll format the category name. Putting it in brackets helps + % How we'll format the type name. Putting it in brackets helps % distinguish it from the body text that may end up on the next line % just below it. \def\temp{#1}% \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi} % - % Figure out line sizes for the paragraph shape. We'll always have at - % least two. - \tempnum = 2 - % + % Figure out line sizes for the paragraph shape. % The first line needs space for \box0; but if \rightskip is nonzero, % we need only space for the part of \box0 which exceeds it: \dimen0=\hsize \advance\dimen0 by -\wd0 \advance\dimen0 by \rightskip - % - % If doing a return type on its own line, we'll have another line. - \ifrettypeownline - \advance\tempnum by 1 - \def\maybeshapeline{0in \hsize}% - \else - \def\maybeshapeline{}% - \fi - % % The continuations: \dimen2=\hsize \advance\dimen2 by -\defargsindent - % - % The final paragraph shape: - \parshape \tempnum 0in \dimen0 \maybeshapeline \defargsindent \dimen2 - % - % Put the category name at the right margin. + % (plain.tex says that \dimen1 should be used only as global.) + \parshape 2 0in \dimen0 \defargsindent \dimen2 + % + % Put the type name to the right margin. \noindent \hbox to 0pt{% \hfil\box0 \kern-\hsize @@ -7004,16 +5507,8 @@ % . this still does not fix the ?` and !` ligatures, but so far no % one has made identifiers using them :). \df \tt - \def\temp{#2}% text of the return type - \ifx\temp\empty\else - \tclose{\temp}% typeset the return type - \ifrettypeownline - % put return type on its own line; prohibit line break following: - \hfil\vadjust{\nobreak}\break - \else - \space % type on same line, so just followed by a space - \fi - \fi % no return type + \def\temp{#2}% return value type + \ifx\temp\empty\else \tclose{\temp} \fi #3% output function name }% {\rm\enskip}% hskip 0.5 em of \tenrm @@ -7034,7 +5529,7 @@ % % On the other hand, if an argument has two dashes (for instance), we % want a way to get ttsl. Let's try @var for that. - \def\var##1{{\setupmarkupstyle{var}\ttslanted{##1}}}% + \let\var=\ttslanted #1% \sl\hyphenchar\font=45 } @@ -7114,14 +5609,12 @@ \ifnum\parencount=0 \else \badparencount \fi \ifnum\brackcount=0 \else \badbrackcount \fi } -% these should not use \errmessage; the glibc manual, at least, actually -% has such constructs (when documenting function pointers). \def\badparencount{% - \message{Warning: unbalanced parentheses in @def...}% + \errmessage{Unbalanced parentheses in @def}% \global\parencount=0 } \def\badbrackcount{% - \message{Warning: unbalanced square brackets in @def...}% + \errmessage{Unbalanced square braces in @def}% \global\brackcount=0 } @@ -7131,7 +5624,7 @@ % To do this right we need a feature of e-TeX, \scantokens, % which we arrange to emulate with a temporary file in ordinary TeX. -\ifx\eTeXversion\thisisundefined +\ifx\eTeXversion\undefined \newwrite\macscribble \def\scantokens#1{% \toks0={#1}% @@ -7142,30 +5635,26 @@ } \fi -\def\scanmacro#1{\begingroup - \newlinechar`\^^M - \let\xeatspaces\eatspaces - % - % Undo catcode changes of \startcontents and \doprintindex - % When called from @insertcopying or (short)caption, we need active - % backslash to get it printed correctly. Previously, we had - % \catcode`\\=\other instead. We'll see whether a problem appears - % with macro expansion. --kasal, 19aug04 - \catcode`\@=0 \catcode`\\=\active \escapechar=`\@ - % - % ... and for \example: - \spaceisspace - % - % The \empty here causes a following catcode 5 newline to be eaten as - % part of reading whitespace after a control sequence. It does not - % eat a catcode 13 newline. There's no good way to handle the two - % cases (untried: maybe e-TeX's \everyeof could help, though plain TeX - % would then have different behavior). See the Macro Details node in - % the manual for the workaround we recommend for macros and - % line-oriented commands. - % - \scantokens{#1\empty}% -\endgroup} +\def\scanmacro#1{% + \begingroup + \newlinechar`\^^M + \let\xeatspaces\eatspaces + % Undo catcode changes of \startcontents and \doprintindex + % When called from @insertcopying or (short)caption, we need active + % backslash to get it printed correctly. Previously, we had + % \catcode`\\=\other instead. We'll see whether a problem appears + % with macro expansion. --kasal, 19aug04 + \catcode`\@=0 \catcode`\\=\active \escapechar=`\@ + % ... and \example + \spaceisspace + % + % Append \endinput to make sure that TeX does not see the ending newline. + % + % I've verified that it is necessary both for e-TeX and for ordinary TeX + % --kasal, 29nov03 + \scantokens{#1\endinput}% + \endgroup +} \def\scanexp#1{% \edef\temp{\noexpand\scanmacro{#1}}% @@ -7193,7 +5682,7 @@ % This does \let #1 = #2, with \csnames; that is, % \let \csname#1\endcsname = \csname#2\endcsname % (except of course we have to play expansion games). -% +% \def\cslet#1#2{% \expandafter\let \csname#1\expandafter\endcsname @@ -7219,18 +5708,13 @@ % Macro bodies are absorbed as an argument in a context where % all characters are catcode 10, 11 or 12, except \ which is active -% (as in normal texinfo). It is necessary to change the definition of \ -% to recognize macro arguments; this is the job of \mbodybackslash. -% -% Non-ASCII encodings make 8-bit characters active, so un-activate -% them to avoid their expansion. Must do this non-globally, to -% confine the change to the current group. -% +% (as in normal texinfo). It is necessary to change the definition of \. + % It's necessary to have hard CRs when the macro is executed. This is -% done by making ^^M (\endlinechar) catcode 12 when reading the macro +% done by making ^^M (\endlinechar) catcode 12 when reading the macro % body, and then making it the \newlinechar in \scanmacro. -% -\def\scanctxt{% used as subroutine + +\def\scanctxt{% \catcode`\"=\other \catcode`\+=\other \catcode`\<=\other @@ -7240,16 +5724,15 @@ \catcode`\_=\other \catcode`\|=\other \catcode`\~=\other - \ifx\declaredencoding\ascii \else \setnonasciicharscatcodenonglobal\other \fi -} - -\def\scanargctxt{% used for copying and captions, not macros. +} + +\def\scanargctxt{% \scanctxt \catcode`\\=\other \catcode`\^^M=\other } -\def\macrobodyctxt{% used for @macro definitions +\def\macrobodyctxt{% \scanctxt \catcode`\{=\other \catcode`\}=\other @@ -7257,56 +5740,32 @@ \usembodybackslash } -\def\macroargctxt{% used when scanning invocations +\def\macroargctxt{% \scanctxt - \catcode`\\=0 -} -% why catcode 0 for \ in the above? To recognize \\ \{ \} as "escapes" -% for the single characters \ { }. Thus, we end up with the "commands" -% that would be written @\ @{ @} in a Texinfo document. -% -% We already have @{ and @}. For @\, we define it here, and only for -% this purpose, to produce a typewriter backslash (so, the @\ that we -% define for @math can't be used with @macro calls): -% -\def\\{\normalbackslash}% -% -% We would like to do this for \, too, since that is what makeinfo does. -% But it is not possible, because Texinfo already has a command @, for a -% cedilla accent. Documents must use @comma{} instead. -% -% \anythingelse will almost certainly be an error of some kind. - + \catcode`\\=\other +} % \mbodybackslash is the definition of \ in @macro bodies. % It maps \foo\ => \csname macarg.foo\endcsname => #N % where N is the macro parameter number. % We define \csname macarg.\endcsname to be \realbackslash, so % \\ in macro replacement text gets you a backslash. -% + {\catcode`@=0 @catcode`@\=@active @gdef@usembodybackslash{@let\=@mbodybackslash} @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname} } \expandafter\def\csname macarg.\endcsname{\realbackslash} -\def\margbackslash#1{\char`\#1 } - \def\macro{\recursivefalse\parsearg\macroxxx} \def\rmacro{\recursivetrue\parsearg\macroxxx} \def\macroxxx#1{% - \getargs{#1}% now \macname is the macname and \argl the arglist + \getargs{#1}% now \macname is the macname and \argl the arglist \ifx\argl\empty % no arguments - \paramno=0\relax + \paramno=0% \else \expandafter\parsemargdef \argl;% - \if\paramno>256\relax - \ifx\eTeXversion\thisisundefined - \errhelp = \EMsimple - \errmessage{You need eTeX to compile a file with macros with more than 256 arguments} - \fi - \fi \fi \if1\csname ismacro.\the\macname\endcsname \message{Warning: redefining \the\macname}% @@ -7353,269 +5812,46 @@ % an opening brace, and that opening brace is not consumed. \def\getargs#1{\getargsxxx#1{}} \def\getargsxxx#1#{\getmacname #1 \relax\getmacargs} -\def\getmacname#1 #2\relax{\macname={#1}} +\def\getmacname #1 #2\relax{\macname={#1}} \def\getmacargs#1{\def\argl{#1}} -% For macro processing make @ a letter so that we can make Texinfo private macro names. -\edef\texiatcatcode{\the\catcode`\@} -\catcode `@=11\relax - % Parse the optional {params} list. Set up \paramno and \paramlist -% so \defmacro knows what to do. Define \macarg.BLAH for each BLAH -% in the params list to some hook where the argument si to be expanded. If -% there are less than 10 arguments that hook is to be replaced by ##N where N -% is the position in that list, that is to say the macro arguments are to be -% defined `a la TeX in the macro body. -% +% so \defmacro knows what to do. Define \macarg.blah for each blah +% in the params list, to be ##N where N is the position in that list. % That gets used by \mbodybackslash (above). -% + % We need to get `macro parameter char #' into several definitions. -% The technique used is stolen from LaTeX: let \hash be something +% The technique used is stolen from LaTeX: let \hash be something % unexpandable, insert that wherever you need a #, and then redefine % it to # just before using the token list produced. % % The same technique is used to protect \eatspaces till just before % the macro is used. -% -% If there are 10 or more arguments, a different technique is used, where the -% hook remains in the body, and when macro is to be expanded the body is -% processed again to replace the arguments. -% -% In that case, the hook is \the\toks N-1, and we simply set \toks N-1 to the -% argument N value and then \edef the body (nothing else will expand because of -% the catcode regime underwhich the body was input). -% -% If you compile with TeX (not eTeX), and you have macros with 10 or more -% arguments, you need that no macro has more than 256 arguments, otherwise an -% error is produced. -\def\parsemargdef#1;{% - \paramno=0\def\paramlist{}% - \let\hash\relax - \let\xeatspaces\relax - \parsemargdefxxx#1,;,% - % In case that there are 10 or more arguments we parse again the arguments - % list to set new definitions for the \macarg.BLAH macros corresponding to - % each BLAH argument. It was anyhow needed to parse already once this list - % in order to count the arguments, and as macros with at most 9 arguments - % are by far more frequent than macro with 10 or more arguments, defining - % twice the \macarg.BLAH macros does not cost too much processing power. - \ifnum\paramno<10\relax\else - \paramno0\relax - \parsemmanyargdef@@#1,;,% 10 or more arguments - \fi -} + +\def\parsemargdef#1;{\paramno=0\def\paramlist{}% + \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,} \def\parsemargdefxxx#1,{% \if#1;\let\next=\relax \else \let\next=\parsemargdefxxx - \advance\paramno by 1 + \advance\paramno by 1% \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname {\xeatspaces{\hash\the\paramno}}% \edef\paramlist{\paramlist\hash\the\paramno,}% \fi\next} -\def\parsemmanyargdef@@#1,{% - \if#1;\let\next=\relax - \else - \let\next=\parsemmanyargdef@@ - \edef\tempb{\eatspaces{#1}}% - \expandafter\def\expandafter\tempa - \expandafter{\csname macarg.\tempb\endcsname}% - % Note that we need some extra \noexpand\noexpand, this is because we - % don't want \the to be expanded in the \parsermacbody as it uses an - % \xdef . - \expandafter\edef\tempa - {\noexpand\noexpand\noexpand\the\toks\the\paramno}% - \advance\paramno by 1\relax - \fi\next} - % These two commands read recursive and nonrecursive macro bodies. % (They're different since rec and nonrec macros end differently.) -% - -\catcode `\@\texiatcatcode + \long\def\parsemacbody#1@end macro% {\xdef\temp{\eatcr{#1}}\endgroup\defmacro}% \long\def\parsermacbody#1@end rmacro% {\xdef\temp{\eatcr{#1}}\endgroup\defmacro}% -\catcode `\@=11\relax - -\let\endargs@\relax -\let\nil@\relax -\def\nilm@{\nil@}% -\long\def\nillm@{\nil@}% - -% This macro is expanded during the Texinfo macro expansion, not during its -% definition. It gets all the arguments values and assigns them to macros -% macarg.ARGNAME -% -% #1 is the macro name -% #2 is the list of argument names -% #3 is the list of argument values -\def\getargvals@#1#2#3{% - \def\macargdeflist@{}% - \def\saveparamlist@{#2}% Need to keep a copy for parameter expansion. - \def\paramlist{#2,\nil@}% - \def\macroname{#1}% - \begingroup - \macroargctxt - \def\argvaluelist{#3,\nil@}% - \def\@tempa{#3}% - \ifx\@tempa\empty - \setemptyargvalues@ - \else - \getargvals@@ - \fi -} - -% -\def\getargvals@@{% - \ifx\paramlist\nilm@ - % Some sanity check needed here that \argvaluelist is also empty. - \ifx\argvaluelist\nillm@ - \else - \errhelp = \EMsimple - \errmessage{Too many arguments in macro `\macroname'!}% - \fi - \let\next\macargexpandinbody@ - \else - \ifx\argvaluelist\nillm@ - % No more arguments values passed to macro. Set remaining named-arg - % macros to empty. - \let\next\setemptyargvalues@ - \else - % pop current arg name into \@tempb - \def\@tempa##1{\pop@{\@tempb}{\paramlist}##1\endargs@}% - \expandafter\@tempa\expandafter{\paramlist}% - % pop current argument value into \@tempc - \def\@tempa##1{\longpop@{\@tempc}{\argvaluelist}##1\endargs@}% - \expandafter\@tempa\expandafter{\argvaluelist}% - % Here \@tempb is the current arg name and \@tempc is the current arg value. - % First place the new argument macro definition into \@tempd - \expandafter\macname\expandafter{\@tempc}% - \expandafter\let\csname macarg.\@tempb\endcsname\relax - \expandafter\def\expandafter\@tempe\expandafter{% - \csname macarg.\@tempb\endcsname}% - \edef\@tempd{\long\def\@tempe{\the\macname}}% - \push@\@tempd\macargdeflist@ - \let\next\getargvals@@ - \fi - \fi - \next -} - -\def\push@#1#2{% - \expandafter\expandafter\expandafter\def - \expandafter\expandafter\expandafter#2% - \expandafter\expandafter\expandafter{% - \expandafter#1#2}% -} - -% Replace arguments by their values in the macro body, and place the result -% in macro \@tempa -\def\macvalstoargs@{% - % To do this we use the property that token registers that are \the'ed - % within an \edef expand only once. So we are going to place all argument - % values into respective token registers. - % - % First we save the token context, and initialize argument numbering. - \begingroup - \paramno0\relax - % Then, for each argument number #N, we place the corresponding argument - % value into a new token list register \toks#N - \expandafter\putargsintokens@\saveparamlist@,;,% - % Then, we expand the body so that argument are replaced by their - % values. The trick for values not to be expanded themselves is that they - % are within tokens and that tokens expand only once in an \edef . - \edef\@tempc{\csname mac.\macroname .body\endcsname}% - % Now we restore the token stack pointer to free the token list registers - % which we have used, but we make sure that expanded body is saved after - % group. - \expandafter - \endgroup - \expandafter\def\expandafter\@tempa\expandafter{\@tempc}% - } - -\def\macargexpandinbody@{% - %% Define the named-macro outside of this group and then close this group. - \expandafter - \endgroup - \macargdeflist@ - % First the replace in body the macro arguments by their values, the result - % is in \@tempa . - \macvalstoargs@ - % Then we point at the \norecurse or \gobble (for recursive) macro value - % with \@tempb . - \expandafter\let\expandafter\@tempb\csname mac.\macroname .recurse\endcsname - % Depending on whether it is recursive or not, we need some tailing - % \egroup . - \ifx\@tempb\gobble - \let\@tempc\relax - \else - \let\@tempc\egroup - \fi - % And now we do the real job: - \edef\@tempd{\noexpand\@tempb{\macroname}\noexpand\scanmacro{\@tempa}\@tempc}% - \@tempd -} - -\def\putargsintokens@#1,{% - \if#1;\let\next\relax - \else - \let\next\putargsintokens@ - % First we allocate the new token list register, and give it a temporary - % alias \@tempb . - \toksdef\@tempb\the\paramno - % Then we place the argument value into that token list register. - \expandafter\let\expandafter\@tempa\csname macarg.#1\endcsname - \expandafter\@tempb\expandafter{\@tempa}% - \advance\paramno by 1\relax - \fi - \next -} - -% Save the token stack pointer into macro #1 -\def\texisavetoksstackpoint#1{\edef#1{\the\@cclvi}} -% Restore the token stack pointer from number in macro #1 -\def\texirestoretoksstackpoint#1{\expandafter\mathchardef\expandafter\@cclvi#1\relax} -% newtoks that can be used non \outer . -\def\texinonouternewtoks{\alloc@ 5\toks \toksdef \@cclvi} - -% Tailing missing arguments are set to empty -\def\setemptyargvalues@{% - \ifx\paramlist\nilm@ - \let\next\macargexpandinbody@ - \else - \expandafter\setemptyargvaluesparser@\paramlist\endargs@ - \let\next\setemptyargvalues@ - \fi - \next -} - -\def\setemptyargvaluesparser@#1,#2\endargs@{% - \expandafter\def\expandafter\@tempa\expandafter{% - \expandafter\def\csname macarg.#1\endcsname{}}% - \push@\@tempa\macargdeflist@ - \def\paramlist{#2}% -} - -% #1 is the element target macro -% #2 is the list macro -% #3,#4\endargs@ is the list value -\def\pop@#1#2#3,#4\endargs@{% - \def#1{#3}% - \def#2{#4}% -} -\long\def\longpop@#1#2#3,#4\endargs@{% - \long\def#1{#3}% - \long\def#2{#4}% -} - -% This defines a Texinfo @macro. There are eight cases: recursive and -% nonrecursive macros of zero, one, up to nine, and many arguments. + +% This defines the macro itself. There are six cases: recursive and +% nonrecursive macros of zero, one, and many arguments. % Much magic with \expandafter here. % \xdef is used so that macro definitions will survive the file % they're defined in; @include reads the file inside a group. -% \def\defmacro{% \let\hash=##% convert placeholders to macro parameter chars \ifrecursive @@ -7630,25 +5866,17 @@ \expandafter\noexpand\csname\the\macname xxx\endcsname}% \expandafter\xdef\csname\the\macname xxx\endcsname##1{% \egroup\noexpand\scanmacro{\temp}}% - \else - \ifnum\paramno<10\relax % at most 9 - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\csname\the\macname xx\endcsname}% - \expandafter\xdef\csname\the\macname xx\endcsname##1{% - \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}% - \expandafter\expandafter - \expandafter\xdef - \expandafter\expandafter - \csname\the\macname xxx\endcsname - \paramlist{\egroup\noexpand\scanmacro{\temp}}% - \else % 10 or more - \expandafter\xdef\csname\the\macname\endcsname{% - \noexpand\getargvals@{\the\macname}{\argl}% - }% - \global\expandafter\let\csname mac.\the\macname .body\endcsname\temp - \global\expandafter\let\csname mac.\the\macname .recurse\endcsname\gobble - \fi + \else % many + \expandafter\xdef\csname\the\macname\endcsname{% + \bgroup\noexpand\macroargctxt + \noexpand\csname\the\macname xx\endcsname}% + \expandafter\xdef\csname\the\macname xx\endcsname##1{% + \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}% + \expandafter\expandafter + \expandafter\xdef + \expandafter\expandafter + \csname\the\macname xxx\endcsname + \paramlist{\egroup\noexpand\scanmacro{\temp}}% \fi \else \ifcase\paramno @@ -7665,51 +5893,39 @@ \egroup \noexpand\norecurse{\the\macname}% \noexpand\scanmacro{\temp}\egroup}% - \else % at most 9 - \ifnum\paramno<10\relax - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \expandafter\noexpand\csname\the\macname xx\endcsname}% - \expandafter\xdef\csname\the\macname xx\endcsname##1{% - \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}% - \expandafter\expandafter - \expandafter\xdef - \expandafter\expandafter - \csname\the\macname xxx\endcsname - \paramlist{% - \egroup - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \else % 10 or more: - \expandafter\xdef\csname\the\macname\endcsname{% - \noexpand\getargvals@{\the\macname}{\argl}% - }% - \global\expandafter\let\csname mac.\the\macname .body\endcsname\temp - \global\expandafter\let\csname mac.\the\macname .recurse\endcsname\norecurse - \fi + \else % many + \expandafter\xdef\csname\the\macname\endcsname{% + \bgroup\noexpand\macroargctxt + \expandafter\noexpand\csname\the\macname xx\endcsname}% + \expandafter\xdef\csname\the\macname xx\endcsname##1{% + \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}% + \expandafter\expandafter + \expandafter\xdef + \expandafter\expandafter + \csname\the\macname xxx\endcsname + \paramlist{% + \egroup + \noexpand\norecurse{\the\macname}% + \noexpand\scanmacro{\temp}\egroup}% \fi \fi} -\catcode `\@\texiatcatcode\relax - \def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}} % \braceorline decides whether the next nonwhitespace character is a % {. If so it reads up to the closing }, if not, it reads the whole % line. Whatever was read is then fed to the next control sequence -% as an argument (by \parsebrace or \parsearg). -% -\def\braceorline#1{\let\macnamexxx=#1\futurelet\nchar\braceorlinexxx} +% as an argument (by \parsebrace or \parsearg) +\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx} \def\braceorlinexxx{% \ifx\nchar\bgroup\else \expandafter\parsearg - \fi \macnamexxx} + \fi \next} % @alias. % We need some trickery to remove the optional spaces around the equal -% sign. Make them active and then expand them all to nothing. -% +% sign. Just make them active and then expand them all to nothing. \def\alias{\parseargusing\obeyspaces\aliasxxx} \def\aliasxxx #1{\aliasyyy#1\relax} \def\aliasyyy #1=#2\relax{% @@ -7725,13 +5941,13 @@ \message{cross references,} \newwrite\auxfile + \newif\ifhavexrefs % True if xref values are known. \newif\ifwarnedxrefs % True if we warned once that they aren't known. % @inforef is relatively simple. \def\inforef #1{\inforefzzz #1,,,,**} -\def\inforefzzz #1,#2,#3,#4**{% - \putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}}, +\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}}, node \samp{\ignorespaces#1{}}} % @node's only job in TeX is to define \lastnode, which is used in @@ -7770,7 +5986,7 @@ % \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an % anchor), which consists of three parts: -% 1) NAME-title - the current sectioning name taken from \lastsection, +% 1) NAME-title - the current sectioning name taken from \thissection, % or the anchor name. % 2) NAME-snt - section number and type, passed as the SNT arg, or % empty for anchors. @@ -7789,35 +6005,14 @@ \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef ##1}{##2}}% these are parameters of \writexrdef }% - \toks0 = \expandafter{\lastsection}% + \toks0 = \expandafter{\thissection}% \immediate \writexrdef{title}{\the\toks0 }% \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc. - \safewhatsit{\writexrdef{pg}{\folio}}% will be written later, at \shipout + \writexrdef{pg}{\folio}% will be written later, during \shipout }% \fi } -% @xrefautosectiontitle on|off says whether @section(ing) names are used -% automatically in xrefs, if the third arg is not explicitly specified. -% This was provided as a "secret" @set xref-automatic-section-title -% variable, now it's official. -% -\parseargdef\xrefautomaticsectiontitle{% - \def\temp{#1}% - \ifx\temp\onword - \expandafter\let\csname SETxref-automatic-section-title\endcsname - = \empty - \else\ifx\temp\offword - \expandafter\let\csname SETxref-automatic-section-title\endcsname - = \relax - \else - \errhelp = \EMsimple - \errmessage{Unknown @xrefautomaticsectiontitle value `\temp', - must be on|off}% - \fi\fi -} - -% % @xref, @pxref, and @ref generate cross-references. For \xrefX, #1 is % the node name, #2 the name of the Info cross-reference, #3 the printed % node name, #4 the name of the Info file, #5 the name of the printed @@ -7826,41 +6021,26 @@ \def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]} \def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]} \def\ref#1{\xrefX[#1,,,,,,,]} -% -\newbox\toprefbox -\newbox\printedrefnamebox -\newbox\infofilenamebox -\newbox\printedmanualbox -% \def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup \unsepspaces - % - % Get args without leading/trailing spaces. + \def\printedmanual{\ignorespaces #5}% \def\printedrefname{\ignorespaces #3}% - \setbox\printedrefnamebox = \hbox{\printedrefname\unskip}% - % - \def\infofilename{\ignorespaces #4}% - \setbox\infofilenamebox = \hbox{\infofilename\unskip}% - % - \def\printedmanual{\ignorespaces #5}% - \setbox\printedmanualbox = \hbox{\printedmanual\unskip}% - % - % If the printed reference name (arg #3) was not explicitly given in - % the @xref, figure out what we want to use. - \ifdim \wd\printedrefnamebox = 0pt + \setbox1=\hbox{\printedmanual\unskip}% + \setbox0=\hbox{\printedrefname\unskip}% + \ifdim \wd0 = 0pt % No printed node name was explicitly given. - \expandafter\ifx\csname SETxref-automatic-section-title\endcsname \relax - % Not auto section-title: use node name inside the square brackets. + \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax + % Use the node name inside the square brackets. \def\printedrefname{\ignorespaces #1}% \else - % Auto section-title: use chapter/section title inside - % the square brackets if we have it. - \ifdim \wd\printedmanualbox > 0pt - % It is in another manual, so we don't have it; use node name. + % Use the actual chapter/section title appear inside + % the square brackets. Use the real section title if we have it. + \ifdim \wd1 > 0pt + % It is in another manual, so we don't have it. \def\printedrefname{\ignorespaces #1}% \else \ifhavexrefs - % We (should) know the real title if we have the xref values. + % We know the real title if we have the xref values. \def\printedrefname{\refx{#1-title}{}}% \else % Otherwise just copy the Info node name. @@ -7872,32 +6052,22 @@ % % Make link in pdf output. \ifpdf - {\indexnofonts - \turnoffactive - \makevalueexpandable - % This expands tokens, so do it after making catcode changes, so _ - % etc. don't get their TeX definitions. This ignores all spaces in - % #4, including (wrongly) those in the middle of the filename. - \getfilename{#4}% + \leavevmode + \getfilename{#4}% + {\turnoffactive + % See comments at \activebackslashdouble. + {\activebackslashdouble \xdef\pdfxrefdest{#1}% + \backslashparens\pdfxrefdest}% % - % This (wrongly) does not take account of leading or trailing - % spaces in #1, which should be ignored. - \edef\pdfxrefdest{#1}% - \ifx\pdfxrefdest\empty - \def\pdfxrefdest{Top}% no empty targets + \ifnum\filenamelength>0 + \startlink attr{/Border [0 0 0]}% + goto file{\the\filename.pdf} name{\pdfxrefdest}% \else - \txiescapepdf\pdfxrefdest % escape PDF special chars - \fi - % - \leavevmode - \startlink attr{/Border [0 0 0]}% - \ifnum\filenamelength>0 - goto file{\the\filename.pdf} name{\pdfxrefdest}% - \else - goto name{\pdfmkpgn{\pdfxrefdest}}% + \startlink attr{/Border [0 0 0]}% + goto name{\pdfmkpgn{\pdfxrefdest}}% \fi }% - \setcolor{\linkcolor}% + \linkcolor \fi % % Float references are printed completely differently: "Figure 1.2" @@ -7914,42 +6084,29 @@ \iffloat\Xthisreftitle % If the user specified the print name (third arg) to the ref, % print it instead of our usual "Figure 1.2". - \ifdim\wd\printedrefnamebox = 0pt - \refx{#1-snt}{}% + \ifdim\wd0 = 0pt + \refx{#1-snt}% \else \printedrefname \fi % - % If the user also gave the printed manual name (fifth arg), append + % if the user also gave the printed manual name (fifth arg), append % "in MANUALNAME". - \ifdim \wd\printedmanualbox > 0pt + \ifdim \wd1 > 0pt \space \putwordin{} \cite{\printedmanual}% \fi \else % node/anchor (non-float) references. - % - % If we use \unhbox to print the node names, TeX does not insert - % empty discretionaries after hyphens, which means that it will not - % find a line break at a hyphen in a node names. Since some manuals - % are best written with fairly long node names, containing hyphens, - % this is a loss. Therefore, we give the text of the node name - % again, so it is as if TeX is seeing it for the first time. - % - \ifdim \wd\printedmanualbox > 0pt - % Cross-manual reference with a printed manual name. - % - \crossmanualxref{\cite{\printedmanual\unskip}}% % - \else\ifdim \wd\infofilenamebox > 0pt - % Cross-manual reference with only an info filename (arg 4), no - % printed manual name (arg 5). This is essentially the same as - % the case above; we output the filename, since we have nothing else. - % - \crossmanualxref{\code{\infofilename\unskip}}% - % + % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not + % insert empty discretionaries after hyphens, which means that it will + % not find a line break at a hyphen in a node names. Since some manuals + % are best written with fairly long node names, containing hyphens, this + % is a loss. Therefore, we give the text of the node name again, so it + % is as if TeX is seeing it for the first time. + \ifdim \wd1 > 0pt + \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}% \else - % Reference within this manual. - % % _ (for example) has to be the character _ for the purposes of the % control sequence corresponding to the node, but it has to expand % into the usual \leavevmode...\vrule stuff for purposes of @@ -7961,7 +6118,7 @@ \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}% \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi }% - % output the `[mynode]' via the macro below so it can be overridden. + % output the `[mynode]' via a macro so it can be overridden. \xrefprintnodename\printedrefname % % But we always want a comma and a space: @@ -7969,37 +6126,11 @@ % % output the `page 3'. \turnoffactive \putwordpage\tie\refx{#1-pg}{}% - \fi\fi + \fi \fi \endlink \endgroup} -% Output a cross-manual xref to #1. Used just above (twice). -% -% Only include the text "Section ``foo'' in" if the foo is neither -% missing or Top. Thus, @xref{,,,foo,The Foo Manual} outputs simply -% "see The Foo Manual", the idea being to refer to the whole manual. -% -% But, this being TeX, we can't easily compare our node name against the -% string "Top" while ignoring the possible spaces before and after in -% the input. By adding the arbitrary 7sp below, we make it much less -% likely that a real node name would have the same width as "Top" (e.g., -% in a monospaced font). Hopefully it will never happen in practice. -% -% For the same basic reason, we retypeset the "Top" at every -% reference, since the current font is indeterminate. -% -\def\crossmanualxref#1{% - \setbox\toprefbox = \hbox{Top\kern7sp}% - \setbox2 = \hbox{\ignorespaces \printedrefname \unskip \kern7sp}% - \ifdim \wd2 > 7sp % nonempty? - \ifdim \wd2 = \wd\toprefbox \else % same as Top? - \putwordSection{} ``\printedrefname'' \putwordin{}\space - \fi - \fi - #1% -} - % This macro is called from \xrefX for the `[nodename]' part of xref % output. It's a separate macro only so it can be changed more easily, % since square brackets don't work well in some documents. Particularly @@ -8050,8 +6181,7 @@ \angleleft un\-de\-fined\angleright \iflinks \ifhavexrefs - {\toks0 = {#1}% avoid expansion of possibly-complex value - \message{\linenumber Undefined cross reference `\the\toks0'.}}% + \message{\linenumber Undefined cross reference `#1'.}% \else \ifwarnedxrefs\else \global\warnedxrefstrue @@ -8071,18 +6201,10 @@ % collisions). But if this is a float type, we have more work to do. % \def\xrdef#1#2{% - {% The node name might contain 8-bit characters, which in our current - % implementation are changed to commands like @'e. Don't let these - % mess up the control sequence name. - \indexnofonts - \turnoffactive - \xdef\safexrefname{#1}% - }% - % - \expandafter\gdef\csname XR\safexrefname\endcsname{#2}% remember this xref + \expandafter\gdef\csname XR#1\endcsname{#2}% remember this xref value. % % Was that xref control sequence that we just defined for a float? - \expandafter\iffloat\csname XR\safexrefname\endcsname + \expandafter\iffloat\csname XR#1\endcsname % it was a float, and we have the (safe) float type in \iffloattype. \expandafter\let\expandafter\floatlist \csname floatlist\iffloattype\endcsname @@ -8097,8 +6219,7 @@ % % Remember this xref in the control sequence \floatlistFLOATTYPE, % for later use in \listoffloats. - \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0 - {\safexrefname}}% + \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0{#1}}% \fi } @@ -8202,7 +6323,6 @@ \input\jobname.#1 \endgroup} - \message{insertions,} % including footnotes. @@ -8215,7 +6335,7 @@ % space to prevent strange expansion errors.) \def\supereject{\par\penalty -20000\footnoteno =0 } -% @footnotestyle is meaningful for Info output only. +% @footnotestyle is meaningful for info output only. \let\footnotestyle=\comment {\catcode `\@=11 @@ -8278,8 +6398,6 @@ % expands into a box, it must come within the paragraph, lest it % provide a place where TeX can split the footnote. \footstrut - % - % Invoke rest of plain TeX footnote routine. \futurelet\next\fo@t } }%end \catcode `\@=11 @@ -8287,7 +6405,7 @@ % In case a @footnote appears in a vbox, save the footnote text and create % the real \insert just after the vbox finished. Otherwise, the insertion % would be lost. -% Similarly, if a @footnote appears inside an alignment, save the footnote +% Similarily, if a @footnote appears inside an alignment, save the footnote % text to a box and make the \insert when a row of the table is finished. % And the same can be done for other insert classes. --kasal, 16nov03. @@ -8367,7 +6485,7 @@ it from ftp://tug.org/tex/epsf.tex.} % \def\image#1{% - \ifx\epsfbox\thisisundefined + \ifx\epsfbox\undefined \ifwarnednoepsf \else \errhelp = \noepsfhelp \errmessage{epsf.tex not found, images will be ignored}% @@ -8383,7 +6501,7 @@ % #2 is (optional) width, #3 is (optional) height. % #4 is (ignored optional) html alt text. % #5 is (ignored optional) extension. -% #6 is just the usual extra ignored arg for parsing stuff. +% #6 is just the usual extra ignored arg for parsing this stuff. \newif\ifimagevmode \def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup \catcode`\^^M = 5 % in case we're inside an example @@ -8391,30 +6509,15 @@ % If the image is by itself, center it. \ifvmode \imagevmodetrue - \else \ifx\centersub\centerV - % for @center @image, we need a vbox so we can have our vertical space - \imagevmodetrue - \vbox\bgroup % vbox has better behavior than vtop herev - \fi\fi - % - \ifimagevmode - \nobreak\medskip + \nobreak\bigskip % Usually we'll have text after the image which will insert % \parskip glue, so insert it here too to equalize the space % above and below. \nobreak\vskip\parskip \nobreak + \line\bgroup\hss \fi % - % Leave vertical mode so that indentation from an enclosing - % environment such as @quotation is respected. - % However, if we're at the top level, we don't want the - % normal paragraph indentation. - % On the other hand, if we are in the case of @center @image, we don't - % want to start a paragraph, which will create a hsize-width box and - % eradicate the centering. - \ifx\centersub\centerV\else \noindent \fi - % % Output the image. \ifpdf \dopdfimage{#1}{#2}{#3}% @@ -8425,10 +6528,7 @@ \epsfbox{#1.eps}% \fi % - \ifimagevmode - \medskip % space after a standalone image - \fi - \ifx\centersub\centerV \egroup \fi + \ifimagevmode \hss \egroup \bigbreak \fi % space after the image \endgroup} @@ -8495,13 +6595,13 @@ \global\advance\floatno by 1 % {% - % This magic value for \lastsection is output by \setref as the + % This magic value for \thissection is output by \setref as the % XREFLABEL-title value. \xrefX uses it to distinguish float % labels (which have a completely different output format) from % node and anchor labels. And \xrdef uses it to construct the % lists of floats. % - \edef\lastsection{\floatmagic=\safefloattype}% + \edef\thissection{\floatmagic=\safefloattype}% \setref{\floatlabel}{Yfloat}% }% \fi @@ -8569,7 +6669,6 @@ % caption if specified, else the full caption if specified, else nothing. {% \atdummies - % % since we read the caption text in the macro world, where ^^M % is turned into a normal character, we have to scan it back, so % we don't write the literal three characters "^^M" into the aux file. @@ -8590,9 +6689,8 @@ % % place the captured inserts % - % BEWARE: when the floats start floating, we have to issue warning - % whenever an insert appears inside a float which could possibly - % float. --kasal, 26may04 + % BEWARE: when the floats start float, we have to issue warning whenever an + % insert appears inside a float which could possibly float. --kasal, 26may04 % \checkinserts } @@ -8636,7 +6734,7 @@ % #1 is the control sequence we are passed; we expand into a conditional % which is true if #1 represents a float ref. That is, the magic -% \lastsection value which we \setref above. +% \thissection value which we \setref above. % \def\iffloat#1{\expandafter\doiffloat#1==\finish} % @@ -8697,909 +6795,39 @@ \writeentry }} - \message{localization,} - -% For single-language documents, @documentlanguage is usually given very -% early, just after @documentencoding. Single argument is the language -% (de) or locale (de_DE) abbreviation. -% -{ - \catcode`\_ = \active - \globaldefs=1 -\parseargdef\documentlanguage{\begingroup - \let_=\normalunderscore % normal _ character for filenames +% and i18n. + +% @documentlanguage is usually given very early, just after +% @setfilename. If done too late, it may not override everything +% properly. Single argument is the language abbreviation. +% It would be nice if we could set up a hyphenation file here. +% +\parseargdef\documentlanguage{% \tex % read txi-??.tex file in plain TeX. - % Read the file by the name they passed if it exists. + % Read the file if it exists. \openin 1 txi-#1.tex \ifeof 1 - \documentlanguagetrywithoutunderscore{#1_\finish}% + \errhelp = \nolanghelp + \errmessage{Cannot read language file txi-#1.tex}% \else - \globaldefs = 1 % everything in the txi-LL files needs to persist \input txi-#1.tex \fi \closein 1 - \endgroup % end raw TeX -\endgroup} -% -% If they passed de_DE, and txi-de_DE.tex doesn't exist, -% try txi-de.tex. -% -\gdef\documentlanguagetrywithoutunderscore#1_#2\finish{% - \openin 1 txi-#1.tex - \ifeof 1 - \errhelp = \nolanghelp - \errmessage{Cannot read language file txi-#1.tex}% - \else - \globaldefs = 1 % everything in the txi-LL files needs to persist - \input txi-#1.tex - \fi - \closein 1 -} -}% end of special _ catcode -% + \endgroup +} \newhelp\nolanghelp{The given language definition file cannot be found or -is empty. Maybe you need to install it? Putting it in the current -directory should work if nowhere else does.} - -% This macro is called from txi-??.tex files; the first argument is the -% \language name to set (without the "\lang@" prefix), the second and -% third args are \{left,right}hyphenmin. -% -% The language names to pass are determined when the format is built. -% See the etex.log file created at that time, e.g., -% /usr/local/texlive/2008/texmf-var/web2c/pdftex/etex.log. -% -% With TeX Live 2008, etex now includes hyphenation patterns for all -% available languages. This means we can support hyphenation in -% Texinfo, at least to some extent. (This still doesn't solve the -% accented characters problem.) -% -\catcode`@=11 -\def\txisetlanguage#1#2#3{% - % do not set the language if the name is undefined in the current TeX. - \expandafter\ifx\csname lang@#1\endcsname \relax - \message{no patterns for #1}% - \else - \global\language = \csname lang@#1\endcsname - \fi - % but there is no harm in adjusting the hyphenmin values regardless. - \global\lefthyphenmin = #2\relax - \global\righthyphenmin = #3\relax -} - -% Helpers for encodings. -% Set the catcode of characters 128 through 255 to the specified number. -% -\def\setnonasciicharscatcode#1{% - \count255=128 - \loop\ifnum\count255<256 - \global\catcode\count255=#1\relax - \advance\count255 by 1 - \repeat -} - -\def\setnonasciicharscatcodenonglobal#1{% - \count255=128 - \loop\ifnum\count255<256 - \catcode\count255=#1\relax - \advance\count255 by 1 - \repeat -} - -% @documentencoding sets the definition of non-ASCII characters -% according to the specified encoding. -% -\parseargdef\documentencoding{% - % Encoding being declared for the document. - \def\declaredencoding{\csname #1.enc\endcsname}% - % - % Supported encodings: names converted to tokens in order to be able - % to compare them with \ifx. - \def\ascii{\csname US-ASCII.enc\endcsname}% - \def\latnine{\csname ISO-8859-15.enc\endcsname}% - \def\latone{\csname ISO-8859-1.enc\endcsname}% - \def\lattwo{\csname ISO-8859-2.enc\endcsname}% - \def\utfeight{\csname UTF-8.enc\endcsname}% - % - \ifx \declaredencoding \ascii - \asciichardefs - % - \else \ifx \declaredencoding \lattwo - \setnonasciicharscatcode\active - \lattwochardefs - % - \else \ifx \declaredencoding \latone - \setnonasciicharscatcode\active - \latonechardefs - % - \else \ifx \declaredencoding \latnine - \setnonasciicharscatcode\active - \latninechardefs - % - \else \ifx \declaredencoding \utfeight - \setnonasciicharscatcode\active - \utfeightchardefs - % - \else - \message{Unknown document encoding #1, ignoring.}% - % - \fi % utfeight - \fi % latnine - \fi % latone - \fi % lattwo - \fi % ascii -} - -% A message to be logged when using a character that isn't available -% the default font encoding (OT1). -% -\def\missingcharmsg#1{\message{Character missing in OT1 encoding: #1.}} - -% Take account of \c (plain) vs. \, (Texinfo) difference. -\def\cedilla#1{\ifx\c\ptexc\c{#1}\else\,{#1}\fi} - -% First, make active non-ASCII characters in order for them to be -% correctly categorized when TeX reads the replacement text of -% macros containing the character definitions. -\setnonasciicharscatcode\active -% -% Latin1 (ISO-8859-1) character definitions. -\def\latonechardefs{% - \gdef^^a0{\tie} - \gdef^^a1{\exclamdown} - \gdef^^a2{\missingcharmsg{CENT SIGN}} - \gdef^^a3{{\pounds}} - \gdef^^a4{\missingcharmsg{CURRENCY SIGN}} - \gdef^^a5{\missingcharmsg{YEN SIGN}} - \gdef^^a6{\missingcharmsg{BROKEN BAR}} - \gdef^^a7{\S} - \gdef^^a8{\"{}} - \gdef^^a9{\copyright} - \gdef^^aa{\ordf} - \gdef^^ab{\guillemetleft} - \gdef^^ac{$\lnot$} - \gdef^^ad{\-} - \gdef^^ae{\registeredsymbol} - \gdef^^af{\={}} - % - \gdef^^b0{\textdegree} - \gdef^^b1{$\pm$} - \gdef^^b2{$^2$} - \gdef^^b3{$^3$} - \gdef^^b4{\'{}} - \gdef^^b5{$\mu$} - \gdef^^b6{\P} - % - \gdef^^b7{$^.$} - \gdef^^b8{\cedilla\ } - \gdef^^b9{$^1$} - \gdef^^ba{\ordm} - % - \gdef^^bb{\guillemetright} - \gdef^^bc{$1\over4$} - \gdef^^bd{$1\over2$} - \gdef^^be{$3\over4$} - \gdef^^bf{\questiondown} - % - \gdef^^c0{\`A} - \gdef^^c1{\'A} - \gdef^^c2{\^A} - \gdef^^c3{\~A} - \gdef^^c4{\"A} - \gdef^^c5{\ringaccent A} - \gdef^^c6{\AE} - \gdef^^c7{\cedilla C} - \gdef^^c8{\`E} - \gdef^^c9{\'E} - \gdef^^ca{\^E} - \gdef^^cb{\"E} - \gdef^^cc{\`I} - \gdef^^cd{\'I} - \gdef^^ce{\^I} - \gdef^^cf{\"I} - % - \gdef^^d0{\DH} - \gdef^^d1{\~N} - \gdef^^d2{\`O} - \gdef^^d3{\'O} - \gdef^^d4{\^O} - \gdef^^d5{\~O} - \gdef^^d6{\"O} - \gdef^^d7{$\times$} - \gdef^^d8{\O} - \gdef^^d9{\`U} - \gdef^^da{\'U} - \gdef^^db{\^U} - \gdef^^dc{\"U} - \gdef^^dd{\'Y} - \gdef^^de{\TH} - \gdef^^df{\ss} - % - \gdef^^e0{\`a} - \gdef^^e1{\'a} - \gdef^^e2{\^a} - \gdef^^e3{\~a} - \gdef^^e4{\"a} - \gdef^^e5{\ringaccent a} - \gdef^^e6{\ae} - \gdef^^e7{\cedilla c} - \gdef^^e8{\`e} - \gdef^^e9{\'e} - \gdef^^ea{\^e} - \gdef^^eb{\"e} - \gdef^^ec{\`{\dotless i}} - \gdef^^ed{\'{\dotless i}} - \gdef^^ee{\^{\dotless i}} - \gdef^^ef{\"{\dotless i}} - % - \gdef^^f0{\dh} - \gdef^^f1{\~n} - \gdef^^f2{\`o} - \gdef^^f3{\'o} - \gdef^^f4{\^o} - \gdef^^f5{\~o} - \gdef^^f6{\"o} - \gdef^^f7{$\div$} - \gdef^^f8{\o} - \gdef^^f9{\`u} - \gdef^^fa{\'u} - \gdef^^fb{\^u} - \gdef^^fc{\"u} - \gdef^^fd{\'y} - \gdef^^fe{\th} - \gdef^^ff{\"y} -} - -% Latin9 (ISO-8859-15) encoding character definitions. -\def\latninechardefs{% - % Encoding is almost identical to Latin1. - \latonechardefs - % - \gdef^^a4{\euro} - \gdef^^a6{\v S} - \gdef^^a8{\v s} - \gdef^^b4{\v Z} - \gdef^^b8{\v z} - \gdef^^bc{\OE} - \gdef^^bd{\oe} - \gdef^^be{\"Y} -} - -% Latin2 (ISO-8859-2) character definitions. -\def\lattwochardefs{% - \gdef^^a0{\tie} - \gdef^^a1{\ogonek{A}} - \gdef^^a2{\u{}} - \gdef^^a3{\L} - \gdef^^a4{\missingcharmsg{CURRENCY SIGN}} - \gdef^^a5{\v L} - \gdef^^a6{\'S} - \gdef^^a7{\S} - \gdef^^a8{\"{}} - \gdef^^a9{\v S} - \gdef^^aa{\cedilla S} - \gdef^^ab{\v T} - \gdef^^ac{\'Z} - \gdef^^ad{\-} - \gdef^^ae{\v Z} - \gdef^^af{\dotaccent Z} - % - \gdef^^b0{\textdegree} - \gdef^^b1{\ogonek{a}} - \gdef^^b2{\ogonek{ }} - \gdef^^b3{\l} - \gdef^^b4{\'{}} - \gdef^^b5{\v l} - \gdef^^b6{\'s} - \gdef^^b7{\v{}} - \gdef^^b8{\cedilla\ } - \gdef^^b9{\v s} - \gdef^^ba{\cedilla s} - \gdef^^bb{\v t} - \gdef^^bc{\'z} - \gdef^^bd{\H{}} - \gdef^^be{\v z} - \gdef^^bf{\dotaccent z} - % - \gdef^^c0{\'R} - \gdef^^c1{\'A} - \gdef^^c2{\^A} - \gdef^^c3{\u A} - \gdef^^c4{\"A} - \gdef^^c5{\'L} - \gdef^^c6{\'C} - \gdef^^c7{\cedilla C} - \gdef^^c8{\v C} - \gdef^^c9{\'E} - \gdef^^ca{\ogonek{E}} - \gdef^^cb{\"E} - \gdef^^cc{\v E} - \gdef^^cd{\'I} - \gdef^^ce{\^I} - \gdef^^cf{\v D} - % - \gdef^^d0{\DH} - \gdef^^d1{\'N} - \gdef^^d2{\v N} - \gdef^^d3{\'O} - \gdef^^d4{\^O} - \gdef^^d5{\H O} - \gdef^^d6{\"O} - \gdef^^d7{$\times$} - \gdef^^d8{\v R} - \gdef^^d9{\ringaccent U} - \gdef^^da{\'U} - \gdef^^db{\H U} - \gdef^^dc{\"U} - \gdef^^dd{\'Y} - \gdef^^de{\cedilla T} - \gdef^^df{\ss} - % - \gdef^^e0{\'r} - \gdef^^e1{\'a} - \gdef^^e2{\^a} - \gdef^^e3{\u a} - \gdef^^e4{\"a} - \gdef^^e5{\'l} - \gdef^^e6{\'c} - \gdef^^e7{\cedilla c} - \gdef^^e8{\v c} - \gdef^^e9{\'e} - \gdef^^ea{\ogonek{e}} - \gdef^^eb{\"e} - \gdef^^ec{\v e} - \gdef^^ed{\'{\dotless{i}}} - \gdef^^ee{\^{\dotless{i}}} - \gdef^^ef{\v d} - % - \gdef^^f0{\dh} - \gdef^^f1{\'n} - \gdef^^f2{\v n} - \gdef^^f3{\'o} - \gdef^^f4{\^o} - \gdef^^f5{\H o} - \gdef^^f6{\"o} - \gdef^^f7{$\div$} - \gdef^^f8{\v r} - \gdef^^f9{\ringaccent u} - \gdef^^fa{\'u} - \gdef^^fb{\H u} - \gdef^^fc{\"u} - \gdef^^fd{\'y} - \gdef^^fe{\cedilla t} - \gdef^^ff{\dotaccent{}} -} - -% UTF-8 character definitions. -% -% This code to support UTF-8 is based on LaTeX's utf8.def, with some -% changes for Texinfo conventions. It is included here under the GPL by -% permission from Frank Mittelbach and the LaTeX team. -% -\newcount\countUTFx -\newcount\countUTFy -\newcount\countUTFz - -\gdef\UTFviiiTwoOctets#1#2{\expandafter - \UTFviiiDefined\csname u8:#1\string #2\endcsname} -% -\gdef\UTFviiiThreeOctets#1#2#3{\expandafter - \UTFviiiDefined\csname u8:#1\string #2\string #3\endcsname} -% -\gdef\UTFviiiFourOctets#1#2#3#4{\expandafter - \UTFviiiDefined\csname u8:#1\string #2\string #3\string #4\endcsname} - -\gdef\UTFviiiDefined#1{% - \ifx #1\relax - \message{\linenumber Unicode char \string #1 not defined for Texinfo}% - \else - \expandafter #1% - \fi -} - -\begingroup - \catcode`\~13 - \catcode`\"12 - - \def\UTFviiiLoop{% - \global\catcode\countUTFx\active - \uccode`\~\countUTFx - \uppercase\expandafter{\UTFviiiTmp}% - \advance\countUTFx by 1 - \ifnum\countUTFx < \countUTFy - \expandafter\UTFviiiLoop - \fi} - - \countUTFx = "C2 - \countUTFy = "E0 - \def\UTFviiiTmp{% - \xdef~{\noexpand\UTFviiiTwoOctets\string~}} - \UTFviiiLoop - - \countUTFx = "E0 - \countUTFy = "F0 - \def\UTFviiiTmp{% - \xdef~{\noexpand\UTFviiiThreeOctets\string~}} - \UTFviiiLoop - - \countUTFx = "F0 - \countUTFy = "F4 - \def\UTFviiiTmp{% - \xdef~{\noexpand\UTFviiiFourOctets\string~}} - \UTFviiiLoop -\endgroup - -\begingroup - \catcode`\"=12 - \catcode`\<=12 - \catcode`\.=12 - \catcode`\,=12 - \catcode`\;=12 - \catcode`\!=12 - \catcode`\~=13 - - \gdef\DeclareUnicodeCharacter#1#2{% - \countUTFz = "#1\relax - %\wlog{\space\space defining Unicode char U+#1 (decimal \the\countUTFz)}% - \begingroup - \parseXMLCharref - \def\UTFviiiTwoOctets##1##2{% - \csname u8:##1\string ##2\endcsname}% - \def\UTFviiiThreeOctets##1##2##3{% - \csname u8:##1\string ##2\string ##3\endcsname}% - \def\UTFviiiFourOctets##1##2##3##4{% - \csname u8:##1\string ##2\string ##3\string ##4\endcsname}% - \expandafter\expandafter\expandafter\expandafter - \expandafter\expandafter\expandafter - \gdef\UTFviiiTmp{#2}% - \endgroup} - - \gdef\parseXMLCharref{% - \ifnum\countUTFz < "A0\relax - \errhelp = \EMsimple - \errmessage{Cannot define Unicode char value < 00A0}% - \else\ifnum\countUTFz < "800\relax - \parseUTFviiiA,% - \parseUTFviiiB C\UTFviiiTwoOctets.,% - \else\ifnum\countUTFz < "10000\relax - \parseUTFviiiA;% - \parseUTFviiiA,% - \parseUTFviiiB E\UTFviiiThreeOctets.{,;}% - \else - \parseUTFviiiA;% - \parseUTFviiiA,% - \parseUTFviiiA!% - \parseUTFviiiB F\UTFviiiFourOctets.{!,;}% - \fi\fi\fi - } - - \gdef\parseUTFviiiA#1{% - \countUTFx = \countUTFz - \divide\countUTFz by 64 - \countUTFy = \countUTFz - \multiply\countUTFz by 64 - \advance\countUTFx by -\countUTFz - \advance\countUTFx by 128 - \uccode `#1\countUTFx - \countUTFz = \countUTFy} - - \gdef\parseUTFviiiB#1#2#3#4{% - \advance\countUTFz by "#10\relax - \uccode `#3\countUTFz - \uppercase{\gdef\UTFviiiTmp{#2#3#4}}} -\endgroup - -\def\utfeightchardefs{% - \DeclareUnicodeCharacter{00A0}{\tie} - \DeclareUnicodeCharacter{00A1}{\exclamdown} - \DeclareUnicodeCharacter{00A3}{\pounds} - \DeclareUnicodeCharacter{00A8}{\"{ }} - \DeclareUnicodeCharacter{00A9}{\copyright} - \DeclareUnicodeCharacter{00AA}{\ordf} - \DeclareUnicodeCharacter{00AB}{\guillemetleft} - \DeclareUnicodeCharacter{00AD}{\-} - \DeclareUnicodeCharacter{00AE}{\registeredsymbol} - \DeclareUnicodeCharacter{00AF}{\={ }} - - \DeclareUnicodeCharacter{00B0}{\ringaccent{ }} - \DeclareUnicodeCharacter{00B4}{\'{ }} - \DeclareUnicodeCharacter{00B8}{\cedilla{ }} - \DeclareUnicodeCharacter{00BA}{\ordm} - \DeclareUnicodeCharacter{00BB}{\guillemetright} - \DeclareUnicodeCharacter{00BF}{\questiondown} - - \DeclareUnicodeCharacter{00C0}{\`A} - \DeclareUnicodeCharacter{00C1}{\'A} - \DeclareUnicodeCharacter{00C2}{\^A} - \DeclareUnicodeCharacter{00C3}{\~A} - \DeclareUnicodeCharacter{00C4}{\"A} - \DeclareUnicodeCharacter{00C5}{\AA} - \DeclareUnicodeCharacter{00C6}{\AE} - \DeclareUnicodeCharacter{00C7}{\cedilla{C}} - \DeclareUnicodeCharacter{00C8}{\`E} - \DeclareUnicodeCharacter{00C9}{\'E} - \DeclareUnicodeCharacter{00CA}{\^E} - \DeclareUnicodeCharacter{00CB}{\"E} - \DeclareUnicodeCharacter{00CC}{\`I} - \DeclareUnicodeCharacter{00CD}{\'I} - \DeclareUnicodeCharacter{00CE}{\^I} - \DeclareUnicodeCharacter{00CF}{\"I} - - \DeclareUnicodeCharacter{00D0}{\DH} - \DeclareUnicodeCharacter{00D1}{\~N} - \DeclareUnicodeCharacter{00D2}{\`O} - \DeclareUnicodeCharacter{00D3}{\'O} - \DeclareUnicodeCharacter{00D4}{\^O} - \DeclareUnicodeCharacter{00D5}{\~O} - \DeclareUnicodeCharacter{00D6}{\"O} - \DeclareUnicodeCharacter{00D8}{\O} - \DeclareUnicodeCharacter{00D9}{\`U} - \DeclareUnicodeCharacter{00DA}{\'U} - \DeclareUnicodeCharacter{00DB}{\^U} - \DeclareUnicodeCharacter{00DC}{\"U} - \DeclareUnicodeCharacter{00DD}{\'Y} - \DeclareUnicodeCharacter{00DE}{\TH} - \DeclareUnicodeCharacter{00DF}{\ss} - - \DeclareUnicodeCharacter{00E0}{\`a} - \DeclareUnicodeCharacter{00E1}{\'a} - \DeclareUnicodeCharacter{00E2}{\^a} - \DeclareUnicodeCharacter{00E3}{\~a} - \DeclareUnicodeCharacter{00E4}{\"a} - \DeclareUnicodeCharacter{00E5}{\aa} - \DeclareUnicodeCharacter{00E6}{\ae} - \DeclareUnicodeCharacter{00E7}{\cedilla{c}} - \DeclareUnicodeCharacter{00E8}{\`e} - \DeclareUnicodeCharacter{00E9}{\'e} - \DeclareUnicodeCharacter{00EA}{\^e} - \DeclareUnicodeCharacter{00EB}{\"e} - \DeclareUnicodeCharacter{00EC}{\`{\dotless{i}}} - \DeclareUnicodeCharacter{00ED}{\'{\dotless{i}}} - \DeclareUnicodeCharacter{00EE}{\^{\dotless{i}}} - \DeclareUnicodeCharacter{00EF}{\"{\dotless{i}}} - - \DeclareUnicodeCharacter{00F0}{\dh} - \DeclareUnicodeCharacter{00F1}{\~n} - \DeclareUnicodeCharacter{00F2}{\`o} - \DeclareUnicodeCharacter{00F3}{\'o} - \DeclareUnicodeCharacter{00F4}{\^o} - \DeclareUnicodeCharacter{00F5}{\~o} - \DeclareUnicodeCharacter{00F6}{\"o} - \DeclareUnicodeCharacter{00F8}{\o} - \DeclareUnicodeCharacter{00F9}{\`u} - \DeclareUnicodeCharacter{00FA}{\'u} - \DeclareUnicodeCharacter{00FB}{\^u} - \DeclareUnicodeCharacter{00FC}{\"u} - \DeclareUnicodeCharacter{00FD}{\'y} - \DeclareUnicodeCharacter{00FE}{\th} - \DeclareUnicodeCharacter{00FF}{\"y} - - \DeclareUnicodeCharacter{0100}{\=A} - \DeclareUnicodeCharacter{0101}{\=a} - \DeclareUnicodeCharacter{0102}{\u{A}} - \DeclareUnicodeCharacter{0103}{\u{a}} - \DeclareUnicodeCharacter{0104}{\ogonek{A}} - \DeclareUnicodeCharacter{0105}{\ogonek{a}} - \DeclareUnicodeCharacter{0106}{\'C} - \DeclareUnicodeCharacter{0107}{\'c} - \DeclareUnicodeCharacter{0108}{\^C} - \DeclareUnicodeCharacter{0109}{\^c} - \DeclareUnicodeCharacter{0118}{\ogonek{E}} - \DeclareUnicodeCharacter{0119}{\ogonek{e}} - \DeclareUnicodeCharacter{010A}{\dotaccent{C}} - \DeclareUnicodeCharacter{010B}{\dotaccent{c}} - \DeclareUnicodeCharacter{010C}{\v{C}} - \DeclareUnicodeCharacter{010D}{\v{c}} - \DeclareUnicodeCharacter{010E}{\v{D}} - - \DeclareUnicodeCharacter{0112}{\=E} - \DeclareUnicodeCharacter{0113}{\=e} - \DeclareUnicodeCharacter{0114}{\u{E}} - \DeclareUnicodeCharacter{0115}{\u{e}} - \DeclareUnicodeCharacter{0116}{\dotaccent{E}} - \DeclareUnicodeCharacter{0117}{\dotaccent{e}} - \DeclareUnicodeCharacter{011A}{\v{E}} - \DeclareUnicodeCharacter{011B}{\v{e}} - \DeclareUnicodeCharacter{011C}{\^G} - \DeclareUnicodeCharacter{011D}{\^g} - \DeclareUnicodeCharacter{011E}{\u{G}} - \DeclareUnicodeCharacter{011F}{\u{g}} - - \DeclareUnicodeCharacter{0120}{\dotaccent{G}} - \DeclareUnicodeCharacter{0121}{\dotaccent{g}} - \DeclareUnicodeCharacter{0124}{\^H} - \DeclareUnicodeCharacter{0125}{\^h} - \DeclareUnicodeCharacter{0128}{\~I} - \DeclareUnicodeCharacter{0129}{\~{\dotless{i}}} - \DeclareUnicodeCharacter{012A}{\=I} - \DeclareUnicodeCharacter{012B}{\={\dotless{i}}} - \DeclareUnicodeCharacter{012C}{\u{I}} - \DeclareUnicodeCharacter{012D}{\u{\dotless{i}}} - - \DeclareUnicodeCharacter{0130}{\dotaccent{I}} - \DeclareUnicodeCharacter{0131}{\dotless{i}} - \DeclareUnicodeCharacter{0132}{IJ} - \DeclareUnicodeCharacter{0133}{ij} - \DeclareUnicodeCharacter{0134}{\^J} - \DeclareUnicodeCharacter{0135}{\^{\dotless{j}}} - \DeclareUnicodeCharacter{0139}{\'L} - \DeclareUnicodeCharacter{013A}{\'l} - - \DeclareUnicodeCharacter{0141}{\L} - \DeclareUnicodeCharacter{0142}{\l} - \DeclareUnicodeCharacter{0143}{\'N} - \DeclareUnicodeCharacter{0144}{\'n} - \DeclareUnicodeCharacter{0147}{\v{N}} - \DeclareUnicodeCharacter{0148}{\v{n}} - \DeclareUnicodeCharacter{014C}{\=O} - \DeclareUnicodeCharacter{014D}{\=o} - \DeclareUnicodeCharacter{014E}{\u{O}} - \DeclareUnicodeCharacter{014F}{\u{o}} - - \DeclareUnicodeCharacter{0150}{\H{O}} - \DeclareUnicodeCharacter{0151}{\H{o}} - \DeclareUnicodeCharacter{0152}{\OE} - \DeclareUnicodeCharacter{0153}{\oe} - \DeclareUnicodeCharacter{0154}{\'R} - \DeclareUnicodeCharacter{0155}{\'r} - \DeclareUnicodeCharacter{0158}{\v{R}} - \DeclareUnicodeCharacter{0159}{\v{r}} - \DeclareUnicodeCharacter{015A}{\'S} - \DeclareUnicodeCharacter{015B}{\'s} - \DeclareUnicodeCharacter{015C}{\^S} - \DeclareUnicodeCharacter{015D}{\^s} - \DeclareUnicodeCharacter{015E}{\cedilla{S}} - \DeclareUnicodeCharacter{015F}{\cedilla{s}} - - \DeclareUnicodeCharacter{0160}{\v{S}} - \DeclareUnicodeCharacter{0161}{\v{s}} - \DeclareUnicodeCharacter{0162}{\cedilla{t}} - \DeclareUnicodeCharacter{0163}{\cedilla{T}} - \DeclareUnicodeCharacter{0164}{\v{T}} - - \DeclareUnicodeCharacter{0168}{\~U} - \DeclareUnicodeCharacter{0169}{\~u} - \DeclareUnicodeCharacter{016A}{\=U} - \DeclareUnicodeCharacter{016B}{\=u} - \DeclareUnicodeCharacter{016C}{\u{U}} - \DeclareUnicodeCharacter{016D}{\u{u}} - \DeclareUnicodeCharacter{016E}{\ringaccent{U}} - \DeclareUnicodeCharacter{016F}{\ringaccent{u}} - - \DeclareUnicodeCharacter{0170}{\H{U}} - \DeclareUnicodeCharacter{0171}{\H{u}} - \DeclareUnicodeCharacter{0174}{\^W} - \DeclareUnicodeCharacter{0175}{\^w} - \DeclareUnicodeCharacter{0176}{\^Y} - \DeclareUnicodeCharacter{0177}{\^y} - \DeclareUnicodeCharacter{0178}{\"Y} - \DeclareUnicodeCharacter{0179}{\'Z} - \DeclareUnicodeCharacter{017A}{\'z} - \DeclareUnicodeCharacter{017B}{\dotaccent{Z}} - \DeclareUnicodeCharacter{017C}{\dotaccent{z}} - \DeclareUnicodeCharacter{017D}{\v{Z}} - \DeclareUnicodeCharacter{017E}{\v{z}} - - \DeclareUnicodeCharacter{01C4}{D\v{Z}} - \DeclareUnicodeCharacter{01C5}{D\v{z}} - \DeclareUnicodeCharacter{01C6}{d\v{z}} - \DeclareUnicodeCharacter{01C7}{LJ} - \DeclareUnicodeCharacter{01C8}{Lj} - \DeclareUnicodeCharacter{01C9}{lj} - \DeclareUnicodeCharacter{01CA}{NJ} - \DeclareUnicodeCharacter{01CB}{Nj} - \DeclareUnicodeCharacter{01CC}{nj} - \DeclareUnicodeCharacter{01CD}{\v{A}} - \DeclareUnicodeCharacter{01CE}{\v{a}} - \DeclareUnicodeCharacter{01CF}{\v{I}} - - \DeclareUnicodeCharacter{01D0}{\v{\dotless{i}}} - \DeclareUnicodeCharacter{01D1}{\v{O}} - \DeclareUnicodeCharacter{01D2}{\v{o}} - \DeclareUnicodeCharacter{01D3}{\v{U}} - \DeclareUnicodeCharacter{01D4}{\v{u}} - - \DeclareUnicodeCharacter{01E2}{\={\AE}} - \DeclareUnicodeCharacter{01E3}{\={\ae}} - \DeclareUnicodeCharacter{01E6}{\v{G}} - \DeclareUnicodeCharacter{01E7}{\v{g}} - \DeclareUnicodeCharacter{01E8}{\v{K}} - \DeclareUnicodeCharacter{01E9}{\v{k}} - - \DeclareUnicodeCharacter{01F0}{\v{\dotless{j}}} - \DeclareUnicodeCharacter{01F1}{DZ} - \DeclareUnicodeCharacter{01F2}{Dz} - \DeclareUnicodeCharacter{01F3}{dz} - \DeclareUnicodeCharacter{01F4}{\'G} - \DeclareUnicodeCharacter{01F5}{\'g} - \DeclareUnicodeCharacter{01F8}{\`N} - \DeclareUnicodeCharacter{01F9}{\`n} - \DeclareUnicodeCharacter{01FC}{\'{\AE}} - \DeclareUnicodeCharacter{01FD}{\'{\ae}} - \DeclareUnicodeCharacter{01FE}{\'{\O}} - \DeclareUnicodeCharacter{01FF}{\'{\o}} - - \DeclareUnicodeCharacter{021E}{\v{H}} - \DeclareUnicodeCharacter{021F}{\v{h}} - - \DeclareUnicodeCharacter{0226}{\dotaccent{A}} - \DeclareUnicodeCharacter{0227}{\dotaccent{a}} - \DeclareUnicodeCharacter{0228}{\cedilla{E}} - \DeclareUnicodeCharacter{0229}{\cedilla{e}} - \DeclareUnicodeCharacter{022E}{\dotaccent{O}} - \DeclareUnicodeCharacter{022F}{\dotaccent{o}} - - \DeclareUnicodeCharacter{0232}{\=Y} - \DeclareUnicodeCharacter{0233}{\=y} - \DeclareUnicodeCharacter{0237}{\dotless{j}} - - \DeclareUnicodeCharacter{02DB}{\ogonek{ }} - - \DeclareUnicodeCharacter{1E02}{\dotaccent{B}} - \DeclareUnicodeCharacter{1E03}{\dotaccent{b}} - \DeclareUnicodeCharacter{1E04}{\udotaccent{B}} - \DeclareUnicodeCharacter{1E05}{\udotaccent{b}} - \DeclareUnicodeCharacter{1E06}{\ubaraccent{B}} - \DeclareUnicodeCharacter{1E07}{\ubaraccent{b}} - \DeclareUnicodeCharacter{1E0A}{\dotaccent{D}} - \DeclareUnicodeCharacter{1E0B}{\dotaccent{d}} - \DeclareUnicodeCharacter{1E0C}{\udotaccent{D}} - \DeclareUnicodeCharacter{1E0D}{\udotaccent{d}} - \DeclareUnicodeCharacter{1E0E}{\ubaraccent{D}} - \DeclareUnicodeCharacter{1E0F}{\ubaraccent{d}} - - \DeclareUnicodeCharacter{1E1E}{\dotaccent{F}} - \DeclareUnicodeCharacter{1E1F}{\dotaccent{f}} - - \DeclareUnicodeCharacter{1E20}{\=G} - \DeclareUnicodeCharacter{1E21}{\=g} - \DeclareUnicodeCharacter{1E22}{\dotaccent{H}} - \DeclareUnicodeCharacter{1E23}{\dotaccent{h}} - \DeclareUnicodeCharacter{1E24}{\udotaccent{H}} - \DeclareUnicodeCharacter{1E25}{\udotaccent{h}} - \DeclareUnicodeCharacter{1E26}{\"H} - \DeclareUnicodeCharacter{1E27}{\"h} - - \DeclareUnicodeCharacter{1E30}{\'K} - \DeclareUnicodeCharacter{1E31}{\'k} - \DeclareUnicodeCharacter{1E32}{\udotaccent{K}} - \DeclareUnicodeCharacter{1E33}{\udotaccent{k}} - \DeclareUnicodeCharacter{1E34}{\ubaraccent{K}} - \DeclareUnicodeCharacter{1E35}{\ubaraccent{k}} - \DeclareUnicodeCharacter{1E36}{\udotaccent{L}} - \DeclareUnicodeCharacter{1E37}{\udotaccent{l}} - \DeclareUnicodeCharacter{1E3A}{\ubaraccent{L}} - \DeclareUnicodeCharacter{1E3B}{\ubaraccent{l}} - \DeclareUnicodeCharacter{1E3E}{\'M} - \DeclareUnicodeCharacter{1E3F}{\'m} - - \DeclareUnicodeCharacter{1E40}{\dotaccent{M}} - \DeclareUnicodeCharacter{1E41}{\dotaccent{m}} - \DeclareUnicodeCharacter{1E42}{\udotaccent{M}} - \DeclareUnicodeCharacter{1E43}{\udotaccent{m}} - \DeclareUnicodeCharacter{1E44}{\dotaccent{N}} - \DeclareUnicodeCharacter{1E45}{\dotaccent{n}} - \DeclareUnicodeCharacter{1E46}{\udotaccent{N}} - \DeclareUnicodeCharacter{1E47}{\udotaccent{n}} - \DeclareUnicodeCharacter{1E48}{\ubaraccent{N}} - \DeclareUnicodeCharacter{1E49}{\ubaraccent{n}} - - \DeclareUnicodeCharacter{1E54}{\'P} - \DeclareUnicodeCharacter{1E55}{\'p} - \DeclareUnicodeCharacter{1E56}{\dotaccent{P}} - \DeclareUnicodeCharacter{1E57}{\dotaccent{p}} - \DeclareUnicodeCharacter{1E58}{\dotaccent{R}} - \DeclareUnicodeCharacter{1E59}{\dotaccent{r}} - \DeclareUnicodeCharacter{1E5A}{\udotaccent{R}} - \DeclareUnicodeCharacter{1E5B}{\udotaccent{r}} - \DeclareUnicodeCharacter{1E5E}{\ubaraccent{R}} - \DeclareUnicodeCharacter{1E5F}{\ubaraccent{r}} - - \DeclareUnicodeCharacter{1E60}{\dotaccent{S}} - \DeclareUnicodeCharacter{1E61}{\dotaccent{s}} - \DeclareUnicodeCharacter{1E62}{\udotaccent{S}} - \DeclareUnicodeCharacter{1E63}{\udotaccent{s}} - \DeclareUnicodeCharacter{1E6A}{\dotaccent{T}} - \DeclareUnicodeCharacter{1E6B}{\dotaccent{t}} - \DeclareUnicodeCharacter{1E6C}{\udotaccent{T}} - \DeclareUnicodeCharacter{1E6D}{\udotaccent{t}} - \DeclareUnicodeCharacter{1E6E}{\ubaraccent{T}} - \DeclareUnicodeCharacter{1E6F}{\ubaraccent{t}} - - \DeclareUnicodeCharacter{1E7C}{\~V} - \DeclareUnicodeCharacter{1E7D}{\~v} - \DeclareUnicodeCharacter{1E7E}{\udotaccent{V}} - \DeclareUnicodeCharacter{1E7F}{\udotaccent{v}} - - \DeclareUnicodeCharacter{1E80}{\`W} - \DeclareUnicodeCharacter{1E81}{\`w} - \DeclareUnicodeCharacter{1E82}{\'W} - \DeclareUnicodeCharacter{1E83}{\'w} - \DeclareUnicodeCharacter{1E84}{\"W} - \DeclareUnicodeCharacter{1E85}{\"w} - \DeclareUnicodeCharacter{1E86}{\dotaccent{W}} - \DeclareUnicodeCharacter{1E87}{\dotaccent{w}} - \DeclareUnicodeCharacter{1E88}{\udotaccent{W}} - \DeclareUnicodeCharacter{1E89}{\udotaccent{w}} - \DeclareUnicodeCharacter{1E8A}{\dotaccent{X}} - \DeclareUnicodeCharacter{1E8B}{\dotaccent{x}} - \DeclareUnicodeCharacter{1E8C}{\"X} - \DeclareUnicodeCharacter{1E8D}{\"x} - \DeclareUnicodeCharacter{1E8E}{\dotaccent{Y}} - \DeclareUnicodeCharacter{1E8F}{\dotaccent{y}} - - \DeclareUnicodeCharacter{1E90}{\^Z} - \DeclareUnicodeCharacter{1E91}{\^z} - \DeclareUnicodeCharacter{1E92}{\udotaccent{Z}} - \DeclareUnicodeCharacter{1E93}{\udotaccent{z}} - \DeclareUnicodeCharacter{1E94}{\ubaraccent{Z}} - \DeclareUnicodeCharacter{1E95}{\ubaraccent{z}} - \DeclareUnicodeCharacter{1E96}{\ubaraccent{h}} - \DeclareUnicodeCharacter{1E97}{\"t} - \DeclareUnicodeCharacter{1E98}{\ringaccent{w}} - \DeclareUnicodeCharacter{1E99}{\ringaccent{y}} - - \DeclareUnicodeCharacter{1EA0}{\udotaccent{A}} - \DeclareUnicodeCharacter{1EA1}{\udotaccent{a}} - - \DeclareUnicodeCharacter{1EB8}{\udotaccent{E}} - \DeclareUnicodeCharacter{1EB9}{\udotaccent{e}} - \DeclareUnicodeCharacter{1EBC}{\~E} - \DeclareUnicodeCharacter{1EBD}{\~e} - - \DeclareUnicodeCharacter{1ECA}{\udotaccent{I}} - \DeclareUnicodeCharacter{1ECB}{\udotaccent{i}} - \DeclareUnicodeCharacter{1ECC}{\udotaccent{O}} - \DeclareUnicodeCharacter{1ECD}{\udotaccent{o}} - - \DeclareUnicodeCharacter{1EE4}{\udotaccent{U}} - \DeclareUnicodeCharacter{1EE5}{\udotaccent{u}} - - \DeclareUnicodeCharacter{1EF2}{\`Y} - \DeclareUnicodeCharacter{1EF3}{\`y} - \DeclareUnicodeCharacter{1EF4}{\udotaccent{Y}} - - \DeclareUnicodeCharacter{1EF8}{\~Y} - \DeclareUnicodeCharacter{1EF9}{\~y} - - \DeclareUnicodeCharacter{2013}{--} - \DeclareUnicodeCharacter{2014}{---} - \DeclareUnicodeCharacter{2018}{\quoteleft} - \DeclareUnicodeCharacter{2019}{\quoteright} - \DeclareUnicodeCharacter{201A}{\quotesinglbase} - \DeclareUnicodeCharacter{201C}{\quotedblleft} - \DeclareUnicodeCharacter{201D}{\quotedblright} - \DeclareUnicodeCharacter{201E}{\quotedblbase} - \DeclareUnicodeCharacter{2022}{\bullet} - \DeclareUnicodeCharacter{2026}{\dots} - \DeclareUnicodeCharacter{2039}{\guilsinglleft} - \DeclareUnicodeCharacter{203A}{\guilsinglright} - \DeclareUnicodeCharacter{20AC}{\euro} - - \DeclareUnicodeCharacter{2192}{\expansion} - \DeclareUnicodeCharacter{21D2}{\result} - - \DeclareUnicodeCharacter{2212}{\minus} - \DeclareUnicodeCharacter{2217}{\point} - \DeclareUnicodeCharacter{2261}{\equiv} -}% end of \utfeightchardefs - - -% US-ASCII character definitions. -\def\asciichardefs{% nothing need be done - \relax -} - -% Make non-ASCII characters printable again for compatibility with -% existing Texinfo documents that may use them, even without declaring a -% document encoding. -% -\setnonasciicharscatcode \other - - -\message{formatting,} - +is empty. Maybe you need to install it? In the current directory +should work if nowhere else does.} + + +% @documentencoding should change something in TeX eventually, most +% likely, but for now just recognize it. +\let\documentencoding = \comment + + +% Page size parameters. +% \newdimen\defaultparindent \defaultparindent = 15pt \chapheadingskip = 15pt plus 4pt minus 2pt @@ -9609,10 +6837,10 @@ % Prevent underfull vbox error messages. \vbadness = 10000 -% Don't be very finicky about underfull hboxes, either. -\hbadness = 6666 - -% Following George Bush, get rid of widows and orphans. +% Don't be so finicky about underfull hboxes, either. +\hbadness = 2000 + +% Following George Bush, just get rid of widows and orphans. \widowpenalty=10000 \clubpenalty=10000 @@ -9659,10 +6887,6 @@ \ifpdf \pdfpageheight #7\relax \pdfpagewidth #8\relax - % if we don't reset these, they will remain at "1 true in" of - % whatever layout pdftex was dumped with. - \pdfhorigin = 1 true in - \pdfvorigin = 1 true in \fi % \setleading{\textleading} @@ -9677,7 +6901,7 @@ \textleading = 13.2pt % % If page is nothing but text, make it come out even. - \internalpagesizes{607.2pt}{6in}% that's 46 lines + \internalpagesizes{46\baselineskip}{6in}% {\voffset}{.25in}% {\bindingoffset}{36pt}% {11in}{8.5in}% @@ -9689,7 +6913,7 @@ \textleading = 12pt % \internalpagesizes{7.5in}{5in}% - {-.2in}{0in}% + {\voffset}{.25in}% {\bindingoffset}{16pt}% {9.25in}{7in}% % @@ -9733,7 +6957,7 @@ % \global\normaloffset = -6mm % \global\bindingoffset = 10mm % @end tex - \internalpagesizes{673.2pt}{160mm}% that's 51 lines + \internalpagesizes{51\baselineskip}{160mm} {\voffset}{\hoffset}% {\bindingoffset}{44pt}% {297mm}{210mm}% @@ -9798,7 +7022,7 @@ \parskip = 3pt plus 2pt minus 1pt \setleading{\textleading}% % - \dimen0 = #1\relax + \dimen0 = #1 \advance\dimen0 by \voffset % \dimen2 = \hsize @@ -9817,21 +7041,25 @@ \message{and turning on texinfo input format.} -\def^^L{\par} % remove \outer, so ^L can appear in an @comment - -% DEL is a comment character, in case @c does not suffice. -\catcode`\^^? = 14 - % Define macros to output various characters with catcode for normal text. -\catcode`\"=\other \def\normaldoublequote{"} -\catcode`\$=\other \def\normaldollar{$}%$ font-lock fix -\catcode`\+=\other \def\normalplus{+} -\catcode`\<=\other \def\normalless{<} -\catcode`\>=\other \def\normalgreater{>} -\catcode`\^=\other \def\normalcaret{^} -\catcode`\_=\other \def\normalunderscore{_} -\catcode`\|=\other \def\normalverticalbar{|} -\catcode`\~=\other \def\normaltilde{~} +\catcode`\"=\other +\catcode`\~=\other +\catcode`\^=\other +\catcode`\_=\other +\catcode`\|=\other +\catcode`\<=\other +\catcode`\>=\other +\catcode`\+=\other +\catcode`\$=\other +\def\normaldoublequote{"} +\def\normaltilde{~} +\def\normalcaret{^} +\def\normalunderscore{_} +\def\normalverticalbar{|} +\def\normalless{<} +\def\normalgreater{>} +\def\normalplus{+} +\def\normaldollar{$}%$ font-lock fix % This macro is used to make a character print one way in \tt % (where it can probably be output as-is), and another way in other fonts, @@ -9889,13 +7117,6 @@ % \otherifyactive is called near the end of this file. \def\otherifyactive{\catcode`+=\other \catcode`\_=\other} -% Used sometimes to turn off (effectively) the active characters even after -% parsing them. -\def\turnoffactive{% - \normalturnoffactive - \otherbackslash -} - \catcode`\@=0 % \backslashcurfont outputs one backslash character in current font, @@ -9903,52 +7124,45 @@ \global\chardef\backslashcurfont=`\\ \global\let\rawbackslashxx=\backslashcurfont % let existing .??s files work +% \rawbackslash defines an active \ to do \backslashcurfont. +% \otherbackslash defines an active \ to be a literal `\' character with +% catcode other. +{\catcode`\\=\active + @gdef@rawbackslash{@let\=@backslashcurfont} + @gdef@otherbackslash{@let\=@realbackslash} +} + % \realbackslash is an actual character `\' with catcode other, and % \doublebackslash is two of them (for the pdf outlines). {\catcode`\\=\other @gdef@realbackslash{\} @gdef@doublebackslash{\\}} -% In texinfo, backslash is an active character; it prints the backslash -% in fixed width font. -\catcode`\\=\active % @ for escape char from now on. - -% The story here is that in math mode, the \char of \backslashcurfont -% ends up printing the roman \ from the math symbol font (because \char -% in math mode uses the \mathcode, and plain.tex sets -% \mathcode`\\="026E). It seems better for @backslashchar{} to always -% print a typewriter backslash, hence we use an explicit \mathchar, -% which is the decimal equivalent of "715c (class 7, e.g., use \fam; -% ignored family value; char position "5C). We can't use " for the -% usual hex value because it has already been made active. -@def@normalbackslash{{@tt @ifmmode @mathchar29020 @else @backslashcurfont @fi}} -@let@backslashchar = @normalbackslash % @backslashchar{} is for user documents. - -% On startup, @fixbackslash assigns: -% @let \ = @normalbackslash -% \rawbackslash defines an active \ to do \backslashcurfont. -% \otherbackslash defines an active \ to be a literal `\' character with -% catcode other. We switch back and forth between these. -@gdef@rawbackslash{@let\=@backslashcurfont} -@gdef@otherbackslash{@let\=@realbackslash} - -% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of -% the literal character `\'. -% -@def@normalturnoffactive{% +% \normalbackslash outputs one backslash in fixed width font. +\def\normalbackslash{{\tt\backslashcurfont}} + +\catcode`\\=\active + +% Used sometimes to turn off (effectively) the active characters +% even after parsing them. +@def@turnoffactive{% @let"=@normaldoublequote - @let$=@normaldollar %$ font-lock fix - @let+=@normalplus - @let<=@normalless - @let>=@normalgreater - @let\=@normalbackslash + @let\=@realbackslash + @let~=@normaltilde @let^=@normalcaret @let_=@normalunderscore @let|=@normalverticalbar - @let~=@normaltilde - @markupsetuplqdefault - @markupsetuprqdefault + @let<=@normalless + @let>=@normalgreater + @let+=@normalplus + @let$=@normaldollar %$ font-lock fix @unsepspaces } +% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of +% the literal character `\'. (Thus, \ is not expandable when this is in +% effect.) +% +@def@normalturnoffactive{@turnoffactive @let\=@normalbackslash} + % Make _ and + \other characters, temporarily. % This is canceled by @fixbackslash. @otherifyactive @@ -9961,7 +7175,7 @@ @global@let\ = @eatinput % On the other hand, perhaps the file did not have a `\input texinfo'. Then -% the first `\' in the file would cause an error. This macro tries to fix +% the first `\{ in the file would cause an error. This macro tries to fix % that, assuming it is called before the first `\' could plausibly occur. % Also turn back on active characters that might appear in the input % file name, in case not using a pre-dumped format. @@ -9975,28 +7189,11 @@ % Say @foo, not \foo, in error messages. @escapechar = `@@ -% These (along with & and #) are made active for url-breaking, so need -% active definitions as the normal characters. -@def@normaldot{.} -@def@normalquest{?} -@def@normalslash{/} - % These look ok in all fonts, so just make them not special. -% @hashchar{} gets its own user-level command, because of #line. -@catcode`@& = @other @def@normalamp{&} -@catcode`@# = @other @def@normalhash{#} -@catcode`@% = @other @def@normalpercent{%} - -@let @hashchar = @normalhash - -@c Finally, make ` and ' active, so that txicodequoteundirected and -@c txicodequotebacktick work right in, e.g., @w{@code{`foo'}}. If we -@c don't make ` and ' active, @code will not get them as active chars. -@c Do this last of all since we use ` in the previous @catcode assignments. -@catcode`@'=@active -@catcode`@`=@active -@markupsetuplqdefault -@markupsetuprqdefault +@catcode`@& = @other +@catcode`@# = @other +@catcode`@% = @other + @c Local variables: @c eval: (add-hook 'write-file-hooks 'time-stamp) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi_osx/ffi.c --- a/Modules/_ctypes/libffi_osx/ffi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi_osx/ffi.c Fri Feb 01 23:12:09 2013 +0100 @@ -38,13 +38,12 @@ /*@out@*/ ffi_type* arg) { /*@-usedef@*/ - ffi_type** ptr; if (arg == NULL || arg->elements == NULL || arg->size != 0 || arg->alignment != 0) return FFI_BAD_TYPEDEF; - ptr = &(arg->elements[0]); + ffi_type** ptr = &(arg->elements[0]); while ((*ptr) != NULL) { @@ -136,16 +135,16 @@ /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type* rtype, /*@dependent@*/ ffi_type** atypes) { - unsigned int bytes = 0; - unsigned int i; - ffi_type** ptr; - if (cif == NULL) return FFI_BAD_TYPEDEF; if (abi <= FFI_FIRST_ABI || abi > FFI_DEFAULT_ABI) return FFI_BAD_ABI; + unsigned int bytes = 0; + unsigned int i; + ffi_type** ptr; + cif->abi = abi; cif->arg_types = atypes; cif->nargs = nargs; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ctypes/libffi_osx/x86/x86-ffi64.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c Fri Feb 01 23:12:09 2013 +0100 @@ -225,16 +225,14 @@ /* Merge the fields of structure. */ for (ptr = type->elements; *ptr != NULL; ptr++) { - int num, pos; - byte_offset = ALIGN(byte_offset, (*ptr)->alignment); - num = classify_argument(*ptr, subclasses, byte_offset % 8); + int num = classify_argument(*ptr, subclasses, byte_offset % 8); if (num == 0) return 0; - pos = byte_offset / 8; + int pos = byte_offset / 8; for (i = 0; i < num; i++) { @@ -591,12 +589,11 @@ void (*fun)(ffi_cif*, void*, void**, void*), void* user_data) { - volatile unsigned short* tramp; - if (cif->abi != FFI_UNIX64) return FFI_BAD_ABI; - tramp = (volatile unsigned short*)&closure->tramp[0]; + volatile unsigned short* tramp = + (volatile unsigned short*)&closure->tramp[0]; tramp[0] = 0xbb49; /* mov , %r11 */ *(void* volatile*)&tramp[1] = ffi_closure_unix64; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_curses_panel.c --- a/Modules/_curses_panel.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_curses_panel.c Fri Feb 01 23:12:09 2013 +0100 @@ -117,7 +117,7 @@ { list_of_panels *new; - if ((new = (list_of_panels *)PyMem_Malloc(sizeof(list_of_panels))) == NULL) { + if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) { PyErr_NoMemory(); return -1; } @@ -136,7 +136,7 @@ temp = lop; if (temp->po == po) { lop = temp->next; - PyMem_Free(temp); + free(temp); return; } while (temp->next == NULL || temp->next->po != po) { @@ -148,7 +148,7 @@ temp = temp->next; } n = temp->next->next; - PyMem_Free(temp->next); + free(temp->next); temp->next = n; return; } @@ -322,18 +322,9 @@ static PyObject * PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) { - PyObject *oldobj; - int rc; - PyCursesInitialised; Py_INCREF(obj); - oldobj = (PyObject *) panel_userptr(self->pan); - rc = set_panel_userptr(self->pan, (void*)obj); - if (rc == ERR) { - /* In case of an ncurses error, decref the new object again */ - Py_DECREF(obj); - } - Py_XDECREF(oldobj); - return PyCursesCheckERR(rc, "set_panel_userptr"); + return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj), + "set_panel_userptr"); } static PyObject * @@ -513,8 +504,6 @@ goto fail; import_curses(); - if (PyErr_Occurred()) - goto fail; /* For exception _curses_panel.error */ _curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_cursesmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -168,6 +168,10 @@ "must call start_color() first"); \ return 0; } +#ifndef MIN +#define MIN(x,y) ((x) < (y) ? (x) : (y)) +#endif + /* Utility Functions */ /* @@ -529,7 +533,7 @@ wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); if (wo == NULL) return NULL; wo->win = win; - wo->encoding = _PyMem_Strdup(encoding); + wo->encoding = strdup(encoding); if (wo->encoding == NULL) { Py_DECREF(wo); PyErr_NoMemory(); @@ -543,7 +547,7 @@ { if (wo->win != stdscr) delwin(wo->win); if (wo->encoding != NULL) - PyMem_Free(wo->encoding); + free(wo->encoding); PyObject_DEL(wo); } @@ -1134,9 +1138,7 @@ } if (rtn == ERR) { /* getch() returns ERR in nodelay mode */ - PyErr_CheckSignals(); - if (!PyErr_Occurred()) - PyErr_SetString(PyCursesError, "no input"); + PyErr_SetString(PyCursesError, "no input"); return NULL; } else if (rtn<=255) { return Py_BuildValue("C", rtn); @@ -1177,9 +1179,6 @@ return NULL; } if (ct == ERR) { - if (PyErr_CheckSignals()) - return NULL; - /* get_wch() returns ERR in nodelay mode */ PyErr_SetString(PyCursesError, "no input"); return NULL; @@ -1208,7 +1207,7 @@ if (!PyArg_ParseTuple(args,"i;n", &n)) return NULL; Py_BEGIN_ALLOW_THREADS - rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023)); + rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023)); Py_END_ALLOW_THREADS break; case 2: @@ -1228,11 +1227,11 @@ #ifdef STRICT_SYSV_CURSES Py_BEGIN_ALLOW_THREADS rtn2 = wmove(self->win,y,x)==ERR ? ERR : - wgetnstr(self->win, rtn, Py_MIN(n, 1023)); + wgetnstr(self->win, rtn, MIN(n, 1023)); Py_END_ALLOW_THREADS #else Py_BEGIN_ALLOW_THREADS - rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023)); + rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023)); Py_END_ALLOW_THREADS #endif break; @@ -1370,7 +1369,7 @@ case 1: if (!PyArg_ParseTuple(args,"i;n", &n)) return NULL; - rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023)); + rtn2 = winnstr(self->win,rtn,MIN(n,1023)); break; case 2: if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) @@ -1380,7 +1379,7 @@ case 3: if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n)) return NULL; - rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023)); + rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023)); break; default: PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); @@ -1702,6 +1701,7 @@ fd = mkstemp(fn); if (fd < 0) return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); + _Py_try_set_cloexec(fd, 1); fp = fdopen(fd, "wb+"); if (fp == NULL) { close(fd); @@ -1938,13 +1938,13 @@ ascii = PyUnicode_AsASCIIString(value); if (ascii == NULL) return -1; - encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii)); + encoding = strdup(PyBytes_AS_STRING(ascii)); Py_DECREF(ascii); if (encoding == NULL) { PyErr_NoMemory(); return -1; } - PyMem_Free(self->encoding); + free(self->encoding); self->encoding = encoding; return 0; } @@ -2257,14 +2257,15 @@ PyObject *data; size_t datalen; WINDOW *win; + + PyCursesInitialised; _Py_IDENTIFIER(read); - PyCursesInitialised; - strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); fd = mkstemp(fn); if (fd < 0) return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); + _Py_try_set_cloexec(fd, 1); fp = fdopen(fd, "wb+"); if (fp == NULL) { close(fd); @@ -2926,13 +2927,9 @@ if (code != ERR) { initialisedcolors = TRUE; c = PyLong_FromLong((long) COLORS); - if (c == NULL) - return NULL; PyDict_SetItemString(ModDict, "COLORS", c); Py_DECREF(c); cp = PyLong_FromLong((long) COLOR_PAIRS); - if (cp == NULL) - return NULL; PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); Py_DECREF(cp); Py_INCREF(Py_None); @@ -3410,7 +3407,7 @@ continue; if (strncmp(key_n,"KEY_F(",6)==0) { char *p1, *p2; - key_n2 = PyMem_Malloc(strlen(key_n)+1); + key_n2 = malloc(strlen(key_n)+1); if (!key_n2) { PyErr_NoMemory(); break; @@ -3429,7 +3426,7 @@ key_n2 = key_n; SetDictInt(key_n2,key); if (key_n2 != key_n) - PyMem_Free(key_n2); + free(key_n2); } #endif SetDictInt("KEY_MIN", KEY_MIN); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_datetimemodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -3598,7 +3598,7 @@ { char buf[100]; PyObject *result; - int us = TIME_GET_MICROSECOND(self); + int us = TIME_GET_MICROSECOND(self);; if (us) result = PyUnicode_FromFormat("%02d:%02d:%02d.%06d", @@ -4749,7 +4749,7 @@ goto error; } result = new_timezone(delta, nameo); - Py_XDECREF(nameo); + Py_DECREF(nameo); error: Py_DECREF(delta); return result; @@ -4873,16 +4873,9 @@ time.tm_wday = -1; time.tm_isdst = -1; timestamp = mktime(&time); - if (timestamp == (time_t)(-1) -#ifndef _AIX - /* Return value of -1 does not necessarily mean an error, - * but tm_wday cannot remain set to -1 if mktime succeeded. */ - && time.tm_wday == -1 -#else - /* on AIX, tm_wday is always sets, even on error */ -#endif - ) - { + /* Return value of -1 does not necessarily mean an error, but tm_wday + * cannot remain set to -1 if mktime succeeded. */ + if (timestamp == (time_t)(-1) && time.tm_wday == -1) { PyErr_SetString(PyExc_OverflowError, "timestamp out of range"); return NULL; @@ -5306,8 +5299,8 @@ return NULL; /* module initialization */ - PyModule_AddIntMacro(m, MINYEAR); - PyModule_AddIntMacro(m, MAXYEAR); + PyModule_AddIntConstant(m, "MINYEAR", MINYEAR); + PyModule_AddIntConstant(m, "MAXYEAR", MAXYEAR); Py_INCREF(&PyDateTime_DateType); PyModule_AddObject(m, "date", (PyObject *) &PyDateTime_DateType); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_decimal/_decimal.c Fri Feb 01 23:12:09 2013 +0100 @@ -3096,29 +3096,6 @@ return res; } -/* Return a duplicate of src, copy embedded null characters. */ -static char * -dec_strdup(const char *src, Py_ssize_t size) -{ - char *dest = PyMem_Malloc(size+1); - if (dest == NULL) { - return NULL; - } - - memcpy(dest, src, size); - dest[size] = '\0'; - return dest; -} - -static void -dec_replace_fillchar(char *dest) -{ - while (*dest != '\0') { - if (*dest == '\xff') *dest = '\0'; - dest++; - } -} - /* Convert decimal_point or thousands_sep, which may be multibyte or in the range [128, 255], to a UTF8 string. */ static PyObject * @@ -3154,14 +3131,13 @@ PyObject *dot = NULL; PyObject *sep = NULL; PyObject *grouping = NULL; + PyObject *fmt = NULL; PyObject *fmtarg; PyObject *context; mpd_spec_t spec; - char *fmt; - char *decstring = NULL; + char *decstring= NULL; uint32_t status = 0; - int replace_fillchar = 0; - Py_ssize_t size; + size_t n; CURRENT_CONTEXT(context); @@ -3170,20 +3146,10 @@ } if (PyUnicode_Check(fmtarg)) { - fmt = PyUnicode_AsUTF8AndSize(fmtarg, &size); + fmt = PyUnicode_AsUTF8String(fmtarg); if (fmt == NULL) { return NULL; } - if (size > 0 && fmt[0] == '\0') { - /* NUL fill character: must be replaced with a valid UTF-8 char - before calling mpd_parse_fmt_str(). */ - replace_fillchar = 1; - fmt = dec_strdup(fmt, size); - if (fmt == NULL) { - return NULL; - } - fmt[0] = '_'; - } } else { PyErr_SetString(PyExc_TypeError, @@ -3191,19 +3157,12 @@ return NULL; } - if (!mpd_parse_fmt_str(&spec, fmt, CtxCaps(context))) { + if (!mpd_parse_fmt_str(&spec, PyBytes_AS_STRING(fmt), + CtxCaps(context))) { PyErr_SetString(PyExc_ValueError, "invalid format string"); goto finish; } - if (replace_fillchar) { - /* In order to avoid clobbering parts of UTF-8 thousands separators or - decimal points when the substitution is reversed later, the actual - placeholder must be an invalid UTF-8 byte. */ - spec.fill[0] = '\xff'; - spec.fill[1] = '\0'; - } - if (override) { /* Values for decimal_point, thousands_sep and grouping can be explicitly specified in the override dict. These values @@ -3240,7 +3199,7 @@ } } else { - size_t n = strlen(spec.dot); + n = strlen(spec.dot); if (n > 1 || (n == 1 && !isascii((uchar)spec.dot[0]))) { /* fix locale dependent non-ascii characters */ dot = dotsep_as_utf8(spec.dot); @@ -3263,28 +3222,17 @@ decstring = mpd_qformat_spec(MPD(dec), &spec, CTX(context), &status); if (decstring == NULL) { - if (status & MPD_Malloc_error) { - PyErr_NoMemory(); - } - else { - PyErr_SetString(PyExc_ValueError, - "format specification exceeds internal limits of _decimal"); - } + dec_addstatus(context, status); goto finish; } - size = strlen(decstring); - if (replace_fillchar) { - dec_replace_fillchar(decstring); - } - - result = PyUnicode_DecodeUTF8(decstring, size, NULL); + result = PyUnicode_DecodeUTF8(decstring, strlen(decstring), NULL); finish: Py_XDECREF(grouping); Py_XDECREF(sep); Py_XDECREF(dot); - if (replace_fillchar) PyMem_Free(fmt); + Py_XDECREF(fmt); if (decstring) mpd_free(decstring); return result; } @@ -4469,10 +4417,10 @@ goto malloc_error; } else { - PyErr_SetString(PyExc_RuntimeError, /* GCOV_NOT_REACHED */ - "dec_hash: internal error: please report"); /* GCOV_NOT_REACHED */ + PyErr_SetString(PyExc_RuntimeError, + "dec_hash: internal error: please report"); } - result = -1; /* GCOV_NOT_REACHED */ + result = -1; } @@ -5623,7 +5571,7 @@ } if (base == NULL) { - goto error; /* GCOV_NOT_REACHED */ + goto error; } ASSIGN_PTR(cm->ex, PyErr_NewException((char *)cm->fqname, base, NULL)); @@ -5655,7 +5603,7 @@ base = PyTuple_Pack(1, signal_map[0].ex); } if (base == NULL) { - goto error; /* GCOV_NOT_REACHED */ + goto error; } ASSIGN_PTR(cm->ex, PyErr_NewException((char *)cm->fqname, base, NULL)); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_decimal/libmpdec/mpdecimal.c --- a/Modules/_decimal/libmpdec/mpdecimal.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_decimal/libmpdec/mpdecimal.c Fri Feb 01 23:12:09 2013 +0100 @@ -2084,7 +2084,7 @@ } /* - * Compare a and b, convert the usual integer result to a decimal and + * Compare a and b, convert the the usual integer result to a decimal and * store it in 'result'. For convenience, the integer result of the comparison * is returned. Comparisons involving NaNs return NaN/INT_MAX. */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_decimal/tests/deccheck.py --- a/Modules/_decimal/tests/deccheck.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_decimal/tests/deccheck.py Fri Feb 01 23:12:09 2013 +0100 @@ -891,7 +891,7 @@ def test_format(method, prec, exp_range, restricted_range, itr, stat): """Iterate the __format__ method through many test cases.""" for op in all_unary(prec, exp_range, itr): - fmt1 = rand_format(chr(random.randrange(0, 128)), 'EeGgn') + fmt1 = rand_format(chr(random.randrange(32, 128)), 'EeGgn') fmt2 = rand_locale() for fmt in (fmt1, fmt2): fmtop = (op[0], fmt) @@ -904,7 +904,7 @@ except VerifyError as err: log(err) for op in all_unary(prec, 9999, itr): - fmt1 = rand_format(chr(random.randrange(0, 128)), 'Ff%') + fmt1 = rand_format(chr(random.randrange(32, 128)), 'Ff%') fmt2 = rand_locale() for fmt in (fmt1, fmt2): fmtop = (op[0], fmt) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_decimal/tests/formathelper.py --- a/Modules/_decimal/tests/formathelper.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_decimal/tests/formathelper.py Fri Feb 01 23:12:09 2013 +0100 @@ -215,6 +215,8 @@ c = chr(i) c.encode('utf-8').decode() format(P.Decimal(0), c + '<19g') + if c in ("'", '"', '\\'): + return None return c except: return None @@ -222,14 +224,14 @@ # Generate all unicode characters that are accepted as # fill characters by decimal.py. def all_fillchars(): - for i in range(0, 0x110002): + for i in range(32, 0x110002): c = check_fillchar(i) if c: yield c # Return random fill character. def rand_fillchar(): while 1: - i = random.randrange(0, 0x110002) + i = random.randrange(32, 0x110002) c = check_fillchar(i) if c: return c diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_decimal/tests/runall-memorydebugger.sh --- a/Modules/_decimal/tests/runall-memorydebugger.sh Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_decimal/tests/runall-memorydebugger.sh Fri Feb 01 23:12:09 2013 +0100 @@ -9,9 +9,8 @@ # Requirements: valgrind # -# Set additional CFLAGS and LDFLAGS for ./configure +# Set additional CFLAGS for ./configure ADD_CFLAGS= -ADD_LDFLAGS= CONFIGS_64="x64 uint128 ansi64 universal" @@ -75,7 +74,7 @@ cd ../../ $GMAKE distclean > /dev/null 2>&1 - ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" --with-pydebug $args > /dev/null 2>&1 + ./configure CFLAGS="$ADD_CFLAGS" --with-pydebug $args > /dev/null 2>&1 $GMAKE | grep _decimal printf "\n\n# ======================== refleak tests ===========================\n\n" @@ -87,7 +86,7 @@ printf "\nbuilding python ...\n\n" $GMAKE distclean > /dev/null 2>&1 - ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" $args > /dev/null 2>&1 + ./configure CFLAGS="$ADD_CFLAGS" $args > /dev/null 2>&1 $GMAKE | grep _decimal printf "\n\n# ======================== regular tests ===========================\n\n" @@ -107,7 +106,7 @@ print_config "valgrind tests: config=$config" $args printf "\nbuilding python ...\n\n" $GMAKE distclean > /dev/null 2>&1 - ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" --without-pymalloc $args > /dev/null 2>&1 + ./configure CFLAGS="$ADD_CFLAGS" --without-pymalloc $args > /dev/null 2>&1 $GMAKE | grep _decimal printf "\n\n# ======================== valgrind tests ===========================\n\n" @@ -133,7 +132,7 @@ printf "\nbuilding python ...\n\n" $GMAKE distclean > /dev/null 2>&1 - ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" --with-pydebug $args > /dev/null 2>&1 + ./configure CFLAGS="$ADD_CFLAGS" --with-pydebug $args > /dev/null 2>&1 $GMAKE | grep _decimal printf "\n\n# ========================== debug ===========================\n\n" @@ -144,7 +143,7 @@ printf "\nbuilding python ...\n\n" $GMAKE distclean > /dev/null 2>&1 - ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" $args > /dev/null 2>&1 + ./configure CFLAGS="$ADD_CFLAGS" $args > /dev/null 2>&1 $GMAKE | grep _decimal printf "\n\n# ======================== regular ===========================\n\n" @@ -164,7 +163,7 @@ printf "\nbuilding python ...\n\n" $GMAKE distclean > /dev/null 2>&1 - ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" --without-pymalloc $args > /dev/null 2>&1 + ./configure CFLAGS="$ADD_CFLAGS" --without-pymalloc $args > /dev/null 2>&1 $GMAKE | grep _decimal printf "\n\n# ======================== valgrind ==========================\n\n" diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_elementtree.c --- a/Modules/_elementtree.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_elementtree.c Fri Feb 01 23:12:09 2013 +0100 @@ -1,22 +1,63 @@ -/*-------------------------------------------------------------------- - * Licensed to PSF under a Contributor Agreement. - * See http://www.python.org/psf/license for licensing details. +/* + * ElementTree + * $Id: _elementtree.c 3473 2009-01-11 22:53:55Z fredrik $ * - * _elementtree - C accelerator for xml.etree.ElementTree + * elementtree accelerator + * + * History: + * 1999-06-20 fl created (as part of sgmlop) + * 2001-05-29 fl effdom edition + * 2003-02-27 fl elementtree edition (alpha) + * 2004-06-03 fl updates for elementtree 1.2 + * 2005-01-05 fl major optimization effort + * 2005-01-11 fl first public release (cElementTree 0.8) + * 2005-01-12 fl split element object into base and extras + * 2005-01-13 fl use tagged pointers for tail/text (cElementTree 0.9) + * 2005-01-17 fl added treebuilder close method + * 2005-01-17 fl fixed crash in getchildren + * 2005-01-18 fl removed observer api, added iterparse (cElementTree 0.9.3) + * 2005-01-23 fl revised iterparse api; added namespace event support (0.9.8) + * 2005-01-26 fl added VERSION module property (cElementTree 1.0) + * 2005-01-28 fl added remove method (1.0.1) + * 2005-03-01 fl added iselement function; fixed makeelement aliasing (1.0.2) + * 2005-03-13 fl export Comment and ProcessingInstruction/PI helpers + * 2005-03-26 fl added Comment and PI support to XMLParser + * 2005-03-27 fl event optimizations; complain about bogus events + * 2005-08-08 fl fixed read error handling in parse + * 2005-08-11 fl added runtime test for copy workaround (1.0.3) + * 2005-12-13 fl added expat_capi support (for xml.etree) (1.0.4) + * 2005-12-16 fl added support for non-standard encodings + * 2006-03-08 fl fixed a couple of potential null-refs and leaks + * 2006-03-12 fl merge in 2.5 ssize_t changes + * 2007-08-25 fl call custom builder's close method from XMLParser + * 2007-08-31 fl added iter, extend from ET 1.3 + * 2007-09-01 fl fixed ParseError exception, setslice source type, etc + * 2007-09-03 fl fixed handling of negative insert indexes + * 2007-09-04 fl added itertext from ET 1.3 + * 2007-09-06 fl added position attribute to ParseError exception + * 2008-06-06 fl delay error reporting in iterparse (from Hrvoje Niksic) + * * Copyright (c) 1999-2009 by Secret Labs AB. All rights reserved. * Copyright (c) 1999-2009 by Fredrik Lundh. * * info@pythonware.com * http://www.pythonware.com - *-------------------------------------------------------------------- */ +/* Licensed to PSF under a Contributor Agreement. */ +/* See http://www.python.org/psf/license for licensing details. */ + #include "Python.h" #include "structmember.h" +#define VERSION "1.0.6" + /* -------------------------------------------------------------------- */ /* configuration */ +/* Leave defined to include the expat-based XMLParser type */ +#define USE_EXPAT + /* An element can hold this many children without extra memory allocations. */ #define STATIC_CHILDREN 4 @@ -59,13 +100,6 @@ #define JOIN_SET(p, flag) ((void*) ((Py_uintptr_t) (JOIN_OBJ(p)) | (flag))) #define JOIN_OBJ(p) ((PyObject*) ((Py_uintptr_t) (p) & ~(Py_uintptr_t)1)) -/* Types defined by this extension */ -static PyTypeObject Element_Type; -static PyTypeObject ElementIter_Type; -static PyTypeObject TreeBuilder_Type; -static PyTypeObject XMLParser_Type; - - /* glue functions (see the init function for details) */ static PyObject* elementtree_parseerror_obj; static PyObject* elementtree_deepcopy_obj; @@ -166,6 +200,7 @@ } ElementObject; +static PyTypeObject Element_Type; #define Element_CheckExact(op) (Py_TYPE(op) == &Element_Type) @@ -176,10 +211,8 @@ create_extra(ElementObject* self, PyObject* attrib) { self->extra = PyObject_Malloc(sizeof(ElementObjectExtra)); - if (!self->extra) { - PyErr_NoMemory(); + if (!self->extra) return -1; - } if (!attrib) attrib = Py_None; @@ -232,27 +265,26 @@ return NULL; self->extra = NULL; - Py_INCREF(tag); - self->tag = tag; - - Py_INCREF(Py_None); - self->text = Py_None; - - Py_INCREF(Py_None); - self->tail = Py_None; - - self->weakreflist = NULL; - - ALLOC(sizeof(ElementObject), "create element"); - PyObject_GC_Track(self); - if (attrib != Py_None && !is_empty_dict(attrib)) { if (create_extra(self, attrib) < 0) { - Py_DECREF(self); + PyObject_Del(self); return NULL; } } + Py_INCREF(tag); + self->tag = tag; + + Py_INCREF(Py_None); + self->text = Py_None; + + Py_INCREF(Py_None); + self->tail = Py_None; + + self->weakreflist = NULL; + + ALLOC(sizeof(ElementObject), "create element"); + PyObject_GC_Track(self); return (PyObject*) self; } @@ -280,9 +312,7 @@ * This is required by some constructors/functions in this module that can * either accept attrib as a keyword argument or all attributes splashed * directly into *kwds. - * - * Return a dictionary with the content of kwds merged into the content of - * attrib. If there is no attrib keyword, return a copy of kwds. + * If there is no 'attrib' keyword, return an empty dict. */ static PyObject* get_attrib_from_keywords(PyObject *kwds) @@ -308,10 +338,8 @@ Py_DECREF(attrib_str); - /* attrib can be NULL if PyDict_New failed */ if (attrib) - if (PyDict_Update(attrib, kwds) < 0) - return NULL; + PyDict_Update(attrib, kwds); return attrib; } @@ -384,10 +412,8 @@ /* make sure self->children can hold the given number of extra elements. set an exception and return -1 if allocation failed */ - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return -1; - } + if (!self->extra) + create_extra(self, NULL); size = self->extra->length + extra; @@ -539,9 +565,8 @@ } elem = create_new_element(tag, attrib); + Py_DECREF(attrib); - if (elem == NULL) - return NULL; if (element_add_subelement(parent, elem) < 0) { Py_DECREF(elem); @@ -1280,10 +1305,8 @@ &Element_Type, &element)) return NULL; - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return NULL; - } + if (!self->extra) + create_extra(self, NULL); if (index < 0) { index += self->extra->length; @@ -1424,10 +1447,8 @@ if (!PyArg_ParseTuple(args, "OO:set", &key, &value)) return NULL; - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return NULL; - } + if (!self->extra) + create_extra(self, NULL); attrib = element_get_attrib(self); if (!attrib) @@ -1542,10 +1563,8 @@ PyObject* recycle = NULL; PyObject* seq = NULL; - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return -1; - } + if (!self->extra) + create_extra(self, NULL); if (PySlice_GetIndicesEx(item, self->extra->length, @@ -1760,7 +1779,7 @@ return res; } else if (strcmp(name, "text") == 0) { res = element_get_text(self); - Py_XINCREF(res); + Py_INCREF(res); return res; } @@ -1775,10 +1794,8 @@ res = element_get_tail(self); } else if (strcmp(name, "attrib") == 0) { PyErr_Clear(); - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return NULL; - } + if (!self->extra) + create_extra(self, NULL); res = element_get_attrib(self); } @@ -1789,14 +1806,15 @@ return res; } -static int +static PyObject* element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value) { char *name = ""; if (PyUnicode_Check(nameobj)) name = _PyUnicode_AsString(nameobj); + if (name == NULL) - return -1; + return NULL; if (strcmp(name, "tag") == 0) { Py_DECREF(self->tag); @@ -1811,20 +1829,17 @@ self->tail = value; Py_INCREF(self->tail); } else if (strcmp(name, "attrib") == 0) { - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return -1; - } + if (!self->extra) + create_extra(self, NULL); Py_DECREF(self->extra->attrib); self->extra->attrib = value; Py_INCREF(self->extra->attrib); } else { - PyErr_SetString(PyExc_AttributeError, - "Can't set arbitrary attributes on Element"); - return -1; + PyErr_SetString(PyExc_AttributeError, name); + return NULL; } - return 0; + return NULL; } static PySequenceMethods element_as_sequence = { @@ -2130,6 +2145,14 @@ it = PyObject_GC_New(ElementIterObject, &ElementIter_Type); if (!it) return NULL; + if (!(it->parent_stack = PyObject_Malloc(sizeof(ParentLocator)))) { + PyObject_GC_Del(it); + return NULL; + } + + it->parent_stack->parent = NULL; + it->parent_stack->child_index = 0; + it->parent_stack->next = NULL; if (PyUnicode_Check(tag)) star = PyUnicode_FromString("*"); @@ -2138,27 +2161,17 @@ if (star && PyObject_RichCompareBool(tag, star, Py_EQ) == 1) tag = Py_None; + Py_XDECREF(star); - - Py_INCREF(tag); it->sought_tag = tag; it->root_done = 0; it->gettext = gettext; + it->root_element = self; + Py_INCREF(self); - it->root_element = self; + Py_INCREF(tag); PyObject_GC_Track(it); - - it->parent_stack = PyObject_Malloc(sizeof(ParentLocator)); - if (it->parent_stack == NULL) { - Py_DECREF(it); - PyErr_NoMemory(); - return NULL; - } - it->parent_stack->parent = NULL; - it->parent_stack->child_index = 0; - it->parent_stack->next = NULL; - return (PyObject *)it; } @@ -2189,6 +2202,8 @@ PyObject *end_ns_event_obj; } TreeBuilderObject; +static PyTypeObject TreeBuilder_Type; + #define TreeBuilder_CheckExact(op) (Py_TYPE(op) == &TreeBuilder_Type) /* -------------------------------------------------------------------- */ @@ -2364,7 +2379,7 @@ self->data = NULL; } - if (self->element_factory && self->element_factory != Py_None) { + if (self->element_factory) { node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib); } else { node = create_new_element(tag, attrib); @@ -2668,6 +2683,8 @@ /* ==================================================================== */ /* the expat interface */ +#if defined(USE_EXPAT) + #include "expat.h" #include "pyexpat.h" static struct PyExpat_CAPI *expat_capi; @@ -2698,6 +2715,8 @@ } XMLParserObject; +static PyTypeObject XMLParser_Type; + #define XMLParser_CheckExact(op) (Py_TYPE(op) == &XMLParser_Type) /* helpers */ @@ -2736,10 +2755,6 @@ if (i != size) { /* convert to universal name */ tag = PyBytes_FromStringAndSize(NULL, size+1); - if (tag == NULL) { - Py_DECREF(key); - return NULL; - } p = PyBytes_AS_STRING(tag); p[0] = '{'; memcpy(p+1, string, size); @@ -2834,9 +2849,6 @@ if (data_len < 2 || data_in[0] != '&') return; - if (PyErr_Occurred()) - return; - key = PyUnicode_DecodeUTF8(data_in + 1, data_len - 2, "strict"); if (!key) return; @@ -2877,9 +2889,6 @@ PyObject* attrib; int ok; - if (PyErr_Occurred()) - return; - /* tag name */ tag = makeuniversal(self, tag_in); if (!tag) @@ -2938,9 +2947,6 @@ PyObject* data; PyObject* res; - if (PyErr_Occurred()) - return; - data = PyUnicode_DecodeUTF8(data_in, data_len, "strict"); if (!data) return; /* parser will look for errors */ @@ -2964,9 +2970,6 @@ PyObject* tag; PyObject* res = NULL; - if (PyErr_Occurred()) - return; - if (TreeBuilder_CheckExact(self->target)) /* shortcut */ /* the standard tree builder doesn't look at the end tag */ @@ -2991,9 +2994,6 @@ PyObject* sprefix = NULL; PyObject* suri = NULL; - if (PyErr_Occurred()) - return; - suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict"); if (!suri) return; @@ -3018,9 +3018,6 @@ static void expat_end_ns_handler(XMLParserObject* self, const XML_Char* prefix_in) { - if (PyErr_Occurred()) - return; - treebuilder_handle_namespace( (TreeBuilderObject*) self->target, 0, NULL, NULL ); @@ -3032,9 +3029,6 @@ PyObject* comment; PyObject* res; - if (PyErr_Occurred()) - return; - if (self->handle_comment) { comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict"); if (comment) { @@ -3057,9 +3051,6 @@ PyObject *parser_doctype = NULL; PyObject *res = NULL; - if (PyErr_Occurred()) - return; - doctype_name_obj = makeuniversal(self, doctype_name); if (!doctype_name_obj) return; @@ -3128,9 +3119,6 @@ PyObject* data; PyObject* res; - if (PyErr_Occurred()) - return; - if (self->handle_pi) { target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict"); data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict"); @@ -3146,6 +3134,47 @@ } } +static int +expat_unknown_encoding_handler(XMLParserObject *self, const XML_Char *name, + XML_Encoding *info) +{ + PyObject* u; + unsigned char s[256]; + int i; + void *data; + unsigned int kind; + + memset(info, 0, sizeof(XML_Encoding)); + + for (i = 0; i < 256; i++) + s[i] = i; + + u = PyUnicode_Decode((char*) s, 256, name, "replace"); + if (!u) + return XML_STATUS_ERROR; + if (PyUnicode_READY(u)) + return XML_STATUS_ERROR; + + if (PyUnicode_GET_LENGTH(u) != 256) { + Py_DECREF(u); + return XML_STATUS_ERROR; + } + + kind = PyUnicode_KIND(u); + data = PyUnicode_DATA(u); + for (i = 0; i < 256; i++) { + Py_UCS4 ch = PyUnicode_READ(kind, data, i); + if (ch != Py_UNICODE_REPLACEMENT_CHARACTER) + info->map[i] = ch; + else + info->map[i] = -1; + } + + Py_DECREF(u); + + return XML_STATUS_OK; +} + /* -------------------------------------------------------------------- */ static PyObject * @@ -3247,7 +3276,7 @@ ); EXPAT(SetUnknownEncodingHandler)( self_xp->parser, - EXPAT(DefaultUnknownEncodingHandler), NULL + (XML_UnknownEncodingHandler) expat_unknown_encoding_handler, NULL ); return 0; @@ -3299,11 +3328,10 @@ } LOCAL(PyObject*) -expat_parse(XMLParserObject* self, const char* data, int data_len, int final) +expat_parse(XMLParserObject* self, char* data, int data_len, int final) { int ok; - assert(!PyErr_Occurred()); ok = EXPAT(Parse)(self->parser, data, data_len, final); if (PyErr_Occurred()) @@ -3346,43 +3374,23 @@ } static PyObject* -xmlparser_feed(XMLParserObject* self, PyObject* arg) +xmlparser_feed(XMLParserObject* self, PyObject* args) { /* feed data to parser */ - if (PyUnicode_Check(arg)) { - Py_ssize_t data_len; - const char *data = PyUnicode_AsUTF8AndSize(arg, &data_len); - if (data == NULL) - return NULL; - if (data_len > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "size does not fit in an int"); - return NULL; - } - /* Explicitly set UTF-8 encoding. Return code ignored. */ - (void)EXPAT(SetEncoding)(self->parser, "utf-8"); - return expat_parse(self, data, (int)data_len, 0); - } - else { - Py_buffer view; - PyObject *res; - if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) < 0) - return NULL; - if (view.len > INT_MAX) { - PyBuffer_Release(&view); - PyErr_SetString(PyExc_OverflowError, "size does not fit in an int"); - return NULL; - } - res = expat_parse(self, view.buf, (int)view.len, 0); - PyBuffer_Release(&view); - return res; - } + char* data; + int data_len; + if (!PyArg_ParseTuple(args, "s#:feed", &data, &data_len)) + return NULL; + + return expat_parse(self, data, data_len, 0); } static PyObject* -xmlparser_parse_whole(XMLParserObject* self, PyObject* args) +xmlparser_parse(XMLParserObject* self, PyObject* args) { - /* (internal) parse the whole input, until end of stream */ + /* (internal) parse until end of input stream */ + PyObject* reader; PyObject* buffer; PyObject* temp; @@ -3463,14 +3471,14 @@ xmlparser_setevents(XMLParserObject *self, PyObject* args) { /* activate element event reporting */ - Py_ssize_t i, seqlen; - TreeBuilderObject *target; - - PyObject *events_queue; - PyObject *events_to_report = Py_None; - PyObject *events_seq; - if (!PyArg_ParseTuple(args, "O!|O:_setevents", &PyList_Type, &events_queue, - &events_to_report)) + + Py_ssize_t i; + TreeBuilderObject* target; + + PyObject* events; /* event collector */ + PyObject* event_set = Py_None; + if (!PyArg_ParseTuple(args, "O!|O:_setevents", &PyList_Type, &events, + &event_set)) return NULL; if (!TreeBuilder_CheckExact(self->target)) { @@ -3484,9 +3492,9 @@ target = (TreeBuilderObject*) self->target; - Py_INCREF(events_queue); + Py_INCREF(events); Py_XDECREF(target->events); - target->events = events_queue; + target->events = events; /* clear out existing events */ Py_CLEAR(target->start_event_obj); @@ -3494,71 +3502,75 @@ Py_CLEAR(target->start_ns_event_obj); Py_CLEAR(target->end_ns_event_obj); - if (events_to_report == Py_None) { + if (event_set == Py_None) { /* default is "end" only */ target->end_event_obj = PyUnicode_FromString("end"); Py_RETURN_NONE; } - if (!(events_seq = PySequence_Fast(events_to_report, - "events must be a sequence"))) { - return NULL; - } - - seqlen = PySequence_Size(events_seq); - for (i = 0; i < seqlen; ++i) { - PyObject *event_name_obj = PySequence_Fast_GET_ITEM(events_seq, i); - char *event_name = NULL; - if (PyUnicode_Check(event_name_obj)) { - event_name = _PyUnicode_AsString(event_name_obj); - } else if (PyBytes_Check(event_name_obj)) { - event_name = PyBytes_AS_STRING(event_name_obj); + if (!PyTuple_Check(event_set)) /* FIXME: handle arbitrary sequences */ + goto error; + + for (i = 0; i < PyTuple_GET_SIZE(event_set); i++) { + PyObject* item = PyTuple_GET_ITEM(event_set, i); + char* event; + if (PyUnicode_Check(item)) { + event = _PyUnicode_AsString(item); + if (event == NULL) + goto error; + } else if (PyBytes_Check(item)) + event = PyBytes_AS_STRING(item); + else { + goto error; } - - if (event_name == NULL) { - Py_DECREF(events_seq); - PyErr_Format(PyExc_ValueError, "invalid events sequence"); - return NULL; - } else if (strcmp(event_name, "start") == 0) { - Py_INCREF(event_name_obj); - target->start_event_obj = event_name_obj; - } else if (strcmp(event_name, "end") == 0) { - Py_INCREF(event_name_obj); + if (strcmp(event, "start") == 0) { + Py_INCREF(item); + target->start_event_obj = item; + } else if (strcmp(event, "end") == 0) { + Py_INCREF(item); Py_XDECREF(target->end_event_obj); - target->end_event_obj = event_name_obj; - } else if (strcmp(event_name, "start-ns") == 0) { - Py_INCREF(event_name_obj); + target->end_event_obj = item; + } else if (strcmp(event, "start-ns") == 0) { + Py_INCREF(item); Py_XDECREF(target->start_ns_event_obj); - target->start_ns_event_obj = event_name_obj; + target->start_ns_event_obj = item; EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, (XML_EndNamespaceDeclHandler) expat_end_ns_handler ); - } else if (strcmp(event_name, "end-ns") == 0) { - Py_INCREF(event_name_obj); + } else if (strcmp(event, "end-ns") == 0) { + Py_INCREF(item); Py_XDECREF(target->end_ns_event_obj); - target->end_ns_event_obj = event_name_obj; + target->end_ns_event_obj = item; EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, (XML_EndNamespaceDeclHandler) expat_end_ns_handler ); } else { - Py_DECREF(events_seq); - PyErr_Format(PyExc_ValueError, "unknown event '%s'", event_name); + PyErr_Format( + PyExc_ValueError, + "unknown event '%s'", event + ); return NULL; } } - Py_DECREF(events_seq); Py_RETURN_NONE; + + error: + PyErr_SetString( + PyExc_TypeError, + "invalid event tuple" + ); + return NULL; } static PyMethodDef xmlparser_methods[] = { - {"feed", (PyCFunction) xmlparser_feed, METH_O}, + {"feed", (PyCFunction) xmlparser_feed, METH_VARARGS}, {"close", (PyCFunction) xmlparser_close, METH_VARARGS}, - {"_parse_whole", (PyCFunction) xmlparser_parse_whole, METH_VARARGS}, + {"_parse", (PyCFunction) xmlparser_parse, METH_VARARGS}, {"_setevents", (PyCFunction) xmlparser_setevents, METH_VARARGS}, {"doctype", (PyCFunction) xmlparser_doctype, METH_VARARGS}, {NULL, NULL} @@ -3630,6 +3642,8 @@ 0, /* tp_free */ }; +#endif + /* ==================================================================== */ /* python module interface */ @@ -3657,14 +3671,14 @@ PyObject *m, *temp; /* Initialize object types */ - if (PyType_Ready(&ElementIter_Type) < 0) - return NULL; if (PyType_Ready(&TreeBuilder_Type) < 0) return NULL; if (PyType_Ready(&Element_Type) < 0) return NULL; +#if defined(USE_EXPAT) if (PyType_Ready(&XMLParser_Type) < 0) return NULL; +#endif m = PyModule_Create(&_elementtreemodule); if (!m) @@ -3707,8 +3721,10 @@ Py_INCREF((PyObject *)&TreeBuilder_Type); PyModule_AddObject(m, "TreeBuilder", (PyObject *)&TreeBuilder_Type); +#if defined(USE_EXPAT) Py_INCREF((PyObject *)&XMLParser_Type); PyModule_AddObject(m, "XMLParser", (PyObject *)&XMLParser_Type); +#endif return m; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_freeze_importlib.c --- a/Modules/_freeze_importlib.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_freeze_importlib.c Fri Feb 01 23:12:09 2013 +0100 @@ -17,7 +17,7 @@ of frozen modules instead, left deliberately blank so as to avoid unintentional import of a stale version of _frozen_importlib. */ -const static struct _frozen _PyImport_FrozenModules[] = { +static struct _frozen _PyImport_FrozenModules[] = { {0, 0, 0} /* sentinel */ }; @@ -25,7 +25,7 @@ /* On Windows, this links with the regular pythonXY.dll, so this variable comes from frozen.obj. In the Makefile, frozen.o is not linked into this executable, so we define the variable here. */ -const struct _frozen *PyImport_FrozenModules; +struct _frozen *PyImport_FrozenModules; #endif const char header[] = "/* Auto-generated by Modules/_freeze_importlib.c */"; @@ -34,12 +34,12 @@ main(int argc, char *argv[]) { char *inpath, *outpath; - FILE *infile = NULL, *outfile = NULL; + FILE *infile, *outfile = NULL; struct stat st; size_t text_size, data_size, n; - char *text = NULL; + char *text; unsigned char *data; - PyObject *code = NULL, *marshalled = NULL; + PyObject *code, *marshalled; PyImport_FrozenModules = _PyImport_FrozenModules; @@ -52,17 +52,19 @@ infile = fopen(inpath, "rb"); if (infile == NULL) { fprintf(stderr, "cannot open '%s' for reading\n", inpath); - goto error; + return 1; } if (fstat(fileno(infile), &st)) { + fclose(infile); fprintf(stderr, "cannot fstat '%s'\n", inpath); - goto error; + return 1; } text_size = st.st_size; text = (char *) malloc(text_size + 1); if (text == NULL) { + fclose(infile); fprintf(stderr, "could not allocate %ld bytes\n", (long) text_size); - goto error; + return 1; } n = fread(text, 1, text_size, infile); fclose(infile); @@ -70,7 +72,7 @@ if (n < text_size) { fprintf(stderr, "read too short: got %ld instead of %ld bytes\n", (long) n, (long) text_size); - goto error; + return 1; } text[text_size] = '\0'; @@ -86,11 +88,8 @@ Py_file_input, NULL, 0); if (code == NULL) goto error; - free(text); - text = NULL; - marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION); - Py_CLEAR(code); + Py_DECREF(code); if (marshalled == NULL) goto error; @@ -103,10 +102,10 @@ outfile = fopen(outpath, "w"); if (outfile == NULL) { fprintf(stderr, "cannot open '%s' for writing\n", outpath); - goto error; + return 1; } fprintf(outfile, "%s\n", header); - fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); + fprintf(outfile, "unsigned char _Py_M__importlib[] = {\n"); for (n = 0; n < data_size; n += 16) { size_t i, end = Py_MIN(n + 16, data_size); fprintf(outfile, " "); @@ -117,13 +116,16 @@ } fprintf(outfile, "};\n"); - Py_CLEAR(marshalled); + Py_DECREF(marshalled); Py_Finalize(); + if (infile) + fclose(infile); if (outfile) { if (ferror(outfile)) { fprintf(stderr, "error when writing to '%s'\n", outpath); - goto error; + fclose(outfile); + return 1; } fclose(outfile); } @@ -136,9 +138,5 @@ fclose(infile); if (outfile) fclose(outfile); - if (text) - free(text); - if (marshalled) - Py_DECREF(marshalled); return 1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_functoolsmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -218,10 +218,10 @@ } static PyObject * -partial_setstate(partialobject *pto, PyObject *state) +partial_setstate(partialobject *pto, PyObject *args) { PyObject *fn, *fnargs, *kw, *dict; - if (!PyArg_ParseTuple(state, "OOOO", + if (!PyArg_ParseTuple(args, "(OOOO):__setstate__", &fn, &fnargs, &kw, &dict)) return NULL; Py_XDECREF(pto->fn); @@ -245,7 +245,7 @@ static PyMethodDef partial_methods[] = { {"__reduce__", (PyCFunction)partial_reduce, METH_NOARGS}, - {"__setstate__", (PyCFunction)partial_setstate, METH_O}, + {"__setstate__", (PyCFunction)partial_setstate, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_gestalt.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/_gestalt.c Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,84 @@ +/*********************************************************** +Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, +The Netherlands. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Stichting Mathematisch +Centrum or CWI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior permission. + +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + +/* Macintosh Gestalt interface */ + +#include "Python.h" + +#include + +/* Convert a 4-char string object argument to an OSType value */ +static int +convert_to_OSType(PyObject *v, OSType *pr) +{ + uint32_t tmp; + if (!PyUnicode_Check(v) || PyUnicode_GetLength(v) != 4) { + PyErr_SetString(PyExc_TypeError, + "OSType arg must be string of 4 chars"); + return 0; + } + memcpy((char *)&tmp, _PyUnicode_AsString(v), 4); + *pr = (OSType)ntohl(tmp); + return 1; +} + +static PyObject * +gestalt_gestalt(PyObject *self, PyObject *args) +{ + OSErr iErr; + OSType selector; + SInt32 response; + if (!PyArg_ParseTuple(args, "O&", convert_to_OSType, &selector)) + return NULL; + iErr = Gestalt(selector, &response); + if (iErr != 0) { + PyErr_SetString(PyExc_OSError, + "non-zero exit code!"); + return NULL; + } + return PyLong_FromLong(response); +} + +static struct PyMethodDef gestalt_methods[] = { + {"gestalt", gestalt_gestalt, METH_VARARGS}, + {NULL, NULL} /* Sentinel */ +}; + +static struct PyModuleDef gestaltmodule = { + PyModuleDef_HEAD_INIT, + "_gestalt", + NULL, + -1, + gestalt_methods, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC +PyInit__gestalt(void) +{ + return PyModule_Create(&gestaltmodule); +} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_hashopenssl.c --- a/Modules/_hashopenssl.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_hashopenssl.c Fri Feb 01 23:12:09 2013 +0100 @@ -48,7 +48,7 @@ #define DEFINE_CONSTS_FOR_NEW(Name) \ - static PyObject *CONST_ ## Name ## _name_obj = NULL; \ + static PyObject *CONST_ ## Name ## _name_obj; \ static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \ static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p = NULL; @@ -563,15 +563,12 @@ " hash object; optionally initialized with a string") \ } -/* used in the init function to setup a constructor: initialize OpenSSL - constructor constants if they haven't been initialized already. */ +/* used in the init function to setup a constructor */ #define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \ - if (CONST_ ## NAME ## _name_obj == NULL) { \ - CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \ - if (EVP_get_digestbyname(#NAME)) { \ - CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \ - EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \ - } \ + CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \ + if (EVP_get_digestbyname(#NAME)) { \ + CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \ + EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \ } \ } while (0); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_heapqmodule.c --- a/Modules/_heapqmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_heapqmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -11,14 +11,12 @@ static int _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos) { - PyObject *newitem, *parent, *olditem; + PyObject *newitem, *parent; int cmp; Py_ssize_t parentpos; - Py_ssize_t size; assert(PyList_Check(heap)); - size = PyList_GET_SIZE(heap); - if (pos >= size) { + if (pos >= PyList_GET_SIZE(heap)) { PyErr_SetString(PyExc_IndexError, "index out of range"); return -1; } @@ -35,24 +33,12 @@ Py_DECREF(newitem); return -1; } - if (size != PyList_GET_SIZE(heap)) { - Py_DECREF(newitem); - PyErr_SetString(PyExc_RuntimeError, - "list changed size during iteration"); - return -1; - } if (cmp == 0) break; Py_INCREF(parent); - olditem = PyList_GET_ITEM(heap, pos); + Py_DECREF(PyList_GET_ITEM(heap, pos)); PyList_SET_ITEM(heap, pos, parent); - Py_DECREF(olditem); pos = parentpos; - if (size != PyList_GET_SIZE(heap)) { - PyErr_SetString(PyExc_RuntimeError, - "list changed size during iteration"); - return -1; - } } Py_DECREF(PyList_GET_ITEM(heap, pos)); PyList_SET_ITEM(heap, pos, newitem); @@ -64,12 +50,10 @@ { Py_ssize_t startpos, endpos, childpos, rightpos; int cmp; - PyObject *newitem, *tmp, *olditem; - Py_ssize_t size; + PyObject *newitem, *tmp; assert(PyList_Check(heap)); - size = PyList_GET_SIZE(heap); - endpos = size; + endpos = PyList_GET_SIZE(heap); startpos = pos; if (pos >= endpos) { PyErr_SetString(PyExc_IndexError, "index out of range"); @@ -95,28 +79,16 @@ if (cmp == 0) childpos = rightpos; } - if (size != PyList_GET_SIZE(heap)) { - Py_DECREF(newitem); - PyErr_SetString(PyExc_RuntimeError, - "list changed size during iteration"); - return -1; - } /* Move the smaller child up. */ tmp = PyList_GET_ITEM(heap, childpos); Py_INCREF(tmp); - olditem = PyList_GET_ITEM(heap, pos); + Py_DECREF(PyList_GET_ITEM(heap, pos)); PyList_SET_ITEM(heap, pos, tmp); - Py_DECREF(olditem); pos = childpos; childpos = 2*pos + 1; - if (size != PyList_GET_SIZE(heap)) { - PyErr_SetString(PyExc_RuntimeError, - "list changed size during iteration"); - return -1; - } } - /* The leaf at pos is empty now. Put newitem there, and bubble + /* The leaf at pos is empty now. Put newitem there, and and bubble it up to its final resting place (by sifting its parents down). */ Py_DECREF(PyList_GET_ITEM(heap, pos)); PyList_SET_ITEM(heap, pos, newitem); @@ -146,7 +118,7 @@ } PyDoc_STRVAR(heappush_doc, -"heappush(heap, item) -> None. Push item onto heap, maintaining the heap invariant."); +"Push item onto heap, maintaining the heap invariant."); static PyObject * heappop(PyObject *self, PyObject *heap) @@ -168,10 +140,7 @@ lastelt = PyList_GET_ITEM(heap, n-1) ; Py_INCREF(lastelt); - if (PyList_SetSlice(heap, n-1, n, NULL) < 0) { - Py_DECREF(lastelt); - return NULL; - } + PyList_SetSlice(heap, n-1, n, NULL); n--; if (!n) @@ -217,7 +186,7 @@ } PyDoc_STRVAR(heapreplace_doc, -"heapreplace(heap, item) -> value. Pop and return the current smallest value, and add the new item.\n\ +"Pop and return the current smallest value, and add the new item.\n\ \n\ This is more efficient than heappop() followed by heappush(), and can be\n\ more appropriate when using a fixed-size heap. Note that the value\n\ @@ -264,7 +233,7 @@ } PyDoc_STRVAR(heappushpop_doc, -"heappushpop(heap, item) -> value. Push item on the heap, then pop and return the smallest item\n\ +"Push item on the heap, then pop and return the smallest item\n\ from the heap. The combined action runs more efficiently than\n\ heappush() followed by a separate call to heappop()."); @@ -459,7 +428,7 @@ childpos = 2*pos + 1; } - /* The leaf at pos is empty now. Put newitem there, and bubble + /* The leaf at pos is empty now. Put newitem there, and and bubble it up to its final resting place (by sifting its parents down). */ Py_DECREF(PyList_GET_ITEM(heap, pos)); PyList_SET_ITEM(heap, pos, newitem); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_io/_iomodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -94,8 +94,8 @@ * The main open() function */ PyDoc_STRVAR(open_doc, -"open(file, mode='r', buffering=-1, encoding=None,\n" -" errors=None, newline=None, closefd=True, opener=None) -> file object\n" +"open(file, mode='r', buffering=-1, encoding=None, errors=None,\n" +" newline=None, closefd=True, opener=None, cloexec=None) -> file object\n" "\n" "Open file and return a stream. Raise IOError upon failure.\n" "\n" @@ -168,8 +168,8 @@ "'strict' to raise a ValueError exception if there is an encoding error\n" "(the default of None has the same effect), or pass 'ignore' to ignore\n" "errors. (Note that ignoring encoding errors can lead to data loss.)\n" -"See the documentation for codecs.register or run 'help(codecs.Codec)'\n" -"for a list of the permitted encoding error strings.\n" +"See the documentation for codecs.register for a list of the permitted\n" +"encoding error strings.\n" "\n" "newline controls how universal newlines works (it only applies to text\n" "mode). It can be None, '', '\\n', '\\r', and '\\r\\n'. It works as\n" @@ -199,6 +199,8 @@ "file descriptor (passing os.open as *opener* results in functionality\n" "similar to passing None).\n" "\n" +"If cloexec is True, set the close-on-exec flag.\n" +"\n" "open() returns a file object whose type depends on the mode, and\n" "through which the standard file operations such as reading and writing\n" "are performed. When open() is used to open a file in a text mode ('w',\n" @@ -219,8 +221,9 @@ { char *kwlist[] = {"file", "mode", "buffering", "encoding", "errors", "newline", - "closefd", "opener", NULL}; + "closefd", "opener", "cloexec", NULL}; PyObject *file, *opener = Py_None; + int cloexec = Py_DefaultCloexec; char *mode = "r"; int buffering = -1, closefd = 1; char *encoding = NULL, *errors = NULL, *newline = NULL; @@ -238,10 +241,11 @@ _Py_IDENTIFIER(fileno); _Py_IDENTIFIER(mode); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzziO:open", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzziOO&:open", kwlist, &file, &mode, &buffering, &encoding, &errors, &newline, - &closefd, &opener)) { + &closefd, &opener, + _Py_cloexec_converter, &cloexec)) { return NULL; } @@ -345,7 +349,7 @@ /* Create the Raw file stream */ raw = PyObject_CallFunction((PyObject *)&PyFileIO_Type, - "OsiO", file, rawmode, closefd, opener); + "OsiOi", file, rawmode, closefd, opener, cloexec); if (raw == NULL) return NULL; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_io/_iomodule.h --- a/Modules/_io/_iomodule.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_io/_iomodule.h Fri Feb 01 23:12:09 2013 +0100 @@ -77,7 +77,7 @@ long with "%lld" even when both long and long long have the same precision. */ -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) /* Windows uses long long for offsets */ typedef PY_LONG_LONG Py_off_t; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_io/bufferedio.c Fri Feb 01 23:12:09 2013 +0100 @@ -69,14 +69,6 @@ } len = Py_SIZE(data); - if (len > buf.len) { - PyErr_Format(PyExc_ValueError, - "read() returned too much data: " - "%zd bytes requested, %zd returned", - buf.len, len); - Py_DECREF(data); - goto error; - } memcpy(buf.buf, PyBytes_AS_STRING(data), len); PyBuffer_Release(&buf); @@ -663,11 +655,6 @@ _set_BlockingIOError(char *msg, Py_ssize_t written) { PyObject *err; -#ifdef Py_DEBUG - /* in debug mode, PyEval_EvalFrameEx() fails with an assertion error - if an exception is set when it is called */ - PyErr_Clear(); -#endif err = PyObject_CallFunction(PyExc_BlockingIOError, "isn", errno, msg, written); if (err) @@ -1484,7 +1471,7 @@ _bufferedreader_read_all(buffered *self) { Py_ssize_t current_size; - PyObject *res = NULL, *data = NULL, *tmp = NULL, *chunks = NULL; + PyObject *res, *data = NULL, *chunk, *chunks; /* First copy what we have in the current buffer. */ current_size = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t); @@ -1497,82 +1484,85 @@ } /* We're going past the buffer's bounds, flush it */ if (self->writable) { - tmp = buffered_flush_and_rewind_unlocked(self); - if (tmp == NULL) - goto cleanup; - Py_CLEAR(tmp); + res = buffered_flush_and_rewind_unlocked(self); + if (res == NULL) + return NULL; + Py_CLEAR(res); } _bufferedreader_reset_buf(self); if (PyObject_HasAttr(self->raw, _PyIO_str_readall)) { - tmp = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readall, NULL); - if (tmp == NULL) - goto cleanup; - if (tmp != Py_None && !PyBytes_Check(tmp)) { + chunk = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readall, NULL); + if (chunk == NULL) + return NULL; + if (chunk != Py_None && !PyBytes_Check(chunk)) { + Py_XDECREF(data); + Py_DECREF(chunk); PyErr_SetString(PyExc_TypeError, "readall() should return bytes"); - goto cleanup; + return NULL; } - if (tmp == Py_None) { - if (current_size == 0) { - res = Py_None; - goto cleanup; - } else { - res = data; - goto cleanup; + if (chunk == Py_None) { + if (current_size == 0) + return chunk; + else { + Py_DECREF(chunk); + return data; } } else if (current_size) { - PyBytes_Concat(&data, tmp); - res = data; - goto cleanup; - } - else { - res = tmp; - goto cleanup; - } + PyBytes_Concat(&data, chunk); + Py_DECREF(chunk); + if (data == NULL) + return NULL; + return data; + } else + return chunk; } chunks = PyList_New(0); - if (chunks == NULL) - goto cleanup; + if (chunks == NULL) { + Py_XDECREF(data); + return NULL; + } while (1) { if (data) { - if (PyList_Append(chunks, data) < 0) - goto cleanup; - Py_CLEAR(data); + if (PyList_Append(chunks, data) < 0) { + Py_DECREF(data); + Py_DECREF(chunks); + return NULL; + } + Py_DECREF(data); } /* Read until EOF or until read() would block. */ data = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_read, NULL); - if (data == NULL) - goto cleanup; + if (data == NULL) { + Py_DECREF(chunks); + return NULL; + } if (data != Py_None && !PyBytes_Check(data)) { + Py_DECREF(data); + Py_DECREF(chunks); PyErr_SetString(PyExc_TypeError, "read() should return bytes"); - goto cleanup; + return NULL; } if (data == Py_None || PyBytes_GET_SIZE(data) == 0) { if (current_size == 0) { - res = data; - goto cleanup; + Py_DECREF(chunks); + return data; } else { - tmp = _PyBytes_Join(_PyIO_empty_bytes, chunks); - res = tmp; - goto cleanup; + res = _PyBytes_Join(_PyIO_empty_bytes, chunks); + Py_DECREF(data); + Py_DECREF(chunks); + return res; } } current_size += PyBytes_GET_SIZE(data); if (self->abs_pos != -1) self->abs_pos += PyBytes_GET_SIZE(data); } -cleanup: - /* res is either NULL or a borrowed ref */ - Py_XINCREF(res); - Py_XDECREF(data); - Py_XDECREF(tmp); - Py_XDECREF(chunks); - return res; } /* Read n bytes from the buffer if it can, otherwise return None. @@ -1832,7 +1822,7 @@ self->ok = 0; self->detached = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedWriter", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedReader", kwlist, &raw, &buffer_size)) { return -1; } @@ -2461,7 +2451,7 @@ self->ok = 0; self->detached = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedRandom", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedReader", kwlist, &raw, &buffer_size)) { return -1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_io/fileio.c --- a/Modules/_io/fileio.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_io/fileio.c Fri Feb 01 23:12:09 2013 +0100 @@ -171,7 +171,7 @@ static int dircheck(fileio* self, PyObject *nameobj) { -#if defined(HAVE_FSTAT) && defined(S_ISDIR) && defined(EISDIR) +#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) struct stat buf; if (self->fd < 0) return 0; @@ -202,14 +202,18 @@ return 0; } +#ifdef O_CLOEXEC +extern int _Py_open_cloexec_works; +#endif static int fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) { fileio *self = (fileio *) oself; - static char *kwlist[] = {"file", "mode", "closefd", "opener", NULL}; + static char *kwlist[] = {"file", "mode", "closefd", "opener", "cloexec", NULL}; const char *name = NULL; PyObject *nameobj, *stringobj = NULL, *opener = Py_None; + int cloexec = Py_DefaultCloexec; char *mode = "r"; char *s; #ifdef MS_WINDOWS @@ -221,6 +225,11 @@ int fd = -1; int closefd = 1; int fd_is_own = 0; +#ifdef O_CLOEXEC + int *atomic_flag_works = &_Py_open_cloexec_works; +#else + int *atomic_flag_works = NULL; +#endif assert(PyFileIO_Check(oself)); if (self->fd >= 0) { @@ -233,9 +242,10 @@ self->fd = -1; } - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|siO:fileio", + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|siOO&:fileio", kwlist, &nameobj, &mode, &closefd, - &opener)) + &opener, + _Py_cloexec_converter, &cloexec)) return -1; if (PyFloat_Check(nameobj)) { @@ -345,6 +355,13 @@ if (append) flags |= O_APPEND; #endif + if (cloexec) { +#ifdef MS_WINDOWS + flags |= O_NOINHERIT; +#elif defined(O_CLOEXEC) + flags |= O_CLOEXEC; +#endif + } if (fd >= 0) { if (check_fd(fd)) @@ -369,10 +386,16 @@ else #endif self->fd = open(name, flags, 0666); + Py_END_ALLOW_THREADS - } else { - PyObject *fdobj = PyObject_CallFunction( - opener, "Oi", nameobj, flags); + } + else { + PyObject *fdobj; + + /* the opener may clear the atomic flag */ + atomic_flag_works = NULL; + + fdobj = PyObject_CallFunction(opener, "Oi", nameobj, flags); if (fdobj == NULL) goto error; if (!PyLong_Check(fdobj)) { @@ -394,6 +417,12 @@ PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj); goto error; } + +#ifndef MS_WINDOWS + if (cloexec + && _Py_set_cloexec(self->fd, 1, atomic_flag_works) < 0) + goto error; +#endif } if (dircheck(self, nameobj) < 0) goto error; @@ -533,7 +562,7 @@ len = pbuf.len; Py_BEGIN_ALLOW_THREADS errno = 0; -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) if (len > INT_MAX) len = INT_MAX; n = read(self->fd, pbuf.buf, (int)len); @@ -556,27 +585,33 @@ return PyLong_FromSsize_t(n); } -#ifndef HAVE_FSTAT - -static PyObject * -fileio_readall(fileio *self) -{ - _Py_IDENTIFIER(readall); - return _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type, - &PyId_readall, "O", self); -} - -#else - static size_t -new_buffersize(fileio *self, size_t currentsize) +new_buffersize(fileio *self, size_t currentsize +#ifdef HAVE_FSTAT + , Py_off_t pos, Py_off_t end +#endif + ) { size_t addend; - +#ifdef HAVE_FSTAT + if (end != (Py_off_t)-1) { + /* Files claiming a size smaller than SMALLCHUNK may + actually be streaming pseudo-files. In this case, we + apply the more aggressive algorithm below. + */ + if (end >= SMALLCHUNK && end >= pos && pos >= 0) { + /* Add 1 so if the file were to grow we'd notice. */ + Py_off_t bufsize = currentsize + end - pos + 1; + if (bufsize < PY_SSIZE_T_MAX) + return (size_t)bufsize; + else + return PY_SSIZE_T_MAX; + } + } +#endif /* Expand the buffer by an amount proportional to the current size, giving us amortized linear-time behavior. For bigger sizes, use a less-than-double growth factor to avoid excessive allocation. */ - assert(currentsize <= PY_SSIZE_T_MAX); if (currentsize > 65536) addend = currentsize >> 3; else @@ -590,19 +625,26 @@ static PyObject * fileio_readall(fileio *self) { +#ifdef HAVE_FSTAT struct stat st; Py_off_t pos, end; +#endif PyObject *result; - Py_ssize_t bytes_read = 0; + Py_ssize_t total = 0; Py_ssize_t n; - size_t bufsize; + size_t newsize; if (self->fd < 0) return err_closed(); if (!_PyVerify_fd(self->fd)) return PyErr_SetFromErrno(PyExc_IOError); -#ifdef MS_WINDOWS + result = PyBytes_FromStringAndSize(NULL, SMALLCHUNK); + if (result == NULL) + return NULL; + +#ifdef HAVE_FSTAT +#if defined(MS_WIN64) || defined(MS_WINDOWS) pos = _lseeki64(self->fd, 0L, SEEK_CUR); #else pos = lseek(self->fd, 0L, SEEK_CUR); @@ -611,46 +653,44 @@ end = st.st_size; else end = (Py_off_t)-1; +#endif + while (1) { +#ifdef HAVE_FSTAT + newsize = new_buffersize(self, total, pos, end); +#else + newsize = new_buffersize(self, total); +#endif + if (newsize > PY_SSIZE_T_MAX || newsize <= 0) { + PyErr_SetString(PyExc_OverflowError, + "unbounded read returned more bytes " + "than a Python string can hold "); + Py_DECREF(result); + return NULL; + } - if (end > 0 && end >= pos && pos >= 0 && end - pos < PY_SSIZE_T_MAX) { - /* This is probably a real file, so we try to allocate a - buffer one byte larger than the rest of the file. If the - calculation is right then we should get EOF without having - to enlarge the buffer. */ - bufsize = (size_t)(end - pos + 1); - } else { - bufsize = SMALLCHUNK; - } - - result = PyBytes_FromStringAndSize(NULL, bufsize); - if (result == NULL) - return NULL; - - while (1) { - if (bytes_read >= (Py_ssize_t)bufsize) { - bufsize = new_buffersize(self, bytes_read); - if (bufsize > PY_SSIZE_T_MAX || bufsize <= 0) { - PyErr_SetString(PyExc_OverflowError, - "unbounded read returned more bytes " - "than a Python string can hold"); - Py_DECREF(result); - return NULL; - } - - if (PyBytes_GET_SIZE(result) < (Py_ssize_t)bufsize) { - if (_PyBytes_Resize(&result, bufsize) < 0) + if (PyBytes_GET_SIZE(result) < (Py_ssize_t)newsize) { + if (_PyBytes_Resize(&result, newsize) < 0) { + if (total == 0) { + Py_DECREF(result); return NULL; + } + PyErr_Clear(); + break; } } Py_BEGIN_ALLOW_THREADS errno = 0; - n = bufsize - bytes_read; -#ifdef MS_WINDOWS + n = newsize - total; +#if defined(MS_WIN64) || defined(MS_WINDOWS) if (n > INT_MAX) n = INT_MAX; - n = read(self->fd, PyBytes_AS_STRING(result) + bytes_read, (int)n); + n = read(self->fd, + PyBytes_AS_STRING(result) + total, + (int)n); #else - n = read(self->fd, PyBytes_AS_STRING(result) + bytes_read, n); + n = read(self->fd, + PyBytes_AS_STRING(result) + total, + n); #endif Py_END_ALLOW_THREADS if (n == 0) @@ -663,7 +703,7 @@ } continue; } - if (bytes_read > 0) + if (total > 0) break; if (errno == EAGAIN) { Py_DECREF(result); @@ -673,19 +713,22 @@ PyErr_SetFromErrno(PyExc_IOError); return NULL; } - bytes_read += n; + total += n; +#ifdef HAVE_FSTAT pos += n; +#endif } - if (PyBytes_GET_SIZE(result) > bytes_read) { - if (_PyBytes_Resize(&result, bytes_read) < 0) + if (PyBytes_GET_SIZE(result) > total) { + if (_PyBytes_Resize(&result, total) < 0) { + /* This should never happen, but just in case */ + Py_DECREF(result); return NULL; + } } return result; } -#endif /* HAVE_FSTAT */ - static PyObject * fileio_read(fileio *self, PyObject *args) { @@ -706,7 +749,7 @@ return fileio_readall(self); } -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) if (size > INT_MAX) size = INT_MAX; #endif @@ -718,7 +761,7 @@ if (_PyVerify_fd(self->fd)) { Py_BEGIN_ALLOW_THREADS errno = 0; -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) n = read(self->fd, ptr, (int)size); #else n = read(self->fd, ptr, size); @@ -739,7 +782,7 @@ if (n != size) { if (_PyBytes_Resize(&bytes, n) < 0) { - Py_CLEAR(bytes); + Py_DECREF(bytes); return NULL; } } @@ -766,7 +809,7 @@ Py_BEGIN_ALLOW_THREADS errno = 0; len = pbuf.len; -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) if (len > 32767 && isatty(self->fd)) { /* Issue #11395: the Windows console returns an error (12: not enough space error) on writing into stdout if stdout mode is @@ -839,7 +882,7 @@ if (_PyVerify_fd(fd)) { Py_BEGIN_ALLOW_THREADS -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) res = _lseeki64(fd, pos, whence); #else res = lseek(fd, pos, whence); @@ -936,8 +979,7 @@ /* Truncate. Note that this may grow the file! */ Py_BEGIN_ALLOW_THREADS - errno = 0; - hFile = (HANDLE)_get_osfhandle(fd); + hFile = (HANDLE)_Py_get_osfhandle(fd, 0); ret = hFile == (HANDLE)-1; /* testing for INVALID_HANDLE value */ if (ret == 0) { ret = SetEndOfFile(hFile) == 0; @@ -1052,7 +1094,7 @@ PyDoc_STRVAR(fileio_doc, -"file(name: str[, mode: str][, opener: None]) -> file IO object\n" +"file(name: str, mode: str=\"r\", closefd=True, opener=None, cloexec=None) -> file IO object\n" "\n" "Open a file. The mode can be 'r', 'w', 'x' or 'a' for reading (default),\n" "writing, exclusive creation or appending. The file will be created if it\n" @@ -1064,7 +1106,9 @@ "passing a callable as *opener*. The underlying file descriptor for the file\n" "object is then obtained by calling opener with (*name*, *flags*).\n" "*opener* must return an open file descriptor (passing os.open as *opener*\n" -"results in functionality similar to passing None)."); +"results in functionality similar to passing None).\n" +"\n" +"If cloexec is True, set the close-on-exec flag."); PyDoc_STRVAR(read_doc, "read(size: int) -> bytes. read at most size bytes, returned as bytes.\n" diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_io/iobase.c --- a/Modules/_io/iobase.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_io/iobase.c Fri Feb 01 23:12:09 2013 +0100 @@ -76,7 +76,7 @@ PyDoc_STRVAR(iobase_seek_doc, "Change stream position.\n" "\n" - "Change the stream position to the given byte offset. The offset is\n" + "Change the stream position to byte offset offset. offset is\n" "interpreted relative to the position indicated by whence. Values\n" "for whence are:\n" "\n" @@ -669,10 +669,7 @@ break; /* Stop Iteration */ } - res = NULL; - do { - res = PyObject_CallMethodObjArgs(self, _PyIO_str_write, line, NULL); - } while (res == NULL && _PyIO_trap_eintr()); + res = PyObject_CallMethodObjArgs(self, _PyIO_str_write, line, NULL); Py_DECREF(line); if (res == NULL) { Py_DECREF(iter); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_io/textio.c --- a/Modules/_io/textio.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_io/textio.c Fri Feb 01 23:12:09 2013 +0100 @@ -257,25 +257,6 @@ Py_TYPE(self)->tp_free((PyObject *)self); } -static int -check_decoded(PyObject *decoded) -{ - if (decoded == NULL) - return -1; - if (!PyUnicode_Check(decoded)) { - PyErr_Format(PyExc_TypeError, - "decoder should return a string result, not '%.200s'", - Py_TYPE(decoded)->tp_name); - Py_DECREF(decoded); - return -1; - } - if (PyUnicode_READY(decoded) < 0) { - Py_DECREF(decoded); - return -1; - } - return 0; -} - #define SEEN_CR 1 #define SEEN_LF 2 #define SEEN_CRLF 4 @@ -305,9 +286,18 @@ Py_INCREF(output); } - if (check_decoded(output) < 0) + if (output == NULL) return NULL; + if (!PyUnicode_Check(output)) { + PyErr_SetString(PyExc_TypeError, + "decoder should return a string result"); + goto error; + } + + if (PyUnicode_READY(output) == -1) + goto error; + output_len = PyUnicode_GET_LENGTH(output); if (self->pendingcr && (final || output_len > 0)) { /* Prefix output with CR */ @@ -642,9 +632,8 @@ "encoding gives the name of the encoding that the stream will be\n" "decoded or encoded with. It defaults to locale.getpreferredencoding(False).\n" "\n" - "errors determines the strictness of encoding and decoding (see\n" - "help(codecs.Codec) or the documentation for codecs.register) and\n" - "defaults to \"strict\".\n" + "errors determines the strictness of encoding and decoding (see the\n" + "codecs.register) and defaults to \"strict\".\n" "\n" "newline controls how line endings are handled. It can be None, '',\n" "'\\n', '\\r', and '\\r\\n'. It works as follows:\n" @@ -1258,11 +1247,8 @@ Py_DECREF(pending); if (b == NULL) return -1; - ret = NULL; - do { - ret = PyObject_CallMethodObjArgs(self->buffer, - _PyIO_str_write, b, NULL); - } while (ret == NULL && _PyIO_trap_eintr()); + ret = PyObject_CallMethodObjArgs(self->buffer, + _PyIO_str_write, b, NULL); Py_DECREF(b); if (ret == NULL) return -1; @@ -1469,13 +1455,7 @@ Py_DECREF(chunk_size); if (input_chunk == NULL) goto fail; - if (!PyBytes_Check(input_chunk)) { - PyErr_Format(PyExc_TypeError, - "underlying %s() should have returned a bytes object, " - "not '%.200s'", (self->has_read1 ? "read1": "read"), - Py_TYPE(input_chunk)->tp_name); - goto fail; - } + assert(PyBytes_Check(input_chunk)); nbytes = PyBytes_Size(input_chunk); eof = (nbytes == 0); @@ -1489,7 +1469,10 @@ _PyIO_str_decode, input_chunk, eof ? Py_True : Py_False, NULL); } - if (check_decoded(decoded_chars) < 0) + /* TODO sanity check: isinstance(decoded_chars, unicode) */ + if (decoded_chars == NULL) + goto fail; + if (PyUnicode_READY(decoded_chars) == -1) goto fail; textiowrapper_set_decoded_chars(self, decoded_chars); nchars = PyUnicode_GET_LENGTH(decoded_chars); @@ -1507,14 +1490,7 @@ PyObject *next_input = PyNumber_Add(dec_buffer, input_chunk); if (next_input == NULL) goto fail; - if (!PyBytes_Check(next_input)) { - PyErr_Format(PyExc_TypeError, - "decoder getstate() should have returned a bytes " - "object, not '%.200s'", - Py_TYPE(next_input)->tp_name); - Py_DECREF(next_input); - goto fail; - } + assert (PyBytes_Check(next_input)); Py_DECREF(dec_buffer); Py_CLEAR(self->snapshot); self->snapshot = Py_BuildValue("NN", dec_flags, next_input); @@ -1563,7 +1539,7 @@ decoded = PyObject_CallMethodObjArgs( self->decoder, _PyIO_str_decode, bytes, Py_True, NULL); Py_DECREF(bytes); - if (check_decoded(decoded) < 0) + if (decoded == NULL) goto fail; result = textiowrapper_get_decoded_chars(self, -1); @@ -2166,14 +2142,7 @@ if (input_chunk == NULL) goto fail; - if (!PyBytes_Check(input_chunk)) { - PyErr_Format(PyExc_TypeError, - "underlying read() should have returned a bytes " - "object, not '%.200s'", - Py_TYPE(input_chunk)->tp_name); - Py_DECREF(input_chunk); - goto fail; - } + assert (PyBytes_Check(input_chunk)); self->snapshot = Py_BuildValue("iN", cookie.dec_flags, input_chunk); if (self->snapshot == NULL) { @@ -2184,8 +2153,12 @@ decoded = _PyObject_CallMethodId(self->decoder, &PyId_decode, "Oi", input_chunk, (int)cookie.need_eof); - if (check_decoded(decoded) < 0) + if (decoded == NULL) goto fail; + if (PyUnicode_READY(decoded) == -1) { + Py_DECREF(decoded); + goto fail; + } textiowrapper_set_decoded_chars(self, decoded); @@ -2301,11 +2274,13 @@ Py_DECREF(_state); \ } while (0) + /* TODO: replace assert with exception */ #define DECODER_DECODE(start, len, res) do { \ PyObject *_decoded = _PyObject_CallMethodId( \ self->decoder, &PyId_decode, "y#", start, len); \ - if (check_decoded(_decoded) < 0) \ + if (_decoded == NULL) \ goto fail; \ + assert (PyUnicode_Check(_decoded)); \ res = PyUnicode_GET_LENGTH(_decoded); \ Py_DECREF(_decoded); \ } while (0) @@ -2347,7 +2322,7 @@ /* Note our initial start point. */ cookie.start_pos += skip_bytes; - cookie.chars_to_skip = Py_SAFE_DOWNCAST(chars_to_skip, Py_ssize_t, int); + cookie.chars_to_skip = chars_to_skip; if (chars_to_skip == 0) goto finally; @@ -2386,8 +2361,9 @@ /* We didn't get enough decoded data; signal EOF to get more. */ PyObject *decoded = _PyObject_CallMethodId( self->decoder, &PyId_decode, "yi", "", /* final = */ 1); - if (check_decoded(decoded) < 0) + if (decoded == NULL) goto fail; + assert (PyUnicode_Check(decoded)); chars_decoded += PyUnicode_GET_LENGTH(decoded); Py_DECREF(decoded); cookie.need_eof = 1; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_localemodule.c --- a/Modules/_localemodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_localemodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -147,32 +147,26 @@ /* hopefully, the localeconv result survives the C library calls involved herein */ -#define RESULT(key, obj)\ - do { \ - if (obj == NULL) \ - goto failed; \ - if (PyDict_SetItemString(result, key, obj) < 0) \ - goto failed; \ - Py_DECREF(obj); \ - } while (0) - #define RESULT_STRING(s)\ - do { \ - x = PyUnicode_DecodeLocale(l->s, NULL); \ - RESULT(#s, x); \ - } while (0) + x = PyUnicode_DecodeLocale(l->s, NULL); \ + if (!x) goto failed;\ + PyDict_SetItemString(result, #s, x);\ + Py_XDECREF(x) #define RESULT_INT(i)\ - do { \ - x = PyLong_FromLong(l->i); \ - RESULT(#i, x); \ - } while (0) + x = PyLong_FromLong(l->i);\ + if (!x) goto failed;\ + PyDict_SetItemString(result, #i, x);\ + Py_XDECREF(x) /* Numeric information */ RESULT_STRING(decimal_point); RESULT_STRING(thousands_sep); x = copy_grouping(l->grouping); - RESULT("grouping", x); + if (!x) + goto failed; + PyDict_SetItemString(result, "grouping", x); + Py_XDECREF(x); /* Monetary information */ RESULT_STRING(int_curr_symbol); @@ -180,8 +174,10 @@ RESULT_STRING(mon_decimal_point); RESULT_STRING(mon_thousands_sep); x = copy_grouping(l->mon_grouping); - RESULT("mon_grouping", x); - + if (!x) + goto failed; + PyDict_SetItemString(result, "mon_grouping", x); + Py_XDECREF(x); RESULT_STRING(positive_sign); RESULT_STRING(negative_sign); RESULT_INT(int_frac_digits); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_lsprof.c --- a/Modules/_lsprof.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_lsprof.c Fri Feb 01 23:12:09 2013 +0100 @@ -223,7 +223,7 @@ newProfilerEntry(ProfilerObject *pObj, void *key, PyObject *userObj) { ProfilerEntry *self; - self = (ProfilerEntry*) PyMem_Malloc(sizeof(ProfilerEntry)); + self = (ProfilerEntry*) malloc(sizeof(ProfilerEntry)); if (self == NULL) { pObj->flags |= POF_NOMEMORY; return NULL; @@ -231,7 +231,7 @@ userObj = normalizeUserObj(userObj); if (userObj == NULL) { PyErr_Clear(); - PyMem_Free(self); + free(self); pObj->flags |= POF_NOMEMORY; return NULL; } @@ -264,7 +264,7 @@ newSubEntry(ProfilerObject *pObj, ProfilerEntry *caller, ProfilerEntry* entry) { ProfilerSubEntry *self; - self = (ProfilerSubEntry*) PyMem_Malloc(sizeof(ProfilerSubEntry)); + self = (ProfilerSubEntry*) malloc(sizeof(ProfilerSubEntry)); if (self == NULL) { pObj->flags |= POF_NOMEMORY; return NULL; @@ -282,7 +282,7 @@ static int freeSubEntry(rotating_node_t *header, void *arg) { ProfilerSubEntry *subentry = (ProfilerSubEntry*) header; - PyMem_Free(subentry); + free(subentry); return 0; } @@ -291,7 +291,7 @@ ProfilerEntry *entry = (ProfilerEntry*) header; RotatingTree_Enum(entry->calls, freeSubEntry, NULL); Py_DECREF(entry->userObj); - PyMem_Free(entry); + free(entry); return 0; } @@ -301,13 +301,13 @@ pObj->profilerEntries = EMPTY_ROTATING_TREE; /* release the memory hold by the ProfilerContexts */ if (pObj->currentProfilerContext) { - PyMem_Free(pObj->currentProfilerContext); + free(pObj->currentProfilerContext); pObj->currentProfilerContext = NULL; } while (pObj->freelistProfilerContext) { ProfilerContext *c = pObj->freelistProfilerContext; pObj->freelistProfilerContext = c->previous; - PyMem_Free(c); + free(c); } pObj->freelistProfilerContext = NULL; } @@ -393,7 +393,7 @@ else { /* free list exhausted, allocate a new one */ pContext = (ProfilerContext*) - PyMem_Malloc(sizeof(ProfilerContext)); + malloc(sizeof(ProfilerContext)); if (pContext == NULL) { pObj->flags |= POF_NOMEMORY; goto restorePyerr; @@ -712,7 +712,7 @@ else pObj->currentProfilerContext = pContext->previous; if (pContext) - PyMem_Free(pContext); + free(pContext); } } @@ -884,12 +884,10 @@ PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type); if (!initialized) { - if (PyStructSequence_InitType2(&StatsEntryType, - &profiler_entry_desc) < 0) - return NULL; - if (PyStructSequence_InitType2(&StatsSubEntryType, - &profiler_subentry_desc) < 0) - return NULL; + PyStructSequence_InitType(&StatsEntryType, + &profiler_entry_desc); + PyStructSequence_InitType(&StatsSubEntryType, + &profiler_subentry_desc); } Py_INCREF((PyObject*) &StatsEntryType); Py_INCREF((PyObject*) &StatsSubEntryType); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_lzmamodule.c --- a/Modules/_lzmamodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_lzmamodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -51,7 +51,6 @@ typedef struct { PyObject_HEAD - lzma_allocator alloc; lzma_stream lzs; int flushed; #ifdef WITH_THREAD @@ -61,7 +60,6 @@ typedef struct { PyObject_HEAD - lzma_allocator alloc; lzma_stream lzs; int check; char eof; @@ -119,22 +117,6 @@ } } -static void* -PyLzma_Malloc(void *opaque, size_t items, size_t size) -{ - if (items > (size_t)PY_SSIZE_T_MAX / size) - return NULL; - /* PyMem_Malloc() cannot be used: - the GIL is not held when lzma_code() is called */ - return PyMem_RawMalloc(items * size); -} - -static void -PyLzma_Free(void *opaque, void *ptr) -{ - PyMem_RawFree(ptr); -} - #if BUFSIZ < 8192 #define INITIAL_BUFFER_SIZE 8192 #else @@ -674,11 +656,6 @@ if (!uint32_converter(preset_obj, &preset)) return -1; - self->alloc.opaque = NULL; - self->alloc.alloc = PyLzma_Malloc; - self->alloc.free = PyLzma_Free; - self->lzs.allocator = &self->alloc; - #ifdef WITH_THREAD self->lock = PyThread_allocate_lock(); if (self->lock == NULL) { @@ -945,11 +922,6 @@ return -1; } - self->alloc.opaque = NULL; - self->alloc.alloc = PyLzma_Malloc; - self->alloc.free = PyLzma_Free; - self->lzs.allocator = &self->alloc; - #ifdef WITH_THREAD self->lock = PyThread_allocate_lock(); if (self->lock == NULL) { diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_multiprocessing/multiprocessing.c --- a/Modules/_multiprocessing/multiprocessing.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_multiprocessing/multiprocessing.c Fri Feb 01 23:12:09 2013 +0100 @@ -44,7 +44,7 @@ break; default: PyErr_Format(PyExc_RuntimeError, - "unknown error number %d", num); + "unkown error number %d", num); } return NULL; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_multiprocessing/multiprocessing.h --- a/Modules/_multiprocessing/multiprocessing.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_multiprocessing/multiprocessing.h Fri Feb 01 23:12:09 2013 +0100 @@ -99,4 +99,13 @@ extern PyTypeObject _PyMp_SemLockType; +/* + * Miscellaneous + */ + +#ifndef MIN +# define MIN(x, y) ((x) < (y) ? x : y) +# define MAX(x, y) ((x) > (y) ? x : y) +#endif + #endif /* MULTIPROCESSING_H */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_multiprocessing/semaphore.c --- a/Modules/_multiprocessing/semaphore.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_multiprocessing/semaphore.c Fri Feb 01 23:12:09 2013 +0100 @@ -43,7 +43,7 @@ { long previous; - switch (WaitForSingleObjectEx(handle, 0, FALSE)) { + switch (WaitForSingleObject(handle, 0)) { case WAIT_OBJECT_0: if (!ReleaseSemaphore(handle, 1, &previous)) return MP_STANDARD_ERROR; @@ -99,7 +99,7 @@ } /* check whether we can acquire without releasing the GIL and blocking */ - if (WaitForSingleObjectEx(self->handle, 0, FALSE) == WAIT_OBJECT_0) { + if (WaitForSingleObject(self->handle, 0) == WAIT_OBJECT_0) { self->last_tid = GetCurrentThreadId(); ++self->count; Py_RETURN_TRUE; @@ -118,7 +118,7 @@ Py_BEGIN_ALLOW_THREADS if (sigint_event != NULL) ResetEvent(sigint_event); - res = WaitForMultipleObjectsEx(nhandles, handles, FALSE, full_msecs, FALSE); + res = WaitForMultipleObjects(nhandles, handles, FALSE, full_msecs); Py_END_ALLOW_THREADS /* handle result */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_operator.c --- a/Modules/_operator.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,960 +0,0 @@ - -#include "Python.h" - -PyDoc_STRVAR(operator_doc, -"Operator interface.\n\ -\n\ -This module exports a set of functions implemented in C corresponding\n\ -to the intrinsic operators of Python. For example, operator.add(x, y)\n\ -is equivalent to the expression x+y. The function names are those\n\ -used for special methods; variants without leading and trailing\n\ -'__' are also provided for convenience."); - -#define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ - return AOP(a1); } - -#define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2; \ - if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ - return AOP(a1,a2); } - -#define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1; int a2; \ - if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \ - return AOP(a1,a2); } - -#define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2; \ - if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ - if(-1 == AOP(a1,a2)) return NULL; \ - Py_INCREF(Py_None); \ - return Py_None; } - -#define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2, *a3; \ - if(! PyArg_UnpackTuple(a,#OP,3,3,&a1,&a2,&a3)) return NULL; \ - if(-1 == AOP(a1,a2,a3)) return NULL; \ - Py_INCREF(Py_None); \ - return Py_None; } - -#define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ - long r; \ - if(-1 == (r=AOP(a1))) return NULL; \ - return PyBool_FromLong(r); } - -#define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2; long r; \ - if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ - if(-1 == (r=AOP(a1,a2))) return NULL; \ - return PyLong_FromLong(r); } - -#define spamn2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2; Py_ssize_t r; \ - if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ - if(-1 == (r=AOP(a1,a2))) return NULL; \ - return PyLong_FromSsize_t(r); } - -#define spami2b(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2; long r; \ - if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ - if(-1 == (r=AOP(a1,a2))) return NULL; \ - return PyBool_FromLong(r); } - -#define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \ - PyObject *a1, *a2; \ - if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ - return PyObject_RichCompare(a1,a2,A); } - -spami(truth , PyObject_IsTrue) -spam2(op_add , PyNumber_Add) -spam2(op_sub , PyNumber_Subtract) -spam2(op_mul , PyNumber_Multiply) -spam2(op_floordiv , PyNumber_FloorDivide) -spam2(op_truediv , PyNumber_TrueDivide) -spam2(op_mod , PyNumber_Remainder) -spam1(op_neg , PyNumber_Negative) -spam1(op_pos , PyNumber_Positive) -spam1(op_abs , PyNumber_Absolute) -spam1(op_inv , PyNumber_Invert) -spam1(op_invert , PyNumber_Invert) -spam2(op_lshift , PyNumber_Lshift) -spam2(op_rshift , PyNumber_Rshift) -spami(op_not_ , PyObject_Not) -spam2(op_and_ , PyNumber_And) -spam2(op_xor , PyNumber_Xor) -spam2(op_or_ , PyNumber_Or) -spam2(op_iadd , PyNumber_InPlaceAdd) -spam2(op_isub , PyNumber_InPlaceSubtract) -spam2(op_imul , PyNumber_InPlaceMultiply) -spam2(op_ifloordiv , PyNumber_InPlaceFloorDivide) -spam2(op_itruediv , PyNumber_InPlaceTrueDivide) -spam2(op_imod , PyNumber_InPlaceRemainder) -spam2(op_ilshift , PyNumber_InPlaceLshift) -spam2(op_irshift , PyNumber_InPlaceRshift) -spam2(op_iand , PyNumber_InPlaceAnd) -spam2(op_ixor , PyNumber_InPlaceXor) -spam2(op_ior , PyNumber_InPlaceOr) -spam2(op_concat , PySequence_Concat) -spam2(op_iconcat , PySequence_InPlaceConcat) -spami2b(op_contains , PySequence_Contains) -spamn2(indexOf , PySequence_Index) -spamn2(countOf , PySequence_Count) -spam2(op_getitem , PyObject_GetItem) -spam2n(op_delitem , PyObject_DelItem) -spam3n(op_setitem , PyObject_SetItem) -spamrc(op_lt , Py_LT) -spamrc(op_le , Py_LE) -spamrc(op_eq , Py_EQ) -spamrc(op_ne , Py_NE) -spamrc(op_gt , Py_GT) -spamrc(op_ge , Py_GE) - -static PyObject* -op_pow(PyObject *s, PyObject *a) -{ - PyObject *a1, *a2; - if (PyArg_UnpackTuple(a,"pow", 2, 2, &a1, &a2)) - return PyNumber_Power(a1, a2, Py_None); - return NULL; -} - -static PyObject* -op_ipow(PyObject *s, PyObject *a) -{ - PyObject *a1, *a2; - if (PyArg_UnpackTuple(a,"ipow", 2, 2, &a1, &a2)) - return PyNumber_InPlacePower(a1, a2, Py_None); - return NULL; -} - -static PyObject * -op_index(PyObject *s, PyObject *a) -{ - return PyNumber_Index(a); -} - -static PyObject* -is_(PyObject *s, PyObject *a) -{ - PyObject *a1, *a2, *result = NULL; - if (PyArg_UnpackTuple(a,"is_", 2, 2, &a1, &a2)) { - result = (a1 == a2) ? Py_True : Py_False; - Py_INCREF(result); - } - return result; -} - -static PyObject* -is_not(PyObject *s, PyObject *a) -{ - PyObject *a1, *a2, *result = NULL; - if (PyArg_UnpackTuple(a,"is_not", 2, 2, &a1, &a2)) { - result = (a1 != a2) ? Py_True : Py_False; - Py_INCREF(result); - } - return result; -} - -#undef spam1 -#undef spam2 -#undef spam1o -#undef spam1o - -/* compare_digest **********************************************************/ - -/* - * timing safe compare - * - * Returns 1 of the strings are equal. - * In case of len(a) != len(b) the function tries to keep the timing - * dependent on the length of b. CPU cache locally may still alter timing - * a bit. - */ -static int -_tscmp(const unsigned char *a, const unsigned char *b, - Py_ssize_t len_a, Py_ssize_t len_b) -{ - /* The volatile type declarations make sure that the compiler has no - * chance to optimize and fold the code in any way that may change - * the timing. - */ - volatile Py_ssize_t length; - volatile const unsigned char *left; - volatile const unsigned char *right; - Py_ssize_t i; - unsigned char result; - - /* loop count depends on length of b */ - length = len_b; - left = NULL; - right = b; - - /* don't use else here to keep the amount of CPU instructions constant, - * volatile forces re-evaluation - * */ - if (len_a == length) { - left = *((volatile const unsigned char**)&a); - result = 0; - } - if (len_a != length) { - left = b; - result = 1; - } - - for (i=0; i < length; i++) { - result |= *left++ ^ *right++; - } - - return (result == 0); -} - -PyDoc_STRVAR(length_hint__doc__, -"length_hint(obj, default=0) -> int\n" -"Return an estimate of the number of items in obj.\n" -"This is useful for presizing containers when building from an\n" -"iterable.\n" -"\n" -"If the object supports len(), the result will be\n" -"exact. Otherwise, it may over- or under-estimate by an\n" -"arbitrary amount. The result will be an integer >= 0."); - -static PyObject *length_hint(PyObject *self, PyObject *args) -{ - PyObject *obj; - Py_ssize_t defaultvalue = 0, res; - if (!PyArg_ParseTuple(args, "O|n:length_hint", &obj, &defaultvalue)) { - return NULL; - } - res = PyObject_LengthHint(obj, defaultvalue); - if (res == -1 && PyErr_Occurred()) { - return NULL; - } - return PyLong_FromSsize_t(res); -} - - -PyDoc_STRVAR(compare_digest__doc__, -"compare_digest(a, b) -> bool\n" -"\n" -"Return 'a == b'. This function uses an approach designed to prevent\n" -"timing analysis, making it appropriate for cryptography.\n" -"a and b must both be of the same type: either str (ASCII only),\n" -"or any type that supports the buffer protocol (e.g. bytes).\n" -"\n" -"Note: If a and b are of different lengths, or if an error occurs,\n" -"a timing attack could theoretically reveal information about the\n" -"types and lengths of a and b--but not their values.\n"); - -static PyObject* -compare_digest(PyObject *self, PyObject *args) -{ - PyObject *a, *b; - int rc; - - if (!PyArg_ParseTuple(args, "OO:compare_digest", &a, &b)) { - return NULL; - } - - /* ASCII unicode string */ - if(PyUnicode_Check(a) && PyUnicode_Check(b)) { - if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) { - return NULL; - } - if (!PyUnicode_IS_ASCII(a) || !PyUnicode_IS_ASCII(b)) { - PyErr_SetString(PyExc_TypeError, - "comparing strings with non-ASCII characters is " - "not supported"); - return NULL; - } - - rc = _tscmp(PyUnicode_DATA(a), - PyUnicode_DATA(b), - PyUnicode_GET_LENGTH(a), - PyUnicode_GET_LENGTH(b)); - } - /* fallback to buffer interface for bytes, bytesarray and other */ - else { - Py_buffer view_a; - Py_buffer view_b; - - if ((PyObject_CheckBuffer(a) == 0) & (PyObject_CheckBuffer(b) == 0)) { - PyErr_Format(PyExc_TypeError, - "unsupported operand types(s) or combination of types: " - "'%.100s' and '%.100s'", - Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name); - return NULL; - } - - if (PyObject_GetBuffer(a, &view_a, PyBUF_SIMPLE) == -1) { - return NULL; - } - if (view_a.ndim > 1) { - PyErr_SetString(PyExc_BufferError, - "Buffer must be single dimension"); - PyBuffer_Release(&view_a); - return NULL; - } - - if (PyObject_GetBuffer(b, &view_b, PyBUF_SIMPLE) == -1) { - PyBuffer_Release(&view_a); - return NULL; - } - if (view_b.ndim > 1) { - PyErr_SetString(PyExc_BufferError, - "Buffer must be single dimension"); - PyBuffer_Release(&view_a); - PyBuffer_Release(&view_b); - return NULL; - } - - rc = _tscmp((const unsigned char*)view_a.buf, - (const unsigned char*)view_b.buf, - view_a.len, - view_b.len); - - PyBuffer_Release(&view_a); - PyBuffer_Release(&view_b); - } - - return PyBool_FromLong(rc); -} - -/* operator methods **********************************************************/ - -#define spam1(OP,DOC) {#OP, OP, METH_VARARGS, PyDoc_STR(DOC)}, -#define spam2(OP,DOC) {#OP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)}, -#define spam1o(OP,DOC) {#OP, OP, METH_O, PyDoc_STR(DOC)}, -#define spam2o(OP,DOC) {#OP, op_##OP, METH_O, PyDoc_STR(DOC)}, - -static struct PyMethodDef operator_methods[] = { - -spam1o(truth, - "truth(a) -- Return True if a is true, False otherwise.") -spam2(contains, - "contains(a, b) -- Same as b in a (note reversed operands).") -spam1(indexOf, - "indexOf(a, b) -- Return the first index of b in a.") -spam1(countOf, - "countOf(a, b) -- Return the number of times b occurs in a.") - -spam1(is_, "is_(a, b) -- Same as a is b.") -spam1(is_not, "is_not(a, b) -- Same as a is not b.") -spam2o(index, "index(a) -- Same as a.__index__()") -spam2(add, "add(a, b) -- Same as a + b.") -spam2(sub, "sub(a, b) -- Same as a - b.") -spam2(mul, "mul(a, b) -- Same as a * b.") -spam2(floordiv, "floordiv(a, b) -- Same as a // b.") -spam2(truediv, "truediv(a, b) -- Same as a / b.") -spam2(mod, "mod(a, b) -- Same as a % b.") -spam2o(neg, "neg(a) -- Same as -a.") -spam2o(pos, "pos(a) -- Same as +a.") -spam2o(abs, "abs(a) -- Same as abs(a).") -spam2o(inv, "inv(a) -- Same as ~a.") -spam2o(invert, "invert(a) -- Same as ~a.") -spam2(lshift, "lshift(a, b) -- Same as a << b.") -spam2(rshift, "rshift(a, b) -- Same as a >> b.") -spam2o(not_, "not_(a) -- Same as not a.") -spam2(and_, "and_(a, b) -- Same as a & b.") -spam2(xor, "xor(a, b) -- Same as a ^ b.") -spam2(or_, "or_(a, b) -- Same as a | b.") -spam2(iadd, "a = iadd(a, b) -- Same as a += b.") -spam2(isub, "a = isub(a, b) -- Same as a -= b.") -spam2(imul, "a = imul(a, b) -- Same as a *= b.") -spam2(ifloordiv, "a = ifloordiv(a, b) -- Same as a //= b.") -spam2(itruediv, "a = itruediv(a, b) -- Same as a /= b") -spam2(imod, "a = imod(a, b) -- Same as a %= b.") -spam2(ilshift, "a = ilshift(a, b) -- Same as a <<= b.") -spam2(irshift, "a = irshift(a, b) -- Same as a >>= b.") -spam2(iand, "a = iand(a, b) -- Same as a &= b.") -spam2(ixor, "a = ixor(a, b) -- Same as a ^= b.") -spam2(ior, "a = ior(a, b) -- Same as a |= b.") -spam2(concat, - "concat(a, b) -- Same as a + b, for a and b sequences.") -spam2(iconcat, - "a = iconcat(a, b) -- Same as a += b, for a and b sequences.") -spam2(getitem, - "getitem(a, b) -- Same as a[b].") -spam2(setitem, - "setitem(a, b, c) -- Same as a[b] = c.") -spam2(delitem, - "delitem(a, b) -- Same as del a[b].") -spam2(pow, "pow(a, b) -- Same as a ** b.") -spam2(ipow, "a = ipow(a, b) -- Same as a **= b.") -spam2(lt, "lt(a, b) -- Same as ab.") -spam2(ge, "ge(a, b) -- Same as a>=b.") - - {"_compare_digest", (PyCFunction)compare_digest, METH_VARARGS, - compare_digest__doc__}, - {"length_hint", (PyCFunction)length_hint, METH_VARARGS, - length_hint__doc__}, - {NULL, NULL} /* sentinel */ - -}; - -/* itemgetter object **********************************************************/ - -typedef struct { - PyObject_HEAD - Py_ssize_t nitems; - PyObject *item; -} itemgetterobject; - -static PyTypeObject itemgetter_type; - -static PyObject * -itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - itemgetterobject *ig; - PyObject *item; - Py_ssize_t nitems; - - if (!_PyArg_NoKeywords("itemgetter()", kwds)) - return NULL; - - nitems = PyTuple_GET_SIZE(args); - if (nitems <= 1) { - if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &item)) - return NULL; - } else - item = args; - - /* create itemgetterobject structure */ - ig = PyObject_GC_New(itemgetterobject, &itemgetter_type); - if (ig == NULL) - return NULL; - - Py_INCREF(item); - ig->item = item; - ig->nitems = nitems; - - PyObject_GC_Track(ig); - return (PyObject *)ig; -} - -static void -itemgetter_dealloc(itemgetterobject *ig) -{ - PyObject_GC_UnTrack(ig); - Py_XDECREF(ig->item); - PyObject_GC_Del(ig); -} - -static int -itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg) -{ - Py_VISIT(ig->item); - return 0; -} - -static PyObject * -itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw) -{ - PyObject *obj, *result; - Py_ssize_t i, nitems=ig->nitems; - - if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) - return NULL; - if (nitems == 1) - return PyObject_GetItem(obj, ig->item); - - assert(PyTuple_Check(ig->item)); - assert(PyTuple_GET_SIZE(ig->item) == nitems); - - result = PyTuple_New(nitems); - if (result == NULL) - return NULL; - - for (i=0 ; i < nitems ; i++) { - PyObject *item, *val; - item = PyTuple_GET_ITEM(ig->item, i); - val = PyObject_GetItem(obj, item); - if (val == NULL) { - Py_DECREF(result); - return NULL; - } - PyTuple_SET_ITEM(result, i, val); - } - return result; -} - -PyDoc_STRVAR(itemgetter_doc, -"itemgetter(item, ...) --> itemgetter object\n\ -\n\ -Return a callable object that fetches the given item(s) from its operand.\n\ -After f = itemgetter(2), the call f(r) returns r[2].\n\ -After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])"); - -static PyTypeObject itemgetter_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "operator.itemgetter", /* tp_name */ - sizeof(itemgetterobject), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)itemgetter_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)itemgetter_call, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - itemgetter_doc, /* tp_doc */ - (traverseproc)itemgetter_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - itemgetter_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/* attrgetter object **********************************************************/ - -typedef struct { - PyObject_HEAD - Py_ssize_t nattrs; - PyObject *attr; -} attrgetterobject; - -static PyTypeObject attrgetter_type; - -static PyObject * -attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - attrgetterobject *ag; - PyObject *attr; - Py_ssize_t nattrs, idx, char_idx; - - if (!_PyArg_NoKeywords("attrgetter()", kwds)) - return NULL; - - nattrs = PyTuple_GET_SIZE(args); - if (nattrs <= 1) { - if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &attr)) - return NULL; - } - - attr = PyTuple_New(nattrs); - if (attr == NULL) - return NULL; - - /* prepare attr while checking args */ - for (idx = 0; idx < nattrs; ++idx) { - PyObject *item = PyTuple_GET_ITEM(args, idx); - Py_ssize_t item_len; - void *data; - unsigned int kind; - int dot_count; - - if (!PyUnicode_Check(item)) { - PyErr_SetString(PyExc_TypeError, - "attribute name must be a string"); - Py_DECREF(attr); - return NULL; - } - if (PyUnicode_READY(item)) { - Py_DECREF(attr); - return NULL; - } - item_len = PyUnicode_GET_LENGTH(item); - kind = PyUnicode_KIND(item); - data = PyUnicode_DATA(item); - - /* check whethere the string is dotted */ - dot_count = 0; - for (char_idx = 0; char_idx < item_len; ++char_idx) { - if (PyUnicode_READ(kind, data, char_idx) == '.') - ++dot_count; - } - - if (dot_count == 0) { - Py_INCREF(item); - PyUnicode_InternInPlace(&item); - PyTuple_SET_ITEM(attr, idx, item); - } else { /* make it a tuple of non-dotted attrnames */ - PyObject *attr_chain = PyTuple_New(dot_count + 1); - PyObject *attr_chain_item; - Py_ssize_t unibuff_from = 0; - Py_ssize_t unibuff_till = 0; - Py_ssize_t attr_chain_idx = 0; - - if (attr_chain == NULL) { - Py_DECREF(attr); - return NULL; - } - - for (; dot_count > 0; --dot_count) { - while (PyUnicode_READ(kind, data, unibuff_till) != '.') { - ++unibuff_till; - } - attr_chain_item = PyUnicode_Substring(item, - unibuff_from, - unibuff_till); - if (attr_chain_item == NULL) { - Py_DECREF(attr_chain); - Py_DECREF(attr); - return NULL; - } - PyUnicode_InternInPlace(&attr_chain_item); - PyTuple_SET_ITEM(attr_chain, attr_chain_idx, attr_chain_item); - ++attr_chain_idx; - unibuff_till = unibuff_from = unibuff_till + 1; - } - - /* now add the last dotless name */ - attr_chain_item = PyUnicode_Substring(item, - unibuff_from, item_len); - if (attr_chain_item == NULL) { - Py_DECREF(attr_chain); - Py_DECREF(attr); - return NULL; - } - PyUnicode_InternInPlace(&attr_chain_item); - PyTuple_SET_ITEM(attr_chain, attr_chain_idx, attr_chain_item); - - PyTuple_SET_ITEM(attr, idx, attr_chain); - } - } - - /* create attrgetterobject structure */ - ag = PyObject_GC_New(attrgetterobject, &attrgetter_type); - if (ag == NULL) { - Py_DECREF(attr); - return NULL; - } - - ag->attr = attr; - ag->nattrs = nattrs; - - PyObject_GC_Track(ag); - return (PyObject *)ag; -} - -static void -attrgetter_dealloc(attrgetterobject *ag) -{ - PyObject_GC_UnTrack(ag); - Py_XDECREF(ag->attr); - PyObject_GC_Del(ag); -} - -static int -attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg) -{ - Py_VISIT(ag->attr); - return 0; -} - -static PyObject * -dotted_getattr(PyObject *obj, PyObject *attr) -{ - PyObject *newobj; - - /* attr is either a tuple or instance of str. - Ensured by the setup code of attrgetter_new */ - if (PyTuple_CheckExact(attr)) { /* chained getattr */ - Py_ssize_t name_idx = 0, name_count; - PyObject *attr_name; - - name_count = PyTuple_GET_SIZE(attr); - Py_INCREF(obj); - for (name_idx = 0; name_idx < name_count; ++name_idx) { - attr_name = PyTuple_GET_ITEM(attr, name_idx); - newobj = PyObject_GetAttr(obj, attr_name); - Py_DECREF(obj); - if (newobj == NULL) { - return NULL; - } - /* here */ - obj = newobj; - } - } else { /* single getattr */ - newobj = PyObject_GetAttr(obj, attr); - if (newobj == NULL) - return NULL; - obj = newobj; - } - - return obj; -} - -static PyObject * -attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw) -{ - PyObject *obj, *result; - Py_ssize_t i, nattrs=ag->nattrs; - - if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) - return NULL; - if (ag->nattrs == 1) /* ag->attr is always a tuple */ - return dotted_getattr(obj, PyTuple_GET_ITEM(ag->attr, 0)); - - assert(PyTuple_Check(ag->attr)); - assert(PyTuple_GET_SIZE(ag->attr) == nattrs); - - result = PyTuple_New(nattrs); - if (result == NULL) - return NULL; - - for (i=0 ; i < nattrs ; i++) { - PyObject *attr, *val; - attr = PyTuple_GET_ITEM(ag->attr, i); - val = dotted_getattr(obj, attr); - if (val == NULL) { - Py_DECREF(result); - return NULL; - } - PyTuple_SET_ITEM(result, i, val); - } - return result; -} - -PyDoc_STRVAR(attrgetter_doc, -"attrgetter(attr, ...) --> attrgetter object\n\ -\n\ -Return a callable object that fetches the given attribute(s) from its operand.\n\ -After f = attrgetter('name'), the call f(r) returns r.name.\n\ -After g = attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).\n\ -After h = attrgetter('name.first', 'name.last'), the call h(r) returns\n\ -(r.name.first, r.name.last)."); - -static PyTypeObject attrgetter_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "operator.attrgetter", /* tp_name */ - sizeof(attrgetterobject), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)attrgetter_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)attrgetter_call, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - attrgetter_doc, /* tp_doc */ - (traverseproc)attrgetter_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - attrgetter_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/* methodcaller object **********************************************************/ - -typedef struct { - PyObject_HEAD - PyObject *name; - PyObject *args; - PyObject *kwds; -} methodcallerobject; - -static PyTypeObject methodcaller_type; - -static PyObject * -methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - methodcallerobject *mc; - PyObject *name, *newargs; - - if (PyTuple_GET_SIZE(args) < 1) { - PyErr_SetString(PyExc_TypeError, "methodcaller needs at least " - "one argument, the method name"); - return NULL; - } - - /* create methodcallerobject structure */ - mc = PyObject_GC_New(methodcallerobject, &methodcaller_type); - 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; - - PyObject_GC_Track(mc); - return (PyObject *)mc; -} - -static void -methodcaller_dealloc(methodcallerobject *mc) -{ - PyObject_GC_UnTrack(mc); - Py_XDECREF(mc->name); - Py_XDECREF(mc->args); - Py_XDECREF(mc->kwds); - PyObject_GC_Del(mc); -} - -static int -methodcaller_traverse(methodcallerobject *mc, visitproc visit, void *arg) -{ - Py_VISIT(mc->args); - Py_VISIT(mc->kwds); - return 0; -} - -static PyObject * -methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw) -{ - PyObject *method, *obj, *result; - - if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) - return NULL; - method = PyObject_GetAttr(obj, mc->name); - if (method == NULL) - return NULL; - result = PyObject_Call(method, mc->args, mc->kwds); - Py_DECREF(method); - return result; -} - -PyDoc_STRVAR(methodcaller_doc, -"methodcaller(name, ...) --> methodcaller object\n\ -\n\ -Return a callable object that calls the given method on its operand.\n\ -After f = methodcaller('name'), the call f(r) returns r.name().\n\ -After g = methodcaller('name', 'date', foo=1), the call g(r) returns\n\ -r.name('date', foo=1)."); - -static PyTypeObject methodcaller_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "operator.methodcaller", /* tp_name */ - sizeof(methodcallerobject), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)methodcaller_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)methodcaller_call, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ - methodcaller_doc, /* tp_doc */ - (traverseproc)methodcaller_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - methodcaller_new, /* tp_new */ - 0, /* tp_free */ -}; - - -/* Initialization function for the module (*must* be called PyInit__operator) */ - - -static struct PyModuleDef operatormodule = { - PyModuleDef_HEAD_INIT, - "_operator", - operator_doc, - -1, - operator_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__operator(void) -{ - PyObject *m; - - /* Create the module and add the functions */ - m = PyModule_Create(&operatormodule); - if (m == NULL) - return NULL; - - if (PyType_Ready(&itemgetter_type) < 0) - return NULL; - Py_INCREF(&itemgetter_type); - PyModule_AddObject(m, "itemgetter", (PyObject *)&itemgetter_type); - - if (PyType_Ready(&attrgetter_type) < 0) - return NULL; - Py_INCREF(&attrgetter_type); - PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type); - - if (PyType_Ready(&methodcaller_type) < 0) - return NULL; - Py_INCREF(&methodcaller_type); - PyModule_AddObject(m, "methodcaller", (PyObject *)&methodcaller_type); - return m; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_pickle.c --- a/Modules/_pickle.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_pickle.c Fri Feb 01 23:12:09 2013 +0100 @@ -436,7 +436,6 @@ new->mt_table = PyMem_MALLOC(self->mt_allocated * sizeof(PyMemoEntry)); if (new->mt_table == NULL) { PyMem_FREE(new); - PyErr_NoMemory(); return NULL; } for (i = 0; i < self->mt_allocated; i++) { @@ -530,7 +529,7 @@ oldtable = self->mt_table; self->mt_table = PyMem_MALLOC(new_size * sizeof(PyMemoEntry)); if (self->mt_table == NULL) { - self->mt_table = oldtable; + PyMem_FREE(oldtable); PyErr_NoMemory(); return -1; } @@ -775,14 +774,17 @@ self->fast_nesting = 0; self->fix_imports = 0; self->fast_memo = NULL; + + self->memo = PyMemoTable_New(); + if (self->memo == NULL) { + Py_DECREF(self); + return NULL; + } self->max_output_len = WRITE_BUF_SIZE; self->output_len = 0; - - self->memo = PyMemoTable_New(); self->output_buffer = PyBytes_FromStringAndSize(NULL, self->max_output_len); - - if (self->memo == NULL || self->output_buffer == NULL) { + if (self->output_buffer == NULL) { Py_DECREF(self); return NULL; } @@ -1004,10 +1006,8 @@ char **result) { char *input_line = PyMem_Realloc(self->input_line, len + 1); - if (input_line == NULL) { - PyErr_NoMemory(); + if (input_line == NULL) return -1; - } memcpy(input_line, line, len); input_line[len] = '\0'; @@ -1104,10 +1104,8 @@ _Unpickler_NewMemo(Py_ssize_t new_size) { PyObject **memo = PyMem_MALLOC(new_size * sizeof(PyObject *)); - if (memo == NULL) { - PyErr_NoMemory(); + if (memo == NULL) return NULL; - } memset(memo, 0, new_size * sizeof(PyObject *)); return memo; } @@ -1138,6 +1136,20 @@ if (self == NULL) return NULL; + self->stack = (Pdata *)Pdata_New(); + if (self->stack == NULL) { + Py_DECREF(self); + return NULL; + } + memset(&self->buffer, 0, sizeof(Py_buffer)); + + self->memo_size = 32; + self->memo = _Unpickler_NewMemo(self->memo_size); + if (self->memo == NULL) { + Py_DECREF(self); + return NULL; + } + self->arg = NULL; self->pers_func = NULL; self->input_buffer = NULL; @@ -1155,15 +1167,6 @@ self->marks_size = 0; self->proto = 0; self->fix_imports = 0; - memset(&self->buffer, 0, sizeof(Py_buffer)); - self->memo_size = 32; - self->memo = _Unpickler_NewMemo(self->memo_size); - self->stack = (Pdata *)Pdata_New(); - - if (self->memo == NULL || self->stack == NULL) { - Py_DECREF(self); - return NULL; - } return self; } @@ -1210,8 +1213,8 @@ if (errors == NULL) errors = "strict"; - self->encoding = _PyMem_Strdup(encoding); - self->errors = _PyMem_Strdup(errors); + self->encoding = strdup(encoding); + self->errors = strdup(errors); if (self->encoding == NULL || self->errors == NULL) { PyErr_NoMemory(); return -1; @@ -1361,10 +1364,8 @@ search: modules_dict = PySys_GetObject("modules"); - if (modules_dict == NULL) { - PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); + if (modules_dict == NULL) return NULL; - } i = 0; module_name = NULL; @@ -1747,10 +1748,8 @@ return -1; if (latin1 == NULL) { latin1 = PyUnicode_InternFromString("latin1"); - if (latin1 == NULL) { - Py_DECREF(unicode_str); + if (latin1 == NULL) return -1; - } } reduce_value = Py_BuildValue("(O(OO))", codecs_encode, unicode_str, latin1); @@ -1789,7 +1788,7 @@ } else { PyErr_SetString(PyExc_OverflowError, - "cannot serialize a bytes object larger than 4 GiB"); + "cannot serialize a bytes object larger than 4GB"); return -1; /* string too large */ } @@ -1874,97 +1873,63 @@ } static int -write_utf8(PicklerObject *self, char *data, Py_ssize_t size) -{ - char pdata[5]; - -#if SIZEOF_SIZE_T > 4 - if (size > 0xffffffffUL) { - /* string too large */ - PyErr_SetString(PyExc_OverflowError, - "cannot serialize a string larger than 4GiB"); - return -1; - } -#endif - - pdata[0] = BINUNICODE; - pdata[1] = (unsigned char)(size & 0xff); - pdata[2] = (unsigned char)((size >> 8) & 0xff); - pdata[3] = (unsigned char)((size >> 16) & 0xff); - pdata[4] = (unsigned char)((size >> 24) & 0xff); - - if (_Pickler_Write(self, pdata, sizeof(pdata)) < 0) - return -1; - - if (_Pickler_Write(self, data, size) < 0) - return -1; - - return 0; -} - -static int -write_unicode_binary(PicklerObject *self, PyObject *obj) -{ +save_unicode(PicklerObject *self, PyObject *obj) +{ + Py_ssize_t size; PyObject *encoded = NULL; - Py_ssize_t size; - char *data; - int r; - - if (PyUnicode_READY(obj)) - return -1; - - data = PyUnicode_AsUTF8AndSize(obj, &size); - if (data != NULL) - return write_utf8(self, data, size); - - /* Issue #8383: for strings with lone surrogates, fallback on the - "surrogatepass" error handler. */ - PyErr_Clear(); - encoded = PyUnicode_AsEncodedString(obj, "utf-8", "surrogatepass"); - if (encoded == NULL) - return -1; - - r = write_utf8(self, PyBytes_AS_STRING(encoded), - PyBytes_GET_SIZE(encoded)); - Py_DECREF(encoded); - return r; -} - -static int -save_unicode(PicklerObject *self, PyObject *obj) -{ + if (self->bin) { - if (write_unicode_binary(self, obj) < 0) - return -1; + char pdata[5]; + + encoded = PyUnicode_AsEncodedString(obj, "utf-8", "surrogatepass"); + if (encoded == NULL) + goto error; + + size = PyBytes_GET_SIZE(encoded); + if (size > 0xffffffffL) { + PyErr_SetString(PyExc_OverflowError, + "cannot serialize a string larger than 4GB"); + goto error; /* string too large */ + } + + pdata[0] = BINUNICODE; + pdata[1] = (unsigned char)(size & 0xff); + pdata[2] = (unsigned char)((size >> 8) & 0xff); + pdata[3] = (unsigned char)((size >> 16) & 0xff); + pdata[4] = (unsigned char)((size >> 24) & 0xff); + + if (_Pickler_Write(self, pdata, 5) < 0) + goto error; + + if (_Pickler_Write(self, PyBytes_AS_STRING(encoded), size) < 0) + goto error; } else { - PyObject *encoded; - Py_ssize_t size; const char unicode_op = UNICODE; encoded = raw_unicode_escape(obj); if (encoded == NULL) - return -1; - - if (_Pickler_Write(self, &unicode_op, 1) < 0) { - Py_DECREF(encoded); - return -1; - } + goto error; + + if (_Pickler_Write(self, &unicode_op, 1) < 0) + goto error; size = PyBytes_GET_SIZE(encoded); - if (_Pickler_Write(self, PyBytes_AS_STRING(encoded), size) < 0) { - Py_DECREF(encoded); - return -1; - } - Py_DECREF(encoded); + if (_Pickler_Write(self, PyBytes_AS_STRING(encoded), size) < 0) + goto error; if (_Pickler_Write(self, "\n", 1) < 0) - return -1; + goto error; } if (memo_put(self, obj) < 0) - return -1; - + goto error; + + Py_DECREF(encoded); return 0; + + error: + Py_XDECREF(encoded); + return -1; } /* A helper for save_tuple. Push the len elements in tuple t on the stack. */ @@ -2993,7 +2958,7 @@ if (listitems == Py_None) listitems = NULL; else if (!PyIter_Check(listitems)) { - PyErr_Format(PicklingError, "fourth element of the tuple " + PyErr_Format(PicklingError, "Fourth element of tuple" "returned by __reduce__ must be an iterator, not %s", Py_TYPE(listitems)->tp_name); return -1; @@ -3002,7 +2967,7 @@ if (dictitems == Py_None) dictitems = NULL; else if (!PyIter_Check(dictitems)) { - PyErr_Format(PicklingError, "fifth element of the tuple " + PyErr_Format(PicklingError, "Fifth element of tuple" "returned by __reduce__ must be an iterator, not %s", Py_TYPE(dictitems)->tp_name); return -1; @@ -4206,23 +4171,36 @@ if ((len = _Unpickler_Readline(self, &s)) < 0) return -1; - /* Strip the newline */ - len--; + if (len < 3) + return bad_readline(); + if ((s = strdup(s)) == NULL) { + PyErr_NoMemory(); + return -1; + } + /* Strip outermost quotes */ - if (len >= 2 && s[0] == s[len - 1] && (s[0] == '\'' || s[0] == '"')) { + while (s[len - 1] <= ' ') + len--; + if (s[0] == '"' && s[len - 1] == '"') { + s[len - 1] = '\0'; p = s + 1; len -= 2; } + else if (s[0] == '\'' && s[len - 1] == '\'') { + s[len - 1] = '\0'; + p = s + 1; + len -= 2; + } else { - PyErr_SetString(UnpicklingError, - "the STRING opcode argument must be quoted"); + free(s); + PyErr_SetString(PyExc_ValueError, "insecure string pickle"); return -1; } - assert(len >= 0); /* Use the PyBytes API to decode the string, since that is what is used to encode, and then coerce the result to Unicode. */ bytes = PyBytes_DecodeEscape(p, len, NULL, 0, NULL); + free(s); if (bytes == NULL) return -1; str = PyUnicode_FromEncodedObject(bytes, self->encoding, self->errors); @@ -4248,7 +4226,8 @@ if (x < 0) { PyErr_Format(PyExc_OverflowError, "BINBYTES exceeds system's maximum size of %zd bytes", - PY_SSIZE_T_MAX); + PY_SSIZE_T_MAX + ); return -1; } @@ -4372,7 +4351,8 @@ if (size < 0) { PyErr_Format(PyExc_OverflowError, "BINUNICODE exceeds system's maximum size of %zd bytes", - PY_SSIZE_T_MAX); + PY_SSIZE_T_MAX + ); return -1; } @@ -4836,10 +4816,9 @@ value = _Unpickler_MemoGet(self, idx); if (value == NULL) { PyObject *key = PyLong_FromSsize_t(idx); - if (key != NULL) { + if (!PyErr_Occurred()) PyErr_SetObject(PyExc_KeyError, key); - Py_DECREF(key); - } + Py_DECREF(key); return -1; } @@ -4862,10 +4841,9 @@ value = _Unpickler_MemoGet(self, idx); if (value == NULL) { PyObject *key = PyLong_FromSsize_t(idx); - if (key != NULL) { + if (!PyErr_Occurred()) PyErr_SetObject(PyExc_KeyError, key); - Py_DECREF(key); - } + Py_DECREF(key); return -1; } @@ -5061,13 +5039,11 @@ if (result == NULL) { Pdata_clear(self->stack, i + 1); Py_SIZE(self->stack) = x; - Py_DECREF(append_func); return -1; } Py_DECREF(result); } Py_SIZE(self->stack) = x; - Py_DECREF(append_func); } return 0; @@ -5546,10 +5522,8 @@ } modules_dict = PySys_GetObject("modules"); - if (modules_dict == NULL) { - PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); + if (modules_dict == NULL) return NULL; - } module = PyDict_GetItemWithError(modules_dict, module_name); if (module == NULL) { @@ -5593,8 +5567,8 @@ _Unpickler_MemoCleanup(self); PyMem_Free(self->marks); PyMem_Free(self->input_line); - PyMem_Free(self->encoding); - PyMem_Free(self->errors); + free(self->encoding); + free(self->errors); Py_TYPE(self)->tp_free((PyObject *)self); } @@ -5630,9 +5604,9 @@ self->marks = NULL; PyMem_Free(self->input_line); self->input_line = NULL; - PyMem_Free(self->encoding); + free(self->encoding); self->encoding = NULL; - PyMem_Free(self->errors); + free(self->errors); self->errors = NULL; return 0; @@ -5955,11 +5929,6 @@ idx = PyLong_AsSsize_t(key); if (idx == -1 && PyErr_Occurred()) goto error; - if (idx < 0) { - PyErr_SetString(PyExc_ValueError, - "memo key must be positive integers."); - goto error; - } if (_Unpickler_MemoPut(self, idx, value) < 0) goto error; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_posixsubprocess.c Fri Feb 01 23:12:09 2013 +0100 @@ -35,7 +35,7 @@ # define FD_DIR "/proc/self/fd" #endif -#define POSIX_CALL(call) if ((call) == -1) goto error +#define POSIX_CALL(call) do { if ((call) == -1) goto error; } while (0) /* Maximum file descriptor, initialized on module load. */ @@ -87,7 +87,7 @@ if (stat("/dev", &dev_stat) != 0) return 0; if (stat(FD_DIR, &dev_fd_stat) != 0) - return 0; + return 0; if (dev_stat.st_dev == dev_fd_stat.st_dev) return 0; /* / == /dev == /dev/fd means it is static. #fail */ return 1; @@ -176,11 +176,17 @@ * This structure is very old and stable: It will not change unless the kernel * chooses to break compatibility with all existing binaries. Highly Unlikely. */ -struct linux_dirent64 { +struct linux_dirent { +#if defined(__x86_64__) && defined(__ILP32__) + /* Support the wacky x32 ABI (fake 32-bit userspace speaking to x86_64 + * kernel interfaces) - https://sites.google.com/site/x32abi/ */ unsigned long long d_ino; - long long d_off; + unsigned long long d_off; +#else + unsigned long d_ino; /* Inode number */ + unsigned long d_off; /* Offset to next linux_dirent */ +#endif unsigned short d_reclen; /* Length of this linux_dirent */ - unsigned char d_type; char d_name[256]; /* Filename (null-terminated) */ }; @@ -205,33 +211,23 @@ int fd_dir_fd; if (start_fd >= end_fd) return; -#ifdef O_CLOEXEC - fd_dir_fd = open(FD_DIR, O_RDONLY | O_CLOEXEC, 0); -#else - fd_dir_fd = open(FD_DIR, O_RDONLY, 0); -#ifdef FD_CLOEXEC - { - int old = fcntl(fd_dir_fd, F_GETFD); - if (old != -1) - fcntl(fd_dir_fd, F_SETFD, old | FD_CLOEXEC); - } -#endif -#endif + + fd_dir_fd = _Py_open_cloexec(FD_DIR, O_RDONLY); if (fd_dir_fd == -1) { /* No way to get a list of open fds. */ _close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep); return; } else { - char buffer[sizeof(struct linux_dirent64)]; + char buffer[sizeof(struct linux_dirent)]; int bytes; - while ((bytes = syscall(SYS_getdents64, fd_dir_fd, - (struct linux_dirent64 *)buffer, + while ((bytes = syscall(SYS_getdents, fd_dir_fd, + (struct linux_dirent *)buffer, sizeof(buffer))) > 0) { - struct linux_dirent64 *entry; + struct linux_dirent *entry; int offset; for (offset = 0; offset < bytes; offset += entry->d_reclen) { int fd; - entry = (struct linux_dirent64 *)(buffer + offset); + entry = (struct linux_dirent *)(buffer + offset); if ((fd = _pos_int_from_ascii(entry->d_name)) < 0) continue; /* Not a number. */ if (fd != fd_dir_fd && fd >= start_fd && fd < end_fd && @@ -357,15 +353,12 @@ char hex_errno[sizeof(saved_errno)*2+1]; /* Close parent's pipe ends. */ - if (p2cwrite != -1) { + if (p2cwrite != -1) POSIX_CALL(close(p2cwrite)); - } - if (c2pread != -1) { + if (c2pread != -1) POSIX_CALL(close(c2pread)); - } - if (errread != -1) { + if (errread != -1) POSIX_CALL(close(errread)); - } POSIX_CALL(close(errpipe_read)); /* When duping fds, if there arises a situation where one of the fds is @@ -378,39 +371,27 @@ /* Dup fds for child. dup2() removes the CLOEXEC flag but we must do it ourselves if dup2() would be a no-op (issue #10806). */ - if (p2cread == 0) { - int old = fcntl(p2cread, F_GETFD); - if (old != -1) - fcntl(p2cread, F_SETFD, old & ~FD_CLOEXEC); - } else if (p2cread != -1) { + if (p2cread == 0) + _Py_try_set_cloexec(p2cread, 0); + else if (p2cread != -1) POSIX_CALL(dup2(p2cread, 0)); /* stdin */ - } - if (c2pwrite == 1) { - int old = fcntl(c2pwrite, F_GETFD); - if (old != -1) - fcntl(c2pwrite, F_SETFD, old & ~FD_CLOEXEC); - } else if (c2pwrite != -1) { + if (c2pwrite == 1) + _Py_try_set_cloexec(c2pwrite, 0); + else if (c2pwrite != -1) POSIX_CALL(dup2(c2pwrite, 1)); /* stdout */ - } - if (errwrite == 2) { - int old = fcntl(errwrite, F_GETFD); - if (old != -1) - fcntl(errwrite, F_SETFD, old & ~FD_CLOEXEC); - } else if (errwrite != -1) { + if (errwrite == 2) + _Py_try_set_cloexec(errwrite, 0); + else if (errwrite != -1) POSIX_CALL(dup2(errwrite, 2)); /* stderr */ - } /* Close pipe fds. Make sure we don't close the same fd more than */ /* once, or standard fds. */ - if (p2cread > 2) { + if (p2cread > 2) POSIX_CALL(close(p2cread)); - } - if (c2pwrite > 2 && c2pwrite != p2cread) { + if (c2pwrite > 2 && c2pwrite != p2cread) POSIX_CALL(close(c2pwrite)); - } - if (errwrite != c2pwrite && errwrite != p2cread && errwrite > 2) { + if (errwrite != c2pwrite && errwrite != p2cread && errwrite > 2) POSIX_CALL(close(errwrite)); - } if (close_fds) { int local_max_fd = max_fd; @@ -543,7 +524,7 @@ PyObject *result; _Py_IDENTIFIER(isenabled); _Py_IDENTIFIER(disable); - + gc_module = PyImport_ImportModule("gc"); if (gc_module == NULL) return NULL; @@ -720,52 +701,6 @@ Raises: Only on an error in the parent process.\n\ "); -PyDoc_STRVAR(subprocess_cloexec_pipe_doc, -"cloexec_pipe() -> (read_end, write_end)\n\n\ -Create a pipe whose ends have the cloexec flag set."); - -static PyObject * -subprocess_cloexec_pipe(PyObject *self, PyObject *noargs) -{ - int fds[2]; - int res; -#ifdef HAVE_PIPE2 - Py_BEGIN_ALLOW_THREADS - res = pipe2(fds, O_CLOEXEC); - Py_END_ALLOW_THREADS - if (res != 0 && errno == ENOSYS) - { - { -#endif - /* We hold the GIL which offers some protection from other code calling - * fork() before the CLOEXEC flags have been set but we can't guarantee - * anything without pipe2(). */ - long oldflags; - - res = pipe(fds); - - if (res == 0) { - oldflags = fcntl(fds[0], F_GETFD, 0); - if (oldflags < 0) res = oldflags; - } - if (res == 0) - res = fcntl(fds[0], F_SETFD, oldflags | FD_CLOEXEC); - - if (res == 0) { - oldflags = fcntl(fds[1], F_GETFD, 0); - if (oldflags < 0) res = oldflags; - } - if (res == 0) - res = fcntl(fds[1], F_SETFD, oldflags | FD_CLOEXEC); -#ifdef HAVE_PIPE2 - } - } -#endif - if (res != 0) - return PyErr_SetFromErrno(PyExc_OSError); - return Py_BuildValue("(ii)", fds[0], fds[1]); -} - /* module level code ********************************************************/ PyDoc_STRVAR(module_doc, @@ -774,7 +709,6 @@ static PyMethodDef module_methods[] = { {"fork_exec", subprocess_fork_exec, METH_VARARGS, subprocess_fork_exec_doc}, - {"cloexec_pipe", subprocess_cloexec_pipe, METH_NOARGS, subprocess_cloexec_pipe_doc}, {NULL, NULL} /* sentinel */ }; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_randommodule.c --- a/Modules/_randommodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_randommodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -250,10 +250,8 @@ /* Convert seed to byte sequence. */ key_as_bytes = (unsigned char *)PyMem_Malloc((size_t)4 * keyused); - if (key_as_bytes == NULL) { - PyErr_NoMemory(); + if (key_as_bytes == NULL) goto Done; - } res = _PyLong_AsByteArray((PyLongObject *)n, key_as_bytes, keyused * 4, 1, /* little-endian */ @@ -266,7 +264,6 @@ /* Fill array of unsigned longs from byte sequence. */ key = (unsigned long *)PyMem_Malloc(sizeof(unsigned long) * keyused); if (key == NULL) { - PyErr_NoMemory(); PyMem_Free(key_as_bytes); goto Done; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sqlite/connection.c Fri Feb 01 23:12:09 2013 +0100 @@ -60,11 +60,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) { - static char *kwlist[] = { - "database", "timeout", "detect_types", "isolation_level", - "check_same_thread", "factory", "cached_statements", "uri", - NULL - }; + static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL}; char* database; int detect_types = 0; @@ -72,14 +68,11 @@ PyObject* factory = NULL; int check_same_thread = 1; int cached_statements = 100; - int uri = 0; double timeout = 5.0; int rc; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOip", kwlist, - &database, &timeout, &detect_types, - &isolation_level, &check_same_thread, - &factory, &cached_statements, &uri)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist, + &database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements)) { return -1; } @@ -98,19 +91,8 @@ Py_INCREF(&PyUnicode_Type); self->text_factory = (PyObject*)&PyUnicode_Type; -#ifdef SQLITE_OPEN_URI - Py_BEGIN_ALLOW_THREADS - rc = sqlite3_open_v2(database, &self->db, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | - (uri ? SQLITE_OPEN_URI : 0), NULL); -#else - if (uri) { - PyErr_SetString(pysqlite_NotSupportedError, "URIs not supported"); - return -1; - } Py_BEGIN_ALLOW_THREADS rc = sqlite3_open(database, &self->db); -#endif Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { @@ -500,35 +482,32 @@ } } -static int -_pysqlite_set_result(sqlite3_context* context, PyObject* py_val) +void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) { - if (py_val == Py_None) { + const char* buffer; + Py_ssize_t buflen; + + if ((!py_val) || PyErr_Occurred()) { + sqlite3_result_null(context); + } else if (py_val == Py_None) { sqlite3_result_null(context); } else if (PyLong_Check(py_val)) { - sqlite_int64 value = _pysqlite_long_as_int64(py_val); - if (value == -1 && PyErr_Occurred()) - return -1; - sqlite3_result_int64(context, value); + sqlite3_result_int64(context, PyLong_AsLongLong(py_val)); } else if (PyFloat_Check(py_val)) { sqlite3_result_double(context, PyFloat_AsDouble(py_val)); } else if (PyUnicode_Check(py_val)) { - const char *str = _PyUnicode_AsString(py_val); - if (str == NULL) - return -1; - sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT); + char *str = _PyUnicode_AsString(py_val); + if (str != NULL) + sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT); } else if (PyObject_CheckBuffer(py_val)) { - const char* buffer; - Py_ssize_t buflen; if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); - return -1; + } else { + sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); } - sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); } else { - return -1; + /* TODO: raise error */ } - return 0; } PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv) @@ -549,7 +528,7 @@ cur_value = argv[i]; switch (sqlite3_value_type(argv[i])) { case SQLITE_INTEGER: - cur_py_value = _pysqlite_long_from_int64(sqlite3_value_int64(cur_value)); + cur_py_value = PyLong_FromLongLong(sqlite3_value_int64(cur_value)); break; case SQLITE_FLOAT: cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value)); @@ -592,7 +571,6 @@ PyObject* args; PyObject* py_func; PyObject* py_retval = NULL; - int ok; #ifdef WITH_THREAD PyGILState_STATE threadstate; @@ -608,12 +586,10 @@ Py_DECREF(args); } - ok = 0; if (py_retval) { - ok = _pysqlite_set_result(context, py_retval) == 0; + _pysqlite_set_result(context, py_retval); Py_DECREF(py_retval); - } - if (!ok) { + } else { if (_enable_callback_tracebacks) { PyErr_Print(); } else { @@ -693,11 +669,9 @@ void _pysqlite_final_callback(sqlite3_context* context) { - PyObject* function_result; + PyObject* function_result = NULL; PyObject** aggregate_instance; _Py_IDENTIFIER(finalize); - int ok; - PyObject *exception, *value, *tb; #ifdef WITH_THREAD PyGILState_STATE threadstate; @@ -713,32 +687,22 @@ goto error; } - /* Keep the exception (if any) of the last call to step() */ - PyErr_Fetch(&exception, &value, &tb); - function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, ""); - - Py_DECREF(*aggregate_instance); - - ok = 0; - if (function_result) { - ok = _pysqlite_set_result(context, function_result) == 0; - Py_DECREF(function_result); - } - if (!ok) { + if (!function_result) { if (_enable_callback_tracebacks) { PyErr_Print(); } else { PyErr_Clear(); } _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1); + } else { + _pysqlite_set_result(context, function_result); } - /* Restore the exception (if any) of the last call to step(), - but clear also the current exception if finalize() failed */ - PyErr_Restore(exception, value, tb); +error: + Py_XDECREF(*aggregate_instance); + Py_XDECREF(function_result); -error: #ifdef WITH_THREAD PyGILState_Release(threadstate); #endif @@ -883,29 +847,20 @@ gilstate = PyGILState_Ensure(); #endif - ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source); - if (ret == NULL) { - if (_enable_callback_tracebacks) + if (!ret) { + if (_enable_callback_tracebacks) { PyErr_Print(); - else + } else { PyErr_Clear(); + } rc = SQLITE_DENY; - } - else { + } else { if (PyLong_Check(ret)) { - rc = _PyLong_AsInt(ret); - if (rc == -1 && PyErr_Occurred()) { - if (_enable_callback_tracebacks) - PyErr_Print(); - else - PyErr_Clear(); - rc = SQLITE_DENY; - } - } - else { + rc = (int)PyLong_AsLong(ret); + } else { rc = SQLITE_DENY; } Py_DECREF(ret); @@ -1372,7 +1327,6 @@ PyGILState_STATE gilstate; #endif PyObject* retval = NULL; - long longval; int result = 0; #ifdef WITH_THREAD gilstate = PyGILState_Ensure(); @@ -1396,17 +1350,10 @@ goto finally; } - longval = PyLong_AsLongAndOverflow(retval, &result); - if (longval == -1 && PyErr_Occurred()) { - PyErr_Clear(); + result = PyLong_AsLong(retval); + if (PyErr_Occurred()) { result = 0; } - else if (!result) { - if (longval > 0) - result = 1; - else if (longval < 0) - result = -1; - } finally: Py_XDECREF(string1); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sqlite/cursor.c Fri Feb 01 23:12:09 2013 +0100 @@ -26,6 +26,14 @@ #include "util.h" #include "sqlitecompat.h" +/* used to decide wether to call PyLong_FromLong or PyLong_FromLongLong */ +#ifndef INT32_MIN +#define INT32_MIN (-2147483647 - 1) +#endif +#ifndef INT32_MAX +#define INT32_MAX 2147483647 +#endif + PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self); static char* errmsg_fetch_across_rollback = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from."; @@ -271,6 +279,7 @@ PyObject* row; PyObject* item = NULL; int coltype; + PY_LONG_LONG intval; PyObject* converter; PyObject* converted; Py_ssize_t nbytes; @@ -330,7 +339,12 @@ Py_INCREF(Py_None); converted = Py_None; } else if (coltype == SQLITE_INTEGER) { - converted = _pysqlite_long_from_int64(sqlite3_column_int64(self->statement->st, i)); + intval = sqlite3_column_int64(self->statement->st, i); + if (intval < INT32_MIN || intval > INT32_MAX) { + converted = PyLong_FromLongLong(intval); + } else { + converted = PyLong_FromLong((long)intval); + } } else if (coltype == SQLITE_FLOAT) { converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i)); } else if (coltype == SQLITE_TEXT) { @@ -339,11 +353,6 @@ if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) { converted = PyUnicode_FromStringAndSize(val_str, nbytes); if (!converted) { -#ifdef Py_DEBUG - /* in debug mode, type_call() fails with an assertion - error if an exception is set when it is called */ - PyErr_Clear(); -#endif colname = sqlite3_column_name(self->statement->st, i); if (!colname) { colname = ""; @@ -437,6 +446,7 @@ PyObject* func_args; PyObject* result; int numcols; + PY_LONG_LONG lastrowid; int statement_type; PyObject* descriptor; PyObject* second_argument = NULL; @@ -706,11 +716,10 @@ Py_DECREF(self->lastrowid); if (!multiple && statement_type == STATEMENT_INSERT) { - sqlite_int64 lastrowid; Py_BEGIN_ALLOW_THREADS lastrowid = sqlite3_last_insert_rowid(self->connection->db); Py_END_ALLOW_THREADS - self->lastrowid = _pysqlite_long_from_int64(lastrowid); + self->lastrowid = PyLong_FromLong((long)lastrowid); } else { Py_INCREF(Py_None); self->lastrowid = Py_None; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sqlite/module.c --- a/Modules/_sqlite/module.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sqlite/module.c Fri Feb 01 23:12:09 2013 +0100 @@ -50,26 +50,19 @@ * C-level, so this code is redundant with the one in connection_init in * connection.c and must always be copied from there ... */ - static char *kwlist[] = { - "database", "timeout", "detect_types", "isolation_level", - "check_same_thread", "factory", "cached_statements", "uri", - NULL - }; + static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL}; char* database; int detect_types = 0; PyObject* isolation_level; PyObject* factory = NULL; int check_same_thread = 1; int cached_statements; - int uri = 0; double timeout = 5.0; PyObject* result; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOip", kwlist, - &database, &timeout, &detect_types, - &isolation_level, &check_same_thread, - &factory, &cached_statements, &uri)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist, + &database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements)) { return NULL; } @@ -84,8 +77,7 @@ } PyDoc_STRVAR(module_connect_doc, -"connect(database[, timeout, detect_types, isolation_level,\n\ - check_same_thread, factory, cached_statements, uri])\n\ +"connect(database[, timeout, isolation_level, detect_types, factory])\n\ \n\ Opens a connection to the SQLite database file *database*. You can use\n\ \":memory:\" to open a database connection to a database that resides in\n\ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sqlite/statement.c --- a/Modules/_sqlite/statement.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sqlite/statement.c Fri Feb 01 23:12:09 2013 +0100 @@ -26,7 +26,6 @@ #include "connection.h" #include "microprotocols.h" #include "prepare_protocol.h" -#include "util.h" #include "sqlitecompat.h" /* prototypes */ @@ -91,6 +90,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter) { int rc = SQLITE_OK; + PY_LONG_LONG longlongval; const char* buffer; char* string; Py_ssize_t buflen; @@ -120,14 +120,11 @@ } switch (paramtype) { - case TYPE_LONG: { - sqlite_int64 value = _pysqlite_long_as_int64(parameter); - if (value == -1 && PyErr_Occurred()) - rc = -1; - else - rc = sqlite3_bind_int64(self->st, pos, value); + case TYPE_LONG: + /* in the overflow error case, longval/longlongval is -1, and an exception is set */ + longlongval = PyLong_AsLongLong(parameter); + rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval); break; - } case TYPE_FLOAT: rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); break; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sqlite/util.c --- a/Modules/_sqlite/util.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sqlite/util.c Fri Feb 01 23:12:09 2013 +0100 @@ -104,69 +104,3 @@ return errorcode; } -#ifdef WORDS_BIGENDIAN -# define IS_LITTLE_ENDIAN 0 -#else -# define IS_LITTLE_ENDIAN 1 -#endif - -PyObject * -_pysqlite_long_from_int64(sqlite_int64 value) -{ -#ifdef HAVE_LONG_LONG -# if SIZEOF_LONG_LONG < 8 - if (value > PY_LLONG_MAX || value < PY_LLONG_MIN) { - return _PyLong_FromByteArray(&value, sizeof(value), - IS_LITTLE_ENDIAN, 1 /* signed */); - } -# endif -# if SIZEOF_LONG < SIZEOF_LONG_LONG - if (value > LONG_MAX || value < LONG_MIN) - return PyLong_FromLongLong(value); -# endif -#else -# if SIZEOF_LONG < 8 - if (value > LONG_MAX || value < LONG_MIN) { - return _PyLong_FromByteArray(&value, sizeof(value), - IS_LITTLE_ENDIAN, 1 /* signed */); - } -# endif -#endif - return PyLong_FromLong(Py_SAFE_DOWNCAST(value, sqlite_int64, long)); -} - -sqlite_int64 -_pysqlite_long_as_int64(PyObject * py_val) -{ - int overflow; -#ifdef HAVE_LONG_LONG - PY_LONG_LONG value = PyLong_AsLongLongAndOverflow(py_val, &overflow); -#else - long value = PyLong_AsLongAndOverflow(py_val, &overflow); -#endif - if (value == -1 && PyErr_Occurred()) - return -1; - if (!overflow) { -#ifdef HAVE_LONG_LONG -# if SIZEOF_LONG_LONG > 8 - if (-0x8000000000000000LL <= value && value <= 0x7FFFFFFFFFFFFFFFLL) -# endif -#else -# if SIZEOF_LONG > 8 - if (-0x8000000000000000L <= value && value <= 0x7FFFFFFFFFFFFFFFL) -# endif -#endif - return value; - } - else if (sizeof(value) < sizeof(sqlite_int64)) { - sqlite_int64 int64val; - if (_PyLong_AsByteArray((PyLongObject *)py_val, - (unsigned char *)&int64val, sizeof(int64val), - IS_LITTLE_ENDIAN, 1 /* signed */) >= 0) { - return int64val; - } - } - PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to SQLite INTEGER"); - return -1; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sqlite/util.h --- a/Modules/_sqlite/util.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sqlite/util.h Fri Feb 01 23:12:09 2013 +0100 @@ -35,8 +35,4 @@ * Returns the error code (0 means no error occurred). */ int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st); - -PyObject * _pysqlite_long_from_int64(sqlite_int64 value); -sqlite_int64 _pysqlite_long_as_int64(PyObject * value); - #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_sre.c --- a/Modules/_sre.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_sre.c Fri Feb 01 23:12:09 2013 +0100 @@ -492,7 +492,7 @@ Py_ssize_t i; /* adjust end */ - if (maxcount < (end - ptr) / state->charsize && maxcount != SRE_MAXREPEAT) + if (maxcount < (end - ptr) / state->charsize && maxcount != 65535) end = ptr + maxcount*state->charsize; switch (pattern[0]) { @@ -655,7 +655,7 @@ alloc_pos = state->data_stack_base; \ TRACE(("allocating %s in %d (%d)\n", \ SFY(type), alloc_pos, sizeof(type))); \ - if (sizeof(type) > state->data_stack_size - alloc_pos) { \ + if (state->data_stack_size < alloc_pos+sizeof(type)) { \ int j = data_stack_grow(state, sizeof(type)); \ if (j < 0) return j; \ if (ctx_pos != -1) \ @@ -675,7 +675,7 @@ do { \ TRACE(("copy data in %p to %d (%d)\n", \ data, state->data_stack_base, size)); \ - if (size > state->data_stack_size - state->data_stack_base) { \ + if (state->data_stack_size < state->data_stack_base+size) { \ int j = data_stack_grow(state, size); \ if (j < 0) return j; \ if (ctx_pos != -1) \ @@ -997,7 +997,7 @@ TRACE(("|%p|%p|REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr, ctx->pattern[1], ctx->pattern[2])); - if (ctx->pattern[1] > (end - ctx->ptr) / state->charsize) + if (ctx->ptr + state->charsize * ctx->pattern[1] > end) RETURN_FAILURE; /* cannot match */ state->ptr = ctx->ptr; @@ -1081,7 +1081,7 @@ TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr, ctx->pattern[1], ctx->pattern[2])); - if (ctx->pattern[1] > (end - ctx->ptr) / state->charsize) + if (ctx->ptr + state->charsize * ctx->pattern[1] > end) RETURN_FAILURE; /* cannot match */ state->ptr = ctx->ptr; @@ -1109,7 +1109,7 @@ } else { /* general case */ LASTMARK_SAVE(); - while ((Py_ssize_t)ctx->pattern[2] == SRE_MAXREPEAT + while ((Py_ssize_t)ctx->pattern[2] == 65535 || ctx->count <= (Py_ssize_t)ctx->pattern[2]) { state->ptr = ctx->ptr; DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one, @@ -1195,7 +1195,7 @@ } if ((ctx->count < ctx->u.rep->pattern[2] || - ctx->u.rep->pattern[2] == SRE_MAXREPEAT) && + ctx->u.rep->pattern[2] == 65535) && state->ptr != ctx->u.rep->last_ptr) { /* we may have enough matches, but if we can match another item, do so */ @@ -1272,18 +1272,13 @@ LASTMARK_RESTORE(); - if ((ctx->count >= ctx->u.rep->pattern[2] - && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) || - state->ptr == ctx->u.rep->last_ptr) + if (ctx->count >= ctx->u.rep->pattern[2] + && ctx->u.rep->pattern[2] != 65535) RETURN_FAILURE; ctx->u.rep->count = ctx->count; - /* zero-width match protection */ - DATA_PUSH(&ctx->u.rep->last_ptr); - ctx->u.rep->last_ptr = state->ptr; DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3, ctx->u.rep->pattern+3); - DATA_POP(&ctx->u.rep->last_ptr); if (ret) { RETURN_ON_ERROR(ret); RETURN_SUCCESS; @@ -2779,7 +2774,7 @@ skip = *code; \ VTRACE(("%lu (skip to %p)\n", \ (unsigned long)skip, code+skip)); \ - if (skip-adj > end-code) \ + if (code+skip-adj < code || code+skip-adj > end)\ FAIL; \ code++; \ } while (0) @@ -2812,7 +2807,7 @@ case SRE_OP_CHARSET: offset = 32/sizeof(SRE_CODE); /* 32-byte bitmap */ - if (offset > end-code) + if (code+offset < code || code+offset > end) FAIL; code += offset; break; @@ -2820,7 +2815,7 @@ case SRE_OP_BIGCHARSET: GET_ARG; /* Number of blocks */ offset = 256/sizeof(SRE_CODE); /* 256-byte table */ - if (offset > end-code) + if (code+offset < code || code+offset > end) FAIL; /* Make sure that each byte points to a valid block */ for (i = 0; i < 256; i++) { @@ -2829,7 +2824,7 @@ } code += offset; offset = arg * 32/sizeof(SRE_CODE); /* 32-byte bitmap times arg */ - if (offset > end-code) + if (code+offset < code || code+offset > end) FAIL; code += offset; break; @@ -2980,11 +2975,11 @@ GET_ARG; prefix_len = arg; GET_ARG; /* Here comes the prefix string */ - if (prefix_len > newcode-code) + if (code+prefix_len < code || code+prefix_len > newcode) FAIL; code += prefix_len; /* And here comes the overlap table */ - if (prefix_len > newcode-code) + if (code+prefix_len < code || code+prefix_len > newcode) FAIL; /* Each overlap value should be < prefix_len */ for (i = 0; i < prefix_len; i++) { @@ -3042,7 +3037,7 @@ GET_ARG; max = arg; if (min > max) FAIL; - if (max > SRE_MAXREPEAT) + if (max > 65535) FAIL; if (!_validate_inner(code, code+skip-4, groups)) FAIL; @@ -3061,7 +3056,7 @@ GET_ARG; max = arg; if (min > max) FAIL; - if (max > SRE_MAXREPEAT) + if (max > 65535) FAIL; if (!_validate_inner(code, code+skip-3, groups)) FAIL; @@ -3113,7 +3108,7 @@ to allow arbitrary jumps anywhere in the code; so we just look for a JUMP opcode preceding our skip target. */ - if (skip >= 3 && skip-3 < end-code && + if (skip >= 3 && code+skip-3 >= code && code[skip-3] == SRE_OP_JUMP) { VTRACE(("both then and else parts present\n")); @@ -3947,12 +3942,6 @@ Py_DECREF(x); } - x = PyLong_FromUnsignedLong(SRE_MAXREPEAT); - if (x) { - PyDict_SetItemString(d, "MAXREPEAT", x); - Py_DECREF(x); - } - x = PyUnicode_FromString(copyright); if (x) { PyDict_SetItemString(d, "copyright", x); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_ssl.c --- a/Modules/_ssl.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_ssl.c Fri Feb 01 23:12:09 2013 +0100 @@ -40,70 +40,6 @@ #endif -/* Include symbols from _socket module */ -#include "socketmodule.h" - -static PySocketModule_APIObject PySocketModule; - -#if defined(HAVE_POLL_H) -#include -#elif defined(HAVE_SYS_POLL_H) -#include -#endif - -/* Include OpenSSL header files */ -#include "openssl/rsa.h" -#include "openssl/crypto.h" -#include "openssl/x509.h" -#include "openssl/x509v3.h" -#include "openssl/pem.h" -#include "openssl/ssl.h" -#include "openssl/err.h" -#include "openssl/rand.h" - -/* SSL error object */ -static PyObject *PySSLErrorObject; -static PyObject *PySSLZeroReturnErrorObject; -static PyObject *PySSLWantReadErrorObject; -static PyObject *PySSLWantWriteErrorObject; -static PyObject *PySSLSyscallErrorObject; -static PyObject *PySSLEOFErrorObject; - -/* Error mappings */ -static PyObject *err_codes_to_names; -static PyObject *err_names_to_codes; -static PyObject *lib_codes_to_names; - -struct py_ssl_error_code { - const char *mnemonic; - int library, reason; -}; -struct py_ssl_library_code { - const char *library; - int code; -}; - -/* Include generated data (error codes) */ -#include "_ssl_data.h" - -/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1 - http://www.openssl.org/news/changelog.html - */ -#if OPENSSL_VERSION_NUMBER >= 0x10001000L -# define HAVE_TLSv1_2 1 -#else -# define HAVE_TLSv1_2 0 -#endif - -/* SNI support (client- and server-side) appeared in OpenSSL 1.0.0. - * This includes the SSL_set_SSL_CTX() function. - */ -#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME -# define HAVE_SNI 1 -#else -# define HAVE_SNI 0 -#endif - enum py_ssl_error { /* these mirror ssl.h */ PY_SSL_ERROR_NONE, @@ -137,14 +73,55 @@ #endif PY_SSL_VERSION_SSL3=1, PY_SSL_VERSION_SSL23, -#if HAVE_TLSv1_2 - PY_SSL_VERSION_TLS1, - PY_SSL_VERSION_TLS1_1, - PY_SSL_VERSION_TLS1_2 -#else PY_SSL_VERSION_TLS1 +}; + +struct py_ssl_error_code { + const char *mnemonic; + int library, reason; +}; + +struct py_ssl_library_code { + const char *library; + int code; +}; + +/* Include symbols from _socket module */ +#include "socketmodule.h" + +static PySocketModule_APIObject PySocketModule; + +#if defined(HAVE_POLL_H) +#include +#elif defined(HAVE_SYS_POLL_H) +#include #endif -}; + +/* Include OpenSSL header files */ +#include "openssl/rsa.h" +#include "openssl/crypto.h" +#include "openssl/x509.h" +#include "openssl/x509v3.h" +#include "openssl/pem.h" +#include "openssl/ssl.h" +#include "openssl/err.h" +#include "openssl/rand.h" + +/* Include generated data (error codes) */ +#include "_ssl_data.h" + +/* SSL error object */ +static PyObject *PySSLErrorObject; +static PyObject *PySSLZeroReturnErrorObject; +static PyObject *PySSLWantReadErrorObject; +static PyObject *PySSLWantWriteErrorObject; +static PyObject *PySSLSyscallErrorObject; +static PyObject *PySSLEOFErrorObject; + +/* Error mappings */ +static PyObject *err_codes_to_names; +static PyObject *err_names_to_codes; +static PyObject *lib_codes_to_names; #ifdef WITH_THREAD @@ -205,7 +182,7 @@ int npn_protocols_len; #endif #ifndef OPENSSL_NO_TLSEXT - PyObject *set_hostname; + PyObject *set_hostname; #endif } PySSLContext; @@ -470,7 +447,6 @@ { PySSLSocket *self; SSL_CTX *ctx = sslctx->ctx; - long mode; self = PyObject_New(PySSLSocket, &PySSLSocket_Type); if (self == NULL) @@ -491,13 +467,11 @@ PySSL_END_ALLOW_THREADS SSL_set_app_data(self->ssl,self); SSL_set_fd(self->ssl, sock->sock_fd); - mode = SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER; #ifdef SSL_MODE_AUTO_RETRY - mode |= SSL_MODE_AUTO_RETRY; + SSL_set_mode(self->ssl, SSL_MODE_AUTO_RETRY); #endif - SSL_set_mode(self->ssl, mode); - -#if HAVE_SNI + +#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME if (server_hostname != NULL) SSL_set_tlsext_host_name(self->ssl, server_hostname); #endif @@ -937,8 +911,6 @@ Py_DECREF(issuer); version = PyLong_FromLong(X509_get_version(certificate) + 1); - if (version == NULL) - goto fail0; if (PyDict_SetItemString(retval, "version", version) < 0) { Py_DECREF(version); goto fail0; @@ -1025,24 +997,6 @@ return NULL; } -static PyObject * -_certificate_to_der(X509 *certificate) -{ - unsigned char *bytes_buf = NULL; - int len; - PyObject *retval; - - bytes_buf = NULL; - len = i2d_X509(certificate, &bytes_buf); - if (len < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - /* this is actually an immutable bytes sequence */ - retval = PyBytes_FromStringAndSize((const char *) bytes_buf, len); - OPENSSL_free(bytes_buf); - return retval; -} static PyObject * PySSL_test_decode_certificate (PyObject *mod, PyObject *args) { @@ -1088,6 +1042,8 @@ static PyObject * PySSL_peercert(PySSLSocket *self, PyObject *args) { + PyObject *retval = NULL; + int len; int verification; int binary_mode = 0; @@ -1099,7 +1055,21 @@ if (binary_mode) { /* return cert in DER-encoded format */ - return _certificate_to_der(self->peer_cert); + + unsigned char *bytes_buf = NULL; + + bytes_buf = NULL; + len = i2d_X509(self->peer_cert, &bytes_buf); + if (len < 0) { + PySSL_SetError(self, len, __FILE__, __LINE__); + return NULL; + } + /* this is actually an immutable bytes sequence */ + retval = PyBytes_FromStringAndSize + ((const char *) bytes_buf, len); + OPENSSL_free(bytes_buf); + return retval; + } else { verification = SSL_CTX_get_verify_mode(SSL_get_SSL_CTX(self->ssl)); if ((verification & SSL_VERIFY_PEER) == 0) @@ -1174,7 +1144,7 @@ const unsigned char *out; unsigned int outlen; - SSL_get0_next_proto_negotiated(self->ssl, + SSL_get0_next_proto_negotiated(self->ssl, &out, &outlen); if (out == NULL) @@ -1211,16 +1181,11 @@ void *closure) { if (PyObject_TypeCheck(value, &PySSLContext_Type)) { -#if !HAVE_SNI - PyErr_SetString(PyExc_NotImplementedError, "setting a socket's " - "context is not supported by your OpenSSL library"); - return -1; -#else + Py_INCREF(value); Py_DECREF(self->ctx); self->ctx = (PySSLContext *) value; SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); -#endif } else { PyErr_SetString(PyExc_TypeError, "The value must be a SSLContext"); return -1; @@ -1340,12 +1305,6 @@ return NULL; } - if (buf.len > INT_MAX) { - PyErr_Format(PyExc_OverflowError, - "string longer than %d bytes", INT_MAX); - goto error; - } - /* just in case the blocking state of the socket has been changed */ nonblocking = (sock->sock_timeout >= 0.0); BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); @@ -1367,7 +1326,7 @@ } do { PySSL_BEGIN_ALLOW_THREADS - len = SSL_write(self->ssl, buf.buf, (int)buf.len); + len = SSL_write(self->ssl, buf.buf, buf.len); err = SSL_get_error(self->ssl, len); PySSL_END_ALLOW_THREADS if (PyErr_CheckSignals()) { @@ -1658,7 +1617,7 @@ { PyObject *retval = NULL; char buf[PySSL_CB_MAXLEN]; - size_t len; + int len; if (SSL_session_reused(self->ssl) ^ !self->socket_type) { /* if session is resumed XOR we are the client */ @@ -1670,6 +1629,7 @@ } /* It cannot be negative in current OpenSSL version as of July 2011 */ + assert(len >= 0); if (len == 0) Py_RETURN_NONE; @@ -1772,12 +1732,6 @@ PySSL_BEGIN_ALLOW_THREADS if (proto_version == PY_SSL_VERSION_TLS1) ctx = SSL_CTX_new(TLSv1_method()); -#if HAVE_TLSv1_2 - else if (proto_version == PY_SSL_VERSION_TLS1_1) - ctx = SSL_CTX_new(TLSv1_1_method()); - else if (proto_version == PY_SSL_VERSION_TLS1_2) - ctx = SSL_CTX_new(TLSv1_2_method()); -#endif else if (proto_version == PY_SSL_VERSION_SSL3) ctx = SSL_CTX_new(SSLv3_method()); #ifndef OPENSSL_NO_SSL2 @@ -1812,7 +1766,7 @@ self->npn_protocols = NULL; #endif #ifndef OPENSSL_NO_TLSEXT - self->set_hostname = NULL; + self->set_hostname = NULL; #endif /* Defaults */ SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL); @@ -1880,8 +1834,8 @@ #ifdef OPENSSL_NPN_NEGOTIATED /* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */ static int -_advertiseNPN_cb(SSL *s, - const unsigned char **data, unsigned int *len, +_advertiseNPN_cb(SSL *s, + const unsigned char **data, unsigned int *len, void *args) { PySSLContext *ssl_ctx = (PySSLContext *) args; @@ -1898,7 +1852,7 @@ } /* this callback gets passed to SSL_CTX_set_next_proto_select_cb */ static int -_selectNPN_cb(SSL *s, +_selectNPN_cb(SSL *s, unsigned char **out, unsigned char *outlen, const unsigned char *server, unsigned int server_len, void *args) @@ -2032,7 +1986,7 @@ PyThreadState *thread_state; PyObject *callable; char *password; - int size; + Py_ssize_t size; int error; } _PySSLPasswordInfo; @@ -2066,21 +2020,15 @@ goto error; } - if (size > (Py_ssize_t)INT_MAX) { - PyErr_Format(PyExc_ValueError, - "password cannot be longer than %d bytes", INT_MAX); - goto error; - } - - PyMem_Free(pw_info->password); - pw_info->password = PyMem_Malloc(size); + free(pw_info->password); + pw_info->password = malloc(size); if (!pw_info->password) { PyErr_SetString(PyExc_MemoryError, "unable to allocate password buffer"); goto error; } memcpy(pw_info->password, data, size); - pw_info->size = (int)size; + pw_info->size = size; Py_XDECREF(password_bytes); return 1; @@ -2217,13 +2165,13 @@ } SSL_CTX_set_default_passwd_cb(self->ctx, orig_passwd_cb); SSL_CTX_set_default_passwd_cb_userdata(self->ctx, orig_passwd_userdata); - PyMem_Free(pw_info.password); + free(pw_info.password); Py_RETURN_NONE; error: SSL_CTX_set_default_passwd_cb(self->ctx, orig_passwd_cb); SSL_CTX_set_default_passwd_cb_userdata(self->ctx, orig_passwd_userdata); - PyMem_Free(pw_info.password); + free(pw_info.password); Py_XDECREF(keyfile_bytes); Py_XDECREF(certfile_bytes); return NULL; @@ -2339,7 +2287,7 @@ &sock, &server_side, "idna", &hostname)) return NULL; -#if !HAVE_SNI +#ifndef SSL_CTRL_SET_TLSEXT_HOSTNAME PyMem_Free(hostname); PyErr_SetString(PyExc_ValueError, "server_hostname is not supported " "by your OpenSSL library"); @@ -2432,7 +2380,7 @@ } #endif -#if HAVE_SNI && !defined(OPENSSL_NO_TLSEXT) +#ifndef OPENSSL_NO_TLSEXT static int _servername_callback(SSL *s, int *al, void *args) { @@ -2444,17 +2392,15 @@ PyObject *result; /* The high-level ssl.SSLSocket object */ PyObject *ssl_socket; + PyGILState_STATE gstate; const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); -#ifdef WITH_THREAD - PyGILState_STATE gstate = PyGILState_Ensure(); -#endif + + gstate = PyGILState_Ensure(); if (ssl_ctx->set_hostname == NULL) { /* remove race condition in this the call back while if removing the * callback is in progress */ -#ifdef WITH_THREAD PyGILState_Release(gstate); -#endif return SSL_TLSEXT_ERR_OK; } @@ -2465,29 +2411,23 @@ if (ssl_socket == Py_None) { goto error; } - - if (servername == NULL) { - result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, - Py_None, ssl_ctx, NULL); + + servername_o = PyBytes_FromString(servername); + if (servername_o == NULL) { + PyErr_WriteUnraisable((PyObject *) ssl_ctx); + goto error; } - else { - servername_o = PyBytes_FromString(servername); - if (servername_o == NULL) { - PyErr_WriteUnraisable((PyObject *) ssl_ctx); - goto error; - } - servername_idna = PyUnicode_FromEncodedObject(servername_o, "idna", NULL); - if (servername_idna == NULL) { - PyErr_WriteUnraisable(servername_o); - Py_DECREF(servername_o); - goto error; - } + servername_idna = PyUnicode_FromEncodedObject(servername_o, "idna", NULL); + if (servername_idna == NULL) { + PyErr_WriteUnraisable(servername_o); Py_DECREF(servername_o); - result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, - servername_idna, ssl_ctx, NULL); - Py_DECREF(servername_idna); + goto error; } + Py_DECREF(servername_o); + result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, + servername_idna, ssl_ctx, NULL); Py_DECREF(ssl_socket); + Py_DECREF(servername_idna); if (result == NULL) { PyErr_WriteUnraisable(ssl_ctx->set_hostname); @@ -2509,36 +2449,32 @@ Py_DECREF(result); } -#ifdef WITH_THREAD PyGILState_Release(gstate); -#endif return ret; error: Py_DECREF(ssl_socket); *al = SSL_AD_INTERNAL_ERROR; ret = SSL_TLSEXT_ERR_ALERT_FATAL; -#ifdef WITH_THREAD PyGILState_Release(gstate); -#endif return ret; } -#endif PyDoc_STRVAR(PySSL_set_servername_callback_doc, "set_servername_callback(method)\n\ -\n\ +\ This sets a callback that will be called when a server name is provided by\n\ the SSL/TLS client in the SNI extension.\n\ -\n\ +\ If the argument is None then the callback is disabled. The method is called\n\ with the SSLSocket, the server name as a string, and the SSLContext object.\n\ -See RFC 6066 for details of the SNI extension."); +See RFC 6066 for details of the SNI"); +#endif static PyObject * set_servername_callback(PySSLContext *self, PyObject *args) { -#if HAVE_SNI && !defined(OPENSSL_NO_TLSEXT) +#ifndef OPENSSL_NO_TLSEXT PyObject *cb; if (!PyArg_ParseTuple(args, "O", &cb)) @@ -2566,114 +2502,9 @@ "The TLS extension servername callback, " "SSL_CTX_set_tlsext_servername_callback, " "is not in the current OpenSSL library."); - return NULL; #endif } -PyDoc_STRVAR(PySSL_get_stats_doc, -"cert_store_stats() -> {'crl': int, 'x509_ca': int, 'x509': int}\n\ -\n\ -Returns quantities of loaded X.509 certificates. X.509 certificates with a\n\ -CA extension and certificate revocation lists inside the context's cert\n\ -store.\n\ -NOTE: Certificates in a capath directory aren't loaded unless they have\n\ -been used at least once."); - -static PyObject * -cert_store_stats(PySSLContext *self) -{ - X509_STORE *store; - X509_OBJECT *obj; - int x509 = 0, crl = 0, pkey = 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) { - case X509_LU_X509: - x509++; - if (X509_check_ca(obj->data.x509)) { - 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 - * stored in a cert store */ - break; - } - } - return Py_BuildValue("{sisisi}", "x509", x509, "crl", crl, - "x509_ca", ca); -} - -PyDoc_STRVAR(PySSL_get_ca_certs_doc, -"get_ca_certs([der=False]) -> list of loaded certificate\n\ -\n\ -Returns a list of dicts with information of loaded CA certs. If the\n\ -optional argument is True, returns a DER-encoded copy of the CA certificate.\n\ -NOTE: Certificates in a capath directory aren't loaded unless they have\n\ -been used at least once."); - -static PyObject * -get_ca_certs(PySSLContext *self, PyObject *args) -{ - X509_STORE *store; - PyObject *ci = NULL, *rlist = NULL; - int i; - int binary_mode = 0; - - if (!PyArg_ParseTuple(args, "|p:get_ca_certs", &binary_mode)) { - return NULL; - } - - if ((rlist = PyList_New(0)) == NULL) { - return NULL; - } - - store = SSL_CTX_get_cert_store(self->ctx); - for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) { - X509_OBJECT *obj; - X509 *cert; - - obj = sk_X509_OBJECT_value(store->objs, i); - if (obj->type != X509_LU_X509) { - /* not a x509 cert */ - continue; - } - /* CA for any purpose */ - cert = obj->data.x509; - if (!X509_check_ca(cert)) { - continue; - } - if (binary_mode) { - ci = _certificate_to_der(cert); - } else { - ci = _decode_certificate(cert); - } - if (ci == NULL) { - goto error; - } - if (PyList_Append(rlist, ci) == -1) { - goto error; - } - Py_CLEAR(ci); - } - return rlist; - - error: - Py_XDECREF(ci); - Py_XDECREF(rlist); - return NULL; -} - - static PyGetSetDef context_getsetlist[] = { {"options", (getter) get_options, (setter) set_options, NULL}, @@ -2705,10 +2536,6 @@ #endif {"set_servername_callback", (PyCFunction) set_servername_callback, METH_VARARGS, PySSL_set_servername_callback_doc}, - {"cert_store_stats", (PyCFunction) cert_store_stats, - METH_NOARGS, PySSL_get_stats_doc}, - {"get_ca_certs", (PyCFunction) get_ca_certs, - METH_VARARGS, PySSL_get_ca_certs_doc}, {NULL, NULL} /* sentinel */ }; @@ -2884,169 +2711,7 @@ #endif -PyDoc_STRVAR(PySSL_get_default_verify_paths_doc, -"get_default_verify_paths() -> tuple\n\ -\n\ -Return search paths and environment vars that are used by SSLContext's\n\ -set_default_verify_paths() to load default CAs. The values are\n\ -'cert_file_env', 'cert_file', 'cert_dir_env', 'cert_dir'."); - -static PyObject * -PySSL_get_default_verify_paths(PyObject *self) -{ - PyObject *ofile_env = NULL; - PyObject *ofile = NULL; - PyObject *odir_env = NULL; - PyObject *odir = NULL; - -#define convert(info, target) { \ - const char *tmp = (info); \ - target = NULL; \ - if (!tmp) { Py_INCREF(Py_None); target = Py_None; } \ - else if ((target = PyUnicode_DecodeFSDefault(tmp)) == NULL) { \ - target = PyBytes_FromString(tmp); } \ - if (!target) goto error; \ - } while(0) - - convert(X509_get_default_cert_file_env(), ofile_env); - convert(X509_get_default_cert_file(), ofile); - convert(X509_get_default_cert_dir_env(), odir_env); - convert(X509_get_default_cert_dir(), odir); -#undef convert - - return Py_BuildValue("NNNN", ofile_env, ofile, odir_env, odir); - - error: - Py_XDECREF(ofile_env); - Py_XDECREF(ofile); - Py_XDECREF(odir_env); - Py_XDECREF(odir); - return NULL; -} - -#ifdef _MSC_VER -PyDoc_STRVAR(PySSL_enum_cert_store_doc, -"enum_cert_store(store_name, cert_type='certificate') -> []\n\ -\n\ -Retrieve certificates from Windows' cert store. store_name may be one of\n\ -'CA', 'ROOT' or 'MY'. The system may provide more cert storages, too.\n\ -cert_type must be either 'certificate' or 'crl'.\n\ -The function returns a list of (bytes, encoding_type) tuples. The\n\ -encoding_type flag can be interpreted with X509_ASN_ENCODING or\n\ -PKCS_7_ASN_ENCODING."); - -static PyObject * -PySSL_enum_cert_store(PyObject *self, PyObject *args, PyObject *kwds) -{ - char *kwlist[] = {"store_name", "cert_type", NULL}; - char *store_name; - char *cert_type = "certificate"; - HCERTSTORE hStore = NULL; - PyObject *result = NULL; - PyObject *tup = NULL, *cert = NULL, *enc = NULL; - int ok = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s:enum_cert_store", - kwlist, &store_name, &cert_type)) { - return NULL; - } - - if ((strcmp(cert_type, "certificate") != 0) && - (strcmp(cert_type, "crl") != 0)) { - return PyErr_Format(PyExc_ValueError, - "cert_type must be 'certificate' or 'crl', " - "not %.100s", cert_type); - } - - if ((result = PyList_New(0)) == NULL) { - return NULL; - } - - if ((hStore = CertOpenSystemStore(NULL, store_name)) == NULL) { - Py_DECREF(result); - return PyErr_SetFromWindowsErr(GetLastError()); - } - - if (strcmp(cert_type, "certificate") == 0) { - PCCERT_CONTEXT pCertCtx = NULL; - while (pCertCtx = CertEnumCertificatesInStore(hStore, pCertCtx)) { - cert = PyBytes_FromStringAndSize((const char*)pCertCtx->pbCertEncoded, - pCertCtx->cbCertEncoded); - if (!cert) { - ok = 0; - break; - } - if ((enc = PyLong_FromLong(pCertCtx->dwCertEncodingType)) == NULL) { - ok = 0; - break; - } - if ((tup = PyTuple_New(2)) == NULL) { - ok = 0; - break; - } - PyTuple_SET_ITEM(tup, 0, cert); cert = NULL; - PyTuple_SET_ITEM(tup, 1, enc); enc = NULL; - - if (PyList_Append(result, tup) < 0) { - ok = 0; - break; - } - Py_CLEAR(tup); - } - if (pCertCtx) { - /* loop ended with an error, need to clean up context manually */ - CertFreeCertificateContext(pCertCtx); - } - } else { - PCCRL_CONTEXT pCrlCtx = NULL; - while (pCrlCtx = CertEnumCRLsInStore(hStore, pCrlCtx)) { - cert = PyBytes_FromStringAndSize((const char*)pCrlCtx->pbCrlEncoded, - pCrlCtx->cbCrlEncoded); - if (!cert) { - ok = 0; - break; - } - if ((enc = PyLong_FromLong(pCrlCtx->dwCertEncodingType)) == NULL) { - ok = 0; - break; - } - if ((tup = PyTuple_New(2)) == NULL) { - ok = 0; - break; - } - PyTuple_SET_ITEM(tup, 0, cert); cert = NULL; - PyTuple_SET_ITEM(tup, 1, enc); enc = NULL; - - if (PyList_Append(result, tup) < 0) { - ok = 0; - break; - } - Py_CLEAR(tup); - } - if (pCrlCtx) { - /* loop ended with an error, need to clean up context manually */ - CertFreeCRLContext(pCrlCtx); - } - } - - /* In error cases cert, enc and tup may not be NULL */ - Py_XDECREF(cert); - Py_XDECREF(enc); - Py_XDECREF(tup); - - if (!CertCloseStore(hStore, 0)) { - /* This error case might shadow another exception.*/ - Py_DECREF(result); - return PyErr_SetFromWindowsErr(GetLastError()); - } - if (ok) { - return result; - } else { - Py_DECREF(result); - return NULL; - } -} -#endif + /* List of functions exported by this module. */ @@ -3065,12 +2730,6 @@ {"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS, PySSL_RAND_status_doc}, #endif - {"get_default_verify_paths", (PyCFunction)PySSL_get_default_verify_paths, - METH_NOARGS, PySSL_get_default_verify_paths_doc}, -#ifdef _MSC_VER - {"enum_cert_store", (PyCFunction)PySSL_enum_cert_store, - METH_VARARGS | METH_KEYWORDS, PySSL_enum_cert_store_doc}, -#endif {NULL, NULL} /* Sentinel */ }; @@ -3120,7 +2779,7 @@ if (_ssl_locks == NULL) { _ssl_locks_count = CRYPTO_num_locks(); _ssl_locks = (PyThread_type_lock *) - PyMem_Malloc(sizeof(PyThread_type_lock) * _ssl_locks_count); + malloc(sizeof(PyThread_type_lock) * _ssl_locks_count); if (_ssl_locks == NULL) return 0; memset(_ssl_locks, 0, @@ -3132,7 +2791,7 @@ for (j = 0; j < i; j++) { PyThread_free_lock(_ssl_locks[j]); } - PyMem_Free(_ssl_locks); + free(_ssl_locks); return 0; } } @@ -3283,12 +2942,6 @@ PyModule_AddIntConstant(m, "CERT_REQUIRED", PY_SSL_CERT_REQUIRED); -#ifdef _MSC_VER - /* Windows dwCertEncodingType */ - PyModule_AddIntMacro(m, X509_ASN_ENCODING); - PyModule_AddIntMacro(m, PKCS_7_ASN_ENCODING); -#endif - /* Alert Descriptions from ssl.h */ /* note RESERVED constants no longer intended for use have been removed */ /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6 */ @@ -3318,16 +2971,10 @@ ADD_AD_CONSTANT(INTERNAL_ERROR); ADD_AD_CONSTANT(USER_CANCELLED); ADD_AD_CONSTANT(NO_RENEGOTIATION); + ADD_AD_CONSTANT(UNSUPPORTED_EXTENSION); + ADD_AD_CONSTANT(CERTIFICATE_UNOBTAINABLE); + ADD_AD_CONSTANT(UNRECOGNIZED_NAME); /* Not all constants are in old OpenSSL versions */ -#ifdef SSL_AD_UNSUPPORTED_EXTENSION - ADD_AD_CONSTANT(UNSUPPORTED_EXTENSION); -#endif -#ifdef SSL_AD_CERTIFICATE_UNOBTAINABLE - ADD_AD_CONSTANT(CERTIFICATE_UNOBTAINABLE); -#endif -#ifdef SSL_AD_UNRECOGNIZED_NAME - ADD_AD_CONSTANT(UNRECOGNIZED_NAME); -#endif #ifdef SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE ADD_AD_CONSTANT(BAD_CERTIFICATE_STATUS_RESPONSE); #endif @@ -3351,12 +2998,6 @@ PY_SSL_VERSION_SSL23); PyModule_AddIntConstant(m, "PROTOCOL_TLSv1", PY_SSL_VERSION_TLS1); -#if HAVE_TLSv1_2 - PyModule_AddIntConstant(m, "PROTOCOL_TLSv1_1", - PY_SSL_VERSION_TLS1_1); - PyModule_AddIntConstant(m, "PROTOCOL_TLSv1_2", - PY_SSL_VERSION_TLS1_2); -#endif /* protocol options */ PyModule_AddIntConstant(m, "OP_ALL", @@ -3364,10 +3005,6 @@ PyModule_AddIntConstant(m, "OP_NO_SSLv2", SSL_OP_NO_SSLv2); PyModule_AddIntConstant(m, "OP_NO_SSLv3", SSL_OP_NO_SSLv3); PyModule_AddIntConstant(m, "OP_NO_TLSv1", SSL_OP_NO_TLSv1); -#if HAVE_TLSv1_2 - PyModule_AddIntConstant(m, "OP_NO_TLSv1_1", SSL_OP_NO_TLSv1_1); - PyModule_AddIntConstant(m, "OP_NO_TLSv1_2", SSL_OP_NO_TLSv1_2); -#endif PyModule_AddIntConstant(m, "OP_CIPHER_SERVER_PREFERENCE", SSL_OP_CIPHER_SERVER_PREFERENCE); PyModule_AddIntConstant(m, "OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE); @@ -3379,7 +3016,7 @@ SSL_OP_NO_COMPRESSION); #endif -#if HAVE_SNI +#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME r = Py_True; #else r = Py_False; @@ -3454,7 +3091,7 @@ } if (PyModule_AddObject(m, "lib_codes_to_names", lib_codes_to_names)) return NULL; - + /* OpenSSL version */ /* SSLeay() gives us the version of the library linked against, which could be different from the headers version. diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_stat.c --- a/Modules/_stat.c Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,563 +0,0 @@ -/* stat.h interface - * - * The module defines all S_IF*, S_I*, UF_*, SF_* and ST_* constants to - * sensible default values as well as defines S_IS*() macros in order to keep - * backward compatibility with the old stat.py module. - * - * New constants and macros such as S_IFDOOR / S_ISDOOR() are always defined - * as int 0. - * - * NOTE: POSIX only defines the values of the S_I* permission bits. - * - */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ - -#ifdef HAVE_SYS_STAT_H -#include -#endif /* HAVE_SYS_STAT_H */ - -#ifdef MS_WINDOWS -typedef unsigned short mode_t; -#endif - -/* From Python's stat.py */ -#ifndef S_IMODE -# define S_IMODE 07777 -#endif - -/* S_IFXXX constants (file types) - * - * Only the names are defined by POSIX but not their value. All common file - * types seems to have the same numeric value on all platforms, though. - * - * pyport.h guarantees S_IFMT, S_IFDIR, S_IFCHR, S_IFREG and S_IFLNK - */ - -#ifndef S_IFBLK -# define S_IFBLK 0060000 -#endif - -#ifndef S_IFIFO -# define S_IFIFO 0010000 -#endif - -#ifndef S_IFSOCK -# define S_IFSOCK 0140000 -#endif - -#ifndef S_IFDOOR -# define S_IFDOOR 0 -#endif - -#ifndef S_IFPORT -# define S_IFPORT 0 -#endif - -#ifndef S_IFWHT -# define S_IFWHT 0 -#endif - - -/* S_ISXXX() - * pyport.h defines S_ISDIR(), S_ISREG() and S_ISCHR() - */ - -#ifndef S_ISBLK -# define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#endif - -#ifndef S_ISFIFO -# define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) -#endif - -#ifndef S_ISLNK -# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#endif - -#ifndef S_ISSOCK -# define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) -#endif - -#ifndef S_ISDOOR -# define S_ISDOOR(mode) 0 -#endif - -#ifndef S_ISPORT -# define S_ISPORT(mode) 0 -#endif - -#ifndef S_ISWHT -# define S_ISWHT(mode) 0 -#endif - - -/* S_I* file permission - * - * The permission bit value are defined by POSIX standards. - */ -#ifndef S_ISUID -# define S_ISUID 04000 -#endif - -#ifndef S_ISGID -# define S_ISGID 02000 -#endif - -/* what is S_ENFMT? */ -#ifndef S_ENFMT -# define S_ENFMT S_ISGID -#endif - -#ifndef S_ISVTX -# define S_ISVTX 01000 -#endif - -#ifndef S_IREAD -# define S_IREAD 00400 -#endif - -#ifndef S_IWRITE -# define S_IWRITE 00200 -#endif - -#ifndef S_IEXEC -# define S_IEXEC 00100 -#endif - -#ifndef S_IRWXU -# define S_IRWXU 00700 -#endif - -#ifndef S_IRUSR -# define S_IRUSR 00400 -#endif - -#ifndef S_IWUSR -# define S_IWUSR 00200 -#endif - -#ifndef S_IXUSR -# define S_IXUSR 00100 -#endif - -#ifndef S_IRWXG -# define S_IRWXG 00070 -#endif - -#ifndef S_IRGRP -# define S_IRGRP 00040 -#endif - -#ifndef S_IWGRP -# define S_IWGRP 00020 -#endif - -#ifndef S_IXGRP -# define S_IXGRP 00010 -#endif - -#ifndef S_IRWXO -# define S_IRWXO 00007 -#endif - -#ifndef S_IROTH -# define S_IROTH 00004 -#endif - -#ifndef S_IWOTH -# define S_IWOTH 00002 -#endif - -#ifndef S_IXOTH -# define S_IXOTH 00001 -#endif - - -/* Names for file flags */ -#ifndef UF_NODUMP -# define UF_NODUMP 0x00000001 -#endif - -#ifndef UF_IMMUTABLE -# define UF_IMMUTABLE 0x00000002 -#endif - -#ifndef UF_APPEND -# define UF_APPEND 0x00000004 -#endif - -#ifndef UF_OPAQUE -# define UF_OPAQUE 0x00000008 -#endif - -#ifndef UF_NOUNLINK -# define UF_NOUNLINK 0x00000010 -#endif - -#ifndef UF_COMPRESSED -# define UF_COMPRESSED 0x00000020 -#endif - -#ifndef UF_HIDDEN -# define UF_HIDDEN 0x00008000 -#endif - -#ifndef SF_ARCHIVED -# define SF_ARCHIVED 0x00010000 -#endif - -#ifndef SF_IMMUTABLE -# define SF_IMMUTABLE 0x00020000 -#endif - -#ifndef SF_APPEND -# define SF_APPEND 0x00040000 -#endif - -#ifndef SF_NOUNLINK -# define SF_NOUNLINK 0x00100000 -#endif - -#ifndef SF_SNAPSHOT -# define SF_SNAPSHOT 0x00200000 -#endif - -static mode_t -_PyLong_AsMode_t(PyObject *op) -{ - unsigned long value; - mode_t mode; - - value = PyLong_AsUnsignedLong(op); - if ((value == (unsigned long)-1) && PyErr_Occurred()) - return (mode_t)-1; - - mode = (mode_t)value; - if ((unsigned long)mode != value) { - PyErr_SetString(PyExc_OverflowError, "mode out of range"); - return (mode_t)-1; - } - return mode; -} - - -#define stat_S_ISFUNC(isfunc, doc) \ - static PyObject * \ - stat_ ##isfunc (PyObject *self, PyObject *omode) \ - { \ - mode_t mode = _PyLong_AsMode_t(omode); \ - if ((mode == (mode_t)-1) && PyErr_Occurred()) \ - return NULL; \ - return PyBool_FromLong(isfunc(mode)); \ - } \ - PyDoc_STRVAR(stat_ ## isfunc ## _doc, doc) - -stat_S_ISFUNC(S_ISDIR, - "S_ISDIR(mode) -> bool\n\n" - "Return True if mode is from a directory."); - -stat_S_ISFUNC(S_ISCHR, - "S_ISCHR(mode) -> bool\n\n" - "Return True if mode is from a character special device file."); - -stat_S_ISFUNC(S_ISBLK, - "S_ISBLK(mode) -> bool\n\n" - "Return True if mode is from a block special device file."); - -stat_S_ISFUNC(S_ISREG, - "S_ISREG(mode) -> bool\n\n" - "Return True if mode is from a regular file."); - -stat_S_ISFUNC(S_ISFIFO, - "S_ISFIFO(mode) -> bool\n\n" - "Return True if mode is from a FIFO (named pipe)."); - -stat_S_ISFUNC(S_ISLNK, - "S_ISLNK(mode) -> bool\n\n" - "Return True if mode is from a symbolic link."); - -stat_S_ISFUNC(S_ISSOCK, - "S_ISSOCK(mode) -> bool\n\n" - "Return True if mode is from a socket."); - -stat_S_ISFUNC(S_ISDOOR, - "S_ISDOOR(mode) -> bool\n\n" - "Return True if mode is from a door."); - -stat_S_ISFUNC(S_ISPORT, - "S_ISPORT(mode) -> bool\n\n" - "Return True if mode is from an event port."); - -stat_S_ISFUNC(S_ISWHT, - "S_ISWHT(mode) -> bool\n\n" - "Return True if mode is from a whiteout."); - - -PyDoc_STRVAR(stat_S_IMODE_doc, -"Return the portion of the file's mode that can be set by os.chmod()."); - -static PyObject * -stat_S_IMODE(PyObject *self, PyObject *omode) -{ - mode_t mode = _PyLong_AsMode_t(omode); - if ((mode == (mode_t)-1) && PyErr_Occurred()) - return NULL; - return PyLong_FromUnsignedLong(mode & S_IMODE); -} - - -PyDoc_STRVAR(stat_S_IFMT_doc, -"Return the portion of the file's mode that describes the file type."); - -static PyObject * -stat_S_IFMT(PyObject *self, PyObject *omode) -{ - mode_t mode = _PyLong_AsMode_t(omode); - if ((mode == (mode_t)-1) && PyErr_Occurred()) - return NULL; - return PyLong_FromUnsignedLong(mode & S_IFMT); -} - -/* file type chars according to - http://en.wikibooks.org/wiki/C_Programming/POSIX_Reference/sys/stat.h */ - -static char -filetype(mode_t mode) -{ - /* common cases first */ - if (S_ISREG(mode)) return '-'; - if (S_ISDIR(mode)) return 'd'; - if (S_ISLNK(mode)) return 'l'; - /* special files */ - if (S_ISBLK(mode)) return 'b'; - if (S_ISCHR(mode)) return 'c'; - if (S_ISFIFO(mode)) return 'p'; - if (S_ISSOCK(mode)) return 's'; - /* non-standard types */ - if (S_ISDOOR(mode)) return 'D'; - if (S_ISPORT(mode)) return 'P'; - if (S_ISWHT(mode)) return 'w'; - /* unknown */ - return '?'; -} - -static void -fileperm(mode_t mode, char *buf) -{ - buf[0] = mode & S_IRUSR ? 'r' : '-'; - buf[1] = mode & S_IWUSR ? 'w' : '-'; - if (mode & S_ISUID) { - buf[2] = mode & S_IXUSR ? 's' : 'S'; - } else { - buf[2] = mode & S_IXUSR ? 'x' : '-'; - } - buf[3] = mode & S_IRGRP ? 'r' : '-'; - buf[4] = mode & S_IWGRP ? 'w' : '-'; - if (mode & S_ISGID) { - buf[5] = mode & S_IXGRP ? 's' : 'S'; - } else { - buf[5] = mode & S_IXGRP ? 'x' : '-'; - } - buf[6] = mode & S_IROTH ? 'r' : '-'; - buf[7] = mode & S_IWOTH ? 'w' : '-'; - if (mode & S_ISVTX) { - buf[8] = mode & S_IXOTH ? 't' : 'T'; - } else { - buf[8] = mode & S_IXOTH ? 'x' : '-'; - } -} - -PyDoc_STRVAR(stat_filemode_doc, -"Convert a file's mode to a string of the form '-rwxrwxrwx'"); - -static PyObject * -stat_filemode(PyObject *self, PyObject *omode) -{ - char buf[10]; - mode_t mode; - - mode = _PyLong_AsMode_t(omode); - if ((mode == (mode_t)-1) && PyErr_Occurred()) - return NULL; - - buf[0] = filetype(mode); - fileperm(mode, &buf[1]); - return PyUnicode_FromStringAndSize(buf, 10); -} - - -static PyMethodDef stat_methods[] = { - {"S_ISDIR", stat_S_ISDIR, METH_O, stat_S_ISDIR_doc}, - {"S_ISCHR", stat_S_ISCHR, METH_O, stat_S_ISCHR_doc}, - {"S_ISBLK", stat_S_ISBLK, METH_O, stat_S_ISBLK_doc}, - {"S_ISREG", stat_S_ISREG, METH_O, stat_S_ISREG_doc}, - {"S_ISFIFO", stat_S_ISFIFO, METH_O, stat_S_ISFIFO_doc}, - {"S_ISLNK", stat_S_ISLNK, METH_O, stat_S_ISLNK_doc}, - {"S_ISSOCK", stat_S_ISSOCK, METH_O, stat_S_ISSOCK_doc}, - {"S_ISDOOR", stat_S_ISDOOR, METH_O, stat_S_ISDOOR_doc}, - {"S_ISPORT", stat_S_ISPORT, METH_O, stat_S_ISPORT_doc}, - {"S_ISWHT", stat_S_ISWHT, METH_O, stat_S_ISWHT_doc}, - {"S_IMODE", stat_S_IMODE, METH_O, stat_S_IMODE_doc}, - {"S_IFMT", stat_S_IFMT, METH_O, stat_S_IFMT_doc}, - {"filemode", stat_filemode, METH_O, stat_filemode_doc}, - {NULL, NULL} /* sentinel */ -}; - - -PyDoc_STRVAR(module_doc, -"S_IFMT_: file type bits\n\ -S_IFDIR: directory\n\ -S_IFCHR: character device\n\ -S_IFBLK: block device\n\ -S_IFREG: regular file\n\ -S_IFIFO: fifo (named pipe)\n\ -S_IFLNK: symbolic link\n\ -S_IFSOCK: socket file\n\ -S_IFDOOR: door\n\ -S_IFPORT: event port\n\ -S_IFWHT: whiteout\n\ -\n" - -"S_ISUID: set UID bit\n\ -S_ISGID: set GID bit\n\ -S_ENFMT: file locking enforcement\n\ -S_ISVTX: sticky bit\n\ -S_IREAD: Unix V7 synonym for S_IRUSR\n\ -S_IWRITE: Unix V7 synonym for S_IWUSR\n\ -S_IEXEC: Unix V7 synonym for S_IXUSR\n\ -S_IRWXU: mask for owner permissions\n\ -S_IRUSR: read by owner\n\ -S_IWUSR: write by owner\n\ -S_IXUSR: execute by owner\n\ -S_IRWXG: mask for group permissions\n\ -S_IRGRP: read by group\n\ -S_IWGRP: write by group\n\ -S_IXGRP: execute by group\n\ -S_IRWXO: mask for others (not in group) permissions\n\ -S_IROTH: read by others\n\ -S_IWOTH: write by others\n\ -S_IXOTH: execute by others\n\ -\n" - -"UF_NODUMP: do not dump file\n\ -UF_IMMUTABLE: file may not be changed\n\ -UF_APPEND: file may only be appended to\n\ -UF_OPAQUE: directory is opaque when viewed through a union stack\n\ -UF_NOUNLINK: file may not be renamed or deleted\n\ -UF_COMPRESSED: OS X: file is hfs-compressed\n\ -UF_HIDDEN: OS X: file should not be displayed\n\ -SF_ARCHIVED: file may be archived\n\ -SF_IMMUTABLE: file may not be changed\n\ -SF_APPEND: file may only be appended to\n\ -SF_NOUNLINK: file may not be renamed or deleted\n\ -SF_SNAPSHOT: file is a snapshot file\n\ -\n" - -"ST_MODE\n\ -ST_INO\n\ -ST_DEV\n\ -ST_NLINK\n\ -ST_UID\n\ -ST_GID\n\ -ST_SIZE\n\ -ST_ATIME\n\ -ST_MTIME\n\ -ST_CTIME\n\ -"); - - -static struct PyModuleDef statmodule = { - PyModuleDef_HEAD_INIT, - "_stat", - module_doc, - -1, - stat_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__stat(void) -{ - PyObject *m; - m = PyModule_Create(&statmodule); - if (m == NULL) - return NULL; - - if (PyModule_AddIntMacro(m, S_IFDIR)) return NULL; - if (PyModule_AddIntMacro(m, S_IFCHR)) return NULL; - if (PyModule_AddIntMacro(m, S_IFBLK)) return NULL; - if (PyModule_AddIntMacro(m, S_IFREG)) return NULL; - if (PyModule_AddIntMacro(m, S_IFIFO)) return NULL; - if (PyModule_AddIntMacro(m, S_IFLNK)) return NULL; - if (PyModule_AddIntMacro(m, S_IFSOCK)) return NULL; - if (PyModule_AddIntMacro(m, S_IFDOOR)) return NULL; - if (PyModule_AddIntMacro(m, S_IFPORT)) return NULL; - if (PyModule_AddIntMacro(m, S_IFWHT)) return NULL; - - if (PyModule_AddIntMacro(m, S_ISUID)) return NULL; - if (PyModule_AddIntMacro(m, S_ISGID)) return NULL; - if (PyModule_AddIntMacro(m, S_ISVTX)) return NULL; - if (PyModule_AddIntMacro(m, S_ENFMT)) return NULL; - - if (PyModule_AddIntMacro(m, S_IREAD)) return NULL; - if (PyModule_AddIntMacro(m, S_IWRITE)) return NULL; - if (PyModule_AddIntMacro(m, S_IEXEC)) return NULL; - - if (PyModule_AddIntMacro(m, S_IRWXU)) return NULL; - if (PyModule_AddIntMacro(m, S_IRUSR)) return NULL; - if (PyModule_AddIntMacro(m, S_IWUSR)) return NULL; - if (PyModule_AddIntMacro(m, S_IXUSR)) return NULL; - - if (PyModule_AddIntMacro(m, S_IRWXG)) return NULL; - if (PyModule_AddIntMacro(m, S_IRGRP)) return NULL; - if (PyModule_AddIntMacro(m, S_IWGRP)) return NULL; - if (PyModule_AddIntMacro(m, S_IXGRP)) return NULL; - - if (PyModule_AddIntMacro(m, S_IRWXO)) return NULL; - if (PyModule_AddIntMacro(m, S_IROTH)) return NULL; - if (PyModule_AddIntMacro(m, S_IWOTH)) return NULL; - if (PyModule_AddIntMacro(m, S_IXOTH)) return NULL; - - if (PyModule_AddIntMacro(m, UF_NODUMP)) return NULL; - if (PyModule_AddIntMacro(m, UF_IMMUTABLE)) return NULL; - if (PyModule_AddIntMacro(m, UF_APPEND)) return NULL; - if (PyModule_AddIntMacro(m, UF_OPAQUE)) return NULL; - if (PyModule_AddIntMacro(m, UF_NOUNLINK)) return NULL; - if (PyModule_AddIntMacro(m, UF_COMPRESSED)) return NULL; - if (PyModule_AddIntMacro(m, UF_HIDDEN)) return NULL; - if (PyModule_AddIntMacro(m, SF_ARCHIVED)) return NULL; - if (PyModule_AddIntMacro(m, SF_IMMUTABLE)) return NULL; - if (PyModule_AddIntMacro(m, SF_APPEND)) return NULL; - if (PyModule_AddIntMacro(m, SF_NOUNLINK)) return NULL; - if (PyModule_AddIntMacro(m, SF_SNAPSHOT)) return NULL; - - if (PyModule_AddIntConstant(m, "ST_MODE", 0)) return NULL; - if (PyModule_AddIntConstant(m, "ST_INO", 1)) return NULL; - if (PyModule_AddIntConstant(m, "ST_DEV", 2)) return NULL; - if (PyModule_AddIntConstant(m, "ST_NLINK", 3)) return NULL; - if (PyModule_AddIntConstant(m, "ST_UID", 4)) return NULL; - if (PyModule_AddIntConstant(m, "ST_GID", 5)) return NULL; - if (PyModule_AddIntConstant(m, "ST_SIZE", 6)) return NULL; - if (PyModule_AddIntConstant(m, "ST_ATIME", 7)) return NULL; - if (PyModule_AddIntConstant(m, "ST_MTIME", 8)) return NULL; - if (PyModule_AddIntConstant(m, "ST_CTIME", 9)) return NULL; - - return m; -} - -#ifdef __cplusplus -} -#endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_struct.c --- a/Modules/_struct.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_struct.c Fri Feb 01 23:12:09 2013 +0100 @@ -26,7 +26,6 @@ const struct _formatdef *fmtdef; Py_ssize_t offset; Py_ssize_t size; - Py_ssize_t repeat; } formatcode; /* Struct object interface */ @@ -1248,9 +1247,6 @@ return size; } -/* - * Struct object implementation. - */ /* calculate the size of a format string */ @@ -1264,7 +1260,7 @@ const char *s; const char *fmt; char c; - Py_ssize_t size, len, ncodes, num, itemsize; + Py_ssize_t size, len, num, itemsize; fmt = PyBytes_AS_STRING(self->s_format); @@ -1273,9 +1269,8 @@ s = fmt; size = 0; len = 0; - ncodes = 0; while ((c = *s++) != '\0') { - if (Py_ISSPACE(Py_CHARMASK(c))) + if (isspace(Py_CHARMASK(c))) continue; if ('0' <= c && c <= '9') { num = c - '0'; @@ -1303,9 +1298,9 @@ switch (c) { case 's': /* fall through */ - case 'p': len++; ncodes++; break; + case 'p': len++; break; case 'x': break; - default: len += num; if (num) ncodes++; break; + default: len += num; break; } itemsize = e->size; @@ -1320,14 +1315,14 @@ } /* check for overflow */ - if ((ncodes + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) { + if ((len + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) { PyErr_NoMemory(); return -1; } self->s_size = size; self->s_len = len; - codes = PyMem_MALLOC((ncodes + 1) * sizeof(formatcode)); + codes = PyMem_MALLOC((len + 1) * sizeof(formatcode)); if (codes == NULL) { PyErr_NoMemory(); return -1; @@ -1340,7 +1335,7 @@ s = fmt; size = 0; while ((c = *s++) != '\0') { - if (Py_ISSPACE(Py_CHARMASK(c))) + if (isspace(Py_CHARMASK(c))) continue; if ('0' <= c && c <= '9') { num = c - '0'; @@ -1359,24 +1354,23 @@ codes->offset = size; codes->size = num; codes->fmtdef = e; - codes->repeat = 1; codes++; size += num; } else if (c == 'x') { size += num; - } else if (num) { - codes->offset = size; - codes->size = e->size; - codes->fmtdef = e; - codes->repeat = num; - codes++; - size += e->size * num; + } else { + while (--num >= 0) { + codes->offset = size; + codes->size = e->size; + codes->fmtdef = e; + codes++; + size += e->size; + } } } codes->fmtdef = NULL; codes->offset = size; codes->size = 0; - codes->repeat = 0; return 0; @@ -1465,26 +1459,22 @@ return NULL; for (code = soself->s_codes; code->fmtdef != NULL; code++) { + PyObject *v; const formatdef *e = code->fmtdef; const char *res = startfrom + code->offset; - Py_ssize_t j = code->repeat; - while (j--) { - PyObject *v; - if (e->format == 's') { - v = PyBytes_FromStringAndSize(res, code->size); - } else if (e->format == 'p') { - Py_ssize_t n = *(unsigned char*)res; - if (n >= code->size) - n = code->size - 1; - v = PyBytes_FromStringAndSize(res + 1, n); - } else { - v = e->unpack(res, e); - } - if (v == NULL) - goto fail; - PyTuple_SET_ITEM(result, i++, v); - res += code->size; + if (e->format == 's') { + v = PyBytes_FromStringAndSize(res, code->size); + } else if (e->format == 'p') { + Py_ssize_t n = *(unsigned char*)res; + if (n >= code->size) + n = code->size - 1; + v = PyBytes_FromStringAndSize(res + 1, n); + } else { + v = e->unpack(res, e); } + if (v == NULL) + goto fail; + PyTuple_SET_ITEM(result, i++, v); } return result; @@ -1566,142 +1556,6 @@ } -/* Unpack iterator type */ - -typedef struct { - PyObject_HEAD - PyStructObject *so; - Py_buffer buf; - Py_ssize_t index; -} unpackiterobject; - -static void -unpackiter_dealloc(unpackiterobject *self) -{ - Py_XDECREF(self->so); - PyBuffer_Release(&self->buf); - PyObject_GC_Del(self); -} - -static int -unpackiter_traverse(unpackiterobject *self, visitproc visit, void *arg) -{ - Py_VISIT(self->so); - Py_VISIT(self->buf.obj); - return 0; -} - -static PyObject * -unpackiter_len(unpackiterobject *self) -{ - Py_ssize_t len; - if (self->so == NULL) - len = 0; - else - len = (self->buf.len - self->index) / self->so->s_size; - return PyLong_FromSsize_t(len); -} - -static PyMethodDef unpackiter_methods[] = { - {"__length_hint__", (PyCFunction) unpackiter_len, METH_NOARGS, NULL}, - {NULL, NULL} /* sentinel */ -}; - -static PyObject * -unpackiter_iternext(unpackiterobject *self) -{ - PyObject *result; - if (self->so == NULL) - return NULL; - if (self->index >= self->buf.len) { - /* Iterator exhausted */ - Py_CLEAR(self->so); - PyBuffer_Release(&self->buf); - return NULL; - } - assert(self->index + self->so->s_size <= self->buf.len); - result = s_unpack_internal(self->so, - (char*) self->buf.buf + self->index); - self->index += self->so->s_size; - return result; -} - -PyTypeObject unpackiter_type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "unpack_iterator", /* tp_name */ - sizeof(unpackiterobject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)unpackiter_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - 0, /* tp_doc */ - (traverseproc)unpackiter_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ - (iternextfunc)unpackiter_iternext, /* tp_iternext */ - unpackiter_methods /* tp_methods */ -}; - -PyDoc_STRVAR(s_iter_unpack__doc__, -"S.iter_unpack(buffer) -> iterator(v1, v2, ...)\n\ -\n\ -Return an iterator yielding tuples unpacked from the given bytes\n\ -source, like a repeated invocation of unpack_from(). Requires\n\ -that the bytes length be a multiple of the struct size."); - -static PyObject * -s_iter_unpack(PyObject *_so, PyObject *input) -{ - PyStructObject *so = (PyStructObject *) _so; - unpackiterobject *self; - - assert(PyStruct_Check(_so)); - assert(so->s_codes != NULL); - - if (so->s_size == 0) { - PyErr_Format(StructError, - "cannot iteratively unpack with a struct of length 0"); - return NULL; - } - - self = (unpackiterobject *) PyType_GenericAlloc(&unpackiter_type, 0); - if (self == NULL) - return NULL; - - if (PyObject_GetBuffer(input, &self->buf, PyBUF_SIMPLE) < 0) { - Py_DECREF(self); - return NULL; - } - if (self->buf.len % so->s_size != 0) { - PyErr_Format(StructError, - "iterative unpacking requires a bytes length " - "multiple of %zd", - so->s_size); - Py_DECREF(self); - return NULL; - } - Py_INCREF(so); - self->so = so; - self->index = 0; - return (PyObject *) self; -} - - /* * Guts of the pack function. * @@ -1723,67 +1577,62 @@ memset(buf, '\0', soself->s_size); i = offset; for (code = soself->s_codes; code->fmtdef != NULL; code++) { + Py_ssize_t n; + PyObject *v = PyTuple_GET_ITEM(args, i++); const formatdef *e = code->fmtdef; char *res = buf + code->offset; - Py_ssize_t j = code->repeat; - while (j--) { - PyObject *v = PyTuple_GET_ITEM(args, i++); - if (e->format == 's') { - Py_ssize_t n; - int isstring; - void *p; - isstring = PyBytes_Check(v); - if (!isstring && !PyByteArray_Check(v)) { + if (e->format == 's') { + int isstring; + void *p; + isstring = PyBytes_Check(v); + if (!isstring && !PyByteArray_Check(v)) { + PyErr_SetString(StructError, + "argument for 's' must be a bytes object"); + return -1; + } + if (isstring) { + n = PyBytes_GET_SIZE(v); + p = PyBytes_AS_STRING(v); + } + else { + n = PyByteArray_GET_SIZE(v); + p = PyByteArray_AS_STRING(v); + } + if (n > code->size) + n = code->size; + if (n > 0) + memcpy(res, p, n); + } else if (e->format == 'p') { + int isstring; + void *p; + isstring = PyBytes_Check(v); + if (!isstring && !PyByteArray_Check(v)) { + PyErr_SetString(StructError, + "argument for 'p' must be a bytes object"); + return -1; + } + if (isstring) { + n = PyBytes_GET_SIZE(v); + p = PyBytes_AS_STRING(v); + } + else { + n = PyByteArray_GET_SIZE(v); + p = PyByteArray_AS_STRING(v); + } + if (n > (code->size - 1)) + n = code->size - 1; + if (n > 0) + memcpy(res + 1, p, n); + if (n > 255) + n = 255; + *res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char); + } else { + if (e->pack(res, v, e) < 0) { + if (PyLong_Check(v) && PyErr_ExceptionMatches(PyExc_OverflowError)) PyErr_SetString(StructError, - "argument for 's' must be a bytes object"); - return -1; - } - if (isstring) { - n = PyBytes_GET_SIZE(v); - p = PyBytes_AS_STRING(v); - } - else { - n = PyByteArray_GET_SIZE(v); - p = PyByteArray_AS_STRING(v); - } - if (n > code->size) - n = code->size; - if (n > 0) - memcpy(res, p, n); - } else if (e->format == 'p') { - Py_ssize_t n; - int isstring; - void *p; - isstring = PyBytes_Check(v); - if (!isstring && !PyByteArray_Check(v)) { - PyErr_SetString(StructError, - "argument for 'p' must be a bytes object"); - return -1; - } - if (isstring) { - n = PyBytes_GET_SIZE(v); - p = PyBytes_AS_STRING(v); - } - else { - n = PyByteArray_GET_SIZE(v); - p = PyByteArray_AS_STRING(v); - } - if (n > (code->size - 1)) - n = code->size - 1; - if (n > 0) - memcpy(res + 1, p, n); - if (n > 255) - n = 255; - *res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char); - } else { - if (e->pack(res, v, e) < 0) { - if (PyLong_Check(v) && PyErr_ExceptionMatches(PyExc_OverflowError)) - PyErr_SetString(StructError, - "long too large to convert to int"); - return -1; - } + "long too large to convert to int"); + return -1; } - res += code->size; } } @@ -1919,18 +1768,14 @@ s_sizeof(PyStructObject *self, void *unused) { Py_ssize_t size; - formatcode *code; - size = sizeof(PyStructObject) + sizeof(formatcode); - for (code = self->s_codes; code->fmtdef != NULL; code++) - size += sizeof(formatcode); + size = sizeof(PyStructObject) + sizeof(formatcode) * (self->s_len + 1); return PyLong_FromSsize_t(size); } /* List of functions */ static struct PyMethodDef s_methods[] = { - {"iter_unpack", s_iter_unpack, METH_O, s_iter_unpack__doc__}, {"pack", s_pack, METH_VARARGS, s_pack__doc__}, {"pack_into", s_pack_into, METH_VARARGS, s_pack_into__doc__}, {"unpack", s_unpack, METH_O, s_unpack__doc__}, @@ -2180,34 +2025,9 @@ return result; } -PyDoc_STRVAR(iter_unpack_doc, -"iter_unpack(fmt, buffer) -> iterator(v1, v2, ...)\n\ -\n\ -Return an iterator yielding tuples unpacked from the given bytes\n\ -source according to the format string, like a repeated invocation of\n\ -unpack_from(). Requires that the bytes length be a multiple of the\n\ -format struct size."); - -static PyObject * -iter_unpack(PyObject *self, PyObject *args) -{ - PyObject *s_object, *fmt, *input, *result; - - if (!PyArg_ParseTuple(args, "OO:iter_unpack", &fmt, &input)) - return NULL; - - s_object = cache_struct(fmt); - if (s_object == NULL) - return NULL; - result = s_iter_unpack(s_object, input); - Py_DECREF(s_object); - return result; -} - static struct PyMethodDef module_functions[] = { {"_clearcache", (PyCFunction)clearcache, METH_NOARGS, clearcache_doc}, {"calcsize", calcsize, METH_O, calcsize_doc}, - {"iter_unpack", iter_unpack, METH_VARARGS, iter_unpack_doc}, {"pack", pack, METH_VARARGS, pack_doc}, {"pack_into", pack_into, METH_VARARGS, pack_into_doc}, {"unpack", unpack, METH_VARARGS, unpack_doc}, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_testbuffer.c --- a/Modules/_testbuffer.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_testbuffer.c Fri Feb 01 23:12:09 2013 +0100 @@ -2837,36 +2837,36 @@ if (simple_format == NULL) return NULL; - PyModule_AddIntMacro(m, ND_MAX_NDIM); - PyModule_AddIntMacro(m, ND_VAREXPORT); - PyModule_AddIntMacro(m, ND_WRITABLE); - PyModule_AddIntMacro(m, ND_FORTRAN); - PyModule_AddIntMacro(m, ND_SCALAR); - PyModule_AddIntMacro(m, ND_PIL); - PyModule_AddIntMacro(m, ND_GETBUF_FAIL); - PyModule_AddIntMacro(m, ND_GETBUF_UNDEFINED); - PyModule_AddIntMacro(m, ND_REDIRECT); - - PyModule_AddIntMacro(m, PyBUF_SIMPLE); - PyModule_AddIntMacro(m, PyBUF_WRITABLE); - PyModule_AddIntMacro(m, PyBUF_FORMAT); - PyModule_AddIntMacro(m, PyBUF_ND); - PyModule_AddIntMacro(m, PyBUF_STRIDES); - PyModule_AddIntMacro(m, PyBUF_INDIRECT); - PyModule_AddIntMacro(m, PyBUF_C_CONTIGUOUS); - PyModule_AddIntMacro(m, PyBUF_F_CONTIGUOUS); - PyModule_AddIntMacro(m, PyBUF_ANY_CONTIGUOUS); - PyModule_AddIntMacro(m, PyBUF_FULL); - PyModule_AddIntMacro(m, PyBUF_FULL_RO); - PyModule_AddIntMacro(m, PyBUF_RECORDS); - PyModule_AddIntMacro(m, PyBUF_RECORDS_RO); - PyModule_AddIntMacro(m, PyBUF_STRIDED); - PyModule_AddIntMacro(m, PyBUF_STRIDED_RO); - PyModule_AddIntMacro(m, PyBUF_CONTIG); - PyModule_AddIntMacro(m, PyBUF_CONTIG_RO); - - PyModule_AddIntMacro(m, PyBUF_READ); - PyModule_AddIntMacro(m, PyBUF_WRITE); + PyModule_AddIntConstant(m, "ND_MAX_NDIM", ND_MAX_NDIM); + PyModule_AddIntConstant(m, "ND_VAREXPORT", ND_VAREXPORT); + PyModule_AddIntConstant(m, "ND_WRITABLE", ND_WRITABLE); + PyModule_AddIntConstant(m, "ND_FORTRAN", ND_FORTRAN); + PyModule_AddIntConstant(m, "ND_SCALAR", ND_SCALAR); + PyModule_AddIntConstant(m, "ND_PIL", ND_PIL); + PyModule_AddIntConstant(m, "ND_GETBUF_FAIL", ND_GETBUF_FAIL); + PyModule_AddIntConstant(m, "ND_GETBUF_UNDEFINED", ND_GETBUF_UNDEFINED); + PyModule_AddIntConstant(m, "ND_REDIRECT", ND_REDIRECT); + + PyModule_AddIntConstant(m, "PyBUF_SIMPLE", PyBUF_SIMPLE); + PyModule_AddIntConstant(m, "PyBUF_WRITABLE", PyBUF_WRITABLE); + PyModule_AddIntConstant(m, "PyBUF_FORMAT", PyBUF_FORMAT); + PyModule_AddIntConstant(m, "PyBUF_ND", PyBUF_ND); + PyModule_AddIntConstant(m, "PyBUF_STRIDES", PyBUF_STRIDES); + PyModule_AddIntConstant(m, "PyBUF_INDIRECT", PyBUF_INDIRECT); + PyModule_AddIntConstant(m, "PyBUF_C_CONTIGUOUS", PyBUF_C_CONTIGUOUS); + PyModule_AddIntConstant(m, "PyBUF_F_CONTIGUOUS", PyBUF_F_CONTIGUOUS); + PyModule_AddIntConstant(m, "PyBUF_ANY_CONTIGUOUS", PyBUF_ANY_CONTIGUOUS); + PyModule_AddIntConstant(m, "PyBUF_FULL", PyBUF_FULL); + PyModule_AddIntConstant(m, "PyBUF_FULL_RO", PyBUF_FULL_RO); + PyModule_AddIntConstant(m, "PyBUF_RECORDS", PyBUF_RECORDS); + PyModule_AddIntConstant(m, "PyBUF_RECORDS_RO", PyBUF_RECORDS_RO); + PyModule_AddIntConstant(m, "PyBUF_STRIDED", PyBUF_STRIDED); + PyModule_AddIntConstant(m, "PyBUF_STRIDED_RO", PyBUF_STRIDED_RO); + PyModule_AddIntConstant(m, "PyBUF_CONTIG", PyBUF_CONTIG); + PyModule_AddIntConstant(m, "PyBUF_CONTIG_RO", PyBUF_CONTIG_RO); + + PyModule_AddIntConstant(m, "PyBUF_READ", PyBUF_READ); + PyModule_AddIntConstant(m, "PyBUF_WRITE", PyBUF_WRITE); return m; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_testcapimodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -120,13 +120,7 @@ for (i = 0; i < count; i++) { v = PyLong_FromLong(i); - if (v == NULL) { - return -1; - } - if (PyDict_SetItem(dict, v, v) < 0) { - Py_DECREF(v); - return -1; - } + PyDict_SetItem(dict, v, v); Py_DECREF(v); } @@ -1424,20 +1418,6 @@ else return raiseTestError("test_widechar", "PyUnicode_FromUnicode(L\"\\U00110000\", 1) didn't fail"); - - wide = PyUnicode_FromUnicode(NULL, 1); - if (wide == NULL) - return NULL; - PyUnicode_AS_UNICODE(wide)[0] = invalid[0]; - if (_PyUnicode_Ready(wide) < 0) { - Py_DECREF(wide); - PyErr_Clear(); - } - else { - Py_DECREF(wide); - return raiseTestError("test_widechar", - "PyUnicode_Ready() didn't fail"); - } #endif Py_RETURN_NONE; @@ -1658,15 +1638,9 @@ int i; for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) { - size_t nbits; - int sign; - PyObject *plong; - - plong = PyLong_FromLong(testcases[i].input); - if (plong == NULL) - return NULL; - nbits = _PyLong_NumBits(plong); - sign = _PyLong_Sign(plong); + PyObject *plong = PyLong_FromLong(testcases[i].input); + size_t nbits = _PyLong_NumBits(plong); + int sign = _PyLong_Sign(plong); Py_DECREF(plong); if (nbits != testcases[i].nbits) @@ -2200,8 +2174,6 @@ /* Test 3: Allocate a few integers, then release them all simultaneously. */ multiple = malloc(sizeof(PyObject*) * 1000); - if (multiple == NULL) - return PyErr_NoMemory(); gettimeofday(&start, NULL); for(k=0; k < 20000; k++) { for(i=0; i < 1000; i++) { @@ -2213,13 +2185,10 @@ } gettimeofday(&stop, NULL); print_delta(3, &start, &stop); - free(multiple); /* Test 4: Allocate many integers, then release them all simultaneously. */ multiple = malloc(sizeof(PyObject*) * 1000000); - if (multiple == NULL) - return PyErr_NoMemory(); gettimeofday(&start, NULL); for(k=0; k < 20; k++) { for(i=0; i < 1000000; i++) { @@ -2231,12 +2200,9 @@ } gettimeofday(&stop, NULL); print_delta(4, &start, &stop); - free(multiple); /* Test 5: Allocate many integers < 32000 */ multiple = malloc(sizeof(PyObject*) * 1000000); - if (multiple == NULL) - return PyErr_NoMemory(); gettimeofday(&start, NULL); for(k=0; k < 10; k++) { for(i=0; i < 1000000; i++) { @@ -2248,7 +2214,6 @@ } gettimeofday(&stop, NULL); print_delta(5, &start, &stop); - free(multiple); /* Test 6: Perform small int addition */ op1 = PyLong_FromLong(1); @@ -2263,12 +2228,10 @@ /* Test 7: Perform medium int addition */ op1 = PyLong_FromLong(1000); - if (op1 == NULL) - return NULL; gettimeofday(&start, NULL); for(i=0; i < 10000000; i++) { result = PyNumber_Add(op1, op1); - Py_XDECREF(result); + Py_DECREF(result); } gettimeofday(&stop, NULL); Py_DECREF(op1); @@ -2491,203 +2454,6 @@ return Py_BuildValue("Nl", _PyLong_FromTime_t(sec), nsec); } -static PyObject * -_test_incref(PyObject *ob) -{ - Py_INCREF(ob); - return ob; -} - -static PyObject * -test_xincref_doesnt_leak(PyObject *ob) -{ - PyObject *obj = PyLong_FromLong(0); - Py_XINCREF(_test_incref(obj)); - Py_DECREF(obj); - Py_DECREF(obj); - Py_DECREF(obj); - Py_RETURN_NONE; -} - -static PyObject * -test_incref_doesnt_leak(PyObject *ob) -{ - PyObject *obj = PyLong_FromLong(0); - Py_INCREF(_test_incref(obj)); - Py_DECREF(obj); - Py_DECREF(obj); - Py_DECREF(obj); - Py_RETURN_NONE; -} - -static PyObject * -test_xdecref_doesnt_leak(PyObject *ob) -{ - Py_XDECREF(PyLong_FromLong(0)); - Py_RETURN_NONE; -} - -static PyObject * -test_decref_doesnt_leak(PyObject *ob) -{ - Py_DECREF(PyLong_FromLong(0)); - Py_RETURN_NONE; -} - -static PyObject * -test_pymem_alloc0(PyObject *self) -{ - void *ptr; - - ptr = PyMem_Malloc(0); - if (ptr == NULL) { - PyErr_SetString(PyExc_RuntimeError, "PyMem_Malloc(0) returns NULL"); - return NULL; - } - PyMem_Free(ptr); - - ptr = PyObject_Malloc(0); - if (ptr == NULL) { - PyErr_SetString(PyExc_RuntimeError, "PyObject_Malloc(0) returns NULL"); - return NULL; - } - PyObject_Free(ptr); - - Py_RETURN_NONE; -} - -typedef struct { - PyMemAllocator alloc; - - size_t malloc_size; - void *realloc_ptr; - size_t realloc_new_size; - void *free_ptr; -} alloc_hook_t; - -static void* hook_malloc (void* ctx, size_t size) -{ - alloc_hook_t *hook = (alloc_hook_t *)ctx; - hook->malloc_size = size; - return hook->alloc.malloc(hook->alloc.ctx, size); -} - -static void* hook_realloc (void* ctx, void* ptr, size_t new_size) -{ - alloc_hook_t *hook = (alloc_hook_t *)ctx; - hook->realloc_ptr = ptr; - hook->realloc_new_size = new_size; - return hook->alloc.realloc(hook->alloc.ctx, ptr, new_size); -} - -static void hook_free (void *ctx, void *ptr) -{ - alloc_hook_t *hook = (alloc_hook_t *)ctx; - hook->free_ptr = ptr; - hook->alloc.free(hook->alloc.ctx, ptr); -} - -static PyObject * -test_setallocators(PyMemAllocatorDomain domain) -{ - PyObject *res = NULL; - const char *error_msg; - alloc_hook_t hook; - PyMemAllocator alloc; - size_t size, size2; - void *ptr, *ptr2; - - hook.malloc_size = 0; - hook.realloc_ptr = NULL; - hook.realloc_new_size = 0; - hook.free_ptr = NULL; - - alloc.ctx = &hook; - alloc.malloc = &hook_malloc; - alloc.realloc = &hook_realloc; - alloc.free = &hook_free; - PyMem_GetAllocator(domain, &hook.alloc); - PyMem_SetAllocator(domain, &alloc); - - size = 42; - switch(domain) - { - case PYMEM_DOMAIN_RAW: ptr = PyMem_RawMalloc(size); break; - case PYMEM_DOMAIN_MEM: ptr = PyMem_Malloc(size); break; - case PYMEM_DOMAIN_OBJ: ptr = PyObject_Malloc(size); break; - default: ptr = NULL; break; - } - - if (ptr == NULL) { - error_msg = "malloc failed"; - goto fail; - } - - if (hook.malloc_size != size) { - error_msg = "malloc invalid size"; - goto fail; - } - - size2 = 200; - switch(domain) - { - case PYMEM_DOMAIN_RAW: ptr2 = PyMem_RawRealloc(ptr, size2); break; - case PYMEM_DOMAIN_MEM: ptr2 = PyMem_Realloc(ptr, size2); break; - case PYMEM_DOMAIN_OBJ: ptr2 = PyObject_Realloc(ptr, size2); break; - } - - if (ptr2 == NULL) { - error_msg = "realloc failed"; - goto fail; - } - - if (hook.realloc_ptr != ptr - || hook.realloc_new_size != size2) { - error_msg = "realloc invalid parameters"; - goto fail; - } - - switch(domain) - { - case PYMEM_DOMAIN_RAW: PyMem_RawFree(ptr2); break; - case PYMEM_DOMAIN_MEM: PyMem_Free(ptr2); break; - case PYMEM_DOMAIN_OBJ: PyObject_Free(ptr2); break; - } - - if (hook.free_ptr != ptr2) { - error_msg = "free invalid pointer"; - goto fail; - } - - Py_INCREF(Py_None); - res = Py_None; - goto finally; - -fail: - PyErr_SetString(PyExc_RuntimeError, error_msg); - -finally: - PyMem_SetAllocator(domain, &hook.alloc); - return res; -} - -static PyObject * -test_pymem_setrawallocators(PyObject *self) -{ - return test_setallocators(PYMEM_DOMAIN_RAW); -} - -static PyObject * -test_pymem_setallocators(PyObject *self) -{ - return test_setallocators(PYMEM_DOMAIN_MEM); -} - -static PyObject * -test_pyobject_setallocators(PyObject *self) -{ - return test_setallocators(PYMEM_DOMAIN_OBJ); -} static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, @@ -2698,10 +2464,6 @@ {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS}, {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, - {"test_xincref_doesnt_leak",(PyCFunction)test_xincref_doesnt_leak, METH_NOARGS}, - {"test_incref_doesnt_leak", (PyCFunction)test_incref_doesnt_leak, METH_NOARGS}, - {"test_xdecref_doesnt_leak",(PyCFunction)test_xdecref_doesnt_leak, METH_NOARGS}, - {"test_decref_doesnt_leak", (PyCFunction)test_decref_doesnt_leak, METH_NOARGS}, {"test_long_and_overflow", (PyCFunction)test_long_and_overflow, METH_NOARGS}, {"test_long_as_double", (PyCFunction)test_long_as_double,METH_NOARGS}, @@ -2789,14 +2551,6 @@ {"pytime_object_to_time_t", test_pytime_object_to_time_t, METH_VARARGS}, {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, - {"test_pymem", - (PyCFunction)test_pymem_alloc0, METH_NOARGS}, - {"test_pymem_alloc0", - (PyCFunction)test_pymem_setrawallocators, METH_NOARGS}, - {"test_pymem_setallocators", - (PyCFunction)test_pymem_setallocators, METH_NOARGS}, - {"test_pyobject_setallocators", - (PyCFunction)test_pyobject_setallocators, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_threadmodule.c --- a/Modules/_threadmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_threadmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -145,12 +145,12 @@ } PyDoc_STRVAR(acquire_doc, -"acquire([wait]) -> bool\n\ +"acquire([wait]) -> None or bool\n\ (acquire_lock() is an obsolete synonym)\n\ \n\ Lock the lock. Without argument, this blocks if the lock is already\n\ locked (even by the same thread), waiting for another thread to release\n\ -the lock, and return True once the lock is acquired.\n\ +the lock, and return None once the lock is acquired.\n\ With an argument, this will only block if the argument is true,\n\ and the return value reflects whether the lock is acquired.\n\ The blocking operation is interruptible."); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_tkinter.c --- a/Modules/_tkinter.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_tkinter.c Fri Feb 01 23:12:09 2013 +0100 @@ -423,21 +423,6 @@ return result; /* Fall through, returning arg. */ } - else if (PyUnicode_Check(arg)) { - int argc; - char **argv; - char *list = PyUnicode_AsUTF8(arg); - - if (list == NULL || - Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { - Py_INCREF(arg); - return arg; - } - Tcl_Free(FREECAST argv); - if (argc > 1) - return Split(list); - /* Fall through, returning arg. */ - } else if (PyBytes_Check(arg)) { int argc; char **argv; @@ -885,7 +870,7 @@ #if TCL_UTF_MAX == 3 if (ch >= 0x10000) { /* Tcl doesn't do UTF-16, yet. */ - PyErr_Format(Tkinter_TclError, + PyErr_Format(PyExc_ValueError, "character U+%x is above the range " "(U+0000-U+FFFF) allowed by Tcl", ch); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/_winapi.c --- a/Modules/_winapi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/_winapi.c Fri Feb 01 23:12:09 2013 +0100 @@ -62,8 +62,6 @@ #define T_HANDLE T_POINTER -#define DWORD_MAX 4294967295U - /* Grab CancelIoEx dynamically from kernel32 */ static int has_CancelIoEx = -1; static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); @@ -1144,7 +1142,7 @@ HANDLE handle; Py_buffer _buf, *buf; PyObject *bufobj; - DWORD len, written; + DWORD written; BOOL ret; int use_overlapped = 0; DWORD err; @@ -1172,8 +1170,7 @@ } Py_BEGIN_ALLOW_THREADS - len = (DWORD)Py_MIN(buf->len, DWORD_MAX); - ret = WriteFile(handle, buf->buf, len, &written, + ret = WriteFile(handle, buf->buf, buf->len, &written, overlapped ? &overlapped->overlapped : NULL); Py_END_ALLOW_THREADS diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/arraymodule.c --- a/Modules/arraymodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/arraymodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -968,13 +968,8 @@ Py_ssize_t i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *selfi; - int cmp; - - selfi = getarrayitem((PyObject *)self, i); - if (selfi == NULL) - return NULL; - cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); + PyObject *selfi = getarrayitem((PyObject *)self, i); + int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) count++; @@ -995,13 +990,8 @@ Py_ssize_t i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *selfi; - int cmp; - - selfi = getarrayitem((PyObject *)self, i); - if (selfi == NULL) - return NULL; - cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); + PyObject *selfi = getarrayitem((PyObject *)self, i); + int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) { return PyLong_FromLong((long)i); @@ -1026,8 +1016,6 @@ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(self); i++) { PyObject *selfi = getarrayitem((PyObject *)self, i); - if (selfi == NULL) - return -1; cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); } @@ -1040,13 +1028,8 @@ int i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *selfi; - int cmp; - - selfi = getarrayitem((PyObject *)self,i); - if (selfi == NULL) - return NULL; - cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); + PyObject *selfi = getarrayitem((PyObject *)self,i); + int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) { if (array_ass_slice(self, i, i+1, @@ -1085,9 +1068,7 @@ PyErr_SetString(PyExc_IndexError, "pop index out of range"); return NULL; } - v = getarrayitem((PyObject *)self, i); - if (v == NULL) - return NULL; + v = getarrayitem((PyObject *)self,i); if (array_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) { Py_DECREF(v); return NULL; @@ -1405,16 +1386,13 @@ return NULL; for (i = 0; i < Py_SIZE(self); i++) { PyObject *v = getarrayitem((PyObject *)self, i); - if (v == NULL) - goto error; - if (PyList_SetItem(list, i, v) < 0) - goto error; + if (v == NULL) { + Py_DECREF(list); + return NULL; + } + PyList_SetItem(list, i, v); } return list; - -error: - Py_DECREF(list); - return NULL; } PyDoc_STRVAR(tolist_doc, @@ -2199,8 +2177,6 @@ } else { v = array_tolist(a, NULL); } - if (v == NULL) - return NULL; s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v); Py_DECREF(v); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/audioop.c --- a/Modules/audioop.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/audioop.c Fri Feb 01 23:12:09 2013 +0100 @@ -26,21 +26,6 @@ #endif #endif -static const int maxvals[] = {0, 0x7F, 0x7FFF, 0x7FFFFF, 0x7FFFFFFF}; -static const int minvals[] = {0, -0x80, -0x8000, -0x800000, -0x80000000}; -static const unsigned int masks[] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF}; - -static int -fbound(double val, double minval, double maxval) -{ - if (val > maxval) - val = maxval; - else if (val < minval + 1) - val = minval; - return (int)val; -} - - /* Code shamelessly stolen from sox, 12.17.7, g711.c ** (c) Craig Reese, Joe Campbell and Jeff Poskanzer 1989 */ @@ -362,7 +347,7 @@ signed char *cp; Py_ssize_t len, i; int size, val = 0; - unsigned int absval, max = 0; + int max = 0; if ( !PyArg_ParseTuple(args, "s#i:max", &cp, &len, &size) ) return 0; @@ -372,11 +357,10 @@ if ( size == 1 ) val = (int)*CHARP(cp, i); else if ( size == 2 ) val = (int)*SHORTP(cp, i); else if ( size == 4 ) val = (int)*LONGP(cp, i); - if (val < 0) absval = (-val); - else absval = val; - if (absval > max) max = absval; + if ( val < 0 ) val = (-val); + if ( val > max ) max = val; } - return PyLong_FromUnsignedLong(max); + return PyLong_FromLong(max); } static PyObject * @@ -385,7 +369,7 @@ signed char *cp; Py_ssize_t len, i; int size, val = 0; - int min = 0x7fffffff, max = -0x80000000; + int min = 0x7fffffff, max = -0x7fffffff; if (!PyArg_ParseTuple(args, "s#i:minmax", &cp, &len, &size)) return NULL; @@ -422,7 +406,7 @@ if ( len == 0 ) val = 0; else - val = (int)floor(avg / (double)(len/size)); + val = (int)(avg / (double)(len/size)); return PyLong_FromLong(val); } @@ -432,7 +416,6 @@ signed char *cp; Py_ssize_t len, i; int size, val = 0; - unsigned int res; double sum_squares = 0.0; if ( !PyArg_ParseTuple(args, "s#i:rms", &cp, &len, &size) ) @@ -446,10 +429,10 @@ sum_squares += (double)val*(double)val; } if ( len == 0 ) - res = 0; + val = 0; else - res = (unsigned int)sqrt(sum_squares / (double)(len/size)); - return PyLong_FromUnsignedLong(res); + val = (int)sqrt(sum_squares / (double)(len/size)); + return PyLong_FromLong(val); } static double _sum2(short *a, short *b, Py_ssize_t len) @@ -639,46 +622,52 @@ Py_ssize_t len, i; int size, val = 0, prevval = 0, prevextremevalid = 0, prevextreme = 0; - double sum = 0.0; - unsigned int avg; - int diff, prevdiff, nextreme = 0; + double avg = 0.0; + int diff, prevdiff, extremediff, nextreme = 0; if ( !PyArg_ParseTuple(args, "s#i:avgpp", &cp, &len, &size) ) return 0; if (!audioop_check_parameters(len, size)) return NULL; - if (len <= size) - return PyLong_FromLong(0); + /* Compute first delta value ahead. Also automatically makes us + ** skip the first extreme value + */ if ( size == 1 ) prevval = (int)*CHARP(cp, 0); else if ( size == 2 ) prevval = (int)*SHORTP(cp, 0); else if ( size == 4 ) prevval = (int)*LONGP(cp, 0); - prevdiff = 17; /* Anything != 0, 1 */ + if ( size == 1 ) val = (int)*CHARP(cp, size); + else if ( size == 2 ) val = (int)*SHORTP(cp, size); + else if ( size == 4 ) val = (int)*LONGP(cp, size); + prevdiff = val - prevval; + for ( i=size; i max ) - max = extremediff; - } - prevextremevalid = 1; - prevextreme = prevval; + diff = val - prevval; + if ( diff*prevdiff < 0 ) { + /* Derivative changed sign. Compute difference to + ** last extreme value and remember. + */ + if ( prevextremevalid ) { + extremediff = prevval - prevextreme; + if ( extremediff < 0 ) + extremediff = -extremediff; + if ( extremediff > max ) + max = extremediff; } - prevval = val; + prevextremevalid = 1; + prevextreme = prevval; + } + prevval = val; + if ( diff != 0 ) prevdiff = diff; - } } - return PyLong_FromUnsignedLong(max); + return PyLong_FromLong(max); } static PyObject * @@ -763,7 +753,7 @@ signed char *cp, *ncp; Py_ssize_t len, i; int size, val = 0; - double factor, fval, maxval, minval; + double factor, fval, maxval; PyObject *rv; if ( !PyArg_ParseTuple(args, "s#id:mul", &cp, &len, &size, &factor ) ) @@ -771,8 +761,13 @@ if (!audioop_check_parameters(len, size)) return NULL; - maxval = (double) maxvals[size]; - minval = (double) minvals[size]; + if ( size == 1 ) maxval = (double) 0x7f; + else if ( size == 2 ) maxval = (double) 0x7fff; + else if ( size == 4 ) maxval = (double) 0x7fffffff; + else { + PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); + return 0; + } rv = PyBytes_FromStringAndSize(NULL, len); if ( rv == 0 ) @@ -785,7 +780,9 @@ else if ( size == 2 ) val = (int)*SHORTP(cp, i); else if ( size == 4 ) val = (int)*LONGP(cp, i); fval = (double)val*factor; - val = (int)floor(fbound(fval, minval, maxval)); + if ( fval > maxval ) fval = maxval; + else if ( fval < -maxval ) fval = -maxval; + val = (int)fval; if ( size == 1 ) *CHARP(ncp, i) = (signed char)val; else if ( size == 2 ) *SHORTP(ncp, i) = (short)val; else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)val; @@ -800,7 +797,7 @@ signed char *cp, *ncp; Py_ssize_t len, i; int size, val1 = 0, val2 = 0; - double fac1, fac2, fval, maxval, minval; + double fac1, fac2, fval, maxval; PyObject *rv; if ( !PyArg_ParseTuple(args, "s*idd:tomono", @@ -818,8 +815,14 @@ return NULL; } - maxval = (double) maxvals[size]; - minval = (double) minvals[size]; + if ( size == 1 ) maxval = (double) 0x7f; + else if ( size == 2 ) maxval = (double) 0x7fff; + else if ( size == 4 ) maxval = (double) 0x7fffffff; + else { + PyBuffer_Release(&pcp); + PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); + return 0; + } rv = PyBytes_FromStringAndSize(NULL, len/2); if ( rv == 0 ) { @@ -837,7 +840,9 @@ else if ( size == 2 ) val2 = (int)*SHORTP(cp, i+2); else if ( size == 4 ) val2 = (int)*LONGP(cp, i+4); fval = (double)val1*fac1 + (double)val2*fac2; - val1 = (int)floor(fbound(fval, minval, maxval)); + if ( fval > maxval ) fval = maxval; + else if ( fval < -maxval ) fval = -maxval; + val1 = (int)fval; if ( size == 1 ) *CHARP(ncp, i/2) = (signed char)val1; else if ( size == 2 ) *SHORTP(ncp, i/2) = (short)val1; else if ( size == 4 ) *LONGP(ncp, i/2)= (Py_Int32)val1; @@ -852,7 +857,7 @@ signed char *cp, *ncp; Py_ssize_t len, i; int size, val1, val2, val = 0; - double fac1, fac2, fval, maxval, minval; + double fac1, fac2, fval, maxval; PyObject *rv; if ( !PyArg_ParseTuple(args, "s#idd:tostereo", @@ -861,8 +866,13 @@ if (!audioop_check_parameters(len, size)) return NULL; - maxval = (double) maxvals[size]; - minval = (double) minvals[size]; + if ( size == 1 ) maxval = (double) 0x7f; + else if ( size == 2 ) maxval = (double) 0x7fff; + else if ( size == 4 ) maxval = (double) 0x7fffffff; + else { + PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); + return 0; + } if (len > PY_SSIZE_T_MAX/2) { PyErr_SetString(PyExc_MemoryError, @@ -882,10 +892,14 @@ else if ( size == 4 ) val = (int)*LONGP(cp, i); fval = (double)val*fac1; - val1 = (int)floor(fbound(fval, minval, maxval)); + if ( fval > maxval ) fval = maxval; + else if ( fval < -maxval ) fval = -maxval; + val1 = (int)fval; fval = (double)val*fac2; - val2 = (int)floor(fbound(fval, minval, maxval)); + if ( fval > maxval ) fval = maxval; + else if ( fval < -maxval ) fval = -maxval; + val2 = (int)fval; if ( size == 1 ) *CHARP(ncp, i*2) = (signed char)val1; else if ( size == 2 ) *SHORTP(ncp, i*2) = (short)val1; @@ -903,7 +917,7 @@ { signed char *cp1, *cp2, *ncp; Py_ssize_t len1, len2, i; - int size, val1 = 0, val2 = 0, minval, maxval, newval; + int size, val1 = 0, val2 = 0, maxval, newval; PyObject *rv; if ( !PyArg_ParseTuple(args, "s#s#i:add", @@ -916,8 +930,13 @@ return 0; } - maxval = maxvals[size]; - minval = minvals[size]; + if ( size == 1 ) maxval = 0x7f; + else if ( size == 2 ) maxval = 0x7fff; + else if ( size == 4 ) maxval = 0x7fffffff; + else { + PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); + return 0; + } rv = PyBytes_FromStringAndSize(NULL, len1); if ( rv == 0 ) @@ -933,19 +952,12 @@ else if ( size == 2 ) val2 = (int)*SHORTP(cp2, i); else if ( size == 4 ) val2 = (int)*LONGP(cp2, i); - if (size < 4) { - newval = val1 + val2; - /* truncate in case of overflow */ - if (newval > maxval) - newval = maxval; - else if (newval < minval) - newval = minval; - } - else { - double fval = (double)val1 + (double)val2; - /* truncate in case of overflow */ - newval = (int)floor(fbound(fval, minval, maxval)); - } + newval = val1 + val2; + /* truncate in case of overflow */ + if (newval > maxval) newval = maxval; + else if (newval < -maxval) newval = -maxval; + else if (size == 4 && (newval^val1) < 0 && (newval^val2) < 0) + newval = val1 > 0 ? maxval : - maxval; if ( size == 1 ) *CHARP(ncp, i) = (signed char)newval; else if ( size == 2 ) *SHORTP(ncp, i) = (short)newval; @@ -959,9 +971,9 @@ { signed char *cp, *ncp; Py_ssize_t len, i; - int size, bias; - unsigned int val = 0, mask; + int size, val = 0; PyObject *rv; + int bias; if ( !PyArg_ParseTuple(args, "s#ii:bias", &cp, &len, &size , &bias) ) @@ -975,20 +987,15 @@ return 0; ncp = (signed char *)PyBytes_AsString(rv); - mask = masks[size]; for ( i=0; i < len; i += size ) { - if ( size == 1 ) val = (unsigned int)(unsigned char)*CHARP(cp, i); - else if ( size == 2 ) val = (unsigned int)(unsigned short)*SHORTP(cp, i); - else if ( size == 4 ) val = (unsigned int)(Py_UInt32)*LONGP(cp, i); + if ( size == 1 ) val = (int)*CHARP(cp, i); + else if ( size == 2 ) val = (int)*SHORTP(cp, i); + else if ( size == 4 ) val = (int)*LONGP(cp, i); - val += (unsigned int)bias; - /* wrap around in case of overflow */ - val &= mask; - - if ( size == 1 ) *CHARP(ncp, i) = (signed char)(unsigned char)val; - else if ( size == 2 ) *SHORTP(ncp, i) = (short)(unsigned short)val; - else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(Py_UInt32)val; + if ( size == 1 ) *CHARP(ncp, i) = (signed char)(val+bias); + else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val+bias); + else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val+bias); } return rv; } @@ -1015,15 +1022,15 @@ ncp = (unsigned char *)PyBytes_AsString(rv); for ( i=0; i < len; i += size ) { - if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 24; - else if ( size == 2 ) val = ((int)*SHORTP(cp, i)) << 16; - else if ( size == 4 ) val = (int)*LONGP(cp, i); + if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8; + else if ( size == 2 ) val = (int)*SHORTP(cp, i); + else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16; j = len - i - size; - if ( size == 1 ) *CHARP(ncp, j) = (signed char)(val >> 24); - else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val >> 16); - else if ( size == 4 ) *LONGP(ncp, j) = (Py_Int32)val; + if ( size == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8); + else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val); + else if ( size == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16); } return rv; } @@ -1057,13 +1064,13 @@ ncp = (unsigned char *)PyBytes_AsString(rv); for ( i=0, j=0; i < len; i += size, j += size2 ) { - if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 24; - else if ( size == 2 ) val = ((int)*SHORTP(cp, i)) << 16; - else if ( size == 4 ) val = (int)*LONGP(cp, i); + if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8; + else if ( size == 2 ) val = (int)*SHORTP(cp, i); + else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16; - if ( size2 == 1 ) *CHARP(ncp, j) = (signed char)(val >> 24); - else if ( size2 == 2 ) *SHORTP(ncp, j) = (short)(val >> 16); - else if ( size2 == 4 ) *LONGP(ncp, j) = (Py_Int32)val; + if ( size2 == 1 ) *CHARP(ncp, j) = (signed char)(val >> 8); + else if ( size2 == 2 ) *SHORTP(ncp, j) = (short)(val); + else if ( size2 == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16); } return rv; } @@ -1127,18 +1134,14 @@ d = gcd(inrate, outrate); inrate /= d; outrate /= d; - /* divide weightA and weightB by their greatest common divisor */ - d = gcd(weightA, weightB); - weightA /= d; - weightA /= d; if ((size_t)nchannels > PY_SIZE_MAX/sizeof(int)) { PyErr_SetString(PyExc_MemoryError, "not enough memory for output buffer"); return 0; } - prev_i = (int *) PyMem_Malloc(nchannels * sizeof(int)); - cur_i = (int *) PyMem_Malloc(nchannels * sizeof(int)); + prev_i = (int *) malloc(nchannels * sizeof(int)); + cur_i = (int *) malloc(nchannels * sizeof(int)); if (prev_i == NULL || cur_i == NULL) { (void) PyErr_NoMemory(); goto exit; @@ -1170,9 +1173,7 @@ } /* str <- Space for the output buffer. */ - if (len == 0) - str = PyBytes_FromStringAndSize(NULL, 0); - else { + { /* There are len input frames, so we need (mathematically) ceiling(len*outrate/inrate) output frames, and each frame requires bytes_per_frame bytes. Computing this @@ -1187,11 +1188,12 @@ else str = PyBytes_FromStringAndSize(NULL, q * outrate * bytes_per_frame); - } - if (str == NULL) { - PyErr_SetString(PyExc_MemoryError, - "not enough memory for output buffer"); - goto exit; + + if (str == NULL) { + PyErr_SetString(PyExc_MemoryError, + "not enough memory for output buffer"); + goto exit; + } } ncp = PyBytes_AsString(str); @@ -1225,40 +1227,42 @@ for (chan = 0; chan < nchannels; chan++) { prev_i[chan] = cur_i[chan]; if (size == 1) - cur_i[chan] = ((int)*CHARP(cp, 0)) << 24; + cur_i[chan] = ((int)*CHARP(cp, 0)) << 8; else if (size == 2) - cur_i[chan] = ((int)*SHORTP(cp, 0)) << 16; + cur_i[chan] = (int)*SHORTP(cp, 0); else if (size == 4) - cur_i[chan] = (int)*LONGP(cp, 0); + cur_i[chan] = ((int)*LONGP(cp, 0)) >> 16; cp += size; /* implements a simple digital filter */ - cur_i[chan] = (int)( - ((double)weightA * (double)cur_i[chan] + - (double)weightB * (double)prev_i[chan]) / - ((double)weightA + (double)weightB)); + cur_i[chan] = + (weightA * cur_i[chan] + + weightB * prev_i[chan]) / + (weightA + weightB); } len--; d += outrate; } while (d >= 0) { for (chan = 0; chan < nchannels; chan++) { - cur_o = (int)(((double)prev_i[chan] * (double)d + - (double)cur_i[chan] * (double)(outrate - d)) / - (double)outrate); + cur_o = (prev_i[chan] * d + + cur_i[chan] * (outrate - d)) / + outrate; if (size == 1) - *CHARP(ncp, 0) = (signed char)(cur_o >> 24); + *CHARP(ncp, 0) = (signed char)(cur_o >> 8); else if (size == 2) - *SHORTP(ncp, 0) = (short)(cur_o >> 16); + *SHORTP(ncp, 0) = (short)(cur_o); else if (size == 4) - *LONGP(ncp, 0) = (Py_Int32)(cur_o); + *LONGP(ncp, 0) = (Py_Int32)(cur_o<<16); ncp += size; } d -= inrate; } } exit: - PyMem_Free(prev_i); - PyMem_Free(cur_i); + if (prev_i != NULL) + free(prev_i); + if (cur_i != NULL) + free(cur_i); return rv; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/binascii.c --- a/Modules/binascii.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/binascii.c Fri Feb 01 23:12:09 2013 +0100 @@ -361,7 +361,8 @@ if (_PyBytes_Resize(&rv, (ascii_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } PyBuffer_Release(&pbin); return rv; @@ -490,7 +491,8 @@ */ if (bin_len > 0) { if (_PyBytes_Resize(&rv, bin_len) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } } else { @@ -561,7 +563,8 @@ if (_PyBytes_Resize(&rv, (ascii_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } PyBuffer_Release(&pbuf); return rv; @@ -639,7 +642,8 @@ if (_PyBytes_Resize(&rv, (bin_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } if (rv) { PyObject *rrv = Py_BuildValue("Oi", rv, done); @@ -709,7 +713,8 @@ if (_PyBytes_Resize(&rv, (out_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } PyBuffer_Release(&pbuf); return rv; @@ -765,7 +770,8 @@ if (_PyBytes_Resize(&rv, (ascii_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } PyBuffer_Release(&pbin); return rv; @@ -828,7 +834,7 @@ if ( --out_len_left < 0 ) { \ if ( out_len > PY_SSIZE_T_MAX / 2) return PyErr_NoMemory(); \ if (_PyBytes_Resize(&rv, 2*out_len) < 0) \ - { Py_XDECREF(rv); PyBuffer_Release(&pin); return NULL; } \ + { Py_DECREF(rv); PyBuffer_Release(&pin); return NULL; } \ out_data = (unsigned char *)PyBytes_AS_STRING(rv) \ + out_len; \ out_len_left = out_len-1; \ @@ -881,7 +887,8 @@ if (_PyBytes_Resize(&rv, (out_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_CLEAR(rv); + Py_DECREF(rv); + rv = NULL; } PyBuffer_Release(&pin); return rv; @@ -1128,7 +1135,7 @@ static int to_int(int c) { - if (Py_ISDIGIT(c)) + if (isdigit(c)) return c - '0'; else { if (Py_ISUPPER(c)) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/_codecs_cn.c --- a/Modules/cjkcodecs/_codecs_cn.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/_codecs_cn.c Fri Feb 01 23:12:09 2013 +0100 @@ -23,12 +23,12 @@ * A844 undefined U+2015 HORIZONTAL BAR */ -#define GBK_DECODE(dc1, dc2, writer) \ - if ((dc1) == 0xa1 && (dc2) == 0xaa) OUTCHAR(0x2014); \ - else if ((dc1) == 0xa8 && (dc2) == 0x44) OUTCHAR(0x2015); \ - else if ((dc1) == 0xa1 && (dc2) == 0xa4) OUTCHAR(0x00b7); \ - else TRYMAP_DEC(gb2312, writer, dc1 ^ 0x80, dc2 ^ 0x80); \ - else TRYMAP_DEC(gbkext, writer, dc1, dc2); +#define GBK_DECODE(dc1, dc2, assi) \ + if ((dc1) == 0xa1 && (dc2) == 0xaa) (assi) = 0x2014; \ + else if ((dc1) == 0xa8 && (dc2) == 0x44) (assi) = 0x2015; \ + else if ((dc1) == 0xa1 && (dc2) == 0xa4) (assi) = 0x00b7; \ + else TRYMAP_DEC(gb2312, assi, dc1 ^ 0x80, dc2 ^ 0x80); \ + else TRYMAP_DEC(gbkext, assi, dc1, dc2); #define GBK_ENCODE(code, assi) \ if ((code) == 0x2014) (assi) = 0xa1aa; \ @@ -42,18 +42,16 @@ ENCODER(gb2312) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) TRYMAP_ENC(gbcommon, code, c); @@ -62,9 +60,9 @@ if (code & 0x8000) /* MSB set: GBK */ return 1; - OUTBYTE1((code >> 8) | 0x80) - OUTBYTE2((code & 0xFF) | 0x80) - NEXT(1, 2); + OUT1((code >> 8) | 0x80) + OUT2((code & 0xFF) | 0x80) + NEXT(1, 2) } return 0; @@ -75,15 +73,17 @@ while (inleft > 0) { unsigned char c = **inbuf; + REQUIRE_OUTBUF(1) + if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - TRYMAP_DEC(gb2312, writer, c ^ 0x80, INBYTE2 ^ 0x80) { - NEXT_IN(2); + TRYMAP_DEC(gb2312, **outbuf, c ^ 0x80, IN2 ^ 0x80) { + NEXT(2, 1) } else return 1; } @@ -98,30 +98,28 @@ ENCODER(gbk) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) GBK_ENCODE(c, code) else return 1; - OUTBYTE1((code >> 8) | 0x80) + OUT1((code >> 8) | 0x80) if (code & 0x8000) - OUTBYTE2((code & 0xFF)) /* MSB set: GBK */ + OUT2((code & 0xFF)) /* MSB set: GBK */ else - OUTBYTE2((code & 0xFF) | 0x80) /* MSB unset: GB2312 */ - NEXT(1, 2); + OUT2((code & 0xFF) | 0x80) /* MSB unset: GB2312 */ + NEXT(1, 2) } return 0; @@ -130,20 +128,22 @@ DECODER(gbk) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - GBK_DECODE(c, INBYTE2, writer) + GBK_DECODE(c, IN2, **outbuf) else return 1; - NEXT_IN(2); + NEXT(2, 1) } return 0; @@ -156,31 +156,41 @@ ENCODER(gb18030) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + ucs4_t c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1(c) - NEXT(1, 1); + WRITE1(c) + NEXT(1, 1) continue; } - if (c >= 0x10000) { - Py_UCS4 tc = c - 0x10000; - assert (c <= 0x10FFFF); + DECODE_SURROGATE(c) + if (c > 0x10FFFF) +#if Py_UNICODE_SIZE == 2 + return 2; /* surrogates pair */ +#else + return 1; +#endif + else if (c >= 0x10000) { + ucs4_t tc = c - 0x10000; REQUIRE_OUTBUF(4) - OUTBYTE4((unsigned char)(tc % 10) + 0x30) + OUT4((unsigned char)(tc % 10) + 0x30) tc /= 10; - OUTBYTE3((unsigned char)(tc % 126) + 0x81) + OUT3((unsigned char)(tc % 126) + 0x81) tc /= 126; - OUTBYTE2((unsigned char)(tc % 10) + 0x30) + OUT2((unsigned char)(tc % 10) + 0x30) tc /= 10; - OUTBYTE1((unsigned char)(tc + 0x90)) + OUT1((unsigned char)(tc + 0x90)) - NEXT(1, 4); +#if Py_UNICODE_SIZE == 2 + NEXT(2, 4) /* surrogates pair */ +#else + NEXT(1, 4) +#endif continue; } @@ -198,20 +208,20 @@ utrrange++) if (utrrange->first <= c && c <= utrrange->last) { - Py_UCS4 tc; + Py_UNICODE tc; tc = c - utrrange->first + utrrange->base; - OUTBYTE4((unsigned char)(tc % 10) + 0x30) + OUT4((unsigned char)(tc % 10) + 0x30) tc /= 10; - OUTBYTE3((unsigned char)(tc % 126) + 0x81) + OUT3((unsigned char)(tc % 126) + 0x81) tc /= 126; - OUTBYTE2((unsigned char)(tc % 10) + 0x30) + OUT2((unsigned char)(tc % 10) + 0x30) tc /= 10; - OUTBYTE1((unsigned char)tc + 0x81) + OUT1((unsigned char)tc + 0x81) - NEXT(1, 4); + NEXT(1, 4) break; } @@ -220,13 +230,13 @@ continue; } - OUTBYTE1((code >> 8) | 0x80) + OUT1((code >> 8) | 0x80) if (code & 0x8000) - OUTBYTE2((code & 0xFF)) /* MSB set: GBK or GB18030ext */ + OUT2((code & 0xFF)) /* MSB set: GBK or GB18030ext */ else - OUTBYTE2((code & 0xFF) | 0x80) /* MSB unset: GB2312 */ + OUT2((code & 0xFF) | 0x80) /* MSB unset: GB2312 */ - NEXT(1, 2); + NEXT(1, 2) } return 0; @@ -235,59 +245,61 @@ DECODER(gb18030) { while (inleft > 0) { - unsigned char c = INBYTE1, c2; + unsigned char c = IN1, c2; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; if (c2 >= 0x30 && c2 <= 0x39) { /* 4 bytes seq */ const struct _gb18030_to_unibmp_ranges *utr; unsigned char c3, c4; - Py_UCS4 lseq; + ucs4_t lseq; REQUIRE_INBUF(4) - c3 = INBYTE3; - c4 = INBYTE4; + c3 = IN3; + c4 = IN4; if (c < 0x81 || c3 < 0x81 || c4 < 0x30 || c4 > 0x39) return 1; c -= 0x81; c2 -= 0x30; c3 -= 0x81; c4 -= 0x30; if (c < 4) { /* U+0080 - U+FFFF */ - lseq = ((Py_UCS4)c * 10 + c2) * 1260 + - (Py_UCS4)c3 * 10 + c4; + lseq = ((ucs4_t)c * 10 + c2) * 1260 + + (ucs4_t)c3 * 10 + c4; if (lseq < 39420) { for (utr = gb18030_to_unibmp_ranges; lseq >= (utr + 1)->base; utr++) ; - OUTCHAR(utr->first - utr->base + lseq); - NEXT_IN(4); + OUT1(utr->first - utr->base + lseq) + NEXT(4, 1) continue; } } else if (c >= 15) { /* U+10000 - U+10FFFF */ - lseq = 0x10000 + (((Py_UCS4)c-15) * 10 + c2) - * 1260 + (Py_UCS4)c3 * 10 + c4; + lseq = 0x10000 + (((ucs4_t)c-15) * 10 + c2) + * 1260 + (ucs4_t)c3 * 10 + c4; if (lseq <= 0x10FFFF) { - OUTCHAR(lseq); - NEXT_IN(4); + WRITEUCS4(lseq); + NEXT_IN(4) continue; } } return 1; } - GBK_DECODE(c, c2, writer) - else TRYMAP_DEC(gb18030ext, writer, c, c2); + GBK_DECODE(c, c2, **outbuf) + else TRYMAP_DEC(gb18030ext, **outbuf, c, c2); else return 1; - NEXT_IN(2); + NEXT(2, 1) } return 0; @@ -307,34 +319,33 @@ ENCODER_RESET(hz) { if (state->i != 0) { - WRITEBYTE2('~', '}') + WRITE2('~', '}') state->i = 0; - NEXT_OUT(2); + NEXT_OUT(2) } return 0; } ENCODER(hz) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { if (state->i == 0) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) } else { - WRITEBYTE3('~', '}', (unsigned char)c) - NEXT(1, 3); + WRITE3('~', '}', (unsigned char)c) + NEXT(1, 3) state->i = 0; } continue; } - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) TRYMAP_ENC(gbcommon, code, c); else return 1; @@ -343,13 +354,13 @@ return 1; if (state->i == 0) { - WRITEBYTE4('~', '{', code >> 8, code & 0xff) - NEXT(1, 4); + WRITE4('~', '{', code >> 8, code & 0xff) + NEXT(1, 4) state->i = 1; } else { - WRITEBYTE2(code >> 8, code & 0xff) - NEXT(1, 2); + WRITE2(code >> 8, code & 0xff) + NEXT(1, 2) } } @@ -371,15 +382,15 @@ DECODER(hz) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; if (c == '~') { - unsigned char c2 = INBYTE2; + unsigned char c2 = IN2; REQUIRE_INBUF(2) if (c2 == '~') { - OUTCHAR('~'); - NEXT_IN(2); + WRITE1('~') + NEXT(2, 1) continue; } else if (c2 == '{' && state->i == 0) @@ -390,7 +401,7 @@ ; /* line-continuation */ else return 1; - NEXT_IN(2); + NEXT(2, 0); continue; } @@ -398,13 +409,14 @@ return 1; if (state->i == 0) { /* ASCII mode */ - OUTCHAR(c); - NEXT_IN(1); + WRITE1(c) + NEXT(1, 1) } else { /* GB mode */ REQUIRE_INBUF(2) - TRYMAP_DEC(gb2312, writer, c, INBYTE2) { - NEXT_IN(2); + REQUIRE_OUTBUF(1) + TRYMAP_DEC(gb2312, **outbuf, c, IN2) { + NEXT(2, 1) } else return 1; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/_codecs_hk.c --- a/Modules/cjkcodecs/_codecs_hk.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/_codecs_hk.c Fri Feb 01 23:12:09 2013 +0100 @@ -38,39 +38,35 @@ ENCODER(big5hkscs) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + ucs4_t c = **inbuf; DBCHAR code; Py_ssize_t insize; if (c < 0x80) { REQUIRE_OUTBUF(1) **outbuf = (unsigned char)c; - NEXT(1, 1); + NEXT(1, 1) continue; } - insize = 1; + DECODE_SURROGATE(c) + insize = GET_INSIZE(c); + REQUIRE_OUTBUF(2) if (c < 0x10000) { TRYMAP_ENC(big5hkscs_bmp, code, c) { if (code == MULTIC) { - Py_UCS4 c2; - if (inlen - *inpos >= 2) - c2 = INCHAR2; - else - c2 = 0; - - if (inlen - *inpos >= 2 && + if (inleft >= 2 && ((c & 0xffdf) == 0x00ca) && - ((c2 & 0xfff7) == 0x0304)) { + (((*inbuf)[1] & 0xfff7) == 0x0304)) { code = big5hkscs_pairenc_table[ ((c >> 4) | - (c2 >> 3)) & 3]; + ((*inbuf)[1] >> 3)) & 3]; insize = 2; } - else if (inlen - *inpos < 2 && + else if (inleft < 2 && !(flags & MBENC_FLUSH)) return MBERR_TOOFEW; else { @@ -93,9 +89,9 @@ else return insize; - OUTBYTE1(code >> 8) - OUTBYTE2(code & 0xFF) - NEXT(insize, 2); + OUT1(code >> 8) + OUT2(code & 0xFF) + NEXT(insize, 2) } return 0; @@ -106,31 +102,33 @@ DECODER(big5hkscs) { while (inleft > 0) { - unsigned char c = INBYTE1; - Py_UCS4 decoded; + unsigned char c = IN1; + ucs4_t decoded; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - if (0xc6 > c || c > 0xc8 || (c < 0xc7 && INBYTE2 < 0xa1)) { - TRYMAP_DEC(big5, writer, c, INBYTE2) { - NEXT_IN(2); + if (0xc6 > c || c > 0xc8 || (c < 0xc7 && IN2 < 0xa1)) { + TRYMAP_DEC(big5, **outbuf, c, IN2) { + NEXT(2, 1) continue; } } - TRYMAP_DEC_CHAR(big5hkscs, decoded, c, INBYTE2) + TRYMAP_DEC(big5hkscs, decoded, c, IN2) { - int s = BH2S(c, INBYTE2); + int s = BH2S(c, IN2); const unsigned char *hintbase; assert(0x87 <= c && c <= 0xfe); - assert(0x40 <= INBYTE2 && INBYTE2 <= 0xfe); + assert(0x40 <= IN2 && IN2 <= 0xfe); if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) { hintbase = big5hkscs_phint_0; @@ -148,25 +146,25 @@ return MBERR_INTERNAL; if (hintbase[s >> 3] & (1 << (s & 7))) { - OUTCHAR(decoded | 0x20000); - NEXT_IN(2); + WRITEUCS4(decoded | 0x20000) + NEXT_IN(2) } else { - OUTCHAR(decoded); - NEXT_IN(2); + OUT1(decoded) + NEXT(2, 1) } continue; } - switch ((c << 8) | INBYTE2) { - case 0x8862: OUTCHAR2(0x00ca, 0x0304); break; - case 0x8864: OUTCHAR2(0x00ca, 0x030c); break; - case 0x88a3: OUTCHAR2(0x00ea, 0x0304); break; - case 0x88a5: OUTCHAR2(0x00ea, 0x030c); break; + switch ((c << 8) | IN2) { + case 0x8862: WRITE2(0x00ca, 0x0304); break; + case 0x8864: WRITE2(0x00ca, 0x030c); break; + case 0x88a3: WRITE2(0x00ea, 0x0304); break; + case 0x88a5: WRITE2(0x00ea, 0x030c); break; default: return 1; } - NEXT_IN(2); /* all decoded codepoints are pairs, above. */ + NEXT(2, 2) /* all decoded codepoints are pairs, above. */ } return 0; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/_codecs_iso2022.c --- a/Modules/cjkcodecs/_codecs_iso2022.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/_codecs_iso2022.c Fri Feb 01 23:12:09 2013 +0100 @@ -102,8 +102,8 @@ /*-*- internal data structures -*-*/ typedef int (*iso2022_init_func)(void); -typedef Py_UCS4 (*iso2022_decode_func)(const unsigned char *data); -typedef DBCHAR (*iso2022_encode_func)(const Py_UCS4 *data, Py_ssize_t *length); +typedef ucs4_t (*iso2022_decode_func)(const unsigned char *data); +typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, Py_ssize_t *length); struct iso2022_designation { unsigned char mark; @@ -141,13 +141,13 @@ ENCODER_RESET(iso2022) { if (STATE_GETFLAG(F_SHIFTED)) { - WRITEBYTE1(SI) - NEXT_OUT(1); + WRITE1(SI) + NEXT_OUT(1) STATE_CLEARFLAG(F_SHIFTED) } if (STATE_G0 != CHARSET_ASCII) { - WRITEBYTE3(ESC, '(', 'B') - NEXT_OUT(3); + WRITE3(ESC, '(', 'B') + NEXT_OUT(3) STATE_SETG0(CHARSET_ASCII) } return 0; @@ -155,29 +155,30 @@ ENCODER(iso2022) { - while (*inpos < inlen) { + while (inleft > 0) { const struct iso2022_designation *dsg; DBCHAR encoded; - Py_UCS4 c = INCHAR1; + ucs4_t c = **inbuf; Py_ssize_t insize; if (c < 0x80) { if (STATE_G0 != CHARSET_ASCII) { - WRITEBYTE3(ESC, '(', 'B') + WRITE3(ESC, '(', 'B') STATE_SETG0(CHARSET_ASCII) - NEXT_OUT(3); + NEXT_OUT(3) } if (STATE_GETFLAG(F_SHIFTED)) { - WRITEBYTE1(SI) + WRITE1(SI) STATE_CLEARFLAG(F_SHIFTED) - NEXT_OUT(1); + NEXT_OUT(1) } - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - insize = 1; + DECODE_SURROGATE(c) + insize = GET_INSIZE(c); encoded = MAP_UNMAPPABLE; for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) { @@ -186,14 +187,24 @@ if (encoded == MAP_MULTIPLE_AVAIL) { /* this implementation won't work for pair * of non-bmp characters. */ - if (inlen - *inpos < 2) { + if (inleft < 2) { if (!(flags & MBENC_FLUSH)) return MBERR_TOOFEW; length = -1; } else length = 2; +#if Py_UNICODE_SIZE == 2 + if (length == 2) { + ucs4_t u4in[2]; + u4in[0] = (ucs4_t)IN1; + u4in[1] = (ucs4_t)IN2; + encoded = dsg->encoder(u4in, &length); + } else + encoded = dsg->encoder(&c, &length); +#else encoded = dsg->encoder(&c, &length); +#endif if (encoded != MAP_UNMAPPABLE) { insize = length; break; @@ -210,47 +221,47 @@ switch (dsg->plane) { case 0: /* G0 */ if (STATE_GETFLAG(F_SHIFTED)) { - WRITEBYTE1(SI) + WRITE1(SI) STATE_CLEARFLAG(F_SHIFTED) - NEXT_OUT(1); + NEXT_OUT(1) } if (STATE_G0 != dsg->mark) { if (dsg->width == 1) { - WRITEBYTE3(ESC, '(', ESCMARK(dsg->mark)) + WRITE3(ESC, '(', ESCMARK(dsg->mark)) STATE_SETG0(dsg->mark) - NEXT_OUT(3); + NEXT_OUT(3) } else if (dsg->mark == CHARSET_JISX0208) { - WRITEBYTE3(ESC, '$', ESCMARK(dsg->mark)) + WRITE3(ESC, '$', ESCMARK(dsg->mark)) STATE_SETG0(dsg->mark) - NEXT_OUT(3); + NEXT_OUT(3) } else { - WRITEBYTE4(ESC, '$', '(', + WRITE4(ESC, '$', '(', ESCMARK(dsg->mark)) STATE_SETG0(dsg->mark) - NEXT_OUT(4); + NEXT_OUT(4) } } break; case 1: /* G1 */ if (STATE_G1 != dsg->mark) { if (dsg->width == 1) { - WRITEBYTE3(ESC, ')', ESCMARK(dsg->mark)) + WRITE3(ESC, ')', ESCMARK(dsg->mark)) STATE_SETG1(dsg->mark) - NEXT_OUT(3); + NEXT_OUT(3) } else { - WRITEBYTE4(ESC, '$', ')', + WRITE4(ESC, '$', ')', ESCMARK(dsg->mark)) STATE_SETG1(dsg->mark) - NEXT_OUT(4); + NEXT_OUT(4) } } if (!STATE_GETFLAG(F_SHIFTED)) { - WRITEBYTE1(SO) + WRITE1(SO) STATE_SETFLAG(F_SHIFTED) - NEXT_OUT(1); + NEXT_OUT(1) } break; default: /* G2 and G3 is not supported: no encoding in @@ -259,14 +270,14 @@ } if (dsg->width == 1) { - WRITEBYTE1((unsigned char)encoded) - NEXT_OUT(1); + WRITE1((unsigned char)encoded) + NEXT_OUT(1) } else { - WRITEBYTE2(encoded >> 8, encoded & 0xff) - NEXT_OUT(2); + WRITE2(encoded >> 8, encoded & 0xff) + NEXT_OUT(2) } - NEXT_INCHAR(insize); + NEXT_IN(insize) } return 0; @@ -312,26 +323,26 @@ switch (esclen) { case 3: - if (INBYTE2 == '$') { - charset = INBYTE3 | CHARSET_DBCS; + if (IN2 == '$') { + charset = IN3 | CHARSET_DBCS; designation = 0; } else { - charset = INBYTE3; - if (INBYTE2 == '(') designation = 0; - else if (INBYTE2 == ')') designation = 1; - else if (CONFIG_ISSET(USE_G2) && INBYTE2 == '.') + charset = IN3; + if (IN2 == '(') designation = 0; + else if (IN2 == ')') designation = 1; + else if (CONFIG_ISSET(USE_G2) && IN2 == '.') designation = 2; else return 3; } break; case 4: - if (INBYTE2 != '$') + if (IN2 != '$') return 4; - charset = INBYTE4 | CHARSET_DBCS; - if (INBYTE3 == '(') designation = 0; - else if (INBYTE3 == ')') designation = 1; + charset = IN4 | CHARSET_DBCS; + if (IN3 == '(') designation = 0; + else if (IN3 == ')') designation = 1; else return 4; break; case 6: /* designation with prefix */ @@ -365,43 +376,45 @@ return 0; } -#define ISO8859_7_DECODE(c, writer) \ - if ((c) < 0xa0) OUTCHAR(c); \ - else if ((c) < 0xc0 && (0x288f3bc9L & (1L << ((c)-0xa0)))) \ - OUTCHAR(c); \ - else if ((c) >= 0xb4 && (c) <= 0xfe && ((c) >= 0xd4 || \ - (0xbffffd77L & (1L << ((c)-0xb4))))) \ - OUTCHAR(0x02d0 + (c)); \ - else if ((c) == 0xa1) OUTCHAR(0x2018); \ - else if ((c) == 0xa2) OUTCHAR(0x2019); \ - else if ((c) == 0xaf) OUTCHAR(0x2015); +#define ISO8859_7_DECODE(c, assi) \ + if ((c) < 0xa0) (assi) = (c); \ + else if ((c) < 0xc0 && (0x288f3bc9L & (1L << ((c)-0xa0)))) \ + (assi) = (c); \ + else if ((c) >= 0xb4 && (c) <= 0xfe && ((c) >= 0xd4 || \ + (0xbffffd77L & (1L << ((c)-0xb4))))) \ + (assi) = 0x02d0 + (c); \ + else if ((c) == 0xa1) (assi) = 0x2018; \ + else if ((c) == 0xa2) (assi) = 0x2019; \ + else if ((c) == 0xaf) (assi) = 0x2015; static Py_ssize_t iso2022processg2(const void *config, MultibyteCodec_State *state, const unsigned char **inbuf, Py_ssize_t *inleft, - _PyUnicodeWriter *writer) + Py_UNICODE **outbuf, Py_ssize_t *outleft) { /* not written to use encoder, decoder functions because only few * encodings use G2 designations in CJKCodecs */ if (STATE_G2 == CHARSET_ISO8859_1) { - if (INBYTE3 < 0x80) - OUTCHAR(INBYTE3 + 0x80); + if (IN3 < 0x80) + OUT1(IN3 + 0x80) else return 3; } else if (STATE_G2 == CHARSET_ISO8859_7) { - ISO8859_7_DECODE(INBYTE3 ^ 0x80, writer) + ISO8859_7_DECODE(IN3 ^ 0x80, **outbuf) else return 3; } else if (STATE_G2 == CHARSET_ASCII) { - if (INBYTE3 & 0x80) return 3; - else OUTCHAR(INBYTE3); + if (IN3 & 0x80) return 3; + else **outbuf = IN3; } else return MBERR_INTERNAL; (*inbuf) += 3; *inleft -= 3; + (*outbuf) += 1; + *outleft -= 1; return 0; } @@ -410,14 +423,14 @@ const struct iso2022_designation *dsgcache = NULL; while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; Py_ssize_t err; if (STATE_GETFLAG(F_ESCTHROUGHOUT)) { /* ESC throughout mode: * for non-iso2022 escape sequences */ - OUTCHAR(c); /* assume as ISO-8859-1 */ - NEXT_IN(1); + WRITE1(c) /* assume as ISO-8859-1 */ + NEXT(1, 1) if (IS_ESCEND(c)) { STATE_CLEARFLAG(F_ESCTHROUGHOUT) } @@ -427,41 +440,41 @@ switch (c) { case ESC: REQUIRE_INBUF(2) - if (IS_ISO2022ESC(INBYTE2)) { + if (IS_ISO2022ESC(IN2)) { err = iso2022processesc(config, state, inbuf, &inleft); if (err != 0) return err; } - else if (CONFIG_ISSET(USE_G2) && INBYTE2 == 'N') {/* SS2 */ + else if (CONFIG_ISSET(USE_G2) && IN2 == 'N') {/* SS2 */ REQUIRE_INBUF(3) err = iso2022processg2(config, state, - inbuf, &inleft, writer); + inbuf, &inleft, outbuf, &outleft); if (err != 0) return err; } else { - OUTCHAR(ESC); + WRITE1(ESC) STATE_SETFLAG(F_ESCTHROUGHOUT) - NEXT_IN(1); + NEXT(1, 1) } break; case SI: if (CONFIG_ISSET(NO_SHIFT)) goto bypass; STATE_CLEARFLAG(F_SHIFTED) - NEXT_IN(1); + NEXT_IN(1) break; case SO: if (CONFIG_ISSET(NO_SHIFT)) goto bypass; STATE_SETFLAG(F_SHIFTED) - NEXT_IN(1); + NEXT_IN(1) break; case LF: STATE_CLEARFLAG(F_SHIFTED) - OUTCHAR(LF); - NEXT_IN(1); + WRITE1(LF) + NEXT(1, 1) break; default: if (c < 0x20) /* C0 */ @@ -471,7 +484,7 @@ else { const struct iso2022_designation *dsg; unsigned char charset; - Py_UCS4 decoded; + ucs4_t decoded; if (STATE_GETFLAG(F_SHIFTED)) charset = STATE_G1; @@ -479,8 +492,8 @@ charset = STATE_G0; if (charset == CHARSET_ASCII) { -bypass: OUTCHAR(c); - NEXT_IN(1); +bypass: WRITE1(c) + NEXT(1, 1) break; } @@ -505,15 +518,17 @@ return dsg->width; if (decoded < 0x10000) { - OUTCHAR(decoded); + WRITE1(decoded) + NEXT_OUT(1) } else if (decoded < 0x30000) { - OUTCHAR(decoded); + WRITEUCS4(decoded) } else { /* JIS X 0213 pairs */ - OUTCHAR2(decoded >> 16, decoded & 0xffff); + WRITE2(decoded >> 16, decoded & 0xffff) + NEXT_OUT(2) } - NEXT_IN(dsg->width); + NEXT_IN(dsg->width) } break; } @@ -562,18 +577,18 @@ return 0; } -static Py_UCS4 +static ucs4_t ksx1001_decoder(const unsigned char *data) { - Py_UCS4 u; - TRYMAP_DEC_CHAR(ksx1001, u, data[0], data[1]) + ucs4_t u; + TRYMAP_DEC(ksx1001, u, data[0], data[1]) return u; else return MAP_UNMAPPABLE; } static DBCHAR -ksx1001_encoder(const Py_UCS4 *data, Py_ssize_t *length) +ksx1001_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; assert(*length == 1); @@ -598,20 +613,20 @@ return 0; } -static Py_UCS4 +static ucs4_t jisx0208_decoder(const unsigned char *data) { - Py_UCS4 u; + ucs4_t u; if (data[0] == 0x21 && data[1] == 0x40) /* F/W REVERSE SOLIDUS */ return 0xff3c; - else TRYMAP_DEC_CHAR(jisx0208, u, data[0], data[1]) + else TRYMAP_DEC(jisx0208, u, data[0], data[1]) return u; else return MAP_UNMAPPABLE; } static DBCHAR -jisx0208_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0208_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; assert(*length == 1); @@ -639,18 +654,18 @@ return 0; } -static Py_UCS4 +static ucs4_t jisx0212_decoder(const unsigned char *data) { - Py_UCS4 u; - TRYMAP_DEC_CHAR(jisx0212, u, data[0], data[1]) + ucs4_t u; + TRYMAP_DEC(jisx0212, u, data[0], data[1]) return u; else return MAP_UNMAPPABLE; } static DBCHAR -jisx0212_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0212_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; assert(*length == 1); @@ -690,30 +705,30 @@ } #define config ((void *)2000) -static Py_UCS4 +static ucs4_t jisx0213_2000_1_decoder(const unsigned char *data) { - Py_UCS4 u; + ucs4_t u; EMULATE_JISX0213_2000_DECODE_PLANE1(u, data[0], data[1]) else if (data[0] == 0x21 && data[1] == 0x40) /* F/W REVERSE SOLIDUS */ return 0xff3c; - else TRYMAP_DEC_CHAR(jisx0208, u, data[0], data[1]); - else TRYMAP_DEC_CHAR(jisx0213_1_bmp, u, data[0], data[1]); - else TRYMAP_DEC_CHAR(jisx0213_1_emp, u, data[0], data[1]) + else TRYMAP_DEC(jisx0208, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_1_bmp, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_1_emp, u, data[0], data[1]) u |= 0x20000; - else TRYMAP_DEC_CHAR(jisx0213_pair, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_pair, u, data[0], data[1]); else return MAP_UNMAPPABLE; return u; } -static Py_UCS4 +static ucs4_t jisx0213_2000_2_decoder(const unsigned char *data) { - Py_UCS4 u; - EMULATE_JISX0213_2000_DECODE_PLANE2_CHAR(u, data[0], data[1]) - TRYMAP_DEC_CHAR(jisx0213_2_bmp, u, data[0], data[1]); - else TRYMAP_DEC_CHAR(jisx0213_2_emp, u, data[0], data[1]) + ucs4_t u; + EMULATE_JISX0213_2000_DECODE_PLANE2(u, data[0], data[1]) + TRYMAP_DEC(jisx0213_2_bmp, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_2_emp, u, data[0], data[1]) u |= 0x20000; else return MAP_UNMAPPABLE; @@ -721,28 +736,28 @@ } #undef config -static Py_UCS4 +static ucs4_t jisx0213_2004_1_decoder(const unsigned char *data) { - Py_UCS4 u; + ucs4_t u; if (data[0] == 0x21 && data[1] == 0x40) /* F/W REVERSE SOLIDUS */ return 0xff3c; - else TRYMAP_DEC_CHAR(jisx0208, u, data[0], data[1]); - else TRYMAP_DEC_CHAR(jisx0213_1_bmp, u, data[0], data[1]); - else TRYMAP_DEC_CHAR(jisx0213_1_emp, u, data[0], data[1]) + else TRYMAP_DEC(jisx0208, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_1_bmp, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_1_emp, u, data[0], data[1]) u |= 0x20000; - else TRYMAP_DEC_CHAR(jisx0213_pair, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_pair, u, data[0], data[1]); else return MAP_UNMAPPABLE; return u; } -static Py_UCS4 +static ucs4_t jisx0213_2004_2_decoder(const unsigned char *data) { - Py_UCS4 u; - TRYMAP_DEC_CHAR(jisx0213_2_bmp, u, data[0], data[1]); - else TRYMAP_DEC_CHAR(jisx0213_2_emp, u, data[0], data[1]) + ucs4_t u; + TRYMAP_DEC(jisx0213_2_bmp, u, data[0], data[1]); + else TRYMAP_DEC(jisx0213_2_emp, u, data[0], data[1]) u |= 0x20000; else return MAP_UNMAPPABLE; @@ -750,7 +765,7 @@ } static DBCHAR -jisx0213_encoder(const Py_UCS4 *data, Py_ssize_t *length, void *config) +jisx0213_encoder(const ucs4_t *data, Py_ssize_t *length, void *config) { DBCHAR coded; @@ -804,7 +819,7 @@ } static DBCHAR -jisx0213_2000_1_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0213_2000_1_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded = jisx0213_encoder(data, length, (void *)2000); if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL) @@ -816,7 +831,7 @@ } static DBCHAR -jisx0213_2000_1_encoder_paironly(const Py_UCS4 *data, Py_ssize_t *length) +jisx0213_2000_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; Py_ssize_t ilength = *length; @@ -839,7 +854,7 @@ } static DBCHAR -jisx0213_2000_2_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0213_2000_2_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded = jisx0213_encoder(data, length, (void *)2000); if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL) @@ -851,7 +866,7 @@ } static DBCHAR -jisx0213_2004_1_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0213_2004_1_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded = jisx0213_encoder(data, length, NULL); if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL) @@ -863,7 +878,7 @@ } static DBCHAR -jisx0213_2004_1_encoder_paironly(const Py_UCS4 *data, Py_ssize_t *length) +jisx0213_2004_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; Py_ssize_t ilength = *length; @@ -886,7 +901,7 @@ } static DBCHAR -jisx0213_2004_2_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0213_2004_2_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded = jisx0213_encoder(data, length, NULL); if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL) @@ -897,17 +912,17 @@ return MAP_UNMAPPABLE; } -static Py_UCS4 +static ucs4_t jisx0201_r_decoder(const unsigned char *data) { - Py_UCS4 u; - JISX0201_R_DECODE_CHAR(*data, u) + ucs4_t u; + JISX0201_R_DECODE(*data, u) else return MAP_UNMAPPABLE; return u; } static DBCHAR -jisx0201_r_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0201_r_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; JISX0201_R_ENCODE(*data, coded) @@ -915,17 +930,17 @@ return coded; } -static Py_UCS4 +static ucs4_t jisx0201_k_decoder(const unsigned char *data) { - Py_UCS4 u; - JISX0201_K_DECODE_CHAR(*data ^ 0x80, u) + ucs4_t u; + JISX0201_K_DECODE(*data ^ 0x80, u) else return MAP_UNMAPPABLE; return u; } static DBCHAR -jisx0201_k_encoder(const Py_UCS4 *data, Py_ssize_t *length) +jisx0201_k_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; JISX0201_K_ENCODE(*data, coded) @@ -946,18 +961,18 @@ return 0; } -static Py_UCS4 +static ucs4_t gb2312_decoder(const unsigned char *data) { - Py_UCS4 u; - TRYMAP_DEC_CHAR(gb2312, u, data[0], data[1]) + ucs4_t u; + TRYMAP_DEC(gb2312, u, data[0], data[1]) return u; else return MAP_UNMAPPABLE; } static DBCHAR -gb2312_encoder(const Py_UCS4 *data, Py_ssize_t *length) +gb2312_encoder(const ucs4_t *data, Py_ssize_t *length) { DBCHAR coded; assert(*length == 1); @@ -971,14 +986,14 @@ } -static Py_UCS4 +static ucs4_t dummy_decoder(const unsigned char *data) { return MAP_UNMAPPABLE; } static DBCHAR -dummy_encoder(const Py_UCS4 *data, Py_ssize_t *length) +dummy_encoder(const ucs4_t *data, Py_ssize_t *length) { return MAP_UNMAPPABLE; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/_codecs_jp.c --- a/Modules/cjkcodecs/_codecs_jp.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/_codecs_jp.c Fri Feb 01 23:12:09 2013 +0100 @@ -19,39 +19,38 @@ ENCODER(cp932) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; unsigned char c1, c2; if (c <= 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } else if (c >= 0xff61 && c <= 0xff9f) { - WRITEBYTE1(c - 0xfec0) - NEXT(1, 1); + WRITE1(c - 0xfec0) + NEXT(1, 1) continue; } else if (c >= 0xf8f0 && c <= 0xf8f3) { /* Windows compatibility */ REQUIRE_OUTBUF(1) if (c == 0xf8f0) - OUTBYTE1(0xa0) + OUT1(0xa0) else - OUTBYTE1(c - 0xfef1 + 0xfd) - NEXT(1, 1); + OUT1(c - 0xfef1 + 0xfd) + NEXT(1, 1) continue; } - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) TRYMAP_ENC(cp932ext, code, c) { - OUTBYTE1(code >> 8) - OUTBYTE2(code & 0xff) + OUT1(code >> 8) + OUT2(code & 0xff) } else TRYMAP_ENC(jisxcommon, code, c) { if (code & 0x8000) /* MSB set: JIS X 0212 */ @@ -62,20 +61,20 @@ c2 = code & 0xff; c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21); c1 = (c1 - 0x21) >> 1; - OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1) - OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41) + OUT1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1) + OUT2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41) } else if (c >= 0xe000 && c < 0xe758) { /* User-defined area */ - c1 = (Py_UCS4)(c - 0xe000) / 188; - c2 = (Py_UCS4)(c - 0xe000) % 188; - OUTBYTE1(c1 + 0xf0) - OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41) + c1 = (Py_UNICODE)(c - 0xe000) / 188; + c2 = (Py_UNICODE)(c - 0xe000) % 188; + OUT1(c1 + 0xf0) + OUT2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41) } else return 1; - NEXT(1, 2); + NEXT(1, 2) } return 0; @@ -84,32 +83,33 @@ DECODER(cp932) { while (inleft > 0) { - unsigned char c = INBYTE1, c2; + unsigned char c = IN1, c2; + REQUIRE_OUTBUF(1) if (c <= 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } else if (c >= 0xa0 && c <= 0xdf) { if (c == 0xa0) - OUTCHAR(0xf8f0); /* half-width katakana */ + OUT1(0xf8f0) /* half-width katakana */ else - OUTCHAR(0xfec0 + c); - NEXT_IN(1); + OUT1(0xfec0 + c) + NEXT(1, 1) continue; } else if (c >= 0xfd/* && c <= 0xff*/) { /* Windows compatibility */ - OUTCHAR(0xf8f1 - 0xfd + c); - NEXT_IN(1); + OUT1(0xf8f1 - 0xfd + c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; - TRYMAP_DEC(cp932ext, writer, c, c2); + TRYMAP_DEC(cp932ext, **outbuf, c, c2); else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)){ if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 1; @@ -119,21 +119,21 @@ c = (2 * c + (c2 < 0x5e ? 0 : 1) + 0x21); c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21; - TRYMAP_DEC(jisx0208, writer, c, c2); + TRYMAP_DEC(jisx0208, **outbuf, c, c2); else return 1; } else if (c >= 0xf0 && c <= 0xf9) { if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfc)) - OUTCHAR(0xe000 + 188 * (c - 0xf0) + - (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41)); + OUT1(0xe000 + 188 * (c - 0xf0) + + (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41)) else return 1; } else return 1; - NEXT_IN(2); + NEXT(2, 1) } return 0; @@ -146,24 +146,25 @@ ENCODER(euc_jis_2004) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + ucs4_t c = IN1; DBCHAR code; Py_ssize_t insize; if (c < 0x80) { - WRITEBYTE1(c) - NEXT(1, 1); + WRITE1(c) + NEXT(1, 1) continue; } - insize = 1; + DECODE_SURROGATE(c) + insize = GET_INSIZE(c); if (c <= 0xFFFF) { EMULATE_JISX0213_2000_ENCODE_BMP(code, c) else TRYMAP_ENC(jisx0213_bmp, code, c) { if (code == MULTIC) { - if (inlen - *inpos < 2) { + if (inleft < 2) { if (flags & MBENC_FLUSH) { code = find_pairencmap( (ucs2_t)c, 0, @@ -176,9 +177,8 @@ return MBERR_TOOFEW; } else { - Py_UCS4 c2 = INCHAR2; code = find_pairencmap( - (ucs2_t)c, c2, + (ucs2_t)c, (*inbuf)[1], jisx0213_pair_encmap, JISX0213_ENCPAIRS); if (code == DBCINV) { @@ -196,8 +196,8 @@ else TRYMAP_ENC(jisxcommon, code, c); else if (c >= 0xff61 && c <= 0xff9f) { /* JIS X 0201 half-width katakana */ - WRITEBYTE2(0x8e, c - 0xfec0) - NEXT(1, 2); + WRITE2(0x8e, c - 0xfec0) + NEXT(1, 2) continue; } else if (c == 0xff3c) @@ -219,12 +219,12 @@ if (code & 0x8000) { /* Codeset 2 */ - WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80) - NEXT(insize, 3); + WRITE3(0x8f, code >> 8, (code & 0xFF) | 0x80) + NEXT(insize, 3) } else { /* Codeset 1 */ - WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80) - NEXT(insize, 2); + WRITE2((code >> 8) | 0x80, (code & 0xFF) | 0x80) + NEXT(insize, 2) } } @@ -234,12 +234,14 @@ DECODER(euc_jis_2004) { while (inleft > 0) { - unsigned char c = INBYTE1; - Py_UCS4 code; + unsigned char c = IN1; + ucs4_t code; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } @@ -248,10 +250,10 @@ unsigned char c2; REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; if (c2 >= 0xa1 && c2 <= 0xdf) { - OUTCHAR(0xfec0 + c2); - NEXT_IN(2); + OUT1(0xfec0 + c2) + NEXT(2, 1) } else return 1; @@ -260,46 +262,46 @@ unsigned char c2, c3; REQUIRE_INBUF(3) - c2 = INBYTE2 ^ 0x80; - c3 = INBYTE3 ^ 0x80; + c2 = IN2 ^ 0x80; + c3 = IN3 ^ 0x80; /* JIS X 0213 Plane 2 or JIS X 0212 (see NOTES) */ - EMULATE_JISX0213_2000_DECODE_PLANE2(writer, c2, c3) - else TRYMAP_DEC(jisx0213_2_bmp, writer, c2, c3) ; - else TRYMAP_DEC_CHAR(jisx0213_2_emp, code, c2, c3) { - OUTCHAR(EMPBASE | code); - NEXT_IN(3); + EMULATE_JISX0213_2000_DECODE_PLANE2(**outbuf, c2, c3) + else TRYMAP_DEC(jisx0213_2_bmp, **outbuf, c2, c3) ; + else TRYMAP_DEC(jisx0213_2_emp, code, c2, c3) { + WRITEUCS4(EMPBASE | code) + NEXT_IN(3) continue; } - else TRYMAP_DEC(jisx0212, writer, c2, c3) ; + else TRYMAP_DEC(jisx0212, **outbuf, c2, c3) ; else return 1; - NEXT_IN(3); + NEXT(3, 1) } else { unsigned char c2; REQUIRE_INBUF(2) c ^= 0x80; - c2 = INBYTE2 ^ 0x80; + c2 = IN2 ^ 0x80; /* JIS X 0213 Plane 1 */ - EMULATE_JISX0213_2000_DECODE_PLANE1(writer, c, c2) - else if (c == 0x21 && c2 == 0x40) OUTCHAR(0xff3c); - else if (c == 0x22 && c2 == 0x32) OUTCHAR(0xff5e); - else TRYMAP_DEC(jisx0208, writer, c, c2); - else TRYMAP_DEC(jisx0213_1_bmp, writer, c, c2); - else TRYMAP_DEC_CHAR(jisx0213_1_emp, code, c, c2) { - OUTCHAR(EMPBASE | code); - NEXT_IN(2); + EMULATE_JISX0213_2000_DECODE_PLANE1(**outbuf, c, c2) + else if (c == 0x21 && c2 == 0x40) **outbuf = 0xff3c; + else if (c == 0x22 && c2 == 0x32) **outbuf = 0xff5e; + else TRYMAP_DEC(jisx0208, **outbuf, c, c2); + else TRYMAP_DEC(jisx0213_1_bmp, **outbuf, c, c2); + else TRYMAP_DEC(jisx0213_1_emp, code, c, c2) { + WRITEUCS4(EMPBASE | code) + NEXT_IN(2) continue; } - else TRYMAP_DEC_CHAR(jisx0213_pair, code, c, c2) { - OUTCHAR2(code >> 16, code & 0xffff); - NEXT_IN(2); + else TRYMAP_DEC(jisx0213_pair, code, c, c2) { + WRITE2(code >> 16, code & 0xffff) + NEXT(2, 2) continue; } else return 1; - NEXT_IN(2); + NEXT(2, 1) } } @@ -313,36 +315,35 @@ ENCODER(euc_jp) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) TRYMAP_ENC(jisxcommon, code, c); else if (c >= 0xff61 && c <= 0xff9f) { /* JIS X 0201 half-width katakana */ - WRITEBYTE2(0x8e, c - 0xfec0) - NEXT(1, 2); + WRITE2(0x8e, c - 0xfec0) + NEXT(1, 2) continue; } #ifndef STRICT_BUILD else if (c == 0xff3c) /* FULL-WIDTH REVERSE SOLIDUS */ code = 0x2140; else if (c == 0xa5) { /* YEN SIGN */ - WRITEBYTE1(0x5c); - NEXT(1, 1); + WRITE1(0x5c); + NEXT(1, 1) continue; } else if (c == 0x203e) { /* OVERLINE */ - WRITEBYTE1(0x7e); - NEXT(1, 1); + WRITE1(0x7e); + NEXT(1, 1) continue; } #endif @@ -351,12 +352,12 @@ if (code & 0x8000) { /* JIS X 0212 */ - WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80) - NEXT(1, 3); + WRITE3(0x8f, code >> 8, (code & 0xFF) | 0x80) + NEXT(1, 3) } else { /* JIS X 0208 */ - WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80) - NEXT(1, 2); + WRITE2((code >> 8) | 0x80, (code & 0xFF) | 0x80) + NEXT(1, 2) } } @@ -366,11 +367,13 @@ DECODER(euc_jp) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } @@ -379,10 +382,10 @@ unsigned char c2; REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; if (c2 >= 0xa1 && c2 <= 0xdf) { - OUTCHAR(0xfec0 + c2); - NEXT_IN(2); + OUT1(0xfec0 + c2) + NEXT(2, 1) } else return 1; @@ -391,11 +394,11 @@ unsigned char c2, c3; REQUIRE_INBUF(3) - c2 = INBYTE2; - c3 = INBYTE3; + c2 = IN2; + c3 = IN3; /* JIS X 0212 */ - TRYMAP_DEC(jisx0212, writer, c2 ^ 0x80, c3 ^ 0x80) { - NEXT_IN(3); + TRYMAP_DEC(jisx0212, **outbuf, c2 ^ 0x80, c3 ^ 0x80) { + NEXT(3, 1) } else return 1; @@ -404,18 +407,18 @@ unsigned char c2; REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; /* JIS X 0208 */ #ifndef STRICT_BUILD if (c == 0xa1 && c2 == 0xc0) /* FULL-WIDTH REVERSE SOLIDUS */ - OUTCHAR(0xff3c); + **outbuf = 0xff3c; else #endif - TRYMAP_DEC(jisx0208, writer, + TRYMAP_DEC(jisx0208, **outbuf, c ^ 0x80, c2 ^ 0x80) ; else return 1; - NEXT_IN(2); + NEXT(2, 1) } } @@ -429,8 +432,8 @@ ENCODER(shift_jis) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; unsigned char c1, c2; @@ -442,16 +445,14 @@ else if (c == 0x203e) code = 0x7e; /* OVERLINE */ #endif else JISX0201_K_ENCODE(c, code) - else if (c > 0xFFFF) - return 1; - else - code = NOCHAR; + else UCS4INVALID(c) + else code = NOCHAR; if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) { REQUIRE_OUTBUF(1) - OUTBYTE1((unsigned char)code) - NEXT(1, 1); + OUT1((unsigned char)code) + NEXT(1, 1) continue; } @@ -474,9 +475,9 @@ c2 = code & 0xff; c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21); c1 = (c1 - 0x21) >> 1; - OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1) - OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41) - NEXT(1, 2); + OUT1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1) + OUT2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41) + NEXT(1, 2) } return 0; @@ -485,19 +486,21 @@ DECODER(shift_jis) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) #ifdef STRICT_BUILD - JISX0201_R_DECODE(c, writer) + JISX0201_R_DECODE(c, **outbuf) #else - if (c < 0x80) OUTCHAR(c); + if (c < 0x80) **outbuf = c; #endif - else JISX0201_K_DECODE(c, writer) + else JISX0201_K_DECODE(c, **outbuf) else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)){ unsigned char c1, c2; REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 1; @@ -509,13 +512,13 @@ #ifndef STRICT_BUILD if (c1 == 0x21 && c2 == 0x40) { /* FULL-WIDTH REVERSE SOLIDUS */ - OUTCHAR(0xff3c); - NEXT_IN(2); + OUT1(0xff3c) + NEXT(2, 1) continue; } #endif - TRYMAP_DEC(jisx0208, writer, c1, c2) { - NEXT_IN(2); + TRYMAP_DEC(jisx0208, **outbuf, c1, c2) { + NEXT(2, 1) continue; } else @@ -524,7 +527,7 @@ else return 1; - NEXT_IN(1); /* JIS X 0201 */ + NEXT(1, 1) /* JIS X 0201 */ } return 0; @@ -537,29 +540,30 @@ ENCODER(shift_jis_2004) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + ucs4_t c = IN1; DBCHAR code = NOCHAR; int c1, c2; Py_ssize_t insize; JISX0201_ENCODE(c, code) + else DECODE_SURROGATE(c) if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) { - WRITEBYTE1((unsigned char)code) - NEXT(1, 1); + WRITE1((unsigned char)code) + NEXT(1, 1) continue; } REQUIRE_OUTBUF(2) - insize = 1; + insize = GET_INSIZE(c); if (code == NOCHAR) { if (c <= 0xffff) { EMULATE_JISX0213_2000_ENCODE_BMP(code, c) else TRYMAP_ENC(jisx0213_bmp, code, c) { if (code == MULTIC) { - if (inlen - *inpos < 2) { + if (inleft < 2) { if (flags & MBENC_FLUSH) { code = find_pairencmap ((ucs2_t)c, 0, @@ -572,9 +576,8 @@ return MBERR_TOOFEW; } else { - Py_UCS4 ch2 = INCHAR2; code = find_pairencmap( - (ucs2_t)c, ch2, + (ucs2_t)c, IN2, jisx0213_pair_encmap, JISX0213_ENCPAIRS); if (code == DBCINV) { @@ -619,10 +622,10 @@ if (c1 & 1) c2 += 0x5e; c1 >>= 1; - OUTBYTE1(c1 + (c1 < 0x1f ? 0x81 : 0xc1)) - OUTBYTE2(c2 + (c2 < 0x3f ? 0x40 : 0x41)) + OUT1(c1 + (c1 < 0x1f ? 0x81 : 0xc1)) + OUT2(c2 + (c2 < 0x3f ? 0x40 : 0x41)) - NEXT(insize, 2); + NEXT(insize, 2) } return 0; @@ -631,15 +634,16 @@ DECODER(shift_jis_2004) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; - JISX0201_DECODE(c, writer) + REQUIRE_OUTBUF(1) + JISX0201_DECODE(c, **outbuf) else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)){ unsigned char c1, c2; - Py_UCS4 code; + ucs4_t code; REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 1; @@ -650,47 +654,50 @@ if (c1 < 0x5e) { /* Plane 1 */ c1 += 0x21; - EMULATE_JISX0213_2000_DECODE_PLANE1(writer, + EMULATE_JISX0213_2000_DECODE_PLANE1(**outbuf, c1, c2) - else TRYMAP_DEC(jisx0208, writer, c1, c2) { + else TRYMAP_DEC(jisx0208, **outbuf, c1, c2) { + NEXT_OUT(1) } - else TRYMAP_DEC(jisx0213_1_bmp, writer, + else TRYMAP_DEC(jisx0213_1_bmp, **outbuf, c1, c2) { + NEXT_OUT(1) } - else TRYMAP_DEC_CHAR(jisx0213_1_emp, code, c1, c2) { - OUTCHAR(EMPBASE | code); + else TRYMAP_DEC(jisx0213_1_emp, code, c1, c2) { + WRITEUCS4(EMPBASE | code) } - else TRYMAP_DEC_CHAR(jisx0213_pair, code, c1, c2) { - OUTCHAR2(code >> 16, code & 0xffff); + else TRYMAP_DEC(jisx0213_pair, code, c1, c2) { + WRITE2(code >> 16, code & 0xffff) + NEXT_OUT(2) } else return 1; - NEXT_IN(2); + NEXT_IN(2) } else { /* Plane 2 */ if (c1 >= 0x67) c1 += 0x07; else if (c1 >= 0x63 || c1 == 0x5f) c1 -= 0x37; else c1 -= 0x3d; - EMULATE_JISX0213_2000_DECODE_PLANE2(writer, + EMULATE_JISX0213_2000_DECODE_PLANE2(**outbuf, c1, c2) - else TRYMAP_DEC(jisx0213_2_bmp, writer, - c1, c2) { - } else TRYMAP_DEC_CHAR(jisx0213_2_emp, code, c1, c2) { - OUTCHAR(EMPBASE | code); - NEXT_IN(2); + else TRYMAP_DEC(jisx0213_2_bmp, **outbuf, + c1, c2) ; + else TRYMAP_DEC(jisx0213_2_emp, code, c1, c2) { + WRITEUCS4(EMPBASE | code) + NEXT_IN(2) continue; } else return 1; - NEXT_IN(2); + NEXT(2, 1) } continue; } else return 1; - NEXT_IN(1); /* JIS X 0201 */ + NEXT(1, 1) /* JIS X 0201 */ } return 0; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/_codecs_kr.c --- a/Modules/cjkcodecs/_codecs_kr.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/_codecs_kr.c Fri Feb 01 23:12:09 2013 +0100 @@ -33,18 +33,16 @@ ENCODER(euc_kr) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) TRYMAP_ENC(cp949, code, c); @@ -52,9 +50,9 @@ if ((code & 0x8000) == 0) { /* KS X 1001 coded character */ - OUTBYTE1((code >> 8) | 0x80) - OUTBYTE2((code & 0xFF) | 0x80) - NEXT(1, 2); + OUT1((code >> 8) | 0x80) + OUT2((code & 0xFF) | 0x80) + NEXT(1, 2) } else { /* Mapping is found in CP949 extension, * but we encode it in KS X 1001:1998 Annex 3, @@ -63,23 +61,23 @@ REQUIRE_OUTBUF(8) /* syllable composition precedence */ - OUTBYTE1(EUCKR_JAMO_FIRSTBYTE) - OUTBYTE2(EUCKR_JAMO_FILLER) + OUT1(EUCKR_JAMO_FIRSTBYTE) + OUT2(EUCKR_JAMO_FILLER) /* All codepoints in CP949 extension are in unicode * Hangul Syllable area. */ assert(0xac00 <= c && c <= 0xd7a3); c -= 0xac00; - OUTBYTE3(EUCKR_JAMO_FIRSTBYTE) - OUTBYTE4(u2cgk_choseong[c / 588]) - NEXT_OUT(4); + OUT3(EUCKR_JAMO_FIRSTBYTE) + OUT4(u2cgk_choseong[c / 588]) + NEXT_OUT(4) - OUTBYTE1(EUCKR_JAMO_FIRSTBYTE) - OUTBYTE2(u2cgk_jungseong[(c / 28) % 21]) - OUTBYTE3(EUCKR_JAMO_FIRSTBYTE) - OUTBYTE4(u2cgk_jongseong[c % 28]) - NEXT(1, 4); + OUT1(EUCKR_JAMO_FIRSTBYTE) + OUT2(u2cgk_jungseong[(c / 28) % 21]) + OUT3(EUCKR_JAMO_FIRSTBYTE) + OUT4(u2cgk_jongseong[c % 28]) + NEXT(1, 4) } } @@ -104,18 +102,20 @@ DECODER(euc_kr) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) if (c == EUCKR_JAMO_FIRSTBYTE && - INBYTE2 == EUCKR_JAMO_FILLER) { + IN2 == EUCKR_JAMO_FILLER) { /* KS X 1001:1998 Annex 3 make-up sequence */ DBCHAR cho, jung, jong; @@ -145,11 +145,11 @@ if (cho == NONE || jung == NONE || jong == NONE) return 1; - OUTCHAR(0xac00 + cho*588 + jung*28 + jong); - NEXT_IN(8); + OUT1(0xac00 + cho*588 + jung*28 + jong); + NEXT(8, 1) } - else TRYMAP_DEC(ksx1001, writer, c ^ 0x80, INBYTE2 ^ 0x80) { - NEXT_IN(2); + else TRYMAP_DEC(ksx1001, **outbuf, c ^ 0x80, IN2 ^ 0x80) { + NEXT(2, 1) } else return 1; @@ -166,29 +166,27 @@ ENCODER(cp949) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) TRYMAP_ENC(cp949, code, c); else return 1; - OUTBYTE1((code >> 8) | 0x80) + OUT1((code >> 8) | 0x80) if (code & 0x8000) - OUTBYTE2(code & 0xFF) /* MSB set: CP949 */ + OUT2(code & 0xFF) /* MSB set: CP949 */ else - OUTBYTE2((code & 0xFF) | 0x80) /* MSB unset: ks x 1001 */ - NEXT(1, 2); + OUT2((code & 0xFF) | 0x80) /* MSB unset: ks x 1001 */ + NEXT(1, 2) } return 0; @@ -197,20 +195,22 @@ DECODER(cp949) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - TRYMAP_DEC(ksx1001, writer, c ^ 0x80, INBYTE2 ^ 0x80); - else TRYMAP_DEC(cp949ext, writer, c, INBYTE2); + TRYMAP_DEC(ksx1001, **outbuf, c ^ 0x80, IN2 ^ 0x80); + else TRYMAP_DEC(cp949ext, **outbuf, c, IN2); else return 1; - NEXT_IN(2); + NEXT(2, 1) } return 0; @@ -250,18 +250,16 @@ ENCODER(johab) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) @@ -287,9 +285,9 @@ t1 = (c1 < 0x4a ? (c1 - 0x21 + 0x1b2) : (c1 - 0x21 + 0x197)); t2 = ((t1 & 1) ? 0x5e : 0) + (c2 - 0x21); - OUTBYTE1(t1 >> 1) - OUTBYTE2(t2 < 0x4e ? t2 + 0x31 : t2 + 0x43) - NEXT(1, 2); + OUT1(t1 >> 1) + OUT2(t2 < 0x4e ? t2 + 0x31 : t2 + 0x43) + NEXT(1, 2) continue; } else @@ -298,9 +296,9 @@ else return 1; - OUTBYTE1(code >> 8) - OUTBYTE2(code & 0xff) - NEXT(1, 2); + OUT1(code >> 8) + OUT2(code & 0xff) + NEXT(1, 2) } return 0; @@ -350,16 +348,18 @@ DECODER(johab) { while (inleft > 0) { - unsigned char c = INBYTE1, c2; + unsigned char c = IN1, c2; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - c2 = INBYTE2; + c2 = IN2; if (c < 0xd8) { /* johab hangul */ @@ -381,33 +381,33 @@ if (i_cho == FILL) { if (i_jung == FILL) { if (i_jong == FILL) - OUTCHAR(0x3000); + OUT1(0x3000) else - OUTCHAR(0x3100 | - johabjamo_jongseong[c_jong]); + OUT1(0x3100 | + johabjamo_jongseong[c_jong]) } else { if (i_jong == FILL) - OUTCHAR(0x3100 | - johabjamo_jungseong[c_jung]); + OUT1(0x3100 | + johabjamo_jungseong[c_jung]) else return 1; } } else { if (i_jung == FILL) { if (i_jong == FILL) - OUTCHAR(0x3100 | - johabjamo_choseong[c_cho]); + OUT1(0x3100 | + johabjamo_choseong[c_cho]) else return 1; } else - OUTCHAR(0xac00 + - i_cho * 588 + - i_jung * 28 + - (i_jong == FILL ? 0 : i_jong)); + OUT1(0xac00 + + i_cho * 588 + + i_jung * 28 + + (i_jong == FILL ? 0 : i_jong)) } - NEXT_IN(2); + NEXT(2, 1) } else { /* KS X 1001 except hangul jamos and syllables */ if (c == 0xdf || c > 0xf9 || @@ -424,9 +424,9 @@ t1 = t1 + (t2 < 0x5e ? 0 : 1) + 0x21; t2 = (t2 < 0x5e ? t2 : t2 - 0x5e) + 0x21; - TRYMAP_DEC(ksx1001, writer, t1, t2); + TRYMAP_DEC(ksx1001, **outbuf, t1, t2); else return 1; - NEXT_IN(2); + NEXT(2, 1) } } } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/_codecs_tw.c --- a/Modules/cjkcodecs/_codecs_tw.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/_codecs_tw.c Fri Feb 01 23:12:09 2013 +0100 @@ -13,28 +13,26 @@ ENCODER(big5) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = **inbuf; DBCHAR code; if (c < 0x80) { REQUIRE_OUTBUF(1) **outbuf = (unsigned char)c; - NEXT(1, 1); + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) TRYMAP_ENC(big5, code, c); else return 1; - OUTBYTE1(code >> 8) - OUTBYTE2(code & 0xFF) - NEXT(1, 2); + OUT1(code >> 8) + OUT2(code & 0xFF) + NEXT(1, 2) } return 0; @@ -43,17 +41,19 @@ DECODER(big5) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - TRYMAP_DEC(big5, writer, c, INBYTE2) { - NEXT_IN(2); + TRYMAP_DEC(big5, **outbuf, c, IN2) { + NEXT(2, 1) } else return 1; } @@ -68,27 +68,25 @@ ENCODER(cp950) { - while (*inpos < inlen) { - Py_UCS4 c = INCHAR1; + while (inleft > 0) { + Py_UNICODE c = IN1; DBCHAR code; if (c < 0x80) { - WRITEBYTE1((unsigned char)c) - NEXT(1, 1); + WRITE1((unsigned char)c) + NEXT(1, 1) continue; } - - if (c > 0xFFFF) - return 1; + UCS4INVALID(c) REQUIRE_OUTBUF(2) TRYMAP_ENC(cp950ext, code, c); else TRYMAP_ENC(big5, code, c); else return 1; - OUTBYTE1(code >> 8) - OUTBYTE2(code & 0xFF) - NEXT(1, 2); + OUT1(code >> 8) + OUT2(code & 0xFF) + NEXT(1, 2) } return 0; @@ -97,21 +95,23 @@ DECODER(cp950) { while (inleft > 0) { - unsigned char c = INBYTE1; + unsigned char c = IN1; + + REQUIRE_OUTBUF(1) if (c < 0x80) { - OUTCHAR(c); - NEXT_IN(1); + OUT1(c) + NEXT(1, 1) continue; } REQUIRE_INBUF(2) - TRYMAP_DEC(cp950ext, writer, c, INBYTE2); - else TRYMAP_DEC(big5, writer, c, INBYTE2); + TRYMAP_DEC(cp950ext, **outbuf, c, IN2); + else TRYMAP_DEC(big5, **outbuf, c, IN2); else return 1; - NEXT_IN(2); + NEXT(2, 1) } return 0; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/alg_jisx0201.h --- a/Modules/cjkcodecs/alg_jisx0201.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/alg_jisx0201.h Fri Feb 01 23:12:09 2013 +0100 @@ -10,24 +10,15 @@ JISX0201_R_ENCODE(c, assi) \ else JISX0201_K_ENCODE(c, assi) -#define JISX0201_R_DECODE_CHAR(c, assi) \ +#define JISX0201_R_DECODE(c, assi) \ if ((c) < 0x5c) (assi) = (c); \ else if ((c) == 0x5c) (assi) = 0x00a5; \ else if ((c) < 0x7e) (assi) = (c); \ else if ((c) == 0x7e) (assi) = 0x203e; \ else if ((c) == 0x7f) (assi) = 0x7f; -#define JISX0201_R_DECODE(c, writer) \ - if ((c) < 0x5c) OUTCHAR(c); \ - else if ((c) == 0x5c) OUTCHAR(0x00a5); \ - else if ((c) < 0x7e) OUTCHAR(c); \ - else if ((c) == 0x7e) OUTCHAR(0x203e); \ - else if ((c) == 0x7f) OUTCHAR(0x7f); -#define JISX0201_K_DECODE(c, writer) \ +#define JISX0201_K_DECODE(c, assi) \ if ((c) >= 0xa1 && (c) <= 0xdf) \ - OUTCHAR(0xfec0 + (c)); -#define JISX0201_K_DECODE_CHAR(c, assi) \ - if ((c) >= 0xa1 && (c) <= 0xdf) \ - (assi) = 0xfec0 + (c); -#define JISX0201_DECODE(c, writer) \ - JISX0201_R_DECODE(c, writer) \ - else JISX0201_K_DECODE(c, writer) + (assi) = 0xfec0 + (c); +#define JISX0201_DECODE(c, assi) \ + JISX0201_R_DECODE(c, assi) \ + else JISX0201_K_DECODE(c, assi) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/cjkcodecs.h --- a/Modules/cjkcodecs/cjkcodecs.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/cjkcodecs.h Fri Feb 01 23:12:09 2013 +0100 @@ -33,7 +33,7 @@ typedef struct dbcs_index decode_map; struct widedbcs_index { - const Py_UCS4 *map; + const ucs4_t *map; unsigned char bottom, top; }; typedef struct widedbcs_index widedecode_map; @@ -56,7 +56,7 @@ }; struct pair_encodemap { - Py_UCS4 uniseq; + ucs4_t uniseq; DBCHAR code; }; @@ -72,8 +72,7 @@ #define ENCODER(encoding) \ static Py_ssize_t encoding##_encode( \ MultibyteCodec_State *state, const void *config, \ - int kind, void *data, \ - Py_ssize_t *inpos, Py_ssize_t inlen, \ + const Py_UNICODE **inbuf, Py_ssize_t inleft, \ unsigned char **outbuf, Py_ssize_t outleft, int flags) #define ENCODER_RESET(encoding) \ static Py_ssize_t encoding##_encode_reset( \ @@ -87,30 +86,28 @@ static Py_ssize_t encoding##_decode( \ MultibyteCodec_State *state, const void *config, \ const unsigned char **inbuf, Py_ssize_t inleft, \ - _PyUnicodeWriter *writer) + Py_UNICODE **outbuf, Py_ssize_t outleft) #define DECODER_RESET(encoding) \ static Py_ssize_t encoding##_decode_reset( \ MultibyteCodec_State *state, const void *config) +#if Py_UNICODE_SIZE == 4 +#define UCS4INVALID(code) \ + if ((code) > 0xFFFF) \ + return 1; +#else +#define UCS4INVALID(code) \ + if (0) ; +#endif + #define NEXT_IN(i) \ - do { \ - (*inbuf) += (i); \ - (inleft) -= (i); \ - } while (0) -#define NEXT_INCHAR(i) \ - do { \ - (*inpos) += (i); \ - } while (0) + (*inbuf) += (i); \ + (inleft) -= (i); #define NEXT_OUT(o) \ - do { \ - (*outbuf) += (o); \ - (outleft) -= (o); \ - } while (0) + (*outbuf) += (o); \ + (outleft) -= (o); #define NEXT(i, o) \ - do { \ - NEXT_INCHAR(i); \ - NEXT_OUT(o); \ - } while (0) + NEXT_IN(i) NEXT_OUT(o) #define REQUIRE_INBUF(n) \ if (inleft < (n)) \ @@ -119,55 +116,48 @@ if (outleft < (n)) \ return MBERR_TOOSMALL; -#define INBYTE1 ((*inbuf)[0]) -#define INBYTE2 ((*inbuf)[1]) -#define INBYTE3 ((*inbuf)[2]) -#define INBYTE4 ((*inbuf)[3]) +#define IN1 ((*inbuf)[0]) +#define IN2 ((*inbuf)[1]) +#define IN3 ((*inbuf)[2]) +#define IN4 ((*inbuf)[3]) -#define INCHAR1 PyUnicode_READ(kind, data, *inpos) -#define INCHAR2 PyUnicode_READ(kind, data, *inpos + 1) +#define OUT1(c) ((*outbuf)[0]) = (c); +#define OUT2(c) ((*outbuf)[1]) = (c); +#define OUT3(c) ((*outbuf)[2]) = (c); +#define OUT4(c) ((*outbuf)[3]) = (c); -#define OUTCHAR(c) \ - do { \ - if (_PyUnicodeWriter_WriteChar(writer, (c)) < 0) \ - return MBERR_EXCEPTION; \ - } while (0) - -#define OUTCHAR2(c1, c2) \ - do { \ - Py_UCS4 _c1 = (c1); \ - Py_UCS4 _c2 = (c2); \ - if (_PyUnicodeWriter_Prepare(writer, 2, Py_MAX(_c1, c2)) < 0) \ - return MBERR_EXCEPTION; \ - PyUnicode_WRITE(writer->kind, writer->data, writer->pos, _c1); \ - PyUnicode_WRITE(writer->kind, writer->data, writer->pos + 1, _c2); \ - writer->pos += 2; \ - } while (0) - -#define OUTBYTE1(c) ((*outbuf)[0]) = (c); -#define OUTBYTE2(c) ((*outbuf)[1]) = (c); -#define OUTBYTE3(c) ((*outbuf)[2]) = (c); -#define OUTBYTE4(c) ((*outbuf)[3]) = (c); - -#define WRITEBYTE1(c1) \ +#define WRITE1(c1) \ REQUIRE_OUTBUF(1) \ (*outbuf)[0] = (c1); -#define WRITEBYTE2(c1, c2) \ +#define WRITE2(c1, c2) \ REQUIRE_OUTBUF(2) \ (*outbuf)[0] = (c1); \ (*outbuf)[1] = (c2); -#define WRITEBYTE3(c1, c2, c3) \ +#define WRITE3(c1, c2, c3) \ REQUIRE_OUTBUF(3) \ (*outbuf)[0] = (c1); \ (*outbuf)[1] = (c2); \ (*outbuf)[2] = (c3); -#define WRITEBYTE4(c1, c2, c3, c4) \ +#define WRITE4(c1, c2, c3, c4) \ REQUIRE_OUTBUF(4) \ (*outbuf)[0] = (c1); \ (*outbuf)[1] = (c2); \ (*outbuf)[2] = (c3); \ (*outbuf)[3] = (c4); +#if Py_UNICODE_SIZE == 2 +# define WRITEUCS4(c) \ + REQUIRE_OUTBUF(2) \ + (*outbuf)[0] = Py_UNICODE_HIGH_SURROGATE(c); \ + (*outbuf)[1] = Py_UNICODE_LOW_SURROGATE(c); \ + NEXT_OUT(2) +#else +# define WRITEUCS4(c) \ + REQUIRE_OUTBUF(1) \ + **outbuf = (Py_UNICODE)(c); \ + NEXT_OUT(1) +#endif + #define _TRYMAP_ENC(m, assi, val) \ ((m)->map != NULL && (val) >= (m)->bottom && \ (val)<= (m)->top && ((assi) = (m)->map[(val) - \ @@ -177,41 +167,38 @@ #define TRYMAP_ENC(charset, assi, uni) \ if TRYMAP_ENC_COND(charset, assi, uni) -Py_LOCAL_INLINE(int) -_TRYMAP_DEC_WRITE(_PyUnicodeWriter *writer, Py_UCS4 c) -{ - if (c == UNIINV || _PyUnicodeWriter_WriteChar(writer, c) < 0) - return UNIINV; - else - return c; -} +#define _TRYMAP_DEC(m, assi, val) \ + ((m)->map != NULL && (val) >= (m)->bottom && \ + (val)<= (m)->top && ((assi) = (m)->map[(val) - \ + (m)->bottom]) != UNIINV) +#define TRYMAP_DEC(charset, assi, c1, c2) \ + if _TRYMAP_DEC(&charset##_decmap[c1], assi, c2) -#define _TRYMAP_DEC(m, writer, val) \ - ((m)->map != NULL && \ - (val) >= (m)->bottom && \ - (val)<= (m)->top && \ - _TRYMAP_DEC_WRITE(writer, (m)->map[(val) - (m)->bottom]) != UNIINV) -#define _TRYMAP_DEC_CHAR(m, assi, val) \ - ((m)->map != NULL && \ - (val) >= (m)->bottom && \ - (val)<= (m)->top && \ - ((assi) = (m)->map[(val) - (m)->bottom]) != UNIINV) -#define TRYMAP_DEC(charset, writer, c1, c2) \ - if _TRYMAP_DEC(&charset##_decmap[c1], writer, c2) -#define TRYMAP_DEC_CHAR(charset, assi, c1, c2) \ - if _TRYMAP_DEC_CHAR(&charset##_decmap[c1], assi, c2) - -#define _TRYMAP_ENC_MPLANE(m, assplane, asshi, asslo, val) \ - ((m)->map != NULL && (val) >= (m)->bottom && \ - (val)<= (m)->top && \ - ((assplane) = (m)->map[((val) - (m)->bottom)*3]) != 0 && \ +#define _TRYMAP_ENC_MPLANE(m, assplane, asshi, asslo, val) \ + ((m)->map != NULL && (val) >= (m)->bottom && \ + (val)<= (m)->top && \ + ((assplane) = (m)->map[((val) - (m)->bottom)*3]) != 0 && \ (((asshi) = (m)->map[((val) - (m)->bottom)*3 + 1]), 1) && \ (((asslo) = (m)->map[((val) - (m)->bottom)*3 + 2]), 1)) #define TRYMAP_ENC_MPLANE(charset, assplane, asshi, asslo, uni) \ if _TRYMAP_ENC_MPLANE(&charset##_encmap[(uni) >> 8], \ assplane, asshi, asslo, (uni) & 0xff) -#define TRYMAP_DEC_MPLANE(charset, writer, plane, c1, c2) \ - if _TRYMAP_DEC(&charset##_decmap[plane][c1], writer, c2) +#define TRYMAP_DEC_MPLANE(charset, assi, plane, c1, c2) \ + if _TRYMAP_DEC(&charset##_decmap[plane][c1], assi, c2) + +#if Py_UNICODE_SIZE == 2 +#define DECODE_SURROGATE(c) \ + if (Py_UNICODE_IS_HIGH_SURROGATE(c)) { \ + REQUIRE_INBUF(2) \ + if (Py_UNICODE_IS_LOW_SURROGATE(IN2)) { \ + c = Py_UNICODE_JOIN_SURROGATES(c, IN2); \ + } \ + } +#define GET_INSIZE(c) ((c) > 0xffff ? 2 : 1) +#else +#define DECODE_SURROGATE(c) {;} +#define GET_INSIZE(c) 1 +#endif #define BEGIN_MAPPINGS_LIST static const struct dbcs_map _mapping_list[] = { #define MAPPING_ENCONLY(enc) {#enc, (void*)enc##_encmap, NULL}, @@ -336,7 +323,7 @@ const struct pair_encodemap *haystack, int haystacksize) { int pos, min, max; - Py_UCS4 value = body << 16 | modifier; + ucs4_t value = body << 16 | modifier; min = 0; max = haystacksize; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/emu_jisx0213_2000.h --- a/Modules/cjkcodecs/emu_jisx0213_2000.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/emu_jisx0213_2000.h Fri Feb 01 23:12:09 2013 +0100 @@ -38,9 +38,6 @@ ((c1) == 0x7E && (c2) == 0x7E))) \ return EMULATE_JISX0213_2000_DECODE_INVALID; -#define EMULATE_JISX0213_2000_DECODE_PLANE2(writer, c1, c2) \ - if (config == (void *)2000 && (c1) == 0x7D && (c2) == 0x3B) \ - OUTCHAR(0x9B1D); -#define EMULATE_JISX0213_2000_DECODE_PLANE2_CHAR(assi, c1, c2) \ +#define EMULATE_JISX0213_2000_DECODE_PLANE2(assi, c1, c2) \ if (config == (void *)2000 && (c1) == 0x7D && (c2) == 0x3B) \ (assi) = 0x9B1D; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/mappings_cn.h --- a/Modules/cjkcodecs/mappings_cn.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/mappings_cn.h Fri Feb 01 23:12:09 2013 +0100 @@ -4049,7 +4049,7 @@ static const struct _gb18030_to_unibmp_ranges { - Py_UCS4 first, last; + Py_UNICODE first, last; DBCHAR base; } gb18030_to_unibmp_ranges[] = { {128,163,0},{165,166,36},{169,175,38},{178,182,45},{184,214,50},{216,223,81},{ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/mappings_jisx0213_pair.h --- a/Modules/cjkcodecs/mappings_jisx0213_pair.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/mappings_jisx0213_pair.h Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,7 @@ static const struct widedbcs_index *jisx0213_pair_decmap; static const struct pair_encodemap *jisx0213_pair_encmap; #else -static const Py_UCS4 __jisx0213_pair_decmap[49] = { +static const ucs4_t __jisx0213_pair_decmap[49] = { 810234010,810365082,810496154,810627226,810758298,816525466,816656538, 816787610,816918682,817049754,817574042,818163866,818426010,838283418, 15074048,U,U,U,39060224,39060225,42730240,42730241,39387904,39387905,39453440, diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/multibytecodec.c Fri Feb 01 23:12:09 2013 +0100 @@ -10,16 +10,15 @@ #include "multibytecodec.h" typedef struct { - PyObject *inobj; - Py_ssize_t inpos, inlen; + const Py_UNICODE *inbuf, *inbuf_top, *inbuf_end; unsigned char *outbuf, *outbuf_end; PyObject *excobj, *outobj; } MultibyteEncodeBuffer; typedef struct { const unsigned char *inbuf, *inbuf_top, *inbuf_end; - PyObject *excobj; - _PyUnicodeWriter writer; + Py_UNICODE *outbuf, *outbuf_end; + PyObject *excobj, *outobj; } MultibyteDecodeBuffer; PyDoc_STRVAR(MultibyteCodec_Encode__doc__, @@ -46,7 +45,7 @@ static char *streamkwarglist[] = {"stream", "errors", NULL}; static PyObject *multibytecodec_encode(MultibyteCodec *, - MultibyteCodec_State *, PyObject *, Py_ssize_t *, + MultibyteCodec_State *, const Py_UNICODE **, Py_ssize_t, PyObject *, int); #define MBENC_RESET MBENC_MAX<<1 /* reset after an encoding session */ @@ -198,6 +197,29 @@ goto errorexit; \ } +static int +expand_decodebuffer(MultibyteDecodeBuffer *buf, Py_ssize_t esize) +{ + Py_ssize_t orgpos, orgsize; + + orgpos = (Py_ssize_t)(buf->outbuf - PyUnicode_AS_UNICODE(buf->outobj)); + orgsize = PyUnicode_GET_SIZE(buf->outobj); + if (PyUnicode_Resize(&buf->outobj, orgsize + ( + esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1) + return -1; + + buf->outbuf = PyUnicode_AS_UNICODE(buf->outobj) + orgpos; + buf->outbuf_end = PyUnicode_AS_UNICODE(buf->outobj) + + PyUnicode_GET_SIZE(buf->outobj); + + return 0; +} +#define REQUIRE_DECODEBUFFER(buf, s) { \ + if ((s) < 1 || (buf)->outbuf + (s) > (buf)->outbuf_end) \ + if (expand_decodebuffer(buf, s) == -1) \ + goto errorexit; \ +} + /** * MultibyteCodec object @@ -225,7 +247,7 @@ return 0; /* retry it */ case MBERR_TOOFEW: reason = "incomplete multibyte sequence"; - esize = (Py_ssize_t)buf->inpos; + esize = (Py_ssize_t)(buf->inbuf_end - buf->inbuf); break; case MBERR_INTERNAL: PyErr_SetString(PyExc_RuntimeError, @@ -239,24 +261,14 @@ } if (errors == ERROR_REPLACE) { - PyObject *replchar; + const Py_UNICODE replchar = '?', *inbuf = &replchar; Py_ssize_t r; - Py_ssize_t inpos; - int kind; - void *data; - replchar = PyUnicode_FromOrdinal('?'); - if (replchar == NULL) - goto errorexit; - kind = PyUnicode_KIND(replchar); - data = PyUnicode_DATA(replchar); + for (;;) { + Py_ssize_t outleft; - inpos = 0; - for (;;) { - Py_ssize_t outleft = (Py_ssize_t)(buf->outbuf_end - buf->outbuf); - - r = codec->encode(state, codec->config, - kind, data, &inpos, 1, + outleft = (Py_ssize_t)(buf->outbuf_end - buf->outbuf); + r = codec->encode(state, codec->config, &inbuf, 1, &buf->outbuf, outleft, 0); if (r == MBERR_TOOSMALL) { REQUIRE_ENCODEBUFFER(buf, -1); @@ -266,27 +278,25 @@ break; } - Py_DECREF(replchar); - if (r != 0) { REQUIRE_ENCODEBUFFER(buf, 1); *buf->outbuf++ = '?'; } } if (errors == ERROR_IGNORE || errors == ERROR_REPLACE) { - buf->inpos += esize; + buf->inbuf += esize; return 0; } - start = (Py_ssize_t)buf->inpos; + start = (Py_ssize_t)(buf->inbuf - buf->inbuf_top); end = start + esize; /* use cached exception object if available */ if (buf->excobj == NULL) { - buf->excobj = PyObject_CallFunction(PyExc_UnicodeEncodeError, - "sOnns", - codec->encoding, buf->inobj, - start, end, reason); + buf->excobj = PyUnicodeEncodeError_Create(codec->encoding, + buf->inbuf_top, + buf->inbuf_end - buf->inbuf_top, + start, end, reason); if (buf->excobj == NULL) goto errorexit; } @@ -315,10 +325,10 @@ } if (PyUnicode_Check(tobj)) { - Py_ssize_t inpos; + const Py_UNICODE *uraw = PyUnicode_AS_UNICODE(tobj); - retstr = multibytecodec_encode(codec, state, tobj, - &inpos, ERROR_STRICT, + retstr = multibytecodec_encode(codec, state, &uraw, + PyUnicode_GET_SIZE(tobj), ERROR_STRICT, MBENC_FLUSH); if (retstr == NULL) goto errorexit; @@ -337,15 +347,15 @@ newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); if (newpos < 0 && !PyErr_Occurred()) - newpos += (Py_ssize_t)buf->inlen; - if (newpos < 0 || newpos > buf->inlen) { + newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top); + if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) { PyErr_Clear(); PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", newpos); goto errorexit; } - buf->inpos = newpos; + buf->inbuf = buf->inbuf_top + newpos; Py_DECREF(retobj); Py_DECREF(retstr); @@ -364,7 +374,7 @@ PyObject *errors, Py_ssize_t e) { PyObject *retobj = NULL, *retuni = NULL; - Py_ssize_t newpos; + Py_ssize_t retunisize, newpos; const char *reason; Py_ssize_t esize, start, end; @@ -375,6 +385,7 @@ else { switch (e) { case MBERR_TOOSMALL: + REQUIRE_DECODEBUFFER(buf, -1); return 0; /* retry it */ case MBERR_TOOFEW: reason = "incomplete multibyte sequence"; @@ -384,8 +395,6 @@ PyErr_SetString(PyExc_RuntimeError, "internal codec error"); return -1; - case MBERR_EXCEPTION: - return -1; default: PyErr_SetString(PyExc_RuntimeError, "unknown runtime error"); @@ -394,9 +403,8 @@ } if (errors == ERROR_REPLACE) { - if (_PyUnicodeWriter_WriteChar(&buf->writer, - Py_UNICODE_REPLACEMENT_CHARACTER) < 0) - goto errorexit; + REQUIRE_DECODEBUFFER(buf, 1); + *buf->outbuf++ = Py_UNICODE_REPLACEMENT_CHARACTER; } if (errors == ERROR_IGNORE || errors == ERROR_REPLACE) { buf->inbuf += esize; @@ -439,8 +447,15 @@ goto errorexit; } - if (_PyUnicodeWriter_WriteStr(&buf->writer, retuni) < 0) + if (PyUnicode_AsUnicode(retuni) == NULL) goto errorexit; + retunisize = PyUnicode_GET_SIZE(retuni); + if (retunisize > 0) { + REQUIRE_DECODEBUFFER(buf, retunisize); + memcpy((char *)buf->outbuf, PyUnicode_AS_UNICODE(retuni), + retunisize * Py_UNICODE_SIZE); + buf->outbuf += retunisize; + } newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); if (newpos < 0 && !PyErr_Occurred()) @@ -464,29 +479,19 @@ static PyObject * multibytecodec_encode(MultibyteCodec *codec, MultibyteCodec_State *state, - PyObject *text, Py_ssize_t *inpos_t, + const Py_UNICODE **data, Py_ssize_t datalen, PyObject *errors, int flags) { MultibyteEncodeBuffer buf; Py_ssize_t finalsize, r = 0; - Py_ssize_t datalen; - int kind; - void *data; - - if (PyUnicode_READY(text) < 0) - return NULL; - datalen = PyUnicode_GET_LENGTH(text); if (datalen == 0 && !(flags & MBENC_RESET)) return PyBytes_FromStringAndSize(NULL, 0); buf.excobj = NULL; buf.outobj = NULL; - buf.inobj = text; /* borrowed reference */ - buf.inpos = 0; - buf.inlen = datalen; - kind = PyUnicode_KIND(buf.inobj); - data = PyUnicode_DATA(buf.inobj); + buf.inbuf = buf.inbuf_top = *data; + buf.inbuf_end = buf.inbuf_top + datalen; if (datalen > (PY_SSIZE_T_MAX - 16) / 2) { PyErr_NoMemory(); @@ -499,14 +504,14 @@ buf.outbuf = (unsigned char *)PyBytes_AS_STRING(buf.outobj); buf.outbuf_end = buf.outbuf + PyBytes_GET_SIZE(buf.outobj); - while (buf.inpos < buf.inlen) { + while (buf.inbuf < buf.inbuf_end) { + Py_ssize_t inleft, outleft; + /* we don't reuse inleft and outleft here. * error callbacks can relocate the cursor anywhere on buffer*/ - Py_ssize_t outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf); - - r = codec->encode(state, codec->config, - kind, data, - &buf.inpos, buf.inlen, + inleft = (Py_ssize_t)(buf.inbuf_end - buf.inbuf); + outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf); + r = codec->encode(state, codec->config, &buf.inbuf, inleft, &buf.outbuf, outleft, flags); if ((r == 0) || (r == MBERR_TOOFEW && !(flags & MBENC_FLUSH))) break; @@ -537,8 +542,7 @@ if (_PyBytes_Resize(&buf.outobj, finalsize) == -1) goto errorexit; - if (inpos_t) - *inpos_t = buf.inpos; + *data = buf.inbuf; Py_XDECREF(buf.excobj); return buf.outobj; @@ -553,6 +557,7 @@ PyObject *args, PyObject *kwargs) { MultibyteCodec_State state; + Py_UNICODE *data; PyObject *errorcb, *r, *arg, *ucvt; const char *errors = NULL; Py_ssize_t datalen; @@ -575,11 +580,11 @@ } } - if (PyUnicode_READY(arg) < 0) { + data = PyUnicode_AsUnicodeAndSize(arg, &datalen); + if (data == NULL) { Py_XDECREF(ucvt); return NULL; } - datalen = PyUnicode_GET_LENGTH(arg); errorcb = internal_error_callback(errors); if (errorcb == NULL) { @@ -591,7 +596,7 @@ self->codec->encinit(&state, self->codec->config) != 0) goto errorexit; r = multibytecodec_encode(self->codec, &state, - arg, NULL, errorcb, + (const Py_UNICODE **)&data, datalen, errorcb, MBENC_FLUSH | MBENC_RESET); if (r == NULL) goto errorexit; @@ -612,10 +617,10 @@ { MultibyteCodec_State state; MultibyteDecodeBuffer buf; - PyObject *errorcb, *res; + PyObject *errorcb; Py_buffer pdata; const char *data, *errors = NULL; - Py_ssize_t datalen; + Py_ssize_t datalen, finalsize; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|z:decode", codeckwarglist, &pdata, &errors)) @@ -635,23 +640,29 @@ return make_tuple(PyUnicode_New(0, 0), 0); } - _PyUnicodeWriter_Init(&buf.writer); - buf.writer.min_length = datalen; buf.excobj = NULL; buf.inbuf = buf.inbuf_top = (unsigned char *)data; buf.inbuf_end = buf.inbuf_top + datalen; + buf.outobj = PyUnicode_FromUnicode(NULL, datalen); + if (buf.outobj == NULL) + goto errorexit; + buf.outbuf = PyUnicode_AS_UNICODE(buf.outobj); + if (buf.outbuf == NULL) + goto errorexit; + buf.outbuf_end = buf.outbuf + PyUnicode_GET_SIZE(buf.outobj); if (self->codec->decinit != NULL && self->codec->decinit(&state, self->codec->config) != 0) goto errorexit; while (buf.inbuf < buf.inbuf_end) { - Py_ssize_t inleft, r; + Py_ssize_t inleft, outleft, r; inleft = (Py_ssize_t)(buf.inbuf_end - buf.inbuf); + outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf); r = self->codec->decode(&state, self->codec->config, - &buf.inbuf, inleft, &buf.writer); + &buf.inbuf, inleft, &buf.outbuf, outleft); if (r == 0) break; else if (multibytecodec_decerror(self->codec, &state, @@ -659,20 +670,23 @@ goto errorexit; } - res = _PyUnicodeWriter_Finish(&buf.writer); - if (res == NULL) - goto errorexit; + finalsize = (Py_ssize_t)(buf.outbuf - + PyUnicode_AS_UNICODE(buf.outobj)); + + if (finalsize != PyUnicode_GET_SIZE(buf.outobj)) + if (PyUnicode_Resize(&buf.outobj, finalsize) == -1) + goto errorexit; PyBuffer_Release(&pdata); Py_XDECREF(buf.excobj); ERROR_DECREF(errorcb); - return make_tuple(res, datalen); + return make_tuple(buf.outobj, datalen); errorexit: PyBuffer_Release(&pdata); ERROR_DECREF(errorcb); Py_XDECREF(buf.excobj); - _PyUnicodeWriter_Dealloc(&buf.writer); + Py_XDECREF(buf.outobj); return NULL; } @@ -738,9 +752,9 @@ PyObject *unistr, int final) { PyObject *ucvt, *r = NULL; - PyObject *inbuf = NULL; - Py_ssize_t inpos, datalen; - PyObject *origpending = NULL; + Py_UNICODE *inbuf, *inbuf_end, *inbuf_tmp = NULL; + Py_ssize_t datalen, origpending; + wchar_t *data; if (PyUnicode_Check(unistr)) ucvt = NULL; @@ -756,66 +770,69 @@ } } - if (ctx->pending) { - PyObject *inbuf_tmp; + data = PyUnicode_AsUnicodeAndSize(unistr, &datalen); + if (data == NULL) + goto errorexit; + origpending = ctx->pendingsize; - Py_INCREF(ctx->pending); - origpending = ctx->pending; - - Py_INCREF(ctx->pending); - inbuf_tmp = ctx->pending; - PyUnicode_Append(&inbuf_tmp, unistr); + if (origpending > 0) { + if (datalen > PY_SSIZE_T_MAX - ctx->pendingsize) { + PyErr_NoMemory(); + /* inbuf_tmp == NULL */ + goto errorexit; + } + inbuf_tmp = PyMem_New(Py_UNICODE, datalen + ctx->pendingsize); if (inbuf_tmp == NULL) goto errorexit; - Py_CLEAR(ctx->pending); + memcpy(inbuf_tmp, ctx->pending, + Py_UNICODE_SIZE * ctx->pendingsize); + memcpy(inbuf_tmp + ctx->pendingsize, + PyUnicode_AS_UNICODE(unistr), + Py_UNICODE_SIZE * datalen); + datalen += ctx->pendingsize; + ctx->pendingsize = 0; inbuf = inbuf_tmp; } - else { - origpending = NULL; + else + inbuf = (Py_UNICODE *)PyUnicode_AS_UNICODE(unistr); - Py_INCREF(unistr); - inbuf = unistr; - } - if (PyUnicode_READY(inbuf) < 0) - goto errorexit; - inpos = 0; - datalen = PyUnicode_GET_LENGTH(inbuf); + inbuf_end = inbuf + datalen; r = multibytecodec_encode(ctx->codec, &ctx->state, - inbuf, &inpos, - ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0); + (const Py_UNICODE **)&inbuf, datalen, + ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0); if (r == NULL) { /* recover the original pending buffer */ - Py_CLEAR(ctx->pending); - ctx->pending = origpending; - origpending = NULL; + if (origpending > 0) + memcpy(ctx->pending, inbuf_tmp, + Py_UNICODE_SIZE * origpending); + ctx->pendingsize = origpending; goto errorexit; } - Py_XDECREF(origpending); - if (inpos < datalen) { - if (datalen - inpos > MAXENCPENDING) { + if (inbuf < inbuf_end) { + ctx->pendingsize = (Py_ssize_t)(inbuf_end - inbuf); + if (ctx->pendingsize > MAXENCPENDING) { /* normal codecs can't reach here */ + ctx->pendingsize = 0; PyErr_SetString(PyExc_UnicodeError, "pending buffer overflow"); goto errorexit; } - ctx->pending = PyUnicode_Substring(inbuf, inpos, datalen); - if (ctx->pending == NULL) { - /* normal codecs can't reach here */ - goto errorexit; - } + memcpy(ctx->pending, inbuf, + ctx->pendingsize * Py_UNICODE_SIZE); } - Py_DECREF(inbuf); + if (inbuf_tmp != NULL) + PyMem_Del(inbuf_tmp); Py_XDECREF(ucvt); return r; errorexit: + if (inbuf_tmp != NULL) + PyMem_Del(inbuf_tmp); Py_XDECREF(r); Py_XDECREF(ucvt); - Py_XDECREF(origpending); - Py_XDECREF(inbuf); return NULL; } @@ -842,7 +859,17 @@ { buf->inbuf = buf->inbuf_top = (const unsigned char *)data; buf->inbuf_end = buf->inbuf_top + size; - buf->writer.min_length += size; + if (buf->outobj == NULL) { /* only if outobj is not allocated yet */ + buf->outobj = PyUnicode_FromUnicode(NULL, size); + if (buf->outobj == NULL) + return -1; + buf->outbuf = PyUnicode_AsUnicode(buf->outobj); + if (buf->outbuf == NULL) + return -1; + buf->outbuf_end = buf->outbuf + + PyUnicode_GET_SIZE(buf->outobj); + } + return 0; } @@ -851,13 +878,14 @@ MultibyteDecodeBuffer *buf) { while (buf->inbuf < buf->inbuf_end) { - Py_ssize_t inleft; + Py_ssize_t inleft, outleft; Py_ssize_t r; inleft = (Py_ssize_t)(buf->inbuf_end - buf->inbuf); + outleft = (Py_ssize_t)(buf->outbuf_end - buf->outbuf); r = ctx->codec->decode(&ctx->state, ctx->codec->config, - &buf->inbuf, inleft, &buf->writer); + &buf->inbuf, inleft, &buf->outbuf, outleft); if (r == 0 || r == MBERR_TOOFEW) break; else if (multibytecodec_decerror(ctx->codec, &ctx->state, @@ -899,7 +927,7 @@ if (r != 0) return NULL; } - Py_CLEAR(self->pending); + self->pendingsize = 0; Py_RETURN_NONE; } @@ -935,7 +963,7 @@ } self->codec = ((MultibyteCodecObject *)codec)->codec; - self->pending = NULL; + self->pendingsize = 0; self->errors = internal_error_callback(errors); if (self->errors == NULL) goto errorexit; @@ -1030,9 +1058,8 @@ MultibyteDecodeBuffer buf; char *data, *wdata = NULL; Py_buffer pdata; - Py_ssize_t wsize, size, origpending; + Py_ssize_t wsize, finalsize = 0, size, origpending; int final = 0; - PyObject *res; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i:decode", incrementalkwarglist, &pdata, &final)) @@ -1040,8 +1067,7 @@ data = pdata.buf; size = pdata.len; - _PyUnicodeWriter_Init(&buf.writer); - buf.excobj = NULL; + buf.outobj = buf.excobj = NULL; origpending = self->pendingsize; if (self->pendingsize == 0) { @@ -1055,10 +1081,8 @@ } wsize = size + self->pendingsize; wdata = PyMem_Malloc(wsize); - if (wdata == NULL) { - PyErr_NoMemory(); + if (wdata == NULL) goto errorexit; - } memcpy(wdata, self->pending, self->pendingsize); memcpy(wdata + self->pendingsize, data, size); self->pendingsize = 0; @@ -1085,22 +1109,23 @@ goto errorexit; } - res = _PyUnicodeWriter_Finish(&buf.writer); - if (res == NULL) - goto errorexit; + finalsize = (Py_ssize_t)(buf.outbuf - PyUnicode_AS_UNICODE(buf.outobj)); + if (finalsize != PyUnicode_GET_SIZE(buf.outobj)) + if (PyUnicode_Resize(&buf.outobj, finalsize) == -1) + goto errorexit; PyBuffer_Release(&pdata); if (wdata != data) PyMem_Del(wdata); Py_XDECREF(buf.excobj); - return res; + return buf.outobj; errorexit: PyBuffer_Release(&pdata); if (wdata != NULL && wdata != data) PyMem_Del(wdata); Py_XDECREF(buf.excobj); - _PyUnicodeWriter_Dealloc(&buf.writer); + Py_XDECREF(buf.outobj); return NULL; } @@ -1240,14 +1265,13 @@ const char *method, Py_ssize_t sizehint) { MultibyteDecodeBuffer buf; - PyObject *cres, *res; - Py_ssize_t rsize; + PyObject *cres; + Py_ssize_t rsize, finalsize = 0; if (sizehint == 0) return PyUnicode_New(0, 0); - _PyUnicodeWriter_Init(&buf.writer); - buf.excobj = NULL; + buf.outobj = buf.excobj = NULL; cres = NULL; for (;;) { @@ -1279,19 +1303,19 @@ if (PyBytes_GET_SIZE(cres) > PY_SSIZE_T_MAX - self->pendingsize) { PyErr_NoMemory(); goto errorexit; - } - rsize = PyBytes_GET_SIZE(cres) + self->pendingsize; - ctr = PyBytes_FromStringAndSize(NULL, rsize); - if (ctr == NULL) - goto errorexit; - ctrdata = PyBytes_AS_STRING(ctr); - memcpy(ctrdata, self->pending, self->pendingsize); - memcpy(ctrdata + self->pendingsize, - PyBytes_AS_STRING(cres), - PyBytes_GET_SIZE(cres)); - Py_DECREF(cres); - cres = ctr; - self->pendingsize = 0; + } + rsize = PyBytes_GET_SIZE(cres) + self->pendingsize; + ctr = PyBytes_FromStringAndSize(NULL, rsize); + if (ctr == NULL) + goto errorexit; + ctrdata = PyBytes_AS_STRING(ctr); + memcpy(ctrdata, self->pending, self->pendingsize); + memcpy(ctrdata + self->pendingsize, + PyBytes_AS_STRING(cres), + PyBytes_GET_SIZE(cres)); + Py_DECREF(cres); + cres = ctr; + self->pendingsize = 0; } rsize = PyBytes_GET_SIZE(cres); @@ -1316,27 +1340,29 @@ goto errorexit; } + finalsize = (Py_ssize_t)(buf.outbuf - + PyUnicode_AS_UNICODE(buf.outobj)); Py_DECREF(cres); cres = NULL; - if (sizehint < 0 || buf.writer.pos != 0 || rsize == 0) + if (sizehint < 0 || finalsize != 0 || rsize == 0) break; sizehint = 1; /* read 1 more byte and retry */ } - res = _PyUnicodeWriter_Finish(&buf.writer); - if (res == NULL) - goto errorexit; + if (finalsize != PyUnicode_GET_SIZE(buf.outobj)) + if (PyUnicode_Resize(&buf.outobj, finalsize) == -1) + goto errorexit; Py_XDECREF(cres); Py_XDECREF(buf.excobj); - return res; + return buf.outobj; errorexit: Py_XDECREF(cres); Py_XDECREF(buf.excobj); - _PyUnicodeWriter_Dealloc(&buf.writer); + Py_XDECREF(buf.outobj); return NULL; } @@ -1623,16 +1649,18 @@ static PyObject * mbstreamwriter_reset(MultibyteStreamWriterObject *self) { + const Py_UNICODE *pending; PyObject *pwrt; + pending = self->pending; pwrt = multibytecodec_encode(self->codec, &self->state, - self->pending, NULL, self->errors, + &pending, self->pendingsize, self->errors, MBENC_FLUSH | MBENC_RESET); /* some pending buffer can be truncated when UnicodeEncodeError is * raised on 'strict' mode. but, 'reset' method is designed to * reset the pending buffer or states so failed string sequence * ought to be missed */ - Py_CLEAR(self->pending); + self->pendingsize = 0; if (pwrt == NULL) return NULL; @@ -1678,7 +1706,7 @@ self->codec = ((MultibyteCodecObject *)codec)->codec; self->stream = stream; Py_INCREF(stream); - self->pending = NULL; + self->pendingsize = 0; self->errors = internal_error_callback(errors); if (self->errors == NULL) goto errorexit; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cjkcodecs/multibytecodec.h --- a/Modules/cjkcodecs/multibytecodec.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cjkcodecs/multibytecodec.h Fri Feb 01 23:12:09 2013 +0100 @@ -10,6 +10,12 @@ extern "C" { #endif +#ifdef uint32_t +typedef uint32_t ucs4_t; +#else +typedef unsigned int ucs4_t; +#endif + #ifdef uint16_t typedef uint16_t ucs2_t, DBCHAR; #else @@ -21,14 +27,13 @@ int i; unsigned char c[8]; ucs2_t u2[4]; - Py_UCS4 u4[2]; + ucs4_t u4[2]; } MultibyteCodec_State; typedef int (*mbcodec_init)(const void *config); typedef Py_ssize_t (*mbencode_func)(MultibyteCodec_State *state, const void *config, - int kind, void *data, - Py_ssize_t *inpos, Py_ssize_t inlen, + const Py_UNICODE **inbuf, Py_ssize_t inleft, unsigned char **outbuf, Py_ssize_t outleft, int flags); typedef int (*mbencodeinit_func)(MultibyteCodec_State *state, @@ -39,7 +44,7 @@ typedef Py_ssize_t (*mbdecode_func)(MultibyteCodec_State *state, const void *config, const unsigned char **inbuf, Py_ssize_t inleft, - _PyUnicodeWriter *writer); + Py_UNICODE **outbuf, Py_ssize_t outleft); typedef int (*mbdecodeinit_func)(MultibyteCodec_State *state, const void *config); typedef Py_ssize_t (*mbdecodereset_func)(MultibyteCodec_State *state, @@ -76,7 +81,8 @@ #define MAXENCPENDING 2 #define _MultibyteStatefulEncoder_HEAD \ _MultibyteStatefulCodec_HEAD \ - PyObject *pending; + Py_UNICODE pending[MAXENCPENDING]; \ + Py_ssize_t pendingsize; typedef struct { _MultibyteStatefulEncoder_HEAD } MultibyteStatefulEncoderContext; @@ -112,7 +118,6 @@ #define MBERR_TOOSMALL (-1) /* insufficient output buffer space */ #define MBERR_TOOFEW (-2) /* incomplete input buffer */ #define MBERR_INTERNAL (-3) /* internal runtime error */ -#define MBERR_EXCEPTION (-4) /* an exception has been raised */ #define ERROR_STRICT (PyObject *)(1) #define ERROR_IGNORE (PyObject *)(2) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/cmathmodule.c --- a/Modules/cmathmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/cmathmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -1006,13 +1006,6 @@ else errno = 0; } - else if (phi == 0.0) { - /* Workaround for buggy results with phi=-0.0 on OS X 10.8. See - bugs.python.org/issue18513. */ - z.real = r; - z.imag = r * phi; - errno = 0; - } else { z.real = r * cos(phi); z.imag = r * sin(phi); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/expat/xmltok.c --- a/Modules/expat/xmltok.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/expat/xmltok.c Fri Feb 01 23:12:09 2013 +0100 @@ -1584,7 +1584,7 @@ if (ptr[0] == '\0') { /* 0 isn't a legal data character. Furthermore a document entity can only start with ASCII characters. So the only - way this can fail to be big-endian UTF-16 is if it is an + way this can fail to be big-endian UTF-16 if it it's an external parsed general entity that's labelled as UTF-16LE. */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/faulthandler.c --- a/Modules/faulthandler.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/faulthandler.c Fri Feb 01 23:12:09 2013 +0100 @@ -475,7 +475,7 @@ Py_CLEAR(thread.file); if (thread.header) { - PyMem_Free(thread.header); + free(thread.header); thread.header = NULL; } } @@ -504,7 +504,7 @@ "Timeout (%lu:%02lu:%02lu)!\n", hour, min, sec); - return _PyMem_Strdup(buffer); + return strdup(buffer); } static PyObject* @@ -570,7 +570,7 @@ if (PyThread_start_new_thread(faulthandler_thread, NULL) == -1) { PyThread_release_lock(thread.running); Py_CLEAR(thread.file); - PyMem_Free(header); + free(header); thread.header = NULL; PyErr_SetString(PyExc_RuntimeError, "unable to start watchdog thread"); @@ -729,10 +729,9 @@ return NULL; if (user_signals == NULL) { - user_signals = PyMem_Malloc(NSIG * sizeof(user_signal_t)); + user_signals = calloc(NSIG, sizeof(user_signal_t)); if (user_signals == NULL) return PyErr_NoMemory(); - memset(user_signals, 0, NSIG * sizeof(user_signal_t)); } user = &user_signals[signum]; @@ -742,8 +741,6 @@ PyErr_SetFromErrno(PyExc_OSError); return NULL; } - - user->previous = previous; } Py_XDECREF(user->file); @@ -752,6 +749,7 @@ user->fd = fd; user->all_threads = all_threads; user->chain = chain; + user->previous = previous; user->interp = tstate->interp; user->enabled = 1; @@ -1137,7 +1135,7 @@ if (user_signals != NULL) { for (signum=0; signum < NSIG; signum++) faulthandler_unregister(&user_signals[signum], signum); - PyMem_Free(user_signals); + free(user_signals); user_signals = NULL; } #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/fcntlmodule.c --- a/Modules/fcntlmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/fcntlmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -424,179 +424,191 @@ /* Module initialisation */ +static int +ins(PyObject* d, char* symbol, long value) +{ + PyObject* v = PyLong_FromLong(value); + if (!v || PyDict_SetItemString(d, symbol, v) < 0) + return -1; + + Py_DECREF(v); + return 0; +} + +#define INS(x) if (ins(d, #x, (long)x)) return -1 static int -all_ins(PyObject* m) +all_ins(PyObject* d) { - if (PyModule_AddIntMacro(m, LOCK_SH)) return -1; - if (PyModule_AddIntMacro(m, LOCK_EX)) return -1; - if (PyModule_AddIntMacro(m, LOCK_NB)) return -1; - if (PyModule_AddIntMacro(m, LOCK_UN)) return -1; + if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1; + if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1; + if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1; + if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1; /* GNU extensions, as of glibc 2.2.4 */ #ifdef LOCK_MAND - if (PyModule_AddIntMacro(m, LOCK_MAND)) return -1; + if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) return -1; #endif #ifdef LOCK_READ - if (PyModule_AddIntMacro(m, LOCK_READ)) return -1; + if (ins(d, "LOCK_READ", (long)LOCK_READ)) return -1; #endif #ifdef LOCK_WRITE - if (PyModule_AddIntMacro(m, LOCK_WRITE)) return -1; + if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) return -1; #endif #ifdef LOCK_RW - if (PyModule_AddIntMacro(m, LOCK_RW)) return -1; + if (ins(d, "LOCK_RW", (long)LOCK_RW)) return -1; #endif #ifdef F_DUPFD - if (PyModule_AddIntMacro(m, F_DUPFD)) return -1; + if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1; #endif #ifdef F_DUPFD_CLOEXEC - if (PyModule_AddIntMacro(m, F_DUPFD_CLOEXEC)) return -1; + if (ins(d, "F_DUPFD_CLOEXEC", (long)F_DUPFD_CLOEXEC)) return -1; #endif #ifdef F_GETFD - if (PyModule_AddIntMacro(m, F_GETFD)) return -1; + if (ins(d, "F_GETFD", (long)F_GETFD)) return -1; #endif #ifdef F_SETFD - if (PyModule_AddIntMacro(m, F_SETFD)) return -1; + if (ins(d, "F_SETFD", (long)F_SETFD)) return -1; #endif #ifdef F_GETFL - if (PyModule_AddIntMacro(m, F_GETFL)) return -1; + if (ins(d, "F_GETFL", (long)F_GETFL)) return -1; #endif #ifdef F_SETFL - if (PyModule_AddIntMacro(m, F_SETFL)) return -1; + if (ins(d, "F_SETFL", (long)F_SETFL)) return -1; #endif #ifdef F_GETLK - if (PyModule_AddIntMacro(m, F_GETLK)) return -1; + if (ins(d, "F_GETLK", (long)F_GETLK)) return -1; #endif #ifdef F_SETLK - if (PyModule_AddIntMacro(m, F_SETLK)) return -1; + if (ins(d, "F_SETLK", (long)F_SETLK)) return -1; #endif #ifdef F_SETLKW - if (PyModule_AddIntMacro(m, F_SETLKW)) return -1; + if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1; #endif #ifdef F_GETOWN - if (PyModule_AddIntMacro(m, F_GETOWN)) return -1; + if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1; #endif #ifdef F_SETOWN - if (PyModule_AddIntMacro(m, F_SETOWN)) return -1; + if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1; #endif #ifdef F_GETSIG - if (PyModule_AddIntMacro(m, F_GETSIG)) return -1; + if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1; #endif #ifdef F_SETSIG - if (PyModule_AddIntMacro(m, F_SETSIG)) return -1; + if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1; #endif #ifdef F_RDLCK - if (PyModule_AddIntMacro(m, F_RDLCK)) return -1; + if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1; #endif #ifdef F_WRLCK - if (PyModule_AddIntMacro(m, F_WRLCK)) return -1; + if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1; #endif #ifdef F_UNLCK - if (PyModule_AddIntMacro(m, F_UNLCK)) return -1; + if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1; #endif /* LFS constants */ #ifdef F_GETLK64 - if (PyModule_AddIntMacro(m, F_GETLK64)) return -1; + if (ins(d, "F_GETLK64", (long)F_GETLK64)) return -1; #endif #ifdef F_SETLK64 - if (PyModule_AddIntMacro(m, F_SETLK64)) return -1; + if (ins(d, "F_SETLK64", (long)F_SETLK64)) return -1; #endif #ifdef F_SETLKW64 - if (PyModule_AddIntMacro(m, F_SETLKW64)) return -1; + if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) return -1; #endif /* GNU extensions, as of glibc 2.2.4. */ #ifdef FASYNC - if (PyModule_AddIntMacro(m, FASYNC)) return -1; + if (ins(d, "FASYNC", (long)FASYNC)) return -1; #endif #ifdef F_SETLEASE - if (PyModule_AddIntMacro(m, F_SETLEASE)) return -1; + if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) return -1; #endif #ifdef F_GETLEASE - if (PyModule_AddIntMacro(m, F_GETLEASE)) return -1; + if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) return -1; #endif #ifdef F_NOTIFY - if (PyModule_AddIntMacro(m, F_NOTIFY)) return -1; + if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) return -1; #endif /* Old BSD flock(). */ #ifdef F_EXLCK - if (PyModule_AddIntMacro(m, F_EXLCK)) return -1; + if (ins(d, "F_EXLCK", (long)F_EXLCK)) return -1; #endif #ifdef F_SHLCK - if (PyModule_AddIntMacro(m, F_SHLCK)) return -1; + if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1; #endif /* OS X specifics */ #ifdef F_FULLFSYNC - if (PyModule_AddIntMacro(m, F_FULLFSYNC)) return -1; + if (ins(d, "F_FULLFSYNC", (long)F_FULLFSYNC)) return -1; #endif #ifdef F_NOCACHE - if (PyModule_AddIntMacro(m, F_NOCACHE)) return -1; + if (ins(d, "F_NOCACHE", (long)F_NOCACHE)) return -1; #endif /* For F_{GET|SET}FL */ #ifdef FD_CLOEXEC - if (PyModule_AddIntMacro(m, FD_CLOEXEC)) return -1; + if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1; #endif /* For F_NOTIFY */ #ifdef DN_ACCESS - if (PyModule_AddIntMacro(m, DN_ACCESS)) return -1; + if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) return -1; #endif #ifdef DN_MODIFY - if (PyModule_AddIntMacro(m, DN_MODIFY)) return -1; + if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) return -1; #endif #ifdef DN_CREATE - if (PyModule_AddIntMacro(m, DN_CREATE)) return -1; + if (ins(d, "DN_CREATE", (long)DN_CREATE)) return -1; #endif #ifdef DN_DELETE - if (PyModule_AddIntMacro(m, DN_DELETE)) return -1; + if (ins(d, "DN_DELETE", (long)DN_DELETE)) return -1; #endif #ifdef DN_RENAME - if (PyModule_AddIntMacro(m, DN_RENAME)) return -1; + if (ins(d, "DN_RENAME", (long)DN_RENAME)) return -1; #endif #ifdef DN_ATTRIB - if (PyModule_AddIntMacro(m, DN_ATTRIB)) return -1; + if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) return -1; #endif #ifdef DN_MULTISHOT - if (PyModule_AddIntMacro(m, DN_MULTISHOT)) return -1; + if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1; #endif #ifdef HAVE_STROPTS_H /* Unix 98 guarantees that these are in stropts.h. */ - if (PyModule_AddIntMacro(m, I_PUSH)) return -1; - if (PyModule_AddIntMacro(m, I_POP)) return -1; - if (PyModule_AddIntMacro(m, I_LOOK)) return -1; - if (PyModule_AddIntMacro(m, I_FLUSH)) return -1; - if (PyModule_AddIntMacro(m, I_FLUSHBAND)) return -1; - if (PyModule_AddIntMacro(m, I_SETSIG)) return -1; - if (PyModule_AddIntMacro(m, I_GETSIG)) return -1; - if (PyModule_AddIntMacro(m, I_FIND)) return -1; - if (PyModule_AddIntMacro(m, I_PEEK)) return -1; - if (PyModule_AddIntMacro(m, I_SRDOPT)) return -1; - if (PyModule_AddIntMacro(m, I_GRDOPT)) return -1; - if (PyModule_AddIntMacro(m, I_NREAD)) return -1; - if (PyModule_AddIntMacro(m, I_FDINSERT)) return -1; - if (PyModule_AddIntMacro(m, I_STR)) return -1; - if (PyModule_AddIntMacro(m, I_SWROPT)) return -1; + INS(I_PUSH); + INS(I_POP); + INS(I_LOOK); + INS(I_FLUSH); + INS(I_FLUSHBAND); + INS(I_SETSIG); + INS(I_GETSIG); + INS(I_FIND); + INS(I_PEEK); + INS(I_SRDOPT); + INS(I_GRDOPT); + INS(I_NREAD); + INS(I_FDINSERT); + INS(I_STR); + INS(I_SWROPT); #ifdef I_GWROPT /* despite the comment above, old-ish glibcs miss a couple... */ - if (PyModule_AddIntMacro(m, I_GWROPT)) return -1; + INS(I_GWROPT); #endif - if (PyModule_AddIntMacro(m, I_SENDFD)) return -1; - if (PyModule_AddIntMacro(m, I_RECVFD)) return -1; - if (PyModule_AddIntMacro(m, I_LIST)) return -1; - if (PyModule_AddIntMacro(m, I_ATMARK)) return -1; - if (PyModule_AddIntMacro(m, I_CKBAND)) return -1; - if (PyModule_AddIntMacro(m, I_GETBAND)) return -1; - if (PyModule_AddIntMacro(m, I_CANPUT)) return -1; - if (PyModule_AddIntMacro(m, I_SETCLTIME)) return -1; + INS(I_SENDFD); + INS(I_RECVFD); + INS(I_LIST); + INS(I_ATMARK); + INS(I_CKBAND); + INS(I_GETBAND); + INS(I_CANPUT); + INS(I_SETCLTIME); #ifdef I_GETCLTIME - if (PyModule_AddIntMacro(m, I_GETCLTIME)) return -1; + INS(I_GETCLTIME); #endif - if (PyModule_AddIntMacro(m, I_LINK)) return -1; - if (PyModule_AddIntMacro(m, I_UNLINK)) return -1; - if (PyModule_AddIntMacro(m, I_PLINK)) return -1; - if (PyModule_AddIntMacro(m, I_PUNLINK)) return -1; + INS(I_LINK); + INS(I_UNLINK); + INS(I_PLINK); + INS(I_PUNLINK); #endif return 0; @@ -618,7 +630,7 @@ PyMODINIT_FUNC PyInit_fcntl(void) { - PyObject *m; + PyObject *m, *d; /* Create the module and add the functions and documentation */ m = PyModule_Create(&fcntlmodule); @@ -626,6 +638,7 @@ return NULL; /* Add some symbolic constants to the module */ - all_ins(m); + d = PyModule_GetDict(m); + all_ins(d); return m; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/gcmodule.c --- a/Modules/gcmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/gcmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -118,7 +118,7 @@ /* NOTE: about untracking of mutable objects. - + Certain types of container cannot participate in a reference cycle, and so do not need to be tracked by the garbage collector. Untracking these objects reduces the cost of garbage collections. However, determining @@ -136,10 +136,10 @@ not survive until garbage collection. It is therefore not worthwhile to untrack eligible tuples at creation time. - Instead, all tuples except the empty tuple are tracked when created. - During garbage collection it is determined whether any surviving tuples - can be untracked. A tuple can be untracked if all of its contents are - already not tracked. Tuples are examined for untracking in all garbage + Instead, all tuples except the empty tuple are tracked when created. + During garbage collection it is determined whether any surviving tuples + can be untracked. A tuple can be untracked if all of its contents are + already not tracked. Tuples are examined for untracking in all garbage collection cycles. It may take more than one cycle to untrack a tuple. Dictionaries containing only immutable objects also do not need to be @@ -152,8 +152,8 @@ The module provides the python function is_tracked(obj), which returns the CURRENT tracking status of the object. Subsequent garbage collections may change the tracking status of the object. - - Untracking of certain containers was introduced in issue #4688, and + + Untracking of certain containers was introduced in issue #4688, and the algorithm was refined in response to issue #14775. */ @@ -853,8 +853,7 @@ /* This is the main function. Read this to understand how the * collection process works. */ static Py_ssize_t -collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable, - int nofail) +collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable) { int i; Py_ssize_t m = 0; /* # objects collected */ @@ -1001,15 +1000,10 @@ } if (PyErr_Occurred()) { - if (nofail) { - PyErr_Clear(); - } - else { - if (gc_str == NULL) - gc_str = PyUnicode_FromString("garbage collection"); - PyErr_WriteUnraisable(gc_str); - Py_FatalError("unexpected exception during garbage collection"); - } + if (gc_str == NULL) + gc_str = PyUnicode_FromString("garbage collection"); + PyErr_WriteUnraisable(gc_str); + Py_FatalError("unexpected exception during garbage collection"); } /* Update stats */ @@ -1068,7 +1062,7 @@ { Py_ssize_t result, collected, uncollectable; invoke_gc_callback("start", generation, 0, 0); - result = collect(generation, &collected, &uncollectable, 0); + result = collect(generation, &collected, &uncollectable); invoke_gc_callback("stop", generation, collected, uncollectable); return result; } @@ -1550,22 +1544,8 @@ return n; } -Py_ssize_t -_PyGC_CollectNoFail(void) -{ - Py_ssize_t n; - - /* This function should only be called on interpreter shutdown, and - therefore not recursively. */ - assert(!collecting); - collecting = 1; - n = collect(NUM_GENERATIONS - 1, NULL, NULL, 1); - collecting = 0; - return n; -} - void -_PyGC_DumpShutdownStats(void) +_PyGC_Fini(void) { if (!(debug & DEBUG_SAVEALL) && garbage != NULL && PyList_GET_SIZE(garbage) > 0) { @@ -1576,12 +1556,8 @@ else message = "gc: %zd uncollectable objects at " \ "shutdown; use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them"; - /* PyErr_WarnFormat does too many things and we are at shutdown, - the warnings module's dependencies (e.g. linecache) may be gone - already. */ - if (PyErr_WarnExplicitFormat(PyExc_ResourceWarning, "gc", 0, - "gc", NULL, message, - PyList_GET_SIZE(garbage))) + if (PyErr_WarnFormat(PyExc_ResourceWarning, 0, message, + PyList_GET_SIZE(garbage)) < 0) PyErr_WriteUnraisable(NULL); if (debug & DEBUG_UNCOLLECTABLE) { PyObject *repr = NULL, *bytes = NULL; @@ -1590,7 +1566,7 @@ PyErr_WriteUnraisable(garbage); else { PySys_WriteStderr( - " %s\n", + " %s\n", PyBytes_AS_STRING(bytes) ); } @@ -1598,11 +1574,6 @@ Py_XDECREF(bytes); } } -} - -void -_PyGC_Fini(void) -{ Py_CLEAR(callbacks); } @@ -1689,15 +1660,8 @@ PyVarObject * _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems) { - size_t size; - PyVarObject *op; - - if (nitems < 0) { - PyErr_BadInternalCall(); - return NULL; - } - size = _PyObject_VAR_SIZE(tp, nitems); - op = (PyVarObject *) _PyObject_GC_Malloc(size); + const size_t size = _PyObject_VAR_SIZE(tp, nitems); + PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size); if (op != NULL) op = PyObject_INIT_VAR(op, tp, nitems); return op; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/getpath.c --- a/Modules/getpath.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/getpath.c Fri Feb 01 23:12:09 2013 +0100 @@ -326,7 +326,6 @@ if (home) { wchar_t *delim; wcsncpy(prefix, home, MAXPATHLEN); - prefix[MAXPATHLEN] = L'\0'; delim = wcschr(prefix, DELIM); if (delim) *delim = L'\0'; @@ -336,17 +335,15 @@ } /* Check to see if argv[0] is in the build directory */ - wcsncpy(prefix, argv0_path, MAXPATHLEN); - prefix[MAXPATHLEN] = L'\0'; + wcscpy(prefix, argv0_path); joinpath(prefix, L"Modules/Setup"); if (isfile(prefix)) { /* Check VPATH to see if argv0_path is in the build directory. */ vpath = _Py_char2wchar(VPATH, NULL); if (vpath != NULL) { - wcsncpy(prefix, argv0_path, MAXPATHLEN); - prefix[MAXPATHLEN] = L'\0'; + wcscpy(prefix, argv0_path); joinpath(prefix, vpath); - PyMem_RawFree(vpath); + PyMem_Free(vpath); joinpath(prefix, L"Lib"); joinpath(prefix, LANDMARK); if (ismodule(prefix)) @@ -368,7 +365,6 @@ /* Look at configure's PREFIX */ wcsncpy(prefix, _prefix, MAXPATHLEN); - prefix[MAXPATHLEN] = L'\0'; joinpath(prefix, lib_python); joinpath(prefix, LANDMARK); if (ismodule(prefix)) @@ -395,7 +391,6 @@ wcsncpy(exec_prefix, delim+1, MAXPATHLEN); else wcsncpy(exec_prefix, home, MAXPATHLEN); - exec_prefix[MAXPATHLEN] = L'\0'; joinpath(exec_prefix, lib_python); joinpath(exec_prefix, L"lib-dynload"); return 1; @@ -404,8 +399,7 @@ /* Check to see if argv[0] is in the build directory. "pybuilddir.txt" is written by setup.py and contains the relative path to the location of shared library modules. */ - wcsncpy(exec_prefix, argv0_path, MAXPATHLEN); - exec_prefix[MAXPATHLEN] = L'\0'; + wcscpy(exec_prefix, argv0_path); joinpath(exec_prefix, L"pybuilddir.txt"); if (isfile(exec_prefix)) { FILE *f = _Py_wfopen(exec_prefix, L"rb"); @@ -426,8 +420,7 @@ Py_DECREF(decoded); if (k >= 0) { rel_builddir_path[k] = L'\0'; - wcsncpy(exec_prefix, argv0_path, MAXPATHLEN); - exec_prefix[MAXPATHLEN] = L'\0'; + wcscpy(exec_prefix, argv0_path); joinpath(exec_prefix, rel_builddir_path); return -1; } @@ -449,7 +442,6 @@ /* Look at configure's EXEC_PREFIX */ wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN); - exec_prefix[MAXPATHLEN] = L'\0'; joinpath(exec_prefix, lib_python); joinpath(exec_prefix, L"lib-dynload"); if (isdir(exec_prefix)) @@ -562,7 +554,8 @@ } else progpath[0] = '\0'; - PyMem_RawFree(path_buffer); + if (path_buffer != NULL) + PyMem_Free(path_buffer); if (progpath[0] != SEP && progpath[0] != '\0') absolutize(progpath); wcsncpy(argv0_path, progpath, MAXPATHLEN); @@ -604,7 +597,7 @@ /* Use the location of the library as the progpath */ wcsncpy(argv0_path, wbuf, MAXPATHLEN); } - PyMem_RawFree(wbuf); + PyMem_Free(wbuf); } #endif @@ -815,10 +808,11 @@ else wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN); - PyMem_RawFree(_pythonpath); - PyMem_RawFree(_prefix); - PyMem_RawFree(_exec_prefix); - PyMem_RawFree(rtpypath); + PyMem_Free(_pythonpath); + PyMem_Free(_prefix); + PyMem_Free(_exec_prefix); + if (rtpypath != NULL) + PyMem_Free(rtpypath); } @@ -828,7 +822,7 @@ { if (module_search_path != NULL) { if (module_search_path_malloced) - PyMem_RawFree(module_search_path); + PyMem_Free(module_search_path); module_search_path = NULL; module_search_path_malloced = 0; } @@ -837,7 +831,7 @@ wchar_t *prog = Py_GetProgramName(); wcsncpy(progpath, prog, MAXPATHLEN); exec_prefix[0] = prefix[0] = L'\0'; - module_search_path = PyMem_RawMalloc((wcslen(path) + 1) * sizeof(wchar_t)); + module_search_path = PyMem_Malloc((wcslen(path) + 1) * sizeof(wchar_t)); module_search_path_malloced = 1; if (module_search_path != NULL) wcscpy(module_search_path, path); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/grpmodule.c --- a/Modules/grpmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/grpmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -2,8 +2,8 @@ /* UNIX group file access module */ #include "Python.h" -#include "posixmodule.h" +#include #include static PyStructSequence_Field struct_group_type_fields[] = { @@ -69,7 +69,7 @@ Py_INCREF(Py_None); } #endif - SET(setIndex++, _PyLong_FromGid(p->gr_gid)); + SET(setIndex++, PyLong_FromLong((long) p->gr_gid)); SET(setIndex++, w); #undef SET @@ -85,24 +85,17 @@ grp_getgrgid(PyObject *self, PyObject *pyo_id) { PyObject *py_int_id; - gid_t gid; + unsigned int gid; struct group *p; py_int_id = PyNumber_Long(pyo_id); if (!py_int_id) return NULL; - if (!_Py_Gid_Converter(py_int_id, &gid)) { - Py_DECREF(py_int_id); - return NULL; - } + gid = PyLong_AS_LONG(py_int_id); Py_DECREF(py_int_id); if ((p = getgrgid(gid)) == NULL) { - PyObject *gid_obj = _PyLong_FromGid(gid); - if (gid_obj == NULL) - return NULL; - PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %S", gid_obj); - Py_DECREF(gid_obj); + PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid); return NULL; } return mkgrent(p); @@ -210,14 +203,9 @@ if (m == NULL) return NULL; d = PyModule_GetDict(m); - if (!initialized) { - if (PyStructSequence_InitType2(&StructGrpType, - &struct_group_type_desc) < 0) - return NULL; - } - if (PyDict_SetItemString(d, "struct_group", - (PyObject *)&StructGrpType) < 0) - return NULL; + if (!initialized) + PyStructSequence_InitType(&StructGrpType, &struct_group_type_desc); + PyDict_SetItemString(d, "struct_group", (PyObject *) &StructGrpType); initialized = 1; return m; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/itertoolsmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -473,31 +473,14 @@ return 0; } -static void -teedataobject_safe_decref(PyObject *obj) -{ - while (obj && Py_TYPE(obj) == &teedataobject_type && - Py_REFCNT(obj) == 1) { - PyObject *nextlink = ((teedataobject *)obj)->nextlink; - ((teedataobject *)obj)->nextlink = NULL; - Py_DECREF(obj); - obj = nextlink; - } - Py_XDECREF(obj); -} - static int teedataobject_clear(teedataobject *tdo) { int i; - PyObject *tmp; - Py_CLEAR(tdo->it); for (i=0 ; inumread ; i++) Py_CLEAR(tdo->values[i]); - tmp = tdo->nextlink; - tdo->nextlink = NULL; - teedataobject_safe_decref(tmp); + Py_CLEAR(tdo->nextlink); return 0; } @@ -634,8 +617,6 @@ if (to->index >= LINKCELLS) { link = teedataobject_jumplink(to->dataobj); - if (link == NULL) - return NULL; Py_DECREF(to->dataobj); to->dataobj = (teedataobject *)link; to->index = 0; @@ -964,7 +945,7 @@ /* Create a new cycle with the iterator tuple, then set * the saved state on it. */ - return Py_BuildValue("O(O)(Oi)", Py_TYPE(lz), + return Py_BuildValue("O(O)(Oi)", Py_TYPE(lz), lz->it, lz->saved, lz->firstpass); } @@ -1554,8 +1535,7 @@ }; PyDoc_STRVAR(islice_doc, -"islice(iterable, stop) --> islice object\n\ -islice(iterable, start, stop[, step]) --> islice object\n\ +"islice(iterable, [start,] stop [, step]) --> islice object\n\ \n\ Return an iterator whose next() method returns selected values from an\n\ iterable. If start is specified, will skip all preceding elements;\n\ @@ -2230,7 +2210,7 @@ }; PyDoc_STRVAR(product_doc, -"product(*iterables, repeat=1) --> product object\n\ +"product(*iterables) --> product object\n\ \n\ Cartesian product of input iterables. Equivalent to nested for-loops.\n\n\ For example, product(A, B) returns the same as: ((x,y) for x in A for y in B).\n\ @@ -3155,7 +3135,7 @@ goto err; PyTuple_SET_ITEM(indices, i, index); } - + cycles = PyTuple_New(po->r); if (cycles == NULL) goto err; @@ -3181,7 +3161,7 @@ { PyObject *indices, *cycles, *result; Py_ssize_t n, i; - + if (!PyArg_ParseTuple(state, "O!O!", &PyTuple_Type, &indices, &PyTuple_Type, &cycles)) @@ -3360,18 +3340,18 @@ accumulate_next(accumulateobject *lz) { PyObject *val, *oldtotal, *newtotal; - + val = PyIter_Next(lz->it); if (val == NULL) return NULL; - + if (lz->total == NULL) { Py_INCREF(val); lz->total = val; return lz->total; } - if (lz->binop == NULL) + if (lz->binop == NULL) newtotal = PyNumber_Add(lz->total, val); else newtotal = PyObject_CallFunctionObjArgs(lz->binop, lz->total, val, NULL); @@ -3382,7 +3362,7 @@ oldtotal = lz->total; lz->total = newtotal; Py_DECREF(oldtotal); - + Py_INCREF(newtotal); return newtotal; } @@ -4352,7 +4332,7 @@ static PyObject * zip_longest_reduce(ziplongestobject *lz) { - + /* Create a new tuple with empty sequences where appropriate to pickle. * Then use setstate to set the fillvalue */ @@ -4453,7 +4433,7 @@ "Functional tools for creating and using iterators.\n\ \n\ Infinite iterators:\n\ -count(start=0, step=1) --> start, start+step, start+2*step, ...\n\ +count([n]) --> n, n+1, n+2, ...\n\ cycle(p) --> p0, p1, ... plast, p0, p1, ...\n\ repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times\n\ \n\ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/main.c --- a/Modules/main.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/main.c Fri Feb 01 23:12:09 2013 +0100 @@ -22,6 +22,10 @@ #include #endif +#ifdef HAVE_FCNTL_H +#include +#endif /* HAVE_FCNTL_H */ + #if defined(MS_WINDOWS) #define PYTHONHOMEHELP "\\lib" #else @@ -43,7 +47,7 @@ static int orig_argc; /* command line options */ -#define BASE_OPTS L"bBc:dEhiJm:OqRsStuvVW:xX:?" +#define BASE_OPTS L"bBc:deEhiJm:OqRsStuvVW:xX:?" #define PROGRAM_OPTS BASE_OPTS @@ -59,6 +63,8 @@ -B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x\n\ -c cmd : program passed in as string (terminates option list)\n\ -d : debug output from parser; also PYTHONDEBUG=x\n\ +-e : set default value of the cloexec (close-on-exec) parameter\n\ + to True; also PYTHONCLOEXEC=1\n\ -E : ignore PYTHON* environment variables (such as PYTHONPATH)\n\ -h : print this help message and exit (also --help)\n\ "; @@ -73,8 +79,7 @@ -S : don't imply 'import site' on initialization\n\ "; static char *usage_3 = "\ --u : unbuffered binary stdout and stderr, stdin always buffered;\n\ - also PYTHONUNBUFFERED=x\n\ +-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x\n\ see man page for details on internal buffering relating to '-u'\n\ -v : verbose (trace import statements); also PYTHONVERBOSE=x\n\ can be supplied multiple times to increase verbosity\n\ @@ -105,6 +110,8 @@ to seed the hashes of str, bytes and datetime objects. It can also be\n\ set to an integer in the range [0,4294967295] to get hash values with a\n\ predictable seed.\n\ +PYTHONCLOEXEC: set default value of the cloexec (close-on-exec) parameter\n\ + to True.\n\ "; static int @@ -142,7 +149,12 @@ { char *startup = Py_GETENV("PYTHONSTARTUP"); if (startup != NULL && startup[0] != '\0') { - FILE *fp = fopen(startup, "r"); + FILE *fp; + int fd = _Py_open(startup, O_RDONLY); + if (fd >= 0) + fp = fdopen(fd, "r"); + else + fp = NULL; if (fp != NULL) { (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf); PyErr_Clear(); @@ -161,32 +173,6 @@ } } -static void RunInteractiveHook(void) -{ - PyObject *sys, *hook, *result; - sys = PyImport_ImportModule("sys"); - if (sys == NULL) - goto error; - hook = PyObject_GetAttrString(sys, "__interactivehook__"); - Py_DECREF(sys); - if (hook == NULL) - PyErr_Clear(); - else { - result = PyObject_CallObject(hook, NULL); - Py_DECREF(hook); - if (result == NULL) - goto error; - else - Py_DECREF(result); - } - return; - -error: - PySys_WriteStderr("Failed calling sys.__interactivehook__\n"); - PyErr_Print(); - PyErr_Clear(); -} - static int RunModule(wchar_t *modname, int set_argv0) { @@ -194,20 +180,17 @@ runpy = PyImport_ImportModule("runpy"); if (runpy == NULL) { fprintf(stderr, "Could not import runpy module\n"); - PyErr_Print(); return -1; } runmodule = PyObject_GetAttrString(runpy, "_run_module_as_main"); if (runmodule == NULL) { fprintf(stderr, "Could not access runpy._run_module_as_main\n"); - PyErr_Print(); Py_DECREF(runpy); return -1; } module = PyUnicode_FromWideChar(modname, wcslen(modname)); if (module == NULL) { fprintf(stderr, "Could not convert module name to unicode\n"); - PyErr_Print(); Py_DECREF(runpy); Py_DECREF(runmodule); return -1; @@ -216,7 +199,6 @@ if (runargs == NULL) { fprintf(stderr, "Could not create arguments for runpy._run_module_as_main\n"); - PyErr_Print(); Py_DECREF(runpy); Py_DECREF(runmodule); Py_DECREF(module); @@ -261,10 +243,8 @@ /* argv0 is usable as an import source, so put it in sys.path[0] and import __main__ */ sys_path = PySys_GetObject("path"); - if (sys_path == NULL) { - PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path"); + if (sys_path == NULL) goto error; - } if (PyList_SetItem(sys_path, 0, argv0)) { argv0 = NULL; goto error; @@ -394,7 +374,7 @@ command to interpret. */ len = wcslen(_PyOS_optarg) + 1 + 1; - command = (wchar_t *)PyMem_RawMalloc(sizeof(wchar_t) * len); + command = (wchar_t *)malloc(sizeof(wchar_t) * len); if (command == NULL) Py_FatalError( "not enough memory to copy -c argument"); @@ -436,6 +416,10 @@ Py_DontWriteBytecodeFlag++; break; + case 'e': + Py_DefaultCloexec = 1; + break; + case 's': Py_NoUserSiteDirectory++; break; @@ -503,7 +487,7 @@ return usage(0, argv[0]); if (version) { - printf("Python %s\n", PY_VERSION); + fprintf(stderr, "Python %s\n", PY_VERSION); return 0; } @@ -523,7 +507,7 @@ *wp != L'\0') { wchar_t *buf, *warning; - buf = (wchar_t *)PyMem_RawMalloc((wcslen(wp) + 1) * sizeof(wchar_t)); + buf = (wchar_t *)malloc((wcslen(wp) + 1) * sizeof(wchar_t)); if (buf == NULL) Py_FatalError( "not enough memory to copy PYTHONWARNINGS"); @@ -533,7 +517,7 @@ warning = wcstok(NULL, L",")) { PySys_AddWarnOption(warning); } - PyMem_RawFree(buf); + free(buf); } #else if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') { @@ -542,12 +526,12 @@ /* settle for strtok here as there's no one standard C89 wcstok */ - buf = (char *)PyMem_RawMalloc(strlen(p) + 1); + buf = (char *)malloc(strlen(p) + 1); if (buf == NULL) Py_FatalError( "not enough memory to copy PYTHONWARNINGS"); strcpy(buf, p); - oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); + oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) { #ifdef __APPLE__ @@ -565,8 +549,8 @@ Py_DECREF(unicode); } setlocale(LC_ALL, oldloc); - PyMem_RawFree(oldloc); - PyMem_RawFree(buf); + free(oldloc); + free(buf); } #endif @@ -636,7 +620,7 @@ wchar_t* buffer; size_t len = strlen(p) + 1; - buffer = PyMem_RawMalloc(len * sizeof(wchar_t)); + buffer = malloc(len * sizeof(wchar_t)); if (buffer == NULL) { Py_FatalError( "not enough memory to copy PYTHONEXECUTABLE"); @@ -710,7 +694,7 @@ if (command) { sts = run_command(command, &cf); - PyMem_RawFree(command); + free(command); } else if (module) { sts = (RunModule(module, 1) != 0); } @@ -719,7 +703,6 @@ if (filename == NULL && stdin_is_interactive) { Py_InspectFlag = 0; /* do exit on SystemExit */ RunStartupFile(&cf); - RunInteractiveHook(); } /* XXX */ @@ -785,7 +768,6 @@ if (Py_InspectFlag && stdin_is_interactive && (filename != NULL || command != NULL || module != NULL)) { Py_InspectFlag = 0; - RunInteractiveHook(); /* XXX */ sts = PyRun_AnyFileFlags(stdin, "", &cf) != 0; } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/md5module.c --- a/Modules/md5module.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/md5module.c Fri Feb 01 23:12:09 2013 +0100 @@ -91,6 +91,10 @@ (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \ (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } +#ifndef MIN + #define MIN(x, y) ( ((x)<(y))?(x):(y) ) +#endif + /* MD5 macros */ @@ -240,7 +244,7 @@ in += MD5_BLOCKSIZE; inlen -= MD5_BLOCKSIZE; } else { - n = Py_MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen)); + n = MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen)); memcpy(md5->buf + md5->curlen, in, (size_t)n); md5->curlen += (MD5_INT32)n; in += n; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/mmapmodule.c --- a/Modules/mmapmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/mmapmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -1162,6 +1162,7 @@ # endif if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { if (map_size == 0) { + off_t calc_size; if (st.st_size == 0) { PyErr_SetString(PyExc_ValueError, "cannot mmap an empty file"); @@ -1172,12 +1173,13 @@ "mmap offset is greater than file size"); return NULL; } - if (st.st_size - offset > PY_SSIZE_T_MAX) { + calc_size = st.st_size - offset; + map_size = calc_size; + if (map_size != calc_size) { PyErr_SetString(PyExc_ValueError, "mmap length is too large"); - return NULL; - } - map_size = (Py_ssize_t) (st.st_size - offset); + return NULL; + } } else if (offset + (size_t)map_size > st.st_size) { PyErr_SetString(PyExc_ValueError, "mmap length is greater than file size"); @@ -1203,7 +1205,7 @@ flags |= MAP_ANONYMOUS; #else /* SVR4 method to map anonymous memory is to open /dev/zero */ - fd = devzero = open("/dev/zero", O_RDWR); + fd = devzero = _Py_open("/dev/zero", O_RDWR); if (devzero == -1) { Py_DECREF(m_obj); PyErr_SetFromErrno(PyExc_OSError); @@ -1217,6 +1219,7 @@ PyErr_SetFromErrno(PyExc_OSError); return NULL; } + _Py_try_set_default_cloexec(m_obj->fd); } m_obj->data = mmap(NULL, map_size, @@ -1309,16 +1312,10 @@ 1); */ if (fileno != -1 && fileno != 0) { - /* Ensure that fileno is within the CRT's valid range */ - if (_PyVerify_fd(fileno) == 0) { - PyErr_SetFromErrno(PyExc_OSError); + fh = (HANDLE)_Py_get_osfhandle(fileno, 1); + if (fh == INVALID_HANDLE_VALUE) return NULL; - } - fh = (HANDLE)_get_osfhandle(fileno); - if (fh==(HANDLE)-1) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } + /* Win9x appears to need us seeked to zero */ lseek(fileno, 0, SEEK_SET); } @@ -1374,13 +1371,11 @@ Py_DECREF(m_obj); return NULL; } - if (size - offset > PY_SSIZE_T_MAX) { - PyErr_SetString(PyExc_ValueError, - "mmap length is too large"); - Py_DECREF(m_obj); - return NULL; - } - m_obj->size = (Py_ssize_t) (size - offset); + if (offset - size > PY_SSIZE_T_MAX) + /* Map area too large to fit in memory */ + m_obj->size = (Py_ssize_t) -1; + else + m_obj->size = (Py_ssize_t) (size - offset); } else { m_obj->size = map_size; size = offset + map_size; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/operator.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/operator.c Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,962 @@ + +#include "Python.h" + +PyDoc_STRVAR(operator_doc, +"Operator interface.\n\ +\n\ +This module exports a set of functions implemented in C corresponding\n\ +to the intrinsic operators of Python. For example, operator.add(x, y)\n\ +is equivalent to the expression x+y. The function names are those\n\ +used for special methods; variants without leading and trailing\n\ +'__' are also provided for convenience."); + +#define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ + return AOP(a1); } + +#define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2; \ + if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ + return AOP(a1,a2); } + +#define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1; int a2; \ + if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \ + return AOP(a1,a2); } + +#define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2; \ + if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ + if(-1 == AOP(a1,a2)) return NULL; \ + Py_INCREF(Py_None); \ + return Py_None; } + +#define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2, *a3; \ + if(! PyArg_UnpackTuple(a,#OP,3,3,&a1,&a2,&a3)) return NULL; \ + if(-1 == AOP(a1,a2,a3)) return NULL; \ + Py_INCREF(Py_None); \ + return Py_None; } + +#define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ + long r; \ + if(-1 == (r=AOP(a1))) return NULL; \ + return PyBool_FromLong(r); } + +#define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2; long r; \ + if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ + if(-1 == (r=AOP(a1,a2))) return NULL; \ + return PyLong_FromLong(r); } + +#define spamn2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2; Py_ssize_t r; \ + if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ + if(-1 == (r=AOP(a1,a2))) return NULL; \ + return PyLong_FromSsize_t(r); } + +#define spami2b(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2; long r; \ + if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ + if(-1 == (r=AOP(a1,a2))) return NULL; \ + return PyBool_FromLong(r); } + +#define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \ + PyObject *a1, *a2; \ + if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ + return PyObject_RichCompare(a1,a2,A); } + +spami(truth , PyObject_IsTrue) +spam2(op_add , PyNumber_Add) +spam2(op_sub , PyNumber_Subtract) +spam2(op_mul , PyNumber_Multiply) +spam2(op_floordiv , PyNumber_FloorDivide) +spam2(op_truediv , PyNumber_TrueDivide) +spam2(op_mod , PyNumber_Remainder) +spam1(op_neg , PyNumber_Negative) +spam1(op_pos , PyNumber_Positive) +spam1(op_abs , PyNumber_Absolute) +spam1(op_inv , PyNumber_Invert) +spam1(op_invert , PyNumber_Invert) +spam2(op_lshift , PyNumber_Lshift) +spam2(op_rshift , PyNumber_Rshift) +spami(op_not_ , PyObject_Not) +spam2(op_and_ , PyNumber_And) +spam2(op_xor , PyNumber_Xor) +spam2(op_or_ , PyNumber_Or) +spam2(op_iadd , PyNumber_InPlaceAdd) +spam2(op_isub , PyNumber_InPlaceSubtract) +spam2(op_imul , PyNumber_InPlaceMultiply) +spam2(op_ifloordiv , PyNumber_InPlaceFloorDivide) +spam2(op_itruediv , PyNumber_InPlaceTrueDivide) +spam2(op_imod , PyNumber_InPlaceRemainder) +spam2(op_ilshift , PyNumber_InPlaceLshift) +spam2(op_irshift , PyNumber_InPlaceRshift) +spam2(op_iand , PyNumber_InPlaceAnd) +spam2(op_ixor , PyNumber_InPlaceXor) +spam2(op_ior , PyNumber_InPlaceOr) +spam2(op_concat , PySequence_Concat) +spam2(op_iconcat , PySequence_InPlaceConcat) +spami2b(op_contains , PySequence_Contains) +spamn2(indexOf , PySequence_Index) +spamn2(countOf , PySequence_Count) +spam2(op_getitem , PyObject_GetItem) +spam2n(op_delitem , PyObject_DelItem) +spam3n(op_setitem , PyObject_SetItem) +spamrc(op_lt , Py_LT) +spamrc(op_le , Py_LE) +spamrc(op_eq , Py_EQ) +spamrc(op_ne , Py_NE) +spamrc(op_gt , Py_GT) +spamrc(op_ge , Py_GE) + +static PyObject* +op_pow(PyObject *s, PyObject *a) +{ + PyObject *a1, *a2; + if (PyArg_UnpackTuple(a,"pow", 2, 2, &a1, &a2)) + return PyNumber_Power(a1, a2, Py_None); + return NULL; +} + +static PyObject* +op_ipow(PyObject *s, PyObject *a) +{ + PyObject *a1, *a2; + if (PyArg_UnpackTuple(a,"ipow", 2, 2, &a1, &a2)) + return PyNumber_InPlacePower(a1, a2, Py_None); + return NULL; +} + +static PyObject * +op_index(PyObject *s, PyObject *a) +{ + return PyNumber_Index(a); +} + +static PyObject* +is_(PyObject *s, PyObject *a) +{ + PyObject *a1, *a2, *result = NULL; + if (PyArg_UnpackTuple(a,"is_", 2, 2, &a1, &a2)) { + result = (a1 == a2) ? Py_True : Py_False; + Py_INCREF(result); + } + return result; +} + +static PyObject* +is_not(PyObject *s, PyObject *a) +{ + PyObject *a1, *a2, *result = NULL; + if (PyArg_UnpackTuple(a,"is_not", 2, 2, &a1, &a2)) { + result = (a1 != a2) ? Py_True : Py_False; + Py_INCREF(result); + } + return result; +} + +#undef spam1 +#undef spam2 +#undef spam1o +#undef spam1o + +/* compare_digest **********************************************************/ + +/* + * timing safe compare + * + * Returns 1 of the strings are equal. + * In case of len(a) != len(b) the function tries to keep the timing + * dependent on the length of b. CPU cache locally may still alter timing + * a bit. + */ +static int +_tscmp(const unsigned char *a, const unsigned char *b, + Py_ssize_t len_a, Py_ssize_t len_b) +{ + /* The volatile type declarations make sure that the compiler has no + * chance to optimize and fold the code in any way that may change + * the timing. + */ + volatile Py_ssize_t length; + volatile const unsigned char *left; + volatile const unsigned char *right; + Py_ssize_t i; + unsigned char result; + + /* loop count depends on length of b */ + length = len_b; + left = NULL; + right = b; + + /* don't use else here to keep the amount of CPU instructions constant, + * volatile forces re-evaluation + * */ + if (len_a == length) { + left = *((volatile const unsigned char**)&a); + result = 0; + } + if (len_a != length) { + left = b; + result = 1; + } + + for (i=0; i < length; i++) { + result |= *left++ ^ *right++; + } + + return (result == 0); +} + +PyDoc_STRVAR(length_hint__doc__, +"length_hint(obj, default=0) -> int\n" +"Return an estimate of the number of items in obj.\n" +"This is useful for presizing containers when building from an\n" +"iterable.\n" +"\n" +"If the object supports len(), the result will be\n" +"exact. Otherwise, it may over- or under-estimate by an\n" +"arbitrary amount. The result will be an integer >= 0."); + +static PyObject *length_hint(PyObject *self, PyObject *args) +{ + PyObject *obj; + Py_ssize_t defaultvalue = 0, res; + if (!PyArg_ParseTuple(args, "O|n:length_hint", &obj, &defaultvalue)) { + return NULL; + } + res = PyObject_LengthHint(obj, defaultvalue); + if (res == -1 && PyErr_Occurred()) { + return NULL; + } + return PyLong_FromSsize_t(res); +} + + +PyDoc_STRVAR(compare_digest__doc__, +"compare_digest(a, b) -> bool\n" +"\n" +"Return 'a == b'. This function uses an approach designed to prevent\n" +"timing analysis, making it appropriate for cryptography.\n" +"a and b must both be of the same type: either str (ASCII only),\n" +"or any type that supports the buffer protocol (e.g. bytes).\n" +"\n" +"Note: If a and b are of different lengths, or if an error occurs,\n" +"a timing attack could theoretically reveal information about the\n" +"types and lengths of a and b--but not their values.\n"); + +static PyObject* +compare_digest(PyObject *self, PyObject *args) +{ + PyObject *a, *b; + int rc; + + if (!PyArg_ParseTuple(args, "OO:compare_digest", &a, &b)) { + return NULL; + } + + /* ASCII unicode string */ + if(PyUnicode_Check(a) && PyUnicode_Check(b)) { + if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) { + return NULL; + } + if (!PyUnicode_IS_ASCII(a) || !PyUnicode_IS_ASCII(b)) { + PyErr_SetString(PyExc_TypeError, + "comparing strings with non-ASCII characters is " + "not supported"); + return NULL; + } + + rc = _tscmp(PyUnicode_DATA(a), + PyUnicode_DATA(b), + PyUnicode_GET_LENGTH(a), + PyUnicode_GET_LENGTH(b)); + } + /* fallback to buffer interface for bytes, bytesarray and other */ + else { + Py_buffer view_a; + Py_buffer view_b; + + if ((PyObject_CheckBuffer(a) == 0) & (PyObject_CheckBuffer(b) == 0)) { + PyErr_Format(PyExc_TypeError, + "unsupported operand types(s) or combination of types: " + "'%.100s' and '%.100s'", + Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name); + return NULL; + } + + if (PyObject_GetBuffer(a, &view_a, PyBUF_SIMPLE) == -1) { + return NULL; + } + if (view_a.ndim > 1) { + PyErr_SetString(PyExc_BufferError, + "Buffer must be single dimension"); + PyBuffer_Release(&view_a); + return NULL; + } + + if (PyObject_GetBuffer(b, &view_b, PyBUF_SIMPLE) == -1) { + PyBuffer_Release(&view_a); + return NULL; + } + if (view_b.ndim > 1) { + PyErr_SetString(PyExc_BufferError, + "Buffer must be single dimension"); + PyBuffer_Release(&view_a); + PyBuffer_Release(&view_b); + return NULL; + } + + rc = _tscmp((const unsigned char*)view_a.buf, + (const unsigned char*)view_b.buf, + view_a.len, + view_b.len); + + PyBuffer_Release(&view_a); + PyBuffer_Release(&view_b); + } + + return PyBool_FromLong(rc); +} + +/* operator methods **********************************************************/ + +#define spam1(OP,DOC) {#OP, OP, METH_VARARGS, PyDoc_STR(DOC)}, +#define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)}, \ + {#ALTOP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)}, +#define spam1o(OP,DOC) {#OP, OP, METH_O, PyDoc_STR(DOC)}, +#define spam2o(OP,ALTOP,DOC) {#OP, op_##OP, METH_O, PyDoc_STR(DOC)}, \ + {#ALTOP, op_##OP, METH_O, PyDoc_STR(DOC)}, + +static struct PyMethodDef operator_methods[] = { + +spam1o(truth, + "truth(a) -- Return True if a is true, False otherwise.") +spam2(contains,__contains__, + "contains(a, b) -- Same as b in a (note reversed operands).") +spam1(indexOf, + "indexOf(a, b) -- Return the first index of b in a.") +spam1(countOf, + "countOf(a, b) -- Return the number of times b occurs in a.") + +spam1(is_, "is_(a, b) -- Same as a is b.") +spam1(is_not, "is_not(a, b) -- Same as a is not b.") +spam2o(index, __index__, "index(a) -- Same as a.__index__()") +spam2(add,__add__, "add(a, b) -- Same as a + b.") +spam2(sub,__sub__, "sub(a, b) -- Same as a - b.") +spam2(mul,__mul__, "mul(a, b) -- Same as a * b.") +spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.") +spam2(truediv,__truediv__, "truediv(a, b) -- Same as a / b.") +spam2(mod,__mod__, "mod(a, b) -- Same as a % b.") +spam2o(neg,__neg__, "neg(a) -- Same as -a.") +spam2o(pos,__pos__, "pos(a) -- Same as +a.") +spam2o(abs,__abs__, "abs(a) -- Same as abs(a).") +spam2o(inv,__inv__, "inv(a) -- Same as ~a.") +spam2o(invert,__invert__, "invert(a) -- Same as ~a.") +spam2(lshift,__lshift__, "lshift(a, b) -- Same as a << b.") +spam2(rshift,__rshift__, "rshift(a, b) -- Same as a >> b.") +spam2o(not_,__not__, "not_(a) -- Same as not a.") +spam2(and_,__and__, "and_(a, b) -- Same as a & b.") +spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") +spam2(or_,__or__, "or_(a, b) -- Same as a | b.") +spam2(iadd,__iadd__, "a = iadd(a, b) -- Same as a += b.") +spam2(isub,__isub__, "a = isub(a, b) -- Same as a -= b.") +spam2(imul,__imul__, "a = imul(a, b) -- Same as a *= b.") +spam2(ifloordiv,__ifloordiv__, "a = ifloordiv(a, b) -- Same as a //= b.") +spam2(itruediv,__itruediv__, "a = itruediv(a, b) -- Same as a /= b") +spam2(imod,__imod__, "a = imod(a, b) -- Same as a %= b.") +spam2(ilshift,__ilshift__, "a = ilshift(a, b) -- Same as a <<= b.") +spam2(irshift,__irshift__, "a = irshift(a, b) -- Same as a >>= b.") +spam2(iand,__iand__, "a = iand(a, b) -- Same as a &= b.") +spam2(ixor,__ixor__, "a = ixor(a, b) -- Same as a ^= b.") +spam2(ior,__ior__, "a = ior(a, b) -- Same as a |= b.") +spam2(concat,__concat__, + "concat(a, b) -- Same as a + b, for a and b sequences.") +spam2(iconcat,__iconcat__, + "a = iconcat(a, b) -- Same as a += b, for a and b sequences.") +spam2(getitem,__getitem__, + "getitem(a, b) -- Same as a[b].") +spam2(setitem,__setitem__, + "setitem(a, b, c) -- Same as a[b] = c.") +spam2(delitem,__delitem__, + "delitem(a, b) -- Same as del a[b].") +spam2(pow,__pow__, "pow(a, b) -- Same as a ** b.") +spam2(ipow,__ipow__, "a = ipow(a, b) -- Same as a **= b.") +spam2(lt,__lt__, "lt(a, b) -- Same as ab.") +spam2(ge,__ge__, "ge(a, b) -- Same as a>=b.") + + {"_compare_digest", (PyCFunction)compare_digest, METH_VARARGS, + compare_digest__doc__}, + {"length_hint", (PyCFunction)length_hint, METH_VARARGS, + length_hint__doc__}, + {NULL, NULL} /* sentinel */ + +}; + +/* itemgetter object **********************************************************/ + +typedef struct { + PyObject_HEAD + Py_ssize_t nitems; + PyObject *item; +} itemgetterobject; + +static PyTypeObject itemgetter_type; + +static PyObject * +itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + itemgetterobject *ig; + PyObject *item; + Py_ssize_t nitems; + + if (!_PyArg_NoKeywords("itemgetter()", kwds)) + return NULL; + + nitems = PyTuple_GET_SIZE(args); + if (nitems <= 1) { + if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &item)) + return NULL; + } else + item = args; + + /* create itemgetterobject structure */ + ig = PyObject_GC_New(itemgetterobject, &itemgetter_type); + if (ig == NULL) + return NULL; + + Py_INCREF(item); + ig->item = item; + ig->nitems = nitems; + + PyObject_GC_Track(ig); + return (PyObject *)ig; +} + +static void +itemgetter_dealloc(itemgetterobject *ig) +{ + PyObject_GC_UnTrack(ig); + Py_XDECREF(ig->item); + PyObject_GC_Del(ig); +} + +static int +itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg) +{ + Py_VISIT(ig->item); + return 0; +} + +static PyObject * +itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw) +{ + PyObject *obj, *result; + Py_ssize_t i, nitems=ig->nitems; + + if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) + return NULL; + if (nitems == 1) + return PyObject_GetItem(obj, ig->item); + + assert(PyTuple_Check(ig->item)); + assert(PyTuple_GET_SIZE(ig->item) == nitems); + + result = PyTuple_New(nitems); + if (result == NULL) + return NULL; + + for (i=0 ; i < nitems ; i++) { + PyObject *item, *val; + item = PyTuple_GET_ITEM(ig->item, i); + val = PyObject_GetItem(obj, item); + if (val == NULL) { + Py_DECREF(result); + return NULL; + } + PyTuple_SET_ITEM(result, i, val); + } + return result; +} + +PyDoc_STRVAR(itemgetter_doc, +"itemgetter(item, ...) --> itemgetter object\n\ +\n\ +Return a callable object that fetches the given item(s) from its operand.\n\ +After, f=itemgetter(2), the call f(r) returns r[2].\n\ +After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])"); + +static PyTypeObject itemgetter_type = { + PyVarObject_HEAD_INIT(NULL, 0) + "operator.itemgetter", /* tp_name */ + sizeof(itemgetterobject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor)itemgetter_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)itemgetter_call, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + itemgetter_doc, /* tp_doc */ + (traverseproc)itemgetter_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + itemgetter_new, /* tp_new */ + 0, /* tp_free */ +}; + + +/* attrgetter object **********************************************************/ + +typedef struct { + PyObject_HEAD + Py_ssize_t nattrs; + PyObject *attr; +} attrgetterobject; + +static PyTypeObject attrgetter_type; + +static PyObject * +attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + attrgetterobject *ag; + PyObject *attr; + Py_ssize_t nattrs, idx, char_idx; + + if (!_PyArg_NoKeywords("attrgetter()", kwds)) + return NULL; + + nattrs = PyTuple_GET_SIZE(args); + if (nattrs <= 1) { + if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &attr)) + return NULL; + } + + attr = PyTuple_New(nattrs); + if (attr == NULL) + return NULL; + + /* prepare attr while checking args */ + for (idx = 0; idx < nattrs; ++idx) { + PyObject *item = PyTuple_GET_ITEM(args, idx); + Py_ssize_t item_len; + void *data; + unsigned int kind; + int dot_count; + + if (!PyUnicode_Check(item)) { + PyErr_SetString(PyExc_TypeError, + "attribute name must be a string"); + Py_DECREF(attr); + return NULL; + } + if (PyUnicode_READY(item)) { + Py_DECREF(attr); + return NULL; + } + item_len = PyUnicode_GET_LENGTH(item); + kind = PyUnicode_KIND(item); + data = PyUnicode_DATA(item); + + /* check whethere the string is dotted */ + dot_count = 0; + for (char_idx = 0; char_idx < item_len; ++char_idx) { + if (PyUnicode_READ(kind, data, char_idx) == '.') + ++dot_count; + } + + if (dot_count == 0) { + Py_INCREF(item); + PyUnicode_InternInPlace(&item); + PyTuple_SET_ITEM(attr, idx, item); + } else { /* make it a tuple of non-dotted attrnames */ + PyObject *attr_chain = PyTuple_New(dot_count + 1); + PyObject *attr_chain_item; + Py_ssize_t unibuff_from = 0; + Py_ssize_t unibuff_till = 0; + Py_ssize_t attr_chain_idx = 0; + + if (attr_chain == NULL) { + Py_DECREF(attr); + return NULL; + } + + for (; dot_count > 0; --dot_count) { + while (PyUnicode_READ(kind, data, unibuff_till) != '.') { + ++unibuff_till; + } + attr_chain_item = PyUnicode_Substring(item, + unibuff_from, + unibuff_till); + if (attr_chain_item == NULL) { + Py_DECREF(attr_chain); + Py_DECREF(attr); + return NULL; + } + PyUnicode_InternInPlace(&attr_chain_item); + PyTuple_SET_ITEM(attr_chain, attr_chain_idx, attr_chain_item); + ++attr_chain_idx; + unibuff_till = unibuff_from = unibuff_till + 1; + } + + /* now add the last dotless name */ + attr_chain_item = PyUnicode_Substring(item, + unibuff_from, item_len); + if (attr_chain_item == NULL) { + Py_DECREF(attr_chain); + Py_DECREF(attr); + return NULL; + } + PyUnicode_InternInPlace(&attr_chain_item); + PyTuple_SET_ITEM(attr_chain, attr_chain_idx, attr_chain_item); + + PyTuple_SET_ITEM(attr, idx, attr_chain); + } + } + + /* create attrgetterobject structure */ + ag = PyObject_GC_New(attrgetterobject, &attrgetter_type); + if (ag == NULL) { + Py_DECREF(attr); + return NULL; + } + + ag->attr = attr; + ag->nattrs = nattrs; + + PyObject_GC_Track(ag); + return (PyObject *)ag; +} + +static void +attrgetter_dealloc(attrgetterobject *ag) +{ + PyObject_GC_UnTrack(ag); + Py_XDECREF(ag->attr); + PyObject_GC_Del(ag); +} + +static int +attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg) +{ + Py_VISIT(ag->attr); + return 0; +} + +static PyObject * +dotted_getattr(PyObject *obj, PyObject *attr) +{ + PyObject *newobj; + + /* attr is either a tuple or instance of str. + Ensured by the setup code of attrgetter_new */ + if (PyTuple_CheckExact(attr)) { /* chained getattr */ + Py_ssize_t name_idx = 0, name_count; + PyObject *attr_name; + + name_count = PyTuple_GET_SIZE(attr); + Py_INCREF(obj); + for (name_idx = 0; name_idx < name_count; ++name_idx) { + attr_name = PyTuple_GET_ITEM(attr, name_idx); + newobj = PyObject_GetAttr(obj, attr_name); + Py_DECREF(obj); + if (newobj == NULL) { + return NULL; + } + /* here */ + obj = newobj; + } + } else { /* single getattr */ + newobj = PyObject_GetAttr(obj, attr); + if (newobj == NULL) + return NULL; + obj = newobj; + } + + return obj; +} + +static PyObject * +attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw) +{ + PyObject *obj, *result; + Py_ssize_t i, nattrs=ag->nattrs; + + if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) + return NULL; + if (ag->nattrs == 1) /* ag->attr is always a tuple */ + return dotted_getattr(obj, PyTuple_GET_ITEM(ag->attr, 0)); + + assert(PyTuple_Check(ag->attr)); + assert(PyTuple_GET_SIZE(ag->attr) == nattrs); + + result = PyTuple_New(nattrs); + if (result == NULL) + return NULL; + + for (i=0 ; i < nattrs ; i++) { + PyObject *attr, *val; + attr = PyTuple_GET_ITEM(ag->attr, i); + val = dotted_getattr(obj, attr); + if (val == NULL) { + Py_DECREF(result); + return NULL; + } + PyTuple_SET_ITEM(result, i, val); + } + return result; +} + +PyDoc_STRVAR(attrgetter_doc, +"attrgetter(attr, ...) --> attrgetter object\n\ +\n\ +Return a callable object that fetches the given attribute(s) from its operand.\n\ +After, f=attrgetter('name'), the call f(r) returns r.name.\n\ +After, g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).\n\ +After, h=attrgetter('name.first', 'name.last'), the call h(r) returns\n\ +(r.name.first, r.name.last)."); + +static PyTypeObject attrgetter_type = { + PyVarObject_HEAD_INIT(NULL, 0) + "operator.attrgetter", /* tp_name */ + sizeof(attrgetterobject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor)attrgetter_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)attrgetter_call, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + attrgetter_doc, /* tp_doc */ + (traverseproc)attrgetter_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + attrgetter_new, /* tp_new */ + 0, /* tp_free */ +}; + + +/* methodcaller object **********************************************************/ + +typedef struct { + PyObject_HEAD + PyObject *name; + PyObject *args; + PyObject *kwds; +} methodcallerobject; + +static PyTypeObject methodcaller_type; + +static PyObject * +methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + methodcallerobject *mc; + PyObject *name, *newargs; + + if (PyTuple_GET_SIZE(args) < 1) { + PyErr_SetString(PyExc_TypeError, "methodcaller needs at least " + "one argument, the method name"); + return NULL; + } + + /* create methodcallerobject structure */ + mc = PyObject_GC_New(methodcallerobject, &methodcaller_type); + 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; + + PyObject_GC_Track(mc); + return (PyObject *)mc; +} + +static void +methodcaller_dealloc(methodcallerobject *mc) +{ + PyObject_GC_UnTrack(mc); + Py_XDECREF(mc->name); + Py_XDECREF(mc->args); + Py_XDECREF(mc->kwds); + PyObject_GC_Del(mc); +} + +static int +methodcaller_traverse(methodcallerobject *mc, visitproc visit, void *arg) +{ + Py_VISIT(mc->args); + Py_VISIT(mc->kwds); + return 0; +} + +static PyObject * +methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw) +{ + PyObject *method, *obj, *result; + + if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) + return NULL; + method = PyObject_GetAttr(obj, mc->name); + if (method == NULL) + return NULL; + result = PyObject_Call(method, mc->args, mc->kwds); + Py_DECREF(method); + return result; +} + +PyDoc_STRVAR(methodcaller_doc, +"methodcaller(name, ...) --> methodcaller object\n\ +\n\ +Return a callable object that calls the given method on its operand.\n\ +After, f = methodcaller('name'), the call f(r) returns r.name().\n\ +After, g = methodcaller('name', 'date', foo=1), the call g(r) returns\n\ +r.name('date', foo=1)."); + +static PyTypeObject methodcaller_type = { + PyVarObject_HEAD_INIT(NULL, 0) + "operator.methodcaller", /* tp_name */ + sizeof(methodcallerobject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor)methodcaller_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)methodcaller_call, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ + methodcaller_doc, /* tp_doc */ + (traverseproc)methodcaller_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + methodcaller_new, /* tp_new */ + 0, /* tp_free */ +}; + + +/* Initialization function for the module (*must* be called PyInit_operator) */ + + +static struct PyModuleDef operatormodule = { + PyModuleDef_HEAD_INIT, + "operator", + operator_doc, + -1, + operator_methods, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC +PyInit_operator(void) +{ + PyObject *m; + + /* Create the module and add the functions */ + m = PyModule_Create(&operatormodule); + if (m == NULL) + return NULL; + + if (PyType_Ready(&itemgetter_type) < 0) + return NULL; + Py_INCREF(&itemgetter_type); + PyModule_AddObject(m, "itemgetter", (PyObject *)&itemgetter_type); + + if (PyType_Ready(&attrgetter_type) < 0) + return NULL; + Py_INCREF(&attrgetter_type); + PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type); + + if (PyType_Ready(&methodcaller_type) < 0) + return NULL; + Py_INCREF(&methodcaller_type); + PyModule_AddObject(m, "methodcaller", (PyObject *)&methodcaller_type); + return m; +} diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/ossaudiodev.c --- a/Modules/ossaudiodev.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/ossaudiodev.c Fri Feb 01 23:12:09 2013 +0100 @@ -115,7 +115,9 @@ one open at a time. This does *not* affect later I/O; OSS provides a special ioctl() for non-blocking read/write, which is exposed via oss_nonblock() below. */ - if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) { + fd = _Py_open(devicename, imode|O_NONBLOCK); + + if (fd == -1) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); return NULL; } @@ -177,7 +179,8 @@ devicename = "/dev/mixer"; } - if ((fd = open(devicename, O_RDWR)) == -1) { + fd = _Py_open(devicename, O_RDWR); + if (fd == -1) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); return NULL; } @@ -230,7 +233,7 @@ } /* _do_ioctl_1() is a private helper function used for the OSS ioctls -- - SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that are called from C + SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C like this: ioctl(fd, SNDCTL_DSP_cmd, &arg) @@ -245,7 +248,7 @@ int arg; assert(strlen(fname) <= 30); - strncat(argfmt, fname, 30); + strcat(argfmt, fname); if (!PyArg_ParseTuple(args, argfmt, &arg)) return NULL; @@ -270,7 +273,7 @@ int arg = 0; assert(strlen(fname) <= 30); - strncat(argfmt, fname, 30); + strcat(argfmt, fname); if (!PyArg_ParseTuple(args, argfmt, &arg)) return NULL; @@ -290,7 +293,7 @@ int rv; assert(strlen(fname) <= 30); - strncat(argfmt, fname, 30); + strcat(argfmt, fname); if (!PyArg_ParseTuple(args, argfmt)) return NULL; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/parsermodule.c --- a/Modules/parsermodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/parsermodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -83,78 +83,54 @@ int lineno, /* include line numbers? */ int col_offset) /* include column offsets? */ { - PyObject *result = NULL, *w; - if (n == NULL) { Py_INCREF(Py_None); - return Py_None; + return (Py_None); } - if (ISNONTERMINAL(TYPE(n))) { int i; - - result = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl)); - if (result == NULL) - goto error; - + PyObject *v; + PyObject *w; + + v = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl)); + if (v == NULL) + return (v); w = PyLong_FromLong(TYPE(n)); - if (w == NULL) - goto error; - (void) addelem(result, 0, w); - + if (w == NULL) { + Py_DECREF(v); + return ((PyObject*) NULL); + } + (void) addelem(v, 0, w); for (i = 0; i < NCH(n); i++) { w = node2tuple(CHILD(n, i), mkseq, addelem, lineno, col_offset); - if (w == NULL) - goto error; - (void) addelem(result, i+1, w); + if (w == NULL) { + Py_DECREF(v); + return ((PyObject*) NULL); + } + (void) addelem(v, i+1, w); } - if (TYPE(n) == encoding_decl) { - w = PyUnicode_FromString(STR(n)); - if (w == NULL) - goto error; - (void) addelem(result, i+1, w); - } + if (TYPE(n) == encoding_decl) + (void) addelem(v, i+1, PyUnicode_FromString(STR(n))); + return (v); } else if (ISTERMINAL(TYPE(n))) { - result = mkseq(2 + lineno + col_offset); - if (result == NULL) - goto error; - - w = PyLong_FromLong(TYPE(n)); - if (w == NULL) - goto error; - (void) addelem(result, 0, w); - - w = PyUnicode_FromString(STR(n)); - if (w == NULL) - goto error; - (void) addelem(result, 1, w); - - if (lineno == 1) { - w = PyLong_FromLong(n->n_lineno); - if (w == NULL) - goto error; - (void) addelem(result, 2, w); + PyObject *result = mkseq(2 + lineno + col_offset); + if (result != NULL) { + (void) addelem(result, 0, PyLong_FromLong(TYPE(n))); + (void) addelem(result, 1, PyUnicode_FromString(STR(n))); + if (lineno == 1) + (void) addelem(result, 2, PyLong_FromLong(n->n_lineno)); + if (col_offset == 1) + (void) addelem(result, 3, PyLong_FromLong(n->n_col_offset)); } - - if (col_offset == 1) { - w = PyLong_FromLong(n->n_col_offset); - if (w == NULL) - goto error; - (void) addelem(result, 3, w); - } + return (result); } else { PyErr_SetString(PyExc_SystemError, "unrecognized parse tree node type"); return ((PyObject*) NULL); } - return result; - -error: - Py_XDECREF(result); - return NULL; } /* * End of material copyrighted by Stichting Mathematisch Centrum. @@ -833,13 +809,8 @@ return 0; } strn = (char *)PyObject_MALLOC(len + 1); - if (strn == NULL) { - Py_DECREF(temp); - Py_XDECREF(elem); - PyErr_NoMemory(); - return 0; - } - (void) memcpy(strn, temp_str, len + 1); + if (strn != NULL) + (void) memcpy(strn, temp_str, len + 1); Py_DECREF(temp); } else if (!ISNONTERMINAL(type)) { @@ -899,7 +870,7 @@ * The tuple is simple, but it doesn't start with a start symbol. * Raise an exception now and be done with it. */ - tuple = Py_BuildValue("Os", tuple, + tuple = Py_BuildValue("os", tuple, "Illegal syntax-tree; cannot start with terminal symbol."); PyErr_SetObject(parser_error, tuple); Py_XDECREF(tuple); @@ -935,14 +906,8 @@ return NULL; } res->n_str = (char *)PyObject_MALLOC(len + 1); - if (res->n_str == NULL) { - Py_DECREF(res); - Py_DECREF(encoding); - Py_DECREF(tuple); - PyErr_NoMemory(); - return NULL; - } - (void) memcpy(res->n_str, temp, len + 1); + if (res->n_str != NULL && temp != NULL) + (void) memcpy(res->n_str, temp, len + 1); Py_DECREF(encoding); Py_DECREF(tuple); } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/posixmodule.c --- a/Modules/posixmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/posixmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -23,9 +23,6 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#ifndef MS_WINDOWS -#include "posixmodule.h" -#endif #if defined(__VMS) # error "PEP 11: VMS is now unsupported, code will be removed in Python 3.4" @@ -113,18 +110,6 @@ #include #endif -#ifdef __hpux -#include -#endif - -#if defined(__DragonFly__) || \ - defined(__OpenBSD__) || \ - defined(__FreeBSD__) || \ - defined(__NetBSD__) || \ - defined(__APPLE__) -#include -#endif - #if defined(MS_WINDOWS) # define TERMSIZE_USE_CONIO #elif defined(HAVE_SYS_IOCTL_H) @@ -361,7 +346,7 @@ #undef STAT #undef FSTAT #undef STRUCT_STAT -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) # define STAT win32_stat # define LSTAT win32_lstat # define FSTAT win32_fstat @@ -397,133 +382,6 @@ #endif -#ifndef MS_WINDOWS -PyObject * -_PyLong_FromUid(uid_t uid) -{ - if (uid == (uid_t)-1) - return PyLong_FromLong(-1); - return PyLong_FromUnsignedLong(uid); -} - -PyObject * -_PyLong_FromGid(gid_t gid) -{ - if (gid == (gid_t)-1) - return PyLong_FromLong(-1); - return PyLong_FromUnsignedLong(gid); -} - -int -_Py_Uid_Converter(PyObject *obj, void *p) -{ - int overflow; - long result; - if (PyFloat_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float"); - return 0; - } - result = PyLong_AsLongAndOverflow(obj, &overflow); - if (overflow < 0) - goto OverflowDown; - if (!overflow && result == -1) { - /* error or -1 */ - if (PyErr_Occurred()) - return 0; - *(uid_t *)p = (uid_t)-1; - } - else { - /* unsigned uid_t */ - unsigned long uresult; - if (overflow > 0) { - uresult = PyLong_AsUnsignedLong(obj); - if (PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) - goto OverflowUp; - return 0; - } - if ((uid_t)uresult == (uid_t)-1) - goto OverflowUp; - } else { - if (result < 0) - goto OverflowDown; - uresult = result; - } - if (sizeof(uid_t) < sizeof(long) && - (unsigned long)(uid_t)uresult != uresult) - goto OverflowUp; - *(uid_t *)p = (uid_t)uresult; - } - return 1; - -OverflowDown: - PyErr_SetString(PyExc_OverflowError, - "user id is less than minimum"); - return 0; - -OverflowUp: - PyErr_SetString(PyExc_OverflowError, - "user id is greater than maximum"); - return 0; -} - -int -_Py_Gid_Converter(PyObject *obj, void *p) -{ - int overflow; - long result; - if (PyFloat_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float"); - return 0; - } - result = PyLong_AsLongAndOverflow(obj, &overflow); - if (overflow < 0) - goto OverflowDown; - if (!overflow && result == -1) { - /* error or -1 */ - if (PyErr_Occurred()) - return 0; - *(gid_t *)p = (gid_t)-1; - } - else { - /* unsigned gid_t */ - unsigned long uresult; - if (overflow > 0) { - uresult = PyLong_AsUnsignedLong(obj); - if (PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) - goto OverflowUp; - return 0; - } - if ((gid_t)uresult == (gid_t)-1) - goto OverflowUp; - } else { - if (result < 0) - goto OverflowDown; - uresult = result; - } - if (sizeof(gid_t) < sizeof(long) && - (unsigned long)(gid_t)uresult != uresult) - goto OverflowUp; - *(gid_t *)p = (gid_t)uresult; - } - return 1; - -OverflowDown: - PyErr_SetString(PyExc_OverflowError, - "group id is less than minimum"); - return 0; - -OverflowUp: - PyErr_SetString(PyExc_OverflowError, - "group id is greater than maximum"); - return 0; -} -#endif /* MS_WINDOWS */ - - #ifdef AT_FDCWD /* * Why the (int) cast? Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965); @@ -1066,10 +924,9 @@ #endif /* MS_WINDOWS */ /* Return a dictionary corresponding to the POSIX environment table */ -#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) +#ifdef WITH_NEXT_FRAMEWORK /* On Darwin/MacOSX a shared library or framework has no access to -** environ directly, we must obtain it with _NSGetEnviron(). See also -** man environ(7). +** environ directly, we must obtain it with _NSGetEnviron(). */ #include static char **environ; @@ -1090,7 +947,7 @@ d = PyDict_New(); if (d == NULL) return NULL; -#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) +#ifdef WITH_NEXT_FRAMEWORK if (environ == NULL) environ = *_NSGetEnviron(); #endif @@ -1298,14 +1155,14 @@ if (!result) return FALSE; if (result > MAX_PATH+1) { - new_path = PyMem_RawMalloc(result * sizeof(wchar_t)); + new_path = malloc(result * sizeof(wchar_t)); if (!new_path) { SetLastError(ERROR_OUTOFMEMORY); return FALSE; } result = GetCurrentDirectoryW(result, new_path); if (!result) { - PyMem_RawFree(new_path); + free(new_path); return FALSE; } } @@ -1316,7 +1173,7 @@ env[1] = new_path[0]; result = SetEnvironmentVariableW(env, new_path); if (new_path != _new_path) - PyMem_RawFree(new_path); + free(new_path); return result; } #endif @@ -1405,9 +1262,9 @@ result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow; if (reparse_tag == IO_REPARSE_TAG_SYMLINK) { /* first clear the S_IFMT bits */ - result->st_mode ^= (result->st_mode & S_IFMT); + result->st_mode ^= (result->st_mode & 0170000); /* now set the bits that make this a symlink */ - result->st_mode |= S_IFLNK; + result->st_mode |= 0120000; } return 0; @@ -1497,7 +1354,7 @@ if(!buf_size) return FALSE; - buf = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t)); + buf = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t)); if (!buf) { SetLastError(ERROR_OUTOFMEMORY); return FALSE; @@ -1507,12 +1364,12 @@ buf, buf_size, VOLUME_NAME_DOS); if(!result_length) { - PyMem_Free(buf); + free(buf); return FALSE; } if(!CloseHandle(hdl)) { - PyMem_Free(buf); + free(buf); return FALSE; } @@ -1603,7 +1460,7 @@ return -1; code = win32_xstat_impl_w(target_path, result, FALSE); - PyMem_Free(target_path); + free(target_path); return code; } } else @@ -1699,7 +1556,7 @@ return -1; code = win32_xstat_impl_w(target_path, result, FALSE); - PyMem_Free(target_path); + free(target_path); return code; } } else @@ -1780,21 +1637,9 @@ HANDLE h; int type; - if (!_PyVerify_fd(file_number)) - h = INVALID_HANDLE_VALUE; - else - h = (HANDLE)_get_osfhandle(file_number); - - /* Protocol violation: we explicitly clear errno, instead of - setting it to a POSIX error. Callers should use GetLastError. */ - errno = 0; - - if (h == INVALID_HANDLE_VALUE) { - /* This is really a C library error (invalid file handle). - We set the Win32 error to the closes one matching. */ - SetLastError(ERROR_INVALID_HANDLE); + h = (HANDLE)_Py_get_osfhandle(file_number, 0); + if (h == INVALID_HANDLE_VALUE) return -1; - } memset(result, 0, sizeof(*result)); type = GetFileType(h); @@ -2107,13 +1952,8 @@ PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev)); #endif PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink)); -#if defined(MS_WINDOWS) - PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong(0)); - PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong(0)); -#else - PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid)); - PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid)); -#endif + PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long)st->st_uid)); + PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long)st->st_gid)); #ifdef HAVE_LARGEFILE_SUPPORT PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong((PY_LONG_LONG)st->st_size)); @@ -2778,7 +2618,7 @@ unsigned long flags; int follow_symlinks = 1; int result; - PyObject *return_value = NULL; + PyObject *return_value; static char *keywords[] = {"path", "flags", "follow_symlinks", NULL}; memset(&path, 0, sizeof(path)); @@ -2927,6 +2767,7 @@ posix_chown(PyObject *self, PyObject *args, PyObject *kwargs) { path_t path; + long uid_l, gid_l; uid_t uid; gid_t gid; int dir_fd = DEFAULT_DIR_FD; @@ -2941,10 +2782,9 @@ #ifdef HAVE_FCHOWN path.allow_fd = 1; #endif - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&|$O&p:chown", keywords, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&ll|$O&p:chown", keywords, path_converter, &path, - _Py_Uid_Converter, &uid, - _Py_Gid_Converter, &gid, + &uid_l, &gid_l, #ifdef HAVE_FCHOWNAT dir_fd_converter, &dir_fd, #else @@ -2975,6 +2815,8 @@ #endif Py_BEGIN_ALLOW_THREADS + uid = (uid_t)uid_l; + gid = (uid_t)gid_l; #ifdef HAVE_FCHOWN if (path.fd != -1) result = fchown(path.fd, uid, gid); @@ -3018,15 +2860,12 @@ posix_fchown(PyObject *self, PyObject *args) { int fd; - uid_t uid; - gid_t gid; + long uid, gid; int res; - if (!PyArg_ParseTuple(args, "iO&O&:fchown", &fd, - _Py_Uid_Converter, &uid, - _Py_Gid_Converter, &gid)) + if (!PyArg_ParseTuple(args, "ill:fchown", &fd, &uid, &gid)) return NULL; Py_BEGIN_ALLOW_THREADS - res = fchown(fd, uid, gid); + res = fchown(fd, (uid_t) uid, (gid_t) gid); Py_END_ALLOW_THREADS if (res < 0) return posix_error(); @@ -3045,18 +2884,16 @@ posix_lchown(PyObject *self, PyObject *args) { path_t path; - uid_t uid; - gid_t gid; + long uid, gid; int res; memset(&path, 0, sizeof(path)); path.function_name = "lchown"; - if (!PyArg_ParseTuple(args, "O&O&O&:lchown", + if (!PyArg_ParseTuple(args, "O&ll:lchown", path_converter, &path, - _Py_Uid_Converter, &uid, - _Py_Gid_Converter, &gid)) + &uid, &gid)) return NULL; Py_BEGIN_ALLOW_THREADS - res = lchown(path.narrow, uid, gid); + res = lchown(path.narrow, (uid_t) uid, (gid_t) gid); Py_END_ALLOW_THREADS if (res < 0) { path_error(&path); @@ -3089,7 +2926,7 @@ terminating \0. If the buffer is too small, len includes the space needed for the terminator. */ if (len >= sizeof wbuf/ sizeof wbuf[0]) { - wbuf2 = PyMem_RawMalloc(len * sizeof(wchar_t)); + wbuf2 = malloc(len * sizeof(wchar_t)); if (wbuf2) len = GetCurrentDirectoryW(len, wbuf2); } @@ -3100,12 +2937,12 @@ } if (!len) { if (wbuf2 != wbuf) - PyMem_RawFree(wbuf2); + free(wbuf2); return PyErr_SetFromWindowsErr(0); } resobj = PyUnicode_FromWideChar(wbuf2, len); if (wbuf2 != wbuf) - PyMem_RawFree(wbuf2); + free(wbuf2); return resobj; } @@ -3261,11 +3098,15 @@ the file descriptor must refer to a directory.\n\ If this functionality is unavailable, using it raises NotImplementedError."); +static PyObject * +posix_listdir(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + PyObject *list = NULL; + static char *keywords[] = {"path", NULL}; + int fd = -1; + #if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR) -static PyObject * -_listdir_windows_no_opendir(path_t *path, PyObject *list) -{ - static char *keywords[] = {"path", NULL}; PyObject *v; HANDLE hFindFile = INVALID_HANDLE_VALUE; BOOL result; @@ -3276,20 +3117,41 @@ Py_ssize_t len = sizeof(namebuf)-5; PyObject *po = NULL; wchar_t *wnamebuf = NULL; - - if (!path->narrow) { +#else + PyObject *v; + DIR *dirp = NULL; + struct dirent *ep; + int return_str; /* if false, return bytes */ +#endif + + memset(&path, 0, sizeof(path)); + path.function_name = "listdir"; + path.nullable = 1; +#ifdef HAVE_FDOPENDIR + path.allow_fd = 1; + path.fd = -1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:listdir", keywords, + path_converter, &path + )) + return NULL; + + /* XXX Should redo this putting the (now four) versions of opendir + in separate files instead of having them all here... */ +#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR) + if (!path.narrow) { WIN32_FIND_DATAW wFileData; wchar_t *po_wchars; - if (!path->wide) { /* Default arg: "." */ + if (!path.wide) { /* Default arg: "." */ po_wchars = L"."; len = 1; } else { - po_wchars = path->wide; - len = wcslen(path->wide); + po_wchars = path.wide; + len = wcslen(path.wide); } /* The +5 is so we can append "\\*.*\0" */ - wnamebuf = PyMem_Malloc((len + 5) * sizeof(wchar_t)); + wnamebuf = malloc((len + 5) * sizeof(wchar_t)); if (!wnamebuf) { PyErr_NoMemory(); goto exit; @@ -3312,7 +3174,7 @@ if (error == ERROR_FILE_NOT_FOUND) goto exit; Py_DECREF(list); - list = path_error(path); + list = path_error(&path); goto exit; } do { @@ -3341,15 +3203,15 @@ it got to the end of the directory. */ if (!result && GetLastError() != ERROR_NO_MORE_FILES) { Py_DECREF(list); - list = path_error(path); + list = path_error(&path); goto exit; } } while (result == TRUE); goto exit; } - strcpy(namebuf, path->narrow); - len = path->length; + strcpy(namebuf, path.narrow); + len = path.length; if (len > 0) { char ch = namebuf[len-1]; if (ch != SEP && ch != ALTSEP && ch != ':') @@ -3368,7 +3230,7 @@ if (error == ERROR_FILE_NOT_FOUND) goto exit; Py_DECREF(list); - list = path_error(path); + list = path_error(&path); goto exit; } do { @@ -3396,7 +3258,7 @@ it got to the end of the directory. */ if (!result && GetLastError() != ERROR_NO_MORE_FILES) { Py_DECREF(list); - list = path_error(path); + list = path_error(&path); goto exit; } } while (result == TRUE); @@ -3406,33 +3268,26 @@ if (FindClose(hFindFile) == FALSE) { if (list != NULL) { Py_DECREF(list); - list = path_error(path); + list = path_error(&path); } } } - PyMem_Free(wnamebuf); + if (wnamebuf) + free(wnamebuf); + path_cleanup(&path); return list; -} /* end of _listdir_windows_no_opendir */ - -#else /* thus POSIX, ie: not (MS_WINDOWS and not HAVE_OPENDIR) */ - -static PyObject * -_posix_listdir(path_t *path, PyObject *list) -{ - int fd = -1; - - PyObject *v; - DIR *dirp = NULL; - struct dirent *ep; - int return_str; /* if false, return bytes */ + +#else errno = 0; #ifdef HAVE_FDOPENDIR - if (path->fd != -1) { + if (path.fd != -1) { /* closedir() closes the FD, so we duplicate it */ Py_BEGIN_ALLOW_THREADS - fd = dup(path->fd); + fd = dup(path.fd); + if (fd != -1) + _Py_try_set_default_cloexec(fd); Py_END_ALLOW_THREADS if (fd == -1) { @@ -3450,10 +3305,10 @@ #endif { char *name; - if (path->narrow) { - name = path->narrow; + if (path.narrow) { + name = path.narrow; /* only return bytes if they specified a bytes object */ - return_str = !(PyBytes_Check(path->object)); + return_str = !(PyBytes_Check(path.object)); } else { name = "."; @@ -3466,7 +3321,7 @@ } if (dirp == NULL) { - list = path_error(path); + list = path_error(&path); goto exit; } if ((list = PyList_New(0)) == NULL) { @@ -3482,7 +3337,7 @@ break; } else { Py_DECREF(list); - list = path_error(path); + list = path_error(&path); goto exit; } } @@ -3515,39 +3370,12 @@ Py_END_ALLOW_THREADS } + path_cleanup(&path); + return list; -} /* end of _posix_listdir */ -#endif /* which OS */ - -static PyObject * -posix_listdir(PyObject *self, PyObject *args, PyObject *kwargs) -{ - path_t path; - PyObject *list = NULL; - static char *keywords[] = {"path", NULL}; - PyObject *return_value; - - memset(&path, 0, sizeof(path)); - path.function_name = "listdir"; - path.nullable = 1; -#ifdef HAVE_FDOPENDIR - path.allow_fd = 1; - path.fd = -1; -#endif - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:listdir", keywords, - path_converter, &path)) { - return NULL; - } - -#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR) - return_value = _listdir_windows_no_opendir(&path, list); -#else - return_value = _posix_listdir(&path, list); -#endif - path_cleanup(&path); - return return_value; -} + +#endif /* which OS */ +} /* end of posix_listdir */ #ifdef MS_WINDOWS /* A helper function for abspath on win32 */ @@ -3574,7 +3402,7 @@ Py_ARRAY_LENGTH(woutbuf), woutbuf, &wtemp); if (result > Py_ARRAY_LENGTH(woutbuf)) { - woutbufp = PyMem_Malloc(result * sizeof(wchar_t)); + woutbufp = malloc(result * sizeof(wchar_t)); if (!woutbufp) return PyErr_NoMemory(); result = GetFullPathNameW(wpath, result, woutbufp, &wtemp); @@ -3584,7 +3412,7 @@ else v = win32_error_object("GetFullPathNameW", po); if (woutbufp != woutbuf) - PyMem_Free(woutbufp); + free(woutbufp); return v; } /* Drop the argument parsing error as narrow strings @@ -3654,7 +3482,7 @@ if(!buf_size) return win32_error_object("GetFinalPathNameByHandle", po); - target_path = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t)); + target_path = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t)); if(!target_path) return PyErr_NoMemory(); @@ -3668,7 +3496,7 @@ target_path[result_length] = 0; result = PyUnicode_FromWideChar(target_path, result_length); - PyMem_Free(target_path); + free(target_path); return result; } /* end of posix__getfinalpathname */ @@ -4256,7 +4084,7 @@ #define SET(i, field) \ { \ - PyObject *o = PyUnicode_DecodeFSDefault(field); \ + PyObject *o = PyUnicode_DecodeASCII(field, strlen(field), NULL); \ if (!o) { \ Py_DECREF(value); \ return NULL; \ @@ -4518,8 +4346,6 @@ } if (times && (times != Py_None)) { - time_t a_sec, m_sec; - long a_nsec, m_nsec; if (!PyTuple_CheckExact(times) || (PyTuple_Size(times) != 2)) { PyErr_SetString(PyExc_TypeError, "utime: 'times' must be either" @@ -4528,15 +4354,11 @@ } utime.now = 0; if (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 0), - &a_sec, &a_nsec) == -1 || + &utime.atime_s, &utime.atime_ns) == -1 || _PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 1), - &m_sec, &m_nsec) == -1) { + &utime.mtime_s, &utime.mtime_ns) == -1) { goto exit; } - utime.atime_s = a_sec; - utime.atime_ns = a_nsec; - utime.mtime_s = m_sec; - utime.mtime_ns = m_nsec; } else if (ns) { if (!PyTuple_CheckExact(ns) || (PyTuple_Size(ns) != 2)) { @@ -5013,7 +4835,11 @@ if (spawnval == -1) return posix_error(); else - return Py_BuildValue(_Py_PARSE_INTPTR, spawnval); +#if SIZEOF_LONG == SIZEOF_VOID_P + return Py_BuildValue("l", (long) spawnval); +#else + return Py_BuildValue("L", (PY_LONG_LONG) spawnval); +#endif } @@ -5099,7 +4925,11 @@ if (spawnval == -1) (void) posix_error(); else - res = Py_BuildValue(_Py_PARSE_INTPTR, spawnval); +#if SIZEOF_LONG == SIZEOF_VOID_P + res = Py_BuildValue("l", (long) spawnval); +#else + res = Py_BuildValue("L", (PY_LONG_LONG) spawnval); +#endif while (--envc >= 0) PyMem_DEL(envlist[envc]); @@ -5607,14 +5437,17 @@ #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) PyDoc_STRVAR(posix_openpty__doc__, -"openpty() -> (master_fd, slave_fd)\n\n\ -Open a pseudo-terminal, returning open fd's for both master and slave end.\n"); - -static PyObject * -posix_openpty(PyObject *self, PyObject *noargs) -{ - int master_fd, slave_fd; +"openpty(cloexec=None) -> (master_fd, slave_fd)\n\n\ +Open a pseudo-terminal, returning open fd's for both master and slave end.\n\ +If cloexec is True, set the close-on-exec flag."); + +static PyObject * +posix_openpty(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *keywords[] = {"cloexec", NULL}; + int master_fd = -1, slave_fd = -1; #ifndef HAVE_OPENPTY + int flags; char * slave_name; #endif #if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY) @@ -5623,40 +5456,94 @@ extern char *ptsname(int fildes); #endif #endif + int cloexec = Py_DefaultCloexec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&:openpty", keywords, + _Py_cloexec_converter, &cloexec)) + return NULL; #ifdef HAVE_OPENPTY - if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0) - return posix_error(); + if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0) { + posix_error(); + goto error; + } + + if (cloexec && _Py_set_cloexec(master_fd, 1, NULL) < 0) + goto error; + if (cloexec && _Py_set_cloexec(slave_fd, 1, NULL) < 0) + goto error; + #elif defined(HAVE__GETPTY) slave_name = _getpty(&master_fd, O_RDWR, 0666, 0); - if (slave_name == NULL) - return posix_error(); - - slave_fd = open(slave_name, O_RDWR); - if (slave_fd < 0) - return posix_error(); -#else - master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */ - if (master_fd < 0) - return posix_error(); + if (slave_name == NULL) { + posix_error(); + goto error; + } + if (cloexec && _Py_set_cloexec(master_fd, 1, NULL) < 0) + goto error; + + flags = O_RDWR; +#ifdef O_CLOEXEC + if (cloexec) + flags |= O_CLOEXEC; +#endif + slave_fd = open(slave_name, flags); + if (slave_fd < 0) { + posix_error(); + goto error; + } + if (cloexec && _Py_set_cloexec(slave_fd, 1, NULL) < 0) + goto error; + +#else + flags = O_RDWR | O_NOCTTY; +#ifdef O_CLOEXEC + if (cloexec) + flags |= O_CLOEXEC; +#endif + master_fd = open(DEV_PTY_FILE, flags); /* open master */ + if (master_fd < 0) { + posix_error(); + goto error; + } + sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL); /* change permission of slave */ if (grantpt(master_fd) < 0) { PyOS_setsig(SIGCHLD, sig_saved); - return posix_error(); + posix_error(); + goto error; } /* unlock slave */ if (unlockpt(master_fd) < 0) { PyOS_setsig(SIGCHLD, sig_saved); - return posix_error(); + posix_error(); + goto error; } PyOS_setsig(SIGCHLD, sig_saved); + + /* grantpt() fails on Solaris 9 if the close-on-exec flag + * is set */ + if (cloexec && _Py_set_cloexec(master_fd, 1, NULL) < 0) + goto error; + slave_name = ptsname(master_fd); /* get name of slave */ - if (slave_name == NULL) - return posix_error(); - slave_fd = open(slave_name, O_RDWR | O_NOCTTY); /* open slave */ - if (slave_fd < 0) - return posix_error(); + if (slave_name == NULL) { + posix_error(); + goto error; + } + flags = O_RDWR | O_NOCTTY; +#ifdef O_CLOEXEC + if (cloexec) + flags |= O_CLOEXEC; +#endif + slave_fd = open(slave_name, flags); /* open slave */ + if (slave_fd < 0) { + posix_error(); + goto error; + } + if (cloexec && _Py_set_cloexec(slave_fd, 1, NULL) < 0) + goto error; #if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC) ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */ ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */ @@ -5668,6 +5555,12 @@ return Py_BuildValue("(ii)", master_fd, slave_fd); +error: + if (master_fd >= 0) + close(master_fd); + if (slave_fd >= 0) + close(slave_fd); + return NULL; } #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */ @@ -5714,7 +5607,7 @@ static PyObject * posix_getegid(PyObject *self, PyObject *noargs) { - return _PyLong_FromGid(getegid()); + return PyLong_FromLong((long)getegid()); } #endif @@ -5727,7 +5620,7 @@ static PyObject * posix_geteuid(PyObject *self, PyObject *noargs) { - return _PyLong_FromUid(geteuid()); + return PyLong_FromLong((long)geteuid()); } #endif @@ -5740,7 +5633,7 @@ static PyObject * posix_getgid(PyObject *self, PyObject *noargs) { - return _PyLong_FromGid(getgid()); + return PyLong_FromLong((long)getgid()); } #endif @@ -5782,14 +5675,8 @@ #endif ngroups = MAX_GROUPS; -#ifdef __APPLE__ - if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid)) - return NULL; -#else - if (!PyArg_ParseTuple(args, "sO&:getgrouplist", &user, - _Py_Gid_Converter, &basegid)) - return NULL; -#endif + if (!PyArg_ParseTuple(args, "si", &user, &basegid)) + return NULL; #ifdef __APPLE__ groups = PyMem_Malloc(ngroups * sizeof(int)); @@ -5811,11 +5698,7 @@ } for (i = 0; i < ngroups; i++) { -#ifdef __APPLE__ PyObject *o = PyLong_FromUnsignedLong((unsigned long)groups[i]); -#else - PyObject *o = _PyLong_FromGid(groups[i]); -#endif if (o == NULL) { Py_DECREF(list); PyMem_Del(groups); @@ -5889,7 +5772,7 @@ if (result != NULL) { int i; for (i = 0; i < n; ++i) { - PyObject *o = _PyLong_FromGid(alt_grouplist[i]); + PyObject *o = PyLong_FromLong((long)alt_grouplist[i]); if (o == NULL) { Py_DECREF(result); result = NULL; @@ -5920,25 +5803,14 @@ PyObject *oname; char *username; int res; -#ifdef __APPLE__ - int gid; -#else - gid_t gid; -#endif - -#ifdef __APPLE__ - if (!PyArg_ParseTuple(args, "O&i:initgroups", - PyUnicode_FSConverter, &oname, - &gid)) -#else - if (!PyArg_ParseTuple(args, "O&O&:initgroups", - PyUnicode_FSConverter, &oname, - _Py_Gid_Converter, &gid)) -#endif + long gid; + + if (!PyArg_ParseTuple(args, "O&l:initgroups", + PyUnicode_FSConverter, &oname, &gid)) return NULL; username = PyBytes_AS_STRING(oname); - res = initgroups(username, gid); + res = initgroups(username, (gid_t) gid); Py_DECREF(oname); if (res == -1) return PyErr_SetFromErrno(PyExc_OSError); @@ -6113,7 +5985,7 @@ static PyObject * posix_getuid(PyObject *self, PyObject *noargs) { - return _PyLong_FromUid(getuid()); + return PyLong_FromLong((long)getuid()); } #endif @@ -6169,17 +6041,16 @@ win32_kill(PyObject *self, PyObject *args) { PyObject *result; - pid_t pid; - DWORD sig, err; + DWORD pid, sig, err; HANDLE handle; - if (!PyArg_ParseTuple(args, _Py_PARSE_PID "k:kill", &pid, &sig)) + if (!PyArg_ParseTuple(args, "kk:kill", &pid, &sig)) return NULL; /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { - if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) { + if (GenerateConsoleCtrlEvent(sig, pid) == 0) { err = GetLastError(); PyErr_SetFromWindowsErr(err); } @@ -6189,7 +6060,7 @@ /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */ - handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid); + handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); if (handle == NULL) { err = GetLastError(); return PyErr_SetFromWindowsErr(err); @@ -6239,9 +6110,15 @@ static PyObject * posix_setuid(PyObject *self, PyObject *args) { + long uid_arg; uid_t uid; - if (!PyArg_ParseTuple(args, "O&:setuid", _Py_Uid_Converter, &uid)) - return NULL; + if (!PyArg_ParseTuple(args, "l:setuid", &uid_arg)) + return NULL; + uid = uid_arg; + if (uid != uid_arg) { + PyErr_SetString(PyExc_OverflowError, "user id too big"); + return NULL; + } if (setuid(uid) < 0) return posix_error(); Py_INCREF(Py_None); @@ -6258,9 +6135,15 @@ static PyObject * posix_seteuid (PyObject *self, PyObject *args) { + long euid_arg; uid_t euid; - if (!PyArg_ParseTuple(args, "O&:seteuid", _Py_Uid_Converter, &euid)) - return NULL; + if (!PyArg_ParseTuple(args, "l", &euid_arg)) + return NULL; + euid = euid_arg; + if (euid != euid_arg) { + PyErr_SetString(PyExc_OverflowError, "user id too big"); + return NULL; + } if (seteuid(euid) < 0) { return posix_error(); } else { @@ -6278,9 +6161,15 @@ static PyObject * posix_setegid (PyObject *self, PyObject *args) { + long egid_arg; gid_t egid; - if (!PyArg_ParseTuple(args, "O&:setegid", _Py_Gid_Converter, &egid)) - return NULL; + if (!PyArg_ParseTuple(args, "l", &egid_arg)) + return NULL; + egid = egid_arg; + if (egid != egid_arg) { + PyErr_SetString(PyExc_OverflowError, "group id too big"); + return NULL; + } if (setegid(egid) < 0) { return posix_error(); } else { @@ -6298,11 +6187,23 @@ static PyObject * posix_setreuid (PyObject *self, PyObject *args) { + long ruid_arg, euid_arg; uid_t ruid, euid; - if (!PyArg_ParseTuple(args, "O&O&:setreuid", - _Py_Uid_Converter, &ruid, - _Py_Uid_Converter, &euid)) - return NULL; + if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg)) + return NULL; + if (ruid_arg == -1) + ruid = (uid_t)-1; /* let the compiler choose how -1 fits */ + else + ruid = ruid_arg; /* otherwise, assign from our long */ + if (euid_arg == -1) + euid = (uid_t)-1; + else + euid = euid_arg; + if ((euid_arg != -1 && euid != euid_arg) || + (ruid_arg != -1 && ruid != ruid_arg)) { + PyErr_SetString(PyExc_OverflowError, "user id too big"); + return NULL; + } if (setreuid(ruid, euid) < 0) { return posix_error(); } else { @@ -6320,11 +6221,23 @@ static PyObject * posix_setregid (PyObject *self, PyObject *args) { + long rgid_arg, egid_arg; gid_t rgid, egid; - if (!PyArg_ParseTuple(args, "O&O&:setregid", - _Py_Gid_Converter, &rgid, - _Py_Gid_Converter, &egid)) - return NULL; + if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg)) + return NULL; + if (rgid_arg == -1) + rgid = (gid_t)-1; /* let the compiler choose how -1 fits */ + else + rgid = rgid_arg; /* otherwise, assign from our long */ + if (egid_arg == -1) + egid = (gid_t)-1; + else + egid = egid_arg; + if ((egid_arg != -1 && egid != egid_arg) || + (rgid_arg != -1 && rgid != rgid_arg)) { + PyErr_SetString(PyExc_OverflowError, "group id too big"); + return NULL; + } if (setregid(rgid, egid) < 0) { return posix_error(); } else { @@ -6342,9 +6255,15 @@ static PyObject * posix_setgid(PyObject *self, PyObject *args) { + long gid_arg; gid_t gid; - if (!PyArg_ParseTuple(args, "O&:setgid", _Py_Gid_Converter, &gid)) - return NULL; + if (!PyArg_ParseTuple(args, "l:setgid", &gid_arg)) + return NULL; + gid = gid_arg; + if (gid != gid_arg) { + PyErr_SetString(PyExc_OverflowError, "group id too big"); + return NULL; + } if (setgid(gid) < 0) return posix_error(); Py_INCREF(Py_None); @@ -6383,7 +6302,18 @@ Py_DECREF(elem); return NULL; } else { - if (!_Py_Gid_Converter(elem, &grouplist[i])) { + unsigned long x = PyLong_AsUnsignedLong(elem); + if (PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "group id too big"); + Py_DECREF(elem); + return NULL; + } + grouplist[i] = x; + /* read back the value to see if it fitted in gid_t */ + if (grouplist[i] != x) { + PyErr_SetString(PyExc_TypeError, + "group id too big"); Py_DECREF(elem); return NULL; } @@ -6545,7 +6475,7 @@ return NULL; PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid)); - PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid)); + PyStructSequence_SET_ITEM(result, 1, PyLong_FromPid(si.si_uid)); PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo))); PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status))); PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code))); @@ -6595,7 +6525,7 @@ Py_intptr_t pid; int status, options; - if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:waitpid", &pid, &options)) + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:waitpid", &pid, &options)) return NULL; Py_BEGIN_ALLOW_THREADS pid = _cwait(&status, pid, options); @@ -6604,7 +6534,7 @@ return posix_error(); /* shift the status left a byte so this is more like the POSIX waitpid */ - return Py_BuildValue(_Py_PARSE_INTPTR "i", pid, status << 8); + return Py_BuildValue("Ni", PyLong_FromPid(pid), status << 8); } #endif /* HAVE_WAITPID || HAVE_CWAIT */ @@ -6712,9 +6642,8 @@ /* Grab CreateSymbolicLinkW dynamically from kernel32 */ static DWORD (CALLBACK *Py_CreateSymbolicLinkW)(LPWSTR, LPWSTR, DWORD) = NULL; static DWORD (CALLBACK *Py_CreateSymbolicLinkA)(LPSTR, LPSTR, DWORD) = NULL; - static int -check_CreateSymbolicLink(void) +check_CreateSymbolicLink() { HINSTANCE hKernel32; /* only recheck */ @@ -6728,130 +6657,6 @@ return (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA); } -/* Remove the last portion of the path */ -static void -_dirnameW(WCHAR *path) -{ - WCHAR *ptr; - - /* walk the path from the end until a backslash is encountered */ - for(ptr = path + wcslen(path); ptr != path; ptr--) { - if (*ptr == L'\\' || *ptr == L'/') - break; - } - *ptr = 0; -} - -/* Remove the last portion of the path */ -static void -_dirnameA(char *path) -{ - char *ptr; - - /* walk the path from the end until a backslash is encountered */ - for(ptr = path + strlen(path); ptr != path; ptr--) { - if (*ptr == '\\' || *ptr == '/') - break; - } - *ptr = 0; -} - -/* Is this path absolute? */ -static int -_is_absW(const WCHAR *path) -{ - return path[0] == L'\\' || path[0] == L'/' || path[1] == L':'; - -} - -/* Is this path absolute? */ -static int -_is_absA(const char *path) -{ - return path[0] == '\\' || path[0] == '/' || path[1] == ':'; - -} - -/* join root and rest with a backslash */ -static void -_joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest) -{ - size_t root_len; - - if (_is_absW(rest)) { - wcscpy(dest_path, rest); - return; - } - - root_len = wcslen(root); - - wcscpy(dest_path, root); - if(root_len) { - dest_path[root_len] = L'\\'; - root_len++; - } - wcscpy(dest_path+root_len, rest); -} - -/* join root and rest with a backslash */ -static void -_joinA(char *dest_path, const char *root, const char *rest) -{ - size_t root_len; - - if (_is_absA(rest)) { - strcpy(dest_path, rest); - return; - } - - root_len = strlen(root); - - strcpy(dest_path, root); - if(root_len) { - dest_path[root_len] = '\\'; - root_len++; - } - strcpy(dest_path+root_len, rest); -} - -/* Return True if the path at src relative to dest is a directory */ -static int -_check_dirW(WCHAR *src, WCHAR *dest) -{ - WIN32_FILE_ATTRIBUTE_DATA src_info; - WCHAR dest_parent[MAX_PATH]; - WCHAR src_resolved[MAX_PATH] = L""; - - /* dest_parent = os.path.dirname(dest) */ - wcscpy(dest_parent, dest); - _dirnameW(dest_parent); - /* src_resolved = os.path.join(dest_parent, src) */ - _joinW(src_resolved, dest_parent, src); - return ( - GetFileAttributesExW(src_resolved, GetFileExInfoStandard, &src_info) - && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY - ); -} - -/* Return True if the path at src relative to dest is a directory */ -static int -_check_dirA(char *src, char *dest) -{ - WIN32_FILE_ATTRIBUTE_DATA src_info; - char dest_parent[MAX_PATH]; - char src_resolved[MAX_PATH] = ""; - - /* dest_parent = os.path.dirname(dest) */ - strcpy(dest_parent, dest); - _dirnameA(dest_parent); - /* src_resolved = os.path.join(dest_parent, src) */ - _joinA(src_resolved, dest_parent, src); - return ( - GetFileAttributesExA(src_resolved, GetFileExInfoStandard, &src_info) - && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY - ); -} - #endif static PyObject * @@ -6910,20 +6715,13 @@ } #ifdef MS_WINDOWS - Py_BEGIN_ALLOW_THREADS - if (dst.wide) { - /* if src is a directory, ensure target_is_directory==1 */ - target_is_directory |= _check_dirW(src.wide, dst.wide); + if (dst.wide) result = Py_CreateSymbolicLinkW(dst.wide, src.wide, target_is_directory); - } - else { - /* if src is a directory, ensure target_is_directory==1 */ - target_is_directory |= _check_dirA(src.narrow, dst.narrow); + else result = Py_CreateSymbolicLinkA(dst.narrow, src.narrow, target_is_directory); - } Py_END_ALLOW_THREADS if (!result) { @@ -7247,14 +7045,20 @@ /* Functions acting on file descriptors */ +#ifdef O_CLOEXEC +extern int _Py_open_cloexec_works; +#endif + PyDoc_STRVAR(posix_open__doc__, -"open(path, flags, mode=0o777, *, dir_fd=None)\n\n\ +"open(path, flags, mode=0o777, *, dir_fd=None, cloexec=None)\n\n\ Open a file for low level IO. Returns a file handle (integer).\n\ \n\ If dir_fd is not None, it should be a file descriptor open to a directory,\n\ and path should be relative; path will then be relative to that directory.\n\ dir_fd may not be implemented on your platform.\n\ - If it is unavailable, using it will raise a NotImplementedError."); + If it is unavailable, using it will raise a NotImplementedError.\n\ +\n\ +If cloexec is True, set the close-on-exec flag."); static PyObject * posix_open(PyObject *self, PyObject *args, PyObject *kwargs) @@ -7263,22 +7067,31 @@ int flags; int mode = 0777; int dir_fd = DEFAULT_DIR_FD; + int cloexec = Py_DefaultCloexec; int fd; PyObject *return_value = NULL; - static char *keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; + static char *keywords[] = {"path", "flags", "mode", "dir_fd", "cloexec", NULL}; memset(&path, 0, sizeof(path)); path.function_name = "open"; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|i$O&:open", keywords, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|i$O&O&:open", keywords, path_converter, &path, &flags, &mode, #ifdef HAVE_OPENAT - dir_fd_converter, &dir_fd -#else - dir_fd_unavailable, &dir_fd -#endif - )) - return NULL; + dir_fd_converter, &dir_fd, +#else + dir_fd_unavailable, &dir_fd, +#endif + _Py_cloexec_converter, &cloexec)) + return NULL; + + if (cloexec) { +#ifdef MS_WINDOWS + flags |= O_NOINHERIT; +#elif defined(O_CLOEXEC) + flags |= O_CLOEXEC; +#endif + } Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS @@ -7299,6 +7112,20 @@ goto exit; } +#ifndef MS_WINDOWS + if (cloexec) { +#ifdef O_CLOEXEC + int *atomic_flag_works = &_Py_open_cloexec_works; +#else + int *atomic_flag_works = NULL; +#endif + if (_Py_set_cloexec(fd, 1, atomic_flag_works) < 0) { + close(fd); + goto exit; + } + } +#endif + return_value = PyLong_FromLong((long)fd); exit: @@ -7348,39 +7175,142 @@ PyDoc_STRVAR(posix_dup__doc__, -"dup(fd) -> fd2\n\n\ -Return a duplicate of a file descriptor."); - -static PyObject * -posix_dup(PyObject *self, PyObject *args) -{ + "dup(fd, cloexec=None) -> fd2\n\n" + "Return a duplicate of a file descriptor.\n" + "If cloexec is True, set the close-on-exec flag."); + +static PyObject * +posix_dup(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = {"fd", "cloexec", NULL}; int fd; - if (!PyArg_ParseTuple(args, "i:dup", &fd)) - return NULL; + int cloexec = Py_DefaultCloexec; +#ifdef MS_WINDOWS + HANDLE handle, handle2, process; + BOOL ok; +#endif + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|O&:dup", keywords, + &fd, _Py_cloexec_converter, &cloexec)) + return NULL; + if (!_PyVerify_fd(fd)) return posix_error(); - fd = dup(fd); - if (fd < 0) - return posix_error(); + +#ifdef MS_WINDOWS + handle = (HANDLE)_Py_get_osfhandle(fd, 1); + if (handle == INVALID_HANDLE_VALUE) + return NULL; + process = GetCurrentProcess(); + + ok = DuplicateHandle(process, handle, + process, &handle2, + 0, + cloexec ? FALSE : TRUE, + DUPLICATE_SAME_ACCESS); + if (!ok) + return PyErr_SetFromWindowsErr(0); + + fd = _Py_open_osfhandle((Py_intptr_t)handle2, _O_RDWR, 1); + if (fd == -1) { + CloseHandle(handle2); + return NULL; + } +#else + +#if defined(HAVE_FCNTL_H) && defined(F_DUPFD_CLOEXEC) + if (cloexec) { + fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); + if (fd < 0) + return posix_error(); + } + else { +#endif + fd = dup(fd); + if (fd < 0) + return posix_error(); + if (cloexec && _Py_set_cloexec(fd, 1, NULL) < 0) { + close(fd); + return NULL; + } +#if defined(HAVE_FCNTL_H) && defined(F_DUPFD_CLOEXEC) + } +#endif +#endif return PyLong_FromLong((long)fd); } PyDoc_STRVAR(posix_dup2__doc__, -"dup2(old_fd, new_fd)\n\n\ -Duplicate file descriptor."); - -static PyObject * -posix_dup2(PyObject *self, PyObject *args) -{ +"dup2(fd, fd2, cloexec=None)\n\n\ +Duplicate file descriptor. If cloexec is True, set the close-on-exec flag on fd2."); + +static PyObject * +posix_dup2(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *keywords[] = {"fd", "fd2", "cloexec", NULL}; int fd, fd2, res; - if (!PyArg_ParseTuple(args, "ii:dup2", &fd, &fd2)) + int cloexec = Py_DefaultCloexec; +#if defined(HAVE_DUP3) && \ + !(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC)) + /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */ + int dup3_works = -1; +#endif + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii|O&:dup2", keywords, + &fd, &fd2, + _Py_cloexec_converter, &cloexec)) return NULL; if (!_PyVerify_fd_dup2(fd, fd2)) return posix_error(); - res = dup2(fd, fd2); + +#if defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC) + Py_BEGIN_ALLOW_THREADS + if (cloexec) + res = fcntl(fd, F_DUP2FD_CLOEXEC, fd2); + else + res = dup2(fd, fd2); + Py_END_ALLOW_THREADS if (res < 0) return posix_error(); +#else + +#ifdef HAVE_DUP3 + if (dup3_works != 0) { + int flags; + if (cloexec) + flags = O_CLOEXEC; + else + flags = 0; + Py_BEGIN_ALLOW_THREADS + res = dup3(fd, fd2, flags); + Py_END_ALLOW_THREADS + if (res < 0) { + if (dup3_works == -1) + dup3_works = (errno != ENOSYS); + if (dup3_works) + return posix_error(); + } + } + + if (dup3_works == 0) + { +#endif /* HAVE_DUP3 */ + Py_BEGIN_ALLOW_THREADS + res = dup2(fd, fd2); + Py_END_ALLOW_THREADS + if (res < 0) + return posix_error(); + if (cloexec && _Py_set_cloexec(fd2, 1, NULL) < 0) { + close(fd2); + return NULL; + } +#ifdef HAVE_DUP3 + } +#endif /* HAVE_DUP3 */ + +#endif /* !(defined(HAVE_FCNTL_H) && defined(F_DUPFD_CLOEXEC)) */ + Py_INCREF(Py_None); return Py_None; } @@ -7424,7 +7354,7 @@ posix_lseek(PyObject *self, PyObject *args) { int fd, how; -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) PY_LONG_LONG pos, res; #else off_t pos, res; @@ -7452,7 +7382,7 @@ if (!_PyVerify_fd(fd)) return posix_error(); Py_BEGIN_ALLOW_THREADS -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) res = _lseeki64(fd, pos, how); #else res = lseek(fd, pos, how); @@ -7470,7 +7400,7 @@ PyDoc_STRVAR(posix_read__doc__, -"read(fd, buffersize) -> bytes\n\n\ +"read(fd, buffersize) -> string\n\n\ Read a file descriptor."); static PyObject * @@ -7640,8 +7570,8 @@ #endif PyDoc_STRVAR(posix_write__doc__, -"write(fd, data) -> byteswritten\n\n\ -Write bytes to a file descriptor."); +"write(fd, string) -> byteswritten\n\n\ +Write a string to a file descriptor."); static PyObject * posix_write(PyObject *self, PyObject *args) @@ -7658,7 +7588,7 @@ } len = pbuf.len; Py_BEGIN_ALLOW_THREADS -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) if (len > INT_MAX) len = INT_MAX; size = write(fd, pbuf.buf, (int)len); @@ -7695,13 +7625,12 @@ off_t sbytes; struct sf_hdtr sf; int flags = 0; + sf.headers = NULL; + sf.trailers = NULL; static char *keywords[] = {"out", "in", "offset", "count", "headers", "trailers", "flags", NULL}; - sf.headers = NULL; - sf.trailers = NULL; - #ifdef __APPLE__ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&O&|OOi:sendfile", keywords, &out, &in, _parse_off_t, &offset, _parse_off_t, &sbytes, @@ -7861,30 +7790,91 @@ #ifdef HAVE_PIPE PyDoc_STRVAR(posix_pipe__doc__, -"pipe() -> (read_end, write_end)\n\n\ -Create a pipe."); - -static PyObject * -posix_pipe(PyObject *self, PyObject *noargs) -{ -#if !defined(MS_WINDOWS) +"pipe(cloexec=None) -> (read_end, write_end)\n\n" +"Create a pipe. If cloexec is True, set the close-on-exec flag."); + +static PyObject * +posix_pipe(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = {"cloexec", NULL}; int fds[2]; + int cloexec = Py_DefaultCloexec; +#ifdef MS_WINDOWS + HANDLE read, write; + SECURITY_ATTRIBUTES attr; + BOOL ok; +#else +#ifdef HAVE_PIPE2 + static int pipe2_works = -1; + int flags; +#endif int res; - res = pipe(fds); - if (res != 0) - return posix_error(); - return Py_BuildValue("(ii)", fds[0], fds[1]); -#else /* MS_WINDOWS */ - HANDLE read, write; - int read_fd, write_fd; - BOOL ok; - ok = CreatePipe(&read, &write, NULL, 0); +#endif + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:pipe", keywords, + _Py_cloexec_converter, &cloexec)) + return NULL; + +#ifdef MS_WINDOWS + attr.nLength = sizeof(attr); + attr.lpSecurityDescriptor = NULL; + attr.bInheritHandle = (cloexec ? FALSE : TRUE); + + ok = CreatePipe(&read, &write, &attr, 0); + if (!ok) return PyErr_SetFromWindowsErr(0); - read_fd = _open_osfhandle((Py_intptr_t)read, 0); - write_fd = _open_osfhandle((Py_intptr_t)write, 1); - return Py_BuildValue("(ii)", read_fd, write_fd); -#endif /* MS_WINDOWS */ + + fds[0] = _Py_open_osfhandle((Py_intptr_t)read, _O_RDONLY, 1); + if (fds[0] == -1) { + CloseHandle(read); + CloseHandle(write); + return NULL; + } + + fds[1] = _Py_open_osfhandle((Py_intptr_t)write, _O_WRONLY, 1); + if (fds[1] == -1) { + CloseHandle(read); + CloseHandle(write); + return NULL; + } +#else + +#ifdef HAVE_PIPE2 + if (pipe2_works != 0) { + flags = cloexec ? O_CLOEXEC : 0; + + res = pipe2(fds, flags); + + if (pipe2_works == -1) + pipe2_works = (res == 0 || errno != ENOSYS); + } + + if (pipe2_works == 0) + { +#endif + res = pipe(fds); + + if (cloexec && res == 0) { + if (_Py_set_cloexec(fds[0], 1, NULL) < 0) { + close(fds[0]); + close(fds[1]); + return NULL; + } + if (_Py_set_cloexec(fds[1], 1, NULL) < 0) { + close(fds[0]); + close(fds[1]); + return NULL; + } + } +#ifdef HAVE_PIPE2 + } +#endif + + if (res != 0) + return PyErr_SetFromErrno(PyExc_OSError); +#endif /* !MS_WINDOWS */ + return Py_BuildValue("(ii)", fds[0], fds[1]); } #endif /* HAVE_PIPE */ @@ -9140,7 +9130,7 @@ PyObject *result = NULL; int name; char buffer[255]; - size_t len; + int len; if (!PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) return NULL; @@ -9157,7 +9147,7 @@ } } - if (len >= sizeof(buffer)) { + if ((unsigned int)len >= sizeof(buffer)) { char *buf = PyMem_Malloc(len); if (buf == NULL) return PyErr_NoMemory(); @@ -9687,7 +9677,7 @@ int name; if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) { - long value; + int value; errno = 0; value = sysconf(name); @@ -9928,11 +9918,8 @@ posix_setresuid (PyObject *self, PyObject *args) { /* We assume uid_t is no larger than a long. */ - uid_t ruid, euid, suid; - if (!PyArg_ParseTuple(args, "O&O&O&:setresuid", - _Py_Uid_Converter, &ruid, - _Py_Uid_Converter, &euid, - _Py_Uid_Converter, &suid)) + long ruid, euid, suid; + if (!PyArg_ParseTuple(args, "lll", &ruid, &euid, &suid)) return NULL; if (setresuid(ruid, euid, suid) < 0) return posix_error(); @@ -9948,11 +9935,9 @@ static PyObject* posix_setresgid (PyObject *self, PyObject *args) { - gid_t rgid, egid, sgid; - if (!PyArg_ParseTuple(args, "O&O&O&:setresgid", - _Py_Gid_Converter, &rgid, - _Py_Gid_Converter, &egid, - _Py_Gid_Converter, &sgid)) + /* We assume uid_t is no larger than a long. */ + long rgid, egid, sgid; + if (!PyArg_ParseTuple(args, "lll", &rgid, &egid, &sgid)) return NULL; if (setresgid(rgid, egid, sgid) < 0) return posix_error(); @@ -9969,11 +9954,14 @@ posix_getresuid (PyObject *self, PyObject *noargs) { uid_t ruid, euid, suid; + long l_ruid, l_euid, l_suid; if (getresuid(&ruid, &euid, &suid) < 0) return posix_error(); - return Py_BuildValue("(NNN)", _PyLong_FromUid(ruid), - _PyLong_FromUid(euid), - _PyLong_FromUid(suid)); + /* Force the values into long's as we don't know the size of uid_t. */ + l_ruid = ruid; + l_euid = euid; + l_suid = suid; + return Py_BuildValue("(lll)", l_ruid, l_euid, l_suid); } #endif @@ -9986,11 +9974,14 @@ posix_getresgid (PyObject *self, PyObject *noargs) { uid_t rgid, egid, sgid; + long l_rgid, l_egid, l_sgid; if (getresgid(&rgid, &egid, &sgid) < 0) return posix_error(); - return Py_BuildValue("(NNN)", _PyLong_FromGid(rgid), - _PyLong_FromGid(egid), - _PyLong_FromGid(sgid)); + /* Force the values into long's as we don't know the size of uid_t. */ + l_rgid = rgid; + l_egid = egid; + l_sgid = sgid; + return Py_BuildValue("(lll)", l_rgid, l_egid, l_sgid); } #endif @@ -10256,11 +10247,8 @@ Py_END_ALLOW_THREADS; if (length < 0) { - if (errno == ERANGE) { - PyMem_FREE(buffer); - buffer = NULL; + if (errno == ERANGE) continue; - } path_error(&path); break; } @@ -10439,40 +10427,81 @@ } #endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */ -PyDoc_STRVAR(posix_cpu_count__doc__, -"cpu_count() -> integer\n\n\ -Return the number of CPUs in the system, or None if this value cannot be\n\ -established."); - -static PyObject * -posix_cpu_count(PyObject *self) -{ - int ncpu = 0; +#if defined(MS_WINDOWS) \ + || (defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX)) \ + || defined(HAVE_FCNTL_H) +#define POSIX_SET_CLOEXEC +#endif + +#ifdef POSIX_SET_CLOEXEC +PyDoc_STRVAR(get_cloexec__doc__, + "get_cloexec(fd) -> bool\n" \ + "\n" \ + "Get the close-on-exe flag of the specified file descriptor."); + +static PyObject* +posix_get_cloexec(PyObject *self, PyObject *args) +{ + int cloexec; #ifdef MS_WINDOWS - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - ncpu = sysinfo.dwNumberOfProcessors; -#elif defined(__hpux) - ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL); -#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) - ncpu = sysconf(_SC_NPROCESSORS_ONLN); -#elif defined(__DragonFly__) || \ - defined(__OpenBSD__) || \ - defined(__FreeBSD__) || \ - defined(__NetBSD__) || \ - defined(__APPLE__) - int mib[2]; - size_t len = sizeof(ncpu); - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0) - ncpu = 0; -#endif - if (ncpu >= 1) - return PyLong_FromLong(ncpu); + long handle; + + if (!PyArg_ParseTuple(args, "l:get_cloexec", &handle)) + return NULL; + + if (handle < INT_MIN || handle > INT_MAX || !_PyVerify_fd((int)handle)) + cloexec = _Py_get_cloexec_handle((Py_intptr_t)handle); else - Py_RETURN_NONE; -} + cloexec = _Py_get_cloexec((int)handle); +#else + int fd; + + if (!PyArg_ParseTuple(args, "i:get_cloexec", &fd)) + return NULL; + + cloexec = _Py_get_cloexec(fd); +#endif + if (cloexec < 0) + return NULL; + + return PyBool_FromLong(cloexec); +} + +PyDoc_STRVAR(set_cloexec__doc__, + "set_cloexec(fd, cloexec=True)\n" \ + "\n" \ + "Set or clear close-on-exe flag on the specified file descriptor."); + +static PyObject* +posix_set_cloexec(PyObject *self, PyObject *args) +{ + int cloexec = 1; + int res; +#ifdef MS_WINDOWS + long handle; + + if (!PyArg_ParseTuple(args, "l|i:set_cloexec", &handle, &cloexec)) + return NULL; + + if (handle < INT_MIN || handle > INT_MAX || !_PyVerify_fd((int)handle)) + res = _Py_set_cloexec_handle((Py_intptr_t)handle, cloexec, NULL); + else + res = _Py_set_cloexec((int)handle, cloexec, NULL); +#else + int fd; + + if (!PyArg_ParseTuple(args, "i|i:set_cloexec", &fd, &cloexec)) + return NULL; + + res = _Py_set_cloexec(fd, cloexec, NULL); +#endif + if (res < 0) + return NULL; + + Py_RETURN_NONE; +} +#endif /* POSIX_SET_CLOEXEC */ + static PyMethodDef posix_methods[] = { @@ -10638,7 +10667,8 @@ #endif #endif /* HAVE_SCHED_H */ #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) - {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__}, + {"openpty", (PyCFunction)posix_openpty, + METH_VARARGS | METH_KEYWORDS, posix_openpty__doc__}, #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */ #ifdef HAVE_FORKPTY {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__}, @@ -10750,8 +10780,10 @@ {"close", posix_close, METH_VARARGS, posix_close__doc__}, {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__}, {"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__}, - {"dup", posix_dup, METH_VARARGS, posix_dup__doc__}, - {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__}, + {"dup", (PyCFunction)posix_dup, + METH_VARARGS | METH_KEYWORDS, posix_dup__doc__}, + {"dup2", (PyCFunction)posix_dup2, + METH_VARARGS | METH_KEYWORDS, posix_dup2__doc__}, #ifdef HAVE_LOCKF {"lockf", posix_lockf, METH_VARARGS, posix_lockf__doc__}, #endif @@ -10777,7 +10809,8 @@ {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__}, {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__}, #ifdef HAVE_PIPE - {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__}, + {"pipe", (PyCFunction)posix_pipe, + METH_VARARGS | METH_KEYWORDS, posix_pipe__doc__}, #endif #ifdef HAVE_PIPE2 {"pipe2", posix_pipe2, METH_O, posix_pipe2__doc__}, @@ -10919,12 +10952,20 @@ #if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) {"get_terminal_size", get_terminal_size, METH_VARARGS, termsize__doc__}, #endif - {"cpu_count", (PyCFunction)posix_cpu_count, - METH_NOARGS, posix_cpu_count__doc__}, +#ifdef POSIX_SET_CLOEXEC + {"get_cloexec", posix_get_cloexec, METH_VARARGS, get_cloexec__doc__}, + {"set_cloexec", posix_set_cloexec, METH_VARARGS, set_cloexec__doc__}, +#endif {NULL, NULL} /* Sentinel */ }; +static int +ins(PyObject *module, char *symbol, long value) +{ + return PyModule_AddIntConstant(module, symbol, value); +} + #if defined(HAVE_SYMLINK) && defined(MS_WINDOWS) static int enable_symlink() @@ -10955,376 +10996,373 @@ #endif /* defined(HAVE_SYMLINK) && defined(MS_WINDOWS) */ static int -all_ins(PyObject *m) +all_ins(PyObject *d) { #ifdef F_OK - if (PyModule_AddIntMacro(m, F_OK)) return -1; + if (ins(d, "F_OK", (long)F_OK)) return -1; #endif #ifdef R_OK - if (PyModule_AddIntMacro(m, R_OK)) return -1; + if (ins(d, "R_OK", (long)R_OK)) return -1; #endif #ifdef W_OK - if (PyModule_AddIntMacro(m, W_OK)) return -1; + if (ins(d, "W_OK", (long)W_OK)) return -1; #endif #ifdef X_OK - if (PyModule_AddIntMacro(m, X_OK)) return -1; + if (ins(d, "X_OK", (long)X_OK)) return -1; #endif #ifdef NGROUPS_MAX - if (PyModule_AddIntMacro(m, NGROUPS_MAX)) return -1; + if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1; #endif #ifdef TMP_MAX - if (PyModule_AddIntMacro(m, TMP_MAX)) return -1; + if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1; #endif #ifdef WCONTINUED - if (PyModule_AddIntMacro(m, WCONTINUED)) return -1; + if (ins(d, "WCONTINUED", (long)WCONTINUED)) return -1; #endif #ifdef WNOHANG - if (PyModule_AddIntMacro(m, WNOHANG)) return -1; + if (ins(d, "WNOHANG", (long)WNOHANG)) return -1; #endif #ifdef WUNTRACED - if (PyModule_AddIntMacro(m, WUNTRACED)) return -1; + if (ins(d, "WUNTRACED", (long)WUNTRACED)) return -1; #endif #ifdef O_RDONLY - if (PyModule_AddIntMacro(m, O_RDONLY)) return -1; + if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1; #endif #ifdef O_WRONLY - if (PyModule_AddIntMacro(m, O_WRONLY)) return -1; + if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1; #endif #ifdef O_RDWR - if (PyModule_AddIntMacro(m, O_RDWR)) return -1; + if (ins(d, "O_RDWR", (long)O_RDWR)) return -1; #endif #ifdef O_NDELAY - if (PyModule_AddIntMacro(m, O_NDELAY)) return -1; + if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1; #endif #ifdef O_NONBLOCK - if (PyModule_AddIntMacro(m, O_NONBLOCK)) return -1; + if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1; #endif #ifdef O_APPEND - if (PyModule_AddIntMacro(m, O_APPEND)) return -1; + if (ins(d, "O_APPEND", (long)O_APPEND)) return -1; #endif #ifdef O_DSYNC - if (PyModule_AddIntMacro(m, O_DSYNC)) return -1; + if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1; #endif #ifdef O_RSYNC - if (PyModule_AddIntMacro(m, O_RSYNC)) return -1; + if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1; #endif #ifdef O_SYNC - if (PyModule_AddIntMacro(m, O_SYNC)) return -1; + if (ins(d, "O_SYNC", (long)O_SYNC)) return -1; #endif #ifdef O_NOCTTY - if (PyModule_AddIntMacro(m, O_NOCTTY)) return -1; + if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1; #endif #ifdef O_CREAT - if (PyModule_AddIntMacro(m, O_CREAT)) return -1; + if (ins(d, "O_CREAT", (long)O_CREAT)) return -1; #endif #ifdef O_EXCL - if (PyModule_AddIntMacro(m, O_EXCL)) return -1; + if (ins(d, "O_EXCL", (long)O_EXCL)) return -1; #endif #ifdef O_TRUNC - if (PyModule_AddIntMacro(m, O_TRUNC)) return -1; + if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1; #endif #ifdef O_BINARY - if (PyModule_AddIntMacro(m, O_BINARY)) return -1; + if (ins(d, "O_BINARY", (long)O_BINARY)) return -1; #endif #ifdef O_TEXT - if (PyModule_AddIntMacro(m, O_TEXT)) return -1; + if (ins(d, "O_TEXT", (long)O_TEXT)) return -1; #endif #ifdef O_XATTR - if (PyModule_AddIntMacro(m, O_XATTR)) return -1; + if (ins(d, "O_XATTR", (long)O_XATTR)) return -1; #endif #ifdef O_LARGEFILE - if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1; + if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1; #endif #ifdef O_SHLOCK - if (PyModule_AddIntMacro(m, O_SHLOCK)) return -1; + if (ins(d, "O_SHLOCK", (long)O_SHLOCK)) return -1; #endif #ifdef O_EXLOCK - if (PyModule_AddIntMacro(m, O_EXLOCK)) return -1; + if (ins(d, "O_EXLOCK", (long)O_EXLOCK)) return -1; #endif #ifdef O_EXEC - if (PyModule_AddIntMacro(m, O_EXEC)) return -1; + if (ins(d, "O_EXEC", (long)O_EXEC)) return -1; #endif #ifdef O_SEARCH - if (PyModule_AddIntMacro(m, O_SEARCH)) return -1; -#endif -#ifdef O_PATH - if (PyModule_AddIntMacro(m, O_PATH)) return -1; + if (ins(d, "O_SEARCH", (long)O_SEARCH)) return -1; #endif #ifdef O_TTY_INIT - if (PyModule_AddIntMacro(m, O_TTY_INIT)) return -1; + if (ins(d, "O_TTY_INIT", (long)O_TTY_INIT)) return -1; #endif #ifdef PRIO_PROCESS - if (PyModule_AddIntMacro(m, PRIO_PROCESS)) return -1; + if (ins(d, "PRIO_PROCESS", (long)PRIO_PROCESS)) return -1; #endif #ifdef PRIO_PGRP - if (PyModule_AddIntMacro(m, PRIO_PGRP)) return -1; + if (ins(d, "PRIO_PGRP", (long)PRIO_PGRP)) return -1; #endif #ifdef PRIO_USER - if (PyModule_AddIntMacro(m, PRIO_USER)) return -1; + if (ins(d, "PRIO_USER", (long)PRIO_USER)) return -1; #endif #ifdef O_CLOEXEC - if (PyModule_AddIntMacro(m, O_CLOEXEC)) return -1; + if (ins(d, "O_CLOEXEC", (long)O_CLOEXEC)) return -1; #endif #ifdef O_ACCMODE - if (PyModule_AddIntMacro(m, O_ACCMODE)) return -1; + if (ins(d, "O_ACCMODE", (long)O_ACCMODE)) return -1; #endif #ifdef SEEK_HOLE - if (PyModule_AddIntMacro(m, SEEK_HOLE)) return -1; + if (ins(d, "SEEK_HOLE", (long)SEEK_HOLE)) return -1; #endif #ifdef SEEK_DATA - if (PyModule_AddIntMacro(m, SEEK_DATA)) return -1; + if (ins(d, "SEEK_DATA", (long)SEEK_DATA)) return -1; #endif /* MS Windows */ #ifdef O_NOINHERIT /* Don't inherit in child processes. */ - if (PyModule_AddIntMacro(m, O_NOINHERIT)) return -1; + if (ins(d, "O_NOINHERIT", (long)O_NOINHERIT)) return -1; #endif #ifdef _O_SHORT_LIVED /* Optimize for short life (keep in memory). */ /* MS forgot to define this one with a non-underscore form too. */ - if (PyModule_AddIntConstant(m, "O_SHORT_LIVED", _O_SHORT_LIVED)) return -1; + if (ins(d, "O_SHORT_LIVED", (long)_O_SHORT_LIVED)) return -1; #endif #ifdef O_TEMPORARY /* Automatically delete when last handle is closed. */ - if (PyModule_AddIntMacro(m, O_TEMPORARY)) return -1; + if (ins(d, "O_TEMPORARY", (long)O_TEMPORARY)) return -1; #endif #ifdef O_RANDOM /* Optimize for random access. */ - if (PyModule_AddIntMacro(m, O_RANDOM)) return -1; + if (ins(d, "O_RANDOM", (long)O_RANDOM)) return -1; #endif #ifdef O_SEQUENTIAL /* Optimize for sequential access. */ - if (PyModule_AddIntMacro(m, O_SEQUENTIAL)) return -1; + if (ins(d, "O_SEQUENTIAL", (long)O_SEQUENTIAL)) return -1; #endif /* GNU extensions. */ #ifdef O_ASYNC /* Send a SIGIO signal whenever input or output becomes available on file descriptor */ - if (PyModule_AddIntMacro(m, O_ASYNC)) return -1; + if (ins(d, "O_ASYNC", (long)O_ASYNC)) return -1; #endif #ifdef O_DIRECT /* Direct disk access. */ - if (PyModule_AddIntMacro(m, O_DIRECT)) return -1; + if (ins(d, "O_DIRECT", (long)O_DIRECT)) return -1; #endif #ifdef O_DIRECTORY /* Must be a directory. */ - if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1; + if (ins(d, "O_DIRECTORY", (long)O_DIRECTORY)) return -1; #endif #ifdef O_NOFOLLOW /* Do not follow links. */ - if (PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1; + if (ins(d, "O_NOFOLLOW", (long)O_NOFOLLOW)) return -1; #endif #ifdef O_NOLINKS /* Fails if link count of the named file is greater than 1 */ - if (PyModule_AddIntMacro(m, O_NOLINKS)) return -1; + if (ins(d, "O_NOLINKS", (long)O_NOLINKS)) return -1; #endif #ifdef O_NOATIME /* Do not update the access time. */ - if (PyModule_AddIntMacro(m, O_NOATIME)) return -1; + if (ins(d, "O_NOATIME", (long)O_NOATIME)) return -1; #endif /* These come from sysexits.h */ #ifdef EX_OK - if (PyModule_AddIntMacro(m, EX_OK)) return -1; + if (ins(d, "EX_OK", (long)EX_OK)) return -1; #endif /* EX_OK */ #ifdef EX_USAGE - if (PyModule_AddIntMacro(m, EX_USAGE)) return -1; + if (ins(d, "EX_USAGE", (long)EX_USAGE)) return -1; #endif /* EX_USAGE */ #ifdef EX_DATAERR - if (PyModule_AddIntMacro(m, EX_DATAERR)) return -1; + if (ins(d, "EX_DATAERR", (long)EX_DATAERR)) return -1; #endif /* EX_DATAERR */ #ifdef EX_NOINPUT - if (PyModule_AddIntMacro(m, EX_NOINPUT)) return -1; + if (ins(d, "EX_NOINPUT", (long)EX_NOINPUT)) return -1; #endif /* EX_NOINPUT */ #ifdef EX_NOUSER - if (PyModule_AddIntMacro(m, EX_NOUSER)) return -1; + if (ins(d, "EX_NOUSER", (long)EX_NOUSER)) return -1; #endif /* EX_NOUSER */ #ifdef EX_NOHOST - if (PyModule_AddIntMacro(m, EX_NOHOST)) return -1; + if (ins(d, "EX_NOHOST", (long)EX_NOHOST)) return -1; #endif /* EX_NOHOST */ #ifdef EX_UNAVAILABLE - if (PyModule_AddIntMacro(m, EX_UNAVAILABLE)) return -1; + if (ins(d, "EX_UNAVAILABLE", (long)EX_UNAVAILABLE)) return -1; #endif /* EX_UNAVAILABLE */ #ifdef EX_SOFTWARE - if (PyModule_AddIntMacro(m, EX_SOFTWARE)) return -1; + if (ins(d, "EX_SOFTWARE", (long)EX_SOFTWARE)) return -1; #endif /* EX_SOFTWARE */ #ifdef EX_OSERR - if (PyModule_AddIntMacro(m, EX_OSERR)) return -1; + if (ins(d, "EX_OSERR", (long)EX_OSERR)) return -1; #endif /* EX_OSERR */ #ifdef EX_OSFILE - if (PyModule_AddIntMacro(m, EX_OSFILE)) return -1; + if (ins(d, "EX_OSFILE", (long)EX_OSFILE)) return -1; #endif /* EX_OSFILE */ #ifdef EX_CANTCREAT - if (PyModule_AddIntMacro(m, EX_CANTCREAT)) return -1; + if (ins(d, "EX_CANTCREAT", (long)EX_CANTCREAT)) return -1; #endif /* EX_CANTCREAT */ #ifdef EX_IOERR - if (PyModule_AddIntMacro(m, EX_IOERR)) return -1; + if (ins(d, "EX_IOERR", (long)EX_IOERR)) return -1; #endif /* EX_IOERR */ #ifdef EX_TEMPFAIL - if (PyModule_AddIntMacro(m, EX_TEMPFAIL)) return -1; + if (ins(d, "EX_TEMPFAIL", (long)EX_TEMPFAIL)) return -1; #endif /* EX_TEMPFAIL */ #ifdef EX_PROTOCOL - if (PyModule_AddIntMacro(m, EX_PROTOCOL)) return -1; + if (ins(d, "EX_PROTOCOL", (long)EX_PROTOCOL)) return -1; #endif /* EX_PROTOCOL */ #ifdef EX_NOPERM - if (PyModule_AddIntMacro(m, EX_NOPERM)) return -1; + if (ins(d, "EX_NOPERM", (long)EX_NOPERM)) return -1; #endif /* EX_NOPERM */ #ifdef EX_CONFIG - if (PyModule_AddIntMacro(m, EX_CONFIG)) return -1; + if (ins(d, "EX_CONFIG", (long)EX_CONFIG)) return -1; #endif /* EX_CONFIG */ #ifdef EX_NOTFOUND - if (PyModule_AddIntMacro(m, EX_NOTFOUND)) return -1; + if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1; #endif /* EX_NOTFOUND */ /* statvfs */ #ifdef ST_RDONLY - if (PyModule_AddIntMacro(m, ST_RDONLY)) return -1; + if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1; #endif /* ST_RDONLY */ #ifdef ST_NOSUID - if (PyModule_AddIntMacro(m, ST_NOSUID)) return -1; + if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1; #endif /* ST_NOSUID */ /* FreeBSD sendfile() constants */ #ifdef SF_NODISKIO - if (PyModule_AddIntMacro(m, SF_NODISKIO)) return -1; + if (ins(d, "SF_NODISKIO", (long)SF_NODISKIO)) return -1; #endif #ifdef SF_MNOWAIT - if (PyModule_AddIntMacro(m, SF_MNOWAIT)) return -1; + if (ins(d, "SF_MNOWAIT", (long)SF_MNOWAIT)) return -1; #endif #ifdef SF_SYNC - if (PyModule_AddIntMacro(m, SF_SYNC)) return -1; + if (ins(d, "SF_SYNC", (long)SF_SYNC)) return -1; #endif /* constants for posix_fadvise */ #ifdef POSIX_FADV_NORMAL - if (PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1; + if (ins(d, "POSIX_FADV_NORMAL", (long)POSIX_FADV_NORMAL)) return -1; #endif #ifdef POSIX_FADV_SEQUENTIAL - if (PyModule_AddIntMacro(m, POSIX_FADV_SEQUENTIAL)) return -1; + if (ins(d, "POSIX_FADV_SEQUENTIAL", (long)POSIX_FADV_SEQUENTIAL)) return -1; #endif #ifdef POSIX_FADV_RANDOM - if (PyModule_AddIntMacro(m, POSIX_FADV_RANDOM)) return -1; + if (ins(d, "POSIX_FADV_RANDOM", (long)POSIX_FADV_RANDOM)) return -1; #endif #ifdef POSIX_FADV_NOREUSE - if (PyModule_AddIntMacro(m, POSIX_FADV_NOREUSE)) return -1; + if (ins(d, "POSIX_FADV_NOREUSE", (long)POSIX_FADV_NOREUSE)) return -1; #endif #ifdef POSIX_FADV_WILLNEED - if (PyModule_AddIntMacro(m, POSIX_FADV_WILLNEED)) return -1; + if (ins(d, "POSIX_FADV_WILLNEED", (long)POSIX_FADV_WILLNEED)) return -1; #endif #ifdef POSIX_FADV_DONTNEED - if (PyModule_AddIntMacro(m, POSIX_FADV_DONTNEED)) return -1; + if (ins(d, "POSIX_FADV_DONTNEED", (long)POSIX_FADV_DONTNEED)) return -1; #endif /* constants for waitid */ #if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID) - if (PyModule_AddIntMacro(m, P_PID)) return -1; - if (PyModule_AddIntMacro(m, P_PGID)) return -1; - if (PyModule_AddIntMacro(m, P_ALL)) return -1; + if (ins(d, "P_PID", (long)P_PID)) return -1; + if (ins(d, "P_PGID", (long)P_PGID)) return -1; + if (ins(d, "P_ALL", (long)P_ALL)) return -1; #endif #ifdef WEXITED - if (PyModule_AddIntMacro(m, WEXITED)) return -1; + if (ins(d, "WEXITED", (long)WEXITED)) return -1; #endif #ifdef WNOWAIT - if (PyModule_AddIntMacro(m, WNOWAIT)) return -1; + if (ins(d, "WNOWAIT", (long)WNOWAIT)) return -1; #endif #ifdef WSTOPPED - if (PyModule_AddIntMacro(m, WSTOPPED)) return -1; + if (ins(d, "WSTOPPED", (long)WSTOPPED)) return -1; #endif #ifdef CLD_EXITED - if (PyModule_AddIntMacro(m, CLD_EXITED)) return -1; + if (ins(d, "CLD_EXITED", (long)CLD_EXITED)) return -1; #endif #ifdef CLD_DUMPED - if (PyModule_AddIntMacro(m, CLD_DUMPED)) return -1; + if (ins(d, "CLD_DUMPED", (long)CLD_DUMPED)) return -1; #endif #ifdef CLD_TRAPPED - if (PyModule_AddIntMacro(m, CLD_TRAPPED)) return -1; + if (ins(d, "CLD_TRAPPED", (long)CLD_TRAPPED)) return -1; #endif #ifdef CLD_CONTINUED - if (PyModule_AddIntMacro(m, CLD_CONTINUED)) return -1; + if (ins(d, "CLD_CONTINUED", (long)CLD_CONTINUED)) return -1; #endif /* constants for lockf */ #ifdef F_LOCK - if (PyModule_AddIntMacro(m, F_LOCK)) return -1; + if (ins(d, "F_LOCK", (long)F_LOCK)) return -1; #endif #ifdef F_TLOCK - if (PyModule_AddIntMacro(m, F_TLOCK)) return -1; + if (ins(d, "F_TLOCK", (long)F_TLOCK)) return -1; #endif #ifdef F_ULOCK - if (PyModule_AddIntMacro(m, F_ULOCK)) return -1; + if (ins(d, "F_ULOCK", (long)F_ULOCK)) return -1; #endif #ifdef F_TEST - if (PyModule_AddIntMacro(m, F_TEST)) return -1; + if (ins(d, "F_TEST", (long)F_TEST)) return -1; #endif #ifdef HAVE_SPAWNV - if (PyModule_AddIntConstant(m, "P_WAIT", _P_WAIT)) return -1; - if (PyModule_AddIntConstant(m, "P_NOWAIT", _P_NOWAIT)) return -1; - if (PyModule_AddIntConstant(m, "P_OVERLAY", _OLD_P_OVERLAY)) return -1; - if (PyModule_AddIntConstant(m, "P_NOWAITO", _P_NOWAITO)) return -1; - if (PyModule_AddIntConstant(m, "P_DETACH", _P_DETACH)) return -1; + if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1; + if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1; + if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1; + if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1; + if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1; #endif #ifdef HAVE_SCHED_H - if (PyModule_AddIntMacro(m, SCHED_OTHER)) return -1; - if (PyModule_AddIntMacro(m, SCHED_FIFO)) return -1; - if (PyModule_AddIntMacro(m, SCHED_RR)) return -1; + if (ins(d, "SCHED_OTHER", (long)SCHED_OTHER)) return -1; + if (ins(d, "SCHED_FIFO", (long)SCHED_FIFO)) return -1; + if (ins(d, "SCHED_RR", (long)SCHED_RR)) return -1; #ifdef SCHED_SPORADIC - if (PyModule_AddIntMacro(m, SCHED_SPORADIC) return -1; + if (ins(d, "SCHED_SPORADIC", (long)SCHED_SPORADIC) return -1; #endif #ifdef SCHED_BATCH - if (PyModule_AddIntMacro(m, SCHED_BATCH)) return -1; + if (ins(d, "SCHED_BATCH", (long)SCHED_BATCH)) return -1; #endif #ifdef SCHED_IDLE - if (PyModule_AddIntMacro(m, SCHED_IDLE)) return -1; + if (ins(d, "SCHED_IDLE", (long)SCHED_IDLE)) return -1; #endif #ifdef SCHED_RESET_ON_FORK - if (PyModule_AddIntMacro(m, SCHED_RESET_ON_FORK)) return -1; + if (ins(d, "SCHED_RESET_ON_FORK", (long)SCHED_RESET_ON_FORK)) return -1; #endif #ifdef SCHED_SYS - if (PyModule_AddIntMacro(m, SCHED_SYS)) return -1; + if (ins(d, "SCHED_SYS", (long)SCHED_SYS)) return -1; #endif #ifdef SCHED_IA - if (PyModule_AddIntMacro(m, SCHED_IA)) return -1; + if (ins(d, "SCHED_IA", (long)SCHED_IA)) return -1; #endif #ifdef SCHED_FSS - if (PyModule_AddIntMacro(m, SCHED_FSS)) return -1; + if (ins(d, "SCHED_FSS", (long)SCHED_FSS)) return -1; #endif #ifdef SCHED_FX - if (PyModule_AddIntConstant(m, "SCHED_FX", SCHED_FSS)) return -1; + if (ins(d, "SCHED_FX", (long)SCHED_FSS)) return -1; #endif #endif #ifdef USE_XATTRS - if (PyModule_AddIntMacro(m, XATTR_CREATE)) return -1; - if (PyModule_AddIntMacro(m, XATTR_REPLACE)) return -1; - if (PyModule_AddIntMacro(m, XATTR_SIZE_MAX)) return -1; + if (ins(d, "XATTR_CREATE", (long)XATTR_CREATE)) return -1; + if (ins(d, "XATTR_REPLACE", (long)XATTR_REPLACE)) return -1; + if (ins(d, "XATTR_SIZE_MAX", (long)XATTR_SIZE_MAX)) return -1; #endif #ifdef RTLD_LAZY - if (PyModule_AddIntMacro(m, RTLD_LAZY)) return -1; + if (PyModule_AddIntMacro(d, RTLD_LAZY)) return -1; #endif #ifdef RTLD_NOW - if (PyModule_AddIntMacro(m, RTLD_NOW)) return -1; + if (PyModule_AddIntMacro(d, RTLD_NOW)) return -1; #endif #ifdef RTLD_GLOBAL - if (PyModule_AddIntMacro(m, RTLD_GLOBAL)) return -1; + if (PyModule_AddIntMacro(d, RTLD_GLOBAL)) return -1; #endif #ifdef RTLD_LOCAL - if (PyModule_AddIntMacro(m, RTLD_LOCAL)) return -1; + if (PyModule_AddIntMacro(d, RTLD_LOCAL)) return -1; #endif #ifdef RTLD_NODELETE - if (PyModule_AddIntMacro(m, RTLD_NODELETE)) return -1; + if (PyModule_AddIntMacro(d, RTLD_NODELETE)) return -1; #endif #ifdef RTLD_NOLOAD - if (PyModule_AddIntMacro(m, RTLD_NOLOAD)) return -1; + if (PyModule_AddIntMacro(d, RTLD_NOLOAD)) return -1; #endif #ifdef RTLD_DEEPBIND - if (PyModule_AddIntMacro(m, RTLD_DEEPBIND)) return -1; + if (PyModule_AddIntMacro(d, RTLD_DEEPBIND)) return -1; #endif return 0; @@ -11518,23 +11556,19 @@ if (!initialized) { #if defined(HAVE_WAITID) && !defined(__APPLE__) waitid_result_desc.name = MODNAME ".waitid_result"; - if (PyStructSequence_InitType2(&WaitidResultType, &waitid_result_desc) < 0) - return NULL; + PyStructSequence_InitType(&WaitidResultType, &waitid_result_desc); #endif stat_result_desc.name = MODNAME ".stat_result"; stat_result_desc.fields[7].name = PyStructSequence_UnnamedField; stat_result_desc.fields[8].name = PyStructSequence_UnnamedField; stat_result_desc.fields[9].name = PyStructSequence_UnnamedField; - if (PyStructSequence_InitType2(&StatResultType, &stat_result_desc) < 0) - return NULL; + PyStructSequence_InitType(&StatResultType, &stat_result_desc); structseq_new = StatResultType.tp_new; StatResultType.tp_new = statresult_new; statvfs_result_desc.name = MODNAME ".statvfs_result"; - if (PyStructSequence_InitType2(&StatVFSResultType, - &statvfs_result_desc) < 0) - return NULL; + PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc); #ifdef NEED_TICKS_PER_SECOND # if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) ticks_per_second = sysconf(_SC_CLK_TCK); @@ -11547,15 +11581,12 @@ #if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) sched_param_desc.name = MODNAME ".sched_param"; - if (PyStructSequence_InitType2(&SchedParamType, &sched_param_desc) < 0) - return NULL; + PyStructSequence_InitType(&SchedParamType, &sched_param_desc); SchedParamType.tp_new = sched_param_new; #endif /* initialize TerminalSize_info */ - if (PyStructSequence_InitType2(&TerminalSizeType, - &TerminalSize_desc) < 0) - return NULL; + PyStructSequence_InitType(&TerminalSizeType, &TerminalSize_desc); } #if defined(HAVE_WAITID) && !defined(__APPLE__) Py_INCREF((PyObject*) &WaitidResultType); @@ -11573,13 +11604,11 @@ #endif times_result_desc.name = MODNAME ".times_result"; - if (PyStructSequence_InitType2(&TimesResultType, ×_result_desc) < 0) - return NULL; + PyStructSequence_InitType(&TimesResultType, ×_result_desc); PyModule_AddObject(m, "times_result", (PyObject *)&TimesResultType); uname_result_desc.name = MODNAME ".uname_result"; - if (PyStructSequence_InitType2(&UnameResultType, &uname_result_desc) < 0) - return NULL; + PyStructSequence_InitType(&UnameResultType, &uname_result_desc); PyModule_AddObject(m, "uname_result", (PyObject *)&UnameResultType); #ifdef __APPLE__ @@ -11657,6 +11686,7 @@ initialized = 1; return m; + } #ifdef __cplusplus diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/posixmodule.h --- a/Modules/posixmodule.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -/* Declarations shared between the different POSIX-related modules */ - -#ifndef Py_POSIXMODULE_H -#define Py_POSIXMODULE_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifndef Py_LIMITED_API -#ifndef MS_WINDOWS -PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t); -PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t); -PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, void *); -PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *); -#endif /* MS_WINDOWS */ -#endif - -#ifdef __cplusplus -} -#endif -#endif /* !Py_POSIXMODULE_H */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/pwdmodule.c --- a/Modules/pwdmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/pwdmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -2,8 +2,8 @@ /* UNIX password file access module */ #include "Python.h" -#include "posixmodule.h" +#include #include static PyStructSequence_Field struct_pwd_type_fields[] = { @@ -74,8 +74,8 @@ #else SETS(setIndex++, p->pw_passwd); #endif - PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid)); - PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid)); + SETI(setIndex++, p->pw_uid); + SETI(setIndex++, p->pw_gid); #ifdef __VMS SETS(setIndex++, ""); #else @@ -104,21 +104,13 @@ static PyObject * pwd_getpwuid(PyObject *self, PyObject *args) { - uid_t uid; + unsigned int uid; struct passwd *p; - if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) - PyErr_Format(PyExc_KeyError, - "getpwuid(): uid not found"); + if (!PyArg_ParseTuple(args, "I:getpwuid", &uid)) return NULL; - } if ((p = getpwuid(uid)) == NULL) { - PyObject *uid_obj = _PyLong_FromUid(uid); - if (uid_obj == NULL) - return NULL; PyErr_Format(PyExc_KeyError, - "getpwuid(): uid not found: %S", uid_obj); - Py_DECREF(uid_obj); + "getpwuid(): uid not found: %d", uid); return NULL; } return mkpwent(p); @@ -216,9 +208,8 @@ return NULL; if (!initialized) { - if (PyStructSequence_InitType2(&StructPwdType, - &struct_pwd_type_desc) < 0) - return NULL; + PyStructSequence_InitType(&StructPwdType, + &struct_pwd_type_desc); initialized = 1; } Py_INCREF((PyObject *) &StructPwdType); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/pyexpat.c --- a/Modules/pyexpat.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/pyexpat.c Fri Feb 01 23:12:09 2013 +0100 @@ -10,9 +10,6 @@ #define FIX_TRACE -static XML_Memory_Handling_Suite ExpatMemoryHandler = { - PyObject_Malloc, PyObject_Realloc, PyObject_Free}; - enum HandlerTypes { StartElement, EndElement, @@ -286,17 +283,12 @@ { PyThreadState *tstate = PyThreadState_GET(); PyFrameObject *f; - PyObject *res, *globals; + PyObject *res; if (c == NULL) return NULL; - globals = PyEval_GetGlobals(); - if (globals == NULL) { - return NULL; - } - - f = PyFrame_New(tstate, c, globals, NULL); + f = PyFrame_New(tstate, c, PyEval_GetGlobals(), NULL); if (f == NULL) return NULL; tstate->frame = f; @@ -407,10 +399,6 @@ my_CharacterDataHandler(void *userData, const XML_Char *data, int len) { xmlparseobject *self = (xmlparseobject *) userData; - - if (PyErr_Occurred()) - return; - if (self->buffer == NULL) call_character_handler(self, data, len); else { @@ -445,9 +433,6 @@ PyObject *container, *rv, *args; int i, max; - if (PyErr_Occurred()) - return; - if (flush_character_buffer(self) < 0) return; /* Set max to the number of slots filled in atts[]; max/2 is @@ -531,8 +516,6 @@ INIT \ \ if (have_handler(self, NAME)) { \ - if (PyErr_Occurred()) \ - return RETURN; \ if (flush_character_buffer(self) < 0) \ return RETURN; \ args = Py_BuildValue PARAM_FORMAT ;\ @@ -647,9 +630,6 @@ PyObject *rv = NULL; PyObject *modelobj, *nameobj; - if (PyErr_Occurred()) - return; - if (flush_character_buffer(self) < 0) goto finally; modelobj = conv_content_model(model, (conv_string_to_unicode)); @@ -798,49 +778,17 @@ "Parse(data[, isfinal])\n\ Parse XML data. `isfinal' should be true at end of input."); -#define MAX_CHUNK_SIZE (1 << 20) - static PyObject * xmlparse_Parse(xmlparseobject *self, PyObject *args) { - PyObject *data; + char *s; + int slen; int isFinal = 0; - const char *s; - Py_ssize_t slen; - Py_buffer view; - int rc; - if (!PyArg_ParseTuple(args, "O|i:Parse", &data, &isFinal)) + if (!PyArg_ParseTuple(args, "s#|i:Parse", &s, &slen, &isFinal)) return NULL; - if (PyUnicode_Check(data)) { - view.buf = NULL; - s = PyUnicode_AsUTF8AndSize(data, &slen); - if (s == NULL) - return NULL; - /* Explicitly set UTF-8 encoding. Return code ignored. */ - (void)XML_SetEncoding(self->itself, "utf-8"); - } - else { - if (PyObject_GetBuffer(data, &view, PyBUF_SIMPLE) < 0) - return NULL; - s = view.buf; - slen = view.len; - } - - while (slen > MAX_CHUNK_SIZE) { - rc = XML_Parse(self->itself, s, MAX_CHUNK_SIZE, 0); - if (!rc) - goto done; - s += MAX_CHUNK_SIZE; - slen -= MAX_CHUNK_SIZE; - } - rc = XML_Parse(self->itself, s, slen, isFinal); - -done: - if (view.buf != NULL) - PyBuffer_Release(&view); - return get_parse_result(self, rc); + return get_parse_result(self, XML_Parse(self->itself, s, slen, isFinal)); } /* File reading copied from cPickle */ @@ -1017,7 +965,7 @@ PyObject_GC_Track(new_parser); if (self->buffer != NULL) { - new_parser->buffer = PyMem_Malloc(new_parser->buffer_size); + new_parser->buffer = malloc(new_parser->buffer_size); if (new_parser->buffer == NULL) { Py_DECREF(new_parser); return PyErr_NoMemory(); @@ -1034,7 +982,7 @@ for (i = 0; handler_info[i].name != NULL; i++) /* do nothing */; - new_parser->handlers = PyMem_Malloc(sizeof(PyObject *) * i); + new_parser->handlers = malloc(sizeof(PyObject *) * i); if (!new_parser->handlers) { Py_DECREF(new_parser); return PyErr_NoMemory(); @@ -1131,54 +1079,53 @@ Make it as simple as possible. */ +static char template_buffer[257]; + +static void +init_template_buffer(void) +{ + int i; + for (i = 0; i < 256; i++) { + template_buffer[i] = i; + } + template_buffer[256] = 0; +} + static int PyUnknownEncodingHandler(void *encodingHandlerData, const XML_Char *name, XML_Encoding *info) { - static unsigned char template_buffer[256] = {0}; - PyObject* u; + PyUnicodeObject *_u_string = NULL; + int result = 0; int i; + int kind; void *data; - unsigned int kind; - if (PyErr_Occurred()) - return XML_STATUS_ERROR; + /* Yes, supports only 8bit encodings */ + _u_string = (PyUnicodeObject *) + PyUnicode_Decode(template_buffer, 256, name, "replace"); - if (template_buffer[1] == 0) { - for (i = 0; i < 256; i++) - template_buffer[i] = i; + if (_u_string == NULL || PyUnicode_READY(_u_string) == -1) + return result; + + kind = PyUnicode_KIND(_u_string); + data = PyUnicode_DATA(_u_string); + + for (i = 0; i < 256; i++) { + /* Stupid to access directly, but fast */ + Py_UCS4 c = PyUnicode_READ(kind, data, i); + if (c == Py_UNICODE_REPLACEMENT_CHARACTER) + info->map[i] = -1; + else + info->map[i] = c; } - - u = PyUnicode_Decode((char*) template_buffer, 256, name, "replace"); - if (u == NULL || PyUnicode_READY(u)) { - Py_XDECREF(u); - return XML_STATUS_ERROR; - } - - if (PyUnicode_GET_LENGTH(u) != 256) { - Py_DECREF(u); - PyErr_SetString(PyExc_ValueError, - "multi-byte encodings are not supported"); - return XML_STATUS_ERROR; - } - - kind = PyUnicode_KIND(u); - data = PyUnicode_DATA(u); - for (i = 0; i < 256; i++) { - Py_UCS4 ch = PyUnicode_READ(kind, data, i); - if (ch != Py_UNICODE_REPLACEMENT_CHARACTER) - info->map[i] = ch; - else - info->map[i] = -1; - } - info->data = NULL; info->convert = NULL; info->release = NULL; - Py_DECREF(u); - - return XML_STATUS_OK; + result = 1; + Py_DECREF(_u_string); + return result; } @@ -1200,18 +1147,11 @@ self->in_callback = 0; self->ns_prefixes = 0; self->handlers = NULL; - self->intern = intern; - Py_XINCREF(self->intern); - PyObject_GC_Track(self); - - /* namespace_separator is either NULL or contains one char + \0 */ - self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler, - namespace_separator); - if (self->itself == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "XML_ParserCreate failed"); - Py_DECREF(self); - return NULL; + if (namespace_separator != NULL) { + self->itself = XML_ParserCreateNS(encoding, *namespace_separator); + } + else { + self->itself = XML_ParserCreate(encoding); } #if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT) /* This feature was added upstream in libexpat 2.1.0. Our expat copy @@ -1220,6 +1160,15 @@ XML_SetHashSalt(self->itself, (unsigned long)_Py_HashSecret.prefix); #endif + self->intern = intern; + Py_XINCREF(self->intern); + PyObject_GC_Track(self); + if (self->itself == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "XML_ParserCreate failed"); + Py_DECREF(self); + return NULL; + } XML_SetUserData(self->itself, (void *)self); XML_SetUnknownEncodingHandler(self->itself, (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL); @@ -1227,7 +1176,7 @@ for (i = 0; handler_info[i].name != NULL; i++) /* do nothing */; - self->handlers = PyMem_Malloc(sizeof(PyObject *) * i); + self->handlers = malloc(sizeof(PyObject *) * i); if (!self->handlers) { Py_DECREF(self); return PyErr_NoMemory(); @@ -1254,11 +1203,11 @@ self->handlers[i] = NULL; Py_XDECREF(temp); } - PyMem_Free(self->handlers); + free(self->handlers); self->handlers = NULL; } if (self->buffer != NULL) { - PyMem_Free(self->buffer); + free(self->buffer); self->buffer = NULL; } Py_XDECREF(self->intern); @@ -1458,7 +1407,7 @@ return -1; if (b) { if (self->buffer == NULL) { - self->buffer = PyMem_Malloc(self->buffer_size); + self->buffer = malloc(self->buffer_size); if (self->buffer == NULL) { PyErr_NoMemory(); return -1; @@ -1469,7 +1418,7 @@ else if (self->buffer != NULL) { if (flush_character_buffer(self) < 0) return -1; - PyMem_Free(self->buffer); + free(self->buffer); self->buffer = NULL; } return 0; @@ -1526,14 +1475,12 @@ if (self->buffer != NULL) { /* there is already a buffer */ if (self->buffer_used != 0) { - if (flush_character_buffer(self) < 0) { - return -1; - } + flush_character_buffer(self); } /* free existing buffer */ - PyMem_Free(self->buffer); + free(self->buffer); } - self->buffer = PyMem_Malloc(new_buffer_size); + self->buffer = malloc(new_buffer_size); if (self->buffer == NULL) { PyErr_NoMemory(); return -1; @@ -1773,6 +1720,7 @@ Py_BuildValue("(iii)", info.major, info.minor, info.micro)); } + init_template_buffer(); /* XXX When Expat supports some way of figuring out how it was compiled, this should check and set native_encoding appropriately. @@ -1957,8 +1905,6 @@ capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler; capi.SetUserData = XML_SetUserData; capi.SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler; - capi.SetEncoding = XML_SetEncoding; - capi.DefaultUnknownEncodingHandler = PyUnknownEncodingHandler; /* export using capsule */ capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/python.c --- a/Modules/python.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/python.c Fri Feb 01 23:12:09 2013 +0100 @@ -18,43 +18,32 @@ int main(int argc, char **argv) { - wchar_t **argv_copy; - /* We need a second copy, as Python might modify the first one. */ - wchar_t **argv_copy2; + wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); + /* We need a second copies, as Python might modify the first one. */ + wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); int i, res; char *oldloc; -#ifdef __FreeBSD__ - fp_except_t m; -#endif - - argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); - argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); - if (!argv_copy || !argv_copy2) { - fprintf(stderr, "out of memory\n"); - return 1; - } - /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ + fp_except_t m; + m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif - - oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); - if (!oldloc) { + if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } - + oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy[i] = _Py_char2wchar(argv[i], NULL); if (!argv_copy[i]) { - PyMem_RawFree(oldloc); + free(oldloc); fprintf(stderr, "Fatal Python error: " "unable to decode the command line argument #%i\n", i + 1); @@ -65,13 +54,13 @@ argv_copy2[argc] = argv_copy[argc] = NULL; setlocale(LC_ALL, oldloc); - PyMem_RawFree(oldloc); + free(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { - PyMem_RawFree(argv_copy2[i]); + PyMem_Free(argv_copy2[i]); } - PyMem_RawFree(argv_copy); - PyMem_RawFree(argv_copy2); + PyMem_Free(argv_copy); + PyMem_Free(argv_copy2); return res; } #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/readline.c --- a/Modules/readline.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/readline.c Fri Feb 01 23:12:09 2013 +0100 @@ -70,10 +70,6 @@ int num_matches, int max_length); #endif -/* Memory allocated for rl_completer_word_break_characters - (see issue #17289 for the motivation). */ -static char *completer_word_break_characters; - /* Exported function to send one line to readline's init file parser */ static PyObject * @@ -84,12 +80,12 @@ return NULL; /* Make a copy -- rl_parse_and_bind() modifies its argument */ /* Bernard Herzog */ - copy = PyMem_Malloc(1 + strlen(s)); + copy = malloc(1 + strlen(s)); if (copy == NULL) return PyErr_NoMemory(); strcpy(copy, s); rl_parse_and_bind(copy); - PyMem_Free(copy); /* Free the copy */ + free(copy); /* Free the copy */ Py_RETURN_NONE; } @@ -372,20 +368,12 @@ { char *break_chars; - if (!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) { + if(!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) { return NULL; } - /* Keep a reference to the allocated memory in the module state in case - some other module modifies rl_completer_word_break_characters - (see issue #17289). */ - free(completer_word_break_characters); - completer_word_break_characters = strdup(break_chars); - if (completer_word_break_characters) { - rl_completer_word_break_characters = completer_word_break_characters; - Py_RETURN_NONE; - } - else - return PyErr_NoMemory(); + free((void*)rl_completer_word_break_characters); + rl_completer_word_break_characters = strdup(break_chars); + Py_RETURN_NONE; } PyDoc_STRVAR(doc_set_completer_delims, @@ -926,8 +914,7 @@ /* Set our completion function */ rl_attempted_completion_function = (CPPFunction *)flex_complete; /* Set Python word break characters */ - completer_word_break_characters = - rl_completer_word_break_characters = + rl_completer_word_break_characters = strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); /* All nonalphanums except '.' */ @@ -1183,6 +1170,8 @@ if (m == NULL) return NULL; + + PyOS_ReadlineFunctionPointer = call_readline; setup_readline(); return m; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/resource.c --- a/Modules/resource.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/resource.c Fri Feb 01 23:12:09 2013 +0100 @@ -142,9 +142,10 @@ { struct rlimit rl; int resource; - PyObject *limits, *curobj, *maxobj; + PyObject *curobj, *maxobj; - if (!PyArg_ParseTuple(args, "iO:setrlimit", &resource, &limits)) + if (!PyArg_ParseTuple(args, "i(OO):setrlimit", + &resource, &curobj, &maxobj)) return NULL; if (resource < 0 || resource >= RLIM_NLIMITS) { @@ -153,34 +154,21 @@ return NULL; } - limits = PySequence_Tuple(limits); - if (!limits) - /* Here limits is a borrowed reference */ - return NULL; - - if (PyTuple_GET_SIZE(limits) != 2) { - PyErr_SetString(PyExc_ValueError, - "expected a tuple of 2 integers"); - goto error; - } - curobj = PyTuple_GET_ITEM(limits, 0); - maxobj = PyTuple_GET_ITEM(limits, 1); - #if !defined(HAVE_LARGEFILE_SUPPORT) rl.rlim_cur = PyLong_AsLong(curobj); if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred()) - goto error; + return NULL; rl.rlim_max = PyLong_AsLong(maxobj); if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred()) - goto error; + return NULL; #else /* The limits are probably bigger than a long */ rl.rlim_cur = PyLong_AsLongLong(curobj); if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred()) - goto error; + return NULL; rl.rlim_max = PyLong_AsLongLong(maxobj); if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred()) - goto error; + return NULL; #endif rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY; @@ -194,15 +182,10 @@ "not allowed to raise maximum limit"); else PyErr_SetFromErrno(PyExc_OSError); - goto error; + return NULL; } - Py_DECREF(limits); Py_INCREF(Py_None); return Py_None; - - error: - Py_DECREF(limits); - return NULL; } static PyObject * @@ -263,83 +246,80 @@ /* Add some symbolic constants to the module */ Py_INCREF(PyExc_OSError); PyModule_AddObject(m, "error", PyExc_OSError); - if (!initialized) { - if (PyStructSequence_InitType2(&StructRUsageType, - &struct_rusage_desc) < 0) - return NULL; - } - + if (!initialized) + PyStructSequence_InitType(&StructRUsageType, + &struct_rusage_desc); Py_INCREF(&StructRUsageType); PyModule_AddObject(m, "struct_rusage", (PyObject*) &StructRUsageType); /* insert constants */ #ifdef RLIMIT_CPU - PyModule_AddIntMacro(m, RLIMIT_CPU); + PyModule_AddIntConstant(m, "RLIMIT_CPU", RLIMIT_CPU); #endif #ifdef RLIMIT_FSIZE - PyModule_AddIntMacro(m, RLIMIT_FSIZE); + PyModule_AddIntConstant(m, "RLIMIT_FSIZE", RLIMIT_FSIZE); #endif #ifdef RLIMIT_DATA - PyModule_AddIntMacro(m, RLIMIT_DATA); + PyModule_AddIntConstant(m, "RLIMIT_DATA", RLIMIT_DATA); #endif #ifdef RLIMIT_STACK - PyModule_AddIntMacro(m, RLIMIT_STACK); + PyModule_AddIntConstant(m, "RLIMIT_STACK", RLIMIT_STACK); #endif #ifdef RLIMIT_CORE - PyModule_AddIntMacro(m, RLIMIT_CORE); + PyModule_AddIntConstant(m, "RLIMIT_CORE", RLIMIT_CORE); #endif #ifdef RLIMIT_NOFILE - PyModule_AddIntMacro(m, RLIMIT_NOFILE); + PyModule_AddIntConstant(m, "RLIMIT_NOFILE", RLIMIT_NOFILE); #endif #ifdef RLIMIT_OFILE - PyModule_AddIntMacro(m, RLIMIT_OFILE); + PyModule_AddIntConstant(m, "RLIMIT_OFILE", RLIMIT_OFILE); #endif #ifdef RLIMIT_VMEM - PyModule_AddIntMacro(m, RLIMIT_VMEM); + PyModule_AddIntConstant(m, "RLIMIT_VMEM", RLIMIT_VMEM); #endif #ifdef RLIMIT_AS - PyModule_AddIntMacro(m, RLIMIT_AS); + PyModule_AddIntConstant(m, "RLIMIT_AS", RLIMIT_AS); #endif #ifdef RLIMIT_RSS - PyModule_AddIntMacro(m, RLIMIT_RSS); + PyModule_AddIntConstant(m, "RLIMIT_RSS", RLIMIT_RSS); #endif #ifdef RLIMIT_NPROC - PyModule_AddIntMacro(m, RLIMIT_NPROC); + PyModule_AddIntConstant(m, "RLIMIT_NPROC", RLIMIT_NPROC); #endif #ifdef RLIMIT_MEMLOCK - PyModule_AddIntMacro(m, RLIMIT_MEMLOCK); + PyModule_AddIntConstant(m, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK); #endif #ifdef RLIMIT_SBSIZE - PyModule_AddIntMacro(m, RLIMIT_SBSIZE); + PyModule_AddIntConstant(m, "RLIMIT_SBSIZE", RLIMIT_SBSIZE); #endif #ifdef RUSAGE_SELF - PyModule_AddIntMacro(m, RUSAGE_SELF); + PyModule_AddIntConstant(m, "RUSAGE_SELF", RUSAGE_SELF); #endif #ifdef RUSAGE_CHILDREN - PyModule_AddIntMacro(m, RUSAGE_CHILDREN); + PyModule_AddIntConstant(m, "RUSAGE_CHILDREN", RUSAGE_CHILDREN); #endif #ifdef RUSAGE_BOTH - PyModule_AddIntMacro(m, RUSAGE_BOTH); + PyModule_AddIntConstant(m, "RUSAGE_BOTH", RUSAGE_BOTH); #endif #ifdef RUSAGE_THREAD - PyModule_AddIntMacro(m, RUSAGE_THREAD); + PyModule_AddIntConstant(m, "RUSAGE_THREAD", RUSAGE_THREAD); #endif #if defined(HAVE_LONG_LONG) diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/selectmodule.c --- a/Modules/selectmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/selectmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -299,9 +299,9 @@ else ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist); - Py_XDECREF(ifdlist); - Py_XDECREF(ofdlist); - Py_XDECREF(efdlist); + Py_DECREF(ifdlist); + Py_DECREF(ofdlist); + Py_DECREF(efdlist); } finally: @@ -882,6 +882,17 @@ return NULL; } +static PyObject* +devpoll_fileno(devpollObject *self) +{ + return PyLong_FromLong(self->fd_devpoll); +} + +PyDoc_STRVAR(devpoll_fileno_doc, +"fileno() -> int\n\ +\n\ +Return the file descriptor."); + static PyMethodDef devpoll_methods[] = { {"register", (PyCFunction)devpoll_register, METH_VARARGS, devpoll_register_doc}, @@ -891,11 +902,13 @@ METH_O, devpoll_unregister_doc}, {"poll", (PyCFunction)devpoll_poll, METH_VARARGS, devpoll_poll_doc}, + {"fileno", (PyCFunction)devpoll_fileno, METH_NOARGS, + devpoll_fileno_doc}, {NULL, NULL} /* sentinel */ }; static devpollObject * -newDevPollObject(void) +newDevPollObject(int cloexec) { devpollObject *self; int fd_devpoll, limit_result; @@ -923,6 +936,11 @@ return NULL; } + if (cloexec && _Py_set_cloexec(fd_devpoll, 1, NULL) < 0) { + close(fd_devpoll); + return NULL; + } + fds = PyMem_NEW(struct pollfd, limit.rlim_cur); if (fds == NULL) { close(fd_devpoll); @@ -1005,13 +1023,24 @@ #ifdef HAVE_SYS_DEVPOLL_H PyDoc_STRVAR(devpoll_doc, -"Returns a polling object, which supports registering and\n\ -unregistering file descriptors, and then polling them for I/O events."); +"devpoll(cloexec=None)\n\ +\n\ +Returns a polling object, which supports registering and\n\ +unregistering file descriptors, and then polling them for I/O events.\n\ +\n\ +If cloexec is True, set the close-on-exec flag."); static PyObject * -select_devpoll(PyObject *self, PyObject *unused) +select_devpoll(PyObject *self, PyObject *args, PyObject *kwds) { - return (PyObject *)newDevPollObject(); + static char *kwlist[] = {"cloexec", NULL}; + int cloexec = Py_DefaultCloexec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&:devpoll", kwlist, + _Py_cloexec_converter, &cloexec)) + return NULL; + + return (PyObject *)newDevPollObject(cloexec); } #endif @@ -1091,7 +1120,8 @@ } static PyObject * -newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd) +newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd, + int cloexec) { pyEpoll_Object *self; @@ -1103,6 +1133,8 @@ if (fd == -1) { Py_BEGIN_ALLOW_THREADS #ifdef HAVE_EPOLL_CREATE1 + if (cloexec) + flags |= EPOLL_CLOEXEC; if (flags) self->epfd = epoll_create1(flags); else @@ -1118,6 +1150,14 @@ PyErr_SetFromErrno(PyExc_OSError); return NULL; } + +#ifndef HAVE_EPOLL_CREATE1 + if (cloexec && _Py_set_cloexec(self->epfd, 1, NULL) < 0) { + Py_DECREF(self); + return NULL; + } +#endif + return (PyObject *)self; } @@ -1126,17 +1166,19 @@ pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { int flags = 0, sizehint = FD_SETSIZE - 1; - static char *kwlist[] = {"sizehint", "flags", NULL}; + static char *kwlist[] = {"sizehint", "flags", "cloexec", NULL}; + int cloexec = Py_DefaultCloexec; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii:epoll", kwlist, - &sizehint, &flags)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiO&:epoll", kwlist, + &sizehint, &flags, + _Py_cloexec_converter, &cloexec)) return NULL; if (sizehint < 0) { PyErr_SetString(PyExc_ValueError, "negative sizehint"); return NULL; } - return newPyEpoll_Object(type, sizehint, flags, -1); + return newPyEpoll_Object(type, sizehint, flags, -1, cloexec); } @@ -1194,7 +1236,7 @@ if (!PyArg_ParseTuple(args, "i:fromfd", &fd)) return NULL; - return newPyEpoll_Object((PyTypeObject*)cls, FD_SETSIZE - 1, 0, fd); + return newPyEpoll_Object((PyTypeObject*)cls, FD_SETSIZE - 1, 0, fd, 0); } PyDoc_STRVAR(pyepoll_fromfd_doc, @@ -1445,13 +1487,15 @@ }; PyDoc_STRVAR(pyepoll_doc, -"select.epoll(sizehint=-1, flags=0)\n\ +"select.epoll(sizehint=-1, flags=0, cloexec=None)\n\ \n\ Returns an epolling object\n\ \n\ sizehint must be a positive integer or -1 for the default size. The\n\ sizehint is used to optimize internal data structures. It doesn't limit\n\ -the maximum number of monitored events."); +the maximum number of monitored events.\n\ +\n\ +If cloexec is True, set the close-on-exec flag."); static PyTypeObject pyEpoll_Type = { PyVarObject_HEAD_INIT(NULL, 0) @@ -1588,23 +1632,6 @@ # error uintptr_t does not match int, long, or long long! #endif -/* - * kevent is not standard and its members vary across BSDs. - */ -#if !defined(__OpenBSD__) -# define IDENT_TYPE T_UINTPTRT -# define IDENT_CAST Py_intptr_t -# define DATA_TYPE T_INTPTRT -# define DATA_FMT_UNIT INTPTRT_FMT_UNIT -# define IDENT_AsType PyLong_AsUintptr_t -#else -# define IDENT_TYPE T_UINT -# define IDENT_CAST int -# define DATA_TYPE T_INT -# define DATA_FMT_UNIT "i" -# define IDENT_AsType PyLong_AsUnsignedLong -#endif - /* Unfortunately, we can't store python objects in udata, because * kevents in the kernel can be removed without warning, which would * forever lose the refcount on the object stored with it. @@ -1612,11 +1639,11 @@ #define KQ_OFF(x) offsetof(kqueue_event_Object, x) static struct PyMemberDef kqueue_event_members[] = { - {"ident", IDENT_TYPE, KQ_OFF(e.ident)}, + {"ident", T_UINTPTRT, KQ_OFF(e.ident)}, {"filter", T_SHORT, KQ_OFF(e.filter)}, {"flags", T_USHORT, KQ_OFF(e.flags)}, {"fflags", T_UINT, KQ_OFF(e.fflags)}, - {"data", DATA_TYPE, KQ_OFF(e.data)}, + {"data", T_INTPTRT, KQ_OFF(e.data)}, {"udata", T_UINTPTRT, KQ_OFF(e.udata)}, {NULL} /* Sentinel */ }; @@ -1642,7 +1669,7 @@ PyObject *pfd; static char *kwlist[] = {"ident", "filter", "flags", "fflags", "data", "udata", NULL}; - static char *fmt = "O|hhi" DATA_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent"; + static char *fmt = "O|hhi" INTPTRT_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent"; EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0); /* defaults */ @@ -1652,12 +1679,8 @@ return -1; } - if (PyLong_Check(pfd) -#if IDENT_TYPE == T_UINT - && PyLong_AsUnsignedLong(pfd) <= UINT_MAX -#endif - ) { - self->e.ident = IDENT_AsType(pfd); + if (PyLong_Check(pfd)) { + self->e.ident = PyLong_AsUintptr_t(pfd); } else { self->e.ident = PyObject_AsFileDescriptor(pfd); @@ -1685,10 +1708,10 @@ Py_TYPE(s)->tp_name, Py_TYPE(o)->tp_name); return NULL; } - if (((result = (IDENT_CAST)(s->e.ident - o->e.ident)) == 0) && + if (((result = s->e.ident - o->e.ident) == 0) && ((result = s->e.filter - o->e.filter) == 0) && ((result = s->e.flags - o->e.flags) == 0) && - ((result = (int)(s->e.fflags - o->e.fflags)) == 0) && + ((result = s->e.fflags - o->e.fflags) == 0) && ((result = s->e.data - o->e.data) == 0) && ((result = s->e.udata - o->e.udata) == 0) ) { @@ -1783,7 +1806,7 @@ } static PyObject * -newKqueue_Object(PyTypeObject *type, SOCKET fd) +newKqueue_Object(PyTypeObject *type, SOCKET fd, int cloexec) { kqueue_queue_Object *self; assert(type != NULL && type->tp_alloc != NULL); @@ -1805,21 +1828,27 @@ PyErr_SetFromErrno(PyExc_OSError); return NULL; } + + if (fd == -1 && cloexec) { + if (_Py_set_cloexec(self->kqfd, 1, NULL) < 0) { + Py_DECREF(self); + return NULL; + } + } return (PyObject *)self; } static PyObject * kqueue_queue_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"cloexec", NULL}; + int cloexec = Py_DefaultCloexec; - if ((args != NULL && PyObject_Size(args)) || - (kwds != NULL && PyObject_Size(kwds))) { - PyErr_SetString(PyExc_ValueError, - "select.kqueue doesn't accept arguments"); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&:kqueue", kwlist, + _Py_cloexec_converter, &cloexec)) return NULL; - } - return newKqueue_Object(type, -1); + return newKqueue_Object(type, -1, cloexec); } static void @@ -1876,7 +1905,7 @@ if (!PyArg_ParseTuple(args, "i:fromfd", &fd)) return NULL; - return newKqueue_Object((PyTypeObject*)cls, fd); + return newKqueue_Object((PyTypeObject*)cls, fd, 0); } PyDoc_STRVAR(kqueue_queue_fromfd_doc, @@ -2046,7 +2075,7 @@ }; PyDoc_STRVAR(kqueue_queue_doc, -"Kqueue syscall wrapper.\n\ +"kqueue(cloexec=None): Kqueue syscall wrapper.\n\ \n\ For example, to start watching a socket for input:\n\ >>> kq = kqueue()\n\ @@ -2058,7 +2087,9 @@ >>> kq.control(None, 1, 1000)\n\ \n\ To stop listening:\n\ ->>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"); +>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)\n\ +\n\ +If cloexec is True, set the close-on-exec flag."); static PyTypeObject kqueue_queue_Type = { PyVarObject_HEAD_INIT(NULL, 0) @@ -2136,11 +2167,12 @@ static PyMethodDef select_methods[] = { {"select", select_select, METH_VARARGS, select_doc}, -#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL) +#ifdef HAVE_POLL {"poll", select_poll, METH_NOARGS, poll_doc}, #endif /* HAVE_POLL */ #ifdef HAVE_SYS_DEVPOLL_H - {"devpoll", select_devpoll, METH_NOARGS, devpoll_doc}, + {"devpoll", (PyCFunction)select_devpoll, + METH_VARARGS | METH_KEYWORDS, devpoll_doc}, #endif {0, 0}, /* sentinel */ }; @@ -2183,10 +2215,10 @@ #undef PIPE_BUF #define PIPE_BUF 512 #endif - PyModule_AddIntMacro(m, PIPE_BUF); + PyModule_AddIntConstant(m, "PIPE_BUF", PIPE_BUF); #endif -#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL) +#if defined(HAVE_POLL) #ifdef __APPLE__ if (select_have_broken_poll()) { if (PyObject_DelAttrString(m, "poll") == -1) { @@ -2198,27 +2230,27 @@ #endif if (PyType_Ready(&poll_Type) < 0) return NULL; - PyModule_AddIntMacro(m, POLLIN); - PyModule_AddIntMacro(m, POLLPRI); - PyModule_AddIntMacro(m, POLLOUT); - PyModule_AddIntMacro(m, POLLERR); - PyModule_AddIntMacro(m, POLLHUP); - PyModule_AddIntMacro(m, POLLNVAL); + PyModule_AddIntConstant(m, "POLLIN", POLLIN); + PyModule_AddIntConstant(m, "POLLPRI", POLLPRI); + PyModule_AddIntConstant(m, "POLLOUT", POLLOUT); + PyModule_AddIntConstant(m, "POLLERR", POLLERR); + PyModule_AddIntConstant(m, "POLLHUP", POLLHUP); + PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL); #ifdef POLLRDNORM - PyModule_AddIntMacro(m, POLLRDNORM); + PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM); #endif #ifdef POLLRDBAND - PyModule_AddIntMacro(m, POLLRDBAND); + PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND); #endif #ifdef POLLWRNORM - PyModule_AddIntMacro(m, POLLWRNORM); + PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM); #endif #ifdef POLLWRBAND - PyModule_AddIntMacro(m, POLLWRBAND); + PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND); #endif #ifdef POLLMSG - PyModule_AddIntMacro(m, POLLMSG); + PyModule_AddIntConstant(m, "POLLMSG", POLLMSG); #endif } #endif /* HAVE_POLL */ @@ -2236,25 +2268,25 @@ Py_INCREF(&pyEpoll_Type); PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type); - PyModule_AddIntMacro(m, EPOLLIN); - PyModule_AddIntMacro(m, EPOLLOUT); - PyModule_AddIntMacro(m, EPOLLPRI); - PyModule_AddIntMacro(m, EPOLLERR); - PyModule_AddIntMacro(m, EPOLLHUP); - PyModule_AddIntMacro(m, EPOLLET); + PyModule_AddIntConstant(m, "EPOLLIN", EPOLLIN); + PyModule_AddIntConstant(m, "EPOLLOUT", EPOLLOUT); + PyModule_AddIntConstant(m, "EPOLLPRI", EPOLLPRI); + PyModule_AddIntConstant(m, "EPOLLERR", EPOLLERR); + PyModule_AddIntConstant(m, "EPOLLHUP", EPOLLHUP); + PyModule_AddIntConstant(m, "EPOLLET", EPOLLET); #ifdef EPOLLONESHOT /* Kernel 2.6.2+ */ - PyModule_AddIntMacro(m, EPOLLONESHOT); + PyModule_AddIntConstant(m, "EPOLLONESHOT", EPOLLONESHOT); #endif /* PyModule_AddIntConstant(m, "EPOLL_RDHUP", EPOLLRDHUP); */ - PyModule_AddIntMacro(m, EPOLLRDNORM); - PyModule_AddIntMacro(m, EPOLLRDBAND); - PyModule_AddIntMacro(m, EPOLLWRNORM); - PyModule_AddIntMacro(m, EPOLLWRBAND); - PyModule_AddIntMacro(m, EPOLLMSG); + PyModule_AddIntConstant(m, "EPOLLRDNORM", EPOLLRDNORM); + PyModule_AddIntConstant(m, "EPOLLRDBAND", EPOLLRDBAND); + PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM); + PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND); + PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG); #ifdef EPOLL_CLOEXEC - PyModule_AddIntMacro(m, EPOLL_CLOEXEC); + PyModule_AddIntConstant(m, "EPOLL_CLOEXEC", EPOLL_CLOEXEC); #endif #endif /* HAVE_EPOLL */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/sha1module.c --- a/Modules/sha1module.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/sha1module.c Fri Feb 01 23:12:09 2013 +0100 @@ -92,6 +92,10 @@ (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \ (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } +#ifndef MIN + #define MIN(x, y) ( ((x)<(y))?(x):(y) ) +#endif + /* SHA1 macros */ @@ -216,7 +220,7 @@ in += SHA1_BLOCKSIZE; inlen -= SHA1_BLOCKSIZE; } else { - n = Py_MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen)); + n = MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen)); memcpy(sha1->buf + sha1->curlen, in, (size_t)n); sha1->curlen += (SHA1_INT32)n; in += n; @@ -316,8 +320,13 @@ { SHA1object *newobj; - if ((newobj = newSHA1object()) == NULL) - return NULL; + if (Py_TYPE(self) == &SHA1type) { + if ( (newobj = newSHA1object())==NULL) + return NULL; + } else { + if ( (newobj = newSHA1object())==NULL) + return NULL; + } newobj->hash_state = self->hash_state; return (PyObject *)newobj; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/sha256module.c --- a/Modules/sha256module.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/sha256module.c Fri Feb 01 23:12:09 2013 +0100 @@ -274,7 +274,7 @@ memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i); count -= i; buffer += i; - sha_info->local += (int)i; + sha_info->local += i; if (sha_info->local == SHA_BLOCKSIZE) { sha_transform(sha_info); } @@ -289,7 +289,7 @@ sha_transform(sha_info); } memcpy(sha_info->data, buffer, count); - sha_info->local = (int)count; + sha_info->local = count; } /* finish computing the SHA digest */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/sha512module.c --- a/Modules/sha512module.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/sha512module.c Fri Feb 01 23:12:09 2013 +0100 @@ -300,7 +300,7 @@ memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i); count -= i; buffer += i; - sha_info->local += (int)i; + sha_info->local += i; if (sha_info->local == SHA_BLOCKSIZE) { sha512_transform(sha_info); } @@ -315,7 +315,7 @@ sha512_transform(sha_info); } memcpy(sha_info->data, buffer, count); - sha_info->local = (int)count; + sha_info->local = count; } /* finish computing the SHA digest */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/signalmodule.c --- a/Modules/signalmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/signalmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -4,12 +4,9 @@ /* XXX Signals should be recorded per thread, now we have thread state. */ #include "Python.h" -#ifndef MS_WINDOWS -#include "posixmodule.h" -#endif #ifdef MS_WINDOWS -#include +#include #ifdef HAVE_PROCESS_H #include #endif @@ -339,10 +336,7 @@ Handlers[sig_num].tripped = 0; Py_INCREF(obj); Handlers[sig_num].func = obj; - if (old_handler != NULL) - return old_handler; - else - Py_RETURN_NONE; + return old_handler; } PyDoc_STRVAR(signal_doc, @@ -370,13 +364,8 @@ return NULL; } old_handler = Handlers[sig_num].func; - if (old_handler != NULL) { - Py_INCREF(old_handler); - return old_handler; - } - else { - Py_RETURN_NONE; - } + Py_INCREF(old_handler); + return old_handler; } PyDoc_STRVAR(getsignal_doc, @@ -433,7 +422,7 @@ return NULL; } #endif - if (fd != -1 && (!_PyVerify_fd(fd) || fstat(fd, &buf) != 0)) { + if (fd != -1 && fstat(fd, &buf) != 0) { PyErr_SetString(PyExc_ValueError, "invalid fd"); return NULL; } @@ -734,7 +723,7 @@ PyStructSequence_SET_ITEM(result, 1, PyLong_FromLong((long)(si->si_code))); PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si->si_errno))); PyStructSequence_SET_ITEM(result, 3, PyLong_FromPid(si->si_pid)); - PyStructSequence_SET_ITEM(result, 4, _PyLong_FromUid(si->si_uid)); + PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si->si_uid))); PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong((long)(si->si_status))); PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(si->si_band)); @@ -787,18 +776,14 @@ struct timespec buf; sigset_t set; siginfo_t si; - time_t tv_sec; - long tv_nsec; int err; if (!PyArg_ParseTuple(args, "OO:sigtimedwait", &signals, &timeout)) return NULL; - if (_PyTime_ObjectToTimespec(timeout, &tv_sec, &tv_nsec) == -1) + if (_PyTime_ObjectToTimespec(timeout, &buf.tv_sec, &buf.tv_nsec) == -1) return NULL; - buf.tv_sec = tv_sec; - buf.tv_nsec = tv_nsec; if (buf.tv_sec < 0 || buf.tv_nsec < 0) { PyErr_SetString(PyExc_ValueError, "timeout must be non-negative"); @@ -978,10 +963,9 @@ return NULL; #if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT) - if (!initialized) { - if (PyStructSequence_InitType2(&SiginfoType, &struct_siginfo_desc) < 0) - return NULL; - } + if (!initialized) + PyStructSequence_InitType(&SiginfoType, &struct_siginfo_desc); + Py_INCREF((PyObject*) &SiginfoType); PyModule_AddObject(m, "struct_siginfo", (PyObject*) &SiginfoType); initialized = 1; @@ -1378,8 +1362,9 @@ void PyOS_InitInterrupts(void) { - PyObject *m = PyImport_ImportModule("signal"); + PyObject *m = PyInit_signal(); if (m) { + _PyImport_FixupBuiltin(m, "signal"); Py_DECREF(m); } } diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/socketmodule.c --- a/Modules/socketmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/socketmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -95,15 +95,19 @@ #include "Python.h" #include "structmember.h" +#undef MAX +#define MAX(x, y) ((x) < (y) ? (y) : (x)) + /* Socket object documentation */ PyDoc_STRVAR(sock_doc, -"socket([family[, type[, proto]]]) -> socket object\n\ +"socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None, cloexec=None) -> socket object\n\ \n\ Open a socket of the given type. The family argument specifies the\n\ address family; it defaults to AF_INET. The type argument specifies\n\ whether this is a stream (SOCK_STREAM, this is the default)\n\ or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\ specifying the default protocol. Keyword arguments are accepted.\n\ +If cloexec is True, set close-on-exec flag.\n\ \n\ A socket object represents one endpoint of a network connection.\n\ \n\ @@ -114,7 +118,7 @@ close() -- close the socket\n\ connect(addr) -- connect the socket to a remote address\n\ connect_ex(addr) -- connect, return an error code instead of an exception\n\ -_dup() -- return a new socket fd duplicated from fileno()\n\ +dup(cloexec=None) -- return a new socket fd duplicated from fileno()\n\ fileno() -- return underlying file descriptor\n\ getpeername() -- return remote address [*]\n\ getsockname() -- return local address\n\ @@ -1595,16 +1599,13 @@ case AF_CAN: switch (s->sock_proto) { case CAN_RAW: - /* fall-through */ - case CAN_BCM: { struct sockaddr_can *addr; PyObject *interfaceName; struct ifreq ifr; + addr = (struct sockaddr_can *)addr_ret; Py_ssize_t len; - addr = (struct sockaddr_can *)addr_ret; - if (!PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, &interfaceName)) return 0; @@ -1946,8 +1947,9 @@ /* s._accept() -> (fd, address) */ static PyObject * -sock_accept(PySocketSockObject *s) +sock_accept(PySocketSockObject *s, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"cloexec", 0}; sock_addr_t addrbuf; SOCKET_T newfd = INVALID_SOCKET; socklen_t addrlen; @@ -1955,6 +1957,17 @@ PyObject *addr = NULL; PyObject *res = NULL; int timeout; + int cloexec = Py_DefaultCloexec; +#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) + /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */ + static int accept4_works = -1; +#endif + + /* Get the buffer's memory */ + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&:_accept", kwlist, + _Py_cloexec_converter, &cloexec)) + return NULL; + if (!getsockaddrlen(s, &addrlen)) return NULL; memset(&addrbuf, 0, addrlen); @@ -1963,10 +1976,26 @@ return select_error(); BEGIN_SELECT_LOOP(s) + Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 0, interval); if (!timeout) { +#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) + if (accept4_works != 0) { + int flags; + if (cloexec) + flags = SOCK_CLOEXEC; + else + flags = 0; + newfd = accept4(s->sock_fd, SAS2SA(&addrbuf), &addrlen, flags); + if (newfd == INVALID_SOCKET && accept4_works == -1) + accept4_works = (errno != ENOSYS); + } + if (accept4_works == 0) + newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); +#else newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); +#endif } Py_END_ALLOW_THREADS @@ -1979,11 +2008,24 @@ if (newfd == INVALID_SOCKET) return s->errorhandler(); + if (cloexec +#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) + && accept4_works == 0 +#endif + ) + { +#ifdef MS_WINDOWS + if (_Py_set_cloexec_handle((Py_intptr_t)newfd, 1, NULL) < 0) + goto error; +#else + if (_Py_set_cloexec(newfd, 1, NULL) < 0) + goto error; +#endif + } + sock = PyLong_FromSocket_t(newfd); - if (sock == NULL) { - SOCKETCLOSE(newfd); - goto finally; - } + if (sock == NULL) + goto error; addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, s->sock_proto); @@ -1991,6 +2033,10 @@ goto finally; res = PyTuple_Pack(2, sock, addr); + goto finally; + +error: + SOCKETCLOSE(newfd); finally: Py_XDECREF(sock); @@ -1999,11 +2045,12 @@ } PyDoc_STRVAR(accept_doc, -"_accept() -> (integer, address info)\n\ +"_accept(cloexec=None) -> (integer, address info)\n\ \n\ Wait for an incoming connection. Return a new socket file descriptor\n\ representing the connection, and the address of the client.\n\ -For IP sockets, the address info is a pair (hostaddr, port)."); +For IP sockets, the address info is a pair (hostaddr, port).\n\ +If cloexec is True, set close-on-exec flag."); /* s.setblocking(flag) method. Argument: False -- non-blocking mode; same as settimeout(0) @@ -2552,15 +2599,8 @@ BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 0, interval); - if (!timeout) { -#ifdef MS_WINDOWS - if (len > INT_MAX) - len = INT_MAX; - outlen = recv(s->sock_fd, cbuf, (int)len, flags); -#else + if (!timeout) outlen = recv(s->sock_fd, cbuf, len, flags); -#endif - } Py_END_ALLOW_THREADS if (timeout == 1) { @@ -2767,9 +2807,7 @@ timeout = internal_select_ex(s, 0, interval); if (!timeout) { #ifndef MS_WINDOWS - if (len > INT_MAX) - len = INT_MAX; - n = recvfrom(s->sock_fd, cbuf, (int)len, flags, + n = recvfrom(s->sock_fd, cbuf, len, flags, (void *) &addrbuf, &addrlen); #else n = recvfrom(s->sock_fd, cbuf, len, flags, @@ -3248,17 +3286,12 @@ BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 1, interval); - if (!timeout) { + if (!timeout) #ifdef __VMS n = sendsegmented(s->sock_fd, buf, len, flags); -#elif defined(MS_WINDOWS) - if (len > INT_MAX) - len = INT_MAX; - n = send(s->sock_fd, buf, (int)len, flags); #else n = send(s->sock_fd, buf, len, flags); #endif - } Py_END_ALLOW_THREADS if (timeout == 1) { PyBuffer_Release(&pbuf); @@ -3308,10 +3341,6 @@ if (!timeout) { #ifdef __VMS n = sendsegmented(s->sock_fd, buf, len, flags); -#elif defined(MS_WINDOWS) - if (len > INT_MAX) - len = INT_MAX; - n = send(s->sock_fd, buf, (int)len, flags); #else n = send(s->sock_fd, buf, len, flags); #endif @@ -3406,17 +3435,8 @@ BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 1, interval); - if (!timeout) { -#ifdef MS_WINDOWS - if (len > INT_MAX) - len = INT_MAX; - n = sendto(s->sock_fd, buf, (int)len, flags, - SAS2SA(&addrbuf), addrlen); -#else - n = sendto(s->sock_fd, buf, len, flags, - SAS2SA(&addrbuf), addrlen); -#endif - } + if (!timeout) + n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen); Py_END_ALLOW_THREADS if (timeout == 1) { @@ -3571,7 +3591,7 @@ the next header, it checks its (uninitialized) cmsg_len member to see if the "message" fits in the buffer, and returns NULL if it doesn't. Zero-filling the buffer - ensures that this doesn't happen. */ + ensures that that doesn't happen. */ memset(controlbuf, 0, controllen); for (i = 0; i < ncmsgbufs; i++) { @@ -3768,8 +3788,8 @@ /* List of methods for socket objects */ static PyMethodDef sock_methods[] = { - {"_accept", (PyCFunction)sock_accept, METH_NOARGS, - accept_doc}, + {"_accept", (PyCFunction)sock_accept, + METH_VARARGS | METH_KEYWORDS, accept_doc}, {"bind", (PyCFunction)sock_bind, METH_O, bind_doc}, {"close", (PyCFunction)sock_close, METH_NOARGS, @@ -3909,19 +3929,27 @@ /* Initialize a new socket object. */ +#ifdef SOCK_CLOEXEC +/* socket() and socketpair() fail with EINVAL on Linux kernel older + * than 2.6.27 if SOCK_CLOEXEC flag is set in the socket type. */ +static int sock_cloexec_works = -1; +#endif + /*ARGSUSED*/ static int sock_initobj(PyObject *self, PyObject *args, PyObject *kwds) { PySocketSockObject *s = (PySocketSockObject *)self; PyObject *fdobj = NULL; + int cloexec = Py_DefaultCloexec; SOCKET_T fd = INVALID_SOCKET; int family = AF_INET, type = SOCK_STREAM, proto = 0; - static char *keywords[] = {"family", "type", "proto", "fileno", 0}; + static char *keywords[] = {"family", "type", "proto", "fileno", "cloexec", 0}; if (!PyArg_ParseTupleAndKeywords(args, kwds, - "|iiiO:socket", keywords, - &family, &type, &proto, &fdobj)) + "|iiiOO&:socket", keywords, + &family, &type, &proto, &fdobj, + _Py_cloexec_converter, &cloexec)) return -1; if (fdobj != NULL && fdobj != Py_None) { @@ -3963,14 +3991,48 @@ } else { Py_BEGIN_ALLOW_THREADS - fd = socket(family, type, proto); +#ifdef SOCK_CLOEXEC + if (cloexec && sock_cloexec_works != 0) { + fd = socket(family, type | SOCK_CLOEXEC, proto); + if (sock_cloexec_works == -1 && fd < 0) { + sock_cloexec_works = (errno != EINVAL); + if (!sock_cloexec_works) { + fd = socket(family, type, proto); + } + } + } + else +#endif + { + fd = socket(family, type, proto); + } Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error(); return -1; } - } + + if (cloexec) { +#ifdef MS_WINDOWS + if (_Py_set_cloexec_handle((Py_intptr_t)fd, 1, NULL) < 0) { + SOCKETCLOSE(fd); + return -1; + } +#else +#ifdef SOCK_CLOEXEC + int *atomic_flag_works = &sock_cloexec_works; +#else + int *atomic_flag_works = NULL; +#endif + if (_Py_set_cloexec(fd, 1, atomic_flag_works) < 0) { + SOCKETCLOSE(fd); + return -1; + } +#endif + } + } + init_sockobject(s, fd, family, type, proto); return 0; @@ -4072,7 +4134,7 @@ if (res < 0) return set_error(); buf[sizeof buf - 1] = '\0'; - return PyUnicode_DecodeFSDefault(buf); + return PyUnicode_FromString(buf); #endif } @@ -4093,11 +4155,6 @@ Py_buffer buf; int res, flag = 0; -#ifdef _AIX -/* issue #18259, not declared in any useful header file */ -extern int sethostname(const char *, size_t); -#endif - if (!PyArg_ParseTuple(args, "S:sethostname", &hnobj)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "O&:sethostname", @@ -4531,11 +4588,17 @@ /* dup() function for socket fds */ static PyObject * -socket_dup(PyObject *self, PyObject *fdobj) +socket_dup(PyObject *self, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"fd", "cloexec", 0}; SOCKET_T fd, newfd; - PyObject *newfdobj; - + PyObject *fdobj, *newfdobj; + int cloexec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&:dup", kwlist, + &fdobj, + _Py_cloexec_converter, &cloexec)) + return NULL; fd = PyLong_AsSocket_t(fdobj); if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) @@ -4545,10 +4608,24 @@ if (newfd == INVALID_SOCKET) return set_error(); + if (cloexec) { +#ifdef MS_WINDOWS + if (_Py_set_cloexec_handle((Py_intptr_t)newfd, 1, NULL) < 0) + goto error; +#else + if (_Py_set_cloexec(newfd, 1, NULL) < 0) + goto error; +#endif + } + newfdobj = PyLong_FromSocket_t(newfd); if (newfdobj == NULL) - SOCKETCLOSE(newfd); + goto error; return newfdobj; + +error: + SOCKETCLOSE(newfd); + return NULL; } PyDoc_STRVAR(dup_doc, @@ -4566,24 +4643,57 @@ /*ARGSUSED*/ static PyObject * -socket_socketpair(PyObject *self, PyObject *args) +socket_socketpair(PyObject *self, PyObject *args, PyObject *kwargs) { + static char *kwlist[] = {"family", "type", "proto", "cloexec", 0}; PySocketSockObject *s0 = NULL, *s1 = NULL; SOCKET_T sv[2]; - int family, type = SOCK_STREAM, proto = 0; + int family = AF_INET, type = SOCK_STREAM, proto = 0; PyObject *res = NULL; + int cloexec = Py_DefaultCloexec; +#ifdef SOCK_CLOEXEC + int *atomic_flag_works = &sock_cloexec_works; +#else + int *atomic_flag_works = NULL; +#endif + int ret; #if defined(AF_UNIX) family = AF_UNIX; #else family = AF_INET; #endif - if (!PyArg_ParseTuple(args, "|iii:socketpair", - &family, &type, &proto)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiiO&:socketpair", kwlist, + &family, &type, &proto, + _Py_cloexec_converter, &cloexec)) return NULL; + /* Create a pair of socket fds */ - if (socketpair(family, type, proto, sv) < 0) +#ifdef SOCK_CLOEXEC + if (cloexec && sock_cloexec_works != 0) { + ret = socketpair(family, type | SOCK_CLOEXEC, proto, sv); + if (sock_cloexec_works == -1 && ret < 0) { + sock_cloexec_works = (errno != EINVAL); + if (!sock_cloexec_works) + ret = socketpair(family, type, proto, sv); + } + } + else +#endif + { + ret = socketpair(family, type, proto, sv); + } + + if (ret < 0) return set_error(); + + if (cloexec) { + if (_Py_set_cloexec(sv[0], 1, atomic_flag_works) < 0) + goto finally; + if (_Py_set_cloexec(sv[1], 1, atomic_flag_works) < 0) + goto finally; + } + s0 = new_sockobject(sv[0], family, type, proto); if (s0 == NULL) goto finally; @@ -4605,12 +4715,13 @@ } PyDoc_STRVAR(socketpair_doc, -"socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\ +"socketpair(family=AF_INET, type=SOCK_STREAM, proto=0, cloexec=None) -> (socket object, socket object)\n\ \n\ Create a pair of socket objects from the sockets returned by the platform\n\ socketpair() function.\n\ The arguments are the same as for socket() except the default family is\n\ -AF_UNIX if defined on the platform; otherwise, the default is AF_INET."); +AF_UNIX if defined on the platform; otherwise, the default is AF_INET.\n\ +If cloexec is True, set close-on-exec flag."); #endif /* HAVE_SOCKETPAIR */ @@ -4663,6 +4774,8 @@ return PyErr_Format(PyExc_TypeError, "expected int/long, %s found", Py_TYPE(arg)->tp_name); + if (x == (unsigned long) -1 && PyErr_Occurred()) + return NULL; return PyLong_FromUnsignedLong(ntohl(x)); } @@ -4846,7 +4959,7 @@ char* ip; int retval; #ifdef ENABLE_IPV6 - char packed[Py_MAX(sizeof(struct in_addr), sizeof(struct in6_addr))]; + char packed[MAX(sizeof(struct in_addr), sizeof(struct in6_addr))]; #else char packed[sizeof(struct in_addr)]; #endif @@ -4897,7 +5010,7 @@ int len; const char* retval; #ifdef ENABLE_IPV6 - char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1]; + char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1]; #else char ip[INET_ADDRSTRLEN + 1]; #endif @@ -5005,15 +5118,6 @@ PyErr_SetString(PyExc_OSError, "Int or String expected"); goto err; } -#if defined(__APPLE__) && defined(AI_NUMERICSERV) - if ((flags & AI_NUMERICSERV) && (pptr == NULL || (pptr[0] == '0' && pptr[1] == 0))) { - /* On OSX upto at least OSX 10.8 getaddrinfo crashes - * if AI_NUMERICSERV is set and the servname is NULL or "0". - * This workaround avoids a segfault in libsystem. - */ - pptr = "00"; - } -#endif memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = socktype; @@ -5389,12 +5493,12 @@ {"getprotobyname", socket_getprotobyname, METH_VARARGS, getprotobyname_doc}, #ifndef NO_DUP - {"dup", socket_dup, - METH_O, dup_doc}, + {"dup", (PyCFunction)socket_dup, + METH_VARARGS | METH_KEYWORDS, dup_doc}, #endif #ifdef HAVE_SOCKETPAIR - {"socketpair", socket_socketpair, - METH_VARARGS, socketpair_doc}, + {"socketpair", (PyCFunction)socket_socketpair, + METH_VARARGS | METH_KEYWORDS, socketpair_doc}, #endif {"ntohs", socket_ntohs, METH_VARARGS, ntohs_doc}, @@ -5592,187 +5696,184 @@ /* Address families (we only support AF_INET and AF_UNIX) */ #ifdef AF_UNSPEC - PyModule_AddIntMacro(m, AF_UNSPEC); -#endif - PyModule_AddIntMacro(m, AF_INET); + PyModule_AddIntConstant(m, "AF_UNSPEC", AF_UNSPEC); +#endif + PyModule_AddIntConstant(m, "AF_INET", AF_INET); #ifdef AF_INET6 - PyModule_AddIntMacro(m, AF_INET6); + PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); #endif /* AF_INET6 */ #if defined(AF_UNIX) - PyModule_AddIntMacro(m, AF_UNIX); + PyModule_AddIntConstant(m, "AF_UNIX", AF_UNIX); #endif /* AF_UNIX */ #ifdef AF_AX25 /* Amateur Radio AX.25 */ - PyModule_AddIntMacro(m, AF_AX25); + PyModule_AddIntConstant(m, "AF_AX25", AF_AX25); #endif #ifdef AF_IPX - PyModule_AddIntMacro(m, AF_IPX); /* Novell IPX */ + PyModule_AddIntConstant(m, "AF_IPX", AF_IPX); /* Novell IPX */ #endif #ifdef AF_APPLETALK /* Appletalk DDP */ - PyModule_AddIntMacro(m, AF_APPLETALK); + PyModule_AddIntConstant(m, "AF_APPLETALK", AF_APPLETALK); #endif #ifdef AF_NETROM /* Amateur radio NetROM */ - PyModule_AddIntMacro(m, AF_NETROM); + PyModule_AddIntConstant(m, "AF_NETROM", AF_NETROM); #endif #ifdef AF_BRIDGE /* Multiprotocol bridge */ - PyModule_AddIntMacro(m, AF_BRIDGE); + PyModule_AddIntConstant(m, "AF_BRIDGE", AF_BRIDGE); #endif #ifdef AF_ATMPVC /* ATM PVCs */ - PyModule_AddIntMacro(m, AF_ATMPVC); + PyModule_AddIntConstant(m, "AF_ATMPVC", AF_ATMPVC); #endif #ifdef AF_AAL5 /* Reserved for Werner's ATM */ - PyModule_AddIntMacro(m, AF_AAL5); + PyModule_AddIntConstant(m, "AF_AAL5", AF_AAL5); #endif #ifdef AF_X25 /* Reserved for X.25 project */ - PyModule_AddIntMacro(m, AF_X25); + PyModule_AddIntConstant(m, "AF_X25", AF_X25); #endif #ifdef AF_INET6 - PyModule_AddIntMacro(m, AF_INET6); /* IP version 6 */ + PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); /* IP version 6 */ #endif #ifdef AF_ROSE /* Amateur Radio X.25 PLP */ - PyModule_AddIntMacro(m, AF_ROSE); + PyModule_AddIntConstant(m, "AF_ROSE", AF_ROSE); #endif #ifdef AF_DECnet /* Reserved for DECnet project */ - PyModule_AddIntMacro(m, AF_DECnet); + PyModule_AddIntConstant(m, "AF_DECnet", AF_DECnet); #endif #ifdef AF_NETBEUI /* Reserved for 802.2LLC project */ - PyModule_AddIntMacro(m, AF_NETBEUI); + PyModule_AddIntConstant(m, "AF_NETBEUI", AF_NETBEUI); #endif #ifdef AF_SECURITY /* Security callback pseudo AF */ - PyModule_AddIntMacro(m, AF_SECURITY); + PyModule_AddIntConstant(m, "AF_SECURITY", AF_SECURITY); #endif #ifdef AF_KEY /* PF_KEY key management API */ - PyModule_AddIntMacro(m, AF_KEY); + PyModule_AddIntConstant(m, "AF_KEY", AF_KEY); #endif #ifdef AF_NETLINK /* */ - PyModule_AddIntMacro(m, AF_NETLINK); - PyModule_AddIntMacro(m, NETLINK_ROUTE); + PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK); + PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE); #ifdef NETLINK_SKIP - PyModule_AddIntMacro(m, NETLINK_SKIP); + PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP); #endif #ifdef NETLINK_W1 - PyModule_AddIntMacro(m, NETLINK_W1); -#endif - PyModule_AddIntMacro(m, NETLINK_USERSOCK); - PyModule_AddIntMacro(m, NETLINK_FIREWALL); + PyModule_AddIntConstant(m, "NETLINK_W1", NETLINK_W1); +#endif + PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK); + PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL); #ifdef NETLINK_TCPDIAG - PyModule_AddIntMacro(m, NETLINK_TCPDIAG); + PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG); #endif #ifdef NETLINK_NFLOG - PyModule_AddIntMacro(m, NETLINK_NFLOG); + PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG); #endif #ifdef NETLINK_XFRM - PyModule_AddIntMacro(m, NETLINK_XFRM); + PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM); #endif #ifdef NETLINK_ARPD - PyModule_AddIntMacro(m, NETLINK_ARPD); + PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD); #endif #ifdef NETLINK_ROUTE6 - PyModule_AddIntMacro(m, NETLINK_ROUTE6); -#endif - PyModule_AddIntMacro(m, NETLINK_IP6_FW); + PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6); +#endif + PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW); #ifdef NETLINK_DNRTMSG - PyModule_AddIntMacro(m, NETLINK_DNRTMSG); + PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG); #endif #ifdef NETLINK_TAPBASE - PyModule_AddIntMacro(m, NETLINK_TAPBASE); + PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE); #endif #endif /* AF_NETLINK */ #ifdef AF_ROUTE /* Alias to emulate 4.4BSD */ - PyModule_AddIntMacro(m, AF_ROUTE); -#endif -#ifdef AF_LINK - PyModule_AddIntMacro(m, AF_LINK); + PyModule_AddIntConstant(m, "AF_ROUTE", AF_ROUTE); #endif #ifdef AF_ASH /* Ash */ - PyModule_AddIntMacro(m, AF_ASH); + PyModule_AddIntConstant(m, "AF_ASH", AF_ASH); #endif #ifdef AF_ECONET /* Acorn Econet */ - PyModule_AddIntMacro(m, AF_ECONET); + PyModule_AddIntConstant(m, "AF_ECONET", AF_ECONET); #endif #ifdef AF_ATMSVC /* ATM SVCs */ - PyModule_AddIntMacro(m, AF_ATMSVC); + PyModule_AddIntConstant(m, "AF_ATMSVC", AF_ATMSVC); #endif #ifdef AF_SNA /* Linux SNA Project (nutters!) */ - PyModule_AddIntMacro(m, AF_SNA); + PyModule_AddIntConstant(m, "AF_SNA", AF_SNA); #endif #ifdef AF_IRDA /* IRDA sockets */ - PyModule_AddIntMacro(m, AF_IRDA); + PyModule_AddIntConstant(m, "AF_IRDA", AF_IRDA); #endif #ifdef AF_PPPOX /* PPPoX sockets */ - PyModule_AddIntMacro(m, AF_PPPOX); + PyModule_AddIntConstant(m, "AF_PPPOX", AF_PPPOX); #endif #ifdef AF_WANPIPE /* Wanpipe API Sockets */ - PyModule_AddIntMacro(m, AF_WANPIPE); + PyModule_AddIntConstant(m, "AF_WANPIPE", AF_WANPIPE); #endif #ifdef AF_LLC /* Linux LLC */ - PyModule_AddIntMacro(m, AF_LLC); + PyModule_AddIntConstant(m, "AF_LLC", AF_LLC); #endif #ifdef USE_BLUETOOTH - PyModule_AddIntMacro(m, AF_BLUETOOTH); - PyModule_AddIntMacro(m, BTPROTO_L2CAP); - PyModule_AddIntMacro(m, BTPROTO_HCI); - PyModule_AddIntMacro(m, SOL_HCI); + PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH); + PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP); + PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI); + PyModule_AddIntConstant(m, "SOL_HCI", SOL_HCI); #if !defined(__NetBSD__) && !defined(__DragonFly__) - PyModule_AddIntMacro(m, HCI_FILTER); + PyModule_AddIntConstant(m, "HCI_FILTER", HCI_FILTER); #endif #if !defined(__FreeBSD__) #if !defined(__NetBSD__) && !defined(__DragonFly__) - PyModule_AddIntMacro(m, HCI_TIME_STAMP); -#endif - PyModule_AddIntMacro(m, HCI_DATA_DIR); - PyModule_AddIntMacro(m, BTPROTO_SCO); -#endif - PyModule_AddIntMacro(m, BTPROTO_RFCOMM); + PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP); +#endif + PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR); + PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO); +#endif + PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM); PyModule_AddStringConstant(m, "BDADDR_ANY", "00:00:00:00:00:00"); PyModule_AddStringConstant(m, "BDADDR_LOCAL", "00:00:00:FF:FF:FF"); #endif #ifdef AF_CAN /* Controller Area Network */ - PyModule_AddIntMacro(m, AF_CAN); + PyModule_AddIntConstant(m, "AF_CAN", AF_CAN); #endif #ifdef PF_CAN /* Controller Area Network */ - PyModule_AddIntMacro(m, PF_CAN); + PyModule_AddIntConstant(m, "PF_CAN", PF_CAN); #endif /* Reliable Datagram Sockets */ #ifdef AF_RDS - PyModule_AddIntMacro(m, AF_RDS); + PyModule_AddIntConstant(m, "AF_RDS", AF_RDS); #endif #ifdef PF_RDS - PyModule_AddIntMacro(m, PF_RDS); + PyModule_AddIntConstant(m, "PF_RDS", PF_RDS); #endif /* Kernel event messages */ #ifdef PF_SYSTEM - PyModule_AddIntMacro(m, PF_SYSTEM); + PyModule_AddIntConstant(m, "PF_SYSTEM", PF_SYSTEM); #endif #ifdef AF_SYSTEM - PyModule_AddIntMacro(m, AF_SYSTEM); + PyModule_AddIntConstant(m, "AF_SYSTEM", AF_SYSTEM); #endif #ifdef AF_PACKET @@ -5804,129 +5905,134 @@ #endif #ifdef HAVE_LINUX_TIPC_H - PyModule_AddIntMacro(m, AF_TIPC); + PyModule_AddIntConstant(m, "AF_TIPC", AF_TIPC); /* for addresses */ - PyModule_AddIntMacro(m, TIPC_ADDR_NAMESEQ); - PyModule_AddIntMacro(m, TIPC_ADDR_NAME); - PyModule_AddIntMacro(m, TIPC_ADDR_ID); - - PyModule_AddIntMacro(m, TIPC_ZONE_SCOPE); - PyModule_AddIntMacro(m, TIPC_CLUSTER_SCOPE); - PyModule_AddIntMacro(m, TIPC_NODE_SCOPE); + PyModule_AddIntConstant(m, "TIPC_ADDR_NAMESEQ", TIPC_ADDR_NAMESEQ); + PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME); + PyModule_AddIntConstant(m, "TIPC_ADDR_ID", TIPC_ADDR_ID); + + PyModule_AddIntConstant(m, "TIPC_ZONE_SCOPE", TIPC_ZONE_SCOPE); + PyModule_AddIntConstant(m, "TIPC_CLUSTER_SCOPE", TIPC_CLUSTER_SCOPE); + PyModule_AddIntConstant(m, "TIPC_NODE_SCOPE", TIPC_NODE_SCOPE); /* for setsockopt() */ - PyModule_AddIntMacro(m, SOL_TIPC); - PyModule_AddIntMacro(m, TIPC_IMPORTANCE); - PyModule_AddIntMacro(m, TIPC_SRC_DROPPABLE); - PyModule_AddIntMacro(m, TIPC_DEST_DROPPABLE); - PyModule_AddIntMacro(m, TIPC_CONN_TIMEOUT); - - PyModule_AddIntMacro(m, TIPC_LOW_IMPORTANCE); - PyModule_AddIntMacro(m, TIPC_MEDIUM_IMPORTANCE); - PyModule_AddIntMacro(m, TIPC_HIGH_IMPORTANCE); - PyModule_AddIntMacro(m, TIPC_CRITICAL_IMPORTANCE); + PyModule_AddIntConstant(m, "SOL_TIPC", SOL_TIPC); + PyModule_AddIntConstant(m, "TIPC_IMPORTANCE", TIPC_IMPORTANCE); + PyModule_AddIntConstant(m, "TIPC_SRC_DROPPABLE", TIPC_SRC_DROPPABLE); + PyModule_AddIntConstant(m, "TIPC_DEST_DROPPABLE", + TIPC_DEST_DROPPABLE); + PyModule_AddIntConstant(m, "TIPC_CONN_TIMEOUT", TIPC_CONN_TIMEOUT); + + PyModule_AddIntConstant(m, "TIPC_LOW_IMPORTANCE", + TIPC_LOW_IMPORTANCE); + PyModule_AddIntConstant(m, "TIPC_MEDIUM_IMPORTANCE", + TIPC_MEDIUM_IMPORTANCE); + PyModule_AddIntConstant(m, "TIPC_HIGH_IMPORTANCE", + TIPC_HIGH_IMPORTANCE); + PyModule_AddIntConstant(m, "TIPC_CRITICAL_IMPORTANCE", + TIPC_CRITICAL_IMPORTANCE); /* for subscriptions */ - PyModule_AddIntMacro(m, TIPC_SUB_PORTS); - PyModule_AddIntMacro(m, TIPC_SUB_SERVICE); + PyModule_AddIntConstant(m, "TIPC_SUB_PORTS", TIPC_SUB_PORTS); + PyModule_AddIntConstant(m, "TIPC_SUB_SERVICE", TIPC_SUB_SERVICE); #ifdef TIPC_SUB_CANCEL /* doesn't seem to be available everywhere */ - PyModule_AddIntMacro(m, TIPC_SUB_CANCEL); -#endif - PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER); - PyModule_AddIntMacro(m, TIPC_PUBLISHED); - PyModule_AddIntMacro(m, TIPC_WITHDRAWN); - PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT); - PyModule_AddIntMacro(m, TIPC_CFG_SRV); - PyModule_AddIntMacro(m, TIPC_TOP_SRV); + PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL); +#endif + PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER); + PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED); + PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN); + PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT); + PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV); + PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV); #endif /* Socket types */ - PyModule_AddIntMacro(m, SOCK_STREAM); - PyModule_AddIntMacro(m, SOCK_DGRAM); + PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM); + PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM); /* We have incomplete socket support. */ - PyModule_AddIntMacro(m, SOCK_RAW); - PyModule_AddIntMacro(m, SOCK_SEQPACKET); + PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW); + PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET); #if defined(SOCK_RDM) - PyModule_AddIntMacro(m, SOCK_RDM); + PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM); #endif #ifdef SOCK_CLOEXEC - PyModule_AddIntMacro(m, SOCK_CLOEXEC); + PyModule_AddIntConstant(m, "SOCK_CLOEXEC", SOCK_CLOEXEC); #endif #ifdef SOCK_NONBLOCK - PyModule_AddIntMacro(m, SOCK_NONBLOCK); + PyModule_AddIntConstant(m, "SOCK_NONBLOCK", SOCK_NONBLOCK); #endif #ifdef SO_DEBUG - PyModule_AddIntMacro(m, SO_DEBUG); + PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG); #endif #ifdef SO_ACCEPTCONN - PyModule_AddIntMacro(m, SO_ACCEPTCONN); + PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN); #endif #ifdef SO_REUSEADDR - PyModule_AddIntMacro(m, SO_REUSEADDR); + PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR); #endif #ifdef SO_EXCLUSIVEADDRUSE - PyModule_AddIntMacro(m, SO_EXCLUSIVEADDRUSE); + PyModule_AddIntConstant(m, "SO_EXCLUSIVEADDRUSE", SO_EXCLUSIVEADDRUSE); #endif #ifdef SO_KEEPALIVE - PyModule_AddIntMacro(m, SO_KEEPALIVE); + PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE); #endif #ifdef SO_DONTROUTE - PyModule_AddIntMacro(m, SO_DONTROUTE); + PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE); #endif #ifdef SO_BROADCAST - PyModule_AddIntMacro(m, SO_BROADCAST); + PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST); #endif #ifdef SO_USELOOPBACK - PyModule_AddIntMacro(m, SO_USELOOPBACK); + PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK); #endif #ifdef SO_LINGER - PyModule_AddIntMacro(m, SO_LINGER); + PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER); #endif #ifdef SO_OOBINLINE - PyModule_AddIntMacro(m, SO_OOBINLINE); + PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE); #endif #ifdef SO_REUSEPORT - PyModule_AddIntMacro(m, SO_REUSEPORT); + PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT); #endif #ifdef SO_SNDBUF - PyModule_AddIntMacro(m, SO_SNDBUF); + PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF); #endif #ifdef SO_RCVBUF - PyModule_AddIntMacro(m, SO_RCVBUF); + PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF); #endif #ifdef SO_SNDLOWAT - PyModule_AddIntMacro(m, SO_SNDLOWAT); + PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT); #endif #ifdef SO_RCVLOWAT - PyModule_AddIntMacro(m, SO_RCVLOWAT); + PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT); #endif #ifdef SO_SNDTIMEO - PyModule_AddIntMacro(m, SO_SNDTIMEO); + PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO); #endif #ifdef SO_RCVTIMEO - PyModule_AddIntMacro(m, SO_RCVTIMEO); + PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO); #endif #ifdef SO_ERROR - PyModule_AddIntMacro(m, SO_ERROR); + PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR); #endif #ifdef SO_TYPE - PyModule_AddIntMacro(m, SO_TYPE); + PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE); #endif #ifdef SO_SETFIB - PyModule_AddIntMacro(m, SO_SETFIB); + PyModule_AddIntConstant(m, "SO_SETFIB", SO_SETFIB); #endif #ifdef SO_PASSCRED - PyModule_AddIntMacro(m, SO_PASSCRED); + PyModule_AddIntConstant(m, "SO_PASSCRED", SO_PASSCRED); #endif #ifdef SO_PEERCRED - PyModule_AddIntMacro(m, SO_PEERCRED); + PyModule_AddIntConstant(m, "SO_PEERCRED", SO_PEERCRED); #endif #ifdef LOCAL_PEERCRED - PyModule_AddIntMacro(m, LOCAL_PEERCRED); + PyModule_AddIntConstant(m, "LOCAL_PEERCRED", LOCAL_PEERCRED); #endif #ifdef SO_BINDTODEVICE PyModule_AddIntMacro(m, SO_BINDTODEVICE); @@ -5934,330 +6040,315 @@ /* Maximum number of connections for "listen" */ #ifdef SOMAXCONN - PyModule_AddIntMacro(m, SOMAXCONN); + PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN); #else PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ #endif /* Ancilliary message types */ #ifdef SCM_RIGHTS - PyModule_AddIntMacro(m, SCM_RIGHTS); + PyModule_AddIntConstant(m, "SCM_RIGHTS", SCM_RIGHTS); #endif #ifdef SCM_CREDENTIALS - PyModule_AddIntMacro(m, SCM_CREDENTIALS); + PyModule_AddIntConstant(m, "SCM_CREDENTIALS", SCM_CREDENTIALS); #endif #ifdef SCM_CREDS - PyModule_AddIntMacro(m, SCM_CREDS); + PyModule_AddIntConstant(m, "SCM_CREDS", SCM_CREDS); #endif /* Flags for send, recv */ #ifdef MSG_OOB - PyModule_AddIntMacro(m, MSG_OOB); + PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB); #endif #ifdef MSG_PEEK - PyModule_AddIntMacro(m, MSG_PEEK); + PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK); #endif #ifdef MSG_DONTROUTE - PyModule_AddIntMacro(m, MSG_DONTROUTE); + PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE); #endif #ifdef MSG_DONTWAIT - PyModule_AddIntMacro(m, MSG_DONTWAIT); + PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT); #endif #ifdef MSG_EOR - PyModule_AddIntMacro(m, MSG_EOR); + PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR); #endif #ifdef MSG_TRUNC - PyModule_AddIntMacro(m, MSG_TRUNC); + PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC); #endif #ifdef MSG_CTRUNC - PyModule_AddIntMacro(m, MSG_CTRUNC); + PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC); #endif #ifdef MSG_WAITALL - PyModule_AddIntMacro(m, MSG_WAITALL); + PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL); #endif #ifdef MSG_BTAG - PyModule_AddIntMacro(m, MSG_BTAG); + PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG); #endif #ifdef MSG_ETAG - PyModule_AddIntMacro(m, MSG_ETAG); + PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG); #endif #ifdef MSG_NOSIGNAL - PyModule_AddIntMacro(m, MSG_NOSIGNAL); + PyModule_AddIntConstant(m, "MSG_NOSIGNAL", MSG_NOSIGNAL); #endif #ifdef MSG_NOTIFICATION - PyModule_AddIntMacro(m, MSG_NOTIFICATION); + PyModule_AddIntConstant(m, "MSG_NOTIFICATION", MSG_NOTIFICATION); #endif #ifdef MSG_CMSG_CLOEXEC - PyModule_AddIntMacro(m, MSG_CMSG_CLOEXEC); + PyModule_AddIntConstant(m, "MSG_CMSG_CLOEXEC", MSG_CMSG_CLOEXEC); #endif #ifdef MSG_ERRQUEUE - PyModule_AddIntMacro(m, MSG_ERRQUEUE); + PyModule_AddIntConstant(m, "MSG_ERRQUEUE", MSG_ERRQUEUE); #endif #ifdef MSG_CONFIRM - PyModule_AddIntMacro(m, MSG_CONFIRM); + PyModule_AddIntConstant(m, "MSG_CONFIRM", MSG_CONFIRM); #endif #ifdef MSG_MORE - PyModule_AddIntMacro(m, MSG_MORE); + PyModule_AddIntConstant(m, "MSG_MORE", MSG_MORE); #endif #ifdef MSG_EOF - PyModule_AddIntMacro(m, MSG_EOF); + PyModule_AddIntConstant(m, "MSG_EOF", MSG_EOF); #endif #ifdef MSG_BCAST - PyModule_AddIntMacro(m, MSG_BCAST); + PyModule_AddIntConstant(m, "MSG_BCAST", MSG_BCAST); #endif #ifdef MSG_MCAST - PyModule_AddIntMacro(m, MSG_MCAST); + PyModule_AddIntConstant(m, "MSG_MCAST", MSG_MCAST); #endif #ifdef MSG_FASTOPEN - PyModule_AddIntMacro(m, MSG_FASTOPEN); + PyModule_AddIntConstant(m, "MSG_FASTOPEN", MSG_FASTOPEN); #endif /* Protocol level and numbers, usable for [gs]etsockopt */ #ifdef SOL_SOCKET - PyModule_AddIntMacro(m, SOL_SOCKET); + PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET); #endif #ifdef SOL_IP - PyModule_AddIntMacro(m, SOL_IP); + PyModule_AddIntConstant(m, "SOL_IP", SOL_IP); #else PyModule_AddIntConstant(m, "SOL_IP", 0); #endif #ifdef SOL_IPX - PyModule_AddIntMacro(m, SOL_IPX); + PyModule_AddIntConstant(m, "SOL_IPX", SOL_IPX); #endif #ifdef SOL_AX25 - PyModule_AddIntMacro(m, SOL_AX25); + PyModule_AddIntConstant(m, "SOL_AX25", SOL_AX25); #endif #ifdef SOL_ATALK - PyModule_AddIntMacro(m, SOL_ATALK); + PyModule_AddIntConstant(m, "SOL_ATALK", SOL_ATALK); #endif #ifdef SOL_NETROM - PyModule_AddIntMacro(m, SOL_NETROM); + PyModule_AddIntConstant(m, "SOL_NETROM", SOL_NETROM); #endif #ifdef SOL_ROSE - PyModule_AddIntMacro(m, SOL_ROSE); + PyModule_AddIntConstant(m, "SOL_ROSE", SOL_ROSE); #endif #ifdef SOL_TCP - PyModule_AddIntMacro(m, SOL_TCP); + PyModule_AddIntConstant(m, "SOL_TCP", SOL_TCP); #else PyModule_AddIntConstant(m, "SOL_TCP", 6); #endif #ifdef SOL_UDP - PyModule_AddIntMacro(m, SOL_UDP); + PyModule_AddIntConstant(m, "SOL_UDP", SOL_UDP); #else PyModule_AddIntConstant(m, "SOL_UDP", 17); #endif #ifdef SOL_CAN_BASE - PyModule_AddIntMacro(m, SOL_CAN_BASE); + PyModule_AddIntConstant(m, "SOL_CAN_BASE", SOL_CAN_BASE); #endif #ifdef SOL_CAN_RAW - PyModule_AddIntMacro(m, SOL_CAN_RAW); - PyModule_AddIntMacro(m, CAN_RAW); + PyModule_AddIntConstant(m, "SOL_CAN_RAW", SOL_CAN_RAW); + PyModule_AddIntConstant(m, "CAN_RAW", CAN_RAW); #endif #ifdef HAVE_LINUX_CAN_H - PyModule_AddIntMacro(m, CAN_EFF_FLAG); - PyModule_AddIntMacro(m, CAN_RTR_FLAG); - PyModule_AddIntMacro(m, CAN_ERR_FLAG); - - PyModule_AddIntMacro(m, CAN_SFF_MASK); - PyModule_AddIntMacro(m, CAN_EFF_MASK); - PyModule_AddIntMacro(m, CAN_ERR_MASK); + PyModule_AddIntConstant(m, "CAN_EFF_FLAG", CAN_EFF_FLAG); + PyModule_AddIntConstant(m, "CAN_RTR_FLAG", CAN_RTR_FLAG); + PyModule_AddIntConstant(m, "CAN_ERR_FLAG", CAN_ERR_FLAG); + + PyModule_AddIntConstant(m, "CAN_SFF_MASK", CAN_SFF_MASK); + PyModule_AddIntConstant(m, "CAN_EFF_MASK", CAN_EFF_MASK); + PyModule_AddIntConstant(m, "CAN_ERR_MASK", CAN_ERR_MASK); #endif #ifdef HAVE_LINUX_CAN_RAW_H - PyModule_AddIntMacro(m, CAN_RAW_FILTER); - PyModule_AddIntMacro(m, CAN_RAW_ERR_FILTER); - PyModule_AddIntMacro(m, CAN_RAW_LOOPBACK); - PyModule_AddIntMacro(m, CAN_RAW_RECV_OWN_MSGS); -#endif -#ifdef HAVE_LINUX_CAN_BCM_H - PyModule_AddIntMacro(m, CAN_BCM); - PyModule_AddIntConstant(m, "CAN_BCM_TX_SETUP", TX_SETUP); - PyModule_AddIntConstant(m, "CAN_BCM_TX_DELETE", TX_DELETE); - PyModule_AddIntConstant(m, "CAN_BCM_TX_READ", TX_READ); - PyModule_AddIntConstant(m, "CAN_BCM_TX_SEND", TX_SEND); - PyModule_AddIntConstant(m, "CAN_BCM_RX_SETUP", RX_SETUP); - PyModule_AddIntConstant(m, "CAN_BCM_RX_DELETE", RX_DELETE); - PyModule_AddIntConstant(m, "CAN_BCM_RX_READ", RX_READ); - PyModule_AddIntConstant(m, "CAN_BCM_TX_STATUS", TX_STATUS); - PyModule_AddIntConstant(m, "CAN_BCM_TX_EXPIRED", TX_EXPIRED); - PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS); - PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT); - PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED); + PyModule_AddIntConstant(m, "CAN_RAW_FILTER", CAN_RAW_FILTER); + PyModule_AddIntConstant(m, "CAN_RAW_ERR_FILTER", CAN_RAW_ERR_FILTER); + PyModule_AddIntConstant(m, "CAN_RAW_LOOPBACK", CAN_RAW_LOOPBACK); + PyModule_AddIntConstant(m, "CAN_RAW_RECV_OWN_MSGS", CAN_RAW_RECV_OWN_MSGS); #endif #ifdef SOL_RDS - PyModule_AddIntMacro(m, SOL_RDS); + PyModule_AddIntConstant(m, "SOL_RDS", SOL_RDS); #endif #ifdef RDS_CANCEL_SENT_TO - PyModule_AddIntMacro(m, RDS_CANCEL_SENT_TO); + PyModule_AddIntConstant(m, "RDS_CANCEL_SENT_TO", RDS_CANCEL_SENT_TO); #endif #ifdef RDS_GET_MR - PyModule_AddIntMacro(m, RDS_GET_MR); + PyModule_AddIntConstant(m, "RDS_GET_MR", RDS_GET_MR); #endif #ifdef RDS_FREE_MR - PyModule_AddIntMacro(m, RDS_FREE_MR); + PyModule_AddIntConstant(m, "RDS_FREE_MR", RDS_FREE_MR); #endif #ifdef RDS_RECVERR - PyModule_AddIntMacro(m, RDS_RECVERR); + PyModule_AddIntConstant(m, "RDS_RECVERR", RDS_RECVERR); #endif #ifdef RDS_CONG_MONITOR - PyModule_AddIntMacro(m, RDS_CONG_MONITOR); + PyModule_AddIntConstant(m, "RDS_CONG_MONITOR", RDS_CONG_MONITOR); #endif #ifdef RDS_GET_MR_FOR_DEST - PyModule_AddIntMacro(m, RDS_GET_MR_FOR_DEST); + PyModule_AddIntConstant(m, "RDS_GET_MR_FOR_DEST", RDS_GET_MR_FOR_DEST); #endif #ifdef IPPROTO_IP - PyModule_AddIntMacro(m, IPPROTO_IP); + PyModule_AddIntConstant(m, "IPPROTO_IP", IPPROTO_IP); #else PyModule_AddIntConstant(m, "IPPROTO_IP", 0); #endif #ifdef IPPROTO_HOPOPTS - PyModule_AddIntMacro(m, IPPROTO_HOPOPTS); + PyModule_AddIntConstant(m, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS); #endif #ifdef IPPROTO_ICMP - PyModule_AddIntMacro(m, IPPROTO_ICMP); + PyModule_AddIntConstant(m, "IPPROTO_ICMP", IPPROTO_ICMP); #else PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1); #endif #ifdef IPPROTO_IGMP - PyModule_AddIntMacro(m, IPPROTO_IGMP); + PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP); #endif #ifdef IPPROTO_GGP - PyModule_AddIntMacro(m, IPPROTO_GGP); + PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP); #endif #ifdef IPPROTO_IPV4 - PyModule_AddIntMacro(m, IPPROTO_IPV4); + PyModule_AddIntConstant(m, "IPPROTO_IPV4", IPPROTO_IPV4); #endif #ifdef IPPROTO_IPV6 - PyModule_AddIntMacro(m, IPPROTO_IPV6); + PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); #endif #ifdef IPPROTO_IPIP - PyModule_AddIntMacro(m, IPPROTO_IPIP); + PyModule_AddIntConstant(m, "IPPROTO_IPIP", IPPROTO_IPIP); #endif #ifdef IPPROTO_TCP - PyModule_AddIntMacro(m, IPPROTO_TCP); + PyModule_AddIntConstant(m, "IPPROTO_TCP", IPPROTO_TCP); #else PyModule_AddIntConstant(m, "IPPROTO_TCP", 6); #endif #ifdef IPPROTO_EGP - PyModule_AddIntMacro(m, IPPROTO_EGP); + PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP); #endif #ifdef IPPROTO_PUP - PyModule_AddIntMacro(m, IPPROTO_PUP); + PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP); #endif #ifdef IPPROTO_UDP - PyModule_AddIntMacro(m, IPPROTO_UDP); + PyModule_AddIntConstant(m, "IPPROTO_UDP", IPPROTO_UDP); #else PyModule_AddIntConstant(m, "IPPROTO_UDP", 17); #endif #ifdef IPPROTO_IDP - PyModule_AddIntMacro(m, IPPROTO_IDP); + PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP); #endif #ifdef IPPROTO_HELLO - PyModule_AddIntMacro(m, IPPROTO_HELLO); + PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO); #endif #ifdef IPPROTO_ND - PyModule_AddIntMacro(m, IPPROTO_ND); + PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND); #endif #ifdef IPPROTO_TP - PyModule_AddIntMacro(m, IPPROTO_TP); + PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP); #endif #ifdef IPPROTO_IPV6 - PyModule_AddIntMacro(m, IPPROTO_IPV6); + PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); #endif #ifdef IPPROTO_ROUTING - PyModule_AddIntMacro(m, IPPROTO_ROUTING); + PyModule_AddIntConstant(m, "IPPROTO_ROUTING", IPPROTO_ROUTING); #endif #ifdef IPPROTO_FRAGMENT - PyModule_AddIntMacro(m, IPPROTO_FRAGMENT); + PyModule_AddIntConstant(m, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT); #endif #ifdef IPPROTO_RSVP - PyModule_AddIntMacro(m, IPPROTO_RSVP); + PyModule_AddIntConstant(m, "IPPROTO_RSVP", IPPROTO_RSVP); #endif #ifdef IPPROTO_GRE - PyModule_AddIntMacro(m, IPPROTO_GRE); + PyModule_AddIntConstant(m, "IPPROTO_GRE", IPPROTO_GRE); #endif #ifdef IPPROTO_ESP - PyModule_AddIntMacro(m, IPPROTO_ESP); + PyModule_AddIntConstant(m, "IPPROTO_ESP", IPPROTO_ESP); #endif #ifdef IPPROTO_AH - PyModule_AddIntMacro(m, IPPROTO_AH); + PyModule_AddIntConstant(m, "IPPROTO_AH", IPPROTO_AH); #endif #ifdef IPPROTO_MOBILE - PyModule_AddIntMacro(m, IPPROTO_MOBILE); + PyModule_AddIntConstant(m, "IPPROTO_MOBILE", IPPROTO_MOBILE); #endif #ifdef IPPROTO_ICMPV6 - PyModule_AddIntMacro(m, IPPROTO_ICMPV6); + PyModule_AddIntConstant(m, "IPPROTO_ICMPV6", IPPROTO_ICMPV6); #endif #ifdef IPPROTO_NONE - PyModule_AddIntMacro(m, IPPROTO_NONE); + PyModule_AddIntConstant(m, "IPPROTO_NONE", IPPROTO_NONE); #endif #ifdef IPPROTO_DSTOPTS - PyModule_AddIntMacro(m, IPPROTO_DSTOPTS); + PyModule_AddIntConstant(m, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS); #endif #ifdef IPPROTO_XTP - PyModule_AddIntMacro(m, IPPROTO_XTP); + PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP); #endif #ifdef IPPROTO_EON - PyModule_AddIntMacro(m, IPPROTO_EON); + PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON); #endif #ifdef IPPROTO_PIM - PyModule_AddIntMacro(m, IPPROTO_PIM); + PyModule_AddIntConstant(m, "IPPROTO_PIM", IPPROTO_PIM); #endif #ifdef IPPROTO_IPCOMP - PyModule_AddIntMacro(m, IPPROTO_IPCOMP); + PyModule_AddIntConstant(m, "IPPROTO_IPCOMP", IPPROTO_IPCOMP); #endif #ifdef IPPROTO_VRRP - PyModule_AddIntMacro(m, IPPROTO_VRRP); + PyModule_AddIntConstant(m, "IPPROTO_VRRP", IPPROTO_VRRP); #endif #ifdef IPPROTO_SCTP - PyModule_AddIntMacro(m, IPPROTO_SCTP); + PyModule_AddIntConstant(m, "IPPROTO_SCTP", IPPROTO_SCTP); #endif #ifdef IPPROTO_BIP - PyModule_AddIntMacro(m, IPPROTO_BIP); + PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP); #endif /**/ #ifdef IPPROTO_RAW - PyModule_AddIntMacro(m, IPPROTO_RAW); + PyModule_AddIntConstant(m, "IPPROTO_RAW", IPPROTO_RAW); #else PyModule_AddIntConstant(m, "IPPROTO_RAW", 255); #endif #ifdef IPPROTO_MAX - PyModule_AddIntMacro(m, IPPROTO_MAX); + PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); #endif #ifdef SYSPROTO_CONTROL - PyModule_AddIntMacro(m, SYSPROTO_CONTROL); + PyModule_AddIntConstant(m, "SYSPROTO_CONTROL", SYSPROTO_CONTROL); #endif /* Some port configuration */ #ifdef IPPORT_RESERVED - PyModule_AddIntMacro(m, IPPORT_RESERVED); + PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); #else PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024); #endif #ifdef IPPORT_USERRESERVED - PyModule_AddIntMacro(m, IPPORT_USERRESERVED); + PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); #else PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000); #endif /* Some reserved IP v.4 addresses */ #ifdef INADDR_ANY - PyModule_AddIntMacro(m, INADDR_ANY); + PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY); #else PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000); #endif #ifdef INADDR_BROADCAST - PyModule_AddIntMacro(m, INADDR_BROADCAST); + PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST); #else PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff); #endif #ifdef INADDR_LOOPBACK - PyModule_AddIntMacro(m, INADDR_LOOPBACK); + PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK); #else PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001); #endif #ifdef INADDR_UNSPEC_GROUP - PyModule_AddIntMacro(m, INADDR_UNSPEC_GROUP); + PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); #else PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000); #endif @@ -6268,353 +6359,356 @@ PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001); #endif #ifdef INADDR_MAX_LOCAL_GROUP - PyModule_AddIntMacro(m, INADDR_MAX_LOCAL_GROUP); + PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", + INADDR_MAX_LOCAL_GROUP); #else PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); #endif #ifdef INADDR_NONE - PyModule_AddIntMacro(m, INADDR_NONE); + PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE); #else PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff); #endif /* IPv4 [gs]etsockopt options */ #ifdef IP_OPTIONS - PyModule_AddIntMacro(m, IP_OPTIONS); + PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS); #endif #ifdef IP_HDRINCL - PyModule_AddIntMacro(m, IP_HDRINCL); + PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL); #endif #ifdef IP_TOS - PyModule_AddIntMacro(m, IP_TOS); + PyModule_AddIntConstant(m, "IP_TOS", IP_TOS); #endif #ifdef IP_TTL - PyModule_AddIntMacro(m, IP_TTL); + PyModule_AddIntConstant(m, "IP_TTL", IP_TTL); #endif #ifdef IP_RECVOPTS - PyModule_AddIntMacro(m, IP_RECVOPTS); + PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS); #endif #ifdef IP_RECVRETOPTS - PyModule_AddIntMacro(m, IP_RECVRETOPTS); + PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS); #endif #ifdef IP_RECVDSTADDR - PyModule_AddIntMacro(m, IP_RECVDSTADDR); + PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR); #endif #ifdef IP_RETOPTS - PyModule_AddIntMacro(m, IP_RETOPTS); + PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS); #endif #ifdef IP_MULTICAST_IF - PyModule_AddIntMacro(m, IP_MULTICAST_IF); + PyModule_AddIntConstant(m, "IP_MULTICAST_IF", IP_MULTICAST_IF); #endif #ifdef IP_MULTICAST_TTL - PyModule_AddIntMacro(m, IP_MULTICAST_TTL); + PyModule_AddIntConstant(m, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); #endif #ifdef IP_MULTICAST_LOOP - PyModule_AddIntMacro(m, IP_MULTICAST_LOOP); + PyModule_AddIntConstant(m, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); #endif #ifdef IP_ADD_MEMBERSHIP - PyModule_AddIntMacro(m, IP_ADD_MEMBERSHIP); + PyModule_AddIntConstant(m, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); #endif #ifdef IP_DROP_MEMBERSHIP - PyModule_AddIntMacro(m, IP_DROP_MEMBERSHIP); + PyModule_AddIntConstant(m, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); #endif #ifdef IP_DEFAULT_MULTICAST_TTL - PyModule_AddIntMacro(m, IP_DEFAULT_MULTICAST_TTL); + PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_TTL", + IP_DEFAULT_MULTICAST_TTL); #endif #ifdef IP_DEFAULT_MULTICAST_LOOP - PyModule_AddIntMacro(m, IP_DEFAULT_MULTICAST_LOOP); + PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_LOOP", + IP_DEFAULT_MULTICAST_LOOP); #endif #ifdef IP_MAX_MEMBERSHIPS - PyModule_AddIntMacro(m, IP_MAX_MEMBERSHIPS); + PyModule_AddIntConstant(m, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); #endif #ifdef IP_TRANSPARENT - PyModule_AddIntMacro(m, IP_TRANSPARENT); + PyModule_AddIntConstant(m, "IP_TRANSPARENT", IP_TRANSPARENT); #endif /* IPv6 [gs]etsockopt options, defined in RFC2553 */ #ifdef IPV6_JOIN_GROUP - PyModule_AddIntMacro(m, IPV6_JOIN_GROUP); + PyModule_AddIntConstant(m, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP); #endif #ifdef IPV6_LEAVE_GROUP - PyModule_AddIntMacro(m, IPV6_LEAVE_GROUP); + PyModule_AddIntConstant(m, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP); #endif #ifdef IPV6_MULTICAST_HOPS - PyModule_AddIntMacro(m, IPV6_MULTICAST_HOPS); + PyModule_AddIntConstant(m, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS); #endif #ifdef IPV6_MULTICAST_IF - PyModule_AddIntMacro(m, IPV6_MULTICAST_IF); + PyModule_AddIntConstant(m, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF); #endif #ifdef IPV6_MULTICAST_LOOP - PyModule_AddIntMacro(m, IPV6_MULTICAST_LOOP); + PyModule_AddIntConstant(m, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP); #endif #ifdef IPV6_UNICAST_HOPS - PyModule_AddIntMacro(m, IPV6_UNICAST_HOPS); + PyModule_AddIntConstant(m, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS); #endif /* Additional IPV6 socket options, defined in RFC 3493 */ #ifdef IPV6_V6ONLY - PyModule_AddIntMacro(m, IPV6_V6ONLY); + PyModule_AddIntConstant(m, "IPV6_V6ONLY", IPV6_V6ONLY); #endif /* Advanced IPV6 socket options, from RFC 3542 */ #ifdef IPV6_CHECKSUM - PyModule_AddIntMacro(m, IPV6_CHECKSUM); + PyModule_AddIntConstant(m, "IPV6_CHECKSUM", IPV6_CHECKSUM); #endif #ifdef IPV6_DONTFRAG - PyModule_AddIntMacro(m, IPV6_DONTFRAG); + PyModule_AddIntConstant(m, "IPV6_DONTFRAG", IPV6_DONTFRAG); #endif #ifdef IPV6_DSTOPTS - PyModule_AddIntMacro(m, IPV6_DSTOPTS); + PyModule_AddIntConstant(m, "IPV6_DSTOPTS", IPV6_DSTOPTS); #endif #ifdef IPV6_HOPLIMIT - PyModule_AddIntMacro(m, IPV6_HOPLIMIT); + PyModule_AddIntConstant(m, "IPV6_HOPLIMIT", IPV6_HOPLIMIT); #endif #ifdef IPV6_HOPOPTS - PyModule_AddIntMacro(m, IPV6_HOPOPTS); + PyModule_AddIntConstant(m, "IPV6_HOPOPTS", IPV6_HOPOPTS); #endif #ifdef IPV6_NEXTHOP - PyModule_AddIntMacro(m, IPV6_NEXTHOP); + PyModule_AddIntConstant(m, "IPV6_NEXTHOP", IPV6_NEXTHOP); #endif #ifdef IPV6_PATHMTU - PyModule_AddIntMacro(m, IPV6_PATHMTU); + PyModule_AddIntConstant(m, "IPV6_PATHMTU", IPV6_PATHMTU); #endif #ifdef IPV6_PKTINFO - PyModule_AddIntMacro(m, IPV6_PKTINFO); + PyModule_AddIntConstant(m, "IPV6_PKTINFO", IPV6_PKTINFO); #endif #ifdef IPV6_RECVDSTOPTS - PyModule_AddIntMacro(m, IPV6_RECVDSTOPTS); + PyModule_AddIntConstant(m, "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS); #endif #ifdef IPV6_RECVHOPLIMIT - PyModule_AddIntMacro(m, IPV6_RECVHOPLIMIT); + PyModule_AddIntConstant(m, "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT); #endif #ifdef IPV6_RECVHOPOPTS - PyModule_AddIntMacro(m, IPV6_RECVHOPOPTS); + PyModule_AddIntConstant(m, "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS); #endif #ifdef IPV6_RECVPKTINFO - PyModule_AddIntMacro(m, IPV6_RECVPKTINFO); + PyModule_AddIntConstant(m, "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO); #endif #ifdef IPV6_RECVRTHDR - PyModule_AddIntMacro(m, IPV6_RECVRTHDR); + PyModule_AddIntConstant(m, "IPV6_RECVRTHDR", IPV6_RECVRTHDR); #endif #ifdef IPV6_RECVTCLASS - PyModule_AddIntMacro(m, IPV6_RECVTCLASS); + PyModule_AddIntConstant(m, "IPV6_RECVTCLASS", IPV6_RECVTCLASS); #endif #ifdef IPV6_RTHDR - PyModule_AddIntMacro(m, IPV6_RTHDR); + PyModule_AddIntConstant(m, "IPV6_RTHDR", IPV6_RTHDR); #endif #ifdef IPV6_RTHDRDSTOPTS - PyModule_AddIntMacro(m, IPV6_RTHDRDSTOPTS); + PyModule_AddIntConstant(m, "IPV6_RTHDRDSTOPTS", IPV6_RTHDRDSTOPTS); #endif #ifdef IPV6_RTHDR_TYPE_0 - PyModule_AddIntMacro(m, IPV6_RTHDR_TYPE_0); + PyModule_AddIntConstant(m, "IPV6_RTHDR_TYPE_0", IPV6_RTHDR_TYPE_0); #endif #ifdef IPV6_RECVPATHMTU - PyModule_AddIntMacro(m, IPV6_RECVPATHMTU); + PyModule_AddIntConstant(m, "IPV6_RECVPATHMTU", IPV6_RECVPATHMTU); #endif #ifdef IPV6_TCLASS - PyModule_AddIntMacro(m, IPV6_TCLASS); + PyModule_AddIntConstant(m, "IPV6_TCLASS", IPV6_TCLASS); #endif #ifdef IPV6_USE_MIN_MTU - PyModule_AddIntMacro(m, IPV6_USE_MIN_MTU); + PyModule_AddIntConstant(m, "IPV6_USE_MIN_MTU", IPV6_USE_MIN_MTU); #endif /* TCP options */ #ifdef TCP_NODELAY - PyModule_AddIntMacro(m, TCP_NODELAY); + PyModule_AddIntConstant(m, "TCP_NODELAY", TCP_NODELAY); #endif #ifdef TCP_MAXSEG - PyModule_AddIntMacro(m, TCP_MAXSEG); + PyModule_AddIntConstant(m, "TCP_MAXSEG", TCP_MAXSEG); #endif #ifdef TCP_CORK - PyModule_AddIntMacro(m, TCP_CORK); + PyModule_AddIntConstant(m, "TCP_CORK", TCP_CORK); #endif #ifdef TCP_KEEPIDLE - PyModule_AddIntMacro(m, TCP_KEEPIDLE); + PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPIDLE); #endif #ifdef TCP_KEEPINTVL - PyModule_AddIntMacro(m, TCP_KEEPINTVL); + PyModule_AddIntConstant(m, "TCP_KEEPINTVL", TCP_KEEPINTVL); #endif #ifdef TCP_KEEPCNT - PyModule_AddIntMacro(m, TCP_KEEPCNT); + PyModule_AddIntConstant(m, "TCP_KEEPCNT", TCP_KEEPCNT); #endif #ifdef TCP_SYNCNT - PyModule_AddIntMacro(m, TCP_SYNCNT); + PyModule_AddIntConstant(m, "TCP_SYNCNT", TCP_SYNCNT); #endif #ifdef TCP_LINGER2 - PyModule_AddIntMacro(m, TCP_LINGER2); + PyModule_AddIntConstant(m, "TCP_LINGER2", TCP_LINGER2); #endif #ifdef TCP_DEFER_ACCEPT - PyModule_AddIntMacro(m, TCP_DEFER_ACCEPT); + PyModule_AddIntConstant(m, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); #endif #ifdef TCP_WINDOW_CLAMP - PyModule_AddIntMacro(m, TCP_WINDOW_CLAMP); + PyModule_AddIntConstant(m, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); #endif #ifdef TCP_INFO - PyModule_AddIntMacro(m, TCP_INFO); + PyModule_AddIntConstant(m, "TCP_INFO", TCP_INFO); #endif #ifdef TCP_QUICKACK - PyModule_AddIntMacro(m, TCP_QUICKACK); + PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK); #endif #ifdef TCP_FASTOPEN - PyModule_AddIntMacro(m, TCP_FASTOPEN); + PyModule_AddIntConstant(m, "TCP_FASTOPEN", TCP_FASTOPEN); #endif /* IPX options */ #ifdef IPX_TYPE - PyModule_AddIntMacro(m, IPX_TYPE); + PyModule_AddIntConstant(m, "IPX_TYPE", IPX_TYPE); #endif /* Reliable Datagram Sockets */ #ifdef RDS_CMSG_RDMA_ARGS - PyModule_AddIntMacro(m, RDS_CMSG_RDMA_ARGS); + PyModule_AddIntConstant(m, "RDS_CMSG_RDMA_ARGS", RDS_CMSG_RDMA_ARGS); #endif #ifdef RDS_CMSG_RDMA_DEST - PyModule_AddIntMacro(m, RDS_CMSG_RDMA_DEST); + PyModule_AddIntConstant(m, "RDS_CMSG_RDMA_DEST", RDS_CMSG_RDMA_DEST); #endif #ifdef RDS_CMSG_RDMA_MAP - PyModule_AddIntMacro(m, RDS_CMSG_RDMA_MAP); + PyModule_AddIntConstant(m, "RDS_CMSG_RDMA_MAP", RDS_CMSG_RDMA_MAP); #endif #ifdef RDS_CMSG_RDMA_STATUS - PyModule_AddIntMacro(m, RDS_CMSG_RDMA_STATUS); + PyModule_AddIntConstant(m, "RDS_CMSG_RDMA_STATUS", RDS_CMSG_RDMA_STATUS); #endif #ifdef RDS_CMSG_RDMA_UPDATE - PyModule_AddIntMacro(m, RDS_CMSG_RDMA_UPDATE); + PyModule_AddIntConstant(m, "RDS_CMSG_RDMA_UPDATE", RDS_CMSG_RDMA_UPDATE); #endif #ifdef RDS_RDMA_READWRITE - PyModule_AddIntMacro(m, RDS_RDMA_READWRITE); + PyModule_AddIntConstant(m, "RDS_RDMA_READWRITE", RDS_RDMA_READWRITE); #endif #ifdef RDS_RDMA_FENCE - PyModule_AddIntMacro(m, RDS_RDMA_FENCE); + PyModule_AddIntConstant(m, "RDS_RDMA_FENCE", RDS_RDMA_FENCE); #endif #ifdef RDS_RDMA_INVALIDATE - PyModule_AddIntMacro(m, RDS_RDMA_INVALIDATE); + PyModule_AddIntConstant(m, "RDS_RDMA_INVALIDATE", RDS_RDMA_INVALIDATE); #endif #ifdef RDS_RDMA_USE_ONCE - PyModule_AddIntMacro(m, RDS_RDMA_USE_ONCE); + PyModule_AddIntConstant(m, "RDS_RDMA_USE_ONCE", RDS_RDMA_USE_ONCE); #endif #ifdef RDS_RDMA_DONTWAIT - PyModule_AddIntMacro(m, RDS_RDMA_DONTWAIT); + PyModule_AddIntConstant(m, "RDS_RDMA_DONTWAIT", RDS_RDMA_DONTWAIT); #endif #ifdef RDS_RDMA_NOTIFY_ME - PyModule_AddIntMacro(m, RDS_RDMA_NOTIFY_ME); + PyModule_AddIntConstant(m, "RDS_RDMA_NOTIFY_ME", RDS_RDMA_NOTIFY_ME); #endif #ifdef RDS_RDMA_SILENT - PyModule_AddIntMacro(m, RDS_RDMA_SILENT); + PyModule_AddIntConstant(m, "RDS_RDMA_SILENT", RDS_RDMA_SILENT); #endif /* get{addr,name}info parameters */ #ifdef EAI_ADDRFAMILY - PyModule_AddIntMacro(m, EAI_ADDRFAMILY); + PyModule_AddIntConstant(m, "EAI_ADDRFAMILY", EAI_ADDRFAMILY); #endif #ifdef EAI_AGAIN - PyModule_AddIntMacro(m, EAI_AGAIN); + PyModule_AddIntConstant(m, "EAI_AGAIN", EAI_AGAIN); #endif #ifdef EAI_BADFLAGS - PyModule_AddIntMacro(m, EAI_BADFLAGS); + PyModule_AddIntConstant(m, "EAI_BADFLAGS", EAI_BADFLAGS); #endif #ifdef EAI_FAIL - PyModule_AddIntMacro(m, EAI_FAIL); + PyModule_AddIntConstant(m, "EAI_FAIL", EAI_FAIL); #endif #ifdef EAI_FAMILY - PyModule_AddIntMacro(m, EAI_FAMILY); + PyModule_AddIntConstant(m, "EAI_FAMILY", EAI_FAMILY); #endif #ifdef EAI_MEMORY - PyModule_AddIntMacro(m, EAI_MEMORY); + PyModule_AddIntConstant(m, "EAI_MEMORY", EAI_MEMORY); #endif #ifdef EAI_NODATA - PyModule_AddIntMacro(m, EAI_NODATA); + PyModule_AddIntConstant(m, "EAI_NODATA", EAI_NODATA); #endif #ifdef EAI_NONAME - PyModule_AddIntMacro(m, EAI_NONAME); + PyModule_AddIntConstant(m, "EAI_NONAME", EAI_NONAME); #endif #ifdef EAI_OVERFLOW - PyModule_AddIntMacro(m, EAI_OVERFLOW); + PyModule_AddIntConstant(m, "EAI_OVERFLOW", EAI_OVERFLOW); #endif #ifdef EAI_SERVICE - PyModule_AddIntMacro(m, EAI_SERVICE); + PyModule_AddIntConstant(m, "EAI_SERVICE", EAI_SERVICE); #endif #ifdef EAI_SOCKTYPE - PyModule_AddIntMacro(m, EAI_SOCKTYPE); + PyModule_AddIntConstant(m, "EAI_SOCKTYPE", EAI_SOCKTYPE); #endif #ifdef EAI_SYSTEM - PyModule_AddIntMacro(m, EAI_SYSTEM); + PyModule_AddIntConstant(m, "EAI_SYSTEM", EAI_SYSTEM); #endif #ifdef EAI_BADHINTS - PyModule_AddIntMacro(m, EAI_BADHINTS); + PyModule_AddIntConstant(m, "EAI_BADHINTS", EAI_BADHINTS); #endif #ifdef EAI_PROTOCOL - PyModule_AddIntMacro(m, EAI_PROTOCOL); + PyModule_AddIntConstant(m, "EAI_PROTOCOL", EAI_PROTOCOL); #endif #ifdef EAI_MAX - PyModule_AddIntMacro(m, EAI_MAX); + PyModule_AddIntConstant(m, "EAI_MAX", EAI_MAX); #endif #ifdef AI_PASSIVE - PyModule_AddIntMacro(m, AI_PASSIVE); + PyModule_AddIntConstant(m, "AI_PASSIVE", AI_PASSIVE); #endif #ifdef AI_CANONNAME - PyModule_AddIntMacro(m, AI_CANONNAME); + PyModule_AddIntConstant(m, "AI_CANONNAME", AI_CANONNAME); #endif #ifdef AI_NUMERICHOST - PyModule_AddIntMacro(m, AI_NUMERICHOST); + PyModule_AddIntConstant(m, "AI_NUMERICHOST", AI_NUMERICHOST); #endif #ifdef AI_NUMERICSERV - PyModule_AddIntMacro(m, AI_NUMERICSERV); + PyModule_AddIntConstant(m, "AI_NUMERICSERV", AI_NUMERICSERV); #endif #ifdef AI_MASK - PyModule_AddIntMacro(m, AI_MASK); + PyModule_AddIntConstant(m, "AI_MASK", AI_MASK); #endif #ifdef AI_ALL - PyModule_AddIntMacro(m, AI_ALL); + PyModule_AddIntConstant(m, "AI_ALL", AI_ALL); #endif #ifdef AI_V4MAPPED_CFG - PyModule_AddIntMacro(m, AI_V4MAPPED_CFG); + PyModule_AddIntConstant(m, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG); #endif #ifdef AI_ADDRCONFIG - PyModule_AddIntMacro(m, AI_ADDRCONFIG); + PyModule_AddIntConstant(m, "AI_ADDRCONFIG", AI_ADDRCONFIG); #endif #ifdef AI_V4MAPPED - PyModule_AddIntMacro(m, AI_V4MAPPED); + PyModule_AddIntConstant(m, "AI_V4MAPPED", AI_V4MAPPED); #endif #ifdef AI_DEFAULT - PyModule_AddIntMacro(m, AI_DEFAULT); + PyModule_AddIntConstant(m, "AI_DEFAULT", AI_DEFAULT); #endif #ifdef NI_MAXHOST - PyModule_AddIntMacro(m, NI_MAXHOST); + PyModule_AddIntConstant(m, "NI_MAXHOST", NI_MAXHOST); #endif #ifdef NI_MAXSERV - PyModule_AddIntMacro(m, NI_MAXSERV); + PyModule_AddIntConstant(m, "NI_MAXSERV", NI_MAXSERV); #endif #ifdef NI_NOFQDN - PyModule_AddIntMacro(m, NI_NOFQDN); + PyModule_AddIntConstant(m, "NI_NOFQDN", NI_NOFQDN); #endif #ifdef NI_NUMERICHOST - PyModule_AddIntMacro(m, NI_NUMERICHOST); + PyModule_AddIntConstant(m, "NI_NUMERICHOST", NI_NUMERICHOST); #endif #ifdef NI_NAMEREQD - PyModule_AddIntMacro(m, NI_NAMEREQD); + PyModule_AddIntConstant(m, "NI_NAMEREQD", NI_NAMEREQD); #endif #ifdef NI_NUMERICSERV - PyModule_AddIntMacro(m, NI_NUMERICSERV); + PyModule_AddIntConstant(m, "NI_NUMERICSERV", NI_NUMERICSERV); #endif #ifdef NI_DGRAM - PyModule_AddIntMacro(m, NI_DGRAM); + PyModule_AddIntConstant(m, "NI_DGRAM", NI_DGRAM); #endif /* shutdown() parameters */ #ifdef SHUT_RD - PyModule_AddIntMacro(m, SHUT_RD); + PyModule_AddIntConstant(m, "SHUT_RD", SHUT_RD); #elif defined(SD_RECEIVE) PyModule_AddIntConstant(m, "SHUT_RD", SD_RECEIVE); #else PyModule_AddIntConstant(m, "SHUT_RD", 0); #endif #ifdef SHUT_WR - PyModule_AddIntMacro(m, SHUT_WR); + PyModule_AddIntConstant(m, "SHUT_WR", SHUT_WR); #elif defined(SD_SEND) PyModule_AddIntConstant(m, "SHUT_WR", SD_SEND); #else PyModule_AddIntConstant(m, "SHUT_WR", 1); #endif #ifdef SHUT_RDWR - PyModule_AddIntMacro(m, SHUT_RDWR); + PyModule_AddIntConstant(m, "SHUT_RDWR", SHUT_RDWR); #elif defined(SD_BOTH) PyModule_AddIntConstant(m, "SHUT_RDWR", SD_BOTH); #else @@ -6634,14 +6728,14 @@ PyModule_AddObject(m, names[i], tmp); } } - PyModule_AddIntMacro(m, RCVALL_OFF); - PyModule_AddIntMacro(m, RCVALL_ON); - PyModule_AddIntMacro(m, RCVALL_SOCKETLEVELONLY); + PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF); + PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON); + PyModule_AddIntConstant(m, "RCVALL_SOCKETLEVELONLY", RCVALL_SOCKETLEVELONLY); #ifdef RCVALL_IPLEVEL - PyModule_AddIntMacro(m, RCVALL_IPLEVEL); + PyModule_AddIntConstant(m, "RCVALL_IPLEVEL", RCVALL_IPLEVEL); #endif #ifdef RCVALL_MAX - PyModule_AddIntMacro(m, RCVALL_MAX); + PyModule_AddIntConstant(m, "RCVALL_MAX", RCVALL_MAX); #endif #endif /* _MSTCPIP_ */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/socketmodule.h --- a/Modules/socketmodule.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/socketmodule.h Fri Feb 01 23:12:09 2013 +0100 @@ -80,10 +80,6 @@ #include #endif -#ifdef HAVE_LINUX_CAN_BCM_H -#include -#endif - #ifdef HAVE_SYS_SYS_DOMAIN_H #include #endif diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/spwdmodule.c --- a/Modules/spwdmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/spwdmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -196,11 +196,9 @@ m=PyModule_Create(&spwdmodule); if (m == NULL) return NULL; - if (!initialized) { - if (PyStructSequence_InitType2(&StructSpwdType, - &struct_spwd_type_desc) < 0) - return NULL; - } + if (!initialized) + PyStructSequence_InitType(&StructSpwdType, + &struct_spwd_type_desc); Py_INCREF((PyObject *) &StructSpwdType); PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType); initialized = 1; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/sre.h --- a/Modules/sre.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/sre.h Fri Feb 01 23:12:09 2013 +0100 @@ -16,11 +16,6 @@ /* size of a code word (must be unsigned short or larger, and large enough to hold a UCS4 character) */ #define SRE_CODE Py_UCS4 -#if SIZEOF_SIZE_T > 4 -# define SRE_MAXREPEAT (~(SRE_CODE)0) -#else -# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u) -#endif typedef struct { PyObject_VAR_HEAD diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/symtablemodule.c --- a/Modules/symtablemodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/symtablemodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -69,30 +69,30 @@ m = PyModule_Create(&symtablemodule); if (m == NULL) return NULL; - PyModule_AddIntMacro(m, USE); - PyModule_AddIntMacro(m, DEF_GLOBAL); - PyModule_AddIntMacro(m, DEF_LOCAL); - PyModule_AddIntMacro(m, DEF_PARAM); - PyModule_AddIntMacro(m, DEF_FREE); - PyModule_AddIntMacro(m, DEF_FREE_CLASS); - PyModule_AddIntMacro(m, DEF_IMPORT); - PyModule_AddIntMacro(m, DEF_BOUND); + PyModule_AddIntConstant(m, "USE", USE); + PyModule_AddIntConstant(m, "DEF_GLOBAL", DEF_GLOBAL); + PyModule_AddIntConstant(m, "DEF_LOCAL", DEF_LOCAL); + PyModule_AddIntConstant(m, "DEF_PARAM", DEF_PARAM); + PyModule_AddIntConstant(m, "DEF_FREE", DEF_FREE); + PyModule_AddIntConstant(m, "DEF_FREE_CLASS", DEF_FREE_CLASS); + PyModule_AddIntConstant(m, "DEF_IMPORT", DEF_IMPORT); + PyModule_AddIntConstant(m, "DEF_BOUND", DEF_BOUND); PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock); PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock); PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock); - PyModule_AddIntMacro(m, OPT_IMPORT_STAR); - PyModule_AddIntMacro(m, OPT_TOPLEVEL); + PyModule_AddIntConstant(m, "OPT_IMPORT_STAR", OPT_IMPORT_STAR); + PyModule_AddIntConstant(m, "OPT_TOPLEVEL", OPT_TOPLEVEL); - PyModule_AddIntMacro(m, LOCAL); - PyModule_AddIntMacro(m, GLOBAL_EXPLICIT); - PyModule_AddIntMacro(m, GLOBAL_IMPLICIT); - PyModule_AddIntMacro(m, FREE); - PyModule_AddIntMacro(m, CELL); + PyModule_AddIntConstant(m, "LOCAL", LOCAL); + PyModule_AddIntConstant(m, "GLOBAL_EXPLICIT", GLOBAL_EXPLICIT); + PyModule_AddIntConstant(m, "GLOBAL_IMPLICIT", GLOBAL_IMPLICIT); + PyModule_AddIntConstant(m, "FREE", FREE); + PyModule_AddIntConstant(m, "CELL", CELL); PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFFSET); - PyModule_AddIntMacro(m, SCOPE_MASK); + PyModule_AddIntConstant(m, "SCOPE_MASK", SCOPE_MASK); if (PyErr_Occurred()) { Py_DECREF(m); diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/syslogmodule.c --- a/Modules/syslogmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/syslogmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -278,44 +278,44 @@ /* Add some symbolic constants to the module */ /* Priorities */ - PyModule_AddIntMacro(m, LOG_EMERG); - PyModule_AddIntMacro(m, LOG_ALERT); - PyModule_AddIntMacro(m, LOG_CRIT); - PyModule_AddIntMacro(m, LOG_ERR); - PyModule_AddIntMacro(m, LOG_WARNING); - PyModule_AddIntMacro(m, LOG_NOTICE); - PyModule_AddIntMacro(m, LOG_INFO); - PyModule_AddIntMacro(m, LOG_DEBUG); + PyModule_AddIntConstant(m, "LOG_EMERG", LOG_EMERG); + PyModule_AddIntConstant(m, "LOG_ALERT", LOG_ALERT); + PyModule_AddIntConstant(m, "LOG_CRIT", LOG_CRIT); + PyModule_AddIntConstant(m, "LOG_ERR", LOG_ERR); + PyModule_AddIntConstant(m, "LOG_WARNING", LOG_WARNING); + PyModule_AddIntConstant(m, "LOG_NOTICE", LOG_NOTICE); + PyModule_AddIntConstant(m, "LOG_INFO", LOG_INFO); + PyModule_AddIntConstant(m, "LOG_DEBUG", LOG_DEBUG); /* openlog() option flags */ - PyModule_AddIntMacro(m, LOG_PID); - PyModule_AddIntMacro(m, LOG_CONS); - PyModule_AddIntMacro(m, LOG_NDELAY); + PyModule_AddIntConstant(m, "LOG_PID", LOG_PID); + PyModule_AddIntConstant(m, "LOG_CONS", LOG_CONS); + PyModule_AddIntConstant(m, "LOG_NDELAY", LOG_NDELAY); #ifdef LOG_ODELAY - PyModule_AddIntMacro(m, LOG_ODELAY); + PyModule_AddIntConstant(m, "LOG_ODELAY", LOG_ODELAY); #endif #ifdef LOG_NOWAIT - PyModule_AddIntMacro(m, LOG_NOWAIT); + PyModule_AddIntConstant(m, "LOG_NOWAIT", LOG_NOWAIT); #endif #ifdef LOG_PERROR - PyModule_AddIntMacro(m, LOG_PERROR); + PyModule_AddIntConstant(m, "LOG_PERROR", LOG_PERROR); #endif /* Facilities */ - PyModule_AddIntMacro(m, LOG_KERN); - PyModule_AddIntMacro(m, LOG_USER); - PyModule_AddIntMacro(m, LOG_MAIL); - PyModule_AddIntMacro(m, LOG_DAEMON); - PyModule_AddIntMacro(m, LOG_AUTH); - PyModule_AddIntMacro(m, LOG_LPR); - PyModule_AddIntMacro(m, LOG_LOCAL0); - PyModule_AddIntMacro(m, LOG_LOCAL1); - PyModule_AddIntMacro(m, LOG_LOCAL2); - PyModule_AddIntMacro(m, LOG_LOCAL3); - PyModule_AddIntMacro(m, LOG_LOCAL4); - PyModule_AddIntMacro(m, LOG_LOCAL5); - PyModule_AddIntMacro(m, LOG_LOCAL6); - PyModule_AddIntMacro(m, LOG_LOCAL7); + PyModule_AddIntConstant(m, "LOG_KERN", LOG_KERN); + PyModule_AddIntConstant(m, "LOG_USER", LOG_USER); + PyModule_AddIntConstant(m, "LOG_MAIL", LOG_MAIL); + PyModule_AddIntConstant(m, "LOG_DAEMON", LOG_DAEMON); + PyModule_AddIntConstant(m, "LOG_AUTH", LOG_AUTH); + PyModule_AddIntConstant(m, "LOG_LPR", LOG_LPR); + PyModule_AddIntConstant(m, "LOG_LOCAL0", LOG_LOCAL0); + PyModule_AddIntConstant(m, "LOG_LOCAL1", LOG_LOCAL1); + PyModule_AddIntConstant(m, "LOG_LOCAL2", LOG_LOCAL2); + PyModule_AddIntConstant(m, "LOG_LOCAL3", LOG_LOCAL3); + PyModule_AddIntConstant(m, "LOG_LOCAL4", LOG_LOCAL4); + PyModule_AddIntConstant(m, "LOG_LOCAL5", LOG_LOCAL5); + PyModule_AddIntConstant(m, "LOG_LOCAL6", LOG_LOCAL6); + PyModule_AddIntConstant(m, "LOG_LOCAL7", LOG_LOCAL7); #ifndef LOG_SYSLOG #define LOG_SYSLOG LOG_DAEMON @@ -330,13 +330,13 @@ #define LOG_CRON LOG_DAEMON #endif - PyModule_AddIntMacro(m, LOG_SYSLOG); - PyModule_AddIntMacro(m, LOG_CRON); - PyModule_AddIntMacro(m, LOG_UUCP); - PyModule_AddIntMacro(m, LOG_NEWS); + PyModule_AddIntConstant(m, "LOG_SYSLOG", LOG_SYSLOG); + PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON); + PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP); + PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS); #ifdef LOG_AUTHPRIV - PyModule_AddIntMacro(m, LOG_AUTHPRIV); + PyModule_AddIntConstant(m, "LOG_AUTHPRIV", LOG_AUTHPRIV); #endif return m; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/timemodule.c --- a/Modules/timemodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/timemodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -185,18 +185,14 @@ { int clk_id; PyObject *obj; - time_t tv_sec; - long tv_nsec; struct timespec tp; int ret; if (!PyArg_ParseTuple(args, "iO:clock_settime", &clk_id, &obj)) return NULL; - if (_PyTime_ObjectToTimespec(obj, &tv_sec, &tv_nsec) == -1) + if (_PyTime_ObjectToTimespec(obj, &tp.tv_sec, &tp.tv_nsec) == -1) return NULL; - tp.tv_sec = tv_sec; - tp.tv_nsec = tv_nsec; ret = clock_settime((clockid_t)clk_id, &tp); if (ret != 0) { @@ -598,7 +594,7 @@ else if (!gettmarg(tup, &buf) || !checktm(&buf)) return NULL; -#if defined(_MSC_VER) || defined(sun) || defined(_AIX) +#if defined(_MSC_VER) || defined(sun) if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) { PyErr_SetString(PyExc_ValueError, "strftime() requires year in [1; 9999]"); @@ -807,16 +803,7 @@ tt = mktime(&buf); /* Return value of -1 does not necessarily mean an error, but tm_wday * cannot remain set to -1 if mktime succeeded. */ - if (tt == (time_t)(-1) -#ifndef _AIX - /* Return value of -1 does not necessarily mean an error, but - * tm_wday cannot remain set to -1 if mktime succeeded. */ - && buf.tm_wday == -1 -#else - /* on AIX, tm_wday is always sets, even on error */ -#endif - ) - { + if (tt == (time_t)(-1) && buf.tm_wday == -1) { PyErr_SetString(PyExc_OverflowError, "mktime argument out of range"); return NULL; @@ -851,8 +838,6 @@ /* Reset timezone, altzone, daylight and tzname */ PyInit_timezone(m); Py_DECREF(m); - if (PyErr_Occurred()) - return NULL; Py_INCREF(Py_None); return Py_None; @@ -1476,9 +1461,8 @@ PyInit_timezone(m); if (!initialized) { - if (PyStructSequence_InitType2(&StructTimeType, - &struct_time_type_desc) < 0) - return NULL; + PyStructSequence_InitType(&StructTimeType, + &struct_time_type_desc); #ifdef MS_WINDOWS winver.dwOSVersionInfoSize = sizeof(winver); @@ -1590,7 +1574,7 @@ DWORD rc; HANDLE hInterruptEvent = _PyOS_SigintEvent(); ResetEvent(hInterruptEvent); - rc = WaitForSingleObjectEx(hInterruptEvent, ul_millis, FALSE); + rc = WaitForSingleObject(hInterruptEvent, ul_millis); if (rc == WAIT_OBJECT_0) { Py_BLOCK_THREADS errno = EINTR; diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/zipimport.c --- a/Modules/zipimport.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/zipimport.c Fri Feb 01 23:12:09 2013 +0100 @@ -862,7 +862,6 @@ long l, count; Py_ssize_t i; char name[MAXPATHLEN + 5]; - char dummy[8]; /* Buffer to read unused header values into */ PyObject *nameobj = NULL; char *p, endof_central_dir[22]; Py_ssize_t arc_offset; /* Absolute offset to start of the zip-archive. */ @@ -906,23 +905,17 @@ /* Start of Central Directory */ count = 0; - if (fseek(fp, header_offset, 0) == -1) - goto file_error; for (;;) { PyObject *t; int err; - /* Start of file header */ + if (fseek(fp, header_offset, 0) == -1) /* Start of file header */ + goto fseek_error; l = PyMarshal_ReadLongFromFile(fp); if (l != 0x02014B50) break; /* Bad: Central Dir File Header */ - - /* On Windows, calling fseek to skip over the fields we don't use is - slower than reading the data into a dummy buffer because fseek flushes - stdio's internal buffers. See issue #8745. */ - if (fread(dummy, 1, 4, fp) != 4) /* Skip unused fields, avoid fseek */ - goto file_error; - + if (fseek(fp, header_offset + 8, 0) == -1) + goto fseek_error; flags = (unsigned short)PyMarshal_ReadShortFromFile(fp); compress = PyMarshal_ReadShortFromFile(fp); time = PyMarshal_ReadShortFromFile(fp); @@ -931,11 +924,11 @@ data_size = PyMarshal_ReadLongFromFile(fp); file_size = PyMarshal_ReadLongFromFile(fp); name_size = PyMarshal_ReadShortFromFile(fp); - header_size = name_size + + header_size = 46 + name_size + PyMarshal_ReadShortFromFile(fp) + PyMarshal_ReadShortFromFile(fp); - if (fread(dummy, 1, 8, fp) != 8) /* Skip unused fields, avoid fseek */ - goto file_error; + if (fseek(fp, header_offset + 42, 0) == -1) + goto fseek_error; file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset; if (name_size > MAXPATHLEN) name_size = MAXPATHLEN; @@ -948,9 +941,7 @@ p++; } *p = 0; /* Add terminating null byte */ - for (; i < header_size; i++) /* Skip the rest of the header */ - if(getc(fp) == EOF) /* Avoid fseek */ - goto file_error; + header_offset += header_size; bootstrap = 0; if (flags & 0x0800) @@ -997,7 +988,7 @@ PySys_FormatStderr("# zipimport: found %ld names in %R\n", count, archive); return files; -file_error: +fseek_error: fclose(fp); Py_XDECREF(files); Py_XDECREF(nameobj); @@ -1258,7 +1249,7 @@ } /* Given a string buffer containing Python source code, compile it - and return a code object as a new reference. */ + return and return a code object as a new reference. */ static PyObject * compile_source(PyObject *pathname, PyObject *source) { diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/zlib/deflate.c --- a/Modules/zlib/deflate.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/zlib/deflate.c Fri Feb 01 23:12:09 2013 +0100 @@ -157,7 +157,7 @@ /* =========================================================================== * Update a hash value with the given input byte - * IN assertion: all calls to UPDATE_HASH are made with consecutive + * IN assertion: all calls to to UPDATE_HASH are made with consecutive * input characters, so that a running hash key can be computed from the * previous key instead of complete recalculation each time. */ @@ -170,7 +170,7 @@ * the previous length of the hash chain. * If this file is compiled with -DFASTEST, the compression level is forced * to 1, and no hash chains are maintained. - * IN assertion: all calls to INSERT_STRING are made with consecutive + * IN assertion: all calls to to INSERT_STRING are made with consecutive * input characters and the first MIN_MATCH bytes of str are valid * (except for the last MIN_MATCH-1 bytes of the input file). */ diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/zlib/inftrees.h --- a/Modules/zlib/inftrees.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/zlib/inftrees.h Fri Feb 01 23:12:09 2013 +0100 @@ -41,7 +41,7 @@ examples/enough.c found in the zlib distribtution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns 852, and "enough 30 6 15" for distance codes returns 592. + returns returns 852, and "enough 30 6 15" for distance codes returns 592. The initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in inflate.c and infback.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/zlib/zlib.h --- a/Modules/zlib/zlib.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/zlib/zlib.h Fri Feb 01 23:12:09 2013 +0100 @@ -812,7 +812,7 @@ inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the - success case, the application may save the current value of total_in + success case, the application may save the current current value of total_in which indicates where valid compressed data was found. In the error case, the application may repeatedly call inflateSync, providing more input each time, until success or end of the input data. diff -r 35c88c53cf64 -r ecc10f0afb76 Modules/zlibmodule.c --- a/Modules/zlibmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Modules/zlibmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -132,30 +132,10 @@ } #ifdef WITH_THREAD self->lock = PyThread_allocate_lock(); - if (self->lock == NULL) { - PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock"); - return NULL; - } #endif return self; } -static void* -PyZlib_Malloc(voidpf ctx, uInt items, uInt size) -{ - if (items > (size_t)PY_SSIZE_T_MAX / size) - return NULL; - /* PyMem_Malloc() cannot be used: the GIL is not held when - inflate() and deflate() are called */ - return PyMem_RawMalloc(items * size); -} - -static void -PyZlib_Free(voidpf ctx, void *ptr) -{ - PyMem_RawFree(ptr); -} - PyDoc_STRVAR(compress__doc__, "compress(string[, level]) -- Returned compressed string.\n" "\n" @@ -185,7 +165,7 @@ zst.avail_out = length + length/1000 + 12 + 1; - output = (Byte*)PyMem_Malloc(zst.avail_out); + output = (Byte*)malloc(zst.avail_out); if (output == NULL) { PyErr_SetString(PyExc_MemoryError, "Can't allocate memory to compress data"); @@ -195,9 +175,8 @@ /* Past the point of no return. From here on out, we need to make sure we clean up mallocs & INCREFs. */ - zst.opaque = NULL; - zst.zalloc = PyZlib_Malloc; - zst.zfree = PyZlib_Free; + 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; @@ -239,7 +218,7 @@ error: PyBuffer_Release(&pinput); - PyMem_Free(output); + free(output); return ReturnVal; } @@ -283,9 +262,8 @@ if (!(result_str = PyBytes_FromStringAndSize(NULL, r_strlen))) goto error; - zst.opaque = NULL; - zst.zalloc = PyZlib_Malloc; - zst.zfree = PyZlib_Free; + zst.zalloc = (alloc_func)NULL; + zst.zfree = (free_func)Z_NULL; zst.next_out = (Byte *)PyBytes_AS_STRING(result_str); zst.next_in = (Byte *)input; err = inflateInit2(&zst, wsize); @@ -378,9 +356,8 @@ self = newcompobject(&Comptype); if (self==NULL) goto error; - self->zst.opaque = NULL; - self->zst.zalloc = PyZlib_Malloc; - self->zst.zfree = PyZlib_Free; + 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); @@ -443,9 +420,8 @@ self = newcompobject(&Decomptype); if (self == NULL) return(NULL); - self->zst.opaque = NULL; - self->zst.zalloc = PyZlib_Malloc; - self->zst.zfree = PyZlib_Free; + self->zst.zalloc = (alloc_func)NULL; + self->zst.zfree = (free_func)Z_NULL; self->zst.next_in = NULL; self->zst.avail_in = 0; if (zdict != NULL) { @@ -549,7 +525,8 @@ so extend the output buffer and try again */ while (err == Z_OK && self->zst.avail_out == 0) { if (_PyBytes_Resize(&RetVal, length << 1) < 0) { - Py_CLEAR(RetVal); + Py_DECREF(RetVal); + RetVal = NULL; goto error; } self->zst.next_out = @@ -573,7 +550,8 @@ goto error; } if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) { - Py_CLEAR(RetVal); + Py_DECREF(RetVal); + RetVal = NULL; } error: @@ -595,7 +573,7 @@ Py_ssize_t old_size = PyBytes_GET_SIZE(self->unused_data); Py_ssize_t new_size; PyObject *new_data; - if ((Py_ssize_t)self->zst.avail_in > PY_SSIZE_T_MAX - old_size) { + if (self->zst.avail_in > PY_SSIZE_T_MAX - old_size) { PyErr_NoMemory(); return -1; } @@ -720,7 +698,8 @@ length = max_length; if (_PyBytes_Resize(&RetVal, length) < 0) { - Py_CLEAR(RetVal); + Py_DECREF(RetVal); + RetVal = NULL; goto error; } self->zst.next_out = @@ -754,7 +733,8 @@ } if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) { - Py_CLEAR(RetVal); + Py_DECREF(RetVal); + RetVal = NULL; } error: @@ -807,7 +787,8 @@ so extend the output buffer and try again */ while (err == Z_OK && self->zst.avail_out == 0) { if (_PyBytes_Resize(&RetVal, length << 1) < 0) { - Py_CLEAR(RetVal); + Py_DECREF(RetVal); + RetVal = NULL; goto error; } self->zst.next_out = @@ -846,7 +827,8 @@ } if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) { - Py_CLEAR(RetVal); + Py_DECREF(RetVal); + RetVal = NULL; } error: @@ -1006,7 +988,8 @@ so extend the output buffer and try again */ while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) { if (_PyBytes_Resize(&retval, length << 1) < 0) { - Py_CLEAR(retval); + Py_DECREF(retval); + retval = NULL; goto error; } self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval) + length; @@ -1038,7 +1021,8 @@ } if (_PyBytes_Resize(&retval, self->zst.total_out - start_total_out) < 0) { - Py_CLEAR(retval); + Py_DECREF(retval); + retval = NULL; } error: @@ -1110,10 +1094,10 @@ buf += (size_t) UINT_MAX; len -= (size_t) UINT_MAX; } - adler32val = adler32(adler32val, buf, (unsigned int)len); + adler32val = adler32(adler32val, buf, len); Py_END_ALLOW_THREADS } else { - adler32val = adler32(adler32val, pbuf.buf, (unsigned int)pbuf.len); + adler32val = adler32(adler32val, pbuf.buf, pbuf.len); } PyBuffer_Release(&pbuf); return PyLong_FromUnsignedLong(adler32val & 0xffffffffU); @@ -1148,10 +1132,10 @@ buf += (size_t) UINT_MAX; len -= (size_t) UINT_MAX; } - signed_val = crc32(crc32val, buf, (unsigned int)len); + signed_val = crc32(crc32val, buf, len); Py_END_ALLOW_THREADS } else { - signed_val = crc32(crc32val, pbuf.buf, (unsigned int)pbuf.len); + signed_val = crc32(crc32val, pbuf.buf, pbuf.len); } PyBuffer_Release(&pbuf); return PyLong_FromUnsignedLong(signed_val & 0xffffffffU); @@ -1282,20 +1266,20 @@ Py_INCREF(ZlibError); PyModule_AddObject(m, "error", ZlibError); } - PyModule_AddIntMacro(m, MAX_WBITS); - PyModule_AddIntMacro(m, DEFLATED); - PyModule_AddIntMacro(m, DEF_MEM_LEVEL); - PyModule_AddIntMacro(m, Z_BEST_SPEED); - PyModule_AddIntMacro(m, Z_BEST_COMPRESSION); - PyModule_AddIntMacro(m, Z_DEFAULT_COMPRESSION); - PyModule_AddIntMacro(m, Z_FILTERED); - PyModule_AddIntMacro(m, Z_HUFFMAN_ONLY); - PyModule_AddIntMacro(m, Z_DEFAULT_STRATEGY); + PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS); + PyModule_AddIntConstant(m, "DEFLATED", DEFLATED); + PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL); + PyModule_AddIntConstant(m, "Z_BEST_SPEED", Z_BEST_SPEED); + PyModule_AddIntConstant(m, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION); + PyModule_AddIntConstant(m, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION); + PyModule_AddIntConstant(m, "Z_FILTERED", Z_FILTERED); + PyModule_AddIntConstant(m, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY); + PyModule_AddIntConstant(m, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY); - PyModule_AddIntMacro(m, Z_FINISH); - PyModule_AddIntMacro(m, Z_NO_FLUSH); - PyModule_AddIntMacro(m, Z_SYNC_FLUSH); - PyModule_AddIntMacro(m, Z_FULL_FLUSH); + PyModule_AddIntConstant(m, "Z_FINISH", Z_FINISH); + PyModule_AddIntConstant(m, "Z_NO_FLUSH", Z_NO_FLUSH); + PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH); + PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH); ver = PyUnicode_FromString(ZLIB_VERSION); if (ver != NULL) diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/abstract.c --- a/Objects/abstract.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/abstract.c Fri Feb 01 23:12:09 2013 +0100 @@ -1238,7 +1238,7 @@ to be an int or have an __int__ method. Steals integral's reference. error_format will be used to create the TypeError if integral isn't actually an Integral instance. error_format should be a format string - that can accept a char* naming integral's type. + that can accept a char* naming integral's type. */ static PyObject * convert_integral_to_int(PyObject *integral, const char *error_format) @@ -1257,7 +1257,7 @@ } PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name); Py_DECREF(integral); - return NULL; + return NULL; } @@ -1314,8 +1314,6 @@ PyObject *truncated = PyEval_CallObject(trunc_func, NULL); PyObject *int_instance; Py_DECREF(trunc_func); - if (truncated == NULL) - return NULL; /* __trunc__ is specified to return an Integral type, but int() needs to return a int. */ int_instance = convert_integral_to_int(truncated, @@ -2104,15 +2102,10 @@ return NULL; result = (*call)(func, arg, kw); Py_LeaveRecursiveCall(); -#ifdef NDEBUG - if (result == NULL && !PyErr_Occurred()) { + if (result == NULL && !PyErr_Occurred()) PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); - } -#else - assert(result != NULL || PyErr_Occurred()); -#endif return result; } PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable", @@ -2147,7 +2140,7 @@ } PyObject * -PyObject_CallFunction(PyObject *callable, const char *format, ...) +PyObject_CallFunction(PyObject *callable, char *format, ...) { va_list va; PyObject *args; @@ -2167,7 +2160,7 @@ } PyObject * -_PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) +_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...) { va_list va; PyObject *args; @@ -2187,7 +2180,7 @@ } static PyObject* -callmethod(PyObject* func, const char *format, va_list va, int is_size_t) +callmethod(PyObject* func, char *format, va_list va, int is_size_t) { PyObject *retval = NULL; PyObject *args; @@ -2216,7 +2209,7 @@ } PyObject * -PyObject_CallMethod(PyObject *o, const char *name, const char *format, ...) +PyObject_CallMethod(PyObject *o, char *name, char *format, ...) { va_list va; PyObject *func = NULL; @@ -2237,8 +2230,7 @@ } PyObject * -_PyObject_CallMethodId(PyObject *o, _Py_Identifier *name, - const char *format, ...) +_PyObject_CallMethodId(PyObject *o, _Py_Identifier *name, char *format, ...) { va_list va; PyObject *func = NULL; @@ -2259,8 +2251,7 @@ } PyObject * -_PyObject_CallMethod_SizeT(PyObject *o, const char *name, - const char *format, ...) +_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...) { va_list va; PyObject *func = NULL; @@ -2280,8 +2271,7 @@ } PyObject * -_PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, - const char *format, ...) +_PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, char *format, ...) { va_list va; PyObject *func = NULL; @@ -2351,7 +2341,7 @@ } PyObject * -_PyObject_CallMethodIdObjArgs(PyObject *callable, +_PyObject_CallMethodObjIdArgs(PyObject *callable, struct _Py_Identifier *name, ...) { PyObject *args, *tmp; @@ -2726,8 +2716,8 @@ * NULL terminated string pointers with a NULL char* terminating the array. * (ie: an argv or env list) * - * Memory allocated for the returned list is allocated using PyMem_Malloc() - * and MUST be freed by _Py_FreeCharPArray(). + * Memory allocated for the returned list is allocated using malloc() and MUST + * be freed by the caller using a free() loop or _Py_FreeCharPArray(). */ char *const * _PySequence_BytesToCharpArray(PyObject* self) @@ -2735,7 +2725,6 @@ char **array; Py_ssize_t i, argc; PyObject *item = NULL; - Py_ssize_t size; argc = PySequence_Size(self); if (argc == -1) @@ -2748,7 +2737,7 @@ return NULL; } - array = PyMem_Malloc((argc + 1) * sizeof(char *)); + array = malloc((argc + 1) * sizeof(char *)); if (array == NULL) { PyErr_NoMemory(); return NULL; @@ -2767,13 +2756,11 @@ array[i] = NULL; goto fail; } - size = PyBytes_GET_SIZE(item) + 1; - array[i] = PyMem_Malloc(size); + array[i] = strdup(data); if (!array[i]) { PyErr_NoMemory(); goto fail; } - memcpy(array[i], data, size); Py_DECREF(item); } array[argc] = NULL; @@ -2793,7 +2780,7 @@ { Py_ssize_t i; for (i = 0; array[i] != NULL; ++i) { - PyMem_Free(array[i]); + free(array[i]); } - PyMem_Free((void*)array); + free((void*)array); } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/bytearrayobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -1508,10 +1508,7 @@ } /* Fix the size of the resulting string */ if (inlen > 0) - if (PyByteArray_Resize(result, output - output_start) < 0) { - Py_CLEAR(result); - goto done; - } + PyByteArray_Resize(result, output - output_start); done: if (tableobj != NULL) diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/bytesobject.c --- a/Objects/bytesobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/bytesobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -474,9 +474,8 @@ break; } if (!errors || strcmp(errors, "strict") == 0) { - PyErr_Format(PyExc_ValueError, - "invalid \\x escape at position %d", - s - 2 - (end - len)); + PyErr_SetString(PyExc_ValueError, + "invalid \\x escape"); goto failed; } if (strcmp(errors, "replace") == 0) { @@ -490,10 +489,6 @@ errors); goto failed; } - /* skip \x */ - if (s < end && Py_ISXDIGIT(s[0])) - s++; /* and a hexdigit */ - break; default: *p++ = '\\'; s--; @@ -2755,7 +2750,8 @@ if (*pv == NULL) return; if (w == NULL) { - Py_CLEAR(*pv); + Py_DECREF(*pv); + *pv = NULL; return; } v = bytes_concat(*pv, w); @@ -2819,9 +2815,12 @@ PyBytes_Fini(void) { int i; - for (i = 0; i < UCHAR_MAX + 1; i++) - Py_CLEAR(characters[i]); - Py_CLEAR(nullstring); + for (i = 0; i < UCHAR_MAX + 1; i++) { + Py_XDECREF(characters[i]); + characters[i] = NULL; + } + Py_XDECREF(nullstring); + nullstring = NULL; } /*********************** Bytes Iterator ****************************/ diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/complexobject.c --- a/Objects/complexobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/complexobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -705,7 +705,7 @@ if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) return NULL; - _PyUnicodeWriter_Init(&writer); + _PyUnicodeWriter_Init(&writer, 0); ret = _PyComplex_FormatAdvancedWriter( &writer, self, diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/descrobject.c --- a/Objects/descrobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/descrobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -1009,7 +1009,7 @@ static PyObject * wrapper_richcompare(PyObject *a, PyObject *b, int op) { - Py_intptr_t result; + int result; PyObject *v; PyWrapperDescrObject *a_descr, *b_descr; diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/dictobject.c --- a/Objects/dictobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/dictobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -305,18 +305,14 @@ * #define USABLE_FRACTION(n) (((n) >> 1) + ((n) >> 2) - ((n) >> 3)) */ -/* GROWTH_RATE. Growth rate upon hitting maximum load. - * Currently set to used*2 + capacity/2. - * This means that dicts double in size when growing without deletions, - * but have more head room when the number of deletions is on a par with the - * number of insertions. - * Raising this to used*4 doubles memory consumption depending on the size of +/* GROWTH_RATE. Growth rate upon hitting maximum load. Currently set to *2. + * Raising this to *4 doubles memory consumption depending on the size of * the dictionary, but results in half the number of resizes, less effort to - * resize. - * GROWTH_RATE was set to used*4 up to version 3.2. - * GROWTH_RATE was set to used*2 in version 3.3.0 + * resize and better sparseness for some (but not all dict sizes). + * Setting to *4 eliminates every other resize step. + * GROWTH_RATE was set to *4 up to version 3.2. */ -#define GROWTH_RATE(d) (((d)->ma_used*2)+((d)->ma_keys->dk_size>>1)) +#define GROWTH_RATE(x) ((x) * 2) #define ENSURE_ALLOWS_DELETIONS(d) \ if ((d)->ma_keys->dk_lookup == lookdict_unicode_nodummy) { \ @@ -389,7 +385,6 @@ new_dict(PyDictKeysObject *keys, PyObject **values) { PyDictObject *mp; - assert(keys != NULL); if (numfree) { mp = free_list[--numfree]; assert (mp != NULL); @@ -432,10 +427,7 @@ PyObject * PyDict_New(void) { - PyDictKeysObject *keys = new_keys_object(PyDict_MINSIZE_COMBINED); - if (keys == NULL) - return NULL; - return new_dict(keys, NULL); + return new_dict(new_keys_object(PyDict_MINSIZE_COMBINED), NULL); } /* @@ -798,7 +790,7 @@ static int insertion_resize(PyDictObject *mp) { - return dictresize(mp, GROWTH_RATE(mp)); + return dictresize(mp, GROWTH_RATE(mp->ma_used)); } /* @@ -1395,7 +1387,7 @@ } DK_DECREF(keys); } - else if (keys != NULL) { + else { assert(keys->dk_refcnt == 1); DK_DECREF(keys); } @@ -1443,9 +1435,6 @@ Py_INCREF(value); s = PyObject_Repr(key); PyUnicode_Append(&s, colon); - if (s == NULL) - goto Done; - PyUnicode_AppendAndDel(&s, PyObject_Repr(value)); Py_DECREF(key); Py_DECREF(value); @@ -2222,19 +2211,19 @@ return val; } -PyObject * -PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj) +static PyObject * +dict_setdefault(register PyDictObject *mp, PyObject *args) { - PyDictObject *mp = (PyDictObject *)d; + PyObject *key; + PyObject *failobj = Py_None; PyObject *val = NULL; Py_hash_t hash; PyDictKeyEntry *ep; PyObject **value_addr; - if (!PyDict_Check(d)) { - PyErr_BadInternalCall(); + if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj)) return NULL; - } + if (!PyUnicode_CheckExact(key) || (hash = ((PyASCIIObject *) key)->hash) == -1) { hash = PyObject_Hash(key); @@ -2246,38 +2235,26 @@ return NULL; val = *value_addr; if (val == NULL) { + Py_INCREF(failobj); + Py_INCREF(key); if (mp->ma_keys->dk_usable <= 0) { /* Need to resize. */ if (insertion_resize(mp) < 0) return NULL; ep = find_empty_slot(mp, key, hash, &value_addr); } - Py_INCREF(defaultobj); - Py_INCREF(key); - MAINTAIN_TRACKING(mp, key, defaultobj); + MAINTAIN_TRACKING(mp, key, failobj); ep->me_key = key; ep->me_hash = hash; - *value_addr = defaultobj; - val = defaultobj; + *value_addr = failobj; + val = failobj; mp->ma_keys->dk_usable--; mp->ma_used++; } + Py_INCREF(val); return val; } -static PyObject * -dict_setdefault(PyDictObject *mp, PyObject *args) -{ - PyObject *key, *val; - PyObject *defaultobj = Py_None; - - if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &defaultobj)) - return NULL; - - val = PyDict_SetDefault((PyObject *)mp, key, defaultobj); - Py_XINCREF(val); - return val; -} static PyObject * dict_clear(register PyDictObject *mp) @@ -2484,10 +2461,10 @@ 2-tuple; but raise KeyError if D is empty."); PyDoc_STRVAR(update__doc__, -"D.update([E, ]**F) -> None. Update D from dict/iterable E and F.\n\ -If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]\n\ -If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v\n\ -In either case, this is followed by: for k in F: D[k] = F[k]"); +"D.update([E, ]**F) -> None. Update D from dict/iterable E and F.\n" +"If E present and has a .keys() method, does: for k in E: D[k] = E[k]\n\ +If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v\n\ +In either case, this is followed by: for k in F: D[k] = F[k]"); PyDoc_STRVAR(fromkeys__doc__, "dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n\ @@ -2592,23 +2569,22 @@ dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *self; - PyDictObject *d; assert(type != NULL && type->tp_alloc != NULL); self = type->tp_alloc(type, 0); - if (self == NULL) - return NULL; - d = (PyDictObject *)self; - - /* The object has been implicitly tracked by tp_alloc */ - if (type == &PyDict_Type) - _PyObject_GC_UNTRACK(d); - - d->ma_used = 0; - d->ma_keys = new_keys_object(PyDict_MINSIZE_COMBINED); - if (d->ma_keys == NULL) { - Py_DECREF(self); - return NULL; + if (self != NULL) { + PyDictObject *d = (PyDictObject *)self; + d->ma_keys = new_keys_object(PyDict_MINSIZE_COMBINED); + /* XXX - Should we raise a no-memory error? */ + if (d->ma_keys == NULL) { + DK_INCREF(Py_EMPTY_KEYS); + d->ma_keys = Py_EMPTY_KEYS; + d->ma_values = empty_values; + } + d->ma_used = 0; + /* The object has been implicitly tracked by tp_alloc */ + if (type == &PyDict_Type) + _PyObject_GC_UNTRACK(d); } return self; } @@ -2684,10 +2660,8 @@ { PyObject *kv; kv = _PyUnicode_FromId(key); /* borrowed */ - if (kv == NULL) { - PyErr_Clear(); + if (kv == NULL) return NULL; - } return PyDict_GetItem(dp, kv); } @@ -2698,10 +2672,8 @@ { PyObject *kv, *rv; kv = PyUnicode_FromString(key); - if (kv == NULL) { - PyErr_Clear(); + if (kv == NULL) return NULL; - } rv = PyDict_GetItem(v, kv); Py_DECREF(kv); return rv; diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/exceptions.c --- a/Objects/exceptions.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/exceptions.c Fri Feb 01 23:12:09 2013 +0100 @@ -2327,7 +2327,7 @@ } #ifdef MS_WINDOWS -#include +#include /* The following constants were added to errno.h in VS2010 but have preferred WSA equivalents. */ #undef EADDRINUSE diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/fileobject.c --- a/Objects/fileobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/fileobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -390,7 +390,7 @@ Py_BEGIN_ALLOW_THREADS errno = 0; -#ifdef MS_WINDOWS +#if defined(MS_WIN64) || defined(MS_WINDOWS) if (n > INT_MAX) n = INT_MAX; n = write(self->fd, c, (int)n); diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/floatobject.c --- a/Objects/floatobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/floatobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -9,6 +9,11 @@ #include #include +#undef MAX +#undef MIN +#define MAX(x, y) ((x) < (y) ? (y) : (x)) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + /* Special free list free_list is a singly-linked list of available PyFloatObjects, linked @@ -284,7 +289,7 @@ * may lose info from fractional bits. Converting the integer to a double * also has two failure modes: (1) a long int may trigger overflow (too * large to fit in the dynamic range of a C double); (2) even a C long may have - * more bits than fit in a C double (e.g., on a 64-bit box long may have + * more bits than fit in a C double (e.g., on a a 64-bit box long may have * 63 bits of precision, but a C double probably has only 53), and then * we can falsely claim equality when low-order integer bits are lost by * coercion to double. So this part is painful too. @@ -1126,7 +1131,7 @@ } m = frexp(fabs(x), &e); - shift = 1 - Py_MAX(DBL_MIN_EXP - e, 0); + shift = 1 - MAX(DBL_MIN_EXP - e, 0); m = ldexp(m, shift); e -= shift; @@ -1280,8 +1285,8 @@ fdigits = coeff_end - s_store; if (ndigits == 0) goto parse_error; - if (ndigits > Py_MIN(DBL_MIN_EXP - DBL_MANT_DIG - LONG_MIN/2, - LONG_MAX/2 + 1 - DBL_MAX_EXP)/4) + if (ndigits > MIN(DBL_MIN_EXP - DBL_MANT_DIG - LONG_MIN/2, + LONG_MAX/2 + 1 - DBL_MAX_EXP)/4) goto insane_length_error; /* [p ] */ @@ -1337,7 +1342,7 @@ /* lsb = exponent of least significant bit of the *rounded* value. This is top_exp - DBL_MANT_DIG unless result is subnormal. */ - lsb = Py_MAX(top_exp, (long)DBL_MIN_EXP) - DBL_MANT_DIG; + lsb = MAX(top_exp, (long)DBL_MIN_EXP) - DBL_MANT_DIG; x = 0.0; if (exp >= lsb) { @@ -1706,7 +1711,7 @@ if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) return NULL; - _PyUnicodeWriter_Init(&writer); + _PyUnicodeWriter_Init(&writer, 0); ret = _PyFloat_FormatAdvancedWriter( &writer, self, @@ -1853,7 +1858,7 @@ float_new, /* tp_new */ }; -int +void _PyFloat_Init(void) { /* We attempt to determine if this machine is using IEEE @@ -1903,11 +1908,8 @@ float_format = detected_float_format; /* Init float info */ - if (FloatInfoType.tp_name == NULL) { - if (PyStructSequence_InitType2(&FloatInfoType, &floatinfo_desc) < 0) - return 0; - } - return 1; + if (FloatInfoType.tp_name == 0) + PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc); } int diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/frameobject.c --- a/Objects/frameobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/frameobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -7,6 +7,11 @@ #include "opcode.h" #include "structmember.h" +#undef MIN +#undef MAX +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + #define OFF(x) offsetof(PyFrameObject, x) static PyMemberDef frame_memberlist[] = { @@ -155,8 +160,8 @@ /* We're now ready to look at the bytecode. */ PyBytes_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len); - min_addr = Py_MIN(new_lasti, f->f_lasti); - max_addr = Py_MAX(new_lasti, f->f_lasti); + min_addr = MIN(new_lasti, f->f_lasti); + max_addr = MAX(new_lasti, f->f_lasti); /* You can't jump onto a line with an 'except' statement on it - * they expect to have an exception on the top of the stack, which @@ -288,7 +293,7 @@ break; } - min_delta_iblock = Py_MIN(min_delta_iblock, delta_iblock); + min_delta_iblock = MIN(min_delta_iblock, delta_iblock); if (op >= HAVE_ARGUMENT) { addr += 2; diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/funcobject.c --- a/Objects/funcobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/funcobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -8,59 +8,60 @@ PyObject * PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname) { - PyFunctionObject *op; - PyObject *doc, *consts, *module; - static PyObject *__name__ = NULL; + PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, + &PyFunction_Type); + static PyObject *__name__ = 0; + if (op != NULL) { + PyObject *doc; + PyObject *consts; + PyObject *module; + op->func_weakreflist = NULL; + Py_INCREF(code); + op->func_code = code; + Py_INCREF(globals); + op->func_globals = globals; + op->func_name = ((PyCodeObject *)code)->co_name; + Py_INCREF(op->func_name); + op->func_defaults = NULL; /* No default arguments */ + op->func_kwdefaults = NULL; /* No keyword only defaults */ + op->func_closure = NULL; + consts = ((PyCodeObject *)code)->co_consts; + if (PyTuple_Size(consts) >= 1) { + doc = PyTuple_GetItem(consts, 0); + if (!PyUnicode_Check(doc)) + doc = Py_None; + } + else + doc = Py_None; + Py_INCREF(doc); + op->func_doc = doc; + op->func_dict = NULL; + op->func_module = NULL; + op->func_annotations = NULL; - if (__name__ == NULL) { - __name__ = PyUnicode_InternFromString("__name__"); - if (__name__ == NULL) - return NULL; - } - - op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); - if (op == NULL) - return NULL; - - op->func_weakreflist = NULL; - Py_INCREF(code); - op->func_code = code; - Py_INCREF(globals); - op->func_globals = globals; - op->func_name = ((PyCodeObject *)code)->co_name; - Py_INCREF(op->func_name); - op->func_defaults = NULL; /* No default arguments */ - op->func_kwdefaults = NULL; /* No keyword only defaults */ - op->func_closure = NULL; - - consts = ((PyCodeObject *)code)->co_consts; - if (PyTuple_Size(consts) >= 1) { - doc = PyTuple_GetItem(consts, 0); - if (!PyUnicode_Check(doc)) - doc = Py_None; + /* __module__: If module name is in globals, use it. + Otherwise, use None. + */ + if (!__name__) { + __name__ = PyUnicode_InternFromString("__name__"); + if (!__name__) { + Py_DECREF(op); + return NULL; + } + } + module = PyDict_GetItem(globals, __name__); + if (module) { + Py_INCREF(module); + op->func_module = module; + } + if (qualname) + op->func_qualname = qualname; + else + op->func_qualname = op->func_name; + Py_INCREF(op->func_qualname); } else - doc = Py_None; - Py_INCREF(doc); - op->func_doc = doc; - - op->func_dict = NULL; - op->func_module = NULL; - op->func_annotations = NULL; - - /* __module__: If module name is in globals, use it. - Otherwise, use None. */ - module = PyDict_GetItem(globals, __name__); - if (module) { - Py_INCREF(module); - op->func_module = module; - } - if (qualname) - op->func_qualname = qualname; - else - op->func_qualname = op->func_name; - Py_INCREF(op->func_qualname); - + return NULL; _PyObject_GC_TRACK(op); return (PyObject *)op; } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/genobject.c --- a/Objects/genobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/genobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -178,7 +178,7 @@ PyObject *yf = NULL; PyFrameObject *f = gen->gi_frame; - if (f && f->f_stacktop) { + if (f) { PyObject *bytecode = f->f_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/iterobject.c --- a/Objects/iterobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/iterobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -4,7 +4,7 @@ typedef struct { PyObject_HEAD - Py_ssize_t it_index; + long it_index; PyObject *it_seq; /* Set to NULL when iterator is exhausted */ } seqiterobject; diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/listobject.c --- a/Objects/listobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/listobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -644,14 +644,9 @@ memcpy(recycle, &item[ilow], s); if (d < 0) { /* Delete -d items */ - Py_ssize_t tail; - tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *); - memmove(&item[ihigh+d], &item[ihigh], tail); - if (list_resize(a, Py_SIZE(a) + d) < 0) { - memmove(&item[ihigh], &item[ihigh+d], tail); - memcpy(&item[ilow], recycle, s); - goto Error; - } + memmove(&item[ihigh+d], &item[ihigh], + (Py_SIZE(a) - ihigh)*sizeof(PyObject *)); + list_resize(a, Py_SIZE(a) + d); item = a->ob_item; } else if (d > 0) { /* Insert d items */ @@ -876,10 +871,8 @@ } /* Cut back result list if initial guess was too large. */ - if (Py_SIZE(self) < self->allocated) { - if (list_resize(self, Py_SIZE(self)) < 0) - goto error; - } + if (Py_SIZE(self) < self->allocated) + list_resize(self, Py_SIZE(self)); /* shrinking can't fail */ Py_DECREF(it); Py_RETURN_NONE; @@ -932,17 +925,17 @@ v = self->ob_item[i]; if (i == Py_SIZE(self) - 1) { status = list_resize(self, Py_SIZE(self) - 1); - if (status >= 0) - return v; /* and v now owns the reference the list had */ - else - return NULL; + assert(status >= 0); + return v; /* and v now owns the reference the list had */ } Py_INCREF(v); status = list_ass_slice(self, i, i+1, (PyObject *)NULL); - if (status < 0) { - Py_DECREF(v); - return NULL; - } + assert(status >= 0); + /* Use status, so that in a release build compilers don't + * complain about the unused name. + */ + (void) status; + return v; } @@ -2667,7 +2660,7 @@ typedef struct { PyObject_HEAD - Py_ssize_t it_index; + long it_index; PyListObject *it_seq; /* Set to NULL when iterator is exhausted */ } listiterobject; @@ -2804,7 +2797,7 @@ static PyObject * listiter_setstate(listiterobject *it, PyObject *state) { - Py_ssize_t index = PyLong_AsSsize_t(state); + long index = PyLong_AsLong(state); if (index == -1 && PyErr_Occurred()) return NULL; if (it->it_seq != NULL) { @@ -2965,7 +2958,7 @@ if (forward) { listiterobject *it = (listiterobject *)_it; if (it->it_seq) - return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), + return Py_BuildValue("N(O)l", _PyObject_GetBuiltin("iter"), it->it_seq, it->it_index); } else { listreviterobject *it = (listreviterobject *)_it; diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/longobject.c --- a/Objects/longobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/longobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -17,8 +17,7 @@ #endif /* convert a PyLong of size 1, 0 or -1 to an sdigit */ -#define MEDIUM_VALUE(x) (assert(-1 <= Py_SIZE(x) && Py_SIZE(x) <= 1), \ - Py_SIZE(x) < 0 ? -(sdigit)(x)->ob_digit[0] : \ +#define MEDIUM_VALUE(x) (Py_SIZE(x) < 0 ? -(sdigit)(x)->ob_digit[0] : \ (Py_SIZE(x) == 0 ? (sdigit)0 : \ (sdigit)(x)->ob_digit[0])) #define ABS(x) ((x) < 0 ? -(x) : (x)) @@ -71,21 +70,11 @@ /* If a freshly-allocated long is already shared, it must be a small integer, so negating it must go to PyLong_FromLong */ -Py_LOCAL_INLINE(void) -_PyLong_Negate(PyLongObject **x_p) -{ - PyLongObject *x; - - x = (PyLongObject *)*x_p; - if (Py_REFCNT(x) == 1) { - Py_SIZE(x) = -Py_SIZE(x); - return; - } - - *x_p = (PyLongObject *)PyLong_FromLong(-MEDIUM_VALUE(x)); - Py_DECREF(x); -} - +#define NEGATE(x) \ + do if (Py_REFCNT(x) == 1) Py_SIZE(x) = -Py_SIZE(x); \ + else { PyObject* tmp=PyLong_FromLong(-MEDIUM_VALUE(x)); \ + Py_DECREF(x); (x) = (PyLongObject*)tmp; } \ + while(0) /* For long multiplication, use the O(N**2) school algorithm unless * both operands contain more than KARATSUBA_CUTOFF digits (this * being an internal Python long digit, in base BASE). @@ -100,6 +89,11 @@ */ #define FIVEARY_CUTOFF 8 +#undef MIN +#undef MAX +#define MAX(x, y) ((x) < (y) ? (y) : (x)) +#define MIN(x, y) ((x) > (y) ? (y) : (x)) + #define SIGCHECK(PyTryBlock) \ do { \ if (PyErr_CheckSignals()) PyTryBlock \ @@ -2014,7 +2008,7 @@ "int() arg 2 must be >= 2 and <= 36"); return NULL; } - while (*str != '\0' && Py_ISSPACE(Py_CHARMASK(*str))) + while (*str != '\0' && isspace(Py_CHARMASK(*str))) str++; if (*str == '+') ++str; @@ -2258,7 +2252,7 @@ goto onError; if (sign < 0) Py_SIZE(z) = -(Py_SIZE(z)); - while (*str && Py_ISSPACE(Py_CHARMASK(*str))) + while (*str && isspace(Py_CHARMASK(*str))) str++; if (*str != '\0') goto onError; @@ -2368,21 +2362,10 @@ The quotient z has the sign of a*b; the remainder r has the sign of a, so a = b*z + r. */ - if ((Py_SIZE(a) < 0) != (Py_SIZE(b) < 0)) { - _PyLong_Negate(&z); - if (z == NULL) { - Py_CLEAR(*prem); - return -1; - } - } - if (Py_SIZE(a) < 0 && Py_SIZE(*prem) != 0) { - _PyLong_Negate(prem); - if (*prem == NULL) { - Py_DECREF(z); - Py_CLEAR(*prem); - return -1; - } - } + if ((Py_SIZE(a) < 0) != (Py_SIZE(b) < 0)) + NEGATE(z); + if (Py_SIZE(a) < 0 && Py_SIZE(*prem) != 0) + NEGATE(*prem); *pdiv = maybe_small_long(z); return 0; } @@ -2878,11 +2861,8 @@ borrow &= 1; /* Keep only one sign bit */ } assert(borrow == 0); - if (sign < 0) { - _PyLong_Negate(&z); - if (z == NULL) - return NULL; - } + if (sign < 0) + NEGATE(z); return long_normalize(z); } @@ -3049,7 +3029,7 @@ Py_ssize_t size_lo, size_hi; const Py_ssize_t size_n = ABS(Py_SIZE(n)); - size_lo = Py_MIN(size_n, size); + size_lo = MIN(size_n, size); size_hi = size_n - size_lo; if ((hi = _PyLong_New(size_hi)) == NULL) @@ -3320,7 +3300,7 @@ nbdone = 0; while (bsize > 0) { PyLongObject *product; - const Py_ssize_t nbtouse = Py_MIN(bsize, asize); + const Py_ssize_t nbtouse = MIN(bsize, asize); /* Multiply the next slice of b by a. */ memcpy(bslice->ob_digit, b->ob_digit + nbdone, @@ -3373,11 +3353,8 @@ z = k_mul(a, b); /* Negate if exactly one of the inputs is negative. */ - if (((Py_SIZE(a) ^ Py_SIZE(b)) < 0) && z) { - _PyLong_Negate(&z); - if (z == NULL) - return NULL; - } + if (((Py_SIZE(a) ^ Py_SIZE(b)) < 0) && z) + NEGATE(z); return (PyObject *)z; } @@ -3614,7 +3591,7 @@ goto underflow_or_zero; /* Choose value for shift; see comments for step 1 above. */ - shift = Py_MAX(diff, DBL_MIN_EXP) - DBL_MANT_DIG - 2; + shift = MAX(diff, DBL_MIN_EXP) - DBL_MANT_DIG - 2; inexact = 0; @@ -3685,7 +3662,7 @@ x_bits = (x_size-1)*PyLong_SHIFT+bits_in_digit(x->ob_digit[x_size-1]); /* The number of extra bits that have to be rounded away. */ - extra_bits = Py_MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG; + extra_bits = MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG; assert(extra_bits == 2 || extra_bits == 3); /* Round by directly modifying the low digit of x. */ @@ -3824,9 +3801,7 @@ Py_DECREF(c); c = temp; temp = NULL; - _PyLong_Negate(&c); - if (c == NULL) - goto Error; + NEGATE(c); } /* if modulus == 1: @@ -3926,7 +3901,10 @@ goto Done; Error: - Py_CLEAR(z); + if (z != NULL) { + Py_DECREF(z); + z = NULL; + } /* fall through */ Done: if (Py_SIZE(b) > FIVEARY_CUTOFF) { @@ -4056,10 +4034,10 @@ shiftby = PyLong_AsSsize_t((PyObject *)b); if (shiftby == -1L && PyErr_Occurred()) - return NULL; + goto lshift_error; if (shiftby < 0) { PyErr_SetString(PyExc_ValueError, "negative shift count"); - return NULL; + goto lshift_error; } /* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */ wordshift = shiftby / PyLong_SHIFT; @@ -4071,11 +4049,9 @@ ++newsize; z = _PyLong_New(newsize); if (z == NULL) - return NULL; - if (Py_SIZE(a) < 0) { - assert(Py_REFCNT(z) == 1); - Py_SIZE(z) = -Py_SIZE(z); - } + goto lshift_error; + if (Py_SIZE(a) < 0) + NEGATE(z); for (i = 0; i < wordshift; i++) z->ob_digit[i] = 0; accum = 0; @@ -4089,6 +4065,7 @@ else assert(!accum); z = long_normalize(z); + lshift_error: return (PyObject *) maybe_small_long(z); } @@ -4306,6 +4283,11 @@ } if (obase == NULL) return PyNumber_Long(x); + if (!PyLong_Check(obase)) { + PyErr_SetString(PyExc_TypeError, + "int() base must be an integer."); + return NULL; + } base = PyNumber_AsSsize_t(obase, NULL); if (base == -1 && PyErr_Occurred()) @@ -4402,7 +4384,7 @@ if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) return NULL; - _PyUnicodeWriter_Init(&writer); + _PyUnicodeWriter_Init(&writer, 0); ret = _PyLong_FormatAdvancedWriter( &writer, self, @@ -5059,10 +5041,8 @@ } #endif /* initialize int_info */ - if (Int_InfoType.tp_name == NULL) { - if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) - return 0; - } + if (Int_InfoType.tp_name == 0) + PyStructSequence_InitType(&Int_InfoType, &int_info_desc); return 1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/memoryobject.c --- a/Objects/memoryobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/memoryobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -307,8 +307,7 @@ if (!equiv_format(dest, src) || !equiv_shape(dest, src)) { PyErr_SetString(PyExc_ValueError, - "memoryview assignment: lvalue and rvalue have different " - "structures"); + "ndarray assignment: lvalue and rvalue have different structures"); return 0; } @@ -1434,7 +1433,7 @@ /* PyBUF_SIMPLE|PyBUF_FORMAT and PyBUF_WRITABLE|PyBUF_FORMAT do not make sense. */ PyErr_Format(PyExc_BufferError, - "memoryview: cannot cast to unsigned bytes if the format flag " + "ndarray: cannot cast to unsigned bytes if the format flag " "is present"); return -1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/methodobject.c --- a/Objects/methodobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/methodobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -79,34 +79,23 @@ PyObject * PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { -#define CHECK_RESULT(res) assert(res != NULL || PyErr_Occurred()) - PyCFunctionObject* f = (PyCFunctionObject*)func; PyCFunction meth = PyCFunction_GET_FUNCTION(func); PyObject *self = PyCFunction_GET_SELF(func); - PyObject *res; Py_ssize_t size; switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) { case METH_VARARGS: - if (kw == NULL || PyDict_Size(kw) == 0) { - res = (*meth)(self, arg); - CHECK_RESULT(res); - return res; - } + if (kw == NULL || PyDict_Size(kw) == 0) + return (*meth)(self, arg); break; case METH_VARARGS | METH_KEYWORDS: - res = (*(PyCFunctionWithKeywords)meth)(self, arg, kw); - CHECK_RESULT(res); - return res; + return (*(PyCFunctionWithKeywords)meth)(self, arg, kw); case METH_NOARGS: if (kw == NULL || PyDict_Size(kw) == 0) { size = PyTuple_GET_SIZE(arg); - if (size == 0) { - res = (*meth)(self, NULL); - CHECK_RESULT(res); - return res; - } + if (size == 0) + return (*meth)(self, NULL); PyErr_Format(PyExc_TypeError, "%.200s() takes no arguments (%zd given)", f->m_ml->ml_name, size); @@ -116,11 +105,8 @@ case METH_O: if (kw == NULL || PyDict_Size(kw) == 0) { size = PyTuple_GET_SIZE(arg); - if (size == 1) { - res = (*meth)(self, PyTuple_GET_ITEM(arg, 0)); - CHECK_RESULT(res); - return res; - } + if (size == 1) + return (*meth)(self, PyTuple_GET_ITEM(arg, 0)); PyErr_Format(PyExc_TypeError, "%.200s() takes exactly one argument (%zd given)", f->m_ml->ml_name, size); @@ -137,8 +123,6 @@ PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", f->m_ml->ml_name); return NULL; - -#undef CHECK_RESULT } /* Methods (the standard built-in methods, that is) */ @@ -368,6 +352,6 @@ _PyCFunction_DebugMallocStats(FILE *out) { _PyDebugAllocatorStats(out, - "free PyCFunctionObject", + "free PyCFunctionObjects", numfree, sizeof(PyCFunctionObject)); } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/moduleobject.c --- a/Objects/moduleobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/moduleobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -26,27 +26,6 @@ }; -static int -module_init_dict(PyObject *md_dict, PyObject *name, PyObject *doc) -{ - if (md_dict == NULL) - return -1; - if (doc == NULL) - doc = Py_None; - - if (PyDict_SetItemString(md_dict, "__name__", name) != 0) - return -1; - if (PyDict_SetItemString(md_dict, "__doc__", doc) != 0) - return -1; - if (PyDict_SetItemString(md_dict, "__package__", Py_None) != 0) - return -1; - if (PyDict_SetItemString(md_dict, "__loader__", Py_None) != 0) - return -1; - - return 0; -} - - PyObject * PyModule_NewObject(PyObject *name) { @@ -57,7 +36,13 @@ m->md_def = NULL; m->md_state = NULL; m->md_dict = PyDict_New(); - if (module_init_dict(m->md_dict, name, NULL) != 0) + if (m->md_dict == NULL) + goto fail; + if (PyDict_SetItemString(m->md_dict, "__name__", name) != 0) + goto fail; + if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0) + goto fail; + if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0) goto fail; PyObject_GC_Track(m); return (PyObject *)m; @@ -362,7 +347,9 @@ return -1; m->md_dict = dict; } - if (module_init_dict(dict, name, doc) < 0) + if (PyDict_SetItemString(dict, "__name__", name) < 0) + return -1; + if (PyDict_SetItemString(dict, "__doc__", doc) < 0) return -1; return 0; } @@ -393,7 +380,7 @@ if (m->md_dict != NULL) { loader = PyDict_GetItemString(m->md_dict, "__loader__"); } - if (loader != NULL && loader != Py_None) { + if (loader != NULL) { repr = PyObject_CallMethod(loader, "module_repr", "(O)", (PyObject *)m, NULL); if (repr == NULL) { @@ -417,10 +404,10 @@ filename = PyModule_GetFilenameObject((PyObject *)m); if (filename == NULL) { PyErr_Clear(); - /* There's no m.__file__, so if there was a __loader__, use that in + /* There's no m.__file__, so if there was an __loader__, use that in * the repr, otherwise, the only thing you can use is m.__name__ */ - if (loader == NULL || loader == Py_None) { + if (loader == NULL) { repr = PyUnicode_FromFormat("", name); } else { diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/namespaceobject.c --- a/Objects/namespaceobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/namespaceobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -44,7 +44,7 @@ if (args != NULL) { Py_ssize_t argcount = PyObject_Size(args); if (argcount < 0) - return -1; + return argcount; else if (argcount > 0) { PyErr_Format(PyExc_TypeError, "no positional arguments expected"); return -1; @@ -66,20 +66,16 @@ static PyObject * -namespace_repr(PyObject *ns) +namespace_repr(_PyNamespaceObject *ns) { int i, loop_error = 0; PyObject *pairs = NULL, *d = NULL, *keys = NULL, *keys_iter = NULL; PyObject *key; PyObject *separator, *pairsrepr, *repr = NULL; - const char * name; - name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace" - : ns->ob_type->tp_name; - - i = Py_ReprEnter(ns); + i = Py_ReprEnter((PyObject *)ns); if (i != 0) { - return i > 0 ? PyUnicode_FromFormat("%s(...)", name) : NULL; + return i > 0 ? PyUnicode_FromString("namespace(...)") : NULL; } pairs = PyList_New(0); @@ -131,7 +127,8 @@ if (pairsrepr == NULL) goto error; - repr = PyUnicode_FromFormat("%s(%S)", name, pairsrepr); + repr = PyUnicode_FromFormat("%s(%S)", + ((PyObject *)ns)->ob_type->tp_name, pairsrepr); Py_DECREF(pairsrepr); error: @@ -139,7 +136,7 @@ Py_XDECREF(d); Py_XDECREF(keys); Py_XDECREF(keys_iter); - Py_ReprLeave(ns); + Py_ReprLeave((PyObject *)ns); return repr; } @@ -161,49 +158,14 @@ } -static PyObject * -namespace_richcompare(PyObject *self, PyObject *other, int op) -{ - if (PyObject_IsInstance(self, (PyObject *)&_PyNamespace_Type) && - PyObject_IsInstance(other, (PyObject *)&_PyNamespace_Type)) - return PyObject_RichCompare(((_PyNamespaceObject *)self)->ns_dict, - ((_PyNamespaceObject *)other)->ns_dict, op); - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; -} - - -PyDoc_STRVAR(namespace_reduce__doc__, "Return state information for pickling"); - -static PyObject * -namespace_reduce(register _PyNamespaceObject *ns) -{ - PyObject *result, *args = PyTuple_New(0); - - if (!args) - return NULL; - - result = PyTuple_Pack(3, (PyObject *)Py_TYPE(ns), args, ns->ns_dict); - Py_DECREF(args); - return result; -} - - -static PyMethodDef namespace_methods[] = { - {"__reduce__", (PyCFunction)namespace_reduce, METH_NOARGS, - namespace_reduce__doc__}, - {NULL, NULL} /* sentinel */ -}; - - PyDoc_STRVAR(namespace_doc, "A simple attribute-based namespace.\n\ \n\ -SimpleNamespace(**kwargs)"); +namespace(**kwargs)"); PyTypeObject _PyNamespace_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "types.SimpleNamespace", /* tp_name */ + "namespace", /* tp_name */ sizeof(_PyNamespaceObject), /* tp_size */ 0, /* tp_itemsize */ (destructor)namespace_dealloc, /* tp_dealloc */ @@ -226,11 +188,11 @@ namespace_doc, /* tp_doc */ (traverseproc)namespace_traverse, /* tp_traverse */ (inquiry)namespace_clear, /* tp_clear */ - namespace_richcompare, /* tp_richcompare */ + 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - namespace_methods, /* tp_methods */ + 0, /* tp_methods */ namespace_members, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/object.c --- a/Objects/object.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/object.c Fri Feb 01 23:12:09 2013 +0100 @@ -377,14 +377,6 @@ if (Py_TYPE(v)->tp_repr == NULL) return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v); - -#ifdef Py_DEBUG - /* PyObject_Repr() must not be called with an exception set, - because it may clear it (directly or indirectly) and so the - caller looses its exception */ - assert(!PyErr_Occurred()); -#endif - res = (*v->ob_type->tp_repr)(v); if (res == NULL) return NULL; @@ -416,7 +408,6 @@ #endif if (v == NULL) return PyUnicode_FromString(""); - if (PyUnicode_CheckExact(v)) { #ifndef Py_DEBUG if (PyUnicode_READY(v) < 0) @@ -428,13 +419,6 @@ if (Py_TYPE(v)->tp_str == NULL) return PyObject_Repr(v); -#ifdef Py_DEBUG - /* PyObject_Str() must not be called with an exception set, - because it may clear it (directly or indirectly) and so the - caller looses its exception */ - assert(!PyErr_Occurred()); -#endif - /* It is possible for a type to have a tp_str representation that loops infinitely. */ if (Py_EnterRecursiveCall(" while getting the str of an object")) @@ -467,9 +451,6 @@ if (repr == NULL) return NULL; - if (PyUnicode_IS_ASCII(repr)) - return repr; - /* repr is guaranteed to be a PyUnicode object by PyObject_Repr */ ascii = _PyUnicode_AsASCIIString(repr, "backslashreplace"); Py_DECREF(repr); @@ -1875,6 +1856,26 @@ Py_ssize_t (*_Py_abstract_hack)(PyObject *) = PyObject_Size; +/* Python's malloc wrappers (see pymem.h) */ + +void * +PyMem_Malloc(size_t nbytes) +{ + return PyMem_MALLOC(nbytes); +} + +void * +PyMem_Realloc(void *p, size_t nbytes) +{ + return PyMem_REALLOC(p, nbytes); +} + +void +PyMem_Free(void *p) +{ + PyMem_FREE(p); +} + void _PyObject_DebugTypeStats(FILE *out) { @@ -1926,8 +1927,7 @@ if (PyList_GET_ITEM(list, i) == obj) return 1; } - if (PyList_Append(list, obj) < 0) - return -1; + PyList_Append(list, obj); return 0; } @@ -1937,18 +1937,13 @@ PyObject *dict; PyObject *list; Py_ssize_t i; - PyObject *error_type, *error_value, *error_traceback; - - PyErr_Fetch(&error_type, &error_value, &error_traceback); dict = PyThreadState_GetDict(); if (dict == NULL) - goto finally; - + return; list = PyDict_GetItemString(dict, KEY); if (list == NULL || !PyList_Check(list)) - goto finally; - + return; i = PyList_GET_SIZE(list); /* Count backwards because we always expect obj to be list[-1] */ while (--i >= 0) { @@ -1957,10 +1952,6 @@ break; } } - -finally: - /* ignore exceptions because there is no way to report them. */ - PyErr_Restore(error_type, error_value, error_traceback); } /* Trashcan support. */ diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/obmalloc.c --- a/Objects/obmalloc.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/obmalloc.c Fri Feb 01 23:12:09 2013 +0100 @@ -1,354 +1,14 @@ #include "Python.h" -/* Python's malloc wrappers (see pymem.h) */ - -#ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */ -/* Forward declaration */ -static void* _PyMem_DebugMalloc(void *ctx, size_t size); -static void _PyMem_DebugFree(void *ctx, void *p); -static void* _PyMem_DebugRealloc(void *ctx, void *ptr, size_t size); - -static void _PyObject_DebugDumpAddress(const void *p); -static void _PyMem_DebugCheckAddress(char api_id, const void *p); -#endif - #ifdef WITH_PYMALLOC -#ifdef MS_WINDOWS -# include -#elif defined(HAVE_MMAP) -# include -# ifdef MAP_ANONYMOUS -# define ARENAS_USE_MMAP -# endif +#ifdef HAVE_MMAP + #include + #ifdef MAP_ANONYMOUS + #define ARENAS_USE_MMAP + #endif #endif -/* Forward declaration */ -static void* _PyObject_Malloc(void *ctx, size_t size); -static void _PyObject_Free(void *ctx, void *p); -static void* _PyObject_Realloc(void *ctx, void *ptr, size_t size); -#endif - - -static void * -_PyMem_RawMalloc(void *ctx, size_t size) -{ - /* PyMem_Malloc(0) means malloc(1). Some systems would return NULL - for malloc(0), which would be treated as an error. Some platforms would - return a pointer with no memory behind it, which would break pymalloc. - To solve these problems, allocate an extra byte. */ - if (size == 0) - size = 1; - return malloc(size); -} - -static void * -_PyMem_RawRealloc(void *ctx, void *ptr, size_t size) -{ - if (size == 0) - size = 1; - return realloc(ptr, size); -} - -static void -_PyMem_RawFree(void *ctx, void *ptr) -{ - free(ptr); -} - - -#ifdef MS_WINDOWS -static void * -_PyObject_ArenaVirtualAlloc(void *ctx, size_t size) -{ - return VirtualAlloc(NULL, size, - MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); -} - -static void -_PyObject_ArenaVirtualFree(void *ctx, void *ptr, size_t size) -{ - VirtualFree(ptr, 0, MEM_RELEASE); -} - -#elif defined(ARENAS_USE_MMAP) -static void * -_PyObject_ArenaMmap(void *ctx, size_t size) -{ - void *ptr; - ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if (ptr == MAP_FAILED) - return NULL; - assert(ptr != NULL); - return ptr; -} - -static void -_PyObject_ArenaMunmap(void *ctx, void *ptr, size_t size) -{ - munmap(ptr, size); -} - -#else -static void * -_PyObject_ArenaMalloc(void *ctx, size_t size) -{ - return malloc(size); -} - -static void -_PyObject_ArenaFree(void *ctx, void *ptr, size_t size) -{ - free(ptr); -} -#endif - - -#define PYRAW_FUNCS _PyMem_RawMalloc, _PyMem_RawRealloc, _PyMem_RawFree -#ifdef WITH_PYMALLOC -#define PYOBJECT_FUNCS _PyObject_Malloc, _PyObject_Realloc, _PyObject_Free -#else -#define PYOBJECT_FUNCS PYRAW_FUNCS -#endif - -#ifdef PYMALLOC_DEBUG -typedef struct { - /* We tag each block with an API ID in order to tag API violations */ - char api_id; - PyMemAllocator alloc; -} debug_alloc_api_t; -static struct { - debug_alloc_api_t raw; - debug_alloc_api_t mem; - debug_alloc_api_t obj; -} _PyMem_Debug = { - {'r', {NULL, PYRAW_FUNCS}}, - {'m', {NULL, PYRAW_FUNCS}}, - {'o', {NULL, PYOBJECT_FUNCS}} - }; - -#define PYDEBUG_FUNCS _PyMem_DebugMalloc, _PyMem_DebugRealloc, _PyMem_DebugFree -#endif - -static PyMemAllocator _PyMem_Raw = { -#ifdef PYMALLOC_DEBUG - &_PyMem_Debug.raw, PYDEBUG_FUNCS -#else - NULL, PYRAW_FUNCS -#endif - }; - -static PyMemAllocator _PyMem = { -#ifdef PYMALLOC_DEBUG - &_PyMem_Debug.mem, PYDEBUG_FUNCS -#else - NULL, PYRAW_FUNCS -#endif - }; - -static PyMemAllocator _PyObject = { -#ifdef PYMALLOC_DEBUG - &_PyMem_Debug.obj, PYDEBUG_FUNCS -#else - NULL, PYOBJECT_FUNCS -#endif - }; - -#undef PYRAW_FUNCS -#undef PYOBJECT_FUNCS -#undef PYDEBUG_FUNCS - -static PyObjectArenaAllocator _PyObject_Arena = {NULL, -#ifdef MS_WINDOWS - _PyObject_ArenaVirtualAlloc, _PyObject_ArenaVirtualFree -#elif defined(ARENAS_USE_MMAP) - _PyObject_ArenaMmap, _PyObject_ArenaMunmap -#else - _PyObject_ArenaMalloc, _PyObject_ArenaFree -#endif - }; - -void -PyMem_SetupDebugHooks(void) -{ -#ifdef PYMALLOC_DEBUG - PyMemAllocator alloc; - - alloc.malloc = _PyMem_DebugMalloc; - alloc.realloc = _PyMem_DebugRealloc; - alloc.free = _PyMem_DebugFree; - - if (_PyMem_Raw.malloc != _PyMem_DebugMalloc) { - alloc.ctx = &_PyMem_Debug.raw; - PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &_PyMem_Debug.raw.alloc); - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc); - } - - if (_PyMem.malloc != _PyMem_DebugMalloc) { - alloc.ctx = &_PyMem_Debug.mem; - PyMem_GetAllocator(PYMEM_DOMAIN_MEM, &_PyMem_Debug.mem.alloc); - PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &alloc); - } - - if (_PyObject.malloc != _PyMem_DebugMalloc) { - alloc.ctx = &_PyMem_Debug.obj; - PyMem_GetAllocator(PYMEM_DOMAIN_OBJ, &_PyMem_Debug.obj.alloc); - PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &alloc); - } -#endif -} - -void -PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) -{ - switch(domain) - { - case PYMEM_DOMAIN_RAW: *allocator = _PyMem_Raw; break; - case PYMEM_DOMAIN_MEM: *allocator = _PyMem; break; - case PYMEM_DOMAIN_OBJ: *allocator = _PyObject; break; - default: - /* unknown domain */ - allocator->ctx = NULL; - allocator->malloc = NULL; - allocator->realloc = NULL; - allocator->free = NULL; - } -} - -void -PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) -{ - switch(domain) - { - case PYMEM_DOMAIN_RAW: _PyMem_Raw = *allocator; break; - case PYMEM_DOMAIN_MEM: _PyMem = *allocator; break; - case PYMEM_DOMAIN_OBJ: _PyObject = *allocator; break; - /* ignore unknown domain */ - } - -} - -void -PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator) -{ - *allocator = _PyObject_Arena; -} - -void -PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator) -{ - _PyObject_Arena = *allocator; -} - -void * -PyMem_RawMalloc(size_t size) -{ - /* - * Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes. - * Most python internals blindly use a signed Py_ssize_t to track - * things without checking for overflows or negatives. - * As size_t is unsigned, checking for size < 0 is not required. - */ - if (size > (size_t)PY_SSIZE_T_MAX) - return NULL; - - return _PyMem_Raw.malloc(_PyMem_Raw.ctx, size); -} - -void* -PyMem_RawRealloc(void *ptr, size_t new_size) -{ - /* see PyMem_RawMalloc() */ - if (new_size > (size_t)PY_SSIZE_T_MAX) - return NULL; - return _PyMem_Raw.realloc(_PyMem_Raw.ctx, ptr, new_size); -} - -void PyMem_RawFree(void *ptr) -{ - _PyMem_Raw.free(_PyMem_Raw.ctx, ptr); -} - -void * -PyMem_Malloc(size_t size) -{ - /* see PyMem_RawMalloc() */ - if (size > (size_t)PY_SSIZE_T_MAX) - return NULL; - return _PyMem.malloc(_PyMem.ctx, size); -} - -void * -PyMem_Realloc(void *ptr, size_t new_size) -{ - /* see PyMem_RawMalloc() */ - if (new_size > (size_t)PY_SSIZE_T_MAX) - return NULL; - return _PyMem.realloc(_PyMem.ctx, ptr, new_size); -} - -void -PyMem_Free(void *ptr) -{ - _PyMem.free(_PyMem.ctx, ptr); -} - -char * -_PyMem_RawStrdup(const char *str) -{ - size_t size; - char *copy; - - size = strlen(str) + 1; - copy = PyMem_RawMalloc(size); - if (copy == NULL) - return NULL; - memcpy(copy, str, size); - return copy; -} - -char * -_PyMem_Strdup(const char *str) -{ - size_t size; - char *copy; - - size = strlen(str) + 1; - copy = PyMem_Malloc(size); - if (copy == NULL) - return NULL; - memcpy(copy, str, size); - return copy; -} - -void * -PyObject_Malloc(size_t size) -{ - /* see PyMem_RawMalloc() */ - if (size > (size_t)PY_SSIZE_T_MAX) - return NULL; - return _PyObject.malloc(_PyObject.ctx, size); -} - -void * -PyObject_Realloc(void *ptr, size_t new_size) -{ - /* see PyMem_RawMalloc() */ - if (new_size > (size_t)PY_SSIZE_T_MAX) - return NULL; - return _PyObject.realloc(_PyObject.ctx, ptr, new_size); -} - -void -PyObject_Free(void *ptr) -{ - _PyObject.free(_PyObject.ctx, ptr); -} - - -#ifdef WITH_PYMALLOC - #ifdef WITH_VALGRIND #include @@ -885,6 +545,7 @@ struct arena_object* arenaobj; uint excess; /* number of bytes above pool alignment */ void *address; + int err; #ifdef PYMALLOC_DEBUG if (Py_GETENV("PYTHONMALLOCSTATS")) @@ -906,7 +567,7 @@ return NULL; /* overflow */ #endif nbytes = numarenas * sizeof(*arenas); - arenaobj = (struct arena_object *)PyMem_Realloc(arenas, nbytes); + arenaobj = (struct arena_object *)realloc(arenas, nbytes); if (arenaobj == NULL) return NULL; arenas = arenaobj; @@ -937,8 +598,15 @@ arenaobj = unused_arena_objects; unused_arena_objects = arenaobj->nextarena; assert(arenaobj->address == 0); - address = _PyObject_Arena.alloc(_PyObject_Arena.ctx, ARENA_SIZE); - if (address == NULL) { +#ifdef ARENAS_USE_MMAP + address = mmap(NULL, ARENA_SIZE, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + err = (address == MAP_FAILED); +#else + address = malloc(ARENA_SIZE); + err = (address == 0); +#endif + if (err) { /* The allocation failed: return NULL after putting the * arenaobj back. */ @@ -1101,16 +769,15 @@ * Unless the optimizer reorders everything, being too smart... */ -static void * -_PyObject_Malloc(void *ctx, size_t nbytes) +#undef PyObject_Malloc +void * +PyObject_Malloc(size_t nbytes) { block *bp; poolp pool; poolp next; uint size; - _Py_AllocatedBlocks++; - #ifdef WITH_VALGRIND if (UNLIKELY(running_on_valgrind == -1)) running_on_valgrind = RUNNING_ON_VALGRIND; @@ -1119,6 +786,17 @@ #endif /* + * Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes. + * Most python internals blindly use a signed Py_ssize_t to track + * things without checking for overflows or negatives. + * As size_t is unsigned, checking for nbytes < 0 is not required. + */ + if (nbytes > PY_SSIZE_T_MAX) + return NULL; + + _Py_AllocatedBlocks++; + + /* * This implicitly redirects malloc(0). */ if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) { @@ -1290,8 +968,10 @@ * last chance to serve the request) or when the max memory limit * has been reached. */ + if (nbytes == 0) + nbytes = 1; { - void *result = PyMem_Malloc(nbytes); + void *result = malloc(nbytes); if (!result) _Py_AllocatedBlocks--; return result; @@ -1300,8 +980,9 @@ /* free */ -static void -_PyObject_Free(void *ctx, void *p) +#undef PyObject_Free +void +PyObject_Free(void *p) { poolp pool; block *lastfree; @@ -1410,8 +1091,11 @@ unused_arena_objects = ao; /* Free the entire arena. */ - _PyObject_Arena.free(_PyObject_Arena.ctx, - (void *)ao->address, ARENA_SIZE); +#ifdef ARENAS_USE_MMAP + munmap((void *)ao->address, ARENA_SIZE); +#else + free((void *)ao->address); +#endif ao->address = 0; /* mark unassociated */ --narenas_currently_allocated; @@ -1520,7 +1204,7 @@ redirect: #endif /* We didn't allocate this address. */ - PyMem_Free(p); + free(p); } /* realloc. If p is NULL, this acts like malloc(nbytes). Else if nbytes==0, @@ -1528,8 +1212,9 @@ * return a non-NULL result. */ -static void * -_PyObject_Realloc(void *ctx, void *p, size_t nbytes) +#undef PyObject_Realloc +void * +PyObject_Realloc(void *p, size_t nbytes) { void *bp; poolp pool; @@ -1539,7 +1224,16 @@ #endif if (p == NULL) - return _PyObject_Malloc(ctx, nbytes); + return PyObject_Malloc(nbytes); + + /* + * Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes. + * Most python internals blindly use a signed Py_ssize_t to track + * things without checking for overflows or negatives. + * As size_t is unsigned, checking for nbytes < 0 is not required. + */ + if (nbytes > PY_SSIZE_T_MAX) + return NULL; #ifdef WITH_VALGRIND /* Treat running_on_valgrind == -1 the same as 0 */ @@ -1567,10 +1261,10 @@ } size = nbytes; } - bp = _PyObject_Malloc(ctx, nbytes); + bp = PyObject_Malloc(nbytes); if (bp != NULL) { memcpy(bp, p, size); - _PyObject_Free(ctx, p); + PyObject_Free(p); } return bp; } @@ -1588,14 +1282,14 @@ * at p. Instead we punt: let C continue to manage this block. */ if (nbytes) - return PyMem_Realloc(p, nbytes); + return realloc(p, nbytes); /* C doesn't define the result of realloc(p, 0) (it may or may not * return NULL then), but Python's docs promise that nbytes==0 never * returns NULL. We don't pass 0 to realloc(), to avoid that endcase * to begin with. Even then, we can't be sure that realloc() won't * return NULL. */ - bp = PyMem_Realloc(p, 1); + bp = realloc(p, 1); return bp ? bp : p; } @@ -1605,6 +1299,24 @@ /* pymalloc not enabled: Redirect the entry points to malloc. These will * only be used by extensions that are compiled with pymalloc enabled. */ +void * +PyObject_Malloc(size_t n) +{ + return PyMem_MALLOC(n); +} + +void * +PyObject_Realloc(void *p, size_t n) +{ + return PyMem_REALLOC(p, n); +} + +void +PyObject_Free(void *p) +{ + PyMem_FREE(p); +} + Py_ssize_t _Py_GetAllocatedBlocks(void) { @@ -1630,6 +1342,10 @@ #define DEADBYTE 0xDB /* dead (newly freed) memory */ #define FORBIDDENBYTE 0xFB /* untouchable bytes at each end of a block */ +/* We tag each block with an API ID in order to tag API violations */ +#define _PYMALLOC_MEM_ID 'm' /* the PyMem_Malloc() API */ +#define _PYMALLOC_OBJ_ID 'o' /* The PyObject_Malloc() API */ + static size_t serialno = 0; /* incremented on each debug {m,re}alloc */ /* serialno is always incremented via calling this routine. The point is @@ -1712,18 +1428,58 @@ p[2*S+n: 2*S+n+S] Copies of FORBIDDENBYTE. Used to catch over- writes and reads. p[2*S+n+S: 2*S+n+2*S] - A serial number, incremented by 1 on each call to _PyMem_DebugMalloc - and _PyMem_DebugRealloc. + A serial number, incremented by 1 on each call to _PyObject_DebugMalloc + and _PyObject_DebugRealloc. This is a big-endian size_t. If "bad memory" is detected later, the serial number gives an excellent way to set a breakpoint on the next run, to capture the instant at which this block was passed out. */ -static void * -_PyMem_DebugMalloc(void *ctx, size_t nbytes) +/* debug replacements for the PyMem_* memory API */ +void * +_PyMem_DebugMalloc(size_t nbytes) { - debug_alloc_api_t *api = (debug_alloc_api_t *)ctx; + return _PyObject_DebugMallocApi(_PYMALLOC_MEM_ID, nbytes); +} +void * +_PyMem_DebugRealloc(void *p, size_t nbytes) +{ + return _PyObject_DebugReallocApi(_PYMALLOC_MEM_ID, p, nbytes); +} +void +_PyMem_DebugFree(void *p) +{ + _PyObject_DebugFreeApi(_PYMALLOC_MEM_ID, p); +} + +/* debug replacements for the PyObject_* memory API */ +void * +_PyObject_DebugMalloc(size_t nbytes) +{ + return _PyObject_DebugMallocApi(_PYMALLOC_OBJ_ID, nbytes); +} +void * +_PyObject_DebugRealloc(void *p, size_t nbytes) +{ + return _PyObject_DebugReallocApi(_PYMALLOC_OBJ_ID, p, nbytes); +} +void +_PyObject_DebugFree(void *p) +{ + _PyObject_DebugFreeApi(_PYMALLOC_OBJ_ID, p); +} +void +_PyObject_DebugCheckAddress(const void *p) +{ + _PyObject_DebugCheckAddressApi(_PYMALLOC_OBJ_ID, p); +} + + +/* generic debug memory api, with an "id" to identify the API in use */ +void * +_PyObject_DebugMallocApi(char id, size_t nbytes) +{ uchar *p; /* base address of malloc'ed block */ uchar *tail; /* p + 2*SST + nbytes == pointer to tail pad bytes */ size_t total; /* nbytes + 4*SST */ @@ -1734,14 +1490,14 @@ /* overflow: can't represent total as a size_t */ return NULL; - p = (uchar *)api->alloc.malloc(api->alloc.ctx, total); + p = (uchar *)PyObject_Malloc(total); if (p == NULL) return NULL; /* at p, write size (SST bytes), id (1 byte), pad (SST-1 bytes) */ write_size_t(p, nbytes); - p[SST] = (uchar)api->api_id; - memset(p + SST + 1, FORBIDDENBYTE, SST-1); + p[SST] = (uchar)id; + memset(p + SST + 1 , FORBIDDENBYTE, SST-1); if (nbytes > 0) memset(p + 2*SST, CLEANBYTE, nbytes); @@ -1759,37 +1515,35 @@ Then fills the original bytes with DEADBYTE. Then calls the underlying free. */ -static void -_PyMem_DebugFree(void *ctx, void *p) +void +_PyObject_DebugFreeApi(char api, void *p) { - debug_alloc_api_t *api = (debug_alloc_api_t *)ctx; uchar *q = (uchar *)p - 2*SST; /* address returned from malloc */ size_t nbytes; if (p == NULL) return; - _PyMem_DebugCheckAddress(api->api_id, p); + _PyObject_DebugCheckAddressApi(api, p); nbytes = read_size_t(q); nbytes += 4*SST; if (nbytes > 0) memset(q, DEADBYTE, nbytes); - api->alloc.free(api->alloc.ctx, q); + PyObject_Free(q); } -static void * -_PyMem_DebugRealloc(void *ctx, void *p, size_t nbytes) +void * +_PyObject_DebugReallocApi(char api, void *p, size_t nbytes) { - debug_alloc_api_t *api = (debug_alloc_api_t *)ctx; - uchar *q = (uchar *)p, *oldq; + uchar *q = (uchar *)p; uchar *tail; size_t total; /* nbytes + 4*SST */ size_t original_nbytes; int i; if (p == NULL) - return _PyMem_DebugMalloc(ctx, nbytes); + return _PyObject_DebugMallocApi(api, nbytes); - _PyMem_DebugCheckAddress(api->api_id, p); + _PyObject_DebugCheckAddressApi(api, p); bumpserialno(); original_nbytes = read_size_t(q - 2*SST); total = nbytes + 4*SST; @@ -1797,26 +1551,24 @@ /* overflow: can't represent total as a size_t */ return NULL; + if (nbytes < original_nbytes) { + /* shrinking: mark old extra memory dead */ + memset(q + nbytes, DEADBYTE, original_nbytes - nbytes + 2*SST); + } + /* Resize and add decorations. We may get a new pointer here, in which * case we didn't get the chance to mark the old memory with DEADBYTE, * but we live with that. */ - oldq = q; - q = (uchar *)api->alloc.realloc(api->alloc.ctx, q - 2*SST, total); + q = (uchar *)PyObject_Realloc(q - 2*SST, total); if (q == NULL) return NULL; - if (q == oldq && nbytes < original_nbytes) { - /* shrinking: mark old extra memory dead */ - memset(q + nbytes, DEADBYTE, original_nbytes - nbytes); - } - write_size_t(q, nbytes); - assert(q[SST] == (uchar)api->api_id); + assert(q[SST] == (uchar)api); for (i = 1; i < SST; ++i) assert(q[SST + i] == FORBIDDENBYTE); q += 2*SST; - tail = q + nbytes; memset(tail, FORBIDDENBYTE, SST); write_size_t(tail + SST, serialno); @@ -1835,8 +1587,8 @@ * and call Py_FatalError to kill the program. * The API id, is also checked. */ -static void -_PyMem_DebugCheckAddress(char api, const void *p) + void +_PyObject_DebugCheckAddressApi(char api, const void *p) { const uchar *q = (const uchar *)p; char msgbuf[64]; @@ -1888,7 +1640,7 @@ } /* Display info to stderr about the memory block at p. */ -static void +void _PyObject_DebugDumpAddress(const void *p) { const uchar *q = (const uchar *)p; @@ -2011,7 +1763,7 @@ k = 3; do { size_t nextvalue = value / 10; - unsigned int digit = (unsigned int)(value - nextvalue * 10); + uint digit = (uint)(value - nextvalue * 10); value = nextvalue; buf[i--] = (char)(digit + '0'); --k; diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/setobject.c --- a/Objects/setobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/setobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -214,6 +214,7 @@ set_insert_key(register PySetObject *so, PyObject *key, Py_hash_t hash) { register setentry *entry; + typedef setentry *(*lookupfunc)(PySetObject *, PyObject *, Py_hash_t); assert(so->lookup != NULL); entry = so->lookup(so, key, hash); diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/asciilib.h --- a/Objects/stringlib/asciilib.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/asciilib.h Fri Feb 01 23:12:09 2013 +0100 @@ -19,6 +19,7 @@ #define STRINGLIB_STR PyUnicode_1BYTE_DATA #define STRINGLIB_LEN PyUnicode_GET_LENGTH #define STRINGLIB_NEW(STR,LEN) _PyUnicode_FromASCII((char*)(STR),(LEN)) +#define STRINGLIB_RESIZE not_supported #define STRINGLIB_CHECK PyUnicode_Check #define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/fastsearch.h --- a/Objects/stringlib/fastsearch.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/fastsearch.h Fri Feb 01 23:12:09 2013 +0100 @@ -142,8 +142,6 @@ mask = 0; if (mode != FAST_RSEARCH) { - const STRINGLIB_CHAR *ss = s + m - 1; - const STRINGLIB_CHAR *pp = p + m - 1; /* create compressed boyer-moore delta 1 table */ @@ -158,7 +156,7 @@ for (i = 0; i <= w; i++) { /* note: using mlast in the skip path slows things down on x86 */ - if (ss[i] == pp[0]) { + if (s[i+m-1] == p[m-1]) { /* candidate match */ for (j = 0; j < mlast; j++) if (s[i+j] != p[j]) @@ -174,13 +172,13 @@ continue; } /* miss: check if next character is part of pattern */ - if (!STRINGLIB_BLOOM(mask, ss[i+1])) + if (!STRINGLIB_BLOOM(mask, s[i+m])) i = i + m; else i = i + skip; } else { /* skip: check if next character is part of pattern */ - if (!STRINGLIB_BLOOM(mask, ss[i+1])) + if (!STRINGLIB_BLOOM(mask, s[i+m])) i = i + m; } } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/replace.h --- a/Objects/stringlib/replace.h Fri Jul 26 23:14:22 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* stringlib: replace implementation */ - -#ifndef STRINGLIB_FASTSEARCH_H -#error must include "stringlib/fastsearch.h" before including this module -#endif - -Py_LOCAL_INLINE(void) -STRINGLIB(replace_1char_inplace)(STRINGLIB_CHAR* s, STRINGLIB_CHAR* end, - Py_UCS4 u1, Py_UCS4 u2, Py_ssize_t maxcount) -{ - *s = u2; - while (--maxcount && ++s != end) { - /* Find the next character to be replaced. - - If it occurs often, it is faster to scan for it using an inline - loop. If it occurs seldom, it is faster to scan for it using a - function call; the overhead of the function call is amortized - across the many characters that call covers. We start with an - inline loop and use a heuristic to determine whether to fall back - to a function call. */ - if (*s != u1) { - int attempts = 10; - /* search u1 in a dummy loop */ - while (1) { - if (++s == end) - return; - if (*s == u1) - break; - if (!--attempts) { - /* if u1 was not found for attempts iterations, - use FASTSEARCH() or memchr() */ -#if STRINGLIB_SIZEOF_CHAR == 1 - s++; - s = memchr(s, u1, end - s); - if (s == NULL) - return; -#else - Py_ssize_t i; - STRINGLIB_CHAR ch1 = (STRINGLIB_CHAR) u1; - s++; - i = FASTSEARCH(s, end - s, &ch1, 1, 0, FAST_SEARCH); - if (i < 0) - return; - s += i; -#endif - /* restart the dummy loop */ - break; - } - } - } - *s = u2; - } -} diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/stringdefs.h --- a/Objects/stringlib/stringdefs.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/stringdefs.h Fri Feb 01 23:12:09 2013 +0100 @@ -21,6 +21,7 @@ #define STRINGLIB_STR PyBytes_AS_STRING #define STRINGLIB_LEN PyBytes_GET_SIZE #define STRINGLIB_NEW PyBytes_FromStringAndSize +#define STRINGLIB_RESIZE _PyBytes_Resize #define STRINGLIB_CHECK PyBytes_Check #define STRINGLIB_CHECK_EXACT PyBytes_CheckExact #define STRINGLIB_TOSTR PyObject_Str diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/transmogrify.h --- a/Objects/stringlib/transmogrify.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/transmogrify.h Fri Feb 01 23:12:09 2013 +0100 @@ -18,10 +18,10 @@ size_t i, j; PyObject *u; int tabsize = 8; - + if (!PyArg_ParseTuple(args, "|i:expandtabs", &tabsize)) return NULL; - + /* First pass: determine size of output string */ i = j = 0; e = STRINGLIB_STR(self) + STRINGLIB_LEN(self); @@ -48,20 +48,20 @@ } } } - + if ((i + j) > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "result is too long"); return NULL; } - + /* Second pass: create output string and fill it */ u = STRINGLIB_NEW(NULL, i + j); if (!u) return NULL; - + j = 0; q = STRINGLIB_STR(u); - + for (p = STRINGLIB_STR(self); p < e; p++) if (*p == '\t') { if (tabsize > 0) { @@ -77,7 +77,7 @@ if (*p == '\n' || *p == '\r') j = 0; } - + return u; } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/ucs1lib.h --- a/Objects/stringlib/ucs1lib.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/ucs1lib.h Fri Feb 01 23:12:09 2013 +0100 @@ -19,6 +19,7 @@ #define STRINGLIB_STR PyUnicode_1BYTE_DATA #define STRINGLIB_LEN PyUnicode_GET_LENGTH #define STRINGLIB_NEW _PyUnicode_FromUCS1 +#define STRINGLIB_RESIZE not_supported #define STRINGLIB_CHECK PyUnicode_Check #define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/ucs2lib.h --- a/Objects/stringlib/ucs2lib.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/ucs2lib.h Fri Feb 01 23:12:09 2013 +0100 @@ -19,6 +19,7 @@ #define STRINGLIB_STR PyUnicode_2BYTE_DATA #define STRINGLIB_LEN PyUnicode_GET_LENGTH #define STRINGLIB_NEW _PyUnicode_FromUCS2 +#define STRINGLIB_RESIZE not_supported #define STRINGLIB_CHECK PyUnicode_Check #define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/ucs4lib.h --- a/Objects/stringlib/ucs4lib.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/ucs4lib.h Fri Feb 01 23:12:09 2013 +0100 @@ -19,6 +19,7 @@ #define STRINGLIB_STR PyUnicode_4BYTE_DATA #define STRINGLIB_LEN PyUnicode_GET_LENGTH #define STRINGLIB_NEW _PyUnicode_FromUCS4 +#define STRINGLIB_RESIZE not_supported #define STRINGLIB_CHECK PyUnicode_Check #define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/undef.h --- a/Objects/stringlib/undef.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/undef.h Fri Feb 01 23:12:09 2013 +0100 @@ -6,6 +6,7 @@ #undef STRINGLIB_STR #undef STRINGLIB_LEN #undef STRINGLIB_NEW +#undef STRINGLIB_RESIZE #undef _Py_InsertThousandsGrouping #undef STRINGLIB_IS_UNICODE diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/unicode_format.h --- a/Objects/stringlib/unicode_format.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/unicode_format.h Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,12 @@ unicode_format.h -- implementation of str.format(). */ +/* Defines for more efficiently reallocating the string buffer */ +#define INITIAL_SIZE_INCREMENT 100 +#define SIZE_MULTIPLIER 2 +#define MAX_SIZE_INCREMENT 3200 + + /************************************************************************/ /*********** Global data structures and forward declarations *********/ /************************************************************************/ @@ -543,7 +549,7 @@ static int parse_field(SubString *str, SubString *field_name, SubString *format_spec, - int *format_spec_needs_expanding, Py_UCS4 *conversion) + Py_UCS4 *conversion) { /* Note this function works if the field name is zero length, which is good. Zero length field names are handled later, in @@ -561,15 +567,6 @@ field_name->start = str->start; while (str->start < str->end) { switch ((c = PyUnicode_READ_CHAR(str->str, str->start++))) { - case '{': - PyErr_SetString(PyExc_ValueError, "unexpected '{' in field name"); - return 0; - case '[': - for (; str->start < str->end; str->start++) - if (PyUnicode_READ_CHAR(str->str, str->start) == ']') - break; - continue; - case '}': case ':': case '!': break; @@ -579,62 +576,41 @@ break; } - field_name->end = str->start - 1; if (c == '!' || c == ':') { - Py_ssize_t count; /* we have a format specifier and/or a conversion */ /* don't include the last character */ + field_name->end = str->start-1; + + /* the format specifier is the rest of the string */ + format_spec->str = str->str; + format_spec->start = str->start; + format_spec->end = str->end; /* see if there's a conversion specifier */ if (c == '!') { /* there must be another character present */ - if (str->start >= str->end) { + if (format_spec->start >= format_spec->end) { PyErr_SetString(PyExc_ValueError, - "end of string while looking for conversion " + "end of format while looking for conversion " "specifier"); return 0; } - *conversion = PyUnicode_READ_CHAR(str->str, str->start++); + *conversion = PyUnicode_READ_CHAR(format_spec->str, format_spec->start++); - if (str->start < str->end) { - c = PyUnicode_READ_CHAR(str->str, str->start++); - if (c == '}') - return 1; + /* if there is another character, it must be a colon */ + if (format_spec->start < format_spec->end) { + c = PyUnicode_READ_CHAR(format_spec->str, format_spec->start++); if (c != ':') { PyErr_SetString(PyExc_ValueError, - "expected ':' after conversion specifier"); + "expected ':' after format specifier"); return 0; } } } - format_spec->str = str->str; - format_spec->start = str->start; - count = 1; - while (str->start < str->end) { - switch ((c = PyUnicode_READ_CHAR(str->str, str->start++))) { - case '{': - *format_spec_needs_expanding = 1; - count++; - break; - case '}': - count--; - if (count == 0) { - format_spec->end = str->start - 1; - return 1; - } - break; - default: - break; - } - } - - PyErr_SetString(PyExc_ValueError, "unmatched '{' in format spec"); - return 0; } - else if (c != '}') { - PyErr_SetString(PyExc_ValueError, "expected '}' before end of string"); - return 0; - } + else + /* end of string, there's no format_spec or conversion */ + field_name->end = str->start; return 1; } @@ -671,6 +647,7 @@ int at_end; Py_UCS4 c = 0; Py_ssize_t start; + int count; Py_ssize_t len; int markup_follows = 0; @@ -742,12 +719,44 @@ if (!markup_follows) return 2; - /* this is markup; parse the field */ + /* this is markup, find the end of the string by counting nested + braces. note that this prohibits escaped braces, so that + format_specs cannot have braces in them. */ *field_present = 1; - if (!parse_field(&self->str, field_name, format_spec, - format_spec_needs_expanding, conversion)) - return 0; - return 2; + count = 1; + + start = self->str.start; + + /* we know we can't have a zero length string, so don't worry + about that case */ + while (self->str.start < self->str.end) { + switch (c = PyUnicode_READ_CHAR(self->str.str, self->str.start++)) { + case '{': + /* the format spec needs to be recursively expanded. + this is an optimization, and not strictly needed */ + *format_spec_needs_expanding = 1; + count++; + break; + case '}': + count--; + if (count <= 0) { + /* we're done. parse and get out */ + SubString s; + + SubString_init(&s, self->str.str, start, self->str.start - 1); + if (parse_field(&s, field_name, format_spec, conversion) == 0) + return 0; + + /* success */ + return 2; + } + break; + } + } + + /* end of string while searching for matching '}' */ + PyErr_SetString(PyExc_ValueError, "unmatched '{' in format"); + return 0; } @@ -866,19 +875,25 @@ SubString literal; SubString field_name; SubString format_spec; - Py_UCS4 conversion; + Py_UCS4 conversion, maxchar; + Py_ssize_t sublen; + int err; MarkupIterator_init(&iter, input->str, input->start, input->end); while ((result = MarkupIterator_next(&iter, &literal, &field_present, &field_name, &format_spec, &conversion, &format_spec_needs_expanding)) == 2) { - if (literal.end != literal.start) { - if (!field_present && iter.str.start == iter.str.end) - writer->overallocate = 0; - if (_PyUnicodeWriter_WriteSubstring(writer, literal.str, - literal.start, literal.end) < 0) + sublen = literal.end - literal.start; + if (sublen) { + maxchar = _PyUnicode_FindMaxChar(literal.str, + literal.start, literal.end); + err = _PyUnicodeWriter_Prepare(writer, sublen, maxchar); + if (err == -1) return 0; + _PyUnicode_FastCopyCharacters(writer->buffer, writer->pos, + literal.str, literal.start, sublen); + writer->pos += sublen; } if (field_present) { @@ -903,6 +918,7 @@ int recursion_depth, AutoNumber *auto_number) { _PyUnicodeWriter writer; + Py_ssize_t minlen; /* check the recursion level */ if (recursion_depth <= 0) { @@ -911,9 +927,8 @@ return NULL; } - _PyUnicodeWriter_Init(&writer); - writer.overallocate = 1; - writer.min_length = PyUnicode_GET_LENGTH(input->str) + 100; + minlen = PyUnicode_GET_LENGTH(input->str) + 100; + _PyUnicodeWriter_Init(&writer, minlen); if (!do_markup(input, args, kwargs, &writer, recursion_depth, auto_number)) { diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/stringlib/unicodedefs.h --- a/Objects/stringlib/unicodedefs.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/stringlib/unicodedefs.h Fri Feb 01 23:12:09 2013 +0100 @@ -21,6 +21,7 @@ #define STRINGLIB_STR PyUnicode_AS_UNICODE #define STRINGLIB_LEN PyUnicode_GET_SIZE #define STRINGLIB_NEW PyUnicode_FromUnicode +#define STRINGLIB_RESIZE PyUnicode_Resize #define STRINGLIB_CHECK PyUnicode_Check #define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/structseq.c --- a/Objects/structseq.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/structseq.c Fri Feb 01 23:12:09 2013 +0100 @@ -11,20 +11,17 @@ /* Fields with this name have only a field index, not a field name. They are only allowed for indices < n_visible_fields. */ char *PyStructSequence_UnnamedField = "unnamed field"; -_Py_IDENTIFIER(n_sequence_fields); -_Py_IDENTIFIER(n_fields); -_Py_IDENTIFIER(n_unnamed_fields); #define VISIBLE_SIZE(op) Py_SIZE(op) #define VISIBLE_SIZE_TP(tp) PyLong_AsLong( \ - _PyDict_GetItemId((tp)->tp_dict, &PyId_n_sequence_fields)) + PyDict_GetItemString((tp)->tp_dict, visible_length_key)) #define REAL_SIZE_TP(tp) PyLong_AsLong( \ - _PyDict_GetItemId((tp)->tp_dict, &PyId_n_fields)) + PyDict_GetItemString((tp)->tp_dict, real_length_key)) #define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op)) #define UNNAMED_FIELDS_TP(tp) PyLong_AsLong( \ - _PyDict_GetItemId((tp)->tp_dict, &PyId_n_unnamed_fields)) + PyDict_GetItemString((tp)->tp_dict, unnamed_fields_key)) #define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op)) @@ -62,7 +59,7 @@ structseq_dealloc(PyStructSequence *obj) { Py_ssize_t i, size; - + size = REAL_SIZE(obj); for (i = 0; i < size; ++i) { Py_XDECREF(obj->ob_item[i]); @@ -233,8 +230,8 @@ static PyObject * structseq_reduce(PyStructSequence* self) { - PyObject* tup = NULL; - PyObject* dict = NULL; + PyObject* tup; + PyObject* dict; PyObject* result; Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields; int i; @@ -243,12 +240,15 @@ n_visible_fields = VISIBLE_SIZE(self); n_unnamed_fields = UNNAMED_FIELDS(self); tup = PyTuple_New(n_visible_fields); - if (!tup) - goto error; + if (!tup) { + return NULL; + } dict = PyDict_New(); - if (!dict) - goto error; + if (!dict) { + Py_DECREF(tup); + return NULL; + } for (i = 0; i < n_visible_fields; i++) { Py_INCREF(self->ob_item[i]); @@ -257,8 +257,8 @@ for (; i < n_fields; i++) { char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name; - if (PyDict_SetItemString(dict, n, self->ob_item[i]) < 0) - goto error; + PyDict_SetItemString(dict, n, + self->ob_item[i]); } result = Py_BuildValue("(O(OO))", Py_TYPE(self), tup, dict); @@ -267,11 +267,6 @@ Py_DECREF(dict); return result; - -error: - Py_XDECREF(tup); - Py_XDECREF(dict); - return NULL; } static PyMethodDef structseq_methods[] = { @@ -320,13 +315,12 @@ structseq_new, /* tp_new */ }; -int -PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc) +void +PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc) { PyObject *dict; PyMemberDef* members; int n_members, n_unnamed_members, i, k; - PyObject *v; #ifdef Py_TRACE_REFS /* if the type object was chained, unchain it first @@ -348,10 +342,8 @@ type->tp_doc = desc->doc; members = PyMem_NEW(PyMemberDef, n_members-n_unnamed_members+1); - if (members == NULL) { - PyErr_NoMemory(); - return -1; - } + if (members == NULL) + return; for (i = k = 0; i < n_members; ++i) { if (desc->fields[i].name == PyStructSequence_UnnamedField) @@ -369,56 +361,30 @@ type->tp_members = members; if (PyType_Ready(type) < 0) - return -1; + return; Py_INCREF(type); dict = type->tp_dict; #define SET_DICT_FROM_INT(key, value) \ do { \ - v = PyLong_FromLong((long) value); \ - if (v == NULL) \ - return -1; \ - if (PyDict_SetItemString(dict, key, v) < 0) { \ + PyObject *v = PyLong_FromLong((long) value); \ + if (v != NULL) { \ + PyDict_SetItemString(dict, key, v); \ Py_DECREF(v); \ - return -1; \ } \ - Py_DECREF(v); \ } while (0) SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence); SET_DICT_FROM_INT(real_length_key, n_members); SET_DICT_FROM_INT(unnamed_fields_key, n_unnamed_members); - - return 0; -} - -void -PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc) -{ - (void)PyStructSequence_InitType2(type, desc); } PyTypeObject* PyStructSequence_NewType(PyStructSequence_Desc *desc) { - PyTypeObject *result; - - result = (PyTypeObject*)PyType_GenericAlloc(&PyType_Type, 0); - if (result == NULL) - return NULL; - if (PyStructSequence_InitType2(result, desc) < 0) { - Py_DECREF(result); - return NULL; + PyTypeObject *result = (PyTypeObject*)PyType_GenericAlloc(&PyType_Type, 0); + if (result != NULL) { + PyStructSequence_InitType(result, desc); } return result; } - -int _PyStructSequence_Init(void) -{ - if (_PyUnicode_FromId(&PyId_n_sequence_fields) == NULL - || _PyUnicode_FromId(&PyId_n_fields) == NULL - || _PyUnicode_FromId(&PyId_n_unnamed_fields) == NULL) - return -1; - - return 0; -} diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/tupleobject.c --- a/Objects/tupleobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/tupleobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -930,7 +930,7 @@ typedef struct { PyObject_HEAD - Py_ssize_t it_index; + long it_index; PyTupleObject *it_seq; /* Set to NULL when iterator is exhausted */ } tupleiterobject; @@ -988,7 +988,7 @@ tupleiter_reduce(tupleiterobject *it) { if (it->it_seq) - return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), + return Py_BuildValue("N(O)l", _PyObject_GetBuiltin("iter"), it->it_seq, it->it_index); else return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter")); @@ -997,7 +997,7 @@ static PyObject * tupleiter_setstate(tupleiterobject *it, PyObject *state) { - Py_ssize_t index = PyLong_AsSsize_t(state); + long index = PyLong_AsLong(state); if (index == -1 && PyErr_Occurred()) return NULL; if (it->it_seq != NULL) { diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/typeobject.c --- a/Objects/typeobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/typeobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -7,10 +7,6 @@ #include -/* Cached lookup of the copyreg module, for faster __reduce__ calls */ - -static PyObject *cached_copyreg_module = NULL; - /* Support type attribute cache */ /* The cache can keep references to the names alive for longer than @@ -73,15 +69,6 @@ } void -_PyType_Fini(void) -{ - PyType_ClearCache(); - /* Need to forget our obsolete instance of the copyreg module at - * interpreter shutdown (issue #17408). */ - Py_CLEAR(cached_copyreg_module); -} - -void PyType_Modified(PyTypeObject *type) { /* Invalidate any cached data for the specified type and all @@ -311,13 +298,10 @@ Py_INCREF(value); - /* Wait until et is a sane state before Py_DECREF'ing the old et->ht_name - value. (Bug #16447.) */ - tmp = et->ht_name; + Py_DECREF(et->ht_name); et->ht_name = value; type->tp_name = tp_name; - Py_DECREF(tmp); return 0; } @@ -736,13 +720,6 @@ return NULL; } -#ifdef Py_DEBUG - /* type_call() must not be called with an exception set, - because it may clear it (directly or indirectly) and so the - caller looses its exception */ - assert(!PyErr_Occurred()); -#endif - obj = type->tp_new(type, args, kwds); if (obj != NULL) { /* Ugly exception: when the call was type(something), @@ -757,12 +734,10 @@ if (!PyType_IsSubtype(Py_TYPE(obj), type)) return obj; type = Py_TYPE(obj); - if (type->tp_init != NULL) { - int res = type->tp_init(obj, args, kwds); - if (res < 0) { - Py_DECREF(obj); - obj = NULL; - } + if (type->tp_init != NULL && + type->tp_init(obj, args, kwds) < 0) { + Py_DECREF(obj); + obj = NULL; } } return obj; @@ -1465,10 +1440,8 @@ that is not included in acc. */ remain = (int *)PyMem_MALLOC(SIZEOF_INT*to_merge_size); - if (remain == NULL) { - PyErr_NoMemory(); + if (remain == NULL) return -1; - } for (i = 0; i < to_merge_size; i++) remain[i] = 0; @@ -1500,7 +1473,7 @@ } ok = PyList_Append(acc, candidate); if (ok < 0) { - PyMem_FREE(remain); + PyMem_Free(remain); return -1; } for (j = 0; j < to_merge_size; j++) { @@ -2301,10 +2274,8 @@ /* Silently truncate the docstring if it contains null bytes. */ len = strlen(doc_str); tp_doc = (char *)PyObject_MALLOC(len + 1); - if (tp_doc == NULL) { - PyErr_NoMemory(); + if (tp_doc == NULL) goto error; - } memcpy(tp_doc, doc_str, len + 1); type->tp_doc = tp_doc; } @@ -2424,7 +2395,7 @@ char *s; char *res_start = (char*)res; PyType_Slot *slot; - + /* Set the type name and qualname */ s = strrchr(spec->name, '.'); if (s == NULL) @@ -2445,7 +2416,7 @@ type->tp_name = spec->name; if (!type->tp_name) goto fail; - + /* Adjust for empty tuple bases */ if (!bases) { base = &PyBaseObject_Type; @@ -2507,10 +2478,8 @@ if (slot->slot == Py_tp_doc) { size_t len = strlen(slot->pfunc)+1; char *tp_doc = PyObject_MALLOC(len); - if (tp_doc == NULL) { - PyErr_NoMemory(); + if (tp_doc == NULL) goto fail; - } memcpy(tp_doc, slot->pfunc, len); type->tp_doc = tp_doc; } @@ -2531,7 +2500,7 @@ /* Set type.__module__ */ s = strrchr(spec->name, '.'); if (s != NULL) - _PyDict_SetItemId(type->tp_dict, &PyId___module__, + _PyDict_SetItemId(type->tp_dict, &PyId___module__, PyUnicode_FromStringAndSize( spec->name, (Py_ssize_t)(s - spec->name))); @@ -3090,7 +3059,7 @@ { if (excess_args(args, kwds) && (type->tp_init == object_init || type->tp_new != object_new)) { - PyErr_SetString(PyExc_TypeError, "object() takes no parameters"); + PyErr_SetString(PyExc_TypeError, "object.__new__() takes no parameters"); return NULL; } @@ -3338,7 +3307,7 @@ "__class__ assignment: only for heap types"); return -1; } - if (compatible_for_assignment(oldto, newto, "__class__")) { + if (compatible_for_assignment(newto, oldto, "__class__")) { Py_INCREF(newto); Py_TYPE(self) = newto; Py_DECREF(oldto); @@ -3367,18 +3336,19 @@ import_copyreg(void) { static PyObject *copyreg_str; + static PyObject *mod_copyreg = NULL; if (!copyreg_str) { copyreg_str = PyUnicode_InternFromString("copyreg"); if (copyreg_str == NULL) return NULL; } - if (!cached_copyreg_module) { - cached_copyreg_module = PyImport_Import(copyreg_str); - } - - Py_XINCREF(cached_copyreg_module); - return cached_copyreg_module; + if (!mod_copyreg) { + mod_copyreg = PyImport_Import(copyreg_str); + } + + Py_XINCREF(mod_copyreg); + return mod_copyreg; } static PyObject * @@ -4263,15 +4233,11 @@ PyObject *doc = PyUnicode_FromString(type->tp_doc); if (doc == NULL) goto error; - if (_PyDict_SetItemId(type->tp_dict, &PyId___doc__, doc) < 0) { - Py_DECREF(doc); - goto error; - } + _PyDict_SetItemId(type->tp_dict, &PyId___doc__, doc); Py_DECREF(doc); } else { - if (_PyDict_SetItemId(type->tp_dict, - &PyId___doc__, Py_None) < 0) - goto error; + _PyDict_SetItemId(type->tp_dict, + &PyId___doc__, Py_None); } } @@ -4348,8 +4314,6 @@ } assert(PyList_Check(list)); newobj = PyWeakref_NewRef((PyObject *)type, NULL); - if (newobj == NULL) - return -1; i = PyList_GET_SIZE(list); while (--i >= 0) { ref = PyList_GET_ITEM(list, i); @@ -5293,12 +5257,29 @@ _Py_IDENTIFIER(__str__); func = lookup_method(self, &PyId___str__); - if (func == NULL) - return NULL; + if (func != NULL) { res = PyEval_CallObject(func, NULL); Py_DECREF(func); return res; } + else { + /* PyObject *ress; */ + PyErr_Clear(); + res = slot_tp_repr(self); + if (!res) + return NULL; + /* XXX this is non-sensical. Why should we return + a bytes object from __str__. Is this code even + used? - mvl */ + assert(0); + return res; + /* + ress = _PyUnicode_AsDefaultEncodedString(res); + Py_DECREF(res); + return ress; + */ + } +} static Py_hash_t slot_tp_hash(PyObject *self) @@ -5677,16 +5658,15 @@ } -/* -Table mapping __foo__ names to tp_foo offsets and slot_tp_foo wrapper functions. - -The table is ordered by offsets relative to the 'PyHeapTypeObject' structure, -which incorporates the additional structures used for numbers, sequences and -mappings. Note that multiple names may map to the same slot (e.g. __eq__, -__ne__ etc. all map to tp_richcompare) and one name may map to multiple slots -(e.g. __str__ affects tp_str as well as tp_repr). The table is terminated with -an all-zero entry. (This table is further initialized in init_slotdefs().) -*/ +/* Table mapping __foo__ names to tp_foo offsets and slot_tp_foo wrapper + functions. The offsets here are relative to the 'PyHeapTypeObject' + structure, which incorporates the additional structures used for numbers, + sequences and mappings. + Note that multiple names may map to the same slot (e.g. __eq__, + __ne__ etc. all map to tp_richcompare) and one name may map to multiple + slots (e.g. __str__ affects tp_str as well as tp_repr). The table is + terminated with an all-zero entry. (This table is further initialized and + sorted in init_slotdefs() below.) */ typedef struct wrapperbase slotdef; @@ -5736,53 +5716,43 @@ "x." NAME "(y) <==> " DOC) static slotdef slotdefs[] = { - TPSLOT("__getattribute__", tp_getattr, NULL, NULL, ""), - TPSLOT("__getattr__", tp_getattr, NULL, NULL, ""), - TPSLOT("__setattr__", tp_setattr, NULL, NULL, ""), - TPSLOT("__delattr__", tp_setattr, NULL, NULL, ""), - TPSLOT("__repr__", tp_repr, slot_tp_repr, wrap_unaryfunc, - "x.__repr__() <==> repr(x)"), - TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc, - "x.__hash__() <==> hash(x)"), - FLSLOT("__call__", tp_call, slot_tp_call, (wrapperfunc)wrap_call, - "x.__call__(...) <==> x(...)", PyWrapperFlag_KEYWORDS), - TPSLOT("__str__", tp_str, slot_tp_str, wrap_unaryfunc, - "x.__str__() <==> str(x)"), - TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook, - wrap_binaryfunc, "x.__getattribute__('name') <==> x.name"), - TPSLOT("__getattr__", tp_getattro, slot_tp_getattr_hook, NULL, ""), - TPSLOT("__setattr__", tp_setattro, slot_tp_setattro, wrap_setattr, - "x.__setattr__('name', value) <==> x.name = value"), - TPSLOT("__delattr__", tp_setattro, slot_tp_setattro, wrap_delattr, - "x.__delattr__('name') <==> del x.name"), - TPSLOT("__lt__", tp_richcompare, slot_tp_richcompare, richcmp_lt, - "x.__lt__(y) <==> x x<=y"), - TPSLOT("__eq__", tp_richcompare, slot_tp_richcompare, richcmp_eq, - "x.__eq__(y) <==> x==y"), - TPSLOT("__ne__", tp_richcompare, slot_tp_richcompare, richcmp_ne, - "x.__ne__(y) <==> x!=y"), - TPSLOT("__gt__", tp_richcompare, slot_tp_richcompare, richcmp_gt, - "x.__gt__(y) <==> x>y"), - TPSLOT("__ge__", tp_richcompare, slot_tp_richcompare, richcmp_ge, - "x.__ge__(y) <==> x>=y"), - TPSLOT("__iter__", tp_iter, slot_tp_iter, wrap_unaryfunc, - "x.__iter__() <==> iter(x)"), - TPSLOT("__next__", tp_iternext, slot_tp_iternext, wrap_next, - "x.__next__() <==> next(x)"), - TPSLOT("__get__", tp_descr_get, slot_tp_descr_get, wrap_descr_get, - "descr.__get__(obj[, type]) -> value"), - TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set, - "descr.__set__(obj, value)"), - TPSLOT("__delete__", tp_descr_set, slot_tp_descr_set, - wrap_descr_delete, "descr.__delete__(obj)"), - FLSLOT("__init__", tp_init, slot_tp_init, (wrapperfunc)wrap_init, - "x.__init__(...) initializes x; " - "see help(type(x)) for signature", - PyWrapperFlag_KEYWORDS), - TPSLOT("__new__", tp_new, slot_tp_new, NULL, ""), - TPSLOT("__del__", tp_del, slot_tp_del, NULL, ""), + SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc, + "x.__len__() <==> len(x)"), + /* Heap types defining __add__/__mul__ have sq_concat/sq_repeat == NULL. + The logic in abstract.c always falls back to nb_add/nb_multiply in + this case. Defining both the nb_* and the sq_* slots to call the + user-defined methods has unexpected side-effects, as shown by + test_descr.notimplemented() */ + SQSLOT("__add__", sq_concat, NULL, wrap_binaryfunc, + "x.__add__(y) <==> x+y"), + SQSLOT("__mul__", sq_repeat, NULL, wrap_indexargfunc, + "x.__mul__(n) <==> x*n"), + SQSLOT("__rmul__", sq_repeat, NULL, wrap_indexargfunc, + "x.__rmul__(n) <==> n*x"), + SQSLOT("__getitem__", sq_item, slot_sq_item, wrap_sq_item, + "x.__getitem__(y) <==> x[y]"), + SQSLOT("__setitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_setitem, + "x.__setitem__(i, y) <==> x[i]=y"), + SQSLOT("__delitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_delitem, + "x.__delitem__(y) <==> del x[y]"), + SQSLOT("__contains__", sq_contains, slot_sq_contains, wrap_objobjproc, + "x.__contains__(y) <==> y in x"), + SQSLOT("__iadd__", sq_inplace_concat, NULL, + wrap_binaryfunc, "x.__iadd__(y) <==> x+=y"), + SQSLOT("__imul__", sq_inplace_repeat, NULL, + wrap_indexargfunc, "x.__imul__(y) <==> x*=y"), + + MPSLOT("__len__", mp_length, slot_mp_length, wrap_lenfunc, + "x.__len__() <==> len(x)"), + MPSLOT("__getitem__", mp_subscript, slot_mp_subscript, + wrap_binaryfunc, + "x.__getitem__(y) <==> x[y]"), + MPSLOT("__setitem__", mp_ass_subscript, slot_mp_ass_subscript, + wrap_objobjargproc, + "x.__setitem__(i, y) <==> x[i]=y"), + MPSLOT("__delitem__", mp_ass_subscript, slot_mp_ass_subscript, + wrap_delitem, + "x.__delitem__(y) <==> del x[y]"), BINSLOT("__add__", nb_add, slot_nb_add, "+"), @@ -5829,6 +5799,8 @@ "int(x)"), UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc, "float(x)"), + NBSLOT("__index__", nb_index, slot_nb_index, wrap_unaryfunc, + "x[y:z] <==> x[y.__index__():z.__index__()]"), IBSLOT("__iadd__", nb_inplace_add, slot_nb_inplace_add, wrap_binaryfunc, "+="), IBSLOT("__isub__", nb_inplace_subtract, slot_nb_inplace_subtract, @@ -5857,47 +5829,54 @@ slot_nb_inplace_floor_divide, wrap_binaryfunc, "//"), IBSLOT("__itruediv__", nb_inplace_true_divide, slot_nb_inplace_true_divide, wrap_binaryfunc, "/"), - NBSLOT("__index__", nb_index, slot_nb_index, wrap_unaryfunc, - "x[y:z] <==> x[y.__index__():z.__index__()]"), - - MPSLOT("__len__", mp_length, slot_mp_length, wrap_lenfunc, - "x.__len__() <==> len(x)"), - MPSLOT("__getitem__", mp_subscript, slot_mp_subscript, - wrap_binaryfunc, - "x.__getitem__(y) <==> x[y]"), - MPSLOT("__setitem__", mp_ass_subscript, slot_mp_ass_subscript, - wrap_objobjargproc, - "x.__setitem__(i, y) <==> x[i]=y"), - MPSLOT("__delitem__", mp_ass_subscript, slot_mp_ass_subscript, - wrap_delitem, - "x.__delitem__(y) <==> del x[y]"), - - SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc, - "x.__len__() <==> len(x)"), - /* Heap types defining __add__/__mul__ have sq_concat/sq_repeat == NULL. - The logic in abstract.c always falls back to nb_add/nb_multiply in - this case. Defining both the nb_* and the sq_* slots to call the - user-defined methods has unexpected side-effects, as shown by - test_descr.notimplemented() */ - SQSLOT("__add__", sq_concat, NULL, wrap_binaryfunc, - "x.__add__(y) <==> x+y"), - SQSLOT("__mul__", sq_repeat, NULL, wrap_indexargfunc, - "x.__mul__(n) <==> x*n"), - SQSLOT("__rmul__", sq_repeat, NULL, wrap_indexargfunc, - "x.__rmul__(n) <==> n*x"), - SQSLOT("__getitem__", sq_item, slot_sq_item, wrap_sq_item, - "x.__getitem__(y) <==> x[y]"), - SQSLOT("__setitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_setitem, - "x.__setitem__(i, y) <==> x[i]=y"), - SQSLOT("__delitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_delitem, - "x.__delitem__(y) <==> del x[y]"), - SQSLOT("__contains__", sq_contains, slot_sq_contains, wrap_objobjproc, - "x.__contains__(y) <==> y in x"), - SQSLOT("__iadd__", sq_inplace_concat, NULL, - wrap_binaryfunc, "x.__iadd__(y) <==> x+=y"), - SQSLOT("__imul__", sq_inplace_repeat, NULL, - wrap_indexargfunc, "x.__imul__(y) <==> x*=y"), - + + TPSLOT("__str__", tp_str, slot_tp_str, wrap_unaryfunc, + "x.__str__() <==> str(x)"), + TPSLOT("__repr__", tp_repr, slot_tp_repr, wrap_unaryfunc, + "x.__repr__() <==> repr(x)"), + TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc, + "x.__hash__() <==> hash(x)"), + FLSLOT("__call__", tp_call, slot_tp_call, (wrapperfunc)wrap_call, + "x.__call__(...) <==> x(...)", PyWrapperFlag_KEYWORDS), + TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook, + wrap_binaryfunc, "x.__getattribute__('name') <==> x.name"), + TPSLOT("__getattribute__", tp_getattr, NULL, NULL, ""), + TPSLOT("__getattr__", tp_getattro, slot_tp_getattr_hook, NULL, ""), + TPSLOT("__getattr__", tp_getattr, NULL, NULL, ""), + TPSLOT("__setattr__", tp_setattro, slot_tp_setattro, wrap_setattr, + "x.__setattr__('name', value) <==> x.name = value"), + TPSLOT("__setattr__", tp_setattr, NULL, NULL, ""), + TPSLOT("__delattr__", tp_setattro, slot_tp_setattro, wrap_delattr, + "x.__delattr__('name') <==> del x.name"), + TPSLOT("__delattr__", tp_setattr, NULL, NULL, ""), + TPSLOT("__lt__", tp_richcompare, slot_tp_richcompare, richcmp_lt, + "x.__lt__(y) <==> x x<=y"), + TPSLOT("__eq__", tp_richcompare, slot_tp_richcompare, richcmp_eq, + "x.__eq__(y) <==> x==y"), + TPSLOT("__ne__", tp_richcompare, slot_tp_richcompare, richcmp_ne, + "x.__ne__(y) <==> x!=y"), + TPSLOT("__gt__", tp_richcompare, slot_tp_richcompare, richcmp_gt, + "x.__gt__(y) <==> x>y"), + TPSLOT("__ge__", tp_richcompare, slot_tp_richcompare, richcmp_ge, + "x.__ge__(y) <==> x>=y"), + TPSLOT("__iter__", tp_iter, slot_tp_iter, wrap_unaryfunc, + "x.__iter__() <==> iter(x)"), + TPSLOT("__next__", tp_iternext, slot_tp_iternext, wrap_next, + "x.__next__() <==> next(x)"), + TPSLOT("__get__", tp_descr_get, slot_tp_descr_get, wrap_descr_get, + "descr.__get__(obj[, type]) -> value"), + TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set, + "descr.__set__(obj, value)"), + TPSLOT("__delete__", tp_descr_set, slot_tp_descr_set, + wrap_descr_delete, "descr.__delete__(obj)"), + FLSLOT("__init__", tp_init, slot_tp_init, (wrapperfunc)wrap_init, + "x.__init__(...) initializes x; " + "see help(type(x)) for signature", + PyWrapperFlag_KEYWORDS), + TPSLOT("__new__", tp_new, slot_tp_new, NULL, ""), + TPSLOT("__del__", tp_del, slot_tp_del, NULL, ""), {NULL} }; @@ -6078,6 +6057,21 @@ return 0; } +/* Comparison function for qsort() to compare slotdefs by their offset, and + for equal offset by their address (to force a stable sort). */ +static int +slotdef_cmp(const void *aa, const void *bb) +{ + const slotdef *a = (const slotdef *)aa, *b = (const slotdef *)bb; + int c = a->offset - b->offset; + if (c != 0) + return c; + else + /* Cannot use a-b, as this gives off_t, + which may lose precision when converted to int. */ + return (a > b) ? 1 : (a < b) ? -1 : 0; +} + /* Initialize the slotdefs table by adding interned string objects for the names and sorting the entries. */ static void @@ -6089,12 +6083,12 @@ if (initialized) return; for (p = slotdefs; p->name; p++) { - /* Slots must be ordered by their offset in the PyHeapTypeObject. */ - assert(!p[1].name || p->offset <= p[1].offset); p->name_strobj = PyUnicode_InternFromString(p->name); if (!p->name_strobj) Py_FatalError("Out of memory interning slotdef names"); } + qsort((void *)slotdefs, (size_t)(p-slotdefs), sizeof(slotdef), + slotdef_cmp); initialized = 1; } @@ -6514,18 +6508,6 @@ return -1; } obj = f->f_localsplus[0]; - if (obj == NULL && co->co_cell2arg) { - /* The first argument might be a cell. */ - n = PyTuple_GET_SIZE(co->co_cellvars); - for (i = 0; i < n; i++) { - if (co->co_cell2arg[i] == 0) { - PyObject *cell = f->f_localsplus[co->co_nlocals + i]; - assert(PyCell_Check(cell)); - obj = PyCell_GET(cell); - break; - } - } - } if (obj == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): arg[0] deleted"); diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/unicodeobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -49,9 +49,8 @@ /* --- Globals ------------------------------------------------------------ -NOTE: In the interpreter's initialization phase, some globals are currently - initialized dynamically as needed. In the process Unicode objects may - be created before the Unicode type is ready. + The globals are initialized by the _PyUnicode_Init() API and should + not be used before calling that API. */ @@ -104,6 +103,11 @@ #define _PyUnicode_DATA_ANY(op) \ (((PyUnicodeObject*)(op))->data.any) +/* Optimized version of Py_MAX() to compute the maximum character: + use it when your are computing the second argument of PyUnicode_New() */ +#define MAX_MAXCHAR(maxchar1, maxchar2) \ + ((maxchar1) | (maxchar2)) + #undef PyUnicode_READY #define PyUnicode_READY(op) \ (assert(_PyUnicode_CHECK(op)), \ @@ -122,14 +126,16 @@ /* true if the Unicode object has an allocated UTF-8 memory block (not shared with other data) */ #define _PyUnicode_HAS_UTF8_MEMORY(op) \ - ((!PyUnicode_IS_COMPACT_ASCII(op) \ + (assert(_PyUnicode_CHECK(op)), \ + (!PyUnicode_IS_COMPACT_ASCII(op) \ && _PyUnicode_UTF8(op) \ && _PyUnicode_UTF8(op) != PyUnicode_DATA(op))) /* true if the Unicode object has an allocated wstr memory block (not shared with other data) */ #define _PyUnicode_HAS_WSTR_MEMORY(op) \ - ((_PyUnicode_WSTR(op) && \ + (assert(_PyUnicode_CHECK(op)), \ + (_PyUnicode_WSTR(op) && \ (!PyUnicode_IS_READY(op) || \ _PyUnicode_WSTR(op) != PyUnicode_DATA(op)))) @@ -165,40 +171,17 @@ Another way to look at this is that to say that the actual reference count of a string is: s->ob_refcnt + (s->state ? 2 : 0) */ -static PyObject *interned = NULL; +static PyObject *interned; /* The empty Unicode object is shared to improve performance. */ -static PyObject *unicode_empty = NULL; - -#define _Py_INCREF_UNICODE_EMPTY() \ - do { \ - if (unicode_empty != NULL) \ - Py_INCREF(unicode_empty); \ - else { \ - unicode_empty = PyUnicode_New(0, 0); \ - if (unicode_empty != NULL) { \ - Py_INCREF(unicode_empty); \ - assert(_PyUnicode_CheckConsistency(unicode_empty, 1)); \ - } \ - } \ - } while (0) - -#define _Py_RETURN_UNICODE_EMPTY() \ - do { \ - _Py_INCREF_UNICODE_EMPTY(); \ - return unicode_empty; \ - } while (0) - -/* Forward declaration */ -Py_LOCAL_INLINE(int) -_PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch); +static PyObject *unicode_empty; /* List of static strings. */ -static _Py_Identifier *static_strings = NULL; +static _Py_Identifier *static_strings; /* Single character Unicode strings in the Latin-1 range are being shared as well. */ -static PyObject *unicode_latin1[256] = {NULL}; +static PyObject *unicode_latin1[256]; /* Fast detection of the most frequent whitespace characters */ const unsigned char _Py_ascii_whitespace[] = { @@ -238,7 +221,7 @@ static PyObject * -_PyUnicode_FromUCS1(const Py_UCS1 *s, Py_ssize_t size); +_PyUnicode_FromUCS1(const unsigned char *s, Py_ssize_t size); static PyObject * _PyUnicode_FromUCS2(const Py_UCS2 *s, Py_ssize_t size); static PyObject * @@ -423,13 +406,14 @@ len = _PyUnicode_WSTR_LENGTH(unicode); if (len == 0) { + Py_INCREF(unicode_empty); Py_DECREF(unicode); - _Py_RETURN_UNICODE_EMPTY(); + return unicode_empty; } if (len == 1) { wchar_t ch = _PyUnicode_WSTR(unicode)[0]; - if ((Py_UCS4)ch < 256) { + if (ch < 256) { PyObject *latin1_char = get_latin1_char((unsigned char)ch); Py_DECREF(unicode); return latin1_char; @@ -458,16 +442,14 @@ length = PyUnicode_GET_LENGTH(unicode); if (length == 0) { if (unicode != unicode_empty) { + Py_INCREF(unicode_empty); Py_DECREF(unicode); - _Py_RETURN_UNICODE_EMPTY(); } return unicode_empty; } if (length == 1) { - void *data = PyUnicode_DATA(unicode); - int kind = PyUnicode_KIND(unicode); - Py_UCS4 ch = PyUnicode_READ(kind, data, 0); + Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0); if (ch < 256) { PyObject *latin1_char = unicode_latin1[ch]; if (latin1_char != NULL) { @@ -538,8 +520,9 @@ #define BLOOM_MASK unsigned long -static BLOOM_MASK bloom_linebreak = ~(BLOOM_MASK)0; - +static BLOOM_MASK bloom_linebreak; + +#define BLOOM_ADD(mask, ch) ((mask |= (1UL << ((ch) & (BLOOM_WIDTH - 1))))) #define BLOOM(mask, ch) ((mask & (1UL << ((ch) & (BLOOM_WIDTH - 1))))) #define BLOOM_LINEBREAK(ch) \ @@ -549,40 +532,21 @@ Py_LOCAL_INLINE(BLOOM_MASK) make_bloom_mask(int kind, void* ptr, Py_ssize_t len) { -#define BLOOM_UPDATE(TYPE, MASK, PTR, LEN) \ - do { \ - TYPE *data = (TYPE *)PTR; \ - TYPE *end = data + LEN; \ - Py_UCS4 ch; \ - for (; data != end; data++) { \ - ch = *data; \ - MASK |= (1UL << (ch & (BLOOM_WIDTH - 1))); \ - } \ - break; \ - } while (0) - /* calculate simple bloom-style bitmask for a given unicode string */ BLOOM_MASK mask; + Py_ssize_t i; mask = 0; - switch (kind) { - case PyUnicode_1BYTE_KIND: - BLOOM_UPDATE(Py_UCS1, mask, ptr, len); - break; - case PyUnicode_2BYTE_KIND: - BLOOM_UPDATE(Py_UCS2, mask, ptr, len); - break; - case PyUnicode_4BYTE_KIND: - BLOOM_UPDATE(Py_UCS4, mask, ptr, len); - break; - default: - assert(0); - } + for (i = 0; i < len; i++) + BLOOM_ADD(mask, PyUnicode_READ(kind, ptr, i)); + return mask; - -#undef BLOOM_UPDATE -} +} + +#define BLOOM_MEMBER(mask, chr, str) \ + (BLOOM(mask, chr) \ + && (PyUnicode_FindChar(str, chr, 0, PyUnicode_GET_LENGTH(str), 1) >= 0)) /* Compilation of templated routines */ @@ -602,7 +566,6 @@ #include "stringlib/split.h" #include "stringlib/count.h" #include "stringlib/find.h" -#include "stringlib/replace.h" #include "stringlib/find_max_char.h" #include "stringlib/localeutil.h" #include "stringlib/undef.h" @@ -613,7 +576,6 @@ #include "stringlib/split.h" #include "stringlib/count.h" #include "stringlib/find.h" -#include "stringlib/replace.h" #include "stringlib/find_max_char.h" #include "stringlib/localeutil.h" #include "stringlib/undef.h" @@ -624,7 +586,6 @@ #include "stringlib/split.h" #include "stringlib/count.h" #include "stringlib/find.h" -#include "stringlib/replace.h" #include "stringlib/find_max_char.h" #include "stringlib/localeutil.h" #include "stringlib/undef.h" @@ -737,10 +698,6 @@ if (!PyUnicode_IS_ASCII(unicode)) _PyUnicode_WSTR_LENGTH(unicode) = length; } - else if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) { - PyObject_DEL(_PyUnicode_WSTR(unicode)); - _PyUnicode_WSTR(unicode) = NULL; - } #ifdef Py_DEBUG unicode_fill_invalid(unicode, old_length); #endif @@ -1645,11 +1602,9 @@ return 0; if (length == 0) { - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) - return -1; Py_DECREF(*p_unicode); *p_unicode = unicode_empty; + Py_INCREF(*p_unicode); return 0; } @@ -1772,12 +1727,14 @@ some optimizations which share commonly used objects. */ /* Optimization for empty strings */ - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0 && unicode_empty != NULL) { + Py_INCREF(unicode_empty); + return unicode_empty; + } /* Single character Unicode objects in the Latin-1 range are shared when using this constructor */ - if (size == 1 && (Py_UCS4)*u < 256) + if (size == 1 && *u < 256) return get_latin1_char((unsigned char)*u); /* If not empty and not single character, copy the Unicode data @@ -1885,7 +1842,7 @@ PyObject *unicode; if (size == 1) { #ifdef Py_DEBUG - assert((unsigned char)s[0] < 128); + assert(s[0] < 128); #endif return get_latin1_char(s[0]); } @@ -1927,13 +1884,15 @@ } static PyObject* -_PyUnicode_FromUCS1(const Py_UCS1* u, Py_ssize_t size) +_PyUnicode_FromUCS1(const unsigned char* u, Py_ssize_t size) { PyObject *res; unsigned char max_char; - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } assert(size > 0); if (size == 1) return get_latin1_char(u[0]); @@ -1953,22 +1912,20 @@ PyObject *res; Py_UCS2 max_char; - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } assert(size > 0); if (size == 1) { Py_UCS4 ch = u[0]; - int kind; - void *data; if (ch < 256) return get_latin1_char((unsigned char)ch); res = PyUnicode_New(1, ch); if (res == NULL) return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); - PyUnicode_WRITE(kind, data, 0, ch); + PyUnicode_WRITE(PyUnicode_KIND(res), PyUnicode_DATA(res), 0, ch); assert(_PyUnicode_CheckConsistency(res, 1)); return res; } @@ -1993,22 +1950,20 @@ PyObject *res; Py_UCS4 max_char; - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } assert(size > 0); if (size == 1) { Py_UCS4 ch = u[0]; - int kind; - void *data; if (ch < 256) return get_latin1_char((unsigned char)ch); res = PyUnicode_New(1, ch); if (res == NULL) return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); - PyUnicode_WRITE(kind, data, 0, ch); + PyUnicode_WRITE(PyUnicode_KIND(res), PyUnicode_DATA(res), 0, ch); assert(_PyUnicode_CheckConsistency(res, 1)); return res; } @@ -2290,8 +2245,10 @@ PyUnicode_FromWideChar(register const wchar_t *w, Py_ssize_t size) { if (w == NULL) { - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } PyErr_BadInternalCall(); return NULL; } @@ -2339,67 +2296,6 @@ plus 1 for the sign. 53/22 is an upper bound for log10(256). */ #define MAX_LONG_LONG_CHARS (2 + (SIZEOF_LONG_LONG*53-1) / 22) -static int -unicode_fromformat_write_str(_PyUnicodeWriter *writer, PyObject *str, - Py_ssize_t width, Py_ssize_t precision) -{ - Py_ssize_t length, fill, arglen; - Py_UCS4 maxchar; - - if (PyUnicode_READY(str) == -1) - return -1; - - length = PyUnicode_GET_LENGTH(str); - if ((precision == -1 || precision >= length) - && width <= length) - return _PyUnicodeWriter_WriteStr(writer, str); - - if (precision != -1) - length = Py_MIN(precision, length); - - arglen = Py_MAX(length, width); - if (PyUnicode_MAX_CHAR_VALUE(str) > writer->maxchar) - maxchar = _PyUnicode_FindMaxChar(str, 0, length); - else - maxchar = writer->maxchar; - - if (_PyUnicodeWriter_Prepare(writer, arglen, maxchar) == -1) - return -1; - - if (width > length) { - fill = width - length; - if (PyUnicode_Fill(writer->buffer, writer->pos, fill, ' ') == -1) - return -1; - writer->pos += fill; - } - - _PyUnicode_FastCopyCharacters(writer->buffer, writer->pos, - str, 0, length); - writer->pos += length; - return 0; -} - -static int -unicode_fromformat_write_cstr(_PyUnicodeWriter *writer, const char *str, - Py_ssize_t width, Py_ssize_t precision) -{ - /* UTF-8 */ - Py_ssize_t length; - PyObject *unicode; - int res; - - length = strlen(str); - if (precision != -1) - length = Py_MIN(length, precision); - unicode = PyUnicode_DecodeUTF8Stateful(str, length, "replace", NULL); - if (unicode == NULL) - return -1; - - res = unicode_fromformat_write_str(writer, unicode, width, -1); - Py_DECREF(unicode); - return res; -} - static const char* unicode_fromformat_arg(_PyUnicodeWriter *writer, const char *f, va_list *vargs) @@ -2407,12 +2303,12 @@ const char *p; Py_ssize_t len; int zeropad; - Py_ssize_t width; - Py_ssize_t precision; + int width; + int precision; int longflag; int longlongflag; int size_tflag; - Py_ssize_t fill; + int fill; p = f; f++; @@ -2423,36 +2319,28 @@ } /* parse the width.precision part, e.g. "%2.5s" => width=2, precision=5 */ - width = -1; - if (Py_ISDIGIT((unsigned)*f)) { - width = *f - '0'; + width = 0; + while (Py_ISDIGIT((unsigned)*f)) { + if (width > (INT_MAX - ((int)*f - '0')) / 10) { + PyErr_SetString(PyExc_ValueError, + "width too big"); + return NULL; + } + width = (width*10) + (*f - '0'); + f++; + } + precision = 0; + if (*f == '.') { f++; while (Py_ISDIGIT((unsigned)*f)) { - if (width > (PY_SSIZE_T_MAX - ((int)*f - '0')) / 10) { + if (precision > (INT_MAX - ((int)*f - '0')) / 10) { PyErr_SetString(PyExc_ValueError, - "width too big"); + "precision too big"); return NULL; } - width = (width * 10) + (*f - '0'); + precision = (precision*10) + (*f - '0'); f++; } - } - precision = -1; - if (*f == '.') { - f++; - if (Py_ISDIGIT((unsigned)*f)) { - precision = (*f - '0'); - f++; - while (Py_ISDIGIT((unsigned)*f)) { - if (precision > (PY_SSIZE_T_MAX - ((int)*f - '0')) / 10) { - PyErr_SetString(PyExc_ValueError, - "precision too big"); - return NULL; - } - precision = (precision * 10) + (*f - '0'); - f++; - } - } if (*f == '%') { /* "%.3%s" => f points to "3" */ f--; @@ -2494,12 +2382,14 @@ { int ordinal = va_arg(*vargs, int); if (ordinal < 0 || ordinal > MAX_UNICODE) { - PyErr_SetString(PyExc_OverflowError, + PyErr_SetString(PyExc_ValueError, "character argument not in range(0x110000)"); return NULL; } - if (_PyUnicodeWriter_WriteCharInline(writer, ordinal) < 0) + if (_PyUnicodeWriter_Prepare(writer, 1, ordinal) == -1) return NULL; + PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ordinal); + writer->pos++; break; } @@ -2511,7 +2401,6 @@ /* used by sprintf */ char fmt[10]; /* should be enough for "%0lld\0" */ char buffer[MAX_LONG_LONG_CHARS]; - Py_ssize_t arglen; if (*f == 'u') { makefmt(fmt, longflag, longlongflag, size_tflag, *f); @@ -2557,29 +2446,26 @@ if (precision < len) precision = len; - - arglen = Py_MAX(precision, width); - assert(ucs1lib_find_max_char((Py_UCS1*)buffer, (Py_UCS1*)buffer + len) <= 127); - if (_PyUnicodeWriter_Prepare(writer, arglen, 127) == -1) - return NULL; - if (width > precision) { Py_UCS4 fillchar; fill = width - precision; fillchar = zeropad?'0':' '; + if (_PyUnicodeWriter_Prepare(writer, fill, fillchar) == -1) + return NULL; if (PyUnicode_Fill(writer->buffer, writer->pos, fill, fillchar) == -1) return NULL; writer->pos += fill; } if (precision > len) { fill = precision - len; + if (_PyUnicodeWriter_Prepare(writer, fill, '0') == -1) + return NULL; if (PyUnicode_Fill(writer->buffer, writer->pos, fill, '0') == -1) return NULL; writer->pos += fill; } - - unicode_write_cstr(writer->buffer, writer->pos, buffer, len); - writer->pos += len; + if (_PyUnicodeWriter_WriteCstr(writer, buffer, len) == -1) + return NULL; break; } @@ -2601,11 +2487,8 @@ len += 2; } - assert(ucs1lib_find_max_char((Py_UCS1*)number, (Py_UCS1*)number + len) <= 127); - if (_PyUnicodeWriter_Prepare(writer, len, 127) == -1) + if (_PyUnicodeWriter_WriteCstr(writer, number, len) == -1) return NULL; - unicode_write_cstr(writer->buffer, writer->pos, number, len); - writer->pos += len; break; } @@ -2613,8 +2496,14 @@ { /* UTF-8 */ const char *s = va_arg(*vargs, const char*); - if (unicode_fromformat_write_cstr(writer, s, width, precision) < 0) + PyObject *str = PyUnicode_DecodeUTF8Stateful(s, strlen(s), "replace", NULL); + if (!str) return NULL; + if (_PyUnicodeWriter_WriteStr(writer, str) == -1) { + Py_DECREF(str); + return NULL; + } + Py_DECREF(str); break; } @@ -2623,7 +2512,7 @@ PyObject *obj = va_arg(*vargs, PyObject *); assert(obj && _PyUnicode_CHECK(obj)); - if (unicode_fromformat_write_str(writer, obj, width, precision) == -1) + if (_PyUnicodeWriter_WriteStr(writer, obj) == -1) return NULL; break; } @@ -2632,15 +2521,22 @@ { PyObject *obj = va_arg(*vargs, PyObject *); const char *str = va_arg(*vargs, const char *); + PyObject *str_obj; + assert(obj || str); if (obj) { assert(_PyUnicode_CHECK(obj)); - if (unicode_fromformat_write_str(writer, obj, width, precision) == -1) + if (_PyUnicodeWriter_WriteStr(writer, obj) == -1) return NULL; } else { - assert(str != NULL); - if (unicode_fromformat_write_cstr(writer, str, width, precision) < 0) + str_obj = PyUnicode_DecodeUTF8Stateful(str, strlen(str), "replace", NULL); + if (!str_obj) return NULL; + if (_PyUnicodeWriter_WriteStr(writer, str_obj) == -1) { + Py_DECREF(str_obj); + return NULL; + } + Py_DECREF(str_obj); } break; } @@ -2653,7 +2549,7 @@ str = PyObject_Str(obj); if (!str) return NULL; - if (unicode_fromformat_write_str(writer, str, width, precision) == -1) { + if (_PyUnicodeWriter_WriteStr(writer, str) == -1) { Py_DECREF(str); return NULL; } @@ -2669,7 +2565,7 @@ repr = PyObject_Repr(obj); if (!repr) return NULL; - if (unicode_fromformat_write_str(writer, repr, width, precision) == -1) { + if (_PyUnicodeWriter_WriteStr(writer, repr) == -1) { Py_DECREF(repr); return NULL; } @@ -2685,7 +2581,7 @@ ascii = PyObject_ASCII(obj); if (!ascii) return NULL; - if (unicode_fromformat_write_str(writer, ascii, width, precision) == -1) { + if (_PyUnicodeWriter_WriteStr(writer, ascii) == -1) { Py_DECREF(ascii); return NULL; } @@ -2694,8 +2590,10 @@ } case '%': - if (_PyUnicodeWriter_WriteCharInline(writer, '%') < 0) + if (_PyUnicodeWriter_Prepare(writer, 1, '%') == 1) return NULL; + PyUnicode_WRITE(writer->kind, writer->data, writer->pos, '%'); + writer->pos++; break; default: @@ -2721,9 +2619,7 @@ const char *f; _PyUnicodeWriter writer; - _PyUnicodeWriter_Init(&writer); - writer.min_length = strlen(format) + 100; - writer.overallocate = 1; + _PyUnicodeWriter_Init(&writer, strlen(format) + 100); /* va_list may be an array (of 1 item) on some platforms (ex: AMD64). Copy it to be able to pass a reference to a subfunction. */ @@ -2875,24 +2771,19 @@ PyUnicode_FromOrdinal(int ordinal) { PyObject *v; - void *data; - int kind; - if (ordinal < 0 || ordinal > MAX_UNICODE) { PyErr_SetString(PyExc_ValueError, "chr() arg not in range(0x110000)"); return NULL; } - if ((Py_UCS4)ordinal < 256) - return get_latin1_char((unsigned char)ordinal); + if (ordinal < 256) + return get_latin1_char(ordinal); v = PyUnicode_New(1, ordinal); if (v == NULL) return NULL; - kind = PyUnicode_KIND(v); - data = PyUnicode_DATA(v); - PyUnicode_WRITE(kind, data, 0, ordinal); + PyUnicode_WRITE(PyUnicode_KIND(v), PyUnicode_DATA(v), 0, ordinal); assert(_PyUnicode_CheckConsistency(v, 1)); return v; } @@ -2934,11 +2825,15 @@ /* Decoding bytes objects is the most common case and should be fast */ if (PyBytes_Check(obj)) { - if (PyBytes_GET_SIZE(obj) == 0) - _Py_RETURN_UNICODE_EMPTY(); - v = PyUnicode_Decode( - PyBytes_AS_STRING(obj), PyBytes_GET_SIZE(obj), - encoding, errors); + if (PyBytes_GET_SIZE(obj) == 0) { + Py_INCREF(unicode_empty); + v = unicode_empty; + } + else { + v = PyUnicode_Decode( + PyBytes_AS_STRING(obj), PyBytes_GET_SIZE(obj), + encoding, errors); + } return v; } @@ -2958,11 +2853,12 @@ } if (buffer.len == 0) { - PyBuffer_Release(&buffer); - _Py_RETURN_UNICODE_EMPTY(); - } - - v = PyUnicode_Decode((char*) buffer.buf, buffer.len, encoding, errors); + Py_INCREF(unicode_empty); + v = unicode_empty; + } + else + v = PyUnicode_Decode((char*) buffer.buf, buffer.len, encoding, errors); + PyBuffer_Release(&buffer); return v; } @@ -3314,7 +3210,7 @@ wstr = _Py_char2wchar(errmsg, &errlen); if (wstr != NULL) { reason = PyUnicode_FromWideChar(wstr, errlen); - PyMem_RawFree(wstr); + PyMem_Free(wstr); } else errmsg = NULL; } @@ -3533,7 +3429,7 @@ } unicode = PyUnicode_FromWideChar(wstr, wlen); - PyMem_RawFree(wstr); + PyMem_Free(wstr); } else { /* strict mode */ @@ -3581,7 +3477,7 @@ wstr = _Py_char2wchar(errmsg, &errlen); if (wstr != NULL) { reason = PyUnicode_FromWideChar(wstr, errlen); - PyMem_RawFree(wstr); + PyMem_Free(wstr); } else errmsg = NULL; } @@ -3934,9 +3830,6 @@ Py_UCS4 PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index) { - void *data; - int kind; - if (!PyUnicode_Check(unicode) || PyUnicode_READY(unicode) == -1) { PyErr_BadArgument(); return (Py_UCS4)-1; @@ -3945,9 +3838,7 @@ PyErr_SetString(PyExc_IndexError, "string index out of range"); return (Py_UCS4)-1; } - data = PyUnicode_DATA(unicode); - kind = PyUnicode_KIND(unicode); - return PyUnicode_READ(kind, data, index); + return PyUnicode_READ_CHAR(unicode, index); } int @@ -4127,7 +4018,6 @@ PyObject *repunicode = NULL; Py_ssize_t insize; Py_ssize_t newpos; - Py_ssize_t replen; PyObject *inputobj = NULL; if (*errorHandler == NULL) { @@ -4176,14 +4066,9 @@ goto onError; } - if (PyUnicode_READY(repunicode) < 0) - goto onError; - replen = PyUnicode_GET_LENGTH(repunicode); - writer->min_length += replen; - if (replen > 1) - writer->overallocate = 1; + writer->overallocate = 1; if (_PyUnicodeWriter_WriteStr(writer, repunicode) == -1) - goto onError; + return *endinpos = newpos; *inptr = *input + newpos; @@ -4316,12 +4201,14 @@ if (size == 0) { if (consumed) *consumed = 0; - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + return unicode_empty; } /* Start off assuming it's all ASCII. Widen later as necessary. */ - _PyUnicodeWriter_Init(&writer); - writer.min_length = size; + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, size, 127) == -1) + goto onError; shiftOutStart = 0; e = s + size; @@ -4345,14 +4232,18 @@ /* expecting a second surrogate */ if (Py_UNICODE_IS_LOW_SURROGATE(outCh)) { Py_UCS4 ch2 = Py_UNICODE_JOIN_SURROGATES(surrogate, outCh); - if (_PyUnicodeWriter_WriteCharInline(&writer, ch2) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch2) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch2); + writer.pos++; surrogate = 0; continue; } else { - if (_PyUnicodeWriter_WriteCharInline(&writer, surrogate) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, surrogate) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, surrogate); + writer.pos++; surrogate = 0; } } @@ -4361,8 +4252,10 @@ surrogate = outCh; } else { - if (_PyUnicodeWriter_WriteCharInline(&writer, outCh) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, outCh) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, outCh); + writer.pos++; } } } @@ -4370,8 +4263,10 @@ inShift = 0; s++; if (surrogate) { - if (_PyUnicodeWriter_WriteCharInline(&writer, surrogate) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, surrogate) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, surrogate); + writer.pos++; surrogate = 0; } if (base64bits > 0) { /* left-over bits */ @@ -4391,8 +4286,10 @@ if (ch != '-') { /* '-' is absorbed; other terminating characters are preserved */ - if (_PyUnicodeWriter_WriteCharInline(&writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); + writer.pos++; } } } @@ -4401,8 +4298,10 @@ s++; /* consume '+' */ if (s < e && *s == '-') { /* '+-' encodes '+' */ s++; - if (_PyUnicodeWriter_WriteCharInline(&writer, '+') < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, '+') == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, '+'); + writer.pos++; } else { /* begin base64-encoded section */ inShift = 1; @@ -4412,8 +4311,10 @@ } else if (DECODE_DIRECT(ch)) { /* character decodes as itself */ s++; - if (_PyUnicodeWriter_WriteCharInline(&writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); + writer.pos++; } else { startinpos = s-starts; @@ -4640,14 +4541,6 @@ const char *p = start; const char *aligned_end = (const char *) _Py_ALIGN_DOWN(end, SIZEOF_LONG); - /* - * Issue #17237: m68k is a bit different from most architectures in - * that objects do not use "natural alignment" - for example, int and - * long are only aligned at 2-byte boundaries. Therefore the assert() - * won't work; also, tests have shown that skipping the "optimised - * version" will even speed up m68k. - */ -#if !defined(__m68k__) #if SIZEOF_LONG <= SIZEOF_VOID_P assert(_Py_IS_ALIGNED(dest, SIZEOF_LONG)); if (_Py_IS_ALIGNED(p, SIZEOF_LONG)) { @@ -4673,7 +4566,6 @@ return p - start; } #endif -#endif while (p < end) { /* Fast path, see in STRINGLIB(utf8_decode) in stringlib/codecs.h for an explanation. */ @@ -4717,7 +4609,8 @@ if (size == 0) { if (consumed) *consumed = 0; - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + return unicode_empty; } /* ASCII is equivalent to the first 128 ordinals in Unicode. */ @@ -4727,9 +4620,8 @@ return get_latin1_char((unsigned char)s[0]); } - _PyUnicodeWriter_Init(&writer); - writer.min_length = size; - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) == -1) + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, size, 127) == -1) goto onError; writer.pos = ascii_decode(s, end, writer.data); @@ -4770,8 +4662,10 @@ endinpos = startinpos + ch - 1; break; default: - if (_PyUnicodeWriter_WriteCharInline(&writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); + writer.pos++; continue; } @@ -4804,7 +4698,7 @@ used to decode the command line arguments on Mac OS X. Return a pointer to a newly allocated wide character string (use - PyMem_RawFree() to free the memory), or NULL on memory allocation error. */ + PyMem_Free() to free the memory), or NULL on memory allocation error. */ wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size) @@ -4817,7 +4711,7 @@ character count */ if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) return NULL; - unicode = PyMem_RawMalloc((size + 1) * sizeof(wchar_t)); + unicode = PyMem_Malloc((size + 1) * sizeof(wchar_t)); if (!unicode) return NULL; @@ -4974,7 +4868,8 @@ if (q == e) { if (consumed) *consumed = size; - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + return unicode_empty; } #ifdef WORDS_BIGENDIAN @@ -4983,9 +4878,8 @@ le = bo <= 0; #endif - _PyUnicodeWriter_Init(&writer); - writer.min_length = (e - q + 3) / 4; - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) == -1) + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, (e - q + 3) / 4, 127) == -1) goto onError; while (1) { @@ -5028,8 +4922,10 @@ } else { if (ch < 0x110000) { - if (_PyUnicodeWriter_WriteCharInline(&writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); + writer.pos++; q += 4; continue; } @@ -5212,7 +5108,8 @@ if (q == e) { if (consumed) *consumed = size; - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + return unicode_empty; } #if PY_LITTLE_ENDIAN @@ -5223,9 +5120,8 @@ /* Note: size will always be longer than the resulting Unicode character count */ - _PyUnicodeWriter_Init(&writer); - writer.min_length = (e - q + 1) / 2; - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) == -1) + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, (e - q + 1) / 2, 127) == -1) goto onError; while (1) { @@ -5284,8 +5180,10 @@ endinpos = startinpos + 2; break; default: - if (_PyUnicodeWriter_WriteCharInline(&writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); + writer.pos++; continue; } @@ -5478,6 +5376,7 @@ const char *starts = s; Py_ssize_t startinpos; Py_ssize_t endinpos; + int j; _PyUnicodeWriter writer; const char *end; char* message; @@ -5487,17 +5386,21 @@ Py_ssize_t len; len = length_of_escaped_ascii_string(s, size); - if (len == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (len == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } /* After length_of_escaped_ascii_string() there are two alternatives, either the string is pure ASCII with named escapes like \n, etc. and we determined it's exact size (common case) or it contains \x, \u, ... escape sequences. then we create a legacy wchar string and resize it at the end of this function. */ - _PyUnicodeWriter_Init(&writer); + _PyUnicodeWriter_Init(&writer, 0); if (len > 0) { - writer.min_length = len; + if (_PyUnicodeWriter_Prepare(&writer, len, 127) == -1) + goto onError; + assert(writer.kind == PyUnicode_1BYTE_KIND); } else { /* Escaped strings will always be longer than the resulting @@ -5505,7 +5408,8 @@ length after conversion to the true value. (but if the error callback returns a long replacement string we'll have to allocate more space) */ - writer.min_length = size; + if (_PyUnicodeWriter_Prepare(&writer, size, 127) == -1) + goto onError; } if (size == 0) @@ -5521,8 +5425,10 @@ if (*s != '\\') { x = (unsigned char)*s; s++; - if (_PyUnicodeWriter_WriteCharInline(&writer, x) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, x) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, x); + writer.pos++; continue; } @@ -5533,13 +5439,19 @@ if (s > end) c = '\0'; /* Invalid after \ */ + /* The only case in which i == ascii_length is a backslash + followed by a newline. */ + assert(writer.pos < writer.size || (writer.pos == writer.size && c == '\n')); + switch (c) { /* \x escapes */ #define WRITECHAR(ch) \ do { \ - if (_PyUnicodeWriter_WriteCharInline(&writer, (ch)) < 0) \ + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) \ goto onError; \ + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); \ + writer.pos++; \ } while(0) case '\n': break; @@ -5588,19 +5500,28 @@ message = "truncated \\UXXXXXXXX escape"; hexescape: chr = 0; - if (end - s < digits) { - /* count only hex digits */ - for (; s < end; ++s) { - c = (unsigned char)*s; - if (!Py_ISXDIGIT(c)) - goto error; + if (s+digits>end) { + endinpos = size; + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "unicodeescape", "end of string in escape sequence", + &starts, &end, &startinpos, &endinpos, &exc, &s, + &writer)) + goto onError; + goto nextByte; + } + for (j = 0; j < digits; ++j) { + c = (unsigned char) s[j]; + if (!Py_ISXDIGIT(c)) { + endinpos = (s+j+1)-starts; + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "unicodeescape", message, + &starts, &end, &startinpos, &endinpos, &exc, &s, + &writer)) + goto onError; + goto nextByte; } - goto error; - } - for (; digits--; ++s) { - c = (unsigned char)*s; - if (!Py_ISXDIGIT(c)) - goto error; chr = (chr<<4) & ~0xF; if (c >= '0' && c <= '9') chr += c - '0'; @@ -5609,16 +5530,24 @@ else chr += 10 + c - 'A'; } + s += j; if (chr == 0xffffffff && PyErr_Occurred()) /* _decoding_error will have already written into the target buffer. */ break; store: /* when we get here, chr is a 32-bit unicode character */ - message = "illegal Unicode character"; - if (chr > MAX_UNICODE) - goto error; - WRITECHAR(chr); + if (chr <= MAX_UNICODE) { + WRITECHAR(chr); + } else { + endinpos = s-starts; + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "unicodeescape", "illegal Unicode character", + &starts, &end, &startinpos, &endinpos, &exc, &s, + &writer)) + goto onError; + } break; /* \N{name} */ @@ -5640,37 +5569,40 @@ /* found a name. look it up in the unicode database */ message = "unknown Unicode character name"; s++; - if (s - start - 1 <= INT_MAX && - ucnhash_CAPI->getcode(NULL, start, (int)(s-start-1), + if (ucnhash_CAPI->getcode(NULL, start, (int)(s-start-1), &chr, 0)) goto store; } } - goto error; + endinpos = s-starts; + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "unicodeescape", message, + &starts, &end, &startinpos, &endinpos, &exc, &s, + &writer)) + goto onError; + break; default: if (s > end) { message = "\\ at end of string"; s--; - goto error; + endinpos = s-starts; + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "unicodeescape", message, + &starts, &end, &startinpos, &endinpos, &exc, &s, + &writer)) + goto onError; } else { WRITECHAR('\\'); - WRITECHAR((unsigned char)s[-1]); + WRITECHAR(s[-1]); } break; } - continue; - - error: - endinpos = s-starts; - if (unicode_decode_call_errorhandler_writer( - errors, &errorHandler, - "unicodeescape", message, - &starts, &end, &startinpos, &endinpos, &exc, &s, - &writer)) - goto onError; - continue; + nextByte: + ; } #undef WRITECHAR @@ -5848,15 +5780,18 @@ PyObject *errorHandler = NULL; PyObject *exc = NULL; - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } /* Escaped strings will always be longer than the resulting Unicode string, so we start with size here and then reduce the length after conversion to the true value. (But decoding error handler might have to resize the string) */ - _PyUnicodeWriter_Init(&writer); - writer.min_length = size; + _PyUnicodeWriter_Init(&writer, 1); + if (_PyUnicodeWriter_Prepare(&writer, size, 127) == -1) + goto onError; end = s + size; while (s < end) { @@ -5868,8 +5803,10 @@ /* Non-escape characters are interpreted as Unicode ordinals */ if (*s != '\\') { x = (unsigned char)*s++; - if (_PyUnicodeWriter_WriteCharInline(&writer, x) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, x) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, x); + writer.pos++; continue; } startinpos = s-starts; @@ -5881,8 +5818,10 @@ if (*s != '\\') break; x = (unsigned char)*s++; - if (_PyUnicodeWriter_WriteCharInline(&writer, x) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, x) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, x); + writer.pos++; } if (((s - bs) & 1) == 0 || s >= end || @@ -5915,8 +5854,10 @@ x += 10 + c - 'A'; } if (x <= MAX_UNICODE) { - if (_PyUnicodeWriter_WriteCharInline(&writer, x) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, x) == -1) goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, x); + writer.pos++; } else { endinpos = s-starts; @@ -6046,25 +5987,20 @@ 1)) return NULL; - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); - - _PyUnicodeWriter_Init(&writer); - if (size / Py_UNICODE_SIZE > PY_SSIZE_T_MAX - 1) { - PyErr_NoMemory(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } + + /* XXX overflow detection missing */ + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, (size+Py_UNICODE_SIZE-1)/ Py_UNICODE_SIZE, 127) == -1) goto onError; - } - writer.min_length = (size + (Py_UNICODE_SIZE - 1)) / Py_UNICODE_SIZE; - end = s + size; + while (s < end) { Py_UNICODE uch; Py_UCS4 ch; - if (end - s < Py_UNICODE_SIZE) { - endinpos = end-starts; - reason = "truncated input"; - goto error; - } /* We copy the raw representation one byte at a time because the pointer may be unaligned (see test_codeccallbacks). */ ((char *) &uch)[0] = s[0]; @@ -6074,18 +6010,37 @@ ((char *) &uch)[3] = s[3]; #endif ch = uch; -#ifdef Py_UNICODE_WIDE + /* We have to sanity check the raw data, otherwise doom looms for some malformed UCS-4 data. */ - if (ch > 0x10ffff) { - endinpos = s - starts + Py_UNICODE_SIZE; - reason = "illegal code point (> 0x10FFFF)"; - goto error; - } -#endif + if ( +#ifdef Py_UNICODE_WIDE + ch > 0x10ffff || +#endif + end-s < Py_UNICODE_SIZE + ) + { + startinpos = s - starts; + if (end-s < Py_UNICODE_SIZE) { + endinpos = end-starts; + reason = "truncated input"; + } + else { + endinpos = s - starts + Py_UNICODE_SIZE; + reason = "illegal code point (> 0x10FFFF)"; + } + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "unicode_internal", reason, + &starts, &end, &startinpos, &endinpos, &exc, &s, + &writer)) + goto onError; + continue; + } + s += Py_UNICODE_SIZE; #ifndef Py_UNICODE_WIDE - if (Py_UNICODE_IS_HIGH_SURROGATE(ch) && end - s >= Py_UNICODE_SIZE) + if (Py_UNICODE_IS_HIGH_SURROGATE(ch) && s < end) { Py_UNICODE uch2; ((char *) &uch2)[0] = s[0]; @@ -6098,18 +6053,10 @@ } #endif - if (_PyUnicodeWriter_WriteCharInline(&writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(&writer, 1, ch) == -1) goto onError; - continue; - - error: - startinpos = s - starts; - if (unicode_decode_call_errorhandler_writer( - errors, &errorHandler, - "unicode_internal", reason, - &starts, &end, &startinpos, &endinpos, &exc, &s, - &writer)) - goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, ch); + writer.pos++; } Py_XDECREF(errorHandler); @@ -6491,17 +6438,18 @@ PyObject *errorHandler = NULL; PyObject *exc = NULL; - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } /* ASCII is equivalent to the first 128 ordinals in Unicode. */ if (size == 1 && (unsigned char)s[0] < 128) return get_latin1_char((unsigned char)s[0]); - _PyUnicodeWriter_Init(&writer); - writer.min_length = size; - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) - return NULL; + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, size, 127) == -1) + goto onError; e = s + size; data = writer.data; @@ -6569,7 +6517,7 @@ return NULL; /* Fast path: if it is an ASCII-only string, construct bytes object directly. Else defer to above function to raise the exception. */ - if (PyUnicode_IS_ASCII(unicode)) + if (PyUnicode_MAX_CHAR_VALUE(unicode) < 128) return PyBytes_FromStringAndSize(PyUnicode_DATA(unicode), PyUnicode_GET_LENGTH(unicode)); return unicode_encode_ucs1(unicode, errors, 128); @@ -6718,8 +6666,7 @@ /* each step cannot decode more than 1 character, but a character can be represented as a surrogate pair */ wchar_t buffer[2], *startout, *out; - int insize; - Py_ssize_t outsize; + int insize, outsize; PyObject *errorHandler = NULL; PyObject *exc = NULL; PyObject *encoding_obj = NULL; @@ -6872,7 +6819,8 @@ if (chunk_size == 0 && done) { if (v != NULL) break; - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + return unicode_empty; } @@ -6989,11 +6937,10 @@ Py_DECREF(substring); return -1; } - assert(size <= INT_MAX); /* First get the size of the result */ outsize = WideCharToMultiByte(code_page, flags, - p, (int)size, + p, size, NULL, 0, NULL, pusedDefaultChar); if (outsize <= 0) @@ -7030,7 +6977,7 @@ /* Do the conversion */ outsize = WideCharToMultiByte(code_page, flags, - p, (int)size, + p, size, out, outsize, NULL, pusedDefaultChar); Py_CLEAR(substring); @@ -7332,257 +7279,194 @@ /* --- Character Mapping Codec -------------------------------------------- */ -static int -charmap_decode_string(const char *s, - Py_ssize_t size, - PyObject *mapping, - const char *errors, - _PyUnicodeWriter *writer) +PyObject * +PyUnicode_DecodeCharmap(const char *s, + Py_ssize_t size, + PyObject *mapping, + const char *errors) { const char *starts = s; + Py_ssize_t startinpos; + Py_ssize_t endinpos; const char *e; - Py_ssize_t startinpos, endinpos; - PyObject *errorHandler = NULL, *exc = NULL; - Py_ssize_t maplen; - enum PyUnicode_Kind mapkind; - void *mapdata; - Py_UCS4 x; - unsigned char ch; - - if (PyUnicode_READY(mapping) == -1) - return -1; - - maplen = PyUnicode_GET_LENGTH(mapping); - mapdata = PyUnicode_DATA(mapping); - mapkind = PyUnicode_KIND(mapping); + _PyUnicodeWriter writer; + PyObject *errorHandler = NULL; + PyObject *exc = NULL; + + /* Default to Latin-1 */ + if (mapping == NULL) + return PyUnicode_DecodeLatin1(s, size, errors); + + if (size == 0) { + Py_INCREF(unicode_empty); + return unicode_empty; + } + _PyUnicodeWriter_Init(&writer, 0); + if (_PyUnicodeWriter_Prepare(&writer, size, 127) == -1) + goto onError; e = s + size; - - if (mapkind == PyUnicode_1BYTE_KIND && maplen >= 256) { - /* fast-path for cp037, cp500 and iso8859_1 encodings. iso8859_1 - * is disabled in encoding aliases, latin1 is preferred because - * its implementation is faster. */ - Py_UCS1 *mapdata_ucs1 = (Py_UCS1 *)mapdata; - Py_UCS1 *outdata = (Py_UCS1 *)writer->data; - Py_UCS4 maxchar = writer->maxchar; - - assert (writer->kind == PyUnicode_1BYTE_KIND); + if (PyUnicode_CheckExact(mapping)) { + Py_ssize_t maplen; + enum PyUnicode_Kind mapkind; + void *mapdata; + Py_UCS4 x; + + if (PyUnicode_READY(mapping) == -1) + return NULL; + + maplen = PyUnicode_GET_LENGTH(mapping); + mapdata = PyUnicode_DATA(mapping); + mapkind = PyUnicode_KIND(mapping); while (s < e) { + unsigned char ch; + if (mapkind == PyUnicode_2BYTE_KIND && maplen >= 256) { + enum PyUnicode_Kind outkind = writer.kind; + void *outdata = writer.data; + if (outkind == PyUnicode_1BYTE_KIND) { + Py_UCS4 maxchar = writer.maxchar; + while (s < e) { + unsigned char ch = *s; + x = PyUnicode_READ(PyUnicode_2BYTE_KIND, mapdata, ch); + if (x > maxchar) + goto Error; + PyUnicode_WRITE(PyUnicode_1BYTE_KIND, outdata, writer.pos, x); + writer.pos++; + ++s; + } + break; + } + else if (outkind == PyUnicode_2BYTE_KIND) { + while (s < e) { + unsigned char ch = *s; + x = PyUnicode_READ(PyUnicode_2BYTE_KIND, mapdata, ch); + if (x == 0xFFFE) + goto Error; + PyUnicode_WRITE(PyUnicode_2BYTE_KIND, outdata, writer.pos, x); + writer.pos++; + ++s; + } + break; + } + } ch = *s; - x = mapdata_ucs1[ch]; - if (x > maxchar) { - if (_PyUnicodeWriter_Prepare(writer, 1, 0xff) == -1) + + if (ch < maplen) + x = PyUnicode_READ(mapkind, mapdata, ch); + else + x = 0xfffe; /* invalid value */ +Error: + if (x == 0xfffe) + { + /* undefined mapping */ + startinpos = s-starts; + endinpos = startinpos+1; + if (unicode_decode_call_errorhandler_writer( + errors, &errorHandler, + "charmap", "character maps to ", + &starts, &e, &startinpos, &endinpos, &exc, &s, + &writer)) { goto onError; - maxchar = writer->maxchar; - outdata = (Py_UCS1 *)writer->data; - } - outdata[writer->pos] = x; - writer->pos++; + } + continue; + } + + if (_PyUnicodeWriter_Prepare(&writer, 1, x) == -1) + goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, x); + writer.pos++; ++s; } - return 0; - } - - while (s < e) { - if (mapkind == PyUnicode_2BYTE_KIND && maplen >= 256) { - enum PyUnicode_Kind outkind = writer->kind; - Py_UCS2 *mapdata_ucs2 = (Py_UCS2 *)mapdata; - if (outkind == PyUnicode_1BYTE_KIND) { - Py_UCS1 *outdata = (Py_UCS1 *)writer->data; - Py_UCS4 maxchar = writer->maxchar; - while (s < e) { - ch = *s; - x = mapdata_ucs2[ch]; - if (x > maxchar) - goto Error; - outdata[writer->pos] = x; - writer->pos++; - ++s; + } + else { + while (s < e) { + unsigned char ch = *s; + PyObject *w, *x; + + /* Get mapping (char ordinal -> integer, Unicode char or None) */ + w = PyLong_FromLong((long)ch); + if (w == NULL) + goto onError; + x = PyObject_GetItem(mapping, w); + Py_DECREF(w); + if (x == NULL) { + if (PyErr_ExceptionMatches(PyExc_LookupError)) { + /* No mapping found means: mapping is undefined. */ + PyErr_Clear(); + goto Undefined; + } else + goto onError; + } + + /* Apply mapping */ + if (x == Py_None) + goto Undefined; + if (PyLong_Check(x)) { + long value = PyLong_AS_LONG(x); + if (value == 0xFFFE) + goto Undefined; + if (value < 0 || value > MAX_UNICODE) { + PyErr_Format(PyExc_TypeError, + "character mapping must be in range(0x%lx)", + (unsigned long)MAX_UNICODE + 1); + Py_DECREF(x); + goto onError; } - break; - } - else if (outkind == PyUnicode_2BYTE_KIND) { - Py_UCS2 *outdata = (Py_UCS2 *)writer->data; - while (s < e) { - ch = *s; - x = mapdata_ucs2[ch]; - if (x == 0xFFFE) - goto Error; - outdata[writer->pos] = x; - writer->pos++; - ++s; + + if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) + goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value); + writer.pos++; + } + else if (PyUnicode_Check(x)) { + if (PyUnicode_READY(x) == -1) + goto onError; + if (PyUnicode_GET_LENGTH(x) == 1) { + Py_UCS4 value = PyUnicode_READ_CHAR(x, 0); + if (value == 0xFFFE) + goto Undefined; + if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) + goto onError; + PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value); + writer.pos++; } - break; - } - } - ch = *s; - - if (ch < maplen) - x = PyUnicode_READ(mapkind, mapdata, ch); - else - x = 0xfffe; /* invalid value */ -Error: - if (x == 0xfffe) - { + else { + writer.overallocate = 1; + if (_PyUnicodeWriter_WriteStr(&writer, x) == -1) + goto onError; + } + } + else { + /* wrong return value */ + PyErr_SetString(PyExc_TypeError, + "character mapping must return integer, None or str"); + Py_DECREF(x); + goto onError; + } + Py_DECREF(x); + ++s; + continue; +Undefined: /* undefined mapping */ + Py_XDECREF(x); startinpos = s-starts; endinpos = startinpos+1; if (unicode_decode_call_errorhandler_writer( errors, &errorHandler, "charmap", "character maps to ", &starts, &e, &startinpos, &endinpos, &exc, &s, - writer)) { + &writer)) { goto onError; } - continue; - } - - if (_PyUnicodeWriter_WriteCharInline(writer, x) < 0) - goto onError; - ++s; + } } Py_XDECREF(errorHandler); Py_XDECREF(exc); - return 0; - -onError: + return _PyUnicodeWriter_Finish(&writer); + + onError: Py_XDECREF(errorHandler); Py_XDECREF(exc); - return -1; -} - -static int -charmap_decode_mapping(const char *s, - Py_ssize_t size, - PyObject *mapping, - const char *errors, - _PyUnicodeWriter *writer) -{ - const char *starts = s; - const char *e; - Py_ssize_t startinpos, endinpos; - PyObject *errorHandler = NULL, *exc = NULL; - unsigned char ch; - PyObject *key, *item = NULL; - - e = s + size; - - while (s < e) { - ch = *s; - - /* Get mapping (char ordinal -> integer, Unicode char or None) */ - key = PyLong_FromLong((long)ch); - if (key == NULL) - goto onError; - - item = PyObject_GetItem(mapping, key); - Py_DECREF(key); - if (item == NULL) { - if (PyErr_ExceptionMatches(PyExc_LookupError)) { - /* No mapping found means: mapping is undefined. */ - PyErr_Clear(); - goto Undefined; - } else - goto onError; - } - - /* Apply mapping */ - if (item == Py_None) - goto Undefined; - if (PyLong_Check(item)) { - long value = PyLong_AS_LONG(item); - if (value == 0xFFFE) - goto Undefined; - if (value < 0 || value > MAX_UNICODE) { - PyErr_Format(PyExc_TypeError, - "character mapping must be in range(0x%lx)", - (unsigned long)MAX_UNICODE + 1); - goto onError; - } - - if (_PyUnicodeWriter_WriteCharInline(writer, value) < 0) - goto onError; - } - else if (PyUnicode_Check(item)) { - if (PyUnicode_READY(item) == -1) - goto onError; - if (PyUnicode_GET_LENGTH(item) == 1) { - Py_UCS4 value = PyUnicode_READ_CHAR(item, 0); - if (value == 0xFFFE) - goto Undefined; - if (_PyUnicodeWriter_WriteCharInline(writer, value) < 0) - goto onError; - } - else { - writer->overallocate = 1; - if (_PyUnicodeWriter_WriteStr(writer, item) == -1) - goto onError; - } - } - else { - /* wrong return value */ - PyErr_SetString(PyExc_TypeError, - "character mapping must return integer, None or str"); - goto onError; - } - Py_CLEAR(item); - ++s; - continue; - -Undefined: - /* undefined mapping */ - Py_CLEAR(item); - startinpos = s-starts; - endinpos = startinpos+1; - if (unicode_decode_call_errorhandler_writer( - errors, &errorHandler, - "charmap", "character maps to ", - &starts, &e, &startinpos, &endinpos, &exc, &s, - writer)) { - goto onError; - } - } - Py_XDECREF(errorHandler); - Py_XDECREF(exc); - return 0; - -onError: - Py_XDECREF(item); - Py_XDECREF(errorHandler); - Py_XDECREF(exc); - return -1; -} - -PyObject * -PyUnicode_DecodeCharmap(const char *s, - Py_ssize_t size, - PyObject *mapping, - const char *errors) -{ - _PyUnicodeWriter writer; - - /* Default to Latin-1 */ - if (mapping == NULL) - return PyUnicode_DecodeLatin1(s, size, errors); - - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); - _PyUnicodeWriter_Init(&writer); - writer.min_length = size; - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) == -1) - goto onError; - - if (PyUnicode_CheckExact(mapping)) { - if (charmap_decode_string(s, size, mapping, errors, &writer) < 0) - goto onError; - } - else { - if (charmap_decode_mapping(s, size, mapping, errors, &writer) < 0) - goto onError; - } - return _PyUnicodeWriter_Finish(&writer); - - onError: _PyUnicodeWriter_Dealloc(&writer); return NULL; } @@ -8097,14 +7981,10 @@ * -1=not initialized, 0=unknown, 1=strict, 2=replace, * 3=ignore, 4=xmlcharrefreplace */ int known_errorHandler = -1; - void *data; - int kind; if (PyUnicode_READY(unicode) == -1) return NULL; size = PyUnicode_GET_LENGTH(unicode); - data = PyUnicode_DATA(unicode); - kind = PyUnicode_KIND(unicode); /* Default to Latin-1 */ if (mapping == NULL) @@ -8119,7 +7999,7 @@ return res; while (inpos= 0) ch = '0' + decimal; - maxchar = Py_MAX(maxchar, ch); + maxchar = MAX_MAXCHAR(maxchar, ch); } } @@ -8888,7 +8768,7 @@ if (unicode == NULL) { *maxchar = 127; if (len != n_digits) { - *maxchar = Py_MAX(*maxchar, + *maxchar = MAX_MAXCHAR(*maxchar, PyUnicode_MAX_CHAR_VALUE(thousands_sep)); } } @@ -9282,14 +9162,14 @@ c = PyUnicode_READ(kind, data, 0); n_res = _PyUnicode_ToUpperFull(c, mapped); for (j = 0; j < n_res; j++) { - *maxchar = Py_MAX(*maxchar, mapped[j]); + *maxchar = MAX_MAXCHAR(*maxchar, mapped[j]); res[k++] = mapped[j]; } for (i = 1; i < length; i++) { c = PyUnicode_READ(kind, data, i); n_res = lower_ucs4(kind, data, length, i, c, mapped); for (j = 0; j < n_res; j++) { - *maxchar = Py_MAX(*maxchar, mapped[j]); + *maxchar = MAX_MAXCHAR(*maxchar, mapped[j]); res[k++] = mapped[j]; } } @@ -9314,7 +9194,7 @@ mapped[0] = c; } for (j = 0; j < n_res; j++) { - *maxchar = Py_MAX(*maxchar, mapped[j]); + *maxchar = MAX_MAXCHAR(*maxchar, mapped[j]); res[k++] = mapped[j]; } } @@ -9335,7 +9215,7 @@ else n_res = _PyUnicode_ToUpperFull(c, mapped); for (j = 0; j < n_res; j++) { - *maxchar = Py_MAX(*maxchar, mapped[j]); + *maxchar = MAX_MAXCHAR(*maxchar, mapped[j]); res[k++] = mapped[j]; } } @@ -9364,7 +9244,7 @@ Py_UCS4 mapped[3]; int j, n_res = _PyUnicode_ToFoldedFull(c, mapped); for (j = 0; j < n_res; j++) { - *maxchar = Py_MAX(*maxchar, mapped[j]); + *maxchar = MAX_MAXCHAR(*maxchar, mapped[j]); res[k++] = mapped[j]; } } @@ -9389,7 +9269,7 @@ n_res = _PyUnicode_ToTitleFull(c, mapped); for (j = 0; j < n_res; j++) { - *maxchar = Py_MAX(*maxchar, mapped[j]); + *maxchar = MAX_MAXCHAR(*maxchar, mapped[j]); res[k++] = mapped[j]; } @@ -9473,7 +9353,9 @@ /* If empty sequence, return u"". */ if (seqlen == 0) { Py_DECREF(fseq); - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + res = unicode_empty; + return res; } /* If singleton sequence with an exact Unicode, return that. */ @@ -9544,7 +9426,7 @@ goto onError; sz += PyUnicode_GET_LENGTH(item); item_maxchar = PyUnicode_MAX_CHAR_VALUE(item); - maxchar = Py_MAX(maxchar, item_maxchar); + maxchar = MAX_MAXCHAR(maxchar, item_maxchar); if (i != 0) sz += seplen; if (sz < old_sz || sz > PY_SSIZE_T_MAX) { @@ -9574,49 +9456,41 @@ sep_data = PyUnicode_1BYTE_DATA(sep); } #endif - if (use_memcpy) { - for (i = 0; i < seqlen; ++i) { - Py_ssize_t itemlen; - item = items[i]; - - /* Copy item, and maybe the separator. */ - if (i && seplen != 0) { + for (i = 0, res_offset = 0; i < seqlen; ++i) { + Py_ssize_t itemlen; + item = items[i]; + /* Copy item, and maybe the separator. */ + if (i && seplen != 0) { + if (use_memcpy) { Py_MEMCPY(res_data, sep_data, kind * seplen); res_data += kind * seplen; } - - itemlen = PyUnicode_GET_LENGTH(item); - if (itemlen != 0) { + else { + _PyUnicode_FastCopyCharacters(res, res_offset, sep, 0, seplen); + res_offset += seplen; + } + } + itemlen = PyUnicode_GET_LENGTH(item); + if (itemlen != 0) { + if (use_memcpy) { Py_MEMCPY(res_data, PyUnicode_DATA(item), kind * itemlen); res_data += kind * itemlen; } - } + else { + _PyUnicode_FastCopyCharacters(res, res_offset, item, 0, itemlen); + res_offset += itemlen; + } + } + } + if (use_memcpy) assert(res_data == PyUnicode_1BYTE_DATA(res) + kind * PyUnicode_GET_LENGTH(res)); - } - else { - for (i = 0, res_offset = 0; i < seqlen; ++i) { - Py_ssize_t itemlen; - item = items[i]; - - /* Copy item, and maybe the separator. */ - if (i && seplen != 0) { - _PyUnicode_FastCopyCharacters(res, res_offset, sep, 0, seplen); - res_offset += seplen; - } - - itemlen = PyUnicode_GET_LENGTH(item); - if (itemlen != 0) { - _PyUnicode_FastCopyCharacters(res, res_offset, item, 0, itemlen); - res_offset += itemlen; - } - } + else assert(res_offset == PyUnicode_GET_LENGTH(res)); - } Py_DECREF(fseq); Py_XDECREF(sep); @@ -9728,7 +9602,7 @@ return NULL; } maxchar = PyUnicode_MAX_CHAR_VALUE(self); - maxchar = Py_MAX(maxchar, fill); + maxchar = MAX_MAXCHAR(maxchar, fill); u = PyUnicode_New(left + _PyUnicode_LENGTH(self) + right, maxchar); if (!u) return NULL; @@ -10008,31 +9882,6 @@ return 0; } -static void -replace_1char_inplace(PyObject *u, Py_ssize_t pos, - Py_UCS4 u1, Py_UCS4 u2, Py_ssize_t maxcount) -{ - int kind = PyUnicode_KIND(u); - void *data = PyUnicode_DATA(u); - Py_ssize_t len = PyUnicode_GET_LENGTH(u); - if (kind == PyUnicode_1BYTE_KIND) { - ucs1lib_replace_1char_inplace((Py_UCS1 *)data + pos, - (Py_UCS1 *)data + len, - u1, u2, maxcount); - } - else if (kind == PyUnicode_2BYTE_KIND) { - ucs2lib_replace_1char_inplace((Py_UCS2 *)data + pos, - (Py_UCS2 *)data + len, - u1, u2, maxcount); - } - else { - assert(kind == PyUnicode_4BYTE_KIND); - ucs4lib_replace_1char_inplace((Py_UCS4 *)data + pos, - (Py_UCS4 *)data + len, - u1, u2, maxcount); - } -} - static PyObject * replace(PyObject *self, PyObject *str1, PyObject *str2, Py_ssize_t maxcount) @@ -10049,7 +9898,7 @@ Py_ssize_t len1 = PyUnicode_GET_LENGTH(str1); Py_ssize_t len2 = PyUnicode_GET_LENGTH(str2); int mayshrink; - Py_UCS4 maxchar, maxchar_str1, maxchar_str2; + Py_UCS4 maxchar, maxchar_str2; if (maxcount < 0) maxcount = PY_SSIZE_T_MAX; @@ -10058,17 +9907,16 @@ if (str1 == str2) goto nothing; - - maxchar = PyUnicode_MAX_CHAR_VALUE(self); - maxchar_str1 = PyUnicode_MAX_CHAR_VALUE(str1); - if (maxchar < maxchar_str1) + if (skind < kind1) /* substring too wide to be present */ goto nothing; + + maxchar = PyUnicode_MAX_CHAR_VALUE(self); maxchar_str2 = PyUnicode_MAX_CHAR_VALUE(str2); /* Replacing str1 with str2 may cause a maxchar reduction in the result string. */ - mayshrink = (maxchar_str2 < maxchar_str1) && (maxchar == maxchar_str1); - maxchar = Py_MAX(maxchar, maxchar_str2); + mayshrink = (maxchar_str2 < maxchar); + maxchar = MAX_MAXCHAR(maxchar, maxchar_str2); if (len1 == len2) { /* same length */ @@ -10077,19 +9925,35 @@ if (len1 == 1) { /* replace characters */ Py_UCS4 u1, u2; - Py_ssize_t pos; - - u1 = PyUnicode_READ(kind1, buf1, 0); - pos = findchar(sbuf, skind, slen, u1, 1); + int rkind; + Py_ssize_t index, pos; + char *src; + + u1 = PyUnicode_READ_CHAR(str1, 0); + pos = findchar(sbuf, PyUnicode_KIND(self), slen, u1, 1); if (pos < 0) goto nothing; - u2 = PyUnicode_READ(kind2, buf2, 0); + u2 = PyUnicode_READ_CHAR(str2, 0); u = PyUnicode_New(slen, maxchar); if (!u) goto error; - _PyUnicode_FastCopyCharacters(u, 0, self, 0, slen); - replace_1char_inplace(u, pos, u1, u2, maxcount); + rkind = PyUnicode_KIND(u); + + PyUnicode_WRITE(rkind, PyUnicode_DATA(u), pos, u2); + index = 0; + src = sbuf; + while (--maxcount) + { + pos++; + src += pos * PyUnicode_KIND(self); + slen -= pos; + index += pos; + pos = findchar(src, PyUnicode_KIND(self), slen, u1, 1); + if (pos < 0) + break; + PyUnicode_WRITE(rkind, PyUnicode_DATA(u), index + pos, u2); + } } else { int rkind = skind; @@ -10191,9 +10055,7 @@ } new_size = slen + n * (len2 - len1); if (new_size == 0) { - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) - goto error; + Py_INCREF(unicode_empty); u = unicode_empty; goto done; } @@ -10401,24 +10263,10 @@ static int unicode_compare(PyObject *str1, PyObject *str2) { -#define COMPARE(TYPE1, TYPE2) \ - do { \ - TYPE1* p1 = (TYPE1 *)data1; \ - TYPE2* p2 = (TYPE2 *)data2; \ - TYPE1* end = p1 + len; \ - Py_UCS4 c1, c2; \ - for (; p1 != end; p1++, p2++) { \ - c1 = *p1; \ - c2 = *p2; \ - if (c1 != c2) \ - return (c1 < c2) ? -1 : 1; \ - } \ - } \ - while (0) - int kind1, kind2; void *data1, *data2; - Py_ssize_t len1, len2, len; + Py_ssize_t len1, len2; + Py_ssize_t i, len; /* a string is equal to itself */ if (str1 == str2) @@ -10432,80 +10280,23 @@ len2 = PyUnicode_GET_LENGTH(str2); len = Py_MIN(len1, len2); - switch(kind1) { - case PyUnicode_1BYTE_KIND: - { - switch(kind2) { - case PyUnicode_1BYTE_KIND: - { - int cmp = memcmp(data1, data2, len); - /* normalize result of memcmp() into the range [-1; 1] */ - if (cmp < 0) - return -1; - if (cmp > 0) - return 1; - break; - } - case PyUnicode_2BYTE_KIND: - COMPARE(Py_UCS1, Py_UCS2); - break; - case PyUnicode_4BYTE_KIND: - COMPARE(Py_UCS1, Py_UCS4); - break; - default: - assert(0); - } - break; - } - case PyUnicode_2BYTE_KIND: - { - switch(kind2) { - case PyUnicode_1BYTE_KIND: - COMPARE(Py_UCS2, Py_UCS1); - break; - case PyUnicode_2BYTE_KIND: - { - COMPARE(Py_UCS2, Py_UCS2); - break; - } - case PyUnicode_4BYTE_KIND: - COMPARE(Py_UCS2, Py_UCS4); - break; - default: - assert(0); - } - break; - } - case PyUnicode_4BYTE_KIND: - { - switch(kind2) { - case PyUnicode_1BYTE_KIND: - COMPARE(Py_UCS4, Py_UCS1); - break; - case PyUnicode_2BYTE_KIND: - COMPARE(Py_UCS4, Py_UCS2); - break; - case PyUnicode_4BYTE_KIND: - { -#if defined(HAVE_WMEMCMP) && SIZEOF_WCHAR_T == 4 - int cmp = wmemcmp((wchar_t *)data1, (wchar_t *)data2, len); - /* normalize result of wmemcmp() into the range [-1; 1] */ - if (cmp < 0) - return -1; - if (cmp > 0) - return 1; -#else - COMPARE(Py_UCS4, Py_UCS4); -#endif - break; - } - default: - assert(0); - } - break; - } - default: - assert(0); + if (kind1 == 1 && kind2 == 1) { + int cmp = memcmp(data1, data2, len); + /* normalize result of memcmp() into the range [-1; 1] */ + if (cmp < 0) + return -1; + if (cmp > 0) + return 1; + } + else { + for (i = 0; i < len; ++i) { + Py_UCS4 c1, c2; + c1 = PyUnicode_READ(kind1, data1, i); + c2 = PyUnicode_READ(kind2, data2, i); + + if (c1 != c2) + return (c1 < c2) ? -1 : 1; + } } if (len1 == len2) @@ -10514,8 +10305,6 @@ return -1; else return 1; - -#undef COMPARE } static int @@ -10640,7 +10429,7 @@ PyUnicode_Contains(PyObject *container, PyObject *element) { PyObject *str, *sub; - int kind1, kind2; + int kind1, kind2, kind; void *buf1, *buf2; Py_ssize_t len1, len2; int result; @@ -10659,18 +10448,23 @@ Py_DECREF(sub); return -1; } + if (PyUnicode_READY(sub) == -1 || PyUnicode_READY(str) == -1) { + Py_DECREF(sub); + Py_DECREF(str); + } kind1 = PyUnicode_KIND(str); kind2 = PyUnicode_KIND(sub); + kind = kind1; buf1 = PyUnicode_DATA(str); buf2 = PyUnicode_DATA(sub); - if (kind2 != kind1) { - if (kind2 > kind1) { + if (kind2 != kind) { + if (kind2 > kind) { Py_DECREF(sub); Py_DECREF(str); return 0; } - buf2 = _PyUnicode_AsKind(sub, kind1); + buf2 = _PyUnicode_AsKind(sub, kind); } if (!buf2) { Py_DECREF(sub); @@ -10680,7 +10474,7 @@ len1 = PyUnicode_GET_LENGTH(str); len2 = PyUnicode_GET_LENGTH(sub); - switch (kind1) { + switch (kind) { case PyUnicode_1BYTE_KIND: result = ucs1lib_find(buf1, len1, buf2, len2, 0) != -1; break; @@ -10698,7 +10492,7 @@ Py_DECREF(str); Py_DECREF(sub); - if (kind2 != kind1) + if (kind2 != kind) PyMem_Free(buf2); return result; @@ -10742,7 +10536,7 @@ maxchar = PyUnicode_MAX_CHAR_VALUE(u); maxchar2 = PyUnicode_MAX_CHAR_VALUE(v); - maxchar = Py_MAX(maxchar, maxchar2); + maxchar = MAX_MAXCHAR(maxchar, maxchar2); /* Concat the two Unicode strings */ w = PyUnicode_New(new_len, maxchar); @@ -10774,8 +10568,7 @@ return; } left = *p_left; - if (right == NULL || left == NULL - || !PyUnicode_Check(left) || !PyUnicode_Check(right)) { + if (right == NULL || left == NULL || !PyUnicode_Check(left)) { if (!PyErr_Occurred()) PyErr_BadInternalCall(); goto error; @@ -10815,16 +10608,22 @@ && !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) { /* append inplace */ - if (unicode_resize(p_left, new_len) != 0) + if (unicode_resize(p_left, new_len) != 0) { + /* XXX if _PyUnicode_Resize() fails, 'left' has been + * deallocated so it cannot be put back into + * 'variable'. The MemoryError is raised when there + * is no value in 'variable', which might (very + * remotely) be a cause of incompatibilities. + */ goto error; - + } /* copy 'right' into the newly allocated area of 'left' */ _PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len); } else { maxchar = PyUnicode_MAX_CHAR_VALUE(left); maxchar2 = PyUnicode_MAX_CHAR_VALUE(right); - maxchar = Py_MAX(maxchar, maxchar2); + maxchar = MAX_MAXCHAR(maxchar, maxchar2); /* Concat the two Unicode strings */ res = PyUnicode_New(new_len, maxchar); @@ -10873,10 +10672,8 @@ kind1 = PyUnicode_KIND(self); kind2 = PyUnicode_KIND(substring); - if (kind2 > kind1) { - Py_DECREF(substring); + if (kind2 > kind1) return PyLong_FromLong(0); - } kind = kind1; buf1 = PyUnicode_DATA(self); buf2 = PyUnicode_DATA(substring); @@ -11054,14 +10851,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } + if (PyUnicode_READY(self) == -1) + return NULL; + if (PyUnicode_READY(substring) == -1) + return NULL; result = any_find_slice(1, self, substring, start, end); @@ -11184,14 +10977,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } + if (PyUnicode_READY(self) == -1) + return NULL; + if (PyUnicode_READY(substring) == -1) + return NULL; result = any_find_slice(1, self, substring, start, end); @@ -11602,10 +11391,7 @@ "S.isidentifier() -> bool\n\ \n\ Return True if S is a valid identifier according\n\ -to the language definition.\n\ -\n\ -Use keyword.iskeyword() to test for reserved identifiers\n\ -such as \"def\" and \"class\".\n"); +to the language definition."); static PyObject* unicode_isidentifier(PyObject *self) @@ -11721,7 +11507,6 @@ int kind; Py_ssize_t i, j, len; BLOOM_MASK sepmask; - Py_ssize_t seplen; if (PyUnicode_READY(self) == -1 || PyUnicode_READY(sepobj) == -1) return NULL; @@ -11729,35 +11514,24 @@ kind = PyUnicode_KIND(self); data = PyUnicode_DATA(self); len = PyUnicode_GET_LENGTH(self); - seplen = PyUnicode_GET_LENGTH(sepobj); sepmask = make_bloom_mask(PyUnicode_KIND(sepobj), PyUnicode_DATA(sepobj), - seplen); + PyUnicode_GET_LENGTH(sepobj)); i = 0; if (striptype != RIGHTSTRIP) { - while (i < len) { - Py_UCS4 ch = PyUnicode_READ(kind, data, i); - if (!BLOOM(sepmask, ch)) - break; - if (PyUnicode_FindChar(sepobj, ch, 0, seplen, 1) < 0) - break; + while (i < len && + BLOOM_MEMBER(sepmask, PyUnicode_READ(kind, data, i), sepobj)) { i++; } } j = len; if (striptype != LEFTSTRIP) { - j--; - while (j >= i) { - Py_UCS4 ch = PyUnicode_READ(kind, data, j); - if (!BLOOM(sepmask, ch)) - break; - if (PyUnicode_FindChar(sepobj, ch, 0, seplen, 1) < 0) - break; + do { j--; - } - + } while (j >= i && + BLOOM_MEMBER(sepmask, PyUnicode_READ(kind, data, j), sepobj)); j++; } @@ -11784,8 +11558,10 @@ PyErr_SetString(PyExc_IndexError, "string index out of range"); return NULL; } - if (start >= length || end < start) - _Py_RETURN_UNICODE_EMPTY(); + if (start >= length || end < start) { + Py_INCREF(unicode_empty); + return unicode_empty; + } length = end - start; if (PyUnicode_IS_ASCII(self)) { @@ -11804,63 +11580,30 @@ static PyObject * do_strip(PyObject *self, int striptype) { + int kind; + void *data; Py_ssize_t len, i, j; if (PyUnicode_READY(self) == -1) return NULL; + kind = PyUnicode_KIND(self); + data = PyUnicode_DATA(self); len = PyUnicode_GET_LENGTH(self); - if (PyUnicode_IS_ASCII(self)) { - Py_UCS1 *data = PyUnicode_1BYTE_DATA(self); - - i = 0; - if (striptype != RIGHTSTRIP) { - while (i < len) { - Py_UCS1 ch = data[i]; - if (!_Py_ascii_whitespace[ch]) - break; - i++; - } - } - - j = len; - if (striptype != LEFTSTRIP) { + i = 0; + if (striptype != RIGHTSTRIP) { + while (i < len && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, i))) { + i++; + } + } + + j = len; + if (striptype != LEFTSTRIP) { + do { j--; - while (j >= i) { - Py_UCS1 ch = data[j]; - if (!_Py_ascii_whitespace[ch]) - break; - j--; - } - j++; - } - } - else { - int kind = PyUnicode_KIND(self); - void *data = PyUnicode_DATA(self); - - i = 0; - if (striptype != RIGHTSTRIP) { - while (i < len) { - Py_UCS4 ch = PyUnicode_READ(kind, data, i); - if (!Py_UNICODE_ISSPACE(ch)) - break; - i++; - } - } - - j = len; - if (striptype != LEFTSTRIP) { - j--; - while (j >= i) { - Py_UCS4 ch = PyUnicode_READ(kind, data, j); - if (!Py_UNICODE_ISSPACE(ch)) - break; - j--; - } - j++; - } + } while (j >= i && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, j))); + j++; } return PyUnicode_Substring(self, i, j); @@ -11945,8 +11688,10 @@ PyObject *u; Py_ssize_t nchars, n; - if (len < 1) - _Py_RETURN_UNICODE_EMPTY(); + if (len < 1) { + Py_INCREF(unicode_empty); + return unicode_empty; + } /* no repeat, return original string */ if (len == 1) @@ -12084,7 +11829,7 @@ Py_ssize_t isize; Py_ssize_t osize, squote, dquote, i, o; Py_UCS4 max, quote; - int ikind, okind, unchanged; + int ikind, okind; void *idata, *odata; if (PyUnicode_READY(unicode) == -1) @@ -12095,7 +11840,7 @@ /* Compute length of output, quote characters, and maximum character */ - osize = 0; + osize = 2; /* quotes */ max = 127; squote = dquote = 0; ikind = PyUnicode_KIND(unicode); @@ -12126,9 +11871,7 @@ } quote = '\''; - unchanged = (osize == isize); if (squote) { - unchanged = 0; if (dquote) /* Both squote and dquote present. Use squote, and escape them */ @@ -12136,7 +11879,6 @@ else quote = '"'; } - osize += 2; /* quotes */ repr = PyUnicode_New(osize, max); if (repr == NULL) @@ -12146,87 +11888,81 @@ PyUnicode_WRITE(okind, odata, 0, quote); PyUnicode_WRITE(okind, odata, osize-1, quote); - if (unchanged) { - _PyUnicode_FastCopyCharacters(repr, 1, - unicode, 0, - isize); - } - else { - for (i = 0, o = 1; i < isize; i++) { - Py_UCS4 ch = PyUnicode_READ(ikind, idata, i); - - /* Escape quotes and backslashes */ - if ((ch == quote) || (ch == '\\')) { + + for (i = 0, o = 1; i < isize; i++) { + Py_UCS4 ch = PyUnicode_READ(ikind, idata, i); + + /* Escape quotes and backslashes */ + if ((ch == quote) || (ch == '\\')) { + PyUnicode_WRITE(okind, odata, o++, '\\'); + PyUnicode_WRITE(okind, odata, o++, ch); + continue; + } + + /* Map special whitespace to '\t', \n', '\r' */ + if (ch == '\t') { + PyUnicode_WRITE(okind, odata, o++, '\\'); + PyUnicode_WRITE(okind, odata, o++, 't'); + } + else if (ch == '\n') { + PyUnicode_WRITE(okind, odata, o++, '\\'); + PyUnicode_WRITE(okind, odata, o++, 'n'); + } + else if (ch == '\r') { + PyUnicode_WRITE(okind, odata, o++, '\\'); + PyUnicode_WRITE(okind, odata, o++, 'r'); + } + + /* Map non-printable US ASCII to '\xhh' */ + else if (ch < ' ' || ch == 0x7F) { + PyUnicode_WRITE(okind, odata, o++, '\\'); + PyUnicode_WRITE(okind, odata, o++, 'x'); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0x000F]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0x000F]); + } + + /* Copy ASCII characters as-is */ + else if (ch < 0x7F) { + PyUnicode_WRITE(okind, odata, o++, ch); + } + + /* Non-ASCII characters */ + else { + /* Map Unicode whitespace and control characters + (categories Z* and C* except ASCII space) + */ + if (!Py_UNICODE_ISPRINTABLE(ch)) { PyUnicode_WRITE(okind, odata, o++, '\\'); + /* Map 8-bit characters to '\xhh' */ + if (ch <= 0xff) { + PyUnicode_WRITE(okind, odata, o++, 'x'); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0x000F]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0x000F]); + } + /* Map 16-bit characters to '\uxxxx' */ + else if (ch <= 0xffff) { + PyUnicode_WRITE(okind, odata, o++, 'u'); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 12) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 8) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0xF]); + } + /* Map 21-bit characters to '\U00xxxxxx' */ + else { + PyUnicode_WRITE(okind, odata, o++, 'U'); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 28) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 24) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 20) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 16) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 12) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 8) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0xF]); + PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0xF]); + } + } + /* Copy characters as-is */ + else { PyUnicode_WRITE(okind, odata, o++, ch); - continue; - } - - /* Map special whitespace to '\t', \n', '\r' */ - if (ch == '\t') { - PyUnicode_WRITE(okind, odata, o++, '\\'); - PyUnicode_WRITE(okind, odata, o++, 't'); - } - else if (ch == '\n') { - PyUnicode_WRITE(okind, odata, o++, '\\'); - PyUnicode_WRITE(okind, odata, o++, 'n'); - } - else if (ch == '\r') { - PyUnicode_WRITE(okind, odata, o++, '\\'); - PyUnicode_WRITE(okind, odata, o++, 'r'); - } - - /* Map non-printable US ASCII to '\xhh' */ - else if (ch < ' ' || ch == 0x7F) { - PyUnicode_WRITE(okind, odata, o++, '\\'); - PyUnicode_WRITE(okind, odata, o++, 'x'); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0x000F]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0x000F]); - } - - /* Copy ASCII characters as-is */ - else if (ch < 0x7F) { - PyUnicode_WRITE(okind, odata, o++, ch); - } - - /* Non-ASCII characters */ - else { - /* Map Unicode whitespace and control characters - (categories Z* and C* except ASCII space) - */ - if (!Py_UNICODE_ISPRINTABLE(ch)) { - PyUnicode_WRITE(okind, odata, o++, '\\'); - /* Map 8-bit characters to '\xhh' */ - if (ch <= 0xff) { - PyUnicode_WRITE(okind, odata, o++, 'x'); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0x000F]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0x000F]); - } - /* Map 16-bit characters to '\uxxxx' */ - else if (ch <= 0xffff) { - PyUnicode_WRITE(okind, odata, o++, 'u'); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 12) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 8) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0xF]); - } - /* Map 21-bit characters to '\U00xxxxxx' */ - else { - PyUnicode_WRITE(okind, odata, o++, 'U'); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 28) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 24) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 20) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 16) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 12) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 8) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0xF]); - PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0xF]); - } - } - /* Copy characters as-is */ - else { - PyUnicode_WRITE(okind, odata, o++, ch); - } } } } @@ -12256,14 +11992,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } + if (PyUnicode_READY(self) == -1) + return NULL; + if (PyUnicode_READY(substring) == -1) + return NULL; result = any_find_slice(-1, self, substring, start, end); @@ -12292,14 +12024,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } + if (PyUnicode_READY(self) == -1) + return NULL; + if (PyUnicode_READY(substring) == -1) + return NULL; result = any_find_slice(-1, self, substring, start, end); @@ -12957,36 +12685,30 @@ return NULL; } result = tailmatch(self, substring, start, end, +1); + if (result == -1) + return NULL; Py_DECREF(substring); - if (result == -1) - return NULL; return PyBool_FromLong(result); } Py_LOCAL_INLINE(void) _PyUnicodeWriter_Update(_PyUnicodeWriter *writer) { - if (!writer->readonly) - writer->size = PyUnicode_GET_LENGTH(writer->buffer); - else { - /* Copy-on-write mode: set buffer size to 0 so - * _PyUnicodeWriter_Prepare() will copy (and enlarge) the buffer on - * next write. */ - writer->size = 0; - } + writer->size = PyUnicode_GET_LENGTH(writer->buffer); writer->maxchar = PyUnicode_MAX_CHAR_VALUE(writer->buffer); writer->data = PyUnicode_DATA(writer->buffer); writer->kind = PyUnicode_KIND(writer->buffer); } void -_PyUnicodeWriter_Init(_PyUnicodeWriter *writer) +_PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length) { memset(writer, 0, sizeof(*writer)); #ifdef Py_DEBUG writer->kind = 5; /* invalid kind */ #endif - writer->min_char = 127; + writer->min_length = Py_MAX(min_length, 100); + writer->overallocate = (min_length > 0); } int @@ -13004,28 +12726,29 @@ } newlen = writer->pos + length; - maxchar = Py_MAX(maxchar, writer->min_char); - if (writer->buffer == NULL) { - assert(!writer->readonly); - if (writer->overallocate && newlen <= (PY_SSIZE_T_MAX - newlen / 4)) { + if (writer->overallocate) { /* overallocate 25% to limit the number of resize */ - newlen += newlen / 4; - } - if (newlen < writer->min_length) - newlen = writer->min_length; - + if (newlen <= (PY_SSIZE_T_MAX - newlen / 4)) + newlen += newlen / 4; + if (newlen < writer->min_length) + newlen = writer->min_length; + } writer->buffer = PyUnicode_New(newlen, maxchar); if (writer->buffer == NULL) return -1; - } - else if (newlen > writer->size) { - if (writer->overallocate && newlen <= (PY_SSIZE_T_MAX - newlen / 4)) { + _PyUnicodeWriter_Update(writer); + return 0; + } + + if (newlen > writer->size) { + if (writer->overallocate) { /* overallocate 25% to limit the number of resize */ - newlen += newlen / 4; - } - if (newlen < writer->min_length) - newlen = writer->min_length; + if (newlen <= (PY_SSIZE_T_MAX - newlen / 4)) + newlen += newlen / 4; + if (newlen < writer->min_length) + newlen = writer->min_length; + } if (maxchar > writer->maxchar || writer->readonly) { /* resize + widen */ @@ -13043,6 +12766,7 @@ return -1; } writer->buffer = newbuffer; + _PyUnicodeWriter_Update(writer); } else if (maxchar > writer->maxchar) { assert(!writer->readonly); @@ -13053,27 +12777,11 @@ writer->buffer, 0, writer->pos); Py_DECREF(writer->buffer); writer->buffer = newbuffer; - } - _PyUnicodeWriter_Update(writer); + _PyUnicodeWriter_Update(writer); + } return 0; } -Py_LOCAL_INLINE(int) -_PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch) -{ - if (_PyUnicodeWriter_Prepare(writer, 1, ch) < 0) - return -1; - PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch); - writer->pos++; - return 0; -} - -int -_PyUnicodeWriter_WriteChar(_PyUnicodeWriter *writer, Py_UCS4 ch) -{ - return _PyUnicodeWriter_WriteCharInline(writer, ch); -} - int _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str) { @@ -13088,10 +12796,11 @@ maxchar = PyUnicode_MAX_CHAR_VALUE(str); if (maxchar > writer->maxchar || len > writer->size - writer->pos) { if (writer->buffer == NULL && !writer->overallocate) { - writer->readonly = 1; Py_INCREF(str); writer->buffer = str; _PyUnicodeWriter_Update(writer); + writer->readonly = 1; + writer->size = 0; writer->pos += len; return 0; } @@ -13105,41 +12814,6 @@ } int -_PyUnicodeWriter_WriteSubstring(_PyUnicodeWriter *writer, PyObject *str, - Py_ssize_t start, Py_ssize_t end) -{ - Py_UCS4 maxchar; - Py_ssize_t len; - - if (PyUnicode_READY(str) == -1) - return -1; - - assert(0 <= start); - assert(end <= PyUnicode_GET_LENGTH(str)); - assert(start <= end); - - if (end == 0) - return 0; - - if (start == 0 && end == PyUnicode_GET_LENGTH(str)) - return _PyUnicodeWriter_WriteStr(writer, str); - - if (PyUnicode_MAX_CHAR_VALUE(str) > writer->maxchar) - maxchar = _PyUnicode_FindMaxChar(str, start, end); - else - maxchar = writer->maxchar; - len = end - start; - - if (_PyUnicodeWriter_Prepare(writer, len, maxchar) < 0) - return -1; - - _PyUnicode_FastCopyCharacters(writer->buffer, writer->pos, - str, start, len); - writer->pos += len; - return 0; -} - -int _PyUnicodeWriter_WriteCstr(_PyUnicodeWriter *writer, const char *str, Py_ssize_t len) { Py_UCS4 maxchar; @@ -13155,31 +12829,26 @@ PyObject * _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer) { - PyObject *str; if (writer->pos == 0) { - Py_CLEAR(writer->buffer); - _Py_RETURN_UNICODE_EMPTY(); + Py_XDECREF(writer->buffer); + Py_INCREF(unicode_empty); + return unicode_empty; } if (writer->readonly) { - str = writer->buffer; - writer->buffer = NULL; - assert(PyUnicode_GET_LENGTH(str) == writer->pos); - return str; + assert(PyUnicode_GET_LENGTH(writer->buffer) == writer->pos); + return writer->buffer; } if (PyUnicode_GET_LENGTH(writer->buffer) != writer->pos) { PyObject *newbuffer; newbuffer = resize_compact(writer->buffer, writer->pos); if (newbuffer == NULL) { Py_DECREF(writer->buffer); - writer->buffer = NULL; return NULL; } writer->buffer = newbuffer; } - str = writer->buffer; - writer->buffer = NULL; - assert(_PyUnicode_CheckConsistency(str, 1)); - return unicode_result_ready(str); + assert(_PyUnicode_CheckConsistency(writer->buffer, 1)); + return writer->buffer; } void @@ -13214,7 +12883,7 @@ if (PyUnicode_READY(self) == -1) return NULL; - _PyUnicodeWriter_Init(&writer); + _PyUnicodeWriter_Init(&writer, 0); ret = _PyUnicode_FormatAdvancedWriter(&writer, self, format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); @@ -13381,7 +13050,8 @@ } if (slicelength <= 0) { - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(unicode_empty); + return unicode_empty; } else if (start == 0 && step == 1 && slicelength == PyUnicode_GET_LENGTH(self)) { return unicode_result_unchanged(self); @@ -13591,14 +13261,12 @@ /* To modify the string in-place, there can only be one reference. */ if (Py_REFCNT(result) != 1) { - Py_DECREF(result); PyErr_BadInternalCall(); return NULL; } buf = PyUnicode_DATA(result); llen = PyUnicode_GET_LENGTH(result); if (llen > INT_MAX) { - Py_DECREF(result); PyErr_SetString(PyExc_ValueError, "string too large in _PyBytes_FormatLong"); return NULL; @@ -13985,8 +13653,10 @@ ctx->writer.overallocate = 0; if (arg->ch == '%') { - if (_PyUnicodeWriter_WriteCharInline(writer, '%') < 0) + if (_PyUnicodeWriter_Prepare(writer, 1, '%') == -1) return -1; + PyUnicode_WRITE(writer->kind, writer->data, writer->pos, '%'); + writer->pos += 1; return 1; } @@ -14061,8 +13731,10 @@ return -1; if (arg->width == -1 && arg->prec == -1) { /* Fast path */ - if (_PyUnicodeWriter_WriteCharInline(writer, ch) < 0) + if (_PyUnicodeWriter_Prepare(writer, 1, ch) == -1) return -1; + PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch); + writer->pos += 1; return 1; } *p_str = PyUnicode_FromOrdinal(ch); @@ -14095,7 +13767,7 @@ Py_ssize_t pindex; Py_UCS4 signchar; Py_ssize_t buflen; - Py_UCS4 maxchar; + Py_UCS4 maxchar, bufmaxchar; Py_ssize_t sublen; _PyUnicodeWriter *writer = &ctx->writer; Py_UCS4 fill; @@ -14148,26 +13820,23 @@ arg->width = len; /* Prepare the writer */ - maxchar = writer->maxchar; + bufmaxchar = 127; if (!(arg->flags & F_LJUST)) { if (arg->sign) { if ((arg->width-1) > len) - maxchar = Py_MAX(maxchar, fill); + bufmaxchar = MAX_MAXCHAR(bufmaxchar, fill); } else { if (arg->width > len) - maxchar = Py_MAX(maxchar, fill); - } - } - if (PyUnicode_MAX_CHAR_VALUE(str) > maxchar) { - Py_UCS4 strmaxchar = _PyUnicode_FindMaxChar(str, 0, pindex+len); - maxchar = Py_MAX(maxchar, strmaxchar); - } - + bufmaxchar = MAX_MAXCHAR(bufmaxchar, fill); + } + } + maxchar = _PyUnicode_FindMaxChar(str, 0, pindex+len); + bufmaxchar = MAX_MAXCHAR(bufmaxchar, maxchar); buflen = arg->width; if (arg->sign && len == arg->width) buflen++; - if (_PyUnicodeWriter_Prepare(writer, buflen, maxchar) == -1) + if (_PyUnicodeWriter_Prepare(writer, buflen, bufmaxchar) == -1) return -1; /* Write the sign if needed */ @@ -14300,9 +13969,7 @@ ctx.fmtcnt = PyUnicode_GET_LENGTH(ctx.fmtstr); ctx.fmtpos = 0; - _PyUnicodeWriter_Init(&ctx.writer); - ctx.writer.min_length = ctx.fmtcnt + 100; - ctx.writer.overallocate = 1; + _PyUnicodeWriter_Init(&ctx.writer, ctx.fmtcnt + 100); if (PyTuple_Check(args)) { ctx.arglen = PyTuple_Size(args); @@ -14321,7 +13988,8 @@ while (--ctx.fmtcnt >= 0) { if (PyUnicode_READ(ctx.fmtkind, ctx.fmtdata, ctx.fmtpos) != '%') { - Py_ssize_t nonfmtpos; + Py_ssize_t nonfmtpos, sublen; + Py_UCS4 maxchar; nonfmtpos = ctx.fmtpos++; while (ctx.fmtcnt >= 0 && @@ -14333,10 +14001,15 @@ ctx.fmtpos--; ctx.writer.overallocate = 0; } - - if (_PyUnicodeWriter_WriteSubstring(&ctx.writer, ctx.fmtstr, - nonfmtpos, ctx.fmtpos) < 0) + sublen = ctx.fmtpos - nonfmtpos; + maxchar = _PyUnicode_FindMaxChar(ctx.fmtstr, + nonfmtpos, nonfmtpos + sublen); + if (_PyUnicodeWriter_Prepare(&ctx.writer, sublen, maxchar) == -1) goto onError; + + _PyUnicode_FastCopyCharacters(ctx.writer.buffer, ctx.writer.pos, + ctx.fmtstr, nonfmtpos, sublen); + ctx.writer.pos += sublen; } else { ctx.fmtpos++; @@ -14382,8 +14055,10 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:str", kwlist, &x, &encoding, &errors)) return NULL; - if (x == NULL) - _Py_RETURN_UNICODE_EMPTY(); + if (x == NULL) { + Py_INCREF(unicode_empty); + return unicode_empty; + } if (encoding == NULL && errors == NULL) return PyObject_Str(x); else @@ -14552,6 +14227,8 @@ int _PyUnicode_Init(void) { + int i; + /* XXX - move this array to unicodectype.c ? */ Py_UCS2 linebreak[] = { 0x000A, /* LINE FEED */ @@ -14565,11 +14242,13 @@ }; /* Init the implementation */ - _Py_INCREF_UNICODE_EMPTY(); + unicode_empty = PyUnicode_New(0, 0); if (!unicode_empty) Py_FatalError("Can't create empty string"); - Py_DECREF(unicode_empty); - + assert(_PyUnicode_CheckConsistency(unicode_empty, 1)); + + for (i = 0; i < 256; i++) + unicode_latin1[i] = NULL; if (PyType_Ready(&PyUnicode_Type) < 0) Py_FatalError("Can't initialize 'unicode'"); @@ -14578,8 +14257,7 @@ PyUnicode_2BYTE_KIND, linebreak, Py_ARRAY_LENGTH(linebreak)); - if (PyType_Ready(&EncodingMapType) < 0) - Py_FatalError("Can't initialize encoding map type"); + PyType_Ready(&EncodingMapType); if (PyType_Ready(&PyFieldNameIter_Type) < 0) Py_FatalError("Can't initialize field name iterator type"); @@ -14610,10 +14288,15 @@ { int i; - Py_CLEAR(unicode_empty); - - for (i = 0; i < 256; i++) - Py_CLEAR(unicode_latin1[i]); + Py_XDECREF(unicode_empty); + unicode_empty = NULL; + + for (i = 0; i < 256; i++) { + if (unicode_latin1[i]) { + Py_DECREF(unicode_latin1[i]); + unicode_latin1[i] = NULL; + } + } _PyUnicode_ClearStaticStrings(); (void)PyUnicode_ClearFreeList(); } @@ -14650,12 +14333,12 @@ t = PyDict_GetItem(interned, s); Py_END_ALLOW_RECURSION - if (t) { - Py_INCREF(t); - Py_DECREF(*p); - *p = t; - return; - } + if (t) { + Py_INCREF(t); + Py_DECREF(*p); + *p = t; + return; + } PyThreadState_GET()->recursion_critical = 1; if (PyDict_SetItem(interned, s, s) < 0) { @@ -14742,7 +14425,8 @@ "mortal/immortal\n", mortal_size, immortal_size); Py_DECREF(keys); PyDict_Clear(interned); - Py_CLEAR(interned); + Py_DECREF(interned); + interned = NULL; } diff -r 35c88c53cf64 -r ecc10f0afb76 Objects/weakrefobject.c --- a/Objects/weakrefobject.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Objects/weakrefobject.c Fri Feb 01 23:12:09 2013 +0100 @@ -338,11 +338,6 @@ } -static PyMemberDef weakref_members[] = { - {"__callback__", T_OBJECT, offsetof(PyWeakReference, wr_callback), READONLY}, - {NULL} /* Sentinel */ -}; - PyTypeObject _PyWeakref_RefType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) @@ -374,7 +369,7 @@ 0, /*tp_iter*/ 0, /*tp_iternext*/ 0, /*tp_methods*/ - weakref_members, /*tp_members*/ + 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_ctypes.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_ctypes.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,131 @@ +# Microsoft Developer Studio Project File - Name="_ctypes" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_ctypes - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_ctypes.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_ctypes.mak" CFG="_ctypes - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_ctypes - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_ctypes - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_ctypes" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_ctypes - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_ctypes" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\_ctypes\libffi_msvc" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1d1a0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_ctypes.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_ctypes - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_ctypes" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\_ctypes\libffi_msvc" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1d1a0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_ctypes_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_ctypes - Win32 Release" +# Name "_ctypes - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\_ctypes.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\callbacks.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\callproc.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\cfield.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\libffi_msvc\ffi.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\malloc_closure.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\libffi_msvc\prep_cif.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\stgdict.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\libffi_msvc\win32.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_ctypes_test.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_ctypes_test.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="_ctypes_test" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_ctypes_test - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_ctypes_test.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_ctypes_test.mak" CFG="_ctypes_test - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_ctypes_test - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_ctypes_test - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_ctypes_test" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_ctypes_test - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_ctypes_test" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"./_ctypes_test.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_ctypes_test - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_ctypes_test" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"./_ctypes_test_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_ctypes_test - Win32 Release" +# Name "_ctypes_test - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_ctypes\_ctypes_test.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_elementtree.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_elementtree.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,111 @@ +# Microsoft Developer Studio Project File - Name="_elementtree" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_elementtree - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_elementtree.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_elementtree.mak" CFG="_elementtree - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_elementtree - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_elementtree - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_elementtree" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_elementtree - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_elementtree" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D "BYTEORDER=1234" /D "XML_CONTEXT_BYTES=1024" /D "USE_PYEXPAT_CAPI" /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1d100000" /subsystem:windows /dll /debug /machine:I386 /out:"./_elementtree.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_elementtree - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_elementtree" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D "BYTEORDER=1234" /D "XML_CONTEXT_BYTES=1024" /D "USE_PYEXPAT_CAPI" /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1d100000" /subsystem:windows /dll /debug /machine:I386 /out:"./_elementtree_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_elementtree - Win32 Release" +# Name "_elementtree - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_elementtree.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\expat\xmlparse.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\expat\xmlrole.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\expat\xmltok.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_msi.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_msi.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="_msi" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_msi - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_msi.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_msi.mak" CFG="_msi - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_msi - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_msi - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_msi" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_msi - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_msi" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fci.lib msi.lib rpcrt4.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fci.lib msi.lib rpcrt4.lib /nologo /base:"0x1d1a0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_msi.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_msi - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_msi" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fci.lib msi.lib rpcrt4.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fci.lib msi.lib rpcrt4.lib /nologo /base:"0x1d1a0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_msi_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_msi - Win32 Release" +# Name "_msi - Win32 Debug" +# Begin Source File + +SOURCE=..\..\PC\_msi.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_multiprocessing.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_multiprocessing.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,107 @@ +# Microsoft Developer Studio Project File - Name="_multiprocessing" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_multiprocessing - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_multiprocessing.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_multiprocessing.mak" CFG="_multiprocessing - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_multiprocessing - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_multiprocessing - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_multiprocessing" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_multiprocessing - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_multiprocessing" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /base:"0x1e1D0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_multiprocessing.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_multiprocessing - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_multiprocessing" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /base:"0x1e1d0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_multiprocessing_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_multiprocessing - Win32 Release" +# Name "_multiprocessing - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_multiprocessing\multiprocessing.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_multiprocessing\semaphore.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_multiprocessing\win32_functions.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_socket.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_socket.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="_socket" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_socket - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_socket.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_socket.mak" CFG="_socket - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_socket - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_socket - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_socket" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_socket - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_socket" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /base:"0x1e1D0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_socket.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_socket - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_socket" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /base:"0x1e1D0000" /subsystem:windows /dll /debug /machine:I386 /out:"./_socket_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_socket - Win32 Release" +# Name "_socket - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\socketmodule.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_sqlite3.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_sqlite3.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,131 @@ +# Microsoft Developer Studio Project File - Name="_sqlite3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_sqlite3 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_sqlite3.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_sqlite3.mak" CFG="_sqlite3 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_sqlite3 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_sqlite3 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_sqlite3" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_sqlite3 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_sqlite3" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\sqlite-source-3.3.4" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D MODULE_NAME=\"sqlite3\" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\sqlite-source-3.3.4\sqlite3.lib /nologo /base:"0x1e180000" /subsystem:windows /dll /debug /machine:I386 /out:"./_sqlite3.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_sqlite3 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_sqlite3" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\sqlite-source-3.3.4" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D MODULE_NAME=\"sqlite3\" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\sqlite-source-3.3.4\sqlite3.lib /nologo /base:"0x1e180000" /subsystem:windows /dll /debug /machine:I386 /out:"./_sqlite3_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_sqlite3 - Win32 Release" +# Name "_sqlite3 - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\cache.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\connection.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\cursor.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\microprotocols.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\module.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\prepare_protocol.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\row.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\statement.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sqlite\util.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_ssl.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_ssl.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,89 @@ +# Microsoft Developer Studio Project File - Name="_ssl" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=_ssl - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_ssl.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_ssl.mak" CFG="_ssl - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_ssl - Win32 Release" (based on "Win32 (x86) External Target") +!MESSAGE "_ssl - Win32 Debug" (based on "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "_ssl - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Cmd_Line "NMAKE /f _ssl.mak" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "_ssl.exe" +# PROP BASE Bsc_Name "_ssl.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_ssl" +# PROP Cmd_Line "python build_ssl.py" +# PROP Rebuild_Opt "-a" +# PROP Target_File "_ssl.pyd" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ELSEIF "$(CFG)" == "_ssl - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "x86-temp-debug\_ssl" +# PROP BASE Intermediate_Dir "x86-temp-debug\_ssl" +# PROP BASE Cmd_Line "NMAKE /f _ssl.mak" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "_ssl_d.pyd" +# PROP BASE Bsc_Name "_ssl_d.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_ssl" +# PROP Cmd_Line "python_d -u build_ssl.py -d" +# PROP Rebuild_Opt "-a" +# PROP Target_File "_ssl_d.pyd" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ENDIF + +# Begin Target + +# Name "_ssl - Win32 Release" +# Name "_ssl - Win32 Debug" + +!IF "$(CFG)" == "_ssl - Win32 Release" + +!ELSEIF "$(CFG)" == "_ssl - Win32 Debug" + +!ENDIF + +# Begin Source File + +SOURCE=..\..\Modules\_ssl.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_ssl.mak --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_ssl.mak Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,22 @@ + +!IFDEF DEBUG +MODULE=_ssl_d.pyd +TEMP_DIR=x86-temp-debug/_ssl +CFLAGS=/Od /Zi /MDd /LDd /DDEBUG /D_DEBUG /DWIN32 +LFLAGS=/nodefaultlib:"msvcrt" +!ELSE +MODULE=_ssl.pyd +TEMP_DIR=x86-temp-release/_ssl +CFLAGS=/Ox /MD /LD /DWIN32 +LFLAGS= +!ENDIF + +INCLUDES=-I ../../Include -I .. -I $(SSL_DIR)/inc32 +SSL_LIB_DIR=$(SSL_DIR)/out32 +LIBS=gdi32.lib wsock32.lib user32.lib advapi32.lib /libpath:$(SSL_LIB_DIR) libeay32.lib ssleay32.lib + +SOURCE=../../Modules/_ssl.c $(SSL_LIB_DIR)/libeay32.lib $(SSL_LIB_DIR)/ssleay32.lib + +$(MODULE): $(SOURCE) ../*.h ../../Include/*.h + @if not exist "$(TEMP_DIR)/." mkdir "$(TEMP_DIR)" + cl /nologo $(SOURCE) $(CFLAGS) /Fo$(TEMP_DIR)\$*.obj $(INCLUDES) /link /out:$(MODULE) $(LIBS) $(LFLAGS) diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_testcapi.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_testcapi.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="_testcapi" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_testcapi - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_testcapi.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_testcapi.mak" CFG="_testcapi - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_testcapi - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_testcapi - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_testcapi" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_testcapi - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_testcapi" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "NDEBUG" +# ADD RSC /l 0xc09 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1e1F0000" /dll /machine:I386 /out:"./_testcapi.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_testcapi - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_testcapi" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "_DEBUG" +# ADD RSC /l 0xc09 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1e1F0000" /dll /debug /machine:I386 /out:"./_testcapi_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_testcapi - Win32 Release" +# Name "_testcapi - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_testcapimodule.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/_tkinter.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/_tkinter.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,103 @@ +# Microsoft Developer Studio Project File - Name="_tkinter" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=_tkinter - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "_tkinter.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "_tkinter.mak" CFG="_tkinter - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "_tkinter - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "_tkinter - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "_tkinter" +# PROP Scc_LocalPath "..\..\.." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "_tkinter - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\_tkinter" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\..\tcltk\include" /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "WITH_APPINIT" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 ..\..\..\tcltk\lib\tk85g.lib ..\..\..\tcltk\lib\tcl85g.lib odbc32.lib odbccp32.lib user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1e190000" /subsystem:windows /dll /debug /machine:I386 /out:"./_tkinter_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "_tkinter - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\_tkinter" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\..\tcltk\include" /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "WITH_APPINIT" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 ..\..\..\tcltk\lib\tk85.lib ..\..\..\tcltk\lib\tcl85.lib odbc32.lib odbccp32.lib user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1e190000" /subsystem:windows /dll /debug /machine:I386 /out:"./_tkinter.pyd" +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "_tkinter - Win32 Release" +# Name "_tkinter - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_tkinter.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\tkappinit.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/build_ssl.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/build_ssl.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,228 @@ +# Script for building the _ssl module for Windows. +# Uses Perl to setup the OpenSSL environment correctly +# and build OpenSSL, then invokes a simple nmake session +# for _ssl.pyd itself. + +# THEORETICALLY, you can: +# * Unpack the latest SSL release one level above your main Python source +# directory. It is likely you will already find the zlib library and +# any other external packages there. +# * Install ActivePerl and ensure it is somewhere on your path. +# * Run this script from the PC/VC6 directory. +# +# it should configure and build SSL, then build the ssl Python extension +# without intervention. + +# Modified by Christian Heimes +# Now this script supports pre-generated makefiles and assembly files. +# Developers don't need an installation of Perl anymore to build Python. A svn +# checkout from our svn repository is enough. + +import os, sys, re, shutil + +# 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: + fh = os.popen('"%s" -e "use Win32;"' % perl) + fh.read() + rc = fh.close() + if rc: + continue + return perl + print("Can not find a suitable 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") + return None + +# Locate the best SSL directory given a few roots to look into. +def find_best_ssl_dir(sources): + candidates = [] + for s in sources: + try: + # note: do not abspath s; the build will fail if any + # higher up directory name has spaces in it. + fnames = os.listdir(s) + except OSError: + fnames = [] + for fname in fnames: + fqn = os.path.join(s, fname) + if os.path.isdir(fqn) and fname.startswith("openssl-"): + candidates.append(fqn) + # Now we have all the candidates, locate the best. + best_parts = [] + best_name = None + for c in candidates: + parts = re.split("[.-]", os.path.basename(c))[1:] + # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers + if len(parts) >= 4: + continue + if parts > best_parts: + best_parts = parts + best_name = c + if best_name is not None: + print("Found an SSL directory at '%s'" % (best_name,)) + else: + print("Could not find an SSL directory in '%s'" % (sources,)) + sys.stdout.flush() + return best_name + +def fix_makefile(makefile): + """Fix some stuff in all makefiles + """ + if not os.path.isfile(makefile): + return + with open(makefile) as fin: + lines = fin.readlines() + with open(makefile, 'w') as fout: + for line in lines: + if line.startswith("PERL="): + continue + if line.startswith("CP="): + line = "CP=copy\n" + if line.startswith("MKDIR="): + line = "MKDIR=mkdir\n" + if line.startswith("CFLAG="): + line = line.strip() + for algo in ("RC5", "MDC2", "IDEA"): + noalgo = " -DOPENSSL_NO_%s" % algo + if noalgo not in line: + line = line + noalgo + line = line + '\n' + fout.write(line) + +def run_configure(configure, do_script): + print("perl Configure "+configure) + os.system("perl Configure "+configure) + print(do_script) + os.system(do_script) + +def cmp(f1, f2): + bufsize = 1024 * 8 + with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2: + while True: + b1 = fp1.read(bufsize) + b2 = fp2.read(bufsize) + if b1 != b2: + return False + if not b1: + return True + +def copy(src, dst): + if os.path.isfile(dst) and cmp(src, dst): + return + shutil.copy(src, dst) + +def main(): + debug = "-d" in sys.argv + build_all = "-a" in sys.argv + if 1: # Win32 + arch = "x86" + configure = "VC-WIN32" + do_script = "ms\\do_nasm" + makefile="ms\\nt.mak" + m32 = makefile + dirsuffix = "32" + configure += " no-idea no-rc5 no-mdc2" + make_flags = "" + if build_all: + make_flags = "-a" + # 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", ["\\perl\\bin", "C:\\perl\\bin"]) + perl = find_working_perl(perls) + if perl: + print("Found a working perl at '%s'" % (perl,)) + else: + print("No Perl installation was found. Existing Makefiles are used.") + sys.stdout.flush() + # Look for SSL 3 levels up from PC/VC6 - ie, same place zlib etc all live. + ssl_dir = find_best_ssl_dir(("..\\..\\..",)) + if ssl_dir is None: + sys.exit(1) + + old_cd = os.getcwd() + try: + os.chdir(ssl_dir) + # If the ssl makefiles do not exist, we invoke Perl to generate them. + # Due to a bug in this script, the makefile sometimes ended up empty + # Force a regeneration if it is. + if not os.path.isfile(makefile) or os.path.getsize(makefile)==0: + if perl is None: + print("Perl is required to build the makefiles!") + sys.exit(1) + + print("Creating the makefiles...") + 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"] + run_configure(configure, do_script) + if debug: + print("OpenSSL debug builds aren't supported.") + #if arch=="x86" and debug: + # # the do_masm script in openssl doesn't generate a debug + # # build makefile so we generate it here: + # os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile) + + fix_makefile(makefile) + copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch) + copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch) + + # If the assembler files don't exist in tmpXX, copy them there + if perl is None and os.path.exists("asm"+dirsuffix): + if not os.path.exists("tmp"+dirsuffix): + os.mkdir("tmp"+dirsuffix) + for f in os.listdir("asm"+dirsuffix): + if not f.endswith(".asm"): continue + if os.path.isfile(r"tmp%s\%s" % (dirsuffix, f)): continue + shutil.copy(r"asm%s\%s" % (dirsuffix, f), "tmp"+dirsuffix) + + # Now run make. + copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h") + copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h") + + #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile) + makeCommand = "nmake /nologo -f \"%s\"" % makefile + print("Executing ssl makefiles:", makeCommand) + sys.stdout.flush() + rc = os.system(makeCommand) + if rc: + print("Executing "+makefile+" failed") + print(rc) + sys.exit(rc) + finally: + os.chdir(old_cd) + # And finally, we can build the _ssl module itself for Python. + defs = "SSL_DIR=%s" % (ssl_dir,) + if debug: + defs = defs + " " + "DEBUG=1" + rc = os.system('nmake /nologo -f _ssl.mak ' + defs + " " + make_flags) + sys.exit(rc) + +if __name__=='__main__': + main() diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/build_tkinter.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/build_tkinter.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,81 @@ +import os +import sys +import subprocess + +TCL_MAJOR = 8 +TCL_MINOR = 5 +TCL_PATCH = 2 + +TIX_MAJOR = 8 +TIX_MINOR = 4 +TIX_PATCH = 3 + +def abspath(name): + par = os.path.pardir + return os.path.abspath(os.path.join(__file__, par, par, par, par, name)) + +TCL_DIR = abspath("tcl%d.%d.%d" % (TCL_MAJOR, TCL_MINOR, TCL_PATCH)) +TK_DIR = abspath("tk%d.%d.%d" % (TCL_MAJOR, TCL_MINOR, TCL_PATCH)) +TIX_DIR = abspath("tix%d.%d.%d" % (TIX_MAJOR, TIX_MINOR, TIX_PATCH)) +OUT_DIR = abspath("tcltk") + +def have_args(*a): + return any(s in sys.argv[1:] for s in a) + +def enter(dir): + os.chdir(os.path.join(dir, "win")) + +def main(): + debug = have_args("-d", "--debug") + clean = have_args("clean") + install = have_args("install") + tcl = have_args("tcl") + tk = have_args("tk") + tix = have_args("tix") + if not(tcl) and not(tk) and not(tix): + tcl = tk = tix = True + + def nmake(makefile, *a): + args = ["nmake", "/nologo", "/f", makefile, "DEBUG=%d" % debug] + args.extend(a) + subprocess.check_call(args) + + if tcl: + enter(TCL_DIR) + def nmake_tcl(*a): + nmake("makefile.vc", *a) + if clean: + nmake_tcl("clean") + elif install: + nmake_tcl("install", "INSTALLDIR=" + OUT_DIR) + else: + nmake_tcl() + + if tk: + enter(TK_DIR) + def nmake_tk(*a): + nmake("makefile.vc", "TCLDIR=" + TCL_DIR, *a) + if clean: + nmake_tk("clean") + elif install: + nmake_tk("install", "INSTALLDIR=" + OUT_DIR) + else: + nmake_tk() + + if tix: + enter(TIX_DIR) + def nmake_tix(*a): + nmake("python.mak", + "TCL_MAJOR=%d" % TCL_MAJOR, + "TCL_MINOR=%d" % TCL_MINOR, + "TCL_PATCH=%d" % TCL_PATCH, + "MACHINE=IX86", *a) + if clean: + nmake_tix("clean") + elif install: + nmake_tix("install", "INSTALL_DIR=" + OUT_DIR) + else: + nmake_tix() + +if __name__ == '__main__': + main() diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/bz2.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/bz2.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="bz2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=bz2 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "bz2.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "bz2.mak" CFG="bz2 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "bz2 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "bz2 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "bz2" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "bz2 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\bz2" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\..\bzip2-1.0.6" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 ..\..\..\bzip2-1.0.6\libbz2.lib /nologo /base:"0x1D170000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./bz2.pyd" +# SUBTRACT LINK32 /pdb:none /nodefaultlib + +!ELSEIF "$(CFG)" == "bz2 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\bz2" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\bzip2-1.0.6" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 ..\..\..\bzip2-1.0.6\libbz2.lib /nologo /base:"0x1D170000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"msvcrt" /nodefaultlib:"libc" /out:"./bz2_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "bz2 - Win32 Release" +# Name "bz2 - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\bz2module.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/make_versioninfo.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/make_versioninfo.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="make_versioninfo" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=make_versioninfo - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "make_versioninfo.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "make_versioninfo.mak" CFG="make_versioninfo - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "make_versioninfo - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "make_versioninfo - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "make_versioninfo" +# PROP Scc_LocalPath ".." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "make_versioninfo - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\make_versioninfo" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1d000000" /subsystem:console /debug /machine:I386 +# SUBTRACT LINK32 /pdb:none +# Begin Custom Build +InputPath=.\make_versioninfo.exe +SOURCE="$(InputPath)" + +"..\pythonnt_rc.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + .\make_versioninfo.exe >..\pythonnt_rc.h + +# End Custom Build + +!ELSEIF "$(CFG)" == "make_versioninfo - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\make_versioninfo" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /i "..\..\Include" /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1d000000" /subsystem:console /debug /machine:I386 /out:"./make_versioninfo_d.exe" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none +# Begin Custom Build +InputPath=.\make_versioninfo_d.exe +SOURCE="$(InputPath)" + +"..\pythonnt_rc_d.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + .\make_versioninfo_d.exe >..\pythonnt_rc_d.h + +# End Custom Build + +!ENDIF + +# Begin Target + +# Name "make_versioninfo - Win32 Release" +# Name "make_versioninfo - Win32 Debug" +# Begin Source File + +SOURCE=..\make_versioninfo.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/pcbuild.dsw --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/pcbuild.dsw Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,293 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "_ctypes"=".\_ctypes.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "_ctypes_test"=".\_ctypes_test.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "_elementtree"=".\_elementtree.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "_msi"=".\_msi.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "_multiprocessing"=".\_multiprocessing.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "_socket"=".\_socket.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "_sqlite3"=".\_sqlite3.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "_ssl"=".\_ssl.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency + Begin Project Dependency + Project_Dep_Name python + End Project Dependency + Begin Project Dependency + End Project Dependency +}}} + +############################################################################### + +Project: "_testcapi"=".\_testcapi.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "_tkinter"=".\_tkinter.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "bz2"=".\bz2.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "make_versioninfo"=".\make_versioninfo.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "pyexpat"=".\pyexpat.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "python"=".\python.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "pythoncore"=".\pythoncore.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name make_versioninfo + End Project Dependency +}}} + +############################################################################### + +Project: "pythonw"=".\pythonw.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "select"=".\select.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Project: "unicodedata"=".\unicodedata.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################## + +Project: "winsound"=".\winsound.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name pythoncore + End Project Dependency +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/pyexpat.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/pyexpat.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,111 @@ +# Microsoft Developer Studio Project File - Name="pyexpat" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=pyexpat - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "pyexpat.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "pyexpat.mak" CFG="pyexpat - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "pyexpat - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "pyexpat - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "pyexpat" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "pyexpat - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\pyexpat" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D BYTEORDER=1234 /D XML_CONTEXT_BYTES=1024 /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1D100000" /subsystem:windows /dll /debug /machine:I386 /out:"./pyexpat.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "pyexpat - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\pyexpat" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\Modules\expat" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "HAVE_EXPAT_H" /D "WIN32" /D "_WINDOWS" /D "XML_NS" /D "XML_DTD" /D BYTEORDER=1234 /D XML_CONTEXT_BYTES=1024 /D "XML_STATIC" /D "HAVE_MEMMOVE" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1D100000" /subsystem:windows /dll /debug /machine:I386 /out:"./pyexpat_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "pyexpat - Win32 Release" +# Name "pyexpat - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\pyexpat.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\expat\xmlparse.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\expat\xmlrole.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\expat\xmltok.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/python.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/python.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="python" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=python - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "python.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "python.mak" CFG="python - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "python - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "python - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "python" +# PROP Scc_LocalPath ".." +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "python - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\python" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1d000000" /subsystem:console /debug /machine:I386 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "python - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\python" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /i "....\\Include" /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1d000000" /stack:0x200000 /subsystem:console /debug /machine:I386 /out:"./python_d.exe" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "python - Win32 Release" +# Name "python - Win32 Debug" +# Begin Source File + +SOURCE=..\pycon.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\python.c +# End Source File +# Begin Source File + +SOURCE=..\python_exe.rc +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/pythoncore.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/pythoncore.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,780 @@ +# Microsoft Developer Studio Project File - Name="pythoncore" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=pythoncore - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "pythoncore.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "pythoncore.mak" CFG="pythoncore - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "pythoncore - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "pythoncore - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "pythoncore" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "pythoncore - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\pythoncore" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /I "..\..\modules\zlib" /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_DL_EXPORT" /YX /FD /Zm200 /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL" +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL" +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /i "..\..\Include" /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python34.dll" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "pythoncore - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\pythoncore" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\modules\zlib" /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "USE_DL_EXPORT" /D "WIN32" /D "_WINDOWS" /YX /FD /Zm200 /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL" +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL" +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /i "..\..\Include" /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python34_d.dll" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "pythoncore - Win32 Release" +# Name "pythoncore - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\_bisectmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\_codecs_cn.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\_codecs_hk.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\_codecs_iso2022.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\_codecs_jp.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\_codecs_kr.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\_codecs_tw.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_codecsmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_collectionsmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_csv.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_datetimemodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_functoolsmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_heapqmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\_iomodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_json.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_localemodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_lsprof.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_math.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_pickle.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_randommodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_sre.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_struct.c +# End Source File +# Begin Source File + +SOURCE=..\..\PC\_subprocess.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_threadmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_time.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\_warnings.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_weakref.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\abstract.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\accu.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\acceler.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\adler32.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\arraymodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\asdl.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\ast.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\atexitmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\audioop.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\binascii.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\bitset.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\bltinmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\boolobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\bufferedio.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\bytearrayobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\bytes_methods.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\bytesio.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\bytesobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\capsule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\cellobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\ceval.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\classobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cmathmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\codecs.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\codeobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\compile.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\complexobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\compress.c +# End Source File +# Begin Source File + +SOURCE=..\config.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\crc32.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\dynamic_annotations.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\deflate.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\descrobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\dictobject.c +# End Source File +# Begin Source File + +SOURCE=..\dl_nt.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\dtoa.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\dynload_win.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\enumobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\errnomodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\errors.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\exceptions.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\fileio.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\fileobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\fileutils.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\firstsets.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\floatobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\formatter_unicode.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\frameobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\frozen.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\funcobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\future.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\gcmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\genobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\getargs.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\getbuildinfo.c +# ADD CPP /D BUILD=46 +# End Source File +# Begin Source File + +SOURCE=..\..\Python\getcompiler.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\getcopyright.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\getopt.c +# End Source File +# Begin Source File + +SOURCE=..\getpathp.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\getplatform.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\getversion.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\graminit.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\grammar.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\grammar1.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\gzio.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\import.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\importdl.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\infback.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\inffast.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\inflate.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\inftrees.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\iobase.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\iterobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\itertoolsmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\listnode.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\listobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\longobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\main.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\marshal.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\mathmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\md5module.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\memoryobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\metagrammar.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\methodobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\mmapmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\modsupport.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\moduleobject.c +# End Source File +# Begin Source File + +SOURCE=..\msvcrtmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\cjkcodecs\multibytecodec.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\myreadline.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\mysnprintf.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\mystrtoul.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\node.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\object.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\obmalloc.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\operator.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\parser.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\parsermodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\parsetok.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\peephole.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\posixmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pyarena.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pyctype.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pyfpe.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pymath.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pystate.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pystrcmp.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pystrtod.c +# End Source File +# Begin Source File + +SOURCE="..\..\Python\Python-ast.c" +# End Source File +# Begin Source File + +SOURCE=..\python_nt.rc +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pythonrun.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\pytime.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\random.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\rangeobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\rotatingtree.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\setobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\sha1module.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\sha256module.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\sha512module.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\signalmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\sliceobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\stringio.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\structmember.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\structseq.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\symtable.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\symtablemodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\sysmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\_io\textio.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\thread.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\timemodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Parser\tokenizer.c +# End Source File +# Begin Source File + +SOURCE=..\..\Python\traceback.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\trees.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\tupleobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\typeobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\uncompr.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\unicodectype.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\unicodeobject.c +# End Source File +# Begin Source File + +SOURCE=..\..\Objects\weakrefobject.c +# End Source File +# Begin Source File + +SOURCE=..\winreg.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\xxsubtype.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zipimport.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlibmodule.c +# End Source File +# Begin Source File + +SOURCE=..\..\Modules\zlib\zutil.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/pythonw.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/pythonw.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,101 @@ +# Microsoft Developer Studio Project File - Name="pythonw" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=pythonw - Win32 Alpha Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "pythonw.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "pythonw.mak" CFG="pythonw - Win32 Alpha Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "pythonw - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "pythonw - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "pythonw" +# PROP Scc_LocalPath "..\pc" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "pythonw - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\pythonw" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1d000000" /subsystem:windows /debug /machine:I386 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "pythonw - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\pythonw" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1d000000" /subsystem:windows /debug /machine:I386 /out:"./pythonw_d.exe" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "pythonw - Win32 Release" +# Name "pythonw - Win32 Debug" +# Begin Source File + +SOURCE=..\python_exe.rc +# End Source File +# Begin Source File + +SOURCE=..\WinMain.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/readme.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/readme.txt Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,192 @@ +Building Python using VC++ 6.0 or 5.0 +------------------------------------- +This directory is used to build Python for Win32 platforms, e.g. Windows +2000 and XP. It requires Microsoft Visual C++ 6.x or 5.x and Platform +SDK February 2003 Edition (Core SDK). +(For other Windows platforms and compilers, see ../readme.txt.) + +All you need to do is open the workspace "pcbuild.dsw" in MSVC++, select +the Debug or Release setting (using Build -> Set Active Configuration...), +and build the projects. + +The proper order to build subprojects: + +1) pythoncore (this builds the main Python DLL and library files, + python34.{dll, lib} in Release mode) + +2) python (this builds the main Python executable, + python.exe in Release mode) + +3) the other subprojects, as desired or needed (note: you probably don't + want to build most of the other subprojects, unless you're building an + entire Python distribution from scratch, or specifically making changes + to the subsystems they implement; see SUBPROJECTS below) + +When using the Debug setting, the output files have a _d added to +their name: python34_d.dll, python_d.exe, pyexpat_d.pyd, and so on. + +SUBPROJECTS +----------- +These subprojects should build out of the box. Subprojects other than the +main ones (pythoncore, python, pythonw) generally build a DLL (renamed to +.pyd) from a specific module so that users don't have to load the code +supporting that module unless they import the module. + +pythoncore + .dll and .lib +python + .exe +pythonw + pythonw.exe, a variant of python.exe that doesn't pop up a DOS box +_msi + _msi.c. You need to install Windows Installer SDK to build this module. +_socket + socketmodule.c +_testcapi + tests of the Python C API, run via Lib/test/test_capi.py, and + implemented by module Modules/_testcapimodule.c +pyexpat + Python wrapper for accelerated XML parsing, which incorporates stable + code from the Expat project: http://sourceforge.net/projects/expat/ +select + selectmodule.c +unicodedata + large tables of Unicode data +winsound + play sounds (typically .wav files) under Windows + +The following subprojects will generally NOT build out of the box. They +wrap code Python doesn't control, and you'll need to download the base +packages first and unpack them into siblings of PCbuilds's parent +directory; for example, if your PCbuild is .......\dist\src\PCbuild\, +unpack into new subdirectories of dist\. + +_tkinter + Python wrapper for the Tk windowing system. Requires building + Tcl/Tk first. Following are instructions for Tcl/Tk 8.5.2. + + Get source + ---------- + In the dist directory, run + svn export http://svn.python.org/projects/external/tcl-8.5.2.1 tcl8.5.2 + svn export http://svn.python.org/projects/external/tk-8.5.2.0 tk8.5.2 + svn export http://svn.python.org/projects/external/tix-8.4.3.1 tix8.4.3 + + Debug Build + ----------- + To build debug version, add DEBUG=1 to all nmake call bellow. + + Build Tcl first (done here w/ MSVC 6 on Win2K) + --------------- + If your environment doesn't have struct _stat64, you need to apply + tcl852.patch in this directory to dist\tcl8.5.2\generic\tcl.h. + + cd dist\tcl8.5.2\win + run vcvars32.bat + nmake -f makefile.vc + nmake -f makefile.vc INSTALLDIR=..\..\tcltk install + + XXX Should we compile with OPTS=threads? + + Optional: run tests, via + nmake -f makefile.vc test + + all.tcl: Total 24242 Passed 23358 Skipped 877 Failed 7 + Sourced 137 Test Files. + Files with failing tests: exec.test http.test io.test main.test string.test stri + ngObj.test + + Build Tk + -------- + cd dist\tk8.5.2\win + nmake -f makefile.vc TCLDIR=..\..\tcl8.5.2 + nmake -f makefile.vc TCLDIR=..\..\tcl8.5.2 INSTALLDIR=..\..\tcltk install + + XXX Should we compile with OPTS=threads? + + XXX I have no idea whether "nmake -f makefile.vc test" passed or + XXX failed. It popped up tons of little windows, and did lots of + XXX stuff, and nothing blew up. + + Build Tix + --------- + cd dist\tix8.4.3\win + nmake -f python.mak TCL_MAJOR=8 TCL_MINOR=5 TCL_PATCH=2 MACHINE=IX86 DEBUG=0 + nmake -f python.mak TCL_MAJOR=8 TCL_MINOR=5 TCL_PATCH=2 MACHINE=IX86 DEBUG=0 INSTALL_DIR=..\..\tcltk install + +bz2 + Python wrapper for the libbz2 compression library. Homepage + http://www.bzip.org/ + Download the source from the python.org copy into the dist + directory: + + svn export http://svn.python.org/projects/external/bzip2-1.0.6 + + And requires building bz2 first. + + cd dist\bzip2-1.0.6 + nmake -f makefile.msc + + All of this managed to build bzip2-1.0.6\libbz2.lib, which the Python + project links in. + + +_sqlite3 + Python wrapper for SQLite library. + + Get the source code through + + svn export http://svn.python.org/projects/external/sqlite-source-3.3.4 + + To use the extension module in a Python build tree, copy sqlite3.dll into + the PC/VC6 folder. + + +_ssl + Python wrapper for the secure sockets library. + + Get the latest source code for OpenSSL from + http://www.openssl.org + + You (probably) don't want the "engine" code. For example, don't get + openssl-engine-0.9.6g.tar.gz + + Unpack into the "dist" directory, retaining the folder name from + the archive - for example, the latest stable OpenSSL will install as + dist/openssl-1.0.1c + + You need to use version 1.0.1c of OpenSSL. + + You can install the NASM assembler from + http://www.nasm.us/ + for x86 builds. Put nasmw.exe anywhere in your PATH. + Note: recent releases of nasm only have nasm.exe. Just rename it to + nasmw.exe. + + You can also install ActivePerl from + http://www.activestate.com/activeperl/ + if you like to use the official sources instead of the files from + python's subversion repository. The svn version contains pre-build + makefiles and assembly files. + + The MSVC project simply invokes PC/VC6/build_ssl.py to perform + the build. This Python script locates and builds your OpenSSL + installation, then invokes a simple makefile to build the final .pyd. + + build_ssl.py attempts to catch the most common errors (such as not + being able to find OpenSSL sources, or not being able to find a Perl + that works with OpenSSL) and give a reasonable error message. + If you have a problem that doesn't seem to be handled correctly + (eg, you know you have ActivePerl but we can't find it), please take + a peek at build_ssl.py and suggest patches. Note that build_ssl.py + should be able to be run directly from the command-line. + + build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do + this by hand. + + +YOUR OWN EXTENSION DLLs +----------------------- +If you want to create your own extension module DLL, there's an example +with easy-to-follow instructions in ../PC/example/; read the file +readme.txt there first. diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/rmpyc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/rmpyc.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,25 @@ +# Remove all the .pyc and .pyo files under ../Lib. + + +def deltree(root): + import os + from os.path import join + + npyc = npyo = 0 + for root, dirs, files in os.walk(root): + for name in files: + delete = False + if name.endswith('.pyc'): + delete = True + npyc += 1 + elif name.endswith('.pyo'): + delete = True + npyo += 1 + + if delete: + os.remove(join(root, name)) + + return npyc, npyo + +npyc, npyo = deltree("../../Lib") +print npyc, ".pyc deleted,", npyo, ".pyo deleted" diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/rt.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/rt.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,41 @@ +@rem Run Tests. Run the regression test suite. +@rem Usage: rt [-d] [-O] [-q] regrtest_args +@rem -d Run Debug build (python_d.exe). Else release build. +@rem -O Run python.exe or python_d.exe (see -d) with -O. +@rem -q "quick" -- normally the tests are run twice, the first time +@rem after deleting all the .py[co] files reachable from Lib/. +@rem -q runs the tests just once, and without deleting .py[co] files. +@rem All leading instances of these switches are shifted off, and +@rem whatever remains is passed to regrtest.py. For example, +@rem rt -O -d -x test_thread +@rem runs +@rem python_d -O ../../lib/test/regrtest.py -x test_thread +@rem twice, and +@rem rt -q -g test_binascii +@rem runs +@rem python_d ../../lib/test/regrtest.py -g test_binascii +@rem to generate the expected-output file for binascii quickly. +@set _exe=python +@set _qmode=no +@set _dashO= +@goto CheckOpts +:Again +@shift +:CheckOpts +@if "%1"=="-O" set _dashO=-O +@if "%1"=="-O" goto Again +@if "%1"=="-q" set _qmode=yes +@if "%1"=="-q" goto Again +@if "%1"=="-d" set _exe=python_d +@if "%1"=="-d" goto Again +@if "%_qmode%"=="yes" goto Qmode +@echo Deleting .pyc/.pyo files ... +@%_exe% rmpyc.py +%_exe% %_dashO% -E ../../lib/test/regrtest.py %1 %2 %3 %4 %5 %6 %7 %8 %9 +@echo About to run again without deleting .pyc/.pyo first: +@pause +:Qmode +%_exe% %_dashO% -E ../../lib/test/regrtest.py %1 %2 %3 %4 %5 %6 %7 %8 %9 +@set _exe= +@set _qmode= +@set _dashO= diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/select.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/select.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="select" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=select - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "select.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "select.mak" CFG="select - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "select - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "select - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "select" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "select - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\select" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /base:"0x1D110000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./select.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "select - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\select" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /base:"0x1D110000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"msvcrt" /out:"./select_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "select - Win32 Release" +# Name "select - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\selectmodule.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/tcl852.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/tcl852.patch Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,11 @@ +--- tcl8.5.2\generic\tcl.h Fri Jun 13 03:35:39 2008 ++++ tcl8.5.2\generic\tcl.h Sun Jan 4 16:52:30 2009 +@@ -367,7 +367,7 @@ + typedef struct stati64 Tcl_StatBuf; + # define TCL_LL_MODIFIER "L" + # else /* __BORLANDC__ */ +-# if _MSC_VER < 1400 && !defined(_M_IX86) ++# if _MSC_VER < 1400 /*&& !defined(_M_IX86)*/ + typedef struct _stati64 Tcl_StatBuf; + # else + typedef struct _stat64 Tcl_StatBuf; diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/unicodedata.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/unicodedata.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="unicodedata" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=unicodedata - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "unicodedata.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "unicodedata.mak" CFG="unicodedata - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "unicodedata - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "unicodedata - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "unicodedata" +# PROP Scc_LocalPath ".." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "unicodedata - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\unicodedata" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "NDEBUG" +# ADD RSC /l 0xc09 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1D120000" /dll /machine:I386 /out:"./unicodedata.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "unicodedata - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\unicodedata" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMAP_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "_DEBUG" +# ADD RSC /l 0xc09 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1D120000" /dll /debug /machine:I386 /out:"./unicodedata_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "unicodedata - Win32 Release" +# Name "unicodedata - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Modules\unicodedata.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VC6/winsound.dsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VC6/winsound.dsp Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="winsound" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=winsound - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "winsound.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "winsound.mak" CFG="winsound - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "winsound - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "winsound - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "winsound" +# PROP Scc_LocalPath "..\pc" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "winsound - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-release\winsound" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "NDEBUG" +# ADD RSC /l 0xc09 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib winmm.lib user32.lib /nologo /base:"0x1D160000" /dll /machine:I386 /out:"./winsound.pyd" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "winsound - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "x86-temp-debug\winsound" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +F90=df.exe +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WINSOUND_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "_DEBUG" +# ADD RSC /l 0xc09 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib kernel32.lib winmm.lib /nologo /base:"0x1D160000" /dll /debug /machine:I386 /out:"./winsound_d.pyd" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "winsound - Win32 Release" +# Name "winsound - Win32 Debug" +# Begin Source File + +SOURCE=..\winsound.c +# End Source File +# End Target +# End Project diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/Uninstal.wse --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/Uninstal.wse Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,514 @@ +Document Type: WSE +item: Global + Version=8.14 + Flags=00000100 + Split=1420 + Languages=65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=10 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00000000000000000000101000001000 + Message Font=MS Sans Serif + Font Size=8 + Disk Label=GLBS + Disk Filename=INSTALL + Patch Flags=0000000000000001 + Patch Threshold=200 + Patch Memory=4096 + Per-User Version ID=1 + Crystal Format=10111100101100000010001001001001 + Step View=&Properties +end +item: Remark + Text=Note from Tim: This is a verbatim copy of Wise's Uninstal.wse, altered at the end to write +end +item: Remark + Text=uninstall info under HKCU instead of HKLM if our DOADMIN var is false. +end +item: Remark +end +item: Remark + Text= Install Support for uninstalling the application. +end +item: Remark +end +item: Set Variable + Variable=UNINSTALL_PATH + Value=%_LOGFILE_PATH_% + Flags=00000010 +end +item: Set Variable + Variable=UNINSTALL_PATH + Value=%UNINSTALL_PATH%\UNWISE.EXE +end +item: Compiler Variable If + Variable=_EXE_OS_TYPE_ + Value=WIN32 +end +item: Install File + Source=%_WISE_%\UNWISE32.EXE + Destination=%UNINSTALL_PATH% + Flags=0000000000000010 +end +item: Compiler Variable Else +end +item: Install File + Source=%_WISE_%\UNWISE.EXE + Destination=%UNINSTALL_PATH% + Flags=0000000000000010 +end +item: Compiler Variable End +end +item: Remark +end +item: Remark + Text= Install Support for multiple languages +end +item: Remark +end +item: Set Variable + Variable=UNINSTALL_LANG + Value=%UNINSTALL_PATH% + Flags=00000010 +end +item: Set Variable + Variable=UNINSTALL_LANG + Value=%UNINSTALL_LANG%\UNWISE.INI +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=C + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.FRA + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_C_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.FRA + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=D + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.FRA + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_D_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.FRA + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=E + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.DEU + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_E_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.DEU + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=F + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.PTG + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_F_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.PTG + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=G + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.ESP + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_G_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.ESP + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=H + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.ESP + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_H_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.ESP + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=I + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.ITA + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_I_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.ITA + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=J + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.DAN + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_J_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.DAN + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=K + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.FIN + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_K_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.FIN + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=L + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.ISL + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_L_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.ISL + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=M + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.NLD + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_M_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.NLD + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=N + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.NOR + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_N_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.NOR + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=O + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.SVE + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_O_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.SVE + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Compiler Variable If + Variable=_LANG_LIST_ + Value=P + Flags=00000010 +end +item: Compiler Variable If + Value=%_WISE_%\LANGUAGE\UNWISE.JPN + Flags=00000011 +end +item: If/While Statement + Variable=LANG + Value=%_LANG_P_NAME_% +end +item: Install File + Source=%_WISE_%\LANGUAGE\UNWISE.JPN + Destination=%UNINSTALL_LANG% + Flags=0000000000000010 +end +item: End Block +end +item: Compiler Variable End +end +item: Compiler Variable End +end +item: Remark +end +item: Remark + Text= Install the add/remove or uninstall icon +end +item: Remark +end +item: Set Variable + Variable=UNINSTALL_PATH + Value=%UNINSTALL_PATH% + Flags=00010100 +end +item: Set Variable + Variable=INST_LOG_PATH + Value=%_LOGFILE_PATH_% + Flags=00010100 +end +item: Check Configuration + Flags=10111011 +end +item: If/While Statement + Variable=DOADMIN + Value=1 +end +item: Remark + Text=Write uninstall info under HKLM. This if/else/end block added by Tim. +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%APPTITLE% + Value Name=DisplayName + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%UNINSTALL_PATH% %INST_LOG_PATH% + New Value= + Value Name=UninstallString + Root=2 +end +item: Else Statement +end +item: Remark + Text=The same, but write under HKCU instead. +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%APPTITLE% + Value Name=DisplayName + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%UNINSTALL_PATH% %INST_LOG_PATH% + New Value= + Value Name=UninstallString + Root=1 +end +item: End Block +end +item: Else Statement +end +item: Add ProgMan Icon + Group=%GROUP% + Icon Name=Uninstall %APPTITLE% + Command Line=%UNINSTALL_PATH% %INST_LOG_PATH% +end +item: End Block +end +item: Check Configuration + Flags=11110010 +end +item: If/While Statement + Variable=DOBRAND + Value=1 +end +item: Edit Registry + Total Keys=2 + item: Key + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%COMPANY% + Value Name=RegCompany + Root=2 + end + item: Key + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%NAME% + Value Name=RegOwner + Root=2 + end +end +item: End Block +end +item: End Block +end diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_ctypes.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_ctypes.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_ctypes_test.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_ctypes_test.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_elementtree.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_elementtree.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_msi.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_msi.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_socket.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_socket.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_sqlite3.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_sqlite3.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_ssl.mak --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_ssl.mak Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,38 @@ +EXTRA_LIBS= + +!IFDEF DEBUG +SUFFIX=_d.pyd +TEMP=x86-temp-debug/ +CFLAGS=/Od /Zi /MDd /LDd /DDEBUG /D_DEBUG /DWIN32 +SSL_LIB_DIR=$(SSL_DIR)/out32.dbg +!ELSE +SUFFIX=.pyd +TEMP=x86-temp-release/ +CFLAGS=/Ox /MD /LD /DWIN32 +SSL_LIB_DIR=$(SSL_DIR)/out32 +!ENDIF + +INCLUDES=-I ../../Include -I ../../PC -I $(SSL_DIR)/inc32 + +SSL_LIBS=gdi32.lib wsock32.lib user32.lib advapi32.lib /LIBPATH:$(SSL_LIB_DIR) libeay32.lib ssleay32.lib +SSL_SOURCE=../../Modules/_ssl.c + +HASH_LIBS=gdi32.lib user32.lib advapi32.lib /libpath:$(SSL_LIB_DIR) libeay32.lib +HASH_SOURCE=../../Modules/_hashopenssl.c + +all: _ssl$(SUFFIX) _hashlib$(SUFFIX) + +# Split compile/link into two steps to better support VSExtComp +_ssl$(SUFFIX): $(SSL_SOURCE) $(SSL_LIB_DIR)/libeay32.lib $(SSL_LIB_DIR)/ssleay32.lib ../../PC/*.h ../../Include/*.h + @if not exist "$(TEMP)/_ssl/." mkdir "$(TEMP)/_ssl" + cl /nologo /c $(SSL_SOURCE) $(CFLAGS) /Fo$(TEMP)\_ssl\$*.obj $(INCLUDES) + link /nologo @<< + /dll /out:_ssl$(SUFFIX) $(TEMP)\_ssl\$*.obj $(SSL_LIBS) $(EXTRA_LIBS) +<< + +_hashlib$(SUFFIX): $(HASH_SOURCE) $(SSL_LIB_DIR)/libeay32.lib ../../PC/*.h ../../Include/*.h + @if not exist "$(TEMP)/_hashlib/." mkdir "$(TEMP)/_hashlib" + cl /nologo /c $(HASH_SOURCE) $(CFLAGS) $(EXTRA_CFLAGS) /Fo$(TEMP)\_hashlib\$*.obj $(INCLUDES) + link /nologo @<< + /dll /out:_hashlib$(SUFFIX) $(HASH_LIBS) $(EXTRA_LIBS) $(TEMP)\_hashlib\$*.obj +<< diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_ssl.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_ssl.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_testcapi.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_testcapi.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/_tkinter.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/_tkinter.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,261 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/amd64_ml64.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/amd64_ml64.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,17 @@ +@echo off +rem Try to find the AMD64 assembler and call it with the supplied arguments. + +set MLEXE=Microsoft Platform SDK\Bin\Win64\x86\AMD64\ml64.EXE + +rem For the environment variables see also +rem http://msdn.microsoft.com/library/en-us/win64/win64/wow64_implementation_details.asp + +if exist "%ProgramFiles%\%MLEXE%" ( + set ML64="%ProgramFiles%\%MLEXE%" +) else if exist "%ProgramW6432%\%MLEXE%" ( + set ML64="%ProgramW6432%\%MLEXE%" +) else ( + set ML64=ml64.exe +) + +%ML64% %* diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/build_ssl.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/build_ssl.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,12 @@ +if "%1" == "ReleaseAMD64" call "%MSSdk%\SetEnv" /XP64 /RETAIL + +@echo off +if not defined HOST_PYTHON ( + if %1 EQU Debug ( + set HOST_PYTHON=python_d.exe + ) ELSE ( + set HOST_PYTHON=python.exe + ) +) +%HOST_PYTHON% build_ssl.py %1 %2 + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/build_ssl.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/build_ssl.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,181 @@ +# Script for building the _ssl and _hashlib modules for Windows. +# Uses Perl to setup the OpenSSL environment correctly +# and build OpenSSL, then invokes a simple nmake session +# for the actual _ssl.pyd and _hashlib.pyd DLLs. + +# THEORETICALLY, you can: +# * Unpack the latest SSL release one level above your main Python source +# directory. It is likely you will already find the zlib library and +# any other external packages there. +# * Install ActivePerl and ensure it is somewhere on your path. +# * Run this script from the PCBuild directory. +# +# it should configure and build SSL, then build the _ssl and _hashlib +# Python extensions without intervention. + +import os, sys, re + +# 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: + fh = os.popen(perl + ' -e "use Win32;"') + fh.read() + rc = fh.close() + if rc: + continue + return perl + print "Can not find a suitable 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" + print "The Python SSL module was not built" + return None + +# Locate the best SSL directory given a few roots to look into. +def find_best_ssl_dir(sources): + candidates = [] + for s in sources: + try: + # note: do not abspath s; the build will fail if any + # higher up directory name has spaces in it. + fnames = os.listdir(s) + except OSError: + fnames = [] + for fname in fnames: + fqn = os.path.join(s, fname) + if os.path.isdir(fqn) and fname.startswith("openssl-"): + candidates.append(fqn) + # Now we have all the candidates, locate the best. + best_parts = [] + best_name = None + for c in candidates: + parts = re.split("[.-]", os.path.basename(c))[1:] + # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers + if len(parts) >= 4: + continue + if parts > best_parts: + best_parts = parts + best_name = c + if best_name is not None: + print "Found an SSL directory at '%s'" % (best_name,) + else: + print "Could not find an SSL directory in '%s'" % (sources,) + sys.stdout.flush() + return best_name + +def run_configure(configure, do_script): + os.system("perl Configure "+configure) + os.system(do_script) + +def main(): + build_all = "-a" in sys.argv + if sys.argv[1] == "Release": + arch = "x86" + debug = False + configure = "VC-WIN32" + do_script = "ms\\do_masm" + makefile = "ms\\nt.mak" + elif sys.argv[1] == "Debug": + arch = "x86" + debug = True + configure = "VC-WIN32" + do_script = "ms\\do_masm" + makefile="ms\\d32.mak" + elif sys.argv[1] == "ReleaseItanium": + arch = "ia64" + debug = False + configure = "VC-WIN64I" + do_script = "ms\\do_win64i" + makefile = "ms\\nt.mak" + os.environ["VSEXTCOMP_USECL"] = "MS_ITANIUM" + elif sys.argv[1] == "ReleaseAMD64": + arch="amd64" + debug=False + configure = "VC-WIN64A" + do_script = "ms\\do_win64a" + makefile = "ms\\nt.mak" + os.environ["VSEXTCOMP_USECL"] = "MS_OPTERON" + make_flags = "" + if build_all: + make_flags = "-a" + # 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", ["\\perl\\bin", "C:\\perl\\bin"]) + perl = find_working_perl(perls) + if perl is None: + sys.exit(1) + + print "Found a working perl at '%s'" % (perl,) + sys.stdout.flush() + # Look for SSL 2 levels up from pcbuild - ie, same place zlib etc all live. + ssl_dir = find_best_ssl_dir(("..\\..\\..",)) + if ssl_dir is None: + sys.exit(1) + + old_cd = os.getcwd() + try: + os.chdir(ssl_dir) + # If the ssl makefiles do not exist, we invoke Perl to generate them. + # Due to a bug in this script, the makefile sometimes ended up empty + # Force a regeneration if it is. + if not os.path.isfile(makefile) or os.path.getsize(makefile)==0: + print "Creating the makefiles..." + 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"] + run_configure(configure, do_script) + if arch=="x86" and debug: + # the do_masm script in openssl doesn't generate a debug + # build makefile so we generate it here: + os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile) + + # Now run make. + makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile) + print "Executing ssl makefiles:", makeCommand + sys.stdout.flush() + rc = os.system(makeCommand) + if rc: + print "Executing "+makefile+" failed" + print rc + sys.exit(rc) + finally: + os.chdir(old_cd) + # And finally, we can build the _ssl module itself for Python. + defs = "SSL_DIR=\"%s\"" % (ssl_dir,) + if debug: + defs = defs + " " + "DEBUG=1" + if arch in ('amd64', 'ia64'): + defs = defs + " EXTRA_CFLAGS=/GS- EXTRA_LIBS=bufferoverflowU.lib" + makeCommand = 'nmake /nologo -f _ssl.mak ' + defs + " " + make_flags + print "Executing:", makeCommand + sys.stdout.flush() + rc = os.system(makeCommand) + sys.exit(rc) + +if __name__=='__main__': + main() diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/bz2.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/bz2.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/db.build --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/db.build Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,10 @@ + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/field3.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/field3.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,35 @@ +# An absurd workaround for the lack of arithmetic in MS's resource compiler. +# After building Python, run this, then paste the output into the appropriate +# part of PC\python_nt.rc. +# Example output: +# +# * For 2.3a0, +# * PY_MICRO_VERSION = 0 +# * PY_RELEASE_LEVEL = 'alpha' = 0xA +# * PY_RELEASE_SERIAL = 1 +# * +# * and 0*1000 + 10*10 + 1 = 101. +# */ +# #define FIELD3 101 + +import sys + +major, minor, micro, level, serial = sys.version_info +levelnum = {'alpha': 0xA, + 'beta': 0xB, + 'candidate': 0xC, + 'final': 0xF, + }[level] +string = sys.version.split()[0] # like '2.3a0' + +print " * For %s," % string +print " * PY_MICRO_VERSION = %d" % micro +print " * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum)) +print " * PY_RELEASE_SERIAL = %d" % serial +print " *" + +field3 = micro * 1000 + levelnum * 10 + serial + +print " * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3) +print " */" +print "#define FIELD3", field3 diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/installer.bmp Binary file PC/VS7.1/installer.bmp has changed diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/make_buildinfo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/make_buildinfo.c Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +/* This file creates the getbuildinfo.o object, by first + invoking subwcrev.exe (if found), and then invoking cl.exe. + As a side effect, it might generate PC\VS7.1\getbuildinfo2.c + also. If this isn't a subversion checkout, or subwcrev isn't + found, it compiles ..\\..\\Modules\\getbuildinfo.c instead. + + Currently, subwcrev.exe is found from the registry entries + of TortoiseSVN. + + No attempt is made to place getbuildinfo.o into the proper + binary directory. This isn't necessary, as this tool is + invoked as a pre-link step for pythoncore, so that overwrites + any previous getbuildinfo.o. + +*/ + +int make_buildinfo2() +{ + struct _stat st; + HKEY hTortoise; + char command[500]; + DWORD type, size; + if (_stat(".svn", &st) < 0) + return 0; + /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */ + if (_stat("no_subwcrev", &st) == 0) + return 0; + if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS && + RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS) + /* Tortoise not installed */ + return 0; + command[0] = '"'; /* quote the path to the executable */ + size = sizeof(command) - 1; + if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS || + type != REG_SZ) + /* Registry corrupted */ + return 0; + strcat(command, "bin\\subwcrev.exe"); + if (_stat(command+1, &st) < 0) + /* subwcrev.exe not part of the release */ + return 0; + strcat(command, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c getbuildinfo2.c"); + puts(command); fflush(stdout); + if (system(command) < 0) + return 0; + return 1; +} + +int main(int argc, char*argv[]) +{ + char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL "; + int do_unlink, result; + if (argc != 2) { + fprintf(stderr, "make_buildinfo $(ConfigurationName)\n"); + return EXIT_FAILURE; + } + if (strcmp(argv[1], "Release") == 0) { + strcat(command, "-MD "); + } + else if (strcmp(argv[1], "Debug") == 0) { + strcat(command, "-D_DEBUG -MDd "); + } + else if (strcmp(argv[1], "ReleaseItanium") == 0) { + strcat(command, "-MD /USECL:MS_ITANIUM "); + } + else if (strcmp(argv[1], "ReleaseAMD64") == 0) { + strcat(command, "-MD "); + strcat(command, "-MD /USECL:MS_OPTERON "); + } + else { + fprintf(stderr, "unsupported configuration %s\n", argv[1]); + return EXIT_FAILURE; + } + + if ((do_unlink = make_buildinfo2())) + strcat(command, "getbuildinfo2.c -DSUBWCREV "); + else + strcat(command, "..\\..\\Modules\\getbuildinfo.c"); + strcat(command, " -Fogetbuildinfo.o -I..\\..\\Include -I..\\..\\PC"); + puts(command); fflush(stdout); + result = system(command); + if (do_unlink) + unlink("getbuildinfo2.c"); + if (result < 0) + return EXIT_FAILURE; + return 0; +} diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/make_buildinfo.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/make_buildinfo.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/make_versioninfo.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/make_versioninfo.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/pcbuild.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/pcbuild.sln Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,271 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_socket", "_socket.vcproj", "{324F66C2-44D0-4D50-B979-F9DAE7FD36DB}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ssl", "_ssl.vcproj", "{8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}" + ProjectSection(ProjectDependencies) = postProject + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} = {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058} = {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testcapi", "_testcapi.vcproj", "{59CBF474-9E06-4C50-9142-C44A118BB447}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_tkinter", "_tkinter.vcproj", "{5B51DFF7-5DC0-41F8-8791-A4AB7114A151}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bz2", "bz2.vcproj", "{AC557788-6354-43F7-BE05-C9C8C59A344A}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_versioninfo", "make_versioninfo.vcproj", "{F0E0541E-F17D-430B-97C4-93ADF0DD284E}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pyexpat", "pyexpat.vcproj", "{7E551393-3C43-47F8-9F3F-5BC368A6C487}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "python", "python.vcproj", "{B11D750F-CD1F-4A96-85CE-E69A5C5259F9}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore", "pythoncore.vcproj", "{CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}" + ProjectSection(ProjectDependencies) = postProject + {F0E0541E-F17D-430B-97C4-93ADF0DD284E} = {F0E0541E-F17D-430B-97C4-93ADF0DD284E} + {C73F0EC1-358B-4177-940F-0846AC8B04CD} = {C73F0EC1-358B-4177-940F-0846AC8B04CD} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythonw", "pythonw.vcproj", "{F4229CC3-873C-49AE-9729-DD308ED4CD4A}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "select", "select.vcproj", "{97239A56-DBC0-41D2-BC14-C87D9B97D63B}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unicodedata", "unicodedata.vcproj", "{FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{51F35FAE-FB92-4B2C-9187-1542C065AD77}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_elementtree", "_elementtree.vcproj", "{1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_msi", "_msi.vcproj", "{2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes", "_ctypes.vcproj", "{F22F40F4-D318-40DC-96B3-88DC81CE0894}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes_test", "_ctypes_test.vcproj", "{8CF334D9-4F82-42EB-97AF-83592C5AFD2F}" + ProjectSection(ProjectDependencies) = postProject + {F22F40F4-D318-40DC-96B3-88DC81CE0894} = {F22F40F4-D318-40DC-96B3-88DC81CE0894} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sqlite3", "_sqlite3.vcproj", "{2FF0A312-22F9-4C34-B070-842916DE27A9}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + ReleaseAMD64 = ReleaseAMD64 + ReleaseItanium = ReleaseItanium + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.Debug.ActiveCfg = Debug|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.Debug.Build.0 = Debug|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.Release.ActiveCfg = Release|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.Release.Build.0 = Release|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {324F66C2-44D0-4D50-B979-F9DAE7FD36DB}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.Debug.ActiveCfg = Debug|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.Debug.Build.0 = Debug|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.Release.ActiveCfg = Release|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.Release.Build.0 = Release|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {8E85BA54-8A47-4C8B-B72E-8E17579CC6D7}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.Debug.ActiveCfg = Debug|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.Debug.Build.0 = Debug|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.Release.ActiveCfg = Release|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.Release.Build.0 = Release|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {59CBF474-9E06-4C50-9142-C44A118BB447}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.Debug.ActiveCfg = Debug|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.Debug.Build.0 = Debug|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.Release.ActiveCfg = Release|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.Release.Build.0 = Release|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {5B51DFF7-5DC0-41F8-8791-A4AB7114A151}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.Debug.ActiveCfg = Debug|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.Debug.Build.0 = Debug|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.Release.ActiveCfg = Release|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.Release.Build.0 = Release|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {AC557788-6354-43F7-BE05-C9C8C59A344A}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug.ActiveCfg = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug.Build.0 = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseAMD64.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseAMD64.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseItanium.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseItanium.Build.0 = Release|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.Debug.ActiveCfg = Debug|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.Debug.Build.0 = Debug|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.Release.ActiveCfg = Release|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.Release.Build.0 = Release|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {7E551393-3C43-47F8-9F3F-5BC368A6C487}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug.ActiveCfg = Debug|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug.Build.0 = Debug|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release.ActiveCfg = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release.Build.0 = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug.ActiveCfg = Debug|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug.Build.0 = Debug|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release.ActiveCfg = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release.Build.0 = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug.ActiveCfg = Debug|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug.Build.0 = Debug|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release.ActiveCfg = Release|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release.Build.0 = Release|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Debug.ActiveCfg = Debug|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Debug.Build.0 = Debug|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Release.ActiveCfg = Release|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Release.Build.0 = Release|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Debug.ActiveCfg = Debug|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Debug.Build.0 = Debug|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Release.ActiveCfg = Release|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Release.Build.0 = Release|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug.ActiveCfg = Debug|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug.Build.0 = Debug|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release.ActiveCfg = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release.Build.0 = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.ReleaseAMD64.ActiveCfg = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.ReleaseItanium.ActiveCfg = Release|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Debug.ActiveCfg = Debug|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Debug.Build.0 = Debug|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Release.ActiveCfg = Release|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Release.Build.0 = Release|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Debug.ActiveCfg = Debug|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Debug.Build.0 = Debug|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Release.ActiveCfg = Release|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Release.Build.0 = Release|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug.ActiveCfg = Debug|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug.Build.0 = Debug|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseAMD64.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseAMD64.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseItanium.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseItanium.Build.0 = Release|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Debug.ActiveCfg = Debug|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Debug.Build.0 = Debug|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Release.ActiveCfg = Release|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Release.Build.0 = Release|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Debug.ActiveCfg = Debug|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Debug.Build.0 = Debug|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release.ActiveCfg = Release|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release.Build.0 = Release|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug.ActiveCfg = Debug|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug.Build.0 = Debug|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release.ActiveCfg = Release|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release.Build.0 = Release|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug.ActiveCfg = Debug|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug.Build.0 = Debug|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Release.ActiveCfg = Release|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Release.Build.0 = Release|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseItanium.Build.0 = ReleaseItanium|Win32 + EndGlobalSection + GlobalSection(SolutionItems) = postSolution + ..\Modules\getbuildinfo.c = ..\Modules\getbuildinfo.c + readme.txt = readme.txt + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/pyexpat.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/pyexpat.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/python.build --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/python.build Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/python.iss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/python.iss Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,340 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +; This is the whole ball of wax for an Inno installer for Python. +; To use, download Inno Setup from http://www.jrsoftware.org/isdl.htm/, +; install it, and double-click on this file. That launches the Inno +; script compiler. The GUI is extemely simple, and has only one button +; you may not recognize instantly: click it. You're done. It builds +; the installer into PCBuild/Python-2.2a1.exe. Size and speed of the +; installer are competitive with the Wise installer; Inno uninstall +; seems much quicker than Wise (but also feebler, and the uninstall +; log is in some un(human)readable binary format). +; +; What's Done +; ----------- +; All the usual Windows Python files are installed by this now. +; All the usual Windows Python Start menu entries are created and +; work fine. +; .py, .pyw, .pyc and .pyo extensions are registered. +; PROBLEM: Inno uninstall does not restore their previous registry +; associations (if any). Wise did. This will make life +; difficult for alpha (etc) testers. +; The Python install is fully functional for "typical" uses. +; +; What's Not Done +; --------------- +; None of "Mark Hammond's" registry entries are written. +; No installation of files is done into the system dir: +; The MS DLLs aren't handled at all by this yet. +; Python22.dll is unpacked into the main Python dir. +; +; Inno can't do different things on NT/2000 depending on whether the user +; has Admin privileges, so I don't know how to "solve" either of those, +; short of building two installers (one *requiring* Admin privs, the +; other not doing anything that needs Admin privs). +; +; Inno has no concept of variables, so lots of lines in this file need +; to be fiddled by hand across releases. Simplest way out: stick this +; file in a giant triple-quoted r-string (note that backslashes are +; required all over the place here -- forward slashes DON'T WORK in +; Inno), and use %(yadda)s string interpolation to do substitutions; i.e., +; write a very simple Python program to *produce* this script. + +[Setup] +AppName=Python and combined Win32 Extensions +AppVerName=Python 2.2.2 and combined Win32 Extensions 150 +AppId=Python 2.2.2.150 +AppVersion=2.2.2.150 +AppCopyright=Python is Copyright © 2001 Python Software Foundation. Win32 Extensions are Copyright © 1996-2001 Greg Stein and Mark Hammond. + +; Default install dir; value of {app} later (unless user overrides). +; {sd} = system root drive, probably "C:". +DefaultDirName={sd}\Python22 +;DefaultDirName={pf}\Python + +; Start menu folder name; value of {group} later (unless user overrides). +DefaultGroupName=Python 2.2 + +; Point SourceDir to one above PCBuild = src. +; means this script can run unchanged from anyone's CVS tree, no matter +; what they called the top-level directories. +SourceDir=. +OutputDir=.. +OutputBaseFilename=Python-2.2.2-Win32-150-Setup + +AppPublisher=PythonLabs at Digital Creations +AppPublisherURL=http://www.python.org +AppSupportURL=http://www.python.org +AppUpdatesURL=http://www.python.org + +AlwaysCreateUninstallIcon=true +ChangesAssociations=true +UninstallLogMode=new +AllowNoIcons=true +AdminPrivilegesRequired=true +UninstallDisplayIcon={app}\pyc.ico +WizardDebug=false + +; The fewer screens the better; leave these commented. + +Compression=bzip +InfoBeforeFile=LICENSE.txt +;InfoBeforeFile=Misc\NEWS + +; uncomment the following line if you want your installation to run on NT 3.51 too. +; MinVersion=4,3.51 + +[Types] +Name: normal; Description: Select desired components; Flags: iscustom + +[Components] +Name: main; Description: Python and Win32 Extensions; Types: normal +Name: docs; Description: Python documentation (HTML); Types: normal +Name: tk; Description: TCL/TK, tkinter, and Idle; Types: normal +Name: tools; Description: Python utility scripts (Tools\); Types: normal +Name: test; Description: Python test suite (Lib\test\); Types: normal + +[Tasks] +Name: extensions; Description: Register file associations (.py, .pyw, .pyc, .pyo); Components: main; Check: IsAdminLoggedOn + +[Files] +; Caution: Using forward slashes instead screws up in amazing ways. +; Unknown: By the time Components (and other attrs) are added to these lines, they're +; going to get awfully long. But don't see a way to continue logical lines across +; physical lines. + +Source: LICENSE.txt; DestDir: {app}; CopyMode: alwaysoverwrite +Source: README.txt; DestDir: {app}; CopyMode: alwaysoverwrite +Source: News.txt; DestDir: {app}; CopyMode: alwaysoverwrite +Source: *.ico; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main + +Source: python.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main +Source: pythonw.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main + + +Source: DLLs\tcl83.dll; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: tk +Source: DLLs\tk83.dll; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: tk +Source: tcl\*.*; DestDir: {app}\tcl; CopyMode: alwaysoverwrite; Components: tk; Flags: recursesubdirs + +Source: sysdir\python22.dll; DestDir: {sys}; CopyMode: alwaysskipifsameorolder; Components: main; Flags: sharedfile restartreplace +Source: sysdir\PyWinTypes22.dll; DestDir: {sys}; CopyMode: alwaysskipifsameorolder; Components: main; Flags: restartreplace sharedfile +Source: sysdir\pythoncom22.dll; DestDir: {sys}; CopyMode: alwaysskipifsameorolder; Components: main; Flags: restartreplace sharedfile + +Source: DLLs\_socket.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\_socket.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\_sre.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\_sre.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\_symtable.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\_symtable.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\_testcapi.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\_testcapi.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\_tkinter.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: tk +Source: libs\_tkinter.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: tk + +Source: DLLs\mmap.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\mmap.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\parser.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\parser.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\pyexpat.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\pyexpat.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\select.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\select.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\unicodedata.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\unicodedata.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\winreg.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\winreg.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\winsound.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\winsound.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\zlib.pyd; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main +Source: libs\zlib.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: libs\python22.lib; DestDir: {app}\libs; CopyMode: alwaysoverwrite; Components: main + +Source: DLLs\expat.dll; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: main + + + +Source: Lib\*.py; DestDir: {app}\Lib; CopyMode: alwaysoverwrite; Components: main +Source: Lib\compiler\*.*; DestDir: {app}\Lib\compiler; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\distutils\*.*; DestDir: {app}\Lib\distutils; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\email\*.*; DestDir: {app}\Lib\email; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\encodings\*.*; DestDir: {app}\Lib\encodings; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\hotshot\*.*; DestDir: {app}\Lib\hotshot; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\lib-old\*.*; DestDir: {app}\Lib\lib-old; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\xml\*.*; DestDir: {app}\Lib\xml; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\hotshot\*.*; DestDir: {app}\Lib\hotshot; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\test\*.*; DestDir: {app}\Lib\test; CopyMode: alwaysoverwrite; Components: test; Flags: recursesubdirs +Source: Lib\tkinter\*.py; DestDir: {app}\Lib\tkinter; CopyMode: alwaysoverwrite; Components: tk; Flags: recursesubdirs + +Source: Lib\site-packages\README.txt; DestDir: {app}\Lib\site-packages; CopyMode: alwaysoverwrite; Components: main + +Source: Lib\site-packages\PyWin32.chm; DestDir: {app}\Lib\site-packages; CopyMode: alwaysoverwrite; Components: docs +Source: Lib\site-packages\win32\*.*; DestDir: {app}\Lib\site-packages\win32; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\site-packages\win32com\*.*; DestDir: {app}\Lib\site-packages\win32com; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs +Source: Lib\site-packages\win32comext\*.*; DestDir: {app}\Lib\site-packages\win32comext; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs + +Source: include\*.h; DestDir: {app}\include; CopyMode: alwaysoverwrite; Components: main + +Source: Tools\idle\*.*; DestDir: {app}\Tools\idle; CopyMode: alwaysoverwrite; Components: tk; Flags: recursesubdirs + +Source: Tools\pynche\*.*; DestDir: {app}\Tools\pynche; CopyMode: alwaysoverwrite; Components: tools; Flags: recursesubdirs +Source: Tools\scripts\*.*; DestDir: {app}\Tools\Scripts; CopyMode: alwaysoverwrite; Components: tools; Flags: recursesubdirs +Source: Tools\webchecker\*.*; DestDir: {app}\Tools\webchecker; CopyMode: alwaysoverwrite; Components: tools; Flags: recursesubdirs +Source: Tools\versioncheck\*.*; DestDir: {app}\Tools\versioncheck; CopyMode: alwaysoverwrite; Components: tools; Flags: recursesubdirs + +Source: Doc\*.*; DestDir: {app}\Doc; CopyMode: alwaysoverwrite; Flags: recursesubdirs; Components: docs + + +[Icons] +Name: {group}\Python (command line); Filename: {app}\python.exe; WorkingDir: {app}; Components: main +Name: {group}\Python Manuals; Filename: {app}\Doc\index.html; WorkingDir: {app}; Components: docs +Name: {group}\Win32 Extensions Help; Filename: {app}\Lib\site-packages\PyWin32.chm; WorkingDir: {app}\Lib\site-packages; Components: docs +Name: {group}\Module Docs; Filename: {app}\pythonw.exe; WorkingDir: {app}; Parameters: """{app}\Tools\Scripts\pydoc.pyw"""; Components: tools +Name: {group}\IDLE (Python GUI); Filename: {app}\pythonw.exe; WorkingDir: {app}; Parameters: """{app}\Tools\idle\idle.pyw"""; Components: tools + +[Registry] +; Register .py +Tasks: extensions; Root: HKCR; Subkey: .py; ValueType: string; ValueName: ; ValueData: Python File; Flags: uninsdeletevalue +Tasks: extensions; Root: HKCR; Subkey: .py; ValueType: string; ValueName: Content Type; ValueData: text/plain; Flags: uninsdeletevalue +Tasks: extensions; Root: HKCR; Subkey: Python File; ValueType: string; ValueName: ; ValueData: Python File; Flags: uninsdeletekey +Tasks: extensions; Root: HKCR; Subkey: Python File\DefaultIcon; ValueType: string; ValueName: ; ValueData: {app}\Py.ico +Tasks: extensions; Root: HKCR; Subkey: Python File\shell\open\command; ValueType: string; ValueName: ; ValueData: """{app}\python.exe"" ""%1"" %*" + +; Register .pyc +Tasks: extensions; Root: HKCR; Subkey: .pyc; ValueType: string; ValueName: ; ValueData: Python CompiledFile; Flags: uninsdeletevalue +Tasks: extensions; Root: HKCR; Subkey: Python CompiledFile; ValueType: string; ValueName: ; ValueData: Compiled Python File; Flags: uninsdeletekey +Tasks: extensions; Root: HKCR; Subkey: Python CompiledFile\DefaultIcon; ValueType: string; ValueName: ; ValueData: {app}\pyc.ico +Tasks: extensions; Root: HKCR; Subkey: Python CompiledFile\shell\open\command; ValueType: string; ValueName: ; ValueData: """{app}\python.exe"" ""%1"" %*" + +; Register .pyo +Tasks: extensions; Root: HKCR; Subkey: .pyo; ValueType: string; ValueName: ; ValueData: Python CompiledFile; Flags: uninsdeletevalue + +; Register .pyw +Tasks: extensions; Root: HKCR; Subkey: .pyw; ValueType: string; ValueName: ; ValueData: Python NoConFile; Flags: uninsdeletevalue +Tasks: extensions; Root: HKCR; Subkey: .pyw; ValueType: string; ValueName: Content Type; ValueData: text/plain; Flags: uninsdeletevalue +Tasks: extensions; Root: HKCR; Subkey: Python NoConFile; ValueType: string; ValueName: ; ValueData: Python File (no console); Flags: uninsdeletekey +Tasks: extensions; Root: HKCR; Subkey: Python NoConFile\DefaultIcon; ValueType: string; ValueName: ; ValueData: {app}\Py.ico +Tasks: extensions; Root: HKCR; Subkey: Python NoConFile\shell\open\command; ValueType: string; ValueName: ; ValueData: """{app}\pythonw.exe"" ""%1"" %*" + + +; Python Registry Keys +Root: HKLM; Subkey: SOFTWARE\Python; Flags: uninsdeletekeyifempty; Check: IsAdminLoggedOn +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore; Flags: uninsdeletekeyifempty +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2; Flags: uninsdeletekeyifempty +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\PythonPath; ValueData: "{app}\Lib;{app}\DLLs"; Flags: uninsdeletekeyifempty +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\PythonPath\win32; ValueData: "{app}\lib\site-packages\win32;{app}\lib\site-packages\win32\lib"; Flags: uninsdeletekey +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\PythonPath\win32com; ValueData: C:\Python\lib\site-packages; Flags: uninsdeletekey +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\Modules; Flags: uninsdeletekeyifempty +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\Modules\pythoncom; ValueData: {sys}\pythoncom22.dll; Flags: uninsdeletekey +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\Modules\pywintypes; ValueData: {sys}\PyWinTypes22.dll; Flags: uninsdeletekey +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\InstallPath; ValueData: {app}; Flags: uninsdeletekeyifempty; ValueType: string +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\InstallPath\InstallGroup; ValueData: {group}; Flags: uninsdeletekey +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\Help; Flags: uninsdeletekeyifempty +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\Help\Main Python Documentation; ValueType: string; ValueData: {app}\Doc\index.html; Flags: uninsdeletekey; Components: docs +Root: HKLM; Subkey: SOFTWARE\Python\PythonCore\2.2\Help\Python Win32 Documentation; ValueType: string; ValueData: {app}\lib\site-packages\PyWin32.chm; Flags: uninsdeletekey; Components: docs + +[_ISTool] +EnableISX=true + + +[Code] +Program Setup; + +Function IsAdminNotLoggedOn(): Boolean; +begin + Result := Not IsAdminLoggedOn(); +end; + +begin +end. + + + + +[UninstallDelete] +Name: {app}\Lib\compiler\*.pyc; Type: files +Name: {app}\Lib\compiler\*.pyo; Type: files +Name: {app}\Lib\compiler; Type: dirifempty +Name: {app}\Lib\distutils\command\*.pyc; Type: files +Name: {app}\Lib\distutils\command\*.pyo; Type: files +Name: {app}\Lib\distutils\command; Type: dirifempty +Name: {app}\Lib\distutils\*.pyc; Type: files +Name: {app}\Lib\distutils\*.pyo; Type: files +Name: {app}\Lib\distutils; Type: dirifempty +Name: {app}\Lib\email\test\*.pyc; Type: files +Name: {app}\Lib\email\test\*.pyo; Type: files +Name: {app}\Lib\email\test; Type: dirifempty +Name: {app}\Lib\email\*.pyc; Type: files +Name: {app}\Lib\email\*.pyo; Type: files +Name: {app}\Lib\email; Type: dirifempty +Name: {app}\Lib\encodings\*.pyc; Type: files +Name: {app}\Lib\encodings\*.pyo; Type: files +Name: {app}\Lib\encodings; Type: dirifempty +Name: {app}\Lib\hotshot\*.pyc; Type: files +Name: {app}\Lib\hotshot\*.pyo; Type: files +Name: {app}\Lib\hotshot; Type: dirifempty +Name: {app}\Lib\lib-old\*.pyc; Type: files +Name: {app}\Lib\lib-old\*.pyo; Type: files +Name: {app}\Lib\lib-old; Type: dirifempty +Name: {app}\Lib\tkinter\*.pyc; Type: files +Name: {app}\Lib\tkinter\*.pyo; Type: files +Name: {app}\Lib\tkinter; Type: dirifempty +Name: {app}\Lib\test\*.pyc; Type: files +Name: {app}\Lib\test\*.pyo; Type: files +Name: {app}\Lib\test; Type: dirifempty +Name: {app}\Lib\xml\dom\*.pyc; Type: files +Name: {app}\Lib\xml\dom\*.pyo; Type: files +Name: {app}\Lib\xml\dom; Type: dirifempty +Name: {app}\Lib\xml\parsers\*.pyc; Type: files +Name: {app}\Lib\xml\parsers\*.pyo; Type: files +Name: {app}\Lib\xml\parsers; Type: dirifempty +Name: {app}\Lib\xml\sax\*.pyc; Type: files +Name: {app}\Lib\xml\sax\*.pyo; Type: files +Name: {app}\Lib\xml\sax; Type: dirifempty +Name: {app}\Lib\xml\*.pyc; Type: files +Name: {app}\Lib\xml\*.pyo; Type: files +Name: {app}\Lib\xml; Type: dirifempty + +Name: {app}\Lib\site-packages\win32; Type: filesandordirs +Name: {app}\Lib\site-packages\win32com; Type: filesandordirs +Name: {app}\Lib\site-packages\win32comext; Type: filesandordirs +Name: {app}\Lib\site-packages\pythoncom.py*; Type: files +Name: {app}\Lib\site-packages; Type: dirifempty + +Name: {app}\Lib\*.pyc; Type: files +Name: {app}\Lib; Type: dirifempty + +Name: {app}\Tools\pynche\*.pyc; Type: files +Name: {app}\Tools\pynche\*.pyo; Type: files +Name: {app}\Tools\pynche; Type: dirifempty + +Name: {app}\Tools\idle\*.pyc; Type: files +Name: {app}\Tools\idle\*.pyo; Type: files +Name: {app}\Tools\idle; Type: dirifempty + +Name: {app}\Tools\scripts\*.pyc; Type: files +Name: {app}\Tools\scripts\*.pyo; Type: files +Name: {app}\Tools\scripts; Type: dirifempty + +Name: {app}\Tools\versioncheck\*.pyc; Type: files +Name: {app}\Tools\versioncheck\*.pyo; Type: files +Name: {app}\Tools\versioncheck; Type: dirifempty + +Name: {app}\Tools\webchecker\*.pyc; Type: files +Name: {app}\Tools\webchecker\*.pyo; Type: files +Name: {app}\Tools\webchecker; Type: dirifempty + +Name: {app}\Tools; Type: dirifempty + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/python.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/python.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,274 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/python20.wse --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/python20.wse Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,3112 @@ +Document Type: WSE +item: Global + Version=9.0 + Title=Python 2.4a1 + Flags=00010100 + Languages=65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + Japanese Font Name=MS Gothic + Japanese Font Size=10 + Start Gradient=0 255 0 + End Gradient=0 128 0 + Windows Flags=00000100000011010010010100001010 + Log Pathname=%MAINDIR%\INSTALL.LOG + Message Font=MS Sans Serif + Font Size=8 + Pages Modified=00010000011101000000000100000111 + Extra Pages=00000000000000000000000010110010 + Disk Filename=SETUP + Patch Flags=0000000000001001 + Patch Threshold=85 + Patch Memory=4000 + MIF PDF Version=1.0 + MIF SMS Version=2.0 + EXE Filename=Python-2.4a1.exe + Dialogs Version=8 + Version File=2.4a1 + Version Description=Python Programming Language + Version Copyright=©2001-2007 Python Software Foundation + Version Company=Python Software Foundation + Crystal Format=10111100101100000010001001001001 + Step View=&All + Variable Name1=_WISE_ + Variable Description1=WISE root directory + Variable Default1=C:\Programme\Wise Installation System + Variable Flags1=00001000 + Variable Name2=_TCLDIR_ + Variable Description2=The directory in which the Tcl/Tk installation + Variable Description2=lives. This must be a sibling of the Python + Variable Description2=directory. + Variable Default2=tcl84 + Variable Flags2=00001000 + Variable Name3=_DOC_ + Variable Description3=The unpacked HTML doc directory. + Variable Default3=..\html + Variable Flags3=00001001 + Variable Name4=_SYS_ + Variable Description4=System directory (where to find MSVCRT.DLL) + Variable Default4=C:\Windows\System + Variable Values4=C:\Windows\System + Variable Values4=C:\WINNT\System32 + Variable Values4=C:\Code\MSDLLs + Variable Values4=C:\Windows\System32 + Variable Flags4=00000010 + Variable Name5=_PYMAJOR_ + Variable Description5=Python major version number; the 2 in 2.3. + Variable Default5=2 + Variable Flags5=00001000 + Variable Name6=_PYMINOR_ + Variable Description6=Python minor version number; the 3 in 2.3 + Variable Default6=3 + Variable Flags6=00001000 + Variable Name7=_DOADMIN_ + Variable Description7=The initial value for %DOADMIN%. + Variable Description7=When 0, we never try to write under HKLM, + Variable Description7=and install the Python + MS runtime DLLs in + Variable Description7=the Python directory instead of the system dir. + Variable Default7=1 + Variable Values7=1 + Variable Values7=0 + Variable Flags7=00001010 + Variable Name8=_ALIASNAME_ + Variable Flags8=00001000 + Variable Name9=_ALIASPATH_ + Variable Flags9=00001000 + Variable Name10=_ALIASTYPE_ + Variable Flags10=00001000 +end +item: Set Variable + Variable=PYVER_STRING + Value=2.3 +end +item: Remark +end +item: Remark + Text=When the version number changes, set the compiler +end +item: Remark + Text=vrbls _PYMAJOR_ and _PYMINOR_. +end +item: Remark + Text=Nothing in the script below should need fiddling then. +end +item: Remark + Text=Other things that need fiddling: +end +item: Remark + Text= PYVER_STRING above. +end +item: Remark + Text= The "Title:" in the upper left corner of the GUI. +end +item: Remark + Text= Build Settings and Version Resource on step 6 (Finish) of the Installation Expert +end +item: Remark + Text= Be sure to select Steps->All or you may not see these! +end +item: Remark +end +item: Remark + Text=When the version of Tcl/Tk changes, the compiler vrbl +end +item: Remark + Text=_TCLDIR_ may also need to be changed. +end +item: Remark +end +item: Set Variable + Variable=APPTITLE + Value=Python %PYVER_STRING% +end +item: Remark + Text=PY_VERSION should be major.minor only; used to create the registry key; must match MS_DLL_ID in python_nt.rc +end +item: Set Variable + Variable=PY_VERSION + Value=%_PYMAJOR_%.%_PYMINOR_% +end +item: Remark + Text=GROUP is the Start menu group name; user can override. +end +item: Set Variable + Variable=GROUP + Value=Python %PY_VERSION% + Flags=10000000 +end +item: Remark + Text=MAINDIR is the app directory; user can override. +end +item: Set Variable + Variable=MAINDIR + Value=Python%_PYMAJOR_%%_PYMINOR_% +end +item: Remark +end +item: Set Variable + Variable=DOADMIN + Value=%_DOADMIN_% +end +item: Remark + Text=Give non-admin users a chance to abort. +end +item: Check Configuration + Flags=10011111 +end +item: Set Variable + Variable=DOADMIN + Value=0 +end +item: Display Message + Title=Doing non-admin install + Text=The current login does not have Administrator Privileges on this machine. Python will install its registry information into the per-user area only for the current login, instead of into the per-machine area for every account on this machine. Some advanced uses of Python may not work as a result (for example, running a Python script as a service). + Text= + Text=If this is not what you want, please click Cancel to abort this installation, log on as an Administrator, and start the installation again. + Flags=00001000 +end +item: End Block +end +item: Remark +end +item: Remark + Text=BEGIN WIZARD STUFF ----------------------------------------------------------------------------------------------------------------------------- +end +item: Remark + Text=Note from Tim: the "stop" on the next line is actually "pause". +end +item: Open/Close INSTALL.LOG + Flags=00000001 +end +item: Remark + Text=If the destination system does not have a writable Windows\System directory, system files will be written to the Windows\ directory +end +item: Check if File/Dir Exists + Pathname=%SYS% + Flags=10000100 +end +item: Set Variable + Variable=SYS + Value=%WIN% +end +item: End Block +end +item: Check Configuration + Flags=10111011 +end +item: Get Registry Key Value + Variable=COMMON + Key=SOFTWARE\Microsoft\Windows\CurrentVersion + Default=C:\Program Files\Common Files + Value Name=CommonFilesDir + Flags=00000100 +end +item: Get Registry Key Value + Variable=PROGRAM_FILES + Key=SOFTWARE\Microsoft\Windows\CurrentVersion + Default=C:\Program Files + Value Name=ProgramFilesDir + Flags=00000100 +end +item: Set Variable + Variable=EXPLORER + Value=1 +end +item: End Block +end +item: Remark + Text=Note from Tim: The Wizard hardcod "C:" at the start of the replacement text for MAINDIR. +end +item: Remark + Text=That's not appropriate if the system drive doesn't happen to be C:. +end +item: Remark + Text=I removed the "C:", and that did the right thing for two people who tested it on non-C: machines, +end +item: Remark + Text=but it's unclear whether it will always do the right thing. +end +item: Set Variable + Variable=MAINDIR + Value=\%MAINDIR% + Flags=00001100 +end +item: Remark + Text=BACKUP is the variable that holds the path that all backup files will be copied to when overwritten +end +item: Set Variable + Variable=BACKUP + Value=%MAINDIR%\BACKUP + Flags=10000000 +end +item: Remark + Text=DOBACKUP determines if a backup will be performed. The possible values are A (do backup) or B (do not do backup) +end +item: Set Variable + Variable=DOBACKUP + Value=A +end +item: Remark + Text=BRANDING determines if the installation will be branded with a name and company. By default, this is written to the INST directory (installation media). +end +item: Set Variable + Variable=BRANDING + Value=0 +end +item: If/While Statement + Variable=BRANDING + Value=1 +end +item: Read INI Value + Variable=NAME + Pathname=%INST%\CUSTDATA.INI + Section=Registration + Item=Name +end +item: Read INI Value + Variable=COMPANY + Pathname=%INST%\CUSTDATA.INI + Section=Registration + Item=Company +end +item: If/While Statement + Variable=NAME +end +item: Set Variable + Variable=DOBRAND + Value=1 +end +item: Get System Information + Variable=NAME + Flags=00000110 +end +item: Get System Information + Variable=COMPANY + Flags=00000111 +end +item: End Block +end +item: End Block +end +item: Remark + Text=END WIZARD STUFF ----------------------------------------------------------------------------------------------------------------------------- +end +item: Remark +end +item: Remark + Text=Set vrbls for the "Advanced Options" subdialog of Components. +end +item: Set Variable + Variable=SELECT_ADMIN + Value=A +end +item: If/While Statement + Variable=DOADMIN + Value=0 +end +item: Set Variable + Variable=SELECT_ADMIN + Value=B +end +item: End Block +end +item: Remark +end +item: Remark + Text=TASKS values: +end +item: Remark + Text=A: Register file extensions +end +item: Remark + Text=B: Create Start Menu shortcuts +end +item: Set Variable + Variable=TASKS + Value=AB +end +item: Remark +end +item: Remark + Text=COMPONENTS values: +end +item: Remark + Text=A: interpreter and libraries +end +item: Remark + Text=B: Tcl/Tk +end +item: Remark + Text=C: docs +end +item: Remark + Text=D: tools +end +item: Remark + Text=E: test suite +end +item: Set Variable + Variable=COMPONENTS + Value=ABCDE +end +item: Remark +end +item: Remark + Text=March thru the user GUI. +end +item: Wizard Block + Direction Variable=DIRECTION + Display Variable=DISPLAY + Bitmap Pathname=.\installer.bmp + X Position=9 + Y Position=10 + Filler Color=11173759 + Dialog=Select Destination Directory + Dialog=Backup Replaced Files + Dialog=Select Components + Dialog=Select Program Manager Group + Variable= + Variable= + Variable= + Variable=TASKS + Value= + Value= + Value= + Value=B + Compare=0 + Compare=0 + Compare=0 + Compare=3 + Flags=00000011 +end +item: If/While Statement + Variable=DISPLAY + Value=Start Installation +end +item: Set Variable + Variable=SUMMARY + Value=Install directory: %MAINDIR%%CRLF% +end +item: Remark +end +item: If/While Statement + Variable=SELECT_ADMIN + Value=A +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Doing admin install.%CRLF% + Flags=00000001 +end +item: Else Statement +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Doing non-admin install.%CRLF% + Flags=00000001 +end +item: End Block +end +item: Remark +end +item: If/While Statement + Variable=DOBACKUP + Value=A +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Make backups, into %BACKUP%%CRLF% + Flags=00000001 +end +item: Else Statement +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Don't make backups.%CRLF% + Flags=00000001 +end +item: End Block +end +item: Remark +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Components:%CRLF% + Flags=00000001 +end +item: If/While Statement + Variable=COMPONENTS + Value=A + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value= Python interpreter and libraries%CRLF% + Flags=00000001 +end +item: End Block +end +item: If/While Statement + Variable=COMPONENTS + Value=B + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value= Tcl/Tk (Tkinter, IDLE, pydoc)%CRLF% + Flags=00000001 +end +item: End Block +end +item: If/While Statement + Variable=COMPONENTS + Value=C + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value= Python documentation%CRLF% + Flags=00000001 +end +item: End Block +end +item: If/While Statement + Variable=COMPONENTS + Value=D + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value= Tool and utility scripts%CRLF% + Flags=00000001 +end +item: End Block +end +item: If/While Statement + Variable=COMPONENTS + Value=E + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value= Python test suite%CRLF% + Flags=00000001 +end +item: End Block +end +item: Remark +end +item: If/While Statement + Variable=TASKS + Value=A + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Register file extensions.%CRLF% + Flags=00000001 +end +item: Else Statement +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Don't register file extensions.%CRLF% + Flags=00000001 +end +item: End Block +end +item: Remark +end +item: If/While Statement + Variable=TASKS + Value=B + Flags=00000010 +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%Start Menu group: %GROUP%%CRLF% + Flags=00000001 +end +item: Else Statement +end +item: Set Variable + Variable=SUMMARY + Value=%CRLF%No Start Menu shortcuts.%CRLF% + Flags=00000001 +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Custom Dialog Set + Name=Select Destination Directory + Display Variable=DISPLAY + item: Dialog + Title=%APPTITLE% Installation + Title French=Installation de %APPTITLE% + Title German=Installation von %APPTITLE% + Title Spanish=Instalación de %APPTITLE% + Title Italian=Installazione di %APPTITLE% + Width=339 + Height=280 + Font Name=Helv + Font Size=8 + item: Push Button + Rectangle=188 234 244 253 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=&Next > + Text French=&Suite > + Text German=&Weiter > + Text Spanish=&Siguiente > + Text Italian=&Avanti > + end + item: Push Button + Rectangle=264 234 320 253 + Action=3 + Create Flags=01010000000000010000000000000000 + Text=&Cancel + Text French=&Annuler + Text German=&Abbrechen + Text Spanish=&Cancelar + Text Italian=&Annulla + end + item: Static + Rectangle=10 225 320 226 + Action=3 + Create Flags=01010000000000000000000000000111 + end + item: Static + Rectangle=108 11 323 33 + Create Flags=01010000000000000000000000000000 + Flags=0000000000000001 + Name=Times New Roman + Font Style=-24 0 0 0 700 255 0 0 0 3 2 1 18 + Text=Select Destination Directory + Text French=Sélectionner le répertoire de destination + Text German=Zielverzeichnis wählen + Text Spanish=Seleccione el directorio de destino + Text Italian=Selezionare Directory di destinazione + end + item: Listbox + Rectangle=108 58 321 219 + Variable=MAINDIR + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000100000010000000101000001 + Flags=0000110000001010 + Text=%MAINDIR% + Text= + end + item: Static + Rectangle=108 40 313 58 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000000000 + Text=Please select a directory for the %APPTITLE% files. + end + end + item: Dialog + Title=Select Destination Directory + Title French=Sélectionner le répertoire de destination + Title German=Zielverzeichnis wählen + Title Spanish=Seleccione el directorio de destino + Title Italian=Selezionare Directory di destinazione + Width=276 + Height=216 + Font Name=Helv + Font Size=8 + item: Listbox + Rectangle=6 6 204 186 + Variable=MAINDIR + Create Flags=01010000100000010000000101000000 + Flags=0000110000100010 + Text=%MAINDIR% + Text French=%MAINDIR% + Text German=%MAINDIR% + Text Spanish=%MAINDIR% + Text Italian=%MAINDIR% + end + item: Push Button + Rectangle=209 8 265 26 + Create Flags=01010000000000010000000000000001 + Text=OK + Text French=OK + Text German=OK + Text Spanish=Aceptar + Text Italian=OK + end + item: Push Button + Rectangle=209 31 265 50 + Variable=MAINDIR + Value=%MAINDIR_SAVE% + Create Flags=01010000000000010000000000000000 + Flags=0000000000000001 + Text=Cancel + Text French=Annuler + Text German=Abbrechen + Text Spanish=Cancelar + Text Italian=Annulla + end + end +end +item: Custom Dialog Set + Name=Backup Replaced Files + Display Variable=DISPLAY + item: Dialog + Title=%APPTITLE% Installation + Title French=Fichiers de Sauvegarde Remplacés + Title German=Sicherungskopie von ersetzten Dateien erstellen + Title Portuguese=Ficheiros substituídos de segurança + Title Spanish=Copias de seguridad de los archivos reemplazados + Title Italian=Backup file sostituiti + Title Danish=Sikkerhedskopiering af erstattede filer + Title Dutch=Vervangen bestanden kopiëren + Title Norwegian=Sikkerhetskopiere erstattede filer + Title Swedish=Säkerhetskopiera utbytta filer + Width=350 + Height=280 + Font Name=Helv + Font Size=8 + item: Push Button + Rectangle=188 234 244 251 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=&Next > + Text French=&Suivant> + Text German=&Weiter> + Text Portuguese=&Próximo> + Text Spanish=&Siguiente > + Text Italian=&Avanti > + Text Danish=&Næste> + Text Dutch=&Volgende> + Text Norwegian=&Neste> + Text Swedish=&Nästa > + end + item: Push Button + Rectangle=131 234 188 251 + Variable=DIRECTION + Value=B + Create Flags=01010000000000010000000000000000 + Text=< &Back + Text French=<&Retour + Text German=<&Zurück + Text Portuguese=<&Retornar + Text Spanish=<&Retroceder + Text Italian=< &Indietro + Text Danish=<&Tilbage + Text Dutch=<&Terug + Text Norwegian=<&Tilbake + Text Swedish=< &Tillbaka + end + item: Push Button + Rectangle=278 234 330 251 + Action=3 + Create Flags=01010000000000010000000000000000 + Text=Cancel + Text French=Annuler + Text German=Abbrechen + Text Portuguese=Cancelar + Text Spanish=Cancelar + Text Italian=Annulla + Text Danish=Annuller + Text Dutch=Annuleren + Text Norwegian=Avbryt + Text Swedish=Avbryt + end + item: Static + Rectangle=11 221 329 223 + Action=3 + Create Flags=01010000000000000000000000000111 + end + item: Static + Rectangle=108 46 320 98 + Create Flags=01010000000000000000000000000000 + Text=This installation program can create backup copies of all files replaced during the installation. These files will be used when the software is uninstalled and a rollback is requested. If backup copies are not created, you will only be able to uninstall the software and not roll the system back to a previous state. + Text= + Text=Do you want to create backups of replaced files? + Text French=Le programme d'installation peut créer des copies de sauvegarde de tous les fichiers remplacés pendant l'installation. Ces fichiers sont utilisés au cas où le logiciel est désinstallé et que l'on procède à la reprise du système. Si les copies de sauvegarde ne sont pas créées, on ne pourra que désinstaller le logiciel sans reprendre le système à un état précédent. Voulez-vous créer une sauvegarde des fichiers remplacés ? + Text German=Dieses Installationsprogramm kann Sicherungskopien von allen während der Installation ersetzten Dateien erstellen. Diese Dateien werden zur Rückgängigmachung der Installation und bei Anforderung eines Rollbacks verwendet. Ohne Sicherungskopien ist nur eine Rückgängigmachung der Installation möglich, nicht aber ein Rollback des Systems. Sicherungskopien der ersetzten Dateien erstellen? + Text Portuguese=Este programa de instalação pode criar cópias de segurança de todos os ficheiros substituídos durante a instalação. Estes ficheiros serão utilizados quando o programa for desinstalado e for requisitada uma retomada. Se as cópias de segurança não forem criadas, só poderá desinstalar o programa e não pode retomar um estado anterior do sistema. Deseja criar cópias de segurança dos ficheiros substituídos? + Text Spanish=Este programa de instalación puede crear copias de seguridad de todos los archivos reemplazados durante la instalación. Estos archivos se utilizarán cuando se desinstale el software y se solicite volver al estado anterior. Si no se crean copias de seguridad, únicamente podrá desinstalar el software y no podrá devolver el sistema al estado anterior. ¿Desea crear archivos de seguridad de los archivos reemplazados? + Text Italian=Questo programma di installazione può creare copie di backup di tutti i file sostituiti durante l’installazione. Questi file saranno usati quando il software sarà disinstallato e sarà richiesto un ritorno allo stato precedente. Se non crei le copie di backup, potrai solo disinstallare il software, ma non potrai riportare il sistema allo stato precedente. Vuoi creare i file di backup dei file sostituiti? + Text Danish=Dette installationsprogram kan oprette sikkerhedskopier af alle filer, som erstattes under installationen. Disse filer benyttes, når softwaren fjernes, og den tidligere systemkonfiguration genetableres. Hvis der ikke oprettes sikkerhedskopier, kan du kun fjerne den installerede software og ikke genetablere den tidligere systemkonfiguration. Vil du oprette sikkerhedskopier af filer, som erstattes? + Text Dutch=Dit installatieprogramma kan kopieën maken van alle bestanden die tijdens de installatie worden vervangen. Deze worden dan gebruikt als de software-installatie ongedaan wordt gemaakt en u het systeem wilt laten terugkeren naar de oorspronkelijke staat. Als er geen back-up kopieën worden gemaakt, kunt u de software enkel verwijderen maar het systeem niet in de oorspronkelijke staat terugbrengen. Wilt u een back-up maken van de vervangen bestanden? + Text Norwegian=Dette installasjonsprogrammet kan lage sikkerhetskopier av alle filer som blir erstattet under installasjonen. Disse filene vil tas i bruk når programvaren er avinstallert og det er behov for tilbakestilling. Hvis det ikke er laget sikkerhetskopier, kan du kun avinstallere programvaren og ikke stille systemet tilbake til tidligere status. Ønsker du å lage sikkerhetskopier av de filene som blir erstattet nå? + Text Swedish=Installationsprogrammet kan skapa säkerhetskopior av alla filer som byts ut under installationen. Dessa filer kan sedan användas när programvaran avinstalleras och du begär rollback. Om du då inte har några säkerhetskopior kan du bara avinstallera programvaran, inte återskapa systemet i dess tidigare skick. Vill du göra säkerhetskopior av de ersatta filerna? + end + item: Radio Button + Rectangle=141 106 265 136 + Variable=DOBACKUP + Create Flags=01010000000000010000000000001001 + Text=&Yes, make backups + Text=N&o, do not make backups + Text= + Text French=&Oui + Text French=N&on + Text French= + Text German=&Ja + Text German=N&ein + Text German= + Text Portuguese=&Sim + Text Portuguese=Nã&o + Text Portuguese= + Text Spanish=&Sí + Text Spanish=N&o + Text Spanish= + Text Italian=&Sì + Text Italian=N&o + Text Italian= + Text Danish=&Ja + Text Danish=&Nej + Text Danish= + Text Dutch=&Ja + Text Dutch=N&ee + Text Dutch= + Text Norwegian=&Ja + Text Norwegian=&Nei + Text Norwegian= + Text Swedish=&Ja + Text Swedish=N&ej + Text Swedish= + end + item: Static + Control Name=BACK2 + Rectangle=108 173 320 208 + Action=1 + Create Flags=01010000000000000000000000000111 + Text=Backup File Destination Directory + Text French=Répertoire de destination des fichiers de sauvegarde + Text German=Zielverzeichnis für die Sicherungsdatei + Text Portuguese=Directório de destino de ficheiro de segurança + Text Spanish=Directorio de Destino de los Archivos de Seguridad + Text Italian=Directory di destinazione dei file di backup + Text Danish=Destinationsbibliotek til sikkerhedskopier + Text Dutch=Doeldirectory backup-bestand + Text Norwegian=Målkatalog for sikkerhetskopier + Text Swedish=Katalog för säkerhetskopierade filer + end + item: Push Button + Control Name=BACK3 + Rectangle=265 185 318 203 + Variable=BACKUP_SAVE + Value=%BACKUP% + Destination Dialog=1 + Action=2 + Create Flags=01010000000000010000000000000000 + Text=B&rowse... + Text French=P&arcourir + Text German=B&lättern... + Text Portuguese=P&rocurar + Text Spanish=V&isualizar... + Text Italian=Sfoglia... + Text Danish=&Gennemse... + Text Dutch=B&laderen... + Text Norwegian=Bla igjennom + Text Swedish=&Bläddra + end + item: Static + Control Name=BACK4 + Rectangle=129 188 254 200 + Destination Dialog=2 + Create Flags=01010000000000000000000000000000 + Text=%BACKUP% + Text French=%BACKUP% + Text German=%BACKUP% + Text Portuguese=%BACKUP% + Text Spanish=%BACKUP% + Text Italian=%BACKUP% + Text Danish=%BACKUP% + Text Dutch=%BACKUP% + Text Norwegian=%BACKUP% + Text Swedish=%BACKUP% + end + item: Static + Rectangle=108 11 323 36 + Create Flags=01010000000000000000000000000000 + Flags=0000000000000001 + Name=Times New Roman + Font Style=-24 0 0 0 700 255 0 0 0 3 2 1 18 + Text=Backup Replaced Files + Text French=Sélectionner les composants + Text German=Komponenten auswählen + Text Spanish=Seleccione componentes + Text Italian=Selezionare i componenti + end + item: If/While Statement + Variable=DOBACKUP + Value=B + end + item: Set Control Attribute + Control Name=BACK3 + Operation=1 + end + item: Set Control Attribute + Control Name=BACK4 + Operation=1 + end + item: Else Statement + end + item: Set Control Attribute + Control Name=BACK3 + end + item: Set Control Attribute + Control Name=BACK4 + end + item: End Block + end + end + item: Dialog + Title=Select Destination Directory + Title French=Choisissez le répertoire de destination + Title German=Zielverzeichnis wählen + Title Portuguese=Seleccionar Directório de Destino + Title Spanish=Seleccione el Directorio de Destino + Title Italian=Seleziona Directory di destinazione + Title Danish=Vælg Destinationsbibliotek + Title Dutch=Kies Doeldirectory + Title Norwegian=Velg målkatalog + Title Swedish=Välj destinationskalatog + Width=276 + Height=216 + Font Name=Helv + Font Size=8 + item: Listbox + Rectangle=6 3 200 186 + Variable=BACKUP + Create Flags=01010000100000010000000101000000 + Flags=0000110000100010 + Text=%BACKUP% + Text= + Text French=%BACKUP% + Text French= + Text German=%BACKUP% + Text German= + Text Portuguese=%BACKUP% + Text Portuguese= + Text Spanish=%BACKUP% + Text Spanish= + Text Italian=%BACKUP% + Text Italian= + Text Danish=%BACKUP% + Text Danish= + Text Dutch=%BACKUP% + Text Dutch= + Text Norwegian=%BACKUP% + Text Norwegian= + Text Swedish=%BACKUP% + Text Swedish= + end + item: Push Button + Rectangle=209 8 265 26 + Create Flags=01010000000000010000000000000001 + Text=OK + Text French=OK + Text German=OK + Text Portuguese=OK + Text Spanish=ACEPTAR + Text Italian=OK + Text Danish=OK + Text Dutch=OK + Text Norwegian=OK + Text Swedish=OK + end + item: Push Button + Rectangle=209 31 265 50 + Variable=BACKUP + Value=%BACKUP_SAVE% + Create Flags=01010000000000010000000000000000 + Flags=0000000000000001 + Text=Cancel + Text French=Annuler + Text German=Abbrechen + Text Portuguese=Cancelar + Text Spanish=Cancelar + Text Italian=Annulla + Text Danish=Slet + Text Dutch=Annuleren + Text Norwegian=Avbryt + Text Swedish=Avbryt + end + end +end +item: Custom Dialog Set + Name=Select Components + Display Variable=DISPLAY + item: Dialog + Title=%APPTITLE% Installation + Title French=Installation de %APPTITLE% + Title German=Installation von %APPTITLE% + Title Spanish=Instalación de %APPTITLE% + Title Italian=Installazione di %APPTITLE% + Width=339 + Height=280 + Font Name=Helv + Font Size=8 + item: Push Button + Rectangle=188 234 244 253 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=&Next > + Text French=&Suite > + Text German=&Weiter > + Text Spanish=&Siguiente > + Text Italian=&Avanti > + end + item: Push Button + Rectangle=131 234 188 253 + Variable=DIRECTION + Value=B + Create Flags=01010000000000010000000000000000 + Text=< &Back + Text French=< &Retour + Text German=< &Zurück + Text Spanish=< &Atrás + Text Italian=< &Indietro + end + item: Push Button + Rectangle=264 234 320 253 + Action=3 + Create Flags=01010000000000010000000000000000 + Text=&Cancel + Text French=&Annuler + Text German=&Abbrechen + Text Spanish=&Cancelar + Text Italian=&Annulla + end + item: Checkbox + Rectangle=108 66 313 156 + Variable=COMPONENTS + Create Flags=01010000000000010000000000000011 + Flags=0000000000000110 + Text=Python interpreter and libraries + Text=Tcl/Tk (Tkinter, IDLE, pydoc) + Text=Python HTML docs + Text=Python utility scripts (Tools/) + Text=Python test suite (Lib/test/) + Text= + Text French=Python interpreter, library and IDLE + Text French=Python HTML docs + Text French=Python utility scripts (Tools/) + Text French=Python test suite (Lib/test/) + Text French= + Text German=Python interpreter, library and IDLE + Text German=Python HTML docs + Text German=Python utility scripts (Tools/) + Text German=Python test suite (Lib/test/) + Text German= + Text Spanish=Python interpreter, library and IDLE + Text Spanish=Python HTML docs + Text Spanish=Python utility scripts (Tools/) + Text Spanish=Python test suite (Lib/test/) + Text Spanish= + Text Italian=Python interpreter, library and IDLE + Text Italian=Python HTML docs + Text Italian=Python utility scripts (Tools/) + Text Italian=Python test suite (Lib/test/) + Text Italian= + end + item: Static + Rectangle=108 45 320 63 + Create Flags=01010000000000000000000000000000 + Text=Choose which components to install by checking the boxes below. + Text French=Choisissez les composants que vous voulez installer en cochant les cases ci-dessous. + Text German=Wählen Sie die zu installierenden Komponenten, indem Sie in die entsprechenden Kästchen klicken. + Text Spanish=Elija los componentes que desee instalar marcando los cuadros de abajo. + Text Italian=Scegliere quali componenti installare selezionando le caselle sottostanti. + end + item: Push Button + Rectangle=188 203 269 220 + Destination Dialog=1 + Action=2 + Enabled Color=00000000000000000000000011111111 + Create Flags=01010000000000010000000000000000 + Text=Advanced Options ... + end + item: Static + Rectangle=10 225 320 226 + Action=3 + Create Flags=01010000000000000000000000000111 + end + item: Static + Rectangle=108 10 323 43 + Create Flags=01010000000000000000000000000000 + Flags=0000000000000001 + Name=Times New Roman + Font Style=-24 0 0 0 700 255 0 0 0 3 2 1 18 + Text=Select Components + Text French=Sélectionner les composants + Text German=Komponenten auswählen + Text Spanish=Seleccione componentes + Text Italian=Selezionare i componenti + end + item: Static + Rectangle=251 180 311 193 + Variable=COMPONENTS + Value=MAINDIR + Create Flags=01010000000000000000000000000010 + end + item: Static + Rectangle=251 168 311 179 + Variable=COMPONENTS + Create Flags=01010000000000000000000000000010 + end + item: Static + Rectangle=123 168 234 181 + Create Flags=01010000000000000000000000000000 + Text=Disk Space Required: + Text French=Espace disque requis : + Text German=Notwendiger Speicherplatz: + Text Spanish=Espacio requerido en el disco: + Text Italian=Spazio su disco necessario: + end + item: Static + Rectangle=123 180 234 193 + Create Flags=01010000000000000000000000000000 + Text=Disk Space Remaining: + Text French=Espace disque disponible : + Text German=Verbleibender Speicherplatz: + Text Spanish=Espacio en disco disponible: + Text Italian=Spazio su disco disponibile: + end + item: Static + Rectangle=108 158 320 196 + Action=1 + Create Flags=01010000000000000000000000000111 + end + item: If/While Statement + Variable=DLG_EVENT_TYPE + Value=VERIFY + end + item: Remark + Text=If they're installing Tcl/Tk, Tools, or the test suite, doesn't make much sense unless they're installing Python too. + end + item: If/While Statement + Variable=COMPONENTS + Value=BDE + Flags=00001010 + end + item: If/While Statement + Variable=COMPONENTS + Value=A + Flags=00000011 + end + item: Display Message + Title=Are you sure? + Text=Installing Tcl/Tk, Tools or the test suite doesn't make much sense unless you install the Python interpreter and libraries too. + Text= + Text=Click Yes if that's really what you want. + Flags=00101101 + end + item: Remark + Text=Nothing -- just proceed to the next dialog. + end + item: Else Statement + end + item: Remark + Text=Return to the dialog. + end + item: Set Variable + Variable=DLG_EVENT_TYPE + end + item: End Block + end + item: End Block + end + item: End Block + end + item: End Block + end + end + item: Dialog + Title=Advanced Options + Width=339 + Height=213 + Font Name=Helv + Font Size=8 + item: Radio Button + Control Name=ADMIN2 + Rectangle=11 46 90 76 + Variable=SELECT_ADMIN + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000010000000000001001 + Text=Admin install + Text=Non-Admin installl + Text= + end + item: Push Button + Rectangle=188 170 244 189 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=OK + Text French=&Suite > + Text German=&Weiter > + Text Spanish=&Siguiente > + Text Italian=&Avanti > + end + item: Static + Rectangle=5 3 326 83 + Action=1 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000000111 + end + item: Static + Control Name=ADMIN1 + Rectangle=11 11 321 45 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000000000 + Text=By default, the install records settings in the per-machine area of the registry (HKLM), and installs the Python and C runtime DLLs to %SYS32%. Choose "Non-Admin install" if you would prefer settings made in the per-user registry (HKCU), and DLLs installed in %MAINDIR%. + end + item: Static + Rectangle=5 90 326 157 + Action=1 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000000111 + end + item: Checkbox + Rectangle=11 121 243 151 + Variable=TASKS + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000010000000000000011 + Text=Register file extensions (.py, .pyw, .pyc, .pyo) + Text=Create Start Menu shortcuts + Text= + end + item: Static + Rectangle=11 103 320 121 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000000000 + Text=Choose tasks to perform by checking the boxes below. + end + item: If/While Statement + Variable=DLG_EVENT_TYPE + Value=INIT + end + item: If/While Statement + Variable=DOADMIN + Value=1 + end + item: Set Control Attribute + Control Name=ADMIN2 + end + item: Else Statement + end + item: Set Control Text + Control Name=ADMIN1 + Control Text=This section is available only if logged in to an account with Administrator privileges. + end + item: Set Control Attribute + Control Name=ADMIN2 + Operation=1 + end + item: End Block + end + item: End Block + end + end +end +item: Custom Dialog Set + Name=Select Program Manager Group + Display Variable=DISPLAY + item: Dialog + Title=%APPTITLE% Installation + Title French=Installation de %APPTITLE% + Title German=Installation von %APPTITLE% + Title Spanish=Instalación de %APPTITLE% + Title Italian=Installazione di %APPTITLE% + Width=339 + Height=280 + Font Name=Helv + Font Size=8 + item: Push Button + Rectangle=188 234 244 253 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=&Next > + Text French=&Suite > + Text German=&Weiter > + Text Spanish=&Siguiente > + Text Italian=&Avanti > + end + item: Push Button + Rectangle=131 234 188 253 + Variable=DIRECTION + Value=B + Create Flags=01010000000000010000000000000000 + Flags=0000000000000001 + Text=< &Back + Text French=< &Retour + Text German=< &Zurück + Text Spanish=< &Atrás + Text Italian=< &Indietro + end + item: Push Button + Rectangle=264 234 320 253 + Action=3 + Create Flags=01010000000000010000000000000000 + Text=&Cancel + Text French=&Annuler + Text German=&Abbrechen + Text Spanish=&Cancelar + Text Italian=&Annulla + end + item: Static + Rectangle=10 225 320 226 + Action=3 + Create Flags=01010000000000000000000000000111 + end + item: Static + Rectangle=108 10 323 53 + Create Flags=01010000000000000000000000000000 + Flags=0000000000000001 + Name=Times New Roman + Font Style=-24 0 0 0 700 255 0 0 0 3 2 1 18 + Text=Select Start Menu Group + Text French=Sélectionner le groupe du Gestionnaire de programme + Text German=Bestimmung der Programm-Managergruppe + Text Spanish=Seleccione grupo del Administrador de programas + Text Italian=Selezionare il gruppo ProgMan + end + item: Static + Rectangle=108 35 320 65 + Create Flags=01010000000000000000000000000000 + Text=Enter the name of the Start Menu program group to which to add the %APPTITLE% icons: + Text French=Entrez le nom du groupe du Gestionnaire de programme dans lequel vous souhaitez ajouter les icônes de %APPTITLE% : + Text German=Geben Sie den Namen der Programmgruppe ein, der das Symbol %APPTITLE% hinzugefügt werden soll: + Text Spanish=Escriba el nombre del grupo del Administrador de programas en el que desea agregar los iconos de %APPTITLE%: + Text Italian=Inserire il nome del gruppo Program Manager per aggiungere le icone %APPTITLE% a: + end + item: Combobox + Rectangle=108 56 320 219 + Variable=GROUP + Create Flags=01010000001000010000001100000001 + Flags=0000000000000001 + Text=%GROUP% + Text= + Text French=%GROUP% + Text German=%GROUP% + Text Spanish=%GROUP% + Text Italian=%GROUP% + end + end +end +item: Custom Dialog Set + Name=Start Installation + Display Variable=DISPLAY + item: Dialog + Title=%APPTITLE% Installation + Title French=Installation de %APPTITLE% + Title German=Installation von %APPTITLE% + Title Spanish=Instalación de %APPTITLE% + Title Italian=Installazione di %APPTITLE% + Width=339 + Height=280 + Font Name=Helv + Font Size=8 + item: Push Button + Rectangle=188 234 244 253 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=&Next > + Text French=&Suite > + Text German=&Weiter > + Text Spanish=&Siguiente > + Text Italian=&Avanti > + end + item: Push Button + Rectangle=131 234 188 253 + Variable=DIRECTION + Value=B + Create Flags=01010000000000010000000000000000 + Text=< &Back + Text French=< &Retour + Text German=< &Zurück + Text Spanish=< &Atrás + Text Italian=< &Indietro + end + item: Push Button + Rectangle=264 234 320 253 + Action=3 + Create Flags=01010000000000010000000000000000 + Text=&Cancel + Text French=&Annuler + Text German=&Abbrechen + Text Spanish=&Cancelar + Text Italian=&Annulla + end + item: Static + Rectangle=10 225 320 226 + Action=3 + Create Flags=01010000000000000000000000000111 + end + item: Static + Rectangle=108 10 323 53 + Create Flags=01010000000000000000000000000000 + Flags=0000000000000001 + Name=Times New Roman + Font Style=-24 0 0 0 700 255 0 0 0 3 2 1 18 + Text=Ready to Install! + Text French=Prêt à installer ! + Text German=Installationsbereit! + Text Spanish=¡Preparado para la instalación! + Text Italian=Pronto per l'installazione! + end + item: Static + Rectangle=108 40 320 62 + Create Flags=01010000000000000000000000000000 + Text=Click the Next button to install %APPTITLE%, or the Back button to change choices: + Text French=Vous êtes maintenant prêt à installer les fichiers %APPTITLE%. + Text French= + Text French=Cliquez sur le bouton Suite pour commencer l'installation ou sur le bouton Retour pour entrer les informations d'installation à nouveau. + Text German=Sie können %APPTITLE% nun installieren. + Text German= + Text German=Klicken Sie auf "Weiter", um mit der Installation zu beginnen. Klicken Sie auf "Zurück", um die Installationsinformationen neu einzugeben. + Text Spanish=Ya está listo para instalar %APPTITLE%. + Text Spanish= + Text Spanish=Presione el botón Siguiente para comenzar la instalación o presione Atrás para volver a ingresar la información para la instalación. + Text Italian=Ora è possibile installare %APPTITLE%. + Text Italian= + Text Italian=Premere il pulsante Avanti per avviare l'installazione o il pulsante Indietro per reinserire le informazioni di installazione. + end + item: Editbox + Rectangle=108 66 324 219 + Help Context=16711681 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000100000000001100011000100 + Text=%SUMMARY% + end + end +end +item: Remark +end +item: If/While Statement + Variable=DISPLAY + Value=Select Destination Directory +end +item: Remark + Text=User may have changed MAINDIR, so reset BACKUP to match. +end +item: Set Variable + Variable=BACKUP + Value=%MAINDIR%\BACKUP +end +item: End Block +end +item: Remark +end +item: End Block +end +item: Remark +end +item: Remark + Text=BEGIN WIZARD STUFF ----------------------------------------------------------------------------------------------------------------------------- +end +item: Remark + Text=When the BACKUP feature is enabled, the BACKUPDIR is initialized +end +item: If/While Statement + Variable=DOBACKUP + Value=A +end +item: Set Variable + Variable=BACKUPDIR + Value=%BACKUP% +end +item: End Block +end +item: Remark + Text=The BRANDING information is written to the INI file on the installation media. +end +item: If/While Statement + Variable=BRANDING + Value=1 +end +item: If/While Statement + Variable=DOBRAND + Value=1 +end +item: Edit INI File + Pathname=%INST%\CUSTDATA.INI + Settings=[Registration] + Settings=NAME=%NAME% + Settings=COMPANY=%COMPANY% + Settings= +end +item: End Block +end +item: End Block +end +item: Remark + Text=Begin writing to the INSTALL.LOG +end +item: Open/Close INSTALL.LOG +end +item: Remark + Text=Check free disk space calculates free disk space as well as component sizes. +end +item: Remark + Text=It should be located before all Install File actions. +end +item: Check Disk Space + Component=COMPONENTS +end +item: Remark + Text=This include script allows uninstall support +end +item: Remark + Text=Note from Tim: this is our own Uninstal.wse, a copy of Wise's except +end +item: Remark + Text=it writes to HKCU (instead of HKLM) if the user doesn't have admin privs. +end +item: Include Script + Pathname=.\Uninstal.wse +end +item: Remark + Text=Note from Tim: these seeming no-ops actually convert to short filenames. +end +item: Set Variable + Variable=COMMON + Value=%COMMON% + Flags=00010100 +end +item: Set Variable + Variable=MAINDIR + Value=%MAINDIR% + Flags=00010100 +end +item: Remark + Text=This IF/THEN/ELSE reads the correct registry entries for shortcut/icon placement +end +item: Check Configuration + Flags=10111011 +end +item: Get Registry Key Value + Variable=STARTUPDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%WIN%\Start Menu\Programs\StartUp + Value Name=StartUp + Flags=00000010 +end +item: Get Registry Key Value + Variable=DESKTOPDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%WIN%\Desktop + Value Name=Desktop + Flags=00000010 +end +item: Get Registry Key Value + Variable=STARTMENUDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%WIN%\Start Menu + Value Name=Start Menu + Flags=00000010 +end +item: Get Registry Key Value + Variable=GROUPDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%WIN%\Start Menu\Programs + Value Name=Programs + Flags=00000010 +end +item: Get Registry Key Value + Variable=CSTARTUPDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%STARTUPDIR% + Value Name=Common Startup + Flags=00000100 +end +item: Get Registry Key Value + Variable=CDESKTOPDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%DESKTOPDIR% + Value Name=Common Desktop + Flags=00000100 +end +item: Get Registry Key Value + Variable=CSTARTMENUDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%STARTMENUDIR% + Value Name=Common Start Menu + Flags=00000100 +end +item: Get Registry Key Value + Variable=CGROUPDIR + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Default=%GROUPDIR% + Value Name=Common Programs + Flags=00000100 +end +item: Else Statement +end +item: Remark + Text=Note from Tim: the Wizard left this block empty! +end +item: Remark + Text=Perhaps it's only relevant on Windows 3.1. +end +item: End Block +end +item: Remark + Text=END WIZARD STUFF ----------------------------------------------------------------------------------------------------------------------------- +end +item: Remark +end +item: If/While Statement + Variable=SELECT_ADMIN + Value=B +end +item: Remark + Text=The user chose a non-admin install in "Advanced Options". +end +item: Remark + Text=This should come after the include of Uninstal.wse above, because +end +item: Remark + Text=writing uninstall info to HKCU is ineffective except under Win2K. +end +item: Set Variable + Variable=DOADMIN + Value=0 +end +item: End Block +end +item: Remark +end +item: Set Variable + Variable=CGROUP_SAVE + Value=%GROUP% +end +item: If/While Statement + Variable=TASKS + Value=B + Flags=00000010 +end +item: If/While Statement + Variable=DOADMIN + Value=1 +end +item: Set Variable + Variable=GROUP + Value=%CGROUPDIR%\%GROUP% +end +item: Else Statement +end +item: Set Variable + Variable=GROUP + Value=%GROUPDIR%\%GROUP% +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Remark + Text=Long section to install files. +end +item: Remark +end +item: If/While Statement + Variable=DOADMIN + Value=1 +end +item: Set Variable + Variable=DLLDEST + Value=%SYS32% +end +item: Else Statement +end +item: Set Variable + Variable=DLLDEST + Value=%MAINDIR% +end +item: End Block +end +item: Remark +end +item: Remark + Text=Install the license even if they deselect everything . +end +item: Install File + Source=..\license + Destination=%MAINDIR%\LICENSE.txt + Flags=0000000000000010 +end +item: Install File + Source=..\readme + Destination=%MAINDIR%\README.txt + Flags=0000000000000010 +end +item: Install File + Source=..\misc\news + Destination=%MAINDIR%\NEWS.txt + Flags=0000000000000010 +end +item: Remark + Text=Icons -- always install so that the uninstaller can use them for its own display. +end +item: Install File + Source=..\pc\pycon.ico + Destination=%MAINDIR%\pycon.ico + Flags=0000000010000010 +end +item: Install File + Source=..\pc\pyc.ico + Destination=%MAINDIR%\pyc.ico + Flags=0000000010000010 +end +item: Install File + Source=..\pc\py.ico + Destination=%MAINDIR%\py.ico + Flags=0000000010000010 +end +item: Remark +end +item: Remark + Text=These arrange to (recursively!) delete all .pyc and .pyo files at uninstall time. +end +item: Remark + Text=This "does the right thing": any directories left empty at the end are removed. +end +item: Add Text to INSTALL.LOG + Text=File Tree: %MAINDIR%\*.pyc +end +item: Add Text to INSTALL.LOG + Text=File Tree: %MAINDIR%\*.pyo +end +item: Remark +end +item: Remark + Text=A: interpreter and libraries +end +item: If/While Statement + Variable=COMPONENTS + Value=A + Flags=00000010 +end +item: Remark + Text=Executables +end +item: Install File + Source=.\python.exe + Destination=%MAINDIR%\python.exe + Flags=0000000000000010 +end +item: Install File + Source=.\pythonw.exe + Destination=%MAINDIR%\pythonw.exe + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Extension module DLLs (.pyd); keep in synch with libs directory next +end +item: Install File + Source=.\winreg.pyd + Destination=%MAINDIR%\DLLs\winreg.pyd + Description=Extension modules + Flags=0000000000000010 +end +item: Install File + Source=.\_csv.pyd + Destination=%MAINDIR%\DLLs\_csv.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\_sre.pyd + Destination=%MAINDIR%\DLLs\_sre.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\_ssl.pyd + Destination=%MAINDIR%\DLLs\_ssl.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\_symtable.pyd + Destination=%MAINDIR%\DLLs\_symtable.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\_testcapi.pyd + Destination=%MAINDIR%\DLLs\_testcapi.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\_tkinter.pyd + Destination=%MAINDIR%\DLLs\_tkinter.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\_socket.pyd + Destination=%MAINDIR%\DLLs\_socket.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\bz2.pyd + Destination=%MAINDIR%\DLLs\bz2.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\datetime.pyd + Destination=%MAINDIR%\DLLs\datetime.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\mmap.pyd + Destination=%MAINDIR%\DLLs\mmap.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\parser.pyd + Destination=%MAINDIR%\DLLs\parser.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\pyexpat.pyd + Destination=%MAINDIR%\DLLs\pyexpat.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\select.pyd + Destination=%MAINDIR%\DLLs\select.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\unicodedata.pyd + Destination=%MAINDIR%\DLLs\unicodedata.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\winsound.pyd + Destination=%MAINDIR%\DLLs\winsound.pyd + Flags=0000000000000010 +end +item: Install File + Source=.\zlib.pyd + Destination=%MAINDIR%\DLLs\zlib.pyd + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Link libraries (.lib); keep in synch with DLLs above, except that the Python lib lives here. +end +item: Install File + Source=.\winreg.lib + Destination=%MAINDIR%\libs\winreg.lib + Description=Link library files + Flags=0000000000000010 +end +item: Install File + Source=.\_csv.lib + Destination=%MAINDIR%\libs\_csv.lib + Flags=0000000000000010 +end +item: Install File + Source=.\_sre.lib + Destination=%MAINDIR%\libs\_sre.lib + Flags=0000000000000010 +end +item: Install File + Source=.\_ssl.lib + Destination=%MAINDIR%\libs\_ssl.lib + Flags=0000000000000010 +end +item: Install File + Source=.\_symtable.lib + Destination=%MAINDIR%\libs\_symtable.lib + Flags=0000000000000010 +end +item: Install File + Source=.\_testcapi.lib + Destination=%MAINDIR%\libs\_testcapi.lib + Flags=0000000000000010 +end +item: Install File + Source=.\_tkinter.lib + Destination=%MAINDIR%\libs\_tkinter.lib + Description=Extension modules + Flags=0000000000000010 +end +item: Install File + Source=.\_socket.lib + Destination=%MAINDIR%\libs\_socket.lib + Flags=0000000000000010 +end +item: Install File + Source=.\bz2.lib + Destination=%MAINDIR%\libs\bz2.lib + Flags=0000000000000010 +end +item: Install File + Source=.\datetime.lib + Destination=%MAINDIR%\libs\datetime.lib + Flags=0000000000000010 +end +item: Install File + Source=.\mmap.lib + Destination=%MAINDIR%\libs\mmap.lib + Flags=0000000000000010 +end +item: Install File + Source=.\parser.lib + Destination=%MAINDIR%\libs\parser.lib + Flags=0000000000000010 +end +item: Install File + Source=.\pyexpat.lib + Destination=%MAINDIR%\libs\pyexpat.lib + Flags=0000000000000010 +end +item: Install File + Source=.\select.lib + Destination=%MAINDIR%\libs\select.lib + Flags=0000000000000010 +end +item: Install File + Source=.\unicodedata.lib + Destination=%MAINDIR%\libs\unicodedata.lib + Flags=0000000000000010 +end +item: Install File + Source=.\winsound.lib + Destination=%MAINDIR%\libs\winsound.lib + Flags=0000000000000010 +end +item: Install File + Source=.\zlib.lib + Destination=%MAINDIR%\libs\zlib.lib + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=.\python%_pymajor_%%_pyminor_%.lib + Destination=%MAINDIR%\libs\python%_PYMAJOR_%%_PYMINOR_%.lib + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Main Python DLL +end +item: Remark + Text=Tell Wise it's OK to delete the Python DLL at uninstall time, +end +item: Remark + Text=despite that we (may) write it into a system directory. +end +item: Add Text to INSTALL.LOG + Text=Non-System File: +end +item: Install File + Source=.\python%_pymajor_%%_pyminor_%.dll + Destination=%DLLDEST%\python%_PYMAJOR_%%_PYMINOR_%.dll + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Libraries (Lib/) +end +item: Install File + Source=..\lib\*.py + Destination=%MAINDIR%\Lib + Description=Library Modules + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\compiler\*.py + Destination=%MAINDIR%\Lib\compiler + Description=Python compiler written in Python + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\distutils\*.py + Destination=%MAINDIR%\Lib\distutils + Description=Distribution utility modules + Flags=0000000000000010 +end +item: Install File + Source=..\lib\distutils\readme + Destination=%MAINDIR%\Lib\distutils\README.txt + Flags=0000000000000010 +end +item: Install File + Source=..\lib\distutils\command\*.py + Destination=%MAINDIR%\Lib\distutils\command + Flags=0000000000000010 +end +item: Install File + Source=..\lib\distutils\command\wininst.exe + Destination=%MAINDIR%\Lib\distutils\command\wininst.exe + Flags=0000000000000010 +end +item: Install File + Source=..\lib\distutils\command\command_template + Destination=%MAINDIR%\Lib\distutils\command\command_template + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\email\*.py + Destination=%MAINDIR%\Lib\email + Description=Library email package + Flags=0000000000000010 +end +item: Install File + Source=..\lib\email\test\*.py + Destination=%MAINDIR%\Lib\email\test + Description=email tests + Flags=0000000000000010 +end +item: Install File + Source=..\lib\email\test\data\*.txt + Destination=%MAINDIR%\Lib\email\test\data + Description=email test data + Flags=0000000000000010 +end +item: Install File + Source=..\lib\email\test\data\*.gif + Destination=%MAINDIR%\Lib\email\test\data + Description=email test data + Flags=0000000000000010 +end +item: Install File + Source=..\lib\email\test\data\*.au + Destination=%MAINDIR%\Lib\email\test\data + Description=email test data + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\encodings\*.py + Destination=%MAINDIR%\Lib\encodings + Description=Unicode encoding tables + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\hotshot\*.py + Destination=%MAINDIR%\Lib\hotshot + Description=Fast Python profiler + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\lib-old\*.py + Destination=%MAINDIR%\Lib\lib-old + Description=Obsolete modules + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\tkinter\*.py + Destination=%MAINDIR%\Lib\tkinter + Description=Tkinter related library modules + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\logging\*.py + Destination=%MAINDIR%\Lib\logging + Description=Logging package + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\site-packages\readme + Destination=%MAINDIR%\Lib\site-packages\README.txt + Description=Site packages + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\xml\*.py + Destination=%MAINDIR%\Lib\xml + Description=XML support packages + Flags=0000000000000010 +end +item: Install File + Source=..\lib\xml\dom\*.py + Destination=%MAINDIR%\Lib\xml\dom + Flags=0000000000000010 +end +item: Install File + Source=..\lib\xml\parsers\*.py + Destination=%MAINDIR%\Lib\xml\parsers + Flags=0000000000000010 +end +item: Install File + Source=..\lib\xml\sax\*.py + Destination=%MAINDIR%\Lib\xml\sax + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=C Include files +end +item: Install File + Source=..\include\*.h + Destination=%MAINDIR%\include + Description=Header files + Flags=0000000000000010 +end +item: Install File + Source=..\pc\pyconfig.h + Destination=%MAINDIR%\include\pyconfig.h + Description=Header files (pyconfig.h) + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Microsoft C runtime libraries +end +item: Install File + Source=%_SYS_%\MSVCIRT.DLL + Destination=%DLLDEST%\MSVCIRT.DLL + Description=Visual C++ Runtime DLLs + Flags=0000011000010011 +end +item: Install File + Source=%_SYS_%\MSVCRT.DLL + Destination=%DLLDEST%\MSVCRT.DLL + Description=Visual C++ Runtime DLLs + Flags=0000011000010011 +end +item: End Block +end +item: Remark +end +item: Remark + Text=B: Tcl/Tk (Tkinter, IDLE, pydoc) +end +item: If/While Statement + Variable=COMPONENTS + Value=B + Flags=00000010 +end +item: Remark + Text=Tcl/Tk +end +item: Install File + Source=..\..\%_tcldir_%\bin\*.dll + Destination=%MAINDIR%\DLLs + Description=Tcl/Tk binaries and libraries + Flags=0000000000000010 +end +item: Install File + Source=..\..\%_tcldir_%\lib\*.* + Destination=%MAINDIR%\tcl + Description=Tcl/Tk binaries and libraries + Flags=0000000100000010 +end +item: Remark +end +item: Remark + Text=IDLE +end +item: Install File + Source=..\Lib\idlelib\*.py + Destination=%MAINDIR%\Lib\idlelib + Description=Integrated DeveLopment Environment for Python + Flags=0000000000000010 +end +item: Install File + Source=..\Lib\idlelib\*.txt + Destination=%MAINDIR%\Lib\idlelib + Description=Integrated DeveLopment Environment for Python + Flags=0000000000000010 +end +item: Install File + Source=..\Lib\idlelib\*.def + Destination=%MAINDIR%\Lib\idlelib + Description=Integrated DeveLopment Environment for Python + Flags=0000000000000010 +end +item: Install File + Source=..\Lib\idlelib\Icons\* + Destination=%MAINDIR%\Lib\idlelib\Icons + Description=Integrated DeveLopment Environment for Python + Flags=0000000000000010 +end +item: Install File + Source=..\Tools\scripts\idle + Destination=%MAINDIR%\Lib\idlelib\idle.pyw + Description=IDLE bootstrap script + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Windows pydoc driver +end +item: Install File + Source=..\tools\scripts\*.pyw + Destination=%MAINDIR%\Tools\Scripts + Description=Windows pydoc driver + Flags=0000000000000010 +end +item: End Block +end +item: Remark +end +item: Remark + Text=C: docs +end +item: If/While Statement + Variable=COMPONENTS + Value=C + Flags=00000010 +end +item: Install File + Source=%_DOC_%\*.* + Destination=%MAINDIR%\Doc + Description=Python Documentation (HTML) + Flags=0000000100000010 +end +item: End Block +end +item: Remark +end +item: Remark + Text=D: tools +end +item: If/While Statement + Variable=COMPONENTS + Value=D + Flags=00000010 +end +item: Install File + Source=..\tools\scripts\*.py + Destination=%MAINDIR%\Tools\Scripts + Description=Utility Scripts + Flags=0000000000000010 +end +item: Install File + Source=..\tools\scripts\*.doc + Destination=%MAINDIR%\Tools\Scripts + Description=Utility Scripts + Flags=0000000000000010 +end +item: Install File + Source=..\tools\scripts\readme + Destination=%MAINDIR%\Tools\Scripts\README.txt + Description=Utility Scripts + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\tools\webchecker\*.py + Destination=%MAINDIR%\Tools\webchecker + Description=Web checker tool + Flags=0000000000000010 +end +item: Install File + Source=..\tools\webchecker\readme + Destination=%MAINDIR%\Tools\webchecker\README.txt + Description=Web checker tool + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\tools\versioncheck\*.py + Destination=%MAINDIR%\Tools\versioncheck + Description=Version checker tool + Flags=0000000000000010 +end +item: Install File + Source=..\tools\versioncheck\readme + Destination=%MAINDIR%\Tools\versioncheck\README.txt + Description=Version checker tool + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\tools\pynche\*.py + Destination=%MAINDIR%\Tools\pynche + Description=pynche color editor + Flags=0000000000000010 +end +item: Install File + Source=..\tools\pynche\*.txt + Destination=%MAINDIR%\Tools\pynche + Description=pynche color editor + Flags=0000000000000010 +end +item: Install File + Source=..\tools\pynche\x\*.txt + Destination=%MAINDIR%\Tools\pynche\X + Description=pynche color editor - X files + Flags=0000000000000010 +end +item: Install File + Source=..\tools\pynche\readme + Destination=%MAINDIR%\Tools\pynche\README.txt + Description=pynche color editor - README + Flags=0000000100000010 +end +item: Install File + Source=..\tools\pynche\pynche + Destination=%MAINDIR%\Tools\pynche\pynche.py + Description=pynche color editor - main + Flags=0000000100000010 +end +item: Install File + Source=..\tools\pynche\pynche.pyw + Destination=%MAINDIR%\Tools\pynche\pynche.pyw + Description=pynche color editor - noconsole main + Flags=0000000100000010 +end +item: Remark +end +item: Install File + Source=..\tools\i18n\*.py + Destination=%MAINDIR%\Tools\i18n + Description=Internationalization helpers + Flags=0000000000000010 +end +item: End Block +end +item: Remark +end +item: Remark + Text=E: test suite +end +item: If/While Statement + Variable=COMPONENTS + Value=E + Flags=00000010 +end +item: Install File + Source=..\lib\test\audiotest.au + Destination=%MAINDIR%\Lib\test\audiotest.au + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.uue + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.py + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.xml + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.out + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.bz2 + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.tar + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.gz + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Install File + Source=..\lib\test\*.txt + Destination=%MAINDIR%\Lib\test + Description=Python Test files + Flags=0000000000000010 +end +item: Remark +end +item: Install File + Source=..\lib\test\output\*.* + Destination=%MAINDIR%\Lib\test\output + Description=Python Test output files + Flags=0000000000000010 +end +item: End Block +end +item: Remark +end +item: Remark + Text=DONE with file copying. +end +item: Remark + Text=The rest is registry and Start Menu fiddling. +end +item: Remark +end +item: If/While Statement + Variable=COMPONENTS + Value=A + Flags=00000010 +end +item: If/While Statement + Variable=TASKS + Value=A + Flags=00000010 +end +item: Remark + Text=Register file extensions. As usual, Admin privs get in the way, but with a twist: +end +item: Remark + Text=You don't need admin privs to write to HKEY_CLASSES_ROOT *except* under Win2K. +end +item: Remark + Text=On Win2K, a user without Admin privs has to register extensions under HKCU\Software\CLASSES instead. +end +item: Remark + Text=But while you can *do* that under other flavors of Windows too, it has no useful effect except in Win2K. +end +item: Set Variable + Variable=USE_HKCR + Value=1 +end +item: Check Configuration + Flags=11110010 +end +item: If/While Statement + Variable=DOADMIN + Value=0 +end +item: Set Variable + Variable=USE_HKCR + Value=0 +end +item: End Block +end +item: End Block +end +item: If/While Statement + Variable=USE_HKCR + Value=1 +end +item: Remark + Text=File types. +end +item: Edit Registry + Total Keys=1 + Key=Python.File + New Value=Python File +end +item: Edit Registry + Total Keys=1 + Key=Python.File\shell\open\command + New Value=%MAINDIR%\python.exe "%%1" %%* +end +item: Edit Registry + Total Keys=1 + Key=Python.File\DefaultIcon + New Value=%MAINDIR%\Py.ico +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=Python.NoConFile + New Value=Python File (no console) +end +item: Edit Registry + Total Keys=1 + Key=Python.NoConFile\shell\open\command + New Value=%MAINDIR%\pythonw.exe "%%1" %%* +end +item: Edit Registry + Total Keys=1 + Key=Python.NoConFile\DefaultIcon + New Value=%MAINDIR%\Py.ico +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=Python.CompiledFile + New Value=Compiled Python File +end +item: Edit Registry + Total Keys=1 + Key=Python.CompiledFile\shell\open\command + New Value=%MAINDIR%\python.exe "%%1" %%* +end +item: Edit Registry + Total Keys=1 + Key=Python.CompiledFile\DefaultIcon + New Value=%MAINDIR%\pyc.ico +end +item: Remark +end +item: Remark + Text=File extensions. +end +item: Edit Registry + Total Keys=1 + Key=.py + New Value=Python.File +end +item: Edit Registry + Total Keys=1 + Key=.py + New Value=text/plain + Value Name=Content Type +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=.pyw + New Value=Python.NoConFile +end +item: Edit Registry + Total Keys=1 + Key=.pyw + New Value=text/plain + Value Name=Content Type +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=.pyc + New Value=Python.CompiledFile +end +item: Edit Registry + Total Keys=1 + Key=.pyo + New Value=Python.CompiledFile +end +item: Else Statement +end +item: Remark + Text=File types. +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.File + New Value=Python File + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.File\shell\open\command + New Value=%MAINDIR%\python.exe "%%1" %%* + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.File\DefaultIcon + New Value=%MAINDIR%\Py.ico + Root=1 +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.NoConFile + New Value=Python File (no console) + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.NoConFile\shell\open\command + New Value=%MAINDIR%\pythonw.exe "%%1" %%* + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.NoConFile\DefaultIcon + New Value=%MAINDIR%\Py.ico + Root=1 +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.CompiledFile + New Value=Compiled Python File + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.CompiledFile\shell\open\command + New Value=%MAINDIR%\python.exe "%%1" %%* + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.CompiledFile\DefaultIcon + New Value=%MAINDIR%\pyc.ico + Root=1 +end +item: Remark +end +item: Remark + Text=File extensions. +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\.py + New Value=Python.File + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\.py + New Value=text/plain + Value Name=Content Type + Root=1 +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\.pyw + New Value=Python.NoConFile + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\.pyw + New Value=text/plain + Value Name=Content Type + Root=1 +end +item: Remark +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\.pyc + New Value=Python.CompiledFile + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\.pyo + New Value=Python.CompiledFile + Root=1 +end +item: End Block +end +item: Remark +end +item: Remark + Text=If we're installing IDLE, also set an Edit context menu action to use IDLE, for .py and .pyw files. +end +item: If/While Statement + Variable=COMPONENTS + Value=B + Flags=00000010 +end +item: If/While Statement + Variable=USE_HKCR + Value=1 +end +item: Edit Registry + Total Keys=1 + Key=Python.NoConFile\shell\Edit with IDLE\command + New Value=%MAINDIR%\pythonw.exe %MAINDIR%\Lib\idlelib\idle.pyw -n -e "%%1" +end +item: Edit Registry + Total Keys=1 + Key=Python.File\shell\Edit with IDLE\command + New Value=%MAINDIR%\pythonw.exe %MAINDIR%\Lib\idlelib\idle.pyw -n -e "%%1" +end +item: Else Statement +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.NoConFile\shell\Edit with IDLE\command + New Value=%MAINDIR%\pythonw.exe %MAINDIR%\Lib\idlelib\idle.pyw -n -e "%%1" + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\CLASSES\Python.File\shell\Edit with IDLE\command + New Value=%MAINDIR%\pythonw.exe %MAINDIR%\Lib\idlelib\idle.pyw -n -e "%%1" + Root=1 +end +item: End Block +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Remark + Text=Register Python paths. +end +item: Remark + Text=Write to HKLM for admin, else HKCU. Keep these blocks otherwise identical! +end +item: If/While Statement + Variable=DOADMIN + Value=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\CurrentVersion + Root=130 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\InstallPath + New Value=%MAINDIR% + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\InstallPath\InstallGroup + New Value=%CGROUP_SAVE% + New Value= + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\PythonPath + New Value=%MAINDIR%\Lib;%MAINDIR%\DLLs + New Value= + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\Modules + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe + New Value=%MAINDIR%\Python.exe + Root=2 +end +item: Else Statement +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\CurrentVersion + Root=129 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\InstallPath + New Value=%MAINDIR% + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\InstallPath\InstallGroup + New Value=%CGROUP_SAVE% + New Value= + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\PythonPath + New Value=%MAINDIR%\Lib;%MAINDIR%\DLLs + New Value= + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\Modules + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe + New Value=%MAINDIR%\Python.exe + Root=1 +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Remark + Text=Registry fiddling for docs. +end +item: Remark + Text=Write to HKLM for admin, else HKCU. Keep these blocks otherwise identical! +end +item: If/While Statement + Variable=COMPONENTS + Value=C + Flags=00000010 +end +item: If/While Statement + Variable=DOADMIN + Value=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\Help\Main Python Documentation + New Value=%MAINDIR%\Doc\index.html + Root=2 +end +item: Else Statement +end +item: Edit Registry + Total Keys=1 + Key=Software\Python\PythonCore\%PY_VERSION%\Help\Main Python Documentation + New Value=%MAINDIR%\Doc\index.html + Root=1 +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Remark + Text=Set the app publisher and URL entries for Win2K add/remove. +end +item: Remark + Text=It doesn't hurt on other systems. +end +item: Remark + Text=As usual, write to HKLM or HKCU depending on Admin privs. +end +item: Remark + Text=CAUTION: If you set this info on the "Windows 2000" page (step 6) of the +end +item: Remark + Text=Installation Expert, it only shows up in the "If" block below. Keep in synch! +end +item: If/While Statement + Variable=DOADMIN + Value=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=http://www.python.org/ + Value Name=HelpLink + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=PythonLabs at Zope Corporation + Value Name=Publisher + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=http://www.python.org/ + Value Name=URLInfoAbout + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%PYVER_STRING% + Value Name=DisplayVersion + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%MAINDIR%\py.ico,-0 + Value Name=DisplayIcon + Root=2 +end +item: Else Statement +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=http://www.python.org/ + Value Name=HelpLink + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=PythonLabs at Zope Corporation + Value Name=Publisher + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=http://www.python.org/ + Value Name=URLInfoAbout + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%PYVER_STRING% + Value Name=DisplayVersion + Root=1 +end +item: Edit Registry + Total Keys=1 + Key=Software\Microsoft\Windows\CurrentVersion\Uninstall\%APPTITLE% + New Value=%MAINDIR%\py.ico,-0 + Value Name=DisplayIcon + Root=1 +end +item: End Block +end +item: Remark +end +item: Remark + Text=Populate Start Menu group +end +item: If/While Statement + Variable=TASKS + Value=B + Flags=00000010 +end +item: Remark + Text=Shortcut to installer no matter what. +end +item: Create Shortcut + Source=%MAINDIR%\unwise.exe + Destination=%GROUP%\Uninstall Python.lnk + Working Directory=%MAINDIR% + Key Type=1536 + Flags=00000001 +end +item: Remark +end +item: If/While Statement + Variable=COMPONENTS + Value=A + Flags=00000010 +end +item: Create Shortcut + Source=%MAINDIR%\python.exe + Destination=%GROUP%\Python (command line).lnk + Working Directory=%MAINDIR% + Icon Pathname=%MAINDIR%\pycon.ico + Key Type=1536 + Flags=00000001 +end +item: End Block +end +item: Remark +end +item: If/While Statement + Variable=COMPONENTS + Value=B + Flags=00000010 +end +item: Create Shortcut + Source=%MAINDIR%\pythonw.exe + Destination=%GROUP%\IDLE (Python GUI).lnk + Command Options="%MAINDIR%\Lib\idlelib\idle.pyw" + Working Directory=%MAINDIR% + Key Type=1536 + Flags=00000001 +end +item: Create Shortcut + Source=%MAINDIR%\pythonw.exe + Destination=%GROUP%\Module Docs.lnk + Command Options="%MAINDIR%\Tools\Scripts\pydocgui.pyw" + Working Directory=%MAINDIR% + Key Type=1536 + Flags=00000001 +end +item: End Block +end +item: Remark +end +item: If/While Statement + Variable=COMPONENTS + Value=C + Flags=00000010 +end +item: Create Shortcut + Source=%MAINDIR%\Doc\index.html + Destination=%GROUP%\Python Manuals.lnk + Working Directory=%MAINDIR% + Key Type=1536 + Flags=00000001 +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Remark + Text=I don't think we need this, but have always done it. +end +item: Self-Register OCXs/DLLs + Description=Updating System Configuration, Please Wait... +end +item: Remark +end +remarked item: Remark + Text=Don't enable "Delete in-use files". Here's what happens: +end +remarked item: Remark + Text=Install Python; uninstall Python; install Python again. Reboot the machine. +end +remarked item: Remark + Text=Now UNWISE.EXE is missing. I think this is a Wise bug, but so it goes. +end +remarked item: Add Text to INSTALL.LOG + Text=Delete in-use files: On +end +item: Remark +end +item: Wizard Block + Direction Variable=DIRECTION + Display Variable=DISPLAY + Bitmap Pathname=.\installer.bmp + X Position=9 + Y Position=10 + Filler Color=11173759 + Flags=00000011 +end +item: Custom Dialog Set + Name=Finished + Display Variable=DISPLAY + item: Dialog + Title=%APPTITLE% Installation + Title French=Installation de %APPTITLE% + Title German=Installation von %APPTITLE% + Title Spanish=Instalación de %APPTITLE% + Title Italian=Installazione di %APPTITLE% + Width=339 + Height=280 + Font Name=Helv + Font Size=8 + item: Push Button + Rectangle=188 234 244 253 + Variable=DIRECTION + Value=N + Create Flags=01010000000000010000000000000001 + Text=&Finish + Text French=&Fin + Text German=&Weiter + Text Spanish=&Terminar + Text Italian=&Fine + end + item: Push Button + Rectangle=264 234 320 253 + Variable=DISABLED + Value=! + Action=3 + Create Flags=01010000000000010000000000000000 + Text=&Cancel + Text French=&Annuler + Text German=&Abbrechen + Text Spanish=&Cancelar + Text Italian=&Annulla + end + item: Static + Rectangle=108 10 323 48 + Create Flags=01010000000000000000000000000000 + Flags=0000000000000001 + Name=Times New Roman + Font Style=-24 0 0 0 700 255 0 0 0 3 2 1 18 + Text=Installation Completed! + Text French=Installation terminée ! + Text German=Die Installation ist abgeschlossen! + Text Spanish=¡Instalación terminada! + Text Italian=Installazione completata! + end + item: Static + Rectangle=108 44 320 82 + Create Flags=01010000000000000000000000000000 + Text=%APPTITLE% has been successfully installed. + Text= + Text=Press the Finish button to exit this installation. + Text French=%APPTITLE% est maintenant installé. + Text French= + Text French=Cliquez sur le bouton Fin pour quitter l'installation. + Text German=%APPTITLE% wurde erfolgreich installiert. + Text German= + Text German=Klicken Sie auf "Weiter", um die Installation zu beenden. + Text Spanish=%APPTITLE% se ha instalado con éxito. + Text Spanish= + Text Spanish=Presione el botón Terminar para salir de esta instalación. + Text Italian=L'installazione %APPTITLE% è stata portata a termine con successo. + Text Italian= + Text Italian=Premere il pulsante Fine per uscire dall'installazione. + end + item: Static + Rectangle=10 225 320 226 + Action=3 + Create Flags=01010000000000000000000000000111 + end + item: Static + Rectangle=106 105 312 210 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000000000 + Text=Special Windows thanks to: + Text= + Text=Wise Solutions, for the use of InstallMaster 8.1. + Text= http://www.wisesolutions.com/ + Text= + Text= + Text=LettError, Erik van Blokland, for the Python for Windows graphic. + Text= http://www.letterror.com/ + Text= + Text= + Text=Mark Hammond, without whose years of freely shared Windows expertise, Python for Windows would still be Python for DOS. + end + item: Static + Rectangle=106 95 312 96 + Action=3 + Enabled Color=00000000000000001111111111111111 + Create Flags=01010000000000000000000000001001 + end + end +end +item: End Block +end +item: New Event + Name=Cancel +end +item: Remark + Text=This include script supports a rollback to preinstallation state if the user chooses to cancel before the installation is complete. +end +item: Include Script + Pathname=%_WISE_%\INCLUDE\rollback.wse +end diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/pythoncore.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/pythoncore.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,826 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/pythonw.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/pythonw.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,261 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/readme.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/readme.txt Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,337 @@ +Building Python using VC++ 7.1 +------------------------------------- +This directory is used to build Python for Win32 platforms, e.g. Windows +95, 98 and NT. It requires Microsoft Visual C++ 7.1 +(a.k.a. Visual Studio .NET 2003). +(For other Windows platforms and compilers, see ../PC/readme.txt.) + +All you need to do is open the workspace "pcbuild.sln" in MSVC++, select +the Debug or Release setting (using "Solution Configuration" from +the "Standard" toolbar"), and build the projects. + +The proper order to build subprojects: + +1) pythoncore (this builds the main Python DLL and library files, + python34.{dll, lib} in Release mode) + NOTE: in previous releases, this subproject was + named after the release number, e.g. python20. + +2) python (this builds the main Python executable, + python.exe in Release mode) + +3) the other subprojects, as desired or needed (note: you probably don't + want to build most of the other subprojects, unless you're building an + entire Python distribution from scratch, or specifically making changes + to the subsystems they implement, or are running a Python core buildbot + test slave; see SUBPROJECTS below) + +When using the Debug setting, the output files have a _d added to +their name: python34_d.dll, python_d.exe, parser_d.pyd, and so on. + +SUBPROJECTS +----------- +These subprojects should build out of the box. Subprojects other than the +main ones (pythoncore, python, pythonw) generally build a DLL (renamed to +.pyd) from a specific module so that users don't have to load the code +supporting that module unless they import the module. + +pythoncore + .dll and .lib +python + .exe +pythonw + pythonw.exe, a variant of python.exe that doesn't pop up a DOS box +_socket + socketmodule.c +_testcapi + tests of the Python C API, run via Lib/test/test_capi.py, and + implemented by module Modules/_testcapimodule.c +pyexpat + Python wrapper for accelerated XML parsing, which incorporates stable + code from the Expat project: http://sourceforge.net/projects/expat/ +select + selectmodule.c +unicodedata + large tables of Unicode data +winsound + play sounds (typically .wav files) under Windows + +The following subprojects will generally NOT build out of the box. They +wrap code Python doesn't control, and you'll need to download the base +packages first and unpack them into siblings of PC's parent +directory; for example, if this directory is ....\dist\trunk\PC\VS7.1, +unpack into new subdirectories of dist\. + +_tkinter + Python wrapper for the Tk windowing system. Requires building + Tcl/Tk first. Following are instructions for Tcl/Tk 8.4.12. + + Get source + ---------- + In the dist directory, run + svn export http://svn.python.org/projects/external/tcl8.4.12 + svn export http://svn.python.org/projects/external/tk8.4.12 + svn export http://svn.python.org/projects/external/tix-8.4.0 + + Build Tcl first (done here w/ MSVC 7.1 on Windows XP) + --------------- + Use "Start -> All Programs -> Microsoft Visual Studio .NET 2003 + -> Visual Studio .NET Tools -> Visual Studio .NET 2003 Command Prompt" + to get a shell window with the correct environment settings + cd dist\tcl8.4.12\win + nmake -f makefile.vc + nmake -f makefile.vc INSTALLDIR=..\..\tcltk install + + XXX Should we compile with OPTS=threads? + + Optional: run tests, via + nmake -f makefile.vc test + + On WinXP Pro, wholly up to date as of 30-Aug-2004: + all.tcl: Total 10678 Passed 9969 Skipped 709 Failed 0 + Sourced 129 Test Files. + + Build Tk + -------- + cd dist\tk8.4.12\win + nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 + nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 INSTALLDIR=..\..\tcltk install + + XXX Should we compile with OPTS=threads? + + XXX Our installer copies a lot of stuff out of the Tcl/Tk install + XXX directory. Is all of that really needed for Python use of Tcl/Tk? + + Optional: run tests, via + nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 test + + On WinXP Pro, wholly up to date as of 30-Aug-2004: + all.tcl: Total 8420 Passed 6826 Skipped 1581 Failed 13 + Sourced 91 Test Files. + Files with failing tests: canvImg.test scrollbar.test textWind.test winWm.test + + Built Tix + --------- + cd dist\tix-8.4.0\win + nmake -f python.mak + nmake -f python.mak install + +bz2 + Python wrapper for the libbz2 compression library. Homepage + http://sources.redhat.com/bzip2/ + Download the source from the python.org copy into the dist + directory: + + svn export http://svn.python.org/projects/external/bzip2-1.0.3 + + A custom pre-link step in the bz2 project settings should manage to + build bzip2-1.0.3\libbz2.lib by magic before bz2.pyd (or bz2_d.pyd) is + linked in VS7.1\. + However, the bz2 project is not smart enough to remove anything under + bzip2-1.0.3\ when you do a clean, so if you want to rebuild bzip2.lib + you need to clean up bzip2-1.0.3\ by hand. + + The build step shouldn't yield any warnings or errors, and should end + by displaying 6 blocks each terminated with + FC: no differences encountered + + All of this managed to build bzip2-1.0.3\libbz2.lib, which the Python + project links in. + +_sqlite3 + Python wrapper for SQLite library. + + Get the source code through + + svn export http://svn.python.org/projects/external/sqlite-source-3.3.4 + + To use the extension module in a Python build tree, copy sqlite3.dll into + the VS7.1 folder. + +_ssl + Python wrapper for the secure sockets library. + + Get the source code through + + svn export http://svn.python.org/projects/external/openssl-0.9.8a + + Alternatively, get the latest version from http://www.openssl.org. + You can (theoretically) use any version of OpenSSL you like - the + build process will automatically select the latest version. + + You must also install ActivePerl from + http://www.activestate.com/Products/ActivePerl/ + as this is used by the OpenSSL build process. Complain to them . + + The MSVC project simply invokes build_ssl.py to perform + the build. This Python script locates and builds your OpenSSL + installation, then invokes a simple makefile to build the final .pyd. + + build_ssl.py attempts to catch the most common errors (such as not + being able to find OpenSSL sources, or not being able to find a Perl + that works with OpenSSL) and give a reasonable error message. + If you have a problem that doesn't seem to be handled correctly + (eg, you know you have ActivePerl but we can't find it), please take + a peek at build_ssl.py and suggest patches. Note that build_ssl.py + should be able to be run directly from the command-line. + + build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do + this by hand. + +Building for Itanium +-------------------- + +The project files support a ReleaseItanium configuration which creates +Win64/Itanium binaries. For this to work, you need to install the Platform +SDK, in particular the 64-bit support. This includes an Itanium compiler +(future releases of the SDK likely include an AMD64 compiler as well). +In addition, you need the Visual Studio plugin for external C compilers, +from http://sf.net/projects/vsextcomp. The plugin will wrap cl.exe, to +locate the proper target compiler, and convert compiler options +accordingly. The project files require atleast version 0.9. + +Building for AMD64 +------------------ + +The build process for the ReleaseAMD64 configuration is very similar +to the Itanium configuration; make sure you use the latest version of +vsextcomp. + +Building Python Using the free MS Toolkit Compiler +-------------------------------------------------- + +The build process for Visual C++ can be used almost unchanged with the free MS +Toolkit Compiler. This provides a way of building Python using freely +available software. + +Note that Microsoft have withdrawn the free MS Toolkit Compiler, so this can +no longer be considered a supported option. The instructions are still +correct, but you need to already have a copy of the compiler in order to use +them. Microsoft now supply Visual C++ 2008 Express Edition for free, but this +is NOT compatible with Visual C++ 7.1 (it uses a different C runtime), and so +cannot be used to build a version of Python compatible with the standard +python.org build. If you are interested in using Visual C++ 2008 Express +Edition, however, you should look at the PCBuild directory. + +Requirements + + To build Python, the following tools are required: + + * The Visual C++ Toolkit Compiler + no longer available for download - see above + * A recent Platform SDK + from http://www.microsoft.com/downloads/details.aspx?FamilyID=484269e2-3b89-47e3-8eb7-1f2be6d7123a + * The .NET 1.1 SDK + from http://www.microsoft.com/downloads/details.aspx?FamilyID=9b3a2ca6-3647-4070-9f41-a333c6b9181d + + [Does anyone have better URLs for the last 2 of these?] + + The toolkit compiler is needed as it is an optimising compiler (the + compiler supplied with the .NET SDK is a non-optimising version). The + platform SDK is needed to provide the Windows header files and libraries + (the Windows 2003 Server SP1 edition, typical install, is known to work - + other configurations or versions are probably fine as well). The .NET 1.1 + SDK is needed because it contains a version of msvcrt.dll which links to + the msvcr71.dll CRT. Note that the .NET 2.0 SDK is NOT acceptable, as it + references msvcr80.dll. + + All of the above items should be installed as normal. + + If you intend to build the openssl (needed for the _ssl extension) you + will need the C runtime sources installed as part of the platform SDK. + + In addition, you will need Nant, available from + http://nant.sourceforge.net. The 0.85 release candidate 3 version is known + to work. This is the latest released version at the time of writing. Later + "nightly build" versions are known NOT to work - it is not clear at + present whether future released versions will work. + +Setting up the environment + + Start a platform SDK "build environment window" from the start menu. The + "Windows XP 32-bit retail" version is known to work. + + Add the following directories to your PATH: + * The toolkit compiler directory + * The SDK "Win64" binaries directory + * The Nant directory + Add to your INCLUDE environment variable: + * The toolkit compiler INCLUDE directory + Add to your LIB environment variable: + * The toolkit compiler LIB directory + * The .NET SDK Visual Studio 2003 VC7\lib directory + + The following commands should set things up as you need them: + + rem Set these values according to where you installed the software + set TOOLKIT=C:\Program Files\Microsoft Visual C++ Toolkit 2003 + set SDK=C:\Program Files\Microsoft Platform SDK + set NET=C:\Program Files\Microsoft Visual Studio .NET 2003 + set NANT=C:\Utils\Nant + + set PATH=%TOOLKIT%\bin;%PATH%;%SDK%\Bin\win64;%NANT%\bin + set INCLUDE=%TOOLKIT%\include;%INCLUDE% + set LIB=%TOOLKIT%\lib;%NET%\VC7\lib;%LIB% + + The "win64" directory from the SDK is added to supply executables such as + "cvtres" and "lib", which are not available elsewhere. The versions in the + "win64" directory are 32-bit programs, so they are fine to use here. + + That's it. To build Python (the core only, no binary extensions which + depend on external libraries) you just need to issue the command + + nant -buildfile:python.build all + + from within the VS7.1 directory. + +Extension modules + + To build those extension modules which require external libraries + (_tkinter, bz2, _sqlite3, _ssl) you can follow the instructions + for the Visual Studio build above, with a few minor modifications. These + instructions have only been tested using the sources in the Python + subversion repository - building from original sources should work, but + has not been tested. + + For each extension module you wish to build, you should remove the + associated include line from the excludeprojects section of pc.build. + + The changes required are: + + _tkinter + The tix makefile (tix-8.4.0\win\makefile.vc) must be modified to + remove references to TOOLS32. The relevant lines should be changed to + read: + cc32 = cl.exe + link32 = link.exe + include32 = + The remainder of the build instructions will work as given. + + bz2 + No changes are needed + + _sqlite3 + No changes are needed. However, in order for the tests to succeed, a + copy of sqlite3.dll must be downloaded, and placed alongside + python.exe. + + _ssl + The documented build process works as written. However, it needs a + copy of the file setargv.obj, which is not supplied in the platform + SDK. However, the sources are available (in the crt source code). To + build setargv.obj, proceed as follows: + + Copy setargv.c, cruntime.h and internal.h from %SDK%\src\crt to a + temporary directory. + Compile using "cl /c /I. /MD /D_CRTBLD setargv.c" + Copy the resulting setargv.obj to somewhere on your LIB environment + (%SDK%\lib is a reasonable place). + + With setargv.obj in place, the standard build process should work + fine. + +YOUR OWN EXTENSION DLLs +----------------------- +If you want to create your own extension module DLL, there's an example +with easy-to-follow instructions in ../PC/example/; read the file +readme.txt there first. diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/rmpyc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/rmpyc.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,25 @@ +# Remove all the .pyc and .pyo files under ../Lib. + + +def deltree(root): + import os + from os.path import join + + npyc = npyo = 0 + for root, dirs, files in os.walk(root): + for name in files: + delete = False + if name.endswith('.pyc'): + delete = True + npyc += 1 + elif name.endswith('.pyo'): + delete = True + npyo += 1 + + if delete: + os.remove(join(root, name)) + + return npyc, npyo + +npyc, npyo = deltree("../Lib") +print npyc, ".pyc deleted,", npyo, ".pyo deleted" diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/rt.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/rt.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,52 @@ +@echo off +rem Run Tests. Run the regression test suite. +rem Usage: rt [-d] [-O] [-q] regrtest_args +rem -d Run Debug build (python_d.exe). Else release build. +rem -O Run python.exe or python_d.exe (see -d) with -O. +rem -q "quick" -- normally the tests are run twice, the first time +rem after deleting all the .py[co] files reachable from Lib/. +rem -q runs the tests just once, and without deleting .py[co] files. +rem All leading instances of these switches are shifted off, and +rem whatever remains is passed to regrtest.py. For example, +rem rt -O -d -x test_thread +rem runs +rem python_d -O ../../lib/test/regrtest.py -x test_thread +rem twice, and +rem rt -q -g test_binascii +rem runs +rem python_d ../../lib/test/regrtest.py -g test_binascii +rem to generate the expected-output file for binascii quickly. +rem +rem Confusing: if you want to pass a comma-separated list, like +rem -u network,largefile +rem then you have to quote it on the rt line, like +rem rt -u "network,largefile" + +setlocal + +set exe=python +set qmode= +set dashO= +PATH %PATH%;%~dp0..\..\..\tcltk\bin + +:CheckOpts +if "%1"=="-O" (set dashO=-O) & shift & goto CheckOpts +if "%1"=="-q" (set qmode=yes) & shift & goto CheckOpts +if "%1"=="-d" (set exe=python_d) & shift & goto CheckOpts + +set cmd=%exe% %dashO% -E ../../lib/test/regrtest.py %1 %2 %3 %4 %5 %6 %7 %8 %9 +if defined qmode goto Qmode + +echo Deleting .pyc/.pyo files ... +%exe% rmpyc.py + +echo on +%cmd% +@echo off + +echo About to run again without deleting .pyc/.pyo first: +pause + +:Qmode +echo on +%cmd% diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/select.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/select.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/unicodedata.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/unicodedata.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS7.1/winsound.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS7.1/winsound.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_ctypes.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_ctypes.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,705 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_ctypes_test.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_ctypes_test.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,521 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_elementtree.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_elementtree.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,613 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_hashlib.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_hashlib.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_msi.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_msi.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,529 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_multiprocessing.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_multiprocessing.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,545 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_socket.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_socket.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_sqlite3.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_sqlite3.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,613 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_ssl.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_ssl.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_testcapi.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_testcapi.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,521 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/_tkinter.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/_tkinter.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,541 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/bdist_wininst.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/bdist_wininst.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/build.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/build.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,17 @@ +@echo off +rem A batch program to build or rebuild a particular configuration. +rem just for convenience. + +setlocal +set platf=Win32 +set conf=Release +set build=/build + +:CheckOpts +if "%1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts +if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts +if "%1"=="-r" (set build=/rebuild) & shift & goto CheckOpts + +set cmd=devenv pcbuild.sln %build% "%conf%|%platf%" +echo %cmd% +%cmd% diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/build_env.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/build_env.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,1 @@ +@%comspec% /k env.bat %* diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/build_pgo.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/build_pgo.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,41 @@ +@echo off +rem A batch program to build PGO (Profile guided optimization) by first +rem building instrumented binaries, then running the testsuite, and +rem finally building the optimized code. +rem Note, after the first instrumented run, one can just keep on +rem building the PGUpdate configuration while developing. + +setlocal +set platf=Win32 + +rem use the performance testsuite. This is quick and simple +set job1=..\..\tools\pybench\pybench.py -n 1 -C 1 --with-gc +set path1=..\..\tools\pybench + +rem or the whole testsuite for more thorough testing +set job2=..\..\lib\test\regrtest.py +set path2=..\..\lib + +set job=%job1% +set clrpath=%path1% + +:CheckOpts +if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts +if "%1"=="-2" (set job=%job2%) & (set clrpath=%path2%) & shift & goto CheckOpts + +set PGI=%platf%-pgi +set PGO=%platf%-pgo + +@echo on +rem build the instrumented version +call build -p %platf% -c PGInstrument + +rem remove .pyc files, .pgc files and execute the job +%PGI%\python.exe rmpyc.py %clrpath% +del %PGI%\*.pgc +%PGI%\python.exe %job% + +rem finally build the optimized version +if exist %PGO% del /s /q %PGO% +call build -p %platf% -c PGUpdate + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/build_ssl.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/build_ssl.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,12 @@ +@echo off +if not defined HOST_PYTHON ( + if %1 EQU Debug ( + set HOST_PYTHON=python_d.exe + if not exist python34_d.dll exit 1 + ) ELSE ( + set HOST_PYTHON=python.exe + if not exist python34.dll exit 1 + ) +) +%HOST_PYTHON% build_ssl.py %1 %2 %3 + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/build_ssl.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/build_ssl.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,277 @@ +# Script for building the _ssl and _hashlib modules for Windows. +# Uses Perl to setup the OpenSSL environment correctly +# and build OpenSSL, then invokes a simple nmake session +# for the actual _ssl.pyd and _hashlib.pyd DLLs. + +# THEORETICALLY, you can: +# * Unpack the latest SSL release one level above your main Python source +# directory. It is likely you will already find the zlib library and +# any other external packages there. +# * Install ActivePerl and ensure it is somewhere on your path. +# * Run this script from the PC/VS8.0 directory. +# +# it should configure and build SSL, then build the _ssl and _hashlib +# Python extensions without intervention. + +# Modified by Christian Heimes +# Now this script supports pre-generated makefiles and assembly files. +# Developers don't need an installation of Perl anymore to build Python. A svn +# checkout from our svn repository is enough. +# +# In Order to create the files in the case of an update you still need Perl. +# Run build_ssl in this order: +# python.exe build_ssl.py Release x64 +# python.exe build_ssl.py Release Win32 + +import os, sys, re, shutil + +# 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: + fh = os.popen('"%s" -e "use Win32;"' % perl) + fh.read() + rc = fh.close() + if rc: + continue + return perl + print("Can not find a suitable 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") + return None + +# Locate the best SSL directory given a few roots to look into. +def find_best_ssl_dir(sources): + candidates = [] + for s in sources: + try: + # note: do not abspath s; the build will fail if any + # higher up directory name has spaces in it. + fnames = os.listdir(s) + except OSError: + fnames = [] + for fname in fnames: + fqn = os.path.join(s, fname) + if os.path.isdir(fqn) and fname.startswith("openssl-"): + candidates.append(fqn) + # Now we have all the candidates, locate the best. + best_parts = [] + best_name = None + for c in candidates: + parts = re.split("[.-]", os.path.basename(c))[1:] + # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers + if len(parts) >= 4: + continue + if parts > best_parts: + best_parts = parts + best_name = c + if best_name is not None: + print("Found an SSL directory at '%s'" % (best_name,)) + else: + print("Could not find an SSL directory in '%s'" % (sources,)) + sys.stdout.flush() + return best_name + +def create_makefile64(makefile, m32): + """Create and fix makefile for 64bit + + Replace 32 with 64bit directories + """ + if not os.path.isfile(m32): + return + with open(m32) as fin: + with open(makefile, 'w') as fout: + for line in fin: + line = line.replace("=tmp32", "=tmp64") + line = line.replace("=out32", "=out64") + line = line.replace("=inc32", "=inc64") + # force 64 bit machine + line = line.replace("MKLIB=lib", "MKLIB=lib /MACHINE:X64") + line = line.replace("LFLAGS=", "LFLAGS=/MACHINE:X64 ") + # don't link against the lib on 64bit systems + line = line.replace("bufferoverflowu.lib", "") + fout.write(line) + os.unlink(m32) + +def fix_makefile(makefile): + """Fix some stuff in all makefiles + """ + if not os.path.isfile(makefile): + return + with open(makefile) as fin: + lines = fin.readlines() + with open(makefile, 'w') as fout: + for line in lines: + if line.startswith("PERL="): + continue + if line.startswith("CP="): + line = "CP=copy\n" + if line.startswith("MKDIR="): + line = "MKDIR=mkdir\n" + if line.startswith("CFLAG="): + line = line.strip() + for algo in ("RC5", "MDC2", "IDEA"): + noalgo = " -DOPENSSL_NO_%s" % algo + if noalgo not in line: + line = line + noalgo + line = line + '\n' + fout.write(line) + +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 cmp(f1, f2): + bufsize = 1024 * 8 + with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2: + while True: + b1 = fp1.read(bufsize) + b2 = fp2.read(bufsize) + if b1 != b2: + return False + if not b1: + return True + +def copy(src, dst): + if os.path.isfile(dst) and cmp(src, dst): + return + shutil.copy(src, dst) + +def main(): + build_all = "-a" in sys.argv + if sys.argv[1] == "Release": + debug = False + elif sys.argv[1] == "Debug": + debug = True + else: + raise ValueError(str(sys.argv)) + + if sys.argv[2] == "Win32": + arch = "x86" + configure = "VC-WIN32" + do_script = "ms\\do_nasm" + makefile="ms\\nt.mak" + m32 = makefile + dirsuffix = "32" + elif sys.argv[2] == "x64": + arch="amd64" + configure = "VC-WIN64A" + do_script = "ms\\do_win64a" + makefile = "ms\\nt64.mak" + m32 = makefile.replace('64', '') + dirsuffix = "64" + #os.environ["VSEXTCOMP_USECL"] = "MS_OPTERON" + else: + raise ValueError(str(sys.argv)) + + make_flags = "" + if build_all: + make_flags = "-a" + # 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", ["\\perl\\bin", "C:\\perl\\bin"]) + perl = find_working_perl(perls) + if perl: + print("Found a working perl at '%s'" % (perl,)) + else: + print("No Perl installation was found. Existing Makefiles are used.") + sys.stdout.flush() + # Look for SSL 3 levels up from PC/VS8.0 - ie, same place zlib etc all live. + ssl_dir = find_best_ssl_dir(("..\\..\\..",)) + if ssl_dir is None: + sys.exit(1) + + old_cd = os.getcwd() + try: + os.chdir(ssl_dir) + # rebuild makefile when we do the role over from 32 to 64 build + if arch == "amd64" and os.path.isfile(m32) and not os.path.isfile(makefile): + os.unlink(m32) + + # If the ssl makefiles do not exist, we invoke Perl to generate them. + # Due to a bug in this script, the makefile sometimes ended up empty + # Force a regeneration if it is. + if not os.path.isfile(makefile) or os.path.getsize(makefile)==0: + if perl is None: + print("Perl is required to build the makefiles!") + sys.exit(1) + + print("Creating the makefiles...") + 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"] + run_configure(configure, do_script) + if debug: + print("OpenSSL debug builds aren't supported.") + #if arch=="x86" and debug: + # # the do_masm script in openssl doesn't generate a debug + # # build makefile so we generate it here: + # os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile) + + if arch == "amd64": + create_makefile64(makefile, m32) + fix_makefile(makefile) + copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch) + copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch) + + # If the assembler files don't exist in tmpXX, copy them there + if perl is None and os.path.exists("asm"+dirsuffix): + if not os.path.exists("tmp"+dirsuffix): + os.mkdir("tmp"+dirsuffix) + for f in os.listdir("asm"+dirsuffix): + if not f.endswith(".asm"): continue + if os.path.isfile(r"tmp%s\%s" % (dirsuffix, f)): continue + shutil.copy(r"asm%s\%s" % (dirsuffix, f), "tmp"+dirsuffix) + + # Now run make. + if arch == "amd64": + rc = os.system("ml64 -c -Foms\\uptable.obj ms\\uptable.asm") + if rc: + print("ml64 assembler has failed.") + sys.exit(rc) + + copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h") + copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h") + + #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile) + makeCommand = "nmake /nologo -f \"%s\"" % makefile + print("Executing ssl makefiles:", makeCommand) + sys.stdout.flush() + rc = os.system(makeCommand) + if rc: + print("Executing "+makefile+" failed") + print(rc) + sys.exit(rc) + finally: + os.chdir(old_cd) + sys.exit(rc) + +if __name__=='__main__': + main() diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/build_tkinter.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/build_tkinter.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,85 @@ +"""Script to compile the dependencies of _tkinter + +Copyright (c) 2007 by Christian Heimes + +Licensed to PSF under a Contributor Agreement. +""" + +import os +import sys + +here = os.path.abspath(os.path.dirname(__file__)) +par = os.path.pardir + +if 1: + TCL = "tcl8.4.16" + TK = "tk8.4.16" + TIX = "tix-8.4.0" +else: + TCL = "tcl8.5b3" + TK = "tcl8.5b3" + TIX = "Tix8.4.2" + +ROOT = os.path.abspath(os.path.join(here, par, par, par)) +# Windows 2000 compatibility: WINVER 0x0500 +# http://msdn2.microsoft.com/en-us/library/aa383745.aspx +NMAKE = "nmake /nologo /f %s COMPILERFLAGS=-DWINVER=0x0500 %s %s" + +def nmake(makefile, command="", **kw): + defines = ' '.join(k+'='+v for k, v in kw.items()) + cmd = NMAKE % (makefile, defines, command) + print("\n\n"+cmd+"\n") + if os.system(cmd) != 0: + raise RuntimeError(cmd) + +def build(platform, clean): + if platform == "Win32": + dest = os.path.join(ROOT, "tcltk") + machine = "X86" + elif platform == "x64": + dest = os.path.join(ROOT, "tcltk64") + machine = "X64" + else: + raise ValueError(platform) + + # TCL + tcldir = os.path.join(ROOT, TCL) + if 1: + os.chdir(os.path.join(tcldir, "win")) + if clean: + nmake("makefile.vc", "clean") + nmake("makefile.vc") + nmake("makefile.vc", "install", INSTALLDIR=dest) + + # TK + if 1: + os.chdir(os.path.join(ROOT, TK, "win")) + if clean: + nmake("makefile.vc", "clean", TCLDIR=tcldir) + nmake("makefile.vc", TCLDIR=tcldir) + nmake("makefile.vc", "install", TCLDIR=tcldir, INSTALLDIR=dest) + + # TIX + if 1: + # python9.mak is available at http://svn.python.org + os.chdir(os.path.join(ROOT, TIX, "win")) + if clean: + nmake("python9.mak", "clean") + nmake("python9.mak", MACHINE=machine) + nmake("python9.mak", "install") + +def main(): + if len(sys.argv) < 2 or sys.argv[1] not in ("Win32", "x64"): + print("%s Win32|x64" % sys.argv[0]) + sys.exit(1) + + if "-c" in sys.argv: + clean = True + else: + clean = False + + build(sys.argv[1], clean) + + +if __name__ == '__main__': + main() diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/bz2.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/bz2.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,581 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/debug.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/debug.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,15 @@ + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/env.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/env.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,5 @@ +@echo off +set VS8=%ProgramFiles%\Microsoft Visual Studio 8 +echo Build environments: x86, ia64, amd64, x86_amd64, x86_ia64 +echo. +call "%VS8%\VC\vcvarsall.bat" %1 diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/field3.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/field3.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,35 @@ +# An absurd workaround for the lack of arithmetic in MS's resource compiler. +# After building Python, run this, then paste the output into the appropriate +# part of PC\python_nt.rc. +# Example output: +# +# * For 2.3a0, +# * PY_MICRO_VERSION = 0 +# * PY_RELEASE_LEVEL = 'alpha' = 0xA +# * PY_RELEASE_SERIAL = 1 +# * +# * and 0*1000 + 10*10 + 1 = 101. +# */ +# #define FIELD3 101 + +import sys + +major, minor, micro, level, serial = sys.version_info +levelnum = {'alpha': 0xA, + 'beta': 0xB, + 'candidate': 0xC, + 'final': 0xF, + }[level] +string = sys.version.split()[0] # like '2.3a0' + +print(" * For %s," % string) +print(" * PY_MICRO_VERSION = %d" % micro) +print(" * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum))) +print(" * PY_RELEASE_SERIAL = %d" % serial) +print(" *") + +field3 = micro * 1000 + levelnum * 10 + serial + +print(" * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3)) +print(" */") +print("#define FIELD3", field3) diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/idle.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/idle.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,15 @@ +@echo off +rem start idle +rem Usage: idle [-d] +rem -d Run Debug build (python_d.exe). Else release build. + +setlocal +set exe=python +PATH %PATH%;..\..\..\tcltk\bin + +if "%1"=="-d" (set exe=python_d) & shift + +set cmd=%exe% ../../Lib/idlelib/idle.py %1 %2 %3 %4 %5 %6 %7 %8 %9 + +echo on +%cmd% diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/kill_python.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/kill_python.c Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,178 @@ +/* + * Helper program for killing lingering python[_d].exe processes before + * building, thus attempting to avoid build failures due to files being + * locked. + */ + +#include +#include +#include +#include + +#pragma comment(lib, "psapi") + +#ifdef _DEBUG +#define PYTHON_EXE (L"python_d.exe") +#define PYTHON_EXE_LEN (12) +#define KILL_PYTHON_EXE (L"kill_python_d.exe") +#define KILL_PYTHON_EXE_LEN (17) +#else +#define PYTHON_EXE (L"python.exe") +#define PYTHON_EXE_LEN (10) +#define KILL_PYTHON_EXE (L"kill_python.exe") +#define KILL_PYTHON_EXE_LEN (15) +#endif + +int +main(int argc, char **argv) +{ + HANDLE hp, hsp, hsm; /* process, snapshot processes, snapshot modules */ + DWORD dac, our_pid; + size_t len; + wchar_t path[MAX_PATH+1]; + + MODULEENTRY32W me; + PROCESSENTRY32W pe; + + me.dwSize = sizeof(MODULEENTRY32W); + pe.dwSize = sizeof(PROCESSENTRY32W); + + memset(path, 0, MAX_PATH+1); + + our_pid = GetCurrentProcessId(); + + hsm = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, our_pid); + if (hsm == INVALID_HANDLE_VALUE) { + printf("CreateToolhelp32Snapshot[1] failed: %d\n", GetLastError()); + return 1; + } + + if (!Module32FirstW(hsm, &me)) { + printf("Module32FirstW[1] failed: %d\n", GetLastError()); + CloseHandle(hsm); + return 1; + } + + /* + * Enumerate over the modules for the current process in order to find + * kill_process[_d].exe, then take a note of the directory it lives in. + */ + do { + if (_wcsnicmp(me.szModule, KILL_PYTHON_EXE, KILL_PYTHON_EXE_LEN)) + continue; + + len = wcsnlen_s(me.szExePath, MAX_PATH) - KILL_PYTHON_EXE_LEN; + wcsncpy_s(path, MAX_PATH+1, me.szExePath, len); + + break; + + } while (Module32NextW(hsm, &me)); + + CloseHandle(hsm); + + if (path == NULL) { + printf("failed to discern directory of running process\n"); + return 1; + } + + /* + * Take a snapshot of system processes. Enumerate over the snapshot, + * looking for python processes. When we find one, verify it lives + * in the same directory we live in. If it does, kill it. If we're + * unable to kill it, treat this as a fatal error and return 1. + * + * The rationale behind this is that we're called at the start of the + * build process on the basis that we'll take care of killing any + * running instances, such that the build won't encounter permission + * denied errors during linking. If we can't kill one of the processes, + * we can't provide this assurance, and the build shouldn't start. + */ + + hsp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hsp == INVALID_HANDLE_VALUE) { + printf("CreateToolhelp32Snapshot[2] failed: %d\n", GetLastError()); + return 1; + } + + if (!Process32FirstW(hsp, &pe)) { + printf("Process32FirstW failed: %d\n", GetLastError()); + CloseHandle(hsp); + return 1; + } + + dac = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE; + do { + + /* + * XXX TODO: if we really wanted to be fancy, we could check the + * modules for all processes (not just the python[_d].exe ones) + * and see if any of our DLLs are loaded (i.e. python34[_d].dll), + * as that would also inhibit our ability to rebuild the solution. + * Not worth loosing sleep over though; for now, a simple check + * for just the python executable should be sufficient. + */ + + if (_wcsnicmp(pe.szExeFile, PYTHON_EXE, PYTHON_EXE_LEN)) + /* This isn't a python process. */ + continue; + + /* It's a python process, so figure out which directory it's in... */ + hsm = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe.th32ProcessID); + if (hsm == INVALID_HANDLE_VALUE) + /* + * If our module snapshot fails (which will happen if we don't own + * the process), just ignore it and continue. (It seems different + * versions of Windows return different values for GetLastError() + * in this situation; it's easier to just ignore it and move on vs. + * stopping the build for what could be a false positive.) + */ + continue; + + if (!Module32FirstW(hsm, &me)) { + printf("Module32FirstW[2] failed: %d\n", GetLastError()); + CloseHandle(hsp); + CloseHandle(hsm); + return 1; + } + + do { + if (_wcsnicmp(me.szModule, PYTHON_EXE, PYTHON_EXE_LEN)) + /* Wrong module, we're looking for python[_d].exe... */ + continue; + + if (_wcsnicmp(path, me.szExePath, len)) + /* Process doesn't live in our directory. */ + break; + + /* Python process residing in the right directory, kill it! */ + hp = OpenProcess(dac, FALSE, pe.th32ProcessID); + if (!hp) { + printf("OpenProcess failed: %d\n", GetLastError()); + CloseHandle(hsp); + CloseHandle(hsm); + return 1; + } + + if (!TerminateProcess(hp, 1)) { + printf("TerminateProcess failed: %d\n", GetLastError()); + CloseHandle(hsp); + CloseHandle(hsm); + CloseHandle(hp); + return 1; + } + + CloseHandle(hp); + break; + + } while (Module32NextW(hsm, &me)); + + CloseHandle(hsm); + + } while (Process32NextW(hsp, &pe)); + + CloseHandle(hsp); + + return 0; +} + +/* vi: set ts=8 sw=4 sts=4 expandtab */ diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/kill_python.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/kill_python.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/make_buildinfo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/make_buildinfo.c Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,116 @@ +#include +#include +#include +#include + +#define CMD_SIZE 500 + +/* This file creates the getbuildinfo.o object, by first + invoking subwcrev.exe (if found), and then invoking cl.exe. + As a side effect, it might generate PCBuild\getbuildinfo2.c + also. If this isn't a subversion checkout, or subwcrev isn't + found, it compiles ..\\..\\Modules\\getbuildinfo.c instead. + + Currently, subwcrev.exe is found from the registry entries + of TortoiseSVN. + + No attempt is made to place getbuildinfo.o into the proper + binary directory. This isn't necessary, as this tool is + invoked as a pre-link step for pythoncore, so that overwrites + any previous getbuildinfo.o. + + However, if a second argument is provided, this will be used + as a temporary directory where any getbuildinfo2.c and + getbuildinfo.o files are put. This is useful if multiple + configurations are being built in parallel, to avoid them + trampling each other's files. + +*/ + +int make_buildinfo2(const char *tmppath) +{ + struct _stat st; + HKEY hTortoise; + char command[CMD_SIZE+1]; + DWORD type, size; + if (_stat(".svn", &st) < 0) + return 0; + /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */ + if (_stat("no_subwcrev", &st) == 0) + return 0; + if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS && + RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS) + /* Tortoise not installed */ + return 0; + command[0] = '"'; /* quote the path to the executable */ + size = sizeof(command) - 1; + if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS || + type != REG_SZ) + /* Registry corrupted */ + return 0; + strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe"); + if (_stat(command+1, &st) < 0) + /* subwcrev.exe not part of the release */ + return 0; + strcat_s(command, CMD_SIZE, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c "); + strcat_s(command, CMD_SIZE, tmppath); + strcat_s(command, CMD_SIZE, "getbuildinfo2.c"); + puts(command); fflush(stdout); + if (system(command) < 0) + return 0; + return 1; +} + +int main(int argc, char*argv[]) +{ + char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL "; + char tmppath[CMD_SIZE] = ""; + int do_unlink, result; + char *tmpdir = NULL; + if (argc <= 2 || argc > 3) { + fprintf(stderr, "make_buildinfo $(ConfigurationName) [tmpdir]\n"); + return EXIT_FAILURE; + } + if (strcmp(argv[1], "Release") == 0) { + strcat_s(command, CMD_SIZE, "-MD "); + } + else if (strcmp(argv[1], "Debug") == 0) { + strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd "); + } + else if (strcmp(argv[1], "ReleaseItanium") == 0) { + strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM "); + } + else if (strcmp(argv[1], "ReleaseAMD64") == 0) { + strcat_s(command, CMD_SIZE, "-MD "); + strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON "); + } + else { + fprintf(stderr, "unsupported configuration %s\n", argv[1]); + return EXIT_FAILURE; + } + if (argc > 2) { + tmpdir = argv[2]; + strcat_s(tmppath, _countof(tmppath), tmpdir); + strcat_s(tmppath, _countof(tmppath), "\\"); + } + + if ((do_unlink = make_buildinfo2(tmppath))) { + strcat_s(command, CMD_SIZE, tmppath); + strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV "); + } else + strcat_s(command, CMD_SIZE, "..\\..\\Modules\\getbuildinfo.c"); + strcat_s(command, CMD_SIZE, " -Fo"); + strcat_s(command, CMD_SIZE, tmppath); + strcat_s(command, CMD_SIZE, "getbuildinfo.o -I..\\..\\Include -I..\\..\\PC"); + puts(command); fflush(stdout); + result = system(command); + if (do_unlink) { + command[0] = '\0'; + strcat_s(command, CMD_SIZE, tmppath); + strcat_s(command, CMD_SIZE, "getbuildinfo2.c"); + _unlink(command); + } + if (result < 0) + return EXIT_FAILURE; + return 0; +} diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/make_buildinfo.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/make_buildinfo.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/make_versioninfo.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/make_versioninfo.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pcbuild.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pcbuild.sln Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,555 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "python", "python.vcproj", "{B11D750F-CD1F-4A96-85CE-E69A5C5259F9}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058} = {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_versioninfo", "make_versioninfo.vcproj", "{F0E0541E-F17D-430B-97C4-93ADF0DD284E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore", "pythoncore.vcproj", "{CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}" + ProjectSection(ProjectDependencies) = postProject + {F0E0541E-F17D-430B-97C4-93ADF0DD284E} = {F0E0541E-F17D-430B-97C4-93ADF0DD284E} + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} + {C73F0EC1-358B-4177-940F-0846AC8B04CD} = {C73F0EC1-358B-4177-940F-0846AC8B04CD} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythonw", "pythonw.vcproj", "{F4229CC3-873C-49AE-9729-DD308ED4CD4A}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" + ProjectSection(SolutionItems) = preProject + ..\..\Modules\getbuildinfo.c = ..\..\Modules\getbuildinfo.c + readme.txt = readme.txt + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{28B5D777-DDF2-4B6B-B34F-31D938813856}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes", "_ctypes.vcproj", "{0E9791DB-593A-465F-98BC-681011311618}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes_test", "_ctypes_test.vcproj", "{9EC7190A-249F-4180-A900-548FDCF3055F}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_elementtree", "_elementtree.vcproj", "{17E1E049-C309-4D79-843F-AE483C264AEA}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_msi", "_msi.vcproj", "{31FFC478-7B4A-43E8-9954-8D03E2187E9C}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_socket", "_socket.vcproj", "{86937F53-C189-40EF-8CE8-8759D8E7D480}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sqlite3", "_sqlite3.vcproj", "{13CECB97-4119-4316-9D42-8534019A5A44}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + {A1A295E5-463C-437F-81CA-1F32367685DA} = {A1A295E5-463C-437F-81CA-1F32367685DA} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ssl", "_ssl.vcproj", "{C6E20F84-3247-4AD6-B051-B073268F73BA}" + ProjectSection(ProjectDependencies) = postProject + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} = {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} + {86937F53-C189-40EF-8CE8-8759D8E7D480} = {86937F53-C189-40EF-8CE8-8759D8E7D480} + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0} = {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testcapi", "_testcapi.vcproj", "{6901D91C-6E48-4BB7-9FEC-700C8131DF1D}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_tkinter", "_tkinter.vcproj", "{4946ECAC-2E69-4BF8-A90A-F5136F5094DF}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bz2", "bz2.vcproj", "{73FCD2BD-F133-46B7-8EC1-144CD82A59D5}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "select", "select.vcproj", "{18CAE28C-B454-46C1-87A0-493D91D97F03}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unicodedata", "unicodedata.vcproj", "{ECC7CEAC-A5E5-458E-BB9E-2413CC847881}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pyexpat", "pyexpat.vcproj", "{D06B6426-4762-44CC-8BAD-D79052507F2F}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bdist_wininst", "bdist_wininst.vcproj", "{EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_hashlib", "_hashlib.vcproj", "{447F05A8-F581-4CAC-A466-5AC7936E207E}" + ProjectSection(ProjectDependencies) = postProject + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} = {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0} = {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqlite3", "sqlite3.vcproj", "{A1A295E5-463C-437F-81CA-1F32367685DA}" + ProjectSection(ProjectDependencies) = postProject + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_multiprocessing", "_multiprocessing.vcproj", "{9E48B300-37D1-11DD-8C41-005056C00008}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssl", "ssl.vcproj", "{E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}" + ProjectSection(ProjectDependencies) = postProject + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} = {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kill_python", "kill_python.vcproj", "{6DE10744-E396-40A5-B4E2-1B69AA7C8D31}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + PGInstrument|Win32 = PGInstrument|Win32 + PGInstrument|x64 = PGInstrument|x64 + PGUpdate|Win32 = PGUpdate|Win32 + PGUpdate|x64 = PGUpdate|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|Win32.ActiveCfg = Debug|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|Win32.Build.0 = Debug|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|x64.ActiveCfg = Debug|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|x64.Build.0 = Debug|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|Win32.ActiveCfg = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|Win32.Build.0 = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|x64.ActiveCfg = Release|x64 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|x64.Build.0 = Release|x64 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug|Win32.ActiveCfg = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug|Win32.Build.0 = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug|x64.ActiveCfg = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug|x64.Build.0 = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGInstrument|Win32.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGInstrument|Win32.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGInstrument|x64.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGInstrument|x64.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGUpdate|Win32.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGUpdate|Win32.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGUpdate|x64.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.PGUpdate|x64.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release|Win32.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release|Win32.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release|x64.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release|x64.Build.0 = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|Win32.ActiveCfg = Debug|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|Win32.Build.0 = Debug|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|x64.ActiveCfg = Debug|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|x64.Build.0 = Debug|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|Win32.ActiveCfg = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|Win32.Build.0 = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|x64.ActiveCfg = Release|x64 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|x64.Build.0 = Release|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|Win32.ActiveCfg = Debug|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|Win32.Build.0 = Debug|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|x64.ActiveCfg = Debug|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|x64.Build.0 = Debug|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|Win32.ActiveCfg = Release|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|Win32.Build.0 = Release|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|x64.ActiveCfg = Release|x64 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|x64.Build.0 = Release|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|Win32.ActiveCfg = Debug|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|Win32.Build.0 = Debug|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|x64.ActiveCfg = Debug|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|x64.Build.0 = Debug|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|Win32.ActiveCfg = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|Win32.Build.0 = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|x64.ActiveCfg = Release|x64 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|x64.Build.0 = Release|x64 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|Win32.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|x64.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|x64.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGInstrument|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGInstrument|Win32.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGInstrument|x64.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGInstrument|x64.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGUpdate|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGUpdate|Win32.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGUpdate|x64.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.PGUpdate|x64.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|Win32.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|x64.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|x64.Build.0 = Release|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Debug|Win32.ActiveCfg = Debug|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Debug|Win32.Build.0 = Debug|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Debug|x64.ActiveCfg = Debug|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Debug|x64.Build.0 = Debug|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Release|Win32.ActiveCfg = Release|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Release|Win32.Build.0 = Release|Win32 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Release|x64.ActiveCfg = Release|x64 + {28B5D777-DDF2-4B6B-B34F-31D938813856}.Release|x64.Build.0 = Release|x64 + {0E9791DB-593A-465F-98BC-681011311618}.Debug|Win32.ActiveCfg = Debug|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.Debug|Win32.Build.0 = Debug|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.Debug|x64.ActiveCfg = Debug|x64 + {0E9791DB-593A-465F-98BC-681011311618}.Debug|x64.Build.0 = Debug|x64 + {0E9791DB-593A-465F-98BC-681011311618}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {0E9791DB-593A-465F-98BC-681011311618}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {0E9791DB-593A-465F-98BC-681011311618}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {0E9791DB-593A-465F-98BC-681011311618}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {0E9791DB-593A-465F-98BC-681011311618}.Release|Win32.ActiveCfg = Release|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.Release|Win32.Build.0 = Release|Win32 + {0E9791DB-593A-465F-98BC-681011311618}.Release|x64.ActiveCfg = Release|x64 + {0E9791DB-593A-465F-98BC-681011311618}.Release|x64.Build.0 = Release|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Debug|Win32.ActiveCfg = Debug|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Debug|Win32.Build.0 = Debug|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Debug|x64.ActiveCfg = Debug|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Debug|x64.Build.0 = Debug|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Release|Win32.ActiveCfg = Release|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Release|Win32.Build.0 = Release|Win32 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Release|x64.ActiveCfg = Release|x64 + {9EC7190A-249F-4180-A900-548FDCF3055F}.Release|x64.Build.0 = Release|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Debug|Win32.ActiveCfg = Debug|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Debug|Win32.Build.0 = Debug|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Debug|x64.ActiveCfg = Debug|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Debug|x64.Build.0 = Debug|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Release|Win32.ActiveCfg = Release|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Release|Win32.Build.0 = Release|Win32 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Release|x64.ActiveCfg = Release|x64 + {17E1E049-C309-4D79-843F-AE483C264AEA}.Release|x64.Build.0 = Release|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Debug|Win32.ActiveCfg = Debug|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Debug|Win32.Build.0 = Debug|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Debug|x64.ActiveCfg = Debug|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Debug|x64.Build.0 = Debug|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Release|Win32.ActiveCfg = Release|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Release|Win32.Build.0 = Release|Win32 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Release|x64.ActiveCfg = Release|x64 + {31FFC478-7B4A-43E8-9954-8D03E2187E9C}.Release|x64.Build.0 = Release|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Debug|Win32.ActiveCfg = Debug|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Debug|Win32.Build.0 = Debug|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Debug|x64.ActiveCfg = Debug|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Debug|x64.Build.0 = Debug|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Release|Win32.ActiveCfg = Release|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Release|Win32.Build.0 = Release|Win32 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Release|x64.ActiveCfg = Release|x64 + {86937F53-C189-40EF-8CE8-8759D8E7D480}.Release|x64.Build.0 = Release|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.Debug|Win32.ActiveCfg = Debug|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.Debug|Win32.Build.0 = Debug|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.Debug|x64.ActiveCfg = Debug|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.Debug|x64.Build.0 = Debug|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.Release|Win32.ActiveCfg = Release|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.Release|Win32.Build.0 = Release|Win32 + {13CECB97-4119-4316-9D42-8534019A5A44}.Release|x64.ActiveCfg = Release|x64 + {13CECB97-4119-4316-9D42-8534019A5A44}.Release|x64.Build.0 = Release|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Debug|Win32.ActiveCfg = Debug|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Debug|Win32.Build.0 = Debug|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Debug|x64.ActiveCfg = Debug|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Debug|x64.Build.0 = Debug|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Release|Win32.ActiveCfg = Release|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Release|Win32.Build.0 = Release|Win32 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Release|x64.ActiveCfg = Release|x64 + {C6E20F84-3247-4AD6-B051-B073268F73BA}.Release|x64.Build.0 = Release|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Debug|Win32.ActiveCfg = Debug|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Debug|Win32.Build.0 = Debug|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Debug|x64.ActiveCfg = Debug|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Debug|x64.Build.0 = Debug|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|Win32.ActiveCfg = Release|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|Win32.Build.0 = Release|Win32 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|x64.ActiveCfg = Release|x64 + {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|x64.Build.0 = Release|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|Win32.ActiveCfg = Debug|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|Win32.Build.0 = Debug|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|x64.ActiveCfg = Debug|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|x64.Build.0 = Debug|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Release|Win32.ActiveCfg = Release|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Release|Win32.Build.0 = Release|Win32 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Release|x64.ActiveCfg = Release|x64 + {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Release|x64.Build.0 = Release|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Debug|Win32.ActiveCfg = Debug|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Debug|Win32.Build.0 = Debug|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Debug|x64.ActiveCfg = Debug|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Debug|x64.Build.0 = Debug|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Release|Win32.ActiveCfg = Release|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Release|Win32.Build.0 = Release|Win32 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Release|x64.ActiveCfg = Release|x64 + {73FCD2BD-F133-46B7-8EC1-144CD82A59D5}.Release|x64.Build.0 = Release|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Debug|Win32.ActiveCfg = Debug|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Debug|Win32.Build.0 = Debug|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Debug|x64.ActiveCfg = Debug|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Debug|x64.Build.0 = Debug|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Release|Win32.ActiveCfg = Release|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Release|Win32.Build.0 = Release|Win32 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Release|x64.ActiveCfg = Release|x64 + {18CAE28C-B454-46C1-87A0-493D91D97F03}.Release|x64.Build.0 = Release|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Debug|Win32.ActiveCfg = Debug|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Debug|Win32.Build.0 = Debug|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Debug|x64.ActiveCfg = Debug|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Debug|x64.Build.0 = Debug|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Release|Win32.ActiveCfg = Release|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Release|Win32.Build.0 = Release|Win32 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Release|x64.ActiveCfg = Release|x64 + {ECC7CEAC-A5E5-458E-BB9E-2413CC847881}.Release|x64.Build.0 = Release|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Debug|Win32.ActiveCfg = Debug|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Debug|Win32.Build.0 = Debug|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Debug|x64.ActiveCfg = Debug|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Debug|x64.Build.0 = Debug|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Release|Win32.ActiveCfg = Release|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Release|Win32.Build.0 = Release|Win32 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Release|x64.ActiveCfg = Release|x64 + {D06B6426-4762-44CC-8BAD-D79052507F2F}.Release|x64.Build.0 = Release|x64 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.Debug|Win32.ActiveCfg = Release|Win32 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.Debug|x64.ActiveCfg = Release|x64 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.PGInstrument|Win32.ActiveCfg = Release|Win32 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.PGInstrument|x64.ActiveCfg = Release|x64 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.PGUpdate|Win32.ActiveCfg = Release|Win32 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.PGUpdate|x64.ActiveCfg = Release|x64 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.Release|Win32.ActiveCfg = Release|Win32 + {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C}.Release|x64.ActiveCfg = Release|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Debug|Win32.ActiveCfg = Debug|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Debug|Win32.Build.0 = Debug|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Debug|x64.ActiveCfg = Debug|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Debug|x64.Build.0 = Debug|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Release|Win32.ActiveCfg = Release|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Release|Win32.Build.0 = Release|Win32 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Release|x64.ActiveCfg = Release|x64 + {447F05A8-F581-4CAC-A466-5AC7936E207E}.Release|x64.Build.0 = Release|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Debug|Win32.ActiveCfg = Debug|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Debug|Win32.Build.0 = Debug|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Debug|x64.ActiveCfg = Debug|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Debug|x64.Build.0 = Debug|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Release|Win32.ActiveCfg = Release|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Release|Win32.Build.0 = Release|Win32 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Release|x64.ActiveCfg = Release|x64 + {A1A295E5-463C-437F-81CA-1F32367685DA}.Release|x64.Build.0 = Release|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.Debug|Win32.ActiveCfg = Debug|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.Debug|Win32.Build.0 = Debug|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.Debug|x64.ActiveCfg = Debug|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.Debug|x64.Build.0 = Debug|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.Release|Win32.ActiveCfg = Release|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.Release|Win32.Build.0 = Release|Win32 + {9E48B300-37D1-11DD-8C41-005056C00008}.Release|x64.ActiveCfg = Release|x64 + {9E48B300-37D1-11DD-8C41-005056C00008}.Release|x64.Build.0 = Release|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Debug|Win32.ActiveCfg = Debug|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Debug|Win32.Build.0 = Debug|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Debug|x64.ActiveCfg = Debug|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Debug|x64.Build.0 = Debug|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Release|Win32.ActiveCfg = Release|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Release|Win32.Build.0 = Release|Win32 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Release|x64.ActiveCfg = Release|x64 + {E5B04CC0-EB4C-42AB-B4DC-18EF95F864B0}.Release|x64.Build.0 = Release|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Debug|Win32.ActiveCfg = Debug|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Debug|Win32.Build.0 = Debug|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Debug|x64.ActiveCfg = Debug|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Debug|x64.Build.0 = Debug|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGInstrument|Win32.ActiveCfg = Release|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGInstrument|Win32.Build.0 = Release|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGInstrument|x64.ActiveCfg = Release|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGInstrument|x64.Build.0 = Release|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGUpdate|Win32.ActiveCfg = Release|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGUpdate|Win32.Build.0 = Release|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGUpdate|x64.ActiveCfg = Release|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.PGUpdate|x64.Build.0 = Release|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Release|Win32.ActiveCfg = Release|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Release|Win32.Build.0 = Release|Win32 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Release|x64.ActiveCfg = Release|x64 + {6DE10744-E396-40A5-B4E2-1B69AA7C8D31}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pginstrument.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pginstrument.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,34 @@ + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pgupdate.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pgupdate.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,14 @@ + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pyd.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pyd.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,28 @@ + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pyd_d.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pyd_d.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,36 @@ + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pyexpat.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pyexpat.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,553 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pyproject.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pyproject.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/python.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/python.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,637 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pythoncore.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pythoncore.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,1921 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/pythonw.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/pythonw.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,618 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/release.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/release.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,15 @@ + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/rmpyc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/rmpyc.py Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,25 @@ +# Remove all the .pyc and .pyo files under ../Lib. + + +def deltree(root): + import os + from os.path import join + + npyc = npyo = 0 + for root, dirs, files in os.walk(root): + for name in files: + delete = False + if name.endswith('.pyc'): + delete = True + npyc += 1 + elif name.endswith('.pyo'): + delete = True + npyo += 1 + + if delete: + os.remove(join(root, name)) + + return npyc, npyo + +npyc, npyo = deltree("../../Lib") +print(npyc, ".pyc deleted,", npyo, ".pyo deleted") diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/rt.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/rt.bat Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,52 @@ +@echo off +rem Run Tests. Run the regression test suite. +rem Usage: rt [-d] [-O] [-q] regrtest_args +rem -d Run Debug build (python_d.exe). Else release build. +rem -O Run python.exe or python_d.exe (see -d) with -O. +rem -q "quick" -- normally the tests are run twice, the first time +rem after deleting all the .py[co] files reachable from Lib/. +rem -q runs the tests just once, and without deleting .py[co] files. +rem All leading instances of these switches are shifted off, and +rem whatever remains is passed to regrtest.py. For example, +rem rt -O -d -x test_thread +rem runs +rem python_d -O ../lib/test/regrtest.py -x test_thread +rem twice, and +rem rt -q -g test_binascii +rem runs +rem python_d ../lib/test/regrtest.py -g test_binascii +rem to generate the expected-output file for binascii quickly. +rem +rem Confusing: if you want to pass a comma-separated list, like +rem -u network,largefile +rem then you have to quote it on the rt line, like +rem rt -u "network,largefile" + +setlocal + +set exe=python +set qmode= +set dashO= +PATH %PATH%;%~dp0..\..\..\tcltk\bin + +:CheckOpts +if "%1"=="-O" (set dashO=-O) & shift & goto CheckOpts +if "%1"=="-q" (set qmode=yes) & shift & goto CheckOpts +if "%1"=="-d" (set exe=python_d) & shift & goto CheckOpts + +set cmd=%exe% %dashO% -E ../../lib/test/regrtest.py %1 %2 %3 %4 %5 %6 %7 %8 %9 +if defined qmode goto Qmode + +echo Deleting .pyc/.pyo files ... +%exe% rmpyc.py + +echo on +%cmd% +@echo off + +echo About to run again without deleting .pyc/.pyo first: +pause + +:Qmode +echo on +%cmd% diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/select.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/select.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/sqlite3.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/sqlite3.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/sqlite3.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/sqlite3.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,14 @@ + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/ssl.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/ssl.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/unicodedata.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/unicodedata.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,533 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/winsound.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/winsound.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,523 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS8.0/x64.vsprops --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/VS8.0/x64.vsprops Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,22 @@ + + + + + + diff -r 35c88c53cf64 -r ecc10f0afb76 PC/VS9.0/_ssl.vcproj --- a/PC/VS9.0/_ssl.vcproj Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/VS9.0/_ssl.vcproj Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ - - @@ -1591,10 +1587,6 @@ > - - diff -r 35c88c53cf64 -r ecc10f0afb76 PC/_msi.c --- a/PC/_msi.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/_msi.c Fri Feb 01 23:12:09 2013 +0100 @@ -1030,40 +1030,40 @@ PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (int)MSIDBOPEN_TRANSACT); PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (int)MSIDBOPEN_PATCHFILE); - PyModule_AddIntMacro(m, MSICOLINFO_NAMES); - PyModule_AddIntMacro(m, MSICOLINFO_TYPES); + PyModule_AddIntConstant(m, "MSICOLINFO_NAMES", MSICOLINFO_NAMES); + PyModule_AddIntConstant(m, "MSICOLINFO_TYPES", MSICOLINFO_TYPES); - PyModule_AddIntMacro(m, MSIMODIFY_SEEK); - PyModule_AddIntMacro(m, MSIMODIFY_REFRESH); - PyModule_AddIntMacro(m, MSIMODIFY_INSERT); - PyModule_AddIntMacro(m, MSIMODIFY_UPDATE); - PyModule_AddIntMacro(m, MSIMODIFY_ASSIGN); - PyModule_AddIntMacro(m, MSIMODIFY_REPLACE); - PyModule_AddIntMacro(m, MSIMODIFY_MERGE); - PyModule_AddIntMacro(m, MSIMODIFY_DELETE); - PyModule_AddIntMacro(m, MSIMODIFY_INSERT_TEMPORARY); - PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE); - PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE_NEW); - PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE_FIELD); - PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE_DELETE); + PyModule_AddIntConstant(m, "MSIMODIFY_SEEK", MSIMODIFY_SEEK); + PyModule_AddIntConstant(m, "MSIMODIFY_REFRESH", MSIMODIFY_REFRESH); + PyModule_AddIntConstant(m, "MSIMODIFY_INSERT", MSIMODIFY_INSERT); + PyModule_AddIntConstant(m, "MSIMODIFY_UPDATE", MSIMODIFY_UPDATE); + PyModule_AddIntConstant(m, "MSIMODIFY_ASSIGN", MSIMODIFY_ASSIGN); + PyModule_AddIntConstant(m, "MSIMODIFY_REPLACE", MSIMODIFY_REPLACE); + PyModule_AddIntConstant(m, "MSIMODIFY_MERGE", MSIMODIFY_MERGE); + PyModule_AddIntConstant(m, "MSIMODIFY_DELETE", MSIMODIFY_DELETE); + PyModule_AddIntConstant(m, "MSIMODIFY_INSERT_TEMPORARY", MSIMODIFY_INSERT_TEMPORARY); + PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE", MSIMODIFY_VALIDATE); + PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_NEW", MSIMODIFY_VALIDATE_NEW); + PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_FIELD", MSIMODIFY_VALIDATE_FIELD); + PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_DELETE", MSIMODIFY_VALIDATE_DELETE); - PyModule_AddIntMacro(m, PID_CODEPAGE); - PyModule_AddIntMacro(m, PID_TITLE); - PyModule_AddIntMacro(m, PID_SUBJECT); - PyModule_AddIntMacro(m, PID_AUTHOR); - PyModule_AddIntMacro(m, PID_KEYWORDS); - PyModule_AddIntMacro(m, PID_COMMENTS); - PyModule_AddIntMacro(m, PID_TEMPLATE); - PyModule_AddIntMacro(m, PID_LASTAUTHOR); - PyModule_AddIntMacro(m, PID_REVNUMBER); - PyModule_AddIntMacro(m, PID_LASTPRINTED); - PyModule_AddIntMacro(m, PID_CREATE_DTM); - PyModule_AddIntMacro(m, PID_LASTSAVE_DTM); - PyModule_AddIntMacro(m, PID_PAGECOUNT); - PyModule_AddIntMacro(m, PID_WORDCOUNT); - PyModule_AddIntMacro(m, PID_CHARCOUNT); - PyModule_AddIntMacro(m, PID_APPNAME); - PyModule_AddIntMacro(m, PID_SECURITY); + PyModule_AddIntConstant(m, "PID_CODEPAGE", PID_CODEPAGE); + PyModule_AddIntConstant(m, "PID_TITLE", PID_TITLE); + PyModule_AddIntConstant(m, "PID_SUBJECT", PID_SUBJECT); + PyModule_AddIntConstant(m, "PID_AUTHOR", PID_AUTHOR); + PyModule_AddIntConstant(m, "PID_KEYWORDS", PID_KEYWORDS); + PyModule_AddIntConstant(m, "PID_COMMENTS", PID_COMMENTS); + PyModule_AddIntConstant(m, "PID_TEMPLATE", PID_TEMPLATE); + PyModule_AddIntConstant(m, "PID_LASTAUTHOR", PID_LASTAUTHOR); + PyModule_AddIntConstant(m, "PID_REVNUMBER", PID_REVNUMBER); + PyModule_AddIntConstant(m, "PID_LASTPRINTED", PID_LASTPRINTED); + PyModule_AddIntConstant(m, "PID_CREATE_DTM", PID_CREATE_DTM); + PyModule_AddIntConstant(m, "PID_LASTSAVE_DTM", PID_LASTSAVE_DTM); + PyModule_AddIntConstant(m, "PID_PAGECOUNT", PID_PAGECOUNT); + PyModule_AddIntConstant(m, "PID_WORDCOUNT", PID_WORDCOUNT); + PyModule_AddIntConstant(m, "PID_CHARCOUNT", PID_CHARCOUNT); + PyModule_AddIntConstant(m, "PID_APPNAME", PID_APPNAME); + PyModule_AddIntConstant(m, "PID_SECURITY", PID_SECURITY); MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL); if (!MSIError) diff -r 35c88c53cf64 -r ecc10f0afb76 PC/bdist_wininst/extract.c --- a/PC/bdist_wininst/extract.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/bdist_wininst/extract.c Fri Feb 01 23:12:09 2013 +0100 @@ -127,7 +127,7 @@ CloseHandle(hFile); - if (hFileMapping == NULL) { + if (hFileMapping == INVALID_HANDLE_VALUE) { if (notify) notify(SYSTEM_ERROR, "CreateFileMapping (%s)", filename); diff -r 35c88c53cf64 -r ecc10f0afb76 PC/bdist_wininst/install.c --- a/PC/bdist_wininst/install.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/bdist_wininst/install.c Fri Feb 01 23:12:09 2013 +0100 @@ -1019,7 +1019,7 @@ NULL, PAGE_READONLY, 0, 0, NULL); CloseHandle(hFile); - if (hFileMapping == NULL) + if (hFileMapping == INVALID_HANDLE_VALUE) return NULL; data = MapViewOfFile(hFileMapping, diff -r 35c88c53cf64 -r ecc10f0afb76 PC/config.c --- a/PC/config.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/config.c Fri Feb 01 23:12:09 2013 +0100 @@ -17,7 +17,7 @@ extern PyObject* PyInit_math(void); extern PyObject* PyInit__md5(void); extern PyObject* PyInit_nt(void); -extern PyObject* PyInit__operator(void); +extern PyObject* PyInit_operator(void); extern PyObject* PyInit_signal(void); extern PyObject* PyInit__sha1(void); extern PyObject* PyInit__sha256(void); @@ -64,7 +64,6 @@ extern PyObject* PyInit_atexit(void); extern PyObject* _PyWarnings_Init(void); extern PyObject* PyInit__string(void); -extern PyObject* PyInit__stat(void); /* tools/freeze/makeconfig.py marker for additional "extern" */ /* -- ADDMODULE MARKER 1 -- */ @@ -88,7 +87,7 @@ {"gc", PyInit_gc}, {"math", PyInit_math}, {"nt", PyInit_nt}, /* Use the NT os functions, not posix */ - {"_operator", PyInit__operator}, + {"operator", PyInit_operator}, {"signal", PyInit_signal}, {"_md5", PyInit__md5}, {"_sha1", PyInit__sha1}, @@ -155,7 +154,6 @@ {"_io", PyInit__io}, {"_pickle", PyInit__pickle}, {"atexit", PyInit_atexit}, - {"_stat", PyInit__stat}, /* Sentinel */ {0, 0} diff -r 35c88c53cf64 -r ecc10f0afb76 PC/getpathp.c --- a/PC/getpathp.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/getpathp.c Fri Feb 01 23:12:09 2013 +0100 @@ -245,9 +245,9 @@ /* Tried to use sysget("winver") but here is too early :-( */ versionLen = strlen(PyWin_DLLVersionString); /* Space for all the chars, plus one \0 */ - keyBuf = keyBufPtr = PyMem_RawMalloc(sizeof(keyPrefix) + - sizeof(WCHAR)*(versionLen-1) + - sizeof(keySuffix)); + keyBuf = keyBufPtr = malloc(sizeof(keyPrefix) + + sizeof(WCHAR)*(versionLen-1) + + sizeof(keySuffix)); if (keyBuf==NULL) goto done; memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(WCHAR)); @@ -271,7 +271,7 @@ /* Allocate a temp array of char buffers, so we only need to loop reading the registry once */ - ppPaths = PyMem_RawMalloc( sizeof(WCHAR *) * numKeys ); + ppPaths = malloc( sizeof(WCHAR *) * numKeys ); if (ppPaths==NULL) goto done; memset(ppPaths, 0, sizeof(WCHAR *) * numKeys); /* Loop over all subkeys, allocating a temp sub-buffer. */ @@ -293,7 +293,7 @@ /* Find the value of the buffer size, malloc, then read it */ RegQueryValueExW(subKey, NULL, 0, NULL, NULL, &reqdSize); if (reqdSize) { - ppPaths[index] = PyMem_RawMalloc(reqdSize); + ppPaths[index] = malloc(reqdSize); if (ppPaths[index]) { RegQueryValueExW(subKey, NULL, 0, NULL, (LPBYTE)ppPaths[index], @@ -308,7 +308,7 @@ if (dataSize == 0) goto done; /* original datasize from RegQueryInfo doesn't include the \0 */ - dataBuf = PyMem_RawMalloc((dataSize+1) * sizeof(WCHAR)); + dataBuf = malloc((dataSize+1) * sizeof(WCHAR)); if (dataBuf) { WCHAR *szCur = dataBuf; DWORD reqdSize = dataSize; @@ -346,13 +346,14 @@ done: /* Loop freeing my temp buffers */ if (ppPaths) { - for(index=0; index 255) { + /* Large environment variable. Accept some leakage */ + wchar_t *buf2 = (wchar_t*)malloc(sizeof(wchar_t) * (result+1)); + GetEnvironmentVariableW(key, buf2, result); + return buf2; + } + + if (result == 0) + /* Either some error, e.g. ERROR_ENVVAR_NOT_FOUND, + or an empty environment variable. */ + return NULL; + + return buf; +} + + static void debug(wchar_t * format, ...) { @@ -95,40 +100,11 @@ #if !defined(_WINDOWS) fwprintf(stderr, L"%s\n", message); #else - MessageBox(NULL, message, TEXT("Python Launcher is sorry to say ..."), - MB_OK); + MessageBox(NULL, message, TEXT("Python Launcher is sorry to say ..."), MB_OK); #endif ExitProcess(rc); } -/* - * This function is here to simplify memory management - * and to treat blank values as if they are absent. - */ -static wchar_t * get_env(wchar_t * key) -{ - /* This is not thread-safe, just like getenv */ - static wchar_t buf[BUFSIZE]; - DWORD result = GetEnvironmentVariableW(key, buf, BUFSIZE); - - if (result >= BUFSIZE) { - /* Large environment variable. Accept some leakage */ - wchar_t *buf2 = (wchar_t*)malloc(sizeof(wchar_t) * (result+1)); - if (buf2 = NULL) { - error(RC_NO_MEMORY, L"Could not allocate environment buffer"); - } - GetEnvironmentVariableW(key, buf2, result); - return buf2; - } - - if (result == 0) - /* Either some error, e.g. ERROR_ENVVAR_NOT_FOUND, - or an empty environment variable. */ - return NULL; - - return buf; -} - #if defined(_WINDOWS) #define PYTHON_EXECUTABLE L"pythonw.exe" @@ -139,6 +115,11 @@ #endif +#define RC_NO_STD_HANDLES 100 +#define RC_CREATE_PROCESS 101 +#define RC_BAD_VIRTUAL_PATH 102 +#define RC_NO_PYTHON 103 + #define MAX_VERSION_SIZE 4 typedef struct { @@ -476,51 +457,6 @@ return result; } -#if defined(SCRIPT_WRAPPER) -/* - * Check for a script located alongside the executable - */ - -#if defined(_WINDOWS) -#define SCRIPT_SUFFIX L"-script.pyw" -#else -#define SCRIPT_SUFFIX L"-script.py" -#endif - -static wchar_t wrapped_script_path[MAX_PATH]; - -/* Locate the script being wrapped. - * - * This code should store the name of the wrapped script in - * wrapped_script_path, or terminate the program with an error if there is no - * valid wrapped script file. - */ -static void -locate_wrapped_script() -{ - wchar_t * p; - size_t plen; - DWORD attrs; - - plen = GetModuleFileNameW(NULL, wrapped_script_path, MAX_PATH); - p = wcsrchr(wrapped_script_path, L'.'); - if (p == NULL) { - debug(L"GetModuleFileNameW returned value has no extension: %s\n", - wrapped_script_path); - error(RC_NO_SCRIPT, L"Wrapper name '%s' is not valid.", wrapped_script_path); - } - - wcsncpy_s(p, MAX_PATH - (p - wrapped_script_path) + 1, SCRIPT_SUFFIX, _TRUNCATE); - attrs = GetFileAttributesW(wrapped_script_path); - if (attrs == INVALID_FILE_ATTRIBUTES) { - debug(L"File '%s' non-existent\n", wrapped_script_path); - error(RC_NO_SCRIPT, L"Script file '%s' is not present.", wrapped_script_path); - } - - debug(L"Using wrapped script file '%s'\n", wrapped_script_path); -} -#endif - /* * Process creation code */ @@ -564,21 +500,6 @@ STARTUPINFOW si; PROCESS_INFORMATION pi; -#if defined(_WINDOWS) - // When explorer launches a Windows (GUI) application, it displays - // the "app starting" (the "pointer + hourglass") cursor for a number - // of seconds, or until the app does something UI-ish (eg, creating a - // window, or fetching a message). As this launcher doesn't do this - // directly, that cursor remains even after the child process does these - // things. We avoid that by doing a simple post+get message. - // See http://bugs.python.org/issue17290 and - // https://bitbucket.org/vinay.sajip/pylauncher/issue/20/busy-cursor-for-a-long-time-when-running - MSG msg; - - PostMessage(0, 0, 0, 0); - GetMessage(&msg, 0, 0, 0); -#endif - debug(L"run_child: about to run '%s'\n", cmdline); job = CreateJobObject(NULL, NULL); ok = QueryInformationJobObject(job, JobObjectExtendedLimitInformation, @@ -614,7 +535,7 @@ error(RC_CREATE_PROCESS, L"Unable to create process using '%s'", cmdline); AssignProcessToJobObject(job, pi.hProcess); CloseHandle(pi.hThread); - WaitForSingleObjectEx(pi.hProcess, INFINITE, FALSE); + WaitForSingleObject(pi.hProcess, INFINITE); ok = GetExitCodeProcess(pi.hProcess, &rc); if (!ok) error(RC_CREATE_PROCESS, L"Failed to get exit code of process"); @@ -659,17 +580,12 @@ } } -typedef struct { - wchar_t *shebang; - BOOL search; -} SHEBANG; - -static SHEBANG builtin_virtual_paths [] = { - { L"/usr/bin/env python", TRUE }, - { L"/usr/bin/python", FALSE }, - { L"/usr/local/bin/python", FALSE }, - { L"python", FALSE }, - { NULL, FALSE }, +static wchar_t * builtin_virtual_paths [] = { + L"/usr/bin/env python", + L"/usr/bin/python", + L"/usr/local/bin/python", + L"python", + NULL }; /* For now, a static array of commands. */ @@ -845,10 +761,10 @@ static BOOL parse_shebang(wchar_t * shebang_line, int nchars, wchar_t ** command, - wchar_t ** suffix, BOOL *search) + wchar_t ** suffix) { BOOL rc = FALSE; - SHEBANG * vpp; + wchar_t ** vpp; size_t plen; wchar_t * p; wchar_t zapped; @@ -858,17 +774,15 @@ *command = NULL; /* failure return */ *suffix = NULL; - *search = FALSE; if ((*shebang_line++ == L'#') && (*shebang_line++ == L'!')) { shebang_line = skip_whitespace(shebang_line); if (*shebang_line) { *command = shebang_line; - for (vpp = builtin_virtual_paths; vpp->shebang; ++vpp) { - plen = wcslen(vpp->shebang); - if (wcsncmp(shebang_line, vpp->shebang, plen) == 0) { + for (vpp = builtin_virtual_paths; *vpp; ++vpp) { + plen = wcslen(*vpp); + if (wcsncmp(shebang_line, *vpp, plen) == 0) { rc = TRUE; - *search = vpp->search; /* We can do this because all builtin commands contain * "python". */ @@ -876,7 +790,7 @@ break; } } - if (vpp->shebang == NULL) { + if (*vpp == NULL) { /* * Not found in builtins - look in customised commands. * @@ -927,7 +841,7 @@ } BOM; /* - * Strictly, we don't need to handle UTF-16 and UTF-32, since Python itself + * Strictly, we don't need to handle UTF-16 anf UTF-32, since Python itself * doesn't. Never mind, one day it might - there's no harm leaving it in. */ static BOM BOMs[] = { @@ -1083,10 +997,8 @@ int i, j, nchars = 0; int header_len; BOOL is_virt; - BOOL search; wchar_t * command; wchar_t * suffix; - COMMAND *cmd = NULL; INSTALLED_PYTHON * ip; if (rc == 0) { @@ -1198,7 +1110,7 @@ if (nchars > 0) { shebang_line[--nchars] = L'\0'; is_virt = parse_shebang(shebang_line, nchars, &command, - &suffix, &search); + &suffix); if (command != NULL) { debug(L"parse_shebang: found command: %s\n", command); if (!is_virt) { @@ -1214,23 +1126,6 @@ error(RC_BAD_VIRTUAL_PATH, L"Unknown virtual \ path '%s'", command); command += 6; /* skip past "python" */ - if (search && ((*command == L'\0') || isspace(*command))) { - /* Command is eligible for path search, and there - * is no version specification. - */ - debug(L"searching PATH for python executable\n"); - cmd = find_on_path(L"python"); - debug(L"Python on path: %s\n", cmd ? cmd->value : L""); - if (cmd) { - debug(L"located python on PATH: %s\n", cmd->value); - invoke_child(cmd->value, suffix, cmdline); - /* Exit here, as we have found the command */ - return; - } - /* FALL THROUGH: No python found on PATH, so fall - * back to locating the correct installed python. - */ - } if (*command && !validate_version(command)) error(RC_BAD_VIRTUAL_PATH, L"Invalid version \ specification: '%s'.\nIn the first line of the script, 'python' needs to be \ @@ -1313,12 +1208,6 @@ void * version_data; VS_FIXEDFILEINFO * file_info; UINT block_size; - int index; -#if defined(SCRIPT_WRAPPER) - int newlen; - wchar_t * newcommand; - wchar_t * av[2]; -#endif wp = get_env(L"PYLAUNCH_DEBUG"); if ((wp != NULL) && (*wp != L'\0')) @@ -1367,8 +1256,8 @@ if (!valid) debug(L"GetFileVersionInfo failed: %X\n", GetLastError()); else { - valid = VerQueryValueW(version_data, L"\\", - (LPVOID *) &file_info, &block_size); + valid = VerQueryValueW(version_data, L"\\", &file_info, + &block_size); if (!valid) debug(L"VerQueryValue failed: %X\n", GetLastError()); else { @@ -1398,40 +1287,7 @@ } command = skip_me(GetCommandLineW()); - debug(L"Called with command line: %s\n", command); - -#if defined(SCRIPT_WRAPPER) - /* The launcher is being used in "script wrapper" mode. - * There should therefore be a Python script named -script.py in - * the same directory as the launcher executable. - * Put the script name into argv as the first (script name) argument. - */ - - /* Get the wrapped script name - if the script is not present, this will - * terminate the program with an error. - */ - locate_wrapped_script(); - - /* Add the wrapped script to the start of command */ - newlen = wcslen(wrapped_script_path) + wcslen(command) + 2; /* ' ' + NUL */ - newcommand = malloc(sizeof(wchar_t) * newlen); - if (!newcommand) { - error(RC_NO_MEMORY, L"Could not allocate new command line"); - } - else { - wcscpy_s(newcommand, newlen, wrapped_script_path); - wcscat_s(newcommand, newlen, L" "); - wcscat_s(newcommand, newlen, command); - debug(L"Running wrapped script with command line '%s'\n", newcommand); - read_commands(); - av[0] = wrapped_script_path; - av[1] = NULL; - maybe_handle_shebang(av, newcommand); - /* Returns if no shebang line - pass to default processing */ - command = newcommand; - valid = FALSE; - } -#else + debug(L"Called with command line: %s", command); if (argc <= 1) { valid = FALSE; p = NULL; @@ -1439,6 +1295,13 @@ else { p = argv[1]; plen = wcslen(p); + if (p[0] != L'-') { + read_commands(); + maybe_handle_shebang(&argv[1], command); + } + /* No file with shebang, or an unrecognised shebang. + * Is the first arg a special version qualifier? + */ valid = (*p == L'-') && validate_version(&p[1]); if (valid) { ip = locate_python(&p[1]); @@ -1448,19 +1311,7 @@ command += wcslen(p); command = skip_whitespace(command); } - else { - for (index = 1; index < argc; ++index) { - if (*argv[index] != L'-') - break; - } - if (index < argc) { - read_commands(); - maybe_handle_shebang(&argv[index], command); - } - } } -#endif - if (!valid) { ip = locate_python(L""); if (ip == NULL) @@ -1478,7 +1329,7 @@ fwprintf(stdout, L"\ Python Launcher for Windows Version %s\n\n", version_text); fwprintf(stdout, L"\ -usage: %s [ launcher-arguments ] [ python-arguments ] script [ script-arguments ]\n\n", argv[0]); +usage: %s [ launcher-arguments ] script [ script-arguments ]\n\n", argv[0]); fputws(L"\ Launcher arguments:\n\n\ -2 : Launch the latest Python 2.x version\n\ @@ -1511,4 +1362,4 @@ return process(argc, argv); } -#endif +#endif \ No newline at end of file diff -r 35c88c53cf64 -r ecc10f0afb76 PC/msvcrtmodule.c --- a/PC/msvcrtmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/msvcrtmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -113,17 +113,16 @@ static PyObject * msvcrt_open_osfhandle(PyObject *self, PyObject *args) { - Py_intptr_t handle; + long handle; int flags; int fd; - if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:open_osfhandle", - &handle, &flags)) + if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags)) return NULL; - fd = _open_osfhandle(handle, flags); + fd = _Py_open_osfhandle(handle, flags, 1); if (fd == -1) - return PyErr_SetFromErrno(PyExc_IOError); + return NULL; return PyLong_FromLong(fd); } @@ -146,12 +145,9 @@ if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) return NULL; - if (!_PyVerify_fd(fd)) - return PyErr_SetFromErrno(PyExc_IOError); - - handle = _get_osfhandle(fd); + handle = _Py_get_osfhandle(fd, 1); if (handle == -1) - return PyErr_SetFromErrno(PyExc_IOError); + return NULL; /* technically 'handle' is not a pointer, but a integer as large as a pointer, Python's *VoidPtr interface is the diff -r 35c88c53cf64 -r ecc10f0afb76 PC/pyconfig.h --- a/PC/pyconfig.h Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/pyconfig.h Fri Feb 01 23:12:09 2013 +0100 @@ -156,9 +156,15 @@ #endif /* MS_WIN64 */ /* set the version macros for the windows headers */ -/* Python 3.4+ requires Windows XP or greater */ +#ifdef MS_WINX64 +/* 64 bit only runs on XP or greater */ #define Py_WINVER 0x0501 /* _WIN32_WINNT_WINXP */ #define Py_NTDDI NTDDI_WINXP +#else +/* Python 2.6+ requires Windows 2000 or greater */ +#define Py_WINVER 0x0500 /* _WIN32_WINNT_WIN2K */ +#define Py_NTDDI NTDDI_WIN2KSP4 +#endif /* We only set these values when building Python - we don't want to force these values on extensions, as that will affect the prototypes and @@ -193,10 +199,8 @@ #define HAVE_SSIZE_T 1 #if defined(MS_WIN32) && !defined(MS_WIN64) -#if defined(_M_IX86) +#ifdef _M_IX86 #define COMPILER _Py_PASTE_VERSION("32 bit (Intel)") -#elif defined(_M_ARM) -#define COMPILER _Py_PASTE_VERSION("32 bit (ARM)") #else #define COMPILER _Py_PASTE_VERSION("32 bit (Unknown)") #endif @@ -723,9 +727,6 @@ /* The size of `wchar_t', as computed by sizeof. */ #define SIZEOF_WCHAR_T 2 -/* The size of `pid_t', as computed by sizeof. */ -#define SIZEOF_PID_T SIZEOF_INT - /* Define if you have the dl library (-ldl). */ /* #undef HAVE_LIBDL */ diff -r 35c88c53cf64 -r ecc10f0afb76 PC/python_nt.rc --- a/PC/python_nt.rc Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/python_nt.rc Fri Feb 01 23:12:09 2013 +0100 @@ -61,7 +61,7 @@ VALUE "FileDescription", "Python Core\0" VALUE "FileVersion", PYTHON_VERSION VALUE "InternalName", "Python DLL\0" - VALUE "LegalCopyright", "Copyright © 2001-2013 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0" + VALUE "LegalCopyright", "Copyright © 2001-2012 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0" VALUE "OriginalFilename", PYTHON_DLL_NAME "\0" VALUE "ProductName", "Python\0" VALUE "ProductVersion", PYTHON_VERSION diff -r 35c88c53cf64 -r ecc10f0afb76 PC/winreg.c --- a/PC/winreg.c Fri Jul 26 23:14:22 2013 -0700 +++ b/PC/winreg.c Fri Feb 01 23:12:09 2013 +0100 @@ -938,7 +938,7 @@ wchar_t *data = (wchar_t *)retDataBuf; int len = retDataSize / 2; int s = countStrings(data, len); - wchar_t **str = (wchar_t **)PyMem_Malloc(sizeof(wchar_t *)*s); + wchar_t **str = (wchar_t **)malloc(sizeof(wchar_t *)*s); if (str == NULL) return PyErr_NoMemory(); @@ -959,7 +959,7 @@ index, PyUnicode_FromWideChar(str[index], len)); } - PyMem_Free(str); + free(str); break; } diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/_ssl.vcxproj --- a/PCbuild/_ssl.vcxproj Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/_ssl.vcxproj Fri Feb 01 23:12:09 2013 +0100 @@ -158,7 +158,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) @@ -173,7 +173,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) @@ -185,7 +185,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) @@ -200,7 +200,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) @@ -212,7 +212,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) @@ -227,7 +227,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) MachineX64 @@ -240,7 +240,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib;%(AdditionalDependencies) @@ -255,7 +255,7 @@ - ws2_32.lib;crypt32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) + ws2_32.lib;$(opensslDir)\out64\libeay32.lib;$(opensslDir)\out64\ssleay32.lib;%(AdditionalDependencies) MachineX64 diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/build_tkinter.py --- a/PCbuild/build_tkinter.py Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/build_tkinter.py Fri Feb 01 23:12:09 2013 +0100 @@ -16,7 +16,11 @@ TIX = "tix-8.4.3.x" ROOT = os.path.abspath(os.path.join(here, par, par)) -NMAKE = ('nmake /nologo /f %s %s %s') +# Windows 2000 compatibility: WINVER 0x0500 +# http://msdn2.microsoft.com/en-us/library/aa383745.aspx +NMAKE = ('nmake /nologo /f %s ' + 'COMPILERFLAGS=\"-DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=NTDDI_WIN2KSP4\" ' + '%s %s') def nmake(makefile, command="", **kw): defines = ' '.join(k+'='+str(v) for k, v in kw.items()) diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/pyproject.props --- a/PCbuild/pyproject.props Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/pyproject.props Fri Feb 01 23:12:09 2013 +0100 @@ -20,7 +20,7 @@ $(externalsDir)\sqlite-3.7.12 $(externalsDir)\bzip2-1.0.6 $(externalsDir)\xz-5.0.3 - $(externalsDir)\openssl-1.0.1e + $(externalsDir)\openssl-1.0.1c $(externalsDir)\tcltk $(externalsDir)\tcltk64 $(tcltkDir)\lib\tcl85.lib;$(tcltkDir)\lib\tk85.lib diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/python.vcxproj --- a/PCbuild/python.vcxproj Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/python.vcxproj Fri Feb 01 23:12:09 2013 +0100 @@ -243,7 +243,7 @@ $(OutDir)python_d.exe Console - 4194304 + 2100000 0x1d000000 diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/pythoncore.vcxproj --- a/PCbuild/pythoncore.vcxproj Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/pythoncore.vcxproj Fri Feb 01 23:12:09 2013 +0100 @@ -475,7 +475,6 @@ - @@ -501,7 +500,6 @@ - @@ -518,7 +516,7 @@ - + diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/pythoncore.vcxproj.filters --- a/PCbuild/pythoncore.vcxproj.filters Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/pythoncore.vcxproj.filters Fri Feb 01 23:12:09 2013 +0100 @@ -378,9 +378,6 @@ Objects - - Objects - Objects @@ -501,7 +498,7 @@ Modules - + Modules @@ -919,9 +916,6 @@ PC - - Modules - diff -r 35c88c53cf64 -r ecc10f0afb76 PCbuild/readme.txt --- a/PCbuild/readme.txt Fri Jul 26 23:14:22 2013 -0700 +++ b/PCbuild/readme.txt Fri Feb 01 23:12:09 2013 +0100 @@ -142,7 +142,7 @@ Get the source code through - svn export http://svn.python.org/projects/external/openssl-1.0.1e + svn export http://svn.python.org/projects/external/openssl-1.0.1c ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for obtaining external sources then you don't need to manually get the source @@ -152,12 +152,9 @@ You can (theoretically) use any version of OpenSSL you like - the build process will automatically select the latest version. - You must install the NASM assembler 2.10 or newer from + You must install the NASM assembler from http://nasm.sf.net - for x86 builds. Put nasmw.exe anywhere in your PATH. More recent - versions of OpenSSL may need a later version of NASM. If OpenSSL's self - tests don't pass, you should first try to update NASM and do a full - rebuild of OpenSSL. + for x86 builds. Put nasmw.exe anywhere in your PATH. Note: recent releases of nasm only have nasm.exe. Just rename it to nasmw.exe. diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/Python.asdl --- a/Parser/Python.asdl Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/Python.asdl Fri Feb 01 23:12:09 2013 +0100 @@ -103,11 +103,11 @@ excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) attributes (int lineno, int col_offset) - arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, - arg? kwarg, expr* defaults) - + arguments = (arg* args, identifier? vararg, expr? varargannotation, + arg* kwonlyargs, identifier? kwarg, + expr? kwargannotation, expr* defaults, + expr* kw_defaults) arg = (identifier arg, expr? annotation) - attributes (int lineno, int col_offset) -- keyword arguments supplied to call keyword = (identifier arg, expr value) diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/asdl.py --- a/Parser/asdl.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/asdl.py Fri Feb 01 23:12:09 2013 +0100 @@ -158,19 +158,11 @@ msg="expected attributes, found %s" % id) return Sum(sum, attributes) - def p_product_0(self, info): + def p_product(self, info): " product ::= ( fields ) " _0, fields, _1 = info return Product(fields) - def p_product_1(self, info): - " product ::= ( fields ) Id ( fields ) " - _0, fields, _1, id, _2, attributes, _3 = info - if id.value != "attributes": - raise ASDLSyntaxError(id.lineno, - msg="expected attributes, found %s" % id) - return Product(fields, attributes) - def p_sum_0(self, constructor): " sum ::= constructor " return [constructor[0]] @@ -297,15 +289,11 @@ return "Sum(%s, %s)" % (self.types, self.attributes) class Product(AST): - def __init__(self, fields, attributes=None): + def __init__(self, fields): self.fields = fields - self.attributes = attributes or [] def __repr__(self): - if self.attributes is None: - return "Product(%s)" % self.fields - else: - return "Product(%s, %s)" % (self.fields, self.attributes) + return "Product(%s)" % self.fields class VisitorBase(object): diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/asdl_c.py --- a/Parser/asdl_c.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/asdl_c.py Fri Feb 01 23:12:09 2013 +0100 @@ -8,7 +8,7 @@ import asdl -TABSIZE = 4 +TABSIZE = 8 MAX_COL = 80 def get_c_type(name): @@ -209,11 +209,6 @@ self.emit("struct _%(name)s {" % locals(), depth) for f in product.fields: self.visit(f, depth + 1) - for field in product.attributes: - # rudimentary attribute handling - type = str(field.type) - assert type in asdl.builtin_types, type - self.emit("%s %s;" % (type, field.name), depth + 1); self.emit("};", depth) self.emit("", depth) @@ -498,11 +493,7 @@ def visitField(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) - if field.opt: - check = "exists_not_none(obj, &PyId_%s)" % (field.name,) - else: - check = "_PyObject_HasAttrId(obj, &PyId_%s)" % (field.name,) - self.emit("if (%s) {" % (check,), depth, reflow=False) + self.emit("if (_PyObject_HasAttrId(obj, &PyId_%s)) {" % field.name, depth) self.emit("int res;", depth+1) if field.seq: self.emit("Py_ssize_t len;", depth+1) @@ -535,7 +526,8 @@ (field.type, field.name), depth+1) self.emit("if (res != 0) goto failed;", depth+1) - self.emit("Py_CLEAR(tmp);", depth+1) + self.emit("Py_XDECREF(tmp);", depth+1) + self.emit("tmp = NULL;", depth+1) self.emit("} else {", depth) if not field.opt: message = "required field \\\"%s\\\" missing from %s" % (field.name, name) @@ -567,13 +559,6 @@ def visitProduct(self, prod, name): self.emit("static PyTypeObject *%s_type;" % name, 0) self.emit("static PyObject* ast2obj_%s(void*);" % name, 0) - if prod.attributes: - for a in prod.attributes: - self.emit_identifier(a.name) - self.emit("static char *%s_attributes[] = {" % name, 0) - for a in prod.attributes: - self.emit('"%s",' % a.name, 1) - self.emit("};", 0) if prod.fields: for f in prod.fields: self.emit_identifier(f.name) @@ -862,13 +847,9 @@ { if (obj == Py_None) obj = NULL; - if (obj) { - if (PyArena_AddPyObject(arena, obj) < 0) { - *out = NULL; - return -1; - } - Py_INCREF(obj); - } + if (obj) + PyArena_AddPyObject(arena, obj); + Py_XINCREF(obj); *out = obj; return 0; } @@ -932,19 +913,6 @@ return 0; } -static int exists_not_none(PyObject *obj, _Py_Identifier *id) -{ - int isnone; - PyObject *attr = _PyObject_GetAttrId(obj, id); - if (!attr) { - PyErr_Clear(); - return 0; - } - isnone = attr == Py_None; - Py_DECREF(attr); - return !isnone; -} - """, 0, reflow=False) self.emit("static int init_types(void)",0) @@ -966,11 +934,6 @@ self.emit('%s_type = make_type("%s", &AST_type, %s, %d);' % (name, name, fields, len(prod.fields)), 1) self.emit("if (!%s_type) return 0;" % name, 1) - if prod.attributes: - self.emit("if (!add_attributes(%s_type, %s_attributes, %d)) return 0;" % - (name, name, len(prod.attributes)), 1) - else: - self.emit("if (!add_attributes(%s_type, NULL, 0)) return 0;" % name, 1) def visitSum(self, sum, name): self.emit('%s_type = make_type("%s", &AST_type, NULL, 0);' % @@ -1014,7 +977,7 @@ self.emit("if (!m) return NULL;", 1) self.emit("d = PyModule_GetDict(m);", 1) self.emit('if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;', 1) - self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)', 1) + self.emit('if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)', 1) self.emit("return NULL;", 2) for dfn in mod.dfns: self.visit(dfn) @@ -1126,12 +1089,6 @@ self.emit("if (!result) return NULL;", 1) for field in prod.fields: self.visitField(field, name, 1, True) - for a in prod.attributes: - self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1) - self.emit("if (!value) goto failed;", 1) - self.emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) < 0)' % a.name, 1) - self.emit('goto failed;', 2) - self.emit('Py_DECREF(value);', 1) self.func_end() def visitConstructor(self, cons, enum, name): @@ -1194,8 +1151,7 @@ CODE = """ PyObject* PyAST_mod2obj(mod_ty t) { - if (!init_types()) - return NULL; + init_types(); return ast2obj_mod(t); } @@ -1209,8 +1165,7 @@ int isinstance; assert(0 <= mode && mode <= 2); - if (!init_types()) - return NULL; + init_types(); isinstance = PyObject_IsInstance(ast, req_type[mode]); if (isinstance == -1) @@ -1228,8 +1183,7 @@ int PyAST_Check(PyObject* obj) { - if (!init_types()) - return -1; + init_types(); return PyObject_IsInstance(obj, (PyObject*)&AST_type); } """ diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/grammar1.c --- a/Parser/grammar1.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/grammar1.c Fri Feb 01 23:12:09 2013 +0100 @@ -45,7 +45,7 @@ else return lb->lb_str; } - else if (lb->lb_type < N_TOKENS) { + else { if (lb->lb_str == NULL) return _PyParser_TokenNames[lb->lb_type]; else { @@ -54,8 +54,4 @@ return buf; } } - else { - Py_FatalError("invalid label"); - return NULL; - } } diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/myreadline.c --- a/Parser/myreadline.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/myreadline.c Fri Feb 01 23:12:09 2013 +0100 @@ -68,7 +68,7 @@ */ if (GetLastError()==ERROR_OPERATION_ABORTED) { hInterruptEvent = _PyOS_SigintEvent(); - switch (WaitForSingleObjectEx(hInterruptEvent, 10, FALSE)) { + switch (WaitForSingleObject(hInterruptEvent, 10)) { case WAIT_OBJECT_0: ResetEvent(hInterruptEvent); return 1; /* Interrupt */ diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/parsetok.c --- a/Parser/parsetok.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/parsetok.c Fri Feb 01 23:12:09 2013 +0100 @@ -138,6 +138,7 @@ int started = 0; if ((ps = PyParser_New(g, start)) == NULL) { + fprintf(stderr, "no mem for new parser\n"); err_ret->error = E_NOMEM; PyTokenizer_Free(tok); return NULL; @@ -177,6 +178,7 @@ len = b - a; /* XXX this may compute NULL - NULL */ str = (char *) PyObject_MALLOC(len + 1); if (str == NULL) { + fprintf(stderr, "no mem for next token\n"); err_ret->error = E_NOMEM; break; } diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/pgenmain.c --- a/Parser/pgenmain.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/pgenmain.c Fri Feb 01 23:12:09 2013 +0100 @@ -113,7 +113,6 @@ Py_Exit(1); } g = pgen(n); - PyNode_Free(n); if (g == NULL) { printf("Bad grammar.\n"); Py_Exit(1); diff -r 35c88c53cf64 -r ecc10f0afb76 Parser/tokenizer.c --- a/Parser/tokenizer.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Parser/tokenizer.c Fri Feb 01 23:12:09 2013 +0100 @@ -147,15 +147,13 @@ } static char * -new_string(const char *s, Py_ssize_t len, struct tok_state *tok) +new_string(const char *s, Py_ssize_t len) { char* result = (char *)PyMem_MALLOC(len + 1); - if (!result) { - tok->done = E_NOMEM; - return NULL; + if (result != NULL) { + memcpy(result, s, len); + result[len] = '\0'; } - memcpy(result, s, len); - result[len] = '\0'; return result; } @@ -176,7 +174,7 @@ static char * decode_str(const char *str, int exec_input, struct tok_state *tok) { - return new_string(str, strlen(str), tok); + return new_string(str, strlen(str)); } #else /* PGEN */ @@ -223,18 +221,17 @@ /* Return the coding spec in S, or NULL if none is found. */ -static int -get_coding_spec(const char *s, char **spec, Py_ssize_t size, struct tok_state *tok) +static char * +get_coding_spec(const char *s, Py_ssize_t size) { Py_ssize_t i; - *spec = NULL; /* Coding spec must be in a comment, and that comment must be * the only statement on the source code line. */ for (i = 0; i < size - 6; i++) { if (s[i] == '#') break; if (s[i] != ' ' && s[i] != '\t' && s[i] != '\014') - return 1; + return NULL; } for (; i < size - 6; i++) { /* XXX inefficient search */ const char* t = s + i; @@ -253,22 +250,17 @@ t++; if (begin < t) { - char* r = new_string(begin, t - begin, tok); - char* q; - if (!r) - return 0; - q = get_normal_name(r); + char* r = new_string(begin, t - begin); + char* q = get_normal_name(r); if (r != q) { PyMem_FREE(r); - r = new_string(q, strlen(q), tok); - if (!r) - return 0; + r = new_string(q, strlen(q)); } - *spec = r; + return r; } } } - return 1; + return NULL; } /* Check whether the line contains a coding spec. If it does, @@ -280,39 +272,38 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok, int set_readline(struct tok_state *, const char *)) { - char *cs; + char * cs; int r = 1; if (tok->cont_line) /* It's a continuation line, so it can't be a coding spec. */ return 1; - if (!get_coding_spec(line, &cs, size, tok)) - return 0; - if (!cs) - return 1; - tok->read_coding_spec = 1; - if (tok->encoding == NULL) { - assert(tok->decoding_state == STATE_RAW); - if (strcmp(cs, "utf-8") == 0) { - tok->encoding = cs; - } else { - r = set_readline(tok, cs); - if (r) { + cs = get_coding_spec(line, size); + if (cs != NULL) { + tok->read_coding_spec = 1; + if (tok->encoding == NULL) { + assert(tok->decoding_state == STATE_RAW); + if (strcmp(cs, "utf-8") == 0) { tok->encoding = cs; - tok->decoding_state = STATE_NORMAL; + } else { + r = set_readline(tok, cs); + if (r) { + tok->encoding = cs; + tok->decoding_state = STATE_NORMAL; + } + else + PyMem_FREE(cs); } - else { - PyErr_Format(PyExc_SyntaxError, - "encoding problem: %s", cs); - PyMem_FREE(cs); - } + } else { /* then, compare cs with BOM */ + r = (strcmp(tok->encoding, cs) == 0); + PyMem_FREE(cs); } - } else { /* then, compare cs with BOM */ - r = (strcmp(tok->encoding, cs) == 0); - if (!r) - PyErr_Format(PyExc_SyntaxError, - "encoding problem: %s with BOM", cs); - PyMem_FREE(cs); + } + if (!r) { + cs = tok->encoding; + if (!cs) + cs = "with BOM"; + PyErr_Format(PyExc_SyntaxError, "encoding problem: %s", cs); } return r; } @@ -376,9 +367,7 @@ } if (tok->encoding != NULL) PyMem_FREE(tok->encoding); - tok->encoding = new_string("utf-8", 5, tok); - if (!tok->encoding) - return 0; + tok->encoding = new_string("utf-8", 5); /* resulting is in utf-8 */ /* No need to set_readline: input is already utf-8 */ return 1; } @@ -671,8 +660,7 @@ static char * translate_newlines(const char *s, int exec_input, struct tok_state *tok) { - int skip_next_lf = 0; - size_t needed_length = strlen(s) + 2, final_length; + int skip_next_lf = 0, needed_length = strlen(s) + 2, final_length; char *buf, *current; char c = '\0'; buf = PyMem_MALLOC(needed_length); @@ -1734,6 +1722,10 @@ if (fd < 0) { return NULL; } +#ifndef PGEN + _Py_try_set_default_cloexec(fd); +#endif + fp = fdopen(fd, "r"); if (fp == NULL) { return NULL; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/Python-ast.c --- a/Python/Python-ast.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/Python-ast.c Fri Feb 01 23:12:09 2013 +0100 @@ -11,26 +11,26 @@ static PyTypeObject *Module_type; _Py_IDENTIFIER(body); static char *Module_fields[]={ - "body", + "body", }; static PyTypeObject *Interactive_type; static char *Interactive_fields[]={ - "body", + "body", }; static PyTypeObject *Expression_type; static char *Expression_fields[]={ - "body", + "body", }; static PyTypeObject *Suite_type; static char *Suite_fields[]={ - "body", + "body", }; static PyTypeObject *stmt_type; _Py_IDENTIFIER(lineno); _Py_IDENTIFIER(col_offset); static char *stmt_attributes[] = { - "lineno", - "col_offset", + "lineno", + "col_offset", }; static PyObject* ast2obj_stmt(void*); static PyTypeObject *FunctionDef_type; @@ -39,11 +39,11 @@ _Py_IDENTIFIER(decorator_list); _Py_IDENTIFIER(returns); static char *FunctionDef_fields[]={ - "name", - "args", - "body", - "decorator_list", - "returns", + "name", + "args", + "body", + "decorator_list", + "returns", }; static PyTypeObject *ClassDef_type; _Py_IDENTIFIER(bases); @@ -51,266 +51,266 @@ _Py_IDENTIFIER(starargs); _Py_IDENTIFIER(kwargs); static char *ClassDef_fields[]={ - "name", - "bases", - "keywords", - "starargs", - "kwargs", - "body", - "decorator_list", + "name", + "bases", + "keywords", + "starargs", + "kwargs", + "body", + "decorator_list", }; static PyTypeObject *Return_type; _Py_IDENTIFIER(value); static char *Return_fields[]={ - "value", + "value", }; static PyTypeObject *Delete_type; _Py_IDENTIFIER(targets); static char *Delete_fields[]={ - "targets", + "targets", }; static PyTypeObject *Assign_type; static char *Assign_fields[]={ - "targets", - "value", + "targets", + "value", }; static PyTypeObject *AugAssign_type; _Py_IDENTIFIER(target); _Py_IDENTIFIER(op); static char *AugAssign_fields[]={ - "target", - "op", - "value", + "target", + "op", + "value", }; static PyTypeObject *For_type; _Py_IDENTIFIER(iter); _Py_IDENTIFIER(orelse); static char *For_fields[]={ - "target", - "iter", - "body", - "orelse", + "target", + "iter", + "body", + "orelse", }; static PyTypeObject *While_type; _Py_IDENTIFIER(test); static char *While_fields[]={ - "test", - "body", - "orelse", + "test", + "body", + "orelse", }; static PyTypeObject *If_type; static char *If_fields[]={ - "test", - "body", - "orelse", + "test", + "body", + "orelse", }; static PyTypeObject *With_type; _Py_IDENTIFIER(items); static char *With_fields[]={ - "items", - "body", + "items", + "body", }; static PyTypeObject *Raise_type; _Py_IDENTIFIER(exc); _Py_IDENTIFIER(cause); static char *Raise_fields[]={ - "exc", - "cause", + "exc", + "cause", }; static PyTypeObject *Try_type; _Py_IDENTIFIER(handlers); _Py_IDENTIFIER(finalbody); static char *Try_fields[]={ - "body", - "handlers", - "orelse", - "finalbody", + "body", + "handlers", + "orelse", + "finalbody", }; static PyTypeObject *Assert_type; _Py_IDENTIFIER(msg); static char *Assert_fields[]={ - "test", - "msg", + "test", + "msg", }; static PyTypeObject *Import_type; _Py_IDENTIFIER(names); static char *Import_fields[]={ - "names", + "names", }; static PyTypeObject *ImportFrom_type; _Py_IDENTIFIER(module); _Py_IDENTIFIER(level); static char *ImportFrom_fields[]={ - "module", - "names", - "level", + "module", + "names", + "level", }; static PyTypeObject *Global_type; static char *Global_fields[]={ - "names", + "names", }; static PyTypeObject *Nonlocal_type; static char *Nonlocal_fields[]={ - "names", + "names", }; static PyTypeObject *Expr_type; static char *Expr_fields[]={ - "value", + "value", }; static PyTypeObject *Pass_type; static PyTypeObject *Break_type; static PyTypeObject *Continue_type; static PyTypeObject *expr_type; static char *expr_attributes[] = { - "lineno", - "col_offset", + "lineno", + "col_offset", }; static PyObject* ast2obj_expr(void*); static PyTypeObject *BoolOp_type; _Py_IDENTIFIER(values); static char *BoolOp_fields[]={ - "op", - "values", + "op", + "values", }; static PyTypeObject *BinOp_type; _Py_IDENTIFIER(left); _Py_IDENTIFIER(right); static char *BinOp_fields[]={ - "left", - "op", - "right", + "left", + "op", + "right", }; static PyTypeObject *UnaryOp_type; _Py_IDENTIFIER(operand); static char *UnaryOp_fields[]={ - "op", - "operand", + "op", + "operand", }; static PyTypeObject *Lambda_type; static char *Lambda_fields[]={ - "args", - "body", + "args", + "body", }; static PyTypeObject *IfExp_type; static char *IfExp_fields[]={ - "test", - "body", - "orelse", + "test", + "body", + "orelse", }; static PyTypeObject *Dict_type; _Py_IDENTIFIER(keys); static char *Dict_fields[]={ - "keys", - "values", + "keys", + "values", }; static PyTypeObject *Set_type; _Py_IDENTIFIER(elts); static char *Set_fields[]={ - "elts", + "elts", }; static PyTypeObject *ListComp_type; _Py_IDENTIFIER(elt); _Py_IDENTIFIER(generators); static char *ListComp_fields[]={ - "elt", - "generators", + "elt", + "generators", }; static PyTypeObject *SetComp_type; static char *SetComp_fields[]={ - "elt", - "generators", + "elt", + "generators", }; static PyTypeObject *DictComp_type; _Py_IDENTIFIER(key); static char *DictComp_fields[]={ - "key", - "value", - "generators", + "key", + "value", + "generators", }; static PyTypeObject *GeneratorExp_type; static char *GeneratorExp_fields[]={ - "elt", - "generators", + "elt", + "generators", }; static PyTypeObject *Yield_type; static char *Yield_fields[]={ - "value", + "value", }; static PyTypeObject *YieldFrom_type; static char *YieldFrom_fields[]={ - "value", + "value", }; static PyTypeObject *Compare_type; _Py_IDENTIFIER(ops); _Py_IDENTIFIER(comparators); static char *Compare_fields[]={ - "left", - "ops", - "comparators", + "left", + "ops", + "comparators", }; static PyTypeObject *Call_type; _Py_IDENTIFIER(func); static char *Call_fields[]={ - "func", - "args", - "keywords", - "starargs", - "kwargs", + "func", + "args", + "keywords", + "starargs", + "kwargs", }; static PyTypeObject *Num_type; _Py_IDENTIFIER(n); static char *Num_fields[]={ - "n", + "n", }; static PyTypeObject *Str_type; _Py_IDENTIFIER(s); static char *Str_fields[]={ - "s", + "s", }; static PyTypeObject *Bytes_type; static char *Bytes_fields[]={ - "s", + "s", }; static PyTypeObject *NameConstant_type; static char *NameConstant_fields[]={ - "value", + "value", }; static PyTypeObject *Ellipsis_type; static PyTypeObject *Attribute_type; _Py_IDENTIFIER(attr); _Py_IDENTIFIER(ctx); static char *Attribute_fields[]={ - "value", - "attr", - "ctx", + "value", + "attr", + "ctx", }; static PyTypeObject *Subscript_type; _Py_IDENTIFIER(slice); static char *Subscript_fields[]={ - "value", - "slice", - "ctx", + "value", + "slice", + "ctx", }; static PyTypeObject *Starred_type; static char *Starred_fields[]={ - "value", - "ctx", + "value", + "ctx", }; static PyTypeObject *Name_type; _Py_IDENTIFIER(id); static char *Name_fields[]={ - "id", - "ctx", + "id", + "ctx", }; static PyTypeObject *List_type; static char *List_fields[]={ - "elts", - "ctx", + "elts", + "ctx", }; static PyTypeObject *Tuple_type; static char *Tuple_fields[]={ - "elts", - "ctx", + "elts", + "ctx", }; static PyTypeObject *expr_context_type; static PyObject *Load_singleton, *Store_singleton, *Del_singleton, @@ -329,18 +329,18 @@ _Py_IDENTIFIER(upper); _Py_IDENTIFIER(step); static char *Slice_fields[]={ - "lower", - "upper", - "step", + "lower", + "upper", + "step", }; static PyTypeObject *ExtSlice_type; _Py_IDENTIFIER(dims); static char *ExtSlice_fields[]={ - "dims", + "dims", }; static PyTypeObject *Index_type; static char *Index_fields[]={ - "value", + "value", }; static PyTypeObject *boolop_type; static PyObject *And_singleton, *Or_singleton; @@ -392,70 +392,70 @@ static PyObject* ast2obj_comprehension(void*); _Py_IDENTIFIER(ifs); static char *comprehension_fields[]={ - "target", - "iter", - "ifs", + "target", + "iter", + "ifs", }; static PyTypeObject *excepthandler_type; static char *excepthandler_attributes[] = { - "lineno", - "col_offset", + "lineno", + "col_offset", }; static PyObject* ast2obj_excepthandler(void*); static PyTypeObject *ExceptHandler_type; _Py_IDENTIFIER(type); static char *ExceptHandler_fields[]={ - "type", - "name", - "body", + "type", + "name", + "body", }; static PyTypeObject *arguments_type; static PyObject* ast2obj_arguments(void*); _Py_IDENTIFIER(vararg); +_Py_IDENTIFIER(varargannotation); _Py_IDENTIFIER(kwonlyargs); +_Py_IDENTIFIER(kwarg); +_Py_IDENTIFIER(kwargannotation); +_Py_IDENTIFIER(defaults); _Py_IDENTIFIER(kw_defaults); -_Py_IDENTIFIER(kwarg); -_Py_IDENTIFIER(defaults); static char *arguments_fields[]={ - "args", - "vararg", - "kwonlyargs", - "kw_defaults", - "kwarg", - "defaults", + "args", + "vararg", + "varargannotation", + "kwonlyargs", + "kwarg", + "kwargannotation", + "defaults", + "kw_defaults", }; static PyTypeObject *arg_type; static PyObject* ast2obj_arg(void*); -static char *arg_attributes[] = { - "lineno", - "col_offset", -}; _Py_IDENTIFIER(arg); _Py_IDENTIFIER(annotation); static char *arg_fields[]={ - "arg", - "annotation", + "arg", + "annotation", }; static PyTypeObject *keyword_type; static PyObject* ast2obj_keyword(void*); static char *keyword_fields[]={ - "arg", - "value", + "arg", + "value", }; static PyTypeObject *alias_type; static PyObject* ast2obj_alias(void*); _Py_IDENTIFIER(asname); static char *alias_fields[]={ - "name", - "asname", + "name", + "asname", }; static PyTypeObject *withitem_type; static PyObject* ast2obj_withitem(void*); _Py_IDENTIFIER(context_expr); _Py_IDENTIFIER(optional_vars); static char *withitem_fields[]={ - "context_expr", - "optional_vars", + "context_expr", + "optional_vars", }; @@ -704,13 +704,9 @@ { if (obj == Py_None) obj = NULL; - if (obj) { - if (PyArena_AddPyObject(arena, obj) < 0) { - *out = NULL; - return -1; - } - Py_INCREF(obj); - } + if (obj) + PyArena_AddPyObject(arena, obj); + Py_XINCREF(obj); *out = obj; return 0; } @@ -774,328 +770,311 @@ return 0; } -static int exists_not_none(PyObject *obj, _Py_Identifier *id) -{ - int isnone; - PyObject *attr = _PyObject_GetAttrId(obj, id); - if (!attr) { - PyErr_Clear(); - return 0; - } - isnone = attr == Py_None; - Py_DECREF(attr); - return !isnone; -} - static int init_types(void) { - static int initialized; - if (initialized) return 1; - if (add_ast_fields() < 0) return 0; - mod_type = make_type("mod", &AST_type, NULL, 0); - if (!mod_type) return 0; - if (!add_attributes(mod_type, NULL, 0)) return 0; - Module_type = make_type("Module", mod_type, Module_fields, 1); - if (!Module_type) return 0; - Interactive_type = make_type("Interactive", mod_type, Interactive_fields, - 1); - if (!Interactive_type) return 0; - Expression_type = make_type("Expression", mod_type, Expression_fields, 1); - if (!Expression_type) return 0; - Suite_type = make_type("Suite", mod_type, Suite_fields, 1); - if (!Suite_type) return 0; - stmt_type = make_type("stmt", &AST_type, NULL, 0); - if (!stmt_type) return 0; - if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; - FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, - 5); - if (!FunctionDef_type) return 0; - ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); - if (!ClassDef_type) return 0; - Return_type = make_type("Return", stmt_type, Return_fields, 1); - if (!Return_type) return 0; - Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); - if (!Delete_type) return 0; - Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); - if (!Assign_type) return 0; - AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); - if (!AugAssign_type) return 0; - For_type = make_type("For", stmt_type, For_fields, 4); - if (!For_type) return 0; - While_type = make_type("While", stmt_type, While_fields, 3); - if (!While_type) return 0; - If_type = make_type("If", stmt_type, If_fields, 3); - if (!If_type) return 0; - With_type = make_type("With", stmt_type, With_fields, 2); - if (!With_type) return 0; - Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); - if (!Raise_type) return 0; - Try_type = make_type("Try", stmt_type, Try_fields, 4); - if (!Try_type) return 0; - Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); - if (!Assert_type) return 0; - Import_type = make_type("Import", stmt_type, Import_fields, 1); - if (!Import_type) return 0; - ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); - if (!ImportFrom_type) return 0; - Global_type = make_type("Global", stmt_type, Global_fields, 1); - if (!Global_type) return 0; - Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); - if (!Nonlocal_type) return 0; - Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); - if (!Expr_type) return 0; - Pass_type = make_type("Pass", stmt_type, NULL, 0); - if (!Pass_type) return 0; - Break_type = make_type("Break", stmt_type, NULL, 0); - if (!Break_type) return 0; - Continue_type = make_type("Continue", stmt_type, NULL, 0); - if (!Continue_type) return 0; - expr_type = make_type("expr", &AST_type, NULL, 0); - if (!expr_type) return 0; - if (!add_attributes(expr_type, expr_attributes, 2)) return 0; - BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); - if (!BoolOp_type) return 0; - BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); - if (!BinOp_type) return 0; - UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); - if (!UnaryOp_type) return 0; - Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); - if (!Lambda_type) return 0; - IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); - if (!IfExp_type) return 0; - Dict_type = make_type("Dict", expr_type, Dict_fields, 2); - if (!Dict_type) return 0; - Set_type = make_type("Set", expr_type, Set_fields, 1); - if (!Set_type) return 0; - ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); - if (!ListComp_type) return 0; - SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); - if (!SetComp_type) return 0; - DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); - if (!DictComp_type) return 0; - GeneratorExp_type = make_type("GeneratorExp", expr_type, - GeneratorExp_fields, 2); - if (!GeneratorExp_type) return 0; - Yield_type = make_type("Yield", expr_type, Yield_fields, 1); - if (!Yield_type) return 0; - YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); - if (!YieldFrom_type) return 0; - Compare_type = make_type("Compare", expr_type, Compare_fields, 3); - if (!Compare_type) return 0; - Call_type = make_type("Call", expr_type, Call_fields, 5); - if (!Call_type) return 0; - Num_type = make_type("Num", expr_type, Num_fields, 1); - if (!Num_type) return 0; - Str_type = make_type("Str", expr_type, Str_fields, 1); - if (!Str_type) return 0; - Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); - if (!Bytes_type) return 0; - NameConstant_type = make_type("NameConstant", expr_type, - NameConstant_fields, 1); - if (!NameConstant_type) return 0; - Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); - if (!Ellipsis_type) return 0; - Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); - if (!Attribute_type) return 0; - Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); - if (!Subscript_type) return 0; - Starred_type = make_type("Starred", expr_type, Starred_fields, 2); - if (!Starred_type) return 0; - Name_type = make_type("Name", expr_type, Name_fields, 2); - if (!Name_type) return 0; - List_type = make_type("List", expr_type, List_fields, 2); - if (!List_type) return 0; - Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); - if (!Tuple_type) return 0; - expr_context_type = make_type("expr_context", &AST_type, NULL, 0); - if (!expr_context_type) return 0; - if (!add_attributes(expr_context_type, NULL, 0)) return 0; - Load_type = make_type("Load", expr_context_type, NULL, 0); - if (!Load_type) return 0; - Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); - if (!Load_singleton) return 0; - Store_type = make_type("Store", expr_context_type, NULL, 0); - if (!Store_type) return 0; - Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); - if (!Store_singleton) return 0; - Del_type = make_type("Del", expr_context_type, NULL, 0); - if (!Del_type) return 0; - Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); - if (!Del_singleton) return 0; - AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); - if (!AugLoad_type) return 0; - AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); - if (!AugLoad_singleton) return 0; - AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); - if (!AugStore_type) return 0; - AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); - if (!AugStore_singleton) return 0; - Param_type = make_type("Param", expr_context_type, NULL, 0); - if (!Param_type) return 0; - Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); - if (!Param_singleton) return 0; - slice_type = make_type("slice", &AST_type, NULL, 0); - if (!slice_type) return 0; - if (!add_attributes(slice_type, NULL, 0)) return 0; - Slice_type = make_type("Slice", slice_type, Slice_fields, 3); - if (!Slice_type) return 0; - ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); - if (!ExtSlice_type) return 0; - Index_type = make_type("Index", slice_type, Index_fields, 1); - if (!Index_type) return 0; - boolop_type = make_type("boolop", &AST_type, NULL, 0); - if (!boolop_type) return 0; - if (!add_attributes(boolop_type, NULL, 0)) return 0; - And_type = make_type("And", boolop_type, NULL, 0); - if (!And_type) return 0; - And_singleton = PyType_GenericNew(And_type, NULL, NULL); - if (!And_singleton) return 0; - Or_type = make_type("Or", boolop_type, NULL, 0); - if (!Or_type) return 0; - Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); - if (!Or_singleton) return 0; - operator_type = make_type("operator", &AST_type, NULL, 0); - if (!operator_type) return 0; - if (!add_attributes(operator_type, NULL, 0)) return 0; - Add_type = make_type("Add", operator_type, NULL, 0); - if (!Add_type) return 0; - Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); - if (!Add_singleton) return 0; - Sub_type = make_type("Sub", operator_type, NULL, 0); - if (!Sub_type) return 0; - Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); - if (!Sub_singleton) return 0; - Mult_type = make_type("Mult", operator_type, NULL, 0); - if (!Mult_type) return 0; - Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); - if (!Mult_singleton) return 0; - Div_type = make_type("Div", operator_type, NULL, 0); - if (!Div_type) return 0; - Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); - if (!Div_singleton) return 0; - Mod_type = make_type("Mod", operator_type, NULL, 0); - if (!Mod_type) return 0; - Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); - if (!Mod_singleton) return 0; - Pow_type = make_type("Pow", operator_type, NULL, 0); - if (!Pow_type) return 0; - Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); - if (!Pow_singleton) return 0; - LShift_type = make_type("LShift", operator_type, NULL, 0); - if (!LShift_type) return 0; - LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); - if (!LShift_singleton) return 0; - RShift_type = make_type("RShift", operator_type, NULL, 0); - if (!RShift_type) return 0; - RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); - if (!RShift_singleton) return 0; - BitOr_type = make_type("BitOr", operator_type, NULL, 0); - if (!BitOr_type) return 0; - BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); - if (!BitOr_singleton) return 0; - BitXor_type = make_type("BitXor", operator_type, NULL, 0); - if (!BitXor_type) return 0; - BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); - if (!BitXor_singleton) return 0; - BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); - if (!BitAnd_type) return 0; - BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); - if (!BitAnd_singleton) return 0; - FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); - if (!FloorDiv_type) return 0; - FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); - if (!FloorDiv_singleton) return 0; - unaryop_type = make_type("unaryop", &AST_type, NULL, 0); - if (!unaryop_type) return 0; - if (!add_attributes(unaryop_type, NULL, 0)) return 0; - Invert_type = make_type("Invert", unaryop_type, NULL, 0); - if (!Invert_type) return 0; - Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); - if (!Invert_singleton) return 0; - Not_type = make_type("Not", unaryop_type, NULL, 0); - if (!Not_type) return 0; - Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); - if (!Not_singleton) return 0; - UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); - if (!UAdd_type) return 0; - UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); - if (!UAdd_singleton) return 0; - USub_type = make_type("USub", unaryop_type, NULL, 0); - if (!USub_type) return 0; - USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); - if (!USub_singleton) return 0; - cmpop_type = make_type("cmpop", &AST_type, NULL, 0); - if (!cmpop_type) return 0; - if (!add_attributes(cmpop_type, NULL, 0)) return 0; - Eq_type = make_type("Eq", cmpop_type, NULL, 0); - if (!Eq_type) return 0; - Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); - if (!Eq_singleton) return 0; - NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); - if (!NotEq_type) return 0; - NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); - if (!NotEq_singleton) return 0; - Lt_type = make_type("Lt", cmpop_type, NULL, 0); - if (!Lt_type) return 0; - Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); - if (!Lt_singleton) return 0; - LtE_type = make_type("LtE", cmpop_type, NULL, 0); - if (!LtE_type) return 0; - LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); - if (!LtE_singleton) return 0; - Gt_type = make_type("Gt", cmpop_type, NULL, 0); - if (!Gt_type) return 0; - Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); - if (!Gt_singleton) return 0; - GtE_type = make_type("GtE", cmpop_type, NULL, 0); - if (!GtE_type) return 0; - GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); - if (!GtE_singleton) return 0; - Is_type = make_type("Is", cmpop_type, NULL, 0); - if (!Is_type) return 0; - Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); - if (!Is_singleton) return 0; - IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); - if (!IsNot_type) return 0; - IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); - if (!IsNot_singleton) return 0; - In_type = make_type("In", cmpop_type, NULL, 0); - if (!In_type) return 0; - In_singleton = PyType_GenericNew(In_type, NULL, NULL); - if (!In_singleton) return 0; - NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); - if (!NotIn_type) return 0; - NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); - if (!NotIn_singleton) return 0; - comprehension_type = make_type("comprehension", &AST_type, - comprehension_fields, 3); - if (!comprehension_type) return 0; - if (!add_attributes(comprehension_type, NULL, 0)) return 0; - excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); - if (!excepthandler_type) return 0; - if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) - return 0; - ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, - ExceptHandler_fields, 3); - if (!ExceptHandler_type) return 0; - arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); - if (!arguments_type) return 0; - if (!add_attributes(arguments_type, NULL, 0)) return 0; - arg_type = make_type("arg", &AST_type, arg_fields, 2); - if (!arg_type) return 0; - if (!add_attributes(arg_type, arg_attributes, 2)) return 0; - keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); - if (!keyword_type) return 0; - if (!add_attributes(keyword_type, NULL, 0)) return 0; - alias_type = make_type("alias", &AST_type, alias_fields, 2); - if (!alias_type) return 0; - if (!add_attributes(alias_type, NULL, 0)) return 0; - withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); - if (!withitem_type) return 0; - if (!add_attributes(withitem_type, NULL, 0)) return 0; - initialized = 1; - return 1; + static int initialized; + if (initialized) return 1; + if (add_ast_fields() < 0) return 0; + mod_type = make_type("mod", &AST_type, NULL, 0); + if (!mod_type) return 0; + if (!add_attributes(mod_type, NULL, 0)) return 0; + Module_type = make_type("Module", mod_type, Module_fields, 1); + if (!Module_type) return 0; + Interactive_type = make_type("Interactive", mod_type, + Interactive_fields, 1); + if (!Interactive_type) return 0; + Expression_type = make_type("Expression", mod_type, Expression_fields, + 1); + if (!Expression_type) return 0; + Suite_type = make_type("Suite", mod_type, Suite_fields, 1); + if (!Suite_type) return 0; + stmt_type = make_type("stmt", &AST_type, NULL, 0); + if (!stmt_type) return 0; + if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; + FunctionDef_type = make_type("FunctionDef", stmt_type, + FunctionDef_fields, 5); + if (!FunctionDef_type) return 0; + ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); + if (!ClassDef_type) return 0; + Return_type = make_type("Return", stmt_type, Return_fields, 1); + if (!Return_type) return 0; + Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); + if (!Delete_type) return 0; + Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); + if (!Assign_type) return 0; + AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); + if (!AugAssign_type) return 0; + For_type = make_type("For", stmt_type, For_fields, 4); + if (!For_type) return 0; + While_type = make_type("While", stmt_type, While_fields, 3); + if (!While_type) return 0; + If_type = make_type("If", stmt_type, If_fields, 3); + if (!If_type) return 0; + With_type = make_type("With", stmt_type, With_fields, 2); + if (!With_type) return 0; + Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); + if (!Raise_type) return 0; + Try_type = make_type("Try", stmt_type, Try_fields, 4); + if (!Try_type) return 0; + Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); + if (!Assert_type) return 0; + Import_type = make_type("Import", stmt_type, Import_fields, 1); + if (!Import_type) return 0; + ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, + 3); + if (!ImportFrom_type) return 0; + Global_type = make_type("Global", stmt_type, Global_fields, 1); + if (!Global_type) return 0; + Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); + if (!Nonlocal_type) return 0; + Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); + if (!Expr_type) return 0; + Pass_type = make_type("Pass", stmt_type, NULL, 0); + if (!Pass_type) return 0; + Break_type = make_type("Break", stmt_type, NULL, 0); + if (!Break_type) return 0; + Continue_type = make_type("Continue", stmt_type, NULL, 0); + if (!Continue_type) return 0; + expr_type = make_type("expr", &AST_type, NULL, 0); + if (!expr_type) return 0; + if (!add_attributes(expr_type, expr_attributes, 2)) return 0; + BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); + if (!BoolOp_type) return 0; + BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); + if (!BinOp_type) return 0; + UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); + if (!UnaryOp_type) return 0; + Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); + if (!Lambda_type) return 0; + IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); + if (!IfExp_type) return 0; + Dict_type = make_type("Dict", expr_type, Dict_fields, 2); + if (!Dict_type) return 0; + Set_type = make_type("Set", expr_type, Set_fields, 1); + if (!Set_type) return 0; + ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); + if (!ListComp_type) return 0; + SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); + if (!SetComp_type) return 0; + DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); + if (!DictComp_type) return 0; + GeneratorExp_type = make_type("GeneratorExp", expr_type, + GeneratorExp_fields, 2); + if (!GeneratorExp_type) return 0; + Yield_type = make_type("Yield", expr_type, Yield_fields, 1); + if (!Yield_type) return 0; + YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); + if (!YieldFrom_type) return 0; + Compare_type = make_type("Compare", expr_type, Compare_fields, 3); + if (!Compare_type) return 0; + Call_type = make_type("Call", expr_type, Call_fields, 5); + if (!Call_type) return 0; + Num_type = make_type("Num", expr_type, Num_fields, 1); + if (!Num_type) return 0; + Str_type = make_type("Str", expr_type, Str_fields, 1); + if (!Str_type) return 0; + Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); + if (!Bytes_type) return 0; + NameConstant_type = make_type("NameConstant", expr_type, + NameConstant_fields, 1); + if (!NameConstant_type) return 0; + Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); + if (!Ellipsis_type) return 0; + Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); + if (!Attribute_type) return 0; + Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); + if (!Subscript_type) return 0; + Starred_type = make_type("Starred", expr_type, Starred_fields, 2); + if (!Starred_type) return 0; + Name_type = make_type("Name", expr_type, Name_fields, 2); + if (!Name_type) return 0; + List_type = make_type("List", expr_type, List_fields, 2); + if (!List_type) return 0; + Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); + if (!Tuple_type) return 0; + expr_context_type = make_type("expr_context", &AST_type, NULL, 0); + if (!expr_context_type) return 0; + if (!add_attributes(expr_context_type, NULL, 0)) return 0; + Load_type = make_type("Load", expr_context_type, NULL, 0); + if (!Load_type) return 0; + Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); + if (!Load_singleton) return 0; + Store_type = make_type("Store", expr_context_type, NULL, 0); + if (!Store_type) return 0; + Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); + if (!Store_singleton) return 0; + Del_type = make_type("Del", expr_context_type, NULL, 0); + if (!Del_type) return 0; + Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); + if (!Del_singleton) return 0; + AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); + if (!AugLoad_type) return 0; + AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); + if (!AugLoad_singleton) return 0; + AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); + if (!AugStore_type) return 0; + AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); + if (!AugStore_singleton) return 0; + Param_type = make_type("Param", expr_context_type, NULL, 0); + if (!Param_type) return 0; + Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); + if (!Param_singleton) return 0; + slice_type = make_type("slice", &AST_type, NULL, 0); + if (!slice_type) return 0; + if (!add_attributes(slice_type, NULL, 0)) return 0; + Slice_type = make_type("Slice", slice_type, Slice_fields, 3); + if (!Slice_type) return 0; + ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); + if (!ExtSlice_type) return 0; + Index_type = make_type("Index", slice_type, Index_fields, 1); + if (!Index_type) return 0; + boolop_type = make_type("boolop", &AST_type, NULL, 0); + if (!boolop_type) return 0; + if (!add_attributes(boolop_type, NULL, 0)) return 0; + And_type = make_type("And", boolop_type, NULL, 0); + if (!And_type) return 0; + And_singleton = PyType_GenericNew(And_type, NULL, NULL); + if (!And_singleton) return 0; + Or_type = make_type("Or", boolop_type, NULL, 0); + if (!Or_type) return 0; + Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); + if (!Or_singleton) return 0; + operator_type = make_type("operator", &AST_type, NULL, 0); + if (!operator_type) return 0; + if (!add_attributes(operator_type, NULL, 0)) return 0; + Add_type = make_type("Add", operator_type, NULL, 0); + if (!Add_type) return 0; + Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); + if (!Add_singleton) return 0; + Sub_type = make_type("Sub", operator_type, NULL, 0); + if (!Sub_type) return 0; + Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); + if (!Sub_singleton) return 0; + Mult_type = make_type("Mult", operator_type, NULL, 0); + if (!Mult_type) return 0; + Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); + if (!Mult_singleton) return 0; + Div_type = make_type("Div", operator_type, NULL, 0); + if (!Div_type) return 0; + Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); + if (!Div_singleton) return 0; + Mod_type = make_type("Mod", operator_type, NULL, 0); + if (!Mod_type) return 0; + Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); + if (!Mod_singleton) return 0; + Pow_type = make_type("Pow", operator_type, NULL, 0); + if (!Pow_type) return 0; + Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); + if (!Pow_singleton) return 0; + LShift_type = make_type("LShift", operator_type, NULL, 0); + if (!LShift_type) return 0; + LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); + if (!LShift_singleton) return 0; + RShift_type = make_type("RShift", operator_type, NULL, 0); + if (!RShift_type) return 0; + RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); + if (!RShift_singleton) return 0; + BitOr_type = make_type("BitOr", operator_type, NULL, 0); + if (!BitOr_type) return 0; + BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); + if (!BitOr_singleton) return 0; + BitXor_type = make_type("BitXor", operator_type, NULL, 0); + if (!BitXor_type) return 0; + BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); + if (!BitXor_singleton) return 0; + BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); + if (!BitAnd_type) return 0; + BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); + if (!BitAnd_singleton) return 0; + FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); + if (!FloorDiv_type) return 0; + FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); + if (!FloorDiv_singleton) return 0; + unaryop_type = make_type("unaryop", &AST_type, NULL, 0); + if (!unaryop_type) return 0; + if (!add_attributes(unaryop_type, NULL, 0)) return 0; + Invert_type = make_type("Invert", unaryop_type, NULL, 0); + if (!Invert_type) return 0; + Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); + if (!Invert_singleton) return 0; + Not_type = make_type("Not", unaryop_type, NULL, 0); + if (!Not_type) return 0; + Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); + if (!Not_singleton) return 0; + UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); + if (!UAdd_type) return 0; + UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); + if (!UAdd_singleton) return 0; + USub_type = make_type("USub", unaryop_type, NULL, 0); + if (!USub_type) return 0; + USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); + if (!USub_singleton) return 0; + cmpop_type = make_type("cmpop", &AST_type, NULL, 0); + if (!cmpop_type) return 0; + if (!add_attributes(cmpop_type, NULL, 0)) return 0; + Eq_type = make_type("Eq", cmpop_type, NULL, 0); + if (!Eq_type) return 0; + Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); + if (!Eq_singleton) return 0; + NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); + if (!NotEq_type) return 0; + NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); + if (!NotEq_singleton) return 0; + Lt_type = make_type("Lt", cmpop_type, NULL, 0); + if (!Lt_type) return 0; + Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); + if (!Lt_singleton) return 0; + LtE_type = make_type("LtE", cmpop_type, NULL, 0); + if (!LtE_type) return 0; + LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); + if (!LtE_singleton) return 0; + Gt_type = make_type("Gt", cmpop_type, NULL, 0); + if (!Gt_type) return 0; + Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); + if (!Gt_singleton) return 0; + GtE_type = make_type("GtE", cmpop_type, NULL, 0); + if (!GtE_type) return 0; + GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); + if (!GtE_singleton) return 0; + Is_type = make_type("Is", cmpop_type, NULL, 0); + if (!Is_type) return 0; + Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); + if (!Is_singleton) return 0; + IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); + if (!IsNot_type) return 0; + IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); + if (!IsNot_singleton) return 0; + In_type = make_type("In", cmpop_type, NULL, 0); + if (!In_type) return 0; + In_singleton = PyType_GenericNew(In_type, NULL, NULL); + if (!In_singleton) return 0; + NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); + if (!NotIn_type) return 0; + NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); + if (!NotIn_singleton) return 0; + comprehension_type = make_type("comprehension", &AST_type, + comprehension_fields, 3); + if (!comprehension_type) return 0; + excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); + if (!excepthandler_type) return 0; + if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) + return 0; + ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, + ExceptHandler_fields, 3); + if (!ExceptHandler_type) return 0; + arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); + if (!arguments_type) return 0; + arg_type = make_type("arg", &AST_type, arg_fields, 2); + if (!arg_type) return 0; + keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); + if (!keyword_type) return 0; + alias_type = make_type("alias", &AST_type, alias_fields, 2); + if (!alias_type) return 0; + withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); + if (!withitem_type) return 0; + initialized = 1; + return 1; } static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); @@ -1121,54 +1100,54 @@ mod_ty Module(asdl_seq * body, PyArena *arena) { - mod_ty p; - p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Module_kind; - p->v.Module.body = body; - return p; + mod_ty p; + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Module_kind; + p->v.Module.body = body; + return p; } mod_ty Interactive(asdl_seq * body, PyArena *arena) { - mod_ty p; - p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Interactive_kind; - p->v.Interactive.body = body; - return p; + mod_ty p; + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Interactive_kind; + p->v.Interactive.body = body; + return p; } mod_ty Expression(expr_ty body, PyArena *arena) { - mod_ty p; - if (!body) { - PyErr_SetString(PyExc_ValueError, - "field body is required for Expression"); - return NULL; - } - p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Expression_kind; - p->v.Expression.body = body; - return p; + mod_ty p; + if (!body) { + PyErr_SetString(PyExc_ValueError, + "field body is required for Expression"); + return NULL; + } + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Expression_kind; + p->v.Expression.body = body; + return p; } mod_ty Suite(asdl_seq * body, PyArena *arena) { - mod_ty p; - p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Suite_kind; - p->v.Suite.body = body; - return p; + mod_ty p; + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Suite_kind; + p->v.Suite.body = body; + return p; } stmt_ty @@ -1176,29 +1155,29 @@ decorator_list, expr_ty returns, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!name) { - PyErr_SetString(PyExc_ValueError, - "field name is required for FunctionDef"); - return NULL; - } - if (!args) { - PyErr_SetString(PyExc_ValueError, - "field args is required for FunctionDef"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = FunctionDef_kind; - p->v.FunctionDef.name = name; - p->v.FunctionDef.args = args; - p->v.FunctionDef.body = body; - p->v.FunctionDef.decorator_list = decorator_list; - p->v.FunctionDef.returns = returns; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!name) { + PyErr_SetString(PyExc_ValueError, + "field name is required for FunctionDef"); + return NULL; + } + if (!args) { + PyErr_SetString(PyExc_ValueError, + "field args is required for FunctionDef"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = FunctionDef_kind; + p->v.FunctionDef.name = name; + p->v.FunctionDef.args = args; + p->v.FunctionDef.body = body; + p->v.FunctionDef.decorator_list = decorator_list; + p->v.FunctionDef.returns = returns; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty @@ -1206,5618 +1185,5790 @@ starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!name) { - PyErr_SetString(PyExc_ValueError, - "field name is required for ClassDef"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = ClassDef_kind; - p->v.ClassDef.name = name; - p->v.ClassDef.bases = bases; - p->v.ClassDef.keywords = keywords; - p->v.ClassDef.starargs = starargs; - p->v.ClassDef.kwargs = kwargs; - p->v.ClassDef.body = body; - p->v.ClassDef.decorator_list = decorator_list; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!name) { + PyErr_SetString(PyExc_ValueError, + "field name is required for ClassDef"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = ClassDef_kind; + p->v.ClassDef.name = name; + p->v.ClassDef.bases = bases; + p->v.ClassDef.keywords = keywords; + p->v.ClassDef.starargs = starargs; + p->v.ClassDef.kwargs = kwargs; + p->v.ClassDef.body = body; + p->v.ClassDef.decorator_list = decorator_list; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Return(expr_ty value, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Return_kind; - p->v.Return.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Return_kind; + p->v.Return.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Delete_kind; - p->v.Delete.targets = targets; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Delete_kind; + p->v.Delete.targets = targets; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Assign"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Assign_kind; - p->v.Assign.targets = targets; - p->v.Assign.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for Assign"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Assign_kind; + p->v.Assign.targets = targets; + p->v.Assign.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!target) { - PyErr_SetString(PyExc_ValueError, - "field target is required for AugAssign"); - return NULL; - } - if (!op) { - PyErr_SetString(PyExc_ValueError, - "field op is required for AugAssign"); - return NULL; - } - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for AugAssign"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = AugAssign_kind; - p->v.AugAssign.target = target; - p->v.AugAssign.op = op; - p->v.AugAssign.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!target) { + PyErr_SetString(PyExc_ValueError, + "field target is required for AugAssign"); + return NULL; + } + if (!op) { + PyErr_SetString(PyExc_ValueError, + "field op is required for AugAssign"); + return NULL; + } + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for AugAssign"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = AugAssign_kind; + p->v.AugAssign.target = target; + p->v.AugAssign.op = op; + p->v.AugAssign.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!target) { - PyErr_SetString(PyExc_ValueError, - "field target is required for For"); - return NULL; - } - if (!iter) { - PyErr_SetString(PyExc_ValueError, - "field iter is required for For"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = For_kind; - p->v.For.target = target; - p->v.For.iter = iter; - p->v.For.body = body; - p->v.For.orelse = orelse; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!target) { + PyErr_SetString(PyExc_ValueError, + "field target is required for For"); + return NULL; + } + if (!iter) { + PyErr_SetString(PyExc_ValueError, + "field iter is required for For"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = For_kind; + p->v.For.target = target; + p->v.For.iter = iter; + p->v.For.body = body; + p->v.For.orelse = orelse; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!test) { - PyErr_SetString(PyExc_ValueError, - "field test is required for While"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = While_kind; - p->v.While.test = test; - p->v.While.body = body; - p->v.While.orelse = orelse; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!test) { + PyErr_SetString(PyExc_ValueError, + "field test is required for While"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = While_kind; + p->v.While.test = test; + p->v.While.body = body; + p->v.While.orelse = orelse; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!test) { - PyErr_SetString(PyExc_ValueError, - "field test is required for If"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = If_kind; - p->v.If.test = test; - p->v.If.body = body; - p->v.If.orelse = orelse; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!test) { + PyErr_SetString(PyExc_ValueError, + "field test is required for If"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = If_kind; + p->v.If.test = test; + p->v.If.body = body; + p->v.If.orelse = orelse; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = With_kind; - p->v.With.items = items; - p->v.With.body = body; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = With_kind; + p->v.With.items = items; + p->v.With.body = body; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Raise_kind; - p->v.Raise.exc = exc; - p->v.Raise.cause = cause; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Raise_kind; + p->v.Raise.exc = exc; + p->v.Raise.cause = cause; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * finalbody, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Try_kind; - p->v.Try.body = body; - p->v.Try.handlers = handlers; - p->v.Try.orelse = orelse; - p->v.Try.finalbody = finalbody; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Try_kind; + p->v.Try.body = body; + p->v.Try.handlers = handlers; + p->v.Try.orelse = orelse; + p->v.Try.finalbody = finalbody; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!test) { - PyErr_SetString(PyExc_ValueError, - "field test is required for Assert"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Assert_kind; - p->v.Assert.test = test; - p->v.Assert.msg = msg; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!test) { + PyErr_SetString(PyExc_ValueError, + "field test is required for Assert"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Assert_kind; + p->v.Assert.test = test; + p->v.Assert.msg = msg; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Import_kind; - p->v.Import.names = names; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Import_kind; + p->v.Import.names = names; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = ImportFrom_kind; - p->v.ImportFrom.module = module; - p->v.ImportFrom.names = names; - p->v.ImportFrom.level = level; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = ImportFrom_kind; + p->v.ImportFrom.module = module; + p->v.ImportFrom.names = names; + p->v.ImportFrom.level = level; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Global_kind; - p->v.Global.names = names; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Global_kind; + p->v.Global.names = names; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Nonlocal_kind; - p->v.Nonlocal.names = names; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Nonlocal_kind; + p->v.Nonlocal.names = names; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Expr"); - return NULL; - } - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Expr_kind; - p->v.Expr.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for Expr"); + return NULL; + } + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Expr_kind; + p->v.Expr.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Pass(int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Pass_kind; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Pass_kind; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Break(int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Break_kind; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Break_kind; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } stmt_ty Continue(int lineno, int col_offset, PyArena *arena) { - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Continue_kind; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + stmt_ty p; + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Continue_kind; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!op) { - PyErr_SetString(PyExc_ValueError, - "field op is required for BoolOp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = BoolOp_kind; - p->v.BoolOp.op = op; - p->v.BoolOp.values = values; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!op) { + PyErr_SetString(PyExc_ValueError, + "field op is required for BoolOp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = BoolOp_kind; + p->v.BoolOp.op = op; + p->v.BoolOp.values = values; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!left) { - PyErr_SetString(PyExc_ValueError, - "field left is required for BinOp"); - return NULL; - } - if (!op) { - PyErr_SetString(PyExc_ValueError, - "field op is required for BinOp"); - return NULL; - } - if (!right) { - PyErr_SetString(PyExc_ValueError, - "field right is required for BinOp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = BinOp_kind; - p->v.BinOp.left = left; - p->v.BinOp.op = op; - p->v.BinOp.right = right; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!left) { + PyErr_SetString(PyExc_ValueError, + "field left is required for BinOp"); + return NULL; + } + if (!op) { + PyErr_SetString(PyExc_ValueError, + "field op is required for BinOp"); + return NULL; + } + if (!right) { + PyErr_SetString(PyExc_ValueError, + "field right is required for BinOp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = BinOp_kind; + p->v.BinOp.left = left; + p->v.BinOp.op = op; + p->v.BinOp.right = right; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!op) { - PyErr_SetString(PyExc_ValueError, - "field op is required for UnaryOp"); - return NULL; - } - if (!operand) { - PyErr_SetString(PyExc_ValueError, - "field operand is required for UnaryOp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = UnaryOp_kind; - p->v.UnaryOp.op = op; - p->v.UnaryOp.operand = operand; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!op) { + PyErr_SetString(PyExc_ValueError, + "field op is required for UnaryOp"); + return NULL; + } + if (!operand) { + PyErr_SetString(PyExc_ValueError, + "field operand is required for UnaryOp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = UnaryOp_kind; + p->v.UnaryOp.op = op; + p->v.UnaryOp.operand = operand; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!args) { - PyErr_SetString(PyExc_ValueError, - "field args is required for Lambda"); - return NULL; - } - if (!body) { - PyErr_SetString(PyExc_ValueError, - "field body is required for Lambda"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Lambda_kind; - p->v.Lambda.args = args; - p->v.Lambda.body = body; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!args) { + PyErr_SetString(PyExc_ValueError, + "field args is required for Lambda"); + return NULL; + } + if (!body) { + PyErr_SetString(PyExc_ValueError, + "field body is required for Lambda"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Lambda_kind; + p->v.Lambda.args = args; + p->v.Lambda.body = body; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!test) { - PyErr_SetString(PyExc_ValueError, - "field test is required for IfExp"); - return NULL; - } - if (!body) { - PyErr_SetString(PyExc_ValueError, - "field body is required for IfExp"); - return NULL; - } - if (!orelse) { - PyErr_SetString(PyExc_ValueError, - "field orelse is required for IfExp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = IfExp_kind; - p->v.IfExp.test = test; - p->v.IfExp.body = body; - p->v.IfExp.orelse = orelse; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!test) { + PyErr_SetString(PyExc_ValueError, + "field test is required for IfExp"); + return NULL; + } + if (!body) { + PyErr_SetString(PyExc_ValueError, + "field body is required for IfExp"); + return NULL; + } + if (!orelse) { + PyErr_SetString(PyExc_ValueError, + "field orelse is required for IfExp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = IfExp_kind; + p->v.IfExp.test = test; + p->v.IfExp.body = body; + p->v.IfExp.orelse = orelse; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Dict_kind; - p->v.Dict.keys = keys; - p->v.Dict.values = values; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Dict_kind; + p->v.Dict.keys = keys; + p->v.Dict.values = values; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Set_kind; - p->v.Set.elts = elts; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Set_kind; + p->v.Set.elts = elts; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!elt) { - PyErr_SetString(PyExc_ValueError, - "field elt is required for ListComp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = ListComp_kind; - p->v.ListComp.elt = elt; - p->v.ListComp.generators = generators; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!elt) { + PyErr_SetString(PyExc_ValueError, + "field elt is required for ListComp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = ListComp_kind; + p->v.ListComp.elt = elt; + p->v.ListComp.generators = generators; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!elt) { - PyErr_SetString(PyExc_ValueError, - "field elt is required for SetComp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = SetComp_kind; - p->v.SetComp.elt = elt; - p->v.SetComp.generators = generators; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!elt) { + PyErr_SetString(PyExc_ValueError, + "field elt is required for SetComp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = SetComp_kind; + p->v.SetComp.elt = elt; + p->v.SetComp.generators = generators; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!key) { - PyErr_SetString(PyExc_ValueError, - "field key is required for DictComp"); - return NULL; - } - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for DictComp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = DictComp_kind; - p->v.DictComp.key = key; - p->v.DictComp.value = value; - p->v.DictComp.generators = generators; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!key) { + PyErr_SetString(PyExc_ValueError, + "field key is required for DictComp"); + return NULL; + } + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for DictComp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = DictComp_kind; + p->v.DictComp.key = key; + p->v.DictComp.value = value; + p->v.DictComp.generators = generators; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!elt) { - PyErr_SetString(PyExc_ValueError, - "field elt is required for GeneratorExp"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = GeneratorExp_kind; - p->v.GeneratorExp.elt = elt; - p->v.GeneratorExp.generators = generators; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!elt) { + PyErr_SetString(PyExc_ValueError, + "field elt is required for GeneratorExp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = GeneratorExp_kind; + p->v.GeneratorExp.elt = elt; + p->v.GeneratorExp.generators = generators; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Yield_kind; - p->v.Yield.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Yield_kind; + p->v.Yield.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for YieldFrom"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = YieldFrom_kind; - p->v.YieldFrom.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for YieldFrom"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = YieldFrom_kind; + p->v.YieldFrom.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!left) { - PyErr_SetString(PyExc_ValueError, - "field left is required for Compare"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Compare_kind; - p->v.Compare.left = left; - p->v.Compare.ops = ops; - p->v.Compare.comparators = comparators; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!left) { + PyErr_SetString(PyExc_ValueError, + "field left is required for Compare"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Compare_kind; + p->v.Compare.left = left; + p->v.Compare.ops = ops; + p->v.Compare.comparators = comparators; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs, expr_ty kwargs, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!func) { - PyErr_SetString(PyExc_ValueError, - "field func is required for Call"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Call_kind; - p->v.Call.func = func; - p->v.Call.args = args; - p->v.Call.keywords = keywords; - p->v.Call.starargs = starargs; - p->v.Call.kwargs = kwargs; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!func) { + PyErr_SetString(PyExc_ValueError, + "field func is required for Call"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Call_kind; + p->v.Call.func = func; + p->v.Call.args = args; + p->v.Call.keywords = keywords; + p->v.Call.starargs = starargs; + p->v.Call.kwargs = kwargs; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Num(object n, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!n) { - PyErr_SetString(PyExc_ValueError, - "field n is required for Num"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Num_kind; - p->v.Num.n = n; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!n) { + PyErr_SetString(PyExc_ValueError, + "field n is required for Num"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Num_kind; + p->v.Num.n = n; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Str(string s, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!s) { - PyErr_SetString(PyExc_ValueError, - "field s is required for Str"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Str_kind; - p->v.Str.s = s; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!s) { + PyErr_SetString(PyExc_ValueError, + "field s is required for Str"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Str_kind; + p->v.Str.s = s; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Bytes(bytes s, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!s) { - PyErr_SetString(PyExc_ValueError, - "field s is required for Bytes"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Bytes_kind; - p->v.Bytes.s = s; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!s) { + PyErr_SetString(PyExc_ValueError, + "field s is required for Bytes"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Bytes_kind; + p->v.Bytes.s = s; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for NameConstant"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = NameConstant_kind; - p->v.NameConstant.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for NameConstant"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = NameConstant_kind; + p->v.NameConstant.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Ellipsis(int lineno, int col_offset, PyArena *arena) { - expr_ty p; - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Ellipsis_kind; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Ellipsis_kind; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Attribute"); - return NULL; - } - if (!attr) { - PyErr_SetString(PyExc_ValueError, - "field attr is required for Attribute"); - return NULL; - } - if (!ctx) { - PyErr_SetString(PyExc_ValueError, - "field ctx is required for Attribute"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Attribute_kind; - p->v.Attribute.value = value; - p->v.Attribute.attr = attr; - p->v.Attribute.ctx = ctx; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for Attribute"); + return NULL; + } + if (!attr) { + PyErr_SetString(PyExc_ValueError, + "field attr is required for Attribute"); + return NULL; + } + if (!ctx) { + PyErr_SetString(PyExc_ValueError, + "field ctx is required for Attribute"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Attribute_kind; + p->v.Attribute.value = value; + p->v.Attribute.attr = attr; + p->v.Attribute.ctx = ctx; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Subscript"); - return NULL; - } - if (!slice) { - PyErr_SetString(PyExc_ValueError, - "field slice is required for Subscript"); - return NULL; - } - if (!ctx) { - PyErr_SetString(PyExc_ValueError, - "field ctx is required for Subscript"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Subscript_kind; - p->v.Subscript.value = value; - p->v.Subscript.slice = slice; - p->v.Subscript.ctx = ctx; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for Subscript"); + return NULL; + } + if (!slice) { + PyErr_SetString(PyExc_ValueError, + "field slice is required for Subscript"); + return NULL; + } + if (!ctx) { + PyErr_SetString(PyExc_ValueError, + "field ctx is required for Subscript"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Subscript_kind; + p->v.Subscript.value = value; + p->v.Subscript.slice = slice; + p->v.Subscript.ctx = ctx; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Starred"); - return NULL; - } - if (!ctx) { - PyErr_SetString(PyExc_ValueError, - "field ctx is required for Starred"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Starred_kind; - p->v.Starred.value = value; - p->v.Starred.ctx = ctx; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for Starred"); + return NULL; + } + if (!ctx) { + PyErr_SetString(PyExc_ValueError, + "field ctx is required for Starred"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Starred_kind; + p->v.Starred.value = value; + p->v.Starred.ctx = ctx; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!id) { - PyErr_SetString(PyExc_ValueError, - "field id is required for Name"); - return NULL; - } - if (!ctx) { - PyErr_SetString(PyExc_ValueError, - "field ctx is required for Name"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Name_kind; - p->v.Name.id = id; - p->v.Name.ctx = ctx; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!id) { + PyErr_SetString(PyExc_ValueError, + "field id is required for Name"); + return NULL; + } + if (!ctx) { + PyErr_SetString(PyExc_ValueError, + "field ctx is required for Name"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Name_kind; + p->v.Name.id = id; + p->v.Name.ctx = ctx; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!ctx) { - PyErr_SetString(PyExc_ValueError, - "field ctx is required for List"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = List_kind; - p->v.List.elts = elts; - p->v.List.ctx = ctx; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!ctx) { + PyErr_SetString(PyExc_ValueError, + "field ctx is required for List"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = List_kind; + p->v.List.elts = elts; + p->v.List.ctx = ctx; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } expr_ty Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { - expr_ty p; - if (!ctx) { - PyErr_SetString(PyExc_ValueError, - "field ctx is required for Tuple"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Tuple_kind; - p->v.Tuple.elts = elts; - p->v.Tuple.ctx = ctx; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + expr_ty p; + if (!ctx) { + PyErr_SetString(PyExc_ValueError, + "field ctx is required for Tuple"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Tuple_kind; + p->v.Tuple.elts = elts; + p->v.Tuple.ctx = ctx; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } slice_ty Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) { - slice_ty p; - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Slice_kind; - p->v.Slice.lower = lower; - p->v.Slice.upper = upper; - p->v.Slice.step = step; - return p; + slice_ty p; + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Slice_kind; + p->v.Slice.lower = lower; + p->v.Slice.upper = upper; + p->v.Slice.step = step; + return p; } slice_ty ExtSlice(asdl_seq * dims, PyArena *arena) { - slice_ty p; - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = ExtSlice_kind; - p->v.ExtSlice.dims = dims; - return p; + slice_ty p; + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = ExtSlice_kind; + p->v.ExtSlice.dims = dims; + return p; } slice_ty Index(expr_ty value, PyArena *arena) { - slice_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Index"); - return NULL; - } - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Index_kind; - p->v.Index.value = value; - return p; + slice_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for Index"); + return NULL; + } + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = Index_kind; + p->v.Index.value = value; + return p; } comprehension_ty comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) { - comprehension_ty p; - if (!target) { - PyErr_SetString(PyExc_ValueError, - "field target is required for comprehension"); - return NULL; - } - if (!iter) { - PyErr_SetString(PyExc_ValueError, - "field iter is required for comprehension"); - return NULL; - } - p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->target = target; - p->iter = iter; - p->ifs = ifs; - return p; + comprehension_ty p; + if (!target) { + PyErr_SetString(PyExc_ValueError, + "field target is required for comprehension"); + return NULL; + } + if (!iter) { + PyErr_SetString(PyExc_ValueError, + "field iter is required for comprehension"); + return NULL; + } + p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->target = target; + p->iter = iter; + p->ifs = ifs; + return p; } excepthandler_ty ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int col_offset, PyArena *arena) { - excepthandler_ty p; - p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = ExceptHandler_kind; - p->v.ExceptHandler.type = type; - p->v.ExceptHandler.name = name; - p->v.ExceptHandler.body = body; - p->lineno = lineno; - p->col_offset = col_offset; - return p; + excepthandler_ty p; + p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = ExceptHandler_kind; + p->v.ExceptHandler.type = type; + p->v.ExceptHandler.name = name; + p->v.ExceptHandler.body = body; + p->lineno = lineno; + p->col_offset = col_offset; + return p; } arguments_ty -arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * - kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) +arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, + asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, + asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) { - arguments_ty p; - p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->args = args; - p->vararg = vararg; - p->kwonlyargs = kwonlyargs; - p->kw_defaults = kw_defaults; - p->kwarg = kwarg; - p->defaults = defaults; - return p; + arguments_ty p; + p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->args = args; + p->vararg = vararg; + p->varargannotation = varargannotation; + p->kwonlyargs = kwonlyargs; + p->kwarg = kwarg; + p->kwargannotation = kwargannotation; + p->defaults = defaults; + p->kw_defaults = kw_defaults; + return p; } arg_ty arg(identifier arg, expr_ty annotation, PyArena *arena) { - arg_ty p; - if (!arg) { - PyErr_SetString(PyExc_ValueError, - "field arg is required for arg"); - return NULL; - } - p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->arg = arg; - p->annotation = annotation; - return p; + arg_ty p; + if (!arg) { + PyErr_SetString(PyExc_ValueError, + "field arg is required for arg"); + return NULL; + } + p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->arg = arg; + p->annotation = annotation; + return p; } keyword_ty keyword(identifier arg, expr_ty value, PyArena *arena) { - keyword_ty p; - if (!arg) { - PyErr_SetString(PyExc_ValueError, - "field arg is required for keyword"); - return NULL; - } - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for keyword"); - return NULL; - } - p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->arg = arg; - p->value = value; - return p; + keyword_ty p; + if (!arg) { + PyErr_SetString(PyExc_ValueError, + "field arg is required for keyword"); + return NULL; + } + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for keyword"); + return NULL; + } + p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->arg = arg; + p->value = value; + return p; } alias_ty alias(identifier name, identifier asname, PyArena *arena) { - alias_ty p; - if (!name) { - PyErr_SetString(PyExc_ValueError, - "field name is required for alias"); - return NULL; - } - p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->name = name; - p->asname = asname; - return p; + alias_ty p; + if (!name) { + PyErr_SetString(PyExc_ValueError, + "field name is required for alias"); + return NULL; + } + p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->name = name; + p->asname = asname; + return p; } withitem_ty withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) { - withitem_ty p; - if (!context_expr) { - PyErr_SetString(PyExc_ValueError, - "field context_expr is required for withitem"); - return NULL; - } - p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->context_expr = context_expr; - p->optional_vars = optional_vars; - return p; + withitem_ty p; + if (!context_expr) { + PyErr_SetString(PyExc_ValueError, + "field context_expr is required for withitem"); + return NULL; + } + p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->context_expr = context_expr; + p->optional_vars = optional_vars; + return p; } PyObject* ast2obj_mod(void* _o) { - mod_ty o = (mod_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - switch (o->kind) { - case Module_kind: - result = PyType_GenericNew(Module_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Module.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Interactive_kind: - result = PyType_GenericNew(Interactive_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Expression_kind: - result = PyType_GenericNew(Expression_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Expression.body); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Suite_kind: - result = PyType_GenericNew(Suite_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - } - return result; + mod_ty o = (mod_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + switch (o->kind) { + case Module_kind: + result = PyType_GenericNew(Module_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Module.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Interactive_kind: + result = PyType_GenericNew(Interactive_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Expression_kind: + result = PyType_GenericNew(Expression_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Expression.body); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Suite_kind: + result = PyType_GenericNew(Suite_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + } + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_stmt(void* _o) { - stmt_ty o = (stmt_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - switch (o->kind) { - case FunctionDef_kind: - result = PyType_GenericNew(FunctionDef_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_identifier(o->v.FunctionDef.name); + stmt_ty o = (stmt_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + switch (o->kind) { + case FunctionDef_kind: + result = PyType_GenericNew(FunctionDef_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_identifier(o->v.FunctionDef.name); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_arguments(o->v.FunctionDef.args); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.FunctionDef.decorator_list, + ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == + -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.FunctionDef.returns); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) + goto failed; + Py_DECREF(value); + break; + case ClassDef_kind: + result = PyType_GenericNew(ClassDef_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_identifier(o->v.ClassDef.name); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.ClassDef.starargs); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.ClassDef.kwargs); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ClassDef.decorator_list, + ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == + -1) + goto failed; + Py_DECREF(value); + break; + case Return_kind: + result = PyType_GenericNew(Return_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Return.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Delete_kind: + result = PyType_GenericNew(Delete_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Assign_kind: + result = PyType_GenericNew(Assign_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Assign.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case AugAssign_kind: + result = PyType_GenericNew(AugAssign_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.AugAssign.target); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_operator(o->v.AugAssign.op); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.AugAssign.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case For_kind: + result = PyType_GenericNew(For_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.For.target); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.For.iter); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.For.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + goto failed; + Py_DECREF(value); + break; + case While_kind: + result = PyType_GenericNew(While_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.While.test); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.While.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + goto failed; + Py_DECREF(value); + break; + case If_kind: + result = PyType_GenericNew(If_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.If.test); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.If.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + goto failed; + Py_DECREF(value); + break; + case With_kind: + result = PyType_GenericNew(With_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.With.items, ast2obj_withitem); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.With.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Raise_kind: + result = PyType_GenericNew(Raise_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Raise.exc); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Raise.cause); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Try_kind: + result = PyType_GenericNew(Try_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Try.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Assert_kind: + result = PyType_GenericNew(Assert_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Assert.test); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Assert.msg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Import_kind: + result = PyType_GenericNew(Import_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Import.names, ast2obj_alias); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + goto failed; + Py_DECREF(value); + break; + case ImportFrom_kind: + result = PyType_GenericNew(ImportFrom_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_identifier(o->v.ImportFrom.module); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->v.ImportFrom.level); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Global_kind: + result = PyType_GenericNew(Global_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Global.names, ast2obj_identifier); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Nonlocal_kind: + result = PyType_GenericNew(Nonlocal_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Expr_kind: + result = PyType_GenericNew(Expr_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Expr.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Pass_kind: + result = PyType_GenericNew(Pass_type, NULL, NULL); + if (!result) goto failed; + break; + case Break_kind: + result = PyType_GenericNew(Break_type, NULL, NULL); + if (!result) goto failed; + break; + case Continue_kind: + result = PyType_GenericNew(Continue_type, NULL, NULL); + if (!result) goto failed; + break; + } + value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) - goto failed; + if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + goto failed; Py_DECREF(value); - value = ast2obj_arguments(o->v.FunctionDef.args); + value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) - goto failed; + if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.FunctionDef.returns); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) - goto failed; - Py_DECREF(value); - break; - case ClassDef_kind: - result = PyType_GenericNew(ClassDef_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_identifier(o->v.ClassDef.name); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.ClassDef.starargs); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.ClassDef.kwargs); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Return_kind: - result = PyType_GenericNew(Return_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Return.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Delete_kind: - result = PyType_GenericNew(Delete_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Assign_kind: - result = PyType_GenericNew(Assign_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Assign.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case AugAssign_kind: - result = PyType_GenericNew(AugAssign_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.AugAssign.target); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_operator(o->v.AugAssign.op); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.AugAssign.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case For_kind: - result = PyType_GenericNew(For_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.For.target); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.For.iter); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.For.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) - goto failed; - Py_DECREF(value); - break; - case While_kind: - result = PyType_GenericNew(While_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.While.test); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.While.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) - goto failed; - Py_DECREF(value); - break; - case If_kind: - result = PyType_GenericNew(If_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.If.test); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.If.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) - goto failed; - Py_DECREF(value); - break; - case With_kind: - result = PyType_GenericNew(With_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.With.items, ast2obj_withitem); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.With.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Raise_kind: - result = PyType_GenericNew(Raise_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Raise.exc); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Raise.cause); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Try_kind: - result = PyType_GenericNew(Try_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Try.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Assert_kind: - result = PyType_GenericNew(Assert_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Assert.test); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Assert.msg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Import_kind: - result = PyType_GenericNew(Import_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Import.names, ast2obj_alias); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) - goto failed; - Py_DECREF(value); - break; - case ImportFrom_kind: - result = PyType_GenericNew(ImportFrom_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_identifier(o->v.ImportFrom.module); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_int(o->v.ImportFrom.level); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Global_kind: - result = PyType_GenericNew(Global_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Global.names, ast2obj_identifier); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Nonlocal_kind: - result = PyType_GenericNew(Nonlocal_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Expr_kind: - result = PyType_GenericNew(Expr_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Expr.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Pass_kind: - result = PyType_GenericNew(Pass_type, NULL, NULL); - if (!result) goto failed; - break; - case Break_kind: - result = PyType_GenericNew(Break_type, NULL, NULL); - if (!result) goto failed; - break; - case Continue_kind: - result = PyType_GenericNew(Continue_type, NULL, NULL); - if (!result) goto failed; - break; - } - value = ast2obj_int(o->lineno); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) - goto failed; - Py_DECREF(value); - value = ast2obj_int(o->col_offset); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) - goto failed; - Py_DECREF(value); - return result; + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_expr(void* _o) { - expr_ty o = (expr_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - switch (o->kind) { - case BoolOp_kind: - result = PyType_GenericNew(BoolOp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_boolop(o->v.BoolOp.op); + expr_ty o = (expr_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + switch (o->kind) { + case BoolOp_kind: + result = PyType_GenericNew(BoolOp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_boolop(o->v.BoolOp.op); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) + goto failed; + Py_DECREF(value); + break; + case BinOp_kind: + result = PyType_GenericNew(BinOp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.BinOp.left); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_operator(o->v.BinOp.op); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.BinOp.right); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) + goto failed; + Py_DECREF(value); + break; + case UnaryOp_kind: + result = PyType_GenericNew(UnaryOp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_unaryop(o->v.UnaryOp.op); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.UnaryOp.operand); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Lambda_kind: + result = PyType_GenericNew(Lambda_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_arguments(o->v.Lambda.args); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Lambda.body); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + case IfExp_kind: + result = PyType_GenericNew(IfExp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.IfExp.test); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.IfExp.body); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.IfExp.orelse); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Dict_kind: + result = PyType_GenericNew(Dict_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Dict.values, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Set_kind: + result = PyType_GenericNew(Set_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Set.elts, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) + goto failed; + Py_DECREF(value); + break; + case ListComp_kind: + result = PyType_GenericNew(ListComp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.ListComp.elt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ListComp.generators, + ast2obj_comprehension); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + goto failed; + Py_DECREF(value); + break; + case SetComp_kind: + result = PyType_GenericNew(SetComp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.SetComp.elt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.SetComp.generators, + ast2obj_comprehension); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + goto failed; + Py_DECREF(value); + break; + case DictComp_kind: + result = PyType_GenericNew(DictComp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.DictComp.key); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.DictComp.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.DictComp.generators, + ast2obj_comprehension); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + goto failed; + Py_DECREF(value); + break; + case GeneratorExp_kind: + result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.GeneratorExp.elt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.GeneratorExp.generators, + ast2obj_comprehension); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Yield_kind: + result = PyType_GenericNew(Yield_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Yield.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case YieldFrom_kind: + result = PyType_GenericNew(YieldFrom_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.YieldFrom.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Compare_kind: + result = PyType_GenericNew(Compare_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Compare.left); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) + goto failed; + Py_DECREF(value); + { + Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); + value = PyList_New(n); + if (!value) goto failed; + for(i = 0; i < n; i++) + PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); + } + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Call_kind: + result = PyType_GenericNew(Call_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Call.func); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Call.args, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Call.starargs); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Call.kwargs); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Num_kind: + result = PyType_GenericNew(Num_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_object(o->v.Num.n); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Str_kind: + result = PyType_GenericNew(Str_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_string(o->v.Str.s); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Bytes_kind: + result = PyType_GenericNew(Bytes_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_bytes(o->v.Bytes.s); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) + goto failed; + Py_DECREF(value); + break; + case NameConstant_kind: + result = PyType_GenericNew(NameConstant_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_singleton(o->v.NameConstant.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Ellipsis_kind: + result = PyType_GenericNew(Ellipsis_type, NULL, NULL); + if (!result) goto failed; + break; + case Attribute_kind: + result = PyType_GenericNew(Attribute_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Attribute.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_identifier(o->v.Attribute.attr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr_context(o->v.Attribute.ctx); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Subscript_kind: + result = PyType_GenericNew(Subscript_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Subscript.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_slice(o->v.Subscript.slice); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr_context(o->v.Subscript.ctx); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Starred_kind: + result = PyType_GenericNew(Starred_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Starred.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr_context(o->v.Starred.ctx); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Name_kind: + result = PyType_GenericNew(Name_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_identifier(o->v.Name.id); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr_context(o->v.Name.ctx); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + case List_kind: + result = PyType_GenericNew(List_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.List.elts, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr_context(o->v.List.ctx); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Tuple_kind: + result = PyType_GenericNew(Tuple_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr_context(o->v.Tuple.ctx); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + } + value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) - goto failed; + if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); + value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) - goto failed; + if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + goto failed; Py_DECREF(value); - break; - case BinOp_kind: - result = PyType_GenericNew(BinOp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.BinOp.left); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_operator(o->v.BinOp.op); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.BinOp.right); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) - goto failed; - Py_DECREF(value); - break; - case UnaryOp_kind: - result = PyType_GenericNew(UnaryOp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_unaryop(o->v.UnaryOp.op); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.UnaryOp.operand); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Lambda_kind: - result = PyType_GenericNew(Lambda_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_arguments(o->v.Lambda.args); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Lambda.body); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - case IfExp_kind: - result = PyType_GenericNew(IfExp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.IfExp.test); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.IfExp.body); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.IfExp.orelse); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Dict_kind: - result = PyType_GenericNew(Dict_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Dict.values, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Set_kind: - result = PyType_GenericNew(Set_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Set.elts, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) - goto failed; - Py_DECREF(value); - break; - case ListComp_kind: - result = PyType_GenericNew(ListComp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.ListComp.elt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) - goto failed; - Py_DECREF(value); - break; - case SetComp_kind: - result = PyType_GenericNew(SetComp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.SetComp.elt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) - goto failed; - Py_DECREF(value); - break; - case DictComp_kind: - result = PyType_GenericNew(DictComp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.DictComp.key); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.DictComp.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) - goto failed; - Py_DECREF(value); - break; - case GeneratorExp_kind: - result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.GeneratorExp.elt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.GeneratorExp.generators, - ast2obj_comprehension); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Yield_kind: - result = PyType_GenericNew(Yield_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Yield.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case YieldFrom_kind: - result = PyType_GenericNew(YieldFrom_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.YieldFrom.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Compare_kind: - result = PyType_GenericNew(Compare_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Compare.left); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) - goto failed; - Py_DECREF(value); - { - Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); - value = PyList_New(n); - if (!value) goto failed; - for(i = 0; i < n; i++) - PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); - } - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Call_kind: - result = PyType_GenericNew(Call_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Call.func); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Call.args, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Call.starargs); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Call.kwargs); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Num_kind: - result = PyType_GenericNew(Num_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_object(o->v.Num.n); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Str_kind: - result = PyType_GenericNew(Str_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_string(o->v.Str.s); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Bytes_kind: - result = PyType_GenericNew(Bytes_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_bytes(o->v.Bytes.s); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) - goto failed; - Py_DECREF(value); - break; - case NameConstant_kind: - result = PyType_GenericNew(NameConstant_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_singleton(o->v.NameConstant.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Ellipsis_kind: - result = PyType_GenericNew(Ellipsis_type, NULL, NULL); - if (!result) goto failed; - break; - case Attribute_kind: - result = PyType_GenericNew(Attribute_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Attribute.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_identifier(o->v.Attribute.attr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr_context(o->v.Attribute.ctx); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Subscript_kind: - result = PyType_GenericNew(Subscript_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Subscript.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_slice(o->v.Subscript.slice); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr_context(o->v.Subscript.ctx); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Starred_kind: - result = PyType_GenericNew(Starred_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Starred.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr_context(o->v.Starred.ctx); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Name_kind: - result = PyType_GenericNew(Name_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_identifier(o->v.Name.id); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr_context(o->v.Name.ctx); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) - goto failed; - Py_DECREF(value); - break; - case List_kind: - result = PyType_GenericNew(List_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.List.elts, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr_context(o->v.List.ctx); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Tuple_kind: - result = PyType_GenericNew(Tuple_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr_context(o->v.Tuple.ctx); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) - goto failed; - Py_DECREF(value); - break; - } - value = ast2obj_int(o->lineno); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) - goto failed; - Py_DECREF(value); - value = ast2obj_int(o->col_offset); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) - goto failed; - Py_DECREF(value); - return result; + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_expr_context(expr_context_ty o) { - switch(o) { - case Load: - Py_INCREF(Load_singleton); - return Load_singleton; - case Store: - Py_INCREF(Store_singleton); - return Store_singleton; - case Del: - Py_INCREF(Del_singleton); - return Del_singleton; - case AugLoad: - Py_INCREF(AugLoad_singleton); - return AugLoad_singleton; - case AugStore: - Py_INCREF(AugStore_singleton); - return AugStore_singleton; - case Param: - Py_INCREF(Param_singleton); - return Param_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown expr_context found"); - return NULL; - } + switch(o) { + case Load: + Py_INCREF(Load_singleton); + return Load_singleton; + case Store: + Py_INCREF(Store_singleton); + return Store_singleton; + case Del: + Py_INCREF(Del_singleton); + return Del_singleton; + case AugLoad: + Py_INCREF(AugLoad_singleton); + return AugLoad_singleton; + case AugStore: + Py_INCREF(AugStore_singleton); + return AugStore_singleton; + case Param: + Py_INCREF(Param_singleton); + return Param_singleton; + default: + /* should never happen, but just in case ... */ + PyErr_Format(PyExc_SystemError, "unknown expr_context found"); + return NULL; + } } PyObject* ast2obj_slice(void* _o) { - slice_ty o = (slice_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - switch (o->kind) { - case Slice_kind: - result = PyType_GenericNew(Slice_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Slice.lower); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Slice.upper); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Slice.step); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) - goto failed; - Py_DECREF(value); - break; - case ExtSlice_kind: - result = PyType_GenericNew(ExtSlice_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Index_kind: - result = PyType_GenericNew(Index_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Index.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; - } - return result; + slice_ty o = (slice_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + switch (o->kind) { + case Slice_kind: + result = PyType_GenericNew(Slice_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Slice.lower); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Slice.upper); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Slice.step); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) + goto failed; + Py_DECREF(value); + break; + case ExtSlice_kind: + result = PyType_GenericNew(ExtSlice_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Index_kind: + result = PyType_GenericNew(Index_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Index.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; + } + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_boolop(boolop_ty o) { - switch(o) { - case And: - Py_INCREF(And_singleton); - return And_singleton; - case Or: - Py_INCREF(Or_singleton); - return Or_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown boolop found"); - return NULL; - } + switch(o) { + case And: + Py_INCREF(And_singleton); + return And_singleton; + case Or: + Py_INCREF(Or_singleton); + return Or_singleton; + default: + /* should never happen, but just in case ... */ + PyErr_Format(PyExc_SystemError, "unknown boolop found"); + return NULL; + } } PyObject* ast2obj_operator(operator_ty o) { - switch(o) { - case Add: - Py_INCREF(Add_singleton); - return Add_singleton; - case Sub: - Py_INCREF(Sub_singleton); - return Sub_singleton; - case Mult: - Py_INCREF(Mult_singleton); - return Mult_singleton; - case Div: - Py_INCREF(Div_singleton); - return Div_singleton; - case Mod: - Py_INCREF(Mod_singleton); - return Mod_singleton; - case Pow: - Py_INCREF(Pow_singleton); - return Pow_singleton; - case LShift: - Py_INCREF(LShift_singleton); - return LShift_singleton; - case RShift: - Py_INCREF(RShift_singleton); - return RShift_singleton; - case BitOr: - Py_INCREF(BitOr_singleton); - return BitOr_singleton; - case BitXor: - Py_INCREF(BitXor_singleton); - return BitXor_singleton; - case BitAnd: - Py_INCREF(BitAnd_singleton); - return BitAnd_singleton; - case FloorDiv: - Py_INCREF(FloorDiv_singleton); - return FloorDiv_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown operator found"); - return NULL; - } + switch(o) { + case Add: + Py_INCREF(Add_singleton); + return Add_singleton; + case Sub: + Py_INCREF(Sub_singleton); + return Sub_singleton; + case Mult: + Py_INCREF(Mult_singleton); + return Mult_singleton; + case Div: + Py_INCREF(Div_singleton); + return Div_singleton; + case Mod: + Py_INCREF(Mod_singleton); + return Mod_singleton; + case Pow: + Py_INCREF(Pow_singleton); + return Pow_singleton; + case LShift: + Py_INCREF(LShift_singleton); + return LShift_singleton; + case RShift: + Py_INCREF(RShift_singleton); + return RShift_singleton; + case BitOr: + Py_INCREF(BitOr_singleton); + return BitOr_singleton; + case BitXor: + Py_INCREF(BitXor_singleton); + return BitXor_singleton; + case BitAnd: + Py_INCREF(BitAnd_singleton); + return BitAnd_singleton; + case FloorDiv: + Py_INCREF(FloorDiv_singleton); + return FloorDiv_singleton; + default: + /* should never happen, but just in case ... */ + PyErr_Format(PyExc_SystemError, "unknown operator found"); + return NULL; + } } PyObject* ast2obj_unaryop(unaryop_ty o) { - switch(o) { - case Invert: - Py_INCREF(Invert_singleton); - return Invert_singleton; - case Not: - Py_INCREF(Not_singleton); - return Not_singleton; - case UAdd: - Py_INCREF(UAdd_singleton); - return UAdd_singleton; - case USub: - Py_INCREF(USub_singleton); - return USub_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown unaryop found"); - return NULL; - } + switch(o) { + case Invert: + Py_INCREF(Invert_singleton); + return Invert_singleton; + case Not: + Py_INCREF(Not_singleton); + return Not_singleton; + case UAdd: + Py_INCREF(UAdd_singleton); + return UAdd_singleton; + case USub: + Py_INCREF(USub_singleton); + return USub_singleton; + default: + /* should never happen, but just in case ... */ + PyErr_Format(PyExc_SystemError, "unknown unaryop found"); + return NULL; + } } PyObject* ast2obj_cmpop(cmpop_ty o) { - switch(o) { - case Eq: - Py_INCREF(Eq_singleton); - return Eq_singleton; - case NotEq: - Py_INCREF(NotEq_singleton); - return NotEq_singleton; - case Lt: - Py_INCREF(Lt_singleton); - return Lt_singleton; - case LtE: - Py_INCREF(LtE_singleton); - return LtE_singleton; - case Gt: - Py_INCREF(Gt_singleton); - return Gt_singleton; - case GtE: - Py_INCREF(GtE_singleton); - return GtE_singleton; - case Is: - Py_INCREF(Is_singleton); - return Is_singleton; - case IsNot: - Py_INCREF(IsNot_singleton); - return IsNot_singleton; - case In: - Py_INCREF(In_singleton); - return In_singleton; - case NotIn: - Py_INCREF(NotIn_singleton); - return NotIn_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown cmpop found"); - return NULL; - } + switch(o) { + case Eq: + Py_INCREF(Eq_singleton); + return Eq_singleton; + case NotEq: + Py_INCREF(NotEq_singleton); + return NotEq_singleton; + case Lt: + Py_INCREF(Lt_singleton); + return Lt_singleton; + case LtE: + Py_INCREF(LtE_singleton); + return LtE_singleton; + case Gt: + Py_INCREF(Gt_singleton); + return Gt_singleton; + case GtE: + Py_INCREF(GtE_singleton); + return GtE_singleton; + case Is: + Py_INCREF(Is_singleton); + return Is_singleton; + case IsNot: + Py_INCREF(IsNot_singleton); + return IsNot_singleton; + case In: + Py_INCREF(In_singleton); + return In_singleton; + case NotIn: + Py_INCREF(NotIn_singleton); + return NotIn_singleton; + default: + /* should never happen, but just in case ... */ + PyErr_Format(PyExc_SystemError, "unknown cmpop found"); + return NULL; + } } PyObject* ast2obj_comprehension(void* _o) { - comprehension_ty o = (comprehension_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - result = PyType_GenericNew(comprehension_type, NULL, NULL); - if (!result) return NULL; - value = ast2obj_expr(o->target); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->iter); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->ifs, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) - goto failed; - Py_DECREF(value); - return result; + comprehension_ty o = (comprehension_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(comprehension_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_expr(o->target); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->iter); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->ifs, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) + goto failed; + Py_DECREF(value); + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_excepthandler(void* _o) { - excepthandler_ty o = (excepthandler_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - switch (o->kind) { - case ExceptHandler_kind: - result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.ExceptHandler.type); + excepthandler_ty o = (excepthandler_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + switch (o->kind) { + case ExceptHandler_kind: + result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.ExceptHandler.type); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_identifier(o->v.ExceptHandler.name); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + goto failed; + Py_DECREF(value); + break; + } + value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) - goto failed; + if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + goto failed; Py_DECREF(value); - value = ast2obj_identifier(o->v.ExceptHandler.name); + value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) - goto failed; + if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) - goto failed; - Py_DECREF(value); - break; - } - value = ast2obj_int(o->lineno); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) - goto failed; - Py_DECREF(value); - value = ast2obj_int(o->col_offset); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) - goto failed; - Py_DECREF(value); - return result; + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_arguments(void* _o) { - arguments_ty o = (arguments_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - result = PyType_GenericNew(arguments_type, NULL, NULL); - if (!result) return NULL; - value = ast2obj_list(o->args, ast2obj_arg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_arg(o->vararg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->kwonlyargs, ast2obj_arg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->kw_defaults, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_arg(o->kwarg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->defaults, ast2obj_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) - goto failed; - Py_DECREF(value); - return result; + arguments_ty o = (arguments_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(arguments_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_list(o->args, ast2obj_arg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_identifier(o->vararg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->varargannotation); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->kwonlyargs, ast2obj_arg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_identifier(o->kwarg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->kwargannotation); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->defaults, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->kw_defaults, ast2obj_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) + goto failed; + Py_DECREF(value); + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_arg(void* _o) { - arg_ty o = (arg_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - result = PyType_GenericNew(arg_type, NULL, NULL); - if (!result) return NULL; - value = ast2obj_identifier(o->arg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->annotation); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_int(o->lineno); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) - goto failed; - Py_DECREF(value); - value = ast2obj_int(o->col_offset); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) - goto failed; - Py_DECREF(value); - return result; + arg_ty o = (arg_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(arg_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_identifier(o->arg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->annotation); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) + goto failed; + Py_DECREF(value); + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_keyword(void* _o) { - keyword_ty o = (keyword_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - result = PyType_GenericNew(keyword_type, NULL, NULL); - if (!result) return NULL; - value = ast2obj_identifier(o->arg); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - return result; + keyword_ty o = (keyword_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(keyword_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_identifier(o->arg); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_alias(void* _o) { - alias_ty o = (alias_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - result = PyType_GenericNew(alias_type, NULL, NULL); - if (!result) return NULL; - value = ast2obj_identifier(o->name); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_identifier(o->asname); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) - goto failed; - Py_DECREF(value); - return result; + alias_ty o = (alias_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(alias_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_identifier(o->name); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_identifier(o->asname); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) + goto failed; + Py_DECREF(value); + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } PyObject* ast2obj_withitem(void* _o) { - withitem_ty o = (withitem_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_INCREF(Py_None); - return Py_None; - } - - result = PyType_GenericNew(withitem_type, NULL, NULL); - if (!result) return NULL; - value = ast2obj_expr(o->context_expr); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->optional_vars); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) - goto failed; - Py_DECREF(value); - return result; + withitem_ty o = (withitem_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(withitem_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_expr(o->context_expr); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->optional_vars); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) + goto failed; + Py_DECREF(value); + return result; failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; } int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) { - int isinstance; - - PyObject *tmp = NULL; - - if (obj == Py_None) { - *out = NULL; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); - if (isinstance == -1) { + int isinstance; + + PyObject *tmp = NULL; + + if (obj == Py_None) { + *out = NULL; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* body; + + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); + return 1; + } + *out = Module(body, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* body; + + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); + return 1; + } + *out = Interactive(body, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty body; + + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &body, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); + return 1; + } + *out = Expression(body, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* body; + + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); + return 1; + } + *out = Suite(body, arena); + if (*out == NULL) goto failed; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); + failed: + Py_XDECREF(tmp); return 1; - } - if (isinstance) { - asdl_seq* body; - - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); - return 1; - } - *out = Module(body, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* body; - - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); - return 1; - } - *out = Interactive(body, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty body; - - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &body, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); - return 1; - } - *out = Expression(body, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* body; - - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); - return 1; - } - *out = Suite(body, arena); - if (*out == NULL) goto failed; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); - failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) { - int isinstance; - - PyObject *tmp = NULL; - int lineno; - int col_offset; - - if (obj == Py_None) { - *out = NULL; - return 0; - } - if (_PyObject_HasAttrId(obj, &PyId_lineno)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_lineno); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &lineno, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); + int isinstance; + + PyObject *tmp = NULL; + int lineno; + int col_offset; + + if (obj == Py_None) { + *out = NULL; + return 0; + } + if (_PyObject_HasAttrId(obj, &PyId_lineno)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_lineno); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &lineno, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &col_offset, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); + return 1; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + identifier name; + arguments_ty args; + asdl_seq* body; + asdl_seq* decorator_list; + expr_ty returns; + + if (_PyObject_HasAttrId(obj, &PyId_name)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_name); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &name, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_args)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_args); + if (tmp == NULL) goto failed; + res = obj2ast_arguments(tmp, &args, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + decorator_list = asdl_seq_new(len, arena); + if (decorator_list == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(decorator_list, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_returns)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_returns); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &returns, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + returns = NULL; + } + *out = FunctionDef(name, args, body, decorator_list, returns, + lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + identifier name; + asdl_seq* bases; + asdl_seq* keywords; + expr_ty starargs; + expr_ty kwargs; + asdl_seq* body; + asdl_seq* decorator_list; + + if (_PyObject_HasAttrId(obj, &PyId_name)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_name); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &name, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_bases)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_bases); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + bases = asdl_seq_new(len, arena); + if (bases == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(bases, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_keywords)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_keywords); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + keywords = asdl_seq_new(len, arena); + if (keywords == NULL) goto failed; + for (i = 0; i < len; i++) { + keyword_ty value; + res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(keywords, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_starargs)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_starargs); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &starargs, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + starargs = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &kwargs, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + kwargs = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + decorator_list = asdl_seq_new(len, arena); + if (decorator_list == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(decorator_list, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); + return 1; + } + *out = ClassDef(name, bases, keywords, starargs, kwargs, body, + decorator_list, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + value = NULL; + } + *out = Return(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* targets; + + if (_PyObject_HasAttrId(obj, &PyId_targets)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_targets); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + targets = asdl_seq_new(len, arena); + if (targets == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(targets, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); + return 1; + } + *out = Delete(targets, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* targets; + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_targets)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_targets); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + targets = asdl_seq_new(len, arena); + if (targets == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(targets, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); + return 1; + } + *out = Assign(targets, value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty target; + operator_ty op; + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_target)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_target); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &target, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_op)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_op); + if (tmp == NULL) goto failed; + res = obj2ast_operator(tmp, &op, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); + return 1; + } + *out = AugAssign(target, op, value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty target; + expr_ty iter; + asdl_seq* body; + asdl_seq* orelse; + + if (_PyObject_HasAttrId(obj, &PyId_target)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_target); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &target, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_iter)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_iter); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &iter, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + orelse = asdl_seq_new(len, arena); + if (orelse == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(orelse, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); + return 1; + } + *out = For(target, iter, body, orelse, lineno, col_offset, + arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty test; + asdl_seq* body; + asdl_seq* orelse; + + if (_PyObject_HasAttrId(obj, &PyId_test)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_test); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &test, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + orelse = asdl_seq_new(len, arena); + if (orelse == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(orelse, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); + return 1; + } + *out = While(test, body, orelse, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty test; + asdl_seq* body; + asdl_seq* orelse; + + if (_PyObject_HasAttrId(obj, &PyId_test)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_test); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &test, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + orelse = asdl_seq_new(len, arena); + if (orelse == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(orelse, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); + return 1; + } + *out = If(test, body, orelse, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* items; + asdl_seq* body; + + if (_PyObject_HasAttrId(obj, &PyId_items)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_items); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + items = asdl_seq_new(len, arena); + if (items == NULL) goto failed; + for (i = 0; i < len; i++) { + withitem_ty value; + res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(items, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); + return 1; + } + *out = With(items, body, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty exc; + expr_ty cause; + + if (_PyObject_HasAttrId(obj, &PyId_exc)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_exc); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &exc, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + exc = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_cause)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_cause); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &cause, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + cause = NULL; + } + *out = Raise(exc, cause, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* body; + asdl_seq* handlers; + asdl_seq* orelse; + asdl_seq* finalbody; + + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_handlers)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_handlers); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + handlers = asdl_seq_new(len, arena); + if (handlers == NULL) goto failed; + for (i = 0; i < len; i++) { + excepthandler_ty value; + res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(handlers, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + orelse = asdl_seq_new(len, arena); + if (orelse == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(orelse, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + finalbody = asdl_seq_new(len, arena); + if (finalbody == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(finalbody, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); + return 1; + } + *out = Try(body, handlers, orelse, finalbody, lineno, + col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty test; + expr_ty msg; + + if (_PyObject_HasAttrId(obj, &PyId_test)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_test); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &test, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_msg)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_msg); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &msg, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + msg = NULL; + } + *out = Assert(test, msg, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* names; + + if (_PyObject_HasAttrId(obj, &PyId_names)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_names); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + names = asdl_seq_new(len, arena); + if (names == NULL) goto failed; + for (i = 0; i < len; i++) { + alias_ty value; + res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(names, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); + return 1; + } + *out = Import(names, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + identifier module; + asdl_seq* names; + int level; + + if (_PyObject_HasAttrId(obj, &PyId_module)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_module); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &module, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + module = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_names)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_names); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + names = asdl_seq_new(len, arena); + if (names == NULL) goto failed; + for (i = 0; i < len; i++) { + alias_ty value; + res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(names, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_level)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_level); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &level, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + level = 0; + } + *out = ImportFrom(module, names, level, lineno, col_offset, + arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* names; + + if (_PyObject_HasAttrId(obj, &PyId_names)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_names); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + names = asdl_seq_new(len, arena); + if (names == NULL) goto failed; + for (i = 0; i < len; i++) { + identifier value; + res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(names, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); + return 1; + } + *out = Global(names, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* names; + + if (_PyObject_HasAttrId(obj, &PyId_names)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_names); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + names = asdl_seq_new(len, arena); + if (names == NULL) goto failed; + for (i = 0; i < len; i++) { + identifier value; + res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(names, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); + return 1; + } + *out = Nonlocal(names, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); + return 1; + } + *out = Expr(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + + *out = Pass(lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + + *out = Break(lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + + *out = Continue(lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); + failed: + Py_XDECREF(tmp); return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &col_offset, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); - return 1; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - identifier name; - arguments_ty args; - asdl_seq* body; - asdl_seq* decorator_list; - expr_ty returns; - - if (_PyObject_HasAttrId(obj, &PyId_name)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_name); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &name, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_args)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_args); - if (tmp == NULL) goto failed; - res = obj2ast_arguments(tmp, &args, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - decorator_list = asdl_seq_new(len, arena); - if (decorator_list == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(decorator_list, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); - return 1; - } - if (exists_not_none(obj, &PyId_returns)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_returns); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &returns, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - returns = NULL; - } - *out = FunctionDef(name, args, body, decorator_list, returns, lineno, - col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - identifier name; - asdl_seq* bases; - asdl_seq* keywords; - expr_ty starargs; - expr_ty kwargs; - asdl_seq* body; - asdl_seq* decorator_list; - - if (_PyObject_HasAttrId(obj, &PyId_name)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_name); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &name, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_bases)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_bases); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - bases = asdl_seq_new(len, arena); - if (bases == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(bases, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_keywords)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_keywords); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - keywords = asdl_seq_new(len, arena); - if (keywords == NULL) goto failed; - for (i = 0; i < len; i++) { - keyword_ty value; - res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(keywords, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); - return 1; - } - if (exists_not_none(obj, &PyId_starargs)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_starargs); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &starargs, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - starargs = NULL; - } - if (exists_not_none(obj, &PyId_kwargs)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &kwargs, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - kwargs = NULL; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - decorator_list = asdl_seq_new(len, arena); - if (decorator_list == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(decorator_list, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); - return 1; - } - *out = ClassDef(name, bases, keywords, starargs, kwargs, body, - decorator_list, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - - if (exists_not_none(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - value = NULL; - } - *out = Return(value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* targets; - - if (_PyObject_HasAttrId(obj, &PyId_targets)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_targets); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - targets = asdl_seq_new(len, arena); - if (targets == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(targets, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); - return 1; - } - *out = Delete(targets, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* targets; - expr_ty value; - - if (_PyObject_HasAttrId(obj, &PyId_targets)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_targets); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - targets = asdl_seq_new(len, arena); - if (targets == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(targets, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); - return 1; - } - *out = Assign(targets, value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty target; - operator_ty op; - expr_ty value; - - if (_PyObject_HasAttrId(obj, &PyId_target)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_target); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &target, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_op)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_op); - if (tmp == NULL) goto failed; - res = obj2ast_operator(tmp, &op, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); - return 1; - } - *out = AugAssign(target, op, value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty target; - expr_ty iter; - asdl_seq* body; - asdl_seq* orelse; - - if (_PyObject_HasAttrId(obj, &PyId_target)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_target); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &target, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_iter)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_iter); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &iter, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_orelse)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_orelse); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - orelse = asdl_seq_new(len, arena); - if (orelse == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(orelse, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); - return 1; - } - *out = For(target, iter, body, orelse, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty test; - asdl_seq* body; - asdl_seq* orelse; - - if (_PyObject_HasAttrId(obj, &PyId_test)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_test); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &test, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_orelse)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_orelse); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - orelse = asdl_seq_new(len, arena); - if (orelse == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(orelse, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); - return 1; - } - *out = While(test, body, orelse, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty test; - asdl_seq* body; - asdl_seq* orelse; - - if (_PyObject_HasAttrId(obj, &PyId_test)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_test); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &test, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_orelse)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_orelse); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - orelse = asdl_seq_new(len, arena); - if (orelse == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(orelse, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); - return 1; - } - *out = If(test, body, orelse, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* items; - asdl_seq* body; - - if (_PyObject_HasAttrId(obj, &PyId_items)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_items); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - items = asdl_seq_new(len, arena); - if (items == NULL) goto failed; - for (i = 0; i < len; i++) { - withitem_ty value; - res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(items, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); - return 1; - } - *out = With(items, body, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty exc; - expr_ty cause; - - if (exists_not_none(obj, &PyId_exc)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_exc); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &exc, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - exc = NULL; - } - if (exists_not_none(obj, &PyId_cause)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_cause); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &cause, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - cause = NULL; - } - *out = Raise(exc, cause, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* body; - asdl_seq* handlers; - asdl_seq* orelse; - asdl_seq* finalbody; - - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_handlers)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_handlers); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - handlers = asdl_seq_new(len, arena); - if (handlers == NULL) goto failed; - for (i = 0; i < len; i++) { - excepthandler_ty value; - res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(handlers, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_orelse)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_orelse); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - orelse = asdl_seq_new(len, arena); - if (orelse == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(orelse, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - finalbody = asdl_seq_new(len, arena); - if (finalbody == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(finalbody, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); - return 1; - } - *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, - arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty test; - expr_ty msg; - - if (_PyObject_HasAttrId(obj, &PyId_test)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_test); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &test, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); - return 1; - } - if (exists_not_none(obj, &PyId_msg)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_msg); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &msg, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - msg = NULL; - } - *out = Assert(test, msg, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* names; - - if (_PyObject_HasAttrId(obj, &PyId_names)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_names); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - names = asdl_seq_new(len, arena); - if (names == NULL) goto failed; - for (i = 0; i < len; i++) { - alias_ty value; - res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(names, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); - return 1; - } - *out = Import(names, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - identifier module; - asdl_seq* names; - int level; - - if (exists_not_none(obj, &PyId_module)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_module); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &module, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - module = NULL; - } - if (_PyObject_HasAttrId(obj, &PyId_names)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_names); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - names = asdl_seq_new(len, arena); - if (names == NULL) goto failed; - for (i = 0; i < len; i++) { - alias_ty value; - res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(names, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); - return 1; - } - if (exists_not_none(obj, &PyId_level)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_level); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &level, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - level = 0; - } - *out = ImportFrom(module, names, level, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* names; - - if (_PyObject_HasAttrId(obj, &PyId_names)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_names); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - names = asdl_seq_new(len, arena); - if (names == NULL) goto failed; - for (i = 0; i < len; i++) { - identifier value; - res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(names, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); - return 1; - } - *out = Global(names, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* names; - - if (_PyObject_HasAttrId(obj, &PyId_names)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_names); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - names = asdl_seq_new(len, arena); - if (names == NULL) goto failed; - for (i = 0; i < len; i++) { - identifier value; - res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(names, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); - return 1; - } - *out = Nonlocal(names, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); - return 1; - } - *out = Expr(value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - - *out = Pass(lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - - *out = Break(lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - - *out = Continue(lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); - failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) { - int isinstance; - - PyObject *tmp = NULL; - int lineno; - int col_offset; - - if (obj == Py_None) { - *out = NULL; - return 0; - } - if (_PyObject_HasAttrId(obj, &PyId_lineno)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_lineno); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &lineno, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); + int isinstance; + + PyObject *tmp = NULL; + int lineno; + int col_offset; + + if (obj == Py_None) { + *out = NULL; + return 0; + } + if (_PyObject_HasAttrId(obj, &PyId_lineno)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_lineno); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &lineno, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &col_offset, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); + return 1; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + boolop_ty op; + asdl_seq* values; + + if (_PyObject_HasAttrId(obj, &PyId_op)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_op); + if (tmp == NULL) goto failed; + res = obj2ast_boolop(tmp, &op, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_values)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_values); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + values = asdl_seq_new(len, arena); + if (values == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(values, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); + return 1; + } + *out = BoolOp(op, values, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty left; + operator_ty op; + expr_ty right; + + if (_PyObject_HasAttrId(obj, &PyId_left)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_left); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &left, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_op)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_op); + if (tmp == NULL) goto failed; + res = obj2ast_operator(tmp, &op, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_right)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_right); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &right, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); + return 1; + } + *out = BinOp(left, op, right, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + unaryop_ty op; + expr_ty operand; + + if (_PyObject_HasAttrId(obj, &PyId_op)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_op); + if (tmp == NULL) goto failed; + res = obj2ast_unaryop(tmp, &op, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_operand)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_operand); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &operand, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); + return 1; + } + *out = UnaryOp(op, operand, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + arguments_ty args; + expr_ty body; + + if (_PyObject_HasAttrId(obj, &PyId_args)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_args); + if (tmp == NULL) goto failed; + res = obj2ast_arguments(tmp, &args, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &body, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); + return 1; + } + *out = Lambda(args, body, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty test; + expr_ty body; + expr_ty orelse; + + if (_PyObject_HasAttrId(obj, &PyId_test)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_test); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &test, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &body, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &orelse, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); + return 1; + } + *out = IfExp(test, body, orelse, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* keys; + asdl_seq* values; + + if (_PyObject_HasAttrId(obj, &PyId_keys)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_keys); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + keys = asdl_seq_new(len, arena); + if (keys == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(keys, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_values)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_values); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + values = asdl_seq_new(len, arena); + if (values == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(values, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); + return 1; + } + *out = Dict(keys, values, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* elts; + + if (_PyObject_HasAttrId(obj, &PyId_elts)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_elts); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + elts = asdl_seq_new(len, arena); + if (elts == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(elts, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); + return 1; + } + *out = Set(elts, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty elt; + asdl_seq* generators; + + if (_PyObject_HasAttrId(obj, &PyId_elt)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_elt); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &elt, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_generators)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_generators); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + generators = asdl_seq_new(len, arena); + if (generators == NULL) goto failed; + for (i = 0; i < len; i++) { + comprehension_ty value; + res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(generators, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); + return 1; + } + *out = ListComp(elt, generators, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty elt; + asdl_seq* generators; + + if (_PyObject_HasAttrId(obj, &PyId_elt)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_elt); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &elt, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_generators)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_generators); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + generators = asdl_seq_new(len, arena); + if (generators == NULL) goto failed; + for (i = 0; i < len; i++) { + comprehension_ty value; + res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(generators, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); + return 1; + } + *out = SetComp(elt, generators, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty key; + expr_ty value; + asdl_seq* generators; + + if (_PyObject_HasAttrId(obj, &PyId_key)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_key); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &key, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_generators)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_generators); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + generators = asdl_seq_new(len, arena); + if (generators == NULL) goto failed; + for (i = 0; i < len; i++) { + comprehension_ty value; + res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(generators, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); + return 1; + } + *out = DictComp(key, value, generators, lineno, col_offset, + arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty elt; + asdl_seq* generators; + + if (_PyObject_HasAttrId(obj, &PyId_elt)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_elt); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &elt, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_generators)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_generators); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + generators = asdl_seq_new(len, arena); + if (generators == NULL) goto failed; + for (i = 0; i < len; i++) { + comprehension_ty value; + res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(generators, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); + return 1; + } + *out = GeneratorExp(elt, generators, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + value = NULL; + } + *out = Yield(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); + return 1; + } + *out = YieldFrom(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty left; + asdl_int_seq* ops; + asdl_seq* comparators; + + if (_PyObject_HasAttrId(obj, &PyId_left)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_left); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &left, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ops)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_ops); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + ops = asdl_int_seq_new(len, arena); + if (ops == NULL) goto failed; + for (i = 0; i < len; i++) { + cmpop_ty value; + res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(ops, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_comparators)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_comparators); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + comparators = asdl_seq_new(len, arena); + if (comparators == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(comparators, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); + return 1; + } + *out = Compare(left, ops, comparators, lineno, col_offset, + arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty func; + asdl_seq* args; + asdl_seq* keywords; + expr_ty starargs; + expr_ty kwargs; + + if (_PyObject_HasAttrId(obj, &PyId_func)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_func); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &func, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_args)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_args); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + args = asdl_seq_new(len, arena); + if (args == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(args, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_keywords)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_keywords); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + keywords = asdl_seq_new(len, arena); + if (keywords == NULL) goto failed; + for (i = 0; i < len; i++) { + keyword_ty value; + res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(keywords, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_starargs)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_starargs); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &starargs, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + starargs = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &kwargs, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + kwargs = NULL; + } + *out = Call(func, args, keywords, starargs, kwargs, lineno, + col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + object n; + + if (_PyObject_HasAttrId(obj, &PyId_n)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_n); + if (tmp == NULL) goto failed; + res = obj2ast_object(tmp, &n, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); + return 1; + } + *out = Num(n, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + string s; + + if (_PyObject_HasAttrId(obj, &PyId_s)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_s); + if (tmp == NULL) goto failed; + res = obj2ast_string(tmp, &s, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); + return 1; + } + *out = Str(s, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + bytes s; + + if (_PyObject_HasAttrId(obj, &PyId_s)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_s); + if (tmp == NULL) goto failed; + res = obj2ast_bytes(tmp, &s, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); + return 1; + } + *out = Bytes(s, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + singleton value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_singleton(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); + return 1; + } + *out = NameConstant(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + + *out = Ellipsis(lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + identifier attr; + expr_context_ty ctx; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_attr)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_attr); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &attr, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); + if (tmp == NULL) goto failed; + res = obj2ast_expr_context(tmp, &ctx, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); + return 1; + } + *out = Attribute(value, attr, ctx, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + slice_ty slice; + expr_context_ty ctx; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_slice)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_slice); + if (tmp == NULL) goto failed; + res = obj2ast_slice(tmp, &slice, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); + if (tmp == NULL) goto failed; + res = obj2ast_expr_context(tmp, &ctx, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); + return 1; + } + *out = Subscript(value, slice, ctx, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + expr_context_ty ctx; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); + if (tmp == NULL) goto failed; + res = obj2ast_expr_context(tmp, &ctx, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); + return 1; + } + *out = Starred(value, ctx, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + identifier id; + expr_context_ty ctx; + + if (_PyObject_HasAttrId(obj, &PyId_id)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_id); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &id, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); + if (tmp == NULL) goto failed; + res = obj2ast_expr_context(tmp, &ctx, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); + return 1; + } + *out = Name(id, ctx, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* elts; + expr_context_ty ctx; + + if (_PyObject_HasAttrId(obj, &PyId_elts)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_elts); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + elts = asdl_seq_new(len, arena); + if (elts == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(elts, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); + if (tmp == NULL) goto failed; + res = obj2ast_expr_context(tmp, &ctx, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); + return 1; + } + *out = List(elts, ctx, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* elts; + expr_context_ty ctx; + + if (_PyObject_HasAttrId(obj, &PyId_elts)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_elts); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + elts = asdl_seq_new(len, arena); + if (elts == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(elts, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); + if (tmp == NULL) goto failed; + res = obj2ast_expr_context(tmp, &ctx, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); + return 1; + } + *out = Tuple(elts, ctx, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); + failed: + Py_XDECREF(tmp); return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &col_offset, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); - return 1; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - boolop_ty op; - asdl_seq* values; - - if (_PyObject_HasAttrId(obj, &PyId_op)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_op); - if (tmp == NULL) goto failed; - res = obj2ast_boolop(tmp, &op, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_values)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_values); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - values = asdl_seq_new(len, arena); - if (values == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(values, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); - return 1; - } - *out = BoolOp(op, values, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty left; - operator_ty op; - expr_ty right; - - if (_PyObject_HasAttrId(obj, &PyId_left)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_left); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &left, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_op)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_op); - if (tmp == NULL) goto failed; - res = obj2ast_operator(tmp, &op, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_right)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_right); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &right, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); - return 1; - } - *out = BinOp(left, op, right, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - unaryop_ty op; - expr_ty operand; - - if (_PyObject_HasAttrId(obj, &PyId_op)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_op); - if (tmp == NULL) goto failed; - res = obj2ast_unaryop(tmp, &op, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_operand)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_operand); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &operand, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); - return 1; - } - *out = UnaryOp(op, operand, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - arguments_ty args; - expr_ty body; - - if (_PyObject_HasAttrId(obj, &PyId_args)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_args); - if (tmp == NULL) goto failed; - res = obj2ast_arguments(tmp, &args, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &body, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); - return 1; - } - *out = Lambda(args, body, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty test; - expr_ty body; - expr_ty orelse; - - if (_PyObject_HasAttrId(obj, &PyId_test)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_test); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &test, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &body, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_orelse)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_orelse); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &orelse, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); - return 1; - } - *out = IfExp(test, body, orelse, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* keys; - asdl_seq* values; - - if (_PyObject_HasAttrId(obj, &PyId_keys)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_keys); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - keys = asdl_seq_new(len, arena); - if (keys == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(keys, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_values)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_values); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - values = asdl_seq_new(len, arena); - if (values == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(values, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); - return 1; - } - *out = Dict(keys, values, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* elts; - - if (_PyObject_HasAttrId(obj, &PyId_elts)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_elts); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - elts = asdl_seq_new(len, arena); - if (elts == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(elts, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); - return 1; - } - *out = Set(elts, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty elt; - asdl_seq* generators; - - if (_PyObject_HasAttrId(obj, &PyId_elt)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_elt); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &elt, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_generators)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_generators); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - generators = asdl_seq_new(len, arena); - if (generators == NULL) goto failed; - for (i = 0; i < len; i++) { - comprehension_ty value; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(generators, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); - return 1; - } - *out = ListComp(elt, generators, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty elt; - asdl_seq* generators; - - if (_PyObject_HasAttrId(obj, &PyId_elt)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_elt); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &elt, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_generators)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_generators); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - generators = asdl_seq_new(len, arena); - if (generators == NULL) goto failed; - for (i = 0; i < len; i++) { - comprehension_ty value; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(generators, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); - return 1; - } - *out = SetComp(elt, generators, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty key; - expr_ty value; - asdl_seq* generators; - - if (_PyObject_HasAttrId(obj, &PyId_key)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_key); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &key, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_generators)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_generators); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - generators = asdl_seq_new(len, arena); - if (generators == NULL) goto failed; - for (i = 0; i < len; i++) { - comprehension_ty value; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(generators, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); - return 1; - } - *out = DictComp(key, value, generators, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty elt; - asdl_seq* generators; - - if (_PyObject_HasAttrId(obj, &PyId_elt)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_elt); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &elt, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_generators)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_generators); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - generators = asdl_seq_new(len, arena); - if (generators == NULL) goto failed; - for (i = 0; i < len; i++) { - comprehension_ty value; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(generators, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); - return 1; - } - *out = GeneratorExp(elt, generators, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - - if (exists_not_none(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - value = NULL; - } - *out = Yield(value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); - return 1; - } - *out = YieldFrom(value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty left; - asdl_int_seq* ops; - asdl_seq* comparators; - - if (_PyObject_HasAttrId(obj, &PyId_left)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_left); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &left, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ops)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_ops); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - ops = asdl_int_seq_new(len, arena); - if (ops == NULL) goto failed; - for (i = 0; i < len; i++) { - cmpop_ty value; - res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(ops, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_comparators)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_comparators); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - comparators = asdl_seq_new(len, arena); - if (comparators == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(comparators, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); - return 1; - } - *out = Compare(left, ops, comparators, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty func; - asdl_seq* args; - asdl_seq* keywords; - expr_ty starargs; - expr_ty kwargs; - - if (_PyObject_HasAttrId(obj, &PyId_func)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_func); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &func, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_args)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_args); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - args = asdl_seq_new(len, arena); - if (args == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(args, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_keywords)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_keywords); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - keywords = asdl_seq_new(len, arena); - if (keywords == NULL) goto failed; - for (i = 0; i < len; i++) { - keyword_ty value; - res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(keywords, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); - return 1; - } - if (exists_not_none(obj, &PyId_starargs)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_starargs); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &starargs, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - starargs = NULL; - } - if (exists_not_none(obj, &PyId_kwargs)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &kwargs, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - kwargs = NULL; - } - *out = Call(func, args, keywords, starargs, kwargs, lineno, col_offset, - arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - object n; - - if (_PyObject_HasAttrId(obj, &PyId_n)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_n); - if (tmp == NULL) goto failed; - res = obj2ast_object(tmp, &n, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); - return 1; - } - *out = Num(n, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - string s; - - if (_PyObject_HasAttrId(obj, &PyId_s)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_s); - if (tmp == NULL) goto failed; - res = obj2ast_string(tmp, &s, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); - return 1; - } - *out = Str(s, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - bytes s; - - if (_PyObject_HasAttrId(obj, &PyId_s)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_s); - if (tmp == NULL) goto failed; - res = obj2ast_bytes(tmp, &s, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); - return 1; - } - *out = Bytes(s, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - singleton value; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_singleton(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); - return 1; - } - *out = NameConstant(value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - - *out = Ellipsis(lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - identifier attr; - expr_context_ty ctx; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_attr)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_attr); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &attr, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ctx)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_ctx); - if (tmp == NULL) goto failed; - res = obj2ast_expr_context(tmp, &ctx, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); - return 1; - } - *out = Attribute(value, attr, ctx, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - slice_ty slice; - expr_context_ty ctx; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_slice)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_slice); - if (tmp == NULL) goto failed; - res = obj2ast_slice(tmp, &slice, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ctx)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_ctx); - if (tmp == NULL) goto failed; - res = obj2ast_expr_context(tmp, &ctx, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); - return 1; - } - *out = Subscript(value, slice, ctx, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - expr_context_ty ctx; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ctx)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_ctx); - if (tmp == NULL) goto failed; - res = obj2ast_expr_context(tmp, &ctx, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); - return 1; - } - *out = Starred(value, ctx, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - identifier id; - expr_context_ty ctx; - - if (_PyObject_HasAttrId(obj, &PyId_id)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_id); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &id, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ctx)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_ctx); - if (tmp == NULL) goto failed; - res = obj2ast_expr_context(tmp, &ctx, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); - return 1; - } - *out = Name(id, ctx, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* elts; - expr_context_ty ctx; - - if (_PyObject_HasAttrId(obj, &PyId_elts)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_elts); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - elts = asdl_seq_new(len, arena); - if (elts == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(elts, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ctx)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_ctx); - if (tmp == NULL) goto failed; - res = obj2ast_expr_context(tmp, &ctx, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); - return 1; - } - *out = List(elts, ctx, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* elts; - expr_context_ty ctx; - - if (_PyObject_HasAttrId(obj, &PyId_elts)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_elts); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - elts = asdl_seq_new(len, arena); - if (elts == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(elts, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ctx)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_ctx); - if (tmp == NULL) goto failed; - res = obj2ast_expr_context(tmp, &ctx, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); - return 1; - } - *out = Tuple(elts, ctx, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); - failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) { - int isinstance; - - isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); - if (isinstance == -1) { + int isinstance; + + isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Load; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Store; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Del; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = AugLoad; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = AugStore; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Param; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); return 1; - } - if (isinstance) { - *out = Load; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Store; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Del; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = AugLoad; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = AugStore; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Param; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); - return 1; } int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) { - int isinstance; - - PyObject *tmp = NULL; - - if (obj == Py_None) { - *out = NULL; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); - if (isinstance == -1) { + int isinstance; + + PyObject *tmp = NULL; + + if (obj == Py_None) { + *out = NULL; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty lower; + expr_ty upper; + expr_ty step; + + if (_PyObject_HasAttrId(obj, &PyId_lower)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_lower); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &lower, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + lower = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_upper)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_upper); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &upper, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + upper = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_step)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_step); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &step, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + step = NULL; + } + *out = Slice(lower, upper, step, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + asdl_seq* dims; + + if (_PyObject_HasAttrId(obj, &PyId_dims)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_dims); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + dims = asdl_seq_new(len, arena); + if (dims == NULL) goto failed; + for (i = 0; i < len; i++) { + slice_ty value; + res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(dims, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); + return 1; + } + *out = ExtSlice(dims, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); + return 1; + } + *out = Index(value, arena); + if (*out == NULL) goto failed; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); + failed: + Py_XDECREF(tmp); return 1; - } - if (isinstance) { - expr_ty lower; - expr_ty upper; - expr_ty step; - - if (exists_not_none(obj, &PyId_lower)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_lower); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &lower, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - lower = NULL; - } - if (exists_not_none(obj, &PyId_upper)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_upper); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &upper, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - upper = NULL; - } - if (exists_not_none(obj, &PyId_step)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_step); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &step, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - step = NULL; - } - *out = Slice(lower, upper, step, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* dims; - - if (_PyObject_HasAttrId(obj, &PyId_dims)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_dims); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - dims = asdl_seq_new(len, arena); - if (dims == NULL) goto failed; - for (i = 0; i < len; i++) { - slice_ty value; - res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(dims, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); - return 1; - } - *out = ExtSlice(dims, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty value; - - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); - return 1; - } - *out = Index(value, arena); - if (*out == NULL) goto failed; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); - failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) { - int isinstance; - - isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); - if (isinstance == -1) { + int isinstance; + + isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = And; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Or; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); return 1; - } - if (isinstance) { - *out = And; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Or; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); - return 1; } int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) { - int isinstance; - - isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); - if (isinstance == -1) { + int isinstance; + + isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Add; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Sub; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Mult; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Div; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Mod; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Pow; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = LShift; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = RShift; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = BitOr; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = BitXor; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = BitAnd; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = FloorDiv; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); return 1; - } - if (isinstance) { - *out = Add; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Sub; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Mult; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Div; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Mod; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Pow; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = LShift; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = RShift; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = BitOr; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = BitXor; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = BitAnd; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = FloorDiv; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); - return 1; } int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) { - int isinstance; - - isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); - if (isinstance == -1) { + int isinstance; + + isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Invert; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Not; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = UAdd; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = USub; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); return 1; - } - if (isinstance) { - *out = Invert; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Not; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = UAdd; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = USub; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); - return 1; } int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) { - int isinstance; - - isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); - if (isinstance == -1) { + int isinstance; + + isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Eq; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = NotEq; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Lt; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = LtE; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Gt; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = GtE; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Is; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = IsNot; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = In; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = NotIn; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); return 1; - } - if (isinstance) { - *out = Eq; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = NotEq; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Lt; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = LtE; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Gt; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = GtE; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Is; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = IsNot; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = In; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = NotIn; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); - return 1; } int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) { - PyObject* tmp = NULL; - expr_ty target; - expr_ty iter; - asdl_seq* ifs; - - if (_PyObject_HasAttrId(obj, &PyId_target)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_target); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &target, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); + PyObject* tmp = NULL; + expr_ty target; + expr_ty iter; + asdl_seq* ifs; + + if (_PyObject_HasAttrId(obj, &PyId_target)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_target); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &target, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_iter)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_iter); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &iter, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_ifs)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_ifs); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + ifs = asdl_seq_new(len, arena); + if (ifs == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(ifs, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); + return 1; + } + *out = comprehension(target, iter, ifs, arena); + return 0; +failed: + Py_XDECREF(tmp); return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_iter)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_iter); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &iter, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_ifs)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_ifs); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - ifs = asdl_seq_new(len, arena); - if (ifs == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(ifs, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); - return 1; - } - *out = comprehension(target, iter, ifs, arena); - return 0; -failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) { - int isinstance; - - PyObject *tmp = NULL; - int lineno; - int col_offset; - - if (obj == Py_None) { - *out = NULL; - return 0; - } - if (_PyObject_HasAttrId(obj, &PyId_lineno)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_lineno); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &lineno, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); + int isinstance; + + PyObject *tmp = NULL; + int lineno; + int col_offset; + + if (obj == Py_None) { + *out = NULL; + return 0; + } + if (_PyObject_HasAttrId(obj, &PyId_lineno)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_lineno); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &lineno, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &col_offset, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); + return 1; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty type; + identifier name; + asdl_seq* body; + + if (_PyObject_HasAttrId(obj, &PyId_type)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_type); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &type, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + type = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_name)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_name); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &name, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + name = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_body)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_body); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + body = asdl_seq_new(len, arena); + if (body == NULL) goto failed; + for (i = 0; i < len; i++) { + stmt_ty value; + res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(body, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); + return 1; + } + *out = ExceptHandler(type, name, body, lineno, col_offset, + arena); + if (*out == NULL) goto failed; + return 0; + } + + PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); + failed: + Py_XDECREF(tmp); return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); - if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &col_offset, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); - return 1; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - expr_ty type; - identifier name; - asdl_seq* body; - - if (exists_not_none(obj, &PyId_type)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_type); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &type, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - type = NULL; - } - if (exists_not_none(obj, &PyId_name)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_name); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &name, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - name = NULL; - } - if (_PyObject_HasAttrId(obj, &PyId_body)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_body); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); - return 1; - } - *out = ExceptHandler(type, name, body, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); - failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) { - PyObject* tmp = NULL; - asdl_seq* args; - arg_ty vararg; - asdl_seq* kwonlyargs; - asdl_seq* kw_defaults; - arg_ty kwarg; - asdl_seq* defaults; - - if (_PyObject_HasAttrId(obj, &PyId_args)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_args); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - args = asdl_seq_new(len, arena); - if (args == NULL) goto failed; - for (i = 0; i < len; i++) { - arg_ty value; - res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(args, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); + PyObject* tmp = NULL; + asdl_seq* args; + identifier vararg; + expr_ty varargannotation; + asdl_seq* kwonlyargs; + identifier kwarg; + expr_ty kwargannotation; + asdl_seq* defaults; + asdl_seq* kw_defaults; + + if (_PyObject_HasAttrId(obj, &PyId_args)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_args); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + args = asdl_seq_new(len, arena); + if (args == NULL) goto failed; + for (i = 0; i < len; i++) { + arg_ty value; + res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(args, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_vararg)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_vararg); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &vararg, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + vararg = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &varargannotation, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + varargannotation = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + kwonlyargs = asdl_seq_new(len, arena); + if (kwonlyargs == NULL) goto failed; + for (i = 0; i < len; i++) { + arg_ty value; + res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(kwonlyargs, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &kwarg, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + kwarg = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &kwargannotation, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + kwargannotation = NULL; + } + if (_PyObject_HasAttrId(obj, &PyId_defaults)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_defaults); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + defaults = asdl_seq_new(len, arena); + if (defaults == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(defaults, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { + int res; + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); + if (tmp == NULL) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + kw_defaults = asdl_seq_new(len, arena); + if (kw_defaults == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(kw_defaults, i, value); + } + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); + return 1; + } + *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, + kwargannotation, defaults, kw_defaults, arena); + return 0; +failed: + Py_XDECREF(tmp); return 1; - } - if (exists_not_none(obj, &PyId_vararg)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_vararg); - if (tmp == NULL) goto failed; - res = obj2ast_arg(tmp, &vararg, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - vararg = NULL; - } - if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - kwonlyargs = asdl_seq_new(len, arena); - if (kwonlyargs == NULL) goto failed; - for (i = 0; i < len; i++) { - arg_ty value; - res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(kwonlyargs, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); - return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - kw_defaults = asdl_seq_new(len, arena); - if (kw_defaults == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(kw_defaults, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); - return 1; - } - if (exists_not_none(obj, &PyId_kwarg)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); - if (tmp == NULL) goto failed; - res = obj2ast_arg(tmp, &kwarg, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - kwarg = NULL; - } - if (_PyObject_HasAttrId(obj, &PyId_defaults)) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = _PyObject_GetAttrId(obj, &PyId_defaults); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - defaults = asdl_seq_new(len, arena); - if (defaults == NULL) goto failed; - for (i = 0; i < len; i++) { - expr_ty value; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(defaults, i, value); - } - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); - return 1; - } - *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, - arena); - return 0; -failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) { - PyObject* tmp = NULL; - identifier arg; - expr_ty annotation; - - if (_PyObject_HasAttrId(obj, &PyId_arg)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_arg); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &arg, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); + PyObject* tmp = NULL; + identifier arg; + expr_ty annotation; + + if (_PyObject_HasAttrId(obj, &PyId_arg)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_arg); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &arg, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_annotation)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_annotation); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &annotation, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + annotation = NULL; + } + *out = arg(arg, annotation, arena); + return 0; +failed: + Py_XDECREF(tmp); return 1; - } - if (exists_not_none(obj, &PyId_annotation)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_annotation); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &annotation, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - annotation = NULL; - } - *out = arg(arg, annotation, arena); - return 0; -failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) { - PyObject* tmp = NULL; - identifier arg; - expr_ty value; - - if (_PyObject_HasAttrId(obj, &PyId_arg)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_arg); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &arg, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); + PyObject* tmp = NULL; + identifier arg; + expr_ty value; + + if (_PyObject_HasAttrId(obj, &PyId_arg)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_arg); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &arg, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); + return 1; + } + *out = keyword(arg, value, arena); + return 0; +failed: + Py_XDECREF(tmp); return 1; - } - if (_PyObject_HasAttrId(obj, &PyId_value)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_value); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); - return 1; - } - *out = keyword(arg, value, arena); - return 0; -failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) { - PyObject* tmp = NULL; - identifier name; - identifier asname; - - if (_PyObject_HasAttrId(obj, &PyId_name)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_name); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &name, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); + PyObject* tmp = NULL; + identifier name; + identifier asname; + + if (_PyObject_HasAttrId(obj, &PyId_name)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_name); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &name, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_asname)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_asname); + if (tmp == NULL) goto failed; + res = obj2ast_identifier(tmp, &asname, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + asname = NULL; + } + *out = alias(name, asname, arena); + return 0; +failed: + Py_XDECREF(tmp); return 1; - } - if (exists_not_none(obj, &PyId_asname)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_asname); - if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &asname, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - asname = NULL; - } - *out = alias(name, asname, arena); - return 0; -failed: - Py_XDECREF(tmp); - return 1; } int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) { - PyObject* tmp = NULL; - expr_ty context_expr; - expr_ty optional_vars; - - if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &context_expr, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); + PyObject* tmp = NULL; + expr_ty context_expr; + expr_ty optional_vars; + + if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &context_expr, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); + return 1; + } + if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &optional_vars, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + optional_vars = NULL; + } + *out = withitem(context_expr, optional_vars, arena); + return 0; +failed: + Py_XDECREF(tmp); return 1; - } - if (exists_not_none(obj, &PyId_optional_vars)) { - int res; - tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &optional_vars, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } else { - optional_vars = NULL; - } - *out = withitem(context_expr, optional_vars, arena); - return 0; -failed: - Py_XDECREF(tmp); - return 1; } @@ -6827,195 +6978,225 @@ PyMODINIT_FUNC PyInit__ast(void) { - PyObject *m, *d; - if (!init_types()) return NULL; - m = PyModule_Create(&_astmodule); - if (!m) return NULL; - d = PyModule_GetDict(m); - if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; - if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) - return NULL; - if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; - if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; - if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; - if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; - if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; - if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; - if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; - if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; - if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; - if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; - if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; - if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; - if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; - if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; - if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; - if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; - if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; - if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) - < 0) return NULL; - if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) - < 0) return NULL; - if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) - < 0) return NULL; - if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; - if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) - return NULL; - return m; + PyObject *m, *d; + if (!init_types()) return NULL; + m = PyModule_Create(&_astmodule); + if (!m) return NULL; + d = PyModule_GetDict(m); + if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return + NULL; + if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) + return NULL; + if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) + < 0) return NULL; + if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) + < 0) return NULL; + if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; + if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "GeneratorExp", + (PyObject*)GeneratorExp_type) < 0) return NULL; + if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "NameConstant", + (PyObject*)NameConstant_type) < 0) return NULL; + if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "expr_context", + (PyObject*)expr_context_type) < 0) return NULL; + if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; + if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; + if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; + if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; + if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; + if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; + if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "comprehension", + (PyObject*)comprehension_type) < 0) return NULL; + if (PyDict_SetItemString(d, "excepthandler", + (PyObject*)excepthandler_type) < 0) return NULL; + if (PyDict_SetItemString(d, "ExceptHandler", + (PyObject*)ExceptHandler_type) < 0) return NULL; + if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < + 0) return NULL; + if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) + return NULL; + if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return + NULL; + if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) + return NULL; + return m; } PyObject* PyAST_mod2obj(mod_ty t) { - if (!init_types()) - return NULL; + init_types(); return ast2obj_mod(t); } @@ -7029,8 +7210,7 @@ int isinstance; assert(0 <= mode && mode <= 2); - if (!init_types()) - return NULL; + init_types(); isinstance = PyObject_IsInstance(ast, req_type[mode]); if (isinstance == -1) @@ -7048,8 +7228,7 @@ int PyAST_Check(PyObject* obj) { - if (!init_types()) - return -1; + init_types(); return PyObject_IsInstance(obj, (PyObject*)&AST_type); } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/_warnings.c --- a/Python/_warnings.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/_warnings.c Fri Feb 01 23:12:09 2013 +0100 @@ -283,9 +283,9 @@ PyFile_WriteString(source_line_str, f_stderr); PyFile_WriteString("\n", f_stderr); } - else { - _Py_DisplaySourceLine(f_stderr, filename, lineno, 2); - } + else + if (_Py_DisplaySourceLine(f_stderr, filename, lineno, 2) < 0) + return; PyErr_Clear(); } @@ -800,8 +800,8 @@ goto exit; if (module_str != NULL) { module = PyUnicode_FromString(module_str); - if (module == NULL) - goto exit; + if (module == NULL) + goto exit; } if (category == NULL) @@ -820,49 +820,6 @@ return ret; } -int -PyErr_WarnExplicitFormat(PyObject *category, - const char *filename_str, int lineno, - const char *module_str, PyObject *registry, - const char *format, ...) -{ - PyObject *message; - PyObject *module = NULL; - PyObject *filename = PyUnicode_DecodeFSDefault(filename_str); - int ret = -1; - va_list vargs; - - if (filename == NULL) - goto exit; - if (module_str != NULL) { - module = PyUnicode_FromString(module_str); - if (module == NULL) - goto exit; - } - -#ifdef HAVE_STDARG_PROTOTYPES - va_start(vargs, format); -#else - va_start(vargs); -#endif - message = PyUnicode_FromFormatV(format, vargs); - if (message != NULL) { - PyObject *res; - res = warn_explicit(category, message, filename, lineno, - module, registry, NULL); - Py_DECREF(message); - if (res != NULL) { - Py_DECREF(res); - ret = 0; - } - } - va_end(vargs); -exit: - Py_XDECREF(module); - Py_XDECREF(filename); - return ret; -} - PyDoc_STRVAR(warn_doc, "Issue a warning, or maybe ignore it or raise an exception."); diff -r 35c88c53cf64 -r ecc10f0afb76 Python/ast.c --- a/Python/ast.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/ast.c Fri Feb 01 23:12:09 2013 +0100 @@ -109,14 +109,22 @@ { if (!validate_args(args->args)) return 0; - if (args->vararg && args->vararg->annotation - && !validate_expr(args->vararg->annotation, Load)) { + if (args->varargannotation) { + if (!args->vararg) { + PyErr_SetString(PyExc_ValueError, "varargannotation but no vararg on arguments"); + return 0; + } + if (!validate_expr(args->varargannotation, Load)) return 0; } if (!validate_args(args->kwonlyargs)) return 0; - if (args->kwarg && args->kwarg->annotation - && !validate_expr(args->kwarg->annotation, Load)) { + if (args->kwargannotation) { + if (!args->kwarg) { + PyErr_SetString(PyExc_ValueError, "kwargannotation but no kwarg on arguments"); + return 0; + } + if (!validate_expr(args->kwargannotation, Load)) return 0; } if (asdl_seq_LEN(args->defaults) > asdl_seq_LEN(args->args)) { @@ -528,11 +536,11 @@ if (!c->c_normalize) return 0; c->c_normalize_args = Py_BuildValue("(sN)", "NFKC", Py_None); + PyTuple_SET_ITEM(c->c_normalize_args, 1, NULL); if (!c->c_normalize_args) { Py_CLEAR(c->c_normalize); return 0; } - PyTuple_SET_ITEM(c->c_normalize_args, 1, NULL); return 1; } @@ -560,10 +568,7 @@ id = id2; } PyUnicode_InternInPlace(&id); - if (PyArena_AddPyObject(c->c_arena, id) < 0) { - Py_DECREF(id); - return NULL; - } + PyArena_AddPyObject(c->c_arena, id); return id; } @@ -1118,7 +1123,6 @@ identifier name; expr_ty annotation = NULL; node *ch; - arg_ty tmp; assert(TYPE(n) == tfpdef || TYPE(n) == vfpdef); ch = CHILD(n, 0); @@ -1134,13 +1138,7 @@ return NULL; } - tmp = arg(name, annotation, c->c_arena); - if (!tmp) - return NULL; - - tmp->lineno = LINENO(n); - tmp->col_offset = n->n_col_offset; - return tmp; + return arg(name, annotation, c->c_arena); } /* returns -1 if failed to handle keyword only arguments @@ -1236,13 +1234,15 @@ int i, j, k, nposargs = 0, nkwonlyargs = 0; int nposdefaults = 0, found_default = 0; asdl_seq *posargs, *posdefaults, *kwonlyargs, *kwdefaults; - arg_ty vararg = NULL, kwarg = NULL; + identifier vararg = NULL, kwarg = NULL; arg_ty arg; + expr_ty varargannotation = NULL, kwargannotation = NULL; node *ch; if (TYPE(n) == parameters) { if (NCH(n) == 2) /* () as argument list */ - return arguments(NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena); + return arguments(NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, c->c_arena); n = CHILD(n, 1); } assert(TYPE(n) == typedargslist || TYPE(n) == varargslist); @@ -1348,10 +1348,17 @@ i = res; /* res has new position to process */ } else { - vararg = ast_for_arg(c, ch); + vararg = NEW_IDENTIFIER(CHILD(ch, 0)); if (!vararg) return NULL; - + if (forbidden_name(c, vararg, CHILD(ch, 0), 0)) + return NULL; + if (NCH(ch) > 1) { + /* there is an annotation on the vararg */ + varargannotation = ast_for_expr(c, CHILD(ch, 2)); + if (!varargannotation) + return NULL; + } i += 3; if (i < NCH(n) && (TYPE(CHILD(n, i)) == tfpdef || TYPE(CHILD(n, i)) == vfpdef)) { @@ -1366,9 +1373,17 @@ case DOUBLESTAR: ch = CHILD(n, i+1); /* tfpdef */ assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef); - kwarg = ast_for_arg(c, ch); + kwarg = NEW_IDENTIFIER(CHILD(ch, 0)); if (!kwarg) return NULL; + if (NCH(ch) > 1) { + /* there is an annotation on the kwarg */ + kwargannotation = ast_for_expr(c, CHILD(ch, 2)); + if (!kwargannotation) + return NULL; + } + if (forbidden_name(c, kwarg, CHILD(ch, 0), 0)) + return NULL; i += 3; break; default: @@ -1378,7 +1393,8 @@ return NULL; } } - return arguments(posargs, vararg, kwonlyargs, kwdefaults, kwarg, posdefaults, c->c_arena); + return arguments(posargs, vararg, varargannotation, kwonlyargs, kwarg, + kwargannotation, posdefaults, kwdefaults, c->c_arena); } static expr_ty @@ -1543,7 +1559,8 @@ expr_ty expression; if (NCH(n) == 3) { - args = arguments(NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena); + args = arguments(NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, c->c_arena); if (!args) return NULL; expression = ast_for_expr(c, CHILD(n, 2)); @@ -1826,34 +1843,27 @@ case STRING: { PyObject *str = parsestrplus(c, n, &bytesmode); if (!str) { - const char *errtype = NULL; - if (PyErr_ExceptionMatches(PyExc_UnicodeError)) - errtype = "unicode error"; - else if (PyErr_ExceptionMatches(PyExc_ValueError)) - errtype = "value error"; - if (errtype) { - char buf[128]; + if (PyErr_ExceptionMatches(PyExc_UnicodeError)) { PyObject *type, *value, *tback, *errstr; PyErr_Fetch(&type, &value, &tback); errstr = PyObject_Str(value); if (errstr) { - char *s = _PyUnicode_AsString(errstr); - PyOS_snprintf(buf, sizeof(buf), "(%s) %s", errtype, s); + char *s = ""; + char buf[128]; + s = _PyUnicode_AsString(errstr); + PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s); + ast_error(c, n, buf); Py_DECREF(errstr); } else { - PyOS_snprintf(buf, sizeof(buf), "(%s) unknown error", errtype); + ast_error(c, n, "(unicode error) unknown error"); } - ast_error(c, n, buf); Py_DECREF(type); - Py_XDECREF(value); + Py_DECREF(value); Py_XDECREF(tback); } return NULL; } - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } + PyArena_AddPyObject(c->c_arena, str); if (bytesmode) return Bytes(str, LINENO(n), n->n_col_offset, c->c_arena); else @@ -1864,10 +1874,7 @@ if (!pynum) return NULL; - if (PyArena_AddPyObject(c->c_arena, pynum) < 0) { - Py_DECREF(pynum); - return NULL; - } + PyArena_AddPyObject(c->c_arena, pynum); return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena); } case ELLIPSIS: /* Ellipsis */ @@ -2096,22 +2103,15 @@ if (NCH(n) == 2) return Call(left_expr, NULL, NULL, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); - else { - expr_ty tmp = ast_for_call(c, CHILD(n, 1), left_expr); - if (!tmp) - return NULL; - - tmp->lineno = LINENO(n); - tmp->col_offset = n->n_col_offset; - return tmp; - } + else + return ast_for_call(c, CHILD(n, 1), left_expr); } else if (TYPE(CHILD(n, 0)) == DOT ) { PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1)); if (!attr_id) return NULL; return Attribute(left_expr, attr_id, Load, - LINENO(CHILD(n, 1)), CHILD(n, 1)->n_col_offset, c->c_arena); + LINENO(n), n->n_col_offset, c->c_arena); } else { REQ(CHILD(n, 0), LSQB); @@ -2212,6 +2212,8 @@ tmp = ast_for_trailer(c, ch, e); if (!tmp) return NULL; + tmp->lineno = e->lineno; + tmp->col_offset = e->col_offset; e = tmp; } if (TYPE(CHILD(n, NCH(n) - 1)) == factor) { @@ -2854,19 +2856,13 @@ return NULL; str = uni; PyUnicode_InternInPlace(&str); - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } + PyArena_AddPyObject(c->c_arena, str); return alias(str, NULL, c->c_arena); } break; case STAR: str = PyUnicode_InternFromString("*"); - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } + PyArena_AddPyObject(c->c_arena, str); return alias(str, NULL, c->c_arena); default: PyErr_Format(PyExc_SystemError, @@ -3765,7 +3761,7 @@ int quote = Py_CHARMASK(*s); int rawmode = 0; int need_encoding; - if (Py_ISALPHA(quote)) { + if (isalpha(quote)) { while (!*bytesmode || !rawmode) { if (quote == 'b' || quote == 'B') { quote = *++s; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/bltinmodule.c --- a/Python/bltinmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/bltinmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -57,11 +57,6 @@ return NULL; } func = PyTuple_GET_ITEM(args, 0); /* Better be callable */ - if (!PyFunction_Check(func)) { - PyErr_SetString(PyExc_TypeError, - "__build__class__: func must be a function"); - return NULL; - } name = PyTuple_GET_ITEM(args, 1); if (!PyUnicode_Check(name)) { PyErr_SetString(PyExc_TypeError, @@ -160,9 +155,7 @@ Py_DECREF(bases); return NULL; } - cell = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(func), ns, - NULL, 0, NULL, 0, NULL, 0, NULL, - PyFunction_GET_CLOSURE(func)); + cell = PyObject_CallFunctionObjArgs(func, ns, NULL); if (cell != NULL) { PyObject *margs; margs = PyTuple_Pack(3, name, bases, ns); @@ -270,8 +263,7 @@ PyDoc_STRVAR(all_doc, "all(iterable) -> bool\n\ \n\ -Return True if bool(x) is True for all values x in the iterable.\n\ -If the iterable is empty, return True."); +Return True if bool(x) is True for all values x in the iterable."); static PyObject * builtin_any(PyObject *self, PyObject *v) @@ -313,8 +305,7 @@ PyDoc_STRVAR(any_doc, "any(iterable) -> bool\n\ \n\ -Return True if bool(x) is True for any x in the iterable.\n\ -If the iterable is empty, return False."); +Return True if bool(x) is True for any x in the iterable."); static PyObject * builtin_ascii(PyObject *self, PyObject *v) @@ -1329,35 +1320,26 @@ min_max(PyObject *args, PyObject *kwds, int op) { PyObject *v, *it, *item, *val, *maxitem, *maxval, *keyfunc=NULL; - PyObject *emptytuple, *defaultval = NULL; - static char *kwlist[] = {"key", "default", NULL}; const char *name = op == Py_LT ? "min" : "max"; - const int positional = PyTuple_Size(args) > 1; - int ret; - if (positional) + if (PyTuple_Size(args) > 1) v = args; else if (!PyArg_UnpackTuple(args, (char *)name, 1, 1, &v)) return NULL; - emptytuple = PyTuple_New(0); - if (emptytuple == NULL) - return NULL; - ret = PyArg_ParseTupleAndKeywords(emptytuple, kwds, "|$OO", kwlist, - &keyfunc, &defaultval); - Py_DECREF(emptytuple); - if (!ret) - return NULL; - - if (positional && defaultval != NULL) { - PyErr_Format(PyExc_TypeError, - "Cannot specify a default for %s() with multiple " - "positional arguments", name); - return NULL; + if (kwds != NULL && PyDict_Check(kwds) && PyDict_Size(kwds)) { + keyfunc = PyDict_GetItemString(kwds, "key"); + if (PyDict_Size(kwds)!=1 || keyfunc == NULL) { + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument", name); + return NULL; + } + Py_INCREF(keyfunc); } it = PyObject_GetIter(v); if (it == NULL) { + Py_XDECREF(keyfunc); return NULL; } @@ -1401,18 +1383,14 @@ if (PyErr_Occurred()) goto Fail_it; if (maxval == NULL) { + PyErr_Format(PyExc_ValueError, + "%s() arg is an empty sequence", name); assert(maxitem == NULL); - if (defaultval != NULL) { - Py_INCREF(defaultval); - maxitem = defaultval; - } else { - PyErr_Format(PyExc_ValueError, - "%s() arg is an empty sequence", name); - } } else Py_DECREF(maxval); Py_DECREF(it); + Py_XDECREF(keyfunc); return maxitem; Fail_it_item_and_val: @@ -1423,6 +1401,7 @@ Py_XDECREF(maxval); Py_XDECREF(maxitem); Py_DECREF(it); + Py_XDECREF(keyfunc); return NULL; } @@ -1550,11 +1529,6 @@ return NULL; if (file == NULL || file == Py_None) { file = PySys_GetObject("stdout"); - if (file == NULL) { - PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); - return NULL; - } - /* sys.stdout may be None when FILE* stdout isn't connected */ if (file == Py_None) Py_RETURN_NONE; @@ -1757,7 +1731,6 @@ } s = PyOS_Readline(stdin, stdout, prompt); if (s == NULL) { - PyErr_CheckSignals(); if (!PyErr_Occurred()) PyErr_SetNone(PyExc_KeyboardInterrupt); goto _readline_errors; @@ -1834,10 +1807,10 @@ static PyObject * builtin_round(PyObject *self, PyObject *args, PyObject *kwds) { + static PyObject *round_str = NULL; PyObject *ndigits = NULL; static char *kwlist[] = {"number", "ndigits", 0}; - PyObject *number, *round, *result; - _Py_IDENTIFIER(__round__); + PyObject *number, *round; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round", kwlist, &number, &ndigits)) @@ -1848,21 +1821,24 @@ return NULL; } - round = _PyObject_LookupSpecial(number, &PyId___round__); + if (round_str == NULL) { + round_str = PyUnicode_InternFromString("__round__"); + if (round_str == NULL) + return NULL; + } + + round = _PyType_Lookup(Py_TYPE(number), round_str); if (round == NULL) { - if (!PyErr_Occurred()) - PyErr_Format(PyExc_TypeError, - "type %.100s doesn't define __round__ method", - Py_TYPE(number)->tp_name); + PyErr_Format(PyExc_TypeError, + "type %.100s doesn't define __round__ method", + Py_TYPE(number)->tp_name); return NULL; } if (ndigits == NULL) - result = PyObject_CallFunctionObjArgs(round, NULL); + return PyObject_CallFunction(round, "O", number); else - result = PyObject_CallFunctionObjArgs(round, ndigits, NULL); - Py_DECREF(round); - return result; + return PyObject_CallFunction(round, "OO", number, ndigits); } PyDoc_STRVAR(round_doc, @@ -2030,11 +2006,6 @@ } /* Either overflowed or is not an int. Restore real objects and process normally */ result = PyLong_FromLong(i_result); - if (result == NULL) { - Py_DECREF(item); - Py_DECREF(iter); - return NULL; - } temp = PyNumber_Add(result, item); Py_DECREF(result); Py_DECREF(item); @@ -2123,9 +2094,9 @@ PyDoc_STRVAR(sum_doc, "sum(iterable[, start]) -> value\n\ \n\ -Return the sum of an iterable of numbers (NOT strings) plus the value\n\ +Returns the sum of an iterable of numbers (NOT strings) plus the value\n\ of parameter 'start' (which defaults to 0). When the iterable is\n\ -empty, return start."); +empty, returns start."); static PyObject * diff -r 35c88c53cf64 -r ecc10f0afb76 Python/ceval.c --- a/Python/ceval.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/ceval.c Fri Feb 01 23:12:09 2013 +0100 @@ -142,6 +142,8 @@ #define NAME_ERROR_MSG \ "name '%.200s' is not defined" +#define GLOBAL_NAME_ERROR_MSG \ + "global name '%.200s' is not defined" #define UNBOUNDLOCAL_ERROR_MSG \ "local variable '%.200s' referenced before assignment" #define UNBOUNDFREE_ERROR_MSG \ @@ -362,28 +364,29 @@ drop_gil(tstate); } -/* This function is called from PyOS_AfterFork to destroy all threads which are - * not running in the child process, and clear internal locks which might be - * held by those threads. (This could also be done using pthread_atfork - * mechanism, at least for the pthreads implementation.) */ +/* This function is called from PyOS_AfterFork to ensure that newly + created child processes don't hold locks referring to threads which + are not running in the child process. (This could also be done using + pthread_atfork mechanism, at least for the pthreads implementation.) */ void PyEval_ReInitThreads(void) { _Py_IDENTIFIER(_after_fork); PyObject *threading, *result; - PyThreadState *current_tstate = PyThreadState_GET(); + PyThreadState *tstate = PyThreadState_GET(); if (!gil_created()) return; recreate_gil(); pending_lock = PyThread_allocate_lock(); - take_gil(current_tstate); + take_gil(tstate); main_thread = PyThread_get_thread_ident(); /* Update the threading module with the new state. */ - threading = PyMapping_GetItemString(current_tstate->interp->modules, + tstate = PyThreadState_GET(); + threading = PyMapping_GetItemString(tstate->interp->modules, "threading"); if (threading == NULL) { /* threading not imported */ @@ -396,9 +399,6 @@ else Py_DECREF(result); Py_DECREF(threading); - - /* Destroy all threads except the current one */ - _PyThreadState_DeleteExcept(current_tstate); } #else @@ -1203,13 +1203,6 @@ if (throwflag) /* support for generator.throw() */ goto error; -#ifdef Py_DEBUG - /* PyEval_EvalFrameEx() must not be called with an exception set, - because it may clear it (directly or indirectly) and so the - caller looses its exception */ - assert(!PyErr_Occurred()); -#endif - for (;;) { #ifdef WITH_TSC if (inst1 == 0) { @@ -1230,7 +1223,6 @@ #endif assert(stack_pointer >= f->f_valuestack); /* else underflow */ assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */ - assert(!PyErr_Occurred()); /* Do periodic things. Doing this every time through the loop would add too much overhead, so we do it @@ -1285,7 +1277,8 @@ /* line-by-line tracing support */ if (_Py_TracingPossible && - tstate->c_tracefunc != NULL && !tstate->tracing) { + tstate->c_tracefunc != NULL && !tstate->tracing && + f->f_trace != NULL) { int err; /* see maybe_call_line_trace for expository comments */ @@ -1881,6 +1874,14 @@ goto error; } + TARGET(STORE_LOCALS) { + PyObject *locals = POP(); + PyObject *old = f->f_locals; + Py_XDECREF(old); + f->f_locals = locals; + DISPATCH(); + } + TARGET(RETURN_VALUE) { retval = POP(); why = WHY_RETURN; @@ -2140,7 +2141,7 @@ err = PyDict_DelItem(f->f_globals, name); if (err != 0) { format_exc_check_arg( - PyExc_NameError, NAME_ERROR_MSG, name); + PyExc_NameError, GLOBAL_NAME_ERROR_MSG, name); goto error; } DISPATCH(); @@ -2208,7 +2209,7 @@ if (v == NULL) { if (!PyErr_Occurred()) format_exc_check_arg(PyExc_NameError, - NAME_ERROR_MSG, name); + GLOBAL_NAME_ERROR_MSG, name); goto error; } Py_INCREF(v); @@ -2222,7 +2223,7 @@ if (PyErr_ExceptionMatches(PyExc_KeyError)) format_exc_check_arg( PyExc_NameError, - NAME_ERROR_MSG, name); + GLOBAL_NAME_ERROR_MSG, name); goto error; } } @@ -2262,39 +2263,6 @@ DISPATCH(); } - TARGET(LOAD_CLASSDEREF) { - PyObject *name, *value, *locals = f->f_locals; - Py_ssize_t idx; - assert(locals); - assert(oparg >= PyTuple_GET_SIZE(co->co_cellvars)); - idx = oparg - PyTuple_GET_SIZE(co->co_cellvars); - assert(idx >= 0 && idx < PyTuple_GET_SIZE(co->co_freevars)); - name = PyTuple_GET_ITEM(co->co_freevars, idx); - if (PyDict_CheckExact(locals)) { - value = PyDict_GetItem(locals, name); - Py_XINCREF(value); - } - else { - value = PyObject_GetItem(locals, name); - if (value == NULL && PyErr_Occurred()) { - if (!PyErr_ExceptionMatches(PyExc_KeyError)) - goto error; - PyErr_Clear(); - } - } - if (!value) { - PyObject *cell = freevars[oparg]; - value = PyCell_GET(cell); - if (value == NULL) { - format_exc_unbound(co, oparg); - goto error; - } - Py_INCREF(value); - } - PUSH(value); - DISPATCH(); - } - TARGET(LOAD_DEREF) { PyObject *cell = freevars[oparg]; PyObject *value = PyCell_GET(cell); @@ -2934,6 +2902,23 @@ } /* XXX Maybe this should be a separate opcode? */ + if (posdefaults > 0) { + PyObject *defs = PyTuple_New(posdefaults); + if (defs == NULL) { + Py_DECREF(func); + goto error; + } + while (--posdefaults >= 0) + PyTuple_SET_ITEM(defs, posdefaults, POP()); + if (PyFunction_SetDefaults(func, defs) != 0) { + /* Can't happen unless + PyFunction_SetDefaults changes. */ + Py_DECREF(defs); + Py_DECREF(func); + goto error; + } + Py_DECREF(defs); + } if (kwdefaults > 0) { PyObject *defs = PyDict_New(); if (defs == NULL) { @@ -2961,23 +2946,6 @@ } Py_DECREF(defs); } - if (posdefaults > 0) { - PyObject *defs = PyTuple_New(posdefaults); - if (defs == NULL) { - Py_DECREF(func); - goto error; - } - while (--posdefaults >= 0) - PyTuple_SET_ITEM(defs, posdefaults, POP()); - if (PyFunction_SetDefaults(func, defs) != 0) { - /* Can't happen unless - PyFunction_SetDefaults changes. */ - Py_DECREF(defs); - Py_DECREF(func); - goto error; - } - Py_DECREF(defs); - } PUSH(func); DISPATCH(); } @@ -3034,18 +3002,14 @@ why = WHY_EXCEPTION; /* Double-check exception status. */ -#ifdef NDEBUG if (!PyErr_Occurred()) PyErr_SetString(PyExc_SystemError, "error return without exception set"); -#else - assert(PyErr_Occurred()); -#endif /* Log traceback info. */ PyTraceBack_Here(f); - if (tstate->c_tracefunc != NULL) + if (tstate->c_tracefunc != NULL && f->f_trace != NULL) call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, f); fast_block_end: @@ -3098,10 +3062,7 @@ Python main loop. */ PyErr_NormalizeException( &exc, &val, &tb); - if (tb != NULL) - PyException_SetTraceback(val, tb); - else - PyException_SetTraceback(val, Py_None); + PyException_SetTraceback(val, tb); Py_INCREF(exc); tstate->exc_type = exc; Py_INCREF(val); @@ -3133,8 +3094,6 @@ break; READ_TIMESTAMP(loop1); - assert(!PyErr_Occurred()); - } /* main loop */ assert(why != WHY_YIELD); @@ -3147,9 +3106,6 @@ if (why != WHY_RETURN) retval = NULL; - assert((retval != NULL && !PyErr_Occurred()) - || (retval == NULL && PyErr_Occurred())); - fast_yield: if (co->co_flags & CO_GENERATOR && (why == WHY_YIELD || why == WHY_RETURN)) { /* The purpose of this block is to put aside the generator's exception @@ -3172,7 +3128,7 @@ } if (tstate->use_tracing) { - if (tstate->c_tracefunc) { + if (tstate->c_tracefunc && f->f_trace != NULL) { if (why == WHY_RETURN || why == WHY_YIELD) { if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, f, @@ -3461,9 +3417,7 @@ keyword); goto fail; } - if (PyDict_SetItem(kwdict, keyword, value) == -1) { - goto fail; - } + PyDict_SetItem(kwdict, keyword, value); continue; kw_found: if (GETLOCAL(j) != NULL) { @@ -3533,14 +3487,10 @@ int arg; /* Possibly account for the cell variable being an argument. */ if (co->co_cell2arg != NULL && - (arg = co->co_cell2arg[i]) != CO_CELL_NOT_AN_ARG) { + (arg = co->co_cell2arg[i]) != CO_CELL_NOT_AN_ARG) c = PyCell_New(GETLOCAL(arg)); - /* Clear the local copy. */ - SETLOCAL(arg, NULL); - } - else { + else c = PyCell_New(NULL); - } if (c == NULL) goto fail; SETLOCAL(co->co_nlocals + i, c); @@ -3839,19 +3789,13 @@ static void call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f) { - PyObject *type, *value, *traceback, *orig_traceback, *arg; + PyObject *type, *value, *traceback, *arg; int err; PyErr_Fetch(&type, &value, &traceback); if (value == NULL) { value = Py_None; Py_INCREF(value); } - PyErr_NormalizeException(&type, &value, &traceback); - orig_traceback = traceback; - if (traceback == NULL) { - Py_INCREF(Py_None); - traceback = Py_None; - } arg = PyTuple_Pack(3, type, value, traceback); if (arg == NULL) { PyErr_Restore(type, value, traceback); @@ -3860,11 +3804,11 @@ err = call_trace(func, self, f, PyTrace_EXCEPTION, arg); Py_DECREF(arg); if (err == 0) - PyErr_Restore(type, value, orig_traceback); + PyErr_Restore(type, value, traceback); else { Py_XDECREF(type); Py_XDECREF(value); - Py_XDECREF(orig_traceback); + Py_XDECREF(traceback); } } @@ -4059,13 +4003,6 @@ { PyObject *result; -#ifdef Py_DEBUG - /* PyEval_CallObjectWithKeywords() must not be called with an exception - set, because it may clear it (directly or indirectly) - and so the caller looses its exception */ - assert(!PyErr_Occurred()); -#endif - if (arg == NULL) { arg = PyTuple_New(0); if (arg == NULL) @@ -4088,9 +4025,6 @@ result = PyObject_Call(func, arg, kw); Py_DECREF(arg); - - assert((result != NULL && !PyErr_Occurred()) - || (result == NULL && PyErr_Occurred())); return result; } @@ -4208,15 +4142,10 @@ else { PyObject *callargs; callargs = load_args(pp_stack, na); - if (callargs != NULL) { - READ_TIMESTAMP(*pintr0); - C_TRACE(x, PyCFunction_Call(func,callargs,NULL)); - READ_TIMESTAMP(*pintr1); - Py_XDECREF(callargs); - } - else { - x = NULL; - } + READ_TIMESTAMP(*pintr0); + C_TRACE(x, PyCFunction_Call(func,callargs,NULL)); + READ_TIMESTAMP(*pintr1); + Py_XDECREF(callargs); } } else { if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { @@ -4241,8 +4170,6 @@ READ_TIMESTAMP(*pintr1); Py_DECREF(func); } - assert((x != NULL && !PyErr_Occurred()) - || (x == NULL && PyErr_Occurred())); /* Clear the stack of the function object. Also removes the arguments in case they weren't consumed already @@ -4253,9 +4180,6 @@ Py_DECREF(w); PCALL(PCALL_POP); } - - assert((x != NULL && !PyErr_Occurred()) - || (x == NULL && PyErr_Occurred())); return x; } @@ -4539,8 +4463,6 @@ Py_XDECREF(callargs); Py_XDECREF(kwdict); Py_XDECREF(stararg); - assert((result != NULL && !PyErr_Occurred()) - || (result == NULL && PyErr_Occurred())); return result; } @@ -4637,7 +4559,7 @@ x = PyObject_GetAttr(v, name); if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Format(PyExc_ImportError, "cannot import name %R", name); + PyErr_Format(PyExc_ImportError, "cannot import name %S", name); } return x; } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/codecs.c --- a/Python/codecs.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/codecs.c Fri Feb 01 23:12:09 2013 +0100 @@ -65,7 +65,7 @@ p = PyMem_Malloc(len + 1); if (p == NULL) - return PyErr_NoMemory(); + return NULL; for (i = 0; i < len; i++) { register char ch = string[i]; if (ch == ' ') diff -r 35c88c53cf64 -r ecc10f0afb76 Python/compile.c --- a/Python/compile.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/compile.c Fri Feb 01 23:12:09 2013 +0100 @@ -248,11 +248,8 @@ } plen -= ipriv; - if (plen + nlen >= PY_SSIZE_T_MAX - 1) { - PyErr_SetString(PyExc_OverflowError, - "private identifier too large to be mangled"); - return NULL; - } + assert(1 <= PY_SSIZE_T_MAX - nlen); + assert(1 + nlen <= PY_SSIZE_T_MAX - plen); maxchar = PyUnicode_MAX_CHAR_VALUE(ident); if (PyUnicode_MAX_CHAR_VALUE(privateobj) > maxchar) @@ -535,37 +532,6 @@ compiler_unit_free(u); return 0; } - if (u->u_ste->ste_needs_class_closure) { - /* Cook up a implicit __class__ cell. */ - _Py_IDENTIFIER(__class__); - PyObject *tuple, *name, *zero; - int res; - assert(u->u_scope_type == COMPILER_SCOPE_CLASS); - assert(PyDict_Size(u->u_cellvars) == 0); - name = _PyUnicode_FromId(&PyId___class__); - if (!name) { - compiler_unit_free(u); - return 0; - } - tuple = PyTuple_Pack(2, name, Py_TYPE(name)); - if (!tuple) { - compiler_unit_free(u); - return 0; - } - zero = PyLong_FromLong(0); - if (!zero) { - Py_DECREF(tuple); - compiler_unit_free(u); - return 0; - } - res = PyDict_SetItem(u->u_cellvars, tuple, zero); - Py_DECREF(tuple); - Py_DECREF(zero); - if (res < 0) { - compiler_unit_free(u); - return 0; - } - } u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE, DEF_FREE_CLASS, PyDict_Size(u->u_cellvars)); @@ -893,6 +859,8 @@ return 7; case WITH_CLEANUP: return -1; /* XXX Sometimes more */ + case STORE_LOCALS: + return -1; case RETURN_VALUE: return -1; case IMPORT_STAR: @@ -999,7 +967,6 @@ case LOAD_CLOSURE: return 1; case LOAD_DEREF: - case LOAD_CLASSDEREF: return 1; case STORE_DEREF: return -1; @@ -1360,11 +1327,7 @@ static int get_ref_type(struct compiler *c, PyObject *name) { - int scope; - if (c->u->u_scope_type == COMPILER_SCOPE_CLASS && - !PyUnicode_CompareWithASCIIString(name, "__class__")) - return CELL; - scope = PyST_GetScope(c->u->u_ste, name); + int scope = PyST_GetScope(c->u->u_ste, name); if (scope == 0) { char buf[350]; PyOS_snprintf(buf, sizeof(buf), @@ -1535,15 +1498,15 @@ if (compiler_visit_argannotations(c, args->args, names)) goto error; - if (args->vararg && args->vararg->annotation && - compiler_visit_argannotation(c, args->vararg->arg, - args->vararg->annotation, names)) + if (args->varargannotation && + compiler_visit_argannotation(c, args->vararg, + args->varargannotation, names)) goto error; if (compiler_visit_argannotations(c, args->kwonlyargs, names)) goto error; - if (args->kwarg && args->kwarg->annotation && - compiler_visit_argannotation(c, args->kwarg->arg, - args->kwarg->annotation, names)) + if (args->kwargannotation && + compiler_visit_argannotation(c, args->kwarg, + args->kwargannotation, names)) goto error; if (!return_str) { @@ -1602,8 +1565,6 @@ if (!compiler_decorators(c, decos)) return 0; - if (args->defaults) - VISIT_SEQ(c, expr, args->defaults); if (args->kwonlyargs) { int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs, args->kw_defaults); @@ -1611,6 +1572,8 @@ return 0; kw_default_count = res; } + if (args->defaults) + VISIT_SEQ(c, expr, args->defaults); num_annotations = compiler_visit_annotations(c, args, returns); if (num_annotations < 0) return 0; @@ -1695,6 +1658,12 @@ Py_INCREF(s->v.ClassDef.name); Py_XDECREF(c->u->u_private); c->u->u_private = s->v.ClassDef.name; + /* force it to have one mandatory argument */ + c->u->u_argcount = 1; + /* load the first argument (__locals__) ... */ + ADDOP_I(c, LOAD_FAST, 0); + /* ... and store it into f_locals */ + ADDOP_IN_SCOPE(c, STORE_LOCALS); /* load (global) __name__ ... */ str = PyUnicode_InternFromString("__name__"); if (!str || !compiler_nameop(c, str, Load)) { @@ -1731,24 +1700,24 @@ compiler_exit_scope(c); return 0; } - if (c->u->u_ste->ste_needs_class_closure) { - /* return the (empty) __class__ cell */ - str = PyUnicode_InternFromString("__class__"); - if (str == NULL) { - compiler_exit_scope(c); - return 0; - } - i = compiler_lookup_arg(c->u->u_cellvars, str); - Py_DECREF(str); - assert(i == 0); + /* return the (empty) __class__ cell */ + str = PyUnicode_InternFromString("__class__"); + if (str == NULL) { + compiler_exit_scope(c); + return 0; + } + i = compiler_lookup_arg(c->u->u_cellvars, str); + Py_DECREF(str); + if (i == -1) { + /* This happens when nobody references the cell */ + PyErr_Clear(); + /* Return None */ + ADDOP_O(c, LOAD_CONST, Py_None, consts); + } + else { /* Return the cell where to store __class__ */ ADDOP_I(c, LOAD_CLOSURE, i); } - else { - assert(PyDict_Size(c->u->u_cellvars) == 0); - /* This happens when nobody references the cell. Return None. */ - ADDOP_O(c, LOAD_CONST, Py_None, consts); - } ADDOP_IN_SCOPE(c, RETURN_VALUE); /* create the code object */ co = assemble(c, 1); @@ -1825,14 +1794,14 @@ return 0; } - if (args->defaults) - VISIT_SEQ(c, expr, args->defaults); if (args->kwonlyargs) { int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs, args->kw_defaults); if (res < 0) return 0; kw_default_count = res; } + if (args->defaults) + VISIT_SEQ(c, expr, args->defaults); if (!compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION, (void *)e, e->lineno)) return 0; @@ -2174,13 +2143,13 @@ /* try: - # body + # body except type as name: - try: - # body - finally: - name = None - del name + try: + # body + finally: + name = None + del name */ /* second try: */ @@ -2316,11 +2285,8 @@ identifier tmp = alias->name; Py_ssize_t dot = PyUnicode_FindChar( alias->name, '.', 0, PyUnicode_GET_LENGTH(alias->name), 1); - if (dot != -1) { + if (dot != -1) tmp = PyUnicode_Substring(alias->name, 0, dot); - if (tmp == NULL) - return 0; - } r = compiler_nameop(c, tmp, Store); if (dot != -1) { Py_DECREF(tmp); @@ -2708,9 +2674,7 @@ switch (optype) { case OP_DEREF: switch (ctx) { - case Load: - op = (c->u->u_ste->ste_type == ClassBlock) ? LOAD_CLASSDEREF : LOAD_DEREF; - break; + case Load: op = LOAD_DEREF; break; case Store: op = STORE_DEREF; break; case AugLoad: case AugStore: @@ -4106,8 +4070,9 @@ { PySTEntryObject *ste = c->u->u_ste; int flags = 0, n; + if (ste->ste_type != ModuleBlock) + flags |= CO_NEWLOCALS; if (ste->ste_type == FunctionBlock) { - flags |= CO_NEWLOCALS; if (!ste->ste_unoptimized) flags |= CO_OPTIMIZED; if (ste->ste_nested) diff -r 35c88c53cf64 -r ecc10f0afb76 Python/condvar.h --- a/Python/condvar.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/condvar.h Fri Feb 01 23:12:09 2013 +0100 @@ -163,9 +163,10 @@ Generic emulations of the pthread_cond_* API using earlier Win32 functions can be found on the Web. - The following read can be give background information to these issues, - but the implementations are all broken in some way. + The following read can be edificating (or not): http://www.cse.wustl.edu/~schmidt/win32-cv-1.html + + See also */ typedef CRITICAL_SECTION PyMUTEX_T; @@ -241,7 +242,7 @@ * but we are safe because we are using a semaphore wich has an internal * count. */ - wait = WaitForSingleObjectEx(cv->sem, ms, FALSE); + wait = WaitForSingleObject(cv->sem, ms); PyMUTEX_LOCK(cs); if (wait != WAIT_OBJECT_0) --cv->waiting; @@ -296,10 +297,9 @@ Py_LOCAL_INLINE(int) PyCOND_BROADCAST(PyCOND_T *cv) { - int waiting = cv->waiting; - if (waiting > 0) { - cv->waiting = 0; - return ReleaseSemaphore(cv->sem, waiting, NULL) ? 0 : -1; + if (cv->waiting > 0) { + return ReleaseSemaphore(cv->sem, cv->waiting, NULL) ? 0 : -1; + cv->waiting = 0; } return 0; } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/dynload_aix.c --- a/Python/dynload_aix.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/dynload_aix.c Fri Feb 01 23:12:09 2013 +0100 @@ -4,6 +4,7 @@ #include "Python.h" #include "importdl.h" +#include /* for isdigit() */ #include /* for global errno */ #include /* for strerror() */ #include /* for malloc(), free() */ @@ -140,7 +141,7 @@ if (nerr == load_errtab[j].errNo && load_errtab[j].errstr) ERRBUF_APPEND(load_errtab[j].errstr); } - while (Py_ISDIGIT(Py_CHARMASK(*message[i]))) message[i]++ ; + while (isdigit(Py_CHARMASK(*message[i]))) message[i]++ ; ERRBUF_APPEND(message[i]); ERRBUF_APPEND("\n"); } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/dynload_shlib.c --- a/Python/dynload_shlib.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/dynload_shlib.c Fri Feb 01 23:12:09 2013 +0100 @@ -81,10 +81,7 @@ if (fp != NULL) { int i; struct stat statb; - if (fstat(fileno(fp), &statb) == -1) { - PyErr_SetFromErrno(PyExc_IOError); - return NULL; - } + fstat(fileno(fp), &statb); for (i = 0; i < nhandles; i++) { if (statb.st_dev == handles[i].dev && statb.st_ino == handles[i].ino) { diff -r 35c88c53cf64 -r ecc10f0afb76 Python/dynload_win.c --- a/Python/dynload_win.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/dynload_win.c Fri Feb 01 23:12:09 2013 +0100 @@ -235,7 +235,7 @@ SUBLANG_DEFAULT), /* Default language */ theInfo, /* the buffer */ - sizeof(theInfo) / sizeof(wchar_t), /* size in wchars */ + sizeof(theInfo), /* the buffer size */ NULL); /* no additional format args. */ /* Problem: could not get the error message. @@ -262,9 +262,8 @@ theLength)); } if (message != NULL) { - PyObject *shortname_obj = PyUnicode_FromString(shortname); - PyErr_SetImportError(message, shortname_obj, pathname); - Py_XDECREF(shortname_obj); + PyErr_SetImportError(message, PyUnicode_FromString(shortname), + pathname); Py_DECREF(message); } return NULL; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/errors.c --- a/Python/errors.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/errors.c Fri Feb 01 23:12:09 2013 +0100 @@ -2,6 +2,7 @@ /* Error handling */ #include "Python.h" +#include #ifndef __STDC__ #ifndef MS_WINDOWS @@ -71,11 +72,6 @@ if (value == NULL || !PyExceptionInstance_Check(value)) { /* We must normalize the value right now */ PyObject *args, *fixed_value; -#ifdef Py_DEBUG - /* in debug mode, PyEval_EvalFrameEx() fails with an assertion - error if an exception is set when it is called */ - PyErr_Clear(); -#endif if (value == NULL || value == Py_None) args = PyTuple_New(0); else if (PyTuple_Check(value)) { @@ -232,21 +228,12 @@ value will be an instance. */ if (PyExceptionClass_Check(type)) { - int is_subclass; - if (inclass) { - is_subclass = PyObject_IsSubclass(inclass, type); - if (is_subclass < 0) - goto finally; - } - else - is_subclass = 0; - /* if the value was not an instance, or is not an instance whose class is (or is derived from) type, then use the value as an argument to instantiation of the type class. */ - if (!inclass || !is_subclass) { + if (!inclass || !PyObject_IsSubclass(inclass, type)) { PyObject *args, *res; if (value == Py_None) @@ -380,12 +367,6 @@ PyObject * PyErr_NoMemory(void) { - if (Py_TYPE(PyExc_MemoryError) == NULL) { - /* PyErr_NoMemory() has been called before PyExc_MemoryError has been - initialized by _PyExc_Init() */ - Py_FatalError("Out of memory and PyExc_MemoryError is not " - "initialized yet"); - } PyErr_SetNone(PyExc_MemoryError); return NULL; } @@ -666,11 +647,8 @@ Py_INCREF(msg); PyTuple_SET_ITEM(args, 0, msg); - - if (PyDict_SetItemString(kwargs, "name", name) < 0) - return NULL; - if (PyDict_SetItemString(kwargs, "path", path) < 0) - return NULL; + PyDict_SetItemString(kwargs, "name", name); + PyDict_SetItemString(kwargs, "path", path); error = PyObject_Call(PyExc_ImportError, args, kwargs); if (error != NULL) { @@ -698,7 +676,6 @@ void PyErr_BadInternalCall(void) { - assert(0 && "bad argument to internal function"); PyErr_Format(PyExc_SystemError, "bad argument to internal function"); } @@ -718,12 +695,6 @@ va_start(vargs); #endif -#ifdef Py_DEBUG - /* in debug mode, PyEval_EvalFrameEx() fails with an assertion error - if an exception is set when it is called */ - PyErr_Clear(); -#endif - string = PyUnicode_FromFormatV(format, vargs); PyErr_SetObject(exception, string); Py_XDECREF(string); @@ -971,13 +942,17 @@ PyObject * PyErr_ProgramText(const char *filename, int lineno) { + int fd; FILE *fp; int i; char linebuf[1000]; if (filename == NULL || *filename == '\0' || lineno <= 0) return NULL; - fp = fopen(filename, "r" PY_STDIOTEXTMODE); + fd = _Py_open(filename, O_RDONLY); + if (fd < 0) + return NULL; + fp = fdopen(fd, "r" PY_STDIOTEXTMODE); if (fp == NULL) return NULL; for (i = 0; i < lineno; i++) { diff -r 35c88c53cf64 -r ecc10f0afb76 Python/fileutils.c --- a/Python/fileutils.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/fileutils.c Fri Feb 01 23:12:09 2013 +0100 @@ -9,20 +9,41 @@ #include #endif +#if defined(HAVE_SYS_IOCTL_H) +# include +#endif + +#ifdef HAVE_FCNTL_H +#include +#endif /* HAVE_FCNTL_H */ + #ifdef __APPLE__ extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); #endif +int Py_DefaultCloexec = 0; + +#ifdef O_CLOEXEC +/* Does open() supports the O_CLOEXEC flag? Possible values: + + -1: unknown + 0: open() ignores O_CLOEXEC flag, ex: Linux kernel older than 2.6.23 + 1: open() supports O_CLOEXEC flag, close-on-exec is set + + The flag is used by open_cloexec(), io.FileIO and os.open() */ +int _Py_open_cloexec_works = -1; +#endif + PyObject * _Py_device_encoding(int fd) { -#if defined(MS_WINDOWS) +#if defined(MS_WINDOWS) || defined(MS_WIN64) UINT cp; #endif if (!_PyVerify_fd(fd) || !isatty(fd)) { Py_RETURN_NONE; } -#if defined(MS_WINDOWS) +#if defined(MS_WINDOWS) || defined(MS_WIN64) if (fd == 0) cp = GetConsoleCP(); else if (fd == 1 || fd == 2) @@ -201,7 +222,7 @@ unsigned char *in; wchar_t *out; - res = PyMem_RawMalloc((strlen(arg)+1)*sizeof(wchar_t)); + res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t)); if (!res) return NULL; @@ -229,7 +250,7 @@ Use _Py_wchar2char() to encode the character string back to a byte string. Return a pointer to a newly allocated wide character string (use - PyMem_RawFree() to free the memory) and write the number of written wide + PyMem_Free() to free the memory) and write the number of written wide characters excluding the null character into *size if size is not NULL, or NULL on error (decoding or memory allocation error). If size is not NULL, *size is set to (size_t)-1 on memory error and (size_t)-2 on decoding @@ -254,9 +275,9 @@ wchar_t *res; size_t argsize; size_t count; -#ifdef HAVE_MBRTOWC unsigned char *in; wchar_t *out; +#ifdef HAVE_MBRTOWC mbstate_t mbs; #endif @@ -283,7 +304,7 @@ argsize = mbstowcs(NULL, arg, 0); #endif if (argsize != (size_t)-1) { - res = (wchar_t *)PyMem_RawMalloc((argsize+1)*sizeof(wchar_t)); + res = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t)); if (!res) goto oom; count = mbstowcs(res, arg, argsize+1); @@ -300,7 +321,7 @@ return res; } } - PyMem_RawFree(res); + PyMem_Free(res); } /* Conversion failed. Fall back to escaping with surrogateescape. */ #ifdef HAVE_MBRTOWC @@ -309,7 +330,7 @@ /* Overallocate; as multi-byte characters are in the argument, the actual output could use less memory. */ argsize = strlen(arg) + 1; - res = (wchar_t*)PyMem_RawMalloc(argsize*sizeof(wchar_t)); + res = (wchar_t*)PyMem_Malloc(argsize*sizeof(wchar_t)); if (!res) goto oom; in = (unsigned char*)arg; @@ -325,7 +346,7 @@ since we provide everything that we have - unless there is a bug in the C library, or I misunderstood how mbrtowc works. */ - PyMem_RawFree(res); + PyMem_Free(res); if (size != NULL) *size = (size_t)-2; return NULL; @@ -547,14 +568,329 @@ #endif +#ifdef MS_WINDOWS +/* _get_osfhandle(fd) wrapper. + * + * On success, return the handle of the file descriptor. + * On error, return INVALID_HANDLE_VALUE and: + * + * - raise an exception if raise is nonzero, + * - set errno to EBADF and set the Windows last error to + * ERROR_INVALID_HANDLE otherwise. + */ +Py_intptr_t +_Py_get_osfhandle(int fd, int raise) +{ + Py_intptr_t handle; + + if (!_PyVerify_fd(fd)) { + if (raise) + PyErr_SetFromWindowsErr(ERROR_INVALID_HANDLE); + else { + errno = EBADF; + SetLastError(ERROR_INVALID_HANDLE); + } + return (Py_intptr_t)INVALID_HANDLE_VALUE; + } + + handle = _get_osfhandle(fd); + if (handle == (Py_intptr_t)INVALID_HANDLE_VALUE) { + /* errno is EBADF */ + if (raise) + PyErr_SetFromErrno(PyExc_OSError); + else + SetLastError(ERROR_INVALID_HANDLE); + return (Py_intptr_t)INVALID_HANDLE_VALUE; + } + return handle; +} + +/* Wrapper to _open_osfhandle(). + * + * On success, return the file descriptor of the handle. + * On error, return -1 and: raise an exception if raise is + * nonzero, set errno otherwise. + */ +int +_Py_open_osfhandle(Py_intptr_t handle, int flags, int raise) +{ + int fd; + errno = 0; + fd = _open_osfhandle(handle, flags); + if (fd == -1) { + if (errno == 0) { + /* bcc32 never set EMFILE */ + errno = EMFILE; + } + if (raise) + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return fd; +} + +/* Get the close-on-exec flag of the specified handle. + Return 1 if it is set, 0 if is not set, + raise an exception and return -1 on error. */ +int +_Py_get_cloexec_handle(Py_intptr_t handle) +{ + BOOL success; + DWORD flags; + + success = GetHandleInformation(handle, &flags); + if (!success) { + PyErr_SetFromWindowsErr(0); + return -1; + } + + return !(flags & HANDLE_FLAG_INHERIT); +} +#endif /* MS_WINDOWS */ + +/* Get the close-on-exec flag of the specified file descriptor. + Return 1 if it is set, 0 if is not set, + raise an exception and return -1 on error. */ +int +_Py_get_cloexec(int fd) +{ +#ifdef MS_WINDOWS + HANDLE handle; + + handle = (HANDLE)_Py_get_osfhandle(fd, 1); + if (handle == INVALID_HANDLE_VALUE) + return -1; + + return _Py_get_cloexec_handle(handle); +#else + int flags; + + flags = fcntl(fd, F_GETFD, 0); + if (flags == -1) { + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return (flags & FD_CLOEXEC); +#endif +} + +static int +set_cloexec(int fd, int cloexec, int raise) +{ +#ifdef MS_WINDOWS + HANDLE handle; + DWORD flags; + BOOL success; +#elif defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX) + int request; + int err; +#elif defined(HAVE_FCNTL_H) + int flags; + int res; +#endif + +#ifdef MS_WINDOWS + handle = (HANDLE)_Py_get_osfhandle(fd, raise); + if (handle == INVALID_HANDLE_VALUE) + return -1; + + if (cloexec) + flags = 0; + else + flags = HANDLE_FLAG_INHERIT; + success = SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags); + if (!success) { + if (raise) + PyErr_SetFromWindowsErr(0); + return -1; + } + return 0; +#elif defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX) + if (cloexec) + request = FIOCLEX; + else + request = FIONCLEX; + err = ioctl(fd, request); + if (err) { + if (raise) + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return 0; +#elif defined(HAVE_FCNTL_H) + flags = fcntl(fd, F_GETFD); + if (flags < 0) { + if (raise) + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + + if (cloexec) + flags |= FD_CLOEXEC; + else + flags &= ~FD_CLOEXEC; + res = fcntl(fd, F_SETFD, flags); + if (res < 0) { + if (raise) + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return 0; +#else + if (raise) + PyErr_SetString(PyExc_NotImplementedError, + "close-on-exec flag is not supported on your platform"); + return -1; +#endif +} + +/* Set or clear close-on-exec flag of the specified file descriptor. + On success: return 0. On error: raise an exception and return -1. */ +int +_Py_set_cloexec(int fd, int cloexec, int *atomic_flag_works) +{ + if (atomic_flag_works != NULL) { + if (*atomic_flag_works == -1) { + int works = _Py_get_cloexec(fd); + if (works == -1) + return -1; + *atomic_flag_works = works; + } + + if (*atomic_flag_works) + return 0; + } + + return set_cloexec(fd, cloexec, 1); +} + +#ifdef MS_WINDOWS +/* Set or clear close-on-exec flag of the specified handle. + On success: return 0. On error: return -1, and raise an exception if raise + is nonzero. */ +int +_Py_set_cloexec_handle(Py_intptr_t handle, int cloexec, + int *atomic_flag_works) +{ + DWORD mask, flags; + + if (atomic_flag_works != NULL) { + if (*atomic_flag_works == -1) { + int works = _Py_get_cloexec_handle(handle); + if (works == -1) + return -1; + *atomic_flag_works = works; + } + + if (*atomic_flag_works) + return 0; + } + + if (cloexec) + flags = 0; + else + flags = HANDLE_FLAG_INHERIT; + + success = SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags); + if (!success) { + PyErr_SetFromWindowsErr(0); + return -1; + } + return 0; +} +#endif + +/* Try to set or clear the close-on-exec flag of the specified file descriptor. + If setting the close-on-exec flag failed, ignore the error. */ +void +_Py_try_set_cloexec(int fd, int cloexec) +{ + (void)set_cloexec(fd, cloexec, 0); +} + +/* Try to set the default value of the close-on-exec flag of the specified file + descriptor. If setting the close-on-exec flag failed, ignore the error. + + The function considers that the close-on-exec flag is not set on the + specified file descriptor, and so does nothing if the default is False. */ +void +_Py_try_set_default_cloexec(int fd) +{ + if (!Py_DefaultCloexec) { + /* close-on-exec flag is cleared by default */ + return; + } + (void)set_cloexec(fd, 1, 0); +} + +static int +open_cloexec(const char *pathname, int flags, int cloexec) +{ + int fd; + + if (!cloexec) + return open(pathname, flags); + +#ifdef MS_WINDOWS + flags |= O_NOINHERIT; +#elif defined(O_CLOEXEC) + flags |= O_CLOEXEC; +#endif + fd = open(pathname, flags); + if (fd < 0) + return fd; + +#if defined(O_CLOEXEC) && !defined(MS_WINDOWS) + if (_Py_open_cloexec_works == -1) { + int flags = fcntl(fd, F_GETFD, 0); + if (flags != -1) + _Py_open_cloexec_works = (flags & FD_CLOEXEC); + else + _Py_open_cloexec_works = 0; + } + + if (!_Py_open_cloexec_works) { + /* Linux kernel older than 2.6.23 ignores O_CLOEXEC flag */ + (void)set_cloexec(fd, 1, 0); + } +#elif !defined(MS_WINDOWS) + (void)set_cloexec(fd, 1, 0); +#endif + return fd; +} + +/* Open a file with the specified flags (wrapper to open() function). + + Try to apply the default value of the close-on-exec flag on the newly + created file descriptor. If setting the close-on-exec flag failed, ignore + the error. */ +int +_Py_open(const char *pathname, int flags) +{ + return open_cloexec(pathname, flags, Py_DefaultCloexec); +} + +/* Open a file with the specified flags (wrapper to open() function). + + Try to set close-on-exec flag of the newly created file descriptor. + If setting the close-on-exec flag failed, ignore the error. */ +int +_Py_open_cloexec(const char *pathname, int flags) +{ + return open_cloexec(pathname, flags, 1); +} + /* Open a file. Use _wfopen() on Windows, encode the path to the locale - encoding and use fopen() otherwise. */ + encoding and use fopen() otherwise. + Try to apply the default value of the close-on-exec flag on the newly + created file descriptor. If setting the close-on-exec flag failed, ignore + the error. */ FILE * _Py_wfopen(const wchar_t *path, const wchar_t *mode) { + FILE *f; #ifndef MS_WINDOWS - FILE *f; char *cpath; char cmode[10]; size_t r; @@ -570,19 +906,28 @@ PyMem_Free(cpath); return f; #else - return _wfopen(path, mode); + f = _wfopen(path, mode); #endif + if (f == NULL) + return NULL; + if (Py_DefaultCloexec) + (void)set_cloexec(fileno(f), 1, 0); + return f; } -/* Call _wfopen() on Windows, or encode the path to the filesystem encoding and - call fopen() otherwise. +/* Open a file. Call _wfopen() on Windows, or encode the path to the filesystem + encoding and call fopen() otherwise. + + Try to apply the default value of the close-on-exec flag on the newly + created file descriptor. If setting the close-on-exec flag failed, ignore + the error. Return the new file object on success, or NULL if the file cannot be open or - (if PyErr_Occurred()) on unicode error */ - + (if PyErr_Occurred()) on unicode error. */ FILE* _Py_fopen(PyObject *path, const char *mode) { + FILE *f; #ifdef MS_WINDOWS wchar_t *wpath; wchar_t wmode[10]; @@ -602,16 +947,19 @@ if (usize == 0) return NULL; - return _wfopen(wpath, wmode); + f = _wfopen(wpath, wmode); #else - FILE *f; PyObject *bytes; if (!PyUnicode_FSConverter(path, &bytes)) return NULL; f = fopen(PyBytes_AS_STRING(bytes), mode); Py_DECREF(bytes); +#endif + if (f == NULL) + return NULL; + if (Py_DefaultCloexec) + (void)set_cloexec(fileno(f), 1, 0); return f; -#endif } #ifdef HAVE_READLINK @@ -648,12 +996,12 @@ return -1; } if (bufsiz <= r1) { - PyMem_RawFree(wbuf); + PyMem_Free(wbuf); errno = EINVAL; return -1; } wcsncpy(buf, wbuf, bufsiz); - PyMem_RawFree(wbuf); + PyMem_Free(wbuf); return (int)r1; } #endif @@ -689,12 +1037,12 @@ return NULL; } if (resolved_path_size <= r) { - PyMem_RawFree(wresolved_path); + PyMem_Free(wresolved_path); errno = EINVAL; return NULL; } wcsncpy(resolved_path, wresolved_path, resolved_path_size); - PyMem_RawFree(wresolved_path); + PyMem_Free(wresolved_path); return resolved_path; } #endif @@ -707,8 +1055,7 @@ _Py_wgetcwd(wchar_t *buf, size_t size) { #ifdef MS_WINDOWS - int isize = (int)Py_MIN(size, INT_MAX); - return _wgetcwd(buf, isize); + return _wgetcwd(buf, size); #else char fname[PATH_MAX]; wchar_t *wname; @@ -720,12 +1067,35 @@ if (wname == NULL) return NULL; if (size <= len) { - PyMem_RawFree(wname); + PyMem_Free(wname); return NULL; } wcsncpy(buf, wname, size); - PyMem_RawFree(wname); + PyMem_Free(wname); return buf; #endif } +/* Converter for PyArg_ParseTuple() to parse the 'cloexec' parameter: + + - if the argument is None, return sys.getdefaultcloexec() + - otherwise, return bool(argument) + + Return 0 on error, 1 on success. +*/ +int +_Py_cloexec_converter(PyObject* arg, void* addr) +{ + int cloexec; + if (arg == Py_None) { + cloexec = Py_DefaultCloexec; + } + else { + cloexec = PyObject_IsTrue(arg); + if (cloexec == -1) + return 0; + } + *(int *)addr = cloexec; + return 1; +} + diff -r 35c88c53cf64 -r ecc10f0afb76 Python/formatter_unicode.c --- a/Python/formatter_unicode.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/formatter_unicode.c Fri Feb 01 23:12:09 2013 +0100 @@ -315,7 +315,7 @@ /* Do the padding, and return a pointer to where the caller-supplied content goes. */ -static int +static Py_ssize_t fill_padding(_PyUnicodeWriter *writer, Py_ssize_t nchars, Py_UCS4 fill_char, Py_ssize_t n_lpadding, @@ -401,7 +401,7 @@ { Py_ssize_t remainder; - while (poskind; + const enum PyUnicode_Kind kind = writer->kind; const void *data = writer->data; Py_ssize_t r; @@ -771,13 +771,9 @@ calc_padding(len, format->width, format->align, &lpad, &rpad, &total); - maxchar = writer->maxchar; + maxchar = _PyUnicode_FindMaxChar(value, 0, len); if (lpad != 0 || rpad != 0) maxchar = Py_MAX(maxchar, format->fill_char); - if (PyUnicode_MAX_CHAR_VALUE(value) > maxchar) { - Py_UCS4 valmaxchar = _PyUnicode_FindMaxChar(value, 0, len); - maxchar = Py_MAX(maxchar, valmaxchar); - } /* allocate the resulting string */ if (_PyUnicodeWriter_Prepare(writer, total, maxchar) == -1) @@ -982,7 +978,8 @@ Py_ssize_t n_total; int has_decimal; double val; - int precision, default_precision = 6; + Py_ssize_t precision = format->precision; + Py_ssize_t default_precision = 6; Py_UCS4 type = format->type; int add_pct = 0; Py_ssize_t index; @@ -998,12 +995,6 @@ from a hard-code pseudo-locale */ LocaleInfo locale = STATIC_LOCALE_INFO_INIT; - if (format->precision > INT_MAX) { - PyErr_SetString(PyExc_ValueError, "precision too big"); - goto done; - } - precision = (int)format->precision; - if (format->alternate) flags |= Py_DTSF_ALT; @@ -1137,7 +1128,8 @@ Py_ssize_t n_im_total; int re_has_decimal; int im_has_decimal; - int precision, default_precision = 6; + Py_ssize_t precision = format->precision; + Py_ssize_t default_precision = 6; Py_UCS4 type = format->type; Py_ssize_t i_re; Py_ssize_t i_im; @@ -1164,12 +1156,6 @@ from a hard-code pseudo-locale */ LocaleInfo locale = STATIC_LOCALE_INFO_INIT; - if (format->precision > INT_MAX) { - PyErr_SetString(PyExc_ValueError, "precision too big"); - goto done; - } - precision = (int)format->precision; - /* Zero padding is not allowed. */ if (format->fill_char == '0') { PyErr_SetString(PyExc_ValueError, diff -r 35c88c53cf64 -r ecc10f0afb76 Python/frozen.c --- a/Python/frozen.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/frozen.c Fri Feb 01 23:12:09 2013 +0100 @@ -28,7 +28,7 @@ #define SIZE (int)sizeof(M___hello__) -static const struct _frozen _PyImport_FrozenModules[] = { +static struct _frozen _PyImport_FrozenModules[] = { /* importlib */ {"_frozen_importlib", _Py_M__importlib, (int)sizeof(_Py_M__importlib)}, /* Test module */ @@ -42,4 +42,4 @@ /* Embedding apps may change this pointer to point to their favorite collection of frozen modules: */ -const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; +struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/frozenmain.c --- a/Python/frozenmain.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/frozenmain.c Fri Feb 01 23:12:09 2013 +0100 @@ -16,20 +16,13 @@ Py_FrozenMain(int argc, char **argv) { char *p; - int i, n, sts = 1; + int i, n, sts; int inspect = 0; int unbuffered = 0; - char *oldloc = NULL; - wchar_t **argv_copy = NULL; + char *oldloc; + wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc); /* We need a second copies, as Python might modify the first one. */ - wchar_t **argv_copy2 = NULL; - - argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc); - argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc); - if (!argv_copy || !argv_copy2) { - fprintf(stderr, "out of memory\n"); - goto error; - } + wchar_t **argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc); Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ @@ -44,26 +37,37 @@ setbuf(stderr, (char *)NULL); } - oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); - if (!oldloc) { + if (!argv_copy) { fprintf(stderr, "out of memory\n"); - goto error; + return 1; } + oldloc = setlocale(LC_ALL, NULL); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { - argv_copy[i] = _Py_char2wchar(argv[i], NULL); +#ifdef HAVE_BROKEN_MBSTOWCS + size_t argsize = strlen(argv[i]); +#else + size_t argsize = mbstowcs(NULL, argv[i], 0); +#endif + size_t count; + if (argsize == (size_t)-1) { + fprintf(stderr, "Could not convert argument %d to string\n", i); + return 1; + } + argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); argv_copy2[i] = argv_copy[i]; if (!argv_copy[i]) { - fprintf(stderr, "Unable to decode the command line argument #%i\n", - i + 1); - argc = i; - goto error; + fprintf(stderr, "out of memory\n"); + return 1; + } + count = mbstowcs(argv_copy[i], argv[i], argsize+1); + if (count == (size_t)-1) { + fprintf(stderr, "Could not convert argument %d to string\n", i); + return 1; } } setlocale(LC_ALL, oldloc); - PyMem_RawFree(oldloc); - oldloc = NULL; #ifdef MS_WINDOWS PyInitFrozenExtensions(); @@ -97,14 +101,10 @@ PyWinFreeze_ExeTerm(); #endif Py_Finalize(); - -error: - PyMem_RawFree(argv_copy); - if (argv_copy2) { - for (i = 0; i < argc; i++) - PyMem_RawFree(argv_copy2[i]); - PyMem_RawFree(argv_copy2); + for (i = 0; i < argc; i++) { + PyMem_Free(argv_copy2[i]); } - PyMem_RawFree(oldloc); + PyMem_Free(argv_copy); + PyMem_Free(argv_copy2); return sts; } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/future.c --- a/Python/future.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/future.c Fri Feb 01 23:12:09 2013 +0100 @@ -58,15 +58,11 @@ static int future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) { - int i, done = 0, prev_line = 0; - stmt_ty first; + int i, found_docstring = 0, done = 0, prev_line = 0; if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) return 1; - if (asdl_seq_LEN(mod->v.Module.body) == 0) - return 1; - /* A subsequent pass will detect future imports that don't appear at the beginning of the file. There's one case, however, that is easier to handle here: A series of imports @@ -75,13 +71,8 @@ but is preceded by a regular import. */ - i = 0; - first = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i); - if (first->kind == Expr_kind && first->v.Expr.value->kind == Str_kind) - i++; - - for (; i < asdl_seq_LEN(mod->v.Module.body); i++) { + for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) { stmt_ty s = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i); if (done && s->lineno > prev_line) @@ -108,13 +99,18 @@ return 0; ff->ff_lineno = s->lineno; } - else { + else done = 1; - } } - else { + else if (s->kind == Expr_kind && !found_docstring) { + expr_ty e = s->v.Expr.value; + if (e->kind != Str_kind) + done = 1; + else + found_docstring = 1; + } + else done = 1; - } } return 1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/getargs.c --- a/Python/getargs.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/getargs.c Fri Feb 01 23:12:09 2013 +0100 @@ -46,16 +46,14 @@ } freelistentry_t; typedef struct { + int first_available; freelistentry_t *entries; - int first_available; - int entries_malloced; } freelist_t; -#define STATIC_FREELIST_ENTRIES 8 /* Forward */ static int vgetargs1(PyObject *, const char *, va_list *, int); -static void seterror(Py_ssize_t, const char *, int *, const char *, const char *); +static void seterror(int, const char *, int *, const char *, const char *); static char *convertitem(PyObject *, const char **, va_list *, int, int *, char *, size_t, freelist_t *); static char *converttuple(PyObject *, const char **, va_list *, int, @@ -189,8 +187,7 @@ freelist->entries[index].item); } } - if (freelist->entries_malloced) - PyMem_FREE(freelist->entries); + PyMem_FREE(freelist->entries); return retval; } @@ -200,8 +197,6 @@ { char msgbuf[256]; int levels[32]; - freelistentry_t static_entries[STATIC_FREELIST_ENTRIES]; - freelist_t freelist = {static_entries, 0, 0}; const char *fname = NULL; const char *message = NULL; int min = -1; @@ -211,6 +206,7 @@ const char *formatsave = format; Py_ssize_t i, len; char *msg; + freelist_t freelist = {0, NULL}; int compat = flags & FLAG_COMPAT; assert(compat || (args != (PyObject*)NULL)); @@ -244,15 +240,15 @@ message = format; endfmt = 1; break; - case '|': - if (level == 0) - min = max; - break; default: if (level == 0) { - if (Py_ISALPHA(Py_CHARMASK(c))) + if (c == 'O') + max++; + else if (isalpha(Py_CHARMASK(c))) { if (c != 'e') /* skip encoded */ max++; + } else if (c == '|') + min = max; } break; } @@ -266,13 +262,10 @@ format = formatsave; - if (max > STATIC_FREELIST_ENTRIES) { - freelist.entries = PyMem_NEW(freelistentry_t, max); - if (freelist.entries == NULL) { - PyErr_NoMemory(); - return 0; - } - freelist.entries_malloced = 1; + freelist.entries = PyMem_NEW(freelistentry_t, max); + if (freelist.entries == NULL) { + PyErr_NoMemory(); + return 0; } if (compat) { @@ -343,7 +336,7 @@ } } - if (*format != '\0' && !Py_ISALPHA(Py_CHARMASK(*format)) && + if (*format != '\0' && !isalpha(Py_CHARMASK(*format)) && *format != '(' && *format != '|' && *format != ':' && *format != ';') { PyErr_Format(PyExc_SystemError, @@ -357,7 +350,7 @@ static void -seterror(Py_ssize_t iarg, const char *msg, int *levels, const char *fname, +seterror(int iarg, const char *msg, int *levels, const char *fname, const char *message) { char buf[512]; @@ -373,7 +366,7 @@ } if (iarg != 0) { PyOS_snprintf(p, sizeof(buf) - (p - buf), - "argument %" PY_FORMAT_SIZE_T "d", iarg); + "argument %d", iarg); i = 0; p += strlen(p); while (levels[i] > 0 && i < 32 && (int)(p-buf) < 220) { @@ -436,7 +429,7 @@ } else if (c == ':' || c == ';' || c == '\0') break; - else if (level == 0 && Py_ISALPHA(Py_CHARMASK(c))) + else if (level == 0 && isalpha(Py_CHARMASK(c))) n++; } @@ -570,7 +563,7 @@ "size does not fit in an int"); \ return converterr("", arg, msgbuf, bufsize); \ } \ - *q = (int)s; \ + *q=s; \ } #define BUFFER_LEN ((flags & FLAG_SIZE_T) ? *q2:*q) #define RETURN_ERR_OCCURRED return msgbuf @@ -1428,8 +1421,7 @@ int max = INT_MAX; int i, len, nargs, nkeywords; PyObject *current_arg; - freelistentry_t static_entries[STATIC_FREELIST_ENTRIES]; - freelist_t freelist = {static_entries, 0, 0}; + freelist_t freelist = {0, NULL}; assert(args != NULL && PyTuple_Check(args)); assert(keywords == NULL || PyDict_Check(keywords)); @@ -1453,13 +1445,10 @@ for (len=0; kwlist[len]; len++) continue; - if (len > STATIC_FREELIST_ENTRIES) { - freelist.entries = PyMem_NEW(freelistentry_t, len); - if (freelist.entries == NULL) { - PyErr_NoMemory(); - return 0; - } - freelist.entries_malloced = 1; + freelist.entries = PyMem_NEW(freelistentry_t, len); + if (freelist.entries == NULL) { + PyErr_NoMemory(); + return 0; } nargs = PyTuple_GET_SIZE(args); @@ -1585,16 +1574,20 @@ Py_ssize_t pos = 0; while (PyDict_Next(keywords, &pos, &key, &value)) { int match = 0; + char *ks; if (!PyUnicode_Check(key)) { PyErr_SetString(PyExc_TypeError, "keywords must be strings"); return cleanreturn(0, &freelist); } /* check that _PyUnicode_AsString() result is not NULL */ - for (i = 0; i < len; i++) { - if (!PyUnicode_CompareWithASCIIString(key, kwlist[i])) { - match = 1; - break; + ks = _PyUnicode_AsString(key); + if (ks != NULL) { + for (i = 0; i < len; i++) { + if (!strcmp(ks, kwlist[i])) { + match = 1; + break; + } } } if (!match) { diff -r 35c88c53cf64 -r ecc10f0afb76 Python/import.c --- a/Python/import.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/import.c Fri Feb 01 23:12:09 2013 +0100 @@ -19,6 +19,14 @@ extern "C" { #endif +#ifdef MS_WINDOWS +/* for stat.st_mode */ +typedef unsigned short mode_t; +/* for _mkdir */ +#include +#endif + + #define CACHEDIR "__pycache__" /* See _PyImport_FixupExtensionObject() below */ @@ -85,10 +93,8 @@ int err = 0; path_hooks = PySys_GetObject("path_hooks"); - if (path_hooks == NULL) { - PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path_hooks"); + if (path_hooks == NULL) goto error; - } if (Py_VerboseFlag) PySys_WriteStderr("# installing zipimport hook\n"); @@ -289,30 +295,6 @@ NULL }; -static int -is_essential_module(PyObject *name) -{ - Py_ssize_t name_len; - char *name_str = PyUnicode_AsUTF8AndSize(name, &name_len); - - if (name_str == NULL) { - PyErr_Clear(); - return 0; - } - if (strcmp(name_str, "builtins") == 0) - return 1; - if (strcmp(name_str, "sys") == 0) - return 1; - /* These are all needed for stderr to still function */ - if (strcmp(name_str, "codecs") == 0) - return 1; - if (strcmp(name_str, "_codecs") == 0) - return 1; - if (strncmp(name_str, "encodings.", 10) == 0) - return 1; - return 0; -} - /* Un-initialize things, as good as we can */ @@ -392,7 +374,9 @@ if (value->ob_refcnt != 1) continue; if (PyUnicode_Check(key) && PyModule_Check(value)) { - if (is_essential_module(key)) + if (PyUnicode_CompareWithASCIIString(key, "builtins") == 0) + continue; + if (PyUnicode_CompareWithASCIIString(key, "sys") == 0) continue; if (Py_VerboseFlag) PySys_FormatStderr( @@ -408,7 +392,9 @@ pos = 0; while (PyDict_Next(modules, &pos, &key, &value)) { if (PyUnicode_Check(key) && PyModule_Check(value)) { - if (is_essential_module(key)) + if (PyUnicode_CompareWithASCIIString(key, "builtins") == 0) + continue; + if (PyUnicode_CompareWithASCIIString(key, "sys") == 0) continue; if (Py_VerboseFlag) PySys_FormatStderr("# cleanup[2] %U\n", key); @@ -417,28 +403,24 @@ } } - /* Collect garbage remaining after deleting the modules. Mostly - reference cycles created by classes. */ - PyGC_Collect(); - - /* Dump GC stats before it's too late, since it uses the warnings - machinery. */ - _PyGC_DumpShutdownStats(); - - /* Next, delete all remaining modules */ - pos = 0; - while (PyDict_Next(modules, &pos, &key, &value)) { - if (PyUnicode_Check(key) && PyModule_Check(value)) { - if (Py_VerboseFlag) - PySys_FormatStderr("# cleanup[3] %U\n", key); - _PyModule_Clear(value); - PyDict_SetItem(modules, key, Py_None); - } + /* Next, delete sys and builtins (in that order) */ + value = PyDict_GetItemString(modules, "sys"); + if (value != NULL && PyModule_Check(value)) { + if (Py_VerboseFlag) + PySys_WriteStderr("# cleanup sys\n"); + _PyModule_Clear(value); + PyDict_SetItemString(modules, "sys", Py_None); + } + value = PyDict_GetItemString(modules, "builtins"); + if (value != NULL && PyModule_Check(value)) { + if (Py_VerboseFlag) + PySys_WriteStderr("# cleanup builtins\n"); + _PyModule_Clear(value); + PyDict_SetItemString(modules, "builtins", Py_None); } /* Finally, clear and delete the modules directory */ PyDict_Clear(modules); - _PyGC_CollectNoFail(); interp->modules = NULL; Py_DECREF(modules); } @@ -585,10 +567,7 @@ mod = def->m_base.m_init(); if (mod == NULL) return NULL; - if (PyDict_SetItem(PyImport_GetModuleDict(), name, mod) == -1) { - Py_DECREF(mod); - return NULL; - } + PyDict_SetItem(PyImport_GetModuleDict(), name, mod); Py_DECREF(mod); } if (_PyState_AddModule(mod, def) < 0) { @@ -725,7 +704,7 @@ "no interpreter!"); } - pathobj = _PyObject_CallMethodIdObjArgs(interp->importlib, + pathobj = _PyObject_CallMethodObjIdArgs(interp->importlib, &PyId__get_sourcefile, cpathobj, NULL); if (pathobj == NULL) @@ -867,7 +846,7 @@ /* Forward */ -static const struct _frozen * find_frozen(PyObject *); +static struct _frozen * find_frozen(PyObject *); /* Helper to test for built-in module */ @@ -949,11 +928,11 @@ PyImport_GetImporter(PyObject *path) { PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL; - path_importer_cache = PySys_GetObject("path_importer_cache"); - path_hooks = PySys_GetObject("path_hooks"); - if (path_importer_cache != NULL && path_hooks != NULL) { - importer = get_path_importer(path_importer_cache, - path_hooks, path); + if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) { + if ((path_hooks = PySys_GetObject("path_hooks"))) { + importer = get_path_importer(path_importer_cache, + path_hooks, path); + } } Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */ return importer; @@ -1004,10 +983,10 @@ /* Frozen modules */ -static const struct _frozen * +static struct _frozen * find_frozen(PyObject *name) { - const struct _frozen *p; + struct _frozen *p; if (name == NULL) return NULL; @@ -1024,7 +1003,7 @@ static PyObject * get_frozen_object(PyObject *name) { - const struct _frozen *p = find_frozen(name); + struct _frozen *p = find_frozen(name); int size; if (p == NULL) { @@ -1048,7 +1027,7 @@ static PyObject * is_frozen_package(PyObject *name) { - const struct _frozen *p = find_frozen(name); + struct _frozen *p = find_frozen(name); int size; if (p == NULL) { @@ -1075,7 +1054,7 @@ int PyImport_ImportFrozenModuleObject(PyObject *name) { - const struct _frozen *p; + struct _frozen *p; PyObject *co, *m, *path; int ispackage; int size; @@ -1104,17 +1083,19 @@ goto err_return; } if (ispackage) { - /* Set __path__ to the empty list */ + /* Set __path__ to the package name */ PyObject *d, *l; int err; m = PyImport_AddModuleObject(name); if (m == NULL) goto err_return; d = PyModule_GetDict(m); - l = PyList_New(0); + l = PyList_New(1); if (l == NULL) { goto err_return; } + Py_INCREF(name); + PyList_SET_ITEM(l, 0, name); err = PyDict_SetItemString(d, "__path__", l); Py_DECREF(l); if (err != 0) @@ -1422,8 +1403,7 @@ if (builtins_import == NULL) { builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__); if (builtins_import == NULL) { - PyErr_SetString(PyExc_ImportError, "__import__ not found"); - goto error_with_unlock; + Py_FatalError("__import__ missing"); } } Py_INCREF(builtins_import); @@ -1460,7 +1440,7 @@ } if (initializing > 0) { /* _bootstrap._lock_unlock_module() releases the import lock */ - value = _PyObject_CallMethodIdObjArgs(interp->importlib, + value = _PyObject_CallMethodObjIdArgs(interp->importlib, &PyId__lock_unlock_module, abs_name, NULL); if (value == NULL) @@ -1478,7 +1458,7 @@ } else { /* _bootstrap._find_and_load() releases the import lock */ - mod = _PyObject_CallMethodIdObjArgs(interp->importlib, + mod = _PyObject_CallMethodObjIdArgs(interp->importlib, &PyId__find_and_load, abs_name, builtins_import, NULL); if (mod == NULL) { @@ -1547,7 +1527,7 @@ } } else { - final_mod = _PyObject_CallMethodIdObjArgs(interp->importlib, + final_mod = _PyObject_CallMethodObjIdArgs(interp->importlib, &PyId__handle_fromlist, mod, fromlist, builtins_import, NULL); @@ -1801,7 +1781,7 @@ imp_is_frozen(PyObject *self, PyObject *args) { PyObject *name; - const struct _frozen *p; + struct _frozen *p; if (!PyArg_ParseTuple(args, "U:is_frozen", &name)) return NULL; p = find_frozen(name); diff -r 35c88c53cf64 -r ecc10f0afb76 Python/importdl.c --- a/Python/importdl.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/importdl.c Fri Feb 01 23:12:09 2013 +0100 @@ -77,8 +77,6 @@ PyObject *msg = PyUnicode_FromFormat("dynamic module does not define " "init function (PyInit_%s)", shortname); - if (msg == NULL) - goto error; PyErr_SetImportError(msg, name, path); Py_DECREF(msg); goto error; @@ -99,12 +97,6 @@ /* Remember pointer to module init function. */ def = PyModule_GetDef(m); - if (def == NULL) { - PyErr_Format(PyExc_SystemError, - "initialization of %s did not return an extension " - "module", shortname); - goto error; - } def->m_base.m_init = p; /* Remember the filename as the __file__ attribute */ diff -r 35c88c53cf64 -r ecc10f0afb76 Python/importlib.h --- a/Python/importlib.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/importlib.h Fri Feb 01 23:12:09 2013 +0100 @@ -1,8 +1,8 @@ /* Auto-generated by Modules/_freeze_importlib.c */ -const unsigned char _Py_M__importlib[] = { +unsigned char _Py_M__importlib[] = { 99,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0, - 0,64,0,0,0,115,72,4,0,0,100,0,0,90,0,0, - 100,145,0,90,1,0,100,4,0,100,5,0,132,0,0,90, + 0,64,0,0,0,115,242,3,0,0,100,0,0,90,0,0, + 100,133,0,90,1,0,100,4,0,100,5,0,132,0,0,90, 2,0,100,6,0,100,7,0,132,0,0,90,3,0,100,8, 0,100,9,0,132,0,0,90,4,0,100,10,0,100,11,0, 132,0,0,90,5,0,100,12,0,100,13,0,132,0,0,90, @@ -11,1229 +11,1349 @@ 132,0,0,90,9,0,100,20,0,100,21,0,100,22,0,132, 1,0,90,10,0,100,23,0,100,24,0,132,0,0,90,11, 0,101,12,0,101,11,0,106,13,0,131,1,0,90,14,0, - 105,0,0,90,15,0,105,0,0,90,16,0,71,100,25,0, - 100,26,0,132,0,0,100,26,0,101,17,0,131,3,0,90, - 18,0,71,100,27,0,100,28,0,132,0,0,100,28,0,131, - 2,0,90,19,0,71,100,29,0,100,30,0,132,0,0,100, - 30,0,131,2,0,90,20,0,100,31,0,100,32,0,132,0, + 100,25,0,100,26,0,132,0,0,90,15,0,105,0,0,90, + 16,0,105,0,0,90,17,0,71,100,27,0,100,28,0,132, + 0,0,100,28,0,101,18,0,131,3,0,90,19,0,71,100, + 29,0,100,30,0,132,0,0,100,30,0,131,2,0,90,20, + 0,71,100,31,0,100,32,0,132,0,0,100,32,0,131,2, 0,90,21,0,100,33,0,100,34,0,132,0,0,90,22,0, - 100,35,0,100,36,0,132,0,0,90,23,0,100,37,0,106, - 24,0,100,38,0,100,39,0,131,2,0,100,40,0,23,90, - 25,0,101,26,0,106,27,0,101,25,0,100,39,0,131,2, - 0,90,28,0,100,41,0,90,29,0,100,42,0,103,1,0, - 90,30,0,100,43,0,103,1,0,90,31,0,100,44,0,103, - 1,0,90,32,0,100,45,0,100,46,0,100,47,0,132,1, - 0,90,33,0,100,48,0,100,49,0,132,0,0,90,34,0, - 100,50,0,100,51,0,132,0,0,90,35,0,100,52,0,100, - 53,0,132,0,0,90,36,0,100,54,0,100,55,0,100,56, - 0,100,57,0,132,0,1,90,37,0,71,100,58,0,100,59, - 0,132,0,0,100,59,0,131,2,0,90,38,0,71,100,60, - 0,100,61,0,132,0,0,100,61,0,101,38,0,131,3,0, - 90,39,0,100,62,0,100,63,0,100,64,0,100,65,0,132, - 0,1,90,40,0,100,66,0,100,67,0,132,0,0,90,41, - 0,100,68,0,100,69,0,132,0,0,90,42,0,100,70,0, - 100,71,0,132,0,0,90,43,0,100,72,0,100,73,0,132, - 0,0,90,44,0,100,74,0,100,75,0,132,0,0,90,45, - 0,100,76,0,100,77,0,132,0,0,90,46,0,100,78,0, - 100,79,0,132,0,0,90,47,0,100,80,0,100,81,0,132, - 0,0,90,48,0,100,45,0,100,45,0,100,45,0,100,82, - 0,100,83,0,132,3,0,90,49,0,100,45,0,100,45,0, - 100,45,0,100,84,0,100,85,0,132,3,0,90,50,0,100, - 86,0,100,86,0,100,87,0,100,88,0,132,2,0,90,51, - 0,100,89,0,100,90,0,132,0,0,90,52,0,71,100,91, - 0,100,92,0,132,0,0,100,92,0,131,2,0,90,53,0, - 71,100,93,0,100,94,0,132,0,0,100,94,0,131,2,0, - 90,54,0,71,100,95,0,100,96,0,132,0,0,100,96,0, - 131,2,0,90,55,0,71,100,97,0,100,98,0,132,0,0, - 100,98,0,131,2,0,90,56,0,71,100,99,0,100,100,0, - 132,0,0,100,100,0,101,56,0,131,3,0,90,57,0,71, - 100,101,0,100,102,0,132,0,0,100,102,0,131,2,0,90, - 58,0,71,100,103,0,100,104,0,132,0,0,100,104,0,101, - 58,0,101,57,0,131,4,0,90,59,0,71,100,105,0,100, - 106,0,132,0,0,100,106,0,101,58,0,101,56,0,131,4, - 0,90,60,0,103,0,0,90,61,0,71,100,107,0,100,108, - 0,132,0,0,100,108,0,131,2,0,90,62,0,71,100,109, - 0,100,110,0,132,0,0,100,110,0,131,2,0,90,63,0, - 71,100,111,0,100,112,0,132,0,0,100,112,0,131,2,0, - 90,64,0,71,100,113,0,100,114,0,132,0,0,100,114,0, - 131,2,0,90,65,0,71,100,115,0,100,116,0,132,0,0, - 100,116,0,131,2,0,90,66,0,71,100,117,0,100,118,0, - 132,0,0,100,118,0,131,2,0,90,67,0,100,119,0,100, - 120,0,132,0,0,90,68,0,100,121,0,100,122,0,132,0, - 0,90,69,0,100,123,0,100,124,0,132,0,0,90,70,0, - 100,125,0,90,71,0,101,71,0,100,126,0,23,90,72,0, - 100,127,0,100,128,0,132,0,0,90,73,0,100,129,0,100, - 130,0,132,0,0,90,74,0,100,45,0,100,86,0,100,131, - 0,100,132,0,132,2,0,90,75,0,100,133,0,100,134,0, - 132,0,0,90,76,0,100,135,0,100,136,0,132,0,0,90, - 77,0,100,137,0,100,138,0,132,0,0,90,78,0,100,45, - 0,100,45,0,102,0,0,100,86,0,100,139,0,100,140,0, - 132,4,0,90,79,0,100,141,0,100,142,0,132,0,0,90, - 80,0,100,143,0,100,144,0,132,0,0,90,81,0,100,45, - 0,83,40,146,0,0,0,117,83,1,0,0,67,111,114,101, + 100,35,0,100,36,0,132,0,0,90,23,0,100,37,0,100, + 38,0,132,0,0,90,24,0,100,39,0,101,25,0,100,40, + 0,131,1,0,100,41,0,62,66,101,25,0,100,42,0,131, + 1,0,100,43,0,62,66,90,26,0,101,27,0,100,44,0, + 100,45,0,132,0,0,101,28,0,100,46,0,100,47,0,100, + 48,0,131,3,0,68,131,1,0,131,1,0,90,29,0,100, + 49,0,90,30,0,100,50,0,103,1,0,90,31,0,100,51, + 0,103,1,0,90,32,0,100,52,0,103,1,0,90,33,0, + 100,53,0,100,54,0,100,55,0,132,1,0,90,34,0,100, + 56,0,100,57,0,132,0,0,90,35,0,100,58,0,100,59, + 0,132,0,0,90,36,0,100,60,0,100,61,0,132,0,0, + 90,37,0,100,62,0,100,63,0,132,0,0,90,38,0,100, + 64,0,100,65,0,132,0,0,90,39,0,100,66,0,100,67, + 0,132,0,0,90,40,0,100,68,0,100,69,0,132,0,0, + 90,41,0,100,70,0,100,71,0,132,0,0,90,42,0,100, + 72,0,100,73,0,132,0,0,90,43,0,100,74,0,100,75, + 0,132,0,0,90,44,0,100,53,0,100,53,0,100,53,0, + 100,76,0,100,77,0,132,3,0,90,45,0,100,53,0,100, + 53,0,100,53,0,100,78,0,100,79,0,132,3,0,90,46, + 0,71,100,80,0,100,81,0,132,0,0,100,81,0,131,2, + 0,90,47,0,71,100,82,0,100,83,0,132,0,0,100,83, + 0,131,2,0,90,48,0,71,100,84,0,100,85,0,132,0, + 0,100,85,0,131,2,0,90,49,0,71,100,86,0,100,87, + 0,132,0,0,100,87,0,131,2,0,90,50,0,71,100,88, + 0,100,89,0,132,0,0,100,89,0,101,50,0,131,3,0, + 90,51,0,71,100,90,0,100,91,0,132,0,0,100,91,0, + 131,2,0,90,52,0,71,100,92,0,100,93,0,132,0,0, + 100,93,0,101,52,0,101,51,0,131,4,0,90,53,0,71, + 100,94,0,100,95,0,132,0,0,100,95,0,101,52,0,101, + 50,0,131,4,0,90,54,0,103,0,0,90,55,0,71,100, + 96,0,100,97,0,132,0,0,100,97,0,131,2,0,90,56, + 0,71,100,98,0,100,99,0,132,0,0,100,99,0,131,2, + 0,90,57,0,71,100,100,0,100,101,0,132,0,0,100,101, + 0,131,2,0,90,58,0,71,100,102,0,100,103,0,132,0, + 0,100,103,0,131,2,0,90,59,0,71,100,104,0,100,105, + 0,132,0,0,100,105,0,131,2,0,90,60,0,71,100,106, + 0,100,107,0,132,0,0,100,107,0,131,2,0,90,61,0, + 100,108,0,100,109,0,132,0,0,90,62,0,100,110,0,100, + 111,0,132,0,0,90,63,0,100,112,0,100,113,0,132,0, + 0,90,64,0,100,114,0,90,65,0,100,115,0,100,116,0, + 132,0,0,90,66,0,100,117,0,100,118,0,132,0,0,90, + 67,0,100,53,0,100,46,0,100,119,0,100,120,0,132,2, + 0,90,68,0,100,121,0,100,122,0,132,0,0,90,69,0, + 100,123,0,100,124,0,132,0,0,90,70,0,100,125,0,100, + 126,0,132,0,0,90,71,0,100,53,0,100,53,0,102,0, + 0,100,46,0,100,127,0,100,128,0,132,4,0,90,72,0, + 100,129,0,100,130,0,132,0,0,90,73,0,100,131,0,100, + 132,0,132,0,0,90,74,0,100,53,0,83,40,134,0,0, + 0,117,83,1,0,0,67,111,114,101,32,105,109,112,108,101, + 109,101,110,116,97,116,105,111,110,32,111,102,32,105,109,112, + 111,114,116,46,10,10,84,104,105,115,32,109,111,100,117,108, + 101,32,105,115,32,78,79,84,32,109,101,97,110,116,32,116, + 111,32,98,101,32,100,105,114,101,99,116,108,121,32,105,109, + 112,111,114,116,101,100,33,32,73,116,32,104,97,115,32,98, + 101,101,110,32,100,101,115,105,103,110,101,100,32,115,117,99, + 104,10,116,104,97,116,32,105,116,32,99,97,110,32,98,101, + 32,98,111,111,116,115,116,114,97,112,112,101,100,32,105,110, + 116,111,32,80,121,116,104,111,110,32,97,115,32,116,104,101, 32,105,109,112,108,101,109,101,110,116,97,116,105,111,110,32, - 111,102,32,105,109,112,111,114,116,46,10,10,84,104,105,115, - 32,109,111,100,117,108,101,32,105,115,32,78,79,84,32,109, - 101,97,110,116,32,116,111,32,98,101,32,100,105,114,101,99, - 116,108,121,32,105,109,112,111,114,116,101,100,33,32,73,116, - 32,104,97,115,32,98,101,101,110,32,100,101,115,105,103,110, - 101,100,32,115,117,99,104,10,116,104,97,116,32,105,116,32, - 99,97,110,32,98,101,32,98,111,111,116,115,116,114,97,112, - 112,101,100,32,105,110,116,111,32,80,121,116,104,111,110,32, - 97,115,32,116,104,101,32,105,109,112,108,101,109,101,110,116, - 97,116,105,111,110,32,111,102,32,105,109,112,111,114,116,46, - 32,65,115,10,115,117,99,104,32,105,116,32,114,101,113,117, - 105,114,101,115,32,116,104,101,32,105,110,106,101,99,116,105, - 111,110,32,111,102,32,115,112,101,99,105,102,105,99,32,109, - 111,100,117,108,101,115,32,97,110,100,32,97,116,116,114,105, - 98,117,116,101,115,32,105,110,32,111,114,100,101,114,32,116, - 111,10,119,111,114,107,46,32,79,110,101,32,115,104,111,117, - 108,100,32,117,115,101,32,105,109,112,111,114,116,108,105,98, - 32,97,115,32,116,104,101,32,112,117,98,108,105,99,45,102, - 97,99,105,110,103,32,118,101,114,115,105,111,110,32,111,102, - 32,116,104,105,115,32,109,111,100,117,108,101,46,10,10,244, - 3,0,0,0,119,105,110,244,6,0,0,0,99,121,103,119, - 105,110,244,6,0,0,0,100,97,114,119,105,110,99,0,0, - 0,0,0,0,0,0,1,0,0,0,2,0,0,0,67,0, - 0,0,115,49,0,0,0,116,0,0,106,1,0,106,2,0, - 116,3,0,131,1,0,114,33,0,100,1,0,100,2,0,132, - 0,0,125,0,0,110,12,0,100,3,0,100,2,0,132,0, - 0,125,0,0,124,0,0,83,40,4,0,0,0,78,99,0, - 0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,83, - 0,0,0,115,13,0,0,0,100,1,0,116,0,0,106,1, - 0,107,6,0,83,40,2,0,0,0,117,53,0,0,0,84, - 114,117,101,32,105,102,32,102,105,108,101,110,97,109,101,115, - 32,109,117,115,116,32,98,101,32,99,104,101,99,107,101,100, - 32,99,97,115,101,45,105,110,115,101,110,115,105,116,105,118, - 101,108,121,46,115,12,0,0,0,80,89,84,72,79,78,67, - 65,83,69,79,75,40,2,0,0,0,244,3,0,0,0,95, - 111,115,116,7,0,0,0,101,110,118,105,114,111,110,168,0, - 0,0,0,114,4,0,0,0,114,4,0,0,0,245,29,0, + 111,102,32,105,109,112,111,114,116,46,32,65,115,10,115,117, + 99,104,32,105,116,32,114,101,113,117,105,114,101,115,32,116, + 104,101,32,105,110,106,101,99,116,105,111,110,32,111,102,32, + 115,112,101,99,105,102,105,99,32,109,111,100,117,108,101,115, + 32,97,110,100,32,97,116,116,114,105,98,117,116,101,115,32, + 105,110,32,111,114,100,101,114,32,116,111,10,119,111,114,107, + 46,32,79,110,101,32,115,104,111,117,108,100,32,117,115,101, + 32,105,109,112,111,114,116,108,105,98,32,97,115,32,116,104, + 101,32,112,117,98,108,105,99,45,102,97,99,105,110,103,32, + 118,101,114,115,105,111,110,32,111,102,32,116,104,105,115,32, + 109,111,100,117,108,101,46,10,10,117,3,0,0,0,119,105, + 110,117,6,0,0,0,99,121,103,119,105,110,117,6,0,0, + 0,100,97,114,119,105,110,99,0,0,0,0,0,0,0,0, + 1,0,0,0,2,0,0,0,67,0,0,0,115,49,0,0, + 0,116,0,0,106,1,0,106,2,0,116,3,0,131,1,0, + 114,33,0,100,1,0,100,2,0,132,0,0,125,0,0,110, + 12,0,100,3,0,100,2,0,132,0,0,125,0,0,124,0, + 0,83,40,4,0,0,0,78,99,0,0,0,0,0,0,0, + 0,0,0,0,0,2,0,0,0,83,0,0,0,115,13,0, + 0,0,100,1,0,116,0,0,106,1,0,107,6,0,83,40, + 2,0,0,0,117,53,0,0,0,84,114,117,101,32,105,102, + 32,102,105,108,101,110,97,109,101,115,32,109,117,115,116,32, + 98,101,32,99,104,101,99,107,101,100,32,99,97,115,101,45, + 105,110,115,101,110,115,105,116,105,118,101,108,121,46,115,12, + 0,0,0,80,89,84,72,79,78,67,65,83,69,79,75,40, + 2,0,0,0,117,3,0,0,0,95,111,115,117,7,0,0, + 0,101,110,118,105,114,111,110,40,0,0,0,0,40,0,0, + 0,0,40,0,0,0,0,117,29,0,0,0,60,102,114,111, + 122,101,110,32,105,109,112,111,114,116,108,105,98,46,95,98, + 111,111,116,115,116,114,97,112,62,117,11,0,0,0,95,114, + 101,108,97,120,95,99,97,115,101,34,0,0,0,115,2,0, + 0,0,0,2,117,37,0,0,0,95,109,97,107,101,95,114, + 101,108,97,120,95,99,97,115,101,46,60,108,111,99,97,108, + 115,62,46,95,114,101,108,97,120,95,99,97,115,101,99,0, + 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,83, + 0,0,0,115,4,0,0,0,100,1,0,83,40,2,0,0, + 0,117,53,0,0,0,84,114,117,101,32,105,102,32,102,105, + 108,101,110,97,109,101,115,32,109,117,115,116,32,98,101,32, + 99,104,101,99,107,101,100,32,99,97,115,101,45,105,110,115, + 101,110,115,105,116,105,118,101,108,121,46,70,40,0,0,0, + 0,40,0,0,0,0,40,0,0,0,0,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,11,0,0,0,95,114,101,108,97,120,95,99,97, + 115,101,38,0,0,0,115,2,0,0,0,0,2,40,4,0, + 0,0,117,3,0,0,0,115,121,115,117,8,0,0,0,112, + 108,97,116,102,111,114,109,117,10,0,0,0,115,116,97,114, + 116,115,119,105,116,104,117,27,0,0,0,95,67,65,83,69, + 95,73,78,83,69,78,83,73,84,73,86,69,95,80,76,65, + 84,70,79,82,77,83,40,1,0,0,0,117,11,0,0,0, + 95,114,101,108,97,120,95,99,97,115,101,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,16,0,0,0,95,109,97,107, + 101,95,114,101,108,97,120,95,99,97,115,101,32,0,0,0, + 115,8,0,0,0,0,1,18,1,15,4,12,3,117,16,0, + 0,0,95,109,97,107,101,95,114,101,108,97,120,95,99,97, + 115,101,99,1,0,0,0,0,0,0,0,2,0,0,0,3, + 0,0,0,67,0,0,0,115,108,0,0,0,116,0,0,124, + 0,0,131,1,0,125,0,0,103,0,0,125,1,0,124,1, + 0,106,1,0,124,0,0,100,1,0,64,131,1,0,1,124, + 1,0,106,1,0,124,0,0,100,2,0,63,100,1,0,64, + 131,1,0,1,124,1,0,106,1,0,124,0,0,100,3,0, + 63,100,1,0,64,131,1,0,1,124,1,0,106,1,0,124, + 0,0,100,4,0,63,100,1,0,64,131,1,0,1,116,2, + 0,124,1,0,131,1,0,83,40,5,0,0,0,117,111,0, + 0,0,67,111,110,118,101,114,116,32,97,32,51,50,45,98, + 105,116,32,105,110,116,101,103,101,114,32,116,111,32,108,105, + 116,116,108,101,45,101,110,100,105,97,110,46,10,10,32,32, + 32,32,88,88,88,32,84,101,109,112,111,114,97,114,121,32, + 117,110,116,105,108,32,109,97,114,115,104,97,108,39,115,32, + 108,111,110,103,32,102,117,110,99,116,105,111,110,115,32,97, + 114,101,32,101,120,112,111,115,101,100,46,10,10,32,32,32, + 32,105,255,0,0,0,105,8,0,0,0,105,16,0,0,0, + 105,24,0,0,0,40,3,0,0,0,117,3,0,0,0,105, + 110,116,117,6,0,0,0,97,112,112,101,110,100,117,9,0, + 0,0,98,121,116,101,97,114,114,97,121,40,2,0,0,0, + 117,1,0,0,0,120,117,9,0,0,0,105,110,116,95,98, + 121,116,101,115,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,7,0,0,0,95,119,95,108,111,110,103,45,0,0,0, + 115,14,0,0,0,0,6,12,1,6,1,17,1,21,1,21, + 1,21,1,117,7,0,0,0,95,119,95,108,111,110,103,99, + 1,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, + 67,0,0,0,115,68,0,0,0,124,0,0,100,1,0,25, + 125,1,0,124,1,0,124,0,0,100,2,0,25,100,3,0, + 62,79,125,1,0,124,1,0,124,0,0,100,4,0,25,100, + 5,0,62,79,125,1,0,124,1,0,124,0,0,100,6,0, + 25,100,7,0,62,79,125,1,0,124,1,0,83,40,8,0, + 0,0,117,115,0,0,0,67,111,110,118,101,114,116,32,52, + 32,98,121,116,101,115,32,105,110,32,108,105,116,116,108,101, + 45,101,110,100,105,97,110,32,116,111,32,97,110,32,105,110, + 116,101,103,101,114,46,10,10,32,32,32,32,88,88,88,32, + 84,101,109,112,111,114,97,114,121,32,117,110,116,105,108,32, + 109,97,114,115,104,97,108,39,115,32,108,111,110,103,32,102, + 117,110,99,116,105,111,110,32,97,114,101,32,101,120,112,111, + 115,101,100,46,10,10,32,32,32,32,105,0,0,0,0,105, + 1,0,0,0,105,8,0,0,0,105,2,0,0,0,105,16, + 0,0,0,105,3,0,0,0,105,24,0,0,0,40,0,0, + 0,0,40,2,0,0,0,117,9,0,0,0,105,110,116,95, + 98,121,116,101,115,117,1,0,0,0,120,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,7,0,0,0,95,114,95,108, + 111,110,103,61,0,0,0,115,10,0,0,0,0,6,10,1, + 18,1,18,1,18,1,117,7,0,0,0,95,114,95,108,111, + 110,103,99,0,0,0,0,0,0,0,0,3,0,0,0,4, + 0,0,0,71,0,0,0,115,103,0,0,0,103,0,0,125, + 1,0,120,71,0,124,0,0,68,93,63,0,125,2,0,124, + 2,0,115,31,0,113,13,0,110,0,0,124,1,0,106,0, + 0,124,2,0,131,1,0,1,124,2,0,100,4,0,25,116, + 1,0,107,7,0,114,13,0,124,1,0,106,0,0,116,2, + 0,131,1,0,1,113,13,0,113,13,0,87,100,2,0,106, + 3,0,124,1,0,100,3,0,100,5,0,133,2,0,25,131, + 1,0,83,40,6,0,0,0,117,31,0,0,0,82,101,112, + 108,97,99,101,109,101,110,116,32,102,111,114,32,111,115,46, + 112,97,116,104,46,106,111,105,110,40,41,46,105,1,0,0, + 0,117,0,0,0,0,78,105,255,255,255,255,105,255,255,255, + 255,40,4,0,0,0,117,6,0,0,0,97,112,112,101,110, + 100,117,15,0,0,0,112,97,116,104,95,115,101,112,97,114, + 97,116,111,114,115,117,8,0,0,0,112,97,116,104,95,115, + 101,112,117,4,0,0,0,106,111,105,110,40,3,0,0,0, + 117,10,0,0,0,112,97,116,104,95,112,97,114,116,115,117, + 9,0,0,0,110,101,119,95,112,97,114,116,115,117,4,0, + 0,0,112,97,114,116,40,0,0,0,0,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,10,0,0,0,95,112,97,116,104,95,106,111,105, + 110,74,0,0,0,115,16,0,0,0,0,2,6,1,13,1, + 6,1,6,1,13,1,16,1,20,1,117,10,0,0,0,95, + 112,97,116,104,95,106,111,105,110,99,1,0,0,0,0,0, + 0,0,6,0,0,0,3,0,0,0,67,0,0,0,115,85, + 0,0,0,120,48,0,116,0,0,124,0,0,131,1,0,68, + 93,28,0,125,1,0,124,1,0,116,1,0,107,6,0,114, + 13,0,124,1,0,125,2,0,80,113,13,0,113,13,0,87, + 116,2,0,125,2,0,124,0,0,106,3,0,124,2,0,131, + 1,0,92,3,0,125,3,0,125,4,0,125,5,0,124,3, + 0,124,5,0,102,2,0,83,40,1,0,0,0,117,32,0, + 0,0,82,101,112,108,97,99,101,109,101,110,116,32,102,111, + 114,32,111,115,46,112,97,116,104,46,115,112,108,105,116,40, + 41,46,40,4,0,0,0,117,8,0,0,0,114,101,118,101, + 114,115,101,100,117,15,0,0,0,112,97,116,104,95,115,101, + 112,97,114,97,116,111,114,115,117,8,0,0,0,112,97,116, + 104,95,115,101,112,117,10,0,0,0,114,112,97,114,116,105, + 116,105,111,110,40,6,0,0,0,117,4,0,0,0,112,97, + 116,104,117,1,0,0,0,120,117,3,0,0,0,115,101,112, + 117,5,0,0,0,102,114,111,110,116,117,1,0,0,0,95, + 117,4,0,0,0,116,97,105,108,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,11,0,0,0,95,112,97,116,104,95, + 115,112,108,105,116,86,0,0,0,115,14,0,0,0,0,2, + 19,1,12,1,6,1,8,2,6,1,24,1,117,11,0,0, + 0,95,112,97,116,104,95,115,112,108,105,116,99,2,0,0, + 0,0,0,0,0,3,0,0,0,11,0,0,0,67,0,0, + 0,115,61,0,0,0,121,19,0,116,0,0,106,1,0,124, + 0,0,131,1,0,125,2,0,87,110,22,0,4,116,2,0, + 107,10,0,114,43,0,1,1,1,100,1,0,83,89,110,1, + 0,88,124,2,0,106,3,0,100,2,0,64,124,1,0,107, + 2,0,83,40,3,0,0,0,117,49,0,0,0,84,101,115, + 116,32,119,104,101,116,104,101,114,32,116,104,101,32,112,97, + 116,104,32,105,115,32,116,104,101,32,115,112,101,99,105,102, + 105,101,100,32,109,111,100,101,32,116,121,112,101,46,70,105, + 0,240,0,0,40,4,0,0,0,117,3,0,0,0,95,111, + 115,117,4,0,0,0,115,116,97,116,117,7,0,0,0,79, + 83,69,114,114,111,114,117,7,0,0,0,115,116,95,109,111, + 100,101,40,3,0,0,0,117,4,0,0,0,112,97,116,104, + 117,4,0,0,0,109,111,100,101,117,9,0,0,0,115,116, + 97,116,95,105,110,102,111,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,18,0,0,0,95,112,97,116,104,95,105,115, + 95,109,111,100,101,95,116,121,112,101,98,0,0,0,115,10, + 0,0,0,0,2,3,1,19,1,13,1,9,1,117,18,0, + 0,0,95,112,97,116,104,95,105,115,95,109,111,100,101,95, + 116,121,112,101,99,1,0,0,0,0,0,0,0,1,0,0, + 0,3,0,0,0,67,0,0,0,115,13,0,0,0,116,0, + 0,124,0,0,100,1,0,131,2,0,83,40,2,0,0,0, + 117,31,0,0,0,82,101,112,108,97,99,101,109,101,110,116, + 32,102,111,114,32,111,115,46,112,97,116,104,46,105,115,102, + 105,108,101,46,105,0,128,0,0,40,1,0,0,0,117,18, + 0,0,0,95,112,97,116,104,95,105,115,95,109,111,100,101, + 95,116,121,112,101,40,1,0,0,0,117,4,0,0,0,112, + 97,116,104,40,0,0,0,0,40,0,0,0,0,117,29,0, 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, - 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,244, - 11,0,0,0,95,114,101,108,97,120,95,99,97,115,101,30, - 0,0,0,115,2,0,0,0,0,2,117,37,0,0,0,95, - 109,97,107,101,95,114,101,108,97,120,95,99,97,115,101,46, - 60,108,111,99,97,108,115,62,46,95,114,101,108,97,120,95, - 99,97,115,101,99,0,0,0,0,0,0,0,0,0,0,0, - 0,1,0,0,0,83,0,0,0,115,4,0,0,0,100,1, - 0,83,40,2,0,0,0,117,53,0,0,0,84,114,117,101, - 32,105,102,32,102,105,108,101,110,97,109,101,115,32,109,117, - 115,116,32,98,101,32,99,104,101,99,107,101,100,32,99,97, - 115,101,45,105,110,115,101,110,115,105,116,105,118,101,108,121, - 46,70,114,4,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,114,6,0,0,0, - 34,0,0,0,115,2,0,0,0,0,2,40,4,0,0,0, - 244,3,0,0,0,115,121,115,244,8,0,0,0,112,108,97, - 116,102,111,114,109,244,10,0,0,0,115,116,97,114,116,115, - 119,105,116,104,244,27,0,0,0,95,67,65,83,69,95,73, - 78,83,69,78,83,73,84,73,86,69,95,80,76,65,84,70, - 79,82,77,83,40,1,0,0,0,114,6,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,244,16,0, - 0,0,95,109,97,107,101,95,114,101,108,97,120,95,99,97, - 115,101,28,0,0,0,115,8,0,0,0,0,1,18,1,15, - 4,12,3,114,11,0,0,0,99,1,0,0,0,0,0,0, - 0,1,0,0,0,3,0,0,0,67,0,0,0,115,26,0, - 0,0,116,0,0,124,0,0,131,1,0,100,1,0,64,106, - 1,0,100,2,0,100,3,0,131,2,0,83,40,4,0,0, - 0,117,42,0,0,0,67,111,110,118,101,114,116,32,97,32, - 51,50,45,98,105,116,32,105,110,116,101,103,101,114,32,116, - 111,32,108,105,116,116,108,101,45,101,110,100,105,97,110,46, - 108,3,0,0,0,255,127,255,127,3,0,233,4,0,0,0, - 244,6,0,0,0,108,105,116,116,108,101,40,2,0,0,0, - 244,3,0,0,0,105,110,116,244,8,0,0,0,116,111,95, - 98,121,116,101,115,40,1,0,0,0,244,1,0,0,0,120, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,244, - 7,0,0,0,95,119,95,108,111,110,103,40,0,0,0,115, - 2,0,0,0,0,2,114,17,0,0,0,99,1,0,0,0, - 0,0,0,0,1,0,0,0,3,0,0,0,67,0,0,0, - 115,16,0,0,0,116,0,0,106,1,0,124,0,0,100,1, - 0,131,2,0,83,40,2,0,0,0,117,47,0,0,0,67, - 111,110,118,101,114,116,32,52,32,98,121,116,101,115,32,105, - 110,32,108,105,116,116,108,101,45,101,110,100,105,97,110,32, - 116,111,32,97,110,32,105,110,116,101,103,101,114,46,114,13, - 0,0,0,40,2,0,0,0,114,14,0,0,0,244,10,0, - 0,0,102,114,111,109,95,98,121,116,101,115,40,1,0,0, - 0,116,9,0,0,0,105,110,116,95,98,121,116,101,115,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,244,7, - 0,0,0,95,114,95,108,111,110,103,45,0,0,0,115,2, - 0,0,0,0,2,114,19,0,0,0,99,0,0,0,0,0, - 0,0,0,1,0,0,0,3,0,0,0,71,0,0,0,115, - 26,0,0,0,116,0,0,106,1,0,100,1,0,100,2,0, - 132,0,0,124,0,0,68,131,1,0,131,1,0,83,40,3, - 0,0,0,117,31,0,0,0,82,101,112,108,97,99,101,109, - 101,110,116,32,102,111,114,32,111,115,46,112,97,116,104,46, - 106,111,105,110,40,41,46,99,1,0,0,0,0,0,0,0, - 2,0,0,0,4,0,0,0,83,0,0,0,115,37,0,0, - 0,103,0,0,124,0,0,93,27,0,125,1,0,124,1,0, - 114,6,0,124,1,0,106,0,0,116,1,0,131,1,0,145, - 2,0,113,6,0,83,114,4,0,0,0,40,2,0,0,0, - 244,6,0,0,0,114,115,116,114,105,112,244,15,0,0,0, - 112,97,116,104,95,115,101,112,97,114,97,116,111,114,115,40, - 2,0,0,0,244,2,0,0,0,46,48,244,4,0,0,0, - 112,97,114,116,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,245,10,0,0,0,60,108,105,115,116,99,111,109, - 112,62,52,0,0,0,115,2,0,0,0,9,1,117,30,0, - 0,0,95,112,97,116,104,95,106,111,105,110,46,60,108,111, - 99,97,108,115,62,46,60,108,105,115,116,99,111,109,112,62, - 40,2,0,0,0,244,8,0,0,0,112,97,116,104,95,115, - 101,112,244,4,0,0,0,106,111,105,110,40,1,0,0,0, - 244,10,0,0,0,112,97,116,104,95,112,97,114,116,115,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,244,10, - 0,0,0,95,112,97,116,104,95,106,111,105,110,50,0,0, - 0,115,4,0,0,0,0,2,15,1,114,28,0,0,0,99, - 1,0,0,0,0,0,0,0,5,0,0,0,5,0,0,0, - 67,0,0,0,115,134,0,0,0,116,0,0,116,1,0,131, - 1,0,100,1,0,107,2,0,114,52,0,124,0,0,106,2, - 0,116,3,0,131,1,0,92,3,0,125,1,0,125,2,0, - 125,3,0,124,1,0,124,3,0,102,2,0,83,120,69,0, - 116,4,0,124,0,0,131,1,0,68,93,55,0,125,4,0, - 124,4,0,116,1,0,107,6,0,114,65,0,124,0,0,106, - 5,0,124,4,0,100,2,0,100,1,0,131,1,1,92,2, - 0,125,1,0,125,3,0,124,1,0,124,3,0,102,2,0, - 83,113,65,0,87,100,3,0,124,0,0,102,2,0,83,40, - 4,0,0,0,117,32,0,0,0,82,101,112,108,97,99,101, - 109,101,110,116,32,102,111,114,32,111,115,46,112,97,116,104, - 46,115,112,108,105,116,40,41,46,233,1,0,0,0,116,8, - 0,0,0,109,97,120,115,112,108,105,116,244,0,0,0,0, - 40,6,0,0,0,244,3,0,0,0,108,101,110,114,21,0, - 0,0,244,10,0,0,0,114,112,97,114,116,105,116,105,111, - 110,114,25,0,0,0,244,8,0,0,0,114,101,118,101,114, - 115,101,100,244,6,0,0,0,114,115,112,108,105,116,40,5, - 0,0,0,244,4,0,0,0,112,97,116,104,116,5,0,0, - 0,102,114,111,110,116,244,1,0,0,0,95,244,4,0,0, - 0,116,97,105,108,114,16,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,244,11,0,0,0,95,112, - 97,116,104,95,115,112,108,105,116,56,0,0,0,115,16,0, - 0,0,0,2,18,1,24,1,10,1,19,1,12,1,27,1, - 14,1,114,38,0,0,0,99,2,0,0,0,0,0,0,0, - 3,0,0,0,11,0,0,0,67,0,0,0,115,61,0,0, - 0,121,19,0,116,0,0,106,1,0,124,0,0,131,1,0, - 125,2,0,87,110,22,0,4,116,2,0,107,10,0,114,43, - 0,1,1,1,100,1,0,83,89,110,1,0,88,124,2,0, - 106,3,0,100,2,0,64,124,1,0,107,2,0,83,40,3, - 0,0,0,117,49,0,0,0,84,101,115,116,32,119,104,101, - 116,104,101,114,32,116,104,101,32,112,97,116,104,32,105,115, - 32,116,104,101,32,115,112,101,99,105,102,105,101,100,32,109, - 111,100,101,32,116,121,112,101,46,70,105,0,240,0,0,40, - 4,0,0,0,114,3,0,0,0,244,4,0,0,0,115,116, - 97,116,244,7,0,0,0,79,83,69,114,114,111,114,244,7, - 0,0,0,115,116,95,109,111,100,101,40,3,0,0,0,114, - 35,0,0,0,244,4,0,0,0,109,111,100,101,116,9,0, - 0,0,115,116,97,116,95,105,110,102,111,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,244,18,0,0,0,95, - 112,97,116,104,95,105,115,95,109,111,100,101,95,116,121,112, - 101,68,0,0,0,115,10,0,0,0,0,2,3,1,19,1, - 13,1,9,1,114,43,0,0,0,99,1,0,0,0,0,0, - 0,0,1,0,0,0,3,0,0,0,67,0,0,0,115,13, - 0,0,0,116,0,0,124,0,0,100,1,0,131,2,0,83, - 40,2,0,0,0,117,31,0,0,0,82,101,112,108,97,99, - 101,109,101,110,116,32,102,111,114,32,111,115,46,112,97,116, - 104,46,105,115,102,105,108,101,46,105,0,128,0,0,40,1, - 0,0,0,114,43,0,0,0,40,1,0,0,0,114,35,0, - 0,0,114,4,0,0,0,114,4,0,0,0,114,5,0,0, - 0,244,12,0,0,0,95,112,97,116,104,95,105,115,102,105, - 108,101,78,0,0,0,115,2,0,0,0,0,2,114,44,0, - 0,0,99,1,0,0,0,0,0,0,0,1,0,0,0,3, - 0,0,0,67,0,0,0,115,34,0,0,0,124,0,0,115, - 21,0,116,0,0,106,1,0,131,0,0,125,0,0,110,0, - 0,116,2,0,124,0,0,100,1,0,131,2,0,83,40,2, - 0,0,0,117,30,0,0,0,82,101,112,108,97,99,101,109, - 101,110,116,32,102,111,114,32,111,115,46,112,97,116,104,46, - 105,115,100,105,114,46,105,0,64,0,0,40,3,0,0,0, - 114,3,0,0,0,116,6,0,0,0,103,101,116,99,119,100, - 114,43,0,0,0,40,1,0,0,0,114,35,0,0,0,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,244,11, - 0,0,0,95,112,97,116,104,95,105,115,100,105,114,84,0, - 0,0,115,6,0,0,0,0,2,6,1,15,1,114,45,0, - 0,0,105,182,1,0,0,99,3,0,0,0,0,0,0,0, - 6,0,0,0,17,0,0,0,67,0,0,0,115,192,0,0, - 0,100,1,0,106,0,0,124,0,0,116,1,0,124,0,0, - 131,1,0,131,2,0,125,3,0,116,2,0,106,3,0,124, - 3,0,116,2,0,106,4,0,116,2,0,106,5,0,66,116, - 2,0,106,6,0,66,124,2,0,100,2,0,64,131,3,0, - 125,4,0,121,60,0,116,7,0,106,8,0,124,4,0,100, - 3,0,131,2,0,143,20,0,125,5,0,124,5,0,106,9, - 0,124,1,0,131,1,0,1,87,100,4,0,81,88,116,2, - 0,106,10,0,124,3,0,124,0,0,131,2,0,1,87,110, - 59,0,4,116,11,0,107,10,0,114,187,0,1,1,1,121, - 17,0,116,2,0,106,12,0,124,3,0,131,1,0,1,87, - 110,18,0,4,116,11,0,107,10,0,114,179,0,1,1,1, - 89,110,1,0,88,130,0,0,89,110,1,0,88,100,4,0, - 83,40,5,0,0,0,117,162,0,0,0,66,101,115,116,45, - 101,102,102,111,114,116,32,102,117,110,99,116,105,111,110,32, - 116,111,32,119,114,105,116,101,32,100,97,116,97,32,116,111, - 32,97,32,112,97,116,104,32,97,116,111,109,105,99,97,108, - 108,121,46,10,32,32,32,32,66,101,32,112,114,101,112,97, - 114,101,100,32,116,111,32,104,97,110,100,108,101,32,97,32, - 70,105,108,101,69,120,105,115,116,115,69,114,114,111,114,32, - 105,102,32,99,111,110,99,117,114,114,101,110,116,32,119,114, - 105,116,105,110,103,32,111,102,32,116,104,101,10,32,32,32, - 32,116,101,109,112,111,114,97,114,121,32,102,105,108,101,32, - 105,115,32,97,116,116,101,109,112,116,101,100,46,117,5,0, - 0,0,123,125,46,123,125,105,182,1,0,0,116,2,0,0, - 0,119,98,78,40,13,0,0,0,244,6,0,0,0,102,111, - 114,109,97,116,244,2,0,0,0,105,100,114,3,0,0,0, - 116,4,0,0,0,111,112,101,110,116,6,0,0,0,79,95, - 69,88,67,76,116,7,0,0,0,79,95,67,82,69,65,84, - 116,8,0,0,0,79,95,87,82,79,78,76,89,244,3,0, - 0,0,95,105,111,244,6,0,0,0,70,105,108,101,73,79, - 244,5,0,0,0,119,114,105,116,101,244,7,0,0,0,114, - 101,112,108,97,99,101,114,40,0,0,0,116,6,0,0,0, - 117,110,108,105,110,107,40,6,0,0,0,114,35,0,0,0, - 244,4,0,0,0,100,97,116,97,114,42,0,0,0,116,8, - 0,0,0,112,97,116,104,95,116,109,112,116,2,0,0,0, - 102,100,244,4,0,0,0,102,105,108,101,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,244,13,0,0,0,95, - 119,114,105,116,101,95,97,116,111,109,105,99,91,0,0,0, - 115,26,0,0,0,0,5,24,1,9,1,33,1,3,3,21, - 1,19,1,20,1,13,1,3,1,17,1,13,1,5,1,114, - 54,0,0,0,99,2,0,0,0,0,0,0,0,3,0,0, - 0,7,0,0,0,67,0,0,0,115,95,0,0,0,120,69, - 0,100,1,0,100,2,0,100,3,0,100,4,0,103,4,0, - 68,93,49,0,125,2,0,116,0,0,124,1,0,124,2,0, - 131,2,0,114,19,0,116,1,0,124,0,0,124,2,0,116, - 2,0,124,1,0,124,2,0,131,2,0,131,3,0,1,113, - 19,0,113,19,0,87,124,0,0,106,3,0,106,4,0,124, - 1,0,106,3,0,131,1,0,1,100,5,0,83,40,6,0, - 0,0,117,47,0,0,0,83,105,109,112,108,101,32,115,117, - 98,115,116,105,116,117,116,101,32,102,111,114,32,102,117,110, - 99,116,111,111,108,115,46,117,112,100,97,116,101,95,119,114, - 97,112,112,101,114,46,244,10,0,0,0,95,95,109,111,100, - 117,108,101,95,95,244,8,0,0,0,95,95,110,97,109,101, - 95,95,244,12,0,0,0,95,95,113,117,97,108,110,97,109, - 101,95,95,244,7,0,0,0,95,95,100,111,99,95,95,78, - 40,5,0,0,0,244,7,0,0,0,104,97,115,97,116,116, - 114,244,7,0,0,0,115,101,116,97,116,116,114,244,7,0, - 0,0,103,101,116,97,116,116,114,244,8,0,0,0,95,95, - 100,105,99,116,95,95,244,6,0,0,0,117,112,100,97,116, - 101,40,3,0,0,0,116,3,0,0,0,110,101,119,116,3, - 0,0,0,111,108,100,114,51,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,244,5,0,0,0,95, - 119,114,97,112,113,0,0,0,115,8,0,0,0,0,2,25, - 1,15,1,32,1,114,64,0,0,0,99,0,0,0,0,0, - 0,0,0,0,0,0,0,1,0,0,0,64,0,0,0,115, - 16,0,0,0,101,0,0,90,1,0,100,0,0,90,2,0, - 100,1,0,83,40,2,0,0,0,244,14,0,0,0,95,68, - 101,97,100,108,111,99,107,69,114,114,111,114,78,40,3,0, - 0,0,114,56,0,0,0,114,55,0,0,0,114,57,0,0, - 0,114,4,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,65,0,0,0,132,0,0,0,115,2, - 0,0,0,12,1,114,65,0,0,0,99,0,0,0,0,0, - 0,0,0,0,0,0,0,2,0,0,0,64,0,0,0,115, - 82,0,0,0,101,0,0,90,1,0,100,0,0,90,2,0, - 100,1,0,90,3,0,100,2,0,100,3,0,132,0,0,90, - 4,0,100,4,0,100,5,0,132,0,0,90,5,0,100,6, - 0,100,7,0,132,0,0,90,6,0,100,8,0,100,9,0, - 132,0,0,90,7,0,100,10,0,100,11,0,132,0,0,90, - 8,0,100,12,0,83,40,13,0,0,0,244,11,0,0,0, - 95,77,111,100,117,108,101,76,111,99,107,117,169,0,0,0, - 65,32,114,101,99,117,114,115,105,118,101,32,108,111,99,107, - 32,105,109,112,108,101,109,101,110,116,97,116,105,111,110,32, - 119,104,105,99,104,32,105,115,32,97,98,108,101,32,116,111, - 32,100,101,116,101,99,116,32,100,101,97,100,108,111,99,107, - 115,10,32,32,32,32,40,101,46,103,46,32,116,104,114,101, - 97,100,32,49,32,116,114,121,105,110,103,32,116,111,32,116, - 97,107,101,32,108,111,99,107,115,32,65,32,116,104,101,110, - 32,66,44,32,97,110,100,32,116,104,114,101,97,100,32,50, - 32,116,114,121,105,110,103,32,116,111,10,32,32,32,32,116, - 97,107,101,32,108,111,99,107,115,32,66,32,116,104,101,110, - 32,65,41,46,10,32,32,32,32,99,2,0,0,0,0,0, - 0,0,2,0,0,0,2,0,0,0,67,0,0,0,115,70, - 0,0,0,116,0,0,106,1,0,131,0,0,124,0,0,95, - 2,0,116,0,0,106,1,0,131,0,0,124,0,0,95,3, - 0,124,1,0,124,0,0,95,4,0,100,0,0,124,0,0, - 95,5,0,100,1,0,124,0,0,95,6,0,100,1,0,124, - 0,0,95,7,0,100,0,0,83,40,2,0,0,0,78,233, - 0,0,0,0,40,8,0,0,0,244,7,0,0,0,95,116, - 104,114,101,97,100,116,13,0,0,0,97,108,108,111,99,97, - 116,101,95,108,111,99,107,244,4,0,0,0,108,111,99,107, - 244,6,0,0,0,119,97,107,101,117,112,244,4,0,0,0, - 110,97,109,101,244,5,0,0,0,111,119,110,101,114,244,5, - 0,0,0,99,111,117,110,116,244,7,0,0,0,119,97,105, - 116,101,114,115,40,2,0,0,0,244,4,0,0,0,115,101, - 108,102,114,71,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,5,0,0,0,244,8,0,0,0,95,95,105,110,105, - 116,95,95,142,0,0,0,115,12,0,0,0,0,1,15,1, - 15,1,9,1,9,1,9,1,117,20,0,0,0,95,77,111, - 100,117,108,101,76,111,99,107,46,95,95,105,110,105,116,95, - 95,99,1,0,0,0,0,0,0,0,4,0,0,0,2,0, - 0,0,67,0,0,0,115,87,0,0,0,116,0,0,106,1, - 0,131,0,0,125,1,0,124,0,0,106,2,0,125,2,0, - 120,59,0,116,3,0,106,4,0,124,2,0,131,1,0,125, - 3,0,124,3,0,100,0,0,107,8,0,114,55,0,100,1, - 0,83,124,3,0,106,2,0,125,2,0,124,2,0,124,1, - 0,107,2,0,114,24,0,100,2,0,83,113,24,0,100,0, - 0,83,40,3,0,0,0,78,70,84,40,5,0,0,0,114, - 68,0,0,0,244,9,0,0,0,103,101,116,95,105,100,101, - 110,116,114,72,0,0,0,244,12,0,0,0,95,98,108,111, - 99,107,105,110,103,95,111,110,244,3,0,0,0,103,101,116, - 40,4,0,0,0,114,75,0,0,0,244,2,0,0,0,109, - 101,244,3,0,0,0,116,105,100,114,69,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,244,12,0, - 0,0,104,97,115,95,100,101,97,100,108,111,99,107,150,0, - 0,0,115,18,0,0,0,0,2,12,1,9,1,3,1,15, - 1,12,1,4,1,9,1,12,1,117,24,0,0,0,95,77, - 111,100,117,108,101,76,111,99,107,46,104,97,115,95,100,101, - 97,100,108,111,99,107,99,1,0,0,0,0,0,0,0,2, - 0,0,0,17,0,0,0,67,0,0,0,115,214,0,0,0, - 116,0,0,106,1,0,131,0,0,125,1,0,124,0,0,116, - 2,0,124,1,0,60,122,177,0,120,170,0,124,0,0,106, - 3,0,143,130,0,1,124,0,0,106,4,0,100,1,0,107, - 2,0,115,68,0,124,0,0,106,5,0,124,1,0,107,2, - 0,114,96,0,124,1,0,124,0,0,95,5,0,124,0,0, - 4,106,4,0,100,2,0,55,2,95,4,0,100,3,0,83, - 124,0,0,106,6,0,131,0,0,114,127,0,116,7,0,100, - 4,0,124,0,0,22,131,1,0,130,1,0,110,0,0,124, - 0,0,106,8,0,106,9,0,100,5,0,131,1,0,114,163, - 0,124,0,0,4,106,10,0,100,2,0,55,2,95,10,0, - 110,0,0,87,100,6,0,81,88,124,0,0,106,8,0,106, - 9,0,131,0,0,1,124,0,0,106,8,0,106,11,0,131, - 0,0,1,113,28,0,87,100,6,0,116,2,0,124,1,0, - 61,88,100,6,0,83,40,7,0,0,0,117,185,0,0,0, - 10,32,32,32,32,32,32,32,32,65,99,113,117,105,114,101, - 32,116,104,101,32,109,111,100,117,108,101,32,108,111,99,107, - 46,32,32,73,102,32,97,32,112,111,116,101,110,116,105,97, - 108,32,100,101,97,100,108,111,99,107,32,105,115,32,100,101, - 116,101,99,116,101,100,44,10,32,32,32,32,32,32,32,32, - 97,32,95,68,101,97,100,108,111,99,107,69,114,114,111,114, - 32,105,115,32,114,97,105,115,101,100,46,10,32,32,32,32, - 32,32,32,32,79,116,104,101,114,119,105,115,101,44,32,116, - 104,101,32,108,111,99,107,32,105,115,32,97,108,119,97,121, - 115,32,97,99,113,117,105,114,101,100,32,97,110,100,32,84, - 114,117,101,32,105,115,32,114,101,116,117,114,110,101,100,46, - 10,32,32,32,32,32,32,32,32,114,67,0,0,0,114,29, - 0,0,0,84,117,23,0,0,0,100,101,97,100,108,111,99, - 107,32,100,101,116,101,99,116,101,100,32,98,121,32,37,114, - 70,78,40,12,0,0,0,114,68,0,0,0,114,77,0,0, - 0,114,78,0,0,0,114,69,0,0,0,114,73,0,0,0, - 114,72,0,0,0,114,82,0,0,0,114,65,0,0,0,114, - 70,0,0,0,244,7,0,0,0,97,99,113,117,105,114,101, - 114,74,0,0,0,244,7,0,0,0,114,101,108,101,97,115, - 101,40,2,0,0,0,114,75,0,0,0,114,81,0,0,0, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,114, - 83,0,0,0,162,0,0,0,115,32,0,0,0,0,6,12, - 1,10,1,3,1,3,1,10,1,30,1,9,1,15,1,4, - 1,12,1,19,1,18,1,24,2,13,1,20,2,117,19,0, - 0,0,95,77,111,100,117,108,101,76,111,99,107,46,97,99, - 113,117,105,114,101,99,1,0,0,0,0,0,0,0,2,0, - 0,0,10,0,0,0,67,0,0,0,115,165,0,0,0,116, - 0,0,106,1,0,131,0,0,125,1,0,124,0,0,106,2, - 0,143,138,0,1,124,0,0,106,3,0,124,1,0,107,3, - 0,114,52,0,116,4,0,100,1,0,131,1,0,130,1,0, - 110,0,0,124,0,0,106,5,0,100,2,0,107,4,0,115, - 73,0,116,6,0,130,1,0,124,0,0,4,106,5,0,100, - 3,0,56,2,95,5,0,124,0,0,106,5,0,100,2,0, - 107,2,0,114,155,0,100,0,0,124,0,0,95,3,0,124, - 0,0,106,7,0,114,155,0,124,0,0,4,106,7,0,100, - 3,0,56,2,95,7,0,124,0,0,106,8,0,106,9,0, - 131,0,0,1,113,155,0,110,0,0,87,100,0,0,81,88, - 100,0,0,83,40,4,0,0,0,78,117,31,0,0,0,99, - 97,110,110,111,116,32,114,101,108,101,97,115,101,32,117,110, - 45,97,99,113,117,105,114,101,100,32,108,111,99,107,114,67, - 0,0,0,114,29,0,0,0,40,10,0,0,0,114,68,0, - 0,0,114,77,0,0,0,114,69,0,0,0,114,72,0,0, - 0,244,12,0,0,0,82,117,110,116,105,109,101,69,114,114, - 111,114,114,73,0,0,0,244,14,0,0,0,65,115,115,101, - 114,116,105,111,110,69,114,114,111,114,114,74,0,0,0,114, - 70,0,0,0,114,84,0,0,0,40,2,0,0,0,114,75, - 0,0,0,114,81,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,114,84,0,0,0,187,0,0,0, - 115,22,0,0,0,0,1,12,1,10,1,15,1,15,1,21, - 1,15,1,15,1,9,1,9,1,15,1,117,19,0,0,0, - 95,77,111,100,117,108,101,76,111,99,107,46,114,101,108,101, - 97,115,101,99,1,0,0,0,0,0,0,0,1,0,0,0, - 4,0,0,0,67,0,0,0,115,25,0,0,0,100,1,0, - 106,0,0,124,0,0,106,1,0,116,2,0,124,0,0,131, - 1,0,131,2,0,83,40,2,0,0,0,78,117,23,0,0, - 0,95,77,111,100,117,108,101,76,111,99,107,40,123,33,114, - 125,41,32,97,116,32,123,125,40,3,0,0,0,114,46,0, - 0,0,114,71,0,0,0,114,47,0,0,0,40,1,0,0, - 0,114,75,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,244,8,0,0,0,95,95,114,101,112,114, - 95,95,200,0,0,0,115,2,0,0,0,0,1,117,20,0, - 0,0,95,77,111,100,117,108,101,76,111,99,107,46,95,95, - 114,101,112,114,95,95,78,40,9,0,0,0,114,56,0,0, - 0,114,55,0,0,0,114,57,0,0,0,114,58,0,0,0, - 114,76,0,0,0,114,82,0,0,0,114,83,0,0,0,114, - 84,0,0,0,114,87,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,114,66,0, - 0,0,136,0,0,0,115,12,0,0,0,12,4,6,2,12, - 8,12,12,12,25,12,13,114,66,0,0,0,99,0,0,0, - 0,0,0,0,0,0,0,0,0,2,0,0,0,64,0,0, - 0,115,70,0,0,0,101,0,0,90,1,0,100,0,0,90, - 2,0,100,1,0,90,3,0,100,2,0,100,3,0,132,0, - 0,90,4,0,100,4,0,100,5,0,132,0,0,90,5,0, - 100,6,0,100,7,0,132,0,0,90,6,0,100,8,0,100, - 9,0,132,0,0,90,7,0,100,10,0,83,40,11,0,0, - 0,244,16,0,0,0,95,68,117,109,109,121,77,111,100,117, - 108,101,76,111,99,107,117,86,0,0,0,65,32,115,105,109, - 112,108,101,32,95,77,111,100,117,108,101,76,111,99,107,32, - 101,113,117,105,118,97,108,101,110,116,32,102,111,114,32,80, - 121,116,104,111,110,32,98,117,105,108,100,115,32,119,105,116, - 104,111,117,116,10,32,32,32,32,109,117,108,116,105,45,116, - 104,114,101,97,100,105,110,103,32,115,117,112,112,111,114,116, - 46,99,2,0,0,0,0,0,0,0,2,0,0,0,2,0, - 0,0,67,0,0,0,115,22,0,0,0,124,1,0,124,0, - 0,95,0,0,100,1,0,124,0,0,95,1,0,100,0,0, - 83,40,2,0,0,0,78,114,67,0,0,0,40,2,0,0, - 0,114,71,0,0,0,114,73,0,0,0,40,2,0,0,0, - 114,75,0,0,0,114,71,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,114,76,0,0,0,208,0, - 0,0,115,4,0,0,0,0,1,9,1,117,25,0,0,0, - 95,68,117,109,109,121,77,111,100,117,108,101,76,111,99,107, - 46,95,95,105,110,105,116,95,95,99,1,0,0,0,0,0, - 0,0,1,0,0,0,3,0,0,0,67,0,0,0,115,19, - 0,0,0,124,0,0,4,106,0,0,100,1,0,55,2,95, - 0,0,100,2,0,83,40,3,0,0,0,78,114,29,0,0, - 0,84,40,1,0,0,0,114,73,0,0,0,40,1,0,0, - 0,114,75,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,83,0,0,0,212,0,0,0,115,4, - 0,0,0,0,1,15,1,117,24,0,0,0,95,68,117,109, - 109,121,77,111,100,117,108,101,76,111,99,107,46,97,99,113, - 117,105,114,101,99,1,0,0,0,0,0,0,0,1,0,0, - 0,3,0,0,0,67,0,0,0,115,49,0,0,0,124,0, - 0,106,0,0,100,1,0,107,2,0,114,30,0,116,1,0, - 100,2,0,131,1,0,130,1,0,110,0,0,124,0,0,4, - 106,0,0,100,3,0,56,2,95,0,0,100,0,0,83,40, - 4,0,0,0,78,114,67,0,0,0,117,31,0,0,0,99, - 97,110,110,111,116,32,114,101,108,101,97,115,101,32,117,110, - 45,97,99,113,117,105,114,101,100,32,108,111,99,107,114,29, - 0,0,0,40,2,0,0,0,114,73,0,0,0,114,85,0, - 0,0,40,1,0,0,0,114,75,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,114,84,0,0,0, - 216,0,0,0,115,6,0,0,0,0,1,15,1,15,1,117, - 24,0,0,0,95,68,117,109,109,121,77,111,100,117,108,101, - 76,111,99,107,46,114,101,108,101,97,115,101,99,1,0,0, - 0,0,0,0,0,1,0,0,0,4,0,0,0,67,0,0, - 0,115,25,0,0,0,100,1,0,106,0,0,124,0,0,106, - 1,0,116,2,0,124,0,0,131,1,0,131,2,0,83,40, - 2,0,0,0,78,117,28,0,0,0,95,68,117,109,109,121, - 77,111,100,117,108,101,76,111,99,107,40,123,33,114,125,41, - 32,97,116,32,123,125,40,3,0,0,0,114,46,0,0,0, - 114,71,0,0,0,114,47,0,0,0,40,1,0,0,0,114, - 75,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,114,87,0,0,0,221,0,0,0,115,2,0,0, - 0,0,1,117,25,0,0,0,95,68,117,109,109,121,77,111, - 100,117,108,101,76,111,99,107,46,95,95,114,101,112,114,95, - 95,78,40,8,0,0,0,114,56,0,0,0,114,55,0,0, - 0,114,57,0,0,0,114,58,0,0,0,114,76,0,0,0, - 114,83,0,0,0,114,84,0,0,0,114,87,0,0,0,114, - 4,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,114,88,0,0,0,204,0,0,0,115,10,0,0, - 0,12,2,6,2,12,4,12,4,12,5,114,88,0,0,0, - 99,1,0,0,0,0,0,0,0,3,0,0,0,11,0,0, - 0,3,0,0,0,115,142,0,0,0,100,1,0,125,1,0, - 121,17,0,116,0,0,136,0,0,25,131,0,0,125,1,0, - 87,110,18,0,4,116,1,0,107,10,0,114,43,0,1,1, - 1,89,110,1,0,88,124,1,0,100,1,0,107,8,0,114, - 138,0,116,2,0,100,1,0,107,8,0,114,83,0,116,3, - 0,136,0,0,131,1,0,125,1,0,110,12,0,116,4,0, - 136,0,0,131,1,0,125,1,0,135,0,0,102,1,0,100, - 2,0,100,3,0,134,0,0,125,2,0,116,5,0,106,6, - 0,124,1,0,124,2,0,131,2,0,116,0,0,136,0,0, - 60,110,0,0,124,1,0,83,40,4,0,0,0,117,109,0, - 0,0,71,101,116,32,111,114,32,99,114,101,97,116,101,32, - 116,104,101,32,109,111,100,117,108,101,32,108,111,99,107,32, - 102,111,114,32,97,32,103,105,118,101,110,32,109,111,100,117, - 108,101,32,110,97,109,101,46,10,10,32,32,32,32,83,104, - 111,117,108,100,32,111,110,108,121,32,98,101,32,99,97,108, - 108,101,100,32,119,105,116,104,32,116,104,101,32,105,109,112, - 111,114,116,32,108,111,99,107,32,116,97,107,101,110,46,78, - 99,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0, - 0,19,0,0,0,115,11,0,0,0,116,0,0,136,0,0, - 61,100,0,0,83,40,1,0,0,0,78,40,1,0,0,0, - 244,13,0,0,0,95,109,111,100,117,108,101,95,108,111,99, - 107,115,40,1,0,0,0,114,36,0,0,0,40,1,0,0, - 0,114,71,0,0,0,114,4,0,0,0,114,5,0,0,0, - 244,2,0,0,0,99,98,241,0,0,0,115,2,0,0,0, - 0,1,117,28,0,0,0,95,103,101,116,95,109,111,100,117, - 108,101,95,108,111,99,107,46,60,108,111,99,97,108,115,62, - 46,99,98,40,7,0,0,0,114,89,0,0,0,244,8,0, - 0,0,75,101,121,69,114,114,111,114,114,68,0,0,0,114, - 88,0,0,0,114,66,0,0,0,244,8,0,0,0,95,119, - 101,97,107,114,101,102,116,3,0,0,0,114,101,102,40,3, - 0,0,0,114,71,0,0,0,114,69,0,0,0,114,90,0, - 0,0,114,4,0,0,0,40,1,0,0,0,114,71,0,0, - 0,114,5,0,0,0,244,16,0,0,0,95,103,101,116,95, - 109,111,100,117,108,101,95,108,111,99,107,227,0,0,0,115, - 24,0,0,0,0,4,6,1,3,1,17,1,13,1,5,1, - 12,1,12,1,15,2,12,1,18,2,25,1,114,93,0,0, - 0,99,1,0,0,0,0,0,0,0,2,0,0,0,11,0, - 0,0,67,0,0,0,115,71,0,0,0,116,0,0,124,0, - 0,131,1,0,125,1,0,116,1,0,106,2,0,131,0,0, - 1,121,14,0,124,1,0,106,3,0,131,0,0,1,87,110, - 18,0,4,116,4,0,107,10,0,114,56,0,1,1,1,89, - 110,11,0,88,124,1,0,106,5,0,131,0,0,1,100,1, - 0,83,40,2,0,0,0,117,21,1,0,0,82,101,108,101, - 97,115,101,32,116,104,101,32,103,108,111,98,97,108,32,105, - 109,112,111,114,116,32,108,111,99,107,44,32,97,110,100,32, - 97,99,113,117,105,114,101,115,32,116,104,101,110,32,114,101, - 108,101,97,115,101,32,116,104,101,10,32,32,32,32,109,111, - 100,117,108,101,32,108,111,99,107,32,102,111,114,32,97,32, - 103,105,118,101,110,32,109,111,100,117,108,101,32,110,97,109, - 101,46,10,32,32,32,32,84,104,105,115,32,105,115,32,117, - 115,101,100,32,116,111,32,101,110,115,117,114,101,32,97,32, - 109,111,100,117,108,101,32,105,115,32,99,111,109,112,108,101, - 116,101,108,121,32,105,110,105,116,105,97,108,105,122,101,100, - 44,32,105,110,32,116,104,101,10,32,32,32,32,101,118,101, - 110,116,32,105,116,32,105,115,32,98,101,105,110,103,32,105, - 109,112,111,114,116,101,100,32,98,121,32,97,110,111,116,104, - 101,114,32,116,104,114,101,97,100,46,10,10,32,32,32,32, - 83,104,111,117,108,100,32,111,110,108,121,32,98,101,32,99, - 97,108,108,101,100,32,119,105,116,104,32,116,104,101,32,105, - 109,112,111,114,116,32,108,111,99,107,32,116,97,107,101,110, - 46,78,40,6,0,0,0,114,93,0,0,0,244,4,0,0, - 0,95,105,109,112,244,12,0,0,0,114,101,108,101,97,115, - 101,95,108,111,99,107,114,83,0,0,0,114,65,0,0,0, - 114,84,0,0,0,40,2,0,0,0,114,71,0,0,0,114, - 69,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,244,19,0,0,0,95,108,111,99,107,95,117,110, - 108,111,99,107,95,109,111,100,117,108,101,246,0,0,0,115, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 12,0,0,0,95,112,97,116,104,95,105,115,102,105,108,101, + 108,0,0,0,115,2,0,0,0,0,2,117,12,0,0,0, + 95,112,97,116,104,95,105,115,102,105,108,101,99,1,0,0, + 0,0,0,0,0,1,0,0,0,3,0,0,0,67,0,0, + 0,115,34,0,0,0,124,0,0,115,21,0,116,0,0,106, + 1,0,131,0,0,125,0,0,110,0,0,116,2,0,124,0, + 0,100,1,0,131,2,0,83,40,2,0,0,0,117,30,0, + 0,0,82,101,112,108,97,99,101,109,101,110,116,32,102,111, + 114,32,111,115,46,112,97,116,104,46,105,115,100,105,114,46, + 105,0,64,0,0,40,3,0,0,0,117,3,0,0,0,95, + 111,115,117,6,0,0,0,103,101,116,99,119,100,117,18,0, + 0,0,95,112,97,116,104,95,105,115,95,109,111,100,101,95, + 116,121,112,101,40,1,0,0,0,117,4,0,0,0,112,97, + 116,104,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,11, + 0,0,0,95,112,97,116,104,95,105,115,100,105,114,114,0, + 0,0,115,6,0,0,0,0,2,6,1,15,1,117,11,0, + 0,0,95,112,97,116,104,95,105,115,100,105,114,105,182,1, + 0,0,99,3,0,0,0,0,0,0,0,6,0,0,0,17, + 0,0,0,67,0,0,0,115,192,0,0,0,100,1,0,106, + 0,0,124,0,0,116,1,0,124,0,0,131,1,0,131,2, + 0,125,3,0,116,2,0,106,3,0,124,3,0,116,2,0, + 106,4,0,116,2,0,106,5,0,66,116,2,0,106,6,0, + 66,124,2,0,100,2,0,64,131,3,0,125,4,0,121,60, + 0,116,7,0,106,8,0,124,4,0,100,3,0,131,2,0, + 143,20,0,125,5,0,124,5,0,106,9,0,124,1,0,131, + 1,0,1,87,100,4,0,81,88,116,2,0,106,10,0,124, + 3,0,124,0,0,131,2,0,1,87,110,59,0,4,116,11, + 0,107,10,0,114,187,0,1,1,1,121,17,0,116,2,0, + 106,12,0,124,3,0,131,1,0,1,87,110,18,0,4,116, + 11,0,107,10,0,114,179,0,1,1,1,89,110,1,0,88, + 130,0,0,89,110,1,0,88,100,4,0,83,40,5,0,0, + 0,117,162,0,0,0,66,101,115,116,45,101,102,102,111,114, + 116,32,102,117,110,99,116,105,111,110,32,116,111,32,119,114, + 105,116,101,32,100,97,116,97,32,116,111,32,97,32,112,97, + 116,104,32,97,116,111,109,105,99,97,108,108,121,46,10,32, + 32,32,32,66,101,32,112,114,101,112,97,114,101,100,32,116, + 111,32,104,97,110,100,108,101,32,97,32,70,105,108,101,69, + 120,105,115,116,115,69,114,114,111,114,32,105,102,32,99,111, + 110,99,117,114,114,101,110,116,32,119,114,105,116,105,110,103, + 32,111,102,32,116,104,101,10,32,32,32,32,116,101,109,112, + 111,114,97,114,121,32,102,105,108,101,32,105,115,32,97,116, + 116,101,109,112,116,101,100,46,117,5,0,0,0,123,125,46, + 123,125,105,182,1,0,0,117,2,0,0,0,119,98,78,40, + 13,0,0,0,117,6,0,0,0,102,111,114,109,97,116,117, + 2,0,0,0,105,100,117,3,0,0,0,95,111,115,117,4, + 0,0,0,111,112,101,110,117,6,0,0,0,79,95,69,88, + 67,76,117,7,0,0,0,79,95,67,82,69,65,84,117,8, + 0,0,0,79,95,87,82,79,78,76,89,117,3,0,0,0, + 95,105,111,117,6,0,0,0,70,105,108,101,73,79,117,5, + 0,0,0,119,114,105,116,101,117,7,0,0,0,114,101,112, + 108,97,99,101,117,7,0,0,0,79,83,69,114,114,111,114, + 117,6,0,0,0,117,110,108,105,110,107,40,6,0,0,0, + 117,4,0,0,0,112,97,116,104,117,4,0,0,0,100,97, + 116,97,117,4,0,0,0,109,111,100,101,117,8,0,0,0, + 112,97,116,104,95,116,109,112,117,2,0,0,0,102,100,117, + 4,0,0,0,102,105,108,101,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,13,0,0,0,95,119,114,105,116,101,95, + 97,116,111,109,105,99,121,0,0,0,115,26,0,0,0,0, + 5,24,1,9,1,33,1,3,3,21,1,19,1,20,1,13, + 1,3,1,17,1,13,1,5,1,117,13,0,0,0,95,119, + 114,105,116,101,95,97,116,111,109,105,99,99,2,0,0,0, + 0,0,0,0,3,0,0,0,7,0,0,0,67,0,0,0, + 115,95,0,0,0,120,69,0,100,1,0,100,2,0,100,3, + 0,100,4,0,103,4,0,68,93,49,0,125,2,0,116,0, + 0,124,1,0,124,2,0,131,2,0,114,19,0,116,1,0, + 124,0,0,124,2,0,116,2,0,124,1,0,124,2,0,131, + 2,0,131,3,0,1,113,19,0,113,19,0,87,124,0,0, + 106,3,0,106,4,0,124,1,0,106,3,0,131,1,0,1, + 100,5,0,83,40,6,0,0,0,117,47,0,0,0,83,105, + 109,112,108,101,32,115,117,98,115,116,105,116,117,116,101,32, + 102,111,114,32,102,117,110,99,116,111,111,108,115,46,117,112, + 100,97,116,101,95,119,114,97,112,112,101,114,46,117,10,0, + 0,0,95,95,109,111,100,117,108,101,95,95,117,8,0,0, + 0,95,95,110,97,109,101,95,95,117,12,0,0,0,95,95, + 113,117,97,108,110,97,109,101,95,95,117,7,0,0,0,95, + 95,100,111,99,95,95,78,40,5,0,0,0,117,7,0,0, + 0,104,97,115,97,116,116,114,117,7,0,0,0,115,101,116, + 97,116,116,114,117,7,0,0,0,103,101,116,97,116,116,114, + 117,8,0,0,0,95,95,100,105,99,116,95,95,117,6,0, + 0,0,117,112,100,97,116,101,40,3,0,0,0,117,3,0, + 0,0,110,101,119,117,3,0,0,0,111,108,100,117,7,0, + 0,0,114,101,112,108,97,99,101,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,5,0,0,0,95,119,114,97,112,143, + 0,0,0,115,8,0,0,0,0,2,25,1,15,1,32,1, + 117,5,0,0,0,95,119,114,97,112,99,1,0,0,0,0, + 0,0,0,1,0,0,0,2,0,0,0,67,0,0,0,115, + 16,0,0,0,116,0,0,116,1,0,131,1,0,124,0,0, + 131,1,0,83,40,1,0,0,0,117,75,0,0,0,67,114, + 101,97,116,101,32,97,32,110,101,119,32,109,111,100,117,108, + 101,46,10,10,32,32,32,32,84,104,101,32,109,111,100,117, + 108,101,32,105,115,32,110,111,116,32,101,110,116,101,114,101, + 100,32,105,110,116,111,32,115,121,115,46,109,111,100,117,108, + 101,115,46,10,10,32,32,32,32,40,2,0,0,0,117,4, + 0,0,0,116,121,112,101,117,3,0,0,0,95,105,111,40, + 1,0,0,0,117,4,0,0,0,110,97,109,101,40,0,0, + 0,0,40,0,0,0,0,117,29,0,0,0,60,102,114,111, + 122,101,110,32,105,109,112,111,114,116,108,105,98,46,95,98, + 111,111,116,115,116,114,97,112,62,117,10,0,0,0,110,101, + 119,95,109,111,100,117,108,101,154,0,0,0,115,2,0,0, + 0,0,6,117,10,0,0,0,110,101,119,95,109,111,100,117, + 108,101,99,1,0,0,0,0,0,0,0,1,0,0,0,1, + 0,0,0,66,0,0,0,115,20,0,0,0,124,0,0,69, + 101,0,0,90,1,0,100,0,0,90,2,0,100,1,0,83, + 40,2,0,0,0,117,14,0,0,0,95,68,101,97,100,108, + 111,99,107,69,114,114,111,114,78,40,3,0,0,0,117,8, + 0,0,0,95,95,110,97,109,101,95,95,117,10,0,0,0, + 95,95,109,111,100,117,108,101,95,95,117,12,0,0,0,95, + 95,113,117,97,108,110,97,109,101,95,95,40,1,0,0,0, + 117,10,0,0,0,95,95,108,111,99,97,108,115,95,95,40, + 0,0,0,0,40,0,0,0,0,117,29,0,0,0,60,102, + 114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46, + 95,98,111,111,116,115,116,114,97,112,62,117,14,0,0,0, + 95,68,101,97,100,108,111,99,107,69,114,114,111,114,171,0, + 0,0,115,2,0,0,0,16,1,117,14,0,0,0,95,68, + 101,97,100,108,111,99,107,69,114,114,111,114,99,1,0,0, + 0,0,0,0,0,1,0,0,0,2,0,0,0,66,0,0, + 0,115,86,0,0,0,124,0,0,69,101,0,0,90,1,0, + 100,0,0,90,2,0,100,1,0,90,3,0,100,2,0,100, + 3,0,132,0,0,90,4,0,100,4,0,100,5,0,132,0, + 0,90,5,0,100,6,0,100,7,0,132,0,0,90,6,0, + 100,8,0,100,9,0,132,0,0,90,7,0,100,10,0,100, + 11,0,132,0,0,90,8,0,100,12,0,83,40,13,0,0, + 0,117,11,0,0,0,95,77,111,100,117,108,101,76,111,99, + 107,117,169,0,0,0,65,32,114,101,99,117,114,115,105,118, + 101,32,108,111,99,107,32,105,109,112,108,101,109,101,110,116, + 97,116,105,111,110,32,119,104,105,99,104,32,105,115,32,97, + 98,108,101,32,116,111,32,100,101,116,101,99,116,32,100,101, + 97,100,108,111,99,107,115,10,32,32,32,32,40,101,46,103, + 46,32,116,104,114,101,97,100,32,49,32,116,114,121,105,110, + 103,32,116,111,32,116,97,107,101,32,108,111,99,107,115,32, + 65,32,116,104,101,110,32,66,44,32,97,110,100,32,116,104, + 114,101,97,100,32,50,32,116,114,121,105,110,103,32,116,111, + 10,32,32,32,32,116,97,107,101,32,108,111,99,107,115,32, + 66,32,116,104,101,110,32,65,41,46,10,32,32,32,32,99, + 2,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0, + 67,0,0,0,115,70,0,0,0,116,0,0,106,1,0,131, + 0,0,124,0,0,95,2,0,116,0,0,106,1,0,131,0, + 0,124,0,0,95,3,0,124,1,0,124,0,0,95,4,0, + 100,0,0,124,0,0,95,5,0,100,1,0,124,0,0,95, + 6,0,100,1,0,124,0,0,95,7,0,100,0,0,83,40, + 2,0,0,0,78,105,0,0,0,0,40,8,0,0,0,117, + 7,0,0,0,95,116,104,114,101,97,100,117,13,0,0,0, + 97,108,108,111,99,97,116,101,95,108,111,99,107,117,4,0, + 0,0,108,111,99,107,117,6,0,0,0,119,97,107,101,117, + 112,117,4,0,0,0,110,97,109,101,117,5,0,0,0,111, + 119,110,101,114,117,5,0,0,0,99,111,117,110,116,117,7, + 0,0,0,119,97,105,116,101,114,115,40,2,0,0,0,117, + 4,0,0,0,115,101,108,102,117,4,0,0,0,110,97,109, + 101,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,8,0, + 0,0,95,95,105,110,105,116,95,95,181,0,0,0,115,12, + 0,0,0,0,1,15,1,15,1,9,1,9,1,9,1,117, + 20,0,0,0,95,77,111,100,117,108,101,76,111,99,107,46, + 95,95,105,110,105,116,95,95,99,1,0,0,0,0,0,0, + 0,4,0,0,0,2,0,0,0,67,0,0,0,115,87,0, + 0,0,116,0,0,106,1,0,131,0,0,125,1,0,124,0, + 0,106,2,0,125,2,0,120,59,0,116,3,0,106,4,0, + 124,2,0,131,1,0,125,3,0,124,3,0,100,0,0,107, + 8,0,114,55,0,100,1,0,83,124,3,0,106,2,0,125, + 2,0,124,2,0,124,1,0,107,2,0,114,24,0,100,2, + 0,83,113,24,0,100,0,0,83,40,3,0,0,0,78,70, + 84,40,5,0,0,0,117,7,0,0,0,95,116,104,114,101, + 97,100,117,9,0,0,0,103,101,116,95,105,100,101,110,116, + 117,5,0,0,0,111,119,110,101,114,117,12,0,0,0,95, + 98,108,111,99,107,105,110,103,95,111,110,117,3,0,0,0, + 103,101,116,40,4,0,0,0,117,4,0,0,0,115,101,108, + 102,117,2,0,0,0,109,101,117,3,0,0,0,116,105,100, + 117,4,0,0,0,108,111,99,107,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,12,0,0,0,104,97,115,95,100,101, + 97,100,108,111,99,107,189,0,0,0,115,18,0,0,0,0, + 2,12,1,9,1,3,1,15,1,12,1,4,1,9,1,12, + 1,117,24,0,0,0,95,77,111,100,117,108,101,76,111,99, + 107,46,104,97,115,95,100,101,97,100,108,111,99,107,99,1, + 0,0,0,0,0,0,0,2,0,0,0,17,0,0,0,67, + 0,0,0,115,214,0,0,0,116,0,0,106,1,0,131,0, + 0,125,1,0,124,0,0,116,2,0,124,1,0,60,122,177, + 0,120,170,0,124,0,0,106,3,0,143,130,0,1,124,0, + 0,106,4,0,100,1,0,107,2,0,115,68,0,124,0,0, + 106,5,0,124,1,0,107,2,0,114,96,0,124,1,0,124, + 0,0,95,5,0,124,0,0,4,106,4,0,100,2,0,55, + 2,95,4,0,100,3,0,83,124,0,0,106,6,0,131,0, + 0,114,127,0,116,7,0,100,4,0,124,0,0,22,131,1, + 0,130,1,0,110,0,0,124,0,0,106,8,0,106,9,0, + 100,5,0,131,1,0,114,163,0,124,0,0,4,106,10,0, + 100,2,0,55,2,95,10,0,110,0,0,87,100,6,0,81, + 88,124,0,0,106,8,0,106,9,0,131,0,0,1,124,0, + 0,106,8,0,106,11,0,131,0,0,1,113,28,0,87,100, + 6,0,116,2,0,124,1,0,61,88,100,6,0,83,40,7, + 0,0,0,117,185,0,0,0,10,32,32,32,32,32,32,32, + 32,65,99,113,117,105,114,101,32,116,104,101,32,109,111,100, + 117,108,101,32,108,111,99,107,46,32,32,73,102,32,97,32, + 112,111,116,101,110,116,105,97,108,32,100,101,97,100,108,111, + 99,107,32,105,115,32,100,101,116,101,99,116,101,100,44,10, + 32,32,32,32,32,32,32,32,97,32,95,68,101,97,100,108, + 111,99,107,69,114,114,111,114,32,105,115,32,114,97,105,115, + 101,100,46,10,32,32,32,32,32,32,32,32,79,116,104,101, + 114,119,105,115,101,44,32,116,104,101,32,108,111,99,107,32, + 105,115,32,97,108,119,97,121,115,32,97,99,113,117,105,114, + 101,100,32,97,110,100,32,84,114,117,101,32,105,115,32,114, + 101,116,117,114,110,101,100,46,10,32,32,32,32,32,32,32, + 32,105,0,0,0,0,105,1,0,0,0,84,117,23,0,0, + 0,100,101,97,100,108,111,99,107,32,100,101,116,101,99,116, + 101,100,32,98,121,32,37,114,70,78,40,12,0,0,0,117, + 7,0,0,0,95,116,104,114,101,97,100,117,9,0,0,0, + 103,101,116,95,105,100,101,110,116,117,12,0,0,0,95,98, + 108,111,99,107,105,110,103,95,111,110,117,4,0,0,0,108, + 111,99,107,117,5,0,0,0,99,111,117,110,116,117,5,0, + 0,0,111,119,110,101,114,117,12,0,0,0,104,97,115,95, + 100,101,97,100,108,111,99,107,117,14,0,0,0,95,68,101, + 97,100,108,111,99,107,69,114,114,111,114,117,6,0,0,0, + 119,97,107,101,117,112,117,7,0,0,0,97,99,113,117,105, + 114,101,117,7,0,0,0,119,97,105,116,101,114,115,117,7, + 0,0,0,114,101,108,101,97,115,101,40,2,0,0,0,117, + 4,0,0,0,115,101,108,102,117,3,0,0,0,116,105,100, + 40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,7,0,0, + 0,97,99,113,117,105,114,101,201,0,0,0,115,32,0,0, + 0,0,6,12,1,10,1,3,1,3,1,10,1,30,1,9, + 1,15,1,4,1,12,1,19,1,18,1,24,2,13,1,20, + 2,117,19,0,0,0,95,77,111,100,117,108,101,76,111,99, + 107,46,97,99,113,117,105,114,101,99,1,0,0,0,0,0, + 0,0,2,0,0,0,10,0,0,0,67,0,0,0,115,165, + 0,0,0,116,0,0,106,1,0,131,0,0,125,1,0,124, + 0,0,106,2,0,143,138,0,1,124,0,0,106,3,0,124, + 1,0,107,3,0,114,52,0,116,4,0,100,1,0,131,1, + 0,130,1,0,110,0,0,124,0,0,106,5,0,100,2,0, + 107,4,0,115,73,0,116,6,0,130,1,0,124,0,0,4, + 106,5,0,100,3,0,56,2,95,5,0,124,0,0,106,5, + 0,100,2,0,107,2,0,114,155,0,100,0,0,124,0,0, + 95,3,0,124,0,0,106,7,0,114,155,0,124,0,0,4, + 106,7,0,100,3,0,56,2,95,7,0,124,0,0,106,8, + 0,106,9,0,131,0,0,1,113,155,0,110,0,0,87,100, + 0,0,81,88,100,0,0,83,40,4,0,0,0,78,117,31, + 0,0,0,99,97,110,110,111,116,32,114,101,108,101,97,115, + 101,32,117,110,45,97,99,113,117,105,114,101,100,32,108,111, + 99,107,105,0,0,0,0,105,1,0,0,0,40,10,0,0, + 0,117,7,0,0,0,95,116,104,114,101,97,100,117,9,0, + 0,0,103,101,116,95,105,100,101,110,116,117,4,0,0,0, + 108,111,99,107,117,5,0,0,0,111,119,110,101,114,117,12, + 0,0,0,82,117,110,116,105,109,101,69,114,114,111,114,117, + 5,0,0,0,99,111,117,110,116,117,14,0,0,0,65,115, + 115,101,114,116,105,111,110,69,114,114,111,114,117,7,0,0, + 0,119,97,105,116,101,114,115,117,6,0,0,0,119,97,107, + 101,117,112,117,7,0,0,0,114,101,108,101,97,115,101,40, + 2,0,0,0,117,4,0,0,0,115,101,108,102,117,3,0, + 0,0,116,105,100,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,7,0,0,0,114,101,108,101,97,115,101,226,0,0, + 0,115,22,0,0,0,0,1,12,1,10,1,15,1,15,1, + 21,1,15,1,15,1,9,1,9,1,15,1,117,19,0,0, + 0,95,77,111,100,117,108,101,76,111,99,107,46,114,101,108, + 101,97,115,101,99,1,0,0,0,0,0,0,0,1,0,0, + 0,4,0,0,0,67,0,0,0,115,25,0,0,0,100,1, + 0,106,0,0,124,0,0,106,1,0,116,2,0,124,0,0, + 131,1,0,131,2,0,83,40,2,0,0,0,78,117,23,0, + 0,0,95,77,111,100,117,108,101,76,111,99,107,40,123,33, + 114,125,41,32,97,116,32,123,125,40,3,0,0,0,117,6, + 0,0,0,102,111,114,109,97,116,117,4,0,0,0,110,97, + 109,101,117,2,0,0,0,105,100,40,1,0,0,0,117,4, + 0,0,0,115,101,108,102,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,8,0,0,0,95,95,114,101,112,114,95,95, + 239,0,0,0,115,2,0,0,0,0,1,117,20,0,0,0, + 95,77,111,100,117,108,101,76,111,99,107,46,95,95,114,101, + 112,114,95,95,78,40,9,0,0,0,117,8,0,0,0,95, + 95,110,97,109,101,95,95,117,10,0,0,0,95,95,109,111, + 100,117,108,101,95,95,117,12,0,0,0,95,95,113,117,97, + 108,110,97,109,101,95,95,117,7,0,0,0,95,95,100,111, + 99,95,95,117,8,0,0,0,95,95,105,110,105,116,95,95, + 117,12,0,0,0,104,97,115,95,100,101,97,100,108,111,99, + 107,117,7,0,0,0,97,99,113,117,105,114,101,117,7,0, + 0,0,114,101,108,101,97,115,101,117,8,0,0,0,95,95, + 114,101,112,114,95,95,40,1,0,0,0,117,10,0,0,0, + 95,95,108,111,99,97,108,115,95,95,40,0,0,0,0,40, + 0,0,0,0,117,29,0,0,0,60,102,114,111,122,101,110, + 32,105,109,112,111,114,116,108,105,98,46,95,98,111,111,116, + 115,116,114,97,112,62,117,11,0,0,0,95,77,111,100,117, + 108,101,76,111,99,107,175,0,0,0,115,12,0,0,0,16, + 4,6,2,12,8,12,12,12,25,12,13,117,11,0,0,0, + 95,77,111,100,117,108,101,76,111,99,107,99,1,0,0,0, + 0,0,0,0,1,0,0,0,2,0,0,0,66,0,0,0, + 115,74,0,0,0,124,0,0,69,101,0,0,90,1,0,100, + 0,0,90,2,0,100,1,0,90,3,0,100,2,0,100,3, + 0,132,0,0,90,4,0,100,4,0,100,5,0,132,0,0, + 90,5,0,100,6,0,100,7,0,132,0,0,90,6,0,100, + 8,0,100,9,0,132,0,0,90,7,0,100,10,0,83,40, + 11,0,0,0,117,16,0,0,0,95,68,117,109,109,121,77, + 111,100,117,108,101,76,111,99,107,117,86,0,0,0,65,32, + 115,105,109,112,108,101,32,95,77,111,100,117,108,101,76,111, + 99,107,32,101,113,117,105,118,97,108,101,110,116,32,102,111, + 114,32,80,121,116,104,111,110,32,98,117,105,108,100,115,32, + 119,105,116,104,111,117,116,10,32,32,32,32,109,117,108,116, + 105,45,116,104,114,101,97,100,105,110,103,32,115,117,112,112, + 111,114,116,46,99,2,0,0,0,0,0,0,0,2,0,0, + 0,2,0,0,0,67,0,0,0,115,22,0,0,0,124,1, + 0,124,0,0,95,0,0,100,1,0,124,0,0,95,1,0, + 100,0,0,83,40,2,0,0,0,78,105,0,0,0,0,40, + 2,0,0,0,117,4,0,0,0,110,97,109,101,117,5,0, + 0,0,99,111,117,110,116,40,2,0,0,0,117,4,0,0, + 0,115,101,108,102,117,4,0,0,0,110,97,109,101,40,0, + 0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,8,0,0,0,95, + 95,105,110,105,116,95,95,247,0,0,0,115,4,0,0,0, + 0,1,9,1,117,25,0,0,0,95,68,117,109,109,121,77, + 111,100,117,108,101,76,111,99,107,46,95,95,105,110,105,116, + 95,95,99,1,0,0,0,0,0,0,0,1,0,0,0,3, + 0,0,0,67,0,0,0,115,19,0,0,0,124,0,0,4, + 106,0,0,100,1,0,55,2,95,0,0,100,2,0,83,40, + 3,0,0,0,78,105,1,0,0,0,84,40,1,0,0,0, + 117,5,0,0,0,99,111,117,110,116,40,1,0,0,0,117, + 4,0,0,0,115,101,108,102,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,7,0,0,0,97,99,113,117,105,114,101, + 251,0,0,0,115,4,0,0,0,0,1,15,1,117,24,0, + 0,0,95,68,117,109,109,121,77,111,100,117,108,101,76,111, + 99,107,46,97,99,113,117,105,114,101,99,1,0,0,0,0, + 0,0,0,1,0,0,0,3,0,0,0,67,0,0,0,115, + 49,0,0,0,124,0,0,106,0,0,100,1,0,107,2,0, + 114,30,0,116,1,0,100,2,0,131,1,0,130,1,0,110, + 0,0,124,0,0,4,106,0,0,100,3,0,56,2,95,0, + 0,100,0,0,83,40,4,0,0,0,78,105,0,0,0,0, + 117,31,0,0,0,99,97,110,110,111,116,32,114,101,108,101, + 97,115,101,32,117,110,45,97,99,113,117,105,114,101,100,32, + 108,111,99,107,105,1,0,0,0,40,2,0,0,0,117,5, + 0,0,0,99,111,117,110,116,117,12,0,0,0,82,117,110, + 116,105,109,101,69,114,114,111,114,40,1,0,0,0,117,4, + 0,0,0,115,101,108,102,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,7,0,0,0,114,101,108,101,97,115,101,255, + 0,0,0,115,6,0,0,0,0,1,15,1,15,1,117,24, + 0,0,0,95,68,117,109,109,121,77,111,100,117,108,101,76, + 111,99,107,46,114,101,108,101,97,115,101,99,1,0,0,0, + 0,0,0,0,1,0,0,0,4,0,0,0,67,0,0,0, + 115,25,0,0,0,100,1,0,106,0,0,124,0,0,106,1, + 0,116,2,0,124,0,0,131,1,0,131,2,0,83,40,2, + 0,0,0,78,117,28,0,0,0,95,68,117,109,109,121,77, + 111,100,117,108,101,76,111,99,107,40,123,33,114,125,41,32, + 97,116,32,123,125,40,3,0,0,0,117,6,0,0,0,102, + 111,114,109,97,116,117,4,0,0,0,110,97,109,101,117,2, + 0,0,0,105,100,40,1,0,0,0,117,4,0,0,0,115, + 101,108,102,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 8,0,0,0,95,95,114,101,112,114,95,95,4,1,0,0, + 115,2,0,0,0,0,1,117,25,0,0,0,95,68,117,109, + 109,121,77,111,100,117,108,101,76,111,99,107,46,95,95,114, + 101,112,114,95,95,78,40,8,0,0,0,117,8,0,0,0, + 95,95,110,97,109,101,95,95,117,10,0,0,0,95,95,109, + 111,100,117,108,101,95,95,117,12,0,0,0,95,95,113,117, + 97,108,110,97,109,101,95,95,117,7,0,0,0,95,95,100, + 111,99,95,95,117,8,0,0,0,95,95,105,110,105,116,95, + 95,117,7,0,0,0,97,99,113,117,105,114,101,117,7,0, + 0,0,114,101,108,101,97,115,101,117,8,0,0,0,95,95, + 114,101,112,114,95,95,40,1,0,0,0,117,10,0,0,0, + 95,95,108,111,99,97,108,115,95,95,40,0,0,0,0,40, + 0,0,0,0,117,29,0,0,0,60,102,114,111,122,101,110, + 32,105,109,112,111,114,116,108,105,98,46,95,98,111,111,116, + 115,116,114,97,112,62,117,16,0,0,0,95,68,117,109,109, + 121,77,111,100,117,108,101,76,111,99,107,243,0,0,0,115, + 10,0,0,0,16,2,6,2,12,4,12,4,12,5,117,16, + 0,0,0,95,68,117,109,109,121,77,111,100,117,108,101,76, + 111,99,107,99,1,0,0,0,0,0,0,0,3,0,0,0, + 11,0,0,0,3,0,0,0,115,142,0,0,0,100,1,0, + 125,1,0,121,17,0,116,0,0,136,0,0,25,131,0,0, + 125,1,0,87,110,18,0,4,116,1,0,107,10,0,114,43, + 0,1,1,1,89,110,1,0,88,124,1,0,100,1,0,107, + 8,0,114,138,0,116,2,0,100,1,0,107,8,0,114,83, + 0,116,3,0,136,0,0,131,1,0,125,1,0,110,12,0, + 116,4,0,136,0,0,131,1,0,125,1,0,135,0,0,102, + 1,0,100,2,0,100,3,0,134,0,0,125,2,0,116,5, + 0,106,6,0,124,1,0,124,2,0,131,2,0,116,0,0, + 136,0,0,60,110,0,0,124,1,0,83,40,4,0,0,0, + 117,109,0,0,0,71,101,116,32,111,114,32,99,114,101,97, + 116,101,32,116,104,101,32,109,111,100,117,108,101,32,108,111, + 99,107,32,102,111,114,32,97,32,103,105,118,101,110,32,109, + 111,100,117,108,101,32,110,97,109,101,46,10,10,32,32,32, + 32,83,104,111,117,108,100,32,111,110,108,121,32,98,101,32, + 99,97,108,108,101,100,32,119,105,116,104,32,116,104,101,32, + 105,109,112,111,114,116,32,108,111,99,107,32,116,97,107,101, + 110,46,78,99,1,0,0,0,0,0,0,0,1,0,0,0, + 2,0,0,0,19,0,0,0,115,11,0,0,0,116,0,0, + 136,0,0,61,100,0,0,83,40,1,0,0,0,78,40,1, + 0,0,0,117,13,0,0,0,95,109,111,100,117,108,101,95, + 108,111,99,107,115,40,1,0,0,0,117,1,0,0,0,95, + 40,1,0,0,0,117,4,0,0,0,110,97,109,101,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,2,0,0,0,99,98,24,1,0,0, + 115,2,0,0,0,0,1,117,28,0,0,0,95,103,101,116, + 95,109,111,100,117,108,101,95,108,111,99,107,46,60,108,111, + 99,97,108,115,62,46,99,98,40,7,0,0,0,117,13,0, + 0,0,95,109,111,100,117,108,101,95,108,111,99,107,115,117, + 8,0,0,0,75,101,121,69,114,114,111,114,117,7,0,0, + 0,95,116,104,114,101,97,100,117,16,0,0,0,95,68,117, + 109,109,121,77,111,100,117,108,101,76,111,99,107,117,11,0, + 0,0,95,77,111,100,117,108,101,76,111,99,107,117,8,0, + 0,0,95,119,101,97,107,114,101,102,117,3,0,0,0,114, + 101,102,40,3,0,0,0,117,4,0,0,0,110,97,109,101, + 117,4,0,0,0,108,111,99,107,117,2,0,0,0,99,98, + 40,0,0,0,0,40,1,0,0,0,117,4,0,0,0,110, + 97,109,101,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,16,0,0,0,95,103,101,116,95,109, + 111,100,117,108,101,95,108,111,99,107,10,1,0,0,115,24, + 0,0,0,0,4,6,1,3,1,17,1,13,1,5,1,12, + 1,12,1,15,2,12,1,18,2,25,1,117,16,0,0,0, + 95,103,101,116,95,109,111,100,117,108,101,95,108,111,99,107, + 99,1,0,0,0,0,0,0,0,2,0,0,0,11,0,0, + 0,67,0,0,0,115,71,0,0,0,116,0,0,124,0,0, + 131,1,0,125,1,0,116,1,0,106,2,0,131,0,0,1, + 121,14,0,124,1,0,106,3,0,131,0,0,1,87,110,18, + 0,4,116,4,0,107,10,0,114,56,0,1,1,1,89,110, + 11,0,88,124,1,0,106,5,0,131,0,0,1,100,1,0, + 83,40,2,0,0,0,117,21,1,0,0,82,101,108,101,97, + 115,101,32,116,104,101,32,103,108,111,98,97,108,32,105,109, + 112,111,114,116,32,108,111,99,107,44,32,97,110,100,32,97, + 99,113,117,105,114,101,115,32,116,104,101,110,32,114,101,108, + 101,97,115,101,32,116,104,101,10,32,32,32,32,109,111,100, + 117,108,101,32,108,111,99,107,32,102,111,114,32,97,32,103, + 105,118,101,110,32,109,111,100,117,108,101,32,110,97,109,101, + 46,10,32,32,32,32,84,104,105,115,32,105,115,32,117,115, + 101,100,32,116,111,32,101,110,115,117,114,101,32,97,32,109, + 111,100,117,108,101,32,105,115,32,99,111,109,112,108,101,116, + 101,108,121,32,105,110,105,116,105,97,108,105,122,101,100,44, + 32,105,110,32,116,104,101,10,32,32,32,32,101,118,101,110, + 116,32,105,116,32,105,115,32,98,101,105,110,103,32,105,109, + 112,111,114,116,101,100,32,98,121,32,97,110,111,116,104,101, + 114,32,116,104,114,101,97,100,46,10,10,32,32,32,32,83, + 104,111,117,108,100,32,111,110,108,121,32,98,101,32,99,97, + 108,108,101,100,32,119,105,116,104,32,116,104,101,32,105,109, + 112,111,114,116,32,108,111,99,107,32,116,97,107,101,110,46, + 78,40,6,0,0,0,117,16,0,0,0,95,103,101,116,95, + 109,111,100,117,108,101,95,108,111,99,107,117,4,0,0,0, + 95,105,109,112,117,12,0,0,0,114,101,108,101,97,115,101, + 95,108,111,99,107,117,7,0,0,0,97,99,113,117,105,114, + 101,117,14,0,0,0,95,68,101,97,100,108,111,99,107,69, + 114,114,111,114,117,7,0,0,0,114,101,108,101,97,115,101, + 40,2,0,0,0,117,4,0,0,0,110,97,109,101,117,4, + 0,0,0,108,111,99,107,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,19,0,0,0,95,108,111,99,107,95,117,110, + 108,111,99,107,95,109,111,100,117,108,101,29,1,0,0,115, 14,0,0,0,0,7,12,1,10,1,3,1,14,1,13,3, - 5,2,114,96,0,0,0,99,1,0,0,0,0,0,0,0, - 3,0,0,0,3,0,0,0,79,0,0,0,115,13,0,0, - 0,124,0,0,124,1,0,124,2,0,142,0,0,83,40,1, - 0,0,0,117,46,1,0,0,114,101,109,111,118,101,95,105, - 109,112,111,114,116,108,105,98,95,102,114,97,109,101,115,32, - 105,110,32,105,109,112,111,114,116,46,99,32,119,105,108,108, - 32,97,108,119,97,121,115,32,114,101,109,111,118,101,32,115, - 101,113,117,101,110,99,101,115,10,32,32,32,32,111,102,32, - 105,109,112,111,114,116,108,105,98,32,102,114,97,109,101,115, - 32,116,104,97,116,32,101,110,100,32,119,105,116,104,32,97, - 32,99,97,108,108,32,116,111,32,116,104,105,115,32,102,117, - 110,99,116,105,111,110,10,10,32,32,32,32,85,115,101,32, - 105,116,32,105,110,115,116,101,97,100,32,111,102,32,97,32, - 110,111,114,109,97,108,32,99,97,108,108,32,105,110,32,112, - 108,97,99,101,115,32,119,104,101,114,101,32,105,110,99,108, - 117,100,105,110,103,32,116,104,101,32,105,109,112,111,114,116, - 108,105,98,10,32,32,32,32,102,114,97,109,101,115,32,105, - 110,116,114,111,100,117,99,101,115,32,117,110,119,97,110,116, - 101,100,32,110,111,105,115,101,32,105,110,116,111,32,116,104, - 101,32,116,114,97,99,101,98,97,99,107,32,40,101,46,103, - 46,32,119,104,101,110,32,101,120,101,99,117,116,105,110,103, - 10,32,32,32,32,109,111,100,117,108,101,32,99,111,100,101, - 41,10,32,32,32,32,114,4,0,0,0,40,3,0,0,0, - 244,1,0,0,0,102,244,4,0,0,0,97,114,103,115,116, - 4,0,0,0,107,119,100,115,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,244,25,0,0,0,95,99,97,108, + 5,2,117,19,0,0,0,95,108,111,99,107,95,117,110,108, + 111,99,107,95,109,111,100,117,108,101,99,1,0,0,0,0, + 0,0,0,3,0,0,0,3,0,0,0,79,0,0,0,115, + 13,0,0,0,124,0,0,124,1,0,124,2,0,142,0,0, + 83,40,1,0,0,0,117,46,1,0,0,114,101,109,111,118, + 101,95,105,109,112,111,114,116,108,105,98,95,102,114,97,109, + 101,115,32,105,110,32,105,109,112,111,114,116,46,99,32,119, + 105,108,108,32,97,108,119,97,121,115,32,114,101,109,111,118, + 101,32,115,101,113,117,101,110,99,101,115,10,32,32,32,32, + 111,102,32,105,109,112,111,114,116,108,105,98,32,102,114,97, + 109,101,115,32,116,104,97,116,32,101,110,100,32,119,105,116, + 104,32,97,32,99,97,108,108,32,116,111,32,116,104,105,115, + 32,102,117,110,99,116,105,111,110,10,10,32,32,32,32,85, + 115,101,32,105,116,32,105,110,115,116,101,97,100,32,111,102, + 32,97,32,110,111,114,109,97,108,32,99,97,108,108,32,105, + 110,32,112,108,97,99,101,115,32,119,104,101,114,101,32,105, + 110,99,108,117,100,105,110,103,32,116,104,101,32,105,109,112, + 111,114,116,108,105,98,10,32,32,32,32,102,114,97,109,101, + 115,32,105,110,116,114,111,100,117,99,101,115,32,117,110,119, + 97,110,116,101,100,32,110,111,105,115,101,32,105,110,116,111, + 32,116,104,101,32,116,114,97,99,101,98,97,99,107,32,40, + 101,46,103,46,32,119,104,101,110,32,101,120,101,99,117,116, + 105,110,103,10,32,32,32,32,109,111,100,117,108,101,32,99, + 111,100,101,41,10,32,32,32,32,40,0,0,0,0,40,3, + 0,0,0,117,1,0,0,0,102,117,4,0,0,0,97,114, + 103,115,117,4,0,0,0,107,119,100,115,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,25,0,0,0,95,99,97,108, 108,95,119,105,116,104,95,102,114,97,109,101,115,95,114,101, - 109,111,118,101,100,10,1,0,0,115,2,0,0,0,0,8, - 114,99,0,0,0,105,208,12,0,0,233,2,0,0,0,114, - 13,0,0,0,115,2,0,0,0,13,10,116,11,0,0,0, - 95,95,112,121,99,97,99,104,101,95,95,117,3,0,0,0, - 46,112,121,117,4,0,0,0,46,112,121,99,117,4,0,0, - 0,46,112,121,111,78,99,2,0,0,0,0,0,0,0,11, - 0,0,0,6,0,0,0,67,0,0,0,115,180,0,0,0, - 124,1,0,100,1,0,107,8,0,114,25,0,116,0,0,106, - 1,0,106,2,0,12,110,3,0,124,1,0,125,2,0,124, - 2,0,114,46,0,116,3,0,125,3,0,110,6,0,116,4, - 0,125,3,0,116,5,0,124,0,0,131,1,0,92,2,0, - 125,4,0,125,5,0,124,5,0,106,6,0,100,2,0,131, - 1,0,92,3,0,125,6,0,125,7,0,125,8,0,116,0, - 0,106,7,0,106,8,0,125,9,0,124,9,0,100,1,0, - 107,8,0,114,133,0,116,9,0,100,3,0,131,1,0,130, - 1,0,110,0,0,100,4,0,106,10,0,124,6,0,124,7, - 0,124,9,0,124,3,0,100,5,0,25,103,4,0,131,1, - 0,125,10,0,116,11,0,124,4,0,116,12,0,124,10,0, - 131,3,0,83,40,6,0,0,0,117,244,1,0,0,71,105, - 118,101,110,32,116,104,101,32,112,97,116,104,32,116,111,32, - 97,32,46,112,121,32,102,105,108,101,44,32,114,101,116,117, - 114,110,32,116,104,101,32,112,97,116,104,32,116,111,32,105, - 116,115,32,46,112,121,99,47,46,112,121,111,32,102,105,108, - 101,46,10,10,32,32,32,32,84,104,101,32,46,112,121,32, - 102,105,108,101,32,100,111,101,115,32,110,111,116,32,110,101, - 101,100,32,116,111,32,101,120,105,115,116,59,32,116,104,105, - 115,32,115,105,109,112,108,121,32,114,101,116,117,114,110,115, - 32,116,104,101,32,112,97,116,104,32,116,111,32,116,104,101, - 10,32,32,32,32,46,112,121,99,47,46,112,121,111,32,102, - 105,108,101,32,99,97,108,99,117,108,97,116,101,100,32,97, - 115,32,105,102,32,116,104,101,32,46,112,121,32,102,105,108, - 101,32,119,101,114,101,32,105,109,112,111,114,116,101,100,46, - 32,32,84,104,101,32,101,120,116,101,110,115,105,111,110,10, - 32,32,32,32,119,105,108,108,32,98,101,32,46,112,121,99, - 32,117,110,108,101,115,115,32,115,121,115,46,102,108,97,103, - 115,46,111,112,116,105,109,105,122,101,32,105,115,32,110,111, - 110,45,122,101,114,111,44,32,116,104,101,110,32,105,116,32, - 119,105,108,108,32,98,101,32,46,112,121,111,46,10,10,32, - 32,32,32,73,102,32,100,101,98,117,103,95,111,118,101,114, - 114,105,100,101,32,105,115,32,110,111,116,32,78,111,110,101, - 44,32,116,104,101,110,32,105,116,32,109,117,115,116,32,98, - 101,32,97,32,98,111,111,108,101,97,110,32,97,110,100,32, - 105,115,32,117,115,101,100,32,105,110,10,32,32,32,32,112, - 108,97,99,101,32,111,102,32,115,121,115,46,102,108,97,103, - 115,46,111,112,116,105,109,105,122,101,46,10,10,32,32,32, - 32,73,102,32,115,121,115,46,105,109,112,108,101,109,101,110, - 116,97,116,105,111,110,46,99,97,99,104,101,95,116,97,103, - 32,105,115,32,78,111,110,101,32,116,104,101,110,32,78,111, - 116,73,109,112,108,101,109,101,110,116,101,100,69,114,114,111, - 114,32,105,115,32,114,97,105,115,101,100,46,10,10,32,32, - 32,32,78,244,1,0,0,0,46,117,36,0,0,0,115,121, - 115,46,105,109,112,108,101,109,101,110,116,97,116,105,111,110, - 46,99,97,99,104,101,95,116,97,103,32,105,115,32,78,111, - 110,101,114,30,0,0,0,114,67,0,0,0,40,13,0,0, - 0,114,7,0,0,0,244,5,0,0,0,102,108,97,103,115, - 244,8,0,0,0,111,112,116,105,109,105,122,101,244,23,0, - 0,0,68,69,66,85,71,95,66,89,84,69,67,79,68,69, - 95,83,85,70,70,73,88,69,83,244,27,0,0,0,79,80, - 84,73,77,73,90,69,68,95,66,89,84,69,67,79,68,69, - 95,83,85,70,70,73,88,69,83,114,38,0,0,0,244,9, - 0,0,0,112,97,114,116,105,116,105,111,110,244,14,0,0, - 0,105,109,112,108,101,109,101,110,116,97,116,105,111,110,244, - 9,0,0,0,99,97,99,104,101,95,116,97,103,244,19,0, - 0,0,78,111,116,73,109,112,108,101,109,101,110,116,101,100, - 69,114,114,111,114,114,26,0,0,0,114,28,0,0,0,244, - 8,0,0,0,95,80,89,67,65,67,72,69,40,11,0,0, - 0,114,35,0,0,0,116,14,0,0,0,100,101,98,117,103, - 95,111,118,101,114,114,105,100,101,244,5,0,0,0,100,101, - 98,117,103,244,8,0,0,0,115,117,102,102,105,120,101,115, - 244,4,0,0,0,104,101,97,100,114,37,0,0,0,244,13, - 0,0,0,98,97,115,101,95,102,105,108,101,110,97,109,101, - 244,3,0,0,0,115,101,112,114,36,0,0,0,116,3,0, - 0,0,116,97,103,244,8,0,0,0,102,105,108,101,110,97, - 109,101,114,4,0,0,0,114,4,0,0,0,114,5,0,0, - 0,244,17,0,0,0,99,97,99,104,101,95,102,114,111,109, - 95,115,111,117,114,99,101,131,1,0,0,115,22,0,0,0, - 0,13,31,1,6,1,9,2,6,1,18,1,24,1,12,1, - 12,1,15,1,31,1,114,117,0,0,0,99,1,0,0,0, - 0,0,0,0,5,0,0,0,5,0,0,0,67,0,0,0, - 115,193,0,0,0,116,0,0,106,1,0,106,2,0,100,1, - 0,107,8,0,114,33,0,116,3,0,100,2,0,131,1,0, - 130,1,0,110,0,0,116,4,0,124,0,0,131,1,0,92, - 2,0,125,1,0,125,2,0,116,4,0,124,1,0,131,1, - 0,92,2,0,125,1,0,125,3,0,124,3,0,116,5,0, - 107,3,0,114,108,0,116,6,0,100,3,0,106,7,0,116, - 5,0,124,0,0,131,2,0,131,1,0,130,1,0,110,0, - 0,124,2,0,106,8,0,100,4,0,131,1,0,100,5,0, - 107,3,0,114,153,0,116,6,0,100,6,0,106,7,0,124, - 2,0,131,1,0,131,1,0,130,1,0,110,0,0,124,2, - 0,106,9,0,100,4,0,131,1,0,100,7,0,25,125,4, - 0,116,10,0,124,1,0,124,4,0,116,11,0,100,7,0, - 25,23,131,2,0,83,40,8,0,0,0,117,121,1,0,0, - 71,105,118,101,110,32,116,104,101,32,112,97,116,104,32,116, - 111,32,97,32,46,112,121,99,46,47,46,112,121,111,32,102, - 105,108,101,44,32,114,101,116,117,114,110,32,116,104,101,32, - 112,97,116,104,32,116,111,32,105,116,115,32,46,112,121,32, - 102,105,108,101,46,10,10,32,32,32,32,84,104,101,32,46, - 112,121,99,47,46,112,121,111,32,102,105,108,101,32,100,111, - 101,115,32,110,111,116,32,110,101,101,100,32,116,111,32,101, - 120,105,115,116,59,32,116,104,105,115,32,115,105,109,112,108, - 121,32,114,101,116,117,114,110,115,32,116,104,101,32,112,97, - 116,104,32,116,111,10,32,32,32,32,116,104,101,32,46,112, - 121,32,102,105,108,101,32,99,97,108,99,117,108,97,116,101, - 100,32,116,111,32,99,111,114,114,101,115,112,111,110,100,32, - 116,111,32,116,104,101,32,46,112,121,99,47,46,112,121,111, - 32,102,105,108,101,46,32,32,73,102,32,112,97,116,104,32, - 100,111,101,115,10,32,32,32,32,110,111,116,32,99,111,110, - 102,111,114,109,32,116,111,32,80,69,80,32,51,49,52,55, - 32,102,111,114,109,97,116,44,32,86,97,108,117,101,69,114, - 114,111,114,32,119,105,108,108,32,98,101,32,114,97,105,115, - 101,100,46,32,73,102,10,32,32,32,32,115,121,115,46,105, - 109,112,108,101,109,101,110,116,97,116,105,111,110,46,99,97, - 99,104,101,95,116,97,103,32,105,115,32,78,111,110,101,32, - 116,104,101,110,32,78,111,116,73,109,112,108,101,109,101,110, - 116,101,100,69,114,114,111,114,32,105,115,32,114,97,105,115, - 101,100,46,10,10,32,32,32,32,78,117,36,0,0,0,115, - 121,115,46,105,109,112,108,101,109,101,110,116,97,116,105,111, - 110,46,99,97,99,104,101,95,116,97,103,32,105,115,32,78, - 111,110,101,117,37,0,0,0,123,125,32,110,111,116,32,98, - 111,116,116,111,109,45,108,101,118,101,108,32,100,105,114,101, - 99,116,111,114,121,32,105,110,32,123,33,114,125,114,101,0, - 0,0,114,100,0,0,0,117,28,0,0,0,101,120,112,101, - 99,116,101,100,32,111,110,108,121,32,50,32,100,111,116,115, - 32,105,110,32,123,33,114,125,114,67,0,0,0,40,12,0, - 0,0,114,7,0,0,0,114,107,0,0,0,114,108,0,0, - 0,114,109,0,0,0,114,38,0,0,0,114,110,0,0,0, - 244,10,0,0,0,86,97,108,117,101,69,114,114,111,114,114, - 46,0,0,0,114,73,0,0,0,114,106,0,0,0,114,28, - 0,0,0,244,15,0,0,0,83,79,85,82,67,69,95,83, - 85,70,70,73,88,69,83,40,5,0,0,0,114,35,0,0, - 0,114,113,0,0,0,116,16,0,0,0,112,121,99,97,99, - 104,101,95,102,105,108,101,110,97,109,101,116,7,0,0,0, - 112,121,99,97,99,104,101,114,114,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,244,17,0,0,0, - 115,111,117,114,99,101,95,102,114,111,109,95,99,97,99,104, - 101,158,1,0,0,115,24,0,0,0,0,9,18,1,15,1, - 18,1,18,1,12,1,3,1,24,1,21,1,3,1,21,1, - 19,1,114,120,0,0,0,99,1,0,0,0,0,0,0,0, - 5,0,0,0,13,0,0,0,67,0,0,0,115,164,0,0, - 0,116,0,0,124,0,0,131,1,0,100,1,0,107,2,0, - 114,22,0,100,2,0,83,124,0,0,106,1,0,100,3,0, - 131,1,0,92,3,0,125,1,0,125,2,0,125,3,0,124, - 1,0,12,115,81,0,124,3,0,106,2,0,131,0,0,100, - 7,0,100,8,0,133,2,0,25,100,6,0,107,3,0,114, - 85,0,124,0,0,83,121,16,0,116,3,0,124,0,0,131, - 1,0,125,4,0,87,110,40,0,4,116,4,0,116,5,0, - 102,2,0,107,10,0,114,143,0,1,1,1,124,0,0,100, - 2,0,100,9,0,133,2,0,25,125,4,0,89,110,1,0, - 88,116,6,0,124,4,0,131,1,0,114,160,0,124,4,0, - 83,124,0,0,83,40,10,0,0,0,117,188,0,0,0,67, - 111,110,118,101,114,116,32,97,32,98,121,116,101,99,111,100, - 101,32,102,105,108,101,32,112,97,116,104,32,116,111,32,97, - 32,115,111,117,114,99,101,32,112,97,116,104,32,40,105,102, - 32,112,111,115,115,105,98,108,101,41,46,10,10,32,32,32, - 32,84,104,105,115,32,102,117,110,99,116,105,111,110,32,101, - 120,105,115,116,115,32,112,117,114,101,108,121,32,102,111,114, - 32,98,97,99,107,119,97,114,100,115,45,99,111,109,112,97, - 116,105,98,105,108,105,116,121,32,102,111,114,10,32,32,32, - 32,80,121,73,109,112,111,114,116,95,69,120,101,99,67,111, - 100,101,77,111,100,117,108,101,87,105,116,104,70,105,108,101, - 110,97,109,101,115,40,41,32,105,110,32,116,104,101,32,67, - 32,65,80,73,46,10,10,32,32,32,32,114,67,0,0,0, - 78,114,101,0,0,0,233,3,0,0,0,114,29,0,0,0, - 116,2,0,0,0,112,121,233,253,255,255,255,233,255,255,255, - 255,114,123,0,0,0,40,7,0,0,0,114,31,0,0,0, - 114,32,0,0,0,244,5,0,0,0,108,111,119,101,114,114, - 120,0,0,0,114,109,0,0,0,114,118,0,0,0,114,44, - 0,0,0,40,5,0,0,0,244,13,0,0,0,98,121,116, - 101,99,111,100,101,95,112,97,116,104,116,4,0,0,0,114, - 101,115,116,114,36,0,0,0,116,9,0,0,0,101,120,116, - 101,110,115,105,111,110,244,11,0,0,0,115,111,117,114,99, - 101,95,112,97,116,104,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,244,15,0,0,0,95,103,101,116,95,115, - 111,117,114,99,101,102,105,108,101,181,1,0,0,115,20,0, - 0,0,0,7,18,1,4,1,24,1,35,1,4,1,3,1, - 16,1,19,1,21,1,114,127,0,0,0,99,1,0,0,0, - 0,0,0,0,2,0,0,0,11,0,0,0,67,0,0,0, - 115,63,0,0,0,121,22,0,116,0,0,106,1,0,124,0, - 0,131,1,0,106,2,0,125,1,0,87,110,24,0,4,116, - 3,0,107,10,0,114,48,0,1,1,1,100,1,0,125,1, - 0,89,110,1,0,88,124,1,0,100,2,0,79,125,1,0, - 124,1,0,83,40,3,0,0,0,117,51,0,0,0,67,97, - 108,99,117,108,97,116,101,32,116,104,101,32,109,111,100,101, - 32,112,101,114,109,105,115,115,105,111,110,115,32,102,111,114, - 32,97,32,98,121,116,101,99,111,100,101,32,102,105,108,101, - 46,105,182,1,0,0,233,128,0,0,0,40,4,0,0,0, - 114,3,0,0,0,114,39,0,0,0,114,41,0,0,0,114, - 40,0,0,0,40,2,0,0,0,114,35,0,0,0,114,42, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,244,10,0,0,0,95,99,97,108,99,95,109,111,100, - 101,200,1,0,0,115,12,0,0,0,0,2,3,1,22,1, - 13,1,11,3,10,1,114,129,0,0,0,244,9,0,0,0, - 118,101,114,98,111,115,105,116,121,114,29,0,0,0,99,1, - 0,0,0,1,0,0,0,3,0,0,0,4,0,0,0,71, - 0,0,0,115,81,0,0,0,116,0,0,106,1,0,106,2, - 0,124,1,0,107,5,0,114,77,0,124,0,0,106,3,0, - 100,6,0,131,1,0,115,46,0,100,3,0,124,0,0,23, - 125,0,0,110,0,0,116,4,0,124,0,0,106,5,0,124, - 2,0,140,0,0,100,4,0,116,0,0,106,6,0,131,1, - 1,1,110,0,0,100,5,0,83,40,7,0,0,0,117,61, - 0,0,0,80,114,105,110,116,32,116,104,101,32,109,101,115, - 115,97,103,101,32,116,111,32,115,116,100,101,114,114,32,105, - 102,32,45,118,47,80,89,84,72,79,78,86,69,82,66,79, - 83,69,32,105,115,32,116,117,114,110,101,100,32,111,110,46, - 245,1,0,0,0,35,245,7,0,0,0,105,109,112,111,114, - 116,32,117,2,0,0,0,35,32,114,53,0,0,0,78,40, - 2,0,0,0,114,131,0,0,0,114,132,0,0,0,40,7, - 0,0,0,114,7,0,0,0,114,102,0,0,0,244,7,0, - 0,0,118,101,114,98,111,115,101,114,9,0,0,0,244,5, - 0,0,0,112,114,105,110,116,114,46,0,0,0,244,6,0, - 0,0,115,116,100,101,114,114,40,3,0,0,0,244,7,0, - 0,0,109,101,115,115,97,103,101,114,130,0,0,0,114,98, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,244,16,0,0,0,95,118,101,114,98,111,115,101,95, - 109,101,115,115,97,103,101,212,1,0,0,115,8,0,0,0, - 0,2,18,1,15,1,13,1,114,137,0,0,0,99,0,0, - 0,0,0,0,0,0,0,0,0,0,2,0,0,0,64,0, - 0,0,115,52,0,0,0,101,0,0,90,1,0,100,0,0, - 90,2,0,100,1,0,100,2,0,132,0,0,90,3,0,100, - 3,0,100,4,0,132,0,0,90,4,0,100,5,0,100,6, - 0,132,0,0,90,5,0,100,7,0,83,40,8,0,0,0, - 244,13,0,0,0,95,77,97,110,97,103,101,82,101,108,111, - 97,100,99,2,0,0,0,0,0,0,0,2,0,0,0,2, - 0,0,0,67,0,0,0,115,13,0,0,0,124,1,0,124, - 0,0,95,0,0,100,0,0,83,40,1,0,0,0,78,40, - 1,0,0,0,244,5,0,0,0,95,110,97,109,101,40,2, - 0,0,0,114,75,0,0,0,114,71,0,0,0,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,114,76,0,0, - 0,222,1,0,0,115,2,0,0,0,0,1,117,22,0,0, - 0,95,77,97,110,97,103,101,82,101,108,111,97,100,46,95, - 95,105,110,105,116,95,95,99,1,0,0,0,0,0,0,0, - 1,0,0,0,2,0,0,0,67,0,0,0,115,25,0,0, - 0,124,0,0,106,0,0,116,1,0,106,2,0,107,6,0, - 124,0,0,95,3,0,100,0,0,83,40,1,0,0,0,78, - 40,4,0,0,0,114,139,0,0,0,114,7,0,0,0,244, - 7,0,0,0,109,111,100,117,108,101,115,244,10,0,0,0, - 95,105,115,95,114,101,108,111,97,100,40,1,0,0,0,114, - 75,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,244,9,0,0,0,95,95,101,110,116,101,114,95, - 95,225,1,0,0,115,2,0,0,0,0,1,117,23,0,0, - 0,95,77,97,110,97,103,101,82,101,108,111,97,100,46,95, - 95,101,110,116,101,114,95,95,99,1,0,0,0,0,0,0, - 0,2,0,0,0,12,0,0,0,71,0,0,0,115,80,0, - 0,0,116,0,0,100,1,0,100,2,0,132,0,0,124,1, - 0,68,131,1,0,131,1,0,114,76,0,124,0,0,106,1, - 0,12,114,76,0,121,17,0,116,2,0,106,3,0,124,0, - 0,106,4,0,61,87,113,76,0,4,116,5,0,107,10,0, - 114,72,0,1,1,1,89,113,76,0,88,110,0,0,100,0, - 0,83,40,3,0,0,0,78,99,1,0,0,0,0,0,0, - 0,2,0,0,0,3,0,0,0,115,0,0,0,115,27,0, - 0,0,124,0,0,93,17,0,125,1,0,124,1,0,100,0, - 0,107,9,0,86,1,113,3,0,100,0,0,83,40,1,0, - 0,0,78,114,4,0,0,0,40,2,0,0,0,114,22,0, - 0,0,116,3,0,0,0,97,114,103,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,245,9,0,0,0,60,103, - 101,110,101,120,112,114,62,229,1,0,0,115,2,0,0,0, - 6,0,117,41,0,0,0,95,77,97,110,97,103,101,82,101, - 108,111,97,100,46,95,95,101,120,105,116,95,95,46,60,108, - 111,99,97,108,115,62,46,60,103,101,110,101,120,112,114,62, - 40,6,0,0,0,244,3,0,0,0,97,110,121,114,141,0, - 0,0,114,7,0,0,0,114,140,0,0,0,114,139,0,0, - 0,114,91,0,0,0,40,2,0,0,0,114,75,0,0,0, - 114,98,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,244,8,0,0,0,95,95,101,120,105,116,95, - 95,228,1,0,0,115,10,0,0,0,0,1,35,1,3,1, - 17,1,13,1,117,22,0,0,0,95,77,97,110,97,103,101, - 82,101,108,111,97,100,46,95,95,101,120,105,116,95,95,78, - 40,6,0,0,0,114,56,0,0,0,114,55,0,0,0,114, - 57,0,0,0,114,76,0,0,0,114,142,0,0,0,114,145, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,114,138,0,0,0,220,1,0,0, - 115,6,0,0,0,12,2,12,3,12,3,114,138,0,0,0, - 99,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0, - 0,0,0,0,0,115,82,0,0,0,101,0,0,90,1,0, - 100,0,0,90,2,0,100,1,0,90,3,0,100,2,0,100, - 3,0,135,0,0,102,1,0,100,4,0,100,5,0,134,0, - 1,90,4,0,135,0,0,102,1,0,100,6,0,100,7,0, - 134,0,0,90,5,0,135,0,0,102,1,0,100,8,0,100, - 9,0,134,0,0,90,6,0,135,0,0,83,40,10,0,0, - 0,244,14,0,0,0,95,77,111,100,117,108,101,77,97,110, - 97,103,101,114,117,122,0,0,0,67,111,110,116,101,120,116, - 32,109,97,110,97,103,101,114,32,119,104,105,99,104,32,114, - 101,116,117,114,110,115,32,116,104,101,32,109,111,100,117,108, - 101,32,116,111,32,98,101,32,108,111,97,100,101,100,46,10, - 10,32,32,32,32,68,111,101,115,32,116,104,101,32,112,114, - 111,112,101,114,32,117,110,108,111,97,100,105,110,103,32,102, - 114,111,109,32,115,121,115,46,109,111,100,117,108,101,115,32, - 117,112,111,110,32,102,97,105,108,117,114,101,46,10,10,32, - 32,32,32,244,10,0,0,0,114,101,115,101,116,95,110,97, - 109,101,84,99,2,0,0,0,1,0,0,0,3,0,0,0, - 2,0,0,0,3,0,0,0,115,29,0,0,0,116,0,0, - 131,0,0,106,1,0,124,1,0,131,1,0,1,124,2,0, - 124,0,0,95,2,0,100,1,0,83,40,2,0,0,0,117, - 183,0,0,0,80,114,101,112,97,114,101,32,116,104,101,32, - 99,111,110,116,101,120,116,32,109,97,110,97,103,101,114,46, - 10,10,32,32,32,32,32,32,32,32,84,104,101,32,114,101, - 115,101,116,95,110,97,109,101,32,97,114,103,117,109,101,110, - 116,32,115,112,101,99,105,102,105,101,115,32,119,104,101,116, - 104,101,114,32,116,111,32,117,110,99,111,110,100,105,116,105, - 111,110,97,108,108,121,32,114,101,115,101,116,10,32,32,32, - 32,32,32,32,32,116,104,101,32,95,95,110,97,109,101,95, - 95,32,97,116,116,114,105,98,117,116,101,32,105,102,32,116, - 104,101,32,109,111,100,117,108,101,32,105,115,32,102,111,117, - 110,100,32,116,111,32,98,101,32,97,32,114,101,108,111,97, - 100,46,10,32,32,32,32,32,32,32,32,78,40,3,0,0, - 0,244,5,0,0,0,115,117,112,101,114,114,76,0,0,0, - 244,11,0,0,0,95,114,101,115,101,116,95,110,97,109,101, - 40,3,0,0,0,114,75,0,0,0,114,71,0,0,0,114, - 147,0,0,0,40,1,0,0,0,244,9,0,0,0,95,95, - 99,108,97,115,115,95,95,114,4,0,0,0,114,5,0,0, - 0,114,76,0,0,0,245,1,0,0,115,4,0,0,0,0, - 6,16,1,117,23,0,0,0,95,77,111,100,117,108,101,77, - 97,110,97,103,101,114,46,95,95,105,110,105,116,95,95,99, - 1,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0, - 3,0,0,0,115,163,0,0,0,116,0,0,131,0,0,106, - 1,0,131,0,0,1,116,2,0,106,3,0,106,4,0,124, - 0,0,106,5,0,131,1,0,124,0,0,95,6,0,124,0, - 0,106,7,0,115,104,0,116,8,0,116,9,0,131,1,0, - 124,0,0,106,5,0,131,1,0,124,0,0,95,6,0,100, - 1,0,124,0,0,106,6,0,95,10,0,124,0,0,106,6, - 0,116,2,0,106,3,0,124,0,0,106,5,0,60,110,52, - 0,124,0,0,106,11,0,114,156,0,121,19,0,124,0,0, - 106,5,0,124,0,0,106,6,0,95,12,0,87,113,156,0, - 4,116,13,0,107,10,0,114,152,0,1,1,1,89,113,156, - 0,88,110,0,0,124,0,0,106,6,0,83,40,2,0,0, - 0,78,84,40,14,0,0,0,114,148,0,0,0,114,142,0, - 0,0,114,7,0,0,0,114,140,0,0,0,114,79,0,0, - 0,114,139,0,0,0,244,7,0,0,0,95,109,111,100,117, - 108,101,114,141,0,0,0,244,4,0,0,0,116,121,112,101, - 114,48,0,0,0,244,16,0,0,0,95,95,105,110,105,116, - 105,97,108,105,122,105,110,103,95,95,114,149,0,0,0,114, - 56,0,0,0,244,14,0,0,0,65,116,116,114,105,98,117, - 116,101,69,114,114,111,114,40,1,0,0,0,114,75,0,0, - 0,40,1,0,0,0,114,150,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,142,0,0,0,254,1,0,0,115,24, - 0,0,0,0,1,13,1,24,1,9,4,24,3,12,1,22, - 1,9,1,3,1,19,1,13,1,8,1,117,24,0,0,0, - 95,77,111,100,117,108,101,77,97,110,97,103,101,114,46,95, - 95,101,110,116,101,114,95,95,99,1,0,0,0,0,0,0, - 0,2,0,0,0,2,0,0,0,7,0,0,0,115,38,0, - 0,0,100,1,0,124,0,0,106,0,0,95,1,0,124,0, - 0,96,0,0,116,2,0,131,0,0,106,3,0,124,1,0, - 140,0,0,1,100,0,0,83,40,2,0,0,0,78,70,40, - 4,0,0,0,114,151,0,0,0,114,153,0,0,0,114,148, - 0,0,0,114,145,0,0,0,40,2,0,0,0,114,75,0, - 0,0,114,98,0,0,0,40,1,0,0,0,114,150,0,0, - 0,114,4,0,0,0,114,5,0,0,0,114,145,0,0,0, - 17,2,0,0,115,6,0,0,0,0,1,12,1,6,1,117, - 23,0,0,0,95,77,111,100,117,108,101,77,97,110,97,103, - 101,114,46,95,95,101,120,105,116,95,95,40,7,0,0,0, - 114,56,0,0,0,114,55,0,0,0,114,57,0,0,0,114, - 58,0,0,0,114,76,0,0,0,114,142,0,0,0,114,145, - 0,0,0,114,4,0,0,0,114,4,0,0,0,40,1,0, - 0,0,114,150,0,0,0,114,5,0,0,0,114,146,0,0, - 0,237,1,0,0,115,8,0,0,0,12,6,6,2,24,9, - 18,19,114,146,0,0,0,114,147,0,0,0,84,99,1,0, - 0,0,1,0,0,0,2,0,0,0,4,0,0,0,67,0, - 0,0,115,16,0,0,0,116,0,0,124,0,0,100,1,0, - 124,1,0,131,1,1,83,40,2,0,0,0,117,138,0,0, - 0,82,101,116,117,114,110,32,97,32,99,111,110,116,101,120, - 116,32,109,97,110,97,103,101,114,32,119,104,105,99,104,32, - 112,114,111,118,105,100,101,115,32,116,104,101,32,109,111,100, - 117,108,101,32,111,98,106,101,99,116,32,116,111,32,108,111, - 97,100,46,10,10,32,32,32,32,73,102,32,114,101,115,101, - 116,95,110,97,109,101,32,105,115,32,116,114,117,101,44,32, - 114,101,115,101,116,32,116,104,101,32,109,111,100,117,108,101, - 39,115,32,95,95,110,97,109,101,95,95,32,116,111,32,39, - 110,97,109,101,39,46,10,32,32,32,32,114,147,0,0,0, - 40,1,0,0,0,114,146,0,0,0,40,2,0,0,0,114, - 71,0,0,0,114,147,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,244,14,0,0,0,109,111,100, - 117,108,101,95,116,111,95,108,111,97,100,23,2,0,0,115, - 2,0,0,0,0,6,114,155,0,0,0,99,2,0,0,0, - 0,0,0,0,4,0,0,0,11,0,0,0,67,0,0,0, - 115,102,0,0,0,124,1,0,106,0,0,125,2,0,121,19, - 0,124,0,0,106,1,0,124,2,0,131,1,0,125,3,0, - 87,110,18,0,4,116,2,0,107,10,0,114,48,0,1,1, - 1,89,110,50,0,88,124,3,0,114,76,0,124,2,0,124, - 1,0,95,3,0,103,0,0,124,1,0,95,4,0,110,22, - 0,124,2,0,106,5,0,100,1,0,131,1,0,100,2,0, - 25,124,1,0,95,3,0,100,3,0,83,40,4,0,0,0, - 117,68,0,0,0,83,101,116,32,95,95,112,97,99,107,97, - 103,101,95,95,32,97,110,100,32,95,95,112,97,116,104,95, - 95,32,98,97,115,101,100,32,111,110,32,119,104,97,116,32, - 108,111,97,100,101,114,46,105,115,95,112,97,99,107,97,103, - 101,40,41,32,115,97,121,115,46,114,101,0,0,0,114,67, - 0,0,0,78,40,6,0,0,0,114,56,0,0,0,244,10, - 0,0,0,105,115,95,112,97,99,107,97,103,101,244,11,0, - 0,0,73,109,112,111,114,116,69,114,114,111,114,244,11,0, - 0,0,95,95,112,97,99,107,97,103,101,95,95,244,8,0, - 0,0,95,95,112,97,116,104,95,95,114,32,0,0,0,40, - 4,0,0,0,244,6,0,0,0,108,111,97,100,101,114,244, - 6,0,0,0,109,111,100,117,108,101,114,71,0,0,0,114, - 156,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,244,19,0,0,0,95,105,110,105,116,95,112,97, - 99,107,97,103,101,95,97,116,116,114,115,32,2,0,0,115, - 18,0,0,0,0,2,9,1,3,1,19,1,13,1,5,2, - 6,1,9,1,12,2,114,162,0,0,0,99,2,0,0,0, - 0,0,0,0,2,0,0,0,11,0,0,0,67,0,0,0, - 115,100,0,0,0,121,25,0,124,0,0,106,0,0,124,1, - 0,106,1,0,131,1,0,124,1,0,95,2,0,87,110,18, - 0,4,116,3,0,107,10,0,114,45,0,1,1,1,89,110, - 51,0,88,124,1,0,106,1,0,124,1,0,106,4,0,107, - 2,0,114,96,0,124,1,0,106,5,0,106,6,0,116,7, - 0,124,1,0,106,2,0,131,1,0,100,1,0,25,131,1, - 0,1,110,0,0,100,2,0,83,40,3,0,0,0,117,57, - 0,0,0,83,101,116,32,95,95,102,105,108,101,95,95,32, - 97,110,100,32,95,95,112,97,116,104,95,95,32,98,97,115, - 101,100,32,111,110,32,108,111,97,100,101,114,46,103,101,116, - 95,102,105,108,101,110,97,109,101,40,41,46,114,67,0,0, - 0,78,40,8,0,0,0,244,12,0,0,0,103,101,116,95, - 102,105,108,101,110,97,109,101,114,56,0,0,0,244,8,0, - 0,0,95,95,102,105,108,101,95,95,114,157,0,0,0,114, - 158,0,0,0,114,159,0,0,0,244,6,0,0,0,97,112, - 112,101,110,100,114,38,0,0,0,40,2,0,0,0,114,160, - 0,0,0,114,161,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,244,16,0,0,0,95,105,110,105, - 116,95,102,105,108,101,95,97,116,116,114,115,47,2,0,0, - 115,12,0,0,0,0,2,3,1,25,1,13,1,5,2,18, - 1,114,166,0,0,0,99,1,0,0,0,0,0,0,0,2, + 109,111,118,101,100,49,1,0,0,115,2,0,0,0,0,8, + 117,25,0,0,0,95,99,97,108,108,95,119,105,116,104,95, + 102,114,97,109,101,115,95,114,101,109,111,118,101,100,105,158, + 12,0,0,117,1,0,0,0,13,105,16,0,0,0,117,1, + 0,0,0,10,105,24,0,0,0,99,1,0,0,0,0,0, + 0,0,2,0,0,0,3,0,0,0,99,0,0,0,115,29, + 0,0,0,124,0,0,93,19,0,125,1,0,116,0,0,124, + 1,0,63,100,0,0,64,86,1,113,3,0,100,1,0,83, + 40,2,0,0,0,105,255,0,0,0,78,40,1,0,0,0, + 117,17,0,0,0,95,82,65,87,95,77,65,71,73,67,95, + 78,85,77,66,69,82,40,2,0,0,0,117,2,0,0,0, + 46,48,117,1,0,0,0,110,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,9,0,0,0,60,103,101,110,101,120,112, + 114,62,150,1,0,0,115,2,0,0,0,6,0,117,9,0, + 0,0,60,103,101,110,101,120,112,114,62,105,0,0,0,0, + 105,25,0,0,0,105,8,0,0,0,117,11,0,0,0,95, + 95,112,121,99,97,99,104,101,95,95,117,3,0,0,0,46, + 112,121,117,4,0,0,0,46,112,121,99,117,4,0,0,0, + 46,112,121,111,78,99,2,0,0,0,0,0,0,0,11,0, + 0,0,6,0,0,0,67,0,0,0,115,180,0,0,0,124, + 1,0,100,1,0,107,8,0,114,25,0,116,0,0,106,1, + 0,106,2,0,12,110,3,0,124,1,0,125,2,0,124,2, + 0,114,46,0,116,3,0,125,3,0,110,6,0,116,4,0, + 125,3,0,116,5,0,124,0,0,131,1,0,92,2,0,125, + 4,0,125,5,0,124,5,0,106,6,0,100,2,0,131,1, + 0,92,3,0,125,6,0,125,7,0,125,8,0,116,0,0, + 106,7,0,106,8,0,125,9,0,124,9,0,100,1,0,107, + 8,0,114,133,0,116,9,0,100,3,0,131,1,0,130,1, + 0,110,0,0,100,4,0,106,10,0,124,6,0,124,7,0, + 124,9,0,124,3,0,100,5,0,25,103,4,0,131,1,0, + 125,10,0,116,11,0,124,4,0,116,12,0,124,10,0,131, + 3,0,83,40,6,0,0,0,117,244,1,0,0,71,105,118, + 101,110,32,116,104,101,32,112,97,116,104,32,116,111,32,97, + 32,46,112,121,32,102,105,108,101,44,32,114,101,116,117,114, + 110,32,116,104,101,32,112,97,116,104,32,116,111,32,105,116, + 115,32,46,112,121,99,47,46,112,121,111,32,102,105,108,101, + 46,10,10,32,32,32,32,84,104,101,32,46,112,121,32,102, + 105,108,101,32,100,111,101,115,32,110,111,116,32,110,101,101, + 100,32,116,111,32,101,120,105,115,116,59,32,116,104,105,115, + 32,115,105,109,112,108,121,32,114,101,116,117,114,110,115,32, + 116,104,101,32,112,97,116,104,32,116,111,32,116,104,101,10, + 32,32,32,32,46,112,121,99,47,46,112,121,111,32,102,105, + 108,101,32,99,97,108,99,117,108,97,116,101,100,32,97,115, + 32,105,102,32,116,104,101,32,46,112,121,32,102,105,108,101, + 32,119,101,114,101,32,105,109,112,111,114,116,101,100,46,32, + 32,84,104,101,32,101,120,116,101,110,115,105,111,110,10,32, + 32,32,32,119,105,108,108,32,98,101,32,46,112,121,99,32, + 117,110,108,101,115,115,32,115,121,115,46,102,108,97,103,115, + 46,111,112,116,105,109,105,122,101,32,105,115,32,110,111,110, + 45,122,101,114,111,44,32,116,104,101,110,32,105,116,32,119, + 105,108,108,32,98,101,32,46,112,121,111,46,10,10,32,32, + 32,32,73,102,32,100,101,98,117,103,95,111,118,101,114,114, + 105,100,101,32,105,115,32,110,111,116,32,78,111,110,101,44, + 32,116,104,101,110,32,105,116,32,109,117,115,116,32,98,101, + 32,97,32,98,111,111,108,101,97,110,32,97,110,100,32,105, + 115,32,117,115,101,100,32,105,110,10,32,32,32,32,112,108, + 97,99,101,32,111,102,32,115,121,115,46,102,108,97,103,115, + 46,111,112,116,105,109,105,122,101,46,10,10,32,32,32,32, + 73,102,32,115,121,115,46,105,109,112,108,101,109,101,110,116, + 97,116,105,111,110,46,99,97,99,104,101,95,116,97,103,32, + 105,115,32,78,111,110,101,32,116,104,101,110,32,78,111,116, + 73,109,112,108,101,109,101,110,116,101,100,69,114,114,111,114, + 32,105,115,32,114,97,105,115,101,100,46,10,10,32,32,32, + 32,78,117,1,0,0,0,46,117,36,0,0,0,115,121,115, + 46,105,109,112,108,101,109,101,110,116,97,116,105,111,110,46, + 99,97,99,104,101,95,116,97,103,32,105,115,32,78,111,110, + 101,117,0,0,0,0,105,0,0,0,0,40,13,0,0,0, + 117,3,0,0,0,115,121,115,117,5,0,0,0,102,108,97, + 103,115,117,8,0,0,0,111,112,116,105,109,105,122,101,117, + 23,0,0,0,68,69,66,85,71,95,66,89,84,69,67,79, + 68,69,95,83,85,70,70,73,88,69,83,117,27,0,0,0, + 79,80,84,73,77,73,90,69,68,95,66,89,84,69,67,79, + 68,69,95,83,85,70,70,73,88,69,83,117,11,0,0,0, + 95,112,97,116,104,95,115,112,108,105,116,117,9,0,0,0, + 112,97,114,116,105,116,105,111,110,117,14,0,0,0,105,109, + 112,108,101,109,101,110,116,97,116,105,111,110,117,9,0,0, + 0,99,97,99,104,101,95,116,97,103,117,19,0,0,0,78, + 111,116,73,109,112,108,101,109,101,110,116,101,100,69,114,114, + 111,114,117,4,0,0,0,106,111,105,110,117,10,0,0,0, + 95,112,97,116,104,95,106,111,105,110,117,8,0,0,0,95, + 80,89,67,65,67,72,69,40,11,0,0,0,117,4,0,0, + 0,112,97,116,104,117,14,0,0,0,100,101,98,117,103,95, + 111,118,101,114,114,105,100,101,117,5,0,0,0,100,101,98, + 117,103,117,8,0,0,0,115,117,102,102,105,120,101,115,117, + 4,0,0,0,104,101,97,100,117,4,0,0,0,116,97,105, + 108,117,13,0,0,0,98,97,115,101,95,102,105,108,101,110, + 97,109,101,117,3,0,0,0,115,101,112,117,1,0,0,0, + 95,117,3,0,0,0,116,97,103,117,8,0,0,0,102,105, + 108,101,110,97,109,101,40,0,0,0,0,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,17,0,0,0,99,97,99,104,101,95,102,114,111, + 109,95,115,111,117,114,99,101,159,1,0,0,115,22,0,0, + 0,0,13,31,1,6,1,9,2,6,1,18,1,24,1,12, + 1,12,1,15,1,31,1,117,17,0,0,0,99,97,99,104, + 101,95,102,114,111,109,95,115,111,117,114,99,101,99,1,0, + 0,0,0,0,0,0,5,0,0,0,5,0,0,0,67,0, + 0,0,115,193,0,0,0,116,0,0,106,1,0,106,2,0, + 100,1,0,107,8,0,114,33,0,116,3,0,100,2,0,131, + 1,0,130,1,0,110,0,0,116,4,0,124,0,0,131,1, + 0,92,2,0,125,1,0,125,2,0,116,4,0,124,1,0, + 131,1,0,92,2,0,125,1,0,125,3,0,124,3,0,116, + 5,0,107,3,0,114,108,0,116,6,0,100,3,0,106,7, + 0,116,5,0,124,0,0,131,2,0,131,1,0,130,1,0, + 110,0,0,124,2,0,106,8,0,100,4,0,131,1,0,100, + 5,0,107,3,0,114,153,0,116,6,0,100,6,0,106,7, + 0,124,2,0,131,1,0,131,1,0,130,1,0,110,0,0, + 124,2,0,106,9,0,100,4,0,131,1,0,100,7,0,25, + 125,4,0,116,10,0,124,1,0,124,4,0,116,11,0,100, + 7,0,25,23,131,2,0,83,40,8,0,0,0,117,121,1, + 0,0,71,105,118,101,110,32,116,104,101,32,112,97,116,104, + 32,116,111,32,97,32,46,112,121,99,46,47,46,112,121,111, + 32,102,105,108,101,44,32,114,101,116,117,114,110,32,116,104, + 101,32,112,97,116,104,32,116,111,32,105,116,115,32,46,112, + 121,32,102,105,108,101,46,10,10,32,32,32,32,84,104,101, + 32,46,112,121,99,47,46,112,121,111,32,102,105,108,101,32, + 100,111,101,115,32,110,111,116,32,110,101,101,100,32,116,111, + 32,101,120,105,115,116,59,32,116,104,105,115,32,115,105,109, + 112,108,121,32,114,101,116,117,114,110,115,32,116,104,101,32, + 112,97,116,104,32,116,111,10,32,32,32,32,116,104,101,32, + 46,112,121,32,102,105,108,101,32,99,97,108,99,117,108,97, + 116,101,100,32,116,111,32,99,111,114,114,101,115,112,111,110, + 100,32,116,111,32,116,104,101,32,46,112,121,99,47,46,112, + 121,111,32,102,105,108,101,46,32,32,73,102,32,112,97,116, + 104,32,100,111,101,115,10,32,32,32,32,110,111,116,32,99, + 111,110,102,111,114,109,32,116,111,32,80,69,80,32,51,49, + 52,55,32,102,111,114,109,97,116,44,32,86,97,108,117,101, + 69,114,114,111,114,32,119,105,108,108,32,98,101,32,114,97, + 105,115,101,100,46,32,73,102,10,32,32,32,32,115,121,115, + 46,105,109,112,108,101,109,101,110,116,97,116,105,111,110,46, + 99,97,99,104,101,95,116,97,103,32,105,115,32,78,111,110, + 101,32,116,104,101,110,32,78,111,116,73,109,112,108,101,109, + 101,110,116,101,100,69,114,114,111,114,32,105,115,32,114,97, + 105,115,101,100,46,10,10,32,32,32,32,78,117,36,0,0, + 0,115,121,115,46,105,109,112,108,101,109,101,110,116,97,116, + 105,111,110,46,99,97,99,104,101,95,116,97,103,32,105,115, + 32,78,111,110,101,117,37,0,0,0,123,125,32,110,111,116, + 32,98,111,116,116,111,109,45,108,101,118,101,108,32,100,105, + 114,101,99,116,111,114,121,32,105,110,32,123,33,114,125,117, + 1,0,0,0,46,105,2,0,0,0,117,28,0,0,0,101, + 120,112,101,99,116,101,100,32,111,110,108,121,32,50,32,100, + 111,116,115,32,105,110,32,123,33,114,125,105,0,0,0,0, + 40,12,0,0,0,117,3,0,0,0,115,121,115,117,14,0, + 0,0,105,109,112,108,101,109,101,110,116,97,116,105,111,110, + 117,9,0,0,0,99,97,99,104,101,95,116,97,103,117,19, + 0,0,0,78,111,116,73,109,112,108,101,109,101,110,116,101, + 100,69,114,114,111,114,117,11,0,0,0,95,112,97,116,104, + 95,115,112,108,105,116,117,8,0,0,0,95,80,89,67,65, + 67,72,69,117,10,0,0,0,86,97,108,117,101,69,114,114, + 111,114,117,6,0,0,0,102,111,114,109,97,116,117,5,0, + 0,0,99,111,117,110,116,117,9,0,0,0,112,97,114,116, + 105,116,105,111,110,117,10,0,0,0,95,112,97,116,104,95, + 106,111,105,110,117,15,0,0,0,83,79,85,82,67,69,95, + 83,85,70,70,73,88,69,83,40,5,0,0,0,117,4,0, + 0,0,112,97,116,104,117,4,0,0,0,104,101,97,100,117, + 16,0,0,0,112,121,99,97,99,104,101,95,102,105,108,101, + 110,97,109,101,117,7,0,0,0,112,121,99,97,99,104,101, + 117,13,0,0,0,98,97,115,101,95,102,105,108,101,110,97, + 109,101,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,17, + 0,0,0,115,111,117,114,99,101,95,102,114,111,109,95,99, + 97,99,104,101,186,1,0,0,115,24,0,0,0,0,9,18, + 1,15,1,18,1,18,1,12,1,9,1,18,1,21,1,9, + 1,15,1,19,1,117,17,0,0,0,115,111,117,114,99,101, + 95,102,114,111,109,95,99,97,99,104,101,99,1,0,0,0, + 0,0,0,0,5,0,0,0,13,0,0,0,67,0,0,0, + 115,164,0,0,0,116,0,0,124,0,0,131,1,0,100,1, + 0,107,2,0,114,22,0,100,2,0,83,124,0,0,106,1, + 0,100,3,0,131,1,0,92,3,0,125,1,0,125,2,0, + 125,3,0,124,1,0,12,115,81,0,124,3,0,106,2,0, + 131,0,0,100,7,0,100,8,0,133,2,0,25,100,6,0, + 107,3,0,114,85,0,124,0,0,83,121,16,0,116,3,0, + 124,0,0,131,1,0,125,4,0,87,110,40,0,4,116,4, + 0,116,5,0,102,2,0,107,10,0,114,143,0,1,1,1, + 116,6,0,100,9,0,100,2,0,133,2,0,25,125,4,0, + 89,110,1,0,88,116,7,0,116,8,0,131,1,0,114,160, + 0,124,4,0,83,124,0,0,83,40,10,0,0,0,117,188, + 0,0,0,67,111,110,118,101,114,116,32,97,32,98,121,116, + 101,99,111,100,101,32,102,105,108,101,32,112,97,116,104,32, + 116,111,32,97,32,115,111,117,114,99,101,32,112,97,116,104, + 32,40,105,102,32,112,111,115,115,105,98,108,101,41,46,10, + 10,32,32,32,32,84,104,105,115,32,102,117,110,99,116,105, + 111,110,32,101,120,105,115,116,115,32,112,117,114,101,108,121, + 32,102,111,114,32,98,97,99,107,119,97,114,100,115,45,99, + 111,109,112,97,116,105,98,105,108,105,116,121,32,102,111,114, + 10,32,32,32,32,80,121,73,109,112,111,114,116,95,69,120, + 101,99,67,111,100,101,77,111,100,117,108,101,87,105,116,104, + 70,105,108,101,110,97,109,101,115,40,41,32,105,110,32,116, + 104,101,32,67,32,65,80,73,46,10,10,32,32,32,32,105, + 0,0,0,0,78,117,1,0,0,0,46,105,3,0,0,0, + 105,1,0,0,0,117,3,0,0,0,46,112,121,105,253,255, + 255,255,105,255,255,255,255,105,255,255,255,255,40,9,0,0, + 0,117,3,0,0,0,108,101,110,117,9,0,0,0,114,112, + 97,114,105,116,105,111,110,117,5,0,0,0,108,111,119,101, + 114,117,17,0,0,0,115,111,117,114,99,101,95,102,114,111, + 109,95,99,97,99,104,101,117,19,0,0,0,78,111,116,73, + 109,112,108,101,109,101,110,116,101,100,69,114,114,111,114,117, + 10,0,0,0,86,97,108,117,101,69,114,114,111,114,117,12, + 0,0,0,98,121,116,99,111,100,101,95,112,97,116,104,117, + 12,0,0,0,95,112,97,116,104,95,105,115,102,105,108,101, + 117,12,0,0,0,115,111,117,114,99,101,95,115,116,97,116, + 115,40,5,0,0,0,117,13,0,0,0,98,121,116,101,99, + 111,100,101,95,112,97,116,104,117,4,0,0,0,114,101,115, + 116,117,1,0,0,0,95,117,9,0,0,0,101,120,116,101, + 110,115,105,111,110,117,11,0,0,0,115,111,117,114,99,101, + 95,112,97,116,104,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,15,0,0,0,95,103,101,116,95,115,111,117,114,99, + 101,102,105,108,101,209,1,0,0,115,20,0,0,0,0,7, + 18,1,4,1,24,1,35,1,4,2,3,1,16,1,19,1, + 21,2,117,15,0,0,0,95,103,101,116,95,115,111,117,114, + 99,101,102,105,108,101,99,1,0,0,0,0,0,0,0,2, + 0,0,0,4,0,0,0,71,0,0,0,115,75,0,0,0, + 116,0,0,106,1,0,106,2,0,114,71,0,124,0,0,106, + 3,0,100,6,0,131,1,0,115,40,0,100,3,0,124,0, + 0,23,125,0,0,110,0,0,116,4,0,124,0,0,106,5, + 0,124,1,0,140,0,0,100,4,0,116,0,0,106,6,0, + 131,1,1,1,110,0,0,100,5,0,83,40,7,0,0,0, + 117,61,0,0,0,80,114,105,110,116,32,116,104,101,32,109, + 101,115,115,97,103,101,32,116,111,32,115,116,100,101,114,114, + 32,105,102,32,45,118,47,80,89,84,72,79,78,86,69,82, + 66,79,83,69,32,105,115,32,116,117,114,110,101,100,32,111, + 110,46,117,1,0,0,0,35,117,7,0,0,0,105,109,112, + 111,114,116,32,117,2,0,0,0,35,32,117,4,0,0,0, + 102,105,108,101,78,40,2,0,0,0,117,1,0,0,0,35, + 117,7,0,0,0,105,109,112,111,114,116,32,40,7,0,0, + 0,117,3,0,0,0,115,121,115,117,5,0,0,0,102,108, + 97,103,115,117,7,0,0,0,118,101,114,98,111,115,101,117, + 10,0,0,0,115,116,97,114,116,115,119,105,116,104,117,5, + 0,0,0,112,114,105,110,116,117,6,0,0,0,102,111,114, + 109,97,116,117,6,0,0,0,115,116,100,101,114,114,40,2, + 0,0,0,117,7,0,0,0,109,101,115,115,97,103,101,117, + 4,0,0,0,97,114,103,115,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,16,0,0,0,95,118,101,114,98,111,115, + 101,95,109,101,115,115,97,103,101,230,1,0,0,115,8,0, + 0,0,0,2,12,1,15,1,13,1,117,16,0,0,0,95, + 118,101,114,98,111,115,101,95,109,101,115,115,97,103,101,99, + 1,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, + 3,0,0,0,115,35,0,0,0,135,0,0,102,1,0,100, + 1,0,100,2,0,134,0,0,125,1,0,116,0,0,124,1, + 0,136,0,0,131,2,0,1,124,1,0,83,40,3,0,0, + 0,117,39,0,0,0,83,101,116,32,95,95,112,97,99,107, + 97,103,101,95,95,32,111,110,32,116,104,101,32,114,101,116, + 117,114,110,101,100,32,109,111,100,117,108,101,46,99,0,0, + 0,0,0,0,0,0,3,0,0,0,4,0,0,0,31,0, + 0,0,115,101,0,0,0,136,0,0,124,0,0,124,1,0, + 142,0,0,125,2,0,116,0,0,124,2,0,100,1,0,100, + 0,0,131,3,0,100,0,0,107,8,0,114,97,0,124,2, + 0,106,1,0,124,2,0,95,2,0,116,3,0,124,2,0, + 100,2,0,131,2,0,115,97,0,124,2,0,106,2,0,106, + 4,0,100,3,0,131,1,0,100,4,0,25,124,2,0,95, + 2,0,113,97,0,110,0,0,124,2,0,83,40,5,0,0, + 0,78,117,11,0,0,0,95,95,112,97,99,107,97,103,101, + 95,95,117,8,0,0,0,95,95,112,97,116,104,95,95,117, + 1,0,0,0,46,105,0,0,0,0,40,5,0,0,0,117, + 7,0,0,0,103,101,116,97,116,116,114,117,8,0,0,0, + 95,95,110,97,109,101,95,95,117,11,0,0,0,95,95,112, + 97,99,107,97,103,101,95,95,117,7,0,0,0,104,97,115, + 97,116,116,114,117,10,0,0,0,114,112,97,114,116,105,116, + 105,111,110,40,3,0,0,0,117,4,0,0,0,97,114,103, + 115,117,6,0,0,0,107,119,97,114,103,115,117,6,0,0, + 0,109,111,100,117,108,101,40,1,0,0,0,117,3,0,0, + 0,102,120,110,40,0,0,0,0,117,29,0,0,0,60,102, + 114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46, + 95,98,111,111,116,115,116,114,97,112,62,117,19,0,0,0, + 115,101,116,95,112,97,99,107,97,103,101,95,119,114,97,112, + 112,101,114,240,1,0,0,115,12,0,0,0,0,1,15,1, + 24,1,12,1,15,1,31,1,117,40,0,0,0,115,101,116, + 95,112,97,99,107,97,103,101,46,60,108,111,99,97,108,115, + 62,46,115,101,116,95,112,97,99,107,97,103,101,95,119,114, + 97,112,112,101,114,40,1,0,0,0,117,5,0,0,0,95, + 119,114,97,112,40,2,0,0,0,117,3,0,0,0,102,120, + 110,117,19,0,0,0,115,101,116,95,112,97,99,107,97,103, + 101,95,119,114,97,112,112,101,114,40,0,0,0,0,40,1, + 0,0,0,117,3,0,0,0,102,120,110,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,11,0, + 0,0,115,101,116,95,112,97,99,107,97,103,101,238,1,0, + 0,115,6,0,0,0,0,2,18,7,13,1,117,11,0,0, + 0,115,101,116,95,112,97,99,107,97,103,101,99,1,0,0, + 0,0,0,0,0,2,0,0,0,3,0,0,0,3,0,0, + 0,115,35,0,0,0,135,0,0,102,1,0,100,1,0,100, + 2,0,134,0,0,125,1,0,116,0,0,124,1,0,136,0, + 0,131,2,0,1,124,1,0,83,40,3,0,0,0,117,38, + 0,0,0,83,101,116,32,95,95,108,111,97,100,101,114,95, + 95,32,111,110,32,116,104,101,32,114,101,116,117,114,110,101, + 100,32,109,111,100,117,108,101,46,99,1,0,0,0,0,0, + 0,0,4,0,0,0,4,0,0,0,31,0,0,0,115,49, + 0,0,0,136,0,0,124,0,0,124,1,0,124,2,0,142, + 1,0,125,3,0,116,0,0,124,3,0,100,1,0,131,2, + 0,115,45,0,124,0,0,124,3,0,95,1,0,110,0,0, + 124,3,0,83,40,2,0,0,0,78,117,10,0,0,0,95, + 95,108,111,97,100,101,114,95,95,40,2,0,0,0,117,7, + 0,0,0,104,97,115,97,116,116,114,117,10,0,0,0,95, + 95,108,111,97,100,101,114,95,95,40,4,0,0,0,117,4, + 0,0,0,115,101,108,102,117,4,0,0,0,97,114,103,115, + 117,6,0,0,0,107,119,97,114,103,115,117,6,0,0,0, + 109,111,100,117,108,101,40,1,0,0,0,117,3,0,0,0, + 102,120,110,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,18,0,0,0,115, + 101,116,95,108,111,97,100,101,114,95,119,114,97,112,112,101, + 114,253,1,0,0,115,8,0,0,0,0,1,18,1,15,1, + 12,1,117,38,0,0,0,115,101,116,95,108,111,97,100,101, + 114,46,60,108,111,99,97,108,115,62,46,115,101,116,95,108, + 111,97,100,101,114,95,119,114,97,112,112,101,114,40,1,0, + 0,0,117,5,0,0,0,95,119,114,97,112,40,2,0,0, + 0,117,3,0,0,0,102,120,110,117,18,0,0,0,115,101, + 116,95,108,111,97,100,101,114,95,119,114,97,112,112,101,114, + 40,0,0,0,0,40,1,0,0,0,117,3,0,0,0,102, + 120,110,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,10,0,0,0,115,101,116,95,108,111,97, + 100,101,114,251,1,0,0,115,6,0,0,0,0,2,18,5, + 13,1,117,10,0,0,0,115,101,116,95,108,111,97,100,101, + 114,99,1,0,0,0,0,0,0,0,2,0,0,0,3,0, + 0,0,3,0,0,0,115,35,0,0,0,135,0,0,102,1, + 0,100,1,0,100,2,0,134,0,0,125,1,0,116,0,0, + 124,1,0,136,0,0,131,2,0,1,124,1,0,83,40,3, + 0,0,0,117,42,3,0,0,68,101,99,111,114,97,116,111, + 114,32,116,111,32,104,97,110,100,108,101,32,115,101,108,101, + 99,116,105,110,103,32,116,104,101,32,112,114,111,112,101,114, + 32,109,111,100,117,108,101,32,102,111,114,32,108,111,97,100, + 101,114,115,46,10,10,32,32,32,32,84,104,101,32,100,101, + 99,111,114,97,116,101,100,32,102,117,110,99,116,105,111,110, + 32,105,115,32,112,97,115,115,101,100,32,116,104,101,32,109, + 111,100,117,108,101,32,116,111,32,117,115,101,32,105,110,115, + 116,101,97,100,32,111,102,32,116,104,101,32,109,111,100,117, + 108,101,10,32,32,32,32,110,97,109,101,46,32,84,104,101, + 32,109,111,100,117,108,101,32,112,97,115,115,101,100,32,105, + 110,32,116,111,32,116,104,101,32,102,117,110,99,116,105,111, + 110,32,105,115,32,101,105,116,104,101,114,32,102,114,111,109, + 32,115,121,115,46,109,111,100,117,108,101,115,32,105,102,10, + 32,32,32,32,105,116,32,97,108,114,101,97,100,121,32,101, + 120,105,115,116,115,32,111,114,32,105,115,32,97,32,110,101, + 119,32,109,111,100,117,108,101,46,32,73,102,32,116,104,101, + 32,109,111,100,117,108,101,32,105,115,32,110,101,119,44,32, + 116,104,101,110,32,95,95,110,97,109,101,95,95,10,32,32, + 32,32,105,115,32,115,101,116,32,116,104,101,32,102,105,114, + 115,116,32,97,114,103,117,109,101,110,116,32,116,111,32,116, + 104,101,32,109,101,116,104,111,100,44,32,95,95,108,111,97, + 100,101,114,95,95,32,105,115,32,115,101,116,32,116,111,32, + 115,101,108,102,44,32,97,110,100,10,32,32,32,32,95,95, + 112,97,99,107,97,103,101,95,95,32,105,115,32,115,101,116, + 32,97,99,99,111,114,100,105,110,103,108,121,32,40,105,102, + 32,115,101,108,102,46,105,115,95,112,97,99,107,97,103,101, + 40,41,32,105,115,32,100,101,102,105,110,101,100,41,32,119, + 105,108,108,32,98,101,32,115,101,116,10,32,32,32,32,98, + 101,102,111,114,101,32,105,116,32,105,115,32,112,97,115,115, + 101,100,32,116,111,32,116,104,101,32,100,101,99,111,114,97, + 116,101,100,32,102,117,110,99,116,105,111,110,32,40,105,102, + 32,115,101,108,102,46,105,115,95,112,97,99,107,97,103,101, + 40,41,32,100,111,101,115,10,32,32,32,32,110,111,116,32, + 119,111,114,107,32,102,111,114,32,116,104,101,32,109,111,100, + 117,108,101,32,105,116,32,119,105,108,108,32,98,101,32,115, + 101,116,32,112,111,115,116,45,108,111,97,100,41,46,10,10, + 32,32,32,32,73,102,32,97,110,32,101,120,99,101,112,116, + 105,111,110,32,105,115,32,114,97,105,115,101,100,32,97,110, + 100,32,116,104,101,32,100,101,99,111,114,97,116,111,114,32, + 99,114,101,97,116,101,100,32,116,104,101,32,109,111,100,117, + 108,101,32,105,116,32,105,115,10,32,32,32,32,115,117,98, + 115,101,113,117,101,110,116,108,121,32,114,101,109,111,118,101, + 100,32,102,114,111,109,32,115,121,115,46,109,111,100,117,108, + 101,115,46,10,10,32,32,32,32,84,104,101,32,100,101,99, + 111,114,97,116,111,114,32,97,115,115,117,109,101,115,32,116, + 104,97,116,32,116,104,101,32,100,101,99,111,114,97,116,101, + 100,32,102,117,110,99,116,105,111,110,32,116,97,107,101,115, + 32,116,104,101,32,109,111,100,117,108,101,32,110,97,109,101, + 32,97,115,10,32,32,32,32,116,104,101,32,115,101,99,111, + 110,100,32,97,114,103,117,109,101,110,116,46,10,10,32,32, + 32,32,99,2,0,0,0,0,0,0,0,7,0,0,0,25, + 0,0,0,31,0,0,0,115,254,0,0,0,116,0,0,106, + 1,0,106,2,0,124,1,0,131,1,0,125,4,0,124,4, + 0,100,0,0,107,9,0,125,5,0,124,5,0,115,168,0, + 116,3,0,124,1,0,131,1,0,125,4,0,100,1,0,124, + 4,0,95,4,0,124,4,0,116,0,0,106,1,0,124,1, + 0,60,124,0,0,124,4,0,95,5,0,121,19,0,124,0, + 0,106,6,0,124,1,0,131,1,0,125,6,0,87,110,24, + 0,4,116,7,0,116,8,0,102,2,0,107,10,0,114,124, + 0,1,1,1,89,113,177,0,88,124,6,0,114,143,0,124, + 1,0,124,4,0,95,9,0,113,177,0,124,1,0,106,10, + 0,100,2,0,131,1,0,100,3,0,25,124,4,0,95,9, + 0,110,9,0,100,1,0,124,4,0,95,4,0,122,60,0, + 121,23,0,136,0,0,124,0,0,124,4,0,124,2,0,124, + 3,0,142,2,0,83,87,110,30,0,1,1,1,124,5,0, + 115,228,0,116,0,0,106,1,0,124,1,0,61,110,0,0, + 130,0,0,89,110,1,0,88,87,100,0,0,100,4,0,124, + 4,0,95,4,0,88,100,0,0,83,40,5,0,0,0,78, + 84,117,1,0,0,0,46,105,0,0,0,0,70,40,11,0, + 0,0,117,3,0,0,0,115,121,115,117,7,0,0,0,109, + 111,100,117,108,101,115,117,3,0,0,0,103,101,116,117,10, + 0,0,0,110,101,119,95,109,111,100,117,108,101,117,16,0, + 0,0,95,95,105,110,105,116,105,97,108,105,122,105,110,103, + 95,95,117,10,0,0,0,95,95,108,111,97,100,101,114,95, + 95,117,10,0,0,0,105,115,95,112,97,99,107,97,103,101, + 117,11,0,0,0,73,109,112,111,114,116,69,114,114,111,114, + 117,14,0,0,0,65,116,116,114,105,98,117,116,101,69,114, + 114,111,114,117,11,0,0,0,95,95,112,97,99,107,97,103, + 101,95,95,117,10,0,0,0,114,112,97,114,116,105,116,105, + 111,110,40,7,0,0,0,117,4,0,0,0,115,101,108,102, + 117,8,0,0,0,102,117,108,108,110,97,109,101,117,4,0, + 0,0,97,114,103,115,117,6,0,0,0,107,119,97,114,103, + 115,117,6,0,0,0,109,111,100,117,108,101,117,9,0,0, + 0,105,115,95,114,101,108,111,97,100,117,10,0,0,0,105, + 115,95,112,97,99,107,97,103,101,40,1,0,0,0,117,3, + 0,0,0,102,120,110,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,25,0, + 0,0,109,111,100,117,108,101,95,102,111,114,95,108,111,97, + 100,101,114,95,119,114,97,112,112,101,114,24,2,0,0,115, + 44,0,0,0,0,1,18,1,12,1,6,4,12,3,9,1, + 13,1,9,1,3,1,19,1,19,1,5,2,6,1,12,2, + 25,2,9,1,6,2,23,1,3,1,6,1,13,1,12,2, + 117,52,0,0,0,109,111,100,117,108,101,95,102,111,114,95, + 108,111,97,100,101,114,46,60,108,111,99,97,108,115,62,46, + 109,111,100,117,108,101,95,102,111,114,95,108,111,97,100,101, + 114,95,119,114,97,112,112,101,114,40,1,0,0,0,117,5, + 0,0,0,95,119,114,97,112,40,2,0,0,0,117,3,0, + 0,0,102,120,110,117,25,0,0,0,109,111,100,117,108,101, + 95,102,111,114,95,108,111,97,100,101,114,95,119,114,97,112, + 112,101,114,40,0,0,0,0,40,1,0,0,0,117,3,0, + 0,0,102,120,110,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,17,0,0,0,109,111,100,117, + 108,101,95,102,111,114,95,108,111,97,100,101,114,6,2,0, + 0,115,6,0,0,0,0,18,18,33,13,1,117,17,0,0, + 0,109,111,100,117,108,101,95,102,111,114,95,108,111,97,100, + 101,114,99,1,0,0,0,0,0,0,0,2,0,0,0,4, + 0,0,0,3,0,0,0,115,38,0,0,0,100,1,0,135, + 0,0,102,1,0,100,2,0,100,3,0,134,1,0,125,1, + 0,116,0,0,124,1,0,136,0,0,131,2,0,1,124,1, + 0,83,40,4,0,0,0,117,252,0,0,0,68,101,99,111, + 114,97,116,111,114,32,116,111,32,118,101,114,105,102,121,32, + 116,104,97,116,32,116,104,101,32,109,111,100,117,108,101,32, + 98,101,105,110,103,32,114,101,113,117,101,115,116,101,100,32, + 109,97,116,99,104,101,115,32,116,104,101,32,111,110,101,32, + 116,104,101,10,32,32,32,32,108,111,97,100,101,114,32,99, + 97,110,32,104,97,110,100,108,101,46,10,10,32,32,32,32, + 84,104,101,32,102,105,114,115,116,32,97,114,103,117,109,101, + 110,116,32,40,115,101,108,102,41,32,109,117,115,116,32,100, + 101,102,105,110,101,32,95,110,97,109,101,32,119,104,105,99, + 104,32,116,104,101,32,115,101,99,111,110,100,32,97,114,103, + 117,109,101,110,116,32,105,115,10,32,32,32,32,99,111,109, + 112,97,114,101,100,32,97,103,97,105,110,115,116,46,32,73, + 102,32,116,104,101,32,99,111,109,112,97,114,105,115,111,110, + 32,102,97,105,108,115,32,116,104,101,110,32,73,109,112,111, + 114,116,69,114,114,111,114,32,105,115,32,114,97,105,115,101, + 100,46,10,10,32,32,32,32,78,99,2,0,0,0,0,0, + 0,0,4,0,0,0,5,0,0,0,31,0,0,0,115,83, + 0,0,0,124,1,0,100,0,0,107,8,0,114,24,0,124, + 0,0,106,0,0,125,1,0,110,40,0,124,0,0,106,0, + 0,124,1,0,107,3,0,114,64,0,116,1,0,100,1,0, + 124,1,0,22,100,2,0,124,1,0,131,1,1,130,1,0, + 110,0,0,136,0,0,124,0,0,124,1,0,124,2,0,124, + 3,0,142,2,0,83,40,3,0,0,0,78,117,23,0,0, + 0,108,111,97,100,101,114,32,99,97,110,110,111,116,32,104, + 97,110,100,108,101,32,37,115,117,4,0,0,0,110,97,109, + 101,40,2,0,0,0,117,4,0,0,0,110,97,109,101,117, + 11,0,0,0,73,109,112,111,114,116,69,114,114,111,114,40, + 4,0,0,0,117,4,0,0,0,115,101,108,102,117,4,0, + 0,0,110,97,109,101,117,4,0,0,0,97,114,103,115,117, + 6,0,0,0,107,119,97,114,103,115,40,1,0,0,0,117, + 6,0,0,0,109,101,116,104,111,100,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,19,0,0,0,95,99,104,101,99,107,95,110,97,109, + 101,95,119,114,97,112,112,101,114,69,2,0,0,115,10,0, + 0,0,0,1,12,1,12,1,15,1,25,1,117,40,0,0, + 0,95,99,104,101,99,107,95,110,97,109,101,46,60,108,111, + 99,97,108,115,62,46,95,99,104,101,99,107,95,110,97,109, + 101,95,119,114,97,112,112,101,114,40,1,0,0,0,117,5, + 0,0,0,95,119,114,97,112,40,2,0,0,0,117,6,0, + 0,0,109,101,116,104,111,100,117,19,0,0,0,95,99,104, + 101,99,107,95,110,97,109,101,95,119,114,97,112,112,101,114, + 40,0,0,0,0,40,1,0,0,0,117,6,0,0,0,109, + 101,116,104,111,100,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,11,0,0,0,95,99,104,101, + 99,107,95,110,97,109,101,61,2,0,0,115,6,0,0,0, + 0,8,21,6,13,1,117,11,0,0,0,95,99,104,101,99, + 107,95,110,97,109,101,99,1,0,0,0,0,0,0,0,2, 0,0,0,3,0,0,0,3,0,0,0,115,35,0,0,0, 135,0,0,102,1,0,100,1,0,100,2,0,134,0,0,125, 1,0,116,0,0,124,1,0,136,0,0,131,2,0,1,124, - 1,0,83,40,3,0,0,0,117,39,0,0,0,83,101,116, - 32,95,95,112,97,99,107,97,103,101,95,95,32,111,110,32, - 116,104,101,32,114,101,116,117,114,110,101,100,32,109,111,100, - 117,108,101,46,99,0,0,0,0,0,0,0,0,3,0,0, - 0,4,0,0,0,31,0,0,0,115,101,0,0,0,136,0, - 0,124,0,0,124,1,0,142,0,0,125,2,0,116,0,0, - 124,2,0,100,1,0,100,0,0,131,3,0,100,0,0,107, - 8,0,114,97,0,124,2,0,106,1,0,124,2,0,95,2, - 0,116,3,0,124,2,0,100,2,0,131,2,0,115,97,0, - 124,2,0,106,2,0,106,4,0,100,3,0,131,1,0,100, - 4,0,25,124,2,0,95,2,0,113,97,0,110,0,0,124, - 2,0,83,40,5,0,0,0,78,114,158,0,0,0,114,159, - 0,0,0,114,101,0,0,0,114,67,0,0,0,40,5,0, - 0,0,114,61,0,0,0,114,56,0,0,0,114,158,0,0, - 0,114,59,0,0,0,114,32,0,0,0,40,3,0,0,0, - 114,98,0,0,0,244,6,0,0,0,107,119,97,114,103,115, - 114,161,0,0,0,40,1,0,0,0,244,3,0,0,0,102, - 120,110,114,4,0,0,0,114,5,0,0,0,244,19,0,0, - 0,115,101,116,95,112,97,99,107,97,103,101,95,119,114,97, - 112,112,101,114,60,2,0,0,115,12,0,0,0,0,1,15, - 1,24,1,12,1,15,1,31,1,117,40,0,0,0,115,101, - 116,95,112,97,99,107,97,103,101,46,60,108,111,99,97,108, - 115,62,46,115,101,116,95,112,97,99,107,97,103,101,95,119, - 114,97,112,112,101,114,40,1,0,0,0,114,64,0,0,0, - 40,2,0,0,0,114,168,0,0,0,114,169,0,0,0,114, - 4,0,0,0,40,1,0,0,0,114,168,0,0,0,114,5, - 0,0,0,244,11,0,0,0,115,101,116,95,112,97,99,107, - 97,103,101,58,2,0,0,115,6,0,0,0,0,2,18,7, - 13,1,114,170,0,0,0,99,1,0,0,0,0,0,0,0, - 2,0,0,0,3,0,0,0,3,0,0,0,115,35,0,0, - 0,135,0,0,102,1,0,100,1,0,100,2,0,134,0,0, - 125,1,0,116,0,0,124,1,0,136,0,0,131,2,0,1, - 124,1,0,83,40,3,0,0,0,117,38,0,0,0,83,101, - 116,32,95,95,108,111,97,100,101,114,95,95,32,111,110,32, - 116,104,101,32,114,101,116,117,114,110,101,100,32,109,111,100, - 117,108,101,46,99,1,0,0,0,0,0,0,0,4,0,0, - 0,4,0,0,0,31,0,0,0,115,58,0,0,0,136,0, - 0,124,0,0,124,1,0,124,2,0,142,1,0,125,3,0, - 116,0,0,124,3,0,100,1,0,100,0,0,131,3,0,100, - 0,0,107,8,0,114,54,0,124,0,0,124,3,0,95,1, - 0,110,0,0,124,3,0,83,40,2,0,0,0,78,244,10, - 0,0,0,95,95,108,111,97,100,101,114,95,95,40,2,0, - 0,0,114,61,0,0,0,114,171,0,0,0,40,4,0,0, - 0,114,75,0,0,0,114,98,0,0,0,114,167,0,0,0, - 114,161,0,0,0,40,1,0,0,0,114,168,0,0,0,114, - 4,0,0,0,114,5,0,0,0,244,18,0,0,0,115,101, - 116,95,108,111,97,100,101,114,95,119,114,97,112,112,101,114, - 73,2,0,0,115,8,0,0,0,0,1,18,1,24,1,12, - 1,117,38,0,0,0,115,101,116,95,108,111,97,100,101,114, - 46,60,108,111,99,97,108,115,62,46,115,101,116,95,108,111, - 97,100,101,114,95,119,114,97,112,112,101,114,40,1,0,0, - 0,114,64,0,0,0,40,2,0,0,0,114,168,0,0,0, - 114,172,0,0,0,114,4,0,0,0,40,1,0,0,0,114, - 168,0,0,0,114,5,0,0,0,244,10,0,0,0,115,101, - 116,95,108,111,97,100,101,114,71,2,0,0,115,6,0,0, - 0,0,2,18,5,13,1,114,173,0,0,0,99,1,0,0, - 0,0,0,0,0,2,0,0,0,4,0,0,0,3,0,0, - 0,115,38,0,0,0,100,1,0,135,0,0,102,1,0,100, - 2,0,100,3,0,134,1,0,125,1,0,116,0,0,124,1, - 0,136,0,0,131,2,0,1,124,1,0,83,40,4,0,0, - 0,117,252,0,0,0,68,101,99,111,114,97,116,111,114,32, - 116,111,32,118,101,114,105,102,121,32,116,104,97,116,32,116, - 104,101,32,109,111,100,117,108,101,32,98,101,105,110,103,32, - 114,101,113,117,101,115,116,101,100,32,109,97,116,99,104,101, - 115,32,116,104,101,32,111,110,101,32,116,104,101,10,32,32, - 32,32,108,111,97,100,101,114,32,99,97,110,32,104,97,110, - 100,108,101,46,10,10,32,32,32,32,84,104,101,32,102,105, - 114,115,116,32,97,114,103,117,109,101,110,116,32,40,115,101, - 108,102,41,32,109,117,115,116,32,100,101,102,105,110,101,32, - 95,110,97,109,101,32,119,104,105,99,104,32,116,104,101,32, - 115,101,99,111,110,100,32,97,114,103,117,109,101,110,116,32, - 105,115,10,32,32,32,32,99,111,109,112,97,114,101,100,32, - 97,103,97,105,110,115,116,46,32,73,102,32,116,104,101,32, - 99,111,109,112,97,114,105,115,111,110,32,102,97,105,108,115, - 32,116,104,101,110,32,73,109,112,111,114,116,69,114,114,111, - 114,32,105,115,32,114,97,105,115,101,100,46,10,10,32,32, - 32,32,78,99,2,0,0,0,0,0,0,0,4,0,0,0, - 5,0,0,0,31,0,0,0,115,83,0,0,0,124,1,0, - 100,0,0,107,8,0,114,24,0,124,0,0,106,0,0,125, - 1,0,110,40,0,124,0,0,106,0,0,124,1,0,107,3, - 0,114,64,0,116,1,0,100,1,0,124,1,0,22,100,2, - 0,124,1,0,131,1,1,130,1,0,110,0,0,136,0,0, - 124,0,0,124,1,0,124,2,0,124,3,0,142,2,0,83, - 40,3,0,0,0,78,117,23,0,0,0,108,111,97,100,101, - 114,32,99,97,110,110,111,116,32,104,97,110,100,108,101,32, - 37,115,114,71,0,0,0,40,2,0,0,0,114,71,0,0, - 0,114,157,0,0,0,40,4,0,0,0,114,75,0,0,0, - 114,71,0,0,0,114,98,0,0,0,114,167,0,0,0,40, - 1,0,0,0,244,6,0,0,0,109,101,116,104,111,100,114, - 4,0,0,0,114,5,0,0,0,244,19,0,0,0,95,99, - 104,101,99,107,95,110,97,109,101,95,119,114,97,112,112,101, - 114,90,2,0,0,115,10,0,0,0,0,1,12,1,12,1, - 15,1,25,1,117,40,0,0,0,95,99,104,101,99,107,95, - 110,97,109,101,46,60,108,111,99,97,108,115,62,46,95,99, - 104,101,99,107,95,110,97,109,101,95,119,114,97,112,112,101, - 114,40,1,0,0,0,114,64,0,0,0,40,2,0,0,0, - 114,174,0,0,0,114,175,0,0,0,114,4,0,0,0,40, - 1,0,0,0,114,174,0,0,0,114,5,0,0,0,244,11, - 0,0,0,95,99,104,101,99,107,95,110,97,109,101,82,2, - 0,0,115,6,0,0,0,0,8,21,6,13,1,114,176,0, - 0,0,99,1,0,0,0,0,0,0,0,2,0,0,0,3, - 0,0,0,3,0,0,0,115,35,0,0,0,135,0,0,102, - 1,0,100,1,0,100,2,0,134,0,0,125,1,0,116,0, - 0,124,1,0,136,0,0,131,2,0,1,124,1,0,83,40, - 3,0,0,0,117,49,0,0,0,68,101,99,111,114,97,116, - 111,114,32,116,111,32,118,101,114,105,102,121,32,116,104,101, - 32,110,97,109,101,100,32,109,111,100,117,108,101,32,105,115, - 32,98,117,105,108,116,45,105,110,46,99,2,0,0,0,0, - 0,0,0,2,0,0,0,4,0,0,0,19,0,0,0,115, - 58,0,0,0,124,1,0,116,0,0,106,1,0,107,7,0, - 114,45,0,116,2,0,100,1,0,106,3,0,124,1,0,131, - 1,0,100,2,0,124,1,0,131,1,1,130,1,0,110,0, - 0,136,0,0,124,0,0,124,1,0,131,2,0,83,40,3, - 0,0,0,78,117,27,0,0,0,123,125,32,105,115,32,110, - 111,116,32,97,32,98,117,105,108,116,45,105,110,32,109,111, - 100,117,108,101,114,71,0,0,0,40,4,0,0,0,114,7, - 0,0,0,244,20,0,0,0,98,117,105,108,116,105,110,95, - 109,111,100,117,108,101,95,110,97,109,101,115,114,157,0,0, - 0,114,46,0,0,0,40,2,0,0,0,114,75,0,0,0, - 244,8,0,0,0,102,117,108,108,110,97,109,101,40,1,0, - 0,0,114,168,0,0,0,114,4,0,0,0,114,5,0,0, - 0,244,25,0,0,0,95,114,101,113,117,105,114,101,115,95, - 98,117,105,108,116,105,110,95,119,114,97,112,112,101,114,102, + 1,0,83,40,3,0,0,0,117,49,0,0,0,68,101,99, + 111,114,97,116,111,114,32,116,111,32,118,101,114,105,102,121, + 32,116,104,101,32,110,97,109,101,100,32,109,111,100,117,108, + 101,32,105,115,32,98,117,105,108,116,45,105,110,46,99,2, + 0,0,0,0,0,0,0,2,0,0,0,4,0,0,0,19, + 0,0,0,115,58,0,0,0,124,1,0,116,0,0,106,1, + 0,107,7,0,114,45,0,116,2,0,100,1,0,106,3,0, + 124,1,0,131,1,0,100,2,0,124,1,0,131,1,1,130, + 1,0,110,0,0,136,0,0,124,0,0,124,1,0,131,2, + 0,83,40,3,0,0,0,78,117,27,0,0,0,123,125,32, + 105,115,32,110,111,116,32,97,32,98,117,105,108,116,45,105, + 110,32,109,111,100,117,108,101,117,4,0,0,0,110,97,109, + 101,40,4,0,0,0,117,3,0,0,0,115,121,115,117,20, + 0,0,0,98,117,105,108,116,105,110,95,109,111,100,117,108, + 101,95,110,97,109,101,115,117,11,0,0,0,73,109,112,111, + 114,116,69,114,114,111,114,117,6,0,0,0,102,111,114,109, + 97,116,40,2,0,0,0,117,4,0,0,0,115,101,108,102, + 117,8,0,0,0,102,117,108,108,110,97,109,101,40,1,0, + 0,0,117,3,0,0,0,102,120,110,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,25,0,0,0,95,114,101,113,117,105,114,101,115,95, + 98,117,105,108,116,105,110,95,119,114,97,112,112,101,114,81, 2,0,0,115,8,0,0,0,0,1,15,1,18,1,12,1, 117,52,0,0,0,95,114,101,113,117,105,114,101,115,95,98, 117,105,108,116,105,110,46,60,108,111,99,97,108,115,62,46, 95,114,101,113,117,105,114,101,115,95,98,117,105,108,116,105, - 110,95,119,114,97,112,112,101,114,40,1,0,0,0,114,64, - 0,0,0,40,2,0,0,0,114,168,0,0,0,114,179,0, - 0,0,114,4,0,0,0,40,1,0,0,0,114,168,0,0, - 0,114,5,0,0,0,244,17,0,0,0,95,114,101,113,117, - 105,114,101,115,95,98,117,105,108,116,105,110,100,2,0,0, - 115,6,0,0,0,0,2,18,5,13,1,114,180,0,0,0, - 99,1,0,0,0,0,0,0,0,2,0,0,0,3,0,0, - 0,3,0,0,0,115,35,0,0,0,135,0,0,102,1,0, - 100,1,0,100,2,0,134,0,0,125,1,0,116,0,0,124, - 1,0,136,0,0,131,2,0,1,124,1,0,83,40,3,0, - 0,0,117,47,0,0,0,68,101,99,111,114,97,116,111,114, - 32,116,111,32,118,101,114,105,102,121,32,116,104,101,32,110, - 97,109,101,100,32,109,111,100,117,108,101,32,105,115,32,102, - 114,111,122,101,110,46,99,2,0,0,0,0,0,0,0,2, - 0,0,0,4,0,0,0,19,0,0,0,115,58,0,0,0, - 116,0,0,106,1,0,124,1,0,131,1,0,115,45,0,116, - 2,0,100,1,0,106,3,0,124,1,0,131,1,0,100,2, - 0,124,1,0,131,1,1,130,1,0,110,0,0,136,0,0, - 124,0,0,124,1,0,131,2,0,83,40,3,0,0,0,78, - 117,25,0,0,0,123,125,32,105,115,32,110,111,116,32,97, - 32,102,114,111,122,101,110,32,109,111,100,117,108,101,114,71, - 0,0,0,40,4,0,0,0,114,94,0,0,0,244,9,0, - 0,0,105,115,95,102,114,111,122,101,110,114,157,0,0,0, - 114,46,0,0,0,40,2,0,0,0,114,75,0,0,0,114, - 178,0,0,0,40,1,0,0,0,114,168,0,0,0,114,4, - 0,0,0,114,5,0,0,0,244,24,0,0,0,95,114,101, - 113,117,105,114,101,115,95,102,114,111,122,101,110,95,119,114, - 97,112,112,101,114,113,2,0,0,115,8,0,0,0,0,1, - 15,1,18,1,12,1,117,50,0,0,0,95,114,101,113,117, - 105,114,101,115,95,102,114,111,122,101,110,46,60,108,111,99, - 97,108,115,62,46,95,114,101,113,117,105,114,101,115,95,102, - 114,111,122,101,110,95,119,114,97,112,112,101,114,40,1,0, - 0,0,114,64,0,0,0,40,2,0,0,0,114,168,0,0, - 0,114,182,0,0,0,114,4,0,0,0,40,1,0,0,0, - 114,168,0,0,0,114,5,0,0,0,244,16,0,0,0,95, - 114,101,113,117,105,114,101,115,95,102,114,111,122,101,110,111, - 2,0,0,115,6,0,0,0,0,2,18,5,13,1,114,183, - 0,0,0,99,2,0,0,0,0,0,0,0,5,0,0,0, - 5,0,0,0,67,0,0,0,115,87,0,0,0,124,0,0, - 106,0,0,124,1,0,131,1,0,92,2,0,125,2,0,125, - 3,0,124,2,0,100,1,0,107,8,0,114,83,0,116,1, - 0,124,3,0,131,1,0,114,83,0,100,2,0,125,4,0, - 116,2,0,106,3,0,124,4,0,106,4,0,124,3,0,100, - 3,0,25,131,1,0,116,5,0,131,2,0,1,110,0,0, - 124,2,0,83,40,4,0,0,0,117,86,0,0,0,84,114, - 121,32,116,111,32,102,105,110,100,32,97,32,108,111,97,100, - 101,114,32,102,111,114,32,116,104,101,32,115,112,101,99,105, - 102,105,101,100,32,109,111,100,117,108,101,32,98,121,32,100, - 101,108,101,103,97,116,105,110,103,32,116,111,10,32,32,32, - 32,115,101,108,102,46,102,105,110,100,95,108,111,97,100,101, - 114,40,41,46,78,117,44,0,0,0,78,111,116,32,105,109, - 112,111,114,116,105,110,103,32,100,105,114,101,99,116,111,114, - 121,32,123,125,58,32,109,105,115,115,105,110,103,32,95,95, - 105,110,105,116,95,95,114,67,0,0,0,40,6,0,0,0, - 244,11,0,0,0,102,105,110,100,95,108,111,97,100,101,114, - 114,31,0,0,0,244,9,0,0,0,95,119,97,114,110,105, - 110,103,115,244,4,0,0,0,119,97,114,110,114,46,0,0, - 0,244,13,0,0,0,73,109,112,111,114,116,87,97,114,110, - 105,110,103,40,5,0,0,0,114,75,0,0,0,114,178,0, - 0,0,114,160,0,0,0,244,8,0,0,0,112,111,114,116, - 105,111,110,115,244,3,0,0,0,109,115,103,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,244,17,0,0,0, - 95,102,105,110,100,95,109,111,100,117,108,101,95,115,104,105, - 109,122,2,0,0,115,10,0,0,0,0,6,21,1,24,1, - 6,1,32,1,114,190,0,0,0,99,4,0,0,0,0,0, - 0,0,11,0,0,0,19,0,0,0,67,0,0,0,115,243, + 110,95,119,114,97,112,112,101,114,40,1,0,0,0,117,5, + 0,0,0,95,119,114,97,112,40,2,0,0,0,117,3,0, + 0,0,102,120,110,117,25,0,0,0,95,114,101,113,117,105, + 114,101,115,95,98,117,105,108,116,105,110,95,119,114,97,112, + 112,101,114,40,0,0,0,0,40,1,0,0,0,117,3,0, + 0,0,102,120,110,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,17,0,0,0,95,114,101,113, + 117,105,114,101,115,95,98,117,105,108,116,105,110,79,2,0, + 0,115,6,0,0,0,0,2,18,5,13,1,117,17,0,0, + 0,95,114,101,113,117,105,114,101,115,95,98,117,105,108,116, + 105,110,99,1,0,0,0,0,0,0,0,2,0,0,0,3, + 0,0,0,3,0,0,0,115,35,0,0,0,135,0,0,102, + 1,0,100,1,0,100,2,0,134,0,0,125,1,0,116,0, + 0,124,1,0,136,0,0,131,2,0,1,124,1,0,83,40, + 3,0,0,0,117,47,0,0,0,68,101,99,111,114,97,116, + 111,114,32,116,111,32,118,101,114,105,102,121,32,116,104,101, + 32,110,97,109,101,100,32,109,111,100,117,108,101,32,105,115, + 32,102,114,111,122,101,110,46,99,2,0,0,0,0,0,0, + 0,2,0,0,0,4,0,0,0,19,0,0,0,115,58,0, + 0,0,116,0,0,106,1,0,124,1,0,131,1,0,115,45, + 0,116,2,0,100,1,0,106,3,0,124,1,0,131,1,0, + 100,2,0,124,1,0,131,1,1,130,1,0,110,0,0,136, + 0,0,124,0,0,124,1,0,131,2,0,83,40,3,0,0, + 0,78,117,25,0,0,0,123,125,32,105,115,32,110,111,116, + 32,97,32,102,114,111,122,101,110,32,109,111,100,117,108,101, + 117,4,0,0,0,110,97,109,101,40,4,0,0,0,117,4, + 0,0,0,95,105,109,112,117,9,0,0,0,105,115,95,102, + 114,111,122,101,110,117,11,0,0,0,73,109,112,111,114,116, + 69,114,114,111,114,117,6,0,0,0,102,111,114,109,97,116, + 40,2,0,0,0,117,4,0,0,0,115,101,108,102,117,8, + 0,0,0,102,117,108,108,110,97,109,101,40,1,0,0,0, + 117,3,0,0,0,102,120,110,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 24,0,0,0,95,114,101,113,117,105,114,101,115,95,102,114, + 111,122,101,110,95,119,114,97,112,112,101,114,92,2,0,0, + 115,8,0,0,0,0,1,15,1,18,1,12,1,117,50,0, + 0,0,95,114,101,113,117,105,114,101,115,95,102,114,111,122, + 101,110,46,60,108,111,99,97,108,115,62,46,95,114,101,113, + 117,105,114,101,115,95,102,114,111,122,101,110,95,119,114,97, + 112,112,101,114,40,1,0,0,0,117,5,0,0,0,95,119, + 114,97,112,40,2,0,0,0,117,3,0,0,0,102,120,110, + 117,24,0,0,0,95,114,101,113,117,105,114,101,115,95,102, + 114,111,122,101,110,95,119,114,97,112,112,101,114,40,0,0, + 0,0,40,1,0,0,0,117,3,0,0,0,102,120,110,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,16,0,0,0,95,114,101,113,117,105,114,101,115,95, + 102,114,111,122,101,110,90,2,0,0,115,6,0,0,0,0, + 2,18,5,13,1,117,16,0,0,0,95,114,101,113,117,105, + 114,101,115,95,102,114,111,122,101,110,99,2,0,0,0,0, + 0,0,0,5,0,0,0,5,0,0,0,67,0,0,0,115, + 87,0,0,0,124,0,0,106,0,0,124,1,0,131,1,0, + 92,2,0,125,2,0,125,3,0,124,2,0,100,1,0,107, + 8,0,114,83,0,116,1,0,124,3,0,131,1,0,114,83, + 0,100,2,0,125,4,0,116,2,0,106,3,0,124,4,0, + 106,4,0,124,3,0,100,3,0,25,131,1,0,116,5,0, + 131,2,0,1,110,0,0,124,2,0,83,40,4,0,0,0, + 117,86,0,0,0,84,114,121,32,116,111,32,102,105,110,100, + 32,97,32,108,111,97,100,101,114,32,102,111,114,32,116,104, + 101,32,115,112,101,99,105,102,105,101,100,32,109,111,100,117, + 108,101,32,98,121,32,100,101,108,101,103,97,116,105,110,103, + 32,116,111,10,32,32,32,32,115,101,108,102,46,102,105,110, + 100,95,108,111,97,100,101,114,40,41,46,78,117,44,0,0, + 0,78,111,116,32,105,109,112,111,114,116,105,110,103,32,100, + 105,114,101,99,116,111,114,121,32,123,125,58,32,109,105,115, + 115,105,110,103,32,95,95,105,110,105,116,95,95,105,0,0, + 0,0,40,6,0,0,0,117,11,0,0,0,102,105,110,100, + 95,108,111,97,100,101,114,117,3,0,0,0,108,101,110,117, + 9,0,0,0,95,119,97,114,110,105,110,103,115,117,4,0, + 0,0,119,97,114,110,117,6,0,0,0,102,111,114,109,97, + 116,117,13,0,0,0,73,109,112,111,114,116,87,97,114,110, + 105,110,103,40,5,0,0,0,117,4,0,0,0,115,101,108, + 102,117,8,0,0,0,102,117,108,108,110,97,109,101,117,6, + 0,0,0,108,111,97,100,101,114,117,8,0,0,0,112,111, + 114,116,105,111,110,115,117,3,0,0,0,109,115,103,40,0, + 0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,17,0,0,0,95, + 102,105,110,100,95,109,111,100,117,108,101,95,115,104,105,109, + 101,2,0,0,115,10,0,0,0,0,6,21,1,24,1,6, + 1,32,1,117,17,0,0,0,95,102,105,110,100,95,109,111, + 100,117,108,101,95,115,104,105,109,99,4,0,0,0,0,0, + 0,0,12,0,0,0,19,0,0,0,67,0,0,0,115,233, 1,0,0,105,0,0,125,4,0,124,2,0,100,1,0,107, 9,0,114,31,0,124,2,0,124,4,0,100,2,0,60,110, 6,0,100,3,0,125,2,0,124,3,0,100,1,0,107,9, @@ -1241,205 +1361,168 @@ 0,124,0,0,100,1,0,100,5,0,133,2,0,25,125,5, 0,124,0,0,100,5,0,100,6,0,133,2,0,25,125,6, 0,124,0,0,100,6,0,100,7,0,133,2,0,25,125,7, - 0,124,5,0,116,0,0,107,3,0,114,168,0,100,8,0, + 0,124,5,0,116,0,0,107,3,0,114,158,0,100,8,0, 106,1,0,124,2,0,124,5,0,131,2,0,125,8,0,116, - 2,0,124,8,0,131,1,0,1,116,3,0,124,8,0,124, - 4,0,141,1,0,130,1,0,110,116,0,116,4,0,124,6, - 0,131,1,0,100,5,0,107,3,0,114,226,0,100,9,0, - 106,1,0,124,2,0,131,1,0,125,8,0,116,2,0,124, - 8,0,131,1,0,1,116,5,0,124,8,0,131,1,0,130, - 1,0,110,58,0,116,4,0,124,7,0,131,1,0,100,5, - 0,107,3,0,114,28,1,100,10,0,106,1,0,124,2,0, - 131,1,0,125,8,0,116,2,0,124,8,0,131,1,0,1, - 116,5,0,124,8,0,131,1,0,130,1,0,110,0,0,124, - 1,0,100,1,0,107,9,0,114,229,1,121,20,0,116,6, - 0,124,1,0,100,11,0,25,131,1,0,125,9,0,87,110, - 18,0,4,116,7,0,107,10,0,114,80,1,1,1,1,89, - 110,62,0,88,116,8,0,124,6,0,131,1,0,124,9,0, - 107,3,0,114,142,1,100,12,0,106,1,0,124,2,0,131, - 1,0,125,8,0,116,2,0,124,8,0,131,1,0,1,116, - 3,0,124,8,0,124,4,0,141,1,0,130,1,0,110,0, - 0,121,18,0,124,1,0,100,13,0,25,100,14,0,64,125, - 10,0,87,110,18,0,4,116,7,0,107,10,0,114,180,1, - 1,1,1,89,113,229,1,88,116,8,0,124,7,0,131,1, - 0,124,10,0,107,3,0,114,229,1,116,3,0,100,12,0, - 106,1,0,124,2,0,131,1,0,124,4,0,141,1,0,130, - 1,0,113,229,1,110,0,0,124,0,0,100,7,0,100,1, - 0,133,2,0,25,83,40,15,0,0,0,117,122,1,0,0, - 86,97,108,105,100,97,116,101,32,116,104,101,32,104,101,97, - 100,101,114,32,111,102,32,116,104,101,32,112,97,115,115,101, - 100,45,105,110,32,98,121,116,101,99,111,100,101,32,97,103, - 97,105,110,115,116,32,115,111,117,114,99,101,95,115,116,97, - 116,115,32,40,105,102,10,32,32,32,32,103,105,118,101,110, - 41,32,97,110,100,32,114,101,116,117,114,110,105,110,103,32, - 116,104,101,32,98,121,116,101,99,111,100,101,32,116,104,97, - 116,32,99,97,110,32,98,101,32,99,111,109,112,105,108,101, - 100,32,98,121,32,99,111,109,112,105,108,101,40,41,46,10, - 10,32,32,32,32,65,108,108,32,111,116,104,101,114,32,97, - 114,103,117,109,101,110,116,115,32,97,114,101,32,117,115,101, - 100,32,116,111,32,101,110,104,97,110,99,101,32,101,114,114, - 111,114,32,114,101,112,111,114,116,105,110,103,46,10,10,32, - 32,32,32,73,109,112,111,114,116,69,114,114,111,114,32,105, - 115,32,114,97,105,115,101,100,32,119,104,101,110,32,116,104, - 101,32,109,97,103,105,99,32,110,117,109,98,101,114,32,105, - 115,32,105,110,99,111,114,114,101,99,116,32,111,114,32,116, - 104,101,32,98,121,116,101,99,111,100,101,32,105,115,10,32, - 32,32,32,102,111,117,110,100,32,116,111,32,98,101,32,115, - 116,97,108,101,46,32,69,79,70,69,114,114,111,114,32,105, - 115,32,114,97,105,115,101,100,32,119,104,101,110,32,116,104, - 101,32,100,97,116,97,32,105,115,32,102,111,117,110,100,32, - 116,111,32,98,101,10,32,32,32,32,116,114,117,110,99,97, - 116,101,100,46,10,10,32,32,32,32,78,114,71,0,0,0, - 117,10,0,0,0,60,98,121,116,101,99,111,100,101,62,114, - 35,0,0,0,114,12,0,0,0,233,8,0,0,0,233,12, - 0,0,0,117,30,0,0,0,98,97,100,32,109,97,103,105, - 99,32,110,117,109,98,101,114,32,105,110,32,123,33,114,125, - 58,32,123,33,114,125,117,43,0,0,0,114,101,97,99,104, - 101,100,32,69,79,70,32,119,104,105,108,101,32,114,101,97, - 100,105,110,103,32,116,105,109,101,115,116,97,109,112,32,105, - 110,32,123,33,114,125,117,48,0,0,0,114,101,97,99,104, - 101,100,32,69,79,70,32,119,104,105,108,101,32,114,101,97, - 100,105,110,103,32,115,105,122,101,32,111,102,32,115,111,117, - 114,99,101,32,105,110,32,123,33,114,125,244,5,0,0,0, - 109,116,105,109,101,117,26,0,0,0,98,121,116,101,99,111, - 100,101,32,105,115,32,115,116,97,108,101,32,102,111,114,32, - 123,33,114,125,244,4,0,0,0,115,105,122,101,108,3,0, - 0,0,255,127,255,127,3,0,40,9,0,0,0,244,12,0, - 0,0,77,65,71,73,67,95,78,85,77,66,69,82,114,46, - 0,0,0,114,137,0,0,0,114,157,0,0,0,114,31,0, - 0,0,244,8,0,0,0,69,79,70,69,114,114,111,114,114, - 14,0,0,0,114,91,0,0,0,114,19,0,0,0,40,11, - 0,0,0,114,52,0,0,0,244,12,0,0,0,115,111,117, - 114,99,101,95,115,116,97,116,115,114,71,0,0,0,114,35, - 0,0,0,116,11,0,0,0,101,120,99,95,100,101,116,97, - 105,108,115,116,5,0,0,0,109,97,103,105,99,116,13,0, - 0,0,114,97,119,95,116,105,109,101,115,116,97,109,112,116, - 8,0,0,0,114,97,119,95,115,105,122,101,114,136,0,0, - 0,244,12,0,0,0,115,111,117,114,99,101,95,109,116,105, - 109,101,244,11,0,0,0,115,111,117,114,99,101,95,115,105, - 122,101,114,4,0,0,0,114,4,0,0,0,114,5,0,0, - 0,244,25,0,0,0,95,118,97,108,105,100,97,116,101,95, - 98,121,116,101,99,111,100,101,95,104,101,97,100,101,114,135, - 2,0,0,115,76,0,0,0,0,11,6,1,12,1,13,3, - 6,1,12,1,13,1,16,1,16,1,16,1,12,1,18,1, - 10,1,18,1,18,1,15,1,10,1,15,1,18,1,15,1, - 10,1,15,1,12,1,3,1,20,1,13,1,5,2,18,1, - 15,1,10,1,18,1,3,1,18,1,13,1,5,2,18,1, - 15,1,15,1,114,200,0,0,0,99,4,0,0,0,0,0, - 0,0,5,0,0,0,6,0,0,0,67,0,0,0,115,115, - 0,0,0,116,0,0,106,1,0,124,0,0,131,1,0,125, - 4,0,116,2,0,124,4,0,116,3,0,131,2,0,114,78, - 0,116,4,0,100,1,0,124,2,0,131,2,0,1,124,3, - 0,100,2,0,107,9,0,114,74,0,116,5,0,106,6,0, - 124,4,0,124,3,0,131,2,0,1,110,0,0,124,4,0, - 83,116,7,0,100,3,0,106,8,0,124,2,0,131,1,0, - 100,4,0,124,1,0,100,5,0,124,2,0,131,1,2,130, - 1,0,100,2,0,83,40,6,0,0,0,117,60,0,0,0, - 67,111,109,112,105,108,101,32,98,121,116,101,99,111,100,101, - 32,97,115,32,114,101,116,117,114,110,101,100,32,98,121,32, - 95,118,97,108,105,100,97,116,101,95,98,121,116,101,99,111, - 100,101,95,104,101,97,100,101,114,40,41,46,117,21,0,0, - 0,99,111,100,101,32,111,98,106,101,99,116,32,102,114,111, - 109,32,123,33,114,125,78,117,23,0,0,0,78,111,110,45, - 99,111,100,101,32,111,98,106,101,99,116,32,105,110,32,123, - 33,114,125,114,71,0,0,0,114,35,0,0,0,40,9,0, - 0,0,244,7,0,0,0,109,97,114,115,104,97,108,116,5, - 0,0,0,108,111,97,100,115,244,10,0,0,0,105,115,105, - 110,115,116,97,110,99,101,244,10,0,0,0,95,99,111,100, - 101,95,116,121,112,101,114,137,0,0,0,114,94,0,0,0, - 116,16,0,0,0,95,102,105,120,95,99,111,95,102,105,108, - 101,110,97,109,101,114,157,0,0,0,114,46,0,0,0,40, - 5,0,0,0,114,52,0,0,0,114,71,0,0,0,114,125, - 0,0,0,114,126,0,0,0,244,4,0,0,0,99,111,100, - 101,114,4,0,0,0,114,4,0,0,0,114,5,0,0,0, - 244,17,0,0,0,95,99,111,109,112,105,108,101,95,98,121, - 116,101,99,111,100,101,190,2,0,0,115,16,0,0,0,0, - 2,15,1,15,1,13,1,12,1,19,1,4,2,18,1,114, - 205,0,0,0,114,67,0,0,0,99,3,0,0,0,0,0, - 0,0,4,0,0,0,3,0,0,0,67,0,0,0,115,76, - 0,0,0,116,0,0,116,1,0,131,1,0,125,3,0,124, - 3,0,106,2,0,116,3,0,124,1,0,131,1,0,131,1, - 0,1,124,3,0,106,2,0,116,3,0,124,2,0,131,1, - 0,131,1,0,1,124,3,0,106,2,0,116,4,0,106,5, - 0,124,0,0,131,1,0,131,1,0,1,124,3,0,83,40, - 1,0,0,0,117,80,0,0,0,67,111,109,112,105,108,101, - 32,97,32,99,111,100,101,32,111,98,106,101,99,116,32,105, - 110,116,111,32,98,121,116,101,99,111,100,101,32,102,111,114, - 32,119,114,105,116,105,110,103,32,111,117,116,32,116,111,32, - 97,32,98,121,116,101,45,99,111,109,112,105,108,101,100,10, - 32,32,32,32,102,105,108,101,46,40,6,0,0,0,244,9, - 0,0,0,98,121,116,101,97,114,114,97,121,114,195,0,0, - 0,244,6,0,0,0,101,120,116,101,110,100,114,17,0,0, - 0,114,201,0,0,0,116,5,0,0,0,100,117,109,112,115, - 40,4,0,0,0,114,204,0,0,0,114,193,0,0,0,114, - 199,0,0,0,114,52,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,244,17,0,0,0,95,99,111, - 100,101,95,116,111,95,98,121,116,101,99,111,100,101,202,2, - 0,0,115,10,0,0,0,0,3,12,1,19,1,19,1,22, - 1,114,208,0,0,0,99,1,0,0,0,0,0,0,0,5, - 0,0,0,4,0,0,0,67,0,0,0,115,89,0,0,0, - 100,1,0,100,2,0,108,0,0,125,1,0,116,1,0,106, - 2,0,124,0,0,131,1,0,106,3,0,125,2,0,124,1, - 0,106,4,0,124,2,0,131,1,0,125,3,0,116,1,0, - 106,5,0,100,2,0,100,3,0,131,2,0,125,4,0,124, - 4,0,106,6,0,124,0,0,106,6,0,124,3,0,100,1, - 0,25,131,1,0,131,1,0,83,40,4,0,0,0,117,121, - 0,0,0,68,101,99,111,100,101,32,98,121,116,101,115,32, - 114,101,112,114,101,115,101,110,116,105,110,103,32,115,111,117, - 114,99,101,32,99,111,100,101,32,97,110,100,32,114,101,116, - 117,114,110,32,116,104,101,32,115,116,114,105,110,103,46,10, - 10,32,32,32,32,85,110,105,118,101,114,115,97,108,32,110, - 101,119,108,105,110,101,32,115,117,112,112,111,114,116,32,105, - 115,32,117,115,101,100,32,105,110,32,116,104,101,32,100,101, - 99,111,100,105,110,103,46,10,32,32,32,32,114,67,0,0, - 0,78,84,40,7,0,0,0,244,8,0,0,0,116,111,107, - 101,110,105,122,101,114,48,0,0,0,116,7,0,0,0,66, - 121,116,101,115,73,79,116,8,0,0,0,114,101,97,100,108, - 105,110,101,116,15,0,0,0,100,101,116,101,99,116,95,101, - 110,99,111,100,105,110,103,116,25,0,0,0,73,110,99,114, - 101,109,101,110,116,97,108,78,101,119,108,105,110,101,68,101, - 99,111,100,101,114,244,6,0,0,0,100,101,99,111,100,101, - 40,5,0,0,0,244,12,0,0,0,115,111,117,114,99,101, - 95,98,121,116,101,115,114,209,0,0,0,116,21,0,0,0, - 115,111,117,114,99,101,95,98,121,116,101,115,95,114,101,97, - 100,108,105,110,101,244,8,0,0,0,101,110,99,111,100,105, - 110,103,116,15,0,0,0,110,101,119,108,105,110,101,95,100, - 101,99,111,100,101,114,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,244,13,0,0,0,100,101,99,111,100,101, - 95,115,111,117,114,99,101,212,2,0,0,115,10,0,0,0, - 0,5,12,1,18,1,15,1,18,1,114,213,0,0,0,99, - 0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0, - 64,0,0,0,115,169,0,0,0,101,0,0,90,1,0,100, - 0,0,90,2,0,100,1,0,90,3,0,101,4,0,100,2, - 0,100,3,0,132,0,0,131,1,0,90,5,0,101,4,0, - 100,4,0,100,5,0,100,6,0,132,1,0,131,1,0,90, - 6,0,101,4,0,101,7,0,101,8,0,101,9,0,100,7, - 0,100,8,0,132,0,0,131,1,0,131,1,0,131,1,0, - 131,1,0,90,10,0,101,4,0,101,9,0,100,9,0,100, - 10,0,132,0,0,131,1,0,131,1,0,90,11,0,101,4, - 0,101,9,0,100,11,0,100,12,0,132,0,0,131,1,0, - 131,1,0,90,12,0,101,4,0,101,9,0,100,13,0,100, - 14,0,132,0,0,131,1,0,131,1,0,90,13,0,100,4, - 0,83,40,15,0,0,0,244,15,0,0,0,66,117,105,108, - 116,105,110,73,109,112,111,114,116,101,114,117,144,0,0,0, - 77,101,116,97,32,112,97,116,104,32,105,109,112,111,114,116, - 32,102,111,114,32,98,117,105,108,116,45,105,110,32,109,111, - 100,117,108,101,115,46,10,10,32,32,32,32,65,108,108,32, - 109,101,116,104,111,100,115,32,97,114,101,32,101,105,116,104, - 101,114,32,99,108,97,115,115,32,111,114,32,115,116,97,116, - 105,99,32,109,101,116,104,111,100,115,32,116,111,32,97,118, - 111,105,100,32,116,104,101,32,110,101,101,100,32,116,111,10, - 32,32,32,32,105,110,115,116,97,110,116,105,97,116,101,32, - 116,104,101,32,99,108,97,115,115,46,10,10,32,32,32,32, - 99,2,0,0,0,0,0,0,0,2,0,0,0,2,0,0, - 0,67,0,0,0,115,16,0,0,0,100,1,0,106,0,0, - 124,1,0,106,1,0,131,1,0,83,40,2,0,0,0,78, - 117,24,0,0,0,60,109,111,100,117,108,101,32,123,33,114, - 125,32,40,98,117,105,108,116,45,105,110,41,62,40,2,0, - 0,0,114,46,0,0,0,114,56,0,0,0,40,2,0,0, - 0,244,3,0,0,0,99,108,115,114,161,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,244,11,0, - 0,0,109,111,100,117,108,101,95,114,101,112,114,235,2,0, + 2,0,124,8,0,124,4,0,141,1,0,130,1,0,110,116, + 0,116,3,0,124,6,0,131,1,0,100,5,0,107,3,0, + 114,216,0,100,9,0,106,1,0,124,2,0,131,1,0,125, + 9,0,116,4,0,124,9,0,131,1,0,1,116,5,0,124, + 9,0,131,1,0,130,1,0,110,58,0,116,3,0,124,7, + 0,131,1,0,100,5,0,107,3,0,114,18,1,100,10,0, + 106,1,0,124,2,0,131,1,0,125,9,0,116,4,0,124, + 9,0,131,1,0,1,116,5,0,124,9,0,131,1,0,130, + 1,0,110,0,0,124,1,0,100,1,0,107,9,0,114,219, + 1,121,20,0,116,6,0,124,1,0,100,11,0,25,131,1, + 0,125,10,0,87,110,18,0,4,116,7,0,107,10,0,114, + 70,1,1,1,1,89,110,62,0,88,116,8,0,124,6,0, + 131,1,0,124,10,0,107,3,0,114,132,1,100,12,0,106, + 1,0,124,2,0,131,1,0,125,9,0,116,4,0,124,9, + 0,131,1,0,1,116,2,0,124,9,0,124,4,0,141,1, + 0,130,1,0,110,0,0,121,18,0,124,1,0,100,13,0, + 25,100,14,0,64,125,11,0,87,110,18,0,4,116,7,0, + 107,10,0,114,170,1,1,1,1,89,113,219,1,88,116,8, + 0,124,7,0,131,1,0,124,11,0,107,3,0,114,219,1, + 116,2,0,100,12,0,106,1,0,124,2,0,131,1,0,124, + 4,0,141,1,0,130,1,0,113,219,1,110,0,0,124,0, + 0,100,7,0,100,1,0,133,2,0,25,83,40,15,0,0, + 0,117,122,1,0,0,86,97,108,105,100,97,116,101,32,116, + 104,101,32,104,101,97,100,101,114,32,111,102,32,116,104,101, + 32,112,97,115,115,101,100,45,105,110,32,98,121,116,101,99, + 111,100,101,32,97,103,97,105,110,115,116,32,115,111,117,114, + 99,101,95,115,116,97,116,115,32,40,105,102,10,32,32,32, + 32,103,105,118,101,110,41,32,97,110,100,32,114,101,116,117, + 114,110,105,110,103,32,116,104,101,32,98,121,116,101,99,111, + 100,101,32,116,104,97,116,32,99,97,110,32,98,101,32,99, + 111,109,112,105,108,101,100,32,98,121,32,99,111,109,112,105, + 108,101,40,41,46,10,10,32,32,32,32,65,108,108,32,111, + 116,104,101,114,32,97,114,103,117,109,101,110,116,115,32,97, + 114,101,32,117,115,101,100,32,116,111,32,101,110,104,97,110, + 99,101,32,101,114,114,111,114,32,114,101,112,111,114,116,105, + 110,103,46,10,10,32,32,32,32,73,109,112,111,114,116,69, + 114,114,111,114,32,105,115,32,114,97,105,115,101,100,32,119, + 104,101,110,32,116,104,101,32,109,97,103,105,99,32,110,117, + 109,98,101,114,32,105,115,32,105,110,99,111,114,114,101,99, + 116,32,111,114,32,116,104,101,32,98,121,116,101,99,111,100, + 101,32,105,115,10,32,32,32,32,102,111,117,110,100,32,116, + 111,32,98,101,32,115,116,97,108,101,46,32,69,79,70,69, + 114,114,111,114,32,105,115,32,114,97,105,115,101,100,32,119, + 104,101,110,32,116,104,101,32,100,97,116,97,32,105,115,32, + 102,111,117,110,100,32,116,111,32,98,101,10,32,32,32,32, + 116,114,117,110,99,97,116,101,100,46,10,10,32,32,32,32, + 78,117,4,0,0,0,110,97,109,101,117,8,0,0,0,98, + 121,116,101,99,111,100,101,117,4,0,0,0,112,97,116,104, + 105,4,0,0,0,105,8,0,0,0,105,12,0,0,0,117, + 30,0,0,0,98,97,100,32,109,97,103,105,99,32,110,117, + 109,98,101,114,32,105,110,32,123,33,114,125,58,32,123,33, + 114,125,117,21,0,0,0,98,97,100,32,116,105,109,101,115, + 116,97,109,112,32,105,110,32,123,33,114,125,117,16,0,0, + 0,98,97,100,32,115,105,122,101,32,105,110,32,123,33,114, + 125,117,5,0,0,0,109,116,105,109,101,117,26,0,0,0, + 98,121,116,101,99,111,100,101,32,105,115,32,115,116,97,108, + 101,32,102,111,114,32,123,33,114,125,117,4,0,0,0,115, + 105,122,101,108,3,0,0,0,255,127,255,127,3,0,40,9, + 0,0,0,117,12,0,0,0,95,77,65,71,73,67,95,66, + 89,84,69,83,117,6,0,0,0,102,111,114,109,97,116,117, + 11,0,0,0,73,109,112,111,114,116,69,114,114,111,114,117, + 3,0,0,0,108,101,110,117,16,0,0,0,95,118,101,114, + 98,111,115,101,95,109,101,115,115,97,103,101,117,8,0,0, + 0,69,79,70,69,114,114,111,114,117,3,0,0,0,105,110, + 116,117,8,0,0,0,75,101,121,69,114,114,111,114,117,7, + 0,0,0,95,114,95,108,111,110,103,40,12,0,0,0,117, + 4,0,0,0,100,97,116,97,117,12,0,0,0,115,111,117, + 114,99,101,95,115,116,97,116,115,117,4,0,0,0,110,97, + 109,101,117,4,0,0,0,112,97,116,104,117,11,0,0,0, + 101,120,99,95,100,101,116,97,105,108,115,117,5,0,0,0, + 109,97,103,105,99,117,13,0,0,0,114,97,119,95,116,105, + 109,101,115,116,97,109,112,117,8,0,0,0,114,97,119,95, + 115,105,122,101,117,3,0,0,0,109,115,103,117,7,0,0, + 0,109,101,115,115,97,103,101,117,12,0,0,0,115,111,117, + 114,99,101,95,109,116,105,109,101,117,11,0,0,0,115,111, + 117,114,99,101,95,115,105,122,101,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,25,0,0,0,95,118,97,108,105,100, + 97,116,101,95,98,121,116,101,99,111,100,101,95,104,101,97, + 100,101,114,114,2,0,0,115,74,0,0,0,0,11,6,1, + 12,1,13,3,6,1,12,1,13,1,16,1,16,1,16,1, + 12,1,18,1,18,1,18,1,15,1,10,1,15,1,18,1, + 15,1,10,1,15,1,12,1,3,1,20,1,13,1,5,2, + 18,1,15,1,10,1,18,1,3,1,18,1,13,1,5,2, + 18,1,15,1,15,1,117,25,0,0,0,95,118,97,108,105, + 100,97,116,101,95,98,121,116,101,99,111,100,101,95,104,101, + 97,100,101,114,99,4,0,0,0,0,0,0,0,5,0,0, + 0,6,0,0,0,67,0,0,0,115,115,0,0,0,116,0, + 0,106,1,0,124,0,0,131,1,0,125,4,0,116,2,0, + 124,4,0,116,3,0,131,2,0,114,78,0,116,4,0,100, + 1,0,124,2,0,131,2,0,1,124,3,0,100,2,0,107, + 9,0,114,74,0,116,5,0,106,6,0,124,4,0,124,3, + 0,131,2,0,1,110,0,0,124,4,0,83,116,7,0,100, + 3,0,106,8,0,124,2,0,131,1,0,100,4,0,124,1, + 0,100,5,0,124,2,0,131,1,2,130,1,0,100,2,0, + 83,40,6,0,0,0,117,60,0,0,0,67,111,109,112,105, + 108,101,32,98,121,116,101,99,111,100,101,32,97,115,32,114, + 101,116,117,114,110,101,100,32,98,121,32,95,118,97,108,105, + 100,97,116,101,95,98,121,116,101,99,111,100,101,95,104,101, + 97,100,101,114,40,41,46,117,21,0,0,0,99,111,100,101, + 32,111,98,106,101,99,116,32,102,114,111,109,32,123,33,114, + 125,78,117,23,0,0,0,78,111,110,45,99,111,100,101,32, + 111,98,106,101,99,116,32,105,110,32,123,33,114,125,117,4, + 0,0,0,110,97,109,101,117,4,0,0,0,112,97,116,104, + 40,9,0,0,0,117,7,0,0,0,109,97,114,115,104,97, + 108,117,5,0,0,0,108,111,97,100,115,117,10,0,0,0, + 105,115,105,110,115,116,97,110,99,101,117,10,0,0,0,95, + 99,111,100,101,95,116,121,112,101,117,16,0,0,0,95,118, + 101,114,98,111,115,101,95,109,101,115,115,97,103,101,117,4, + 0,0,0,95,105,109,112,117,16,0,0,0,95,102,105,120, + 95,99,111,95,102,105,108,101,110,97,109,101,117,11,0,0, + 0,73,109,112,111,114,116,69,114,114,111,114,117,6,0,0, + 0,102,111,114,109,97,116,40,5,0,0,0,117,4,0,0, + 0,100,97,116,97,117,4,0,0,0,110,97,109,101,117,13, + 0,0,0,98,121,116,101,99,111,100,101,95,112,97,116,104, + 117,11,0,0,0,115,111,117,114,99,101,95,112,97,116,104, + 117,4,0,0,0,99,111,100,101,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,17,0,0,0,95,99,111,109,112,105, + 108,101,95,98,121,116,101,99,111,100,101,168,2,0,0,115, + 16,0,0,0,0,2,15,1,15,1,13,1,12,1,19,1, + 4,2,18,1,117,17,0,0,0,95,99,111,109,112,105,108, + 101,95,98,121,116,101,99,111,100,101,99,1,0,0,0,0, + 0,0,0,1,0,0,0,6,0,0,0,66,0,0,0,115, + 173,0,0,0,124,0,0,69,101,0,0,90,1,0,100,0, + 0,90,2,0,100,1,0,90,3,0,101,4,0,100,2,0, + 100,3,0,132,0,0,131,1,0,90,5,0,101,4,0,100, + 4,0,100,5,0,100,6,0,132,1,0,131,1,0,90,6, + 0,101,4,0,101,7,0,101,8,0,101,9,0,100,7,0, + 100,8,0,132,0,0,131,1,0,131,1,0,131,1,0,131, + 1,0,90,10,0,101,4,0,101,9,0,100,9,0,100,10, + 0,132,0,0,131,1,0,131,1,0,90,11,0,101,4,0, + 101,9,0,100,11,0,100,12,0,132,0,0,131,1,0,131, + 1,0,90,12,0,101,4,0,101,9,0,100,13,0,100,14, + 0,132,0,0,131,1,0,131,1,0,90,13,0,100,4,0, + 83,40,15,0,0,0,117,15,0,0,0,66,117,105,108,116, + 105,110,73,109,112,111,114,116,101,114,117,144,0,0,0,77, + 101,116,97,32,112,97,116,104,32,105,109,112,111,114,116,32, + 102,111,114,32,98,117,105,108,116,45,105,110,32,109,111,100, + 117,108,101,115,46,10,10,32,32,32,32,65,108,108,32,109, + 101,116,104,111,100,115,32,97,114,101,32,101,105,116,104,101, + 114,32,99,108,97,115,115,32,111,114,32,115,116,97,116,105, + 99,32,109,101,116,104,111,100,115,32,116,111,32,97,118,111, + 105,100,32,116,104,101,32,110,101,101,100,32,116,111,10,32, + 32,32,32,105,110,115,116,97,110,116,105,97,116,101,32,116, + 104,101,32,99,108,97,115,115,46,10,10,32,32,32,32,99, + 2,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0, + 67,0,0,0,115,16,0,0,0,100,1,0,106,0,0,124, + 1,0,106,1,0,131,1,0,83,40,2,0,0,0,78,117, + 24,0,0,0,60,109,111,100,117,108,101,32,39,123,125,39, + 32,40,98,117,105,108,116,45,105,110,41,62,40,2,0,0, + 0,117,6,0,0,0,102,111,114,109,97,116,117,8,0,0, + 0,95,95,110,97,109,101,95,95,40,2,0,0,0,117,3, + 0,0,0,99,108,115,117,6,0,0,0,109,111,100,117,108, + 101,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,11,0, + 0,0,109,111,100,117,108,101,95,114,101,112,114,192,2,0, 0,115,2,0,0,0,0,2,117,27,0,0,0,66,117,105, 108,116,105,110,73,109,112,111,114,116,101,114,46,109,111,100, 117,108,101,95,114,101,112,114,78,99,3,0,0,0,0,0, @@ -1454,697 +1537,953 @@ 101,100,32,116,104,101,110,32,116,104,101,32,115,101,97,114, 99,104,32,105,115,32,99,111,110,115,105,100,101,114,101,100, 32,97,32,102,97,105,108,117,114,101,46,10,10,32,32,32, - 32,32,32,32,32,78,40,2,0,0,0,114,94,0,0,0, - 116,10,0,0,0,105,115,95,98,117,105,108,116,105,110,40, - 3,0,0,0,114,215,0,0,0,114,178,0,0,0,114,35, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,244,11,0,0,0,102,105,110,100,95,109,111,100,117, - 108,101,239,2,0,0,115,6,0,0,0,0,7,12,1,4, + 32,32,32,32,32,78,40,2,0,0,0,117,4,0,0,0, + 95,105,109,112,117,10,0,0,0,105,115,95,98,117,105,108, + 116,105,110,40,3,0,0,0,117,3,0,0,0,99,108,115, + 117,8,0,0,0,102,117,108,108,110,97,109,101,117,4,0, + 0,0,112,97,116,104,40,0,0,0,0,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,11,0,0,0,102,105,110,100,95,109,111,100,117, + 108,101,196,2,0,0,115,6,0,0,0,0,7,12,1,4, 1,117,27,0,0,0,66,117,105,108,116,105,110,73,109,112, 111,114,116,101,114,46,102,105,110,100,95,109,111,100,117,108, - 101,99,2,0,0,0,0,0,0,0,2,0,0,0,10,0, - 0,0,67,0,0,0,115,39,0,0,0,116,0,0,124,1, - 0,131,1,0,143,21,0,1,116,1,0,116,2,0,106,3, - 0,124,1,0,131,2,0,83,87,100,1,0,81,88,100,1, - 0,83,40,2,0,0,0,117,23,0,0,0,76,111,97,100, - 32,97,32,98,117,105,108,116,45,105,110,32,109,111,100,117, - 108,101,46,78,40,4,0,0,0,114,138,0,0,0,114,99, - 0,0,0,114,94,0,0,0,116,12,0,0,0,105,110,105, - 116,95,98,117,105,108,116,105,110,40,2,0,0,0,114,215, - 0,0,0,114,178,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,244,11,0,0,0,108,111,97,100, - 95,109,111,100,117,108,101,250,2,0,0,115,4,0,0,0, - 0,6,13,1,117,27,0,0,0,66,117,105,108,116,105,110, - 73,109,112,111,114,116,101,114,46,108,111,97,100,95,109,111, - 100,117,108,101,99,2,0,0,0,0,0,0,0,2,0,0, - 0,1,0,0,0,67,0,0,0,115,4,0,0,0,100,1, - 0,83,40,2,0,0,0,117,57,0,0,0,82,101,116,117, - 114,110,32,78,111,110,101,32,97,115,32,98,117,105,108,116, - 45,105,110,32,109,111,100,117,108,101,115,32,100,111,32,110, - 111,116,32,104,97,118,101,32,99,111,100,101,32,111,98,106, - 101,99,116,115,46,78,114,4,0,0,0,40,2,0,0,0, - 114,215,0,0,0,114,178,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,244,8,0,0,0,103,101, - 116,95,99,111,100,101,3,3,0,0,115,2,0,0,0,0, - 4,117,24,0,0,0,66,117,105,108,116,105,110,73,109,112, - 111,114,116,101,114,46,103,101,116,95,99,111,100,101,99,2, + 101,99,2,0,0,0,0,0,0,0,3,0,0,0,9,0, + 0,0,67,0,0,0,115,88,0,0,0,124,1,0,116,0, + 0,106,1,0,107,6,0,125,2,0,121,20,0,116,2,0, + 116,3,0,106,4,0,124,1,0,131,2,0,83,87,110,46, + 0,1,1,1,124,2,0,12,114,76,0,124,1,0,116,0, + 0,106,1,0,107,6,0,114,76,0,116,0,0,106,1,0, + 124,1,0,61,110,0,0,130,0,0,89,110,1,0,88,100, + 1,0,83,40,2,0,0,0,117,23,0,0,0,76,111,97, + 100,32,97,32,98,117,105,108,116,45,105,110,32,109,111,100, + 117,108,101,46,78,40,5,0,0,0,117,3,0,0,0,115, + 121,115,117,7,0,0,0,109,111,100,117,108,101,115,117,25, + 0,0,0,95,99,97,108,108,95,119,105,116,104,95,102,114, + 97,109,101,115,95,114,101,109,111,118,101,100,117,4,0,0, + 0,95,105,109,112,117,12,0,0,0,105,110,105,116,95,98, + 117,105,108,116,105,110,40,3,0,0,0,117,3,0,0,0, + 99,108,115,117,8,0,0,0,102,117,108,108,110,97,109,101, + 117,9,0,0,0,105,115,95,114,101,108,111,97,100,40,0, + 0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,11,0,0,0,108, + 111,97,100,95,109,111,100,117,108,101,207,2,0,0,115,14, + 0,0,0,0,6,15,1,3,1,20,1,3,1,22,1,13, + 1,117,27,0,0,0,66,117,105,108,116,105,110,73,109,112, + 111,114,116,101,114,46,108,111,97,100,95,109,111,100,117,108, + 101,99,2,0,0,0,0,0,0,0,2,0,0,0,1,0, + 0,0,67,0,0,0,115,4,0,0,0,100,1,0,83,40, + 2,0,0,0,117,57,0,0,0,82,101,116,117,114,110,32, + 78,111,110,101,32,97,115,32,98,117,105,108,116,45,105,110, + 32,109,111,100,117,108,101,115,32,100,111,32,110,111,116,32, + 104,97,118,101,32,99,111,100,101,32,111,98,106,101,99,116, + 115,46,78,40,0,0,0,0,40,2,0,0,0,117,3,0, + 0,0,99,108,115,117,8,0,0,0,102,117,108,108,110,97, + 109,101,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,8, + 0,0,0,103,101,116,95,99,111,100,101,221,2,0,0,115, + 2,0,0,0,0,4,117,24,0,0,0,66,117,105,108,116, + 105,110,73,109,112,111,114,116,101,114,46,103,101,116,95,99, + 111,100,101,99,2,0,0,0,0,0,0,0,2,0,0,0, + 1,0,0,0,67,0,0,0,115,4,0,0,0,100,1,0, + 83,40,2,0,0,0,117,56,0,0,0,82,101,116,117,114, + 110,32,78,111,110,101,32,97,115,32,98,117,105,108,116,45, + 105,110,32,109,111,100,117,108,101,115,32,100,111,32,110,111, + 116,32,104,97,118,101,32,115,111,117,114,99,101,32,99,111, + 100,101,46,78,40,0,0,0,0,40,2,0,0,0,117,3, + 0,0,0,99,108,115,117,8,0,0,0,102,117,108,108,110, + 97,109,101,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 10,0,0,0,103,101,116,95,115,111,117,114,99,101,227,2, + 0,0,115,2,0,0,0,0,4,117,26,0,0,0,66,117, + 105,108,116,105,110,73,109,112,111,114,116,101,114,46,103,101, + 116,95,115,111,117,114,99,101,99,2,0,0,0,0,0,0, + 0,2,0,0,0,1,0,0,0,67,0,0,0,115,4,0, + 0,0,100,1,0,83,40,2,0,0,0,117,52,0,0,0, + 82,101,116,117,114,110,32,70,97,108,115,101,32,97,115,32, + 98,117,105,108,116,45,105,110,32,109,111,100,117,108,101,115, + 32,97,114,101,32,110,101,118,101,114,32,112,97,99,107,97, + 103,101,115,46,70,40,0,0,0,0,40,2,0,0,0,117, + 3,0,0,0,99,108,115,117,8,0,0,0,102,117,108,108, + 110,97,109,101,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,10,0,0,0,105,115,95,112,97,99,107,97,103,101,233, + 2,0,0,115,2,0,0,0,0,4,117,26,0,0,0,66, + 117,105,108,116,105,110,73,109,112,111,114,116,101,114,46,105, + 115,95,112,97,99,107,97,103,101,40,14,0,0,0,117,8, + 0,0,0,95,95,110,97,109,101,95,95,117,10,0,0,0, + 95,95,109,111,100,117,108,101,95,95,117,12,0,0,0,95, + 95,113,117,97,108,110,97,109,101,95,95,117,7,0,0,0, + 95,95,100,111,99,95,95,117,11,0,0,0,99,108,97,115, + 115,109,101,116,104,111,100,117,11,0,0,0,109,111,100,117, + 108,101,95,114,101,112,114,117,11,0,0,0,102,105,110,100, + 95,109,111,100,117,108,101,117,11,0,0,0,115,101,116,95, + 112,97,99,107,97,103,101,117,10,0,0,0,115,101,116,95, + 108,111,97,100,101,114,117,17,0,0,0,95,114,101,113,117, + 105,114,101,115,95,98,117,105,108,116,105,110,117,11,0,0, + 0,108,111,97,100,95,109,111,100,117,108,101,117,8,0,0, + 0,103,101,116,95,99,111,100,101,117,10,0,0,0,103,101, + 116,95,115,111,117,114,99,101,117,10,0,0,0,105,115,95, + 112,97,99,107,97,103,101,40,1,0,0,0,117,10,0,0, + 0,95,95,108,111,99,97,108,115,95,95,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,15,0,0,0,66,117,105,108, + 116,105,110,73,109,112,111,114,116,101,114,183,2,0,0,115, + 28,0,0,0,16,7,6,2,18,4,3,1,18,10,3,1, + 3,1,3,1,27,11,3,1,21,5,3,1,21,5,3,1, + 117,15,0,0,0,66,117,105,108,116,105,110,73,109,112,111, + 114,116,101,114,99,1,0,0,0,0,0,0,0,1,0,0, + 0,6,0,0,0,66,0,0,0,115,173,0,0,0,124,0, + 0,69,101,0,0,90,1,0,100,0,0,90,2,0,100,1, + 0,90,3,0,101,4,0,100,2,0,100,3,0,132,0,0, + 131,1,0,90,5,0,101,4,0,100,4,0,100,5,0,100, + 6,0,132,1,0,131,1,0,90,6,0,101,4,0,101,7, + 0,101,8,0,101,9,0,100,7,0,100,8,0,132,0,0, + 131,1,0,131,1,0,131,1,0,131,1,0,90,10,0,101, + 4,0,101,9,0,100,9,0,100,10,0,132,0,0,131,1, + 0,131,1,0,90,11,0,101,4,0,101,9,0,100,11,0, + 100,12,0,132,0,0,131,1,0,131,1,0,90,12,0,101, + 4,0,101,9,0,100,13,0,100,14,0,132,0,0,131,1, + 0,131,1,0,90,13,0,100,4,0,83,40,15,0,0,0, + 117,14,0,0,0,70,114,111,122,101,110,73,109,112,111,114, + 116,101,114,117,142,0,0,0,77,101,116,97,32,112,97,116, + 104,32,105,109,112,111,114,116,32,102,111,114,32,102,114,111, + 122,101,110,32,109,111,100,117,108,101,115,46,10,10,32,32, + 32,32,65,108,108,32,109,101,116,104,111,100,115,32,97,114, + 101,32,101,105,116,104,101,114,32,99,108,97,115,115,32,111, + 114,32,115,116,97,116,105,99,32,109,101,116,104,111,100,115, + 32,116,111,32,97,118,111,105,100,32,116,104,101,32,110,101, + 101,100,32,116,111,10,32,32,32,32,105,110,115,116,97,110, + 116,105,97,116,101,32,116,104,101,32,99,108,97,115,115,46, + 10,10,32,32,32,32,99,2,0,0,0,0,0,0,0,2, + 0,0,0,2,0,0,0,67,0,0,0,115,16,0,0,0, + 100,1,0,106,0,0,124,1,0,106,1,0,131,1,0,83, + 40,2,0,0,0,78,117,22,0,0,0,60,109,111,100,117, + 108,101,32,39,123,125,39,32,40,102,114,111,122,101,110,41, + 62,40,2,0,0,0,117,6,0,0,0,102,111,114,109,97, + 116,117,8,0,0,0,95,95,110,97,109,101,95,95,40,2, + 0,0,0,117,3,0,0,0,99,108,115,117,1,0,0,0, + 109,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,11,0, + 0,0,109,111,100,117,108,101,95,114,101,112,114,249,2,0, + 0,115,2,0,0,0,0,2,117,26,0,0,0,70,114,111, + 122,101,110,73,109,112,111,114,116,101,114,46,109,111,100,117, + 108,101,95,114,101,112,114,78,99,3,0,0,0,0,0,0, + 0,3,0,0,0,2,0,0,0,67,0,0,0,115,23,0, + 0,0,116,0,0,106,1,0,124,1,0,131,1,0,114,19, + 0,124,0,0,83,100,1,0,83,40,2,0,0,0,117,21, + 0,0,0,70,105,110,100,32,97,32,102,114,111,122,101,110, + 32,109,111,100,117,108,101,46,78,40,2,0,0,0,117,4, + 0,0,0,95,105,109,112,117,9,0,0,0,105,115,95,102, + 114,111,122,101,110,40,3,0,0,0,117,3,0,0,0,99, + 108,115,117,8,0,0,0,102,117,108,108,110,97,109,101,117, + 4,0,0,0,112,97,116,104,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,11,0,0,0,102,105,110,100,95,109,111, + 100,117,108,101,253,2,0,0,115,2,0,0,0,0,3,117, + 26,0,0,0,70,114,111,122,101,110,73,109,112,111,114,116, + 101,114,46,102,105,110,100,95,109,111,100,117,108,101,99,2, + 0,0,0,0,0,0,0,4,0,0,0,9,0,0,0,67, + 0,0,0,115,100,0,0,0,124,1,0,116,0,0,106,1, + 0,107,6,0,125,2,0,121,32,0,116,2,0,116,3,0, + 106,4,0,124,1,0,131,2,0,125,3,0,124,3,0,96, + 5,0,124,3,0,83,87,110,46,0,1,1,1,124,2,0, + 12,114,88,0,124,1,0,116,0,0,106,1,0,107,6,0, + 114,88,0,116,0,0,106,1,0,124,1,0,61,110,0,0, + 130,0,0,89,110,1,0,88,100,1,0,83,40,2,0,0, + 0,117,21,0,0,0,76,111,97,100,32,97,32,102,114,111, + 122,101,110,32,109,111,100,117,108,101,46,78,40,6,0,0, + 0,117,3,0,0,0,115,121,115,117,7,0,0,0,109,111, + 100,117,108,101,115,117,25,0,0,0,95,99,97,108,108,95, + 119,105,116,104,95,102,114,97,109,101,115,95,114,101,109,111, + 118,101,100,117,4,0,0,0,95,105,109,112,117,11,0,0, + 0,105,110,105,116,95,102,114,111,122,101,110,117,8,0,0, + 0,95,95,102,105,108,101,95,95,40,4,0,0,0,117,3, + 0,0,0,99,108,115,117,8,0,0,0,102,117,108,108,110, + 97,109,101,117,9,0,0,0,105,115,95,114,101,108,111,97, + 100,117,1,0,0,0,109,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,11,0,0,0,108,111,97,100,95,109,111,100, + 117,108,101,2,3,0,0,115,18,0,0,0,0,6,15,1, + 3,1,18,2,6,1,8,1,3,1,22,1,13,1,117,26, + 0,0,0,70,114,111,122,101,110,73,109,112,111,114,116,101, + 114,46,108,111,97,100,95,109,111,100,117,108,101,99,2,0, + 0,0,0,0,0,0,2,0,0,0,2,0,0,0,67,0, + 0,0,115,13,0,0,0,116,0,0,106,1,0,124,1,0, + 131,1,0,83,40,1,0,0,0,117,45,0,0,0,82,101, + 116,117,114,110,32,116,104,101,32,99,111,100,101,32,111,98, + 106,101,99,116,32,102,111,114,32,116,104,101,32,102,114,111, + 122,101,110,32,109,111,100,117,108,101,46,40,2,0,0,0, + 117,4,0,0,0,95,105,109,112,117,17,0,0,0,103,101, + 116,95,102,114,111,122,101,110,95,111,98,106,101,99,116,40, + 2,0,0,0,117,3,0,0,0,99,108,115,117,8,0,0, + 0,102,117,108,108,110,97,109,101,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,8,0,0,0,103,101,116,95,99,111, + 100,101,19,3,0,0,115,2,0,0,0,0,4,117,23,0, + 0,0,70,114,111,122,101,110,73,109,112,111,114,116,101,114, + 46,103,101,116,95,99,111,100,101,99,2,0,0,0,0,0, + 0,0,2,0,0,0,1,0,0,0,67,0,0,0,115,4, + 0,0,0,100,1,0,83,40,2,0,0,0,117,54,0,0, + 0,82,101,116,117,114,110,32,78,111,110,101,32,97,115,32, + 102,114,111,122,101,110,32,109,111,100,117,108,101,115,32,100, + 111,32,110,111,116,32,104,97,118,101,32,115,111,117,114,99, + 101,32,99,111,100,101,46,78,40,0,0,0,0,40,2,0, + 0,0,117,3,0,0,0,99,108,115,117,8,0,0,0,102, + 117,108,108,110,97,109,101,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,10,0,0,0,103,101,116,95,115,111,117,114, + 99,101,25,3,0,0,115,2,0,0,0,0,4,117,25,0, + 0,0,70,114,111,122,101,110,73,109,112,111,114,116,101,114, + 46,103,101,116,95,115,111,117,114,99,101,99,2,0,0,0, + 0,0,0,0,2,0,0,0,2,0,0,0,67,0,0,0, + 115,13,0,0,0,116,0,0,106,1,0,124,1,0,131,1, + 0,83,40,1,0,0,0,117,46,0,0,0,82,101,116,117, + 114,110,32,84,114,117,101,32,105,102,32,116,104,101,32,102, + 114,111,122,101,110,32,109,111,100,117,108,101,32,105,115,32, + 97,32,112,97,99,107,97,103,101,46,40,2,0,0,0,117, + 4,0,0,0,95,105,109,112,117,17,0,0,0,105,115,95, + 102,114,111,122,101,110,95,112,97,99,107,97,103,101,40,2, + 0,0,0,117,3,0,0,0,99,108,115,117,8,0,0,0, + 102,117,108,108,110,97,109,101,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,10,0,0,0,105,115,95,112,97,99,107, + 97,103,101,31,3,0,0,115,2,0,0,0,0,4,117,25, + 0,0,0,70,114,111,122,101,110,73,109,112,111,114,116,101, + 114,46,105,115,95,112,97,99,107,97,103,101,40,14,0,0, + 0,117,8,0,0,0,95,95,110,97,109,101,95,95,117,10, + 0,0,0,95,95,109,111,100,117,108,101,95,95,117,12,0, + 0,0,95,95,113,117,97,108,110,97,109,101,95,95,117,7, + 0,0,0,95,95,100,111,99,95,95,117,11,0,0,0,99, + 108,97,115,115,109,101,116,104,111,100,117,11,0,0,0,109, + 111,100,117,108,101,95,114,101,112,114,117,11,0,0,0,102, + 105,110,100,95,109,111,100,117,108,101,117,11,0,0,0,115, + 101,116,95,112,97,99,107,97,103,101,117,10,0,0,0,115, + 101,116,95,108,111,97,100,101,114,117,16,0,0,0,95,114, + 101,113,117,105,114,101,115,95,102,114,111,122,101,110,117,11, + 0,0,0,108,111,97,100,95,109,111,100,117,108,101,117,8, + 0,0,0,103,101,116,95,99,111,100,101,117,10,0,0,0, + 103,101,116,95,115,111,117,114,99,101,117,10,0,0,0,105, + 115,95,112,97,99,107,97,103,101,40,1,0,0,0,117,10, + 0,0,0,95,95,108,111,99,97,108,115,95,95,40,0,0, + 0,0,40,0,0,0,0,117,29,0,0,0,60,102,114,111, + 122,101,110,32,105,109,112,111,114,116,108,105,98,46,95,98, + 111,111,116,115,116,114,97,112,62,117,14,0,0,0,70,114, + 111,122,101,110,73,109,112,111,114,116,101,114,240,2,0,0, + 115,28,0,0,0,16,7,6,2,18,4,3,1,18,4,3, + 1,3,1,3,1,27,14,3,1,21,5,3,1,21,5,3, + 1,117,14,0,0,0,70,114,111,122,101,110,73,109,112,111, + 114,116,101,114,99,1,0,0,0,0,0,0,0,1,0,0, + 0,4,0,0,0,66,0,0,0,115,101,0,0,0,124,0, + 0,69,101,0,0,90,1,0,100,0,0,90,2,0,100,1, + 0,90,3,0,100,2,0,90,4,0,100,3,0,90,5,0, + 100,4,0,90,6,0,101,7,0,100,5,0,100,6,0,132, + 0,0,131,1,0,90,8,0,101,7,0,100,7,0,100,8, + 0,132,0,0,131,1,0,90,9,0,101,7,0,100,9,0, + 100,10,0,100,11,0,132,1,0,131,1,0,90,10,0,100, + 9,0,83,40,12,0,0,0,117,21,0,0,0,87,105,110, + 100,111,119,115,82,101,103,105,115,116,114,121,70,105,110,100, + 101,114,117,67,0,0,0,77,101,116,97,32,112,97,116,104, + 32,102,105,110,100,101,114,32,102,111,114,32,109,111,100,117, + 108,101,115,32,100,101,99,108,97,114,101,100,32,105,110,32, + 116,104,101,32,87,105,110,100,111,119,115,32,114,101,103,105, + 115,116,114,121,46,10,32,32,32,32,117,59,0,0,0,83, + 111,102,116,119,97,114,101,92,80,121,116,104,111,110,92,80, + 121,116,104,111,110,67,111,114,101,92,123,115,121,115,95,118, + 101,114,115,105,111,110,125,92,77,111,100,117,108,101,115,92, + 123,102,117,108,108,110,97,109,101,125,117,65,0,0,0,83, + 111,102,116,119,97,114,101,92,80,121,116,104,111,110,92,80, + 121,116,104,111,110,67,111,114,101,92,123,115,121,115,95,118, + 101,114,115,105,111,110,125,92,77,111,100,117,108,101,115,92, + 123,102,117,108,108,110,97,109,101,125,92,68,101,98,117,103, + 70,99,2,0,0,0,0,0,0,0,2,0,0,0,11,0, + 0,0,67,0,0,0,115,67,0,0,0,121,23,0,116,0, + 0,106,1,0,116,0,0,106,2,0,124,1,0,131,2,0, + 83,87,110,37,0,4,116,3,0,107,10,0,114,62,0,1, + 1,1,116,0,0,106,1,0,116,0,0,106,4,0,124,1, + 0,131,2,0,83,89,110,1,0,88,100,0,0,83,40,1, + 0,0,0,78,40,5,0,0,0,117,7,0,0,0,95,119, + 105,110,114,101,103,117,7,0,0,0,79,112,101,110,75,101, + 121,117,17,0,0,0,72,75,69,89,95,67,85,82,82,69, + 78,84,95,85,83,69,82,117,7,0,0,0,79,83,69,114, + 114,111,114,117,18,0,0,0,72,75,69,89,95,76,79,67, + 65,76,95,77,65,67,72,73,78,69,40,2,0,0,0,117, + 3,0,0,0,99,108,115,117,3,0,0,0,107,101,121,40, + 0,0,0,0,40,0,0,0,0,117,29,0,0,0,60,102, + 114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46, + 95,98,111,111,116,115,116,114,97,112,62,117,14,0,0,0, + 95,111,112,101,110,95,114,101,103,105,115,116,114,121,51,3, + 0,0,115,8,0,0,0,0,2,3,1,23,1,13,1,117, + 36,0,0,0,87,105,110,100,111,119,115,82,101,103,105,115, + 116,114,121,70,105,110,100,101,114,46,95,111,112,101,110,95, + 114,101,103,105,115,116,114,121,99,2,0,0,0,0,0,0, + 0,6,0,0,0,16,0,0,0,67,0,0,0,115,142,0, + 0,0,124,0,0,106,0,0,114,21,0,124,0,0,106,1, + 0,125,2,0,110,9,0,124,0,0,106,2,0,125,2,0, + 124,2,0,106,3,0,100,1,0,124,1,0,100,2,0,116, + 4,0,106,5,0,100,0,0,100,3,0,133,2,0,25,131, + 0,2,125,3,0,121,46,0,124,0,0,106,6,0,124,3, + 0,131,1,0,143,25,0,125,4,0,116,7,0,106,8,0, + 124,4,0,100,4,0,131,2,0,125,5,0,87,100,0,0, + 81,88,87,110,22,0,4,116,9,0,107,10,0,114,137,0, + 1,1,1,100,0,0,83,89,110,1,0,88,124,5,0,83, + 40,5,0,0,0,78,117,8,0,0,0,102,117,108,108,110, + 97,109,101,117,11,0,0,0,115,121,115,95,118,101,114,115, + 105,111,110,105,3,0,0,0,117,0,0,0,0,40,10,0, + 0,0,117,11,0,0,0,68,69,66,85,71,95,66,85,73, + 76,68,117,18,0,0,0,82,69,71,73,83,84,82,89,95, + 75,69,89,95,68,69,66,85,71,117,12,0,0,0,82,69, + 71,73,83,84,82,89,95,75,69,89,117,6,0,0,0,102, + 111,114,109,97,116,117,3,0,0,0,115,121,115,117,7,0, + 0,0,118,101,114,115,105,111,110,117,14,0,0,0,95,111, + 112,101,110,95,114,101,103,105,115,116,114,121,117,7,0,0, + 0,95,119,105,110,114,101,103,117,10,0,0,0,81,117,101, + 114,121,86,97,108,117,101,117,7,0,0,0,79,83,69,114, + 114,111,114,40,6,0,0,0,117,3,0,0,0,99,108,115, + 117,8,0,0,0,102,117,108,108,110,97,109,101,117,12,0, + 0,0,114,101,103,105,115,116,114,121,95,107,101,121,117,3, + 0,0,0,107,101,121,117,4,0,0,0,104,107,101,121,117, + 8,0,0,0,102,105,108,101,112,97,116,104,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,16,0,0,0,95,115,101, + 97,114,99,104,95,114,101,103,105,115,116,114,121,58,3,0, + 0,115,22,0,0,0,0,2,9,1,12,2,9,1,15,1, + 22,1,3,1,18,1,28,1,13,1,9,1,117,38,0,0, + 0,87,105,110,100,111,119,115,82,101,103,105,115,116,114,121, + 70,105,110,100,101,114,46,95,115,101,97,114,99,104,95,114, + 101,103,105,115,116,114,121,78,99,3,0,0,0,0,0,0, + 0,7,0,0,0,12,0,0,0,67,0,0,0,115,140,0, + 0,0,124,0,0,106,0,0,124,1,0,131,1,0,125,3, + 0,124,3,0,100,1,0,107,8,0,114,31,0,100,1,0, + 83,121,17,0,116,1,0,106,2,0,124,3,0,131,1,0, + 1,87,110,22,0,4,116,3,0,107,10,0,114,72,0,1, + 1,1,100,1,0,83,89,110,1,0,88,120,60,0,116,4, + 0,131,0,0,68,93,49,0,92,3,0,125,4,0,125,5, + 0,125,6,0,124,3,0,106,5,0,116,6,0,124,5,0, + 131,1,0,131,1,0,114,83,0,124,4,0,124,1,0,124, + 3,0,131,2,0,83,113,83,0,87,100,1,0,83,40,2, + 0,0,0,117,34,0,0,0,70,105,110,100,32,109,111,100, + 117,108,101,32,110,97,109,101,100,32,105,110,32,116,104,101, + 32,114,101,103,105,115,116,114,121,46,78,40,7,0,0,0, + 117,16,0,0,0,95,115,101,97,114,99,104,95,114,101,103, + 105,115,116,114,121,117,3,0,0,0,95,111,115,117,4,0, + 0,0,115,116,97,116,117,7,0,0,0,79,83,69,114,114, + 111,114,117,27,0,0,0,95,103,101,116,95,115,117,112,112, + 111,114,116,101,100,95,102,105,108,101,95,108,111,97,100,101, + 114,115,117,8,0,0,0,101,110,100,115,119,105,116,104,117, + 5,0,0,0,116,117,112,108,101,40,7,0,0,0,117,3, + 0,0,0,99,108,115,117,8,0,0,0,102,117,108,108,110, + 97,109,101,117,4,0,0,0,112,97,116,104,117,8,0,0, + 0,102,105,108,101,112,97,116,104,117,6,0,0,0,108,111, + 97,100,101,114,117,8,0,0,0,115,117,102,102,105,120,101, + 115,117,1,0,0,0,95,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,11,0,0,0,102,105,110,100,95,109,111,100, + 117,108,101,73,3,0,0,115,20,0,0,0,0,3,15,1, + 12,1,4,1,3,1,17,1,13,1,9,1,25,1,21,1, + 117,33,0,0,0,87,105,110,100,111,119,115,82,101,103,105, + 115,116,114,121,70,105,110,100,101,114,46,102,105,110,100,95, + 109,111,100,117,108,101,40,11,0,0,0,117,8,0,0,0, + 95,95,110,97,109,101,95,95,117,10,0,0,0,95,95,109, + 111,100,117,108,101,95,95,117,12,0,0,0,95,95,113,117, + 97,108,110,97,109,101,95,95,117,7,0,0,0,95,95,100, + 111,99,95,95,117,12,0,0,0,82,69,71,73,83,84,82, + 89,95,75,69,89,117,18,0,0,0,82,69,71,73,83,84, + 82,89,95,75,69,89,95,68,69,66,85,71,117,11,0,0, + 0,68,69,66,85,71,95,66,85,73,76,68,117,11,0,0, + 0,99,108,97,115,115,109,101,116,104,111,100,117,14,0,0, + 0,95,111,112,101,110,95,114,101,103,105,115,116,114,121,117, + 16,0,0,0,95,115,101,97,114,99,104,95,114,101,103,105, + 115,116,114,121,117,11,0,0,0,102,105,110,100,95,109,111, + 100,117,108,101,40,1,0,0,0,117,10,0,0,0,95,95, + 108,111,99,97,108,115,95,95,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,21,0,0,0,87,105,110,100,111,119,115, + 82,101,103,105,115,116,114,121,70,105,110,100,101,114,38,3, + 0,0,115,16,0,0,0,16,3,6,3,6,3,6,2,6, + 2,18,7,18,15,3,1,117,21,0,0,0,87,105,110,100, + 111,119,115,82,101,103,105,115,116,114,121,70,105,110,100,101, + 114,99,1,0,0,0,0,0,0,0,1,0,0,0,5,0, + 0,0,66,0,0,0,115,62,0,0,0,124,0,0,69,101, + 0,0,90,1,0,100,0,0,90,2,0,100,1,0,90,3, + 0,100,2,0,100,3,0,132,0,0,90,4,0,101,5,0, + 100,4,0,100,5,0,100,6,0,100,7,0,132,0,1,131, + 1,0,90,6,0,100,8,0,83,40,9,0,0,0,117,13, + 0,0,0,95,76,111,97,100,101,114,66,97,115,105,99,115, + 117,83,0,0,0,66,97,115,101,32,99,108,97,115,115,32, + 111,102,32,99,111,109,109,111,110,32,99,111,100,101,32,110, + 101,101,100,101,100,32,98,121,32,98,111,116,104,32,83,111, + 117,114,99,101,76,111,97,100,101,114,32,97,110,100,10,32, + 32,32,32,83,111,117,114,99,101,108,101,115,115,70,105,108, + 101,76,111,97,100,101,114,46,99,2,0,0,0,0,0,0, + 0,5,0,0,0,3,0,0,0,67,0,0,0,115,88,0, + 0,0,116,0,0,124,0,0,106,1,0,124,1,0,131,1, + 0,131,1,0,100,1,0,25,125,2,0,124,2,0,106,2, + 0,100,2,0,100,1,0,131,2,0,100,3,0,25,125,3, + 0,124,1,0,106,3,0,100,2,0,131,1,0,100,4,0, + 25,125,4,0,124,3,0,100,5,0,107,2,0,111,87,0, + 124,4,0,100,5,0,107,3,0,83,40,6,0,0,0,117, + 141,0,0,0,67,111,110,99,114,101,116,101,32,105,109,112, + 108,101,109,101,110,116,97,116,105,111,110,32,111,102,32,73, + 110,115,112,101,99,116,76,111,97,100,101,114,46,105,115,95, + 112,97,99,107,97,103,101,32,98,121,32,99,104,101,99,107, + 105,110,103,32,105,102,10,32,32,32,32,32,32,32,32,116, + 104,101,32,112,97,116,104,32,114,101,116,117,114,110,101,100, + 32,98,121,32,103,101,116,95,102,105,108,101,110,97,109,101, + 32,104,97,115,32,97,32,102,105,108,101,110,97,109,101,32, + 111,102,32,39,95,95,105,110,105,116,95,95,46,112,121,39, + 46,105,1,0,0,0,117,1,0,0,0,46,105,0,0,0, + 0,105,2,0,0,0,117,8,0,0,0,95,95,105,110,105, + 116,95,95,40,4,0,0,0,117,11,0,0,0,95,112,97, + 116,104,95,115,112,108,105,116,117,12,0,0,0,103,101,116, + 95,102,105,108,101,110,97,109,101,117,6,0,0,0,114,115, + 112,108,105,116,117,10,0,0,0,114,112,97,114,116,105,116, + 105,111,110,40,5,0,0,0,117,4,0,0,0,115,101,108, + 102,117,8,0,0,0,102,117,108,108,110,97,109,101,117,8, + 0,0,0,102,105,108,101,110,97,109,101,117,13,0,0,0, + 102,105,108,101,110,97,109,101,95,98,97,115,101,117,9,0, + 0,0,116,97,105,108,95,110,97,109,101,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,10,0,0,0,105,115,95,112, + 97,99,107,97,103,101,93,3,0,0,115,8,0,0,0,0, + 3,25,1,22,1,19,1,117,24,0,0,0,95,76,111,97, + 100,101,114,66,97,115,105,99,115,46,105,115,95,112,97,99, + 107,97,103,101,117,10,0,0,0,115,111,117,114,99,101,108, + 101,115,115,70,99,2,0,0,0,1,0,0,0,5,0,0, + 0,12,0,0,0,67,0,0,0,115,227,0,0,0,124,1, + 0,106,0,0,125,3,0,124,0,0,106,1,0,124,3,0, + 131,1,0,125,4,0,124,0,0,106,2,0,124,3,0,131, + 1,0,124,1,0,95,3,0,124,2,0,115,106,0,121,22, + 0,116,4,0,124,1,0,106,3,0,131,1,0,124,1,0, + 95,5,0,87,113,118,0,4,116,6,0,107,10,0,114,102, + 0,1,1,1,124,1,0,106,3,0,124,1,0,95,5,0, + 89,113,118,0,88,110,12,0,124,1,0,106,3,0,124,1, + 0,95,5,0,124,3,0,124,1,0,95,7,0,124,0,0, + 106,8,0,124,3,0,131,1,0,114,170,0,116,9,0,124, + 1,0,106,3,0,131,1,0,100,1,0,25,103,1,0,124, + 1,0,95,10,0,110,25,0,124,1,0,106,7,0,106,11, + 0,100,2,0,131,1,0,100,1,0,25,124,1,0,95,7, + 0,124,0,0,124,1,0,95,12,0,116,13,0,116,14,0, + 124,4,0,124,1,0,106,15,0,131,3,0,1,124,1,0, + 83,40,3,0,0,0,117,82,0,0,0,72,101,108,112,101, + 114,32,102,111,114,32,108,111,97,100,95,109,111,100,117,108, + 101,32,97,98,108,101,32,116,111,32,104,97,110,100,108,101, + 32,101,105,116,104,101,114,32,115,111,117,114,99,101,32,111, + 114,32,115,111,117,114,99,101,108,101,115,115,10,32,32,32, + 32,32,32,32,32,108,111,97,100,105,110,103,46,105,0,0, + 0,0,117,1,0,0,0,46,40,16,0,0,0,117,8,0, + 0,0,95,95,110,97,109,101,95,95,117,8,0,0,0,103, + 101,116,95,99,111,100,101,117,12,0,0,0,103,101,116,95, + 102,105,108,101,110,97,109,101,117,8,0,0,0,95,95,102, + 105,108,101,95,95,117,17,0,0,0,99,97,99,104,101,95, + 102,114,111,109,95,115,111,117,114,99,101,117,10,0,0,0, + 95,95,99,97,99,104,101,100,95,95,117,19,0,0,0,78, + 111,116,73,109,112,108,101,109,101,110,116,101,100,69,114,114, + 111,114,117,11,0,0,0,95,95,112,97,99,107,97,103,101, + 95,95,117,10,0,0,0,105,115,95,112,97,99,107,97,103, + 101,117,11,0,0,0,95,112,97,116,104,95,115,112,108,105, + 116,117,8,0,0,0,95,95,112,97,116,104,95,95,117,10, + 0,0,0,114,112,97,114,116,105,116,105,111,110,117,10,0, + 0,0,95,95,108,111,97,100,101,114,95,95,117,25,0,0, + 0,95,99,97,108,108,95,119,105,116,104,95,102,114,97,109, + 101,115,95,114,101,109,111,118,101,100,117,4,0,0,0,101, + 120,101,99,117,8,0,0,0,95,95,100,105,99,116,95,95, + 40,5,0,0,0,117,4,0,0,0,115,101,108,102,117,6, + 0,0,0,109,111,100,117,108,101,117,10,0,0,0,115,111, + 117,114,99,101,108,101,115,115,117,4,0,0,0,110,97,109, + 101,117,11,0,0,0,99,111,100,101,95,111,98,106,101,99, + 116,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,12,0, + 0,0,95,108,111,97,100,95,109,111,100,117,108,101,101,3, + 0,0,115,32,0,0,0,0,4,9,1,15,1,18,1,6, + 1,3,1,22,1,13,1,20,2,12,1,9,1,15,1,28, + 2,25,1,9,1,19,1,117,26,0,0,0,95,76,111,97, + 100,101,114,66,97,115,105,99,115,46,95,108,111,97,100,95, + 109,111,100,117,108,101,78,40,7,0,0,0,117,8,0,0, + 0,95,95,110,97,109,101,95,95,117,10,0,0,0,95,95, + 109,111,100,117,108,101,95,95,117,12,0,0,0,95,95,113, + 117,97,108,110,97,109,101,95,95,117,7,0,0,0,95,95, + 100,111,99,95,95,117,10,0,0,0,105,115,95,112,97,99, + 107,97,103,101,117,17,0,0,0,109,111,100,117,108,101,95, + 102,111,114,95,108,111,97,100,101,114,117,12,0,0,0,95, + 108,111,97,100,95,109,111,100,117,108,101,40,1,0,0,0, + 117,10,0,0,0,95,95,108,111,99,97,108,115,95,95,40, + 0,0,0,0,40,0,0,0,0,117,29,0,0,0,60,102, + 114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46, + 95,98,111,111,116,115,116,114,97,112,62,117,13,0,0,0, + 95,76,111,97,100,101,114,66,97,115,105,99,115,88,3,0, + 0,115,8,0,0,0,16,3,6,2,12,8,6,1,117,13, + 0,0,0,95,76,111,97,100,101,114,66,97,115,105,99,115, + 99,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0, + 0,66,0,0,0,115,116,0,0,0,124,0,0,69,101,0, + 0,90,1,0,100,0,0,90,2,0,100,1,0,100,2,0, + 132,0,0,90,3,0,100,3,0,100,4,0,132,0,0,90, + 4,0,100,5,0,100,6,0,132,0,0,90,5,0,100,7, + 0,100,8,0,132,0,0,90,6,0,100,9,0,100,10,0, + 132,0,0,90,7,0,100,11,0,100,12,0,132,0,0,90, + 8,0,100,13,0,100,14,0,132,0,0,90,9,0,100,15, + 0,100,16,0,132,0,0,90,10,0,100,17,0,83,40,18, + 0,0,0,117,12,0,0,0,83,111,117,114,99,101,76,111, + 97,100,101,114,99,2,0,0,0,0,0,0,0,2,0,0, + 0,1,0,0,0,67,0,0,0,115,10,0,0,0,116,0, + 0,130,1,0,100,1,0,83,40,2,0,0,0,117,121,0, + 0,0,79,112,116,105,111,110,97,108,32,109,101,116,104,111, + 100,32,116,104,97,116,32,114,101,116,117,114,110,115,32,116, + 104,101,32,109,111,100,105,102,105,99,97,116,105,111,110,32, + 116,105,109,101,32,40,97,110,32,105,110,116,41,32,102,111, + 114,32,116,104,101,10,32,32,32,32,32,32,32,32,115,112, + 101,99,105,102,105,101,100,32,112,97,116,104,44,32,119,104, + 101,114,101,32,112,97,116,104,32,105,115,32,97,32,115,116, + 114,46,10,32,32,32,32,32,32,32,32,78,40,1,0,0, + 0,117,19,0,0,0,78,111,116,73,109,112,108,101,109,101, + 110,116,101,100,69,114,114,111,114,40,2,0,0,0,117,4, + 0,0,0,115,101,108,102,117,4,0,0,0,112,97,116,104, + 40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,10,0,0, + 0,112,97,116,104,95,109,116,105,109,101,127,3,0,0,115, + 2,0,0,0,0,4,117,23,0,0,0,83,111,117,114,99, + 101,76,111,97,100,101,114,46,112,97,116,104,95,109,116,105, + 109,101,99,2,0,0,0,0,0,0,0,2,0,0,0,3, + 0,0,0,67,0,0,0,115,20,0,0,0,105,1,0,124, + 0,0,106,0,0,124,1,0,131,1,0,100,1,0,54,83, + 40,2,0,0,0,117,114,1,0,0,79,112,116,105,111,110, + 97,108,32,109,101,116,104,111,100,32,114,101,116,117,114,110, + 105,110,103,32,97,32,109,101,116,97,100,97,116,97,32,100, + 105,99,116,32,102,111,114,32,116,104,101,32,115,112,101,99, + 105,102,105,101,100,32,112,97,116,104,10,32,32,32,32,32, + 32,32,32,116,111,32,98,121,32,116,104,101,32,112,97,116, + 104,32,40,115,116,114,41,46,10,32,32,32,32,32,32,32, + 32,80,111,115,115,105,98,108,101,32,107,101,121,115,58,10, + 32,32,32,32,32,32,32,32,45,32,39,109,116,105,109,101, + 39,32,40,109,97,110,100,97,116,111,114,121,41,32,105,115, + 32,116,104,101,32,110,117,109,101,114,105,99,32,116,105,109, + 101,115,116,97,109,112,32,111,102,32,108,97,115,116,32,115, + 111,117,114,99,101,10,32,32,32,32,32,32,32,32,32,32, + 99,111,100,101,32,109,111,100,105,102,105,99,97,116,105,111, + 110,59,10,32,32,32,32,32,32,32,32,45,32,39,115,105, + 122,101,39,32,40,111,112,116,105,111,110,97,108,41,32,105, + 115,32,116,104,101,32,115,105,122,101,32,105,110,32,98,121, + 116,101,115,32,111,102,32,116,104,101,32,115,111,117,114,99, + 101,32,99,111,100,101,46,10,10,32,32,32,32,32,32,32, + 32,73,109,112,108,101,109,101,110,116,105,110,103,32,116,104, + 105,115,32,109,101,116,104,111,100,32,97,108,108,111,119,115, + 32,116,104,101,32,108,111,97,100,101,114,32,116,111,32,114, + 101,97,100,32,98,121,116,101,99,111,100,101,32,102,105,108, + 101,115,46,10,32,32,32,32,32,32,32,32,117,5,0,0, + 0,109,116,105,109,101,40,1,0,0,0,117,10,0,0,0, + 112,97,116,104,95,109,116,105,109,101,40,2,0,0,0,117, + 4,0,0,0,115,101,108,102,117,4,0,0,0,112,97,116, + 104,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,10,0, + 0,0,112,97,116,104,95,115,116,97,116,115,133,3,0,0, + 115,2,0,0,0,0,10,117,23,0,0,0,83,111,117,114, + 99,101,76,111,97,100,101,114,46,112,97,116,104,95,115,116, + 97,116,115,99,4,0,0,0,0,0,0,0,4,0,0,0, + 3,0,0,0,67,0,0,0,115,16,0,0,0,124,0,0, + 106,0,0,124,2,0,124,3,0,131,2,0,83,40,1,0, + 0,0,117,228,0,0,0,79,112,116,105,111,110,97,108,32, + 109,101,116,104,111,100,32,119,104,105,99,104,32,119,114,105, + 116,101,115,32,100,97,116,97,32,40,98,121,116,101,115,41, + 32,116,111,32,97,32,102,105,108,101,32,112,97,116,104,32, + 40,97,32,115,116,114,41,46,10,10,32,32,32,32,32,32, + 32,32,73,109,112,108,101,109,101,110,116,105,110,103,32,116, + 104,105,115,32,109,101,116,104,111,100,32,97,108,108,111,119, + 115,32,102,111,114,32,116,104,101,32,119,114,105,116,105,110, + 103,32,111,102,32,98,121,116,101,99,111,100,101,32,102,105, + 108,101,115,46,10,10,32,32,32,32,32,32,32,32,84,104, + 101,32,115,111,117,114,99,101,32,112,97,116,104,32,105,115, + 32,110,101,101,100,101,100,32,105,110,32,111,114,100,101,114, + 32,116,111,32,99,111,114,114,101,99,116,108,121,32,116,114, + 97,110,115,102,101,114,32,112,101,114,109,105,115,115,105,111, + 110,115,10,32,32,32,32,32,32,32,32,40,1,0,0,0, + 117,8,0,0,0,115,101,116,95,100,97,116,97,40,4,0, + 0,0,117,4,0,0,0,115,101,108,102,117,11,0,0,0, + 115,111,117,114,99,101,95,112,97,116,104,117,10,0,0,0, + 99,97,99,104,101,95,112,97,116,104,117,4,0,0,0,100, + 97,116,97,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 15,0,0,0,95,99,97,99,104,101,95,98,121,116,101,99, + 111,100,101,145,3,0,0,115,2,0,0,0,0,8,117,28, + 0,0,0,83,111,117,114,99,101,76,111,97,100,101,114,46, + 95,99,97,99,104,101,95,98,121,116,101,99,111,100,101,99, + 3,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, + 67,0,0,0,115,10,0,0,0,116,0,0,130,1,0,100, + 1,0,83,40,2,0,0,0,117,151,0,0,0,79,112,116, + 105,111,110,97,108,32,109,101,116,104,111,100,32,119,104,105, + 99,104,32,119,114,105,116,101,115,32,100,97,116,97,32,40, + 98,121,116,101,115,41,32,116,111,32,97,32,102,105,108,101, + 32,112,97,116,104,32,40,97,32,115,116,114,41,46,10,10, + 32,32,32,32,32,32,32,32,73,109,112,108,101,109,101,110, + 116,105,110,103,32,116,104,105,115,32,109,101,116,104,111,100, + 32,97,108,108,111,119,115,32,102,111,114,32,116,104,101,32, + 119,114,105,116,105,110,103,32,111,102,32,98,121,116,101,99, + 111,100,101,32,102,105,108,101,115,46,10,10,32,32,32,32, + 32,32,32,32,78,40,1,0,0,0,117,19,0,0,0,78, + 111,116,73,109,112,108,101,109,101,110,116,101,100,69,114,114, + 111,114,40,3,0,0,0,117,4,0,0,0,115,101,108,102, + 117,4,0,0,0,112,97,116,104,117,4,0,0,0,100,97, + 116,97,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,8, + 0,0,0,115,101,116,95,100,97,116,97,155,3,0,0,115, + 2,0,0,0,0,6,117,21,0,0,0,83,111,117,114,99, + 101,76,111,97,100,101,114,46,115,101,116,95,100,97,116,97, + 99,2,0,0,0,0,0,0,0,9,0,0,0,44,0,0, + 0,67,0,0,0,115,62,1,0,0,100,1,0,100,2,0, + 108,0,0,125,2,0,124,0,0,106,1,0,124,1,0,131, + 1,0,125,3,0,121,19,0,124,0,0,106,2,0,124,3, + 0,131,1,0,125,4,0,87,110,58,0,4,116,3,0,107, + 10,0,114,106,0,1,125,5,0,1,122,26,0,116,4,0, + 100,3,0,100,4,0,124,1,0,131,1,1,124,5,0,130, + 2,0,87,89,100,2,0,100,2,0,125,5,0,126,5,0, + 88,110,1,0,88,116,5,0,106,6,0,124,4,0,131,1, + 0,106,7,0,125,6,0,121,19,0,124,2,0,106,8,0, + 124,6,0,131,1,0,125,7,0,87,110,58,0,4,116,9, + 0,107,10,0,114,204,0,1,125,5,0,1,122,26,0,116, + 4,0,100,5,0,100,4,0,124,1,0,131,1,1,124,5, + 0,130,2,0,87,89,100,2,0,100,2,0,125,5,0,126, + 5,0,88,110,1,0,88,116,5,0,106,10,0,100,2,0, + 100,6,0,131,2,0,125,8,0,121,30,0,124,8,0,106, + 11,0,124,4,0,106,11,0,124,7,0,100,1,0,25,131, + 1,0,131,1,0,83,87,110,58,0,4,116,12,0,107,10, + 0,114,57,1,1,125,5,0,1,122,26,0,116,4,0,100, + 7,0,100,4,0,124,1,0,131,1,1,124,5,0,130,2, + 0,87,89,100,2,0,100,2,0,125,5,0,126,5,0,88, + 110,1,0,88,100,2,0,83,40,8,0,0,0,117,52,0, + 0,0,67,111,110,99,114,101,116,101,32,105,109,112,108,101, + 109,101,110,116,97,116,105,111,110,32,111,102,32,73,110,115, + 112,101,99,116,76,111,97,100,101,114,46,103,101,116,95,115, + 111,117,114,99,101,46,105,0,0,0,0,78,117,39,0,0, + 0,115,111,117,114,99,101,32,110,111,116,32,97,118,97,105, + 108,97,98,108,101,32,116,104,114,111,117,103,104,32,103,101, + 116,95,100,97,116,97,40,41,117,4,0,0,0,110,97,109, + 101,117,25,0,0,0,70,97,105,108,101,100,32,116,111,32, + 100,101,116,101,99,116,32,101,110,99,111,100,105,110,103,84, + 117,28,0,0,0,70,97,105,108,101,100,32,116,111,32,100, + 101,99,111,100,101,32,115,111,117,114,99,101,32,102,105,108, + 101,40,13,0,0,0,117,8,0,0,0,116,111,107,101,110, + 105,122,101,117,12,0,0,0,103,101,116,95,102,105,108,101, + 110,97,109,101,117,8,0,0,0,103,101,116,95,100,97,116, + 97,117,7,0,0,0,79,83,69,114,114,111,114,117,11,0, + 0,0,73,109,112,111,114,116,69,114,114,111,114,117,3,0, + 0,0,95,105,111,117,7,0,0,0,66,121,116,101,115,73, + 79,117,8,0,0,0,114,101,97,100,108,105,110,101,117,15, + 0,0,0,100,101,116,101,99,116,95,101,110,99,111,100,105, + 110,103,117,11,0,0,0,83,121,110,116,97,120,69,114,114, + 111,114,117,25,0,0,0,73,110,99,114,101,109,101,110,116, + 97,108,78,101,119,108,105,110,101,68,101,99,111,100,101,114, + 117,6,0,0,0,100,101,99,111,100,101,117,18,0,0,0, + 85,110,105,99,111,100,101,68,101,99,111,100,101,69,114,114, + 111,114,40,9,0,0,0,117,4,0,0,0,115,101,108,102, + 117,8,0,0,0,102,117,108,108,110,97,109,101,117,8,0, + 0,0,116,111,107,101,110,105,122,101,117,4,0,0,0,112, + 97,116,104,117,12,0,0,0,115,111,117,114,99,101,95,98, + 121,116,101,115,117,3,0,0,0,101,120,99,117,10,0,0, + 0,114,101,97,100,115,111,117,114,99,101,117,8,0,0,0, + 101,110,99,111,100,105,110,103,117,15,0,0,0,110,101,119, + 108,105,110,101,95,100,101,99,111,100,101,114,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,10,0,0,0,103,101,116, + 95,115,111,117,114,99,101,164,3,0,0,115,38,0,0,0, + 0,2,12,1,15,1,3,1,19,1,18,1,9,1,31,1, + 18,1,3,1,19,1,18,1,9,1,31,1,18,1,3,1, + 30,1,18,1,9,1,117,23,0,0,0,83,111,117,114,99, + 101,76,111,97,100,101,114,46,103,101,116,95,115,111,117,114, + 99,101,99,3,0,0,0,0,0,0,0,3,0,0,0,7, + 0,0,0,67,0,0,0,115,25,0,0,0,116,0,0,116, + 1,0,124,1,0,124,2,0,100,1,0,100,2,0,100,3, + 0,131,4,1,83,40,4,0,0,0,117,130,0,0,0,82, + 101,116,117,114,110,32,116,104,101,32,99,111,100,101,32,111, + 98,106,101,99,116,32,99,111,109,112,105,108,101,100,32,102, + 114,111,109,32,115,111,117,114,99,101,46,10,10,32,32,32, + 32,32,32,32,32,84,104,101,32,39,100,97,116,97,39,32, + 97,114,103,117,109,101,110,116,32,99,97,110,32,98,101,32, + 97,110,121,32,111,98,106,101,99,116,32,116,121,112,101,32, + 116,104,97,116,32,99,111,109,112,105,108,101,40,41,32,115, + 117,112,112,111,114,116,115,46,10,32,32,32,32,32,32,32, + 32,117,4,0,0,0,101,120,101,99,117,12,0,0,0,100, + 111,110,116,95,105,110,104,101,114,105,116,84,40,2,0,0, + 0,117,25,0,0,0,95,99,97,108,108,95,119,105,116,104, + 95,102,114,97,109,101,115,95,114,101,109,111,118,101,100,117, + 7,0,0,0,99,111,109,112,105,108,101,40,3,0,0,0, + 117,4,0,0,0,115,101,108,102,117,4,0,0,0,100,97, + 116,97,117,4,0,0,0,112,97,116,104,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,14,0,0,0,115,111,117,114, + 99,101,95,116,111,95,99,111,100,101,186,3,0,0,115,4, + 0,0,0,0,5,18,1,117,27,0,0,0,83,111,117,114, + 99,101,76,111,97,100,101,114,46,115,111,117,114,99,101,95, + 116,111,95,99,111,100,101,99,2,0,0,0,0,0,0,0, + 10,0,0,0,45,0,0,0,67,0,0,0,115,231,1,0, + 0,124,0,0,106,0,0,124,1,0,131,1,0,125,2,0, + 100,1,0,125,3,0,121,16,0,116,1,0,124,2,0,131, + 1,0,125,4,0,87,110,24,0,4,116,2,0,107,10,0, + 114,63,0,1,1,1,100,1,0,125,4,0,89,110,202,0, + 88,121,19,0,124,0,0,106,3,0,124,2,0,131,1,0, + 125,5,0,87,110,18,0,4,116,2,0,107,10,0,114,103, + 0,1,1,1,89,110,162,0,88,116,4,0,124,5,0,100, + 2,0,25,131,1,0,125,3,0,121,19,0,124,0,0,106, + 5,0,124,4,0,131,1,0,125,6,0,87,110,18,0,4, + 116,6,0,107,10,0,114,159,0,1,1,1,89,110,106,0, + 88,121,34,0,116,7,0,124,6,0,100,3,0,124,5,0, + 100,4,0,124,1,0,100,5,0,124,4,0,131,1,3,125, + 7,0,87,110,24,0,4,116,8,0,116,9,0,102,2,0, + 107,10,0,114,220,0,1,1,1,89,110,45,0,88,116,10, + 0,100,6,0,124,4,0,124,2,0,131,3,0,1,116,11, + 0,124,7,0,100,4,0,124,1,0,100,7,0,124,4,0, + 100,8,0,124,2,0,131,1,3,83,124,0,0,106,5,0, + 124,2,0,131,1,0,125,8,0,124,0,0,106,12,0,124, + 8,0,124,2,0,131,2,0,125,9,0,116,10,0,100,9, + 0,124,2,0,131,2,0,1,116,13,0,106,14,0,12,114, + 227,1,124,4,0,100,1,0,107,9,0,114,227,1,124,3, + 0,100,1,0,107,9,0,114,227,1,116,15,0,116,16,0, + 131,1,0,125,6,0,124,6,0,106,17,0,116,18,0,124, + 3,0,131,1,0,131,1,0,1,124,6,0,106,17,0,116, + 18,0,116,19,0,124,8,0,131,1,0,131,1,0,131,1, + 0,1,124,6,0,106,17,0,116,20,0,106,21,0,124,9, + 0,131,1,0,131,1,0,1,121,36,0,124,0,0,106,22, + 0,124,2,0,124,4,0,124,6,0,131,3,0,1,116,10, + 0,100,10,0,124,4,0,131,2,0,1,87,113,227,1,4, + 116,2,0,107,10,0,114,223,1,1,1,1,89,113,227,1, + 88,110,0,0,124,9,0,83,40,11,0,0,0,117,190,0, + 0,0,67,111,110,99,114,101,116,101,32,105,109,112,108,101, + 109,101,110,116,97,116,105,111,110,32,111,102,32,73,110,115, + 112,101,99,116,76,111,97,100,101,114,46,103,101,116,95,99, + 111,100,101,46,10,10,32,32,32,32,32,32,32,32,82,101, + 97,100,105,110,103,32,111,102,32,98,121,116,101,99,111,100, + 101,32,114,101,113,117,105,114,101,115,32,112,97,116,104,95, + 115,116,97,116,115,32,116,111,32,98,101,32,105,109,112,108, + 101,109,101,110,116,101,100,46,32,84,111,32,119,114,105,116, + 101,10,32,32,32,32,32,32,32,32,98,121,116,101,99,111, + 100,101,44,32,115,101,116,95,100,97,116,97,32,109,117,115, + 116,32,97,108,115,111,32,98,101,32,105,109,112,108,101,109, + 101,110,116,101,100,46,10,10,32,32,32,32,32,32,32,32, + 78,117,5,0,0,0,109,116,105,109,101,117,12,0,0,0, + 115,111,117,114,99,101,95,115,116,97,116,115,117,4,0,0, + 0,110,97,109,101,117,4,0,0,0,112,97,116,104,117,13, + 0,0,0,123,125,32,109,97,116,99,104,101,115,32,123,125, + 117,13,0,0,0,98,121,116,101,99,111,100,101,95,112,97, + 116,104,117,11,0,0,0,115,111,117,114,99,101,95,112,97, + 116,104,117,19,0,0,0,99,111,100,101,32,111,98,106,101, + 99,116,32,102,114,111,109,32,123,125,117,10,0,0,0,119, + 114,111,116,101,32,123,33,114,125,40,23,0,0,0,117,12, + 0,0,0,103,101,116,95,102,105,108,101,110,97,109,101,117, + 17,0,0,0,99,97,99,104,101,95,102,114,111,109,95,115, + 111,117,114,99,101,117,19,0,0,0,78,111,116,73,109,112, + 108,101,109,101,110,116,101,100,69,114,114,111,114,117,10,0, + 0,0,112,97,116,104,95,115,116,97,116,115,117,3,0,0, + 0,105,110,116,117,8,0,0,0,103,101,116,95,100,97,116, + 97,117,7,0,0,0,79,83,69,114,114,111,114,117,25,0, + 0,0,95,118,97,108,105,100,97,116,101,95,98,121,116,101, + 99,111,100,101,95,104,101,97,100,101,114,117,11,0,0,0, + 73,109,112,111,114,116,69,114,114,111,114,117,8,0,0,0, + 69,79,70,69,114,114,111,114,117,16,0,0,0,95,118,101, + 114,98,111,115,101,95,109,101,115,115,97,103,101,117,17,0, + 0,0,95,99,111,109,112,105,108,101,95,98,121,116,101,99, + 111,100,101,117,14,0,0,0,115,111,117,114,99,101,95,116, + 111,95,99,111,100,101,117,3,0,0,0,115,121,115,117,19, + 0,0,0,100,111,110,116,95,119,114,105,116,101,95,98,121, + 116,101,99,111,100,101,117,9,0,0,0,98,121,116,101,97, + 114,114,97,121,117,12,0,0,0,95,77,65,71,73,67,95, + 66,89,84,69,83,117,6,0,0,0,101,120,116,101,110,100, + 117,7,0,0,0,95,119,95,108,111,110,103,117,3,0,0, + 0,108,101,110,117,7,0,0,0,109,97,114,115,104,97,108, + 117,5,0,0,0,100,117,109,112,115,117,15,0,0,0,95, + 99,97,99,104,101,95,98,121,116,101,99,111,100,101,40,10, + 0,0,0,117,4,0,0,0,115,101,108,102,117,8,0,0, + 0,102,117,108,108,110,97,109,101,117,11,0,0,0,115,111, + 117,114,99,101,95,112,97,116,104,117,12,0,0,0,115,111, + 117,114,99,101,95,109,116,105,109,101,117,13,0,0,0,98, + 121,116,101,99,111,100,101,95,112,97,116,104,117,2,0,0, + 0,115,116,117,4,0,0,0,100,97,116,97,117,10,0,0, + 0,98,121,116,101,115,95,100,97,116,97,117,12,0,0,0, + 115,111,117,114,99,101,95,98,121,116,101,115,117,11,0,0, + 0,99,111,100,101,95,111,98,106,101,99,116,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,8,0,0,0,103,101,116, + 95,99,111,100,101,194,3,0,0,115,82,0,0,0,0,7, + 15,1,6,1,3,1,16,1,13,1,11,2,3,1,19,1, + 13,1,5,2,16,1,3,1,19,1,13,1,5,2,3,1, + 9,1,12,1,13,1,19,1,5,2,9,1,7,1,15,1, + 6,1,7,1,15,1,18,1,13,1,22,1,12,1,12,1, + 19,1,25,1,22,1,3,1,19,1,17,1,13,1,8,1, + 117,21,0,0,0,83,111,117,114,99,101,76,111,97,100,101, + 114,46,103,101,116,95,99,111,100,101,99,2,0,0,0,0, + 0,0,0,2,0,0,0,2,0,0,0,67,0,0,0,115, + 13,0,0,0,124,0,0,106,0,0,124,1,0,131,1,0, + 83,40,1,0,0,0,117,0,1,0,0,67,111,110,99,114, + 101,116,101,32,105,109,112,108,101,109,101,110,116,97,116,105, + 111,110,32,111,102,32,76,111,97,100,101,114,46,108,111,97, + 100,95,109,111,100,117,108,101,46,10,10,32,32,32,32,32, + 32,32,32,82,101,113,117,105,114,101,115,32,69,120,101,99, + 117,116,105,111,110,76,111,97,100,101,114,46,103,101,116,95, + 102,105,108,101,110,97,109,101,32,97,110,100,32,82,101,115, + 111,117,114,99,101,76,111,97,100,101,114,46,103,101,116,95, + 100,97,116,97,32,116,111,32,98,101,10,32,32,32,32,32, + 32,32,32,105,109,112,108,101,109,101,110,116,101,100,32,116, + 111,32,108,111,97,100,32,115,111,117,114,99,101,32,99,111, + 100,101,46,32,85,115,101,32,111,102,32,98,121,116,101,99, + 111,100,101,32,105,115,32,100,105,99,116,97,116,101,100,32, + 98,121,32,119,104,101,116,104,101,114,10,32,32,32,32,32, + 32,32,32,103,101,116,95,99,111,100,101,32,117,115,101,115, + 47,119,114,105,116,101,115,32,98,121,116,101,99,111,100,101, + 46,10,10,32,32,32,32,32,32,32,32,40,1,0,0,0, + 117,12,0,0,0,95,108,111,97,100,95,109,111,100,117,108, + 101,40,2,0,0,0,117,4,0,0,0,115,101,108,102,117, + 8,0,0,0,102,117,108,108,110,97,109,101,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,11,0,0,0,108,111,97, + 100,95,109,111,100,117,108,101,247,3,0,0,115,2,0,0, + 0,0,8,117,24,0,0,0,83,111,117,114,99,101,76,111, + 97,100,101,114,46,108,111,97,100,95,109,111,100,117,108,101, + 78,40,11,0,0,0,117,8,0,0,0,95,95,110,97,109, + 101,95,95,117,10,0,0,0,95,95,109,111,100,117,108,101, + 95,95,117,12,0,0,0,95,95,113,117,97,108,110,97,109, + 101,95,95,117,10,0,0,0,112,97,116,104,95,109,116,105, + 109,101,117,10,0,0,0,112,97,116,104,95,115,116,97,116, + 115,117,15,0,0,0,95,99,97,99,104,101,95,98,121,116, + 101,99,111,100,101,117,8,0,0,0,115,101,116,95,100,97, + 116,97,117,10,0,0,0,103,101,116,95,115,111,117,114,99, + 101,117,14,0,0,0,115,111,117,114,99,101,95,116,111,95, + 99,111,100,101,117,8,0,0,0,103,101,116,95,99,111,100, + 101,117,11,0,0,0,108,111,97,100,95,109,111,100,117,108, + 101,40,1,0,0,0,117,10,0,0,0,95,95,108,111,99, + 97,108,115,95,95,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,12,0,0,0,83,111,117,114,99,101,76,111,97,100, + 101,114,125,3,0,0,115,16,0,0,0,16,2,12,6,12, + 12,12,10,12,9,12,22,12,8,12,53,117,12,0,0,0, + 83,111,117,114,99,101,76,111,97,100,101,114,99,1,0,0, + 0,0,0,0,0,1,0,0,0,4,0,0,0,2,0,0, + 0,115,92,0,0,0,124,0,0,69,101,0,0,90,1,0, + 100,0,0,90,2,0,100,1,0,90,3,0,100,2,0,100, + 3,0,132,0,0,90,4,0,101,5,0,135,0,0,102,1, + 0,100,4,0,100,5,0,134,0,0,131,1,0,90,6,0, + 101,5,0,100,6,0,100,7,0,132,0,0,131,1,0,90, + 7,0,100,8,0,100,9,0,132,0,0,90,8,0,135,0, + 0,83,40,10,0,0,0,117,10,0,0,0,70,105,108,101, + 76,111,97,100,101,114,117,103,0,0,0,66,97,115,101,32, + 102,105,108,101,32,108,111,97,100,101,114,32,99,108,97,115, + 115,32,119,104,105,99,104,32,105,109,112,108,101,109,101,110, + 116,115,32,116,104,101,32,108,111,97,100,101,114,32,112,114, + 111,116,111,99,111,108,32,109,101,116,104,111,100,115,32,116, + 104,97,116,10,32,32,32,32,114,101,113,117,105,114,101,32, + 102,105,108,101,32,115,121,115,116,101,109,32,117,115,97,103, + 101,46,99,3,0,0,0,0,0,0,0,3,0,0,0,2, + 0,0,0,67,0,0,0,115,22,0,0,0,124,1,0,124, + 0,0,95,0,0,124,2,0,124,0,0,95,1,0,100,1, + 0,83,40,2,0,0,0,117,75,0,0,0,67,97,99,104, + 101,32,116,104,101,32,109,111,100,117,108,101,32,110,97,109, + 101,32,97,110,100,32,116,104,101,32,112,97,116,104,32,116, + 111,32,116,104,101,32,102,105,108,101,32,102,111,117,110,100, + 32,98,121,32,116,104,101,10,32,32,32,32,32,32,32,32, + 102,105,110,100,101,114,46,78,40,2,0,0,0,117,4,0, + 0,0,110,97,109,101,117,4,0,0,0,112,97,116,104,40, + 3,0,0,0,117,4,0,0,0,115,101,108,102,117,8,0, + 0,0,102,117,108,108,110,97,109,101,117,4,0,0,0,112, + 97,116,104,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 8,0,0,0,95,95,105,110,105,116,95,95,7,4,0,0, + 115,4,0,0,0,0,3,9,1,117,19,0,0,0,70,105, + 108,101,76,111,97,100,101,114,46,95,95,105,110,105,116,95, + 95,99,2,0,0,0,0,0,0,0,2,0,0,0,3,0, + 0,0,3,0,0,0,115,22,0,0,0,116,0,0,116,1, + 0,124,0,0,131,2,0,106,2,0,124,1,0,131,1,0, + 83,40,1,0,0,0,117,26,0,0,0,76,111,97,100,32, + 97,32,109,111,100,117,108,101,32,102,114,111,109,32,97,32, + 102,105,108,101,46,40,3,0,0,0,117,5,0,0,0,115, + 117,112,101,114,117,10,0,0,0,70,105,108,101,76,111,97, + 100,101,114,117,11,0,0,0,108,111,97,100,95,109,111,100, + 117,108,101,40,2,0,0,0,117,4,0,0,0,115,101,108, + 102,117,8,0,0,0,102,117,108,108,110,97,109,101,40,1, + 0,0,0,117,9,0,0,0,95,95,99,108,97,115,115,95, + 95,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,11,0,0,0,108,111,97, + 100,95,109,111,100,117,108,101,13,4,0,0,115,2,0,0, + 0,0,5,117,22,0,0,0,70,105,108,101,76,111,97,100, + 101,114,46,108,111,97,100,95,109,111,100,117,108,101,99,2, 0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,67, - 0,0,0,115,4,0,0,0,100,1,0,83,40,2,0,0, - 0,117,56,0,0,0,82,101,116,117,114,110,32,78,111,110, - 101,32,97,115,32,98,117,105,108,116,45,105,110,32,109,111, - 100,117,108,101,115,32,100,111,32,110,111,116,32,104,97,118, - 101,32,115,111,117,114,99,101,32,99,111,100,101,46,78,114, - 4,0,0,0,40,2,0,0,0,114,215,0,0,0,114,178, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,244,10,0,0,0,103,101,116,95,115,111,117,114,99, - 101,9,3,0,0,115,2,0,0,0,0,4,117,26,0,0, - 0,66,117,105,108,116,105,110,73,109,112,111,114,116,101,114, - 46,103,101,116,95,115,111,117,114,99,101,99,2,0,0,0, - 0,0,0,0,2,0,0,0,1,0,0,0,67,0,0,0, - 115,4,0,0,0,100,1,0,83,40,2,0,0,0,117,52, - 0,0,0,82,101,116,117,114,110,32,70,97,108,115,101,32, - 97,115,32,98,117,105,108,116,45,105,110,32,109,111,100,117, - 108,101,115,32,97,114,101,32,110,101,118,101,114,32,112,97, - 99,107,97,103,101,115,46,70,114,4,0,0,0,40,2,0, - 0,0,114,215,0,0,0,114,178,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,114,156,0,0,0, - 15,3,0,0,115,2,0,0,0,0,4,117,26,0,0,0, - 66,117,105,108,116,105,110,73,109,112,111,114,116,101,114,46, - 105,115,95,112,97,99,107,97,103,101,40,14,0,0,0,114, - 56,0,0,0,114,55,0,0,0,114,57,0,0,0,114,58, - 0,0,0,244,11,0,0,0,99,108,97,115,115,109,101,116, - 104,111,100,114,216,0,0,0,114,217,0,0,0,114,170,0, - 0,0,114,173,0,0,0,114,180,0,0,0,114,218,0,0, - 0,114,219,0,0,0,114,220,0,0,0,114,156,0,0,0, - 114,4,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,214,0,0,0,226,2,0,0,115,28,0, - 0,0,12,7,6,2,18,4,3,1,18,10,3,1,3,1, - 3,1,27,6,3,1,21,5,3,1,21,5,3,1,114,214, - 0,0,0,99,0,0,0,0,0,0,0,0,0,0,0,0, - 6,0,0,0,64,0,0,0,115,169,0,0,0,101,0,0, - 90,1,0,100,0,0,90,2,0,100,1,0,90,3,0,101, - 4,0,100,2,0,100,3,0,132,0,0,131,1,0,90,5, - 0,101,4,0,100,4,0,100,5,0,100,6,0,132,1,0, - 131,1,0,90,6,0,101,4,0,101,7,0,101,8,0,101, - 9,0,100,7,0,100,8,0,132,0,0,131,1,0,131,1, - 0,131,1,0,131,1,0,90,10,0,101,4,0,101,9,0, - 100,9,0,100,10,0,132,0,0,131,1,0,131,1,0,90, - 11,0,101,4,0,101,9,0,100,11,0,100,12,0,132,0, - 0,131,1,0,131,1,0,90,12,0,101,4,0,101,9,0, - 100,13,0,100,14,0,132,0,0,131,1,0,131,1,0,90, - 13,0,100,4,0,83,40,15,0,0,0,244,14,0,0,0, - 70,114,111,122,101,110,73,109,112,111,114,116,101,114,117,142, - 0,0,0,77,101,116,97,32,112,97,116,104,32,105,109,112, - 111,114,116,32,102,111,114,32,102,114,111,122,101,110,32,109, - 111,100,117,108,101,115,46,10,10,32,32,32,32,65,108,108, - 32,109,101,116,104,111,100,115,32,97,114,101,32,101,105,116, - 104,101,114,32,99,108,97,115,115,32,111,114,32,115,116,97, - 116,105,99,32,109,101,116,104,111,100,115,32,116,111,32,97, - 118,111,105,100,32,116,104,101,32,110,101,101,100,32,116,111, - 10,32,32,32,32,105,110,115,116,97,110,116,105,97,116,101, - 32,116,104,101,32,99,108,97,115,115,46,10,10,32,32,32, - 32,99,2,0,0,0,0,0,0,0,2,0,0,0,2,0, - 0,0,67,0,0,0,115,16,0,0,0,100,1,0,106,0, - 0,124,1,0,106,1,0,131,1,0,83,40,2,0,0,0, - 78,117,22,0,0,0,60,109,111,100,117,108,101,32,123,33, - 114,125,32,40,102,114,111,122,101,110,41,62,40,2,0,0, - 0,114,46,0,0,0,114,56,0,0,0,40,2,0,0,0, - 114,215,0,0,0,244,1,0,0,0,109,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,216,0,0,0,31, - 3,0,0,115,2,0,0,0,0,2,117,26,0,0,0,70, - 114,111,122,101,110,73,109,112,111,114,116,101,114,46,109,111, - 100,117,108,101,95,114,101,112,114,78,99,3,0,0,0,0, - 0,0,0,3,0,0,0,2,0,0,0,67,0,0,0,115, - 23,0,0,0,116,0,0,106,1,0,124,1,0,131,1,0, - 114,19,0,124,0,0,83,100,1,0,83,40,2,0,0,0, - 117,21,0,0,0,70,105,110,100,32,97,32,102,114,111,122, - 101,110,32,109,111,100,117,108,101,46,78,40,2,0,0,0, - 114,94,0,0,0,114,181,0,0,0,40,3,0,0,0,114, - 215,0,0,0,114,178,0,0,0,114,35,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,114,217,0, - 0,0,35,3,0,0,115,2,0,0,0,0,3,117,26,0, - 0,0,70,114,111,122,101,110,73,109,112,111,114,116,101,114, - 46,102,105,110,100,95,109,111,100,117,108,101,99,2,0,0, - 0,0,0,0,0,3,0,0,0,10,0,0,0,67,0,0, - 0,115,51,0,0,0,116,0,0,124,1,0,131,1,0,143, - 33,0,1,116,1,0,116,2,0,106,3,0,124,1,0,131, - 2,0,125,2,0,124,2,0,96,4,0,124,2,0,83,87, - 100,1,0,81,88,100,1,0,83,40,2,0,0,0,117,21, - 0,0,0,76,111,97,100,32,97,32,102,114,111,122,101,110, - 32,109,111,100,117,108,101,46,78,40,5,0,0,0,114,138, - 0,0,0,114,99,0,0,0,114,94,0,0,0,116,11,0, - 0,0,105,110,105,116,95,102,114,111,122,101,110,114,164,0, - 0,0,40,3,0,0,0,114,215,0,0,0,114,178,0,0, - 0,114,223,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,218,0,0,0,40,3,0,0,115,8, - 0,0,0,0,6,13,1,18,2,6,1,117,26,0,0,0, - 70,114,111,122,101,110,73,109,112,111,114,116,101,114,46,108, - 111,97,100,95,109,111,100,117,108,101,99,2,0,0,0,0, - 0,0,0,2,0,0,0,2,0,0,0,67,0,0,0,115, - 13,0,0,0,116,0,0,106,1,0,124,1,0,131,1,0, - 83,40,1,0,0,0,117,45,0,0,0,82,101,116,117,114, - 110,32,116,104,101,32,99,111,100,101,32,111,98,106,101,99, - 116,32,102,111,114,32,116,104,101,32,102,114,111,122,101,110, - 32,109,111,100,117,108,101,46,40,2,0,0,0,114,94,0, - 0,0,116,17,0,0,0,103,101,116,95,102,114,111,122,101, - 110,95,111,98,106,101,99,116,40,2,0,0,0,114,215,0, - 0,0,114,178,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,5,0,0,0,114,219,0,0,0,52,3,0,0,115, - 2,0,0,0,0,4,117,23,0,0,0,70,114,111,122,101, - 110,73,109,112,111,114,116,101,114,46,103,101,116,95,99,111, - 100,101,99,2,0,0,0,0,0,0,0,2,0,0,0,1, - 0,0,0,67,0,0,0,115,4,0,0,0,100,1,0,83, - 40,2,0,0,0,117,54,0,0,0,82,101,116,117,114,110, - 32,78,111,110,101,32,97,115,32,102,114,111,122,101,110,32, - 109,111,100,117,108,101,115,32,100,111,32,110,111,116,32,104, - 97,118,101,32,115,111,117,114,99,101,32,99,111,100,101,46, - 78,114,4,0,0,0,40,2,0,0,0,114,215,0,0,0, - 114,178,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,220,0,0,0,58,3,0,0,115,2,0, - 0,0,0,4,117,25,0,0,0,70,114,111,122,101,110,73, - 109,112,111,114,116,101,114,46,103,101,116,95,115,111,117,114, - 99,101,99,2,0,0,0,0,0,0,0,2,0,0,0,2, - 0,0,0,67,0,0,0,115,13,0,0,0,116,0,0,106, - 1,0,124,1,0,131,1,0,83,40,1,0,0,0,117,46, - 0,0,0,82,101,116,117,114,110,32,84,114,117,101,32,105, - 102,32,116,104,101,32,102,114,111,122,101,110,32,109,111,100, - 117,108,101,32,105,115,32,97,32,112,97,99,107,97,103,101, - 46,40,2,0,0,0,114,94,0,0,0,116,17,0,0,0, - 105,115,95,102,114,111,122,101,110,95,112,97,99,107,97,103, - 101,40,2,0,0,0,114,215,0,0,0,114,178,0,0,0, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,114, - 156,0,0,0,64,3,0,0,115,2,0,0,0,0,4,117, - 25,0,0,0,70,114,111,122,101,110,73,109,112,111,114,116, - 101,114,46,105,115,95,112,97,99,107,97,103,101,40,14,0, - 0,0,114,56,0,0,0,114,55,0,0,0,114,57,0,0, - 0,114,58,0,0,0,114,221,0,0,0,114,216,0,0,0, - 114,217,0,0,0,114,170,0,0,0,114,173,0,0,0,114, - 183,0,0,0,114,218,0,0,0,114,219,0,0,0,114,220, - 0,0,0,114,156,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,114,222,0,0, - 0,22,3,0,0,115,28,0,0,0,12,7,6,2,18,4, - 3,1,18,4,3,1,3,1,3,1,27,9,3,1,21,5, - 3,1,21,5,3,1,114,222,0,0,0,99,0,0,0,0, - 0,0,0,0,0,0,0,0,4,0,0,0,64,0,0,0, - 115,97,0,0,0,101,0,0,90,1,0,100,0,0,90,2, - 0,100,1,0,90,3,0,100,2,0,90,4,0,100,3,0, - 90,5,0,100,4,0,90,6,0,101,7,0,100,5,0,100, - 6,0,132,0,0,131,1,0,90,8,0,101,7,0,100,7, - 0,100,8,0,132,0,0,131,1,0,90,9,0,101,7,0, - 100,9,0,100,10,0,100,11,0,132,1,0,131,1,0,90, - 10,0,100,9,0,83,40,12,0,0,0,244,21,0,0,0, - 87,105,110,100,111,119,115,82,101,103,105,115,116,114,121,70, - 105,110,100,101,114,117,67,0,0,0,77,101,116,97,32,112, - 97,116,104,32,102,105,110,100,101,114,32,102,111,114,32,109, - 111,100,117,108,101,115,32,100,101,99,108,97,114,101,100,32, - 105,110,32,116,104,101,32,87,105,110,100,111,119,115,32,114, - 101,103,105,115,116,114,121,46,10,32,32,32,32,117,59,0, - 0,0,83,111,102,116,119,97,114,101,92,80,121,116,104,111, - 110,92,80,121,116,104,111,110,67,111,114,101,92,123,115,121, - 115,95,118,101,114,115,105,111,110,125,92,77,111,100,117,108, - 101,115,92,123,102,117,108,108,110,97,109,101,125,117,65,0, - 0,0,83,111,102,116,119,97,114,101,92,80,121,116,104,111, - 110,92,80,121,116,104,111,110,67,111,114,101,92,123,115,121, - 115,95,118,101,114,115,105,111,110,125,92,77,111,100,117,108, - 101,115,92,123,102,117,108,108,110,97,109,101,125,92,68,101, - 98,117,103,70,99,2,0,0,0,0,0,0,0,2,0,0, - 0,11,0,0,0,67,0,0,0,115,67,0,0,0,121,23, - 0,116,0,0,106,1,0,116,0,0,106,2,0,124,1,0, - 131,2,0,83,87,110,37,0,4,116,3,0,107,10,0,114, - 62,0,1,1,1,116,0,0,106,1,0,116,0,0,106,4, - 0,124,1,0,131,2,0,83,89,110,1,0,88,100,0,0, - 83,40,1,0,0,0,78,40,5,0,0,0,244,7,0,0, - 0,95,119,105,110,114,101,103,116,7,0,0,0,79,112,101, - 110,75,101,121,116,17,0,0,0,72,75,69,89,95,67,85, - 82,82,69,78,84,95,85,83,69,82,114,40,0,0,0,116, - 18,0,0,0,72,75,69,89,95,76,79,67,65,76,95,77, - 65,67,72,73,78,69,40,2,0,0,0,114,215,0,0,0, - 244,3,0,0,0,107,101,121,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,244,14,0,0,0,95,111,112,101, - 110,95,114,101,103,105,115,116,114,121,84,3,0,0,115,8, - 0,0,0,0,2,3,1,23,1,13,1,117,36,0,0,0, - 87,105,110,100,111,119,115,82,101,103,105,115,116,114,121,70, - 105,110,100,101,114,46,95,111,112,101,110,95,114,101,103,105, - 115,116,114,121,99,2,0,0,0,0,0,0,0,6,0,0, - 0,16,0,0,0,67,0,0,0,115,142,0,0,0,124,0, - 0,106,0,0,114,21,0,124,0,0,106,1,0,125,2,0, - 110,9,0,124,0,0,106,2,0,125,2,0,124,2,0,106, - 3,0,100,1,0,124,1,0,100,2,0,116,4,0,106,5, - 0,100,0,0,100,3,0,133,2,0,25,131,0,2,125,3, - 0,121,46,0,124,0,0,106,6,0,124,3,0,131,1,0, - 143,25,0,125,4,0,116,7,0,106,8,0,124,4,0,100, - 4,0,131,2,0,125,5,0,87,100,0,0,81,88,87,110, - 22,0,4,116,9,0,107,10,0,114,137,0,1,1,1,100, - 0,0,83,89,110,1,0,88,124,5,0,83,40,5,0,0, - 0,78,114,178,0,0,0,116,11,0,0,0,115,121,115,95, - 118,101,114,115,105,111,110,114,121,0,0,0,114,30,0,0, - 0,40,10,0,0,0,244,11,0,0,0,68,69,66,85,71, - 95,66,85,73,76,68,244,18,0,0,0,82,69,71,73,83, - 84,82,89,95,75,69,89,95,68,69,66,85,71,244,12,0, - 0,0,82,69,71,73,83,84,82,89,95,75,69,89,114,46, - 0,0,0,114,7,0,0,0,244,7,0,0,0,118,101,114, - 115,105,111,110,114,227,0,0,0,114,225,0,0,0,116,10, - 0,0,0,81,117,101,114,121,86,97,108,117,101,114,40,0, - 0,0,40,6,0,0,0,114,215,0,0,0,114,178,0,0, - 0,116,12,0,0,0,114,101,103,105,115,116,114,121,95,107, - 101,121,114,226,0,0,0,116,4,0,0,0,104,107,101,121, - 244,8,0,0,0,102,105,108,101,112,97,116,104,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,244,16,0,0, - 0,95,115,101,97,114,99,104,95,114,101,103,105,115,116,114, - 121,91,3,0,0,115,22,0,0,0,0,2,9,1,12,2, - 9,1,15,1,22,1,3,1,18,1,28,1,13,1,9,1, - 117,38,0,0,0,87,105,110,100,111,119,115,82,101,103,105, - 115,116,114,121,70,105,110,100,101,114,46,95,115,101,97,114, - 99,104,95,114,101,103,105,115,116,114,121,78,99,3,0,0, - 0,0,0,0,0,7,0,0,0,12,0,0,0,67,0,0, - 0,115,140,0,0,0,124,0,0,106,0,0,124,1,0,131, - 1,0,125,3,0,124,3,0,100,1,0,107,8,0,114,31, - 0,100,1,0,83,121,17,0,116,1,0,106,2,0,124,3, - 0,131,1,0,1,87,110,22,0,4,116,3,0,107,10,0, - 114,72,0,1,1,1,100,1,0,83,89,110,1,0,88,120, - 60,0,116,4,0,131,0,0,68,93,49,0,92,3,0,125, - 4,0,125,5,0,125,6,0,124,3,0,106,5,0,116,6, - 0,124,5,0,131,1,0,131,1,0,114,83,0,124,4,0, - 124,1,0,124,3,0,131,2,0,83,113,83,0,87,100,1, - 0,83,40,2,0,0,0,117,34,0,0,0,70,105,110,100, - 32,109,111,100,117,108,101,32,110,97,109,101,100,32,105,110, - 32,116,104,101,32,114,101,103,105,115,116,114,121,46,78,40, - 7,0,0,0,114,233,0,0,0,114,3,0,0,0,114,39, - 0,0,0,114,40,0,0,0,244,27,0,0,0,95,103,101, - 116,95,115,117,112,112,111,114,116,101,100,95,102,105,108,101, - 95,108,111,97,100,101,114,115,244,8,0,0,0,101,110,100, - 115,119,105,116,104,244,5,0,0,0,116,117,112,108,101,40, - 7,0,0,0,114,215,0,0,0,114,178,0,0,0,114,35, - 0,0,0,114,232,0,0,0,114,160,0,0,0,114,112,0, - 0,0,114,36,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,5,0,0,0,114,217,0,0,0,106,3,0,0,115, - 20,0,0,0,0,3,15,1,12,1,4,1,3,1,17,1, - 13,1,9,1,25,1,21,1,117,33,0,0,0,87,105,110, - 100,111,119,115,82,101,103,105,115,116,114,121,70,105,110,100, - 101,114,46,102,105,110,100,95,109,111,100,117,108,101,40,11, - 0,0,0,114,56,0,0,0,114,55,0,0,0,114,57,0, - 0,0,114,58,0,0,0,114,230,0,0,0,114,229,0,0, - 0,114,228,0,0,0,114,221,0,0,0,114,227,0,0,0, - 114,233,0,0,0,114,217,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,114,224, - 0,0,0,71,3,0,0,115,16,0,0,0,12,3,6,3, - 6,3,6,2,6,2,18,7,18,15,3,1,114,224,0,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,2,0, - 0,0,64,0,0,0,115,58,0,0,0,101,0,0,90,1, - 0,100,0,0,90,2,0,100,1,0,90,3,0,100,2,0, - 100,3,0,132,0,0,90,4,0,100,4,0,100,5,0,132, - 0,0,90,5,0,100,6,0,100,7,0,132,0,0,90,6, - 0,100,8,0,83,40,9,0,0,0,244,13,0,0,0,95, - 76,111,97,100,101,114,66,97,115,105,99,115,117,83,0,0, - 0,66,97,115,101,32,99,108,97,115,115,32,111,102,32,99, - 111,109,109,111,110,32,99,111,100,101,32,110,101,101,100,101, - 100,32,98,121,32,98,111,116,104,32,83,111,117,114,99,101, - 76,111,97,100,101,114,32,97,110,100,10,32,32,32,32,83, - 111,117,114,99,101,108,101,115,115,70,105,108,101,76,111,97, - 100,101,114,46,99,2,0,0,0,0,0,0,0,5,0,0, - 0,3,0,0,0,67,0,0,0,115,88,0,0,0,116,0, - 0,124,0,0,106,1,0,124,1,0,131,1,0,131,1,0, - 100,1,0,25,125,2,0,124,2,0,106,2,0,100,2,0, - 100,1,0,131,2,0,100,3,0,25,125,3,0,124,1,0, - 106,3,0,100,2,0,131,1,0,100,4,0,25,125,4,0, - 124,3,0,100,5,0,107,2,0,111,87,0,124,4,0,100, - 5,0,107,3,0,83,40,6,0,0,0,117,141,0,0,0, - 67,111,110,99,114,101,116,101,32,105,109,112,108,101,109,101, - 110,116,97,116,105,111,110,32,111,102,32,73,110,115,112,101, - 99,116,76,111,97,100,101,114,46,105,115,95,112,97,99,107, - 97,103,101,32,98,121,32,99,104,101,99,107,105,110,103,32, - 105,102,10,32,32,32,32,32,32,32,32,116,104,101,32,112, - 97,116,104,32,114,101,116,117,114,110,101,100,32,98,121,32, - 103,101,116,95,102,105,108,101,110,97,109,101,32,104,97,115, - 32,97,32,102,105,108,101,110,97,109,101,32,111,102,32,39, - 95,95,105,110,105,116,95,95,46,112,121,39,46,114,29,0, - 0,0,114,101,0,0,0,114,67,0,0,0,114,100,0,0, - 0,114,76,0,0,0,40,4,0,0,0,114,38,0,0,0, - 114,163,0,0,0,114,34,0,0,0,114,32,0,0,0,40, - 5,0,0,0,114,75,0,0,0,114,178,0,0,0,114,116, - 0,0,0,116,13,0,0,0,102,105,108,101,110,97,109,101, - 95,98,97,115,101,116,9,0,0,0,116,97,105,108,95,110, - 97,109,101,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,156,0,0,0,126,3,0,0,115,8,0,0,0, - 0,3,25,1,22,1,19,1,117,24,0,0,0,95,76,111, - 97,100,101,114,66,97,115,105,99,115,46,105,115,95,112,97, - 99,107,97,103,101,99,2,0,0,0,0,0,0,0,2,0, - 0,0,11,0,0,0,67,0,0,0,115,100,0,0,0,124, - 0,0,124,1,0,95,0,0,116,1,0,124,0,0,124,1, - 0,131,2,0,1,116,2,0,124,0,0,124,1,0,131,2, - 0,1,116,3,0,124,1,0,100,1,0,131,2,0,114,96, - 0,121,22,0,116,4,0,124,1,0,106,5,0,131,1,0, - 124,1,0,95,6,0,87,113,96,0,4,116,7,0,107,10, - 0,114,92,0,1,1,1,89,113,96,0,88,110,0,0,100, - 2,0,83,40,3,0,0,0,117,2,1,0,0,83,101,116, - 32,118,97,114,105,111,117,115,32,97,116,116,114,105,98,117, - 116,101,115,32,111,110,32,116,104,101,32,109,111,100,117,108, - 101,46,10,10,32,32,32,32,32,32,32,32,69,120,101,99, - 117,116,105,111,110,76,111,97,100,101,114,46,105,110,105,116, - 95,109,111,100,117,108,101,95,97,116,116,114,115,40,41,32, - 105,115,32,117,115,101,100,32,116,111,32,115,101,116,32,95, - 95,108,111,97,100,101,114,95,95,44,10,32,32,32,32,32, - 32,32,32,95,95,112,97,99,107,97,103,101,95,95,44,32, - 95,95,102,105,108,101,95,95,44,32,97,110,100,32,111,112, - 116,105,111,110,97,108,108,121,32,95,95,112,97,116,104,95, - 95,46,32,84,104,101,32,95,95,99,97,99,104,101,100,95, - 95,32,97,116,116,114,105,98,117,116,101,10,32,32,32,32, - 32,32,32,32,105,115,32,115,101,116,32,117,115,105,110,103, - 32,105,109,112,46,99,97,99,104,101,95,102,114,111,109,95, - 115,111,117,114,99,101,40,41,32,97,110,100,32,95,95,102, - 105,108,101,95,95,46,10,32,32,32,32,32,32,32,32,114, - 164,0,0,0,78,40,8,0,0,0,114,171,0,0,0,114, - 162,0,0,0,114,166,0,0,0,114,59,0,0,0,114,117, - 0,0,0,114,164,0,0,0,244,10,0,0,0,95,95,99, - 97,99,104,101,100,95,95,114,109,0,0,0,40,2,0,0, - 0,114,75,0,0,0,114,161,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,244,17,0,0,0,105, - 110,105,116,95,109,111,100,117,108,101,95,97,116,116,114,115, - 134,3,0,0,115,16,0,0,0,0,7,9,1,13,1,13, - 1,15,1,3,1,22,1,13,1,117,31,0,0,0,95,76, - 111,97,100,101,114,66,97,115,105,99,115,46,105,110,105,116, - 95,109,111,100,117,108,101,95,97,116,116,114,115,99,2,0, - 0,0,0,0,0,0,4,0,0,0,11,0,0,0,67,0, - 0,0,115,112,0,0,0,116,0,0,124,1,0,131,1,0, - 143,94,0,125,2,0,124,0,0,106,1,0,124,2,0,131, - 1,0,1,124,0,0,106,2,0,124,1,0,131,1,0,125, - 3,0,124,3,0,100,1,0,107,8,0,114,79,0,116,3, - 0,100,2,0,106,4,0,124,1,0,131,1,0,131,1,0, - 130,1,0,110,0,0,116,5,0,116,6,0,124,3,0,124, - 2,0,106,7,0,131,3,0,1,124,2,0,83,87,100,1, - 0,81,88,100,1,0,83,40,3,0,0,0,117,57,0,0, - 0,76,111,97,100,32,116,104,101,32,115,112,101,99,105,102, - 105,101,100,32,109,111,100,117,108,101,32,105,110,116,111,32, - 115,121,115,46,109,111,100,117,108,101,115,32,97,110,100,32, - 114,101,116,117,114,110,32,105,116,46,78,117,52,0,0,0, - 99,97,110,110,111,116,32,108,111,97,100,32,109,111,100,117, - 108,101,32,123,33,114,125,32,119,104,101,110,32,103,101,116, - 95,99,111,100,101,40,41,32,114,101,116,117,114,110,115,32, - 78,111,110,101,40,8,0,0,0,114,155,0,0,0,114,239, - 0,0,0,114,219,0,0,0,114,157,0,0,0,114,46,0, - 0,0,114,99,0,0,0,244,4,0,0,0,101,120,101,99, - 114,62,0,0,0,40,4,0,0,0,114,75,0,0,0,114, - 178,0,0,0,114,161,0,0,0,114,204,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,114,218,0, - 0,0,150,3,0,0,115,16,0,0,0,0,2,15,1,13, - 1,15,1,12,1,3,1,21,1,19,1,117,25,0,0,0, - 95,76,111,97,100,101,114,66,97,115,105,99,115,46,108,111, - 97,100,95,109,111,100,117,108,101,78,40,7,0,0,0,114, - 56,0,0,0,114,55,0,0,0,114,57,0,0,0,114,58, - 0,0,0,114,156,0,0,0,114,239,0,0,0,114,218,0, - 0,0,114,4,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,5,0,0,0,114,237,0,0,0,121,3,0,0,115, - 8,0,0,0,12,3,6,2,12,8,12,16,114,237,0,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,4,0, - 0,0,64,0,0,0,115,106,0,0,0,101,0,0,90,1, - 0,100,0,0,90,2,0,100,1,0,100,2,0,132,0,0, - 90,3,0,100,3,0,100,4,0,132,0,0,90,4,0,100, - 5,0,100,6,0,132,0,0,90,5,0,100,7,0,100,8, - 0,132,0,0,90,6,0,100,9,0,100,10,0,132,0,0, - 90,7,0,100,11,0,100,18,0,100,13,0,100,14,0,132, - 0,1,90,8,0,100,15,0,100,16,0,132,0,0,90,9, - 0,100,17,0,83,40,19,0,0,0,244,12,0,0,0,83, - 111,117,114,99,101,76,111,97,100,101,114,99,2,0,0,0, - 0,0,0,0,2,0,0,0,1,0,0,0,67,0,0,0, - 115,10,0,0,0,116,0,0,130,1,0,100,1,0,83,40, - 2,0,0,0,117,178,0,0,0,79,112,116,105,111,110,97, - 108,32,109,101,116,104,111,100,32,116,104,97,116,32,114,101, - 116,117,114,110,115,32,116,104,101,32,109,111,100,105,102,105, - 99,97,116,105,111,110,32,116,105,109,101,32,40,97,110,32, - 105,110,116,41,32,102,111,114,32,116,104,101,10,32,32,32, - 32,32,32,32,32,115,112,101,99,105,102,105,101,100,32,112, - 97,116,104,44,32,119,104,101,114,101,32,112,97,116,104,32, - 105,115,32,97,32,115,116,114,46,10,10,32,32,32,32,32, - 32,32,32,82,97,105,115,101,115,32,73,79,69,114,114,111, - 114,32,119,104,101,110,32,116,104,101,32,112,97,116,104,32, - 99,97,110,110,111,116,32,98,101,32,104,97,110,100,108,101, - 100,46,10,32,32,32,32,32,32,32,32,78,40,1,0,0, - 0,244,7,0,0,0,73,79,69,114,114,111,114,40,2,0, - 0,0,114,75,0,0,0,114,35,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,244,10,0,0,0, - 112,97,116,104,95,109,116,105,109,101,164,3,0,0,115,2, - 0,0,0,0,6,117,23,0,0,0,83,111,117,114,99,101, - 76,111,97,100,101,114,46,112,97,116,104,95,109,116,105,109, - 101,99,2,0,0,0,0,0,0,0,2,0,0,0,3,0, - 0,0,67,0,0,0,115,20,0,0,0,105,1,0,124,0, - 0,106,0,0,124,1,0,131,1,0,100,1,0,54,83,40, - 2,0,0,0,117,170,1,0,0,79,112,116,105,111,110,97, - 108,32,109,101,116,104,111,100,32,114,101,116,117,114,110,105, - 110,103,32,97,32,109,101,116,97,100,97,116,97,32,100,105, - 99,116,32,102,111,114,32,116,104,101,32,115,112,101,99,105, - 102,105,101,100,32,112,97,116,104,10,32,32,32,32,32,32, - 32,32,116,111,32,98,121,32,116,104,101,32,112,97,116,104, - 32,40,115,116,114,41,46,10,32,32,32,32,32,32,32,32, - 80,111,115,115,105,98,108,101,32,107,101,121,115,58,10,32, - 32,32,32,32,32,32,32,45,32,39,109,116,105,109,101,39, - 32,40,109,97,110,100,97,116,111,114,121,41,32,105,115,32, - 116,104,101,32,110,117,109,101,114,105,99,32,116,105,109,101, - 115,116,97,109,112,32,111,102,32,108,97,115,116,32,115,111, - 117,114,99,101,10,32,32,32,32,32,32,32,32,32,32,99, - 111,100,101,32,109,111,100,105,102,105,99,97,116,105,111,110, - 59,10,32,32,32,32,32,32,32,32,45,32,39,115,105,122, - 101,39,32,40,111,112,116,105,111,110,97,108,41,32,105,115, - 32,116,104,101,32,115,105,122,101,32,105,110,32,98,121,116, - 101,115,32,111,102,32,116,104,101,32,115,111,117,114,99,101, - 32,99,111,100,101,46,10,10,32,32,32,32,32,32,32,32, - 73,109,112,108,101,109,101,110,116,105,110,103,32,116,104,105, - 115,32,109,101,116,104,111,100,32,97,108,108,111,119,115,32, - 116,104,101,32,108,111,97,100,101,114,32,116,111,32,114,101, - 97,100,32,98,121,116,101,99,111,100,101,32,102,105,108,101, - 115,46,10,32,32,32,32,32,32,32,32,82,97,105,115,101, - 115,32,73,79,69,114,114,111,114,32,119,104,101,110,32,116, - 104,101,32,112,97,116,104,32,99,97,110,110,111,116,32,98, - 101,32,104,97,110,100,108,101,100,46,10,32,32,32,32,32, - 32,32,32,114,193,0,0,0,40,1,0,0,0,114,243,0, - 0,0,40,2,0,0,0,114,75,0,0,0,114,35,0,0, - 0,114,4,0,0,0,114,4,0,0,0,114,5,0,0,0, - 244,10,0,0,0,112,97,116,104,95,115,116,97,116,115,172, - 3,0,0,115,2,0,0,0,0,11,117,23,0,0,0,83, - 111,117,114,99,101,76,111,97,100,101,114,46,112,97,116,104, - 95,115,116,97,116,115,99,4,0,0,0,0,0,0,0,4, - 0,0,0,3,0,0,0,67,0,0,0,115,16,0,0,0, - 124,0,0,106,0,0,124,2,0,124,3,0,131,2,0,83, - 40,1,0,0,0,117,228,0,0,0,79,112,116,105,111,110, - 97,108,32,109,101,116,104,111,100,32,119,104,105,99,104,32, - 119,114,105,116,101,115,32,100,97,116,97,32,40,98,121,116, - 101,115,41,32,116,111,32,97,32,102,105,108,101,32,112,97, - 116,104,32,40,97,32,115,116,114,41,46,10,10,32,32,32, - 32,32,32,32,32,73,109,112,108,101,109,101,110,116,105,110, - 103,32,116,104,105,115,32,109,101,116,104,111,100,32,97,108, - 108,111,119,115,32,102,111,114,32,116,104,101,32,119,114,105, - 116,105,110,103,32,111,102,32,98,121,116,101,99,111,100,101, - 32,102,105,108,101,115,46,10,10,32,32,32,32,32,32,32, - 32,84,104,101,32,115,111,117,114,99,101,32,112,97,116,104, - 32,105,115,32,110,101,101,100,101,100,32,105,110,32,111,114, - 100,101,114,32,116,111,32,99,111,114,114,101,99,116,108,121, - 32,116,114,97,110,115,102,101,114,32,112,101,114,109,105,115, - 115,105,111,110,115,10,32,32,32,32,32,32,32,32,40,1, - 0,0,0,244,8,0,0,0,115,101,116,95,100,97,116,97, - 40,4,0,0,0,114,75,0,0,0,114,126,0,0,0,116, - 10,0,0,0,99,97,99,104,101,95,112,97,116,104,114,52, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,244,15,0,0,0,95,99,97,99,104,101,95,98,121, - 116,101,99,111,100,101,185,3,0,0,115,2,0,0,0,0, - 8,117,28,0,0,0,83,111,117,114,99,101,76,111,97,100, - 101,114,46,95,99,97,99,104,101,95,98,121,116,101,99,111, - 100,101,99,3,0,0,0,0,0,0,0,3,0,0,0,1, - 0,0,0,67,0,0,0,115,4,0,0,0,100,1,0,83, - 40,2,0,0,0,117,150,0,0,0,79,112,116,105,111,110, - 97,108,32,109,101,116,104,111,100,32,119,104,105,99,104,32, - 119,114,105,116,101,115,32,100,97,116,97,32,40,98,121,116, - 101,115,41,32,116,111,32,97,32,102,105,108,101,32,112,97, - 116,104,32,40,97,32,115,116,114,41,46,10,10,32,32,32, - 32,32,32,32,32,73,109,112,108,101,109,101,110,116,105,110, - 103,32,116,104,105,115,32,109,101,116,104,111,100,32,97,108, - 108,111,119,115,32,102,111,114,32,116,104,101,32,119,114,105, - 116,105,110,103,32,111,102,32,98,121,116,101,99,111,100,101, - 32,102,105,108,101,115,46,10,32,32,32,32,32,32,32,32, - 78,114,4,0,0,0,40,3,0,0,0,114,75,0,0,0, - 114,35,0,0,0,114,52,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,114,245,0,0,0,195,3, - 0,0,115,0,0,0,0,117,21,0,0,0,83,111,117,114, - 99,101,76,111,97,100,101,114,46,115,101,116,95,100,97,116, - 97,99,2,0,0,0,0,0,0,0,5,0,0,0,16,0, - 0,0,67,0,0,0,115,105,0,0,0,124,0,0,106,0, - 0,124,1,0,131,1,0,125,2,0,121,19,0,124,0,0, - 106,1,0,124,2,0,131,1,0,125,3,0,87,110,58,0, - 4,116,2,0,107,10,0,114,94,0,1,125,4,0,1,122, - 26,0,116,3,0,100,1,0,100,2,0,124,1,0,131,1, - 1,124,4,0,130,2,0,87,89,100,3,0,100,3,0,125, - 4,0,126,4,0,88,110,1,0,88,116,4,0,124,3,0, - 131,1,0,83,40,4,0,0,0,117,52,0,0,0,67,111, - 110,99,114,101,116,101,32,105,109,112,108,101,109,101,110,116, - 97,116,105,111,110,32,111,102,32,73,110,115,112,101,99,116, - 76,111,97,100,101,114,46,103,101,116,95,115,111,117,114,99, - 101,46,117,39,0,0,0,115,111,117,114,99,101,32,110,111, - 116,32,97,118,97,105,108,97,98,108,101,32,116,104,114,111, - 117,103,104,32,103,101,116,95,100,97,116,97,40,41,114,71, - 0,0,0,78,40,5,0,0,0,114,163,0,0,0,244,8, - 0,0,0,103,101,116,95,100,97,116,97,114,40,0,0,0, - 114,157,0,0,0,114,213,0,0,0,40,5,0,0,0,114, - 75,0,0,0,114,178,0,0,0,114,35,0,0,0,114,211, - 0,0,0,244,3,0,0,0,101,120,99,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,220,0,0,0,202, - 3,0,0,115,14,0,0,0,0,2,15,1,3,1,19,1, - 18,1,9,1,31,1,117,23,0,0,0,83,111,117,114,99, - 101,76,111,97,100,101,114,46,103,101,116,95,115,111,117,114, - 99,101,244,9,0,0,0,95,111,112,116,105,109,105,122,101, - 114,29,0,0,0,99,3,0,0,0,1,0,0,0,4,0, - 0,0,9,0,0,0,67,0,0,0,115,31,0,0,0,116, - 0,0,116,1,0,124,1,0,124,2,0,100,1,0,100,2, - 0,100,3,0,100,4,0,124,3,0,131,4,2,83,40,5, - 0,0,0,117,130,0,0,0,82,101,116,117,114,110,32,116, - 104,101,32,99,111,100,101,32,111,98,106,101,99,116,32,99, - 111,109,112,105,108,101,100,32,102,114,111,109,32,115,111,117, - 114,99,101,46,10,10,32,32,32,32,32,32,32,32,84,104, - 101,32,39,100,97,116,97,39,32,97,114,103,117,109,101,110, - 116,32,99,97,110,32,98,101,32,97,110,121,32,111,98,106, - 101,99,116,32,116,121,112,101,32,116,104,97,116,32,99,111, - 109,112,105,108,101,40,41,32,115,117,112,112,111,114,116,115, - 46,10,32,32,32,32,32,32,32,32,114,240,0,0,0,244, - 12,0,0,0,100,111,110,116,95,105,110,104,101,114,105,116, - 84,114,103,0,0,0,40,2,0,0,0,114,99,0,0,0, - 244,7,0,0,0,99,111,109,112,105,108,101,40,4,0,0, - 0,114,75,0,0,0,114,52,0,0,0,114,35,0,0,0, - 114,249,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,244,14,0,0,0,115,111,117,114,99,101,95, - 116,111,95,99,111,100,101,212,3,0,0,115,4,0,0,0, - 0,5,18,1,117,27,0,0,0,83,111,117,114,99,101,76, - 111,97,100,101,114,46,115,111,117,114,99,101,95,116,111,95, - 99,111,100,101,99,2,0,0,0,0,0,0,0,10,0,0, - 0,45,0,0,0,67,0,0,0,115,177,1,0,0,124,0, - 0,106,0,0,124,1,0,131,1,0,125,2,0,100,1,0, - 125,3,0,121,16,0,116,1,0,124,2,0,131,1,0,125, - 4,0,87,110,24,0,4,116,2,0,107,10,0,114,63,0, - 1,1,1,100,1,0,125,4,0,89,110,202,0,88,121,19, - 0,124,0,0,106,3,0,124,2,0,131,1,0,125,5,0, - 87,110,18,0,4,116,4,0,107,10,0,114,103,0,1,1, - 1,89,110,162,0,88,116,5,0,124,5,0,100,2,0,25, - 131,1,0,125,3,0,121,19,0,124,0,0,106,6,0,124, - 4,0,131,1,0,125,6,0,87,110,18,0,4,116,7,0, - 107,10,0,114,159,0,1,1,1,89,110,106,0,88,121,34, - 0,116,8,0,124,6,0,100,3,0,124,5,0,100,4,0, - 124,1,0,100,5,0,124,4,0,131,1,3,125,7,0,87, - 110,24,0,4,116,9,0,116,10,0,102,2,0,107,10,0, - 114,220,0,1,1,1,89,110,45,0,88,116,11,0,100,6, - 0,124,4,0,124,2,0,131,3,0,1,116,12,0,124,7, - 0,100,4,0,124,1,0,100,7,0,124,4,0,100,8,0, - 124,2,0,131,1,3,83,124,0,0,106,6,0,124,2,0, - 131,1,0,125,8,0,124,0,0,106,13,0,124,8,0,124, - 2,0,131,2,0,125,9,0,116,11,0,100,9,0,124,2, - 0,131,2,0,1,116,14,0,106,15,0,12,114,173,1,124, - 4,0,100,1,0,107,9,0,114,173,1,124,3,0,100,1, - 0,107,9,0,114,173,1,116,16,0,124,9,0,124,3,0, - 116,17,0,124,8,0,131,1,0,131,3,0,125,6,0,121, - 36,0,124,0,0,106,18,0,124,2,0,124,4,0,124,6, - 0,131,3,0,1,116,11,0,100,10,0,124,4,0,131,2, - 0,1,87,113,173,1,4,116,2,0,107,10,0,114,169,1, - 1,1,1,89,113,173,1,88,110,0,0,124,9,0,83,40, - 11,0,0,0,117,190,0,0,0,67,111,110,99,114,101,116, - 101,32,105,109,112,108,101,109,101,110,116,97,116,105,111,110, - 32,111,102,32,73,110,115,112,101,99,116,76,111,97,100,101, - 114,46,103,101,116,95,99,111,100,101,46,10,10,32,32,32, - 32,32,32,32,32,82,101,97,100,105,110,103,32,111,102,32, - 98,121,116,101,99,111,100,101,32,114,101,113,117,105,114,101, - 115,32,112,97,116,104,95,115,116,97,116,115,32,116,111,32, - 98,101,32,105,109,112,108,101,109,101,110,116,101,100,46,32, - 84,111,32,119,114,105,116,101,10,32,32,32,32,32,32,32, - 32,98,121,116,101,99,111,100,101,44,32,115,101,116,95,100, - 97,116,97,32,109,117,115,116,32,97,108,115,111,32,98,101, - 32,105,109,112,108,101,109,101,110,116,101,100,46,10,10,32, - 32,32,32,32,32,32,32,78,114,193,0,0,0,114,197,0, - 0,0,114,71,0,0,0,114,35,0,0,0,117,13,0,0, - 0,123,125,32,109,97,116,99,104,101,115,32,123,125,114,125, - 0,0,0,114,126,0,0,0,117,19,0,0,0,99,111,100, - 101,32,111,98,106,101,99,116,32,102,114,111,109,32,123,125, - 117,10,0,0,0,119,114,111,116,101,32,123,33,114,125,40, - 19,0,0,0,114,163,0,0,0,114,117,0,0,0,114,109, - 0,0,0,114,244,0,0,0,114,242,0,0,0,114,14,0, - 0,0,114,247,0,0,0,114,40,0,0,0,114,200,0,0, - 0,114,157,0,0,0,114,196,0,0,0,114,137,0,0,0, - 114,205,0,0,0,114,252,0,0,0,114,7,0,0,0,244, - 19,0,0,0,100,111,110,116,95,119,114,105,116,101,95,98, - 121,116,101,99,111,100,101,114,208,0,0,0,114,31,0,0, - 0,114,246,0,0,0,40,10,0,0,0,114,75,0,0,0, - 114,178,0,0,0,114,126,0,0,0,114,198,0,0,0,114, - 125,0,0,0,244,2,0,0,0,115,116,114,52,0,0,0, - 244,10,0,0,0,98,121,116,101,115,95,100,97,116,97,114, - 211,0,0,0,116,11,0,0,0,99,111,100,101,95,111,98, - 106,101,99,116,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,114,219,0,0,0,220,3,0,0,115,78,0,0, - 0,0,7,15,1,6,1,3,1,16,1,13,1,11,2,3, - 1,19,1,13,1,5,2,16,1,3,1,19,1,13,1,5, - 2,3,1,9,1,12,1,13,1,19,1,5,2,9,1,7, - 1,15,1,6,1,7,1,15,1,18,1,13,1,22,1,12, - 1,9,1,15,1,3,1,19,1,17,1,13,1,8,1,117, - 21,0,0,0,83,111,117,114,99,101,76,111,97,100,101,114, - 46,103,101,116,95,99,111,100,101,78,114,123,0,0,0,40, - 10,0,0,0,114,56,0,0,0,114,55,0,0,0,114,57, - 0,0,0,114,243,0,0,0,114,244,0,0,0,114,246,0, - 0,0,114,245,0,0,0,114,220,0,0,0,114,252,0,0, - 0,114,219,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,241,0,0,0,162, - 3,0,0,115,14,0,0,0,12,2,12,8,12,13,12,10, - 12,7,12,10,18,8,114,241,0,0,0,99,0,0,0,0, - 0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0, - 115,88,0,0,0,101,0,0,90,1,0,100,0,0,90,2, - 0,100,1,0,90,3,0,100,2,0,100,3,0,132,0,0, - 90,4,0,101,5,0,135,0,0,102,1,0,100,4,0,100, - 5,0,134,0,0,131,1,0,90,6,0,101,5,0,100,6, - 0,100,7,0,132,0,0,131,1,0,90,7,0,100,8,0, - 100,9,0,132,0,0,90,8,0,135,0,0,83,40,10,0, - 0,0,244,10,0,0,0,70,105,108,101,76,111,97,100,101, - 114,117,103,0,0,0,66,97,115,101,32,102,105,108,101,32, - 108,111,97,100,101,114,32,99,108,97,115,115,32,119,104,105, - 99,104,32,105,109,112,108,101,109,101,110,116,115,32,116,104, - 101,32,108,111,97,100,101,114,32,112,114,111,116,111,99,111, - 108,32,109,101,116,104,111,100,115,32,116,104,97,116,10,32, - 32,32,32,114,101,113,117,105,114,101,32,102,105,108,101,32, - 115,121,115,116,101,109,32,117,115,97,103,101,46,99,3,0, - 0,0,0,0,0,0,3,0,0,0,2,0,0,0,67,0, - 0,0,115,22,0,0,0,124,1,0,124,0,0,95,0,0, - 124,2,0,124,0,0,95,1,0,100,1,0,83,40,2,0, - 0,0,117,75,0,0,0,67,97,99,104,101,32,116,104,101, - 32,109,111,100,117,108,101,32,110,97,109,101,32,97,110,100, - 32,116,104,101,32,112,97,116,104,32,116,111,32,116,104,101, - 32,102,105,108,101,32,102,111,117,110,100,32,98,121,32,116, - 104,101,10,32,32,32,32,32,32,32,32,102,105,110,100,101, - 114,46,78,40,2,0,0,0,114,71,0,0,0,114,35,0, - 0,0,40,3,0,0,0,114,75,0,0,0,114,178,0,0, - 0,114,35,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,76,0,0,0,21,4,0,0,115,4, - 0,0,0,0,3,9,1,117,19,0,0,0,70,105,108,101, - 76,111,97,100,101,114,46,95,95,105,110,105,116,95,95,99, - 2,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, - 3,0,0,0,115,22,0,0,0,116,0,0,116,1,0,124, - 0,0,131,2,0,106,2,0,124,1,0,131,1,0,83,40, - 1,0,0,0,117,26,0,0,0,76,111,97,100,32,97,32, - 109,111,100,117,108,101,32,102,114,111,109,32,97,32,102,105, - 108,101,46,40,3,0,0,0,114,148,0,0,0,114,0,1, - 0,0,114,218,0,0,0,40,2,0,0,0,114,75,0,0, - 0,114,178,0,0,0,40,1,0,0,0,114,150,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,218,0,0,0,27, - 4,0,0,115,2,0,0,0,0,5,117,22,0,0,0,70, - 105,108,101,76,111,97,100,101,114,46,108,111,97,100,95,109, - 111,100,117,108,101,99,2,0,0,0,0,0,0,0,2,0, - 0,0,1,0,0,0,67,0,0,0,115,7,0,0,0,124, - 0,0,106,0,0,83,40,1,0,0,0,117,58,0,0,0, - 82,101,116,117,114,110,32,116,104,101,32,112,97,116,104,32, - 116,111,32,116,104,101,32,115,111,117,114,99,101,32,102,105, - 108,101,32,97,115,32,102,111,117,110,100,32,98,121,32,116, - 104,101,32,102,105,110,100,101,114,46,40,1,0,0,0,114, - 35,0,0,0,40,2,0,0,0,114,75,0,0,0,114,178, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,163,0,0,0,34,4,0,0,115,2,0,0,0, - 0,3,117,23,0,0,0,70,105,108,101,76,111,97,100,101, - 114,46,103,101,116,95,102,105,108,101,110,97,109,101,99,2, - 0,0,0,0,0,0,0,3,0,0,0,8,0,0,0,67, - 0,0,0,115,41,0,0,0,116,0,0,106,1,0,124,1, - 0,100,1,0,131,2,0,143,17,0,125,2,0,124,2,0, - 106,2,0,131,0,0,83,87,100,2,0,81,88,100,2,0, - 83,40,3,0,0,0,117,39,0,0,0,82,101,116,117,114, - 110,32,116,104,101,32,100,97,116,97,32,102,114,111,109,32, - 112,97,116,104,32,97,115,32,114,97,119,32,98,121,116,101, - 115,46,244,1,0,0,0,114,78,40,3,0,0,0,114,48, - 0,0,0,114,49,0,0,0,116,4,0,0,0,114,101,97, - 100,40,3,0,0,0,114,75,0,0,0,114,35,0,0,0, - 114,53,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,247,0,0,0,39,4,0,0,115,4,0, - 0,0,0,2,21,1,117,19,0,0,0,70,105,108,101,76, - 111,97,100,101,114,46,103,101,116,95,100,97,116,97,40,9, - 0,0,0,114,56,0,0,0,114,55,0,0,0,114,57,0, - 0,0,114,58,0,0,0,114,76,0,0,0,114,176,0,0, - 0,114,218,0,0,0,114,163,0,0,0,114,247,0,0,0, - 114,4,0,0,0,114,4,0,0,0,40,1,0,0,0,114, - 150,0,0,0,114,5,0,0,0,114,0,1,0,0,16,4, - 0,0,115,10,0,0,0,12,3,6,2,12,6,24,7,18, - 5,114,0,1,0,0,99,0,0,0,0,0,0,0,0,0, - 0,0,0,4,0,0,0,64,0,0,0,115,64,0,0,0, + 0,0,0,115,7,0,0,0,124,0,0,106,0,0,83,40, + 1,0,0,0,117,58,0,0,0,82,101,116,117,114,110,32, + 116,104,101,32,112,97,116,104,32,116,111,32,116,104,101,32, + 115,111,117,114,99,101,32,102,105,108,101,32,97,115,32,102, + 111,117,110,100,32,98,121,32,116,104,101,32,102,105,110,100, + 101,114,46,40,1,0,0,0,117,4,0,0,0,112,97,116, + 104,40,2,0,0,0,117,4,0,0,0,115,101,108,102,117, + 8,0,0,0,102,117,108,108,110,97,109,101,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,12,0,0,0,103,101,116, + 95,102,105,108,101,110,97,109,101,20,4,0,0,115,2,0, + 0,0,0,3,117,23,0,0,0,70,105,108,101,76,111,97, + 100,101,114,46,103,101,116,95,102,105,108,101,110,97,109,101, + 99,2,0,0,0,0,0,0,0,3,0,0,0,8,0,0, + 0,67,0,0,0,115,41,0,0,0,116,0,0,106,1,0, + 124,1,0,100,1,0,131,2,0,143,17,0,125,2,0,124, + 2,0,106,2,0,131,0,0,83,87,100,2,0,81,88,100, + 2,0,83,40,3,0,0,0,117,39,0,0,0,82,101,116, + 117,114,110,32,116,104,101,32,100,97,116,97,32,102,114,111, + 109,32,112,97,116,104,32,97,115,32,114,97,119,32,98,121, + 116,101,115,46,117,1,0,0,0,114,78,40,3,0,0,0, + 117,3,0,0,0,95,105,111,117,6,0,0,0,70,105,108, + 101,73,79,117,4,0,0,0,114,101,97,100,40,3,0,0, + 0,117,4,0,0,0,115,101,108,102,117,4,0,0,0,112, + 97,116,104,117,4,0,0,0,102,105,108,101,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,8,0,0,0,103,101,116, + 95,100,97,116,97,25,4,0,0,115,4,0,0,0,0,2, + 21,1,117,19,0,0,0,70,105,108,101,76,111,97,100,101, + 114,46,103,101,116,95,100,97,116,97,40,9,0,0,0,117, + 8,0,0,0,95,95,110,97,109,101,95,95,117,10,0,0, + 0,95,95,109,111,100,117,108,101,95,95,117,12,0,0,0, + 95,95,113,117,97,108,110,97,109,101,95,95,117,7,0,0, + 0,95,95,100,111,99,95,95,117,8,0,0,0,95,95,105, + 110,105,116,95,95,117,11,0,0,0,95,99,104,101,99,107, + 95,110,97,109,101,117,11,0,0,0,108,111,97,100,95,109, + 111,100,117,108,101,117,12,0,0,0,103,101,116,95,102,105, + 108,101,110,97,109,101,117,8,0,0,0,103,101,116,95,100, + 97,116,97,40,1,0,0,0,117,10,0,0,0,95,95,108, + 111,99,97,108,115,95,95,40,0,0,0,0,40,1,0,0, + 0,117,9,0,0,0,95,95,99,108,97,115,115,95,95,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,10,0,0,0,70,105,108,101,76,111,97,100,101,114, + 2,4,0,0,115,10,0,0,0,16,3,6,2,12,6,24, + 7,18,5,117,10,0,0,0,70,105,108,101,76,111,97,100, + 101,114,99,1,0,0,0,0,0,0,0,1,0,0,0,4, + 0,0,0,66,0,0,0,115,68,0,0,0,124,0,0,69, 101,0,0,90,1,0,100,0,0,90,2,0,100,1,0,90, 3,0,100,2,0,100,3,0,132,0,0,90,4,0,100,4, 0,100,5,0,132,0,0,90,5,0,100,6,0,100,7,0, 100,8,0,100,9,0,132,0,1,90,6,0,100,10,0,83, - 40,11,0,0,0,244,16,0,0,0,83,111,117,114,99,101, + 40,11,0,0,0,117,16,0,0,0,83,111,117,114,99,101, 70,105,108,101,76,111,97,100,101,114,117,62,0,0,0,67, 111,110,99,114,101,116,101,32,105,109,112,108,101,109,101,110, 116,97,116,105,111,110,32,111,102,32,83,111,117,114,99,101, @@ -2156,520 +2495,659 @@ 1,0,54,124,2,0,106,3,0,100,2,0,54,83,40,3, 0,0,0,117,33,0,0,0,82,101,116,117,114,110,32,116, 104,101,32,109,101,116,97,100,97,116,97,32,102,111,114,32, - 116,104,101,32,112,97,116,104,46,114,193,0,0,0,114,194, - 0,0,0,40,4,0,0,0,114,3,0,0,0,114,39,0, - 0,0,244,8,0,0,0,115,116,95,109,116,105,109,101,116, + 116,104,101,32,112,97,116,104,46,117,5,0,0,0,109,116, + 105,109,101,117,4,0,0,0,115,105,122,101,40,4,0,0, + 0,117,3,0,0,0,95,111,115,117,4,0,0,0,115,116, + 97,116,117,8,0,0,0,115,116,95,109,116,105,109,101,117, 7,0,0,0,115,116,95,115,105,122,101,40,3,0,0,0, - 114,75,0,0,0,114,35,0,0,0,114,254,0,0,0,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,114,244, - 0,0,0,49,4,0,0,115,4,0,0,0,0,2,15,1, - 117,27,0,0,0,83,111,117,114,99,101,70,105,108,101,76, - 111,97,100,101,114,46,112,97,116,104,95,115,116,97,116,115, - 99,4,0,0,0,0,0,0,0,5,0,0,0,5,0,0, - 0,67,0,0,0,115,34,0,0,0,116,0,0,124,1,0, - 131,1,0,125,4,0,124,0,0,106,1,0,124,2,0,124, - 3,0,100,1,0,124,4,0,131,2,1,83,40,2,0,0, - 0,78,244,5,0,0,0,95,109,111,100,101,40,2,0,0, - 0,114,129,0,0,0,114,245,0,0,0,40,5,0,0,0, - 114,75,0,0,0,114,126,0,0,0,114,125,0,0,0,114, - 52,0,0,0,114,42,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,114,246,0,0,0,54,4,0, - 0,115,4,0,0,0,0,2,12,1,117,32,0,0,0,83, - 111,117,114,99,101,70,105,108,101,76,111,97,100,101,114,46, - 95,99,97,99,104,101,95,98,121,116,101,99,111,100,101,114, - 4,1,0,0,105,182,1,0,0,99,3,0,0,0,1,0, - 0,0,9,0,0,0,18,0,0,0,67,0,0,0,115,53, - 1,0,0,116,0,0,124,1,0,131,1,0,92,2,0,125, - 4,0,125,5,0,103,0,0,125,6,0,120,54,0,124,4, - 0,114,80,0,116,1,0,124,4,0,131,1,0,12,114,80, - 0,116,0,0,124,4,0,131,1,0,92,2,0,125,4,0, - 125,7,0,124,6,0,106,2,0,124,7,0,131,1,0,1, - 113,27,0,87,120,132,0,116,3,0,124,6,0,131,1,0, - 68,93,118,0,125,7,0,116,4,0,124,4,0,124,7,0, - 131,2,0,125,4,0,121,17,0,116,5,0,106,6,0,124, - 4,0,131,1,0,1,87,113,94,0,4,116,7,0,107,10, - 0,114,155,0,1,1,1,119,94,0,89,113,94,0,4,116, - 8,0,107,10,0,114,211,0,1,125,8,0,1,122,25,0, - 116,9,0,100,1,0,124,4,0,124,8,0,131,3,0,1, - 100,2,0,83,87,89,100,2,0,100,2,0,125,8,0,126, - 8,0,88,113,94,0,88,113,94,0,87,121,33,0,116,10, - 0,124,1,0,124,2,0,124,3,0,131,3,0,1,116,9, - 0,100,3,0,124,1,0,131,2,0,1,87,110,53,0,4, - 116,8,0,107,10,0,114,48,1,1,125,8,0,1,122,21, - 0,116,9,0,100,1,0,124,1,0,124,8,0,131,3,0, - 1,87,89,100,2,0,100,2,0,125,8,0,126,8,0,88, - 110,1,0,88,100,2,0,83,40,4,0,0,0,117,27,0, - 0,0,87,114,105,116,101,32,98,121,116,101,115,32,100,97, - 116,97,32,116,111,32,97,32,102,105,108,101,46,117,27,0, - 0,0,99,111,117,108,100,32,110,111,116,32,99,114,101,97, - 116,101,32,123,33,114,125,58,32,123,33,114,125,78,117,12, - 0,0,0,99,114,101,97,116,101,100,32,123,33,114,125,40, - 11,0,0,0,114,38,0,0,0,114,45,0,0,0,114,165, - 0,0,0,114,33,0,0,0,114,28,0,0,0,114,3,0, - 0,0,116,5,0,0,0,109,107,100,105,114,244,15,0,0, - 0,70,105,108,101,69,120,105,115,116,115,69,114,114,111,114, - 114,40,0,0,0,114,137,0,0,0,114,54,0,0,0,40, - 9,0,0,0,114,75,0,0,0,114,35,0,0,0,114,52, - 0,0,0,114,4,1,0,0,244,6,0,0,0,112,97,114, - 101,110,116,114,116,0,0,0,114,27,0,0,0,114,23,0, - 0,0,114,248,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,5,0,0,0,114,245,0,0,0,59,4,0,0,115, - 38,0,0,0,0,2,18,1,6,2,22,1,18,1,17,2, - 19,1,15,1,3,1,17,1,13,2,7,1,18,3,16,1, - 27,1,3,1,16,1,17,1,18,2,117,25,0,0,0,83, - 111,117,114,99,101,70,105,108,101,76,111,97,100,101,114,46, - 115,101,116,95,100,97,116,97,78,40,7,0,0,0,114,56, - 0,0,0,114,55,0,0,0,114,57,0,0,0,114,58,0, - 0,0,114,244,0,0,0,114,246,0,0,0,114,245,0,0, - 0,114,4,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,2,1,0,0,45,4,0,0,115,8, - 0,0,0,12,2,6,2,12,5,12,5,114,2,1,0,0, - 99,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0, - 0,0,0,0,0,115,64,0,0,0,101,0,0,90,1,0, - 100,0,0,90,2,0,100,1,0,90,3,0,135,0,0,102, - 1,0,100,2,0,100,3,0,134,0,0,90,4,0,100,4, - 0,100,5,0,132,0,0,90,5,0,100,6,0,100,7,0, - 132,0,0,90,6,0,135,0,0,83,40,8,0,0,0,244, + 117,4,0,0,0,115,101,108,102,117,4,0,0,0,112,97, + 116,104,117,2,0,0,0,115,116,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,10,0,0,0,112,97,116,104,95,115, + 116,97,116,115,35,4,0,0,115,4,0,0,0,0,2,15, + 1,117,27,0,0,0,83,111,117,114,99,101,70,105,108,101, + 76,111,97,100,101,114,46,112,97,116,104,95,115,116,97,116, + 115,99,4,0,0,0,0,0,0,0,5,0,0,0,13,0, + 0,0,67,0,0,0,115,81,0,0,0,121,22,0,116,0, + 0,106,1,0,124,1,0,131,1,0,106,2,0,125,4,0, + 87,110,24,0,4,116,3,0,107,10,0,114,48,0,1,1, + 1,100,1,0,125,4,0,89,110,1,0,88,124,4,0,100, + 2,0,79,125,4,0,124,0,0,106,4,0,124,2,0,124, + 3,0,100,3,0,124,4,0,131,2,1,83,40,4,0,0, + 0,78,105,182,1,0,0,105,128,0,0,0,117,5,0,0, + 0,95,109,111,100,101,40,5,0,0,0,117,3,0,0,0, + 95,111,115,117,4,0,0,0,115,116,97,116,117,7,0,0, + 0,115,116,95,109,111,100,101,117,7,0,0,0,79,83,69, + 114,114,111,114,117,8,0,0,0,115,101,116,95,100,97,116, + 97,40,5,0,0,0,117,4,0,0,0,115,101,108,102,117, + 11,0,0,0,115,111,117,114,99,101,95,112,97,116,104,117, + 13,0,0,0,98,121,116,101,99,111,100,101,95,112,97,116, + 104,117,4,0,0,0,100,97,116,97,117,4,0,0,0,109, + 111,100,101,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 15,0,0,0,95,99,97,99,104,101,95,98,121,116,101,99, + 111,100,101,40,4,0,0,115,12,0,0,0,0,2,3,1, + 22,1,13,1,11,3,10,1,117,32,0,0,0,83,111,117, + 114,99,101,70,105,108,101,76,111,97,100,101,114,46,95,99, + 97,99,104,101,95,98,121,116,101,99,111,100,101,117,5,0, + 0,0,95,109,111,100,101,105,182,1,0,0,99,3,0,0, + 0,1,0,0,0,9,0,0,0,18,0,0,0,67,0,0, + 0,115,53,1,0,0,116,0,0,124,1,0,131,1,0,92, + 2,0,125,4,0,125,5,0,103,0,0,125,6,0,120,54, + 0,124,4,0,114,80,0,116,1,0,124,4,0,131,1,0, + 12,114,80,0,116,0,0,124,4,0,131,1,0,92,2,0, + 125,4,0,125,7,0,124,6,0,106,2,0,124,7,0,131, + 1,0,1,113,27,0,87,120,132,0,116,3,0,124,6,0, + 131,1,0,68,93,118,0,125,7,0,116,4,0,124,4,0, + 124,7,0,131,2,0,125,4,0,121,17,0,116,5,0,106, + 6,0,124,4,0,131,1,0,1,87,113,94,0,4,116,7, + 0,107,10,0,114,155,0,1,1,1,119,94,0,89,113,94, + 0,4,116,8,0,107,10,0,114,211,0,1,125,8,0,1, + 122,25,0,116,9,0,100,1,0,124,4,0,124,8,0,131, + 3,0,1,100,2,0,83,87,89,100,2,0,100,2,0,125, + 8,0,126,8,0,88,113,94,0,88,113,94,0,87,121,33, + 0,116,10,0,124,1,0,124,2,0,124,3,0,131,3,0, + 1,116,9,0,100,3,0,124,1,0,131,2,0,1,87,110, + 53,0,4,116,8,0,107,10,0,114,48,1,1,125,8,0, + 1,122,21,0,116,9,0,100,1,0,124,1,0,124,8,0, + 131,3,0,1,87,89,100,2,0,100,2,0,125,8,0,126, + 8,0,88,110,1,0,88,100,2,0,83,40,4,0,0,0, + 117,27,0,0,0,87,114,105,116,101,32,98,121,116,101,115, + 32,100,97,116,97,32,116,111,32,97,32,102,105,108,101,46, + 117,27,0,0,0,99,111,117,108,100,32,110,111,116,32,99, + 114,101,97,116,101,32,123,33,114,125,58,32,123,33,114,125, + 78,117,12,0,0,0,99,114,101,97,116,101,100,32,123,33, + 114,125,40,11,0,0,0,117,11,0,0,0,95,112,97,116, + 104,95,115,112,108,105,116,117,11,0,0,0,95,112,97,116, + 104,95,105,115,100,105,114,117,6,0,0,0,97,112,112,101, + 110,100,117,8,0,0,0,114,101,118,101,114,115,101,100,117, + 10,0,0,0,95,112,97,116,104,95,106,111,105,110,117,3, + 0,0,0,95,111,115,117,5,0,0,0,109,107,100,105,114, + 117,15,0,0,0,70,105,108,101,69,120,105,115,116,115,69, + 114,114,111,114,117,7,0,0,0,79,83,69,114,114,111,114, + 117,16,0,0,0,95,118,101,114,98,111,115,101,95,109,101, + 115,115,97,103,101,117,13,0,0,0,95,119,114,105,116,101, + 95,97,116,111,109,105,99,40,9,0,0,0,117,4,0,0, + 0,115,101,108,102,117,4,0,0,0,112,97,116,104,117,4, + 0,0,0,100,97,116,97,117,5,0,0,0,95,109,111,100, + 101,117,6,0,0,0,112,97,114,101,110,116,117,8,0,0, + 0,102,105,108,101,110,97,109,101,117,10,0,0,0,112,97, + 116,104,95,112,97,114,116,115,117,4,0,0,0,112,97,114, + 116,117,3,0,0,0,101,120,99,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,8,0,0,0,115,101,116,95,100,97, + 116,97,51,4,0,0,115,38,0,0,0,0,2,18,1,6, + 2,22,1,18,1,17,2,19,1,15,1,3,1,17,1,13, + 2,7,1,18,3,16,1,27,1,3,1,16,1,17,1,18, + 2,117,25,0,0,0,83,111,117,114,99,101,70,105,108,101, + 76,111,97,100,101,114,46,115,101,116,95,100,97,116,97,78, + 40,7,0,0,0,117,8,0,0,0,95,95,110,97,109,101, + 95,95,117,10,0,0,0,95,95,109,111,100,117,108,101,95, + 95,117,12,0,0,0,95,95,113,117,97,108,110,97,109,101, + 95,95,117,7,0,0,0,95,95,100,111,99,95,95,117,10, + 0,0,0,112,97,116,104,95,115,116,97,116,115,117,15,0, + 0,0,95,99,97,99,104,101,95,98,121,116,101,99,111,100, + 101,117,8,0,0,0,115,101,116,95,100,97,116,97,40,1, + 0,0,0,117,10,0,0,0,95,95,108,111,99,97,108,115, + 95,95,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,16, + 0,0,0,83,111,117,114,99,101,70,105,108,101,76,111,97, + 100,101,114,31,4,0,0,115,8,0,0,0,16,2,6,2, + 12,5,12,11,117,16,0,0,0,83,111,117,114,99,101,70, + 105,108,101,76,111,97,100,101,114,99,1,0,0,0,0,0, + 0,0,1,0,0,0,2,0,0,0,66,0,0,0,115,62, + 0,0,0,124,0,0,69,101,0,0,90,1,0,100,0,0, + 90,2,0,100,1,0,90,3,0,100,2,0,100,3,0,132, + 0,0,90,4,0,100,4,0,100,5,0,132,0,0,90,5, + 0,100,6,0,100,7,0,132,0,0,90,6,0,100,8,0, + 83,40,9,0,0,0,117,20,0,0,0,83,111,117,114,99, + 101,108,101,115,115,70,105,108,101,76,111,97,100,101,114,117, + 45,0,0,0,76,111,97,100,101,114,32,119,104,105,99,104, + 32,104,97,110,100,108,101,115,32,115,111,117,114,99,101,108, + 101,115,115,32,102,105,108,101,32,105,109,112,111,114,116,115, + 46,99,2,0,0,0,0,0,0,0,2,0,0,0,4,0, + 0,0,67,0,0,0,115,19,0,0,0,124,0,0,106,0, + 0,124,1,0,100,1,0,100,2,0,131,1,1,83,40,3, + 0,0,0,78,117,10,0,0,0,115,111,117,114,99,101,108, + 101,115,115,84,40,1,0,0,0,117,12,0,0,0,95,108, + 111,97,100,95,109,111,100,117,108,101,40,2,0,0,0,117, + 4,0,0,0,115,101,108,102,117,8,0,0,0,102,117,108, + 108,110,97,109,101,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,11,0,0,0,108,111,97,100,95,109,111,100,117,108, + 101,84,4,0,0,115,2,0,0,0,0,1,117,32,0,0, + 0,83,111,117,114,99,101,108,101,115,115,70,105,108,101,76, + 111,97,100,101,114,46,108,111,97,100,95,109,111,100,117,108, + 101,99,2,0,0,0,0,0,0,0,5,0,0,0,6,0, + 0,0,67,0,0,0,115,76,0,0,0,124,0,0,106,0, + 0,124,1,0,131,1,0,125,2,0,124,0,0,106,1,0, + 124,2,0,131,1,0,125,3,0,116,2,0,124,3,0,100, + 1,0,124,1,0,100,2,0,124,2,0,131,1,2,125,4, + 0,116,3,0,124,4,0,100,1,0,124,1,0,100,3,0, + 124,2,0,131,1,2,83,40,4,0,0,0,78,117,4,0, + 0,0,110,97,109,101,117,4,0,0,0,112,97,116,104,117, + 13,0,0,0,98,121,116,101,99,111,100,101,95,112,97,116, + 104,40,4,0,0,0,117,12,0,0,0,103,101,116,95,102, + 105,108,101,110,97,109,101,117,8,0,0,0,103,101,116,95, + 100,97,116,97,117,25,0,0,0,95,118,97,108,105,100,97, + 116,101,95,98,121,116,101,99,111,100,101,95,104,101,97,100, + 101,114,117,17,0,0,0,95,99,111,109,112,105,108,101,95, + 98,121,116,101,99,111,100,101,40,5,0,0,0,117,4,0, + 0,0,115,101,108,102,117,8,0,0,0,102,117,108,108,110, + 97,109,101,117,4,0,0,0,112,97,116,104,117,4,0,0, + 0,100,97,116,97,117,10,0,0,0,98,121,116,101,115,95, + 100,97,116,97,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,8,0,0,0,103,101,116,95,99,111,100,101,87,4,0, + 0,115,8,0,0,0,0,1,15,1,15,1,24,1,117,29, + 0,0,0,83,111,117,114,99,101,108,101,115,115,70,105,108, + 101,76,111,97,100,101,114,46,103,101,116,95,99,111,100,101, + 99,2,0,0,0,0,0,0,0,2,0,0,0,1,0,0, + 0,67,0,0,0,115,4,0,0,0,100,1,0,83,40,2, + 0,0,0,117,39,0,0,0,82,101,116,117,114,110,32,78, + 111,110,101,32,97,115,32,116,104,101,114,101,32,105,115,32, + 110,111,32,115,111,117,114,99,101,32,99,111,100,101,46,78, + 40,0,0,0,0,40,2,0,0,0,117,4,0,0,0,115, + 101,108,102,117,8,0,0,0,102,117,108,108,110,97,109,101, + 40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,10,0,0, + 0,103,101,116,95,115,111,117,114,99,101,93,4,0,0,115, + 2,0,0,0,0,2,117,31,0,0,0,83,111,117,114,99, + 101,108,101,115,115,70,105,108,101,76,111,97,100,101,114,46, + 103,101,116,95,115,111,117,114,99,101,78,40,7,0,0,0, + 117,8,0,0,0,95,95,110,97,109,101,95,95,117,10,0, + 0,0,95,95,109,111,100,117,108,101,95,95,117,12,0,0, + 0,95,95,113,117,97,108,110,97,109,101,95,95,117,7,0, + 0,0,95,95,100,111,99,95,95,117,11,0,0,0,108,111, + 97,100,95,109,111,100,117,108,101,117,8,0,0,0,103,101, + 116,95,99,111,100,101,117,10,0,0,0,103,101,116,95,115, + 111,117,114,99,101,40,1,0,0,0,117,10,0,0,0,95, + 95,108,111,99,97,108,115,95,95,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,20,0,0,0,83,111,117,114,99,101, + 108,101,115,115,70,105,108,101,76,111,97,100,101,114,80,4, + 0,0,115,8,0,0,0,16,2,6,2,12,3,12,6,117, 20,0,0,0,83,111,117,114,99,101,108,101,115,115,70,105, - 108,101,76,111,97,100,101,114,117,45,0,0,0,76,111,97, - 100,101,114,32,119,104,105,99,104,32,104,97,110,100,108,101, - 115,32,115,111,117,114,99,101,108,101,115,115,32,102,105,108, - 101,32,105,109,112,111,114,116,115,46,99,2,0,0,0,0, - 0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,115, - 32,0,0,0,116,0,0,131,0,0,106,1,0,124,1,0, - 131,1,0,1,124,1,0,106,2,0,124,1,0,95,3,0, - 100,0,0,83,40,1,0,0,0,78,40,4,0,0,0,114, - 148,0,0,0,114,239,0,0,0,114,164,0,0,0,114,238, - 0,0,0,40,2,0,0,0,114,75,0,0,0,114,161,0, - 0,0,40,1,0,0,0,114,150,0,0,0,114,4,0,0, - 0,114,5,0,0,0,114,239,0,0,0,92,4,0,0,115, - 4,0,0,0,0,1,16,1,117,38,0,0,0,83,111,117, - 114,99,101,108,101,115,115,70,105,108,101,76,111,97,100,101, - 114,46,105,110,105,116,95,109,111,100,117,108,101,95,97,116, - 116,114,115,99,2,0,0,0,0,0,0,0,5,0,0,0, - 6,0,0,0,67,0,0,0,115,76,0,0,0,124,0,0, - 106,0,0,124,1,0,131,1,0,125,2,0,124,0,0,106, - 1,0,124,2,0,131,1,0,125,3,0,116,2,0,124,3, - 0,100,1,0,124,1,0,100,2,0,124,2,0,131,1,2, - 125,4,0,116,3,0,124,4,0,100,1,0,124,1,0,100, - 3,0,124,2,0,131,1,2,83,40,4,0,0,0,78,114, - 71,0,0,0,114,35,0,0,0,114,125,0,0,0,40,4, - 0,0,0,114,163,0,0,0,114,247,0,0,0,114,200,0, - 0,0,114,205,0,0,0,40,5,0,0,0,114,75,0,0, - 0,114,178,0,0,0,114,35,0,0,0,114,52,0,0,0, - 114,255,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,219,0,0,0,96,4,0,0,115,8,0, - 0,0,0,1,15,1,15,1,24,1,117,29,0,0,0,83, - 111,117,114,99,101,108,101,115,115,70,105,108,101,76,111,97, - 100,101,114,46,103,101,116,95,99,111,100,101,99,2,0,0, + 108,101,76,111,97,100,101,114,99,1,0,0,0,0,0,0, + 0,1,0,0,0,5,0,0,0,66,0,0,0,115,104,0, + 0,0,124,0,0,69,101,0,0,90,1,0,100,0,0,90, + 2,0,100,1,0,90,3,0,100,2,0,100,3,0,132,0, + 0,90,4,0,101,5,0,101,6,0,101,7,0,100,4,0, + 100,5,0,132,0,0,131,1,0,131,1,0,131,1,0,90, + 8,0,100,6,0,100,7,0,132,0,0,90,9,0,100,8, + 0,100,9,0,132,0,0,90,10,0,100,10,0,100,11,0, + 132,0,0,90,11,0,100,12,0,83,40,13,0,0,0,117, + 19,0,0,0,69,120,116,101,110,115,105,111,110,70,105,108, + 101,76,111,97,100,101,114,117,93,0,0,0,76,111,97,100, + 101,114,32,102,111,114,32,101,120,116,101,110,115,105,111,110, + 32,109,111,100,117,108,101,115,46,10,10,32,32,32,32,84, + 104,101,32,99,111,110,115,116,114,117,99,116,111,114,32,105, + 115,32,100,101,115,105,103,110,101,100,32,116,111,32,119,111, + 114,107,32,119,105,116,104,32,70,105,108,101,70,105,110,100, + 101,114,46,10,10,32,32,32,32,99,3,0,0,0,0,0, + 0,0,3,0,0,0,2,0,0,0,67,0,0,0,115,22, + 0,0,0,124,1,0,124,0,0,95,0,0,124,2,0,124, + 0,0,95,1,0,100,0,0,83,40,1,0,0,0,78,40, + 2,0,0,0,117,4,0,0,0,110,97,109,101,117,4,0, + 0,0,112,97,116,104,40,3,0,0,0,117,4,0,0,0, + 115,101,108,102,117,4,0,0,0,110,97,109,101,117,4,0, + 0,0,112,97,116,104,40,0,0,0,0,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,8,0,0,0,95,95,105,110,105,116,95,95,110, + 4,0,0,115,4,0,0,0,0,1,9,1,117,28,0,0, + 0,69,120,116,101,110,115,105,111,110,70,105,108,101,76,111, + 97,100,101,114,46,95,95,105,110,105,116,95,95,99,2,0, + 0,0,0,0,0,0,4,0,0,0,10,0,0,0,67,0, + 0,0,115,175,0,0,0,124,1,0,116,0,0,106,1,0, + 107,6,0,125,2,0,121,107,0,116,2,0,116,3,0,106, + 4,0,124,1,0,124,0,0,106,5,0,131,3,0,125,3, + 0,116,6,0,100,1,0,124,0,0,106,5,0,131,2,0, + 1,124,0,0,106,7,0,124,1,0,131,1,0,114,117,0, + 116,8,0,124,3,0,100,2,0,131,2,0,12,114,117,0, + 116,9,0,124,0,0,106,5,0,131,1,0,100,3,0,25, + 103,1,0,124,3,0,95,10,0,110,0,0,124,3,0,83, + 87,110,46,0,1,1,1,124,2,0,12,114,163,0,124,1, + 0,116,0,0,106,1,0,107,6,0,114,163,0,116,0,0, + 106,1,0,124,1,0,61,110,0,0,130,0,0,89,110,1, + 0,88,100,4,0,83,40,5,0,0,0,117,25,0,0,0, + 76,111,97,100,32,97,110,32,101,120,116,101,110,115,105,111, + 110,32,109,111,100,117,108,101,46,117,33,0,0,0,101,120, + 116,101,110,115,105,111,110,32,109,111,100,117,108,101,32,108, + 111,97,100,101,100,32,102,114,111,109,32,123,33,114,125,117, + 8,0,0,0,95,95,112,97,116,104,95,95,105,0,0,0, + 0,78,40,11,0,0,0,117,3,0,0,0,115,121,115,117, + 7,0,0,0,109,111,100,117,108,101,115,117,25,0,0,0, + 95,99,97,108,108,95,119,105,116,104,95,102,114,97,109,101, + 115,95,114,101,109,111,118,101,100,117,4,0,0,0,95,105, + 109,112,117,12,0,0,0,108,111,97,100,95,100,121,110,97, + 109,105,99,117,4,0,0,0,112,97,116,104,117,16,0,0, + 0,95,118,101,114,98,111,115,101,95,109,101,115,115,97,103, + 101,117,10,0,0,0,105,115,95,112,97,99,107,97,103,101, + 117,7,0,0,0,104,97,115,97,116,116,114,117,11,0,0, + 0,95,112,97,116,104,95,115,112,108,105,116,117,8,0,0, + 0,95,95,112,97,116,104,95,95,40,4,0,0,0,117,4, + 0,0,0,115,101,108,102,117,8,0,0,0,102,117,108,108, + 110,97,109,101,117,9,0,0,0,105,115,95,114,101,108,111, + 97,100,117,6,0,0,0,109,111,100,117,108,101,40,0,0, + 0,0,40,0,0,0,0,117,29,0,0,0,60,102,114,111, + 122,101,110,32,105,109,112,111,114,116,108,105,98,46,95,98, + 111,111,116,115,116,114,97,112,62,117,11,0,0,0,108,111, + 97,100,95,109,111,100,117,108,101,114,4,0,0,115,24,0, + 0,0,0,5,15,1,3,1,9,1,15,1,16,1,31,1, + 28,1,8,1,3,1,22,1,13,1,117,31,0,0,0,69, + 120,116,101,110,115,105,111,110,70,105,108,101,76,111,97,100, + 101,114,46,108,111,97,100,95,109,111,100,117,108,101,99,2, + 0,0,0,0,0,0,0,2,0,0,0,4,0,0,0,3, + 0,0,0,115,48,0,0,0,116,0,0,124,0,0,106,1, + 0,131,1,0,100,1,0,25,137,0,0,116,2,0,135,0, + 0,102,1,0,100,2,0,100,3,0,134,0,0,116,3,0, + 68,131,1,0,131,1,0,83,40,4,0,0,0,117,49,0, + 0,0,82,101,116,117,114,110,32,84,114,117,101,32,105,102, + 32,116,104,101,32,101,120,116,101,110,115,105,111,110,32,109, + 111,100,117,108,101,32,105,115,32,97,32,112,97,99,107,97, + 103,101,46,105,1,0,0,0,99,1,0,0,0,0,0,0, + 0,2,0,0,0,4,0,0,0,51,0,0,0,115,31,0, + 0,0,124,0,0,93,21,0,125,1,0,136,0,0,100,0, + 0,124,1,0,23,107,2,0,86,1,113,3,0,100,1,0, + 83,40,2,0,0,0,117,8,0,0,0,95,95,105,110,105, + 116,95,95,78,40,0,0,0,0,40,2,0,0,0,117,2, + 0,0,0,46,48,117,6,0,0,0,115,117,102,102,105,120, + 40,1,0,0,0,117,9,0,0,0,102,105,108,101,95,110, + 97,109,101,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,9,0,0,0,60, + 103,101,110,101,120,112,114,62,135,4,0,0,115,2,0,0, + 0,6,1,117,49,0,0,0,69,120,116,101,110,115,105,111, + 110,70,105,108,101,76,111,97,100,101,114,46,105,115,95,112, + 97,99,107,97,103,101,46,60,108,111,99,97,108,115,62,46, + 60,103,101,110,101,120,112,114,62,40,4,0,0,0,117,11, + 0,0,0,95,112,97,116,104,95,115,112,108,105,116,117,4, + 0,0,0,112,97,116,104,117,3,0,0,0,97,110,121,117, + 18,0,0,0,69,88,84,69,78,83,73,79,78,95,83,85, + 70,70,73,88,69,83,40,2,0,0,0,117,4,0,0,0, + 115,101,108,102,117,8,0,0,0,102,117,108,108,110,97,109, + 101,40,0,0,0,0,40,1,0,0,0,117,9,0,0,0, + 102,105,108,101,95,110,97,109,101,117,29,0,0,0,60,102, + 114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46, + 95,98,111,111,116,115,116,114,97,112,62,117,10,0,0,0, + 105,115,95,112,97,99,107,97,103,101,132,4,0,0,115,6, + 0,0,0,0,2,19,1,18,1,117,30,0,0,0,69,120, + 116,101,110,115,105,111,110,70,105,108,101,76,111,97,100,101, + 114,46,105,115,95,112,97,99,107,97,103,101,99,2,0,0, 0,0,0,0,0,2,0,0,0,1,0,0,0,67,0,0, 0,115,4,0,0,0,100,1,0,83,40,2,0,0,0,117, - 39,0,0,0,82,101,116,117,114,110,32,78,111,110,101,32, - 97,115,32,116,104,101,114,101,32,105,115,32,110,111,32,115, - 111,117,114,99,101,32,99,111,100,101,46,78,114,4,0,0, - 0,40,2,0,0,0,114,75,0,0,0,114,178,0,0,0, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,114, - 220,0,0,0,102,4,0,0,115,2,0,0,0,0,2,117, - 31,0,0,0,83,111,117,114,99,101,108,101,115,115,70,105, - 108,101,76,111,97,100,101,114,46,103,101,116,95,115,111,117, - 114,99,101,40,7,0,0,0,114,56,0,0,0,114,55,0, - 0,0,114,57,0,0,0,114,58,0,0,0,114,239,0,0, - 0,114,219,0,0,0,114,220,0,0,0,114,4,0,0,0, - 114,4,0,0,0,40,1,0,0,0,114,150,0,0,0,114, - 5,0,0,0,114,7,1,0,0,88,4,0,0,115,8,0, - 0,0,12,2,6,2,18,4,12,6,114,7,1,0,0,99, - 0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0, - 64,0,0,0,115,100,0,0,0,101,0,0,90,1,0,100, - 0,0,90,2,0,100,1,0,90,3,0,100,2,0,100,3, - 0,132,0,0,90,4,0,101,5,0,101,6,0,101,7,0, - 100,4,0,100,5,0,132,0,0,131,1,0,131,1,0,131, - 1,0,90,8,0,100,6,0,100,7,0,132,0,0,90,9, - 0,100,8,0,100,9,0,132,0,0,90,10,0,100,10,0, - 100,11,0,132,0,0,90,11,0,100,12,0,83,40,13,0, - 0,0,244,19,0,0,0,69,120,116,101,110,115,105,111,110, - 70,105,108,101,76,111,97,100,101,114,117,93,0,0,0,76, - 111,97,100,101,114,32,102,111,114,32,101,120,116,101,110,115, - 105,111,110,32,109,111,100,117,108,101,115,46,10,10,32,32, - 32,32,84,104,101,32,99,111,110,115,116,114,117,99,116,111, - 114,32,105,115,32,100,101,115,105,103,110,101,100,32,116,111, - 32,119,111,114,107,32,119,105,116,104,32,70,105,108,101,70, - 105,110,100,101,114,46,10,10,32,32,32,32,99,3,0,0, - 0,0,0,0,0,3,0,0,0,2,0,0,0,67,0,0, - 0,115,22,0,0,0,124,1,0,124,0,0,95,0,0,124, - 2,0,124,0,0,95,1,0,100,0,0,83,40,1,0,0, - 0,78,40,2,0,0,0,114,71,0,0,0,114,35,0,0, - 0,40,3,0,0,0,114,75,0,0,0,114,71,0,0,0, - 114,35,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,76,0,0,0,119,4,0,0,115,4,0, - 0,0,0,1,9,1,117,28,0,0,0,69,120,116,101,110, - 115,105,111,110,70,105,108,101,76,111,97,100,101,114,46,95, - 95,105,110,105,116,95,95,99,2,0,0,0,0,0,0,0, - 3,0,0,0,11,0,0,0,67,0,0,0,115,126,0,0, - 0,116,0,0,124,1,0,131,1,0,143,108,0,1,116,1, - 0,116,2,0,106,3,0,124,1,0,124,0,0,106,4,0, - 131,3,0,125,2,0,116,5,0,100,1,0,124,0,0,106, - 4,0,131,2,0,1,124,0,0,106,6,0,124,1,0,131, - 1,0,114,112,0,116,7,0,124,2,0,100,2,0,131,2, - 0,12,114,112,0,116,8,0,124,0,0,106,4,0,131,1, - 0,100,3,0,25,103,1,0,124,2,0,95,9,0,110,0, - 0,124,2,0,83,87,100,4,0,81,88,100,4,0,83,40, - 5,0,0,0,117,25,0,0,0,76,111,97,100,32,97,110, - 32,101,120,116,101,110,115,105,111,110,32,109,111,100,117,108, - 101,46,117,33,0,0,0,101,120,116,101,110,115,105,111,110, - 32,109,111,100,117,108,101,32,108,111,97,100,101,100,32,102, - 114,111,109,32,123,33,114,125,114,159,0,0,0,114,67,0, - 0,0,78,40,10,0,0,0,114,138,0,0,0,114,99,0, - 0,0,114,94,0,0,0,116,12,0,0,0,108,111,97,100, - 95,100,121,110,97,109,105,99,114,35,0,0,0,114,137,0, - 0,0,114,156,0,0,0,114,59,0,0,0,114,38,0,0, - 0,114,159,0,0,0,40,3,0,0,0,114,75,0,0,0, - 114,178,0,0,0,114,161,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,114,218,0,0,0,123,4, - 0,0,115,14,0,0,0,0,5,13,1,9,1,15,1,16, - 1,31,1,28,1,117,31,0,0,0,69,120,116,101,110,115, - 105,111,110,70,105,108,101,76,111,97,100,101,114,46,108,111, - 97,100,95,109,111,100,117,108,101,99,2,0,0,0,0,0, - 0,0,2,0,0,0,4,0,0,0,3,0,0,0,115,48, - 0,0,0,116,0,0,124,0,0,106,1,0,131,1,0,100, - 1,0,25,137,0,0,116,2,0,135,0,0,102,1,0,100, - 2,0,100,3,0,134,0,0,116,3,0,68,131,1,0,131, - 1,0,83,40,4,0,0,0,117,49,0,0,0,82,101,116, - 117,114,110,32,84,114,117,101,32,105,102,32,116,104,101,32, + 63,0,0,0,82,101,116,117,114,110,32,78,111,110,101,32, + 97,115,32,97,110,32,101,120,116,101,110,115,105,111,110,32, + 109,111,100,117,108,101,32,99,97,110,110,111,116,32,99,114, + 101,97,116,101,32,97,32,99,111,100,101,32,111,98,106,101, + 99,116,46,78,40,0,0,0,0,40,2,0,0,0,117,4, + 0,0,0,115,101,108,102,117,8,0,0,0,102,117,108,108, + 110,97,109,101,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,8,0,0,0,103,101,116,95,99,111,100,101,138,4,0, + 0,115,2,0,0,0,0,2,117,28,0,0,0,69,120,116, + 101,110,115,105,111,110,70,105,108,101,76,111,97,100,101,114, + 46,103,101,116,95,99,111,100,101,99,2,0,0,0,0,0, + 0,0,2,0,0,0,1,0,0,0,67,0,0,0,115,4, + 0,0,0,100,1,0,83,40,2,0,0,0,117,53,0,0, + 0,82,101,116,117,114,110,32,78,111,110,101,32,97,115,32, 101,120,116,101,110,115,105,111,110,32,109,111,100,117,108,101, - 32,105,115,32,97,32,112,97,99,107,97,103,101,46,114,29, - 0,0,0,99,1,0,0,0,0,0,0,0,2,0,0,0, - 4,0,0,0,51,0,0,0,115,31,0,0,0,124,0,0, - 93,21,0,125,1,0,136,0,0,100,0,0,124,1,0,23, - 107,2,0,86,1,113,3,0,100,1,0,83,40,2,0,0, - 0,114,76,0,0,0,78,114,4,0,0,0,40,2,0,0, - 0,114,22,0,0,0,244,6,0,0,0,115,117,102,102,105, - 120,40,1,0,0,0,244,9,0,0,0,102,105,108,101,95, - 110,97,109,101,114,4,0,0,0,114,5,0,0,0,114,143, - 0,0,0,139,4,0,0,115,2,0,0,0,6,1,117,49, - 0,0,0,69,120,116,101,110,115,105,111,110,70,105,108,101, - 76,111,97,100,101,114,46,105,115,95,112,97,99,107,97,103, - 101,46,60,108,111,99,97,108,115,62,46,60,103,101,110,101, - 120,112,114,62,40,4,0,0,0,114,38,0,0,0,114,35, - 0,0,0,114,144,0,0,0,244,18,0,0,0,69,88,84, - 69,78,83,73,79,78,95,83,85,70,70,73,88,69,83,40, - 2,0,0,0,114,75,0,0,0,114,178,0,0,0,114,4, - 0,0,0,40,1,0,0,0,114,10,1,0,0,114,5,0, - 0,0,114,156,0,0,0,136,4,0,0,115,6,0,0,0, - 0,2,19,1,18,1,117,30,0,0,0,69,120,116,101,110, - 115,105,111,110,70,105,108,101,76,111,97,100,101,114,46,105, - 115,95,112,97,99,107,97,103,101,99,2,0,0,0,0,0, - 0,0,2,0,0,0,1,0,0,0,67,0,0,0,115,4, - 0,0,0,100,1,0,83,40,2,0,0,0,117,63,0,0, - 0,82,101,116,117,114,110,32,78,111,110,101,32,97,115,32, - 97,110,32,101,120,116,101,110,115,105,111,110,32,109,111,100, - 117,108,101,32,99,97,110,110,111,116,32,99,114,101,97,116, - 101,32,97,32,99,111,100,101,32,111,98,106,101,99,116,46, - 78,114,4,0,0,0,40,2,0,0,0,114,75,0,0,0, - 114,178,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,219,0,0,0,142,4,0,0,115,2,0, - 0,0,0,2,117,28,0,0,0,69,120,116,101,110,115,105, - 111,110,70,105,108,101,76,111,97,100,101,114,46,103,101,116, - 95,99,111,100,101,99,2,0,0,0,0,0,0,0,2,0, - 0,0,1,0,0,0,67,0,0,0,115,4,0,0,0,100, - 1,0,83,40,2,0,0,0,117,53,0,0,0,82,101,116, - 117,114,110,32,78,111,110,101,32,97,115,32,101,120,116,101, - 110,115,105,111,110,32,109,111,100,117,108,101,115,32,104,97, - 118,101,32,110,111,32,115,111,117,114,99,101,32,99,111,100, - 101,46,78,114,4,0,0,0,40,2,0,0,0,114,75,0, - 0,0,114,178,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,5,0,0,0,114,220,0,0,0,146,4,0,0,115, - 2,0,0,0,0,2,117,30,0,0,0,69,120,116,101,110, - 115,105,111,110,70,105,108,101,76,111,97,100,101,114,46,103, - 101,116,95,115,111,117,114,99,101,78,40,12,0,0,0,114, - 56,0,0,0,114,55,0,0,0,114,57,0,0,0,114,58, - 0,0,0,114,76,0,0,0,114,176,0,0,0,114,170,0, - 0,0,114,173,0,0,0,114,218,0,0,0,114,156,0,0, - 0,114,219,0,0,0,114,220,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,114, - 8,1,0,0,111,4,0,0,115,16,0,0,0,12,6,6, - 2,12,4,3,1,3,1,24,11,12,6,12,4,114,8,1, - 0,0,99,0,0,0,0,0,0,0,0,0,0,0,0,2, - 0,0,0,64,0,0,0,115,130,0,0,0,101,0,0,90, - 1,0,100,0,0,90,2,0,100,1,0,90,3,0,100,2, - 0,100,3,0,132,0,0,90,4,0,100,4,0,100,5,0, - 132,0,0,90,5,0,100,6,0,100,7,0,132,0,0,90, - 6,0,100,8,0,100,9,0,132,0,0,90,7,0,100,10, - 0,100,11,0,132,0,0,90,8,0,100,12,0,100,13,0, - 132,0,0,90,9,0,100,14,0,100,15,0,132,0,0,90, - 10,0,100,16,0,100,17,0,132,0,0,90,11,0,100,18, - 0,100,19,0,132,0,0,90,12,0,100,20,0,83,40,21, - 0,0,0,244,14,0,0,0,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,117,38,1,0,0,82,101,112,114,101, - 115,101,110,116,115,32,97,32,110,97,109,101,115,112,97,99, - 101,32,112,97,99,107,97,103,101,39,115,32,112,97,116,104, - 46,32,32,73,116,32,117,115,101,115,32,116,104,101,32,109, - 111,100,117,108,101,32,110,97,109,101,10,32,32,32,32,116, - 111,32,102,105,110,100,32,105,116,115,32,112,97,114,101,110, - 116,32,109,111,100,117,108,101,44,32,97,110,100,32,102,114, - 111,109,32,116,104,101,114,101,32,105,116,32,108,111,111,107, - 115,32,117,112,32,116,104,101,32,112,97,114,101,110,116,39, - 115,10,32,32,32,32,95,95,112,97,116,104,95,95,46,32, - 32,87,104,101,110,32,116,104,105,115,32,99,104,97,110,103, - 101,115,44,32,116,104,101,32,109,111,100,117,108,101,39,115, - 32,111,119,110,32,112,97,116,104,32,105,115,32,114,101,99, - 111,109,112,117,116,101,100,44,10,32,32,32,32,117,115,105, - 110,103,32,112,97,116,104,95,102,105,110,100,101,114,46,32, - 32,70,111,114,32,116,111,112,45,108,101,118,101,108,32,109, - 111,100,117,108,101,115,44,32,116,104,101,32,112,97,114,101, - 110,116,32,109,111,100,117,108,101,39,115,32,112,97,116,104, - 10,32,32,32,32,105,115,32,115,121,115,46,112,97,116,104, - 46,99,4,0,0,0,0,0,0,0,4,0,0,0,2,0, - 0,0,67,0,0,0,115,52,0,0,0,124,1,0,124,0, - 0,95,0,0,124,2,0,124,0,0,95,1,0,116,2,0, - 124,0,0,106,3,0,131,0,0,131,1,0,124,0,0,95, - 4,0,124,3,0,124,0,0,95,5,0,100,0,0,83,40, - 1,0,0,0,78,40,6,0,0,0,114,139,0,0,0,244, - 5,0,0,0,95,112,97,116,104,114,236,0,0,0,244,16, - 0,0,0,95,103,101,116,95,112,97,114,101,110,116,95,112, - 97,116,104,244,17,0,0,0,95,108,97,115,116,95,112,97, - 114,101,110,116,95,112,97,116,104,244,12,0,0,0,95,112, - 97,116,104,95,102,105,110,100,101,114,40,4,0,0,0,114, - 75,0,0,0,114,71,0,0,0,114,35,0,0,0,244,11, - 0,0,0,112,97,116,104,95,102,105,110,100,101,114,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,114,76,0, - 0,0,158,4,0,0,115,8,0,0,0,0,1,9,1,9, - 1,21,1,117,23,0,0,0,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,46,95,95,105,110,105,116,95,95,99, - 1,0,0,0,0,0,0,0,4,0,0,0,3,0,0,0, - 67,0,0,0,115,53,0,0,0,124,0,0,106,0,0,106, - 1,0,100,1,0,131,1,0,92,3,0,125,1,0,125,2, - 0,125,3,0,124,2,0,100,2,0,107,2,0,114,43,0, - 100,6,0,83,124,1,0,100,5,0,102,2,0,83,40,7, - 0,0,0,117,62,0,0,0,82,101,116,117,114,110,115,32, - 97,32,116,117,112,108,101,32,111,102,32,40,112,97,114,101, - 110,116,45,109,111,100,117,108,101,45,110,97,109,101,44,32, - 112,97,114,101,110,116,45,112,97,116,104,45,97,116,116,114, - 45,110,97,109,101,41,114,101,0,0,0,114,30,0,0,0, - 114,7,0,0,0,114,35,0,0,0,114,159,0,0,0,40, - 2,0,0,0,117,3,0,0,0,115,121,115,117,4,0,0, - 0,112,97,116,104,40,2,0,0,0,114,139,0,0,0,114, - 32,0,0,0,40,4,0,0,0,114,75,0,0,0,114,6, - 1,0,0,244,3,0,0,0,100,111,116,114,80,0,0,0, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,244, - 23,0,0,0,95,102,105,110,100,95,112,97,114,101,110,116, - 95,112,97,116,104,95,110,97,109,101,115,164,4,0,0,115, - 8,0,0,0,0,2,27,1,12,2,4,3,117,38,0,0, - 0,95,78,97,109,101,115,112,97,99,101,80,97,116,104,46, - 95,102,105,110,100,95,112,97,114,101,110,116,95,112,97,116, - 104,95,110,97,109,101,115,99,1,0,0,0,0,0,0,0, - 3,0,0,0,3,0,0,0,67,0,0,0,115,38,0,0, - 0,124,0,0,106,0,0,131,0,0,92,2,0,125,1,0, - 125,2,0,116,1,0,116,2,0,106,3,0,124,1,0,25, - 124,2,0,131,2,0,83,40,1,0,0,0,78,40,4,0, - 0,0,114,19,1,0,0,114,61,0,0,0,114,7,0,0, - 0,114,140,0,0,0,40,3,0,0,0,114,75,0,0,0, - 116,18,0,0,0,112,97,114,101,110,116,95,109,111,100,117, - 108,101,95,110,97,109,101,116,14,0,0,0,112,97,116,104, - 95,97,116,116,114,95,110,97,109,101,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,114,14,1,0,0,174,4, - 0,0,115,4,0,0,0,0,1,18,1,117,31,0,0,0, - 95,78,97,109,101,115,112,97,99,101,80,97,116,104,46,95, - 103,101,116,95,112,97,114,101,110,116,95,112,97,116,104,99, - 1,0,0,0,0,0,0,0,4,0,0,0,3,0,0,0, - 67,0,0,0,115,103,0,0,0,116,0,0,124,0,0,106, - 1,0,131,0,0,131,1,0,125,1,0,124,1,0,124,0, - 0,106,2,0,107,3,0,114,96,0,124,0,0,106,3,0, - 124,0,0,106,4,0,124,1,0,131,2,0,92,2,0,125, - 2,0,125,3,0,124,2,0,100,0,0,107,8,0,114,84, - 0,124,3,0,124,0,0,95,5,0,110,0,0,124,1,0, - 124,0,0,95,2,0,110,0,0,124,0,0,106,5,0,83, - 40,1,0,0,0,78,40,6,0,0,0,114,236,0,0,0, - 114,14,1,0,0,114,15,1,0,0,114,16,1,0,0,114, - 139,0,0,0,114,13,1,0,0,40,4,0,0,0,114,75, - 0,0,0,116,11,0,0,0,112,97,114,101,110,116,95,112, - 97,116,104,114,160,0,0,0,116,8,0,0,0,110,101,119, - 95,112,97,116,104,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,244,12,0,0,0,95,114,101,99,97,108,99, - 117,108,97,116,101,178,4,0,0,115,14,0,0,0,0,2, + 115,32,104,97,118,101,32,110,111,32,115,111,117,114,99,101, + 32,99,111,100,101,46,78,40,0,0,0,0,40,2,0,0, + 0,117,4,0,0,0,115,101,108,102,117,8,0,0,0,102, + 117,108,108,110,97,109,101,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,10,0,0,0,103,101,116,95,115,111,117,114, + 99,101,142,4,0,0,115,2,0,0,0,0,2,117,30,0, + 0,0,69,120,116,101,110,115,105,111,110,70,105,108,101,76, + 111,97,100,101,114,46,103,101,116,95,115,111,117,114,99,101, + 78,40,12,0,0,0,117,8,0,0,0,95,95,110,97,109, + 101,95,95,117,10,0,0,0,95,95,109,111,100,117,108,101, + 95,95,117,12,0,0,0,95,95,113,117,97,108,110,97,109, + 101,95,95,117,7,0,0,0,95,95,100,111,99,95,95,117, + 8,0,0,0,95,95,105,110,105,116,95,95,117,11,0,0, + 0,95,99,104,101,99,107,95,110,97,109,101,117,11,0,0, + 0,115,101,116,95,112,97,99,107,97,103,101,117,10,0,0, + 0,115,101,116,95,108,111,97,100,101,114,117,11,0,0,0, + 108,111,97,100,95,109,111,100,117,108,101,117,10,0,0,0, + 105,115,95,112,97,99,107,97,103,101,117,8,0,0,0,103, + 101,116,95,99,111,100,101,117,10,0,0,0,103,101,116,95, + 115,111,117,114,99,101,40,1,0,0,0,117,10,0,0,0, + 95,95,108,111,99,97,108,115,95,95,40,0,0,0,0,40, + 0,0,0,0,117,29,0,0,0,60,102,114,111,122,101,110, + 32,105,109,112,111,114,116,108,105,98,46,95,98,111,111,116, + 115,116,114,97,112,62,117,19,0,0,0,69,120,116,101,110, + 115,105,111,110,70,105,108,101,76,111,97,100,101,114,102,4, + 0,0,115,16,0,0,0,16,6,6,2,12,4,3,1,3, + 1,24,16,12,6,12,4,117,19,0,0,0,69,120,116,101, + 110,115,105,111,110,70,105,108,101,76,111,97,100,101,114,99, + 1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0, + 66,0,0,0,115,134,0,0,0,124,0,0,69,101,0,0, + 90,1,0,100,0,0,90,2,0,100,1,0,90,3,0,100, + 2,0,100,3,0,132,0,0,90,4,0,100,4,0,100,5, + 0,132,0,0,90,5,0,100,6,0,100,7,0,132,0,0, + 90,6,0,100,8,0,100,9,0,132,0,0,90,7,0,100, + 10,0,100,11,0,132,0,0,90,8,0,100,12,0,100,13, + 0,132,0,0,90,9,0,100,14,0,100,15,0,132,0,0, + 90,10,0,100,16,0,100,17,0,132,0,0,90,11,0,100, + 18,0,100,19,0,132,0,0,90,12,0,100,20,0,83,40, + 21,0,0,0,117,14,0,0,0,95,78,97,109,101,115,112, + 97,99,101,80,97,116,104,117,38,1,0,0,82,101,112,114, + 101,115,101,110,116,115,32,97,32,110,97,109,101,115,112,97, + 99,101,32,112,97,99,107,97,103,101,39,115,32,112,97,116, + 104,46,32,32,73,116,32,117,115,101,115,32,116,104,101,32, + 109,111,100,117,108,101,32,110,97,109,101,10,32,32,32,32, + 116,111,32,102,105,110,100,32,105,116,115,32,112,97,114,101, + 110,116,32,109,111,100,117,108,101,44,32,97,110,100,32,102, + 114,111,109,32,116,104,101,114,101,32,105,116,32,108,111,111, + 107,115,32,117,112,32,116,104,101,32,112,97,114,101,110,116, + 39,115,10,32,32,32,32,95,95,112,97,116,104,95,95,46, + 32,32,87,104,101,110,32,116,104,105,115,32,99,104,97,110, + 103,101,115,44,32,116,104,101,32,109,111,100,117,108,101,39, + 115,32,111,119,110,32,112,97,116,104,32,105,115,32,114,101, + 99,111,109,112,117,116,101,100,44,10,32,32,32,32,117,115, + 105,110,103,32,112,97,116,104,95,102,105,110,100,101,114,46, + 32,32,70,111,114,32,116,111,112,45,108,101,118,101,108,32, + 109,111,100,117,108,101,115,44,32,116,104,101,32,112,97,114, + 101,110,116,32,109,111,100,117,108,101,39,115,32,112,97,116, + 104,10,32,32,32,32,105,115,32,115,121,115,46,112,97,116, + 104,46,99,4,0,0,0,0,0,0,0,4,0,0,0,2, + 0,0,0,67,0,0,0,115,52,0,0,0,124,1,0,124, + 0,0,95,0,0,124,2,0,124,0,0,95,1,0,116,2, + 0,124,0,0,106,3,0,131,0,0,131,1,0,124,0,0, + 95,4,0,124,3,0,124,0,0,95,5,0,100,0,0,83, + 40,1,0,0,0,78,40,6,0,0,0,117,5,0,0,0, + 95,110,97,109,101,117,5,0,0,0,95,112,97,116,104,117, + 5,0,0,0,116,117,112,108,101,117,16,0,0,0,95,103, + 101,116,95,112,97,114,101,110,116,95,112,97,116,104,117,17, + 0,0,0,95,108,97,115,116,95,112,97,114,101,110,116,95, + 112,97,116,104,117,12,0,0,0,95,112,97,116,104,95,102, + 105,110,100,101,114,40,4,0,0,0,117,4,0,0,0,115, + 101,108,102,117,4,0,0,0,110,97,109,101,117,4,0,0, + 0,112,97,116,104,117,11,0,0,0,112,97,116,104,95,102, + 105,110,100,101,114,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,8,0,0,0,95,95,105,110,105,116,95,95,154,4, + 0,0,115,8,0,0,0,0,1,9,1,9,1,21,1,117, + 23,0,0,0,95,78,97,109,101,115,112,97,99,101,80,97, + 116,104,46,95,95,105,110,105,116,95,95,99,1,0,0,0, + 0,0,0,0,4,0,0,0,3,0,0,0,67,0,0,0, + 115,53,0,0,0,124,0,0,106,0,0,106,1,0,100,1, + 0,131,1,0,92,3,0,125,1,0,125,2,0,125,3,0, + 124,2,0,100,2,0,107,2,0,114,43,0,100,6,0,83, + 124,1,0,100,5,0,102,2,0,83,40,7,0,0,0,117, + 62,0,0,0,82,101,116,117,114,110,115,32,97,32,116,117, + 112,108,101,32,111,102,32,40,112,97,114,101,110,116,45,109, + 111,100,117,108,101,45,110,97,109,101,44,32,112,97,114,101, + 110,116,45,112,97,116,104,45,97,116,116,114,45,110,97,109, + 101,41,117,1,0,0,0,46,117,0,0,0,0,117,3,0, + 0,0,115,121,115,117,4,0,0,0,112,97,116,104,117,8, + 0,0,0,95,95,112,97,116,104,95,95,40,2,0,0,0, + 117,3,0,0,0,115,121,115,117,4,0,0,0,112,97,116, + 104,40,2,0,0,0,117,5,0,0,0,95,110,97,109,101, + 117,10,0,0,0,114,112,97,114,116,105,116,105,111,110,40, + 4,0,0,0,117,4,0,0,0,115,101,108,102,117,6,0, + 0,0,112,97,114,101,110,116,117,3,0,0,0,100,111,116, + 117,2,0,0,0,109,101,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,23,0,0,0,95,102,105,110,100,95,112,97, + 114,101,110,116,95,112,97,116,104,95,110,97,109,101,115,160, + 4,0,0,115,8,0,0,0,0,2,27,1,12,2,4,3, + 117,38,0,0,0,95,78,97,109,101,115,112,97,99,101,80, + 97,116,104,46,95,102,105,110,100,95,112,97,114,101,110,116, + 95,112,97,116,104,95,110,97,109,101,115,99,1,0,0,0, + 0,0,0,0,3,0,0,0,3,0,0,0,67,0,0,0, + 115,38,0,0,0,124,0,0,106,0,0,131,0,0,92,2, + 0,125,1,0,125,2,0,116,1,0,116,2,0,106,3,0, + 124,1,0,25,124,2,0,131,2,0,83,40,1,0,0,0, + 78,40,4,0,0,0,117,23,0,0,0,95,102,105,110,100, + 95,112,97,114,101,110,116,95,112,97,116,104,95,110,97,109, + 101,115,117,7,0,0,0,103,101,116,97,116,116,114,117,3, + 0,0,0,115,121,115,117,7,0,0,0,109,111,100,117,108, + 101,115,40,3,0,0,0,117,4,0,0,0,115,101,108,102, + 117,18,0,0,0,112,97,114,101,110,116,95,109,111,100,117, + 108,101,95,110,97,109,101,117,14,0,0,0,112,97,116,104, + 95,97,116,116,114,95,110,97,109,101,40,0,0,0,0,40, + 0,0,0,0,117,29,0,0,0,60,102,114,111,122,101,110, + 32,105,109,112,111,114,116,108,105,98,46,95,98,111,111,116, + 115,116,114,97,112,62,117,16,0,0,0,95,103,101,116,95, + 112,97,114,101,110,116,95,112,97,116,104,170,4,0,0,115, + 4,0,0,0,0,1,18,1,117,31,0,0,0,95,78,97, + 109,101,115,112,97,99,101,80,97,116,104,46,95,103,101,116, + 95,112,97,114,101,110,116,95,112,97,116,104,99,1,0,0, + 0,0,0,0,0,4,0,0,0,3,0,0,0,67,0,0, + 0,115,103,0,0,0,116,0,0,124,0,0,106,1,0,131, + 0,0,131,1,0,125,1,0,124,1,0,124,0,0,106,2, + 0,107,3,0,114,96,0,124,0,0,106,3,0,124,0,0, + 106,4,0,124,1,0,131,2,0,92,2,0,125,2,0,125, + 3,0,124,2,0,100,0,0,107,8,0,114,84,0,124,3, + 0,124,0,0,95,5,0,110,0,0,124,1,0,124,0,0, + 95,2,0,110,0,0,124,0,0,106,5,0,83,40,1,0, + 0,0,78,40,6,0,0,0,117,5,0,0,0,116,117,112, + 108,101,117,16,0,0,0,95,103,101,116,95,112,97,114,101, + 110,116,95,112,97,116,104,117,17,0,0,0,95,108,97,115, + 116,95,112,97,114,101,110,116,95,112,97,116,104,117,12,0, + 0,0,95,112,97,116,104,95,102,105,110,100,101,114,117,5, + 0,0,0,95,110,97,109,101,117,5,0,0,0,95,112,97, + 116,104,40,4,0,0,0,117,4,0,0,0,115,101,108,102, + 117,11,0,0,0,112,97,114,101,110,116,95,112,97,116,104, + 117,6,0,0,0,108,111,97,100,101,114,117,8,0,0,0, + 110,101,119,95,112,97,116,104,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,12,0,0,0,95,114,101,99,97,108,99, + 117,108,97,116,101,174,4,0,0,115,14,0,0,0,0,2, 18,1,15,1,27,3,12,1,12,1,12,1,117,27,0,0, 0,95,78,97,109,101,115,112,97,99,101,80,97,116,104,46, 95,114,101,99,97,108,99,117,108,97,116,101,99,1,0,0, 0,0,0,0,0,1,0,0,0,2,0,0,0,67,0,0, 0,115,16,0,0,0,116,0,0,124,0,0,106,1,0,131, 0,0,131,1,0,83,40,1,0,0,0,78,40,2,0,0, - 0,244,4,0,0,0,105,116,101,114,114,20,1,0,0,40, - 1,0,0,0,114,75,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,244,8,0,0,0,95,95,105, - 116,101,114,95,95,190,4,0,0,115,2,0,0,0,0,1, - 117,23,0,0,0,95,78,97,109,101,115,112,97,99,101,80, - 97,116,104,46,95,95,105,116,101,114,95,95,99,1,0,0, - 0,0,0,0,0,1,0,0,0,2,0,0,0,67,0,0, - 0,115,16,0,0,0,116,0,0,124,0,0,106,1,0,131, - 0,0,131,1,0,83,40,1,0,0,0,78,40,2,0,0, - 0,114,31,0,0,0,114,20,1,0,0,40,1,0,0,0, - 114,75,0,0,0,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,244,7,0,0,0,95,95,108,101,110,95,95, - 193,4,0,0,115,2,0,0,0,0,1,117,22,0,0,0, - 95,78,97,109,101,115,112,97,99,101,80,97,116,104,46,95, - 95,108,101,110,95,95,99,1,0,0,0,0,0,0,0,1, - 0,0,0,2,0,0,0,67,0,0,0,115,16,0,0,0, - 100,1,0,106,0,0,124,0,0,106,1,0,131,1,0,83, - 40,2,0,0,0,78,117,20,0,0,0,95,78,97,109,101, - 115,112,97,99,101,80,97,116,104,40,123,33,114,125,41,40, - 2,0,0,0,114,46,0,0,0,114,13,1,0,0,40,1, - 0,0,0,114,75,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,114,87,0,0,0,196,4,0,0, - 115,2,0,0,0,0,1,117,23,0,0,0,95,78,97,109, - 101,115,112,97,99,101,80,97,116,104,46,95,95,114,101,112, - 114,95,95,99,2,0,0,0,0,0,0,0,2,0,0,0, - 2,0,0,0,67,0,0,0,115,16,0,0,0,124,1,0, - 124,0,0,106,0,0,131,0,0,107,6,0,83,40,1,0, - 0,0,78,40,1,0,0,0,114,20,1,0,0,40,2,0, - 0,0,114,75,0,0,0,244,4,0,0,0,105,116,101,109, - 114,4,0,0,0,114,4,0,0,0,114,5,0,0,0,244, - 12,0,0,0,95,95,99,111,110,116,97,105,110,115,95,95, - 199,4,0,0,115,2,0,0,0,0,1,117,27,0,0,0, - 95,78,97,109,101,115,112,97,99,101,80,97,116,104,46,95, - 95,99,111,110,116,97,105,110,115,95,95,99,2,0,0,0, - 0,0,0,0,2,0,0,0,2,0,0,0,67,0,0,0, - 115,20,0,0,0,124,0,0,106,0,0,106,1,0,124,1, - 0,131,1,0,1,100,0,0,83,40,1,0,0,0,78,40, - 2,0,0,0,114,13,1,0,0,114,165,0,0,0,40,2, - 0,0,0,114,75,0,0,0,114,24,1,0,0,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,114,165,0,0, - 0,202,4,0,0,115,2,0,0,0,0,1,117,21,0,0, - 0,95,78,97,109,101,115,112,97,99,101,80,97,116,104,46, - 97,112,112,101,110,100,78,40,13,0,0,0,114,56,0,0, - 0,114,55,0,0,0,114,57,0,0,0,114,58,0,0,0, - 114,76,0,0,0,114,19,1,0,0,114,14,1,0,0,114, - 20,1,0,0,114,22,1,0,0,114,23,1,0,0,114,87, - 0,0,0,114,25,1,0,0,114,165,0,0,0,114,4,0, - 0,0,114,4,0,0,0,114,4,0,0,0,114,5,0,0, - 0,114,12,1,0,0,151,4,0,0,115,20,0,0,0,12, - 5,6,2,12,6,12,10,12,4,12,12,12,3,12,3,12, - 3,12,3,114,12,1,0,0,99,0,0,0,0,0,0,0, - 0,0,0,0,0,3,0,0,0,64,0,0,0,115,106,0, - 0,0,101,0,0,90,1,0,100,0,0,90,2,0,100,1, - 0,100,2,0,132,0,0,90,3,0,101,4,0,100,3,0, - 100,4,0,132,0,0,131,1,0,90,5,0,100,5,0,100, - 6,0,132,0,0,90,6,0,100,7,0,100,8,0,132,0, - 0,90,7,0,100,9,0,100,10,0,132,0,0,90,8,0, - 100,11,0,100,12,0,132,0,0,90,9,0,100,13,0,100, - 14,0,132,0,0,90,10,0,100,15,0,83,40,16,0,0, - 0,244,15,0,0,0,78,97,109,101,115,112,97,99,101,76, - 111,97,100,101,114,99,4,0,0,0,0,0,0,0,4,0, - 0,0,4,0,0,0,67,0,0,0,115,25,0,0,0,116, - 0,0,124,1,0,124,2,0,124,3,0,131,3,0,124,0, - 0,95,1,0,100,0,0,83,40,1,0,0,0,78,40,2, - 0,0,0,114,12,1,0,0,114,13,1,0,0,40,4,0, - 0,0,114,75,0,0,0,114,71,0,0,0,114,35,0,0, - 0,114,17,1,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,76,0,0,0,207,4,0,0,115,2, - 0,0,0,0,1,117,24,0,0,0,78,97,109,101,115,112, - 97,99,101,76,111,97,100,101,114,46,95,95,105,110,105,116, - 95,95,99,2,0,0,0,0,0,0,0,2,0,0,0,2, - 0,0,0,67,0,0,0,115,16,0,0,0,100,1,0,106, - 0,0,124,1,0,106,1,0,131,1,0,83,40,2,0,0, - 0,78,117,25,0,0,0,60,109,111,100,117,108,101,32,123, - 33,114,125,32,40,110,97,109,101,115,112,97,99,101,41,62, - 40,2,0,0,0,114,46,0,0,0,114,56,0,0,0,40, - 2,0,0,0,114,215,0,0,0,114,161,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,114,216,0, - 0,0,210,4,0,0,115,2,0,0,0,0,2,117,27,0, - 0,0,78,97,109,101,115,112,97,99,101,76,111,97,100,101, - 114,46,109,111,100,117,108,101,95,114,101,112,114,99,2,0, - 0,0,0,0,0,0,2,0,0,0,1,0,0,0,67,0, - 0,0,115,4,0,0,0,100,1,0,83,40,2,0,0,0, - 78,84,114,4,0,0,0,40,2,0,0,0,114,75,0,0, - 0,114,178,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,114,156,0,0,0,214,4,0,0,115,2, - 0,0,0,0,1,117,26,0,0,0,78,97,109,101,115,112, - 97,99,101,76,111,97,100,101,114,46,105,115,95,112,97,99, - 107,97,103,101,99,2,0,0,0,0,0,0,0,2,0,0, - 0,1,0,0,0,67,0,0,0,115,4,0,0,0,100,1, - 0,83,40,2,0,0,0,78,114,30,0,0,0,114,4,0, - 0,0,40,2,0,0,0,114,75,0,0,0,114,178,0,0, - 0,114,4,0,0,0,114,4,0,0,0,114,5,0,0,0, - 114,220,0,0,0,217,4,0,0,115,2,0,0,0,0,1, - 117,26,0,0,0,78,97,109,101,115,112,97,99,101,76,111, - 97,100,101,114,46,103,101,116,95,115,111,117,114,99,101,99, - 2,0,0,0,0,0,0,0,2,0,0,0,6,0,0,0, - 67,0,0,0,115,22,0,0,0,116,0,0,100,1,0,100, - 2,0,100,3,0,100,4,0,100,5,0,131,3,1,83,40, - 6,0,0,0,78,114,30,0,0,0,117,8,0,0,0,60, - 115,116,114,105,110,103,62,114,240,0,0,0,114,250,0,0, - 0,84,40,1,0,0,0,114,251,0,0,0,40,2,0,0, - 0,114,75,0,0,0,114,178,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,219,0,0,0,220, - 4,0,0,115,2,0,0,0,0,1,117,24,0,0,0,78, - 97,109,101,115,112,97,99,101,76,111,97,100,101,114,46,103, - 101,116,95,99,111,100,101,99,2,0,0,0,0,0,0,0, - 2,0,0,0,2,0,0,0,67,0,0,0,115,25,0,0, - 0,124,0,0,124,1,0,95,0,0,124,1,0,106,1,0, - 124,1,0,95,2,0,100,0,0,83,40,1,0,0,0,78, - 40,3,0,0,0,114,171,0,0,0,114,56,0,0,0,114, - 158,0,0,0,40,2,0,0,0,114,75,0,0,0,114,161, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,239,0,0,0,223,4,0,0,115,4,0,0,0, - 0,1,9,1,117,33,0,0,0,78,97,109,101,115,112,97, - 99,101,76,111,97,100,101,114,46,105,110,105,116,95,109,111, - 100,117,108,101,95,97,116,116,114,115,99,2,0,0,0,0, - 0,0,0,3,0,0,0,9,0,0,0,67,0,0,0,115, - 70,0,0,0,116,0,0,100,1,0,124,0,0,106,1,0, - 131,2,0,1,116,2,0,124,1,0,131,1,0,143,36,0, - 125,2,0,124,0,0,106,3,0,124,2,0,131,1,0,1, - 124,0,0,106,1,0,124,2,0,95,4,0,124,2,0,83, - 87,100,2,0,81,88,100,2,0,83,40,3,0,0,0,117, - 24,0,0,0,76,111,97,100,32,97,32,110,97,109,101,115, - 112,97,99,101,32,109,111,100,117,108,101,46,117,38,0,0, - 0,110,97,109,101,115,112,97,99,101,32,109,111,100,117,108, - 101,32,108,111,97,100,101,100,32,119,105,116,104,32,112,97, - 116,104,32,123,33,114,125,78,40,5,0,0,0,114,137,0, - 0,0,114,13,1,0,0,114,155,0,0,0,114,239,0,0, - 0,114,159,0,0,0,40,3,0,0,0,114,75,0,0,0, - 114,178,0,0,0,114,161,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,114,218,0,0,0,227,4, - 0,0,115,10,0,0,0,0,2,16,1,15,1,13,1,12, - 1,117,27,0,0,0,78,97,109,101,115,112,97,99,101,76, - 111,97,100,101,114,46,108,111,97,100,95,109,111,100,117,108, - 101,78,40,11,0,0,0,114,56,0,0,0,114,55,0,0, - 0,114,57,0,0,0,114,76,0,0,0,114,221,0,0,0, - 114,216,0,0,0,114,156,0,0,0,114,220,0,0,0,114, - 219,0,0,0,114,239,0,0,0,114,218,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,26,1,0,0,206,4,0,0,115,14,0,0,0, - 12,1,12,3,18,4,12,3,12,3,12,3,12,4,114,26, - 1,0,0,99,0,0,0,0,0,0,0,0,0,0,0,0, - 4,0,0,0,64,0,0,0,115,115,0,0,0,101,0,0, - 90,1,0,100,0,0,90,2,0,100,1,0,90,3,0,101, - 4,0,100,2,0,100,3,0,132,0,0,131,1,0,90,5, - 0,101,4,0,100,4,0,100,5,0,132,0,0,131,1,0, - 90,6,0,101,4,0,100,6,0,100,7,0,132,0,0,131, - 1,0,90,7,0,101,4,0,100,8,0,100,9,0,132,0, - 0,131,1,0,90,8,0,101,4,0,100,10,0,100,11,0, - 100,12,0,132,1,0,131,1,0,90,9,0,100,10,0,83, - 40,13,0,0,0,244,10,0,0,0,80,97,116,104,70,105, - 110,100,101,114,117,62,0,0,0,77,101,116,97,32,112,97, - 116,104,32,102,105,110,100,101,114,32,102,111,114,32,115,121, - 115,46,112,97,116,104,32,97,110,100,32,112,97,99,107,97, - 103,101,32,95,95,112,97,116,104,95,95,32,97,116,116,114, - 105,98,117,116,101,115,46,99,1,0,0,0,0,0,0,0, - 2,0,0,0,4,0,0,0,67,0,0,0,115,58,0,0, - 0,120,51,0,116,0,0,106,1,0,106,2,0,131,0,0, - 68,93,34,0,125,1,0,116,3,0,124,1,0,100,1,0, - 131,2,0,114,16,0,124,1,0,106,4,0,131,0,0,1, - 113,16,0,113,16,0,87,100,2,0,83,40,3,0,0,0, - 117,125,0,0,0,67,97,108,108,32,116,104,101,32,105,110, + 0,117,4,0,0,0,105,116,101,114,117,12,0,0,0,95, + 114,101,99,97,108,99,117,108,97,116,101,40,1,0,0,0, + 117,4,0,0,0,115,101,108,102,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,8,0,0,0,95,95,105,116,101,114, + 95,95,186,4,0,0,115,2,0,0,0,0,1,117,23,0, + 0,0,95,78,97,109,101,115,112,97,99,101,80,97,116,104, + 46,95,95,105,116,101,114,95,95,99,1,0,0,0,0,0, + 0,0,1,0,0,0,2,0,0,0,67,0,0,0,115,16, + 0,0,0,116,0,0,124,0,0,106,1,0,131,0,0,131, + 1,0,83,40,1,0,0,0,78,40,2,0,0,0,117,3, + 0,0,0,108,101,110,117,12,0,0,0,95,114,101,99,97, + 108,99,117,108,97,116,101,40,1,0,0,0,117,4,0,0, + 0,115,101,108,102,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,7,0,0,0,95,95,108,101,110,95,95,189,4,0, + 0,115,2,0,0,0,0,1,117,22,0,0,0,95,78,97, + 109,101,115,112,97,99,101,80,97,116,104,46,95,95,108,101, + 110,95,95,99,1,0,0,0,0,0,0,0,1,0,0,0, + 2,0,0,0,67,0,0,0,115,16,0,0,0,100,1,0, + 106,0,0,124,0,0,106,1,0,131,1,0,83,40,2,0, + 0,0,78,117,20,0,0,0,95,78,97,109,101,115,112,97, + 99,101,80,97,116,104,40,123,33,114,125,41,40,2,0,0, + 0,117,6,0,0,0,102,111,114,109,97,116,117,5,0,0, + 0,95,112,97,116,104,40,1,0,0,0,117,4,0,0,0, + 115,101,108,102,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,8,0,0,0,95,95,114,101,112,114,95,95,192,4,0, + 0,115,2,0,0,0,0,1,117,23,0,0,0,95,78,97, + 109,101,115,112,97,99,101,80,97,116,104,46,95,95,114,101, + 112,114,95,95,99,2,0,0,0,0,0,0,0,2,0,0, + 0,2,0,0,0,67,0,0,0,115,16,0,0,0,124,1, + 0,124,0,0,106,0,0,131,0,0,107,6,0,83,40,1, + 0,0,0,78,40,1,0,0,0,117,12,0,0,0,95,114, + 101,99,97,108,99,117,108,97,116,101,40,2,0,0,0,117, + 4,0,0,0,115,101,108,102,117,4,0,0,0,105,116,101, + 109,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,12,0, + 0,0,95,95,99,111,110,116,97,105,110,115,95,95,195,4, + 0,0,115,2,0,0,0,0,1,117,27,0,0,0,95,78, + 97,109,101,115,112,97,99,101,80,97,116,104,46,95,95,99, + 111,110,116,97,105,110,115,95,95,99,2,0,0,0,0,0, + 0,0,2,0,0,0,2,0,0,0,67,0,0,0,115,20, + 0,0,0,124,0,0,106,0,0,106,1,0,124,1,0,131, + 1,0,1,100,0,0,83,40,1,0,0,0,78,40,2,0, + 0,0,117,5,0,0,0,95,112,97,116,104,117,6,0,0, + 0,97,112,112,101,110,100,40,2,0,0,0,117,4,0,0, + 0,115,101,108,102,117,4,0,0,0,105,116,101,109,40,0, + 0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,6,0,0,0,97, + 112,112,101,110,100,198,4,0,0,115,2,0,0,0,0,1, + 117,21,0,0,0,95,78,97,109,101,115,112,97,99,101,80, + 97,116,104,46,97,112,112,101,110,100,78,40,13,0,0,0, + 117,8,0,0,0,95,95,110,97,109,101,95,95,117,10,0, + 0,0,95,95,109,111,100,117,108,101,95,95,117,12,0,0, + 0,95,95,113,117,97,108,110,97,109,101,95,95,117,7,0, + 0,0,95,95,100,111,99,95,95,117,8,0,0,0,95,95, + 105,110,105,116,95,95,117,23,0,0,0,95,102,105,110,100, + 95,112,97,114,101,110,116,95,112,97,116,104,95,110,97,109, + 101,115,117,16,0,0,0,95,103,101,116,95,112,97,114,101, + 110,116,95,112,97,116,104,117,12,0,0,0,95,114,101,99, + 97,108,99,117,108,97,116,101,117,8,0,0,0,95,95,105, + 116,101,114,95,95,117,7,0,0,0,95,95,108,101,110,95, + 95,117,8,0,0,0,95,95,114,101,112,114,95,95,117,12, + 0,0,0,95,95,99,111,110,116,97,105,110,115,95,95,117, + 6,0,0,0,97,112,112,101,110,100,40,1,0,0,0,117, + 10,0,0,0,95,95,108,111,99,97,108,115,95,95,40,0, + 0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,14,0,0,0,95, + 78,97,109,101,115,112,97,99,101,80,97,116,104,147,4,0, + 0,115,20,0,0,0,16,5,6,2,12,6,12,10,12,4, + 12,12,12,3,12,3,12,3,12,3,117,14,0,0,0,95, + 78,97,109,101,115,112,97,99,101,80,97,116,104,99,1,0, + 0,0,0,0,0,0,1,0,0,0,3,0,0,0,66,0, + 0,0,115,68,0,0,0,124,0,0,69,101,0,0,90,1, + 0,100,0,0,90,2,0,100,1,0,100,2,0,132,0,0, + 90,3,0,101,4,0,100,3,0,100,4,0,132,0,0,131, + 1,0,90,5,0,101,6,0,100,5,0,100,6,0,132,0, + 0,131,1,0,90,7,0,100,7,0,83,40,8,0,0,0, + 117,15,0,0,0,78,97,109,101,115,112,97,99,101,76,111, + 97,100,101,114,99,4,0,0,0,0,0,0,0,4,0,0, + 0,4,0,0,0,67,0,0,0,115,25,0,0,0,116,0, + 0,124,1,0,124,2,0,124,3,0,131,3,0,124,0,0, + 95,1,0,100,0,0,83,40,1,0,0,0,78,40,2,0, + 0,0,117,14,0,0,0,95,78,97,109,101,115,112,97,99, + 101,80,97,116,104,117,5,0,0,0,95,112,97,116,104,40, + 4,0,0,0,117,4,0,0,0,115,101,108,102,117,4,0, + 0,0,110,97,109,101,117,4,0,0,0,112,97,116,104,117, + 11,0,0,0,112,97,116,104,95,102,105,110,100,101,114,40, + 0,0,0,0,40,0,0,0,0,117,29,0,0,0,60,102, + 114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46, + 95,98,111,111,116,115,116,114,97,112,62,117,8,0,0,0, + 95,95,105,110,105,116,95,95,203,4,0,0,115,2,0,0, + 0,0,1,117,24,0,0,0,78,97,109,101,115,112,97,99, + 101,76,111,97,100,101,114,46,95,95,105,110,105,116,95,95, + 99,2,0,0,0,0,0,0,0,2,0,0,0,2,0,0, + 0,67,0,0,0,115,16,0,0,0,100,1,0,106,0,0, + 124,1,0,106,1,0,131,1,0,83,40,2,0,0,0,78, + 117,25,0,0,0,60,109,111,100,117,108,101,32,39,123,125, + 39,32,40,110,97,109,101,115,112,97,99,101,41,62,40,2, + 0,0,0,117,6,0,0,0,102,111,114,109,97,116,117,8, + 0,0,0,95,95,110,97,109,101,95,95,40,2,0,0,0, + 117,3,0,0,0,99,108,115,117,6,0,0,0,109,111,100, + 117,108,101,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 11,0,0,0,109,111,100,117,108,101,95,114,101,112,114,206, + 4,0,0,115,2,0,0,0,0,2,117,27,0,0,0,78, + 97,109,101,115,112,97,99,101,76,111,97,100,101,114,46,109, + 111,100,117,108,101,95,114,101,112,114,99,2,0,0,0,0, + 0,0,0,2,0,0,0,3,0,0,0,67,0,0,0,115, + 32,0,0,0,116,0,0,100,1,0,124,0,0,106,1,0, + 131,2,0,1,124,0,0,106,1,0,124,1,0,95,2,0, + 124,1,0,83,40,2,0,0,0,117,24,0,0,0,76,111, + 97,100,32,97,32,110,97,109,101,115,112,97,99,101,32,109, + 111,100,117,108,101,46,117,38,0,0,0,110,97,109,101,115, + 112,97,99,101,32,109,111,100,117,108,101,32,108,111,97,100, + 101,100,32,119,105,116,104,32,112,97,116,104,32,123,33,114, + 125,40,3,0,0,0,117,16,0,0,0,95,118,101,114,98, + 111,115,101,95,109,101,115,115,97,103,101,117,5,0,0,0, + 95,112,97,116,104,117,8,0,0,0,95,95,112,97,116,104, + 95,95,40,2,0,0,0,117,4,0,0,0,115,101,108,102, + 117,6,0,0,0,109,111,100,117,108,101,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,11,0,0,0,108,111,97,100, + 95,109,111,100,117,108,101,210,4,0,0,115,6,0,0,0, + 0,3,16,1,12,1,117,27,0,0,0,78,97,109,101,115, + 112,97,99,101,76,111,97,100,101,114,46,108,111,97,100,95, + 109,111,100,117,108,101,78,40,8,0,0,0,117,8,0,0, + 0,95,95,110,97,109,101,95,95,117,10,0,0,0,95,95, + 109,111,100,117,108,101,95,95,117,12,0,0,0,95,95,113, + 117,97,108,110,97,109,101,95,95,117,8,0,0,0,95,95, + 105,110,105,116,95,95,117,11,0,0,0,99,108,97,115,115, + 109,101,116,104,111,100,117,11,0,0,0,109,111,100,117,108, + 101,95,114,101,112,114,117,17,0,0,0,109,111,100,117,108, + 101,95,102,111,114,95,108,111,97,100,101,114,117,11,0,0, + 0,108,111,97,100,95,109,111,100,117,108,101,40,1,0,0, + 0,117,10,0,0,0,95,95,108,111,99,97,108,115,95,95, + 40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,15,0,0, + 0,78,97,109,101,115,112,97,99,101,76,111,97,100,101,114, + 202,4,0,0,115,6,0,0,0,16,1,12,3,18,4,117, + 15,0,0,0,78,97,109,101,115,112,97,99,101,76,111,97, + 100,101,114,99,1,0,0,0,0,0,0,0,1,0,0,0, + 4,0,0,0,66,0,0,0,115,119,0,0,0,124,0,0, + 69,101,0,0,90,1,0,100,0,0,90,2,0,100,1,0, + 90,3,0,101,4,0,100,2,0,100,3,0,132,0,0,131, + 1,0,90,5,0,101,4,0,100,4,0,100,5,0,132,0, + 0,131,1,0,90,6,0,101,4,0,100,6,0,100,7,0, + 132,0,0,131,1,0,90,7,0,101,4,0,100,8,0,100, + 9,0,132,0,0,131,1,0,90,8,0,101,4,0,100,10, + 0,100,11,0,100,12,0,132,1,0,131,1,0,90,9,0, + 100,10,0,83,40,13,0,0,0,117,10,0,0,0,80,97, + 116,104,70,105,110,100,101,114,117,62,0,0,0,77,101,116, + 97,32,112,97,116,104,32,102,105,110,100,101,114,32,102,111, + 114,32,115,121,115,46,112,97,116,104,32,97,110,100,32,112, + 97,99,107,97,103,101,32,95,95,112,97,116,104,95,95,32, + 97,116,116,114,105,98,117,116,101,115,46,99,1,0,0,0, + 0,0,0,0,2,0,0,0,4,0,0,0,67,0,0,0, + 115,58,0,0,0,120,51,0,116,0,0,106,1,0,106,2, + 0,131,0,0,68,93,34,0,125,1,0,116,3,0,124,1, + 0,100,1,0,131,2,0,114,16,0,124,1,0,106,4,0, + 131,0,0,1,113,16,0,113,16,0,87,100,2,0,83,40, + 3,0,0,0,117,125,0,0,0,67,97,108,108,32,116,104, + 101,32,105,110,118,97,108,105,100,97,116,101,95,99,97,99, + 104,101,115,40,41,32,109,101,116,104,111,100,32,111,110,32, + 97,108,108,32,112,97,116,104,32,101,110,116,114,121,32,102, + 105,110,100,101,114,115,10,32,32,32,32,32,32,32,32,115, + 116,111,114,101,100,32,105,110,32,115,121,115,46,112,97,116, + 104,95,105,109,112,111,114,116,101,114,95,99,97,99,104,101, + 115,32,40,119,104,101,114,101,32,105,109,112,108,101,109,101, + 110,116,101,100,41,46,117,17,0,0,0,105,110,118,97,108, + 105,100,97,116,101,95,99,97,99,104,101,115,78,40,5,0, + 0,0,117,3,0,0,0,115,121,115,117,19,0,0,0,112, + 97,116,104,95,105,109,112,111,114,116,101,114,95,99,97,99, + 104,101,117,6,0,0,0,118,97,108,117,101,115,117,7,0, + 0,0,104,97,115,97,116,116,114,117,17,0,0,0,105,110, 118,97,108,105,100,97,116,101,95,99,97,99,104,101,115,40, - 41,32,109,101,116,104,111,100,32,111,110,32,97,108,108,32, - 112,97,116,104,32,101,110,116,114,121,32,102,105,110,100,101, - 114,115,10,32,32,32,32,32,32,32,32,115,116,111,114,101, - 100,32,105,110,32,115,121,115,46,112,97,116,104,95,105,109, - 112,111,114,116,101,114,95,99,97,99,104,101,115,32,40,119, - 104,101,114,101,32,105,109,112,108,101,109,101,110,116,101,100, - 41,46,244,17,0,0,0,105,110,118,97,108,105,100,97,116, - 101,95,99,97,99,104,101,115,78,40,5,0,0,0,114,7, - 0,0,0,244,19,0,0,0,112,97,116,104,95,105,109,112, - 111,114,116,101,114,95,99,97,99,104,101,244,6,0,0,0, - 118,97,108,117,101,115,114,59,0,0,0,114,28,1,0,0, - 40,2,0,0,0,114,215,0,0,0,244,6,0,0,0,102, - 105,110,100,101,114,114,4,0,0,0,114,4,0,0,0,114, - 5,0,0,0,114,28,1,0,0,242,4,0,0,115,6,0, + 2,0,0,0,117,3,0,0,0,99,108,115,117,6,0,0, + 0,102,105,110,100,101,114,40,0,0,0,0,40,0,0,0, + 0,117,29,0,0,0,60,102,114,111,122,101,110,32,105,109, + 112,111,114,116,108,105,98,46,95,98,111,111,116,115,116,114, + 97,112,62,117,17,0,0,0,105,110,118,97,108,105,100,97, + 116,101,95,99,97,99,104,101,115,224,4,0,0,115,6,0, 0,0,0,4,22,1,15,1,117,28,0,0,0,80,97,116, 104,70,105,110,100,101,114,46,105,110,118,97,108,105,100,97, 116,101,95,99,97,99,104,101,115,99,2,0,0,0,0,0, @@ -2689,44 +3167,54 @@ 115,101,32,115,121,115,46,112,97,116,104,95,104,111,111,107, 115,46,10,10,32,32,32,32,32,32,32,32,117,23,0,0, 0,115,121,115,46,112,97,116,104,95,104,111,111,107,115,32, - 105,115,32,101,109,112,116,121,78,40,6,0,0,0,114,7, - 0,0,0,244,10,0,0,0,112,97,116,104,95,104,111,111, - 107,115,114,185,0,0,0,114,186,0,0,0,114,187,0,0, - 0,114,157,0,0,0,40,3,0,0,0,114,215,0,0,0, - 114,35,0,0,0,116,4,0,0,0,104,111,111,107,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,244,11,0, - 0,0,95,112,97,116,104,95,104,111,111,107,115,250,4,0, - 0,115,16,0,0,0,0,7,9,1,19,1,16,1,3,1, - 14,1,13,1,12,2,117,22,0,0,0,80,97,116,104,70, - 105,110,100,101,114,46,95,112,97,116,104,95,104,111,111,107, - 115,99,2,0,0,0,0,0,0,0,3,0,0,0,11,0, - 0,0,67,0,0,0,115,91,0,0,0,124,1,0,100,1, - 0,107,2,0,114,21,0,100,2,0,125,1,0,110,0,0, - 121,17,0,116,0,0,106,1,0,124,1,0,25,125,2,0, - 87,110,46,0,4,116,2,0,107,10,0,114,86,0,1,1, - 1,124,0,0,106,3,0,124,1,0,131,1,0,125,2,0, - 124,2,0,116,0,0,106,1,0,124,1,0,60,89,110,1, - 0,88,124,2,0,83,40,3,0,0,0,117,210,0,0,0, - 71,101,116,32,116,104,101,32,102,105,110,100,101,114,32,102, - 111,114,32,116,104,101,32,112,97,116,104,32,101,110,116,114, - 121,32,102,114,111,109,32,115,121,115,46,112,97,116,104,95, - 105,109,112,111,114,116,101,114,95,99,97,99,104,101,46,10, - 10,32,32,32,32,32,32,32,32,73,102,32,116,104,101,32, - 112,97,116,104,32,101,110,116,114,121,32,105,115,32,110,111, - 116,32,105,110,32,116,104,101,32,99,97,99,104,101,44,32, - 102,105,110,100,32,116,104,101,32,97,112,112,114,111,112,114, - 105,97,116,101,32,102,105,110,100,101,114,10,32,32,32,32, - 32,32,32,32,97,110,100,32,99,97,99,104,101,32,105,116, - 46,32,73,102,32,110,111,32,102,105,110,100,101,114,32,105, - 115,32,97,118,97,105,108,97,98,108,101,44,32,115,116,111, - 114,101,32,78,111,110,101,46,10,10,32,32,32,32,32,32, - 32,32,114,30,0,0,0,114,101,0,0,0,40,4,0,0, - 0,114,7,0,0,0,114,29,1,0,0,114,91,0,0,0, - 114,33,1,0,0,40,3,0,0,0,114,215,0,0,0,114, - 35,0,0,0,114,31,1,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,244,20,0,0,0,95,112,97, + 105,115,32,101,109,112,116,121,78,40,6,0,0,0,117,3, + 0,0,0,115,121,115,117,10,0,0,0,112,97,116,104,95, + 104,111,111,107,115,117,9,0,0,0,95,119,97,114,110,105, + 110,103,115,117,4,0,0,0,119,97,114,110,117,13,0,0, + 0,73,109,112,111,114,116,87,97,114,110,105,110,103,117,11, + 0,0,0,73,109,112,111,114,116,69,114,114,111,114,40,3, + 0,0,0,117,3,0,0,0,99,108,115,117,4,0,0,0, + 112,97,116,104,117,4,0,0,0,104,111,111,107,40,0,0, + 0,0,40,0,0,0,0,117,29,0,0,0,60,102,114,111, + 122,101,110,32,105,109,112,111,114,116,108,105,98,46,95,98, + 111,111,116,115,116,114,97,112,62,117,11,0,0,0,95,112, + 97,116,104,95,104,111,111,107,115,232,4,0,0,115,16,0, + 0,0,0,7,9,1,19,1,16,1,3,1,14,1,13,1, + 12,2,117,22,0,0,0,80,97,116,104,70,105,110,100,101, + 114,46,95,112,97,116,104,95,104,111,111,107,115,99,2,0, + 0,0,0,0,0,0,3,0,0,0,11,0,0,0,67,0, + 0,0,115,91,0,0,0,124,1,0,100,1,0,107,2,0, + 114,21,0,100,2,0,125,1,0,110,0,0,121,17,0,116, + 0,0,106,1,0,124,1,0,25,125,2,0,87,110,46,0, + 4,116,2,0,107,10,0,114,86,0,1,1,1,124,0,0, + 106,3,0,124,1,0,131,1,0,125,2,0,124,2,0,116, + 0,0,106,1,0,124,1,0,60,89,110,1,0,88,124,2, + 0,83,40,3,0,0,0,117,210,0,0,0,71,101,116,32, + 116,104,101,32,102,105,110,100,101,114,32,102,111,114,32,116, + 104,101,32,112,97,116,104,32,101,110,116,114,121,32,102,114, + 111,109,32,115,121,115,46,112,97,116,104,95,105,109,112,111, + 114,116,101,114,95,99,97,99,104,101,46,10,10,32,32,32, + 32,32,32,32,32,73,102,32,116,104,101,32,112,97,116,104, + 32,101,110,116,114,121,32,105,115,32,110,111,116,32,105,110, + 32,116,104,101,32,99,97,99,104,101,44,32,102,105,110,100, + 32,116,104,101,32,97,112,112,114,111,112,114,105,97,116,101, + 32,102,105,110,100,101,114,10,32,32,32,32,32,32,32,32, + 97,110,100,32,99,97,99,104,101,32,105,116,46,32,73,102, + 32,110,111,32,102,105,110,100,101,114,32,105,115,32,97,118, + 97,105,108,97,98,108,101,44,32,115,116,111,114,101,32,78, + 111,110,101,46,10,10,32,32,32,32,32,32,32,32,117,0, + 0,0,0,117,1,0,0,0,46,40,4,0,0,0,117,3, + 0,0,0,115,121,115,117,19,0,0,0,112,97,116,104,95, + 105,109,112,111,114,116,101,114,95,99,97,99,104,101,117,8, + 0,0,0,75,101,121,69,114,114,111,114,117,11,0,0,0, + 95,112,97,116,104,95,104,111,111,107,115,40,3,0,0,0, + 117,3,0,0,0,99,108,115,117,4,0,0,0,112,97,116, + 104,117,6,0,0,0,102,105,110,100,101,114,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,20,0,0,0,95,112,97, 116,104,95,105,109,112,111,114,116,101,114,95,99,97,99,104, - 101,11,5,0,0,115,16,0,0,0,0,8,12,1,9,1, + 101,249,4,0,0,115,16,0,0,0,0,8,12,1,9,1, 3,1,17,1,13,1,15,1,18,1,117,31,0,0,0,80, 97,116,104,70,105,110,100,101,114,46,95,112,97,116,104,95, 105,109,112,111,114,116,101,114,95,99,97,99,104,101,99,3, @@ -2747,377 +3235,484 @@ 105,110,100,32,116,104,101,32,108,111,97,100,101,114,32,111, 114,32,110,97,109,101,115,112,97,99,101,95,112,97,116,104, 32,102,111,114,32,116,104,105,115,32,109,111,100,117,108,101, - 47,112,97,99,107,97,103,101,32,110,97,109,101,46,78,114, - 184,0,0,0,40,8,0,0,0,114,202,0,0,0,244,3, - 0,0,0,115,116,114,244,5,0,0,0,98,121,116,101,115, - 114,34,1,0,0,114,59,0,0,0,114,184,0,0,0,114, - 217,0,0,0,114,207,0,0,0,40,8,0,0,0,114,215, - 0,0,0,114,178,0,0,0,114,35,0,0,0,244,14,0, - 0,0,110,97,109,101,115,112,97,99,101,95,112,97,116,104, - 116,5,0,0,0,101,110,116,114,121,114,31,1,0,0,114, - 160,0,0,0,114,188,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,244,11,0,0,0,95,103,101, - 116,95,108,111,97,100,101,114,28,5,0,0,115,28,0,0, - 0,0,5,6,1,13,1,21,1,6,1,15,1,12,1,15, - 1,24,2,15,1,6,1,12,2,10,5,20,2,117,22,0, - 0,0,80,97,116,104,70,105,110,100,101,114,46,95,103,101, - 116,95,108,111,97,100,101,114,78,99,3,0,0,0,0,0, - 0,0,5,0,0,0,4,0,0,0,67,0,0,0,115,97, - 0,0,0,124,2,0,100,1,0,107,8,0,114,24,0,116, - 0,0,106,1,0,125,2,0,110,0,0,124,0,0,106,2, - 0,124,1,0,124,2,0,131,2,0,92,2,0,125,3,0, - 125,4,0,124,3,0,100,1,0,107,9,0,114,64,0,124, - 3,0,83,124,4,0,114,89,0,116,3,0,124,1,0,124, - 4,0,124,0,0,106,2,0,131,3,0,83,100,1,0,83, - 100,1,0,83,40,2,0,0,0,117,98,0,0,0,70,105, - 110,100,32,116,104,101,32,109,111,100,117,108,101,32,111,110, - 32,115,121,115,46,112,97,116,104,32,111,114,32,39,112,97, - 116,104,39,32,98,97,115,101,100,32,111,110,32,115,121,115, - 46,112,97,116,104,95,104,111,111,107,115,32,97,110,100,10, - 32,32,32,32,32,32,32,32,115,121,115,46,112,97,116,104, - 95,105,109,112,111,114,116,101,114,95,99,97,99,104,101,46, - 78,40,4,0,0,0,114,7,0,0,0,114,35,0,0,0, - 114,38,1,0,0,114,26,1,0,0,40,5,0,0,0,114, - 215,0,0,0,114,178,0,0,0,114,35,0,0,0,114,160, - 0,0,0,114,37,1,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,114,217,0,0,0,55,5,0,0, - 115,16,0,0,0,0,4,12,1,12,1,24,1,12,1,4, - 2,6,3,19,2,117,22,0,0,0,80,97,116,104,70,105, - 110,100,101,114,46,102,105,110,100,95,109,111,100,117,108,101, - 40,10,0,0,0,114,56,0,0,0,114,55,0,0,0,114, - 57,0,0,0,114,58,0,0,0,114,221,0,0,0,114,28, - 1,0,0,114,33,1,0,0,114,34,1,0,0,114,38,1, - 0,0,114,217,0,0,0,114,4,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,114,27,1,0,0, - 238,4,0,0,115,14,0,0,0,12,2,6,2,18,8,18, - 17,18,17,18,27,3,1,114,27,1,0,0,99,0,0,0, - 0,0,0,0,0,0,0,0,0,3,0,0,0,64,0,0, - 0,115,106,0,0,0,101,0,0,90,1,0,100,0,0,90, - 2,0,100,1,0,90,3,0,100,2,0,100,3,0,132,0, - 0,90,4,0,100,4,0,100,5,0,132,0,0,90,5,0, - 101,6,0,90,7,0,100,6,0,100,7,0,132,0,0,90, - 8,0,100,8,0,100,9,0,132,0,0,90,9,0,101,10, - 0,100,10,0,100,11,0,132,0,0,131,1,0,90,11,0, - 100,12,0,100,13,0,132,0,0,90,12,0,100,14,0,83, - 40,15,0,0,0,244,10,0,0,0,70,105,108,101,70,105, - 110,100,101,114,117,172,0,0,0,70,105,108,101,45,98,97, - 115,101,100,32,102,105,110,100,101,114,46,10,10,32,32,32, - 32,73,110,116,101,114,97,99,116,105,111,110,115,32,119,105, - 116,104,32,116,104,101,32,102,105,108,101,32,115,121,115,116, - 101,109,32,97,114,101,32,99,97,99,104,101,100,32,102,111, - 114,32,112,101,114,102,111,114,109,97,110,99,101,44,32,98, - 101,105,110,103,10,32,32,32,32,114,101,102,114,101,115,104, - 101,100,32,119,104,101,110,32,116,104,101,32,100,105,114,101, - 99,116,111,114,121,32,116,104,101,32,102,105,110,100,101,114, - 32,105,115,32,104,97,110,100,108,105,110,103,32,104,97,115, - 32,98,101,101,110,32,109,111,100,105,102,105,101,100,46,10, - 10,32,32,32,32,99,2,0,0,0,0,0,0,0,5,0, - 0,0,5,0,0,0,7,0,0,0,115,122,0,0,0,103, - 0,0,125,3,0,120,52,0,124,2,0,68,93,44,0,92, - 2,0,137,0,0,125,4,0,124,3,0,106,0,0,135,0, - 0,102,1,0,100,1,0,100,2,0,134,0,0,124,4,0, - 68,131,1,0,131,1,0,1,113,13,0,87,124,3,0,124, - 0,0,95,1,0,124,1,0,112,79,0,100,3,0,124,0, - 0,95,2,0,100,6,0,124,0,0,95,3,0,116,4,0, - 131,0,0,124,0,0,95,5,0,116,4,0,131,0,0,124, - 0,0,95,6,0,100,5,0,83,40,7,0,0,0,117,154, - 0,0,0,73,110,105,116,105,97,108,105,122,101,32,119,105, - 116,104,32,116,104,101,32,112,97,116,104,32,116,111,32,115, - 101,97,114,99,104,32,111,110,32,97,110,100,32,97,32,118, - 97,114,105,97,98,108,101,32,110,117,109,98,101,114,32,111, - 102,10,32,32,32,32,32,32,32,32,50,45,116,117,112,108, - 101,115,32,99,111,110,116,97,105,110,105,110,103,32,116,104, - 101,32,108,111,97,100,101,114,32,97,110,100,32,116,104,101, - 32,102,105,108,101,32,115,117,102,102,105,120,101,115,32,116, - 104,101,32,108,111,97,100,101,114,10,32,32,32,32,32,32, - 32,32,114,101,99,111,103,110,105,122,101,115,46,99,1,0, - 0,0,0,0,0,0,2,0,0,0,3,0,0,0,51,0, - 0,0,115,27,0,0,0,124,0,0,93,17,0,125,1,0, - 124,1,0,136,0,0,102,2,0,86,1,113,3,0,100,0, - 0,83,40,1,0,0,0,78,114,4,0,0,0,40,2,0, - 0,0,114,22,0,0,0,114,9,1,0,0,40,1,0,0, - 0,114,160,0,0,0,114,4,0,0,0,114,5,0,0,0, - 114,143,0,0,0,88,5,0,0,115,2,0,0,0,6,0, - 117,38,0,0,0,70,105,108,101,70,105,110,100,101,114,46, - 95,95,105,110,105,116,95,95,46,60,108,111,99,97,108,115, - 62,46,60,103,101,110,101,120,112,114,62,114,101,0,0,0, - 114,29,0,0,0,78,114,123,0,0,0,40,7,0,0,0, - 114,207,0,0,0,244,8,0,0,0,95,108,111,97,100,101, - 114,115,114,35,0,0,0,244,11,0,0,0,95,112,97,116, - 104,95,109,116,105,109,101,244,3,0,0,0,115,101,116,244, - 11,0,0,0,95,112,97,116,104,95,99,97,99,104,101,244, + 47,112,97,99,107,97,103,101,32,110,97,109,101,46,78,117, + 11,0,0,0,102,105,110,100,95,108,111,97,100,101,114,40, + 8,0,0,0,117,10,0,0,0,105,115,105,110,115,116,97, + 110,99,101,117,3,0,0,0,115,116,114,117,5,0,0,0, + 98,121,116,101,115,117,20,0,0,0,95,112,97,116,104,95, + 105,109,112,111,114,116,101,114,95,99,97,99,104,101,117,7, + 0,0,0,104,97,115,97,116,116,114,117,11,0,0,0,102, + 105,110,100,95,108,111,97,100,101,114,117,11,0,0,0,102, + 105,110,100,95,109,111,100,117,108,101,117,6,0,0,0,101, + 120,116,101,110,100,40,8,0,0,0,117,3,0,0,0,99, + 108,115,117,8,0,0,0,102,117,108,108,110,97,109,101,117, + 4,0,0,0,112,97,116,104,117,14,0,0,0,110,97,109, + 101,115,112,97,99,101,95,112,97,116,104,117,5,0,0,0, + 101,110,116,114,121,117,6,0,0,0,102,105,110,100,101,114, + 117,6,0,0,0,108,111,97,100,101,114,117,8,0,0,0, + 112,111,114,116,105,111,110,115,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,11,0,0,0,95,103,101,116,95,108,111, + 97,100,101,114,10,5,0,0,115,28,0,0,0,0,5,6, + 1,13,1,21,1,6,1,15,1,12,1,15,1,24,2,15, + 1,6,1,12,2,10,5,20,2,117,22,0,0,0,80,97, + 116,104,70,105,110,100,101,114,46,95,103,101,116,95,108,111, + 97,100,101,114,78,99,3,0,0,0,0,0,0,0,5,0, + 0,0,4,0,0,0,67,0,0,0,115,97,0,0,0,124, + 2,0,100,1,0,107,8,0,114,24,0,116,0,0,106,1, + 0,125,2,0,110,0,0,124,0,0,106,2,0,124,1,0, + 124,2,0,131,2,0,92,2,0,125,3,0,125,4,0,124, + 3,0,100,1,0,107,9,0,114,64,0,124,3,0,83,124, + 4,0,114,89,0,116,3,0,124,1,0,124,4,0,124,0, + 0,106,2,0,131,3,0,83,100,1,0,83,100,1,0,83, + 40,2,0,0,0,117,98,0,0,0,70,105,110,100,32,116, + 104,101,32,109,111,100,117,108,101,32,111,110,32,115,121,115, + 46,112,97,116,104,32,111,114,32,39,112,97,116,104,39,32, + 98,97,115,101,100,32,111,110,32,115,121,115,46,112,97,116, + 104,95,104,111,111,107,115,32,97,110,100,10,32,32,32,32, + 32,32,32,32,115,121,115,46,112,97,116,104,95,105,109,112, + 111,114,116,101,114,95,99,97,99,104,101,46,78,40,4,0, + 0,0,117,3,0,0,0,115,121,115,117,4,0,0,0,112, + 97,116,104,117,11,0,0,0,95,103,101,116,95,108,111,97, + 100,101,114,117,15,0,0,0,78,97,109,101,115,112,97,99, + 101,76,111,97,100,101,114,40,5,0,0,0,117,3,0,0, + 0,99,108,115,117,8,0,0,0,102,117,108,108,110,97,109, + 101,117,4,0,0,0,112,97,116,104,117,6,0,0,0,108, + 111,97,100,101,114,117,14,0,0,0,110,97,109,101,115,112, + 97,99,101,95,112,97,116,104,40,0,0,0,0,40,0,0, + 0,0,117,29,0,0,0,60,102,114,111,122,101,110,32,105, + 109,112,111,114,116,108,105,98,46,95,98,111,111,116,115,116, + 114,97,112,62,117,11,0,0,0,102,105,110,100,95,109,111, + 100,117,108,101,37,5,0,0,115,16,0,0,0,0,4,12, + 1,12,1,24,1,12,1,4,2,6,3,19,2,117,22,0, + 0,0,80,97,116,104,70,105,110,100,101,114,46,102,105,110, + 100,95,109,111,100,117,108,101,40,10,0,0,0,117,8,0, + 0,0,95,95,110,97,109,101,95,95,117,10,0,0,0,95, + 95,109,111,100,117,108,101,95,95,117,12,0,0,0,95,95, + 113,117,97,108,110,97,109,101,95,95,117,7,0,0,0,95, + 95,100,111,99,95,95,117,11,0,0,0,99,108,97,115,115, + 109,101,116,104,111,100,117,17,0,0,0,105,110,118,97,108, + 105,100,97,116,101,95,99,97,99,104,101,115,117,11,0,0, + 0,95,112,97,116,104,95,104,111,111,107,115,117,20,0,0, + 0,95,112,97,116,104,95,105,109,112,111,114,116,101,114,95, + 99,97,99,104,101,117,11,0,0,0,95,103,101,116,95,108, + 111,97,100,101,114,117,11,0,0,0,102,105,110,100,95,109, + 111,100,117,108,101,40,1,0,0,0,117,10,0,0,0,95, + 95,108,111,99,97,108,115,95,95,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,10,0,0,0,80,97,116,104,70,105, + 110,100,101,114,220,4,0,0,115,14,0,0,0,16,2,6, + 2,18,8,18,17,18,17,18,27,3,1,117,10,0,0,0, + 80,97,116,104,70,105,110,100,101,114,99,1,0,0,0,0, + 0,0,0,1,0,0,0,3,0,0,0,66,0,0,0,115, + 110,0,0,0,124,0,0,69,101,0,0,90,1,0,100,0, + 0,90,2,0,100,1,0,90,3,0,100,2,0,100,3,0, + 132,0,0,90,4,0,100,4,0,100,5,0,132,0,0,90, + 5,0,101,6,0,90,7,0,100,6,0,100,7,0,132,0, + 0,90,8,0,100,8,0,100,9,0,132,0,0,90,9,0, + 101,10,0,100,10,0,100,11,0,132,0,0,131,1,0,90, + 11,0,100,12,0,100,13,0,132,0,0,90,12,0,100,14, + 0,83,40,15,0,0,0,117,10,0,0,0,70,105,108,101, + 70,105,110,100,101,114,117,172,0,0,0,70,105,108,101,45, + 98,97,115,101,100,32,102,105,110,100,101,114,46,10,10,32, + 32,32,32,73,110,116,101,114,97,99,116,105,111,110,115,32, + 119,105,116,104,32,116,104,101,32,102,105,108,101,32,115,121, + 115,116,101,109,32,97,114,101,32,99,97,99,104,101,100,32, + 102,111,114,32,112,101,114,102,111,114,109,97,110,99,101,44, + 32,98,101,105,110,103,10,32,32,32,32,114,101,102,114,101, + 115,104,101,100,32,119,104,101,110,32,116,104,101,32,100,105, + 114,101,99,116,111,114,121,32,116,104,101,32,102,105,110,100, + 101,114,32,105,115,32,104,97,110,100,108,105,110,103,32,104, + 97,115,32,98,101,101,110,32,109,111,100,105,102,105,101,100, + 46,10,10,32,32,32,32,99,2,0,0,0,0,0,0,0, + 5,0,0,0,5,0,0,0,7,0,0,0,115,122,0,0, + 0,103,0,0,125,3,0,120,52,0,124,2,0,68,93,44, + 0,92,2,0,137,0,0,125,4,0,124,3,0,106,0,0, + 135,0,0,102,1,0,100,1,0,100,2,0,134,0,0,124, + 4,0,68,131,1,0,131,1,0,1,113,13,0,87,124,3, + 0,124,0,0,95,1,0,124,1,0,112,79,0,100,3,0, + 124,0,0,95,2,0,100,6,0,124,0,0,95,3,0,116, + 4,0,131,0,0,124,0,0,95,5,0,116,4,0,131,0, + 0,124,0,0,95,6,0,100,5,0,83,40,7,0,0,0, + 117,201,0,0,0,73,110,105,116,105,97,108,105,122,101,32, + 119,105,116,104,32,116,104,101,32,112,97,116,104,32,116,111, + 32,115,101,97,114,99,104,32,111,110,32,97,110,100,32,97, + 32,118,97,114,105,97,98,108,101,32,110,117,109,98,101,114, + 32,111,102,10,32,32,32,32,32,32,32,32,51,45,116,117, + 112,108,101,115,32,99,111,110,116,97,105,110,105,110,103,32, + 116,104,101,32,108,111,97,100,101,114,44,32,102,105,108,101, + 32,115,117,102,102,105,120,101,115,32,116,104,101,32,108,111, + 97,100,101,114,32,114,101,99,111,103,110,105,122,101,115,44, + 10,32,32,32,32,32,32,32,32,97,110,100,32,97,32,98, + 111,111,108,101,97,110,32,111,102,32,119,104,101,116,104,101, + 114,32,116,104,101,32,108,111,97,100,101,114,32,104,97,110, + 100,108,101,115,32,112,97,99,107,97,103,101,115,46,99,1, + 0,0,0,0,0,0,0,2,0,0,0,3,0,0,0,51, + 0,0,0,115,27,0,0,0,124,0,0,93,17,0,125,1, + 0,124,1,0,136,0,0,102,2,0,86,1,113,3,0,100, + 0,0,83,40,1,0,0,0,78,40,0,0,0,0,40,2, + 0,0,0,117,2,0,0,0,46,48,117,6,0,0,0,115, + 117,102,102,105,120,40,1,0,0,0,117,6,0,0,0,108, + 111,97,100,101,114,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,9,0,0, + 0,60,103,101,110,101,120,112,114,62,70,5,0,0,115,2, + 0,0,0,6,0,117,38,0,0,0,70,105,108,101,70,105, + 110,100,101,114,46,95,95,105,110,105,116,95,95,46,60,108, + 111,99,97,108,115,62,46,60,103,101,110,101,120,112,114,62, + 117,1,0,0,0,46,105,1,0,0,0,78,105,255,255,255, + 255,40,7,0,0,0,117,6,0,0,0,101,120,116,101,110, + 100,117,8,0,0,0,95,108,111,97,100,101,114,115,117,4, + 0,0,0,112,97,116,104,117,11,0,0,0,95,112,97,116, + 104,95,109,116,105,109,101,117,3,0,0,0,115,101,116,117, + 11,0,0,0,95,112,97,116,104,95,99,97,99,104,101,117, 19,0,0,0,95,114,101,108,97,120,101,100,95,112,97,116, - 104,95,99,97,99,104,101,40,5,0,0,0,114,75,0,0, - 0,114,35,0,0,0,244,14,0,0,0,108,111,97,100,101, - 114,95,100,101,116,97,105,108,115,116,7,0,0,0,108,111, - 97,100,101,114,115,114,112,0,0,0,114,4,0,0,0,40, - 1,0,0,0,114,160,0,0,0,114,5,0,0,0,114,76, - 0,0,0,82,5,0,0,115,16,0,0,0,0,4,6,1, - 19,1,36,1,9,2,15,1,9,1,12,1,117,19,0,0, - 0,70,105,108,101,70,105,110,100,101,114,46,95,95,105,110, - 105,116,95,95,99,1,0,0,0,0,0,0,0,1,0,0, - 0,2,0,0,0,67,0,0,0,115,13,0,0,0,100,3, - 0,124,0,0,95,0,0,100,2,0,83,40,4,0,0,0, - 117,31,0,0,0,73,110,118,97,108,105,100,97,116,101,32, - 116,104,101,32,100,105,114,101,99,116,111,114,121,32,109,116, - 105,109,101,46,114,29,0,0,0,78,114,123,0,0,0,40, - 1,0,0,0,114,41,1,0,0,40,1,0,0,0,114,75, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,28,1,0,0,96,5,0,0,115,2,0,0,0, - 0,2,117,28,0,0,0,70,105,108,101,70,105,110,100,101, - 114,46,105,110,118,97,108,105,100,97,116,101,95,99,97,99, - 104,101,115,99,2,0,0,0,0,0,0,0,12,0,0,0, - 13,0,0,0,67,0,0,0,115,216,1,0,0,100,1,0, - 125,2,0,124,1,0,106,0,0,100,2,0,131,1,0,100, - 3,0,25,125,3,0,121,25,0,116,1,0,106,2,0,124, - 0,0,106,3,0,131,1,0,106,4,0,125,4,0,87,110, - 24,0,4,116,5,0,107,10,0,114,76,0,1,1,1,100, - 11,0,125,4,0,89,110,1,0,88,124,4,0,124,0,0, - 106,6,0,107,3,0,114,114,0,124,0,0,106,7,0,131, - 0,0,1,124,4,0,124,0,0,95,6,0,110,0,0,116, - 8,0,131,0,0,114,147,0,124,0,0,106,9,0,125,5, - 0,124,3,0,106,10,0,131,0,0,125,6,0,110,15,0, - 124,0,0,106,11,0,125,5,0,124,3,0,125,6,0,124, - 6,0,124,5,0,107,6,0,114,45,1,116,12,0,124,0, - 0,106,3,0,124,3,0,131,2,0,125,7,0,116,13,0, - 124,7,0,131,1,0,114,45,1,120,91,0,124,0,0,106, - 14,0,68,93,71,0,92,2,0,125,8,0,125,9,0,100, - 5,0,124,8,0,23,125,10,0,116,12,0,124,7,0,124, - 10,0,131,2,0,125,11,0,116,15,0,124,11,0,131,1, - 0,114,214,0,124,9,0,124,1,0,124,11,0,131,2,0, - 124,7,0,103,1,0,102,2,0,83,113,214,0,87,100,6, - 0,125,2,0,113,45,1,110,0,0,120,120,0,124,0,0, - 106,14,0,68,93,109,0,92,2,0,125,8,0,125,9,0, - 116,12,0,124,0,0,106,3,0,124,3,0,124,8,0,23, - 131,2,0,125,11,0,116,16,0,100,7,0,106,17,0,124, - 11,0,131,1,0,100,8,0,100,3,0,131,1,1,1,124, - 6,0,124,8,0,23,124,5,0,107,6,0,114,55,1,116, - 15,0,124,11,0,131,1,0,114,164,1,124,9,0,124,1, - 0,124,11,0,131,2,0,103,0,0,102,2,0,83,113,55, - 1,113,55,1,87,124,2,0,114,206,1,116,16,0,100,9, - 0,106,17,0,124,7,0,131,1,0,131,1,0,1,100,10, - 0,124,7,0,103,1,0,102,2,0,83,100,10,0,103,0, - 0,102,2,0,83,40,12,0,0,0,117,125,0,0,0,84, - 114,121,32,116,111,32,102,105,110,100,32,97,32,108,111,97, - 100,101,114,32,102,111,114,32,116,104,101,32,115,112,101,99, - 105,102,105,101,100,32,109,111,100,117,108,101,44,32,111,114, - 32,116,104,101,32,110,97,109,101,115,112,97,99,101,10,32, - 32,32,32,32,32,32,32,112,97,99,107,97,103,101,32,112, - 111,114,116,105,111,110,115,46,32,82,101,116,117,114,110,115, - 32,40,108,111,97,100,101,114,44,32,108,105,115,116,45,111, - 102,45,112,111,114,116,105,111,110,115,41,46,70,114,101,0, - 0,0,114,100,0,0,0,114,29,0,0,0,114,76,0,0, - 0,84,117,9,0,0,0,116,114,121,105,110,103,32,123,125, - 114,130,0,0,0,117,25,0,0,0,112,111,115,115,105,98, - 108,101,32,110,97,109,101,115,112,97,99,101,32,102,111,114, - 32,123,125,78,114,123,0,0,0,40,18,0,0,0,114,32, - 0,0,0,114,3,0,0,0,114,39,0,0,0,114,35,0, - 0,0,114,3,1,0,0,114,40,0,0,0,114,41,1,0, - 0,244,11,0,0,0,95,102,105,108,108,95,99,97,99,104, - 101,114,6,0,0,0,114,44,1,0,0,114,124,0,0,0, - 114,43,1,0,0,114,28,0,0,0,114,45,0,0,0,114, - 40,1,0,0,114,44,0,0,0,114,137,0,0,0,114,46, - 0,0,0,40,12,0,0,0,114,75,0,0,0,114,178,0, - 0,0,116,12,0,0,0,105,115,95,110,97,109,101,115,112, - 97,99,101,116,11,0,0,0,116,97,105,108,95,109,111,100, - 117,108,101,114,193,0,0,0,116,5,0,0,0,99,97,99, - 104,101,116,12,0,0,0,99,97,99,104,101,95,109,111,100, - 117,108,101,116,9,0,0,0,98,97,115,101,95,112,97,116, - 104,114,9,1,0,0,114,160,0,0,0,116,13,0,0,0, - 105,110,105,116,95,102,105,108,101,110,97,109,101,116,9,0, - 0,0,102,117,108,108,95,112,97,116,104,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,184,0,0,0,102, - 5,0,0,115,66,0,0,0,0,3,6,1,19,1,3,1, - 25,1,13,1,11,1,15,1,10,1,12,2,9,1,9,1, - 15,2,9,1,6,2,12,1,18,1,12,1,22,1,10,1, - 15,1,12,1,26,4,12,2,22,1,22,1,25,1,16,1, - 12,1,26,1,6,1,19,1,13,1,117,22,0,0,0,70, - 105,108,101,70,105,110,100,101,114,46,102,105,110,100,95,108, - 111,97,100,101,114,99,1,0,0,0,0,0,0,0,9,0, - 0,0,13,0,0,0,67,0,0,0,115,2,1,0,0,124, - 0,0,106,0,0,125,1,0,121,19,0,116,1,0,106,2, - 0,124,1,0,131,1,0,125,2,0,87,110,33,0,4,116, - 3,0,116,4,0,116,5,0,102,3,0,107,10,0,114,63, - 0,1,1,1,103,0,0,125,2,0,89,110,1,0,88,116, - 6,0,106,7,0,106,8,0,100,1,0,131,1,0,115,100, - 0,116,9,0,124,2,0,131,1,0,124,0,0,95,10,0, - 110,111,0,116,9,0,131,0,0,125,3,0,120,90,0,124, - 2,0,68,93,82,0,125,4,0,124,4,0,106,11,0,100, - 2,0,131,1,0,92,3,0,125,5,0,125,6,0,125,7, - 0,124,6,0,114,179,0,100,3,0,106,12,0,124,5,0, - 124,7,0,106,13,0,131,0,0,131,2,0,125,8,0,110, - 6,0,124,5,0,125,8,0,124,3,0,106,14,0,124,8, - 0,131,1,0,1,113,116,0,87,124,3,0,124,0,0,95, - 10,0,116,6,0,106,7,0,106,8,0,116,15,0,131,1, - 0,114,254,0,100,4,0,100,5,0,132,0,0,124,2,0, - 68,131,1,0,124,0,0,95,16,0,110,0,0,100,6,0, + 104,95,99,97,99,104,101,40,5,0,0,0,117,4,0,0, + 0,115,101,108,102,117,4,0,0,0,112,97,116,104,117,7, + 0,0,0,100,101,116,97,105,108,115,117,7,0,0,0,108, + 111,97,100,101,114,115,117,8,0,0,0,115,117,102,102,105, + 120,101,115,40,0,0,0,0,40,1,0,0,0,117,6,0, + 0,0,108,111,97,100,101,114,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,8,0,0,0,95, + 95,105,110,105,116,95,95,64,5,0,0,115,16,0,0,0, + 0,4,6,1,19,1,36,1,9,2,15,1,9,1,12,1, + 117,19,0,0,0,70,105,108,101,70,105,110,100,101,114,46, + 95,95,105,110,105,116,95,95,99,1,0,0,0,0,0,0, + 0,1,0,0,0,2,0,0,0,67,0,0,0,115,13,0, + 0,0,100,3,0,124,0,0,95,0,0,100,2,0,83,40, + 4,0,0,0,117,31,0,0,0,73,110,118,97,108,105,100, + 97,116,101,32,116,104,101,32,100,105,114,101,99,116,111,114, + 121,32,109,116,105,109,101,46,105,1,0,0,0,78,105,255, + 255,255,255,40,1,0,0,0,117,11,0,0,0,95,112,97, + 116,104,95,109,116,105,109,101,40,1,0,0,0,117,4,0, + 0,0,115,101,108,102,40,0,0,0,0,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,17,0,0,0,105,110,118,97,108,105,100,97,116, + 101,95,99,97,99,104,101,115,78,5,0,0,115,2,0,0, + 0,0,2,117,28,0,0,0,70,105,108,101,70,105,110,100, + 101,114,46,105,110,118,97,108,105,100,97,116,101,95,99,97, + 99,104,101,115,99,2,0,0,0,0,0,0,0,12,0,0, + 0,13,0,0,0,67,0,0,0,115,172,1,0,0,100,1, + 0,125,2,0,124,1,0,106,0,0,100,2,0,131,1,0, + 100,3,0,25,125,3,0,121,25,0,116,1,0,106,2,0, + 124,0,0,106,3,0,131,1,0,106,4,0,125,4,0,87, + 110,24,0,4,116,5,0,107,10,0,114,76,0,1,1,1, + 100,8,0,125,4,0,89,110,1,0,88,124,4,0,124,0, + 0,106,6,0,107,3,0,114,114,0,124,0,0,106,7,0, + 131,0,0,1,124,4,0,124,0,0,95,6,0,110,0,0, + 116,8,0,131,0,0,114,147,0,124,0,0,106,9,0,125, + 5,0,124,3,0,106,10,0,131,0,0,125,6,0,110,15, + 0,124,0,0,106,11,0,125,5,0,124,3,0,125,6,0, + 124,6,0,124,5,0,107,6,0,114,45,1,116,12,0,124, + 0,0,106,3,0,124,3,0,131,2,0,125,7,0,116,13, + 0,124,7,0,131,1,0,114,45,1,120,91,0,124,0,0, + 106,14,0,68,93,71,0,92,2,0,125,8,0,125,9,0, + 100,5,0,124,8,0,23,125,10,0,116,12,0,124,7,0, + 124,10,0,131,2,0,125,11,0,116,15,0,124,11,0,131, + 1,0,114,214,0,124,9,0,124,1,0,124,11,0,131,2, + 0,124,7,0,103,1,0,102,2,0,83,113,214,0,87,100, + 6,0,125,2,0,113,45,1,110,0,0,120,95,0,124,0, + 0,106,14,0,68,93,84,0,92,2,0,125,8,0,125,9, + 0,124,6,0,124,8,0,23,124,5,0,107,6,0,114,55, + 1,116,12,0,124,0,0,106,3,0,124,3,0,124,8,0, + 23,131,2,0,125,11,0,116,15,0,124,11,0,131,1,0, + 114,139,1,124,9,0,124,1,0,124,11,0,131,2,0,103, + 0,0,102,2,0,83,113,55,1,113,55,1,87,124,2,0, + 114,162,1,100,7,0,124,7,0,103,1,0,102,2,0,83, + 100,7,0,103,0,0,102,2,0,83,40,9,0,0,0,117, + 125,0,0,0,84,114,121,32,116,111,32,102,105,110,100,32, + 97,32,108,111,97,100,101,114,32,102,111,114,32,116,104,101, + 32,115,112,101,99,105,102,105,101,100,32,109,111,100,117,108, + 101,44,32,111,114,32,116,104,101,32,110,97,109,101,115,112, + 97,99,101,10,32,32,32,32,32,32,32,32,112,97,99,107, + 97,103,101,32,112,111,114,116,105,111,110,115,46,32,82,101, + 116,117,114,110,115,32,40,108,111,97,100,101,114,44,32,108, + 105,115,116,45,111,102,45,112,111,114,116,105,111,110,115,41, + 46,70,117,1,0,0,0,46,105,2,0,0,0,105,1,0, + 0,0,117,8,0,0,0,95,95,105,110,105,116,95,95,84, + 78,105,255,255,255,255,40,16,0,0,0,117,10,0,0,0, + 114,112,97,114,116,105,116,105,111,110,117,3,0,0,0,95, + 111,115,117,4,0,0,0,115,116,97,116,117,4,0,0,0, + 112,97,116,104,117,8,0,0,0,115,116,95,109,116,105,109, + 101,117,7,0,0,0,79,83,69,114,114,111,114,117,11,0, + 0,0,95,112,97,116,104,95,109,116,105,109,101,117,11,0, + 0,0,95,102,105,108,108,95,99,97,99,104,101,117,11,0, + 0,0,95,114,101,108,97,120,95,99,97,115,101,117,19,0, + 0,0,95,114,101,108,97,120,101,100,95,112,97,116,104,95, + 99,97,99,104,101,117,5,0,0,0,108,111,119,101,114,117, + 11,0,0,0,95,112,97,116,104,95,99,97,99,104,101,117, + 10,0,0,0,95,112,97,116,104,95,106,111,105,110,117,11, + 0,0,0,95,112,97,116,104,95,105,115,100,105,114,117,8, + 0,0,0,95,108,111,97,100,101,114,115,117,12,0,0,0, + 95,112,97,116,104,95,105,115,102,105,108,101,40,12,0,0, + 0,117,4,0,0,0,115,101,108,102,117,8,0,0,0,102, + 117,108,108,110,97,109,101,117,12,0,0,0,105,115,95,110, + 97,109,101,115,112,97,99,101,117,11,0,0,0,116,97,105, + 108,95,109,111,100,117,108,101,117,5,0,0,0,109,116,105, + 109,101,117,5,0,0,0,99,97,99,104,101,117,12,0,0, + 0,99,97,99,104,101,95,109,111,100,117,108,101,117,9,0, + 0,0,98,97,115,101,95,112,97,116,104,117,6,0,0,0, + 115,117,102,102,105,120,117,6,0,0,0,108,111,97,100,101, + 114,117,13,0,0,0,105,110,105,116,95,102,105,108,101,110, + 97,109,101,117,9,0,0,0,102,117,108,108,95,112,97,116, + 104,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,11,0, + 0,0,102,105,110,100,95,108,111,97,100,101,114,84,5,0, + 0,115,62,0,0,0,0,3,6,1,19,1,3,1,25,1, + 13,1,11,1,15,1,10,1,12,2,9,1,9,1,15,2, + 9,1,6,2,12,1,18,1,12,1,22,1,10,1,15,1, + 12,1,26,4,12,2,22,1,16,1,22,1,12,1,26,1, + 6,1,13,1,117,22,0,0,0,70,105,108,101,70,105,110, + 100,101,114,46,102,105,110,100,95,108,111,97,100,101,114,99, + 1,0,0,0,0,0,0,0,9,0,0,0,13,0,0,0, + 67,0,0,0,115,8,1,0,0,124,0,0,106,0,0,125, + 1,0,121,19,0,116,1,0,106,2,0,124,1,0,131,1, + 0,125,2,0,87,110,33,0,4,116,3,0,116,4,0,116, + 5,0,102,3,0,107,10,0,114,63,0,1,1,1,103,0, + 0,125,2,0,89,110,1,0,88,116,6,0,106,7,0,106, + 8,0,100,1,0,131,1,0,115,100,0,116,9,0,124,2, + 0,131,1,0,124,0,0,95,10,0,110,111,0,116,9,0, + 131,0,0,125,3,0,120,90,0,124,2,0,68,93,82,0, + 125,4,0,124,4,0,106,11,0,100,2,0,131,1,0,92, + 3,0,125,5,0,125,6,0,125,7,0,124,6,0,114,179, + 0,100,3,0,106,12,0,124,5,0,124,7,0,106,13,0, + 131,0,0,131,2,0,125,8,0,110,6,0,124,5,0,125, + 8,0,124,3,0,106,14,0,124,8,0,131,1,0,1,113, + 116,0,87,124,3,0,124,0,0,95,10,0,116,6,0,106, + 7,0,106,8,0,116,15,0,131,1,0,114,4,1,116,9, + 0,100,4,0,100,5,0,132,0,0,124,2,0,68,131,1, + 0,131,1,0,124,0,0,95,16,0,110,0,0,100,6,0, 83,40,7,0,0,0,117,68,0,0,0,70,105,108,108,32, 116,104,101,32,99,97,99,104,101,32,111,102,32,112,111,116, 101,110,116,105,97,108,32,109,111,100,117,108,101,115,32,97, 110,100,32,112,97,99,107,97,103,101,115,32,102,111,114,32, - 116,104,105,115,32,100,105,114,101,99,116,111,114,121,46,114, - 0,0,0,0,114,101,0,0,0,117,5,0,0,0,123,125, - 46,123,125,99,1,0,0,0,0,0,0,0,2,0,0,0, - 3,0,0,0,83,0,0,0,115,28,0,0,0,104,0,0, - 124,0,0,93,18,0,125,1,0,124,1,0,106,0,0,131, - 0,0,146,2,0,113,6,0,83,114,4,0,0,0,40,1, - 0,0,0,114,124,0,0,0,40,2,0,0,0,114,22,0, - 0,0,116,2,0,0,0,102,110,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,245,9,0,0,0,60,115,101, - 116,99,111,109,112,62,175,5,0,0,115,2,0,0,0,9, - 0,117,41,0,0,0,70,105,108,101,70,105,110,100,101,114, - 46,95,102,105,108,108,95,99,97,99,104,101,46,60,108,111, - 99,97,108,115,62,46,60,115,101,116,99,111,109,112,62,78, - 40,17,0,0,0,114,35,0,0,0,114,3,0,0,0,116, - 7,0,0,0,108,105,115,116,100,105,114,244,17,0,0,0, - 70,105,108,101,78,111,116,70,111,117,110,100,69,114,114,111, - 114,244,15,0,0,0,80,101,114,109,105,115,115,105,111,110, - 69,114,114,111,114,244,18,0,0,0,78,111,116,65,68,105, - 114,101,99,116,111,114,121,69,114,114,111,114,114,7,0,0, - 0,114,8,0,0,0,114,9,0,0,0,114,42,1,0,0, - 114,43,1,0,0,114,106,0,0,0,114,46,0,0,0,114, - 124,0,0,0,244,3,0,0,0,97,100,100,114,10,0,0, - 0,114,44,1,0,0,40,9,0,0,0,114,75,0,0,0, - 114,35,0,0,0,116,8,0,0,0,99,111,110,116,101,110, - 116,115,116,21,0,0,0,108,111,119,101,114,95,115,117,102, - 102,105,120,95,99,111,110,116,101,110,116,115,114,24,1,0, - 0,114,71,0,0,0,114,18,1,0,0,114,9,1,0,0, - 116,8,0,0,0,110,101,119,95,110,97,109,101,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,114,46,1,0, - 0,146,5,0,0,115,34,0,0,0,0,2,9,1,3,1, - 19,1,22,3,11,3,18,1,18,7,9,1,13,1,24,1, - 6,1,27,2,6,1,17,1,9,1,18,1,117,22,0,0, - 0,70,105,108,101,70,105,110,100,101,114,46,95,102,105,108, - 108,95,99,97,99,104,101,99,1,0,0,0,0,0,0,0, - 3,0,0,0,3,0,0,0,7,0,0,0,115,25,0,0, - 0,135,0,0,135,1,0,102,2,0,100,1,0,100,2,0, - 134,0,0,125,2,0,124,2,0,83,40,3,0,0,0,117, - 20,1,0,0,65,32,99,108,97,115,115,32,109,101,116,104, - 111,100,32,119,104,105,99,104,32,114,101,116,117,114,110,115, - 32,97,32,99,108,111,115,117,114,101,32,116,111,32,117,115, - 101,32,111,110,32,115,121,115,46,112,97,116,104,95,104,111, - 111,107,10,32,32,32,32,32,32,32,32,119,104,105,99,104, - 32,119,105,108,108,32,114,101,116,117,114,110,32,97,110,32, - 105,110,115,116,97,110,99,101,32,117,115,105,110,103,32,116, - 104,101,32,115,112,101,99,105,102,105,101,100,32,108,111,97, - 100,101,114,115,32,97,110,100,32,116,104,101,32,112,97,116, - 104,10,32,32,32,32,32,32,32,32,99,97,108,108,101,100, - 32,111,110,32,116,104,101,32,99,108,111,115,117,114,101,46, - 10,10,32,32,32,32,32,32,32,32,73,102,32,116,104,101, - 32,112,97,116,104,32,99,97,108,108,101,100,32,111,110,32, - 116,104,101,32,99,108,111,115,117,114,101,32,105,115,32,110, - 111,116,32,97,32,100,105,114,101,99,116,111,114,121,44,32, - 73,109,112,111,114,116,69,114,114,111,114,32,105,115,10,32, - 32,32,32,32,32,32,32,114,97,105,115,101,100,46,10,10, - 32,32,32,32,32,32,32,32,99,1,0,0,0,0,0,0, - 0,1,0,0,0,4,0,0,0,19,0,0,0,115,46,0, - 0,0,116,0,0,124,0,0,131,1,0,115,33,0,116,1, - 0,100,1,0,100,2,0,124,0,0,131,1,1,130,1,0, - 110,0,0,136,0,0,124,0,0,136,1,0,140,1,0,83, - 40,3,0,0,0,117,45,0,0,0,80,97,116,104,32,104, - 111,111,107,32,102,111,114,32,105,109,112,111,114,116,108,105, - 98,46,109,97,99,104,105,110,101,114,121,46,70,105,108,101, - 70,105,110,100,101,114,46,117,30,0,0,0,111,110,108,121, - 32,100,105,114,101,99,116,111,114,105,101,115,32,97,114,101, - 32,115,117,112,112,111,114,116,101,100,114,35,0,0,0,40, - 2,0,0,0,114,45,0,0,0,114,157,0,0,0,40,1, - 0,0,0,114,35,0,0,0,40,2,0,0,0,114,215,0, - 0,0,114,45,1,0,0,114,4,0,0,0,114,5,0,0, - 0,244,24,0,0,0,112,97,116,104,95,104,111,111,107,95, - 102,111,114,95,70,105,108,101,70,105,110,100,101,114,187,5, - 0,0,115,6,0,0,0,0,2,12,1,21,1,117,54,0, + 116,104,105,115,32,100,105,114,101,99,116,111,114,121,46,117, + 3,0,0,0,119,105,110,117,1,0,0,0,46,117,5,0, + 0,0,123,125,46,123,125,99,1,0,0,0,0,0,0,0, + 2,0,0,0,2,0,0,0,115,0,0,0,115,27,0,0, + 0,124,0,0,93,17,0,125,1,0,124,1,0,106,0,0, + 131,0,0,86,1,113,3,0,100,0,0,83,40,1,0,0, + 0,78,40,1,0,0,0,117,5,0,0,0,108,111,119,101, + 114,40,2,0,0,0,117,2,0,0,0,46,48,117,2,0, + 0,0,102,110,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,9,0,0,0,60,103,101,110,101,120,112,114,62,155,5, + 0,0,115,2,0,0,0,6,0,117,41,0,0,0,70,105, + 108,101,70,105,110,100,101,114,46,95,102,105,108,108,95,99, + 97,99,104,101,46,60,108,111,99,97,108,115,62,46,60,103, + 101,110,101,120,112,114,62,78,40,17,0,0,0,117,4,0, + 0,0,112,97,116,104,117,3,0,0,0,95,111,115,117,7, + 0,0,0,108,105,115,116,100,105,114,117,17,0,0,0,70, + 105,108,101,78,111,116,70,111,117,110,100,69,114,114,111,114, + 117,15,0,0,0,80,101,114,109,105,115,115,105,111,110,69, + 114,114,111,114,117,18,0,0,0,78,111,116,65,68,105,114, + 101,99,116,111,114,121,69,114,114,111,114,117,3,0,0,0, + 115,121,115,117,8,0,0,0,112,108,97,116,102,111,114,109, + 117,10,0,0,0,115,116,97,114,116,115,119,105,116,104,117, + 3,0,0,0,115,101,116,117,11,0,0,0,95,112,97,116, + 104,95,99,97,99,104,101,117,9,0,0,0,112,97,114,116, + 105,116,105,111,110,117,6,0,0,0,102,111,114,109,97,116, + 117,5,0,0,0,108,111,119,101,114,117,3,0,0,0,97, + 100,100,117,27,0,0,0,95,67,65,83,69,95,73,78,83, + 69,78,83,73,84,73,86,69,95,80,76,65,84,70,79,82, + 77,83,117,19,0,0,0,95,114,101,108,97,120,101,100,95, + 112,97,116,104,95,99,97,99,104,101,40,9,0,0,0,117, + 4,0,0,0,115,101,108,102,117,4,0,0,0,112,97,116, + 104,117,8,0,0,0,99,111,110,116,101,110,116,115,117,21, + 0,0,0,108,111,119,101,114,95,115,117,102,102,105,120,95, + 99,111,110,116,101,110,116,115,117,4,0,0,0,105,116,101, + 109,117,4,0,0,0,110,97,109,101,117,3,0,0,0,100, + 111,116,117,6,0,0,0,115,117,102,102,105,120,117,8,0, + 0,0,110,101,119,95,110,97,109,101,40,0,0,0,0,40, + 0,0,0,0,117,29,0,0,0,60,102,114,111,122,101,110, + 32,105,109,112,111,114,116,108,105,98,46,95,98,111,111,116, + 115,116,114,97,112,62,117,11,0,0,0,95,102,105,108,108, + 95,99,97,99,104,101,126,5,0,0,115,34,0,0,0,0, + 2,9,1,3,1,19,1,22,3,11,3,18,1,18,7,9, + 1,13,1,24,1,6,1,27,2,6,1,17,1,9,1,18, + 1,117,22,0,0,0,70,105,108,101,70,105,110,100,101,114, + 46,95,102,105,108,108,95,99,97,99,104,101,99,1,0,0, + 0,0,0,0,0,3,0,0,0,3,0,0,0,7,0,0, + 0,115,25,0,0,0,135,0,0,135,1,0,102,2,0,100, + 1,0,100,2,0,134,0,0,125,2,0,124,2,0,83,40, + 3,0,0,0,117,20,1,0,0,65,32,99,108,97,115,115, + 32,109,101,116,104,111,100,32,119,104,105,99,104,32,114,101, + 116,117,114,110,115,32,97,32,99,108,111,115,117,114,101,32, + 116,111,32,117,115,101,32,111,110,32,115,121,115,46,112,97, + 116,104,95,104,111,111,107,10,32,32,32,32,32,32,32,32, + 119,104,105,99,104,32,119,105,108,108,32,114,101,116,117,114, + 110,32,97,110,32,105,110,115,116,97,110,99,101,32,117,115, + 105,110,103,32,116,104,101,32,115,112,101,99,105,102,105,101, + 100,32,108,111,97,100,101,114,115,32,97,110,100,32,116,104, + 101,32,112,97,116,104,10,32,32,32,32,32,32,32,32,99, + 97,108,108,101,100,32,111,110,32,116,104,101,32,99,108,111, + 115,117,114,101,46,10,10,32,32,32,32,32,32,32,32,73, + 102,32,116,104,101,32,112,97,116,104,32,99,97,108,108,101, + 100,32,111,110,32,116,104,101,32,99,108,111,115,117,114,101, + 32,105,115,32,110,111,116,32,97,32,100,105,114,101,99,116, + 111,114,121,44,32,73,109,112,111,114,116,69,114,114,111,114, + 32,105,115,10,32,32,32,32,32,32,32,32,114,97,105,115, + 101,100,46,10,10,32,32,32,32,32,32,32,32,99,1,0, + 0,0,0,0,0,0,1,0,0,0,4,0,0,0,19,0, + 0,0,115,46,0,0,0,116,0,0,124,0,0,131,1,0, + 115,33,0,116,1,0,100,1,0,100,2,0,124,0,0,131, + 1,1,130,1,0,110,0,0,136,0,0,124,0,0,136,1, + 0,140,1,0,83,40,3,0,0,0,117,45,0,0,0,80, + 97,116,104,32,104,111,111,107,32,102,111,114,32,105,109,112, + 111,114,116,108,105,98,46,109,97,99,104,105,110,101,114,121, + 46,70,105,108,101,70,105,110,100,101,114,46,117,30,0,0, + 0,111,110,108,121,32,100,105,114,101,99,116,111,114,105,101, + 115,32,97,114,101,32,115,117,112,112,111,114,116,101,100,117, + 4,0,0,0,112,97,116,104,40,2,0,0,0,117,11,0, + 0,0,95,112,97,116,104,95,105,115,100,105,114,117,11,0, + 0,0,73,109,112,111,114,116,69,114,114,111,114,40,1,0, + 0,0,117,4,0,0,0,112,97,116,104,40,2,0,0,0, + 117,3,0,0,0,99,108,115,117,14,0,0,0,108,111,97, + 100,101,114,95,100,101,116,97,105,108,115,40,0,0,0,0, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,24,0,0,0,112,97,116,104,95,104,111,111,107, + 95,102,111,114,95,70,105,108,101,70,105,110,100,101,114,167, + 5,0,0,115,6,0,0,0,0,2,12,1,21,1,117,54, + 0,0,0,70,105,108,101,70,105,110,100,101,114,46,112,97, + 116,104,95,104,111,111,107,46,60,108,111,99,97,108,115,62, + 46,112,97,116,104,95,104,111,111,107,95,102,111,114,95,70, + 105,108,101,70,105,110,100,101,114,40,0,0,0,0,40,3, + 0,0,0,117,3,0,0,0,99,108,115,117,14,0,0,0, + 108,111,97,100,101,114,95,100,101,116,97,105,108,115,117,24, + 0,0,0,112,97,116,104,95,104,111,111,107,95,102,111,114, + 95,70,105,108,101,70,105,110,100,101,114,40,0,0,0,0, + 40,2,0,0,0,117,3,0,0,0,99,108,115,117,14,0, + 0,0,108,111,97,100,101,114,95,100,101,116,97,105,108,115, + 117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112, + 111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97, + 112,62,117,9,0,0,0,112,97,116,104,95,104,111,111,107, + 157,5,0,0,115,4,0,0,0,0,10,21,6,117,20,0, 0,0,70,105,108,101,70,105,110,100,101,114,46,112,97,116, - 104,95,104,111,111,107,46,60,108,111,99,97,108,115,62,46, - 112,97,116,104,95,104,111,111,107,95,102,111,114,95,70,105, - 108,101,70,105,110,100,101,114,114,4,0,0,0,40,3,0, - 0,0,114,215,0,0,0,114,45,1,0,0,114,52,1,0, - 0,114,4,0,0,0,40,2,0,0,0,114,215,0,0,0, - 114,45,1,0,0,114,5,0,0,0,244,9,0,0,0,112, - 97,116,104,95,104,111,111,107,177,5,0,0,115,4,0,0, - 0,0,10,21,6,117,20,0,0,0,70,105,108,101,70,105, - 110,100,101,114,46,112,97,116,104,95,104,111,111,107,99,1, - 0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,67, - 0,0,0,115,16,0,0,0,100,1,0,106,0,0,124,0, - 0,106,1,0,131,1,0,83,40,2,0,0,0,78,117,16, - 0,0,0,70,105,108,101,70,105,110,100,101,114,40,123,33, - 114,125,41,40,2,0,0,0,114,46,0,0,0,114,35,0, - 0,0,40,1,0,0,0,114,75,0,0,0,114,4,0,0, - 0,114,4,0,0,0,114,5,0,0,0,114,87,0,0,0, - 195,5,0,0,115,2,0,0,0,0,1,117,19,0,0,0, - 70,105,108,101,70,105,110,100,101,114,46,95,95,114,101,112, - 114,95,95,78,40,13,0,0,0,114,56,0,0,0,114,55, - 0,0,0,114,57,0,0,0,114,58,0,0,0,114,76,0, - 0,0,114,28,1,0,0,114,190,0,0,0,114,217,0,0, - 0,114,184,0,0,0,114,46,1,0,0,114,221,0,0,0, - 114,53,1,0,0,114,87,0,0,0,114,4,0,0,0,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,114,39, - 1,0,0,73,5,0,0,115,16,0,0,0,12,7,6,2, - 12,14,12,4,6,2,12,44,12,31,18,18,114,39,1,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,2,0, - 0,0,64,0,0,0,115,46,0,0,0,101,0,0,90,1, - 0,100,0,0,90,2,0,100,1,0,90,3,0,100,2,0, - 100,3,0,132,0,0,90,4,0,100,4,0,100,5,0,132, - 0,0,90,5,0,100,6,0,83,40,7,0,0,0,244,18, + 104,95,104,111,111,107,99,1,0,0,0,0,0,0,0,1, + 0,0,0,2,0,0,0,67,0,0,0,115,16,0,0,0, + 100,1,0,106,0,0,124,0,0,106,1,0,131,1,0,83, + 40,2,0,0,0,78,117,16,0,0,0,70,105,108,101,70, + 105,110,100,101,114,40,123,33,114,125,41,40,2,0,0,0, + 117,6,0,0,0,102,111,114,109,97,116,117,4,0,0,0, + 112,97,116,104,40,1,0,0,0,117,4,0,0,0,115,101, + 108,102,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,8, + 0,0,0,95,95,114,101,112,114,95,95,175,5,0,0,115, + 2,0,0,0,0,1,117,19,0,0,0,70,105,108,101,70, + 105,110,100,101,114,46,95,95,114,101,112,114,95,95,78,40, + 13,0,0,0,117,8,0,0,0,95,95,110,97,109,101,95, + 95,117,10,0,0,0,95,95,109,111,100,117,108,101,95,95, + 117,12,0,0,0,95,95,113,117,97,108,110,97,109,101,95, + 95,117,7,0,0,0,95,95,100,111,99,95,95,117,8,0, + 0,0,95,95,105,110,105,116,95,95,117,17,0,0,0,105, + 110,118,97,108,105,100,97,116,101,95,99,97,99,104,101,115, + 117,17,0,0,0,95,102,105,110,100,95,109,111,100,117,108, + 101,95,115,104,105,109,117,11,0,0,0,102,105,110,100,95, + 109,111,100,117,108,101,117,11,0,0,0,102,105,110,100,95, + 108,111,97,100,101,114,117,11,0,0,0,95,102,105,108,108, + 95,99,97,99,104,101,117,11,0,0,0,99,108,97,115,115, + 109,101,116,104,111,100,117,9,0,0,0,112,97,116,104,95, + 104,111,111,107,117,8,0,0,0,95,95,114,101,112,114,95, + 95,40,1,0,0,0,117,10,0,0,0,95,95,108,111,99, + 97,108,115,95,95,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,10,0,0,0,70,105,108,101,70,105,110,100,101,114, + 55,5,0,0,115,16,0,0,0,16,7,6,2,12,14,12, + 4,6,2,12,42,12,31,18,18,117,10,0,0,0,70,105, + 108,101,70,105,110,100,101,114,99,1,0,0,0,0,0,0, + 0,1,0,0,0,2,0,0,0,66,0,0,0,115,50,0, + 0,0,124,0,0,69,101,0,0,90,1,0,100,0,0,90, + 2,0,100,1,0,90,3,0,100,2,0,100,3,0,132,0, + 0,90,4,0,100,4,0,100,5,0,132,0,0,90,5,0, + 100,6,0,83,40,7,0,0,0,117,18,0,0,0,95,73, + 109,112,111,114,116,76,111,99,107,67,111,110,116,101,120,116, + 117,36,0,0,0,67,111,110,116,101,120,116,32,109,97,110, + 97,103,101,114,32,102,111,114,32,116,104,101,32,105,109,112, + 111,114,116,32,108,111,99,107,46,99,1,0,0,0,0,0, + 0,0,1,0,0,0,1,0,0,0,67,0,0,0,115,14, + 0,0,0,116,0,0,106,1,0,131,0,0,1,100,1,0, + 83,40,2,0,0,0,117,24,0,0,0,65,99,113,117,105, + 114,101,32,116,104,101,32,105,109,112,111,114,116,32,108,111, + 99,107,46,78,40,2,0,0,0,117,4,0,0,0,95,105, + 109,112,117,12,0,0,0,97,99,113,117,105,114,101,95,108, + 111,99,107,40,1,0,0,0,117,4,0,0,0,115,101,108, + 102,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0, + 60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105, + 98,46,95,98,111,111,116,115,116,114,97,112,62,117,9,0, + 0,0,95,95,101,110,116,101,114,95,95,185,5,0,0,115, + 2,0,0,0,0,2,117,28,0,0,0,95,73,109,112,111, + 114,116,76,111,99,107,67,111,110,116,101,120,116,46,95,95, + 101,110,116,101,114,95,95,99,4,0,0,0,0,0,0,0, + 4,0,0,0,1,0,0,0,67,0,0,0,115,14,0,0, + 0,116,0,0,106,1,0,131,0,0,1,100,1,0,83,40, + 2,0,0,0,117,60,0,0,0,82,101,108,101,97,115,101, + 32,116,104,101,32,105,109,112,111,114,116,32,108,111,99,107, + 32,114,101,103,97,114,100,108,101,115,115,32,111,102,32,97, + 110,121,32,114,97,105,115,101,100,32,101,120,99,101,112,116, + 105,111,110,115,46,78,40,2,0,0,0,117,4,0,0,0, + 95,105,109,112,117,12,0,0,0,114,101,108,101,97,115,101, + 95,108,111,99,107,40,4,0,0,0,117,4,0,0,0,115, + 101,108,102,117,8,0,0,0,101,120,99,95,116,121,112,101, + 117,9,0,0,0,101,120,99,95,118,97,108,117,101,117,13, + 0,0,0,101,120,99,95,116,114,97,99,101,98,97,99,107, + 40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,8,0,0, + 0,95,95,101,120,105,116,95,95,189,5,0,0,115,2,0, + 0,0,0,2,117,27,0,0,0,95,73,109,112,111,114,116, + 76,111,99,107,67,111,110,116,101,120,116,46,95,95,101,120, + 105,116,95,95,78,40,6,0,0,0,117,8,0,0,0,95, + 95,110,97,109,101,95,95,117,10,0,0,0,95,95,109,111, + 100,117,108,101,95,95,117,12,0,0,0,95,95,113,117,97, + 108,110,97,109,101,95,95,117,7,0,0,0,95,95,100,111, + 99,95,95,117,9,0,0,0,95,95,101,110,116,101,114,95, + 95,117,8,0,0,0,95,95,101,120,105,116,95,95,40,1, + 0,0,0,117,10,0,0,0,95,95,108,111,99,97,108,115, + 95,95,40,0,0,0,0,40,0,0,0,0,117,29,0,0, + 0,60,102,114,111,122,101,110,32,105,109,112,111,114,116,108, + 105,98,46,95,98,111,111,116,115,116,114,97,112,62,117,18, 0,0,0,95,73,109,112,111,114,116,76,111,99,107,67,111, - 110,116,101,120,116,117,36,0,0,0,67,111,110,116,101,120, - 116,32,109,97,110,97,103,101,114,32,102,111,114,32,116,104, - 101,32,105,109,112,111,114,116,32,108,111,99,107,46,99,1, - 0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,67, - 0,0,0,115,14,0,0,0,116,0,0,106,1,0,131,0, - 0,1,100,1,0,83,40,2,0,0,0,117,24,0,0,0, - 65,99,113,117,105,114,101,32,116,104,101,32,105,109,112,111, - 114,116,32,108,111,99,107,46,78,40,2,0,0,0,114,94, - 0,0,0,244,12,0,0,0,97,99,113,117,105,114,101,95, - 108,111,99,107,40,1,0,0,0,114,75,0,0,0,114,4, - 0,0,0,114,4,0,0,0,114,5,0,0,0,114,142,0, - 0,0,205,5,0,0,115,2,0,0,0,0,2,117,28,0, - 0,0,95,73,109,112,111,114,116,76,111,99,107,67,111,110, - 116,101,120,116,46,95,95,101,110,116,101,114,95,95,99,4, - 0,0,0,0,0,0,0,4,0,0,0,1,0,0,0,67, - 0,0,0,115,14,0,0,0,116,0,0,106,1,0,131,0, - 0,1,100,1,0,83,40,2,0,0,0,117,60,0,0,0, - 82,101,108,101,97,115,101,32,116,104,101,32,105,109,112,111, - 114,116,32,108,111,99,107,32,114,101,103,97,114,100,108,101, - 115,115,32,111,102,32,97,110,121,32,114,97,105,115,101,100, - 32,101,120,99,101,112,116,105,111,110,115,46,78,40,2,0, - 0,0,114,94,0,0,0,114,95,0,0,0,40,4,0,0, - 0,114,75,0,0,0,116,8,0,0,0,101,120,99,95,116, - 121,112,101,116,9,0,0,0,101,120,99,95,118,97,108,117, - 101,116,13,0,0,0,101,120,99,95,116,114,97,99,101,98, - 97,99,107,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,145,0,0,0,209,5,0,0,115,2,0,0,0, - 0,2,117,27,0,0,0,95,73,109,112,111,114,116,76,111, - 99,107,67,111,110,116,101,120,116,46,95,95,101,120,105,116, - 95,95,78,40,6,0,0,0,114,56,0,0,0,114,55,0, - 0,0,114,57,0,0,0,114,58,0,0,0,114,142,0,0, - 0,114,145,0,0,0,114,4,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,114,54,1,0,0,201, - 5,0,0,115,6,0,0,0,12,2,6,2,12,4,114,54, - 1,0,0,99,3,0,0,0,0,0,0,0,5,0,0,0, - 4,0,0,0,67,0,0,0,115,91,0,0,0,124,1,0, - 106,0,0,100,1,0,124,2,0,100,2,0,24,131,2,0, - 125,3,0,116,1,0,124,3,0,131,1,0,124,2,0,107, - 0,0,114,55,0,116,2,0,100,3,0,131,1,0,130,1, - 0,110,0,0,124,3,0,100,4,0,25,125,4,0,124,0, - 0,114,87,0,100,5,0,106,3,0,124,4,0,124,0,0, - 131,2,0,83,124,4,0,83,40,6,0,0,0,117,50,0, - 0,0,82,101,115,111,108,118,101,32,97,32,114,101,108,97, - 116,105,118,101,32,109,111,100,117,108,101,32,110,97,109,101, - 32,116,111,32,97,110,32,97,98,115,111,108,117,116,101,32, - 111,110,101,46,114,101,0,0,0,114,29,0,0,0,117,50, - 0,0,0,97,116,116,101,109,112,116,101,100,32,114,101,108, - 97,116,105,118,101,32,105,109,112,111,114,116,32,98,101,121, - 111,110,100,32,116,111,112,45,108,101,118,101,108,32,112,97, - 99,107,97,103,101,114,67,0,0,0,117,5,0,0,0,123, - 125,46,123,125,40,4,0,0,0,114,34,0,0,0,114,31, - 0,0,0,114,118,0,0,0,114,46,0,0,0,40,5,0, - 0,0,114,71,0,0,0,244,7,0,0,0,112,97,99,107, - 97,103,101,244,5,0,0,0,108,101,118,101,108,116,4,0, - 0,0,98,105,116,115,116,4,0,0,0,98,97,115,101,114, - 4,0,0,0,114,4,0,0,0,114,5,0,0,0,244,13, - 0,0,0,95,114,101,115,111,108,118,101,95,110,97,109,101, - 214,5,0,0,115,10,0,0,0,0,2,22,1,18,1,15, - 1,10,1,114,58,1,0,0,99,2,0,0,0,0,0,0, + 110,116,101,120,116,181,5,0,0,115,6,0,0,0,16,2, + 6,2,12,4,117,18,0,0,0,95,73,109,112,111,114,116, + 76,111,99,107,67,111,110,116,101,120,116,99,3,0,0,0, + 0,0,0,0,5,0,0,0,4,0,0,0,67,0,0,0, + 115,91,0,0,0,124,1,0,106,0,0,100,1,0,124,2, + 0,100,2,0,24,131,2,0,125,3,0,116,1,0,124,3, + 0,131,1,0,124,2,0,107,0,0,114,55,0,116,2,0, + 100,3,0,131,1,0,130,1,0,110,0,0,124,3,0,100, + 4,0,25,125,4,0,124,0,0,114,87,0,100,5,0,106, + 3,0,124,4,0,124,0,0,131,2,0,83,124,4,0,83, + 40,6,0,0,0,117,50,0,0,0,82,101,115,111,108,118, + 101,32,97,32,114,101,108,97,116,105,118,101,32,109,111,100, + 117,108,101,32,110,97,109,101,32,116,111,32,97,110,32,97, + 98,115,111,108,117,116,101,32,111,110,101,46,117,1,0,0, + 0,46,105,1,0,0,0,117,50,0,0,0,97,116,116,101, + 109,112,116,101,100,32,114,101,108,97,116,105,118,101,32,105, + 109,112,111,114,116,32,98,101,121,111,110,100,32,116,111,112, + 45,108,101,118,101,108,32,112,97,99,107,97,103,101,105,0, + 0,0,0,117,5,0,0,0,123,125,46,123,125,40,4,0, + 0,0,117,6,0,0,0,114,115,112,108,105,116,117,3,0, + 0,0,108,101,110,117,10,0,0,0,86,97,108,117,101,69, + 114,114,111,114,117,6,0,0,0,102,111,114,109,97,116,40, + 5,0,0,0,117,4,0,0,0,110,97,109,101,117,7,0, + 0,0,112,97,99,107,97,103,101,117,5,0,0,0,108,101, + 118,101,108,117,4,0,0,0,98,105,116,115,117,4,0,0, + 0,98,97,115,101,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,13,0,0,0,95,114,101,115,111,108,118,101,95,110, + 97,109,101,194,5,0,0,115,10,0,0,0,0,2,22,1, + 18,1,15,1,10,1,117,13,0,0,0,95,114,101,115,111, + 108,118,101,95,110,97,109,101,99,2,0,0,0,0,0,0, 0,4,0,0,0,11,0,0,0,67,0,0,0,115,138,0, 0,0,116,0,0,106,1,0,115,28,0,116,2,0,106,3, 0,100,1,0,116,4,0,131,2,0,1,110,0,0,120,103, @@ -3131,521 +3726,706 @@ 0,117,23,0,0,0,70,105,110,100,32,97,32,109,111,100, 117,108,101,39,115,32,108,111,97,100,101,114,46,117,22,0, 0,0,115,121,115,46,109,101,116,97,95,112,97,116,104,32, - 105,115,32,101,109,112,116,121,78,40,9,0,0,0,114,7, - 0,0,0,244,9,0,0,0,109,101,116,97,95,112,97,116, - 104,114,185,0,0,0,114,186,0,0,0,114,187,0,0,0, - 114,54,1,0,0,114,217,0,0,0,114,140,0,0,0,114, - 171,0,0,0,40,4,0,0,0,114,71,0,0,0,114,35, - 0,0,0,114,31,1,0,0,114,160,0,0,0,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,244,12,0,0, - 0,95,102,105,110,100,95,109,111,100,117,108,101,223,5,0, - 0,115,20,0,0,0,0,2,9,1,19,1,16,1,10,1, - 24,1,12,2,15,1,4,2,21,2,114,60,1,0,0,99, - 3,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0, - 67,0,0,0,115,194,0,0,0,116,0,0,124,0,0,116, - 1,0,131,2,0,115,45,0,116,2,0,100,1,0,106,3, - 0,116,4,0,124,0,0,131,1,0,131,1,0,131,1,0, - 130,1,0,110,0,0,124,2,0,100,2,0,107,0,0,114, - 72,0,116,5,0,100,3,0,131,1,0,130,1,0,110,0, - 0,124,1,0,114,156,0,116,0,0,124,1,0,116,1,0, - 131,2,0,115,108,0,116,2,0,100,4,0,131,1,0,130, - 1,0,113,156,0,124,1,0,116,6,0,106,7,0,107,7, - 0,114,156,0,100,5,0,125,3,0,116,8,0,124,3,0, - 106,3,0,124,1,0,131,1,0,131,1,0,130,1,0,113, - 156,0,110,0,0,124,0,0,12,114,190,0,124,2,0,100, - 2,0,107,2,0,114,190,0,116,5,0,100,6,0,131,1, - 0,130,1,0,110,0,0,100,7,0,83,40,8,0,0,0, - 117,28,0,0,0,86,101,114,105,102,121,32,97,114,103,117, - 109,101,110,116,115,32,97,114,101,32,34,115,97,110,101,34, - 46,117,31,0,0,0,109,111,100,117,108,101,32,110,97,109, - 101,32,109,117,115,116,32,98,101,32,115,116,114,44,32,110, - 111,116,32,123,125,114,67,0,0,0,117,18,0,0,0,108, - 101,118,101,108,32,109,117,115,116,32,98,101,32,62,61,32, - 48,117,31,0,0,0,95,95,112,97,99,107,97,103,101,95, - 95,32,110,111,116,32,115,101,116,32,116,111,32,97,32,115, - 116,114,105,110,103,117,61,0,0,0,80,97,114,101,110,116, - 32,109,111,100,117,108,101,32,123,33,114,125,32,110,111,116, - 32,108,111,97,100,101,100,44,32,99,97,110,110,111,116,32, - 112,101,114,102,111,114,109,32,114,101,108,97,116,105,118,101, - 32,105,109,112,111,114,116,117,17,0,0,0,69,109,112,116, - 121,32,109,111,100,117,108,101,32,110,97,109,101,78,40,9, - 0,0,0,114,202,0,0,0,114,35,1,0,0,244,9,0, - 0,0,84,121,112,101,69,114,114,111,114,114,46,0,0,0, - 114,152,0,0,0,114,118,0,0,0,114,7,0,0,0,114, - 140,0,0,0,244,11,0,0,0,83,121,115,116,101,109,69, - 114,114,111,114,40,4,0,0,0,114,71,0,0,0,114,56, - 1,0,0,114,57,1,0,0,114,189,0,0,0,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,244,13,0,0, - 0,95,115,97,110,105,116,121,95,99,104,101,99,107,240,5, - 0,0,115,24,0,0,0,0,2,15,1,30,1,12,1,15, - 1,6,1,15,1,15,1,15,1,6,2,27,1,19,1,114, - 63,1,0,0,117,16,0,0,0,78,111,32,109,111,100,117, - 108,101,32,110,97,109,101,100,32,117,4,0,0,0,123,33, - 114,125,99,2,0,0,0,0,0,0,0,8,0,0,0,27, - 0,0,0,67,0,0,0,115,6,2,0,0,100,0,0,125, - 2,0,124,0,0,106,0,0,100,1,0,131,1,0,100,2, - 0,25,125,3,0,124,3,0,114,178,0,124,3,0,116,1, - 0,106,2,0,107,7,0,114,62,0,116,3,0,124,1,0, - 124,3,0,131,2,0,1,110,0,0,124,0,0,116,1,0, - 106,2,0,107,6,0,114,88,0,116,1,0,106,2,0,124, - 0,0,25,83,116,1,0,106,2,0,124,3,0,25,125,4, - 0,121,13,0,124,4,0,106,4,0,125,2,0,87,113,178, - 0,4,116,5,0,107,10,0,114,174,0,1,1,1,116,6, - 0,100,3,0,23,106,7,0,124,0,0,124,3,0,131,2, - 0,125,5,0,116,8,0,124,5,0,100,4,0,124,0,0, - 131,1,1,130,1,0,89,113,178,0,88,110,0,0,116,9, - 0,124,0,0,124,2,0,131,2,0,125,6,0,124,6,0, - 100,0,0,107,8,0,114,235,0,116,8,0,116,6,0,106, - 7,0,124,0,0,131,1,0,100,4,0,124,0,0,131,1, - 1,130,1,0,110,47,0,124,0,0,116,1,0,106,2,0, - 107,7,0,114,26,1,124,6,0,106,10,0,124,0,0,131, - 1,0,1,116,11,0,100,5,0,124,0,0,124,6,0,131, - 3,0,1,110,0,0,116,1,0,106,2,0,124,0,0,25, - 125,7,0,124,3,0,114,90,1,116,1,0,106,2,0,124, - 3,0,25,125,4,0,116,12,0,124,4,0,124,0,0,106, - 0,0,100,1,0,131,1,0,100,6,0,25,124,7,0,131, - 3,0,1,110,0,0,116,13,0,124,7,0,100,7,0,100, - 0,0,131,3,0,100,0,0,107,8,0,114,197,1,121,59, - 0,124,7,0,106,14,0,124,7,0,95,15,0,116,16,0, - 124,7,0,100,8,0,131,2,0,115,172,1,124,7,0,106, - 15,0,106,0,0,100,1,0,131,1,0,100,2,0,25,124, - 7,0,95,15,0,110,0,0,87,113,197,1,4,116,5,0, - 107,10,0,114,193,1,1,1,1,89,113,197,1,88,110,0, - 0,116,13,0,124,7,0,100,9,0,100,0,0,131,3,0, - 100,0,0,107,8,0,114,2,2,121,13,0,124,6,0,124, - 7,0,95,17,0,87,113,2,2,4,116,5,0,107,10,0, - 114,254,1,1,1,1,89,113,2,2,88,110,0,0,124,7, - 0,83,40,10,0,0,0,78,114,101,0,0,0,114,67,0, - 0,0,117,21,0,0,0,59,32,123,125,32,105,115,32,110, - 111,116,32,97,32,112,97,99,107,97,103,101,114,71,0,0, - 0,117,18,0,0,0,105,109,112,111,114,116,32,123,33,114, - 125,32,35,32,123,33,114,125,114,100,0,0,0,114,158,0, - 0,0,114,159,0,0,0,114,171,0,0,0,40,18,0,0, - 0,114,32,0,0,0,114,7,0,0,0,114,140,0,0,0, - 114,99,0,0,0,114,159,0,0,0,114,154,0,0,0,244, - 8,0,0,0,95,69,82,82,95,77,83,71,114,46,0,0, - 0,114,157,0,0,0,114,60,1,0,0,114,218,0,0,0, - 114,137,0,0,0,114,60,0,0,0,114,61,0,0,0,114, - 56,0,0,0,114,158,0,0,0,114,59,0,0,0,114,171, - 0,0,0,40,8,0,0,0,114,71,0,0,0,244,7,0, - 0,0,105,109,112,111,114,116,95,114,35,0,0,0,114,6, - 1,0,0,116,13,0,0,0,112,97,114,101,110,116,95,109, - 111,100,117,108,101,114,189,0,0,0,114,160,0,0,0,114, - 161,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,244,23,0,0,0,95,102,105,110,100,95,97,110, - 100,95,108,111,97,100,95,117,110,108,111,99,107,101,100,4, - 6,0,0,115,72,0,0,0,0,1,6,1,19,1,6,1, - 15,1,16,2,15,1,11,2,13,1,3,1,13,1,13,1, - 22,1,26,1,15,1,12,1,30,1,15,2,13,1,19,2, - 13,1,6,2,13,1,32,2,24,1,3,1,12,1,15,1, - 32,1,13,1,8,2,24,1,3,1,13,1,13,1,8,1, - 114,66,1,0,0,99,2,0,0,0,0,0,0,0,3,0, - 0,0,18,0,0,0,67,0,0,0,115,75,0,0,0,122, - 16,0,116,0,0,124,0,0,131,1,0,125,2,0,87,100, - 1,0,116,1,0,106,2,0,131,0,0,1,88,124,2,0, - 106,3,0,131,0,0,1,122,17,0,116,4,0,124,0,0, - 124,1,0,131,2,0,83,87,100,1,0,124,2,0,106,5, - 0,131,0,0,1,88,100,1,0,83,40,2,0,0,0,117, - 54,0,0,0,70,105,110,100,32,97,110,100,32,108,111,97, - 100,32,116,104,101,32,109,111,100,117,108,101,44,32,97,110, - 100,32,114,101,108,101,97,115,101,32,116,104,101,32,105,109, - 112,111,114,116,32,108,111,99,107,46,78,40,6,0,0,0, - 114,93,0,0,0,114,94,0,0,0,114,95,0,0,0,114, - 83,0,0,0,114,66,1,0,0,114,84,0,0,0,40,3, - 0,0,0,114,71,0,0,0,114,65,1,0,0,114,69,0, - 0,0,114,4,0,0,0,114,4,0,0,0,114,5,0,0, - 0,244,14,0,0,0,95,102,105,110,100,95,97,110,100,95, - 108,111,97,100,50,6,0,0,115,14,0,0,0,0,2,3, - 1,16,2,11,1,10,1,3,1,17,2,114,67,1,0,0, - 99,3,0,0,0,0,0,0,0,5,0,0,0,4,0,0, - 0,67,0,0,0,115,172,0,0,0,116,0,0,124,0,0, - 124,1,0,124,2,0,131,3,0,1,124,2,0,100,1,0, - 107,4,0,114,49,0,116,1,0,124,0,0,124,1,0,124, - 2,0,131,3,0,125,0,0,110,0,0,116,2,0,106,3, - 0,131,0,0,1,124,0,0,116,4,0,106,5,0,107,7, - 0,114,87,0,116,6,0,124,0,0,116,7,0,131,2,0, - 83,116,4,0,106,5,0,124,0,0,25,125,3,0,124,3, - 0,100,2,0,107,8,0,114,158,0,116,2,0,106,8,0, - 131,0,0,1,100,3,0,106,9,0,124,0,0,131,1,0, - 125,4,0,116,10,0,124,4,0,100,4,0,124,0,0,131, - 1,1,130,1,0,110,0,0,116,11,0,124,0,0,131,1, - 0,1,124,3,0,83,40,5,0,0,0,117,50,1,0,0, - 73,109,112,111,114,116,32,97,110,100,32,114,101,116,117,114, - 110,32,116,104,101,32,109,111,100,117,108,101,32,98,97,115, - 101,100,32,111,110,32,105,116,115,32,110,97,109,101,44,32, - 116,104,101,32,112,97,99,107,97,103,101,32,116,104,101,32, - 99,97,108,108,32,105,115,10,32,32,32,32,98,101,105,110, - 103,32,109,97,100,101,32,102,114,111,109,44,32,97,110,100, - 32,116,104,101,32,108,101,118,101,108,32,97,100,106,117,115, - 116,109,101,110,116,46,10,10,32,32,32,32,84,104,105,115, - 32,102,117,110,99,116,105,111,110,32,114,101,112,114,101,115, - 101,110,116,115,32,116,104,101,32,103,114,101,97,116,101,115, - 116,32,99,111,109,109,111,110,32,100,101,110,111,109,105,110, - 97,116,111,114,32,111,102,32,102,117,110,99,116,105,111,110, - 97,108,105,116,121,10,32,32,32,32,98,101,116,119,101,101, - 110,32,105,109,112,111,114,116,95,109,111,100,117,108,101,32, - 97,110,100,32,95,95,105,109,112,111,114,116,95,95,46,32, - 84,104,105,115,32,105,110,99,108,117,100,101,115,32,115,101, - 116,116,105,110,103,32,95,95,112,97,99,107,97,103,101,95, - 95,32,105,102,10,32,32,32,32,116,104,101,32,108,111,97, - 100,101,114,32,100,105,100,32,110,111,116,46,10,10,32,32, - 32,32,114,67,0,0,0,78,117,40,0,0,0,105,109,112, - 111,114,116,32,111,102,32,123,125,32,104,97,108,116,101,100, - 59,32,78,111,110,101,32,105,110,32,115,121,115,46,109,111, - 100,117,108,101,115,114,71,0,0,0,40,12,0,0,0,114, - 63,1,0,0,114,58,1,0,0,114,94,0,0,0,114,55, - 1,0,0,114,7,0,0,0,114,140,0,0,0,114,67,1, - 0,0,244,11,0,0,0,95,103,99,100,95,105,109,112,111, - 114,116,114,95,0,0,0,114,46,0,0,0,114,157,0,0, - 0,114,96,0,0,0,40,5,0,0,0,114,71,0,0,0, - 114,56,1,0,0,114,57,1,0,0,114,161,0,0,0,114, - 136,0,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,114,68,1,0,0,63,6,0,0,115,26,0,0, - 0,0,9,16,1,12,1,21,1,10,1,15,1,13,1,13, - 1,12,1,10,2,15,1,21,1,10,1,114,68,1,0,0, - 99,3,0,0,0,0,0,0,0,6,0,0,0,17,0,0, - 0,67,0,0,0,115,1,1,0,0,116,0,0,124,0,0, - 100,1,0,131,2,0,114,253,0,100,2,0,124,1,0,107, - 6,0,114,89,0,116,1,0,124,1,0,131,1,0,125,1, - 0,124,1,0,106,2,0,100,2,0,131,1,0,1,116,0, - 0,124,0,0,100,3,0,131,2,0,114,89,0,124,1,0, - 106,3,0,124,0,0,106,4,0,131,1,0,1,113,89,0, - 110,0,0,120,161,0,124,1,0,68,93,150,0,125,3,0, - 116,0,0,124,0,0,124,3,0,131,2,0,115,96,0,100, - 4,0,106,5,0,124,0,0,106,6,0,124,3,0,131,2, - 0,125,4,0,121,17,0,116,7,0,124,2,0,124,4,0, - 131,2,0,1,87,113,246,0,4,116,8,0,107,10,0,114, - 242,0,1,125,5,0,1,122,53,0,116,9,0,124,5,0, - 131,1,0,106,10,0,116,11,0,131,1,0,114,221,0,124, - 5,0,106,12,0,124,4,0,107,2,0,114,221,0,119,96, - 0,113,221,0,110,0,0,130,0,0,87,89,100,5,0,100, - 5,0,125,5,0,126,5,0,88,113,246,0,88,113,96,0, - 113,96,0,87,110,0,0,124,0,0,83,40,6,0,0,0, - 117,238,0,0,0,70,105,103,117,114,101,32,111,117,116,32, - 119,104,97,116,32,95,95,105,109,112,111,114,116,95,95,32, - 115,104,111,117,108,100,32,114,101,116,117,114,110,46,10,10, - 32,32,32,32,84,104,101,32,105,109,112,111,114,116,95,32, - 112,97,114,97,109,101,116,101,114,32,105,115,32,97,32,99, - 97,108,108,97,98,108,101,32,119,104,105,99,104,32,116,97, - 107,101,115,32,116,104,101,32,110,97,109,101,32,111,102,32, - 109,111,100,117,108,101,32,116,111,10,32,32,32,32,105,109, - 112,111,114,116,46,32,73,116,32,105,115,32,114,101,113,117, - 105,114,101,100,32,116,111,32,100,101,99,111,117,112,108,101, - 32,116,104,101,32,102,117,110,99,116,105,111,110,32,102,114, - 111,109,32,97,115,115,117,109,105,110,103,32,105,109,112,111, - 114,116,108,105,98,39,115,10,32,32,32,32,105,109,112,111, - 114,116,32,105,109,112,108,101,109,101,110,116,97,116,105,111, - 110,32,105,115,32,100,101,115,105,114,101,100,46,10,10,32, - 32,32,32,114,159,0,0,0,245,1,0,0,0,42,244,7, - 0,0,0,95,95,97,108,108,95,95,117,5,0,0,0,123, - 125,46,123,125,78,40,13,0,0,0,114,59,0,0,0,244, - 4,0,0,0,108,105,115,116,244,6,0,0,0,114,101,109, - 111,118,101,114,207,0,0,0,114,70,1,0,0,114,46,0, - 0,0,114,56,0,0,0,114,99,0,0,0,114,157,0,0, - 0,114,35,1,0,0,114,9,0,0,0,244,15,0,0,0, - 95,69,82,82,95,77,83,71,95,80,82,69,70,73,88,114, - 71,0,0,0,40,6,0,0,0,114,161,0,0,0,244,8, - 0,0,0,102,114,111,109,108,105,115,116,114,65,1,0,0, - 114,16,0,0,0,116,9,0,0,0,102,114,111,109,95,110, - 97,109,101,114,248,0,0,0,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,244,16,0,0,0,95,104,97,110, - 100,108,101,95,102,114,111,109,108,105,115,116,87,6,0,0, - 115,34,0,0,0,0,10,15,1,12,1,12,1,13,1,15, - 1,22,1,13,1,15,1,21,1,3,1,17,1,18,4,21, - 1,15,1,9,1,32,1,114,75,1,0,0,99,1,0,0, - 0,0,0,0,0,2,0,0,0,2,0,0,0,67,0,0, - 0,115,78,0,0,0,124,0,0,106,0,0,100,1,0,131, - 1,0,125,1,0,124,1,0,100,2,0,107,8,0,114,74, - 0,124,0,0,100,3,0,25,125,1,0,100,4,0,124,0, - 0,107,7,0,114,74,0,124,1,0,106,1,0,100,5,0, - 131,1,0,100,6,0,25,125,1,0,113,74,0,110,0,0, - 124,1,0,83,40,7,0,0,0,117,167,0,0,0,67,97, - 108,99,117,108,97,116,101,32,119,104,97,116,32,95,95,112, - 97,99,107,97,103,101,95,95,32,115,104,111,117,108,100,32, - 98,101,46,10,10,32,32,32,32,95,95,112,97,99,107,97, - 103,101,95,95,32,105,115,32,110,111,116,32,103,117,97,114, - 97,110,116,101,101,100,32,116,111,32,98,101,32,100,101,102, - 105,110,101,100,32,111,114,32,99,111,117,108,100,32,98,101, - 32,115,101,116,32,116,111,32,78,111,110,101,10,32,32,32, - 32,116,111,32,114,101,112,114,101,115,101,110,116,32,116,104, - 97,116,32,105,116,115,32,112,114,111,112,101,114,32,118,97, - 108,117,101,32,105,115,32,117,110,107,110,111,119,110,46,10, - 10,32,32,32,32,114,158,0,0,0,78,114,56,0,0,0, - 114,159,0,0,0,114,101,0,0,0,114,67,0,0,0,40, - 2,0,0,0,114,79,0,0,0,114,32,0,0,0,40,2, - 0,0,0,244,7,0,0,0,103,108,111,98,97,108,115,114, - 56,1,0,0,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,244,17,0,0,0,95,99,97,108,99,95,95,95, - 112,97,99,107,97,103,101,95,95,119,6,0,0,115,12,0, - 0,0,0,7,15,1,12,1,10,1,12,1,25,1,114,77, - 1,0,0,99,0,0,0,0,0,0,0,0,3,0,0,0, - 3,0,0,0,67,0,0,0,115,55,0,0,0,116,0,0, - 116,1,0,106,2,0,131,0,0,102,2,0,125,0,0,116, - 3,0,116,4,0,102,2,0,125,1,0,116,5,0,116,6, - 0,102,2,0,125,2,0,124,0,0,124,1,0,124,2,0, - 103,3,0,83,40,1,0,0,0,117,111,0,0,0,82,101, - 116,117,114,110,115,32,97,32,108,105,115,116,32,111,102,32, - 102,105,108,101,45,98,97,115,101,100,32,109,111,100,117,108, - 101,32,108,111,97,100,101,114,115,46,10,10,32,32,32,32, - 69,97,99,104,32,105,116,101,109,32,105,115,32,97,32,116, - 117,112,108,101,32,40,108,111,97,100,101,114,44,32,115,117, - 102,102,105,120,101,115,44,32,97,108,108,111,119,95,112,97, - 99,107,97,103,101,115,41,46,10,32,32,32,32,40,7,0, - 0,0,114,8,1,0,0,114,94,0,0,0,244,18,0,0, - 0,101,120,116,101,110,115,105,111,110,95,115,117,102,102,105, - 120,101,115,114,2,1,0,0,114,119,0,0,0,114,7,1, - 0,0,244,17,0,0,0,66,89,84,69,67,79,68,69,95, - 83,85,70,70,73,88,69,83,40,3,0,0,0,116,10,0, - 0,0,101,120,116,101,110,115,105,111,110,115,116,6,0,0, - 0,115,111,117,114,99,101,116,8,0,0,0,98,121,116,101, - 99,111,100,101,114,4,0,0,0,114,4,0,0,0,114,5, - 0,0,0,114,234,0,0,0,134,6,0,0,115,8,0,0, - 0,0,5,18,1,12,1,12,1,114,234,0,0,0,99,5, - 0,0,0,0,0,0,0,9,0,0,0,5,0,0,0,67, - 0,0,0,115,227,0,0,0,124,4,0,100,1,0,107,2, - 0,114,27,0,116,0,0,124,0,0,131,1,0,125,5,0, - 110,54,0,124,1,0,100,2,0,107,9,0,114,45,0,124, - 1,0,110,3,0,105,0,0,125,6,0,116,1,0,124,6, - 0,131,1,0,125,7,0,116,0,0,124,0,0,124,7,0, - 124,4,0,131,3,0,125,5,0,124,3,0,115,207,0,124, - 4,0,100,1,0,107,2,0,114,122,0,116,0,0,124,0, - 0,106,2,0,100,3,0,131,1,0,100,1,0,25,131,1, - 0,83,124,0,0,115,132,0,124,5,0,83,116,3,0,124, - 0,0,131,1,0,116,3,0,124,0,0,106,2,0,100,3, - 0,131,1,0,100,1,0,25,131,1,0,24,125,8,0,116, - 4,0,106,5,0,124,5,0,106,6,0,100,2,0,116,3, - 0,124,5,0,106,6,0,131,1,0,124,8,0,24,133,2, - 0,25,25,83,110,16,0,116,7,0,124,5,0,124,3,0, - 116,0,0,131,3,0,83,100,2,0,83,40,4,0,0,0, - 117,214,1,0,0,73,109,112,111,114,116,32,97,32,109,111, - 100,117,108,101,46,10,10,32,32,32,32,84,104,101,32,39, - 103,108,111,98,97,108,115,39,32,97,114,103,117,109,101,110, - 116,32,105,115,32,117,115,101,100,32,116,111,32,105,110,102, - 101,114,32,119,104,101,114,101,32,116,104,101,32,105,109,112, - 111,114,116,32,105,115,32,111,99,99,117,114,105,110,103,32, - 102,114,111,109,10,32,32,32,32,116,111,32,104,97,110,100, - 108,101,32,114,101,108,97,116,105,118,101,32,105,109,112,111, - 114,116,115,46,32,84,104,101,32,39,108,111,99,97,108,115, - 39,32,97,114,103,117,109,101,110,116,32,105,115,32,105,103, - 110,111,114,101,100,46,32,84,104,101,10,32,32,32,32,39, - 102,114,111,109,108,105,115,116,39,32,97,114,103,117,109,101, - 110,116,32,115,112,101,99,105,102,105,101,115,32,119,104,97, - 116,32,115,104,111,117,108,100,32,101,120,105,115,116,32,97, - 115,32,97,116,116,114,105,98,117,116,101,115,32,111,110,32, - 116,104,101,32,109,111,100,117,108,101,10,32,32,32,32,98, - 101,105,110,103,32,105,109,112,111,114,116,101,100,32,40,101, - 46,103,46,32,96,96,102,114,111,109,32,109,111,100,117,108, - 101,32,105,109,112,111,114,116,32,60,102,114,111,109,108,105, - 115,116,62,96,96,41,46,32,32,84,104,101,32,39,108,101, - 118,101,108,39,10,32,32,32,32,97,114,103,117,109,101,110, - 116,32,114,101,112,114,101,115,101,110,116,115,32,116,104,101, - 32,112,97,99,107,97,103,101,32,108,111,99,97,116,105,111, - 110,32,116,111,32,105,109,112,111,114,116,32,102,114,111,109, - 32,105,110,32,97,32,114,101,108,97,116,105,118,101,10,32, - 32,32,32,105,109,112,111,114,116,32,40,101,46,103,46,32, - 96,96,102,114,111,109,32,46,46,112,107,103,32,105,109,112, - 111,114,116,32,109,111,100,96,96,32,119,111,117,108,100,32, - 104,97,118,101,32,97,32,39,108,101,118,101,108,39,32,111, - 102,32,50,41,46,10,10,32,32,32,32,114,67,0,0,0, - 78,114,101,0,0,0,40,8,0,0,0,114,68,1,0,0, - 114,77,1,0,0,114,106,0,0,0,114,31,0,0,0,114, - 7,0,0,0,114,140,0,0,0,114,56,0,0,0,114,75, - 1,0,0,40,9,0,0,0,114,71,0,0,0,114,76,1, - 0,0,244,6,0,0,0,108,111,99,97,108,115,114,74,1, - 0,0,114,57,1,0,0,114,161,0,0,0,116,8,0,0, - 0,103,108,111,98,97,108,115,95,114,56,1,0,0,116,7, - 0,0,0,99,117,116,95,111,102,102,114,4,0,0,0,114, - 4,0,0,0,114,5,0,0,0,244,10,0,0,0,95,95, - 105,109,112,111,114,116,95,95,145,6,0,0,115,26,0,0, - 0,0,11,12,1,15,2,24,1,12,1,18,1,6,3,12, - 1,23,1,6,1,4,4,35,3,40,2,114,81,1,0,0, - 99,2,0,0,0,0,0,0,0,16,0,0,0,13,0,0, - 0,67,0,0,0,115,237,2,0,0,124,1,0,97,0,0, - 124,0,0,97,1,0,116,1,0,106,2,0,106,3,0,114, - 33,0,116,4,0,97,5,0,110,6,0,116,6,0,97,5, - 0,116,7,0,116,1,0,131,1,0,125,2,0,120,128,0, - 116,1,0,106,8,0,106,9,0,131,0,0,68,93,111,0, - 92,2,0,125,3,0,125,4,0,116,10,0,124,4,0,124, - 2,0,131,2,0,114,67,0,116,11,0,124,4,0,100,1, - 0,100,2,0,131,3,0,100,2,0,107,8,0,114,178,0, - 124,3,0,116,1,0,106,12,0,107,6,0,114,145,0,116, - 13,0,124,4,0,95,14,0,113,175,0,116,0,0,106,15, - 0,124,3,0,131,1,0,114,175,0,116,16,0,124,4,0, - 95,14,0,113,175,0,113,178,0,113,67,0,113,67,0,87, - 116,1,0,106,8,0,116,17,0,25,125,5,0,120,76,0, - 100,27,0,68,93,68,0,125,6,0,124,6,0,116,1,0, - 106,8,0,107,7,0,114,241,0,116,13,0,106,18,0,124, - 6,0,131,1,0,125,7,0,110,13,0,116,1,0,106,8, - 0,124,6,0,25,125,7,0,116,19,0,124,5,0,124,6, - 0,124,7,0,131,3,0,1,113,202,0,87,100,7,0,100, - 8,0,103,1,0,102,2,0,100,9,0,100,10,0,100,8, - 0,103,2,0,102,2,0,102,2,0,125,8,0,120,149,0, - 124,8,0,68,93,129,0,92,2,0,125,9,0,125,10,0, - 116,20,0,100,11,0,100,12,0,132,0,0,124,10,0,68, - 131,1,0,131,1,0,115,101,1,116,21,0,130,1,0,124, - 10,0,100,13,0,25,125,11,0,124,9,0,116,1,0,106, - 8,0,107,6,0,114,143,1,116,1,0,106,8,0,124,9, - 0,25,125,12,0,80,113,58,1,121,20,0,116,13,0,106, - 18,0,124,9,0,131,1,0,125,12,0,80,87,113,58,1, - 4,116,22,0,107,10,0,114,186,1,1,1,1,119,58,1, - 89,113,58,1,88,113,58,1,87,116,22,0,100,14,0,131, - 1,0,130,1,0,121,19,0,116,13,0,106,18,0,100,15, - 0,131,1,0,125,13,0,87,110,24,0,4,116,22,0,107, - 10,0,114,248,1,1,1,1,100,2,0,125,13,0,89,110, - 1,0,88,116,13,0,106,18,0,100,16,0,131,1,0,125, - 14,0,124,9,0,100,9,0,107,2,0,114,54,2,116,13, - 0,106,18,0,100,17,0,131,1,0,125,15,0,116,19,0, - 124,5,0,100,18,0,124,15,0,131,3,0,1,110,0,0, - 116,19,0,124,5,0,100,19,0,124,12,0,131,3,0,1, - 116,19,0,124,5,0,100,15,0,124,13,0,131,3,0,1, - 116,19,0,124,5,0,100,16,0,124,14,0,131,3,0,1, - 116,19,0,124,5,0,100,20,0,124,11,0,131,3,0,1, - 116,19,0,124,5,0,100,21,0,100,22,0,106,23,0,124, - 10,0,131,1,0,131,3,0,1,116,19,0,124,5,0,100, - 23,0,116,24,0,131,0,0,131,3,0,1,116,25,0,106, - 26,0,116,0,0,106,27,0,131,0,0,131,1,0,1,124, - 9,0,100,9,0,107,2,0,114,233,2,116,28,0,106,29, - 0,100,24,0,131,1,0,1,100,25,0,116,25,0,107,6, - 0,114,233,2,100,26,0,116,30,0,95,31,0,113,233,2, - 110,0,0,100,2,0,83,40,28,0,0,0,117,250,0,0, - 0,83,101,116,117,112,32,105,109,112,111,114,116,108,105,98, - 32,98,121,32,105,109,112,111,114,116,105,110,103,32,110,101, - 101,100,101,100,32,98,117,105,108,116,45,105,110,32,109,111, - 100,117,108,101,115,32,97,110,100,32,105,110,106,101,99,116, - 105,110,103,32,116,104,101,109,10,32,32,32,32,105,110,116, - 111,32,116,104,101,32,103,108,111,98,97,108,32,110,97,109, - 101,115,112,97,99,101,46,10,10,32,32,32,32,65,115,32, - 115,121,115,32,105,115,32,110,101,101,100,101,100,32,102,111, - 114,32,115,121,115,46,109,111,100,117,108,101,115,32,97,99, - 99,101,115,115,32,97,110,100,32,95,105,109,112,32,105,115, - 32,110,101,101,100,101,100,32,116,111,32,108,111,97,100,32, - 98,117,105,108,116,45,105,110,10,32,32,32,32,109,111,100, - 117,108,101,115,44,32,116,104,111,115,101,32,116,119,111,32, - 109,111,100,117,108,101,115,32,109,117,115,116,32,98,101,32, - 101,120,112,108,105,99,105,116,108,121,32,112,97,115,115,101, - 100,32,105,110,46,10,10,32,32,32,32,114,171,0,0,0, - 78,114,48,0,0,0,114,185,0,0,0,244,8,0,0,0, - 98,117,105,108,116,105,110,115,114,201,0,0,0,116,5,0, - 0,0,112,111,115,105,120,245,1,0,0,0,47,244,2,0, - 0,0,110,116,245,1,0,0,0,92,99,1,0,0,0,0, - 0,0,0,2,0,0,0,3,0,0,0,115,0,0,0,115, - 33,0,0,0,124,0,0,93,23,0,125,1,0,116,0,0, - 124,1,0,131,1,0,100,0,0,107,2,0,86,1,113,3, - 0,100,1,0,83,40,2,0,0,0,114,29,0,0,0,78, - 40,1,0,0,0,114,31,0,0,0,40,2,0,0,0,114, - 22,0,0,0,114,115,0,0,0,114,4,0,0,0,114,4, - 0,0,0,114,5,0,0,0,114,143,0,0,0,218,6,0, - 0,115,2,0,0,0,6,0,117,25,0,0,0,95,115,101, - 116,117,112,46,60,108,111,99,97,108,115,62,46,60,103,101, - 110,101,120,112,114,62,114,67,0,0,0,117,30,0,0,0, - 105,109,112,111,114,116,108,105,98,32,114,101,113,117,105,114, - 101,115,32,112,111,115,105,120,32,111,114,32,110,116,114,68, - 0,0,0,114,92,0,0,0,116,6,0,0,0,119,105,110, - 114,101,103,114,225,0,0,0,114,3,0,0,0,114,25,0, - 0,0,114,21,0,0,0,114,30,0,0,0,114,6,0,0, - 0,117,4,0,0,0,46,112,121,119,117,6,0,0,0,95, - 100,46,112,121,100,84,40,4,0,0,0,117,3,0,0,0, + 105,115,32,101,109,112,116,121,78,40,9,0,0,0,117,3, + 0,0,0,115,121,115,117,9,0,0,0,109,101,116,97,95, + 112,97,116,104,117,9,0,0,0,95,119,97,114,110,105,110, + 103,115,117,4,0,0,0,119,97,114,110,117,13,0,0,0, + 73,109,112,111,114,116,87,97,114,110,105,110,103,117,18,0, + 0,0,95,73,109,112,111,114,116,76,111,99,107,67,111,110, + 116,101,120,116,117,11,0,0,0,102,105,110,100,95,109,111, + 100,117,108,101,117,7,0,0,0,109,111,100,117,108,101,115, + 117,10,0,0,0,95,95,108,111,97,100,101,114,95,95,40, + 4,0,0,0,117,4,0,0,0,110,97,109,101,117,4,0, + 0,0,112,97,116,104,117,6,0,0,0,102,105,110,100,101, + 114,117,6,0,0,0,108,111,97,100,101,114,40,0,0,0, + 0,40,0,0,0,0,117,29,0,0,0,60,102,114,111,122, + 101,110,32,105,109,112,111,114,116,108,105,98,46,95,98,111, + 111,116,115,116,114,97,112,62,117,12,0,0,0,95,102,105, + 110,100,95,109,111,100,117,108,101,203,5,0,0,115,20,0, + 0,0,0,2,9,1,19,1,16,1,10,1,24,1,12,2, + 15,1,4,2,21,2,117,12,0,0,0,95,102,105,110,100, + 95,109,111,100,117,108,101,99,3,0,0,0,0,0,0,0, + 4,0,0,0,4,0,0,0,67,0,0,0,115,194,0,0, + 0,116,0,0,124,0,0,116,1,0,131,2,0,115,45,0, + 116,2,0,100,1,0,106,3,0,116,4,0,124,0,0,131, + 1,0,131,1,0,131,1,0,130,1,0,110,0,0,124,2, + 0,100,2,0,107,0,0,114,72,0,116,5,0,100,3,0, + 131,1,0,130,1,0,110,0,0,124,1,0,114,156,0,116, + 0,0,124,1,0,116,1,0,131,2,0,115,108,0,116,2, + 0,100,4,0,131,1,0,130,1,0,113,156,0,124,1,0, + 116,6,0,106,7,0,107,7,0,114,156,0,100,5,0,125, + 3,0,116,8,0,124,3,0,106,3,0,124,1,0,131,1, + 0,131,1,0,130,1,0,113,156,0,110,0,0,124,0,0, + 12,114,190,0,124,2,0,100,2,0,107,2,0,114,190,0, + 116,5,0,100,6,0,131,1,0,130,1,0,110,0,0,100, + 7,0,83,40,8,0,0,0,117,28,0,0,0,86,101,114, + 105,102,121,32,97,114,103,117,109,101,110,116,115,32,97,114, + 101,32,34,115,97,110,101,34,46,117,31,0,0,0,109,111, + 100,117,108,101,32,110,97,109,101,32,109,117,115,116,32,98, + 101,32,115,116,114,44,32,110,111,116,32,123,125,105,0,0, + 0,0,117,18,0,0,0,108,101,118,101,108,32,109,117,115, + 116,32,98,101,32,62,61,32,48,117,31,0,0,0,95,95, + 112,97,99,107,97,103,101,95,95,32,110,111,116,32,115,101, + 116,32,116,111,32,97,32,115,116,114,105,110,103,117,61,0, + 0,0,80,97,114,101,110,116,32,109,111,100,117,108,101,32, + 123,33,114,125,32,110,111,116,32,108,111,97,100,101,100,44, + 32,99,97,110,110,111,116,32,112,101,114,102,111,114,109,32, + 114,101,108,97,116,105,118,101,32,105,109,112,111,114,116,117, + 17,0,0,0,69,109,112,116,121,32,109,111,100,117,108,101, + 32,110,97,109,101,78,40,9,0,0,0,117,10,0,0,0, + 105,115,105,110,115,116,97,110,99,101,117,3,0,0,0,115, + 116,114,117,9,0,0,0,84,121,112,101,69,114,114,111,114, + 117,6,0,0,0,102,111,114,109,97,116,117,4,0,0,0, + 116,121,112,101,117,10,0,0,0,86,97,108,117,101,69,114, + 114,111,114,117,3,0,0,0,115,121,115,117,7,0,0,0, + 109,111,100,117,108,101,115,117,11,0,0,0,83,121,115,116, + 101,109,69,114,114,111,114,40,4,0,0,0,117,4,0,0, + 0,110,97,109,101,117,7,0,0,0,112,97,99,107,97,103, + 101,117,5,0,0,0,108,101,118,101,108,117,3,0,0,0, + 109,115,103,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 13,0,0,0,95,115,97,110,105,116,121,95,99,104,101,99, + 107,220,5,0,0,115,24,0,0,0,0,2,15,1,30,1, + 12,1,15,1,6,1,15,1,15,1,15,1,6,2,27,1, + 19,1,117,13,0,0,0,95,115,97,110,105,116,121,95,99, + 104,101,99,107,117,20,0,0,0,78,111,32,109,111,100,117, + 108,101,32,110,97,109,101,100,32,123,33,114,125,99,2,0, + 0,0,0,0,0,0,9,0,0,0,27,0,0,0,67,0, + 0,0,115,12,2,0,0,100,0,0,125,2,0,124,0,0, + 106,0,0,100,1,0,131,1,0,100,2,0,25,125,3,0, + 124,3,0,114,178,0,124,3,0,116,1,0,106,2,0,107, + 7,0,114,62,0,116,3,0,124,1,0,124,3,0,131,2, + 0,1,110,0,0,124,0,0,116,1,0,106,2,0,107,6, + 0,114,88,0,116,1,0,106,2,0,124,0,0,25,83,116, + 1,0,106,2,0,124,3,0,25,125,4,0,121,13,0,124, + 4,0,106,4,0,125,2,0,87,113,178,0,4,116,5,0, + 107,10,0,114,174,0,1,1,1,116,6,0,100,3,0,23, + 106,7,0,124,0,0,124,3,0,131,2,0,125,5,0,116, + 8,0,124,5,0,100,4,0,124,0,0,131,1,1,130,1, + 0,89,113,178,0,88,110,0,0,116,9,0,124,0,0,124, + 2,0,131,2,0,125,6,0,124,6,0,100,0,0,107,8, + 0,114,250,0,116,8,0,116,6,0,106,7,0,124,0,0, + 131,1,0,100,4,0,124,0,0,131,1,1,125,7,0,100, + 5,0,124,7,0,95,10,0,124,7,0,130,1,0,110,47, + 0,124,0,0,116,1,0,106,2,0,107,7,0,114,41,1, + 124,6,0,106,11,0,124,0,0,131,1,0,1,116,12,0, + 100,6,0,124,0,0,124,6,0,131,3,0,1,110,0,0, + 116,1,0,106,2,0,124,0,0,25,125,8,0,124,3,0, + 114,105,1,116,1,0,106,2,0,124,3,0,25,125,4,0, + 116,13,0,124,4,0,124,0,0,106,0,0,100,1,0,131, + 1,0,100,7,0,25,124,8,0,131,3,0,1,110,0,0, + 116,14,0,124,8,0,100,8,0,100,0,0,131,3,0,100, + 0,0,107,8,0,114,212,1,121,59,0,124,8,0,106,15, + 0,124,8,0,95,16,0,116,17,0,124,8,0,100,9,0, + 131,2,0,115,187,1,124,8,0,106,16,0,106,0,0,100, + 1,0,131,1,0,100,2,0,25,124,8,0,95,16,0,110, + 0,0,87,113,212,1,4,116,5,0,107,10,0,114,208,1, + 1,1,1,89,113,212,1,88,110,0,0,116,17,0,124,8, + 0,100,10,0,131,2,0,115,8,2,121,13,0,124,6,0, + 124,8,0,95,18,0,87,113,8,2,4,116,5,0,107,10, + 0,114,4,2,1,1,1,89,113,8,2,88,110,0,0,124, + 8,0,83,40,11,0,0,0,78,117,1,0,0,0,46,105, + 0,0,0,0,117,21,0,0,0,59,32,123,125,32,105,115, + 32,110,111,116,32,97,32,112,97,99,107,97,103,101,117,4, + 0,0,0,110,97,109,101,84,117,18,0,0,0,105,109,112, + 111,114,116,32,123,33,114,125,32,35,32,123,33,114,125,105, + 2,0,0,0,117,11,0,0,0,95,95,112,97,99,107,97, + 103,101,95,95,117,8,0,0,0,95,95,112,97,116,104,95, + 95,117,10,0,0,0,95,95,108,111,97,100,101,114,95,95, + 40,19,0,0,0,117,10,0,0,0,114,112,97,114,116,105, + 116,105,111,110,117,3,0,0,0,115,121,115,117,7,0,0, + 0,109,111,100,117,108,101,115,117,25,0,0,0,95,99,97, + 108,108,95,119,105,116,104,95,102,114,97,109,101,115,95,114, + 101,109,111,118,101,100,117,8,0,0,0,95,95,112,97,116, + 104,95,95,117,14,0,0,0,65,116,116,114,105,98,117,116, + 101,69,114,114,111,114,117,8,0,0,0,95,69,82,82,95, + 77,83,71,117,6,0,0,0,102,111,114,109,97,116,117,11, + 0,0,0,73,109,112,111,114,116,69,114,114,111,114,117,12, + 0,0,0,95,102,105,110,100,95,109,111,100,117,108,101,117, + 10,0,0,0,95,110,111,116,95,102,111,117,110,100,117,11, + 0,0,0,108,111,97,100,95,109,111,100,117,108,101,117,16, + 0,0,0,95,118,101,114,98,111,115,101,95,109,101,115,115, + 97,103,101,117,7,0,0,0,115,101,116,97,116,116,114,117, + 7,0,0,0,103,101,116,97,116,116,114,117,8,0,0,0, + 95,95,110,97,109,101,95,95,117,11,0,0,0,95,95,112, + 97,99,107,97,103,101,95,95,117,7,0,0,0,104,97,115, + 97,116,116,114,117,10,0,0,0,95,95,108,111,97,100,101, + 114,95,95,40,9,0,0,0,117,4,0,0,0,110,97,109, + 101,117,7,0,0,0,105,109,112,111,114,116,95,117,4,0, + 0,0,112,97,116,104,117,6,0,0,0,112,97,114,101,110, + 116,117,13,0,0,0,112,97,114,101,110,116,95,109,111,100, + 117,108,101,117,3,0,0,0,109,115,103,117,6,0,0,0, + 108,111,97,100,101,114,117,3,0,0,0,101,120,99,117,6, + 0,0,0,109,111,100,117,108,101,40,0,0,0,0,40,0, + 0,0,0,117,29,0,0,0,60,102,114,111,122,101,110,32, + 105,109,112,111,114,116,108,105,98,46,95,98,111,111,116,115, + 116,114,97,112,62,117,23,0,0,0,95,102,105,110,100,95, + 97,110,100,95,108,111,97,100,95,117,110,108,111,99,107,101, + 100,239,5,0,0,115,76,0,0,0,0,1,6,1,19,1, + 6,1,15,1,16,2,15,1,11,2,13,1,3,1,13,1, + 13,1,22,1,26,1,15,1,12,1,27,3,9,1,9,1, + 15,2,13,1,19,2,13,1,6,2,13,1,32,2,24,1, + 3,1,12,1,15,1,32,1,13,1,8,2,15,1,3,1, + 13,1,13,1,8,1,117,23,0,0,0,95,102,105,110,100, + 95,97,110,100,95,108,111,97,100,95,117,110,108,111,99,107, + 101,100,99,2,0,0,0,0,0,0,0,3,0,0,0,18, + 0,0,0,67,0,0,0,115,75,0,0,0,122,16,0,116, + 0,0,124,0,0,131,1,0,125,2,0,87,100,1,0,116, + 1,0,106,2,0,131,0,0,1,88,124,2,0,106,3,0, + 131,0,0,1,122,17,0,116,4,0,124,0,0,124,1,0, + 131,2,0,83,87,100,1,0,124,2,0,106,5,0,131,0, + 0,1,88,100,1,0,83,40,2,0,0,0,117,54,0,0, + 0,70,105,110,100,32,97,110,100,32,108,111,97,100,32,116, + 104,101,32,109,111,100,117,108,101,44,32,97,110,100,32,114, + 101,108,101,97,115,101,32,116,104,101,32,105,109,112,111,114, + 116,32,108,111,99,107,46,78,40,6,0,0,0,117,16,0, + 0,0,95,103,101,116,95,109,111,100,117,108,101,95,108,111, + 99,107,117,4,0,0,0,95,105,109,112,117,12,0,0,0, + 114,101,108,101,97,115,101,95,108,111,99,107,117,7,0,0, + 0,97,99,113,117,105,114,101,117,23,0,0,0,95,102,105, + 110,100,95,97,110,100,95,108,111,97,100,95,117,110,108,111, + 99,107,101,100,117,7,0,0,0,114,101,108,101,97,115,101, + 40,3,0,0,0,117,4,0,0,0,110,97,109,101,117,7, + 0,0,0,105,109,112,111,114,116,95,117,4,0,0,0,108, + 111,99,107,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 14,0,0,0,95,102,105,110,100,95,97,110,100,95,108,111, + 97,100,33,6,0,0,115,14,0,0,0,0,2,3,1,16, + 2,11,1,10,1,3,1,17,2,117,14,0,0,0,95,102, + 105,110,100,95,97,110,100,95,108,111,97,100,99,3,0,0, + 0,0,0,0,0,5,0,0,0,4,0,0,0,67,0,0, + 0,115,172,0,0,0,116,0,0,124,0,0,124,1,0,124, + 2,0,131,3,0,1,124,2,0,100,1,0,107,4,0,114, + 49,0,116,1,0,124,0,0,124,1,0,124,2,0,131,3, + 0,125,0,0,110,0,0,116,2,0,106,3,0,131,0,0, + 1,124,0,0,116,4,0,106,5,0,107,7,0,114,87,0, + 116,6,0,124,0,0,116,7,0,131,2,0,83,116,4,0, + 106,5,0,124,0,0,25,125,3,0,124,3,0,100,2,0, + 107,8,0,114,158,0,116,2,0,106,8,0,131,0,0,1, + 100,3,0,106,9,0,124,0,0,131,1,0,125,4,0,116, + 10,0,124,4,0,100,4,0,124,0,0,131,1,1,130,1, + 0,110,0,0,116,11,0,124,0,0,131,1,0,1,124,3, + 0,83,40,5,0,0,0,117,50,1,0,0,73,109,112,111, + 114,116,32,97,110,100,32,114,101,116,117,114,110,32,116,104, + 101,32,109,111,100,117,108,101,32,98,97,115,101,100,32,111, + 110,32,105,116,115,32,110,97,109,101,44,32,116,104,101,32, + 112,97,99,107,97,103,101,32,116,104,101,32,99,97,108,108, + 32,105,115,10,32,32,32,32,98,101,105,110,103,32,109,97, + 100,101,32,102,114,111,109,44,32,97,110,100,32,116,104,101, + 32,108,101,118,101,108,32,97,100,106,117,115,116,109,101,110, + 116,46,10,10,32,32,32,32,84,104,105,115,32,102,117,110, + 99,116,105,111,110,32,114,101,112,114,101,115,101,110,116,115, + 32,116,104,101,32,103,114,101,97,116,101,115,116,32,99,111, + 109,109,111,110,32,100,101,110,111,109,105,110,97,116,111,114, + 32,111,102,32,102,117,110,99,116,105,111,110,97,108,105,116, + 121,10,32,32,32,32,98,101,116,119,101,101,110,32,105,109, + 112,111,114,116,95,109,111,100,117,108,101,32,97,110,100,32, + 95,95,105,109,112,111,114,116,95,95,46,32,84,104,105,115, + 32,105,110,99,108,117,100,101,115,32,115,101,116,116,105,110, + 103,32,95,95,112,97,99,107,97,103,101,95,95,32,105,102, + 10,32,32,32,32,116,104,101,32,108,111,97,100,101,114,32, + 100,105,100,32,110,111,116,46,10,10,32,32,32,32,105,0, + 0,0,0,78,117,40,0,0,0,105,109,112,111,114,116,32, + 111,102,32,123,125,32,104,97,108,116,101,100,59,32,78,111, + 110,101,32,105,110,32,115,121,115,46,109,111,100,117,108,101, + 115,117,4,0,0,0,110,97,109,101,40,12,0,0,0,117, + 13,0,0,0,95,115,97,110,105,116,121,95,99,104,101,99, + 107,117,13,0,0,0,95,114,101,115,111,108,118,101,95,110, + 97,109,101,117,4,0,0,0,95,105,109,112,117,12,0,0, + 0,97,99,113,117,105,114,101,95,108,111,99,107,117,3,0, + 0,0,115,121,115,117,7,0,0,0,109,111,100,117,108,101, + 115,117,14,0,0,0,95,102,105,110,100,95,97,110,100,95, + 108,111,97,100,117,11,0,0,0,95,103,99,100,95,105,109, + 112,111,114,116,117,12,0,0,0,114,101,108,101,97,115,101, + 95,108,111,99,107,117,6,0,0,0,102,111,114,109,97,116, + 117,11,0,0,0,73,109,112,111,114,116,69,114,114,111,114, + 117,19,0,0,0,95,108,111,99,107,95,117,110,108,111,99, + 107,95,109,111,100,117,108,101,40,5,0,0,0,117,4,0, + 0,0,110,97,109,101,117,7,0,0,0,112,97,99,107,97, + 103,101,117,5,0,0,0,108,101,118,101,108,117,6,0,0, + 0,109,111,100,117,108,101,117,7,0,0,0,109,101,115,115, + 97,103,101,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 11,0,0,0,95,103,99,100,95,105,109,112,111,114,116,46, + 6,0,0,115,28,0,0,0,0,9,16,1,12,1,21,1, + 10,1,15,1,13,1,13,1,12,1,10,1,6,1,9,1, + 21,1,10,1,117,11,0,0,0,95,103,99,100,95,105,109, + 112,111,114,116,99,3,0,0,0,0,0,0,0,6,0,0, + 0,17,0,0,0,67,0,0,0,115,254,0,0,0,116,0, + 0,124,0,0,100,1,0,131,2,0,114,250,0,100,2,0, + 124,1,0,107,6,0,114,89,0,116,1,0,124,1,0,131, + 1,0,125,1,0,124,1,0,106,2,0,100,2,0,131,1, + 0,1,116,0,0,124,0,0,100,3,0,131,2,0,114,89, + 0,124,1,0,106,3,0,124,0,0,106,4,0,131,1,0, + 1,113,89,0,110,0,0,120,158,0,124,1,0,68,93,147, + 0,125,3,0,116,0,0,124,0,0,124,3,0,131,2,0, + 115,96,0,100,4,0,106,5,0,124,0,0,106,6,0,124, + 3,0,131,2,0,125,4,0,121,17,0,116,7,0,124,2, + 0,124,4,0,131,2,0,1,87,113,243,0,4,116,8,0, + 107,10,0,114,239,0,1,125,5,0,1,122,50,0,116,9, + 0,124,5,0,100,5,0,100,6,0,131,3,0,114,218,0, + 124,5,0,106,10,0,124,4,0,107,2,0,114,218,0,119, + 96,0,113,218,0,110,0,0,130,0,0,87,89,100,7,0, + 100,7,0,125,5,0,126,5,0,88,113,243,0,88,113,96, + 0,113,96,0,87,110,0,0,124,0,0,83,40,8,0,0, + 0,117,238,0,0,0,70,105,103,117,114,101,32,111,117,116, + 32,119,104,97,116,32,95,95,105,109,112,111,114,116,95,95, + 32,115,104,111,117,108,100,32,114,101,116,117,114,110,46,10, + 10,32,32,32,32,84,104,101,32,105,109,112,111,114,116,95, + 32,112,97,114,97,109,101,116,101,114,32,105,115,32,97,32, + 99,97,108,108,97,98,108,101,32,119,104,105,99,104,32,116, + 97,107,101,115,32,116,104,101,32,110,97,109,101,32,111,102, + 32,109,111,100,117,108,101,32,116,111,10,32,32,32,32,105, + 109,112,111,114,116,46,32,73,116,32,105,115,32,114,101,113, + 117,105,114,101,100,32,116,111,32,100,101,99,111,117,112,108, + 101,32,116,104,101,32,102,117,110,99,116,105,111,110,32,102, + 114,111,109,32,97,115,115,117,109,105,110,103,32,105,109,112, + 111,114,116,108,105,98,39,115,10,32,32,32,32,105,109,112, + 111,114,116,32,105,109,112,108,101,109,101,110,116,97,116,105, + 111,110,32,105,115,32,100,101,115,105,114,101,100,46,10,10, + 32,32,32,32,117,8,0,0,0,95,95,112,97,116,104,95, + 95,117,1,0,0,0,42,117,7,0,0,0,95,95,97,108, + 108,95,95,117,5,0,0,0,123,125,46,123,125,117,10,0, + 0,0,95,110,111,116,95,102,111,117,110,100,70,78,40,11, + 0,0,0,117,7,0,0,0,104,97,115,97,116,116,114,117, + 4,0,0,0,108,105,115,116,117,6,0,0,0,114,101,109, + 111,118,101,117,6,0,0,0,101,120,116,101,110,100,117,7, + 0,0,0,95,95,97,108,108,95,95,117,6,0,0,0,102, + 111,114,109,97,116,117,8,0,0,0,95,95,110,97,109,101, + 95,95,117,25,0,0,0,95,99,97,108,108,95,119,105,116, + 104,95,102,114,97,109,101,115,95,114,101,109,111,118,101,100, + 117,11,0,0,0,73,109,112,111,114,116,69,114,114,111,114, + 117,7,0,0,0,103,101,116,97,116,116,114,117,4,0,0, + 0,110,97,109,101,40,6,0,0,0,117,6,0,0,0,109, + 111,100,117,108,101,117,8,0,0,0,102,114,111,109,108,105, + 115,116,117,7,0,0,0,105,109,112,111,114,116,95,117,1, + 0,0,0,120,117,9,0,0,0,102,114,111,109,95,110,97, + 109,101,117,3,0,0,0,101,120,99,40,0,0,0,0,40, + 0,0,0,0,117,29,0,0,0,60,102,114,111,122,101,110, + 32,105,109,112,111,114,116,108,105,98,46,95,98,111,111,116, + 115,116,114,97,112,62,117,16,0,0,0,95,104,97,110,100, + 108,101,95,102,114,111,109,108,105,115,116,70,6,0,0,115, + 34,0,0,0,0,10,15,1,12,1,12,1,13,1,15,1, + 22,1,13,1,15,1,21,1,3,1,17,1,18,6,18,1, + 15,1,9,1,32,1,117,16,0,0,0,95,104,97,110,100, + 108,101,95,102,114,111,109,108,105,115,116,99,1,0,0,0, + 0,0,0,0,2,0,0,0,2,0,0,0,67,0,0,0, + 115,78,0,0,0,124,0,0,106,0,0,100,1,0,131,1, + 0,125,1,0,124,1,0,100,2,0,107,8,0,114,74,0, + 124,0,0,100,3,0,25,125,1,0,100,4,0,124,0,0, + 107,7,0,114,74,0,124,1,0,106,1,0,100,5,0,131, + 1,0,100,6,0,25,125,1,0,113,74,0,110,0,0,124, + 1,0,83,40,7,0,0,0,117,167,0,0,0,67,97,108, + 99,117,108,97,116,101,32,119,104,97,116,32,95,95,112,97, + 99,107,97,103,101,95,95,32,115,104,111,117,108,100,32,98, + 101,46,10,10,32,32,32,32,95,95,112,97,99,107,97,103, + 101,95,95,32,105,115,32,110,111,116,32,103,117,97,114,97, + 110,116,101,101,100,32,116,111,32,98,101,32,100,101,102,105, + 110,101,100,32,111,114,32,99,111,117,108,100,32,98,101,32, + 115,101,116,32,116,111,32,78,111,110,101,10,32,32,32,32, + 116,111,32,114,101,112,114,101,115,101,110,116,32,116,104,97, + 116,32,105,116,115,32,112,114,111,112,101,114,32,118,97,108, + 117,101,32,105,115,32,117,110,107,110,111,119,110,46,10,10, + 32,32,32,32,117,11,0,0,0,95,95,112,97,99,107,97, + 103,101,95,95,78,117,8,0,0,0,95,95,110,97,109,101, + 95,95,117,8,0,0,0,95,95,112,97,116,104,95,95,117, + 1,0,0,0,46,105,0,0,0,0,40,2,0,0,0,117, + 3,0,0,0,103,101,116,117,10,0,0,0,114,112,97,114, + 116,105,116,105,111,110,40,2,0,0,0,117,7,0,0,0, + 103,108,111,98,97,108,115,117,7,0,0,0,112,97,99,107, + 97,103,101,40,0,0,0,0,40,0,0,0,0,117,29,0, + 0,0,60,102,114,111,122,101,110,32,105,109,112,111,114,116, + 108,105,98,46,95,98,111,111,116,115,116,114,97,112,62,117, + 17,0,0,0,95,99,97,108,99,95,95,95,112,97,99,107, + 97,103,101,95,95,104,6,0,0,115,12,0,0,0,0,7, + 15,1,12,1,10,1,12,1,25,1,117,17,0,0,0,95, + 99,97,108,99,95,95,95,112,97,99,107,97,103,101,95,95, + 99,0,0,0,0,0,0,0,0,3,0,0,0,3,0,0, + 0,67,0,0,0,115,55,0,0,0,116,0,0,116,1,0, + 106,2,0,131,0,0,102,2,0,125,0,0,116,3,0,116, + 4,0,102,2,0,125,1,0,116,5,0,116,6,0,102,2, + 0,125,2,0,124,0,0,124,1,0,124,2,0,103,3,0, + 83,40,1,0,0,0,117,111,0,0,0,82,101,116,117,114, + 110,115,32,97,32,108,105,115,116,32,111,102,32,102,105,108, + 101,45,98,97,115,101,100,32,109,111,100,117,108,101,32,108, + 111,97,100,101,114,115,46,10,10,32,32,32,32,69,97,99, + 104,32,105,116,101,109,32,105,115,32,97,32,116,117,112,108, + 101,32,40,108,111,97,100,101,114,44,32,115,117,102,102,105, + 120,101,115,44,32,97,108,108,111,119,95,112,97,99,107,97, + 103,101,115,41,46,10,32,32,32,32,40,7,0,0,0,117, + 19,0,0,0,69,120,116,101,110,115,105,111,110,70,105,108, + 101,76,111,97,100,101,114,117,4,0,0,0,95,105,109,112, + 117,18,0,0,0,101,120,116,101,110,115,105,111,110,95,115, + 117,102,102,105,120,101,115,117,16,0,0,0,83,111,117,114, + 99,101,70,105,108,101,76,111,97,100,101,114,117,15,0,0, + 0,83,79,85,82,67,69,95,83,85,70,70,73,88,69,83, + 117,20,0,0,0,83,111,117,114,99,101,108,101,115,115,70, + 105,108,101,76,111,97,100,101,114,117,17,0,0,0,66,89, + 84,69,67,79,68,69,95,83,85,70,70,73,88,69,83,40, + 3,0,0,0,117,10,0,0,0,101,120,116,101,110,115,105, + 111,110,115,117,6,0,0,0,115,111,117,114,99,101,117,8, + 0,0,0,98,121,116,101,99,111,100,101,40,0,0,0,0, + 40,0,0,0,0,117,29,0,0,0,60,102,114,111,122,101, + 110,32,105,109,112,111,114,116,108,105,98,46,95,98,111,111, + 116,115,116,114,97,112,62,117,27,0,0,0,95,103,101,116, + 95,115,117,112,112,111,114,116,101,100,95,102,105,108,101,95, + 108,111,97,100,101,114,115,119,6,0,0,115,8,0,0,0, + 0,5,18,1,12,1,12,1,117,27,0,0,0,95,103,101, + 116,95,115,117,112,112,111,114,116,101,100,95,102,105,108,101, + 95,108,111,97,100,101,114,115,99,5,0,0,0,0,0,0, + 0,9,0,0,0,5,0,0,0,67,0,0,0,115,227,0, + 0,0,124,4,0,100,1,0,107,2,0,114,27,0,116,0, + 0,124,0,0,131,1,0,125,5,0,110,54,0,124,1,0, + 100,2,0,107,9,0,114,45,0,124,1,0,110,3,0,105, + 0,0,125,6,0,116,1,0,124,6,0,131,1,0,125,7, + 0,116,0,0,124,0,0,124,7,0,124,4,0,131,3,0, + 125,5,0,124,3,0,115,207,0,124,4,0,100,1,0,107, + 2,0,114,122,0,116,0,0,124,0,0,106,2,0,100,3, + 0,131,1,0,100,1,0,25,131,1,0,83,124,0,0,115, + 132,0,124,5,0,83,116,3,0,124,0,0,131,1,0,116, + 3,0,124,0,0,106,2,0,100,3,0,131,1,0,100,1, + 0,25,131,1,0,24,125,8,0,116,4,0,106,5,0,124, + 5,0,106,6,0,100,2,0,116,3,0,124,5,0,106,6, + 0,131,1,0,124,8,0,24,133,2,0,25,25,83,110,16, + 0,116,7,0,124,5,0,124,3,0,116,0,0,131,3,0, + 83,100,2,0,83,40,4,0,0,0,117,214,1,0,0,73, + 109,112,111,114,116,32,97,32,109,111,100,117,108,101,46,10, + 10,32,32,32,32,84,104,101,32,39,103,108,111,98,97,108, + 115,39,32,97,114,103,117,109,101,110,116,32,105,115,32,117, + 115,101,100,32,116,111,32,105,110,102,101,114,32,119,104,101, + 114,101,32,116,104,101,32,105,109,112,111,114,116,32,105,115, + 32,111,99,99,117,114,105,110,103,32,102,114,111,109,10,32, + 32,32,32,116,111,32,104,97,110,100,108,101,32,114,101,108, + 97,116,105,118,101,32,105,109,112,111,114,116,115,46,32,84, + 104,101,32,39,108,111,99,97,108,115,39,32,97,114,103,117, + 109,101,110,116,32,105,115,32,105,103,110,111,114,101,100,46, + 32,84,104,101,10,32,32,32,32,39,102,114,111,109,108,105, + 115,116,39,32,97,114,103,117,109,101,110,116,32,115,112,101, + 99,105,102,105,101,115,32,119,104,97,116,32,115,104,111,117, + 108,100,32,101,120,105,115,116,32,97,115,32,97,116,116,114, + 105,98,117,116,101,115,32,111,110,32,116,104,101,32,109,111, + 100,117,108,101,10,32,32,32,32,98,101,105,110,103,32,105, + 109,112,111,114,116,101,100,32,40,101,46,103,46,32,96,96, + 102,114,111,109,32,109,111,100,117,108,101,32,105,109,112,111, + 114,116,32,60,102,114,111,109,108,105,115,116,62,96,96,41, + 46,32,32,84,104,101,32,39,108,101,118,101,108,39,10,32, + 32,32,32,97,114,103,117,109,101,110,116,32,114,101,112,114, + 101,115,101,110,116,115,32,116,104,101,32,112,97,99,107,97, + 103,101,32,108,111,99,97,116,105,111,110,32,116,111,32,105, + 109,112,111,114,116,32,102,114,111,109,32,105,110,32,97,32, + 114,101,108,97,116,105,118,101,10,32,32,32,32,105,109,112, + 111,114,116,32,40,101,46,103,46,32,96,96,102,114,111,109, + 32,46,46,112,107,103,32,105,109,112,111,114,116,32,109,111, + 100,96,96,32,119,111,117,108,100,32,104,97,118,101,32,97, + 32,39,108,101,118,101,108,39,32,111,102,32,50,41,46,10, + 10,32,32,32,32,105,0,0,0,0,78,117,1,0,0,0, + 46,40,8,0,0,0,117,11,0,0,0,95,103,99,100,95, + 105,109,112,111,114,116,117,17,0,0,0,95,99,97,108,99, + 95,95,95,112,97,99,107,97,103,101,95,95,117,9,0,0, + 0,112,97,114,116,105,116,105,111,110,117,3,0,0,0,108, + 101,110,117,3,0,0,0,115,121,115,117,7,0,0,0,109, + 111,100,117,108,101,115,117,8,0,0,0,95,95,110,97,109, + 101,95,95,117,16,0,0,0,95,104,97,110,100,108,101,95, + 102,114,111,109,108,105,115,116,40,9,0,0,0,117,4,0, + 0,0,110,97,109,101,117,7,0,0,0,103,108,111,98,97, + 108,115,117,6,0,0,0,108,111,99,97,108,115,117,8,0, + 0,0,102,114,111,109,108,105,115,116,117,5,0,0,0,108, + 101,118,101,108,117,6,0,0,0,109,111,100,117,108,101,117, + 8,0,0,0,103,108,111,98,97,108,115,95,117,7,0,0, + 0,112,97,99,107,97,103,101,117,7,0,0,0,99,117,116, + 95,111,102,102,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,10,0,0,0,95,95,105,109,112,111,114,116,95,95,130, + 6,0,0,115,26,0,0,0,0,11,12,1,15,2,24,1, + 12,1,18,1,6,3,12,1,23,1,6,1,4,4,35,3, + 40,2,117,10,0,0,0,95,95,105,109,112,111,114,116,95, + 95,99,2,0,0,0,0,0,0,0,14,0,0,0,13,0, + 0,0,67,0,0,0,115,141,2,0,0,124,1,0,97,0, + 0,124,0,0,97,1,0,116,1,0,106,2,0,106,3,0, + 114,33,0,116,4,0,97,5,0,110,6,0,116,6,0,97, + 5,0,120,47,0,116,0,0,116,1,0,102,2,0,68,93, + 33,0,125,2,0,116,7,0,124,2,0,100,1,0,131,2, + 0,115,52,0,116,8,0,124,2,0,95,9,0,113,52,0, + 113,52,0,87,116,1,0,106,10,0,116,11,0,25,125,3, + 0,120,76,0,100,26,0,68,93,68,0,125,4,0,124,4, + 0,116,1,0,106,10,0,107,7,0,114,148,0,116,8,0, + 106,12,0,124,4,0,131,1,0,125,5,0,110,13,0,116, + 1,0,106,10,0,124,4,0,25,125,5,0,116,13,0,124, + 3,0,124,4,0,124,5,0,131,3,0,1,113,109,0,87, + 100,6,0,100,7,0,103,1,0,102,2,0,100,8,0,100, + 9,0,100,7,0,103,2,0,102,2,0,102,2,0,125,6, + 0,120,149,0,124,6,0,68,93,129,0,92,2,0,125,7, + 0,125,8,0,116,14,0,100,10,0,100,11,0,132,0,0, + 124,8,0,68,131,1,0,131,1,0,115,8,1,116,15,0, + 130,1,0,124,8,0,100,12,0,25,125,9,0,124,7,0, + 116,1,0,106,10,0,107,6,0,114,50,1,116,1,0,106, + 10,0,124,7,0,25,125,10,0,80,113,221,0,121,20,0, + 116,8,0,106,12,0,124,7,0,131,1,0,125,10,0,80, + 87,113,221,0,4,116,16,0,107,10,0,114,93,1,1,1, + 1,119,221,0,89,113,221,0,88,113,221,0,87,116,16,0, + 100,13,0,131,1,0,130,1,0,121,19,0,116,8,0,106, + 12,0,100,14,0,131,1,0,125,11,0,87,110,24,0,4, + 116,16,0,107,10,0,114,155,1,1,1,1,100,15,0,125, + 11,0,89,110,1,0,88,116,8,0,106,12,0,100,16,0, + 131,1,0,125,12,0,124,7,0,100,8,0,107,2,0,114, + 217,1,116,8,0,106,12,0,100,17,0,131,1,0,125,13, + 0,116,13,0,124,3,0,100,18,0,124,13,0,131,3,0, + 1,110,0,0,116,13,0,124,3,0,100,19,0,124,10,0, + 131,3,0,1,116,13,0,124,3,0,100,14,0,124,11,0, + 131,3,0,1,116,13,0,124,3,0,100,16,0,124,12,0, + 131,3,0,1,116,13,0,124,3,0,100,20,0,124,9,0, + 131,3,0,1,116,13,0,124,3,0,100,21,0,116,17,0, + 124,8,0,131,1,0,131,3,0,1,116,13,0,124,3,0, + 100,22,0,116,18,0,131,0,0,131,3,0,1,116,19,0, + 106,20,0,116,0,0,106,21,0,131,0,0,131,1,0,1, + 124,7,0,100,8,0,107,2,0,114,137,2,116,22,0,106, + 23,0,100,23,0,131,1,0,1,100,24,0,116,19,0,107, + 6,0,114,137,2,100,25,0,116,24,0,95,25,0,113,137, + 2,110,0,0,100,15,0,83,40,27,0,0,0,117,250,0, + 0,0,83,101,116,117,112,32,105,109,112,111,114,116,108,105, + 98,32,98,121,32,105,109,112,111,114,116,105,110,103,32,110, + 101,101,100,101,100,32,98,117,105,108,116,45,105,110,32,109, + 111,100,117,108,101,115,32,97,110,100,32,105,110,106,101,99, + 116,105,110,103,32,116,104,101,109,10,32,32,32,32,105,110, + 116,111,32,116,104,101,32,103,108,111,98,97,108,32,110,97, + 109,101,115,112,97,99,101,46,10,10,32,32,32,32,65,115, + 32,115,121,115,32,105,115,32,110,101,101,100,101,100,32,102, + 111,114,32,115,121,115,46,109,111,100,117,108,101,115,32,97, + 99,99,101,115,115,32,97,110,100,32,95,105,109,112,32,105, + 115,32,110,101,101,100,101,100,32,116,111,32,108,111,97,100, + 32,98,117,105,108,116,45,105,110,10,32,32,32,32,109,111, + 100,117,108,101,115,44,32,116,104,111,115,101,32,116,119,111, + 32,109,111,100,117,108,101,115,32,109,117,115,116,32,98,101, + 32,101,120,112,108,105,99,105,116,108,121,32,112,97,115,115, + 101,100,32,105,110,46,10,10,32,32,32,32,117,10,0,0, + 0,95,95,108,111,97,100,101,114,95,95,117,3,0,0,0, 95,105,111,117,9,0,0,0,95,119,97,114,110,105,110,103, 115,117,8,0,0,0,98,117,105,108,116,105,110,115,117,7, - 0,0,0,109,97,114,115,104,97,108,40,32,0,0,0,114, - 94,0,0,0,114,7,0,0,0,114,102,0,0,0,114,103, - 0,0,0,114,105,0,0,0,114,79,1,0,0,114,104,0, - 0,0,114,152,0,0,0,114,140,0,0,0,244,5,0,0, - 0,105,116,101,109,115,114,202,0,0,0,114,61,0,0,0, - 114,177,0,0,0,114,214,0,0,0,114,171,0,0,0,114, - 181,0,0,0,114,222,0,0,0,114,56,0,0,0,114,218, - 0,0,0,114,60,0,0,0,244,3,0,0,0,97,108,108, - 114,86,0,0,0,114,157,0,0,0,114,26,0,0,0,114, - 11,0,0,0,114,11,1,0,0,114,207,0,0,0,114,78, - 1,0,0,114,119,0,0,0,114,165,0,0,0,114,224,0, - 0,0,114,228,0,0,0,40,16,0,0,0,244,10,0,0, - 0,115,121,115,95,109,111,100,117,108,101,244,11,0,0,0, - 95,105,109,112,95,109,111,100,117,108,101,116,11,0,0,0, - 109,111,100,117,108,101,95,116,121,112,101,114,71,0,0,0, - 114,161,0,0,0,116,11,0,0,0,115,101,108,102,95,109, - 111,100,117,108,101,116,12,0,0,0,98,117,105,108,116,105, - 110,95,110,97,109,101,116,14,0,0,0,98,117,105,108,116, - 105,110,95,109,111,100,117,108,101,116,10,0,0,0,111,115, - 95,100,101,116,97,105,108,115,116,10,0,0,0,98,117,105, - 108,116,105,110,95,111,115,114,21,0,0,0,114,25,0,0, - 0,116,9,0,0,0,111,115,95,109,111,100,117,108,101,116, - 13,0,0,0,116,104,114,101,97,100,95,109,111,100,117,108, - 101,116,14,0,0,0,119,101,97,107,114,101,102,95,109,111, - 100,117,108,101,116,13,0,0,0,119,105,110,114,101,103,95, - 109,111,100,117,108,101,114,4,0,0,0,114,4,0,0,0, - 114,5,0,0,0,244,6,0,0,0,95,115,101,116,117,112, - 181,6,0,0,115,102,0,0,0,0,9,6,1,6,2,12, - 1,9,2,6,2,12,1,28,1,15,1,24,1,15,1,12, - 1,15,1,22,2,13,1,13,1,15,1,18,2,13,1,20, - 2,33,1,19,2,31,1,10,1,15,1,13,1,4,2,3, - 1,15,1,5,1,13,1,12,2,12,2,3,1,19,1,13, - 2,11,1,15,2,12,1,15,1,19,2,16,1,16,1,16, - 1,16,1,25,2,19,1,19,1,12,1,13,1,12,1,114, - 90,1,0,0,99,2,0,0,0,0,0,0,0,3,0,0, - 0,3,0,0,0,67,0,0,0,115,136,0,0,0,116,0, - 0,124,0,0,124,1,0,131,2,0,1,116,1,0,131,0, - 0,125,2,0,116,2,0,106,3,0,106,4,0,116,5,0, - 106,6,0,124,2,0,140,0,0,103,1,0,131,1,0,1, - 116,2,0,106,7,0,106,8,0,116,9,0,131,1,0,1, - 116,2,0,106,7,0,106,8,0,116,10,0,131,1,0,1, - 116,11,0,106,12,0,100,1,0,107,2,0,114,116,0,116, - 2,0,106,7,0,106,8,0,116,13,0,131,1,0,1,110, - 0,0,116,2,0,106,7,0,106,8,0,116,14,0,131,1, - 0,1,100,2,0,83,40,3,0,0,0,117,50,0,0,0, - 73,110,115,116,97,108,108,32,105,109,112,111,114,116,108,105, - 98,32,97,115,32,116,104,101,32,105,109,112,108,101,109,101, - 110,116,97,116,105,111,110,32,111,102,32,105,109,112,111,114, - 116,46,114,84,1,0,0,78,40,15,0,0,0,114,90,1, - 0,0,114,234,0,0,0,114,7,0,0,0,114,32,1,0, - 0,114,207,0,0,0,114,39,1,0,0,114,53,1,0,0, - 114,59,1,0,0,114,165,0,0,0,114,214,0,0,0,114, - 222,0,0,0,114,3,0,0,0,114,56,0,0,0,114,224, - 0,0,0,114,27,1,0,0,40,3,0,0,0,114,88,1, - 0,0,114,89,1,0,0,116,17,0,0,0,115,117,112,112, - 111,114,116,101,100,95,108,111,97,100,101,114,115,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,244,8,0,0, - 0,95,105,110,115,116,97,108,108,1,7,0,0,115,16,0, - 0,0,0,2,13,1,9,1,28,1,16,1,16,1,15,1, - 19,1,114,91,1,0,0,40,3,0,0,0,117,3,0,0, - 0,119,105,110,114,1,0,0,0,114,2,0,0,0,40,82, - 0,0,0,114,58,0,0,0,114,10,0,0,0,114,11,0, - 0,0,114,17,0,0,0,114,19,0,0,0,114,28,0,0, - 0,114,38,0,0,0,114,43,0,0,0,114,44,0,0,0, - 114,45,0,0,0,114,54,0,0,0,114,64,0,0,0,114, - 152,0,0,0,244,8,0,0,0,95,95,99,111,100,101,95, - 95,114,203,0,0,0,114,89,0,0,0,114,78,0,0,0, - 114,85,0,0,0,114,65,0,0,0,114,66,0,0,0,114, - 88,0,0,0,114,93,0,0,0,114,96,0,0,0,114,99, - 0,0,0,114,15,0,0,0,114,195,0,0,0,114,14,0, - 0,0,114,18,0,0,0,116,17,0,0,0,95,82,65,87, - 95,77,65,71,73,67,95,78,85,77,66,69,82,114,110,0, - 0,0,114,119,0,0,0,114,104,0,0,0,114,105,0,0, - 0,114,117,0,0,0,114,120,0,0,0,114,127,0,0,0, - 114,129,0,0,0,114,137,0,0,0,114,138,0,0,0,114, - 146,0,0,0,114,155,0,0,0,114,162,0,0,0,114,166, - 0,0,0,114,170,0,0,0,114,173,0,0,0,114,176,0, - 0,0,114,180,0,0,0,114,183,0,0,0,114,190,0,0, - 0,114,200,0,0,0,114,205,0,0,0,114,208,0,0,0, - 114,213,0,0,0,114,214,0,0,0,114,222,0,0,0,114, - 224,0,0,0,114,237,0,0,0,114,241,0,0,0,114,0, - 1,0,0,114,2,1,0,0,114,7,1,0,0,114,11,1, - 0,0,114,8,1,0,0,114,12,1,0,0,114,26,1,0, - 0,114,27,1,0,0,114,39,1,0,0,114,54,1,0,0, - 114,58,1,0,0,114,60,1,0,0,114,63,1,0,0,114, - 73,1,0,0,114,64,1,0,0,114,66,1,0,0,114,67, - 1,0,0,114,68,1,0,0,114,75,1,0,0,114,77,1, - 0,0,114,234,0,0,0,114,81,1,0,0,114,90,1,0, - 0,114,91,1,0,0,114,4,0,0,0,114,4,0,0,0, - 114,4,0,0,0,114,5,0,0,0,244,8,0,0,0,60, - 109,111,100,117,108,101,62,8,0,0,0,115,150,0,0,0, - 6,17,6,3,12,12,12,5,12,5,12,6,12,12,12,10, - 12,6,12,7,15,22,12,8,15,6,6,2,6,3,22,4, - 19,68,19,23,12,19,12,20,12,111,22,1,18,2,6,2, - 9,2,9,1,9,2,15,27,12,23,12,19,12,12,18,8, - 19,17,22,42,18,9,12,15,12,11,12,13,12,11,12,18, - 12,11,12,11,12,13,21,55,21,12,18,10,12,14,19,52, - 19,49,19,50,19,41,22,110,19,29,25,43,25,20,6,3, - 19,40,19,55,19,32,19,91,19,128,19,13,12,9,12,17, - 12,17,6,1,10,2,12,46,12,13,18,24,12,32,12,15, - 12,11,24,36,12,76, + 0,0,0,109,97,114,115,104,97,108,117,5,0,0,0,112, + 111,115,105,120,117,1,0,0,0,47,117,2,0,0,0,110, + 116,117,1,0,0,0,92,99,1,0,0,0,0,0,0,0, + 2,0,0,0,3,0,0,0,115,0,0,0,115,33,0,0, + 0,124,0,0,93,23,0,125,1,0,116,0,0,124,1,0, + 131,1,0,100,0,0,107,2,0,86,1,113,3,0,100,1, + 0,83,40,2,0,0,0,105,1,0,0,0,78,40,1,0, + 0,0,117,3,0,0,0,108,101,110,40,2,0,0,0,117, + 2,0,0,0,46,48,117,3,0,0,0,115,101,112,40,0, + 0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,114, + 111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,95, + 98,111,111,116,115,116,114,97,112,62,117,9,0,0,0,60, + 103,101,110,101,120,112,114,62,198,6,0,0,115,2,0,0, + 0,6,0,117,25,0,0,0,95,115,101,116,117,112,46,60, + 108,111,99,97,108,115,62,46,60,103,101,110,101,120,112,114, + 62,105,0,0,0,0,117,30,0,0,0,105,109,112,111,114, + 116,108,105,98,32,114,101,113,117,105,114,101,115,32,112,111, + 115,105,120,32,111,114,32,110,116,117,7,0,0,0,95,116, + 104,114,101,97,100,78,117,8,0,0,0,95,119,101,97,107, + 114,101,102,117,6,0,0,0,119,105,110,114,101,103,117,7, + 0,0,0,95,119,105,110,114,101,103,117,3,0,0,0,95, + 111,115,117,8,0,0,0,112,97,116,104,95,115,101,112,117, + 15,0,0,0,112,97,116,104,95,115,101,112,97,114,97,116, + 111,114,115,117,11,0,0,0,95,114,101,108,97,120,95,99, + 97,115,101,117,4,0,0,0,46,112,121,119,117,6,0,0, + 0,95,100,46,112,121,100,84,40,4,0,0,0,117,3,0, + 0,0,95,105,111,117,9,0,0,0,95,119,97,114,110,105, + 110,103,115,117,8,0,0,0,98,117,105,108,116,105,110,115, + 117,7,0,0,0,109,97,114,115,104,97,108,40,26,0,0, + 0,117,4,0,0,0,95,105,109,112,117,3,0,0,0,115, + 121,115,117,5,0,0,0,102,108,97,103,115,117,8,0,0, + 0,111,112,116,105,109,105,122,101,117,27,0,0,0,79,80, + 84,73,77,73,90,69,68,95,66,89,84,69,67,79,68,69, + 95,83,85,70,70,73,88,69,83,117,17,0,0,0,66,89, + 84,69,67,79,68,69,95,83,85,70,70,73,88,69,83,117, + 23,0,0,0,68,69,66,85,71,95,66,89,84,69,67,79, + 68,69,95,83,85,70,70,73,88,69,83,117,7,0,0,0, + 104,97,115,97,116,116,114,117,15,0,0,0,66,117,105,108, + 116,105,110,73,109,112,111,114,116,101,114,117,10,0,0,0, + 95,95,108,111,97,100,101,114,95,95,117,7,0,0,0,109, + 111,100,117,108,101,115,117,8,0,0,0,95,95,110,97,109, + 101,95,95,117,11,0,0,0,108,111,97,100,95,109,111,100, + 117,108,101,117,7,0,0,0,115,101,116,97,116,116,114,117, + 3,0,0,0,97,108,108,117,14,0,0,0,65,115,115,101, + 114,116,105,111,110,69,114,114,111,114,117,11,0,0,0,73, + 109,112,111,114,116,69,114,114,111,114,117,3,0,0,0,115, + 101,116,117,16,0,0,0,95,109,97,107,101,95,114,101,108, + 97,120,95,99,97,115,101,117,18,0,0,0,69,88,84,69, + 78,83,73,79,78,95,83,85,70,70,73,88,69,83,117,6, + 0,0,0,101,120,116,101,110,100,117,18,0,0,0,101,120, + 116,101,110,115,105,111,110,95,115,117,102,102,105,120,101,115, + 117,15,0,0,0,83,79,85,82,67,69,95,83,85,70,70, + 73,88,69,83,117,6,0,0,0,97,112,112,101,110,100,117, + 21,0,0,0,87,105,110,100,111,119,115,82,101,103,105,115, + 116,114,121,70,105,110,100,101,114,117,11,0,0,0,68,69, + 66,85,71,95,66,85,73,76,68,40,14,0,0,0,117,10, + 0,0,0,115,121,115,95,109,111,100,117,108,101,117,11,0, + 0,0,95,105,109,112,95,109,111,100,117,108,101,117,6,0, + 0,0,109,111,100,117,108,101,117,11,0,0,0,115,101,108, + 102,95,109,111,100,117,108,101,117,12,0,0,0,98,117,105, + 108,116,105,110,95,110,97,109,101,117,14,0,0,0,98,117, + 105,108,116,105,110,95,109,111,100,117,108,101,117,10,0,0, + 0,111,115,95,100,101,116,97,105,108,115,117,10,0,0,0, + 98,117,105,108,116,105,110,95,111,115,117,15,0,0,0,112, + 97,116,104,95,115,101,112,97,114,97,116,111,114,115,117,8, + 0,0,0,112,97,116,104,95,115,101,112,117,9,0,0,0, + 111,115,95,109,111,100,117,108,101,117,13,0,0,0,116,104, + 114,101,97,100,95,109,111,100,117,108,101,117,14,0,0,0, + 119,101,97,107,114,101,102,95,109,111,100,117,108,101,117,13, + 0,0,0,119,105,110,114,101,103,95,109,111,100,117,108,101, + 40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60, + 102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98, + 46,95,98,111,111,116,115,116,114,97,112,62,117,6,0,0, + 0,95,115,101,116,117,112,166,6,0,0,115,92,0,0,0, + 0,9,6,1,6,2,12,1,9,2,6,2,19,1,15,1, + 16,2,13,1,13,1,15,1,18,2,13,1,20,2,33,1, + 19,2,31,1,10,1,15,1,13,1,4,2,3,1,15,1, + 5,1,13,1,12,2,12,2,3,1,19,1,13,2,11,1, + 15,2,12,1,15,1,19,2,16,1,16,1,16,1,16,1, + 22,2,19,1,19,1,12,1,13,1,12,1,117,6,0,0, + 0,95,115,101,116,117,112,99,2,0,0,0,0,0,0,0, + 3,0,0,0,3,0,0,0,67,0,0,0,115,136,0,0, + 0,116,0,0,124,0,0,124,1,0,131,2,0,1,116,1, + 0,131,0,0,125,2,0,116,2,0,106,3,0,106,4,0, + 116,5,0,106,6,0,124,2,0,140,0,0,103,1,0,131, + 1,0,1,116,2,0,106,7,0,106,8,0,116,9,0,131, + 1,0,1,116,2,0,106,7,0,106,8,0,116,10,0,131, + 1,0,1,116,11,0,106,12,0,100,1,0,107,2,0,114, + 116,0,116,2,0,106,7,0,106,8,0,116,13,0,131,1, + 0,1,110,0,0,116,2,0,106,7,0,106,8,0,116,14, + 0,131,1,0,1,100,2,0,83,40,3,0,0,0,117,50, + 0,0,0,73,110,115,116,97,108,108,32,105,109,112,111,114, + 116,108,105,98,32,97,115,32,116,104,101,32,105,109,112,108, + 101,109,101,110,116,97,116,105,111,110,32,111,102,32,105,109, + 112,111,114,116,46,117,2,0,0,0,110,116,78,40,15,0, + 0,0,117,6,0,0,0,95,115,101,116,117,112,117,27,0, + 0,0,95,103,101,116,95,115,117,112,112,111,114,116,101,100, + 95,102,105,108,101,95,108,111,97,100,101,114,115,117,3,0, + 0,0,115,121,115,117,10,0,0,0,112,97,116,104,95,104, + 111,111,107,115,117,6,0,0,0,101,120,116,101,110,100,117, + 10,0,0,0,70,105,108,101,70,105,110,100,101,114,117,9, + 0,0,0,112,97,116,104,95,104,111,111,107,117,9,0,0, + 0,109,101,116,97,95,112,97,116,104,117,6,0,0,0,97, + 112,112,101,110,100,117,15,0,0,0,66,117,105,108,116,105, + 110,73,109,112,111,114,116,101,114,117,14,0,0,0,70,114, + 111,122,101,110,73,109,112,111,114,116,101,114,117,3,0,0, + 0,95,111,115,117,8,0,0,0,95,95,110,97,109,101,95, + 95,117,21,0,0,0,87,105,110,100,111,119,115,82,101,103, + 105,115,116,114,121,70,105,110,100,101,114,117,10,0,0,0, + 80,97,116,104,70,105,110,100,101,114,40,3,0,0,0,117, + 10,0,0,0,115,121,115,95,109,111,100,117,108,101,117,11, + 0,0,0,95,105,109,112,95,109,111,100,117,108,101,117,17, + 0,0,0,115,117,112,112,111,114,116,101,100,95,108,111,97, + 100,101,114,115,40,0,0,0,0,40,0,0,0,0,117,29, + 0,0,0,60,102,114,111,122,101,110,32,105,109,112,111,114, + 116,108,105,98,46,95,98,111,111,116,115,116,114,97,112,62, + 117,8,0,0,0,95,105,110,115,116,97,108,108,237,6,0, + 0,115,16,0,0,0,0,2,13,1,9,1,28,1,16,1, + 16,1,15,1,19,1,117,8,0,0,0,95,105,110,115,116, + 97,108,108,40,3,0,0,0,117,3,0,0,0,119,105,110, + 117,6,0,0,0,99,121,103,119,105,110,117,6,0,0,0, + 100,97,114,119,105,110,40,75,0,0,0,117,7,0,0,0, + 95,95,100,111,99,95,95,117,27,0,0,0,95,67,65,83, + 69,95,73,78,83,69,78,83,73,84,73,86,69,95,80,76, + 65,84,70,79,82,77,83,117,16,0,0,0,95,109,97,107, + 101,95,114,101,108,97,120,95,99,97,115,101,117,7,0,0, + 0,95,119,95,108,111,110,103,117,7,0,0,0,95,114,95, + 108,111,110,103,117,10,0,0,0,95,112,97,116,104,95,106, + 111,105,110,117,11,0,0,0,95,112,97,116,104,95,115,112, + 108,105,116,117,18,0,0,0,95,112,97,116,104,95,105,115, + 95,109,111,100,101,95,116,121,112,101,117,12,0,0,0,95, + 112,97,116,104,95,105,115,102,105,108,101,117,11,0,0,0, + 95,112,97,116,104,95,105,115,100,105,114,117,13,0,0,0, + 95,119,114,105,116,101,95,97,116,111,109,105,99,117,5,0, + 0,0,95,119,114,97,112,117,4,0,0,0,116,121,112,101, + 117,8,0,0,0,95,95,99,111,100,101,95,95,117,10,0, + 0,0,95,99,111,100,101,95,116,121,112,101,117,10,0,0, + 0,110,101,119,95,109,111,100,117,108,101,117,13,0,0,0, + 95,109,111,100,117,108,101,95,108,111,99,107,115,117,12,0, + 0,0,95,98,108,111,99,107,105,110,103,95,111,110,117,12, + 0,0,0,82,117,110,116,105,109,101,69,114,114,111,114,117, + 14,0,0,0,95,68,101,97,100,108,111,99,107,69,114,114, + 111,114,117,11,0,0,0,95,77,111,100,117,108,101,76,111, + 99,107,117,16,0,0,0,95,68,117,109,109,121,77,111,100, + 117,108,101,76,111,99,107,117,16,0,0,0,95,103,101,116, + 95,109,111,100,117,108,101,95,108,111,99,107,117,19,0,0, + 0,95,108,111,99,107,95,117,110,108,111,99,107,95,109,111, + 100,117,108,101,117,25,0,0,0,95,99,97,108,108,95,119, + 105,116,104,95,102,114,97,109,101,115,95,114,101,109,111,118, + 101,100,117,3,0,0,0,111,114,100,117,17,0,0,0,95, + 82,65,87,95,77,65,71,73,67,95,78,85,77,66,69,82, + 117,5,0,0,0,98,121,116,101,115,117,5,0,0,0,114, + 97,110,103,101,117,12,0,0,0,95,77,65,71,73,67,95, + 66,89,84,69,83,117,8,0,0,0,95,80,89,67,65,67, + 72,69,117,15,0,0,0,83,79,85,82,67,69,95,83,85, + 70,70,73,88,69,83,117,23,0,0,0,68,69,66,85,71, + 95,66,89,84,69,67,79,68,69,95,83,85,70,70,73,88, + 69,83,117,27,0,0,0,79,80,84,73,77,73,90,69,68, + 95,66,89,84,69,67,79,68,69,95,83,85,70,70,73,88, + 69,83,117,17,0,0,0,99,97,99,104,101,95,102,114,111, + 109,95,115,111,117,114,99,101,117,17,0,0,0,115,111,117, + 114,99,101,95,102,114,111,109,95,99,97,99,104,101,117,15, + 0,0,0,95,103,101,116,95,115,111,117,114,99,101,102,105, + 108,101,117,16,0,0,0,95,118,101,114,98,111,115,101,95, + 109,101,115,115,97,103,101,117,11,0,0,0,115,101,116,95, + 112,97,99,107,97,103,101,117,10,0,0,0,115,101,116,95, + 108,111,97,100,101,114,117,17,0,0,0,109,111,100,117,108, + 101,95,102,111,114,95,108,111,97,100,101,114,117,11,0,0, + 0,95,99,104,101,99,107,95,110,97,109,101,117,17,0,0, + 0,95,114,101,113,117,105,114,101,115,95,98,117,105,108,116, + 105,110,117,16,0,0,0,95,114,101,113,117,105,114,101,115, + 95,102,114,111,122,101,110,117,17,0,0,0,95,102,105,110, + 100,95,109,111,100,117,108,101,95,115,104,105,109,117,25,0, + 0,0,95,118,97,108,105,100,97,116,101,95,98,121,116,101, + 99,111,100,101,95,104,101,97,100,101,114,117,17,0,0,0, + 95,99,111,109,112,105,108,101,95,98,121,116,101,99,111,100, + 101,117,15,0,0,0,66,117,105,108,116,105,110,73,109,112, + 111,114,116,101,114,117,14,0,0,0,70,114,111,122,101,110, + 73,109,112,111,114,116,101,114,117,21,0,0,0,87,105,110, + 100,111,119,115,82,101,103,105,115,116,114,121,70,105,110,100, + 101,114,117,13,0,0,0,95,76,111,97,100,101,114,66,97, + 115,105,99,115,117,12,0,0,0,83,111,117,114,99,101,76, + 111,97,100,101,114,117,10,0,0,0,70,105,108,101,76,111, + 97,100,101,114,117,16,0,0,0,83,111,117,114,99,101,70, + 105,108,101,76,111,97,100,101,114,117,20,0,0,0,83,111, + 117,114,99,101,108,101,115,115,70,105,108,101,76,111,97,100, + 101,114,117,18,0,0,0,69,88,84,69,78,83,73,79,78, + 95,83,85,70,70,73,88,69,83,117,19,0,0,0,69,120, + 116,101,110,115,105,111,110,70,105,108,101,76,111,97,100,101, + 114,117,14,0,0,0,95,78,97,109,101,115,112,97,99,101, + 80,97,116,104,117,15,0,0,0,78,97,109,101,115,112,97, + 99,101,76,111,97,100,101,114,117,10,0,0,0,80,97,116, + 104,70,105,110,100,101,114,117,10,0,0,0,70,105,108,101, + 70,105,110,100,101,114,117,18,0,0,0,95,73,109,112,111, + 114,116,76,111,99,107,67,111,110,116,101,120,116,117,13,0, + 0,0,95,114,101,115,111,108,118,101,95,110,97,109,101,117, + 12,0,0,0,95,102,105,110,100,95,109,111,100,117,108,101, + 117,13,0,0,0,95,115,97,110,105,116,121,95,99,104,101, + 99,107,117,8,0,0,0,95,69,82,82,95,77,83,71,117, + 23,0,0,0,95,102,105,110,100,95,97,110,100,95,108,111, + 97,100,95,117,110,108,111,99,107,101,100,117,14,0,0,0, + 95,102,105,110,100,95,97,110,100,95,108,111,97,100,117,11, + 0,0,0,95,103,99,100,95,105,109,112,111,114,116,117,16, + 0,0,0,95,104,97,110,100,108,101,95,102,114,111,109,108, + 105,115,116,117,17,0,0,0,95,99,97,108,99,95,95,95, + 112,97,99,107,97,103,101,95,95,117,27,0,0,0,95,103, + 101,116,95,115,117,112,112,111,114,116,101,100,95,102,105,108, + 101,95,108,111,97,100,101,114,115,117,10,0,0,0,95,95, + 105,109,112,111,114,116,95,95,117,6,0,0,0,95,115,101, + 116,117,112,117,8,0,0,0,95,105,110,115,116,97,108,108, + 40,0,0,0,0,40,0,0,0,0,40,0,0,0,0,117, + 29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,111, + 114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,112, + 62,117,8,0,0,0,60,109,111,100,117,108,101,62,8,0, + 0,0,115,136,0,0,0,6,21,6,3,12,13,12,16,12, + 13,12,12,12,12,12,10,12,6,12,7,15,22,12,8,15, + 3,12,12,6,2,6,3,22,4,19,68,19,23,12,19,12, + 20,12,100,34,1,37,2,6,2,9,2,9,1,9,2,15, + 27,12,23,12,21,12,8,12,13,12,11,12,55,12,18,12, + 11,12,11,12,13,21,54,21,15,19,57,19,54,19,50,19, + 37,22,133,19,29,25,49,25,19,6,3,19,45,19,55,19, + 18,19,91,19,126,19,13,12,9,12,17,12,17,6,2,12, + 50,12,13,18,24,12,34,12,15,12,11,24,36,12,71, }; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/marshal.c --- a/Python/marshal.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/marshal.c Fri Feb 01 23:12:09 2013 +0100 @@ -1,10 +1,8 @@ /* Write Python objects to files and read them back. - This is primarily intended for writing and reading compiled Python code, - even though dicts, lists, sets and frozensets, not commonly seen in - code objects, are supported. - Version 3 of this protocol properly supports circular links - and sharing. */ + This is intended for writing and reading compiled Python code only; + a true persistent storage facility would be much harder, since + it would have to take circular links and sharing into account. */ #define PY_SSIZE_T_CLEAN @@ -33,14 +31,16 @@ #define TYPE_STOPITER 'S' #define TYPE_ELLIPSIS '.' #define TYPE_INT 'i' +/* TYPE_INT64 is deprecated. It is not + generated anymore, and support for reading it + will be removed in Python 3.4. */ +#define TYPE_INT64 'I' #define TYPE_FLOAT 'f' #define TYPE_BINARY_FLOAT 'g' #define TYPE_COMPLEX 'x' #define TYPE_BINARY_COMPLEX 'y' #define TYPE_LONG 'l' #define TYPE_STRING 's' -#define TYPE_INTERNED 't' -#define TYPE_REF 'r' #define TYPE_TUPLE '(' #define TYPE_LIST '[' #define TYPE_DICT '{' @@ -49,7 +49,6 @@ #define TYPE_UNKNOWN '?' #define TYPE_SET '<' #define TYPE_FROZENSET '>' -#define FLAG_REF '\x80' /* with a type, add obj to index */ #define WFERR_OK 0 #define WFERR_UNMARSHALLABLE 1 @@ -66,7 +65,6 @@ PyObject *current_filename; char *ptr; char *end; - PyObject *refs; /* dict on marshal, list on unmarshal */ int version; } WFILE; @@ -97,7 +95,7 @@ } static void -w_string(const char *s, Py_ssize_t n, WFILE *p) +w_string(char *s, int n, WFILE *p) { if (p->fp != NULL) { fwrite(s, 1, n, p->fp); @@ -126,28 +124,6 @@ w_byte((char)((x>>24) & 0xff), p); } -#define SIZE32_MAX 0x7FFFFFFF - -#if SIZEOF_SIZE_T > 4 -# define W_SIZE(n, p) do { \ - if ((n) > SIZE32_MAX) { \ - (p)->depth--; \ - (p)->error = WFERR_UNMARSHALLABLE; \ - return; \ - } \ - w_long((long)(n), p); \ - } while(0) -#else -# define W_SIZE w_long -#endif - -static void -w_pstring(const char *s, Py_ssize_t n, WFILE *p) -{ - W_SIZE(n, p); - w_string(s, n, p); -} - /* We assume that Python longs are stored internally in base some power of 2**15; for the sake of portability we'll always read and write them in base exactly 2**15. */ @@ -160,17 +136,13 @@ #endif #define PyLong_MARSHAL_RATIO (PyLong_SHIFT / PyLong_MARSHAL_SHIFT) -#define W_TYPE(t, p) do { \ - w_byte((t) | flag, (p)); \ -} while(0) - static void -w_PyLong(const PyLongObject *ob, char flag, WFILE *p) +w_PyLong(const PyLongObject *ob, WFILE *p) { Py_ssize_t i, j, n, l; digit d; - W_TYPE(TYPE_LONG, p); + w_byte(TYPE_LONG, p); if (Py_SIZE(ob) == 0) { w_long((long)0, p); return; @@ -185,11 +157,6 @@ d >>= PyLong_MARSHAL_SHIFT; l++; } while (d != 0); - if (l > SIZE32_MAX) { - p->depth--; - p->error = WFERR_UNMARSHALLABLE; - return; - } w_long((long)(Py_SIZE(ob) > 0 ? l : -l), p); for (i=0; i < n-1; i++) { @@ -207,64 +174,10 @@ } while (d != 0); } -static int -w_ref(PyObject *v, char *flag, WFILE *p) -{ - PyObject *id; - PyObject *idx; - - if (p->version < 3 || p->refs == NULL) - return 0; /* not writing object references */ - - /* if it has only one reference, it definitely isn't shared */ - if (Py_REFCNT(v) == 1) - return 0; - - id = PyLong_FromVoidPtr((void*)v); - if (id == NULL) - goto err; - idx = PyDict_GetItem(p->refs, id); - if (idx != NULL) { - /* write the reference index to the stream */ - long w = PyLong_AsLong(idx); - Py_DECREF(id); - if (w == -1 && PyErr_Occurred()) { - goto err; - } - /* we don't store "long" indices in the dict */ - assert(0 <= w && w <= 0x7fffffff); - w_byte(TYPE_REF, p); - w_long(w, p); - return 1; - } else { - int ok; - Py_ssize_t s = PyDict_Size(p->refs); - /* we don't support long indices */ - if (s >= 0x7fffffff) { - PyErr_SetString(PyExc_ValueError, "too many objects"); - goto err; - } - idx = PyLong_FromSsize_t(s); - ok = idx && PyDict_SetItem(p->refs, id, idx) == 0; - Py_DECREF(id); - Py_XDECREF(idx); - if (!ok) - goto err; - *flag |= FLAG_REF; - return 0; - } -err: - p->error = WFERR_UNMARSHALLABLE; - return 1; -} - -static void -w_complex_object(PyObject *v, char flag, WFILE *p); - static void w_object(PyObject *v, WFILE *p) { - char flag = '\0'; + Py_ssize_t i, n; p->depth++; @@ -289,35 +202,24 @@ else if (v == Py_True) { w_byte(TYPE_TRUE, p); } - else if (!w_ref(v, &flag, p)) - w_complex_object(v, flag, p); - - p->depth--; -} - -static void -w_complex_object(PyObject *v, char flag, WFILE *p) -{ - Py_ssize_t i, n; - - if (PyLong_CheckExact(v)) { + else if (PyLong_CheckExact(v)) { long x = PyLong_AsLong(v); if ((x == -1) && PyErr_Occurred()) { PyLongObject *ob = (PyLongObject *)v; PyErr_Clear(); - w_PyLong(ob, flag, p); + w_PyLong(ob, p); } else { #if SIZEOF_LONG > 4 long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31); if (y && y != -1) { /* Too large for TYPE_INT */ - w_PyLong((PyLongObject*)v, flag, p); + w_PyLong((PyLongObject*)v, p); } else #endif { - W_TYPE(TYPE_INT, p); + w_byte(TYPE_INT, p); w_long(x, p); } } @@ -330,7 +232,7 @@ p->error = WFERR_UNMARSHALLABLE; return; } - W_TYPE(TYPE_BINARY_FLOAT, p); + w_byte(TYPE_BINARY_FLOAT, p); w_string((char*)buf, 8, p); } else { @@ -341,9 +243,9 @@ return; } n = strlen(buf); - W_TYPE(TYPE_FLOAT, p); + w_byte(TYPE_FLOAT, p); w_byte((int)n, p); - w_string(buf, n, p); + w_string(buf, (int)n, p); PyMem_Free(buf); } } @@ -355,7 +257,7 @@ p->error = WFERR_UNMARSHALLABLE; return; } - W_TYPE(TYPE_BINARY_COMPLEX, p); + w_byte(TYPE_BINARY_COMPLEX, p); w_string((char*)buf, 8, p); if (_PyFloat_Pack8(PyComplex_ImagAsDouble(v), buf, 1) < 0) { @@ -366,7 +268,7 @@ } else { char *buf; - W_TYPE(TYPE_COMPLEX, p); + w_byte(TYPE_COMPLEX, p); buf = PyOS_double_to_string(PyComplex_RealAsDouble(v), 'g', 17, 0, NULL); if (!buf) { @@ -375,7 +277,7 @@ } n = strlen(buf); w_byte((int)n, p); - w_string(buf, n, p); + w_string(buf, (int)n, p); PyMem_Free(buf); buf = PyOS_double_to_string(PyComplex_ImagAsDouble(v), 'g', 17, 0, NULL); @@ -385,13 +287,21 @@ } n = strlen(buf); w_byte((int)n, p); - w_string(buf, n, p); + w_string(buf, (int)n, p); PyMem_Free(buf); } } else if (PyBytes_CheckExact(v)) { - W_TYPE(TYPE_STRING, p); - w_pstring(PyBytes_AS_STRING(v), PyBytes_GET_SIZE(v), p); + w_byte(TYPE_STRING, p); + n = PyBytes_GET_SIZE(v); + if (n > INT_MAX) { + /* huge strings are not supported */ + p->depth--; + p->error = WFERR_UNMARSHALLABLE; + return; + } + w_long((long)n, p); + w_string(PyBytes_AS_STRING(v), (int)n, p); } else if (PyUnicode_CheckExact(v)) { PyObject *utf8; @@ -401,25 +311,29 @@ p->error = WFERR_UNMARSHALLABLE; return; } - if (p->version >= 3 && PyUnicode_CHECK_INTERNED(v)) - W_TYPE(TYPE_INTERNED, p); - else - W_TYPE(TYPE_UNICODE, p); - w_pstring(PyBytes_AS_STRING(utf8), PyBytes_GET_SIZE(utf8), p); + w_byte(TYPE_UNICODE, p); + n = PyBytes_GET_SIZE(utf8); + if (n > INT_MAX) { + p->depth--; + p->error = WFERR_UNMARSHALLABLE; + return; + } + w_long((long)n, p); + w_string(PyBytes_AS_STRING(utf8), (int)n, p); Py_DECREF(utf8); } else if (PyTuple_CheckExact(v)) { - W_TYPE(TYPE_TUPLE, p); + w_byte(TYPE_TUPLE, p); n = PyTuple_Size(v); - W_SIZE(n, p); + w_long((long)n, p); for (i = 0; i < n; i++) { w_object(PyTuple_GET_ITEM(v, i), p); } } else if (PyList_CheckExact(v)) { - W_TYPE(TYPE_LIST, p); + w_byte(TYPE_LIST, p); n = PyList_GET_SIZE(v); - W_SIZE(n, p); + w_long((long)n, p); for (i = 0; i < n; i++) { w_object(PyList_GET_ITEM(v, i), p); } @@ -427,7 +341,7 @@ else if (PyDict_CheckExact(v)) { Py_ssize_t pos; PyObject *key, *value; - W_TYPE(TYPE_DICT, p); + w_byte(TYPE_DICT, p); /* This one is NULL object terminated! */ pos = 0; while (PyDict_Next(v, &pos, &key, &value)) { @@ -440,16 +354,16 @@ PyObject *value, *it; if (PyObject_TypeCheck(v, &PySet_Type)) - W_TYPE(TYPE_SET, p); + w_byte(TYPE_SET, p); else - W_TYPE(TYPE_FROZENSET, p); + w_byte(TYPE_FROZENSET, p); n = PyObject_Size(v); if (n == -1) { p->depth--; p->error = WFERR_UNMARSHALLABLE; return; } - W_SIZE(n, p); + w_long((long)n, p); it = PyObject_GetIter(v); if (it == NULL) { p->depth--; @@ -469,7 +383,7 @@ } else if (PyCode_Check(v)) { PyCodeObject *co = (PyCodeObject *)v; - W_TYPE(TYPE_CODE, p); + w_byte(TYPE_CODE, p); w_long(co->co_argcount, p); w_long(co->co_kwonlyargcount, p); w_long(co->co_nlocals, p); @@ -488,6 +402,7 @@ } else if (PyObject_CheckBuffer(v)) { /* Write unknown buffer-style objects as a string */ + char *s; Py_buffer view; if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) != 0) { w_byte(TYPE_UNKNOWN, p); @@ -495,14 +410,23 @@ p->error = WFERR_UNMARSHALLABLE; return; } - W_TYPE(TYPE_STRING, p); - w_pstring(view.buf, view.len, p); + w_byte(TYPE_STRING, p); + n = view.len; + s = view.buf; + if (n > INT_MAX) { + p->depth--; + p->error = WFERR_UNMARSHALLABLE; + return; + } + w_long((long)n, p); + w_string(s, (int)n, p); PyBuffer_Release(&view); } else { - W_TYPE(TYPE_UNKNOWN, p); + w_byte(TYPE_UNKNOWN, p); p->error = WFERR_UNMARSHALLABLE; } + p->depth--; } /* version currently has no effect for writing longs. */ @@ -513,7 +437,6 @@ wf.fp = fp; wf.error = WFERR_OK; wf.depth = 0; - wf.refs = NULL; wf.version = version; w_long(x, &wf); } @@ -525,32 +448,26 @@ wf.fp = fp; wf.error = WFERR_OK; wf.depth = 0; - if (version >= 3) { - if ((wf.refs = PyDict_New()) == NULL) - return; /* caller mush check PyErr_Occurred() */ - } else - wf.refs = NULL; wf.version = version; w_object(x, &wf); - Py_XDECREF(wf.refs); } typedef WFILE RFILE; /* Same struct with different invariants */ #define rs_byte(p) (((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr++ : EOF) -static Py_ssize_t -r_string(char *s, Py_ssize_t n, RFILE *p) +static int +r_string(char *s, int n, RFILE *p) { char *ptr; - Py_ssize_t read, left; + int read, left; if (!p->readable) { if (p->fp != NULL) /* The result fits into int because it must be <=n. */ - read = fread(s, 1, n, p->fp); + read = (int) fread(s, 1, n, p->fp); else { - left = p->end - p->ptr; + left = (int)(p->end - p->ptr); read = (left < n) ? left : n; memcpy(s, p->ptr, read); p->ptr += read; @@ -559,7 +476,7 @@ else { _Py_IDENTIFIER(read); - PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "n", n); + PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "i", n); read = 0; if (data != NULL) { if (!PyBytes_Check(data)) { @@ -568,19 +485,10 @@ data->ob_type->tp_name); } else { - read = (int)PyBytes_GET_SIZE(data); + read = PyBytes_GET_SIZE(data); if (read > 0) { - if (read > n) { - PyErr_Format(PyExc_ValueError, - "read() returned too much data: " - "%zd bytes requested, %zd returned", - n, read); - read = -1; - } - else { - ptr = PyBytes_AS_STRING(data); - memcpy(s, ptr, read); - } + ptr = PyBytes_AS_STRING(data); + memcpy(s, ptr, read); } } Py_DECREF(data); @@ -598,7 +506,7 @@ { int c = EOF; unsigned char ch; - Py_ssize_t n; + int n; if (!p->readable) c = p->fp ? getc(p->fp) : rs_byte(p); @@ -642,12 +550,48 @@ return x; } +/* r_long64 deals with the TYPE_INT64 code. On a machine with + sizeof(long) > 4, it returns a Python int object, else a Python long + object. Note that w_long64 writes out TYPE_INT if 32 bits is enough, + so there's no inefficiency here in returning a PyLong on 32-bit boxes + for everything written via TYPE_INT64 (i.e., if an int is written via + TYPE_INT64, it *needs* more than 32 bits). +*/ +static PyObject * +r_long64(RFILE *p) +{ + PyObject *result = NULL; + long lo4 = r_long(p); + long hi4 = r_long(p); + + if (!PyErr_Occurred()) { +#if SIZEOF_LONG > 4 + long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL); + result = PyLong_FromLong(x); +#else + unsigned char buf[8]; + int one = 1; + int is_little_endian = (int)*(char*)&one; + if (is_little_endian) { + memcpy(buf, &lo4, 4); + memcpy(buf+4, &hi4, 4); + } + else { + memcpy(buf, &hi4, 4); + memcpy(buf+4, &lo4, 4); + } + result = _PyLong_FromByteArray(buf, 8, is_little_endian, 1); +#endif + } + return result; +} + static PyObject * r_PyLong(RFILE *p) { PyLongObject *ob; - long n, size, i; - int j, md, shorts_in_top_digit; + int size, i, j, md, shorts_in_top_digit; + long n; digit d; n = r_long(p); @@ -655,7 +599,7 @@ return NULL; if (n == 0) return (PyObject *)_PyLong_New(0); - if (n < -SIZE32_MAX || n > SIZE32_MAX) { + if (n < -INT_MAX || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (long size out of range)"); return NULL; @@ -711,62 +655,6 @@ return NULL; } -/* allocate the reflist index for a new object. Return -1 on failure */ -static Py_ssize_t -r_ref_reserve(int flag, RFILE *p) -{ - if (flag) { /* currently only FLAG_REF is defined */ - Py_ssize_t idx = PyList_Size(p->refs); - if (idx < 0) - return -1; - if (idx >= 0x7ffffffe) { - PyErr_SetString(PyExc_ValueError, "bad marshal data (index list too large)"); - return -1; - } - if (PyList_Append(p->refs, Py_None) < 0) - return -1; - return idx; - } else - return 0; -} - -/* insert the new object 'o' to the reflist at previously - * allocated index 'idx'. - * 'o' can be NULL, in which case nothing is done. - * if 'o' was non-NULL, and the function succeeds, 'o' is returned. - * if 'o' was non-NULL, and the function fails, 'o' is released and - * NULL returned. This simplifies error checking at the call site since - * a single test for NULL for the function result is enough. - */ -static PyObject * -r_ref_insert(PyObject *o, Py_ssize_t idx, int flag, RFILE *p) -{ - if (o != NULL && flag) { /* currently only FLAG_REF is defined */ - if (PyList_SetItem(p->refs, idx, o) < 0) { - Py_DECREF(o); /* release the new object */ - return NULL; - } else { - Py_INCREF(o); /* a reference for the list */ - } - } - return o; -} - -/* combination of both above, used when an object can be - * created whenever it is seen in the file, as opposed to - * after having loaded its sub-objects. - */ -static PyObject * -r_ref(PyObject *o, int flag, RFILE *p) -{ - if (o != NULL && flag) { /* currently only FLAG_REF is defined */ - if (PyList_Append(p->refs, o) < 0) { - Py_DECREF(o); /* release the new object */ - return NULL; - } - } - return o; -} static PyObject * r_object(RFILE *p) @@ -774,18 +662,10 @@ /* NULL is a valid return value, it does not necessarily means that an exception is set. */ PyObject *v, *v2; - Py_ssize_t idx = 0; long i, n; - int type, code = r_byte(p); - int flag; + int type = r_byte(p); PyObject *retval; - if (code == EOF) { - PyErr_SetString(PyExc_EOFError, - "EOF read where object expected"); - return NULL; - } - p->depth++; if (p->depth > MAX_MARSHAL_STACK_DEPTH) { @@ -794,15 +674,13 @@ return NULL; } - flag = code & FLAG_REF; - type = code & ~FLAG_REF; + switch (type) { -#define R_REF(O) do{\ - if (flag) \ - O = r_ref(O, flag, p);\ -} while (0) - - switch (type) { + case EOF: + PyErr_SetString(PyExc_EOFError, + "EOF read where object expected"); + retval = NULL; + break; case TYPE_NULL: retval = NULL; @@ -836,12 +714,14 @@ case TYPE_INT: n = r_long(p); retval = PyErr_Occurred() ? NULL : PyLong_FromLong(n); - R_REF(retval); + break; + + case TYPE_INT64: + retval = r_long64(p); break; case TYPE_LONG: retval = r_PyLong(p); - R_REF(retval); break; case TYPE_FLOAT: @@ -850,19 +730,16 @@ double dx; retval = NULL; n = r_byte(p); - if (n == EOF) { + if (n == EOF || r_string(buf, (int)n, p) != n) { PyErr_SetString(PyExc_EOFError, "EOF read where object expected"); break; } - if (r_string(buf, n, p) != n) - break; buf[n] = '\0'; dx = PyOS_string_to_double(buf, NULL, NULL); if (dx == -1.0 && PyErr_Occurred()) break; retval = PyFloat_FromDouble(dx); - R_REF(retval); break; } @@ -871,6 +748,8 @@ unsigned char buf[8]; double x; if (r_string((char*)buf, 8, p) != 8) { + PyErr_SetString(PyExc_EOFError, + "EOF read where object expected"); retval = NULL; break; } @@ -880,7 +759,6 @@ break; } retval = PyFloat_FromDouble(x); - R_REF(retval); break; } @@ -890,31 +768,26 @@ Py_complex c; retval = NULL; n = r_byte(p); - if (n == EOF) { + if (n == EOF || r_string(buf, (int)n, p) != n) { PyErr_SetString(PyExc_EOFError, "EOF read where object expected"); break; } - if (r_string(buf, n, p) != n) - break; buf[n] = '\0'; c.real = PyOS_string_to_double(buf, NULL, NULL); if (c.real == -1.0 && PyErr_Occurred()) break; n = r_byte(p); - if (n == EOF) { + if (n == EOF || r_string(buf, (int)n, p) != n) { PyErr_SetString(PyExc_EOFError, "EOF read where object expected"); break; } - if (r_string(buf, n, p) != n) - break; buf[n] = '\0'; c.imag = PyOS_string_to_double(buf, NULL, NULL); if (c.imag == -1.0 && PyErr_Occurred()) break; retval = PyComplex_FromCComplex(c); - R_REF(retval); break; } @@ -923,6 +796,8 @@ unsigned char buf[8]; Py_complex c; if (r_string((char*)buf, 8, p) != 8) { + PyErr_SetString(PyExc_EOFError, + "EOF read where object expected"); retval = NULL; break; } @@ -932,6 +807,8 @@ break; } if (r_string((char*)buf, 8, p) != 8) { + PyErr_SetString(PyExc_EOFError, + "EOF read where object expected"); retval = NULL; break; } @@ -941,7 +818,6 @@ break; } retval = PyComplex_FromCComplex(c); - R_REF(retval); break; } @@ -951,7 +827,7 @@ retval = NULL; break; } - if (n < 0 || n > SIZE32_MAX) { + if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (string size out of range)"); retval = NULL; break; @@ -961,17 +837,17 @@ retval = NULL; break; } - if (r_string(PyBytes_AS_STRING(v), n, p) != n) { + if (r_string(PyBytes_AS_STRING(v), (int)n, p) != n) { Py_DECREF(v); + PyErr_SetString(PyExc_EOFError, + "EOF read where object expected"); retval = NULL; break; } retval = v; - R_REF(retval); break; case TYPE_UNICODE: - case TYPE_INTERNED: { char *buffer; @@ -980,36 +856,26 @@ retval = NULL; break; } - if (n < 0 || n > SIZE32_MAX) { + if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (unicode size out of range)"); retval = NULL; break; } - if (n != 0) { - buffer = PyMem_NEW(char, n); - if (buffer == NULL) { - retval = PyErr_NoMemory(); - break; - } - if (r_string(buffer, n, p) != n) { - PyMem_DEL(buffer); - retval = NULL; - break; - } - v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass"); + buffer = PyMem_NEW(char, n); + if (buffer == NULL) { + retval = PyErr_NoMemory(); + break; + } + if (r_string(buffer, (int)n, p) != n) { PyMem_DEL(buffer); - } - else { - v = PyUnicode_New(0, 0); - } - if (v == NULL) { + PyErr_SetString(PyExc_EOFError, + "EOF read where object expected"); retval = NULL; break; } - if (type == TYPE_INTERNED) - PyUnicode_InternInPlace(&v); + v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass"); + PyMem_DEL(buffer); retval = v; - R_REF(retval); break; } @@ -1019,13 +885,12 @@ retval = NULL; break; } - if (n < 0 || n > SIZE32_MAX) { + if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (tuple size out of range)"); retval = NULL; break; } - v = PyTuple_New(n); - R_REF(v); + v = PyTuple_New((int)n); if (v == NULL) { retval = NULL; break; @@ -1040,7 +905,7 @@ v = NULL; break; } - PyTuple_SET_ITEM(v, i, v2); + PyTuple_SET_ITEM(v, (int)i, v2); } retval = v; break; @@ -1051,13 +916,12 @@ retval = NULL; break; } - if (n < 0 || n > SIZE32_MAX) { + if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (list size out of range)"); retval = NULL; break; } - v = PyList_New(n); - R_REF(v); + v = PyList_New((int)n); if (v == NULL) { retval = NULL; break; @@ -1072,14 +936,13 @@ v = NULL; break; } - PyList_SET_ITEM(v, i, v2); + PyList_SET_ITEM(v, (int)i, v2); } retval = v; break; case TYPE_DICT: v = PyDict_New(); - R_REF(v); if (v == NULL) { retval = NULL; break; @@ -1109,22 +972,12 @@ retval = NULL; break; } - if (n < 0 || n > SIZE32_MAX) { + if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)"); retval = NULL; break; } v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL); - if (type == TYPE_SET) { - R_REF(v); - } else { - /* must use delayed registration of frozensets because they must - * be init with a refcount of 1 - */ - idx = r_ref_reserve(flag, p); - if (idx < 0) - Py_CLEAR(v); /* signal error */ - } if (v == NULL) { retval = NULL; break; @@ -1147,8 +1000,6 @@ } Py_DECREF(v2); } - if (type != TYPE_SET) - v = r_ref_insert(v, idx, flag, p); retval = v; break; @@ -1170,12 +1021,6 @@ int firstlineno; PyObject *lnotab = NULL; - idx = r_ref_reserve(flag, p); - if (idx < 0) { - retval = NULL; - break; - } - v = NULL; /* XXX ignore long->int overflows for now */ @@ -1241,7 +1086,6 @@ code, consts, names, varnames, freevars, cellvars, filename, name, firstlineno, lnotab); - v = r_ref_insert(v, idx, flag, p); code_error: Py_XDECREF(code); @@ -1257,23 +1101,6 @@ retval = v; break; - case TYPE_REF: - n = r_long(p); - if (n < 0 || n >= PyList_GET_SIZE(p->refs)) { - PyErr_SetString(PyExc_ValueError, "bad marshal data (invalid reference)"); - retval = NULL; - break; - } - v = PyList_GET_ITEM(p->refs, n); - if (v == Py_None) { - PyErr_SetString(PyExc_ValueError, "bad marshal data (invalid reference)"); - retval = NULL; - break; - } - Py_INCREF(v); - retval = v; - break; - default: /* Bogus data got written, which isn't ideal. This will let you keep working and recover. */ @@ -1353,8 +1180,12 @@ if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) { char* pBuf = (char *)PyMem_MALLOC(filesize); if (pBuf != NULL) { - size_t n = fread(pBuf, 1, (size_t)filesize, fp); - PyObject* v = PyMarshal_ReadObjectFromString(pBuf, n); + PyObject* v; + size_t n; + /* filesize must fit into an int, because it + is smaller than REASONABLE_FILE_LIMIT */ + n = fread(pBuf, 1, (int)filesize, fp); + v = PyMarshal_ReadObjectFromString(pBuf, n); PyMem_FREE(pBuf); return v; } @@ -1379,11 +1210,7 @@ rf.current_filename = NULL; rf.depth = 0; rf.ptr = rf.end = NULL; - rf.refs = PyList_New(0); - if (rf.refs == NULL) - return NULL; result = r_object(&rf); - Py_DECREF(rf.refs); return result; } @@ -1398,11 +1225,7 @@ rf.ptr = str; rf.end = str + len; rf.depth = 0; - rf.refs = PyList_New(0); - if (rf.refs == NULL) - return NULL; result = r_object(&rf); - Py_DECREF(rf.refs); return result; } @@ -1421,13 +1244,7 @@ wf.error = WFERR_OK; wf.depth = 0; wf.version = version; - if (version >= 3) { - if ((wf.refs = PyDict_New()) == NULL) - return NULL; - } else - wf.refs = NULL; w_object(x, &wf); - Py_XDECREF(wf.refs); if (wf.str != NULL) { char *base = PyBytes_AS_STRING((PyBytesObject *)wf.str); if (wf.ptr - base > PY_SSIZE_T_MAX) { @@ -1499,8 +1316,6 @@ * Make a call to the read method, but read zero bytes. * This is to ensure that the object passed in at least * has a read method which returns bytes. - * This can be removed if we guarantee good error handling - * for r_string() */ data = _PyObject_CallMethodId(f, &PyId_read, "i", 0); if (data == NULL) @@ -1516,11 +1331,7 @@ rf.fp = NULL; rf.readable = f; rf.current_filename = NULL; - if ((rf.refs = PyList_New(0)) != NULL) { - result = read_object(&rf); - Py_DECREF(rf.refs); - } else - result = NULL; + result = read_object(&rf); } Py_DECREF(data); return result; @@ -1577,11 +1388,8 @@ rf.ptr = s; rf.end = s + n; rf.depth = 0; - if ((rf.refs = PyList_New(0)) == NULL) - return NULL; result = read_object(&rf); PyBuffer_Release(&p); - Py_DECREF(rf.refs); return result; } @@ -1621,7 +1429,6 @@ version -- indicates the format that the module uses. Version 0 is the\n\ historical format, version 1 shares interned strings and version 2\n\ uses a binary format for floating point numbers.\n\ - Version 3 shares common object references (New in version 3.4).\n\ \n\ Functions:\n\ \n\ diff -r 35c88c53cf64 -r ecc10f0afb76 Python/mystrtoul.c --- a/Python/mystrtoul.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/mystrtoul.c Fri Feb 01 23:12:09 2013 +0100 @@ -99,7 +99,7 @@ register int ovlimit; /* required digits to overflow */ /* skip leading white space */ - while (*str && Py_ISSPACE(Py_CHARMASK(*str))) + while (*str && isspace(Py_CHARMASK(*str))) ++str; /* check for leading 0b, 0o or 0x for auto-base or base 16 */ @@ -138,7 +138,7 @@ /* skip all zeroes... */ while (*str == '0') ++str; - while (Py_ISSPACE(Py_CHARMASK(*str))) + while (isspace(Py_CHARMASK(*str))) ++str; if (ptr) *ptr = str; @@ -266,7 +266,7 @@ unsigned long uresult; char sign; - while (*str && Py_ISSPACE(Py_CHARMASK(*str))) + while (*str && isspace(Py_CHARMASK(*str))) str++; sign = *str; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/opcode_targets.h --- a/Python/opcode_targets.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/opcode_targets.h Fri Feb 01 23:12:09 2013 +0100 @@ -68,7 +68,7 @@ &&TARGET_BINARY_OR, &&TARGET_INPLACE_POWER, &&TARGET_GET_ITER, - &&_unknown_opcode, + &&TARGET_STORE_LOCALS, &&TARGET_PRINT_EXPR, &&TARGET_LOAD_BUILD_CLASS, &&TARGET_YIELD_FROM, @@ -147,7 +147,7 @@ &&TARGET_LIST_APPEND, &&TARGET_SET_ADD, &&TARGET_MAP_ADD, - &&TARGET_LOAD_CLASSDEREF, + &&_unknown_opcode, &&_unknown_opcode, &&_unknown_opcode, &&_unknown_opcode, diff -r 35c88c53cf64 -r ecc10f0afb76 Python/peephole.c --- a/Python/peephole.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/peephole.c Fri Feb 01 23:12:09 2013 +0100 @@ -381,10 +381,8 @@ /* Make a modifiable copy of the code string */ codestr = (unsigned char *)PyMem_Malloc(codelen); - if (codestr == NULL) { - PyErr_NoMemory(); + if (codestr == NULL) goto exitError; - } codestr = (unsigned char *)memcpy(codestr, PyBytes_AS_STRING(code), codelen); @@ -398,10 +396,8 @@ /* Mapping to new jump targets after NOPs are removed */ addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); - if (addrmap == NULL) { - PyErr_NoMemory(); + if (addrmap == NULL) goto exitError; - } blocks = markblocks(codestr, codelen); if (blocks == NULL) diff -r 35c88c53cf64 -r ecc10f0afb76 Python/pyarena.c --- a/Python/pyarena.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/pyarena.c Fri Feb 01 23:12:09 2013 +0100 @@ -77,7 +77,7 @@ { /* Allocate header and block as one unit. ab_mem points just past header. */ - block *b = (block *)PyMem_Malloc(sizeof(block) + size); + block *b = (block *)malloc(sizeof(block) + size); if (!b) return NULL; b->ab_size = size; @@ -92,7 +92,7 @@ block_free(block *b) { while (b) { block *next = b->ab_next; - PyMem_Free(b); + free(b); b = next; } } @@ -127,20 +127,20 @@ PyArena * PyArena_New() { - PyArena* arena = (PyArena *)PyMem_Malloc(sizeof(PyArena)); + PyArena* arena = (PyArena *)malloc(sizeof(PyArena)); if (!arena) return (PyArena*)PyErr_NoMemory(); arena->a_head = block_new(DEFAULT_BLOCK_SIZE); arena->a_cur = arena->a_head; if (!arena->a_head) { - PyMem_Free((void *)arena); + free((void *)arena); return (PyArena*)PyErr_NoMemory(); } arena->a_objects = PyList_New(0); if (!arena->a_objects) { block_free(arena->a_head); - PyMem_Free((void *)arena); + free((void *)arena); return (PyArena*)PyErr_NoMemory(); } #if defined(Py_DEBUG) @@ -156,6 +156,7 @@ void PyArena_Free(PyArena *arena) { + int r; assert(arena); #if defined(Py_DEBUG) /* @@ -172,8 +173,14 @@ assert(arena->a_objects->ob_refcnt == 1); */ + /* Clear all the elements from the list. This is necessary + to guarantee that they will be DECREFed. */ + r = PyList_SetSlice(arena->a_objects, + 0, PyList_GET_SIZE(arena->a_objects), NULL); + assert(r == 0); + assert(PyList_GET_SIZE(arena->a_objects) == 0); Py_DECREF(arena->a_objects); - PyMem_Free(arena); + free(arena); } void * diff -r 35c88c53cf64 -r ecc10f0afb76 Python/pystate.c --- a/Python/pystate.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/pystate.c Fri Feb 01 23:12:09 2013 +0100 @@ -6,11 +6,11 @@ /* -------------------------------------------------------------------------- CAUTION -Always use PyMem_RawMalloc() and PyMem_RawFree() directly in this file. A -number of these functions are advertised as safe to call when the GIL isn't -held, and in a debug build Python redirects (e.g.) PyMem_NEW (etc) to Python's -debugging obmalloc functions. Those aren't thread-safe (they rely on the GIL -to avoid the expense of doing their own locking). +Always use malloc() and free() directly in this file. A number of these +functions are advertised as safe to call when the GIL isn't held, and in +a debug build Python redirects (e.g.) PyMem_NEW (etc) to Python's debugging +obmalloc functions. Those aren't thread-safe (they rely on the GIL to avoid +the expense of doing their own locking). -------------------------------------------------------------------------- */ #ifdef HAVE_DLOPEN @@ -60,7 +60,7 @@ PyInterpreterState_New(void) { PyInterpreterState *interp = (PyInterpreterState *) - PyMem_RawMalloc(sizeof(PyInterpreterState)); + malloc(sizeof(PyInterpreterState)); if (interp != NULL) { HEAD_INIT(); @@ -148,7 +148,7 @@ Py_FatalError("PyInterpreterState_Delete: remaining threads"); *p = interp->next; HEAD_UNLOCK(); - PyMem_RawFree(interp); + free(interp); #ifdef WITH_THREAD if (interp_head == NULL && head_mutex != NULL) { PyThread_free_lock(head_mutex); @@ -168,7 +168,7 @@ static PyThreadState * new_threadstate(PyInterpreterState *interp, int init) { - PyThreadState *tstate = (PyThreadState *)PyMem_RawMalloc(sizeof(PyThreadState)); + PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState)); if (_PyThreadState_GetFrame == NULL) _PyThreadState_GetFrame = threadstate_getframe; @@ -213,10 +213,7 @@ _PyThreadState_Init(tstate); HEAD_LOCK(); - tstate->prev = NULL; tstate->next = interp->tstate_head; - if (tstate->next) - tstate->next->prev = tstate; interp->tstate_head = tstate; HEAD_UNLOCK(); } @@ -352,20 +349,37 @@ tstate_delete_common(PyThreadState *tstate) { PyInterpreterState *interp; + PyThreadState **p; + PyThreadState *prev_p = NULL; if (tstate == NULL) Py_FatalError("PyThreadState_Delete: NULL tstate"); interp = tstate->interp; if (interp == NULL) Py_FatalError("PyThreadState_Delete: NULL interp"); HEAD_LOCK(); - if (tstate->prev) - tstate->prev->next = tstate->next; - else - interp->tstate_head = tstate->next; - if (tstate->next) - tstate->next->prev = tstate->prev; + for (p = &interp->tstate_head; ; p = &(*p)->next) { + if (*p == NULL) + Py_FatalError( + "PyThreadState_Delete: invalid tstate"); + if (*p == tstate) + break; + /* Sanity check. These states should never happen but if + * they do we must abort. Otherwise we'll end up spinning in + * in a tight loop with the lock held. A similar check is done + * in thread.c find_key(). */ + if (*p == prev_p) + Py_FatalError( + "PyThreadState_Delete: small circular list(!)" + " and tstate not found."); + prev_p = *p; + if ((*p)->next == interp->tstate_head) + Py_FatalError( + "PyThreadState_Delete: circular list(!) and" + " tstate not found."); + } + *p = tstate->next; HEAD_UNLOCK(); - PyMem_RawFree(tstate); + free(tstate); } @@ -374,11 +388,11 @@ { if (tstate == _Py_atomic_load_relaxed(&_PyThreadState_Current)) Py_FatalError("PyThreadState_Delete: tstate is still current"); + tstate_delete_common(tstate); #ifdef WITH_THREAD if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) PyThread_delete_key_value(autoTLSkey); #endif /* WITH_THREAD */ - tstate_delete_common(tstate); } @@ -392,51 +406,14 @@ Py_FatalError( "PyThreadState_DeleteCurrent: no current tstate"); _Py_atomic_store_relaxed(&_PyThreadState_Current, NULL); + tstate_delete_common(tstate); if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) PyThread_delete_key_value(autoTLSkey); - tstate_delete_common(tstate); PyEval_ReleaseLock(); } #endif /* WITH_THREAD */ -/* - * Delete all thread states except the one passed as argument. - * Note that, if there is a current thread state, it *must* be the one - * passed as argument. Also, this won't touch any other interpreters - * than the current one, since we don't know which thread state should - * be kept in those other interpreteres. - */ -void -_PyThreadState_DeleteExcept(PyThreadState *tstate) -{ - PyInterpreterState *interp = tstate->interp; - PyThreadState *p, *next, *garbage; - HEAD_LOCK(); - /* Remove all thread states, except tstate, from the linked list of - thread states. This will allow calling PyThreadState_Clear() - without holding the lock. */ - garbage = interp->tstate_head; - if (garbage == tstate) - garbage = tstate->next; - if (tstate->prev) - tstate->prev->next = tstate->next; - if (tstate->next) - tstate->next->prev = tstate->prev; - tstate->prev = tstate->next = NULL; - interp->tstate_head = tstate; - HEAD_UNLOCK(); - /* Clear and deallocate all stale thread states. Even if this - executes Python code, we should be safe since it executes - in the current thread, not one of the stale threads. */ - for (p = garbage; p; p = next) { - next = p->next; - PyThreadState_Clear(p); - PyMem_RawFree(p); - } -} - - PyThreadState * PyThreadState_Get(void) { @@ -720,15 +697,6 @@ return (PyThreadState *)PyThread_get_key_value(autoTLSkey); } -int -PyGILState_Check(void) -{ - /* can't use PyThreadState_Get() since it will assert that it has the GIL */ - PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed( - &_PyThreadState_Current); - return tstate && (tstate == PyGILState_GetThisThreadState()); -} - PyGILState_STATE PyGILState_Ensure(void) { diff -r 35c88c53cf64 -r ecc10f0afb76 Python/pystrtod.c --- a/Python/pystrtod.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/pystrtod.c Fri Feb 01 23:12:09 2013 +0100 @@ -923,7 +923,7 @@ static char * format_float_short(double d, char format_code, - int mode, int precision, + int mode, Py_ssize_t precision, int always_add_sign, int add_dot_0_if_integer, int use_alt_formatting, char **float_strings, int *type) { @@ -1059,7 +1059,7 @@ /* if using an exponent, reset decimal point position to 1 and adjust exponent accordingly.*/ if (use_exp) { - exp = (int)decpt - 1; + exp = decpt - 1; decpt = 1; } /* ensure vdigits_start < decpt <= vdigits_end, or vdigits_start < diff -r 35c88c53cf64 -r ecc10f0afb76 Python/pythonrun.c --- a/Python/pythonrun.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/pythonrun.c Fri Feb 01 23:12:09 2013 +0100 @@ -29,36 +29,23 @@ #include #endif +#ifdef HAVE_FCNTL_H +#include +#endif /* HAVE_FCNTL_H */ + #ifdef MS_WINDOWS #undef BYTE #include "windows.h" #define PATH_MAX MAXPATHLEN #endif -#ifdef Py_REF_DEBUG -static -void _print_total_refs(void) { - PyObject *xoptions, *key, *value; - xoptions = PySys_GetXOptions(); - if (xoptions == NULL) - return; - key = PyUnicode_FromString("showrefcount"); - if (key == NULL) - return; - value = PyDict_GetItem(xoptions, key); - Py_DECREF(key); - if (value == Py_True) - fprintf(stderr, - "[%" PY_FORMAT_SIZE_T "d refs, " - "%" PY_FORMAT_SIZE_T "d blocks]\n", - _Py_GetRefTotal(), _Py_GetAllocatedBlocks()); -} -#endif - #ifndef Py_REF_DEBUG #define PRINT_TOTAL_REFS() #else /* Py_REF_DEBUG */ -#define PRINT_TOTAL_REFS() _print_total_refs() +#define PRINT_TOTAL_REFS() fprintf(stderr, \ + "[%" PY_FORMAT_SIZE_T "d refs, " \ + "%" PY_FORMAT_SIZE_T "d blocks]\n", \ + _Py_GetRefTotal(), _Py_GetAllocatedBlocks()) #endif #ifdef __cplusplus @@ -86,7 +73,6 @@ static void wait_for_thread_shutdown(void); static void call_ll_exitfuncs(void); extern int _PyUnicode_Init(void); -extern int _PyStructSequence_Init(void); extern void _PyUnicode_Fini(void); extern int _PyLong_Init(void); extern void PyLong_Fini(void); @@ -175,7 +161,7 @@ name_utf8 = _PyUnicode_AsString(name); if (name_utf8 == NULL) goto error; - name_str = _PyMem_RawStrdup(name_utf8); + name_str = strdup(name_utf8); Py_DECREF(name); if (name_str == NULL) { PyErr_NoMemory(); @@ -293,6 +279,8 @@ check its value further. */ if ((p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0') Py_HashRandomizationFlag = add_flag(Py_HashRandomizationFlag, p); + if ((p = Py_GETENV("PYTHONCLOEXEC")) && *p != '\0') + Py_DefaultCloexec = 1; _PyRandom_Init(); @@ -328,8 +316,7 @@ if (!PyByteArray_Init()) Py_FatalError("Py_Initialize: can't init bytearray"); - if (!_PyFloat_Init()) - Py_FatalError("Py_Initialize: can't init float"); + _PyFloat_Init(); interp->modules = PyDict_New(); if (interp->modules == NULL) @@ -338,8 +325,6 @@ /* Init Unicode implementation; relies on the codec registry */ if (_PyUnicode_Init() < 0) Py_FatalError("Py_Initialize: can't initialize unicode"); - if (_PyStructSequence_Init() < 0) - Py_FatalError("Py_Initialize: can't initialize structseq"); bimod = _PyBuiltin_Init(); if (bimod == NULL) @@ -528,6 +513,9 @@ /* Disable signal handling */ PyOS_FiniInterrupts(); + /* Clear type lookup cache */ + PyType_ClearCache(); + /* Collect garbage. This may call finalizers; it's nice to call these * before all modules are destroyed. * XXX If a __del__ or weakref callback is triggered here, and tries to @@ -548,6 +536,10 @@ while (PyGC_Collect() > 0) /* nothing */; #endif + /* We run this while most interpreter state is still alive, so that + debug information can be printed out */ + _PyGC_Fini(); + /* Destroy all modules */ PyImport_Cleanup(); @@ -576,9 +568,6 @@ /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ _PyImport_Fini(); - /* Cleanup typeobject.c's internal caches. */ - _PyType_Fini(); - /* unload faulthandler module */ _PyFaulthandler_Fini(); @@ -599,7 +588,7 @@ _Py_PrintReferences(stderr); #endif /* Py_TRACE_REFS */ - /* Clear interpreter state and all thread states. */ + /* Clear interpreter state */ PyInterpreterState_Clear(interp); /* Now we decref the exception classes. After this point nothing @@ -610,6 +599,15 @@ _PyExc_Fini(); + /* Cleanup auto-thread-state */ +#ifdef WITH_THREAD + _PyGILState_Fini(); +#endif /* WITH_THREAD */ + + /* Delete current thread */ + PyThreadState_Swap(NULL); + PyInterpreterState_Delete(interp); + /* Sundry finalizers */ PyMethod_Fini(); PyFrame_Fini(); @@ -623,14 +621,13 @@ PyFloat_Fini(); PyDict_Fini(); PySlice_Fini(); - _PyGC_Fini(); /* Cleanup Unicode implementation */ _PyUnicode_Fini(); /* reset file system default encoding */ if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) { - PyMem_RawFree((char*)Py_FileSystemDefaultEncoding); + free((char*)Py_FileSystemDefaultEncoding); Py_FileSystemDefaultEncoding = NULL; } @@ -642,15 +639,6 @@ PyGrammar_RemoveAccelerators(&_PyParser_Grammar); - /* Cleanup auto-thread-state */ -#ifdef WITH_THREAD - _PyGILState_Fini(); -#endif /* WITH_THREAD */ - - /* Delete current thread. After this, many C API calls become crashy. */ - PyThreadState_Swap(NULL); - PyInterpreterState_Delete(interp); - #ifdef Py_TRACE_REFS /* Display addresses (& refcnts) of all objects still alive. * An address can be used to find the repr of the object, printed @@ -846,7 +834,7 @@ static void initmain(PyInterpreterState *interp) { - PyObject *m, *d, *loader; + PyObject *m, *d; m = PyImport_AddModule("__main__"); if (m == NULL) Py_FatalError("can't create __main__ module"); @@ -867,8 +855,7 @@ * be set if __main__ gets further initialized later in the startup * process. */ - loader = PyDict_GetItemString(d, "__loader__"); - if (loader == NULL || loader == Py_None) { + if (PyDict_GetItemString(d, "__loader__") == NULL) { PyObject *loader = PyObject_GetAttrString(interp->importlib, "BuiltinImporter"); if (loader == NULL) { @@ -918,7 +905,6 @@ PyObject *m; m = PyImport_ImportModule("site"); if (m == NULL) { - fprintf(stderr, "Failed to import the site module\n"); PyErr_Print(); Py_Finalize(); exit(1); @@ -1086,11 +1072,7 @@ encoding = Py_GETENV("PYTHONIOENCODING"); errors = NULL; if (encoding) { - encoding = _PyMem_Strdup(encoding); - if (encoding == NULL) { - PyErr_NoMemory(); - goto error; - } + encoding = strdup(encoding); errors = strchr(encoding, ':'); if (errors) { *errors = '\0'; @@ -1149,24 +1131,18 @@ when import.c tries to write to stderr in verbose mode. */ encoding_attr = PyObject_GetAttrString(std, "encoding"); if (encoding_attr != NULL) { - const char * std_encoding; - std_encoding = _PyUnicode_AsString(encoding_attr); - if (std_encoding != NULL) { - PyObject *codec_info = _PyCodec_Lookup(std_encoding); + const char * encoding; + encoding = _PyUnicode_AsString(encoding_attr); + if (encoding != NULL) { + PyObject *codec_info = _PyCodec_Lookup(encoding); Py_XDECREF(codec_info); } Py_DECREF(encoding_attr); } PyErr_Clear(); /* Not a fatal error if codec isn't available */ - if (PySys_SetObject("__stderr__", std) < 0) { - Py_DECREF(std); - goto error; - } - if (PySys_SetObject("stderr", std) < 0) { - Py_DECREF(std); - goto error; - } + PySys_SetObject("__stderr__", std); + PySys_SetObject("stderr", std); Py_DECREF(std); #endif @@ -1175,7 +1151,8 @@ status = -1; } - PyMem_Free(encoding); + if (encoding) + free(encoding); Py_XDECREF(bimod); Py_XDECREF(iomod); return status; @@ -1267,15 +1244,16 @@ _Py_IDENTIFIER(encoding); if (fp == stdin) { - /* Fetch encoding from sys.stdin if possible. */ + /* Fetch encoding from sys.stdin */ v = PySys_GetObject("stdin"); - if (v && v != Py_None) { - oenc = _PyObject_GetAttrId(v, &PyId_encoding); - if (oenc) - enc = _PyUnicode_AsString(oenc); - if (!enc) - PyErr_Clear(); - } + if (v == NULL || v == Py_None) + return -1; + oenc = _PyObject_GetAttrId(v, &PyId_encoding); + if (!oenc) + return -1; + enc = _PyUnicode_AsString(oenc); + if (enc == NULL) + return -1; } v = PySys_GetObject("ps1"); if (v != NULL) { @@ -1446,11 +1424,17 @@ len = strlen(filename); ext = filename + len - (len > 4 ? 4 : 0); if (maybe_pyc_file(fp, filename, ext, closeit)) { + int fd; FILE *pyc_fp; /* Try to run a pyc file. First, re-open in binary */ if (closeit) fclose(fp); - if ((pyc_fp = fopen(filename, "rb")) == NULL) { + fd = _Py_open(filename, O_RDONLY); + if (fd != -1) + pyc_fp = fdopen(fd, "rb"); + else + pyc_fp = NULL; + if (pyc_fp == NULL) { fprintf(stderr, "python: Can't reopen .pyc file\n"); goto done; } @@ -2489,9 +2473,6 @@ PyOS_setsig(SIGXFSZ, SIG_IGN); #endif PyOS_InitInterrupts(); /* May imply initsignal() */ - if (PyErr_Occurred()) { - Py_FatalError("Py_Initialize: can't import signal"); - } } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/random.c --- a/Python/random.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/random.c Fri Feb 01 23:12:09 2013 +0100 @@ -12,6 +12,13 @@ #endif #ifdef MS_WINDOWS +typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,\ + LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType,\ + DWORD dwFlags ); +typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen,\ + BYTE *pbBuffer ); + +static CRYPTGENRANDOM pCryptGenRandom = NULL; /* This handle is never explicitly released. Instead, the operating system will release it when the process terminates. */ static HCRYPTPROV hCryptProv = 0; @@ -19,9 +26,29 @@ static int win32_urandom_init(int raise) { + HINSTANCE hAdvAPI32 = NULL; + CRYPTACQUIRECONTEXTA pCryptAcquireContext = NULL; + + /* Obtain handle to the DLL containing CryptoAPI. This should not fail. */ + hAdvAPI32 = GetModuleHandle("advapi32.dll"); + if(hAdvAPI32 == NULL) + goto error; + + /* Obtain pointers to the CryptoAPI functions. This will fail on some early + versions of Win95. */ + pCryptAcquireContext = (CRYPTACQUIRECONTEXTA)GetProcAddress( + hAdvAPI32, "CryptAcquireContextA"); + if (pCryptAcquireContext == NULL) + goto error; + + pCryptGenRandom = (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, + "CryptGenRandom"); + if (pCryptGenRandom == NULL) + goto error; + /* Acquire context */ - if (!CryptAcquireContext(&hCryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) + if (! pCryptAcquireContext(&hCryptProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) goto error; return 0; @@ -50,7 +77,7 @@ while (size > 0) { chunk = size > INT_MAX ? INT_MAX : size; - if (!CryptGenRandom(hCryptProv, chunk, buffer)) + if (!pCryptGenRandom(hCryptProv, chunk, buffer)) { /* CryptGenRandom() failed */ if (raise) @@ -101,7 +128,7 @@ assert (0 < size); - fd = open("/dev/urandom", O_RDONLY); + fd = _Py_open("/dev/urandom", O_RDONLY); if (fd < 0) Py_FatalError("Failed to open /dev/urandom"); @@ -134,10 +161,9 @@ return 0; Py_BEGIN_ALLOW_THREADS - fd = open("/dev/urandom", O_RDONLY); + fd = _Py_open("/dev/urandom", O_RDONLY); Py_END_ALLOW_THREADS - if (fd < 0) - { + if (fd < 0) { PyErr_SetString(PyExc_NotImplementedError, "/dev/urandom (or equivalent) not found"); return -1; diff -r 35c88c53cf64 -r ecc10f0afb76 Python/symtable.c --- a/Python/symtable.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/symtable.c Fri Feb 01 23:12:09 2013 +0100 @@ -37,13 +37,25 @@ ste->ste_table = st; ste->ste_id = k; /* ste owns reference to k */ + ste->ste_name = name; Py_INCREF(name); - ste->ste_name = name; ste->ste_symbols = NULL; ste->ste_varnames = NULL; ste->ste_children = NULL; + ste->ste_symbols = PyDict_New(); + if (ste->ste_symbols == NULL) + goto fail; + + ste->ste_varnames = PyList_New(0); + if (ste->ste_varnames == NULL) + goto fail; + + ste->ste_children = PyList_New(0); + if (ste->ste_children == NULL) + goto fail; + ste->ste_directives = NULL; ste->ste_type = block; @@ -65,15 +77,6 @@ ste->ste_child_free = 0; ste->ste_generator = 0; ste->ste_returns_value = 0; - ste->ste_needs_class_closure = 0; - - ste->ste_symbols = PyDict_New(); - ste->ste_varnames = PyList_New(0); - ste->ste_children = PyList_New(0); - if (ste->ste_symbols == NULL - || ste->ste_varnames == NULL - || ste->ste_children == NULL) - goto fail; if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0) goto fail; @@ -188,7 +191,7 @@ static identifier top = NULL, lambda = NULL, genexpr = NULL, listcomp = NULL, setcomp = NULL, dictcomp = NULL, - __class__ = NULL; + __class__ = NULL, __locals__ = NULL; #define GET_IDENTIFIER(VAR) \ ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR))) @@ -511,10 +514,13 @@ Note that the current block's free variables are included in free. That's safe because no name can be free and local in the same scope. + + The 'restricted' argument may be set to a string to restrict the analysis + to the one variable whose name equals that string (e.g. "__class__"). */ static int -analyze_cells(PyObject *scopes, PyObject *free) +analyze_cells(PyObject *scopes, PyObject *free, const char *restricted) { PyObject *name, *v, *v_cell; int success = 0; @@ -531,6 +537,9 @@ continue; if (!PySet_Contains(free, name)) continue; + if (restricted != NULL && + PyUnicode_CompareWithASCIIString(name, restricted)) + continue; /* Replace LOCAL with CELL for this name, and remove from free. It is safe to replace the value of name in the dict, because it will not cause a resize. @@ -546,20 +555,6 @@ return success; } -static int -drop_class_free(PySTEntryObject *ste, PyObject *free) -{ - int res; - if (!GET_IDENTIFIER(__class__)) - return 0; - res = PySet_Discard(free, __class__); - if (res < 0) - return 0; - if (res) - ste->ste_needs_class_closure = 1; - return 1; -} - /* Check for illegal statements in unoptimized namespaces */ static int check_unoptimized(const PySTEntryObject* ste) { @@ -790,6 +785,7 @@ /* Special-case __class__ */ if (!GET_IDENTIFIER(__class__)) goto error; + assert(PySet_Contains(local, __class__) == 1); if (PySet_Add(newbound, __class__) < 0) goto error; } @@ -822,9 +818,11 @@ Py_DECREF(temp); /* Check if any local variables must be converted to cell variables */ - if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree)) + if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree, + NULL)) goto error; - else if (ste->ste_type == ClassBlock && !drop_class_free(ste, newfree)) + else if (ste->ste_type == ClassBlock && !analyze_cells(scopes, newfree, + "__class__")) goto error; /* Records the results of the analysis in the symbol table entry */ if (!update_symbols(ste->ste_symbols, scopes, bound, newfree, @@ -1181,6 +1179,13 @@ if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock, (void *)s, s->lineno, s->col_offset)) VISIT_QUIT(st, 0); + if (!GET_IDENTIFIER(__class__) || + !symtable_add_def(st, __class__, DEF_LOCAL) || + !GET_IDENTIFIER(__locals__) || + !symtable_add_def(st, __locals__, DEF_PARAM)) { + symtable_exit_block(st, s); + VISIT_QUIT(st, 0); + } tmp = st->st_private; st->st_private = s->v.ClassDef.name; VISIT_SEQ(st, stmt, s->v.ClassDef.body); @@ -1525,10 +1530,10 @@ if (a->args && !symtable_visit_argannotations(st, a->args)) return 0; - if (a->vararg && a->vararg->annotation) - VISIT(st, expr, a->vararg->annotation); - if (a->kwarg && a->kwarg->annotation) - VISIT(st, expr, a->kwarg->annotation); + if (a->varargannotation) + VISIT(st, expr, a->varargannotation); + if (a->kwargannotation) + VISIT(st, expr, a->kwargannotation); if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs)) return 0; if (s->v.FunctionDef.returns) @@ -1547,12 +1552,12 @@ if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs)) return 0; if (a->vararg) { - if (!symtable_add_def(st, a->vararg->arg, DEF_PARAM)) + if (!symtable_add_def(st, a->vararg, DEF_PARAM)) return 0; st->st_cur->ste_varargs = 1; } if (a->kwarg) { - if (!symtable_add_def(st, a->kwarg->arg, DEF_PARAM)) + if (!symtable_add_def(st, a->kwarg, DEF_PARAM)) return 0; st->st_cur->ste_varkeywords = 1; } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/sysmodule.c --- a/Python/sysmodule.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/sysmodule.c Fri Feb 01 23:12:09 2013 +0100 @@ -774,7 +774,7 @@ interpreter loads extension modules. Among other things, this will enable\n\ a lazy resolving of symbols when importing a module, if called as\n\ sys.setdlopenflags(0). To share symbols across extension modules, call as\n\ -sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag modules\n\ +sys.setdlopenflags(ctypes.RTLD_GLOBAL). Symbolic names for the flag modules\n\ can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY)."); static PyObject * @@ -790,7 +790,7 @@ "getdlopenflags() -> int\n\ \n\ Return the current value of the flags that are used for dlopen calls.\n\ -The flag constants are defined in the os module."); +The flag constants are defined in the ctypes and DLFCN modules."); #endif /* HAVE_DLOPEN */ @@ -1057,6 +1057,35 @@ Clear the internal type lookup cache."); +static PyObject * +sys_getdefaultcloexec(PyObject* self) +{ + return PyBool_FromLong(Py_DefaultCloexec); +} + +PyDoc_STRVAR(getdefaultcloexec_doc, +"getdefaultcloexec() -> bool\n\ +\n\ +Return the current default value of 'cloexec' (close-on-exec) parameter."); + +static PyObject * +sys_setdefaultcloexec(PyObject* self, PyObject *args) +{ + int cloexec = 1; + + if (!PyArg_ParseTuple(args, "i:setdefaultcloexec", &cloexec)) + return NULL; + + Py_DefaultCloexec = cloexec; + Py_RETURN_NONE; +} + +PyDoc_STRVAR(setdefaultcloexec_doc, +"setdefaultcloexec(cloexec=True)\n\ +\n\ +Set the default value of the 'cloexec' (close-on-exec) parameter."); + + static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, @@ -1131,6 +1160,10 @@ {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, {"_debugmallocstats", sys_debugmallocstats, METH_VARARGS, debugmallocstats_doc}, + {"getdefaultcloexec", (PyCFunction)sys_getdefaultcloexec, + METH_NOARGS, getdefaultcloexec_doc}, + {"setdefaultcloexec", (PyCFunction)sys_setdefaultcloexec, + METH_VARARGS, setdefaultcloexec_doc}, {NULL, NULL} /* sentinel */ }; @@ -1565,24 +1598,17 @@ PyObject * _PySys_Init(void) { - PyObject *m, *sysdict, *version_info; + PyObject *m, *v, *sysdict, *version_info; m = PyModule_Create(&sysmodule); if (m == NULL) return NULL; sysdict = PyModule_GetDict(m); -#define SET_SYS_FROM_STRING(key, value) \ - do { \ - int res; \ - PyObject *v = (value); \ - if (v == NULL) \ - return NULL; \ - res = PyDict_SetItemString(sysdict, key, v); \ - if (res < 0) { \ - Py_DECREF(v); \ - return NULL; \ - } \ - } while (0) +#define SET_SYS_FROM_STRING(key, value) \ + v = value; \ + if (v != NULL) \ + PyDict_SetItemString(sysdict, key, v); \ + Py_XDECREF(v) /* Check that stdin is not a directory Using shell redirection, you can redirect stdin to a directory, @@ -1604,10 +1630,10 @@ /* stdin/stdout/stderr are now set by pythonrun.c */ - SET_SYS_FROM_STRING("__displayhook__", - PyDict_GetItemString(sysdict, "displayhook")); - SET_SYS_FROM_STRING("__excepthook__", - PyDict_GetItemString(sysdict, "excepthook")); + PyDict_SetItemString(sysdict, "__displayhook__", + PyDict_GetItemString(sysdict, "displayhook")); + PyDict_SetItemString(sysdict, "__excepthook__", + PyDict_GetItemString(sysdict, "excepthook")); SET_SYS_FROM_STRING("version", PyUnicode_FromString(Py_GetVersion())); SET_SYS_FROM_STRING("hexversion", @@ -1641,10 +1667,8 @@ SET_SYS_FROM_STRING("int_info", PyLong_GetInfo()); /* initialize hash_info */ - if (Hash_InfoType.tp_name == NULL) { - if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0) - return NULL; - } + if (Hash_InfoType.tp_name == 0) + PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc); SET_SYS_FROM_STRING("hash_info", get_hash_info()); SET_SYS_FROM_STRING("maxunicode", @@ -1671,22 +1695,22 @@ #endif if (warnoptions == NULL) { warnoptions = PyList_New(0); - if (warnoptions == NULL) - return NULL; } else { Py_INCREF(warnoptions); } - SET_SYS_FROM_STRING("warnoptions", warnoptions); + if (warnoptions != NULL) { + PyDict_SetItemString(sysdict, "warnoptions", warnoptions); + } - SET_SYS_FROM_STRING("_xoptions", get_xoptions()); + v = get_xoptions(); + if (v != NULL) { + PyDict_SetItemString(sysdict, "_xoptions", v); + } /* version_info */ - if (VersionInfoType.tp_name == NULL) { - if (PyStructSequence_InitType2(&VersionInfoType, - &version_info_desc) < 0) - return NULL; - } + if (VersionInfoType.tp_name == 0) + PyStructSequence_InitType(&VersionInfoType, &version_info_desc); version_info = make_version_info(); SET_SYS_FROM_STRING("version_info", version_info); /* prevent user from creating new instances */ @@ -1697,10 +1721,8 @@ SET_SYS_FROM_STRING("implementation", make_impl_info(version_info)); /* flags */ - if (FlagsType.tp_name == 0) { - if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0) - return NULL; - } + if (FlagsType.tp_name == 0) + PyStructSequence_InitType(&FlagsType, &flags_desc); SET_SYS_FROM_STRING("flags", make_flags()); /* prevent user from creating new instances */ FlagsType.tp_init = NULL; @@ -1710,9 +1732,7 @@ #if defined(MS_WINDOWS) /* getwindowsversion */ if (WindowsVersionType.tp_name == 0) - if (PyStructSequence_InitType2(&WindowsVersionType, - &windows_version_desc) < 0) - return NULL; + PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc); /* prevent user from creating new instances */ WindowsVersionType.tp_init = NULL; WindowsVersionType.tp_new = NULL; @@ -1867,11 +1887,10 @@ if (q == NULL) argv0 = link; /* argv0 without path */ else { - /* Must make a copy, argv0copy has room for 2 * MAXPATHLEN */ - wcsncpy(argv0copy, argv0, MAXPATHLEN); + /* Must make a copy */ + wcscpy(argv0copy, argv0); q = wcsrchr(argv0copy, SEP); - wcsncpy(q+1, link, MAXPATHLEN); - q[MAXPATHLEN + 1] = L'\0'; + wcscpy(q+1, link); argv0 = argv0copy; } } diff -r 35c88c53cf64 -r ecc10f0afb76 Python/thread.c --- a/Python/thread.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/thread.c Fri Feb 01 23:12:09 2013 +0100 @@ -231,7 +231,7 @@ assert(p == NULL); goto Done; } - p = (struct key *)PyMem_RawMalloc(sizeof(struct key)); + p = (struct key *)malloc(sizeof(struct key)); if (p != NULL) { p->id = id; p->key = key; @@ -270,7 +270,7 @@ while ((p = *q) != NULL) { if (p->key == key) { *q = p->next; - PyMem_RawFree((void *)p); + free((void *)p); /* NB This does *not* free p->value! */ } else @@ -324,7 +324,7 @@ while ((p = *q) != NULL) { if (p->key == key && p->id == id) { *q = p->next; - PyMem_RawFree((void *)p); + free((void *)p); /* NB This does *not* free p->value! */ break; } @@ -357,7 +357,7 @@ while ((p = *q) != NULL) { if (p->id != id) { *q = p->next; - PyMem_RawFree((void *)p); + free((void *)p); /* NB This does *not* free p->value! */ } else @@ -399,10 +399,8 @@ int len; #endif - if (ThreadInfoType.tp_name == 0) { - if (PyStructSequence_InitType2(&ThreadInfoType, &threadinfo_desc) < 0) - return NULL; - } + if (ThreadInfoType.tp_name == 0) + PyStructSequence_InitType(&ThreadInfoType, &threadinfo_desc); threadinfo = PyStructSequence_New(&ThreadInfoType); if (threadinfo == NULL) diff -r 35c88c53cf64 -r ecc10f0afb76 Python/thread_nt.h --- a/Python/thread_nt.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/thread_nt.h Fri Feb 01 23:12:09 2013 +0100 @@ -34,7 +34,7 @@ PNRMUTEX AllocNonRecursiveMutex() { - PNRMUTEX m = (PNRMUTEX)PyMem_RawMalloc(sizeof(NRMUTEX)); + PNRMUTEX m = (PNRMUTEX)malloc(sizeof(NRMUTEX)); if (!m) return NULL; if (PyCOND_INIT(&m->cv)) @@ -46,7 +46,7 @@ m->locked = 0; return m; fail: - PyMem_RawFree(m); + free(m); return NULL; } @@ -56,7 +56,7 @@ if (mutex) { PyCOND_FINI(&mutex->cv); PyMUTEX_FINI(&mutex->cs); - PyMem_RawFree(mutex); + free(mutex); } } @@ -107,7 +107,7 @@ result = PyCOND_SIGNAL(&mutex->cv); result &= PyMUTEX_UNLOCK(&mutex->cs); return result; -} +} #else /* if ! _PY_USE_CV_LOCKS */ @@ -130,7 +130,7 @@ DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds) { - return WaitForSingleObjectEx(mutex, milliseconds, FALSE); + return WaitForSingleObject(mutex, milliseconds); } BOOL diff -r 35c88c53cf64 -r ecc10f0afb76 Python/thread_pthread.h --- a/Python/thread_pthread.h Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/thread_pthread.h Fri Feb 01 23:12:09 2013 +0100 @@ -170,7 +170,6 @@ PyThread__init_thread(void) { #if defined(_AIX) && defined(__GNUC__) - extern void pthread_init(void); pthread_init(); #endif } @@ -282,14 +281,14 @@ if (!initialized) PyThread_init_thread(); - lock = (sem_t *)PyMem_RawMalloc(sizeof(sem_t)); + lock = (sem_t *)malloc(sizeof(sem_t)); if (lock) { status = sem_init(lock,0,1); CHECK_STATUS("sem_init"); if (error) { - PyMem_RawFree((void *)lock); + free((void *)lock); lock = NULL; } } @@ -313,7 +312,7 @@ status = sem_destroy(thelock); CHECK_STATUS("sem_destroy"); - PyMem_RawFree((void *)thelock); + free((void *)thelock); } /* @@ -410,7 +409,7 @@ if (!initialized) PyThread_init_thread(); - lock = (pthread_lock *) PyMem_RawMalloc(sizeof(pthread_lock)); + lock = (pthread_lock *) malloc(sizeof(pthread_lock)); if (lock) { memset((void *)lock, '\0', sizeof(pthread_lock)); lock->locked = 0; @@ -430,7 +429,7 @@ CHECK_STATUS("pthread_cond_init"); if (error) { - PyMem_RawFree((void *)lock); + free((void *)lock); lock = 0; } } @@ -445,7 +444,6 @@ pthread_lock *thelock = (pthread_lock *)lock; int status, error = 0; - (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_free_lock(%p) called\n", lock)); /* some pthread-like implementations tie the mutex to the cond @@ -457,7 +455,7 @@ status = pthread_mutex_destroy( &thelock->mut ); CHECK_STATUS("pthread_mutex_destroy"); - PyMem_RawFree((void *)thelock); + free((void *)thelock); } PyLockStatus @@ -532,7 +530,6 @@ pthread_lock *thelock = (pthread_lock *)lock; int status, error = 0; - (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_release_lock(%p) called\n", lock)); status = pthread_mutex_lock( &thelock->mut ); diff -r 35c88c53cf64 -r ecc10f0afb76 Python/traceback.c --- a/Python/traceback.c Fri Jul 26 23:14:22 2013 -0700 +++ b/Python/traceback.c Fri Feb 01 23:12:09 2013 +0100 @@ -13,7 +13,7 @@ #define OFF(x) offsetof(PyTracebackObject, x) -#define PUTS(fd, str) write(fd, str, (int)strlen(str)) +#define PUTS(fd, str) write(fd, str, strlen(str)) #define MAX_STRING_LENGTH 500 #define MAX_FRAME_DEPTH 100 #define MAX_NTHREADS 100 @@ -246,31 +246,18 @@ binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb"); if (binary == NULL) { - PyErr_Clear(); - binary = _Py_FindSourceFile(filename, buf, sizeof(buf), io); if (binary == NULL) { Py_DECREF(io); - return -1; + return 0; } } /* use the right encoding to decode the file as unicode */ fd = PyObject_AsFileDescriptor(binary); - if (fd < 0) { - Py_DECREF(io); - Py_DECREF(binary); - return 0; - } found_encoding = PyTokenizer_FindEncodingFilename(fd, filename); encoding = (found_encoding != NULL) ? found_encoding : "utf-8"; - /* Reset position */ - if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { - Py_DECREF(io); - Py_DECREF(binary); - PyMem_FREE(found_encoding); - return 0; - } + lseek(fd, 0, 0); /* Reset position */ fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding); Py_DECREF(io); Py_DECREF(binary); @@ -324,7 +311,7 @@ strcpy(buf, " "); assert (strlen(buf) == 10); while (indent > 0) { - if (indent < 10) + if(indent < 10) buf[indent] = '\0'; err = PyFile_WriteString(buf, f); if (err != 0) diff -r 35c88c53cf64 -r ecc10f0afb76 README --- a/README Fri Jul 26 23:14:22 2013 -0700 +++ b/README Fri Feb 01 23:12:09 2013 +0100 @@ -167,8 +167,8 @@ Copyright and License Information --------------------------------- -Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Python Software Foundation. All rights reserved. +Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. All rights reserved. diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/buildbot/external-amd64.bat --- a/Tools/buildbot/external-amd64.bat Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/buildbot/external-amd64.bat Fri Feb 01 23:12:09 2013 +0100 @@ -6,16 +6,16 @@ if not exist tcltk64\bin\tcl85g.dll ( cd tcl-8.5.11.0\win - nmake -f makefile.vc DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all - nmake -f makefile.vc DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 install + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 install cd ..\.. ) if not exist tcltk64\bin\tk85g.dll ( cd tk-8.5.11.0\win - nmake -f makefile.vc OPTS=noxp DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.5.11.0 clean - nmake -f makefile.vc OPTS=noxp DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.5.11.0 all - nmake -f makefile.vc OPTS=noxp DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.5.11.0 install + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 OPTS=noxp DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.5.11.0 clean + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 OPTS=noxp DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.5.11.0 all + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 OPTS=noxp DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.5.11.0 install cd ..\.. ) diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/buildbot/external-common.bat --- a/Tools/buildbot/external-common.bat Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/buildbot/external-common.bat Fri Feb 01 23:12:09 2013 +0100 @@ -14,7 +14,7 @@ @rem if exist tk8.4.16 rd /s/q tk8.4.16 @rem if exist tk-8.4.18.1 rd /s/q tk-8.4.18.1 @rem if exist db-4.4.20 rd /s/q db-4.4.20 -@rem if exist openssl-1.0.1e rd /s/q openssl-1.0.1e +@rem if exist openssl-1.0.1c rd /s/q openssl-1.0.1c @rem if exist sqlite-3.7.12 rd /s/q sqlite-3.7.12 @rem bzip @@ -24,9 +24,9 @@ ) @rem OpenSSL -if not exist openssl-1.0.1e ( - rd /s/q openssl-1.0.1d - svn export http://svn.python.org/projects/external/openssl-1.0.1e +if not exist openssl-1.0.1c ( + rd /s/q openssl-1.0.0j + svn export http://svn.python.org/projects/external/openssl-1.0.1c ) @rem tcl/tk diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/buildbot/external.bat --- a/Tools/buildbot/external.bat Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/buildbot/external.bat Fri Feb 01 23:12:09 2013 +0100 @@ -7,15 +7,15 @@ if not exist tcltk\bin\tcl85g.dll ( @rem all and install need to be separate invocations, otherwise nmakehlp is not found on install cd tcl-8.5.11.0\win - nmake -f makefile.vc DEBUG=1 INSTALLDIR=..\..\tcltk clean all + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 INSTALLDIR=..\..\tcltk clean all nmake -f makefile.vc DEBUG=1 INSTALLDIR=..\..\tcltk install cd ..\.. ) if not exist tcltk\bin\tk85g.dll ( cd tk-8.5.11.0\win - nmake -f makefile.vc OPTS=noxp DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.5.11.0 clean - nmake -f makefile.vc OPTS=noxp DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.5.11.0 all - nmake -f makefile.vc OPTS=noxp DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.5.11.0 install + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 OPTS=noxp DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.5.11.0 clean + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 OPTS=noxp DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.5.11.0 all + nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 OPTS=noxp DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.5.11.0 install cd ..\.. ) diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/demo/eiffel.py --- a/Tools/demo/eiffel.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/demo/eiffel.py Fri Feb 01 23:12:09 2013 +0100 @@ -36,7 +36,7 @@ pre = dict.get("%s_pre" % m) post = dict.get("%s_post" % m) if pre or post: - dict[m] = cls.make_eiffel_method(dict[m], pre, post) + dict[k] = cls.make_eiffel_method(dict[m], pre, post) class EiffelMetaClass1(EiffelBaseMetaClass): diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/demo/ss1.py --- a/Tools/demo/ss1.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/demo/ss1.py Fri Feb 01 23:12:09 2013 +0100 @@ -7,8 +7,8 @@ import os import re import sys +import html from xml.parsers import expat -from xml.sax.saxutils import escape LEFT, CENTER, RIGHT = "LEFT", "CENTER", "RIGHT" @@ -79,10 +79,10 @@ del self.cells[xy] def clearrows(self, y1, y2): - self.clearcells(0, y1, sys.maxsize, y2) + self.clearcells(0, y1, sys.maxint, y2) def clearcolumns(self, x1, x2): - self.clearcells(x1, 0, x2, sys.maxsize) + self.clearcells(x1, 0, x2, sys.maxint) def selectcells(self, x1, y1, x2, y2): if x1 > x2: @@ -113,23 +113,23 @@ def insertrows(self, y, n): assert n > 0 - self.movecells(0, y, sys.maxsize, sys.maxsize, 0, n) + self.movecells(0, y, sys.maxint, sys.maxint, 0, n) def deleterows(self, y1, y2): if y1 > y2: y1, y2 = y2, y1 self.clearrows(y1, y2) - self.movecells(0, y2+1, sys.maxsize, sys.maxsize, 0, y1-y2-1) + self.movecells(0, y2+1, sys.maxint, sys.maxint, 0, y1-y2-1) def insertcolumns(self, x, n): assert n > 0 - self.movecells(x, 0, sys.maxsize, sys.maxsize, n, 0) + self.movecells(x, 0, sys.maxint, sys.maxint, n, 0) def deletecolumns(self, x1, x2): if x1 > x2: x1, x2 = x2, x1 self.clearcells(x1, x2) - self.movecells(x2+1, 0, sys.maxsize, sys.maxsize, x1-x2-1, 0) + self.movecells(x2+1, 0, sys.maxint, sys.maxint, x1-x2-1, 0) def getsize(self): maxx = maxy = 0 @@ -205,7 +205,7 @@ if hasattr(cell, 'xml'): cellxml = cell.xml() else: - cellxml = '%s' % escape(cell) + cellxml = '%s' % html.escape(cell) out.append('\n %s\n' % (y, x, cellxml)) out.append('') @@ -213,14 +213,16 @@ def save(self, filename): text = self.xml() - with open(filename, "w", encoding='utf-8') as f: - f.write(text) - if text and not text.endswith('\n'): - f.write('\n') + f = open(filename, "w") + f.write(text) + if text and not text.endswith('\n'): + f.write('\n') + f.close() def load(self, filename): - with open(filename, 'rb') as f: - SheetParser(self).parsefile(f) + f = open(filename, 'rb') + SheetParser(self).parsefile(f) + f.close() class SheetParser: @@ -237,10 +239,13 @@ def startelement(self, tag, attrs): method = getattr(self, 'start_'+tag, None) if method: + for key, value in attrs.items(): + attrs[key] = str(value) # XXX Convert Unicode to 8-bit method(attrs) self.texts = [] def data(self, text): + text = str(text) # XXX Convert Unicode to 8-bit self.texts.append(text) def endelement(self, tag): @@ -264,7 +269,11 @@ except: self.value = None - end_long = end_int + def end_long(self, text): + try: + self.value = int(text) + except: + self.value = None def end_double(self, text): try: @@ -279,7 +288,10 @@ self.value = None def end_string(self, text): - self.value = text + try: + self.value = text + except: + self.value = None def end_value(self, text): if isinstance(self.value, BaseCell): @@ -316,7 +328,7 @@ class NumericCell(BaseCell): def __init__(self, value, fmt="%s", alignment=RIGHT): - assert isinstance(value, (int, float, complex)) + assert isinstance(value, (int, int, float, complex)) assert alignment in (LEFT, CENTER, RIGHT) self.value = value self.fmt = fmt @@ -343,18 +355,21 @@ if -2**31 <= self.value < 2**31: return '%s' % self.value else: - return '%s' % self.value + return self._xml_long() + + def _xml_long(self): + return '%s' % self.value def _xml_float(self): - return '%r' % self.value + return '%s' % repr(self.value) def _xml_complex(self): - return '%r' % self.value + return '%s' % repr(self.value) class StringCell(BaseCell): def __init__(self, text, fmt="%s", alignment=LEFT): - assert isinstance(text, str) + assert isinstance(text, (str, str)) assert alignment in (LEFT, CENTER, RIGHT) self.text = text self.fmt = fmt @@ -371,7 +386,7 @@ return s % ( align2xml[self.alignment], self.fmt, - escape(self.text)) + html.escape(self.text)) class FormulaCell(BaseCell): @@ -389,6 +404,7 @@ def recalc(self, ns): if self.value is None: try: + # A hack to evaluate expressions using true division self.value = eval(self.translated, ns) except: exc = sys.exc_info()[0] @@ -409,7 +425,7 @@ return '%s' % ( align2xml[self.alignment], self.fmt, - escape(self.formula)) + self.formula) def renumber(self, x1, y1, x2, y2, dx, dy): out = [] @@ -610,29 +626,29 @@ def selectall(self, event): self.setcurrent(1, 1) - self.setcorner(sys.maxsize, sys.maxsize) + self.setcorner(sys.maxint, sys.maxint) def selectcolumn(self, event): x, y = self.whichxy(event) self.setcurrent(x, 1) - self.setcorner(x, sys.maxsize) + self.setcorner(x, sys.maxint) def extendcolumn(self, event): x, y = self.whichxy(event) if x > 0: self.setcurrent(self.currentxy[0], 1) - self.setcorner(x, sys.maxsize) + self.setcorner(x, sys.maxint) def selectrow(self, event): x, y = self.whichxy(event) self.setcurrent(1, y) - self.setcorner(sys.maxsize, y) + self.setcorner(sys.maxint, y) def extendrow(self, event): x, y = self.whichxy(event) if y > 0: self.setcurrent(1, self.currentxy[1]) - self.setcorner(sys.maxsize, y) + self.setcorner(sys.maxint, y) def press(self, event): x, y = self.whichxy(event) @@ -693,14 +709,14 @@ self.setbeacon(x1, y1, x2, y2) def setbeacon(self, x1, y1, x2, y2): - if x1 == y1 == 1 and x2 == y2 == sys.maxsize: + if x1 == y1 == 1 and x2 == y2 == sys.maxint: name = ":" - elif (x1, x2) == (1, sys.maxsize): + elif (x1, x2) == (1, sys.maxint): if y1 == y2: name = "%d" % y1 else: name = "%d:%d" % (y1, y2) - elif (y1, y2) == (1, sys.maxsize): + elif (y1, y2) == (1, sys.maxint): if x1 == x2: name = "%s" % colnum2name(x1) else: @@ -760,7 +776,7 @@ if text.startswith('='): cell = FormulaCell(text[1:]) else: - for cls in int, float, complex: + for cls in int, int, float, complex: try: value = cls(text) except: diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/gdb/libpython.py Fri Feb 01 23:12:09 2013 +0100 @@ -1160,9 +1160,7 @@ # Convert the int code points to unicode characters, and generate a # local unicode instance. # This splits surrogate pairs if sizeof(Py_UNICODE) is 2 here (in gdb). - result = u''.join([ - (_unichr(ucs) if ucs <= 0x10ffff else '\ufffd') - for ucs in Py_UNICODEs]) + result = u''.join([_unichr(ucs) for ucs in Py_UNICODEs]) return result def write_repr(self, out, visited): @@ -1462,10 +1460,10 @@ # This assumes the _POSIX_THREADS version of Python/ceval_gil.h: name = self._gdbframe.name() if name: - return 'pthread_cond_timedwait' in name + return name.startswith('pthread_cond_timedwait') def is_gc_collect(self): - '''Is this frame "collect" within the garbage-collector?''' + '''Is this frame "collect" within the the garbage-collector?''' return self._gdbframe.name() == 'collect' def get_pyop(self): diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/i18n/pygettext.py --- a/Tools/i18n/pygettext.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/i18n/pygettext.py Fri Feb 01 23:12:09 2013 +0100 @@ -188,8 +188,8 @@ "Last-Translator: FULL NAME \\n" "Language-Team: LANGUAGE \\n" "MIME-Version: 1.0\\n" -"Content-Type: text/plain; charset=%(charset)s\\n" -"Content-Transfer-Encoding: %(encoding)s\\n" +"Content-Type: text/plain; charset=CHARSET\\n" +"Content-Transfer-Encoding: ENCODING\\n" "Generated-By: pygettext.py %(version)s\\n" ''') @@ -203,32 +203,35 @@ -def make_escapes(pass_nonascii): - global escapes, escape - if pass_nonascii: - # Allow non-ascii characters to pass through so that e.g. 'msgid +escapes = [] + +def make_escapes(pass_iso8859): + global escapes + if pass_iso8859: + # Allow iso-8859 characters to pass through so that e.g. 'msgid # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we # escape any character outside the 32..126 range. mod = 128 - escape = escape_ascii else: mod = 256 - escape = escape_nonascii - escapes = [r"\%03o" % i for i in range(mod)] - for i in range(32, 127): - escapes[i] = chr(i) - escapes[ord('\\')] = r'\\' - escapes[ord('\t')] = r'\t' - escapes[ord('\r')] = r'\r' - escapes[ord('\n')] = r'\n' - escapes[ord('\"')] = r'\"' + for i in range(256): + if 32 <= (i % mod) <= 126: + escapes.append(chr(i)) + else: + escapes.append("\\%03o" % i) + escapes[ord('\\')] = '\\\\' + escapes[ord('\t')] = '\\t' + escapes[ord('\r')] = '\\r' + escapes[ord('\n')] = '\\n' + escapes[ord('\"')] = '\\"' -def escape_ascii(s, encoding): - return ''.join(escapes[ord(c)] if ord(c) < 128 else c for c in s) - -def escape_nonascii(s, encoding): - return ''.join(escapes[b] for b in s.encode(encoding)) +def escape(s): + global escapes + s = list(s) + for i in range(len(s)): + s[i] = escapes[ord(s[i])] + return EMPTYSTRING.join(s) def safe_eval(s): @@ -236,18 +239,18 @@ return eval(s, {'__builtins__':{}}, {}) -def normalize(s, encoding): +def normalize(s): # This converts the various Python string types into a format that is # appropriate for .po files, namely much closer to C style. lines = s.split('\n') if len(lines) == 1: - s = '"' + escape(s, encoding) + '"' + s = '"' + escape(s) + '"' else: if not lines[-1]: del lines[-1] lines[-1] = lines[-1] + '\n' for i in range(len(lines)): - lines[i] = escape(lines[i], encoding) + lines[i] = escape(lines[i]) lineterm = '\\n"\n"' s = '""\n"' + lineterm.join(lines) + '"' return s @@ -444,10 +447,7 @@ timestamp = time.strftime('%Y-%m-%d %H:%M+%Z') # The time stamp in the header doesn't have the same format as that # generated by xgettext... - encoding = fp.encoding if fp.encoding else 'UTF-8' - print(pot_header % {'time': timestamp, 'version': __version__, - 'charset': encoding, - 'encoding': '8bit'}, file=fp) + print(pot_header % {'time': timestamp, 'version': __version__}, file=fp) # Sort the entries. First sort each particular entry's keys, then # sort all the entries by their first item. reverse = {} @@ -491,7 +491,7 @@ print(locline, file=fp) if isdocstring: print('#, docstring', file=fp) - print('msgid', normalize(k, encoding), file=fp) + print('msgid', normalize(k), file=fp) print('msgstr ""\n', file=fp) @@ -587,7 +587,7 @@ fp.close() # calculate escapes - make_escapes(not options.escape) + make_escapes(options.escape) # calculate all keywords options.keywords.extend(default_keywords) @@ -620,17 +620,17 @@ if filename == '-': if options.verbose: print(_('Reading standard input')) - fp = sys.stdin.buffer + fp = sys.stdin closep = 0 else: if options.verbose: print(_('Working on %s') % filename) - fp = open(filename, 'rb') + fp = open(filename) closep = 1 try: eater.set_filename(filename) try: - tokens = tokenize.tokenize(fp.readline) + tokens = tokenize.generate_tokens(fp.readline) for _token in tokens: eater(*_token) except tokenize.TokenError as e: diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/msi/msilib.py --- a/Tools/msi/msilib.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/msi/msilib.py Fri Feb 01 23:12:09 2013 +0100 @@ -491,7 +491,7 @@ def add_file(self, file, src=None, version=None, language=None): """Add a file to the current component of the directory, starting a new one - if there is no current component. By default, the file name in the source + one if there is no current component. By default, the file name in the source and the file table will be identical. If the src file is specified, it is interpreted relative to the current directory. Optionally, a version and a language can be specified for the entry in the File table.""" diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/msi/schema.py --- a/Tools/msi/schema.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/msi/schema.py Fri Feb 01 23:12:09 2013 +0100 @@ -958,7 +958,7 @@ (u'ServiceInstall',u'StartType',u'N',0,4,None, None, None, None, u'Type of the service',), (u'Shortcut',u'Name',u'N',None, None, None, None, u'Filename',None, u'The name of the shortcut to be created.',), (u'Shortcut',u'Description',u'Y',None, None, None, None, u'Text',None, u'The description for the shortcut.',), -(u'Shortcut',u'Component_',u'N',None, None, u'Component',1,u'Identifier',None, u'Foreign key into the Component table denoting the component whose selection gates the shortcut creation/deletion.',), +(u'Shortcut',u'Component_',u'N',None, None, u'Component',1,u'Identifier',None, u'Foreign key into the Component table denoting the component whose selection gates the the shortcut creation/deletion.',), (u'Shortcut',u'Icon_',u'Y',None, None, u'Icon',1,u'Identifier',None, u'Foreign key into the File table denoting the external icon file for the shortcut.',), (u'Shortcut',u'IconIndex',u'Y',-32767,32767,None, None, None, None, u'The icon index for the shortcut.',), (u'Shortcut',u'Directory_',u'N',None, None, u'Directory',1,u'Identifier',None, u'Foreign key into the Directory table denoting the directory where the shortcut file is created.',), diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/msi/uisample.py --- a/Tools/msi/uisample.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/msi/uisample.py Fri Feb 01 23:12:09 2013 +0100 @@ -1195,7 +1195,7 @@ (u'ServiceInstall', u'StartType', u'N', 0, 4, None, None, None, None, u'Type of the service'), (u'Shortcut', u'Name', u'N', None, None, None, None, u'Filename', None, u'The name of the shortcut to be created.'), (u'Shortcut', u'Description', u'Y', None, None, None, None, u'Text', None, u'The description for the shortcut.'), -(u'Shortcut', u'Component_', u'N', None, None, u'Component', 1, u'Identifier', None, u'Foreign key into the Component table denoting the component whose selection gates the shortcut creation/deletion.'), +(u'Shortcut', u'Component_', u'N', None, None, u'Component', 1, u'Identifier', None, u'Foreign key into the Component table denoting the component whose selection gates the the shortcut creation/deletion.'), (u'Shortcut', u'Icon_', u'Y', None, None, u'Icon', 1, u'Identifier', None, u'Foreign key into the File table denoting the external icon file for the shortcut.'), (u'Shortcut', u'IconIndex', u'Y', -32767, 32767, None, None, None, None, u'The icon index for the shortcut.'), (u'Shortcut', u'Directory_', u'N', None, None, u'Directory', 1, u'Identifier', None, u'Foreign key into the Directory table denoting the directory where the shortcut file is created.'), diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/parser/unparse.py --- a/Tools/parser/unparse.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/parser/unparse.py Fri Feb 01 23:12:09 2013 +0100 @@ -518,10 +518,10 @@ else: self.write(", ") self.write("*") if t.vararg: - self.write(t.vararg.arg) - if t.vararg.annotation: + self.write(t.vararg) + if t.varargannotation: self.write(": ") - self.dispatch(t.vararg.annotation) + self.dispatch(t.varargannotation) # keyword-only arguments if t.kwonlyargs: @@ -537,10 +537,10 @@ if t.kwarg: if first:first = False else: self.write(", ") - self.write("**"+t.kwarg.arg) - if t.kwarg.annotation: + self.write("**"+t.kwarg) + if t.kwargannotation: self.write(": ") - self.dispatch(t.kwarg.annotation) + self.dispatch(t.kwargannotation) def _keyword(self, t): self.write(t.arg) diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/pybench/README --- a/Tools/pybench/README Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/pybench/README Fri Feb 01 23:12:09 2013 +0100 @@ -3,7 +3,7 @@ PYBENCH - A Python Benchmark Suite ________________________________________________________________________ - Extendable suite of low-level benchmarks for measuring + Extendable suite of of low-level benchmarks for measuring the performance of the Python implementation (interpreter, compiler or VM). diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/scripts/abitype.py --- a/Tools/scripts/abitype.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/scripts/abitype.py Fri Feb 01 23:12:09 2013 +0100 @@ -126,8 +126,8 @@ 'tp_cache', 'tp_subclasses', 'tp_weaklist', - 'tp_del', - 'tp_version_tag', + 'tp_del' + 'tp_version_tag' ] # Generate a PyType_Spec definition @@ -194,7 +194,7 @@ break start = m.start() end = m.end() - name, fields = get_fields(start, end) + name, fields = get_fields(start, m) tokens[start:end] = [('',make_slots(name, fields))] # Output result to stdout diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/scripts/checkpyc.py --- a/Tools/scripts/checkpyc.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/scripts/checkpyc.py Fri Feb 01 23:12:09 2013 +0100 @@ -5,11 +5,11 @@ import sys import os from stat import ST_MTIME -import importlib.util +import imp # PEP 3147 compatibility (PYC Repository Directories) -cache_from_source = (importlib.util.cache_from_source if sys.implementation.cache_tag - else lambda path: path + 'c') +cache_from_source = (imp.cache_from_source if hasattr(imp, 'get_tag') else + lambda path: path + 'c') def main(): @@ -18,7 +18,7 @@ silent = (sys.argv[1] == '-s') else: verbose = silent = False - MAGIC = importlib.util.MAGIC_NUMBER + MAGIC = imp.get_magic() if not silent: print('Using MAGIC word', repr(MAGIC)) for dirname in sys.path: diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/scripts/gprof2html.py --- a/Tools/scripts/gprof2html.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/scripts/gprof2html.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,4 +1,4 @@ -#! /usr/bin/env python3 +#! /usr/bin/env python32.3 """Transform gprof(1) output into useful HTML.""" diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/scripts/h2py.py --- a/Tools/scripts/h2py.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/scripts/h2py.py Fri Feb 01 23:12:09 2013 +0100 @@ -50,11 +50,6 @@ searchdirs=os.environ['INCLUDE'].split(';') except KeyError: searchdirs=['/usr/include'] - try: - searchdirs.insert(0, os.path.join('/usr/include', - os.environ['MULTIARCH'])) - except KeyError: - pass def main(): global filedict diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/scripts/patchcheck.py --- a/Tools/scripts/patchcheck.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/scripts/patchcheck.py Fri Feb 01 23:12:09 2013 +0100 @@ -124,13 +124,13 @@ @status("Misc/ACKS updated", modal=True) def credit_given(file_paths): """Check if Misc/ACKS has been changed.""" - return os.path.join('Misc', 'ACKS') in file_paths + return 'Misc/ACKS' in file_paths @status("Misc/NEWS updated", modal=True) def reported_news(file_paths): """Check if Misc/NEWS has been changed.""" - return os.path.join('Misc', 'NEWS') in file_paths + return 'Misc/NEWS' in file_paths @status("configure regenerated", modal=True, info=str) def regenerated_configure(file_paths): @@ -153,8 +153,7 @@ python_files = [fn for fn in file_paths if fn.endswith('.py')] c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))] doc_files = [fn for fn in file_paths if fn.startswith('Doc')] - misc_files = {os.path.join('Misc', 'ACKS'), os.path.join('Misc', 'NEWS')}\ - & set(file_paths) + special_files = {'Misc/ACKS', 'Misc/NEWS'} & set(file_paths) # PEP 8 whitespace rules enforcement. normalize_whitespace(python_files) # C rules enforcement. @@ -164,9 +163,9 @@ # Docs updated. docs_modified(doc_files) # Misc/ACKS changed. - credit_given(misc_files) + credit_given(special_files) # Misc/NEWS changed. - reported_news(misc_files) + reported_news(special_files) # Regenerated configure, if necessary. regenerated_configure(file_paths) # Regenerated pyconfig.h.in, if necessary. diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/scripts/reindent.py --- a/Tools/scripts/reindent.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/scripts/reindent.py Fri Feb 01 23:12:09 2013 +0100 @@ -52,8 +52,8 @@ recurse = False dryrun = False makebackup = True -# A specified newline to be used in the output (set by --newline option) spec_newline = None +"""A specified newline to be used in the output (set by --newline option)""" def usage(msg=None): diff -r 35c88c53cf64 -r ecc10f0afb76 Tools/unicode/mkstringprep.py --- a/Tools/unicode/mkstringprep.py Fri Jul 26 23:14:22 2013 -0700 +++ b/Tools/unicode/mkstringprep.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,5 +1,4 @@ -import re, sys -from unicodedata import ucd_3_2_0 as unicodedata +import re, unicodedata, sys if sys.maxunicode == 65535: raise RuntimeError("need UCS-4 Python") @@ -38,20 +37,16 @@ tuple.append((prev,prev+span+1)) else: single.append(prev) - if not single and len(tuple) == 1: - tuple = "range(%d,%d)" % tuple[0] - else: - tuple = " + ".join("list(range(%d,%d))" % t for t in tuple) + tuple = " + ".join(["list(range(%d,%d))" % t for t in tuple]) if not single: return "set(%s)" % tuple if not tuple: - return "set(%r)" % (single,) - return "set(%r + %s)" % (single, tuple) + return "set(%s)" % repr(single) + return "set(%s + %s)" % (repr(single),tuple) ############## Read the tables in the RFC ####################### -with open("rfc3454.txt") as f: - data = f.readlines() +data = open("rfc3454.txt").readlines() tables = [] curname = None @@ -60,7 +55,8 @@ if not l: continue # Skip RFC page breaks - if l.startswith(("Hoffman & Blanchet", "RFC 3454")): + if l.startswith("Hoffman & Blanchet") or\ + l.startswith("RFC 3454"): continue # Find start/end lines m = re.match("----- (Start|End) Table ([A-Z](.[0-9])+) -----", l) @@ -75,8 +71,6 @@ else: if not curname: raise RuntimeError("End without start", l) - if curname != m.group(2): - raise RuntimeError("Unexpected end", l) curname = None continue if not curname: @@ -119,10 +113,10 @@ and mappings, for which a mapping function is provided. \"\"\" -from unicodedata import ucd_3_2_0 as unicodedata +import unicodedata """) -print("assert unicodedata.unidata_version == %r" % (unicodedata.unidata_version,)) +print("assert unicodedata.unidata_version == %s" % repr(unicodedata.unidata_version)) # A.1 is the table of unassigned characters # XXX Plane 15 PUA is listed as unassigned in Python. @@ -179,15 +173,15 @@ b3_exceptions = {} for k,v in table_b2.items(): - if list(map(ord, chr(k).lower())) != v: - b3_exceptions[k] = "".join(map(chr,v)) + if map(ord, unichr(k).lower()) != v: + b3_exceptions[k] = u"".join(map(unichr,v)) b3 = sorted(b3_exceptions.items()) print(""" b3_exceptions = {""") -for i, kv in enumerate(b3): - print("0x%x:%a," % kv, end=' ') +for i,(k,v) in enumerate(b3): + print("0x%x:%s," % (k, repr(v)), end=' ') if i % 4 == 3: print() print("}") @@ -230,7 +224,7 @@ def map_table_b2(a): al = map_table_b3(a) b = unicodedata.normalize("NFKC", al) - bl = "".join([map_table_b3(ch) for ch in b]) + bl = u"".join([map_table_b3(ch) for ch in b]) c = unicodedata.normalize("NFKC", bl) if b != c: return c @@ -246,7 +240,7 @@ print(""" def in_table_c11(code): - return code == " " + return code == u" " """) # C.1.2 is the rest of all space characters @@ -255,12 +249,12 @@ assert name == "C.1.2" # table = set(table.keys()) -# Zs = set(gen_category(["Zs"])) - {0x20} +# Zs = set(gen_category(["Zs"])) - set([0x20]) # assert Zs == table print(""" def in_table_c12(code): - return unicodedata.category(code) == "Zs" and code != " " + return unicodedata.category(code) == "Zs" and code != u" " def in_table_c11_c12(code): return unicodedata.category(code) == "Zs" diff -r 35c88c53cf64 -r ecc10f0afb76 config.guess --- a/config.guess Fri Jul 26 23:14:22 2013 -0700 +++ b/config.guess Fri Feb 01 23:12:09 2013 +0100 @@ -2,13 +2,13 @@ # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -# 2011, 2012, 2013 Free Software Foundation, Inc. +# 2011, 2012 Free Software Foundation, Inc. -timestamp='2012-12-29' +timestamp='2012-02-10' # 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 -# the Free Software Foundation; either version 3 of the License, or +# 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 @@ -22,17 +22,19 @@ # 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. This Exception is an additional permission under section 7 -# of the GNU General Public License, version 3 ("GPLv3"). +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner. Please send patches (context +# diff format) to and include a ChangeLog +# entry. # -# Originally written by Per Bothner. +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. # # 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 -# -# Please send patches with a ChangeLog entry to config-patches@gnu.org. - me=`echo "$0" | sed -e 's,.*/,,'` @@ -53,8 +55,8 @@ Originally written by Per Bothner. Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Free Software Foundation, Inc. +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +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." @@ -198,10 +200,6 @@ # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" exit ;; - *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} - exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} @@ -304,7 +302,7 @@ arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit ;; - arm*:riscos:*:*|arm*:RISCOS:*:*) + arm:riscos:*:*|arm:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) @@ -803,9 +801,6 @@ i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; - *:MINGW64*:*) - echo ${UNAME_MACHINE}-pc-mingw64 - exit ;; *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; @@ -1206,9 +1201,6 @@ BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; - x86_64:Haiku:*:*) - echo x86_64-unknown-haiku - exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; @@ -1264,7 +1256,7 @@ NEO-?:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk${UNAME_RELEASE} exit ;; - NSE-*:NONSTOP_KERNEL:*:*) + NSE-?:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; NSR-?:NONSTOP_KERNEL:*:*) @@ -1338,6 +1330,9 @@ exit ;; esac +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + eval $set_cc_for_build cat >$dummy.c <. @@ -22,12 +26,11 @@ # 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. This Exception is an additional permission under section 7 -# of the GNU General Public License, version 3 ("GPLv3"). +# the same distribution terms that you use for the rest of that program. -# Please send patches with a ChangeLog entry to config-patches@gnu.org. +# Please send patches to . Submit a context +# diff and a properly formatted GNU ChangeLog entry. # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. @@ -71,8 +74,8 @@ GNU config.sub ($timestamp) Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Free Software Foundation, Inc. +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +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." @@ -120,7 +123,7 @@ maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ - linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ + linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | \ kopensolaris*-gnu* | \ storm-chaos* | os2-emx* | rtmk-nova*) @@ -153,7 +156,7 @@ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray | -microblaze*) + -apple | -axis | -knuth | -cray | -microblaze) os= basic_machine=$1 ;; @@ -222,12 +225,6 @@ -isc*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; - -lynx*178) - os=-lynxos178 - ;; - -lynx*5) - os=-lynxos5 - ;; -lynx*) os=-lynxos ;; @@ -256,10 +253,8 @@ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ - | arc \ - | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ - | avr | avr32 \ - | be32 | be64 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | be32 | be64 \ | bfin \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ @@ -272,7 +267,7 @@ | le32 | le64 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ + | maxq | mb | microblaze | mcore | mep | metag \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -388,8 +383,7 @@ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ - | microblaze-* | microblazeel-* \ + | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ @@ -788,13 +782,9 @@ basic_machine=ns32k-utek os=-sysv ;; - microblaze*) + microblaze) basic_machine=microblaze-xilinx ;; - mingw64) - basic_machine=x86_64-pc - os=-mingw64 - ;; mingw32) basic_machine=i386-pc os=-mingw32 @@ -1023,11 +1013,7 @@ basic_machine=i586-unknown os=-pw32 ;; - rdos | rdos64) - basic_machine=x86_64-pc - os=-rdos - ;; - rdos32) + rdos) basic_machine=i386-pc os=-rdos ;; @@ -1360,15 +1346,15 @@ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -bitrig* | -openbsd* | -solidbsd* \ + | -openbsd* | -solidbsd* \ | -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* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ - | -linux-newlib* | -linux-musl* | -linux-uclibc* \ + | -mingw32* | -linux-gnu* | -linux-android* \ + | -linux-newlib* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ @@ -1551,9 +1537,6 @@ c4x-* | tic4x-*) os=-coff ;; - hexagon-*) - os=-elf - ;; tic54x-*) os=-coff ;; diff -r 35c88c53cf64 -r ecc10f0afb76 configure --- a/configure Fri Jul 26 23:14:22 2013 -0700 +++ b/configure Fri Feb 01 23:12:09 2013 +0100 @@ -1,11 +1,13 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for python 3.4. +# Generated by GNU Autoconf 2.68 for python 3.4. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -134,31 +136,6 @@ # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -192,8 +169,7 @@ else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -238,25 +214,21 @@ if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -359,14 +331,6 @@ } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -488,10 +452,6 @@ chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -526,16 +486,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' - fi -else - as_ln_s='cp -pR' + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -547,8 +507,28 @@ as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -625,9 +605,6 @@ ac_subst_vars='LTLIBOBJS SRCDIRS THREADHEADERS -LIBPL -PY_ENABLE_SHARED -EXT_SUFFIX SOABI LIBC LIBM @@ -655,7 +632,7 @@ BLDSHARED LDCXXSHARED LDSHARED -SHLIB_SUFFIX +SO LIBTOOL_CRUFT OTHER_LIBTOOL_OPT UNIVERSAL_ARCH_FLAGS @@ -687,7 +664,6 @@ DLLLIBRARY LDLIBRARY LIBRARY -MULTIARCH BUILDEXEEXT EGREP GREP @@ -813,7 +789,6 @@ ac_precious_vars='build_alias host_alias target_alias -MACHDEP CC CFLAGS LDFLAGS @@ -1275,6 +1250,8 @@ if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1488,7 +1465,6 @@ default on supported compilers) Some influential environment variables: - MACHDEP name for machine-dependent library files CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a @@ -1565,9 +1541,9 @@ if $ac_init_version; then cat <<\_ACEOF python configure 3.4 -generated by GNU Autoconf 2.69 - -Copyright (C) 2012 Free Software Foundation, Inc. +generated by GNU Autoconf 2.68 + +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1643,7 +1619,7 @@ test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - test -x conftest$ac_exeext + $as_test_x conftest$ac_exeext }; then : ac_retval=0 else @@ -1941,8 +1917,7 @@ main () { static int test_array [1 - 2 * !((($ac_type) -1 >> ($2 / 2 - 1)) >> ($2 / 2 - 1) == 3)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -1996,8 +1971,7 @@ main () { static int test_array [1 - 2 * !(0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2013,8 +1987,7 @@ { static int test_array [1 - 2 * !(($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1) < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2064,8 +2037,7 @@ main () { static int test_array [1 - 2 * !(($2) >= 0)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2081,8 +2053,7 @@ main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2108,8 +2079,7 @@ main () { static int test_array [1 - 2 * !(($2) < 0)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2125,8 +2095,7 @@ main () { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2160,8 +2129,7 @@ main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2404,7 +2372,7 @@ running configure, to aid debugging if configure makes a mistake. It was created by python $as_me 3.4, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2790,7 +2758,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_HAS_HG="found" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2931,8 +2899,6 @@ - - if test "$cross_compiling" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5 $as_echo_n "checking for python interpreter for cross build... " >&6; } @@ -2949,7 +2915,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5 $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 + PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp fi elif test "$cross_compiling" = maybe; then as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5 @@ -3256,9 +3222,9 @@ then # avoid using uname for cross builds if test "$cross_compiling" = yes; then - # ac_sys_system and ac_sys_release are used for setting - # a lot of different things including 'define_xopen_source' - # in the case statement below. + # ac_sys_system and ac_sys_release are only used for setting + # `define_xopen_source' in the case statement below. For the + # current supported cross builds, this macro is not adjusted. case "$host" in *-*-linux*) ac_sys_system=Linux @@ -3583,7 +3549,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3623,7 +3589,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3676,7 +3642,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3717,7 +3683,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -3775,7 +3741,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3819,7 +3785,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -4265,7 +4231,8 @@ /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -4405,7 +4372,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_CXX="$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 @@ -4448,7 +4415,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_CXX="$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 @@ -4503,7 +4470,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_CXX="$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 @@ -4546,7 +4513,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_CXX="$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 @@ -4601,7 +4568,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_CXX="$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 @@ -4644,7 +4611,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_CXX="$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 @@ -4707,7 +4674,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -4751,7 +4718,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CXX="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -4994,7 +4961,7 @@ for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_GREP" || continue + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in @@ -5060,7 +5027,7 @@ for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -5267,8 +5234,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -# define __EXTENSIONS__ 1 - $ac_includes_default +# define __EXTENSIONS__ 1 + $ac_includes_default int main () { @@ -5359,9 +5326,6 @@ esac;; esac -MULTIARCH=$($CC --print-multiarch 2>/dev/null) - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking LIBRARY" >&5 @@ -5534,7 +5498,7 @@ if test "x$enable_profiling" = xyes; then ac_save_cc="$CC" - CC="$CC -pg" + CC="$(CC) -pg" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main() { return 0; } @@ -5578,7 +5542,6 @@ # Other platforms follow if test $enable_shared = "yes"; then - PY_ENABLE_SHARED=1 $as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h @@ -5636,7 +5599,6 @@ esac else # shared is disabled - PY_ENABLE_SHARED=0 case $ac_sys_system in CYGWIN*) BLDLIBRARY='$(LIBRARY)' @@ -5669,7 +5631,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5709,7 +5671,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5764,7 +5726,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5808,7 +5770,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_AR="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5872,7 +5834,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_READELF="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5916,7 +5878,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_READELF="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -5981,7 +5943,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_PYTHON="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -6058,7 +6020,7 @@ # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -6127,7 +6089,7 @@ test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do - as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ @@ -6377,49 +6339,6 @@ BASECFLAGS="$BASECFLAGS -Wno-unused-result" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -Werror=declaration-after-statement" >&5 -$as_echo_n "checking for -Werror=declaration-after-statement... " >&6; } - ac_save_cc="$CC" - CC="$CC -Werror=declaration-after-statement" - save_CFLAGS="$CFLAGS" - if ${ac_cv_declaration_after_statement_warning+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - -int -main () -{ - - ; - return 0; -} - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - ac_cv_declaration_after_statement_warning=yes - -else - - ac_cv_declaration_after_statement_warning=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - - CFLAGS="$save_CFLAGS" - CC="$ac_save_cc" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_declaration_after_statement_warning" >&5 -$as_echo "$ac_cv_declaration_after_statement_warning" >&6; } - - if test $ac_cv_declaration_after_statement_warning = yes - then - BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement" - fi - # if using gcc on alpha, use -mieee to get (near) full IEEE 754 # support. Without this, treatment of subnormals doesn't follow # the standard. @@ -6566,6 +6485,44 @@ BASECFLAGS="$BASECFLAGS $ac_arch_flags" fi +# Check whether GCC supports PyArg_ParseTuple format +if test "$GCC" = "yes" +then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether gcc supports ParseTuple __format__" >&5 +$as_echo_n "checking whether gcc supports ParseTuple __format__... " >&6; } + save_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -Werror" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + void f(char*,...)__attribute((format(PyArg_ParseTuple, 1, 2))); +int +main () +{ + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + +$as_echo "#define HAVE_ATTRIBUTE_FORMAT_PARSETUPLE 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS=$save_CFLAGS +fi + # On some compilers, pthreads are available without further options # (e.g. MacOS X). On some of these systems, the compiler will not # complain if unaccepted options are passed (e.g. gcc on Mac OS X). @@ -6727,7 +6684,7 @@ # function available. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -pthread" >&5 $as_echo_n "checking whether $CC accepts -pthread... " >&6; } -if ${ac_cv_pthread+:} false; then : +if ${ac_cv_thread+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_cc="$CC" @@ -6937,7 +6894,7 @@ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \ sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \ libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ -bluetooth/bluetooth.h linux/tipc.h spawn.h util.h alloca.h +bluetooth/bluetooth.h linux/tipc.h spawn.h util.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -7230,7 +7187,7 @@ # On Linux, can.h and can/raw.h require sys/socket.h -for ac_header in linux/can.h linux/can/raw.h linux/can/bcm.h +for ac_header in linux/can.h linux/can/raw.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" " @@ -8402,24 +8359,10 @@ -# SHLIB_SUFFIX is the extension of shared libraries `(including the dot!) -# -- usually .so, .sl on HP-UX, .dll on Cygwin -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the extension of shared libraries" >&5 -$as_echo_n "checking the extension of shared libraries... " >&6; } -if test -z "$SHLIB_SUFFIX"; then - case $ac_sys_system in - hp*|HP*) - case `uname -m` in - ia64) SHLIB_SUFFIX=.so;; - *) SHLIB_SUFFIX=.sl;; - esac - ;; - CYGWIN*) SHLIB_SUFFIX=.dll;; - *) SHLIB_SUFFIX=.so;; - esac -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SHLIB_SUFFIX" >&5 -$as_echo "$SHLIB_SUFFIX" >&6; } + +cat >>confdefs.h <<_ACEOF +#define SHLIB_EXT "$SO" +_ACEOF # LDSHARED is the ld *command* used to create shared library # -- "cc -G" on SunOS 5.x, "ld -shared" on IRIX 5 @@ -8614,12 +8557,6 @@ # -u libsys_s pulls in all symbols in libsys Darwin/*) LINKFORSHARED="$extra_undefs -framework CoreFoundation" - - # Issue #18075: the default maximum stack size (8MBytes) is too - # small for the default recursion limit. Increase the stack size - # to ensure that tests don't crash - LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED" - if test "$enable_framework" then LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)' @@ -9091,7 +9028,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_PKG_CONFIG="$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 @@ -9134,7 +9071,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_PKG_CONFIG="$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 @@ -10284,7 +10221,7 @@ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ - wcscoll wcsftime wcsxfrm wmemcmp writev _getpty + wcscoll wcsftime wcsxfrm writev _getpty dup3 do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -10734,7 +10671,7 @@ 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 + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_TRUE="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -12172,8 +12109,7 @@ main () { static int test_array [1 - 2 * !(((char) -1) < 0)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -12204,11 +12140,11 @@ int main () { - +/* FIXME: Include the comments suggested by Paul. */ #ifndef __cplusplus - /* Ultrix mips cc rejects this sort of thing. */ + /* Ultrix mips cc rejects this. */ typedef int charset[2]; - const charset cs = { 0, 0 }; + const charset cs; /* SunOS 4.1.1 cc rejects this. */ char const *const *pcpcc; char **ppc; @@ -12225,9 +12161,8 @@ ++pcpcc; ppc = (char**) pcpcc; pcpcc = (char const *const *) ppc; - { /* SCO 3.2v4 cc rejects this sort of thing. */ - char tx; - char *t = &tx; + { /* SCO 3.2v4 cc rejects this. */ + char *t; char const *s = 0 ? (char *) 0 : (char const *) 0; *t++ = 0; @@ -12243,10 +12178,10 @@ iptr p = 0; ++p; } - { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + { /* AIX XL C 1.02.0.0 rejects this saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; } bx; - struct s *b = &bx; b->j = 5; + struct s { int j; const int *ap[3]; }; + struct s *b; b->j = 5; } { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ const int foo = 10; @@ -13720,23 +13655,44 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SOABI" >&5 $as_echo "$SOABI" >&6; } - -case $ac_sys_system in - Linux*|GNU*) - EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX};; - *) - EXT_SUFFIX=${SHLIB_SUFFIX};; -esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking LDVERSION" >&5 $as_echo_n "checking LDVERSION... " >&6; } LDVERSION='$(VERSION)$(ABIFLAGS)' { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDVERSION" >&5 $as_echo "$LDVERSION" >&6; } - -LIBPL="${prefix}/lib/python${VERSION}/config-${LDVERSION}" - +# SO is the extension of shared libraries `(including the dot!) +# -- usually .so, .sl on HP-UX, .dll on Cygwin +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking SO" >&5 +$as_echo_n "checking SO... " >&6; } +if test -z "$SO" +then + case $ac_sys_system in + hp*|HP*) + case `uname -m` in + ia64) SO=.so;; + *) SO=.sl;; + esac + ;; + CYGWIN*) SO=.dll;; + Linux*|GNU*) + SO=.${SOABI}.so;; + *) SO=.so;; + esac +else + # this might also be a termcap variable, see #610332 + echo + echo '=====================================================================' + echo '+ +' + echo '+ WARNING: You have set SO in your environment. +' + echo '+ Do you really mean to change the extension for shared libraries? +' + echo '+ Continuing in 10 seconds to let you to ponder. +' + echo '+ +' + echo '=====================================================================' + sleep 10 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SO" >&5 +$as_echo "$SO" >&6; } # Check whether right shifting a negative integer extends the sign bit # or fills with zeros (like the Cray J90, according to Tim Peters). @@ -15146,7 +15102,7 @@ fi # generate output files -ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh" +ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc" ac_config_files="$ac_config_files Modules/ld_so_aix" @@ -15558,16 +15514,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' - fi -else - as_ln_s='cp -pR' + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -15627,16 +15583,28 @@ as_mkdir_p=false fi - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -15658,7 +15626,7 @@ # values after options handling. ac_log=" This file was extended by python $as_me 3.4, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -15720,10 +15688,10 @@ ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ python config.status 3.4 -configured by $0, generated by GNU Autoconf 2.69, +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -15813,7 +15781,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' @@ -15850,7 +15818,6 @@ "Makefile.pre") CONFIG_FILES="$CONFIG_FILES Makefile.pre" ;; "Modules/Setup.config") CONFIG_FILES="$CONFIG_FILES Modules/Setup.config" ;; "Misc/python.pc") CONFIG_FILES="$CONFIG_FILES Misc/python.pc" ;; - "Misc/python-config.sh") CONFIG_FILES="$CONFIG_FILES Misc/python-config.sh" ;; "Modules/ld_so_aix") CONFIG_FILES="$CONFIG_FILES Modules/ld_so_aix" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff -r 35c88c53cf64 -r ecc10f0afb76 configure.ac --- a/configure.ac Fri Jul 26 23:14:22 2013 -0700 +++ b/configure.ac Fri Feb 01 23:12:09 2013 +0100 @@ -50,8 +50,6 @@ AC_CONFIG_HEADER(pyconfig.h) AC_CANONICAL_HOST -AC_SUBST(build) -AC_SUBST(host) if test "$cross_compiling" = yes; then AC_MSG_CHECKING([for python interpreter for cross build]) @@ -67,7 +65,7 @@ AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found]) fi 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 + PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp fi elif test "$cross_compiling" = maybe; then AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH]) @@ -348,15 +346,15 @@ ## [Use (OpenStep|Rhapsody) dynamic linker])) ## # Set name for machine-dependent library files -AC_ARG_VAR([MACHDEP], [name for machine-dependent library files]) +AC_SUBST(MACHDEP) AC_MSG_CHECKING(MACHDEP) if test -z "$MACHDEP" then # avoid using uname for cross builds if test "$cross_compiling" = yes; then - # ac_sys_system and ac_sys_release are used for setting - # a lot of different things including 'define_xopen_source' - # in the case statement below. + # ac_sys_system and ac_sys_release are only used for setting + # `define_xopen_source' in the case statement below. For the + # current supported cross builds, this macro is not adjusted. case "$host" in *-*-linux*) ac_sys_system=Linux @@ -766,9 +764,6 @@ esac;; esac -MULTIARCH=$($CC --print-multiarch 2>/dev/null) -AC_SUBST(MULTIARCH) - AC_SUBST(LIBRARY) AC_MSG_CHECKING(LIBRARY) @@ -883,7 +878,7 @@ AS_HELP_STRING([--enable-profiling], [enable C-level code profiling])) if test "x$enable_profiling" = xyes; then ac_save_cc="$CC" - CC="$CC -pg" + CC="$(CC) -pg" AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])], [], [enable_profiling=no]) @@ -917,7 +912,6 @@ # Other platforms follow if test $enable_shared = "yes"; then - PY_ENABLE_SHARED=1 AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.]) case $ac_sys_system in CYGWIN*) @@ -973,7 +967,6 @@ esac else # shared is disabled - PY_ENABLE_SHARED=0 case $ac_sys_system in CYGWIN*) BLDLIBRARY='$(LIBRARY)' @@ -1184,28 +1177,6 @@ BASECFLAGS="$BASECFLAGS -Wno-unused-result" fi - AC_MSG_CHECKING(for -Werror=declaration-after-statement) - ac_save_cc="$CC" - CC="$CC -Werror=declaration-after-statement" - save_CFLAGS="$CFLAGS" - AC_CACHE_VAL(ac_cv_declaration_after_statement_warning, - AC_COMPILE_IFELSE( - [ - AC_LANG_PROGRAM([[]], [[]]) - ],[ - ac_cv_declaration_after_statement_warning=yes - ],[ - ac_cv_declaration_after_statement_warning=no - ])) - CFLAGS="$save_CFLAGS" - CC="$ac_save_cc" - AC_MSG_RESULT($ac_cv_declaration_after_statement_warning) - - if test $ac_cv_declaration_after_statement_warning = yes - then - BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement" - fi - # if using gcc on alpha, use -mieee to get (near) full IEEE 754 # support. Without this, treatment of subnormals doesn't follow # the standard. @@ -1350,6 +1321,24 @@ BASECFLAGS="$BASECFLAGS $ac_arch_flags" fi +# Check whether GCC supports PyArg_ParseTuple format +if test "$GCC" = "yes" +then + AC_MSG_CHECKING(whether gcc supports ParseTuple __format__) + save_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -Werror" + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[void f(char*,...)__attribute((format(PyArg_ParseTuple, 1, 2)));]], [[]]) + ],[ + AC_DEFINE(HAVE_ATTRIBUTE_FORMAT_PARSETUPLE, 1, + [Define if GCC supports __attribute__((format(PyArg_ParseTuple, 2, 3)))]) + AC_MSG_RESULT(yes) + ],[ + AC_MSG_RESULT(no) + ]) + CFLAGS=$save_CFLAGS +fi + # On some compilers, pthreads are available without further options # (e.g. MacOS X). On some of these systems, the compiler will not # complain if unaccepted options are passed (e.g. gcc on Mac OS X). @@ -1447,7 +1436,7 @@ # so we need to run a program to see whether it really made the # function available. AC_MSG_CHECKING(whether $CC accepts -pthread) -AC_CACHE_VAL(ac_cv_pthread, +AC_CACHE_VAL(ac_cv_thread, [ac_save_cc="$CC" CC="$CC -pthread" AC_RUN_IFELSE([AC_LANG_SOURCE([[ @@ -1532,7 +1521,7 @@ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \ sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \ libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ -bluetooth/bluetooth.h linux/tipc.h spawn.h util.h alloca.h) +bluetooth/bluetooth.h linux/tipc.h spawn.h util.h) CPPFLAGS=$ac_save_cppflags AC_HEADER_DIRENT AC_HEADER_MAJOR @@ -1572,7 +1561,7 @@ ]) # On Linux, can.h and can/raw.h require sys/socket.h -AC_CHECK_HEADERS(linux/can.h linux/can/raw.h linux/can/bcm.h,,,[ +AC_CHECK_HEADERS(linux/can.h linux/can/raw.h,,,[ #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -1902,30 +1891,14 @@ esac # Set info about shared libraries. -AC_SUBST(SHLIB_SUFFIX) +AC_SUBST(SO) AC_SUBST(LDSHARED) AC_SUBST(LDCXXSHARED) AC_SUBST(BLDSHARED) AC_SUBST(CCSHARED) AC_SUBST(LINKFORSHARED) -# SHLIB_SUFFIX is the extension of shared libraries `(including the dot!) -# -- usually .so, .sl on HP-UX, .dll on Cygwin -AC_MSG_CHECKING(the extension of shared libraries) -if test -z "$SHLIB_SUFFIX"; then - case $ac_sys_system in - hp*|HP*) - case `uname -m` in - ia64) SHLIB_SUFFIX=.so;; - *) SHLIB_SUFFIX=.sl;; - esac - ;; - CYGWIN*) SHLIB_SUFFIX=.dll;; - *) SHLIB_SUFFIX=.so;; - esac -fi -AC_MSG_RESULT($SHLIB_SUFFIX) - +AC_DEFINE_UNQUOTED(SHLIB_EXT, "$SO", [Define this to be extension of shared libraries (including the dot!).]) # LDSHARED is the ld *command* used to create shared library # -- "cc -G" on SunOS 5.x, "ld -shared" on IRIX 5 # (Shared libraries in this instance are shared modules to be loaded into @@ -2114,12 +2087,6 @@ # -u libsys_s pulls in all symbols in libsys Darwin/*) LINKFORSHARED="$extra_undefs -framework CoreFoundation" - - # Issue #18075: the default maximum stack size (8MBytes) is too - # small for the default recursion limit. Increase the stack size - # to ensure that tests don't crash - LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED" - if test "$enable_framework" then LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)' @@ -2826,7 +2793,7 @@ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ - wcscoll wcsftime wcsxfrm wmemcmp writev _getpty) + wcscoll wcsftime wcsxfrm writev _getpty dup3) AC_CHECK_DECL(dirfd, AC_DEFINE(HAVE_DIRFD, 1, @@ -3954,22 +3921,40 @@ SOABI='cpython-'`echo $VERSION | tr -d .`${ABIFLAGS} AC_MSG_RESULT($SOABI) -AC_SUBST(EXT_SUFFIX) -case $ac_sys_system in - Linux*|GNU*) - EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX};; - *) - EXT_SUFFIX=${SHLIB_SUFFIX};; -esac - AC_MSG_CHECKING(LDVERSION) LDVERSION='$(VERSION)$(ABIFLAGS)' AC_MSG_RESULT($LDVERSION) -dnl define LIBPL after ABIFLAGS and LDVERSION is defined. -AC_SUBST(PY_ENABLE_SHARED) -LIBPL="${prefix}/lib/python${VERSION}/config-${LDVERSION}" -AC_SUBST(LIBPL) +# SO is the extension of shared libraries `(including the dot!) +# -- usually .so, .sl on HP-UX, .dll on Cygwin +AC_MSG_CHECKING(SO) +if test -z "$SO" +then + case $ac_sys_system in + hp*|HP*) + case `uname -m` in + ia64) SO=.so;; + *) SO=.sl;; + esac + ;; + CYGWIN*) SO=.dll;; + Linux*|GNU*) + SO=.${SOABI}.so;; + *) SO=.so;; + esac +else + # this might also be a termcap variable, see #610332 + echo + echo '=====================================================================' + echo '+ +' + echo '+ WARNING: You have set SO in your environment. +' + echo '+ Do you really mean to change the extension for shared libraries? +' + echo '+ Continuing in 10 seconds to let you to ponder. +' + echo '+ +' + echo '=====================================================================' + sleep 10 +fi +AC_MSG_RESULT($SO) # Check whether right shifting a negative integer extends the sign bit # or fills with zeros (like the Cray J90, according to Tim Peters). @@ -4650,7 +4635,7 @@ fi # generate output files -AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh) +AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc) AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix]) AC_OUTPUT diff -r 35c88c53cf64 -r ecc10f0afb76 create_patch.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create_patch.sh Fri Feb 01 23:12:09 2013 +0100 @@ -0,0 +1,5 @@ +FILENAME="$(hg id -i).patch" +hg diff -rf87d85f7596c:tip >$FILENAME +diffstat $FILENAME +echo "$FILENAME created" +echo "FIXME: remove configure, Python/importlib.h, PEP-433.patch from the patch" diff -r 35c88c53cf64 -r ecc10f0afb76 pyconfig.h.in --- a/pyconfig.h.in Fri Jul 26 23:14:22 2013 -0700 +++ b/pyconfig.h.in Fri Feb 01 23:12:09 2013 +0100 @@ -49,9 +49,6 @@ /* Define to 1 if you have the `alarm' function. */ #undef HAVE_ALARM -/* Define to 1 if you have the header file. */ -#undef HAVE_ALLOCA_H - /* Define this if your time.h defines altzone. */ #undef HAVE_ALTZONE @@ -64,6 +61,9 @@ /* Define to 1 if you have the `atanh' function. */ #undef HAVE_ATANH +/* Define if GCC supports __attribute__((format(PyArg_ParseTuple, 2, 3))) */ +#undef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE + /* Define to 1 if you have the `bind_textdomain_codeset' function. */ #undef HAVE_BIND_TEXTDOMAIN_CODESET @@ -193,6 +193,9 @@ /* Define to 1 if you have the `dup2' function. */ #undef HAVE_DUP2 +/* Define to 1 if you have the `dup3' function. */ +#undef HAVE_DUP3 + /* Defined when any dynamic module loading is enabled. */ #undef HAVE_DYNAMIC_LOADING @@ -501,9 +504,6 @@ /* Define to 1 if you have the `linkat' function. */ #undef HAVE_LINKAT -/* Define to 1 if you have the header file. */ -#undef HAVE_LINUX_CAN_BCM_H - /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_CAN_H @@ -1118,9 +1118,6 @@ /* Define to 1 if you have the `wcsxfrm' function. */ #undef HAVE_WCSXFRM -/* Define to 1 if you have the `wmemcmp' function. */ -#undef HAVE_WMEMCMP - /* Define if tzset() actually switches the local timezone in a meaningful way. */ #undef HAVE_WORKING_TZSET @@ -1193,6 +1190,9 @@ /* Define if setpgrp() must be called as setpgrp(0, 0). */ #undef SETPGRP_HAVE_ARG +/* Define this to be extension of shared libraries (including the dot!). */ +#undef SHLIB_EXT + /* Define if i>>j for signed int i does not extend the sign bit when i < 0 */ #undef SIGNED_RIGHT_SHIFT_ZERO_FILLS diff -r 35c88c53cf64 -r ecc10f0afb76 setup.py --- a/setup.py Fri Jul 26 23:14:22 2013 -0700 +++ b/setup.py Fri Feb 01 23:12:09 2013 +0100 @@ -1,7 +1,7 @@ # Autodetecting setup.py script for building the Python extensions # -import sys, os, importlib.machinery, re, optparse +import sys, os, imp, re, optparse from glob import glob import sysconfig @@ -169,7 +169,13 @@ def build_extensions(self): # Detect which modules should be compiled - missing = self.detect_modules() + old_so = self.compiler.shared_lib_extension + # Workaround PEP 3149 stuff + self.compiler.shared_lib_extension = os.environ.get("SO", ".so") + try: + missing = self.detect_modules() + finally: + self.compiler.shared_lib_extension = old_so # Remove modules that are present on the disabled list extensions = [ext for ext in self.extensions @@ -259,9 +265,8 @@ if missing: print() - print("Python build finished successfully!") - print("The necessary bits to build these optional modules were not " - "found:") + print("Python build finished, but the necessary bits to build " + "these modules were not found:") print_three_column(missing) print("To find the necessary bits, look in setup.py in" " detect_modules() for the module's name.") @@ -326,9 +331,8 @@ if cross_compiling: return - loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename) try: - loader.load_module() + imp.load_dynamic(ext.name, ext_filename) except ImportError as why: self.failed.append(ext.name) self.announce('*** WARNING: renaming "%s" since importing it' @@ -788,10 +792,10 @@ for line in incfile: m = openssl_ver_re.match(line) if m: - openssl_ver = int(m.group(1), 16) - break + openssl_ver = eval(m.group(1)) except IOError as msg: print("IOError while reading opensshv.h:", msg) + pass #print('openssl_ver = 0x%08x' % openssl_ver) min_openssl_ver = 0x00907000 @@ -1069,7 +1073,7 @@ with open(f) as file: incf = file.read() m = re.search( - r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf) + r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf) if m: sqlite_version = m.group(1) sqlite_version_tuple = tuple([int(x) @@ -1401,7 +1405,6 @@ define_macros = [] expat_lib = ['expat'] expat_sources = [] - expat_depends = [] else: expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')] define_macros = [ @@ -1411,25 +1414,12 @@ expat_sources = ['expat/xmlparse.c', 'expat/xmlrole.c', 'expat/xmltok.c'] - expat_depends = ['expat/ascii.h', - 'expat/asciitab.h', - 'expat/expat.h', - 'expat/expat_config.h', - 'expat/expat_external.h', - 'expat/internal.h', - 'expat/latin1tab.h', - 'expat/utf8tab.h', - 'expat/xmlrole.h', - 'expat/xmltok.h', - 'expat/xmltok_impl.h' - ] exts.append(Extension('pyexpat', define_macros = define_macros, include_dirs = expat_inc, libraries = expat_lib, - sources = ['pyexpat.c'] + expat_sources, - depends = expat_depends, + sources = ['pyexpat.c'] + expat_sources )) # Fredrik Lundh's cElementTree module. Note that this also @@ -1442,8 +1432,6 @@ include_dirs = expat_inc, libraries = expat_lib, sources = ['_elementtree.c'], - depends = ['pyexpat.c'] + expat_sources + - expat_depends, )) else: missing.append('_elementtree') @@ -1520,6 +1508,10 @@ if host_platform == 'darwin': exts.append( + Extension('_gestalt', ['_gestalt.c'], + extra_link_args=['-framework', 'Carbon']) + ) + exts.append( Extension('_scproxy', ['_scproxy.c'], extra_link_args=[ '-framework', 'SystemConfiguration', @@ -2016,12 +2008,8 @@ # Increase warning level for gcc: if 'gcc' in cc: - cmd = ("echo '' | %s -Wextra -Wno-missing-field-initializers -E - " - "> /dev/null 2>&1" % cc) - ret = os.system(cmd) - if ret >> 8 == 0: - extra_compile_args.extend(['-Wextra', - '-Wno-missing-field-initializers']) + extra_compile_args.extend(['-Wextra', + '-Wno-missing-field-initializers']) # Uncomment for extra functionality: #define_macros.append(('EXTRA_FUNCTIONALITY', 1)) @@ -2058,8 +2046,7 @@ # mode 644 unless they are a shared library in which case they will get # mode 755. All installed directories will get mode 755. - # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX - shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX") + so_ext = sysconfig.get_config_var("SO") def install(self): outfiles = install_lib.install(self) @@ -2074,7 +2061,7 @@ for filename in files: if os.path.islink(filename): continue mode = defaultMode - if filename.endswith(self.shlib_suffix): mode = sharedLibMode + if filename.endswith(self.so_ext): mode = sharedLibMode log.info("changing mode of %s to %o", filename, mode) if not self.dry_run: os.chmod(filename, mode)