[pypy-commit] pypy py3k: fix test_escape_encode (thanks amaury)
pjenvey
noreply at buildbot.pypy.org
Wed Nov 9 09:48:45 CET 2011
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r48985:7275e7c2a49a
Date: 2011-11-09 00:46 -0800
http://bitbucket.org/pypy/pypy/changeset/7275e7c2a49a/
Log: fix test_escape_encode (thanks amaury)
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -733,12 +733,8 @@
@unwrap_spec(data="bufferstr", errors='str_or_None')
def escape_encode(space, data, errors='strict'):
from pypy.objspace.std.stringobject import string_escape_encode
- result = string_escape_encode(data, quote="'")
- start = 1
- end = len(result) - 1
- assert end >= 0
- w_result = space.wrapbytes(result[start:end])
- return space.newtuple([w_result, space.wrap(len(data))])
+ result = string_escape_encode(data, False)
+ return space.newtuple([space.wrapbytes(result), space.wrap(len(data))])
@unwrap_spec(data="bufferstr", errors='str_or_None')
def escape_decode(space, data, errors='strict'):
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -887,20 +887,19 @@
return space.newtuple([wrapstr(space, w_str._value)])
def repr__String(space, w_str):
- s = w_str._value
+ return space.wrap(string_escape_encode(w_str._value, True))
+
+def string_escape_encode(s, quotes):
+ buf = StringBuilder(len(s) + 3 if quotes else 0)
quote = "'"
- if quote in s and '"' not in s:
- quote = '"'
+ if quotes:
+ if quote in s and '"' not in s:
+ quote = '"'
+ buf.append('b"')
+ else:
+ buf.append("b'")
- return space.wrap(string_escape_encode(s, quote))
-
-def string_escape_encode(s, quote):
-
- buf = StringBuilder(len(s) + 3)
-
- buf.append('b')
- buf.append(quote)
startslice = 0
for i in range(len(s)):
@@ -938,7 +937,8 @@
if len(s) != startslice:
buf.append_slice(s, startslice, len(s))
- buf.append(quote)
+ if quotes:
+ buf.append(quote)
return buf.build()
More information about the pypy-commit
mailing list