本文整理汇总了Python中pygments.lexer.Lexer.get_tokens方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.get_tokens方法的具体用法?Python Lexer.get_tokens怎么用?Python Lexer.get_tokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.get_tokens方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tokens
# 需要导入模块: from pygments.lexer import Lexer [as 别名]
# 或者: from pygments.lexer.Lexer import get_tokens [as 别名]
def get_tokens(self, text):
if isinstance(text, text_type):
# raw token stream never has any non-ASCII characters
text = text.encode('ascii')
if self.compress == 'gz':
import gzip
gzipfile = gzip.GzipFile('', 'rb', 9, BytesIO(text))
text = gzipfile.read()
elif self.compress == 'bz2':
import bz2
text = bz2.decompress(text)
# do not call Lexer.get_tokens() because we do not want Unicode
# decoding to occur, and stripping is not optional.
text = text.strip(b'\n') + b'\n'
for i, t, v in self.get_tokens_unprocessed(text):
yield t, v
示例2: get_tokens
# 需要导入模块: from pygments.lexer import Lexer [as 别名]
# 或者: from pygments.lexer.Lexer import get_tokens [as 别名]
def get_tokens(self, text):
if isinstance(text, str):
# raw token stream never has any non-ASCII characters
text = text.encode('ascii')
if self.compress == 'gz':
import gzip
gzipfile = gzip.GzipFile('', 'rb', 9, BytesIO(text))
text = gzipfile.read()
elif self.compress == 'bz2':
import bz2
text = bz2.decompress(text)
# do not call Lexer.get_tokens() because we do not want Unicode
# decoding to occur, and stripping is not optional.
text = text.strip(b'\n') + b'\n'
for i, t, v in self.get_tokens_unprocessed(text):
yield t, v