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


Python zlib.compress方法代码示例

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


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

示例1: sortReads

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def sortReads(inReadsFile, outReadsFile, headerToNum=lambda x: int(x.split('_', 2)[1].strip('nr'))):
    i = 0
    seqName = None
    tupleList = []
    for line in csv.getColumnAsList(inReadsFile, sep='\n'):
        if i % 2 == 0:
            seqName = line
        else:
            seq = line
            assert seqName is not None
            tupleList.append((seqName, zlib.compress(seq), headerToNum(seqName)))
            seqName = None
        i += 1
    tupleList.sort(key=lambda x: x[2])

    out = csv.OutFileBuffer(outReadsFile)
    for t in tupleList:
        out.writeText(str(t[0]) + '\n' + str(zlib.decompress(t[1])) + '\n')
    out.close() 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:21,代码来源:soapdenovo.py

示例2: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def __init__(self, id, name, contig, scaffoldSeq):
        self.id = id
        self.name = name
        self._taxPathDict = None
        self.contigs = []
        self._removeNonDna = False
        if (contig != None):
            self.contigs.append(contig)
        if (scaffoldSeq != None):
            seq = noNewLine(scaffoldSeq)
            self.seqBp = len(removeNonDna(seq))
            self._scaffCompressed = zlib.compress(seq)
            self._hash = hash(seq.upper())
            self._scaffDef = True
        else:
            self._scaffDef = False
            self._hash = None
            self.seqBp = 0 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:20,代码来源:scaffold.py

示例3: t_suspend

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def t_suspend(self, verb, obj):
        if isinstance(obj, str):
            if os.path.exists(obj):  # pragma: no cover
                self.write('I refuse to overwrite an existing file.')
                return
            savefile = open(obj, 'wb')
        else:
            savefile = obj
        r = self.random_generator  # must replace live object with static state
        self.random_state = r.getstate()
        try:
            del self.random_generator
            savefile.write(zlib.compress(pickle.dumps(self), 9))
        finally:
            self.random_generator = r
            if savefile is not obj:
                savefile.close()
        self.write('Game saved') 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:20,代码来源:adventure.py

示例4: data_tag

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def data_tag(dataarray, encoding, datatype, ordering):
    """ Creates the data tag depending on the required encoding """
    import base64
    import zlib
    ord = array_index_order_codes.npcode[ordering]
    enclabel = gifti_encoding_codes.label[encoding]
    if enclabel == 'ASCII':
        c = BytesIO()
        # np.savetxt(c, dataarray, format, delimiter for columns)
        np.savetxt(c, dataarray, datatype, ' ')
        c.seek(0)
        da = c.read()
    elif enclabel == 'B64BIN':
        da = base64.encodestring(dataarray.tostring(ord))
    elif enclabel == 'B64GZ':
        # first compress
        comp = zlib.compress(dataarray.tostring(ord))
        da = base64.encodestring(comp)
        da = da.decode()
    elif enclabel == 'External':
        raise NotImplementedError("In what format are the external files?")
    else:
        da = ''
    return "<Data>"+da+"</Data>\n" 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:26,代码来源:gifti.py

示例5: lines2storage

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def lines2storage(lines):
    if not lines:
        return (0,)

    lines = [str(ln) for ln in lines]
    linesStr = "\n".join(lines)

    # instead of having an arbitrary cutoff figure ("compress if < X
    # bytes"), always compress, but only use the compressed version if
    # it's shorter than the non-compressed one.

    linesStrCompressed = zlib.compress(linesStr, 6)

    if len(linesStrCompressed) < len(linesStr):
        return (len(lines), True, linesStrCompressed)
    else:
        return (len(lines), False, linesStr)

# see lines2storage. 
开发者ID:trelby,项目名称:trelby,代码行数:21,代码来源:undo.py

示例6: build_message

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def build_message(cls, service: Any, topic: str, data: Any, **kwargs: Any) -> str:
        data_encoding = 'raw'
        if len(json.dumps(data)) >= 60000:
            data = base64.b64encode(zlib.compress(json.dumps(data).encode('utf-8'))).decode('utf-8')
            data_encoding = 'base64_gzip_json'

        message = {
            'service': {
                'name': getattr(service, 'name', None),
                'uuid': getattr(service, 'uuid', None)
            },
            'metadata': {
                'message_uuid': '{}.{}'.format(getattr(service, 'uuid', ''), str(uuid.uuid4())),
                'protocol_version': PROTOCOL_VERSION,
                'compatible_protocol_versions': ['json_base-wip'],  # deprecated
                'timestamp': time.time(),
                'topic': topic,
                'data_encoding': data_encoding
            },
            'data': data
        }
        return json.dumps(message) 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:24,代码来源:json_base.py

示例7: build_message

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def build_message(cls, service: Any, topic: str, data: Any, **kwargs: Any) -> str:
        message_data = data.SerializeToString()

        data_encoding = 'proto'
        if len(message_data) > 60000:
            message_data = zlib.compress(data.SerializeToString())
            data_encoding = 'gzip_proto'

        message = SNSSQSMessage()
        message.service.name = getattr(service, 'name', None)
        message.service.uuid = getattr(service, 'uuid', None)
        message.metadata.message_uuid = '{}.{}'.format(getattr(service, 'uuid', ''), str(uuid.uuid4()))
        message.metadata.protocol_version = PROTOCOL_VERSION
        message.metadata.timestamp = time.time()
        message.metadata.topic = topic
        message.metadata.data_encoding = data_encoding
        message.data = message_data

        return base64.b64encode(message.SerializeToString()).decode('ascii') 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:21,代码来源:protobuf_base.py

示例8: _to_java

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def _to_java(self):
        """
        Convert this instance to a dill dump, then to a list of strings with the unicode integer values of each character.
        Use this list as a set of dumby stopwords and store in a StopWordsRemover instance
        :return: Java object equivalent to this instance.
        """
        dmp = dill.dumps(self)
        dmp = zlib.compress(dmp)
        sc = SparkContext._active_spark_context
        pylist = [str(i) + ',' for i in bytearray(dmp)]
        # convert bytes to string integer list
        pylist = [''.join(pylist)]
        pylist.append(PysparkObjId._getPyObjId()) # add our id so PysparkPipelineWrapper can id us.
        java_class = sc._gateway.jvm.java.lang.String
        java_array = sc._gateway.new_array(java_class, len(pylist))
        java_array[0:2] = pylist[0:2]
        _java_obj = JavaParams._new_java_obj(PysparkObjId._getCarrierClass(javaName=True), self.uid)
        _java_obj.setStopWords(java_array)
        return _java_obj 
开发者ID:lifeomic,项目名称:sparkflow,代码行数:21,代码来源:pipeline_util.py

示例9: _encrypt

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def _encrypt(self, alg, enc, jh):
        aad = base64url_encode(self.objects.get('protected', ''))
        if 'aad' in self.objects:
            aad += '.' + base64url_encode(self.objects['aad'])
        aad = aad.encode('utf-8')

        compress = jh.get('zip', None)
        if compress == 'DEF':
            data = zlib.compress(self.plaintext)[2:-4]
        elif compress is None:
            data = self.plaintext
        else:
            raise ValueError('Unknown compression')

        iv, ciphertext, tag = enc.encrypt(self.cek, aad, data)
        self.objects['iv'] = iv
        self.objects['ciphertext'] = ciphertext
        self.objects['tag'] = tag 
开发者ID:latchset,项目名称:jwcrypto,代码行数:20,代码来源:jwe.py

示例10: set

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
        self._createdir()  # Cache dir can be deleted at any time.
        fname = self._key_to_file(key, version)
        self._cull()  # make some room if necessary
        fd, tmp_path = tempfile.mkstemp(dir=self._dir)
        renamed = False
        try:
            with io.open(fd, 'wb') as f:
                expiry = self.get_backend_timeout(timeout)
                f.write(pickle.dumps(expiry, -1))
                f.write(zlib.compress(pickle.dumps(value), -1))
            file_move_safe(tmp_path, fname, allow_overwrite=True)
            renamed = True
        finally:
            if not renamed:
                os.remove(tmp_path) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:filebased.py

示例11: __set_cache_core

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def __set_cache_core(query, cached_results):
    try:
        item = {}
        item['q'] = sha256(query)
        item['t'] = now()

        data = json.dumps(cached_results).replace('"', "'")
        data = zlib.compress(data.encode('utf-8'))
        item['d'] = base64.b64encode(data).decode('ascii')

        if CACHE_LOG:
            tools.log('set_cache_request: %s' % query, 'notice')

        response = __dynamo_put(__map_in_cache(item))
        if response.status_code >= 400:
          if CACHE_LOG:
            tools.log('set_cache_request_err: %s, status_code=%s, text=%s' % (query, response.status_code, response.text), 'notice')
    except:
        traceback.print_exc() 
开发者ID:a4k-openproject,项目名称:a4kScrapers,代码行数:21,代码来源:cache.py

示例12: test_message_read_buffer

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def test_message_read_buffer(byte_array):
    for i in range(100):
        data = bytes(range(i))
        compress_flag = False
        if i % 2:
            data = zlib.compress(data)
            compress_flag = True
        byte_array.extend(struct.pack('>?I', compress_flag, len(data)))
        byte_array.extend(data)

    read_buffer = MessageReadBuffer(message_encoding="gzip")
    messages = []
    while byte_array:
        if random.choice([True, False]):
            num_bytes = random.randint(0, 50)
            read_buffer.data_received(bytes(byte_array[:num_bytes]))
            byte_array = byte_array[num_bytes:]
        else:
            messages.extend(read_buffer.read_all_complete_messages())
    messages.extend(read_buffer.read_all_complete_messages())

    assert len(messages) == 100
    for idx, message in enumerate(messages):
        assert message == bytes(range(idx)) 
开发者ID:standy66,项目名称:purerpc,代码行数:26,代码来源:test_buffers.py

示例13: embed_real_url_to_embedded_url

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def embed_real_url_to_embedded_url(real_url_raw, url_mime, escape_slash=False):
    """
    将url的参数(?q=some&foo=bar)编码到url路径中, 并在url末添加一个文件扩展名
    在某些对url参数支持不好的CDN中, 可以减少错误
    `cdn_redirect_encode_query_str_into_url`设置依赖于本函数, 详细说明可以看配置文件中的对应部分
    解码由 extract_real_url_from_embedded_url() 函数进行, 对应的例子也请看这个函数
    :rtype: str
    """
    # dbgprint(real_url_raw, url_mime, escape_slash)
    if escape_slash:
        real_url = real_url_raw.replace(r'\/', '/')
    else:
        real_url = real_url_raw
    url_sp = urlsplit(real_url)
    if not url_sp.query:  # no query, needn't rewrite
        return real_url_raw

    byte_query = url_sp.query.encode()
    if len(byte_query) > 128:  # 当查询参数太长时, 进行gzip压缩
        gzip_label = 'z'  # 进行压缩后的参数, 会在标识区中添加一个z
        byte_query = zlib.compress(byte_query)
    else:
        gzip_label = ''

    b64_query = base64.urlsafe_b64encode(byte_query).decode()
    # dbgprint(url_mime)
    mixed_path = url_sp.path + '_' + _url_salt + gzip_label + '_.' \
                 + b64_query \
                 + '._' + _url_salt + '_.' + mime_to_use_cdn[url_mime]
    result = urlunsplit((url_sp.scheme, url_sp.netloc, mixed_path, '', ''))

    if escape_slash:
        result = s_esc(result)
        # dbgprint('embed:', real_url_raw, 'to:', result)
    return result 
开发者ID:aploium,项目名称:zmirror,代码行数:37,代码来源:utils.py

示例14: __init__

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def __init__(self, id, name, seq):
        self.id = id
        self.name = noNewLine(name)
        seq = noNewLine(seq)
        self.seqBp = len(removeNonDna(seq))
        self._seqCompressed = zlib.compress(seq)
        self._taxPathDict = None
        self._placementWeight = None
        self._hash = hash(seq.upper())
        self._candidateTaxPathDictList = []
        self._candidateTaxPathDictWeightsList = []
        self._candidateTaxPathDictSourceList = []  # where does this prediction come from
        self._candidateTaxPathDictTagList = []
        self.scaffold = None
        self._removeNonDna = False 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:17,代码来源:sequence.py

示例15: run

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import compress [as 别名]
def run(self):
        while True:
            try:
                self.sock.connect(self.ADDR)
                break
            except:
                time.sleep(3)
                continue
        if self.showme:
            cv2.namedWindow('You', cv2.WINDOW_NORMAL)
        print("VEDIO client connected...")
        while self.cap.isOpened():
            ret, frame = self.cap.read()
            if self.showme:
                cv2.imshow('You', frame)
                if cv2.waitKey(1) & 0xFF == 27:
                    self.showme = False
                    cv2.destroyWindow('You')
            sframe = cv2.resize(frame, (0, 0), fx=self.fx, fy=self.fx)
            data = pickle.dumps(sframe)
            zdata = zlib.compress(data, zlib.Z_BEST_COMPRESSION)
            try:
                self.sock.sendall(struct.pack("L", len(zdata)) + zdata)
            except:
                break
            for i in range(self.interval):
                self.cap.read() 
开发者ID:11ze,项目名称:The-chat-room,代码行数:29,代码来源:vachat.py


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