|
8 | 8 |
|
9 | 9 | .. Fix accents on Kristjan Valur Jonsson, Fuerstenau |
10 | 10 |
|
11 | | -.. Big jobs: pep 391, PyCapsule |
| 11 | +.. Big jobs: pep 391 example |
12 | 12 |
|
13 | 13 | .. hyperlink all the methods & functions. |
14 | 14 |
|
@@ -125,6 +125,7 @@ A partial list of 3.1 features that were backported to 2.7: |
125 | 125 | results more correctly. And :func:`repr` of a floating-point |
126 | 126 | number *x* returns a result that's guaranteed to round back to the |
127 | 127 | same number when converted back to a string. |
| 128 | +* The :ctype:`PyCapsule` type, used to provide a C API for an extension module. |
128 | 129 | * The :cfunc:`PyLong_AsLongAndOverflow` C API function. |
129 | 130 |
|
130 | 131 | One porting change: the :option:`-3` switch now automatically |
@@ -1348,11 +1349,26 @@ changes, or look through the Subversion logs for all the details. |
1348 | 1349 | Antoine Pitrou; :issue:`8104`.) |
1349 | 1350 |
|
1350 | 1351 | * The :mod:`SocketServer` module's :class:`~SocketServer.TCPServer` class now |
1351 | | - has a :attr:`~SocketServer.TCPServer.disable_nagle_algorithm` class attribute. |
1352 | | - The default value is False; if overridden to be True, |
| 1352 | + supports socket timeouts and disabling the Nagle algorithm. |
| 1353 | + The :attr:`~SocketServer.TCPServer.disable_nagle_algorithm` class attribute |
| 1354 | + defaults to False; if overridden to be True, |
1353 | 1355 | new request connections will have the TCP_NODELAY option set to |
1354 | 1356 | prevent buffering many small sends into a single TCP packet. |
1355 | | - (Contributed by Kristjan Valur Jonsson; :issue:`6192`.) |
| 1357 | + The :attr:`~SocketServer.TCPServer.timeout` class attribute can hold |
| 1358 | + a timeout in seconds that will be applied to the request socket; if |
| 1359 | + no request is received within that time, :meth:`handle_timeout` |
| 1360 | + will be called and :meth:`handle_request` will return. |
| 1361 | + (Contributed by Kristjan Valur Jonsson; :issue:`6192` and :issue:`6267`.) |
| 1362 | + |
| 1363 | +* The XML-RPC client and server, provided by the :mod:`xmlrpclib` and |
| 1364 | + :mod:`SimpleXMLRPCServer` modules, have improved performance by |
| 1365 | + supporting HTTP/1.1 keep-alive and by optionally using gzip encoding |
| 1366 | + to compress the XML being exchanged. The gzip compression is |
| 1367 | + controlled by the :attr:`encode_threshold` attribute of |
| 1368 | + :class:`SimpleXMLRPCRequestHandler`, which contains a size in bytes; |
| 1369 | + responses larger than this will be compressed. |
| 1370 | + (Contributed by Kristjan Valur Jonsson; :issue:`6267`.) |
| 1371 | + |
1356 | 1372 |
|
1357 | 1373 | * Updated module: the :mod:`sqlite3` module has been updated to |
1358 | 1374 | version 2.6.0 of the `pysqlite package <http://code.google.com/p/pysqlite/>`__. Version 2.6.0 includes a number of bugfixes, and adds |
@@ -1515,6 +1531,15 @@ changes, or look through the Subversion logs for all the details. |
1515 | 1531 | or comment (which looks like ``<!-- comment -->``). |
1516 | 1532 | (Patch by Neil Muller; :issue:`2746`.) |
1517 | 1533 |
|
| 1534 | +* The XML-RPC client and server, provided by the :mod:`xmlrpclib` and |
| 1535 | + :mod:`SimpleXMLRPCServer` modules, have improved performance by |
| 1536 | + supporting HTTP/1.1 keep-alive and by optionally using gzip encoding |
| 1537 | + to compress the XML being exchanged. The gzip compression is |
| 1538 | + controlled by the :attr:`encode_threshold` attribute of |
| 1539 | + :class:`SimpleXMLRPCRequestHandler`, which contains a size in bytes; |
| 1540 | + responses larger than this will be compressed. |
| 1541 | + (Contributed by Kristjan Valur Jonsson; :issue:`6267`.) |
| 1542 | + |
1518 | 1543 | * The :mod:`zipfile` module's :class:`~zipfile.ZipFile` now supports the context |
1519 | 1544 | management protocol, so you can write ``with zipfile.ZipFile(...) as f: ...``. |
1520 | 1545 | (Contributed by Brian Curtin; :issue:`5511`.) |
@@ -2047,6 +2072,52 @@ Changes to Python's build process and to the C API include: |
2047 | 2072 | Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.) |
2048 | 2073 |
|
2049 | 2074 |
|
| 2075 | +.. _whatsnew27-capsules: |
| 2076 | + |
| 2077 | +Capsules |
| 2078 | +------------------- |
| 2079 | + |
| 2080 | +Python 3.1 adds a new C datatype, :ctype:`PyCapsule`, for providing a |
| 2081 | +C API to an extension module. A capsule is essentially the holder for |
| 2082 | +a C ``void *`` pointer, and is bound to a module attribute; for |
| 2083 | +example, the :mod:`socket` module's API is exposed as ``socket.CAPI`, |
| 2084 | +and :mod:`unicodedata` calls it ``ucnhash_CAPI``. Other extensions |
| 2085 | +can import the module, access its dictionary to get the capsule |
| 2086 | +object, and then get the ``void *`` pointer, which will usually point |
| 2087 | +to an array of pointers to the various API functions. |
| 2088 | + |
| 2089 | +There is an existing data type that already does this, |
| 2090 | +:ctype:`PyCObject`, but it doesn't provide type safety. Evil code |
| 2091 | +written in pure Python could cause a segmentation fault by taking a |
| 2092 | +:ctype:`PyCObject` from module A and somehow substituting it for the |
| 2093 | +:ctype:`PyCObject` in module B. Capsules know their own name, |
| 2094 | +and getting the pointer requires providing the name:: |
| 2095 | + |
| 2096 | + void *vtable; |
| 2097 | + |
| 2098 | + if (!PyCapsule_IsValid(capsule, "mymodule.CAPI") { |
| 2099 | + PyErr_SetString(PyExc_ValueError, "argument type invalid"); |
| 2100 | + return NULL; |
| 2101 | + } |
| 2102 | + |
| 2103 | + vtable = PyCapsule_GetPointer(capsule, "mymodule.CAPI"); |
| 2104 | + |
| 2105 | +You are assured that ``vtable`` points to whatever you're expecting. |
| 2106 | +If a different capsule was passed in, :cfunc:`PyCapsule_IsValid` would |
| 2107 | +detect the mismatched name and return false. Refer to |
| 2108 | +:ref:`using-capsules` for more information on using these objects. |
| 2109 | + |
| 2110 | +Python 2.7 now uses capsules internally to provide various |
| 2111 | +extension-module APIs, but the :cfunc:`PyCObject_AsVoidPtr` was |
| 2112 | +modified to handle capsules, preserving compile-time compatibility |
| 2113 | +with the :ctype:`CObject` interface. Use of |
| 2114 | +:cfunc:`PyCObject_AsVoidPtr` will signal a |
| 2115 | +:exc:`PendingDeprecationWarning`, which is silent by default. |
| 2116 | + |
| 2117 | +Implemented in Python 3.1 and backported to 2.7 by Larry Hastings; |
| 2118 | +discussed in :issue:`5630`. |
| 2119 | + |
| 2120 | + |
2050 | 2121 | .. ====================================================================== |
2051 | 2122 |
|
2052 | 2123 | Port-Specific Changes: Windows |
|
0 commit comments