Exemplo n.º 1
0
class ReportRegistry(object):
    def __init__(self, reps):
        self.reps = reps
        self.prefix_tree = PrefixTree(reps.keys())

    def get(self, prefix):
        candidates = self.prefix_tree.from_prefix(prefix)
        if len(candidates) == 1:
            return self.reps[candidates[0]]

    def __getitem__(self, name):
        return self.reps[name]

    def add(self, name, factory):
        if name in self.reps:
            raise Exception.new("Report %s already exists" % name)
        self.reps[name] = factory
        self.prefix_tree.insert(name)
Exemplo n.º 2
0
 def __init__(self, reps):
     self.reps = reps
     self.prefix_tree = PrefixTree(reps.keys())