diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-06-28 12:33:30 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-06-28 12:33:30 +0000 |
commit | dea39fa59174feeb1349bdc6ea6969c120ad111a (patch) | |
tree | 1f9bf5e69afc1e3d87bf5a9ab8a0a2b2038ece4d /fs/path.py | |
parent | 9545ff3d5e3605d2c70a67a2de9607bd34d08014 (diff) | |
download | pyfilesystem-dea39fa59174feeb1349bdc6ea6969c120ad111a.tar.gz |
simpler version of relativefrom
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@858 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/path.py')
-rw-r--r-- | fs/path.py | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -411,12 +411,13 @@ def relativefrom(base, path): base = list(iteratepath(base)) path = list(iteratepath(path)) - while base and path and base[0] == path[0]: - base.pop(0) - path.pop(0) + common = 0 + for a, b in zip(base, path): + if a != b: + break + common += 1 - # If you multiply a list by a negative number, you get an empty list! - return u'/'.join([u'..'] * len(base) + path) + return u'/'.join([u'..'] * (len(base) - common) + path[common:]) class PathMap(object): |