/[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 744 by jonathan, Fri Apr 25 10:26:35 2003 UTC revision 784 by jonathan, Tue Apr 29 17:30:18 2003 UTC
# Line 20  import xml.sax.handler Line 20  import xml.sax.handler
20  from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException  from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException
21    
22  from Thuban import _  from Thuban import _
 from Thuban.common import *  
23    
24  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \
25       FIELDTYPE_STRING       FIELDTYPE_STRING
# Line 76  class XMLReader(xml.sax.handler.ContentH Line 75  class XMLReader(xml.sax.handler.ContentH
75    
76      def __init__(self):      def __init__(self):
77          self.chars = ''          self.chars = ''
         self.__parser = None  
78          self.__directory = ""          self.__directory = ""
79          self.__dispatchers = {}          self.__dispatchers = {}
80    
# Line 91  class XMLReader(xml.sax.handler.ContentH Line 89  class XMLReader(xml.sax.handler.ContentH
89              self.__directory = os.path.dirname(filename)              self.__directory = os.path.dirname(filename)
90              self.__file = open(filename)              self.__file = open(filename)
91    
92          if self.__parser is None:          parser = make_parser()
93              self.__parser = make_parser()          parser.setContentHandler(self)
94              self.__parser.setContentHandler(self)          parser.setErrorHandler(ErrorHandler())
95              self.__parser.setErrorHandler(ErrorHandler())          parser.setFeature(xml.sax.handler.feature_namespaces, 1)
96              self.__parser.setFeature(xml.sax.handler.feature_namespaces, 1)  
97            #
98              #          # Well, this isn't pretty, but it appears that if you
99              # Well, this isn't pretty, but it appears that if you          # use Python 2.2 without the site-package _xmlplus then
100              # use Python 2.2 without the site-package _xmlplus then          # the following will fail, and without them it will work.
101              # the following will fail, and without them it will work.          # However, if you do have the site-package and you don't
102              # However, if you do have the site-package and you don't          # call these functions, the reader raises an exception
103              # call these functions, the reader raises an exception          #
104              #          # The reason we set these to 0 in the first place is
105              # The reason we set these to 0 in the first place is          # because there is an unresolved issue with external
106              # because there is an unresolved issue with external          # entities causing an exception in the reader
107              # entities causing an exception in the reader          #
108              #          try:
109              try:              parser.setFeature(xml.sax.handler.feature_validation,0)
110                  self.__parser.setFeature(xml.sax.handler.feature_validation,0)              parser.setFeature(xml.sax.handler.feature_external_ges,0)
111                  self.__parser.setFeature(xml.sax.handler.feature_external_ges,0)              parser.setFeature(xml.sax.handler.feature_external_pes,0)
112                  self.__parser.setFeature(xml.sax.handler.feature_external_pes,0)          except SAXNotRecognizedException:
113              except SAXNotRecognizedException:              pass
                 pass  
114    
115          self.__parser.parse(self.__file)          parser.parse(self.__file)
116    
117          self.close()          self.close()
118    
# Line 230  class SessionLoader(XMLReader): Line 227  class SessionLoader(XMLReader):
227          title = attrs.get((None, 'title'), "")          title = attrs.get((None, 'title'), "")
228          filename = attrs.get((None, 'filename'), "")          filename = attrs.get((None, 'filename'), "")
229          filename = os.path.join(self.GetDirectory(), filename)          filename = os.path.join(self.GetDirectory(), filename)
230            visible  = attrs.get((None, 'visible'), "true")
231          fill = parse_color(attrs.get((None, 'fill'), "None"))          fill = parse_color(attrs.get((None, 'fill'), "None"))
232          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))
233          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))
234          self.aLayer = layer_class(title,          self.aLayer = layer_class(title,
235                                    self.theSession.OpenShapefile(filename),                                    self.theSession.OpenShapefile(filename),
236                                    fill = fill, stroke = stroke,                                    fill = fill, stroke = stroke,
237                                    lineWidth = stroke_width)                                    lineWidth = stroke_width,
238                                      visible = visible != "false")
239    
240          self.__projReceiver = self.aLayer          self.__projReceiver = self.aLayer
241    
# Line 281  class SessionLoader(XMLReader): Line 280  class SessionLoader(XMLReader):
280      def start_clpoint(self, name, qname, attrs):      def start_clpoint(self, name, qname, attrs):
281          attrib_value = attrs.get((None, 'value'), "0")          attrib_value = attrs.get((None, 'value'), "0")
282    
         #try:  
             #value  = Str2Num(attrib_value)  
         #except:  
             #value  = attrib_value  
   
283          value = self.conv(attrib_value)          value = self.conv(attrib_value)
284    
285          self.cl_group = ClassGroupSingleton(value)          self.cl_group = ClassGroupSingleton(value)
# Line 303  class SessionLoader(XMLReader): Line 297  class SessionLoader(XMLReader):
297          try:          try:
298              min = self.conv(attrs.get((None, 'min'), "0"))              min = self.conv(attrs.get((None, 'min'), "0"))
299              max = self.conv(attrs.get((None, 'max'), "0"))              max = self.conv(attrs.get((None, 'max'), "0"))
             #min = Str2Num(attrs.get((None, 'min'), "0"))  
             #max = Str2Num(attrs.get((None, 'max'), "0"))  
300          except ValueError:          except ValueError:
301              raise ValueError(_("Classification range is not a number!"))              raise ValueError(_("Classification range is not a number!"))
302    

Legend:
Removed from v.744  
changed lines
  Added in v.784

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26