How to use the mappyfile.ordereddict.DefaultOrderedDict function in mappyfile

To help you get started, we’ve selected a few mappyfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geographika / mappyfile / tests / test_ordereddict.py View on Github external
def test_deepcopy():
    """
    See issue #73
    """
    d = DefaultOrderedDict()
    d['__type__'] = 'layer'

    c = deepcopy(d)
    assert c['__type__'] == 'layer'
github geographika / mappyfile / tests / test_ordereddict.py View on Github external
def test_false_value():

    d = DefaultOrderedDict(DefaultOrderedDict)
    d["key"] = False
    print(json.dumps(d, indent=4))
    assert(d["key"] is False)
github geographika / mappyfile / tests / test_ordereddict.py View on Github external
def test_dict():

    d = DefaultOrderedDict()
    d["key"] = ["value"]

    print(d["key"])
github geographika / mappyfile / mappyfile / ordereddict.py View on Github external
def copy(self):
        return self.__copy__()

    def __copy__(self):
        return type(self)(self.default_factory, self)

    def __deepcopy__(self, memo):
        return type(self)(self.default_factory,
                          copy.deepcopy(list(self.items())))

    def __repr__(self):
        return 'DefaultOrderedDict(%s, %s)' % (self.default_factory,
                                               OrderedDict.__repr__(self))


class CaseInsensitiveOrderedDict(DefaultOrderedDict):
    """
    Based on: https://stackoverflow.com/a/32888599/179520
    """
    @classmethod
    def _k(cls, key):
        return key.lower() if isinstance(key, (bytes, str)) else key

    def __init__(self, *args, **kwargs):
        super(CaseInsensitiveOrderedDict, self).__init__(*args, **kwargs)
        self._convert_keys()

    def __getitem__(self, key):
        return super(CaseInsensitiveOrderedDict, self).__getitem__(self.__class__._k(key))

    def __setitem__(self, key, value):
        super(CaseInsensitiveOrderedDict, self).__setitem__(self.__class__._k(key), value)