Commits

Juancarlo Añez  committed 752d649

Work with unicode while rendering.

  • Participants
  • Parent commits fc3c973

Comments (0)

Files changed (2)

File grako/rendering.py

 """
 from __future__ import print_function, division, absolute_import, unicode_literals
 import itertools
-from .util import trim
+from .util import trim, ustr
 
 def render(item, join='', **fields):
     """ Render the given item
     elif isinstance(item, list):
         return join.join(render(e, join=join, **fields) for e in item)
     else:
-        return str(item)
+        return ustr(item)
 
 
 class Renderer(object):

File grako/util.py

 # -*- coding: utf-8 -*-
 from __future__ import print_function, division, absolute_import, unicode_literals
+import sys
 
 __all__ = ['simplify', 'memoize', 'trim', 'indent']
 
+def ustr(s):
+    if sys.version_info[0] >= 3:
+        return str(s)
+    else:
+        return unicode(s)
+
 def simplify(x):
     if isinstance(x, list) and len(x) == 1:
         return simplify(x[0])
     """
     if text is None:
         return ''
-    text = str(text)
+    text = ustr(text)
     if indent >= 0:
         lines = [' ' * 4 * indent + t for t in text.split('\n')]
         text = '\n'.join(lines)