class LocationDataReader(object): 
   def __init__(self, uri, parent): 
      self.uri = uri
      self.parent = parent

      self.title = None
      self.uripattern = None
      self.tabnames = {}
      self.places = {}

      self.parse()

   def parse(self): 
      self.openuri()
      try: self.head()
      except Exception, e: 
         msg = 'This file is invalid and raised the error: %r'
         appuifw.note(msg % e, 'error')
         self.parent.restart()

      for line in self.u: 
         line = line.rstrip('\r\n')
         try: 
            # p and q need naming better
            code, p, q = line.split('\t', 2)
            self.places[code][p] = unicode(q)
            appuifw.app.body.add(u".")
         except: 
            msg = u"\nThe following line is ill formed: %s" % line
            appuifw.app.body.add(msg)

   def openuri(self, uri=None): 
      if uri is None: 
         uri = self.uri

      try: self.u = urllib.urlopen(self.uri)
      except Exception, e: 
         msg = 'That URI produced an error: %r. Restarting.'
         appuifw.note(msg % e, 'error')
         return

   def head(self): 
      line = self.u.next().rstrip('\r\n')
      while line.startswith('#'): 
         line = self.u.next().rstrip('\r\n')
      self.title = unicode(line)
      self.urlpattern = self.u.next().rstrip('\r\n')

      for item in self.u.next().rstrip('\r\n').split('\t'):
         longname, code = item.split('::', 1)
         places[code] = dict()
         tab[code] = unicode(longname)