[Patches] string.py indentation patch

Skip Montanaro skip@mojam.com (Skip Montanaro)
Thu, 10 Feb 2000 08:55:57 -0600


It appears that the only file in the standard distribution that suffers from
the tab devil is the mostly unused string.py.  Attached is a context diff.

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/
"Languages that change by catering to the tastes of non-users tend not to do
so well." - Doug Landauer


Release info:

I confirm that, to the best of my knowledge and belief, this contribution is
free of any claims of third parties under copyright, patent or other rights
or interests ("claims").  To the extent that I have any such claims, I
hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide
license to reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part of the
Python software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize others
to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or not
to incorporate this contribution in the Python software and its related
documentation.  I further grant CNRI permission to use my name and other
identifying information provided to CNRI by me for use in connection with
the Python software and its related documentation.

--[[text/plain; type=patch
Content-Disposition: attachment; filename="string.diff"][quoted-printable]]
*** /tmp/string.py.~1.46~UNAUoC	Thu Feb 10 08:54:00 2000
--- /tmp/string.pyUNAhyI	Thu Feb 10 08:54:00 2000
***************
*** 197,206 ****
  =

      """
      if type(s) =3D=3D _StringType:
! 	return _float(s)
      else:
! 	raise TypeError('argument 1: expected string, %s found' %
! 			type(s).__name__)
  =

  # Convert string to integer
  def atoi(*args):
--- 197,206 ----
  =

      """
      if type(s) =3D=3D _StringType:
!         return _float(s)
      else:
!         raise TypeError('argument 1: expected string, %s found' %
!                         type(s).__name__)
  =

  # Convert string to integer
  def atoi(*args):
***************
*** 215,232 ****
  =

      """
      try:
! 	s =3D args[0]
      except IndexError:
! 	raise TypeError('function requires at least 1 argument: %d given' %
! 			len(args))
      # Don't catch type error resulting from too many arguments to int()=
=2E  The
      # error message isn't compatible but the error type is, and this fu=
nction
      # is complicated enough already.
      if type(s) =3D=3D _StringType:
! 	return _apply(_int, args)
      else:
! 	raise TypeError('argument 1: expected string, %s found' %
! 			type(s).__name__)
  =

  =

  # Convert string to long integer
--- 215,232 ----
  =

      """
      try:
!         s =3D args[0]
      except IndexError:
!         raise TypeError('function requires at least 1 argument: %d give=
n' %
!                         len(args))
      # Don't catch type error resulting from too many arguments to int()=
=2E  The
      # error message isn't compatible but the error type is, and this fu=
nction
      # is complicated enough already.
      if type(s) =3D=3D _StringType:
!         return _apply(_int, args)
      else:
!         raise TypeError('argument 1: expected string, %s found' %
!                         type(s).__name__)
  =

  =

  # Convert string to long integer
***************
*** 243,260 ****
  =

      """
      try:
! 	s =3D args[0]
      except IndexError:
! 	raise TypeError('function requires at least 1 argument: %d given' %
! 			len(args))
      # Don't catch type error resulting from too many arguments to long(=
).  The
      # error message isn't compatible but the error type is, and this fu=
nction
      # is complicated enough already.
      if type(s) =3D=3D _StringType:
! 	return _apply(_long, args)
      else:
! 	raise TypeError('argument 1: expected string, %s found' %
! 			type(s).__name__)
  =

  =

  # Left-justify a string
--- 243,260 ----
  =

      """
      try:
!         s =3D args[0]
      except IndexError:
!         raise TypeError('function requires at least 1 argument: %d give=
n' %
!                         len(args))
      # Don't catch type error resulting from too many arguments to long(=
).  The
      # error message isn't compatible but the error type is, and this fu=
nction
      # is complicated enough already.
      if type(s) =3D=3D _StringType:
!         return _apply(_long, args)
      else:
!         raise TypeError('argument 1: expected string, %s found' %
!                         type(s).__name__)
  =

  =

  # Left-justify a string
***************
*** 296,303 ****
      if n <=3D 0: return s
      half =3D n/2
      if n%2 and width%2:
! 	# This ensures that center(center(s, i), j) =3D center(s, j)
! 	half =3D half+1
      return ' '*half +  s + ' '*(n-half)
  =

  # Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
--- 296,303 ----
      if n <=3D 0: return s
      half =3D n/2
      if n%2 and width%2:
!         # This ensures that center(center(s, i), j) =3D center(s, j)
!         half =3D half+1
      return ' '*half +  s + ' '*(n-half)
  =

  # Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
***************
*** 316,322 ****
      if n >=3D width: return s
      sign =3D ''
      if s[0] in ('-', '+'):
! 	sign, s =3D s[0], s[1:]
      return sign + '0'*(width-n) + s
  =

  # Expand tabs in a string.
--- 316,322 ----
      if n >=3D width: return s
      sign =3D ''
      if s[0] in ('-', '+'):
!         sign, s =3D s[0], s[1:]
      return sign + '0'*(width-n) + s
  =

  # Expand tabs in a string.
***************
*** 331,342 ****
      """
      res =3D line =3D ''
      for c in s:
! 	if c =3D=3D '\t':
! 	    c =3D ' '*(tabsize - len(line) % tabsize)
! 	line =3D line + c
! 	if c =3D=3D '\n':
! 	    res =3D res + line
! 	    line =3D ''
      return res + line
  =

  # Character translation through look-up table.
--- 331,342 ----
      """
      res =3D line =3D ''
      for c in s:
!         if c =3D=3D '\t':
!             c =3D ' '*(tabsize - len(line) % tabsize)
!         line =3D line + c
!         if c =3D=3D '\n':
!             res =3D res + line
!             line =3D ''
      return res + line
  =

  # Character translation through look-up table.
***************
*** 385,398 ****
  =

      """
      if len(fromstr) !=3D len(tostr):
! 	raise ValueError, "maketrans arguments must have same length"
      global _idmapL
      if not _idmapL:
! 	_idmapL =3D map(None, _idmap)
      L =3D _idmapL[:]
      fromstr =3D map(ord, fromstr)
      for i in range(len(fromstr)):
! 	L[fromstr[i]] =3D tostr[i]
      return joinfields(L, "")
  =

  # Substring replacement (global)
--- 385,398 ----
  =

      """
      if len(fromstr) !=3D len(tostr):
!         raise ValueError, "maketrans arguments must have same length"
      global _idmapL
      if not _idmapL:
!         _idmapL =3D map(None, _idmap)
      L =3D _idmapL[:]
      fromstr =3D map(ord, fromstr)
      for i in range(len(fromstr)):
!         L[fromstr[i]] =3D tostr[i]
      return joinfields(L, "")
  =

  # Substring replacement (global)
***************
*** 426,429 ****
      from strop import maketrans, lowercase, uppercase, whitespace
      letters =3D lowercase + uppercase
  except ImportError:
!     pass					  # Use the original versions
--- 426,429 ----
      from strop import maketrans, lowercase, uppercase, whitespace
      letters =3D lowercase + uppercase
  except ImportError:
!     pass                                          # Use the original ve=
rsions