source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wms_capabilities.py @ 2486

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wms_capabilities.py@2486
Revision 2486, 1.5 KB checked in by spascoe, 12 years ago (diff)

Started building a WMS capabilities facade on top of OWS capabilities.

Line 
1"""
2Utilities for extracting WMS 1.3.0 compatible metadata out of an
3OWS common 1.1.0 XML tree.
4
5@author: Stephen Pascoe
6
7"""
8
9from elementtree import ElementTree as ET
10
11# Namespaces
12ows_ns = 'http://www.opengis.net/ows/1.1'
13
14# ElementTree utilities
15def qname(ns, tag):
16    return '{%s}%s' % (ns, tag)
17def path(items):
18    return '/'.join(items)
19
20def ows_path(items):
21    return path([qname(ows_ns, x) for x in items])
22
23class WmsOwsAdapter(object):
24    """
25    This class is a facade over an OWS common XML tree which gives
26    easy access to key WMS metadata.
27
28    """
29    def __init__(self, ows_tree):
30        self.ows_tree = ows_tree
31
32    def _getTitle(self):
33        e = self.ows_tree.find(ows_path(['ServiceIdentification', 'Title']))
34        if e is not None:
35            return e.text
36        else:
37            return None
38    title = property(_getTitle)
39
40    def _getAbstracts(self):
41        es = self.ows_tree.findall(ows_path(['ServiceIdentification', 'Abstract']))
42        return [x.text for x in es]
43    abstracts = property(_getAbstracts)
44
45#-----------------------------------------------------------------------------
46
47from unittest import TestCase
48import pkg_resources
49
50class TestWmsCapabilities(TestCase):
51    def setUp(self):
52        fh = pkg_resources.resource_stream('ows_server.lib.tests',
53                                           'exampleCapabilities1.xml')
54        self.woa = WmsOwsAdapter(ET.parse(fh))
55
56    def testTitle(self):
57        assert self.woa.title == 'Acme Corp. Map Server'
58
59    def testAbstract(self):
60        assert False
Note: See TracBrowser for help on using the repository browser.