summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwillmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f>2012-12-03 14:22:08 +0000
committerwillmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f>2012-12-03 14:22:08 +0000
commit1fd025edd27f3eda1418d9e5231ff7e26acef4ec (patch)
tree97c336e43d07e30fdbe93a5f13c2fea2b66625dd
parent2a33b9e1af6600f32f9eaf1536e6a3fa2feb9ee3 (diff)
downloadpyfilesystem-1fd025edd27f3eda1418d9e5231ff7e26acef4ec.tar.gz
Micro-optimization for normpath. I should probably leave that function alone now.
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@838 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r--fs/path.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/fs/path.py b/fs/path.py
index f56b119..8f9f819 100644
--- a/fs/path.py
+++ b/fs/path.py
@@ -22,9 +22,8 @@ _requires_normalization = re.compile(r'/\.\.|\./|^\.$|\.$|//').search
def normpath(path):
"""Normalizes a path to be in the format expected by FS objects.
- This function remove any leading or trailing slashes, collapses
- duplicate slashes, and generally tries very hard to return a new path
- in the canonical FS format.
+ This function removes trailing slashes, collapses duplicate slashes,
+ and generally tries very hard to return a new path in the canonical FS format.
If the path is invalid, ValueError will be raised.
:param path: path to normalize
@@ -47,7 +46,7 @@ def normpath(path):
if not _requires_normalization(path):
return path.rstrip('/')
- components = []
+ components = [''] if path.startswith('/') else []
append = components.append
special = ('..', '.', '').__contains__
try:
@@ -62,9 +61,7 @@ def normpath(path):
# causing a circular import.
from fs.errors import BackReferenceError
raise BackReferenceError('Too many backrefs in \'%s\'' % path)
- if path[0] == '/':
- return '/%s' % '/'.join(components)
- return '/'.join(components)
+ return u'/'.join(components)
if os.sep != '/':