本文整理汇总了Python中dulwich.pack.Pack.from_objects方法的典型用法代码示例。如果您正苦于以下问题:Python Pack.from_objects方法的具体用法?Python Pack.from_objects怎么用?Python Pack.from_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dulwich.pack.Pack
的用法示例。
在下文中一共展示了Pack.from_objects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_thin_from_file
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def test_thin_from_file(self):
test_sha = "1" * 40
def resolve(sha):
self.assertEqual(test_sha, sha)
return 3, "data"
path = os.path.join(self.datadir, "pack-%s.pack" % pack1_sha)
data = ThinPackData.from_file(resolve, open(path), os.path.getsize(path))
idx = self.get_pack_index(pack1_sha)
Pack.from_objects(data, idx)
self.assertEqual((None, 3, "data"), data.get_ref(test_sha))
示例2: test_checksum_mismatch
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def test_checksum_mismatch(self):
data = self.get_pack_data(pack1_sha)
index = self.get_pack_index(pack1_sha)
Pack.from_objects(data, index).check_length_and_checksum()
data._file.seek(0)
bad_file = BytesIO(data._file.read()[:-20] + ('\xff' * 20))
bad_data = PackData('', file=bad_file)
bad_pack = Pack.from_lazy_objects(lambda: bad_data, lambda: index)
self.assertRaises(ChecksumMismatch, lambda: bad_pack.data)
self.assertRaises(ChecksumMismatch, lambda:
bad_pack.check_length_and_checksum())
示例3: test_length_mismatch
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def test_length_mismatch(self):
data = self.get_pack_data(pack1_sha)
index = self.get_pack_index(pack1_sha)
Pack.from_objects(data, index).check_length_and_checksum()
data._file.seek(12)
bad_file = BytesIO()
write_pack_header(bad_file, 9999)
bad_file.write(data._file.read())
bad_file = BytesIO(bad_file.getvalue())
bad_data = PackData('', file=bad_file)
bad_pack = Pack.from_lazy_objects(lambda: bad_data, lambda: index)
self.assertRaises(AssertionError, lambda: bad_pack.data)
self.assertRaises(AssertionError,
lambda: bad_pack.check_length_and_checksum())
示例4: move_in_thin_pack
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def move_in_thin_pack(self, path):
"""Move a specific file containing a pack into the pack directory.
:note: The file should be on the same file system as the
packs directory.
:param path: Path to the pack file.
"""
data = PackData(path)
# Write index for the thin pack (do we really need this?)
temppath = os.path.join(self.pack_dir,
sha_to_hex(urllib2.randombytes(20))+".tempidx")
data.create_index_v2(temppath, self.get_raw)
p = Pack.from_objects(data, load_pack_index(temppath))
# Write a full pack version
temppath = os.path.join(self.pack_dir,
sha_to_hex(urllib2.randombytes(20))+".temppack")
write_pack(temppath, ((o, None) for o in p.iterobjects(self.get_raw)),
len(p))
pack_sha = load_pack_index(temppath+".idx").objects_sha1()
newbasename = os.path.join(self.pack_dir, "pack-%s" % pack_sha)
os.rename(temppath+".pack", newbasename+".pack")
os.rename(temppath+".idx", newbasename+".idx")
self._add_known_pack(newbasename)
示例5: test_checksum_mismatch
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def test_checksum_mismatch(self):
with self.get_pack_data(pack1_sha) as data:
index = self.get_pack_index(pack1_sha)
with Pack.from_objects(data, index) as p:
p.check_length_and_checksum()
data._file.seek(0)
with BytesIO(data._file.read()[:-20] + (b'\xff' * 20)) as bad_file:
with PackData('', file=bad_file) as bad_data:
with Pack.from_lazy_objects(lambda: bad_data, lambda: index) as bad_pack:
self.assertRaises(ChecksumMismatch, lambda: bad_pack.data)
self.assertRaises(ChecksumMismatch, lambda:
bad_pack.check_length_and_checksum())
示例6: test_length_mismatch
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def test_length_mismatch(self):
with self.get_pack_data(pack1_sha) as data:
index = self.get_pack_index(pack1_sha)
with Pack.from_objects(data, index) as p:
p.check_length_and_checksum()
data._file.seek(12)
with BytesIO() as bad_file:
write_pack_header(bad_file, 9999)
bad_file.write(data._file.read())
with BytesIO(bad_file.getvalue()) as badder_file:
with PackData('', file=badder_file) as bad_data:
with Pack.from_lazy_objects(lambda: bad_data, lambda: index) as bad_pack:
self.assertRaises(AssertionError, lambda: bad_pack.data)
self.assertRaises(AssertionError,
lambda: bad_pack.check_length_and_checksum())
示例7: pack_info_create
# 需要导入模块: from dulwich.pack import Pack [as 别名]
# 或者: from dulwich.pack.Pack import from_objects [as 别名]
def pack_info_create(pack_data, pack_index):
pack = Pack.from_objects(pack_data, pack_index)
info = {}
for obj in pack.iterobjects():
# Commit
if obj.type_num == Commit.type_num:
info[obj.id] = (obj.type_num, obj.parents, obj.tree)
# Tree
elif obj.type_num == Tree.type_num:
shas = [(s, n, not stat.S_ISDIR(m)) for
n, m, s in obj.iteritems() if not S_ISGITLINK(m)]
info[obj.id] = (obj.type_num, shas)
# Blob
elif obj.type_num == Blob.type_num:
info[obj.id] = None
# Tag
elif obj.type_num == Tag.type_num:
info[obj.id] = (obj.type_num, obj.object[1])
return zlib.compress(json_dumps(info))