當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。