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


Python Pack.from_objects方法代码示例

本文整理汇总了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))
开发者ID:Lutger,项目名称:fuzzballflux,代码行数:14,代码来源:test_pack.py

示例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())
开发者ID:sid0,项目名称:dulwich,代码行数:14,代码来源:test_pack.py

示例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())
开发者ID:sid0,项目名称:dulwich,代码行数:17,代码来源:test_pack.py

示例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)
开发者ID:asenchi,项目名称:dulwich,代码行数:28,代码来源:object_store.py

示例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())
开发者ID:TDC-bob,项目名称:dulwich-py3k,代码行数:15,代码来源:test_pack.py

示例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())
开发者ID:TDC-bob,项目名称:dulwich-py3k,代码行数:18,代码来源:test_pack.py

示例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))
开发者ID:PKRoma,项目名称:dulwich,代码行数:21,代码来源:swift.py


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