+# Try to use ordered dicts, so the YAML keys are in database table order
+odict = dict # fall back to regular dict
+try:
+ from collections import OrderedDict as odict
+except ImportError:
+ try:
+ # This is a library for 2.4-2.6
+ from ordereddict import OrderedDict as odict
+ except ImportError:
+ pass
+
+# Tell PyYAML how to dump our ordered dict.
+# The items() is to avoid the sorting the library does automatically.
+# Needs to be added to SafeDumper manually, because we use safe_dump below, and
+# every Representer class has its own independent goddamn dict of these things
+from yaml.dumper import SafeDumper
+yaml.add_representer(
+ odict,
+ lambda dumper, data: dumper.represent_dict(data.items()),
+ Dumper=SafeDumper,
+)
+
+### Do actual work!