Apply the second version of SF patch http://www.python.org/sf/536241
Add a method zfill to str, unicode and UserString and change
Lib/string.py accordingly.
This activates the zfill version in unicodeobject.c that was
commented out and implements the same in stringobject.c. It also
adds the test for unicode support in Lib/string.py back in and
uses repr() instead() of str() (as it was before Lib/string.py 1.62)
diff --git a/Lib/string.py b/Lib/string.py
index d68b0bf..cd9909e 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -190,7 +190,10 @@
_float = float
_int = int
_long = long
-_StringTypes = (str, unicode)
+try:
+ _StringTypes = (str, unicode)
+except NameError:
+ _StringTypes = (str,)
# Convert string to float
def atof(s):
@@ -277,13 +280,8 @@
"""
if not isinstance(x, _StringTypes):
- x = str(x)
- n = len(x)
- if n >= width: return x
- sign = ''
- if x[0] in '-+':
- sign, x = x[0], x[1:]
- return sign + '0'*(width-n) + x
+ x = repr(x)
+ return x.zfill(width)
# Expand tabs in a string.
# Doesn't take non-printing chars into account, but does understand \n.