summaryrefslogtreecommitdiff
path: root/morphlib/morph2.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-09-13 15:39:07 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-09-13 15:39:07 +0100
commit2b82040f847a5595dccb80f8ed537e7d6c5a1e6e (patch)
tree4945051fca5c55c6e8672ad61f0c499916960121 /morphlib/morph2.py
parent90821e1e58317ae105bd2ecf43f46f441e292fcd (diff)
downloadmorph-2b82040f847a5595dccb80f8ed537e7d6c5a1e6e.tar.gz
Fix things so test suite works on Debian squeeze
This requires disabling the feature that retains the original order of fields in a morphlogy when it gets overwritten. The implementation relies on features that are not available in Python 2.6. We need to support Morph on Debian squeeze, for bootstrapping purposes, and therefore need to have it work with Python 2.6. However, the morphology rewriting is only relevant for system branching and merging, and that isn't needed for bootstrapping, so we disable the affected tests on Python 2.6.
Diffstat (limited to 'morphlib/morph2.py')
-rw-r--r--morphlib/morph2.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index 0eca6fed..45d33d8a 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -14,7 +14,12 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import sys
+have_python27 = sys.version_info >= (2,7)
+
import collections
+if not hasattr(collections, 'OrderedDict'): # pragma: no cover
+ collections.OrderedDict = dict
import copy
import json
import re
@@ -53,15 +58,19 @@ class Morphology(object):
]
}
- @staticmethod
- def _order_keys(pairs):
- result = collections.OrderedDict()
- for k,v in pairs:
- result[k] = v
- return result
+ if have_python27: # pragma: no cover
+ @staticmethod
+ def _order_keys(pairs):
+ result = collections.OrderedDict()
+ for k,v in pairs:
+ result[k] = v
+ return result
def __init__(self, text):
- self._dict = json.loads(text, object_pairs_hook=self._order_keys)
+ if have_python27: # pragma: no cover
+ self._dict = json.loads(text, object_pairs_hook=self._order_keys)
+ else: # pragma: no cover
+ self._dict = json.loads(text)
self._set_defaults()
self._validate_children()
@@ -143,9 +152,9 @@ class Morphology(object):
return int(size[:-1]) * 1024 ** 2
elif size.endswith('k'): # pragma: no cover
return int(size[:-1]) * 1024
- return int(size)
+ return int(size) # pragma: no cover
- def write_to_file(self, f):
+ def write_to_file(self, f): # pragma: no cover
# Recreate dict without the empty default values, with a few kind
# specific hacks to try and edit standard morphologies as
# non-destructively as possible