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


Python gzip.decompress方法代码示例

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


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

示例1: patch_id

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def patch_id(repo):
        url = repo + 'repodata/repomd.xml'
        repomd = requests.get(url)
        if not repomd.ok:
            return None
        root = ET.fromstring(repomd.text)

        cs = root.find(
            './/{http://linux.duke.edu/metadata/repo}data[@type="updateinfo"]/{http://linux.duke.edu/metadata/repo}location')
        try:
            url = repo + cs.attrib['href']
        except AttributeError:
            return None

        repomd = requests.get(url).content
        root = ET.fromstring(decompress(repomd))
        return root.find('.//id').text

    # take the first package name we find - often enough correct 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:21,代码来源:update.py

示例2: testRequest

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def testRequest(self):
        runner.run(
            self._func, 'p', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['p']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertTrue(len(stats['p']['callStats']) > 0)
        self.assertTrue(stats['p']['totalTime'] > 0)
        self.assertTrue(stats['p']['primitiveCalls'] > 0)
        self.assertTrue(stats['p']['totalCalls'] > 0)


# pylint: enable=missing-docstring, blacklisted-name 
开发者ID:nvdv,项目名称:vprof,代码行数:19,代码来源:profiler_e2e.py

示例3: testRequest

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def testRequest(self):
        runner.run(
            self._func, 'h', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        self.assertTrue(stats['h']['runTime'] > 0)
        heatmaps = stats['h']['heatmaps']
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['h']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertEqual(len(heatmaps), 1)
        self.assertDictEqual(
            heatmaps[0]['executionCount'], {'101': 1, '102': 1})
        self.assertListEqual(
            heatmaps[0]['srcCode'],
            [['line', 100, u'        def _func(foo, bar):\n'],
             ['line', 101, u'            baz = foo + bar\n'],
             ['line', 102, u'            return baz\n']])

# pylint: enable=missing-docstring, blacklisted-name 
开发者ID:nvdv,项目名称:vprof,代码行数:24,代码来源:code_heatmap_e2e.py

示例4: testRequest

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def testRequest(self):
        runner.run(
            self._func, 'c', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['c']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertEqual(
            stats['c']['sampleInterval'], flame_graph._SAMPLE_INTERVAL)
        self.assertTrue(stats['c']['runTime'] > 0)
        self.assertTrue(len(stats['c']['callStats']) >= 0)
        self.assertTrue(stats['c']['totalSamples'] >= 0)

# pylint: enable=missing-docstring, blacklisted-name, protected-access 
开发者ID:nvdv,项目名称:vprof,代码行数:19,代码来源:flame_graph_e2e.py

示例5: testRequest

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def testRequest(self):
        runner.run(
            self._func, 'm', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['m']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertEqual(stats['m']['totalEvents'], 2)
        self.assertEqual(stats['m']['codeEvents'][0][0], 1)
        self.assertEqual(stats['m']['codeEvents'][0][1], 91)
        self.assertEqual(stats['m']['codeEvents'][0][3], '_func')
        self.assertEqual(stats['m']['codeEvents'][1][0], 2)
        self.assertEqual(stats['m']['codeEvents'][1][1], 92)
        self.assertEqual(stats['m']['codeEvents'][1][3], '_func')

# pylint: enable=missing-docstring, blacklisted-name 
开发者ID:nvdv,项目名称:vprof,代码行数:21,代码来源:memory_profiler_e2e.py

示例6: read_data

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def read_data(self, f):
        """Retrieve (uncompressed) data from WAD file object"""

        f.seek(self.offset)
        # assume files are small enough to fit in memory
        data = f.read(self.compressed_size)
        if self.type == 0:
            return data
        elif self.type == 1:
            return gzip.decompress(data)
        elif self.type == 2:
            n, = struct.unpack('<L', data[:4])
            target = data[4:4+n].rstrip(b'\0').decode('utf-8')
            logger.debug(f"file redirection: {target}")
            return None
        elif self.type == 3:
            return zstd_decompress(data)
        raise ValueError(f"unsupported file type: {self.type}") 
开发者ID:CommunityDragon,项目名称:CDTB,代码行数:20,代码来源:wad.py

示例7: get_items_from_gzip

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def get_items_from_gzip(binary: bytes) -> Tuple[str, Dict[str, bytes]]:
    """
    Return decompressed gzip contents.

    Parameters
    ----------
    binary : bytes
        byte array of gz file

    Returns
    -------
    Tuple[str, bytes]
        File type + decompressed file

    """
    archive_file = gzip.decompress(binary)
    return "gz", {"gzip_file": archive_file} 
开发者ID:microsoft,项目名称:msticpy,代码行数:19,代码来源:base64unpack.py

示例8: main

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def main():
    # Install the library.
    os.makedirs(os.path.join(INSTALL_PATH, 'lib'), exist_ok=True)

    with open(LIBRARY_PATH, 'wb') as fd:
        fd.write(gzip.decompress(base64.b85decode(ENCODED_LIB_CONTENTS)))
        os.fchmod(fd.fileno(), 0o755)

    # Install the wrapper script.
    os.makedirs(os.path.join(INSTALL_PATH, 'bin'), exist_ok=True)

    with open(SCRIPT_PATH, 'w') as fd:
        fd.write(DROPBOX_WRAPPER_CONTENTS)
        os.fchmod(fd.fileno(), 0o755)

    print("Installed the library and the wrapper script at:\n  %s\n  %s" % (LIBRARY_PATH, SCRIPT_PATH))
    print("(To uninstall, simply delete them.)")

    # Check that the correct 'dropbox' is in the $PATH.
    result = subprocess.check_output(['which', 'dropbox']).decode().rstrip()
    if result != SCRIPT_PATH:
        print()
        print("You will need to fix your $PATH! Currently, %r takes precedence." % result) 
开发者ID:dimaryaz,项目名称:dropbox_ext4,代码行数:25,代码来源:fix_dropbox.py

示例9: getstream

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def getstream(file):

    # TODO -- gcs

    if file.startswith('http://') or file.startswith('https://'):
        response = requests.get(file)
        status_code = response.status_code    #TODO Do something with this

        if file.endswith('.gz'):
            content = response.content
            text = gzip.decompress(content).decode('utf-8')
        else:
            text = response.text
        f = io.StringIO(text)
        return text

    elif file.endswith('.gz'):
        f = gzip.open(file, mode='rt')

    else:
        f = open(file, encoding='UTF-8')

    return f 
开发者ID:igvteam,项目名称:igv-reports,代码行数:25,代码来源:feature.py

示例10: download_sifts_xml

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def download_sifts_xml(pdb_id, outdir='', force_rerun=False):
    """Download the SIFTS file for a PDB ID.

    Args:
        pdb_id (str): PDB ID
        outdir (str): Output directory, current working directory if not specified.
        force_rerun (bool): If the file should be downloaded again even if it exists

    Returns:
        str: Path to downloaded file

    """
    baseURL = 'ftp://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/'
    filename = '{}.xml.gz'.format(pdb_id.lower())

    outfile = op.join(outdir, filename.split('.')[0] + '.sifts.xml')

    if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
        response = urlopen(baseURL + filename)
        with open(outfile, 'wb') as f:
            f.write(gzip.decompress(response.read()))

    return outfile 
开发者ID:SBRG,项目名称:ssbio,代码行数:25,代码来源:pdb.py

示例11: __iter__

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def __iter__(self):
        keys = self._get_keys()
        if self.shuffle:
            random.shuffle(keys)
        for key in keys:
            chunk = json.loads(gzip.decompress(self.db[key]).decode('utf-8'))
            # discard long examples
            trunc_chunk = []
            lens = []
            for feat in chunk:
                if feat['input_len'] > self.max_len:
                    continue
                trunc_chunk.append(feat)
                lens.append(feat['input_len'])

            dataset = GPT2FeatureDataset(trunc_chunk, self.max_len)
            sampler = BucketSampler(lens, self.bucket_size, self.batch_size,
                                    droplast=True, shuffle=self.shuffle)
            loader = DataLoader(dataset, batch_sampler=sampler,
                                num_workers=0,  # can test multi-worker
                                collate_fn=GPT2FeatureDataset.collate)
            yield from loader 
开发者ID:microsoft,项目名称:DialoGPT,代码行数:24,代码来源:data_loader.py

示例12: download

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def download(self, mirror, meta):
        """Fetches compressed JSON data from NIST.

        Nothing is done if we have already seen the same version of
        the feed before.

        Returns True if anything has been loaded successfully.
        """
        url = mirror + self.download_uri
        _log.info('Loading %s', url)
        r = requests.get(url, headers=meta.headers_for(url))
        r.raise_for_status()
        if r.status_code == 200:
            _log.debug('Loading JSON feed "%s"', self.name)
            self.parse(gzip.decompress(r.content))
            meta.update_headers_for(url, r.headers)
            return True
        else:
            _log.debug('Skipping JSON feed "%s" (%s)', self.name, r.reason)
            return False 
开发者ID:flyingcircusio,项目名称:vulnix,代码行数:22,代码来源:nvd.py

示例13: raw_decode

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def raw_decode(cls, data, content_encoding=None):
        content_encoding = ContentEncoding.of(content_encoding)
        if content_encoding.is_gzip:
            try:
                data = gzip.decompress(data)
            except (ValueError, TypeError):
                raise ActorMessageDecodeError('gzip decompress failed')
        try:
            if content_encoding.is_json:
                data = json.loads(data.decode('utf-8'))
            else:
                data = msgpack.unpackb(data, raw=False)
        except json.JSONDecodeError:
            raise ActorMessageDecodeError('json decode failed')
        except msgpack.UnpackException:
            raise ActorMessageDecodeError('msgpack decode failed')
        return data 
开发者ID:anyant,项目名称:rssant,代码行数:19,代码来源:message.py

示例14: get_feed_content_divided_to_lines

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def get_feed_content_divided_to_lines(self, url, raw_response):
        """Fetch feed data and divides its content to lines

        Args:
            url: Current feed's url.
            raw_response: The raw response from the feed's url.

        Returns:
            List. List of lines from the feed content.
        """
        if self.feed_url_to_config and self.feed_url_to_config.get(url).get('is_zipped_file'):  # type: ignore
            response_content = gzip.decompress(raw_response.content)
        else:
            response_content = raw_response.content

        return response_content.decode(self.encoding).split('\n') 
开发者ID:demisto,项目名称:content,代码行数:18,代码来源:CSVFeedApiModule.py

示例15: content

# 需要导入模块: import gzip [as 别名]
# 或者: from gzip import decompress [as 别名]
def content(self):
        if self._content:
            return self._content
        encode = self.rep.msg.get('content-encoding', None)
        try:
            body = self.rep.read()
        except socket.timeout:
            body = b''
        if encode == 'gzip':
            body = gzip.decompress(body)
        elif encode == 'deflate':
            try:
                body = zlib.decompress(body, -zlib.MAX_WBITS)
            except:
                body = zlib.decompress(body)
        # redirect = self.rep.msg.get('location', None)   # handle 301/302
        self._content = body
        return body 
开发者ID:boy-hack,项目名称:hack-requests,代码行数:20,代码来源:HackRequests.py


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