From 25576cd076d66dfed4bbd98ce1bbb3bc86a6230e Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Tue, 26 Apr 2011 12:13:04 -0500 Subject: 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 --- .../Server/Reports/reports/templatetags/syntax_coloring.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/lib/Server/Reports/reports/templatetags/syntax_coloring.py') 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'' + + u_str('') 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'
Tip: Install pygments for highlighting
%s
' % value) + return mark_safe(u_str('
Tip: Install pygments for highlighting
%s
') % value) syntaxhilight.needs_autoescape = True -- cgit v1.2.3-1-g7c22