Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2ad88c

Browse files
committed
Rewrite normcase() using string.translate...
1 parent efa6837 commit e2ad88c

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

Lib/ntpath.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,15 @@
55
import string
66

77

8-
# Normalize the case of a pathname.
9-
# On MS-DOS it maps the pathname to lowercase, turns slashes into
10-
# backslashes.
11-
# Other normalizations (such as optimizing '../' away) are not allowed
8+
# Normalize the case of a pathname and map slashes to backslashes.
9+
# Other normalizations (such as optimizing '../' away) are not done
1210
# (this is done by normpath).
13-
# Previously, this version mapped invalid consecutive characters to a
14-
# single '_', but this has been removed. This functionality should
15-
# possibly be added as a new function.
11+
12+
_normtable = string.maketrans(string.uppercase + "\\/",
13+
string.lowercase + os.sep * 2)
1614

1715
def normcase(s):
18-
res, s = splitdrive(s)
19-
for c in s:
20-
if c in '/\\':
21-
res = res + os.sep
22-
else:
23-
res = res + c
24-
return string.lower(res)
16+
return string.translate(s, _normtable)
2517

2618

2719
# Return wheter a path is absolute.

0 commit comments

Comments
 (0)