From dea39fa59174feeb1349bdc6ea6969c120ad111a Mon Sep 17 00:00:00 2001 From: "willmcgugan@gmail.com" Date: Fri, 28 Jun 2013 12:33:30 +0000 Subject: simpler version of relativefrom git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@858 67cdc799-7952-0410-af00-57a81ceafa0f --- fs/path.py | 11 ++++++----- 1 file 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): -- cgit v1.2.1