Skip to content

Commit 85fffc3

Browse files
committed
Add two items
1 parent e6f5e22 commit 85fffc3

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

Doc/whatsnew/2.7.rst

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
.. Fix accents on Kristjan Valur Jonsson, Fuerstenau
1010
11-
.. Big jobs: pep 391, PyCapsule
11+
.. Big jobs: pep 391 example
1212
1313
.. hyperlink all the methods & functions.
1414
@@ -125,6 +125,7 @@ A partial list of 3.1 features that were backported to 2.7:
125125
results more correctly. And :func:`repr` of a floating-point
126126
number *x* returns a result that's guaranteed to round back to the
127127
same number when converted back to a string.
128+
* The :ctype:`PyCapsule` type, used to provide a C API for an extension module.
128129
* The :cfunc:`PyLong_AsLongAndOverflow` C API function.
129130

130131
One porting change: the :option:`-3` switch now automatically
@@ -1348,11 +1349,26 @@ changes, or look through the Subversion logs for all the details.
13481349
Antoine Pitrou; :issue:`8104`.)
13491350

13501351
* 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,
13531355
new request connections will have the TCP_NODELAY option set to
13541356
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+
13561372

13571373
* Updated module: the :mod:`sqlite3` module has been updated to
13581374
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.
15151531
or comment (which looks like ``<!-- comment -->``).
15161532
(Patch by Neil Muller; :issue:`2746`.)
15171533

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+
15181543
* The :mod:`zipfile` module's :class:`~zipfile.ZipFile` now supports the context
15191544
management protocol, so you can write ``with zipfile.ZipFile(...) as f: ...``.
15201545
(Contributed by Brian Curtin; :issue:`5511`.)
@@ -2047,6 +2072,52 @@ Changes to Python's build process and to the C API include:
20472072
Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.)
20482073

20492074

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+
20502121
.. ======================================================================
20512122
20522123
Port-Specific Changes: Windows

0 commit comments

Comments
 (0)