From: Georg Brandl Date: Sat, 3 Jan 2009 23:25:33 +0000 (+0000) Subject: Merged revisions 67653,67655,67682-67683,67724,67755,67780-67783,67786,67789,67841... X-Git-Tag: v3.0.1~194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7167b00542cc1af288c3f09565bb41c436c4d77b;p=thirdparty%2FPython%2Fcpython.git Merged revisions 67653,67655,67682-67683,67724,67755,67780-67783,67786,67789,67841,67843,67865,67881,67884,67925,67929,67931 via svnmerge from svn+ssh://svn.python.org/python/branches/py3k ........ r67653 | neal.norwitz | 2008-12-07 23:42:03 +0100 (Sun, 07 Dec 2008) | 1 line Remove unnecessary import ........ r67655 | georg.brandl | 2008-12-07 23:45:56 +0100 (Sun, 07 Dec 2008) | 2 lines #4586: fix usage of Py_InitModule. ........ r67682 | georg.brandl | 2008-12-10 00:48:44 +0100 (Wed, 10 Dec 2008) | 1 line #4592: fix embedding example with new C API changes. ........ r67683 | fred.drake | 2008-12-10 07:02:39 +0100 (Wed, 10 Dec 2008) | 2 lines simplify imports ........ r67724 | benjamin.peterson | 2008-12-13 04:03:41 +0100 (Sat, 13 Dec 2008) | 1 line string.maketrans -> str.maketrans ........ r67755 | benjamin.peterson | 2008-12-14 16:09:34 +0100 (Sun, 14 Dec 2008) | 1 line tip-toe around dictionary keys view in the tutorial ........ r67780 | jeremy.hylton | 2008-12-15 04:00:50 +0100 (Mon, 15 Dec 2008) | 2 lines Use True/False for ints instead of 1/0. That's so Python 2.0. ........ r67781 | jeremy.hylton | 2008-12-15 04:08:30 +0100 (Mon, 15 Dec 2008) | 2 lines Reflow long line. ........ r67782 | georg.brandl | 2008-12-15 09:28:37 +0100 (Mon, 15 Dec 2008) | 2 lines #4667: fix some 2.x leftovers in the tutorial. ........ r67783 | georg.brandl | 2008-12-15 09:29:32 +0100 (Mon, 15 Dec 2008) | 2 lines #4668: wrap iterator returns in list() in functional howto. ........ r67786 | georg.brandl | 2008-12-15 09:43:10 +0100 (Mon, 15 Dec 2008) | 2 lines #4603: Note that inconsistent tab/space use is now illegal. ........ r67789 | georg.brandl | 2008-12-15 10:16:15 +0100 (Mon, 15 Dec 2008) | 2 lines Use :samp: role. ........ r67841 | kristjan.jonsson | 2008-12-18 18:08:57 +0100 (Thu, 18 Dec 2008) | 2 lines Add missing Py_CHARMASK when calling isspace(). Found by enabling runtime tests on windows, by disabling the _set_invalid_parameter_handler() fiddling. ........ r67843 | kristjan.jonsson | 2008-12-18 18:15:54 +0100 (Thu, 18 Dec 2008) | 5 lines Fix an issue in the tokenizer, where a file is opened by fd, but the underlying PyFileIO object wasn created with the closefd attribute true. Also fix error handling for close() int _fileio.c . It was incorrect, looking for a negative refcount, and so errors weren't raised. This is why this issue wasn't caught. There is a second reason why it isn't seen: Class IOBase in io.py has a try:/except: around the close() funtion in the __del__() method. This also masks these error conditions. This issue was discovered by removing the _set_invalid_parameter_handler() fiddling, thus enabling the C runtime checks on windows. ........ r67865 | benjamin.peterson | 2008-12-20 04:20:23 +0100 (Sat, 20 Dec 2008) | 1 line fix syntax ........ r67881 | benjamin.peterson | 2008-12-20 23:50:25 +0100 (Sat, 20 Dec 2008) | 1 line unpy3kize this; it require 2.x only Mac modules ........ r67884 | benjamin.peterson | 2008-12-21 00:06:29 +0100 (Sun, 21 Dec 2008) | 1 line don't build bsddb anymore ........ r67925 | benjamin.peterson | 2008-12-24 17:27:25 +0100 (Wed, 24 Dec 2008) | 1 line return the module object from PyMODINIT_FUNC ........ r67929 | benjamin.peterson | 2008-12-27 03:58:34 +0100 (Sat, 27 Dec 2008) | 1 line string -> bytes in error message #4745 ........ r67931 | hirokazu.yamamoto | 2008-12-27 05:21:44 +0100 (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) ........ --- diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst index c86ae8ab2a31..5c4fde84644c 100644 --- a/Doc/extending/embedding.rst +++ b/Doc/extending/embedding.rst @@ -218,11 +218,22 @@ Python extension. For example:: {NULL, NULL, 0, NULL} }; + static PyModuleDef EmbModule = { + PyModuleDef_HEAD_INIT, "emb", NULL, -1, EmbMethods, + NULL, NULL, NULL, NULL + }; + + static PyObject* + PyInit_emb(void) + { + return PyModule_Create(&EmbModule); + } + Insert the above code just above the :cfunc:`main` function. Also, insert the -following two statements directly after :cfunc:`Py_Initialize`:: +following two statements before the call to :cfunc:`Py_Initialize`:: numargs = argc; - Py_InitModule("emb", EmbMethods); + PyImport_AppendInittab("emb", &PyInit_emb); These two lines initialize the ``numargs`` variable, and make the :func:`emb.numargs` function accessible to the embedded Python interpreter. diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 8425ff476be3..17a8110961b2 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -326,8 +326,8 @@ only non-\ ``static`` item defined in the module file:: 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, @@ -342,7 +342,7 @@ satisfactorily. The init function must return the module object to its caller, so that it then gets inserted into ``sys.modules``. When embedding Python, the :cfunc:`PyInit_spam` function is not called -automatically unless there's an entry in the :cdata:`_PyImport_Inittab` table. +automatically unless there's an entry in the :cdata:`PyImport_Inittab` table. To add the module to the initialization table, use :cfunc:`PyImport_AppendInittab`, optionally followed by an import of the module:: diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst index ab77a231844e..1d9b42d7b6c4 100644 --- a/Doc/howto/functional.rst +++ b/Doc/howto/functional.rst @@ -634,7 +634,7 @@ features of generator expressions: ... return s.upper() - >>> map(upper, ['sentence', 'fragment']) + >>> list(map(upper, ['sentence', 'fragment'])) ['SENTENCE', 'FRAGMENT'] >>> [upper(s) for s in ['sentence', 'fragment']] ['SENTENCE', 'FRAGMENT'] @@ -650,7 +650,7 @@ value. >>> def is_even(x): ... return (x % 2) == 0 - >>> filter(is_even, range(10)) + >>> list(filter(is_even, range(10))) [0, 2, 4, 6, 8] diff --git a/Doc/includes/noddy.c b/Doc/includes/noddy.c index 26a49a912187..b6b7d6feda33 100644 --- a/Doc/includes/noddy.c +++ b/Doc/includes/noddy.c @@ -52,4 +52,5 @@ PyInit_noddy(void) Py_INCREF(&noddy_NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); + return m; } diff --git a/Doc/includes/noddy2.c b/Doc/includes/noddy2.c index 5daecf9d8aca..db9c7a88d524 100644 --- a/Doc/includes/noddy2.c +++ b/Doc/includes/noddy2.c @@ -186,4 +186,5 @@ PyInit_noddy2(void) Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); + return m; } diff --git a/Doc/includes/noddy3.c b/Doc/includes/noddy3.c index 39cdfdbea3eb..e98b87fdd395 100644 --- a/Doc/includes/noddy3.c +++ b/Doc/includes/noddy3.c @@ -239,4 +239,5 @@ PyInit_noddy3(void) Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); + return m; } diff --git a/Doc/includes/noddy4.c b/Doc/includes/noddy4.c index 94507ecf82ea..5be00a796a96 100644 --- a/Doc/includes/noddy4.c +++ b/Doc/includes/noddy4.c @@ -221,4 +221,5 @@ PyInit_noddy4(void) Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); + return m; } diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 03807489e9d2..877d9b66ecad 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -289,7 +289,7 @@ are always available. They are listed here in alphabetical order. :func:`enumerate` is useful for obtaining an indexed series: ``(0, seq[0])``, ``(1, seq[1])``, ``(2, seq[2])``, .... For example: - >>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter')]: + >>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter']): ... print(i, season) 0 Spring 1 Summer diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 5668623ed345..68e8dbafdb3a 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1090,12 +1090,9 @@ functions based on regular expressions. ordinals, strings or ``None``. Unmapped characters are left untouched. Characters mapped to ``None`` are deleted. - A *map* for :meth:`translate` is usually best created by - :meth:`str.maketrans`. - - You can use the :func:`maketrans` helper function in the :mod:`string` module 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 table. For string + objects, set the *table* argument to ``None`` for translations that only + delete characters: .. note:: diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 1e4312858210..83d3b8ba2d08 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -174,14 +174,18 @@ Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements. -First, tabs are replaced (from left to right) by one to eight spaces such that -the total number of characters up to and including the replacement is a multiple -of eight (this is intended to be the same rule as used by Unix). The total -number of spaces preceding the first non-blank character then determines the -line's indentation. Indentation cannot be split over multiple physical lines -using backslashes; the whitespace up to the first backslash determines the +Tabs are replaced (from left to right) by one to eight spaces such that the +total number of characters up to and including the replacement is a multiple of +eight (this is intended to be the same rule as used by Unix). The total number +of spaces preceding the first non-blank character then determines the line's +indentation. Indentation cannot be split over multiple physical lines using +backslashes; the whitespace up to the first backslash determines the indentation. +Indentation is rejected as inconsistent if a source file mixes tabs and spaces +in a way that makes the meaning dependent on the worth of a tab in spaces; a +:exc:`TabError` is raised in that case. + **Cross-platform compatibility note:** because of the nature of text editors on non-UNIX platforms, it is unwise to use a mixture of spaces and tabs for the indentation in a single source file. It should also be noted that different diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index 84e731d90b28..ca6de17ba0d0 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -440,9 +440,9 @@ pair with ``del``. If you store using a key that is already in use, the old value associated with that key is forgotten. It is an error to extract a value using a non-existent key. -The :meth:`keys` method of a dictionary object returns a list of all the keys +Performing ``list(d.keys())`` on a dictionary returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just apply -the :meth:`sort` method to the list of keys). To check whether a single key is +the :meth:`sorted` function instead). To check whether a single key is in the dictionary, use the :keyword:`in` keyword. Here is a small example using a dictionary:: @@ -458,6 +458,8 @@ Here is a small example using a dictionary:: >>> tel {'guido': 4127, 'irv': 4127, 'jack': 4098} >>> list(tel.keys()) + ['irv', 'guido', 'jack'] + >>> sorted(tel.keys()) ['guido', 'irv', 'jack'] >>> 'guido' in tel True diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index 1b3cbc556e1c..aca553dbc22c 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -112,7 +112,7 @@ you have already defined. For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter -- or, if it's just one module you want to test interactively, - use :func:`reload`, e.g. ``reload(modulename)``. + use :func:`imp.reload`, e.g. ``import imp; imp.reload(modulename)``. .. _tut-modulesasscripts: diff --git a/Doc/whatsnew/3.0.rst b/Doc/whatsnew/3.0.rst index f2d936203981..678ad805be84 100644 --- a/Doc/whatsnew/3.0.rst +++ b/Doc/whatsnew/3.0.rst @@ -696,15 +696,15 @@ new powerful features added: * Exceptions no longer behave as sequences. Use the :attr:`args` attribute instead. -* :pep:`3109`: Raising exceptions. You must now use :keyword:`raise` - *Exception*(*args*) instead of :keyword:`raise` *Exception*, *args*. +* :pep:`3109`: Raising exceptions. You must now use :samp:`raise + {Exception}({args})` instead of :samp:`raise {Exception}, {args}`. Additionally, you can no longer explicitly specify a traceback; instead, if you *have* to do this, you can assign directly to the :attr:`__traceback__` attribute (see below). * :pep:`3110`: Catching exceptions. You must now use - :keyword:`except` *SomeException* :keyword:`as` *variable* instead - of :keyword:`except` *SomeException*, *variable*. Moreover, the + :samp:`except {SomeException} as {variable}` instead + of :samp:`except {SomeException}, {variable}`. Moreover, the *variable* is explicitly deleted when the :keyword:`except` block is left. diff --git a/Lib/http/client.py b/Lib/http/client.py index 99d560e4322f..34bf6a9395c3 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -359,8 +359,8 @@ class HTTPResponse: if self.version == 9: self.length = None - self.chunked = 0 - self.will_close = 1 + self.chunked = False + self.will_close = True self.msg = email.message_from_string('') return @@ -373,10 +373,10 @@ class HTTPResponse: # are we using the chunked-style of transfer encoding? tr_enc = self.msg.get("transfer-encoding") if tr_enc and tr_enc.lower() == "chunked": - self.chunked = 1 + self.chunked = True self.chunk_left = None else: - self.chunked = 0 + self.chunked = False # will the connection close at the end of the response? self.will_close = self._check_close() @@ -411,7 +411,7 @@ class HTTPResponse: if (not self.will_close and not self.chunked and self.length is None): - self.will_close = 1 + self.will_close = True def _check_close(self): conn = self.msg.get("connection") diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 5a505de7ec29..2b80a7d04105 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -7,7 +7,7 @@ import unittest 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 @@ class BaseTest(unittest.TestCase): 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 @@ class BaseTest(unittest.TestCase): 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)) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 1ac43dad27bf..7af0803e5d94 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -375,7 +375,7 @@ class TestBasic(unittest.TestCase): 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)) @@ -384,7 +384,7 @@ class TestBasic(unittest.TestCase): ## 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])) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 054825a5a330..591f95684d97 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -188,7 +188,8 @@ class BasicTest(TestCase): resp.close() def test_negative_content_length(self): - sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: -1\r\n\r\nHello\r\n') + sock = FakeSocket( + 'HTTP/1.1 200 OK\r\nContent-Length: -1\r\n\r\nHello\r\n') resp = httplib.HTTPResponse(sock, method="GET") resp.begin() self.assertEquals(resp.read(), b'Hello\r\n') diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 07319fc20d1c..da3ed0f53a66 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -219,7 +219,7 @@ class TestJointOps(unittest.TestCase): 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)) diff --git a/Lib/traceback.py b/Lib/traceback.py index fac73c4b3e7e..b028db071738 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -2,7 +2,6 @@ import linecache import sys -import types __all__ = ['extract_stack', 'extract_tb', 'format_exception', 'format_exception_only', 'format_list', 'format_stack', diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py index 39f9b99390c4..fb227fec8d0a 100644 --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -2,6 +2,7 @@ """Interfaces for launching and remotely controlling Web browsers.""" # Maintained by Georg Brandl. +import io import os import shlex import sys @@ -223,7 +224,6 @@ class UnixBrowser(BaseBrowser): cmdline = [self.name] + raise_opt + args if remote or self.background: - import io inout = io.open(os.devnull, "r+") else: # for TTY browsers, we need stdin/out @@ -348,7 +348,6 @@ class Konqueror(BaseBrowser): else: action = "openURL" - import io devnull = io.open(os.devnull, "r+") # if possible, put browser in separate process group, so # keyboard interrupts don't affect browser as well as Python diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index abc29dc9f3da..dd606d947faa 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -9,8 +9,7 @@ bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4) 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 @@ def getFullVersion(): 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 @@ LIBRARY_RECIPES = [ 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', - ] - ), ] @@ -298,7 +286,7 @@ def runCommand(commandline): 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() @@ -309,7 +297,7 @@ def captureCommand(commandline): 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 @@ -342,17 +330,17 @@ def parseOptions(args=None): 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'): @@ -368,19 +356,19 @@ def parseOptions(args=None): 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 "" @@ -425,7 +413,7 @@ def extractArchive(builddir, archiveName): 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) @@ -447,9 +435,9 @@ def downloadURL(url, fname): 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: @@ -486,14 +474,14 @@ def buildRecipe(recipe, basedir, archList): 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) @@ -556,14 +544,14 @@ def buildRecipe(recipe, basedir, archList): 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) @@ -571,9 +559,9 @@ def buildLibraries(): """ 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')) @@ -587,7 +575,7 @@ def buildLibraries(): 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') @@ -596,13 +584,13 @@ def buildPythonDocs(): 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) @@ -613,7 +601,7 @@ def buildPythonDocs(): 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') @@ -636,24 +624,24 @@ def buildPython(): # 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( @@ -664,7 +652,7 @@ def buildPython(): '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 @@ -760,7 +748,7 @@ def packageFromRecipe(targetDir, recipe): 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( @@ -1063,9 +1051,9 @@ def main(): 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. diff --git a/Modules/_fileio.c b/Modules/_fileio.c index c23d5a3c1636..b892993ae9ad 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -55,20 +55,27 @@ PyTypeObject PyFileIO_Type; #define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type)) -/* Returns 0 on success, errno (which is < 0) on failure. */ +/* Returns 0 on success, -1 with exception set on failure. */ static int internal_close(PyFileIOObject *self) { - int save_errno = 0; + int err = 0; + int save_errno; if (self->fd >= 0) { int fd = self->fd; self->fd = -1; Py_BEGIN_ALLOW_THREADS - if (close(fd) < 0) + err = close(fd); + if (err < 0) save_errno = errno; Py_END_ALLOW_THREADS } - return save_errno; + if (err < 0) { + errno = save_errno; + PyErr_SetFromErrno(PyExc_IOError); + return -1; + } + return 0; } static PyObject * @@ -78,11 +85,8 @@ fileio_close(PyFileIOObject *self) self->fd = -1; Py_RETURN_NONE; } - errno = internal_close(self); - if (errno < 0) { - PyErr_SetFromErrno(PyExc_IOError); + if (internal_close(self)) return NULL; - } Py_RETURN_NONE; } @@ -121,7 +125,8 @@ dircheck(PyFileIOObject* self) if (fstat(self->fd, &buf) == 0 && S_ISDIR(buf.st_mode)) { char *msg = strerror(EISDIR); PyObject *exc; - internal_close(self); + if (internal_close(self)) + return -1; exc = PyObject_CallFunction(PyExc_IOError, "(is)", EISDIR, msg); @@ -306,11 +311,8 @@ fileio_dealloc(PyFileIOObject *self) PyObject_ClearWeakRefs((PyObject *) self); if (self->fd >= 0 && self->closefd) { - errno = internal_close(self); - if (errno < 0) { - PySys_WriteStderr("close failed: [Errno %d] %s\n", - errno, strerror(errno)); - } + if(internal_close(self)) + PyErr_WriteUnraisable((PyObject*)self); } Py_TYPE(self)->tp_free((PyObject *)self); diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 89eac6466d11..20c1eef01468 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1238,7 +1238,7 @@ float_fromhex(PyObject *cls, PyObject *arg) ********************/ /* leading whitespace and optional sign */ - while (isspace(*s)) + while (isspace(Py_CHARMASK(*s))) s++; if (*s == '-') { s++; @@ -1308,7 +1308,7 @@ float_fromhex(PyObject *cls, PyObject *arg) exp = 0; /* optional trailing whitespace leading to the end of the string */ - while (isspace(*s)) + while (isspace(Py_CHARMASK(*s))) s++; if (s != s_end) goto parse_error; diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index ce8129ddd123..3d52bedc0e67 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -452,8 +452,8 @@ fp_setreadl(struct tok_state *tok, const char* enc) stream = PyObject_CallMethod(io, "open", "ssis", tok->filename, "r", -1, enc); else - stream = PyObject_CallMethod(io, "open", "isis", - fileno(tok->fp), "r", -1, enc); + stream = PyObject_CallMethod(io, "open", "isisOOO", + fileno(tok->fp), "r", -1, enc, Py_None, Py_None, Py_False); if (stream == NULL) goto cleanup; diff --git a/Python/getargs.c b/Python/getargs.c index a63aa43641d5..3ab59b3e42d8 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1392,7 +1392,7 @@ getbuffer(PyObject *arg, Py_buffer *view, char **errmsg) 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) {