[Python-checkins] cpython (2.7): Issue #19912: Fixed numerous bugs in ntpath.splitunc().

serhiy.storchaka python-checkins at python.org
Mon Dec 16 14:22:55 CET 2013


http://hg.python.org/cpython/rev/e4beb183a674
changeset: 87991:e4beb183a674
branch: 2.7
parent: 87956:c10ea224392d
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Dec 16 15:15:29 2013 +0200
summary:
 Issue #19912: Fixed numerous bugs in ntpath.splitunc().
* splitunc() no more returns illegal result for paths with redundant slashes.
* splitunc() now correctly processes the u'İ' character
 (U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
* Added new tests for splitunc().
files:
 Lib/ntpath.py | 40 ++++++++++++++++++++++------
 Lib/test/test_ntpath.py | 14 ++++++++++
 Misc/NEWS | 2 +
 3 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -136,6 +136,25 @@
 using backslashes). unc+rest is always the input path.
 Paths containing drive letters never have an UNC part.
 """
+ #if p[1:2] == ':':
+ #return '', p # Drive letter present
+ #firstTwo = p[0:2]
+ #if firstTwo == '//' or firstTwo == '\\\\':
+ ## is a UNC path:
+ ## vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
+ ## \\machine\mountpoint\directories...
+ ## directory ^^^^^^^^^^^^^^^
+ #normp = normcase(p)
+ #index = normp.find('\\', 2)
+ #if index == -1:
+ ###raise RuntimeError, 'illegal UNC path: "' + p + '"'
+ #return ("", p)
+ #index = normp.find('\\', index + 1)
+ #if index == -1:
+ #index = len(p)
+ #return p[:index], p[index:]
+ #return '', p
+
 if p[1:2] == ':':
 return '', p # Drive letter present
 firstTwo = p[0:2]
@@ -144,15 +163,18 @@
 # vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
 # \\machine\mountpoint\directories...
 # directory ^^^^^^^^^^^^^^^
- normp = normcase(p)
- index = normp.find('\\', 2)
- if index == -1:
- ##raise RuntimeError, 'illegal UNC path: "' + p + '"'
- return ("", p)
- index = normp.find('\\', index + 1)
- if index == -1:
- index = len(p)
- return p[:index], p[index:]
+ normp = p.replace('\\', '/')
+ index = normp.find('/', 2)
+ if index <= 2:
+ return '', p
+ index2 = normp.find('/', index + 1)
+ # a UNC path can't have two slashes in a row
+ # (after the initial two)
+ if index2 == index + 1:
+ return '', p
+ if index2 == -1:
+ index2 = len(p)
+ return p[:index2], p[index2:]
 return '', p
 
 
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -33,10 +33,24 @@
 ('c:', '/foo/bar'))
 
 def test_splitunc(self):
+ 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(u'//conky/MOUNTPO\u0130NT/foo/bar'),
+ (u'//conky/MOUNTPO\u0130NT', u'/foo/bar'))
 
 def test_split(self):
 tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,8 @@
 Library
 -------
 
+- Issue #19912: Fixed numerous bugs in ntpath.splitunc().
+
 - Issue #19623: Fixed writing to unseekable files in the aifc module.
 Fixed writing 'ulaw' (lower case) compressed AIFC files.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /