Пример #1
0
    def keys_dict(self):
        fd = self._fd
        index_start, index_len, data_len = self._check_magic(fd)
        data_start = index_start + index_len
        keys_dict = OrderedDict()
        key_rewrite = self._reading_key_rewrites.get
        while index_len:
            key_len = struct.unpack(">L", fd.read(4))[0]
            key = fd.read(key_len)
            if compatibility.is_py3k:
                key = key.decode('ascii')
            if len(key) != key_len:
                raise MalformedXpak(
                    "tried reading key %i of len %i, but hit EOF" %
                    (len(keys_dict) + 1, key_len))
            try:
                offset, data_len = struct.unpack(">LL", fd.read(8))
            except struct.error:
                raise_from(
                    MalformedXpak(
                        "key %i, tried reading data offset/len but hit EOF" %
                        (len(keys_dict) + 1)))
            key = key_rewrite(key, key)
            keys_dict[key] = (data_start + offset, data_len,
                              compatibility.is_py3k
                              and not key.startswith("environment"))
            index_len -= (key_len + 12
                          )  # 12 for key_len, offset, data_len longs

        return keys_dict
Пример #2
0
    def setUp(self):
        self.d1, self.d2 = {}, {}
        for key, ver in self.tree1_pkgs:
            cat, pkg = key.rsplit("/", 1)
            self.d1.setdefault(cat, {}).setdefault(pkg, []).extend(ver)
        for key, ver in self.tree2_pkgs:
            cat, pkg = key.rsplit("/", 1)
            self.d2.setdefault(cat, {}).setdefault(pkg, []).extend(ver)

        self.d1 = OrderedDict((k, OrderedDict(self.d1[k].iteritems()))
            for k in sorted(self.d1, reverse=True))
        self.d2 = OrderedDict((k, OrderedDict(self.d2[k].iteritems()))
            for k in sorted(self.d2, reverse=True))
        self.tree1 = SimpleTree(self.d1)
        self.tree2 = SimpleTree(self.d2)
        self.ctree = self.kls(self.tree1, self.tree2)
Пример #3
0
    def test_it(self):
        o = OrderedDict((k, None) for k in xrange(10))
        for l, correct, skip in [
            (["asdf", ["asdf", "asdf"], 1,
              None], ["asdf", "asdf", "asdf", 1, None], basestring),
            ([o, 1, "fds"], [o, 1, "fds"], (basestring, OrderedDict)),
            ([o, 1, "fds"], range(10) + [1, "fds"], basestring),
            ("fds", ["fds"], basestring),
            ("fds", ["f", "d", "s"], int),
            ('', [''], basestring),
            (1, [1], int),
        ]:
            iterator = self.func(l, skip)
            self.assertEqual(list(iterator), correct)
            self.assertEqual([], list(iterator))
        # There is a small difference between the cpython and native
        # version: the cpython one raises immediately, for native we
        # have to iterate.
        def fail():
            return list(self.func(None))

        self.assertRaises(TypeError, fail)

        # Yes, no sane code does this, but even insane code shouldn't
        # kill the cpython version.
        iters = []
        iterator = self.func(iters)
        iters.append(iterator)
        self.assertRaises(ValueError, iterator.next)

        # Regression test: this was triggered through demandload.
        # **{} is there to explicitly force a dict.
        self.assertTrue(self.func((), **{}))
Пример #4
0
 def setUp(self):
     # we an orderreddict here specifically to trigger any sorter
     # related bugs
     d = {
         "dev-util": {
             "diffball": ["1.0", "0.7"],
             "bsdiff": ["0.4.1", "0.4.2"]
         },
         "dev-lib": {
             "fake": ["1.0", "1.0-r1"]
         }
     }
     self.repo = SimpleTree(
         OrderedDict((k, d[k]) for k in sorted(d, reverse=True)))