Exemplo n.º 1
0
 def gen_sentences(self, tokens, aliases=None):
     if aliases is None:
         aliases = {}
     for sentence in self._gen_sentences(tokens):
         if sentence[0] in aliases:
             new_tokens = Program(aliases[sentence[0]]).gen_tokens()
             sentence[0:1] = list(new_tokens)
         yield transform(Sentence(sentence), self.transforms)
Exemplo n.º 2
0
    def complete(self, word, state):
        """Return the next possible completion for ``word``.

        This is called successively with ``state == 0, 1, 2, ...`` until it
        returns ``None``.
        
        The completion should begin with ``word``.

        :param word: the word to complete
        :param state: an int, used to iterate over the choices
        """
        try:
            import rl
            # TODO: doing this manually right now, but may make sense to exploit
            rl.completion.suppress_append = True
        except ImportError:
            pass
        word = transform(word, self.transforms, word=True)
        try:
            match = self.get_matches(word)[state]
            return transform(match, self.transforms, word=True, inverse=True)
        except IndexError:
            return None
Exemplo n.º 3
0
def test_transform_inverse(transforms):
    text = "cd %s" % HOME
    assert transform(text, transforms, inverse=True) == "home"
Exemplo n.º 4
0
def test_transform_id(transforms):
    text = "home"
    actual = transform(transform(text, transforms), transforms, inverse=True)
    assert actual == text
Exemplo n.º 5
0
def test_transform(transforms):
    text = "home"
    assert transform(text, transforms) == "cd %s" % HOME