[or-cvs] r17423: {updater} Kludge harder. (updater/trunk/lib/thandy)

nickm at seul.org nickm at seul.org
Mon Dec 1 05:45:11 UTC 2008


Author: nickm
Date: 2008-12-01 00:45:10 -0500 (Mon, 01 Dec 2008)
New Revision: 17423

Modified:
   updater/trunk/lib/thandy/util.py
Log:
Kludge harder.

Modified: updater/trunk/lib/thandy/util.py
===================================================================
--- updater/trunk/lib/thandy/util.py	2008-12-01 05:27:29 UTC (rev 17422)
+++ updater/trunk/lib/thandy/util.py	2008-12-01 05:45:10 UTC (rev 17423)
@@ -42,6 +42,9 @@
         # code is not guaranteed to work on all broken versions of simplejson:
         # it replaces an entry in the internal character-replacement
         # dictionary so that "/" is translated to itself rather than to \/.
+        # We also need to make sure that ensure_ascii is False, so that we
+        # do not call the C-optimized string encoder in these broken versions,
+        # which we can't fix easily.  Both parts are a kludge.
         try:
             escape_dct = mod.encoder.ESCAPE_DCT
         except NameError:
@@ -49,6 +52,16 @@
         else:
             if escape_dct.has_key("/"):
                 escape_dct["/"] = "/"
+                save_dumps = simplejson.dumps
+                save_dump = simplejson.dump
+                def dumps(*k, **v):
+                    v['ensure_ascii']=False
+                    return save_dumps(*k,**v)
+                def dump(*k,**v):
+                    v['ensure_ascii']=False
+                    return save_dump(*k,**v)
+                simplejson.dump = dump
+                simplejson.dumps = dumps
                 logging.warn("Your operating system has an old broken "
                              "simplejson module.  I tried to fix it for you.")
 



More information about the tor-commits mailing list