Pygments 0.6 downgrade.

This commit is contained in:
Martin Mahner 2011-06-02 23:36:57 +02:00
parent 2734acb627
commit db0e060b30

View file

@ -1,7 +1,5 @@
from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, PythonLexer from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, PythonLexer
from pygments.styles import get_all_styles
from pygments.formatters import HtmlFormatter from pygments.formatters import HtmlFormatter
from pygments.util import ClassNotFound
from pygments import highlight from pygments import highlight
from django.utils.html import escape from django.utils.html import escape
@ -41,18 +39,18 @@ class NakedHtmlFormatter(HtmlFormatter):
def pygmentize(code_string, lexer_name=LEXER_DEFAULT): def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
try: try:
lexer = get_lexer_by_name(lexer_name) lexer = get_lexer_by_name(lexer_name)
except ClassNotFound: except ValueError:
logger.warning('Could not find lexer for name "%s"' % lexer_name) logger.warning('Could not find lexer for name "%s"' % lexer_name)
lexer = PythonLexer() lexer = PythonLexer()
try: try:
return highlight(code_string, lexer, NakedHtmlFormatter()) return highlight(code_string, lexer, NakedHtmlFormatter())
except TypeError: except TypeError:
logger.warning('Could not highlight code with lexer "%s"' % lexer_name) logger.warning('Could not highlight code with lexer "%s"' % lexer_name)
return escape(code_string) return escape(code_string)
def guess_code_lexer(code_string, default_lexer='unknown'): def guess_code_lexer(code_string, default_lexer='unknown'):
try: try:
return guess_lexer(code_string).name return guess_lexer(code_string).name
except ClassNotFound: except ValueError:
return default_lexer return default_lexer