Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for load_map_from_string in BaseWMSFactory.loadXML method (2) #27

Merged
merged 3 commits into from
Jul 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions ogcserver/WMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import sys
import ConfigParser
from mapnik import Style, Map, load_map, Envelope, Coord
from mapnik import Style, Map, load_map, load_map_from_string, Envelope, Coord

from ogcserver import common
from ogcserver.wms111 import ServiceHandler as ServiceHandler111
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, configpath=None):
self.configpath = configpath
self.latlonbb = None

def loadXML(self, xmlfile, strict=False):
def loadXML(self, xmlfile=None, strict=False, xmlstring='', basepath=''):
config = ConfigParser.SafeConfigParser()
map_wms_srs = None
if self.configpath:
Expand All @@ -62,7 +62,13 @@ def loadXML(self, xmlfile, strict=False):
map_wms_srs = config.get('map', 'wms_srs')

tmp_map = Map(0,0)
load_map(tmp_map, xmlfile, strict)
if xmlfile:
load_map(tmp_map, xmlfile, strict)
elif xmlstring:
load_map_from_string(tmp_map, xmlstring, strict, basepath)
else:
raise ServerConfigurationError("Mapnik configuration XML is not specified - 'xmlfile' and 'xmlstring' variables are empty.\
Please set one of this variables to load mapnik map object.")
# parse map level attributes
if tmp_map.background:
self.map_attributes['bgcolor'] = tmp_map.background
Expand Down
10 changes: 10 additions & 0 deletions tests/testLoadMapFail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import nose
import os
from ogcserver.WMS import BaseWMSFactory
from ogcserver.exceptions import ServerConfigurationError

def test_wms_capabilities():
wms = BaseWMSFactory()
nose.tools.assert_raises(ServerConfigurationError, wms.loadXML)

return True
19 changes: 19 additions & 0 deletions tests/testLoadMapFromString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import nose
import os
from ogcserver.WMS import BaseWMSFactory

def test_wms_capabilities():
base_path, tail = os.path.split(__file__)
file_path = os.path.join(base_path, 'mapfile_encoding.xml')
wms = BaseWMSFactory()
with open(file_path) as f:
settings = f.read()
wms.loadXML(xmlstring=settings, basepath=base_path)
wms.finalize()

if len(wms.layers) != 1:
raise Exception('Incorrect number of layers')
if len(wms.styles) != 1:
raise Exception('Incorrect number of styles')

return True