[Python-checkins] python/dist/src/Lib ConfigParser.py,1.43,1.44 StringIO.py,1.26,1.27 formatter.py,1.21,1.22 hmac.py,1.6,1.7 markupbase.py,1.5,1.6 nntplib.py,1.29,1.30 popen2.py,1.24,1.25 pyclbr.py,1.25,1.26 rlcompleter.py,1.12,1.13 smtplib.py,1.57,1.58 string.py,1.63,1.64 urllib.py,1.146,1.147 urllib2.py,1.29,1.30 warnings.py,1.15,1.16 zipfile.py,1.23,1.24

doerwalter@users.sourceforge.net doerwalter@users.sourceforge.net
Mon, 03 Jun 2002 08:58:35 -0700


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

Modified Files:
	ConfigParser.py StringIO.py formatter.py hmac.py markupbase.py 
	nntplib.py popen2.py pyclbr.py rlcompleter.py smtplib.py 
	string.py urllib.py urllib2.py warnings.py zipfile.py 
Log Message:
Remove uses of the string and types modules:

x in string.whitespace => x.isspace()
type(x) in types.StringTypes => isinstance(x, basestring)
isinstance(x, types.StringTypes) => isinstance(x, basestring)
type(x) is types.StringType => isinstance(x, str)
type(x) == types.StringType => isinstance(x, str)
string.split(x, ...) => x.split(...)
string.join(x, y) => y.join(x)
string.zfill(x, ...) => x.zfill(...)
string.count(x, ...) => x.count(...)
hasattr(types, "UnicodeType") => try: unicode except NameError:
type(x) != types.TupleTuple => not isinstance(x, tuple)
isinstance(x, types.TupleType) => isinstance(x, tuple)
type(x) is types.IntType => isinstance(x, int)

Do not mention the string module in the rlcompleter docstring.

This partially applies SF patch http://www.python.org/sf/562373
(with basestring instead of string). (It excludes the changes to
unittest.py and does not change the os.stat stuff.)


Index: ConfigParser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ConfigParser.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** ConfigParser.py	1 Jun 2002 14:18:45 -0000	1.43
--- ConfigParser.py	3 Jun 2002 15:58:30 -0000	1.44
***************
*** 84,88 ****
  """
  
! import string, types
  import re
  
--- 84,88 ----
  """
  
! import types
  import re
  
***************
*** 224,228 ****
          filename may also be given.
          """
!         if type(filenames) in types.StringTypes:
              filenames = [filenames]
          for filename in filenames:
--- 224,228 ----
          filename may also be given.
          """
!         if isinstance(filenames, basestring):
              filenames = [filenames]
          for filename in filenames:
***************
*** 455,459 ****
                              # a spacing character
                              pos = optval.find(';')
!                             if pos and optval[pos-1] in string.whitespace:
                                  optval = optval[:pos]
                          optval = optval.strip()
--- 455,459 ----
                              # a spacing character
                              pos = optval.find(';')
!                             if pos and optval[pos-1].isspace():
                                  optval = optval[:pos]
                          optval = optval.strip()

Index: StringIO.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/StringIO.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** StringIO.py	23 May 2002 15:15:29 -0000	1.26
--- StringIO.py	3 Jun 2002 15:58:30 -0000	1.27
***************
*** 29,33 ****
  - There's a simple test set (see end of this file).
  """
- import types
  try:
      from errno import EINVAL
--- 29,32 ----
***************
*** 51,55 ****
      def __init__(self, buf = ''):
          # Force self.buf to be a string or unicode
!         if not isinstance(buf, types.StringTypes):
              buf = str(buf)
          self.buf = buf
--- 50,54 ----
      def __init__(self, buf = ''):
          # Force self.buf to be a string or unicode
!         if not isinstance(buf, basestring):
              buf = str(buf)
          self.buf = buf
***************
*** 152,156 ****
          if not s: return
          # Force s to be a string or unicode
!         if not isinstance(s, types.StringTypes):
              s = str(s)
          if self.pos > self.len:
--- 151,155 ----
          if not s: return
          # Force s to be a string or unicode
!         if not isinstance(s, basestring):
              s = str(s)
          if self.pos > self.len:

Index: formatter.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/formatter.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** formatter.py	1 Jun 2002 01:29:16 -0000	1.21
--- formatter.py	3 Jun 2002 15:58:31 -0000	1.22
***************
*** 19,25 ****
  """
  
- import string
  import sys
- from types import StringType
  
  
--- 19,23 ----
***************
*** 120,124 ****
          if not self.para_end:
              self.writer.send_paragraph((blankline and 1) or 0)
!         if type(format) is StringType:
              self.writer.send_label_data(self.format_counter(format, counter))
          else:
--- 118,122 ----
          if not self.para_end:
              self.writer.send_paragraph((blankline and 1) or 0)
!         if isinstance(format, str):
              self.writer.send_label_data(self.format_counter(format, counter))
          else:
***************
*** 177,190 ****
          return label
  
!     def add_flowing_data(self, data,
!                          # These are only here to load them into locals:
!                          whitespace = string.whitespace,
!                          join = string.join, split = string.split):
          if not data: return
          # The following looks a bit convoluted but is a great improvement over
          # data = regsub.gsub('[' + string.whitespace + ']+', ' ', data)
!         prespace = data[:1] in whitespace
!         postspace = data[-1:] in whitespace
!         data = join(split(data))
          if self.nospace and not data:
              return
--- 175,185 ----
          return label
  
!     def add_flowing_data(self, data):
          if not data: return
          # The following looks a bit convoluted but is a great improvement over
          # data = regsub.gsub('[' + string.whitespace + ']+', ' ', data)
!         prespace = data[:1].isspace()
!         postspace = data[-1:].isspace()
!         data = " ".join(data.split())
          if self.nospace and not data:
              return
***************
*** 412,416 ****
      def send_flowing_data(self, data):
          if not data: return
!         atbreak = self.atbreak or data[0] in string.whitespace
          col = self.col
          maxcol = self.maxcol
--- 407,411 ----
      def send_flowing_data(self, data):
          if not data: return
!         atbreak = self.atbreak or data[0].isspace()
          col = self.col
          maxcol = self.maxcol
***************
*** 428,432 ****
              atbreak = 1
          self.col = col
!         self.atbreak = data[-1] in string.whitespace
  
  
--- 423,427 ----
              atbreak = 1
          self.col = col
!         self.atbreak = data[-1].isspace()
  
  

Index: hmac.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/hmac.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** hmac.py	1 Jun 2002 01:29:16 -0000	1.6
--- hmac.py	3 Jun 2002 15:58:31 -0000	1.7
***************
*** 4,9 ****
  """
  
- import string
- 
  def _strxor(s1, s2):
      """Utility method. XOR the two strings s1 and s2 (must have same length).
--- 4,7 ----
***************
*** 83,87 ****
          """Like digest(), but returns a string of hexadecimal digits instead.
          """
!         return "".join([string.zfill(hex(ord(x))[2:], 2)
                          for x in tuple(self.digest())])
  
--- 81,85 ----
          """Like digest(), but returns a string of hexadecimal digits instead.
          """
!         return "".join([hex(ord(x))[2:].zfill(2)
                          for x in tuple(self.digest())])
  

Index: markupbase.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/markupbase.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** markupbase.py	31 May 2002 14:13:03 -0000	1.5
--- markupbase.py	3 Jun 2002 15:58:31 -0000	1.6
***************
*** 2,6 ****
  
  import re
- import string
  
  _declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match
--- 2,5 ----
***************
*** 152,156 ****
              elif c == "]":
                  j = j + 1
!                 while j < n and rawdata[j] in string.whitespace:
                      j = j + 1
                  if j < n:
--- 151,155 ----
              elif c == "]":
                  j = j + 1
!                 while j < n and rawdata[j].isspace():
                      j = j + 1
                  if j < n:
***************
*** 161,165 ****
                  else:
                      return -1
!             elif c in string.whitespace:
                  j = j + 1
              else:
--- 160,164 ----
                  else:
                      return -1
!             elif c.isspace():
                  j = j + 1
              else:
***************
*** 204,208 ****
                  else:
                      return -1
!                 while rawdata[j:j+1] in string.whitespace:
                      j = j + 1
                  if not rawdata[j:]:
--- 203,207 ----
                  else:
                      return -1
!                 while rawdata[j:j+1].isspace():
                      j = j + 1
                  if not rawdata[j:]:
***************
*** 269,273 ****
                  if not c:
                      return -1
!                 if c in string.whitespace:
                      j = j + 1
                  else:
--- 268,272 ----
                  if not c:
                      return -1
!                 if c.isspace():
                      j = j + 1
                  else:

Index: nntplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/nntplib.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** nntplib.py	16 Feb 2002 23:06:17 -0000	1.29
--- nntplib.py	3 Jun 2002 15:58:31 -0000	1.30
***************
*** 32,36 ****
  import re
  import socket
- import types
  
  __all__ = ["NNTP","NNTPReplyError","NNTPTemporaryError",
--- 32,35 ----
***************
*** 219,223 ****
          try:
              # If a string was passed then open a file with that name
!             if isinstance(file, types.StringType):
                  openedFile = file = open(file, "w")
  
--- 218,222 ----
          try:
              # If a string was passed then open a file with that name
!             if isinstance(file, str):
                  openedFile = file = open(file, "w")
  

Index: popen2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/popen2.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** popen2.py	24 Mar 2002 20:48:26 -0000	1.24
--- popen2.py	3 Jun 2002 15:58:31 -0000	1.25
***************
*** 9,13 ****
  import os
  import sys
- import types
  
  __all__ = ["popen2", "popen3", "popen4"]
--- 9,12 ----
***************
*** 58,62 ****
  
      def _run_child(self, cmd):
!         if isinstance(cmd, types.StringTypes):
              cmd = ['/bin/sh', '-c', cmd]
          for i in range(3, MAXFD):
--- 57,61 ----
  
      def _run_child(self, cmd):
!         if isinstance(cmd, basestring):
              cmd = ['/bin/sh', '-c', cmd]
          for i in range(3, MAXFD):

Index: pyclbr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pyclbr.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** pyclbr.py	2 Jun 2002 18:55:56 -0000	1.25
--- pyclbr.py	3 Jun 2002 15:58:31 -0000	1.26
***************
*** 209,218 ****
  
      # To avoid having to stop the regexp at each newline, instead
!     # when we need a line number we simply string.count the number of
      # newlines in the string since the last time we did this; i.e.,
!     #    lineno = lineno + \
!     #             string.count(src, '\n', last_lineno_pos, here)
      #    last_lineno_pos = here
-     countnl = string.count
      lineno, last_lineno_pos = 1, 0
      i = 0
--- 209,216 ----
  
      # To avoid having to stop the regexp at each newline, instead
!     # when we need a line number we simply count the number of
      # newlines in the string since the last time we did this; i.e.,
!     #    lineno += src.count('\n', last_lineno_pos, here)
      #    last_lineno_pos = here
      lineno, last_lineno_pos = 1, 0
      i = 0
***************
*** 227,233 ****
              thisindent = _indent(m.group("MethodIndent"))
              meth_name = m.group("MethodName")
!             lineno = lineno + \
!                      countnl(src, '\n',
!                              last_lineno_pos, start)
              last_lineno_pos = start
              # close all classes indented at least as much
--- 225,229 ----
              thisindent = _indent(m.group("MethodIndent"))
              meth_name = m.group("MethodName")
!             lineno += src.count('\n', last_lineno_pos, start)
              last_lineno_pos = start
              # close all classes indented at least as much
***************
*** 255,260 ****
                    classstack[-1][1] >= thisindent:
                  del classstack[-1]
!             lineno = lineno + \
!                      countnl(src, '\n', last_lineno_pos, start)
              last_lineno_pos = start
              class_name = m.group("ClassName")
--- 251,255 ----
                    classstack[-1][1] >= thisindent:
                  del classstack[-1]
!             lineno += src.count('\n', last_lineno_pos, start)
              last_lineno_pos = start
              class_name = m.group("ClassName")

Index: rlcompleter.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/rlcompleter.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** rlcompleter.py	2 Jun 2002 18:55:56 -0000	1.12
--- rlcompleter.py	3 Jun 2002 15:58:31 -0000	1.13
***************
*** 6,12 ****
  expression up to the last dot and completes its attributes.
  
! It's very cool to do "import string" type "string.", hit the
  completion key (twice), and see the list of names defined by the
! string module!
  
  Tip: to use the tab key as the completion key, call
--- 6,12 ----
  expression up to the last dot and completes its attributes.
  
! It's very cool to do "import sys" type "sys.", hit the
  completion key (twice), and see the list of names defined by the
! sys module!
  
  Tip: to use the tab key as the completion key, call

Index: smtplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/smtplib.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** smtplib.py	2 Jun 2002 12:33:22 -0000	1.57
--- smtplib.py	3 Jun 2002 15:58:32 -0000	1.58
***************
*** 45,49 ****
  import re
  import rfc822
- import types
  import base64
  import hmac
--- 45,48 ----
***************
*** 652,656 ****
              raise SMTPSenderRefused(code, resp, from_addr)
          senderrs={}
!         if isinstance(to_addrs, types.StringTypes):
              to_addrs = [to_addrs]
          for each in to_addrs:
--- 651,655 ----
              raise SMTPSenderRefused(code, resp, from_addr)
          senderrs={}
!         if isinstance(to_addrs, basestring):
              to_addrs = [to_addrs]
          for each in to_addrs:

Index: string.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/string.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** string.py	15 Apr 2002 13:36:43 -0000	1.63
--- string.py	3 Jun 2002 15:58:32 -0000	1.64
***************
*** 191,198 ****
  _int = int
  _long = long
- try:
-     _StringTypes = (str, unicode)
- except NameError:
-     _StringTypes = (str,)
  
  # Convert string to float
--- 191,194 ----
***************
*** 280,284 ****
  
      """
!     if not isinstance(x, _StringTypes):
          x = repr(x)
      return x.zfill(width)
--- 276,280 ----
  
      """
!     if not isinstance(x, basestring):
          x = repr(x)
      return x.zfill(width)

Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.146
retrieving revision 1.147
diff -C2 -d -r1.146 -r1.147
*** urllib.py	2 Jun 2002 03:04:51 -0000	1.146
--- urllib.py	3 Jun 2002 15:58:32 -0000	1.147
***************
*** 28,32 ****
  import time
  import sys
- import types
  
  __all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve",
--- 28,31 ----
***************
*** 255,259 ****
          import httplib
          user_passwd = None
!         if type(url) is types.StringType:
              host, selector = splithost(url)
              if host:
--- 254,258 ----
          import httplib
          user_passwd = None
!         if isinstance(url, str):
              host, selector = splithost(url)
              if host:
***************
*** 333,337 ****
              import httplib
              user_passwd = None
!             if type(url) is types.StringType:
                  host, selector = splithost(url)
                  if host:
--- 332,336 ----
              import httplib
              user_passwd = None
!             if isinstance(url, str):
                  host, selector = splithost(url)
                  if host:
***************
*** 907,916 ****
  # quote('abc def') -> 'abc%20def')
  
! if hasattr(types, "UnicodeType"):
      def _is_unicode(x):
!         return isinstance(x, unicode)
  else:
      def _is_unicode(x):
!         return 0
  
  def toBytes(url):
--- 906,917 ----
  # quote('abc def') -> 'abc%20def')
  
! try:
!     unicode
! except NameError:
      def _is_unicode(x):
!         return 0
  else:
      def _is_unicode(x):
!         return isinstance(x, unicode)
  
  def toBytes(url):
***************
*** 1174,1178 ****
              # non-sequence items should not work with len()
              # non-empty strings will fail this
!             if len(query) and type(query[0]) != types.TupleType:
                  raise TypeError
              # zero-length sequences of all types will get here and succeed,
--- 1175,1179 ----
              # non-sequence items should not work with len()
              # non-empty strings will fail this
!             if len(query) and not isinstance(query[0], tuple):
                  raise TypeError
              # zero-length sequences of all types will get here and succeed,
***************
*** 1194,1198 ****
          for k, v in query:
              k = quote_plus(str(k))
!             if type(v) == types.StringType:
                  v = quote_plus(v)
                  l.append(k + '=' + v)
--- 1195,1199 ----
          for k, v in query:
              k = quote_plus(str(k))
!             if isinstance(v, str):
                  v = quote_plus(v)
                  l.append(k + '=' + v)

Index: urllib2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib2.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** urllib2.py	1 Jun 2002 14:18:47 -0000	1.29
--- urllib2.py	3 Jun 2002 15:58:32 -0000	1.30
***************
*** 93,97 ****
  import re
  import base64
- import types
  import urlparse
  import md5
--- 93,96 ----
***************
*** 304,308 ****
      def open(self, fullurl, data=None):
          # accept a URL or a Request object
!         if isinstance(fullurl, types.StringTypes):
              req = Request(fullurl, data)
          else:
--- 303,307 ----
      def open(self, fullurl, data=None):
          # accept a URL or a Request object
!         if isinstance(fullurl, basestring):
              req = Request(fullurl, data)
          else:
***************
*** 517,521 ****
      def add_password(self, realm, uri, user, passwd):
          # uri could be a single URI or a sequence
!         if isinstance(uri, types.StringTypes):
              uri = [uri]
          uri = tuple(map(self.reduce_uri, uri))
--- 516,520 ----
      def add_password(self, realm, uri, user, passwd):
          # uri could be a single URI or a sequence
!         if isinstance(uri, basestring):
              uri = [uri]
          uri = tuple(map(self.reduce_uri, uri))
***************
*** 1085,1089 ****
  
      for url in urls:
!         if isinstance(url, types.TupleType):
              url, req = url
          else:
--- 1084,1088 ----
  
      for url in urls:
!         if isinstance(url, tuple):
              url, req = url
          else:

Index: warnings.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/warnings.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** warnings.py	1 Jun 2002 14:18:47 -0000	1.15
--- warnings.py	3 Jun 2002 15:58:32 -0000	1.16
***************
*** 126,134 ****
      assert action in ("error", "ignore", "always", "default", "module",
                        "once"), "invalid action: %s" % `action`
!     assert isinstance(message, types.StringType), "message must be a string"
      assert isinstance(category, types.ClassType), "category must be a class"
      assert issubclass(category, Warning), "category must be a Warning subclass"
!     assert type(module) is types.StringType, "module must be a string"
!     assert type(lineno) is types.IntType and lineno >= 0, \
             "lineno must be an int >= 0"
      item = (action, re.compile(message, re.I), category,
--- 126,134 ----
      assert action in ("error", "ignore", "always", "default", "module",
                        "once"), "invalid action: %s" % `action`
!     assert isinstance(message, str), "message must be a string"
      assert isinstance(category, types.ClassType), "category must be a class"
      assert issubclass(category, Warning), "category must be a Warning subclass"
!     assert isinstance(module, str), "module must be a string"
!     assert isinstance(lineno, int) and lineno >= 0, \
             "lineno must be an int >= 0"
      item = (action, re.compile(message, re.I), category,

Index: zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/zipfile.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** zipfile.py	1 Jun 2002 19:51:15 -0000	1.23
--- zipfile.py	3 Jun 2002 15:58:32 -0000	1.24
***************
*** 66,76 ****
  _FH_EXTRA_FIELD_LENGTH = 11
  
- # Used to compare file passed to ZipFile
- import types
- _STRING_TYPES = (types.StringType,)
- if hasattr(types, "UnicodeType"):
-     _STRING_TYPES = _STRING_TYPES + (types.UnicodeType,)
- 
- 
  def is_zipfile(filename):
      """Quickly see if file is a ZIP file by checking the magic number.
--- 66,69 ----
***************
*** 176,180 ****
  
          # Check if we were passed a file-like object
!         if type(file) in _STRING_TYPES:
              self._filePassed = 0
              self.filename = file
--- 169,173 ----
  
          # Check if we were passed a file-like object
!         if isinstance(file, basestring):
              self._filePassed = 0
              self.filename = file