[pypy-commit] pypy default: fix untranslatable total nonsense in zfill

cfbolz noreply at buildbot.pypy.org
Fri Oct 14 14:54:09 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r48053:c29a0415adb7
Date: 2011-10-14 14:53 +0200
http://bitbucket.org/pypy/pypy/changeset/c29a0415adb7/

Log:	fix untranslatable total nonsense in zfill

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
@@ -756,7 +756,8 @@
     input = w_self._value
     width = space.int_w(w_width)
 
-    if len(input) >= width:
+    num_zeros = width - len(input)
+    if num_zeros <= 0:
         # cannot return w_self, in case it is a subclass of str
         return space.wrap(input)
 
@@ -764,13 +765,11 @@
     if len(input) > 0 and (input[0] == '+' or input[0] == '-'):
         builder.append(input[0])
         start = 1
-        middle = width - len(input) + 1
     else:
         start = 0
-        middle = width - len(input)
 
-    builder.append_multiple_char('0', middle - start)
-    builder.append(input[start:start + (width - middle)])
+    builder.append_multiple_char('0', num_zeros)
+    builder.append_slice(input, start, len(input))
     return space.wrap(builder.build())
 
 


More information about the pypy-commit mailing list