diff --git a/pastebin/apps/dpaste/highlight.py b/pastebin/apps/dpaste/highlight.py index 2353e88..0883c0f 100644 --- a/pastebin/apps/dpaste/highlight.py +++ b/pastebin/apps/dpaste/highlight.py @@ -1,7 +1,5 @@ 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.util import ClassNotFound from pygments import highlight from django.utils.html import escape @@ -41,18 +39,18 @@ class NakedHtmlFormatter(HtmlFormatter): def pygmentize(code_string, lexer_name=LEXER_DEFAULT): try: lexer = get_lexer_by_name(lexer_name) - except ClassNotFound: - logger.warning('Could not find lexer for name "%s"' % lexer_name) + except ValueError: + logger.warning('Could not find lexer for name "%s"' % lexer_name) lexer = PythonLexer() try: return highlight(code_string, lexer, NakedHtmlFormatter()) 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) def guess_code_lexer(code_string, default_lexer='unknown'): try: return guess_lexer(code_string).name - except ClassNotFound: + except ValueError: return default_lexer