本文整理汇总了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()
示例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
示例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
示例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()
示例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())
示例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())
示例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())
示例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())
示例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))
示例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
示例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
示例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)
示例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]
示例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()
示例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)