mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
svn+ssh://pythondev@svn.python.org/python/trunk ........ r53954 | jeremy.hylton | 2007-02-26 10:41:18 -0800 (Mon, 26 Feb 2007) | 10 lines Do not copy free variables to locals in class namespaces. Fixes bug 1569356, but at the cost of a minor incompatibility in locals(). Add test that verifies that the class namespace is not polluted. Also clarify the behavior in the library docs. Along the way, cleaned up the dict_to_map and map_to_dict implementations and added some comments that explain what they do. ........ r53955 | jeremy.hylton | 2007-02-26 11:00:20 -0800 (Mon, 26 Feb 2007) | 2 lines Fix assertion. ........ r53969 | neal.norwitz | 2007-02-26 14:41:45 -0800 (Mon, 26 Feb 2007) | 3 lines When printing an unraisable error, don't print exceptions. before the name. This duplicates the behavior whening normally printing exceptions. ........ r53970 | andrew.kuchling | 2007-02-26 15:02:47 -0800 (Mon, 26 Feb 2007) | 1 line Markup fix ........ r53975 | neal.norwitz | 2007-02-26 15:48:27 -0800 (Mon, 26 Feb 2007) | 3 lines SF #1669182, 2.5 was already fixed. Just assert in 2.6 since string exceptions are gone. ........ r53976 | andrew.kuchling | 2007-02-26 15:54:17 -0800 (Mon, 26 Feb 2007) | 1 line Add some items ........ r53981 | jeremy.hylton | 2007-02-26 17:01:59 -0800 (Mon, 26 Feb 2007) | 4 lines Fix long-standing bug in name mangling for package imports Reported by Mike Verdone. ........ r53993 | jeremy.hylton | 2007-02-27 08:00:06 -0800 (Tue, 27 Feb 2007) | 2 lines tabify ........ r53994 | jeremy.hylton | 2007-02-27 08:13:23 -0800 (Tue, 27 Feb 2007) | 5 lines tabify Note that ast.c still has a mix of tabs and spaces, because it attempts to use four-space indents for more of the new code. ........ r53996 | jeremy.hylton | 2007-02-27 09:24:48 -0800 (Tue, 27 Feb 2007) | 2 lines whitespace normalization ........ r53997 | jeremy.hylton | 2007-02-27 10:29:45 -0800 (Tue, 27 Feb 2007) | 24 lines Add checking for a number of metaclass error conditions. We add some new rules that are required for preserving internal invariants of types. 1. If type (or a subclass of type) appears in bases, it must appear before any non-type bases. If a non-type base (like a regular new-style class) occurred first, it could trick type into allocating the new class an __dict__ which must be impossible. 2. There are several checks that are made of bases when creating a type. Those checks are now repeated when assigning to __bases__. We also add the restriction that assignment to __bases__ may not change the metaclass of the type. Add new tests for these cases and for a few other oddball errors that were no previously tested. Remove a crasher test that was fixed. Also some internal refactoring: Extract the code to find the most derived metaclass of a type and its bases. It is now needed in two places. Rewrite the TypeError checks in test_descr to use doctest. The tests now clearly show what exception they expect to see. ........ r53998 | jeremy.hylton | 2007-02-27 10:33:31 -0800 (Tue, 27 Feb 2007) | 2 lines Add news about changes to metaclasses and __bases__ error checking. ........ r54016 | armin.rigo | 2007-02-28 01:25:29 -0800 (Wed, 28 Feb 2007) | 3 lines Modify the segfaulting example to show why r53997 is not a solution to it. ........ r54022 | brett.cannon | 2007-02-28 10:15:00 -0800 (Wed, 28 Feb 2007) | 2 lines Add a test for instantiating SyntaxError with no arguments. ........ r54026 | raymond.hettinger | 2007-02-28 10:27:41 -0800 (Wed, 28 Feb 2007) | 1 line Docstring nit. ........ r54033 | raymond.hettinger | 2007-02-28 10:37:52 -0800 (Wed, 28 Feb 2007) | 1 line Prepare collections module for pure python code entries. ........ r54053 | raymond.hettinger | 2007-02-28 22:16:43 -0800 (Wed, 28 Feb 2007) | 1 line Add collections.NamedTuple ........ r54054 | neal.norwitz | 2007-02-28 23:04:41 -0800 (Wed, 28 Feb 2007) | 1 line Add Pat and Eric for work on PEP 3101 in the sandbox ........ r54061 | andrew.kuchling | 2007-03-01 06:36:12 -0800 (Thu, 01 Mar 2007) | 1 line Add NamedTuple ........ r54080 | georg.brandl | 2007-03-02 06:37:12 -0800 (Fri, 02 Mar 2007) | 2 lines Bug #1628895: some better tries to find HTML documentation in pydoc. ........ r54086 | raymond.hettinger | 2007-03-02 11:20:46 -0800 (Fri, 02 Mar 2007) | 1 line Fix embarrassing typo and fix constantification of None ........ r54088 | georg.brandl | 2007-03-02 12:30:14 -0800 (Fri, 02 Mar 2007) | 2 lines Bugs #1668032, #1668036, #1669304: clarify behavior of PyMem_Realloc and _Resize. ........ r54114 | georg.brandl | 2007-03-04 09:18:54 -0800 (Sun, 04 Mar 2007) | 2 lines Fix a bug in test_dict and test_userdict, found at the PyPy sprint. ........ r54124 | skip.montanaro | 2007-03-04 12:52:28 -0800 (Sun, 04 Mar 2007) | 2 lines Teach setup.py how to find Berkeley DB on Macs using MacPorts. ........ r54125 | skip.montanaro | 2007-03-04 12:54:12 -0800 (Sun, 04 Mar 2007) | 1 line note MacPorts/BerkDB change in setup.py ........ r54136 | neal.norwitz | 2007-03-04 23:52:01 -0800 (Sun, 04 Mar 2007) | 1 line Added Pete for 3101 too ........ r54138 | facundo.batista | 2007-03-05 08:31:54 -0800 (Mon, 05 Mar 2007) | 1 line Minor corrections to docs, and an explanation comentary ........ r54139 | georg.brandl | 2007-03-05 14:28:08 -0800 (Mon, 05 Mar 2007) | 3 lines Patch #1674228: when assigning a slice (old-style), check for the sq_ass_slice instead of the sq_slice slot. ........ r54149 | georg.brandl | 2007-03-06 01:33:01 -0800 (Tue, 06 Mar 2007) | 3 lines Nit: a struct field is set to GenericAlloc, not GenericAlloc(). ........ r54150 | georg.brandl | 2007-03-06 02:02:47 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1671450: add a section about subclassing builtin types to the "extending and embedding" tutorial. ........ r54152 | martin.v.loewis | 2007-03-06 02:41:24 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1121142: Implement ZipFile.open. ........ r54154 | georg.brandl | 2007-03-06 03:51:14 -0800 (Tue, 06 Mar 2007) | 2 lines A test case for the fix in #1674228. ........ r54156 | georg.brandl | 2007-03-06 03:52:24 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1672481: fix bug in idlelib.MultiCall. ........ r54159 | georg.brandl | 2007-03-06 04:17:50 -0800 (Tue, 06 Mar 2007) | 1 line Bug #1674503: close the file opened by execfile() in an error condition. ........ r54160 | georg.brandl | 2007-03-06 05:32:52 -0800 (Tue, 06 Mar 2007) | 3 lines Fix another reincarnation of bug #1576657 in defaultdict. ........ r54162 | georg.brandl | 2007-03-06 05:35:00 -0800 (Tue, 06 Mar 2007) | 2 lines A test case for the defaultdict KeyError bug. ........ r54164 | georg.brandl | 2007-03-06 05:37:45 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1663234: you can now run doctest on test files and modules using "python -m doctest [-v] filename ...". ........ r54165 | martin.v.loewis | 2007-03-06 06:43:00 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #912410: Replace HTML entity references for attribute values in HTMLParser. ........ r54166 | skip.montanaro | 2007-03-06 07:41:38 -0800 (Tue, 06 Mar 2007) | 1 line patch 1673619 - identify extension modules which cannot be built ........ r54167 | guido.van.rossum | 2007-03-06 07:50:01 -0800 (Tue, 06 Mar 2007) | 5 lines Patch #1646728: datetime.fromtimestamp fails with negative fractional times. With unittest. Somebody please backport to 2.5. ........ r54169 | georg.brandl | 2007-03-06 09:49:14 -0800 (Tue, 06 Mar 2007) | 2 lines Fix cmp vs. key argument for list.sort. ........ r54170 | georg.brandl | 2007-03-06 10:21:32 -0800 (Tue, 06 Mar 2007) | 2 lines Small nit, found by Neal. ........ r54171 | georg.brandl | 2007-03-06 10:29:58 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1602128: clarify that richcmp methods can return NotImplemented and should return True or False otherwise. ........ r54173 | georg.brandl | 2007-03-06 10:41:12 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1638879: don't accept strings with embedded NUL bytes in long(). ........ r54175 | georg.brandl | 2007-03-06 10:47:31 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1673121: update README wrt. OSX default shell. ........ r54177 | georg.brandl | 2007-03-06 10:59:11 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1654417: make operator.{get,set,del}slice use the full range of Py_ssize_t. ........ r54180 | walter.doerwald | 2007-03-06 12:38:57 -0800 (Tue, 06 Mar 2007) | 4 lines Patch for bug #1633621: if curses.resizeterm() or curses.resize_term() is called, update _curses.LINES, _curses.COLS, curses.LINES and curses.COLS. ........ r54182 | walter.doerwald | 2007-03-06 13:15:24 -0800 (Tue, 06 Mar 2007) | 2 lines Document change to curses. ........ r54188 | georg.brandl | 2007-03-06 16:34:46 -0800 (Tue, 06 Mar 2007) | 5 lines Variant of patch #697613: don't exit the interpreter on a SystemExit exception if the -i command line option or PYTHONINSPECT environment variable is given, but break into the interactive interpreter just like on other exceptions or normal program exit. (backport) ........ r54189 | georg.brandl | 2007-03-06 16:40:28 -0800 (Tue, 06 Mar 2007) | 4 lines Patch #703779: unset __file__ in __main__ after running a file. This makes the filenames the warning module prints much more sensible when a PYTHONSTARTUP file is used. ........ r54192 | george.yoshida | 2007-03-06 20:21:18 -0800 (Tue, 06 Mar 2007) | 2 lines add versionadded info ........ r54195 | georg.brandl | 2007-03-06 23:39:06 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #812285: allow multiple auth schemes in AbstractBasicAuthHandler. ........ r54197 | georg.brandl | 2007-03-07 00:31:51 -0800 (Wed, 07 Mar 2007) | 3 lines Patch #1001604: glob.glob() now returns unicode filenames if it was given a unicode argument and os.listdir() returns unicode filenames. ........ r54199 | georg.brandl | 2007-03-07 01:09:40 -0800 (Wed, 07 Mar 2007) | 3 lines Patches #1550273, #1550272: fix a few bugs in unittest and add a comprehensive test suite for the module. ........ r54201 | georg.brandl | 2007-03-07 01:21:06 -0800 (Wed, 07 Mar 2007) | 3 lines Patch #787789: allow to pass custom TestRunner instances to unittest's main() function. ........ r54202 | georg.brandl | 2007-03-07 01:34:45 -0800 (Wed, 07 Mar 2007) | 2 lines Patch #1669331: clarify shutil.copyfileobj() behavior wrt. file position. ........ r54204 | martin.v.loewis | 2007-03-07 03:04:33 -0800 (Wed, 07 Mar 2007) | 2 lines Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', ''). ........ r54206 | georg.brandl | 2007-03-07 03:37:42 -0800 (Wed, 07 Mar 2007) | 2 lines Patch #1675471: convert test_pty to unittest. ........ r54207 | georg.brandl | 2007-03-07 03:54:49 -0800 (Wed, 07 Mar 2007) | 4 lines Add some sanity checks to unittest.TestSuite's addTest(s) methods. Fixes #878275. ........ r54209 | guido.van.rossum | 2007-03-07 07:16:29 -0800 (Wed, 07 Mar 2007) | 3 lines Windows doesn't support negative timestamps. Skip the tests involving them if os.name == "nt". ........ r54219 | martin.v.loewis | 2007-03-08 05:42:43 -0800 (Thu, 08 Mar 2007) | 2 lines Add missing ) in parenthical remark. ........ r54220 | georg.brandl | 2007-03-08 09:49:06 -0800 (Thu, 08 Mar 2007) | 2 lines Fix #1676656: \em is different from \emph... ........ r54222 | georg.brandl | 2007-03-08 10:37:31 -0800 (Thu, 08 Mar 2007) | 2 lines Add a NEWS entry for rev. 54207,8. ........ r54225 | raymond.hettinger | 2007-03-08 11:24:27 -0800 (Thu, 08 Mar 2007) | 1 line SF 1676321: empty() returned wrong result ........ r54227 | collin.winter | 2007-03-08 11:58:14 -0800 (Thu, 08 Mar 2007) | 1 line Backported r54226 from p3yk: Move test_unittest, test_doctest and test_doctest2 higher up in the testing order. ........ r54230 | raymond.hettinger | 2007-03-08 13:33:47 -0800 (Thu, 08 Mar 2007) | 1 line SF #1637850: make_table in difflib did not work with unicode ........ r54232 | collin.winter | 2007-03-08 14:16:25 -0800 (Thu, 08 Mar 2007) | 1 line Patch #1668482: don't use '-' in mkstemp ........ r54233 | brett.cannon | 2007-03-08 15:58:11 -0800 (Thu, 08 Mar 2007) | 10 lines Introduce test.test_support.TransientResource. It's a context manager to surround calls to resources that may or may not be available. Specifying the expected exception and attributes to be raised if the resource is not available prevents overly broad catching of exceptions. This is meant to help suppress spurious failures by raising test.test_support.ResourceDenied if the exception matches. It would probably be good to go through the various network tests and surround the calls to catch connection timeouts (as done with test_socket_ssl in this commit). ........ r54234 | collin.winter | 2007-03-08 19:15:56 -0800 (Thu, 08 Mar 2007) | 1 line Patch #1481079: Support of HTTP_REFERER in CGIHTTPServer.py ........ r54235 | collin.winter | 2007-03-08 19:26:32 -0800 (Thu, 08 Mar 2007) | 1 line Add NEWS item for patch #1481079 (r54234). ........ r54237 | neal.norwitz | 2007-03-08 21:59:01 -0800 (Thu, 08 Mar 2007) | 1 line Fix SF #1676971, Complex OverflowError has a typo ........ r54239 | georg.brandl | 2007-03-09 04:58:41 -0800 (Fri, 09 Mar 2007) | 2 lines Typo. ........ r54240 | martin.v.loewis | 2007-03-09 07:35:55 -0800 (Fri, 09 Mar 2007) | 2 lines Patch #957003: Implement smtplib.LMTP. ........ r54243 | collin.winter | 2007-03-09 10:09:10 -0800 (Fri, 09 Mar 2007) | 2 lines Bug #1629566: clarify the docs on the return values of parsedate() and parsedate_tz() in email.utils and rfc822. ........ r54244 | thomas.heller | 2007-03-09 11:21:28 -0800 (Fri, 09 Mar 2007) | 3 lines Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0) returned string up to the first NUL character. ........ r54245 | martin.v.loewis | 2007-03-09 11:36:01 -0800 (Fri, 09 Mar 2007) | 2 lines Add Ziga Seilnacht. ........ r54247 | collin.winter | 2007-03-09 12:33:07 -0800 (Fri, 09 Mar 2007) | 2 lines Patch #1491866: change the complex() constructor to allow parthensized forms. This means complex(repr(x)) now works instead of raising a ValueError. ........ r54248 | thomas.heller | 2007-03-09 12:39:22 -0800 (Fri, 09 Mar 2007) | 7 lines Bug #1651235: When a tuple was passed to a ctypes function call, Python would crash instead of raising an error. The crash was caused by a section of code that should have been removed long ago, at that time ctypes had other ways to pass parameters to function calls. ........ r54250 | collin.winter | 2007-03-09 15:30:39 -0800 (Fri, 09 Mar 2007) | 1 line Hashing simplification pointed out by Thomas Wouters. ........ r54252 | collin.winter | 2007-03-09 18:23:40 -0800 (Fri, 09 Mar 2007) | 5 lines * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink. * Drop safe_remove() in favor of test_support.unlink(). * Fix the indentation of test_samefile so that it runs. ........ r54253 | collin.winter | 2007-03-09 18:51:26 -0800 (Fri, 09 Mar 2007) | 3 lines Bug #1531963: Make SocketServer.TCPServer's server_address always be equal to calling getsockname() on the server's socket. Will backport. ........ r54254 | neal.norwitz | 2007-03-09 19:19:18 -0800 (Fri, 09 Mar 2007) | 4 lines Simplify a little by handling the TCP case first. Update to use predominant style of spaces around = in args list and print to stderr if debugging. ........ r54256 | collin.winter | 2007-03-09 19:35:34 -0800 (Fri, 09 Mar 2007) | 1 line Add proper attribution for a bug fix. ........ r54257 | georg.brandl | 2007-03-09 23:38:14 -0800 (Fri, 09 Mar 2007) | 2 lines Typos. ........ r54260 | collin.winter | 2007-03-10 06:33:32 -0800 (Sat, 10 Mar 2007) | 1 line Convert an assert to a raise so it works even in the presence of -O. ........ r54262 | collin.winter | 2007-03-10 06:41:48 -0800 (Sat, 10 Mar 2007) | 2 lines Patch #1599845: Add an option to disable the implicit calls to server_bind() and server_activate() in the constructors for TCPServer, SimpleXMLRPCServer and DocXMLRPCServer. ........ r54268 | georg.brandl | 2007-03-11 00:28:46 -0800 (Sun, 11 Mar 2007) | 2 lines Add missing "return" statements in exception handler. ........ r54270 | ziga.seilnacht | 2007-03-11 08:54:54 -0700 (Sun, 11 Mar 2007) | 3 lines Patch #1675981: remove unreachable code from type.__new__() method. __dict__ and __weakref__ are removed from the slots tuple earlier in the code, in the loop that mangles slot names. Will backport. ........ r54271 | collin.winter | 2007-03-11 09:00:20 -0700 (Sun, 11 Mar 2007) | 3 lines Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number. Will backport. ........ r54274 | vinay.sajip | 2007-03-11 11:32:07 -0700 (Sun, 11 Mar 2007) | 1 line Fix resource leak reported in SF #1516995. ........ r54278 | collin.winter | 2007-03-11 18:55:54 -0700 (Sun, 11 Mar 2007) | 4 lines Patch #1678662: ftp.python.org does not exist. So the testcode in urllib.py must use a more stable FTP. Will backport. ........ r54280 | barry.warsaw | 2007-03-11 20:20:01 -0700 (Sun, 11 Mar 2007) | 8 lines Tokio Kikuchi's fix for SF bug #1629369; folding whitespace allowed in the display name of an email address, e.g. Foo \tBar <foo@example.com> Test case added by Barry. ........ r54282 | skip.montanaro | 2007-03-11 20:30:50 -0700 (Sun, 11 Mar 2007) | 4 lines Sane humans would call these invalid tests, but Andrew McNamara pointed out that given the inputs in these tests Excel does indeed produce the output these tests expect. Document that for future confused folks. ........ r54283 | martin.v.loewis | 2007-03-12 03:50:39 -0700 (Mon, 12 Mar 2007) | 2 lines Bug #1675511: Use -Kpic instead of -xcode=pic32 on Solaris/x86. ........ r54285 | martin.v.loewis | 2007-03-12 04:01:10 -0700 (Mon, 12 Mar 2007) | 2 lines Patch #1677862: Require a space or tab after import in .pth files. ........ r54287 | georg.brandl | 2007-03-12 06:17:36 -0700 (Mon, 12 Mar 2007) | 8 lines Backport from Py3k branch: Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir. Had to change a few bits of the patch because classobjs and __methods__ are still in Py2.6. ........ r54288 | georg.brandl | 2007-03-12 07:30:05 -0700 (Mon, 12 Mar 2007) | 3 lines Bug #1678647: write a newline after printing an exception in any case, even when converting the value to a string failed. ........ r54290 | collin.winter | 2007-03-12 08:57:19 -0700 (Mon, 12 Mar 2007) | 1 line Patch #1678088: convert test_operations to use unittest, fold the result into test_dict. ........ r54291 | collin.winter | 2007-03-12 09:11:39 -0700 (Mon, 12 Mar 2007) | 3 lines Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167. Will backport. ........ r54292 | georg.brandl | 2007-03-12 09:15:09 -0700 (Mon, 12 Mar 2007) | 2 lines Typo fix. ........ r54295 | collin.winter | 2007-03-12 10:24:07 -0700 (Mon, 12 Mar 2007) | 1 line Patch #1670993: Refactor test_threadedtempfile.py to use unittest. ........ r54296 | tim.peters | 2007-03-12 11:07:52 -0700 (Mon, 12 Mar 2007) | 2 lines Whitespace normalization. ........ r54297 | tim.peters | 2007-03-12 11:09:22 -0700 (Mon, 12 Mar 2007) | 2 lines Set missing svn:eol-style property on text files. ........ r54315 | brett.cannon | 2007-03-12 19:34:09 -0700 (Mon, 12 Mar 2007) | 8 lines Add test.test_support.transient_internet . Returns a context manager that nests test.test_support.TransientResource context managers that capture exceptions raised when the Internet connection is flaky. Initially using in test_socket_ssl but should probably be expanded to cover any test that should not raise the captured exceptions if the Internet connection works. ........ r54316 | brett.cannon | 2007-03-12 20:05:40 -0700 (Mon, 12 Mar 2007) | 2 lines Fix a typo where the variable name was not updated. ........ r54318 | neal.norwitz | 2007-03-12 21:59:58 -0700 (Mon, 12 Mar 2007) | 1 line Add Jerry Seutter for a bunch of his recent patches refactoring tests ........ r54319 | neal.norwitz | 2007-03-12 22:07:14 -0700 (Mon, 12 Mar 2007) | 7 lines Add some other acks for recent checkins: Brian Leair - 922167 Tomer Filiba - 1591665 Jeremy Jones - 1192590 ........ r54321 | neal.norwitz | 2007-03-12 22:31:38 -0700 (Mon, 12 Mar 2007) | 9 lines Fix some style nits: * lines too long * wrong indentation * space after a function name * wrong function name in error string * simplifying some logic Also add an error check to PyDict_SetItemString. ........ r54322 | georg.brandl | 2007-03-13 00:23:16 -0700 (Tue, 13 Mar 2007) | 2 lines Typo and grammar fixes. ........ r54323 | georg.brandl | 2007-03-13 00:50:57 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1679379: add documentation for fnmatch.translate(). ........ r54325 | georg.brandl | 2007-03-13 00:57:51 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1642844: comments to clarify the complexobject constructor. ........ r54326 | georg.brandl | 2007-03-13 01:14:27 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1668100: urllib2 now correctly raises URLError instead of OSError if accessing a local file via the file:// protocol fails. ........ r54327 | georg.brandl | 2007-03-13 02:32:11 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1635454: the csv.DictWriter class now includes the offending field names in its exception message if you try to write a record with a dictionary containing fields not in the CSV field names list. ........ r54328 | georg.brandl | 2007-03-13 02:41:31 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1555098: use str.join() instead of repeated string concatenation in robotparser. ........ r54329 | georg.brandl | 2007-03-13 03:06:48 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to pydoc's help keywords. ........ r54331 | georg.brandl | 2007-03-13 03:19:22 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1569798: fix a bug in distutils when building Python from a directory within sys.exec_prefix. ........ r54333 | martin.v.loewis | 2007-03-13 03:24:00 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1449244: Support Unicode strings in email.message.Message.{set_charset,get_content_charset}. Will backport. ........ r54335 | lars.gustaebel | 2007-03-13 03:47:19 -0700 (Tue, 13 Mar 2007) | 34 lines This is the implementation of POSIX.1-2001 (pax) format read/write support. The TarInfo class now contains all necessary logic to process and create tar header data which has been moved there from the TarFile class. The fromtarfile() method was added. The new path and linkpath properties are aliases for the name and linkname attributes in correspondence to the pax naming scheme. The TarFile constructor and classmethods now accept a number of keyword arguments which could only be set as attributes before (e.g. dereference, ignore_zeros). The encoding and pax_headers arguments were added for pax support. There is a new tarinfo keyword argument that allows using subclassed TarInfo objects in TarFile. The boolean TarFile.posix attribute is deprecated, because now three tar formats are supported. Instead, the desired format for writing is specified using the constants USTAR_FORMAT, GNU_FORMAT and PAX_FORMAT as the format keyword argument. This change affects TarInfo.tobuf() as well. The test suite has been heavily reorganized and partially rewritten. A new testtar.tar was added that contains sample data in many formats from 4 different tar programs. Some bugs and quirks that also have been fixed: Directory names do no longer have a trailing slash in TarInfo.name or TarFile.getnames(). Adding the same file twice does not create a hardlink file member. The TarFile constructor does no longer need a name argument. The TarFile._mode attribute was renamed to mode and contains either 'r', 'w' or 'a'. ........ r54336 | georg.brandl | 2007-03-13 05:34:25 -0700 (Tue, 13 Mar 2007) | 3 lines Bug #1622896: fix a rare corner case where the bz2 module raised an error in spite of a succesful compression. ........ r54338 | lars.gustaebel | 2007-03-13 08:47:07 -0700 (Tue, 13 Mar 2007) | 3 lines Quick fix for tests that fail on systems with an encoding other than 'iso8859-1'. ........ r54339 | georg.brandl | 2007-03-13 10:43:32 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1603688: ConfigParser.SafeConfigParser now checks values that are set for invalid interpolation sequences that would lead to errors on reading back those values. ........ r54341 | georg.brandl | 2007-03-13 11:15:41 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1581073: add a flag to textwrap that prevents the dropping of whitespace while wrapping. ........ r54343 | georg.brandl | 2007-03-13 11:24:40 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1605192: list allowed states in error messages for imaplib. ........ r54344 | georg.brandl | 2007-03-13 11:31:49 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1537850: tempfile.NamedTemporaryFile now has a "delete" parameter which can be set to False to prevent the default delete-on-close behavior. ........ r54345 | collin.winter | 2007-03-13 11:53:04 -0700 (Tue, 13 Mar 2007) | 9 lines Add acks for recent patch checkins: Arvin Schnell - 1668482 S?\195?\169bastien Martini - 1481079 Heiko Wundram - 1491866 Damon Kohler - 1545011 Peter Parente - 1599845 Bjorn Lindqvist - 1678662 ........ r54346 | georg.brandl | 2007-03-13 12:00:36 -0700 (Tue, 13 Mar 2007) | 2 lines Acks for recent patches. ........ r54347 | georg.brandl | 2007-03-13 12:18:18 -0700 (Tue, 13 Mar 2007) | 3 lines Fix a tab. ........ r54348 | georg.brandl | 2007-03-13 12:32:21 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1533909: the timeit module now accepts callables in addition to strings for the code to time and the setup code. Also added two convenience functions for instantiating a Timer and calling its methods. ........ r54352 | georg.brandl | 2007-03-13 13:02:57 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1530482: add pydoc.render_doc() which returns the documentation for a thing instead of paging it to stdout, which pydoc.doc() does. ........ r54357 | thomas.heller | 2007-03-13 13:42:52 -0700 (Tue, 13 Mar 2007) | 1 line Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl. ........ r54358 | georg.brandl | 2007-03-13 13:46:32 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1444529: the builtin compile() now accepts keyword arguments. (backport) ........ r54359 | thomas.heller | 2007-03-13 14:01:39 -0700 (Tue, 13 Mar 2007) | 1 line Add versionadded marker for ctypes.c_bool. ........ r54360 | georg.brandl | 2007-03-13 14:08:15 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1393667: pdb now has a "run" command which restarts the debugged Python program, optionally with different arguments. ........ r54361 | georg.brandl | 2007-03-13 14:32:01 -0700 (Tue, 13 Mar 2007) | 3 lines Deprecate commands.getstatus(). ........ r54362 | georg.brandl | 2007-03-13 14:32:56 -0700 (Tue, 13 Mar 2007) | 2 lines NEWS entry for getstatus() deprecation. ........ r54363 | georg.brandl | 2007-03-13 14:58:44 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1429539: pdb now correctly initializes the __main__ module for the debugged script, which means that imports from __main__ work correctly now. ........ r54364 | georg.brandl | 2007-03-13 15:07:36 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #957650: "%var%" environment variable references are now properly expanded in ntpath.expandvars(), also "~user" home directory references are recognized and handled on Windows. ........ r54365 | georg.brandl | 2007-03-13 15:16:30 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1194449: correctly detect unbound methods in pydoc. ........ r54367 | georg.brandl | 2007-03-13 15:49:43 -0700 (Tue, 13 Mar 2007) | 5 lines Patch #1185447: binascii.b2a_qp() now correctly quotes binary characters with ASCII value less than 32. Also, it correctly quotes dots only if they occur on a single line, as opposed to the previous behavior of quoting dots if they are the second character of any line. ........ r54368 | collin.winter | 2007-03-13 16:02:15 -0700 (Tue, 13 Mar 2007) | 1 line Inline PyImport_GetModulesReloading(). ........ r54371 | barry.warsaw | 2007-03-13 21:59:50 -0700 (Tue, 13 Mar 2007) | 6 lines SF bug #1582282; decode_header() incorrectly splits not-conformant RFC 2047-like headers where there is no whitespace between encoded words. This fix changes the matching regexp to include a trailing lookahead assertion that the closing ?= must be followed by whitespace, newline, or end-of-string. This also changes the regexp to add the MULTILINE flag. ........ r54372 | gregory.p.smith | 2007-03-14 00:17:40 -0700 (Wed, 14 Mar 2007) | 2 lines correct order and names of the less often used keyword parameters. ........ r54373 | gregory.p.smith | 2007-03-14 00:19:50 -0700 (Wed, 14 Mar 2007) | 5 lines Its time to stop listing (Unix, Windows) when we really mean "everything but Mac OS 9" now that nobody is likely to use Python on Mac OS 9 and most of the (Mac) platform items are all OS X special API specific since OS X is unixy enough for these modules to be available out of the box. ........ r54376 | georg.brandl | 2007-03-14 01:27:52 -0700 (Wed, 14 Mar 2007) | 4 lines Bug #767111: fix long-standing bug in urllib which caused an AttributeError instead of an IOError when the server's response didn't contain a valid HTTP status line. ........ r54378 | ziga.seilnacht | 2007-03-14 05:24:09 -0700 (Wed, 14 Mar 2007) | 4 lines Patch #1680015: Don't modify __slots__ tuple if it contains an unicode name. Remove a reference leak that happened if the name could not be converted to string. Will backport. ........ r54386 | martin.v.loewis | 2007-03-14 13:02:31 -0700 (Wed, 14 Mar 2007) | 3 lines Patch #1559413: Fix test_cmd_line if sys.executable contains a space. Will backport. ........ r54389 | brett.cannon | 2007-03-14 14:40:13 -0700 (Wed, 14 Mar 2007) | 3 lines Note how test_socket_ssl has various exceptions that deal with a flaky Net connection are silenced. ........ r54390 | brett.cannon | 2007-03-14 14:44:15 -0700 (Wed, 14 Mar 2007) | 2 lines Raise ResourceDenied in test_urllib2net when the Net connection goes bad. ........ r54391 | neal.norwitz | 2007-03-14 21:41:20 -0700 (Wed, 14 Mar 2007) | 1 line Wrap a long line and fix a typo (is -> if) ........ r54392 | georg.brandl | 2007-03-15 00:38:14 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1680978: consistently use "alive" instead of "active" in the thread lib doc. ........ r54394 | georg.brandl | 2007-03-15 00:41:30 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1681153: the wave module now closes a file object it opened if initialization failed. ........ r54397 | ziga.seilnacht | 2007-03-15 04:44:55 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1462488: prevent a segfault in object_reduce_ex() by splitting the implementation for __reduce__ and __reduce_ex__ into two separate functions. Fixes bug #931877. Will backport. ........ r54404 | collin.winter | 2007-03-15 21:11:30 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements. Will backport. ........ r54406 | georg.brandl | 2007-03-16 00:55:09 -0700 (Fri, 16 Mar 2007) | 5 lines Bug #1681228: the webbrowser module now correctly uses the default GNOME or KDE browser, depending on whether there is a session of one of those present. Also, it tries the Windows default browser before trying Mozilla variants. (backport) ........ r54407 | georg.brandl | 2007-03-16 01:22:40 -0700 (Fri, 16 Mar 2007) | 4 lines Patch #1273829: os.walk() now has a "followlinks" parameter. If set to True (which is not the default), it visits symlinks pointing to directories. ........ r54408 | georg.brandl | 2007-03-16 01:24:21 -0700 (Fri, 16 Mar 2007) | 2 lines Add \versionadded tag. ........ r54409 | georg.brandl | 2007-03-16 01:33:47 -0700 (Fri, 16 Mar 2007) | 2 lines RFE #1670167: fix in isinstance() docs. ........ r54412 | ziga.seilnacht | 2007-03-16 04:59:38 -0700 (Fri, 16 Mar 2007) | 3 lines Patch #1623563: allow __class__ assignment for classes with __slots__. The old and the new class are still required to have the same slot names, but the order in which they are specified is not relevant. ........ r54413 | ziga.seilnacht | 2007-03-16 05:11:11 -0700 (Fri, 16 Mar 2007) | 2 lines Whitespace cleanup. Also remove the empty lines from the previous check in. ........ r54414 | jeremy.hylton | 2007-03-16 07:49:11 -0700 (Fri, 16 Mar 2007) | 2 lines Remove warning: funcion declaration isn't a prototype ........ r54415 | jeremy.hylton | 2007-03-16 08:59:47 -0700 (Fri, 16 Mar 2007) | 11 lines Clean up formatting of this file. The file should now follow PEP 7, except that it uses 4 space indents (in the style of Py3k). This particular code would be really hard to read with the regular tab idents. Other changes: - reflow long lines - change multi-line conditionals to have test at end of line ........ r54417 | collin.winter | 2007-03-16 14:13:35 -0700 (Fri, 16 Mar 2007) | 1 line Patch #1676994: Refactor test_popen2 to use unittest. ........ r54418 | collin.winter | 2007-03-16 14:15:35 -0700 (Fri, 16 Mar 2007) | 1 line Remove test/output/test_popen2 (missed in r54417). ........ r54419 | collin.winter | 2007-03-16 15:16:08 -0700 (Fri, 16 Mar 2007) | 1 line Patch 1339796: add a relpath() function to os.path. ........ r54421 | georg.brandl | 2007-03-17 09:08:45 -0700 (Sat, 17 Mar 2007) | 5 lines Patch #1675423: PyComplex_AsCComplex() now tries to convert an object to complex using its __complex__() method before falling back to the __float__() method. Therefore, the functions in the cmath module now can operate on objects that define a __complex__() method. (backport) ........ r54423 | gregory.p.smith | 2007-03-17 15:33:35 -0700 (Sat, 17 Mar 2007) | 2 lines move note to the correct section ........ r54426 | georg.brandl | 2007-03-18 01:25:00 -0700 (Sun, 18 Mar 2007) | 2 lines Patch #1682878: the new socket methods are recv_into and recvfrom_into, not *_buf. ........ r54432 | georg.brandl | 2007-03-18 11:28:25 -0700 (Sun, 18 Mar 2007) | 2 lines Patch #1678339: test case for bug in difflib. ........ r54439 | collin.winter | 2007-03-19 11:52:08 -0700 (Mon, 19 Mar 2007) | 1 line Patch #1630118: add a SpooledTemporaryFile class to tempfile. ........ r54441 | georg.brandl | 2007-03-19 12:02:48 -0700 (Mon, 19 Mar 2007) | 2 lines Patch #1683328: fixes and enhancements for "unparse" demo. ........ r54456 | neal.norwitz | 2007-03-19 22:07:28 -0700 (Mon, 19 Mar 2007) | 1 line Add some doc that was left out from some change to platform.py ........ r54457 | neal.norwitz | 2007-03-19 22:08:23 -0700 (Mon, 19 Mar 2007) | 1 line Add a comment about 3k migration ........ r54458 | neal.norwitz | 2007-03-19 22:21:21 -0700 (Mon, 19 Mar 2007) | 1 line Get rid of deprecation warning when testing commands.getstatus() ........ r54459 | neal.norwitz | 2007-03-19 22:23:09 -0700 (Mon, 19 Mar 2007) | 4 lines Try backing out 54407 to see if it corrects the problems on the Windows buildbots. This rev was backported, so we will need to keep both branches in sync, pending the outcome of the test after this checkin. ........ r54460 | neal.norwitz | 2007-03-19 23:13:25 -0700 (Mon, 19 Mar 2007) | 1 line Try to make this test more resistant to dropping from previous runs (ie, files that may exist but cause the test to fail). Should be backported (assuming it works :-) ........ r54461 | neal.norwitz | 2007-03-19 23:16:26 -0700 (Mon, 19 Mar 2007) | 1 line Try to make this test more resistant to dropping from previous runs (ie, files that may exist but cause the test to fail). Should be backported (assuming it works :-) ........ r54462 | neal.norwitz | 2007-03-19 23:53:17 -0700 (Mon, 19 Mar 2007) | 5 lines Try to be a little more resilient to errors. This might help the test pass, but my guess is that it won't. I'm guessing that some other test is leaving this file open which means it can't be removed under Windows AFAIK. ........ r54463 | neal.norwitz | 2007-03-20 01:14:57 -0700 (Tue, 20 Mar 2007) | 8 lines Try to get test_urllib to pass on Windows by closing the file. I'm guessing that's the problem. h.getfile() must be called *after* h.getreply() and the fp can be None. I'm not entirely convinced this is the best fix (or even correct). The buildbots will tell us if things improve or not. I don't know if this needs to be backported (assuming it actually works). ........ r54465 | raymond.hettinger | 2007-03-20 14:27:24 -0700 (Tue, 20 Mar 2007) | 1 line Extend work on rev 52962 and 53829 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability. ........ r54468 | georg.brandl | 2007-03-20 16:05:14 -0700 (Tue, 20 Mar 2007) | 2 lines Fix for glob.py if filesystem encoding is None. ........ r54479 | neal.norwitz | 2007-03-20 23:39:48 -0700 (Tue, 20 Mar 2007) | 1 line Remove unused file spotted by Paul Hankin ........ r54480 | georg.brandl | 2007-03-21 02:00:39 -0700 (Wed, 21 Mar 2007) | 3 lines Patch #1682205: a TypeError while unpacking an iterable is no longer masked by a generic one with the message "unpack non-sequence". ........ r54482 | georg.brandl | 2007-03-21 02:10:29 -0700 (Wed, 21 Mar 2007) | 2 lines New test for rev. 54407 which only uses directories under TESTFN. ........ r54483 | georg.brandl | 2007-03-21 02:16:53 -0700 (Wed, 21 Mar 2007) | 2 lines Patch #1684834: document some utility C API functions. ........ r54485 | georg.brandl | 2007-03-21 04:51:25 -0700 (Wed, 21 Mar 2007) | 2 lines Fix #1684254: split BROWSER contents with shlex to avoid displaying 'URL'. ........ r54487 | andrew.kuchling | 2007-03-21 07:32:43 -0700 (Wed, 21 Mar 2007) | 1 line Add comments on maintenance of this file ........ r54489 | andrew.kuchling | 2007-03-21 09:57:32 -0700 (Wed, 21 Mar 2007) | 1 line Fix sentence, and fix typo in example ........ r54490 | andrew.kuchling | 2007-03-21 09:59:20 -0700 (Wed, 21 Mar 2007) | 1 line Put code examples at left margin instead of indenting them ........ r54491 | facundo.batista | 2007-03-21 12:41:24 -0700 (Wed, 21 Mar 2007) | 1 line Minor clarification, saying that blocking means no timeout (from bug #882297) ........ r54492 | ziga.seilnacht | 2007-03-21 13:07:56 -0700 (Wed, 21 Mar 2007) | 2 lines Bug #1675967: re patterns pickled with older Python versions can now be unpickled. Will backport. ........ r54495 | raymond.hettinger | 2007-03-21 13:33:57 -0700 (Wed, 21 Mar 2007) | 1 line Add test and fix for fromkeys() optional argument. ........ r54524 | georg.brandl | 2007-03-22 01:05:45 -0700 (Thu, 22 Mar 2007) | 2 lines Bug #1685704: use -m switch in timeit docs. ........ r54533 | thomas.heller | 2007-03-22 12:44:31 -0700 (Thu, 22 Mar 2007) | 5 lines Back out "Patch #1643874: memory leak in ctypes fixed." The code in this patch leaves no way to give up the ownership of a BSTR instance. ........ r54538 | thomas.heller | 2007-03-22 13:34:37 -0700 (Thu, 22 Mar 2007) | 2 lines Explain the purpose of the b_needsfree flag (forward ported from release25-maint). ........ r54539 | guido.van.rossum | 2007-03-22 21:58:42 -0700 (Thu, 22 Mar 2007) | 12 lines - Bug #1683368: The object.__init__() and object.__new__() methods are now stricter in rejecting excess arguments. The only time when either allows excess arguments is when it is not overridden and the other one is. For backwards compatibility, when both are overridden, it is a deprecation warning (for now; maybe a Py3k warning later). When merging this into 3.0, the warnings should become errors. Note: without the change to string.py, lots of spurious warnings happen. What's going on there? ........ r54540 | neal.norwitz | 2007-03-22 22:17:23 -0700 (Thu, 22 Mar 2007) | 1 line Add Mark Dickinson for SF # 1675423. ........ r54541 | martin.v.loewis | 2007-03-23 03:35:49 -0700 (Fri, 23 Mar 2007) | 3 lines Patch #1686451: Fix return type for PySequence_{Count,Index,Fast_GET_SIZE}. Will backport. ........ r54543 | martin.v.loewis | 2007-03-23 06:27:15 -0700 (Fri, 23 Mar 2007) | 3 lines Bug #978833: Revert r50844, as it broke _socketobject.dup. Will backport. ........ r54545 | guido.van.rossum | 2007-03-23 11:53:03 -0700 (Fri, 23 Mar 2007) | 8 lines Add a type.__init__() method that enforces the same signature as type.__new__(), and then calls object.__init__(cls), just to be anal. This allows us to restore the code in string.py's _TemplateMetaclass that called super(...).__init__(name, bases, dct), which I commented out yesterday since it broke due to the stricter argument checking added to object.__init__(). ........ r54546 | facundo.batista | 2007-03-23 11:54:07 -0700 (Fri, 23 Mar 2007) | 4 lines Added a 'create_connect()' function to socket.py, which creates a connection with an optional timeout, and modified httplib.py to use this function in HTTPConnection. Applies patch 1676823. ........ r54547 | guido.van.rossum | 2007-03-23 12:39:01 -0700 (Fri, 23 Mar 2007) | 2 lines Add note about type.__init__(). ........ r54553 | thomas.heller | 2007-03-23 12:55:27 -0700 (Fri, 23 Mar 2007) | 5 lines Prevent creation (followed by a segfault) of array types when the size overflows the valid Py_ssize_t range. Check return values of PyMem_Malloc. Will backport to release25-maint. ........ r54555 | facundo.batista | 2007-03-23 13:23:08 -0700 (Fri, 23 Mar 2007) | 6 lines Surrounded with try/finally to socket's default timeout setting changes in the tests, so failing one test won't produce strange results in others. Also relaxed the timeout settings in the test (where actually the value didn't mean anything). ........ r54556 | collin.winter | 2007-03-23 15:24:39 -0700 (Fri, 23 Mar 2007) | 1 line Make test_relpath() pass on Windows. ........ r54559 | ziga.seilnacht | 2007-03-24 07:24:26 -0700 (Sat, 24 Mar 2007) | 6 lines Patch #1489771: update syntax rules in Python Reference Manual. Python 2.5 added support for explicit relative import statements and yield expressions, which were missing in the manual. Also fix grammar productions that used the names from the Grammar file, markup that broke the generated grammar.txt, and wrap some lines that broke the pdf output. Will backport. ........ r54565 | georg.brandl | 2007-03-24 15:20:34 -0700 (Sat, 24 Mar 2007) | 2 lines Remove typo accent. ........ r54566 | georg.brandl | 2007-03-24 15:27:56 -0700 (Sat, 24 Mar 2007) | 2 lines Revert accidental change. ........ r54567 | brett.cannon | 2007-03-24 18:32:36 -0700 (Sat, 24 Mar 2007) | 3 lines Change the docs to no longer claim that unittest is preferred over doctest for regression tests. ........ r54568 | facundo.batista | 2007-03-24 18:53:21 -0700 (Sat, 24 Mar 2007) | 4 lines Redone the tests, using the infrastructure already present for threading and socket serving. ........ r54570 | facundo.batista | 2007-03-24 20:20:05 -0700 (Sat, 24 Mar 2007) | 3 lines Closing the HTTP connection after each test, and listening more. ........ r54572 | georg.brandl | 2007-03-25 11:44:35 -0700 (Sun, 25 Mar 2007) | 2 lines Markup fix. ........ r54573 | georg.brandl | 2007-03-25 12:04:55 -0700 (Sun, 25 Mar 2007) | 2 lines Markup fix. ........ r54580 | facundo.batista | 2007-03-26 13:18:31 -0700 (Mon, 26 Mar 2007) | 5 lines Added an optional timeout to FTP class. Also I started a test_ftplib.py file to test the ftp lib (right now I included a basic test, the timeout one, and nothing else). ........ r54581 | georg.brandl | 2007-03-26 13:28:28 -0700 (Mon, 26 Mar 2007) | 2 lines Some nits. ........ r54582 | facundo.batista | 2007-03-26 13:56:09 -0700 (Mon, 26 Mar 2007) | 4 lines Forgot to add the file before the previous commit, here go the ftplib tests. ........ r54585 | facundo.batista | 2007-03-27 11:23:21 -0700 (Tue, 27 Mar 2007) | 5 lines Added an optional timeout to poplib.POP3. Also created a test_poplib.py file with a basic test and the timeout ones. Docs are also updated. ........ r54586 | facundo.batista | 2007-03-27 11:50:29 -0700 (Tue, 27 Mar 2007) | 3 lines The basic test cases of poplib.py. ........ r54594 | facundo.batista | 2007-03-27 20:45:20 -0700 (Tue, 27 Mar 2007) | 4 lines Bug 1688393. Adds a control of negative values in socket.recvfrom, which caused an ugly crash. ........ r54599 | facundo.batista | 2007-03-28 11:25:54 -0700 (Wed, 28 Mar 2007) | 5 lines Added timeout to smtplib (to SMTP and SMTP_SSL). Also created the test_smtplib.py file, with a basic test and the timeout ones. Docs are updated too. ........ r54603 | collin.winter | 2007-03-28 16:34:06 -0700 (Wed, 28 Mar 2007) | 3 lines Consolidate patches #1690164, 1683397, and 1690169, all of which refactor XML-related test suites. The patches are applied together because they use a common output/xmltests file. Thanks to Jerry Seutter for all three patches. ........ r54604 | collin.winter | 2007-03-28 19:28:16 -0700 (Wed, 28 Mar 2007) | 1 line Make test_zipfile clean up its temporary files properly. ........ r54605 | georg.brandl | 2007-03-29 00:41:32 -0700 (Thu, 29 Mar 2007) | 2 lines These are actually methods. ........ r54606 | georg.brandl | 2007-03-29 05:42:07 -0700 (Thu, 29 Mar 2007) | 4 lines In Windows' time.clock(), when QueryPerformanceFrequency() fails, the C lib's clock() is used, but it must be divided by CLOCKS_PER_SEC as for the POSIX implementation (thanks to #pypy). ........ r54608 | facundo.batista | 2007-03-29 11:22:35 -0700 (Thu, 29 Mar 2007) | 5 lines Added timout parameter to telnetlib.Telnet. Also created test_telnetlib.py with a basic test and timeout ones. Docs are also updated. ........ r54613 | facundo.batista | 2007-03-30 06:00:35 -0700 (Fri, 30 Mar 2007) | 4 lines Added the posibility to pass the timeout to FTP.connect, not only when instantiating the class. Docs and tests are updated. ........ r54614 | collin.winter | 2007-03-30 07:01:25 -0700 (Fri, 30 Mar 2007) | 1 line Bug #1688274: add documentation for C-level class objects. ........ r54615 | marc-andre.lemburg | 2007-03-30 08:01:42 -0700 (Fri, 30 Mar 2007) | 4 lines Bump the patch level version of distutils since there were a few bug fixes since the 2.5.0 release. ........ r54617 | georg.brandl | 2007-03-30 08:49:05 -0700 (Fri, 30 Mar 2007) | 2 lines Markup fix. ........ r54618 | georg.brandl | 2007-03-30 10:39:39 -0700 (Fri, 30 Mar 2007) | 2 lines Label name fix. ........ r54619 | georg.brandl | 2007-03-30 10:47:21 -0700 (Fri, 30 Mar 2007) | 2 lines Duplicate label fix. ........ r54620 | georg.brandl | 2007-03-30 10:48:39 -0700 (Fri, 30 Mar 2007) | 2 lines Markup fix. ........ r54623 | andrew.kuchling | 2007-03-30 11:00:15 -0700 (Fri, 30 Mar 2007) | 1 line Add item. (Oops, accidentally checked this in on my branch) ........ r54624 | georg.brandl | 2007-03-30 12:01:38 -0700 (Fri, 30 Mar 2007) | 2 lines Duplicate label fix. ........ r54625 | georg.brandl | 2007-03-30 12:14:02 -0700 (Fri, 30 Mar 2007) | 2 lines Markup fix. ........ r54629 | georg.brandl | 2007-03-31 03:17:31 -0700 (Sat, 31 Mar 2007) | 2 lines repair string literal. ........ r54630 | georg.brandl | 2007-03-31 04:54:58 -0700 (Sat, 31 Mar 2007) | 2 lines Markup fix. ........ r54631 | georg.brandl | 2007-03-31 04:58:36 -0700 (Sat, 31 Mar 2007) | 2 lines Duplicate label fix. ........ r54632 | georg.brandl | 2007-03-31 04:59:54 -0700 (Sat, 31 Mar 2007) | 2 lines Typo fix. ........ r54633 | neal.norwitz | 2007-03-31 11:54:18 -0700 (Sat, 31 Mar 2007) | 1 line Fix method names. Will backport. ........ r54634 | georg.brandl | 2007-03-31 11:56:11 -0700 (Sat, 31 Mar 2007) | 4 lines Bug #1655392: don't add -L/usr/lib/pythonX.Y/config to the LDFLAGS returned by python-config if Python was built with --enable-shared because that prevented the shared library from being used. ........ r54637 | collin.winter | 2007-03-31 12:31:34 -0700 (Sat, 31 Mar 2007) | 1 line Shut up an occaisonal buildbot error due to test files being left around. ........ r54644 | neal.norwitz | 2007-04-01 11:24:22 -0700 (Sun, 01 Apr 2007) | 11 lines SF #1685563, MSVCCompiler creates redundant and long PATH strings If MSVCCompiler.initialize() was called multiple times, the path would get duplicated. On Windows, this is a problem because the path is limited to 4k. There's no benefit in adding a path multiple times, so prevent that from occuring. We also normalize the path before checking for duplicates so things like /a and /a/ won't both be stored. Will backport. ........ r54646 | brett.cannon | 2007-04-01 11:47:27 -0700 (Sun, 01 Apr 2007) | 8 lines time.strptime's caching of its locale object was being recreated when the locale changed but not used during the function call it was recreated during. The test in this checkin is untested (OS X does not have the proper locale support for me to test), although the fix for the bug this deals with was tested by the OP (#1290505). Once the buildbots verify the test at least doesn't fail it becomes a backport candidate. ........ r54647 | brett.cannon | 2007-04-01 12:46:19 -0700 (Sun, 01 Apr 2007) | 3 lines Fix the test for recreating the locale cache object by not worrying about if one of the test locales cannot be set. ........ r54649 | georg.brandl | 2007-04-01 14:29:15 -0700 (Sun, 01 Apr 2007) | 2 lines Fix a lot of markup and meta-information glitches. ........ r54650 | georg.brandl | 2007-04-01 14:39:52 -0700 (Sun, 01 Apr 2007) | 2 lines Another fix. ........ r54651 | georg.brandl | 2007-04-01 15:39:10 -0700 (Sun, 01 Apr 2007) | 2 lines Lots of explicit class names for method and member descs. ........ r54652 | georg.brandl | 2007-04-01 15:40:12 -0700 (Sun, 01 Apr 2007) | 2 lines Explicit class names. ........ r54653 | georg.brandl | 2007-04-01 15:47:31 -0700 (Sun, 01 Apr 2007) | 2 lines Some semantic fixes. ........ r54654 | georg.brandl | 2007-04-01 16:29:10 -0700 (Sun, 01 Apr 2007) | 2 lines Remove bogus entry. ........ r54655 | georg.brandl | 2007-04-01 16:31:30 -0700 (Sun, 01 Apr 2007) | 2 lines Fix the class name of strings. ........ r54658 | raymond.hettinger | 2007-04-02 10:29:30 -0700 (Mon, 02 Apr 2007) | 1 line SF #1693079: Cannot save empty array in shelve ........ r54663 | raymond.hettinger | 2007-04-02 15:54:21 -0700 (Mon, 02 Apr 2007) | 3 lines Array module's buffer interface can now handle empty arrays. ........ r54664 | guido.van.rossum | 2007-04-02 16:55:37 -0700 (Mon, 02 Apr 2007) | 5 lines Fix warnings about object.__init__() signature. Two (test_array and test_descr) were bug IMO; the third (copy_reg) is a work-around which recognizes that object.__init__() doesn't do anything. ........ r54666 | raymond.hettinger | 2007-04-02 17:02:11 -0700 (Mon, 02 Apr 2007) | 1 line SF 1602378 Clarify docstrings for bisect ........ r54668 | raymond.hettinger | 2007-04-02 18:39:43 -0700 (Mon, 02 Apr 2007) | 3 lines SF #1382213: Tutorial section 9.5.1 ignores MRO for new-style classes ........ r54669 | matthias.klose | 2007-04-02 21:35:59 -0700 (Mon, 02 Apr 2007) | 4 lines - Fix an off-by-one bug in locale.strxfrm(). patch taken from http://bugs.debian.org/416934. ........ r54671 | georg.brandl | 2007-04-03 00:04:27 -0700 (Tue, 03 Apr 2007) | 9 lines Fix the strange case of \begin{methoddesc}[NNTP]{...} where \ifx#1\@undefined ended up comparing N and N, therefore executing the true part of the conditional, blowing up at \@undefined. ........ r54672 | facundo.batista | 2007-04-03 07:05:08 -0700 (Tue, 03 Apr 2007) | 4 lines Now using unittest for the tests infraestructure. Also split the tests in those who need the network, and that who doesn't. ........ r54673 | walter.doerwald | 2007-04-03 09:08:10 -0700 (Tue, 03 Apr 2007) | 4 lines Move the functionality for catching warnings in test_warnings.py into a separate class to that reusing the functionality in test_structmembers.py doesn't rerun the tests from test_warnings.py. ........ r54674 | walter.doerwald | 2007-04-03 09:16:24 -0700 (Tue, 03 Apr 2007) | 2 lines Document that CatchWarningTests is reused by test_structmembers.py. ........ r54675 | walter.doerwald | 2007-04-03 09:53:43 -0700 (Tue, 03 Apr 2007) | 4 lines Add tests for the filename. Test that the stacklevel is handled correctly. ........ r54676 | facundo.batista | 2007-04-03 10:29:48 -0700 (Tue, 03 Apr 2007) | 6 lines Added a SSL server to test_socket_ssl.py to be able to test locally. Now, it checks if have openssl available and run those specific tests (it starts openssl at the beggining of all the tests and then kills it at the end). ........ r54677 | walter.doerwald | 2007-04-03 11:33:29 -0700 (Tue, 03 Apr 2007) | 6 lines Implement a contextmanager test.test_support.catch_warning that can be used to catch the last warning issued by the warning framework. Change test_warnings.py and test_structmembers.py to use this new contextmanager. ........ r54678 | facundo.batista | 2007-04-03 14:15:34 -0700 (Tue, 03 Apr 2007) | 4 lines Changed the whole structure of startup and checking if the server is available. Hope to not get more false alarms. ........ r54681 | facundo.batista | 2007-04-04 07:10:40 -0700 (Wed, 04 Apr 2007) | 4 lines Fixed the way that the .pem files are looked for, and changed how to kill the process in win32 to use the _handle attribute. ........ r54682 | guido.van.rossum | 2007-04-04 10:43:02 -0700 (Wed, 04 Apr 2007) | 4 lines Fix a race condition in this test -- instead of assuming that it will take the test server thread at most 0.5 seconds to get ready, use an event variable. ........ r54683 | collin.winter | 2007-04-04 11:14:17 -0700 (Wed, 04 Apr 2007) | 1 line Clean up imports. ........ r54684 | collin.winter | 2007-04-04 11:16:24 -0700 (Wed, 04 Apr 2007) | 1 line Stop using test_support.verify(). ........ r54685 | martin.v.loewis | 2007-04-04 11:30:36 -0700 (Wed, 04 Apr 2007) | 2 lines Bug #1686475: Support stat'ing open files on Windows again. Will backport to 2.5. ........ r54687 | collin.winter | 2007-04-04 11:33:40 -0700 (Wed, 04 Apr 2007) | 1 line Make test_getopt use unittest. ........ r54688 | collin.winter | 2007-04-04 11:36:30 -0700 (Wed, 04 Apr 2007) | 1 line Make test_softspace use unittest. ........ r54689 | ziga.seilnacht | 2007-04-04 11:38:47 -0700 (Wed, 04 Apr 2007) | 2 lines Fix WalkTests.test_traversal() on Windows. The cleanup in MakedirTests.setUp() can now be removed. ........ r54695 | raymond.hettinger | 2007-04-05 11:00:03 -0700 (Thu, 05 Apr 2007) | 3 lines Bug #1563759: struct.unpack doens't support buffer protocol objects ........ r54697 | collin.winter | 2007-04-05 13:05:07 -0700 (Thu, 05 Apr 2007) | 1 line Convert test_long_future to use unittest. ........ r54698 | collin.winter | 2007-04-05 13:08:56 -0700 (Thu, 05 Apr 2007) | 1 line Convert test_normalization to use unittest. ........ r54699 | andrew.kuchling | 2007-04-05 18:11:58 -0700 (Thu, 05 Apr 2007) | 1 line Some grammar fixes ........ r54704 | collin.winter | 2007-04-06 12:27:40 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_stringprep to use unittest. ........ r54705 | collin.winter | 2007-04-06 12:32:32 -0700 (Fri, 06 Apr 2007) | 1 line Import cleanup in test_crypt. ........ r54706 | collin.winter | 2007-04-06 13:00:05 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_gc to use unittest. ........ r54707 | collin.winter | 2007-04-06 13:03:11 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_module to use unittest. ........ r54711 | collin.winter | 2007-04-06 21:40:43 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_fileinput to use unittest. ........ r54712 | brett.cannon | 2007-04-07 21:29:32 -0700 (Sat, 07 Apr 2007) | 5 lines Doc that file.next() has undefined behaviour when called on a file opened with 'w'. Closes bug #1569057. To be backported once 2.5 branch is unfrozen. ........ r54726 | vinay.sajip | 2007-04-09 09:16:10 -0700 (Mon, 09 Apr 2007) | 1 line Added optional timeout to SocketHandler.makeSocket (SF #1695948) ........ r54727 | ziga.seilnacht | 2007-04-09 12:10:29 -0700 (Mon, 09 Apr 2007) | 3 lines Patch #1695862: remove old test directory that causes test_urllib failures on Windows buildbots. The change is a one time fix and will be removed after a successful buildbot run. ........ r54729 | facundo.batista | 2007-04-09 20:00:37 -0700 (Mon, 09 Apr 2007) | 3 lines Minor fix to the tests pass ok even with -O. ........ r54730 | collin.winter | 2007-04-09 21:44:49 -0700 (Mon, 09 Apr 2007) | 1 line Typo fix. ........ r54732 | facundo.batista | 2007-04-10 05:58:45 -0700 (Tue, 10 Apr 2007) | 5 lines General clean-up. Lot of margin corrections, comments, some typos. Exceptions now are raised in the new style. And a mockup class is now also new style. Thanks Santiago Pereson. ........ r54741 | georg.brandl | 2007-04-10 14:39:38 -0700 (Tue, 10 Apr 2007) | 2 lines Repair a duplicate label and some obsolete uses of \setindexsubitem. ........ r54746 | andrew.kuchling | 2007-04-11 06:39:00 -0700 (Wed, 11 Apr 2007) | 1 line Add window.chgat() method, submitted via e-mail by Fabian Kreutz ........ r54747 | andrew.kuchling | 2007-04-11 06:42:25 -0700 (Wed, 11 Apr 2007) | 1 line Point readers at the patch submission instructions ........ r54748 | andrew.kuchling | 2007-04-11 06:47:13 -0700 (Wed, 11 Apr 2007) | 1 line Describe undocumented third argument to touchline() ........ r54757 | georg.brandl | 2007-04-11 10:16:24 -0700 (Wed, 11 Apr 2007) | 3 lines Add some missing NULL checks which trigger crashes on low-memory conditions. Found by Victor Stinner. Will backport when 2.5 branch is unfrozen. ........ r54760 | raymond.hettinger | 2007-04-11 11:40:58 -0700 (Wed, 11 Apr 2007) | 1 line SF 1191699: Make slices picklable ........ r54762 | georg.brandl | 2007-04-11 12:25:11 -0700 (Wed, 11 Apr 2007) | 2 lines Exceptions are no longer old-style instances. Fix accordingly. ........ r54763 | georg.brandl | 2007-04-11 16:28:44 -0700 (Wed, 11 Apr 2007) | 2 lines Repair missing spaces after \UNIX. ........ r54772 | raymond.hettinger | 2007-04-11 21:10:00 -0700 (Wed, 11 Apr 2007) | 1 line SF 1193128: Let str.translate(None) be an identity transformation ........ r54784 | georg.brandl | 2007-04-12 00:01:19 -0700 (Thu, 12 Apr 2007) | 2 lines Patch #1698951: clarify deprecation message in rexec and Bastion ........ r54785 | ziga.seilnacht | 2007-04-12 01:46:51 -0700 (Thu, 12 Apr 2007) | 2 lines Patch #1695862: remove the cleanup code, now that Windows buildbots are green again. ........ r54786 | walter.doerwald | 2007-04-12 03:35:00 -0700 (Thu, 12 Apr 2007) | 3 lines Fix utf-8-sig incremental decoder, which didn't recognise a BOM when the first chunk fed to the decoder started with a BOM, but was longer than 3 bytes. ........ r54807 | barry.warsaw | 2007-04-13 11:47:14 -0700 (Fri, 13 Apr 2007) | 8 lines Port r54805 from python25-maint branch: Add code to read from master_fd in the parent, breaking when we get an OSError (EIO can occur on Linux) or there's no more data to read. Without this, test_pty.py can hang on the waitpid() because the child is blocking on the stdout write. This will definitely happen on Mac OS X and could potentially happen on other platforms. See the comment for details. ........ r54812 | kristjan.jonsson | 2007-04-13 15:07:33 -0700 (Fri, 13 Apr 2007) | 1 line Fix a bug when using the __lltrace__ opcode tracer, and a problem sith signed chars in frameobject.c which can occur with opcodes > 127 ........ r54814 | kristjan.jonsson | 2007-04-13 15:20:13 -0700 (Fri, 13 Apr 2007) | 1 line Fix potential crash in path manipulation on windows ........ r54816 | trent.mick | 2007-04-13 16:22:05 -0700 (Fri, 13 Apr 2007) | 4 lines Add the necessary dependency for the Windows VC6 build to ensure 'pythoncore' is built before '_ctypes' is attempted. Will backport to 2.5 once it is unfrozen for 2.5.1. ........ r54825 | neal.norwitz | 2007-04-13 22:25:50 -0700 (Fri, 13 Apr 2007) | 3 lines When __slots__ are set to a unicode string, make it work the same as setting a plain string, ie don't expand to single letter identifiers. ........ r54841 | neal.norwitz | 2007-04-16 00:37:55 -0700 (Mon, 16 Apr 2007) | 1 line SF #1701207, Fix bogus assertion (and test it!) ........ r54844 | collin.winter | 2007-04-16 15:10:32 -0700 (Mon, 16 Apr 2007) | 1 line Check the availability of the urlfetch resource earlier than before. ........ r54849 | martin.v.loewis | 2007-04-16 22:02:01 -0700 (Mon, 16 Apr 2007) | 2 lines Add Travis Oliphant. ........ r54873 | brett.cannon | 2007-04-18 20:44:17 -0700 (Wed, 18 Apr 2007) | 2 lines Silence a compiler warning about incompatible pointer types. ........ r54874 | neal.norwitz | 2007-04-18 22:52:37 -0700 (Wed, 18 Apr 2007) | 2 lines SF #1703270, add missing declaration in readline.c to avoid compiler warning. ........ r54875 | armin.rigo | 2007-04-19 07:44:48 -0700 (Thu, 19 Apr 2007) | 8 lines Revert r53997 as per http://mail.python.org/pipermail/python-dev/2007-March/071796.html . I've kept a couple of still-valid extra tests in test_descr, but didn't bother to sort through the new comments and refactorings added in r53997 to see if some of them could be kept. If so, they could go in a follow-up check-in. ........ r54876 | armin.rigo | 2007-04-19 07:56:48 -0700 (Thu, 19 Apr 2007) | 2 lines Fix a usage of the dangerous pattern decref - modify field - incref. ........ r54884 | neal.norwitz | 2007-04-19 22:20:38 -0700 (Thu, 19 Apr 2007) | 9 lines Add an optional address to copy the failure mails to. Detect a conflict in the only file that should have outstanding changes when this script is run. This doesn't matter on the trunk, but does when run on a branch. Trunk always has the date set to today in boilerplate.tex. Each time a release is cut with a different date, a conflict occurs. (We could copy a known good version, but then we would lose changes to this file.) ........ r54918 | georg.brandl | 2007-04-21 13:35:38 -0700 (Sat, 21 Apr 2007) | 3 lines Bug #1704790: bind name "sys" locally in __del__ method so that it is not cleared before __del__ is run. ........ r54920 | facundo.batista | 2007-04-21 18:18:56 -0700 (Sat, 21 Apr 2007) | 5 lines Added tests for other methods of SSL object. Now we cover all the object methods. This is the final step to close the #451607 bug. ........ r54927 | facundo.batista | 2007-04-23 10:08:31 -0700 (Mon, 23 Apr 2007) | 5 lines As specified in RFC 2616, 2xx code indicates that the client's request was successfully received, understood, and accepted. Now in these cases no error is raised. Also fixed tests. ........ r54929 | collin.winter | 2007-04-23 20:43:46 -0700 (Mon, 23 Apr 2007) | 1 line Convert PyUnit -> unittest. ........ r54931 | collin.winter | 2007-04-23 21:09:52 -0700 (Mon, 23 Apr 2007) | 1 line Remove code that hasn't been called in years. ........ r54932 | neal.norwitz | 2007-04-23 21:53:12 -0700 (Mon, 23 Apr 2007) | 1 line Fix SF #1703110, Incorrect example for add_password() (use uri, not host) ........ r54934 | georg.brandl | 2007-04-24 03:36:42 -0700 (Tue, 24 Apr 2007) | 2 lines Some new year updates. ........ r54938 | facundo.batista | 2007-04-24 06:54:38 -0700 (Tue, 24 Apr 2007) | 4 lines Added a comment about last change in urllib2.py (all 2xx responses are ok now). ........ r54939 | georg.brandl | 2007-04-24 08:10:09 -0700 (Tue, 24 Apr 2007) | 2 lines Bug #1705717: error in sys.argv docs. ........ r54941 | georg.brandl | 2007-04-24 08:27:13 -0700 (Tue, 24 Apr 2007) | 4 lines Bug #1706381: Specifying the SWIG option "-c++" in the setup.py file (as opposed to the command line) will now write file names ending in ".cpp" too. ........ r54944 | raymond.hettinger | 2007-04-24 15:13:43 -0700 (Tue, 24 Apr 2007) | 1 line Fix markup ........ r54945 | kristjan.jonsson | 2007-04-24 17:10:50 -0700 (Tue, 24 Apr 2007) | 1 line Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition ........ r54947 | kristjan.jonsson | 2007-04-24 17:17:39 -0700 (Tue, 24 Apr 2007) | 1 line Make pythoncore compile cleanly with VisualStudio 2005. Used an explicit typecast to get a 64 bit integer, and undefined the Yield macro that conflicts with winbase.h ........ r54948 | kristjan.jonsson | 2007-04-24 17:19:26 -0700 (Tue, 24 Apr 2007) | 1 line Remove obsolete comment. Importing of .dll files has been discontinued, only .pyd files supported on windows now. ........ r54949 | georg.brandl | 2007-04-24 23:24:59 -0700 (Tue, 24 Apr 2007) | 2 lines Patch #1698768: updated the "using Python on the Mac" intro. ........ r54951 | georg.brandl | 2007-04-24 23:25:55 -0700 (Tue, 24 Apr 2007) | 2 lines Markup fix. ........ r54953 | neal.norwitz | 2007-04-24 23:30:05 -0700 (Tue, 24 Apr 2007) | 3 lines Whitespace normalization. Ugh, we really need to do this more often. You might want to review this change as it's my first time. Be gentle. :-) ........ r54956 | collin.winter | 2007-04-25 10:29:52 -0700 (Wed, 25 Apr 2007) | 1 line Standardize on test.test_support.run_unittest() (as opposed to a mix of run_unittest() and run_suite()). Also, add functionality to run_unittest() that admits usage of unittest.TestLoader.loadTestsFromModule(). ........ r54957 | collin.winter | 2007-04-25 10:37:35 -0700 (Wed, 25 Apr 2007) | 1 line Remove functionality from test_datetime.test_main() that does reference count checking; 'regrtest.py -R' is the way to do this kind of testing. ........ r54958 | collin.winter | 2007-04-25 10:57:53 -0700 (Wed, 25 Apr 2007) | 1 line Change test_support.have_unicode to use True/False instead of 1/0. ........ r54959 | tim.peters | 2007-04-25 11:47:18 -0700 (Wed, 25 Apr 2007) | 2 lines Whitespace normalization. ........ r54960 | tim.peters | 2007-04-25 11:48:35 -0700 (Wed, 25 Apr 2007) | 2 lines Set missing svn:eol-style property on text files. ........ r54961 | collin.winter | 2007-04-25 11:54:36 -0700 (Wed, 25 Apr 2007) | 1 line Import and raise statement cleanup. ........ r54969 | collin.winter | 2007-04-25 13:41:34 -0700 (Wed, 25 Apr 2007) | 1 line Convert test_ossaudiodev to use unittest. ........ r54974 | collin.winter | 2007-04-25 14:50:25 -0700 (Wed, 25 Apr 2007) | 1 line Fix an issue related to the unittest conversion. ........ r54979 | fred.drake | 2007-04-25 21:42:19 -0700 (Wed, 25 Apr 2007) | 1 line fix some markup errors ........ r54982 | kristjan.jonsson | 2007-04-26 02:15:08 -0700 (Thu, 26 Apr 2007) | 1 line Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile. ........ r54983 | kristjan.jonsson | 2007-04-26 06:44:16 -0700 (Thu, 26 Apr 2007) | 1 line The locale "En" appears not to be valid on windows underi VisualStudio.2005. Added "English" to the test_locale.py to make the testsuite pass for that build ........ r54984 | steve.holden | 2007-04-26 07:23:12 -0700 (Thu, 26 Apr 2007) | 1 line Minor wording change on slicing aide-memoire. ........ r54985 | kristjan.jonsson | 2007-04-26 08:24:54 -0700 (Thu, 26 Apr 2007) | 1 line Accomodate 64 bit time_t in the _bsddb module. ........
2380 lines
90 KiB
TeX
2380 lines
90 KiB
TeX
\documentclass{howto}
|
|
\usepackage{distutils}
|
|
% $Id$
|
|
|
|
\title{What's New in Python 2.3}
|
|
\release{1.01}
|
|
\author{A.M.\ Kuchling}
|
|
\authoraddress{
|
|
\strong{Python Software Foundation}\\
|
|
Email: \email{amk@amk.ca}
|
|
}
|
|
|
|
\begin{document}
|
|
\maketitle
|
|
\tableofcontents
|
|
|
|
This article explains the new features in Python 2.3. Python 2.3 was
|
|
released on July 29, 2003.
|
|
|
|
The main themes for Python 2.3 are polishing some of the features
|
|
added in 2.2, adding various small but useful enhancements to the core
|
|
language, and expanding the standard library. The new object model
|
|
introduced in the previous version has benefited from 18 months of
|
|
bugfixes and from optimization efforts that have improved the
|
|
performance of new-style classes. A few new built-in functions have
|
|
been added such as \function{sum()} and \function{enumerate()}. The
|
|
\keyword{in} operator can now be used for substring searches (e.g.
|
|
\code{"ab" in "abc"} returns \constant{True}).
|
|
|
|
Some of the many new library features include Boolean, set, heap, and
|
|
date/time data types, the ability to import modules from ZIP-format
|
|
archives, metadata support for the long-awaited Python catalog, an
|
|
updated version of IDLE, and modules for logging messages, wrapping
|
|
text, parsing CSV files, processing command-line options, using BerkeleyDB
|
|
databases... the list of new and enhanced modules is lengthy.
|
|
|
|
This article doesn't attempt to provide a complete specification of
|
|
the new features, but instead provides a convenient overview. For
|
|
full details, you should refer to the documentation for Python 2.3,
|
|
such as the \citetitle[../lib/lib.html]{Python Library Reference} and
|
|
the \citetitle[../ref/ref.html]{Python Reference Manual}. If you want
|
|
to understand the complete implementation and design rationale,
|
|
refer to the PEP for a particular new feature.
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 218: A Standard Set Datatype}
|
|
|
|
The new \module{sets} module contains an implementation of a set
|
|
datatype. The \class{Set} class is for mutable sets, sets that can
|
|
have members added and removed. The \class{ImmutableSet} class is for
|
|
sets that can't be modified, and instances of \class{ImmutableSet} can
|
|
therefore be used as dictionary keys. Sets are built on top of
|
|
dictionaries, so the elements within a set must be hashable.
|
|
|
|
Here's a simple example:
|
|
|
|
\begin{verbatim}
|
|
>>> import sets
|
|
>>> S = sets.Set([1,2,3])
|
|
>>> S
|
|
Set([1, 2, 3])
|
|
>>> 1 in S
|
|
True
|
|
>>> 0 in S
|
|
False
|
|
>>> S.add(5)
|
|
>>> S.remove(3)
|
|
>>> S
|
|
Set([1, 2, 5])
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
The union and intersection of sets can be computed with the
|
|
\method{union()} and \method{intersection()} methods; an alternative
|
|
notation uses the bitwise operators \code{\&} and \code{|}.
|
|
Mutable sets also have in-place versions of these methods,
|
|
\method{union_update()} and \method{intersection_update()}.
|
|
|
|
\begin{verbatim}
|
|
>>> S1 = sets.Set([1,2,3])
|
|
>>> S2 = sets.Set([4,5,6])
|
|
>>> S1.union(S2)
|
|
Set([1, 2, 3, 4, 5, 6])
|
|
>>> S1 | S2 # Alternative notation
|
|
Set([1, 2, 3, 4, 5, 6])
|
|
>>> S1.intersection(S2)
|
|
Set([])
|
|
>>> S1 & S2 # Alternative notation
|
|
Set([])
|
|
>>> S1.union_update(S2)
|
|
>>> S1
|
|
Set([1, 2, 3, 4, 5, 6])
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
It's also possible to take the symmetric difference of two sets. This
|
|
is the set of all elements in the union that aren't in the
|
|
intersection. Another way of putting it is that the symmetric
|
|
difference contains all elements that are in exactly one
|
|
set. Again, there's an alternative notation (\code{\^}), and an
|
|
in-place version with the ungainly name
|
|
\method{symmetric_difference_update()}.
|
|
|
|
\begin{verbatim}
|
|
>>> S1 = sets.Set([1,2,3,4])
|
|
>>> S2 = sets.Set([3,4,5,6])
|
|
>>> S1.symmetric_difference(S2)
|
|
Set([1, 2, 5, 6])
|
|
>>> S1 ^ S2
|
|
Set([1, 2, 5, 6])
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
There are also \method{issubset()} and \method{issuperset()} methods
|
|
for checking whether one set is a subset or superset of another:
|
|
|
|
\begin{verbatim}
|
|
>>> S1 = sets.Set([1,2,3])
|
|
>>> S2 = sets.Set([2,3])
|
|
>>> S2.issubset(S1)
|
|
True
|
|
>>> S1.issubset(S2)
|
|
False
|
|
>>> S1.issuperset(S2)
|
|
True
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{218}{Adding a Built-In Set Object Type}{PEP written by Greg V. Wilson.
|
|
Implemented by Greg V. Wilson, Alex Martelli, and GvR.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 255: Simple Generators\label{section-generators}}
|
|
|
|
In Python 2.2, generators were added as an optional feature, to be
|
|
enabled by a \code{from __future__ import generators} directive. In
|
|
2.3 generators no longer need to be specially enabled, and are now
|
|
always present; this means that \keyword{yield} is now always a
|
|
keyword. The rest of this section is a copy of the description of
|
|
generators from the ``What's New in Python 2.2'' document; if you read
|
|
it back when Python 2.2 came out, you can skip the rest of this section.
|
|
|
|
You're doubtless familiar with how function calls work in Python or C.
|
|
When you call a function, it gets a private namespace where its local
|
|
variables are created. When the function reaches a \keyword{return}
|
|
statement, the local variables are destroyed and the resulting value
|
|
is returned to the caller. A later call to the same function will get
|
|
a fresh new set of local variables. But, what if the local variables
|
|
weren't thrown away on exiting a function? What if you could later
|
|
resume the function where it left off? This is what generators
|
|
provide; they can be thought of as resumable functions.
|
|
|
|
Here's the simplest example of a generator function:
|
|
|
|
\begin{verbatim}
|
|
def generate_ints(N):
|
|
for i in range(N):
|
|
yield i
|
|
\end{verbatim}
|
|
|
|
A new keyword, \keyword{yield}, was introduced for generators. Any
|
|
function containing a \keyword{yield} statement is a generator
|
|
function; this is detected by Python's bytecode compiler which
|
|
compiles the function specially as a result.
|
|
|
|
When you call a generator function, it doesn't return a single value;
|
|
instead it returns a generator object that supports the iterator
|
|
protocol. On executing the \keyword{yield} statement, the generator
|
|
outputs the value of \code{i}, similar to a \keyword{return}
|
|
statement. The big difference between \keyword{yield} and a
|
|
\keyword{return} statement is that on reaching a \keyword{yield} the
|
|
generator's state of execution is suspended and local variables are
|
|
preserved. On the next call to the generator's \code{.next()} method,
|
|
the function will resume executing immediately after the
|
|
\keyword{yield} statement. (For complicated reasons, the
|
|
\keyword{yield} statement isn't allowed inside the \keyword{try} block
|
|
of a \keyword{try}...\keyword{finally} statement; read \pep{255} for a full
|
|
explanation of the interaction between \keyword{yield} and
|
|
exceptions.)
|
|
|
|
Here's a sample usage of the \function{generate_ints()} generator:
|
|
|
|
\begin{verbatim}
|
|
>>> gen = generate_ints(3)
|
|
>>> gen
|
|
<generator object at 0x8117f90>
|
|
>>> gen.next()
|
|
0
|
|
>>> gen.next()
|
|
1
|
|
>>> gen.next()
|
|
2
|
|
>>> gen.next()
|
|
Traceback (most recent call last):
|
|
File "stdin", line 1, in ?
|
|
File "stdin", line 2, in generate_ints
|
|
StopIteration
|
|
\end{verbatim}
|
|
|
|
You could equally write \code{for i in generate_ints(5)}, or
|
|
\code{a,b,c = generate_ints(3)}.
|
|
|
|
Inside a generator function, the \keyword{return} statement can only
|
|
be used without a value, and signals the end of the procession of
|
|
values; afterwards the generator cannot return any further values.
|
|
\keyword{return} with a value, such as \code{return 5}, is a syntax
|
|
error inside a generator function. The end of the generator's results
|
|
can also be indicated by raising \exception{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 example, returning a list of integers could
|
|
be done by setting \code{self.count} to 0, and having the
|
|
\method{next()} method increment \code{self.count} and return it.
|
|
However, for a moderately complicated generator, writing a
|
|
corresponding class would be much messier.
|
|
\file{Lib/test/test_generators.py} contains a number of more
|
|
interesting examples. The simplest one implements an in-order
|
|
traversal of a tree using generators recursively.
|
|
|
|
\begin{verbatim}
|
|
# A recursive generator that generates Tree leaves in in-order.
|
|
def inorder(t):
|
|
if t:
|
|
for x in inorder(t.left):
|
|
yield x
|
|
yield t.label
|
|
for x in inorder(t.right):
|
|
yield x
|
|
\end{verbatim}
|
|
|
|
Two other examples in \file{Lib/test/test_generators.py} produce
|
|
solutions for the N-Queens problem (placing $N$ queens on an $NxN$
|
|
chess board so that no queen threatens another) and the Knight's Tour
|
|
(a route that takes a knight to every square of an $NxN$ chessboard
|
|
without visiting any square twice).
|
|
|
|
The idea of generators comes from other programming languages,
|
|
especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the
|
|
idea of generators is central. In Icon, every
|
|
expression and function call behaves like a generator. One example
|
|
from ``An Overview of the Icon Programming Language'' at
|
|
\url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of
|
|
what this looks like:
|
|
|
|
\begin{verbatim}
|
|
sentence := "Store it in the neighboring harbor"
|
|
if (i := find("or", sentence)) > 5 then write(i)
|
|
\end{verbatim}
|
|
|
|
In Icon the \function{find()} function returns the indexes at which the
|
|
substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement,
|
|
\code{i} is first assigned a value of 3, but 3 is less than 5, so the
|
|
comparison fails, and Icon retries it with the second value of 23. 23
|
|
is greater than 5, so the comparison now succeeds, and the code prints
|
|
the value 23 to the screen.
|
|
|
|
Python doesn't go nearly as far as Icon in adopting generators as a
|
|
central concept. Generators are considered part of the core
|
|
Python language, but learning or using them isn't compulsory; if they
|
|
don't solve any problems that you have, feel free to ignore them.
|
|
One novel feature of Python's interface as compared to
|
|
Icon's is that a generator's state is represented as a concrete object
|
|
(the iterator) that can be passed around to other functions or stored
|
|
in a data structure.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{255}{Simple Generators}{Written by Neil Schemenauer, Tim
|
|
Peters, Magnus Lie Hetland. Implemented mostly by Neil Schemenauer
|
|
and Tim Peters, with other fixes from the Python Labs crew.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 263: Source Code Encodings \label{section-encodings}}
|
|
|
|
Python source files can now be declared as being in different
|
|
character set encodings. Encodings are declared by including a
|
|
specially formatted comment in the first or second line of the source
|
|
file. For example, a UTF-8 file can be declared with:
|
|
|
|
\begin{verbatim}
|
|
#!/usr/bin/env python
|
|
# -*- coding: UTF-8 -*-
|
|
\end{verbatim}
|
|
|
|
Without such an encoding declaration, the default encoding used is
|
|
7-bit ASCII. Executing or importing modules that contain string
|
|
literals with 8-bit characters and have no encoding declaration will result
|
|
in a \exception{DeprecationWarning} being signalled by Python 2.3; in
|
|
2.4 this will be a syntax error.
|
|
|
|
The encoding declaration only affects Unicode string literals, which
|
|
will be converted to Unicode using the specified encoding. Note that
|
|
Python identifiers are still restricted to ASCII characters, so you
|
|
can't have variable names that use characters outside of the usual
|
|
alphanumerics.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{263}{Defining Python Source Code Encodings}{Written by
|
|
Marc-Andr\'e Lemburg and Martin von~L\"owis; implemented by Suzuki
|
|
Hisao and Martin von~L\"owis.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 273: Importing Modules from ZIP Archives}
|
|
|
|
The new \module{zipimport} module adds support for importing
|
|
modules from a ZIP-format archive. You don't need to import the
|
|
module explicitly; it will be automatically imported if a ZIP
|
|
archive's filename is added to \code{sys.path}. For example:
|
|
|
|
\begin{verbatim}
|
|
amk@nyman:~/src/python$ unzip -l /tmp/example.zip
|
|
Archive: /tmp/example.zip
|
|
Length Date Time Name
|
|
-------- ---- ---- ----
|
|
8467 11-26-02 22:30 jwzthreading.py
|
|
-------- -------
|
|
8467 1 file
|
|
amk@nyman:~/src/python$ ./python
|
|
Python 2.3 (#1, Aug 1 2003, 19:54:32)
|
|
>>> import sys
|
|
>>> sys.path.insert(0, '/tmp/example.zip') # Add .zip file to front of path
|
|
>>> import jwzthreading
|
|
>>> jwzthreading.__file__
|
|
'/tmp/example.zip/jwzthreading.py'
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
An entry in \code{sys.path} can now be the filename of a ZIP archive.
|
|
The ZIP archive can contain any kind of files, but only files named
|
|
\file{*.py}, \file{*.pyc}, or \file{*.pyo} can be imported. If an
|
|
archive only contains \file{*.py} files, Python will not attempt to
|
|
modify the archive by adding the corresponding \file{*.pyc} file, meaning
|
|
that if a ZIP archive doesn't contain \file{*.pyc} files, importing may be
|
|
rather slow.
|
|
|
|
A path within the archive can also be specified to only import from a
|
|
subdirectory; for example, the path \file{/tmp/example.zip/lib/}
|
|
would only import from the \file{lib/} subdirectory within the
|
|
archive.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{273}{Import Modules from Zip Archives}{Written by James C. Ahlstrom,
|
|
who also provided an implementation.
|
|
Python 2.3 follows the specification in \pep{273},
|
|
but uses an implementation written by Just van~Rossum
|
|
that uses the import hooks described in \pep{302}.
|
|
See section~\ref{section-pep302} for a description of the new import hooks.
|
|
}
|
|
|
|
\end{seealso}
|
|
|
|
%======================================================================
|
|
\section{PEP 277: Unicode file name support for Windows NT}
|
|
|
|
On Windows NT, 2000, and XP, the system stores file names as Unicode
|
|
strings. Traditionally, Python has represented file names as byte
|
|
strings, which is inadequate because it renders some file names
|
|
inaccessible.
|
|
|
|
Python now allows using arbitrary Unicode strings (within the
|
|
limitations of the file system) for all functions that expect file
|
|
names, most notably the \function{open()} built-in function. If a Unicode
|
|
string is passed to \function{os.listdir()}, Python now returns a list
|
|
of Unicode strings. A new function, \function{os.getcwdu()}, returns
|
|
the current directory as a Unicode string.
|
|
|
|
Byte strings still work as file names, and on Windows Python will
|
|
transparently convert them to Unicode using the \code{mbcs} encoding.
|
|
|
|
Other systems also allow Unicode strings as file names but convert
|
|
them to byte strings before passing them to the system, which can
|
|
cause a \exception{UnicodeError} to be raised. Applications can test
|
|
whether arbitrary Unicode strings are supported as file names by
|
|
checking \member{os.path.supports_unicode_filenames}, a Boolean value.
|
|
|
|
Under MacOS, \function{os.listdir()} may now return Unicode filenames.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{277}{Unicode file name support for Windows NT}{Written by Neil
|
|
Hodgson; implemented by Neil Hodgson, Martin von~L\"owis, and Mark
|
|
Hammond.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 278: Universal Newline Support}
|
|
|
|
The three major operating systems used today are Microsoft Windows,
|
|
Apple's Macintosh OS, and the various \UNIX\ derivatives. A minor
|
|
irritation of cross-platform work
|
|
is that these three platforms all use different characters
|
|
to mark the ends of lines in text files. \UNIX\ uses the linefeed
|
|
(ASCII character 10), MacOS uses the carriage return (ASCII
|
|
character 13), and Windows uses a two-character sequence of a
|
|
carriage return plus a newline.
|
|
|
|
Python's file objects can now support end of line conventions other
|
|
than the one followed by the platform on which Python is running.
|
|
Opening a file with the mode \code{'U'} or \code{'rU'} will open a file
|
|
for reading in universal newline mode. All three line ending
|
|
conventions will be translated to a \character{\e n} in the strings
|
|
returned by the various file methods such as \method{read()} and
|
|
\method{readline()}.
|
|
|
|
Universal newline support is also used when importing modules and when
|
|
executing a file with the \function{execfile()} function. This means
|
|
that Python modules can be shared between all three operating systems
|
|
without needing to convert the line-endings.
|
|
|
|
This feature can be disabled when compiling Python by specifying
|
|
the \longprogramopt{without-universal-newlines} switch when running Python's
|
|
\program{configure} script.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{278}{Universal Newline Support}{Written
|
|
and implemented by Jack Jansen.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 279: enumerate()\label{section-enumerate}}
|
|
|
|
A new built-in function, \function{enumerate()}, will make
|
|
certain loops a bit clearer. \code{enumerate(thing)}, where
|
|
\var{thing} is either an iterator or a sequence, returns a iterator
|
|
that will return \code{(0, \var{thing}[0])}, \code{(1,
|
|
\var{thing}[1])}, \code{(2, \var{thing}[2])}, and so forth.
|
|
|
|
A common idiom to change every element of a list looks like this:
|
|
|
|
\begin{verbatim}
|
|
for i in range(len(L)):
|
|
item = L[i]
|
|
# ... compute some result based on item ...
|
|
L[i] = result
|
|
\end{verbatim}
|
|
|
|
This can be rewritten using \function{enumerate()} as:
|
|
|
|
\begin{verbatim}
|
|
for i, item in enumerate(L):
|
|
# ... compute some result based on item ...
|
|
L[i] = result
|
|
\end{verbatim}
|
|
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{279}{The enumerate() built-in function}{Written
|
|
and implemented by Raymond D. Hettinger.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 282: The logging Package}
|
|
|
|
A standard package for writing logs, \module{logging}, has been added
|
|
to Python 2.3. It provides a powerful and flexible mechanism for
|
|
generating logging output which can then be filtered and processed in
|
|
various ways. A configuration file written in a standard format can
|
|
be used to control the logging behavior of a program. Python
|
|
includes handlers that will write log records to
|
|
standard error or to a file or socket, send them to the system log, or
|
|
even e-mail them to a particular address; of course, it's also
|
|
possible to write your own handler classes.
|
|
|
|
The \class{Logger} class is the primary class.
|
|
Most application code will deal with one or more \class{Logger}
|
|
objects, each one used by a particular subsystem of the application.
|
|
Each \class{Logger} is identified by a name, and names are organized
|
|
into a hierarchy using \samp{.} as the component separator. For
|
|
example, you might have \class{Logger} instances named \samp{server},
|
|
\samp{server.auth} and \samp{server.network}. The latter two
|
|
instances are below \samp{server} in the hierarchy. This means that
|
|
if you turn up the verbosity for \samp{server} or direct \samp{server}
|
|
messages to a different handler, the changes will also apply to
|
|
records logged to \samp{server.auth} and \samp{server.network}.
|
|
There's also a root \class{Logger} that's the parent of all other
|
|
loggers.
|
|
|
|
For simple uses, the \module{logging} package contains some
|
|
convenience functions that always use the root log:
|
|
|
|
\begin{verbatim}
|
|
import logging
|
|
|
|
logging.debug('Debugging information')
|
|
logging.info('Informational message')
|
|
logging.warning('Warning:config file %s not found', 'server.conf')
|
|
logging.error('Error occurred')
|
|
logging.critical('Critical error -- shutting down')
|
|
\end{verbatim}
|
|
|
|
This produces the following output:
|
|
|
|
\begin{verbatim}
|
|
WARNING:root:Warning:config file server.conf not found
|
|
ERROR:root:Error occurred
|
|
CRITICAL:root:Critical error -- shutting down
|
|
\end{verbatim}
|
|
|
|
In the default configuration, informational and debugging messages are
|
|
suppressed and the output is sent to standard error. You can enable
|
|
the display of informational and debugging messages by calling the
|
|
\method{setLevel()} method on the root logger.
|
|
|
|
Notice the \function{warning()} call's use of string formatting
|
|
operators; all of the functions for logging messages take the
|
|
arguments \code{(\var{msg}, \var{arg1}, \var{arg2}, ...)} and log the
|
|
string resulting from \code{\var{msg} \% (\var{arg1}, \var{arg2},
|
|
...)}.
|
|
|
|
There's also an \function{exception()} function that records the most
|
|
recent traceback. Any of the other functions will also record the
|
|
traceback if you specify a true value for the keyword argument
|
|
\var{exc_info}.
|
|
|
|
\begin{verbatim}
|
|
def f():
|
|
try: 1/0
|
|
except: logging.exception('Problem recorded')
|
|
|
|
f()
|
|
\end{verbatim}
|
|
|
|
This produces the following output:
|
|
|
|
\begin{verbatim}
|
|
ERROR:root:Problem recorded
|
|
Traceback (most recent call last):
|
|
File "t.py", line 6, in f
|
|
1/0
|
|
ZeroDivisionError: integer division or modulo by zero
|
|
\end{verbatim}
|
|
|
|
Slightly more advanced programs will use a logger other than the root
|
|
logger. The \function{getLogger(\var{name})} function is used to get
|
|
a particular log, creating it if it doesn't exist yet.
|
|
\function{getLogger(None)} returns the root logger.
|
|
|
|
|
|
\begin{verbatim}
|
|
log = logging.getLogger('server')
|
|
...
|
|
log.info('Listening on port %i', port)
|
|
...
|
|
log.critical('Disk full')
|
|
...
|
|
\end{verbatim}
|
|
|
|
Log records are usually propagated up the hierarchy, so a message
|
|
logged to \samp{server.auth} is also seen by \samp{server} and
|
|
\samp{root}, but a \class{Logger} can prevent this by setting its
|
|
\member{propagate} attribute to \constant{False}.
|
|
|
|
There are more classes provided by the \module{logging} package that
|
|
can be customized. When a \class{Logger} instance is told to log a
|
|
message, it creates a \class{LogRecord} instance that is sent to any
|
|
number of different \class{Handler} instances. Loggers and handlers
|
|
can also have an attached list of filters, and each filter can cause
|
|
the \class{LogRecord} to be ignored or can modify the record before
|
|
passing it along. When they're finally output, \class{LogRecord}
|
|
instances are converted to text by a \class{Formatter} class. All of
|
|
these classes can be replaced by your own specially-written classes.
|
|
|
|
With all of these features the \module{logging} package should provide
|
|
enough flexibility for even the most complicated applications. This
|
|
is only an incomplete overview of its features, so please see the
|
|
\ulink{package's reference documentation}{../lib/module-logging.html}
|
|
for all of the details. Reading \pep{282} will also be helpful.
|
|
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{282}{A Logging System}{Written by Vinay Sajip and Trent Mick;
|
|
implemented by Vinay Sajip.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 285: A Boolean Type\label{section-bool}}
|
|
|
|
A Boolean type was added to Python 2.3. Two new constants were added
|
|
to the \module{__builtin__} module, \constant{True} and
|
|
\constant{False}. (\constant{True} and
|
|
\constant{False} constants were added to the built-ins
|
|
in Python 2.2.1, but the 2.2.1 versions are simply set to integer values of
|
|
1 and 0 and aren't a different type.)
|
|
|
|
The type object for this new type is named
|
|
\class{bool}; the constructor for it takes any Python value and
|
|
converts it to \constant{True} or \constant{False}.
|
|
|
|
\begin{verbatim}
|
|
>>> bool(1)
|
|
True
|
|
>>> bool(0)
|
|
False
|
|
>>> bool([])
|
|
False
|
|
>>> bool( (1,) )
|
|
True
|
|
\end{verbatim}
|
|
|
|
Most of the standard library modules and built-in functions have been
|
|
changed to return Booleans.
|
|
|
|
\begin{verbatim}
|
|
>>> obj = []
|
|
>>> hasattr(obj, 'append')
|
|
True
|
|
>>> isinstance(obj, list)
|
|
True
|
|
>>> isinstance(obj, tuple)
|
|
False
|
|
\end{verbatim}
|
|
|
|
Python's Booleans were added with the primary goal of making code
|
|
clearer. For example, if you're reading a function and encounter the
|
|
statement \code{return 1}, you might wonder whether the \code{1}
|
|
represents a Boolean truth value, an index, or a
|
|
coefficient that multiplies some other quantity. If the statement is
|
|
\code{return True}, however, the meaning of the return value is quite
|
|
clear.
|
|
|
|
Python's Booleans were \emph{not} added for the sake of strict
|
|
type-checking. A very strict language such as Pascal would also
|
|
prevent you performing arithmetic with Booleans, and would require
|
|
that the expression in an \keyword{if} statement always evaluate to a
|
|
Boolean result. Python is not this strict and never will be, as
|
|
\pep{285} explicitly says. This means you can still use any
|
|
expression in an \keyword{if} statement, even ones that evaluate to a
|
|
list or tuple or some random object. The Boolean type is a
|
|
subclass of the \class{int} class so that arithmetic using a Boolean
|
|
still works.
|
|
|
|
\begin{verbatim}
|
|
>>> True + 1
|
|
2
|
|
>>> False + 1
|
|
1
|
|
>>> False * 75
|
|
0
|
|
>>> True * 75
|
|
75
|
|
\end{verbatim}
|
|
|
|
To sum up \constant{True} and \constant{False} in a sentence: they're
|
|
alternative ways to spell the integer values 1 and 0, with the single
|
|
difference that \function{str()} and \function{repr()} return the
|
|
strings \code{'True'} and \code{'False'} instead of \code{'1'} and
|
|
\code{'0'}.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{285}{Adding a bool type}{Written and implemented by GvR.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 293: Codec Error Handling Callbacks}
|
|
|
|
When encoding a Unicode string into a byte string, unencodable
|
|
characters may be encountered. So far, Python has allowed specifying
|
|
the error processing as either ``strict'' (raising
|
|
\exception{UnicodeError}), ``ignore'' (skipping the character), or
|
|
``replace'' (using a question mark in the output string), with
|
|
``strict'' being the default behavior. It may be desirable to specify
|
|
alternative processing of such errors, such as inserting an XML
|
|
character reference or HTML entity reference into the converted
|
|
string.
|
|
|
|
Python now has a flexible framework to add different processing
|
|
strategies. New error handlers can be added with
|
|
\function{codecs.register_error}, and codecs then can access the error
|
|
handler with \function{codecs.lookup_error}. An equivalent C API has
|
|
been added for codecs written in C. The error handler gets the
|
|
necessary state information such as the string being converted, the
|
|
position in the string where the error was detected, and the target
|
|
encoding. The handler can then either raise an exception or return a
|
|
replacement string.
|
|
|
|
Two additional error handlers have been implemented using this
|
|
framework: ``backslashreplace'' uses Python backslash quoting to
|
|
represent unencodable characters and ``xmlcharrefreplace'' emits
|
|
XML character references.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{293}{Codec Error Handling Callbacks}{Written and implemented by
|
|
Walter D\"orwald.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 301: Package Index and Metadata for
|
|
Distutils\label{section-pep301}}
|
|
|
|
Support for the long-requested Python catalog makes its first
|
|
appearance in 2.3.
|
|
|
|
The heart of the catalog is the new Distutils \command{register} command.
|
|
Running \code{python setup.py register} will collect the metadata
|
|
describing a package, such as its name, version, maintainer,
|
|
description, \&c., and send it to a central catalog server. The
|
|
resulting catalog is available from \url{http://www.python.org/pypi}.
|
|
|
|
To make the catalog a bit more useful, a new optional
|
|
\var{classifiers} keyword argument has been added to the Distutils
|
|
\function{setup()} function. A list of
|
|
\ulink{Trove}{http://catb.org/\textasciitilde esr/trove/}-style
|
|
strings can be supplied to help classify the software.
|
|
|
|
Here's an example \file{setup.py} with classifiers, written to be compatible
|
|
with older versions of the Distutils:
|
|
|
|
\begin{verbatim}
|
|
from distutils import core
|
|
kw = {'name': "Quixote",
|
|
'version': "0.5.1",
|
|
'description': "A highly Pythonic Web application framework",
|
|
# ...
|
|
}
|
|
|
|
if (hasattr(core, 'setup_keywords') and
|
|
'classifiers' in core.setup_keywords):
|
|
kw['classifiers'] = \
|
|
['Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
|
'Environment :: No Input/Output (Daemon)',
|
|
'Intended Audience :: Developers'],
|
|
|
|
core.setup(**kw)
|
|
\end{verbatim}
|
|
|
|
The full list of classifiers can be obtained by running
|
|
\verb|python setup.py register --list-classifiers|.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{301}{Package Index and Metadata for Distutils}{Written and
|
|
implemented by Richard Jones.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 302: New Import Hooks \label{section-pep302}}
|
|
|
|
While it's been possible to write custom import hooks ever since the
|
|
\module{ihooks} module was introduced in Python 1.3, no one has ever
|
|
been really happy with it because writing new import hooks is
|
|
difficult and messy. There have been various proposed alternatives
|
|
such as the \module{imputil} and \module{iu} modules, but none of them
|
|
has ever gained much acceptance, and none of them were easily usable
|
|
from \C{} code.
|
|
|
|
\pep{302} borrows ideas from its predecessors, especially from
|
|
Gordon McMillan's \module{iu} module. Three new items
|
|
are added to the \module{sys} module:
|
|
|
|
\begin{itemize}
|
|
\item \code{sys.path_hooks} is a list of callable objects; most
|
|
often they'll be classes. Each callable takes a string containing a
|
|
path and either returns an importer object that will handle imports
|
|
from this path or raises an \exception{ImportError} exception if it
|
|
can't handle this path.
|
|
|
|
\item \code{sys.path_importer_cache} caches importer objects for
|
|
each path, so \code{sys.path_hooks} will only need to be traversed
|
|
once for each path.
|
|
|
|
\item \code{sys.meta_path} is a list of importer objects that will
|
|
be traversed before \code{sys.path} is checked. This list is
|
|
initially empty, but user code can add objects to it. Additional
|
|
built-in and frozen modules can be imported by an object added to
|
|
this list.
|
|
|
|
\end{itemize}
|
|
|
|
Importer objects must have a single method,
|
|
\method{find_module(\var{fullname}, \var{path}=None)}. \var{fullname}
|
|
will be a module or package name, e.g. \samp{string} or
|
|
\samp{distutils.core}. \method{find_module()} must return a loader object
|
|
that has a single method, \method{load_module(\var{fullname})}, that
|
|
creates and returns the corresponding module object.
|
|
|
|
Pseudo-code for Python's new import logic, therefore, looks something
|
|
like this (simplified a bit; see \pep{302} for the full details):
|
|
|
|
\begin{verbatim}
|
|
for mp in sys.meta_path:
|
|
loader = mp(fullname)
|
|
if loader is not None:
|
|
<module> = loader.load_module(fullname)
|
|
|
|
for path in sys.path:
|
|
for hook in sys.path_hooks:
|
|
try:
|
|
importer = hook(path)
|
|
except ImportError:
|
|
# ImportError, so try the other path hooks
|
|
pass
|
|
else:
|
|
loader = importer.find_module(fullname)
|
|
<module> = loader.load_module(fullname)
|
|
|
|
# Not found!
|
|
raise ImportError
|
|
\end{verbatim}
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{302}{New Import Hooks}{Written by Just van~Rossum and Paul Moore.
|
|
Implemented by Just van~Rossum.
|
|
}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
%======================================================================
|
|
\section{PEP 305: Comma-separated Files \label{section-pep305}}
|
|
|
|
Comma-separated files are a format frequently used for exporting data
|
|
from databases and spreadsheets. Python 2.3 adds a parser for
|
|
comma-separated files.
|
|
|
|
Comma-separated format is deceptively simple at first glance:
|
|
|
|
\begin{verbatim}
|
|
Costs,150,200,3.95
|
|
\end{verbatim}
|
|
|
|
Read a line and call \code{line.split(',')}: what could be simpler?
|
|
But toss in string data that can contain commas, and things get more
|
|
complicated:
|
|
|
|
\begin{verbatim}
|
|
"Costs",150,200,3.95,"Includes taxes, shipping, and sundry items"
|
|
\end{verbatim}
|
|
|
|
A big ugly regular expression can parse this, but using the new
|
|
\module{csv} package is much simpler:
|
|
|
|
\begin{verbatim}
|
|
import csv
|
|
|
|
input = open('datafile', 'rb')
|
|
reader = csv.reader(input)
|
|
for line in reader:
|
|
print line
|
|
\end{verbatim}
|
|
|
|
The \function{reader} function takes a number of different options.
|
|
The field separator isn't limited to the comma and can be changed to
|
|
any character, and so can the quoting and line-ending characters.
|
|
|
|
Different dialects of comma-separated files can be defined and
|
|
registered; currently there are two dialects, both used by Microsoft Excel.
|
|
A separate \class{csv.writer} class will generate comma-separated files
|
|
from a succession of tuples or lists, quoting strings that contain the
|
|
delimiter.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{305}{CSV File API}{Written and implemented
|
|
by Kevin Altis, Dave Cole, Andrew McNamara, Skip Montanaro, Cliff Wells.
|
|
}
|
|
|
|
\end{seealso}
|
|
|
|
%======================================================================
|
|
\section{PEP 307: Pickle Enhancements \label{section-pep307}}
|
|
|
|
The \module{pickle} and \module{cPickle} modules received some
|
|
attention during the 2.3 development cycle. In 2.2, new-style classes
|
|
could be pickled without difficulty, but they weren't pickled very
|
|
compactly; \pep{307} quotes a trivial example where a new-style class
|
|
results in a pickled string three times longer than that for a classic
|
|
class.
|
|
|
|
The solution was to invent a new pickle protocol. The
|
|
\function{pickle.dumps()} function has supported a text-or-binary flag
|
|
for a long time. In 2.3, this flag is redefined from a Boolean to an
|
|
integer: 0 is the old text-mode pickle format, 1 is the old binary
|
|
format, and now 2 is a new 2.3-specific format. A new constant,
|
|
\constant{pickle.HIGHEST_PROTOCOL}, can be used to select the fanciest
|
|
protocol available.
|
|
|
|
Unpickling is no longer considered a safe operation. 2.2's
|
|
\module{pickle} provided hooks for trying to prevent unsafe classes
|
|
from being unpickled (specifically, a
|
|
\member{__safe_for_unpickling__} attribute), but none of this code
|
|
was ever audited and therefore it's all been ripped out in 2.3. You
|
|
should not unpickle untrusted data in any version of Python.
|
|
|
|
To reduce the pickling overhead for new-style classes, a new interface
|
|
for customizing pickling was added using three special methods:
|
|
\method{__getstate__}, \method{__setstate__}, and
|
|
\method{__getnewargs__}. Consult \pep{307} for the full semantics
|
|
of these methods.
|
|
|
|
As a way to compress pickles yet further, it's now possible to use
|
|
integer codes instead of long strings to identify pickled classes.
|
|
The Python Software Foundation will maintain a list of standardized
|
|
codes; there's also a range of codes for private use. Currently no
|
|
codes have been specified.
|
|
|
|
\begin{seealso}
|
|
|
|
\seepep{307}{Extensions to the pickle protocol}{Written and implemented
|
|
by Guido van Rossum and Tim Peters.}
|
|
|
|
\end{seealso}
|
|
|
|
%======================================================================
|
|
\section{Extended Slices\label{section-slices}}
|
|
|
|
Ever since Python 1.4, the slicing syntax has supported an optional
|
|
third ``step'' or ``stride'' argument. For example, these are all
|
|
legal Python syntax: \code{L[1:10:2]}, \code{L[:-1:1]},
|
|
\code{L[::-1]}. This was added to Python at the request of
|
|
the developers of Numerical Python, which uses the third argument
|
|
extensively. However, Python's built-in list, tuple, and string
|
|
sequence types have never supported this feature, raising a
|
|
\exception{TypeError} if you tried it. Michael Hudson contributed a
|
|
patch to fix this shortcoming.
|
|
|
|
For example, you can now easily extract the elements of a list that
|
|
have even indexes:
|
|
|
|
\begin{verbatim}
|
|
>>> L = range(10)
|
|
>>> L[::2]
|
|
[0, 2, 4, 6, 8]
|
|
\end{verbatim}
|
|
|
|
Negative values also work to make a copy of the same list in reverse
|
|
order:
|
|
|
|
\begin{verbatim}
|
|
>>> L[::-1]
|
|
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
|
|
\end{verbatim}
|
|
|
|
This also works for tuples, arrays, and strings:
|
|
|
|
\begin{verbatim}
|
|
>>> s='abcd'
|
|
>>> s[::2]
|
|
'ac'
|
|
>>> s[::-1]
|
|
'dcba'
|
|
\end{verbatim}
|
|
|
|
If you have a mutable sequence such as a list or an array you can
|
|
assign to or delete an extended slice, but there are some differences
|
|
between assignment to extended and regular slices. Assignment to a
|
|
regular slice can be used to change the length of the sequence:
|
|
|
|
\begin{verbatim}
|
|
>>> a = range(3)
|
|
>>> a
|
|
[0, 1, 2]
|
|
>>> a[1:3] = [4, 5, 6]
|
|
>>> a
|
|
[0, 4, 5, 6]
|
|
\end{verbatim}
|
|
|
|
Extended slices aren't this flexible. When assigning to an extended
|
|
slice, the list on the right hand side of the statement must contain
|
|
the same number of items as the slice it is replacing:
|
|
|
|
\begin{verbatim}
|
|
>>> a = range(4)
|
|
>>> a
|
|
[0, 1, 2, 3]
|
|
>>> a[::2]
|
|
[0, 2]
|
|
>>> a[::2] = [0, -1]
|
|
>>> a
|
|
[0, 1, -1, 3]
|
|
>>> a[::2] = [0,1,2]
|
|
Traceback (most recent call last):
|
|
File "<stdin>", line 1, in ?
|
|
ValueError: attempt to assign sequence of size 3 to extended slice of size 2
|
|
\end{verbatim}
|
|
|
|
Deletion is more straightforward:
|
|
|
|
\begin{verbatim}
|
|
>>> a = range(4)
|
|
>>> a
|
|
[0, 1, 2, 3]
|
|
>>> a[::2]
|
|
[0, 2]
|
|
>>> del a[::2]
|
|
>>> a
|
|
[1, 3]
|
|
\end{verbatim}
|
|
|
|
One can also now pass slice objects to the
|
|
\method{__getitem__} methods of the built-in sequences:
|
|
|
|
\begin{verbatim}
|
|
>>> range(10).__getitem__(slice(0, 5, 2))
|
|
[0, 2, 4]
|
|
\end{verbatim}
|
|
|
|
Or use slice objects directly in subscripts:
|
|
|
|
\begin{verbatim}
|
|
>>> range(10)[slice(0, 5, 2)]
|
|
[0, 2, 4]
|
|
\end{verbatim}
|
|
|
|
To simplify implementing sequences that support extended slicing,
|
|
slice objects now have a method \method{indices(\var{length})} which,
|
|
given the length of a sequence, returns a \code{(\var{start},
|
|
\var{stop}, \var{step})} tuple that can be passed directly to
|
|
\function{range()}.
|
|
\method{indices()} handles omitted and out-of-bounds indices in a
|
|
manner consistent with regular slices (and this innocuous phrase hides
|
|
a welter of confusing details!). The method is intended to be used
|
|
like this:
|
|
|
|
\begin{verbatim}
|
|
class FakeSeq:
|
|
...
|
|
def calc_item(self, i):
|
|
...
|
|
def __getitem__(self, item):
|
|
if isinstance(item, slice):
|
|
indices = item.indices(len(self))
|
|
return FakeSeq([self.calc_item(i) for i in range(*indices)])
|
|
else:
|
|
return self.calc_item(i)
|
|
\end{verbatim}
|
|
|
|
From this example you can also see that the built-in \class{slice}
|
|
object is now the type object for the slice type, and is no longer a
|
|
function. This is consistent with Python 2.2, where \class{int},
|
|
\class{str}, etc., underwent the same change.
|
|
|
|
|
|
%======================================================================
|
|
\section{Other Language Changes}
|
|
|
|
Here are all of the changes that Python 2.3 makes to the core Python
|
|
language.
|
|
|
|
\begin{itemize}
|
|
\item The \keyword{yield} statement is now always a keyword, as
|
|
described in section~\ref{section-generators} of this document.
|
|
|
|
\item A new built-in function \function{enumerate()}
|
|
was added, as described in section~\ref{section-enumerate} of this
|
|
document.
|
|
|
|
\item Two new constants, \constant{True} and \constant{False} were
|
|
added along with the built-in \class{bool} type, as described in
|
|
section~\ref{section-bool} of this document.
|
|
|
|
\item The \function{int()} type constructor will now return a long
|
|
integer instead of raising an \exception{OverflowError} when a string
|
|
or floating-point number is too large to fit into an integer. This
|
|
can lead to the paradoxical result that
|
|
\code{isinstance(int(\var{expression}), int)} is false, but that seems
|
|
unlikely to cause problems in practice.
|
|
|
|
\item Built-in types now support the extended slicing syntax,
|
|
as described in section~\ref{section-slices} of this document.
|
|
|
|
\item A new built-in function, \function{sum(\var{iterable}, \var{start}=0)},
|
|
adds up the numeric items in the iterable object and returns their sum.
|
|
\function{sum()} only accepts numbers, meaning that you can't use it
|
|
to concatenate a bunch of strings. (Contributed by Alex
|
|
Martelli.)
|
|
|
|
\item \code{list.insert(\var{pos}, \var{value})} used to
|
|
insert \var{value} at the front of the list when \var{pos} was
|
|
negative. The behaviour has now been changed to be consistent with
|
|
slice indexing, so when \var{pos} is -1 the value will be inserted
|
|
before the last element, and so forth.
|
|
|
|
\item \code{list.index(\var{value})}, which searches for \var{value}
|
|
within the list and returns its index, now takes optional
|
|
\var{start} and \var{stop} arguments to limit the search to
|
|
only part of the list.
|
|
|
|
\item Dictionaries have a new method, \method{pop(\var{key}\optional{,
|
|
\var{default}})}, that returns the value corresponding to \var{key}
|
|
and removes that key/value pair from the dictionary. If the requested
|
|
key isn't present in the dictionary, \var{default} is returned if it's
|
|
specified and \exception{KeyError} raised if it isn't.
|
|
|
|
\begin{verbatim}
|
|
>>> d = {1:2}
|
|
>>> d
|
|
{1: 2}
|
|
>>> d.pop(4)
|
|
Traceback (most recent call last):
|
|
File "stdin", line 1, in ?
|
|
KeyError: 4
|
|
>>> d.pop(1)
|
|
2
|
|
>>> d.pop(1)
|
|
Traceback (most recent call last):
|
|
File "stdin", line 1, in ?
|
|
KeyError: 'pop(): dictionary is empty'
|
|
>>> d
|
|
{}
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
There's also a new class method,
|
|
\method{dict.fromkeys(\var{iterable}, \var{value})}, that
|
|
creates a dictionary with keys taken from the supplied iterator
|
|
\var{iterable} and all values set to \var{value}, defaulting to
|
|
\code{None}.
|
|
|
|
(Patches contributed by Raymond Hettinger.)
|
|
|
|
Also, the \function{dict()} constructor now accepts keyword arguments to
|
|
simplify creating small dictionaries:
|
|
|
|
\begin{verbatim}
|
|
>>> dict(red=1, blue=2, green=3, black=4)
|
|
{'blue': 2, 'black': 4, 'green': 3, 'red': 1}
|
|
\end{verbatim}
|
|
|
|
(Contributed by Just van~Rossum.)
|
|
|
|
\item The \keyword{assert} statement no longer checks the \code{__debug__}
|
|
flag, so you can no longer disable assertions by assigning to \code{__debug__}.
|
|
Running Python with the \programopt{-O} switch will still generate
|
|
code that doesn't execute any assertions.
|
|
|
|
\item Most type objects are now callable, so you can use them
|
|
to create new objects such as functions, classes, and modules. (This
|
|
means that the \module{new} module can be deprecated in a future
|
|
Python version, because you can now use the type objects available in
|
|
the \module{types} module.)
|
|
% XXX should new.py use PendingDeprecationWarning?
|
|
For example, you can create a new module object with the following code:
|
|
|
|
\begin{verbatim}
|
|
>>> import types
|
|
>>> m = types.ModuleType('abc','docstring')
|
|
>>> m
|
|
<module 'abc' (built-in)>
|
|
>>> m.__doc__
|
|
'docstring'
|
|
\end{verbatim}
|
|
|
|
\item
|
|
A new warning, \exception{PendingDeprecationWarning} was added to
|
|
indicate features which are in the process of being
|
|
deprecated. The warning will \emph{not} be printed by default. To
|
|
check for use of features that will be deprecated in the future,
|
|
supply \programopt{-Walways::PendingDeprecationWarning::} on the
|
|
command line or use \function{warnings.filterwarnings()}.
|
|
|
|
\item The process of deprecating string-based exceptions, as
|
|
in \code{raise "Error occurred"}, has begun. Raising a string will
|
|
now trigger \exception{PendingDeprecationWarning}.
|
|
|
|
\item Using \code{None} as a variable name will now result in a
|
|
\exception{SyntaxWarning} warning. In a future version of Python,
|
|
\code{None} may finally become a keyword.
|
|
|
|
\item The \method{xreadlines()} method of file objects, introduced in
|
|
Python 2.1, is no longer necessary because files now behave as their
|
|
own iterator. \method{xreadlines()} was originally introduced as a
|
|
faster way to loop over all the lines in a file, but now you can
|
|
simply write \code{for line in file_obj}. File objects also have a
|
|
new read-only \member{encoding} attribute that gives the encoding used
|
|
by the file; Unicode strings written to the file will be automatically
|
|
converted to bytes using the given encoding.
|
|
|
|
\item The method resolution order used by new-style classes has
|
|
changed, though you'll only notice the difference if you have a really
|
|
complicated inheritance hierarchy. Classic classes are unaffected by
|
|
this change. Python 2.2 originally used a topological sort of a
|
|
class's ancestors, but 2.3 now uses the C3 algorithm as described in
|
|
the paper \ulink{``A Monotonic Superclass Linearization for
|
|
Dylan''}{http://www.webcom.com/haahr/dylan/linearization-oopsla96.html}.
|
|
To understand the motivation for this change,
|
|
read Michele Simionato's article
|
|
\ulink{``Python 2.3 Method Resolution Order''}
|
|
{http://www.python.org/2.3/mro.html}, or
|
|
read the thread on python-dev starting with the message at
|
|
\url{http://mail.python.org/pipermail/python-dev/2002-October/029035.html}.
|
|
Samuele Pedroni first pointed out the problem and also implemented the
|
|
fix by coding the C3 algorithm.
|
|
|
|
\item Python runs multithreaded programs by switching between threads
|
|
after executing N bytecodes. The default value for N has been
|
|
increased from 10 to 100 bytecodes, speeding up single-threaded
|
|
applications by reducing the switching overhead. Some multithreaded
|
|
applications may suffer slower response time, but that's easily fixed
|
|
by setting the limit back to a lower number using
|
|
\function{sys.setcheckinterval(\var{N})}.
|
|
The limit can be retrieved with the new
|
|
\function{sys.getcheckinterval()} function.
|
|
|
|
\item One minor but far-reaching change is that the names of extension
|
|
types defined by the modules included with Python now contain the
|
|
module and a \character{.} in front of the type name. For example, in
|
|
Python 2.2, if you created a socket and printed its
|
|
\member{__class__}, you'd get this output:
|
|
|
|
\begin{verbatim}
|
|
>>> s = socket.socket()
|
|
>>> s.__class__
|
|
<type 'socket'>
|
|
\end{verbatim}
|
|
|
|
In 2.3, you get this:
|
|
\begin{verbatim}
|
|
>>> s.__class__
|
|
<type '_socket.socket'>
|
|
\end{verbatim}
|
|
|
|
\item One of the noted incompatibilities between old- and new-style
|
|
classes has been removed: you can now assign to the
|
|
\member{__name__} and \member{__bases__} attributes of new-style
|
|
classes. There are some restrictions on what can be assigned to
|
|
\member{__bases__} along the lines of those relating to assigning to
|
|
an instance's \member{__class__} attribute.
|
|
|
|
\end{itemize}
|
|
|
|
|
|
%======================================================================
|
|
\subsection{String Changes}
|
|
|
|
\begin{itemize}
|
|
|
|
\item The \keyword{in} operator now works differently for strings.
|
|
Previously, when evaluating \code{\var{X} in \var{Y}} where \var{X}
|
|
and \var{Y} are strings, \var{X} could only be a single character.
|
|
That's now changed; \var{X} can be a string of any length, and
|
|
\code{\var{X} in \var{Y}} will return \constant{True} if \var{X} is a
|
|
substring of \var{Y}. If \var{X} is the empty string, the result is
|
|
always \constant{True}.
|
|
|
|
\begin{verbatim}
|
|
>>> 'ab' in 'abcd'
|
|
True
|
|
>>> 'ad' in 'abcd'
|
|
False
|
|
>>> '' in 'abcd'
|
|
True
|
|
\end{verbatim}
|
|
|
|
Note that this doesn't tell you where the substring starts; if you
|
|
need that information, use the \method{find()} string method.
|
|
|
|
\item The \method{strip()}, \method{lstrip()}, and \method{rstrip()}
|
|
string methods now have an optional argument for specifying the
|
|
characters to strip. The default is still to remove all whitespace
|
|
characters:
|
|
|
|
\begin{verbatim}
|
|
>>> ' abc '.strip()
|
|
'abc'
|
|
>>> '><><abc<><><>'.strip('<>')
|
|
'abc'
|
|
>>> '><><abc<><><>\n'.strip('<>')
|
|
'abc<><><>\n'
|
|
>>> u'\u4000\u4001abc\u4000'.strip(u'\u4000')
|
|
u'\u4001abc'
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
(Suggested by Simon Brunning and implemented by Walter D\"orwald.)
|
|
|
|
\item The \method{startswith()} and \method{endswith()}
|
|
string methods now accept negative numbers for the \var{start} and \var{end}
|
|
parameters.
|
|
|
|
\item Another new string method is \method{zfill()}, originally a
|
|
function in the \module{string} module. \method{zfill()} pads a
|
|
numeric string with zeros on the left until it's the specified width.
|
|
Note that the \code{\%} operator is still more flexible and powerful
|
|
than \method{zfill()}.
|
|
|
|
\begin{verbatim}
|
|
>>> '45'.zfill(4)
|
|
'0045'
|
|
>>> '12345'.zfill(4)
|
|
'12345'
|
|
>>> 'goofy'.zfill(6)
|
|
'0goofy'
|
|
\end{verbatim}
|
|
|
|
(Contributed by Walter D\"orwald.)
|
|
|
|
\item A new type object, \class{basestring}, has been added.
|
|
Both 8-bit strings and Unicode strings inherit from this type, so
|
|
\code{isinstance(obj, basestring)} will return \constant{True} for
|
|
either kind of string. It's a completely abstract type, so you
|
|
can't create \class{basestring} instances.
|
|
|
|
\item Interned strings are no longer immortal and will now be
|
|
garbage-collected in the usual way when the only reference to them is
|
|
from the internal dictionary of interned strings. (Implemented by
|
|
Oren Tirosh.)
|
|
|
|
\end{itemize}
|
|
|
|
|
|
%======================================================================
|
|
\subsection{Optimizations}
|
|
|
|
\begin{itemize}
|
|
|
|
\item The creation of new-style class instances has been made much
|
|
faster; they're now faster than classic classes!
|
|
|
|
\item The \method{sort()} method of list objects has been extensively
|
|
rewritten by Tim Peters, and the implementation is significantly
|
|
faster.
|
|
|
|
\item Multiplication of large long integers is now much faster thanks
|
|
to an implementation of Karatsuba multiplication, an algorithm that
|
|
scales better than the O(n*n) required for the grade-school
|
|
multiplication algorithm. (Original patch by Christopher A. Craig,
|
|
and significantly reworked by Tim Peters.)
|
|
|
|
\item The \code{SET_LINENO} opcode is now gone. This may provide a
|
|
small speed increase, depending on your compiler's idiosyncrasies.
|
|
See section~\ref{section-other} for a longer explanation.
|
|
(Removed by Michael Hudson.)
|
|
|
|
\item \function{xrange()} objects now have their own iterator, making
|
|
\code{for i in xrange(n)} slightly faster than
|
|
\code{for i in range(n)}. (Patch by Raymond Hettinger.)
|
|
|
|
\item A number of small rearrangements have been made in various
|
|
hotspots to improve performance, such as inlining a function or removing
|
|
some code. (Implemented mostly by GvR, but lots of people have
|
|
contributed single changes.)
|
|
|
|
\end{itemize}
|
|
|
|
The net result of the 2.3 optimizations is that Python 2.3 runs the
|
|
pystone benchmark around 25\% faster than Python 2.2.
|
|
|
|
|
|
%======================================================================
|
|
\section{New, Improved, and Deprecated Modules}
|
|
|
|
As usual, Python's standard library received a number of enhancements and
|
|
bug fixes. Here's a partial list of the most notable changes, sorted
|
|
alphabetically by module name. Consult the
|
|
\file{Misc/NEWS} file in the source tree for a more
|
|
complete list of changes, or look through the CVS logs for all the
|
|
details.
|
|
|
|
\begin{itemize}
|
|
|
|
\item The \module{array} module now supports arrays of Unicode
|
|
characters using the \character{u} format character. Arrays also now
|
|
support using the \code{+=} assignment operator to add another array's
|
|
contents, and the \code{*=} assignment operator to repeat an array.
|
|
(Contributed by Jason Orendorff.)
|
|
|
|
\item The \module{bsddb} module has been replaced by version 4.1.6
|
|
of the \ulink{PyBSDDB}{http://pybsddb.sourceforge.net} package,
|
|
providing a more complete interface to the transactional features of
|
|
the BerkeleyDB library.
|
|
|
|
The old version of the module has been renamed to
|
|
\module{bsddb185} and is no longer built automatically; you'll
|
|
have to edit \file{Modules/Setup} to enable it. Note that the new
|
|
\module{bsddb} package is intended to be compatible with the
|
|
old module, so be sure to file bugs if you discover any
|
|
incompatibilities. When upgrading to Python 2.3, if the new interpreter is compiled
|
|
with a new version of
|
|
the underlying BerkeleyDB library, you will almost certainly have to
|
|
convert your database files to the new version. You can do this
|
|
fairly easily with the new scripts \file{db2pickle.py} and
|
|
\file{pickle2db.py} which you will find in the distribution's
|
|
\file{Tools/scripts} directory. If you've already been using the PyBSDDB
|
|
package and importing it as \module{bsddb3}, you will have to change your
|
|
\code{import} statements to import it as \module{bsddb}.
|
|
|
|
\item The new \module{bz2} module is an interface to the bz2 data
|
|
compression library. bz2-compressed data is usually smaller than
|
|
corresponding \module{zlib}-compressed data. (Contributed by Gustavo Niemeyer.)
|
|
|
|
\item A set of standard date/time types has been added in the new \module{datetime}
|
|
module. See the following section for more details.
|
|
|
|
\item The Distutils \class{Extension} class now supports
|
|
an extra constructor argument named \var{depends} for listing
|
|
additional source files that an extension depends on. This lets
|
|
Distutils recompile the module if any of the dependency files are
|
|
modified. For example, if \file{sampmodule.c} includes the header
|
|
file \file{sample.h}, you would create the \class{Extension} object like
|
|
this:
|
|
|
|
\begin{verbatim}
|
|
ext = Extension("samp",
|
|
sources=["sampmodule.c"],
|
|
depends=["sample.h"])
|
|
\end{verbatim}
|
|
|
|
Modifying \file{sample.h} would then cause the module to be recompiled.
|
|
(Contributed by Jeremy Hylton.)
|
|
|
|
\item Other minor changes to Distutils:
|
|
it now checks for the \envvar{CC}, \envvar{CFLAGS}, \envvar{CPP},
|
|
\envvar{LDFLAGS}, and \envvar{CPPFLAGS} environment variables, using
|
|
them to override the settings in Python's configuration (contributed
|
|
by Robert Weber).
|
|
|
|
\item Previously the \module{doctest} module would only search the
|
|
docstrings of public methods and functions for test cases, but it now
|
|
also examines private ones as well. The \function{DocTestSuite(}
|
|
function creates a \class{unittest.TestSuite} object from a set of
|
|
\module{doctest} tests.
|
|
|
|
\item The new \function{gc.get_referents(\var{object})} function returns a
|
|
list of all the objects referenced by \var{object}.
|
|
|
|
\item The \module{getopt} module gained a new function,
|
|
\function{gnu_getopt()}, that supports the same arguments as the existing
|
|
\function{getopt()} function but uses GNU-style scanning mode.
|
|
The existing \function{getopt()} stops processing options as soon as a
|
|
non-option argument is encountered, but in GNU-style mode processing
|
|
continues, meaning that options and arguments can be mixed. For
|
|
example:
|
|
|
|
\begin{verbatim}
|
|
>>> getopt.getopt(['-f', 'filename', 'output', '-v'], 'f:v')
|
|
([('-f', 'filename')], ['output', '-v'])
|
|
>>> getopt.gnu_getopt(['-f', 'filename', 'output', '-v'], 'f:v')
|
|
([('-f', 'filename'), ('-v', '')], ['output'])
|
|
\end{verbatim}
|
|
|
|
(Contributed by Peter \AA{strand}.)
|
|
|
|
\item The \module{grp}, \module{pwd}, and \module{resource} modules
|
|
now return enhanced tuples:
|
|
|
|
\begin{verbatim}
|
|
>>> import grp
|
|
>>> g = grp.getgrnam('amk')
|
|
>>> g.gr_name, g.gr_gid
|
|
('amk', 500)
|
|
\end{verbatim}
|
|
|
|
\item The \module{gzip} module can now handle files exceeding 2~GiB.
|
|
|
|
\item The new \module{heapq} module contains an implementation of a
|
|
heap queue algorithm. A heap is an array-like data structure that
|
|
keeps items in a partially sorted order such that, for every index
|
|
\var{k}, \code{heap[\var{k}] <= heap[2*\var{k}+1]} and
|
|
\code{heap[\var{k}] <= heap[2*\var{k}+2]}. This makes it quick to
|
|
remove the smallest item, and inserting a new item while maintaining
|
|
the heap property is O(lg~n). (See
|
|
\url{http://www.nist.gov/dads/HTML/priorityque.html} for more
|
|
information about the priority queue data structure.)
|
|
|
|
The \module{heapq} module provides \function{heappush()} and
|
|
\function{heappop()} functions for adding and removing items while
|
|
maintaining the heap property on top of some other mutable Python
|
|
sequence type. Here's an example that uses a Python list:
|
|
|
|
\begin{verbatim}
|
|
>>> import heapq
|
|
>>> heap = []
|
|
>>> for item in [3, 7, 5, 11, 1]:
|
|
... heapq.heappush(heap, item)
|
|
...
|
|
>>> heap
|
|
[1, 3, 5, 11, 7]
|
|
>>> heapq.heappop(heap)
|
|
1
|
|
>>> heapq.heappop(heap)
|
|
3
|
|
>>> heap
|
|
[5, 7, 11]
|
|
\end{verbatim}
|
|
|
|
(Contributed by Kevin O'Connor.)
|
|
|
|
\item The IDLE integrated development environment has been updated
|
|
using the code from the IDLEfork project
|
|
(\url{http://idlefork.sf.net}). The most notable feature is that the
|
|
code being developed is now executed in a subprocess, meaning that
|
|
there's no longer any need for manual \code{reload()} operations.
|
|
IDLE's core code has been incorporated into the standard library as the
|
|
\module{idlelib} package.
|
|
|
|
\item The \module{imaplib} module now supports IMAP over SSL.
|
|
(Contributed by Piers Lauder and Tino Lange.)
|
|
|
|
\item The \module{itertools} contains a number of useful functions for
|
|
use with iterators, inspired by various functions provided by the ML
|
|
and Haskell languages. For example,
|
|
\code{itertools.ifilter(predicate, iterator)} returns all elements in
|
|
the iterator for which the function \function{predicate()} returns
|
|
\constant{True}, and \code{itertools.repeat(obj, \var{N})} returns
|
|
\code{obj} \var{N} times. There are a number of other functions in
|
|
the module; see the \ulink{package's reference
|
|
documentation}{../lib/module-itertools.html} for details.
|
|
(Contributed by Raymond Hettinger.)
|
|
|
|
\item Two new functions in the \module{math} module,
|
|
\function{degrees(\var{rads})} and \function{radians(\var{degs})},
|
|
convert between radians and degrees. Other functions in the
|
|
\module{math} module such as \function{math.sin()} and
|
|
\function{math.cos()} have always required input values measured in
|
|
radians. Also, an optional \var{base} argument was added to
|
|
\function{math.log()} to make it easier to compute logarithms for
|
|
bases other than \code{e} and \code{10}. (Contributed by Raymond
|
|
Hettinger.)
|
|
|
|
\item Several new POSIX functions (\function{getpgid()}, \function{killpg()},
|
|
\function{lchown()}, \function{loadavg()}, \function{major()}, \function{makedev()},
|
|
\function{minor()}, and \function{mknod()}) were added to the
|
|
\module{posix} module that underlies the \module{os} module.
|
|
(Contributed by Gustavo Niemeyer, Geert Jansen, and Denis S. Otkidach.)
|
|
|
|
\item In the \module{os} module, the \function{*stat()} family of
|
|
functions can now report fractions of a second in a timestamp. Such
|
|
time stamps are represented as floats, similar to
|
|
the value returned by \function{time.time()}.
|
|
|
|
During testing, it was found that some applications will break if time
|
|
stamps are floats. For compatibility, when using the tuple interface
|
|
of the \class{stat_result} time stamps will be represented as integers.
|
|
When using named fields (a feature first introduced in Python 2.2),
|
|
time stamps are still represented as integers, unless
|
|
\function{os.stat_float_times()} is invoked to enable float return
|
|
values:
|
|
|
|
\begin{verbatim}
|
|
>>> os.stat("/tmp").st_mtime
|
|
1034791200
|
|
>>> os.stat_float_times(True)
|
|
>>> os.stat("/tmp").st_mtime
|
|
1034791200.6335014
|
|
\end{verbatim}
|
|
|
|
In Python 2.4, the default will change to always returning floats.
|
|
|
|
Application developers should enable this feature only if all their
|
|
libraries work properly when confronted with floating point time
|
|
stamps, or if they use the tuple API. If used, the feature should be
|
|
activated on an application level instead of trying to enable it on a
|
|
per-use basis.
|
|
|
|
\item The \module{optparse} module contains a new parser for command-line arguments
|
|
that can convert option values to a particular Python type
|
|
and will automatically generate a usage message. See the following section for
|
|
more details.
|
|
|
|
\item The old and never-documented \module{linuxaudiodev} module has
|
|
been deprecated, and a new version named \module{ossaudiodev} has been
|
|
added. The module was renamed because the OSS sound drivers can be
|
|
used on platforms other than Linux, and the interface has also been
|
|
tidied and brought up to date in various ways. (Contributed by Greg
|
|
Ward and Nicholas FitzRoy-Dale.)
|
|
|
|
\item The new \module{platform} module contains a number of functions
|
|
that try to determine various properties of the platform you're
|
|
running on. There are functions for getting the architecture, CPU
|
|
type, the Windows OS version, and even the Linux distribution version.
|
|
(Contributed by Marc-Andr\'e Lemburg.)
|
|
|
|
\item The parser objects provided by the \module{pyexpat} module
|
|
can now optionally buffer character data, resulting in fewer calls to
|
|
your character data handler and therefore faster performance. Setting
|
|
the parser object's \member{buffer_text} attribute to \constant{True}
|
|
will enable buffering.
|
|
|
|
\item The \function{sample(\var{population}, \var{k})} function was
|
|
added to the \module{random} module. \var{population} is a sequence or
|
|
\class{xrange} object containing the elements of a population, and
|
|
\function{sample()} chooses \var{k} elements from the population without
|
|
replacing chosen elements. \var{k} can be any value up to
|
|
\code{len(\var{population})}. For example:
|
|
|
|
\begin{verbatim}
|
|
>>> days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'St', 'Sn']
|
|
>>> random.sample(days, 3) # Choose 3 elements
|
|
['St', 'Sn', 'Th']
|
|
>>> random.sample(days, 7) # Choose 7 elements
|
|
['Tu', 'Th', 'Mo', 'We', 'St', 'Fr', 'Sn']
|
|
>>> random.sample(days, 7) # Choose 7 again
|
|
['We', 'Mo', 'Sn', 'Fr', 'Tu', 'St', 'Th']
|
|
>>> random.sample(days, 8) # Can't choose eight
|
|
Traceback (most recent call last):
|
|
File "<stdin>", line 1, in ?
|
|
File "random.py", line 414, in sample
|
|
raise ValueError, "sample larger than population"
|
|
ValueError: sample larger than population
|
|
>>> random.sample(xrange(1,10000,2), 10) # Choose ten odd nos. under 10000
|
|
[3407, 3805, 1505, 7023, 2401, 2267, 9733, 3151, 8083, 9195]
|
|
\end{verbatim}
|
|
|
|
The \module{random} module now uses a new algorithm, the Mersenne
|
|
Twister, implemented in C. It's faster and more extensively studied
|
|
than the previous algorithm.
|
|
|
|
(All changes contributed by Raymond Hettinger.)
|
|
|
|
\item The \module{readline} module also gained a number of new
|
|
functions: \function{get_history_item()},
|
|
\function{get_current_history_length()}, and \function{redisplay()}.
|
|
|
|
\item The \module{rexec} and \module{Bastion} modules have been
|
|
declared dead, and attempts to import them will fail with a
|
|
\exception{RuntimeError}. New-style classes provide new ways to break
|
|
out of the restricted execution environment provided by
|
|
\module{rexec}, and no one has interest in fixing them or time to do
|
|
so. If you have applications using \module{rexec}, rewrite them to
|
|
use something else.
|
|
|
|
(Sticking with Python 2.2 or 2.1 will not make your applications any
|
|
safer because there are known bugs in the \module{rexec} module in
|
|
those versions. To repeat: if you're using \module{rexec}, stop using
|
|
it immediately.)
|
|
|
|
\item The \module{rotor} module has been deprecated because the
|
|
algorithm it uses for encryption is not believed to be secure. If
|
|
you need encryption, use one of the several AES Python modules
|
|
that are available separately.
|
|
|
|
\item The \module{shutil} module gained a \function{move(\var{src},
|
|
\var{dest})} function that recursively moves a file or directory to a new
|
|
location.
|
|
|
|
\item Support for more advanced POSIX signal handling was added
|
|
to the \module{signal} but then removed again as it proved impossible
|
|
to make it work reliably across platforms.
|
|
|
|
\item The \module{socket} module now supports timeouts. You
|
|
can call the \method{settimeout(\var{t})} method on a socket object to
|
|
set a timeout of \var{t} seconds. Subsequent socket operations that
|
|
take longer than \var{t} seconds to complete will abort and raise a
|
|
\exception{socket.timeout} exception.
|
|
|
|
The original timeout implementation was by Tim O'Malley. Michael
|
|
Gilfix integrated it into the Python \module{socket} module and
|
|
shepherded it through a lengthy review. After the code was checked
|
|
in, Guido van~Rossum rewrote parts of it. (This is a good example of
|
|
a collaborative development process in action.)
|
|
|
|
\item On Windows, the \module{socket} module now ships with Secure
|
|
Sockets Layer (SSL) support.
|
|
|
|
\item The value of the C \constant{PYTHON_API_VERSION} macro is now
|
|
exposed at the Python level as \code{sys.api_version}. The current
|
|
exception can be cleared by calling the new \function{sys.exc_clear()}
|
|
function.
|
|
|
|
\item The new \module{tarfile} module
|
|
allows reading from and writing to \program{tar}-format archive files.
|
|
(Contributed by Lars Gust\"abel.)
|
|
|
|
\item The new \module{textwrap} module contains functions for wrapping
|
|
strings containing paragraphs of text. The \function{wrap(\var{text},
|
|
\var{width})} function takes a string and returns a list containing
|
|
the text split into lines of no more than the chosen width. The
|
|
\function{fill(\var{text}, \var{width})} function returns a single
|
|
string, reformatted to fit into lines no longer than the chosen width.
|
|
(As you can guess, \function{fill()} is built on top of
|
|
\function{wrap()}. For example:
|
|
|
|
\begin{verbatim}
|
|
>>> import textwrap
|
|
>>> paragraph = "Not a whit, we defy augury: ... more text ..."
|
|
>>> textwrap.wrap(paragraph, 60)
|
|
["Not a whit, we defy augury: there's a special providence in",
|
|
"the fall of a sparrow. If it be now, 'tis not to come; if it",
|
|
...]
|
|
>>> print textwrap.fill(paragraph, 35)
|
|
Not a whit, we defy augury: there's
|
|
a special providence in the fall of
|
|
a sparrow. If it be now, 'tis not
|
|
to come; if it be not to come, it
|
|
will be now; if it be not now, yet
|
|
it will come: the readiness is all.
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
The module also contains a \class{TextWrapper} class that actually
|
|
implements the text wrapping strategy. Both the
|
|
\class{TextWrapper} class and the \function{wrap()} and
|
|
\function{fill()} functions support a number of additional keyword
|
|
arguments for fine-tuning the formatting; consult the \ulink{module's
|
|
documentation}{../lib/module-textwrap.html} for details.
|
|
(Contributed by Greg Ward.)
|
|
|
|
\item The \module{thread} and \module{threading} modules now have
|
|
companion modules, \module{dummy_thread} and \module{dummy_threading},
|
|
that provide a do-nothing implementation of the \module{thread}
|
|
module's interface for platforms where threads are not supported. The
|
|
intention is to simplify thread-aware modules (ones that \emph{don't}
|
|
rely on threads to run) by putting the following code at the top:
|
|
|
|
\begin{verbatim}
|
|
try:
|
|
import threading as _threading
|
|
except ImportError:
|
|
import dummy_threading as _threading
|
|
\end{verbatim}
|
|
|
|
In this example, \module{_threading} is used as the module name to make
|
|
it clear that the module being used is not necessarily the actual
|
|
\module{threading} module. Code can call functions and use classes in
|
|
\module{_threading} whether or not threads are supported, avoiding an
|
|
\keyword{if} statement and making the code slightly clearer. This
|
|
module will not magically make multithreaded code run without threads;
|
|
code that waits for another thread to return or to do something will
|
|
simply hang forever.
|
|
|
|
\item The \module{time} module's \function{strptime()} function has
|
|
long been an annoyance because it uses the platform C library's
|
|
\function{strptime()} implementation, and different platforms
|
|
sometimes have odd bugs. Brett Cannon contributed a portable
|
|
implementation that's written in pure Python and should behave
|
|
identically on all platforms.
|
|
|
|
\item The new \module{timeit} module helps measure how long snippets
|
|
of Python code take to execute. The \file{timeit.py} file can be run
|
|
directly from the command line, or the module's \class{Timer} class
|
|
can be imported and used directly. Here's a short example that
|
|
figures out whether it's faster to convert an 8-bit string to Unicode
|
|
by appending an empty Unicode string to it or by using the
|
|
\function{unicode()} function:
|
|
|
|
\begin{verbatim}
|
|
import timeit
|
|
|
|
timer1 = timeit.Timer('unicode("abc")')
|
|
timer2 = timeit.Timer('"abc" + u""')
|
|
|
|
# Run three trials
|
|
print timer1.repeat(repeat=3, number=100000)
|
|
print timer2.repeat(repeat=3, number=100000)
|
|
|
|
# On my laptop this outputs:
|
|
# [0.36831796169281006, 0.37441694736480713, 0.35304892063140869]
|
|
# [0.17574405670166016, 0.18193507194519043, 0.17565798759460449]
|
|
\end{verbatim}
|
|
|
|
\item The \module{Tix} module has received various bug fixes and
|
|
updates for the current version of the Tix package.
|
|
|
|
\item The \module{Tkinter} module now works with a thread-enabled
|
|
version of Tcl. Tcl's threading model requires that widgets only be
|
|
accessed from the thread in which they're created; accesses from
|
|
another thread can cause Tcl to panic. For certain Tcl interfaces,
|
|
\module{Tkinter} will now automatically avoid this
|
|
when a widget is accessed from a different thread by marshalling a
|
|
command, passing it to the correct thread, and waiting for the
|
|
results. Other interfaces can't be handled automatically but
|
|
\module{Tkinter} will now raise an exception on such an access so that
|
|
you can at least find out about the problem. See
|
|
\url{http://mail.python.org/pipermail/python-dev/2002-December/031107.html} %
|
|
for a more detailed explanation of this change. (Implemented by
|
|
Martin von~L\"owis.)
|
|
|
|
\item Calling Tcl methods through \module{_tkinter} no longer
|
|
returns only strings. Instead, if Tcl returns other objects those
|
|
objects are converted to their Python equivalent, if one exists, or
|
|
wrapped with a \class{_tkinter.Tcl_Obj} object if no Python equivalent
|
|
exists. This behavior can be controlled through the
|
|
\method{wantobjects()} method of \class{tkapp} objects.
|
|
|
|
When using \module{_tkinter} through the \module{Tkinter} module (as
|
|
most Tkinter applications will), this feature is always activated. It
|
|
should not cause compatibility problems, since Tkinter would always
|
|
convert string results to Python types where possible.
|
|
|
|
If any incompatibilities are found, the old behavior can be restored
|
|
by setting the \member{wantobjects} variable in the \module{Tkinter}
|
|
module to false before creating the first \class{tkapp} object.
|
|
|
|
\begin{verbatim}
|
|
import Tkinter
|
|
Tkinter.wantobjects = 0
|
|
\end{verbatim}
|
|
|
|
Any breakage caused by this change should be reported as a bug.
|
|
|
|
\item The \module{UserDict} module has a new \class{DictMixin} class which
|
|
defines all dictionary methods for classes that already have a minimum
|
|
mapping interface. This greatly simplifies writing classes that need
|
|
to be substitutable for dictionaries, such as the classes in
|
|
the \module{shelve} module.
|
|
|
|
Adding the mix-in as a superclass provides the full dictionary
|
|
interface whenever the class defines \method{__getitem__},
|
|
\method{__setitem__}, \method{__delitem__}, and \method{keys}.
|
|
For example:
|
|
|
|
\begin{verbatim}
|
|
>>> import UserDict
|
|
>>> class SeqDict(UserDict.DictMixin):
|
|
... """Dictionary lookalike implemented with lists."""
|
|
... def __init__(self):
|
|
... self.keylist = []
|
|
... self.valuelist = []
|
|
... def __getitem__(self, key):
|
|
... try:
|
|
... i = self.keylist.index(key)
|
|
... except ValueError:
|
|
... raise KeyError
|
|
... return self.valuelist[i]
|
|
... def __setitem__(self, key, value):
|
|
... try:
|
|
... i = self.keylist.index(key)
|
|
... self.valuelist[i] = value
|
|
... except ValueError:
|
|
... self.keylist.append(key)
|
|
... self.valuelist.append(value)
|
|
... def __delitem__(self, key):
|
|
... try:
|
|
... i = self.keylist.index(key)
|
|
... except ValueError:
|
|
... raise KeyError
|
|
... self.keylist.pop(i)
|
|
... self.valuelist.pop(i)
|
|
... def keys(self):
|
|
... return list(self.keylist)
|
|
...
|
|
>>> s = SeqDict()
|
|
>>> dir(s) # See that other dictionary methods are implemented
|
|
['__cmp__', '__contains__', '__delitem__', '__doc__', '__getitem__',
|
|
'__init__', '__iter__', '__len__', '__module__', '__repr__',
|
|
'__setitem__', 'clear', 'get', 'has_key', 'items', 'iteritems',
|
|
'iterkeys', 'itervalues', 'keylist', 'keys', 'pop', 'popitem',
|
|
'setdefault', 'update', 'valuelist', 'values']
|
|
\end{verbatim}
|
|
|
|
(Contributed by Raymond Hettinger.)
|
|
|
|
\item The DOM implementation
|
|
in \module{xml.dom.minidom} can now generate XML output in a
|
|
particular encoding by providing an optional encoding argument to
|
|
the \method{toxml()} and \method{toprettyxml()} methods of DOM nodes.
|
|
|
|
\item The \module{xmlrpclib} module now supports an XML-RPC extension
|
|
for handling nil data values such as Python's \code{None}. Nil values
|
|
are always supported on unmarshalling an XML-RPC response. To
|
|
generate requests containing \code{None}, you must supply a true value
|
|
for the \var{allow_none} parameter when creating a \class{Marshaller}
|
|
instance.
|
|
|
|
\item The new \module{DocXMLRPCServer} module allows writing
|
|
self-documenting XML-RPC servers. Run it in demo mode (as a program)
|
|
to see it in action. Pointing the Web browser to the RPC server
|
|
produces pydoc-style documentation; pointing xmlrpclib to the
|
|
server allows invoking the actual methods.
|
|
(Contributed by Brian Quinlan.)
|
|
|
|
\item Support for internationalized domain names (RFCs 3454, 3490,
|
|
3491, and 3492) has been added. The ``idna'' encoding can be used
|
|
to convert between a Unicode domain name and the ASCII-compatible
|
|
encoding (ACE) of that name.
|
|
|
|
\begin{alltt}
|
|
>{}>{}> u"www.Alliancefran\c caise.nu".encode("idna")
|
|
'www.xn--alliancefranaise-npb.nu'
|
|
\end{alltt}
|
|
|
|
The \module{socket} module has also been extended to transparently
|
|
convert Unicode hostnames to the ACE version before passing them to
|
|
the C library. Modules that deal with hostnames such as
|
|
\module{httplib} and \module{ftplib}) also support Unicode host names;
|
|
\module{httplib} also sends HTTP \samp{Host} headers using the ACE
|
|
version of the domain name. \module{urllib} supports Unicode URLs
|
|
with non-ASCII host names as long as the \code{path} part of the URL
|
|
is ASCII only.
|
|
|
|
To implement this change, the \module{stringprep} module, the
|
|
\code{mkstringprep} tool and the \code{punycode} encoding have been added.
|
|
|
|
\end{itemize}
|
|
|
|
|
|
%======================================================================
|
|
\subsection{Date/Time Type}
|
|
|
|
Date and time types suitable for expressing timestamps were added as
|
|
the \module{datetime} module. The types don't support different
|
|
calendars or many fancy features, and just stick to the basics of
|
|
representing time.
|
|
|
|
The three primary types are: \class{date}, representing a day, month,
|
|
and year; \class{time}, consisting of hour, minute, and second; and
|
|
\class{datetime}, which contains all the attributes of both
|
|
\class{date} and \class{time}. There's also a
|
|
\class{timedelta} class representing differences between two points
|
|
in time, and time zone logic is implemented by classes inheriting from
|
|
the abstract \class{tzinfo} class.
|
|
|
|
You can create instances of \class{date} and \class{time} by either
|
|
supplying keyword arguments to the appropriate constructor,
|
|
e.g. \code{datetime.date(year=1972, month=10, day=15)}, or by using
|
|
one of a number of class methods. For example, the \method{date.today()}
|
|
class method returns the current local date.
|
|
|
|
Once created, instances of the date/time classes are all immutable.
|
|
There are a number of methods for producing formatted strings from
|
|
objects:
|
|
|
|
\begin{verbatim}
|
|
>>> import datetime
|
|
>>> now = datetime.datetime.now()
|
|
>>> now.isoformat()
|
|
'2002-12-30T21:27:03.994956'
|
|
>>> now.ctime() # Only available on date, datetime
|
|
'Mon Dec 30 21:27:03 2002'
|
|
>>> now.strftime('%Y %d %b')
|
|
'2002 30 Dec'
|
|
\end{verbatim}
|
|
|
|
The \method{replace()} method allows modifying one or more fields
|
|
of a \class{date} or \class{datetime} instance, returning a new instance:
|
|
|
|
\begin{verbatim}
|
|
>>> d = datetime.datetime.now()
|
|
>>> d
|
|
datetime.datetime(2002, 12, 30, 22, 15, 38, 827738)
|
|
>>> d.replace(year=2001, hour = 12)
|
|
datetime.datetime(2001, 12, 30, 12, 15, 38, 827738)
|
|
>>>
|
|
\end{verbatim}
|
|
|
|
Instances can be compared, hashed, and converted to strings (the
|
|
result is the same as that of \method{isoformat()}). \class{date} and
|
|
\class{datetime} instances can be subtracted from each other, and
|
|
added to \class{timedelta} instances. The largest missing feature is
|
|
that there's no standard library support for parsing strings and getting back a
|
|
\class{date} or \class{datetime}.
|
|
|
|
For more information, refer to the \ulink{module's reference
|
|
documentation}{../lib/module-datetime.html}.
|
|
(Contributed by Tim Peters.)
|
|
|
|
|
|
%======================================================================
|
|
\subsection{The optparse Module}
|
|
|
|
The \module{getopt} module provides simple parsing of command-line
|
|
arguments. The new \module{optparse} module (originally named Optik)
|
|
provides more elaborate command-line parsing that follows the \UNIX{}
|
|
conventions, automatically creates the output for \longprogramopt{help},
|
|
and can perform different actions for different options.
|
|
|
|
You start by creating an instance of \class{OptionParser} and telling
|
|
it what your program's options are.
|
|
|
|
\begin{verbatim}
|
|
import sys
|
|
from optparse import OptionParser
|
|
|
|
op = OptionParser()
|
|
op.add_option('-i', '--input',
|
|
action='store', type='string', dest='input',
|
|
help='set input filename')
|
|
op.add_option('-l', '--length',
|
|
action='store', type='int', dest='length',
|
|
help='set maximum length of output')
|
|
\end{verbatim}
|
|
|
|
Parsing a command line is then done by calling the \method{parse_args()}
|
|
method.
|
|
|
|
\begin{verbatim}
|
|
options, args = op.parse_args(sys.argv[1:])
|
|
print options
|
|
print args
|
|
\end{verbatim}
|
|
|
|
This returns an object containing all of the option values,
|
|
and a list of strings containing the remaining arguments.
|
|
|
|
Invoking the script with the various arguments now works as you'd
|
|
expect it to. Note that the length argument is automatically
|
|
converted to an integer.
|
|
|
|
\begin{verbatim}
|
|
$ ./python opt.py -i data arg1
|
|
<Values at 0x400cad4c: {'input': 'data', 'length': None}>
|
|
['arg1']
|
|
$ ./python opt.py --input=data --length=4
|
|
<Values at 0x400cad2c: {'input': 'data', 'length': 4}>
|
|
[]
|
|
$
|
|
\end{verbatim}
|
|
|
|
The help message is automatically generated for you:
|
|
|
|
\begin{verbatim}
|
|
$ ./python opt.py --help
|
|
usage: opt.py [options]
|
|
|
|
options:
|
|
-h, --help show this help message and exit
|
|
-iINPUT, --input=INPUT
|
|
set input filename
|
|
-lLENGTH, --length=LENGTH
|
|
set maximum length of output
|
|
$
|
|
\end{verbatim}
|
|
% $ prevent Emacs tex-mode from getting confused
|
|
|
|
See the \ulink{module's documentation}{../lib/module-optparse.html}
|
|
for more details.
|
|
|
|
Optik was written by Greg Ward, with suggestions from the readers of
|
|
the Getopt SIG.
|
|
|
|
|
|
%======================================================================
|
|
\section{Pymalloc: A Specialized Object Allocator\label{section-pymalloc}}
|
|
|
|
Pymalloc, a specialized object allocator written by Vladimir
|
|
Marangozov, was a feature added to Python 2.1. Pymalloc is intended
|
|
to be faster than the system \cfunction{malloc()} and to have less
|
|
memory overhead for allocation patterns typical of Python programs.
|
|
The allocator uses C's \cfunction{malloc()} function to get large
|
|
pools of memory and then fulfills smaller memory requests from these
|
|
pools.
|
|
|
|
In 2.1 and 2.2, pymalloc was an experimental feature and wasn't
|
|
enabled by default; you had to explicitly enable it when compiling
|
|
Python by providing the
|
|
\longprogramopt{with-pymalloc} option to the \program{configure}
|
|
script. In 2.3, pymalloc has had further enhancements and is now
|
|
enabled by default; you'll have to supply
|
|
\longprogramopt{without-pymalloc} to disable it.
|
|
|
|
This change is transparent to code written in Python; however,
|
|
pymalloc may expose bugs in C extensions. Authors of C extension
|
|
modules should test their code with pymalloc enabled,
|
|
because some incorrect code may cause core dumps at runtime.
|
|
|
|
There's one particularly common error that causes problems. There are
|
|
a number of memory allocation functions in Python's C API that have
|
|
previously just been aliases for the C library's \cfunction{malloc()}
|
|
and \cfunction{free()}, meaning that if you accidentally called
|
|
mismatched functions the error wouldn't be noticeable. When the
|
|
object allocator is enabled, these functions aren't aliases of
|
|
\cfunction{malloc()} and \cfunction{free()} any more, and calling the
|
|
wrong function to free memory may get you a core dump. For example,
|
|
if memory was allocated using \cfunction{PyObject_Malloc()}, it has to
|
|
be freed using \cfunction{PyObject_Free()}, not \cfunction{free()}. A
|
|
few modules included with Python fell afoul of this and had to be
|
|
fixed; doubtless there are more third-party modules that will have the
|
|
same problem.
|
|
|
|
As part of this change, the confusing multiple interfaces for
|
|
allocating memory have been consolidated down into two API families.
|
|
Memory allocated with one family must not be manipulated with
|
|
functions from the other family. There is one family for allocating
|
|
chunks of memory and another family of functions specifically for
|
|
allocating Python objects.
|
|
|
|
\begin{itemize}
|
|
\item To allocate and free an undistinguished chunk of memory use
|
|
the ``raw memory'' family: \cfunction{PyMem_Malloc()},
|
|
\cfunction{PyMem_Realloc()}, and \cfunction{PyMem_Free()}.
|
|
|
|
\item The ``object memory'' family is the interface to the pymalloc
|
|
facility described above and is biased towards a large number of
|
|
``small'' allocations: \cfunction{PyObject_Malloc},
|
|
\cfunction{PyObject_Realloc}, and \cfunction{PyObject_Free}.
|
|
|
|
\item To allocate and free Python objects, use the ``object'' family
|
|
\cfunction{PyObject_New()}, \cfunction{PyObject_NewVar()}, and
|
|
\cfunction{PyObject_Del()}.
|
|
\end{itemize}
|
|
|
|
Thanks to lots of work by Tim Peters, pymalloc in 2.3 also provides
|
|
debugging features to catch memory overwrites and doubled frees in
|
|
both extension modules and in the interpreter itself. To enable this
|
|
support, compile a debugging version of the Python interpreter by
|
|
running \program{configure} with \longprogramopt{with-pydebug}.
|
|
|
|
To aid extension writers, a header file \file{Misc/pymemcompat.h} is
|
|
distributed with the source to Python 2.3 that allows Python
|
|
extensions to use the 2.3 interfaces to memory allocation while
|
|
compiling against any version of Python since 1.5.2. You would copy
|
|
the file from Python's source distribution and bundle it with the
|
|
source of your extension.
|
|
|
|
\begin{seealso}
|
|
|
|
\seeurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c}
|
|
{For the full details of the pymalloc implementation, see
|
|
the comments at the top of the file \file{Objects/obmalloc.c} in the
|
|
Python source code. The above link points to the file within the
|
|
SourceForge CVS browser.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
% ======================================================================
|
|
\section{Build and C API Changes}
|
|
|
|
Changes to Python's build process and to the C API include:
|
|
|
|
\begin{itemize}
|
|
|
|
\item The cycle detection implementation used by the garbage collection
|
|
has proven to be stable, so it's now been made mandatory. You can no
|
|
longer compile Python without it, and the
|
|
\longprogramopt{with-cycle-gc} switch to \program{configure} has been removed.
|
|
|
|
\item Python can now optionally be built as a shared library
|
|
(\file{libpython2.3.so}) by supplying \longprogramopt{enable-shared}
|
|
when running Python's \program{configure} script. (Contributed by Ondrej
|
|
Palkovsky.)
|
|
|
|
\item The \csimplemacro{DL_EXPORT} and \csimplemacro{DL_IMPORT} macros
|
|
are now deprecated. Initialization functions for Python extension
|
|
modules should now be declared using the new macro
|
|
\csimplemacro{PyMODINIT_FUNC}, while the Python core will generally
|
|
use the \csimplemacro{PyAPI_FUNC} and \csimplemacro{PyAPI_DATA}
|
|
macros.
|
|
|
|
\item The interpreter can be compiled without any docstrings for
|
|
the built-in functions and modules by supplying
|
|
\longprogramopt{without-doc-strings} to the \program{configure} script.
|
|
This makes the Python executable about 10\% smaller, but will also
|
|
mean that you can't get help for Python's built-ins. (Contributed by
|
|
Gustavo Niemeyer.)
|
|
|
|
\item The \cfunction{PyArg_NoArgs()} macro is now deprecated, and code
|
|
that uses it should be changed. For Python 2.2 and later, the method
|
|
definition table can specify the
|
|
\constant{METH_NOARGS} flag, signalling that there are no arguments, and
|
|
the argument checking can then be removed. If compatibility with
|
|
pre-2.2 versions of Python is important, the code could use
|
|
\code{PyArg_ParseTuple(\var{args}, "")} instead, but this will be slower
|
|
than using \constant{METH_NOARGS}.
|
|
|
|
\item \cfunction{PyArg_ParseTuple()} accepts new format characters for various sizes of unsigned integers: \samp{B} for \ctype{unsigned char},
|
|
\samp{H} for \ctype{unsigned short int},
|
|
\samp{I} for \ctype{unsigned int},
|
|
and \samp{K} for \ctype{unsigned long long}.
|
|
|
|
\item A new function, \cfunction{PyObject_DelItemString(\var{mapping},
|
|
char *\var{key})} was added as shorthand for
|
|
\code{PyObject_DelItem(\var{mapping}, PyString_New(\var{key}))}.
|
|
|
|
\item File objects now manage their internal string buffer
|
|
differently, increasing it exponentially when needed. This results in
|
|
the benchmark tests in \file{Lib/test/test_bufio.py} speeding up
|
|
considerably (from 57 seconds to 1.7 seconds, according to one
|
|
measurement).
|
|
|
|
\item It's now possible to define class and static methods for a C
|
|
extension type by setting either the \constant{METH_CLASS} or
|
|
\constant{METH_STATIC} flags in a method's \ctype{PyMethodDef}
|
|
structure.
|
|
|
|
\item Python now includes a copy of the Expat XML parser's source code,
|
|
removing any dependence on a system version or local installation of
|
|
Expat.
|
|
|
|
\item If you dynamically allocate type objects in your extension, you
|
|
should be aware of a change in the rules relating to the
|
|
\member{__module__} and \member{__name__} attributes. In summary,
|
|
you will want to ensure the type's dictionary contains a
|
|
\code{'__module__'} key; making the module name the part of the type
|
|
name leading up to the final period will no longer have the desired
|
|
effect. For more detail, read the API reference documentation or the
|
|
source.
|
|
|
|
\end{itemize}
|
|
|
|
|
|
%======================================================================
|
|
\subsection{Port-Specific Changes}
|
|
|
|
Support for a port to IBM's OS/2 using the EMX runtime environment was
|
|
merged into the main Python source tree. EMX is a POSIX emulation
|
|
layer over the OS/2 system APIs. The Python port for EMX tries to
|
|
support all the POSIX-like capability exposed by the EMX runtime, and
|
|
mostly succeeds; \function{fork()} and \function{fcntl()} are
|
|
restricted by the limitations of the underlying emulation layer. The
|
|
standard OS/2 port, which uses IBM's Visual Age compiler, also gained
|
|
support for case-sensitive import semantics as part of the integration
|
|
of the EMX port into CVS. (Contributed by Andrew MacIntyre.)
|
|
|
|
On MacOS, most toolbox modules have been weaklinked to improve
|
|
backward compatibility. This means that modules will no longer fail
|
|
to load if a single routine is missing on the current OS version.
|
|
Instead calling the missing routine will raise an exception.
|
|
(Contributed by Jack Jansen.)
|
|
|
|
The RPM spec files, found in the \file{Misc/RPM/} directory in the
|
|
Python source distribution, were updated for 2.3. (Contributed by
|
|
Sean Reifschneider.)
|
|
|
|
Other new platforms now supported by Python include AtheOS
|
|
(\url{http://www.atheos.cx/}), GNU/Hurd, and OpenVMS.
|
|
|
|
|
|
%======================================================================
|
|
\section{Other Changes and Fixes \label{section-other}}
|
|
|
|
As usual, there were a bunch of other improvements and bugfixes
|
|
scattered throughout the source tree. A search through the CVS change
|
|
logs finds there were 523 patches applied and 514 bugs fixed between
|
|
Python 2.2 and 2.3. Both figures are likely to be underestimates.
|
|
|
|
Some of the more notable changes are:
|
|
|
|
\begin{itemize}
|
|
|
|
\item If the \envvar{PYTHONINSPECT} environment variable is set, the
|
|
Python interpreter will enter the interactive prompt after running a
|
|
Python program, as if Python had been invoked with the \programopt{-i}
|
|
option. The environment variable can be set before running the Python
|
|
interpreter, or it can be set by the Python program as part of its
|
|
execution.
|
|
|
|
\item The \file{regrtest.py} script now provides a way to allow ``all
|
|
resources except \var{foo}.'' A resource name passed to the
|
|
\programopt{-u} option can now be prefixed with a hyphen
|
|
(\character{-}) to mean ``remove this resource.'' For example, the
|
|
option `\code{\programopt{-u}all,-bsddb}' could be used to enable the
|
|
use of all resources except \code{bsddb}.
|
|
|
|
\item The tools used to build the documentation now work under Cygwin
|
|
as well as \UNIX.
|
|
|
|
\item The \code{SET_LINENO} opcode has been removed. Back in the
|
|
mists of time, this opcode was needed to produce line numbers in
|
|
tracebacks and support trace functions (for, e.g., \module{pdb}).
|
|
Since Python 1.5, the line numbers in tracebacks have been computed
|
|
using a different mechanism that works with ``python -O''. For Python
|
|
2.3 Michael Hudson implemented a similar scheme to determine when to
|
|
call the trace function, removing the need for \code{SET_LINENO}
|
|
entirely.
|
|
|
|
It would be difficult to detect any resulting difference from Python
|
|
code, apart from a slight speed up when Python is run without
|
|
\programopt{-O}.
|
|
|
|
C extensions that access the \member{f_lineno} field of frame objects
|
|
should instead call \code{PyCode_Addr2Line(f->f_code, f->f_lasti)}.
|
|
This will have the added effect of making the code work as desired
|
|
under ``python -O'' in earlier versions of Python.
|
|
|
|
A nifty new feature is that trace functions can now assign to the
|
|
\member{f_lineno} attribute of frame objects, changing the line that
|
|
will be executed next. A \samp{jump} command has been added to the
|
|
\module{pdb} debugger taking advantage of this new feature.
|
|
(Implemented by Richie Hindle.)
|
|
|
|
\end{itemize}
|
|
|
|
|
|
%======================================================================
|
|
\section{Porting to Python 2.3}
|
|
|
|
This section lists previously described changes that may require
|
|
changes to your code:
|
|
|
|
\begin{itemize}
|
|
|
|
\item \keyword{yield} is now always a keyword; if it's used as a
|
|
variable name in your code, a different name must be chosen.
|
|
|
|
\item For strings \var{X} and \var{Y}, \code{\var{X} in \var{Y}} now works
|
|
if \var{X} is more than one character long.
|
|
|
|
\item The \function{int()} type constructor will now return a long
|
|
integer instead of raising an \exception{OverflowError} when a string
|
|
or floating-point number is too large to fit into an integer.
|
|
|
|
\item If you have Unicode strings that contain 8-bit characters, you
|
|
must declare the file's encoding (UTF-8, Latin-1, or whatever) by
|
|
adding a comment to the top of the file. See
|
|
section~\ref{section-encodings} for more information.
|
|
|
|
\item Calling Tcl methods through \module{_tkinter} no longer
|
|
returns only strings. Instead, if Tcl returns other objects those
|
|
objects are converted to their Python equivalent, if one exists, or
|
|
wrapped with a \class{_tkinter.Tcl_Obj} object if no Python equivalent
|
|
exists.
|
|
|
|
\item Large octal and hex literals such as
|
|
\code{0xffffffff} now trigger a \exception{FutureWarning}. Currently
|
|
they're stored as 32-bit numbers and result in a negative value, but
|
|
in Python 2.4 they'll become positive long integers.
|
|
|
|
% The empty groups below prevent conversion to guillemets.
|
|
There are a few ways to fix this warning. If you really need a
|
|
positive number, just add an \samp{L} to the end of the literal. If
|
|
you're trying to get a 32-bit integer with low bits set and have
|
|
previously used an expression such as \code{\textasciitilde(1 <{}< 31)},
|
|
it's probably
|
|
clearest to start with all bits set and clear the desired upper bits.
|
|
For example, to clear just the top bit (bit 31), you could write
|
|
\code{0xffffffffL {\&}{\textasciitilde}(1L<{}<31)}.
|
|
|
|
\item You can no longer disable assertions by assigning to \code{__debug__}.
|
|
|
|
\item The Distutils \function{setup()} function has gained various new
|
|
keyword arguments such as \var{depends}. Old versions of the
|
|
Distutils will abort if passed unknown keywords. A solution is to check
|
|
for the presence of the new \function{get_distutil_options()} function
|
|
in your \file{setup.py} and only uses the new keywords
|
|
with a version of the Distutils that supports them:
|
|
|
|
\begin{verbatim}
|
|
from distutils import core
|
|
|
|
kw = {'sources': 'foo.c', ...}
|
|
if hasattr(core, 'get_distutil_options'):
|
|
kw['depends'] = ['foo.h']
|
|
ext = Extension(**kw)
|
|
\end{verbatim}
|
|
|
|
\item Using \code{None} as a variable name will now result in a
|
|
\exception{SyntaxWarning} warning.
|
|
|
|
\item Names of extension types defined by the modules included with
|
|
Python now contain the module and a \character{.} in front of the type
|
|
name.
|
|
|
|
\end{itemize}
|
|
|
|
|
|
%======================================================================
|
|
\section{Acknowledgements \label{acks}}
|
|
|
|
The author would like to thank the following people for offering
|
|
suggestions, corrections and assistance with various drafts of this
|
|
article: Jeff Bauer, Simon Brunning, Brett Cannon, Michael Chermside,
|
|
Andrew Dalke, Scott David Daniels, Fred~L. Drake, Jr., David Fraser,
|
|
Kelly Gerber,
|
|
Raymond Hettinger, Michael Hudson, Chris Lambert, Detlef Lannert,
|
|
Martin von~L\"owis, Andrew MacIntyre, Lalo Martins, Chad Netzer,
|
|
Gustavo Niemeyer, Neal Norwitz, Hans Nowak, Chris Reedy, Francesco
|
|
Ricciardi, Vinay Sajip, Neil Schemenauer, Roman Suzi, Jason Tishler,
|
|
Just van~Rossum.
|
|
|
|
\end{document}
|