[Python-checkins] python/dist/src/Lib UserString.py,1.11,1.12 string.py,1.62,1.63

doerwalter@sourceforge.net doerwalter@sourceforge.net
Mon, 15 Apr 2002 06:37:16 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv32693/Lib

Modified Files:
	UserString.py string.py 
Log Message:
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)


Index: UserString.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserString.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** UserString.py	13 Apr 2002 00:56:08 -0000	1.11
--- UserString.py	15 Apr 2002 13:36:43 -0000	1.12
***************
*** 129,132 ****
--- 129,133 ----
          return self.__class__(self.data.translate(*args))
      def upper(self): return self.__class__(self.data.upper())
+     def zfill(self, width): return self.__class__(self.data.zfill(width))
  
  class MutableString(UserString):

Index: string.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/string.py,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** string.py	29 Mar 2002 16:20:33 -0000	1.62
--- string.py	15 Apr 2002 13:36:43 -0000	1.63
***************
*** 191,195 ****
  _int = int
  _long = long
! _StringTypes = (str, unicode)
  
  # Convert string to float
--- 191,198 ----
  _int = int
  _long = long
! try:
!     _StringTypes = (str, unicode)
! except NameError:
!     _StringTypes = (str,)
  
  # Convert string to float
***************
*** 278,288 ****
      """
      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
  
  # Expand tabs in a string.
--- 281,286 ----
      """
      if not isinstance(x, _StringTypes):
!         x = repr(x)
!     return x.zfill(width)
  
  # Expand tabs in a string.