1. Wubin Qu
  2. pypy

Commits

Amaury Forgeot d'Arc  committed 185a699 Merge

hg merge default

  • Participants
  • Parent commits 175a3fd, b7ae2a1
  • Branches py3k

Comments (0)

Files changed (12)

File lib-python/2.7/test/test_winreg.py

View file
 # Test the windows specific win32reg module.
 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
 
-import os, sys
+import os, sys, errno
 import unittest
 from test import test_support
 threading = test_support.import_module("threading")
     def test_dynamic_key(self):
         # Issue2810, when the value is dynamically generated, these
         # throw "WindowsError: More data is available" in 2.6 and 3.1
-        EnumValue(HKEY_PERFORMANCE_DATA, 0)
+        try:
+            EnumValue(HKEY_PERFORMANCE_DATA, 0)
+        except OSError as e:
+            if e.errno in (errno.EPERM, errno.EACCES):
+                self.skipTest("access denied to registry key "
+                              "(are you running in a non-interactive session?)")
+            raise
         QueryValueEx(HKEY_PERFORMANCE_DATA, None)
 
     # Reflection requires XP x64/Vista at a minimum. XP doesn't have this stuff

File lib-python/conftest.py

View file
     RegrTest('test_isinstance.py', core=True),
     RegrTest('test_iter.py', core=True),
     RegrTest('test_iterlen.py'),
-    RegrTest('test_itertools.py', core=True),
+    RegrTest('test_itertools.py', core=True, usemodules="itertools struct"),
     RegrTest('test_json.py'),
     RegrTest('test_keywordonlyarg.py'),
     RegrTest('test_kqueue.py'),

File pypy/interpreter/astcompiler/optimize.py

View file
 
     def as_constant_truth(self, space):
         """Return the truth of this node if known."""
-        raise AssertionError("only for expressions")
-
-    def as_constant(self):
-        """Return the value of this node as a wrapped constant if possible."""
-        raise AssertionError("only for expressions")
-
-    def accept_jump_if(self, gen, condition, target):
-        raise AssertionError("only for expressions")
-
-
-class __extend__(ast.expr):
-
-    def as_constant_truth(self, space):
         const = self.as_constant()
         if const is None:
             return CONST_NOT_CONST
         return int(space.is_true(const))
 
     def as_constant(self):
+        """Return the value of this node as a wrapped constant if possible."""
         return None
 
     def accept_jump_if(self, gen, condition, target):
+        raise AssertionError("only for expressions")
+
+
+class __extend__(ast.expr):
+
+    def accept_jump_if(self, gen, condition, target):
         self.walkabout(gen)
         if condition:
             gen.emit_jump(ops.POP_JUMP_IF_TRUE, target, True)

File pypy/interpreter/test/test_compiler.py

View file
             ('a = 14%4', '(2)'),                    # binary modulo
             ('a = 2+3', '(5)'),                     # binary add
             ('a = 13-4', '(9)'),                    # binary subtract
-            # ('a = (12,13)[1]', '(13)'),             # binary subscr - pointless optimization
+            ('a = (12,13)[1]', '(13)'),             # binary subscr
             ('a = 13 << 2', '(52)'),                # binary lshift
             ('a = 13 >> 2', '(3)'),                 # binary rshift
             ('a = 13 & 7', '(5)'),                  # binary and
         asm = dis_single('a="x"*1000')
         assert '(1000)' in asm
 
+    def test_folding_of_binops_on_constants_crash(self):
+        compile('()[...]', '', 'eval')
+        # assert did not crash
+
     def test_dis_stopcode(self):
         source = """def _f(a):
                 print(a)

File pypy/module/_cffi_backend/test/_backend_test_c.py

View file
     mandatory_b_prefix = 'b'
     mandatory_u_prefix = ''
     readbuf = lambda buf: buf.tobytes()
-    bufchar = ord
+    if sys.version_info < (3, 3):
+        bufchar = lambda x: bytes([ord(x)])
+    else:
+        bufchar = ord
     bytechr = lambda n: bytes([n])
     u = ""
 
                                        ('j', BInt, -1)])
     BFunc21 = new_function_type((BStruct,), BInt, False)
     f = cast(BFunc21, _testfunc(21))
-    res = f(range(13, 3, -1))
+    res = f(list(range(13, 3, -1)))
     lst = [(n << i) for (i, n) in enumerate(range(13, 3, -1))]
     assert res == sum(lst)
 
                                        ('i', BInt, -1),
                                        ('j', BInt, -1)])
     def cb():
-        return newp(BStructPtr, range(13, 3, -1))[0]
+        return newp(BStructPtr, list(range(13, 3, -1)))[0]
     BFunc = new_function_type((), BStruct)
     f = callback(BFunc, cb)
     s = f()
     c[2] = b'-'
     buf[:2] = b'HI'
     assert string(c) == b'HI-there'
-    assert buf[:4:2] == b'H-'
-    if '__pypy__' not in sys.builtin_module_names:
-        # XXX pypy doesn't support the following assignment so far
-        buf[:4:2] = b'XY'
-        assert string(c) == b'XIYthere'
+    if sys.version_info < (3,) or sys.version_info >= (3, 3):
+        assert buf[:4:2] == b'H-'
+        if '__pypy__' not in sys.builtin_module_names:
+            # XXX pypy doesn't support the following assignment so far
+            buf[:4:2] = b'XY'
+            assert string(c) == b'XIYthere'
 
 def test_getcname():
     BUChar = new_primitive_type("unsigned char")

File pypy/module/_rawffi/__init__.py

View file
         'get_libc'           : 'interp_rawffi.get_libc',
         'get_errno'          : 'interp_rawffi.get_errno',
         'set_errno'          : 'interp_rawffi.set_errno',
+        'get_last_error'     : 'interp_rawffi.get_last_error',
+        'set_last_error'     : 'interp_rawffi.set_last_error',
         'SegfaultException'  : 'space.new_exception_class("_rawffi.SegfaultException")',
     }
 
-    if sys.platform == 'win32':
-        interpleveldefs['get_last_error'] = 'interp_rawffi.get_last_error'
-        interpleveldefs['set_last_error'] = 'interp_rawffi.set_last_error'
-
     appleveldefs = {
     }
 

File pypy/module/_rawffi/interp_rawffi.py

View file
 def set_errno(space, w_errno):
     rposix.set_errno(space.int_w(w_errno))
 
-def get_last_error(space):
-    from pypy.rlib.rwin32 import GetLastError
-    return space.wrap(GetLastError())
-
-@unwrap_spec(error=int)
-def set_last_error(space, error):
-    from pypy.rlib.rwin32 import SetLastError
-    SetLastError(error)
+if sys.platform == 'win32':
+    def get_last_error(space):
+        from pypy.rlib.rwin32 import GetLastError
+        return space.wrap(GetLastError())
+    @unwrap_spec(error=int)
+    def set_last_error(space, error):
+        from pypy.rlib.rwin32 import SetLastError
+        SetLastError(error)
+else:
+    # always have at least a dummy version of these functions
+    # (https://bugs.pypy.org/issue1242)
+    def get_last_error(space):
+        return space.wrap(0)
+    @unwrap_spec(error=int)
+    def set_last_error(space, error):
+        pass

File pypy/module/itertools/interp_itertools.py

View file
                     item = data[i] = next()
                     cnt[0] += 1
                 else:
-                    item = data.pop(i)
+                    item = data[i]   # data.pop(i) if it's the last one
                 yield item
         it = iter(iterable)
         return tuple([gen(it.next) for i in range(n)])
 
     myiter = space.interpclass_w(w_iterable)
     if isinstance(myiter, W_TeeIterable):     # optimization only
-        tee_state = myiter.tee_state
+        chained_list = myiter.chained_list
+        w_iterator = myiter.w_iterator
         iterators_w = [w_iterable] * n
         for i in range(1, n):
-            iterators_w[i] = space.wrap(W_TeeIterable(space, tee_state))
+            iterators_w[i] = space.wrap(W_TeeIterable(space, w_iterator,
+                                                      chained_list))
     else:
-        tee_state = TeeState(space, w_iterable)
-        iterators_w = [space.wrap(W_TeeIterable(space, tee_state)) for x in range(n)]
+        w_iterator = space.iter(w_iterable)
+        chained_list = TeeChainedListNode()
+        iterators_w = [space.wrap(
+                           W_TeeIterable(space, w_iterator, chained_list))
+                       for x in range(n)]
     return space.newtuple(iterators_w)
 
-class TeeState(object):
-    def __init__(self, space, w_iterable):
-        self.space = space
-        self.w_iterable = self.space.iter(w_iterable)
-        self.num_saved = 0
-        self.saved_w = []
-
-    def get_next(self, index):
-        if index >= self.num_saved:
-            w_obj = self.space.next(self.w_iterable)
-            self.saved_w.append(w_obj)
-            self.num_saved += 1
-            return w_obj
-        else:
-            return self.saved_w[index]
+class TeeChainedListNode(object):
+    w_obj = None
 
 class W_TeeIterable(Wrappable):
-    def __init__(self, space, tee_state):
+    def __init__(self, space, w_iterator, chained_list):
         self.space = space
-        self.tee_state = tee_state
-        self.index = 0
+        self.w_iterator = w_iterator
+        assert chained_list is not None
+        self.chained_list = chained_list
 
     def iter_w(self):
         return self.space.wrap(self)
 
     def next_w(self):
-        try:
-            w_obj = self.tee_state.get_next(self.index)
-            return w_obj
-        finally:
-            self.index += 1
+        chained_list = self.chained_list
+        w_obj = chained_list.w_obj
+        if w_obj is None:
+            w_obj = self.space.next(self.w_iterator)
+            chained_list.next = TeeChainedListNode()
+            chained_list.w_obj = w_obj
+        self.chained_list = chained_list.next
+        return w_obj
 
 def W_TeeIterable___new__(space, w_subtype, w_iterable):
     # Obscure and undocumented function.  PyPy only supports w_iterable
     # semantics are then slightly different; see the XXX in lib-python's
     # test_itertools).
     myiter = space.interp_w(W_TeeIterable, w_iterable)
-    tee_state = myiter.tee_state
-    return space.wrap(W_TeeIterable(space, tee_state))
+    return space.wrap(W_TeeIterable(space, myiter.w_iterator,
+                                           myiter.chained_list))
 
 W_TeeIterable.typedef = TypeDef(
         '_tee',

File pypy/module/itertools/test/test_itertools.py

View file
         ref = weakref.ref(b)
         assert ref() is b
 
+    def test_tee_bug1(self):
+        import itertools
+        a, b = itertools.tee('abcde')
+        x = a.next()
+        assert x == 'a'
+        c, d = itertools.tee(a)
+        x = c.next()
+        assert x == 'b'
+        x = d.next()
+        assert x == 'b'
+
 
 class AppTestItertools26:
     def setup_class(cls):

File pypy/rlib/rbigint.py

File contents unchanged.

File pypy/rlib/runicode.py

File contents unchanged.

File pypy/translator/cli/test/test_unicode.py

View file
 
     def test_strformat_unicode_arg(self):
         py.test.skip('fixme!')
+
+    def test_unicode_decode(self):
+        py.test.skip('fixme!')
+
+    def test_unicode_encode(self):
+        py.test.skip('fixme!')