/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/load.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/load.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1844 by bh, Tue Oct 21 10:49:44 2003 UTC revision 2004 by bh, Tue Dec 2 13:25:55 2003 UTC
# Line 143  class SessionLoader(XMLReader): Line 143  class SessionLoader(XMLReader):
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"):                        "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)))
# Line 176  class SessionLoader(XMLReader): Line 187  class SessionLoader(XMLReader):
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    
# Line 202  class SessionLoader(XMLReader): Line 212  class SessionLoader(XMLReader):
212                        ascii encoding.                        ascii encoding.
213    
214             a callable -- The attribute value is passed to the callable             a callable -- The attribute value is passed to the callable
215                           and the return value is used a as the converted                           and the return value is used as the converted
216                           value                           value
217    
218            If no conversion is specified for an attribute it is converted
219            with self.encode.
220          """          """
221          normalized = {}          normalized = {}
222    
# Line 237  class SessionLoader(XMLReader): Line 250  class SessionLoader(XMLReader):
250              elif d.conversion:              elif d.conversion:
251                  # Assume it's a callable                  # Assume it's a callable
252                  value = d.conversion(value)                  value = d.conversion(value)
253                else:
254                   value = self.encode(value)
255    
256              normalized[d.name] = value              normalized[d.name] = value
257          return normalized          return normalized
# Line 436  class SessionLoader(XMLReader): Line 451  class SessionLoader(XMLReader):
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:
# Line 559  def load_session(filename, db_connection Line 577  def load_session(filename, db_connection
577      # Newly loaded session aren't modified      # Newly loaded session aren't modified
578      session.UnsetModified()      session.UnsetModified()
579    
580        handler.Destroy()
581    
582      return session      return session
583    

Legend:
Removed from v.1844  
changed lines
  Added in v.2004

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26