Commit 593568bf authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19912: Fixed numerous bugs in ntpath.splitunc().

* splitunc() no more return illegal result for paths with redundant slashes.
* splitunc() now correctly processes the 'İ' character
  (U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
* Deprecation warnings now emitted for every use of splitunc().
* Added tests for splitunc().
parent 3d7e1152
...@@ -243,26 +243,12 @@ def splitunc(p): ...@@ -243,26 +243,12 @@ def splitunc(p):
""" """
import warnings import warnings
warnings.warn("ntpath.splitunc is deprecated, use ntpath.splitdrive instead", warnings.warn("ntpath.splitunc is deprecated, use ntpath.splitdrive instead",
DeprecationWarning) DeprecationWarning, 2)
sep = _get_sep(p) drive, path = splitdrive(p)
if not p[1:2]: if len(drive) == 2:
return p[:0], p # Drive letter present # Drive letter present
firstTwo = p[0:2] return p[:0], p
if normcase(firstTwo) == sep + sep: return drive, path
# is a UNC path:
# vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
# \\machine\mountpoint\directories...
# directory ^^^^^^^^^^^^^^^
normp = normcase(p)
index = normp.find(sep, 2)
if index == -1:
##raise RuntimeError, 'illegal UNC path: "' + p + '"'
return (p[:0], p)
index = normp.find(sep, index + 1)
if index == -1:
index = len(p)
return p[:index], p[index:]
return p[:0], p
# Split a path in head (everything up to the last '/') and tail (the # Split a path in head (everything up to the last '/') and tail (the
......
...@@ -70,6 +70,29 @@ class TestNtpath(unittest.TestCase): ...@@ -70,6 +70,29 @@ class TestNtpath(unittest.TestCase):
self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'), self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'),
('//conky/MOUNTPOİNT', '/foo/bar')) ('//conky/MOUNTPOİNT', '/foo/bar'))
def test_splitunc(self):
with self.assertWarns(DeprecationWarning):
ntpath.splitunc('')
with support.check_warnings(('', DeprecationWarning)):
tester('ntpath.splitunc("c:\\foo\\bar")',
('', 'c:\\foo\\bar'))
tester('ntpath.splitunc("c:/foo/bar")',
('', 'c:/foo/bar'))
tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
('\\\\conky\\mountpoint', '\\foo\\bar'))
tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
('//conky/mountpoint', '/foo/bar'))
tester('ntpath.splitunc("\\\\\\conky\\mountpoint\\foo\\bar")',
('', '\\\\\\conky\\mountpoint\\foo\\bar'))
tester('ntpath.splitunc("///conky/mountpoint/foo/bar")',
('', '///conky/mountpoint/foo/bar'))
tester('ntpath.splitunc("\\\\conky\\\\mountpoint\\foo\\bar")',
('', '\\\\conky\\\\mountpoint\\foo\\bar'))
tester('ntpath.splitunc("//conky//mountpoint/foo/bar")',
('', '//conky//mountpoint/foo/bar'))
self.assertEqual(ntpath.splitunc('//conky/MOUNTPOİNT/foo/bar'),
('//conky/MOUNTPOİNT', '/foo/bar'))
def test_split(self): def test_split(self):
tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar')) tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")', tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
......
...@@ -29,6 +29,8 @@ Core and Builtins ...@@ -29,6 +29,8 @@ Core and Builtins
Library Library
------- -------
- Issue #19912: Fixed numerous bugs in ntpath.splitunc().
- Issue #19911: ntpath.splitdrive() now correctly processes the 'İ' character - Issue #19911: ntpath.splitdrive() now correctly processes the 'İ' character
(U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE). (U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
...@@ -147,6 +149,8 @@ IDLE ...@@ -147,6 +149,8 @@ IDLE
Tests Tests
----- -----
- Issue #19912: Added tests for ntpath.splitunc().
- Issue #19828: Fixed test_site when the whole suite is run with -S. - Issue #19828: Fixed test_site when the whole suite is run with -S.
- Issue #19928: Implemented a test for repr() of cell objects. - Issue #19928: Implemented a test for repr() of cell objects.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment