[Python-checkins] CVS: python/dist/src/Lib dospath.py,1.18,1.19 macpath.py,1.25,1.26 ntpath.py,1.30,1.31

Fred L. Drake python-dev@python.org
Thu, 28 Sep 2000 09:25:23 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv29621

Modified Files:
	dospath.py macpath.py ntpath.py 
Log Message:

Avoid import of string module; it is only needed for expandvars().

Never assume that os.sep is for the module-specific platform; use the
right separator character directly.
Fix some minor style consistency nits.


Index: dospath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dospath.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** dospath.py	2000/09/19 23:46:56	1.18
--- dospath.py	2000/09/28 16:25:20	1.19
***************
*** 3,7 ****
  import os
  import stat
- import string
  
  
--- 3,6 ----
***************
*** 16,20 ****
      possibly be added as a new function."""
  
!     return string.lower(string.replace(s, "/", "\\"))
  
  
--- 15,19 ----
      possibly be added as a new function."""
  
!     return s.replace("/", "\\").lower()
  
  
***************
*** 40,44 ****
              path = path + b
          else:
!             path = path + os.sep + b
      return path
  
--- 39,43 ----
              path = path + b
          else:
!             path = path + "\\" + b
      return path
  
***************
*** 226,231 ****
  
  
- varchars = string.letters + string.digits + '_-'
- 
  def expandvars(path):
      """Expand paths containing shell variable substitutions.
--- 225,228 ----
***************
*** 240,243 ****
--- 237,242 ----
      if '$' not in path:
          return path
+     import string
+     varchars = string.letters + string.digits + '_-'
      res = ''
      index = 0
***************
*** 249,255 ****
              pathlen = len(path)
              try:
!                 index = string.index(path, '\'')
                  res = res + '\'' + path[:index + 1]
!             except string.index_error:
                  res = res + path
                  index = pathlen -1
--- 248,254 ----
              pathlen = len(path)
              try:
!                 index = path.index('\'')
                  res = res + '\'' + path[:index + 1]
!             except ValueError:
                  res = res + path
                  index = pathlen -1
***************
*** 262,270 ****
                  pathlen = len(path)
                  try:
!                     index = string.index(path, '}')
                      var = path[:index]
                      if os.environ.has_key(var):
                          res = res + os.environ[var]
!                 except string.index_error:
                      res = res + path
                      index = pathlen - 1
--- 261,269 ----
                  pathlen = len(path)
                  try:
!                     index = path.index('}')
                      var = path[:index]
                      if os.environ.has_key(var):
                          res = res + os.environ[var]
!                 except ValueError:
                      res = res + path
                      index = pathlen - 1
***************
*** 291,300 ****
      Also, components of the path are silently truncated to 8+3 notation."""
  
!     path = string.replace(path, "/", "\\")
      prefix, path = splitdrive(path)
!     while path[:1] == os.sep:
!         prefix = prefix + os.sep
          path = path[1:]
!     comps = string.splitfields(path, os.sep)
      i = 0
      while i < len(comps):
--- 290,299 ----
      Also, components of the path are silently truncated to 8+3 notation."""
  
!     path = path.replace("/", "\\")
      prefix, path = splitdrive(path)
!     while path[:1] == "\\":
!         prefix = prefix + "\\"
          path = path[1:]
!     comps = path.split("\\")
      i = 0
      while i < len(comps):
***************
*** 304,323 ****
                        comps[i-1] not in ('', '..'):
              del comps[i-1:i+1]
!             i = i-1
          elif comps[i] == '' and i > 0 and comps[i-1] <> '':
              del comps[i]
          elif '.' in comps[i]:
!             comp = string.splitfields(comps[i], '.')
              comps[i] = comp[0][:8] + '.' + comp[1][:3]
!             i = i+1
          elif len(comps[i]) > 8:
              comps[i] = comps[i][:8]
!             i = i+1
          else:
!             i = i+1
      # If the path is now empty, substitute '.'
      if not prefix and not comps:
          comps.append('.')
!     return prefix + string.joinfields(comps, os.sep)
  
  
--- 303,322 ----
                        comps[i-1] not in ('', '..'):
              del comps[i-1:i+1]
!             i = i - 1
          elif comps[i] == '' and i > 0 and comps[i-1] <> '':
              del comps[i]
          elif '.' in comps[i]:
!             comp = comps[i].split('.')
              comps[i] = comp[0][:8] + '.' + comp[1][:3]
!             i = i + 1
          elif len(comps[i]) > 8:
              comps[i] = comps[i][:8]
!             i = i + 1
          else:
!             i = i + 1
      # If the path is now empty, substitute '.'
      if not prefix and not comps:
          comps.append('.')
!     return prefix + "\\".join(comps)
  
  

Index: macpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/macpath.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** macpath.py	2000/08/23 09:13:40	1.25
--- macpath.py	2000/09/28 16:25:20	1.26
***************
*** 1,12 ****
  """Pathname and path-related operations for the Macintosh."""
  
- import string
  import os
  from stat import *
  
  
! # Normalize the case of a pathname.  Dummy in Posix, but string.lower here.
  
! normcase = string.lower
  
  
--- 1,12 ----
  """Pathname and path-related operations for the Macintosh."""
  
  import os
  from stat import *
  
  
! # Normalize the case of a pathname.  Dummy in Posix, but <s>.lower() here.
  
! def normcase(path):
!     return path.lower()
  
  
***************
*** 45,49 ****
      colon = 0
      for i in range(len(s)):
!         if s[i] == ':': colon = i+1
      path, file = s[:colon-1], s[colon:]
      if path and not ':' in path:
--- 45,49 ----
      colon = 0
      for i in range(len(s)):
!         if s[i] == ':': colon = i + 1
      path, file = s[:colon-1], s[colon:]
      if path and not ':' in path:
***************
*** 176,180 ****
          return ":"+s
  
!     comps = string.splitfields(s, ":")
      i = 1
      while i < len(comps)-1:
--- 176,180 ----
          return ":"+s
  
!     comps = s.split(":")
      i = 1
      while i < len(comps)-1:
***************
*** 182,186 ****
              if i > 1:
                  del comps[i-1:i+1]
!                 i = i-1
              else:
                  # best way to handle this is to raise an exception
--- 182,186 ----
              if i > 1:
                  del comps[i-1:i+1]
!                 i = i - 1
              else:
                  # best way to handle this is to raise an exception
***************
*** 189,193 ****
              i = i + 1
  
!     s = string.join(comps, ":")
  
      # remove trailing ":" except for ":" and "Volume:"
--- 189,193 ----
              i = i + 1
  
!     s = ":".join(comps)
  
      # remove trailing ":" except for ":" and "Volume:"

Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** ntpath.py	2000/09/19 20:39:32	1.30
--- ntpath.py	2000/09/28 16:25:20	1.31
***************
*** 8,12 ****
  import os
  import stat
- import string
  
  
--- 8,11 ----
***************
*** 19,23 ****
  
      Makes all characters lowercase and all slashes into backslashes."""
!     return string.lower(string.replace(s, "/", "\\"))
  
  
--- 18,22 ----
  
      Makes all characters lowercase and all slashes into backslashes."""
!     return s.replace("/", "\\").lower()
  
  
***************
*** 45,49 ****
              path = path + b
          else:
!             path = path + os.sep + b
      return path
  
--- 44,48 ----
              path = path + b
          else:
!             path = path + "\\" + b
      return path
  
***************
*** 78,86 ****
          #           directory ^^^^^^^^^^^^^^^
          normp = normcase(p)
!         index = string.find(normp, '\\', 2)
          if index == -1:
              ##raise RuntimeError, 'illegal UNC path: "' + p + '"'
              return ("", p)
!         index = string.find(normp, '\\', index + 1)
          if index == -1:
              index = len(p)
--- 77,85 ----
          #           directory ^^^^^^^^^^^^^^^
          normp = normcase(p)
!         index = normp.find('\\', 2)
          if index == -1:
              ##raise RuntimeError, 'illegal UNC path: "' + p + '"'
              return ("", p)
!         index = normp.find('\\', index + 1)
          if index == -1:
              index = len(p)
***************
*** 242,246 ****
          return rest in ("", "/", "\\")
      p = splitdrive(path)[1]
!     return len(p)==1 and p[0] in '/\\'
  
  
--- 241,245 ----
          return rest in ("", "/", "\\")
      p = splitdrive(path)[1]
!     return len(p) == 1 and p[0] in '/\\'
  
  
***************
*** 289,293 ****
      i, n = 1, len(path)
      while i < n and path[i] not in '/\\':
!         i = i+1
      if i == 1:
          if os.environ.has_key('HOME'):
--- 288,292 ----
      i, n = 1, len(path)
      while i < n and path[i] not in '/\\':
!         i = i + 1
      if i == 1:
          if os.environ.has_key('HOME'):
***************
*** 297,301 ****
          else:
              try:
!                 drive=os.environ['HOMEDRIVE']
              except KeyError:
                  drive = ''
--- 296,300 ----
          else:
              try:
!                 drive = os.environ['HOMEDRIVE']
              except KeyError:
                  drive = ''
***************
*** 315,320 ****
  # XXX except '^|<>='.
  
- varchars = string.letters + string.digits + '_-'
- 
  def expandvars(path):  
      """Expand shell variables of form $var and ${var}.
--- 314,317 ----
***************
*** 323,326 ****
--- 320,325 ----
      if '$' not in path:
          return path
+     import string
+     varchars = string.letters + string.digits + '_-'
      res = ''
      index = 0
***************
*** 332,340 ****
              pathlen = len(path)
              try:
!                 index = string.index(path, '\'')
                  res = res + '\'' + path[:index + 1]
!             except string.index_error:
                  res = res + path
!                 index = pathlen -1
          elif c == '$':  # variable or '$$'
              if path[index + 1:index + 2] == '$':
--- 331,339 ----
              pathlen = len(path)
              try:
!                 index = path.index('\'')
                  res = res + '\'' + path[:index + 1]
!             except ValueError:
                  res = res + path
!                 index = pathlen - 1
          elif c == '$':  # variable or '$$'
              if path[index + 1:index + 2] == '$':
***************
*** 345,353 ****
                  pathlen = len(path)
                  try:
!                     index = string.index(path, '}')
                      var = path[:index]
                      if os.environ.has_key(var):
                          res = res + os.environ[var]
!                 except string.index_error:
                      res = res + path
                      index = pathlen - 1
--- 344,352 ----
                  pathlen = len(path)
                  try:
!                     index = path.index('}')
                      var = path[:index]
                      if os.environ.has_key(var):
                          res = res + os.environ[var]
!                 except ValueError:
                      res = res + path
                      index = pathlen - 1
***************
*** 376,385 ****
  def normpath(path):
      """Normalize path, eliminating double slashes, etc."""
!     path = string.replace(path, "/", "\\")
      prefix, path = splitdrive(path)
!     while path[:1] == os.sep:
!         prefix = prefix + os.sep
          path = path[1:]
!     comps = string.splitfields(path, os.sep)
      i = 0
      while i < len(comps):
--- 375,384 ----
  def normpath(path):
      """Normalize path, eliminating double slashes, etc."""
!     path = path.replace("/", "\\")
      prefix, path = splitdrive(path)
!     while path[:1] == "\\":
!         prefix = prefix + "\\"
          path = path[1:]
!     comps = path.split("\\")
      i = 0
      while i < len(comps):
***************
*** 388,400 ****
          elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
              del comps[i-1:i+1]
!             i = i-1
          elif comps[i] == '' and i > 0 and comps[i-1] <> '':
              del comps[i]
          else:
!             i = i+1
      # If the path is now empty, substitute '.'
      if not prefix and not comps:
          comps.append('.')
!     return prefix + string.joinfields(comps, os.sep)
  
  
--- 387,399 ----
          elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
              del comps[i-1:i+1]
!             i = i - 1
          elif comps[i] == '' and i > 0 and comps[i-1] <> '':
              del comps[i]
          else:
!             i = i + 1
      # If the path is now empty, substitute '.'
      if not prefix and not comps:
          comps.append('.')
!     return prefix + "\\".join(comps)