summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-26 12:13:04 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-26 12:13:04 -0500
commit25576cd076d66dfed4bbd98ce1bbb3bc86a6230e (patch)
treee27153c4735139f152442c3f1a6326fdd8134d8d /src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
parent7ed0493ee4af4ca14bb7642a29a66cd51f4d5836 (diff)
downloadbcfg2-25576cd076d66dfed4bbd98ce1bbb3bc86a6230e.tar.gz
bcfg2-25576cd076d66dfed4bbd98ce1bbb3bc86a6230e.tar.bz2
bcfg2-25576cd076d66dfed4bbd98ce1bbb3bc86a6230e.zip
Reports: Add full PY3K compatibility
Note that Django still doesn't yet support version 3 so this won't necessarily work until there is a compatible version of django available for use. Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Server/Reports/reports/templatetags/syntax_coloring.py')
-rw-r--r--src/lib/Server/Reports/reports/templatetags/syntax_coloring.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py b/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
index 43dafb262..291528e2e 100644
--- a/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
+++ b/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
@@ -1,3 +1,4 @@
+import sys
from django import template
from django.utils.encoding import smart_unicode, smart_str
from django.utils.html import conditional_escape
@@ -14,6 +15,12 @@ try:
except:
colorize = False
+def u_str(string):
+ if sys.hexversion >= 0x03000000:
+ return string
+ else:
+ return unicode(string)
+
@register.filter
def syntaxhilight(value, arg="diff", autoescape=None):
"""
@@ -26,9 +33,9 @@ def syntaxhilight(value, arg="diff", autoescape=None):
if colorize:
try:
- output = u'<style type="text/css">' \
+ output = u_str('<style type="text/css">') \
+ smart_unicode(HtmlFormatter().get_style_defs('.highlight')) \
- + u'</style>'
+ + u_str('</style>')
lexer = get_lexer_by_name(arg)
output += highlight(value, lexer, HtmlFormatter())
@@ -36,6 +43,6 @@ def syntaxhilight(value, arg="diff", autoescape=None):
except:
return value
else:
- return mark_safe(u'<div class="note-box">Tip: Install pygments for highlighting</div><pre>%s</pre>' % value)
+ return mark_safe(u_str('<div class="note-box">Tip: Install pygments for highlighting</div><pre>%s</pre>') % value)
syntaxhilight.needs_autoescape = True