Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5a3ef5b2
Commit
5a3ef5b2
authored
Jun 25, 2010
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
parent
6186bfb7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
8 deletions
+28
-8
Doc/library/os.path.rst
Doc/library/os.path.rst
+1
-0
Lib/macpath.py
Lib/macpath.py
+3
-0
Lib/ntpath.py
Lib/ntpath.py
+3
-0
Lib/os2emxpath.py
Lib/os2emxpath.py
+3
-0
Lib/posixpath.py
Lib/posixpath.py
+3
-0
Lib/test/test_genericpath.py
Lib/test/test_genericpath.py
+12
-8
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/os.path.rst
View file @
5a3ef5b2
...
@@ -201,6 +201,7 @@ applications should use string objects to access all files.
...
@@ -201,6 +201,7 @@ applications should use string objects to access all files.
Normalize the case of a pathname. On Unix and Mac OS X, this returns the
Normalize the case of a pathname. On Unix and Mac OS X, this returns the
path unchanged; on case-insensitive filesystems, it converts the path to
path unchanged; on case-insensitive filesystems, it converts the path to
lowercase. On Windows, it also converts forward slashes to backward slashes.
lowercase. On Windows, it also converts forward slashes to backward slashes.
Raise a TypeError if the type of *path* is not ``str`` or ``bytes``.
.. function:: normpath(path)
.. function:: normpath(path)
...
...
Lib/macpath.py
View file @
5a3ef5b2
...
@@ -32,6 +32,9 @@ def _get_colon(path):
...
@@ -32,6 +32,9 @@ def _get_colon(path):
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
def
normcase
(
path
):
def
normcase
(
path
):
if
not
isinstance
(
path
,
(
bytes
,
str
)):
raise
TypeError
(
"normcase() argument must be str or bytes, "
"not '{}'"
.
format
(
path
.
__class__
.
__name__
))
return
path
.
lower
()
return
path
.
lower
()
...
...
Lib/ntpath.py
View file @
5a3ef5b2
...
@@ -78,6 +78,9 @@ def normcase(s):
...
@@ -78,6 +78,9 @@ def normcase(s):
"""Normalize case of pathname.
"""Normalize case of pathname.
Makes all characters lowercase and all slashes into backslashes."""
Makes all characters lowercase and all slashes into backslashes."""
if
not
isinstance
(
s
,
(
bytes
,
str
)):
raise
TypeError
(
"normcase() argument must be str or bytes, "
"not '{}'"
.
format
(
s
.
__class__
.
__name__
))
return
s
.
replace
(
_get_altsep
(
s
),
_get_sep
(
s
)).
lower
()
return
s
.
replace
(
_get_altsep
(
s
),
_get_sep
(
s
)).
lower
()
...
...
Lib/os2emxpath.py
View file @
5a3ef5b2
...
@@ -36,6 +36,9 @@ def normcase(s):
...
@@ -36,6 +36,9 @@ def normcase(s):
"""Normalize case of pathname.
"""Normalize case of pathname.
Makes all characters lowercase and all altseps into seps."""
Makes all characters lowercase and all altseps into seps."""
if
not
isinstance
(
s
,
(
bytes
,
str
)):
raise
TypeError
(
"normcase() argument must be str or bytes, "
"not '{}'"
.
format
(
s
.
__class__
.
__name__
))
return
s
.
replace
(
'
\
\
'
,
'/'
).
lower
()
return
s
.
replace
(
'
\
\
'
,
'/'
).
lower
()
...
...
Lib/posixpath.py
View file @
5a3ef5b2
...
@@ -49,6 +49,9 @@ def _get_sep(path):
...
@@ -49,6 +49,9 @@ def _get_sep(path):
def
normcase
(
s
):
def
normcase
(
s
):
"""Normalize case of pathname. Has no effect under Posix"""
"""Normalize case of pathname. Has no effect under Posix"""
# TODO: on Mac OS X, this should really return s.lower().
# TODO: on Mac OS X, this should really return s.lower().
if
not
isinstance
(
s
,
(
bytes
,
str
)):
raise
TypeError
(
"normcase() argument must be str or bytes, "
"not '{}'"
.
format
(
s
.
__class__
.
__name__
))
return
s
return
s
...
...
Lib/test/test_genericpath.py
View file @
5a3ef5b2
...
@@ -194,14 +194,18 @@ class CommonTest(GenericTest):
...
@@ -194,14 +194,18 @@ class CommonTest(GenericTest):
]
]
def
test_normcase
(
self
):
def
test_normcase
(
self
):
# Check that normcase() is idempotent
normcase
=
self
.
pathmodule
.
normcase
p
=
"FoO/./BaR"
# check that normcase() is idempotent
p
=
self
.
pathmodule
.
normcase
(
p
)
for
p
in
[
"FoO/./BaR"
,
b"FoO/./BaR"
]:
self
.
assertEqual
(
p
,
self
.
pathmodule
.
normcase
(
p
))
p
=
normcase
(
p
)
self
.
assertEqual
(
p
,
normcase
(
p
))
p
=
b"FoO/./BaR"
p
=
self
.
pathmodule
.
normcase
(
p
)
self
.
assertEqual
(
normcase
(
''
),
''
)
self
.
assertEqual
(
p
,
self
.
pathmodule
.
normcase
(
p
))
self
.
assertEqual
(
normcase
(
b''
),
b''
)
# check that normcase raises a TypeError for invalid types
for
path
in
(
None
,
True
,
0
,
2.5
,
[],
bytearray
(
b''
),
{
'o'
,
'o'
}):
self
.
assertRaises
(
TypeError
,
normcase
,
path
)
def
test_splitdrive
(
self
):
def
test_splitdrive
(
self
):
# splitdrive for non-NT paths
# splitdrive for non-NT paths
...
...
Misc/NEWS
View file @
5a3ef5b2
...
@@ -454,6 +454,9 @@ C-API
...
@@ -454,6 +454,9 @@ C-API
Library
Library
-------
-------
- Issue #9018: os.path.normcase() now raises a TypeError if the argument is
not ``str`` or ``bytes``.
- Issue #9075: In the ssl module, remove the setting of a ``debug`` flag
- Issue #9075: In the ssl module, remove the setting of a ``debug`` flag
on an OpenSSL structure.
on an OpenSSL structure.
...
...
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