"""
MapHeader is a generalized header class that deals with header parsing and
normalization.
"""
from __future__ import absolute_import, division, print_function

from collections import OrderedDict

__all__ = ['MetaDict']


class MetaDict(OrderedDict):
    """
    A class to hold meta data associated with a Map derivative.

    This class handles everything a lower case. This allows case insensitive
    indexing.
    """
    def __init__(self, *args):
        """Creates a new MapHeader instance"""
        # Store all keys as upper-case to allow for case-insensitive indexing
        # OrderedDict can be instantiated from a list of lists or a tuple of tuples
        tags = dict()
        if args:
            args = list(args)
            adict = args[0]
            if isinstance(adict, list) or isinstance(adict, tuple):
                tags = dict((k.upper(), v) for k, v in adict)
            elif isinstance(adict, dict):
                tags = dict((k.upper(), v) for k, v in adict.items())
            else:
                raise TypeError("Can not create a MetaDict from this type input")
            args[0] = tags

        super(MetaDict, self).__init__(*args)

    def __contains__(self, key):
        """Override __contains__"""
        return OrderedDict.__contains__(self, key.lower())

    def __getitem__(self, key):
        """Override [] indexing"""
        return OrderedDict.__getitem__(self, key.lower())

    def __setitem__(self, key, value):
        """Override [] indexing"""
        return OrderedDict.__setitem__(self, key.lower(), value)

    def get(self, key, default=None):
        """Override .get() indexing"""
        return OrderedDict.get(self, key.lower(), default)

    def has_key(self, key):
        """Override .has_key() to perform case-insensitively"""
        return key.lower() in self

    def pop(self, key, default=None):
        """Override .pop() to perform case-insensitively"""
        return OrderedDict.pop(self, key.lower(), default)

    def update(self, d2):
        """Override .update() to perform case-insensitively"""
        return OrderedDict.update(self, dict((k.lower(), v) for k, v in d2.items()))

    def setdefault(self, key, default=None):
        """Override .setdefault() to perform case-insensitively"""
        return OrderedDict.setdefault(self, key.lower(), default)

@@ -840,33 +840,40 @@
          tags = 
-d
+OrderedD
 ict((k.upper(), 
@@ -955,25 +955,32 @@
      tags = 
-d
+OrderedD
 ict((k.upper

Fix error with the MetaDict class where it would loose the order of the input OrderedDict object. This is an error present in the original MapMeta class that will be fixed in a seperate PR.