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


Python zlib.decompressobj方法代码示例

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


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

示例1: content

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def content(self):
        """Raw content of response (i.e. bytes).

        :returns: Body of HTTP response
        :rtype: str

        """
        if not self._content:

            # Decompress gzipped content
            if self._gzipped:
                decoder = zlib.decompressobj(16 + zlib.MAX_WBITS)
                self._content = decoder.decompress(self.raw.read())

            else:
                self._content = self.raw.read()

            self._content_loaded = True

        return self._content 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:22,代码来源:web.py

示例2: _read_first_gzip_block_into_buffer

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def _read_first_gzip_block_into_buffer(self):
    buf = self._read_data_from_source()
    decompressed = self._decompressor.decompress(buf)
    del buf
    # Discards all data before first `\n`.
    while '\n' not in decompressed:
      if self._decompressor.unused_data != b'':
        buf = self._decompressor.unused_data
        self._decompressor = zlib.decompressobj(self._gzip_mask)
        decompressed = self._decompressor.decompress(buf)
        del buf
      else:
        raise ValueError('Read failed. The block {} does not contain any '
                         'valid record.'.format(self._block))

    lines = decompressed.split('\n')
    self._read_buffer.write('\n'.join(lines[1:])) 
开发者ID:googlegenomics,项目名称:gcp-variant-transforms,代码行数:19,代码来源:bgzf.py

示例3: _complete_last_line

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def _complete_last_line(self):
    # Fetches the first line in the next `self._read_size` bytes.
    buf = self._file.raw._downloader.get_range(
        self._block.end, self._block.end + self._read_size)
    self._decompressor = zlib.decompressobj(self._gzip_mask)
    decompressed = self._decompressor.decompress(buf)
    del buf
    if not decompressed:
      return
    # Writes all data to the buffer until the first `\n` is reached.
    while '\n' not in decompressed:
      if self._decompressor.unused_data != b'':
        self._read_buffer.write(decompressed)
        buf = self._decompressor.unused_data
        self._decompressor = zlib.decompressobj(self._gzip_mask)
        decompressed = self._decompressor.decompress(buf)
        del buf
      else:
        raise ValueError('Read failed. The record is longer than {} '
                         'bytes.'.format(self._read_size))
    self._read_buffer.write(decompressed.split('\n')[0] + '\n') 
开发者ID:googlegenomics,项目名称:gcp-variant-transforms,代码行数:23,代码来源:bgzf.py

示例4: decompress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def decompress(self, data):
        if not data:
            return data

        if not self._first_try:
            return self._obj.decompress(data)

        self._data += data
        try:
            return self._obj.decompress(data)
        except zlib.error:
            self._first_try = False
            self._obj = zlib.decompressobj(-zlib.MAX_WBITS)
            try:
                return self.decompress(self._data)
            finally:
                self._data = None 
开发者ID:war-and-code,项目名称:jawfish,代码行数:19,代码来源:response.py

示例5: decompress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def decompress(self, data):
        if not data:
            return data

        if not self._first_try:
            return self._obj.decompress(data)

        self._data += data
        try:
            decompressed = self._obj.decompress(data)
            if decompressed:
                self._first_try = False
                self._data = None
            return decompressed
        except zlib.error:
            self._first_try = False
            self._obj = zlib.decompressobj(-zlib.MAX_WBITS)
            try:
                return self.decompress(self._data)
            finally:
                self._data = None 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:23,代码来源:response.py

示例6: decompress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def decompress(self, data):
        ret = bytearray()
        if self._state == GzipDecoderState.SWALLOW_DATA or not data:
            return bytes(ret)
        while True:
            try:
                ret += self._obj.decompress(data)
            except zlib.error:
                previous_state = self._state
                # Ignore data after the first error
                self._state = GzipDecoderState.SWALLOW_DATA
                if previous_state == GzipDecoderState.OTHER_MEMBERS:
                    # Allow trailing garbage acceptable in other gzip clients
                    return bytes(ret)
                raise
            data = self._obj.unused_data
            if not data:
                return bytes(ret)
            self._state = GzipDecoderState.OTHER_MEMBERS
            self._obj = zlib.decompressobj(16 + zlib.MAX_WBITS) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:response.py

示例7: decompress_raw_data_to_unicode_stream

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def decompress_raw_data_to_unicode_stream(raw_data_fd: IO):
    """Decompresses a raw data in file like object and yields a Unicode string.

    Args:
        raw_data_fd: File descriptor object.

    Yields:
        A string of the decompressed file in chunks.
    """
    obj = zlib.decompressobj(MAGIC_NUMBER + zlib.MAX_WBITS)
    yield '['
    d = raw_data_fd.read(CHUNK_SIZE)
    while d:
        yield obj.decompress(d).decode('utf-8')
        while obj.unused_data != b'':
            unused_data = obj.unused_data
            obj = zlib.decompressobj(MAGIC_NUMBER + zlib.MAX_WBITS)
            yield obj.decompress(unused_data).decode('utf-8')
        d = raw_data_fd.read(CHUNK_SIZE)
    yield obj.flush().decode('utf-8') + ']' 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:22,代码来源:gzip_decoder.py

示例8: content

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def content(self):
        """Raw content of response (i.e. bytes).

        :returns: Body of HTTP response
        :rtype: :class:`str`

        """
        if not self._content:

            # Decompress gzipped content
            if self._gzipped:
                decoder = zlib.decompressobj(16 + zlib.MAX_WBITS)
                self._content = decoder.decompress(self.raw.read())

            else:
                self._content = self.raw.read()

            self._content_loaded = True

        return self._content 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:22,代码来源:web.py

示例9: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.max_size = None
        # an empty dispatcher to prevent crashes
        self._dispatch = lambda *args: None
        # generic event listeners
        self._dispatch_listeners = []
        # the keep alive
        self._keep_alive = None
        self.thread_id = threading.get_ident()

        # ws related stuff
        self.session_id = None
        self.sequence = None
        self._zlib = zlib.decompressobj()
        self._buffer = bytearray() 
开发者ID:Rapptz,项目名称:discord.py,代码行数:18,代码来源:gateway.py

示例10: _decompress_unused_data

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def _decompress_unused_data(self, num_bytes):
    while (self._decompressor.unused_data != b'' and
           not self._enough_data_in_buffer(num_bytes)):
      buf = self._decompressor.unused_data
      self._decompressor = zlib.decompressobj(self._gzip_mask)
      decompressed = self._decompressor.decompress(buf)
      del buf
      self._read_buffer.write(decompressed) 
开发者ID:googlegenomics,项目名称:gcp-variant-transforms,代码行数:10,代码来源:bgzf.py

示例11: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def __init__(self):
        self._first_try = True
        self._data = binary_type()
        self._obj = zlib.decompressobj() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:response.py

示例12: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def __init__(self):
        self._first_try = True
        self._data = b''
        self._obj = zlib.decompressobj() 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:6,代码来源:response.py

示例13: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import decompressobj [as 别名]
def __init__(self):
        self._first_try = True
        self._data = b""
        self._obj = zlib.decompressobj() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:response.py


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