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


Python zlib.MAX_WBITS属性代码示例

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


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

示例1: content

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [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: decompress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [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

示例3: decompress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [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

示例4: _decompressContent

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def _decompressContent(response, new_content):
    content = new_content
    try:
        encoding = response.get("content-encoding", None)
        if encoding in ["gzip", "deflate"]:
            if encoding == "gzip":
                content = gzip.GzipFile(fileobj=io.BytesIO(new_content)).read()
            if encoding == "deflate":
                content = zlib.decompress(content, -zlib.MAX_WBITS)
            response["content-length"] = str(len(content))
            # Record the historical presence of the encoding in a way the won't interfere.
            response["-content-encoding"] = response["content-encoding"]
            del response["content-encoding"]
    except (IOError, zlib.error):
        content = ""
        raise FailedToDecompressContent(
            _("Content purported to be compressed with %s but failed to decompress.")
            % response.get("content-encoding"),
            response,
            content,
        )
    return content 
开发者ID:remg427,项目名称:misp42splunk,代码行数:24,代码来源:__init__.py

示例5: _decompressContent

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def _decompressContent(response, new_content):
    content = new_content
    try:
        encoding = response.get("content-encoding", None)
        if encoding in ["gzip", "deflate"]:
            if encoding == "gzip":
                content = gzip.GzipFile(fileobj=StringIO.StringIO(new_content)).read()
            if encoding == "deflate":
                content = zlib.decompress(content, -zlib.MAX_WBITS)
            response["content-length"] = str(len(content))
            # Record the historical presence of the encoding in a way the won't interfere.
            response["-content-encoding"] = response["content-encoding"]
            del response["content-encoding"]
    except (IOError, zlib.error):
        content = ""
        raise FailedToDecompressContent(
            _("Content purported to be compressed with %s but failed to decompress.")
            % response.get("content-encoding"),
            response,
            content,
        )
    return content 
开发者ID:remg427,项目名称:misp42splunk,代码行数:24,代码来源:__init__.py

示例6: decompress_raw_data_to_unicode_stream

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [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

示例7: content

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [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

示例8: reference_path

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def reference_path():
    # download chr4 from ucsc if needed
    reference_path = "data/chr4.fa"

    if not os.path.exists(reference_path):
        import urllib.request
        import zlib
        url = "http://hgdownload.cse.ucsc.edu/goldenPath/hg19/chromosomes/chr4.fa.gz"

        resource = urllib.request.urlopen(url)

        with open(reference_path, "w") as outf:
            data = zlib.decompress(resource.read(), 16+zlib.MAX_WBITS).decode("utf-8")
            outf.write(data)

    return reference_path 
开发者ID:nspies,项目名称:genomeview,代码行数:18,代码来源:conftest.py

示例9: gzip_app_iter

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def gzip_app_iter(app_iter):
    size = 0
    crc = zlib.crc32(b"") & 0xffffffff
    compress = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS,
                                zlib.DEF_MEM_LEVEL, 0)

    yield _gzip_header
    for item in app_iter:
        size += len(item)
        crc = zlib.crc32(item, crc) & 0xffffffff

        # The compress function may return zero length bytes if the input is
        # small enough; it buffers the input for the next iteration or for a
        # flush.
        result = compress.compress(item)
        if result:
            yield result

    # Similarly, flush may also not yield a value.
    result = compress.flush()
    if result:
        yield result
    yield struct.pack("<2L", crc, size & 0xffffffff) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:25,代码来源:response.py

示例10: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def __init__(
        self,
        persistent: bool,
        max_wbits: Optional[int],
        max_message_size: int,
        compression_options: Dict[str, Any] = None,
    ) -> None:
        self._max_message_size = max_message_size
        if max_wbits is None:
            max_wbits = zlib.MAX_WBITS
        if not (8 <= max_wbits <= zlib.MAX_WBITS):
            raise ValueError(
                "Invalid max_wbits value %r; allowed range 8-%d",
                max_wbits,
                zlib.MAX_WBITS,
            )
        self._max_wbits = max_wbits
        if persistent:
            self._decompressor = (
                self._create_decompressor()
            )  # type: Optional[_Decompressor]
        else:
            self._decompressor = None 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:websocket.py

示例11: _get_compressor_options

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def _get_compressor_options(
        self,
        side: str,
        agreed_parameters: Dict[str, Any],
        compression_options: Dict[str, Any] = None,
    ) -> Dict[str, Any]:
        """Converts a websocket agreed_parameters set to keyword arguments
        for our compressor objects.
        """
        options = dict(
            persistent=(side + "_no_context_takeover") not in agreed_parameters
        )  # type: Dict[str, Any]
        wbits_header = agreed_parameters.get(side + "_max_window_bits", None)
        if wbits_header is None:
            options["max_wbits"] = zlib.MAX_WBITS
        else:
            options["max_wbits"] = int(wbits_header)
        options["compression_options"] = compression_options
        return options 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:21,代码来源:websocket.py

示例12: compress

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def compress(body, compress_level):
    """Compress 'body' at the given compress_level."""
    import zlib

    # See http://www.gzip.org/zlib/rfc-gzip.html
    yield b'\x1f\x8b'       # ID1 and ID2: gzip marker
    yield b'\x08'           # CM: compression method
    yield b'\x00'           # FLG: none set
    # MTIME: 4 bytes
    yield struct.pack('<L', int(time.time()) & int('FFFFFFFF', 16))
    yield b'\x02'           # XFL: max compression, slowest algo
    yield b'\xff'           # OS: unknown

    crc = zlib.crc32(b'')
    size = 0
    zobj = zlib.compressobj(compress_level,
                            zlib.DEFLATED, -zlib.MAX_WBITS,
                            zlib.DEF_MEM_LEVEL, 0)
    for line in body:
        size += len(line)
        crc = zlib.crc32(line, crc)
        yield zobj.compress(line)
    yield zobj.flush()

    # CRC32: 4 bytes
    yield struct.pack('<L', crc & int('FFFFFFFF', 16))
    # ISIZE: 4 bytes
    yield struct.pack('<L', size & int('FFFFFFFF', 16)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:30,代码来源:encoding.py

示例13: undeflate

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import MAX_WBITS [as 别名]
def undeflate(s):
	import zlib
	return zlib.decompress(s, -zlib.MAX_WBITS) 
开发者ID:jojoin,项目名称:cutout,代码行数:5,代码来源:cutout.py


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