summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-12-07 22:44:56 +0100
committermathieui <mathieui@mathieui.net>2014-12-07 22:44:56 +0100
commit148451c7747b380208938b45238c6f3536efd2bf (patch)
tree57e532694fc00128bd70e5697d265d5605c2f1c4
parent3d97769955f754eb82af8f6a0da7e9d48b90a8a3 (diff)
downloadpoezio-148451c7747b380208938b45238c6f3536efd2bf.tar.gz
poezio-148451c7747b380208938b45238c6f3536efd2bf.tar.bz2
poezio-148451c7747b380208938b45238c6f3536efd2bf.tar.xz
poezio-148451c7747b380208938b45238c6f3536efd2bf.zip
Fix the xml tab when pygments isn’t present
-rw-r--r--src/core/handlers.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/handlers.py b/src/core/handlers.py
index e0c89abf..9ce50d42 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -44,11 +44,9 @@ try:
from pygments.formatters import HtmlFormatter
LEXER = get_lexer_by_name('xml')
FORMATTER = HtmlFormatter(noclasses=True)
+ PYGMENTS = True
except ImportError:
- def highlight(text, *args, **kwargs):
- return text
- LEXER = None
- FORMATTER = None
+ PYGMENTS = False
def on_session_start_features(self, _):
"""
@@ -1117,8 +1115,11 @@ def outgoing_stanza(self, stanza):
We are sending a new stanza, write it in the xml buffer if needed.
"""
if self.xml_tab:
- xhtml_text = highlight('%s' % stanza, LEXER, FORMATTER)
- poezio_colored = xhtml.xhtml_to_poezio_colors(xhtml_text, force=True)
+ if PYGMENTS:
+ xhtml_text = highlight('%s' % stanza, LEXER, FORMATTER)
+ poezio_colored = xhtml.xhtml_to_poezio_colors(xhtml_text, force=True)
+ else:
+ poezio_colored = '%s' % stanza
self.add_message_to_text_buffer(self.xml_buffer, poezio_colored,
nickname=get_theme().CHAR_XML_OUT)
try:
@@ -1137,8 +1138,11 @@ def incoming_stanza(self, stanza):
We are receiving a new stanza, write it in the xml buffer if needed.
"""
if self.xml_tab:
- xhtml_text = highlight('%s' % stanza, LEXER, FORMATTER)
- poezio_colored = xhtml.xhtml_to_poezio_colors(xhtml_text, force=True)
+ if PYGMENTS:
+ xhtml_text = highlight('%s' % stanza, LEXER, FORMATTER)
+ poezio_colored = xhtml.xhtml_to_poezio_colors(xhtml_text, force=True)
+ else:
+ poezio_colored = '%s' % stanza
self.add_message_to_text_buffer(self.xml_buffer, poezio_colored,
nickname=get_theme().CHAR_XML_IN)
try: