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


Python unpack.unpack_archive函数代码示例

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


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

示例1: testExtractIllegal

	def testExtractIllegal(self):
		try:
			with open('HelloWorld.tgz', 'rb') as stream:
				unpack.unpack_archive('ftp://foo/file.tgz', stream, self.tmpdir, extract = 'Hello`World`')
			assert False
		except SafeException as ex:
			assert 'Illegal' in str(ex)
开发者ID:dabrahams,项目名称:0install,代码行数:7,代码来源:testunpack.py

示例2: testNonAscii

    def testNonAscii(self):
        mydir = os.path.join(self.tmpdir, "unicode")
        os.mkdir(mydir)
        with open("unicode.tar.gz", "rb") as stream:
            unpack.unpack_archive("ftp://foo/file.tgz", stream, self.tmpdir)
        self.assertEqual(
            [
                s.decode("utf-8")
                for s in [
                    b"D /unicode",
                    b"D /unicode/test-unic\xcc\xa7\xc3\xb8\xc3\xb0e\xcc\x88",
                    b"F c1c727274876ed5915c75a907131b8462cfdd5ba278140067dc80a2bcba033d6 1377477018 14 file",
                ]
            ],
            list(manifest.generate_manifest(self.tmpdir, alg="sha256")),
        )

        self.assertEqual(
            [
                s.decode("utf-8")
                for s in [
                    b"D /unicode",
                    b"D /unicode/test-unic\xcc\xa7\xc3\xb8\xc3\xb0e\xcc\x88",
                    b"F 5f1ff6172591102593950d1ae6c4a78709b1c44c 1377477018 14 file",
                ]
            ],
            list(manifest.generate_manifest(self.tmpdir, alg="sha1new")),
        )
开发者ID:rammstein,项目名称:0install,代码行数:28,代码来源:testmanifest.py

示例3: testBadExt

 def testBadExt(self):
     try:
         with open("HelloWorld.tgz", "rb") as stream:
             unpack.unpack_archive("ftp://foo/file.foo", stream, self.tmpdir)
         assert False
     except SafeException as ex:
         assert "Unknown extension" in str(ex)
开发者ID:res2k,项目名称:0install,代码行数:7,代码来源:testunpack.py

示例4: testExtractIllegal

 def testExtractIllegal(self):
     try:
         with open("HelloWorld.tgz", "rb") as stream:
             unpack.unpack_archive("ftp://foo/file.tgz", stream, self.tmpdir, extract="Hello`World`")
         assert False
     except SafeException as ex:
         assert "Illegal" in str(ex)
开发者ID:res2k,项目名称:0install,代码行数:7,代码来源:testunpack.py

示例5: testBadExt

	def testBadExt(self):
		try:
			with open('HelloWorld.tgz', 'rb') as stream:
				unpack.unpack_archive('ftp://foo/file.foo', stream, self.tmpdir)
			assert False
		except SafeException as ex:
			assert 'Unknown extension' in str(ex)
开发者ID:dabrahams,项目名称:0install,代码行数:7,代码来源:testunpack.py

示例6: fetch

def fetch(url, base, filename, dest, extract=None, type=None, local_file=None):
	mode = 'w+' if local_file is None else 'r'
	with open(local_file or os.path.join(base, filename), mode) as data:
		if local_file is None:
			log.info("downloading %s -> %s" % (url, os.path.join(base, filename)))
			with contextlib.closing(urllib2.urlopen(url)) as stream:
				while True:
					chunk = stream.read(1024)
					if not chunk: break
					data.write(chunk)
			data.seek(0)
		os.makedirs(os.path.join(base, dest))
		unpack.unpack_archive(url, data = data, destdir = os.path.join(base, dest), extract=extract, type=type)
开发者ID:timbertson,项目名称:0downstream,代码行数:13,代码来源:archive.py

示例7: testExtractFails

 def testExtractFails(self):
     stderr = os.dup(2)
     try:
         null = os.open("/dev/null", os.O_WRONLY)
         os.close(2)
         os.dup2(null, 2)
         try:
             unpack.unpack_archive("ftp://foo/file.tgz", file("HelloWorld.tgz"), self.tmpdir, extract="HelloWorld2")
             assert False
         except SafeException, ex:
             if "Failed to extract" not in str(ex) and "Unable to find" not in str(ex):  # GNU tar  # Python tar
                 raise ex
     finally:
         os.dup2(stderr, 2)
开发者ID:pombredanne,项目名称:zero-install,代码行数:14,代码来源:testunpack.py

示例8: testExtractFails

	def testExtractFails(self):
		stderr = os.dup(2)
		try:
			null = os.open(os.devnull, os.O_WRONLY)
			os.close(2)
			os.dup2(null, 2)
			try:
				unpack.unpack_archive('ftp://foo/file.tgz', open('HelloWorld.tgz'), self.tmpdir, extract = 'HelloWorld2')
				assert False
			except SafeException as ex:
				if ('Failed to extract' not in str(ex) and	# GNU tar
				    'Unable to find' not in str(ex)):		# Python tar
					raise ex
		finally:
			os.dup2(stderr, 2)
开发者ID:dabrahams,项目名称:zeroinstall,代码行数:15,代码来源:testunpack.py

示例9: handle

def handle(config, options, args):
	"""@type args: [str]"""
	if len(args) == 1:
		extract = None
	elif len(args) == 2:
		extract = args[1]
	else:
		raise UsageError()

	source = args[0]
	alg = manifest.algorithms.get(options.algorithm or 'sha1new', None)
	if alg is None:
		raise SafeException(_('Unknown algorithm "%s"') % alg)

	show_manifest = bool(options.manifest)
	show_digest = bool(options.digest) or not show_manifest

	def do_manifest(d):
		if extract is not None:
			d = os.path.join(d, extract)
		digest = alg.new_digest()
		for line in alg.generate_manifest(d):
			if show_manifest:
				print(line)
			digest.update((line + '\n').encode('utf-8'))
		if show_digest:
			print(alg.getID(digest))

	if os.path.isdir(source):
		if extract is not None:
			raise SafeException("Can't use extract with a directory")
		do_manifest(source)
	else:
		data = None
		tmpdir = tempfile.mkdtemp()
		try:
			data = open(args[0], 'rb')
			unpack.unpack_archive(source, data, tmpdir, extract)
			do_manifest(tmpdir)
		finally:
			support.ro_rmtree(tmpdir)
			if data:
				data.close()
开发者ID:AlexanderRyzhko,项目名称:0install-TUF,代码行数:43,代码来源:digest.py

示例10: testGem

	def testGem(self):
		unpack.unpack_archive('ftp://foo/file.gem', open('hello-0.1.gem'), self.tmpdir)
		self.assert_manifest('sha1new=fbd4827be7a18f9821790bdfd83132ee60d54647')
开发者ID:dabrahams,项目名称:zeroinstall,代码行数:3,代码来源:testunpack.py

示例11: testRPM

	def testRPM(self):
		unpack.unpack_archive('ftp://foo/file.rpm', open('dummy-1-1.noarch.rpm'), self.tmpdir)
		self.assert_manifest('sha1=7be9228c8fe2a1434d4d448c4cf130e3c8a4f53d')
开发者ID:dabrahams,项目名称:zeroinstall,代码行数:3,代码来源:testunpack.py

示例12: testDeb

	def testDeb(self):
		unpack.unpack_archive('ftp://foo/file.deb', open('dummy_1-1_all.deb'), self.tmpdir)
		self.assert_manifest('sha1new=2c725156ec3832b7980a3de2270b3d8d85d4e3ea')
开发者ID:dabrahams,项目名称:zeroinstall,代码行数:3,代码来源:testunpack.py

示例13: testExtractZip

 def testExtractZip(self):
     with open("HelloWorld.zip", "rb") as stream:
         unpack.unpack_archive("ftp://foo/file.zip", stream, self.tmpdir, extract="HelloWorld")
     self.assert_manifest("sha1=3ce644dc725f1d21cfcf02562c76f375944b266a")
开发者ID:res2k,项目名称:0install,代码行数:4,代码来源:testunpack.py

示例14: testExtractIllegal

 def testExtractIllegal(self):
     try:
         unpack.unpack_archive("ftp://foo/file.tgz", file("HelloWorld.tgz"), self.tmpdir, extract="Hello`World`")
         assert False
     except SafeException, ex:
         assert "Illegal" in str(ex)
开发者ID:pombredanne,项目名称:zero-install,代码行数:6,代码来源:testunpack.py

示例15: testTbz

 def testTbz(self):
     unpack.unpack_archive("ftp://foo/file.tar.bz2", file("HelloWorld.tar.bz2"), self.tmpdir)
     self.assert_manifest("sha1=3ce644dc725f1d21cfcf02562c76f375944b266a")
开发者ID:pombredanne,项目名称:zero-install,代码行数:3,代码来源:testunpack.py


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