]> granicus.if.org Git - python/commitdiff
Issue #19912: Fixed numerous bugs in ntpath.splitunc().
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 16 Dec 2013 13:13:28 +0000 (15:13 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 16 Dec 2013 13:13:28 +0000 (15:13 +0200)
* 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().

Lib/ntpath.py
Lib/test/test_ntpath.py
Misc/NEWS

index 598c64f641ae65dfea63eae96988613748cfc3f5..b05436ed800a96dbe67e95d60d65fc6c87643ecf 100644 (file)
@@ -243,26 +243,12 @@ def splitunc(p):
     """
     import warnings
     warnings.warn("ntpath.splitunc is deprecated, use ntpath.splitdrive instead",
-                  DeprecationWarning)
-    sep = _get_sep(p)
-    if not p[1:2]:
-        return p[:0], p # Drive letter present
-    firstTwo = p[0:2]
-    if normcase(firstTwo) == sep + sep:
-        # 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
+                  DeprecationWarning, 2)
+    drive, path = splitdrive(p)
+    if len(drive) == 2:
+         # Drive letter present
+        return p[:0], p
+    return drive, path
 
 
 # Split a path in head (everything up to the last '/') and tail (the
index 94c57b2188a32e358d377d529266b31ccef9d577..b0f3011e31feb1164693aee7ad3ebf8318537393 100644 (file)
@@ -70,6 +70,29 @@ class TestNtpath(unittest.TestCase):
         self.assertEqual(ntpath.splitdrive('//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):
         tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
         tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
index c5244d301d13164559d3208a70a8ab1ef13294e8..b0c1e36684caccc295f4b00b07ea77e573ffc580 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #19912: Fixed numerous bugs in ntpath.splitunc().
+
 - Issue #19911: ntpath.splitdrive() now correctly processes the 'İ' character
   (U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
 
@@ -147,6 +149,8 @@ IDLE
 Tests
 -----
 
+- Issue #19912: Added tests for ntpath.splitunc().
+
 - Issue #19828: Fixed test_site when the whole suite is run with -S.
 
 - Issue #19928: Implemented a test for repr() of cell objects.