当前位置: 首页>>代码示例>>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;未经允许,请勿转载。