Example #1
0
File: tags.py Project: tycho/crawl
 def __init__(self, fn):
     f = binfile.reader(fn)
     f.byteorder = ">"
     self.f = f
     self.major, self.minor = f.stream("bb")
     print "  version %d.%d" % (self.major, self.minor)
     if self.major != TAG_MAJOR_VERSION or self.minor > TAG_MINOR_VERSION:
         print "  WARNING: Cannot handle this version!"
     self.tags = dict(self._gen_tags())
Example #2
0
 def __init__(self, fn):
     f = binfile.reader(fn)
     f.byteorder = '>'
     self.f = f
     self.major, self.minor = f.stream('bb')
     print '  version %d.%d' % (self.major, self.minor)
     if (self.major != TAG_MAJOR_VERSION or
         self.minor > TAG_MINOR_VERSION):
         print "  WARNING: Cannot handle this version!"
     self.tags = dict( self._gen_tags() )
Example #3
0
 def _gen_tags(self):
     while True:
         try:
             tag_id, size = self.f.stream('HI')
         except struct.error:
             return
         data = self.f.file.read(size)
         tag_name = TAGS_NAMES[tag_id]
         try:  constructor = TAG_TO_CLASS[tag_name]
         except KeyError:
             print "  Skipping %s" % tag_name
         else:
             print "  Parsing %s" % tag_name
             sub_reader = binfile.reader(StringIO.StringIO(data))
             sub_reader.byteorder = '>'
             data = constructor(sub_reader, self.minor)
         yield (tag_id, data)
Example #4
0
File: tags.py Project: tycho/crawl
 def _gen_tags(self):
     while True:
         try:
             tag_id, size = self.f.stream("HI")
         except struct.error:
             return
         data = self.f.file.read(size)
         tag_name = TAGS_NAMES[tag_id]
         try:
             constructor = TAG_TO_CLASS[tag_name]
         except KeyError:
             print "  Skipping %s" % tag_name
         else:
             print "  Parsing %s" % tag_name
             sub_reader = binfile.reader(StringIO.StringIO(data))
             sub_reader.byteorder = ">"
             data = constructor(sub_reader, self.minor)
         yield (tag_id, data)