Beispiel #1
0
 def testFormatString(self):
     oldPager = os.environ.pop('PAGER', '')
     # test that italic formatting uses reverse video
     self.assertEquals(explain._formatString('I{italic}'),
         '\x1b[7mitalic\x1b[27m')
     # test that constant width formatting uses underscores
     self.assertEquals(explain._formatString('C{cw}'),
         '\x1b[4mcw\x1b[24m')
     # test that bold formatting uses bold
     self.assertEquals(explain._formatString('B{foo}'),
         '\x1b[1mfoo\x1b[21m')
     # test that formatting stacks
     self.assertEquals(explain._formatDocString('C{B{foo}}'),
         '\x1b[4m\x1b[1mfoo\x1b[21m\x1b[24m')
     # inner bold is erased by outer bold because CSR codes do not nest
     self.assertEquals(explain._formatDocString('B{C{B{foo}}}'),
         '\x1b[1m\x1b[4mfoo\x1b[24m\x1b[21m')
     # test that bold text is not re-bolded
     self.assertEquals(explain._formatString('B{\x1b[1mfoo\x1b[21m}'),
             '\x1b[1mfoo\x1b[21m')
     self.assertEquals(explain._formatDocString('B{B{foo}}'),
             '\x1b[1mfoo\x1b[21m')
     os.environ['PAGER'] = oldPager
Beispiel #2
0
    def _getParserFlags(self, thisCommand):
        flags = mainhandler.MainHandler._getParserFlags(self, thisCommand)

        # If thisCommand has no 'description' attribute, clean up epydoc
        # formatting from the doc string and set it as the description.
        if not hasattr(thisCommand, 'description') or \
           thisCommand.description is None:
            docString = thisCommand.__doc__ or ''
            docStringRe = re.compile('[A-Z]\{[^{}]*\}')
            srch = re.search(docStringRe, docString)
            while srch:
                oldString = srch.group()
                newString = explain._formatString(oldString)
                docString = docString.replace(oldString, newString)
                srch = re.search(docStringRe, docString)
            # override the description returned from the super method with
            # this new one.
            flags['description'] = docString

        return flags