当前位置: 首页>>代码示例>>Python>>正文


Python URI.remove方法代码示例

本文整理汇总了Python中abl.vpath.base.URI.remove方法的典型用法代码示例。如果您正苦于以下问题:Python URI.remove方法的具体用法?Python URI.remove怎么用?Python URI.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在abl.vpath.base.URI的用法示例。


在下文中一共展示了URI.remove方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tearDown

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
 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,代码行数:9,代码来源:test_localfs.py

示例2: tearDown

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
 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,代码行数:9,代码来源:test_path.py

示例3: TestWritingZip

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
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,代码行数:37,代码来源:test_zip.py

示例4: TestAdvancedZip

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
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,代码行数:30,代码来源:test_zip.py

示例5: test_locking

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
 def test_locking(self):
     try:
         p = URI("lock.txt")
         content = "I'm something written into a locked file"
         with p.lock() as inf:
             inf.write(content)
         self.assertEqual(p.open().read(), content)
     finally:
         if p.exists():
             p.remove()
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:12,代码来源:test_localfs.py

示例6: TestReadingZip

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
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,代码行数:56,代码来源:test_zip.py

示例7: test_remove_recursive_with_readonly_file

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
    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,代码行数:16,代码来源:test_fs.py

示例8: test_dir

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
    def test_dir(self):
        testdir = URI('testdir')
        testdir.makedirs()
        self.assertTrue(testdir.exists())
        self.assertTrue(testdir.isdir())
        self.assertTrue(not testdir.isfile())
        testfile = URI('testdir/somefile')
        create_file(testfile, content='test')
        testdir.remove(recursive=True)
        self.assertTrue(not testdir.exists())
        self.assertTrue(not testfile.exists())

        testdir = URI(self.existing_dir)
        self.assertTrue(testdir.exists())
        self.assertTrue(testdir.isdir())
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:17,代码来源:test_fs.py

示例9: test_file

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
    def test_file(self):
        path = URI(self.baseurl) / 'testfile.txt'
        create_file(path, content='hallo')
        content = load_file(path)

        self.assertEqual(content, 'hallo')
        self.assertTrue(path.exists())
        self.assertTrue(path.isfile())
        path.remove()
        self.assertTrue(not path.exists())

        path = URI(self.existing_file)
        self.assertTrue(path.exists())
        self.assertTrue(path.isfile())

        content = load_file(path)
        self.assertTrue(content)
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:19,代码来源:test_fs.py

示例10: test_copy_and_move_file

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
    def test_copy_and_move_file(self):
        single_file = URI(self.non_existing_file)
        target_file = URI(self.baseurl) / 'target_file.txt'
        create_file(single_file)

        single_file.copy(target_file)
        self.assertTrue(target_file.exists())
        self.assertTrue(target_file.isfile())
        self.assertEqual(load_file(target_file), 'content')

        target_file.remove()
        self.assertTrue(not target_file.exists())
        single_file.move(target_file)

        self.assertTrue(not single_file.exists())
        self.assertTrue(target_file.exists())
        self.assertTrue(target_file.isfile())

        self.assertEqual(load_file(target_file), 'content')
        target_file.remove()
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:22,代码来源:test_fs.py

示例11: TestListDir

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
class TestListDir(ZipTestCase):
    def setUp(self):
        super(TestListDir, self).setUp()
        self.zip_path = URI('memory:///file.zip')

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

    def test_listdir(self):
        base_path = URI('zip://((%s))/' % self.zip_path.uri)
        self.assertEqual(base_path.listdir(), [])
        p1 = URI('zip://((%s))/foo.txt' % self.zip_path.uri)
        with p1.open('wb') as fd:
            fd.write(b'foo')
        self.assertEqual(base_path.listdir(), ['foo.txt'])
        p2 = URI('zip://((%s))/dir/foo.txt' % self.zip_path.uri)
        with p2.open('w') as fd:
            fd.write(b'foo')
        self.assertEqual(set(base_path.listdir()), set(['foo.txt', 'dir']))
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:22,代码来源:test_zip.py

示例12: test_manipulation_api

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
    def test_manipulation_api(self):
        p = self.root_path / "test.txt"
        p._manipulate(lock=True)
        mfile = p.open("w")
        assert not mfile.lock.acquire(False)
        p._manipulate(unlock=True)
        try:
            assert mfile.lock.acquire(False)
        finally:
            mfile.lock.release()

        with p.open("w") as outf:
            outf.write("foo")

        old_mtime = p.mtime()
        new_mtime = old_mtime + 100
        p._manipulate(mtime=new_mtime)

        self.assertEqual(p.mtime(), new_mtime)

        error_file = self.root_path / "error"

        with error_file.open("wb") as outf:
            outf.write(b"foobarbaz")

        error_dir = self.root_path / "error.dir"
        error_dir.mkdir()

        def next_op_callback(_path, _func):
            raise OSError(13, "Permission denied")

        for error in (error_file, error_dir):
            error._manipulate(next_op_callback=next_op_callback)
            clone = URI(error)
            try:
                clone.remove()
            except OSError as e:
                self.assertEqual(e.errno, 13)
            else:
                assert False, "Shouldn't be here"
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:42,代码来源:test_memory.py

示例13: test_copy_and_move_dir

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
    def test_copy_and_move_dir(self):
        folder = URI(self.baseurl) / 'folder'
        folder.makedirs()

        self.assertTrue(folder.isdir())
        afile = folder / 'afile.txt'
        create_file(afile)

        target = URI(self.baseurl) / 'target'
        self.assertTrue(not target.exists())
        folder.copy(target, recursive=True)
        self.assertTrue(target.exists())

        target_file = target / 'afile.txt'
        self.assertTrue(target_file.exists())
        self.assertEqual(load_file(target_file), 'content')

        target.remove(recursive=True)
        self.assertTrue(not target.exists())
        target.makedirs()
        folder.copy(target, recursive=True)

        newtarget = target / 'folder'
        self.assertTrue(newtarget.exists())
        self.assertTrue(newtarget.isdir())

        newtarget_file = newtarget / 'afile.txt'
        self.assertTrue(newtarget_file.exists())
        self.assertTrue(newtarget_file.isfile())
        target.remove(recursive=True)

        folder.move(target)
        self.assertTrue(not folder.exists())
        self.assertTrue(target.exists())
        self.assertTrue(target.isdir())
        self.assertTrue(target_file.exists())
        self.assertTrue(target_file.isfile())
        target.remove(recursive=True)
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:40,代码来源:test_fs.py

示例14: MemoryFSTests

# 需要导入模块: from abl.vpath.base import URI [as 别名]
# 或者: from abl.vpath.base.URI import remove [as 别名]
class MemoryFSTests(CleanupMemoryBeforeTestMixin, TestCase):

    def setUp(self):
        super(MemoryFSTests, self).setUp()
        self.temp_path = URI(tempfile.mktemp())
        self.temp_path.mkdir()
        self.root = URI("memory:///")


    def tearDown(self):
        if self.temp_path.isdir():
            self.temp_path.remove(recursive=True)
        super(MemoryFSTests, self).tearDown()


    def test_all(self):
        root = self.root
        assert root.isdir()

        subdir = root / "foo"

        subdir.mkdir()

        assert subdir.isdir()
        assert not subdir.isfile()

        out = subdir / "bar"

        with out.open("w") as outf:
            outf.write("foobar")

        assert not out.isdir()
        assert out.isfile()

        with out.open() as inf:
            content = inf.read()
            self.assertEqual(content, "foobar")


        assert subdir == root / "foo"

        time.sleep(.5)
        assert out.info().mtime < time.time()

        connection = subdir.connection
        out = StringIO()
        connection.dump(out)
        print((out.getvalue()))


    def test_write_text_read_binary(self):
        test_file = self.root / 'foo'
        with test_file.open('w') as text_proxy:
            text_proxy.write("spam & eggs")
        with test_file.open('rb') as binary_proxy:
            self.assertEqual(binary_proxy.read(), b"spam & eggs")


    def test_write_binary_read_text(self):
        test_file = self.root / 'foo'
        with test_file.open('wb') as binary_proxy:
            binary_proxy.write(b"spam & eggs")
        with test_file.open('r') as text_proxy:
            self.assertEqual(text_proxy.read(), "spam & eggs")


    def test_info_on_symlinks(self):
        root = self.root
        a_file = root / "a_file"
        a_link = root / "a_link"
        with a_file.open('w') as f:
            f.write("a" * 800)
        a_file.symlink(a_link)

        self.assertEqual(a_file.info().size, 800)
        self.assertEqual(a_link.info().size, 800)
        self.assertNotEqual(a_link.info(followlinks=False).size, 800)

        orig_info = a_file.info()
        new_info = a_file.info()
        new_info.mtime = new_info.mtime + 100
        a_link.info(new_info, followlinks=False)

        self.assertEqual(a_file.info().mtime, orig_info.mtime)
        self.assertEqual(a_link.info().mtime, orig_info.mtime)
        self.assertEqual(a_link.info(followlinks=False).mtime, new_info.mtime)


    def test_listdir_empty_root(self):
        root = self.root
        files = root.listdir()
        assert not files


    def test_listdir_empty_dir(self):
        root = self.root
        foo = root / 'foo'
        foo.mkdir()
        rootfiles = root.listdir()
        assert 'foo' in rootfiles
#.........这里部分代码省略.........
开发者ID:AbletonAG,项目名称:abl.vpath,代码行数:103,代码来源:test_memory.py


注:本文中的abl.vpath.base.URI.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。