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


Python Gluster_DiskFile.mkstemp方法代码示例

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


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

示例1: test_mkstemp

# 需要导入模块: from gluster.swift.common.DiskFile import Gluster_DiskFile [as 别名]
# 或者: from gluster.swift.common.DiskFile.Gluster_DiskFile import mkstemp [as 别名]
 def test_mkstemp(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "dir")
     try:
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "dir/z", self.lg)
         saved_tmppath = ''
         with gdf.mkstemp() as fd:
             assert gdf.datadir == os.path.join(td, "vol0", "bar", "dir")
             assert os.path.isdir(gdf.datadir)
             saved_tmppath = gdf.tmppath
             assert os.path.dirname(saved_tmppath) == gdf.datadir
             assert os.path.basename(saved_tmppath)[:3] == '.z.'
             assert os.path.exists(saved_tmppath)
             os.write(fd, "123")
         # At the end of previous with block a close on fd is called.
         # Calling os.close on the same fd will raise an OSError
         # exception and we must catch it.
         try:
             os.close(fd)
         except OSError as err:
             pass
         else:
             self.fail("Exception expected")
         assert not os.path.exists(saved_tmppath)
     finally:
         shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:30,代码来源:test_diskfile.py

示例2: test_put_obj_path

# 需要导入模块: from gluster.swift.common.DiskFile import Gluster_DiskFile [as 别名]
# 或者: from gluster.swift.common.DiskFile.Gluster_DiskFile import mkstemp [as 别名]
    def test_put_obj_path(self):
        the_obj_path = os.path.join("b", "a")
        the_file = os.path.join(the_obj_path, "z")
        td = tempfile.mkdtemp()
        try:
            gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                   the_file, self.lg)
            assert gdf._obj == "z"
            assert gdf._obj_path == the_obj_path
            assert gdf.name == os.path.join("bar", "b", "a")
            assert gdf.datadir == os.path.join(td, "vol0", "bar", "b", "a")
            assert gdf.data_file is None

            body = '1234\n'
            etag = md5()
            etag.update(body)
            etag = etag.hexdigest()
            metadata = {
                'X-Timestamp': '1234',
                'Content-Type': 'file',
                'ETag': etag,
                'Content-Length': '5',
                }

            with gdf.mkstemp() as fd:
                assert gdf.tmppath is not None
                tmppath = gdf.tmppath
                os.write(fd, body)
                gdf.put(fd, metadata)

            assert gdf.data_file == os.path.join(td, "vol0", "bar", "b", "a", "z")
            assert os.path.exists(gdf.data_file)
            assert not os.path.exists(tmppath)
        finally:
            shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:37,代码来源:test_diskfile.py

示例3: test_put

# 需要导入模块: from gluster.swift.common.DiskFile import Gluster_DiskFile [as 别名]
# 或者: from gluster.swift.common.DiskFile.Gluster_DiskFile import mkstemp [as 别名]
    def test_put(self):
        td = tempfile.mkdtemp()
        try:
            gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", "z", self.lg)
            assert gdf._obj == "z"
            assert gdf._obj_path == ""
            assert gdf.name == "bar"
            assert gdf.datadir == os.path.join(td, "vol0", "bar")
            assert gdf.data_file is None

            body = "1234\n"
            etag = md5()
            etag.update(body)
            etag = etag.hexdigest()
            metadata = {"X-Timestamp": "1234", "Content-Type": "file", "ETag": etag, "Content-Length": "5"}

            with gdf.mkstemp() as fd:
                assert gdf.tmppath is not None
                tmppath = gdf.tmppath
                os.write(fd, body)
                gdf.put(fd, metadata)

            assert gdf.data_file == os.path.join(td, "vol0", "bar", "z")
            assert os.path.exists(gdf.data_file)
            assert not os.path.exists(tmppath)
        finally:
            shutil.rmtree(td)
开发者ID:portante,项目名称:glusterfs,代码行数:29,代码来源:test_diskfile.py

示例4: test_mkstemp

# 需要导入模块: from gluster.swift.common.DiskFile import Gluster_DiskFile [as 别名]
# 或者: from gluster.swift.common.DiskFile.Gluster_DiskFile import mkstemp [as 别名]
 def test_mkstemp(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "dir")
     try:
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "dir/z", self.lg)
         saved_tmppath = ''
         with gdf.mkstemp() as fd:
             assert gdf.tmpdir == os.path.join(td, "vol0", "tmp")
             assert os.path.isdir(gdf.tmpdir)
             saved_tmppath = gdf.tmppath
             assert os.path.dirname(saved_tmppath) == gdf.tmpdir
             assert os.path.exists(saved_tmppath)
             os.write(fd, "123")
         assert not os.path.exists(saved_tmppath)
     finally:
         shutil.rmtree(td)
开发者ID:jayunit100,项目名称:glusterfs,代码行数:20,代码来源:test_diskfile.py

示例5: test_mkstemp_err_on_close

# 需要导入模块: from gluster.swift.common.DiskFile import Gluster_DiskFile [as 别名]
# 或者: from gluster.swift.common.DiskFile.Gluster_DiskFile import mkstemp [as 别名]
 def test_mkstemp_err_on_close(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "dir")
     try:
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "dir/z", self.lg)
         saved_tmppath = ''
         with gdf.mkstemp() as fd:
             assert gdf.datadir == os.path.join(td, "vol0", "bar", "dir")
             assert os.path.isdir(gdf.datadir)
             saved_tmppath = gdf.tmppath
             assert os.path.dirname(saved_tmppath) == gdf.datadir
             assert os.path.basename(saved_tmppath)[:3] == '.z.'
             assert os.path.exists(saved_tmppath)
             os.write(fd, "123")
             # Closing the fd prematurely should not raise any exceptions.
             os.close(fd)
         assert not os.path.exists(saved_tmppath)
     finally:
         shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:23,代码来源:test_diskfile.py


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