[Erp5-report] r42306 jm - /erp5/trunk/products/ERP5Type/patches/python.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Jan 13 15:09:40 CET 2011


Author: jm
Date: Thu Jan 13 15:09:39 2011
New Revision: 42306

URL: http://svn.erp5.org?rev=42306&view=rev
Log:
Python 2.4: monkey-patch pprint to sort keys of dictionaries

Modified:
    erp5/trunk/products/ERP5Type/patches/python.py

Modified: erp5/trunk/products/ERP5Type/patches/python.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/python.py?rev=42306&r1=42305&r2=42306&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/python.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/patches/python.py [utf8] Thu Jan 13 15:09:39 2011
@@ -72,3 +72,16 @@ if sys.version_info < (2, 5):
 
   import re, sre
   re._compile = sre._compile
+
+  # Monkey-patch pprint to sort keys of dictionaries
+  class _ordered_dict(dict):
+    def iteritems(self):
+      return sorted(self.items())
+
+  import pprint as _pprint
+  orig_safe_repr = _pprint._safe_repr
+  def _safe_repr(object, context, maxlevels, level):
+    if type(object) is dict:
+      object = _ordered_dict(object)
+    return orig_safe_repr(object, context, maxlevels, level)
+  _pprint._safe_repr = _safe_repr



More information about the Erp5-report mailing list