# Split a path in head (everything up to the last '/') and tail (the
-# rest). If the original path ends in '/' but is not the root, this
-# '/' is stripped. After the trailing '/' is stripped, the invariant
-# join(head, tail) == p holds.
-# The resulting head won't end in '/' unless it is the root.
+# rest). If the path ends in '/', tail will be empty. If there is no
+# '/' in the path, head will be empty.
+# Trailing '/'es are stripped from head unless it is the root.
- if p[-1:] == '/' and p <> '/'*len(p):
- head, tail = head + tail, ''
- if head[-1:] == '/' and head <> '/'*len(head):
+ i = string.rfind(p, '/') + 1
+ head, tail = p[:i], p[i:]
+ if head and head <> '/'*len(head):