Permalink
Browse files

Convert unicode keys to strings for older Python

  • Loading branch information...
1 parent ec8dce5 commit 410b981e7c855973cf012af689a9d42ba3cb118d @tnm committed Jul 10, 2012
Showing with 11 additions and 2 deletions.
  1. +11 −2 lib/pygments/mentos.py
@@ -6,6 +6,8 @@
if 'PYGMENTS_PATH' in os.environ:
sys.path.insert(0, os.environ['PYGMENTS_PATH'])
sys.path.append(os.getcwd() + "/vendor/")
+sys.path.append(os.getcwd() + "/vendor/pygments-main")
+sys.path.append(os.getcwd() + "/vendor/simplejson")
import pygments
from pygments import lexers, formatters, styles, filters
@@ -15,6 +17,12 @@
except ImportError:
import simplejson as json
+def _convert_keys(dictionary):
+ if not isinstance(dictionary, dict):
+ return dictionary
+ return dict((str(k), _convert_keys(v))
+ for k, v in dictionary.items())
+
def _signal_handler(signal, frame):
"""
Handle the signal given in the first argument, exiting gracefully
@@ -137,9 +145,10 @@ def get_data(self, method, args, kwargs, text=None):
res = json.dumps(res)
elif method == 'highlight':
- res = self.highlight_text(text.decode('utf-8'), formatter_name, args, opts)
+ res = self.highlight_text(text.decode('utf-8'), formatter_name, args, _convert_keys(opts))
elif method == 'css':
+ kwargs = _convert_keys(kwargs)
fmt = pygments.formatters.get_formatter_by_name(args[0], **kwargs)
res = fmt.get_style_defs(args[1])
@@ -192,7 +201,7 @@ def start(self):
except:
header = None
- if header:
+ if header != None:
try:
method = header["method"]

0 comments on commit 410b981

Please sign in to comment.