141 |
|
|
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", |
146 |
|
"http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd", |
147 |
|
"http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd"): |
148 |
for key, value in dispatchers.items(): |
for key, value in dispatchers.items(): |
149 |
dispatchers[(xmlns, key)] = value |
dispatchers[(xmlns, key)] = value |
150 |
|
|
151 |
XMLReader.AddDispatchers(self, dispatchers) |
XMLReader.AddDispatchers(self, dispatchers) |
152 |
|
|
153 |
|
def Destroy(self): |
154 |
|
"""Clear all instance variables to cut cyclic references. |
155 |
|
|
156 |
|
The GC would have collected the loader eventually but it can |
157 |
|
happen that it doesn't run at all until Thuban is closed (2.3 |
158 |
|
but not 2.2 tries a bit harder and forces a collection when the |
159 |
|
interpreter terminates) |
160 |
|
""" |
161 |
|
self.__dict__.clear() |
162 |
|
|
163 |
def start_session(self, name, qname, attrs): |
def start_session(self, name, qname, attrs): |
164 |
self.theSession = Session(self.encode(attrs.get((None, 'title'), |
self.theSession = Session(self.encode(attrs.get((None, 'title'), |
165 |
None))) |
None))) |
187 |
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 |
188 |
attrs, use that default value as the value in the returned dict. |
attrs, use that default value as the value in the returned dict. |
189 |
|
|
190 |
If a conversion is specified, convert the value before putting |
The value is converted before putting it into the returned dict. |
191 |
it into the returned dict. The following conversions are |
The following conversions are available: |
|
available: |
|
192 |
|
|
193 |
'filename' -- The attribute is a filename. |
'filename' -- The attribute is a filename. |
194 |
|
|
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 as the converted |
216 |
|
value |
217 |
|
|
218 |
|
If no conversion is specified for an attribute it is converted |
219 |
|
with self.encode. |
220 |
""" |
""" |
221 |
normalized = {} |
normalized = {} |
222 |
|
|
247 |
value)) |
value)) |
248 |
elif d.conversion == "ascii": |
elif d.conversion == "ascii": |
249 |
value = value.encode("ascii") |
value = value.encode("ascii") |
250 |
|
elif d.conversion: |
251 |
|
# Assume it's a callable |
252 |
|
value = d.conversion(value) |
253 |
else: |
else: |
254 |
if d.conversion: |
value = self.encode(value) |
|
raise ValueError("Unknown attribute conversion %r" |
|
|
% d.conversion) |
|
255 |
|
|
256 |
normalized[d.name] = value |
normalized[d.name] = value |
257 |
return normalized |
return normalized |
383 |
self.aMap = None |
self.aMap = None |
384 |
|
|
385 |
def start_projection(self, name, qname, attrs): |
def start_projection(self, name, qname, attrs): |
386 |
self.ProjectionName = self.encode(attrs.get((None, 'name'), None)) |
attrs = self.check_attrs(name, attrs, |
387 |
self.ProjectionParams = [ ] |
[AttrDesc("name", conversion=self.encode), |
388 |
|
AttrDesc("epsg", default=None, |
389 |
|
conversion=self.encode)]) |
390 |
|
self.projection_name = attrs["name"] |
391 |
|
self.projection_epsg = attrs["epsg"] |
392 |
|
self.projection_params = [ ] |
393 |
|
|
394 |
def end_projection(self, name, qname): |
def end_projection(self, name, qname): |
395 |
if self.aLayer is not None: |
if self.aLayer is not None: |
400 |
assert False, "projection tag out of context" |
assert False, "projection tag out of context" |
401 |
pass |
pass |
402 |
|
|
403 |
obj.SetProjection( |
obj.SetProjection(Projection(self.projection_params, |
404 |
Projection(self.ProjectionParams, self.ProjectionName)) |
self.projection_name, |
405 |
|
epsg = self.projection_epsg)) |
406 |
|
|
407 |
def start_parameter(self, name, qname, attrs): |
def start_parameter(self, name, qname, attrs): |
408 |
s = attrs.get((None, 'value')) |
s = attrs.get((None, 'value')) |
409 |
s = str(s) # we can't handle unicode in proj |
s = str(s) # we can't handle unicode in proj |
410 |
self.ProjectionParams.append(s) |
self.projection_params.append(s) |
411 |
|
|
412 |
def start_layer(self, name, qname, attrs, layer_class = Layer): |
def start_layer(self, name, qname, attrs, layer_class = Layer): |
413 |
"""Start a layer |
"""Start a layer |
451 |
self.aLayer = None |
self.aLayer = None |
452 |
|
|
453 |
def start_classification(self, name, qname, attrs): |
def start_classification(self, name, qname, attrs): |
454 |
field = attrs.get((None, 'field'), None) |
attrs = self.check_attrs(name, attrs, |
455 |
|
[AttrDesc("field", True), |
456 |
|
AttrDesc("field_type", True)]) |
457 |
|
field = attrs["field"] |
458 |
|
fieldType = attrs["field_type"] |
459 |
|
|
|
fieldType = attrs.get((None, 'field_type'), None) |
|
460 |
dbFieldType = self.aLayer.GetFieldType(field) |
dbFieldType = self.aLayer.GetFieldType(field) |
461 |
|
|
462 |
if fieldType != dbFieldType: |
if fieldType != dbFieldType: |
546 |
self.aLayer = self.aMap.LabelLayer() |
self.aLayer = self.aMap.LabelLayer() |
547 |
|
|
548 |
def start_label(self, name, qname, attrs): |
def start_label(self, name, qname, attrs): |
549 |
x = float(attrs[(None, 'x')]) |
attrs = self.check_attrs(name, attrs, |
550 |
y = float(attrs[(None, 'y')]) |
[AttrDesc("x", True, conversion = float), |
551 |
text = self.encode(attrs[(None, 'text')]) |
AttrDesc("y", True, conversion = float), |
552 |
halign = attrs[(None, 'halign')] |
AttrDesc("text", True), |
553 |
valign = attrs[(None, 'valign')] |
AttrDesc("halign", True, |
554 |
|
conversion = "ascii"), |
555 |
|
AttrDesc("valign", True, |
556 |
|
conversion = "ascii")]) |
557 |
|
x = attrs['x'] |
558 |
|
y = attrs['y'] |
559 |
|
text = attrs['text'] |
560 |
|
halign = attrs['halign'] |
561 |
|
valign = attrs['valign'] |
562 |
|
if halign not in ("left", "center", "right"): |
563 |
|
raise LoadError("Unsupported halign value %r" % halign) |
564 |
|
if valign not in ("top", "center", "bottom"): |
565 |
|
raise LoadError("Unsupported valign value %r" % valign) |
566 |
self.aLayer.AddLabel(x, y, text, halign = halign, valign = valign) |
self.aLayer.AddLabel(x, y, text, halign = halign, valign = valign) |
567 |
|
|
568 |
def characters(self, chars): |
def characters(self, chars): |
589 |
# Newly loaded session aren't modified |
# Newly loaded session aren't modified |
590 |
session.UnsetModified() |
session.UnsetModified() |
591 |
|
|
592 |
|
handler.Destroy() |
593 |
|
|
594 |
return session |
return session |
595 |
|
|