Пример #1
0
 def attr_matches(self, text):
     """Compute matches when text contains a dot."""
     line = self.get_line_buffer()
     if line == text:
         # at start of line, special handling for iraf.xxx and
         # taskname.xxx
         fields = text.split(".")
         if fields[0] == "":
             # line starts with dot, look in executive commands
             return self.executive_matches(text)
         elif fields[0] == "iraf":
             return self.taskdot_matches(fields)
         elif iraf.getTask(fields[0], found=1):
             # include both eval results and task. matches
             fields.insert(0, 'iraf')
             matches = self.taskdot_matches(fields)
             try:
                 matches.extend(Completer.attr_matches(self, text))
             except KeyboardInterrupt:
                 raise
             except:
                 pass
             return matches
         else:
             return Completer.attr_matches(self, text)
     else:
         # Check first character following initial alphabetic string
         # If next char is alphabetic (or null) use filename matches
         # Otherwise use matches from Python dictionaries
         # XXX need to make this consistent with the other places
         # XXX where same tests are done
         m = self.taskpat.match(line)
         if m is None or keyword.iskeyword(m.group(1)):
             fields = text.split(".")
             if fields[0] == "iraf":
                 return self.taskdot_matches(fields)
             else:
                 return Completer.attr_matches(self, text)
         else:
             # XXX Could try to match pset.param keywords too?
             lt = len(line) - len(text)
             return self.filename_matches(text, line[:lt])
 def attr_matches(self, text):
     """Compute matches when text contains a dot."""
     line = self.get_line_buffer()
     if line == text:
         # at start of line, special handling for iraf.xxx and
         # taskname.xxx
         fields = string.split(text,".")
         if fields[0] == "":
             # line starts with dot, look in executive commands
             return self.executive_matches(text)
         elif fields[0] == "iraf":
             return self.taskdot_matches(fields)
         elif iraf.getTask(fields[0], found=1):
             # include both eval results and task. matches
             fields.insert(0, 'iraf')
             matches = self.taskdot_matches(fields)
             try:
                 matches.extend(Completer.attr_matches(self,text))
             except KeyboardInterrupt:
                 raise
             except:
                 pass
             return matches
         else:
             return Completer.attr_matches(self,text)
     else:
         # Check first character following initial alphabetic string
         # If next char is alphabetic (or null) use filename matches
         # Otherwise use matches from Python dictionaries
         #XXX need to make this consistent with the other places
         #XXX where same tests are done
         m = self.taskpat.match(line)
         if m is None or keyword.iskeyword(m.group(1)):
             fields = string.split(text,".")
             if fields[0] == "iraf":
                 return self.taskdot_matches(fields)
             else:
                 return Completer.attr_matches(self,text)
         else:
             #XXX Could try to match pset.param keywords too?
             lt = len(line)-len(text)
             return self.filename_matches(text, line[:lt])
Пример #3
0
class DefaultMatcher(AbstractMatcher):
    """Default matcher: delegate to standard's `rlcompleter.Completer`` class
    """

    def __init__(self, local_ctx):
        self.completer = Completer(local_ctx)

    def possible_matches(self, text):
        if "." in text:
            return self.completer.attr_matches(text)
        else:
            return self.completer.global_matches(text)
Пример #4
0
 def tabComplete(self):
     try:
         from rlcompleter import Completer
         c = Completer(self.namespace)
         cmd = self.getCommand()
         if "." in cmd:
             matches = c.attr_matches(cmd)
         else:
             matches = c.global_matches(cmd)
         if len(matches) == 1:
             cmd = matches[0]
         else:
             self.appendPlainText("\t".join(matches))
         self.newPrompt()
         self.setCommand(cmd)
     except ImportError, e:
         log.error(e)
Пример #5
0
 def tab_complete(self):
     try:
         from rlcompleter import Completer
         c = Completer(self.namespace)
         cmd = self.getCommand()
         if "." in cmd:
             matches = c.attr_matches(cmd)
         else:
             matches = c.global_matches(cmd)
         if len(matches) == 1:
             cmd = matches[0]
         else:
             self.appendPlainText("\t".join(matches))
         self.newPrompt()
         self.setCommand(cmd)
     except ImportError, e:
         log(e)
Пример #6
0
    def attr_matches(self, text):
        """
        Compute matches when text contains a dot.
        """
        matches = []
        for name in Completer.attr_matches(self, text):
            if name.endswith("__roles__"):
                continue
            component = name.split('.')[-1]
            if component in self.ignored_names:
                continue
            ignore = False
            for prefix in self.ignored_prefixes:
                if component.startswith(prefix):
                    ignore = True
                    break

            if not ignore:
                matches.append(name)

        return matches
Пример #7
0
    def handle_TAB1(self):
        head_line, tail_line = self.currentLineBuffer()
        search_line = head_line

        completer = Completer(self.namespace)

        def find_term(line):
            chrs = []
            attr = False
            for c in reversed(line):
                if c == '.':
                    attr = True
                if not c.isalnum() and c not in ('_', '.'):
                    break
                chrs.insert(0, c)
            return ''.join(chrs), attr

        search_term, attrQ = find_term(search_line)

        if not search_term:
            return manhole.Manhole.handle_TAB(self)

        if attrQ:
            matches = completer.attr_matches(search_term)
            matches = list(set(matches))
            matches.sort()
        else:
            matches = completer.global_matches(search_term)

        def same(*args):
            if len(set(args)) == 1:
                return args[0]
            return False

        def progress(rem):
            letters = []
            while True:
                letter = same(*[elm.pop(0) for elm in rem if elm])
                if letter:
                    letters.append(letter)
                else:
                    return letters

        if matches is not None:
            rem = [list(s.partition(search_term)[2]) for s in matches]
            more_letters = progress(rem)
#            print 'LEN MATCHES', len(matches), more_letters
#            if len(matches) == 1:
#                length = len(search_line)
#                self.lineBuffer = self.lineBuffer[:-length]
#                self.lineBuffer.extend([matches[0]]+more_letters)
#                self.lineBufferIndex = len(self.lineBuffer)
            if len(matches) > 1:
                match_str = "%s \t\t" * len(matches) % tuple(matches)
                match_rows = text.greedyWrap(match_str)
#                line = self.lineBuffer
                self.terminal.nextLine()
                self.terminal.saveCursor()
                for row in match_rows:
                    self.addOutput(row, True)
                if tail_line:
                    self.terminal.cursorBackward(len(tail_line))
                    self.lineBufferIndex -= len(tail_line)
#            self.addOutput("".join(more_letters), True)
            self._deliverBuffer(more_letters)