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))) |
186 |
If the attribute has a default value and it is not present in |
If the attribute has a default value and it is not present in |
187 |
attrs, use that default value as the value in the returned dict. |
attrs, use that default value as the value in the returned dict. |
188 |
|
|
189 |
If a conversion is specified, convert the value before putting |
The value is converted before putting it into the returned dict. |
190 |
it into the returned dict. The following conversions are |
The following conversions are available: |
|
available: |
|
191 |
|
|
192 |
'filename' -- The attribute is a filename. |
'filename' -- The attribute is a filename. |
193 |
|
|
209 |
|
|
210 |
'ascii' -- The attribute is converted to a bytestring with |
'ascii' -- The attribute is converted to a bytestring with |
211 |
ascii encoding. |
ascii encoding. |
212 |
|
|
213 |
|
a callable -- The attribute value is passed to the callable |
214 |
|
and the return value is used as the converted |
215 |
|
value |
216 |
|
|
217 |
|
If no conversion is specified for an attribute it is converted |
218 |
|
with self.encode. |
219 |
""" |
""" |
220 |
normalized = {} |
normalized = {} |
221 |
|
|
246 |
value)) |
value)) |
247 |
elif d.conversion == "ascii": |
elif d.conversion == "ascii": |
248 |
value = value.encode("ascii") |
value = value.encode("ascii") |
249 |
|
elif d.conversion: |
250 |
|
# Assume it's a callable |
251 |
|
value = d.conversion(value) |
252 |
else: |
else: |
253 |
if d.conversion: |
value = self.encode(value) |
|
raise ValueError("Unknown attribute conversion %r" |
|
|
% d.conversion) |
|
254 |
|
|
255 |
normalized[d.name] = value |
normalized[d.name] = value |
256 |
return normalized |
return normalized |
382 |
self.aMap = None |
self.aMap = None |
383 |
|
|
384 |
def start_projection(self, name, qname, attrs): |
def start_projection(self, name, qname, attrs): |
385 |
self.ProjectionName = self.encode(attrs.get((None, 'name'), None)) |
attrs = self.check_attrs(name, attrs, |
386 |
self.ProjectionParams = [ ] |
[AttrDesc("name", conversion=self.encode), |
387 |
|
AttrDesc("epsg", default=None, |
388 |
|
conversion=self.encode)]) |
389 |
|
self.projection_name = attrs["name"] |
390 |
|
self.projection_epsg = attrs["epsg"] |
391 |
|
self.projection_params = [ ] |
392 |
|
|
393 |
def end_projection(self, name, qname): |
def end_projection(self, name, qname): |
394 |
if self.aLayer is not None: |
if self.aLayer is not None: |
399 |
assert False, "projection tag out of context" |
assert False, "projection tag out of context" |
400 |
pass |
pass |
401 |
|
|
402 |
obj.SetProjection( |
obj.SetProjection(Projection(self.projection_params, |
403 |
Projection(self.ProjectionParams, self.ProjectionName)) |
self.projection_name, |
404 |
|
epsg = self.projection_epsg)) |
405 |
|
|
406 |
def start_parameter(self, name, qname, attrs): |
def start_parameter(self, name, qname, attrs): |
407 |
s = attrs.get((None, 'value')) |
s = attrs.get((None, 'value')) |
408 |
s = str(s) # we can't handle unicode in proj |
s = str(s) # we can't handle unicode in proj |
409 |
self.ProjectionParams.append(s) |
self.projection_params.append(s) |
410 |
|
|
411 |
def start_layer(self, name, qname, attrs, layer_class = Layer): |
def start_layer(self, name, qname, attrs, layer_class = Layer): |
412 |
"""Start a layer |
"""Start a layer |
450 |
self.aLayer = None |
self.aLayer = None |
451 |
|
|
452 |
def start_classification(self, name, qname, attrs): |
def start_classification(self, name, qname, attrs): |
453 |
field = attrs.get((None, 'field'), None) |
attrs = self.check_attrs(name, attrs, |
454 |
|
[AttrDesc("field", True), |
455 |
|
AttrDesc("field_type", True)]) |
456 |
|
field = attrs["field"] |
457 |
|
fieldType = attrs["field_type"] |
458 |
|
|
|
fieldType = attrs.get((None, 'field_type'), None) |
|
459 |
dbFieldType = self.aLayer.GetFieldType(field) |
dbFieldType = self.aLayer.GetFieldType(field) |
460 |
|
|
461 |
if fieldType != dbFieldType: |
if fieldType != dbFieldType: |
576 |
# Newly loaded session aren't modified |
# Newly loaded session aren't modified |
577 |
session.UnsetModified() |
session.UnsetModified() |
578 |
|
|
579 |
|
handler.Destroy() |
580 |
|
|
581 |
return session |
return session |
582 |
|
|