Use find() instead of looping over the string in expanduser().

From SF patch #757058.
This commit is contained in:
Walter Dörwald 2003-06-19 10:21:14 +00:00
parent 76ca1d428f
commit a9da5ae07a
2 changed files with 9 additions and 5 deletions

View file

@ -303,11 +303,11 @@ def expanduser(path):
do nothing."""
if not path.startswith('~'):
return path
i, n = 1, len(path)
while i < n and path[i] != '/':
i += 1
i = path.find('/', 1)
if i < 0:
i = len(path)
if i == 1:
if not 'HOME' in os.environ:
if 'HOME' not in os.environ:
import pwd
userhome = pwd.getpwuid(os.getuid()).pw_dir
else: