File: queued_object.py

package info (click to toggle)
python-pyforge 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: python: 3,666; makefile: 12; sh: 7
file content (30 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from .queued_node import QueuedNode


class QueuedObject(QueuedNode):
    """Base object for all leafs in the call tree."""
    def __init__(self, caller_info):
        super(QueuedObject, self).__init__()
        self.caller_info = caller_info

    def matches(self, queue_object):
        """Returns True if the object matches queue_object. Implemented by derived classes."""
        raise NotImplementedError()  # pragma: no cover

    def describe(self):
        raise NotImplementedError()  # pragma: no cover

    def __repr__(self):
        return "<%s>" % self.describe()

    def __len__(self):
        return 1

    def pop_matching(self, queue_object):
        if not self.matches(queue_object):
            return None

        if self.get_parent():
            self.get_parent().discard_child(self)

        return self