How to use the mappyfile.dumps 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_comments.py View on Github external
def test_metadata_mixed_case_comment():

    txt = """
    METADATA
        'wms_TITLE' 'Title1' # title1
    END
    """

    d = mappyfile.loads(txt, include_comments=True, include_position=False)
    s = mappyfile.dumps(d, indent=0, quote="'", newlinechar="\n")
    expected = """METADATA
'wms_title' 'Title1' # title1
END"""

    assert s == expected
github geographika / mappyfile / tests / test_validation.py View on Github external
s = u"""
    MAP
        LAYER
            CLUSTER
                MAXDISTANCE 50
                REGION "ELLIPSE"
            END
        END
    END
    """

    d = mappyfile.loads(s, include_position=True)
    v = Validator()
    assert d["__position__"]["line"] == 2
    errors = v.validate(d, add_comments=True)
    print(mappyfile.dumps(d))
    assert len(errors) == 0
github geographika / mappyfile / tests / test_sample_maps.py View on Github external
def test_non_ascii():
    p = Parser()

    ast = p.parse_file('./tests/samples/non_ascii.map')
    m = MapfileToDict()

    d = (m.transform(ast))  # works
    print(mappyfile.dumps(d))
github geographika / mappyfile / tests / test_utils.py View on Github external
def test_update_delete_dict():
    d1 = {"__type__": "layer", "name": "Unrated", "metadata": {"__type__": "metadata", "key1": "val1"}}
    print(mappyfile.dumps(d1))
    d2 = {"metadata": {"__delete__": True}}
    d = mappyfile.update(d1, d2)
    output = mappyfile.dumps(d)
    print(output)
    assert "metadata" not in d.keys()
github geographika / mappyfile / tests / test_snippets.py View on Github external
def test_single_layer_data():

    s = u"""
    LAYER
        DATA "dataset1"
    END
    """
    jsn = mappyfile.loads(s)
    print(json.dumps(jsn, indent=4))
    jsn["data"][0] = "dataset1"
    print(mappyfile.dumps(jsn))

    print(output(s, schema_name="layer"))
    exp = u"LAYER DATA 'dataset1' END"
    assert(output(s, schema_name="layer") == exp)
github geographika / mappyfile / tests / mapfiles / profiler.py View on Github external
def parse(mf):
    m = mappyfile.open(mf, expand_includes=False)
    s = mappyfile.dumps(m)
    return s
github geographika / mappyfile / tests / test_utils.py View on Github external
def test_update_add_item():
    d1 = {"__type__": "layer", "name": "Unrated", "styles": [{"__type__": "style", "color": "#888888"}]}
    d2 = {"name": "Unrated", "styles": [None, {"__type__": "style", "color": [0, 0, 255]}]}
    d = mappyfile.update(d1, d2)
    output = mappyfile.dumps(d)
    print(output)
    assert d["styles"][1]["color"] == [0, 0, 255]
github geographika / mappyfile / tests / test_utils.py View on Github external
def test_dumps():

    s = '''MAP NAME "TEST" END'''

    d = mappyfile.loads(s)
    output = mappyfile.dumps(d, indent=1, spacer="\t", newlinechar=" ")
    print(output)
    assert output == 'MAP 	NAME "TEST" END'
github geographika / mappyfile / docs / examples / modifying_values.py View on Github external
mapfile["name"] = "MyNewMap"

# update the error file path in the map config section
# note key names will always need to be lower case

mapfile["config"]["ms_errorfile"] = "/ms4w/tmp/ms_error.txt"
mapfile["config"]["ON_MISSING_DATA"] = "IGNORE"

# currently will need to double-quote non-keyword properties
mapfile["web"]["metadata"]["wms_format"] = "'image/png'"

layers = mapfile["layers"]
layer = layers[0]
layer["name"] = "MyLayer"

print(mappyfile.dumps(mapfile))

# alternatively we can use the Mapfile syntax
# not currently working for CONFIG or METADATA

web = """WEB
        METADATA
            'wms_enable_request' '*'
            'wms_feature_info_mime_type' 'text/html'
            'wms_format' 'image/jpg'
        END
    END"""

web = mappyfile.loads(web)

mapfile["web"] = web
print(mappyfile.dumps(mapfile))