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


Python StringIO.flush方法代码示例

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


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

示例1: open

# 需要导入模块: from fs.filelike import StringIO [as 别名]
# 或者: from fs.filelike.StringIO import flush [as 别名]
    def open(self, path, mode='r', buffering=-1, encoding=None, errors=None, newline=None, line_buffering=False, **kwargs):
        # TODO: chunked transport of large files
        epath = self.encode_path(path)
        if "w" in mode:
            self.proxy.set_contents(epath, xmlrpclib.Binary(b("")))
        if "r" in mode or "a" in mode or "+" in mode:
            try:
                data = self.proxy.get_contents(epath, "rb").data
            except IOError:
                if "w" not in mode and "a" not in mode:
                    raise ResourceNotFoundError(path)
                if not self.isdir(dirname(path)):
                    raise ParentDirectoryMissingError(path)
                self.proxy.set_contents(path, xmlrpclib.Binary(b("")))
        else:
            data = b("")
        f = StringIO(data)
        if "a" not in mode:
            f.seek(0, 0)
        else:
            f.seek(0, 2)
        oldflush = f.flush
        oldclose = f.close
        oldtruncate = f.truncate

        def newflush():
            self._lock.acquire()
            try:
                oldflush()
                self.proxy.set_contents(epath, xmlrpclib.Binary(f.getvalue()))
            finally:
                self._lock.release()

        def newclose():
            self._lock.acquire()
            try:
                f.flush()
                oldclose()
            finally:
                self._lock.release()

        def newtruncate(size=None):
            self._lock.acquire()
            try:
                oldtruncate(size)
                f.flush()
            finally:
                self._lock.release()

        f.flush = newflush
        f.close = newclose
        f.truncate = newtruncate
        return f
开发者ID:Liryna,项目名称:pyfilesystem,代码行数:55,代码来源:rpcfs.py

示例2: open

# 需要导入模块: from fs.filelike import StringIO [as 别名]
# 或者: from fs.filelike.StringIO import flush [as 别名]
 def open(self, path, mode="r"):
     # TODO: chunked transport of large files
     path = self.encode_path(path)
     if "w" in mode:
         self.proxy.set_contents(path,xmlrpclib.Binary(""))
     if "r" in mode or "a" in mode or "+" in mode:
         try:
             data = self.proxy.get_contents(path).data
         except IOError:
             if "w" not in mode and "a" not in mode:
                 raise ResourceNotFoundError(path)
             if not self.isdir(dirname(path)):
                 raise ParentDirectoryMissingError(path)
             self.proxy.set_contents(path,xmlrpclib.Binary(""))
     else:
         data = ""
     f = StringIO(data)
     if "a" not in mode:
         f.seek(0,0)
     else:
         f.seek(0,2)
     oldflush = f.flush
     oldclose = f.close
     oldtruncate = f.truncate
     def newflush():
         oldflush()
         self.proxy.set_contents(path,xmlrpclib.Binary(f.getvalue()))
     def newclose():
         f.flush()
         oldclose()
     def newtruncate(size=None):
         oldtruncate(size)
         f.flush()
     f.flush = newflush
     f.close = newclose
     f.truncate = newtruncate
     return f
开发者ID:atty303,项目名称:pyfilesystem,代码行数:39,代码来源:rpcfs.py


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