def scanPredicate(self, predicate, maxChars=0):
        chars = []
        countChars = 0
        while True:
            if (maxChars != 0 and countChars >= maxChars):
                break
            ch = self.getch()
            if ch != '' and predicate(ch):
                chars.append(ch)
                countChars += 1
            else:
                self.ungetch(ch)
                break
        return ''.join(chars)
More DRY.. we were basically calling this on every IMAP command
dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/maya/site-packages/pymel-1.0.3/pymel/util/scanf.py/CharacterBuffer.scanPredicate--crossover with--dataset/ETHPy150Open scanner/asimap/asimap/client.py/BaseClientHandler.debug_log_cmd