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


Python snappy.uncompress方法代码示例

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


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

示例1: decompress

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import uncompress [as 别名]
def decompress(data, compressor_id):
    if compressor_id == SnappyContext.compressor_id:
        # python-snappy doesn't support the buffer interface.
        # https://github.com/andrix/python-snappy/issues/65
        # This only matters when data is a memoryview since
        # id(bytes(data)) == id(data) when data is a bytes.
        # NOTE: bytes(memoryview) returns the memoryview repr
        # in Python 2.7. The right thing to do in 2.7 is call
        # memoryview.tobytes(), but we currently only use
        # memoryview in Python 3.x.
        return snappy.uncompress(bytes(data))
    elif compressor_id == ZlibContext.compressor_id:
        return zlib.decompress(data)
    elif compressor_id == ZstdContext.compressor_id:
        # ZstdDecompressor is not thread safe.
        # TODO: Use a pool?
        return ZstdDecompressor().decompress(data)
    else:
        raise ValueError("Unknown compressorId %d" % (compressor_id,)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:21,代码来源:compression_support.py

示例2: post

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import uncompress [as 别名]
def post(self):
        buf = snappy.uncompress(pecan.request.body)
        f = remote_pb2.WriteRequest()
        f.ParseFromString(buf)
        measures_by_rid = collections.defaultdict(dict)
        for ts in f.timeseries:
            attrs = dict((l.name, l.value) for l in ts.labels)
            original_rid = (attrs.get("job", "none"),
                            attrs.get("instance", "none"))
            name = attrs['__name__']
            if ts.samples:
                data = [{'timestamp': s.timestamp_ms / 1000.0,
                         'value': s.value} for s in ts.samples]
                measures_by_rid[original_rid][name] = validate(
                    MeasuresListSchema, data)

        creator = pecan.request.auth_helper.get_current_user(pecan.request)

        measures_to_batch = {}
        for (job, instance), measures in measures_by_rid.items():
            original_rid = '%s@%s' % (job, instance)
            rid = ResourceUUID(original_rid, creator=creator)
            metric_names = list(measures.keys())
            timeout = pecan.request.conf.api.operation_timeout
            metrics = get_or_create_resource_and_metrics.retry_with(
                stop=tenacity.stop_after_delay(timeout))(
                    creator, rid, original_rid, metric_names,
                    dict(job=job, instance=instance),
                    "prometheus", self.PROMETHEUS_RESOURCE_TYPE)

            for metric in metrics:
                enforce("post measures", metric)

            measures_to_batch.update(
                dict((metric.id, measures[metric.name]) for metric in
                     metrics if metric.name in measures))

        pecan.request.incoming.add_measures_batch(measures_to_batch)
        pecan.response.status = 202 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:41,代码来源:api.py

示例3: decompress

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import uncompress [as 别名]
def decompress(data, compressor_id):
    if compressor_id == SnappyContext.compressor_id:
        # python-snappy doesn't support the buffer interface.
        # https://github.com/andrix/python-snappy/issues/65
        # This only matters when data is a memoryview since
        # id(bytes(data)) == id(data) when data is a bytes.
        # NOTE: bytes(memoryview) returns the memoryview repr
        # in Python 2.7. The right thing to do in 2.7 is call
        # memoryview.tobytes(), but we currently only use
        # memoryview in Python 3.x.
        return snappy.uncompress(bytes(data))
    elif compressor_id == ZlibContext.compressor_id:
        return zlib.decompress(data)
    else:
        raise ValueError("Unknown compressorId %d" % (compressor_id,)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:17,代码来源:compression_support.py

示例4: _unpack_msgpack_snappy

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import uncompress [as 别名]
def _unpack_msgpack_snappy(str):
    if str.startswith(b'S'):
        tmp = snappy.uncompress(str[1:])
        # print "SNAPPY: ", len(str), len(tmp)
        obj = msgpack.loads(tmp, encoding='utf-8')
    elif str.startswith(b'\0'):
        obj = msgpack.loads(str[1:], encoding='utf-8')
    else:
        return None
    
    return obj 
开发者ID:quantOS-org,项目名称:TradeSim,代码行数:13,代码来源:jrpc_py.py

示例5: decompress

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import uncompress [as 别名]
def decompress(data):
    """
    Decompresses the given data via the snappy algorithm.

    If ``python-snappy`` is not installed a ``RuntimeError`` is raised.
    """
    if not snappy_available:
        raise RuntimeError("Snappy compression unavailable.")

    buff_offset = len(raw_header)  # skip the header
    length = len(data) - len(raw_header)

    output = BytesIO()

    while buff_offset <= length:
        block_size = struct.unpack_from("!i", data, buff_offset)[0]
        buff_offset += struct.calcsize("!i")

        block = struct.unpack_from("!%ds" % block_size, data, buff_offset)[0]
        buff_offset += block_size

        output.write(snappy.uncompress(block))

    result = output.getvalue()

    output.close()

    return result 
开发者ID:wglass,项目名称:kiel,代码行数:30,代码来源:snappy.py


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