Paste number 5997: Location Date File Reader thing for crschmidt (still horrid, but a step in a nice direction)

Index of paste annotations: 1 | 2 | 3 | 4 | 5

Paste number 5997: Location Date File Reader thing for crschmidt (still horrid, but a step in a nice direction)
Pasted by: sbp
3 years, 7 months ago
#swhack | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
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)

Annotations for this paste:

Annotation number 1: Further decrudination
Pasted by: sbp
3 years, 7 months ago
Context in IRC logs
Paste contents:
Raw Source | Display As
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')

Annotation number 2: Even more &c.
Pasted by: sbp
3 years, 7 months ago
Context in IRC logs
Paste contents:
Raw Source | Display As
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:
            code, num, desc = line.split('\t', 2)
            self.places[code][num] = unicode(desc)
            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)
         self.places[code] = {}
         self.tab[code] = unicode(longname)

   def getline(self):
      rawline = self.u.next()
      if not line: return None
      return line.rstrip()

Annotation number 3: Where would we be if not for decrudination?
Pasted by: sbp
3 years, 7 months ago
Context in IRC logs
Paste contents:
Raw Source | Display As
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 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 getline(self):
      try: rawline = self.u.next()
      except StopIteration: return None # thanks deltab
      return line.rstrip()

   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)
         self.places[code] = {}
         self.tab[code] = unicode(longname)

   def body(self):
      while 1:
         line = self.getline()
         if line is None: break
         try:
            code, num, desc = line.split('\t', 2)
            self.places[code][num] = unicode(desc)
            appuifw.app.body.add(u'.')
         except:
            msg = u'\nThe following line is ill formed: %s' % line
            appuifw.app.body.add(msg)

   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()
      self.body()

Annotation number 4: Mmm... teamwork.
Pasted by: sbp
3 years, 7 months ago
Context in IRC logs
Paste contents:
Raw Source | Display As
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 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 getline(self):
      while 1:
         try: rawline = self.u.next()
         except StopIteration: return None # thanks deltab
         if not rawline.startswith('#'): break
      return rawline.rstrip()

   def head(self):
      self.title = unicode(self.getline())
      self.urlpattern = self.getline()

      for item in self.getline().split('\t'):
         longname, area = item.split('::', 1)
         self.places[area] = {}
         self.tab[area] = unicode(longname)

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

   def body(self):
      while 1:
         line = self.getline()
         if line is None: break
         try:
            area, camera, name = line.split('\t', 2)
            self.places[area][camera] = unicode(name)
            appuifw.app.body.add(u'.')
         except:
            msg = u'\nThe following line is ill formed: %s' % line
            appuifw.app.body.add(msg)

   def parse(self):
      self.openuri()
      self.safehead()
      self.body()

Annotation number 5: Typos, &c.
Pasted by: sbp
3 years, 7 months ago
Context in IRC logs
Paste contents:
Raw Source | Display As
# Orginal by: crschmidt
# Refactoring by: sbp
# Insight and ideas by: deltab

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 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 getline(self):
      while 1:
         try: rawline = self.u.next()
         except StopIteration: return None
         if not rawline.startswith('#'): break
      return rawline.rstrip()

   def head(self):
      self.title = unicode(self.getline())
      self.urlpattern = self.getline()

      for item in self.getline().split('\t'):
         longname, area = item.split('::', 1)
         self.places[area] = {}
         self.tabnames[area] = unicode(longname)

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

   def body(self):
      while 1:
         line = self.getline()
         if line is None: break
         try:
            area, camera, name = line.split('\t', 2)
            self.places[area][camera] = unicode(name)
            appuifw.app.body.add(u'.')
         except:
            msg = u'\nThe following line is ill-formed: %s' % line
            appuifw.app.body.add(msg)

   def parse(self):
      self.openuri()
      self.safehead()
      self.body()

Colorize as:
Show Line Numbers
Index of paste annotations: 1 | 2 | 3 | 4 | 5

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.