本文整理匯總了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