[Python-checkins] r82214 - in python/branches/py3k: Doc/library/os.path.rst Lib/macpath.py Lib/ntpath.py Lib/os2emxpath.py Lib/posixpath.py Lib/test/test_genericpath.py Misc/NEWS
ezio.melotti
python-checkins at python.org
Fri Jun 25 12:56:12 CEST 2010
Author: ezio.melotti
Date: Fri Jun 25 12:56:11 2010
New Revision: 82214
Log:
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Modified:
python/branches/py3k/Doc/library/os.path.rst
python/branches/py3k/Lib/macpath.py
python/branches/py3k/Lib/ntpath.py
python/branches/py3k/Lib/os2emxpath.py
python/branches/py3k/Lib/posixpath.py
python/branches/py3k/Lib/test/test_genericpath.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Doc/library/os.path.rst
==============================================================================
--- python/branches/py3k/Doc/library/os.path.rst (original)
+++ python/branches/py3k/Doc/library/os.path.rst Fri Jun 25 12:56:11 2010
@@ -201,6 +201,7 @@
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
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)
Modified: python/branches/py3k/Lib/macpath.py
==============================================================================
--- python/branches/py3k/Lib/macpath.py (original)
+++ python/branches/py3k/Lib/macpath.py Fri Jun 25 12:56:11 2010
@@ -32,6 +32,9 @@
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
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()
Modified: python/branches/py3k/Lib/ntpath.py
==============================================================================
--- python/branches/py3k/Lib/ntpath.py (original)
+++ python/branches/py3k/Lib/ntpath.py Fri Jun 25 12:56:11 2010
@@ -78,6 +78,9 @@
"""Normalize case of pathname.
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()
Modified: python/branches/py3k/Lib/os2emxpath.py
==============================================================================
--- python/branches/py3k/Lib/os2emxpath.py (original)
+++ python/branches/py3k/Lib/os2emxpath.py Fri Jun 25 12:56:11 2010
@@ -36,6 +36,9 @@
"""Normalize case of pathname.
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()
Modified: python/branches/py3k/Lib/posixpath.py
==============================================================================
--- python/branches/py3k/Lib/posixpath.py (original)
+++ python/branches/py3k/Lib/posixpath.py Fri Jun 25 12:56:11 2010
@@ -49,6 +49,9 @@
def normcase(s):
"""Normalize case of pathname. Has no effect under Posix"""
# 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
Modified: python/branches/py3k/Lib/test/test_genericpath.py
==============================================================================
--- python/branches/py3k/Lib/test/test_genericpath.py (original)
+++ python/branches/py3k/Lib/test/test_genericpath.py Fri Jun 25 12:56:11 2010
@@ -194,14 +194,18 @@
]
def test_normcase(self):
- # Check that normcase() is idempotent
- p = "FoO/./BaR"
- p = self.pathmodule.normcase(p)
- self.assertEqual(p, self.pathmodule.normcase(p))
-
- p = b"FoO/./BaR"
- p = self.pathmodule.normcase(p)
- self.assertEqual(p, self.pathmodule.normcase(p))
+ normcase = self.pathmodule.normcase
+ # check that normcase() is idempotent
+ for p in ["FoO/./BaR", b"FoO/./BaR"]:
+ p = normcase(p)
+ self.assertEqual(p, normcase(p))
+
+ self.assertEqual(normcase(''), '')
+ 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):
# splitdrive for non-NT paths
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Fri Jun 25 12:56:11 2010
@@ -454,6 +454,9 @@
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
on an OpenSSL structure.
More information about the Python-checkins
mailing list