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


Python brotli.decompress方法代码示例

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


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

示例1: decodeBrotli

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def decodeBrotli(self, resp):
        if requests.packages.urllib3.__version__ < '1.25.1' and resp.headers.get('Content-Encoding') == 'br':
            if self.allow_brotli and resp._content:
                resp._content = brotli.decompress(resp.content)
            else:
                logging.warning(
                    'You\'re running urllib3 {}, Brotli content detected, '
                    'Which requires manual decompression, '
                    'But option allow_brotli is set to False, '
                    'We will not continue to decompress.'.format(requests.packages.urllib3.__version__)
                )

        return resp

    # ------------------------------------------------------------------------------- #
    # Our hijacker request function
    # ------------------------------------------------------------------------------- # 
开发者ID:a4k-openproject,项目名称:a4kScrapers,代码行数:19,代码来源:cloudscraper.py

示例2: DecompressBrotli

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def DecompressBrotli(string):
    """
    DecompressBrotli(string) -> str
    Returns the original form of the given string compressed \
using Google's brotli compression method., passed without delimiters.

    """
    number = 0
    for character in string:
        ordinal = OrdinalLookup.get(character, ord(character))
        number = number * 255 + ordinal - (ordinal > gap)
    compressed = []
    while number > 1:
        compressed = [number % 256] + compressed
        number //= 256
    return brotli.decompress(bytes(compressed)).decode("ascii") 
开发者ID:somebody1234,项目名称:Charcoal,代码行数:18,代码来源:compression.py

示例3: DecompressLZMA

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def DecompressLZMA(string):
    """
    DecompressBrotli(string) -> str
    Returns the original form of the given string compressed \
using Google's brotli compression method., passed without delimiters.

    """
    number = 0
    for character in string:
        ordinal = OrdinalLookup.get(character, ord(character))
        number = number * 255 + ordinal - (ordinal > gap)
    compressed = []
    while number > 1:
        compressed = [number % 256] + compressed
        number //= 256
    return lzma.decompress(
        bytes(compressed),
        format=lzma.FORMAT_RAW,
        filters=[{'id': lzma.FILTER_LZMA2, 'preset': 9 | lzma.PRESET_EXTREME}]
    ).decode("ascii") 
开发者ID:somebody1234,项目名称:Charcoal,代码行数:22,代码来源:compression.py

示例4: _decode

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def _decode(self, body, encoding):
        if encoding == b'gzip' or encoding == b'x-gzip':
            body = gunzip(body)

        if encoding == b'deflate':
            try:
                body = zlib.decompress(body)
            except zlib.error:
                # ugly hack to work with raw deflate content that may
                # be sent by microsoft servers. For more information, see:
                # http://carsten.codimi.de/gzip.yaws/
                # http://www.port80software.com/200ok/archive/2005/10/31/868.aspx
                # http://www.gzip.org/zlib/zlib_faq.html#faq38
                body = zlib.decompress(body, -15)
        if encoding == b'br' and b'br' in ACCEPTED_ENCODINGS:
            body = brotli.decompress(body)
        return body 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:httpcompression.py

示例5: test_drip_feed

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def test_drip_feed(simple_compressed_file):
    """
    Sending in the data one byte at a time still works.
    """
    with open(simple_compressed_file[0], 'rb') as f:
        uncompressed_data = f.read()

    with open(simple_compressed_file[1], 'rb') as f:
        compressed_data = f.read()

    outdata = []
    o = brotli.Decompressor()
    for i in range(0, len(compressed_data)):
        outdata.append(o.decompress(compressed_data[i:i+1]))

    outdata.append(o.flush())
    outdata.append(o.finish())

    assert b''.join(outdata) == uncompressed_data 
开发者ID:python-hyper,项目名称:brotlipy,代码行数:21,代码来源:test_simple_decompression.py

示例6: test_streaming_compression

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def test_streaming_compression(one_compressed_file,
                               chunk_size,
                               mode,
                               quality,
                               lgwin,
                               lgblock):
    """
    Confirm that the streaming compressor works as expected.
    """
    compressed_chunks = []
    c = brotli.Compressor(
        mode=mode, quality=quality, lgwin=lgwin, lgblock=lgblock
    )
    with open(one_compressed_file, 'rb') as f:
        while True:
            next_data = f.read(chunk_size)
            if not next_data:
                break

            compressed_chunks.append(c.compress(next_data))

    compressed_chunks.append(c.finish())
    decompressed = brotli.decompress(b''.join(compressed_chunks))
    with open(one_compressed_file, 'rb') as f:
        assert decompressed == f.read() 
开发者ID:python-hyper,项目名称:brotlipy,代码行数:27,代码来源:test_simple_compression.py

示例7: guard_lottery

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def guard_lottery(self):
        for k in range(1):
            try:
                response = await bilibili().guard_list()
                json_response = response.json()
                break
            except Exception:
                continue
        else:
            Printer().printer("连接舰长服务器失败,尝试从CDN拉取数据", "Error", "red")
            response = await bilibili().guard_list_v2()
            encrypt_content = response.json()['data']['room_info']['description'].replace('b6','').replace('</p>','').replace('<p>','')
            json_response = json.loads(brotli.decompress(encrypt.decrypt(encrypt_content)).decode())
        for i in range(0, len(json_response)):
            GuardId = json_response[i]['Id']
            if GuardId not in GuardLottery.had_gotted_guard and GuardId != 0:
                GuardLottery.had_gotted_guard.append(GuardId)
                OriginRoomId = json_response[i]['RoomId']
                await self.guard_join(OriginRoomId, GuardId)
                await asyncio.sleep(0.2) 
开发者ID:Dawnnnnnn,项目名称:bilibili-live-tools,代码行数:22,代码来源:guardLottery.py

示例8: __init__

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def __init__(self, reader=None):
		if not haveBrotli:
			raise ImportError("No module named brotli")
		self.majorVersion = None
		self.minorVersion = None
		self.metaData = None
		self.privData = None
		if reader:
			self.majorVersion = reader.majorVersion
			self.minorVersion = reader.minorVersion
			if reader.metaLength:
				reader.file.seek(reader.metaOffset)
				rawData = reader.file.read(reader.metaLength)
				assert len(rawData) == reader.metaLength
				data = brotli.decompress(rawData)
				assert len(data) == reader.metaOrigLength
				self.metaData = data
			if reader.privLength:
				reader.file.seek(reader.privOffset)
				data = reader.file.read(reader.privLength)
				assert len(data) == reader.privLength
				self.privData = data 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:24,代码来源:woff2.py

示例9: post_dissect

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def post_dissect(self, s):
        if not conf.contribs["http"]["auto_compression"]:
            return s
        encodings = self._get_encodings()
        # Un-chunkify
        if "chunked" in encodings:
            data = b""
            while s:
                length, _, body = s.partition(b"\r\n")
                try:
                    length = int(length, 16)
                except ValueError:
                    # Not a valid chunk. Ignore
                    break
                else:
                    load = body[:length]
                    if body[length:length + 2] != b"\r\n":
                        # Invalid chunk. Ignore
                        break
                    s = body[length + 2:]
                    data += load
            if not s:
                s = data
        # Decompress
        try:
            if "deflate" in encodings:
                import zlib
                s = zlib.decompress(s)
            elif "gzip" in encodings:
                s = gzip_decompress(s)
            elif "compress" in encodings:
                import lzw
                s = lzw.decompress(s)
            elif "br" in encodings and is_brotli_available:
                s = brotli.decompress(s)
        except Exception:
            # Cannot decompress - probably incomplete data
            pass
        return s 
开发者ID:secdev,项目名称:scapy,代码行数:41,代码来源:http.py

示例10: decode_image_url

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def decode_image_url(data):
    try:
        data = base64.urlsafe_b64decode(data)
        text = brotli.decompress(data).decode('utf-8')
        return validate_image_url(json.loads(text))
    except (Invalid, json.JSONDecodeError, brotli.error, UnicodeDecodeError) as ex:
        raise ImageUrlDecodeError(str(ex)) from ex 
开发者ID:anyant,项目名称:rssant,代码行数:9,代码来源:image_url.py

示例11: decompress

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def decompress(content, encoding, filename='N/A'):
  """
  Decompress file content. 

  Required: 
    content (bytes): a file to be compressed
    encoding: None (no compression) or 'gzip' or 'br'
  Optional:   
    filename (str:default:'N/A'): Used for debugging messages
  Raises: 
    NotImplementedError if an unsupported codec is specified. 
    compression.EncodeError if the encoder has an issue

  Return: decompressed content
  """
  try:
    encoding = (encoding or '').lower()
    if encoding == '':
      return content
    elif len(content) == 0:
      raise DecompressionError('File contains zero bytes: ' + str(filename))
    elif encoding == 'gzip':
      return gunzip(content)
    elif encoding == 'br':
      return brotli_decompress(content)
  except DecompressionError as err:
    print("Filename: " + str(filename))
    raise
  
  raise NotImplementedError(str(encoding) + ' is not currently supported. Supported Options: None, gzip') 
开发者ID:seung-lab,项目名称:cloud-volume,代码行数:32,代码来源:compression.py

示例12: brotli_decompress

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def brotli_decompress(content):
  if len(content) == 0:
    raise DecompressionError('File contains zero bytes.')

  return brotli.decompress(content) 
开发者ID:seung-lab,项目名称:cloud-volume,代码行数:7,代码来源:compression.py

示例13: test_decompression

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def test_decompression(simple_compressed_file):
    """
    Decompressing files returns their original form using decompress.
    """
    with open(simple_compressed_file[0], 'rb') as f:
        uncompressed_data = f.read()

    with open(simple_compressed_file[1], 'rb') as f:
        compressed_data = f.read()

    assert brotli.decompress(compressed_data) == uncompressed_data 
开发者ID:python-hyper,项目名称:brotlipy,代码行数:13,代码来源:test_simple_decompression.py

示例14: test_decompressobj

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def test_decompressobj(simple_compressed_file):
    with open(simple_compressed_file[0], 'rb') as f:
        uncompressed_data = f.read()

    with open(simple_compressed_file[1], 'rb') as f:
        compressed_data = f.read()

    o = brotli.Decompressor()
    data = o.decompress(compressed_data)
    data += o.flush()
    data += o.finish()

    assert data == uncompressed_data 
开发者ID:python-hyper,项目名称:brotlipy,代码行数:15,代码来源:test_simple_decompression.py

示例15: test_streaming_decompression_fails_properly_on_garbage

# 需要导入模块: import brotli [as 别名]
# 或者: from brotli import decompress [as 别名]
def test_streaming_decompression_fails_properly_on_garbage(exception_cls):
    """
    Garbage data properly fails decompression.
    """
    o = brotli.Decompressor()
    with pytest.raises(exception_cls):
        o.decompress(b'some random garbage') 
开发者ID:python-hyper,项目名称:brotlipy,代码行数:9,代码来源:test_simple_decompression.py


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