[PATCH 1/4] Move OrderedDict and json loading to morphlib.util

Richard Maw richard.maw at codethink.co.uk
Mon Jan 21 18:15:57 GMT 2013


This way everyone who needs json or an OrderedDict doesn't have to worry
about it.

Currently morph2 is the only one that needs this complex behaviour,
other users of the json module don't need object_pairs_hook.
---
 morphlib/morph2.py |   11 +----------
 morphlib/util.py   |   10 ++++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index 4fdf7ba..9e5be2e 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -17,16 +17,7 @@
 import copy
 import re
 
-# It is intentional that if collections does not have OrderedDict that
-# simplejson is also used in preference to json, as OrderedDict became
-# a member of collections in the same release json got its object_pairs_hook
-try: # pragma: no cover
-    from collections import OrderedDict
-    import json
-except ImportError: # pragma: no cover
-    from ordereddict import OrderedDict
-    import simplejson as json
-
+from morphlib.util import OrderedDict, json
 
 class Morphology(object):
 
diff --git a/morphlib/util.py b/morphlib/util.py
index 100f4b6..40164ec 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -20,6 +20,16 @@ import morphlib
 '''Utility functions for morph.'''
 
 
+# It is intentional that if collections does not have OrderedDict that
+# simplejson is also used in preference to json, as OrderedDict became
+# a member of collections in the same release json got its object_pairs_hook
+try: # pragma: no cover
+    from collections import OrderedDict
+    import json
+except ImportError: # pragma: no cover
+    from ordereddict import OrderedDict
+    import simplejson as json
+
 try:
     from multiprocessing import cpu_count
 except NotImplementedError:  # pragma: no cover
-- 
1.7.5.4





More information about the baserock-dev mailing list