summaryrefslogtreecommitdiffstats
path: root/Lib/string.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-04-15 13:36:47 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-04-15 13:36:47 (GMT)
commit068325ef926538a30d7feb13f9b14a6163e24b6e (patch)
treec2eef78d030be1ce7a56b56420ba13a853aab57d /Lib/string.py
parentb384c7263928cc2d8dd16cac8537839673cd4982 (diff)
downloadcpython-068325ef926538a30d7feb13f9b14a6163e24b6e.zip
cpython-068325ef926538a30d7feb13f9b14a6163e24b6e.tar.gz
cpython-068325ef926538a30d7feb13f9b14a6163e24b6e.tar.bz2
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)
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py14
1 files changed, 6 insertions, 8 deletions
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 @@ def rfind(s, *args):
_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 @@ def zfill(x, width):
"""
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.