[pypy-svn] r4700 - in pypy/trunk/src/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Fri May 28 17:39:45 CEST 2004


Author: arigo
Date: Fri May 28 17:39:44 2004
New Revision: 4700

Modified:
   pypy/trunk/src/pypy/objspace/std/stringobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py
Log:
repr(string) bug fixed, corresponding test added.


Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringobject.py	Fri May 28 17:39:44 2004
@@ -910,20 +910,20 @@
 
 
 def app_repr__String(s):
-    quote = '\''
-    if quote in s and not '"' in s:
+    quote = "'"
+    if quote in s and '"' not in s:
         quote = '"'
 
     repr = quote
 
-    for i in range(len(s)):
-        c = s[i]
-        if c == '\\' or c == quote:  repr += '\\'+c
-        elif c == '\t': repr+= '\\t'
-        elif c == '\r': repr+= '\\r'
-        elif c == '\n': repr+= '\\n'
-        elif not chr(32) <= c < chr(127) :
-            repr +=  '\\' + hex(ord(c))[-3:]
+    for c in s:
+        if c == '\\' or c == quote: repr += '\\'+c
+        elif c == '\t': repr += '\\t'
+        elif c == '\r': repr += '\\r'
+        elif c == '\n': repr += '\\n'
+        elif not '\x20' <= c < '\x7f':
+            n = ord(c)
+            repr += '\\x'+"0123456789abcdef"[n>>4]+"0123456789abcdef"[n&0xF]
         else:
             repr += c
 

Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py	Fri May 28 17:39:44 2004
@@ -469,6 +469,7 @@
         self.assertEquals(repr('\\')    ,"'\\\\'")
         self.assertEquals(repr("'''\"") ,'\'\\\'\\\'\\\'"\'')
         self.assertEquals(repr(chr(19)) ,"'\\x13'")
+        self.assertEquals(repr(chr(2))  ,"'\\x02'")
     
 
 if __name__ == '__main__':



More information about the Pypy-commit mailing list