terminal.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:rxjavademo 作者: BaoBaoJianqiang 项目源码 文件源码
def __call__(self, *args):
        try:
            # Re-encode the cap, because tparm() takes a bytestring in Python
            # 3. However, appear to be a plain Unicode string otherwise so
            # concats work.
            #
            # We use *latin1* encoding so that bytes emitted by tparm are
            # encoded to their native value: some terminal kinds, such as
            # 'avatar' or 'kermit', emit 8-bit bytes in range 0x7f to 0xff.
            # latin1 leaves these values unmodified in their conversion to
            # unicode byte values. The terminal emulator will "catch" and
            # handle these values, even if emitting utf8-encoded text, where
            # these bytes would otherwise be illegal utf8 start bytes.
            parametrized = tparm(self.encode('latin1'), *args).decode('latin1')
            return (parametrized if self._normal is None else
                    FormattingString(parametrized, self._normal))
        except curses.error:
            # Catch "must call (at least) setupterm() first" errors, as when
            # running simply `nosetests` (without progressive) on nose-
            # progressive. Perhaps the terminal has gone away between calling
            # tigetstr and calling tparm.
            return u''
        except TypeError:
            # If the first non-int (i.e. incorrect) arg was a string, suggest
            # something intelligent:
            if len(args) == 1 and isinstance(args[0], basestring):
                raise TypeError(
                    'A native or nonexistent capability template received '
                    '%r when it was expecting ints. You probably misspelled a '
                    'formatting call like bright_red_on_white(...).' % args)
            else:
                # Somebody passed a non-string; I don't feel confident
                # guessing what they were trying to do.
                raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号