當前位置: 首頁>>代碼示例>>Python>>正文


Python base.URI類代碼示例

本文整理匯總了Python中abl.vpath.base.URI的典型用法代碼示例。如果您正苦於以下問題:Python URI類的具體用法?Python URI怎麽用?Python URI使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了URI類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_split_windows

 def test_split_windows(self):
     path = URI(r'C:\some\path\on\windows', sep='\\')
     pth, tail = path.split()
     self.assertEqual(pth.uri, 'file:///C/some/path/on')
     self.assertEqual(pth.path, r'C:\some\path\on')
     self.assertEqual(pth, URI(r'C:\some\path\on', sep='\\'))
     self.assertEqual(tail, 'windows')
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:7,代碼來源:test_path.py

示例2: test_dirname

 def test_dirname(self):
     pth = URI("/this/is/a/path")
     self.assertEqual(pth.dirname(), URI("/this/is/a"))
     self.assertEqual(pth.dirname(level=2), URI("/this/is"))
     self.assertEqual(pth.dirname(level=3), URI("/this"))
     self.assertEqual(pth.dirname(level=4), URI("/"))
     self.assertEqual(pth.dirname(level=5), URI("/"))
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:7,代碼來源:test_path.py

示例3: test_write_two_files

 def test_write_two_files(self):
     foo = URI('zip://((%s))/foo.txt' % self.zip_uri)
     with foo.open('wb') as fd:
         fd.write(b'bar')
     bar = URI('zip://((%s))/bar.txt' % self.zip_uri)
     with bar.open('wb') as fd:
         fd.write(b'foo')
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:7,代碼來源:test_zip.py

示例4: TestAdvancedZip

class TestAdvancedZip(ZipTestCase):

    def setUp(self):
        super(TestAdvancedZip, self).setUp()
        self.zip_path = URI('memory:///file.zip')
        zip_handle = self.zip_path.open('wb')
        try:
            self.fp_zip = ZipFile(zip_handle, 'w')
            self.fp_zip.writestr('/dir1/foo.txt', 'bar')
            self.fp_zip.writestr('/dir1/bar.txt', 'bar')
            self.fp_zip.writestr('/bar.txt', 'bar')
            self.fp_zip.close()
        finally:
            zip_handle.close()

    def tearDown(self):
        self.zip_path.remove()


    def test_walk(self):
        root = URI('zip://((%s))/' % self.zip_path.uri)
        self.assertEqual(len(root.listdir()), 2)
        rlist = []
        for base, dirs, files in root.walk():
            rlist.append((base, dirs, files))
        self.assertEqual(rlist,
                         [(root, ['dir1'], ['bar.txt']),
                          ((root / 'dir1'), [], ['bar.txt', 'foo.txt'])])
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:28,代碼來源:test_zip.py

示例5: TestWritingZip

class TestWritingZip(ZipTestCase):
    def setUp(self):
        super(TestWritingZip, self).setUp()
        self.zip_uri = 'file://./file.zip'
        self.zip_path = URI(self.zip_uri)


    def tearDown(self):
        # reset the connection registry, otherwise the zip file cannot
        # be deleted on windows since it is still opened by the
        # backend
        CONNECTION_REGISTRY.cleanup(force=True)
        if self.zip_path.exists():
            self.zip_path.remove()


    def test_write_file_to_non_existing_zip(self):
        foo = URI('zip://((%s))/foo.txt' % self.zip_uri)
        with foo.open('wb') as fd:
            fd.write(b'bar')


    def test_write_file_to_non_existing_zip_2(self):
        foo = URI('zip://((%s))/deeper/foo.txt' % self.zip_uri)
        with foo.open('wb') as fd:
            fd.write(b'bar')


    def test_write_two_files(self):
        foo = URI('zip://((%s))/foo.txt' % self.zip_uri)
        with foo.open('wb') as fd:
            fd.write(b'bar')
        bar = URI('zip://((%s))/bar.txt' % self.zip_uri)
        with bar.open('wb') as fd:
            fd.write(b'foo')
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:35,代碼來源:test_zip.py

示例6: test_walk

 def test_walk(self):
     root = URI('zip://((%s))/' % self.zip_path.uri)
     self.assertEqual(len(root.listdir()), 2)
     rlist = []
     for base, dirs, files in root.walk():
         rlist.append((base, dirs, files))
     self.assertEqual(rlist,
                      [(root, ['dir1'], ['bar.txt']),
                       ((root / 'dir1'), [], ['bar.txt', 'foo.txt'])])
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:9,代碼來源:test_zip.py

示例7: test_globbing_by_suffix

    def test_globbing_by_suffix(self):
        base = URI("memory:///")
        a = base / "a.foo"
        b = base / "b.bar"

        for f in [a, b]:
            with f.open("w") as outf:
                outf.write("foo")

        self.assertEqual([a], base.glob("a.*"))
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:10,代碼來源:test_misc.py

示例8: test_split

    def test_split(self):
        local_path = URI('/some/long/dir/structure')
        pth, tail = local_path.split()
        self.assertEqual(pth, URI('/some/long/dir'))
        self.assertEqual(tail, 'structure')

        local_path = URI('somedir')
        pth, tail = local_path.split()
        self.assertEqual(pth, URI('.'))
        self.assertEqual(tail, 'somedir')
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:10,代碼來源:test_path.py

示例9: test_setting_mode

 def test_setting_mode(self):
     # setting the permission flags are not supported on windows
     if sys.platform != "win32":
         p = URI("test.txt")
         mode = p.info().mode
         new_mode = mode | stat.S_IXUSR
         p.info(dict(mode=new_mode))
         self.assertEqual(
             p.info().mode,
             new_mode,
             )
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:11,代碼來源:test_localfs.py

示例10: TestReadingZip

class TestReadingZip(ZipTestCase):

    def setUp(self):
        super(TestReadingZip, self).setUp()
        self.zip_path = URI('memory:///file.zip')
        zip_handle = self.zip_path.open('wb')
        try:
            self.fp_zip = ZipFile(zip_handle, 'w')
            self.fp_zip.writestr('/foo.txt', 'bar')
            self.fp_zip.close()
        finally:
            zip_handle.close()

    def tearDown(self):
        if self.zip_path.exists():
            self.zip_path.remove()


    def test_read_a_file(self):
        p = URI('zip://((memory:///file.zip))/foo.txt')
        with p.open('rb') as fd:
            self.assertEqual(fd.read(), b'bar')

    def test_write_a_file(self):
        p = URI('zip://((memory:///file.zip))/bar.txt')
        with p.open('wb') as fd:
            fd.write(b'foo')
        with p.open() as fd:
            self.assertEqual(fd.read(), b'foo')

    def test_exists(self):
        p = URI('zip://((memory:///file.zip))/foo.txt')
        with p.open('wb') as fd:
            fd.write(b'foo')
        self.assertTrue(p.exists())

    def test_isfile(self):
        p = URI('zip://((memory:///file.zip))/foo.txt')
        with p.open('wb') as fd:
            fd.write(b'foo')
        self.assertTrue(p.isfile())

    def test_isdir(self):
        dir_path = URI('zip://((memory:///file.zip))/somedir')
        p = dir_path / 'foo.txt'
        with p.open('wb') as fd:
            fd.write(b'foo')
        self.assertTrue(dir_path.isdir())

    def test_path(self):
        dir_path = URI('zip://((memory:///file.zip))/somedir')
        self.assertEqual(dir_path.path, '/somedir')
        new_path = dir_path / 'other'
        self.assertEqual(new_path.path, '/somedir/other')
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:54,代碼來源:test_zip.py

示例11: test_globbing_by_prefix_in_subdir

    def test_globbing_by_prefix_in_subdir(self):
        base = URI("memory:///") / "dir"
        base.mkdir()
        a = base / "a.foo"
        b = base / "b.bar"

        for f in [a, b]:
            with f.open("w") as outf:
                outf.write("foo")

        self.assertEqual([a], base.glob("*.foo"))
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:11,代碼來源:test_misc.py

示例12: test_copy_empty_dirs_recursive

    def test_copy_empty_dirs_recursive(self):
        root = URI(self.baseurl)
        root.makedirs()

        gaz_path = root / 'gaz'
        gaz_path.makedirs()

        moo_path = root / 'moo'

        gaz_path.copy(moo_path, recursive=True)

        self.assertTrue((moo_path).isdir())
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:12,代碼來源:test_fs.py

示例13: tearDown

 def tearDown(self):
     p = URI("test.txt")
     if p.exists():
         p.remove()
     l = URI("test_link")
     if l.islink():
         l.remove()
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:7,代碼來源:test_localfs.py

示例14: test_remove_recursive_with_readonly_file

    def test_remove_recursive_with_readonly_file(self):
        foo_path = URI(self.baseurl) / 'foo'
        bar_path = foo_path / 'bar'
        bar_path.makedirs()

        gaz_path = bar_path / 'ghaz.txt'
        create_file(gaz_path)

        mode = gaz_path.info().mode
        gaz_path.info(set_info=dict(mode=mode & ~stat.S_IWUSR))

        foo_path.remove(recursive=True)

        self.assertTrue(not foo_path.exists())
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:14,代碼來源:test_fs.py

示例15: tearDown

 def tearDown(self):
     p = URI(self.foo_dir)
     if p.isdir():
         p.remove(recursive=True)
     b = URI(self.bar_dir)
     if b.isdir():
         b.remove(recursive=True)
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:7,代碼來源:test_path.py


注:本文中的abl.vpath.base.URI類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。