diff options
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/distutils/builtdist.rst | 36 | ||||
-rw-r--r-- | Doc/includes/tzinfo-examples.py | 46 | ||||
-rw-r--r-- | Doc/library/index.rst | 5 | ||||
-rw-r--r-- | Doc/library/select.rst | 4 | ||||
-rw-r--r-- | Doc/library/types.rst | 18 | ||||
-rw-r--r-- | Doc/whatsnew/2.6.rst | 173 |
6 files changed, 249 insertions, 33 deletions
diff --git a/Doc/distutils/builtdist.rst b/Doc/distutils/builtdist.rst index 2ebc986..cd2bd81 100644 --- a/Doc/distutils/builtdist.rst +++ b/Doc/distutils/builtdist.rst @@ -329,6 +329,42 @@ version number. This can be changed to another text by using the The installer file will be written to the "distribution directory" --- normally :file:`dist/`, but customizable with the :option:`--dist-dir` option. +.. _cross-compile-windows: + +Cross-compiling on Windows +========================== + +Starting with Python 2.6, distutils is capable of cross-compiling between +Windows platforms. In practice, this means that with the correct tools +installed, you can use a 32bit version of Windows to create 64bit extensions +and vice-versa. + +To build for an alternate platform, specify the :option:`--plat-name` option +to the build command. Valid values are currently 'win32', 'win-amd64' and +'win-ia64'. For example, on a 32bit version of Windows, you could execute:: + + python setup.py build --plat-name=win-amd64 + +to build a 64bit version of your extension. The Windows Installers also +support this option, so the command:: + + python setup.py build --plat-name=win-amd64 bdist_wininst + +would create a 64bit installation executable on your 32bit version of Windows. + +To cross-compile, you must download the Python source code and cross-compile +Python itself for the platform you are targetting - it is not possible from a +binary installtion of Python (as the .lib etc file for other platforms are +not included.) In practice, this means the user of a 32 bit operating +system will need to use Visual Studio 2008 to open the +:file:`PCBuild/PCbuild.sln` solution in the Python source tree and build the +"x64" configuration of the 'pythoncore' project before cross-compiling +extensions is possible. + +Note that by default, Visual Studio 2008 does not install 64bit compilers or +tools. You may need to reexecute the Visual Studio setup process and select +these tools (using Control Panel->[Add/Remove] Programs is a convenient way to +check or modify your existing install.) .. _postinstallation-script: diff --git a/Doc/includes/tzinfo-examples.py b/Doc/includes/tzinfo-examples.py index 5a2b8ad..2de95d4 100644 --- a/Doc/includes/tzinfo-examples.py +++ b/Doc/includes/tzinfo-examples.py @@ -87,11 +87,31 @@ def first_sunday_on_or_after(dt): dt += timedelta(days_to_go) return dt -# In the US, DST starts at 2am (standard time) on the first Sunday in April. -DSTSTART = datetime(1, 4, 1, 2) -# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct. -# which is the first Sunday on or after Oct 25. -DSTEND = datetime(1, 10, 25, 1) + +# US DST Rules +# +# This is a simplified (i.e., wrong for a few cases) set of rules for US +# DST start and end times. For a complete and up-to-date set of DST rules +# and timezone definitions, visit the Olson Database (or try pytz): +# http://www.twinsun.com/tz/tz-link.htm +# http://sourceforge.net/projects/pytz/ (might not be up-to-date) +# +# In the US, since 2007, DST starts at 2am (standard time) on the second +# Sunday in March, which is the first Sunday on or after Mar 8. +DSTSTART_2007 = datetime(1, 3, 8, 2) +# and ends at 2am (DST time; 1am standard time) on the first Sunday of Nov. +DSTEND_2007 = datetime(1, 11, 1, 1) +# From 1987 to 2006, DST used to start at 2am (standard time) on the first +# Sunday in April and to end at 2am (DST time; 1am standard time) on the last +# Sunday of October, which is the first Sunday on or after Oct 25. +DSTSTART_1987_2006 = datetime(1, 4, 1, 2) +DSTEND_1987_2006 = datetime(1, 10, 25, 1) +# From 1967 to 1986, DST used to start at 2am (standard time) on the last +# Sunday in April (the one on or after April 24) and to end at 2am (DST time; +# 1am standard time) on the last Sunday of October, which is the first Sunday +# on or after Oct 25. +DSTSTART_1967_1986 = datetime(1, 4, 24, 2) +DSTEND_1967_1986 = DSTEND_1987_2006 class USTimeZone(tzinfo): @@ -122,9 +142,19 @@ class USTimeZone(tzinfo): return ZERO assert dt.tzinfo is self - # Find first Sunday in April & the last in October. - start = first_sunday_on_or_after(DSTSTART.replace(year=dt.year)) - end = first_sunday_on_or_after(DSTEND.replace(year=dt.year)) + # Find start and end times for US DST. For years before 1967, return + # ZERO for no DST. + if 2006 < dt.year: + dststart, dstend = DSTSTART_2007, DSTEND_2007 + elif 1986 < dt.year < 2007: + dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006 + elif 1966 < dt.year < 1987: + dststart, dstend = DSTSTART_1967_1986, DSTEND_1967_1986 + else: + return ZERO + + start = first_sunday_on_or_after(dststart.replace(year=dt.year)) + end = first_sunday_on_or_after(dstend.replace(year=dt.year)) # Can't compare naive to aware objects, so strip the timezone from # dt first. diff --git a/Doc/library/index.rst b/Doc/library/index.rst index 5b98989..a433214 100644 --- a/Doc/library/index.rst +++ b/Doc/library/index.rst @@ -31,8 +31,9 @@ tools provided with the operating system to obtain some or all of the optional components. In addition to the standard library, there is a growing collection of -over 2500 additional components available from the `Python Package Index -<http://pypi.python.org/pypi>`_. +several thousand components (from individual programs and modules to +packages and entire application development frameworks), available from +the `Python Package Index <http://pypi.python.org/pypi>`_. .. toctree:: diff --git a/Doc/library/select.rst b/Doc/library/select.rst index df3ea9f..3fef993 100644 --- a/Doc/library/select.rst +++ b/Doc/library/select.rst @@ -113,9 +113,9 @@ Edge and Level Trigger Polling (epoll) Objects +-----------------------+-----------------------------------------------+ | :const:`EPOLLPRI` | Urgent data for read | +-----------------------+-----------------------------------------------+ - | :const:`EPOLLERR` | Error condition happend on the assoc. fd | + | :const:`EPOLLERR` | Error condition happened on the assoc. fd | +-----------------------+-----------------------------------------------+ - | :const:`EPOLLHUP` | Hang up happend on the assoc. fd | + | :const:`EPOLLHUP` | Hang up happened on the assoc. fd | +-----------------------+-----------------------------------------------+ | :const:`EPOLLET` | Set Edge Trigger behavior, the default is | | | Level Trigger behavior | diff --git a/Doc/library/types.rst b/Doc/library/types.rst index ddb7e7d..e3cbef5 100644 --- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -86,15 +86,17 @@ The module defines the following names: .. data:: GetSetDescriptorType - The type of objects defined in extension modules with ``PyGetSetDef``, such as - ``FrameType.f_locals`` or ``array.array.typecode``. This constant is not - defined in implementations of Python that do not have such extension types, so - for portable code use ``hasattr(types, 'GetSetDescriptorType')``. + The type of objects defined in extension modules with ``PyGetSetDef``, such + as ``FrameType.f_locals`` or ``array.array.typecode``. This type is used as + descriptor for object attributes; it has the same purpose as the + :class:`property` type, but for classes defined in extension modules. .. data:: MemberDescriptorType - The type of objects defined in extension modules with ``PyMemberDef``, such as - ``datetime.timedelta.days``. This constant is not defined in implementations of - Python that do not have such extension types, so for portable code use - ``hasattr(types, 'MemberDescriptorType')``. + The type of objects defined in extension modules with ``PyMemberDef``, such + as ``datetime.timedelta.days``. This type is used as descriptor for simple C + data members which use standard conversion functions; it has the same purpose + as the :class:`property` type, but for classes defined in extension modules. + In other implementations of Python, this type may be identical to + ``GetSetDescriptorType``. diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 2098508..29a2693 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -728,6 +728,12 @@ or using a :class:`bytes` constructor. For future compatibility, Python 2.6 adds :class:`bytes` as a synonym for the :class:`str` type, and it also supports the ``b''`` notation. +There's also a ``__future__`` import that causes all string literals +to become Unicode strings. This means that ``\u`` escape sequences +can be used to include Unicode characters. + +XXX give example + .. seealso:: :pep:`3112` - Bytes literals in Python 3000 @@ -740,7 +746,70 @@ and it also supports the ``b''`` notation. PEP 3116: New I/O Library ===================================================== -XXX write this. +Python's built-in file objects support a number of methods, but +file-like objects don't necessarily support all of them. Objects that +imitate files usually support :meth:`read` and :meth:`write`, but they +may not support :meth:`readline`. Python 3.0 introduces a layered I/O +library in the :mod:`io` module that separates buffering and +text-handling features from the fundamental read and write operations. + +There are three levels of abstract base classes provided by +the :mod:`io` module: + +* :class:`RawIOBase`: defines raw I/O operations: :meth:`read`, + :meth:`readinto`, + :meth:`write`, :meth:`seek`, :meth:`tell`, :meth:`truncate`, + and :meth:`close`. + Most of the methods of this class will often map to a single system call. + There are also :meth:`readable`, :meth:`writable`, and :meth:`seekable` + methods for determining what operations a given object will allow. + + Python 3.0 has concrete implementations of this class for files and + sockets, but Python 2.6 hasn't restructured its file and socket objects + in this way. + + .. XXX should 2.6 register them in io.py? + +* :class:`BufferedIOBase`: is an abstract base class that + buffers data in memory to reduce the number of + system calls used, making I/O processing more efficient. + It supports all of the methods of :class:`RawIOBase`, + and adds a :attr:`raw` attribute holding the underlying raw object. + + There are four concrete classes implementing this ABC: + :class:`BufferedWriter` and + :class:`BufferedReader` for objects that only support + writing or reading and don't support random access, + :class:`BufferedRandom` for objects that support the :meth:`seek` method + for random access, + and :class:`BufferedRWPair` for objects such as TTYs that have + both read and write operations that act upon unconnected streams of data. + +* :class:`TextIOBase`: Provides functions for reading and writing + strings (remember, strings will be Unicode in Python 3.0), + and supporting universal newlines. :class:`TextIOBase` defines + the :meth:`readline` method and supports iteration upon + objects. + + There are two concrete implementations. :class:`TextIOWrapper` + wraps a buffered I/O object, supporting all of the methods for + text I/O and adding a :attr:`buffer` attribute for access + to the underlying object. :class:`StringIO` simply buffers + everything in memory without ever writing anything to disk. + + (In current 2.6 alpha releases, :class:`io.StringIO` is implemented in + pure Python, so it's pretty slow. You should therefore stick with the + existing :mod:`StringIO` module or :mod:`cStringIO` for now. At some + point Python 3.0's :mod:`io` module will be rewritten into C for speed, + and perhaps the C implementation will be backported to the 2.x releases.) + + .. XXX check before final release: is io.py still written in Python? + +In Python 2.6, the underlying implementations haven't been +restructured to build on top of the :mod:`io` module's classes. The +module is being provided to make it easier to write code that's +forward-compatible with 3.0, and to save developers the effort of writing +their own implementations of buffering and text I/O. .. seealso:: @@ -952,22 +1021,48 @@ Subclasses must then define a :meth:`readonly` property PEP 3127: Integer Literal Support and Syntax ===================================================== -XXX write this -- this section is currently just brief notes. +Python 3.0 changes the syntax for octal (base-8) integer literals, +which are now prefixed by "0o" or "0O" instead of a leading zero, and +adds support for binary (base-2) integer literals, signalled by a "0b" +or "0B" prefix. + +Python 2.6 doesn't drop support for a leading 0 signalling +an octal number, but it does add support for "0o" and "0b":: + + >>> 0o21, 2*8 + 1 + (17, 17) + >>> 0b101111 + 47 + +The :func:`oct` built-in still returns numbers +prefixed with a leading zero, and a new :func:`bin` +built-in returns the binary representation for a number:: -Python 3.0 changes the syntax for octal integer literals, and -adds supports for binary integers: 0o instad of 0, -and 0b for binary. Python 2.6 doesn't support this, but a bin() -builtin was added. + >>> oct(42) + '052' + >>> bin(173) + '0b10101101' -XXX changes to the hex/oct builtins +The :func:`int` and :func:`long` built-ins will now accept the "0o" +and "0b" prefixes when base-8 or base-2 are requested, or when the +**base** argument is zero (meaning the base used is determined from +the string): + >>> int ('0o52', 0) + 42 + >>> int('1101', 2) + 13 + >>> int('0b1101', 2) + 13 + >>> int('0b1101', 0) + 13 -New bin() built-in returns the binary form of a number. .. seealso:: :pep:`3127` - Integer Literal Support and Syntax - PEP written by Patrick Maupin. + PEP written by Patrick Maupin; backported to 2.6 by + Eric Smith. .. ====================================================================== @@ -1124,6 +1219,13 @@ Here are all of the changes that Python 2.6 makes to the core Python language. .. Patch 1686487 +* Tuples now have an :meth:`index` method matching the list type's + :meth:`index` method:: + + >>> t = (0,1,2,3,4) + >>> t.index(3) + 3 + * The built-in types now have improved support for extended slicing syntax, where various combinations of ``(start, stop, step)`` are supplied. Previously, the support was partial and certain corner cases wouldn't work. @@ -1532,7 +1634,7 @@ complete list of changes, or look through the CVS logs for all the details. (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)] - ``itertools.chain(*iterables)` is an existing function in + ``itertools.chain(*iterables)`` is an existing function in :mod:`itertools` that gained a new constructor in Python 2.6. ``itertools.chain.from_iterable(iterable)`` takes a single iterable that should return other iterables. :func:`chain` will @@ -1642,6 +1744,12 @@ complete list of changes, or look through the CVS logs for all the details. .. Patch #1393667 + The :func:`post_mortem` function, used to enter debugging of a + traceback, will now use the traceback returned by :func:`sys.exc_info` + if no traceback is supplied. (Contributed by Facundo Batista.) + + .. Patch #1106316 + * The :mod:`pickletools` module now has an :func:`optimize` function that takes a string containing a pickle and removes some unused opcodes, returning a shorter pickle that contains the same data structure. @@ -1720,6 +1828,8 @@ complete list of changes, or look through the CVS logs for all the details. .. Patch 1657 + .. XXX + * The :mod:`sets` module has been deprecated; it's better to use the built-in :class:`set` and :class:`frozenset` types. @@ -1791,9 +1901,12 @@ complete list of changes, or look through the CVS logs for all the details. * The base classes in the :mod:`SocketServer` module now support calling a :meth:`handle_timeout` method after a span of inactivity specified by the server's :attr:`timeout` attribute. (Contributed - by Michael Pomraning.) + by Michael Pomraning.) The :meth:`serve_forever` method + now takes an optional poll interval measured in seconds, + controlling how often the server will check for a shutdown request. + (Contributed by Pedro Werneck and Jeffrey Yasskin.) - .. Patch #742598 + .. Patch #742598, #1193577 * The :mod:`struct` module now supports the C99 :ctype:`_Bool` type, using the format character ``'?'``. @@ -2069,6 +2182,19 @@ Changes to Python's build process and to the C API include: .. Patch 1551895 +* Python's use of the C stdio library is now thread-safe, or at least + as thread-safe as the underlying library is. A long-standing potential + bug occurred if one thread closed a file object while another thread + was reading from or writing to the object. In 2.6 file objects + have a reference count, manipulated by the + :cfunc:`PyFile_IncUseCount` and :cfunc:`PyFile_DecUseCount` + functions. File objects can't be closed unless the reference count + is zero. :cfunc:`PyFile_IncUseCount` should be called while the GIL + is still held, before carrying out an I/O operation using the + ``FILE *`` pointer, and :cfunc:`PyFile_DecUseCount` should be called + immediately after the GIL is re-acquired. + (Contributed by Antoine Pitrou and Gregory P. Smith.) + * Several functions return information about the platform's floating-point support. :cfunc:`PyFloat_GetMax` returns the maximum representable floating point value, @@ -2089,6 +2215,13 @@ Changes to Python's build process and to the C API include: .. Issue 1635 +* Many C extensions define their own little macro for adding + integers and strings to the module's dictionary in the + ``init*`` function. Python 2.6 finally defines standard macros + for adding values to a module, :cmacro:`PyModule_AddStringMacro` + and :cmacro:`PyModule_AddIntMacro()`. (Contributed by + Christian Heimes.) + * Some macros were renamed in both 3.0 and 2.6 to make it clearer that they are macros, not functions. :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`, @@ -2112,6 +2245,13 @@ Changes to Python's build process and to the C API include: ``numfree``, and a macro :cmacro:`Py<typename>_MAXFREELIST` is always defined. +* A new Makefile target, "make check", prepares the Python source tree + for making a patch: it fixes trailing whitespace in all modified + ``.py`` files, checks whether the documentation has been changed, + and reports whether the :file:`Misc/ACKS` and :file:`Misc/NEWS` files + have been updated. + (Contributed by Brett Cannon.) + .. ====================================================================== @@ -2140,6 +2280,13 @@ Port-Specific Changes: Windows module now support the context protocol, so they can be used in :keyword:`with` statements. (Contributed by Christian Heimes.) + :mod:`_winreg` also has better support for x64 systems, + exposing the :func:`DisableReflectionKey`, :func:`EnableReflectionKey`, + and :func:`QueryReflectionKey` functions, which enable and disable + registry reflection for 32-bit processes running on 64-bit systems. + + .. Patch 1753245 + * The new default compiler on Windows is Visual Studio 2008 (VS 9.0). The build directories for Visual Studio 2003 (VS7.1) and 2005 (VS8.0) were moved into the PC/ directory. The new PCbuild directory supports @@ -2237,5 +2384,5 @@ Acknowledgements ================ The author would like to thank the following people for offering suggestions, -corrections and assistance with various drafts of this article: . +corrections and assistance with various drafts of this article: Jim Jewett. |