Python源码示例:ntpath.splitunc()

示例1
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'))
        if test_support.have_unicode:
            self.assertEqual(ntpath.splitunc(u'//conky/MOUNTPO%cNT/foo/bar' % 0x0130),
                             (u'//conky/MOUNTPO%cNT' % 0x0130, u'/foo/bar')) 
示例2
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')) 
示例3
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')) 
示例4
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')) 
示例5
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')) 
示例6
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')) 
示例7
def test_splitunc(self):
        tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar')) 
示例8
def test_splitunc(self):
        tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar')) 
示例9
def relpath_win(self, path, start="."):
        """Return a relative version of a path"""
        sep="\\"

        if not path:
            raise ValueError("no path specified")
        start_list = ntpath.abspath(start).split(sep)
        path_list = ntpath.abspath(path).split(sep)
        if start_list[0].lower() != path_list[0].lower():
            unc_path, rest = ntpath.splitunc(path)
            unc_start, rest = ntpath.splitunc(start)
            if bool(unc_path) ^ bool(unc_start):
                raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
                                                                    % (path, start))
            else:
                raise ValueError("path is on drive %s, start on drive %s"
                                                    % (path_list[0], start_list[0]))
        # Work out how much of the filepath is shared by start and path.
        for i in range(min(len(start_list), len(path_list))):
            if start_list[i].lower() != path_list[i].lower():
                break
        else:
            i += 1
    
        rel_list = ['..'] * (len(start_list)-i) + path_list[i:]
        if not rel_list:
            return "."
        return ntpath.join(*rel_list) 
示例10
def test_splitunc(self):
        tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar'))