本文整理汇总了Python中pygments.lexers.ClassNotFound方法的典型用法代码示例。如果您正苦于以下问题:Python lexers.ClassNotFound方法的具体用法?Python lexers.ClassNotFound怎么用?Python lexers.ClassNotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.lexers
的用法示例。
在下文中一共展示了lexers.ClassNotFound方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_lexer
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import ClassNotFound [as 别名]
def _get_lexer(self, lang):
if lang.lower() == 'sql':
return get_lexer_by_name('postgresql', **self.options)
tries = [lang]
if lang.startswith('pl'):
tries.append(lang[2:])
if lang.endswith('u'):
tries.append(lang[:-1])
if lang.startswith('pl') and lang.endswith('u'):
tries.append(lang[2:-1])
for l in tries:
try:
return get_lexer_by_name(l, **self.options)
except ClassNotFound:
pass
else:
# TODO: better logging
# print >>sys.stderr, "language not found:", lang
return None
示例2: _get_lexer
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import ClassNotFound [as 别名]
def _get_lexer(self, lang):
if lang.lower() == 'sql':
return get_lexer_by_name('postgresql', **self.options)
tries = [lang]
if lang.startswith('pl'):
tries.append(lang[2:])
if lang.endswith('u'):
tries.append(lang[:-1])
if lang.startswith('pl') and lang.endswith('u'):
tries.append(lang[2:-1])
for lx in tries:
try:
return get_lexer_by_name(lx, **self.options)
except ClassNotFound:
pass
else:
# TODO: better logging
# print >>sys.stderr, "language not found:", lang
return None
示例3: get_lexer_for_file
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import ClassNotFound [as 别名]
def get_lexer_for_file(filename):
ext = os.path.splitext(filename)[1]
try:
lexer = lexers.get_lexer_for_filename(filename)
except lexers.ClassNotFound:
if ext == '.kv':
lexer = KivyLexer()
else:
lexer = lexers.TextLexer()
# print('found {} for {}'.format(lexer, filename))
return lexer