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


Python zlib.Z_SYNC_FLUSH属性代码示例

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


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

示例1: flush

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def flush(self):
    """Flush any queued up data in the write buffer and ensure the
    compression buffer is flushed out to the underlying transport
    """
    wout = self.__wbuf.getvalue()
    if len(wout) > 0:
      zbuf = self._zcomp_write.compress(wout)
      self.bytes_out += len(wout)
      self.bytes_out_comp += len(zbuf)
    else:
      zbuf = ''
    ztail = self._zcomp_write.flush(zlib.Z_SYNC_FLUSH)
    self.bytes_out_comp += len(ztail)
    if (len(zbuf) + len(ztail)) > 0:
      self.__wbuf = StringIO()
      self.__trans.write(zbuf + ztail)
    self.__trans.flush() 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:19,代码来源:TZlibTransport.py

示例2: send

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def send(self, data):
        """send(data)
        Send 'data' to remote."""

        if self.compressor is not None:
            data = self.compressor.compress(data)
            data += self.compressor.flush(zlib.Z_SYNC_FLUSH)

        if hasattr(self.sock, "sendall"):
            self.sock.sendall(data)
        else:
            bytes = len(data)
            while bytes > 0:
                sent = self.sock.write(data)
                if sent == bytes:
                    break    # avoid copy
                data = data[sent:]
                bytes = bytes - sent 
开发者ID:Schibum,项目名称:sndlatr,代码行数:20,代码来源:imaplib2.py

示例3: send

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def send(self, data):
        """send(data)
        Send 'data' to remote."""

        if self.compressor is not None:
            data = self.compressor.compress(data)
            data += self.compressor.flush(zlib.Z_SYNC_FLUSH)

        if hasattr(self.sock, "sendall"):
            self.sock.sendall(data)
        else:
            dlen = len(data)
            while dlen > 0:
                sent = self.sock.write(data)
                if sent == dlen:
                    break    # avoid copy
                data = data[sent:]
                dlen = dlen - sent 
开发者ID:OfflineIMAP,项目名称:imapfw,代码行数:20,代码来源:imaplib2.py

示例4: flush

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def flush(self):
        """Flush any queued up data in the write buffer and ensure the
        compression buffer is flushed out to the underlying transport
        """
        wout = self.__wbuf.getvalue()
        if len(wout) > 0:
            zbuf = self._zcomp_write.compress(wout)
            self.bytes_out += len(wout)
            self.bytes_out_comp += len(zbuf)
        else:
            zbuf = ''
        ztail = self._zcomp_write.flush(zlib.Z_SYNC_FLUSH)
        self.bytes_out_comp += len(ztail)
        if (len(zbuf) + len(ztail)) > 0:
            self.__wbuf = BufferIO()
            self.__trans.write(zbuf + ztail)
        self.__trans.flush() 
开发者ID:Aditmadzs,项目名称:Protect4,代码行数:19,代码来源:TZlibTransport.py

示例5: test_send_message

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def test_send_message(self):
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(
            '', deflate_frame_request=extension)
        msgutil.send_message(request, 'Hello')
        msgutil.send_message(request, 'World')

        expected = ''

        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        expected += '\xc1%c' % len(compressed_hello)
        expected += compressed_hello

        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_world = compressed_world[:-4]
        expected += '\xc1%c' % len(compressed_world)
        expected += compressed_world

        self.assertEqual(expected, request.connection.written_data()) 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:27,代码来源:test_msgutil.py

示例6: test_send_message_no_context_takeover_parameter

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def test_send_message_no_context_takeover_parameter(self):
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        extension.add_parameter('no_context_takeover', None)
        request = _create_request_from_rawdata(
            '', deflate_frame_request=extension)
        for i in xrange(3):
            msgutil.send_message(request, 'Hello')

        compressed_message = compress.compress('Hello')
        compressed_message += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_message = compressed_message[:-4]
        expected = '\xc1%c' % len(compressed_message)
        expected += compressed_message

        self.assertEqual(
            expected + expected + expected, request.connection.written_data()) 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:21,代码来源:test_msgutil.py

示例7: test_send_message_fragmented

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def test_send_message_fragmented(self):
        extension = common.ExtensionParameter(
                common.PERMESSAGE_DEFLATE_EXTENSION)
        request = _create_request_from_rawdata(
                '', permessage_deflate_request=extension)
        msgutil.send_message(request, 'Hello', end=False)
        msgutil.send_message(request, 'Goodbye', end=False)
        msgutil.send_message(request, 'World')

        compress = zlib.compressobj(
                zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        expected = '\x41%c' % len(compressed_hello)
        expected += compressed_hello
        compressed_goodbye = compress.compress('Goodbye')
        compressed_goodbye += compress.flush(zlib.Z_SYNC_FLUSH)
        expected += '\x00%c' % len(compressed_goodbye)
        expected += compressed_goodbye
        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_world = compressed_world[:-4]
        expected += '\x80%c' % len(compressed_world)
        expected += compressed_world
        self.assertEqual(expected, request.connection.written_data()) 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:27,代码来源:test_msgutil.py

示例8: test_send_message_fragmented_empty_first_frame

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def test_send_message_fragmented_empty_first_frame(self):
        extension = common.ExtensionParameter(
                common.PERMESSAGE_DEFLATE_EXTENSION)
        request = _create_request_from_rawdata(
                '', permessage_deflate_request=extension)
        msgutil.send_message(request, '', end=False)
        msgutil.send_message(request, 'Hello')

        compress = zlib.compressobj(
                zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_hello = compress.compress('')
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        expected = '\x41%c' % len(compressed_hello)
        expected += compressed_hello
        compressed_empty = compress.compress('Hello')
        compressed_empty += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_empty = compressed_empty[:-4]
        expected += '\x80%c' % len(compressed_empty)
        expected += compressed_empty
        print '%r' % expected
        self.assertEqual(expected, request.connection.written_data()) 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:23,代码来源:test_msgutil.py

示例9: test_receive_message_deflate

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def test_receive_message_deflate(self):
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        data = '\xc1%c' % (len(compressed_hello) | 0x80)
        data += _mask_hybi(compressed_hello)

        # Close frame
        data += '\x88\x8a' + _mask_hybi(struct.pack('!H', 1000) + 'Good bye')

        extension = common.ExtensionParameter(
                common.PERMESSAGE_DEFLATE_EXTENSION)
        request = _create_request_from_rawdata(
                data, permessage_deflate_request=extension)
        self.assertEqual('Hello', msgutil.receive_message(request))

        self.assertEqual(None, msgutil.receive_message(request)) 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:22,代码来源:test_msgutil.py

示例10: filter

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def filter(self, bytes, end=True, bfinal=False):
        if self._deflater is None:
            self._deflater = _Deflater(self._window_bits)

        if bfinal:
            result = self._deflater.compress_and_finish(bytes)
            # Add a padding block with BFINAL = 0 and BTYPE = 0.
            result = result + chr(0)
            self._deflater = None
            return result

        result = self._deflater.compress_and_flush(bytes)
        if end:
            # Strip last 4 octets which is LEN and NLEN field of a
            # non-compressed block added for Z_SYNC_FLUSH.
            result = result[:-4]

        if self._no_context_takeover and end:
            self._deflater = None

        return result 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:23,代码来源:util.py

示例11: test_flushes

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def test_flushes(self):
        # Test flush() with the various options, using all the
        # different levels in order to provide more variations.
        sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH']
        sync_opt = [getattr(zlib, opt) for opt in sync_opt
                    if hasattr(zlib, opt)]
        data = HAMLET_SCENE * 8

        for sync in sync_opt:
            for level in range(10):
                obj = zlib.compressobj( level )
                a = obj.compress( data[:3000] )
                b = obj.flush( sync )
                c = obj.compress( data[3000:] )
                d = obj.flush()
                self.assertEqual(zlib.decompress(''.join([a,b,c,d])),
                                 data, ("Decompress failed: flush "
                                        "mode=%i, level=%i") % (sync, level))
                del obj 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:21,代码来源:test_zlib.py

示例12: flush

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def flush(self, lib_mode=FLUSH):
        self._buffer.flush()
        GzipFile.flush(self, lib_mode) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:5,代码来源:data.py

示例13: compress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def compress(self, data):
        compressor = self._compressor or self._create_compressor()
        data = (compressor.compress(data) +
                compressor.flush(zlib.Z_SYNC_FLUSH))
        assert data.endswith(b'\x00\x00\xff\xff')
        return data[:-4] 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:websocket.py

示例14: flush

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH):
        self._check_closed()
        if self.mode == WRITE:
            # Ensure the compressor's buffer is flushed
            self.fileobj.write(self.compress.flush(zlib_mode))
            self.fileobj.flush() 
开发者ID:glmcdona,项目名称:meddle,代码行数:8,代码来源:gzip.py

示例15: compress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import Z_SYNC_FLUSH [as 别名]
def compress(self, data):
        data = self._compressor.compress(data)
        return data + self._compressor.flush(zlib.Z_SYNC_FLUSH) 
开发者ID:wtolson,项目名称:gnsq,代码行数:5,代码来源:defalte.py


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