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


Python MemoryFS.setcontents方法代码示例

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


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

示例1: test_safety_wrapper

# 需要导入模块: from fs.memoryfs import MemoryFS [as 别名]
# 或者: from fs.memoryfs.MemoryFS import setcontents [as 别名]
 def test_safety_wrapper(self):
     rawfs = MemoryFS()
     safefs = dokan.Win32SafetyFS(rawfs)
     rawfs.setcontents("autoRun.inf", b("evilcodeevilcode"))
     self.assertTrue(safefs.exists("_autoRun.inf"))
     self.assertTrue("autoRun.inf" not in safefs.listdir("/"))
     safefs.setcontents("file:stream",b("test"))
     self.assertFalse(rawfs.exists("file:stream"))
     self.assertTrue(rawfs.exists("file__colon__stream"))
     self.assertTrue("file:stream" in safefs.listdir("/"))
开发者ID:anthonybishopric,项目名称:pyboxfs,代码行数:12,代码来源:test_expose.py

示例2: test_mountfile

# 需要导入模块: from fs.memoryfs import MemoryFS [as 别名]
# 或者: from fs.memoryfs.MemoryFS import setcontents [as 别名]
    def test_mountfile(self):
        """Test mounting a file"""
        quote = b"""If you wish to make an apple pie from scratch, you must first invent the universe."""
        mem_fs = MemoryFS()
        mem_fs.makedir('foo')
        mem_fs.setcontents('foo/bar.txt', quote)
        foo_dir = mem_fs.opendir('foo')

        mount_fs = MountFS()
        mount_fs.mountfile('bar.txt', foo_dir.open, foo_dir.getinfo)

        self.assert_(mount_fs.isdir('/'))
        self.assert_(mount_fs.isdir('./'))
        self.assert_(mount_fs.isdir(''))

        # Check we can see the mounted file in the dir list
        self.assertEqual(mount_fs.listdir(), ["bar.txt"])
        self.assert_(not mount_fs.exists('nobodyhere.txt'))
        self.assert_(mount_fs.exists('bar.txt'))
        self.assert_(mount_fs.isfile('bar.txt'))
        self.assert_(not mount_fs.isdir('bar.txt'))

        # Check open and getinfo callables
        self.assertEqual(mount_fs.getcontents('bar.txt'), quote)
        self.assertEqual(mount_fs.getsize('bar.txt'), len(quote))

        # Check changes are written back
        mem_fs.setcontents('foo/bar.txt', 'baz')
        self.assertEqual(mount_fs.getcontents('bar.txt'), b'baz')
        self.assertEqual(mount_fs.getsize('bar.txt'), len('baz'))

        # Check changes are written to the original fs
        self.assertEqual(mem_fs.getcontents('foo/bar.txt'), b'baz')
        self.assertEqual(mem_fs.getsize('foo/bar.txt'), len('baz'))

        # Check unmount
        self.assert_(mount_fs.unmount("bar.txt"))
        self.assertEqual(mount_fs.listdir(), [])
        self.assert_(not mount_fs.exists('bar.txt'))

        # Check unount a second time is a null op, and returns False
        self.assertFalse(mount_fs.unmount("bar.txt"))
开发者ID:DANCEcollaborative,项目名称:forum-xblock,代码行数:44,代码来源:test_mountfs.py

示例3: TestWalk

# 需要导入模块: from fs.memoryfs import MemoryFS [as 别名]
# 或者: from fs.memoryfs.MemoryFS import setcontents [as 别名]
class TestWalk(unittest.TestCase):
    
    def setUp(self):
        self.fs = MemoryFS()
        self.fs.setcontents('a.txt', 'hello')
        self.fs.setcontents('b.txt', 'world')
        self.fs.makeopendir('foo').setcontents('c', '123')
        self.fs.makeopendir('.svn').setcontents('ignored', '')
    
    def test_wildcard(self):
        for dir_path, paths in self.fs.walk(wildcard='*.txt'):
            for path in paths:
                self.assert_(path.endswith('.txt'))
        for dir_path, paths in self.fs.walk(wildcard=lambda fn:fn.endswith('.txt')):
            for path in paths:
                self.assert_(path.endswith('.txt'))
    
    def test_dir_wildcard(self):
        
        for dir_path, paths in self.fs.walk(dir_wildcard=lambda fn:not fn.endswith('.svn')):            
            for path in paths:                
                self.assert_('.svn' not in path)
开发者ID:atty303,项目名称:pyfilesystem,代码行数:24,代码来源:test_walk.py

示例4: test_priority

# 需要导入模块: from fs.memoryfs import MemoryFS [as 别名]
# 或者: from fs.memoryfs.MemoryFS import setcontents [as 别名]
 def test_priority(self):
     """Test priority order is working"""
     m1 = MemoryFS()
     m2 = MemoryFS()
     m3 = MemoryFS()
     m1.setcontents("name", "m1")
     m2.setcontents("name", "m2")
     m3.setcontents("name", "m3")
     multi_fs = MultiFS(auto_close=False)
     multi_fs.addfs("m1", m1)
     multi_fs.addfs("m2", m2)
     multi_fs.addfs("m3", m3)
     self.assert_(multi_fs.getcontents("name") == "m3")
     
     m1 = MemoryFS()
     m2 = MemoryFS()
     m3 = MemoryFS()
     m1.setcontents("name", "m1")
     m2.setcontents("name", "m2")
     m3.setcontents("name", "m3")
     multi_fs = MultiFS(auto_close=False)
     multi_fs.addfs("m1", m1)
     multi_fs.addfs("m2", m2, priority=10)
     multi_fs.addfs("m3", m3)
     self.assert_(multi_fs.getcontents("name") == "m2")        
     
     m1 = MemoryFS()
     m2 = MemoryFS()
     m3 = MemoryFS()
     m1.setcontents("name", "m1")
     m2.setcontents("name", "m2")
     m3.setcontents("name", "m3")
     multi_fs = MultiFS(auto_close=False)
     multi_fs.addfs("m1", m1)
     multi_fs.addfs("m2", m2, priority=10)
     multi_fs.addfs("m3", m3, priority=10)
     self.assert_(multi_fs.getcontents("name") == "m3")
     
     m1 = MemoryFS()
     m2 = MemoryFS()
     m3 = MemoryFS()
     m1.setcontents("name", "m1")
     m2.setcontents("name", "m2")
     m3.setcontents("name", "m3")
     multi_fs = MultiFS(auto_close=False)
     multi_fs.addfs("m1", m1, priority=11)
     multi_fs.addfs("m2", m2, priority=10)
     multi_fs.addfs("m3", m3, priority=10)
     self.assert_(multi_fs.getcontents("name") == "m1")
     
开发者ID:pombreda,项目名称:agilepyfs,代码行数:51,代码来源:test_multifs.py


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