* change default line numbers for 'list' in pdb.py
* changed eval() into getattr() in cmd.py
* added dirname(), basename() and (dummy) normath() to macpath.py
* renamed nntp.py to nntplib.py
* Made string.index() compatible with strop.index()
* Make string.atoi('') raise string.atoi_error rather than ValueError
* Added dirname() and normpath() to posixpath.
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index d2bda10..57b0af6 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -75,6 +75,12 @@
return split(p)[1]
+# Return the head (dirname) part of a path.
+
+def dirname(p):
+ return split(p)[0]
+
+
# Return the longest prefix of all list elements.
def commonprefix(m):
@@ -256,3 +262,31 @@
if res[-1:] == '\n':
res = res[:-1]
return res
+
+
+# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
+# It should be understood that this may change the meaning of the path
+# if it contains symbolic links!
+
+def normpath(path):
+ import string
+ comps = string.splitfields(path, '/')
+ # If the path begins with '/', comps[0] is '', which we leave alone;
+ # we also leave leading multiple slashes alone for compatibility
+ # with certain networking naming schemes using //host/path
+ i = 0
+ while i < len(comps):
+ if comps[i] == '.':
+ del comps[i]
+ 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 comps:
+ comps.append('.')
+ return string.joinfields(comps, '/')