From 1fd025edd27f3eda1418d9e5231ff7e26acef4ec Mon Sep 17 00:00:00 2001 From: "willmcgugan@gmail.com" Date: Mon, 3 Dec 2012 14:22:08 +0000 Subject: 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 --- fs/path.py | 11 ++++------- 1 file 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 != '/': -- cgit v1.2.1