summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwillmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f>2013-06-28 12:33:30 +0000
committerwillmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f>2013-06-28 12:33:30 +0000
commitdea39fa59174feeb1349bdc6ea6969c120ad111a (patch)
tree1f9bf5e69afc1e3d87bf5a9ab8a0a2b2038ece4d
parent9545ff3d5e3605d2c70a67a2de9607bd34d08014 (diff)
downloadpyfilesystem-dea39fa59174feeb1349bdc6ea6969c120ad111a.tar.gz
simpler version of relativefrom
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@858 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r--fs/path.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/fs/path.py b/fs/path.py
index ec97d1c..8967900 100644
--- a/fs/path.py
+++ b/fs/path.py
@@ -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):