diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-12-03 14:22:08 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-12-03 14:22:08 +0000 |
commit | 1fd025edd27f3eda1418d9e5231ff7e26acef4ec (patch) | |
tree | 97c336e43d07e30fdbe93a5f13c2fea2b66625dd /fs | |
parent | 2a33b9e1af6600f32f9eaf1536e6a3fa2feb9ee3 (diff) | |
download | pyfilesystem-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
Diffstat (limited to 'fs')
-rw-r--r-- | fs/path.py | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -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 != '/': |