Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3.3
Changeset: r72482:fc86a76771f4
Date: 2014-07-20 11:06 -0700
http://bitbucket.org/pypy/pypy/changeset/fc86a76771f4/

Log:    merge py3k

diff --git a/lib-python/3/json/__init__.py b/lib-python/3/json/__init__.py
--- a/lib-python/3/json/__init__.py
+++ b/lib-python/3/json/__init__.py
@@ -104,6 +104,12 @@
 
 __author__ = 'Bob Ippolito <b...@redivi.com>'
 
+try:
+    # PyPy speedup, the interface is different than CPython's _json
+    import _pypyjson
+except ImportError:
+    _pypyjson = None
+
 from .decoder import JSONDecoder
 from .encoder import JSONEncoder
 
@@ -313,7 +319,7 @@
     if (cls is None and object_hook is None and
             parse_int is None and parse_float is None and
             parse_constant is None and object_pairs_hook is None and not kw):
-        return _default_decoder.decode(s)
+        return _pypyjson.loads(s) if _pypyjson else _default_decoder.decode(s)
     if cls is None:
         cls = JSONDecoder
     if object_hook is not None:
diff --git a/pypy/interpreter/test/test_generator.py 
b/pypy/interpreter/test/test_generator.py
--- a/pypy/interpreter/test/test_generator.py
+++ b/pypy/interpreter/test/test_generator.py
@@ -307,13 +307,13 @@
     w_co = space.appexec([], '''():
         def g(x):
             yield x + 5
-        return g.func_code
+        return g.__code__
     ''')
     assert should_not_inline(w_co) == False
     w_co = space.appexec([], '''():
         def g(x):
             yield x + 5
             yield x + 6
-        return g.func_code
+        return g.__code__
     ''')
     assert should_not_inline(w_co) == True
diff --git a/pypy/module/_pypyjson/interp_decoder.py 
b/pypy/module/_pypyjson/interp_decoder.py
--- a/pypy/module/_pypyjson/interp_decoder.py
+++ b/pypy/module/_pypyjson/interp_decoder.py
@@ -56,6 +56,7 @@
         self.end_ptr = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
         self.pos = 0
         self.last_type = TYPE_UNKNOWN
+        self.memo = {}
 
     def close(self):
         rffi.free_charp(self.ll_chars)
@@ -261,6 +262,8 @@
             w_name = self.decode_any(i)
             if self.last_type != TYPE_STRING:
                 self._raise("Key name must be string for object starting at 
char %d", start)
+            w_name = self.memo.setdefault(self.space.unicode_w(w_name), w_name)
+
             i = self.skip_whitespace(self.pos)
             ch = self.ll_chars[i]
             if ch != ':':
diff --git a/pypy/module/_pypyjson/test/test__pypyjson.py 
b/pypy/module/_pypyjson/test/test__pypyjson.py
--- a/pypy/module/_pypyjson/test/test__pypyjson.py
+++ b/pypy/module/_pypyjson/test/test__pypyjson.py
@@ -187,4 +187,12 @@
         import _pypyjson
         # http://json.org/JSON_checker/test/fail25.json
         s = '["\ttab\tcharacter\tin\tstring\t"]'
-        raises(ValueError, "_pypyjson.loads(s)")
\ No newline at end of file
+        raises(ValueError, "_pypyjson.loads(s)")
+
+    def test_keys_reuse(self):
+        import _pypyjson
+        s = '[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'
+        rval = _pypyjson.loads(s)
+        (a, b), (c, d) = sorted(rval[0]), sorted(rval[1])
+        assert a is c
+        assert b is d
diff --git a/pypy/module/array/interp_array.py 
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -244,7 +244,7 @@
         """
         size = self.len
         if size == 0:
-            return space.wrap('')
+            return space.wrapbytes('')
         cbuf = self._charbuf_start()
         s = rffi.charpsize2str(cbuf, size * self.itemsize)
         self._charbuf_stop()
diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -488,8 +488,7 @@
         cur = os.getlogin()
     except OSError, e:
         raise wrap_oserror(space, e)
-    else:
-        return space.wrap(cur)
+    return space.fsdecode(space.wrapbytes(cur))
 
 # ____________________________________________________________
 
@@ -702,14 +701,21 @@
     except OSError, e:
         raise wrap_oserror(space, e)
 
-@unwrap_spec(path='fsencode')
-def readlink(space, path):
+def readlink(space, w_path):
     "Return a string representing the path to which the symbolic link points."
+    is_unicode = space.isinstance_w(w_path, space.w_unicode)
+    if is_unicode:
+        path = space.fsencode_w(w_path)
+    else:
+        path = space.bytes0_w(w_path)
     try:
         result = os.readlink(path)
     except OSError, e:
-        raise wrap_oserror(space, e, path)
-    return space.wrap(result)
+        raise wrap_oserror2(space, e, w_path)
+    w_result = space.wrapbytes(result)
+    if is_unicode:
+        return space.fsdecode(w_result)
+    return w_result
 
 before_fork_hooks = []
 after_fork_child_hooks = []
@@ -899,7 +905,8 @@
         r = os.uname()
     except OSError, e:
         raise wrap_oserror(space, e)
-    l_w = [space.wrap(i) for i in [r[0], r[1], r[2], r[3], r[4]]]
+    l_w = [space.fsdecode(space.wrapbytes(i))
+           for i in [r[0], r[1], r[2], r[3], r[4]]]
     w_tuple = space.newtuple(l_w)
     w_uname_result = space.getattr(space.getbuiltinmodule(os.name),
                                    space.wrap('uname_result'))
@@ -1229,7 +1236,7 @@
 @unwrap_spec(fd=c_int)
 def ttyname(space, fd):
     try:
-        return space.wrap(os.ttyname(fd))
+        return space.fsdecode(space.wrapbytes(os.ttyname(fd)))
     except OSError, e:
         raise wrap_oserror(space, e)
 
@@ -1364,7 +1371,7 @@
 
     Return the name of the controlling terminal for this process.
     """
-    return space.wrap(os.ctermid())
+    return space.fsdecode(space.wrapbytes(os.ctermid()))
 
 @unwrap_spec(fd=c_int)
 def device_encoding(space, fd):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to