Skip to content

Commit

Permalink
Merge pull request #27 from p0cisk/master
Browse files Browse the repository at this point in the history
Added support for load_map_from_string in BaseWMSFactory.loadXML method (2)
  • Loading branch information
manelclos committed Jul 1, 2014
2 parents 8dce40b + 60e2892 commit e839f52
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
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

0 comments on commit e839f52

Please sign in to comment.