def _search(self, direction, partial):
        try:
            if (self.lastcommand != self.history_search_forward and
                    self.lastcommand != self.history_search_backward):
                self.query = ''.join(partial[0:partial.point].get_line_text())
            hcstart=max(self.history_cursor,0) 
            hc = self.history_cursor + direction
            while (direction < 0 and hc >= 0) or (direction > 0 and hc < len(self.history)):
                h = self.history[hc]
                if not self.query:
                    self.history_cursor = hc
                    result=lineobj.ReadLineTextBuffer(h,point=len(h.get_line_text()))
                    return result
                elif (h.get_line_text().startswith(self.query) and (h != partial.get_line_text())):
                    self.history_cursor = hc
                    result=lineobj.ReadLineTextBuffer(h,point=partial.point)
                    return result
                hc += direction
            else:
                if len(self.history)==0:
                    pass 
                elif hc>=len(self.history) and not self.query:
                    self.history_cursor=len(self.history)
                    return lineobj.ReadLineTextBuffer("",point=0)
                elif self.history[max(min(hcstart,len(self.history)-1),0)].get_line_text().startswith(self.query) and self.query:
                    return lineobj.ReadLineTextBuffer(self.history[max(min(hcstart,len(self.history)-1),0)],point=partial.point)
                else:                
                    return lineobj.ReadLineTextBuffer(partial,point=partial.point)
                return lineobj.ReadLineTextBuffer(self.query,point=min(len(self.query),partial.point))
        except __HOLE__:
            raise
dataset/ETHPy150Open deanhiller/databus/webapp/play1.3.x/python/Lib/site-packages/pyreadline/lineeditor/history.py/LineHistory._search