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() while 1: line = self.getline() if line is None: break 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(uri) except Exception, e: msg = 'That URI produced an error: %r. Restarting.' appuifw.note(msg % e, 'error') return def head(self): line = self.getline() while line.startswith('#'): line = self.getline() self.title = unicode(line) self.urlpattern = self.getline() for item in self.getline().split('\t'): longname, code = item.split('::', 1) places[code] = dict() tab[code] = unicode(longname) def getline(self): rawline = self.u.next() if not line: return None return line.rstrip('\r\n')