diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-01-21 18:01:19 +0000 |
---|---|---|
committer | Javier Jardón <javier.jardon@codethink.co.uk> | 2013-01-22 18:34:22 +0000 |
commit | a8d30277932099dcae31f99d3fbd531f74eb0249 (patch) | |
tree | 4440e7df4129a2cd65aed30721f2cc49e6769936 | |
parent | 0a6ab406c667d8b542ee6008349423a83896297b (diff) | |
download | morph-a8d30277932099dcae31f99d3fbd531f74eb0249.tar.gz |
Move OrderedDict and json loading to morphlib.util
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.
-rw-r--r-- | morphlib/morph2.py | 11 | ||||
-rw-r--r-- | morphlib/util.py | 12 |
2 files changed, 12 insertions, 11 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py index 4fdf7ba4..9e5be2e6 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 100f4b6b..e171714a 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2012 Codethink Limited +# Copyright (C) 2011-2013 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -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 |