142 |
# all dispatchers should be used for the 0.8 and 0.9 namespaces too |
# all dispatchers should be used for the 0.8 and 0.9 namespaces too |
143 |
for xmlns in ("http://thuban.intevation.org/dtds/thuban-0.8.dtd", |
for xmlns in ("http://thuban.intevation.org/dtds/thuban-0.8.dtd", |
144 |
"http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd", |
"http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd", |
145 |
"http://thuban.intevation.org/dtds/thuban-0.9.dtd"): |
"http://thuban.intevation.org/dtds/thuban-0.9.dtd", |
146 |
|
"http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"): |
147 |
for key, value in dispatchers.items(): |
for key, value in dispatchers.items(): |
148 |
dispatchers[(xmlns, key)] = value |
dispatchers[(xmlns, key)] = value |
149 |
|
|
150 |
XMLReader.AddDispatchers(self, dispatchers) |
XMLReader.AddDispatchers(self, dispatchers) |
151 |
|
|
152 |
|
def Destroy(self): |
153 |
|
"""Clear all instance variables to cut cyclic references. |
154 |
|
|
155 |
|
The GC would have collected the loader eventually but it can |
156 |
|
happen that it doesn't run at all until Thuban is closed (2.3 |
157 |
|
but not 2.2 tries a bit harder and forces a collection when the |
158 |
|
interpreter terminates) |
159 |
|
""" |
160 |
|
self.__dict__.clear() |
161 |
|
|
162 |
def start_session(self, name, qname, attrs): |
def start_session(self, name, qname, attrs): |
163 |
self.theSession = Session(self.encode(attrs.get((None, 'title'), |
self.theSession = Session(self.encode(attrs.get((None, 'title'), |
164 |
None))) |
None))) |
210 |
|
|
211 |
'ascii' -- The attribute is converted to a bytestring with |
'ascii' -- The attribute is converted to a bytestring with |
212 |
ascii encoding. |
ascii encoding. |
213 |
|
|
214 |
|
a callable -- The attribute value is passed to the callable |
215 |
|
and the return value is used a as the converted |
216 |
|
value |
217 |
""" |
""" |
218 |
normalized = {} |
normalized = {} |
219 |
|
|
244 |
value)) |
value)) |
245 |
elif d.conversion == "ascii": |
elif d.conversion == "ascii": |
246 |
value = value.encode("ascii") |
value = value.encode("ascii") |
247 |
else: |
elif d.conversion: |
248 |
if d.conversion: |
# Assume it's a callable |
249 |
raise ValueError("Unknown attribute conversion %r" |
value = d.conversion(value) |
|
% d.conversion) |
|
250 |
|
|
251 |
normalized[d.name] = value |
normalized[d.name] = value |
252 |
return normalized |
return normalized |
378 |
self.aMap = None |
self.aMap = None |
379 |
|
|
380 |
def start_projection(self, name, qname, attrs): |
def start_projection(self, name, qname, attrs): |
381 |
self.ProjectionName = self.encode(attrs.get((None, 'name'), None)) |
attrs = self.check_attrs(name, attrs, |
382 |
self.ProjectionParams = [ ] |
[AttrDesc("name", conversion=self.encode), |
383 |
|
AttrDesc("epsg", default=None, |
384 |
|
conversion=self.encode)]) |
385 |
|
self.projection_name = attrs["name"] |
386 |
|
self.projection_epsg = attrs["epsg"] |
387 |
|
self.projection_params = [ ] |
388 |
|
|
389 |
def end_projection(self, name, qname): |
def end_projection(self, name, qname): |
390 |
if self.aLayer is not None: |
if self.aLayer is not None: |
395 |
assert False, "projection tag out of context" |
assert False, "projection tag out of context" |
396 |
pass |
pass |
397 |
|
|
398 |
obj.SetProjection( |
obj.SetProjection(Projection(self.projection_params, |
399 |
Projection(self.ProjectionParams, self.ProjectionName)) |
self.projection_name, |
400 |
|
epsg = self.projection_epsg)) |
401 |
|
|
402 |
def start_parameter(self, name, qname, attrs): |
def start_parameter(self, name, qname, attrs): |
403 |
s = attrs.get((None, 'value')) |
s = attrs.get((None, 'value')) |
404 |
s = str(s) # we can't handle unicode in proj |
s = str(s) # we can't handle unicode in proj |
405 |
self.ProjectionParams.append(s) |
self.projection_params.append(s) |
406 |
|
|
407 |
def start_layer(self, name, qname, attrs, layer_class = Layer): |
def start_layer(self, name, qname, attrs, layer_class = Layer): |
408 |
"""Start a layer |
"""Start a layer |
569 |
# Newly loaded session aren't modified |
# Newly loaded session aren't modified |
570 |
session.UnsetModified() |
session.UnsetModified() |
571 |
|
|
572 |
|
handler.Destroy() |
573 |
|
|
574 |
return session |
return session |
575 |
|
|