52 |
|
|
53 |
from domutils import getElementsByName, getElementByName |
from domutils import getElementsByName, getElementByName |
54 |
|
|
55 |
|
from Thuban import _ |
56 |
|
|
57 |
class WMSCapabilitiesParser: |
class WMSCapabilitiesParser: |
58 |
""" |
""" |
59 |
Thuban class to parse capabilities supplied as large string. |
Thuban class to parse capabilities supplied as large string. |
70 |
access = None |
access = None |
71 |
formats = None |
formats = None |
72 |
srs_discrepancies = None |
srs_discrepancies = None |
73 |
|
error = None |
74 |
|
|
75 |
|
|
76 |
def __init__(self): |
def __init__(self): |
81 |
# Note that we must not initialise internal variables of the |
# Note that we must not initialise internal variables of the |
82 |
# class in a mutable way or it will be shared among all |
# class in a mutable way or it will be shared among all |
83 |
# instances. None is immutable, [] is not. |
# instances. None is immutable, [] is not. |
84 |
layers = [] |
self.error = [] |
85 |
|
|
86 |
|
|
87 |
def grok(self, data): |
def grok(self, data): |
108 |
# Extract fees information |
# Extract fees information |
109 |
foo = getElementByName(getElementByName(root, 'Service'), 'Fees') |
foo = getElementByName(getElementByName(root, 'Service'), 'Fees') |
110 |
if foo and len(foo.childNodes[0].data) \ |
if foo and len(foo.childNodes[0].data) \ |
111 |
and lower(foo.childNodes[0].data) != 'none': |
and foo.childNodes[0].data.lower() != 'none': |
112 |
self.fees = foo.childNodes[0].data |
self.fees = foo.childNodes[0].data |
113 |
|
|
114 |
# Extract access information |
# Extract access information |
115 |
foo = getElementByName(getElementByName(root, 'Service'), |
foo = getElementByName(getElementByName(root, 'Service'), |
116 |
'AccessConstraints') |
'AccessConstraints') |
117 |
if foo and len(foo.childNodes[0].data) \ |
if foo and len(foo.childNodes[0].data) \ |
118 |
and lower(foo.childNodes[0].data) != 'none': |
and foo.childNodes[0].data.lower() != 'none': |
119 |
self.access = foo.childNodes[0].data |
self.access = foo.childNodes[0].data |
120 |
|
|
121 |
# Extract output format information |
# Extract output format information |
155 |
foo = getElementByName(top, 'Title') |
foo = getElementByName(top, 'Title') |
156 |
if foo and len(foo.childNodes[0].data): |
if foo and len(foo.childNodes[0].data): |
157 |
self.layers[index]['title'] = foo.childNodes[0].data |
self.layers[index]['title'] = foo.childNodes[0].data |
158 |
|
else: |
159 |
|
# A <Title> is required for each layer, <name> is optional |
160 |
|
# See OGC 01-068r3, 7.1.4.5.1 and 7.1.4.5.2 |
161 |
|
self.error.append(_("No title found for layer #%d") % index) |
162 |
|
|
163 |
foo = getElementByName(top, 'Name') |
foo = getElementByName(top, 'Name') |
164 |
if foo and len(foo.childNodes[0].data): |
if foo and len(foo.childNodes[0].data): |
170 |
if srs[0:5] == 'EPSG:': |
if srs[0:5] == 'EPSG:': |
171 |
srs = srs[5:] |
srs = srs[5:] |
172 |
try: |
try: |
173 |
self.layers[index]['srs'].append(srs) |
int(srs) |
174 |
except KeyError: |
try: |
175 |
self.layers[index]['srs'] = [srs] |
self.layers[index]['srs'].append(srs) |
176 |
|
except KeyError: |
177 |
|
self.layers[index]['srs'] = [srs] |
178 |
|
except ValueError: |
179 |
|
if srs[0:4].upper() == 'AUTO' \ |
180 |
|
or srs[0:4].upper() == 'NONE': |
181 |
|
try: |
182 |
|
self.layers[index]['_srs_'].append(srs) |
183 |
|
except KeyError: |
184 |
|
self.layers[index]['_srs_'] = [srs] |
185 |
|
else: |
186 |
|
self.error.append(_("SRS '%s' is not numerical and not" |
187 |
|
" AUTO/NONE in layer '%s'") \ |
188 |
|
% (srs, self.layers[index]['title'])) |
189 |
|
|
190 |
foo = getElementByName(top, 'LatLonBoundingBox') |
foo = getElementByName(top, 'LatLonBoundingBox') |
191 |
if foo is not None: |
if foo is not None: |
458 |
if srs in pivot['bbox']: |
if srs in pivot['bbox']: |
459 |
return pivot['bbox'][srs] |
return pivot['bbox'][srs] |
460 |
|
|
461 |
|
# No matching BBox found, let's see if it was EPSG:4326 |
462 |
|
if srs == '4326': |
463 |
|
return self.getLayerLatLonBBox(name) |
464 |
|
|
465 |
return None |
return None |
466 |
|
|
467 |
|
|
506 |
|
|
507 |
import os |
import os |
508 |
|
|
509 |
|
sample = "test/sample.xml" |
510 |
try: |
try: |
511 |
f = open("test/sample.xml", "r") |
f = open(sample, "r") |
512 |
except IOError: |
except IOError: |
513 |
try: |
try: |
514 |
f = open(os.path.dirname(__file__) + "/test/sample.xml", "r") |
f = open(os.path.dirname(__file__) + "/" + sample, "r") |
515 |
except IOError: |
except IOError: |
516 |
print "Cannot open sample.xml for reading" |
print "Cannot open %s for reading" % sample |
517 |
|
|
518 |
if f is not None: |
if f is not None: |
519 |
sample = f.read(); |
sample = f.read(); |