Python zlib 模块,Z_SYNC_FLUSH 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用zlib.Z_SYNC_FLUSH

项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
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
项目:download-manager    作者:thispc    | 项目源码 | 文件源码
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()
项目:kiwiclient    作者:dev-zzo    | 项目源码 | 文件源码
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
项目:EverMark    作者:liuwons    | 项目源码 | 文件源码
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()
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
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()
项目:AwesomenautsFileDumper    作者:Nodja    | 项目源码 | 文件源码
def deflate(data):
    c = zlib.compressobj()
    out = c.compress(data)
    out += c.flush(zlib.Z_SYNC_FLUSH)
    return out
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
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)

        self.sock.sendall(data)
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def send(self, data):
        """Send data to remote."""

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

        self.writefile.write(data)
        self.writefile.flush()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
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]
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
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]
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
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]
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def ssh_NEWKEYS(self, packet):
        if packet != '':
            self.sendDisconnect(DISCONNECT_PROTOCOL_ERROR, "NEWKEYS takes no data")
        self.currentEncryptions = self.nextEncryptions
        if self.outgoingCompressionType == 'zlib':
            self.outgoingCompression = zlib.compressobj(6)
            #self.outgoingCompression.compress = lambda x: self.outgoingCompression.compress(x) + self.outgoingCompression.flush(zlib.Z_SYNC_FLUSH)
        if self.incomingCompressionType == 'zlib':
            self.incomingCompression = zlib.decompressobj()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def ssh_NEWKEYS(self, packet):
        if packet != '':
            self.sendDisconnect(DISCONNECT_PROTOCOL_ERROR, "NEWKEYS takes no data")
        if not self.nextEncryptions.enc_block_size:
            self._gotNewKeys = 1
            return
        self.currentEncryptions = self.nextEncryptions
        if self.outgoingCompressionType == 'zlib':
            self.outgoingCompression = zlib.compressobj(6)
            #self.outgoingCompression.compress = lambda x: self.outgoingCompression.compress(x) + self.outgoingCompression.flush(zlib.Z_SYNC_FLUSH)
        if self.incomingCompressionType == 'zlib':
            self.incomingCompression = zlib.decompressobj()
        self.connectionSecure()
项目:wsproto    作者:python-hyper    | 项目源码 | 文件源码
def frame_outbound(self, proto, opcode, rsv, data, fin):
        if not self._compressible_opcode(opcode):
            return (rsv, data)

        if opcode is not Opcode.CONTINUATION:
            rsv = RsvBits(True, *rsv[1:])

        if self._compressor is None:
            assert opcode is not Opcode.CONTINUATION
            if proto.client:
                bits = self.client_max_window_bits
            else:
                bits = self.server_max_window_bits
            self._compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
                                                zlib.DEFLATED, -int(bits))

        data = self._compressor.compress(bytes(data))

        if fin:
            data += self._compressor.flush(zlib.Z_SYNC_FLUSH)
            data = data[:-4]

            if proto.client:
                no_context_takeover = self.client_no_context_takeover
            else:
                no_context_takeover = self.server_no_context_takeover

            if no_context_takeover:
                self._compressor = None

        return (rsv, data)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
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()
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
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()
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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()
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def flush(self, lib_mode=FLUSH):
        self._nltk_buffer.flush()
        GzipFile.flush(self, lib_mode)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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()
项目:simple_ws    作者:WSnettverksprog    | 项目源码 | 文件源码
def compress(self, message):
        self.compressor.compress(message)

        message = self.compressor.flush(zlib.Z_SYNC_FLUSH)
        assert message.endswith(b'\x00\x00\xff\xff')
        return message[:-4]
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def ssh_NEWKEYS(self, packet):
        if packet != '':
            self.sendDisconnect(DISCONNECT_PROTOCOL_ERROR, "NEWKEYS takes no data")
        self.currentEncryptions = self.nextEncryptions
        if self.outgoingCompressionType == 'zlib':
            self.outgoingCompression = zlib.compressobj(6)
            #self.outgoingCompression.compress = lambda x: self.outgoingCompression.compress(x) + self.outgoingCompression.flush(zlib.Z_SYNC_FLUSH)
        if self.incomingCompressionType == 'zlib':
            self.incomingCompression = zlib.decompressobj()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def ssh_NEWKEYS(self, packet):
        if packet != '':
            self.sendDisconnect(DISCONNECT_PROTOCOL_ERROR, "NEWKEYS takes no data")
        if not self.nextEncryptions.enc_block_size:
            self._gotNewKeys = 1
            return
        self.currentEncryptions = self.nextEncryptions
        if self.outgoingCompressionType == 'zlib':
            self.outgoingCompression = zlib.compressobj(6)
            #self.outgoingCompression.compress = lambda x: self.outgoingCompression.compress(x) + self.outgoingCompression.flush(zlib.Z_SYNC_FLUSH)
        if self.incomingCompressionType == 'zlib':
            self.incomingCompression = zlib.decompressobj()
        self.connectionSecure()
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
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]
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def flush(self, lib_mode=FLUSH):
        self._nltk_buffer.flush()
        GzipFile.flush(self, lib_mode)
项目:ServerToolkit    作者:ianjjohnson    | 项目源码 | 文件源码
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 bytes != str:
            self.sock.sendall(bytes(data, 'utf8'))
        else:
            self.sock.sendall(data)
项目:ServerToolkit    作者:ianjjohnson    | 项目源码 | 文件源码
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 bytes != str:
            if hasattr(self.sock, "sendall"):
                self.sock.sendall(bytes(data, 'utf8'))
            else:
                dlen = len(data)
                while dlen > 0:
                    sent = self.sock.write(bytes(data, 'utf8'))
                    if sent == dlen:
                        break    # avoid copy
                    data = data[sent:]
                    dlen = dlen - sent
        else:
            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
项目:ServerToolkit    作者:ianjjohnson    | 项目源码 | 文件源码
def send(self, 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 bytes != str:
            self.writefile.write(bytes(data, 'utf8'))
        else:
            self.writefile.write(data)
        self.writefile.flush()
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
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]
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
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]
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
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()
项目:kiwiclient    作者:dev-zzo    | 项目源码 | 文件源码
def compress_and_flush(self, bytes):
        compressed_bytes = self._compress.compress(bytes)
        compressed_bytes += self._compress.flush(zlib.Z_SYNC_FLUSH)
        self._logger.debug('Compress input %r', bytes)
        self._logger.debug('Compress result %r', compressed_bytes)
        return compressed_bytes
项目:kiwiclient    作者:dev-zzo    | 项目源码 | 文件源码
def filter(self, bytes):
        # Restore stripped LEN and NLEN field of a non-compressed block added
        # for Z_SYNC_FLUSH.
        self._inflater.append(bytes + '\x00\x00\xff\xff')
        return self._inflater.decompress(-1)
项目:neighborhood_mood_aws    作者:jarrellmark    | 项目源码 | 文件源码
def flush(self, lib_mode=FLUSH):
        self._buffer.flush()
        GzipFile.flush(self, lib_mode)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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()
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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()
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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()
项目:deb-python-autobahn    作者:openstack    | 项目源码 | 文件源码
def end_compress_message(self):
        data = self._compressor.flush(zlib.Z_SYNC_FLUSH)
        return data[:-4]
项目:deb-python-autobahn    作者:openstack    | 项目源码 | 文件源码
def end_decompress_message(self):
        # Eat stripped LEN and NLEN field of a non-compressed block added
        # for Z_SYNC_FLUSH.
        self._decompressor.decompress(b'\x00\x00\xff\xff')
项目:hate-to-hugs    作者:sdoran35    | 项目源码 | 文件源码
def flush(self, lib_mode=FLUSH):
        self._nltk_buffer.flush()
        GzipFile.flush(self, lib_mode)
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
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()
项目:teleport    作者:eomsoft    | 项目源码 | 文件源码
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]
项目:projects-2017-2    作者:ncss    | 项目源码 | 文件源码
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]
项目:aweasome_learning    作者:Knight-ZXW    | 项目源码 | 文件源码
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]
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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]
项目:pmatic    作者:LarsMichelsen    | 项目源码 | 文件源码
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()
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
def flush(self, lib_mode=FLUSH):
        self._buffer.flush()
        GzipFile.flush(self, lib_mode)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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()