Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
59b5cfdc
Commit
59b5cfdc
authored
Dec 03, 2012
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Micro-optimization for normpath. I should probably leave that function alone now.
parent
9ff3da0c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
7 deletions
+4
-7
fs/path.py
+4
-7
No files found.
fs/path.py
View file @
59b5cfdc
...
...
@@ -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
!=
'/'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment