diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Doc/library/http.client.rst --- a/Doc/library/http.client.rst Tue Mar 19 16:26:19 2013 -0400 +++ b/Doc/library/http.client.rst Tue Mar 19 01:20:20 2013 -0400 @@ -51,10 +51,6 @@ .. versionchanged:: 3.2 *source_address* was added. - .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9-style "Simple Responses" are - not supported. - .. class:: HTTPSConnection(host, port=None, key_file=None, \ cert_file=None[, timeout], \ @@ -89,20 +85,12 @@ This class now supports HTTPS virtual hosts if possible (that is, if :data:`ssl.HAS_SNI` is true). - .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9-style "Simple Responses" are - not supported anymore. - .. class:: HTTPResponse(sock, debuglevel=0, method=None, url=None) Class whose instances are returned upon successful connection. Not instantiated directly by user. - .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9 style "Simple Responses" are - not supported anymore. - The following exceptions are raised as appropriate: diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/difflib.py --- a/Lib/difflib.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/difflib.py Tue Mar 19 01:20:20 2013 -0400 @@ -1135,6 +1135,33 @@ return ch in ws +def _check_types(a, b, fromfile, tofile): + if (not a or isinstance(a[0], str)) and (not b or isinstance(b[0], str)): + if not (isinstance(fromfile, str) and isinstance(tofile, str)): + raise TypeError('fromfile and tofile must be str ' + '(because a and b contain str)') + def encode(s): + return s + return encode, a, b, fromfile, tofile + + if a and b and type(a[0]) is not type(b[0]): + raise TypeError('a and b must be lists of the same type (str or bytes)') + + # both a and b are lists of something other than str, which we presume + # to be bytes + def decode(s): + if isinstance(s, bytes): + return s.decode('ascii', 'surrogateescape') + return s + def encode(s): + return s.encode('ascii', 'surrogateescape') + + a = list(map(decode, a)) + b = list(map(decode, b)) + fromfile = decode(fromfile) + tofile = decode(tofile) + return encode, a, b, fromfile, tofile + ######################################################################## ### Unified Diff @@ -1155,6 +1182,8 @@ tofiledate='', n=3, lineterm='\n'): r""" Compare two sequences of lines; generate the delta as a unified diff. + Lines may be either str or bytes, but types must be consistent between + 'a' and 'b'. Unified diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which @@ -1171,8 +1200,10 @@ The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for - 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. - The modification times are normally expressed in the ISO 8601 format. + 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. If 'a' and 'b' + are lists of bytes objects, then 'fromfile' and 'tofile' may be either + str or bytes. The modification times are normally expressed in the ISO + 8601 format, and should use only ASCII characters. Example: @@ -1192,31 +1223,32 @@ four """ + encode, a, b, fromfile, tofile = _check_types(a, b, fromfile, tofile) started = False for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' todate = '\t{}'.format(tofiledate) if tofiledate else '' - yield '--- {}{}{}'.format(fromfile, fromdate, lineterm) - yield '+++ {}{}{}'.format(tofile, todate, lineterm) + yield encode('--- {}{}{}'.format(fromfile, fromdate, lineterm)) + yield encode('+++ {}{}{}'.format(tofile, todate, lineterm)) first, last = group[0], group[-1] file1_range = _format_range_unified(first[1], last[2]) file2_range = _format_range_unified(first[3], last[4]) - yield '@@ -{} +{} @@{}'.format(file1_range, file2_range, lineterm) + yield encode('@@ -{} +{} @@{}'.format(file1_range, file2_range, lineterm)) for tag, i1, i2, j1, j2 in group: if tag == 'equal': for line in a[i1:i2]: - yield ' ' + line + yield encode(' ' + line) continue if tag in {'replace', 'delete'}: for line in a[i1:i2]: - yield '-' + line + yield encode('-' + line) if tag in {'replace', 'insert'}: for line in b[j1:j2]: - yield '+' + line + yield encode('+' + line) ######################################################################## @@ -1239,6 +1271,8 @@ fromfiledate='', tofiledate='', n=3, lineterm='\n'): r""" Compare two sequences of lines; generate the delta as a context diff. + Lines may be either str or bytes, but types must be consistent between + 'a' and 'b'. Context diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which @@ -1256,8 +1290,10 @@ The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. - The modification times are normally expressed in the ISO 8601 format. - If not specified, the strings default to blanks. + If 'a' and 'b' are lists of bytes objects, then 'fromfile' and + 'tofile' may be either str or bytes. The modification times are + normally expressed in the ISO 8601 format, and should use only ASCII + characters. If not specified, the strings default to blanks. Example: @@ -1279,6 +1315,7 @@ four """ + encode, a, b, fromfile, tofile = _check_types(a, b, fromfile, tofile) prefix = dict(insert='+ ', delete='- ', replace='! ', equal=' ') started = False for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): @@ -1286,29 +1323,29 @@ started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' todate = '\t{}'.format(tofiledate) if tofiledate else '' - yield '*** {}{}{}'.format(fromfile, fromdate, lineterm) - yield '--- {}{}{}'.format(tofile, todate, lineterm) + yield encode('*** {}{}{}'.format(fromfile, fromdate, lineterm)) + yield encode('--- {}{}{}'.format(tofile, todate, lineterm)) first, last = group[0], group[-1] - yield '***************' + lineterm + yield encode('***************' + lineterm) file1_range = _format_range_context(first[1], last[2]) - yield '*** {} ****{}'.format(file1_range, lineterm) + yield encode('*** {} ****{}'.format(file1_range, lineterm)) if any(tag in {'replace', 'delete'} for tag, _, _, _, _ in group): for tag, i1, i2, _, _ in group: if tag != 'insert': for line in a[i1:i2]: - yield prefix[tag] + line + yield encode(prefix[tag] + line) file2_range = _format_range_context(first[3], last[4]) - yield '--- {} ----{}'.format(file2_range, lineterm) + yield encode('--- {} ----{}'.format(file2_range, lineterm)) if any(tag in {'replace', 'insert'} for tag, _, _, _, _ in group): for tag, _, _, j1, j2 in group: if tag != 'delete': for line in b[j1:j2]: - yield prefix[tag] + line + yield encode(prefix[tag] + line) def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): r""" diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/imaplib.py --- a/Lib/imaplib.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/imaplib.py Tue Mar 19 01:20:20 2013 -0400 @@ -24,8 +24,6 @@ import binascii, errno, random, re, socket, subprocess, sys, time, calendar from datetime import datetime, timezone, timedelta -from io import DEFAULT_BUFFER_SIZE - try: import ssl HAVE_SSL = True @@ -1246,7 +1244,6 @@ self.sock = None self.file = None self.process = subprocess.Popen(self.command, - bufsize=DEFAULT_BUFFER_SIZE, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, close_fds=True) self.writefile = self.process.stdin diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/pydoc.py --- a/Lib/pydoc.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/pydoc.py Tue Mar 19 01:20:20 2013 -0400 @@ -132,10 +132,7 @@ return _re_stripid.sub(r'\1', text) def _is_some_method(obj): - return (inspect.isfunction(obj) or - inspect.ismethod(obj) or - inspect.isbuiltin(obj) or - inspect.ismethoddescriptor(obj)) + return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj) def allmethods(cl): methods = {} diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/test/test_difflib.py --- a/Lib/test/test_difflib.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/test/test_difflib.py Tue Mar 19 01:20:20 2013 -0400 @@ -278,12 +278,148 @@ self.assertEqual(fmt(0,0), '0') +class TestBytes(unittest.TestCase): + # don't really care about the content of the output, just the fact + # that it's bytes and we don't crash + def check(self, diff): + diff = list(diff) # trigger exceptions first + for line in diff: + self.assertTrue( + isinstance(line, bytes), + "all lines of diff should be bytes, but got: %r" % line) + + def test_byte_content(self): + "if we receive byte strings, we return byte strings" + a = [b'hello', b'andrew'] + b = [b'hello', b'andr\xe9'] # latin-1 bytes + + check = self.check + check(difflib.unified_diff(a, a)) + check(difflib.unified_diff(a, b)) + + # now with filenames (content and filenames are all bytes!) + check(difflib.unified_diff(a, a, b'a', b'a')) + check(difflib.unified_diff(a, b, b'a', b'b')) + + # and with filenames and dates + check(difflib.unified_diff(a, a, b'a', b'a', b'2005', b'2013')) + check(difflib.unified_diff(a, b, b'a', b'b', b'2005', b'2013')) + + # same all over again, with context diff + check(difflib.context_diff(a, a)) + check(difflib.context_diff(a, b)) + check(difflib.context_diff(a, a, b'a', b'a')) + check(difflib.context_diff(a, b, b'a', b'b')) + check(difflib.context_diff(a, a, b'a', b'a', b'2005', b'2013')) + check(difflib.context_diff(a, b, b'a', b'b', b'2005', b'2013')) + + def test_byte_filenames(self): + # somebody renamed a file from ISO-8859-2 to UTF-8 + fna = b'\xb3odz.txt' # "łodz.txt" + fnb = b'\xc5\x82odz.txt' + + # they transcoded the content at the same time + a = [b'\xa3odz is a city in Poland.'] + b = [b'\xc5\x81odz is a city in Poland.'] + + check = self.check + check(difflib.unified_diff(a, b, fna, fnb)) + check(difflib.context_diff(a, b, fna, fnb)) + + def assertDiff(expect, actual): + # do not compare expect and equal as lists, because unittest + # uses difflib to report difference between lists + actual = list(actual) + self.assertEqual(len(expect), len(actual)) + for e, a in zip(expect, actual): + self.assertEqual(e, a) + + expect = [ + b'--- \xb3odz.txt', + b'+++ \xc5\x82odz.txt', + b'@@ -1 +1 @@', + b'-\xa3odz is a city in Poland.', + b'+\xc5\x81odz is a city in Poland.', + ] + actual = difflib.unified_diff(a, b, fna, fnb, lineterm='') + assertDiff(expect, actual) + + # with dates (plain ASCII) + datea = '2005-03-18' + dateb = '2005-03-19' + check(difflib.unified_diff(a, b, fna, fnb, datea, dateb)) + check(difflib.context_diff(a, b, fna, fnb, datea, dateb)) + + expect = [ + # note the mixed encodings here: this is deeply wrong by every + # tenet of Unicode, but it doesn't crash and it should be + # parseable by patch (IOW, it's how Unix diff behaves) + b'--- \xb3odz.txt\t2005-03-18', + b'+++ \xc5\x82odz.txt\t2005-03-19', + b'@@ -1 +1 @@', + b'-\xa3odz is a city in Poland.', + b'+\xc5\x81odz is a city in Poland.', + ] + actual = difflib.unified_diff(a, b, fna, fnb, datea, dateb, lineterm='') + assertDiff(expect, actual) + + def test_bytes_filenames_bad(self): + 'cannot pass filenames as bytes if content is str' + # this may not be the right behaviour, but at least the test + # demonstrates how things work + a = ["hello\n"] + b = ["ohell\n"] + fna = b'ol\xe9.txt' # filename transcoded from ISO-8859-1 + fnb = b'ol\xc3a9.txt' # to UTF-8 + try: + list(difflib.unified_diff(a, b, fna, fnb)) + self.fail('expected TypeError') + except TypeError: + pass + + def test_non_ascii_dates(self): + # this isn't necessarily desirable behaviour, but it demonstrates + # exactly how it works (possibly an unexpected side-effect of bytes + # input) + a = [b'foo\n'] + b = [b'bar\n'] + datea = '1 fév' + dateb = '3 fév' + try: + list(difflib.unified_diff(a, b, 'a', 'b', datea, dateb)) + self.fail('expected ValueError') + except UnicodeEncodeError: + pass + + # if input is str, non-ASCII dates are fine (nice feature, but I + # hate the inconsistency) + a = ['foo\n'] + b = ['bar\n'] + list(difflib.unified_diff(a, b, 'a', 'b', datea, dateb)) + + def test_mixed_types(self): + "input types must be consistent: all str or all bytes" + a = [b"hello"] + b = ["hello"] + + try: + list(difflib.unified_diff(a, b)) + self.fail("expected TypeError") + except TypeError: + pass + + try: + list(difflib.unified_diff(b, a)) + self.fail("expected TypeError") + except TypeError: + pass + def test_main(): difflib.HtmlDiff._default_prefix = 0 Doctests = doctest.DocTestSuite(difflib) run_unittest( TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs, - TestOutputFormat, Doctests) + TestOutputFormat, TestBytes, Doctests) if __name__ == '__main__': test_main() diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/test/test_pydoc.py Tue Mar 19 01:20:20 2013 -0400 @@ -420,30 +420,6 @@ self.assertTrue(pydoc.ispackage(test_dir)) os.remove(init_path) - def test_allmethods(self): - # issue 17476: allmethods was no longer returning unbound methods. - # This test is a bit fragile in the face of changes to object and type, - # but I can't think of a better way to do it without duplicating the - # logic of the function under test. - - class TestClass(object): - def method_returning_true(self): - return True - - # What we expect to get back: everything on object... - expected = dict(vars(object)) - # ...plus our unbound method... - expected['method_returning_true'] = TestClass.method_returning_true - # ...but not the non-methods on object. - del expected['__doc__'] - del expected['__class__'] - # inspect resolves descriptors on type into methods, but vars doesn't, - # so we need to update __subclasshook__. - expected['__subclasshook__'] = TestClass.__subclasshook__ - - methods = pydoc.allmethods(TestClass) - self.assertDictEqual(methods, expected) - class PydocImportTest(unittest.TestCase): diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/test/test_urllib2.py Tue Mar 19 01:20:20 2013 -0400 @@ -1387,10 +1387,6 @@ class MiscTests(unittest.TestCase): - def opener_has_handler(self, opener, handler_class): - self.assertTrue(any(h.__class__ == handler_class - for h in opener.handlers)) - def test_build_opener(self): class MyHTTPHandler(urllib.request.HTTPHandler): pass class FooHandler(urllib.request.BaseHandler): @@ -1443,22 +1439,10 @@ self.assertEqual(b"1234567890", request.data) self.assertEqual("10", request.get_header("Content-length")) - def test_HTTPError_interface(self): - """ - Issue 13211 reveals that HTTPError didn't implement the URLError - interface even though HTTPError is a subclass of URLError. - >>> msg = 'something bad happened' - >>> url = code = fp = None - >>> hdrs = 'Content-Length: 42' - >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) - >>> assert hasattr(err, 'reason') - >>> err.reason - 'something bad happened' - >>> assert hasattr(err, 'headers') - >>> err.headers - 'Content-Length: 42' - """ + def opener_has_handler(self, opener, handler_class): + self.assertTrue(any(h.__class__ == handler_class + for h in opener.handlers)) class RequestTests(unittest.TestCase): @@ -1530,6 +1514,23 @@ req = Request(url) self.assertEqual(req.get_full_url(), url) +def test_HTTPError_interface(): + """ + Issue 13211 reveals that HTTPError didn't implement the URLError + interface even though HTTPError is a subclass of URLError. + + >>> msg = 'something bad happened' + >>> url = code = fp = None + >>> hdrs = 'Content-Length: 42' + >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) + >>> assert hasattr(err, 'reason') + >>> err.reason + 'something bad happened' + >>> assert hasattr(err, 'headers') + >>> err.headers + 'Content-Length: 42' + """ + def test_main(verbose=None): from test import test_urllib2 support.run_doctest(test_urllib2, verbose) diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Lib/tkinter/test/test_ttk/test_widgets.py --- a/Lib/tkinter/test/test_ttk/test_widgets.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Lib/tkinter/test/test_ttk/test_widgets.py Tue Mar 19 01:20:20 2013 -0400 @@ -947,7 +947,7 @@ anchor=1) # XXX skipping for now; should be fixed to work with newer ttk - @unittest.skip("skipping pending resolution of Issue #10734") + @unittest.skip def test_heading_callback(self): def simulate_heading_click(x, y): support.simulate_mouse_click(self.tv, x, y) diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Misc/ACKS --- a/Misc/ACKS Tue Mar 19 16:26:19 2013 -0400 +++ b/Misc/ACKS Tue Mar 19 01:20:20 2013 -0400 @@ -1236,7 +1236,6 @@ Matthias Troffaes Tom Tromey John Tromp -Diane Trout Jason Trowbridge Brent Tubbs Anthony Tuininga diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Misc/NEWS --- a/Misc/NEWS Tue Mar 19 16:26:19 2013 -0400 +++ b/Misc/NEWS Tue Mar 19 01:20:20 2013 -0400 @@ -289,15 +289,6 @@ Library ------- -- Issue #8862: Fixed curses cleanup when getkey is interrputed by a signal. - -- Issue #17443: impalib.IMAP4_stream was using the default unbuffered IO - in subprocess, but the imap code assumes buffered IO. In Python2 this - worked by accident. IMAP4_stream now explicitly uses buffered IO. - -- Issue #17476: Fixed regression relative to Python2 in undocumented pydoc - 'allmethods'; it was missing unbound methods on the class. - - Issue #17474: Remove the deprecated methods of Request class. - Issue #16709: unittest discover order is no-longer filesystem specific. Patch diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c Tue Mar 19 16:26:19 2013 -0400 +++ b/Modules/_cursesmodule.c Tue Mar 19 01:20:20 2013 -0400 @@ -1138,9 +1138,7 @@ } if (rtn == ERR) { /* getch() returns ERR in nodelay mode */ - PyErr_CheckSignals(); - if (!PyErr_Occurred()) - PyErr_SetString(PyCursesError, "no input"); + PyErr_SetString(PyCursesError, "no input"); return NULL; } else if (rtn<=255) { return Py_BuildValue("C", rtn); diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Parser/asdl_c.py --- a/Parser/asdl_c.py Tue Mar 19 16:26:19 2013 -0400 +++ b/Parser/asdl_c.py Tue Mar 19 01:20:20 2013 -0400 @@ -499,10 +499,12 @@ def visitField(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) if field.opt: - check = "exists_not_none(obj, &PyId_%s)" % (field.name,) + add_check = " && _PyObject_GetAttrId(obj, &PyId_%s) != Py_None" \ + % (field.name) else: - check = "_PyObject_HasAttrId(obj, &PyId_%s)" % (field.name,) - self.emit("if (%s) {" % (check,), depth, reflow=False) + add_check = str() + self.emit("if (_PyObject_HasAttrId(obj, &PyId_%s)%s) {" + % (field.name, add_check), depth, reflow=False) self.emit("int res;", depth+1) if field.seq: self.emit("Py_ssize_t len;", depth+1) @@ -929,19 +931,6 @@ return 0; } -static int exists_not_none(PyObject *obj, _Py_Identifier *id) -{ - int isnone; - PyObject *attr = _PyObject_GetAttrId(obj, id); - if (!attr) { - PyErr_Clear(); - return 0; - } - isnone = attr == Py_None; - Py_DECREF(attr); - return !isnone; -} - """, 0, reflow=False) self.emit("static int init_types(void)",0) diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Python/Python-ast.c --- a/Python/Python-ast.c Tue Mar 19 16:26:19 2013 -0400 +++ b/Python/Python-ast.c Tue Mar 19 01:20:20 2013 -0400 @@ -770,19 +770,6 @@ return 0; } -static int exists_not_none(PyObject *obj, _Py_Identifier *id) -{ - int isnone; - PyObject *attr = _PyObject_GetAttrId(obj, id); - if (!attr) { - PyErr_Clear(); - return 0; - } - isnone = attr == Py_None; - Py_DECREF(attr); - return !isnone; -} - static int init_types(void) { @@ -3859,7 +3846,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); return 1; } - if (exists_not_none(obj, &PyId_returns)) { + if (_PyObject_HasAttrId(obj, &PyId_returns) && _PyObject_GetAttrId(obj, &PyId_returns) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_returns); if (tmp == NULL) goto failed; @@ -3950,7 +3937,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); return 1; } - if (exists_not_none(obj, &PyId_starargs)) { + if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_starargs); if (tmp == NULL) goto failed; @@ -3961,7 +3948,7 @@ } else { starargs = NULL; } - if (exists_not_none(obj, &PyId_kwargs)) { + if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); if (tmp == NULL) goto failed; @@ -4034,7 +4021,7 @@ if (isinstance) { expr_ty value; - if (exists_not_none(obj, &PyId_value)) { + if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; @@ -4492,7 +4479,7 @@ expr_ty exc; expr_ty cause; - if (exists_not_none(obj, &PyId_exc)) { + if (_PyObject_HasAttrId(obj, &PyId_exc) && _PyObject_GetAttrId(obj, &PyId_exc) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_exc); if (tmp == NULL) goto failed; @@ -4503,7 +4490,7 @@ } else { exc = NULL; } - if (exists_not_none(obj, &PyId_cause)) { + if (_PyObject_HasAttrId(obj, &PyId_cause) && _PyObject_GetAttrId(obj, &PyId_cause) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_cause); if (tmp == NULL) goto failed; @@ -4653,7 +4640,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); return 1; } - if (exists_not_none(obj, &PyId_msg)) { + if (_PyObject_HasAttrId(obj, &PyId_msg) && _PyObject_GetAttrId(obj, &PyId_msg) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_msg); if (tmp == NULL) goto failed; @@ -4713,7 +4700,7 @@ asdl_seq* names; int level; - if (exists_not_none(obj, &PyId_module)) { + if (_PyObject_HasAttrId(obj, &PyId_module) && _PyObject_GetAttrId(obj, &PyId_module) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_module); if (tmp == NULL) goto failed; @@ -4749,7 +4736,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); return 1; } - if (exists_not_none(obj, &PyId_level)) { + if (_PyObject_HasAttrId(obj, &PyId_level) && _PyObject_GetAttrId(obj, &PyId_level) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_level); if (tmp == NULL) goto failed; @@ -5468,7 +5455,7 @@ if (isinstance) { expr_ty value; - if (exists_not_none(obj, &PyId_value)) { + if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; @@ -5655,7 +5642,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); return 1; } - if (exists_not_none(obj, &PyId_starargs)) { + if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_starargs); if (tmp == NULL) goto failed; @@ -5666,7 +5653,7 @@ } else { starargs = NULL; } - if (exists_not_none(obj, &PyId_kwargs)) { + if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); if (tmp == NULL) goto failed; @@ -6137,7 +6124,7 @@ expr_ty upper; expr_ty step; - if (exists_not_none(obj, &PyId_lower)) { + if (_PyObject_HasAttrId(obj, &PyId_lower) && _PyObject_GetAttrId(obj, &PyId_lower) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_lower); if (tmp == NULL) goto failed; @@ -6148,7 +6135,7 @@ } else { lower = NULL; } - if (exists_not_none(obj, &PyId_upper)) { + if (_PyObject_HasAttrId(obj, &PyId_upper) && _PyObject_GetAttrId(obj, &PyId_upper) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_upper); if (tmp == NULL) goto failed; @@ -6159,7 +6146,7 @@ } else { upper = NULL; } - if (exists_not_none(obj, &PyId_step)) { + if (_PyObject_HasAttrId(obj, &PyId_step) && _PyObject_GetAttrId(obj, &PyId_step) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_step); if (tmp == NULL) goto failed; @@ -6614,7 +6601,7 @@ identifier name; asdl_seq* body; - if (exists_not_none(obj, &PyId_type)) { + if (_PyObject_HasAttrId(obj, &PyId_type) && _PyObject_GetAttrId(obj, &PyId_type) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_type); if (tmp == NULL) goto failed; @@ -6625,7 +6612,7 @@ } else { type = NULL; } - if (exists_not_none(obj, &PyId_name)) { + if (_PyObject_HasAttrId(obj, &PyId_name) && _PyObject_GetAttrId(obj, &PyId_name) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_name); if (tmp == NULL) goto failed; @@ -6709,7 +6696,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); return 1; } - if (exists_not_none(obj, &PyId_vararg)) { + if (_PyObject_HasAttrId(obj, &PyId_vararg) && _PyObject_GetAttrId(obj, &PyId_vararg) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_vararg); if (tmp == NULL) goto failed; @@ -6770,7 +6757,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); return 1; } - if (exists_not_none(obj, &PyId_kwarg)) { + if (_PyObject_HasAttrId(obj, &PyId_kwarg) && _PyObject_GetAttrId(obj, &PyId_kwarg) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); if (tmp == NULL) goto failed; @@ -6833,7 +6820,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); return 1; } - if (exists_not_none(obj, &PyId_annotation)) { + if (_PyObject_HasAttrId(obj, &PyId_annotation) && _PyObject_GetAttrId(obj, &PyId_annotation) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_annotation); if (tmp == NULL) goto failed; @@ -6908,7 +6895,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); return 1; } - if (exists_not_none(obj, &PyId_asname)) { + if (_PyObject_HasAttrId(obj, &PyId_asname) && _PyObject_GetAttrId(obj, &PyId_asname) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_asname); if (tmp == NULL) goto failed; @@ -6945,7 +6932,7 @@ PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); return 1; } - if (exists_not_none(obj, &PyId_optional_vars)) { + if (_PyObject_HasAttrId(obj, &PyId_optional_vars) && _PyObject_GetAttrId(obj, &PyId_optional_vars) != Py_None) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); if (tmp == NULL) goto failed; diff -r 4b9705fe3b2a -r 6dedcdbe7cd5 Python/import.c --- a/Python/import.c Tue Mar 19 16:26:19 2013 -0400 +++ b/Python/import.c Tue Mar 19 01:20:20 2013 -0400 @@ -846,7 +846,7 @@ /* Forward */ -static const struct _frozen * find_frozen(PyObject *); +static struct _frozen * find_frozen(PyObject *); /* Helper to test for built-in module */ @@ -983,10 +983,10 @@ /* Frozen modules */ -static const struct _frozen * +static struct _frozen * find_frozen(PyObject *name) { - const struct _frozen *p; + struct _frozen *p; if (name == NULL) return NULL; @@ -1003,7 +1003,7 @@ static PyObject * get_frozen_object(PyObject *name) { - const struct _frozen *p = find_frozen(name); + struct _frozen *p = find_frozen(name); int size; if (p == NULL) { @@ -1027,7 +1027,7 @@ static PyObject * is_frozen_package(PyObject *name) { - const struct _frozen *p = find_frozen(name); + struct _frozen *p = find_frozen(name); int size; if (p == NULL) { @@ -1054,7 +1054,7 @@ int PyImport_ImportFrozenModuleObject(PyObject *name) { - const struct _frozen *p; + struct _frozen *p; PyObject *co, *m, *path; int ispackage; int size; @@ -1781,7 +1781,7 @@ imp_is_frozen(PyObject *self, PyObject *args) { PyObject *name; - const struct _frozen *p; + struct _frozen *p; if (!PyArg_ParseTuple(args, "U:is_frozen", &name)) return NULL; p = find_frozen(name);