'Sort the list based on dependancies.
@return: The sorted items.
@rtype: list'

def sort(self):

    self.sorted = list()
    self.pushed = set()
    for item in self.unsorted:
        popped = []
        self.push(item)
        while len(self.stack):
            try:
                top = self.top()
                ref = top[1].next()
                refd = self.index.get(ref)
                if (refd is None):
                    log.debug('"%s"    not    found,    skipped', Repr(ref))
                    continue
                self.push(refd)
            except StopIteration:
                popped.append(self.pop())
                continue
        for p in popped:
            self.sorted.append(p)
    self.unsorted = self.sorted
    return self.sorted
