How to use the mappyfile.ordereddict.CaseInsensitiveOrderedDict 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_update_case_sensitive_ordered_dict():

    d = CaseInsensitiveOrderedDict(CaseInsensitiveOrderedDict)

    d["b"] = "hello"
    d["a"] = "goodbye"

    print(json.dumps(d, indent=4))

    d["config"]["ms_errorfile"] = "error.log"
    print(json.dumps(d, indent=4))

    d.update({"c": "hello"})

    print(json.dumps(d, indent=4))

    d.update(red=1, blue=2)

    print(json.dumps(d, indent=4))
github geographika / mappyfile / tests / test_ordereddict.py View on Github external
def test_has_key():
    d = CaseInsensitiveOrderedDict()
    d["key1"] = "val1"
    assert "key1" in d
    assert "key2" not in d
github geographika / mappyfile / tests / test_ordereddict.py View on Github external
def test_pop():
    d = CaseInsensitiveOrderedDict()
    d["key1"] = "val1"
    v = d.pop("key1")
    assert v == "val1"
    assert len(d.keys()) == 0
github geographika / mappyfile / tests / test_ordereddict.py View on Github external
def test_copy():
    d = CaseInsensitiveOrderedDict()
    d["key1"] = "val1"
    c = d.copy()
    c["key1"] = "val2"
    assert d["key1"] == "val1"
github geographika / mappyfile / mappyfile / transformer.py View on Github external
def process_value_pairs(self, tokens, type_):
        """
        Metadata, Values, and Validation blocks can either
        have string pairs or attributes
        Attributes will already be processed
        """
        key, body = self.check_composite_tokens(type_, tokens)
        key_name = self.key_name(key)

        d = CaseInsensitiveOrderedDict(CaseInsensitiveOrderedDict)

        for t in body:
            k = self.clean_string(t[0].value).lower()
            v = self.clean_string(t[1].value)

            if k in d.keys():
                log.warning("A duplicate key ({}) was found in {}. Only the last value ({}) will be used. ".format(
                            k, type_, v))

            d[k] = v

        if self.include_position:
            pd = self.create_position_dict(key, body)
            d["__position__"] = pd

        d["__type__"] = key_name
github geographika / mappyfile / mappyfile / ordereddict.py View on Github external
def setdefault(self, key, *args, **kwargs):
        return super(CaseInsensitiveOrderedDict, self).setdefault(self.__class__._k(key), *args, **kwargs)
github geographika / mappyfile / mappyfile / transformer.py View on Github external
Handle the composite types e.g. CLASS..END
        t is a list in the form [[Token(__LAYER36, 'LAYER')], [OrderedDict([...])]]

        """
        if len(t) == 1:
            return t[0]  # metadata and values - already processed

        key_token = t[0][0]
        attribute_dicts = t[1]

        if not isinstance(attribute_dicts, list):
            # always handle a list of attributes
            attribute_dicts = [attribute_dicts]

        key_name = self.key_name(key_token)
        composite_dict = CaseInsensitiveOrderedDict(CaseInsensitiveOrderedDict)
        composite_dict["__type__"] = key_name

        if self.include_position:
            pd = self.create_position_dict(key_token, None)
            composite_dict["__position__"] = pd

        if self.include_comments:
            comments_dict = composite_dict["__comments__"] = OrderedDict()

        for d in attribute_dicts:
            keys = d.keys()
            if "__type__" in keys:
                k = d["__type__"]
                if k in SINGLETON_COMPOSITE_NAMES:
                    composite_dict[k] = d
                else: