[pypy-commit] pypy vendor/stdlib-2.7.16: vendor in 2.7.16 with pip 19, stub implementation of weakref._remove_dead_weakref

mattip pypy.commits at gmail.com
Sun May 19 11:56:19 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: vendor/stdlib-2.7.16
Changeset: r96633:1ef1b169d3cc
Date: 2019-05-19 18:54 +0300
http://bitbucket.org/pypy/pypy/changeset/1ef1b169d3cc/

Log:	vendor in 2.7.16 with pip 19, stub implementation of
	weakref._remove_dead_weakref

diff too long, truncating to 2000 out of 56242 lines

diff --git a/lib-python/2.7/HTMLParser.py b/lib-python/2.7/HTMLParser.py
--- a/lib-python/2.7/HTMLParser.py
+++ b/lib-python/2.7/HTMLParser.py
@@ -462,11 +462,12 @@
             else:
                 # Cannot use name2codepoint directly, because HTMLParser supports apos,
                 # which is not part of HTML 4
-                import htmlentitydefs
                 if HTMLParser.entitydefs is None:
-                    entitydefs = HTMLParser.entitydefs = {'apos':u"'"}
+                    import htmlentitydefs
+                    entitydefs = {'apos':u"'"}
                     for k, v in htmlentitydefs.name2codepoint.iteritems():
                         entitydefs[k] = unichr(v)
+                    HTMLParser.entitydefs = entitydefs
                 try:
                     return self.entitydefs[s]
                 except KeyError:
diff --git a/lib-python/2.7/SocketServer.py b/lib-python/2.7/SocketServer.py
--- a/lib-python/2.7/SocketServer.py
+++ b/lib-python/2.7/SocketServer.py
@@ -229,6 +229,9 @@
                 # shutdown request and wastes cpu at all other times.
                 r, w, e = _eintr_retry(select.select, [self], [], [],
                                        poll_interval)
+                # bpo-35017: shutdown() called during select(), exit immediately.
+                if self.__shutdown_request:
+                    break
                 if self in r:
                     self._handle_request_noblock()
         finally:
diff --git a/lib-python/2.7/UserDict.py b/lib-python/2.7/UserDict.py
--- a/lib-python/2.7/UserDict.py
+++ b/lib-python/2.7/UserDict.py
@@ -113,12 +113,8 @@
     def __iter__(self):
         return iter(self.data)
 
-try:
-    import _abcoll
-except ImportError:
-    pass    # e.g. no '_weakref' module on this pypy
-else:
-    _abcoll.MutableMapping.register(IterableUserDict)
+import _abcoll
+_abcoll.MutableMapping.register(IterableUserDict)
 
 
 class DictMixin:
diff --git a/lib-python/2.7/_pyio.py b/lib-python/2.7/_pyio.py
--- a/lib-python/2.7/_pyio.py
+++ b/lib-python/2.7/_pyio.py
@@ -1619,6 +1619,7 @@
         self.buffer.write(b)
         if self._line_buffering and (haslf or "\r" in s):
             self.flush()
+        self._set_decoded_chars('')
         self._snapshot = None
         if self._decoder:
             self._decoder.reset()
diff --git a/lib-python/2.7/_strptime.py b/lib-python/2.7/_strptime.py
--- a/lib-python/2.7/_strptime.py
+++ b/lib-python/2.7/_strptime.py
@@ -254,8 +254,8 @@
         # format directives (%m, etc.).
         regex_chars = re_compile(r"([\\.^$*+?\(\){}\[\]|])")
         format = regex_chars.sub(r"\\\1", format)
-        whitespace_replacement = re_compile('\s+')
-        format = whitespace_replacement.sub('\s+', format)
+        whitespace_replacement = re_compile(r'\s+')
+        format = whitespace_replacement.sub(r'\\s+', format)
         while '%' in format:
             directive_index = format.index('%')+1
             processed_format = "%s%s%s" % (processed_format,
diff --git a/lib-python/2.7/_threading_local.py b/lib-python/2.7/_threading_local.py
--- a/lib-python/2.7/_threading_local.py
+++ b/lib-python/2.7/_threading_local.py
@@ -57,11 +57,7 @@
 
   >>> class MyLocal(local):
   ...     number = 2
-  ...     initialized = False
   ...     def __init__(self, **kw):
-  ...         if self.initialized:
-  ...             raise SystemError('__init__ called too many times')
-  ...         self.initialized = True
   ...         self.__dict__.update(kw)
   ...     def squared(self):
   ...         return self.number ** 2
@@ -98,7 +94,7 @@
   >>> thread.start()
   >>> thread.join()
   >>> log
-  [[('color', 'red'), ('initialized', True)], 11]
+  [[('color', 'red')], 11]
 
 without affecting this thread's data:
 
@@ -155,7 +151,7 @@
         object.__setattr__(self, '_local__args', (args, kw))
         object.__setattr__(self, '_local__lock', RLock())
 
-        if (args or kw) and (cls.__init__ == object.__init__):
+        if (args or kw) and (cls.__init__ is object.__init__):
             raise TypeError("Initialization arguments are not supported")
 
         # We need to create the thread dict in anticipation of
diff --git a/lib-python/2.7/aifc.py b/lib-python/2.7/aifc.py
--- a/lib-python/2.7/aifc.py
+++ b/lib-python/2.7/aifc.py
@@ -288,6 +288,8 @@
     # _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
     # _framesize -- size of one frame in the file
 
+    _file = None  # Set here since __del__ checks it
+
     def initfp(self, file):
         self._version = 0
         self._decomp = None
@@ -306,6 +308,7 @@
         else:
             raise Error, 'not an AIFF or AIFF-C file'
         self._comm_chunk_read = 0
+        self._ssnd_chunk = None
         while 1:
             self._ssnd_seek_needed = 1
             try:
@@ -341,10 +344,16 @@
             self._decomp.SetParams(params)
 
     def __init__(self, f):
-        if type(f) == type(''):
+        if isinstance(f, basestring):
             f = __builtin__.open(f, 'rb')
-        # else, assume it is an open file object already
-        self.initfp(f)
+            try:
+                self.initfp(f)
+            except:
+                f.close()
+                raise
+        else:
+            # assume it is an open file object already
+            self.initfp(f)
 
     #
     # User visible methods.
@@ -562,8 +571,10 @@
     # _datalength -- the size of the audio samples written to the header
     # _datawritten -- the size of the audio samples actually written
 
+    _file = None  # Set here since __del__ checks it
+
     def __init__(self, f):
-        if type(f) == type(''):
+        if isinstance(f, basestring):
             filename = f
             f = __builtin__.open(f, 'wb')
         else:
diff --git a/lib-python/2.7/argparse.py b/lib-python/2.7/argparse.py
--- a/lib-python/2.7/argparse.py
+++ b/lib-python/2.7/argparse.py
@@ -324,7 +324,11 @@
             if len(prefix) + len(usage) > text_width:
 
                 # break usage into wrappable parts
-                part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
+                part_regexp = (
+                    r'\(.*?\)+(?=\s|$)|'
+                    r'\[.*?\]+(?=\s|$)|'
+                    r'\S+'
+                )
                 opt_usage = format(optionals, groups)
                 pos_usage = format(positionals, groups)
                 opt_parts = _re.findall(part_regexp, opt_usage)
@@ -1793,19 +1797,7 @@
             # error if this argument is not allowed with other previously
             # seen arguments, assuming that actions that use the default
             # value don't really count as "present"
-
-            # XXX PyPy bug-to-bug compatibility: "is" on primitive types
-            # is not consistent in CPython.  We'll assume it is close
-            # enough for ints (which is true only for "small ints"), but
-            # for floats and longs and complexes we'll go for the option
-            # of forcing "is" to say False, like it usually does on
-            # CPython.  A fix is pending on CPython trunk
-            # (http://bugs.python.org/issue18943) but that might change
-            # the details of the semantics and so not be applied to 2.7.
-            # See the line AA below.
-
-            if (argument_values is not action.default or
-                    type(argument_values) in (float, long, complex)):  # AA
+            if argument_values is not action.default:
                 seen_non_default_actions.add(action)
                 for conflict_action in action_conflicts.get(action, []):
                     if conflict_action in seen_non_default_actions:
diff --git a/lib-python/2.7/asynchat.py b/lib-python/2.7/asynchat.py
--- a/lib-python/2.7/asynchat.py
+++ b/lib-python/2.7/asynchat.py
@@ -133,7 +133,7 @@
                 # no terminator, collect it all
                 self.collect_incoming_data (self.ac_in_buffer)
                 self.ac_in_buffer = ''
-            elif isinstance(terminator, int) or isinstance(terminator, long):
+            elif isinstance(terminator, (int, long)):
                 # numeric terminator
                 n = terminator
                 if lb < n:
diff --git a/lib-python/2.7/asyncore.py b/lib-python/2.7/asyncore.py
--- a/lib-python/2.7/asyncore.py
+++ b/lib-python/2.7/asyncore.py
@@ -633,7 +633,11 @@
         write = send
 
         def close(self):
-            os.close(self.fd)
+            if self.fd < 0:
+                return
+            fd = self.fd
+            self.fd = -1
+            os.close(fd)
 
         def fileno(self):
             return self.fd
diff --git a/lib-python/2.7/bsddb/test/test_associate.py b/lib-python/2.7/bsddb/test/test_associate.py
--- a/lib-python/2.7/bsddb/test/test_associate.py
+++ b/lib-python/2.7/bsddb/test/test_associate.py
@@ -114,6 +114,22 @@
             dupDB.close()
             self.fail("DBError exception was expected")
 
+    @unittest.skipUnless(db.version() >= (4, 6), 'Needs 4.6+')
+    def test_associateListError(self):
+        db1 = db.DB(self.env)
+        db1.open('bad.db', "a.db", db.DB_BTREE, db.DB_CREATE)
+        db2 = db.DB(self.env)
+        db2.open('bad.db', "b.db", db.DB_BTREE, db.DB_CREATE)
+
+        db1.associate(db2, lambda a, b: [0])
+
+        msg = "TypeError: The list returned by DB->associate callback" \
+              " should be a list of strings."
+        with test_support.captured_output("stderr") as s:
+            db1.put("0", "1")
+        db1.close()
+        db2.close()
+        self.assertEquals(s.getvalue().strip(), msg)
 
 
 #----------------------------------------------------------------------
@@ -233,7 +249,7 @@
         self.assertEqual(vals, None, vals)
 
         vals = secDB.pget('Unknown', txn=txn)
-        self.assertTrue(vals[0] == 99 or vals[0] == '99', vals)
+        self.assertIn(vals[0], (99, '99'), vals)
         vals[1].index('Unknown')
         vals[1].index('Unnamed')
         vals[1].index('unknown')
@@ -247,7 +263,8 @@
             if type(self.keytype) == type(''):
                 self.assertTrue(int(rec[0]))  # for primary db, key is a number
             else:
-                self.assertTrue(rec[0] and type(rec[0]) == type(0))
+                self.assertTrue(rec[0])
+                self.assertIs(type(rec[0]), int)
             count = count + 1
             if verbose:
                 print rec
@@ -262,7 +279,7 @@
 
         # test cursor pget
         vals = self.cur.pget('Unknown', flags=db.DB_LAST)
-        self.assertTrue(vals[1] == 99 or vals[1] == '99', vals)
+        self.assertIn(vals[1], (99, '99'), vals)
         self.assertEqual(vals[0], 'Unknown')
         vals[2].index('Unknown')
         vals[2].index('Unnamed')
diff --git a/lib-python/2.7/bsddb/test/test_basics.py b/lib-python/2.7/bsddb/test/test_basics.py
--- a/lib-python/2.7/bsddb/test/test_basics.py
+++ b/lib-python/2.7/bsddb/test/test_basics.py
@@ -597,7 +597,7 @@
 
         d.put("abcde", "ABCDE");
         num = d.truncate()
-        self.assertTrue(num >= 1, "truncate returned <= 0 on non-empty database")
+        self.assertGreaterEqual(num, 1, "truncate returned <= 0 on non-empty database")
         num = d.truncate()
         self.assertEqual(num, 0,
                 "truncate on empty DB returned nonzero (%r)" % (num,))
@@ -616,9 +616,9 @@
     if db.version() >= (4, 6):
         def test08_exists(self) :
             self.d.put("abcde", "ABCDE")
-            self.assertTrue(self.d.exists("abcde") == True,
+            self.assertEqual(self.d.exists("abcde"), True,
                     "DB->exists() returns wrong value")
-            self.assertTrue(self.d.exists("x") == False,
+            self.assertEqual(self.d.exists("x"), False,
                     "DB->exists() returns wrong value")
 
     #----------------------------------------
@@ -773,7 +773,7 @@
             if verbose:
                 print 'log file: ' + log
             logs = self.env.log_archive(db.DB_ARCH_REMOVE)
-            self.assertTrue(not logs)
+            self.assertFalse(logs)
 
         self.txn = self.env.txn_begin()
 
@@ -785,9 +785,9 @@
             self.d.put("abcde", "ABCDE", txn=txn)
             txn.commit()
             txn = self.env.txn_begin()
-            self.assertTrue(self.d.exists("abcde", txn=txn) == True,
+            self.assertEqual(self.d.exists("abcde", txn=txn), True,
                     "DB->exists() returns wrong value")
-            self.assertTrue(self.d.exists("x", txn=txn) == False,
+            self.assertEqual(self.d.exists("x", txn=txn), False,
                     "DB->exists() returns wrong value")
             txn.abort()
 
@@ -802,7 +802,7 @@
         d.put("abcde", "ABCDE");
         txn = self.env.txn_begin()
         num = d.truncate(txn)
-        self.assertTrue(num >= 1, "truncate returned <= 0 on non-empty database")
+        self.assertGreaterEqual(num, 1, "truncate returned <= 0 on non-empty database")
         num = d.truncate(txn)
         self.assertEqual(num, 0,
                 "truncate on empty DB returned nonzero (%r)" % (num,))
@@ -1086,7 +1086,7 @@
         a = "example of private object"
         self.obj.set_private(a)
         b = self.obj.get_private()
-        self.assertTrue(a is b)  # Object identity
+        self.assertIs(a, b)  # Object identity
 
     def test03_leak_assignment(self) :
         a = "example of private object"
diff --git a/lib-python/2.7/bsddb/test/test_dbenv.py b/lib-python/2.7/bsddb/test/test_dbenv.py
--- a/lib-python/2.7/bsddb/test/test_dbenv.py
+++ b/lib-python/2.7/bsddb/test/test_dbenv.py
@@ -54,15 +54,15 @@
                 self.env.set_cache_max(0, size)
                 size2 = self.env.get_cache_max()
                 self.assertEqual(0, size2[0])
-                self.assertTrue(size <= size2[1])
-                self.assertTrue(2*size > size2[1])
+                self.assertLessEqual(size, size2[1])
+                self.assertGreater(2*size, size2[1])
 
     if db.version() >= (4, 4) :
         def test_mutex_stat(self) :
             self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL |
                     db.DB_INIT_LOCK)
             stat = self.env.mutex_stat()
-            self.assertTrue("mutex_inuse_max" in stat)
+            self.assertIn("mutex_inuse_max", stat)
 
         def test_lg_filemode(self) :
             for i in [0600, 0660, 0666] :
@@ -128,8 +128,8 @@
                 i = i*1024*1024
                 self.env.set_lg_regionmax(i)
                 j = self.env.get_lg_regionmax()
-                self.assertTrue(i <= j)
-                self.assertTrue(2*i > j)
+                self.assertLessEqual(i, j)
+                self.assertGreater(2*i, j)
 
         def test_lk_detect(self) :
             flags= [db.DB_LOCK_DEFAULT, db.DB_LOCK_EXPIRE, db.DB_LOCK_MAXLOCKS,
@@ -150,10 +150,10 @@
         def test_lg_bsize(self) :
             log_size = 70*1024
             self.env.set_lg_bsize(log_size)
-            self.assertTrue(self.env.get_lg_bsize() >= log_size)
-            self.assertTrue(self.env.get_lg_bsize() < 4*log_size)
+            self.assertGreaterEqual(self.env.get_lg_bsize(), log_size)
+            self.assertLess(self.env.get_lg_bsize(), 4*log_size)
             self.env.set_lg_bsize(4*log_size)
-            self.assertTrue(self.env.get_lg_bsize() >= 4*log_size)
+            self.assertGreaterEqual(self.env.get_lg_bsize(), 4*log_size)
 
         def test_setget_data_dirs(self) :
             dirs = ("a", "b", "c", "d")
@@ -185,7 +185,7 @@
             self.assertEqual(cachesize2[0], cachesize3[0])
             self.assertEqual(cachesize2[2], cachesize3[2])
             # In Berkeley DB 5.1, the cachesize can change when opening the Env
-            self.assertTrue(cachesize2[1] <= cachesize3[1])
+            self.assertLessEqual(cachesize2[1], cachesize3[1])
 
         def test_set_cachesize_dbenv_db(self) :
             # You can not configure the cachesize using
@@ -299,7 +299,7 @@
             msg = "This is a test..."
             self.env.log_printf(msg)
             logc = self.env.log_cursor()
-            self.assertTrue(msg in (logc.last()[1]))
+            self.assertIn(msg, logc.last()[1])
 
     if db.version() >= (4, 7) :
         def test_log_config(self) :
@@ -341,21 +341,21 @@
             txn.commit()
             logc = self.env.log_cursor()
             logc.last()  # Skip the commit
-            self.assertTrue(msg in (logc.prev()[1]))
+            self.assertIn(msg, logc.prev()[1])
 
             msg = "This is another test..."
             txn = self.env.txn_begin()
             self.env.log_printf(msg, txn=txn)
             txn.abort()  # Do not store the new message
             logc.last()  # Skip the abort
-            self.assertTrue(msg not in (logc.prev()[1]))
+            self.assertNotIn(msg, logc.prev()[1])
 
             msg = "This is a third test..."
             txn = self.env.txn_begin()
             self.env.log_printf(msg, txn=txn)
             txn.commit()  # Do not store the new message
             logc.last()  # Skip the commit
-            self.assertTrue(msg in (logc.prev()[1]))
+            self.assertIn(msg, logc.prev()[1])
 
 
 class DBEnv_memp(DBEnv):
@@ -372,39 +372,39 @@
 
     def test_memp_1_trickle(self) :
         self.db.put("hi", "bye")
-        self.assertTrue(self.env.memp_trickle(100) > 0)
+        self.assertGreater(self.env.memp_trickle(100), 0)
 
 # Preserve the order, do "memp_trickle" test first
     def test_memp_2_sync(self) :
         self.db.put("hi", "bye")
         self.env.memp_sync()  # Full flush
         # Nothing to do...
-        self.assertTrue(self.env.memp_trickle(100) == 0)
+        self.assertEqual(self.env.memp_trickle(100), 0)
 
         self.db.put("hi", "bye2")
         self.env.memp_sync((1, 0))  # NOP, probably
         # Something to do... or not
-        self.assertTrue(self.env.memp_trickle(100) >= 0)
+        self.assertGreaterEqual(self.env.memp_trickle(100), 0)
 
         self.db.put("hi", "bye3")
         self.env.memp_sync((123, 99))  # Full flush
         # Nothing to do...
-        self.assertTrue(self.env.memp_trickle(100) == 0)
+        self.assertEqual(self.env.memp_trickle(100), 0)
 
     def test_memp_stat_1(self) :
         stats = self.env.memp_stat()  # No param
-        self.assertTrue(len(stats)==2)
-        self.assertTrue("cache_miss" in stats[0])
+        self.assertEqual(len(stats), 2)
+        self.assertIn("cache_miss", stats[0])
         stats = self.env.memp_stat(db.DB_STAT_CLEAR)  # Positional param
-        self.assertTrue("cache_miss" in stats[0])
+        self.assertIn("cache_miss", stats[0])
         stats = self.env.memp_stat(flags=0)  # Keyword param
-        self.assertTrue("cache_miss" in stats[0])
+        self.assertIn("cache_miss", stats[0])
 
     def test_memp_stat_2(self) :
         stats=self.env.memp_stat()[1]
-        self.assertTrue(len(stats))==1
-        self.assertTrue("test" in stats)
-        self.assertTrue("page_in" in stats["test"])
+        self.assertEqual(len(stats), 1)
+        self.assertIn("test", stats)
+        self.assertIn("page_in", stats["test"])
 
 class DBEnv_logcursor(DBEnv):
     def setUp(self):
@@ -426,28 +426,28 @@
         DBEnv.tearDown(self)
 
     def _check_return(self, value) :
-        self.assertTrue(isinstance(value, tuple))
+        self.assertIsInstance(value, tuple)
         self.assertEqual(len(value), 2)
-        self.assertTrue(isinstance(value[0], tuple))
+        self.assertIsInstance(value[0], tuple)
         self.assertEqual(len(value[0]), 2)
-        self.assertTrue(isinstance(value[0][0], int))
-        self.assertTrue(isinstance(value[0][1], int))
-        self.assertTrue(isinstance(value[1], str))
+        self.assertIsInstance(value[0][0], int)
+        self.assertIsInstance(value[0][1], int)
+        self.assertIsInstance(value[1], str)
 
     # Preserve test order
     def test_1_first(self) :
         logc = self.env.log_cursor()
         v = logc.first()
         self._check_return(v)
-        self.assertTrue((1, 1) < v[0])
-        self.assertTrue(len(v[1])>0)
+        self.assertLess((1, 1), v[0])
+        self.assertGreater(len(v[1]), 0)
 
     def test_2_last(self) :
         logc = self.env.log_cursor()
         lsn_first = logc.first()[0]
         v = logc.last()
         self._check_return(v)
-        self.assertTrue(lsn_first < v[0])
+        self.assertLess(lsn_first, v[0])
 
     def test_3_next(self) :
         logc = self.env.log_cursor()
@@ -456,16 +456,16 @@
         lsn_first = logc.first()[0]
         v = logc.next()
         self._check_return(v)
-        self.assertTrue(lsn_first < v[0])
-        self.assertTrue(lsn_last > v[0])
+        self.assertLess(lsn_first, v[0])
+        self.assertGreater(lsn_last, v[0])
 
         v2 = logc.next()
-        self.assertTrue(v2[0] > v[0])
-        self.assertTrue(lsn_last > v2[0])
+        self.assertGreater(v2[0], v[0])
+        self.assertGreater(lsn_last, v2[0])
 
         v3 = logc.next()
-        self.assertTrue(v3[0] > v2[0])
-        self.assertTrue(lsn_last > v3[0])
+        self.assertGreater(v3[0], v2[0])
+        self.assertGreater(lsn_last, v3[0])
 
     def test_4_prev(self) :
         logc = self.env.log_cursor()
@@ -474,16 +474,16 @@
         lsn_last = logc.last()[0]
         v = logc.prev()
         self._check_return(v)
-        self.assertTrue(lsn_first < v[0])
-        self.assertTrue(lsn_last > v[0])
+        self.assertLess(lsn_first, v[0])
+        self.assertGreater(lsn_last, v[0])
 
         v2 = logc.prev()
-        self.assertTrue(v2[0] < v[0])
-        self.assertTrue(lsn_first < v2[0])
+        self.assertLess(v2[0], v[0])
+        self.assertLess(lsn_first, v2[0])
 
         v3 = logc.prev()
-        self.assertTrue(v3[0] < v2[0])
-        self.assertTrue(lsn_first < v3[0])
+        self.assertLess(v3[0], v2[0])
+        self.assertLess(lsn_first, v3[0])
 
     def test_5_current(self) :
         logc = self.env.log_cursor()
diff --git a/lib-python/2.7/bsddb/test/test_dbshelve.py b/lib-python/2.7/bsddb/test/test_dbshelve.py
--- a/lib-python/2.7/bsddb/test/test_dbshelve.py
+++ b/lib-python/2.7/bsddb/test/test_dbshelve.py
@@ -248,7 +248,7 @@
             self.assertEqual(value.L, [x] * 10)
 
         else:
-            self.assertTrue(0, 'Unknown key type, fix the test')
+            self.fail('Unknown key type, fix the test')
 
 #----------------------------------------------------------------------
 
diff --git a/lib-python/2.7/bsddb/test/test_dbtables.py b/lib-python/2.7/bsddb/test/test_dbtables.py
--- a/lib-python/2.7/bsddb/test/test_dbtables.py
+++ b/lib-python/2.7/bsddb/test/test_dbtables.py
@@ -82,8 +82,8 @@
             colval = pickle.loads(values[0][colname])
         else :
             colval = pickle.loads(bytes(values[0][colname], "iso8859-1"))
-        self.assertTrue(colval > 3.141)
-        self.assertTrue(colval < 3.142)
+        self.assertGreater(colval, 3.141)
+        self.assertLess(colval, 3.142)
 
 
     def test02(self):
diff --git a/lib-python/2.7/bsddb/test/test_distributed_transactions.py b/lib-python/2.7/bsddb/test/test_distributed_transactions.py
--- a/lib-python/2.7/bsddb/test/test_distributed_transactions.py
+++ b/lib-python/2.7/bsddb/test/test_distributed_transactions.py
@@ -79,7 +79,7 @@
         recovered_txns=self.dbenv.txn_recover()
         self.assertEqual(self.num_txns,len(recovered_txns))
         for gid,txn in recovered_txns :
-            self.assertTrue(gid in txns)
+            self.assertIn(gid, txns)
         del txn
         del recovered_txns
 
@@ -122,7 +122,7 @@
     # Be sure there are not pending transactions.
     # Check also database size.
         recovered_txns=self.dbenv.txn_recover()
-        self.assertTrue(len(recovered_txns)==0)
+        self.assertEqual(len(recovered_txns), 0)
         self.assertEqual(len(committed_txns),self.db.stat()["nkeys"])
 
 class DBTxn_distributedSYNC(DBTxn_distributed):
diff --git a/lib-python/2.7/bsddb/test/test_lock.py b/lib-python/2.7/bsddb/test/test_lock.py
--- a/lib-python/2.7/bsddb/test/test_lock.py
+++ b/lib-python/2.7/bsddb/test/test_lock.py
@@ -2,6 +2,7 @@
 TestCases for testing the locking sub-system.
 """
 
+import sys
 import time
 
 import unittest
@@ -10,7 +11,6 @@
 
 if have_threads :
     from threading import Thread
-    import sys
     if sys.version_info[0] < 3 :
         from threading import currentThread
     else :
@@ -129,7 +129,14 @@
         end_time=time.time()
         deadlock_detection.end=True
         # Floating point rounding
-        self.assertTrue((end_time-start_time) >= 0.0999)
+        if sys.platform == 'win32':
+            # bpo-30850: On Windows, tolerate 50 ms whereas 100 ms is expected.
+            # The lock sometimes times out after only 58 ms. Windows clocks
+            # have a bad resolution and bad accuracy.
+            min_dt = 0.050
+        else:
+            min_dt = 0.0999
+        self.assertGreaterEqual(end_time-start_time, min_dt)
         self.env.lock_put(lock)
         t.join()
 
@@ -137,7 +144,7 @@
         self.env.lock_id_free(anID2)
 
         if db.version() >= (4,6):
-            self.assertTrue(deadlock_detection.count>0)
+            self.assertGreater(deadlock_detection.count, 0)
 
     def theThread(self, lockType):
         import sys
diff --git a/lib-python/2.7/bsddb/test/test_misc.py b/lib-python/2.7/bsddb/test/test_misc.py
--- a/lib-python/2.7/bsddb/test/test_misc.py
+++ b/lib-python/2.7/bsddb/test/test_misc.py
@@ -25,7 +25,7 @@
     def test02_db_home(self):
         env = db.DBEnv()
         # check for crash fixed when db_home is used before open()
-        self.assertTrue(env.db_home is None)
+        self.assertIsNone(env.db_home)
         env.open(self.homeDir, db.DB_CREATE)
         if sys.version_info[0] < 3 :
             self.assertEqual(self.homeDir, env.db_home)
diff --git a/lib-python/2.7/bsddb/test/test_recno.py b/lib-python/2.7/bsddb/test/test_recno.py
--- a/lib-python/2.7/bsddb/test/test_recno.py
+++ b/lib-python/2.7/bsddb/test/test_recno.py
@@ -18,7 +18,7 @@
         def assertIsInstance(self, obj, datatype, msg=None) :
             return self.assertEqual(type(obj), datatype, msg=msg)
         def assertGreaterEqual(self, a, b, msg=None) :
-            return self.assertTrue(a>=b, msg=msg)
+            return self.assertGreaterEqual(a, b, msg=msg)
 
 
     def setUp(self):
diff --git a/lib-python/2.7/bsddb/test/test_replication.py b/lib-python/2.7/bsddb/test/test_replication.py
--- a/lib-python/2.7/bsddb/test/test_replication.py
+++ b/lib-python/2.7/bsddb/test/test_replication.py
@@ -186,20 +186,18 @@
         d = d.values()[0]  # There is only one
         self.assertEqual(d[0], "127.0.0.1")
         self.assertEqual(d[1], client_port)
-        self.assertTrue((d[2]==db.DB_REPMGR_CONNECTED) or \
-                (d[2]==db.DB_REPMGR_DISCONNECTED))
+        self.assertIn(d[2], (db.DB_REPMGR_CONNECTED, db.DB_REPMGR_DISCONNECTED))
 
         d = self.dbenvClient.repmgr_site_list()
         self.assertEqual(len(d), 1)
         d = d.values()[0]  # There is only one
         self.assertEqual(d[0], "127.0.0.1")
         self.assertEqual(d[1], master_port)
-        self.assertTrue((d[2]==db.DB_REPMGR_CONNECTED) or \
-                (d[2]==db.DB_REPMGR_DISCONNECTED))
+        self.assertIn(d[2], (db.DB_REPMGR_CONNECTED, db.DB_REPMGR_DISCONNECTED))
 
         if db.version() >= (4,6) :
             d = self.dbenvMaster.repmgr_stat(flags=db.DB_STAT_CLEAR);
-            self.assertTrue("msgs_queued" in d)
+            self.assertIn("msgs_queued", d)
 
         self.dbMaster=db.DB(self.dbenvMaster)
         txn=self.dbenvMaster.txn_begin()
@@ -247,7 +245,7 @@
         if time.time()>=timeout and startup_timeout:
             self.skipTest("replication test skipped due to random failure, "
                 "see issue 3892")
-        self.assertTrue(time.time()<timeout)
+        self.assertLess(time.time(), timeout)
         self.assertEqual("123", v)
 
         txn=self.dbenvMaster.txn_begin()
@@ -260,7 +258,7 @@
             txn.commit()
             if v is None :
                 time.sleep(0.02)
-        self.assertTrue(time.time()<timeout)
+        self.assertLess(time.time(), timeout)
         self.assertEqual(None, v)
 
 class DBBaseReplication(DBReplication) :
@@ -381,7 +379,7 @@
         while (time.time()<timeout) and not (self.confirmed_master and
                 self.client_startupdone) :
             time.sleep(0.02)
-        self.assertTrue(time.time()<timeout)
+        self.assertLess(time.time(), timeout)
 
         self.dbMaster=db.DB(self.dbenvMaster)
         txn=self.dbenvMaster.txn_begin()
@@ -410,7 +408,7 @@
             break
 
         d = self.dbenvMaster.rep_stat(flags=db.DB_STAT_CLEAR);
-        self.assertTrue("master_changes" in d)
+        self.assertIn("master_changes", d)
 
         txn=self.dbenvMaster.txn_begin()
         self.dbMaster.put("ABC", "123", txn=txn)
@@ -424,7 +422,7 @@
             txn.commit()
             if v is None :
                 time.sleep(0.02)
-        self.assertTrue(time.time()<timeout)
+        self.assertLess(time.time(), timeout)
         self.assertEqual("123", v)
 
         txn=self.dbenvMaster.txn_begin()
@@ -437,7 +435,7 @@
             txn.commit()
             if v is None :
                 time.sleep(0.02)
-        self.assertTrue(time.time()<timeout)
+        self.assertLess(time.time(), timeout)
         self.assertEqual(None, v)
 
     if db.version() >= (4,7) :
diff --git a/lib-python/2.7/bsddb/test/test_sequence.py b/lib-python/2.7/bsddb/test/test_sequence.py
--- a/lib-python/2.7/bsddb/test/test_sequence.py
+++ b/lib-python/2.7/bsddb/test/test_sequence.py
@@ -82,7 +82,7 @@
         stat = self.seq.stat()
         for param in ('nowait', 'min', 'max', 'value', 'current',
                       'flags', 'cache_size', 'last_value', 'wait'):
-            self.assertTrue(param in stat, "parameter %s isn't in stat info" % param)
+            self.assertIn(param, stat, "parameter %s isn't in stat info" % param)
 
     if db.version() >= (4,7) :
         # This code checks a crash solved in Berkeley DB 4.7
diff --git a/lib-python/2.7/bsddb/test/test_thread.py b/lib-python/2.7/bsddb/test/test_thread.py
--- a/lib-python/2.7/bsddb/test/test_thread.py
+++ b/lib-python/2.7/bsddb/test/test_thread.py
@@ -85,7 +85,7 @@
         readers_per_writer=self.readers//self.writers
         self.assertEqual(self.records,self.writers*records_per_writer)
         self.assertEqual(self.readers,self.writers*readers_per_writer)
-        self.assertTrue((records_per_writer%readers_per_writer)==0)
+        self.assertEqual(records_per_writer%readers_per_writer, 0)
         readers = []
 
         for x in xrange(self.readers):
@@ -213,7 +213,7 @@
         readers_per_writer=self.readers//self.writers
         self.assertEqual(self.records,self.writers*records_per_writer)
         self.assertEqual(self.readers,self.writers*readers_per_writer)
-        self.assertTrue((records_per_writer%readers_per_writer)==0)
+        self.assertEqual(records_per_writer%readers_per_writer, 0)
 
         readers = []
         for x in xrange(self.readers):
@@ -339,7 +339,7 @@
         readers_per_writer=self.readers//self.writers
         self.assertEqual(self.records,self.writers*records_per_writer)
         self.assertEqual(self.readers,self.writers*readers_per_writer)
-        self.assertTrue((records_per_writer%readers_per_writer)==0)
+        self.assertEqual(records_per_writer%readers_per_writer, 0)
 
         readers=[]
         for x in xrange(self.readers):
diff --git a/lib-python/2.7/cProfile.py b/lib-python/2.7/cProfile.py
--- a/lib-python/2.7/cProfile.py
+++ b/lib-python/2.7/cProfile.py
@@ -64,11 +64,11 @@
 # ____________________________________________________________
 
 class Profile(_lsprof.Profiler):
-    """Profile(custom_timer=None, time_unit=None, subcalls=True, builtins=True)
+    """Profile(timer=None, timeunit=None, subcalls=True, builtins=True)
 
     Builds a profiler object using the specified timer function.
     The default timer is a fast built-in one based on real time.
-    For custom timer functions returning integers, time_unit can
+    For custom timer functions returning integers, timeunit can
     be a float specifying a scale (i.e. how long each integer unit
     is, in seconds).
     """
@@ -161,7 +161,7 @@
 # ____________________________________________________________
 
 def main():
-    import os, sys, types
+    import os, sys, pstats
     from optparse import OptionParser
     usage = "cProfile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
     parser = OptionParser(usage=usage)
@@ -170,7 +170,8 @@
         help="Save stats to <outfile>", default=None)
     parser.add_option('-s', '--sort', dest="sort",
         help="Sort order when printing to stdout, based on pstats.Stats class",
-        default=-1)
+        default=-1,
+        choices=sorted(pstats.Stats.sort_arg_dict_default))
 
     if not sys.argv[1:]:
         parser.print_usage()
@@ -184,10 +185,12 @@
         sys.path.insert(0, os.path.dirname(progname))
         with open(progname, 'rb') as fp:
             code = compile(fp.read(), progname, 'exec')
-        mainmod = types.ModuleType('__main__')
-        mainmod.__file__ = progname
-        mainmod.__package__ = None
-        runctx(code, mainmod.__dict__, None, options.outfile, options.sort)
+        globs = {
+            '__file__': progname,
+            '__name__': '__main__',
+            '__package__': None,
+        }
+        runctx(code, globs, None, options.outfile, options.sort)
     else:
         parser.print_usage()
     return parser
diff --git a/lib-python/2.7/cgi.py b/lib-python/2.7/cgi.py
--- a/lib-python/2.7/cgi.py
+++ b/lib-python/2.7/cgi.py
@@ -184,11 +184,12 @@
     return urlparse.parse_qs(qs, keep_blank_values, strict_parsing)
 
 
-def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
+def parse_qsl(qs, keep_blank_values=0, strict_parsing=0, max_num_fields=None):
     """Parse a query given as a string argument."""
     warn("cgi.parse_qsl is deprecated, use urlparse.parse_qsl instead",
          PendingDeprecationWarning, 2)
-    return urlparse.parse_qsl(qs, keep_blank_values, strict_parsing)
+    return urlparse.parse_qsl(qs, keep_blank_values, strict_parsing,
+                              max_num_fields)
 
 def parse_multipart(fp, pdict):
     """Parse multipart input.
@@ -393,7 +394,8 @@
     """
 
     def __init__(self, fp=None, headers=None, outerboundary="",
-                 environ=os.environ, keep_blank_values=0, strict_parsing=0):
+                 environ=os.environ, keep_blank_values=0, strict_parsing=0,
+                 max_num_fields=None):
         """Constructor.  Read multipart/* until last part.
 
         Arguments, all optional:
@@ -420,10 +422,14 @@
             If false (the default), errors are silently ignored.
             If true, errors raise a ValueError exception.
 
+        max_num_fields: int. If set, then __init__ throws a ValueError
+            if there are more than n fields read by parse_qsl().
+
         """
         method = 'GET'
         self.keep_blank_values = keep_blank_values
         self.strict_parsing = strict_parsing
+        self.max_num_fields = max_num_fields
         if 'REQUEST_METHOD' in environ:
             method = environ['REQUEST_METHOD'].upper()
         self.qs_on_post = None
@@ -606,10 +612,9 @@
         qs = self.fp.read(self.length)
         if self.qs_on_post:
             qs += '&' + self.qs_on_post
-        self.list = list = []
-        for key, value in urlparse.parse_qsl(qs, self.keep_blank_values,
-                                            self.strict_parsing):
-            list.append(MiniFieldStorage(key, value))
+        query = urlparse.parse_qsl(qs, self.keep_blank_values,
+                                   self.strict_parsing, self.max_num_fields)
+        self.list = [MiniFieldStorage(key, value) for key, value in query]
         self.skip_lines()
 
     FieldStorageClass = None
@@ -621,19 +626,38 @@
             raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,)
         self.list = []
         if self.qs_on_post:
-            for key, value in urlparse.parse_qsl(self.qs_on_post,
-                                self.keep_blank_values, self.strict_parsing):
-                self.list.append(MiniFieldStorage(key, value))
+            query = urlparse.parse_qsl(self.qs_on_post,
+                                       self.keep_blank_values,
+                                       self.strict_parsing,
+                                       self.max_num_fields)
+            self.list.extend(MiniFieldStorage(key, value)
+                             for key, value in query)
             FieldStorageClass = None
 
+        # Propagate max_num_fields into the sub class appropriately
+        max_num_fields = self.max_num_fields
+        if max_num_fields is not None:
+            max_num_fields -= len(self.list)
+
         klass = self.FieldStorageClass or self.__class__
         part = klass(self.fp, {}, ib,
-                     environ, keep_blank_values, strict_parsing)
+                     environ, keep_blank_values, strict_parsing,
+                     max_num_fields)
+
         # Throw first part away
         while not part.done:
             headers = rfc822.Message(self.fp)
             part = klass(self.fp, headers, ib,
-                         environ, keep_blank_values, strict_parsing)
+                         environ, keep_blank_values, strict_parsing,
+                         max_num_fields)
+
+            if max_num_fields is not None:
+                max_num_fields -= 1
+                if part.list:
+                    max_num_fields -= len(part.list)
+                if max_num_fields < 0:
+                    raise ValueError('Max number of fields exceeded')
+
             self.list.append(part)
         self.skip_lines()
 
diff --git a/lib-python/2.7/cgitb.py b/lib-python/2.7/cgitb.py
--- a/lib-python/2.7/cgitb.py
+++ b/lib-python/2.7/cgitb.py
@@ -125,7 +125,7 @@
         args, varargs, varkw, locals = inspect.getargvalues(frame)
         call = ''
         if func != '?':
-            call = 'in ' + strong(func) + \
+            call = 'in ' + strong(pydoc.html.escape(func)) + \
                 inspect.formatargvalues(args, varargs, varkw, locals,
                     formatvalue=lambda value: '=' + pydoc.html.repr(value))
 
@@ -285,7 +285,7 @@
 
         if self.display:
             if plain:
-                doc = doc.replace('&', '&').replace('<', '<')
+                doc = pydoc.html.escape(doc)
                 self.file.write('<pre>' + doc + '</pre>\n')
             else:
                 self.file.write(doc + '\n')
diff --git a/lib-python/2.7/code.py b/lib-python/2.7/code.py
--- a/lib-python/2.7/code.py
+++ b/lib-python/2.7/code.py
@@ -104,12 +104,6 @@
         except SystemExit:
             raise
         except:
-            if softspace(sys.stdout, 0):
-                print
-            try:
-                sys.stdout.flush()
-            except:
-                pass
             self.showtraceback()
         else:
             if softspace(sys.stdout, 0):
diff --git a/lib-python/2.7/codecs.py b/lib-python/2.7/codecs.py
--- a/lib-python/2.7/codecs.py
+++ b/lib-python/2.7/codecs.py
@@ -472,15 +472,17 @@
             self.charbuffer = "".join(self.linebuffer)
             self.linebuffer = None
 
+        if chars < 0:
+            # For compatibility with other read() methods that take a
+            # single argument
+            chars = size
+
         # read until we get the required number of characters (if available)
         while True:
             # can the request be satisfied from the character buffer?
             if chars >= 0:
                 if len(self.charbuffer) >= chars:
                     break
-            elif size >= 0:
-                if len(self.charbuffer) >= size:
-                    break
             # we need more data
             if size < 0:
                 newdata = self.stream.read()
diff --git a/lib-python/2.7/collections.py b/lib-python/2.7/collections.py
--- a/lib-python/2.7/collections.py
+++ b/lib-python/2.7/collections.py
@@ -24,19 +24,6 @@
 import heapq as _heapq
 from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
 from itertools import imap as _imap
-try:
-    from __pypy__ import newdict
-except ImportError:
-    assert '__pypy__' not in _sys.builtin_module_names
-    newdict = lambda _ : {}
-try:
-    from __pypy__ import reversed_dict as _reversed_dict
-except ImportError:
-    _reversed_dict = None     # don't have ordered dicts
-try:
-    from __pypy__ import dict_popitem_first as _dict_popitem_first
-except ImportError:
-    _dict_popitem_first = None
 
 try:
     from thread import get_ident as _get_ident
@@ -48,104 +35,8 @@
 ### OrderedDict
 ################################################################################
 
-if _dict_popitem_first is None:
-    def _dict_popitem_first(self):
-        it = dict.iteritems(self)
-        try:
-            k, v = it.next()
-        except StopIteration:
-            raise KeyError('dictionary is empty')
-        dict.__delitem__(self, k)
-        return (k, v)
-
-
 class OrderedDict(dict):
-    '''Dictionary that remembers insertion order.
-
-    In PyPy all dicts are ordered anyway.  This is mostly useful as a
-    placeholder to mean "this dict must be ordered even on CPython".
-
-    Known difference: iterating over an OrderedDict which is being
-    concurrently modified raises RuntimeError in PyPy.  In CPython
-    instead we get some behavior that appears reasonable in some
-    cases but is nonsensical in other cases.  This is officially
-    forbidden by the CPython docs, so we forbid it explicitly for now.
-    '''
-
-    def __reversed__(self):
-        return _reversed_dict(self)
-
-    def popitem(self, last=True):
-        '''od.popitem() -> (k, v), return and remove a (key, value) pair.
-        Pairs are returned in LIFO order if last is true or FIFO order if false.
-
-        '''
-        if last:
-            return dict.popitem(self)
-        else:
-            return _dict_popitem_first(self)
-
-    def __repr__(self, _repr_running={}):
-        'od.__repr__() <==> repr(od)'
-        call_key = id(self), _get_ident()
-        if call_key in _repr_running:
-            return '...'
-        _repr_running[call_key] = 1
-        try:
-            if not self:
-                return '%s()' % (self.__class__.__name__,)
-            return '%s(%r)' % (self.__class__.__name__, self.items())
-        finally:
-            del _repr_running[call_key]
-
-    def __reduce__(self):
-        'Return state information for pickling'
-        items = [[k, self[k]] for k in self]
-        inst_dict = vars(self).copy()
-        if inst_dict:
-            return (self.__class__, (items,), inst_dict)
-        return self.__class__, (items,)
-
-    def copy(self):
-        'od.copy() -> a shallow copy of od'
-        return self.__class__(self)
-
-    def __eq__(self, other):
-        '''od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
-        while comparison to a regular mapping is order-insensitive.
-
-        '''
-        if isinstance(other, OrderedDict):
-            return dict.__eq__(self, other) and all(_imap(_eq, self, other))
-        return dict.__eq__(self, other)
-
-    def __ne__(self, other):
-        'od.__ne__(y) <==> od!=y'
-        return not self == other
-
-    # -- the following methods support python 3.x style dictionary views --
-
-    def viewkeys(self):
-        "od.viewkeys() -> a set-like object providing a view on od's keys"
-        return KeysView(self)
-
-    def viewvalues(self):
-        "od.viewvalues() -> an object providing a view on od's values"
-        return ValuesView(self)
-
-    def viewitems(self):
-        "od.viewitems() -> a set-like object providing a view on od's items"
-        return ItemsView(self)
-
-
-def _compat_with_unordered_dicts():
-    # This returns the methods needed in OrderedDict in case the base
-    # 'dict' class is not actually ordered, like on top of CPython or
-    # old PyPy or PyPy-STM.
-
-    # ===== Original comments and code follows      =====
-    # ===== The unmodified methods are not repeated =====
-
+    'Dictionary that remembers insertion order'
     # An inherited dict maps keys to values.
     # The inherited dict provides __getitem__, __len__, __contains__, and get.
     # The remaining methods are order-aware.
@@ -156,12 +47,17 @@
     # The sentinel element never gets deleted (this simplifies the algorithm).
     # Each link is stored as a list of length three:  [PREV, NEXT, KEY].
 
-    def __init__(self, *args, **kwds):
+    def __init__(*args, **kwds):
         '''Initialize an ordered dictionary.  The signature is the same as
         regular dictionaries, but keyword arguments are not recommended because
         their insertion order is arbitrary.
 
         '''
+        if not args:
+            raise TypeError("descriptor '__init__' of 'OrderedDict' object "
+                            "needs an argument")
+        self = args[0]
+        args = args[1:]
         if len(args) > 1:
             raise TypeError('expected at most 1 arguments, got %d' % len(args))
         try:
@@ -282,6 +178,19 @@
         value = self.pop(key)
         return key, value
 
+    def __repr__(self, _repr_running={}):
+        'od.__repr__() <==> repr(od)'
+        call_key = id(self), _get_ident()
+        if call_key in _repr_running:
+            return '...'
+        _repr_running[call_key] = 1
+        try:
+            if not self:
+                return '%s()' % (self.__class__.__name__,)
+            return '%s(%r)' % (self.__class__.__name__, self.items())
+        finally:
+            del _repr_running[call_key]
+
     def __reduce__(self):
         'Return state information for pickling'
         items = [[k, self[k]] for k in self]
@@ -292,6 +201,10 @@
             return (self.__class__, (items,), inst_dict)
         return self.__class__, (items,)
 
+    def copy(self):
+        'od.copy() -> a shallow copy of od'
+        return self.__class__(self)
+
     @classmethod
     def fromkeys(cls, iterable, value=None):
         '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
@@ -303,12 +216,33 @@
             self[key] = value
         return self
 
-    return locals()
+    def __eq__(self, other):
+        '''od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
+        while comparison to a regular mapping is order-insensitive.
 
-if _reversed_dict is None:
-    for _key, _value in _compat_with_unordered_dicts().items():
-        setattr(OrderedDict, _key, _value)
-    del _key, _value
+        '''
+        if isinstance(other, OrderedDict):
+            return dict.__eq__(self, other) and all(_imap(_eq, self, other))
+        return dict.__eq__(self, other)
+
+    def __ne__(self, other):
+        'od.__ne__(y) <==> od!=y'
+        return not self == other
+
+    # -- the following methods support python 3.x style dictionary views --
+
+    def viewkeys(self):
+        "od.viewkeys() -> a set-like object providing a view on od's keys"
+        return KeysView(self)
+
+    def viewvalues(self):
+        "od.viewvalues() -> an object providing a view on od's values"
+        return ValuesView(self)
+
+    def viewitems(self):
+        "od.viewitems() -> a set-like object providing a view on od's items"
+        return ItemsView(self)
+
 
 ################################################################################
 ### namedtuple
@@ -365,7 +299,7 @@
 _repr_template = '{name}=%r'
 
 _field_template = '''\
-    {name} = _property(lambda self: self[{index:d}], doc='Alias for field number {index:d}')
+    {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
 '''
 
 def namedtuple(typename, field_names, verbose=False, rename=False):
@@ -446,11 +380,8 @@
 
     # Execute the template string in a temporary namespace and support
     # tracing utilities by setting a value for frame.f_globals['__name__']
-    namespace = newdict('module')
-    namespace['__name__'] = 'namedtuple_%s' % typename
-    namespace['OrderedDict'] = OrderedDict
-    namespace['_property'] = property
-    namespace['_tuple'] = tuple
+    namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
+                     OrderedDict=OrderedDict, _property=property, _tuple=tuple)
     try:
         exec class_definition in namespace
     except SyntaxError as e:
diff --git a/lib-python/2.7/compiler/pyassem.py b/lib-python/2.7/compiler/pyassem.py
--- a/lib-python/2.7/compiler/pyassem.py
+++ b/lib-python/2.7/compiler/pyassem.py
@@ -581,7 +581,7 @@
 
 def twobyte(val):
     """Convert an int argument into high and low bytes"""
-    assert isinstance(val, int)
+    assert isinstance(val, (int, long))
     return divmod(val, 256)
 
 class LineAddrTable:
diff --git a/lib-python/2.7/compiler/transformer.py b/lib-python/2.7/compiler/transformer.py
--- a/lib-python/2.7/compiler/transformer.py
+++ b/lib-python/2.7/compiler/transformer.py
@@ -1526,7 +1526,7 @@
 def debug_tree(tree):
     l = []
     for elt in tree:
-        if isinstance(elt, int):
+        if isinstance(elt, (int, long)):
             l.append(_names.get(elt, elt))
         elif isinstance(elt, str):
             l.append(elt)
diff --git a/lib-python/2.7/copy_reg.py b/lib-python/2.7/copy_reg.py
--- a/lib-python/2.7/copy_reg.py
+++ b/lib-python/2.7/copy_reg.py
@@ -127,7 +127,11 @@
                         continue
                     # mangled names
                     elif name.startswith('__') and not name.endswith('__'):
-                        names.append('_%s%s' % (c.__name__, name))
+                        stripped = c.__name__.lstrip('_')
+                        if stripped:
+                            names.append('_%s%s' % (stripped, name))
+                        else:
+                            names.append(name)
                     else:
                         names.append(name)
 
diff --git a/lib-python/2.7/csv.py b/lib-python/2.7/csv.py
--- a/lib-python/2.7/csv.py
+++ b/lib-python/2.7/csv.py
@@ -217,7 +217,7 @@
         matches = []
         for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
                       '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)',   #  ".*?",
-                      '(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)',  # ,".*?"
+                      '(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)',   # ,".*?"
                       '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'):                            #  ".*?" (no delim, no space)
             regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
             matches = regexp.findall(data)
diff --git a/lib-python/2.7/ctypes/__init__.py b/lib-python/2.7/ctypes/__init__.py
--- a/lib-python/2.7/ctypes/__init__.py
+++ b/lib-python/2.7/ctypes/__init__.py
@@ -4,7 +4,6 @@
 
 __version__ = "1.1.0"
 
-import _ffi
 from _ctypes import Union, Structure, Array
 from _ctypes import _Pointer
 from _ctypes import CFuncPtr as _CFuncPtr
@@ -343,6 +342,10 @@
     """
     _func_flags_ = _FUNCFLAG_CDECL
     _func_restype_ = c_int
+    # default values for repr
+    _name = '<uninitialized>'
+    _handle = 0
+    _FuncPtr = None
 
     def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                  use_errno=False,
@@ -360,16 +363,9 @@
         self._FuncPtr = _FuncPtr
 
         if handle is None:
-            handle = 0
-        if flags & _FUNCFLAG_CDECL:
-            pypy_dll = _ffi.CDLL(name, mode, handle)
+            self._handle = _dlopen(self._name, mode)
         else:
-            pypy_dll = _ffi.WinDLL(name, mode, handle)
-        self.__pypy_dll__ = pypy_dll
-        handle = int(pypy_dll)
-        if _sys.maxint > 2 ** 32:
-            handle = int(handle)   # long -> int
-        self._handle = handle
+            self._handle = handle
 
     def __repr__(self):
         return "<%s '%s', handle %x at %x>" % \
@@ -390,13 +386,12 @@
             func.__name__ = name_or_ordinal
         return func
 
-# Not in PyPy
-#class PyDLL(CDLL):
-#    """This class represents the Python library itself.  It allows
-#    accessing Python API functions.  The GIL is not released, and
-#    Python exceptions are handled correctly.
-#    """
-#    _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
+class PyDLL(CDLL):
+    """This class represents the Python library itself.  It allows
+    accessing Python API functions.  The GIL is not released, and
+    Python exceptions are handled correctly.
+    """
+    _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
 
 if _os.name in ("nt", "ce"):
 
@@ -449,8 +444,15 @@
         return self._dlltype(name)
 
 cdll = LibraryLoader(CDLL)
-# not on PyPy
-#pydll = LibraryLoader(PyDLL)
+pydll = LibraryLoader(PyDLL)
+
+if _os.name in ("nt", "ce"):
+    pythonapi = PyDLL("python dll", None, _sys.dllhandle)
+elif _sys.platform == "cygwin":
+    pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
+else:
+    pythonapi = PyDLL(None)
+
 
 if _os.name in ("nt", "ce"):
     windll = LibraryLoader(WinDLL)
@@ -496,12 +498,9 @@
         _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
     return CFunctionType
 
+_cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)(_cast_addr)
 def cast(obj, typ):
-    try:
-        c_void_p.from_param(obj)
-    except TypeError, e:
-        raise ArgumentError(str(e))
-    return _cast_addr(obj, obj, typ)
+    return _cast(obj, obj, typ)
 
 _string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
 def string_at(ptr, size=-1):
diff --git a/lib-python/2.7/ctypes/test/__init__.py b/lib-python/2.7/ctypes/test/__init__.py
--- a/lib-python/2.7/ctypes/test/__init__.py
+++ b/lib-python/2.7/ctypes/test/__init__.py
@@ -214,16 +214,3 @@
         result = unittest.TestResult()
         test(result)
         return result
-
-def xfail(method):
-    """
-    Poor's man xfail: remove it when all the failures have been fixed
-    """
-    def new_method(self, *args, **kwds):
-        try:
-            method(self, *args, **kwds)
-        except:
-            pass
-        else:
-            self.assertTrue(False, "DID NOT RAISE")
-    return new_method
diff --git a/lib-python/2.7/ctypes/test/test_anon.py b/lib-python/2.7/ctypes/test/test_anon.py
--- a/lib-python/2.7/ctypes/test/test_anon.py
+++ b/lib-python/2.7/ctypes/test/test_anon.py
@@ -1,4 +1,5 @@
 import unittest
+from test.support import cpython_only
 from ctypes import *
 
 class AnonTest(unittest.TestCase):
@@ -35,6 +36,18 @@
                                                       {"_fields_": [],
                                                        "_anonymous_": ["x"]}))
 
+    @cpython_only
+    def test_issue31490(self):
+        # There shouldn't be an assertion failure in case the class has an
+        # attribute whose name is specified in _anonymous_ but not in _fields_.
+
+        # AttributeError: 'x' is specified in _anonymous_ but not in _fields_
+        with self.assertRaises(AttributeError):
+            class Name(Structure):
+                _fields_ = []
+                _anonymous_ = ["x"]
+                x = 42
+
     def test_nested(self):
         class ANON_S(Structure):
             _fields_ = [("a", c_int)]
diff --git a/lib-python/2.7/ctypes/test/test_arrays.py b/lib-python/2.7/ctypes/test/test_arrays.py
--- a/lib-python/2.7/ctypes/test/test_arrays.py
+++ b/lib-python/2.7/ctypes/test/test_arrays.py
@@ -1,25 +1,16 @@
 import unittest
+from test.support import precisionbigmemtest, _2G
+import sys
 from ctypes import *
-from test.test_support import impl_detail
 
 from ctypes.test import need_symbol
 
 formats = "bBhHiIlLqQfd"
 
-# c_longdouble commented out for PyPy, look at the commend in test_longdouble
 formats = c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, \
-          c_long, c_ulonglong, c_float, c_double #, c_longdouble
+          c_long, c_ulonglong, c_float, c_double, c_longdouble
 
 class ArrayTestCase(unittest.TestCase):
-
-    @impl_detail('long double not supported by PyPy', pypy=False)
-    def test_longdouble(self):
-        """
-        This test is empty. It's just here to remind that we commented out
-        c_longdouble in "formats". If pypy will ever supports c_longdouble, we
-        should kill this test and uncomment c_longdouble inside formats.
-        """
-
     def test_simple(self):
         # create classes holding simple numeric types, and check
         # various properties.
@@ -143,5 +134,10 @@
         t2 = my_int * 1
         self.assertIs(t1, t2)
 
+    @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
+    @precisionbigmemtest(size=_2G, memuse=1, dry_run=False)
+    def test_large_array(self, size):
+        a = c_char * size
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_as_parameter.py b/lib-python/2.7/ctypes/test/test_as_parameter.py
--- a/lib-python/2.7/ctypes/test/test_as_parameter.py
+++ b/lib-python/2.7/ctypes/test/test_as_parameter.py
@@ -24,7 +24,7 @@
         f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
         result = f(self.wrap(1), self.wrap(u"x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
         self.assertEqual(result, 139)
-        self.assertTrue(type(result), int)
+        self.assertIs(type(result), int)
 
     def test_pointers(self):
         f = dll._testfunc_p_p
diff --git a/lib-python/2.7/ctypes/test/test_bitfields.py b/lib-python/2.7/ctypes/test/test_bitfields.py
--- a/lib-python/2.7/ctypes/test/test_bitfields.py
+++ b/lib-python/2.7/ctypes/test/test_bitfields.py
@@ -1,8 +1,7 @@
 from ctypes import *
-from ctypes.test import need_symbol, xfail
+from ctypes.test import need_symbol
 import unittest
 import os
-import sys
 
 import ctypes
 import _ctypes_test
@@ -117,28 +116,23 @@
     def test_nonint_types(self):
         # bit fields are not allowed on non-integer types.
         result = self.fail_fields(("a", c_char_p, 1))
-        self.assertEqual(result[0], TypeError)
-        self.assertIn('bit fields not allowed for type', result[1])
+        self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_char_p'))
 
         result = self.fail_fields(("a", c_void_p, 1))
-        self.assertEqual(result[0], TypeError)
-        self.assertIn('bit fields not allowed for type', result[1])
+        self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_void_p'))
 
         if c_int != c_long:
             result = self.fail_fields(("a", POINTER(c_int), 1))
-            self.assertEqual(result[0], TypeError)
-            self.assertIn('bit fields not allowed for type', result[1])
+            self.assertEqual(result, (TypeError, 'bit fields not allowed for type LP_c_int'))
 
         result = self.fail_fields(("a", c_char, 1))
-        self.assertEqual(result[0], TypeError)
-        self.assertIn('bit fields not allowed for type', result[1])
+        self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_char'))
 
         class Dummy(Structure):
             _fields_ = []
 
         result = self.fail_fields(("a", Dummy, 1))
-        self.assertEqual(result[0], TypeError)
-        self.assertIn('bit fields not allowed for type', result[1])
+        self.assertEqual(result, (TypeError, 'bit fields not allowed for type Dummy'))
 
     @need_symbol('c_wchar')
     def test_c_wchar(self):
@@ -272,13 +266,12 @@
             _fields_ = [("a", c_uint32, 24),
                         ("b", c_uint32, 4),
                         ("c", c_uint32, 4)]
-        import array
-        b = array.array("c", '\x00' * 4)
+        b = bytearray(4)
         x = Little.from_buffer(b)
         x.a = 0xabcdef
         x.b = 1
         x.c = 2
-        self.assertEqual(b.tostring(), b'\xef\xcd\xab\x21')
+        self.assertEqual(b, b'\xef\xcd\xab\x21')
 
     @need_symbol('c_uint32')
     def test_uint32_swap_big_endian(self):
@@ -287,19 +280,12 @@
             _fields_ = [("a", c_uint32, 24),
                         ("b", c_uint32, 4),
                         ("c", c_uint32, 4)]
-        import array
-        b = array.array("c", '\x00' * 4)
+        b = bytearray(4)
         x = Big.from_buffer(b)
         x.a = 0xabcdef
         x.b = 1
         x.c = 2
-        self.assertEqual(b.tostring(), b'\xab\xcd\xef\x12')
-
-    # see issue #1213, on big endian it fails for the little endian case
-    if sys.byteorder == 'little':
-        test_uint32_swap_big_endian = xfail(test_uint32_swap_big_endian)
-    elif sys.byteorder == 'big':
-        test_uint32_swap_little_endian = xfail(test_uint32_swap_little_endian)
+        self.assertEqual(b, b'\xab\xcd\xef\x12')
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_byteswap.py b/lib-python/2.7/ctypes/test/test_byteswap.py
--- a/lib-python/2.7/ctypes/test/test_byteswap.py
+++ b/lib-python/2.7/ctypes/test/test_byteswap.py
@@ -2,7 +2,6 @@
 from binascii import hexlify
 
 from ctypes import *
-from ctypes.test import xfail
 
 def bin(s):
     return hexlify(memoryview(s)).upper()
diff --git a/lib-python/2.7/ctypes/test/test_callbacks.py b/lib-python/2.7/ctypes/test/test_callbacks.py
--- a/lib-python/2.7/ctypes/test/test_callbacks.py
+++ b/lib-python/2.7/ctypes/test/test_callbacks.py
@@ -2,7 +2,6 @@
 import unittest
 from ctypes import *
 from ctypes.test import need_symbol
-from ctypes.test import xfail
 import _ctypes_test
 
 class Callbacks(unittest.TestCase):
@@ -102,7 +101,6 @@
         self.check_type(c_char_p, "abc")
         self.check_type(c_char_p, "def")
 
-    @xfail
     def test_pyobject(self):
         o = ()
         from sys import getrefcount as grc
@@ -252,6 +250,7 @@
     def test_callback_large_struct(self):
         class Check: pass
 
+        # This should mirror the structure in Modules/_ctypes/_ctypes_test.c
         class X(Structure):
             _fields_ = [
                 ('first', c_ulong),
@@ -263,6 +262,11 @@
             check.first = s.first
             check.second = s.second
             check.third = s.third
+            # See issue #29565.
+            # The structure should be passed by value, so
+            # any changes to it should not be reflected in
+            # the value passed
+            s.first = s.second = s.third = 0x0badf00d
 
         check = Check()
         s = X()
@@ -283,6 +287,11 @@
         self.assertEqual(check.first, 0xdeadbeef)
         self.assertEqual(check.second, 0xcafebabe)
         self.assertEqual(check.third, 0x0bad1dea)
+        # See issue #29565.
+        # Ensure that the original struct is unchanged.
+        self.assertEqual(s.first, check.first)
+        self.assertEqual(s.second, check.second)
+        self.assertEqual(s.third, check.third)
 
 ################################################################
 
diff --git a/lib-python/2.7/ctypes/test/test_cfuncs.py b/lib-python/2.7/ctypes/test/test_cfuncs.py
--- a/lib-python/2.7/ctypes/test/test_cfuncs.py
+++ b/lib-python/2.7/ctypes/test/test_cfuncs.py
@@ -6,7 +6,6 @@
 from ctypes.test import need_symbol
 
 import _ctypes_test
-from test.test_support import impl_detail
 
 class CFunctions(unittest.TestCase):
     _dll = CDLL(_ctypes_test.__file__)
@@ -160,14 +159,12 @@
         self.assertEqual(self._dll.tf_bd(0, 42.), 14.)
         self.assertEqual(self.S(), 42)
 
-    @impl_detail('long double not supported by PyPy', pypy=False)
     def test_longdouble(self):
         self._dll.tf_D.restype = c_longdouble
         self._dll.tf_D.argtypes = (c_longdouble,)
         self.assertEqual(self._dll.tf_D(42.), 14.)
         self.assertEqual(self.S(), 42)
 
-    @impl_detail('long double not supported by PyPy', pypy=False)
     def test_longdouble_plus(self):
         self._dll.tf_bD.restype = c_longdouble
         self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
diff --git a/lib-python/2.7/ctypes/test/test_delattr.py b/lib-python/2.7/ctypes/test/test_delattr.py
--- a/lib-python/2.7/ctypes/test/test_delattr.py
+++ b/lib-python/2.7/ctypes/test/test_delattr.py
@@ -6,15 +6,15 @@
 
 class TestCase(unittest.TestCase):
     def test_simple(self):
-        self.assertRaises((TypeError, AttributeError),
+        self.assertRaises(TypeError,
                           delattr, c_int(42), "value")
 
     def test_chararray(self):
-        self.assertRaises((TypeError, AttributeError),
+        self.assertRaises(TypeError,
                           delattr, (c_char * 5)(), "value")
 
     def test_struct(self):
-        self.assertRaises((TypeError, AttributeError),
+        self.assertRaises(TypeError,
                           delattr, X(), "foo")
 
 if __name__ == "__main__":
diff --git a/lib-python/2.7/ctypes/test/test_frombuffer.py b/lib-python/2.7/ctypes/test/test_frombuffer.py
--- a/lib-python/2.7/ctypes/test/test_frombuffer.py
+++ b/lib-python/2.7/ctypes/test/test_frombuffer.py
@@ -78,12 +78,21 @@
                           (c_int * 1).from_buffer_copy, a, 16 * sizeof(c_int))
 
     def test_abstract(self):
+        from ctypes import _Pointer, _SimpleCData, _CFuncPtr
+
         self.assertRaises(TypeError, Array.from_buffer, bytearray(10))
         self.assertRaises(TypeError, Structure.from_buffer, bytearray(10))
         self.assertRaises(TypeError, Union.from_buffer, bytearray(10))
+        self.assertRaises(TypeError, _CFuncPtr.from_buffer, bytearray(10))
+        self.assertRaises(TypeError, _Pointer.from_buffer, bytearray(10))
+        self.assertRaises(TypeError, _SimpleCData.from_buffer, bytearray(10))
+
         self.assertRaises(TypeError, Array.from_buffer_copy, b"123")
         self.assertRaises(TypeError, Structure.from_buffer_copy, b"123")
         self.assertRaises(TypeError, Union.from_buffer_copy, b"123")
+        self.assertRaises(TypeError, _CFuncPtr.from_buffer_copy, b"123")
+        self.assertRaises(TypeError, _Pointer.from_buffer_copy, b"123")
+        self.assertRaises(TypeError, _SimpleCData.from_buffer_copy, b"123")
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_funcptr.py b/lib-python/2.7/ctypes/test/test_funcptr.py
--- a/lib-python/2.7/ctypes/test/test_funcptr.py
+++ b/lib-python/2.7/ctypes/test/test_funcptr.py
@@ -123,5 +123,10 @@
         self.assertEqual(strtok(None, "\n"), "c")
         self.assertEqual(strtok(None, "\n"), None)
 
+    def test_abstract(self):
+        from ctypes import _CFuncPtr
+
+        self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid")
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_functions.py b/lib-python/2.7/ctypes/test/test_functions.py
--- a/lib-python/2.7/ctypes/test/test_functions.py
+++ b/lib-python/2.7/ctypes/test/test_functions.py
@@ -8,8 +8,6 @@
 from ctypes import *
 from ctypes.test import need_symbol
 import sys, unittest
-from ctypes.test import xfail
-from test.test_support import impl_detail
 
 try:
     WINFUNCTYPE
@@ -140,7 +138,6 @@
         self.assertEqual(result, -21)
         self.assertEqual(type(result), float)
 
-    @impl_detail('long double not supported by PyPy', pypy=False)
     def test_longdoubleresult(self):
         f = dll._testfunc_D_bhilfD
         f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
@@ -391,7 +388,6 @@
                 (s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
                 (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
 
-    @xfail
     def test_sf1651235(self):
         # see http://www.python.org/sf/1651235
 
diff --git a/lib-python/2.7/ctypes/test/test_internals.py b/lib-python/2.7/ctypes/test/test_internals.py
--- a/lib-python/2.7/ctypes/test/test_internals.py
+++ b/lib-python/2.7/ctypes/test/test_internals.py
@@ -1,10 +1,7 @@
 # This tests the internal _objects attribute
 import unittest
 from ctypes import *
-try:
-    from sys import getrefcount as grc
-except ImportError:
-    grc = None      # e.g. PyPy
+from sys import getrefcount as grc
 
 # XXX This test must be reviewed for correctness!!!
 
@@ -25,8 +22,6 @@
         self.assertEqual(id(a), id(b))
 
     def test_ints(self):
-        if grc is None:
-            return unittest.skip("no sys.getrefcount()")
         i = 42000123
         refcnt = grc(i)
         ci = c_int(i)
@@ -34,19 +29,11 @@
         self.assertEqual(ci._objects, None)
 
     def test_c_char_p(self):
-        if grc is None:
-            return unittest.skip("no sys.getrefcount()")
         s = "Hello, World"
         refcnt = grc(s)
         cs = c_char_p(s)
         self.assertEqual(refcnt + 1, grc(s))
-        try:
-            # Moving gcs need to allocate a nonmoving buffer
-            cs._objects._obj
-        except AttributeError:
-            self.assertSame(cs._objects, s)
-        else:
-            self.assertSame(cs._objects._obj, s)
+        self.assertSame(cs._objects, s)
 
     def test_simple_struct(self):
         class X(Structure):
diff --git a/lib-python/2.7/ctypes/test/test_libc.py b/lib-python/2.7/ctypes/test/test_libc.py
--- a/lib-python/2.7/ctypes/test/test_libc.py
+++ b/lib-python/2.7/ctypes/test/test_libc.py
@@ -25,14 +25,5 @@
         lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort))
         self.assertEqual(chars.raw, "   ,,aaaadmmmnpppsss\x00")
 
-    def SKIPPED_test_no_more_xfail(self):
-        # We decided to not explicitly support the whole ctypes-2.7
-        # and instead go for a case-by-case, demand-driven approach.
-        # So this test is skipped instead of failing.
-        import socket
-        import ctypes.test
-        self.assertTrue(not hasattr(ctypes.test, 'xfail'),
-                        "You should incrementally grep for '@xfail' and remove them, they are real failures")
-
 if __name__ == "__main__":
     unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_loading.py b/lib-python/2.7/ctypes/test/test_loading.py
--- a/lib-python/2.7/ctypes/test/test_loading.py
+++ b/lib-python/2.7/ctypes/test/test_loading.py
@@ -2,7 +2,8 @@
 import sys, unittest
 import os
 from ctypes.util import find_library
-from ctypes.test import is_resource_enabled, xfail
+from ctypes.test import is_resource_enabled
+import test.test_support as support
 
 libc_name = None
 if os.name == "nt":
@@ -27,6 +28,12 @@
         CDLL(os.path.basename(libc_name))
         self.assertRaises(OSError, CDLL, self.unknowndll)
 
+    @support.requires_unicode
+    @unittest.skipUnless(libc_name is not None, 'could not find libc')
+    def test_load_unicode(self):
+        CDLL(unicode(libc_name))
+        self.assertRaises(OSError, CDLL, unicode(self.unknowndll))
+
     @unittest.skipUnless(libc_name is not None, 'could not find libc')
     @unittest.skipUnless(libc_name is not None and
                          os.path.basename(libc_name) == "libc.so.6",
@@ -80,7 +87,6 @@
 
         self.assertRaises(AttributeError, dll.__getitem__, 1234)
 
-    @xfail
     @unittest.skipUnless(os.name == "nt", 'Windows-specific test')
     def test_1703286_A(self):
         from _ctypes import LoadLibrary, FreeLibrary
@@ -92,7 +98,6 @@
         handle = LoadLibrary("advapi32")
         FreeLibrary(handle)
 
-    @xfail
     @unittest.skipUnless(os.name == "nt", 'Windows-specific test')
     def test_1703286_B(self):
         # Since on winXP 64-bit advapi32 loads like described
diff --git a/lib-python/2.7/ctypes/test/test_memfunctions.py b/lib-python/2.7/ctypes/test/test_memfunctions.py
--- a/lib-python/2.7/ctypes/test/test_memfunctions.py
+++ b/lib-python/2.7/ctypes/test/test_memfunctions.py
@@ -55,8 +55,7 @@
         s = string_at("foo bar")
         # XXX The following may be wrong, depending on how Python
         # manages string instances
-        if hasattr(sys, 'getrefcount'):
-            self.assertEqual(2, sys.getrefcount(s))
+        self.assertEqual(2, sys.getrefcount(s))
         self.assertTrue(s, "foo bar")
 
         self.assertEqual(string_at("foo bar", 8), "foo bar\0")
diff --git a/lib-python/2.7/ctypes/test/test_numbers.py b/lib-python/2.7/ctypes/test/test_numbers.py
--- a/lib-python/2.7/ctypes/test/test_numbers.py
+++ b/lib-python/2.7/ctypes/test/test_numbers.py
@@ -1,7 +1,6 @@
 from ctypes import *
 import unittest
 import struct
-from ctypes.test import xfail
 
 def valid_ranges(*types):
     # given a sequence of numeric types, collect their _type_
@@ -91,14 +90,12 @@
             self.assertRaises(ValueError, t, l-1)
             self.assertRaises(ValueError, t, h+1)
 
-    @xfail
     def test_from_param(self):
         # the from_param class method attribute always
         # returns PyCArgObject instances
         for t in signed_types + unsigned_types + float_types:
             self.assertEqual(ArgType, type(t.from_param(0)))
 
-    @xfail
     def test_byref(self):
         # calling byref returns also a PyCArgObject instance
         for t in signed_types + unsigned_types + float_types + bool_types:
@@ -119,7 +116,6 @@
             self.assertEqual(t(2L).value, 2.0)
             self.assertEqual(t(f).value, 2.0)
 
-    @xfail
     def test_integers(self):
         class FloatLike(object):
             def __float__(self):
diff --git a/lib-python/2.7/ctypes/test/test_objects.py b/lib-python/2.7/ctypes/test/test_objects.py
--- a/lib-python/2.7/ctypes/test/test_objects.py
+++ b/lib-python/2.7/ctypes/test/test_objects.py
@@ -22,7 +22,7 @@
 
 >>> array[4] = 'foo bar'
 >>> array._objects
-{'4': <CArgObject 'foo bar'>}
+{'4': 'foo bar'}
 >>> array[4]
 'foo bar'
 >>>
@@ -47,9 +47,9 @@
 
 >>> x.array[0] = 'spam spam spam'
 >>> x._objects
-{'0:2': <CArgObject 'spam spam spam'>}
+{'0:2': 'spam spam spam'}
 >>> x.array._b_base_._objects
-{'0:2': <CArgObject 'spam spam spam'>}
+{'0:2': 'spam spam spam'}
 >>>
 
 '''
diff --git a/lib-python/2.7/ctypes/test/test_parameters.py b/lib-python/2.7/ctypes/test/test_parameters.py
--- a/lib-python/2.7/ctypes/test/test_parameters.py
+++ b/lib-python/2.7/ctypes/test/test_parameters.py
@@ -1,7 +1,6 @@
 import unittest, sys
 from ctypes.test import need_symbol
-
-from ctypes.test import xfail
+import test.support
 
 class SimpleTypesTestCase(unittest.TestCase):
 
@@ -51,7 +50,6 @@
         self.assertEqual(CWCHARP.from_param("abc"), "abcabcabc")
 
     # XXX Replace by c_char_p tests
-    @xfail
     def test_cstrings(self):
         from ctypes import c_char_p, byref
 
@@ -85,10 +83,7 @@
 
         pa = c_wchar_p.from_param(c_wchar_p(u"123"))
         self.assertEqual(type(pa), c_wchar_p)
-    if sys.platform == "win32":
-        test_cw_strings = xfail(test_cw_strings)
 
-    @xfail
     def test_int_pointers(self):
         from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
         LPINT = POINTER(c_int)
@@ -180,6 +175,36 @@
         # ArgumentError: argument 1: ValueError: 99
         self.assertRaises(ArgumentError, func, 99)
 
+    def test_abstract(self):
+        from ctypes import (Array, Structure, Union, _Pointer,
+                            _SimpleCData, _CFuncPtr)
+
+        self.assertRaises(TypeError, Array.from_param, 42)
+        self.assertRaises(TypeError, Structure.from_param, 42)
+        self.assertRaises(TypeError, Union.from_param, 42)
+        self.assertRaises(TypeError, _CFuncPtr.from_param, 42)
+        self.assertRaises(TypeError, _Pointer.from_param, 42)
+        self.assertRaises(TypeError, _SimpleCData.from_param, 42)
+
+    @test.support.cpython_only
+    def test_issue31311(self):
+        # __setstate__ should neither raise a SystemError nor crash in case
+        # of a bad __dict__.
+        from ctypes import Structure
+
+        class BadStruct(Structure):
+            @property


More information about the pypy-commit mailing list