Example #1
0
 def get_results(self, query, collection=None):
     if self.lazy_finding:
         # debug.log(LazyArray((result for result in self.find(query, collection)))[0])
         # debug.log([result for result in self.find(query, collection)])
         return LazyArray(
             (result for result in self.find(query, collection)))
     else:
         return [result for result in self.find(query, collection)]
Example #2
0
    def __init__(self,
                 descriptors=None,
                 encoding="utf-8",
                 finder=None,
                 action_finder=None,
                 candidates=None,
                 actions=None,
                 query=None,
                 caret=None,
                 index=None):
        # initialization
        self.global_lock = threading.Lock()
        self.encoding = encoding

        if descriptors is None:
            self.stdin = sys.stdin
            self.stdout = sys.stdout
            self.stderr = sys.stderr
        else:
            self.stdin = descriptors["stdin"]
            self.stdout = descriptors["stdout"]
            self.stderr = descriptors["stderr"]

        if finder is None:
            finder = FinderMultiQueryString
        if action_finder is None:
            action_finder = FinderMultiQueryString

        self.actions = actions

        # wraps candidates (iterator)
        from percol.lazyarray import LazyArray
        self.candidates = LazyArray(candidates or [])
        self.has_no_candidate = self.candidates.has_nth_value(0)
        self.has_only_one_candidate = self.candidates.has_nth_value(
            0) and not self.candidates.has_nth_value(1)

        # create model
        self.model_candidate = SelectorModel(percol=self,
                                             collection=self.candidates,
                                             finder=finder,
                                             query=query,
                                             caret=caret,
                                             index=index)
        self.model_action = SelectorModel(
            percol=self,
            collection=[action.desc for action in actions],
            finder=action_finder)
        self.model = self.model_candidate