• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python zlib.compressobj函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zlib.compressobj函数的典型用法代码示例。如果您正苦于以下问题:Python compressobj函数的具体用法?Python compressobj怎么用?Python compressobj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_send_message_permessage_compress_deflate_fragmented_bfinal

    def test_send_message_permessage_compress_deflate_fragmented_bfinal(self):
        extension = common.ExtensionParameter(
            common.PERMESSAGE_COMPRESSION_EXTENSION)
        extension.add_parameter('method', 'deflate')
        request = _create_request_from_rawdata(
                      '', permessage_compression_request=extension)
        self.assertEquals(1, len(request.ws_extension_processors))
        compression_processor = (
            request.ws_extension_processors[0].get_compression_processor())
        compression_processor.set_bfinal(True)
        msgutil.send_message(request, 'Hello', end=False)
        msgutil.send_message(request, 'World', end=True)

        expected = ''

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_FINISH)
        compressed_hello = compressed_hello + chr(0)
        expected += '\x41%c' % len(compressed_hello)
        expected += compressed_hello

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_FINISH)
        compressed_world = compressed_world + chr(0)
        expected += '\x80%c' % len(compressed_world)
        expected += compressed_world

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


示例2: test_receive_message_deflate_frame_comp_bit

    def test_receive_message_deflate_frame_comp_bit(self):
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = ''

        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)

        data += '\x81\x85' + _mask_hybi('Hello')

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

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

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(
            data, deflate_frame_request=extension)
        for i in xrange(3):
            self.assertEqual('Hello', msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:28,代码来源:test_msgutil.py


示例3: test_send_message_deflate_frame_bfinal

    def test_send_message_deflate_frame_bfinal(self):
        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(
            '', deflate_frame_request=extension)
        self.assertEquals(1, len(request.ws_extension_processors))
        deflate_frame_processor = request.ws_extension_processors[0]
        deflate_frame_processor.set_bfinal(True)
        msgutil.send_message(request, 'Hello')
        msgutil.send_message(request, 'World')

        expected = ''

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_FINISH)
        compressed_hello = compressed_hello + chr(0)
        expected += '\xc1%c' % len(compressed_hello)
        expected += compressed_hello

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_FINISH)
        compressed_world = compressed_world + chr(0)
        expected += '\xc1%c' % len(compressed_world)
        expected += compressed_world

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


示例4: test_receive_message_deflate_frame

    def test_receive_message_deflate_frame(self):
        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = ""

        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)

        compressed_websocket = compress.compress("WebSocket")
        compressed_websocket += compress.flush(zlib.Z_FINISH)
        compressed_websocket += "\x00"
        data += "\xc1%c" % (len(compressed_websocket) | 0x80)
        data += _mask_hybi(compressed_websocket)

        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

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

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

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(data, deflate_frame_request=extension)
        self.assertEqual("Hello", msgutil.receive_message(request))
        self.assertEqual("WebSocket", msgutil.receive_message(request))
        self.assertEqual("World", msgutil.receive_message(request))

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


示例5: setUp

    def setUp(self):
        super(ZlibTest, self).setUp()
        self.text = b"""
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.
Aenean nec lorem. In porttitor. Donec laoreet nonummy augue.
Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy.
Fusce aliquet pede non pede. Suspendisse dapibus lorem pellentesque magna. Integer nulla.
Donec blandit feugiat ligula. Donec hendrerit, felis et imperdiet euismod, purus ipsum pretium metus, in lacinia nulla nisl eget sapien. Donec ut est in lectus consequat consequat.
Etiam eget dui. Aliquam erat volutpat. Sed at lorem in nunc porta tristique.
Proin nec augue. Quisque aliquam tempor magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Nunc ac magna. Maecenas odio dolor, vulputate vel, auctor ac, accumsan id, felis. Pellentesque cursus sagittis felis.
Pellentesque porttitor, velit lacinia egestas auctor, diam eros tempus arcu, nec vulputate augue magna vel risus. Cras non magna vel ante adipiscing rhoncus. Vivamus a mi.
Morbi neque. Aliquam erat volutpat. Integer ultrices lobortis eros.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin semper, ante vitae sollicitudin posuere, metus quam iaculis nibh, vitae scelerisque nunc massa eget pede. Sed velit urna, interdum vel, ultricies vel, faucibus at, quam.
Donec elit est, consectetuer eget, consequat quis, tempus quis, wisi. In in nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos.
Donec ullamcorper fringilla eros. Fusce in sapien eu purus dapibus commodo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Cras faucibus condimentum odio. Sed ac ligula. Aliquam at eros.
Etiam at ligula et tellus ullamcorper ultrices. In fermentum, lorem non cursus porttitor, diam urna accumsan lacus, sed interdum wisi nibh nec nisl. Ut tincidunt volutpat urna.
Mauris eleifend nulla eget mauris. Sed cursus quam id felis. Curabitur posuere quam vel nibh.
Cras dapibus dapibus nisl. Vestibulum quis dolor a felis congue vehicula. Maecenas pede purus, tristique ac, tempus eget, egestas quis, mauris.
Curabitur non eros. Nullam hendrerit bibendum justo. Fusce iaculis, est quis lacinia pretium, pede metus molestie lacus, at gravida wisi ante at libero.
"""
        deflate_compress = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS)
        zlib_compress = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS)
        self.deflate_data = deflate_compress.compress(self.text) + deflate_compress.flush()
        self.zlib_data = zlib_compress.compress(self.text) + zlib_compress.flush()
        self.gzip_data = create_gzip(self.text)
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_zlib.py


示例6: _send_frame

    async def _send_frame(self, message: bytes, opcode: int,
                          compress: Optional[int]=None) -> None:
        """Send a frame over the websocket with message as its payload."""
        if self._closing:
            ws_logger.warning('websocket connection is closing.')

        rsv = 0

        # Only compress larger packets (disabled)
        # Does small packet needs to be compressed?
        # if self.compress and opcode < 8 and len(message) > 124:
        if (compress or self.compress) and opcode < 8:
            if compress:
                # Do not set self._compress if compressing is for this frame
                compressobj = zlib.compressobj(wbits=-compress)
            else:  # self.compress
                if not self._compressobj:
                    self._compressobj = zlib.compressobj(wbits=-self.compress)
                compressobj = self._compressobj

            message = compressobj.compress(message)
            message = message + compressobj.flush(
                zlib.Z_FULL_FLUSH if self.notakeover else zlib.Z_SYNC_FLUSH)
            if message.endswith(_WS_DEFLATE_TRAILING):
                message = message[:-4]
            rsv = rsv | 0x40

        msg_length = len(message)

        use_mask = self.use_mask
        if use_mask:
            mask_bit = 0x80
        else:
            mask_bit = 0

        if msg_length < 126:
            header = PACK_LEN1(0x80 | rsv | opcode, msg_length | mask_bit)
        elif msg_length < (1 << 16):
            header = PACK_LEN2(0x80 | rsv | opcode, 126 | mask_bit, msg_length)
        else:
            header = PACK_LEN3(0x80 | rsv | opcode, 127 | mask_bit, msg_length)
        if use_mask:
            mask = self.randrange(0, 0xffffffff)
            mask = mask.to_bytes(4, 'big')
            message = bytearray(message)
            _websocket_mask(mask, message)
            self.transport.write(header + mask + message)
            self._output_size += len(header) + len(mask) + len(message)
        else:
            if len(message) > MSG_SIZE:
                self.transport.write(header)
                self.transport.write(message)
            else:
                self.transport.write(header + message)

            self._output_size += len(header) + len(message)

        if self._output_size > self._limit:
            self._output_size = 0
            await self.protocol._drain_helper()
开发者ID:wwqgtxx,项目名称:wwqLyParse,代码行数:60,代码来源:http_websocket.py


示例7: __init__

    def __init__(self, level = 6):
        """
Constructor __init__(GzipCompressor)

:since: v1.0.0
        """

        self.compressor = None
        """
Deflate compressor instance
        """
        self.crc32 = None
        """
CRC32 from previous run
        """
        self.header = None
        """
Gzip header
        """
        self.size = None
        """
Total size of compressed data
        """

        # Use the zlib magic +16 to generate the GZip header and trailer on flush() if supported
        try: self.compressor = compressobj(level, wbits = 16 + MAX_WBITS)
        except TypeError:
            self.compressor = compressobj(level)

            if (level == 9): deflate_flag = 2
            elif (level == 1): deflate_flag = 4
            else: deflate_flag = 0

            self.header = pack("<8s2B", Binary.bytes("\x1f\x8b" + ("\x00" if (level == 0) else "\x08") + "\x00\x00\x00\x00\x00"), deflate_flag, 255)
            self.size = 0
开发者ID:dNG-git,项目名称:pas_streamer,代码行数:35,代码来源:gzip_compressor.py


示例8: test_receive_message_permessage_deflate_compression

    def test_receive_message_permessage_deflate_compression(self):
        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = ""

        compressed_hello = compress.compress("HelloWebSocket")
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        split_position = len(compressed_hello) / 2
        data += "\x41%c" % (split_position | 0x80)
        data += _mask_hybi(compressed_hello[:split_position])

        data += "\x80%c" % ((len(compressed_hello) - split_position) | 0x80)
        data += _mask_hybi(compressed_hello[split_position:])

        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

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

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

        extension = common.ExtensionParameter(common.PERMESSAGE_COMPRESSION_EXTENSION)
        extension.add_parameter("method", "deflate")
        request = _create_request_from_rawdata(data, permessage_compression_request=extension)
        self.assertEqual("HelloWebSocket", msgutil.receive_message(request))
        self.assertEqual("World", msgutil.receive_message(request))

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


示例9: test_receive_message_deflate_stream

    def test_receive_message_deflate_stream(self):
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = compress.compress('\x81\x85' + _mask_hybi('Hello'))
        data += compress.flush(zlib.Z_SYNC_FLUSH)
        data += compress.compress('\x81\x89' + _mask_hybi('WebSocket'))
        data += compress.flush(zlib.Z_FINISH)

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data += compress.compress('\x81\x85' + _mask_hybi('World'))
        data += compress.flush(zlib.Z_SYNC_FLUSH)
        # Close frame
        data += compress.compress(
            '\x88\x8a' + _mask_hybi(struct.pack('!H', 1000) + 'Good bye'))
        data += compress.flush(zlib.Z_SYNC_FLUSH)

        request = _create_request_from_rawdata(data, deflate_stream=True)
        self.assertEqual('Hello', msgutil.receive_message(request))
        self.assertEqual('WebSocket', msgutil.receive_message(request))
        self.assertEqual('World', msgutil.receive_message(request))

        self.assertFalse(request.drain_received_data_called)

        self.assertEqual(None, msgutil.receive_message(request))

        self.assertTrue(request.drain_received_data_called)
开发者ID:cscheid,项目名称:forte,代码行数:29,代码来源:test_msgutil.py


示例10: create_CompressedDataBody

def create_CompressedDataBody(alg, d):
    """Create a CompressedDataBody instance.

    :Parameters:
        - `alg`: integer compressed algorithm constant
        - `d`: string data to compress

    :Returns: `CompressedDataBody` instance
    """
    if COMP_ZIP == alg: # ..from zipfile.py source
        cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15)
        data = cmpr.compress(d)
        ex = cmpr.flush()
        if ex:
            data = data + ex
    elif COMP_ZLIB == alg:
        cmpr = zlib.compressobj()
        data = cmpr.compress(d)
        ex = cmpr.flush()
        if ex:
            data = data + ex
    elif COMP_UNCOMPRESSED == alg:
        data = d
    else:
        raise NotImplementedError("Unsupported compression algorithm->(%s)" % alg)
    return CompressedDataBody(''.join([chr(alg), data]))
开发者ID:Ando02,项目名称:wubiuefi,代码行数:26,代码来源:CompressedData.py


示例11: _initialize_compressor

 def _initialize_compressor(self):
   if self._compression_type == CompressionTypes.BZIP2:
     self._compressor = bz2.BZ2Compressor()
   elif self._compression_type == CompressionTypes.DEFLATE:
     self._compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
                                         zlib.DEFLATED)
   else:
     assert self._compression_type == CompressionTypes.GZIP
     self._compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
                                         zlib.DEFLATED, self._gzip_mask)
开发者ID:eralmas7,项目名称:beam,代码行数:10,代码来源:filesystem.py


示例12: start_compress_message

 def start_compress_message(self):
     # compressobj([level[, method[, wbits[, mem_level[, strategy]]]]])
     # http://bugs.python.org/issue19278
     # http://hg.python.org/cpython/rev/c54c8e71b79a
     if self._is_server:
         if self._compressor is None or self.server_no_context_takeover:
             self._compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -self.server_max_window_bits, self.mem_level)
     else:
         if self._compressor is None or self.client_no_context_takeover:
             self._compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -self.client_max_window_bits, self.mem_level)
开发者ID:crossbario,项目名称:autobahn-python,代码行数:10,代码来源:compress_deflate.py


示例13: startCompressMessage

 def startCompressMessage(self):
     if self._isServer:
         if self._compressor is None or self.s2c_no_context_takeover:
             self._compressor = zlib.compressobj(
                 zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -self.s2c_max_window_bits
             )
     else:
         if self._compressor is None or self.c2s_no_context_takeover:
             self._compressor = zlib.compressobj(
                 zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -self.c2s_max_window_bits
             )
开发者ID:rshravan,项目名称:AutobahnPython,代码行数:11,代码来源:compress_deflate.py


示例14: deflate_encoder

def deflate_encoder(level=None):
    if level is None:
        obj = zlib.compressobj()
    else:
        obj = zlib.compressobj(level)

    def enc(data, final):
        ret = obj.compress(data)
        if final:
            ret += obj.flush()
        return ret

    return enc
开发者ID:hubo1016,项目名称:vlcp,代码行数:13,代码来源:encoders.py


示例15: test_multi_decoding_gzip_gzip

    def test_multi_decoding_gzip_gzip(self):
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b'foo')
        data += compress.flush()

        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(data)
        data += compress.flush()

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={'content-encoding': 'gzip, gzip'})

        assert r.data == b'foo'
开发者ID:jonparrott,项目名称:urllib3,代码行数:13,代码来源:test_response.py


示例16: writeblock

def writeblock(mapdir, px,py,pz, block):

	sectordir = mapdir + get_sector_dir(px, pz);
	
	try:
		os.makedirs(sectordir)
	except OSError:
		pass
	
	path = sectordir+"/"+to4h(py)

	print("writing block file "+path)

	f = open(sectordir+"/"+to4h(py), "wb")

	if f == None:
		return

	# version
	version = 17
	f.write(struct.pack('B', version))

	# flags
	# 0x01=is_undg, 0x02=dn_diff, 0x04=lighting_expired
	flags = 0 + 0x02 + 0x04
	f.write(struct.pack('B', flags))
	
	# data
	c_obj = zlib.compressobj()
	c_obj.compress(block.serialize_data())
	f.write(struct.pack('BB', 0x78, 0x9c)) # zlib magic number
	f.write(c_obj.flush())

	# node metadata
	c_obj = zlib.compressobj()
	c_obj.compress(block.serialize_nodemeta())
	f.write(struct.pack('BB', 0x78, 0x9c)) # zlib magic number
	f.write(c_obj.flush())

	# mapblockobject count
	f.write(ser_u16(0))

	# static objects
	f.write(block.serialize_staticobj())

	# timestamp
	f.write(ser_u32(0xffffffff))

	f.close()
开发者ID:11ph22il,项目名称:minetest,代码行数:49,代码来源:genmap.py


示例17: _add_packet_to_queue

 def _add_packet_to_queue(self, packet, start_send_cb=None, end_send_cb=None):
     packets = self.encode(packet)
     if not self.raw_packets:
         assert len(packets)==1
     try:
         self._write_lock.acquire()
         counter = 0
         for index,compress,data in packets:
             if self.raw_packets:
                 if compress and self._compression_level>0:
                     level = self._compression_level
                     if self._compressor is None:
                         self._compressor = zlib.compressobj(level)
                     data = self._compressor.compress(data)+self._compressor.flush(zlib.Z_SYNC_FLUSH)
                 else:
                     level = 0
                 l = len(data)
                 #'p' + protocol-version + compression_level + packet_index + packet_size
                 header = struct.pack('!cBBBL', "P", 0, level, index, l)
             else:
                 assert index==0
                 l = len(data)
                 header = ("PS%014d" % l).encode('latin1')
             scb, ecb = None, None
             #fire the start_send_callback just before the first packet is processed:
             if counter==0:
                 scb = start_send_cb
             #fire the end_send callback when the last packet (index==0) makes it out:
             if index==0:
                 ecb = end_send_cb
             if l<4096 and sys.version<'3':
                 #send size and data together (low copy overhead):
                 self._queue_write(header+data, scb, ecb, True)
             else:
                 self._queue_write(header)
                 self._queue_write(data, scb, ecb, True)
             counter += 1
     finally:
         if packet[0]=="set_deflate":
             level = packet[1]
             log("set_deflate packet, changing compressor from %s to level=%s", self._compression_level, level)
             if self._compression_level!=level or self._compressor is None:
                 if level>0:
                     self._compressor = zlib.compressobj(level)
                 else:
                     self._compressor = None
         self.output_packetcount += 1
         self._write_lock.release()
开发者ID:svn2github,项目名称:Xpra,代码行数:48,代码来源:protocol.py


示例18: testZLibFlushRecord

  def testZLibFlushRecord(self):
    fn = self._WriteRecordsToFile([b"small record"], "small_record")
    with open(fn, "rb") as h:
      buff = h.read()

    # creating more blocks and trailing blocks shouldn't break reads
    compressor = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS)

    output = b""
    for c in buff:
      if isinstance(c, int):
        c = six.int2byte(c)
      output += compressor.compress(c)
      output += compressor.flush(zlib.Z_FULL_FLUSH)

    output += compressor.flush(zlib.Z_FULL_FLUSH)
    output += compressor.flush(zlib.Z_FULL_FLUSH)
    output += compressor.flush(zlib.Z_FINISH)

    # overwrite the original file with the compressed data
    with open(fn, "wb") as h:
      h.write(output)

    with self.test_session() as sess:
      options = tf_record.TFRecordOptions(
          compression_type=TFRecordCompressionType.ZLIB)
      reader = io_ops.TFRecordReader(name="test_reader", options=options)
      queue = data_flow_ops.FIFOQueue(1, [dtypes.string], shapes=())
      key, value = reader.read(queue)
      queue.enqueue(fn).run()
      queue.close().run()
      k, v = sess.run([key, value])
      self.assertTrue(compat.as_text(k).startswith("%s:" % fn))
      self.assertAllEqual(b"small record", v)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:34,代码来源:reader_ops_test.py


示例19: __init__

    def __init__(self, conn):
        asyncore.dispatcher_with_send.__init__(self, conn)
        
        self.ssled = False
        self.secure_connection(certfile="server.passless.crt", keyfile="server.passless.key", server_side=True)               

        self.consumed_ace = False
        self.data = ""
        self.binary_mode = False
        self.decompressor = zlib.decompressobj()
        self.compressor = zlib.compressobj()
        self.unzipped_input = ""
        self.unzipped_output_buffer = ""
        self.output_buffer = ""
        self.speech = dict()
        self.pong = 1
        self.ping = 0
        self.httpClient = AsyncOpenHttp(self.handle_google_data, self.handle_google_failure)
        self.gotGoogleAnswer = False
        self.googleData = None
        self.lastRequestId = None
        self.dictation = None
        self.dbConnection = db.getConnection()
        self.assistant = None
        self.sendLock = threading.Lock()
        self.current_running_plugin = None
        self.current_location = None
        self.plugin_lastAceId = None
        self.logger = logging.getLogger("logger")
开发者ID:alexandred,项目名称:SiriServer,代码行数:29,代码来源:siriServer.py


示例20: png_write

def png_write(width, height, image):
    def _chunk(name, data=""):
        length = struct.pack(">I", len(data))
        crc = struct.pack(">i", crc32(name + data))
        return length + name + data + crc
    
    _data = ""
    _data = struct.pack(">8B", 137, 80, 78, 71, 13, 10, 26, 10)
    _data += _chunk("IHDR", struct.pack(">2I5B", width, height, 8, 2, 0, 0, 0))
    
    image_data = ""
    compressor = zlib.compressobj()
    for y in xrange(1, height+1):
        row = ""
        for x in xrange(1, width+1):
            p = x11.XGetPixel(image, x, y)
            p = struct.pack(">I", p)[1:]
            row += p
        image_data += compressor.compress(row)
    image_data += compressor.flush()
    
    _data += _chunk("IDAT", image_data)
    
    _data += _chunk("IEND")
    return _data
开发者ID:approximatelylinear,项目名称:pyscreenshot,代码行数:25,代码来源:pyimg.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python zlib.crc32函数代码示例发布时间:2022-05-26
下一篇:
Python zlib.compress函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap