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


Python BytesIO.write方法代码示例

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


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

示例1: read

# 需要导入模块: from redis._compat import BytesIO [as 别名]
# 或者: from redis._compat.BytesIO import write [as 别名]
    def read(self, length=None):
        """
        Read a line from the socket is no length is specified,
        otherwise read ``length`` bytes. Always strip away the newlines.
        """
        try:
            if length is not None:
                bytes_left = length + 2  # read the line ending
                if length > self.MAX_READ_LENGTH:
                    # apparently reading more than 1MB or so from a windows
                    # socket can cause MemoryErrors. See:
                    # https://github.com/andymccurdy/redis-py/issues/205
                    # read smaller chunks at a time to work around this
                    try:
                        buf = BytesIO()
                        while bytes_left > 0:
                            read_len = min(bytes_left, self.MAX_READ_LENGTH)
                            buf.write(self._fp.read(read_len))
                            bytes_left -= read_len
                        buf.seek(0)
                        return buf.read(length)
                    finally:
                        buf.close()
                return self._fp.read(bytes_left)[:-2]

            # no length, read a full line
            return self._fp.readline()[:-2]
        except (socket.error, socket.timeout):
            e = sys.exc_info()[1]
            raise ConnectionError("Error while reading from socket: %s" %
                                  (e.args,))
开发者ID:CNCBASHER,项目名称:linuxcnc-1,代码行数:33,代码来源:connection.py

示例2: pack_command

# 需要导入模块: from redis._compat import BytesIO [as 别名]
# 或者: from redis._compat.BytesIO import write [as 别名]
 def pack_command(self, *args):
     "Pack a series of arguments into a value Redis command"
     output = BytesIO()
     output.write(SYM_STAR)
     output.write(b(str(len(args))))
     output.write(SYM_CRLF)
     for enc_value in imap(self.encode, args):
         output.write(SYM_DOLLAR)
         output.write(b(str(len(enc_value))))
         output.write(SYM_CRLF)
         output.write(enc_value)
         output.write(SYM_CRLF)
     return output.getvalue()
开发者ID:DHLabs,项目名称:keep_isn,代码行数:15,代码来源:connection.py


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