Browse files

Simplify url_join

  • Loading branch information...
1 parent f15b4b2 commit f092a84ceb9ee984ef981b1bb533626e1fd90abb @k21 committed Jan 9, 2012
Showing with 6 additions and 11 deletions.
  1. +6 −11 r2/r2/lib/utils/utils.py
View
17 r2/r2/lib/utils/utils.py
@@ -1379,23 +1379,18 @@ def url_join(*parts):
an absolute path, ignore all components in front of it.
"""
- #remove empty parts
- parts = filter(None, parts)
-
- if len(parts) == 0: return ''
-
path = []
- if parts[0].startswith('/'): path = ['/']
- path.append(parts[0].strip('/'))
- if parts[0].endswith('/'): path.append('/')
- for p in parts[1:]:
+ for p in parts:
+ if p == '': continue
if p.startswith('/'):
path = ['/']
- elif not path[-1].endswith('/'): path.append('/')
+ if len(path) != 0 and not path[-1].endswith('/'):
+ path.append('/')
stripped = p.strip('/')
if stripped:
path.append(stripped)
- if p.endswith('/'): path.append('/')
+ if p.endswith('/'):
+ path.append('/')
return ''.join(path)

0 comments on commit f092a84

Please sign in to comment.