From python-checkins at python.org Thu Jan 1 00:30:10 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 00:30:10 +0100 (CET) Subject: [Python-checkins] r68111 - sandbox/trunk/release/release.py Message-ID: <20081231233010.C25541E403F@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 00:30:10 2009 New Revision: 68111 Log: add some basic (and untested) support for uploading a release to dinsdale Modified: sandbox/trunk/release/release.py Modified: sandbox/trunk/release/release.py ============================================================================== --- sandbox/trunk/release/release.py (original) +++ sandbox/trunk/release/release.py Thu Jan 1 00:30:10 2009 @@ -65,6 +65,8 @@ p.add_option('-e', '--export', default=False, action='store_true', help='Export the SVN tag to a tarball and build docs') + p.add_option('-u', '--upload', metavar="username", + help='Upload the tarballs and docs to dinsdale') p.add_option('-m', '--branch', default=False, action='store_true', help='create a maintance branch to go along with the release') @@ -215,8 +217,9 @@ def tarball(source): """Build tarballs for a directory.""" print 'Making .tgz' - tgz = source + '.tgz' - bz = source + '.tar.bz2' + base = os.path.basename(source) + tgz = base + '.tgz' + bz = base + '.tar.bz2' run_cmd(['tar cf - %s | gzip -9 > %s' % (source, tgz)]) print "Making .tar.bz2" run_cmd(['tar cf - %s | bzip2 -9 > %s' % @@ -278,8 +281,10 @@ if filename.endswith('.pyc'): os.remove(os.path.join(dirpath, filename)) - tarball(archivename) - print '\n**Now extract the archives and run the tests**' + os.mkdir('src') + with changed_dir('src'): + tarball(os.path.join("..", archivename)) + print '\n**Now extract the archives in dist/src and run the tests**' print '**You may also want to run make install and re-test**' @@ -290,6 +295,19 @@ run_cmd(['make', 'dist']) return os.path.abspath('dist') +def upload(tag, username): + """scp everything to dinsdale""" + address ='"%s at dinsdale.python.org:' % username + def scp(from_loc, to_loc): + run_cmd(['scp %s %s' % (from_loc, to_loc)]) + with changed_dir('dist'): + print "Uploading source tarballs" + scp('src', '/data/python-releases/%s' % tag.nickname) + print "Upload doc tarballs" + scp('docs', '/data/python-releases/doc/%s' % tag.nickname) + print "* Now change the permissions on the tarballs so they are " \ + "writable by the webmaster group. *" + class Tag(object): @@ -396,7 +414,7 @@ parser.print_usage() sys.exit(1) tag = Tag(args[1]) - if not options.export: + if not (options.export or options.upload): check_env() if options.bump: bump(tag) @@ -406,6 +424,8 @@ branch(tag) if options.export: export(tag) + if options.upload: + upload(tag, options.upload) if options.done: done(tag) From python-checkins at python.org Thu Jan 1 00:48:39 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 00:48:39 +0100 (CET) Subject: [Python-checkins] r68112 - in python/trunk: Lib/inspect.py Misc/NEWS Message-ID: <20081231234839.8E2111E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 00:48:39 2009 New Revision: 68112 Log: #4795 inspect.isgeneratorfunction() should return False instead of None Modified: python/trunk/Lib/inspect.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/inspect.py ============================================================================== --- python/trunk/Lib/inspect.py (original) +++ python/trunk/Lib/inspect.py Thu Jan 1 00:48:39 2009 @@ -161,6 +161,7 @@ if (isfunction(object) or ismethod(object)) and \ object.func_code.co_flags & CO_GENERATOR: return True + return False def isgenerator(object): """Return true if the object is a generator. Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Thu Jan 1 00:48:39 2009 @@ -100,6 +100,9 @@ Library ------- +- Issue #4795: inspect.isgeneratorfunction() returns False instead of None when + the function is not a generator. + - Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case no MSVC compiler is found under Windows. Original patch by Philip Jenvey. From buildbot at python.org Thu Jan 1 01:13:30 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 00:13:30 +0000 Subject: [Python-checkins] buildbot failure in x86 gentoo trunk Message-ID: <20090101001331.057441E4002@bag.python.org> The Buildbot has detected a new failure of x86 gentoo trunk. Full details are available at: http://www.python.org/dev/buildbot/all/x86%20gentoo%20trunk/builds/4390 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-x86 Build Reason: Build Source Stamp: [branch trunk] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_sqlite ====================================================================== FAIL: CheckSqlTimestamp (sqlite3.test.types.DateTimeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/buildslave/python-trunk/trunk.norwitz-x86/build/Lib/sqlite3/test/types.py", line 355, in CheckSqlTimestamp self.failUnlessEqual(ts.year, now.year) AssertionError: 2009 != 2008 make: *** [buildbottest] Error 1 sincerely, -The Buildbot From buildbot at python.org Thu Jan 1 01:16:39 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 00:16:39 +0000 Subject: [Python-checkins] buildbot failure in amd64 gentoo trunk Message-ID: <20090101001639.CA9381E4002@bag.python.org> The Buildbot has detected a new failure of amd64 gentoo trunk. Full details are available at: http://www.python.org/dev/buildbot/all/amd64%20gentoo%20trunk/builds/1706 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-amd64 Build Reason: Build Source Stamp: [branch trunk] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: Traceback (most recent call last): File "/home/buildbot/slave/py-build/trunk.norwitz-amd64/build/Lib/threading.py", line 522, in __bootstrap_inner self.run() File "/home/buildbot/slave/py-build/trunk.norwitz-amd64/build/Lib/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/home/buildbot/slave/py-build/trunk.norwitz-amd64/build/Lib/bsddb/test/test_thread.py", line 306, in readerThread rec = dbutils.DeadlockWrap(c.next, max_retries=10) File "/home/buildbot/slave/py-build/trunk.norwitz-amd64/build/Lib/bsddb/dbutils.py", line 68, in DeadlockWrap return function(*_args, **_kwargs) DBLockDeadlockError: (-30995, 'DB_LOCK_DEADLOCK: Locker killed to resolve a deadlock') 1 test failed: test_sqlite ====================================================================== FAIL: CheckSqlTimestamp (sqlite3.test.types.DateTimeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/buildbot/slave/py-build/trunk.norwitz-amd64/build/Lib/sqlite3/test/types.py", line 355, in CheckSqlTimestamp self.failUnlessEqual(ts.year, now.year) AssertionError: 2009 != 2008 make: *** [buildbottest] Error 1 sincerely, -The Buildbot From python-checkins at python.org Thu Jan 1 01:23:31 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 01:23:31 +0100 (CET) Subject: [Python-checkins] r68113 - in python/branches/py3k: Doc/c-api/arg.rst Doc/c-api/exceptions.rst Doc/howto/unicode.rst Doc/library/multiprocessing.rst Doc/library/pydoc.rst Doc/library/winsound.rst setup.py Message-ID: <20090101002331.5F1221E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 01:23:30 2009 New Revision: 68113 Log: Merged revisions 67952,67957-67958,67960-67961,67963,67973,67978,67995,68030,68057,68061 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67952 | georg.brandl | 2008-12-27 11:42:40 -0600 (Sat, 27 Dec 2008) | 2 lines #4752: actually use custom handler in example. ........ r67957 | georg.brandl | 2008-12-27 12:49:19 -0600 (Sat, 27 Dec 2008) | 2 lines #4754: improve winsound documentation. ........ r67958 | georg.brandl | 2008-12-27 13:02:59 -0600 (Sat, 27 Dec 2008) | 2 lines #4682: 'b' is actually unsigned char. ........ r67960 | georg.brandl | 2008-12-27 13:04:44 -0600 (Sat, 27 Dec 2008) | 2 lines #4695: fix backslashery. ........ r67961 | georg.brandl | 2008-12-27 13:06:04 -0600 (Sat, 27 Dec 2008) | 2 lines Use :samp: role. ........ r67963 | georg.brandl | 2008-12-27 13:11:15 -0600 (Sat, 27 Dec 2008) | 2 lines #4671: document that pydoc imports modules. ........ r67973 | alexandre.vassalotti | 2008-12-27 20:58:22 -0600 (Sat, 27 Dec 2008) | 2 lines Document Py_VaBuildValue. ........ r67978 | georg.brandl | 2008-12-28 05:58:49 -0600 (Sun, 28 Dec 2008) | 2 lines #4731: clarify message about missing module prerequisites. ........ r67995 | benjamin.peterson | 2008-12-28 15:16:07 -0600 (Sun, 28 Dec 2008) | 1 line #4763 PyErr_ExceptionMatches won't blow up with NULL arguments ........ r68030 | benjamin.peterson | 2008-12-29 15:38:14 -0600 (Mon, 29 Dec 2008) | 1 line fix French ........ r68057 | vinay.sajip | 2008-12-30 01:01:25 -0600 (Tue, 30 Dec 2008) | 1 line Minor documentation change relating to NullHandler. ........ r68061 | georg.brandl | 2008-12-30 04:15:49 -0600 (Tue, 30 Dec 2008) | 2 lines #4778: attributes can't be called. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/c-api/arg.rst python/branches/py3k/Doc/c-api/exceptions.rst python/branches/py3k/Doc/howto/unicode.rst python/branches/py3k/Doc/library/multiprocessing.rst python/branches/py3k/Doc/library/pydoc.rst python/branches/py3k/Doc/library/winsound.rst python/branches/py3k/setup.py Modified: python/branches/py3k/Doc/c-api/arg.rst ============================================================================== --- python/branches/py3k/Doc/c-api/arg.rst (original) +++ python/branches/py3k/Doc/c-api/arg.rst Thu Jan 1 01:23:30 2009 @@ -164,8 +164,9 @@ them. Instead, the implementation assumes that the string object uses the encoding passed in as parameter. -``b`` (integer) [char] - Convert a Python integer to a tiny int, stored in a C :ctype:`char`. +``b`` (integer) [unsigned char] + Convert a nonnegative Python integer to an unsigned tiny int, stored in a C + :ctype:`unsigned char`. ``B`` (integer) [unsigned char] Convert a Python integer to a tiny int without overflow checking, stored in a C @@ -552,3 +553,8 @@ If there is an error in the format string, the :exc:`SystemError` exception is set and *NULL* returned. + +.. cfunction:: PyObject* Py_VaBuildValue(const char *format, va_list vargs) + + Identical to :cfunc:`Py_BuildValue`, except that it accepts a va_list + rather than a variable number of arguments. Modified: python/branches/py3k/Doc/c-api/exceptions.rst ============================================================================== --- python/branches/py3k/Doc/c-api/exceptions.rst (original) +++ python/branches/py3k/Doc/c-api/exceptions.rst Thu Jan 1 01:23:30 2009 @@ -67,11 +67,10 @@ .. cfunction:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc) - Return true if the *given* exception matches the exception in *exc*. If *exc* - is a class object, this also returns true when *given* is an instance of a - subclass. If *exc* is a tuple, all exceptions in the tuple (and recursively in - subtuples) are searched for a match. If *given* is *NULL*, a memory access - violation will occur. + Return true if the *given* exception matches the exception in *exc*. If + *exc* is a class object, this also returns true when *given* is an instance + of a subclass. If *exc* is a tuple, all exceptions in the tuple (and + recursively in subtuples) are searched for a match. .. cfunction:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb) Modified: python/branches/py3k/Doc/howto/unicode.rst ============================================================================== --- python/branches/py3k/Doc/howto/unicode.rst (original) +++ python/branches/py3k/Doc/howto/unicode.rst Thu Jan 1 01:23:30 2009 @@ -32,7 +32,7 @@ looking at Apple ][ BASIC programs, published in French-language publications in the mid-1980s, that had lines like these:: - PRINT "FICHER EST COMPLETE." + PRINT "FICHIER EST COMPLETE." PRINT "CARACTERE NON ACCEPTE." Those messages should contain accents, and they just look wrong to someone who Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Thu Jan 1 01:23:30 2009 @@ -356,7 +356,7 @@ .. attribute:: daemon - The process's daemon flag, a Boolean value. This must be called before + The process's daemon flag, a Boolean value. This must be set before :meth:`start` is called. The initial value is inherited from the creating process. @@ -1808,9 +1808,9 @@ filesystem. * An ``'AF_PIPE'`` address is a string of the form - ``r'\\\\.\\pipe\\PipeName'``. To use :func:`Client` to connect to a named + :samp:`r'\\\\.\\pipe\\{PipeName}'`. To use :func:`Client` to connect to a named pipe on a remote computer called ServerName* one should use an address of the - form ``r'\\\\ServerName\\pipe\\PipeName'`` instead. + form :samp:`r'\\\\{ServerName}\\pipe\\{PipeName}'`` instead. Note that any string beginning with two backslashes is assumed by default to be an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address. Modified: python/branches/py3k/Doc/library/pydoc.rst ============================================================================== --- python/branches/py3k/Doc/library/pydoc.rst (original) +++ python/branches/py3k/Doc/library/pydoc.rst Thu Jan 1 01:23:30 2009 @@ -34,6 +34,13 @@ Unix), and refers to an existing Python source file, then documentation is produced for that file. +.. note:: + + In order to find objects and their documentation, :mod:`pydoc` imports the + module(s) to be documented. Therefore, any code on module level will be + executed on that occasion. Use an ``if __name__ == '__main__':`` guard to + only execute code when a file is invoked as a script and not just imported. + Specifying a :option:`-w` flag before the argument will cause HTML documentation to be written out to a file in the current directory, instead of displaying text on the console. Modified: python/branches/py3k/Doc/library/winsound.rst ============================================================================== --- python/branches/py3k/Doc/library/winsound.rst (original) +++ python/branches/py3k/Doc/library/winsound.rst Thu Jan 1 01:23:30 2009 @@ -26,8 +26,9 @@ Call the underlying :cfunc:`PlaySound` function from the Platform API. The *sound* parameter may be a filename, audio data as a string, or ``None``. Its interpretation depends on the value of *flags*, which can be a bitwise ORed - combination of the constants described below. If the system indicates an error, - :exc:`RuntimeError` is raised. + combination of the constants described below. If the *sound* parameter is + ``None``, any currently playing waveform sound is stopped. If the system + indicates an error, :exc:`RuntimeError` is raised. .. function:: MessageBeep([type=MB_OK]) @@ -102,6 +103,10 @@ Stop playing all instances of the specified sound. + .. note:: + + This flag is not supported on modern Windows platforms. + .. data:: SND_ASYNC Modified: python/branches/py3k/setup.py ============================================================================== --- python/branches/py3k/setup.py (original) +++ python/branches/py3k/setup.py Thu Jan 1 01:23:30 2009 @@ -208,7 +208,8 @@ if missing: print() - print("Failed to find the necessary bits to build these modules:") + print("Python build finished, but the necessary bits to build " + "these modules were not found:") print_three_column(missing) print("To find the necessary bits, look in setup.py in" " detect_modules() for the module's name.") From python-checkins at python.org Thu Jan 1 01:28:11 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 01:28:11 +0100 (CET) Subject: [Python-checkins] r68114 - in python/branches/release30-maint: Doc/c-api/arg.rst Doc/c-api/exceptions.rst Doc/howto/unicode.rst Doc/library/multiprocessing.rst Doc/library/pydoc.rst Doc/library/winsound.rst setup.py Message-ID: <20090101002811.EDAF51E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 01:28:11 2009 New Revision: 68114 Log: Merged revisions 68113 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r68113 | benjamin.peterson | 2008-12-31 18:23:30 -0600 (Wed, 31 Dec 2008) | 53 lines Merged revisions 67952,67957-67958,67960-67961,67963,67973,67978,67995,68030,68057,68061 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67952 | georg.brandl | 2008-12-27 11:42:40 -0600 (Sat, 27 Dec 2008) | 2 lines #4752: actually use custom handler in example. ........ r67957 | georg.brandl | 2008-12-27 12:49:19 -0600 (Sat, 27 Dec 2008) | 2 lines #4754: improve winsound documentation. ........ r67958 | georg.brandl | 2008-12-27 13:02:59 -0600 (Sat, 27 Dec 2008) | 2 lines #4682: 'b' is actually unsigned char. ........ r67960 | georg.brandl | 2008-12-27 13:04:44 -0600 (Sat, 27 Dec 2008) | 2 lines #4695: fix backslashery. ........ r67961 | georg.brandl | 2008-12-27 13:06:04 -0600 (Sat, 27 Dec 2008) | 2 lines Use :samp: role. ........ r67963 | georg.brandl | 2008-12-27 13:11:15 -0600 (Sat, 27 Dec 2008) | 2 lines #4671: document that pydoc imports modules. ........ r67973 | alexandre.vassalotti | 2008-12-27 20:58:22 -0600 (Sat, 27 Dec 2008) | 2 lines Document Py_VaBuildValue. ........ r67978 | georg.brandl | 2008-12-28 05:58:49 -0600 (Sun, 28 Dec 2008) | 2 lines #4731: clarify message about missing module prerequisites. ........ r67995 | benjamin.peterson | 2008-12-28 15:16:07 -0600 (Sun, 28 Dec 2008) | 1 line #4763 PyErr_ExceptionMatches won't blow up with NULL arguments ........ r68030 | benjamin.peterson | 2008-12-29 15:38:14 -0600 (Mon, 29 Dec 2008) | 1 line fix French ........ r68057 | vinay.sajip | 2008-12-30 01:01:25 -0600 (Tue, 30 Dec 2008) | 1 line Minor documentation change relating to NullHandler. ........ r68061 | georg.brandl | 2008-12-30 04:15:49 -0600 (Tue, 30 Dec 2008) | 2 lines #4778: attributes can't be called. ........ ................ Modified: python/branches/release30-maint/Doc/c-api/arg.rst python/branches/release30-maint/Doc/c-api/exceptions.rst python/branches/release30-maint/Doc/howto/unicode.rst python/branches/release30-maint/Doc/library/multiprocessing.rst python/branches/release30-maint/Doc/library/pydoc.rst python/branches/release30-maint/Doc/library/winsound.rst python/branches/release30-maint/setup.py Modified: python/branches/release30-maint/Doc/c-api/arg.rst ============================================================================== --- python/branches/release30-maint/Doc/c-api/arg.rst (original) +++ python/branches/release30-maint/Doc/c-api/arg.rst Thu Jan 1 01:28:11 2009 @@ -164,8 +164,9 @@ them. Instead, the implementation assumes that the string object uses the encoding passed in as parameter. -``b`` (integer) [char] - Convert a Python integer to a tiny int, stored in a C :ctype:`char`. +``b`` (integer) [unsigned char] + Convert a nonnegative Python integer to an unsigned tiny int, stored in a C + :ctype:`unsigned char`. ``B`` (integer) [unsigned char] Convert a Python integer to a tiny int without overflow checking, stored in a C @@ -552,3 +553,8 @@ If there is an error in the format string, the :exc:`SystemError` exception is set and *NULL* returned. + +.. cfunction:: PyObject* Py_VaBuildValue(const char *format, va_list vargs) + + Identical to :cfunc:`Py_BuildValue`, except that it accepts a va_list + rather than a variable number of arguments. Modified: python/branches/release30-maint/Doc/c-api/exceptions.rst ============================================================================== --- python/branches/release30-maint/Doc/c-api/exceptions.rst (original) +++ python/branches/release30-maint/Doc/c-api/exceptions.rst Thu Jan 1 01:28:11 2009 @@ -67,11 +67,10 @@ .. cfunction:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc) - Return true if the *given* exception matches the exception in *exc*. If *exc* - is a class object, this also returns true when *given* is an instance of a - subclass. If *exc* is a tuple, all exceptions in the tuple (and recursively in - subtuples) are searched for a match. If *given* is *NULL*, a memory access - violation will occur. + Return true if the *given* exception matches the exception in *exc*. If + *exc* is a class object, this also returns true when *given* is an instance + of a subclass. If *exc* is a tuple, all exceptions in the tuple (and + recursively in subtuples) are searched for a match. .. cfunction:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb) Modified: python/branches/release30-maint/Doc/howto/unicode.rst ============================================================================== --- python/branches/release30-maint/Doc/howto/unicode.rst (original) +++ python/branches/release30-maint/Doc/howto/unicode.rst Thu Jan 1 01:28:11 2009 @@ -32,7 +32,7 @@ looking at Apple ][ BASIC programs, published in French-language publications in the mid-1980s, that had lines like these:: - PRINT "FICHER EST COMPLETE." + PRINT "FICHIER EST COMPLETE." PRINT "CARACTERE NON ACCEPTE." Those messages should contain accents, and they just look wrong to someone who Modified: python/branches/release30-maint/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/release30-maint/Doc/library/multiprocessing.rst (original) +++ python/branches/release30-maint/Doc/library/multiprocessing.rst Thu Jan 1 01:28:11 2009 @@ -356,7 +356,7 @@ .. attribute:: daemon - The process's daemon flag, a Boolean value. This must be called before + The process's daemon flag, a Boolean value. This must be set before :meth:`start` is called. The initial value is inherited from the creating process. @@ -1808,9 +1808,9 @@ filesystem. * An ``'AF_PIPE'`` address is a string of the form - ``r'\\\\.\\pipe\\PipeName'``. To use :func:`Client` to connect to a named + :samp:`r'\\\\.\\pipe\\{PipeName}'`. To use :func:`Client` to connect to a named pipe on a remote computer called ServerName* one should use an address of the - form ``r'\\\\ServerName\\pipe\\PipeName'`` instead. + form :samp:`r'\\\\{ServerName}\\pipe\\{PipeName}'`` instead. Note that any string beginning with two backslashes is assumed by default to be an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address. Modified: python/branches/release30-maint/Doc/library/pydoc.rst ============================================================================== --- python/branches/release30-maint/Doc/library/pydoc.rst (original) +++ python/branches/release30-maint/Doc/library/pydoc.rst Thu Jan 1 01:28:11 2009 @@ -34,6 +34,13 @@ Unix), and refers to an existing Python source file, then documentation is produced for that file. +.. note:: + + In order to find objects and their documentation, :mod:`pydoc` imports the + module(s) to be documented. Therefore, any code on module level will be + executed on that occasion. Use an ``if __name__ == '__main__':`` guard to + only execute code when a file is invoked as a script and not just imported. + Specifying a :option:`-w` flag before the argument will cause HTML documentation to be written out to a file in the current directory, instead of displaying text on the console. Modified: python/branches/release30-maint/Doc/library/winsound.rst ============================================================================== --- python/branches/release30-maint/Doc/library/winsound.rst (original) +++ python/branches/release30-maint/Doc/library/winsound.rst Thu Jan 1 01:28:11 2009 @@ -26,8 +26,9 @@ Call the underlying :cfunc:`PlaySound` function from the Platform API. The *sound* parameter may be a filename, audio data as a string, or ``None``. Its interpretation depends on the value of *flags*, which can be a bitwise ORed - combination of the constants described below. If the system indicates an error, - :exc:`RuntimeError` is raised. + combination of the constants described below. If the *sound* parameter is + ``None``, any currently playing waveform sound is stopped. If the system + indicates an error, :exc:`RuntimeError` is raised. .. function:: MessageBeep([type=MB_OK]) @@ -102,6 +103,10 @@ Stop playing all instances of the specified sound. + .. note:: + + This flag is not supported on modern Windows platforms. + .. data:: SND_ASYNC Modified: python/branches/release30-maint/setup.py ============================================================================== --- python/branches/release30-maint/setup.py (original) +++ python/branches/release30-maint/setup.py Thu Jan 1 01:28:11 2009 @@ -208,7 +208,8 @@ if missing: print() - print("Failed to find the necessary bits to build these modules:") + print("Python build finished, but the necessary bits to build " + "these modules were not found:") print_three_column(missing) print("To find the necessary bits, look in setup.py in" " detect_modules() for the module's name.") From buildbot at python.org Thu Jan 1 01:48:03 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 00:48:03 +0000 Subject: [Python-checkins] buildbot failure in amd64 gentoo 3.x Message-ID: <20090101004803.771971E4002@bag.python.org> The Buildbot has detected a new failure of amd64 gentoo 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/amd64%20gentoo%203.x/builds/44 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-amd64 Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_sqlite ====================================================================== FAIL: CheckSqlTimestamp (sqlite3.test.types.DateTimeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/buildbot/slave/py-build/3.x.norwitz-amd64/build/Lib/sqlite3/test/types.py", line 367, in CheckSqlTimestamp AssertionError: 2009 != 2008 make: *** [buildbottest] Error 1 sincerely, -The Buildbot From buildbot at python.org Thu Jan 1 02:07:45 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 01:07:45 +0000 Subject: [Python-checkins] buildbot failure in amd64 gentoo 3.0 Message-ID: <20090101010746.010C21E4002@bag.python.org> The Buildbot has detected a new failure of amd64 gentoo 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/amd64%20gentoo%203.0/builds/18 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-amd64 Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_sqlite ====================================================================== FAIL: CheckSqlTimestamp (sqlite3.test.types.DateTimeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/buildbot/slave/py-build/3.0.norwitz-amd64/build/Lib/sqlite3/test/types.py", line 367, in CheckSqlTimestamp AssertionError: 2009 != 2008 make: *** [buildbottest] Error 1 sincerely, -The Buildbot From buildbot at python.org Thu Jan 1 04:32:37 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 03:32:37 +0000 Subject: [Python-checkins] buildbot failure in x86 XP-4 3.x Message-ID: <20090101033239.384981E4002@bag.python.org> The Buildbot has detected a new failure of x86 XP-4 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/x86%20XP-4%203.x/builds/27 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: bolen-windows Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_sqlite ====================================================================== FAIL: CheckSqlTimestamp (sqlite3.test.types.DateTimeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "E:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\sqlite3\test\types.py", line 367, in CheckSqlTimestamp self.failUnlessEqual(ts.year, now.year) AssertionError: 2009 != 2008 sincerely, -The Buildbot From python-checkins at python.org Thu Jan 1 05:04:42 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 05:04:42 +0100 (CET) Subject: [Python-checkins] r68115 - python/trunk/Lib/inspect.py Message-ID: <20090101040442.46C701E402F@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 05:04:41 2009 New Revision: 68115 Log: simplfy code Modified: python/trunk/Lib/inspect.py Modified: python/trunk/Lib/inspect.py ============================================================================== --- python/trunk/Lib/inspect.py (original) +++ python/trunk/Lib/inspect.py Thu Jan 1 05:04:41 2009 @@ -158,10 +158,8 @@ Generator function objects provides same attributes as functions. See isfunction.__doc__ for attributes listing.""" - if (isfunction(object) or ismethod(object)) and \ - object.func_code.co_flags & CO_GENERATOR: - return True - return False + return bool((isfunction(object) or ismethod(object)) and + object.func_code.co_flags & CO_GENERATOR) def isgenerator(object): """Return true if the object is a generator. From buildbot at python.org Thu Jan 1 05:11:30 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 04:11:30 +0000 Subject: [Python-checkins] buildbot failure in x86 XP-4 3.0 Message-ID: <20090101041130.A86F91E4021@bag.python.org> The Buildbot has detected a new failure of x86 XP-4 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/x86%20XP-4%203.0/builds/14 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: bolen-windows Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_sqlite ====================================================================== FAIL: CheckSqlTimestamp (sqlite3.test.types.DateTimeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "E:\cygwin\home\db3l\buildarea\3.0.bolen-windows\build\lib\sqlite3\test\types.py", line 367, in CheckSqlTimestamp self.failUnlessEqual(ts.year, now.year) AssertionError: 2009 != 2008 sincerely, -The Buildbot From nnorwitz at gmail.com Thu Jan 1 11:38:09 2009 From: nnorwitz at gmail.com (Neal Norwitz) Date: Thu, 1 Jan 2009 05:38:09 -0500 Subject: [Python-checkins] Python Regression Test Failures doc (1) Message-ID: <20090101103809.GA20608@python.psfb.org> svn update tools/sphinx At revision 68115. svn update tools/docutils At revision 68115. svn update tools/jinja At revision 68115. svn update tools/pygments At revision 68115. mkdir -p build/html build/doctrees python tools/sphinx-build.py -b html -d build/doctrees -D latex_paper_size= . build/html Sphinx v0.5, building html Exception occurred: File "/home/neal/python/trunk/Doc/tools/sphinx/jinja/loaders.py", line 20, in from jinja.utils import CacheDict, raise_syntax_error ImportError: cannot import name raise_syntax_error The full traceback has been saved in /tmp/sphinx-err-vVsS1J.log, if you want to report the issue to the author. Please also report this if it was a user error, so that a better error message can be provided next time. Send reports to sphinx-dev at googlegroups.com. Thanks! make: *** [build] Error 1 From python-checkins at python.org Thu Jan 1 12:46:51 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 12:46:51 +0100 (CET) Subject: [Python-checkins] r68116 - python/trunk/Doc/library/xml.etree.elementtree.rst Message-ID: <20090101114651.9A5A41E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 12:46:51 2009 New Revision: 68116 Log: #4100: note that element children are not necessarily present on "start" events. Modified: python/trunk/Doc/library/xml.etree.elementtree.rst Modified: python/trunk/Doc/library/xml.etree.elementtree.rst ============================================================================== --- python/trunk/Doc/library/xml.etree.elementtree.rst (original) +++ python/trunk/Doc/library/xml.etree.elementtree.rst Thu Jan 1 12:46:51 2009 @@ -94,6 +94,16 @@ *events* is a list of events to report back. If omitted, only "end" events are reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs. + .. note:: + + :func:`iterparse` only guarantees that it has seen the ">" + character of a starting tag when it emits a "start" event, so the + attributes are defined, but the contents of the text and tail attributes + are undefined at that point. The same applies to the element children; + they may or may not be present. + + If you need a fully populated element, look for "end" events instead. + .. function:: parse(source[, parser]) From python-checkins at python.org Thu Jan 1 12:53:56 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 12:53:56 +0100 (CET) Subject: [Python-checkins] r68117 - python/trunk/Doc/library/urllib2.rst Message-ID: <20090101115356.215EF1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 12:53:55 2009 New Revision: 68117 Log: #4156: make clear that "protocol" is to be replaced with the protocol name. Modified: python/trunk/Doc/library/urllib2.rst Modified: python/trunk/Doc/library/urllib2.rst ============================================================================== --- python/trunk/Doc/library/urllib2.rst (original) +++ python/trunk/Doc/library/urllib2.rst Thu Jan 1 12:53:55 2009 @@ -391,23 +391,23 @@ .. method:: OpenerDirector.add_handler(handler) - *handler* should be an instance of :class:`BaseHandler`. The following methods - are searched, and added to the possible chains (note that HTTP errors are a - special case). + *handler* should be an instance of :class:`BaseHandler`. The following + methods are searched, and added to the possible chains (note that HTTP errors + are a special case). - * :meth:`protocol_open` --- signal that the handler knows how to open *protocol* - URLs. + * :samp:`{protocol}_open` --- signal that the handler knows how to open + *protocol* URLs. - * :meth:`http_error_type` --- signal that the handler knows how to handle HTTP - errors with HTTP error code *type*. + * :samp:`http_error_{type}` --- signal that the handler knows how to handle + HTTP errors with HTTP error code *type*. - * :meth:`protocol_error` --- signal that the handler knows how to handle errors - from (non-\ ``http``) *protocol*. + * :samp:`{protocol}_error` --- signal that the handler knows how to handle + errors from (non-\ ``http``) *protocol*. - * :meth:`protocol_request` --- signal that the handler knows how to pre-process - *protocol* requests. + * :samp:`{protocol}_request` --- signal that the handler knows how to + pre-process *protocol* requests. - * :meth:`protocol_response` --- signal that the handler knows how to + * :samp:`{protocol}_response` --- signal that the handler knows how to post-process *protocol* responses. @@ -441,24 +441,24 @@ The order in which these methods are called within each stage is determined by sorting the handler instances. -#. Every handler with a method named like :meth:`protocol_request` has that +#. Every handler with a method named like :samp:`{protocol}_request` has that method called to pre-process the request. -#. Handlers with a method named like :meth:`protocol_open` are called to handle +#. Handlers with a method named like :samp:`{protocol}_open` are called to handle the request. This stage ends when a handler either returns a non-\ :const:`None` value (ie. a response), or raises an exception (usually :exc:`URLError`). Exceptions are allowed to propagate. In fact, the above algorithm is first tried for methods named - :meth:`default_open`. If all such methods return :const:`None`, the algorithm - is repeated for methods named like :meth:`protocol_open`. If all such methods - return :const:`None`, the algorithm is repeated for methods named - :meth:`unknown_open`. + :meth:`default_open`. If all such methods return :const:`None`, the + algorithm is repeated for methods named like :samp:`{protocol}_open`. If all + such methods return :const:`None`, the algorithm is repeated for methods + named :meth:`unknown_open`. Note that the implementation of these methods may involve calls of the parent :class:`OpenerDirector` instance's :meth:`.open` and :meth:`.error` methods. -#. Every handler with a method named like :meth:`protocol_response` has that +#. Every handler with a method named like :samp:`{protocol}_response` has that method called to post-process the response. @@ -514,8 +514,10 @@ .. method:: BaseHandler.protocol_open(req) :noindex: + ("protocol" is to be replaced by the protocol name.) + This method is *not* defined in :class:`BaseHandler`, but subclasses should - define it if they want to handle URLs with the given protocol. + define it if they want to handle URLs with the given *protocol*. This method, if defined, will be called by the parent :class:`OpenerDirector`. Return values should be the same as for :meth:`default_open`. @@ -563,8 +565,10 @@ .. method:: BaseHandler.protocol_request(req) :noindex: + ("protocol" is to be replaced by the protocol name.) + This method is *not* defined in :class:`BaseHandler`, but subclasses should - define it if they want to pre-process requests of the given protocol. + define it if they want to pre-process requests of the given *protocol*. This method, if defined, will be called by the parent :class:`OpenerDirector`. *req* will be a :class:`Request` object. The return value should be a @@ -574,8 +578,10 @@ .. method:: BaseHandler.protocol_response(req, response) :noindex: + ("protocol" is to be replaced by the protocol name.) + This method is *not* defined in :class:`BaseHandler`, but subclasses should - define it if they want to post-process responses of the given protocol. + define it if they want to post-process responses of the given *protocol*. This method, if defined, will be called by the parent :class:`OpenerDirector`. *req* will be a :class:`Request` object. *response* will be an object @@ -660,7 +666,9 @@ .. method:: ProxyHandler.protocol_open(request) :noindex: - The :class:`ProxyHandler` will have a method :meth:`protocol_open` for every + ("protocol" is to be replaced by the protocol name.) + + The :class:`ProxyHandler` will have a method :samp:`{protocol}_open` for every *protocol* which has a proxy in the *proxies* dictionary given in the constructor. The method will modify requests to go through the proxy, by calling ``request.set_proxy()``, and call the next handler in the chain to @@ -865,9 +873,10 @@ For 200 error codes, the response object is returned immediately. For non-200 error codes, this simply passes the job on to the - :meth:`protocol_error_code` handler methods, via :meth:`OpenerDirector.error`. - Eventually, :class:`urllib2.HTTPDefaultErrorHandler` will raise an - :exc:`HTTPError` if no other handler handles the error. + :samp:`{protocol}_error_code` handler methods, via + :meth:`OpenerDirector.error`. Eventually, + :class:`urllib2.HTTPDefaultErrorHandler` will raise an :exc:`HTTPError` if no + other handler handles the error. .. _urllib2-examples: From python-checkins at python.org Thu Jan 1 13:00:20 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:00:20 +0100 (CET) Subject: [Python-checkins] r68118 - python/trunk/Lib/re.py Message-ID: <20090101120021.000BC1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:00:19 2009 New Revision: 68118 Log: #4185: clarify escape behavior of replacement strings. Modified: python/trunk/Lib/re.py Modified: python/trunk/Lib/re.py ============================================================================== --- python/trunk/Lib/re.py (original) +++ python/trunk/Lib/re.py Thu Jan 1 13:00:19 2009 @@ -145,7 +145,8 @@ """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; - if a callable, it's passed the match object and must return + if a string, backslash escapes in it are processed. If it is + a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).sub(repl, string, count) @@ -155,7 +156,8 @@ non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a - callable; if a callable, it's passed the match object and must + callable; if a string, backslash escapes in it are processed. + If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).subn(repl, string, count) From python-checkins at python.org Thu Jan 1 13:09:40 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:09:40 +0100 (CET) Subject: [Python-checkins] r68119 - in python/trunk: Doc/library/dis.rst Lib/dis.py Message-ID: <20090101120940.EF1731E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:09:40 2009 New Revision: 68119 Log: #4222: document dis.findlabels() and dis.findlinestarts() and put them into dis.__all__. Modified: python/trunk/Doc/library/dis.rst python/trunk/Lib/dis.py Modified: python/trunk/Doc/library/dis.rst ============================================================================== --- python/trunk/Doc/library/dis.rst (original) +++ python/trunk/Doc/library/dis.rst Thu Jan 1 13:09:40 2009 @@ -64,10 +64,23 @@ .. function:: disco(code[, lasti]) - A synonym for disassemble. It is more convenient to type, and kept for - compatibility with earlier Python releases. + A synonym for :func:`disassemble`. It is more convenient to type, and kept + for compatibility with earlier Python releases. +.. function:: findlinestarts(code) + + This generator function uses the ``co_firstlineno`` and ``co_lnotab`` + attributes of the code object *code* to find the offsets which are starts of + lines in the source code. They are generated as ``(offset, lineno)`` pairs. + + +.. function:: findlabels(code) + + Detect all offsets in the code object *code* which are jump targets, and + return a list of these offsets. + + .. data:: opname Sequence of operation names, indexable using the bytecode. Modified: python/trunk/Lib/dis.py ============================================================================== --- python/trunk/Lib/dis.py (original) +++ python/trunk/Lib/dis.py Thu Jan 1 13:09:40 2009 @@ -6,7 +6,8 @@ from opcode import * from opcode import __all__ as _opcodes_all -__all__ = ["dis","disassemble","distb","disco"] + _opcodes_all +__all__ = ["dis", "disassemble", "distb", "disco", + "findlinestarts", "findlabels"] + _opcodes_all del _opcodes_all def dis(x=None): From python-checkins at python.org Thu Jan 1 13:15:31 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:15:31 +0100 (CET) Subject: [Python-checkins] r68120 - in python/trunk: Lib/test/test_struct.py Misc/NEWS Modules/_struct.c Message-ID: <20090101121531.DF8911E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:15:31 2009 New Revision: 68120 Log: #4228: Pack negative values the same way as 2.4 in struct's L format. Modified: python/trunk/Lib/test/test_struct.py python/trunk/Misc/NEWS python/trunk/Modules/_struct.c Modified: python/trunk/Lib/test/test_struct.py ============================================================================== --- python/trunk/Lib/test/test_struct.py (original) +++ python/trunk/Lib/test/test_struct.py Thu Jan 1 13:15:31 2009 @@ -2,6 +2,8 @@ import unittest import struct import warnings +warnings.filterwarnings("ignore", "struct integer overflow masking is deprecated", + DeprecationWarning) from functools import wraps from test.test_support import TestFailed, verbose, run_unittest @@ -461,6 +463,11 @@ self.check_float_coerce(endian + fmt, 1.0) self.check_float_coerce(endian + fmt, 1.5) + def test_issue4228(self): + # Packing a long may yield either 32 or 64 bits + x = struct.pack('L', -1)[:4] + self.assertEqual(x, '\xff'*4) + def test_unpack_from(self): test_string = 'abcd01234' fmt = '4s' Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Thu Jan 1 13:15:31 2009 @@ -258,6 +258,8 @@ Extension Modules ----------------- +- Issue #4228: Pack negative values the same way as 2.4 in struct's L format. + - Issue #1040026: Fix os.times result on systems where HZ is incorrect. - Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris, Modified: python/trunk/Modules/_struct.c ============================================================================== --- python/trunk/Modules/_struct.c (original) +++ python/trunk/Modules/_struct.c Thu Jan 1 13:15:31 2009 @@ -663,7 +663,7 @@ return -1; #if (SIZEOF_LONG > SIZEOF_INT) if ((x < ((long)INT_MIN)) || (x > ((long)INT_MAX))) - return _range_error(f, 0); + RANGE_ERROR(x, f, 0, -1); #endif y = (int)x; memcpy(p, (char *)&y, sizeof y); @@ -675,12 +675,12 @@ { unsigned long x; unsigned int y; - if (get_ulong(v, &x) < 0) - return _range_error(f, 1); + if (get_wrapped_ulong(v, &x) < 0) + return -1; y = (unsigned int)x; #if (SIZEOF_LONG > SIZEOF_INT) if (x > ((unsigned long)UINT_MAX)) - return _range_error(f, 1); + RANGE_ERROR(y, f, 1, -1); #endif memcpy(p, (char *)&y, sizeof y); return 0; @@ -700,8 +700,8 @@ np_ulong(char *p, PyObject *v, const formatdef *f) { unsigned long x; - if (get_ulong(v, &x) < 0) - return _range_error(f, 1); + if (get_wrapped_ulong(v, &x) < 0) + return -1; memcpy(p, (char *)&x, sizeof x); return 0; } From python-checkins at python.org Thu Jan 1 13:43:33 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:43:33 +0100 (CET) Subject: [Python-checkins] r68121 - python/trunk/Doc/library/new.rst Message-ID: <20090101124333.5F49D1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:43:33 2009 New Revision: 68121 Log: Point to types module in new module deprecation notice. Modified: python/trunk/Doc/library/new.rst Modified: python/trunk/Doc/library/new.rst ============================================================================== --- python/trunk/Doc/library/new.rst (original) +++ python/trunk/Doc/library/new.rst Thu Jan 1 13:43:33 2009 @@ -1,4 +1,3 @@ - :mod:`new` --- Creation of runtime internal objects =================================================== @@ -7,7 +6,8 @@ :deprecated: .. deprecated:: 2.6 - The :mod:`new` module has been removed in Python 3.0. + The :mod:`new` module has been removed in Python 3.0. Use the :mod:`types` + module's classes instead. .. sectionauthor:: Moshe Zadka From python-checkins at python.org Thu Jan 1 13:49:14 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:49:14 +0100 (CET) Subject: [Python-checkins] r68122 - peps/trunk/pep-0004.txt Message-ID: <20090101124914.EB4181E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:49:14 2009 New Revision: 68122 Log: Update PEP 4 to point to PEP 3108 for all modules deprecated in 2.6 because of removal in 3.0. Modified: peps/trunk/pep-0004.txt Modified: peps/trunk/pep-0004.txt ============================================================================== --- peps/trunk/pep-0004.txt (original) +++ peps/trunk/pep-0004.txt Thu Jan 1 13:49:14 2009 @@ -250,6 +250,13 @@ Documentation: None +Deprecation of modules removed in Python 3.0 + + PEP 3108 lists all modules that have been removed from Python 3.0. + They all are documented as deprecated in Python 2.6, and raise a + DeprecationWarning if the -3 flag is activated. + + Undeprecated modules None. From python-checkins at python.org Thu Jan 1 13:52:29 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:52:29 +0100 (CET) Subject: [Python-checkins] r68123 - python/trunk/Doc/library/webbrowser.rst Message-ID: <20090101125229.7E9FE1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:52:29 2009 New Revision: 68123 Log: #4784: ... on three counts ... Modified: python/trunk/Doc/library/webbrowser.rst Modified: python/trunk/Doc/library/webbrowser.rst ============================================================================== --- python/trunk/Doc/library/webbrowser.rst (original) +++ python/trunk/Doc/library/webbrowser.rst Thu Jan 1 13:52:29 2009 @@ -172,7 +172,7 @@ Browser Controller Objects -------------------------- -Browser controllers provide two methods which parallel two of the module-level +Browser controllers provide these methods which parallel two of the module-level convenience functions: From python-checkins at python.org Thu Jan 1 13:53:20 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 13:53:20 +0100 (CET) Subject: [Python-checkins] r68124 - python/trunk/Doc/library/json.rst Message-ID: <20090101125320.12B561E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 13:53:19 2009 New Revision: 68124 Log: #4782: Fix markup error that hid load() and loads(). Modified: python/trunk/Doc/library/json.rst Modified: python/trunk/Doc/library/json.rst ============================================================================== --- python/trunk/Doc/library/json.rst (original) +++ python/trunk/Doc/library/json.rst Thu Jan 1 13:53:19 2009 @@ -166,7 +166,7 @@ :func:`dump`. -.. function load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. @@ -202,7 +202,7 @@ class. -.. function loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON document) to a Python object. From python-checkins at python.org Thu Jan 1 14:02:10 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 14:02:10 +0100 (CET) Subject: [Python-checkins] r68125 - python/trunk/Doc/distutils/apiref.rst Message-ID: <20090101130210.2E37C1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 14:02:09 2009 New Revision: 68125 Log: #4776: add data_files and package_dir arguments. Modified: python/trunk/Doc/distutils/apiref.rst Modified: python/trunk/Doc/distutils/apiref.rst ============================================================================== --- python/trunk/Doc/distutils/apiref.rst (original) +++ python/trunk/Doc/distutils/apiref.rst Thu Jan 1 14:02:09 2009 @@ -88,9 +88,9 @@ | *options* | default options for the setup | a string | | | script | | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *license* | The license for the package | | + | *license* | The license for the package | a string | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *keywords* | Descriptive meta-data. See | | + | *keywords* | Descriptive meta-data, see | | | | :pep:`314` | | +--------------------+--------------------------------+-------------------------------------------------------------+ | *platforms* | | | @@ -98,6 +98,13 @@ | *cmdclass* | A mapping of command names to | a dictionary | | | :class:`Command` subclasses | | +--------------------+--------------------------------+-------------------------------------------------------------+ + | *data_files* | A list of data files to | a list | + | | install | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + | *package_dir* | A mapping of package to | a dictionary | + | | directory names | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + .. function:: run_setup(script_name[, script_args=None, stop_after='run']) From python-checkins at python.org Thu Jan 1 14:05:14 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 14:05:14 +0100 (CET) Subject: [Python-checkins] r68126 - python/trunk/Doc/library/logging.rst Message-ID: <20090101130514.7CA591E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 14:05:13 2009 New Revision: 68126 Log: Handlers are in the `logging.handlers` module. Modified: python/trunk/Doc/library/logging.rst Modified: python/trunk/Doc/library/logging.rst ============================================================================== --- python/trunk/Doc/library/logging.rst (original) +++ python/trunk/Doc/library/logging.rst Thu Jan 1 14:05:13 2009 @@ -1559,6 +1559,8 @@ StreamHandler ^^^^^^^^^^^^^ +.. module:: logging.handlers + The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -2065,6 +2067,8 @@ Formatter Objects ----------------- +.. currentmodule:: logging + :class:`Formatter`\ s have the following attributes and methods. They are responsible for converting a :class:`LogRecord` to (usually) a string which can be interpreted by either a human or an external system. The base From python-checkins at python.org Thu Jan 1 14:14:49 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 14:14:49 +0100 (CET) Subject: [Python-checkins] r68127 - python/trunk/Doc/library/email.mime.rst Message-ID: <20090101131449.D2BB31E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 14:14:49 2009 New Revision: 68127 Log: #4767: Use correct submodules for all MIME classes. Modified: python/trunk/Doc/library/email.mime.rst Modified: python/trunk/Doc/library/email.mime.rst ============================================================================== --- python/trunk/Doc/library/email.mime.rst (original) +++ python/trunk/Doc/library/email.mime.rst Thu Jan 1 14:14:49 2009 @@ -19,6 +19,7 @@ Here are the classes: +.. currentmodule:: email.mime.base .. class:: MIMEBase(_maintype, _subtype, **_params) @@ -39,6 +40,8 @@ :mailheader:`MIME-Version` header (always set to ``1.0``). +.. currentmodule:: email.mime.nonmultipart + .. class:: MIMENonMultipart() Module: :mod:`email.mime.nonmultipart` @@ -52,6 +55,8 @@ .. versionadded:: 2.2.2 +.. currentmodule:: email.mime.multipart + .. class:: MIMEMultipart([subtype[, boundary[, _subparts[, _params]]]]) Module: :mod:`email.mime.multipart` @@ -77,6 +82,8 @@ .. versionadded:: 2.2.2 +.. currentmodule:: email.mime.application + .. class:: MIMEApplication(_data[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.application` @@ -99,6 +106,8 @@ .. versionadded:: 2.5 +.. currentmodule:: email.mime.audio + .. class:: MIMEAudio(_audiodata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.audio` @@ -122,6 +131,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.image + .. class:: MIMEImage(_imagedata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.image` @@ -145,6 +156,8 @@ *_params* are passed straight through to the :class:`MIMEBase` constructor. +.. currentmodule:: email.mime.message + .. class:: MIMEMessage(_msg[, _subtype]) Module: :mod:`email.mime.message` @@ -158,6 +171,8 @@ :mimetype:`rfc822`. +.. currentmodule:: email.mime.text + .. class:: MIMEText(_text[, _subtype[, _charset]]) Module: :mod:`email.mime.text` From python-checkins at python.org Thu Jan 1 15:11:22 2009 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 1 Jan 2009 15:11:22 +0100 (CET) Subject: [Python-checkins] r68128 - in python/trunk: Lib/test/test_deque.py Lib/test/test_dict.py Lib/test/test_set.py Misc/NEWS Modules/_collectionsmodule.c Objects/dictobject.c Objects/setobject.c Message-ID: <20090101141122.F0CD61E4002@bag.python.org> Author: antoine.pitrou Date: Thu Jan 1 15:11:22 2009 New Revision: 68128 Log: Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. Modified: python/trunk/Lib/test/test_deque.py python/trunk/Lib/test/test_dict.py python/trunk/Lib/test/test_set.py python/trunk/Misc/NEWS python/trunk/Modules/_collectionsmodule.c python/trunk/Objects/dictobject.c python/trunk/Objects/setobject.c Modified: python/trunk/Lib/test/test_deque.py ============================================================================== --- python/trunk/Lib/test/test_deque.py (original) +++ python/trunk/Lib/test/test_deque.py Thu Jan 1 15:11:22 2009 @@ -1,7 +1,8 @@ from collections import deque import unittest from test import test_support, seq_tests -from weakref import proxy +import gc +import weakref import copy import cPickle as pickle import random @@ -418,6 +419,22 @@ d.append(1) gc.collect() + def test_container_iterator(self): + # Bug # XXX: tp_traverse was not implemented for deque iterator objects + class C(object): + pass + for i in range(2): + obj = C() + ref = weakref.ref(obj) + if i == 0: + container = deque([obj, 1]) + else: + container = reversed(deque([obj, 1])) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): @@ -528,7 +545,7 @@ def test_weakref(self): d = deque('gallahad') - p = proxy(d) + p = weakref.proxy(d) self.assertEqual(str(p), str(d)) d = None self.assertRaises(ReferenceError, str, p) Modified: python/trunk/Lib/test/test_dict.py ============================================================================== --- python/trunk/Lib/test/test_dict.py (original) +++ python/trunk/Lib/test/test_dict.py Thu Jan 1 15:11:22 2009 @@ -2,6 +2,7 @@ from test import test_support import UserDict, random, string +import gc, weakref class DictTest(unittest.TestCase): @@ -554,6 +555,19 @@ pass d = {} + def test_container_iterator(self): + # Bug # XXX: tp_traverse was not implemented for dictiter objects + class C(object): + pass + iterators = (dict.iteritems, dict.itervalues, dict.iterkeys) + for i in iterators: + obj = C() + ref = weakref.ref(obj) + container = {obj: 1} + obj.x = i(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") from test import mapping_tests Modified: python/trunk/Lib/test/test_set.py ============================================================================== --- python/trunk/Lib/test/test_set.py (original) +++ python/trunk/Lib/test/test_set.py Thu Jan 1 15:11:22 2009 @@ -1,6 +1,7 @@ import unittest from test import test_support -from weakref import proxy +import gc +import weakref import operator import copy import pickle @@ -322,6 +323,18 @@ self.assertEqual(sum(elem.hash_count for elem in d), n) self.assertEqual(d3, dict.fromkeys(d, 123)) + def test_container_iterator(self): + # Bug # XXX: tp_traverse was not implemented for set iterator object + class C(object): + pass + obj = C() + ref = weakref.ref(obj) + container = set([obj, 1]) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestSet(TestJointOps): thetype = set @@ -538,7 +551,7 @@ def test_weakref(self): s = self.thetype('gallahad') - p = proxy(s) + p = weakref.proxy(s) self.assertEqual(str(p), str(s)) s = None self.assertRaises(ReferenceError, str, p) Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Thu Jan 1 15:11:22 2009 @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #3680: Reference cycles created through a dict, set or deque iterator + did not get collected. + - Issue #4701: PyObject_Hash now implicitly calls PyType_Ready on types where the tp_hash and tp_dict slots are both NULL. Modified: python/trunk/Modules/_collectionsmodule.c ============================================================================== --- python/trunk/Modules/_collectionsmodule.c (original) +++ python/trunk/Modules/_collectionsmodule.c Thu Jan 1 15:11:22 2009 @@ -958,7 +958,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequeiter_type); + it = PyObject_GC_New(dequeiterobject, &dequeiter_type); if (it == NULL) return NULL; it->b = deque->leftblock; @@ -967,14 +967,22 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } +static int +dequeiter_traverse(dequeiterobject *dio, visitproc visit, void *arg) +{ + Py_VISIT(dio->deque); + return 0; +} + static void dequeiter_dealloc(dequeiterobject *dio) { Py_XDECREF(dio->deque); - Py_TYPE(dio)->tp_free(dio); + PyObject_GC_Del(dio); } static PyObject * @@ -1039,9 +1047,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -1060,7 +1068,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequereviter_type); + it = PyObject_GC_New(dequeiterobject, &dequereviter_type); if (it == NULL) return NULL; it->b = deque->rightblock; @@ -1069,6 +1077,7 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } @@ -1121,9 +1130,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/trunk/Objects/dictobject.c ============================================================================== --- python/trunk/Objects/dictobject.c (original) +++ python/trunk/Objects/dictobject.c Thu Jan 1 15:11:22 2009 @@ -2331,7 +2331,7 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) { dictiterobject *di; - di = PyObject_New(dictiterobject, itertype); + di = PyObject_GC_New(dictiterobject, itertype); if (di == NULL) return NULL; Py_INCREF(dict); @@ -2348,6 +2348,7 @@ } else di->di_result = NULL; + _PyObject_GC_TRACK(di); return (PyObject *)di; } @@ -2356,7 +2357,15 @@ { Py_XDECREF(di->di_dict); Py_XDECREF(di->di_result); - PyObject_Del(di); + PyObject_GC_Del(di); +} + +static int +dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) +{ + Py_VISIT(di->di_dict); + Py_VISIT(di->di_result); + return 0; } static PyObject * @@ -2435,9 +2444,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2507,9 +2516,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2593,9 +2602,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/trunk/Objects/setobject.c ============================================================================== --- python/trunk/Objects/setobject.c (original) +++ python/trunk/Objects/setobject.c Thu Jan 1 15:11:22 2009 @@ -810,7 +810,14 @@ setiter_dealloc(setiterobject *si) { Py_XDECREF(si->si_set); - PyObject_Del(si); + PyObject_GC_Del(si); +} + +static int +setiter_traverse(setiterobject *si, visitproc visit, void *arg) +{ + Py_VISIT(si->si_set); + return 0; } static PyObject * @@ -888,9 +895,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)setiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -903,7 +910,7 @@ static PyObject * set_iter(PySetObject *so) { - setiterobject *si = PyObject_New(setiterobject, &PySetIter_Type); + setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type); if (si == NULL) return NULL; Py_INCREF(so); @@ -911,6 +918,7 @@ si->si_used = so->used; si->si_pos = 0; si->len = so->used; + _PyObject_GC_TRACK(si); return (PyObject *)si; } From python-checkins at python.org Thu Jan 1 16:05:06 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 16:05:06 +0100 (CET) Subject: [Python-checkins] r68129 - in python/branches/py3k: Doc/distutils/apiref.rst Doc/library/dis.rst Doc/library/email.mime.rst Doc/library/json.rst Doc/library/logging.rst Doc/library/webbrowser.rst Doc/library/xml.etree.elementtree.rst Lib/dis.py Lib/re.py Message-ID: <20090101150506.CC9341E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 16:05:06 2009 New Revision: 68129 Log: Merged revisions 68116-68119,68121,68123-68127 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68116 | georg.brandl | 2009-01-01 05:46:51 -0600 (Thu, 01 Jan 2009) | 2 lines #4100: note that element children are not necessarily present on "start" events. ........ r68117 | georg.brandl | 2009-01-01 05:53:55 -0600 (Thu, 01 Jan 2009) | 2 lines #4156: make clear that "protocol" is to be replaced with the protocol name. ........ r68118 | georg.brandl | 2009-01-01 06:00:19 -0600 (Thu, 01 Jan 2009) | 2 lines #4185: clarify escape behavior of replacement strings. ........ r68119 | georg.brandl | 2009-01-01 06:09:40 -0600 (Thu, 01 Jan 2009) | 3 lines #4222: document dis.findlabels() and dis.findlinestarts() and put them into dis.__all__. ........ r68121 | georg.brandl | 2009-01-01 06:43:33 -0600 (Thu, 01 Jan 2009) | 2 lines Point to types module in new module deprecation notice. ........ r68123 | georg.brandl | 2009-01-01 06:52:29 -0600 (Thu, 01 Jan 2009) | 2 lines #4784: ... on three counts ... ........ r68124 | georg.brandl | 2009-01-01 06:53:19 -0600 (Thu, 01 Jan 2009) | 2 lines #4782: Fix markup error that hid load() and loads(). ........ r68125 | georg.brandl | 2009-01-01 07:02:09 -0600 (Thu, 01 Jan 2009) | 2 lines #4776: add data_files and package_dir arguments. ........ r68126 | georg.brandl | 2009-01-01 07:05:13 -0600 (Thu, 01 Jan 2009) | 2 lines Handlers are in the `logging.handlers` module. ........ r68127 | georg.brandl | 2009-01-01 07:14:49 -0600 (Thu, 01 Jan 2009) | 2 lines #4767: Use correct submodules for all MIME classes. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/distutils/apiref.rst python/branches/py3k/Doc/library/dis.rst python/branches/py3k/Doc/library/email.mime.rst python/branches/py3k/Doc/library/json.rst python/branches/py3k/Doc/library/logging.rst python/branches/py3k/Doc/library/webbrowser.rst python/branches/py3k/Doc/library/xml.etree.elementtree.rst python/branches/py3k/Lib/dis.py python/branches/py3k/Lib/re.py Modified: python/branches/py3k/Doc/distutils/apiref.rst ============================================================================== --- python/branches/py3k/Doc/distutils/apiref.rst (original) +++ python/branches/py3k/Doc/distutils/apiref.rst Thu Jan 1 16:05:06 2009 @@ -88,9 +88,9 @@ | *options* | default options for the setup | a string | | | script | | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *license* | The license for the package | | + | *license* | The license for the package | a string | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *keywords* | Descriptive meta-data. See | | + | *keywords* | Descriptive meta-data, see | | | | :pep:`314` | | +--------------------+--------------------------------+-------------------------------------------------------------+ | *platforms* | | | @@ -98,6 +98,13 @@ | *cmdclass* | A mapping of command names to | a dictionary | | | :class:`Command` subclasses | | +--------------------+--------------------------------+-------------------------------------------------------------+ + | *data_files* | A list of data files to | a list | + | | install | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + | *package_dir* | A mapping of package to | a dictionary | + | | directory names | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + .. function:: run_setup(script_name[, script_args=None, stop_after='run']) Modified: python/branches/py3k/Doc/library/dis.rst ============================================================================== --- python/branches/py3k/Doc/library/dis.rst (original) +++ python/branches/py3k/Doc/library/dis.rst Thu Jan 1 16:05:06 2009 @@ -64,10 +64,23 @@ .. function:: disco(code[, lasti]) - A synonym for disassemble. It is more convenient to type, and kept for - compatibility with earlier Python releases. + A synonym for :func:`disassemble`. It is more convenient to type, and kept + for compatibility with earlier Python releases. +.. function:: findlinestarts(code) + + This generator function uses the ``co_firstlineno`` and ``co_lnotab`` + attributes of the code object *code* to find the offsets which are starts of + lines in the source code. They are generated as ``(offset, lineno)`` pairs. + + +.. function:: findlabels(code) + + Detect all offsets in the code object *code* which are jump targets, and + return a list of these offsets. + + .. data:: opname Sequence of operation names, indexable using the bytecode. Modified: python/branches/py3k/Doc/library/email.mime.rst ============================================================================== --- python/branches/py3k/Doc/library/email.mime.rst (original) +++ python/branches/py3k/Doc/library/email.mime.rst Thu Jan 1 16:05:06 2009 @@ -19,6 +19,7 @@ Here are the classes: +.. currentmodule:: email.mime.base .. class:: MIMEBase(_maintype, _subtype, **_params) @@ -39,6 +40,8 @@ :mailheader:`MIME-Version` header (always set to ``1.0``). +.. currentmodule:: email.mime.nonmultipart + .. class:: MIMENonMultipart() Module: :mod:`email.mime.nonmultipart` @@ -50,6 +53,8 @@ :exc:`MultipartConversionError` exception is raised. +.. currentmodule:: email.mime.multipart + .. class:: MIMEMultipart([subtype[, boundary[, _subparts[, _params]]]]) Module: :mod:`email.mime.multipart` @@ -73,6 +78,8 @@ dictionary. +.. currentmodule:: email.mime.application + .. class:: MIMEApplication(_data[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.application` @@ -93,6 +100,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.audio + .. class:: MIMEAudio(_audiodata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.audio` @@ -116,6 +125,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.image + .. class:: MIMEImage(_imagedata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.image` @@ -139,6 +150,8 @@ *_params* are passed straight through to the :class:`MIMEBase` constructor. +.. currentmodule:: email.mime.message + .. class:: MIMEMessage(_msg[, _subtype]) Module: :mod:`email.mime.message` @@ -152,6 +165,8 @@ :mimetype:`rfc822`. +.. currentmodule:: email.mime.text + .. class:: MIMEText(_text[, _subtype[, _charset]]) Module: :mod:`email.mime.text` Modified: python/branches/py3k/Doc/library/json.rst ============================================================================== --- python/branches/py3k/Doc/library/json.rst (original) +++ python/branches/py3k/Doc/library/json.rst Thu Jan 1 16:05:06 2009 @@ -165,7 +165,7 @@ :func:`dump`. -.. function load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. @@ -201,7 +201,7 @@ class. -.. function loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON document) to a Python object. Modified: python/branches/py3k/Doc/library/logging.rst ============================================================================== --- python/branches/py3k/Doc/library/logging.rst (original) +++ python/branches/py3k/Doc/library/logging.rst Thu Jan 1 16:05:06 2009 @@ -1534,6 +1534,8 @@ StreamHandler ^^^^^^^^^^^^^ +.. module:: logging.handlers + The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -2035,6 +2037,8 @@ Formatter Objects ----------------- +.. currentmodule:: logging + :class:`Formatter`\ s have the following attributes and methods. They are responsible for converting a :class:`LogRecord` to (usually) a string which can be interpreted by either a human or an external system. The base Modified: python/branches/py3k/Doc/library/webbrowser.rst ============================================================================== --- python/branches/py3k/Doc/library/webbrowser.rst (original) +++ python/branches/py3k/Doc/library/webbrowser.rst Thu Jan 1 16:05:06 2009 @@ -167,7 +167,7 @@ Browser Controller Objects -------------------------- -Browser controllers provide two methods which parallel two of the module-level +Browser controllers provide these methods which parallel two of the module-level convenience functions: Modified: python/branches/py3k/Doc/library/xml.etree.elementtree.rst ============================================================================== --- python/branches/py3k/Doc/library/xml.etree.elementtree.rst (original) +++ python/branches/py3k/Doc/library/xml.etree.elementtree.rst Thu Jan 1 16:05:06 2009 @@ -94,6 +94,16 @@ *events* is a list of events to report back. If omitted, only "end" events are reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs. + .. note:: + + :func:`iterparse` only guarantees that it has seen the ">" + character of a starting tag when it emits a "start" event, so the + attributes are defined, but the contents of the text and tail attributes + are undefined at that point. The same applies to the element children; + they may or may not be present. + + If you need a fully populated element, look for "end" events instead. + .. function:: parse(source[, parser]) Modified: python/branches/py3k/Lib/dis.py ============================================================================== --- python/branches/py3k/Lib/dis.py (original) +++ python/branches/py3k/Lib/dis.py Thu Jan 1 16:05:06 2009 @@ -6,7 +6,8 @@ from opcode import * from opcode import __all__ as _opcodes_all -__all__ = ["dis","disassemble","distb","disco"] + _opcodes_all +__all__ = ["dis", "disassemble", "distb", "disco", + "findlinestarts", "findlabels"] + _opcodes_all del _opcodes_all def dis(x=None): Modified: python/branches/py3k/Lib/re.py ============================================================================== --- python/branches/py3k/Lib/re.py (original) +++ python/branches/py3k/Lib/re.py Thu Jan 1 16:05:06 2009 @@ -160,7 +160,8 @@ """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; - if a callable, it's passed the match object and must return + if a string, backslash escapes in it are processed. If it is + a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).sub(repl, string, count) @@ -170,7 +171,8 @@ non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a - callable; if a callable, it's passed the match object and must + callable; if a string, backslash escapes in it are processed. + If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).subn(repl, string, count) From python-checkins at python.org Thu Jan 1 16:09:10 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 16:09:10 +0100 (CET) Subject: [Python-checkins] r68130 - in python/branches/release30-maint: Doc/distutils/apiref.rst Doc/library/dis.rst Doc/library/email.mime.rst Doc/library/json.rst Doc/library/logging.rst Doc/library/webbrowser.rst Doc/library/xml.etree.elementtree.rst Lib/dis.py Lib/re.py Message-ID: <20090101150910.F145C1E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 16:09:10 2009 New Revision: 68130 Log: Merged revisions 68129 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r68129 | benjamin.peterson | 2009-01-01 09:05:06 -0600 (Thu, 01 Jan 2009) | 46 lines Merged revisions 68116-68119,68121,68123-68127 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68116 | georg.brandl | 2009-01-01 05:46:51 -0600 (Thu, 01 Jan 2009) | 2 lines #4100: note that element children are not necessarily present on "start" events. ........ r68117 | georg.brandl | 2009-01-01 05:53:55 -0600 (Thu, 01 Jan 2009) | 2 lines #4156: make clear that "protocol" is to be replaced with the protocol name. ........ r68118 | georg.brandl | 2009-01-01 06:00:19 -0600 (Thu, 01 Jan 2009) | 2 lines #4185: clarify escape behavior of replacement strings. ........ r68119 | georg.brandl | 2009-01-01 06:09:40 -0600 (Thu, 01 Jan 2009) | 3 lines #4222: document dis.findlabels() and dis.findlinestarts() and put them into dis.__all__. ........ r68121 | georg.brandl | 2009-01-01 06:43:33 -0600 (Thu, 01 Jan 2009) | 2 lines Point to types module in new module deprecation notice. ........ r68123 | georg.brandl | 2009-01-01 06:52:29 -0600 (Thu, 01 Jan 2009) | 2 lines #4784: ... on three counts ... ........ r68124 | georg.brandl | 2009-01-01 06:53:19 -0600 (Thu, 01 Jan 2009) | 2 lines #4782: Fix markup error that hid load() and loads(). ........ r68125 | georg.brandl | 2009-01-01 07:02:09 -0600 (Thu, 01 Jan 2009) | 2 lines #4776: add data_files and package_dir arguments. ........ r68126 | georg.brandl | 2009-01-01 07:05:13 -0600 (Thu, 01 Jan 2009) | 2 lines Handlers are in the `logging.handlers` module. ........ r68127 | georg.brandl | 2009-01-01 07:14:49 -0600 (Thu, 01 Jan 2009) | 2 lines #4767: Use correct submodules for all MIME classes. ........ ................ Modified: python/branches/release30-maint/Doc/distutils/apiref.rst python/branches/release30-maint/Doc/library/dis.rst python/branches/release30-maint/Doc/library/email.mime.rst python/branches/release30-maint/Doc/library/json.rst python/branches/release30-maint/Doc/library/logging.rst python/branches/release30-maint/Doc/library/webbrowser.rst python/branches/release30-maint/Doc/library/xml.etree.elementtree.rst python/branches/release30-maint/Lib/dis.py python/branches/release30-maint/Lib/re.py Modified: python/branches/release30-maint/Doc/distutils/apiref.rst ============================================================================== --- python/branches/release30-maint/Doc/distutils/apiref.rst (original) +++ python/branches/release30-maint/Doc/distutils/apiref.rst Thu Jan 1 16:09:10 2009 @@ -88,9 +88,9 @@ | *options* | default options for the setup | a string | | | script | | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *license* | The license for the package | | + | *license* | The license for the package | a string | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *keywords* | Descriptive meta-data. See | | + | *keywords* | Descriptive meta-data, see | | | | :pep:`314` | | +--------------------+--------------------------------+-------------------------------------------------------------+ | *platforms* | | | @@ -98,6 +98,13 @@ | *cmdclass* | A mapping of command names to | a dictionary | | | :class:`Command` subclasses | | +--------------------+--------------------------------+-------------------------------------------------------------+ + | *data_files* | A list of data files to | a list | + | | install | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + | *package_dir* | A mapping of package to | a dictionary | + | | directory names | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + .. function:: run_setup(script_name[, script_args=None, stop_after='run']) Modified: python/branches/release30-maint/Doc/library/dis.rst ============================================================================== --- python/branches/release30-maint/Doc/library/dis.rst (original) +++ python/branches/release30-maint/Doc/library/dis.rst Thu Jan 1 16:09:10 2009 @@ -64,10 +64,23 @@ .. function:: disco(code[, lasti]) - A synonym for disassemble. It is more convenient to type, and kept for - compatibility with earlier Python releases. + A synonym for :func:`disassemble`. It is more convenient to type, and kept + for compatibility with earlier Python releases. +.. function:: findlinestarts(code) + + This generator function uses the ``co_firstlineno`` and ``co_lnotab`` + attributes of the code object *code* to find the offsets which are starts of + lines in the source code. They are generated as ``(offset, lineno)`` pairs. + + +.. function:: findlabels(code) + + Detect all offsets in the code object *code* which are jump targets, and + return a list of these offsets. + + .. data:: opname Sequence of operation names, indexable using the bytecode. Modified: python/branches/release30-maint/Doc/library/email.mime.rst ============================================================================== --- python/branches/release30-maint/Doc/library/email.mime.rst (original) +++ python/branches/release30-maint/Doc/library/email.mime.rst Thu Jan 1 16:09:10 2009 @@ -19,6 +19,7 @@ Here are the classes: +.. currentmodule:: email.mime.base .. class:: MIMEBase(_maintype, _subtype, **_params) @@ -39,6 +40,8 @@ :mailheader:`MIME-Version` header (always set to ``1.0``). +.. currentmodule:: email.mime.nonmultipart + .. class:: MIMENonMultipart() Module: :mod:`email.mime.nonmultipart` @@ -50,6 +53,8 @@ :exc:`MultipartConversionError` exception is raised. +.. currentmodule:: email.mime.multipart + .. class:: MIMEMultipart([subtype[, boundary[, _subparts[, _params]]]]) Module: :mod:`email.mime.multipart` @@ -73,6 +78,8 @@ dictionary. +.. currentmodule:: email.mime.application + .. class:: MIMEApplication(_data[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.application` @@ -93,6 +100,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.audio + .. class:: MIMEAudio(_audiodata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.audio` @@ -116,6 +125,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.image + .. class:: MIMEImage(_imagedata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.image` @@ -139,6 +150,8 @@ *_params* are passed straight through to the :class:`MIMEBase` constructor. +.. currentmodule:: email.mime.message + .. class:: MIMEMessage(_msg[, _subtype]) Module: :mod:`email.mime.message` @@ -152,6 +165,8 @@ :mimetype:`rfc822`. +.. currentmodule:: email.mime.text + .. class:: MIMEText(_text[, _subtype[, _charset]]) Module: :mod:`email.mime.text` Modified: python/branches/release30-maint/Doc/library/json.rst ============================================================================== --- python/branches/release30-maint/Doc/library/json.rst (original) +++ python/branches/release30-maint/Doc/library/json.rst Thu Jan 1 16:09:10 2009 @@ -165,7 +165,7 @@ :func:`dump`. -.. function load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. @@ -201,7 +201,7 @@ class. -.. function loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON document) to a Python object. Modified: python/branches/release30-maint/Doc/library/logging.rst ============================================================================== --- python/branches/release30-maint/Doc/library/logging.rst (original) +++ python/branches/release30-maint/Doc/library/logging.rst Thu Jan 1 16:09:10 2009 @@ -1519,6 +1519,8 @@ StreamHandler ^^^^^^^^^^^^^ +.. module:: logging.handlers + The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -2020,6 +2022,8 @@ Formatter Objects ----------------- +.. currentmodule:: logging + :class:`Formatter`\ s have the following attributes and methods. They are responsible for converting a :class:`LogRecord` to (usually) a string which can be interpreted by either a human or an external system. The base Modified: python/branches/release30-maint/Doc/library/webbrowser.rst ============================================================================== --- python/branches/release30-maint/Doc/library/webbrowser.rst (original) +++ python/branches/release30-maint/Doc/library/webbrowser.rst Thu Jan 1 16:09:10 2009 @@ -167,7 +167,7 @@ Browser Controller Objects -------------------------- -Browser controllers provide two methods which parallel two of the module-level +Browser controllers provide these methods which parallel two of the module-level convenience functions: Modified: python/branches/release30-maint/Doc/library/xml.etree.elementtree.rst ============================================================================== --- python/branches/release30-maint/Doc/library/xml.etree.elementtree.rst (original) +++ python/branches/release30-maint/Doc/library/xml.etree.elementtree.rst Thu Jan 1 16:09:10 2009 @@ -94,6 +94,16 @@ *events* is a list of events to report back. If omitted, only "end" events are reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs. + .. note:: + + :func:`iterparse` only guarantees that it has seen the ">" + character of a starting tag when it emits a "start" event, so the + attributes are defined, but the contents of the text and tail attributes + are undefined at that point. The same applies to the element children; + they may or may not be present. + + If you need a fully populated element, look for "end" events instead. + .. function:: parse(source[, parser]) Modified: python/branches/release30-maint/Lib/dis.py ============================================================================== --- python/branches/release30-maint/Lib/dis.py (original) +++ python/branches/release30-maint/Lib/dis.py Thu Jan 1 16:09:10 2009 @@ -6,7 +6,8 @@ from opcode import * from opcode import __all__ as _opcodes_all -__all__ = ["dis","disassemble","distb","disco"] + _opcodes_all +__all__ = ["dis", "disassemble", "distb", "disco", + "findlinestarts", "findlabels"] + _opcodes_all del _opcodes_all def dis(x=None): Modified: python/branches/release30-maint/Lib/re.py ============================================================================== --- python/branches/release30-maint/Lib/re.py (original) +++ python/branches/release30-maint/Lib/re.py Thu Jan 1 16:09:10 2009 @@ -160,7 +160,8 @@ """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; - if a callable, it's passed the match object and must return + if a string, backslash escapes in it are processed. If it is + a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).sub(repl, string, count) @@ -170,7 +171,8 @@ non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a - callable; if a callable, it's passed the match object and must + callable; if a string, backslash escapes in it are processed. + If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).subn(repl, string, count) From python-checkins at python.org Thu Jan 1 16:33:11 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 16:33:11 +0100 (CET) Subject: [Python-checkins] r68131 - python/branches/release26-maint Message-ID: <20090101153311.6D64E1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 16:33:10 2009 New Revision: 68131 Log: Blocked revisions 67902,67946,67954,67976,67978-67980,67985,68089,68092,68119 via svnmerge ........ r67902 | benjamin.peterson | 2008-12-22 21:16:25 +0100 (Mon, 22 Dec 2008) | 1 line add py3k warnings to frame.f_exc_* ........ r67946 | antoine.pitrou | 2008-12-27 16:43:12 +0100 (Sat, 27 Dec 2008) | 4 lines Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by Gabriel Genellina. ........ r67954 | benjamin.peterson | 2008-12-27 19:24:11 +0100 (Sat, 27 Dec 2008) | 1 line #4748 lambda generators shouldn't return values ........ r67976 | georg.brandl | 2008-12-28 12:54:53 +0100 (Sun, 28 Dec 2008) | 7 lines Backport r67974: #4759: allow None as first argument of bytearray.translate(), for consistency with bytes.translate(). Also fix segfault for bytearray.translate(x, None) -- will backport this part to 3.0 and 2.6. ........ r67978 | georg.brandl | 2008-12-28 12:58:49 +0100 (Sun, 28 Dec 2008) | 2 lines #4731: clarify message about missing module prerequisites. ........ r67979 | antoine.pitrou | 2008-12-28 15:09:36 +0100 (Sun, 28 Dec 2008) | 3 lines Issue #4444: Allow assertRaises() to be used as a context handler. ........ r67980 | antoine.pitrou | 2008-12-28 15:24:29 +0100 (Sun, 28 Dec 2008) | 1 line wrong version number in doc changes committed in r67979 ........ r67985 | antoine.pitrou | 2008-12-28 17:01:11 +0100 (Sun, 28 Dec 2008) | 4 lines Issue #2153: modernize coding style of unittest.py, remove obsolete compatibility stuff. Patch by Virgil Dupras. ........ r68089 | benjamin.peterson | 2008-12-31 04:37:51 +0100 (Wed, 31 Dec 2008) | 1 line #4788 qualify some bare except clauses ........ r68092 | benjamin.peterson | 2008-12-31 05:08:55 +0100 (Wed, 31 Dec 2008) | 1 line fix name collision issues ........ r68119 | georg.brandl | 2009-01-01 13:09:40 +0100 (Thu, 01 Jan 2009) | 3 lines #4222: document dis.findlabels() and dis.findlinestarts() and put them into dis.__all__. ........ Modified: python/branches/release26-maint/ (props changed) From python-checkins at python.org Thu Jan 1 16:35:34 2009 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 1 Jan 2009 16:35:34 +0100 (CET) Subject: [Python-checkins] r68132 - in python/branches/py3k: Lib/test/test_deque.py Lib/test/test_dict.py Lib/test/test_set.py Misc/NEWS Modules/_collectionsmodule.c Objects/dictobject.c Objects/setobject.c Message-ID: <20090101153534.BD5C01E4002@bag.python.org> Author: antoine.pitrou Date: Thu Jan 1 16:35:33 2009 New Revision: 68132 Log: Merged revisions 68128 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (jeu., 01 janv. 2009) | 3 lines Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_deque.py python/branches/py3k/Lib/test/test_dict.py python/branches/py3k/Lib/test/test_set.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_collectionsmodule.c python/branches/py3k/Objects/dictobject.c python/branches/py3k/Objects/setobject.c Modified: python/branches/py3k/Lib/test/test_deque.py ============================================================================== --- python/branches/py3k/Lib/test/test_deque.py (original) +++ python/branches/py3k/Lib/test/test_deque.py Thu Jan 1 16:35:33 2009 @@ -1,7 +1,8 @@ from collections import deque import unittest from test import support, seq_tests -from weakref import proxy +import gc +import weakref import copy import pickle from io import StringIO @@ -420,6 +421,22 @@ d.append(1) gc.collect() + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for deque iterator objects + class C(object): + pass + for i in range(2): + obj = C() + ref = weakref.ref(obj) + if i == 0: + container = deque([obj, 1]) + else: + container = reversed(deque([obj, 1])) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): @@ -530,7 +547,7 @@ def test_weakref(self): d = deque('gallahad') - p = proxy(d) + p = weakref.proxy(d) self.assertEqual(str(p), str(d)) d = None self.assertRaises(ReferenceError, str, p) Modified: python/branches/py3k/Lib/test/test_dict.py ============================================================================== --- python/branches/py3k/Lib/test/test_dict.py (original) +++ python/branches/py3k/Lib/test/test_dict.py Thu Jan 1 16:35:33 2009 @@ -2,6 +2,7 @@ from test import support import sys, collections, random, string +import gc, weakref class DictTest(unittest.TestCase): @@ -648,6 +649,21 @@ pass d = {} + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for dictiter and + # dictview objects. + class C(object): + pass + views = (dict.items, dict.values, dict.keys) + for v in views: + obj = C() + ref = weakref.ref(obj) + container = {obj: 1} + obj.v = v(container) + obj.x = iter(obj.v) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") from test import mapping_tests Modified: python/branches/py3k/Lib/test/test_set.py ============================================================================== --- python/branches/py3k/Lib/test/test_set.py (original) +++ python/branches/py3k/Lib/test/test_set.py Thu Jan 1 16:35:33 2009 @@ -1,6 +1,7 @@ import unittest from test import support -from weakref import proxy +import gc +import weakref import operator import copy import pickle @@ -323,6 +324,18 @@ self.assertEqual(sum(elem.hash_count for elem in d), n) self.assertEqual(d3, dict.fromkeys(d, 123)) + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for set iterator object + class C(object): + pass + obj = C() + ref = weakref.ref(obj) + container = set([obj, 1]) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestSet(TestJointOps): thetype = set basetype = set @@ -546,7 +559,7 @@ def test_weakref(self): s = self.thetype('gallahad') - p = proxy(s) + p = weakref.proxy(s) self.assertEqual(str(p), str(s)) s = None self.assertRaises(ReferenceError, str, p) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Jan 1 16:35:33 2009 @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #3680: Reference cycles created through a dict, set or deque iterator + did not get collected. + - Issue #4701: PyObject_Hash now implicitly calls PyType_Ready on types where the tp_hash and tp_dict slots are both NULL. Modified: python/branches/py3k/Modules/_collectionsmodule.c ============================================================================== --- python/branches/py3k/Modules/_collectionsmodule.c (original) +++ python/branches/py3k/Modules/_collectionsmodule.c Thu Jan 1 16:35:33 2009 @@ -900,7 +900,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequeiter_type); + it = PyObject_GC_New(dequeiterobject, &dequeiter_type); if (it == NULL) return NULL; it->b = deque->leftblock; @@ -909,14 +909,22 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } +static int +dequeiter_traverse(dequeiterobject *dio, visitproc visit, void *arg) +{ + Py_VISIT(dio->deque); + return 0; +} + static void dequeiter_dealloc(dequeiterobject *dio) { Py_XDECREF(dio->deque); - Py_TYPE(dio)->tp_free(dio); + PyObject_GC_Del(dio); } static PyObject * @@ -981,9 +989,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -1002,7 +1010,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequereviter_type); + it = PyObject_GC_New(dequeiterobject, &dequereviter_type); if (it == NULL) return NULL; it->b = deque->rightblock; @@ -1011,6 +1019,7 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } @@ -1063,9 +1072,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/branches/py3k/Objects/dictobject.c ============================================================================== --- python/branches/py3k/Objects/dictobject.c (original) +++ python/branches/py3k/Objects/dictobject.c Thu Jan 1 16:35:33 2009 @@ -2122,7 +2122,7 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) { dictiterobject *di; - di = PyObject_New(dictiterobject, itertype); + di = PyObject_GC_New(dictiterobject, itertype); if (di == NULL) return NULL; Py_INCREF(dict); @@ -2139,6 +2139,7 @@ } else di->di_result = NULL; + _PyObject_GC_TRACK(di); return (PyObject *)di; } @@ -2147,7 +2148,15 @@ { Py_XDECREF(di->di_dict); Py_XDECREF(di->di_result); - PyObject_Del(di); + PyObject_GC_Del(di); +} + +static int +dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) +{ + Py_VISIT(di->di_dict); + Py_VISIT(di->di_result); + return 0; } static PyObject * @@ -2228,9 +2237,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2300,9 +2309,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2386,9 +2395,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2415,7 +2424,14 @@ dictview_dealloc(dictviewobject *dv) { Py_XDECREF(dv->dv_dict); - PyObject_Del(dv); + PyObject_GC_Del(dv); +} + +static int +dictview_traverse(dictviewobject *dv, visitproc visit, void *arg) +{ + Py_VISIT(dv->dv_dict); + return 0; } static Py_ssize_t @@ -2442,11 +2458,12 @@ type->tp_name, dict->ob_type->tp_name); return NULL; } - dv = PyObject_New(dictviewobject, type); + dv = PyObject_GC_New(dictviewobject, type); if (dv == NULL) return NULL; Py_INCREF(dict); dv->dv_dict = (PyDictObject *)dict; + _PyObject_GC_TRACK(dv); return (PyObject *)dv; } @@ -2693,9 +2710,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictview_traverse, /* tp_traverse */ 0, /* tp_clear */ dictview_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2777,9 +2794,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictview_traverse, /* tp_traverse */ 0, /* tp_clear */ dictview_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2842,9 +2859,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictview_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/branches/py3k/Objects/setobject.c ============================================================================== --- python/branches/py3k/Objects/setobject.c (original) +++ python/branches/py3k/Objects/setobject.c Thu Jan 1 16:35:33 2009 @@ -802,7 +802,14 @@ setiter_dealloc(setiterobject *si) { Py_XDECREF(si->si_set); - PyObject_Del(si); + PyObject_GC_Del(si); +} + +static int +setiter_traverse(setiterobject *si, visitproc visit, void *arg) +{ + Py_VISIT(si->si_set); + return 0; } static PyObject * @@ -880,9 +887,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)setiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -895,7 +902,7 @@ static PyObject * set_iter(PySetObject *so) { - setiterobject *si = PyObject_New(setiterobject, &PySetIter_Type); + setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type); if (si == NULL) return NULL; Py_INCREF(so); @@ -903,6 +910,7 @@ si->si_used = so->used; si->si_pos = 0; si->len = so->used; + _PyObject_GC_TRACK(si); return (PyObject *)si; } From python-checkins at python.org Thu Jan 1 16:38:03 2009 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 1 Jan 2009 16:38:03 +0100 (CET) Subject: [Python-checkins] r68133 - in python/trunk/Lib/test: test_deque.py test_dict.py test_set.py Message-ID: <20090101153803.A35B41E4002@bag.python.org> Author: antoine.pitrou Date: Thu Jan 1 16:38:03 2009 New Revision: 68133 Log: fill in actual issue number in tests Modified: python/trunk/Lib/test/test_deque.py python/trunk/Lib/test/test_dict.py python/trunk/Lib/test/test_set.py Modified: python/trunk/Lib/test/test_deque.py ============================================================================== --- python/trunk/Lib/test/test_deque.py (original) +++ python/trunk/Lib/test/test_deque.py Thu Jan 1 16:38:03 2009 @@ -420,7 +420,7 @@ gc.collect() def test_container_iterator(self): - # Bug # XXX: tp_traverse was not implemented for deque iterator objects + # Bug #3680: tp_traverse was not implemented for deque iterator objects class C(object): pass for i in range(2): Modified: python/trunk/Lib/test/test_dict.py ============================================================================== --- python/trunk/Lib/test/test_dict.py (original) +++ python/trunk/Lib/test/test_dict.py Thu Jan 1 16:38:03 2009 @@ -556,7 +556,7 @@ d = {} def test_container_iterator(self): - # Bug # XXX: tp_traverse was not implemented for dictiter objects + # Bug #3680: tp_traverse was not implemented for dictiter objects class C(object): pass iterators = (dict.iteritems, dict.itervalues, dict.iterkeys) Modified: python/trunk/Lib/test/test_set.py ============================================================================== --- python/trunk/Lib/test/test_set.py (original) +++ python/trunk/Lib/test/test_set.py Thu Jan 1 16:38:03 2009 @@ -324,7 +324,7 @@ self.assertEqual(d3, dict.fromkeys(d, 123)) def test_container_iterator(self): - # Bug # XXX: tp_traverse was not implemented for set iterator object + # Bug #3680: tp_traverse was not implemented for set iterator object class C(object): pass obj = C() From python-checkins at python.org Thu Jan 1 16:45:40 2009 From: python-checkins at python.org (hirokazu.yamamoto) Date: Thu, 1 Jan 2009 16:45:40 +0100 (CET) Subject: [Python-checkins] r68134 - in python/trunk: Misc/NEWS Modules/_fileio.c Message-ID: <20090101154540.1B4501E402A@bag.python.org> Author: hirokazu.yamamoto Date: Thu Jan 1 16:45:39 2009 New Revision: 68134 Log: Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. Modified: python/trunk/Misc/NEWS python/trunk/Modules/_fileio.c Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Thu Jan 1 16:45:39 2009 @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open + file with `str' filename on Windows. + - Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. Modified: python/trunk/Modules/_fileio.c ============================================================================== --- python/trunk/Modules/_fileio.c (original) +++ python/trunk/Modules/_fileio.c Thu Jan 1 16:45:39 2009 @@ -265,10 +265,11 @@ Py_END_ALLOW_THREADS if (self->fd < 0) { #ifdef MS_WINDOWS - PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename); -#else - PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); + if (widename != NULL) + PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename); + else #endif + PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); goto error; } if(dircheck(self, name) < 0) From python-checkins at python.org Thu Jan 1 16:46:11 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 16:46:11 +0100 (CET) Subject: [Python-checkins] r68135 - in python/branches/release26-maint: Doc/c-api/arg.rst Doc/c-api/exceptions.rst Doc/distutils/apiref.rst Doc/howto/unicode.rst Doc/library/email.mime.rst Doc/library/json.rst Doc/library/logging.rst Doc/library/multiprocessing.rst Doc/library/new.rst Doc/library/pydoc.rst Doc/library/socketserver.rst Doc/library/urllib2.rst Doc/library/webbrowser.rst Doc/library/winsound.rst Doc/library/xml.etree.elementtree.rst Include/unicodeobject.h Lib/distutils/util.py Lib/inspect.py Lib/pydoc.py Lib/re.py Lib/test/test_deque.py Lib/test/test_dict.py Lib/test/test_file.py Lib/test/test_fileio.py Lib/test/test_set.py Lib/test/test_struct.py Lib/textwrap.py Misc/NEWS Modules/_collectionsmodule.c Modules/_fileio.c Modules/_struct.c Objects/dictobject.c Objects/fileobject.c Objects/setobject.c Tools/pybench/Lists.py Message-ID: <20090101154611.587EA1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 16:46:10 2009 New Revision: 68135 Log: Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67952 | georg.brandl | 2008-12-27 18:42:40 +0100 (Sat, 27 Dec 2008) | 2 lines #4752: actually use custom handler in example. ........ r67953 | georg.brandl | 2008-12-27 19:20:04 +0100 (Sat, 27 Dec 2008) | 3 lines Patch #4739 by David Laban: add symbols to pydoc help topics, so that ``help('@')`` works as expected. ........ r67955 | georg.brandl | 2008-12-27 19:27:53 +0100 (Sat, 27 Dec 2008) | 3 lines Follow-up to r67746 in order to restore backwards-compatibility for those who (monkey-)patch TextWrapper.wordsep_re with a custom RE. ........ r67957 | georg.brandl | 2008-12-27 19:49:19 +0100 (Sat, 27 Dec 2008) | 2 lines #4754: improve winsound documentation. ........ r67958 | georg.brandl | 2008-12-27 20:02:59 +0100 (Sat, 27 Dec 2008) | 2 lines #4682: 'b' is actually unsigned char. ........ r67960 | georg.brandl | 2008-12-27 20:04:44 +0100 (Sat, 27 Dec 2008) | 2 lines #4695: fix backslashery. ........ r67961 | georg.brandl | 2008-12-27 20:06:04 +0100 (Sat, 27 Dec 2008) | 2 lines Use :samp: role. ........ r67963 | georg.brandl | 2008-12-27 20:11:15 +0100 (Sat, 27 Dec 2008) | 2 lines #4671: document that pydoc imports modules. ........ r67965 | antoine.pitrou | 2008-12-27 21:34:52 +0100 (Sat, 27 Dec 2008) | 3 lines Issue #4677: add two list comprehension tests to pybench. ........ r67967 | benjamin.peterson | 2008-12-27 23:18:58 +0100 (Sat, 27 Dec 2008) | 1 line fix markup ........ r67970 | alexandre.vassalotti | 2008-12-28 02:52:58 +0100 (Sun, 28 Dec 2008) | 2 lines Fix name mangling of PyUnicode_ClearFreeList. ........ r67971 | alexandre.vassalotti | 2008-12-28 03:10:35 +0100 (Sun, 28 Dec 2008) | 2 lines Sort UCS-2/UCS-4 name mangling list. ........ r67973 | alexandre.vassalotti | 2008-12-28 03:58:22 +0100 (Sun, 28 Dec 2008) | 2 lines Document Py_VaBuildValue. ........ r67982 | benjamin.peterson | 2008-12-28 16:37:31 +0100 (Sun, 28 Dec 2008) | 1 line fix WORD_BIGEDIAN declaration in Universal builds; fixes #4060 and #4728 ........ r67988 | ronald.oussoren | 2008-12-28 20:40:56 +0100 (Sun, 28 Dec 2008) | 1 line Issue4064: architecture string for universal builds on OSX ........ r67990 | ronald.oussoren | 2008-12-28 20:50:40 +0100 (Sun, 28 Dec 2008) | 3 lines Update the fix for issue4064 to deal correctly with all three variants of universal builds that are presented by the configure script. ........ r67995 | benjamin.peterson | 2008-12-28 22:16:07 +0100 (Sun, 28 Dec 2008) | 1 line #4763 PyErr_ExceptionMatches won't blow up with NULL arguments ........ r68014 | benjamin.peterson | 2008-12-29 18:47:42 +0100 (Mon, 29 Dec 2008) | 1 line #4764 set IOError.filename when trying to open a directory on POSIX platforms ........ r68016 | benjamin.peterson | 2008-12-29 18:56:58 +0100 (Mon, 29 Dec 2008) | 1 line #4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms ........ r68030 | benjamin.peterson | 2008-12-29 22:38:14 +0100 (Mon, 29 Dec 2008) | 1 line fix French ........ r68057 | vinay.sajip | 2008-12-30 08:01:25 +0100 (Tue, 30 Dec 2008) | 1 line Minor documentation change relating to NullHandler. ........ r68061 | georg.brandl | 2008-12-30 11:15:49 +0100 (Tue, 30 Dec 2008) | 2 lines #4778: attributes can't be called. ........ r68112 | benjamin.peterson | 2009-01-01 00:48:39 +0100 (Thu, 01 Jan 2009) | 1 line #4795 inspect.isgeneratorfunction() should return False instead of None ........ r68115 | benjamin.peterson | 2009-01-01 05:04:41 +0100 (Thu, 01 Jan 2009) | 1 line simplfy code ........ r68116 | georg.brandl | 2009-01-01 12:46:51 +0100 (Thu, 01 Jan 2009) | 2 lines #4100: note that element children are not necessarily present on "start" events. ........ r68117 | georg.brandl | 2009-01-01 12:53:55 +0100 (Thu, 01 Jan 2009) | 2 lines #4156: make clear that "protocol" is to be replaced with the protocol name. ........ r68118 | georg.brandl | 2009-01-01 13:00:19 +0100 (Thu, 01 Jan 2009) | 2 lines #4185: clarify escape behavior of replacement strings. ........ r68120 | georg.brandl | 2009-01-01 13:15:31 +0100 (Thu, 01 Jan 2009) | 4 lines #4228: Pack negative values the same way as 2.4 in struct's L format. ........ r68121 | georg.brandl | 2009-01-01 13:43:33 +0100 (Thu, 01 Jan 2009) | 2 lines Point to types module in new module deprecation notice. ........ r68123 | georg.brandl | 2009-01-01 13:52:29 +0100 (Thu, 01 Jan 2009) | 2 lines #4784: ... on three counts ... ........ r68124 | georg.brandl | 2009-01-01 13:53:19 +0100 (Thu, 01 Jan 2009) | 2 lines #4782: Fix markup error that hid load() and loads(). ........ r68125 | georg.brandl | 2009-01-01 14:02:09 +0100 (Thu, 01 Jan 2009) | 2 lines #4776: add data_files and package_dir arguments. ........ r68126 | georg.brandl | 2009-01-01 14:05:13 +0100 (Thu, 01 Jan 2009) | 2 lines Handlers are in the `logging.handlers` module. ........ r68127 | georg.brandl | 2009-01-01 14:14:49 +0100 (Thu, 01 Jan 2009) | 2 lines #4767: Use correct submodules for all MIME classes. ........ r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (Thu, 01 Jan 2009) | 3 lines Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. ........ Modified: python/branches/release26-maint/ (props changed) python/branches/release26-maint/Doc/c-api/arg.rst python/branches/release26-maint/Doc/c-api/exceptions.rst python/branches/release26-maint/Doc/distutils/apiref.rst python/branches/release26-maint/Doc/howto/unicode.rst python/branches/release26-maint/Doc/library/email.mime.rst python/branches/release26-maint/Doc/library/json.rst python/branches/release26-maint/Doc/library/logging.rst python/branches/release26-maint/Doc/library/multiprocessing.rst python/branches/release26-maint/Doc/library/new.rst python/branches/release26-maint/Doc/library/pydoc.rst python/branches/release26-maint/Doc/library/socketserver.rst python/branches/release26-maint/Doc/library/urllib2.rst python/branches/release26-maint/Doc/library/webbrowser.rst python/branches/release26-maint/Doc/library/winsound.rst python/branches/release26-maint/Doc/library/xml.etree.elementtree.rst python/branches/release26-maint/Include/unicodeobject.h python/branches/release26-maint/Lib/distutils/util.py python/branches/release26-maint/Lib/inspect.py python/branches/release26-maint/Lib/pydoc.py python/branches/release26-maint/Lib/re.py python/branches/release26-maint/Lib/test/test_deque.py python/branches/release26-maint/Lib/test/test_dict.py python/branches/release26-maint/Lib/test/test_file.py python/branches/release26-maint/Lib/test/test_fileio.py python/branches/release26-maint/Lib/test/test_set.py python/branches/release26-maint/Lib/test/test_struct.py python/branches/release26-maint/Lib/textwrap.py python/branches/release26-maint/Misc/NEWS python/branches/release26-maint/Modules/_collectionsmodule.c python/branches/release26-maint/Modules/_fileio.c python/branches/release26-maint/Modules/_struct.c python/branches/release26-maint/Objects/dictobject.c python/branches/release26-maint/Objects/fileobject.c python/branches/release26-maint/Objects/setobject.c python/branches/release26-maint/Tools/pybench/Lists.py Modified: python/branches/release26-maint/Doc/c-api/arg.rst ============================================================================== --- python/branches/release26-maint/Doc/c-api/arg.rst (original) +++ python/branches/release26-maint/Doc/c-api/arg.rst Thu Jan 1 16:46:10 2009 @@ -136,8 +136,9 @@ them. Instead, the implementation assumes that the string object uses the encoding passed in as parameter. -``b`` (integer) [char] - Convert a Python integer to a tiny int, stored in a C :ctype:`char`. +``b`` (integer) [unsigned char] + Convert a nonnegative Python integer to an unsigned tiny int, stored in a C + :ctype:`unsigned char`. ``B`` (integer) [unsigned char] Convert a Python integer to a tiny int without overflow checking, stored in a C @@ -533,3 +534,8 @@ If there is an error in the format string, the :exc:`SystemError` exception is set and *NULL* returned. + +.. cfunction:: PyObject* Py_VaBuildValue(const char *format, va_list vargs) + + Identical to :cfunc:`Py_BuildValue`, except that it accepts a va_list + rather than a variable number of arguments. Modified: python/branches/release26-maint/Doc/c-api/exceptions.rst ============================================================================== --- python/branches/release26-maint/Doc/c-api/exceptions.rst (original) +++ python/branches/release26-maint/Doc/c-api/exceptions.rst Thu Jan 1 16:46:10 2009 @@ -73,11 +73,10 @@ .. cfunction:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc) - Return true if the *given* exception matches the exception in *exc*. If *exc* - is a class object, this also returns true when *given* is an instance of a - subclass. If *exc* is a tuple, all exceptions in the tuple (and recursively in - subtuples) are searched for a match. If *given* is *NULL*, a memory access - violation will occur. + Return true if the *given* exception matches the exception in *exc*. If + *exc* is a class object, this also returns true when *given* is an instance + of a subclass. If *exc* is a tuple, all exceptions in the tuple (and + recursively in subtuples) are searched for a match. .. cfunction:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb) Modified: python/branches/release26-maint/Doc/distutils/apiref.rst ============================================================================== --- python/branches/release26-maint/Doc/distutils/apiref.rst (original) +++ python/branches/release26-maint/Doc/distutils/apiref.rst Thu Jan 1 16:46:10 2009 @@ -88,9 +88,9 @@ | *options* | default options for the setup | a string | | | script | | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *license* | The license for the package | | + | *license* | The license for the package | a string | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *keywords* | Descriptive meta-data. See | | + | *keywords* | Descriptive meta-data, see | | | | :pep:`314` | | +--------------------+--------------------------------+-------------------------------------------------------------+ | *platforms* | | | @@ -98,6 +98,13 @@ | *cmdclass* | A mapping of command names to | a dictionary | | | :class:`Command` subclasses | | +--------------------+--------------------------------+-------------------------------------------------------------+ + | *data_files* | A list of data files to | a list | + | | install | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + | *package_dir* | A mapping of package to | a dictionary | + | | directory names | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + .. function:: run_setup(script_name[, script_args=None, stop_after='run']) @@ -1100,6 +1107,24 @@ For non-POSIX platforms, currently just returns ``sys.platform``. + For MacOS X systems the OS version reflects the minimal version on which + binaries will run (that is, the value of ``MACOSX_DEPLOYMENT_TARGET`` + during the build of Python), not the OS version of the current system. + + For universal binary builds on MacOS X the architecture value reflects + the univeral binary status instead of the architecture of the current + processor. For 32-bit universal binaries the architecture is ``fat``, + for 64-bit universal binaries the architecture is ``fat64``, and + for 4-way universal binaries the architecture is ``universal``. + + Examples of returned values on MacOS X: + + * ``macosx-10.3-ppc`` + + * ``macosx-10.3-fat`` + + * ``macosx-10.5-universal`` + .. % XXX isn't this also provided by some other non-distutils module? Modified: python/branches/release26-maint/Doc/howto/unicode.rst ============================================================================== --- python/branches/release26-maint/Doc/howto/unicode.rst (original) +++ python/branches/release26-maint/Doc/howto/unicode.rst Thu Jan 1 16:46:10 2009 @@ -30,7 +30,7 @@ looking at Apple ][ BASIC programs, published in French-language publications in the mid-1980s, that had lines like these:: - PRINT "FICHER EST COMPLETE." + PRINT "FICHIER EST COMPLETE." PRINT "CARACTERE NON ACCEPTE." Those messages should contain accents, and they just look wrong to someone who Modified: python/branches/release26-maint/Doc/library/email.mime.rst ============================================================================== --- python/branches/release26-maint/Doc/library/email.mime.rst (original) +++ python/branches/release26-maint/Doc/library/email.mime.rst Thu Jan 1 16:46:10 2009 @@ -19,6 +19,7 @@ Here are the classes: +.. currentmodule:: email.mime.base .. class:: MIMEBase(_maintype, _subtype, **_params) @@ -39,6 +40,8 @@ :mailheader:`MIME-Version` header (always set to ``1.0``). +.. currentmodule:: email.mime.nonmultipart + .. class:: MIMENonMultipart() Module: :mod:`email.mime.nonmultipart` @@ -52,6 +55,8 @@ .. versionadded:: 2.2.2 +.. currentmodule:: email.mime.multipart + .. class:: MIMEMultipart([subtype[, boundary[, _subparts[, _params]]]]) Module: :mod:`email.mime.multipart` @@ -77,6 +82,8 @@ .. versionadded:: 2.2.2 +.. currentmodule:: email.mime.application + .. class:: MIMEApplication(_data[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.application` @@ -99,6 +106,8 @@ .. versionadded:: 2.5 +.. currentmodule:: email.mime.audio + .. class:: MIMEAudio(_audiodata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.audio` @@ -122,6 +131,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.image + .. class:: MIMEImage(_imagedata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.image` @@ -145,6 +156,8 @@ *_params* are passed straight through to the :class:`MIMEBase` constructor. +.. currentmodule:: email.mime.message + .. class:: MIMEMessage(_msg[, _subtype]) Module: :mod:`email.mime.message` @@ -158,6 +171,8 @@ :mimetype:`rfc822`. +.. currentmodule:: email.mime.text + .. class:: MIMEText(_text[, _subtype[, _charset]]) Module: :mod:`email.mime.text` Modified: python/branches/release26-maint/Doc/library/json.rst ============================================================================== --- python/branches/release26-maint/Doc/library/json.rst (original) +++ python/branches/release26-maint/Doc/library/json.rst Thu Jan 1 16:46:10 2009 @@ -166,7 +166,7 @@ :func:`dump`. -.. function load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. @@ -202,7 +202,7 @@ class. -.. function loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON document) to a Python object. Modified: python/branches/release26-maint/Doc/library/logging.rst ============================================================================== --- python/branches/release26-maint/Doc/library/logging.rst (original) +++ python/branches/release26-maint/Doc/library/logging.rst Thu Jan 1 16:46:10 2009 @@ -553,10 +553,10 @@ #. :class:`HTTPHandler` instances send error messages to an HTTP server using either ``GET`` or ``POST`` semantics. -The :class:`StreamHandler` and :class:`FileHandler` classes are defined in the -core logging package. The other handlers are defined in a sub- module, -:mod:`logging.handlers`. (There is also another sub-module, -:mod:`logging.config`, for configuration functionality.) +The :class:`NullHandler`, :class:`StreamHandler` and :class:`FileHandler` +classes are defined in the core logging package. The other handlers are +defined in a sub- module, :mod:`logging.handlers`. (There is also another +sub-module, :mod:`logging.config`, for configuration functionality.) Logged messages are formatted for presentation through instances of the :class:`Formatter` class. They are initialized with a format string suitable for @@ -1544,6 +1544,8 @@ StreamHandler ^^^^^^^^^^^^^ +.. module:: logging.handlers + The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -2050,6 +2052,8 @@ Formatter Objects ----------------- +.. currentmodule:: logging + :class:`Formatter`\ s have the following attributes and methods. They are responsible for converting a :class:`LogRecord` to (usually) a string which can be interpreted by either a human or an external system. The base Modified: python/branches/release26-maint/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/release26-maint/Doc/library/multiprocessing.rst (original) +++ python/branches/release26-maint/Doc/library/multiprocessing.rst Thu Jan 1 16:46:10 2009 @@ -358,7 +358,7 @@ .. attribute:: daemon - The process's daemon flag, a Boolean value. This must be called before + The process's daemon flag, a Boolean value. This must be set before :meth:`start` is called. The initial value is inherited from the creating process. @@ -1810,9 +1810,9 @@ filesystem. * An ``'AF_PIPE'`` address is a string of the form - ``r'\\\\.\\pipe\\PipeName'``. To use :func:`Client` to connect to a named + :samp:`r'\\\\.\\pipe\\{PipeName}'`. To use :func:`Client` to connect to a named pipe on a remote computer called ServerName* one should use an address of the - form ``r'\\\\ServerName\\pipe\\PipeName'`` instead. + form :samp:`r'\\\\{ServerName}\\pipe\\{PipeName}'`` instead. Note that any string beginning with two backslashes is assumed by default to be an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address. Modified: python/branches/release26-maint/Doc/library/new.rst ============================================================================== --- python/branches/release26-maint/Doc/library/new.rst (original) +++ python/branches/release26-maint/Doc/library/new.rst Thu Jan 1 16:46:10 2009 @@ -1,4 +1,3 @@ - :mod:`new` --- Creation of runtime internal objects =================================================== @@ -7,7 +6,8 @@ :deprecated: .. deprecated:: 2.6 - The :mod:`new` module has been removed in Python 3.0. + The :mod:`new` module has been removed in Python 3.0. Use the :mod:`types` + module's classes instead. .. sectionauthor:: Moshe Zadka Modified: python/branches/release26-maint/Doc/library/pydoc.rst ============================================================================== --- python/branches/release26-maint/Doc/library/pydoc.rst (original) +++ python/branches/release26-maint/Doc/library/pydoc.rst Thu Jan 1 16:46:10 2009 @@ -36,6 +36,13 @@ Unix), and refers to an existing Python source file, then documentation is produced for that file. +.. note:: + + In order to find objects and their documentation, :mod:`pydoc` imports the + module(s) to be documented. Therefore, any code on module level will be + executed on that occasion. Use an ``if __name__ == '__main__':`` guard to + only execute code when a file is invoked as a script and not just imported. + Specifying a :option:`-w` flag before the argument will cause HTML documentation to be written out to a file in the current directory, instead of displaying text on the console. Modified: python/branches/release26-maint/Doc/library/socketserver.rst ============================================================================== --- python/branches/release26-maint/Doc/library/socketserver.rst (original) +++ python/branches/release26-maint/Doc/library/socketserver.rst Thu Jan 1 16:46:10 2009 @@ -448,7 +448,7 @@ if __name__ == "__main__": HOST, PORT = "localhost", 9999 - server = SocketServer.UDPServer((HOST, PORT), BaseUDPRequestHandler) + server = SocketServer.UDPServer((HOST, PORT), MyUDPHandler) server.serve_forever() This is the client side:: Modified: python/branches/release26-maint/Doc/library/urllib2.rst ============================================================================== --- python/branches/release26-maint/Doc/library/urllib2.rst (original) +++ python/branches/release26-maint/Doc/library/urllib2.rst Thu Jan 1 16:46:10 2009 @@ -391,23 +391,23 @@ .. method:: OpenerDirector.add_handler(handler) - *handler* should be an instance of :class:`BaseHandler`. The following methods - are searched, and added to the possible chains (note that HTTP errors are a - special case). + *handler* should be an instance of :class:`BaseHandler`. The following + methods are searched, and added to the possible chains (note that HTTP errors + are a special case). - * :meth:`protocol_open` --- signal that the handler knows how to open *protocol* - URLs. + * :samp:`{protocol}_open` --- signal that the handler knows how to open + *protocol* URLs. - * :meth:`http_error_type` --- signal that the handler knows how to handle HTTP - errors with HTTP error code *type*. + * :samp:`http_error_{type}` --- signal that the handler knows how to handle + HTTP errors with HTTP error code *type*. - * :meth:`protocol_error` --- signal that the handler knows how to handle errors - from (non-\ ``http``) *protocol*. + * :samp:`{protocol}_error` --- signal that the handler knows how to handle + errors from (non-\ ``http``) *protocol*. - * :meth:`protocol_request` --- signal that the handler knows how to pre-process - *protocol* requests. + * :samp:`{protocol}_request` --- signal that the handler knows how to + pre-process *protocol* requests. - * :meth:`protocol_response` --- signal that the handler knows how to + * :samp:`{protocol}_response` --- signal that the handler knows how to post-process *protocol* responses. @@ -441,24 +441,24 @@ The order in which these methods are called within each stage is determined by sorting the handler instances. -#. Every handler with a method named like :meth:`protocol_request` has that +#. Every handler with a method named like :samp:`{protocol}_request` has that method called to pre-process the request. -#. Handlers with a method named like :meth:`protocol_open` are called to handle +#. Handlers with a method named like :samp:`{protocol}_open` are called to handle the request. This stage ends when a handler either returns a non-\ :const:`None` value (ie. a response), or raises an exception (usually :exc:`URLError`). Exceptions are allowed to propagate. In fact, the above algorithm is first tried for methods named - :meth:`default_open`. If all such methods return :const:`None`, the algorithm - is repeated for methods named like :meth:`protocol_open`. If all such methods - return :const:`None`, the algorithm is repeated for methods named - :meth:`unknown_open`. + :meth:`default_open`. If all such methods return :const:`None`, the + algorithm is repeated for methods named like :samp:`{protocol}_open`. If all + such methods return :const:`None`, the algorithm is repeated for methods + named :meth:`unknown_open`. Note that the implementation of these methods may involve calls of the parent :class:`OpenerDirector` instance's :meth:`.open` and :meth:`.error` methods. -#. Every handler with a method named like :meth:`protocol_response` has that +#. Every handler with a method named like :samp:`{protocol}_response` has that method called to post-process the response. @@ -514,8 +514,10 @@ .. method:: BaseHandler.protocol_open(req) :noindex: + ("protocol" is to be replaced by the protocol name.) + This method is *not* defined in :class:`BaseHandler`, but subclasses should - define it if they want to handle URLs with the given protocol. + define it if they want to handle URLs with the given *protocol*. This method, if defined, will be called by the parent :class:`OpenerDirector`. Return values should be the same as for :meth:`default_open`. @@ -563,8 +565,10 @@ .. method:: BaseHandler.protocol_request(req) :noindex: + ("protocol" is to be replaced by the protocol name.) + This method is *not* defined in :class:`BaseHandler`, but subclasses should - define it if they want to pre-process requests of the given protocol. + define it if they want to pre-process requests of the given *protocol*. This method, if defined, will be called by the parent :class:`OpenerDirector`. *req* will be a :class:`Request` object. The return value should be a @@ -574,8 +578,10 @@ .. method:: BaseHandler.protocol_response(req, response) :noindex: + ("protocol" is to be replaced by the protocol name.) + This method is *not* defined in :class:`BaseHandler`, but subclasses should - define it if they want to post-process responses of the given protocol. + define it if they want to post-process responses of the given *protocol*. This method, if defined, will be called by the parent :class:`OpenerDirector`. *req* will be a :class:`Request` object. *response* will be an object @@ -660,7 +666,9 @@ .. method:: ProxyHandler.protocol_open(request) :noindex: - The :class:`ProxyHandler` will have a method :meth:`protocol_open` for every + ("protocol" is to be replaced by the protocol name.) + + The :class:`ProxyHandler` will have a method :samp:`{protocol}_open` for every *protocol* which has a proxy in the *proxies* dictionary given in the constructor. The method will modify requests to go through the proxy, by calling ``request.set_proxy()``, and call the next handler in the chain to @@ -865,9 +873,10 @@ For 200 error codes, the response object is returned immediately. For non-200 error codes, this simply passes the job on to the - :meth:`protocol_error_code` handler methods, via :meth:`OpenerDirector.error`. - Eventually, :class:`urllib2.HTTPDefaultErrorHandler` will raise an - :exc:`HTTPError` if no other handler handles the error. + :samp:`{protocol}_error_code` handler methods, via + :meth:`OpenerDirector.error`. Eventually, + :class:`urllib2.HTTPDefaultErrorHandler` will raise an :exc:`HTTPError` if no + other handler handles the error. .. _urllib2-examples: Modified: python/branches/release26-maint/Doc/library/webbrowser.rst ============================================================================== --- python/branches/release26-maint/Doc/library/webbrowser.rst (original) +++ python/branches/release26-maint/Doc/library/webbrowser.rst Thu Jan 1 16:46:10 2009 @@ -172,7 +172,7 @@ Browser Controller Objects -------------------------- -Browser controllers provide two methods which parallel two of the module-level +Browser controllers provide these methods which parallel two of the module-level convenience functions: Modified: python/branches/release26-maint/Doc/library/winsound.rst ============================================================================== --- python/branches/release26-maint/Doc/library/winsound.rst (original) +++ python/branches/release26-maint/Doc/library/winsound.rst Thu Jan 1 16:46:10 2009 @@ -30,8 +30,9 @@ Call the underlying :cfunc:`PlaySound` function from the Platform API. The *sound* parameter may be a filename, audio data as a string, or ``None``. Its interpretation depends on the value of *flags*, which can be a bitwise ORed - combination of the constants described below. If the system indicates an error, - :exc:`RuntimeError` is raised. + combination of the constants described below. If the *sound* parameter is + ``None``, any currently playing waveform sound is stopped. If the system + indicates an error, :exc:`RuntimeError` is raised. .. function:: MessageBeep([type=MB_OK]) @@ -108,6 +109,10 @@ Stop playing all instances of the specified sound. + .. note:: + + This flag is not supported on modern Windows platforms. + .. data:: SND_ASYNC Modified: python/branches/release26-maint/Doc/library/xml.etree.elementtree.rst ============================================================================== --- python/branches/release26-maint/Doc/library/xml.etree.elementtree.rst (original) +++ python/branches/release26-maint/Doc/library/xml.etree.elementtree.rst Thu Jan 1 16:46:10 2009 @@ -94,6 +94,16 @@ *events* is a list of events to report back. If omitted, only "end" events are reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs. + .. note:: + + :func:`iterparse` only guarantees that it has seen the ">" + character of a starting tag when it emits a "start" event, so the + attributes are defined, but the contents of the text and tail attributes + are undefined at that point. The same applies to the element children; + they may or may not be present. + + If you need a fully populated element, look for "end" events instead. + .. function:: parse(source[, parser]) Modified: python/branches/release26-maint/Include/unicodeobject.h ============================================================================== --- python/branches/release26-maint/Include/unicodeobject.h (original) +++ python/branches/release26-maint/Include/unicodeobject.h Thu Jan 1 16:46:10 2009 @@ -153,6 +153,7 @@ # define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString # define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar +# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist # define PyUnicode_Compare PyUnicodeUCS2_Compare # define PyUnicode_Concat PyUnicodeUCS2_Concat # define PyUnicode_Contains PyUnicodeUCS2_Contains @@ -182,13 +183,13 @@ # define PyUnicode_Find PyUnicodeUCS2_Find # define PyUnicode_Format PyUnicodeUCS2_Format # define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject +# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat +# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV # define PyUnicode_FromObject PyUnicodeUCS2_FromObject # define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal -# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode # define PyUnicode_FromString PyUnicodeUCS2_FromString # define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize -# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV -# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat +# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode # define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar # define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding # define PyUnicode_GetMax PyUnicodeUCS2_GetMax @@ -209,7 +210,6 @@ # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString # define _PyUnicode_Fini _PyUnicodeUCS2_Fini # define _PyUnicode_Init _PyUnicodeUCS2_Init -# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist # define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit # define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit @@ -240,6 +240,7 @@ # define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString # define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar +# define PyUnicode_ClearFreeList PyUnicodeUCS4_ClearFreelist # define PyUnicode_Compare PyUnicodeUCS4_Compare # define PyUnicode_Concat PyUnicodeUCS4_Concat # define PyUnicode_Contains PyUnicodeUCS4_Contains @@ -269,13 +270,13 @@ # define PyUnicode_Find PyUnicodeUCS4_Find # define PyUnicode_Format PyUnicodeUCS4_Format # define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject +# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat +# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV # define PyUnicode_FromObject PyUnicodeUCS4_FromObject # define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal -# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode # define PyUnicode_FromString PyUnicodeUCS4_FromString # define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize -# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV -# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat +# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode # define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar # define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding # define PyUnicode_GetMax PyUnicodeUCS4_GetMax @@ -296,7 +297,6 @@ # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString # define _PyUnicode_Fini _PyUnicodeUCS4_Fini # define _PyUnicode_Init _PyUnicodeUCS4_Init -# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist # define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit # define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit Modified: python/branches/release26-maint/Lib/distutils/util.py ============================================================================== --- python/branches/release26-maint/Lib/distutils/util.py (original) +++ python/branches/release26-maint/Lib/distutils/util.py Thu Jan 1 16:46:10 2009 @@ -140,9 +140,13 @@ # 'universal' instead of 'fat'. machine = 'fat' + cflags = get_config_vars().get('CFLAGS') - if '-arch x86_64' in get_config_vars().get('CFLAGS'): - machine = 'universal' + if '-arch x86_64' in cflags: + if '-arch i386' in cflags: + machine = 'universal' + else: + machine = 'fat64' elif machine in ('PowerPC', 'Power_Macintosh'): # Pick a sane name for the PPC architecture. Modified: python/branches/release26-maint/Lib/inspect.py ============================================================================== --- python/branches/release26-maint/Lib/inspect.py (original) +++ python/branches/release26-maint/Lib/inspect.py Thu Jan 1 16:46:10 2009 @@ -158,9 +158,8 @@ Generator function objects provides same attributes as functions. See isfunction.__doc__ for attributes listing.""" - if (isfunction(object) or ismethod(object)) and \ - object.func_code.co_flags & CO_GENERATOR: - return True + return bool((isfunction(object) or ismethod(object)) and + object.func_code.co_flags & CO_GENERATOR) def isgenerator(object): """Return true if the object is a generator. Modified: python/branches/release26-maint/Lib/pydoc.py ============================================================================== --- python/branches/release26-maint/Lib/pydoc.py (original) +++ python/branches/release26-maint/Lib/pydoc.py Thu Jan 1 16:46:10 2009 @@ -1574,6 +1574,42 @@ 'with': ('with', 'CONTEXTMANAGERS EXCEPTIONS yield'), 'yield': ('yield', ''), } + # Either add symbols to this dictionary or to the symbols dictionary + # directly: Whichever is easier. They are merged later. + _symbols_inverse = { + 'STRINGS' : ("'", "'''", "r'", "u'", '"""', '"', 'r"', 'u"'), + 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', + '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), + 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'), + 'UNARY' : ('-', '~'), + 'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=', + '^=', '<<=', '>>=', '**=', '//='), + 'BITWISE' : ('<<', '>>', '&', '|', '^', '~'), + 'COMPLEX' : ('j', 'J') + } + symbols = { + '%': 'OPERATORS FORMATTING', + '**': 'POWER', + ',': 'TUPLES LISTS FUNCTIONS', + '.': 'ATTRIBUTES FLOAT MODULES OBJECTS', + '...': 'ELLIPSIS', + ':': 'SLICINGS DICTIONARYLITERALS', + '@': 'def class', + '\\': 'STRINGS', + '_': 'PRIVATENAMES', + '__': 'PRIVATENAMES SPECIALMETHODS', + '`': 'BACKQUOTES', + '(': 'TUPLES FUNCTIONS CALLS', + ')': 'TUPLES FUNCTIONS CALLS', + '[': 'LISTS SUBSCRIPTS SLICINGS', + ']': 'LISTS SUBSCRIPTS SLICINGS' + } + for topic, symbols_ in _symbols_inverse.iteritems(): + for symbol in symbols_: + topics = symbols.get(symbol, topic) + if topic not in topics: + topics = topics + ' ' + topic + symbols[symbol] = topics topics = { 'TYPES': ('types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS ' @@ -1717,10 +1753,12 @@ if type(request) is type(''): if request == 'help': self.intro() elif request == 'keywords': self.listkeywords() + elif request == 'symbols': self.listsymbols() elif request == 'topics': self.listtopics() elif request == 'modules': self.listmodules() elif request[:8] == 'modules ': self.listmodules(split(request)[1]) + elif request in self.symbols: self.showsymbol(request) elif request in self.keywords: self.showtopic(request) elif request in self.topics: self.showtopic(request) elif request: doc(request, 'Help on %s:') @@ -1766,6 +1804,14 @@ ''') self.list(self.keywords.keys()) + def listsymbols(self): + self.output.write(''' +Here is a list of the punctuation symbols which Python assigns special meaning +to. Enter any symbol to get more help. + +''') + self.list(self.symbols.keys()) + def listtopics(self): self.output.write(''' Here is a list of available topics. Enter any topic name to get more help. @@ -1773,7 +1819,7 @@ ''') self.list(self.topics.keys()) - def showtopic(self, topic): + def showtopic(self, topic, more_xrefs=''): try: import pydoc_topics except ImportError: @@ -1787,7 +1833,7 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return if type(target) is type(''): - return self.showtopic(target) + return self.showtopic(target, more_xrefs) label, xrefs = target try: @@ -1796,6 +1842,8 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return pager(strip(doc) + '\n') + if more_xrefs: + xrefs = (xrefs or '') + ' ' + more_xrefs if xrefs: import StringIO, formatter buffer = StringIO.StringIO() @@ -1803,6 +1851,11 @@ 'Related help topics: ' + join(split(xrefs), ', ') + '\n') self.output.write('\n%s\n' % buffer.getvalue()) + def showsymbol(self, symbol): + target = self.symbols[symbol] + topic, _, xrefs = target.partition(' ') + self.showtopic(topic, xrefs) + def listmodules(self, key=''): if key: self.output.write(''' Modified: python/branches/release26-maint/Lib/re.py ============================================================================== --- python/branches/release26-maint/Lib/re.py (original) +++ python/branches/release26-maint/Lib/re.py Thu Jan 1 16:46:10 2009 @@ -145,7 +145,8 @@ """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; - if a callable, it's passed the match object and must return + if a string, backslash escapes in it are processed. If it is + a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).sub(repl, string, count) @@ -155,7 +156,8 @@ non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a - callable; if a callable, it's passed the match object and must + callable; if a string, backslash escapes in it are processed. + If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).subn(repl, string, count) Modified: python/branches/release26-maint/Lib/test/test_deque.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_deque.py (original) +++ python/branches/release26-maint/Lib/test/test_deque.py Thu Jan 1 16:46:10 2009 @@ -1,7 +1,8 @@ from collections import deque import unittest from test import test_support, seq_tests -from weakref import proxy +import gc +import weakref import copy import cPickle as pickle import random @@ -418,6 +419,22 @@ d.append(1) gc.collect() + def test_container_iterator(self): + # Bug # XXX: tp_traverse was not implemented for deque iterator objects + class C(object): + pass + for i in range(2): + obj = C() + ref = weakref.ref(obj) + if i == 0: + container = deque([obj, 1]) + else: + container = reversed(deque([obj, 1])) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): @@ -528,7 +545,7 @@ def test_weakref(self): d = deque('gallahad') - p = proxy(d) + p = weakref.proxy(d) self.assertEqual(str(p), str(d)) d = None self.assertRaises(ReferenceError, str, p) Modified: python/branches/release26-maint/Lib/test/test_dict.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_dict.py (original) +++ python/branches/release26-maint/Lib/test/test_dict.py Thu Jan 1 16:46:10 2009 @@ -2,6 +2,7 @@ from test import test_support import UserDict, random, string +import gc, weakref class DictTest(unittest.TestCase): @@ -554,6 +555,19 @@ pass d = {} + def test_container_iterator(self): + # Bug # XXX: tp_traverse was not implemented for dictiter objects + class C(object): + pass + iterators = (dict.iteritems, dict.itervalues, dict.iterkeys) + for i in iterators: + obj = C() + ref = weakref.ref(obj) + container = {obj: 1} + obj.x = i(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") from test import mapping_tests Modified: python/branches/release26-maint/Lib/test/test_file.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_file.py (original) +++ python/branches/release26-maint/Lib/test/test_file.py Thu Jan 1 16:46:10 2009 @@ -125,6 +125,19 @@ class OtherFileTests(unittest.TestCase): + def testOpenDir(self): + this_dir = os.path.dirname(__file__) + for mode in (None, "w"): + try: + if mode: + f = open(this_dir, mode) + else: + f = open(this_dir) + except IOError as e: + self.assertEqual(e.filename, this_dir) + else: + self.fail("opening a directory didn't raise an IOError") + def testModeStrings(self): # check invalid mode strings for mode in ("", "aU", "wU+"): Modified: python/branches/release26-maint/Lib/test/test_fileio.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_fileio.py (original) +++ python/branches/release26-maint/Lib/test/test_fileio.py Thu Jan 1 16:46:10 2009 @@ -109,6 +109,7 @@ _fileio._FileIO('.', 'r') except IOError as e: self.assertNotEqual(e.errno, 0) + self.assertEqual(e.filename, ".") else: self.fail("Should have raised IOError") Modified: python/branches/release26-maint/Lib/test/test_set.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_set.py (original) +++ python/branches/release26-maint/Lib/test/test_set.py Thu Jan 1 16:46:10 2009 @@ -1,6 +1,7 @@ import unittest from test import test_support -from weakref import proxy +import gc +import weakref import operator import copy import pickle @@ -322,6 +323,18 @@ self.assertEqual(sum(elem.hash_count for elem in d), n) self.assertEqual(d3, dict.fromkeys(d, 123)) + def test_container_iterator(self): + # Bug # XXX: tp_traverse was not implemented for set iterator object + class C(object): + pass + obj = C() + ref = weakref.ref(obj) + container = set([obj, 1]) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestSet(TestJointOps): thetype = set @@ -538,7 +551,7 @@ def test_weakref(self): s = self.thetype('gallahad') - p = proxy(s) + p = weakref.proxy(s) self.assertEqual(str(p), str(s)) s = None self.assertRaises(ReferenceError, str, p) Modified: python/branches/release26-maint/Lib/test/test_struct.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_struct.py (original) +++ python/branches/release26-maint/Lib/test/test_struct.py Thu Jan 1 16:46:10 2009 @@ -2,6 +2,8 @@ import unittest import struct import warnings +warnings.filterwarnings("ignore", "struct integer overflow masking is deprecated", + DeprecationWarning) from functools import wraps from test.test_support import TestFailed, verbose, run_unittest @@ -461,6 +463,11 @@ self.check_float_coerce(endian + fmt, 1.0) self.check_float_coerce(endian + fmt, 1.5) + def test_issue4228(self): + # Packing a long may yield either 32 or 64 bits + x = struct.pack('L', -1)[:4] + self.assertEqual(x, '\xff'*4) + def test_unpack_from(self): test_string = 'abcd01234' fmt = '4s' Modified: python/branches/release26-maint/Lib/textwrap.py ============================================================================== --- python/branches/release26-maint/Lib/textwrap.py (original) +++ python/branches/release26-maint/Lib/textwrap.py Thu Jan 1 16:46:10 2009 @@ -84,7 +84,7 @@ # splits into # Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option! # (after stripping out empty strings). - wordsep_re = ( + wordsep_re = re.compile( r'(\s+|' # any whitespace r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|' # hyphenated words r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash @@ -93,7 +93,7 @@ # "Hello there -- you goof-ball, use the -b option!" # splits into # Hello/ /there/ /--/ /you/ /goof-ball,/ /use/ /the/ /-b/ /option!/ - wordsep_simple_re = r'(\s+)' + wordsep_simple_re = re.compile(r'(\s+)') # XXX this is not locale- or charset-aware -- string.lowercase # is US-ASCII only (and therefore English-only) @@ -124,6 +124,13 @@ self.drop_whitespace = drop_whitespace self.break_on_hyphens = break_on_hyphens + # recompile the regexes for Unicode mode -- done in this clumsy way for + # backwards compatibility because it's rather common to monkey-patch + # the TextWrapper class' wordsep_re attribute. + self.wordsep_re_uni = re.compile(self.wordsep_re.pattern, re.U) + self.wordsep_simple_re_uni = re.compile( + self.wordsep_simple_re.pattern, re.U) + # -- Private methods ----------------------------------------------- # (possibly useful for subclasses to override) @@ -160,12 +167,17 @@ 'use', ' ', 'the', ' ', '-b', ' ', option!' otherwise. """ - flags = re.UNICODE if isinstance(text, unicode) else 0 - if self.break_on_hyphens: - pat = self.wordsep_re + if isinstance(text, unicode): + if self.break_on_hyphens: + pat = self.wordsep_re_uni + else: + pat = self.wordsep_simple_re_uni else: - pat = self.wordsep_simple_re - chunks = re.compile(pat, flags).split(text) + if self.break_on_hyphens: + pat = self.wordsep_re + else: + pat = self.wordsep_simple_re + chunks = pat.split(text) chunks = filter(None, chunks) # remove empty chunks return chunks Modified: python/branches/release26-maint/Misc/NEWS ============================================================================== --- python/branches/release26-maint/Misc/NEWS (original) +++ python/branches/release26-maint/Misc/NEWS Thu Jan 1 16:46:10 2009 @@ -12,9 +12,21 @@ Core and Builtins ----------------- +- Issue #3680: Reference cycles created through a dict, set or deque iterator + did not get collected. + - Issue #4701: PyObject_Hash now implicitly calls PyType_Ready on types where the tp_hash and tp_dict slots are both NULL. +- Issue #4764: With io.open, IOError.filename is set when trying to open a + directory on POSIX systems. + +- Issue #4764: IOError.filename is set when trying to open a directory on POSIX + systems. + +- Issue #4759: None is now allowed as the first argument of + bytearray.translate(). It was always allowed for bytes.translate(). + - Issue #4759: fix a segfault for bytearray.translate(x, None). - Added test case to ensure attempts to read from a file opened for writing @@ -138,9 +150,18 @@ Library ------- +- Issue #4795: inspect.isgeneratorfunction() returns False instead of None when + the function is not a generator. + - Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case no MSVC compiler is found under Windows. Original patch by Philip Jenvey. + - Issue #4739: Add pydoc help topics for symbols, so that e.g. help('@') + works as expected in the interactive environment. + +- Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by + Gabriel Genellina. + - Issue #4646: distutils was choking on empty options arg in the setup function. Original patch by Thomas Heller. @@ -206,9 +227,16 @@ - Issue #4730: Fixed the cPickle module to handle correctly astral characters when protocol 0 is used. +Tools/Demos +----------- + +- Issue #4677: add two list comprehension tests to pybench. + Build ----- +- Issues #4728 and #4060: WORDS_BIGEDIAN is now correct in Universal builds. + - Issue #4389: Add icon to the uninstall entry in "add-and-remove-programs". - Issue #4289: Remove Cancel button from AdvancedDlg. @@ -239,6 +267,10 @@ Extension Modules ----------------- +- Issue #4228: Pack negative values the same way as 2.4 in struct's L format. + +- Issue #1040026: Fix os.times result on systems where HZ is incorrect. + - Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris, OpenBSD. Modified: python/branches/release26-maint/Modules/_collectionsmodule.c ============================================================================== --- python/branches/release26-maint/Modules/_collectionsmodule.c (original) +++ python/branches/release26-maint/Modules/_collectionsmodule.c Thu Jan 1 16:46:10 2009 @@ -958,7 +958,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequeiter_type); + it = PyObject_GC_New(dequeiterobject, &dequeiter_type); if (it == NULL) return NULL; it->b = deque->leftblock; @@ -967,14 +967,22 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } +static int +dequeiter_traverse(dequeiterobject *dio, visitproc visit, void *arg) +{ + Py_VISIT(dio->deque); + return 0; +} + static void dequeiter_dealloc(dequeiterobject *dio) { Py_XDECREF(dio->deque); - Py_TYPE(dio)->tp_free(dio); + PyObject_GC_Del(dio); } static PyObject * @@ -1039,9 +1047,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -1060,7 +1068,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequereviter_type); + it = PyObject_GC_New(dequeiterobject, &dequereviter_type); if (it == NULL) return NULL; it->b = deque->rightblock; @@ -1069,6 +1077,7 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } @@ -1121,9 +1130,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/branches/release26-maint/Modules/_fileio.c ============================================================================== --- python/branches/release26-maint/Modules/_fileio.c (original) +++ python/branches/release26-maint/Modules/_fileio.c Thu Jan 1 16:46:10 2009 @@ -98,7 +98,7 @@ directories, so we need a check. */ static int -dircheck(PyFileIOObject* self) +dircheck(PyFileIOObject* self, char *name) { #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) struct stat buf; @@ -109,8 +109,8 @@ PyObject *exc; internal_close(self); - exc = PyObject_CallFunction(PyExc_IOError, "(is)", - EISDIR, msg); + exc = PyObject_CallFunction(PyExc_IOError, "(iss)", + EISDIR, msg, name); PyErr_SetObject(PyExc_IOError, exc); Py_XDECREF(exc); return -1; @@ -271,7 +271,7 @@ #endif goto error; } - if(dircheck(self) < 0) + if(dircheck(self, name) < 0) goto error; } Modified: python/branches/release26-maint/Modules/_struct.c ============================================================================== --- python/branches/release26-maint/Modules/_struct.c (original) +++ python/branches/release26-maint/Modules/_struct.c Thu Jan 1 16:46:10 2009 @@ -663,7 +663,7 @@ return -1; #if (SIZEOF_LONG > SIZEOF_INT) if ((x < ((long)INT_MIN)) || (x > ((long)INT_MAX))) - return _range_error(f, 0); + RANGE_ERROR(x, f, 0, -1); #endif y = (int)x; memcpy(p, (char *)&y, sizeof y); @@ -675,12 +675,12 @@ { unsigned long x; unsigned int y; - if (get_ulong(v, &x) < 0) - return _range_error(f, 1); + if (get_wrapped_ulong(v, &x) < 0) + return -1; y = (unsigned int)x; #if (SIZEOF_LONG > SIZEOF_INT) if (x > ((unsigned long)UINT_MAX)) - return _range_error(f, 1); + RANGE_ERROR(y, f, 1, -1); #endif memcpy(p, (char *)&y, sizeof y); return 0; @@ -700,8 +700,8 @@ np_ulong(char *p, PyObject *v, const formatdef *f) { unsigned long x; - if (get_ulong(v, &x) < 0) - return _range_error(f, 1); + if (get_wrapped_ulong(v, &x) < 0) + return -1; memcpy(p, (char *)&x, sizeof x); return 0; } Modified: python/branches/release26-maint/Objects/dictobject.c ============================================================================== --- python/branches/release26-maint/Objects/dictobject.c (original) +++ python/branches/release26-maint/Objects/dictobject.c Thu Jan 1 16:46:10 2009 @@ -2331,7 +2331,7 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) { dictiterobject *di; - di = PyObject_New(dictiterobject, itertype); + di = PyObject_GC_New(dictiterobject, itertype); if (di == NULL) return NULL; Py_INCREF(dict); @@ -2348,6 +2348,7 @@ } else di->di_result = NULL; + _PyObject_GC_TRACK(di); return (PyObject *)di; } @@ -2356,7 +2357,15 @@ { Py_XDECREF(di->di_dict); Py_XDECREF(di->di_result); - PyObject_Del(di); + PyObject_GC_Del(di); +} + +static int +dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) +{ + Py_VISIT(di->di_dict); + Py_VISIT(di->di_result); + return 0; } static PyObject * @@ -2435,9 +2444,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2507,9 +2516,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2593,9 +2602,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/branches/release26-maint/Objects/fileobject.c ============================================================================== --- python/branches/release26-maint/Objects/fileobject.c (original) +++ python/branches/release26-maint/Objects/fileobject.c Thu Jan 1 16:46:10 2009 @@ -132,8 +132,8 @@ if (fstat(fileno(f->f_fp), &buf) == 0 && S_ISDIR(buf.st_mode)) { char *msg = strerror(EISDIR); - PyObject *exc = PyObject_CallFunction(PyExc_IOError, "(is)", - EISDIR, msg); + PyObject *exc = PyObject_CallFunction(PyExc_IOError, "(isO)", + EISDIR, msg, f->f_name); PyErr_SetObject(PyExc_IOError, exc); Py_XDECREF(exc); return NULL; Modified: python/branches/release26-maint/Objects/setobject.c ============================================================================== --- python/branches/release26-maint/Objects/setobject.c (original) +++ python/branches/release26-maint/Objects/setobject.c Thu Jan 1 16:46:10 2009 @@ -810,7 +810,14 @@ setiter_dealloc(setiterobject *si) { Py_XDECREF(si->si_set); - PyObject_Del(si); + PyObject_GC_Del(si); +} + +static int +setiter_traverse(setiterobject *si, visitproc visit, void *arg) +{ + Py_VISIT(si->si_set); + return 0; } static PyObject * @@ -888,9 +895,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)setiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -903,7 +910,7 @@ static PyObject * set_iter(PySetObject *so) { - setiterobject *si = PyObject_New(setiterobject, &PySetIter_Type); + setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type); if (si == NULL) return NULL; Py_INCREF(so); @@ -911,6 +918,7 @@ si->si_used = so->used; si->si_pos = 0; si->len = so->used; + _PyObject_GC_TRACK(si); return (PyObject *)si; } Modified: python/branches/release26-maint/Tools/pybench/Lists.py ============================================================================== --- python/branches/release26-maint/Tools/pybench/Lists.py (original) +++ python/branches/release26-maint/Tools/pybench/Lists.py Thu Jan 1 16:46:10 2009 @@ -293,3 +293,58 @@ for i in xrange(self.rounds): pass + +class SimpleListComprehensions(Test): + + version = 2.0 + operations = 6 + rounds = 20000 + + def test(self): + + n = range(10) * 10 + + for i in xrange(self.rounds): + l = [x for x in n] + l = [x for x in n if x] + l = [x for x in n if not x] + + l = [x for x in n] + l = [x for x in n if x] + l = [x for x in n if not x] + + def calibrate(self): + + n = range(10) * 10 + + for i in xrange(self.rounds): + pass + +class NestedListComprehensions(Test): + + version = 2.0 + operations = 6 + rounds = 20000 + + def test(self): + + m = range(10) + n = range(10) + + for i in xrange(self.rounds): + l = [x for x in n for y in m] + l = [y for x in n for y in m] + + l = [x for x in n for y in m if y] + l = [y for x in n for y in m if x] + + l = [x for x in n for y in m if not y] + l = [y for x in n for y in m if not x] + + def calibrate(self): + + m = range(10) + n = range(10) + + for i in xrange(self.rounds): + pass From python-checkins at python.org Thu Jan 1 16:49:47 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 16:49:47 +0100 (CET) Subject: [Python-checkins] r68136 - python/branches/py3k Message-ID: <20090101154947.668291E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 16:49:47 2009 New Revision: 68136 Log: Blocked revisions 67967,67980 via svnmerge ........ r67967 | benjamin.peterson | 2008-12-27 23:18:58 +0100 (Sat, 27 Dec 2008) | 1 line fix markup ........ r67980 | antoine.pitrou | 2008-12-28 15:24:29 +0100 (Sun, 28 Dec 2008) | 1 line wrong version number in doc changes committed in r67979 ........ Modified: python/branches/py3k/ (props changed) From python-checkins at python.org Thu Jan 1 16:53:14 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 16:53:14 +0100 (CET) Subject: [Python-checkins] r68137 - in python/branches/py3k: Lib/pydoc.py Misc/NEWS Message-ID: <20090101155314.6EB101E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 16:53:14 2009 New Revision: 68137 Log: Merged revisions 67953 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67953 | georg.brandl | 2008-12-27 19:20:04 +0100 (Sat, 27 Dec 2008) | 3 lines Patch #4739 by David Laban: add symbols to pydoc help topics, so that ``help('@')`` works as expected. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/pydoc.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/pydoc.py ============================================================================== --- python/branches/py3k/Lib/pydoc.py (original) +++ python/branches/py3k/Lib/pydoc.py Thu Jan 1 16:53:14 2009 @@ -1568,6 +1568,42 @@ 'with': ('with', 'CONTEXTMANAGERS EXCEPTIONS yield'), 'yield': ('yield', ''), } + # Either add symbols to this dictionary or to the symbols dictionary + # directly: Whichever is easier. They are merged later. + _symbols_inverse = { + 'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'), + 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', + '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), + 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'), + 'UNARY' : ('-', '~'), + 'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=', + '^=', '<<=', '>>=', '**=', '//='), + 'BITWISE' : ('<<', '>>', '&', '|', '^', '~'), + 'COMPLEX' : ('j', 'J') + } + symbols = { + '%': 'OPERATORS FORMATTING', + '**': 'POWER', + ',': 'TUPLES LISTS FUNCTIONS', + '.': 'ATTRIBUTES FLOAT MODULES OBJECTS', + '...': 'ELLIPSIS', + ':': 'SLICINGS DICTIONARYLITERALS', + '@': 'def class', + '\\': 'STRINGS', + '_': 'PRIVATENAMES', + '__': 'PRIVATENAMES SPECIALMETHODS', + '`': 'BACKQUOTES', + '(': 'TUPLES FUNCTIONS CALLS', + ')': 'TUPLES FUNCTIONS CALLS', + '[': 'LISTS SUBSCRIPTS SLICINGS', + ']': 'LISTS SUBSCRIPTS SLICINGS' + } + for topic, symbols_ in _symbols_inverse.items(): + for symbol in symbols_: + topics = symbols.get(symbol, topic) + if topic not in topics: + topics = topics + ' ' + topic + symbols[symbol] = topics topics = { 'TYPES': ('types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS ' @@ -1705,10 +1741,12 @@ if type(request) is type(''): if request == 'help': self.intro() elif request == 'keywords': self.listkeywords() + elif request == 'symbols': self.listsymbols() elif request == 'topics': self.listtopics() elif request == 'modules': self.listmodules() elif request[:8] == 'modules ': self.listmodules(request.split()[1]) + elif request in self.symbols: self.showsymbol(request) elif request in self.keywords: self.showtopic(request) elif request in self.topics: self.showtopic(request) elif request: doc(request, 'Help on %s:') @@ -1753,6 +1791,14 @@ ''') self.list(self.keywords.keys()) + def listsymbols(self): + self.output.write(''' +Here is a list of the punctuation symbols which Python assigns special meaning +to. Enter any symbol to get more help. + +''') + self.list(self.symbols.keys()) + def listtopics(self): self.output.write(''' Here is a list of available topics. Enter any topic name to get more help. @@ -1760,7 +1806,7 @@ ''') self.list(self.topics.keys()) - def showtopic(self, topic): + def showtopic(self, topic, more_xrefs=''): try: import pydoc_topics except ImportError: @@ -1774,7 +1820,7 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return if type(target) is type(''): - return self.showtopic(target) + return self.showtopic(target, more_xrefs) label, xrefs = target try: @@ -1783,6 +1829,8 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return pager(doc.strip() + '\n') + if more_xrefs: + xrefs = (xrefs or '') + ' ' + more_xrefs if xrefs: import io, formatter buffer = io.StringIO() @@ -1790,6 +1838,11 @@ 'Related help topics: ' + ', '.join(xrefs.split()) + '\n') self.output.write('\n%s\n' % buffer.getvalue()) + def showsymbol(self, symbol): + target = self.symbols[symbol] + topic, _, xrefs = target.partition(' ') + self.showtopic(topic, xrefs) + def listmodules(self, key=''): if key: self.output.write(''' Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Jan 1 16:53:14 2009 @@ -83,6 +83,9 @@ - Issue #4444: Allow assertRaises() to be used as a context handler, so that the code under test can be written inline if more practical. +- Issue #4739: Add pydoc help topics for symbols, so that e.g. help('@') + works as expected in the interactive environment. + - Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by Gabriel Genellina. From python-checkins at python.org Thu Jan 1 16:55:56 2009 From: python-checkins at python.org (georg.brandl) Date: Thu, 1 Jan 2009 16:55:56 +0100 (CET) Subject: [Python-checkins] r68138 - python/branches/py3k Message-ID: <20090101155556.D471C1E4002@bag.python.org> Author: georg.brandl Date: Thu Jan 1 16:55:56 2009 New Revision: 68138 Log: Blocked revisions 67955 via svnmerge ........ r67955 | georg.brandl | 2008-12-27 19:27:53 +0100 (Sat, 27 Dec 2008) | 3 lines Follow-up to r67746 in order to restore backwards-compatibility for those who (monkey-)patch TextWrapper.wordsep_re with a custom RE. ........ Modified: python/branches/py3k/ (props changed) From buildbot at python.org Thu Jan 1 16:58:39 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 15:58:39 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090101155840.19DD51E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/43 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 2 tests failed: test_posix test_subprocess ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' ====================================================================== FAIL: test_executable (test.test_subprocess.ProcessTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_subprocess.py", line 149, in test_executable self.assertEqual(p.returncode, 47) AssertionError: -6 != 47 sincerely, -The Buildbot From python-checkins at python.org Thu Jan 1 17:03:47 2009 From: python-checkins at python.org (hirokazu.yamamoto) Date: Thu, 1 Jan 2009 17:03:47 +0100 (CET) Subject: [Python-checkins] r68139 - in python/branches/py3k: Misc/NEWS Modules/_fileio.c Message-ID: <20090101160347.5446D1E4002@bag.python.org> Author: hirokazu.yamamoto Date: Thu Jan 1 17:03:45 2009 New Revision: 68139 Log: Merged revisions 68134 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68134 | hirokazu.yamamoto | 2009-01-02 00:45:39 +0900 | 2 lines Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_fileio.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Jan 1 17:03:45 2009 @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open + file with `str' filename on Windows. + - Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. Modified: python/branches/py3k/Modules/_fileio.c ============================================================================== --- python/branches/py3k/Modules/_fileio.c (original) +++ python/branches/py3k/Modules/_fileio.c Thu Jan 1 17:03:45 2009 @@ -284,10 +284,11 @@ Py_END_ALLOW_THREADS if (self->fd < 0) { #ifdef MS_WINDOWS - PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename); -#else - PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); + if (widename != NULL) + PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename); + else #endif + PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); goto error; } if(dircheck(self, name) < 0) From python-checkins at python.org Thu Jan 1 17:09:52 2009 From: python-checkins at python.org (hirokazu.yamamoto) Date: Thu, 1 Jan 2009 17:09:52 +0100 (CET) Subject: [Python-checkins] r68140 - python/branches/py3k/Misc/NEWS Message-ID: <20090101160952.F2D211E4002@bag.python.org> Author: hirokazu.yamamoto Date: Thu Jan 1 17:09:52 2009 New Revision: 68140 Log: News fix. On py3k, `str' is unicode. should use `bytes'. Modified: python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Jan 1 17:09:52 2009 @@ -13,7 +13,7 @@ ----------------- - Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open - file with `str' filename on Windows. + file with `bytes' filename on Windows. - Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. From buildbot at python.org Thu Jan 1 17:38:24 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 16:38:24 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.0 Message-ID: <20090101163824.E2FBE1E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.0/builds/18 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_posix ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.0.loewis-sun/build/@test.getcwd/@test.getcwd' sincerely, -The Buildbot From python-checkins at python.org Thu Jan 1 17:43:12 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 17:43:12 +0100 (CET) Subject: [Python-checkins] r68141 - python/trunk/Doc/library/itertools.rst Message-ID: <20090101164312.6A5E01E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 17:43:12 2009 New Revision: 68141 Log: fix highlighting Modified: python/trunk/Doc/library/itertools.rst Modified: python/trunk/Doc/library/itertools.rst ============================================================================== --- python/trunk/Doc/library/itertools.rst (original) +++ python/trunk/Doc/library/itertools.rst Thu Jan 1 17:43:12 2009 @@ -547,7 +547,7 @@ .. doctest:: - # Show a dictionary sorted and grouped by value + >>> # Show a dictionary sorted and grouped by value >>> from operator import itemgetter >>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3) >>> di = sorted(d.iteritems(), key=itemgetter(1)) @@ -558,9 +558,9 @@ 2 ['b', 'd', 'f'] 3 ['g'] - # Find runs of consecutive numbers using groupby. The key to the solution - # is differencing with a range so that consecutive numbers all appear in - # same group. + >>> # Find runs of consecutive numbers using groupby. The key to the solution + >>> # is differencing with a range so that consecutive numbers all appear in + >>> # same group. >>> data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28] >>> for k, g in groupby(enumerate(data), lambda (i,x):i-x): ... print map(itemgetter(1), g) From python-checkins at python.org Thu Jan 1 18:29:51 2009 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 1 Jan 2009 18:29:51 +0100 (CET) Subject: [Python-checkins] r68142 - in python/trunk: Doc/license.rst LICENSE Python/getcopyright.c README Message-ID: <20090101172951.863701E4002@bag.python.org> Author: benjamin.peterson Date: Thu Jan 1 18:29:49 2009 New Revision: 68142 Log: welcome to 2009, Python! Modified: python/trunk/Doc/license.rst python/trunk/LICENSE python/trunk/Python/getcopyright.c python/trunk/README Modified: python/trunk/Doc/license.rst ============================================================================== --- python/trunk/Doc/license.rst (original) +++ python/trunk/Doc/license.rst Thu Jan 1 18:29:49 2009 @@ -124,7 +124,7 @@ analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python |release| alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of - copyright, i.e., "Copyright ? 2001-2008 Python Software Foundation; All Rights + copyright, i.e., "Copyright ? 2001-2009 Python Software Foundation; All Rights Reserved" are retained in Python |release| alone or in any derivative version prepared by Licensee. Modified: python/trunk/LICENSE ============================================================================== --- python/trunk/LICENSE (original) +++ python/trunk/LICENSE Thu Jan 1 18:29:49 2009 @@ -88,15 +88,14 @@ otherwise using this software ("Python") in source or binary form and its associated documentation. -2. Subject to the terms and conditions of this License Agreement, PSF -hereby grants Licensee a nonexclusive, royalty-free, world-wide -license to reproduce, analyze, test, perform and/or display publicly, -prepare derivative works, distribute, and otherwise use Python -alone or in any derivative version, provided, however, that PSF's -License Agreement and PSF's notice of copyright, i.e., "Copyright (c) -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Python Software Foundation; -All Rights Reserved" are retained in Python alone or in any derivative -version prepared by Licensee. +2. Subject to the terms and conditions of this License Agreement, PSF hereby +grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, +analyze, test, perform and/or display publicly, prepare derivative works, +distribute, and otherwise use Python alone or in any derivative version, +provided, however, that PSF's License Agreement and PSF's notice of copyright, +i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Python +Software Foundation; All Rights Reserved" are retained in Python alone or in any +derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python or any part thereof, and wants to make Modified: python/trunk/Python/getcopyright.c ============================================================================== --- python/trunk/Python/getcopyright.c (original) +++ python/trunk/Python/getcopyright.c Thu Jan 1 18:29:49 2009 @@ -4,7 +4,7 @@ static char cprt[] = "\ -Copyright (c) 2001-2008 Python Software Foundation.\n\ +Copyright (c) 2001-2009 Python Software Foundation.\n\ All Rights Reserved.\n\ \n\ Copyright (c) 2000 BeOpen.com.\n\ Modified: python/trunk/README ============================================================================== --- python/trunk/README (original) +++ python/trunk/README Thu Jan 1 18:29:49 2009 @@ -1,7 +1,7 @@ This is Python version 2.7 alpha 0 ================================== -Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Python Software Foundation. All rights reserved. From buildbot at python.org Thu Jan 1 19:05:38 2009 From: buildbot at python.org (buildbot at python.org) Date: Thu, 01 Jan 2009 18:05:38 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090101180538.ABCD51E4036@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/45 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: georg.brandl,hirokazu.yamamoto BUILD FAILED: failed test Excerpt from the test logfile: 3 tests failed: test_distutils test_posix test_subprocess ====================================================================== FAIL: test_get_python_inc (distutils.tests.test_sysconfig.SysconfigTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/distutils/tests/test_sysconfig.py", line 43, in test_get_python_inc self.assert_(os.path.isdir(inc_dir), inc_dir) AssertionError: /home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/Include ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' ====================================================================== FAIL: test_executable (test.test_subprocess.ProcessTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_subprocess.py", line 149, in test_executable self.assertEqual(p.returncode, 47) AssertionError: -6 != 47 sincerely, -The Buildbot From mal at egenix.com Thu Jan 1 22:29:37 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 01 Jan 2009 22:29:37 +0100 Subject: [Python-checkins] r68092 - python/trunk/Lib/ssl.py In-Reply-To: <20081231040855.B409E1E4002@bag.python.org> References: <20081231040855.B409E1E4002@bag.python.org> Message-ID: <495D35C1.6060804@egenix.com> On 2008-12-31 05:08, benjamin.peterson wrote: > Author: benjamin.peterson > Date: Wed Dec 31 05:08:55 2008 > New Revision: 68092 > > Log: > fix name collision issues > > Modified: > python/trunk/Lib/ssl.py > > Modified: python/trunk/Lib/ssl.py > ============================================================================== > --- python/trunk/Lib/ssl.py (original) > +++ python/trunk/Lib/ssl.py Wed Dec 31 05:08:55 2008 > @@ -74,7 +74,7 @@ > SSL_ERROR_EOF, \ > SSL_ERROR_INVALID_ERROR_CODE > > -from socket import socket, _fileobject > +from socket import socket, _fileobject, error as socket_error > from socket import getnameinfo as _getnameinfo I'd suggest you remove all these direct imports and replace them with a single "import socket" and proper references to the module attribute where needed. It's probably also better to replace the variable name "socket" with something different. Otherwise, we'll end up reintroducing such naming collisions. > import base64 # for DER-to-PEM translation > > @@ -103,7 +103,7 @@ > # see if it's connected > try: > socket.getpeername(self) > - except socket.error: > + except socket_error: > # no, no connection yet > self._sslobj = None > else: > @@ -441,7 +441,7 @@ > PROTOCOL_SSLv23, None) > try: > sock.getpeername() > - except socket.error: > + except socket_error: > # no, no connection yet > pass > else: > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 01 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From python-checkins at python.org Fri Jan 2 00:05:36 2009 From: python-checkins at python.org (amaury.forgeotdarc) Date: Fri, 2 Jan 2009 00:05:36 +0100 (CET) Subject: [Python-checkins] r68143 - in python/branches/py3k: Misc/NEWS Modules/main.c Message-ID: <20090101230536.E5D921E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Jan 2 00:05:36 2009 New Revision: 68143 Log: #4747: on Windows, starting a module with a non-ascii filename would print a useless "SyntaxError: None" when the script contains a "# coding:" declaration. The Python API expects char* to be utf-8 encoded. wcstombs should be avoided here. Reviewed by Benjamin. Will backport to 3.0 Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/main.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Jan 2 00:05:36 2009 @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #4747: When the terminal does not use utf-8, executing a script with + non-ascii characters in its name could fail with a "SyntaxError: None" error. + - Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `bytes' filename on Windows. Modified: python/branches/py3k/Modules/main.c ============================================================================== --- python/branches/py3k/Modules/main.c (original) +++ python/branches/py3k/Modules/main.c Fri Jan 2 00:05:36 2009 @@ -600,18 +600,21 @@ } if (sts==-1) { - char cfilename[PATH_MAX]; + PyObject *filenameObj = NULL; char *p_cfilename = ""; if (filename) { - size_t r = wcstombs(cfilename, filename, PATH_MAX); - p_cfilename = cfilename; - if (r == (size_t)-1 || r >= PATH_MAX) + filenameObj = PyUnicode_FromWideChar( + filename, wcslen(filename)); + if (filenameObj != NULL) + p_cfilename = _PyUnicode_AsString(filenameObj); + else p_cfilename = ""; } sts = PyRun_AnyFileExFlags( fp, p_cfilename, filename != NULL, &cf) != 0; + Py_XDECREF(filenameObj); } } From python-checkins at python.org Fri Jan 2 00:07:21 2009 From: python-checkins at python.org (amaury.forgeotdarc) Date: Fri, 2 Jan 2009 00:07:21 +0100 (CET) Subject: [Python-checkins] r68144 - in python/branches/release30-maint: Misc/NEWS Modules/main.c Message-ID: <20090101230721.5F2F81E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Jan 2 00:07:21 2009 New Revision: 68144 Log: Merged revisions 68143 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ........ r68143 | amaury.forgeotdarc | 2009-01-02 00:05:36 +0100 (ven., 02 janv. 2009) | 7 lines #4747: on Windows, starting a module with a non-ascii filename would print a useless "SyntaxError: None" when the script contains a "# coding:" declaration. The Python API expects char* to be utf-8 encoded. wcstombs should be avoided here. Reviewed by Benjamin. Will backport to 3.0 ........ Modified: python/branches/release30-maint/ (props changed) python/branches/release30-maint/Misc/NEWS python/branches/release30-maint/Modules/main.c Modified: python/branches/release30-maint/Misc/NEWS ============================================================================== --- python/branches/release30-maint/Misc/NEWS (original) +++ python/branches/release30-maint/Misc/NEWS Fri Jan 2 00:07:21 2009 @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #4747: When the terminal does not use utf-8, executing a script with + non-ascii characters in its name could fail with a "SyntaxError: None" error. + - Issue #4701: PyObject_Hash now implicitly calls PyType_Ready on types where the tp_hash and tp_dict slots are both NULL. Modified: python/branches/release30-maint/Modules/main.c ============================================================================== --- python/branches/release30-maint/Modules/main.c (original) +++ python/branches/release30-maint/Modules/main.c Fri Jan 2 00:07:21 2009 @@ -600,18 +600,21 @@ } if (sts==-1) { - char cfilename[PATH_MAX]; + PyObject *filenameObj = NULL; char *p_cfilename = ""; if (filename) { - size_t r = wcstombs(cfilename, filename, PATH_MAX); - p_cfilename = cfilename; - if (r == (size_t)-1 || r >= PATH_MAX) + filenameObj = PyUnicode_FromWideChar( + filename, wcslen(filename)); + if (filenameObj != NULL) + p_cfilename = _PyUnicode_AsString(filenameObj); + else p_cfilename = ""; } sts = PyRun_AnyFileExFlags( fp, p_cfilename, filename != NULL, &cf) != 0; + Py_XDECREF(filenameObj); } } From benjamin at python.org Fri Jan 2 00:37:27 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 1 Jan 2009 17:37:27 -0600 Subject: [Python-checkins] r68092 - python/trunk/Lib/ssl.py In-Reply-To: <495D35C1.6060804@egenix.com> References: <20081231040855.B409E1E4002@bag.python.org> <495D35C1.6060804@egenix.com> Message-ID: <1afaf6160901011537u5f419ce4sf45322cb2cede8a6@mail.gmail.com> On Thu, Jan 1, 2009 at 3:29 PM, M.-A. Lemburg wrote: > > I'd suggest you remove all these direct imports and replace > them with a single "import socket" and proper references to > the module attribute where needed. > > It's probably also better to replace the variable name "socket" > with something different. Otherwise, we'll end up reintroducing > such naming collisions. That's a good idea. It's not my library, so I didn't want to be too invasive. You should probably write a tracker ticket and assign it to Bill. -- Regards, Benjamin Peterson From python-checkins at python.org Fri Jan 2 01:03:54 2009 From: python-checkins at python.org (amaury.forgeotdarc) Date: Fri, 2 Jan 2009 01:03:54 +0100 (CET) Subject: [Python-checkins] r68145 - python/trunk/Modules/_collectionsmodule.c Message-ID: <20090102000354.BCF451E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Jan 2 01:03:54 2009 New Revision: 68145 Log: #4801 _collections module fails to build on cygwin. _PyObject_GC_TRACK is the macro version of PyObject_GC_Track, and according to documentation it should not be used for extension modules. Modified: python/trunk/Modules/_collectionsmodule.c Modified: python/trunk/Modules/_collectionsmodule.c ============================================================================== --- python/trunk/Modules/_collectionsmodule.c (original) +++ python/trunk/Modules/_collectionsmodule.c Fri Jan 2 01:03:54 2009 @@ -967,7 +967,7 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; - _PyObject_GC_TRACK(it); + PyObject_GC_Track(it); return (PyObject *)it; } @@ -1077,7 +1077,7 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; - _PyObject_GC_TRACK(it); + PyObject_GC_Track(it); return (PyObject *)it; } From buildbot at python.org Fri Jan 2 08:01:29 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 07:01:29 +0000 Subject: [Python-checkins] buildbot failure in sparc Debian 3.x Message-ID: <20090102070129.A38A91E4002@bag.python.org> The Buildbot has detected a new failure of sparc Debian 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Debian%203.x/builds/29 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-sparc Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: amaury.forgeotdarc,hirokazu.yamamoto BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_cmd_line_script make: *** [buildbottest] Error 1 sincerely, -The Buildbot From nnorwitz at gmail.com Fri Jan 2 11:32:25 2009 From: nnorwitz at gmail.com (Neal Norwitz) Date: Fri, 2 Jan 2009 05:32:25 -0500 Subject: [Python-checkins] Python Regression Test Failures doc (1) Message-ID: <20090102103225.GA21546@python.psfb.org> svn update tools/sphinx At revision 68145. svn update tools/docutils At revision 68145. svn update tools/jinja At revision 68145. svn update tools/pygments At revision 68145. mkdir -p build/html build/doctrees python tools/sphinx-build.py -b html -d build/doctrees -D latex_paper_size= . build/html Sphinx v0.5, building html Exception occurred: File "/home/neal/python/trunk/Doc/tools/sphinx/jinja/loaders.py", line 20, in from jinja.utils import CacheDict, raise_syntax_error ImportError: cannot import name raise_syntax_error The full traceback has been saved in /tmp/sphinx-err-xG5zQy.log, if you want to report the issue to the author. Please also report this if it was a user error, so that a better error message can be provided next time. Send reports to sphinx-dev at googlegroups.com. Thanks! make: *** [build] Error 1 From python-checkins at python.org Fri Jan 2 11:44:46 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 11:44:46 +0100 (CET) Subject: [Python-checkins] r68146 - in python/trunk: Makefile.pre.in configure configure.in Message-ID: <20090102104446.8847D1E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 11:44:46 2009 New Revision: 68146 Log: Fix for issue4472: "configure --enable-shared doesn't work on OSX" Modified: python/trunk/Makefile.pre.in python/trunk/configure python/trunk/configure.in Modified: python/trunk/Makefile.pre.in ============================================================================== --- python/trunk/Makefile.pre.in (original) +++ python/trunk/Makefile.pre.in Fri Jan 2 11:44:46 2009 @@ -414,10 +414,14 @@ if test $(INSTSONAME) != $(LDLIBRARY); then \ $(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ $(LN) -f $(INSTSONAME) $@; \ - else\ + else \ $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ fi +libpython$(VERSION).dylib: $(LIBRARY_OBJS) + $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ + + libpython$(VERSION).sl: $(LIBRARY_OBJS) $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST) @@ -768,13 +772,13 @@ fi; \ done $(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE) - if test -f libpython$(VERSION)$(SO); then \ + if test -f $(LDLIBRARY); then \ if test "$(SO)" = .dll; then \ - $(INSTALL_SHARED) libpython$(VERSION)$(SO) $(DESTDIR)$(BINDIR); \ + $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(BINDIR); \ else \ - $(INSTALL_SHARED) libpython$(VERSION)$(SO) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ - if test libpython$(VERSION)$(SO) != $(INSTSONAME); then \ - (cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) libpython$(VERSION)$(SO)); \ + $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ + if test $(LDLIBRARY) != $(INSTSONAME); then \ + (cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \ fi \ fi; \ else true; \ Modified: python/trunk/configure ============================================================================== --- python/trunk/configure (original) +++ python/trunk/configure Fri Jan 2 11:44:46 2009 @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 67227 . +# From configure.in Revision: 67463 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for python 2.7. # @@ -4139,6 +4139,12 @@ BLDLIBRARY='-L. -lpython$(VERSION)' RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} ;; + Darwin*) + LDLIBRARY='libpython$(VERSION).dylib' + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}' + ;; + esac else # shared is disabled case $ac_sys_system in @@ -13003,6 +13009,7 @@ { echo "$as_me:$LINENO: result: $SO" >&5 echo "${ECHO_T}$SO" >&6; } + cat >>confdefs.h <<_ACEOF #define SHLIB_EXT "$SO" _ACEOF @@ -13403,7 +13410,7 @@ fi # Dynamic linking for HP-UX -# only check for sem_ini if thread support is requested +# only check for sem_init if thread support is requested if test "$with_threads" = "yes" -o -z "$with_threads"; then { echo "$as_me:$LINENO: checking for library containing sem_init" >&5 echo $ECHO_N "checking for library containing sem_init... $ECHO_C" >&6; } Modified: python/trunk/configure.in ============================================================================== --- python/trunk/configure.in (original) +++ python/trunk/configure.in Fri Jan 2 11:44:46 2009 @@ -737,6 +737,12 @@ BLDLIBRARY='-L. -lpython$(VERSION)' RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} ;; + Darwin*) + LDLIBRARY='libpython$(VERSION).dylib' + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}' + ;; + esac else # shared is disabled case $ac_sys_system in @@ -1597,6 +1603,7 @@ sleep 10 fi AC_MSG_RESULT($SO) + AC_DEFINE_UNQUOTED(SHLIB_EXT, "$SO", [Define this to be extension of shared libraries (including the dot!).]) # LDSHARED is the ld *command* used to create shared library # -- "cc -G" on SunOS 5.x, "ld -shared" on IRIX 5 From python-checkins at python.org Fri Jan 2 11:46:42 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 11:46:42 +0100 (CET) Subject: [Python-checkins] r68147 - in python/branches/release26-maint: Makefile.pre.in configure configure.in Message-ID: <20090102104642.86D371E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 11:46:42 2009 New Revision: 68147 Log: Backport of r68146 Modified: python/branches/release26-maint/Makefile.pre.in python/branches/release26-maint/configure python/branches/release26-maint/configure.in Modified: python/branches/release26-maint/Makefile.pre.in ============================================================================== --- python/branches/release26-maint/Makefile.pre.in (original) +++ python/branches/release26-maint/Makefile.pre.in Fri Jan 2 11:46:42 2009 @@ -414,10 +414,14 @@ if test $(INSTSONAME) != $(LDLIBRARY); then \ $(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ $(LN) -f $(INSTSONAME) $@; \ - else\ + else \ $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ fi +libpython$(VERSION).dylib: $(LIBRARY_OBJS) + $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ + + libpython$(VERSION).sl: $(LIBRARY_OBJS) $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST) @@ -768,13 +772,13 @@ fi; \ done $(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE) - if test -f libpython$(VERSION)$(SO); then \ + if test -f $(LDLIBRARY); then \ if test "$(SO)" = .dll; then \ - $(INSTALL_SHARED) libpython$(VERSION)$(SO) $(DESTDIR)$(BINDIR); \ + $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(BINDIR); \ else \ - $(INSTALL_SHARED) libpython$(VERSION)$(SO) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ - if test libpython$(VERSION)$(SO) != $(INSTSONAME); then \ - (cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) libpython$(VERSION)$(SO)); \ + $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ + if test $(LDLIBRARY) != $(INSTSONAME); then \ + (cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \ fi \ fi; \ else true; \ Modified: python/branches/release26-maint/configure ============================================================================== --- python/branches/release26-maint/configure (original) +++ python/branches/release26-maint/configure Fri Jan 2 11:46:42 2009 @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 67229 . +# From configure.in Revision: 67565 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for python 2.6. # @@ -4139,6 +4139,12 @@ BLDLIBRARY='-L. -lpython$(VERSION)' RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} ;; + Darwin*) + LDLIBRARY='libpython$(VERSION).dylib' + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}' + ;; + esac else # shared is disabled case $ac_sys_system in @@ -13003,6 +13009,7 @@ { echo "$as_me:$LINENO: result: $SO" >&5 echo "${ECHO_T}$SO" >&6; } + cat >>confdefs.h <<_ACEOF #define SHLIB_EXT "$SO" _ACEOF @@ -13403,7 +13410,7 @@ fi # Dynamic linking for HP-UX -# only check for sem_ini if thread support is requested +# only check for sem_init if thread support is requested if test "$with_threads" = "yes" -o -z "$with_threads"; then { echo "$as_me:$LINENO: checking for library containing sem_init" >&5 echo $ECHO_N "checking for library containing sem_init... $ECHO_C" >&6; } Modified: python/branches/release26-maint/configure.in ============================================================================== --- python/branches/release26-maint/configure.in (original) +++ python/branches/release26-maint/configure.in Fri Jan 2 11:46:42 2009 @@ -737,6 +737,12 @@ BLDLIBRARY='-L. -lpython$(VERSION)' RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} ;; + Darwin*) + LDLIBRARY='libpython$(VERSION).dylib' + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}' + ;; + esac else # shared is disabled case $ac_sys_system in @@ -1597,6 +1603,7 @@ sleep 10 fi AC_MSG_RESULT($SO) + AC_DEFINE_UNQUOTED(SHLIB_EXT, "$SO", [Define this to be extension of shared libraries (including the dot!).]) # LDSHARED is the ld *command* used to create shared library # -- "cc -G" on SunOS 5.x, "ld -shared" on IRIX 5 From python-checkins at python.org Fri Jan 2 11:48:31 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 11:48:31 +0100 (CET) Subject: [Python-checkins] r68148 - python/trunk/Misc/NEWS Message-ID: <20090102104831.5B7BB1E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 11:48:31 2009 New Revision: 68148 Log: Forgot to add a NEWS item in my previous checkin Modified: python/trunk/Misc/NEWS Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 11:48:31 2009 @@ -232,6 +232,8 @@ Build ----- +- Issue #4472: "configure --enable-shared" now works on OSX + - Issues #4728 and #4060: WORDS_BIGEDIAN is now correct in Universal builds. - Issue #4389: Add icon to the uninstall entry in "add-and-remove-programs". From python-checkins at python.org Fri Jan 2 11:50:48 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 11:50:48 +0100 (CET) Subject: [Python-checkins] r68149 - python/trunk/Makefile.pre.in Message-ID: <20090102105048.6DFD81E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 11:50:48 2009 New Revision: 68149 Log: Fix for issue4780 Modified: python/trunk/Makefile.pre.in Modified: python/trunk/Makefile.pre.in ============================================================================== --- python/trunk/Makefile.pre.in (original) +++ python/trunk/Makefile.pre.in Fri Jan 2 11:50:48 2009 @@ -909,7 +909,7 @@ export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \ export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \ export EXE; EXE="$(BUILDEXE)"; \ - cd $(srcdir)/Lib/$(PLATDIR); ./regen + cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen # Install the include files INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY) From python-checkins at python.org Fri Jan 2 12:46:05 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 12:46:05 +0100 (CET) Subject: [Python-checkins] r68150 - in python/trunk/Mac: IDLE/Makefile.in PythonLauncher/Makefile.in Message-ID: <20090102114605.A95101E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 12:46:05 2009 New Revision: 68150 Log: Fix for issue 3433 Modified: python/trunk/Mac/IDLE/Makefile.in python/trunk/Mac/PythonLauncher/Makefile.in Modified: python/trunk/Mac/IDLE/Makefile.in ============================================================================== --- python/trunk/Mac/IDLE/Makefile.in (original) +++ python/trunk/Mac/IDLE/Makefile.in Fri Jan 2 12:46:05 2009 @@ -29,10 +29,10 @@ install: IDLE.app $(srcdir)/config-main.def $(srcdir)/config-extensions.def test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp -PR IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -PR IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp $(srcdir)/config-main.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-main.def" - cp $(srcdir)/config-extensions.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-extensions.def" + /bin/cp $(srcdir)/config-main.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-main.def" + /bin/cp $(srcdir)/config-extensions.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-extensions.def" clean: rm -rf IDLE.app Modified: python/trunk/Mac/PythonLauncher/Makefile.in ============================================================================== --- python/trunk/Mac/PythonLauncher/Makefile.in (original) +++ python/trunk/Mac/PythonLauncher/Makefile.in Fri Jan 2 12:46:05 2009 @@ -29,7 +29,7 @@ install: Python\ Launcher.app test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" clean: From python-checkins at python.org Fri Jan 2 12:47:17 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 12:47:17 +0100 (CET) Subject: [Python-checkins] r68151 - in python/branches/release26-maint/Mac: IDLE/Makefile.in PythonLauncher/Makefile.in Message-ID: <20090102114717.4E7071E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 12:47:17 2009 New Revision: 68151 Log: Backport of r68150 Modified: python/branches/release26-maint/Mac/IDLE/Makefile.in python/branches/release26-maint/Mac/PythonLauncher/Makefile.in Modified: python/branches/release26-maint/Mac/IDLE/Makefile.in ============================================================================== --- python/branches/release26-maint/Mac/IDLE/Makefile.in (original) +++ python/branches/release26-maint/Mac/IDLE/Makefile.in Fri Jan 2 12:47:17 2009 @@ -29,10 +29,10 @@ install: IDLE.app $(srcdir)/config-main.def $(srcdir)/config-extensions.def test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp -PR IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -PR IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp $(srcdir)/config-main.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-main.def" - cp $(srcdir)/config-extensions.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-extensions.def" + /bin/cp $(srcdir)/config-main.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-main.def" + /bin/cp $(srcdir)/config-extensions.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-extensions.def" clean: rm -rf IDLE.app Modified: python/branches/release26-maint/Mac/PythonLauncher/Makefile.in ============================================================================== --- python/branches/release26-maint/Mac/PythonLauncher/Makefile.in (original) +++ python/branches/release26-maint/Mac/PythonLauncher/Makefile.in Fri Jan 2 12:47:17 2009 @@ -29,7 +29,7 @@ install: Python\ Launcher.app test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" clean: From python-checkins at python.org Fri Jan 2 12:48:29 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 12:48:29 +0100 (CET) Subject: [Python-checkins] r68152 - in python/branches/py3k/Mac: Makefile.in PythonLauncher/Makefile.in Message-ID: <20090102114829.467B41E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 12:48:29 2009 New Revision: 68152 Log: Fix for issue 3433 Modified: python/branches/py3k/Mac/Makefile.in python/branches/py3k/Mac/PythonLauncher/Makefile.in Modified: python/branches/py3k/Mac/Makefile.in ============================================================================== --- python/branches/py3k/Mac/Makefile.in (original) +++ python/branches/py3k/Mac/Makefile.in Fri Jan 2 12:48:29 2009 @@ -216,9 +216,9 @@ install_IDLE: test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" ln -sf $(INSTALLED_PYTHONAPP) "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/Python" - sed "s!%prefix%!$(prefix)!g" < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE" + sed -e "s!%prefix%!$(prefix)!g" -e 's!%exe%!$(PYTHONFRAMEWORK)!g' < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE" sed "s!%version%!`$(RUNSHARED) $(BUILDPYTHON) -c 'import platform; print(platform.python_version())'`!g" < "$(srcdir)/IDLE/IDLE.app/Contents/Info.plist" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/Info.plist" touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" Modified: python/branches/py3k/Mac/PythonLauncher/Makefile.in ============================================================================== --- python/branches/py3k/Mac/PythonLauncher/Makefile.in (original) +++ python/branches/py3k/Mac/PythonLauncher/Makefile.in Fri Jan 2 12:48:29 2009 @@ -27,7 +27,7 @@ install: Python\ Launcher.app test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" From buildbot at python.org Fri Jan 2 13:33:37 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 12:33:37 +0000 Subject: [Python-checkins] buildbot failure in x86 gentoo 2.6 Message-ID: <20090102123337.8DCC21E4002@bag.python.org> The Buildbot has detected a new failure of x86 gentoo 2.6. Full details are available at: http://www.python.org/dev/buildbot/all/x86%20gentoo%202.6/builds/21 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-x86 Build Reason: Build Source Stamp: [branch branches/release26-maint] HEAD Blamelist: ronald.oussoren BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_pickletools make: *** [buildbottest] Error 1 sincerely, -The Buildbot From buildbot at python.org Fri Jan 2 13:36:33 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 12:36:33 +0000 Subject: [Python-checkins] buildbot failure in x86 gentoo 3.x Message-ID: <20090102123633.6F1D21E4002@bag.python.org> The Buildbot has detected a new failure of x86 gentoo 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/x86%20gentoo%203.x/builds/49 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-x86 Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: ronald.oussoren BUILD FAILED: failed test Excerpt from the test logfile: make: *** [buildbottest] Unknown signal 32 sincerely, -The Buildbot From buildbot at python.org Fri Jan 2 13:43:07 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 12:43:07 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090102124307.BAF801E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/47 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: ronald.oussoren BUILD FAILED: failed test Excerpt from the test logfile: 3 tests failed: test_distutils test_posix test_subprocess ====================================================================== FAIL: test_get_python_inc (distutils.tests.test_sysconfig.SysconfigTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/distutils/tests/test_sysconfig.py", line 43, in test_get_python_inc self.assert_(os.path.isdir(inc_dir), inc_dir) AssertionError: /home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/Include ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' ====================================================================== FAIL: test_executable (test.test_subprocess.ProcessTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_subprocess.py", line 149, in test_executable self.assertEqual(p.returncode, 47) AssertionError: -6 != 47 sincerely, -The Buildbot From python-checkins at python.org Fri Jan 2 13:59:33 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 13:59:33 +0100 (CET) Subject: [Python-checkins] r68153 - in python/trunk/Lib/idlelib: NEWS.txt help.txt macosxSupport.py Message-ID: <20090102125933.4A47A1E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 13:59:32 2009 New Revision: 68153 Log: Fix for issue3559: No preferences menu in IDLE on OSX 1) Add a comment to the help file to that points to the preferences menu. 2) An earlier checkin tried to detect Tk >= 8.10.14, but did this in the wrong way. The end result of this was that the IDLE->Preferences... menu got surpressed when using the system version of Tcl/Tk Modified: python/trunk/Lib/idlelib/NEWS.txt python/trunk/Lib/idlelib/help.txt python/trunk/Lib/idlelib/macosxSupport.py Modified: python/trunk/Lib/idlelib/NEWS.txt ============================================================================== --- python/trunk/Lib/idlelib/NEWS.txt (original) +++ python/trunk/Lib/idlelib/NEWS.txt Fri Jan 2 13:59:32 2009 @@ -3,6 +3,8 @@ *Release date: XX-XXX-2008* +- Issue #3549: On MacOS the preferences menu was not present + - Issue #2665: On Windows, an IDLE installation upgraded from an old version would not start if a custom theme was defined. Modified: python/trunk/Lib/idlelib/help.txt ============================================================================== --- python/trunk/Lib/idlelib/help.txt (original) +++ python/trunk/Lib/idlelib/help.txt Fri Jan 2 13:59:32 2009 @@ -90,7 +90,10 @@ Configure IDLE -- Open a configuration dialog. Fonts, indentation, keybindings, and color themes may be altered. Startup Preferences may be set, and Additional Help - Souces can be specified. + Sources can be specified. + + On MacOS X this menu is not present, use + menu 'IDLE -> Preferences...' instead. --- Code Context -- Open a pane at the top of the edit window which shows the block context of the section of code Modified: python/trunk/Lib/idlelib/macosxSupport.py ============================================================================== --- python/trunk/Lib/idlelib/macosxSupport.py (original) +++ python/trunk/Lib/idlelib/macosxSupport.py Fri Jan 2 13:59:32 2009 @@ -89,7 +89,9 @@ ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding tkversion = root.tk.eval('info patchlevel') - if tkversion >= '8.4.14': + # Note: we cannot check if the string tkversion >= '8.4.14', because + # the string '8.4.7' is greater than the string '8.4.14'. + if map(int, tkversion.split('.')) >= (8, 4, 14): Bindings.menudefs[0] = ('application', [ ('About IDLE', '<>'), None, From python-checkins at python.org Fri Jan 2 14:00:10 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 14:00:10 +0100 (CET) Subject: [Python-checkins] r68154 - in python/branches/release26-maint/Lib/idlelib: help.txt macosxSupport.py Message-ID: <20090102130010.09D991E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 14:00:09 2009 New Revision: 68154 Log: Backport of r68153 Modified: python/branches/release26-maint/Lib/idlelib/help.txt python/branches/release26-maint/Lib/idlelib/macosxSupport.py Modified: python/branches/release26-maint/Lib/idlelib/help.txt ============================================================================== --- python/branches/release26-maint/Lib/idlelib/help.txt (original) +++ python/branches/release26-maint/Lib/idlelib/help.txt Fri Jan 2 14:00:09 2009 @@ -90,7 +90,10 @@ Configure IDLE -- Open a configuration dialog. Fonts, indentation, keybindings, and color themes may be altered. Startup Preferences may be set, and Additional Help - Souces can be specified. + Sources can be specified. + + On MacOS X this menu is not present, use + menu 'IDLE -> Preferences...' instead. --- Code Context -- Open a pane at the top of the edit window which shows the block context of the section of code Modified: python/branches/release26-maint/Lib/idlelib/macosxSupport.py ============================================================================== --- python/branches/release26-maint/Lib/idlelib/macosxSupport.py (original) +++ python/branches/release26-maint/Lib/idlelib/macosxSupport.py Fri Jan 2 14:00:09 2009 @@ -89,7 +89,9 @@ ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding tkversion = root.tk.eval('info patchlevel') - if tkversion >= '8.4.14': + # Note: we cannot check if the string tkversion >= '8.4.14', because + # the string '8.4.7' is greater than the string '8.4.14'. + if map(int, tkversion.split('.')) >= (8, 4, 14): Bindings.menudefs[0] = ('application', [ ('About IDLE', '<>'), None, From python-checkins at python.org Fri Jan 2 14:10:35 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 14:10:35 +0100 (CET) Subject: [Python-checkins] r68155 - in python/branches/py3k: Lib/idlelib/NEWS.txt Lib/idlelib/help.txt Lib/idlelib/macosxSupport.py Message-ID: <20090102131035.00A791E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 14:10:34 2009 New Revision: 68155 Log: Recorded merge of revisions 68153 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68153 | ronald.oussoren | 2009-01-02 13:59:32 +0100 (Fri, 02 Jan 2009) | 10 lines Fix for issue3559: No preferences menu in IDLE on OSX 1) Add a comment to the help file to that points to the preferences menu. 2) An earlier checkin tried to detect Tk >= 8.10.14, but did this in the wrong way. The end result of this was that the IDLE->Preferences... menu got surpressed when using the system version of Tcl/Tk ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/idlelib/NEWS.txt python/branches/py3k/Lib/idlelib/help.txt python/branches/py3k/Lib/idlelib/macosxSupport.py Modified: python/branches/py3k/Lib/idlelib/NEWS.txt ============================================================================== --- python/branches/py3k/Lib/idlelib/NEWS.txt (original) +++ python/branches/py3k/Lib/idlelib/NEWS.txt Fri Jan 2 14:10:34 2009 @@ -8,6 +8,11 @@ user configuration of source encoding; all according to PEP 3120. +- Issue #3549: On MacOS the preferences menu was not present + +- Issue #2665: On Windows, an IDLE installation upgraded from an old version + would not start if a custom theme was defined. + What's New in IDLE 3.0a3? ========================= Modified: python/branches/py3k/Lib/idlelib/help.txt ============================================================================== --- python/branches/py3k/Lib/idlelib/help.txt (original) +++ python/branches/py3k/Lib/idlelib/help.txt Fri Jan 2 14:10:34 2009 @@ -90,7 +90,10 @@ Configure IDLE -- Open a configuration dialog. Fonts, indentation, keybindings, and color themes may be altered. Startup Preferences may be set, and Additional Help - Souces can be specified. + Sources can be specified. + + On MacOS X this menu is not present, use + menu 'IDLE -> Preferences...' instead. --- Code Context -- Open a pane at the top of the edit window which shows the block context of the section of code Modified: python/branches/py3k/Lib/idlelib/macosxSupport.py ============================================================================== --- python/branches/py3k/Lib/idlelib/macosxSupport.py (original) +++ python/branches/py3k/Lib/idlelib/macosxSupport.py Fri Jan 2 14:10:34 2009 @@ -89,7 +89,9 @@ ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding tkversion = root.tk.eval('info patchlevel') - if tkversion >= '8.4.14': + # Note: we cannot check if the string tkversion >= '8.4.14', because + # the string '8.4.7' is greater than the string '8.4.14'. + if tuple(map(int, tkversion.split('.'))) >= (8, 4, 14): Bindings.menudefs[0] = ('application', [ ('About IDLE', '<>'), None, From python-checkins at python.org Fri Jan 2 15:10:20 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 15:10:20 +0100 (CET) Subject: [Python-checkins] r68156 - in python/trunk: Lib/test/test_macos.py Mac/Modules/MacOS.c Misc/NEWS Message-ID: <20090102141020.ACAAF1E4025@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 15:10:20 2009 New Revision: 68156 Log: Fix for issue1594 Modified: python/trunk/Lib/test/test_macos.py python/trunk/Mac/Modules/MacOS.c python/trunk/Misc/NEWS Modified: python/trunk/Lib/test/test_macos.py ============================================================================== --- python/trunk/Lib/test/test_macos.py (original) +++ python/trunk/Lib/test/test_macos.py Fri Jan 2 15:10:20 2009 @@ -3,11 +3,66 @@ import Carbon.File from test import test_support import os +import subprocess TESTFN2 = test_support.TESTFN + '2' class TestMacOS(unittest.TestCase): + def testGetCreatorAndType(self): + if not os.path.exists('/Developer/Tools/SetFile'): + return + + try: + fp = open(test_support.TESTFN, 'w') + fp.write('\n') + fp.close() + + subprocess.call( + ['/Developer/Tools/SetFile', '-t', 'ABCD', '-c', 'EFGH', + test_support.TESTFN]) + + cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN) + self.assertEquals(tp, 'ABCD') + self.assertEquals(cr, 'EFGH') + + finally: + os.unlink(test_support.TESTFN) + + def testSetCreatorAndType(self): + if not os.path.exists('/Developer/Tools/GetFileInfo'): + return + + try: + fp = open(test_support.TESTFN, 'w') + fp.write('\n') + fp.close() + + MacOS.SetCreatorAndType(test_support.TESTFN, + 'ABCD', 'EFGH') + + cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN) + self.assertEquals(cr, 'ABCD') + self.assertEquals(tp, 'EFGH') + + data = subprocess.Popen(["/Developer/Tools/GetFileInfo", test_support.TESTFN], + stdout=subprocess.PIPE).communicate()[0] + + tp = None + cr = None + for ln in data.splitlines(): + if ln.startswith('type:'): + tp = ln.split()[-1][1:-1] + if ln.startswith('creator:'): + cr = ln.split()[-1][1:-1] + + self.assertEquals(cr, 'ABCD') + self.assertEquals(tp, 'EFGH') + + finally: + os.unlink(test_support.TESTFN) + + def testOpenRF(self): try: fp = open(test_support.TESTFN, 'w') Modified: python/trunk/Mac/Modules/MacOS.c ============================================================================== --- python/trunk/Mac/Modules/MacOS.c (original) +++ python/trunk/Mac/Modules/MacOS.c Fri Jan 2 15:10:20 2009 @@ -30,6 +30,9 @@ #include #include +#include /* for ntohl, htonl */ + + #ifndef HAVE_OSX105_SDK typedef SInt16 FSIORefNum; #endif @@ -310,6 +313,10 @@ if ((err = FSpGetFInfo(&fss, &info)) != noErr) { return PyErr_Mac(MacOS_Error, err); } + + info.fdCreator = ntohl(info.fdCreator); + info.fdType = ntohl(info.fdType); + creator = PyString_FromStringAndSize( (char *)&info.fdCreator, 4); type = PyString_FromStringAndSize((char *)&info.fdType, 4); @@ -341,6 +348,8 @@ } finfo = (FileInfo*)&(cataloginfo.finderInfo); + finfo->fileCreator = ntohl(finfo->fileCreator); + finfo->fileType = ntohl(finfo->fileType); creator = PyString_FromStringAndSize((char*)&(finfo->fileCreator), 4); type = PyString_FromStringAndSize((char*)&(finfo->fileType), 4); Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 15:10:20 2009 @@ -224,6 +224,9 @@ - Issue #4730: Fixed the cPickle module to handle correctly astral characters when protocol 0 is used. +- Issue #1594: MacOS.GetCreatorAndType now always returns a big-endian result, + to be consistent with Apple tools. + Tools/Demos ----------- From python-checkins at python.org Fri Jan 2 15:30:43 2009 From: python-checkins at python.org (mark.dickinson) Date: Fri, 2 Jan 2009 15:30:43 +0100 (CET) Subject: [Python-checkins] r68157 - in python/branches/py3k-issue1717: Doc/Makefile Doc/README.txt Doc/c-api/arg.rst Doc/c-api/exceptions.rst Doc/distutils/apiref.rst Doc/distutils/setupscript.rst Doc/extending/extending.rst Doc/howto/functional.rst Doc/howto/unicode.rst Doc/includes/noddy.c Doc/includes/noddy2.c Doc/includes/noddy3.c Doc/includes/noddy4.c Doc/library/dis.rst Doc/library/email.mime.rst Doc/library/functions.rst Doc/library/hashlib.rst Doc/library/json.rst Doc/library/logging.rst Doc/library/math.rst Doc/library/multiprocessing.rst Doc/library/optparse.rst Doc/library/pydoc.rst Doc/library/shutil.rst Doc/library/signal.rst Doc/library/stdtypes.rst Doc/library/subprocess.rst Doc/library/unittest.rst Doc/library/webbrowser.rst Doc/library/winsound.rst Doc/library/xml.etree.elementtree.rst Doc/library/zipfile.rst Doc/license.rst Doc/tools/sphinx-web.py Doc/tools/sphinxext/download.html Doc/tools/sphinxext/pyspecific.py Doc/tutorial/controlflow.rst Doc/using/unix.rst Doc/whatsnew/2.6.rst Include/pymacconfig.h Include/unicodeobject.h LICENSE Lib/dis.py Lib/distutils/ccompiler.py Lib/distutils/command/register.py Lib/distutils/config.py Lib/distutils/dist.py Lib/distutils/msvc9compiler.py Lib/distutils/tests/test_config.py Lib/distutils/tests/test_dist.py Lib/distutils/tests/test_msvc9compiler.py Lib/distutils/tests/test_register.py Lib/distutils/util.py Lib/idlelib/IOBinding.py Lib/idlelib/NEWS.txt Lib/idlelib/configDialog.py Lib/io.py Lib/lib2to3/main.py Lib/pickle.py Lib/pydoc.py Lib/re.py Lib/ssl.py Lib/test/pickletester.py Lib/test/test_array.py Lib/test/test_bytes.py Lib/test/test_deque.py Lib/test/test_dict.py Lib/test/test_file.py Lib/test/test_fileio.py Lib/test/test_generators.py Lib/test/test_hash.py Lib/test/test_io.py Lib/test/test_set.py Lib/test/test_unittest.py Lib/test/test_urllib2.py Lib/test/test_zipfile.py Lib/tkinter/colorchooser.py Lib/tkinter/filedialog.py Lib/tkinter/scrolledtext.py Lib/unittest.py Lib/zipfile.py Mac/BuildScript/build-installer.py Mac/BuildScript/resources/Welcome.rtf Mac/IDLE/IDLE.app/Contents/Info.plist Mac/IDLE/IDLE.app/Contents/MacOS/IDLE Mac/Makefile.in Mac/PythonLauncher/Info.plist.in Mac/PythonLauncher/Makefile.in Mac/Tools/bundlebuilder.py Mac/Tools/fixapplepython23.py Makefile.pre.in Misc/NEWS Misc/developers.txt Modules/_collectionsmodule.c Modules/_fileio.c Modules/_pickle.c Modules/_testcapimodule.c Modules/main.c Modules/mathmodule.c Modules/posixmodule.c Objects/bytearrayobject.c Objects/bytesobject.c Objects/dictobject.c Objects/object.c Objects/setobject.c Objects/unicodeobject.c Python/compile.c Python/getargs.c Tools/pybench/Lists.py setup.py Message-ID: <20090102143043.80EC81E4024@bag.python.org> Author: mark.dickinson Date: Fri Jan 2 15:30:39 2009 New Revision: 68157 Log: Merged revisions 67881,67884,67886-67887,67903,67910,67925,67929,67931,67933,67937-67942,67945,67947-67950,67956,67959,67962,67964,67966,67968-67969,67972,67974,67981,67983,68008,68012,68015,68017,68020,68022,68027,68036,68058-68059,68062,68064,68074-68075,68083,68090-68091,68093-68094,68101,68103,68113,68129,68132,68136-68140,68143,68152 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r67881 | benjamin.peterson | 2008-12-20 22:50:25 +0000 (Sat, 20 Dec 2008) | 1 line unpy3kize this; it require 2.x only Mac modules ................ r67884 | benjamin.peterson | 2008-12-20 23:06:29 +0000 (Sat, 20 Dec 2008) | 1 line don't build bsddb anymore ................ r67886 | benjamin.peterson | 2008-12-21 00:06:59 +0000 (Sun, 21 Dec 2008) | 93 lines Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines #4457: rewrite __import__() documentation. ........ r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line specify how things are copied ........ r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line revert unrelated change to installer script ........ r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines Add simple unittests for Request ........ r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines #1030250: correctly pass the dry_run option to the mkpath() function. ........ r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line fix incorrect example ........ r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line fix missing bracket ........ r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines #4446: document "platforms" argument for setup(). ........ r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines #4611: fix typo. ........ r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines #4578: fix has_key() usage in compiler package. ........ r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines #4568: remove limitation in varargs callback example. ........ r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines #3632: the "pyo" macro from gdbinit can now run when the GIL is released. Patch by haypo. ........ r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line fix typo ........ r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line _call_method -> _callmethod and _get_value to _getvalue ........ r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines Fix-up and clean-up docs for int.bit_length(). * Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers. * Add comments to the pure python code equivalent. * replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float). * add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to. * make one combined example with a negative input. ........ r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line copy sentence from docstring ........ r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line add headings ........ r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line beef up docstring ........ r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line remove redundant sentence ........ r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line add some recent releases to the list ........ ................ r67887 | benjamin.peterson | 2008-12-21 00:16:13 +0000 (Sun, 21 Dec 2008) | 9 lines Merged revisions 67885 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67885 | benjamin.peterson | 2008-12-20 17:48:54 -0600 (Sat, 20 Dec 2008) | 1 line silence annoying DeprecationWarning ........ ................ r67903 | benjamin.peterson | 2008-12-22 20:19:52 +0000 (Mon, 22 Dec 2008) | 8 lines Blocked revisions 67902 via svnmerge ........ r67902 | benjamin.peterson | 2008-12-22 14:16:25 -0600 (Mon, 22 Dec 2008) | 1 line add py3k warnings to frame.f_exc_* ........ ................ r67910 | skip.montanaro | 2008-12-23 03:51:14 +0000 (Tue, 23 Dec 2008) | 11 lines Merged revisions 67908 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67908 | skip.montanaro | 2008-12-22 21:30:15 -0600 (Mon, 22 Dec 2008) | 4 lines As a result of a regression that snuck into 2.5.3 add a test case that ensures that when you try to read from a file opened for writing an IOError is raised. ........ ................ r67925 | benjamin.peterson | 2008-12-24 16:27:25 +0000 (Wed, 24 Dec 2008) | 1 line return the module object from PyMODINIT_FUNC ................ r67929 | benjamin.peterson | 2008-12-27 02:58:34 +0000 (Sat, 27 Dec 2008) | 1 line string -> bytes in error message #4745 ................ r67931 | hirokazu.yamamoto | 2008-12-27 04:21:44 +0000 (Sat, 27 Dec 2008) | 2 lines Issue #4740: Use HIGHEST_PROTOCOL in pickle test. This enables test for protocol 3 (== HIGHEST_PROTOCOL in 3.x) ................ r67933 | alexandre.vassalotti | 2008-12-27 06:43:58 +0000 (Sat, 27 Dec 2008) | 12 lines Merged revisions 67932 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67932 | alexandre.vassalotti | 2008-12-27 01:36:10 -0500 (Sat, 27 Dec 2008) | 5 lines Remove unnecessary casts related to unicode_decode_call_errorhandler. Make the _PyUnicode_Resize macro a static function. These changes are needed to avoid breaking strict aliasing rules. ........ ................ r67937 | alexandre.vassalotti | 2008-12-27 07:32:41 +0000 (Sat, 27 Dec 2008) | 3 lines Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle. Add astral character test case. ................ r67938 | alexandre.vassalotti | 2008-12-27 09:09:15 +0000 (Sat, 27 Dec 2008) | 3 lines Fix wrong bytes type conversion in PyUnicode_AsUnicodeEscapeString. Fix wrong bytes type conversion in PyUnicode_AsUnicodeDecodeString. ................ r67939 | alexandre.vassalotti | 2008-12-27 09:16:49 +0000 (Sat, 27 Dec 2008) | 6 lines Optimize built-in unicode codecs by avoiding unnecessary copying. The approach used is similiar to what is currently used in the version of unicodeobject.c in Python 2.x. The only difference is we use _PyBytes_Resize instead of _PyString_Resize. ................ r67940 | alexandre.vassalotti | 2008-12-27 09:30:39 +0000 (Sat, 27 Dec 2008) | 4 lines Fix issue #4374: Pickle tests fail w/o _pickle extension. Add an initialization check to mimic the interface of _pickle. ................ r67941 | alexandre.vassalotti | 2008-12-27 09:49:09 +0000 (Sat, 27 Dec 2008) | 2 lines Fix bogus assertion. ................ r67942 | alexandre.vassalotti | 2008-12-27 09:59:15 +0000 (Sat, 27 Dec 2008) | 14 lines Blocked revisions 67934-67935 via svnmerge ........ r67934 | alexandre.vassalotti | 2008-12-27 02:08:47 -0500 (Sat, 27 Dec 2008) | 4 lines Fix issue #4730: cPickle corrupts high-unicode strings. Update outdated copy of PyUnicode_EncodeRawUnicodeEscape. Add a test case. ........ r67935 | alexandre.vassalotti | 2008-12-27 02:13:01 -0500 (Sat, 27 Dec 2008) | 2 lines Add Misc/NEWS entry for r67934. ........ ................ r67945 | hirokazu.yamamoto | 2008-12-27 14:58:17 +0000 (Sat, 27 Dec 2008) | 1 line Fixed incompatible pointer warning. ................ r67947 | antoine.pitrou | 2008-12-27 15:50:40 +0000 (Sat, 27 Dec 2008) | 10 lines Merged revisions 67946 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67946 | antoine.pitrou | 2008-12-27 16:43:12 +0100 (sam., 27 d??c. 2008) | 4 lines Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by Gabriel Genellina. ........ ................ r67948 | benjamin.peterson | 2008-12-27 16:00:54 +0000 (Sat, 27 Dec 2008) | 93 lines Merged revisions 67889-67892,67895,67898,67904-67907,67912,67918,67920-67921,67923-67924,67926-67927,67930,67943 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r67889 | benjamin.peterson | 2008-12-20 19:04:32 -0600 (Sat, 20 Dec 2008) | 1 line sphinx.web is long gone ................ r67890 | benjamin.peterson | 2008-12-20 19:12:26 -0600 (Sat, 20 Dec 2008) | 1 line update readme ................ r67891 | benjamin.peterson | 2008-12-20 19:14:47 -0600 (Sat, 20 Dec 2008) | 1 line there are way too many places which need to have the current version added ................ r67892 | benjamin.peterson | 2008-12-20 19:29:32 -0600 (Sat, 20 Dec 2008) | 9 lines Merged revisions 67809 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67809 | benjamin.peterson | 2008-12-15 21:54:45 -0600 (Mon, 15 Dec 2008) | 1 line fix logic error ........ ................ r67895 | neal.norwitz | 2008-12-21 08:28:32 -0600 (Sun, 21 Dec 2008) | 2 lines Add Tarek for work on distutils. ................ r67898 | benjamin.peterson | 2008-12-21 15:00:53 -0600 (Sun, 21 Dec 2008) | 1 line compute DISTVERSION with patchlevel.py ................ r67904 | benjamin.peterson | 2008-12-22 14:44:58 -0600 (Mon, 22 Dec 2008) | 1 line less attitude ................ r67905 | benjamin.peterson | 2008-12-22 14:51:15 -0600 (Mon, 22 Dec 2008) | 1 line fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|' ................ r67906 | benjamin.peterson | 2008-12-22 14:52:53 -0600 (Mon, 22 Dec 2008) | 1 line add NEWS note ................ r67907 | benjamin.peterson | 2008-12-22 16:12:19 -0600 (Mon, 22 Dec 2008) | 1 line silence compiler warning ................ r67912 | georg.brandl | 2008-12-23 06:37:21 -0600 (Tue, 23 Dec 2008) | 2 lines Fix missing "svn" command. ................ r67918 | georg.brandl | 2008-12-23 09:44:25 -0600 (Tue, 23 Dec 2008) | 2 lines Markup fix. ................ r67920 | benjamin.peterson | 2008-12-23 14:09:28 -0600 (Tue, 23 Dec 2008) | 1 line use a global variable, so the compiler doesn't optimize the assignment out ................ r67921 | benjamin.peterson | 2008-12-23 14:12:33 -0600 (Tue, 23 Dec 2008) | 1 line make global static ................ r67923 | benjamin.peterson | 2008-12-24 09:10:27 -0600 (Wed, 24 Dec 2008) | 1 line #4736 BufferRWPair.closed shouldn't try to call another property as a function ................ r67924 | benjamin.peterson | 2008-12-24 10:10:05 -0600 (Wed, 24 Dec 2008) | 1 line pretend exceptions don't exist a while longer ................ r67926 | tarek.ziade | 2008-12-24 13:10:05 -0600 (Wed, 24 Dec 2008) | 1 line fixed #4400 : distutils .pypirc default generated file was broken. ................ r67927 | benjamin.peterson | 2008-12-26 17:26:30 -0600 (Fri, 26 Dec 2008) | 1 line python version is included in file name now ................ r67930 | hirokazu.yamamoto | 2008-12-26 22:19:48 -0600 (Fri, 26 Dec 2008) | 2 lines Issue #4740: Use HIGHEST_PROTOCOL in pickle test. (There is no behavior difference in 2.x because HIGHEST_PROTOCOL == 2) ................ r67943 | alexandre.vassalotti | 2008-12-27 04:02:59 -0600 (Sat, 27 Dec 2008) | 2 lines Fix bogus unicode tests in pickletester. ................ ................ r67949 | benjamin.peterson | 2008-12-27 16:58:50 +0000 (Sat, 27 Dec 2008) | 1 line fix syntax ................ r67950 | benjamin.peterson | 2008-12-27 17:00:44 +0000 (Sat, 27 Dec 2008) | 1 line fix 2.x isms in distutils test ................ r67956 | benjamin.peterson | 2008-12-27 18:35:25 +0000 (Sat, 27 Dec 2008) | 1 line fix svnmerge properties ................ r67959 | benjamin.peterson | 2008-12-27 19:03:36 +0000 (Sat, 27 Dec 2008) | 9 lines Merged revisions 67954 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67954 | benjamin.peterson | 2008-12-27 12:24:11 -0600 (Sat, 27 Dec 2008) | 1 line #4748 lambda generators shouldn't return values ........ ................ r67962 | georg.brandl | 2008-12-27 19:08:11 +0000 (Sat, 27 Dec 2008) | 2 lines #4697: clarify that the functions are Unix-only. ................ r67964 | alexandre.vassalotti | 2008-12-27 19:46:35 +0000 (Sat, 27 Dec 2008) | 2 lines Revert unwanted function name change introduced by r67939. ................ r67966 | antoine.pitrou | 2008-12-27 20:39:28 +0000 (Sat, 27 Dec 2008) | 9 lines Merged revisions 67965 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67965 | antoine.pitrou | 2008-12-27 21:34:52 +0100 (sam., 27 d??c. 2008) | 3 lines Issue #4677: add two list comprehension tests to pybench. ........ ................ r67968 | georg.brandl | 2008-12-27 23:12:09 +0000 (Sat, 27 Dec 2008) | 2 lines Remove confusing error message in bytes.translate. ................ r67969 | georg.brandl | 2008-12-27 23:33:20 +0000 (Sat, 27 Dec 2008) | 5 lines Document bytes.translate(). BTW, having str.maketrans() as a static method and string.maketrans() as a function that creates translation tables for bytes objects is not very consistent :) ................ r67972 | alexandre.vassalotti | 2008-12-28 02:13:22 +0000 (Sun, 28 Dec 2008) | 13 lines Merged revisions 67970-67971 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67970 | alexandre.vassalotti | 2008-12-27 20:52:58 -0500 (Sat, 27 Dec 2008) | 2 lines Fix name mangling of PyUnicode_ClearFreeList. ........ r67971 | alexandre.vassalotti | 2008-12-27 21:10:35 -0500 (Sat, 27 Dec 2008) | 2 lines Sort UCS-2/UCS-4 name mangling list. ........ ................ r67974 | georg.brandl | 2008-12-28 11:44:14 +0000 (Sun, 28 Dec 2008) | 4 lines #4759: allow None as first argument of bytearray.translate(), for consistency with bytes.translate(). Also fix segfault for bytearray.translate(x, None) -- will backport this part to 3.0 and 2.6. ................ r67981 | antoine.pitrou | 2008-12-28 14:29:00 +0000 (Sun, 28 Dec 2008) | 9 lines Merged revisions 67979 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67979 | antoine.pitrou | 2008-12-28 15:09:36 +0100 (dim., 28 d??c. 2008) | 3 lines Issue #4444: Allow assertRaises() to be used as a context handler. ........ ................ r67983 | benjamin.peterson | 2008-12-28 15:44:55 +0000 (Sun, 28 Dec 2008) | 12 lines Blocked revisions 67976 via svnmerge ........ r67976 | georg.brandl | 2008-12-28 05:54:53 -0600 (Sun, 28 Dec 2008) | 7 lines Backport r67974: #4759: allow None as first argument of bytearray.translate(), for consistency with bytes.translate(). Also fix segfault for bytearray.translate(x, None) -- will backport this part to 3.0 and 2.6. ........ ................ r68008 | martin.v.loewis | 2008-12-29 16:03:04 +0000 (Mon, 29 Dec 2008) | 9 lines Merged revisions 68006 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68006 | martin.v.loewis | 2008-12-29 16:51:01 +0100 (Mo, 29 Dez 2008) | 2 lines Issue #3248: Allow placing ScrolledText in a PanedWindow. ........ ................ r68012 | martin.v.loewis | 2008-12-29 16:27:13 +0000 (Mon, 29 Dec 2008) | 9 lines Merged revisions 68010 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68010 | martin.v.loewis | 2008-12-29 17:22:25 +0100 (Mo, 29 Dez 2008) | 2 lines Issue #3767: Convert Tk object to string in tkColorChooser. ........ ................ r68015 | benjamin.peterson | 2008-12-29 17:50:07 +0000 (Mon, 29 Dec 2008) | 8 lines Blocked revisions 68014 via svnmerge ........ r68014 | benjamin.peterson | 2008-12-29 11:47:42 -0600 (Mon, 29 Dec 2008) | 1 line #4764 set IOError.filename when trying to open a directory on POSIX platforms ........ ................ r68017 | benjamin.peterson | 2008-12-29 18:02:28 +0000 (Mon, 29 Dec 2008) | 9 lines Merged revisions 68016 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68016 | benjamin.peterson | 2008-12-29 11:56:58 -0600 (Mon, 29 Dec 2008) | 1 line #4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms ........ ................ r68020 | martin.v.loewis | 2008-12-29 18:21:47 +0000 (Mon, 29 Dec 2008) | 9 lines Merged revisions 68018 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68018 | martin.v.loewis | 2008-12-29 19:17:34 +0100 (Mo, 29 Dez 2008) | 2 lines Issue #1040026: Fix os.times result on systems where HZ is incorrect. ........ ................ r68022 | martin.v.loewis | 2008-12-29 18:43:40 +0000 (Mon, 29 Dec 2008) | 5 lines Issue #4323: Always encode source as UTF-8 without asking the user (unless a different encoding is declared); remove user configuration of source encoding; all according to PEP 3120. ................ r68027 | benjamin.peterson | 2008-12-29 20:52:09 +0000 (Mon, 29 Dec 2008) | 1 line hexdigest() doesn't return bytes #4771 ................ r68036 | tarek.ziade | 2008-12-29 22:38:38 +0000 (Mon, 29 Dec 2008) | 9 lines Merged revisions 68033 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68033 | tarek.ziade | 2008-12-29 23:23:53 +0100 (Mon, 29 Dec 2008) | 1 line fixed #4646 : distutils was choking on empty options arg in the setup function. ........ ................ r68058 | nick.coghlan | 2008-12-30 07:29:12 +0000 (Tue, 30 Dec 2008) | 9 lines Recorded merge of revisions 68051 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68051 | nick.coghlan | 2008-12-30 11:18:48 +1000 (Tue, 30 Dec 2008) | 1 line Issue #4701: implicitly call PyType_Ready from PyObject_Hash ........ ................ r68059 | vinay.sajip | 2008-12-30 07:32:59 +0000 (Tue, 30 Dec 2008) | 1 line Minor documentation change relating to NullHandler. ................ r68062 | ronald.oussoren | 2008-12-30 12:59:02 +0000 (Tue, 30 Dec 2008) | 12 lines Make it possible to install a framework build of Python 3.x on OSX. This the build machinery on OSX to re-enable building (and installing) PythonLauncher.app and IDLE.app. This needs ports of fixes to Lib/distutils/util.py and Include/pymacconfig.h to be fully functiontional, to be fully functional. I also have a patch for Makefile.pre.in that I'll post on bugs.python.org for review. ................ r68064 | ronald.oussoren | 2008-12-30 14:16:51 +0000 (Tue, 30 Dec 2008) | 11 lines Py3k: update OSX installer-generator This update makes sure that the installer won't write files in /usr/local/bin by default. The installer also won't replace /Library/Frameworks/Python.framework/Version/Current. Both to ensure that the installer doens't break an existing install of python 2.x. ................ r68074 | benjamin.peterson | 2008-12-30 17:56:45 +0000 (Tue, 30 Dec 2008) | 18 lines Merged revisions 67982,67988,67990 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67982 | benjamin.peterson | 2008-12-28 09:37:31 -0600 (Sun, 28 Dec 2008) | 1 line fix WORD_BIGEDIAN declaration in Universal builds; fixes #4060 and #4728 ........ r67988 | ronald.oussoren | 2008-12-28 13:40:56 -0600 (Sun, 28 Dec 2008) | 1 line Issue4064: architecture string for universal builds on OSX ........ r67990 | ronald.oussoren | 2008-12-28 13:50:40 -0600 (Sun, 28 Dec 2008) | 3 lines Update the fix for issue4064 to deal correctly with all three variants of universal builds that are presented by the configure script. ........ ................ r68075 | benjamin.peterson | 2008-12-30 18:05:46 +0000 (Tue, 30 Dec 2008) | 2 lines use $(RUNSHARED) to run plat-mac/regen ................ r68083 | tarek.ziade | 2008-12-30 23:09:20 +0000 (Tue, 30 Dec 2008) | 9 lines Merged revisions 68081 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68081 | tarek.ziade | 2008-12-31 00:03:41 +0100 (Wed, 31 Dec 2008) | 1 line Fixed #4702: Throwing DistutilsPlatformError instead of IOError under win32 if MSVC is not found ........ ................ r68090 | benjamin.peterson | 2008-12-31 03:41:35 +0000 (Wed, 31 Dec 2008) | 8 lines Blocked revisions 68089 via svnmerge ........ r68089 | benjamin.peterson | 2008-12-30 21:37:51 -0600 (Tue, 30 Dec 2008) | 1 line #4788 qualify some bare except clauses ........ ................ r68091 | benjamin.peterson | 2008-12-31 03:43:28 +0000 (Wed, 31 Dec 2008) | 1 line #4788 qualify remove a bare except ................ r68093 | benjamin.peterson | 2008-12-31 04:10:35 +0000 (Wed, 31 Dec 2008) | 1 line fix name usage ................ r68094 | benjamin.peterson | 2008-12-31 04:13:40 +0000 (Wed, 31 Dec 2008) | 8 lines Blocked revisions 68092 via svnmerge ........ r68092 | benjamin.peterson | 2008-12-30 22:08:55 -0600 (Tue, 30 Dec 2008) | 1 line fix name collision issues ........ ................ r68101 | hirokazu.yamamoto | 2008-12-31 06:05:46 +0000 (Wed, 31 Dec 2008) | 13 lines Merged revisions 68097,68099 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68097 | hirokazu.yamamoto | 2008-12-31 14:24:37 +0900 | 1 line Fixed compile error on windows. ........ r68099 | hirokazu.yamamoto | 2008-12-31 14:47:19 +0900 | 1 line Just inserted blank line. ........ ................ r68103 | benjamin.peterson | 2008-12-31 14:51:07 +0000 (Wed, 31 Dec 2008) | 1 line #4406 Directory has to inherit from commondialog.Dialog ................ r68113 | benjamin.peterson | 2009-01-01 00:23:30 +0000 (Thu, 01 Jan 2009) | 53 lines Merged revisions 67952,67957-67958,67960-67961,67963,67973,67978,67995,68030,68057,68061 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67952 | georg.brandl | 2008-12-27 11:42:40 -0600 (Sat, 27 Dec 2008) | 2 lines #4752: actually use custom handler in example. ........ r67957 | georg.brandl | 2008-12-27 12:49:19 -0600 (Sat, 27 Dec 2008) | 2 lines #4754: improve winsound documentation. ........ r67958 | georg.brandl | 2008-12-27 13:02:59 -0600 (Sat, 27 Dec 2008) | 2 lines #4682: 'b' is actually unsigned char. ........ r67960 | georg.brandl | 2008-12-27 13:04:44 -0600 (Sat, 27 Dec 2008) | 2 lines #4695: fix backslashery. ........ r67961 | georg.brandl | 2008-12-27 13:06:04 -0600 (Sat, 27 Dec 2008) | 2 lines Use :samp: role. ........ r67963 | georg.brandl | 2008-12-27 13:11:15 -0600 (Sat, 27 Dec 2008) | 2 lines #4671: document that pydoc imports modules. ........ r67973 | alexandre.vassalotti | 2008-12-27 20:58:22 -0600 (Sat, 27 Dec 2008) | 2 lines Document Py_VaBuildValue. ........ r67978 | georg.brandl | 2008-12-28 05:58:49 -0600 (Sun, 28 Dec 2008) | 2 lines #4731: clarify message about missing module prerequisites. ........ r67995 | benjamin.peterson | 2008-12-28 15:16:07 -0600 (Sun, 28 Dec 2008) | 1 line #4763 PyErr_ExceptionMatches won't blow up with NULL arguments ........ r68030 | benjamin.peterson | 2008-12-29 15:38:14 -0600 (Mon, 29 Dec 2008) | 1 line fix French ........ r68057 | vinay.sajip | 2008-12-30 01:01:25 -0600 (Tue, 30 Dec 2008) | 1 line Minor documentation change relating to NullHandler. ........ r68061 | georg.brandl | 2008-12-30 04:15:49 -0600 (Tue, 30 Dec 2008) | 2 lines #4778: attributes can't be called. ........ ................ r68129 | benjamin.peterson | 2009-01-01 15:05:06 +0000 (Thu, 01 Jan 2009) | 46 lines Merged revisions 68116-68119,68121,68123-68127 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68116 | georg.brandl | 2009-01-01 05:46:51 -0600 (Thu, 01 Jan 2009) | 2 lines #4100: note that element children are not necessarily present on "start" events. ........ r68117 | georg.brandl | 2009-01-01 05:53:55 -0600 (Thu, 01 Jan 2009) | 2 lines #4156: make clear that "protocol" is to be replaced with the protocol name. ........ r68118 | georg.brandl | 2009-01-01 06:00:19 -0600 (Thu, 01 Jan 2009) | 2 lines #4185: clarify escape behavior of replacement strings. ........ r68119 | georg.brandl | 2009-01-01 06:09:40 -0600 (Thu, 01 Jan 2009) | 3 lines #4222: document dis.findlabels() and dis.findlinestarts() and put them into dis.__all__. ........ r68121 | georg.brandl | 2009-01-01 06:43:33 -0600 (Thu, 01 Jan 2009) | 2 lines Point to types module in new module deprecation notice. ........ r68123 | georg.brandl | 2009-01-01 06:52:29 -0600 (Thu, 01 Jan 2009) | 2 lines #4784: ... on three counts ... ........ r68124 | georg.brandl | 2009-01-01 06:53:19 -0600 (Thu, 01 Jan 2009) | 2 lines #4782: Fix markup error that hid load() and loads(). ........ r68125 | georg.brandl | 2009-01-01 07:02:09 -0600 (Thu, 01 Jan 2009) | 2 lines #4776: add data_files and package_dir arguments. ........ r68126 | georg.brandl | 2009-01-01 07:05:13 -0600 (Thu, 01 Jan 2009) | 2 lines Handlers are in the `logging.handlers` module. ........ r68127 | georg.brandl | 2009-01-01 07:14:49 -0600 (Thu, 01 Jan 2009) | 2 lines #4767: Use correct submodules for all MIME classes. ........ ................ r68132 | antoine.pitrou | 2009-01-01 15:35:33 +0000 (Thu, 01 Jan 2009) | 9 lines Merged revisions 68128 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (jeu., 01 janv. 2009) | 3 lines Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected. ........ ................ r68136 | georg.brandl | 2009-01-01 15:49:47 +0000 (Thu, 01 Jan 2009) | 12 lines Blocked revisions 67967,67980 via svnmerge ........ r67967 | benjamin.peterson | 2008-12-27 23:18:58 +0100 (Sat, 27 Dec 2008) | 1 line fix markup ........ r67980 | antoine.pitrou | 2008-12-28 15:24:29 +0100 (Sun, 28 Dec 2008) | 1 line wrong version number in doc changes committed in r67979 ........ ................ r68137 | georg.brandl | 2009-01-01 15:53:14 +0000 (Thu, 01 Jan 2009) | 10 lines Merged revisions 67953 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67953 | georg.brandl | 2008-12-27 19:20:04 +0100 (Sat, 27 Dec 2008) | 3 lines Patch #4739 by David Laban: add symbols to pydoc help topics, so that ``help('@')`` works as expected. ........ ................ r68138 | georg.brandl | 2009-01-01 15:55:56 +0000 (Thu, 01 Jan 2009) | 9 lines Blocked revisions 67955 via svnmerge ........ r67955 | georg.brandl | 2008-12-27 19:27:53 +0100 (Sat, 27 Dec 2008) | 3 lines Follow-up to r67746 in order to restore backwards-compatibility for those who (monkey-)patch TextWrapper.wordsep_re with a custom RE. ........ ................ r68139 | hirokazu.yamamoto | 2009-01-01 16:03:45 +0000 (Thu, 01 Jan 2009) | 10 lines Merged revisions 68134 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68134 | hirokazu.yamamoto | 2009-01-02 00:45:39 +0900 | 2 lines Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. ........ ................ r68140 | hirokazu.yamamoto | 2009-01-01 16:09:52 +0000 (Thu, 01 Jan 2009) | 1 line News fix. On py3k, `str' is unicode. should use `bytes'. ................ r68143 | amaury.forgeotdarc | 2009-01-01 23:05:36 +0000 (Thu, 01 Jan 2009) | 7 lines #4747: on Windows, starting a module with a non-ascii filename would print a useless "SyntaxError: None" when the script contains a "# coding:" declaration. The Python API expects char* to be utf-8 encoded. wcstombs should be avoided here. Reviewed by Benjamin. Will backport to 3.0 ................ r68152 | ronald.oussoren | 2009-01-02 11:48:29 +0000 (Fri, 02 Jan 2009) | 2 lines Fix for issue 3433 ................ Added: python/branches/py3k-issue1717/Lib/distutils/tests/test_msvc9compiler.py - copied unchanged from r68152, /python/branches/py3k/Lib/distutils/tests/test_msvc9compiler.py python/branches/py3k-issue1717/Lib/distutils/tests/test_register.py - copied unchanged from r68152, /python/branches/py3k/Lib/distutils/tests/test_register.py python/branches/py3k-issue1717/Mac/Tools/bundlebuilder.py - copied unchanged from r68152, /python/branches/py3k/Mac/Tools/bundlebuilder.py Removed: python/branches/py3k-issue1717/Doc/tools/sphinx-web.py Modified: python/branches/py3k-issue1717/ (props changed) python/branches/py3k-issue1717/Doc/Makefile python/branches/py3k-issue1717/Doc/README.txt python/branches/py3k-issue1717/Doc/c-api/arg.rst python/branches/py3k-issue1717/Doc/c-api/exceptions.rst python/branches/py3k-issue1717/Doc/distutils/apiref.rst python/branches/py3k-issue1717/Doc/distutils/setupscript.rst python/branches/py3k-issue1717/Doc/extending/extending.rst python/branches/py3k-issue1717/Doc/howto/functional.rst python/branches/py3k-issue1717/Doc/howto/unicode.rst python/branches/py3k-issue1717/Doc/includes/noddy.c python/branches/py3k-issue1717/Doc/includes/noddy2.c python/branches/py3k-issue1717/Doc/includes/noddy3.c python/branches/py3k-issue1717/Doc/includes/noddy4.c python/branches/py3k-issue1717/Doc/library/dis.rst python/branches/py3k-issue1717/Doc/library/email.mime.rst python/branches/py3k-issue1717/Doc/library/functions.rst python/branches/py3k-issue1717/Doc/library/hashlib.rst python/branches/py3k-issue1717/Doc/library/json.rst python/branches/py3k-issue1717/Doc/library/logging.rst python/branches/py3k-issue1717/Doc/library/math.rst python/branches/py3k-issue1717/Doc/library/multiprocessing.rst python/branches/py3k-issue1717/Doc/library/optparse.rst python/branches/py3k-issue1717/Doc/library/pydoc.rst python/branches/py3k-issue1717/Doc/library/shutil.rst python/branches/py3k-issue1717/Doc/library/signal.rst python/branches/py3k-issue1717/Doc/library/stdtypes.rst python/branches/py3k-issue1717/Doc/library/subprocess.rst python/branches/py3k-issue1717/Doc/library/unittest.rst python/branches/py3k-issue1717/Doc/library/webbrowser.rst python/branches/py3k-issue1717/Doc/library/winsound.rst python/branches/py3k-issue1717/Doc/library/xml.etree.elementtree.rst python/branches/py3k-issue1717/Doc/library/zipfile.rst python/branches/py3k-issue1717/Doc/license.rst python/branches/py3k-issue1717/Doc/tools/sphinxext/download.html python/branches/py3k-issue1717/Doc/tools/sphinxext/pyspecific.py python/branches/py3k-issue1717/Doc/tutorial/controlflow.rst python/branches/py3k-issue1717/Doc/using/unix.rst python/branches/py3k-issue1717/Doc/whatsnew/2.6.rst python/branches/py3k-issue1717/Include/pymacconfig.h python/branches/py3k-issue1717/Include/unicodeobject.h python/branches/py3k-issue1717/LICENSE python/branches/py3k-issue1717/Lib/dis.py python/branches/py3k-issue1717/Lib/distutils/ccompiler.py python/branches/py3k-issue1717/Lib/distutils/command/register.py python/branches/py3k-issue1717/Lib/distutils/config.py python/branches/py3k-issue1717/Lib/distutils/dist.py python/branches/py3k-issue1717/Lib/distutils/msvc9compiler.py python/branches/py3k-issue1717/Lib/distutils/tests/test_config.py python/branches/py3k-issue1717/Lib/distutils/tests/test_dist.py python/branches/py3k-issue1717/Lib/distutils/util.py python/branches/py3k-issue1717/Lib/idlelib/IOBinding.py python/branches/py3k-issue1717/Lib/idlelib/NEWS.txt python/branches/py3k-issue1717/Lib/idlelib/configDialog.py python/branches/py3k-issue1717/Lib/io.py python/branches/py3k-issue1717/Lib/lib2to3/main.py python/branches/py3k-issue1717/Lib/pickle.py python/branches/py3k-issue1717/Lib/pydoc.py python/branches/py3k-issue1717/Lib/re.py python/branches/py3k-issue1717/Lib/ssl.py python/branches/py3k-issue1717/Lib/test/pickletester.py python/branches/py3k-issue1717/Lib/test/test_array.py python/branches/py3k-issue1717/Lib/test/test_bytes.py python/branches/py3k-issue1717/Lib/test/test_deque.py python/branches/py3k-issue1717/Lib/test/test_dict.py python/branches/py3k-issue1717/Lib/test/test_file.py python/branches/py3k-issue1717/Lib/test/test_fileio.py python/branches/py3k-issue1717/Lib/test/test_generators.py python/branches/py3k-issue1717/Lib/test/test_hash.py python/branches/py3k-issue1717/Lib/test/test_io.py python/branches/py3k-issue1717/Lib/test/test_set.py python/branches/py3k-issue1717/Lib/test/test_unittest.py python/branches/py3k-issue1717/Lib/test/test_urllib2.py python/branches/py3k-issue1717/Lib/test/test_zipfile.py python/branches/py3k-issue1717/Lib/tkinter/colorchooser.py python/branches/py3k-issue1717/Lib/tkinter/filedialog.py python/branches/py3k-issue1717/Lib/tkinter/scrolledtext.py python/branches/py3k-issue1717/Lib/unittest.py python/branches/py3k-issue1717/Lib/zipfile.py python/branches/py3k-issue1717/Mac/BuildScript/build-installer.py python/branches/py3k-issue1717/Mac/BuildScript/resources/Welcome.rtf python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/Info.plist python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE python/branches/py3k-issue1717/Mac/Makefile.in python/branches/py3k-issue1717/Mac/PythonLauncher/Info.plist.in python/branches/py3k-issue1717/Mac/PythonLauncher/Makefile.in python/branches/py3k-issue1717/Mac/Tools/fixapplepython23.py python/branches/py3k-issue1717/Makefile.pre.in python/branches/py3k-issue1717/Misc/NEWS python/branches/py3k-issue1717/Misc/developers.txt python/branches/py3k-issue1717/Modules/_collectionsmodule.c python/branches/py3k-issue1717/Modules/_fileio.c python/branches/py3k-issue1717/Modules/_pickle.c python/branches/py3k-issue1717/Modules/_testcapimodule.c python/branches/py3k-issue1717/Modules/main.c python/branches/py3k-issue1717/Modules/mathmodule.c python/branches/py3k-issue1717/Modules/posixmodule.c python/branches/py3k-issue1717/Objects/bytearrayobject.c python/branches/py3k-issue1717/Objects/bytesobject.c python/branches/py3k-issue1717/Objects/dictobject.c python/branches/py3k-issue1717/Objects/object.c python/branches/py3k-issue1717/Objects/setobject.c python/branches/py3k-issue1717/Objects/unicodeobject.c python/branches/py3k-issue1717/Python/compile.c python/branches/py3k-issue1717/Python/getargs.c python/branches/py3k-issue1717/Tools/pybench/Lists.py python/branches/py3k-issue1717/setup.py Modified: python/branches/py3k-issue1717/Doc/Makefile ============================================================================== --- python/branches/py3k-issue1717/Doc/Makefile (original) +++ python/branches/py3k-issue1717/Doc/Makefile Fri Jan 2 15:30:39 2009 @@ -9,7 +9,7 @@ SPHINXOPTS = PAPER = SOURCES = -DISTVERSION = +DISTVERSION = $(shell $(PYTHON) tools/sphinxext/patchlevel.py) ALLSPHINXOPTS = -b $(BUILDER) -d build/doctrees -D latex_paper_size=$(PAPER) \ $(SPHINXOPTS) . build/$(BUILDER) $(SOURCES) @@ -111,33 +111,33 @@ # archive the HTML make html - cp -pPR build/html dist/python$(DISTVERSION)-docs-html - tar -C dist -cf dist/python$(DISTVERSION)-docs-html.tar python$(DISTVERSION)-docs-html - bzip2 -9 -k dist/python$(DISTVERSION)-docs-html.tar - (cd dist; zip -q -r -9 python$(DISTVERSION)-docs-html.zip python$(DISTVERSION)-docs-html) - rm -r dist/python$(DISTVERSION)-docs-html - rm dist/python$(DISTVERSION)-docs-html.tar + cp -pPR build/html dist/python-$(DISTVERSION)-docs-html + tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html + bzip2 -9 -k dist/python-$(DISTVERSION)-docs-html.tar + (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-html.zip python-$(DISTVERSION)-docs-html) + rm -r dist/python-$(DISTVERSION)-docs-html + rm dist/python-$(DISTVERSION)-docs-html.tar # archive the text build make text - cp -pPR build/text dist/python$(DISTVERSION)-docs-text - tar -C dist -cf dist/python$(DISTVERSION)-docs-text.tar python$(DISTVERSION)-docs-text - bzip2 -9 -k dist/python$(DISTVERSION)-docs-text.tar - (cd dist; zip -q -r -9 python$(DISTVERSION)-docs-text.zip python$(DISTVERSION)-docs-text) - rm -r dist/python$(DISTVERSION)-docs-text - rm dist/python$(DISTVERSION)-docs-text.tar + cp -pPR build/text dist/python-$(DISTVERSION)-docs-text + tar -C dist -cf dist/python-$(DISTVERSION)-docs-text.tar python-$(DISTVERSION)-docs-text + bzip2 -9 -k dist/python-$(DISTVERSION)-docs-text.tar + (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-text.zip python-$(DISTVERSION)-docs-text) + rm -r dist/python-$(DISTVERSION)-docs-text + rm dist/python-$(DISTVERSION)-docs-text.tar # archive the A4 latex -rm -r build/latex make latex PAPER=a4 (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2) - cp build/latex/docs-pdf.zip dist/python$(DISTVERSION)-docs-pdf-a4.zip - cp build/latex/docs-pdf.tar.bz2 dist/python$(DISTVERSION)-docs-pdf-a4.tar.bz2 + cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-a4.zip + cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2 # archive the letter latex rm -r build/latex make latex PAPER=letter (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2) - cp build/latex/docs-pdf.zip dist/python$(DISTVERSION)-docs-pdf-letter.zip - cp build/latex/docs-pdf.tar.bz2 dist/python$(DISTVERSION)-docs-pdf-letter.tar.bz2 + cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip + cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2 Modified: python/branches/py3k-issue1717/Doc/README.txt ============================================================================== --- python/branches/py3k-issue1717/Doc/README.txt (original) +++ python/branches/py3k-issue1717/Doc/README.txt Fri Jan 2 15:30:39 2009 @@ -81,8 +81,7 @@ svn co http://svn.python.org/projects/doctools/trunk/sphinx tools/sphinx -Then, you need to install Docutils 0.4 (the SVN snapshot won't work), either -by checking it out via :: +Then, you need to install Docutils, either by checking it out via :: svn co http://svn.python.org/projects/external/docutils-0.4/docutils tools/docutils @@ -99,19 +98,18 @@ python tools/sphinx-build.py -b . build/ -where `` is one of html, web or htmlhelp (for explanations see the make -targets above). +where `` is one of html, text, latex, or htmlhelp (for explanations see +the make targets above). Contributing ============ -For bugs in the content, the online version at http://docs.python.org/ has a -"suggest change" facility that can be used to correct errors in the source text -and submit them as a patch to the maintainers. +Bugs in the content should be reported to the Python bug tracker at +http://bugs.python.org. -Bugs in the toolset should be reported in the Python bug tracker at -http://bugs.python.org/. +Bugs in the toolset should be reported in the Sphinx bug tracker at +http://www.bitbucket.org/birkenfeld/sphinx/issues/. You can also send a mail to the Python Documentation Team at docs at python.org, and we will process your request as soon as possible. Modified: python/branches/py3k-issue1717/Doc/c-api/arg.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/c-api/arg.rst (original) +++ python/branches/py3k-issue1717/Doc/c-api/arg.rst Fri Jan 2 15:30:39 2009 @@ -164,8 +164,9 @@ them. Instead, the implementation assumes that the string object uses the encoding passed in as parameter. -``b`` (integer) [char] - Convert a Python integer to a tiny int, stored in a C :ctype:`char`. +``b`` (integer) [unsigned char] + Convert a nonnegative Python integer to an unsigned tiny int, stored in a C + :ctype:`unsigned char`. ``B`` (integer) [unsigned char] Convert a Python integer to a tiny int without overflow checking, stored in a C @@ -305,8 +306,8 @@ ``;`` The list of format units ends here; the string after the semicolon is used as - the error message *instead* of the default error message. Clearly, ``:`` and - ``;`` mutually exclude each other. + the error message *instead* of the default error message. ``:`` and ``;`` + mutually exclude each other. Note that any Python object references which are provided to the caller are *borrowed* references; do not decrement their reference count! @@ -552,3 +553,8 @@ If there is an error in the format string, the :exc:`SystemError` exception is set and *NULL* returned. + +.. cfunction:: PyObject* Py_VaBuildValue(const char *format, va_list vargs) + + Identical to :cfunc:`Py_BuildValue`, except that it accepts a va_list + rather than a variable number of arguments. Modified: python/branches/py3k-issue1717/Doc/c-api/exceptions.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/c-api/exceptions.rst (original) +++ python/branches/py3k-issue1717/Doc/c-api/exceptions.rst Fri Jan 2 15:30:39 2009 @@ -67,11 +67,10 @@ .. cfunction:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc) - Return true if the *given* exception matches the exception in *exc*. If *exc* - is a class object, this also returns true when *given* is an instance of a - subclass. If *exc* is a tuple, all exceptions in the tuple (and recursively in - subtuples) are searched for a match. If *given* is *NULL*, a memory access - violation will occur. + Return true if the *given* exception matches the exception in *exc*. If + *exc* is a class object, this also returns true when *given* is an instance + of a subclass. If *exc* is a tuple, all exceptions in the tuple (and + recursively in subtuples) are searched for a match. .. cfunction:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb) Modified: python/branches/py3k-issue1717/Doc/distutils/apiref.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/distutils/apiref.rst (original) +++ python/branches/py3k-issue1717/Doc/distutils/apiref.rst Fri Jan 2 15:30:39 2009 @@ -88,9 +88,9 @@ | *options* | default options for the setup | a string | | | script | | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *license* | The license for the package | | + | *license* | The license for the package | a string | +--------------------+--------------------------------+-------------------------------------------------------------+ - | *keywords* | Descriptive meta-data. See | | + | *keywords* | Descriptive meta-data, see | | | | :pep:`314` | | +--------------------+--------------------------------+-------------------------------------------------------------+ | *platforms* | | | @@ -98,6 +98,13 @@ | *cmdclass* | A mapping of command names to | a dictionary | | | :class:`Command` subclasses | | +--------------------+--------------------------------+-------------------------------------------------------------+ + | *data_files* | A list of data files to | a list | + | | install | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + | *package_dir* | A mapping of package to | a dictionary | + | | directory names | | + +--------------------+--------------------------------+-------------------------------------------------------------+ + .. function:: run_setup(script_name[, script_args=None, stop_after='run']) @@ -1100,6 +1107,24 @@ For non-POSIX platforms, currently just returns ``sys.platform``. + For MacOS X systems the OS version reflects the minimal version on which + binaries will run (that is, the value of ``MACOSX_DEPLOYMENT_TARGET`` + during the build of Python), not the OS version of the current system. + + For universal binary builds on MacOS X the architecture value reflects + the univeral binary status instead of the architecture of the current + processor. For 32-bit universal binaries the architecture is ``fat``, + for 64-bit universal binaries the architecture is ``fat64``, and + for 4-way universal binaries the architecture is ``universal``. + + Examples of returned values on MacOS X: + + * ``macosx-10.3-ppc`` + + * ``macosx-10.3-fat`` + + * ``macosx-10.5-universal`` + .. % XXX isn't this also provided by some other non-distutils module? Modified: python/branches/py3k-issue1717/Doc/distutils/setupscript.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/distutils/setupscript.rst (original) +++ python/branches/py3k-issue1717/Doc/distutils/setupscript.rst Fri Jan 2 15:30:39 2009 @@ -561,6 +561,8 @@ +----------------------+---------------------------+-----------------+--------+ | ``classifiers`` | a list of classifiers | list of strings | \(4) | +----------------------+---------------------------+-----------------+--------+ +| ``platforms`` | a list of platforms | list of strings | | ++----------------------+---------------------------+-----------------+--------+ Notes: Modified: python/branches/py3k-issue1717/Doc/extending/extending.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/extending/extending.rst (original) +++ python/branches/py3k-issue1717/Doc/extending/extending.rst Fri Jan 2 15:30:39 2009 @@ -326,8 +326,8 @@ return PyModule_Create(&spammodule); } -Note that PyMODINIT_FUNC declares the function as ``void`` return type, -declares any special linkage declarations required by the platform, and for C++ +Note that PyMODINIT_FUNC declares the function as ``PyObject *`` return type, +declares any special linkage declarations required by the platform, and for C++ declares the function as ``extern "C"``. When the Python program imports module :mod:`spam` for the first time, @@ -882,7 +882,7 @@ The advantage of borrowing over owning a reference is that you don't need to take care of disposing of the reference on all possible paths through the code --- in other words, with a borrowed reference you don't run the risk of leaking -when a premature exit is taken. The disadvantage of borrowing over leaking is +when a premature exit is taken. The disadvantage of borrowing over owning is that there are some subtle situations where in seemingly correct code a borrowed reference can be used after the owner from which it was borrowed has in fact disposed of it. Modified: python/branches/py3k-issue1717/Doc/howto/functional.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/howto/functional.rst (original) +++ python/branches/py3k-issue1717/Doc/howto/functional.rst Fri Jan 2 15:30:39 2009 @@ -677,11 +677,10 @@ if line.strip() == '': print('Blank line at line #%i' % i) - -``sorted(iterable, [key=None], [reverse=False)`` collects all the -elements of the iterable into a list, sorts the list, and returns the sorted -result. The ``key`` and ``reverse`` arguments are passed through to -the constructed list's ``.sort()`` method. :: +``sorted(iterable, [key=None], [reverse=False])`` collects all the elements of +the iterable into a list, sorts the list, and returns the sorted result. The +``key``, and ``reverse`` arguments are passed through to the constructed list's +``.sort()`` method. :: >>> import random >>> # Generate 8 random numbers between [0, 10000) Modified: python/branches/py3k-issue1717/Doc/howto/unicode.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/howto/unicode.rst (original) +++ python/branches/py3k-issue1717/Doc/howto/unicode.rst Fri Jan 2 15:30:39 2009 @@ -32,7 +32,7 @@ looking at Apple ][ BASIC programs, published in French-language publications in the mid-1980s, that had lines like these:: - PRINT "FICHER EST COMPLETE." + PRINT "FICHIER EST COMPLETE." PRINT "CARACTERE NON ACCEPTE." Those messages should contain accents, and they just look wrong to someone who Modified: python/branches/py3k-issue1717/Doc/includes/noddy.c ============================================================================== --- python/branches/py3k-issue1717/Doc/includes/noddy.c (original) +++ python/branches/py3k-issue1717/Doc/includes/noddy.c Fri Jan 2 15:30:39 2009 @@ -52,4 +52,5 @@ Py_INCREF(&noddy_NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); + return m; } Modified: python/branches/py3k-issue1717/Doc/includes/noddy2.c ============================================================================== --- python/branches/py3k-issue1717/Doc/includes/noddy2.c (original) +++ python/branches/py3k-issue1717/Doc/includes/noddy2.c Fri Jan 2 15:30:39 2009 @@ -186,4 +186,5 @@ Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); + return m; } Modified: python/branches/py3k-issue1717/Doc/includes/noddy3.c ============================================================================== --- python/branches/py3k-issue1717/Doc/includes/noddy3.c (original) +++ python/branches/py3k-issue1717/Doc/includes/noddy3.c Fri Jan 2 15:30:39 2009 @@ -239,4 +239,5 @@ Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); + return m; } Modified: python/branches/py3k-issue1717/Doc/includes/noddy4.c ============================================================================== --- python/branches/py3k-issue1717/Doc/includes/noddy4.c (original) +++ python/branches/py3k-issue1717/Doc/includes/noddy4.c Fri Jan 2 15:30:39 2009 @@ -221,4 +221,5 @@ Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); + return m; } Modified: python/branches/py3k-issue1717/Doc/library/dis.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/dis.rst (original) +++ python/branches/py3k-issue1717/Doc/library/dis.rst Fri Jan 2 15:30:39 2009 @@ -64,10 +64,23 @@ .. function:: disco(code[, lasti]) - A synonym for disassemble. It is more convenient to type, and kept for - compatibility with earlier Python releases. + A synonym for :func:`disassemble`. It is more convenient to type, and kept + for compatibility with earlier Python releases. +.. function:: findlinestarts(code) + + This generator function uses the ``co_firstlineno`` and ``co_lnotab`` + attributes of the code object *code* to find the offsets which are starts of + lines in the source code. They are generated as ``(offset, lineno)`` pairs. + + +.. function:: findlabels(code) + + Detect all offsets in the code object *code* which are jump targets, and + return a list of these offsets. + + .. data:: opname Sequence of operation names, indexable using the bytecode. Modified: python/branches/py3k-issue1717/Doc/library/email.mime.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/email.mime.rst (original) +++ python/branches/py3k-issue1717/Doc/library/email.mime.rst Fri Jan 2 15:30:39 2009 @@ -19,6 +19,7 @@ Here are the classes: +.. currentmodule:: email.mime.base .. class:: MIMEBase(_maintype, _subtype, **_params) @@ -39,6 +40,8 @@ :mailheader:`MIME-Version` header (always set to ``1.0``). +.. currentmodule:: email.mime.nonmultipart + .. class:: MIMENonMultipart() Module: :mod:`email.mime.nonmultipart` @@ -50,6 +53,8 @@ :exc:`MultipartConversionError` exception is raised. +.. currentmodule:: email.mime.multipart + .. class:: MIMEMultipart([subtype[, boundary[, _subparts[, _params]]]]) Module: :mod:`email.mime.multipart` @@ -73,6 +78,8 @@ dictionary. +.. currentmodule:: email.mime.application + .. class:: MIMEApplication(_data[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.application` @@ -93,6 +100,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.audio + .. class:: MIMEAudio(_audiodata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.audio` @@ -116,6 +125,8 @@ *_params* are passed straight through to the base class constructor. +.. currentmodule:: email.mime.image + .. class:: MIMEImage(_imagedata[, _subtype[, _encoder[, **_params]]]) Module: :mod:`email.mime.image` @@ -139,6 +150,8 @@ *_params* are passed straight through to the :class:`MIMEBase` constructor. +.. currentmodule:: email.mime.message + .. class:: MIMEMessage(_msg[, _subtype]) Module: :mod:`email.mime.message` @@ -152,6 +165,8 @@ :mimetype:`rfc822`. +.. currentmodule:: email.mime.text + .. class:: MIMEText(_text[, _subtype[, _charset]]) Module: :mod:`email.mime.text` Modified: python/branches/py3k-issue1717/Doc/library/functions.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/functions.rst (original) +++ python/branches/py3k-issue1717/Doc/library/functions.rst Fri Jan 2 15:30:39 2009 @@ -1172,47 +1172,64 @@ This is an advanced function that is not needed in everyday Python programming. - The function is invoked by the :keyword:`import` statement. It mainly exists - so that you can replace it with another function that has a compatible - interface, in order to change the semantics of the :keyword:`import` - statement. See the built-in module :mod:`imp`, which defines some useful - operations out of which you can build your own :func:`__import__` function. - - For example, the statement ``import spam`` results in the following call: - ``__import__('spam', globals(), locals(), [], -1)``; the statement - ``from spam.ham import eggs`` results in ``__import__('spam.ham', globals(), - locals(), ['eggs'], -1)``. Note that even though ``locals()`` and ``['eggs']`` - are passed in as arguments, the :func:`__import__` function does not set the - local variable named ``eggs``; this is done by subsequent code that is generated - for the import statement. (In fact, the standard implementation does not use - its *locals* argument at all, and uses its *globals* only to determine the - package context of the :keyword:`import` statement.) + This function is invoked by the :keyword:`import` statement. It can be + replaced (by importing the :mod:`builtins` module and assigning to + ``builtins.__import__``) in order to change semantics of the + :keyword:`import` statement, but nowadays it is usually simpler to use import + hooks (see :pep:`302`). Direct use of :func:`__import__` is rare, except in + cases where you want to import a module whose name is only known at runtime. + + The function imports the module *name*, potentially using the given *globals* + and *locals* to determine how to interpret the name in a package context. + The *fromlist* gives the names of objects or submodules that should be + imported from the module given by *name*. The standard implementation does + not use its *locals* argument at all, and uses its *globals* only to + determine the package context of the :keyword:`import` statement. + + *level* specifies whether to use absolute or relative imports. The default + is ``-1`` which indicates both absolute and relative imports will be + attempted. ``0`` means only perform absolute imports. Positive values for + *level* indicate the number of parent directories to search relative to the + directory of the module calling :func:`__import__`. When the *name* variable is of the form ``package.module``, normally, the top-level package (the name up till the first dot) is returned, *not* the module named by *name*. However, when a non-empty *fromlist* argument is - given, the module named by *name* is returned. This is done for - compatibility with the :term:`bytecode` generated for the different kinds of import - statement; when using ``import spam.ham.eggs``, the top-level package - :mod:`spam` must be placed in the importing namespace, but when using ``from - spam.ham import eggs``, the ``spam.ham`` subpackage must be used to find the - ``eggs`` variable. As a workaround for this behavior, use :func:`getattr` to - extract the desired components. For example, you could define the following - helper:: - - def my_import(name): - mod = __import__(name) - components = name.split('.') - for comp in components[1:]: - mod = getattr(mod, comp) - return mod - - *level* specifies whether to use absolute or relative imports. The default is - ``-1`` which indicates both absolute and relative imports will be attempted. - ``0`` means only perform absolute imports. Positive values for *level* indicate - the number of parent directories to search relative to the directory of the - module calling :func:`__import__`. + given, the module named by *name* is returned. + For example, the statement ``import spam`` results in bytecode resembling the + following code:: + + spam = __import__('spam', globals(), locals(), [], -1) + + The statement ``import spam.ham`` results in this call:: + + spam = __import__('spam.ham', globals(), locals(), [], -1) + + Note how :func:`__import__` returns the toplevel module here because this is + the object that is bound to a name by the :keyword:`import` statement. + + On the other hand, the statement ``from spam.ham import eggs, sausage as + saus`` results in :: + + _temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], -1) + eggs = _temp.eggs + saus = _temp.sausage + + Here, the ``spam.ham`` module is returned from :func:`__import__`. From this + object, the names to import are retrieved and assigned to their respective + names. + + If you simply want to import a module (potentially within a package) by name, + you can get it from :data:`sys.modules`:: + + >>> import sys + >>> name = 'foo.bar.baz' + >>> __import__(name) + + >>> baz = sys.modules[name] + >>> baz + .. rubric:: Footnotes Modified: python/branches/py3k-issue1717/Doc/library/hashlib.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/hashlib.rst (original) +++ python/branches/py3k-issue1717/Doc/library/hashlib.rst Fri Jan 2 15:30:39 2009 @@ -64,7 +64,7 @@ More condensed: >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest() - b'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' + 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' A generic :func:`new` constructor that takes the string name of the desired algorithm as its first parameter also exists to allow access to the above listed @@ -76,7 +76,7 @@ >>> h = hashlib.new('ripemd160') >>> h.update(b"Nobody inspects the spammish repetition") >>> h.hexdigest() - b'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc' + 'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc' The following values are provided as constant attributes of the hash objects returned by the constructors: Modified: python/branches/py3k-issue1717/Doc/library/json.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/json.rst (original) +++ python/branches/py3k-issue1717/Doc/library/json.rst Fri Jan 2 15:30:39 2009 @@ -165,7 +165,7 @@ :func:`dump`. -.. function load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. @@ -201,7 +201,7 @@ class. -.. function loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) +.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]]) Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON document) to a Python object. Modified: python/branches/py3k-issue1717/Doc/library/logging.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/logging.rst (original) +++ python/branches/py3k-issue1717/Doc/library/logging.rst Fri Jan 2 15:30:39 2009 @@ -566,10 +566,10 @@ The :class:`NullHandler` class was not present in previous versions. -The :class:`StreamHandler` and :class:`FileHandler` classes are defined in the -core logging package. The other handlers are defined in a sub- module, -:mod:`logging.handlers`. (There is also another sub-module, -:mod:`logging.config`, for configuration functionality.) +The :class:`NullHandler`, :class:`StreamHandler` and :class:`FileHandler` +classes are defined in the core logging package. The other handlers are +defined in a sub- module, :mod:`logging.handlers`. (There is also another +sub-module, :mod:`logging.config`, for configuration functionality.) Logged messages are formatted for presentation through instances of the :class:`Formatter` class. They are initialized with a format string suitable for @@ -1534,6 +1534,8 @@ StreamHandler ^^^^^^^^^^^^^ +.. module:: logging.handlers + The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -2035,6 +2037,8 @@ Formatter Objects ----------------- +.. currentmodule:: logging + :class:`Formatter`\ s have the following attributes and methods. They are responsible for converting a :class:`LogRecord` to (usually) a string which can be interpreted by either a human or an external system. The base Modified: python/branches/py3k-issue1717/Doc/library/math.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/math.rst (original) +++ python/branches/py3k-issue1717/Doc/library/math.rst Fri Jan 2 15:30:39 2009 @@ -21,8 +21,9 @@ The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats. -Number-theoretic and representation functions: +Number-theoretic and representation functions +--------------------------------------------- .. function:: ceil(x) @@ -110,8 +111,8 @@ .. function:: modf(x) - Return the fractional and integer parts of *x*. Both results carry the sign of - *x*, and both are floats. + Return the fractional and integer parts of *x*. Both results carry the sign + of *x* and are floats. .. function:: trunc(x) @@ -131,7 +132,9 @@ platform C double type), in which case any float *x* with ``abs(x) >= 2**52`` necessarily has no fractional bits. -Power and logarithmic functions: + +Power and logarithmic functions +------------------------------- .. function:: exp(x) @@ -169,7 +172,8 @@ Return the square root of *x*. -Trigonometric functions: +Trigonometric functions +----------------------- .. function:: acos(x) @@ -217,7 +221,8 @@ Return the tangent of *x* radians. -Angular conversion: +Angular conversion +------------------ .. function:: degrees(x) @@ -229,7 +234,8 @@ Converts angle *x* from degrees to radians. -Hyperbolic functions: +Hyperbolic functions +-------------------- .. function:: acosh(x) @@ -262,9 +268,8 @@ Return the hyperbolic tangent of *x*. - -The module also defines two mathematical constants: - +Constants +========= .. data:: pi Modified: python/branches/py3k-issue1717/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k-issue1717/Doc/library/multiprocessing.rst Fri Jan 2 15:30:39 2009 @@ -356,7 +356,7 @@ .. attribute:: daemon - The process's daemon flag, a Boolean value. This must be called before + The process's daemon flag, a Boolean value. This must be set before :meth:`start` is called. The initial value is inherited from the creating process. @@ -1436,13 +1436,13 @@ Proxy objects are instances of subclasses of :class:`BaseProxy`. - .. method:: _call_method(methodname[, args[, kwds]]) + .. method:: _callmethod(methodname[, args[, kwds]]) Call and return the result of a method of the proxy's referent. If ``proxy`` is a proxy whose referent is ``obj`` then the expression :: - proxy._call_method(methodname, args, kwds) + proxy._callmethod(methodname, args, kwds) will evaluate the expression :: @@ -1455,26 +1455,26 @@ argument of :meth:`BaseManager.register`. If an exception is raised by the call, then then is re-raised by - :meth:`_call_method`. If some other exception is raised in the manager's + :meth:`_callmethod`. If some other exception is raised in the manager's process then this is converted into a :exc:`RemoteError` exception and is - raised by :meth:`_call_method`. + raised by :meth:`_callmethod`. Note in particular that an exception will be raised if *methodname* has not been *exposed* - An example of the usage of :meth:`_call_method`:: + An example of the usage of :meth:`_callmethod`:: >>> l = manager.list(range(10)) - >>> l._call_method('__len__') + >>> l._callmethod('__len__') 10 - >>> l._call_method('__getslice__', (2, 7)) # equiv to `l[2:7]` + >>> l._callmethod('__getslice__', (2, 7)) # equiv to `l[2:7]` [2, 3, 4, 5, 6] - >>> l._call_method('__getitem__', (20,)) # equiv to `l[20]` + >>> l._callmethod('__getitem__', (20,)) # equiv to `l[20]` Traceback (most recent call last): ... IndexError: list index out of range - .. method:: _get_value() + .. method:: _getvalue() Return a copy of the referent. @@ -1808,9 +1808,9 @@ filesystem. * An ``'AF_PIPE'`` address is a string of the form - ``r'\\\\.\\pipe\\PipeName'``. To use :func:`Client` to connect to a named + :samp:`r'\\\\.\\pipe\\{PipeName}'`. To use :func:`Client` to connect to a named pipe on a remote computer called ServerName* one should use an address of the - form ``r'\\\\ServerName\\pipe\\PipeName'`` instead. + form :samp:`r'\\\\{ServerName}\\pipe\\{PipeName}'`` instead. Note that any string beginning with two backslashes is assumed by default to be an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address. Modified: python/branches/py3k-issue1717/Doc/library/optparse.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/optparse.rst (original) +++ python/branches/py3k-issue1717/Doc/library/optparse.rst Fri Jan 2 15:30:39 2009 @@ -1625,36 +1625,33 @@ Nevertheless, here's a stab at a callback for an option with variable arguments:: - def vararg_callback(option, opt_str, value, parser): - assert value is None - done = 0 - value = [] - rargs = parser.rargs - while rargs: - arg = rargs[0] - - # Stop if we hit an arg like "--foo", "-a", "-fx", "--file=f", - # etc. Note that this also stops on "-3" or "-3.0", so if - # your option takes numeric values, you will need to handle - # this. - if ((arg[:2] == "--" and len(arg) > 2) or - (arg[:1] == "-" and len(arg) > 1 and arg[1] != "-")): - break - else: - value.append(arg) - del rargs[0] + def vararg_callback(option, opt_str, value, parser): + assert value is None + value = [] + + def floatable(str): + try: + float(str) + return True + except ValueError: + return False + + for arg in parser.rargs: + # stop on --foo like options + if arg[:2] == "--" and len(arg) > 2: + break + # stop on -a, but not on -3 or -3.0 + if arg[:1] == "-" and len(arg) > 1 and not floatable(arg): + break + value.append(arg) - setattr(parser.values, option.dest, value) + del parser.rargs[:len(value)] + setattr(parser.values, option.dest, value)) [...] parser.add_option("-c", "--callback", dest="vararg_attr", action="callback", callback=vararg_callback) -The main weakness with this particular implementation is that negative numbers -in the arguments following ``"-c"`` will be interpreted as further options -(probably causing an error), rather than as arguments to ``"-c"``. Fixing this -is left as an exercise for the reader. - .. _optparse-extending-optparse: Modified: python/branches/py3k-issue1717/Doc/library/pydoc.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/pydoc.rst (original) +++ python/branches/py3k-issue1717/Doc/library/pydoc.rst Fri Jan 2 15:30:39 2009 @@ -34,6 +34,13 @@ Unix), and refers to an existing Python source file, then documentation is produced for that file. +.. note:: + + In order to find objects and their documentation, :mod:`pydoc` imports the + module(s) to be documented. Therefore, any code on module level will be + executed on that occasion. Use an ``if __name__ == '__main__':`` guard to + only execute code when a file is invoked as a script and not just imported. + Specifying a :option:`-w` flag before the argument will cause HTML documentation to be written out to a file in the current directory, instead of displaying text on the console. Modified: python/branches/py3k-issue1717/Doc/library/shutil.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/shutil.rst (original) +++ python/branches/py3k-issue1717/Doc/library/shutil.rst Fri Jan 2 15:30:39 2009 @@ -139,7 +139,7 @@ Recursively move a file or directory to another location. If the destination is on the current filesystem, then simply use rename. - Otherwise, copy src to the dst and then remove src. + Otherwise, copy src (with :func:`copy2`) to the dst and then remove src. .. exception:: Error Modified: python/branches/py3k-issue1717/Doc/library/signal.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/signal.rst (original) +++ python/branches/py3k-issue1717/Doc/library/signal.rst Fri Jan 2 15:30:39 2009 @@ -52,10 +52,10 @@ .. data:: SIG_DFL - This is one of two standard signal handling options; it will simply perform the - default function for the signal. For example, on most systems the default - action for :const:`SIGQUIT` is to dump core and exit, while the default action - for :const:`SIGCLD` is to simply ignore it. + This is one of two standard signal handling options; it will simply perform + the default function for the signal. For example, on most systems the + default action for :const:`SIGQUIT` is to dump core and exit, while the + default action for :const:`SIGCHLD` is to simply ignore it. .. data:: SIG_IGN Modified: python/branches/py3k-issue1717/Doc/library/stdtypes.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/stdtypes.rst (original) +++ python/branches/py3k-issue1717/Doc/library/stdtypes.rst Fri Jan 2 15:30:39 2009 @@ -442,7 +442,7 @@ Equivalent to:: def bit_length(self): - s = bin(self) # binary representation: bin(-37) --> '-0b100101' + s = bin(x) # binary representation: bin(-37) --> '-0b100101' s = s.lstrip('-0b') # remove leading zeros and minus sign return len(s) # len('100101') --> 6 @@ -1116,13 +1116,12 @@ .. method:: str.translate(map) Return a copy of the *s* where all characters have been mapped through the - *map* which must be a dictionary of Unicode ordinals(integers) to Unicode + *map* which must be a dictionary of Unicode ordinals (integers) to Unicode ordinals, strings or ``None``. Unmapped characters are left untouched. Characters mapped to ``None`` are deleted. - You can use :meth:`str.maketrans` to create a translation table. For string - objects, set the *table* argument to ``None`` for translations that only - delete characters: + You can use :meth:`str.maketrans` to create a translation map from + character-to-character mappings in different formats. .. note:: @@ -1525,23 +1524,23 @@ >>> bytes.fromhex('f0 f1f2 ') b'\xf0\xf1\xf2' -.. XXX verify/document translate() semantics! - - .. method:: bytes.translate(table[, delete]) +The translate method differs in semantics from the version available on strings: + +.. method:: bytes.translate(table[, delete]) - Return a copy of the bytes object where all bytes occurring in the optional - argument *delete* are removed, and the remaining bytes have been mapped - through the given translation table, which must be a bytes object of length - 256. + Return a copy of the bytes or bytearray object where all bytes occurring in + the optional argument *delete* are removed, and the remaining bytes have been + mapped through the given translation table, which must be a bytes object of + length 256. - You can use the :func:`maketrans` helper function in the :mod:`string` module to - create a translation table. + You can use the :func:`string.maketrans` helper function to create a + translation table. - .. XXX a None table doesn't seem to be supported - Set the *table* argument to ``None`` for translations that only delete characters:: + Set the *table* argument to ``None`` for translations that only delete + characters:: - >>> 'read this short text'.translate(None, 'aeiou') - 'rd ths shrt txt' + >>> b'read this short text'.translate(None, b'aeiou') + b'rd ths shrt txt' .. _types-set: Modified: python/branches/py3k-issue1717/Doc/library/subprocess.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/subprocess.rst (original) +++ python/branches/py3k-issue1717/Doc/library/subprocess.rst Fri Jan 2 15:30:39 2009 @@ -197,6 +197,8 @@ >>> subprocess.getstatusoutput('/bin/junk') (256, 'sh: /bin/junk: not found') + Availability: UNIX. + .. function:: getoutput(cmd) Return output (stdout and stderr) of executing *cmd* in a shell. @@ -208,6 +210,8 @@ >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' + Availability: UNIX. + Exceptions ^^^^^^^^^^ Modified: python/branches/py3k-issue1717/Doc/library/unittest.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/unittest.rst (original) +++ python/branches/py3k-issue1717/Doc/library/unittest.rst Fri Jan 2 15:30:39 2009 @@ -610,8 +610,8 @@ equal, the test will fail with the explanation given by *msg*, or :const:`None`. -.. method:: TestCase.assertRaises(exception, callable, ...) - TestCase.failUnlessRaises(exception, callable, ...) +.. method:: TestCase.assertRaises(exception[, callable, ...]) + TestCase.failUnlessRaises(exception[, callable, ...]) Test that an exception is raised when *callable* is called with any positional or keyword arguments that are also passed to :meth:`assertRaises`. The test @@ -619,6 +619,11 @@ fails if no exception is raised. To catch any of a group of exceptions, a tuple containing the exception classes may be passed as *exception*. + If *callable* is omitted or None, returns a context manager so that the code + under test can be written inline rather than as a function:: + + with self.failUnlessRaises(some_error_class): + do_something() .. method:: TestCase.failIf(expr[, msg]) TestCase.assertFalse(expr[, msg]) Modified: python/branches/py3k-issue1717/Doc/library/webbrowser.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/webbrowser.rst (original) +++ python/branches/py3k-issue1717/Doc/library/webbrowser.rst Fri Jan 2 15:30:39 2009 @@ -167,7 +167,7 @@ Browser Controller Objects -------------------------- -Browser controllers provide two methods which parallel two of the module-level +Browser controllers provide these methods which parallel two of the module-level convenience functions: Modified: python/branches/py3k-issue1717/Doc/library/winsound.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/winsound.rst (original) +++ python/branches/py3k-issue1717/Doc/library/winsound.rst Fri Jan 2 15:30:39 2009 @@ -26,8 +26,9 @@ Call the underlying :cfunc:`PlaySound` function from the Platform API. The *sound* parameter may be a filename, audio data as a string, or ``None``. Its interpretation depends on the value of *flags*, which can be a bitwise ORed - combination of the constants described below. If the system indicates an error, - :exc:`RuntimeError` is raised. + combination of the constants described below. If the *sound* parameter is + ``None``, any currently playing waveform sound is stopped. If the system + indicates an error, :exc:`RuntimeError` is raised. .. function:: MessageBeep([type=MB_OK]) @@ -102,6 +103,10 @@ Stop playing all instances of the specified sound. + .. note:: + + This flag is not supported on modern Windows platforms. + .. data:: SND_ASYNC Modified: python/branches/py3k-issue1717/Doc/library/xml.etree.elementtree.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/xml.etree.elementtree.rst (original) +++ python/branches/py3k-issue1717/Doc/library/xml.etree.elementtree.rst Fri Jan 2 15:30:39 2009 @@ -94,6 +94,16 @@ *events* is a list of events to report back. If omitted, only "end" events are reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs. + .. note:: + + :func:`iterparse` only guarantees that it has seen the ">" + character of a starting tag when it emits a "start" event, so the + attributes are defined, but the contents of the text and tail attributes + are undefined at that point. The same applies to the element children; + they may or may not be present. + + If you need a fully populated element, look for "end" events instead. + .. function:: parse(source[, parser]) Modified: python/branches/py3k-issue1717/Doc/library/zipfile.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/library/zipfile.rst (original) +++ python/branches/py3k-issue1717/Doc/library/zipfile.rst Fri Jan 2 15:30:39 2009 @@ -64,9 +64,11 @@ .. function:: is_zipfile(filename) Returns ``True`` if *filename* is a valid ZIP file based on its magic number, - otherwise returns ``False``. This module does not currently handle ZIP files - which have appended comments. + otherwise returns ``False``. *filename* may be a file or file-like object too. + This module does not currently handle ZIP files which have appended comments. + .. versionchanged:: 2.7 + Support for file and file-like objects. .. data:: ZIP_STORED Modified: python/branches/py3k-issue1717/Doc/license.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/license.rst (original) +++ python/branches/py3k-issue1717/Doc/license.rst Fri Jan 2 15:30:39 2009 @@ -31,6 +31,7 @@ Source Definition). Historically, most, but not all, Python releases have also been GPL-compatible; the table below summarizes the various releases. +<<<<<<< .working +----------------+--------------+------------+------------+-----------------+ | Release | Derived from | Year | Owner | GPL compatible? | +================+==============+============+============+=================+ @@ -90,9 +91,12 @@ +----------------+--------------+------------+------------+-----------------+ | 2.6 | 2.5 | 2008 | PSF | yes | +----------------+--------------+------------+------------+-----------------+ +| 2.6.1 | 2.6 | 2008 | PSF | yes | ++----------------+--------------+------------+------------+-----------------+ | 3.0 | 2.6 | 2008 | PSF | yes | +----------------+--------------+------------+------------+-----------------+ + .. note:: GPL-compatible doesn't mean that we're distributing Python under the GPL. All Deleted: python/branches/py3k-issue1717/Doc/tools/sphinx-web.py ============================================================================== --- python/branches/py3k-issue1717/Doc/tools/sphinx-web.py Fri Jan 2 15:30:39 2009 +++ (empty file) @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -""" - Sphinx - Python documentation webserver - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :copyright: 2007 by Georg Brandl. - :license: Python license. -""" - -import sys - -if __name__ == '__main__': - from sphinx.web import main - sys.exit(main(sys.argv)) Modified: python/branches/py3k-issue1717/Doc/tools/sphinxext/download.html ============================================================================== --- python/branches/py3k-issue1717/Doc/tools/sphinxext/download.html (original) +++ python/branches/py3k-issue1717/Doc/tools/sphinxext/download.html Fri Jan 2 15:30:39 2009 @@ -19,20 +19,20 @@ - - + + - - + + - - + + - +
FormatPacked as .zipPacked as .tar.bz2
PDF (US-Letter paper size)Download (ca. 8 MB)Download (ca. 8 MB)Download (ca. 8 MB)Download (ca. 8 MB)
PDF (A4 paper size)Download (ca. 8 MB)Download (ca. 8 MB)Download (ca. 8 MB)Download (ca. 8 MB)
HTMLDownload (ca. 6 MB)Download (ca. 4 MB)Download (ca. 6 MB)Download (ca. 4 MB)
Plain Text Download (ca. 2 MB)Download (ca. 1.5 MB)Download (ca. 1.5 MB)
Modified: python/branches/py3k-issue1717/Doc/tools/sphinxext/pyspecific.py ============================================================================== --- python/branches/py3k-issue1717/Doc/tools/sphinxext/pyspecific.py (original) +++ python/branches/py3k-issue1717/Doc/tools/sphinxext/pyspecific.py Fri Jan 2 15:30:39 2009 @@ -45,7 +45,11 @@ from pprint import pformat from docutils.io import StringOutput from docutils.utils import new_document -from sphinx.builder import Builder + +try: + from sphinx.builders import Builder +except ImportError: + from sphinx.builder import Builder try: from sphinx.writers.text import TextWriter Modified: python/branches/py3k-issue1717/Doc/tutorial/controlflow.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/tutorial/controlflow.rst (original) +++ python/branches/py3k-issue1717/Doc/tutorial/controlflow.rst Fri Jan 2 15:30:39 2009 @@ -200,42 +200,20 @@ ... pass # Busy-wait for keyboard interrupt (Ctrl+C) ... -This is commonly used for creating minimal classes such as exceptions, or -for ignoring unwanted exceptions:: +This is commonly used for creating minimal classes:: - >>> class ParserError(Exception): + >>> class MyEmptyClass: ... pass - ... - >>> try: - ... import audioop - ... except ImportError: - ... pass - ... + ... Another place :keyword:`pass` can be used is as a place-holder for a function or -conditional body when you are working on new code, allowing you to keep -thinking at a more abstract level. However, as :keyword:`pass` is silently -ignored, a better choice may be to raise a :exc:`NotImplementedError` -exception:: +conditional body when you are working on new code, allowing you to keep thinking +at a more abstract level. The :keyword:`pass` is silently ignored:: >>> def initlog(*args): - ... raise NotImplementedError # Open logfile if not already open - ... if not logfp: - ... raise NotImplementedError # Set up dummy log back-end - ... raise NotImplementedError('Call log initialization handler') + ... pass # Remember to implement this! ... -If :keyword:`pass` were used here and you later ran tests, they may fail -without indicating why. Using :exc:`NotImplementedError` causes this code -to raise an exception, telling you exactly where the incomplete code -is. Note the two calling styles of the exceptions above. -The first style, with no message but with an accompanying comment, -lets you easily leave the comment when you remove the exception, -which ideally would be a good description for -the block of code the exception is a placeholder for. However, the -third example, providing a message for the exception, will produce -a more useful traceback. - .. _tut-functions: Defining Functions Modified: python/branches/py3k-issue1717/Doc/using/unix.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/using/unix.rst (original) +++ python/branches/py3k-issue1717/Doc/using/unix.rst Fri Jan 2 15:30:39 2009 @@ -140,8 +140,8 @@ Vim and Emacs are excellent editors which support Python very well. For more information on how to code in python in these editors, look at: -http://www.vim.org/scripts/script.php?script_id=790 -http://sourceforge.net/projects/python-mode +* http://www.vim.org/scripts/script.php?script_id=790 +* http://sourceforge.net/projects/python-mode Geany is an excellent IDE with support for a lot of languages. For more information, read: http://geany.uvena.de/ Modified: python/branches/py3k-issue1717/Doc/whatsnew/2.6.rst ============================================================================== --- python/branches/py3k-issue1717/Doc/whatsnew/2.6.rst (original) +++ python/branches/py3k-issue1717/Doc/whatsnew/2.6.rst Fri Jan 2 15:30:39 2009 @@ -738,7 +738,7 @@ Curly brackets can be escaped by doubling them:: - >>> format("Empty dict: {{}}") + >>> "Empty dict: {{}}".format() "Empty dict: {}" Field names can be integers indicating positional arguments, such as Modified: python/branches/py3k-issue1717/Include/pymacconfig.h ============================================================================== --- python/branches/py3k-issue1717/Include/pymacconfig.h (original) +++ python/branches/py3k-issue1717/Include/pymacconfig.h Fri Jan 2 15:30:39 2009 @@ -15,6 +15,8 @@ # undef SIZEOF_SIZE_T # undef SIZEOF_TIME_T # undef SIZEOF_VOID_P +# undef SIZEOF__BOOL +# undef WORDS_BIGENDIAN # undef VA_LIST_IS_ARRAY # if defined(__LP64__) && defined(__x86_64__) @@ -28,12 +30,19 @@ # undef SIZEOF_LONG # ifdef __LP64__ +# define SIZEOF__BOOL 1 +# define SIZEOF__BOOL 1 # define SIZEOF_LONG 8 # define SIZEOF_PTHREAD_T 8 # define SIZEOF_SIZE_T 8 # define SIZEOF_TIME_T 8 # define SIZEOF_VOID_P 8 # else +# ifdef __ppc__ +# define SIZEOF__BOOL 4 +# else +# define SIZEOF__BOOL 1 +# endif # define SIZEOF_LONG 4 # define SIZEOF_PTHREAD_T 4 # define SIZEOF_SIZE_T 4 @@ -54,6 +63,11 @@ # endif +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#endif /* __BIG_ENDIAN */ + + #endif /* defined(_APPLE__) */ #endif /* PYMACCONFIG_H */ Modified: python/branches/py3k-issue1717/Include/unicodeobject.h ============================================================================== --- python/branches/py3k-issue1717/Include/unicodeobject.h (original) +++ python/branches/py3k-issue1717/Include/unicodeobject.h Fri Jan 2 15:30:39 2009 @@ -152,6 +152,7 @@ # define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString # define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar +# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist # define PyUnicode_Compare PyUnicodeUCS2_Compare # define PyUnicode_Concat PyUnicodeUCS2_Concat # define PyUnicode_Append PyUnicodeUCS2_Append @@ -185,13 +186,13 @@ # define PyUnicode_Find PyUnicodeUCS2_Find # define PyUnicode_Format PyUnicodeUCS2_Format # define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject +# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat +# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV # define PyUnicode_FromObject PyUnicodeUCS2_FromObject # define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal -# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode # define PyUnicode_FromString PyUnicodeUCS2_FromString # define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize -# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV -# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat +# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode # define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar # define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding # define PyUnicode_GetMax PyUnicodeUCS2_GetMax @@ -213,7 +214,6 @@ # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString # define _PyUnicode_Fini _PyUnicodeUCS2_Fini # define _PyUnicode_Init _PyUnicodeUCS2_Init -# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist # define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit # define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit @@ -250,6 +250,7 @@ # define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString # define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar +# define PyUnicode_ClearFreeList PyUnicodeUCS4_ClearFreelist # define PyUnicode_Compare PyUnicodeUCS4_Compare # define PyUnicode_Concat PyUnicodeUCS4_Concat # define PyUnicode_Append PyUnicodeUCS4_Append @@ -283,13 +284,13 @@ # define PyUnicode_Find PyUnicodeUCS4_Find # define PyUnicode_Format PyUnicodeUCS4_Format # define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject +# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat +# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV # define PyUnicode_FromObject PyUnicodeUCS4_FromObject # define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal -# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode # define PyUnicode_FromString PyUnicodeUCS4_FromString # define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize -# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV -# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat +# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode # define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar # define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding # define PyUnicode_GetMax PyUnicodeUCS4_GetMax @@ -311,7 +312,6 @@ # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString # define _PyUnicode_Fini _PyUnicodeUCS4_Fini # define _PyUnicode_Init _PyUnicodeUCS4_Init -# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist # define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit # define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit Modified: python/branches/py3k-issue1717/LICENSE ============================================================================== --- python/branches/py3k-issue1717/LICENSE (original) +++ python/branches/py3k-issue1717/LICENSE Fri Jan 2 15:30:39 2009 @@ -55,7 +55,10 @@ 2.4.4 2.4.3 2006 PSF yes 2.5 2.4 2006 PSF yes 2.5.1 2.5 2007 PSF yes + 2.5.2 2.5.1 2008 PSF yes + 2.5.3 2.5.2 2008 PSF yes 2.6 2.5 2008 PSF yes + 2.6.1 2.6 2008 PSF yes 3.0 2.6 2008 PSF yes Footnotes: Modified: python/branches/py3k-issue1717/Lib/dis.py ============================================================================== --- python/branches/py3k-issue1717/Lib/dis.py (original) +++ python/branches/py3k-issue1717/Lib/dis.py Fri Jan 2 15:30:39 2009 @@ -6,7 +6,8 @@ from opcode import * from opcode import __all__ as _opcodes_all -__all__ = ["dis","disassemble","distb","disco"] + _opcodes_all +__all__ = ["dis", "disassemble", "distb", "disco", + "findlinestarts", "findlabels"] + _opcodes_all del _opcodes_all def dis(x=None): Modified: python/branches/py3k-issue1717/Lib/distutils/ccompiler.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/ccompiler.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/ccompiler.py Fri Jan 2 15:30:39 2009 @@ -984,8 +984,8 @@ def move_file(self, src, dst): return move_file(src, dst, dry_run=self.dry_run) - def mkpath(self, name, mode=0o777): - mkpath(name, mode, self.dry_run) + def mkpath (self, name, mode=0o777): + mkpath(name, mode, dry_run=self.dry_run) # Map a sys.platform/os.name ('posix', 'nt') to the default compiler Modified: python/branches/py3k-issue1717/Lib/distutils/command/register.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/command/register.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/command/register.py Fri Jan 2 15:30:39 2009 @@ -143,12 +143,13 @@ # get the user's login info choices = '1 2 3 4'.split() while choice not in choices: - print('''We need to know who you are, so please choose either: + self.announce('''\ +We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and email it to you), or 4. quit -Your selection [default 1]: ''', end=' ') +Your selection [default 1]: ''', log.INFO) choice = input() if not choice: choice = '1' @@ -169,12 +170,16 @@ # send the info to the server and report the result code, result = self.post_to_server(self.build_post_data('submit'), auth) - print('Server response (%s): %s'%(code, result)) + self.announce('Server response (%s): %s' % (code, result), + log.INFO) # possibly save the login if not self.has_config and code == 200: - print('I can store your PyPI login so future submissions will be faster.') - print('(the login will be stored in %s)' % self._get_rc_file()) + self.announce(('I can store your PyPI login so future ' + 'submissions will be faster.'), log.INFO) + self.announce('(the login will be stored in %s)' % \ + self._get_rc_file(), log.INFO) + choice = 'X' while choice.lower() not in 'yn': choice = input('Save your login (y/N)?') Modified: python/branches/py3k-issue1717/Lib/distutils/config.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/config.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/config.py Fri Jan 2 15:30:39 2009 @@ -10,8 +10,8 @@ from distutils.cmd import Command DEFAULT_PYPIRC = """\ -[pypirc] -servers = +[distutils] +index-servers = pypi [pypi] Modified: python/branches/py3k-issue1717/Lib/distutils/dist.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/dist.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/dist.py Fri Jan 2 15:30:39 2009 @@ -228,7 +228,7 @@ # command options will override any supplied redundantly # through the general options dictionary. options = attrs.get('options') - if options: + if options is not None: del attrs['options'] for (command, cmd_options) in options.items(): opt_dict = self.get_option_dict(command) Modified: python/branches/py3k-issue1717/Lib/distutils/msvc9compiler.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/msvc9compiler.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/msvc9compiler.py Fri Jan 2 15:30:39 2009 @@ -247,7 +247,7 @@ result = {} if vcvarsall is None: - raise IOError("Unable to find vcvarsall.bat") + raise DistutilsPlatformError("Unable to find vcvarsall.bat") log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version) popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch), stdout=subprocess.PIPE, @@ -255,7 +255,7 @@ stdout, stderr = popen.communicate() if popen.wait() != 0: - raise IOError(stderr.decode("mbcs")) + raise DistutilsPlatformError(stderr.decode("mbcs")) stdout = stdout.decode("mbcs") for line in stdout.split("\n"): Modified: python/branches/py3k-issue1717/Lib/distutils/tests/test_config.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/tests/test_config.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/tests/test_config.py Fri Jan 2 15:30:39 2009 @@ -5,6 +5,8 @@ from distutils.core import PyPIRCCommand from distutils.core import Distribution +from distutils.log import set_threshold +from distutils.log import WARN from distutils.tests import support @@ -32,6 +34,17 @@ password:secret """ +WANTED = """\ +[distutils] +index-servers = + pypi + +[pypi] +username:tarek +password:xxx +""" + + class PyPIRCCommandTestCase(support.TempdirManager, unittest.TestCase): def setUp(self): @@ -53,6 +66,7 @@ finalize_options = initialize_options self._cmd = command + self.old_threshold = set_threshold(WARN) def tearDown(self): """Removes the patch.""" @@ -62,6 +76,7 @@ os.environ['HOME'] = self._old_home if os.path.exists(self.rc): os.remove(self.rc) + set_threshold(self.old_threshold) def test_server_registration(self): # This test makes sure PyPIRCCommand knows how to: @@ -96,6 +111,20 @@ ('server', 'server-login'), ('username', 'tarek')] self.assertEquals(config, waited) + def test_server_empty_registration(self): + + cmd = self._cmd(self.dist) + rc = cmd._get_rc_file() + self.assert_(not os.path.exists(rc)) + + cmd._store_pypirc('tarek', 'xxx') + + self.assert_(os.path.exists(rc)) + content = open(rc).read() + + self.assertEquals(content, WANTED) + + def test_suite(): return unittest.makeSuite(PyPIRCCommandTestCase) Modified: python/branches/py3k-issue1717/Lib/distutils/tests/test_dist.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/tests/test_dist.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/tests/test_dist.py Fri Jan 2 15:30:39 2009 @@ -6,6 +6,7 @@ import io import sys import unittest +import warnings from test.support import TESTFN @@ -96,6 +97,29 @@ os.unlink(TESTFN) + def test_empty_options(self): + # an empty options dictionary should not stay in the + # list of attributes + klass = distutils.dist.Distribution + + # catching warnings + warns = [] + def _warn(msg): + warns.append(msg) + + old_warn = warnings.warn + warnings.warn = _warn + try: + dist = klass(attrs={'author': 'xxx', + 'name': 'xxx', + 'version': 'xxx', + 'url': 'xxxx', + 'options': {}}) + finally: + warnings.warn = old_warn + + self.assertEquals(len(warns), 0) + class MetadataTestCase(unittest.TestCase): def test_simple_metadata(self): Modified: python/branches/py3k-issue1717/Lib/distutils/util.py ============================================================================== --- python/branches/py3k-issue1717/Lib/distutils/util.py (original) +++ python/branches/py3k-issue1717/Lib/distutils/util.py Fri Jan 2 15:30:39 2009 @@ -99,7 +99,11 @@ if not macver: macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET') - if not macver: + if 1: + # Always calculate the release of the running machine, + # needed to determine if we can build fat binaries or not. + + macrelease = macver # Get the system version. Reading this plist is a documented # way to get the system version (see the documentation for # the Gestalt Manager) @@ -115,16 +119,18 @@ r'(.*?)', f.read()) f.close() if m is not None: - macver = '.'.join(m.group(1).split('.')[:2]) + macrelease = '.'.join(m.group(1).split('.')[:2]) # else: fall back to the default behaviour + if not macver: + macver = macrelease + if macver: from distutils.sysconfig import get_config_vars release = macver osname = "macosx" - - if (release + '.') >= '10.4.' and \ + if (macrelease + '.') >= '10.4.' and \ '-arch' in get_config_vars().get('CFLAGS', '').strip(): # The universal build will build fat binaries, but not on # systems before 10.4 @@ -133,9 +139,13 @@ # 'universal' instead of 'fat'. machine = 'fat' + cflags = get_config_vars().get('CFLAGS') - if '-arch x86_64' in get_config_vars().get('CFLAGS'): - machine = 'universal' + if '-arch x86_64' in cflags: + if '-arch i386' in cflags: + machine = 'universal' + else: + machine = 'fat64' elif machine in ('PowerPC', 'Power_Macintosh'): # Pick a sane name for the PPC architecture. Modified: python/branches/py3k-issue1717/Lib/idlelib/IOBinding.py ============================================================================== --- python/branches/py3k-issue1717/Lib/idlelib/IOBinding.py (original) +++ python/branches/py3k-issue1717/Lib/idlelib/IOBinding.py Fri Jan 2 15:30:39 2009 @@ -64,52 +64,6 @@ coding_re = re.compile("coding[:=]\s*([-\w_.]+)") -class EncodingMessage(SimpleDialog): - "Inform user that an encoding declaration is needed." - def __init__(self, master, enc): - self.should_edit = False - - self.root = top = Toplevel(master) - top.bind("", self.return_event) - top.bind("", self.do_ok) - top.protocol("WM_DELETE_WINDOW", self.wm_delete_window) - top.wm_title("I/O Warning") - top.wm_iconname("I/O Warning") - self.top = top - - l1 = Label(top, - text="Non-ASCII found, yet no encoding declared. Add a line like") - l1.pack(side=TOP, anchor=W) - l2 = Entry(top, font="courier") - l2.insert(0, "# -*- coding: %s -*-" % enc) - # For some reason, the text is not selectable anymore if the - # widget is disabled. - # l2['state'] = DISABLED - l2.pack(side=TOP, anchor = W, fill=X) - l3 = Label(top, text="to your file\n" - "Choose OK to save this file as %s\n" - "Edit your general options to silence this warning" % enc) - l3.pack(side=TOP, anchor = W) - - buttons = Frame(top) - buttons.pack(side=TOP, fill=X) - # Both return and cancel mean the same thing: do nothing - self.default = self.cancel = 0 - b1 = Button(buttons, text="Ok", default="active", - command=self.do_ok) - b1.pack(side=LEFT, fill=BOTH, expand=1) - b2 = Button(buttons, text="Edit my file", - command=self.do_edit) - b2.pack(side=LEFT, fill=BOTH, expand=1) - - self._set_transient(master) - - def do_ok(self): - self.done(0) - - def do_edit(self): - self.done(1) - def coding_spec(data): """Return the encoding declaration according to PEP 263. @@ -409,6 +363,9 @@ # This is either plain ASCII, or Tk was returning mixed-encoding # text to us. Don't try to guess further. return chars + # Preserve a BOM that might have been present on opening + if self.fileencoding == 'BOM': + return BOM_UTF8 + chars.encode("utf-8") # See whether there is anything non-ASCII in it. # If not, no need to figure out the encoding. try: @@ -423,61 +380,22 @@ except LookupError as msg: failed = msg enc = None + else: + if not enc: + # PEP 3120: default source encoding is UTF-8 + enc = 'utf-8' if enc: try: return chars.encode(enc) except UnicodeError: failed = "Invalid encoding '%s'" % enc - if failed: - tkMessageBox.showerror( - "I/O Error", - "%s.\nSaving as UTF-8" % failed, - master = self.text) - # If there was a UTF-8 signature, use that. This should not fail - if self.fileencoding == 'BOM' or failed: - return BOM_UTF8 + chars.encode("utf-8") - # Try the original file encoding next, if any - if self.fileencoding: - try: - return chars.encode(self.fileencoding) - except UnicodeError: - tkMessageBox.showerror( - "I/O Error", - "Cannot save this as '%s' anymore. Saving as UTF-8" \ - % self.fileencoding, - master = self.text) - return BOM_UTF8 + chars.encode("utf-8") - # Nothing was declared, and we had not determined an encoding - # on loading. Recommend an encoding line. - config_encoding = idleConf.GetOption("main","EditorWindow", - "encoding") - if config_encoding == 'utf-8': - # User has requested that we save files as UTF-8 - return BOM_UTF8 + chars.encode("utf-8") - ask_user = True - try: - chars = chars.encode(encoding) - enc = encoding - if config_encoding == 'locale': - ask_user = False - except UnicodeError: - chars = BOM_UTF8 + chars.encode("utf-8") - enc = "utf-8" - if not ask_user: - return chars - dialog = EncodingMessage(self.editwin.top, enc) - dialog.go() - if dialog.num == 1: - # User asked us to edit the file - encline = "# -*- coding: %s -*-\n" % enc - firstline = self.text.get("1.0", "2.0") - if firstline.startswith("#!"): - # Insert encoding after #! line - self.text.insert("2.0", encline) - else: - self.text.insert("1.0", encline) - return self.encode(self.text.get("1.0", "end-1c")) - return chars + tkMessageBox.showerror( + "I/O Error", + "%s.\nSaving as UTF-8" % failed, + master = self.text) + # Fallback: save as UTF-8, with BOM - ignoring the incorrect + # declared encoding + return BOM_UTF8 + chars.encode("utf-8") def fixlastline(self): c = self.text.get("end-2c") Modified: python/branches/py3k-issue1717/Lib/idlelib/NEWS.txt ============================================================================== --- python/branches/py3k-issue1717/Lib/idlelib/NEWS.txt (original) +++ python/branches/py3k-issue1717/Lib/idlelib/NEWS.txt Fri Jan 2 15:30:39 2009 @@ -1,3 +1,14 @@ +What's New in IDLE 3.1a1? +========================= + +*Release date: XX-XXX-XXXX* + +- Issue #4323: Always encode source as UTF-8 without asking + the user (unless a different encoding is declared); remove + user configuration of source encoding; all according to + PEP 3120. + + What's New in IDLE 3.0a3? ========================= Modified: python/branches/py3k-issue1717/Lib/idlelib/configDialog.py ============================================================================== --- python/branches/py3k-issue1717/Lib/idlelib/configDialog.py (original) +++ python/branches/py3k-issue1717/Lib/idlelib/configDialog.py Fri Jan 2 15:30:39 2009 @@ -336,7 +336,6 @@ text=' Autosave Preferences ') frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE) frameParaSize=Frame(frame,borderwidth=2,relief=GROOVE) - frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE) frameHelp=LabelFrame(frame,borderwidth=2,relief=GROOVE, text=' Additional Help Sources ') #frameRun @@ -365,14 +364,6 @@ ' width (in characters)') entryParaWidth=Entry(frameParaSize,textvariable=self.paraWidth, width=3) - #frameEncoding - labelEncodingTitle=Label(frameEncoding,text="Default Source Encoding") - radioEncLocale=Radiobutton(frameEncoding,variable=self.encoding, - value="locale",text="Locale-defined") - radioEncUTF8=Radiobutton(frameEncoding,variable=self.encoding, - value="utf-8",text="UTF-8") - radioEncNone=Radiobutton(frameEncoding,variable=self.encoding, - value="none",text="None") #frameHelp frameHelpList=Frame(frameHelp) frameHelpListButtons=Frame(frameHelpList) @@ -394,7 +385,6 @@ frameSave.pack(side=TOP,padx=5,pady=5,fill=X) frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X) frameParaSize.pack(side=TOP,padx=5,pady=5,fill=X) - frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X) frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) #frameRun labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) @@ -413,11 +403,6 @@ #paragraphFormatWidth labelParaWidthTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) entryParaWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5) - #frameEncoding - labelEncodingTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) - radioEncNone.pack(side=RIGHT,anchor=E,pady=5) - radioEncUTF8.pack(side=RIGHT,anchor=E,pady=5) - radioEncLocale.pack(side=RIGHT,anchor=E,pady=5) #frameHelp frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y) frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) Modified: python/branches/py3k-issue1717/Lib/io.py ============================================================================== --- python/branches/py3k-issue1717/Lib/io.py (original) +++ python/branches/py3k-issue1717/Lib/io.py Fri Jan 2 15:30:39 2009 @@ -1157,7 +1157,7 @@ @property def closed(self): - return self.writer.closed() + return self.writer.closed class BufferedRandom(BufferedWriter, BufferedReader): Modified: python/branches/py3k-issue1717/Lib/lib2to3/main.py ============================================================================== --- python/branches/py3k-issue1717/Lib/lib2to3/main.py (original) +++ python/branches/py3k-issue1717/Lib/lib2to3/main.py Fri Jan 2 15:30:39 2009 @@ -40,7 +40,8 @@ # Actually write the new file super(StdoutRefactoringTool, self).write_file(new_text, filename, old_text) - shutil.copymode(filename, backup) + if not self.nobackups: + shutil.copymode(filename, backup) def print_output(self, lines): for line in lines: Modified: python/branches/py3k-issue1717/Lib/pickle.py ============================================================================== --- python/branches/py3k-issue1717/Lib/pickle.py (original) +++ python/branches/py3k-issue1717/Lib/pickle.py Fri Jan 2 15:30:39 2009 @@ -222,6 +222,11 @@ def dump(self, obj): """Write a pickled representation of obj to the open file.""" + # Check whether Pickler was initialized correctly. This is + # only needed to mimic the behavior of _pickle.Pickler.dump(). + if not hasattr(self, "write"): + raise PicklingError("Pickler.__init__() was not called by " + "%s.__init__()" % (self.__class__.__name__,)) if self.proto >= 2: self.write(PROTO + bytes([self.proto])) self.save(obj) @@ -789,6 +794,11 @@ Return the reconstituted object hierarchy specified in the file. """ + # Check whether Unpickler was initialized correctly. This is + # only needed to mimic the behavior of _pickle.Unpickler.dump(). + if not hasattr(self, "read"): + raise UnpicklingError("Unpickler.__init__() was not called by " + "%s.__init__()" % (self.__class__.__name__,)) self.mark = object() # any new unique object self.stack = [] self.append = self.stack.append Modified: python/branches/py3k-issue1717/Lib/pydoc.py ============================================================================== --- python/branches/py3k-issue1717/Lib/pydoc.py (original) +++ python/branches/py3k-issue1717/Lib/pydoc.py Fri Jan 2 15:30:39 2009 @@ -1568,6 +1568,42 @@ 'with': ('with', 'CONTEXTMANAGERS EXCEPTIONS yield'), 'yield': ('yield', ''), } + # Either add symbols to this dictionary or to the symbols dictionary + # directly: Whichever is easier. They are merged later. + _symbols_inverse = { + 'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'), + 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', + '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), + 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'), + 'UNARY' : ('-', '~'), + 'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=', + '^=', '<<=', '>>=', '**=', '//='), + 'BITWISE' : ('<<', '>>', '&', '|', '^', '~'), + 'COMPLEX' : ('j', 'J') + } + symbols = { + '%': 'OPERATORS FORMATTING', + '**': 'POWER', + ',': 'TUPLES LISTS FUNCTIONS', + '.': 'ATTRIBUTES FLOAT MODULES OBJECTS', + '...': 'ELLIPSIS', + ':': 'SLICINGS DICTIONARYLITERALS', + '@': 'def class', + '\\': 'STRINGS', + '_': 'PRIVATENAMES', + '__': 'PRIVATENAMES SPECIALMETHODS', + '`': 'BACKQUOTES', + '(': 'TUPLES FUNCTIONS CALLS', + ')': 'TUPLES FUNCTIONS CALLS', + '[': 'LISTS SUBSCRIPTS SLICINGS', + ']': 'LISTS SUBSCRIPTS SLICINGS' + } + for topic, symbols_ in _symbols_inverse.items(): + for symbol in symbols_: + topics = symbols.get(symbol, topic) + if topic not in topics: + topics = topics + ' ' + topic + symbols[symbol] = topics topics = { 'TYPES': ('types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS ' @@ -1705,10 +1741,12 @@ if type(request) is type(''): if request == 'help': self.intro() elif request == 'keywords': self.listkeywords() + elif request == 'symbols': self.listsymbols() elif request == 'topics': self.listtopics() elif request == 'modules': self.listmodules() elif request[:8] == 'modules ': self.listmodules(request.split()[1]) + elif request in self.symbols: self.showsymbol(request) elif request in self.keywords: self.showtopic(request) elif request in self.topics: self.showtopic(request) elif request: doc(request, 'Help on %s:') @@ -1753,6 +1791,14 @@ ''') self.list(self.keywords.keys()) + def listsymbols(self): + self.output.write(''' +Here is a list of the punctuation symbols which Python assigns special meaning +to. Enter any symbol to get more help. + +''') + self.list(self.symbols.keys()) + def listtopics(self): self.output.write(''' Here is a list of available topics. Enter any topic name to get more help. @@ -1760,7 +1806,7 @@ ''') self.list(self.topics.keys()) - def showtopic(self, topic): + def showtopic(self, topic, more_xrefs=''): try: import pydoc_topics except ImportError: @@ -1774,7 +1820,7 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return if type(target) is type(''): - return self.showtopic(target) + return self.showtopic(target, more_xrefs) label, xrefs = target try: @@ -1783,6 +1829,8 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return pager(doc.strip() + '\n') + if more_xrefs: + xrefs = (xrefs or '') + ' ' + more_xrefs if xrefs: import io, formatter buffer = io.StringIO() @@ -1790,6 +1838,11 @@ 'Related help topics: ' + ', '.join(xrefs.split()) + '\n') self.output.write('\n%s\n' % buffer.getvalue()) + def showsymbol(self, symbol): + target = self.symbols[symbol] + topic, _, xrefs = target.partition(' ') + self.showtopic(topic, xrefs) + def listmodules(self, key=''): if key: self.output.write(''' Modified: python/branches/py3k-issue1717/Lib/re.py ============================================================================== --- python/branches/py3k-issue1717/Lib/re.py (original) +++ python/branches/py3k-issue1717/Lib/re.py Fri Jan 2 15:30:39 2009 @@ -160,7 +160,8 @@ """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; - if a callable, it's passed the match object and must return + if a string, backslash escapes in it are processed. If it is + a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).sub(repl, string, count) @@ -170,7 +171,8 @@ non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a - callable; if a callable, it's passed the match object and must + callable; if a string, backslash escapes in it are processed. + If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, 0).subn(repl, string, count) Modified: python/branches/py3k-issue1717/Lib/ssl.py ============================================================================== --- python/branches/py3k-issue1717/Lib/ssl.py (original) +++ python/branches/py3k-issue1717/Lib/ssl.py Fri Jan 2 15:30:39 2009 @@ -114,7 +114,7 @@ # see if it's connected try: socket.getpeername(self) - except: + except socket_error: # no, no connection yet self._sslobj = None else: Modified: python/branches/py3k-issue1717/Lib/test/pickletester.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/pickletester.py (original) +++ python/branches/py3k-issue1717/Lib/test/pickletester.py Fri Jan 2 15:30:39 2009 @@ -484,13 +484,21 @@ self.assertRaises(ValueError, self.loads, buf) def test_unicode(self): - endcases = ['', '<\\u>', '<\\\u1234>', '<\n>', '<\\>'] + endcases = ['', '<\\u>', '<\\\u1234>', '<\n>', + '<\\>', '<\\\U00012345>'] for proto in protocols: for u in endcases: p = self.dumps(u, proto) u2 = self.loads(p) self.assertEqual(u2, u) + def test_unicode_high_plane(self): + t = '\U00012345' + for proto in protocols: + p = self.dumps(t, proto) + t2 = self.loads(p) + self.assertEqual(t2, t) + def test_bytes(self): for proto in protocols: for u in b'', b'xyz', b'xyz'*100: Modified: python/branches/py3k-issue1717/Lib/test/test_array.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_array.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_array.py Fri Jan 2 15:30:39 2009 @@ -7,7 +7,7 @@ from test import support from weakref import proxy import array, io, math -from pickle import loads, dumps +from pickle import loads, dumps, HIGHEST_PROTOCOL import operator class ArraySubclass(array.array): @@ -98,7 +98,7 @@ self.assertEqual(a, b) def test_pickle(self): - for protocol in (0, 1, 2): + for protocol in range(HIGHEST_PROTOCOL + 1): a = array.array(self.typecode, self.example) b = loads(dumps(a, protocol)) self.assertNotEqual(id(a), id(b)) @@ -113,7 +113,7 @@ self.assertEqual(type(a), type(b)) def test_pickle_for_empty_array(self): - for protocol in (0, 1, 2): + for protocol in range(HIGHEST_PROTOCOL + 1): a = array.array(self.typecode) b = loads(dumps(a, protocol)) self.assertNotEqual(id(a), id(b)) Modified: python/branches/py3k-issue1717/Lib/test/test_bytes.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_bytes.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_bytes.py Fri Jan 2 15:30:39 2009 @@ -888,11 +888,21 @@ def test_translate(self): b = b'hello' + ba = bytearray(b) rosetta = bytearray(range(0, 256)) rosetta[ord('o')] = ord('e') c = b.translate(rosetta, b'l') self.assertEqual(b, b'hello') self.assertEqual(c, b'hee') + c = ba.translate(rosetta, b'l') + self.assertEqual(ba, b'hello') + self.assertEqual(c, b'hee') + c = b.translate(None, b'e') + self.assertEqual(c, b'hllo') + c = ba.translate(None, b'e') + self.assertEqual(c, b'hllo') + self.assertRaises(TypeError, b.translate, None, None) + self.assertRaises(TypeError, ba.translate, None, None) def test_split_bytearray(self): self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b']) Modified: python/branches/py3k-issue1717/Lib/test/test_deque.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_deque.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_deque.py Fri Jan 2 15:30:39 2009 @@ -1,7 +1,8 @@ from collections import deque import unittest from test import support, seq_tests -from weakref import proxy +import gc +import weakref import copy import pickle from io import StringIO @@ -374,7 +375,7 @@ def test_pickle(self): d = deque(range(200)) - for i in (0, 1, 2): + for i in range(pickle.HIGHEST_PROTOCOL + 1): s = pickle.dumps(d, i) e = pickle.loads(s) self.assertNotEqual(id(d), id(e)) @@ -383,7 +384,7 @@ ## def test_pickle_recursive(self): ## d = deque('abc') ## d.append(d) -## for i in (0, 1, 2): +## for i in range(pickle.HIGHEST_PROTOCOL + 1): ## e = pickle.loads(pickle.dumps(d, i)) ## self.assertNotEqual(id(d), id(e)) ## self.assertEqual(id(e), id(e[-1])) @@ -419,6 +420,22 @@ d.append(1) gc.collect() + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for deque iterator objects + class C(object): + pass + for i in range(2): + obj = C() + ref = weakref.ref(obj) + if i == 0: + container = deque([obj, 1]) + else: + container = reversed(deque([obj, 1])) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): @@ -529,7 +546,7 @@ def test_weakref(self): d = deque('gallahad') - p = proxy(d) + p = weakref.proxy(d) self.assertEqual(str(p), str(d)) d = None self.assertRaises(ReferenceError, str, p) Modified: python/branches/py3k-issue1717/Lib/test/test_dict.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_dict.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_dict.py Fri Jan 2 15:30:39 2009 @@ -2,6 +2,7 @@ from test import support import sys, collections, random, string +import gc, weakref class DictTest(unittest.TestCase): @@ -648,6 +649,21 @@ pass d = {} + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for dictiter and + # dictview objects. + class C(object): + pass + views = (dict.items, dict.values, dict.keys) + for v in views: + obj = C() + ref = weakref.ref(obj) + container = {obj: 1} + obj.v = v(container) + obj.x = iter(obj.v) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") from test import mapping_tests Modified: python/branches/py3k-issue1717/Lib/test/test_file.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_file.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_file.py Fri Jan 2 15:30:39 2009 @@ -123,6 +123,8 @@ except: self.assertEquals(self.f.__exit__(*sys.exc_info()), None) + def testReadWhenWriting(self): + self.assertRaises(IOError, self.f.read) class OtherFileTests(unittest.TestCase): Modified: python/branches/py3k-issue1717/Lib/test/test_fileio.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_fileio.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_fileio.py Fri Jan 2 15:30:39 2009 @@ -108,6 +108,7 @@ _fileio._FileIO('.', 'r') except IOError as e: self.assertNotEqual(e.errno, 0) + self.assertEqual(e.filename, ".") else: self.fail("Should have raised IOError") Modified: python/branches/py3k-issue1717/Lib/test/test_generators.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_generators.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_generators.py Fri Jan 2 15:30:39 2009 @@ -928,6 +928,16 @@ 'f' >>> repr(g) # doctest: +ELLIPSIS '' + +Lambdas shouldn't have their usual return behavior. + +>>> x = lambda: (yield 1) +>>> list(x()) +[1] + +>>> x = lambda: ((yield 1), (yield 2)) +>>> list(x()) +[1, 2] """ # conjoin is a simple backtracking generator, named in honor of Icon's Modified: python/branches/py3k-issue1717/Lib/test/test_hash.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_hash.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_hash.py Fri Jan 2 15:30:39 2009 @@ -97,9 +97,30 @@ self.assertFalse(isinstance(obj, Hashable), repr(obj)) +# Issue #4701: Check that some builtin types are correctly hashable +class DefaultIterSeq(object): + seq = range(10) + def __len__(self): + return len(self.seq) + def __getitem__(self, index): + return self.seq[index] + +class HashBuiltinsTestCase(unittest.TestCase): + hashes_to_check = [range(10), + enumerate(range(10)), + iter(DefaultIterSeq()), + iter(lambda: 0, 0), + ] + + def test_hashes(self): + _default_hash = object.__hash__ + for obj in self.hashes_to_check: + self.assertEqual(hash(obj), _default_hash(obj)) + def test_main(): support.run_unittest(HashEqualityTestCase, - HashInheritanceTestCase) + HashInheritanceTestCase, + HashBuiltinsTestCase) if __name__ == "__main__": Modified: python/branches/py3k-issue1717/Lib/test/test_io.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_io.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_io.py Fri Jan 2 15:30:39 2009 @@ -553,8 +553,9 @@ r = MockRawIO(()) w = MockRawIO() pair = io.BufferedRWPair(r, w) + self.assertFalse(pair.closed) - # XXX need implementation + # XXX More Tests class BufferedRandomTest(unittest.TestCase): Modified: python/branches/py3k-issue1717/Lib/test/test_set.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_set.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_set.py Fri Jan 2 15:30:39 2009 @@ -1,6 +1,7 @@ import unittest from test import support -from weakref import proxy +import gc +import weakref import operator import copy import pickle @@ -219,7 +220,7 @@ self.failIf(set('cbs').issuperset('a')) def test_pickling(self): - for i in (0, 1, 2): + for i in range(pickle.HIGHEST_PROTOCOL + 1): p = pickle.dumps(self.s, i) dup = pickle.loads(p) self.assertEqual(self.s, dup, "%s != %s" % (self.s, dup)) @@ -323,6 +324,18 @@ self.assertEqual(sum(elem.hash_count for elem in d), n) self.assertEqual(d3, dict.fromkeys(d, 123)) + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for set iterator object + class C(object): + pass + obj = C() + ref = weakref.ref(obj) + container = set([obj, 1]) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestSet(TestJointOps): thetype = set basetype = set @@ -546,7 +559,7 @@ def test_weakref(self): s = self.thetype('gallahad') - p = proxy(s) + p = weakref.proxy(s) self.assertEqual(str(p), str(s)) s = None self.assertRaises(ReferenceError, str, p) Modified: python/branches/py3k-issue1717/Lib/test/test_unittest.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_unittest.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_unittest.py Fri Jan 2 15:30:39 2009 @@ -2294,6 +2294,43 @@ self.assertRaises(AssertionError, self.failIfAlmostEqual, 0, .1+.1j, places=0) + def test_assertRaises(self): + def _raise(e): + raise e + self.assertRaises(KeyError, _raise, KeyError) + self.assertRaises(KeyError, _raise, KeyError("key")) + try: + self.assertRaises(KeyError, lambda: None) + except AssertionError as e: + self.assert_("KeyError not raised" in str(e), str(e)) + else: + self.fail("assertRaises() didn't fail") + try: + self.assertRaises(KeyError, _raise, ValueError) + except ValueError: + pass + else: + self.fail("assertRaises() didn't let exception pass through") + with self.assertRaises(KeyError): + raise KeyError + with self.assertRaises(KeyError): + raise KeyError("key") + try: + with self.assertRaises(KeyError): + pass + except AssertionError as e: + self.assert_("KeyError not raised" in str(e), str(e)) + else: + self.fail("assertRaises() didn't fail") + try: + with self.assertRaises(KeyError): + raise ValueError + except ValueError: + pass + else: + self.fail("assertRaises() didn't let exception pass through") + + ###################################################################### ## Main ###################################################################### Modified: python/branches/py3k-issue1717/Lib/test/test_urllib2.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_urllib2.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_urllib2.py Fri Jan 2 15:30:39 2009 @@ -1104,6 +1104,51 @@ else: self.assert_(False) +class RequestTests(unittest.TestCase): + + def setUp(self): + self.get = Request("http://www.python.org/~jeremy/") + self.post = Request("http://www.python.org/~jeremy/", + "data", + headers={"X-Test": "test"}) + + def test_method(self): + self.assertEqual("POST", self.post.get_method()) + self.assertEqual("GET", self.get.get_method()) + + def test_add_data(self): + self.assert_(not self.get.has_data()) + self.assertEqual("GET", self.get.get_method()) + self.get.add_data("spam") + self.assert_(self.get.has_data()) + self.assertEqual("POST", self.get.get_method()) + + def test_get_full_url(self): + self.assertEqual("http://www.python.org/~jeremy/", + self.get.get_full_url()) + + def test_selector(self): + self.assertEqual("/~jeremy/", self.get.get_selector()) + req = Request("http://www.python.org/") + self.assertEqual("/", req.get_selector()) + + def test_get_type(self): + self.assertEqual("http", self.get.get_type()) + + def test_get_host(self): + self.assertEqual("www.python.org", self.get.get_host()) + + def test_get_host_unquote(self): + req = Request("http://www.%70ython.org/") + self.assertEqual("www.python.org", req.get_host()) + + def test_proxy(self): + self.assert_(not self.get.has_proxy()) + self.get.set_proxy("www.perl.org", "http") + self.assert_(self.get.has_proxy()) + self.assertEqual("www.python.org", self.get.get_origin_req_host()) + self.assertEqual("www.perl.org", self.get.get_host()) + def test_main(verbose=None): from test import test_urllib2 @@ -1112,7 +1157,8 @@ tests = (TrivialTests, OpenerDirectorTests, HandlerTests, - MiscTests) + MiscTests, + RequestTests) support.run_unittest(*tests) if __name__ == "__main__": Modified: python/branches/py3k-issue1717/Lib/test/test_zipfile.py ============================================================================== --- python/branches/py3k-issue1717/Lib/test/test_zipfile.py (original) +++ python/branches/py3k-issue1717/Lib/test/test_zipfile.py Fri Jan 2 15:30:39 2009 @@ -621,20 +621,49 @@ def testIsZipErroneousFile(self): # This test checks that the is_zipfile function correctly identifies # a file that is not a zip file - fp = open(TESTFN, "w") - fp.write("this is not a legal zip file\n") - fp.close() + + # - passing a filename + with open(TESTFN, "w") as fp: + fp.write("this is not a legal zip file\n") chk = zipfile.is_zipfile(TESTFN) - self.assert_(chk is False) + self.assert_(not chk) + # - passing a file object + with open(TESTFN, "rb") as fp: + chk = zipfile.is_zipfile(fp) + self.assert_(not chk) + # - passing a file-like object + fp = io.BytesIO() + fp.write(b"this is not a legal zip file\n") + chk = zipfile.is_zipfile(fp) + self.assert_(not chk) + fp.seek(0,0) + chk = zipfile.is_zipfile(fp) + self.assert_(not chk) def testIsZipValidFile(self): # This test checks that the is_zipfile function correctly identifies # a file that is a zip file + + # - passing a filename zipf = zipfile.ZipFile(TESTFN, mode="w") zipf.writestr("foo.txt", b"O, for a Muse of Fire!") zipf.close() chk = zipfile.is_zipfile(TESTFN) - self.assert_(chk is True) + self.assert_(chk) + # - passing a file object + with open(TESTFN, "rb") as fp: + chk = zipfile.is_zipfile(fp) + self.assert_(chk) + fp.seek(0,0) + zip_contents = fp.read() + # - passing a file-like object + fp = io.BytesIO() + fp.write(zip_contents) + chk = zipfile.is_zipfile(fp) + self.assert_(chk) + fp.seek(0,0) + chk = zipfile.is_zipfile(fp) + self.assert_(chk) def testNonExistentFileRaisesIOError(self): # make sure we don't raise an AttributeError when a partially-constructed Modified: python/branches/py3k-issue1717/Lib/tkinter/colorchooser.py ============================================================================== --- python/branches/py3k-issue1717/Lib/tkinter/colorchooser.py (original) +++ python/branches/py3k-issue1717/Lib/tkinter/colorchooser.py Fri Jan 2 15:30:39 2009 @@ -34,19 +34,22 @@ try: # make sure initialcolor is a tk color string color = self.options["initialcolor"] - if type(color) == type(()): + if isinstance(color, tuple): # assume an RGB triplet self.options["initialcolor"] = "#%02x%02x%02x" % color except KeyError: pass def _fixresult(self, widget, result): + # result can be somethings: an empty tuple, an empty string or + # a Tcl_Obj, so this somewhat weird check handles that + if not result or not str(result): + return None, None # canceled + # to simplify application code, the color chooser returns # an RGB tuple together with the Tk color string - if not result: - return None, None # canceled r, g, b = widget.winfo_rgb(result) - return (r/256, g/256, b/256), result + return (r/256, g/256, b/256), str(result) # @@ -66,5 +69,4 @@ # test stuff if __name__ == "__main__": - print("color", askcolor()) Modified: python/branches/py3k-issue1717/Lib/tkinter/filedialog.py ============================================================================== --- python/branches/py3k-issue1717/Lib/tkinter/filedialog.py (original) +++ python/branches/py3k-issue1717/Lib/tkinter/filedialog.py Fri Jan 2 15:30:39 2009 @@ -350,7 +350,7 @@ # the directory dialog has its own _fix routines. -class Directory(Dialog): +class Directory(commondialog.Dialog): "Ask for a directory" command = "tk_chooseDirectory" Modified: python/branches/py3k-issue1717/Lib/tkinter/scrolledtext.py ============================================================================== --- python/branches/py3k-issue1717/Lib/tkinter/scrolledtext.py (original) +++ python/branches/py3k-issue1717/Lib/tkinter/scrolledtext.py Fri Jan 2 15:30:39 2009 @@ -1,42 +1,52 @@ -# A ScrolledText widget feels like a text widget but also has a -# vertical scroll bar on its right. (Later, options may be added to -# add a horizontal bar as well, to make the bars disappear -# automatically when not needed, to move them to the other side of the -# window, etc.) -# -# Configuration options are passed to the Text widget. -# A Frame widget is inserted between the master and the text, to hold -# the Scrollbar widget. -# Most methods calls are inherited from the Text widget; Pack methods -# are redirected to the Frame widget however. +"""A ScrolledText widget feels like a text widget but also has a +vertical scroll bar on its right. (Later, options may be added to +add a horizontal bar as well, to make the bars disappear +automatically when not needed, to move them to the other side of the +window, etc.) -from tkinter import * -from tkinter import _cnfmerge +Configuration options are passed to the Text widget. +A Frame widget is inserted between the master and the text, to hold +the Scrollbar widget. +Most methods calls are inherited from the Text widget; Pack, Grid and +Place methods are redirected to the Frame widget however. +""" -class ScrolledText(Text): - def __init__(self, master=None, cnf=None, **kw): - if cnf is None: - cnf = {} - if kw: - cnf = _cnfmerge((cnf, kw)) - fcnf = {k:v for k,v in cnf.items() if isinstance(k,type) or k=='name'} - for k in fcnf.keys(): - del cnf[k] +__all__ = ['ScrolledText'] + +from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place +from tkinter.constants import RIGHT, LEFT, Y, BOTH - self.frame = Frame(master, **fcnf) - self.vbar = Scrollbar(self.frame, name='vbar') +class ScrolledText(Text): + def __init__(self, master=None, **kw): + self.frame = Frame(master) + self.vbar = Scrollbar(self.frame) self.vbar.pack(side=RIGHT, fill=Y) - cnf['name'] = 'text' - Text.__init__(self, self.frame, **cnf) - self.pack(side=LEFT, fill=BOTH, expand=1) - self['yscrollcommand'] = self.vbar.set + + kw.update({'yscrollcommand': self.vbar.set}) + Text.__init__(self, self.frame, **kw) + self.pack(side=LEFT, fill=BOTH, expand=True) self.vbar['command'] = self.yview # Copy geometry methods of self.frame -- hack! - methods = Pack.__dict__.keys() - methods = methods + Grid.__dict__.keys() - methods = methods + Place.__dict__.keys() + methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys() for m in methods: if m[0] != '_' and m != 'config' and m != 'configure': setattr(self, m, getattr(self.frame, m)) + + def __str__(self): + return str(self.frame) + + +def example(): + import __main__ + from tkinter.constants import END + + stext = ScrolledText(bg='white', height=10) + stext.insert(END, __main__.__doc__) + stext.pack(fill=BOTH, side=LEFT, expand=True) + stext.focus_set() + stext.mainloop() + +if __name__ == "__main__": + example() Modified: python/branches/py3k-issue1717/Lib/unittest.py ============================================================================== --- python/branches/py3k-issue1717/Lib/unittest.py (original) +++ python/branches/py3k-issue1717/Lib/unittest.py Fri Jan 2 15:30:39 2009 @@ -149,6 +149,36 @@ (_strclass(self.__class__), self.testsRun, len(self.errors), len(self.failures)) +class AssertRaisesContext: + def __init__(self, expected, test_case, callable_obj=None): + self.expected = expected + self.failureException = test_case.failureException + if callable_obj is not None: + try: + self.obj_name = callable_obj.__name__ + except AttributeError: + self.obj_name = str(callable_obj) + else: + self.obj_name = None + def __enter__(self): + pass + def __exit__(self, exc_type, exc_value, traceback): + if exc_type is None: + try: + exc_name = self.expected.__name__ + except AttributeError: + exc_name = str(self.expected) + if self.obj_name: + raise self.failureException("{0} not raised by {1}" + .format(exc_name, self.obj_name)) + else: + raise self.failureException("{0} not raised" + .format(exc_name)) + if issubclass(exc_type, self.expected): + return True + # Let unexpected exceptions skip through + return False + class TestCase: """A class whose instances are single test cases. @@ -299,23 +329,25 @@ """Fail the test unless the expression is true.""" if not expr: raise self.failureException(msg) - def failUnlessRaises(self, excClass, callableObj, *args, **kwargs): + def failUnlessRaises(self, excClass, callableObj=None, *args, **kwargs): """Fail unless an exception of class excClass is thrown by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is thrown, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception. + + If called with callableObj omitted or None, will return a + context object used like this:: + + with self.failUnlessRaises(some_error_class): + do_something() """ - try: + context = AssertRaisesContext(excClass, self, callableObj) + if callableObj is None: + return context + with context: callableObj(*args, **kwargs) - except excClass: - return - else: - excName = str(getattr(excClass, '__name__', excClass)) - objName = str(getattr(callableObj, '__name__', callableObj)) - raise self.failureException("%s not raised by %s" % (excName, - objName)) def failUnlessEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' Modified: python/branches/py3k-issue1717/Lib/zipfile.py ============================================================================== --- python/branches/py3k-issue1717/Lib/zipfile.py (original) +++ python/branches/py3k-issue1717/Lib/zipfile.py Fri Jan 2 15:30:39 2009 @@ -130,18 +130,30 @@ _CD64_DIRECTORY_SIZE = 8 _CD64_OFFSET_START_CENTDIR = 9 -def is_zipfile(filename): - """Quickly see if file is a ZIP file by checking the magic number.""" +def _check_zipfile(fp): try: - fpin = io.open(filename, "rb") - endrec = _EndRecData(fpin) - fpin.close() - if endrec: - return True # file has correct magic number + if _EndRecData(fp): + return True # file has correct magic number except IOError: pass return False +def is_zipfile(filename): + """Quickly see if a file is a ZIP file by checking the magic number. + + The filename argument may be a file or file-like object too. + """ + result = False + try: + if hasattr(filename, "read"): + result = _check_zipfile(fp=filename) + else: + with open(filename, "rb") as fp: + result = _check_zipfile(fp) + except IOError: + pass + return result + def _EndRecData64(fpin, offset, endrec): """ Read the ZIP64 end-of-archive records and use that to update endrec Modified: python/branches/py3k-issue1717/Mac/BuildScript/build-installer.py ============================================================================== --- python/branches/py3k-issue1717/Mac/BuildScript/build-installer.py (original) +++ python/branches/py3k-issue1717/Mac/BuildScript/build-installer.py Fri Jan 2 15:30:39 2009 @@ -9,8 +9,7 @@ Usage: see USAGE variable in the script. """ -import platform, os, sys, getopt, textwrap, shutil, stat, time, pwd -import urllib.request +import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd import grp INCLUDE_TIMESTAMP = 1 @@ -55,7 +54,7 @@ if 'PY_VERSION' in ln: return ln.split()[-1][1:-1] - raise RuntimeError("Cannot find full version??") + raise RuntimeError, "Cannot find full version??" # The directory we'll use to create the build (will be erased and recreated) WORKDIR = "/tmp/_py" @@ -170,17 +169,6 @@ getVersion(), ), ), - dict( - name="Sleepycat DB 4.7.25", - url="http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz", - #name="Sleepycat DB 4.3.29", - #url="http://downloads.sleepycat.com/db-4.3.29.tar.gz", - buildDir="build_unix", - configure="../dist/configure", - configure_pre=[ - '--includedir=/usr/local/include/db4', - ] - ), ] @@ -196,6 +184,7 @@ wrappers for lots of Mac OS X API's. """, postflight="scripts/postflight.framework", + selected='selected', ), dict( name="PythonApplications", @@ -209,6 +198,7 @@ It also installs a number of examples and demos. """, required=False, + selected='selected', ), dict( name="PythonUnixTools", @@ -220,6 +210,7 @@ is not necessary to use MacPython. """, required=False, + selected='unselected', ), dict( name="PythonDocumentation", @@ -234,6 +225,7 @@ """, postflight="scripts/postflight.documentation", required=False, + selected='selected', ), dict( name="PythonProfileChanges", @@ -251,6 +243,7 @@ topdir="/Library/Frameworks/Python.framework", source="/empty-dir", required=False, + selected='unselected', ), dict( name="PythonSystemFixes", @@ -264,6 +257,7 @@ topdir="/Library/Frameworks/Python.framework", source="/empty-dir", required=False, + selected='unselected', ) ] @@ -292,7 +286,7 @@ xit = fd.close() if xit is not None: sys.stdout.write(data) - raise RuntimeError("command failed: %s"%(commandline,)) + raise RuntimeError, "command failed: %s"%(commandline,) if VERBOSE: sys.stdout.write(data); sys.stdout.flush() @@ -303,7 +297,7 @@ xit = fd.close() if xit is not None: sys.stdout.write(data) - raise RuntimeError("command failed: %s"%(commandline,)) + raise RuntimeError, "command failed: %s"%(commandline,) return data @@ -336,17 +330,17 @@ try: options, args = getopt.getopt(args, '?hb', [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=']) - except getopt.error as msg: - print(msg) + except getopt.error, msg: + print msg sys.exit(1) if args: - print("Additional arguments") + print "Additional arguments" sys.exit(1) for k, v in options: if k in ('-h', '-?'): - print(USAGE) + print USAGE sys.exit(0) elif k in ('-d', '--build-dir'): @@ -362,19 +356,19 @@ SRCDIR=v else: - raise NotImplementedError(k) + raise NotImplementedError, k SRCDIR=os.path.abspath(SRCDIR) WORKDIR=os.path.abspath(WORKDIR) SDKPATH=os.path.abspath(SDKPATH) DEPSRC=os.path.abspath(DEPSRC) - print("Settings:") - print(" * Source directory:", SRCDIR) - print(" * Build directory: ", WORKDIR) - print(" * SDK location: ", SDKPATH) - print(" * third-party source:", DEPSRC) - print("") + print "Settings:" + print " * Source directory:", SRCDIR + print " * Build directory: ", WORKDIR + print " * SDK location: ", SDKPATH + print " * third-party source:", DEPSRC + print "" @@ -419,7 +413,7 @@ xit = fp.close() if xit is not None: sys.stdout.write(data) - raise RuntimeError("Cannot extract %s"%(archiveName,)) + raise RuntimeError, "Cannot extract %s"%(archiveName,) return os.path.join(builddir, retval) @@ -441,9 +435,9 @@ pass else: if KNOWNSIZES.get(url) == size: - print("Using existing file for", url) + print "Using existing file for", url return - fpIn = urllib.request.urlopen(url) + fpIn = urllib2.urlopen(url) fpOut = open(fname, 'wb') block = fpIn.read(10240) try: @@ -480,14 +474,14 @@ if os.path.exists(sourceArchive): - print("Using local copy of %s"%(name,)) + print "Using local copy of %s"%(name,) else: - print("Downloading %s"%(name,)) + print "Downloading %s"%(name,) downloadURL(url, sourceArchive) - print("Archive for %s stored as %s"%(name, sourceArchive)) + print "Archive for %s stored as %s"%(name, sourceArchive) - print("Extracting archive for %s"%(name,)) + print "Extracting archive for %s"%(name,) buildDir=os.path.join(WORKDIR, '_bld') if not os.path.exists(buildDir): os.mkdir(buildDir) @@ -550,14 +544,14 @@ configure_args.insert(0, configure) configure_args = [ shellQuote(a) for a in configure_args ] - print("Running configure for %s"%(name,)) + print "Running configure for %s"%(name,) runCommand(' '.join(configure_args) + ' 2>&1') - print("Running install for %s"%(name,)) + print "Running install for %s"%(name,) runCommand('{ ' + install + ' ;} 2>&1') - print("Done %s"%(name,)) - print("") + print "Done %s"%(name,) + print "" os.chdir(curdir) @@ -565,9 +559,9 @@ """ Build our dependencies into $WORKDIR/libraries/usr/local """ - print("") - print("Building required libraries") - print("") + print "" + print "Building required libraries" + print "" universal = os.path.join(WORKDIR, 'libraries') os.mkdir(universal) os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) @@ -581,7 +575,7 @@ def buildPythonDocs(): # This stores the documentation as Resources/English.lproj/Docuentation # inside the framwork. pydoc and IDLE will pick it up there. - print("Install python documentation") + print "Install python documentation" rootDir = os.path.join(WORKDIR, '_root') version = getVersion() docdir = os.path.join(rootDir, 'pydocs') @@ -590,13 +584,13 @@ name = 'html-%s.tar.bz2'%(getFullVersion(),) sourceArchive = os.path.join(DEPSRC, name) if os.path.exists(sourceArchive): - print("Using local copy of %s"%(name,)) + print "Using local copy of %s"%(name,) else: print "Downloading %s"%(novername,) downloadURL('http://www.python.org/ftp/python/doc/%s/%s'%( getFullVersion(), novername), sourceArchive) - print("Archive for %s stored as %s"%(name, sourceArchive)) + print "Archive for %s stored as %s"%(name, sourceArchive) extractArchive(os.path.dirname(docdir), sourceArchive) @@ -607,7 +601,7 @@ def buildPython(): - print("Building a universal python") + print "Building a universal python" buildDir = os.path.join(WORKDIR, '_bld', 'python') rootDir = os.path.join(WORKDIR, '_root') @@ -630,24 +624,24 @@ # several paths. version = getVersion() - print("Running configure...") + print "Running configure..." runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( shellQuote(os.path.join(SRCDIR, 'configure')), shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1], shellQuote(WORKDIR)[1:-1])) - print("Running make") + print "Running make" runCommand("make") - print("Running make frameworkinstall") + print "Running make frameworkinstall" runCommand("make frameworkinstall DESTDIR=%s"%( shellQuote(rootDir))) - print("Running make frameworkinstallextras") + print "Running make frameworkinstallextras" runCommand("make frameworkinstallextras DESTDIR=%s"%( shellQuote(rootDir))) - print("Copying required shared libraries") + print "Copying required shared libraries" if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): runCommand("mv %s/* %s"%( shellQuote(os.path.join( @@ -658,10 +652,12 @@ 'Python.framework', 'Versions', getVersion(), 'lib')))) - print("Fix file modes") + print "Fix file modes" frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') gid = grp.getgrnam('admin').gr_gid + + for dirpath, dirnames, filenames in os.walk(frmDir): for dn in dirnames: os.chmod(os.path.join(dirpath, dn), 0775) @@ -708,6 +704,11 @@ os.chdir(curdir) + # Remove the 'Current' link, that way we don't accidently mess with an already installed + # version of python + os.unlink(os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework', 'Versions', 'Current')) + + def patchFile(inPath, outPath): @@ -747,7 +748,7 @@ readme = textwrap.dedent(recipe['readme']) isRequired = recipe.get('required', True) - print("- building package %s"%(pkgname,)) + print "- building package %s"%(pkgname,) # Substitute some variables textvars = dict( @@ -842,7 +843,7 @@ IFPkgFlagPackageList=[ dict( IFPkgFlagPackageLocation='%s-%s.pkg'%(item['name'], getVersion()), - IFPkgFlagPackageSelection='selected' + IFPkgFlagPackageSelection=item['selected'], ) for item in PKG_RECIPES ], @@ -1050,9 +1051,9 @@ shutil.copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') - print("# BUILD INFO", file=fp) - print("# Date:", time.ctime(), file=fp) - print("# By:", pwd.getpwuid(os.getuid()).pw_gecos, file=fp) + print >> fp, "# BUILD INFO" + print >> fp, "# Date:", time.ctime() + print >> fp, "# By:", pwd.getpwuid(os.getuid()).pw_gecos fp.close() # Custom icon for the DMG, shown when the DMG is mounted. Modified: python/branches/py3k-issue1717/Mac/BuildScript/resources/Welcome.rtf ============================================================================== --- python/branches/py3k-issue1717/Mac/BuildScript/resources/Welcome.rtf (original) +++ python/branches/py3k-issue1717/Mac/BuildScript/resources/Welcome.rtf Fri Jan 2 15:30:39 2009 @@ -1,18 +1,20 @@ -{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf410 -{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} +{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf430 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww9920\viewh10660\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural \f0\fs24 \cf0 This package will install -\f1\b MacPython $FULL_VERSION -\f0\b0 for -\f1\b Mac OS X $MACOSX_DEPLOYMENT_TARGET -\f0\b0 .\ +\b MacPython $FULL_VERSION +\b0 for +\b Mac OS X $MACOSX_DEPLOYMENT_TARGET +\b0 .\ \ MacPython consists of the Python programming language interpreter, plus a set of programs to allow easy access to it for Mac users (an integrated development environment, an applet builder), plus a set of pre-built extension modules that open up specific Macintosh technologies to Python programs (Carbon, AppleScript, Quicktime, more).\ \ See the ReadMe file for more information.\ \ -\ -This package will by default update your shell profile to ensure that this version of Python is on the search path of your shell. Please deselect the "Shell profile updater" package on the package customization screen if you want to avoid this modification. } \ No newline at end of file + +\b NOTE: +\b0 This package will by default update not your shell profile, and will also not install\ +files in /usr/local. } \ No newline at end of file Modified: python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/Info.plist ============================================================================== --- python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/Info.plist (original) +++ python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/Info.plist Fri Jan 2 15:30:39 2009 @@ -36,7 +36,7 @@ CFBundleExecutable IDLE CFBundleGetInfoString - 2.6.0, ?? 001-2006 Python Software Foundation + %version%, ?? 2001-2008 Python Software Foundation CFBundleIconFile IDLE.icns CFBundleIdentifier @@ -48,10 +48,10 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.6.0 + %version% CFBundleSignature ???? CFBundleVersion - 2.6.0 + %version% Modified: python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE ============================================================================== --- python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE (original) +++ python/branches/py3k-issue1717/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE Fri Jan 2 15:30:39 2009 @@ -1,4 +1,4 @@ -#!/Library/Frameworks/Python.framework/Versions/3.0/Resources/Python.app/Contents/MacOS/Python +#!%prefix%/Resources/Python.app/Contents/MacOS/Python3 import sys, os execdir = os.path.dirname(sys.argv[0]) Modified: python/branches/py3k-issue1717/Mac/Makefile.in ============================================================================== --- python/branches/py3k-issue1717/Mac/Makefile.in (original) +++ python/branches/py3k-issue1717/Mac/Makefile.in Fri Jan 2 15:30:39 2009 @@ -216,8 +216,10 @@ install_IDLE: test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp -PR IDLE/IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" ln -sf $(INSTALLED_PYTHONAPP) "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/Python" + sed -e "s!%prefix%!$(prefix)!g" -e 's!%exe%!$(PYTHONFRAMEWORK)!g' < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE" + sed "s!%version%!`$(RUNSHARED) $(BUILDPYTHON) -c 'import platform; print(platform.python_version())'`!g" < "$(srcdir)/IDLE/IDLE.app/Contents/Info.plist" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/Info.plist" touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" $(INSTALLED_PYTHONAPP): install_Python Modified: python/branches/py3k-issue1717/Mac/PythonLauncher/Info.plist.in ============================================================================== --- python/branches/py3k-issue1717/Mac/PythonLauncher/Info.plist.in (original) +++ python/branches/py3k-issue1717/Mac/PythonLauncher/Info.plist.in Fri Jan 2 15:30:39 2009 @@ -40,7 +40,7 @@ CFBundleExecutable PythonLauncher CFBundleGetInfoString - %VERSION%, ?? 001-2006 Python Software Foundation + %VERSION%, ?? 2001-2008 Python Software Foundation CFBundleIconFile PythonLauncher.icns CFBundleIdentifier Modified: python/branches/py3k-issue1717/Mac/PythonLauncher/Makefile.in ============================================================================== --- python/branches/py3k-issue1717/Mac/PythonLauncher/Makefile.in (original) +++ python/branches/py3k-issue1717/Mac/PythonLauncher/Makefile.in Fri Jan 2 15:30:39 2009 @@ -19,13 +19,63 @@ MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ @EXPORT_MACOSX_DEPLOYMENT_TARGET at export MACOSX_DEPLOYMENT_TARGET -BUNDLEBULDER=$(srcdir)/../../Lib/plat-mac/bundlebuilder.py +BUNDLEBULDER=$(srcdir)/../Tools/bundlebuilder.py PYTHONAPPSDIR=/Applications/$(PYTHONFRAMEWORK) $(VERSION) OBJECTS=FileSettings.o MyAppDelegate.o MyDocument.o PreferencesWindowController.o doscript.o main.o -install: +install: Python\ Launcher.app test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" + + +clean: + rm -f *.o "Python Launcher" + rm -rf "Python Launcher.app" + +Python\ Launcher.app: Info.plist \ + Python\ Launcher $(srcdir)/../Icons/PythonLauncher.icns \ + $(srcdir)/../Icons/PythonSource.icns \ + $(srcdir)/../Icons/PythonCompiled.icns \ + $(srcdir)/factorySettings.plist + rm -fr "Python Launcher.app" + $(RUNSHARED) $(BUILDPYTHON) $(BUNDLEBULDER) \ + --builddir=. \ + --name="Python Launcher" \ + --executable="Python Launcher" \ + --iconfile=$(srcdir)/../Icons/PythonLauncher.icns \ + --bundle-id=org.python.PythonLauncher \ + --resource=$(srcdir)/../Icons/PythonSource.icns \ + --resource=$(srcdir)/../Icons/PythonCompiled.icns \ + --resource=$(srcdir)/English.lproj \ + --resource=$(srcdir)/factorySettings.plist \ + --plist Info.plist \ + build + find "Python Launcher.app" -name '.svn' -print0 | xargs -0 rm -r + + +FileSettings.o: $(srcdir)/FileSettings.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/FileSettings.m + +MyAppDelegate.o: $(srcdir)/MyAppDelegate.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/MyAppDelegate.m + +MyDocument.o: $(srcdir)/MyDocument.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/MyDocument.m + +PreferencesWindowController.o: $(srcdir)/PreferencesWindowController.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/PreferencesWindowController.m + +doscript.o: $(srcdir)/doscript.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/doscript.m + +main.o: $(srcdir)/main.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/main.m + +Python\ Launcher: $(OBJECTS) + $(CC) $(LDFLAGS) -o "Python Launcher" $(OBJECTS) -framework AppKit -framework Carbon + +Info.plist: $(srcdir)/Info.plist.in + sed 's/%VERSION%/'"`$(RUNSHARED) $(BUILDPYTHON) -c 'import platform; print(platform.python_version())'`"'/g' < $(srcdir)/Info.plist.in > Info.plist Modified: python/branches/py3k-issue1717/Mac/Tools/fixapplepython23.py ============================================================================== --- python/branches/py3k-issue1717/Mac/Tools/fixapplepython23.py (original) +++ python/branches/py3k-issue1717/Mac/Tools/fixapplepython23.py Fri Jan 2 15:30:39 2009 @@ -14,7 +14,7 @@ """ import sys import os -import gestalt as _gestalt +import platform MAKEFILE='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/Makefile' CHANGES=(( @@ -99,11 +99,12 @@ print("fixapplypython23: no fix is needed on MacOSX on Intel") sys.exit(0) - if gestalt.gestalt('sysv') < 0x1030: + osver = platform.mac_ver() + if osver != '10.3' and os.ver < '10.3.': print('fixapplepython23: no fix needed on MacOSX < 10.3') sys.exit(0) - if gestalt.gestalt('sysv') >= 0x1040: + if osver >= '10.4': print('fixapplepython23: no fix needed on MacOSX >= 10.4') sys.exit(0) Modified: python/branches/py3k-issue1717/Makefile.pre.in ============================================================================== --- python/branches/py3k-issue1717/Makefile.pre.in (original) +++ python/branches/py3k-issue1717/Makefile.pre.in Fri Jan 2 15:30:39 2009 @@ -899,7 +899,7 @@ export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \ export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \ export EXE; EXE="$(BUILDEXE)"; \ - cd $(srcdir)/Lib/$(PLATDIR); ./regen + cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen # Install the include files INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY) Modified: python/branches/py3k-issue1717/Misc/NEWS ============================================================================== --- python/branches/py3k-issue1717/Misc/NEWS (original) +++ python/branches/py3k-issue1717/Misc/NEWS Fri Jan 2 15:30:39 2009 @@ -19,6 +19,24 @@ The tp_compare slot is reserved for future usage. A type definition with an assigned tp_compare slot will raise a TypeError. +- Issue #4747: When the terminal does not use utf-8, executing a script with + non-ascii characters in its name could fail with a "SyntaxError: None" error. + +- Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open + file with `bytes' filename on Windows. + +- Issue #3680: Reference cycles created through a dict, set or deque iterator + did not get collected. + +- Issue #4701: PyObject_Hash now implicitly calls PyType_Ready on types + where the tp_hash and tp_dict slots are both NULL. + +- Issue #4759: None is now allowed as the first argument of + bytearray.translate(). It was always allowed for bytes.translate(). + +- Added test case to ensure attempts to read from a file opened for writing + fail. + - Issue #3106: Speedup some comparisons (str/str and int/int). - Issue #2183: Simplify and optimize bytecode for list, dict and set @@ -60,9 +78,30 @@ - Issue #4569: Interpreter crash when mutating a memoryview with an item size larger than 1. +- Issue #4748: Lambda generators no longer return a value. + Library ------- +- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case + no MSVC compiler is found under Windows. Original patch by Philip Jenvey. + +- Issue #4646: distutils was choking on empty options arg in the setup + function. Original patch by Thomas Heller. + +- Issue #3767: Convert Tk object to string in tkColorChooser. + +- Issue #3248: Allow placing ScrolledText in a PanedWindow. + +- Issue #4444: Allow assertRaises() to be used as a context handler, so that + the code under test can be written inline if more practical. + +- Issue #4739: Add pydoc help topics for symbols, so that e.g. help('@') + works as expected in the interactive environment. + +- Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by + Gabriel Genellina. + - Issue #4574: reading an UTF16-encoded text file crashes if \r on 64-char boundary. @@ -135,9 +174,16 @@ support unusual filenames (such as those containing semi-colons) in Content-Disposition headers. +Tools/Demos +----------- + +- Issue #4677: add two list comprehension tests to pybench. + Extension Modules ----------------- +- Issue #1040026: Fix os.times result on systems where HZ is incorrect. + - Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris, OpenBSD. Modified: python/branches/py3k-issue1717/Misc/developers.txt ============================================================================== --- python/branches/py3k-issue1717/Misc/developers.txt (original) +++ python/branches/py3k-issue1717/Misc/developers.txt Fri Jan 2 15:30:39 2009 @@ -17,6 +17,9 @@ Permissions History ------------------- +- Tarek Ziad? as given SVN access on Decmeber 21 2008 by NCN, + for maintenance of distutils. + - Hirokazu Yamamoto was given SVN access on August 12 2008 by MvL, for contributions to the Windows build. Modified: python/branches/py3k-issue1717/Modules/_collectionsmodule.c ============================================================================== --- python/branches/py3k-issue1717/Modules/_collectionsmodule.c (original) +++ python/branches/py3k-issue1717/Modules/_collectionsmodule.c Fri Jan 2 15:30:39 2009 @@ -900,7 +900,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequeiter_type); + it = PyObject_GC_New(dequeiterobject, &dequeiter_type); if (it == NULL) return NULL; it->b = deque->leftblock; @@ -909,14 +909,22 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } +static int +dequeiter_traverse(dequeiterobject *dio, visitproc visit, void *arg) +{ + Py_VISIT(dio->deque); + return 0; +} + static void dequeiter_dealloc(dequeiterobject *dio) { Py_XDECREF(dio->deque); - Py_TYPE(dio)->tp_free(dio); + PyObject_GC_Del(dio); } static PyObject * @@ -981,9 +989,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -1002,7 +1010,7 @@ { dequeiterobject *it; - it = PyObject_New(dequeiterobject, &dequereviter_type); + it = PyObject_GC_New(dequeiterobject, &dequereviter_type); if (it == NULL) return NULL; it->b = deque->rightblock; @@ -1011,6 +1019,7 @@ it->deque = deque; it->state = deque->state; it->counter = deque->len; + _PyObject_GC_TRACK(it); return (PyObject *)it; } @@ -1063,9 +1072,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dequeiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/branches/py3k-issue1717/Modules/_fileio.c ============================================================================== --- python/branches/py3k-issue1717/Modules/_fileio.c (original) +++ python/branches/py3k-issue1717/Modules/_fileio.c Fri Jan 2 15:30:39 2009 @@ -116,7 +116,7 @@ directories, so we need a check. */ static int -dircheck(PyFileIOObject* self) +dircheck(PyFileIOObject* self, char *name) { #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) struct stat buf; @@ -128,8 +128,8 @@ if (internal_close(self)) return -1; - exc = PyObject_CallFunction(PyExc_IOError, "(is)", - EISDIR, msg); + exc = PyObject_CallFunction(PyExc_IOError, "(iss)", + EISDIR, msg, name); PyErr_SetObject(PyExc_IOError, exc); Py_XDECREF(exc); return -1; @@ -284,13 +284,14 @@ Py_END_ALLOW_THREADS if (self->fd < 0) { #ifdef MS_WINDOWS - PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename); -#else - PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); + if (widename != NULL) + PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename); + else #endif + PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); goto error; } - if(dircheck(self) < 0) + if(dircheck(self, name) < 0) goto error; } Modified: python/branches/py3k-issue1717/Modules/_pickle.c ============================================================================== --- python/branches/py3k-issue1717/Modules/_pickle.c (original) +++ python/branches/py3k-issue1717/Modules/_pickle.c Fri Jan 2 15:30:39 2009 @@ -1109,16 +1109,21 @@ static const char *hexdigits = "0123456789abcdef"; #ifdef Py_UNICODE_WIDE - repr = PyBytes_FromStringAndSize(NULL, 10 * size); + const Py_ssize_t expandsize = 10; #else - repr = PyBytes_FromStringAndSize(NULL, 6 * size); + const Py_ssize_t expandsize = 6; #endif + + if (size > PY_SSIZE_T_MAX / expandsize) + return PyErr_NoMemory(); + + repr = PyByteArray_FromStringAndSize(NULL, expandsize * size); if (repr == NULL) return NULL; if (size == 0) goto done; - p = q = PyBytes_AS_STRING(repr); + p = q = PyByteArray_AS_STRING(repr); while (size-- > 0) { Py_UNICODE ch = *s++; #ifdef Py_UNICODE_WIDE @@ -1136,6 +1141,32 @@ *p++ = hexdigits[ch & 15]; } else +#else + /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */ + if (ch >= 0xD800 && ch < 0xDC00) { + Py_UNICODE ch2; + Py_UCS4 ucs; + + ch2 = *s++; + size--; + if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { + ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000; + *p++ = '\\'; + *p++ = 'U'; + *p++ = hexdigits[(ucs >> 28) & 0xf]; + *p++ = hexdigits[(ucs >> 24) & 0xf]; + *p++ = hexdigits[(ucs >> 20) & 0xf]; + *p++ = hexdigits[(ucs >> 16) & 0xf]; + *p++ = hexdigits[(ucs >> 12) & 0xf]; + *p++ = hexdigits[(ucs >> 8) & 0xf]; + *p++ = hexdigits[(ucs >> 4) & 0xf]; + *p++ = hexdigits[ucs & 0xf]; + continue; + } + /* Fall through: isolated surrogates are copied as-is */ + s--; + size++; + } #endif /* Map 16-bit characters to '\uxxxx' */ if (ch >= 256 || ch == '\\' || ch == '\n') { @@ -1146,14 +1177,14 @@ *p++ = hexdigits[(ch >> 4) & 0xf]; *p++ = hexdigits[ch & 15]; } - /* Copy everything else as-is */ + /* Copy everything else as-is */ else *p++ = (char) ch; } size = p - q; done: - result = PyBytes_FromStringAndSize(PyBytes_AS_STRING(repr), size); + result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(repr), size); Py_DECREF(repr); return result; } Modified: python/branches/py3k-issue1717/Modules/_testcapimodule.c ============================================================================== --- python/branches/py3k-issue1717/Modules/_testcapimodule.c (original) +++ python/branches/py3k-issue1717/Modules/_testcapimodule.c Fri Jan 2 15:30:39 2009 @@ -175,6 +175,105 @@ } +/* Issue #4701: Check that PyObject_Hash implicitly calls + * PyType_Ready if it hasn't already been called + */ +static PyTypeObject _HashInheritanceTester_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "hashinheritancetester", /* Name of this type */ + sizeof(PyObject), /* Basic object size */ + 0, /* Item size for varobject */ + (destructor)PyObject_Del, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +static PyObject* +test_lazy_hash_inheritance(PyObject* self) +{ + PyTypeObject *type; + PyObject *obj; + long hash; + + type = &_HashInheritanceTester_Type; + obj = PyObject_New(PyObject, type); + if (obj == NULL) { + PyErr_Clear(); + PyErr_SetString( + TestError, + "test_lazy_hash_inheritance: failed to create object"); + return NULL; + } + + if (type->tp_dict != NULL) { + PyErr_SetString( + TestError, + "test_lazy_hash_inheritance: type initialised too soon"); + Py_DECREF(obj); + return NULL; + } + + hash = PyObject_Hash(obj); + if ((hash == -1) && PyErr_Occurred()) { + PyErr_Clear(); + PyErr_SetString( + TestError, + "test_lazy_hash_inheritance: could not hash object"); + Py_DECREF(obj); + return NULL; + } + + if (type->tp_dict == NULL) { + PyErr_SetString( + TestError, + "test_lazy_hash_inheritance: type not initialised by hash()"); + Py_DECREF(obj); + return NULL; + } + + if (type->tp_hash != PyType_Type.tp_hash) { + PyErr_SetString( + TestError, + "test_lazy_hash_inheritance: unexpected hash function"); + Py_DECREF(obj); + return NULL; + } + + Py_RETURN_NONE; +} + + /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG) PyLong_{As, From}{Unsigned,}LongLong(). @@ -508,6 +607,8 @@ Py_RETURN_NONE; } +static volatile int x; + /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case of an error. */ @@ -522,7 +623,6 @@ /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */ /* Just use the macro and check that it compiles */ x = Py_UNICODE_ISSPACE(25); - x = x; tuple = PyTuple_New(1); if (tuple == NULL) @@ -608,6 +708,32 @@ } static PyObject * +test_empty_argparse(PyObject *self) +{ + /* Test that formats can begin with '|'. See issue #4720. */ + PyObject *tuple, *dict = NULL; + static char *kwlist[] = {NULL}; + int result; + tuple = PyTuple_New(0); + if (!tuple) + return NULL; + if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0) + goto done; + dict = PyDict_New(); + if (!dict) + goto done; + result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist); + done: + Py_DECREF(tuple); + Py_XDECREF(dict); + if (result < 0) + return NULL; + else { + Py_RETURN_NONE; + } +} + +static PyObject * codec_incrementalencoder(PyObject *self, PyObject *args) { const char *encoding, *errors = NULL; @@ -1009,9 +1135,11 @@ {"test_config", (PyCFunction)test_config, METH_NOARGS}, {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS}, {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, + {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS}, {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS}, {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, + {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS}, {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, @@ -1211,6 +1339,8 @@ if (m == NULL) return NULL; + Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type; + Py_TYPE(&test_structmembersType)=&PyType_Type; Py_INCREF(&test_structmembersType); PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType); Modified: python/branches/py3k-issue1717/Modules/main.c ============================================================================== --- python/branches/py3k-issue1717/Modules/main.c (original) +++ python/branches/py3k-issue1717/Modules/main.c Fri Jan 2 15:30:39 2009 @@ -600,18 +600,21 @@ } if (sts==-1) { - char cfilename[PATH_MAX]; + PyObject *filenameObj = NULL; char *p_cfilename = ""; if (filename) { - size_t r = wcstombs(cfilename, filename, PATH_MAX); - p_cfilename = cfilename; - if (r == (size_t)-1 || r >= PATH_MAX) + filenameObj = PyUnicode_FromWideChar( + filename, wcslen(filename)); + if (filenameObj != NULL) + p_cfilename = _PyUnicode_AsString(filenameObj); + else p_cfilename = ""; } sts = PyRun_AnyFileExFlags( fp, p_cfilename, filename != NULL, &cf) != 0; + Py_XDECREF(filenameObj); } } Modified: python/branches/py3k-issue1717/Modules/mathmodule.c ============================================================================== --- python/branches/py3k-issue1717/Modules/mathmodule.c (original) +++ python/branches/py3k-issue1717/Modules/mathmodule.c Fri Jan 2 15:30:39 2009 @@ -685,7 +685,10 @@ return NULL; } -PyDoc_STRVAR(math_factorial_doc, "Return n!"); +PyDoc_STRVAR(math_factorial_doc, +"factorial(x) -> Integral\n" +"\n" +"Find x!. Raise a ValueError if x is negative or non-integral."); static PyObject * math_trunc(PyObject *self, PyObject *number) @@ -837,7 +840,7 @@ "modf(x)\n" "\n" "Return the fractional and integer parts of x. Both results carry the sign\n" -"of x. The integer part is returned as a real."); +"of x and are floats."); /* A decent logarithm is easy to compute even for huge longs, but libm can't do that by itself -- loghelper can. func is log or log10, and name is Modified: python/branches/py3k-issue1717/Modules/posixmodule.c ============================================================================== --- python/branches/py3k-issue1717/Modules/posixmodule.c (original) +++ python/branches/py3k-issue1717/Modules/posixmodule.c Fri Jan 2 15:30:39 2009 @@ -4494,10 +4494,6 @@ #ifdef HAVE_TIMES -#ifndef HZ -#define HZ 60 /* Universal constant :-) */ -#endif /* HZ */ - #if defined(PYCC_VACPP) && defined(PYOS_OS2) static long system_uptime(void) @@ -4523,6 +4519,8 @@ (double)system_uptime() / 1000); } #else /* not OS2 */ +#define NEED_TICKS_PER_SECOND +static long ticks_per_second = -1; static PyObject * posix_times(PyObject *self, PyObject *noargs) { @@ -4533,11 +4531,11 @@ if (c == (clock_t) -1) return posix_error(); return Py_BuildValue("ddddd", - (double)t.tms_utime / HZ, - (double)t.tms_stime / HZ, - (double)t.tms_cutime / HZ, - (double)t.tms_cstime / HZ, - (double)c / HZ); + (double)t.tms_utime / ticks_per_second, + (double)t.tms_stime / ticks_per_second, + (double)t.tms_cutime / ticks_per_second, + (double)t.tms_cstime / ticks_per_second, + (double)c / ticks_per_second); } #endif /* not OS2 */ #endif /* HAVE_TIMES */ @@ -7409,6 +7407,15 @@ statvfs_result_desc.name = MODNAME ".statvfs_result"; PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc); +#ifdef NEED_TICKS_PER_SECOND +# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) + ticks_per_second = sysconf(_SC_CLK_TCK); +# elif defined(HZ) + ticks_per_second = HZ; +# else + ticks_per_second = 60; /* magic fallback value; may be bogus */ +# endif +#endif } Py_INCREF((PyObject*) &StatResultType); PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType); Modified: python/branches/py3k-issue1717/Objects/bytearrayobject.c ============================================================================== --- python/branches/py3k-issue1717/Objects/bytearrayobject.c (original) +++ python/branches/py3k-issue1717/Objects/bytearrayobject.c Fri Jan 2 15:30:39 2009 @@ -1371,28 +1371,32 @@ PyObject *input_obj = (PyObject*)self; const char *output_start; Py_ssize_t inlen; - PyObject *result; + PyObject *result = NULL; int trans_table[256]; - PyObject *tableobj, *delobj = NULL; + PyObject *tableobj = NULL, *delobj = NULL; Py_buffer vtable, vdel; if (!PyArg_UnpackTuple(args, "translate", 1, 2, &tableobj, &delobj)) return NULL; - if (_getbuffer(tableobj, &vtable) < 0) + if (tableobj == Py_None) { + table = NULL; + tableobj = NULL; + } else if (_getbuffer(tableobj, &vtable) < 0) { return NULL; - - if (vtable.len != 256) { - PyErr_SetString(PyExc_ValueError, - "translation table must be 256 characters long"); - result = NULL; - goto done; + } else { + if (vtable.len != 256) { + PyErr_SetString(PyExc_ValueError, + "translation table must be 256 characters long"); + goto done; + } + table = (const char*)vtable.buf; } if (delobj != NULL) { if (_getbuffer(delobj, &vdel) < 0) { - result = NULL; + delobj = NULL; /* don't try to release vdel buffer on exit */ goto done; } } @@ -1401,7 +1405,6 @@ vdel.len = 0; } - table = (const char *)vtable.buf; inlen = PyByteArray_GET_SIZE(input_obj); result = PyByteArray_FromStringAndSize((char *)NULL, inlen); if (result == NULL) @@ -1409,7 +1412,7 @@ output_start = output = PyByteArray_AsString(result); input = PyByteArray_AS_STRING(input_obj); - if (vdel.len == 0) { + if (vdel.len == 0 && table != NULL) { /* If no deletions are required, use faster code */ for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); @@ -1417,9 +1420,14 @@ } goto done; } - - for (i = 0; i < 256; i++) - trans_table[i] = Py_CHARMASK(table[i]); + + if (table == NULL) { + for (i = 0; i < 256; i++) + trans_table[i] = Py_CHARMASK(i); + } else { + for (i = 0; i < 256; i++) + trans_table[i] = Py_CHARMASK(table[i]); + } for (i = 0; i < vdel.len; i++) trans_table[(int) Py_CHARMASK( ((unsigned char*)vdel.buf)[i] )] = -1; @@ -1435,7 +1443,8 @@ PyByteArray_Resize(result, output - output_start); done: - PyBuffer_Release(&vtable); + if (tableobj != NULL) + PyBuffer_Release(&vtable); if (delobj != NULL) PyBuffer_Release(&vdel); return result; Modified: python/branches/py3k-issue1717/Objects/bytesobject.c ============================================================================== --- python/branches/py3k-issue1717/Objects/bytesobject.c (original) +++ python/branches/py3k-issue1717/Objects/bytesobject.c Fri Jan 2 15:30:39 2009 @@ -1892,11 +1892,6 @@ del_table = PyBytes_AS_STRING(delobj); dellen = PyBytes_GET_SIZE(delobj); } - else if (PyUnicode_Check(delobj)) { - PyErr_SetString(PyExc_TypeError, - "deletions are implemented differently for unicode"); - return NULL; - } else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen)) return NULL; } Modified: python/branches/py3k-issue1717/Objects/dictobject.c ============================================================================== --- python/branches/py3k-issue1717/Objects/dictobject.c (original) +++ python/branches/py3k-issue1717/Objects/dictobject.c Fri Jan 2 15:30:39 2009 @@ -2122,7 +2122,7 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) { dictiterobject *di; - di = PyObject_New(dictiterobject, itertype); + di = PyObject_GC_New(dictiterobject, itertype); if (di == NULL) return NULL; Py_INCREF(dict); @@ -2139,6 +2139,7 @@ } else di->di_result = NULL; + _PyObject_GC_TRACK(di); return (PyObject *)di; } @@ -2147,7 +2148,15 @@ { Py_XDECREF(di->di_dict); Py_XDECREF(di->di_result); - PyObject_Del(di); + PyObject_GC_Del(di); +} + +static int +dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) +{ + Py_VISIT(di->di_dict); + Py_VISIT(di->di_result); + return 0; } static PyObject * @@ -2228,9 +2237,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2300,9 +2309,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2386,9 +2395,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2415,7 +2424,14 @@ dictview_dealloc(dictviewobject *dv) { Py_XDECREF(dv->dv_dict); - PyObject_Del(dv); + PyObject_GC_Del(dv); +} + +static int +dictview_traverse(dictviewobject *dv, visitproc visit, void *arg) +{ + Py_VISIT(dv->dv_dict); + return 0; } static Py_ssize_t @@ -2442,11 +2458,12 @@ type->tp_name, dict->ob_type->tp_name); return NULL; } - dv = PyObject_New(dictviewobject, type); + dv = PyObject_GC_New(dictviewobject, type); if (dv == NULL) return NULL; Py_INCREF(dict); dv->dv_dict = (PyDictObject *)dict; + _PyObject_GC_TRACK(dv); return (PyObject *)dv; } @@ -2693,9 +2710,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictview_traverse, /* tp_traverse */ 0, /* tp_clear */ dictview_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2777,9 +2794,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictview_traverse, /* tp_traverse */ 0, /* tp_clear */ dictview_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -2842,9 +2859,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)dictview_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ Modified: python/branches/py3k-issue1717/Objects/object.c ============================================================================== --- python/branches/py3k-issue1717/Objects/object.c (original) +++ python/branches/py3k-issue1717/Objects/object.c Fri Jan 2 15:30:39 2009 @@ -344,8 +344,11 @@ if (op == NULL) fprintf(stderr, "NULL\n"); else { + PyGILState_STATE gil; fprintf(stderr, "object : "); + gil = PyGILState_Ensure(); (void)PyObject_Print(op, stderr, 0); + PyGILState_Release(gil); /* XXX(twouters) cast refcount to long until %zd is universally available */ fprintf(stderr, "\n" @@ -724,6 +727,17 @@ PyTypeObject *tp = Py_TYPE(v); if (tp->tp_hash != NULL) return (*tp->tp_hash)(v); + /* To keep to the general practice that inheriting + * solely from object in C code should work without + * an explicit call to PyType_Ready, we implicitly call + * PyType_Ready here and then check the tp_hash slot again + */ + if (tp->tp_dict == NULL) { + if (PyType_Ready(tp) < 0) + return -1; + if (tp->tp_hash != NULL) + return (*tp->tp_hash)(v); + } /* Otherwise, the object can't be hashed */ return PyObject_HashNotImplemented(v); } Modified: python/branches/py3k-issue1717/Objects/setobject.c ============================================================================== --- python/branches/py3k-issue1717/Objects/setobject.c (original) +++ python/branches/py3k-issue1717/Objects/setobject.c Fri Jan 2 15:30:39 2009 @@ -802,7 +802,14 @@ setiter_dealloc(setiterobject *si) { Py_XDECREF(si->si_set); - PyObject_Del(si); + PyObject_GC_Del(si); +} + +static int +setiter_traverse(setiterobject *si, visitproc visit, void *arg) +{ + Py_VISIT(si->si_set); + return 0; } static PyObject * @@ -880,9 +887,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)setiter_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ @@ -895,7 +902,7 @@ static PyObject * set_iter(PySetObject *so) { - setiterobject *si = PyObject_New(setiterobject, &PySetIter_Type); + setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type); if (si == NULL) return NULL; Py_INCREF(so); @@ -903,6 +910,7 @@ si->si_used = so->used; si->si_pos = 0; si->len = so->used; + _PyObject_GC_TRACK(si); return (PyObject *)si; } Modified: python/branches/py3k-issue1717/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k-issue1717/Objects/unicodeobject.c (original) +++ python/branches/py3k-issue1717/Objects/unicodeobject.c Fri Jan 2 15:30:39 2009 @@ -418,7 +418,8 @@ } } -int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length) +static +int _PyUnicode_Resize(PyUnicodeObject **unicode, Py_ssize_t length) { register PyUnicodeObject *v; @@ -427,7 +428,7 @@ PyErr_BadInternalCall(); return -1; } - v = (PyUnicodeObject *)*unicode; + v = *unicode; if (v == NULL || !PyUnicode_Check(v) || Py_REFCNT(v) != 1 || length < 0) { PyErr_BadInternalCall(); return -1; @@ -444,7 +445,7 @@ Py_UNICODE_COPY(w->str, v->str, length < v->length ? length : v->length); Py_DECREF(*unicode); - *unicode = (PyObject *)w; + *unicode = w; return 0; } @@ -453,9 +454,10 @@ return unicode_resize(v, length); } -/* Internal API for use in unicodeobject.c only ! */ -#define _PyUnicode_Resize(unicodevar, length) \ - PyUnicode_Resize(((PyObject **)(unicodevar)), length) +int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length) +{ + return _PyUnicode_Resize((PyUnicodeObject **)unicode, length); +} PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) @@ -989,7 +991,7 @@ PyObject_Free(callresults); if (abuffer) PyObject_Free(abuffer); - _PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string)); + PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string)); return string; fail: if (callresults) { @@ -1549,7 +1551,7 @@ const char *encoding, const char *reason, const char **input, const char **inend, Py_ssize_t *startinpos, Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr, - PyObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr) + PyUnicodeObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr) { static char *argparse = "O!n;decoding error handler must return (str, int) tuple"; @@ -1627,7 +1629,7 @@ if (requiredsize > outsize) { if (requiredsize<2*outsize) requiredsize = 2*outsize; - if (PyUnicode_Resize(output, requiredsize) < 0) + if (_PyUnicode_Resize(output, requiredsize) < 0) goto onError; *outptr = PyUnicode_AS_UNICODE(*output) + *outpos; } @@ -1827,7 +1829,7 @@ errors, &errorHandler, "utf7", errmsg, &starts, &e, &startinpos, &endinpos, &exc, &s, - (PyObject **)&unicode, &outpos, &p)) + &unicode, &outpos, &p)) goto onError; } @@ -1838,7 +1840,7 @@ errors, &errorHandler, "utf7", "unterminated shift sequence", &starts, &e, &startinpos, &endinpos, &exc, &s, - (PyObject **)&unicode, &outpos, &p)) + &unicode, &outpos, &p)) goto onError; if (s < e) goto restart; @@ -1871,7 +1873,7 @@ int encodeWhiteSpace, const char *errors) { - PyObject *v, *result; + PyObject *v; /* It might be possible to tighten this worst case */ Py_ssize_t cbAllocated = 5 * size; int inShift = 0; @@ -1887,11 +1889,11 @@ if (cbAllocated / 5 != size) return PyErr_NoMemory(); - v = PyByteArray_FromStringAndSize(NULL, cbAllocated); + v = PyBytes_FromStringAndSize(NULL, cbAllocated); if (v == NULL) return NULL; - start = out = PyByteArray_AS_STRING(v); + start = out = PyBytes_AS_STRING(v); for (;i < size; ++i) { Py_UNICODE ch = s[i]; @@ -1956,10 +1958,9 @@ *out++= B64(charsleft << (6-bitsleft) ); *out++ = '-'; } - - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), out - start); - Py_DECREF(v); - return result; + if (_PyBytes_Resize(&v, out - start) < 0) + return NULL; + return v; } #undef SPECIAL @@ -2166,7 +2167,7 @@ errors, &errorHandler, "utf8", errmsg, &starts, &e, &startinpos, &endinpos, &exc, &s, - (PyObject **)&unicode, &outpos, &p)) + &unicode, &outpos, &p)) goto onError; } if (consumed) @@ -2446,7 +2447,7 @@ errors, &errorHandler, "utf32", errmsg, &starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q, - (PyObject **)&unicode, &outpos, &p)) + &unicode, &outpos, &p)) goto onError; } @@ -2477,7 +2478,7 @@ const char *errors, int byteorder) { - PyObject *v, *result; + PyObject *v; unsigned char *p; Py_ssize_t nsize, bytesize; #ifndef Py_UNICODE_WIDE @@ -2513,11 +2514,11 @@ bytesize = nsize * 4; if (bytesize / 4 != nsize) return PyErr_NoMemory(); - v = PyByteArray_FromStringAndSize(NULL, bytesize); + v = PyBytes_FromStringAndSize(NULL, bytesize); if (v == NULL) return NULL; - p = (unsigned char *)PyByteArray_AS_STRING(v); + p = (unsigned char *)PyBytes_AS_STRING(v); if (byteorder == 0) STORECHAR(0xFEFF); if (size == 0) @@ -2554,9 +2555,7 @@ } done: - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v)); - Py_DECREF(v); - return result; + return v; #undef STORECHAR } @@ -2724,7 +2723,7 @@ errors, &errorHandler, "utf16", errmsg, &starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q, - (PyObject **)&unicode, &outpos, &p)) + &unicode, &outpos, &p)) goto onError; } @@ -2755,7 +2754,7 @@ const char *errors, int byteorder) { - PyObject *v, *result; + PyObject *v; unsigned char *p; Py_ssize_t nsize, bytesize; #ifdef Py_UNICODE_WIDE @@ -2790,11 +2789,11 @@ bytesize = nsize * 2; if (bytesize / 2 != nsize) return PyErr_NoMemory(); - v = PyByteArray_FromStringAndSize(NULL, bytesize); + v = PyBytes_FromStringAndSize(NULL, bytesize); if (v == NULL) return NULL; - p = (unsigned char *)PyByteArray_AS_STRING(v); + p = (unsigned char *)PyBytes_AS_STRING(v); if (byteorder == 0) STORECHAR(0xFEFF); if (size == 0) @@ -2826,9 +2825,7 @@ } done: - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v)); - Py_DECREF(v); - return result; + return v; #undef STORECHAR } @@ -2949,7 +2946,7 @@ errors, &errorHandler, "unicodeescape", "end of string in escape sequence", &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; goto nextByte; } @@ -2961,7 +2958,7 @@ errors, &errorHandler, "unicodeescape", message, &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; goto nextByte; } @@ -3000,7 +2997,7 @@ errors, &errorHandler, "unicodeescape", "illegal Unicode character", &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; } break; @@ -3042,7 +3039,7 @@ errors, &errorHandler, "unicodeescape", message, &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; break; @@ -3056,7 +3053,7 @@ errors, &errorHandler, "unicodeescape", message, &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; } else { @@ -3118,7 +3115,7 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size) { - PyObject *repr, *result; + PyObject *repr; char *p; #ifdef Py_UNICODE_WIDE @@ -3145,17 +3142,20 @@ escape. */ + if (size == 0) + return PyBytes_FromStringAndSize(NULL, 0); + if (size > (PY_SSIZE_T_MAX - 2 - 1) / expandsize) return PyErr_NoMemory(); - repr = PyByteArray_FromStringAndSize(NULL, + repr = PyBytes_FromStringAndSize(NULL, 2 + expandsize*size + 1); if (repr == NULL) return NULL; - p = PyByteArray_AS_STRING(repr); + p = PyBytes_AS_STRING(repr); while (size-- > 0) { Py_UNICODE ch = *s++; @@ -3247,28 +3247,22 @@ *p++ = (char) ch; } - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(repr), - p - PyByteArray_AS_STRING(repr)); - Py_DECREF(repr); - return result; + assert(p - PyBytes_AS_STRING(repr) > 0); + if (_PyBytes_Resize(&repr, p - PyBytes_AS_STRING(repr)) < 0) + return NULL; + return repr; } PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode) { - PyObject *s, *result; + PyObject *s; if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); return NULL; } s = PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode)); - - if (!s) - return NULL; - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(s), - PyByteArray_GET_SIZE(s)); - Py_DECREF(s); - return result; + return s; } /* --- Raw Unicode Escape Codec ------------------------------------------- */ @@ -3339,7 +3333,7 @@ errors, &errorHandler, "rawunicodeescape", "truncated \\uXXXX", &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; goto nextByte; } @@ -3371,7 +3365,7 @@ errors, &errorHandler, "rawunicodeescape", "\\Uxxxxxxxx out of range", &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; } nextByte: @@ -3393,7 +3387,7 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size) { - PyObject *repr, *result; + PyObject *repr; char *p; char *q; @@ -3406,13 +3400,13 @@ if (size > PY_SSIZE_T_MAX / expandsize) return PyErr_NoMemory(); - repr = PyByteArray_FromStringAndSize(NULL, expandsize * size); + repr = PyBytes_FromStringAndSize(NULL, expandsize * size); if (repr == NULL) return NULL; if (size == 0) - goto done; + return repr; - p = q = PyByteArray_AS_STRING(repr); + p = q = PyBytes_AS_STRING(repr); while (size-- > 0) { Py_UNICODE ch = *s++; #ifdef Py_UNICODE_WIDE @@ -3472,15 +3466,15 @@ } size = p - q; - done: - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(repr), size); - Py_DECREF(repr); - return result; + assert(size > 0); + if (_PyBytes_Resize(&repr, size) < 0) + return NULL; + return repr; } PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode) { - PyObject *s, *result; + PyObject *s; if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); return NULL; @@ -3488,12 +3482,7 @@ s = PyUnicode_EncodeRawUnicodeEscape(PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode)); - if (!s) - return NULL; - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(s), - PyByteArray_GET_SIZE(s)); - Py_DECREF(s); - return result; + return s; } /* --- Unicode Internal Codec ------------------------------------------- */ @@ -3551,7 +3540,7 @@ errors, &errorHandler, "unicode_internal", reason, &starts, &end, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) { + &v, &outpos, &p)) { goto onError; } } @@ -3715,7 +3704,6 @@ const char *reason = (limit == 256) ? "ordinal not in range(256)" : "ordinal not in range(128)"; PyObject *errorHandler = NULL; PyObject *exc = NULL; - PyObject *result = NULL; /* the following variable is used for caching string comparisons * -1=not initialized, 0=unknown, 1=strict, 2=replace, 3=ignore, 4=xmlcharrefreplace */ int known_errorHandler = -1; @@ -3724,10 +3712,10 @@ replacements, if we need more, we'll resize */ if (size == 0) return PyBytes_FromStringAndSize(NULL, 0); - res = PyByteArray_FromStringAndSize(NULL, size); + res = PyBytes_FromStringAndSize(NULL, size); if (res == NULL) return NULL; - str = PyByteArray_AS_STRING(res); + str = PyBytes_AS_STRING(res); ressize = size; while (p ressize) { if (requiredsize<2*ressize) requiredsize = 2*ressize; - if (PyByteArray_Resize(res, requiredsize)) + if (_PyBytes_Resize(&res, requiredsize)) goto onError; - str = PyByteArray_AS_STRING(res) + respos; + str = PyBytes_AS_STRING(res) + respos; ressize = requiredsize; } /* generate replacement (temporarily (mis)uses p) */ @@ -3824,17 +3812,17 @@ /* need more space? (at least enough for what we have+the replacement+the rest of the string, so we won't have to check space for encodable characters) */ - respos = str - PyByteArray_AS_STRING(res); + respos = str - PyBytes_AS_STRING(res); repsize = PyUnicode_GET_SIZE(repunicode); requiredsize = respos+repsize+(endp-collend); if (requiredsize > ressize) { if (requiredsize<2*ressize) requiredsize = 2*ressize; - if (PyByteArray_Resize(res, requiredsize)) { + if (_PyBytes_Resize(&res, requiredsize)) { Py_DECREF(repunicode); goto onError; } - str = PyByteArray_AS_STRING(res) + respos; + str = PyBytes_AS_STRING(res) + respos; ressize = requiredsize; } /* check if there is anything unencodable in the replacement @@ -3854,13 +3842,23 @@ } } } - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(res), - str - PyByteArray_AS_STRING(res)); + /* Resize if we allocated to much */ + size = str - PyBytes_AS_STRING(res); + if (size < ressize) { /* If this falls res will be NULL */ + assert(size >= 0); + if (_PyBytes_Resize(&res, size) < 0) + goto onError; + } + + Py_XDECREF(errorHandler); + Py_XDECREF(exc); + return res; + onError: - Py_DECREF(res); + Py_XDECREF(res); Py_XDECREF(errorHandler); Py_XDECREF(exc); - return result; + return NULL; } PyObject *PyUnicode_EncodeLatin1(const Py_UNICODE *p, @@ -3924,7 +3922,7 @@ errors, &errorHandler, "ascii", "ordinal not in range(128)", &starts, &e, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) + &v, &outpos, &p)) goto onError; } } @@ -4225,7 +4223,7 @@ errors, &errorHandler, "charmap", "character maps to ", &starts, &e, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) { + &v, &outpos, &p)) { goto onError; } continue; @@ -4275,7 +4273,7 @@ errors, &errorHandler, "charmap", "character maps to ", &starts, &e, &startinpos, &endinpos, &exc, &s, - (PyObject **)&v, &outpos, &p)) { + &v, &outpos, &p)) { Py_DECREF(x); goto onError; } @@ -4843,7 +4841,8 @@ /* Resize if we allocated to much */ if (resposu->u_argcount = asdl_seq_LEN(args->args); c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs); VISIT_IN_SCOPE(c, expr, e->v.Lambda.body); - ADDOP_IN_SCOPE(c, RETURN_VALUE); + if (c->u->u_ste->ste_generator) { + ADDOP_IN_SCOPE(c, POP_TOP); + } + else { + ADDOP_IN_SCOPE(c, RETURN_VALUE); + } co = assemble(c, 1); compiler_exit_scope(c); if (co == NULL) Modified: python/branches/py3k-issue1717/Python/getargs.c ============================================================================== --- python/branches/py3k-issue1717/Python/getargs.c (original) +++ python/branches/py3k-issue1717/Python/getargs.c Fri Jan 2 15:30:39 2009 @@ -1392,7 +1392,7 @@ Py_ssize_t count; PyBufferProcs *pb = arg->ob_type->tp_as_buffer; if (pb == NULL) { - *errmsg = "string or buffer"; + *errmsg = "bytes or buffer"; return -1; } if (pb->bf_getbuffer) { @@ -1649,7 +1649,7 @@ } } - if (!IS_END_OF_FORMAT(*format)) { + if (!IS_END_OF_FORMAT(*format) && *format != '|') { PyErr_Format(PyExc_RuntimeError, "more argument specifiers than keyword list entries " "(remaining format:'%s')", format); Modified: python/branches/py3k-issue1717/Tools/pybench/Lists.py ============================================================================== --- python/branches/py3k-issue1717/Tools/pybench/Lists.py (original) +++ python/branches/py3k-issue1717/Tools/pybench/Lists.py Fri Jan 2 15:30:39 2009 @@ -293,3 +293,58 @@ for i in range(self.rounds): pass + +class SimpleListComprehensions(Test): + + version = 2.0 + operations = 6 + rounds = 20000 + + def test(self): + + n = list(range(10)) * 10 + + for i in range(self.rounds): + l = [x for x in n] + l = [x for x in n if x] + l = [x for x in n if not x] + + l = [x for x in n] + l = [x for x in n if x] + l = [x for x in n if not x] + + def calibrate(self): + + n = list(range(10)) * 10 + + for i in range(self.rounds): + pass + +class NestedListComprehensions(Test): + + version = 2.0 + operations = 6 + rounds = 20000 + + def test(self): + + m = list(range(10)) + n = list(range(10)) + + for i in range(self.rounds): + l = [x for x in n for y in m] + l = [y for x in n for y in m] + + l = [x for x in n for y in m if y] + l = [y for x in n for y in m if x] + + l = [x for x in n for y in m if not y] + l = [y for x in n for y in m if not x] + + def calibrate(self): + + m = list(range(10)) + n = list(range(10)) + + for i in range(self.rounds): + pass Modified: python/branches/py3k-issue1717/setup.py ============================================================================== --- python/branches/py3k-issue1717/setup.py (original) +++ python/branches/py3k-issue1717/setup.py Fri Jan 2 15:30:39 2009 @@ -208,7 +208,8 @@ if missing: print() - print("Failed to find the necessary bits to build these modules:") + print("Python build finished, but the necessary bits to build " + "these modules were not found:") print_three_column(missing) print("To find the necessary bits, look in setup.py in" " detect_modules() for the module's name.") From python-checkins at python.org Fri Jan 2 15:46:19 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 15:46:19 +0100 (CET) Subject: [Python-checkins] r68158 - in python/trunk: Lib/plat-mac/videoreader.py Misc/NEWS Message-ID: <20090102144619.7431B1E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 15:46:19 2009 New Revision: 68158 Log: Fix for issue 900949 Modified: python/trunk/Lib/plat-mac/videoreader.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/plat-mac/videoreader.py ============================================================================== --- python/trunk/Lib/plat-mac/videoreader.py (original) +++ python/trunk/Lib/plat-mac/videoreader.py Fri Jan 2 15:46:19 2009 @@ -238,12 +238,12 @@ width = self.videodescr['width'] height = self.videodescr['height'] start = 0 - rv = '' + rv = [] for i in range(height): nextline = Qdoffs.GetPixMapBytes(self.pixmap, start, width*4) start = start + rowbytes - rv = rv + nextline - return rv + rv.append(nextline) + return ''.join(rv) def reader(url): try: @@ -255,9 +255,9 @@ def _test(): import EasyDialogs try: - import img + from PIL import Image except ImportError: - img = None + Image = None import MacOS Qt.EnterMovies() path = EasyDialogs.AskFileForOpen(message='Video to convert') @@ -277,13 +277,11 @@ fname = 'frame%04.4d.jpg'%num num = num+1 pname = os.path.join(dstdir, fname) - if not img: print 'Not', + if not Image: print 'Not', print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data)) - if img: - wrt = img.writer(imgfmt, pname) - wrt.width = imgw - wrt.height = imgh - wrt.write(data) + if Image: + img = Image.fromstring("RGBA", (imgw, imgh), data) + img.save(pname, 'JPEG') timestamp, data = rdr.ReadVideo() MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG') if num > 20: Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 15:46:19 2009 @@ -227,6 +227,9 @@ - Issue #1594: MacOS.GetCreatorAndType now always returns a big-endian result, to be consistent with Apple tools. +- Issue #900949: plat-mac/videoreader.py no longer relies on a non-existing + module. + Tools/Demos ----------- From python-checkins at python.org Fri Jan 2 15:48:18 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 15:48:18 +0100 (CET) Subject: [Python-checkins] r68159 - in python/trunk: Lib/plat-mac/videoreader.py Misc/NEWS Message-ID: <20090102144818.56B211E405A@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 15:48:17 2009 New Revision: 68159 Log: Fix for issue 1627952 Modified: python/trunk/Lib/plat-mac/videoreader.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/plat-mac/videoreader.py ============================================================================== --- python/trunk/Lib/plat-mac/videoreader.py (original) +++ python/trunk/Lib/plat-mac/videoreader.py Fri Jan 2 15:48:17 2009 @@ -18,7 +18,7 @@ from Carbon import QDOffscreen from Carbon import Res try: - import MediaDescr + from Carbon import MediaDescr except ImportError: def _audiodescr(data): return None Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 15:48:17 2009 @@ -230,6 +230,8 @@ - Issue #900949: plat-mac/videoreader.py no longer relies on a non-existing module. +- Issue #16278952: plat-mac/videoreader.py now correctly imports MediaDescr + Tools/Demos ----------- From python-checkins at python.org Fri Jan 2 15:52:09 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 15:52:09 +0100 (CET) Subject: [Python-checkins] r68160 - in python/trunk: Lib/plat-mac/EasyDialogs.py Misc/NEWS Message-ID: <20090102145209.9D1DF1E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 15:52:09 2009 New Revision: 68160 Log: Fix for issue r1737832 Modified: python/trunk/Lib/plat-mac/EasyDialogs.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/plat-mac/EasyDialogs.py ============================================================================== --- python/trunk/Lib/plat-mac/EasyDialogs.py (original) +++ python/trunk/Lib/plat-mac/EasyDialogs.py Fri Jan 2 15:52:09 2009 @@ -573,7 +573,7 @@ del d def _process_Nav_args(dftflags, **args): - import aepack + import Carbon.AppleEvents import Carbon.AE import Carbon.File for k in args.keys(): @@ -585,11 +585,14 @@ if args.has_key('defaultLocation') and \ not isinstance(args['defaultLocation'], Carbon.AE.AEDesc): defaultLocation = args['defaultLocation'] - if isinstance(defaultLocation, (Carbon.File.FSSpec, Carbon.File.FSRef)): - args['defaultLocation'] = aepack.pack(defaultLocation) + if isinstance(defaultLocation, Carbon.File.FSSpec): + args['defaultLocation'] = Carbon.AE.AECreateDesc( + Carbon.AppleEvents.typeFSS, defaultLocation.data) else: - defaultLocation = Carbon.File.FSRef(defaultLocation) - args['defaultLocation'] = aepack.pack(defaultLocation) + if not isinstance(defaultLocation, Carbon.File.FSRef): + defaultLocation = Carbon.File.FSRef(defaultLocation) + args['defaultLocation'] = Carbon.AE.AECreateDesc( + Carbon.AppleEvents.typeFSRef, defaultLocation.data) if args.has_key('typeList') and not isinstance(args['typeList'], Carbon.Res.ResourceType): typeList = args['typeList'][:] # Workaround for OSX typeless files: Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 15:52:09 2009 @@ -232,6 +232,9 @@ - Issue #16278952: plat-mac/videoreader.py now correctly imports MediaDescr +- Issue #1737832 : plat-mac/EasyDialog.py no longer uses the broken aepack + module. + Tools/Demos ----------- From python-checkins at python.org Fri Jan 2 16:00:06 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 16:00:06 +0100 (CET) Subject: [Python-checkins] r68161 - in python/trunk: Lib/plat-mac/macostools.py Misc/NEWS Message-ID: <20090102150006.34DAC1E4002@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 16:00:05 2009 New Revision: 68161 Log: Fix for issue 1149804 Modified: python/trunk/Lib/plat-mac/macostools.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/plat-mac/macostools.py ============================================================================== --- python/trunk/Lib/plat-mac/macostools.py (original) +++ python/trunk/Lib/plat-mac/macostools.py Fri Jan 2 16:00:05 2009 @@ -62,7 +62,14 @@ if os.sep == ':' and not ':' in head: head = head + ':' mkdirs(head) - os.mkdir(dst, 0777) + + try: + os.mkdir(dst, 0777) + except OSError, e: + # be happy if someone already created the path + if e.errno != errno.EEXIST: + raise + def touched(dst): """Tell the finder a file has changed. No-op on MacOSX.""" Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 16:00:05 2009 @@ -235,6 +235,9 @@ - Issue #1737832 : plat-mac/EasyDialog.py no longer uses the broken aepack module. +- Issue #1149804: macostools.mkdirs now even works when another process + creates one of the needed subdirectories. + Tools/Demos ----------- From python-checkins at python.org Fri Jan 2 16:06:00 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 16:06:00 +0100 (CET) Subject: [Python-checkins] r68162 - python/trunk/Makefile.pre.in Message-ID: <20090102150600.7D0A91E401E@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 16:06:00 2009 New Revision: 68162 Log: Fix for issue 4472 is incompatible with Cygwin, this patch should fix that. Modified: python/trunk/Makefile.pre.in Modified: python/trunk/Makefile.pre.in ============================================================================== --- python/trunk/Makefile.pre.in (original) +++ python/trunk/Makefile.pre.in Fri Jan 2 16:06:00 2009 @@ -773,8 +773,8 @@ done $(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE) if test -f $(LDLIBRARY); then \ - if test "$(SO)" = .dll; then \ - $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(BINDIR); \ + if test -n "$(DLLLIBRARY)" ; then \ + $(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \ else \ $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ if test $(LDLIBRARY) != $(INSTSONAME); then \ From python-checkins at python.org Fri Jan 2 16:25:36 2009 From: python-checkins at python.org (ronald.oussoren) Date: Fri, 2 Jan 2009 16:25:36 +0100 (CET) Subject: [Python-checkins] r68163 - in python/trunk: Lib/plat-mac/bundlebuilder.py Misc/NEWS Message-ID: <20090102152536.73A901E402B@bag.python.org> Author: ronald.oussoren Date: Fri Jan 2 16:25:36 2009 New Revision: 68163 Log: Fix for issues #841800 and #900506 Modified: python/trunk/Lib/plat-mac/bundlebuilder.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/plat-mac/bundlebuilder.py ============================================================================== --- python/trunk/Lib/plat-mac/bundlebuilder.py (original) +++ python/trunk/Lib/plat-mac/bundlebuilder.py Fri Jan 2 16:25:36 2009 @@ -245,14 +245,14 @@ del sys.path[1:] # sys.path[0] is Contents/Resources/ """ -if USE_ZIPIMPORT: - ZIP_ARCHIVE = "Modules.zip" - SITE_PY += "sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE - def getPycData(fullname, code, ispkg): - if ispkg: - fullname += ".__init__" - path = fullname.replace(".", os.sep) + PYC_EXT - return path, MAGIC + '\0\0\0\0' + marshal.dumps(code) +ZIP_ARCHIVE = "Modules.zip" +SITE_PY_ZIP = SITE_PY + ("sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE) + +def getPycData(fullname, code, ispkg): + if ispkg: + fullname += ".__init__" + path = fullname.replace(".", os.sep) + PYC_EXT + return path, MAGIC + '\0\0\0\0' + marshal.dumps(code) # # Extension modules can't be in the modules zip archive, so a placeholder @@ -301,6 +301,9 @@ libdir = os.path.join(os.path.dirname(execdir), "Frameworks") mainprogram = os.path.join(resdir, "%(mainprogram)s") +if %(optimize)s: + sys.argv.insert(1, '-O') + sys.argv.insert(1, mainprogram) if %(standalone)s or %(semi_standalone)s: os.environ["PYTHONPATH"] = resdir @@ -311,6 +314,7 @@ if pypath: pypath = ":" + pypath os.environ["PYTHONPATH"] = resdir + pypath + os.environ["PYTHONEXECUTABLE"] = executable os.environ["DYLD_LIBRARY_PATH"] = libdir os.environ["DYLD_FRAMEWORK_PATH"] = libdir @@ -350,6 +354,8 @@ class AppBuilder(BundleBuilder): + use_zipimport = USE_ZIPIMPORT + # Override type of the bundle. type = "APPL" @@ -506,6 +512,7 @@ hashbang = os.path.realpath(sys.executable) standalone = self.standalone semi_standalone = self.semi_standalone + optimize = sys.flags.optimize open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals()) os.chmod(bootstrappath, 0775) @@ -552,13 +559,14 @@ self.files.append((src, dst)) def _getSiteCode(self): - return compile(SITE_PY % {"semi_standalone": self.semi_standalone}, + if self.use_zipimport: + return compile(SITE_PY % {"semi_standalone": self.semi_standalone}, "<-bundlebuilder.py->", "exec") def addPythonModules(self): self.message("Adding Python modules", 1) - if USE_ZIPIMPORT: + if self.use_zipimport: # Create a zip file containing all modules as pyc. import zipfile relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE) @@ -624,7 +632,7 @@ self.message("Finding module dependencies", 1) import modulefinder mf = modulefinder.ModuleFinder(excludes=self.excludeModules) - if USE_ZIPIMPORT: + if self.use_zipimport: # zipimport imports zlib, must add it manually mf.import_hook("zlib") # manually add our own site.py @@ -658,7 +666,7 @@ filename = os.path.basename(path) pathitems = name.split(".")[:-1] + [filename] dstpath = pathjoin(*pathitems) - if USE_ZIPIMPORT: + if self.use_zipimport: if name != "zlib": # neatly pack all extension modules in a subdirectory, # except zlib, since it's neccesary for bootstrapping. @@ -672,9 +680,9 @@ self.files.append((path, pathjoin("Contents", "Resources", dstpath))) if mod.__code__ is not None: ispkg = mod.__path__ is not None - if not USE_ZIPIMPORT or name != "site": + if not self.use_zipimport or name != "site": # Our site.py is doing the bootstrapping, so we must - # include a real .pyc file if USE_ZIPIMPORT is True. + # include a real .pyc file if self.use_zipimport is True. self.pymodules.append((name, mod.__code__, ispkg)) if hasattr(mf, "any_missing_maybe"): @@ -820,6 +828,7 @@ --semi-standalone build a standalone application, which depends on an installed Python, yet includes all third-party modules. + --no-zipimport Do not copy code into a zip file --python=FILE Python to use in #! line in stead of current Python --lib=FILE shared library or framework to be copied into the bundle @@ -847,7 +856,9 @@ "mainprogram=", "creator=", "nib=", "plist=", "link", "link-exec", "help", "verbose", "quiet", "argv", "standalone", "exclude=", "include=", "package=", "strip", "iconfile=", - "lib=", "python=", "semi-standalone", "bundle-id=", "destroot=") + "lib=", "python=", "semi-standalone", "bundle-id=", "destroot=" + "no-zipimport" + ) try: options, args = getopt.getopt(sys.argv[1:], shortopts, longopts) @@ -911,6 +922,8 @@ builder.strip = 1 elif opt == '--destroot': builder.destroot = arg + elif opt == '--no-zipimport': + builder.use_zipimport = False if len(args) != 1: usage("Must specify one command ('build', 'report' or 'help')") Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 16:25:36 2009 @@ -238,6 +238,10 @@ - Issue #1149804: macostools.mkdirs now even works when another process creates one of the needed subdirectories. +- Issue #900506: added --no-zipimport flag to the bundlebuilder script + +- Issue #841800: bundlebuilder now works with 'python -O' + Tools/Demos ----------- From buildbot at python.org Fri Jan 2 16:35:46 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 15:35:46 +0000 Subject: [Python-checkins] buildbot failure in sparc Ubuntu 3.x Message-ID: <20090102153546.998BD1E4002@bag.python.org> The Buildbot has detected a new failure of sparc Ubuntu 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Ubuntu%203.x/builds/40 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-sparc Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: ronald.oussoren BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_traceback make: *** [buildbottest] Error 1 sincerely, -The Buildbot From python-checkins at python.org Fri Jan 2 18:01:59 2009 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 2 Jan 2009 18:01:59 +0100 (CET) Subject: [Python-checkins] r68164 - in python/branches/release30-maint: Lib/idlelib/NEWS.txt Lib/idlelib/help.txt Lib/idlelib/macosxSupport.py Mac/Makefile.in Mac/PythonLauncher/Makefile.in Message-ID: <20090102170159.497491E4002@bag.python.org> Author: benjamin.peterson Date: Fri Jan 2 18:01:59 2009 New Revision: 68164 Log: Merged revisions 68152,68155 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r68152 | ronald.oussoren | 2009-01-02 05:48:29 -0600 (Fri, 02 Jan 2009) | 2 lines Fix for issue 3433 ................ r68155 | ronald.oussoren | 2009-01-02 07:10:34 -0600 (Fri, 02 Jan 2009) | 17 lines Recorded merge of revisions 68153 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68153 | ronald.oussoren | 2009-01-02 13:59:32 +0100 (Fri, 02 Jan 2009) | 10 lines Fix for issue3559: No preferences menu in IDLE on OSX 1) Add a comment to the help file to that points to the preferences menu. 2) An earlier checkin tried to detect Tk >= 8.10.14, but did this in the wrong way. The end result of this was that the IDLE->Preferences... menu got surpressed when using the system version of Tcl/Tk ........ ................ Modified: python/branches/release30-maint/Lib/idlelib/NEWS.txt python/branches/release30-maint/Lib/idlelib/help.txt python/branches/release30-maint/Lib/idlelib/macosxSupport.py python/branches/release30-maint/Mac/Makefile.in python/branches/release30-maint/Mac/PythonLauncher/Makefile.in Modified: python/branches/release30-maint/Lib/idlelib/NEWS.txt ============================================================================== --- python/branches/release30-maint/Lib/idlelib/NEWS.txt (original) +++ python/branches/release30-maint/Lib/idlelib/NEWS.txt Fri Jan 2 18:01:59 2009 @@ -8,6 +8,11 @@ user configuration of source encoding; all according to PEP 3120. +- Issue #3549: On MacOS the preferences menu was not present + +- Issue #2665: On Windows, an IDLE installation upgraded from an old version + would not start if a custom theme was defined. + What's New in IDLE 3.0a3? ========================= Modified: python/branches/release30-maint/Lib/idlelib/help.txt ============================================================================== --- python/branches/release30-maint/Lib/idlelib/help.txt (original) +++ python/branches/release30-maint/Lib/idlelib/help.txt Fri Jan 2 18:01:59 2009 @@ -90,7 +90,10 @@ Configure IDLE -- Open a configuration dialog. Fonts, indentation, keybindings, and color themes may be altered. Startup Preferences may be set, and Additional Help - Souces can be specified. + Sources can be specified. + + On MacOS X this menu is not present, use + menu 'IDLE -> Preferences...' instead. --- Code Context -- Open a pane at the top of the edit window which shows the block context of the section of code Modified: python/branches/release30-maint/Lib/idlelib/macosxSupport.py ============================================================================== --- python/branches/release30-maint/Lib/idlelib/macosxSupport.py (original) +++ python/branches/release30-maint/Lib/idlelib/macosxSupport.py Fri Jan 2 18:01:59 2009 @@ -89,7 +89,9 @@ ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding tkversion = root.tk.eval('info patchlevel') - if tkversion >= '8.4.14': + # Note: we cannot check if the string tkversion >= '8.4.14', because + # the string '8.4.7' is greater than the string '8.4.14'. + if tuple(map(int, tkversion.split('.'))) >= (8, 4, 14): Bindings.menudefs[0] = ('application', [ ('About IDLE', '<>'), None, Modified: python/branches/release30-maint/Mac/Makefile.in ============================================================================== --- python/branches/release30-maint/Mac/Makefile.in (original) +++ python/branches/release30-maint/Mac/Makefile.in Fri Jan 2 18:01:59 2009 @@ -216,9 +216,9 @@ install_IDLE: test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" ln -sf $(INSTALLED_PYTHONAPP) "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/Python" - sed "s!%prefix%!$(prefix)!g" < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE" + sed -e "s!%prefix%!$(prefix)!g" -e 's!%exe%!$(PYTHONFRAMEWORK)!g' < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE" sed "s!%version%!`$(RUNSHARED) $(BUILDPYTHON) -c 'import platform; print(platform.python_version())'`!g" < "$(srcdir)/IDLE/IDLE.app/Contents/Info.plist" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/Info.plist" touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" Modified: python/branches/release30-maint/Mac/PythonLauncher/Makefile.in ============================================================================== --- python/branches/release30-maint/Mac/PythonLauncher/Makefile.in (original) +++ python/branches/release30-maint/Mac/PythonLauncher/Makefile.in Fri Jan 2 18:01:59 2009 @@ -27,7 +27,7 @@ install: Python\ Launcher.app test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + /bin/cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" From python-checkins at python.org Fri Jan 2 18:34:35 2009 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 2 Jan 2009 18:34:35 +0100 (CET) Subject: [Python-checkins] r68165 - in python/branches/py3k: Misc/NEWS Modules/zlibmodule.c Message-ID: <20090102173435.7BFD01E4002@bag.python.org> Author: antoine.pitrou Date: Fri Jan 2 18:34:35 2009 New Revision: 68165 Log: Issue #4738: finer-grained locking in the zlib module. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/zlibmodule.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Jan 2 18:34:35 2009 @@ -175,6 +175,10 @@ Extension Modules ----------------- +- Issue #4738: Each zlib object now has a separate lock, allowing to compress + or decompress several streams at once on multi-CPU systems. Also, the GIL + is now released when computing the CRC of a large buffer. Patch by ebfe. + - Issue #1040026: Fix os.times result on systems where HZ is incorrect. - Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris, Modified: python/branches/py3k/Modules/zlibmodule.c ============================================================================== --- python/branches/py3k/Modules/zlibmodule.c (original) +++ python/branches/py3k/Modules/zlibmodule.c Fri Jan 2 18:34:35 2009 @@ -9,38 +9,15 @@ #include "zlib.h" #ifdef WITH_THREAD -#include "pythread.h" - -/* #defs ripped off from _tkinter.c, even though the situation here is much - simpler, because we don't have to worry about waiting for Tcl - events! And, since zlib itself is threadsafe, we don't need to worry - about re-entering zlib functions. - - N.B. - - Since ENTER_ZLIB and LEAVE_ZLIB only need to be called on functions - that modify the components of preexisting de/compress objects, it - could prove to be a performance gain on multiprocessor machines if - there was an de/compress object-specific lock. However, for the - moment the ENTER_ZLIB and LEAVE_ZLIB calls are global for ALL - de/compress objects. - */ - -static PyThread_type_lock zlib_lock = NULL; /* initialized on module load */ - -#define ENTER_ZLIB \ - Py_BEGIN_ALLOW_THREADS \ - PyThread_acquire_lock(zlib_lock, 1); \ - Py_END_ALLOW_THREADS - -#define LEAVE_ZLIB \ - PyThread_release_lock(zlib_lock); - + #include "pythread.h" + #define ENTER_ZLIB(obj) \ + Py_BEGIN_ALLOW_THREADS; \ + PyThread_acquire_lock((obj)->lock, 1); \ + Py_END_ALLOW_THREADS; + #define LEAVE_ZLIB(obj) PyThread_release_lock((obj)->lock); #else - -#define ENTER_ZLIB -#define LEAVE_ZLIB - + #define ENTER_ZLIB(obj) + #define LEAVE_ZLIB(obj) #endif /* The following parameters are copied from zutil.h, version 0.95 */ @@ -67,6 +44,9 @@ PyObject *unused_data; PyObject *unconsumed_tail; int is_initialised; + #ifdef WITH_THREAD + PyThread_type_lock lock; + #endif } compobject; static void @@ -106,6 +86,9 @@ Py_DECREF(self); return NULL; } +#ifdef WITH_THREAD + self->lock = PyThread_allocate_lock(); +#endif return self; } @@ -376,23 +359,30 @@ } static void -Comp_dealloc(compobject *self) +Dealloc(compobject *self) { - if (self->is_initialised) - deflateEnd(&self->zst); +#ifdef WITH_THREAD + PyThread_free_lock(self->lock); +#endif Py_XDECREF(self->unused_data); Py_XDECREF(self->unconsumed_tail); PyObject_Del(self); } static void +Comp_dealloc(compobject *self) +{ + if (self->is_initialised) + deflateEnd(&self->zst); + Dealloc(self); +} + +static void Decomp_dealloc(compobject *self) { if (self->is_initialised) - inflateEnd(&self->zst); - Py_XDECREF(self->unused_data); - Py_XDECREF(self->unconsumed_tail); - PyObject_Del(self); + inflateEnd(&self->zst); + Dealloc(self); } PyDoc_STRVAR(comp_compress__doc__, @@ -422,7 +412,7 @@ return NULL; } - ENTER_ZLIB + ENTER_ZLIB(self); start_total_out = self->zst.total_out; self->zst.avail_in = inplen; @@ -468,7 +458,7 @@ } error: - LEAVE_ZLIB + LEAVE_ZLIB(self); PyBuffer_Release(&pinput); return RetVal; } @@ -514,7 +504,7 @@ return NULL; } - ENTER_ZLIB + ENTER_ZLIB(self); start_total_out = self->zst.total_out; self->zst.avail_in = inplen; @@ -600,7 +590,7 @@ } error: - LEAVE_ZLIB + LEAVE_ZLIB(self); PyBuffer_Release(&pinput); return RetVal; } @@ -633,7 +623,7 @@ if (!(RetVal = PyBytes_FromStringAndSize(NULL, length))) return NULL; - ENTER_ZLIB + ENTER_ZLIB(self); start_total_out = self->zst.total_out; self->zst.avail_in = 0; @@ -693,7 +683,7 @@ } error: - LEAVE_ZLIB + LEAVE_ZLIB(self); return RetVal; } @@ -714,7 +704,7 @@ /* Copy the zstream state * We use ENTER_ZLIB / LEAVE_ZLIB to make this thread-safe */ - ENTER_ZLIB + ENTER_ZLIB(self); err = deflateCopy(&retval->zst, &self->zst); switch(err) { case(Z_OK): @@ -730,7 +720,6 @@ zlib_error(self->zst, err, "while copying compression object"); goto error; } - Py_INCREF(self->unused_data); Py_INCREF(self->unconsumed_tail); Py_XDECREF(retval->unused_data); @@ -741,11 +730,11 @@ /* Mark it as being initialized */ retval->is_initialised = 1; - LEAVE_ZLIB + LEAVE_ZLIB(self); return (PyObject *)retval; error: - LEAVE_ZLIB + LEAVE_ZLIB(self); Py_XDECREF(retval); return NULL; } @@ -765,7 +754,7 @@ /* Copy the zstream state * We use ENTER_ZLIB / LEAVE_ZLIB to make this thread-safe */ - ENTER_ZLIB + ENTER_ZLIB(self); err = inflateCopy(&retval->zst, &self->zst); switch(err) { case(Z_OK): @@ -792,11 +781,11 @@ /* Mark it as being initialized */ retval->is_initialised = 1; - LEAVE_ZLIB + LEAVE_ZLIB(self); return (PyObject *)retval; error: - LEAVE_ZLIB + LEAVE_ZLIB(self); Py_XDECREF(retval); return NULL; } @@ -826,7 +815,7 @@ return NULL; - ENTER_ZLIB + ENTER_ZLIB(self); start_total_out = self->zst.total_out; self->zst.avail_out = length; @@ -873,7 +862,7 @@ error: - LEAVE_ZLIB + LEAVE_ZLIB(self); return retval; } @@ -921,12 +910,20 @@ PyZlib_adler32(PyObject *self, PyObject *args) { unsigned int adler32val = 1; /* adler32(0L, Z_NULL, 0) */ - Byte *buf; - int len; + Py_buffer pbuf; - if (!PyArg_ParseTuple(args, "s#|I:adler32", &buf, &len, &adler32val)) + if (!PyArg_ParseTuple(args, "s*|I:adler32", &pbuf, &adler32val)) return NULL; - adler32val = adler32(adler32val, buf, len); + /* Releasing the GIL for very small buffers is inefficient + and may lower performance */ + if (pbuf.len > 1024*5) { + Py_BEGIN_ALLOW_THREADS + adler32val = adler32(adler32val, pbuf.buf, pbuf.len); + Py_END_ALLOW_THREADS + } else { + adler32val = adler32(adler32val, pbuf.buf, pbuf.len); + } + PyBuffer_Release(&pbuf); return PyLong_FromUnsignedLong(adler32val & 0xffffffffU); } @@ -945,7 +942,15 @@ if (!PyArg_ParseTuple(args, "s*|I:crc32", &pbuf, &crc32val)) return NULL; - signed_val = crc32(crc32val, pbuf.buf, pbuf.len); + /* Releasing the GIL for very small buffers is inefficient + and may lower performance */ + if (pbuf.len > 1024*5) { + Py_BEGIN_ALLOW_THREADS + signed_val = crc32(crc32val, pbuf.buf, pbuf.len); + Py_END_ALLOW_THREADS + } else { + signed_val = crc32(crc32val, pbuf.buf, pbuf.len); + } PyBuffer_Release(&pbuf); return PyLong_FromUnsignedLong(signed_val & 0xffffffffU); } @@ -1096,8 +1101,5 @@ PyModule_AddStringConstant(m, "__version__", "1.0"); -#ifdef WITH_THREAD - zlib_lock = PyThread_allocate_lock(); -#endif /* WITH_THREAD */ return m; } From buildbot at python.org Fri Jan 2 18:55:54 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 17:55:54 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.0 Message-ID: <20090102175554.355451E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.0/builds/20 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 2 tests failed: test_posix test_subprocess ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.0.loewis-sun/build/@test.getcwd/@test.getcwd' ====================================================================== FAIL: test_executable (test.test_subprocess.ProcessTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/test_subprocess.py", line 115, in test_executable self.assertEqual(p.returncode, 47) AssertionError: -6 != 47 sincerely, -The Buildbot From python-checkins at python.org Fri Jan 2 19:26:23 2009 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 2 Jan 2009 19:26:23 +0100 (CET) Subject: [Python-checkins] r68166 - python/trunk/Doc/c-api/structures.rst Message-ID: <20090102182623.564E91E4002@bag.python.org> Author: benjamin.peterson Date: Fri Jan 2 19:26:23 2009 New Revision: 68166 Log: document PyMemberDef Modified: python/trunk/Doc/c-api/structures.rst Modified: python/trunk/Doc/c-api/structures.rst ============================================================================== --- python/trunk/Doc/c-api/structures.rst (original) +++ python/trunk/Doc/c-api/structures.rst Fri Jan 2 19:26:23 2009 @@ -205,6 +205,69 @@ .. versionadded:: 2.4 +.. ctype:: PyMemberDef + + Structure which describes an attribute of a type which corresponds to a C + struct member. It's fields are: + + +------------------+-------------+-------------------------------+ + | Field | C Type | Meaning | + +==================+=============+===============================+ + | :attr:`name` | char \* | name of the member | + +------------------+-------------+-------------------------------+ + | :attr:`type` | int | the type of the member in the | + | | | C struct | + +------------------+-------------+-------------------------------+ + | :attr:`offset` | Py_ssize_t | the offset in bytes that the | + | | | member is located on the | + | | | type's object struct | + +------------------+-------------+-------------------------------+ + | :attr:`flags` | int | flag bits indicating if the | + | | | field should be read-only or | + | | | writable | + +------------------+-------------+-------------------------------+ + | :attr:`doc` | char \* | points to the contents of the | + | | | docstring | + +------------------+-------------+-------------------------------+ + + :attr:`type` can be one of many ``T_`` macros corresponding to various C + types. When the member is accessed in Python, it will be converted to the + equivalent Python type. + + =============== ================== + Macro name C type + =============== ================== + T_SHORT short + T_INT int + T_LONG long + T_FLOAT float + T_DOUBLE double + T_STRING char \* + T_OBJECT PyObject \* + T_OBJECT_EX PyObject \* + T_CHAR char + T_BYTE char + T_UNBYTE unsigned char + T_UINT unsigned int + T_USHORT unsigned short + T_ULONG unsigned long + T_BOOL char + T_LONGLONG long long + T_ULONGLONG unsigned long long + T_PYSSIZET Py_ssize_t + =============== ================== + + :cmacro:`T_OBJECT` and :cmacro:`T_OBJECT_EX` differ in that + :cmacro:`T_OBJECT` returns ``None`` if the member is *NULL* and + :cmacro:`T_OBJECT_EX` raises an :exc:`AttributeError`. + + :attr:`flags` can be 0 for write and read access or :cmacro:`READONLY` for + read-only access. Using :cmacro:`T_STRING` for :attr:`type` implies + :cmacro:`READONLY`. Only :cmacro:`T_OBJECT` and :cmacro:`T_OBJECT_EX` can be + deleted. (They are set to *NULL*). + + + .. cfunction:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name) Return a bound method object for an extension type implemented in C. This can From buildbot at python.org Fri Jan 2 19:36:11 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 18:36:11 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090102183611.ABD651E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/49 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: antoine.pitrou BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_posix ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' sincerely, -The Buildbot From buildbot at python.org Fri Jan 2 19:36:51 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 18:36:51 +0000 Subject: [Python-checkins] buildbot failure in sparc Ubuntu 3.0 Message-ID: <20090102183652.023601E4039@bag.python.org> The Buildbot has detected a new failure of sparc Ubuntu 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Ubuntu%203.0/builds/19 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-sparc Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_smtplib make: *** [buildbottest] Error 1 sincerely, -The Buildbot From python-checkins at python.org Fri Jan 2 19:53:05 2009 From: python-checkins at python.org (vinay.sajip) Date: Fri, 2 Jan 2009 19:53:05 +0100 (CET) Subject: [Python-checkins] r68167 - python/trunk/Doc/library/logging.rst Message-ID: <20090102185305.01BCE1E4002@bag.python.org> Author: vinay.sajip Date: Fri Jan 2 19:53:04 2009 New Revision: 68167 Log: Minor documentation changes relating to NullHandler, the module used for handlers and references to ConfigParser. Modified: python/trunk/Doc/library/logging.rst Modified: python/trunk/Doc/library/logging.rst ============================================================================== --- python/trunk/Doc/library/logging.rst (original) +++ python/trunk/Doc/library/logging.rst Fri Jan 2 19:53:04 2009 @@ -1559,8 +1559,6 @@ StreamHandler ^^^^^^^^^^^^^ -.. module:: logging.handlers - The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -1616,11 +1614,32 @@ Outputs the record to the file. +NullHandler +^^^^^^^^^^^ + +.. versionadded:: 2.7 + +The :class:`NullHandler` class, located in the core :mod:`logging` package, +does not do any formatting or output. It is essentially a "no-op" handler +for use by library developers. + + +.. class:: NullHandler() + + Returns a new instance of the :class:`NullHandler` class. + + + .. method:: emit(record) + + This method does nothing. + WatchedFileHandler ^^^^^^^^^^^^^^^^^^ .. versionadded:: 2.6 +.. module:: logging.handlers + The :class:`WatchedFileHandler` class, located in the :mod:`logging.handlers` module, is a :class:`FileHandler` which watches the file it is logging to. If the file changes, it is closed and reopened using the file name. @@ -2304,12 +2323,12 @@ .. function:: fileConfig(fname[, defaults]) - Reads the logging configuration from a ConfigParser-format file named *fname*. - This function can be called several times from an application, allowing an end - user the ability to select from various pre-canned configurations (if the - developer provides a mechanism to present the choices and load the chosen - configuration). Defaults to be passed to ConfigParser can be specified in the - *defaults* argument. + Reads the logging configuration from a :mod:`ConfigParser`\-format file named + *fname*. This function can be called several times from an application, + allowing an end user the ability to select from various pre-canned + configurations (if the developer provides a mechanism to present the choices + and load the chosen configuration). Defaults to be passed to the ConfigParser + can be specified in the *defaults* argument. .. function:: listen([port]) @@ -2340,17 +2359,17 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^ The configuration file format understood by :func:`fileConfig` is based on -ConfigParser functionality. The file must contain sections called ``[loggers]``, -``[handlers]`` and ``[formatters]`` which identify by name the entities of each -type which are defined in the file. For each such entity, there is a separate -section which identified how that entity is configured. Thus, for a logger named -``log01`` in the ``[loggers]`` section, the relevant configuration details are -held in a section ``[logger_log01]``. Similarly, a handler called ``hand01`` in -the ``[handlers]`` section will have its configuration held in a section called -``[handler_hand01]``, while a formatter called ``form01`` in the -``[formatters]`` section will have its configuration specified in a section -called ``[formatter_form01]``. The root logger configuration must be specified -in a section called ``[logger_root]``. +:mod:`ConfigParser` functionality. The file must contain sections called +``[loggers]``, ``[handlers]`` and ``[formatters]`` which identify by name the +entities of each type which are defined in the file. For each such entity, +there is a separate section which identifies how that entity is configured. +Thus, for a logger named ``log01`` in the ``[loggers]`` section, the relevant +configuration details are held in a section ``[logger_log01]``. Similarly, a +handler called ``hand01`` in the ``[handlers]`` section will have its +configuration held in a section called ``[handler_hand01]``, while a formatter +called ``form01`` in the ``[formatters]`` section will have its configuration +specified in a section called ``[formatter_form01]``. The root logger +configuration must be specified in a section called ``[logger_root]``. Examples of these sections in the file are given below. :: From python-checkins at python.org Fri Jan 2 19:53:46 2009 From: python-checkins at python.org (vinay.sajip) Date: Fri, 2 Jan 2009 19:53:46 +0100 (CET) Subject: [Python-checkins] r68168 - python/branches/py3k/Doc/library/logging.rst Message-ID: <20090102185346.0AA5F1E4002@bag.python.org> Author: vinay.sajip Date: Fri Jan 2 19:53:45 2009 New Revision: 68168 Log: Minor documentation changes relating to NullHandler, the module used for handlers and references to ConfigParser. Modified: python/branches/py3k/Doc/library/logging.rst Modified: python/branches/py3k/Doc/library/logging.rst ============================================================================== --- python/branches/py3k/Doc/library/logging.rst (original) +++ python/branches/py3k/Doc/library/logging.rst Fri Jan 2 19:53:45 2009 @@ -1534,8 +1534,6 @@ StreamHandler ^^^^^^^^^^^^^ -.. module:: logging.handlers - The :class:`StreamHandler` class, located in the core :mod:`logging` package, sends logging output to streams such as *sys.stdout*, *sys.stderr* or any file-like object (or, more precisely, any object which supports :meth:`write` @@ -1591,9 +1589,30 @@ Outputs the record to the file. +NullHandler +^^^^^^^^^^^ + +.. versionadded:: 3.1 + +The :class:`NullHandler` class, located in the core :mod:`logging` package, +does not do any formatting or output. It is essentially a "no-op" handler +for use by library developers. + + +.. class:: NullHandler() + + Returns a new instance of the :class:`NullHandler` class. + + + .. method:: emit(record) + + This method does nothing. + WatchedFileHandler ^^^^^^^^^^^^^^^^^^ +.. module:: logging.handlers + The :class:`WatchedFileHandler` class, located in the :mod:`logging.handlers` module, is a :class:`FileHandler` which watches the file it is logging to. If the file changes, it is closed and reopened using the file name. @@ -2306,7 +2325,7 @@ sections called ``[loggers]``, ``[handlers]`` and ``[formatters]`` which identify by name the entities of each type which are defined in the file. For each such entity, there is a separate section which -identified how that entity is configured. Thus, for a logger named +identifies how that entity is configured. Thus, for a logger named ``log01`` in the ``[loggers]`` section, the relevant configuration details are held in a section ``[logger_log01]``. Similarly, a handler called ``hand01`` in the ``[handlers]`` section will have its From python-checkins at python.org Fri Jan 2 20:20:26 2009 From: python-checkins at python.org (georg.brandl) Date: Fri, 2 Jan 2009 20:20:26 +0100 (CET) Subject: [Python-checkins] r68169 - in python/branches/py3k: Objects/moduleobject.c PC/example_nt/example.c Message-ID: <20090102192026.8B0CA1E4043@bag.python.org> Author: georg.brandl Date: Fri Jan 2 20:20:26 2009 New Revision: 68169 Log: Remove traces of Py_InitModule*. Modified: python/branches/py3k/Objects/moduleobject.c python/branches/py3k/PC/example_nt/example.c Modified: python/branches/py3k/Objects/moduleobject.c ============================================================================== --- python/branches/py3k/Objects/moduleobject.c (original) +++ python/branches/py3k/Objects/moduleobject.c Fri Jan 2 20:20:26 2009 @@ -91,9 +91,9 @@ This is a bit of a hack: when the shared library is loaded, the module name is "package.module", but the module calls - Py_InitModule*() with just "module" for the name. The shared + PyModule_Create*() with just "module" for the name. The shared library loader squirrels away the true name of the module in - _Py_PackageContext, and Py_InitModule*() will substitute this + _Py_PackageContext, and PyModule_Create*() will substitute this (if the name actually matches). */ if (_Py_PackageContext != NULL) { Modified: python/branches/py3k/PC/example_nt/example.c ============================================================================== --- python/branches/py3k/PC/example_nt/example.c (original) +++ python/branches/py3k/PC/example_nt/example.c Fri Jan 2 20:20:26 2009 @@ -13,8 +13,20 @@ {NULL, NULL} }; +static struct PyModuleDef examplemodule = { + PyModuleDef_HEAD_INIT, + "example", + "example module doc string", + -1, + example_methods, + NULL, + NULL, + NULL, + NULL +}; + PyMODINIT_FUNC -initexample(void) +PyInit_example(void) { - Py_InitModule("example", example_methods); + return PyModule_Create(&examplemodule); } From python-checkins at python.org Fri Jan 2 21:10:06 2009 From: python-checkins at python.org (georg.brandl) Date: Fri, 2 Jan 2009 21:10:06 +0100 (CET) Subject: [Python-checkins] r68170 - python/branches/py3k/Doc/library/threading.rst Message-ID: <20090102201006.196B81E4002@bag.python.org> Author: georg.brandl Date: Fri Jan 2 21:10:05 2009 New Revision: 68170 Log: #4808: move old API below new API doc. Modified: python/branches/py3k/Doc/library/threading.rst Modified: python/branches/py3k/Doc/library/threading.rst ============================================================================== --- python/branches/py3k/Doc/library/threading.rst (original) +++ python/branches/py3k/Doc/library/threading.rst Fri Jan 2 21:10:05 2009 @@ -278,12 +278,6 @@ raises the same exception. -.. method:: Thread.getName() - Thread.setName() - - Old API for :attr:`~Thread.name`. - - .. attribute:: Thread.name A string used for identification purposes only. It has no semantics. @@ -291,6 +285,13 @@ constructor. +.. method:: Thread.getName() + Thread.setName() + + Old getter/setter API for :attr:`~Thread.name`; use it directly as a property + instead. + + .. attribute:: Thread.ident The 'thread identifier' of this thread or ``None`` if the thread has not been @@ -309,12 +310,6 @@ returns a list of all alive threads. -.. method:: Thread.isDaemon() - Thread.setDaemon() - - Old API for :attr:`~Thread.daemon`. - - .. attribute:: Thread.daemon The thread's daemon flag. This must be set before :meth:`start` is called, @@ -325,6 +320,13 @@ The entire Python program exits when no alive non-daemon threads are left. +.. method:: Thread.isDaemon() + Thread.setDaemon() + + Old getter/setter API for :attr:`~Thread.daemon`; use it directly as a + property instead. + + .. _lock-objects: Lock Objects From python-checkins at python.org Fri Jan 2 21:25:14 2009 From: python-checkins at python.org (georg.brandl) Date: Fri, 2 Jan 2009 21:25:14 +0100 (CET) Subject: [Python-checkins] r68171 - in python/trunk/Doc: ACKS.txt c-api/arg.rst distutils/apiref.rst howto/functional.rst howto/urllib2.rst install/index.rst library/cookielib.rst library/email.mime.rst library/gzip.rst library/json.rst library/multiprocessing.rst library/numbers.rst library/parser.rst library/smtplib.rst library/urlparse.rst tutorial/inputoutput.rst using/cmdline.rst whatsnew/2.4.rst whatsnew/2.5.rst Message-ID: <20090102202514.91AD31E4002@bag.python.org> Author: georg.brandl Date: Fri Jan 2 21:25:14 2009 New Revision: 68171 Log: #4811: fix markup glitches (mostly remains of the conversion), found by Gabriel Genellina. Modified: python/trunk/Doc/ACKS.txt python/trunk/Doc/c-api/arg.rst python/trunk/Doc/distutils/apiref.rst python/trunk/Doc/howto/functional.rst python/trunk/Doc/howto/urllib2.rst python/trunk/Doc/install/index.rst python/trunk/Doc/library/cookielib.rst python/trunk/Doc/library/email.mime.rst python/trunk/Doc/library/gzip.rst python/trunk/Doc/library/json.rst python/trunk/Doc/library/multiprocessing.rst python/trunk/Doc/library/numbers.rst python/trunk/Doc/library/parser.rst python/trunk/Doc/library/smtplib.rst python/trunk/Doc/library/urlparse.rst python/trunk/Doc/tutorial/inputoutput.rst python/trunk/Doc/using/cmdline.rst python/trunk/Doc/whatsnew/2.4.rst python/trunk/Doc/whatsnew/2.5.rst Modified: python/trunk/Doc/ACKS.txt ============================================================================== --- python/trunk/Doc/ACKS.txt (original) +++ python/trunk/Doc/ACKS.txt Fri Jan 2 21:25:14 2009 @@ -60,6 +60,7 @@ * Peter Funk * Lele Gaifax * Matthew Gallagher + * Gabriel Genellina * Ben Gertzfield * Nadim Ghaznavi * Jonathan Giddy Modified: python/trunk/Doc/c-api/arg.rst ============================================================================== --- python/trunk/Doc/c-api/arg.rst (original) +++ python/trunk/Doc/c-api/arg.rst Fri Jan 2 21:25:14 2009 @@ -46,12 +46,12 @@ :ctype:`Py_ssize_t` rather than an int. ``s*`` (string, Unicode, or any buffer compatible object) [Py_buffer \*] - Similar to ``s#``, this code fills a Py_buffer structure provided by the caller. - The buffer gets locked, so that the caller can subsequently use the buffer even - inside a ``Py_BEGIN_ALLOW_THREADS`` block; the caller is responsible for calling - ``PyBuffer_Release`` with the structure after it has processed the data. + Similar to ``s#``, this code fills a Py_buffer structure provided by the caller. + The buffer gets locked, so that the caller can subsequently use the buffer even + inside a ``Py_BEGIN_ALLOW_THREADS`` block; the caller is responsible for calling + ``PyBuffer_Release`` with the structure after it has processed the data. - .. versionadded:: 2.6 + .. versionadded:: 2.6 ``z`` (string or ``None``) [const char \*] Like ``s``, but the Python object may also be ``None``, in which case the C @@ -63,7 +63,7 @@ ``z*`` (string or ``None`` or any buffer compatible object) [Py_buffer*] This is to ``s*`` as ``z`` is to ``s``. - .. versionadded:: 2.6 + .. versionadded:: 2.6 ``u`` (Unicode object) [Py_UNICODE \*] Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of @@ -261,6 +261,7 @@ ``w*`` (read-write byte-oriented buffer) [Py_buffer \*] This is to ``w`` what ``s*`` is to ``s``. + .. versionadded:: 2.6 ``(items)`` (tuple) [*matching-items*] Modified: python/trunk/Doc/distutils/apiref.rst ============================================================================== --- python/trunk/Doc/distutils/apiref.rst (original) +++ python/trunk/Doc/distutils/apiref.rst Fri Jan 2 21:25:14 2009 @@ -188,9 +188,10 @@ | | for C/C++ header files (in | | | | Unix form for portability) | | +------------------------+--------------------------------+---------------------------+ - | *define_macros* | list of macros to define; each | (string,string) tuple or | - | | macro is defined using a | (name,``None``) | - | | 2-tuple, where 'value' is | | + | *define_macros* | list of macros to define; each | (string, string) tuple or | + | | macro is defined using a | (name, ``None``) | + | | 2-tuple ``(name, value)``, | | + | | where *value* is | | | | either the string to define it | | | | to or ``None`` to define it | | | | without a particular value | | Modified: python/trunk/Doc/howto/functional.rst ============================================================================== --- python/trunk/Doc/howto/functional.rst (original) +++ python/trunk/Doc/howto/functional.rst Fri Jan 2 21:25:14 2009 @@ -585,7 +585,7 @@ 9 >>> print it.next() Traceback (most recent call last): - File ``t.py'', line 15, in ? + File "t.py", line 15, in ? print it.next() StopIteration Modified: python/trunk/Doc/howto/urllib2.rst ============================================================================== --- python/trunk/Doc/howto/urllib2.rst (original) +++ python/trunk/Doc/howto/urllib2.rst Fri Jan 2 21:25:14 2009 @@ -470,7 +470,7 @@ password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() # Add the username and password. - # If we knew the realm, we could use it instead of ``None``. + # If we knew the realm, we could use it instead of None. top_level_url = "http://example.com/foo/" password_mgr.add_password(None, top_level_url, username, password) Modified: python/trunk/Doc/install/index.rst ============================================================================== --- python/trunk/Doc/install/index.rst (original) +++ python/trunk/Doc/install/index.rst Fri Jan 2 21:25:14 2009 @@ -587,7 +587,7 @@ $ python Python 2.2 (#11, Oct 3 2002, 13:31:27) [GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2 - Type ``help'', ``copyright'', ``credits'' or ``license'' for more information. + Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2', Modified: python/trunk/Doc/library/cookielib.rst ============================================================================== --- python/trunk/Doc/library/cookielib.rst (original) +++ python/trunk/Doc/library/cookielib.rst Fri Jan 2 21:25:14 2009 @@ -733,7 +733,7 @@ The :class:`Cookie` class also defines the following method: -.. method:: Cookie.is_expired([now=:const:`None`]) +.. method:: Cookie.is_expired([now=None]) True if cookie has passed the time at which the server requested it should expire. If *now* is given (in seconds since the epoch), return whether the Modified: python/trunk/Doc/library/email.mime.rst ============================================================================== --- python/trunk/Doc/library/email.mime.rst (original) +++ python/trunk/Doc/library/email.mime.rst Fri Jan 2 21:25:14 2009 @@ -57,14 +57,14 @@ .. currentmodule:: email.mime.multipart -.. class:: MIMEMultipart([subtype[, boundary[, _subparts[, _params]]]]) +.. class:: MIMEMultipart([_subtype[, boundary[, _subparts[, _params]]]]) Module: :mod:`email.mime.multipart` A subclass of :class:`MIMEBase`, this is an intermediate base class for MIME messages that are :mimetype:`multipart`. Optional *_subtype* defaults to :mimetype:`mixed`, but can be used to specify the subtype of the message. A - :mailheader:`Content-Type` header of :mimetype:`multipart/`*_subtype* will be + :mailheader:`Content-Type` header of :mimetype:`multipart/_subtype` will be added to the message object. A :mailheader:`MIME-Version` header will also be added. Modified: python/trunk/Doc/library/gzip.rst ============================================================================== --- python/trunk/Doc/library/gzip.rst (original) +++ python/trunk/Doc/library/gzip.rst Fri Jan 2 21:25:14 2009 @@ -7,7 +7,7 @@ This module provides a simple interface to compress and decompress files just like the GNU programs :program:`gzip` and :program:`gunzip` would. -The data compression is provided by the :mod:``zlib`` module. +The data compression is provided by the :mod:`zlib` module. The :mod:`gzip` module provides the :class:`GzipFile` class which is modeled after Python's File Object. The :class:`GzipFile` class reads and writes Modified: python/trunk/Doc/library/json.rst ============================================================================== --- python/trunk/Doc/library/json.rst (original) +++ python/trunk/Doc/library/json.rst Fri Jan 2 21:25:14 2009 @@ -152,7 +152,7 @@ *default(obj)* is a function that should return a serializable version of *obj* or raise :exc:`TypeError`. The default simply raises :exc:`TypeError`. - To use a custom :class:`JSONEncoder`` subclass (e.g. one that overrides the + To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the :meth:`default` method to serialize additional types), specify it with the *cls* kwarg. Modified: python/trunk/Doc/library/multiprocessing.rst ============================================================================== --- python/trunk/Doc/library/multiprocessing.rst (original) +++ python/trunk/Doc/library/multiprocessing.rst Fri Jan 2 21:25:14 2009 @@ -1138,18 +1138,18 @@ Returns a :class:`Server` object which represents the actual server under the control of the Manager. The :class:`Server` object supports the - :meth:`serve_forever` method:: + :meth:`serve_forever` method: - >>> from multiprocessing.managers import BaseManager - >>> m = BaseManager(address=('', 50000), authkey='abc')) - >>> server = m.get_server() - >>> s.serve_forever() + >>> from multiprocessing.managers import BaseManager + >>> m = BaseManager(address=('', 50000), authkey='abc')) + >>> server = m.get_server() + >>> s.serve_forever() - :class:`Server` additionally have an :attr:`address` attribute. + :class:`Server` additionally have an :attr:`address` attribute. .. method:: connect() - Connect a local manager object to a remote manager process:: + Connect a local manager object to a remote manager process: >>> from multiprocessing.managers import BaseManager >>> m = BaseManager(address='127.0.0.1', authkey='abc)) @@ -1295,7 +1295,7 @@ >>>>>>>>>>>>>>>>>>> To create one's own manager, one creates a subclass of :class:`BaseManager` and -use the :meth:`~BaseManager.resgister` classmethod to register new types or +use the :meth:`~BaseManager.register` classmethod to register new types or callables with the manager class. For example:: from multiprocessing.managers import BaseManager @@ -1811,7 +1811,7 @@ * An ``'AF_PIPE'`` address is a string of the form :samp:`r'\\\\.\\pipe\\{PipeName}'`. To use :func:`Client` to connect to a named - pipe on a remote computer called ServerName* one should use an address of the + pipe on a remote computer called *ServerName* one should use an address of the form :samp:`r'\\\\{ServerName}\\pipe\\{PipeName}'`` instead. Note that any string beginning with two backslashes is assumed by default to be Modified: python/trunk/Doc/library/numbers.rst ============================================================================== --- python/trunk/Doc/library/numbers.rst (original) +++ python/trunk/Doc/library/numbers.rst Fri Jan 2 21:25:14 2009 @@ -51,14 +51,14 @@ :func:`round`, :func:`math.floor`, :func:`math.ceil`, :func:`divmod`, ``//``, ``%``, ``<``, ``<=``, ``>``, and ``>=``. - Real also provides defaults for :func:`complex`, :attr:`Complex.real`, - :attr:`Complex.imag`, and :meth:`Complex.conjugate`. + Real also provides defaults for :func:`complex`, :attr:`~Complex.real`, + :attr:`~Complex.imag`, and :meth:`~Complex.conjugate`. .. class:: Rational Subtypes :class:`Real` and adds - :attr:`Rational.numerator` and :attr:`Rational.denominator` properties, which + :attr:`~Rational.numerator` and :attr:`~Rational.denominator` properties, which should be in lowest terms. With these, it provides a default for :func:`float`. @@ -74,8 +74,8 @@ .. class:: Integral Subtypes :class:`Rational` and adds a conversion to :class:`int`. - Provides defaults for :func:`float`, :attr:`Rational.numerator`, and - :attr:`Rational.denominator`, and bit-string operations: ``<<``, + Provides defaults for :func:`float`, :attr:`~Rational.numerator`, and + :attr:`~Rational.denominator`, and bit-string operations: ``<<``, ``>>``, ``&``, ``^``, ``|``, ``~``. @@ -171,7 +171,7 @@ knowledge of ``A``, so it can handle those instances before delegating to :class:`Complex`. -If ``A<:Complex`` and ``B<:Real`` without sharing any other knowledge, +If ``A <: Complex`` and ``B <: Real`` without sharing any other knowledge, then the appropriate shared operation is the one involving the built in :class:`complex`, and both :meth:`__radd__` s land there, so ``a+b == b+a``. Modified: python/trunk/Doc/library/parser.rst ============================================================================== --- python/trunk/Doc/library/parser.rst (original) +++ python/trunk/Doc/library/parser.rst Fri Jan 2 21:25:14 2009 @@ -641,7 +641,7 @@ while the long form uses an indented block and allows nested definitions:: def make_power(exp): - "Make a function that raises an argument to the exponent `exp'." + "Make a function that raises an argument to the exponent `exp`." def raiser(x, y=exp): return x ** y return raiser Modified: python/trunk/Doc/library/smtplib.rst ============================================================================== --- python/trunk/Doc/library/smtplib.rst (original) +++ python/trunk/Doc/library/smtplib.rst Fri Jan 2 21:25:14 2009 @@ -207,7 +207,7 @@ previous ``EHLO`` or ``HELO`` command this session. It tries ESMTP ``EHLO`` first. - :exc:SMTPHeloError + :exc:`SMTPHeloError` The server didn't reply properly to the ``HELO`` greeting. .. versionadded:: 2.6 Modified: python/trunk/Doc/library/urlparse.rst ============================================================================== --- python/trunk/Doc/library/urlparse.rst (original) +++ python/trunk/Doc/library/urlparse.rst Fri Jan 2 21:25:14 2009 @@ -290,7 +290,7 @@ .. versionadded:: 2.5 -The following classes provide the implementations of the parse results:: +The following classes provide the implementations of the parse results: .. class:: BaseResult Modified: python/trunk/Doc/tutorial/inputoutput.rst ============================================================================== --- python/trunk/Doc/tutorial/inputoutput.rst (original) +++ python/trunk/Doc/tutorial/inputoutput.rst Fri Jan 2 21:25:14 2009 @@ -148,7 +148,7 @@ ... other='Georg') The story of Bill, Manfred, and Georg. -An optional ``':``` and format specifier can follow the field name. This also +An optional ``':'`` and format specifier can follow the field name. This also greater control over how the value is formatted. The following example truncates the Pi to three places after the decimal. Modified: python/trunk/Doc/using/cmdline.rst ============================================================================== --- python/trunk/Doc/using/cmdline.rst (original) +++ python/trunk/Doc/using/cmdline.rst Fri Jan 2 21:25:14 2009 @@ -404,7 +404,7 @@ compiled form). Extension modules cannot be imported from zipfiles. The default search path is installation dependent, but generally begins with - :file:`{prefix}/lib/python{version}`` (see :envvar:`PYTHONHOME` above). It + :file:`{prefix}/lib/python{version}` (see :envvar:`PYTHONHOME` above). It is *always* appended to :envvar:`PYTHONPATH`. An additional directory will be inserted in the search path in front of Modified: python/trunk/Doc/whatsnew/2.4.rst ============================================================================== --- python/trunk/Doc/whatsnew/2.4.rst (original) +++ python/trunk/Doc/whatsnew/2.4.rst Fri Jan 2 21:25:14 2009 @@ -1428,7 +1428,7 @@ you get the following output:: ********************************************************************** - File ``t.py'', line 15, in g + File "t.py", line 15, in g Failed example: g(4) Differences (unified diff with -expected +actual): Modified: python/trunk/Doc/whatsnew/2.5.rst ============================================================================== --- python/trunk/Doc/whatsnew/2.5.rst (original) +++ python/trunk/Doc/whatsnew/2.5.rst Fri Jan 2 21:25:14 2009 @@ -485,7 +485,7 @@ 9 >>> print it.next() Traceback (most recent call last): - File ``t.py'', line 15, in ? + File "t.py", line 15, in ? print it.next() StopIteration From python-checkins at python.org Fri Jan 2 21:32:55 2009 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 2 Jan 2009 21:32:55 +0100 (CET) Subject: [Python-checkins] r68172 - in python/trunk: Misc/NEWS Python/pythonrun.c Message-ID: <20090102203255.D76961E4002@bag.python.org> Author: martin.v.loewis Date: Fri Jan 2 21:32:55 2009 New Revision: 68172 Log: Issue #4075: Use OutputDebugStringW in Py_FatalError. Modified: python/trunk/Misc/NEWS python/trunk/Python/pythonrun.c Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 21:32:55 2009 @@ -12,6 +12,8 @@ Core and Builtins ----------------- +- Issue #4075: Use OutputDebugStringW in Py_FatalError. + - Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. Modified: python/trunk/Python/pythonrun.c ============================================================================== --- python/trunk/Python/pythonrun.c (original) +++ python/trunk/Python/pythonrun.c Fri Jan 2 21:32:55 2009 @@ -22,6 +22,8 @@ #include #endif +#include "malloc.h" /* for alloca */ + #ifdef HAVE_LANGINFO_H #include #include @@ -1628,9 +1630,21 @@ { fprintf(stderr, "Fatal Python error: %s\n", msg); #ifdef MS_WINDOWS - OutputDebugString("Fatal Python error: "); - OutputDebugString(msg); - OutputDebugString("\n"); + { + size_t len = strlen(msg); + WCHAR* buffer; + size_t i; + + /* Convert the message to wchar_t. This uses a simple one-to-one + conversion, assuming that the this error message actually uses ASCII + only. If this ceases to be true, we will have to convert. */ + buffer = alloca( (len+1) * (sizeof *buffer)); + for( i=0; i<=len; ++i) + buffer[i] = msg[i]; + OutputDebugStringW(L"Fatal Python error: "); + OutputDebugStringW(buffer); + OutputDebugStringW(L"\n"); + } #ifdef _DEBUG DebugBreak(); #endif From python-checkins at python.org Fri Jan 2 21:40:15 2009 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 2 Jan 2009 21:40:15 +0100 (CET) Subject: [Python-checkins] r68173 - in python/trunk: Misc/NEWS Modules/cPickle.c Message-ID: <20090102204015.030C91E4002@bag.python.org> Author: martin.v.loewis Date: Fri Jan 2 21:40:14 2009 New Revision: 68173 Log: Issue #4051: Prevent conflict of UNICODE macros in cPickle. Modified: python/trunk/Misc/NEWS python/trunk/Modules/cPickle.c Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Fri Jan 2 21:40:14 2009 @@ -286,6 +286,8 @@ Extension Modules ----------------- +- Issue #4051: Prevent conflict of UNICODE macros in cPickle. + - Issue #4228: Pack negative values the same way as 2.4 in struct's L format. - Issue #1040026: Fix os.times result on systems where HZ is incorrect. Modified: python/trunk/Modules/cPickle.c ============================================================================== --- python/trunk/Modules/cPickle.c (original) +++ python/trunk/Modules/cPickle.c Fri Jan 2 21:40:14 2009 @@ -18,6 +18,14 @@ #define HIGHEST_PROTOCOL 2 /* + * Note: The UNICODE macro controls the TCHAR meaning of the win32 API. Since + * all headers have already been included here, we can safely redefine it. + */ +#ifdef UNICODE +# undef UNICODE +#endif + +/* * Pickle opcodes. These must be kept in synch with pickle.py. Extensive * docs are in pickletools.py. */ From python-checkins at python.org Fri Jan 2 21:47:27 2009 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 2 Jan 2009 21:47:27 +0100 (CET) Subject: [Python-checkins] r68174 - python/trunk/Python/pythonrun.c Message-ID: <20090102204727.CC34F1E4002@bag.python.org> Author: benjamin.peterson Date: Fri Jan 2 21:47:27 2009 New Revision: 68174 Log: fix compilation on non-Windows platforms Modified: python/trunk/Python/pythonrun.c Modified: python/trunk/Python/pythonrun.c ============================================================================== --- python/trunk/Python/pythonrun.c (original) +++ python/trunk/Python/pythonrun.c Fri Jan 2 21:47:27 2009 @@ -22,7 +22,9 @@ #include #endif +#ifdef MS_WINDOWS #include "malloc.h" /* for alloca */ +#endif #ifdef HAVE_LANGINFO_H #include From python-checkins at python.org Fri Jan 2 21:47:49 2009 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 2 Jan 2009 21:47:49 +0100 (CET) Subject: [Python-checkins] r68175 - in python/branches/py3k: Misc/NEWS Python/pythonrun.c Message-ID: <20090102204749.078BD1E4002@bag.python.org> Author: martin.v.loewis Date: Fri Jan 2 21:47:48 2009 New Revision: 68175 Log: Merged revisions 68172-68173 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fr, 02 Jan 2009) | 2 lines Issue #4075: Use OutputDebugStringW in Py_FatalError. ........ r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fr, 02 Jan 2009) | 2 lines Issue #4051: Prevent conflict of UNICODE macros in cPickle. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/Python/pythonrun.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Jan 2 21:47:48 2009 @@ -12,6 +12,8 @@ Core and Builtins ----------------- +- Issue #4075: Use OutputDebugStringW in Py_FatalError. + - Issue #4747: When the terminal does not use utf-8, executing a script with non-ascii characters in its name could fail with a "SyntaxError: None" error. @@ -175,6 +177,8 @@ Extension Modules ----------------- +- Issue #4051: Prevent conflict of UNICODE macros in cPickle. + - Issue #4738: Each zlib object now has a separate lock, allowing to compress or decompress several streams at once on multi-CPU systems. Also, the GIL is now released when computing the CRC of a large buffer. Patch by ebfe. Modified: python/branches/py3k/Python/pythonrun.c ============================================================================== --- python/branches/py3k/Python/pythonrun.c (original) +++ python/branches/py3k/Python/pythonrun.c Fri Jan 2 21:47:48 2009 @@ -23,6 +23,8 @@ #include #endif +#include "malloc.h" /* for alloca */ + #ifdef HAVE_LANGINFO_H #include #include @@ -1918,9 +1920,21 @@ PyErr_Print(); } #ifdef MS_WINDOWS - OutputDebugString("Fatal Python error: "); - OutputDebugString(msg); - OutputDebugString("\n"); + { + size_t len = strlen(msg); + WCHAR* buffer; + size_t i; + + /* Convert the message to wchar_t. This uses a simple one-to-one + conversion, assuming that the this error message actually uses ASCII + only. If this ceases to be true, we will have to convert. */ + buffer = alloca( (len+1) * (sizeof *buffer)); + for( i=0; i<=len; ++i) + buffer[i] = msg[i]; + OutputDebugStringW(L"Fatal Python error: "); + OutputDebugStringW(buffer); + OutputDebugStringW(L"\n"); + } #ifdef _DEBUG DebugBreak(); #endif From python-checkins at python.org Fri Jan 2 22:00:36 2009 From: python-checkins at python.org (andrew.kuchling) Date: Fri, 2 Jan 2009 22:00:36 +0100 (CET) Subject: [Python-checkins] r68176 - python/trunk/Doc/whatsnew/2.7.rst Message-ID: <20090102210036.09BF81E402D@bag.python.org> Author: andrew.kuchling Date: Fri Jan 2 22:00:35 2009 New Revision: 68176 Log: Add various items Modified: python/trunk/Doc/whatsnew/2.7.rst Modified: python/trunk/Doc/whatsnew/2.7.rst ============================================================================== --- python/trunk/Doc/whatsnew/2.7.rst (original) +++ python/trunk/Doc/whatsnew/2.7.rst Fri Jan 2 22:00:35 2009 @@ -103,7 +103,23 @@ :file:`Misc/NEWS` file in the source tree for a more complete list of changes, or look through the Subversion logs for all the details. -* To be written. +* A new function in the :mod:`subprocess` module, + :func:`check_output`, runs a command with a specified set of arguments + and returns the command's output as a string if the command runs without + error, or raises a :exc:`CalledProcessError` exception otherwise. + + :: + + >>> subprocess.check_output(['df', '-h', '.']) + 'Filesystem Size Used Avail Capacity Mounted on\n + /dev/disk0s2 52G 49G 3.0G 94% /\n' + + >>> subprocess.check_output(['df', '-h', '/bogus']) + ... + subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1 + + (Contributed by Gregory P. Smith.) + .. ====================================================================== .. whole new modules get described in subsections here @@ -116,13 +132,22 @@ Changes to Python's build process and to the C API include: -* To be written. +* If you use the :file:`.gdbinit` file provided with Python, + the "pyo" macro in the 2.7 version will now work when the thread being + debugged doesn't hold the GIL; the macro will now acquire it before printing. + (Contributed by haypo XXX; :issue:`3632`.) .. ====================================================================== Port-Specific Changes: Windows ----------------------------------- +* The :mod:`msvcrt` module now contains some constants from + the :file:`crtassem.h` header file: + :data:`CRT_ASSEMBLY_VERSION`, + :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`, + and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`. + (Added by Martin von Loewis (XXX check); :issue:`4365`.) .. ====================================================================== From nnorwitz at gmail.com Fri Jan 2 22:15:56 2009 From: nnorwitz at gmail.com (Neal Norwitz) Date: Fri, 2 Jan 2009 16:15:56 -0500 Subject: [Python-checkins] Python Regression Test Failures basics (2) Message-ID: <20090102211556.GA31381@python.psfb.org> 327 tests OK. 2 tests failed: test_fork1 test_ftplib 33 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_bsddb3 test_cd test_cl test_curses test_epoll test_gl test_imgfile test_ioctl test_kqueue test_lib2to3 test_linuxaudiodev test_macos test_macostools test_multiprocessing test_ossaudiodev test_pep277 test_py3kwarn test_scriptpackages test_socketserver test_startfile test_sunaudiodev test_tcl test_timeout test_unicode_file test_urllib2net test_urllibnet test_winreg test_winsound test_zipfile64 4 skips unexpected on linux2: test_epoll test_multiprocessing test_lib2to3 test_ioctl test_grammar test_opcodes test_dict test_builtin test_exceptions test_types test_unittest test_doctest test_doctest2 test_MimeWriter test_SimpleHTTPServer test_StringIO test___all__ test___future__ test__locale test_abc test_abstract_numbers test_aepack test_aepack skipped -- No module named aepack test_al test_al skipped -- No module named al test_anydbm test_applesingle test_applesingle skipped -- No module named macostools test_array test_ast test_asynchat test_asyncore test_atexit test_audioop test_augassign test_base64 test_bastion test_bigaddrspace test_bigmem test_binascii test_binhex test_binop test_bisect test_bool test_bsddb test_bsddb185 test_bsddb185 skipped -- No module named bsddb185 test_bsddb3 test_bsddb3 skipped -- Use of the `bsddb' resource not enabled test_buffer test_bufio test_bytes test_bz2 test_calendar test_call test_capi test_cd test_cd skipped -- No module named cd test_cfgparser test_cgi test_charmapcodec test_cl test_cl skipped -- No module named cl test_class test_cmath test_cmd test_cmd_line test_cmd_line_script test_code test_codeccallbacks test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_codecs test_codeop test_coding test_coercion test_collections test_colorsys test_commands test_compare test_compile test_compiler test_complex test_complex_args test_contains test_contextlib test_cookie test_cookielib test_copy test_copy_reg test_cpickle test_cprofile test_crypt test_csv test_ctypes test_curses test_curses skipped -- Use of the `curses' resource not enabled test_datetime test_dbm test_decimal test_decorators test_defaultdict test_deque test_descr test_descrtut test_difflib test_dircache test_dis test_distutils test_dl test_docxmlrpc test_dumbdbm test_dummy_thread test_dummy_threading test_email test_email_codecs test_email_renamed test_enumerate test_eof test_epoll test_epoll skipped -- kernel doesn't support epoll() test_errno test_exception_variations test_extcall test_fcntl test_file test_filecmp test_fileinput test_fileio test_float test_fnmatch test_fork1 test test_fork1 failed -- Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/fork_wait.py", line 55, in test_wait self.assertEquals(a, range(NUM_THREADS)) AssertionError: [] != [0, 1, 2, 3] test_format test_fpformat test_fractions test_frozen test_ftplib test test_ftplib failed -- Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/test_ftplib.py", line 234, in setUp self.client.connect(self.server.host, self.server.port) File "/tmp/python-test/local/lib/python2.7/ftplib.py", line 134, in connect self.welcome = self.getresp() File "/tmp/python-test/local/lib/python2.7/ftplib.py", line 209, in getresp resp = self.getmultiline() File "/tmp/python-test/local/lib/python2.7/ftplib.py", line 195, in getmultiline line = self.getline() File "/tmp/python-test/local/lib/python2.7/ftplib.py", line 182, in getline line = self.file.readline() File "/tmp/python-test/local/lib/python2.7/socket.py", line 404, in readline data = self._sock.recv(self._rbufsize) timeout: timed out test_funcattrs test_functools test_future test_future3 test_future4 test_future5 test_future_builtins test_gc test_gdbm test_generators test_genericpath test_genexps test_getargs test_getargs2 test_getopt test_gettext test_gl test_gl skipped -- No module named gl test_glob test_global test_grp test_gzip test_hash test_hashlib test_heapq test_hmac test_hotshot test_htmllib test_htmlparser test_httplib test_httpservers [12871 refs] [12871 refs] [21405 refs] test_imageop test_imaplib test_imgfile test_imgfile skipped -- No module named imgfile test_imp test_import test_importhooks test_index test_inspect test_int test_int_literal test_io test_ioctl test_ioctl skipped -- Unable to open /dev/tty test_isinstance test_iter test_iterlen test_itertools test_json test_kqueue test_kqueue skipped -- test works only on BSD test_largefile test_lib2to3 test_lib2to3 skipped -- No module named myfixes test_linuxaudiodev test_linuxaudiodev skipped -- Use of the `audio' resource not enabled test_list test_locale test_logging test_long test_long_future test_longexp test_macos test_macos skipped -- No module named MacOS test_macostools test_macostools skipped -- No module named macostools test_macpath test_mailbox test_marshal test_math test_md5 test_memoryio test_mhlib test_mimetools test_mimetypes test_minidom test_mmap test_module test_modulefinder test_multibytecodec test_multibytecodec_support test_multifile test_multiprocessing test_multiprocessing skipped -- OSError raises on RLock creation, see issue 3111! test_mutants test_mutex test_netrc test_new test_nis test_normalization test_ntpath test_old_mailbox test_openpty test_operator test_optparse test_os /tmp/python-test/local/lib/python2.7/os.py:759: DeprecationWarning: integer argument expected, got float bs += read(_urandomfd, n - len(bs)) test_ossaudiodev test_ossaudiodev skipped -- Use of the `audio' resource not enabled test_parser Expecting 's_push: parser stack overflow' in next line s_push: parser stack overflow test_peepholer test_pep247 test_pep263 test_pep277 test_pep277 skipped -- test works only on NT+ test_pep292 test_pep352 test_pickle test_pickletools test_pipes test_pkg test_pkgimport test_pkgutil test_platform [14526 refs] [14526 refs] test_plistlib test_poll test_popen [12876 refs] [12876 refs] [12876 refs] test_popen2 test_poplib test_posix test_posixpath test_pow test_pprint test_print test_profile test_profilehooks test_property test_pstats test_pty test_pwd test_py3kwarn test_py3kwarn skipped -- test.test_py3kwarn must be run with the -3 flag test_pyclbr test_pydoc [17405 refs] test_pyexpat test_queue test_quopri [15396 refs] [15396 refs] test_random test_re test_repr test_resource test_rfc822 test_richcmp test_robotparser test_runpy test_sax test_scope test_scriptpackages test_scriptpackages skipped -- No module named aetools test_select test_set test_sets test_sgmllib test_sha test_shelve test_shlex test_shutil test_signal test_site [12871 refs] [12871 refs] [12874 refs] [12871 refs] test_slice test_smtplib test_socket test_socketserver test_socketserver skipped -- Use of the `network' resource not enabled test_softspace test_sort test_sqlite test_ssl test_startfile test_startfile skipped -- cannot import name startfile test_str test_strftime test_string test_stringprep test_strop test_strptime test_struct test_structmembers test_structseq test_subprocess [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [14771 refs] [13086 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] . [12871 refs] [12871 refs] this bit of output is from a test of stdout in a different process ... [12871 refs] [12871 refs] [13086 refs] test_sunaudiodev test_sunaudiodev skipped -- No module named sunaudiodev test_sundry /tmp/python-test/local/lib/python2.7/test/test_sundry.py:67: DeprecationWarning: The posixfile module is deprecated; fcntl.lockf() provides better locking import posixfile test_symtable test_syntax test_sys [12871 refs] [12871 refs] [13100 refs] [12894 refs] test_tarfile test_tcl test_tcl skipped -- No module named _tkinter test_telnetlib test_tempfile [12874 refs] test_textwrap test_thread test_threaded_import test_threadedtempfile test_threading [16367 refs] [16857 refs] [15828 refs] [15828 refs] [15828 refs] [15828 refs] test_threading_local test_threadsignals test_time test_timeout test_timeout skipped -- Use of the `network' resource not enabled test_tokenize test_trace test_traceback test_transformer test_tuple test_typechecks test_ucn test_unary test_undocumented_details test_unicode test_unicode_file test_unicode_file skipped -- No Unicode filesystem semantics on this platform. test_unicodedata test_univnewlines test_unpack test_urllib test_urllib2 test_urllib2_localnet test_urllib2net test_urllib2net skipped -- Use of the `network' resource not enabled test_urllibnet test_urllibnet skipped -- Use of the `network' resource not enabled test_urlparse test_userdict test_userlist test_userstring test_uu test_uuid WARNING: uuid.getnode is unreliable on many platforms. It is disabled until the code and/or test can be fixed properly. WARNING: uuid._ifconfig_getnode is unreliable on many platforms. It is disabled until the code and/or test can be fixed properly. WARNING: uuid._unixdll_getnode is unreliable on many platforms. It is disabled until the code and/or test can be fixed properly. test_wait3 Unhandled exception in thread started by > Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/fork_wait.py", line 29, in f self.alive[id] = os.getpid() AttributeError: 'NoneType' object has no attribute 'getpid' Unhandled exception in thread started by > Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/fork_wait.py", line 29, in f self.alive[id] = os.getpid() AttributeError: 'NoneType' object has no attribute 'getpid' Unhandled exception in thread started by > Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/fork_wait.py", line 29, in f self.alive[id] = os.getpid() AttributeError: 'NoneType' object has no attribute 'getpid' Unhandled exception in thread started by > Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/fork_wait.py", line 29, in f self.alive[id] = os.getpid() AttributeError: 'NoneType' object has no attribute 'getpid' test_wait4 test_warnings test_wave test_weakref test_whichdb test_winreg test_winreg skipped -- No module named _winreg test_winsound test_winsound skipped -- No module named winsound test_with test_wsgiref test_xdrlib test_xml_etree test_xml_etree_c test_xmllib test_xmlrpc test_xpickle test_xrange test_zipfile test_zipfile64 test_zipfile64 skipped -- test requires loads of disk-space bytes and a long time to run test_zipimport test_zipimport_support test_zlib 327 tests OK. 2 tests failed: test_fork1 test_ftplib 33 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_bsddb3 test_cd test_cl test_curses test_epoll test_gl test_imgfile test_ioctl test_kqueue test_lib2to3 test_linuxaudiodev test_macos test_macostools test_multiprocessing test_ossaudiodev test_pep277 test_py3kwarn test_scriptpackages test_socketserver test_startfile test_sunaudiodev test_tcl test_timeout test_unicode_file test_urllib2net test_urllibnet test_winreg test_winsound test_zipfile64 4 skips unexpected on linux2: test_epoll test_multiprocessing test_lib2to3 test_ioctl [655167 refs] From python-checkins at python.org Fri Jan 2 22:20:39 2009 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 2 Jan 2009 22:20:39 +0100 (CET) Subject: [Python-checkins] r68177 - in python/branches/release26-maint: Doc/library/itertools.rst Lib/test/test_itertools.py Message-ID: <20090102212039.4D12F1E402C@bag.python.org> Author: raymond.hettinger Date: Fri Jan 2 22:20:38 2009 New Revision: 68177 Log: Issue #4615. Document how to use itertools for de-duping. Modified: python/branches/release26-maint/Doc/library/itertools.rst python/branches/release26-maint/Lib/test/test_itertools.py Modified: python/branches/release26-maint/Doc/library/itertools.rst ============================================================================== --- python/branches/release26-maint/Doc/library/itertools.rst (original) +++ python/branches/release26-maint/Doc/library/itertools.rst Fri Jan 2 22:20:38 2009 @@ -687,3 +687,27 @@ return indices[i:] = [indices[i] + 1] * (r - i) yield tuple(pool[i] for i in indices) + + def unique_everseen(iterable, key=None): + "List unique elements, preserving order. Remember all elements ever seen." + # unique_everseen('AAAABBBCCDAABBB') --> A B C D + # unique_everseen('ABBCcAD', str.lower) --> A B C D + seen = set() + seen_add = seen.add + if key is None: + for element in iterable: + if element not in seen: + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element + + def unique_justseen(iterable, key=None): + "List unique elements, preserving order. Remember only the element just seen." + # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B + # unique_justseen('ABBCcAD', str.lower) --> A B C A D + return imap(next, imap(itemgetter(1), groupby(iterable, key))) Modified: python/branches/release26-maint/Lib/test/test_itertools.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_itertools.py (original) +++ python/branches/release26-maint/Lib/test/test_itertools.py Fri Jan 2 22:20:38 2009 @@ -1277,6 +1277,30 @@ ... indices[i:] = [indices[i] + 1] * (r - i) ... yield tuple(pool[i] for i in indices) +>>> def unique_everseen(iterable, key=None): +... "List unique elements, preserving order. Remember all elements ever seen." +... # unique_everseen('AAAABBBCCDAABBB') --> A B C D +... # unique_everseen('ABBCcAD', str.lower) --> A B C D +... seen = set() +... seen_add = seen.add +... if key is None: +... for element in iterable: +... if element not in seen: +... seen_add(element) +... yield element +... else: +... for element in iterable: +... k = key(element) +... if k not in seen: +... seen_add(k) +... yield element + +>>> def unique_justseen(iterable, key=None): +... "List unique elements, preserving order. Remember only the element just seen." +... # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B +... # unique_justseen('ABBCcAD', str.lower) --> A B C A D +... return imap(next, imap(itemgetter(1), groupby(iterable, key))) + This is not part of the examples but it tests to make sure the definitions perform as purported. @@ -1339,6 +1363,18 @@ >>> list(combinations_with_replacement('abc', 2)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] +>>> list(unique_everseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D'] + +>>> list(unique_everseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'D'] + +>>> list(unique_justseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D', 'A', 'B'] + +>>> list(unique_justseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'A', 'D'] + """ __test__ = {'libreftest' : libreftest} From python-checkins at python.org Fri Jan 2 22:24:04 2009 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 2 Jan 2009 22:24:04 +0100 (CET) Subject: [Python-checkins] r68178 - in python/branches/py3k: Python/pythonrun.c Message-ID: <20090102212404.9BC741E402B@bag.python.org> Author: benjamin.peterson Date: Fri Jan 2 22:24:04 2009 New Revision: 68178 Log: Merged revisions 68174 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68174 | benjamin.peterson | 2009-01-02 14:47:27 -0600 (Fri, 02 Jan 2009) | 1 line fix compilation on non-Windows platforms ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Python/pythonrun.c Modified: python/branches/py3k/Python/pythonrun.c ============================================================================== --- python/branches/py3k/Python/pythonrun.c (original) +++ python/branches/py3k/Python/pythonrun.c Fri Jan 2 22:24:04 2009 @@ -23,7 +23,9 @@ #include #endif +#ifdef MS_WINDOWS #include "malloc.h" /* for alloca */ +#endif #ifdef HAVE_LANGINFO_H #include From python-checkins at python.org Fri Jan 2 22:26:45 2009 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 2 Jan 2009 22:26:45 +0100 (CET) Subject: [Python-checkins] r68179 - in python/trunk: Doc/library/itertools.rst Lib/test/test_itertools.py Message-ID: <20090102212645.AA4B11E4002@bag.python.org> Author: raymond.hettinger Date: Fri Jan 2 22:26:45 2009 New Revision: 68179 Log: Issue #4615. Document how to use itertools for de-duping. Modified: python/trunk/Doc/library/itertools.rst python/trunk/Lib/test/test_itertools.py Modified: python/trunk/Doc/library/itertools.rst ============================================================================== --- python/trunk/Doc/library/itertools.rst (original) +++ python/trunk/Doc/library/itertools.rst Fri Jan 2 22:26:45 2009 @@ -687,3 +687,27 @@ return indices[i:] = [indices[i] + 1] * (r - i) yield tuple(pool[i] for i in indices) + + def unique_everseen(iterable, key=None): + "List unique elements, preserving order. Remember all elements ever seen." + # unique_everseen('AAAABBBCCDAABBB') --> A B C D + # unique_everseen('ABBCcAD', str.lower) --> A B C D + seen = set() + seen_add = seen.add + if key is None: + for element in iterable: + if element not in seen: + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element + + def unique_justseen(iterable, key=None): + "List unique elements, preserving order. Remember only the element just seen." + # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B + # unique_justseen('ABBCcAD', str.lower) --> A B C A D + return imap(next, imap(itemgetter(1), groupby(iterable, key))) Modified: python/trunk/Lib/test/test_itertools.py ============================================================================== --- python/trunk/Lib/test/test_itertools.py (original) +++ python/trunk/Lib/test/test_itertools.py Fri Jan 2 22:26:45 2009 @@ -1277,6 +1277,30 @@ ... indices[i:] = [indices[i] + 1] * (r - i) ... yield tuple(pool[i] for i in indices) +>>> def unique_everseen(iterable, key=None): +... "List unique elements, preserving order. Remember all elements ever seen." +... # unique_everseen('AAAABBBCCDAABBB') --> A B C D +... # unique_everseen('ABBCcAD', str.lower) --> A B C D +... seen = set() +... seen_add = seen.add +... if key is None: +... for element in iterable: +... if element not in seen: +... seen_add(element) +... yield element +... else: +... for element in iterable: +... k = key(element) +... if k not in seen: +... seen_add(k) +... yield element + +>>> def unique_justseen(iterable, key=None): +... "List unique elements, preserving order. Remember only the element just seen." +... # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B +... # unique_justseen('ABBCcAD', str.lower) --> A B C A D +... return imap(next, imap(itemgetter(1), groupby(iterable, key))) + This is not part of the examples but it tests to make sure the definitions perform as purported. @@ -1339,6 +1363,18 @@ >>> list(combinations_with_replacement('abc', 2)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] +>>> list(unique_everseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D'] + +>>> list(unique_everseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'D'] + +>>> list(unique_justseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D', 'A', 'B'] + +>>> list(unique_justseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'A', 'D'] + """ __test__ = {'libreftest' : libreftest} From nnorwitz at gmail.com Fri Jan 2 22:27:10 2009 From: nnorwitz at gmail.com (Neal Norwitz) Date: Fri, 2 Jan 2009 16:27:10 -0500 Subject: [Python-checkins] Python Regression Test Failures opt (1) Message-ID: <20090102212710.GA374@python.psfb.org> 328 tests OK. 1 test failed: test_urllib2 33 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_bsddb3 test_cd test_cl test_curses test_epoll test_gl test_imgfile test_ioctl test_kqueue test_lib2to3 test_linuxaudiodev test_macos test_macostools test_multiprocessing test_ossaudiodev test_pep277 test_py3kwarn test_scriptpackages test_socketserver test_startfile test_sunaudiodev test_tcl test_timeout test_unicode_file test_urllib2net test_urllibnet test_winreg test_winsound test_zipfile64 4 skips unexpected on linux2: test_epoll test_multiprocessing test_lib2to3 test_ioctl test_grammar test_opcodes test_dict test_builtin test_exceptions test_types test_unittest test_doctest test_doctest2 test_MimeWriter test_SimpleHTTPServer test_StringIO test___all__ test___future__ test__locale test_abc test_abstract_numbers test_aepack test_aepack skipped -- No module named aepack test_al test_al skipped -- No module named al test_anydbm test_applesingle test_applesingle skipped -- No module named macostools test_array test_ast test_asynchat test_asyncore test_atexit test_audioop test_augassign test_base64 test_bastion test_bigaddrspace test_bigmem test_binascii test_binhex test_binop test_bisect test_bool test_bsddb test_bsddb185 test_bsddb185 skipped -- No module named bsddb185 test_bsddb3 test_bsddb3 skipped -- Use of the `bsddb' resource not enabled test_buffer test_bufio test_bytes test_bz2 test_calendar test_call test_capi test_cd test_cd skipped -- No module named cd test_cfgparser test_cgi test_charmapcodec test_cl test_cl skipped -- No module named cl test_class test_cmath test_cmd test_cmd_line test_cmd_line_script test_code test_codeccallbacks test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_codecs test_codeop test_coding test_coercion test_collections test_colorsys test_commands test_compare test_compile test_compiler test_complex test_complex_args test_contains test_contextlib test_cookie test_cookielib test_copy test_copy_reg test_cpickle test_cprofile test_crypt test_csv test_ctypes test_curses test_curses skipped -- Use of the `curses' resource not enabled test_datetime test_dbm test_decimal test_decorators test_defaultdict test_deque test_descr test_descrtut test_difflib test_dircache test_dis test_distutils [17051 refs] test_dl test_docxmlrpc test_dumbdbm test_dummy_thread test_dummy_threading test_email test_email_codecs test_email_renamed test_enumerate test_eof test_epoll test_epoll skipped -- kernel doesn't support epoll() test_errno test_exception_variations test_extcall test_fcntl test_file test_filecmp test_fileinput test_fileio test_float test_fnmatch test_fork1 test_format test_fpformat test_fractions test_frozen test_ftplib test_funcattrs test_functools test_future test_future3 test_future4 test_future5 test_future_builtins test_gc test_gdbm test_generators test_genericpath test_genexps test_getargs test_getargs2 test_getopt test_gettext test_gl test_gl skipped -- No module named gl test_glob test_global test_grp test_gzip test_hash test_hashlib test_heapq test_hmac test_hotshot test_htmllib test_htmlparser test_httplib test_httpservers [12871 refs] [12871 refs] [21405 refs] test_imageop test_imaplib test_imgfile test_imgfile skipped -- No module named imgfile test_imp test_import test_importhooks test_index test_inspect test_int test_int_literal test_io test_ioctl test_ioctl skipped -- Unable to open /dev/tty test_isinstance test_iter test_iterlen test_itertools test_json test_kqueue test_kqueue skipped -- test works only on BSD test_largefile test_lib2to3 test_lib2to3 skipped -- No module named myfixes test_linuxaudiodev test_linuxaudiodev skipped -- Use of the `audio' resource not enabled test_list test_locale test_logging test_long test_long_future test_longexp test_macos test_macos skipped -- No module named MacOS test_macostools test_macostools skipped -- No module named macostools test_macpath test_mailbox test_marshal test_math test_md5 test_memoryio test_mhlib test_mimetools test_mimetypes test_minidom test_mmap test_module test_modulefinder test_multibytecodec test_multibytecodec_support test_multifile test_multiprocessing test_multiprocessing skipped -- OSError raises on RLock creation, see issue 3111! test_mutants test_mutex test_netrc test_new test_nis test_normalization test_ntpath test_old_mailbox test_openpty test_operator test_optparse test_os /tmp/python-test/local/lib/python2.7/os.py:759: DeprecationWarning: integer argument expected, got float bs += read(_urandomfd, n - len(bs)) test_ossaudiodev test_ossaudiodev skipped -- Use of the `audio' resource not enabled test_parser Expecting 's_push: parser stack overflow' in next line s_push: parser stack overflow test_peepholer test_pep247 test_pep263 test_pep277 test_pep277 skipped -- test works only on NT+ test_pep292 test_pep352 test_pickle test_pickletools test_pipes test_pkg test_pkgimport test_pkgutil test_platform [14526 refs] [14526 refs] test_plistlib test_poll test_popen [12876 refs] [12876 refs] [12876 refs] test_popen2 test_poplib test_posix test_posixpath test_pow test_pprint test_print test_profile test_profilehooks test_property test_pstats test_pty test_pwd test_py3kwarn test_py3kwarn skipped -- test.test_py3kwarn must be run with the -3 flag test_pyclbr test_pydoc [17405 refs] test_pyexpat test_queue test_quopri [15396 refs] [15396 refs] test_random test_re test_repr test_resource test_rfc822 test_richcmp test_robotparser test_runpy test_sax test_scope test_scriptpackages test_scriptpackages skipped -- No module named aetools test_select test_set test_sets test_sgmllib test_sha test_shelve test_shlex test_shutil test_signal test_site [12871 refs] [12871 refs] [12874 refs] [12871 refs] test_slice test_smtplib test_socket test_socketserver test_socketserver skipped -- Use of the `network' resource not enabled test_softspace test_sort test_sqlite test_ssl test_startfile test_startfile skipped -- cannot import name startfile test_str test_strftime test_string test_stringprep test_strop test_strptime test_struct test_structmembers test_structseq test_subprocess [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [14771 refs] [13086 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] [12871 refs] . [12871 refs] [12871 refs] this bit of output is from a test of stdout in a different process ... [12871 refs] [12871 refs] [13086 refs] test_sunaudiodev test_sunaudiodev skipped -- No module named sunaudiodev test_sundry /tmp/python-test/local/lib/python2.7/test/test_sundry.py:67: DeprecationWarning: The posixfile module is deprecated; fcntl.lockf() provides better locking import posixfile test_symtable test_syntax test_sys [12871 refs] [12871 refs] [13100 refs] [12894 refs] test_tarfile test_tcl test_tcl skipped -- No module named _tkinter test_telnetlib test_tempfile [12874 refs] test_textwrap test_thread test_threaded_import test_threadedtempfile test_threading [16367 refs] [16857 refs] [15828 refs] [15828 refs] [15828 refs] [15828 refs] test_threading_local test_threadsignals test_time test_timeout test_timeout skipped -- Use of the `network' resource not enabled test_tokenize test_trace test_traceback test_transformer test_tuple test_typechecks test_ucn test_unary test_undocumented_details test_unicode test_unicode_file test_unicode_file skipped -- No Unicode filesystem semantics on this platform. test_unicodedata test_univnewlines test_unpack test_urllib test_urllib2 test test_urllib2 failed -- Traceback (most recent call last): File "/tmp/python-test/local/lib/python2.7/test/test_urllib2.py", line 653, in test_file h.file_open, Request(url)) File "/tmp/python-test/local/lib/python2.7/unittest.py", line 345, in failUnlessRaises callableObj(*args, **kwargs) File "/tmp/python-test/local/lib/python2.7/urllib2.py", line 1226, in file_open return self.open_local_file(req) File "/tmp/python-test/local/lib/python2.7/urllib2.py", line 1257, in open_local_file (not port and socket.gethostbyname(host) in self.get_names()): gaierror: [Errno -2] Name or service not known test_urllib2_localnet test_urllib2net test_urllib2net skipped -- Use of the `network' resource not enabled test_urllibnet test_urllibnet skipped -- Use of the `network' resource not enabled test_urlparse test_userdict test_userlist test_userstring test_uu test_uuid WARNING: uuid.getnode is unreliable on many platforms. It is disabled until the code and/or test can be fixed properly. WARNING: uuid._ifconfig_getnode is unreliable on many platforms. It is disabled until the code and/or test can be fixed properly. WARNING: uuid._unixdll_getnode is unreliable on many platforms. It is disabled until the code and/or test can be fixed properly. test_wait3 test_wait4 test_warnings test_wave test_weakref test_whichdb test_winreg test_winreg skipped -- No module named _winreg test_winsound test_winsound skipped -- No module named winsound test_with test_wsgiref test_xdrlib test_xml_etree test_xml_etree_c test_xmllib test_xmlrpc test_xpickle test_xrange test_zipfile test_zipfile64 test_zipfile64 skipped -- test requires loads of disk-space bytes and a long time to run test_zipimport test_zipimport_support test_zlib 328 tests OK. 1 test failed: test_urllib2 33 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_bsddb3 test_cd test_cl test_curses test_epoll test_gl test_imgfile test_ioctl test_kqueue test_lib2to3 test_linuxaudiodev test_macos test_macostools test_multiprocessing test_ossaudiodev test_pep277 test_py3kwarn test_scriptpackages test_socketserver test_startfile test_sunaudiodev test_tcl test_timeout test_unicode_file test_urllib2net test_urllibnet test_winreg test_winsound test_zipfile64 4 skips unexpected on linux2: test_epoll test_multiprocessing test_lib2to3 test_ioctl [654440 refs] From python-checkins at python.org Fri Jan 2 22:30:35 2009 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 2 Jan 2009 22:30:35 +0100 (CET) Subject: [Python-checkins] r68180 - in python/branches/release30-maint: Doc/library/itertools.rst Lib/test/test_itertools.py Message-ID: <20090102213035.D9EC31E4002@bag.python.org> Author: raymond.hettinger Date: Fri Jan 2 22:30:35 2009 New Revision: 68180 Log: Issue #4615. Document how to use itertools for de-duping. Modified: python/branches/release30-maint/Doc/library/itertools.rst python/branches/release30-maint/Lib/test/test_itertools.py Modified: python/branches/release30-maint/Doc/library/itertools.rst ============================================================================== --- python/branches/release30-maint/Doc/library/itertools.rst (original) +++ python/branches/release30-maint/Doc/library/itertools.rst Fri Jan 2 22:30:35 2009 @@ -606,3 +606,27 @@ return indices[i:] = [indices[i] + 1] * (r - i) yield tuple(pool[i] for i in indices) + + def unique_everseen(iterable, key=None): + "List unique elements, preserving order. Remember all elements ever seen." + # unique_everseen('AAAABBBCCDAABBB') --> A B C D + # unique_everseen('ABBCcAD', str.lower) --> A B C D + seen = set() + seen_add = seen.add + if key is None: + for element in iterable: + if element not in seen: + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element + + def unique_justseen(iterable, key=None): + "List unique elements, preserving order. Remember only the element just seen." + # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B + # unique_justseen('ABBCcAD', str.lower) --> A B C A D + return map(next, map(itemgetter(1), groupby(iterable, key))) Modified: python/branches/release30-maint/Lib/test/test_itertools.py ============================================================================== --- python/branches/release30-maint/Lib/test/test_itertools.py (original) +++ python/branches/release30-maint/Lib/test/test_itertools.py Fri Jan 2 22:30:35 2009 @@ -1298,6 +1298,30 @@ ... indices[i:] = [indices[i] + 1] * (r - i) ... yield tuple(pool[i] for i in indices) +>>> def unique_everseen(iterable, key=None): +... "List unique elements, preserving order. Remember all elements ever seen." +... # unique_everseen('AAAABBBCCDAABBB') --> A B C D +... # unique_everseen('ABBCcAD', str.lower) --> A B C D +... seen = set() +... seen_add = seen.add +... if key is None: +... for element in iterable: +... if element not in seen: +... seen_add(element) +... yield element +... else: +... for element in iterable: +... k = key(element) +... if k not in seen: +... seen_add(k) +... yield element + +>>> def unique_justseen(iterable, key=None): +... "List unique elements, preserving order. Remember only the element just seen." +... # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B +... # unique_justseen('ABBCcAD', str.lower) --> A B C A D +... return map(next, map(itemgetter(1), groupby(iterable, key))) + This is not part of the examples but it tests to make sure the definitions perform as purported. @@ -1360,6 +1384,18 @@ >>> list(combinations_with_replacement('abc', 2)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] +>>> list(unique_everseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D'] + +>>> list(unique_everseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'D'] + +>>> list(unique_justseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D', 'A', 'B'] + +>>> list(unique_justseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'A', 'D'] + """ __test__ = {'libreftest' : libreftest} From buildbot at python.org Fri Jan 2 22:32:36 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 21:32:36 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090102213236.BCF2B1E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/51 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: georg.brandl,martin.v.loewis BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_posix ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' sincerely, -The Buildbot From python-checkins at python.org Fri Jan 2 22:39:08 2009 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 2 Jan 2009 22:39:08 +0100 (CET) Subject: [Python-checkins] r68181 - in python/branches/py3k: Doc/library/itertools.rst Lib/test/test_itertools.py Message-ID: <20090102213908.10A601E4002@bag.python.org> Author: raymond.hettinger Date: Fri Jan 2 22:39:07 2009 New Revision: 68181 Log: Issue #4615. Document how to use itertools for de-duping. Modified: python/branches/py3k/Doc/library/itertools.rst python/branches/py3k/Lib/test/test_itertools.py Modified: python/branches/py3k/Doc/library/itertools.rst ============================================================================== --- python/branches/py3k/Doc/library/itertools.rst (original) +++ python/branches/py3k/Doc/library/itertools.rst Fri Jan 2 22:39:07 2009 @@ -606,3 +606,27 @@ return indices[i:] = [indices[i] + 1] * (r - i) yield tuple(pool[i] for i in indices) + + def unique_everseen(iterable, key=None): + "List unique elements, preserving order. Remember all elements ever seen." + # unique_everseen('AAAABBBCCDAABBB') --> A B C D + # unique_everseen('ABBCcAD', str.lower) --> A B C D + seen = set() + seen_add = seen.add + if key is None: + for element in iterable: + if element not in seen: + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element + + def unique_justseen(iterable, key=None): + "List unique elements, preserving order. Remember only the element just seen." + # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B + # unique_justseen('ABBCcAD', str.lower) --> A B C A D + return map(next, map(itemgetter(1), groupby(iterable, key))) Modified: python/branches/py3k/Lib/test/test_itertools.py ============================================================================== --- python/branches/py3k/Lib/test/test_itertools.py (original) +++ python/branches/py3k/Lib/test/test_itertools.py Fri Jan 2 22:39:07 2009 @@ -1298,6 +1298,30 @@ ... indices[i:] = [indices[i] + 1] * (r - i) ... yield tuple(pool[i] for i in indices) +>>> def unique_everseen(iterable, key=None): +... "List unique elements, preserving order. Remember all elements ever seen." +... # unique_everseen('AAAABBBCCDAABBB') --> A B C D +... # unique_everseen('ABBCcAD', str.lower) --> A B C D +... seen = set() +... seen_add = seen.add +... if key is None: +... for element in iterable: +... if element not in seen: +... seen_add(element) +... yield element +... else: +... for element in iterable: +... k = key(element) +... if k not in seen: +... seen_add(k) +... yield element + +>>> def unique_justseen(iterable, key=None): +... "List unique elements, preserving order. Remember only the element just seen." +... # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B +... # unique_justseen('ABBCcAD', str.lower) --> A B C A D +... return map(next, map(itemgetter(1), groupby(iterable, key))) + This is not part of the examples but it tests to make sure the definitions perform as purported. @@ -1360,6 +1384,18 @@ >>> list(combinations_with_replacement('abc', 2)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] +>>> list(unique_everseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D'] + +>>> list(unique_everseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'D'] + +>>> list(unique_justseen('AAAABBBCCDAABBB')) +['A', 'B', 'C', 'D', 'A', 'B'] + +>>> list(unique_justseen('ABBCcAD', str.lower)) +['A', 'B', 'C', 'A', 'D'] + """ __test__ = {'libreftest' : libreftest} From python-checkins at python.org Sat Jan 3 00:07:09 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 00:07:09 +0100 (CET) Subject: [Python-checkins] r68182 - in python/trunk: Lib/decimal.py Misc/NEWS Message-ID: <20090102230709.032011E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 00:07:08 2009 New Revision: 68182 Log: Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) Modified: python/trunk/Lib/decimal.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/decimal.py ============================================================================== --- python/trunk/Lib/decimal.py (original) +++ python/trunk/Lib/decimal.py Sat Jan 3 00:07:08 2009 @@ -216,7 +216,7 @@ if args: ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True) return ans._fix_nan(context) - return NaN + return _NaN class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. @@ -226,7 +226,7 @@ syntax. The result is [0,qNaN]. """ def handle(self, context, *args): - return NaN + return _NaN class DivisionByZero(DecimalException, ZeroDivisionError): """Division by 0. @@ -242,7 +242,7 @@ """ def handle(self, context, sign, *args): - return Infsign[sign] + return _Infsign[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -253,7 +253,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class DivisionUndefined(InvalidOperation, ZeroDivisionError): """Undefined result of division. @@ -264,7 +264,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Inexact(DecimalException): """Had to round, losing information. @@ -290,7 +290,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Rounded(DecimalException): """Number got rounded (not necessarily changed during rounding). @@ -340,15 +340,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return Infsign[sign] + return _Infsign[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1171,12 +1171,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return Infsign[resultsign] + return _Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return Infsign[resultsign] + return _Infsign[resultsign] resultexp = self._exp + other._exp @@ -1226,7 +1226,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return Infsign[sign] + return _Infsign[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1329,7 +1329,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (Infsign[sign], + return (_Infsign[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1477,7 +1477,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return Infsign[self._sign ^ other._sign] + return _Infsign[self._sign ^ other._sign] if not other: if self: @@ -1732,12 +1732,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2087,7 +2087,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return Dec_p1 + return _Dec_p1 # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2109,19 +2109,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return Infsign[result_sign] + return _Infsign[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == Dec_p1: + if self == _Dec_p1: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2154,7 +2154,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2674,9 +2674,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return Dec_n1 + return _Dec_n1 if not self._sign and other._sign: - return Dec_p1 + return _Dec_p1 sign = self._sign # let's handle both NaN types @@ -2686,51 +2686,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._int > other._int: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 if sign: if self_nan == 1: - return Dec_n1 + return _Dec_n1 if other_nan == 1: - return Dec_p1 + return _Dec_p1 if self_nan == 2: - return Dec_n1 + return _Dec_n1 if other_nan == 2: - return Dec_p1 + return _Dec_p1 else: if self_nan == 1: - return Dec_p1 + return _Dec_p1 if other_nan == 1: - return Dec_n1 + return _Dec_n1 if self_nan == 2: - return Dec_p1 + return _Dec_p1 if other_nan == 2: - return Dec_n1 + return _Dec_n1 if self < other: - return Dec_n1 + return _Dec_n1 if self > other: - return Dec_p1 + return _Dec_p1 if self._exp < other._exp: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._exp > other._exp: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 def compare_total_mag(self, other): @@ -2771,11 +2771,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return Dec_0 + return _Dec_0 # exp(0) = 1 if not self: - return Dec_p1 + return _Dec_p1 # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -2927,15 +2927,15 @@ # ln(0.0) == -Infinity if not self: - return negInf + return _negInf # ln(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # ln(1.0) == 0.0 - if self == Dec_p1: - return Dec_0 + if self == _Dec_p1: + return _Dec_0 # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3007,11 +3007,11 @@ # log10(0.0) == -Infinity if not self: - return negInf + return _negInf # log10(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3063,7 +3063,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return Inf + return _Inf # logb(0) = -Inf, DivisionByZero if not self: @@ -3220,7 +3220,7 @@ return ans if self._isinfinity() == -1: - return negInf + return _negInf if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3243,7 +3243,7 @@ return ans if self._isinfinity() == 1: - return Inf + return _Inf if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5490,15 +5490,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -Inf = Decimal('Inf') -negInf = Decimal('-Inf') -NaN = Decimal('NaN') -Dec_0 = Decimal(0) -Dec_p1 = Decimal(1) -Dec_n1 = Decimal(-1) +_Inf = Decimal('Inf') +_negInf = Decimal('-Inf') +_NaN = Decimal('NaN') +_Dec_0 = Decimal(0) +_Dec_p1 = Decimal(1) +_Dec_n1 = Decimal(-1) -# Infsign[sign] is infinity w/ that sign -Infsign = (Inf, negInf) +# _Infsign[sign] is infinity w/ that sign +_Infsign = (_Inf, _negInf) Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Sat Jan 3 00:07:08 2009 @@ -108,6 +108,9 @@ Library ------- +- Issue #4812: add missing underscore prefix to some internal-use-only + constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) + - Issue #4795: inspect.isgeneratorfunction() returns False instead of None when the function is not a generator. From python-checkins at python.org Sat Jan 3 00:16:52 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 00:16:52 +0100 (CET) Subject: [Python-checkins] r68183 - in python/branches/release26-maint: Lib/decimal.py Misc/NEWS Message-ID: <20090102231652.079671E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 00:16:51 2009 New Revision: 68183 Log: Merged revisions 68182 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68182 | mark.dickinson | 2009-01-02 23:07:08 +0000 (Fri, 02 Jan 2009) | 4 lines Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) ........ Modified: python/branches/release26-maint/ (props changed) python/branches/release26-maint/Lib/decimal.py python/branches/release26-maint/Misc/NEWS Modified: python/branches/release26-maint/Lib/decimal.py ============================================================================== --- python/branches/release26-maint/Lib/decimal.py (original) +++ python/branches/release26-maint/Lib/decimal.py Sat Jan 3 00:16:51 2009 @@ -216,7 +216,7 @@ if args: ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True) return ans._fix_nan(context) - return NaN + return _NaN class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. @@ -226,7 +226,7 @@ syntax. The result is [0,qNaN]. """ def handle(self, context, *args): - return NaN + return _NaN class DivisionByZero(DecimalException, ZeroDivisionError): """Division by 0. @@ -242,7 +242,7 @@ """ def handle(self, context, sign, *args): - return Infsign[sign] + return _Infsign[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -253,7 +253,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class DivisionUndefined(InvalidOperation, ZeroDivisionError): """Undefined result of division. @@ -264,7 +264,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Inexact(DecimalException): """Had to round, losing information. @@ -290,7 +290,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Rounded(DecimalException): """Number got rounded (not necessarily changed during rounding). @@ -340,15 +340,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return Infsign[sign] + return _Infsign[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1171,12 +1171,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return Infsign[resultsign] + return _Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return Infsign[resultsign] + return _Infsign[resultsign] resultexp = self._exp + other._exp @@ -1226,7 +1226,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return Infsign[sign] + return _Infsign[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1329,7 +1329,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (Infsign[sign], + return (_Infsign[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1477,7 +1477,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return Infsign[self._sign ^ other._sign] + return _Infsign[self._sign ^ other._sign] if not other: if self: @@ -1732,12 +1732,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2087,7 +2087,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return Dec_p1 + return _Dec_p1 # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2109,19 +2109,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return Infsign[result_sign] + return _Infsign[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == Dec_p1: + if self == _Dec_p1: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2154,7 +2154,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2674,9 +2674,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return Dec_n1 + return _Dec_n1 if not self._sign and other._sign: - return Dec_p1 + return _Dec_p1 sign = self._sign # let's handle both NaN types @@ -2686,51 +2686,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._int > other._int: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 if sign: if self_nan == 1: - return Dec_n1 + return _Dec_n1 if other_nan == 1: - return Dec_p1 + return _Dec_p1 if self_nan == 2: - return Dec_n1 + return _Dec_n1 if other_nan == 2: - return Dec_p1 + return _Dec_p1 else: if self_nan == 1: - return Dec_p1 + return _Dec_p1 if other_nan == 1: - return Dec_n1 + return _Dec_n1 if self_nan == 2: - return Dec_p1 + return _Dec_p1 if other_nan == 2: - return Dec_n1 + return _Dec_n1 if self < other: - return Dec_n1 + return _Dec_n1 if self > other: - return Dec_p1 + return _Dec_p1 if self._exp < other._exp: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._exp > other._exp: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 def compare_total_mag(self, other): @@ -2771,11 +2771,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return Dec_0 + return _Dec_0 # exp(0) = 1 if not self: - return Dec_p1 + return _Dec_p1 # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -2927,15 +2927,15 @@ # ln(0.0) == -Infinity if not self: - return negInf + return _negInf # ln(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # ln(1.0) == 0.0 - if self == Dec_p1: - return Dec_0 + if self == _Dec_p1: + return _Dec_0 # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3007,11 +3007,11 @@ # log10(0.0) == -Infinity if not self: - return negInf + return _negInf # log10(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3063,7 +3063,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return Inf + return _Inf # logb(0) = -Inf, DivisionByZero if not self: @@ -3220,7 +3220,7 @@ return ans if self._isinfinity() == -1: - return negInf + return _negInf if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3243,7 +3243,7 @@ return ans if self._isinfinity() == 1: - return Inf + return _Inf if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5490,15 +5490,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -Inf = Decimal('Inf') -negInf = Decimal('-Inf') -NaN = Decimal('NaN') -Dec_0 = Decimal(0) -Dec_p1 = Decimal(1) -Dec_n1 = Decimal(-1) +_Inf = Decimal('Inf') +_negInf = Decimal('-Inf') +_NaN = Decimal('NaN') +_Dec_0 = Decimal(0) +_Dec_p1 = Decimal(1) +_Dec_n1 = Decimal(-1) -# Infsign[sign] is infinity w/ that sign -Infsign = (Inf, negInf) +# _Infsign[sign] is infinity w/ that sign +_Infsign = (_Inf, _negInf) Modified: python/branches/release26-maint/Misc/NEWS ============================================================================== --- python/branches/release26-maint/Misc/NEWS (original) +++ python/branches/release26-maint/Misc/NEWS Sat Jan 3 00:16:51 2009 @@ -150,6 +150,9 @@ Library ------- +- Issue #4812: add missing underscore prefix to some internal-use-only + constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) + - Issue #4795: inspect.isgeneratorfunction() returns False instead of None when the function is not a generator. From python-checkins at python.org Sat Jan 3 00:23:21 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 00:23:21 +0100 (CET) Subject: [Python-checkins] r68184 - in python/branches/py3k: Lib/decimal.py Misc/NEWS Message-ID: <20090102232321.A01901E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 00:23:21 2009 New Revision: 68184 Log: Merged revisions 68182 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68182 | mark.dickinson | 2009-01-02 23:07:08 +0000 (Fri, 02 Jan 2009) | 4 lines Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/decimal.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/decimal.py ============================================================================== --- python/branches/py3k/Lib/decimal.py (original) +++ python/branches/py3k/Lib/decimal.py Sat Jan 3 00:23:21 2009 @@ -217,7 +217,7 @@ if args: ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True) return ans._fix_nan(context) - return NaN + return _NaN class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. @@ -227,7 +227,7 @@ syntax. The result is [0,qNaN]. """ def handle(self, context, *args): - return NaN + return _NaN class DivisionByZero(DecimalException, ZeroDivisionError): """Division by 0. @@ -243,7 +243,7 @@ """ def handle(self, context, sign, *args): - return Infsign[sign] + return _Infsign[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -254,7 +254,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class DivisionUndefined(InvalidOperation, ZeroDivisionError): """Undefined result of division. @@ -265,7 +265,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Inexact(DecimalException): """Had to round, losing information. @@ -291,7 +291,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Rounded(DecimalException): """Number got rounded (not necessarily changed during rounding). @@ -341,15 +341,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return Infsign[sign] + return _Infsign[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1173,12 +1173,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return Infsign[resultsign] + return _Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return Infsign[resultsign] + return _Infsign[resultsign] resultexp = self._exp + other._exp @@ -1228,7 +1228,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return Infsign[sign] + return _Infsign[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1328,7 +1328,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (Infsign[sign], + return (_Infsign[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1476,7 +1476,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return Infsign[self._sign ^ other._sign] + return _Infsign[self._sign ^ other._sign] if not other: if self: @@ -1820,12 +1820,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2175,7 +2175,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return Dec_p1 + return _Dec_p1 # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2197,19 +2197,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return Infsign[result_sign] + return _Infsign[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == Dec_p1: + if self == _Dec_p1: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2242,7 +2242,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2762,9 +2762,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return Dec_n1 + return _Dec_n1 if not self._sign and other._sign: - return Dec_p1 + return _Dec_p1 sign = self._sign # let's handle both NaN types @@ -2774,51 +2774,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._int > other._int: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 if sign: if self_nan == 1: - return Dec_n1 + return _Dec_n1 if other_nan == 1: - return Dec_p1 + return _Dec_p1 if self_nan == 2: - return Dec_n1 + return _Dec_n1 if other_nan == 2: - return Dec_p1 + return _Dec_p1 else: if self_nan == 1: - return Dec_p1 + return _Dec_p1 if other_nan == 1: - return Dec_n1 + return _Dec_n1 if self_nan == 2: - return Dec_p1 + return _Dec_p1 if other_nan == 2: - return Dec_n1 + return _Dec_n1 if self < other: - return Dec_n1 + return _Dec_n1 if self > other: - return Dec_p1 + return _Dec_p1 if self._exp < other._exp: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._exp > other._exp: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 def compare_total_mag(self, other): @@ -2859,11 +2859,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return Dec_0 + return _Dec_0 # exp(0) = 1 if not self: - return Dec_p1 + return _Dec_p1 # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -3015,15 +3015,15 @@ # ln(0.0) == -Infinity if not self: - return negInf + return _negInf # ln(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # ln(1.0) == 0.0 - if self == Dec_p1: - return Dec_0 + if self == _Dec_p1: + return _Dec_0 # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3095,11 +3095,11 @@ # log10(0.0) == -Infinity if not self: - return negInf + return _negInf # log10(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3151,7 +3151,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return Inf + return _Inf # logb(0) = -Inf, DivisionByZero if not self: @@ -3308,7 +3308,7 @@ return ans if self._isinfinity() == -1: - return negInf + return _negInf if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3331,7 +3331,7 @@ return ans if self._isinfinity() == 1: - return Inf + return _Inf if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5572,15 +5572,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -Inf = Decimal('Inf') -negInf = Decimal('-Inf') -NaN = Decimal('NaN') -Dec_0 = Decimal(0) -Dec_p1 = Decimal(1) -Dec_n1 = Decimal(-1) +_Inf = Decimal('Inf') +_negInf = Decimal('-Inf') +_NaN = Decimal('NaN') +_Dec_0 = Decimal(0) +_Dec_p1 = Decimal(1) +_Dec_n1 = Decimal(-1) -# Infsign[sign] is infinity w/ that sign -Infsign = (Inf, negInf) +# _Infsign[sign] is infinity w/ that sign +_Infsign = (_Inf, _negInf) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Jan 3 00:23:21 2009 @@ -78,6 +78,9 @@ Library ------- +- Issue #4812: add missing underscore prefix to some internal-use-only + constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) + - Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case no MSVC compiler is found under Windows. Original patch by Philip Jenvey. From python-checkins at python.org Sat Jan 3 00:28:00 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 00:28:00 +0100 (CET) Subject: [Python-checkins] r68185 - in python/branches/release30-maint: Lib/decimal.py Misc/NEWS Message-ID: <20090102232800.D815F1E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 00:28:00 2009 New Revision: 68185 Log: Merged revisions 68184 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r68184 | mark.dickinson | 2009-01-02 23:23:21 +0000 (Fri, 02 Jan 2009) | 10 lines Merged revisions 68182 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68182 | mark.dickinson | 2009-01-02 23:07:08 +0000 (Fri, 02 Jan 2009) | 4 lines Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) ........ ................ Modified: python/branches/release30-maint/ (props changed) python/branches/release30-maint/Lib/decimal.py python/branches/release30-maint/Misc/NEWS Modified: python/branches/release30-maint/Lib/decimal.py ============================================================================== --- python/branches/release30-maint/Lib/decimal.py (original) +++ python/branches/release30-maint/Lib/decimal.py Sat Jan 3 00:28:00 2009 @@ -217,7 +217,7 @@ if args: ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True) return ans._fix_nan(context) - return NaN + return _NaN class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. @@ -227,7 +227,7 @@ syntax. The result is [0,qNaN]. """ def handle(self, context, *args): - return NaN + return _NaN class DivisionByZero(DecimalException, ZeroDivisionError): """Division by 0. @@ -243,7 +243,7 @@ """ def handle(self, context, sign, *args): - return Infsign[sign] + return _Infsign[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -254,7 +254,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class DivisionUndefined(InvalidOperation, ZeroDivisionError): """Undefined result of division. @@ -265,7 +265,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Inexact(DecimalException): """Had to round, losing information. @@ -291,7 +291,7 @@ """ def handle(self, context, *args): - return NaN + return _NaN class Rounded(DecimalException): """Number got rounded (not necessarily changed during rounding). @@ -341,15 +341,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return Infsign[sign] + return _Infsign[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return Infsign[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1173,12 +1173,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return Infsign[resultsign] + return _Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return Infsign[resultsign] + return _Infsign[resultsign] resultexp = self._exp + other._exp @@ -1228,7 +1228,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return Infsign[sign] + return _Infsign[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1328,7 +1328,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (Infsign[sign], + return (_Infsign[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1476,7 +1476,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return Infsign[self._sign ^ other._sign] + return _Infsign[self._sign ^ other._sign] if not other: if self: @@ -1820,12 +1820,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = Infsign[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2175,7 +2175,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return Dec_p1 + return _Dec_p1 # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2197,19 +2197,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return Infsign[result_sign] + return _Infsign[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == Dec_p1: + if self == _Dec_p1: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2242,7 +2242,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return Infsign[result_sign] + return _Infsign[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2762,9 +2762,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return Dec_n1 + return _Dec_n1 if not self._sign and other._sign: - return Dec_p1 + return _Dec_p1 sign = self._sign # let's handle both NaN types @@ -2774,51 +2774,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._int > other._int: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 if sign: if self_nan == 1: - return Dec_n1 + return _Dec_n1 if other_nan == 1: - return Dec_p1 + return _Dec_p1 if self_nan == 2: - return Dec_n1 + return _Dec_n1 if other_nan == 2: - return Dec_p1 + return _Dec_p1 else: if self_nan == 1: - return Dec_p1 + return _Dec_p1 if other_nan == 1: - return Dec_n1 + return _Dec_n1 if self_nan == 2: - return Dec_p1 + return _Dec_p1 if other_nan == 2: - return Dec_n1 + return _Dec_n1 if self < other: - return Dec_n1 + return _Dec_n1 if self > other: - return Dec_p1 + return _Dec_p1 if self._exp < other._exp: if sign: - return Dec_p1 + return _Dec_p1 else: - return Dec_n1 + return _Dec_n1 if self._exp > other._exp: if sign: - return Dec_n1 + return _Dec_n1 else: - return Dec_p1 - return Dec_0 + return _Dec_p1 + return _Dec_0 def compare_total_mag(self, other): @@ -2859,11 +2859,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return Dec_0 + return _Dec_0 # exp(0) = 1 if not self: - return Dec_p1 + return _Dec_p1 # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -3015,15 +3015,15 @@ # ln(0.0) == -Infinity if not self: - return negInf + return _negInf # ln(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # ln(1.0) == 0.0 - if self == Dec_p1: - return Dec_0 + if self == _Dec_p1: + return _Dec_0 # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3095,11 +3095,11 @@ # log10(0.0) == -Infinity if not self: - return negInf + return _negInf # log10(Infinity) = Infinity if self._isinfinity() == 1: - return Inf + return _Inf # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3151,7 +3151,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return Inf + return _Inf # logb(0) = -Inf, DivisionByZero if not self: @@ -3308,7 +3308,7 @@ return ans if self._isinfinity() == -1: - return negInf + return _negInf if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3331,7 +3331,7 @@ return ans if self._isinfinity() == 1: - return Inf + return _Inf if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5572,15 +5572,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -Inf = Decimal('Inf') -negInf = Decimal('-Inf') -NaN = Decimal('NaN') -Dec_0 = Decimal(0) -Dec_p1 = Decimal(1) -Dec_n1 = Decimal(-1) +_Inf = Decimal('Inf') +_negInf = Decimal('-Inf') +_NaN = Decimal('NaN') +_Dec_0 = Decimal(0) +_Dec_p1 = Decimal(1) +_Dec_n1 = Decimal(-1) -# Infsign[sign] is infinity w/ that sign -Infsign = (Inf, negInf) +# _Infsign[sign] is infinity w/ that sign +_Infsign = (_Inf, _negInf) Modified: python/branches/release30-maint/Misc/NEWS ============================================================================== --- python/branches/release30-maint/Misc/NEWS (original) +++ python/branches/release30-maint/Misc/NEWS Sat Jan 3 00:28:00 2009 @@ -48,6 +48,9 @@ Library ------- +- Issue #4812: add missing underscore prefix to some internal-use-only + constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) + - Issue 4790: The nsmallest() and nlargest() functions in the heapq module did unnecessary work in the common case where no key function was specified. From buildbot at python.org Sat Jan 3 00:43:15 2009 From: buildbot at python.org (buildbot at python.org) Date: Fri, 02 Jan 2009 23:43:15 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090102234315.213631E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/53 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: raymond.hettinger BUILD FAILED: failed test Excerpt from the test logfile: 3 tests failed: test_distutils test_posix test_subprocess ====================================================================== FAIL: test_get_python_inc (distutils.tests.test_sysconfig.SysconfigTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/distutils/tests/test_sysconfig.py", line 43, in test_get_python_inc self.assert_(os.path.isdir(inc_dir), inc_dir) AssertionError: /home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/Include ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' ====================================================================== FAIL: test_executable (test.test_subprocess.ProcessTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_subprocess.py", line 149, in test_executable self.assertEqual(p.returncode, 47) AssertionError: -6 != 47 sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 01:22:45 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 00:22:45 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.0 Message-ID: <20090103002245.9C3101E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.0/builds/22 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_posix ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.0.loewis-sun/build/@test.getcwd/@test.getcwd' sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 08:46:36 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 08:46:36 +0100 (CET) Subject: [Python-checkins] r68186 - python/branches/release26-maint/Doc/library/decimal.rst Message-ID: <20090103074636.987911E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 08:46:36 2009 New Revision: 68186 Log: Simplify one of the decimal recipes. Modified: python/branches/release26-maint/Doc/library/decimal.rst Modified: python/branches/release26-maint/Doc/library/decimal.rst ============================================================================== --- python/branches/release26-maint/Doc/library/decimal.rst (original) +++ python/branches/release26-maint/Doc/library/decimal.rst Sat Jan 3 08:46:36 2009 @@ -1880,13 +1880,13 @@ def float_to_decimal(f): "Convert a floating point number to a Decimal with no loss of information" n, d = f.as_integer_ratio() - with localcontext() as ctx: - ctx.traps[Inexact] = True - while True: - try: - return Decimal(n) / Decimal(d) - except Inexact: - ctx.prec += 1 + numerator, denominator = Decimal(n), Decimal(d) + ctx = Context(prec=60) + result = ctx.divide(numerator, denominator) + while ctx.flags[Inexact]: + ctx.prec *= 2 + result = ctx.divide(numerator, denominator) + return result .. doctest:: From python-checkins at python.org Sat Jan 3 08:50:46 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 08:50:46 +0100 (CET) Subject: [Python-checkins] r68187 - python/branches/release26-maint/Doc/library/decimal.rst Message-ID: <20090103075046.7A19A1E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 08:50:46 2009 New Revision: 68187 Log: Lost one line on a decimal recipe. Modified: python/branches/release26-maint/Doc/library/decimal.rst Modified: python/branches/release26-maint/Doc/library/decimal.rst ============================================================================== --- python/branches/release26-maint/Doc/library/decimal.rst (original) +++ python/branches/release26-maint/Doc/library/decimal.rst Sat Jan 3 08:50:46 2009 @@ -1884,6 +1884,7 @@ ctx = Context(prec=60) result = ctx.divide(numerator, denominator) while ctx.flags[Inexact]: + ctx.flags[Inexact] = False ctx.prec *= 2 result = ctx.divide(numerator, denominator) return result From python-checkins at python.org Sat Jan 3 10:24:19 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 10:24:19 +0100 (CET) Subject: [Python-checkins] r68188 - in python/branches/release26-maint: Lib/fractions.py Lib/test/test_fractions.py Misc/NEWS Message-ID: <20090103092419.202201E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 10:24:18 2009 New Revision: 68188 Log: Fractions.from_float() no longer loses precision with large integer inputs. Modified: python/branches/release26-maint/Lib/fractions.py python/branches/release26-maint/Lib/test/test_fractions.py python/branches/release26-maint/Misc/NEWS Modified: python/branches/release26-maint/Lib/fractions.py ============================================================================== --- python/branches/release26-maint/Lib/fractions.py (original) +++ python/branches/release26-maint/Lib/fractions.py Sat Jan 3 10:24:18 2009 @@ -111,7 +111,7 @@ """ if isinstance(f, numbers.Integral): - f = float(f) + return cls(f) elif not isinstance(f, float): raise TypeError("%s.from_float() only takes floats, not %r (%s)" % (cls.__name__, f, type(f).__name__)) Modified: python/branches/release26-maint/Lib/test/test_fractions.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_fractions.py (original) +++ python/branches/release26-maint/Lib/test/test_fractions.py Sat Jan 3 10:24:18 2009 @@ -139,6 +139,8 @@ def testFromFloat(self): self.assertRaises(TypeError, F.from_float, 3+4j) self.assertEquals((10, 1), _components(F.from_float(10))) + bigint = 1234567890123456789 + self.assertEquals((bigint, 1), _components(F.from_float(bigint))) self.assertEquals((0, 1), _components(F.from_float(-0.0))) self.assertEquals((10, 1), _components(F.from_float(10.0))) self.assertEquals((-5, 2), _components(F.from_float(-2.5))) Modified: python/branches/release26-maint/Misc/NEWS ============================================================================== --- python/branches/release26-maint/Misc/NEWS (original) +++ python/branches/release26-maint/Misc/NEWS Sat Jan 3 10:24:18 2009 @@ -56,6 +56,9 @@ Library ------- +- Fractions.from_float() no longer loses precision for integers to big to + cast as floats. + - Issue 4790: The nsmallest() and nlargest() functions in the heapq module did unnecessary work in the common case where no key function was specified. From python-checkins at python.org Sat Jan 3 10:27:09 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 10:27:09 +0100 (CET) Subject: [Python-checkins] r68189 - in python/branches/release30-maint: Lib/fractions.py Lib/test/test_fractions.py Misc/NEWS Message-ID: <20090103092709.46F641E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 10:27:08 2009 New Revision: 68189 Log: Fractions.from_float() no longer loses precision with large integer inputs. Modified: python/branches/release30-maint/Lib/fractions.py python/branches/release30-maint/Lib/test/test_fractions.py python/branches/release30-maint/Misc/NEWS Modified: python/branches/release30-maint/Lib/fractions.py ============================================================================== --- python/branches/release30-maint/Lib/fractions.py (original) +++ python/branches/release30-maint/Lib/fractions.py Sat Jan 3 10:27:08 2009 @@ -109,7 +109,7 @@ """ if isinstance(f, numbers.Integral): - f = float(f) + return cls(f) elif not isinstance(f, float): raise TypeError("%s.from_float() only takes floats, not %r (%s)" % (cls.__name__, f, type(f).__name__)) Modified: python/branches/release30-maint/Lib/test/test_fractions.py ============================================================================== --- python/branches/release30-maint/Lib/test/test_fractions.py (original) +++ python/branches/release30-maint/Lib/test/test_fractions.py Sat Jan 3 10:27:08 2009 @@ -136,6 +136,8 @@ def testFromFloat(self): self.assertRaises(TypeError, F.from_float, 3+4j) self.assertEquals((10, 1), _components(F.from_float(10))) + bigint = 1234567890123456789 + self.assertEquals((bigint, 1), _components(F.from_float(bigint))) self.assertEquals((0, 1), _components(F.from_float(-0.0))) self.assertEquals((10, 1), _components(F.from_float(10.0))) self.assertEquals((-5, 2), _components(F.from_float(-2.5))) Modified: python/branches/release30-maint/Misc/NEWS ============================================================================== --- python/branches/release30-maint/Misc/NEWS (original) +++ python/branches/release30-maint/Misc/NEWS Sat Jan 3 10:27:08 2009 @@ -48,6 +48,9 @@ Library ------- +- Fractions.from_float() no longer loses precision for integers too big to + cast as floats. + - Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) From python-checkins at python.org Sat Jan 3 10:27:41 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 10:27:41 +0100 (CET) Subject: [Python-checkins] r68190 - python/branches/release26-maint/Misc/NEWS Message-ID: <20090103092741.9E6BC1E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 10:27:41 2009 New Revision: 68190 Log: Fix spelling. Modified: python/branches/release26-maint/Misc/NEWS Modified: python/branches/release26-maint/Misc/NEWS ============================================================================== --- python/branches/release26-maint/Misc/NEWS (original) +++ python/branches/release26-maint/Misc/NEWS Sat Jan 3 10:27:41 2009 @@ -56,7 +56,7 @@ Library ------- -- Fractions.from_float() no longer loses precision for integers to big to +- Fractions.from_float() no longer loses precision for integers too big to cast as floats. - Issue 4790: The nsmallest() and nlargest() functions in the heapq module From python-checkins at python.org Sat Jan 3 13:07:21 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 13:07:21 +0100 (CET) Subject: [Python-checkins] r68191 - python/trunk/Lib/decimal.py Message-ID: <20090103120721.2DCDF1E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 13:07:20 2009 New Revision: 68191 Log: Issue #4812: further renaming of internal Decimal constants, for clarity. Modified: python/trunk/Lib/decimal.py Modified: python/trunk/Lib/decimal.py ============================================================================== --- python/trunk/Lib/decimal.py (original) +++ python/trunk/Lib/decimal.py Sat Jan 3 13:07:20 2009 @@ -242,7 +242,7 @@ """ def handle(self, context, sign, *args): - return _Infsign[sign] + return _SignedInfinity[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -340,15 +340,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return _Infsign[sign] + return _SignedInfinity[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1171,12 +1171,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] resultexp = self._exp + other._exp @@ -1226,7 +1226,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return _Infsign[sign] + return _SignedInfinity[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1329,7 +1329,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (_Infsign[sign], + return (_SignedInfinity[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1477,7 +1477,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return _Infsign[self._sign ^ other._sign] + return _SignedInfinity[self._sign ^ other._sign] if not other: if self: @@ -1732,12 +1732,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2087,7 +2087,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return _Dec_p1 + return _One # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2109,19 +2109,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == _Dec_p1: + if self == _One: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2154,7 +2154,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2674,9 +2674,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return _Dec_n1 + return _NegativeOne if not self._sign and other._sign: - return _Dec_p1 + return _One sign = self._sign # let's handle both NaN types @@ -2686,51 +2686,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._int > other._int: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero if sign: if self_nan == 1: - return _Dec_n1 + return _NegativeOne if other_nan == 1: - return _Dec_p1 + return _One if self_nan == 2: - return _Dec_n1 + return _NegativeOne if other_nan == 2: - return _Dec_p1 + return _One else: if self_nan == 1: - return _Dec_p1 + return _One if other_nan == 1: - return _Dec_n1 + return _NegativeOne if self_nan == 2: - return _Dec_p1 + return _One if other_nan == 2: - return _Dec_n1 + return _NegativeOne if self < other: - return _Dec_n1 + return _NegativeOne if self > other: - return _Dec_p1 + return _One if self._exp < other._exp: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._exp > other._exp: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero def compare_total_mag(self, other): @@ -2771,11 +2771,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return _Dec_0 + return _Zero # exp(0) = 1 if not self: - return _Dec_p1 + return _One # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -2927,15 +2927,15 @@ # ln(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # ln(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # ln(1.0) == 0.0 - if self == _Dec_p1: - return _Dec_0 + if self == _One: + return _Zero # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3007,11 +3007,11 @@ # log10(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # log10(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3063,7 +3063,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return _Inf + return _Infinity # logb(0) = -Inf, DivisionByZero if not self: @@ -3220,7 +3220,7 @@ return ans if self._isinfinity() == -1: - return _negInf + return _NegativeInfinity if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3243,7 +3243,7 @@ return ans if self._isinfinity() == 1: - return _Inf + return _Infinity if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5490,15 +5490,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -_Inf = Decimal('Inf') -_negInf = Decimal('-Inf') +_Infinity = Decimal('Inf') +_NegativeInfinity = Decimal('-Inf') _NaN = Decimal('NaN') -_Dec_0 = Decimal(0) -_Dec_p1 = Decimal(1) -_Dec_n1 = Decimal(-1) +_Zero = Decimal(0) +_One = Decimal(1) +_NegativeOne = Decimal(-1) -# _Infsign[sign] is infinity w/ that sign -_Infsign = (_Inf, _negInf) +# _SignedInfinity[sign] is infinity w/ that sign +_SignedInfinity = (_Infinity, _NegativeInfinity) From python-checkins at python.org Sat Jan 3 13:09:22 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 13:09:22 +0100 (CET) Subject: [Python-checkins] r68192 - in python/branches/release26-maint: Lib/decimal.py Message-ID: <20090103120922.E881E1E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 13:09:22 2009 New Revision: 68192 Log: Merged revisions 68191 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68191 | mark.dickinson | 2009-01-03 12:07:20 +0000 (Sat, 03 Jan 2009) | 2 lines Issue #4812: further renaming of internal Decimal constants, for clarity. ........ Modified: python/branches/release26-maint/ (props changed) python/branches/release26-maint/Lib/decimal.py Modified: python/branches/release26-maint/Lib/decimal.py ============================================================================== --- python/branches/release26-maint/Lib/decimal.py (original) +++ python/branches/release26-maint/Lib/decimal.py Sat Jan 3 13:09:22 2009 @@ -242,7 +242,7 @@ """ def handle(self, context, sign, *args): - return _Infsign[sign] + return _SignedInfinity[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -340,15 +340,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return _Infsign[sign] + return _SignedInfinity[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1171,12 +1171,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] resultexp = self._exp + other._exp @@ -1226,7 +1226,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return _Infsign[sign] + return _SignedInfinity[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1329,7 +1329,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (_Infsign[sign], + return (_SignedInfinity[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1477,7 +1477,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return _Infsign[self._sign ^ other._sign] + return _SignedInfinity[self._sign ^ other._sign] if not other: if self: @@ -1732,12 +1732,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2087,7 +2087,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return _Dec_p1 + return _One # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2109,19 +2109,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == _Dec_p1: + if self == _One: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2154,7 +2154,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2674,9 +2674,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return _Dec_n1 + return _NegativeOne if not self._sign and other._sign: - return _Dec_p1 + return _One sign = self._sign # let's handle both NaN types @@ -2686,51 +2686,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._int > other._int: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero if sign: if self_nan == 1: - return _Dec_n1 + return _NegativeOne if other_nan == 1: - return _Dec_p1 + return _One if self_nan == 2: - return _Dec_n1 + return _NegativeOne if other_nan == 2: - return _Dec_p1 + return _One else: if self_nan == 1: - return _Dec_p1 + return _One if other_nan == 1: - return _Dec_n1 + return _NegativeOne if self_nan == 2: - return _Dec_p1 + return _One if other_nan == 2: - return _Dec_n1 + return _NegativeOne if self < other: - return _Dec_n1 + return _NegativeOne if self > other: - return _Dec_p1 + return _One if self._exp < other._exp: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._exp > other._exp: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero def compare_total_mag(self, other): @@ -2771,11 +2771,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return _Dec_0 + return _Zero # exp(0) = 1 if not self: - return _Dec_p1 + return _One # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -2927,15 +2927,15 @@ # ln(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # ln(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # ln(1.0) == 0.0 - if self == _Dec_p1: - return _Dec_0 + if self == _One: + return _Zero # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3007,11 +3007,11 @@ # log10(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # log10(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3063,7 +3063,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return _Inf + return _Infinity # logb(0) = -Inf, DivisionByZero if not self: @@ -3220,7 +3220,7 @@ return ans if self._isinfinity() == -1: - return _negInf + return _NegativeInfinity if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3243,7 +3243,7 @@ return ans if self._isinfinity() == 1: - return _Inf + return _Infinity if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5490,15 +5490,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -_Inf = Decimal('Inf') -_negInf = Decimal('-Inf') +_Infinity = Decimal('Inf') +_NegativeInfinity = Decimal('-Inf') _NaN = Decimal('NaN') -_Dec_0 = Decimal(0) -_Dec_p1 = Decimal(1) -_Dec_n1 = Decimal(-1) +_Zero = Decimal(0) +_One = Decimal(1) +_NegativeOne = Decimal(-1) -# _Infsign[sign] is infinity w/ that sign -_Infsign = (_Inf, _negInf) +# _SignedInfinity[sign] is infinity w/ that sign +_SignedInfinity = (_Infinity, _NegativeInfinity) From python-checkins at python.org Sat Jan 3 13:11:47 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 13:11:47 +0100 (CET) Subject: [Python-checkins] r68193 - in python/branches/py3k: Lib/decimal.py Message-ID: <20090103121147.E8D631E4002@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 13:11:47 2009 New Revision: 68193 Log: Merged revisions 68191 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68191 | mark.dickinson | 2009-01-03 12:07:20 +0000 (Sat, 03 Jan 2009) | 2 lines Issue #4812: further renaming of internal Decimal constants, for clarity. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/decimal.py Modified: python/branches/py3k/Lib/decimal.py ============================================================================== --- python/branches/py3k/Lib/decimal.py (original) +++ python/branches/py3k/Lib/decimal.py Sat Jan 3 13:11:47 2009 @@ -243,7 +243,7 @@ """ def handle(self, context, sign, *args): - return _Infsign[sign] + return _SignedInfinity[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -341,15 +341,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return _Infsign[sign] + return _SignedInfinity[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1173,12 +1173,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] resultexp = self._exp + other._exp @@ -1228,7 +1228,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return _Infsign[sign] + return _SignedInfinity[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1328,7 +1328,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (_Infsign[sign], + return (_SignedInfinity[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1476,7 +1476,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return _Infsign[self._sign ^ other._sign] + return _SignedInfinity[self._sign ^ other._sign] if not other: if self: @@ -1820,12 +1820,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2175,7 +2175,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return _Dec_p1 + return _One # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2197,19 +2197,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == _Dec_p1: + if self == _One: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2242,7 +2242,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2762,9 +2762,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return _Dec_n1 + return _NegativeOne if not self._sign and other._sign: - return _Dec_p1 + return _One sign = self._sign # let's handle both NaN types @@ -2774,51 +2774,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._int > other._int: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero if sign: if self_nan == 1: - return _Dec_n1 + return _NegativeOne if other_nan == 1: - return _Dec_p1 + return _One if self_nan == 2: - return _Dec_n1 + return _NegativeOne if other_nan == 2: - return _Dec_p1 + return _One else: if self_nan == 1: - return _Dec_p1 + return _One if other_nan == 1: - return _Dec_n1 + return _NegativeOne if self_nan == 2: - return _Dec_p1 + return _One if other_nan == 2: - return _Dec_n1 + return _NegativeOne if self < other: - return _Dec_n1 + return _NegativeOne if self > other: - return _Dec_p1 + return _One if self._exp < other._exp: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._exp > other._exp: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero def compare_total_mag(self, other): @@ -2859,11 +2859,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return _Dec_0 + return _Zero # exp(0) = 1 if not self: - return _Dec_p1 + return _One # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -3015,15 +3015,15 @@ # ln(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # ln(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # ln(1.0) == 0.0 - if self == _Dec_p1: - return _Dec_0 + if self == _One: + return _Zero # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3095,11 +3095,11 @@ # log10(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # log10(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3151,7 +3151,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return _Inf + return _Infinity # logb(0) = -Inf, DivisionByZero if not self: @@ -3308,7 +3308,7 @@ return ans if self._isinfinity() == -1: - return _negInf + return _NegativeInfinity if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3331,7 +3331,7 @@ return ans if self._isinfinity() == 1: - return _Inf + return _Infinity if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5572,15 +5572,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -_Inf = Decimal('Inf') -_negInf = Decimal('-Inf') +_Infinity = Decimal('Inf') +_NegativeInfinity = Decimal('-Inf') _NaN = Decimal('NaN') -_Dec_0 = Decimal(0) -_Dec_p1 = Decimal(1) -_Dec_n1 = Decimal(-1) +_Zero = Decimal(0) +_One = Decimal(1) +_NegativeOne = Decimal(-1) -# _Infsign[sign] is infinity w/ that sign -_Infsign = (_Inf, _negInf) +# _SignedInfinity[sign] is infinity w/ that sign +_SignedInfinity = (_Infinity, _NegativeInfinity) From python-checkins at python.org Sat Jan 3 13:15:35 2009 From: python-checkins at python.org (mark.dickinson) Date: Sat, 3 Jan 2009 13:15:35 +0100 (CET) Subject: [Python-checkins] r68194 - in python/branches/release30-maint: Lib/decimal.py Message-ID: <20090103121535.840B41E401C@bag.python.org> Author: mark.dickinson Date: Sat Jan 3 13:15:35 2009 New Revision: 68194 Log: Merged revisions 68193 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r68193 | mark.dickinson | 2009-01-03 12:11:47 +0000 (Sat, 03 Jan 2009) | 9 lines Merged revisions 68191 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68191 | mark.dickinson | 2009-01-03 12:07:20 +0000 (Sat, 03 Jan 2009) | 2 lines Issue #4812: further renaming of internal Decimal constants, for clarity. ........ ................ Modified: python/branches/release30-maint/ (props changed) python/branches/release30-maint/Lib/decimal.py Modified: python/branches/release30-maint/Lib/decimal.py ============================================================================== --- python/branches/release30-maint/Lib/decimal.py (original) +++ python/branches/release30-maint/Lib/decimal.py Sat Jan 3 13:15:35 2009 @@ -243,7 +243,7 @@ """ def handle(self, context, sign, *args): - return _Infsign[sign] + return _SignedInfinity[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -341,15 +341,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return _Infsign[sign] + return _SignedInfinity[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1173,12 +1173,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] resultexp = self._exp + other._exp @@ -1228,7 +1228,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return _Infsign[sign] + return _SignedInfinity[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1328,7 +1328,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (_Infsign[sign], + return (_SignedInfinity[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1476,7 +1476,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return _Infsign[self._sign ^ other._sign] + return _SignedInfinity[self._sign ^ other._sign] if not other: if self: @@ -1820,12 +1820,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2175,7 +2175,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return _Dec_p1 + return _One # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2197,19 +2197,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == _Dec_p1: + if self == _One: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2242,7 +2242,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2762,9 +2762,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return _Dec_n1 + return _NegativeOne if not self._sign and other._sign: - return _Dec_p1 + return _One sign = self._sign # let's handle both NaN types @@ -2774,51 +2774,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._int > other._int: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero if sign: if self_nan == 1: - return _Dec_n1 + return _NegativeOne if other_nan == 1: - return _Dec_p1 + return _One if self_nan == 2: - return _Dec_n1 + return _NegativeOne if other_nan == 2: - return _Dec_p1 + return _One else: if self_nan == 1: - return _Dec_p1 + return _One if other_nan == 1: - return _Dec_n1 + return _NegativeOne if self_nan == 2: - return _Dec_p1 + return _One if other_nan == 2: - return _Dec_n1 + return _NegativeOne if self < other: - return _Dec_n1 + return _NegativeOne if self > other: - return _Dec_p1 + return _One if self._exp < other._exp: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._exp > other._exp: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero def compare_total_mag(self, other): @@ -2859,11 +2859,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return _Dec_0 + return _Zero # exp(0) = 1 if not self: - return _Dec_p1 + return _One # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -3015,15 +3015,15 @@ # ln(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # ln(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # ln(1.0) == 0.0 - if self == _Dec_p1: - return _Dec_0 + if self == _One: + return _Zero # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3095,11 +3095,11 @@ # log10(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # log10(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3151,7 +3151,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return _Inf + return _Infinity # logb(0) = -Inf, DivisionByZero if not self: @@ -3308,7 +3308,7 @@ return ans if self._isinfinity() == -1: - return _negInf + return _NegativeInfinity if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3331,7 +3331,7 @@ return ans if self._isinfinity() == 1: - return _Inf + return _Infinity if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5572,15 +5572,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -_Inf = Decimal('Inf') -_negInf = Decimal('-Inf') +_Infinity = Decimal('Inf') +_NegativeInfinity = Decimal('-Inf') _NaN = Decimal('NaN') -_Dec_0 = Decimal(0) -_Dec_p1 = Decimal(1) -_Dec_n1 = Decimal(-1) +_Zero = Decimal(0) +_One = Decimal(1) +_NegativeOne = Decimal(-1) -# _Infsign[sign] is infinity w/ that sign -_Infsign = (_Inf, _negInf) +# _SignedInfinity[sign] is infinity w/ that sign +_SignedInfinity = (_Infinity, _NegativeInfinity) From buildbot at python.org Sat Jan 3 13:32:40 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 12:32:40 +0000 Subject: [Python-checkins] buildbot failure in x86 gentoo trunk Message-ID: <20090103123240.55B0E1E4002@bag.python.org> The Buildbot has detected a new failure of x86 gentoo trunk. Full details are available at: http://www.python.org/dev/buildbot/all/x86%20gentoo%20trunk/builds/4411 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: norwitz-x86 Build Reason: Build Source Stamp: [branch trunk] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_pickletools make: *** [buildbottest] Error 1 sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 13:57:40 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 12:57:40 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090103125740.9BA5E1E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/55 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: 2 tests failed: test_distutils test_posix ====================================================================== FAIL: test_get_python_inc (distutils.tests.test_sysconfig.SysconfigTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/distutils/tests/test_sysconfig.py", line 43, in test_get_python_inc self.assert_(os.path.isdir(inc_dir), inc_dir) AssertionError: /home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/Include ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 14:26:21 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 13:26:21 +0000 Subject: [Python-checkins] buildbot failure in i386 Ubuntu 3.x Message-ID: <20090103132622.2CE0B1E4002@bag.python.org> The Buildbot has detected a new failure of i386 Ubuntu 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/i386%20Ubuntu%203.x/builds/58 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-i386 Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 14:38:12 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 13:38:12 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.0 Message-ID: <20090103133812.725561E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.0/builds/24 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_posix ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.0.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.0.loewis-sun/build/@test.getcwd/@test.getcwd' sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 14:45:15 2009 From: python-checkins at python.org (georg.brandl) Date: Sat, 3 Jan 2009 14:45:15 +0100 (CET) Subject: [Python-checkins] r68195 - python/trunk/Parser/asdl.py Message-ID: <20090103134515.C6C141E4002@bag.python.org> Author: georg.brandl Date: Sat Jan 3 14:45:15 2009 New Revision: 68195 Log: Remove useless string literal. Modified: python/trunk/Parser/asdl.py Modified: python/trunk/Parser/asdl.py ============================================================================== --- python/trunk/Parser/asdl.py (original) +++ python/trunk/Parser/asdl.py Sat Jan 3 14:45:15 2009 @@ -167,7 +167,7 @@ return Product(fields) def p_sum_0(self, (constructor,)): - " sum ::= constructor """ + " sum ::= constructor " return [constructor] def p_sum_1(self, (constructor, _, sum)): From buildbot at python.org Sat Jan 3 15:02:06 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 14:02:06 +0000 Subject: [Python-checkins] buildbot failure in i386 Ubuntu 3.0 Message-ID: <20090103140207.188391E4002@bag.python.org> The Buildbot has detected a new failure of i386 Ubuntu 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/i386%20Ubuntu%203.0/builds/25 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-i386 Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 15:12:02 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 14:12:02 +0000 Subject: [Python-checkins] buildbot failure in ia64 Ubuntu 2.6 Message-ID: <20090103141202.E02511E4002@bag.python.org> The Buildbot has detected a new failure of ia64 Ubuntu 2.6. Full details are available at: http://www.python.org/dev/buildbot/all/ia64%20Ubuntu%202.6/builds/26 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-ia64 Build Reason: Build Source Stamp: [branch branches/release26-maint] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 15:13:04 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 14:13:04 +0000 Subject: [Python-checkins] buildbot failure in sparc Ubuntu 3.x Message-ID: <20090103141305.87E0B1E4002@bag.python.org> The Buildbot has detected a new failure of sparc Ubuntu 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Ubuntu%203.x/builds/45 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-sparc Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 15:26:29 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 14:26:29 +0000 Subject: [Python-checkins] buildbot failure in sparc Debian 2.6 Message-ID: <20090103142629.6188E1E4002@bag.python.org> The Buildbot has detected a new failure of sparc Debian 2.6. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Debian%202.6/builds/22 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-sparc Build Reason: Build Source Stamp: [branch branches/release26-maint] HEAD Blamelist: raymond.hettinger BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 15:29:54 2009 From: python-checkins at python.org (georg.brandl) Date: Sat, 3 Jan 2009 15:29:54 +0100 (CET) Subject: [Python-checkins] r68196 - python/trunk/Doc/library/multiprocessing.rst Message-ID: <20090103142954.06CD51E4002@bag.python.org> Author: georg.brandl Date: Sat Jan 3 15:29:53 2009 New Revision: 68196 Log: Fix indentation. Modified: python/trunk/Doc/library/multiprocessing.rst Modified: python/trunk/Doc/library/multiprocessing.rst ============================================================================== --- python/trunk/Doc/library/multiprocessing.rst (original) +++ python/trunk/Doc/library/multiprocessing.rst Sat Jan 3 15:29:53 2009 @@ -109,12 +109,12 @@ def f(q): q.put([42, None, 'hello']) - if __name__ == '__main__': - q = Queue() - p = Process(target=f, args=(q,)) - p.start() - print q.get() # prints "[42, None, 'hello']" - p.join() + if __name__ == '__main__': + q = Queue() + p = Process(target=f, args=(q,)) + p.start() + print q.get() # prints "[42, None, 'hello']" + p.join() Queues are thread and process safe. From buildbot at python.org Sat Jan 3 15:48:25 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 14:48:25 +0000 Subject: [Python-checkins] buildbot failure in i386 Ubuntu trunk Message-ID: <20090103144826.1D5761E4002@bag.python.org> The Buildbot has detected a new failure of i386 Ubuntu trunk. Full details are available at: http://www.python.org/dev/buildbot/all/i386%20Ubuntu%20trunk/builds/640 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-i386 Build Reason: Build Source Stamp: [branch trunk] HEAD Blamelist: georg.brandl BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 16:09:09 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 15:09:09 +0000 Subject: [Python-checkins] buildbot failure in ia64 Ubuntu 3.x Message-ID: <20090103150909.71C3C1E4002@bag.python.org> The Buildbot has detected a new failure of ia64 Ubuntu 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/ia64%20Ubuntu%203.x/builds/48 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-ia64 Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 16:53:25 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 15:53:25 +0000 Subject: [Python-checkins] buildbot failure in sparc Ubuntu 3.0 Message-ID: <20090103155325.801431E4002@bag.python.org> The Buildbot has detected a new failure of sparc Ubuntu 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Ubuntu%203.0/builds/23 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-sparc Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 17:12:29 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 16:12:29 +0000 Subject: [Python-checkins] buildbot failure in ia64 Ubuntu 3.0 Message-ID: <20090103161229.C24D91E4002@bag.python.org> The Buildbot has detected a new failure of ia64 Ubuntu 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/ia64%20Ubuntu%203.0/builds/23 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-ia64 Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 17:15:41 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 16:15:41 +0000 Subject: [Python-checkins] buildbot failure in sparc Debian trunk Message-ID: <20090103161541.46C2B1E4002@bag.python.org> The Buildbot has detected a new failure of sparc Debian trunk. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Debian%20trunk/builds/935 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-sparc Build Reason: Build Source Stamp: [branch trunk] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 17:34:03 2009 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 3 Jan 2009 17:34:03 +0100 (CET) Subject: [Python-checkins] r68197 - in python/trunk/Lib/lib2to3: fixer_util.py fixes/fix_execfile.py fixes/fix_import.py fixes/fix_imports.py fixes/fix_long.py main.py refactor.py tests/data/py3_test_grammar.py tests/test_fixers.py Message-ID: <20090103163403.1044D1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Jan 3 17:34:02 2009 New Revision: 68197 Log: Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved also add unittests for the fixer ........ r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line remove unused import ........ r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line copy permission bits from the backup to the original ........ r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line ........ r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line don't need loop ........ r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line actually call finish_tree() ........ r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line remove useless test ........ r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line update pyk3's test grammar ........ r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line #2734 don't convert every instance of long (eg if it's an attribute) ........ r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line add another test ........ r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line don't change long even if it's the only argument name ........ r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line remove unused import ........ Modified: python/trunk/Lib/lib2to3/ (props changed) python/trunk/Lib/lib2to3/fixer_util.py python/trunk/Lib/lib2to3/fixes/fix_execfile.py python/trunk/Lib/lib2to3/fixes/fix_import.py python/trunk/Lib/lib2to3/fixes/fix_imports.py python/trunk/Lib/lib2to3/fixes/fix_long.py python/trunk/Lib/lib2to3/main.py python/trunk/Lib/lib2to3/refactor.py python/trunk/Lib/lib2to3/tests/data/py3_test_grammar.py python/trunk/Lib/lib2to3/tests/test_fixers.py Modified: python/trunk/Lib/lib2to3/fixer_util.py ============================================================================== --- python/trunk/Lib/lib2to3/fixer_util.py (original) +++ python/trunk/Lib/lib2to3/fixer_util.py Sat Jan 3 17:34:02 2009 @@ -222,6 +222,29 @@ return True return False +def is_probably_builtin(node): + """ + Check that something isn't an attribute or function name etc. + """ + prev = node.get_prev_sibling() + if prev is not None and prev.type == token.DOT: + # Attribute lookup. + return False + parent = node.parent + if parent.type in (syms.funcdef, syms.classdef): + return False + if parent.type == syms.expr_stmt and parent.children[0] is node: + # Assignment. + return False + if parent.type == syms.parameters or \ + (parent.type == syms.typedargslist and ( + (prev is not None and prev.type == token.COMMA) or + parent.children[0] is node + )): + # The name of an argument. + return False + return True + ########################################################### ### The following functions are to find bindings in a suite ########################################################### Modified: python/trunk/Lib/lib2to3/fixes/fix_execfile.py ============================================================================== --- python/trunk/Lib/lib2to3/fixes/fix_execfile.py (original) +++ python/trunk/Lib/lib2to3/fixes/fix_execfile.py Sat Jan 3 17:34:02 2009 @@ -7,9 +7,9 @@ exec() function. """ -from .. import pytree from .. import fixer_base -from ..fixer_util import Comma, Name, Call, LParen, RParen, Dot +from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node, + ArgList, String, syms) class FixExecfile(fixer_base.BaseFix): @@ -22,16 +22,30 @@ def transform(self, node, results): assert results - syms = self.syms filename = results["filename"] globals = results.get("globals") locals = results.get("locals") - args = [Name('open'), LParen(), filename.clone(), RParen(), Dot(), - Name('read'), LParen(), RParen()] - args[0].set_prefix("") + + # Copy over the prefix from the right parentheses end of the execfile + # call. + execfile_paren = node.children[-1].children[-1].clone() + # Construct open().read(). + open_args = ArgList([filename.clone()], rparen=execfile_paren) + open_call = Node(syms.power, [Name("open"), open_args]) + read = [Node(syms.trailer, [Dot(), Name('read')]), + Node(syms.trailer, [LParen(), RParen()])] + open_expr = [open_call] + read + # Wrap the open call in a compile call. This is so the filename will be + # preserved in the execed code. + filename_arg = filename.clone() + filename_arg.set_prefix(" ") + exec_str = String("'exec'", " ") + compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str] + compile_call = Call(Name("compile"), compile_args, "") + # Finally, replace the execfile call with an exec call. + args = [compile_call] if globals is not None: args.extend([Comma(), globals.clone()]) if locals is not None: args.extend([Comma(), locals.clone()]) - return Call(Name("exec"), args, prefix=node.get_prefix()) Modified: python/trunk/Lib/lib2to3/fixes/fix_import.py ============================================================================== --- python/trunk/Lib/lib2to3/fixes/fix_import.py (original) +++ python/trunk/Lib/lib2to3/fixes/fix_import.py Sat Jan 3 17:34:02 2009 @@ -13,55 +13,78 @@ # Local imports from .. import fixer_base from os.path import dirname, join, exists, pathsep -from ..fixer_util import FromImport, syms +from ..fixer_util import FromImport, syms, token + + +def traverse_imports(names): + """ + Walks over all the names imported in a dotted_as_names node. + """ + pending = [names] + while pending: + node = pending.pop() + if node.type == token.NAME: + yield node.value + elif node.type == syms.dotted_name: + yield "".join([ch.value for ch in node.children]) + elif node.type == syms.dotted_as_name: + pending.append(node.children[0]) + elif node.type == syms.dotted_as_names: + pending.extend(node.children[::-2]) + else: + raise AssertionError("unkown node type") + class FixImport(fixer_base.BaseFix): PATTERN = """ - import_from< type='from' imp=any 'import' ['('] any [')'] > + import_from< 'from' imp=any 'import' ['('] any [')'] > | - import_name< type='import' imp=any > + import_name< 'import' imp=any > """ def transform(self, node, results): imp = results['imp'] - mod_name = unicode(imp.children[0] if imp.type == syms.dotted_as_name \ - else imp) - - if mod_name.startswith('.'): - # Already a new-style import - return - - if not probably_a_local_import(mod_name, self.filename): - # I guess this is a global import -- skip it! - return - - if results['type'].value == 'from': + if node.type == syms.import_from: # Some imps are top-level (eg: 'import ham') # some are first level (eg: 'import ham.eggs') # some are third level (eg: 'import ham.eggs as spam') # Hence, the loop while not hasattr(imp, 'value'): imp = imp.children[0] - imp.value = "." + imp.value - node.changed() + if self.probably_a_local_import(imp.value): + imp.value = "." + imp.value + imp.changed() + return node else: - new = FromImport('.', getattr(imp, 'content', None) or [imp]) + have_local = False + have_absolute = False + for mod_name in traverse_imports(imp): + if self.probably_a_local_import(mod_name): + have_local = True + else: + have_absolute = True + if have_absolute: + if have_local: + # We won't handle both sibling and absolute imports in the + # same statement at the moment. + self.warning(node, "absolute and local imports together") + return + + new = FromImport('.', [imp]) new.set_prefix(node.get_prefix()) - node = new - return node + return new -def probably_a_local_import(imp_name, file_path): - # Must be stripped because the right space is included by the parser - imp_name = imp_name.split('.', 1)[0].strip() - base_path = dirname(file_path) - base_path = join(base_path, imp_name) - # If there is no __init__.py next to the file its not in a package - # so can't be a relative import. - if not exists(join(dirname(base_path), '__init__.py')): + def probably_a_local_import(self, imp_name): + imp_name = imp_name.split('.', 1)[0] + base_path = dirname(self.filename) + base_path = join(base_path, imp_name) + # If there is no __init__.py next to the file its not in a package + # so can't be a relative import. + if not exists(join(dirname(base_path), '__init__.py')): + return False + for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: + if exists(base_path + ext): + return True return False - for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: - if exists(base_path + ext): - return True - return False Modified: python/trunk/Lib/lib2to3/fixes/fix_imports.py ============================================================================== --- python/trunk/Lib/lib2to3/fixes/fix_imports.py (original) +++ python/trunk/Lib/lib2to3/fixes/fix_imports.py Sat Jan 3 17:34:02 2009 @@ -118,7 +118,7 @@ def transform(self, node, results): import_mod = results.get("module_name") if import_mod: - new_name = self.mapping[(import_mod or mod_name).value] + new_name = self.mapping[import_mod.value] import_mod.replace(Name(new_name, prefix=import_mod.get_prefix())) if "name_import" in results: # If it's not a "from x import x, y" or "import x as y" import, @@ -129,10 +129,8 @@ # line (e.g., "import StringIO, urlparse"). The problem is that I # can't figure out an easy way to make a pattern recognize the # keys of MAPPING randomly sprinkled in an import statement. - while True: - results = self.match(node) - if not results: - break + results = self.match(node) + if results: self.transform(node, results) else: # Replace usage of the module. Modified: python/trunk/Lib/lib2to3/fixes/fix_long.py ============================================================================== --- python/trunk/Lib/lib2to3/fixes/fix_long.py (original) +++ python/trunk/Lib/lib2to3/fixes/fix_long.py Sat Jan 3 17:34:02 2009 @@ -5,20 +5,18 @@ """ # Local imports -from .. import pytree from .. import fixer_base -from ..fixer_util import Name, Number +from ..fixer_util import Name, Number, is_probably_builtin class FixLong(fixer_base.BaseFix): PATTERN = "'long'" - static_long = Name("long") static_int = Name("int") def transform(self, node, results): - assert node == self.static_long, node - new = self.static_int.clone() - new.set_prefix(node.get_prefix()) - return new + if is_probably_builtin(node): + new = self.static_int.clone() + new.set_prefix(node.get_prefix()) + return new Modified: python/trunk/Lib/lib2to3/main.py ============================================================================== --- python/trunk/Lib/lib2to3/main.py (original) +++ python/trunk/Lib/lib2to3/main.py Sat Jan 3 17:34:02 2009 @@ -41,7 +41,7 @@ super(StdoutRefactoringTool, self).write_file(new_text, filename, old_text) if not self.nobackups: - shutil.copymode(filename, backup) + shutil.copymode(backup, filename) def print_output(self, lines): for line in lines: Modified: python/trunk/Lib/lib2to3/refactor.py ============================================================================== --- python/trunk/Lib/lib2to3/refactor.py (original) +++ python/trunk/Lib/lib2to3/refactor.py Sat Jan 3 17:34:02 2009 @@ -287,17 +287,13 @@ Returns: True if the tree was modified, False otherwise. """ - # Two calls to chain are required because pre_order.values() - # will be a list of lists of fixers: - # [[, ], []] - all_fixers = chain(self.pre_order, self.post_order) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.start_tree(tree, name) self.traverse_by(self.pre_order_heads, tree.pre_order()) self.traverse_by(self.post_order_heads, tree.post_order()) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.finish_tree(tree, name) return tree.was_changed Modified: python/trunk/Lib/lib2to3/tests/data/py3_test_grammar.py ============================================================================== --- python/trunk/Lib/lib2to3/tests/data/py3_test_grammar.py (original) +++ python/trunk/Lib/lib2to3/tests/data/py3_test_grammar.py Sat Jan 3 17:34:02 2009 @@ -485,6 +485,14 @@ global a, b global one, two, three, four, five, six, seven, eight, nine, ten + def testNonlocal(self): + # 'nonlocal' NAME (',' NAME)* + x = 0 + y = 0 + def f(): + nonlocal x + nonlocal x, y + def testAssert(self): # assert_stmt: 'assert' test [',' test] assert 1 Modified: python/trunk/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/trunk/Lib/lib2to3/tests/test_fixers.py (original) +++ python/trunk/Lib/lib2to3/tests/test_fixers.py Sat Jan 3 17:34:02 2009 @@ -1073,11 +1073,72 @@ a = """z = type(x) in (int, int)""" self.check(b, a) + def test_unchanged(self): + s = """long = True""" + self.unchanged(s) + + s = """s.long = True""" + self.unchanged(s) + + s = """def long(): pass""" + self.unchanged(s) + + s = """class long(): pass""" + self.unchanged(s) + + s = """def f(long): pass""" + self.unchanged(s) + + s = """def f(g, long): pass""" + self.unchanged(s) + + s = """def f(x, long=True): pass""" + self.unchanged(s) + def test_prefix_preservation(self): b = """x = long( x )""" a = """x = int( x )""" self.check(b, a) + +class Test_execfile(FixerTestCase): + fixer = "execfile" + + def test_conversion(self): + b = """execfile("fn")""" + a = """exec(compile(open("fn").read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)""" + self.check(b, a) + + b = """execfile("fn", glob, loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)""" + self.check(b, a) + + b = """execfile("fn", locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob, locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)""" + self.check(b, a) + + def test_spacing(self): + b = """execfile( "fn" )""" + a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", globals = glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)""" + self.check(b, a) + + class Test_isinstance(FixerTestCase): fixer = "isinstance" @@ -3466,11 +3527,30 @@ a = "from . import foo, bar" self.check_both(b, a) + b = "import foo, bar, x" + a = "from . import foo, bar, x" + self.check_both(b, a) + + b = "import x, y, z" + a = "from . import x, y, z" + self.check_both(b, a) + def test_import_as(self): b = "import foo as x" a = "from . import foo as x" self.check_both(b, a) + b = "import a as b, b as c, c as d" + a = "from . import a as b, b as c, c as d" + self.check_both(b, a) + + def test_local_and_absolute(self): + self.always_exists = False + self.present_files = set(["foo.py", "__init__.py"]) + + s = "import foo, bar" + self.warns_unchanged(s, "absolute and local imports together") + def test_dotted_import(self): b = "import foo.bar" a = "from . import foo.bar" From python-checkins at python.org Sat Jan 3 17:53:14 2009 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 3 Jan 2009 17:53:14 +0100 (CET) Subject: [Python-checkins] r68198 - in python/branches/py3k: Lib/lib2to3/fixer_util.py Lib/lib2to3/fixes/fix_execfile.py Lib/lib2to3/fixes/fix_import.py Lib/lib2to3/fixes/fix_imports.py Lib/lib2to3/fixes/fix_long.py Lib/lib2to3/main.py Lib/lib2to3/refactor.py Lib/lib2to3/tests/data/py3_test_grammar.py Lib/lib2to3/tests/test_fixers.py Message-ID: <20090103165314.5B55A1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Jan 3 17:53:14 2009 New Revision: 68198 Log: Merged revisions 68197 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved also add unittests for the fixer ........ r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line remove unused import ........ r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line copy permission bits from the backup to the original ........ r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line ........ r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line don't need loop ........ r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line actually call finish_tree() ........ r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line remove useless test ........ r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line update pyk3's test grammar ........ r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line #2734 don't convert every instance of long (eg if it's an attribute) ........ r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line add another test ........ r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line don't change long even if it's the only argument name ........ r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line remove unused import ........ ................ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/lib2to3/fixer_util.py python/branches/py3k/Lib/lib2to3/fixes/fix_execfile.py python/branches/py3k/Lib/lib2to3/fixes/fix_import.py python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py python/branches/py3k/Lib/lib2to3/fixes/fix_long.py python/branches/py3k/Lib/lib2to3/main.py python/branches/py3k/Lib/lib2to3/refactor.py python/branches/py3k/Lib/lib2to3/tests/data/py3_test_grammar.py python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Modified: python/branches/py3k/Lib/lib2to3/fixer_util.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixer_util.py (original) +++ python/branches/py3k/Lib/lib2to3/fixer_util.py Sat Jan 3 17:53:14 2009 @@ -222,6 +222,29 @@ return True return False +def is_probably_builtin(node): + """ + Check that something isn't an attribute or function name etc. + """ + prev = node.get_prev_sibling() + if prev is not None and prev.type == token.DOT: + # Attribute lookup. + return False + parent = node.parent + if parent.type in (syms.funcdef, syms.classdef): + return False + if parent.type == syms.expr_stmt and parent.children[0] is node: + # Assignment. + return False + if parent.type == syms.parameters or \ + (parent.type == syms.typedargslist and ( + (prev is not None and prev.type == token.COMMA) or + parent.children[0] is node + )): + # The name of an argument. + return False + return True + ########################################################### ### The following functions are to find bindings in a suite ########################################################### Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_execfile.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_execfile.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_execfile.py Sat Jan 3 17:53:14 2009 @@ -7,9 +7,9 @@ exec() function. """ -from .. import pytree from .. import fixer_base -from ..fixer_util import Comma, Name, Call, LParen, RParen, Dot +from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node, + ArgList, String, syms) class FixExecfile(fixer_base.BaseFix): @@ -22,16 +22,30 @@ def transform(self, node, results): assert results - syms = self.syms filename = results["filename"] globals = results.get("globals") locals = results.get("locals") - args = [Name('open'), LParen(), filename.clone(), RParen(), Dot(), - Name('read'), LParen(), RParen()] - args[0].set_prefix("") + + # Copy over the prefix from the right parentheses end of the execfile + # call. + execfile_paren = node.children[-1].children[-1].clone() + # Construct open().read(). + open_args = ArgList([filename.clone()], rparen=execfile_paren) + open_call = Node(syms.power, [Name("open"), open_args]) + read = [Node(syms.trailer, [Dot(), Name('read')]), + Node(syms.trailer, [LParen(), RParen()])] + open_expr = [open_call] + read + # Wrap the open call in a compile call. This is so the filename will be + # preserved in the execed code. + filename_arg = filename.clone() + filename_arg.set_prefix(" ") + exec_str = String("'exec'", " ") + compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str] + compile_call = Call(Name("compile"), compile_args, "") + # Finally, replace the execfile call with an exec call. + args = [compile_call] if globals is not None: args.extend([Comma(), globals.clone()]) if locals is not None: args.extend([Comma(), locals.clone()]) - return Call(Name("exec"), args, prefix=node.get_prefix()) Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_import.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_import.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_import.py Sat Jan 3 17:53:14 2009 @@ -13,55 +13,78 @@ # Local imports from .. import fixer_base from os.path import dirname, join, exists, pathsep -from ..fixer_util import FromImport, syms +from ..fixer_util import FromImport, syms, token + + +def traverse_imports(names): + """ + Walks over all the names imported in a dotted_as_names node. + """ + pending = [names] + while pending: + node = pending.pop() + if node.type == token.NAME: + yield node.value + elif node.type == syms.dotted_name: + yield "".join([ch.value for ch in node.children]) + elif node.type == syms.dotted_as_name: + pending.append(node.children[0]) + elif node.type == syms.dotted_as_names: + pending.extend(node.children[::-2]) + else: + raise AssertionError("unkown node type") + class FixImport(fixer_base.BaseFix): PATTERN = """ - import_from< type='from' imp=any 'import' ['('] any [')'] > + import_from< 'from' imp=any 'import' ['('] any [')'] > | - import_name< type='import' imp=any > + import_name< 'import' imp=any > """ def transform(self, node, results): imp = results['imp'] - mod_name = str(imp.children[0] if imp.type == syms.dotted_as_name \ - else imp) - - if str(imp).startswith('.'): - # Already a new-style import - return - - if not probably_a_local_import(str(mod_name), self.filename): - # I guess this is a global import -- skip it! - return - - if results['type'].value == 'from': + if node.type == syms.import_from: # Some imps are top-level (eg: 'import ham') # some are first level (eg: 'import ham.eggs') # some are third level (eg: 'import ham.eggs as spam') # Hence, the loop while not hasattr(imp, 'value'): imp = imp.children[0] - imp.value = "." + imp.value - node.changed() + if self.probably_a_local_import(imp.value): + imp.value = "." + imp.value + imp.changed() + return node else: - new = FromImport('.', getattr(imp, 'content', None) or [imp]) + have_local = False + have_absolute = False + for mod_name in traverse_imports(imp): + if self.probably_a_local_import(mod_name): + have_local = True + else: + have_absolute = True + if have_absolute: + if have_local: + # We won't handle both sibling and absolute imports in the + # same statement at the moment. + self.warning(node, "absolute and local imports together") + return + + new = FromImport('.', [imp]) new.set_prefix(node.get_prefix()) - node = new - return node + return new -def probably_a_local_import(imp_name, file_path): - # Must be stripped because the right space is included by the parser - imp_name = imp_name.split('.', 1)[0].strip() - base_path = dirname(file_path) - base_path = join(base_path, imp_name) - # If there is no __init__.py next to the file its not in a package - # so can't be a relative import. - if not exists(join(dirname(base_path), '__init__.py')): + def probably_a_local_import(self, imp_name): + imp_name = imp_name.split('.', 1)[0] + base_path = dirname(self.filename) + base_path = join(base_path, imp_name) + # If there is no __init__.py next to the file its not in a package + # so can't be a relative import. + if not exists(join(dirname(base_path), '__init__.py')): + return False + for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: + if exists(base_path + ext): + return True return False - for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: - if exists(base_path + ext): - return True - return False Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py Sat Jan 3 17:53:14 2009 @@ -118,7 +118,7 @@ def transform(self, node, results): import_mod = results.get("module_name") if import_mod: - new_name = self.mapping[(import_mod or mod_name).value] + new_name = self.mapping[import_mod.value] import_mod.replace(Name(new_name, prefix=import_mod.get_prefix())) if "name_import" in results: # If it's not a "from x import x, y" or "import x as y" import, @@ -129,10 +129,8 @@ # line (e.g., "import StringIO, urlparse"). The problem is that I # can't figure out an easy way to make a pattern recognize the # keys of MAPPING randomly sprinkled in an import statement. - while True: - results = self.match(node) - if not results: - break + results = self.match(node) + if results: self.transform(node, results) else: # Replace usage of the module. Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_long.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_long.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_long.py Sat Jan 3 17:53:14 2009 @@ -5,20 +5,18 @@ """ # Local imports -from .. import pytree from .. import fixer_base -from ..fixer_util import Name, Number +from ..fixer_util import Name, Number, is_probably_builtin class FixLong(fixer_base.BaseFix): PATTERN = "'long'" - static_long = Name("long") static_int = Name("int") def transform(self, node, results): - assert node == self.static_long, node - new = self.static_int.clone() - new.set_prefix(node.get_prefix()) - return new + if is_probably_builtin(node): + new = self.static_int.clone() + new.set_prefix(node.get_prefix()) + return new Modified: python/branches/py3k/Lib/lib2to3/main.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/main.py (original) +++ python/branches/py3k/Lib/lib2to3/main.py Sat Jan 3 17:53:14 2009 @@ -41,7 +41,7 @@ super(StdoutRefactoringTool, self).write_file(new_text, filename, old_text) if not self.nobackups: - shutil.copymode(filename, backup) + shutil.copymode(backup, filename) def print_output(self, lines): for line in lines: Modified: python/branches/py3k/Lib/lib2to3/refactor.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/refactor.py (original) +++ python/branches/py3k/Lib/lib2to3/refactor.py Sat Jan 3 17:53:14 2009 @@ -287,17 +287,13 @@ Returns: True if the tree was modified, False otherwise. """ - # Two calls to chain are required because pre_order.values() - # will be a list of lists of fixers: - # [[, ], []] - all_fixers = chain(self.pre_order, self.post_order) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.start_tree(tree, name) self.traverse_by(self.pre_order_heads, tree.pre_order()) self.traverse_by(self.post_order_heads, tree.post_order()) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.finish_tree(tree, name) return tree.was_changed Modified: python/branches/py3k/Lib/lib2to3/tests/data/py3_test_grammar.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/data/py3_test_grammar.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/data/py3_test_grammar.py Sat Jan 3 17:53:14 2009 @@ -485,6 +485,14 @@ global a, b global one, two, three, four, five, six, seven, eight, nine, ten + def testNonlocal(self): + # 'nonlocal' NAME (',' NAME)* + x = 0 + y = 0 + def f(): + nonlocal x + nonlocal x, y + def testAssert(self): # assert_stmt: 'assert' test [',' test] assert 1 Modified: python/branches/py3k/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/test_fixers.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Sat Jan 3 17:53:14 2009 @@ -1073,11 +1073,72 @@ a = """z = type(x) in (int, int)""" self.check(b, a) + def test_unchanged(self): + s = """long = True""" + self.unchanged(s) + + s = """s.long = True""" + self.unchanged(s) + + s = """def long(): pass""" + self.unchanged(s) + + s = """class long(): pass""" + self.unchanged(s) + + s = """def f(long): pass""" + self.unchanged(s) + + s = """def f(g, long): pass""" + self.unchanged(s) + + s = """def f(x, long=True): pass""" + self.unchanged(s) + def test_prefix_preservation(self): b = """x = long( x )""" a = """x = int( x )""" self.check(b, a) + +class Test_execfile(FixerTestCase): + fixer = "execfile" + + def test_conversion(self): + b = """execfile("fn")""" + a = """exec(compile(open("fn").read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)""" + self.check(b, a) + + b = """execfile("fn", glob, loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)""" + self.check(b, a) + + b = """execfile("fn", locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob, locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)""" + self.check(b, a) + + def test_spacing(self): + b = """execfile( "fn" )""" + a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", globals = glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)""" + self.check(b, a) + + class Test_isinstance(FixerTestCase): fixer = "isinstance" @@ -3466,11 +3527,30 @@ a = "from . import foo, bar" self.check_both(b, a) + b = "import foo, bar, x" + a = "from . import foo, bar, x" + self.check_both(b, a) + + b = "import x, y, z" + a = "from . import x, y, z" + self.check_both(b, a) + def test_import_as(self): b = "import foo as x" a = "from . import foo as x" self.check_both(b, a) + b = "import a as b, b as c, c as d" + a = "from . import a as b, b as c, c as d" + self.check_both(b, a) + + def test_local_and_absolute(self): + self.always_exists = False + self.present_files = set(["foo.py", "__init__.py"]) + + s = "import foo, bar" + self.warns_unchanged(s, "absolute and local imports together") + def test_dotted_import(self): b = "import foo.bar" a = "from . import foo.bar" From python-checkins at python.org Sat Jan 3 17:54:29 2009 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 3 Jan 2009 17:54:29 +0100 (CET) Subject: [Python-checkins] r68199 - in python/branches/release26-maint: Lib/lib2to3/fixer_util.py Lib/lib2to3/fixes/fix_execfile.py Lib/lib2to3/fixes/fix_import.py Lib/lib2to3/fixes/fix_imports.py Lib/lib2to3/fixes/fix_long.py Lib/lib2to3/main.py Lib/lib2to3/refactor.py Lib/lib2to3/tests/data/py3_test_grammar.py Lib/lib2to3/tests/test_fixers.py Message-ID: <20090103165429.4B3991E4002@bag.python.org> Author: benjamin.peterson Date: Sat Jan 3 17:54:28 2009 New Revision: 68199 Log: Merged revisions 68197 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved also add unittests for the fixer ........ r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line remove unused import ........ r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line copy permission bits from the backup to the original ........ r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line ........ r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line don't need loop ........ r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line actually call finish_tree() ........ r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line remove useless test ........ r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line update pyk3's test grammar ........ r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line #2734 don't convert every instance of long (eg if it's an attribute) ........ r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line add another test ........ r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line don't change long even if it's the only argument name ........ r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line remove unused import ........ ................ Modified: python/branches/release26-maint/ (props changed) python/branches/release26-maint/Lib/lib2to3/fixer_util.py python/branches/release26-maint/Lib/lib2to3/fixes/fix_execfile.py python/branches/release26-maint/Lib/lib2to3/fixes/fix_import.py python/branches/release26-maint/Lib/lib2to3/fixes/fix_imports.py python/branches/release26-maint/Lib/lib2to3/fixes/fix_long.py python/branches/release26-maint/Lib/lib2to3/main.py python/branches/release26-maint/Lib/lib2to3/refactor.py python/branches/release26-maint/Lib/lib2to3/tests/data/py3_test_grammar.py python/branches/release26-maint/Lib/lib2to3/tests/test_fixers.py Modified: python/branches/release26-maint/Lib/lib2to3/fixer_util.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/fixer_util.py (original) +++ python/branches/release26-maint/Lib/lib2to3/fixer_util.py Sat Jan 3 17:54:28 2009 @@ -222,6 +222,29 @@ return True return False +def is_probably_builtin(node): + """ + Check that something isn't an attribute or function name etc. + """ + prev = node.get_prev_sibling() + if prev is not None and prev.type == token.DOT: + # Attribute lookup. + return False + parent = node.parent + if parent.type in (syms.funcdef, syms.classdef): + return False + if parent.type == syms.expr_stmt and parent.children[0] is node: + # Assignment. + return False + if parent.type == syms.parameters or \ + (parent.type == syms.typedargslist and ( + (prev is not None and prev.type == token.COMMA) or + parent.children[0] is node + )): + # The name of an argument. + return False + return True + ########################################################### ### The following functions are to find bindings in a suite ########################################################### Modified: python/branches/release26-maint/Lib/lib2to3/fixes/fix_execfile.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/fixes/fix_execfile.py (original) +++ python/branches/release26-maint/Lib/lib2to3/fixes/fix_execfile.py Sat Jan 3 17:54:28 2009 @@ -7,9 +7,9 @@ exec() function. """ -from .. import pytree from .. import fixer_base -from ..fixer_util import Comma, Name, Call, LParen, RParen, Dot +from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node, + ArgList, String, syms) class FixExecfile(fixer_base.BaseFix): @@ -22,16 +22,30 @@ def transform(self, node, results): assert results - syms = self.syms filename = results["filename"] globals = results.get("globals") locals = results.get("locals") - args = [Name('open'), LParen(), filename.clone(), RParen(), Dot(), - Name('read'), LParen(), RParen()] - args[0].set_prefix("") + + # Copy over the prefix from the right parentheses end of the execfile + # call. + execfile_paren = node.children[-1].children[-1].clone() + # Construct open().read(). + open_args = ArgList([filename.clone()], rparen=execfile_paren) + open_call = Node(syms.power, [Name("open"), open_args]) + read = [Node(syms.trailer, [Dot(), Name('read')]), + Node(syms.trailer, [LParen(), RParen()])] + open_expr = [open_call] + read + # Wrap the open call in a compile call. This is so the filename will be + # preserved in the execed code. + filename_arg = filename.clone() + filename_arg.set_prefix(" ") + exec_str = String("'exec'", " ") + compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str] + compile_call = Call(Name("compile"), compile_args, "") + # Finally, replace the execfile call with an exec call. + args = [compile_call] if globals is not None: args.extend([Comma(), globals.clone()]) if locals is not None: args.extend([Comma(), locals.clone()]) - return Call(Name("exec"), args, prefix=node.get_prefix()) Modified: python/branches/release26-maint/Lib/lib2to3/fixes/fix_import.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/fixes/fix_import.py (original) +++ python/branches/release26-maint/Lib/lib2to3/fixes/fix_import.py Sat Jan 3 17:54:28 2009 @@ -13,55 +13,78 @@ # Local imports from .. import fixer_base from os.path import dirname, join, exists, pathsep -from ..fixer_util import FromImport, syms +from ..fixer_util import FromImport, syms, token + + +def traverse_imports(names): + """ + Walks over all the names imported in a dotted_as_names node. + """ + pending = [names] + while pending: + node = pending.pop() + if node.type == token.NAME: + yield node.value + elif node.type == syms.dotted_name: + yield "".join([ch.value for ch in node.children]) + elif node.type == syms.dotted_as_name: + pending.append(node.children[0]) + elif node.type == syms.dotted_as_names: + pending.extend(node.children[::-2]) + else: + raise AssertionError("unkown node type") + class FixImport(fixer_base.BaseFix): PATTERN = """ - import_from< type='from' imp=any 'import' ['('] any [')'] > + import_from< 'from' imp=any 'import' ['('] any [')'] > | - import_name< type='import' imp=any > + import_name< 'import' imp=any > """ def transform(self, node, results): imp = results['imp'] - mod_name = unicode(imp.children[0] if imp.type == syms.dotted_as_name \ - else imp) - - if mod_name.startswith('.'): - # Already a new-style import - return - - if not probably_a_local_import(mod_name, self.filename): - # I guess this is a global import -- skip it! - return - - if results['type'].value == 'from': + if node.type == syms.import_from: # Some imps are top-level (eg: 'import ham') # some are first level (eg: 'import ham.eggs') # some are third level (eg: 'import ham.eggs as spam') # Hence, the loop while not hasattr(imp, 'value'): imp = imp.children[0] - imp.value = "." + imp.value - node.changed() + if self.probably_a_local_import(imp.value): + imp.value = "." + imp.value + imp.changed() + return node else: - new = FromImport('.', getattr(imp, 'content', None) or [imp]) + have_local = False + have_absolute = False + for mod_name in traverse_imports(imp): + if self.probably_a_local_import(mod_name): + have_local = True + else: + have_absolute = True + if have_absolute: + if have_local: + # We won't handle both sibling and absolute imports in the + # same statement at the moment. + self.warning(node, "absolute and local imports together") + return + + new = FromImport('.', [imp]) new.set_prefix(node.get_prefix()) - node = new - return node + return new -def probably_a_local_import(imp_name, file_path): - # Must be stripped because the right space is included by the parser - imp_name = imp_name.split('.', 1)[0].strip() - base_path = dirname(file_path) - base_path = join(base_path, imp_name) - # If there is no __init__.py next to the file its not in a package - # so can't be a relative import. - if not exists(join(dirname(base_path), '__init__.py')): + def probably_a_local_import(self, imp_name): + imp_name = imp_name.split('.', 1)[0] + base_path = dirname(self.filename) + base_path = join(base_path, imp_name) + # If there is no __init__.py next to the file its not in a package + # so can't be a relative import. + if not exists(join(dirname(base_path), '__init__.py')): + return False + for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: + if exists(base_path + ext): + return True return False - for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: - if exists(base_path + ext): - return True - return False Modified: python/branches/release26-maint/Lib/lib2to3/fixes/fix_imports.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/fixes/fix_imports.py (original) +++ python/branches/release26-maint/Lib/lib2to3/fixes/fix_imports.py Sat Jan 3 17:54:28 2009 @@ -118,7 +118,7 @@ def transform(self, node, results): import_mod = results.get("module_name") if import_mod: - new_name = self.mapping[(import_mod or mod_name).value] + new_name = self.mapping[import_mod.value] import_mod.replace(Name(new_name, prefix=import_mod.get_prefix())) if "name_import" in results: # If it's not a "from x import x, y" or "import x as y" import, @@ -129,10 +129,8 @@ # line (e.g., "import StringIO, urlparse"). The problem is that I # can't figure out an easy way to make a pattern recognize the # keys of MAPPING randomly sprinkled in an import statement. - while True: - results = self.match(node) - if not results: - break + results = self.match(node) + if results: self.transform(node, results) else: # Replace usage of the module. Modified: python/branches/release26-maint/Lib/lib2to3/fixes/fix_long.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/fixes/fix_long.py (original) +++ python/branches/release26-maint/Lib/lib2to3/fixes/fix_long.py Sat Jan 3 17:54:28 2009 @@ -5,20 +5,18 @@ """ # Local imports -from .. import pytree from .. import fixer_base -from ..fixer_util import Name, Number +from ..fixer_util import Name, Number, is_probably_builtin class FixLong(fixer_base.BaseFix): PATTERN = "'long'" - static_long = Name("long") static_int = Name("int") def transform(self, node, results): - assert node == self.static_long, node - new = self.static_int.clone() - new.set_prefix(node.get_prefix()) - return new + if is_probably_builtin(node): + new = self.static_int.clone() + new.set_prefix(node.get_prefix()) + return new Modified: python/branches/release26-maint/Lib/lib2to3/main.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/main.py (original) +++ python/branches/release26-maint/Lib/lib2to3/main.py Sat Jan 3 17:54:28 2009 @@ -41,7 +41,7 @@ super(StdoutRefactoringTool, self).write_file(new_text, filename, old_text) if not self.nobackups: - shutil.copymode(filename, backup) + shutil.copymode(backup, filename) def print_output(self, lines): for line in lines: Modified: python/branches/release26-maint/Lib/lib2to3/refactor.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/refactor.py (original) +++ python/branches/release26-maint/Lib/lib2to3/refactor.py Sat Jan 3 17:54:28 2009 @@ -287,17 +287,13 @@ Returns: True if the tree was modified, False otherwise. """ - # Two calls to chain are required because pre_order.values() - # will be a list of lists of fixers: - # [[, ], []] - all_fixers = chain(self.pre_order, self.post_order) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.start_tree(tree, name) self.traverse_by(self.pre_order_heads, tree.pre_order()) self.traverse_by(self.post_order_heads, tree.post_order()) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.finish_tree(tree, name) return tree.was_changed Modified: python/branches/release26-maint/Lib/lib2to3/tests/data/py3_test_grammar.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/tests/data/py3_test_grammar.py (original) +++ python/branches/release26-maint/Lib/lib2to3/tests/data/py3_test_grammar.py Sat Jan 3 17:54:28 2009 @@ -485,6 +485,14 @@ global a, b global one, two, three, four, five, six, seven, eight, nine, ten + def testNonlocal(self): + # 'nonlocal' NAME (',' NAME)* + x = 0 + y = 0 + def f(): + nonlocal x + nonlocal x, y + def testAssert(self): # assert_stmt: 'assert' test [',' test] assert 1 Modified: python/branches/release26-maint/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/branches/release26-maint/Lib/lib2to3/tests/test_fixers.py (original) +++ python/branches/release26-maint/Lib/lib2to3/tests/test_fixers.py Sat Jan 3 17:54:28 2009 @@ -1073,11 +1073,72 @@ a = """z = type(x) in (int, int)""" self.check(b, a) + def test_unchanged(self): + s = """long = True""" + self.unchanged(s) + + s = """s.long = True""" + self.unchanged(s) + + s = """def long(): pass""" + self.unchanged(s) + + s = """class long(): pass""" + self.unchanged(s) + + s = """def f(long): pass""" + self.unchanged(s) + + s = """def f(g, long): pass""" + self.unchanged(s) + + s = """def f(x, long=True): pass""" + self.unchanged(s) + def test_prefix_preservation(self): b = """x = long( x )""" a = """x = int( x )""" self.check(b, a) + +class Test_execfile(FixerTestCase): + fixer = "execfile" + + def test_conversion(self): + b = """execfile("fn")""" + a = """exec(compile(open("fn").read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)""" + self.check(b, a) + + b = """execfile("fn", glob, loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)""" + self.check(b, a) + + b = """execfile("fn", locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob, locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)""" + self.check(b, a) + + def test_spacing(self): + b = """execfile( "fn" )""" + a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", globals = glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)""" + self.check(b, a) + + class Test_isinstance(FixerTestCase): fixer = "isinstance" @@ -3466,11 +3527,30 @@ a = "from . import foo, bar" self.check_both(b, a) + b = "import foo, bar, x" + a = "from . import foo, bar, x" + self.check_both(b, a) + + b = "import x, y, z" + a = "from . import x, y, z" + self.check_both(b, a) + def test_import_as(self): b = "import foo as x" a = "from . import foo as x" self.check_both(b, a) + b = "import a as b, b as c, c as d" + a = "from . import a as b, b as c, c as d" + self.check_both(b, a) + + def test_local_and_absolute(self): + self.always_exists = False + self.present_files = set(["foo.py", "__init__.py"]) + + s = "import foo, bar" + self.warns_unchanged(s, "absolute and local imports together") + def test_dotted_import(self): b = "import foo.bar" a = "from . import foo.bar" From python-checkins at python.org Sat Jan 3 17:59:18 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 17:59:18 +0100 (CET) Subject: [Python-checkins] r68200 - in python/branches/py3k: Include/object.h Lib/ctypes/test/test_pep3118.py Lib/test/test_io.py Lib/test/test_memoryview.py Lib/test/test_sys.py Misc/NEWS Objects/memoryobject.c Objects/unicodeobject.c Message-ID: <20090103165918.8AB9C1E4044@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 17:59:18 2009 New Revision: 68200 Log: Issue #4580: slicing of memoryviews when itemsize != 1 is wrong. Also fix len() to return number of items rather than length in bytes. I'm sorry it was not possible for me to work on this without reindenting a bit some stuff around. The indentation in memoryobject.c is a mess, I'll open a separate bug for it. Modified: python/branches/py3k/Include/object.h python/branches/py3k/Lib/ctypes/test/test_pep3118.py python/branches/py3k/Lib/test/test_io.py python/branches/py3k/Lib/test/test_memoryview.py python/branches/py3k/Lib/test/test_sys.py python/branches/py3k/Misc/NEWS python/branches/py3k/Objects/memoryobject.c python/branches/py3k/Objects/unicodeobject.c Modified: python/branches/py3k/Include/object.h ============================================================================== --- python/branches/py3k/Include/object.h (original) +++ python/branches/py3k/Include/object.h Sat Jan 3 17:59:18 2009 @@ -144,16 +144,18 @@ typedef struct bufferinfo { void *buf; PyObject *obj; /* owned reference */ - Py_ssize_t len; - Py_ssize_t itemsize; /* This is Py_ssize_t so it can be - pointed to by strides in simple case.*/ - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; + Py_ssize_t len; + Py_ssize_t itemsize; /* This is Py_ssize_t so it can be + pointed to by strides in simple case.*/ + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + Py_ssize_t smalltable[2]; /* static store for shape and strides of + mono-dimensional buffers. */ + void *internal; } Py_buffer; typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); Modified: python/branches/py3k/Lib/ctypes/test/test_pep3118.py ============================================================================== --- python/branches/py3k/Lib/ctypes/test/test_pep3118.py (original) +++ python/branches/py3k/Lib/ctypes/test/test_pep3118.py Sat Jan 3 17:59:18 2009 @@ -25,7 +25,10 @@ v = memoryview(ob) try: self.failUnlessEqual(normalize(v.format), normalize(fmt)) - self.failUnlessEqual(len(v), sizeof(ob)) + if shape is not None: + self.failUnlessEqual(len(v), shape[0]) + else: + self.failUnlessEqual(len(v) * sizeof(itemtp), sizeof(ob)) self.failUnlessEqual(v.itemsize, sizeof(itemtp)) self.failUnlessEqual(v.shape, shape) # ctypes object always have a non-strided memory block @@ -37,7 +40,7 @@ n = 1 for dim in v.shape: n = n * dim - self.failUnlessEqual(v.itemsize * n, len(v)) + self.failUnlessEqual(n * v.itemsize, len(v.tobytes())) except: # so that we can see the failing type print(tp) @@ -49,7 +52,10 @@ v = memoryview(ob) try: self.failUnlessEqual(v.format, fmt) - self.failUnlessEqual(len(v), sizeof(ob)) + if shape is not None: + self.failUnlessEqual(len(v), shape[0]) + else: + self.failUnlessEqual(len(v) * sizeof(itemtp), sizeof(ob)) self.failUnlessEqual(v.itemsize, sizeof(itemtp)) self.failUnlessEqual(v.shape, shape) # ctypes object always have a non-strided memory block @@ -61,7 +67,7 @@ n = 1 for dim in v.shape: n = n * dim - self.failUnlessEqual(v.itemsize * n, len(v)) + self.failUnlessEqual(n, len(v)) except: # so that we can see the failing type print(tp) Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Sat Jan 3 17:59:18 2009 @@ -260,7 +260,7 @@ def test_array_writes(self): a = array.array('i', range(10)) - n = len(memoryview(a)) + n = len(a.tostring()) f = io.open(support.TESTFN, "wb", 0) self.assertEqual(f.write(a), n) f.close() Modified: python/branches/py3k/Lib/test/test_memoryview.py ============================================================================== --- python/branches/py3k/Lib/test/test_memoryview.py (original) +++ python/branches/py3k/Lib/test/test_memoryview.py Sat Jan 3 17:59:18 2009 @@ -8,24 +8,30 @@ import sys import gc import weakref +import array -class CommonMemoryTests: - # - # Tests common to direct memoryviews and sliced memoryviews - # +class AbstractMemoryTests: + source_bytes = b"abcdef" - base_object = b"abcdef" + @property + def _source(self): + return self.source_bytes + + @property + def _types(self): + return filter(None, [self.ro_type, self.rw_type]) def check_getitem_with_type(self, tp): - b = tp(self.base_object) + item = self.getitem_type + b = tp(self._source) oldrefcount = sys.getrefcount(b) m = self._view(b) - self.assertEquals(m[0], b"a") + self.assertEquals(m[0], item(b"a")) self.assert_(isinstance(m[0], bytes), type(m[0])) - self.assertEquals(m[5], b"f") - self.assertEquals(m[-1], b"f") - self.assertEquals(m[-6], b"a") + self.assertEquals(m[5], item(b"f")) + self.assertEquals(m[-1], item(b"f")) + self.assertEquals(m[-6], item(b"a")) # Bounds checking self.assertRaises(IndexError, lambda: m[6]) self.assertRaises(IndexError, lambda: m[-7]) @@ -38,14 +44,14 @@ m = None self.assertEquals(sys.getrefcount(b), oldrefcount) - def test_getitem_readonly(self): - self.check_getitem_with_type(bytes) - - def test_getitem_writable(self): - self.check_getitem_with_type(bytearray) + def test_getitem(self): + for tp in self._types: + self.check_getitem_with_type(tp) def test_setitem_readonly(self): - b = self.base_object + if not self.ro_type: + return + b = self.ro_type(self._source) oldrefcount = sys.getrefcount(b) m = self._view(b) def setitem(value): @@ -57,27 +63,30 @@ self.assertEquals(sys.getrefcount(b), oldrefcount) def test_setitem_writable(self): - b = bytearray(self.base_object) + if not self.rw_type: + return + tp = self.rw_type + b = self.rw_type(self._source) oldrefcount = sys.getrefcount(b) m = self._view(b) - m[0] = b"0" - self._check_contents(b, b"0bcdef") - m[1:3] = b"12" - self._check_contents(b, b"012def") - m[1:1] = b"" - self._check_contents(b, b"012def") - m[:] = b"abcdef" - self._check_contents(b, b"abcdef") + m[0] = tp(b"0") + self._check_contents(tp, b, b"0bcdef") + m[1:3] = tp(b"12") + self._check_contents(tp, b, b"012def") + m[1:1] = tp(b"") + self._check_contents(tp, b, b"012def") + m[:] = tp(b"abcdef") + self._check_contents(tp, b, b"abcdef") # Overlapping copies of a view into itself m[0:3] = m[2:5] - self._check_contents(b, b"cdedef") - m[:] = b"abcdef" + self._check_contents(tp, b, b"cdedef") + m[:] = tp(b"abcdef") m[2:5] = m[0:3] - self._check_contents(b, b"ababcf") + self._check_contents(tp, b, b"ababcf") def setitem(key, value): - m[key] = value + m[key] = tp(value) # Bounds checking self.assertRaises(IndexError, setitem, 6, b"a") self.assertRaises(IndexError, setitem, -7, b"a") @@ -96,159 +105,224 @@ m = None self.assertEquals(sys.getrefcount(b), oldrefcount) - def test_len(self): - self.assertEquals(len(self._view(self.base_object)), 6) - def test_tobytes(self): - m = self._view(self.base_object) - b = m.tobytes() - self.assertEquals(b, b"abcdef") - self.assert_(isinstance(b, bytes), type(b)) + for tp in self._types: + m = self._view(tp(self._source)) + b = m.tobytes() + # This calls self.getitem_type() on each separate byte of b"abcdef" + expected = b"".join( + self.getitem_type(bytes([c])) for c in b"abcdef") + self.assertEquals(b, expected) + self.assert_(isinstance(b, bytes), type(b)) def test_tolist(self): - m = self._view(self.base_object) - l = m.tolist() - self.assertEquals(l, list(b"abcdef")) + for tp in self._types: + m = self._view(tp(self._source)) + l = m.tolist() + self.assertEquals(l, list(b"abcdef")) def test_compare(self): # memoryviews can compare for equality with other objects # having the buffer interface. - m = self._view(self.base_object) - for tp in (bytes, bytearray): - self.assertTrue(m == tp(b"abcdef")) - self.assertFalse(m != tp(b"abcdef")) - self.assertFalse(m == tp(b"abcde")) - self.assertTrue(m != tp(b"abcde")) - self.assertFalse(m == tp(b"abcde1")) - self.assertTrue(m != tp(b"abcde1")) - self.assertTrue(m == m) - self.assertTrue(m == m[:]) - self.assertTrue(m[0:6] == m[:]) - self.assertFalse(m[0:5] == m) - - # Comparison with objects which don't support the buffer API - self.assertFalse(m == "abc") - self.assertTrue(m != "abc") - self.assertFalse("abc" == m) - self.assertTrue("abc" != m) - - # Unordered comparisons - for c in (m, b"abcdef"): - self.assertRaises(TypeError, lambda: m < c) - self.assertRaises(TypeError, lambda: c <= m) - self.assertRaises(TypeError, lambda: m >= c) - self.assertRaises(TypeError, lambda: c > m) + for tp in self._types: + m = self._view(tp(self._source)) + for tp_comp in self._types: + self.assertTrue(m == tp_comp(b"abcdef")) + self.assertFalse(m != tp_comp(b"abcdef")) + self.assertFalse(m == tp_comp(b"abcde")) + self.assertTrue(m != tp_comp(b"abcde")) + self.assertFalse(m == tp_comp(b"abcde1")) + self.assertTrue(m != tp_comp(b"abcde1")) + self.assertTrue(m == m) + self.assertTrue(m == m[:]) + self.assertTrue(m[0:6] == m[:]) + self.assertFalse(m[0:5] == m) + + # Comparison with objects which don't support the buffer API + self.assertFalse(m == "abcdef") + self.assertTrue(m != "abcdef") + self.assertFalse("abcdef" == m) + self.assertTrue("abcdef" != m) + + # Unordered comparisons + for c in (m, b"abcdef"): + self.assertRaises(TypeError, lambda: m < c) + self.assertRaises(TypeError, lambda: c <= m) + self.assertRaises(TypeError, lambda: m >= c) + self.assertRaises(TypeError, lambda: c > m) def check_attributes_with_type(self, tp): - b = tp(self.base_object) - m = self._view(b) - self.assertEquals(m.format, 'B') - self.assertEquals(m.itemsize, 1) + m = self._view(tp(self._source)) + self.assertEquals(m.format, self.format) + self.assertEquals(m.itemsize, self.itemsize) self.assertEquals(m.ndim, 1) self.assertEquals(m.shape, (6,)) self.assertEquals(len(m), 6) - self.assertEquals(m.strides, (1,)) + self.assertEquals(m.strides, (self.itemsize,)) self.assertEquals(m.suboffsets, None) return m def test_attributes_readonly(self): - m = self.check_attributes_with_type(bytes) + if not self.ro_type: + return + m = self.check_attributes_with_type(self.ro_type) self.assertEquals(m.readonly, True) def test_attributes_writable(self): - m = self.check_attributes_with_type(bytearray) + if not self.rw_type: + return + m = self.check_attributes_with_type(self.rw_type) self.assertEquals(m.readonly, False) def test_getbuffer(self): # Test PyObject_GetBuffer() on a memoryview object. - b = self.base_object - oldrefcount = sys.getrefcount(b) - m = self._view(b) - oldviewrefcount = sys.getrefcount(m) - s = str(m, "utf-8") - self._check_contents(b, s.encode("utf-8")) - self.assertEquals(sys.getrefcount(m), oldviewrefcount) - m = None - self.assertEquals(sys.getrefcount(b), oldrefcount) + for tp in self._types: + b = tp(self._source) + oldrefcount = sys.getrefcount(b) + m = self._view(b) + oldviewrefcount = sys.getrefcount(m) + s = str(m, "utf-8") + self._check_contents(tp, b, s.encode("utf-8")) + self.assertEquals(sys.getrefcount(m), oldviewrefcount) + m = None + self.assertEquals(sys.getrefcount(b), oldrefcount) def test_gc(self): - class MyBytes(bytes): - pass - class MyObject: - pass + for tp in self._types: + if not isinstance(tp, type): + # If tp is a factory rather than a plain type, skip + continue + + class MySource(tp): + pass + class MyObject: + pass + + # Create a reference cycle through a memoryview object + b = MySource(tp(b'abc')) + m = self._view(b) + o = MyObject() + b.m = m + b.o = o + wr = weakref.ref(o) + b = m = o = None + # The cycle must be broken + gc.collect() + self.assert_(wr() is None, wr()) + + +# Variations on source objects for the buffer: bytes-like objects, then arrays +# with itemsize > 1. +# NOTE: support for multi-dimensional objects is unimplemented. + +class BaseBytesMemoryTests(AbstractMemoryTests): + ro_type = bytes + rw_type = bytearray + getitem_type = bytes + itemsize = 1 + format = 'B' + +class BaseArrayMemoryTests(AbstractMemoryTests): + ro_type = None + rw_type = lambda self, b: array.array('i', list(b)) + getitem_type = lambda self, b: array.array('i', list(b)).tostring() + itemsize = array.array('i').itemsize + format = 'i' - # Create a reference cycle through a memoryview object - b = MyBytes(b'abc') - m = self._view(b) - o = MyObject() - b.m = m - b.o = o - wr = weakref.ref(o) - b = m = o = None - # The cycle must be broken - gc.collect() - self.assert_(wr() is None, wr()) + def test_getbuffer(self): + # XXX Test should be adapted for non-byte buffers + pass + + def test_tolist(self): + # XXX NotImplementedError: tolist() only supports byte views + pass -class MemoryviewTest(unittest.TestCase, CommonMemoryTests): +# Variations on indirection levels: memoryview, slice of memoryview, +# slice of slice of memoryview. +# This is important to test allocation subtleties. +class BaseMemoryviewTests: def _view(self, obj): return memoryview(obj) - def _check_contents(self, obj, contents): - self.assertEquals(obj, contents) + def _check_contents(self, tp, obj, contents): + self.assertEquals(obj, tp(contents)) - def test_constructor(self): - ob = b'test' - self.assert_(memoryview(ob)) - self.assert_(memoryview(object=ob)) - self.assertRaises(TypeError, memoryview) - self.assertRaises(TypeError, memoryview, ob, ob) - self.assertRaises(TypeError, memoryview, argument=ob) - self.assertRaises(TypeError, memoryview, ob, argument=True) - - def test_array_assign(self): - # Issue #4569: segfault when mutating a memoryview with itemsize != 1 - from array import array - a = array('i', range(10)) - m = memoryview(a) - new_a = array('i', range(9, -1, -1)) - m[:] = new_a - self.assertEquals(a, new_a) - - -class MemorySliceTest(unittest.TestCase, CommonMemoryTests): - base_object = b"XabcdefY" +class BaseMemorySliceTests: + source_bytes = b"XabcdefY" def _view(self, obj): m = memoryview(obj) return m[1:7] - def _check_contents(self, obj, contents): - self.assertEquals(obj[1:7], contents) + def _check_contents(self, tp, obj, contents): + self.assertEquals(obj[1:7], tp(contents)) def test_refs(self): - m = memoryview(b"ab") - oldrefcount = sys.getrefcount(m) - m[1:2] - self.assertEquals(sys.getrefcount(m), oldrefcount) - + for tp in self._types: + m = memoryview(tp(self._source)) + oldrefcount = sys.getrefcount(m) + m[1:2] + self.assertEquals(sys.getrefcount(m), oldrefcount) -class MemorySliceSliceTest(unittest.TestCase, CommonMemoryTests): - base_object = b"XabcdefY" +class BaseMemorySliceSliceTests: + source_bytes = b"XabcdefY" def _view(self, obj): m = memoryview(obj) return m[:7][1:] - def _check_contents(self, obj, contents): - self.assertEquals(obj[1:7], contents) + def _check_contents(self, tp, obj, contents): + self.assertEquals(obj[1:7], tp(contents)) -def test_main(): - test.support.run_unittest( - MemoryviewTest, MemorySliceTest, MemorySliceSliceTest) +# Concrete test classes + +class BytesMemoryviewTest(unittest.TestCase, + BaseMemoryviewTests, BaseBytesMemoryTests): + + def test_constructor(self): + for tp in self._types: + ob = tp(self._source) + self.assert_(memoryview(ob)) + self.assert_(memoryview(object=ob)) + self.assertRaises(TypeError, memoryview) + self.assertRaises(TypeError, memoryview, ob, ob) + self.assertRaises(TypeError, memoryview, argument=ob) + self.assertRaises(TypeError, memoryview, ob, argument=True) + +class ArrayMemoryviewTest(unittest.TestCase, + BaseMemoryviewTests, BaseArrayMemoryTests): + + def test_array_assign(self): + # Issue #4569: segfault when mutating a memoryview with itemsize != 1 + a = array.array('i', range(10)) + m = memoryview(a) + new_a = array.array('i', range(9, -1, -1)) + m[:] = new_a + self.assertEquals(a, new_a) +class BytesMemorySliceTest(unittest.TestCase, + BaseMemorySliceTests, BaseBytesMemoryTests): + pass + +class ArrayMemorySliceTest(unittest.TestCase, + BaseMemorySliceTests, BaseArrayMemoryTests): + pass + +class BytesMemorySliceSliceTest(unittest.TestCase, + BaseMemorySliceSliceTests, BaseBytesMemoryTests): + pass + +class ArrayMemorySliceSliceTest(unittest.TestCase, + BaseMemorySliceSliceTests, BaseArrayMemoryTests): + pass + + +def test_main(): + test.support.run_unittest(__name__) + if __name__ == "__main__": test_main() Modified: python/branches/py3k/Lib/test/test_sys.py ============================================================================== --- python/branches/py3k/Lib/test/test_sys.py (original) +++ python/branches/py3k/Lib/test/test_sys.py Sat Jan 3 17:59:18 2009 @@ -559,7 +559,7 @@ check(32768*32768-1, size(vh) + 2*self.H) check(32768*32768, size(vh) + 3*self.H) # memory - check(memoryview(b''), size(h + 'P PP2P2i5P')) + check(memoryview(b''), size(h + 'P PP2P2i7P')) # module check(unittest, size(h + '3P')) # None Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Jan 3 17:59:18 2009 @@ -12,6 +12,10 @@ Core and Builtins ----------------- +- Issue #4580: Fix slicing of memoryviews when the item size is greater than + one byte. Also fixes the meaning of len() so that it returns the number of + items, rather than the size in bytes. + - Issue #4075: Use OutputDebugStringW in Py_FatalError. - Issue #4747: When the terminal does not use utf-8, executing a script with Modified: python/branches/py3k/Objects/memoryobject.c ============================================================================== --- python/branches/py3k/Objects/memoryobject.c (original) +++ python/branches/py3k/Objects/memoryobject.c Sat Jan 3 17:59:18 2009 @@ -3,26 +3,31 @@ #include "Python.h" -static void -dup_buffer(Py_buffer *dest, Py_buffer *src) -{ - *dest = *src; - if (src->shape == &(src->len)) - dest->shape = &(dest->len); - if (src->strides == &(src->itemsize)) - dest->strides = &(dest->itemsize); -} - -/* XXX The buffer API should mandate that the shape array be non-NULL, but - it would complicate some code since the (de)allocation semantics of shape - are not specified. */ static Py_ssize_t get_shape0(Py_buffer *buf) { if (buf->shape != NULL) return buf->shape[0]; - assert(buf->ndim == 1 && buf->itemsize > 0); - return buf->len / buf->itemsize; + if (buf->ndim == 0) + return 1; + PyErr_SetString(PyExc_TypeError, + "exported buffer does not have any shape information associated " + "to it"); + return -1; +} + +static void +dup_buffer(Py_buffer *dest, Py_buffer *src) +{ + *dest = *src; + if (src->ndim == 1 && src->shape != NULL) { + dest->shape = &(dest->smalltable[0]); + dest->shape[0] = get_shape0(src); + } + if (src->ndim == 1 && src->strides != NULL) { + dest->strides = &(dest->smalltable[1]); + dest->strides[0] = src->strides[0]; + } } static int @@ -449,8 +454,6 @@ return res; } - - static PyMethodDef memory_methods[] = { {"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, NULL}, {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, NULL}, @@ -474,19 +477,19 @@ PyObject_CopyData(PyTuple_GET_ITEM(self->base,0), PyTuple_GET_ITEM(self->base,1)); - /* The view member should have readonly == -1 in - this instance indicating that the memory can - be "locked" and was locked and will be unlocked - again after this call. - */ - PyBuffer_Release(&(self->view)); - } - else { - PyBuffer_Release(&(self->view)); - } - Py_CLEAR(self->base); + /* The view member should have readonly == -1 in + this instance indicating that the memory can + be "locked" and was locked and will be unlocked + again after this call. + */ + PyBuffer_Release(&(self->view)); + } + else { + PyBuffer_Release(&(self->view)); } - PyObject_GC_Del(self); + Py_CLEAR(self->base); + } + PyObject_GC_Del(self); } static PyObject * @@ -512,16 +515,10 @@ } /* Sequence methods */ - static Py_ssize_t memory_length(PyMemoryViewObject *self) { - Py_buffer view; - - if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0) - return -1; - PyBuffer_Release(&view); - return view.len; + return get_shape0(&self->view); } /* @@ -589,40 +586,38 @@ } } else if (PySlice_Check(key)) { - Py_ssize_t start, stop, step, slicelength; - + Py_ssize_t start, stop, step, slicelength; + if (PySlice_GetIndicesEx((PySliceObject*)key, get_shape0(view), - &start, &stop, &step, &slicelength) < 0) { - return NULL; - } + &start, &stop, &step, &slicelength) < 0) { + return NULL; + } - if (step == 1 && view->ndim == 1) { - Py_buffer newview; - void *newbuf = (char *) view->buf - + start * view->itemsize; - int newflags = view->readonly - ? PyBUF_CONTIG_RO : PyBUF_CONTIG; + if (step == 1 && view->ndim == 1) { + Py_buffer newview; + void *newbuf = (char *) view->buf + + start * view->itemsize; + int newflags = view->readonly + ? PyBUF_CONTIG_RO : PyBUF_CONTIG; - /* XXX There should be an API to create a subbuffer */ - if (view->obj != NULL) { - if (PyObject_GetBuffer(view->obj, - &newview, newflags) == -1) - return NULL; - } - else { - newview = *view; - } - newview.buf = newbuf; - newview.len = slicelength; - newview.format = view->format; - if (view->shape == &(view->len)) - newview.shape = &(newview.len); - if (view->strides == &(view->itemsize)) - newview.strides = &(newview.itemsize); - return PyMemoryView_FromBuffer(&newview); - } - PyErr_SetNone(PyExc_NotImplementedError); - return NULL; + /* XXX There should be an API to create a subbuffer */ + if (view->obj != NULL) { + if (PyObject_GetBuffer(view->obj, &newview, newflags) == -1) + return NULL; + } + else { + newview = *view; + } + newview.buf = newbuf; + newview.len = slicelength * newview.itemsize; + newview.format = view->format; + newview.shape = &(newview.smalltable[0]); + newview.shape[0] = slicelength; + newview.strides = &(newview.itemsize); + return PyMemoryView_FromBuffer(&newview); + } + PyErr_SetNone(PyExc_NotImplementedError); + return NULL; } PyErr_Format(PyExc_TypeError, "cannot index memory using \"%.200s\"", @@ -747,7 +742,7 @@ if (vv.itemsize != ww.itemsize || vv.len != ww.len) goto _end; - equal = !memcmp(vv.buf, ww.buf, vv.len * vv.itemsize); + equal = !memcmp(vv.buf, ww.buf, vv.len); _end: PyBuffer_Release(&vv); Modified: python/branches/py3k/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k/Objects/unicodeobject.c (original) +++ python/branches/py3k/Objects/unicodeobject.c Sat Jan 3 17:59:18 2009 @@ -1205,7 +1205,7 @@ /* Decode via the codec registry */ buffer = NULL; - if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_SIMPLE) < 0) + if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_FULL_RO) < 0) goto onError; buffer = PyMemoryView_FromBuffer(&info); if (buffer == NULL) From python-checkins at python.org Sat Jan 3 18:06:28 2009 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 3 Jan 2009 18:06:28 +0100 (CET) Subject: [Python-checkins] r68201 - in python/branches/release30-maint/Lib/lib2to3: fixer_util.py fixes/fix_execfile.py fixes/fix_import.py fixes/fix_imports.py fixes/fix_long.py main.py refactor.py tests/data/py3_test_grammar.py tests/test_fixers.py Message-ID: <20090103170628.88F5E1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Jan 3 18:06:28 2009 New Revision: 68201 Log: Merged revisions 68198 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ................ r68198 | benjamin.peterson | 2009-01-03 10:53:14 -0600 (Sat, 03 Jan 2009) | 62 lines Merged revisions 68197 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved also add unittests for the fixer ........ r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line remove unused import ........ r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line copy permission bits from the backup to the original ........ r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line ........ r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line don't need loop ........ r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line actually call finish_tree() ........ r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line remove useless test ........ r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line update pyk3's test grammar ........ r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line #2734 don't convert every instance of long (eg if it's an attribute) ........ r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line add another test ........ r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line don't change long even if it's the only argument name ........ r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line remove unused import ........ ................ ................ Modified: python/branches/release30-maint/Lib/lib2to3/fixer_util.py python/branches/release30-maint/Lib/lib2to3/fixes/fix_execfile.py python/branches/release30-maint/Lib/lib2to3/fixes/fix_import.py python/branches/release30-maint/Lib/lib2to3/fixes/fix_imports.py python/branches/release30-maint/Lib/lib2to3/fixes/fix_long.py python/branches/release30-maint/Lib/lib2to3/main.py python/branches/release30-maint/Lib/lib2to3/refactor.py python/branches/release30-maint/Lib/lib2to3/tests/data/py3_test_grammar.py python/branches/release30-maint/Lib/lib2to3/tests/test_fixers.py Modified: python/branches/release30-maint/Lib/lib2to3/fixer_util.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/fixer_util.py (original) +++ python/branches/release30-maint/Lib/lib2to3/fixer_util.py Sat Jan 3 18:06:28 2009 @@ -222,6 +222,29 @@ return True return False +def is_probably_builtin(node): + """ + Check that something isn't an attribute or function name etc. + """ + prev = node.get_prev_sibling() + if prev is not None and prev.type == token.DOT: + # Attribute lookup. + return False + parent = node.parent + if parent.type in (syms.funcdef, syms.classdef): + return False + if parent.type == syms.expr_stmt and parent.children[0] is node: + # Assignment. + return False + if parent.type == syms.parameters or \ + (parent.type == syms.typedargslist and ( + (prev is not None and prev.type == token.COMMA) or + parent.children[0] is node + )): + # The name of an argument. + return False + return True + ########################################################### ### The following functions are to find bindings in a suite ########################################################### Modified: python/branches/release30-maint/Lib/lib2to3/fixes/fix_execfile.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/fixes/fix_execfile.py (original) +++ python/branches/release30-maint/Lib/lib2to3/fixes/fix_execfile.py Sat Jan 3 18:06:28 2009 @@ -7,9 +7,9 @@ exec() function. """ -from .. import pytree from .. import fixer_base -from ..fixer_util import Comma, Name, Call, LParen, RParen, Dot +from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node, + ArgList, String, syms) class FixExecfile(fixer_base.BaseFix): @@ -22,16 +22,30 @@ def transform(self, node, results): assert results - syms = self.syms filename = results["filename"] globals = results.get("globals") locals = results.get("locals") - args = [Name('open'), LParen(), filename.clone(), RParen(), Dot(), - Name('read'), LParen(), RParen()] - args[0].set_prefix("") + + # Copy over the prefix from the right parentheses end of the execfile + # call. + execfile_paren = node.children[-1].children[-1].clone() + # Construct open().read(). + open_args = ArgList([filename.clone()], rparen=execfile_paren) + open_call = Node(syms.power, [Name("open"), open_args]) + read = [Node(syms.trailer, [Dot(), Name('read')]), + Node(syms.trailer, [LParen(), RParen()])] + open_expr = [open_call] + read + # Wrap the open call in a compile call. This is so the filename will be + # preserved in the execed code. + filename_arg = filename.clone() + filename_arg.set_prefix(" ") + exec_str = String("'exec'", " ") + compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str] + compile_call = Call(Name("compile"), compile_args, "") + # Finally, replace the execfile call with an exec call. + args = [compile_call] if globals is not None: args.extend([Comma(), globals.clone()]) if locals is not None: args.extend([Comma(), locals.clone()]) - return Call(Name("exec"), args, prefix=node.get_prefix()) Modified: python/branches/release30-maint/Lib/lib2to3/fixes/fix_import.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/fixes/fix_import.py (original) +++ python/branches/release30-maint/Lib/lib2to3/fixes/fix_import.py Sat Jan 3 18:06:28 2009 @@ -13,55 +13,78 @@ # Local imports from .. import fixer_base from os.path import dirname, join, exists, pathsep -from ..fixer_util import FromImport, syms +from ..fixer_util import FromImport, syms, token + + +def traverse_imports(names): + """ + Walks over all the names imported in a dotted_as_names node. + """ + pending = [names] + while pending: + node = pending.pop() + if node.type == token.NAME: + yield node.value + elif node.type == syms.dotted_name: + yield "".join([ch.value for ch in node.children]) + elif node.type == syms.dotted_as_name: + pending.append(node.children[0]) + elif node.type == syms.dotted_as_names: + pending.extend(node.children[::-2]) + else: + raise AssertionError("unkown node type") + class FixImport(fixer_base.BaseFix): PATTERN = """ - import_from< type='from' imp=any 'import' ['('] any [')'] > + import_from< 'from' imp=any 'import' ['('] any [')'] > | - import_name< type='import' imp=any > + import_name< 'import' imp=any > """ def transform(self, node, results): imp = results['imp'] - mod_name = str(imp.children[0] if imp.type == syms.dotted_as_name \ - else imp) - - if str(imp).startswith('.'): - # Already a new-style import - return - - if not probably_a_local_import(str(mod_name), self.filename): - # I guess this is a global import -- skip it! - return - - if results['type'].value == 'from': + if node.type == syms.import_from: # Some imps are top-level (eg: 'import ham') # some are first level (eg: 'import ham.eggs') # some are third level (eg: 'import ham.eggs as spam') # Hence, the loop while not hasattr(imp, 'value'): imp = imp.children[0] - imp.value = "." + imp.value - node.changed() + if self.probably_a_local_import(imp.value): + imp.value = "." + imp.value + imp.changed() + return node else: - new = FromImport('.', getattr(imp, 'content', None) or [imp]) + have_local = False + have_absolute = False + for mod_name in traverse_imports(imp): + if self.probably_a_local_import(mod_name): + have_local = True + else: + have_absolute = True + if have_absolute: + if have_local: + # We won't handle both sibling and absolute imports in the + # same statement at the moment. + self.warning(node, "absolute and local imports together") + return + + new = FromImport('.', [imp]) new.set_prefix(node.get_prefix()) - node = new - return node + return new -def probably_a_local_import(imp_name, file_path): - # Must be stripped because the right space is included by the parser - imp_name = imp_name.split('.', 1)[0].strip() - base_path = dirname(file_path) - base_path = join(base_path, imp_name) - # If there is no __init__.py next to the file its not in a package - # so can't be a relative import. - if not exists(join(dirname(base_path), '__init__.py')): + def probably_a_local_import(self, imp_name): + imp_name = imp_name.split('.', 1)[0] + base_path = dirname(self.filename) + base_path = join(base_path, imp_name) + # If there is no __init__.py next to the file its not in a package + # so can't be a relative import. + if not exists(join(dirname(base_path), '__init__.py')): + return False + for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: + if exists(base_path + ext): + return True return False - for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: - if exists(base_path + ext): - return True - return False Modified: python/branches/release30-maint/Lib/lib2to3/fixes/fix_imports.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/fixes/fix_imports.py (original) +++ python/branches/release30-maint/Lib/lib2to3/fixes/fix_imports.py Sat Jan 3 18:06:28 2009 @@ -118,7 +118,7 @@ def transform(self, node, results): import_mod = results.get("module_name") if import_mod: - new_name = self.mapping[(import_mod or mod_name).value] + new_name = self.mapping[import_mod.value] import_mod.replace(Name(new_name, prefix=import_mod.get_prefix())) if "name_import" in results: # If it's not a "from x import x, y" or "import x as y" import, @@ -129,10 +129,8 @@ # line (e.g., "import StringIO, urlparse"). The problem is that I # can't figure out an easy way to make a pattern recognize the # keys of MAPPING randomly sprinkled in an import statement. - while True: - results = self.match(node) - if not results: - break + results = self.match(node) + if results: self.transform(node, results) else: # Replace usage of the module. Modified: python/branches/release30-maint/Lib/lib2to3/fixes/fix_long.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/fixes/fix_long.py (original) +++ python/branches/release30-maint/Lib/lib2to3/fixes/fix_long.py Sat Jan 3 18:06:28 2009 @@ -5,20 +5,18 @@ """ # Local imports -from .. import pytree from .. import fixer_base -from ..fixer_util import Name, Number +from ..fixer_util import Name, Number, is_probably_builtin class FixLong(fixer_base.BaseFix): PATTERN = "'long'" - static_long = Name("long") static_int = Name("int") def transform(self, node, results): - assert node == self.static_long, node - new = self.static_int.clone() - new.set_prefix(node.get_prefix()) - return new + if is_probably_builtin(node): + new = self.static_int.clone() + new.set_prefix(node.get_prefix()) + return new Modified: python/branches/release30-maint/Lib/lib2to3/main.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/main.py (original) +++ python/branches/release30-maint/Lib/lib2to3/main.py Sat Jan 3 18:06:28 2009 @@ -41,7 +41,7 @@ super(StdoutRefactoringTool, self).write_file(new_text, filename, old_text) if not self.nobackups: - shutil.copymode(filename, backup) + shutil.copymode(backup, filename) def print_output(self, lines): for line in lines: Modified: python/branches/release30-maint/Lib/lib2to3/refactor.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/refactor.py (original) +++ python/branches/release30-maint/Lib/lib2to3/refactor.py Sat Jan 3 18:06:28 2009 @@ -287,17 +287,13 @@ Returns: True if the tree was modified, False otherwise. """ - # Two calls to chain are required because pre_order.values() - # will be a list of lists of fixers: - # [[, ], []] - all_fixers = chain(self.pre_order, self.post_order) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.start_tree(tree, name) self.traverse_by(self.pre_order_heads, tree.pre_order()) self.traverse_by(self.post_order_heads, tree.post_order()) - for fixer in all_fixers: + for fixer in chain(self.pre_order, self.post_order): fixer.finish_tree(tree, name) return tree.was_changed Modified: python/branches/release30-maint/Lib/lib2to3/tests/data/py3_test_grammar.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/tests/data/py3_test_grammar.py (original) +++ python/branches/release30-maint/Lib/lib2to3/tests/data/py3_test_grammar.py Sat Jan 3 18:06:28 2009 @@ -485,6 +485,14 @@ global a, b global one, two, three, four, five, six, seven, eight, nine, ten + def testNonlocal(self): + # 'nonlocal' NAME (',' NAME)* + x = 0 + y = 0 + def f(): + nonlocal x + nonlocal x, y + def testAssert(self): # assert_stmt: 'assert' test [',' test] assert 1 Modified: python/branches/release30-maint/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/branches/release30-maint/Lib/lib2to3/tests/test_fixers.py (original) +++ python/branches/release30-maint/Lib/lib2to3/tests/test_fixers.py Sat Jan 3 18:06:28 2009 @@ -1073,11 +1073,72 @@ a = """z = type(x) in (int, int)""" self.check(b, a) + def test_unchanged(self): + s = """long = True""" + self.unchanged(s) + + s = """s.long = True""" + self.unchanged(s) + + s = """def long(): pass""" + self.unchanged(s) + + s = """class long(): pass""" + self.unchanged(s) + + s = """def f(long): pass""" + self.unchanged(s) + + s = """def f(g, long): pass""" + self.unchanged(s) + + s = """def f(x, long=True): pass""" + self.unchanged(s) + def test_prefix_preservation(self): b = """x = long( x )""" a = """x = int( x )""" self.check(b, a) + +class Test_execfile(FixerTestCase): + fixer = "execfile" + + def test_conversion(self): + b = """execfile("fn")""" + a = """exec(compile(open("fn").read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)""" + self.check(b, a) + + b = """execfile("fn", glob, loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)""" + self.check(b, a) + + b = """execfile("fn", locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)""" + self.check(b, a) + + b = """execfile("fn", globals=glob, locals=loc)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)""" + self.check(b, a) + + def test_spacing(self): + b = """execfile( "fn" )""" + a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))""" + self.check(b, a) + + b = """execfile("fn", globals = glob)""" + a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)""" + self.check(b, a) + + class Test_isinstance(FixerTestCase): fixer = "isinstance" @@ -3466,11 +3527,30 @@ a = "from . import foo, bar" self.check_both(b, a) + b = "import foo, bar, x" + a = "from . import foo, bar, x" + self.check_both(b, a) + + b = "import x, y, z" + a = "from . import x, y, z" + self.check_both(b, a) + def test_import_as(self): b = "import foo as x" a = "from . import foo as x" self.check_both(b, a) + b = "import a as b, b as c, c as d" + a = "from . import a as b, b as c, c as d" + self.check_both(b, a) + + def test_local_and_absolute(self): + self.always_exists = False + self.present_files = set(["foo.py", "__init__.py"]) + + s = "import foo, bar" + self.warns_unchanged(s, "absolute and local imports together") + def test_dotted_import(self): b = "import foo.bar" a = "from . import foo.bar" From python-checkins at python.org Sat Jan 3 18:10:06 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 18:10:06 +0100 (CET) Subject: [Python-checkins] r68202 - in python/branches/release30-maint: Include/object.h Lib/ctypes/test/test_pep3118.py Lib/test/test_io.py Lib/test/test_memoryview.py Lib/test/test_sys.py Misc/NEWS Objects/memoryobject.c Objects/unicodeobject.c Message-ID: <20090103171006.598291E4002@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 18:10:05 2009 New Revision: 68202 Log: Merged revisions 68200 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ........ r68200 | antoine.pitrou | 2009-01-03 17:59:18 +0100 (sam., 03 janv. 2009) | 8 lines Issue #4580: slicing of memoryviews when itemsize != 1 is wrong. Also fix len() to return number of items rather than length in bytes. I'm sorry it was not possible for me to work on this without reindenting a bit some stuff around. The indentation in memoryobject.c is a mess, I'll open a separate bug for it. ........ Modified: python/branches/release30-maint/ (props changed) python/branches/release30-maint/Include/object.h python/branches/release30-maint/Lib/ctypes/test/test_pep3118.py python/branches/release30-maint/Lib/test/test_io.py python/branches/release30-maint/Lib/test/test_memoryview.py python/branches/release30-maint/Lib/test/test_sys.py python/branches/release30-maint/Misc/NEWS python/branches/release30-maint/Objects/memoryobject.c python/branches/release30-maint/Objects/unicodeobject.c Modified: python/branches/release30-maint/Include/object.h ============================================================================== --- python/branches/release30-maint/Include/object.h (original) +++ python/branches/release30-maint/Include/object.h Sat Jan 3 18:10:05 2009 @@ -144,16 +144,18 @@ typedef struct bufferinfo { void *buf; PyObject *obj; /* owned reference */ - Py_ssize_t len; - Py_ssize_t itemsize; /* This is Py_ssize_t so it can be - pointed to by strides in simple case.*/ - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; + Py_ssize_t len; + Py_ssize_t itemsize; /* This is Py_ssize_t so it can be + pointed to by strides in simple case.*/ + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + Py_ssize_t smalltable[2]; /* static store for shape and strides of + mono-dimensional buffers. */ + void *internal; } Py_buffer; typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); Modified: python/branches/release30-maint/Lib/ctypes/test/test_pep3118.py ============================================================================== --- python/branches/release30-maint/Lib/ctypes/test/test_pep3118.py (original) +++ python/branches/release30-maint/Lib/ctypes/test/test_pep3118.py Sat Jan 3 18:10:05 2009 @@ -25,7 +25,10 @@ v = memoryview(ob) try: self.failUnlessEqual(normalize(v.format), normalize(fmt)) - self.failUnlessEqual(len(v), sizeof(ob)) + if shape is not None: + self.failUnlessEqual(len(v), shape[0]) + else: + self.failUnlessEqual(len(v) * sizeof(itemtp), sizeof(ob)) self.failUnlessEqual(v.itemsize, sizeof(itemtp)) self.failUnlessEqual(v.shape, shape) # ctypes object always have a non-strided memory block @@ -37,7 +40,7 @@ n = 1 for dim in v.shape: n = n * dim - self.failUnlessEqual(v.itemsize * n, len(v)) + self.failUnlessEqual(n * v.itemsize, len(v.tobytes())) except: # so that we can see the failing type print(tp) @@ -49,7 +52,10 @@ v = memoryview(ob) try: self.failUnlessEqual(v.format, fmt) - self.failUnlessEqual(len(v), sizeof(ob)) + if shape is not None: + self.failUnlessEqual(len(v), shape[0]) + else: + self.failUnlessEqual(len(v) * sizeof(itemtp), sizeof(ob)) self.failUnlessEqual(v.itemsize, sizeof(itemtp)) self.failUnlessEqual(v.shape, shape) # ctypes object always have a non-strided memory block @@ -61,7 +67,7 @@ n = 1 for dim in v.shape: n = n * dim - self.failUnlessEqual(v.itemsize * n, len(v)) + self.failUnlessEqual(n, len(v)) except: # so that we can see the failing type print(tp) Modified: python/branches/release30-maint/Lib/test/test_io.py ============================================================================== --- python/branches/release30-maint/Lib/test/test_io.py (original) +++ python/branches/release30-maint/Lib/test/test_io.py Sat Jan 3 18:10:05 2009 @@ -260,7 +260,7 @@ def test_array_writes(self): a = array.array('i', range(10)) - n = len(memoryview(a)) + n = len(a.tostring()) f = io.open(support.TESTFN, "wb", 0) self.assertEqual(f.write(a), n) f.close() Modified: python/branches/release30-maint/Lib/test/test_memoryview.py ============================================================================== --- python/branches/release30-maint/Lib/test/test_memoryview.py (original) +++ python/branches/release30-maint/Lib/test/test_memoryview.py Sat Jan 3 18:10:05 2009 @@ -8,24 +8,30 @@ import sys import gc import weakref +import array -class CommonMemoryTests: - # - # Tests common to direct memoryviews and sliced memoryviews - # +class AbstractMemoryTests: + source_bytes = b"abcdef" - base_object = b"abcdef" + @property + def _source(self): + return self.source_bytes + + @property + def _types(self): + return filter(None, [self.ro_type, self.rw_type]) def check_getitem_with_type(self, tp): - b = tp(self.base_object) + item = self.getitem_type + b = tp(self._source) oldrefcount = sys.getrefcount(b) m = self._view(b) - self.assertEquals(m[0], b"a") + self.assertEquals(m[0], item(b"a")) self.assert_(isinstance(m[0], bytes), type(m[0])) - self.assertEquals(m[5], b"f") - self.assertEquals(m[-1], b"f") - self.assertEquals(m[-6], b"a") + self.assertEquals(m[5], item(b"f")) + self.assertEquals(m[-1], item(b"f")) + self.assertEquals(m[-6], item(b"a")) # Bounds checking self.assertRaises(IndexError, lambda: m[6]) self.assertRaises(IndexError, lambda: m[-7]) @@ -38,14 +44,14 @@ m = None self.assertEquals(sys.getrefcount(b), oldrefcount) - def test_getitem_readonly(self): - self.check_getitem_with_type(bytes) - - def test_getitem_writable(self): - self.check_getitem_with_type(bytearray) + def test_getitem(self): + for tp in self._types: + self.check_getitem_with_type(tp) def test_setitem_readonly(self): - b = self.base_object + if not self.ro_type: + return + b = self.ro_type(self._source) oldrefcount = sys.getrefcount(b) m = self._view(b) def setitem(value): @@ -57,27 +63,30 @@ self.assertEquals(sys.getrefcount(b), oldrefcount) def test_setitem_writable(self): - b = bytearray(self.base_object) + if not self.rw_type: + return + tp = self.rw_type + b = self.rw_type(self._source) oldrefcount = sys.getrefcount(b) m = self._view(b) - m[0] = b"0" - self._check_contents(b, b"0bcdef") - m[1:3] = b"12" - self._check_contents(b, b"012def") - m[1:1] = b"" - self._check_contents(b, b"012def") - m[:] = b"abcdef" - self._check_contents(b, b"abcdef") + m[0] = tp(b"0") + self._check_contents(tp, b, b"0bcdef") + m[1:3] = tp(b"12") + self._check_contents(tp, b, b"012def") + m[1:1] = tp(b"") + self._check_contents(tp, b, b"012def") + m[:] = tp(b"abcdef") + self._check_contents(tp, b, b"abcdef") # Overlapping copies of a view into itself m[0:3] = m[2:5] - self._check_contents(b, b"cdedef") - m[:] = b"abcdef" + self._check_contents(tp, b, b"cdedef") + m[:] = tp(b"abcdef") m[2:5] = m[0:3] - self._check_contents(b, b"ababcf") + self._check_contents(tp, b, b"ababcf") def setitem(key, value): - m[key] = value + m[key] = tp(value) # Bounds checking self.assertRaises(IndexError, setitem, 6, b"a") self.assertRaises(IndexError, setitem, -7, b"a") @@ -96,159 +105,224 @@ m = None self.assertEquals(sys.getrefcount(b), oldrefcount) - def test_len(self): - self.assertEquals(len(self._view(self.base_object)), 6) - def test_tobytes(self): - m = self._view(self.base_object) - b = m.tobytes() - self.assertEquals(b, b"abcdef") - self.assert_(isinstance(b, bytes), type(b)) + for tp in self._types: + m = self._view(tp(self._source)) + b = m.tobytes() + # This calls self.getitem_type() on each separate byte of b"abcdef" + expected = b"".join( + self.getitem_type(bytes([c])) for c in b"abcdef") + self.assertEquals(b, expected) + self.assert_(isinstance(b, bytes), type(b)) def test_tolist(self): - m = self._view(self.base_object) - l = m.tolist() - self.assertEquals(l, list(b"abcdef")) + for tp in self._types: + m = self._view(tp(self._source)) + l = m.tolist() + self.assertEquals(l, list(b"abcdef")) def test_compare(self): # memoryviews can compare for equality with other objects # having the buffer interface. - m = self._view(self.base_object) - for tp in (bytes, bytearray): - self.assertTrue(m == tp(b"abcdef")) - self.assertFalse(m != tp(b"abcdef")) - self.assertFalse(m == tp(b"abcde")) - self.assertTrue(m != tp(b"abcde")) - self.assertFalse(m == tp(b"abcde1")) - self.assertTrue(m != tp(b"abcde1")) - self.assertTrue(m == m) - self.assertTrue(m == m[:]) - self.assertTrue(m[0:6] == m[:]) - self.assertFalse(m[0:5] == m) - - # Comparison with objects which don't support the buffer API - self.assertFalse(m == "abc") - self.assertTrue(m != "abc") - self.assertFalse("abc" == m) - self.assertTrue("abc" != m) - - # Unordered comparisons - for c in (m, b"abcdef"): - self.assertRaises(TypeError, lambda: m < c) - self.assertRaises(TypeError, lambda: c <= m) - self.assertRaises(TypeError, lambda: m >= c) - self.assertRaises(TypeError, lambda: c > m) + for tp in self._types: + m = self._view(tp(self._source)) + for tp_comp in self._types: + self.assertTrue(m == tp_comp(b"abcdef")) + self.assertFalse(m != tp_comp(b"abcdef")) + self.assertFalse(m == tp_comp(b"abcde")) + self.assertTrue(m != tp_comp(b"abcde")) + self.assertFalse(m == tp_comp(b"abcde1")) + self.assertTrue(m != tp_comp(b"abcde1")) + self.assertTrue(m == m) + self.assertTrue(m == m[:]) + self.assertTrue(m[0:6] == m[:]) + self.assertFalse(m[0:5] == m) + + # Comparison with objects which don't support the buffer API + self.assertFalse(m == "abcdef") + self.assertTrue(m != "abcdef") + self.assertFalse("abcdef" == m) + self.assertTrue("abcdef" != m) + + # Unordered comparisons + for c in (m, b"abcdef"): + self.assertRaises(TypeError, lambda: m < c) + self.assertRaises(TypeError, lambda: c <= m) + self.assertRaises(TypeError, lambda: m >= c) + self.assertRaises(TypeError, lambda: c > m) def check_attributes_with_type(self, tp): - b = tp(self.base_object) - m = self._view(b) - self.assertEquals(m.format, 'B') - self.assertEquals(m.itemsize, 1) + m = self._view(tp(self._source)) + self.assertEquals(m.format, self.format) + self.assertEquals(m.itemsize, self.itemsize) self.assertEquals(m.ndim, 1) self.assertEquals(m.shape, (6,)) self.assertEquals(len(m), 6) - self.assertEquals(m.strides, (1,)) + self.assertEquals(m.strides, (self.itemsize,)) self.assertEquals(m.suboffsets, None) return m def test_attributes_readonly(self): - m = self.check_attributes_with_type(bytes) + if not self.ro_type: + return + m = self.check_attributes_with_type(self.ro_type) self.assertEquals(m.readonly, True) def test_attributes_writable(self): - m = self.check_attributes_with_type(bytearray) + if not self.rw_type: + return + m = self.check_attributes_with_type(self.rw_type) self.assertEquals(m.readonly, False) def test_getbuffer(self): # Test PyObject_GetBuffer() on a memoryview object. - b = self.base_object - oldrefcount = sys.getrefcount(b) - m = self._view(b) - oldviewrefcount = sys.getrefcount(m) - s = str(m, "utf-8") - self._check_contents(b, s.encode("utf-8")) - self.assertEquals(sys.getrefcount(m), oldviewrefcount) - m = None - self.assertEquals(sys.getrefcount(b), oldrefcount) + for tp in self._types: + b = tp(self._source) + oldrefcount = sys.getrefcount(b) + m = self._view(b) + oldviewrefcount = sys.getrefcount(m) + s = str(m, "utf-8") + self._check_contents(tp, b, s.encode("utf-8")) + self.assertEquals(sys.getrefcount(m), oldviewrefcount) + m = None + self.assertEquals(sys.getrefcount(b), oldrefcount) def test_gc(self): - class MyBytes(bytes): - pass - class MyObject: - pass + for tp in self._types: + if not isinstance(tp, type): + # If tp is a factory rather than a plain type, skip + continue + + class MySource(tp): + pass + class MyObject: + pass + + # Create a reference cycle through a memoryview object + b = MySource(tp(b'abc')) + m = self._view(b) + o = MyObject() + b.m = m + b.o = o + wr = weakref.ref(o) + b = m = o = None + # The cycle must be broken + gc.collect() + self.assert_(wr() is None, wr()) + + +# Variations on source objects for the buffer: bytes-like objects, then arrays +# with itemsize > 1. +# NOTE: support for multi-dimensional objects is unimplemented. + +class BaseBytesMemoryTests(AbstractMemoryTests): + ro_type = bytes + rw_type = bytearray + getitem_type = bytes + itemsize = 1 + format = 'B' + +class BaseArrayMemoryTests(AbstractMemoryTests): + ro_type = None + rw_type = lambda self, b: array.array('i', list(b)) + getitem_type = lambda self, b: array.array('i', list(b)).tostring() + itemsize = array.array('i').itemsize + format = 'i' - # Create a reference cycle through a memoryview object - b = MyBytes(b'abc') - m = self._view(b) - o = MyObject() - b.m = m - b.o = o - wr = weakref.ref(o) - b = m = o = None - # The cycle must be broken - gc.collect() - self.assert_(wr() is None, wr()) + def test_getbuffer(self): + # XXX Test should be adapted for non-byte buffers + pass + + def test_tolist(self): + # XXX NotImplementedError: tolist() only supports byte views + pass -class MemoryviewTest(unittest.TestCase, CommonMemoryTests): +# Variations on indirection levels: memoryview, slice of memoryview, +# slice of slice of memoryview. +# This is important to test allocation subtleties. +class BaseMemoryviewTests: def _view(self, obj): return memoryview(obj) - def _check_contents(self, obj, contents): - self.assertEquals(obj, contents) + def _check_contents(self, tp, obj, contents): + self.assertEquals(obj, tp(contents)) - def test_constructor(self): - ob = b'test' - self.assert_(memoryview(ob)) - self.assert_(memoryview(object=ob)) - self.assertRaises(TypeError, memoryview) - self.assertRaises(TypeError, memoryview, ob, ob) - self.assertRaises(TypeError, memoryview, argument=ob) - self.assertRaises(TypeError, memoryview, ob, argument=True) - - def test_array_assign(self): - # Issue #4569: segfault when mutating a memoryview with itemsize != 1 - from array import array - a = array('i', range(10)) - m = memoryview(a) - new_a = array('i', range(9, -1, -1)) - m[:] = new_a - self.assertEquals(a, new_a) - - -class MemorySliceTest(unittest.TestCase, CommonMemoryTests): - base_object = b"XabcdefY" +class BaseMemorySliceTests: + source_bytes = b"XabcdefY" def _view(self, obj): m = memoryview(obj) return m[1:7] - def _check_contents(self, obj, contents): - self.assertEquals(obj[1:7], contents) + def _check_contents(self, tp, obj, contents): + self.assertEquals(obj[1:7], tp(contents)) def test_refs(self): - m = memoryview(b"ab") - oldrefcount = sys.getrefcount(m) - m[1:2] - self.assertEquals(sys.getrefcount(m), oldrefcount) - + for tp in self._types: + m = memoryview(tp(self._source)) + oldrefcount = sys.getrefcount(m) + m[1:2] + self.assertEquals(sys.getrefcount(m), oldrefcount) -class MemorySliceSliceTest(unittest.TestCase, CommonMemoryTests): - base_object = b"XabcdefY" +class BaseMemorySliceSliceTests: + source_bytes = b"XabcdefY" def _view(self, obj): m = memoryview(obj) return m[:7][1:] - def _check_contents(self, obj, contents): - self.assertEquals(obj[1:7], contents) + def _check_contents(self, tp, obj, contents): + self.assertEquals(obj[1:7], tp(contents)) -def test_main(): - test.support.run_unittest( - MemoryviewTest, MemorySliceTest, MemorySliceSliceTest) +# Concrete test classes + +class BytesMemoryviewTest(unittest.TestCase, + BaseMemoryviewTests, BaseBytesMemoryTests): + + def test_constructor(self): + for tp in self._types: + ob = tp(self._source) + self.assert_(memoryview(ob)) + self.assert_(memoryview(object=ob)) + self.assertRaises(TypeError, memoryview) + self.assertRaises(TypeError, memoryview, ob, ob) + self.assertRaises(TypeError, memoryview, argument=ob) + self.assertRaises(TypeError, memoryview, ob, argument=True) + +class ArrayMemoryviewTest(unittest.TestCase, + BaseMemoryviewTests, BaseArrayMemoryTests): + + def test_array_assign(self): + # Issue #4569: segfault when mutating a memoryview with itemsize != 1 + a = array.array('i', range(10)) + m = memoryview(a) + new_a = array.array('i', range(9, -1, -1)) + m[:] = new_a + self.assertEquals(a, new_a) +class BytesMemorySliceTest(unittest.TestCase, + BaseMemorySliceTests, BaseBytesMemoryTests): + pass + +class ArrayMemorySliceTest(unittest.TestCase, + BaseMemorySliceTests, BaseArrayMemoryTests): + pass + +class BytesMemorySliceSliceTest(unittest.TestCase, + BaseMemorySliceSliceTests, BaseBytesMemoryTests): + pass + +class ArrayMemorySliceSliceTest(unittest.TestCase, + BaseMemorySliceSliceTests, BaseArrayMemoryTests): + pass + + +def test_main(): + test.support.run_unittest(__name__) + if __name__ == "__main__": test_main() Modified: python/branches/release30-maint/Lib/test/test_sys.py ============================================================================== --- python/branches/release30-maint/Lib/test/test_sys.py (original) +++ python/branches/release30-maint/Lib/test/test_sys.py Sat Jan 3 18:10:05 2009 @@ -559,7 +559,7 @@ check(32768*32768-1, size(vh) + 2*self.H) check(32768*32768, size(vh) + 3*self.H) # memory - check(memoryview(b''), size(h + 'P PP2P2i5P')) + check(memoryview(b''), size(h + 'P PP2P2i7P')) # module check(unittest, size(h + '3P')) # None Modified: python/branches/release30-maint/Misc/NEWS ============================================================================== --- python/branches/release30-maint/Misc/NEWS (original) +++ python/branches/release30-maint/Misc/NEWS Sat Jan 3 18:10:05 2009 @@ -12,6 +12,10 @@ Core and Builtins ----------------- +- Issue #4580: Fix slicing of memoryviews when the item size is greater than + one byte. Also fixes the meaning of len() so that it returns the number of + items, rather than the size in bytes. + - Issue #4747: When the terminal does not use utf-8, executing a script with non-ascii characters in its name could fail with a "SyntaxError: None" error. Modified: python/branches/release30-maint/Objects/memoryobject.c ============================================================================== --- python/branches/release30-maint/Objects/memoryobject.c (original) +++ python/branches/release30-maint/Objects/memoryobject.c Sat Jan 3 18:10:05 2009 @@ -3,26 +3,31 @@ #include "Python.h" -static void -dup_buffer(Py_buffer *dest, Py_buffer *src) -{ - *dest = *src; - if (src->shape == &(src->len)) - dest->shape = &(dest->len); - if (src->strides == &(src->itemsize)) - dest->strides = &(dest->itemsize); -} - -/* XXX The buffer API should mandate that the shape array be non-NULL, but - it would complicate some code since the (de)allocation semantics of shape - are not specified. */ static Py_ssize_t get_shape0(Py_buffer *buf) { if (buf->shape != NULL) return buf->shape[0]; - assert(buf->ndim == 1 && buf->itemsize > 0); - return buf->len / buf->itemsize; + if (buf->ndim == 0) + return 1; + PyErr_SetString(PyExc_TypeError, + "exported buffer does not have any shape information associated " + "to it"); + return -1; +} + +static void +dup_buffer(Py_buffer *dest, Py_buffer *src) +{ + *dest = *src; + if (src->ndim == 1 && src->shape != NULL) { + dest->shape = &(dest->smalltable[0]); + dest->shape[0] = get_shape0(src); + } + if (src->ndim == 1 && src->strides != NULL) { + dest->strides = &(dest->smalltable[1]); + dest->strides[0] = src->strides[0]; + } } static int @@ -449,8 +454,6 @@ return res; } - - static PyMethodDef memory_methods[] = { {"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, NULL}, {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, NULL}, @@ -474,19 +477,19 @@ PyObject_CopyData(PyTuple_GET_ITEM(self->base,0), PyTuple_GET_ITEM(self->base,1)); - /* The view member should have readonly == -1 in - this instance indicating that the memory can - be "locked" and was locked and will be unlocked - again after this call. - */ - PyBuffer_Release(&(self->view)); - } - else { - PyBuffer_Release(&(self->view)); - } - Py_CLEAR(self->base); + /* The view member should have readonly == -1 in + this instance indicating that the memory can + be "locked" and was locked and will be unlocked + again after this call. + */ + PyBuffer_Release(&(self->view)); + } + else { + PyBuffer_Release(&(self->view)); } - PyObject_GC_Del(self); + Py_CLEAR(self->base); + } + PyObject_GC_Del(self); } static PyObject * @@ -512,16 +515,10 @@ } /* Sequence methods */ - static Py_ssize_t memory_length(PyMemoryViewObject *self) { - Py_buffer view; - - if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0) - return -1; - PyBuffer_Release(&view); - return view.len; + return get_shape0(&self->view); } /* @@ -589,40 +586,38 @@ } } else if (PySlice_Check(key)) { - Py_ssize_t start, stop, step, slicelength; - + Py_ssize_t start, stop, step, slicelength; + if (PySlice_GetIndicesEx((PySliceObject*)key, get_shape0(view), - &start, &stop, &step, &slicelength) < 0) { - return NULL; - } + &start, &stop, &step, &slicelength) < 0) { + return NULL; + } - if (step == 1 && view->ndim == 1) { - Py_buffer newview; - void *newbuf = (char *) view->buf - + start * view->itemsize; - int newflags = view->readonly - ? PyBUF_CONTIG_RO : PyBUF_CONTIG; + if (step == 1 && view->ndim == 1) { + Py_buffer newview; + void *newbuf = (char *) view->buf + + start * view->itemsize; + int newflags = view->readonly + ? PyBUF_CONTIG_RO : PyBUF_CONTIG; - /* XXX There should be an API to create a subbuffer */ - if (view->obj != NULL) { - if (PyObject_GetBuffer(view->obj, - &newview, newflags) == -1) - return NULL; - } - else { - newview = *view; - } - newview.buf = newbuf; - newview.len = slicelength; - newview.format = view->format; - if (view->shape == &(view->len)) - newview.shape = &(newview.len); - if (view->strides == &(view->itemsize)) - newview.strides = &(newview.itemsize); - return PyMemoryView_FromBuffer(&newview); - } - PyErr_SetNone(PyExc_NotImplementedError); - return NULL; + /* XXX There should be an API to create a subbuffer */ + if (view->obj != NULL) { + if (PyObject_GetBuffer(view->obj, &newview, newflags) == -1) + return NULL; + } + else { + newview = *view; + } + newview.buf = newbuf; + newview.len = slicelength * newview.itemsize; + newview.format = view->format; + newview.shape = &(newview.smalltable[0]); + newview.shape[0] = slicelength; + newview.strides = &(newview.itemsize); + return PyMemoryView_FromBuffer(&newview); + } + PyErr_SetNone(PyExc_NotImplementedError); + return NULL; } PyErr_Format(PyExc_TypeError, "cannot index memory using \"%.200s\"", @@ -747,7 +742,7 @@ if (vv.itemsize != ww.itemsize || vv.len != ww.len) goto _end; - equal = !memcmp(vv.buf, ww.buf, vv.len * vv.itemsize); + equal = !memcmp(vv.buf, ww.buf, vv.len); _end: PyBuffer_Release(&vv); Modified: python/branches/release30-maint/Objects/unicodeobject.c ============================================================================== --- python/branches/release30-maint/Objects/unicodeobject.c (original) +++ python/branches/release30-maint/Objects/unicodeobject.c Sat Jan 3 18:10:05 2009 @@ -1203,7 +1203,7 @@ /* Decode via the codec registry */ buffer = NULL; - if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_SIMPLE) < 0) + if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_FULL_RO) < 0) goto onError; buffer = PyMemoryView_FromBuffer(&info); if (buffer == NULL) From python-checkins at python.org Sat Jan 3 18:19:27 2009 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 3 Jan 2009 18:19:27 +0100 (CET) Subject: [Python-checkins] r68203 - in python/trunk: Doc/c-api/sys.rst Doc/data/refcounts.dat Makefile.pre.in Misc/NEWS PC/VC6/pythoncore.dsp PC/VS7.1/pythoncore.vcproj PC/VS8.0/pythoncore.vcproj PC/os2emx/Makefile PC/os2emx/python27.def PC/os2vacpp/makefile PC/os2vacpp/makefile.omk PC/os2vacpp/python.def PCbuild/pythoncore.vcproj Python/getmtime.c Python/import.c RISCOS/Makefile RISCOS/Python/getmtime_riscos.c Message-ID: <20090103171927.1BDBB1E4002@bag.python.org> Author: martin.v.loewis Date: Sat Jan 3 18:19:26 2009 New Revision: 68203 Log: Issue #4817: Remove unused function PyOS_GetLastModificationTime. Removed: python/trunk/Python/getmtime.c python/trunk/RISCOS/Python/getmtime_riscos.c Modified: python/trunk/Doc/c-api/sys.rst python/trunk/Doc/data/refcounts.dat python/trunk/Makefile.pre.in python/trunk/Misc/NEWS python/trunk/PC/VC6/pythoncore.dsp python/trunk/PC/VS7.1/pythoncore.vcproj python/trunk/PC/VS8.0/pythoncore.vcproj python/trunk/PC/os2emx/Makefile python/trunk/PC/os2emx/python27.def python/trunk/PC/os2vacpp/makefile python/trunk/PC/os2vacpp/makefile.omk python/trunk/PC/os2vacpp/python.def python/trunk/PCbuild/pythoncore.vcproj python/trunk/Python/import.c python/trunk/RISCOS/Makefile Modified: python/trunk/Doc/c-api/sys.rst ============================================================================== --- python/trunk/Doc/c-api/sys.rst (original) +++ python/trunk/Doc/c-api/sys.rst Sat Jan 3 18:19:26 2009 @@ -15,13 +15,6 @@ one of the strings ``''`` or ``'???'``. -.. cfunction:: long PyOS_GetLastModificationTime(char *filename) - - Return the time of last modification of the file *filename*. The result is - encoded in the same way as the timestamp returned by the standard C library - function :cfunc:`time`. - - .. cfunction:: void PyOS_AfterFork() Function to update some internal state after a process fork; this should be Modified: python/trunk/Doc/data/refcounts.dat ============================================================================== --- python/trunk/Doc/data/refcounts.dat (original) +++ python/trunk/Doc/data/refcounts.dat Sat Jan 3 18:19:26 2009 @@ -841,9 +841,6 @@ PyNumber_Xor:PyObject*:o1:0: PyNumber_Xor:PyObject*:o2:0: -PyOS_GetLastModificationTime:long::: -PyOS_GetLastModificationTime:char*:filename:: - PyObject_AsFileDescriptor:int::: PyObject_AsFileDescriptor:PyObject*:o:0: Modified: python/trunk/Makefile.pre.in ============================================================================== --- python/trunk/Makefile.pre.in (original) +++ python/trunk/Makefile.pre.in Sat Jan 3 18:19:26 2009 @@ -264,7 +264,6 @@ Python/getargs.o \ Python/getcompiler.o \ Python/getcopyright.o \ - Python/getmtime.o \ Python/getplatform.o \ Python/getversion.o \ Python/graminit.o \ Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Sat Jan 3 18:19:26 2009 @@ -12,6 +12,8 @@ Core and Builtins ----------------- +- Issue #4817: Remove unused function PyOS_GetLastModificationTime. + - Issue #4075: Use OutputDebugStringW in Py_FatalError. - Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open Modified: python/trunk/PC/VC6/pythoncore.dsp ============================================================================== --- python/trunk/PC/VC6/pythoncore.dsp (original) +++ python/trunk/PC/VC6/pythoncore.dsp Sat Jan 3 18:19:26 2009 @@ -410,10 +410,6 @@ # End Source File # Begin Source File -SOURCE=..\..\Python\getmtime.c -# End Source File -# Begin Source File - SOURCE=..\..\Python\getopt.c # End Source File # Begin Source File Modified: python/trunk/PC/VS7.1/pythoncore.vcproj ============================================================================== --- python/trunk/PC/VS7.1/pythoncore.vcproj (original) +++ python/trunk/PC/VS7.1/pythoncore.vcproj Sat Jan 3 18:19:26 2009 @@ -569,9 +569,6 @@ RelativePath="..\..\Python\getcopyright.c"> - - - - Modified: python/trunk/PC/os2emx/Makefile ============================================================================== --- python/trunk/PC/os2emx/Makefile (original) +++ python/trunk/PC/os2emx/Makefile Sat Jan 3 18:19:26 2009 @@ -351,7 +351,6 @@ Python/getargs.c \ Python/getcompiler.c \ Python/getcopyright.c \ - Python/getmtime.c \ Python/getplatform.c \ Python/getversion.c \ Python/graminit.c \ Modified: python/trunk/PC/os2emx/python27.def ============================================================================== --- python/trunk/PC/os2emx/python27.def (original) +++ python/trunk/PC/os2emx/python27.def Sat Jan 3 18:19:26 2009 @@ -931,9 +931,6 @@ ; From python27_s.lib(getcopyright) "Py_GetCopyright" -; From python27_s.lib(getmtime) - "PyOS_GetLastModificationTime" - ; From python27_s.lib(getplatform) "Py_GetPlatform" Modified: python/trunk/PC/os2vacpp/makefile ============================================================================== --- python/trunk/PC/os2vacpp/makefile (original) +++ python/trunk/PC/os2vacpp/makefile Sat Jan 3 18:19:26 2009 @@ -1693,8 +1693,6 @@ $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ $(PY_INCLUDE)\tupleobject.h -getmtime.obj: pyconfig.h - getplatform.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \ pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \ Modified: python/trunk/PC/os2vacpp/makefile.omk ============================================================================== --- python/trunk/PC/os2vacpp/makefile.omk (original) +++ python/trunk/PC/os2vacpp/makefile.omk Sat Jan 3 18:19:26 2009 @@ -1155,8 +1155,6 @@ pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \ stringobject.h sysmodule.h traceback.h tupleobject.h -getmtime.obj: pyconfig.h - getplatform.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \ import.h intobject.h intrcheck.h listobject.h longobject.h \ Modified: python/trunk/PC/os2vacpp/python.def ============================================================================== --- python/trunk/PC/os2vacpp/python.def (original) +++ python/trunk/PC/os2vacpp/python.def Sat Jan 3 18:19:26 2009 @@ -284,7 +284,6 @@ PyNumber_Xor PyOS_AfterFork PyOS_FiniInterrupts - PyOS_GetLastModificationTime PyOS_InitInterrupts PyOS_InterruptOccurred PyOS_Readline Modified: python/trunk/PCbuild/pythoncore.vcproj ============================================================================== --- python/trunk/PCbuild/pythoncore.vcproj (original) +++ python/trunk/PCbuild/pythoncore.vcproj Sat Jan 3 18:19:26 2009 @@ -1687,10 +1687,6 @@ > - - Deleted: python/trunk/Python/getmtime.c ============================================================================== --- python/trunk/Python/getmtime.c Sat Jan 3 18:19:26 2009 +++ (empty file) @@ -1,26 +0,0 @@ - -/* Subroutine to get the last modification time of a file */ - -/* (A separate file because this may be OS dependent) */ - -#include "Python.h" -#include "pyconfig.h" - -#ifdef __cplusplus -extern "C" { -#endif - -time_t -PyOS_GetLastModificationTime(char *path, FILE *fp) -{ - struct stat st; - if (fstat(fileno(fp), &st) != 0) - return -1; - else - return st.st_mtime; -} - -#ifdef __cplusplus -} -#endif - Modified: python/trunk/Python/import.c ============================================================================== --- python/trunk/Python/import.c (original) +++ python/trunk/Python/import.c Sat Jan 3 18:19:26 2009 @@ -27,8 +27,6 @@ typedef unsigned short mode_t; #endif -extern time_t PyOS_GetLastModificationTime(char *, FILE *); - /* In getmtime.c */ /* Magic word to reject .pyc files generated by other Python versions. It should change for each incompatible change to the bytecode. Modified: python/trunk/RISCOS/Makefile ============================================================================== --- python/trunk/RISCOS/Makefile (original) +++ python/trunk/RISCOS/Makefile Sat Jan 3 18:19:26 2009 @@ -135,7 +135,6 @@ OBJECTS_RISCOS = \ @.Python.o.dynload_riscos\ @.Python.o.getcwd_riscos\ - @.Python.o.getmtime_riscos\ @.o.unixstuff Deleted: python/trunk/RISCOS/Python/getmtime_riscos.c ============================================================================== --- python/trunk/RISCOS/Python/getmtime_riscos.c Sat Jan 3 18:19:26 2009 +++ (empty file) @@ -1,20 +0,0 @@ -#include - -#define __swi -#include "oslib/osfile.h" - -long PyOS_GetLastModificationTime(char *path, FILE *fp) -{ - int obj; - bits load, exec, ftype; - - if (xosfile_read_stamped_no_path(path, &obj, &load, &exec, 0, 0, &ftype)) return -1; - if (obj != osfile_IS_FILE) return -1; - if (ftype == osfile_TYPE_UNTYPED) return -1; - - load &= 0xFF; - load -= 51; - if (exec < 1855548004U) load--; - exec -= 1855548004U; - return exec/100+42949672*load+(95*load)/100; -} From python-checkins at python.org Sat Jan 3 18:22:41 2009 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 3 Jan 2009 18:22:41 +0100 (CET) Subject: [Python-checkins] r68204 - in python/branches/py3k: Doc/c-api/sys.rst Doc/data/refcounts.dat Makefile.pre.in Misc/NEWS PC/VC6/pythoncore.dsp PC/VS7.1/pythoncore.vcproj PC/VS8.0/pythoncore.vcproj PC/os2emx/Makefile PC/os2emx/python27.def PC/os2vacpp/makefile PC/os2vacpp/makefile.omk PC/os2vacpp/python.def PCbuild/pythoncore.vcproj Python/getmtime.c Python/import.c Message-ID: <20090103172241.23FDA1E4002@bag.python.org> Author: martin.v.loewis Date: Sat Jan 3 18:22:40 2009 New Revision: 68204 Log: Merged revisions 68203 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r68203 | martin.v.loewis | 2009-01-03 18:19:26 +0100 (Sa, 03 Jan 2009) | 2 lines Issue #4817: Remove unused function PyOS_GetLastModificationTime. ........ Removed: python/branches/py3k/Python/getmtime.c Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/c-api/sys.rst python/branches/py3k/Doc/data/refcounts.dat python/branches/py3k/Makefile.pre.in python/branches/py3k/Misc/NEWS python/branches/py3k/PC/VC6/pythoncore.dsp python/branches/py3k/PC/VS7.1/pythoncore.vcproj python/branches/py3k/PC/VS8.0/pythoncore.vcproj python/branches/py3k/PC/os2emx/Makefile python/branches/py3k/PC/os2emx/python27.def python/branches/py3k/PC/os2vacpp/makefile python/branches/py3k/PC/os2vacpp/makefile.omk python/branches/py3k/PC/os2vacpp/python.def python/branches/py3k/PCbuild/pythoncore.vcproj python/branches/py3k/Python/import.c Modified: python/branches/py3k/Doc/c-api/sys.rst ============================================================================== --- python/branches/py3k/Doc/c-api/sys.rst (original) +++ python/branches/py3k/Doc/c-api/sys.rst Sat Jan 3 18:22:40 2009 @@ -15,13 +15,6 @@ one of the strings ``''`` or ``'???'``. -.. cfunction:: long PyOS_GetLastModificationTime(char *filename) - - Return the time of last modification of the file *filename*. The result is - encoded in the same way as the timestamp returned by the standard C library - function :cfunc:`time`. - - .. cfunction:: void PyOS_AfterFork() Function to update some internal state after a process fork; this should be Modified: python/branches/py3k/Doc/data/refcounts.dat ============================================================================== --- python/branches/py3k/Doc/data/refcounts.dat (original) +++ python/branches/py3k/Doc/data/refcounts.dat Sat Jan 3 18:22:40 2009 @@ -841,9 +841,6 @@ PyNumber_Xor:PyObject*:o1:0: PyNumber_Xor:PyObject*:o2:0: -PyOS_GetLastModificationTime:long::: -PyOS_GetLastModificationTime:char*:filename:: - PyObject_AsFileDescriptor:int::: PyObject_AsFileDescriptor:PyObject*:o:0: Modified: python/branches/py3k/Makefile.pre.in ============================================================================== --- python/branches/py3k/Makefile.pre.in (original) +++ python/branches/py3k/Makefile.pre.in Sat Jan 3 18:22:40 2009 @@ -263,7 +263,6 @@ Python/getargs.o \ Python/getcompiler.o \ Python/getcopyright.o \ - Python/getmtime.o \ Python/getplatform.o \ Python/getversion.o \ Python/graminit.o \ Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Jan 3 18:22:40 2009 @@ -12,6 +12,8 @@ Core and Builtins ----------------- +- Issue #4817: Remove unused function PyOS_GetLastModificationTime. + - Issue #4580: Fix slicing of memoryviews when the item size is greater than one byte. Also fixes the meaning of len() so that it returns the number of items, rather than the size in bytes. Modified: python/branches/py3k/PC/VC6/pythoncore.dsp ============================================================================== --- python/branches/py3k/PC/VC6/pythoncore.dsp (original) +++ python/branches/py3k/PC/VC6/pythoncore.dsp Sat Jan 3 18:22:40 2009 @@ -402,10 +402,6 @@ # End Source File # Begin Source File -SOURCE=..\..\Python\getmtime.c -# End Source File -# Begin Source File - SOURCE=..\..\Python\getopt.c # End Source File # Begin Source File Modified: python/branches/py3k/PC/VS7.1/pythoncore.vcproj ============================================================================== --- python/branches/py3k/PC/VS7.1/pythoncore.vcproj (original) +++ python/branches/py3k/PC/VS7.1/pythoncore.vcproj Sat Jan 3 18:22:40 2009 @@ -557,9 +557,6 @@ RelativePath="..\..\Python\getcopyright.c"> - - - - Modified: python/branches/py3k/PC/os2emx/Makefile ============================================================================== --- python/branches/py3k/PC/os2emx/Makefile (original) +++ python/branches/py3k/PC/os2emx/Makefile Sat Jan 3 18:22:40 2009 @@ -339,7 +339,6 @@ Python/getargs.c \ Python/getcompiler.c \ Python/getcopyright.c \ - Python/getmtime.c \ Python/getplatform.c \ Python/getversion.c \ Python/graminit.c \ Modified: python/branches/py3k/PC/os2emx/python27.def ============================================================================== --- python/branches/py3k/PC/os2emx/python27.def (original) +++ python/branches/py3k/PC/os2emx/python27.def Sat Jan 3 18:22:40 2009 @@ -930,9 +930,6 @@ ; From python26_s.lib(getcopyright) "Py_GetCopyright" -; From python26_s.lib(getmtime) - "PyOS_GetLastModificationTime" - ; From python26_s.lib(getplatform) "Py_GetPlatform" Modified: python/branches/py3k/PC/os2vacpp/makefile ============================================================================== --- python/branches/py3k/PC/os2vacpp/makefile (original) +++ python/branches/py3k/PC/os2vacpp/makefile Sat Jan 3 18:22:40 2009 @@ -1377,8 +1377,6 @@ $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ $(PY_INCLUDE)\tupleobject.h -getmtime.obj: pyconfig.h - getplatform.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \ pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \ Modified: python/branches/py3k/PC/os2vacpp/makefile.omk ============================================================================== --- python/branches/py3k/PC/os2vacpp/makefile.omk (original) +++ python/branches/py3k/PC/os2vacpp/makefile.omk Sat Jan 3 18:22:40 2009 @@ -939,8 +939,6 @@ pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \ stringobject.h sysmodule.h traceback.h tupleobject.h -getmtime.obj: pyconfig.h - getplatform.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \ import.h intobject.h intrcheck.h listobject.h longobject.h \ Modified: python/branches/py3k/PC/os2vacpp/python.def ============================================================================== --- python/branches/py3k/PC/os2vacpp/python.def (original) +++ python/branches/py3k/PC/os2vacpp/python.def Sat Jan 3 18:22:40 2009 @@ -280,7 +280,6 @@ PyNumber_Xor PyOS_AfterFork PyOS_FiniInterrupts - PyOS_GetLastModificationTime PyOS_InitInterrupts PyOS_InterruptOccurred PyOS_Readline Modified: python/branches/py3k/PCbuild/pythoncore.vcproj ============================================================================== --- python/branches/py3k/PCbuild/pythoncore.vcproj (original) +++ python/branches/py3k/PCbuild/pythoncore.vcproj Sat Jan 3 18:22:40 2009 @@ -1651,10 +1651,6 @@ > - - Deleted: python/branches/py3k/Python/getmtime.c ============================================================================== --- python/branches/py3k/Python/getmtime.c Sat Jan 3 18:22:40 2009 +++ (empty file) @@ -1,26 +0,0 @@ - -/* Subroutine to get the last modification time of a file */ - -/* (A separate file because this may be OS dependent) */ - -#include "Python.h" -#include "pyconfig.h" - -#ifdef __cplusplus -extern "C" { -#endif - -time_t -PyOS_GetLastModificationTime(char *path, FILE *fp) -{ - struct stat st; - if (fstat(fileno(fp), &st) != 0) - return -1; - else - return st.st_mtime; -} - -#ifdef __cplusplus -} -#endif - Modified: python/branches/py3k/Python/import.c ============================================================================== --- python/branches/py3k/Python/import.c (original) +++ python/branches/py3k/Python/import.c Sat Jan 3 18:22:40 2009 @@ -27,8 +27,6 @@ typedef unsigned short mode_t; #endif -extern time_t PyOS_GetLastModificationTime(char *, FILE *); - /* In getmtime.c */ /* Magic word to reject .pyc files generated by other Python versions. It should change for each incompatible change to the bytecode. From buildbot at python.org Sat Jan 3 18:24:24 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 17:24:24 +0000 Subject: [Python-checkins] buildbot failure in sparc Debian 3.x Message-ID: <20090103172425.2A8541E4002@bag.python.org> The Buildbot has detected a new failure of sparc Debian 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20Debian%203.x/builds/34 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-sparc Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: mark.dickinson BUILD FAILED: failed test Excerpt from the test logfile: sincerely, -The Buildbot From buildbot at python.org Sat Jan 3 19:07:38 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 18:07:38 +0000 Subject: [Python-checkins] buildbot failure in ppc Debian unstable 2.6 Message-ID: <20090103180738.611F61E4002@bag.python.org> The Buildbot has detected a new failure of ppc Debian unstable 2.6. Full details are available at: http://www.python.org/dev/buildbot/all/ppc%20Debian%20unstable%202.6/builds/27 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-debian-ppc Build Reason: Build Source Stamp: [branch branches/release26-maint] HEAD Blamelist: benjamin.peterson BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_bsddb3 make: *** [buildbottest] Error 1 sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 19:41:50 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 19:41:50 +0100 (CET) Subject: [Python-checkins] r68205 - in python/branches/py3k: Doc/library/wsgiref.rst Lib/test/test_wsgiref.py Lib/wsgiref/handlers.py Lib/wsgiref/headers.py Lib/wsgiref/simple_server.py Lib/wsgiref/util.py Lib/wsgiref/validate.py Misc/NEWS Message-ID: <20090103184150.1D2C61E4002@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 19:41:49 2009 New Revision: 68205 Log: Issue #4718: Adapt the wsgiref package so that it actually works with Python 3.x, in accordance with http://www.wsgi.org/wsgi/Amendments_1.0 Modified: python/branches/py3k/Doc/library/wsgiref.rst python/branches/py3k/Lib/test/test_wsgiref.py python/branches/py3k/Lib/wsgiref/handlers.py python/branches/py3k/Lib/wsgiref/headers.py python/branches/py3k/Lib/wsgiref/simple_server.py python/branches/py3k/Lib/wsgiref/util.py python/branches/py3k/Lib/wsgiref/validate.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Doc/library/wsgiref.rst ============================================================================== --- python/branches/py3k/Doc/library/wsgiref.rst (original) +++ python/branches/py3k/Doc/library/wsgiref.rst Sat Jan 3 19:41:49 2009 @@ -122,13 +122,13 @@ def simple_app(environ, start_response): setup_testing_defaults(environ) - status = '200 OK' - headers = [('Content-type', 'text/plain')] + status = b'200 OK' + headers = [(b'Content-type', b'text/plain; charset=utf-8')] start_response(status, headers) - ret = ["%s: %s\n" % (key, value) - for key, value in environ.iteritems()] + ret = [("%s: %s\n" % (key, value)).encode("utf-8") + for key, value in environ.items()] return ret httpd = make_server('', 8000, simple_app) @@ -161,7 +161,7 @@ Example usage:: - from StringIO import StringIO + from io import StringIO from wsgiref.util import FileWrapper # We're using a StringIO-buffer for as the file-like object @@ -416,13 +416,13 @@ # Our callable object which is intentionally not compliant to the # standard, so the validator is going to break def simple_app(environ, start_response): - status = '200 OK' # HTTP Status - headers = [('Content-type', 'text/plain')] # HTTP Headers + status = b'200 OK' # HTTP Status + headers = [(b'Content-type', b'text/plain')] # HTTP Headers start_response(status, headers) # This is going to break because we need to return a list, and # the validator is going to inform us - return "Hello World" + return b"Hello World" # This is the application wrapped in a validator validator_app = validator(simple_app) @@ -509,7 +509,7 @@ .. method:: BaseHandler._write(data) - Buffer the string *data* for transmission to the client. It's okay if this + Buffer the bytes *data* for transmission to the client. It's okay if this method actually transmits the data; :class:`BaseHandler` just separates write and flush operations for greater efficiency when the underlying system actually has such a distinction. @@ -712,12 +712,12 @@ # is a dictionary containing CGI-style envrironment variables and the # second variable is the callable object (see PEP333) def hello_world_app(environ, start_response): - status = '200 OK' # HTTP Status - headers = [('Content-type', 'text/plain')] # HTTP Headers + status = b'200 OK' # HTTP Status + headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers start_response(status, headers) # The returned object is going to be printed - return ["Hello World"] + return [b"Hello World"] httpd = make_server('', 8000, hello_world_app) print("Serving on port 8000...") Modified: python/branches/py3k/Lib/test/test_wsgiref.py ============================================================================== --- python/branches/py3k/Lib/test/test_wsgiref.py (original) +++ python/branches/py3k/Lib/test/test_wsgiref.py Sat Jan 3 19:41:49 2009 @@ -50,7 +50,7 @@ def run_amock(app=hello_app, data=b"GET / HTTP/1.0\n\n"): server = make_server("", 80, app, MockServer, MockHandler) inp = BufferedReader(BytesIO(data)) - out = StringIO() + out = BytesIO() olderr = sys.stderr err = sys.stderr = StringIO() @@ -128,13 +128,13 @@ def check_hello(self, out, has_length=True): self.assertEqual(out, - "HTTP/1.0 200 OK\r\n" + ("HTTP/1.0 200 OK\r\n" "Server: WSGIServer/0.1 Python/"+sys.version.split()[0]+"\r\n" "Content-Type: text/plain\r\n" "Date: Mon, 05 Jun 2006 18:49:54 GMT\r\n" + (has_length and "Content-Length: 13\r\n" or "") + "\r\n" - "Hello, world!" + "Hello, world!").encode("iso-8859-1") ) def test_plain_hello(self): @@ -152,7 +152,7 @@ return ["Hello, world!"] out, err = run_amock(validator(bad_app)) self.failUnless(out.endswith( - "A server error occurred. Please contact the administrator." + b"A server error occurred. Please contact the administrator." )) self.assertEqual( err.splitlines()[-2], @@ -160,7 +160,36 @@ " be of type list: " ) + def test_wsgi_input(self): + def bad_app(e,s): + e["wsgi.input"].read() + s(b"200 OK", [(b"Content-Type", b"text/plain; charset=utf-8")]) + return [b"data"] + out, err = run_amock(validator(bad_app)) + self.failUnless(out.endswith( + b"A server error occurred. Please contact the administrator." + )) + self.assertEqual( + err.splitlines()[-2], "AssertionError" + ) + def test_bytes_validation(self): + def app(e, s): + s(b"200 OK", [ + (b"Content-Type", b"text/plain; charset=utf-8"), + ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), + ]) + return [b"data"] + out, err = run_amock(validator(app)) + self.failUnless(err.endswith('"GET / HTTP/1.0" 200 4\n')) + self.assertEqual( + b"HTTP/1.0 200 OK\r\n" + b"Server: WSGIServer/0.1 Python/3.1a0\r\n" + b"Content-Type: text/plain; charset=utf-8\r\n" + b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n" + b"\r\n" + b"data", + out) @@ -181,6 +210,8 @@ util.setup_testing_defaults(env) if isinstance(value,StringIO): self.failUnless(isinstance(env[key],StringIO)) + elif isinstance(value,BytesIO): + self.failUnless(isinstance(env[key],BytesIO)) else: self.assertEqual(env[key],value) @@ -260,7 +291,7 @@ ('wsgi.run_once', 0), ('wsgi.multithread', 0), ('wsgi.multiprocess', 0), - ('wsgi.input', StringIO("")), + ('wsgi.input', BytesIO()), ('wsgi.errors', StringIO()), ('wsgi.url_scheme','http'), ]: @@ -386,6 +417,23 @@ '\r\n' ) + def testBytes(self): + h = Headers([ + (b"Content-Type", b"text/plain; charset=utf-8"), + ]) + self.assertEqual("text/plain; charset=utf-8", h.get("Content-Type")) + + h[b"Foo"] = bytes(b"bar") + self.assertEqual("bar", h.get("Foo")) + + h.setdefault(b"Bar", b"foo") + self.assertEqual("foo", h.get("Bar")) + + h.add_header(b'content-disposition', b'attachment', + filename=b'bud.gif') + self.assertEqual('attachment; filename="bud.gif"', + h.get("content-disposition")) + class ErrorHandler(BaseCGIHandler): """Simple handler subclass for testing BaseHandler""" @@ -393,7 +441,7 @@ def __init__(self,**kw): setup_testing_defaults(kw) BaseCGIHandler.__init__( - self, StringIO(''), StringIO(), StringIO(), kw, + self, BytesIO(), BytesIO(), StringIO(), kw, multithread=True, multiprocess=True ) @@ -474,21 +522,32 @@ s('200 OK',[])(e['wsgi.url_scheme']) return [] + def trivial_app3(e,s): + s('200 OK',[]) + return ['\u0442\u0435\u0441\u0442'.encode("utf-8")] + h = TestHandler() h.run(trivial_app1) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" + ("Status: 200 OK\r\n" "Content-Length: 4\r\n" "\r\n" - "http") + "http").encode("iso-8859-1")) h = TestHandler() h.run(trivial_app2) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" + ("Status: 200 OK\r\n" "\r\n" - "http") + "http").encode("iso-8859-1")) + h = TestHandler() + h.run(trivial_app3) + self.assertEqual(h.stdout.getvalue(), + b'Status: 200 OK\r\n' + b'Content-Length: 8\r\n' + b'\r\n' + b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82') @@ -507,18 +566,19 @@ h = ErrorHandler() h.run(non_error_app) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" + ("Status: 200 OK\r\n" "Content-Length: 0\r\n" - "\r\n") + "\r\n").encode("iso-8859-1")) self.assertEqual(h.stderr.getvalue(),"") h = ErrorHandler() h.run(error_app) self.assertEqual(h.stdout.getvalue(), - "Status: %s\r\n" + ("Status: %s\r\n" "Content-Type: text/plain\r\n" "Content-Length: %d\r\n" - "\r\n%s" % (h.error_status,len(h.error_body),h.error_body)) + "\r\n%s" % (h.error_status,len(h.error_body),h.error_body) + ).encode("iso-8859-1")) self.failUnless("AssertionError" in h.stderr.getvalue()) @@ -531,8 +591,8 @@ h = ErrorHandler() h.run(error_app) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" - "\r\n"+MSG) + ("Status: 200 OK\r\n" + "\r\n"+MSG).encode("iso-8859-1")) self.failUnless("AssertionError" in h.stderr.getvalue()) @@ -549,7 +609,7 @@ ) shortpat = ( "Status: 200 OK\r\n" "Content-Length: 0\r\n" "\r\n" - ) + ).encode("iso-8859-1") for ssw in "FooBar/1.0", None: sw = ssw and "Server: %s\r\n" % ssw or "" @@ -570,13 +630,31 @@ h.server_software = ssw h.run(non_error_app) if proto=="HTTP/0.9": - self.assertEqual(h.stdout.getvalue(),"") + self.assertEqual(h.stdout.getvalue(),b"") else: self.failUnless( - re.match(stdpat%(version,sw), h.stdout.getvalue()), - (stdpat%(version,sw), h.stdout.getvalue()) + re.match((stdpat%(version,sw)).encode("iso-8859-1"), + h.stdout.getvalue()), + ((stdpat%(version,sw)).encode("iso-8859-1"), + h.stdout.getvalue()) ) + def testBytesData(self): + def app(e, s): + s(b"200 OK", [ + (b"Content-Type", b"text/plain; charset=utf-8"), + ]) + return [b"data"] + + h = TestHandler() + h.run(app) + self.assertEqual(b"Status: 200 OK\r\n" + b"Content-Type: text/plain; charset=utf-8\r\n" + b"Content-Length: 4\r\n" + b"\r\n" + b"data", + h.stdout.getvalue()) + # This epilogue is needed for compatibility with the Python 2.5 regrtest module def test_main(): Modified: python/branches/py3k/Lib/wsgiref/handlers.py ============================================================================== --- python/branches/py3k/Lib/wsgiref/handlers.py (original) +++ python/branches/py3k/Lib/wsgiref/handlers.py Sat Jan 3 19:41:49 2009 @@ -157,19 +157,29 @@ elif self.headers is not None: raise AssertionError("Headers already set!") - assert type(status) is str,"Status must be a string" + status = self._convert_string_type(status, "Status") assert len(status)>=4,"Status must be at least 4 characters" assert int(status[:3]),"Status message must begin w/3-digit code" assert status[3]==" ", "Status message must have a space after code" - if __debug__: - for name,val in headers: - assert type(name) is str,"Header names must be strings" - assert type(val) is str,"Header values must be strings" - assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed" + + str_headers = [] + for name,val in headers: + name = self._convert_string_type(name, "Header name") + val = self._convert_string_type(val, "Header value") + str_headers.append((name, val)) + assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed" + self.status = status - self.headers = self.headers_class(headers) + self.headers = self.headers_class(str_headers) return self.write + def _convert_string_type(self, value, title): + """Convert/check value type.""" + if isinstance(value, str): + return value + assert isinstance(value, bytes), \ + "{0} must be a string or bytes object (not {1})".format(title, value) + return str(value, "iso-8859-1") def send_preamble(self): """Transmit version/status/date/server, via self._write()""" @@ -188,7 +198,8 @@ def write(self, data): """'write()' callable as specified by PEP 333""" - assert type(data) is str,"write() argument must be string" + assert isinstance(data, (str, bytes)), \ + "write() argument must be a string or bytes" if not self.status: raise AssertionError("write() before start_response()") @@ -382,8 +393,13 @@ self.environ.update(self.base_env) def _write(self,data): + if isinstance(data, str): + try: + data = data.encode("iso-8859-1") + except UnicodeEncodeError: + raise ValueError("Unicode data must contain only code points" + " representable in ISO-8859-1 encoding") self.stdout.write(data) - self._write = self.stdout.write def _flush(self): self.stdout.flush() Modified: python/branches/py3k/Lib/wsgiref/headers.py ============================================================================== --- python/branches/py3k/Lib/wsgiref/headers.py (original) +++ python/branches/py3k/Lib/wsgiref/headers.py Sat Jan 3 19:41:49 2009 @@ -44,7 +44,19 @@ def __init__(self,headers): if not isinstance(headers, list): raise TypeError("Headers must be a list of name/value tuples") - self._headers = headers + self._headers = [] + for k, v in headers: + k = self._convert_string_type(k) + v = self._convert_string_type(v) + self._headers.append((k, v)) + + def _convert_string_type(self, value): + """Convert/check value type.""" + if isinstance(value, str): + return value + assert isinstance(value, bytes), ("Header names/values must be" + " a string or bytes object (not {0})".format(value)) + return str(value, "iso-8859-1") def __len__(self): """Return the total number of headers, including duplicates.""" @@ -53,7 +65,8 @@ def __setitem__(self, name, val): """Set the value of a header.""" del self[name] - self._headers.append((name, val)) + self._headers.append( + (self._convert_string_type(name), self._convert_string_type(val))) def __delitem__(self,name): """Delete all occurrences of a header, if present. @@ -152,7 +165,8 @@ and value 'value'.""" result = self.get(name) if result is None: - self._headers.append((name,value)) + self._headers.append((self._convert_string_type(name), + self._convert_string_type(value))) return value else: return result @@ -176,13 +190,16 @@ """ parts = [] if _value is not None: + _value = self._convert_string_type(_value) parts.append(_value) for k, v in _params.items(): + k = self._convert_string_type(k) if v is None: parts.append(k.replace('_', '-')) else: + v = self._convert_string_type(v) parts.append(_formatparam(k.replace('_', '-'), v)) - self._headers.append((_name, "; ".join(parts))) + self._headers.append((self._convert_string_type(_name), "; ".join(parts))) Modified: python/branches/py3k/Lib/wsgiref/simple_server.py ============================================================================== --- python/branches/py3k/Lib/wsgiref/simple_server.py (original) +++ python/branches/py3k/Lib/wsgiref/simple_server.py Sat Jan 3 19:41:49 2009 @@ -111,8 +111,7 @@ if length: env['CONTENT_LENGTH'] = length - for h in self.headers: - k,v = h.split(':',1) + for k, v in self.headers.items(): k=k.replace('-','_').upper(); v=v.strip() if k in env: continue # skip content length, type,etc. @@ -168,11 +167,11 @@ stdout = StringIO() print("Hello world!", file=stdout) print(file=stdout) - h = environ.items(); h.sort() + h = sorted(environ.items()) for k,v in h: print(k,'=',repr(v), file=stdout) - start_response("200 OK", [('Content-Type','text/plain')]) - return [stdout.getvalue()] + start_response(b"200 OK", [(b'Content-Type',b'text/plain; charset=utf-8')]) + return [stdout.getvalue().encode("utf-8")] def make_server( Modified: python/branches/py3k/Lib/wsgiref/util.py ============================================================================== --- python/branches/py3k/Lib/wsgiref/util.py (original) +++ python/branches/py3k/Lib/wsgiref/util.py Sat Jan 3 19:41:49 2009 @@ -149,8 +149,8 @@ environ.setdefault('wsgi.multithread', 0) environ.setdefault('wsgi.multiprocess', 0) - from io import StringIO - environ.setdefault('wsgi.input', StringIO("")) + from io import StringIO, BytesIO + environ.setdefault('wsgi.input', BytesIO()) environ.setdefault('wsgi.errors', StringIO()) environ.setdefault('wsgi.url_scheme',guess_scheme(environ)) Modified: python/branches/py3k/Lib/wsgiref/validate.py ============================================================================== --- python/branches/py3k/Lib/wsgiref/validate.py (original) +++ python/branches/py3k/Lib/wsgiref/validate.py Sat Jan 3 19:41:49 2009 @@ -127,6 +127,13 @@ if not cond: raise AssertionError(*args) +def check_string_type(value, title): + if isinstance(value, str): + return value + assert isinstance(value, bytes), \ + "{0} must be a string or bytes object (not {1})".format(title, value) + return str(value, "iso-8859-1") + def validator(application): """ @@ -188,14 +195,14 @@ self.input = wsgi_input def read(self, *args): - assert_(len(args) <= 1) + assert_(len(args) == 1) v = self.input.read(*args) - assert_(isinstance(v, str)) + assert_(isinstance(v, bytes)) return v def readline(self): v = self.input.readline() - assert_(isinstance(v, str)) + assert_(isinstance(v, bytes)) return v def readlines(self, *args): @@ -203,7 +210,7 @@ lines = self.input.readlines(*args) assert_(isinstance(lines, list)) for line in lines: - assert_(isinstance(line, str)) + assert_(isinstance(line, bytes)) return lines def __iter__(self): @@ -241,7 +248,7 @@ self.writer = wsgi_writer def __call__(self, s): - assert_(isinstance(s, str)) + assert_(isinstance(s, (str, bytes))) self.writer(s) class PartialIteratorWrapper: @@ -364,8 +371,7 @@ % (wsgi_errors, attr)) def check_status(status): - assert_(isinstance(status, str), - "Status must be a string (not %r)" % status) + status = check_string_type(status, "Status") # Implicitly check that we can turn it into an integer: status_code = status.split(None, 1)[0] assert_(len(status_code) == 3, @@ -389,6 +395,8 @@ % (item, type(item))) assert_(len(item) == 2) name, value = item + name = check_string_type(name, "Header name") + value = check_string_type(value, "Header value") assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " @@ -404,11 +412,13 @@ % (value, bad_header_value_re.search(value).group(0))) def check_content_type(status, headers): + status = check_string_type(status, "Status") code = int(status.split(None, 1)[0]) # @@: need one more person to verify this interpretation of RFC 2616 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html NO_MESSAGE_BODY = (204, 304) for name, value in headers: + name = check_string_type(name, "Header name") if name.lower() == 'content-type': if code not in NO_MESSAGE_BODY: return @@ -426,6 +436,6 @@ # Technically a string is legal, which is why it's a really bad # idea, because it may cause the response to be returned # character-by-character - assert_(not isinstance(iterator, str), + assert_(not isinstance(iterator, (str, bytes)), "You should not return a string as your application iterator, " "instead return a single-item list containing that string.") Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Jan 3 19:41:49 2009 @@ -84,6 +84,10 @@ Library ------- +- Issue #4718: Adapt the wsgiref package so that it actually works with + Python 3.x, in accordance with the `official amendments of the spec + `_. + - Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) From python-checkins at python.org Sat Jan 3 19:49:42 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 19:49:42 +0100 (CET) Subject: [Python-checkins] r68206 - python/branches/py3k/Lib/test/test_wsgiref.py Message-ID: <20090103184942.0E0951E4002@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 19:49:41 2009 New Revision: 68206 Log: Actually make test_wsgiref independent from the Python version. Modified: python/branches/py3k/Lib/test/test_wsgiref.py Modified: python/branches/py3k/Lib/test/test_wsgiref.py ============================================================================== --- python/branches/py3k/Lib/test/test_wsgiref.py (original) +++ python/branches/py3k/Lib/test/test_wsgiref.py Sat Jan 3 19:49:41 2009 @@ -182,9 +182,10 @@ return [b"data"] out, err = run_amock(validator(app)) self.failUnless(err.endswith('"GET / HTTP/1.0" 200 4\n')) + ver = sys.version.split()[0].encode('ascii') self.assertEqual( b"HTTP/1.0 200 OK\r\n" - b"Server: WSGIServer/0.1 Python/3.1a0\r\n" + b"Server: WSGIServer/0.1 Python/" + ver + b"\r\n" b"Content-Type: text/plain; charset=utf-8\r\n" b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n" b"\r\n" From python-checkins at python.org Sat Jan 3 19:57:08 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 19:57:08 +0100 (CET) Subject: [Python-checkins] r68207 - in python/branches/release30-maint: Doc/library/wsgiref.rst Lib/test/test_wsgiref.py Lib/wsgiref/handlers.py Lib/wsgiref/headers.py Lib/wsgiref/simple_server.py Lib/wsgiref/util.py Lib/wsgiref/validate.py Misc/NEWS Message-ID: <20090103185708.EA9901E4002@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 19:57:08 2009 New Revision: 68207 Log: Merged revisions 68205-68206 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ........ r68205 | antoine.pitrou | 2009-01-03 19:41:49 +0100 (sam., 03 janv. 2009) | 4 lines Issue #4718: Adapt the wsgiref package so that it actually works with Python 3.x, in accordance with http://www.wsgi.org/wsgi/Amendments_1.0 ........ r68206 | antoine.pitrou | 2009-01-03 19:49:41 +0100 (sam., 03 janv. 2009) | 3 lines Actually make test_wsgiref independent from the Python version. ........ Modified: python/branches/release30-maint/ (props changed) python/branches/release30-maint/Doc/library/wsgiref.rst python/branches/release30-maint/Lib/test/test_wsgiref.py python/branches/release30-maint/Lib/wsgiref/handlers.py python/branches/release30-maint/Lib/wsgiref/headers.py python/branches/release30-maint/Lib/wsgiref/simple_server.py python/branches/release30-maint/Lib/wsgiref/util.py python/branches/release30-maint/Lib/wsgiref/validate.py python/branches/release30-maint/Misc/NEWS Modified: python/branches/release30-maint/Doc/library/wsgiref.rst ============================================================================== --- python/branches/release30-maint/Doc/library/wsgiref.rst (original) +++ python/branches/release30-maint/Doc/library/wsgiref.rst Sat Jan 3 19:57:08 2009 @@ -122,13 +122,13 @@ def simple_app(environ, start_response): setup_testing_defaults(environ) - status = '200 OK' - headers = [('Content-type', 'text/plain')] + status = b'200 OK' + headers = [(b'Content-type', b'text/plain; charset=utf-8')] start_response(status, headers) - ret = ["%s: %s\n" % (key, value) - for key, value in environ.iteritems()] + ret = [("%s: %s\n" % (key, value)).encode("utf-8") + for key, value in environ.items()] return ret httpd = make_server('', 8000, simple_app) @@ -161,7 +161,7 @@ Example usage:: - from StringIO import StringIO + from io import StringIO from wsgiref.util import FileWrapper # We're using a StringIO-buffer for as the file-like object @@ -416,13 +416,13 @@ # Our callable object which is intentionally not compliant to the # standard, so the validator is going to break def simple_app(environ, start_response): - status = '200 OK' # HTTP Status - headers = [('Content-type', 'text/plain')] # HTTP Headers + status = b'200 OK' # HTTP Status + headers = [(b'Content-type', b'text/plain')] # HTTP Headers start_response(status, headers) # This is going to break because we need to return a list, and # the validator is going to inform us - return "Hello World" + return b"Hello World" # This is the application wrapped in a validator validator_app = validator(simple_app) @@ -509,7 +509,7 @@ .. method:: BaseHandler._write(data) - Buffer the string *data* for transmission to the client. It's okay if this + Buffer the bytes *data* for transmission to the client. It's okay if this method actually transmits the data; :class:`BaseHandler` just separates write and flush operations for greater efficiency when the underlying system actually has such a distinction. @@ -712,12 +712,12 @@ # is a dictionary containing CGI-style envrironment variables and the # second variable is the callable object (see PEP333) def hello_world_app(environ, start_response): - status = '200 OK' # HTTP Status - headers = [('Content-type', 'text/plain')] # HTTP Headers + status = b'200 OK' # HTTP Status + headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers start_response(status, headers) # The returned object is going to be printed - return ["Hello World"] + return [b"Hello World"] httpd = make_server('', 8000, hello_world_app) print("Serving on port 8000...") Modified: python/branches/release30-maint/Lib/test/test_wsgiref.py ============================================================================== --- python/branches/release30-maint/Lib/test/test_wsgiref.py (original) +++ python/branches/release30-maint/Lib/test/test_wsgiref.py Sat Jan 3 19:57:08 2009 @@ -50,7 +50,7 @@ def run_amock(app=hello_app, data=b"GET / HTTP/1.0\n\n"): server = make_server("", 80, app, MockServer, MockHandler) inp = BufferedReader(BytesIO(data)) - out = StringIO() + out = BytesIO() olderr = sys.stderr err = sys.stderr = StringIO() @@ -128,13 +128,13 @@ def check_hello(self, out, has_length=True): self.assertEqual(out, - "HTTP/1.0 200 OK\r\n" + ("HTTP/1.0 200 OK\r\n" "Server: WSGIServer/0.1 Python/"+sys.version.split()[0]+"\r\n" "Content-Type: text/plain\r\n" "Date: Mon, 05 Jun 2006 18:49:54 GMT\r\n" + (has_length and "Content-Length: 13\r\n" or "") + "\r\n" - "Hello, world!" + "Hello, world!").encode("iso-8859-1") ) def test_plain_hello(self): @@ -152,7 +152,7 @@ return ["Hello, world!"] out, err = run_amock(validator(bad_app)) self.failUnless(out.endswith( - "A server error occurred. Please contact the administrator." + b"A server error occurred. Please contact the administrator." )) self.assertEqual( err.splitlines()[-2], @@ -160,7 +160,37 @@ " be of type list: " ) + def test_wsgi_input(self): + def bad_app(e,s): + e["wsgi.input"].read() + s(b"200 OK", [(b"Content-Type", b"text/plain; charset=utf-8")]) + return [b"data"] + out, err = run_amock(validator(bad_app)) + self.failUnless(out.endswith( + b"A server error occurred. Please contact the administrator." + )) + self.assertEqual( + err.splitlines()[-2], "AssertionError" + ) + def test_bytes_validation(self): + def app(e, s): + s(b"200 OK", [ + (b"Content-Type", b"text/plain; charset=utf-8"), + ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), + ]) + return [b"data"] + out, err = run_amock(validator(app)) + self.failUnless(err.endswith('"GET / HTTP/1.0" 200 4\n')) + ver = sys.version.split()[0].encode('ascii') + self.assertEqual( + b"HTTP/1.0 200 OK\r\n" + b"Server: WSGIServer/0.1 Python/" + ver + b"\r\n" + b"Content-Type: text/plain; charset=utf-8\r\n" + b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n" + b"\r\n" + b"data", + out) @@ -181,6 +211,8 @@ util.setup_testing_defaults(env) if isinstance(value,StringIO): self.failUnless(isinstance(env[key],StringIO)) + elif isinstance(value,BytesIO): + self.failUnless(isinstance(env[key],BytesIO)) else: self.assertEqual(env[key],value) @@ -260,7 +292,7 @@ ('wsgi.run_once', 0), ('wsgi.multithread', 0), ('wsgi.multiprocess', 0), - ('wsgi.input', StringIO("")), + ('wsgi.input', BytesIO()), ('wsgi.errors', StringIO()), ('wsgi.url_scheme','http'), ]: @@ -386,6 +418,23 @@ '\r\n' ) + def testBytes(self): + h = Headers([ + (b"Content-Type", b"text/plain; charset=utf-8"), + ]) + self.assertEqual("text/plain; charset=utf-8", h.get("Content-Type")) + + h[b"Foo"] = bytes(b"bar") + self.assertEqual("bar", h.get("Foo")) + + h.setdefault(b"Bar", b"foo") + self.assertEqual("foo", h.get("Bar")) + + h.add_header(b'content-disposition', b'attachment', + filename=b'bud.gif') + self.assertEqual('attachment; filename="bud.gif"', + h.get("content-disposition")) + class ErrorHandler(BaseCGIHandler): """Simple handler subclass for testing BaseHandler""" @@ -393,7 +442,7 @@ def __init__(self,**kw): setup_testing_defaults(kw) BaseCGIHandler.__init__( - self, StringIO(''), StringIO(), StringIO(), kw, + self, BytesIO(), BytesIO(), StringIO(), kw, multithread=True, multiprocess=True ) @@ -474,21 +523,32 @@ s('200 OK',[])(e['wsgi.url_scheme']) return [] + def trivial_app3(e,s): + s('200 OK',[]) + return ['\u0442\u0435\u0441\u0442'.encode("utf-8")] + h = TestHandler() h.run(trivial_app1) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" + ("Status: 200 OK\r\n" "Content-Length: 4\r\n" "\r\n" - "http") + "http").encode("iso-8859-1")) h = TestHandler() h.run(trivial_app2) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" + ("Status: 200 OK\r\n" "\r\n" - "http") + "http").encode("iso-8859-1")) + h = TestHandler() + h.run(trivial_app3) + self.assertEqual(h.stdout.getvalue(), + b'Status: 200 OK\r\n' + b'Content-Length: 8\r\n' + b'\r\n' + b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82') @@ -507,18 +567,19 @@ h = ErrorHandler() h.run(non_error_app) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" + ("Status: 200 OK\r\n" "Content-Length: 0\r\n" - "\r\n") + "\r\n").encode("iso-8859-1")) self.assertEqual(h.stderr.getvalue(),"") h = ErrorHandler() h.run(error_app) self.assertEqual(h.stdout.getvalue(), - "Status: %s\r\n" + ("Status: %s\r\n" "Content-Type: text/plain\r\n" "Content-Length: %d\r\n" - "\r\n%s" % (h.error_status,len(h.error_body),h.error_body)) + "\r\n%s" % (h.error_status,len(h.error_body),h.error_body) + ).encode("iso-8859-1")) self.failUnless("AssertionError" in h.stderr.getvalue()) @@ -531,8 +592,8 @@ h = ErrorHandler() h.run(error_app) self.assertEqual(h.stdout.getvalue(), - "Status: 200 OK\r\n" - "\r\n"+MSG) + ("Status: 200 OK\r\n" + "\r\n"+MSG).encode("iso-8859-1")) self.failUnless("AssertionError" in h.stderr.getvalue()) @@ -549,7 +610,7 @@ ) shortpat = ( "Status: 200 OK\r\n" "Content-Length: 0\r\n" "\r\n" - ) + ).encode("iso-8859-1") for ssw in "FooBar/1.0", None: sw = ssw and "Server: %s\r\n" % ssw or "" @@ -570,13 +631,31 @@ h.server_software = ssw h.run(non_error_app) if proto=="HTTP/0.9": - self.assertEqual(h.stdout.getvalue(),"") + self.assertEqual(h.stdout.getvalue(),b"") else: self.failUnless( - re.match(stdpat%(version,sw), h.stdout.getvalue()), - (stdpat%(version,sw), h.stdout.getvalue()) + re.match((stdpat%(version,sw)).encode("iso-8859-1"), + h.stdout.getvalue()), + ((stdpat%(version,sw)).encode("iso-8859-1"), + h.stdout.getvalue()) ) + def testBytesData(self): + def app(e, s): + s(b"200 OK", [ + (b"Content-Type", b"text/plain; charset=utf-8"), + ]) + return [b"data"] + + h = TestHandler() + h.run(app) + self.assertEqual(b"Status: 200 OK\r\n" + b"Content-Type: text/plain; charset=utf-8\r\n" + b"Content-Length: 4\r\n" + b"\r\n" + b"data", + h.stdout.getvalue()) + # This epilogue is needed for compatibility with the Python 2.5 regrtest module def test_main(): Modified: python/branches/release30-maint/Lib/wsgiref/handlers.py ============================================================================== --- python/branches/release30-maint/Lib/wsgiref/handlers.py (original) +++ python/branches/release30-maint/Lib/wsgiref/handlers.py Sat Jan 3 19:57:08 2009 @@ -157,19 +157,29 @@ elif self.headers is not None: raise AssertionError("Headers already set!") - assert type(status) is str,"Status must be a string" + status = self._convert_string_type(status, "Status") assert len(status)>=4,"Status must be at least 4 characters" assert int(status[:3]),"Status message must begin w/3-digit code" assert status[3]==" ", "Status message must have a space after code" - if __debug__: - for name,val in headers: - assert type(name) is str,"Header names must be strings" - assert type(val) is str,"Header values must be strings" - assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed" + + str_headers = [] + for name,val in headers: + name = self._convert_string_type(name, "Header name") + val = self._convert_string_type(val, "Header value") + str_headers.append((name, val)) + assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed" + self.status = status - self.headers = self.headers_class(headers) + self.headers = self.headers_class(str_headers) return self.write + def _convert_string_type(self, value, title): + """Convert/check value type.""" + if isinstance(value, str): + return value + assert isinstance(value, bytes), \ + "{0} must be a string or bytes object (not {1})".format(title, value) + return str(value, "iso-8859-1") def send_preamble(self): """Transmit version/status/date/server, via self._write()""" @@ -188,7 +198,8 @@ def write(self, data): """'write()' callable as specified by PEP 333""" - assert type(data) is str,"write() argument must be string" + assert isinstance(data, (str, bytes)), \ + "write() argument must be a string or bytes" if not self.status: raise AssertionError("write() before start_response()") @@ -382,8 +393,13 @@ self.environ.update(self.base_env) def _write(self,data): + if isinstance(data, str): + try: + data = data.encode("iso-8859-1") + except UnicodeEncodeError: + raise ValueError("Unicode data must contain only code points" + " representable in ISO-8859-1 encoding") self.stdout.write(data) - self._write = self.stdout.write def _flush(self): self.stdout.flush() Modified: python/branches/release30-maint/Lib/wsgiref/headers.py ============================================================================== --- python/branches/release30-maint/Lib/wsgiref/headers.py (original) +++ python/branches/release30-maint/Lib/wsgiref/headers.py Sat Jan 3 19:57:08 2009 @@ -44,7 +44,19 @@ def __init__(self,headers): if not isinstance(headers, list): raise TypeError("Headers must be a list of name/value tuples") - self._headers = headers + self._headers = [] + for k, v in headers: + k = self._convert_string_type(k) + v = self._convert_string_type(v) + self._headers.append((k, v)) + + def _convert_string_type(self, value): + """Convert/check value type.""" + if isinstance(value, str): + return value + assert isinstance(value, bytes), ("Header names/values must be" + " a string or bytes object (not {0})".format(value)) + return str(value, "iso-8859-1") def __len__(self): """Return the total number of headers, including duplicates.""" @@ -53,7 +65,8 @@ def __setitem__(self, name, val): """Set the value of a header.""" del self[name] - self._headers.append((name, val)) + self._headers.append( + (self._convert_string_type(name), self._convert_string_type(val))) def __delitem__(self,name): """Delete all occurrences of a header, if present. @@ -152,7 +165,8 @@ and value 'value'.""" result = self.get(name) if result is None: - self._headers.append((name,value)) + self._headers.append((self._convert_string_type(name), + self._convert_string_type(value))) return value else: return result @@ -176,13 +190,16 @@ """ parts = [] if _value is not None: + _value = self._convert_string_type(_value) parts.append(_value) for k, v in _params.items(): + k = self._convert_string_type(k) if v is None: parts.append(k.replace('_', '-')) else: + v = self._convert_string_type(v) parts.append(_formatparam(k.replace('_', '-'), v)) - self._headers.append((_name, "; ".join(parts))) + self._headers.append((self._convert_string_type(_name), "; ".join(parts))) Modified: python/branches/release30-maint/Lib/wsgiref/simple_server.py ============================================================================== --- python/branches/release30-maint/Lib/wsgiref/simple_server.py (original) +++ python/branches/release30-maint/Lib/wsgiref/simple_server.py Sat Jan 3 19:57:08 2009 @@ -111,8 +111,7 @@ if length: env['CONTENT_LENGTH'] = length - for h in self.headers: - k,v = h.split(':',1) + for k, v in self.headers.items(): k=k.replace('-','_').upper(); v=v.strip() if k in env: continue # skip content length, type,etc. @@ -168,11 +167,11 @@ stdout = StringIO() print("Hello world!", file=stdout) print(file=stdout) - h = environ.items(); h.sort() + h = sorted(environ.items()) for k,v in h: print(k,'=',repr(v), file=stdout) - start_response("200 OK", [('Content-Type','text/plain')]) - return [stdout.getvalue()] + start_response(b"200 OK", [(b'Content-Type',b'text/plain; charset=utf-8')]) + return [stdout.getvalue().encode("utf-8")] def make_server( Modified: python/branches/release30-maint/Lib/wsgiref/util.py ============================================================================== --- python/branches/release30-maint/Lib/wsgiref/util.py (original) +++ python/branches/release30-maint/Lib/wsgiref/util.py Sat Jan 3 19:57:08 2009 @@ -149,8 +149,8 @@ environ.setdefault('wsgi.multithread', 0) environ.setdefault('wsgi.multiprocess', 0) - from io import StringIO - environ.setdefault('wsgi.input', StringIO("")) + from io import StringIO, BytesIO + environ.setdefault('wsgi.input', BytesIO()) environ.setdefault('wsgi.errors', StringIO()) environ.setdefault('wsgi.url_scheme',guess_scheme(environ)) Modified: python/branches/release30-maint/Lib/wsgiref/validate.py ============================================================================== --- python/branches/release30-maint/Lib/wsgiref/validate.py (original) +++ python/branches/release30-maint/Lib/wsgiref/validate.py Sat Jan 3 19:57:08 2009 @@ -127,6 +127,13 @@ if not cond: raise AssertionError(*args) +def check_string_type(value, title): + if isinstance(value, str): + return value + assert isinstance(value, bytes), \ + "{0} must be a string or bytes object (not {1})".format(title, value) + return str(value, "iso-8859-1") + def validator(application): """ @@ -188,14 +195,14 @@ self.input = wsgi_input def read(self, *args): - assert_(len(args) <= 1) + assert_(len(args) == 1) v = self.input.read(*args) - assert_(isinstance(v, str)) + assert_(isinstance(v, bytes)) return v def readline(self): v = self.input.readline() - assert_(isinstance(v, str)) + assert_(isinstance(v, bytes)) return v def readlines(self, *args): @@ -203,7 +210,7 @@ lines = self.input.readlines(*args) assert_(isinstance(lines, list)) for line in lines: - assert_(isinstance(line, str)) + assert_(isinstance(line, bytes)) return lines def __iter__(self): @@ -241,7 +248,7 @@ self.writer = wsgi_writer def __call__(self, s): - assert_(isinstance(s, str)) + assert_(isinstance(s, (str, bytes))) self.writer(s) class PartialIteratorWrapper: @@ -364,8 +371,7 @@ % (wsgi_errors, attr)) def check_status(status): - assert_(isinstance(status, str), - "Status must be a string (not %r)" % status) + status = check_string_type(status, "Status") # Implicitly check that we can turn it into an integer: status_code = status.split(None, 1)[0] assert_(len(status_code) == 3, @@ -389,6 +395,8 @@ % (item, type(item))) assert_(len(item) == 2) name, value = item + name = check_string_type(name, "Header name") + value = check_string_type(value, "Header value") assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " @@ -404,11 +412,13 @@ % (value, bad_header_value_re.search(value).group(0))) def check_content_type(status, headers): + status = check_string_type(status, "Status") code = int(status.split(None, 1)[0]) # @@: need one more person to verify this interpretation of RFC 2616 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html NO_MESSAGE_BODY = (204, 304) for name, value in headers: + name = check_string_type(name, "Header name") if name.lower() == 'content-type': if code not in NO_MESSAGE_BODY: return @@ -426,6 +436,6 @@ # Technically a string is legal, which is why it's a really bad # idea, because it may cause the response to be returned # character-by-character - assert_(not isinstance(iterator, str), + assert_(not isinstance(iterator, (str, bytes)), "You should not return a string as your application iterator, " "instead return a single-item list containing that string.") Modified: python/branches/release30-maint/Misc/NEWS ============================================================================== --- python/branches/release30-maint/Misc/NEWS (original) +++ python/branches/release30-maint/Misc/NEWS Sat Jan 3 19:57:08 2009 @@ -52,6 +52,10 @@ Library ------- +- Issue #4718: Adapt the wsgiref package so that it actually works with + Python 3.x, in accordance with the `official amendments of the spec + `_. + - Fractions.from_float() no longer loses precision for integers too big to cast as floats. From python-checkins at python.org Sat Jan 3 20:02:24 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 20:02:24 +0100 (CET) Subject: [Python-checkins] r68208 - in python/trunk: Doc/library/decimal.rst Lib/decimal.py Lib/test/test_decimal.py Misc/NEWS Message-ID: <20090103190224.9F2EE1E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 20:02:23 2009 New Revision: 68208 Log: Issue 4796: Add from_float methods to the decimal module. Modified: python/trunk/Doc/library/decimal.rst python/trunk/Lib/decimal.py python/trunk/Lib/test/test_decimal.py python/trunk/Misc/NEWS Modified: python/trunk/Doc/library/decimal.rst ============================================================================== --- python/trunk/Doc/library/decimal.rst (original) +++ python/trunk/Doc/library/decimal.rst Sat Jan 3 20:02:23 2009 @@ -484,6 +484,29 @@ .. versionadded:: 2.6 + .. method:: from_float(f) + + Classmethod that converts a float to a decimal number, exactly. + + Note `Decimal.from_float(0.1)` is not the same as `Decimal('0.1')`. + Since 0.1 is not exactly representable in binary floating point, the + value is stored as the nearest representable value which is + `0x1.999999999999ap-4`. That equivalent value in decimal is + `0.1000000000000000055511151231257827021181583404541015625`. + + .. doctest:: + + >>> Decimal.from_float(0.1) + Decimal('0.1000000000000000055511151231257827021181583404541015625') + >>> Decimal.from_float(float('nan')) + Decimal('NaN') + >>> Decimal.from_float(float('inf')) + Decimal('Infinity') + >>> Decimal.from_float(float('-inf')) + Decimal('-Infinity') + + .. versionadded:: 2.7 + .. method:: fma(other, third[, context]) Fused multiply-add. Return self*other+third with no rounding of the @@ -1007,6 +1030,26 @@ If the argument is a string, no leading or trailing whitespace is permitted. +.. method:: create_decimal_from_float(f) + + Creates a new Decimal instance from a float *f* but rounding using *self* + as the context. Unlike the :method:`Decimal.from_float` class method, + the context precision, rounding method, flags, and traps are applied to + the conversion. + + .. doctest:: + + >>> context = Context(prec=5, rounding=ROUND_DOWN) + >>> context.create_decimal_from_float(math.pi) + Decimal('3.1415') + >>> context = Context(prec=5, traps=[Inexact]) + >>> context.create_decimal_from_float(math.pi) + Traceback (most recent call last): + ... + Inexact: None + + .. versionadded:: 2.7 + .. method:: Etiny() Returns a value equal to ``Emin - prec + 1`` which is the minimum exponent Modified: python/trunk/Lib/decimal.py ============================================================================== --- python/trunk/Lib/decimal.py (original) +++ python/trunk/Lib/decimal.py Sat Jan 3 20:02:23 2009 @@ -135,6 +135,7 @@ ] import copy as _copy +import math as _math try: from collections import namedtuple as _namedtuple @@ -242,7 +243,7 @@ """ def handle(self, context, sign, *args): - return _SignedInfinity[sign] + return _Infsign[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -340,15 +341,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return _SignedInfinity[sign] + return _Infsign[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return _SignedInfinity[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return _SignedInfinity[sign] + return _Infsign[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -653,6 +654,38 @@ raise TypeError("Cannot convert %r to Decimal" % value) + @classmethod + def from_float(cls, f): + """Converts a float to a decimal number, exactly. + + Note that Decimal.from_float(0.1) is not the same as Decimal('0.1'). + Since 0.1 is not exactly representable in binary floating point, the + value is stored as the nearest representable value which is + 0x1.999999999999ap-4. The exact equivalent of the value in decimal + is 0.1000000000000000055511151231257827021181583404541015625. + + >>> Decimal.from_float(0.1) + Decimal('0.1000000000000000055511151231257827021181583404541015625') + >>> Decimal.from_float(float('nan')) + Decimal('NaN') + >>> Decimal.from_float(float('inf')) + Decimal('Infinity') + >>> Decimal.from_float(-float('inf')) + Decimal('-Infinity') + >>> Decimal.from_float(-0.0) + Decimal('-0') + + """ + if isinstance(f, (int, long)): # handle integer inputs + return cls(f) + if _math.isinf(f) or _math.isnan(f): # raises TypeError if not a float + return cls(repr(f)) + sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 + n, d = abs(f).as_integer_ratio() + k = d.bit_length() - 1 + result = _dec_from_triple(sign, str(n*5**k), -k) + return result if cls is Decimal else cls(result) + def _isnan(self): """Returns whether the number is not actually one. @@ -1171,12 +1204,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return _SignedInfinity[resultsign] + return _Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return _SignedInfinity[resultsign] + return _Infsign[resultsign] resultexp = self._exp + other._exp @@ -1226,7 +1259,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return _SignedInfinity[sign] + return _Infsign[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1329,7 +1362,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (_SignedInfinity[sign], + return (_Infsign[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1477,7 +1510,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return _SignedInfinity[self._sign ^ other._sign] + return _Infsign[self._sign ^ other._sign] if not other: if self: @@ -1732,12 +1765,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = _SignedInfinity[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = _SignedInfinity[self._sign ^ other._sign] + product = _Infsign[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2087,7 +2120,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return _One + return _Dec_p1 # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2109,19 +2142,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return _SignedInfinity[result_sign] + return _Infsign[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return _SignedInfinity[result_sign] + return _Infsign[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == _One: + if self == _Dec_p1: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2154,7 +2187,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return _SignedInfinity[result_sign] + return _Infsign[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2674,9 +2707,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return _NegativeOne + return _Dec_n1 if not self._sign and other._sign: - return _One + return _Dec_p1 sign = self._sign # let's handle both NaN types @@ -2686,51 +2719,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return _One + return _Dec_p1 else: - return _NegativeOne + return _Dec_n1 if self._int > other._int: if sign: - return _NegativeOne + return _Dec_n1 else: - return _One - return _Zero + return _Dec_p1 + return _Dec_0 if sign: if self_nan == 1: - return _NegativeOne + return _Dec_n1 if other_nan == 1: - return _One + return _Dec_p1 if self_nan == 2: - return _NegativeOne + return _Dec_n1 if other_nan == 2: - return _One + return _Dec_p1 else: if self_nan == 1: - return _One + return _Dec_p1 if other_nan == 1: - return _NegativeOne + return _Dec_n1 if self_nan == 2: - return _One + return _Dec_p1 if other_nan == 2: - return _NegativeOne + return _Dec_n1 if self < other: - return _NegativeOne + return _Dec_n1 if self > other: - return _One + return _Dec_p1 if self._exp < other._exp: if sign: - return _One + return _Dec_p1 else: - return _NegativeOne + return _Dec_n1 if self._exp > other._exp: if sign: - return _NegativeOne + return _Dec_n1 else: - return _One - return _Zero + return _Dec_p1 + return _Dec_0 def compare_total_mag(self, other): @@ -2771,11 +2804,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return _Zero + return _Dec_0 # exp(0) = 1 if not self: - return _One + return _Dec_p1 # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -2927,15 +2960,15 @@ # ln(0.0) == -Infinity if not self: - return _NegativeInfinity + return _negInf # ln(Infinity) = Infinity if self._isinfinity() == 1: - return _Infinity + return _Inf # ln(1.0) == 0.0 - if self == _One: - return _Zero + if self == _Dec_p1: + return _Dec_0 # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3007,11 +3040,11 @@ # log10(0.0) == -Infinity if not self: - return _NegativeInfinity + return _negInf # log10(Infinity) = Infinity if self._isinfinity() == 1: - return _Infinity + return _Inf # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3063,7 +3096,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return _Infinity + return _Inf # logb(0) = -Inf, DivisionByZero if not self: @@ -3220,7 +3253,7 @@ return ans if self._isinfinity() == -1: - return _NegativeInfinity + return _negInf if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3243,7 +3276,7 @@ return ans if self._isinfinity() == 1: - return _Infinity + return _Inf if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -3744,6 +3777,23 @@ "diagnostic info too long in NaN") return d._fix(self) + def create_decimal_from_float(self, f): + """Creates a new Decimal instance from a float but rounding using self + as the context. + + >>> context = Context(prec=5, rounding=ROUND_DOWN) + >>> context.create_decimal_from_float(3.1415926535897932) + Decimal('3.1415') + >>> context = Context(prec=5, traps=[Inexact]) + >>> context.create_decimal_from_float(3.1415926535897932) + Traceback (most recent call last): + ... + Inexact: None + + """ + d = Decimal.from_float(f) # An exact conversion + return d._fix(self) # Apply the context rounding + # Methods def abs(self, a): """Returns the absolute value of the operand. @@ -5490,15 +5540,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -_Infinity = Decimal('Inf') -_NegativeInfinity = Decimal('-Inf') +_Inf = Decimal('Inf') +_negInf = Decimal('-Inf') _NaN = Decimal('NaN') -_Zero = Decimal(0) -_One = Decimal(1) -_NegativeOne = Decimal(-1) +_Dec_0 = Decimal(0) +_Dec_p1 = Decimal(1) +_Dec_n1 = Decimal(-1) -# _SignedInfinity[sign] is infinity w/ that sign -_SignedInfinity = (_Infinity, _NegativeInfinity) +# _Infsign[sign] is infinity w/ that sign +_Infsign = (_Inf, _negInf) Modified: python/trunk/Lib/test/test_decimal.py ============================================================================== --- python/trunk/Lib/test/test_decimal.py (original) +++ python/trunk/Lib/test/test_decimal.py Sat Jan 3 20:02:23 2009 @@ -1361,6 +1361,55 @@ r = d.to_integral(ROUND_DOWN) self.assertEqual(Decimal(math.trunc(d)), r) + def test_from_float(self): + + class MyDecimal(Decimal): + pass + + r = MyDecimal.from_float(0.1) + self.assertEqual(type(r), MyDecimal) + self.assertEqual(str(r), + '0.1000000000000000055511151231257827021181583404541015625') + bigint = 12345678901234567890123456789 + self.assertEqual(MyDecimal.from_float(bigint), MyDecimal(bigint)) + self.assert_(MyDecimal.from_float(float('nan')).is_qnan()) + self.assert_(MyDecimal.from_float(float('inf')).is_infinite()) + self.assert_(MyDecimal.from_float(float('-inf')).is_infinite()) + self.assertEqual(str(MyDecimal.from_float(float('nan'))), + str(Decimal('NaN'))) + self.assertEqual(str(MyDecimal.from_float(float('inf'))), + str(Decimal('Infinity'))) + self.assertEqual(str(MyDecimal.from_float(float('-inf'))), + str(Decimal('-Infinity'))) + self.assertRaises(TypeError, MyDecimal.from_float, 'abc') + for i in range(200): + x = random.expovariate(0.01) * (random.random() * 2.0 - 1.0) + self.assertEqual(x, float(MyDecimal.from_float(x))) # roundtrip + + def test_create_decimal_from_float(self): + context = Context(prec=5, rounding=ROUND_DOWN) + self.assertEqual( + context.create_decimal_from_float(math.pi), + Decimal('3.1415') + ) + context = Context(prec=5, rounding=ROUND_UP) + self.assertEqual( + context.create_decimal_from_float(math.pi), + Decimal('3.1416') + ) + context = Context(prec=5, traps=[Inexact]) + self.assertRaises( + Inexact, + context.create_decimal_from_float, + math.pi + ) + self.assertEqual(repr(context.create_decimal_from_float(-0.0)), + "Decimal('-0')") + self.assertEqual(repr(context.create_decimal_from_float(1.0)), + "Decimal('1')") + self.assertEqual(repr(context.create_decimal_from_float(10)), + "Decimal('10')") + class ContextAPItests(unittest.TestCase): def test_pickle(self): Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Sat Jan 3 20:02:23 2009 @@ -12,8 +12,6 @@ Core and Builtins ----------------- -- Issue #4817: Remove unused function PyOS_GetLastModificationTime. - - Issue #4075: Use OutputDebugStringW in Py_FatalError. - Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open @@ -110,6 +108,9 @@ Library ------- +- Issue #4796: Added Decimal.from_float() and Context.create_decimal_from_float() + to the decimal module. + - Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) From buildbot at python.org Sat Jan 3 20:07:11 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 19:07:11 +0000 Subject: [Python-checkins] buildbot failure in sparc solaris10 gcc 3.x Message-ID: <20090103190711.90AEF1E4002@bag.python.org> The Buildbot has detected a new failure of sparc solaris10 gcc 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/sparc%20solaris10%20gcc%203.x/builds/57 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: loewis-sun Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: antoine.pitrou,martin.v.loewis BUILD FAILED: failed test Excerpt from the test logfile: 4 tests failed: test_distutils test_doctest test_posix test_subprocess ====================================================================== FAIL: test_get_python_inc (distutils.tests.test_sysconfig.SysconfigTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/distutils/tests/test_sysconfig.py", line 43, in test_get_python_inc self.assert_(os.path.isdir(inc_dir), inc_dir) AssertionError: /home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/Include ====================================================================== ERROR: test_getcwd_long_pathnames (test.test_posix.PosixTester) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_posix.py", line 252, in test_getcwd_long_pathnames support.rmtree(base_path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/support.py", line 98, in rmtree shutil.rmtree(path) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 225, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/shutil.py", line 223, in rmtree os.rmdir(path) OSError: [Errno 22] Invalid argument: '/home2/buildbot/slave/3.x.loewis-sun/build/@test.getcwd/@test.getcwd' ====================================================================== FAIL: test_executable (test.test_subprocess.ProcessTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_subprocess.py", line 149, in test_executable self.assertEqual(p.returncode, 47) AssertionError: -6 != 47 sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 20:08:13 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 20:08:13 +0100 (CET) Subject: [Python-checkins] r68209 - python/trunk/Lib/decimal.py Message-ID: <20090103190813.23DBE1E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 20:08:10 2009 New Revision: 68209 Log: Reapply r68191. Modified: python/trunk/Lib/decimal.py Modified: python/trunk/Lib/decimal.py ============================================================================== --- python/trunk/Lib/decimal.py (original) +++ python/trunk/Lib/decimal.py Sat Jan 3 20:08:10 2009 @@ -243,7 +243,7 @@ """ def handle(self, context, sign, *args): - return _Infsign[sign] + return _SignedInfinity[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -341,15 +341,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_HALF_DOWN, ROUND_UP): - return _Infsign[sign] + return _SignedInfinity[sign] if sign == 0: if context.rounding == ROUND_CEILING: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUND_FLOOR: - return _Infsign[sign] + return _SignedInfinity[sign] return _dec_from_triple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1204,12 +1204,12 @@ if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') - return _Infsign[resultsign] + return _SignedInfinity[resultsign] resultexp = self._exp + other._exp @@ -1259,7 +1259,7 @@ return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF') if self._isinfinity(): - return _Infsign[sign] + return _SignedInfinity[sign] if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') @@ -1362,7 +1362,7 @@ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (_Infsign[sign], + return (_SignedInfinity[sign], context._raise_error(InvalidOperation, 'INF % x')) if not other: @@ -1510,7 +1510,7 @@ if other._isinfinity(): return context._raise_error(InvalidOperation, 'INF // INF') else: - return _Infsign[self._sign ^ other._sign] + return _SignedInfinity[self._sign ^ other._sign] if not other: if self: @@ -1765,12 +1765,12 @@ if not other: return context._raise_error(InvalidOperation, 'INF * 0 in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] elif other._exp == 'F': if not self: return context._raise_error(InvalidOperation, '0 * INF in fma') - product = _Infsign[self._sign ^ other._sign] + product = _SignedInfinity[self._sign ^ other._sign] else: product = _dec_from_triple(self._sign ^ other._sign, str(int(self._int) * int(other._int)), @@ -2120,7 +2120,7 @@ if not self: return context._raise_error(InvalidOperation, '0 ** 0') else: - return _Dec_p1 + return _One # result has sign 1 iff self._sign is 1 and other is an odd integer result_sign = 0 @@ -2142,19 +2142,19 @@ if other._sign == 0: return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self._isinfinity(): if other._sign == 0: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] else: return _dec_from_triple(result_sign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == _Dec_p1: + if self == _One: if other._isinteger(): # exp = max(self._exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2187,7 +2187,7 @@ if (other._sign == 0) == (self_adj < 0): return _dec_from_triple(result_sign, '0', 0) else: - return _Infsign[result_sign] + return _SignedInfinity[result_sign] # from here on, the result always goes through the call # to _fix at the end of this function. @@ -2707,9 +2707,9 @@ """ # if one is negative and the other is positive, it's easy if self._sign and not other._sign: - return _Dec_n1 + return _NegativeOne if not self._sign and other._sign: - return _Dec_p1 + return _One sign = self._sign # let's handle both NaN types @@ -2719,51 +2719,51 @@ if self_nan == other_nan: if self._int < other._int: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._int > other._int: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero if sign: if self_nan == 1: - return _Dec_n1 + return _NegativeOne if other_nan == 1: - return _Dec_p1 + return _One if self_nan == 2: - return _Dec_n1 + return _NegativeOne if other_nan == 2: - return _Dec_p1 + return _One else: if self_nan == 1: - return _Dec_p1 + return _One if other_nan == 1: - return _Dec_n1 + return _NegativeOne if self_nan == 2: - return _Dec_p1 + return _One if other_nan == 2: - return _Dec_n1 + return _NegativeOne if self < other: - return _Dec_n1 + return _NegativeOne if self > other: - return _Dec_p1 + return _One if self._exp < other._exp: if sign: - return _Dec_p1 + return _One else: - return _Dec_n1 + return _NegativeOne if self._exp > other._exp: if sign: - return _Dec_n1 + return _NegativeOne else: - return _Dec_p1 - return _Dec_0 + return _One + return _Zero def compare_total_mag(self, other): @@ -2804,11 +2804,11 @@ # exp(-Infinity) = 0 if self._isinfinity() == -1: - return _Dec_0 + return _Zero # exp(0) = 1 if not self: - return _Dec_p1 + return _One # exp(Infinity) = Infinity if self._isinfinity() == 1: @@ -2960,15 +2960,15 @@ # ln(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # ln(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # ln(1.0) == 0.0 - if self == _Dec_p1: - return _Dec_0 + if self == _One: + return _Zero # ln(negative) raises InvalidOperation if self._sign == 1: @@ -3040,11 +3040,11 @@ # log10(0.0) == -Infinity if not self: - return _negInf + return _NegativeInfinity # log10(Infinity) = Infinity if self._isinfinity() == 1: - return _Inf + return _Infinity # log10(negative or -Infinity) raises InvalidOperation if self._sign == 1: @@ -3096,7 +3096,7 @@ # logb(+/-Inf) = +Inf if self._isinfinity(): - return _Inf + return _Infinity # logb(0) = -Inf, DivisionByZero if not self: @@ -3253,7 +3253,7 @@ return ans if self._isinfinity() == -1: - return _negInf + return _NegativeInfinity if self._isinfinity() == 1: return _dec_from_triple(0, '9'*context.prec, context.Etop()) @@ -3276,7 +3276,7 @@ return ans if self._isinfinity() == 1: - return _Inf + return _Infinity if self._isinfinity() == -1: return _dec_from_triple(1, '9'*context.prec, context.Etop()) @@ -5540,15 +5540,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -_Inf = Decimal('Inf') -_negInf = Decimal('-Inf') +_Infinity = Decimal('Inf') +_NegativeInfinity = Decimal('-Inf') _NaN = Decimal('NaN') -_Dec_0 = Decimal(0) -_Dec_p1 = Decimal(1) -_Dec_n1 = Decimal(-1) +_Zero = Decimal(0) +_One = Decimal(1) +_NegativeOne = Decimal(-1) -# _Infsign[sign] is infinity w/ that sign -_Infsign = (_Inf, _negInf) +# _SignedInfinity[sign] is infinity w/ that sign +_SignedInfinity = (_Infinity, _NegativeInfinity) From buildbot at python.org Sat Jan 3 20:10:01 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 19:10:01 +0000 Subject: [Python-checkins] buildbot failure in i386 Ubuntu 3.x Message-ID: <20090103191001.BF8351E400C@bag.python.org> The Buildbot has detected a new failure of i386 Ubuntu 3.x. Full details are available at: http://www.python.org/dev/buildbot/all/i386%20Ubuntu%203.x/builds/63 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-i386 Build Reason: Build Source Stamp: [branch branches/py3k] HEAD Blamelist: antoine.pitrou BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_wsgiref ====================================================================== ERROR: testEnviron (test.test_wsgiref.HandlerTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/pybot/buildarea/3.x.klose-ubuntu-i386/build/Lib/test/test_wsgiref.py", line 490, in testEnviron File "/home/pybot/buildarea/3.x.klose-ubuntu-i386/build/Lib/test/test_wsgiref.py", line 482, in checkOSEnviron KeyError: 'AUTH_TYPE' make: *** [buildbottest] Error 1 sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 20:10:13 2009 From: python-checkins at python.org (georg.brandl) Date: Sat, 3 Jan 2009 20:10:13 +0100 (CET) Subject: [Python-checkins] r68210 - python/trunk/Doc/includes/mp_distributing.py Message-ID: <20090103191013.1735D1E4002@bag.python.org> Author: georg.brandl Date: Sat Jan 3 20:10:12 2009 New Revision: 68210 Log: Set eol-style correctly for mp_distributing.py. Modified: python/trunk/Doc/includes/mp_distributing.py (contents, props changed) Modified: python/trunk/Doc/includes/mp_distributing.py ============================================================================== --- python/trunk/Doc/includes/mp_distributing.py (original) +++ python/trunk/Doc/includes/mp_distributing.py Sat Jan 3 20:10:12 2009 @@ -1,364 +1,364 @@ -# -# Module to allow spawning of processes on foreign host -# -# Depends on `multiprocessing` package -- tested with `processing-0.60` -# -# Copyright (c) 2006-2008, R Oudkerk -# All rights reserved. -# - -__all__ = ['Cluster', 'Host', 'get_logger', 'current_process'] - -# -# Imports -# - -import sys -import os -import tarfile -import shutil -import subprocess -import logging -import itertools -import Queue - -try: - import cPickle as pickle -except ImportError: - import pickle - -from multiprocessing import Process, current_process, cpu_count -from multiprocessing import util, managers, connection, forking, pool - -# -# Logging -# - -def get_logger(): - return _logger - -_logger = logging.getLogger('distributing') -_logger.propogate = 0 - -_formatter = logging.Formatter(util.DEFAULT_LOGGING_FORMAT) -_handler = logging.StreamHandler() -_handler.setFormatter(_formatter) -_logger.addHandler(_handler) - -info = _logger.info -debug = _logger.debug - -# -# Get number of cpus -# - -try: - slot_count = cpu_count() -except NotImplemented: - slot_count = 1 - -# -# Manager type which spawns subprocesses -# - -class HostManager(managers.SyncManager): - ''' - Manager type used for spawning processes on a (presumably) foreign host - ''' - def __init__(self, address, authkey): - managers.SyncManager.__init__(self, address, authkey) - self._name = 'Host-unknown' - - def Process(self, group=None, target=None, name=None, args=(), kwargs={}): - if hasattr(sys.modules['__main__'], '__file__'): - main_path = os.path.basename(sys.modules['__main__'].__file__) - else: - main_path = None - data = pickle.dumps((target, args, kwargs)) - p = self._RemoteProcess(data, main_path) - if name is None: - temp = self._name.split('Host-')[-1] + '/Process-%s' - name = temp % ':'.join(map(str, p.get_identity())) - p.set_name(name) - return p - - @classmethod - def from_address(cls, address, authkey): - manager = cls(address, authkey) - managers.transact(address, authkey, 'dummy') - manager._state.value = managers.State.STARTED - manager._name = 'Host-%s:%s' % manager.address - manager.shutdown = util.Finalize( - manager, HostManager._finalize_host, - args=(manager._address, manager._authkey, manager._name), - exitpriority=-10 - ) - return manager - - @staticmethod - def _finalize_host(address, authkey, name): - managers.transact(address, authkey, 'shutdown') - - def __repr__(self): - return '' % self._name - -# -# Process subclass representing a process on (possibly) a remote machine -# - -class RemoteProcess(Process): - ''' - Represents a process started on a remote host - ''' - def __init__(self, data, main_path): - assert not main_path or os.path.basename(main_path) == main_path - Process.__init__(self) - self._data = data - self._main_path = main_path - - def _bootstrap(self): - forking.prepare({'main_path': self._main_path}) - self._target, self._args, self._kwargs = pickle.loads(self._data) - return Process._bootstrap(self) - - def get_identity(self): - return self._identity - -HostManager.register('_RemoteProcess', RemoteProcess) - -# -# A Pool class that uses a cluster -# - -class DistributedPool(pool.Pool): - - def __init__(self, cluster, processes=None, initializer=None, initargs=()): - self._cluster = cluster - self.Process = cluster.Process - pool.Pool.__init__(self, processes or len(cluster), - initializer, initargs) - - def _setup_queues(self): - self._inqueue = self._cluster._SettableQueue() - self._outqueue = self._cluster._SettableQueue() - self._quick_put = self._inqueue.put - self._quick_get = self._outqueue.get - - @staticmethod - def _help_stuff_finish(inqueue, task_handler, size): - inqueue.set_contents([None] * size) - -# -# Manager type which starts host managers on other machines -# - -def LocalProcess(**kwds): - p = Process(**kwds) - p.set_name('localhost/' + p.name) - return p - -class Cluster(managers.SyncManager): - ''' - Represents collection of slots running on various hosts. - - `Cluster` is a subclass of `SyncManager` so it allows creation of - various types of shared objects. - ''' - def __init__(self, hostlist, modules): - managers.SyncManager.__init__(self, address=('localhost', 0)) - self._hostlist = hostlist - self._modules = modules - if __name__ not in modules: - modules.append(__name__) - files = [sys.modules[name].__file__ for name in modules] - for i, file in enumerate(files): - if file.endswith('.pyc') or file.endswith('.pyo'): - files[i] = file[:-4] + '.py' - self._files = [os.path.abspath(file) for file in files] - - def start(self): - managers.SyncManager.start(self) - - l = connection.Listener(family='AF_INET', authkey=self._authkey) - - for i, host in enumerate(self._hostlist): - host._start_manager(i, self._authkey, l.address, self._files) - - for host in self._hostlist: - if host.hostname != 'localhost': - conn = l.accept() - i, address, cpus = conn.recv() - conn.close() - other_host = self._hostlist[i] - other_host.manager = HostManager.from_address(address, - self._authkey) - other_host.slots = other_host.slots or cpus - other_host.Process = other_host.manager.Process - else: - host.slots = host.slots or slot_count - host.Process = LocalProcess - - self._slotlist = [ - Slot(host) for host in self._hostlist for i in range(host.slots) - ] - self._slot_iterator = itertools.cycle(self._slotlist) - self._base_shutdown = self.shutdown - del self.shutdown - - def shutdown(self): - for host in self._hostlist: - if host.hostname != 'localhost': - host.manager.shutdown() - self._base_shutdown() - - def Process(self, group=None, target=None, name=None, args=(), kwargs={}): - slot = self._slot_iterator.next() - return slot.Process( - group=group, target=target, name=name, args=args, kwargs=kwargs - ) - - def Pool(self, processes=None, initializer=None, initargs=()): - return DistributedPool(self, processes, initializer, initargs) - - def __getitem__(self, i): - return self._slotlist[i] - - def __len__(self): - return len(self._slotlist) - - def __iter__(self): - return iter(self._slotlist) - -# -# Queue subclass used by distributed pool -# - -class SettableQueue(Queue.Queue): - def empty(self): - return not self.queue - def full(self): - return self.maxsize > 0 and len(self.queue) == self.maxsize - def set_contents(self, contents): - # length of contents must be at least as large as the number of - # threads which have potentially called get() - self.not_empty.acquire() - try: - self.queue.clear() - self.queue.extend(contents) - self.not_empty.notifyAll() - finally: - self.not_empty.release() - -Cluster.register('_SettableQueue', SettableQueue) - -# -# Class representing a notional cpu in the cluster -# - -class Slot(object): - def __init__(self, host): - self.host = host - self.Process = host.Process - -# -# Host -# - -class Host(object): - ''' - Represents a host to use as a node in a cluster. - - `hostname` gives the name of the host. If hostname is not - "localhost" then ssh is used to log in to the host. To log in as - a different user use a host name of the form - "username at somewhere.org" - - `slots` is used to specify the number of slots for processes on - the host. This affects how often processes will be allocated to - this host. Normally this should be equal to the number of cpus on - that host. - ''' - def __init__(self, hostname, slots=None): - self.hostname = hostname - self.slots = slots - - def _start_manager(self, index, authkey, address, files): - if self.hostname != 'localhost': - tempdir = copy_to_remote_temporary_directory(self.hostname, files) - debug('startup files copied to %s:%s', self.hostname, tempdir) - p = subprocess.Popen( - ['ssh', self.hostname, 'python', '-c', - '"import os; os.chdir(%r); ' - 'from distributing import main; main()"' % tempdir], - stdin=subprocess.PIPE - ) - data = dict( - name='BoostrappingHost', index=index, - dist_log_level=_logger.getEffectiveLevel(), - dir=tempdir, authkey=str(authkey), parent_address=address - ) - pickle.dump(data, p.stdin, pickle.HIGHEST_PROTOCOL) - p.stdin.close() - -# -# Copy files to remote directory, returning name of directory -# - -unzip_code = '''" -import tempfile, os, sys, tarfile -tempdir = tempfile.mkdtemp(prefix='distrib-') -os.chdir(tempdir) -tf = tarfile.open(fileobj=sys.stdin, mode='r|gz') -for ti in tf: - tf.extract(ti) -print tempdir -"''' - -def copy_to_remote_temporary_directory(host, files): - p = subprocess.Popen( - ['ssh', host, 'python', '-c', unzip_code], - stdout=subprocess.PIPE, stdin=subprocess.PIPE - ) - tf = tarfile.open(fileobj=p.stdin, mode='w|gz') - for name in files: - tf.add(name, os.path.basename(name)) - tf.close() - p.stdin.close() - return p.stdout.read().rstrip() - -# -# Code which runs a host manager -# - -def main(): - # get data from parent over stdin - data = pickle.load(sys.stdin) - sys.stdin.close() - - # set some stuff - _logger.setLevel(data['dist_log_level']) - forking.prepare(data) - - # create server for a `HostManager` object - server = managers.Server(HostManager._registry, ('', 0), data['authkey']) - current_process()._server = server - - # report server address and number of cpus back to parent - conn = connection.Client(data['parent_address'], authkey=data['authkey']) - conn.send((data['index'], server.address, slot_count)) - conn.close() - - # set name etc - current_process().set_name('Host-%s:%s' % server.address) - util._run_after_forkers() - - # register a cleanup function - def cleanup(directory): - debug('removing directory %s', directory) - shutil.rmtree(directory) - debug('shutting down host manager') - util.Finalize(None, cleanup, args=[data['dir']], exitpriority=0) - - # start host manager - debug('remote host manager starting in %s', data['dir']) - server.serve_forever() +# +# Module to allow spawning of processes on foreign host +# +# Depends on `multiprocessing` package -- tested with `processing-0.60` +# +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# + +__all__ = ['Cluster', 'Host', 'get_logger', 'current_process'] + +# +# Imports +# + +import sys +import os +import tarfile +import shutil +import subprocess +import logging +import itertools +import Queue + +try: + import cPickle as pickle +except ImportError: + import pickle + +from multiprocessing import Process, current_process, cpu_count +from multiprocessing import util, managers, connection, forking, pool + +# +# Logging +# + +def get_logger(): + return _logger + +_logger = logging.getLogger('distributing') +_logger.propogate = 0 + +_formatter = logging.Formatter(util.DEFAULT_LOGGING_FORMAT) +_handler = logging.StreamHandler() +_handler.setFormatter(_formatter) +_logger.addHandler(_handler) + +info = _logger.info +debug = _logger.debug + +# +# Get number of cpus +# + +try: + slot_count = cpu_count() +except NotImplemented: + slot_count = 1 + +# +# Manager type which spawns subprocesses +# + +class HostManager(managers.SyncManager): + ''' + Manager type used for spawning processes on a (presumably) foreign host + ''' + def __init__(self, address, authkey): + managers.SyncManager.__init__(self, address, authkey) + self._name = 'Host-unknown' + + def Process(self, group=None, target=None, name=None, args=(), kwargs={}): + if hasattr(sys.modules['__main__'], '__file__'): + main_path = os.path.basename(sys.modules['__main__'].__file__) + else: + main_path = None + data = pickle.dumps((target, args, kwargs)) + p = self._RemoteProcess(data, main_path) + if name is None: + temp = self._name.split('Host-')[-1] + '/Process-%s' + name = temp % ':'.join(map(str, p.get_identity())) + p.set_name(name) + return p + + @classmethod + def from_address(cls, address, authkey): + manager = cls(address, authkey) + managers.transact(address, authkey, 'dummy') + manager._state.value = managers.State.STARTED + manager._name = 'Host-%s:%s' % manager.address + manager.shutdown = util.Finalize( + manager, HostManager._finalize_host, + args=(manager._address, manager._authkey, manager._name), + exitpriority=-10 + ) + return manager + + @staticmethod + def _finalize_host(address, authkey, name): + managers.transact(address, authkey, 'shutdown') + + def __repr__(self): + return '' % self._name + +# +# Process subclass representing a process on (possibly) a remote machine +# + +class RemoteProcess(Process): + ''' + Represents a process started on a remote host + ''' + def __init__(self, data, main_path): + assert not main_path or os.path.basename(main_path) == main_path + Process.__init__(self) + self._data = data + self._main_path = main_path + + def _bootstrap(self): + forking.prepare({'main_path': self._main_path}) + self._target, self._args, self._kwargs = pickle.loads(self._data) + return Process._bootstrap(self) + + def get_identity(self): + return self._identity + +HostManager.register('_RemoteProcess', RemoteProcess) + +# +# A Pool class that uses a cluster +# + +class DistributedPool(pool.Pool): + + def __init__(self, cluster, processes=None, initializer=None, initargs=()): + self._cluster = cluster + self.Process = cluster.Process + pool.Pool.__init__(self, processes or len(cluster), + initializer, initargs) + + def _setup_queues(self): + self._inqueue = self._cluster._SettableQueue() + self._outqueue = self._cluster._SettableQueue() + self._quick_put = self._inqueue.put + self._quick_get = self._outqueue.get + + @staticmethod + def _help_stuff_finish(inqueue, task_handler, size): + inqueue.set_contents([None] * size) + +# +# Manager type which starts host managers on other machines +# + +def LocalProcess(**kwds): + p = Process(**kwds) + p.set_name('localhost/' + p.name) + return p + +class Cluster(managers.SyncManager): + ''' + Represents collection of slots running on various hosts. + + `Cluster` is a subclass of `SyncManager` so it allows creation of + various types of shared objects. + ''' + def __init__(self, hostlist, modules): + managers.SyncManager.__init__(self, address=('localhost', 0)) + self._hostlist = hostlist + self._modules = modules + if __name__ not in modules: + modules.append(__name__) + files = [sys.modules[name].__file__ for name in modules] + for i, file in enumerate(files): + if file.endswith('.pyc') or file.endswith('.pyo'): + files[i] = file[:-4] + '.py' + self._files = [os.path.abspath(file) for file in files] + + def start(self): + managers.SyncManager.start(self) + + l = connection.Listener(family='AF_INET', authkey=self._authkey) + + for i, host in enumerate(self._hostlist): + host._start_manager(i, self._authkey, l.address, self._files) + + for host in self._hostlist: + if host.hostname != 'localhost': + conn = l.accept() + i, address, cpus = conn.recv() + conn.close() + other_host = self._hostlist[i] + other_host.manager = HostManager.from_address(address, + self._authkey) + other_host.slots = other_host.slots or cpus + other_host.Process = other_host.manager.Process + else: + host.slots = host.slots or slot_count + host.Process = LocalProcess + + self._slotlist = [ + Slot(host) for host in self._hostlist for i in range(host.slots) + ] + self._slot_iterator = itertools.cycle(self._slotlist) + self._base_shutdown = self.shutdown + del self.shutdown + + def shutdown(self): + for host in self._hostlist: + if host.hostname != 'localhost': + host.manager.shutdown() + self._base_shutdown() + + def Process(self, group=None, target=None, name=None, args=(), kwargs={}): + slot = self._slot_iterator.next() + return slot.Process( + group=group, target=target, name=name, args=args, kwargs=kwargs + ) + + def Pool(self, processes=None, initializer=None, initargs=()): + return DistributedPool(self, processes, initializer, initargs) + + def __getitem__(self, i): + return self._slotlist[i] + + def __len__(self): + return len(self._slotlist) + + def __iter__(self): + return iter(self._slotlist) + +# +# Queue subclass used by distributed pool +# + +class SettableQueue(Queue.Queue): + def empty(self): + return not self.queue + def full(self): + return self.maxsize > 0 and len(self.queue) == self.maxsize + def set_contents(self, contents): + # length of contents must be at least as large as the number of + # threads which have potentially called get() + self.not_empty.acquire() + try: + self.queue.clear() + self.queue.extend(contents) + self.not_empty.notifyAll() + finally: + self.not_empty.release() + +Cluster.register('_SettableQueue', SettableQueue) + +# +# Class representing a notional cpu in the cluster +# + +class Slot(object): + def __init__(self, host): + self.host = host + self.Process = host.Process + +# +# Host +# + +class Host(object): + ''' + Represents a host to use as a node in a cluster. + + `hostname` gives the name of the host. If hostname is not + "localhost" then ssh is used to log in to the host. To log in as + a different user use a host name of the form + "username at somewhere.org" + + `slots` is used to specify the number of slots for processes on + the host. This affects how often processes will be allocated to + this host. Normally this should be equal to the number of cpus on + that host. + ''' + def __init__(self, hostname, slots=None): + self.hostname = hostname + self.slots = slots + + def _start_manager(self, index, authkey, address, files): + if self.hostname != 'localhost': + tempdir = copy_to_remote_temporary_directory(self.hostname, files) + debug('startup files copied to %s:%s', self.hostname, tempdir) + p = subprocess.Popen( + ['ssh', self.hostname, 'python', '-c', + '"import os; os.chdir(%r); ' + 'from distributing import main; main()"' % tempdir], + stdin=subprocess.PIPE + ) + data = dict( + name='BoostrappingHost', index=index, + dist_log_level=_logger.getEffectiveLevel(), + dir=tempdir, authkey=str(authkey), parent_address=address + ) + pickle.dump(data, p.stdin, pickle.HIGHEST_PROTOCOL) + p.stdin.close() + +# +# Copy files to remote directory, returning name of directory +# + +unzip_code = '''" +import tempfile, os, sys, tarfile +tempdir = tempfile.mkdtemp(prefix='distrib-') +os.chdir(tempdir) +tf = tarfile.open(fileobj=sys.stdin, mode='r|gz') +for ti in tf: + tf.extract(ti) +print tempdir +"''' + +def copy_to_remote_temporary_directory(host, files): + p = subprocess.Popen( + ['ssh', host, 'python', '-c', unzip_code], + stdout=subprocess.PIPE, stdin=subprocess.PIPE + ) + tf = tarfile.open(fileobj=p.stdin, mode='w|gz') + for name in files: + tf.add(name, os.path.basename(name)) + tf.close() + p.stdin.close() + return p.stdout.read().rstrip() + +# +# Code which runs a host manager +# + +def main(): + # get data from parent over stdin + data = pickle.load(sys.stdin) + sys.stdin.close() + + # set some stuff + _logger.setLevel(data['dist_log_level']) + forking.prepare(data) + + # create server for a `HostManager` object + server = managers.Server(HostManager._registry, ('', 0), data['authkey']) + current_process()._server = server + + # report server address and number of cpus back to parent + conn = connection.Client(data['parent_address'], authkey=data['authkey']) + conn.send((data['index'], server.address, slot_count)) + conn.close() + + # set name etc + current_process().set_name('Host-%s:%s' % server.address) + util._run_after_forkers() + + # register a cleanup function + def cleanup(directory): + debug('removing directory %s', directory) + shutil.rmtree(directory) + debug('shutting down host manager') + util.Finalize(None, cleanup, args=[data['dir']], exitpriority=0) + + # start host manager + debug('remote host manager starting in %s', data['dir']) + server.serve_forever() From python-checkins at python.org Sat Jan 3 20:20:32 2009 From: python-checkins at python.org (raymond.hettinger) Date: Sat, 3 Jan 2009 20:20:32 +0100 (CET) Subject: [Python-checkins] r68211 - in python/branches/py3k: Doc/library/decimal.rst Lib/decimal.py Lib/test/test_decimal.py Misc/NEWS Message-ID: <20090103192032.89D111E4002@bag.python.org> Author: raymond.hettinger Date: Sat Jan 3 20:20:32 2009 New Revision: 68211 Log: Issue 4796: Add from_float methods to the decimal module. Modified: python/branches/py3k/Doc/library/decimal.rst python/branches/py3k/Lib/decimal.py python/branches/py3k/Lib/test/test_decimal.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Doc/library/decimal.rst ============================================================================== --- python/branches/py3k/Doc/library/decimal.rst (original) +++ python/branches/py3k/Doc/library/decimal.rst Sat Jan 3 20:20:32 2009 @@ -453,6 +453,29 @@ >>> Decimal(321).exp() Decimal('2.561702493119680037517373933E+139') + .. method:: from_float(f) + + Classmethod that converts a float to a decimal number, exactly. + + Note `Decimal.from_float(0.1)` is not the same as `Decimal('0.1')`. + Since 0.1 is not exactly representable in binary floating point, the + value is stored as the nearest representable value which is + `0x1.999999999999ap-4`. That equivalent value in decimal is + `0.1000000000000000055511151231257827021181583404541015625`. + + .. doctest:: + + >>> Decimal.from_float(0.1) + Decimal('0.1000000000000000055511151231257827021181583404541015625') + >>> Decimal.from_float(float('nan')) + Decimal('NaN') + >>> Decimal.from_float(float('inf')) + Decimal('Infinity') + >>> Decimal.from_float(float('-inf')) + Decimal('-Infinity') + + .. versionadded:: 2.7 + .. method:: fma(other, third[, context]) Fused multiply-add. Return self*other+third with no rounding of the @@ -910,6 +933,26 @@ If the argument is a string, no leading or trailing whitespace is permitted. +.. method:: create_decimal_from_float(f) + + Creates a new Decimal instance from a float *f* but rounding using *self* + as the context. Unlike the :method:`Decimal.from_float` class method, + the context precision, rounding method, flags, and traps are applied to + the conversion. + + .. doctest:: + + >>> context = Context(prec=5, rounding=ROUND_DOWN) + >>> context.create_decimal_from_float(math.pi) + Decimal('3.1415') + >>> context = Context(prec=5, traps=[Inexact]) + >>> context.create_decimal_from_float(math.pi) + Traceback (most recent call last): + ... + decimal.Inexact: None + + .. versionadded:: 2.7 + .. method:: Etiny() Returns a value equal to ``Emin - prec + 1`` which is the minimum exponent Modified: python/branches/py3k/Lib/decimal.py ============================================================================== --- python/branches/py3k/Lib/decimal.py (original) +++ python/branches/py3k/Lib/decimal.py Sat Jan 3 20:20:32 2009 @@ -136,6 +136,7 @@ import numbers as _numbers import copy as _copy +import math as _math try: from collections import namedtuple as _namedtuple @@ -654,6 +655,38 @@ raise TypeError("Cannot convert %r to Decimal" % value) + @classmethod + def from_float(cls, f): + """Converts a float to a decimal number, exactly. + + Note that Decimal.from_float(0.1) is not the same as Decimal('0.1'). + Since 0.1 is not exactly representable in binary floating point, the + value is stored as the nearest representable value which is + 0x1.999999999999ap-4. The exact equivalent of the value in decimal + is 0.1000000000000000055511151231257827021181583404541015625. + + >>> Decimal.from_float(0.1) + Decimal('0.1000000000000000055511151231257827021181583404541015625') + >>> Decimal.from_float(float('nan')) + Decimal('NaN') + >>> Decimal.from_float(float('inf')) + Decimal('Infinity') + >>> Decimal.from_float(-float('inf')) + Decimal('-Infinity') + >>> Decimal.from_float(-0.0) + Decimal('-0') + + """ + if isinstance(f, int): # handle integer inputs + return cls(f) + if _math.isinf(f) or _math.isnan(f): # raises TypeError if not a float + return cls(repr(f)) + sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 + n, d = abs(f).as_integer_ratio() + k = d.bit_length() - 1 + result = _dec_from_triple(sign, str(n*5**k), -k) + return result if cls is Decimal else cls(result) + def _isnan(self): """Returns whether the number is not actually one. @@ -3830,6 +3863,23 @@ "diagnostic info too long in NaN") return d._fix(self) + def create_decimal_from_float(self, f): + """Creates a new Decimal instance from a float but rounding using self + as the context. + + >>> context = Context(prec=5, rounding=ROUND_DOWN) + >>> context.create_decimal_from_float(3.1415926535897932) + Decimal('3.1415') + >>> context = Context(prec=5, traps=[Inexact]) + >>> context.create_decimal_from_float(3.1415926535897932) + Traceback (most recent call last): + ... + decimal.Inexact: None + + """ + d = Decimal.from_float(f) # An exact conversion + return d._fix(self) # Apply the context rounding + # Methods def abs(self, a): """Returns the absolute value of the operand. Modified: python/branches/py3k/Lib/test/test_decimal.py ============================================================================== --- python/branches/py3k/Lib/test/test_decimal.py (original) +++ python/branches/py3k/Lib/test/test_decimal.py Sat Jan 3 20:20:32 2009 @@ -1421,6 +1421,55 @@ r = d.to_integral(ROUND_DOWN) self.assertEqual(Decimal(math.trunc(d)), r) + def test_from_float(self): + + class MyDecimal(Decimal): + pass + + r = MyDecimal.from_float(0.1) + self.assertEqual(type(r), MyDecimal) + self.assertEqual(str(r), + '0.1000000000000000055511151231257827021181583404541015625') + bigint = 12345678901234567890123456789 + self.assertEqual(MyDecimal.from_float(bigint), MyDecimal(bigint)) + self.assert_(MyDecimal.from_float(float('nan')).is_qnan()) + self.assert_(MyDecimal.from_float(float('inf')).is_infinite()) + self.assert_(MyDecimal.from_float(float('-inf')).is_infinite()) + self.assertEqual(str(MyDecimal.from_float(float('nan'))), + str(Decimal('NaN'))) + self.assertEqual(str(MyDecimal.from_float(float('inf'))), + str(Decimal('Infinity'))) + self.assertEqual(str(MyDecimal.from_float(float('-inf'))), + str(Decimal('-Infinity'))) + self.assertRaises(TypeError, MyDecimal.from_float, 'abc') + for i in range(200): + x = random.expovariate(0.01) * (random.random() * 2.0 - 1.0) + self.assertEqual(x, float(MyDecimal.from_float(x))) # roundtrip + + def test_create_decimal_from_float(self): + context = Context(prec=5, rounding=ROUND_DOWN) + self.assertEqual( + context.create_decimal_from_float(math.pi), + Decimal('3.1415') + ) + context = Context(prec=5, rounding=ROUND_UP) + self.assertEqual( + context.create_decimal_from_float(math.pi), + Decimal('3.1416') + ) + context = Context(prec=5, traps=[Inexact]) + self.assertRaises( + Inexact, + context.create_decimal_from_float, + math.pi + ) + self.assertEqual(repr(context.create_decimal_from_float(-0.0)), + "Decimal('-0')") + self.assertEqual(repr(context.create_decimal_from_float(1.0)), + "Decimal('1')") + self.assertEqual(repr(context.create_decimal_from_float(10)), + "Decimal('10')") + class ContextAPItests(unittest.TestCase): def test_pickle(self): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Jan 3 20:20:32 2009 @@ -12,8 +12,6 @@ Core and Builtins ----------------- -- Issue #4817: Remove unused function PyOS_GetLastModificationTime. - - Issue #4580: Fix slicing of memoryviews when the item size is greater than one byte. Also fixes the meaning of len() so that it returns the number of items, rather than the size in bytes. @@ -88,6 +86,9 @@ Python 3.x, in accordance with the `official amendments of the spec `_. +- Issue #4796: Added Decimal.from_float() and Context.create_decimal_from_float() + to the decimal module. + - Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) From python-checkins at python.org Sat Jan 3 20:20:37 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 20:20:37 +0100 (CET) Subject: [Python-checkins] r68212 - in python/branches/py3k: Include/memoryobject.h Objects/memoryobject.c Message-ID: <20090103192037.3C6641E4002@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 20:20:36 2009 New Revision: 68212 Log: Issue #4822: fix messy indentation in memoryobject.c/.h, before we may backport it to trunk. Reviewed on IRC by Georg Brandl, with assistance by Benjamin Peterson. Modified: python/branches/py3k/Include/memoryobject.h python/branches/py3k/Objects/memoryobject.c Modified: python/branches/py3k/Include/memoryobject.h ============================================================================== --- python/branches/py3k/Include/memoryobject.h (original) +++ python/branches/py3k/Include/memoryobject.h Sat Jan 3 20:20:36 2009 @@ -20,53 +20,53 @@ int buffertype, char fort); - /* Return a contiguous chunk of memory representing the buffer - from an object in a memory view object. If a copy is made then the - base object for the memory view will be a *new* bytes object. - - Otherwise, the base-object will be the object itself and no - data-copying will be done. - - The buffertype argument can be PyBUF_READ, PyBUF_WRITE, - PyBUF_SHADOW to determine whether the returned buffer - should be READONLY, WRITABLE, or set to update the - original buffer if a copy must be made. If buffertype is - PyBUF_WRITE and the buffer is not contiguous an error will - be raised. In this circumstance, the user can use - PyBUF_SHADOW to ensure that a a writable temporary - contiguous buffer is returned. The contents of this - contiguous buffer will be copied back into the original - object after the memoryview object is deleted as long as - the original object is writable and allows setting an - exclusive write lock. If this is not allowed by the - original object, then a BufferError is raised. - - If the object is multi-dimensional and if fortran is 'F', - the first dimension of the underlying array will vary the - fastest in the buffer. If fortran is 'C', then the last - dimension will vary the fastest (C-style contiguous). If - fortran is 'A', then it does not matter and you will get - whatever the object decides is more efficient. + /* Return a contiguous chunk of memory representing the buffer + from an object in a memory view object. If a copy is made then the + base object for the memory view will be a *new* bytes object. + + Otherwise, the base-object will be the object itself and no + data-copying will be done. + + The buffertype argument can be PyBUF_READ, PyBUF_WRITE, + PyBUF_SHADOW to determine whether the returned buffer + should be READONLY, WRITABLE, or set to update the + original buffer if a copy must be made. If buffertype is + PyBUF_WRITE and the buffer is not contiguous an error will + be raised. In this circumstance, the user can use + PyBUF_SHADOW to ensure that a a writable temporary + contiguous buffer is returned. The contents of this + contiguous buffer will be copied back into the original + object after the memoryview object is deleted as long as + the original object is writable and allows setting an + exclusive write lock. If this is not allowed by the + original object, then a BufferError is raised. + + If the object is multi-dimensional and if fortran is 'F', + the first dimension of the underlying array will vary the + fastest in the buffer. If fortran is 'C', then the last + dimension will vary the fastest (C-style contiguous). If + fortran is 'A', then it does not matter and you will get + whatever the object decides is more efficient. - A new reference is returned that must be DECREF'd when finished. - */ + A new reference is returned that must be DECREF'd when finished. + */ PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); - /* create new if bufptr is NULL - will be a new bytesobject in base */ + /* create new if bufptr is NULL + will be a new bytesobject in base */ + - /* The struct is declared here so that macros can work, but it shouldn't be considered public. Don't access those fields directly, use the macros and functions instead! */ typedef struct { - PyObject_HEAD - PyObject *base; - Py_buffer view; + PyObject_HEAD + PyObject *base; + Py_buffer view; } PyMemoryViewObject; - + #ifdef __cplusplus } Modified: python/branches/py3k/Objects/memoryobject.c ============================================================================== --- python/branches/py3k/Objects/memoryobject.c (original) +++ python/branches/py3k/Objects/memoryobject.c Sat Jan 3 20:20:36 2009 @@ -33,21 +33,21 @@ static int memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags) { - int res = 0; - /* XXX for whatever reason fixing the flags seems necessary */ - if (self->view.readonly) - flags &= ~PyBUF_WRITABLE; - if (self->view.obj != NULL) - res = PyObject_GetBuffer(self->view.obj, view, flags); - if (view) - dup_buffer(view, &self->view); - return res; + int res = 0; + /* XXX for whatever reason fixing the flags seems necessary */ + if (self->view.readonly) + flags &= ~PyBUF_WRITABLE; + if (self->view.obj != NULL) + res = PyObject_GetBuffer(self->view.obj, view, flags); + if (view) + dup_buffer(view, &self->view); + return res; } static void memory_releasebuf(PyMemoryViewObject *self, Py_buffer *view) { - PyBuffer_Release(view); + PyBuffer_Release(view); } PyDoc_STRVAR(memory_doc, @@ -58,61 +58,61 @@ PyObject * PyMemoryView_FromBuffer(Py_buffer *info) { - PyMemoryViewObject *mview; + PyMemoryViewObject *mview; - mview = (PyMemoryViewObject *) - PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); - if (mview == NULL) - return NULL; - mview->base = NULL; - dup_buffer(&mview->view, info); - /* NOTE: mview->view.obj should already have been incref'ed as - part of PyBuffer_FillInfo(). */ - _PyObject_GC_TRACK(mview); - return (PyObject *)mview; + mview = (PyMemoryViewObject *) + PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + if (mview == NULL) + return NULL; + mview->base = NULL; + dup_buffer(&mview->view, info); + /* NOTE: mview->view.obj should already have been incref'ed as + part of PyBuffer_FillInfo(). */ + _PyObject_GC_TRACK(mview); + return (PyObject *)mview; } PyObject * PyMemoryView_FromObject(PyObject *base) { - PyMemoryViewObject *mview; + PyMemoryViewObject *mview; - if (!PyObject_CheckBuffer(base)) { - PyErr_SetString(PyExc_TypeError, - "cannot make memory view because object does " - "not have the buffer interface"); - return NULL; - } + if (!PyObject_CheckBuffer(base)) { + PyErr_SetString(PyExc_TypeError, + "cannot make memory view because object does " + "not have the buffer interface"); + return NULL; + } - mview = (PyMemoryViewObject *) - PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); - if (mview == NULL) - return NULL; - - mview->base = NULL; - if (PyObject_GetBuffer(base, &(mview->view), PyBUF_FULL_RO) < 0) { - Py_DECREF(mview); - return NULL; - } + mview = (PyMemoryViewObject *) + PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + if (mview == NULL) + return NULL; - mview->base = base; - Py_INCREF(base); - _PyObject_GC_TRACK(mview); - return (PyObject *)mview; + mview->base = NULL; + if (PyObject_GetBuffer(base, &(mview->view), PyBUF_FULL_RO) < 0) { + Py_DECREF(mview); + return NULL; + } + + mview->base = base; + Py_INCREF(base); + _PyObject_GC_TRACK(mview); + return (PyObject *)mview; } static PyObject * memory_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { - PyObject *obj; - static char *kwlist[] = {"object", 0}; + PyObject *obj; + static char *kwlist[] = {"object", 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist, - &obj)) { - return NULL; - } + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist, + &obj)) { + return NULL; + } - return PyMemoryView_FromObject(obj); + return PyMemoryView_FromObject(obj); } @@ -120,58 +120,58 @@ _strided_copy_nd(char *dest, char *src, int nd, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fort) { - int k; - Py_ssize_t outstride; + int k; + Py_ssize_t outstride; - if (nd==0) { - memcpy(dest, src, itemsize); + if (nd==0) { + memcpy(dest, src, itemsize); + } + else if (nd == 1) { + for (k = 0; kndim > PY_SSIZE_T_MAX / sizeof(Py_ssize_t)) { - PyErr_NoMemory(); - return -1; - } + if (view->ndim > PY_SSIZE_T_MAX / sizeof(Py_ssize_t)) { + PyErr_NoMemory(); + return -1; + } - indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*view->ndim); - if (indices == NULL) { - PyErr_NoMemory(); - return -1; - } - for (k=0; kndim;k++) { - indices[k] = 0; - } + indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*view->ndim); + if (indices == NULL) { + PyErr_NoMemory(); + return -1; + } + for (k=0; kndim;k++) { + indices[k] = 0; + } - elements = 1; - for (k=0; kndim; k++) { - elements *= view->shape[k]; - } - if (fort == 'F') { - func = _add_one_to_index_F; - } - else { - func = _add_one_to_index_C; - } - while (elements--) { - func(view->ndim, indices, view->shape); - ptr = PyBuffer_GetPointer(view, indices); - memcpy(dest, ptr, view->itemsize); - dest += view->itemsize; - } + elements = 1; + for (k=0; kndim; k++) { + elements *= view->shape[k]; + } + if (fort == 'F') { + func = _add_one_to_index_F; + } + else { + func = _add_one_to_index_C; + } + while (elements--) { + func(view->ndim, indices, view->shape); + ptr = PyBuffer_GetPointer(view, indices); + memcpy(dest, ptr, view->itemsize); + dest += view->itemsize; + } - PyMem_Free(indices); - return 0; + PyMem_Free(indices); + return 0; } /* @@ -240,181 +240,181 @@ the shadow buffer which can be written to and then will be copied back into the other buffer when the memory view is de-allocated. While the shadow buffer is - being used, it will have an exclusive write lock on - the original buffer. + being used, it will have an exclusive write lock on + the original buffer. */ PyObject * PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort) { - PyMemoryViewObject *mem; - PyObject *bytes; - Py_buffer *view; - int flags; - char *dest; - - if (!PyObject_CheckBuffer(obj)) { - PyErr_SetString(PyExc_TypeError, - "object does not have the buffer interface"); - return NULL; - } + PyMemoryViewObject *mem; + PyObject *bytes; + Py_buffer *view; + int flags; + char *dest; - mem = PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); - if (mem == NULL) - return NULL; - - view = &mem->view; - flags = PyBUF_FULL_RO; - switch(buffertype) { - case PyBUF_WRITE: - flags = PyBUF_FULL; - break; - } + if (!PyObject_CheckBuffer(obj)) { + PyErr_SetString(PyExc_TypeError, + "object does not have the buffer interface"); + return NULL; + } - if (PyObject_GetBuffer(obj, view, flags) != 0) { - Py_DECREF(mem); - return NULL; - } + mem = PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + if (mem == NULL) + return NULL; - if (PyBuffer_IsContiguous(view, fort)) { - /* no copy needed */ - Py_INCREF(obj); - mem->base = obj; - _PyObject_GC_TRACK(mem); - return (PyObject *)mem; - } - /* otherwise a copy is needed */ - if (buffertype == PyBUF_WRITE) { - Py_DECREF(mem); - PyErr_SetString(PyExc_BufferError, - "writable contiguous buffer requested " - "for a non-contiguousobject."); - return NULL; - } - bytes = PyBytes_FromStringAndSize(NULL, view->len); - if (bytes == NULL) { - Py_DECREF(mem); - return NULL; - } - dest = PyBytes_AS_STRING(bytes); - /* different copying strategy depending on whether - or not any pointer de-referencing is needed - */ - /* strided or in-direct copy */ - if (view->suboffsets==NULL) { - _strided_copy_nd(dest, view->buf, view->ndim, view->shape, - view->strides, view->itemsize, fort); - } - else { - if (_indirect_copy_nd(dest, view, fort) < 0) { - Py_DECREF(bytes); - Py_DECREF(mem); - return NULL; - } - } - if (buffertype == PyBUF_SHADOW) { - /* return a shadowed memory-view object */ - view->buf = dest; - mem->base = PyTuple_Pack(2, obj, bytes); - Py_DECREF(bytes); - if (mem->base == NULL) { - Py_DECREF(mem); - return NULL; - } + view = &mem->view; + flags = PyBUF_FULL_RO; + switch(buffertype) { + case PyBUF_WRITE: + flags = PyBUF_FULL; + break; + } + + if (PyObject_GetBuffer(obj, view, flags) != 0) { + Py_DECREF(mem); + return NULL; + } + + if (PyBuffer_IsContiguous(view, fort)) { + /* no copy needed */ + Py_INCREF(obj); + mem->base = obj; + _PyObject_GC_TRACK(mem); + return (PyObject *)mem; + } + /* otherwise a copy is needed */ + if (buffertype == PyBUF_WRITE) { + Py_DECREF(mem); + PyErr_SetString(PyExc_BufferError, + "writable contiguous buffer requested " + "for a non-contiguousobject."); + return NULL; + } + bytes = PyBytes_FromStringAndSize(NULL, view->len); + if (bytes == NULL) { + Py_DECREF(mem); + return NULL; + } + dest = PyBytes_AS_STRING(bytes); + /* different copying strategy depending on whether + or not any pointer de-referencing is needed + */ + /* strided or in-direct copy */ + if (view->suboffsets==NULL) { + _strided_copy_nd(dest, view->buf, view->ndim, view->shape, + view->strides, view->itemsize, fort); + } + else { + if (_indirect_copy_nd(dest, view, fort) < 0) { + Py_DECREF(bytes); + Py_DECREF(mem); + return NULL; } - else { - PyBuffer_Release(view); /* XXX ? */ - /* steal the reference */ - mem->base = bytes; + } + if (buffertype == PyBUF_SHADOW) { + /* return a shadowed memory-view object */ + view->buf = dest; + mem->base = PyTuple_Pack(2, obj, bytes); + Py_DECREF(bytes); + if (mem->base == NULL) { + Py_DECREF(mem); + return NULL; } - _PyObject_GC_TRACK(mem); - return (PyObject *)mem; + } + else { + PyBuffer_Release(view); /* XXX ? */ + /* steal the reference */ + mem->base = bytes; + } + _PyObject_GC_TRACK(mem); + return (PyObject *)mem; } static PyObject * memory_format_get(PyMemoryViewObject *self) { - return PyUnicode_FromString(self->view.format); + return PyUnicode_FromString(self->view.format); } static PyObject * memory_itemsize_get(PyMemoryViewObject *self) { - return PyLong_FromSsize_t(self->view.itemsize); + return PyLong_FromSsize_t(self->view.itemsize); } static PyObject * _IntTupleFromSsizet(int len, Py_ssize_t *vals) { - int i; - PyObject *o; - PyObject *intTuple; - - if (vals == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - intTuple = PyTuple_New(len); - if (!intTuple) return NULL; - for(i=0; iview.ndim, self->view.shape); + return _IntTupleFromSsizet(self->view.ndim, self->view.shape); } static PyObject * memory_strides_get(PyMemoryViewObject *self) { - return _IntTupleFromSsizet(self->view.ndim, self->view.strides); + return _IntTupleFromSsizet(self->view.ndim, self->view.strides); } static PyObject * memory_suboffsets_get(PyMemoryViewObject *self) { - return _IntTupleFromSsizet(self->view.ndim, self->view.suboffsets); + return _IntTupleFromSsizet(self->view.ndim, self->view.suboffsets); } static PyObject * memory_readonly_get(PyMemoryViewObject *self) { - return PyBool_FromLong(self->view.readonly); + return PyBool_FromLong(self->view.readonly); } static PyObject * memory_ndim_get(PyMemoryViewObject *self) { - return PyLong_FromLong(self->view.ndim); + return PyLong_FromLong(self->view.ndim); } static PyGetSetDef memory_getsetlist[] ={ - {"format", (getter)memory_format_get, NULL, NULL}, - {"itemsize", (getter)memory_itemsize_get, NULL, NULL}, - {"shape", (getter)memory_shape_get, NULL, NULL}, - {"strides", (getter)memory_strides_get, NULL, NULL}, - {"suboffsets", (getter)memory_suboffsets_get, NULL, NULL}, - {"readonly", (getter)memory_readonly_get, NULL, NULL}, - {"ndim", (getter)memory_ndim_get, NULL, NULL}, - {NULL, NULL, NULL, NULL}, + {"format", (getter)memory_format_get, NULL, NULL}, + {"itemsize", (getter)memory_itemsize_get, NULL, NULL}, + {"shape", (getter)memory_shape_get, NULL, NULL}, + {"strides", (getter)memory_strides_get, NULL, NULL}, + {"suboffsets", (getter)memory_suboffsets_get, NULL, NULL}, + {"readonly", (getter)memory_readonly_get, NULL, NULL}, + {"ndim", (getter)memory_ndim_get, NULL, NULL}, + {NULL, NULL, NULL, NULL}, }; static PyObject * memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs) { - return PyObject_CallFunctionObjArgs( - (PyObject *) &PyBytes_Type, mem, NULL); + return PyObject_CallFunctionObjArgs( + (PyObject *) &PyBytes_Type, mem, NULL); } /* TODO: rewrite this function using the struct module to unpack @@ -423,59 +423,59 @@ static PyObject * memory_tolist(PyMemoryViewObject *mem, PyObject *noargs) { - Py_buffer *view = &(mem->view); - Py_ssize_t i; - PyObject *res, *item; - char *buf; - - if (strcmp(view->format, "B") || view->itemsize != 1) { - PyErr_SetString(PyExc_NotImplementedError, - "tolist() only supports byte views"); - return NULL; - } - if (view->ndim != 1) { - PyErr_SetString(PyExc_NotImplementedError, - "tolist() only supports one-dimensional objects"); - return NULL; - } - res = PyList_New(view->len); - if (res == NULL) - return NULL; - buf = view->buf; - for (i = 0; i < view->len; i++) { - item = PyLong_FromUnsignedLong((unsigned char) *buf); - if (item == NULL) { - Py_DECREF(res); - return NULL; - } - PyList_SET_ITEM(res, i, item); - buf++; - } - return res; + Py_buffer *view = &(mem->view); + Py_ssize_t i; + PyObject *res, *item; + char *buf; + + if (strcmp(view->format, "B") || view->itemsize != 1) { + PyErr_SetString(PyExc_NotImplementedError, + "tolist() only supports byte views"); + return NULL; + } + if (view->ndim != 1) { + PyErr_SetString(PyExc_NotImplementedError, + "tolist() only supports one-dimensional objects"); + return NULL; + } + res = PyList_New(view->len); + if (res == NULL) + return NULL; + buf = view->buf; + for (i = 0; i < view->len; i++) { + item = PyLong_FromUnsignedLong((unsigned char) *buf); + if (item == NULL) { + Py_DECREF(res); + return NULL; + } + PyList_SET_ITEM(res, i, item); + buf++; + } + return res; } static PyMethodDef memory_methods[] = { - {"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, NULL}, - {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, NULL}, - {NULL, NULL} /* sentinel */ + {"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, NULL}, + {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, NULL}, + {NULL, NULL} /* sentinel */ }; static void memory_dealloc(PyMemoryViewObject *self) { - _PyObject_GC_UNTRACK(self); - if (self->view.obj != NULL) { - if (self->base && PyTuple_Check(self->base)) { - /* Special case when first element is generic object - with buffer interface and the second element is a - contiguous "shadow" that must be copied back into - the data areay of the first tuple element before - releasing the buffer on the first element. - */ + _PyObject_GC_UNTRACK(self); + if (self->view.obj != NULL) { + if (self->base && PyTuple_Check(self->base)) { + /* Special case when first element is generic object + with buffer interface and the second element is a + contiguous "shadow" that must be copied back into + the data areay of the first tuple element before + releasing the buffer on the first element. + */ - PyObject_CopyData(PyTuple_GET_ITEM(self->base,0), - PyTuple_GET_ITEM(self->base,1)); + PyObject_CopyData(PyTuple_GET_ITEM(self->base,0), + PyTuple_GET_ITEM(self->base,1)); /* The view member should have readonly == -1 in this instance indicating that the memory can @@ -495,23 +495,23 @@ static PyObject * memory_repr(PyMemoryViewObject *self) { - return PyUnicode_FromFormat("", self); + return PyUnicode_FromFormat("", self); } static PyObject * memory_str(PyMemoryViewObject *self) { - Py_buffer view; - PyObject *res; + Py_buffer view; + PyObject *res; - if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0) - return NULL; + if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0) + return NULL; - res = PyBytes_FromStringAndSize(NULL, view.len); - PyBuffer_ToContiguous(PyBytes_AS_STRING(res), &view, view.len, 'C'); - PyBuffer_Release(&view); - return res; + res = PyBytes_FromStringAndSize(NULL, view.len); + PyBuffer_ToContiguous(PyBytes_AS_STRING(res), &view, view.len, 'C'); + PyBuffer_Release(&view); + return res; } /* Sequence methods */ @@ -524,10 +524,10 @@ /* mem[obj] returns a bytes object holding the data for one element if obj fully indexes the memory view or another memory-view object - if it does not. + if it does not. - 0-d memory-view objects can be referenced using ... or () but - not with anything else. + 0-d memory-view objects can be referenced using ... or () but + not with anything else. */ static PyObject * memory_subscript(PyMemoryViewObject *self, PyObject *key) @@ -536,61 +536,60 @@ view = &(self->view); if (view->ndim == 0) { - if (key == Py_Ellipsis || - (PyTuple_Check(key) && PyTuple_GET_SIZE(key)==0)) { - Py_INCREF(self); - return (PyObject *)self; - } - else { - PyErr_SetString(PyExc_IndexError, - "invalid indexing of 0-dim memory"); - return NULL; - } + if (key == Py_Ellipsis || + (PyTuple_Check(key) && PyTuple_GET_SIZE(key)==0)) { + Py_INCREF(self); + return (PyObject *)self; + } + else { + PyErr_SetString(PyExc_IndexError, + "invalid indexing of 0-dim memory"); + return NULL; + } } if (PyIndex_Check(key)) { - Py_ssize_t result; - result = PyNumber_AsSsize_t(key, NULL); - if (result == -1 && PyErr_Occurred()) - return NULL; - if (view->ndim == 1) { - /* Return a bytes object */ - char *ptr; - ptr = (char *)view->buf; - if (result < 0) { + Py_ssize_t result; + result = PyNumber_AsSsize_t(key, NULL); + if (result == -1 && PyErr_Occurred()) + return NULL; + if (view->ndim == 1) { + /* Return a bytes object */ + char *ptr; + ptr = (char *)view->buf; + if (result < 0) { result += get_shape0(view); - } + } if ((result < 0) || (result >= get_shape0(view))) { - PyErr_SetString(PyExc_IndexError, - "index out of bounds"); - return NULL; - } - if (view->strides == NULL) - ptr += view->itemsize * result; - else - ptr += view->strides[0] * result; - if (view->suboffsets != NULL && - view->suboffsets[0] >= 0) - { - ptr = *((char **)ptr) + view->suboffsets[0]; - } - return PyBytes_FromStringAndSize(ptr, view->itemsize); - } - else { - /* Return a new memory-view object */ - Py_buffer newview; - memset(&newview, 0, sizeof(newview)); - /* XXX: This needs to be fixed so it - actually returns a sub-view - */ - return PyMemoryView_FromBuffer(&newview); - } + PyErr_SetString(PyExc_IndexError, + "index out of bounds"); + return NULL; + } + if (view->strides == NULL) + ptr += view->itemsize * result; + else + ptr += view->strides[0] * result; + if (view->suboffsets != NULL && + view->suboffsets[0] >= 0) { + ptr = *((char **)ptr) + view->suboffsets[0]; + } + return PyBytes_FromStringAndSize(ptr, view->itemsize); + } + else { + /* Return a new memory-view object */ + Py_buffer newview; + memset(&newview, 0, sizeof(newview)); + /* XXX: This needs to be fixed so it + actually returns a sub-view + */ + return PyMemoryView_FromBuffer(&newview); + } } else if (PySlice_Check(key)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx((PySliceObject*)key, get_shape0(view), &start, &stop, &step, &slicelength) < 0) { - return NULL; + return NULL; } if (step == 1 && view->ndim == 1) { @@ -620,8 +619,8 @@ return NULL; } PyErr_Format(PyExc_TypeError, - "cannot index memory using \"%.200s\"", - key->ob_type->tp_name); + "cannot index memory using \"%.200s\"", + key->ob_type->tp_name); return NULL; } @@ -722,118 +721,118 @@ static PyObject * memory_richcompare(PyObject *v, PyObject *w, int op) { - Py_buffer vv, ww; - int equal = 0; - PyObject *res; - - vv.obj = NULL; - ww.obj = NULL; - if (op != Py_EQ && op != Py_NE) - goto _notimpl; - if (PyObject_GetBuffer(v, &vv, PyBUF_CONTIG_RO) == -1) { - PyErr_Clear(); - goto _notimpl; - } - if (PyObject_GetBuffer(w, &ww, PyBUF_CONTIG_RO) == -1) { - PyErr_Clear(); - goto _notimpl; - } + Py_buffer vv, ww; + int equal = 0; + PyObject *res; + + vv.obj = NULL; + ww.obj = NULL; + if (op != Py_EQ && op != Py_NE) + goto _notimpl; + if (PyObject_GetBuffer(v, &vv, PyBUF_CONTIG_RO) == -1) { + PyErr_Clear(); + goto _notimpl; + } + if (PyObject_GetBuffer(w, &ww, PyBUF_CONTIG_RO) == -1) { + PyErr_Clear(); + goto _notimpl; + } - if (vv.itemsize != ww.itemsize || vv.len != ww.len) - goto _end; + if (vv.itemsize != ww.itemsize || vv.len != ww.len) + goto _end; - equal = !memcmp(vv.buf, ww.buf, vv.len); + equal = !memcmp(vv.buf, ww.buf, vv.len); _end: - PyBuffer_Release(&vv); - PyBuffer_Release(&ww); - if ((equal && op == Py_EQ) || (!equal && op == Py_NE)) - res = Py_True; - else - res = Py_False; - Py_INCREF(res); - return res; + PyBuffer_Release(&vv); + PyBuffer_Release(&ww); + if ((equal && op == Py_EQ) || (!equal && op == Py_NE)) + res = Py_True; + else + res = Py_False; + Py_INCREF(res); + return res; _notimpl: - PyBuffer_Release(&vv); - PyBuffer_Release(&ww); - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; + PyBuffer_Release(&vv); + PyBuffer_Release(&ww); + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; } static int memory_traverse(PyMemoryViewObject *self, visitproc visit, void *arg) { - if (self->base != NULL) - Py_VISIT(self->base); - if (self->view.obj != NULL) - Py_VISIT(self->view.obj); - return 0; + if (self->base != NULL) + Py_VISIT(self->base); + if (self->view.obj != NULL) + Py_VISIT(self->view.obj); + return 0; } static int memory_clear(PyMemoryViewObject *self) { - Py_CLEAR(self->base); - PyBuffer_Release(&self->view); - return 0; + Py_CLEAR(self->base); + PyBuffer_Release(&self->view); + return 0; } /* As mapping */ static PyMappingMethods memory_as_mapping = { - (lenfunc)memory_length, /*mp_length*/ - (binaryfunc)memory_subscript, /*mp_subscript*/ - (objobjargproc)memory_ass_sub, /*mp_ass_subscript*/ + (lenfunc)memory_length, /* mp_length */ + (binaryfunc)memory_subscript, /* mp_subscript */ + (objobjargproc)memory_ass_sub, /* mp_ass_subscript */ }; /* Buffer methods */ static PyBufferProcs memory_as_buffer = { - (getbufferproc)memory_getbuf, /* bf_getbuffer */ - (releasebufferproc)memory_releasebuf, /* bf_releasebuffer */ + (getbufferproc)memory_getbuf, /* bf_getbuffer */ + (releasebufferproc)memory_releasebuf, /* bf_releasebuffer */ }; PyTypeObject PyMemoryView_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "memoryview", - sizeof(PyMemoryViewObject), - 0, - (destructor)memory_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)memory_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - &memory_as_mapping, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc)memory_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - &memory_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ - memory_doc, /* tp_doc */ - (traverseproc)memory_traverse, /* tp_traverse */ - (inquiry)memory_clear, /* tp_clear */ - memory_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - memory_methods, /* tp_methods */ - 0, /* tp_members */ - memory_getsetlist, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - memory_new, /* tp_new */ + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "memoryview", + sizeof(PyMemoryViewObject), + 0, + (destructor)memory_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)memory_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + &memory_as_mapping, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc)memory_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + &memory_as_buffer, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + memory_doc, /* tp_doc */ + (traverseproc)memory_traverse, /* tp_traverse */ + (inquiry)memory_clear, /* tp_clear */ + memory_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + memory_methods, /* tp_methods */ + 0, /* tp_members */ + memory_getsetlist, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + memory_new, /* tp_new */ }; From buildbot at python.org Sat Jan 3 20:21:19 2009 From: buildbot at python.org (buildbot at python.org) Date: Sat, 03 Jan 2009 19:21:19 +0000 Subject: [Python-checkins] buildbot failure in i386 Ubuntu 3.0 Message-ID: <20090103192119.69A181E4002@bag.python.org> The Buildbot has detected a new failure of i386 Ubuntu 3.0. Full details are available at: http://www.python.org/dev/buildbot/all/i386%20Ubuntu%203.0/builds/27 Buildbot URL: http://www.python.org/dev/buildbot/all/ Buildslave for this Build: klose-ubuntu-i386 Build Reason: Build Source Stamp: [branch branches/release30-maint] HEAD Blamelist: antoine.pitrou BUILD FAILED: failed test Excerpt from the test logfile: 1 test failed: test_wsgiref ====================================================================== ERROR: testEnviron (test.test_wsgiref.HandlerTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/pybot/buildarea/3.0.klose-ubuntu-i386/build/Lib/test/test_wsgiref.py", line 490, in testEnviron File "/home/pybot/buildarea/3.0.klose-ubuntu-i386/build/Lib/test/test_wsgiref.py", line 482, in checkOSEnviron KeyError: 'NO_PROXY' ====================================================================== ERROR: testBytes (test.test_wsgiref.HeaderTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/pybot/buildarea/3.0.klose-ubuntu-i386/build/Lib/test/test_wsgiref.py", line 427, in testBytes File "/home/pybot/buildarea/3.0.klose-ubuntu-i386/build/Lib/wsgiref/headers.py", line 67, in __setitem__ del self[name] File "/home/pybot/buildarea/3.0.klose-ubuntu-i386/build/Lib/wsgiref/headers.py", line 77, in __delitem__ self._headers[:] = [kv for kv in self._headers if kv[0].lower() != name] File "/home/pybot/buildarea/3.0.klose-ubuntu-i386/build/Lib/wsgiref/headers.py", line 77, in self._headers[:] = [kv for kv in self._headers if kv[0].lower() != name] BytesWarning: Comparison between bytes and string make: *** [buildbottest] Error 1 sincerely, -The Buildbot From python-checkins at python.org Sat Jan 3 20:29:01 2009 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 3 Jan 2009 20:29:01 +0100 (CET) Subject: [Python-checkins] r68213 - in python/branches/release30-maint: Include/memoryobject.h Objects/memoryobject.c Message-ID: <20090103192901.582F81E4002@bag.python.org> Author: antoine.pitrou Date: Sat Jan 3 20:29:00 2009 New Revision: 68213 Log: Merged revisions 68212 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/py3k ........ r68212 | antoine.pitrou | 2009-01-03 20:20:36 +0100 (sam., 03 janv. 2009) | 4 lines Issue #4822: fix messy indentation in memoryobject.c/.h, before we may backport it to trunk. Reviewed on IRC by Georg Brandl, with assistance by Benjamin Peterson. ........ Modified: python/branches/release30-maint/ (props changed) python/branches/release30-maint/Include/memoryobject.h python/branches/release30-maint/Objects/memoryobject.c Modified: python/branches/release30-maint/Include/memoryobject.h ============================================================================== --- python/branches/release30-maint/Include/memoryobject.h (original) +++ python/branches/release30-maint/Include/memoryobject.h Sat Jan 3 20:29:00 2009 @@ -20,53 +20,53 @@ int buffertype, char fort); - /* Return a contiguous chunk of memory representing the buffer - from an object in a memory view object. If a copy is made then the - base object for the memory view will be a *new* bytes object. - - Otherwise, the base-object will be the object itself and no - data-copying will be done. - - The buffertype argument can be PyBUF_READ, PyBUF_WRITE, - PyBUF_SHADOW to determine whether the returned buffer - should be READONLY, WRITABLE, or set to update the - original buffer if a copy must be made. If buffertype is - PyBUF_WRITE and the buffer is not contiguous an error will - be raised. In this circumstance, the user can use - PyBUF_SHADOW to ensure that a a writable temporary - contiguous buffer is returned. The contents of this - contiguous buffer will be copied back into the original - object after the memoryview object is deleted as long as - the original object is writable and allows setting an - exclusive write lock. If this is not allowed by the - original object, then a BufferError is raised. - - If the object is multi-dimensional and if fortran is 'F', - the first dimension of the underlying array will vary the - fastest in the buffer. If fortran is 'C', then the last - dimension will vary the fastest (C-style contiguous). If - fortran is 'A', then it does not matter and you will get - whatever the object decides is more efficient. + /* Return a contiguous chunk of memory representing the buffer + from an object in a memory view object. If a copy is made then the + base object for the memory view will be a *new* bytes object. + + Otherwise, the base-object will be the object itself and no + data-copying will be done. + + The buffertype argument can be PyBUF_READ, PyBUF_WRITE, + PyBUF_SHADOW to determine whether the returned buffer + should be READONLY, WRITABLE, or set to update the + original buffer if a copy must be made. If buffertype is + PyBUF_WRITE and the buffer is not contiguous an error will + be raised. In this circumstance, the user can use + PyBUF_SHADOW to ensure that a a writable temporary + contiguous buffer is returned. The contents of this + contiguous buffer will be copied back into the original + object after the memoryview object is deleted as long as + the original object is writable and allows setting an + exclusive write lock. If this is not allowed by the + original object, then a BufferError is raised. + + If the object is multi-dimensional and if fortran is 'F', + the first dimension of the underlying array will vary the + fastest in the buffer. If fortran is 'C', then the last + dimension will vary the fastest (C-style contiguous). If + fortran is 'A', then it does not matter and you will get + whatever the object decides is more efficient. - A new reference is returned that must be DECREF'd when finished. - */ + A new reference is returned that must be DECREF'd when finished. + */ PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); - /* create new if bufptr is NULL - will be a new bytesobject in base */ + /* create new if bufptr is NULL + will be a new bytesobject in base */ + - /* The struct is declared here so that macros can work, but it shouldn't be considered public. Don't access those fields directly, use the macros and functions instead! */ typedef struct { - PyObject_HEAD - PyObject *base; - Py_buffer view; + PyObject_HEAD + PyObject *base; + Py_buffer view; } PyMemoryViewObject; - + #ifdef __cplusplus } Modified: python/branches/release30-maint/Objects/memoryobject.c ============================================================================== --- python/branches/release30-maint/Objects/memoryobject.c (original) +++ python/branches/release30-maint/Objects/memoryobject.c Sat Jan 3 20:29:00 2009 @@ -33,21 +33,21 @@ static int memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags) { - int res = 0; - /* XXX for whatever reason fixing the flags seems necessary */ - if (self->view.readonly) - flags &= ~PyBUF_WRITABLE; - if (self->view.obj != NULL) - res = PyObject_GetBuffer(self->view.obj, view, flags); - if (view) - dup_buffer(view, &self->view); - return res; + int res = 0; + /* XXX for whatever reason fixing the flags seems necessary */ + if (self->view.readonly) + flags &= ~PyBUF_WRITABLE; + if (self->view.obj != NULL) + res = PyObject_GetBuffer(self->view.obj, view, flags); + if (view) + dup_buffer(view, &self->view); + return res; } static void memory_releasebuf(PyMemoryViewObject *self, Py_buffer *view) { - PyBuffer_Release(view); + PyBuffer_Release(view); } PyDoc_STRVAR(memory_doc, @@ -58,61 +58,61 @@ PyObject * PyMemoryView_FromBuffer(Py_buffer *info) { - PyMemoryViewObject *mview; + PyMemoryViewObject *mview; - mview = (PyMemoryViewObject *) - PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); - if (mview == NULL) - return NULL; - mview->base = NULL; - dup_buffer(&mview->view, info); - /* NOTE: mview->view.obj should already have been incref'ed as - part of PyBuffer_FillInfo(). */ - _PyObject_GC_TRACK(mview); - return (PyObject *)mview; + mview = (PyMemoryViewObject *) + PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + if (mview == NULL) + return NULL; + mview->base = NULL; + dup_buffer(&mview->view, info); + /* NOTE: mview->view.obj should already have been incref'ed as + part of PyBuffer_FillInfo(). */ + _PyObject_GC_TRACK(mview); + return (PyObject *)mview; } PyObject * PyMemoryView_FromObject(PyObject *base) { - PyMemoryViewObject *mview; + PyMemoryViewObject *mview; - if (!PyObject_CheckBuffer(base)) { - PyErr_SetString(PyExc_TypeError, - "cannot make memory view because object does " - "not have the buffer interface"); - return NULL; - } + if (!PyObject_CheckBuffer(base)) { + PyErr_SetString(PyExc_TypeError, + "cannot make memory view because object does " + "not have the buffer interface"); + return NULL; + } - mview = (PyMemoryViewObject *) - PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); - if (mview == NULL) - return NULL; - - mview->base = NULL; - if (PyObject_GetBuffer(base, &(mview->view), PyBUF_FULL_RO) < 0) { - Py_DECREF(mview); - return NULL; - } + mview = (PyMemoryViewObject *) + PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + if (mview == NULL) + return NULL; - mview->base = base; - Py_INCREF(base); - _PyObject_GC_TRACK(mview); - return (PyObject *)mview; + mview->base = NULL; + if (PyObject_GetBuffer(base, &(mview->view), PyBUF_FULL_RO) < 0) { + Py_DECREF(mview); + return NULL; + } + + mview->base = base; + Py_INCREF(base); + _PyObject_GC_TRACK(mview); + return (PyObject *)mview; } static PyObject * memory_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { - PyObject *obj; - static char *kwlist[] = {"object", 0}; + PyObject *obj; + static char *kwlist[] = {"object", 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist, - &obj)) { - return NULL; - } + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist, + &obj)) { + return NULL; + } - return PyMemoryView_FromObject(obj); + return PyMemoryView_FromObject(obj); } @@ -120,58 +120,58 @@ _strided_copy_nd(char *dest, char *src, int nd, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fort) { - int k; - Py_ssize_t outstride; + int k; + Py_ssize_t outstride; - if (nd==0) { - memcpy(dest, src, itemsize); + if (nd==0) { + memcpy(dest, src, itemsize); + } + else if (nd == 1) { + for (k = 0; k