当前位置: 首页>>代码示例>>Python>>正文


Python Token.Error方法代码示例

本文整理汇总了Python中pygments.token.Token.Error方法的典型用法代码示例。如果您正苦于以下问题:Python Token.Error方法的具体用法?Python Token.Error怎么用?Python Token.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.token.Token的用法示例。


在下文中一共展示了Token.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_tokens_aux

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def get_tokens_aux(self, index, text):
        while text:
            a, sep1, text = text.partition(self.left)
            if a:
                for i, t, v in self.lang.get_tokens_unprocessed(a):
                    yield index + i, t, v
                    index += len(a)
            if sep1:
                b, sep2, text = text.partition(self.right)
                if sep2:
                    yield index + len(sep1), Token.Escape, b
                    index += len(sep1) + len(b) + len(sep2)
                else:
                    yield index, Token.Error, sep1
                    index += len(sep1)
                    text = b 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:18,代码来源:latex.py

示例2: _getRole

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _getRole(self, matchedVars):
        """
        :param matchedVars:
        :return: NULL or the role's integer value
        """
        role = matchedVars.get(ROLE)
        if role is not None and role.strip() == '':
            role = NULL
        else:
            valid = Authoriser.isValidRoleName(role)
            if valid:
                role = Authoriser.getRoleFromName(role)
            else:
                self.print("Invalid role. Valid roles are: {}".
                           format(", ".join(map(lambda r: r.name, Roles))),
                           Token.Error)
                return False
        return role 
开发者ID:hyperledger-archives,项目名称:indy-client,代码行数:20,代码来源:cli.py

示例3: _addAttribToNym

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _addAttribToNym(self, nym, raw, enc, hsh):
        attrib = self.activeWallet.build_attrib(nym, raw, enc, hsh)
        # TODO: What is the purpose of this?
        # if nym != self.activeWallet.defaultId:
        #     attrib.dest = nym

        self.activeWallet.addAttribute(attrib)
        reqs = self.activeWallet.preparePending()
        req, = self.activeClient.submitReqs(*reqs)
        self.print("Adding attributes {} for {}".format(attrib.value, nym))

        def out(reply, error, *args, **kwargs):
            if error:
                self.print("Error: {}".format(error), Token.BoldOrange)
            else:
                self.print("Attribute added for nym {}".
                           format(reply[TARGET_NYM]), Token.BoldBlue)

        self.looper.loop.call_later(.2, self._ensureReqCompleted,
                                    req.key, self.activeClient, out) 
开发者ID:hyperledger-archives,项目名称:indy-client,代码行数:22,代码来源:cli.py

示例4: _getSchema

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _getSchema(self, nym, name, version):
        req = self.activeWallet.requestSchema(nym,name,version,sender=self.activeWallet.defaultId)
        self.activeClient.submitReqs(req)
        self.print("Getting schema {}".format(nym))

        def getSchema(reply, err, *args):
            try:
                if reply and reply[DATA]:
                    self.print(
                        "Found schema {}"
                        .format(reply[DATA]))
                else:
                    self.print("Schema not found")
            except:
                self.print('"data" must be in proper format', Token.Error)


        self.looper.loop.call_later(.2, self._ensureReqCompleted,
                                    req.key, self.activeClient, getSchema) 
开发者ID:hyperledger-archives,项目名称:indy-client,代码行数:21,代码来源:cli.py

示例5: format

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def format(self, tokensource, outfile):
        try:
            outfile.write(b'')
        except TypeError:
            raise TypeError('The raw tokens formatter needs a binary '
                            'output file')
        if self.compress == 'gz':
            import gzip
            outfile = gzip.GzipFile('', 'wb', 9, outfile)
            def write(text):
                outfile.write(text.encode())
            flush = outfile.flush
        elif self.compress == 'bz2':
            import bz2
            compressor = bz2.BZ2Compressor(9)
            def write(text):
                outfile.write(compressor.compress(text.encode()))
            def flush():
                outfile.write(compressor.flush())
                outfile.flush()
        else:
            def write(text):
                outfile.write(text.encode())
            flush = outfile.flush

        if self.error_color:
            for ttype, value in tokensource:
                line = "%s\t%r\n" % (ttype, value)
                if ttype is Token.Error:
                    write(colorize(self.error_color, line))
                else:
                    write(line)
        else:
            for ttype, value in tokensource:
                write("%s\t%r\n" % (ttype, value))
        flush() 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:38,代码来源:other.py

示例6: _getRole

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _getRole(self, matchedVars):
        role = matchedVars.get("role")
        validRoles = (SPONSOR, STEWARD)
        if role and role not in validRoles:
            self.print("Invalid role. Valid roles are: {}".
                       format(", ".join(validRoles)), Token.Error)
            return False
        return role 
开发者ID:sovrin-foundation,项目名称:old-sovrin,代码行数:10,代码来源:cli.py

示例7: _getNym

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _getNym(self, nym):
        identity = Identity(identifier=nym)
        req = self.activeWallet.requestIdentity(
            identity, sender=self.activeWallet.defaultId)
        self.activeClient.submitReqs(req)
        self.print("Getting nym {}".format(nym))

        def getNymReply(reply, err, *args):
            self.print("Transaction id for NYM {} is {}".
                       format(nym, reply[TXN_ID]), Token.BoldBlue)
            try:
                if reply[DATA]:
                    data=json.loads(reply[DATA])
                    if data:
                        idr = base58.b58decode(nym)
                        if data.get(VERKEY) is None:
                            if len(idr) == 32:
                                self.print(
                                    "Current verkey is same as identifier {}"
                                        .format(nym), Token.BoldBlue)
                            else:
                                self.print(
                                    "No verkey ever assigned to the identifier {}".
                                    format(nym), Token.BoldBlue)
                            return
                        if data.get(VERKEY) == '':
                            self.print("No active verkey found for the identifier {}".
                                       format(nym), Token.BoldBlue)
                        else:
                            self.print("Current verkey for NYM {} is {}".
                               format(nym, data[VERKEY]), Token.BoldBlue)
                else:
                    self.print("NYM {} not found".format(nym), Token.BoldBlue)
            except BaseException as e:
                self.print("Error during fetching verkey: {}".format(e),
                           Token.BoldOrange)

        self.looper.loop.call_later(.2, self._ensureReqCompleted,
                                    req.key, self.activeClient, getNymReply) 
开发者ID:sovrin-foundation,项目名称:old-sovrin,代码行数:41,代码来源:cli.py

示例8: _addNym

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _addNym(self, nym, role, newVerKey=None, otherClientName=None):
        idy = Identity(nym, verkey=newVerKey, role=role)
        try:
            self.activeWallet.addSponsoredIdentity(idy)
        except Exception as e:
            if e.args[0] == 'identifier already added':
                pass
            else:
                raise e
        reqs = self.activeWallet.preparePending()
        req, = self.activeClient.submitReqs(*reqs)
        printStr = "Adding nym {}".format(nym)

        if otherClientName:
            printStr = printStr + " for " + otherClientName
        self.print(printStr)

        def out(reply, error, *args, **kwargs):
            if error:
                self.print("Error: {}".format(error), Token.BoldBlue)
            else:
                self.print("Nym {} added".format(reply[TARGET_NYM]),
                           Token.BoldBlue)

        self.looper.loop.call_later(.2, self._ensureReqCompleted,
                                    req.key, self.activeClient, out)
        return True 
开发者ID:sovrin-foundation,项目名称:old-sovrin,代码行数:29,代码来源:cli.py

示例9: _sendNodeAction

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _sendNodeAction(self, matchedVars):
        if matchedVars.get('send_node') == 'send NODE':
            if not self.canMakeSovrinRequest:
                return True
            nym = matchedVars.get('dest_id')
            data = matchedVars.get('data').strip()
            try:
                data = ast.literal_eval(data)
                self._sendNodeTxn(nym, data)
            except:
                self.print('"data" must be in proper format', Token.Error)
            return True 
开发者ID:sovrin-foundation,项目名称:old-sovrin,代码行数:14,代码来源:cli.py

示例10: _sendPoolUpgAction

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _sendPoolUpgAction(self, matchedVars):
        if matchedVars.get('send_pool_upg') == 'send POOL_UPGRADE':
            if not self.canMakeSovrinRequest:
                return True
            name = matchedVars.get(NAME).strip()
            version = matchedVars.get(VERSION).strip()
            action = matchedVars.get(ACTION).strip()
            sha256 = matchedVars.get(SHA256).strip()
            timeout = matchedVars.get(TIMEOUT)
            schedule = matchedVars.get(SCHEDULE)
            if action == START:
                if not schedule:
                    self.print('{} need to be provided'.format(SCHEDULE),
                               Token.Error)
                    return True
                if not timeout:
                    self.print('{} need to be provided'.format(TIMEOUT),
                               Token.Error)
                    return True
            try:
                if schedule:
                    schedule = ast.literal_eval(schedule.strip())
            except:
                self.print('"schedule" must be in proper format', Token.Error)
                return True
            if timeout:
                timeout = int(timeout.strip())
            self._sendPoolUpgTxn(name, version, action, sha256,
                                 schedule=schedule, timeout=timeout)
            return True 
开发者ID:sovrin-foundation,项目名称:old-sovrin,代码行数:32,代码来源:cli.py

示例11: format

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def format(self, tokensource, outfile):
        try:
            outfile.write(b'')
        except TypeError:
            raise TypeError('The raw tokens formatter needs a binary '
                            'output file')
        if self.compress == 'gz':
            import gzip
            outfile = gzip.GzipFile('', 'wb', 9, outfile)

            def write(text):
                outfile.write(text.encode())
            flush = outfile.flush
        elif self.compress == 'bz2':
            import bz2
            compressor = bz2.BZ2Compressor(9)

            def write(text):
                outfile.write(compressor.compress(text.encode()))

            def flush():
                outfile.write(compressor.flush())
                outfile.flush()
        else:
            def write(text):
                outfile.write(text.encode())
            flush = outfile.flush

        if self.error_color:
            for ttype, value in tokensource:
                line = "%s\t%r\n" % (ttype, value)
                if ttype is Token.Error:
                    write(colorize(self.error_color, line))
                else:
                    write(line)
        else:
            for ttype, value in tokensource:
                write("%s\t%r\n" % (ttype, value))
        flush() 
开发者ID:pygments,项目名称:pygments,代码行数:41,代码来源:other.py

示例12: test_closing_curly

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def test_closing_curly(lexer_bare):
    # This can be an Error token, but should not be a can't-pop-from-stack
    # exception.
    fragment = '}"a"\n'
    tokens = [
        (Token.Error, '}'),
        (Token.Name.Tag, '"a"'),
        (Token.Text, '\n'),
    ]
    assert list(lexer_bare.get_tokens(fragment)) == tokens 
开发者ID:pygments,项目名称:pygments,代码行数:12,代码来源:test_data.py

示例13: test_closing_curly_in_value

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def test_closing_curly_in_value(lexer_bare):
    fragment = '"": ""}\n'
    tokens = [
        (Token.Name.Tag, '""'),
        (Token.Punctuation, ':'),
        (Token.Text, ' '),
        (Token.Literal.String.Double, '""'),
        (Token.Error, '}'),
        (Token.Text, '\n'),
    ]
    assert list(lexer_bare.get_tokens(fragment)) == tokens 
开发者ID:pygments,项目名称:pygments,代码行数:13,代码来源:test_data.py

示例14: test_missing_body

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def test_missing_body(lexer):
    data = '@ARTICLE xxx'
    tokens = [
        (Token.Name.Class, u'@ARTICLE'),
        (Token.Text, u' '),
        (Token.Error, u'x'),
        (Token.Error, u'x'),
        (Token.Error, u'x'),
        (Token.Text, u'\n'),
    ]
    assert list(lexer.get_tokens(data)) == tokens 
开发者ID:pygments,项目名称:pygments,代码行数:13,代码来源:test_bibtex.py

示例15: _getNym

# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Error [as 别名]
def _getNym(self, nym):
        identity = Identity(identifier=nym)
        req = self.activeWallet.requestIdentity(
            identity, sender=self.activeWallet.defaultId)
        self.activeClient.submitReqs(req)
        self.print("Getting nym {}".format(nym))

        def getNymReply(reply, err, *args):
            try:
                if err:
                    self.print("Error: {}".format(err), Token.BoldOrange)
                    return

                if reply and reply[DATA]:
                    data=json.loads(reply[DATA])
                    if data:
                        idr = base58.b58decode(nym)
                        if data.get(VERKEY) is None:
                            if len(idr) == 32:
                                self.print(
                                    "Current verkey is same as identifier {}"
                                        .format(nym), Token.BoldBlue)
                            else:
                                self.print(
                                    "No verkey ever assigned to the identifier {}".
                                    format(nym), Token.BoldBlue)
                            return
                        if data.get(VERKEY) == '':
                            self.print("No active verkey found for the identifier {}".
                                       format(nym), Token.BoldBlue)
                        else:
                            self.print("Current verkey for NYM {} is {}".
                                       format(nym, data[VERKEY]), Token.BoldBlue)
                else:
                    self.print("NYM {} not found".format(nym), Token.BoldBlue)
            except BaseException as e:
                self.print("Error during fetching verkey: {}".format(e),
                           Token.BoldOrange)

        self.looper.loop.call_later(.2, self._ensureReqCompleted,
                                    req.key, self.activeClient, getNymReply) 
开发者ID:hyperledger-archives,项目名称:indy-client,代码行数:43,代码来源:cli.py


注:本文中的pygments.token.Token.Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。