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


Python zlib.decompress函数代码示例

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


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

示例1: parse

def parse(stream): 
    gzip_maybe = None
    deflate_maybe = None
    chunked_maybe = None
    header_end = stream.find("\r\n\r\n")
    if header_end < 0:
        raise Exception("no header")
    header = simple_http.parse_server_header(stream[:header_end]) 
    if header.get("Content-Encoding") == "gzip":
        gzip_maybe = True
    if header.get("Content-Encoding") == "deflate":
        deflate_maybe = True
    if header.get("Content-Encoding") == "chunked":
        chunked_maybe = True
    stream_buffer = StringIO() 
    content = stream[header_end+4:]
    if chunked_maybe:
        chunked_end = content.rfind("0\r\n\r\n") 
        if chunked_end > -1:
            _handle_chunked(content, stream_buffer)
    else:
        stream_buffer.write(content) 
    final = stream_buffer.getvalue()
    if gzip_maybe:
        final = zlib.decompress(stream_buffer.getvalue(), 16+zlib.MAX_WBITS)
    if deflate_maybe:
        final = zlib.decompress(content_buffer.getvalue(), -zlib.MAX_WBITS)
    stream_buffer.close() 
    return header, final 
开发者ID:DevilMayCry4,项目名称:simple_http,代码行数:29,代码来源:http_stream_parser.py

示例2: testCreateRequestSetNameIDPolicy

    def testCreateRequestSetNameIDPolicy(self):
        """
        Tests the OneLogin_Saml2_Authn_Request Constructor.
        The creation of a deflated SAML Request with and without NameIDPolicy
        """
        saml_settings = self.loadSettingsJSON()
        settings = OneLogin_Saml2_Settings(saml_settings)
        authn_request = OneLogin_Saml2_Authn_Request(settings)
        authn_request_encoded = authn_request.get_request()
        decoded = b64decode(authn_request_encoded)
        inflated = decompress(decoded, -15)
        self.assertRegexpMatches(inflated, '^<samlp:AuthnRequest')
        self.assertIn('<samlp:NameIDPolicy', inflated)

        authn_request_2 = OneLogin_Saml2_Authn_Request(settings, False, False, True)
        authn_request_encoded_2 = authn_request_2.get_request()
        decoded_2 = b64decode(authn_request_encoded_2)
        inflated_2 = decompress(decoded_2, -15)
        self.assertRegexpMatches(inflated_2, '^<samlp:AuthnRequest')
        self.assertIn('<samlp:NameIDPolicy', inflated_2)

        authn_request_3 = OneLogin_Saml2_Authn_Request(settings, False, False, False)
        authn_request_encoded_3 = authn_request_3.get_request()
        decoded_3 = b64decode(authn_request_encoded_3)
        inflated_3 = decompress(decoded_3, -15)
        self.assertRegexpMatches(inflated_3, '^<samlp:AuthnRequest')
        self.assertNotIn('<samlp:NameIDPolicy', inflated_3)
开发者ID:RegBinder,项目名称:python-saml,代码行数:27,代码来源:authn_request_test.py

示例3: node_load

    def node_load (self, desc):
        """Load node by its descriptor
        """
        node_data   = self.store.Load (desc)
        node_tag    = node_data [-1:]

        if node_tag != b'\x01':
            # load node
            node_stream = io.BytesIO (node_data [:-1]) if not self.compress else \
                          io.BytesIO (zlib.decompress (node_data [:-1]))

            node =  StoreBPTreeNode (desc,
                self.keys_from_stream (node_stream),
                Serializer (node_stream).StructListRead (self.desc_struct))
        else:
            # load leaf
            prev, next = self.leaf_struct.unpack (node_data [:self.leaf_struct.size])

            node_stream = io.BytesIO (node_data [self.leaf_struct.size:-1]) if not self.compress else \
                          io.BytesIO (zlib.decompress (node_data [self.leaf_struct.size:-1]))

            node = StoreBPTreeLeaf (desc,
                self.keys_from_stream (node_stream),
                self.values_from_stream (node_stream))
            node.prev = prev
            node.next = next

        self.d2n [desc] = node
        return node
开发者ID:aslpavel,项目名称:store,代码行数:29,代码来源:store.py

示例4: getVersionDiff

 def getVersionDiff( self, fromDate, toDate ):
   retVal = self.rpcClient.getVersionContents( [ fromDate, toDate ] )
   if retVal[ 'OK' ]:
     fromData = zlib.decompress( retVal[ 'Value' ][0] )
     toData = zlib.decompress( retVal[ 'Value' ][1] )
     return difflib.ndiff( fromData.split( "\n" ), toData.split( "\n" ) )
   return []
开发者ID:ahaupt,项目名称:DIRAC,代码行数:7,代码来源:Modificator.py

示例5: postreply

    def postreply(self, reply):

        if self.options.compression in ['yes', 'auto']:
            for header, headerval in reply.headers.items():   # this needs to be items() and not iteritems() because it's sometimes an httplib.HTTPMessage (when decoding an error response) and that doesn't support iteritems()!
                if header.lower() == 'content-encoding':
                    log.debug('http reply with a content-encoding header')
                    if headerval == 'gzip':
                        log.debug('decompressing gzip content')
                        replydatafile = cStringIO.StringIO(reply.message)
                        gzipper = gzip.GzipFile(fileobj=replydatafile)
                        reply.message = gzipper.read()
                    elif headerval == 'deflate':
                        # decompress the deflate content
                        log.debug('decompressing deflate content')
                        try:
                            reply.message = zlib.decompress(reply.message)
                        except zlib.error:
                            # Many web sites fail to send the first bytes of the header
                            reply.message = zlib.decompress(reply.message, -zlib.MAX_WBITS)
                    else:
                        # unknown scheme
                        log.debug('unsupported content-encoding scheme')
                        pass

                    break

        return reply
开发者ID:jazinga,项目名称:suds-philpem,代码行数:27,代码来源:http.py

示例6: decompress_data

    def decompress_data(self,compression):
        
        ### ONLY HANDLING ZLIB_COMPRESSED AT THE MOMENT
        
        hex_compress = hex(compression['magic_cookie'])
        
        #print(hex_compress)
        
#        TA_NOT_COMPRESSED = hex(0x2f2f2f2f)   #The data is not compressed. Use as is it.
        GZIP_COMPRESSED = hex(0xf7f7f7f7)     #The data was compressed using GZIP. Uncompressed appropriately.
#        GZIP_NOT_COMPRESSED = hex(0xf8f8f8f8) #GZIP compression was tried, but it failed. The data is not compressed. Use as it is.
#        BZIP_COMPRESSED = hex(0xf3f3f3f3)     #The data was compressed with BZIP2 version 0.9.0c. Uncompress appropriately.
#        BZIP_NOT_COMPRESSED = hex(0xf4f4f4f4) #BZIP2 compression was tried, but it failed. The data is not compressed. Use it as it is.
        ZLIB_COMPRESSED = hex(0xf5f5f5f5)     #The data was compressed with ZLIB compression. This is the same as GZIP but without the GZIP header structure. Uncompress appropriately.
#        ZLIB_NOT_COMPRESSED = hex(0xf6f6f6f6) #ZLIB compression was tried, but it failed. Data is not compressed, us it as it is.
        
        if hex_compress == ZLIB_COMPRESSED:
            nbytes = compression['nbytes_compressed']
            bin_data=self.mdvfile.read(nbytes)
            
            uncompressed_bytes = zlib.decompress(bin_data)
            
            return uncompressed_bytes
            
        if hex_compress == GZIP_COMPRESSED:
            nbytes = compression['nbytes_compressed']
            bin_data=self.mdvfile.read(nbytes)
            
            #print(bin_data)

            uncompressed_bytes = zlib.decompress(bytes(bin_data), 15+32)
            
            return uncompressed_bytes
开发者ID:jbuonagurio,项目名称:lrose-core,代码行数:33,代码来源:MDV_to_RB5_DP.py

示例7: default_url_fetcher

def default_url_fetcher(url):
    """Fetch an external resource such as an image or stylesheet.

    Another callable with the same signature can be given as the
    :obj:`url_fetcher` argument to :class:`HTML` or :class:`CSS`.
    (See :ref:`url-fetchers`.)

    :type url: Unicode string
    :param url: The URL of the resource to fetch
    :raises: any exception to indicate failure. Failures are logged
        as warnings, with the string representation of the exception
        in the message.
    :returns: In case of success, a dict with the following keys:

        * One of ``string`` (a byte string) or ``file_obj``
          (a file-like object)
        * Optionally: ``mime_type``, a MIME type extracted eg. from a
          *Content-Type* header. If not provided, the type is guessed from the
          file extension in the URL.
        * Optionally: ``encoding``, a character encoding extracted eg. from a
          *charset* parameter in a *Content-Type* header
        * Optionally: ``redirected_url``, the actual URL of the ressource
          in case there were eg. HTTP redirects.
        * Optionally: ``filename``, the filename of the resource. Usually
          derived from the *filename* parameter in a *Content-Disposition*
          header

        If a ``file_obj`` key is given, it is the caller’s responsability
        to call ``file_obj.close()``.

    """
    if url.lower().startswith('data:'):
        return open_data_url(url)
    elif UNICODE_SCHEME_RE.match(url):
        url = iri_to_uri(url)
        response = urlopen(Request(url, headers=HTTP_HEADERS))
        result = dict(redirected_url=response.geturl(),
                      mime_type=urllib_get_content_type(response),
                      encoding=urllib_get_charset(response),
                      filename=urllib_get_filename(response))
        content_encoding = response.info().get('Content-Encoding')
        if content_encoding == 'gzip':
            if StreamingGzipFile is None:
                result['string'] = gzip.GzipFile(
                    fileobj=io.BytesIO(response.read())).read()
                response.close()
            else:
                result['file_obj'] = StreamingGzipFile(fileobj=response)
        elif content_encoding == 'deflate':
            data = response.read()
            try:
                result['string'] = zlib.decompress(data)
            except zlib.error:
                # Try without zlib header or checksum
                result['string'] = zlib.decompress(data, -15)
        else:
            result['file_obj'] = response
        return result
    else:
        raise ValueError('Not an absolute URI: %r' % url)
开发者ID:PierreBizouard,项目名称:WeasyPrint,代码行数:60,代码来源:urls.py

示例8: get_variant_genes

def get_variant_genes(c, args, idx_to_sample):
    samples = defaultdict(list)
    for r in c:
        gt_types = np.array(cPickle.loads(zlib.decompress(r['gt_types'])))
        gts      = np.array(cPickle.loads(zlib.decompress(r['gts'])))
        var_id = str(r['variant_id'])
        chrom = str(r['chrom'])
        start = str(r['start'])
        end = str(r['end'])   
        gene     = str(r['gene'])
        impact = str(r['impact'])
        biotype = str(r['biotype'])
        in_dbsnp = str(r['in_dbsnp'])
        clin_sigs = str(r['clin_sigs'])
        aaf_1kg_all = str(r['aaf_1kg_all'])
        aaf_esp_all = str(r['aaf_esp_all'])
        
        for idx, gt_type in enumerate(gt_types):
            if (gt_type == HET or gt_type == HOM_ALT):
                if gene != "None":
                    (key, value) = (idx_to_sample[idx], \
                                   (gene,var_id,chrom,start,end,impact, \
                                   biotype,in_dbsnp,clin_sigs,aaf_1kg_all, \
                                   aaf_esp_all))
                    samples[idx_to_sample[idx]].append(value)
    return samples
开发者ID:angelinasusan,项目名称:gemini,代码行数:26,代码来源:tool_interactions.py

示例9: load_savegame_string

def load_savegame_string(string):
    """
    :rtype: AIstate
    """
    import base64
    import zlib

    new_string = string
    try:
        new_string = base64.b64decode(string)
    except TypeError as e:
        # The base64 module docs only mention a TypeError exception, for wrong padding
        # Older save files won't be base64 encoded, but seemingly that doesn't trigger
        # an exception here;
        debug("When trying to base64 decode savestate got exception: %s" % e)
    try:
        new_string = zlib.decompress(new_string)
    except zlib.error:
        pass  # probably an uncompressed (or wrongly base64 decompressed) string
    try:
        decoded_state = decode(new_string)
        debug("Decoded a zlib-compressed and apparently base64-encoded save-state string.")
        return decoded_state
    except (InvalidSaveGameException, ValueError, TypeError) as e:
        debug("Base64/zlib decoding path for savestate failed: %s" % e)

    try:
        string = zlib.decompress(string)
        debug("zlib-decompressed a non-base64-encoded save-state string.")
    except zlib.error:
        # probably an uncompressed string
        debug("Will try decoding savestate string without base64 or zlib compression.")
    return decode(string)
开发者ID:Vezzra,项目名称:freeorion,代码行数:33,代码来源:_decoder.py

示例10: convertToFullForm

def convertToFullForm(compactForm):
    arenaUniqueID, avatarResults, fullResultsList, pickled = compactForm
    fullResultsList = cPickle.loads(zlib.decompress(fullResultsList))
    avatarResults = cPickle.loads(zlib.decompress(avatarResults))
    personal = {}
    fullForm = {'arenaUniqueID': arenaUniqueID,
     'personal': personal,
     'common': {},
     'players': {},
     'vehicles': {},
     'avatars': {}}
    personal['avatar'] = avatarResults = AVATAR_FULL_RESULTS.unpack(avatarResults)
    for vehTypeCompDescr, ownResults in fullResultsList.iteritems():
        vehPersonal = personal[vehTypeCompDescr] = VEH_FULL_RESULTS.unpack(ownResults)
        vehPersonal['details'] = VehicleInteractionDetails.fromPacked(vehPersonal['details']).toDict()
        vehPersonal['isPrematureLeave'] = avatarResults['isPrematureLeave']
        vehPersonal['fairplayViolations'] = avatarResults['fairplayViolations']

    commonAsList, playersAsList, vehiclesAsList, avatarsAsList = cPickle.loads(zlib.decompress(pickled))
    fullForm['common'] = COMMON_RESULTS.unpack(commonAsList)
    for accountDBID, playerAsList in playersAsList.iteritems():
        fullForm['players'][accountDBID] = PLAYER_INFO.unpack(playerAsList)

    for accountDBID, avatarAsList in avatarsAsList.iteritems():
        fullForm['avatars'][accountDBID] = AVATAR_PUBLIC_RESULTS.unpack(avatarAsList)

    for vehicleID, vehiclesInfo in vehiclesAsList.iteritems():
        fullForm['vehicles'][vehicleID] = []
        for vehTypeCompDescr, vehicleInfo in vehiclesInfo.iteritems():
            fullForm['vehicles'][vehicleID].append(VEH_PUBLIC_RESULTS.unpack(vehicleInfo))

    return fullForm
开发者ID:webiumsk,项目名称:WOT-0.9.12-CT,代码行数:32,代码来源:battleresultscache.py

示例11: send_http

def send_http(remote, use_ssl, message, timeout, proxy=None, header_only=False): 
    try: 
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
        sock.settimeout(timeout)
        #if there is a proxy , connect proxy server instead 
        proxy_type = None 
        if proxy:
            proxy_type = connect_proxy(sock, remote, proxy)
        else:
            sock.connect(remote) 
        if use_ssl and proxy_type != "http":
            sock = ssl.wrap_socket(sock) 
        sock.send(message) 
        header, body = wait_response(sock, header_only)
    except socket.error:
        sock.close() 
        raise 
    #handle compressed stream: gzip, deflate 
    if not header_only and header: 
        #maybe gzip stream
        if header.get("Content-Encoding") == "gzip": 
            body = zlib.decompress(body, 16+zlib.MAX_WBITS)  
        elif header.get("Content-Encoding") == "deflate":
            body = zlib.decompress(body, -zlib.MAX_WBITS)  
    return header, body 
开发者ID:Ethan-zhengyw,项目名称:simple_http,代码行数:25,代码来源:simple_http.py

示例12: decode_deflate

def decode_deflate(data):
    ''' decode deflate content '''
    import zlib
    try:
        return zlib.decompress(data)
    except zlib.error:
        return zlib.decompress(data, -zlib.MAX_WBITS)
开发者ID:9000000,项目名称:xbmc-addons,代码行数:7,代码来源:urlfetch.py

示例13: extract_pkg_from_data

def extract_pkg_from_data(byte_data):
    complete_pkg = []

    z_packages = byte_data.split(compress_pkg_header)
    len_pkg = len(z_packages)
    dbgprint('Len_Sep:', len_pkg)
    if len_pkg < 2:
        errprint('ReceiveError,CannotFindGzipHeader', byte_data)
        raise ValueError('ReceiveError,CannotFindGzipHeader')

    else:
        data_to_preserve = z_packages.pop()
        for z_pkg in z_packages:
            z_pkg = z_pkg[:-compress_pkg_footer_len]  # Remove footer mark
            if not z_pkg:
                continue
            dbgprint('AfterGzip', len(z_pkg), v=4)
            decompressed_data = zlib.decompress(z_pkg)
            dbgprint('BeforeGzip', len(decompressed_data), v=4)
            complete_pkg.append(decompressed_data)

        if data_to_preserve[-compress_pkg_footer_len:] == compress_pkg_footer:  # last pkg is complete
            data_to_preserve = data_to_preserve[:-compress_pkg_footer_len]
            dbgprint('AfterGzip', len(data_to_preserve), v=4)
            decompressed_data = zlib.decompress(data_to_preserve)
            dbgprint('BeforeGzip', len(decompressed_data), v=4)
            complete_pkg.append(decompressed_data)
            data_to_preserve = b''
        else:
            data_to_preserve = compress_pkg_header + data_to_preserve

    return complete_pkg, data_to_preserve
开发者ID:zeropool,项目名称:shootback,代码行数:32,代码来源:common_func.py

示例14: resp_deflate

 def resp_deflate(data):
     # zlib only provides the zlib compress format, not the deflate format;
     # so on top of all there's this workaround:   
     try:               
         return zlib.decompress(data, -zlib.MAX_WBITS)
     except zlib.error:
         return zlib.decompress(data)
开发者ID:BGCX261,项目名称:zouqi-svn-to-git,代码行数:7,代码来源:spider_urllib2_extend.py

示例15: _restoreb

 def _restoreb(self, bdata, pwd=''):
     '''
     Restores binary data from SQL information. \n\
     '''
     # If password is null in some way, do not encrypt.
     if not pwd:
         try: return zlib.decompress(bdata)
         except: return bz2.decompress(bdata)
     # If using global password.
     elif pwd == 1:
         # If global password is null, do not decrypt.
         if not self.glob_key:
             try: return zlib.decompress(bdata)
             except: return bz2.decompress(bdata)
         # If global password exists, use it.
         else:
             pwd = self.glob_key
     # If password is provided, generate key derivation.
     else:
         pwd = PBKDF2(password=pwd, salt=self.glob_salt, dkLen=32, count=1000)
     # Decrypt and return.
     crypt = AES.new(pwd)
     vCompressed = crypt.decrypt(bdata)
     try: return zlib.decompress(vCompressed)
     except: return bz2.decompress(vCompressed)
开发者ID:croqaz,项目名称:private-briefcase,代码行数:25,代码来源:briefcase.py


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