Esempio n. 1
0
    def testCollateIterators(self):
        """Test basic collating"""
        indicies = map(index, [0, 1, 2, 3])
        helper = lambda i: indicies[i]

        makeiter1 = lambda: iter(indicies)
        makeiter2 = lambda: iter(map(helper, [0, 1, 3]))
        makeiter3 = lambda: iter(map(helper, [1, 2]))

        outiter = rorpiter.CollateIterators(makeiter1(), makeiter2())
        assert lazy.Iter.equal(
            outiter,
            iter([(indicies[0], indicies[0]), (indicies[1], indicies[1]),
                  (indicies[2], None), (indicies[3], indicies[3])]))

        assert lazy.Iter.equal(
            rorpiter.CollateIterators(makeiter1(), makeiter2(), makeiter3()),
            iter([(indicies[0], indicies[0], None),
                  (indicies[1], indicies[1], indicies[1]),
                  (indicies[2], None, indicies[2]),
                  (indicies[3], indicies[3], None)]))

        assert lazy.Iter.equal(
            rorpiter.CollateIterators(makeiter1(), iter([])),
            iter(map(lambda i: (i, None), indicies)))
        assert lazy.Iter.equal(
            iter(map(lambda i: (i, None), indicies)),
            rorpiter.CollateIterators(makeiter1(), iter([])))
Esempio n. 2
0
    def testCollateIterators(self):
        """Test basic collating"""
        indices = list(map(index, [0, 1, 2, 3]))

        helper = lambda i: indices[i]  # noqa: E731 use def instead of lambda
        makeiter1 = lambda: iter(indices
                                 )  # noqa: E731 use def instead of lambda
        makeiter2 = lambda: iter(map(helper, [0, 1, 3])
                                 )  # noqa: E731 use def instead of lambda
        makeiter3 = lambda: iter(map(helper, [1, 2])
                                 )  # noqa: E731 use def instead of lambda

        outiter = rorpiter.CollateIterators(makeiter1(), makeiter2())
        self.assertTrue(
            iter_equal(
                outiter,
                iter([(indices[0], indices[0]), (indices[1], indices[1]),
                      (indices[2], None), (indices[3], indices[3])])))

        self.assertTrue(
            iter_equal(
                rorpiter.CollateIterators(makeiter1(), makeiter2(),
                                          makeiter3()),
                iter([(indices[0], indices[0], None),
                      (indices[1], indices[1], indices[1]),
                      (indices[2], None, indices[2]),
                      (indices[3], indices[3], None)])))

        self.assertTrue(
            iter_equal(rorpiter.CollateIterators(makeiter1(), iter([])),
                       iter([(i, None) for i in indices])))
        self.assertTrue(
            iter_equal(iter([(i, None) for i in indices]),
                       rorpiter.CollateIterators(makeiter1(), iter([]))))
Esempio n. 3
0
 def join_iter(rorp_iter, wacl_iter):
     """Update a rorp iter by adding the information from acl_iter"""
     for rorp, wacl in rorpiter.CollateIterators(rorp_iter, wacl_iter):
         assert rorp, "Missing rorp for index {idx}.".format(idx=wacl.index)
         if not wacl:
             wacl = get_meta_object(rorp.index)
         rorp.set_win_acl(bytes(wacl))
         yield rorp
Esempio n. 4
0
 def join_iter(rorp_iter, acl_iter):
     """Update a rorp iter by adding the information from acl_iter"""
     for rorp, acl in rorpiter.CollateIterators(rorp_iter, acl_iter):
         assert rorp, ("Missing rorp for ACL index '{aidx}'.".format(
             aidx=acl.index))
         if not acl:
             acl = get_meta_object(rorp.index)
         rorp.set_acl(acl)
         yield rorp
Esempio n. 5
0
    def _iterate_patched_attr(self, attr_iter_list):
        """
        Return an iter of metadata rorps by combining the given iters

        The iters should be given as a list/tuple in reverse
        chronological order.  The earliest rorp in each iter will
        supercede all the later ones.
        """
        for meta_tuple in rorpiter.CollateIterators(*attr_iter_list):
            for i in range(len(meta_tuple) - 1, -1, -1):
                if meta_tuple[i]:
                    if meta_tuple[i].lstat():
                        yield meta_tuple[i]
                    break  # move to next index
            else:
                log.Log.FatalError("No valid metadata tuple in list")
Esempio n. 6
0
    def join_iter(rorp_iter, ea_iter):
        """Update a rorp iter by adding the information from ea_iter"""
        def _safe_str(cmd):
            """Transform bytes into string without risk of conversion error"""
            if isinstance(cmd, str):
                return cmd
            else:
                return str(cmd, errors='replace')

        for rorp, ea in rorpiter.CollateIterators(rorp_iter, ea_iter):
            assert rorp, ("Missing rorp for EA index '{eaidx}'.".format(
                eaidx=map(_safe_str, ea.index)))
            if not ea:
                ea = get_meta_object(rorp.index)
            rorp.set_ea(ea)
            yield rorp