[Bug 6413] Fix importing ProGen files

This isn't a perfect fix because it requires that the ProGen file is
encoded with CP437, which is guaranteed only in Version 3.21 and later.

svn: r21355
This commit is contained in:
John Ralls 2013-02-14 18:41:43 +00:00
parent 8abf7677d6
commit 5d6e2c991a

View File

@ -116,8 +116,8 @@ def _read_mem(bname):
fname = bname + '.mem'
f = open(fname, "rb")
recfmt = "i28s"
reclen = struct.calcsize( recfmt )
#print "# reclen = %d" % reclen
reclen = struct.calcsize( str(recfmt) )
print "# reclen = %d" % reclen
mems = []
while 1:
@ -138,7 +138,7 @@ def _read_recs(table, bname):
f = open(fname, "rb")
recfmt = table.recfmt
log.info("# %s - recfmt = %s" % (table['name1'], recfmt))
reclen = struct.calcsize( recfmt )
reclen = struct.calcsize(str(recfmt))
log.info("# %s - reclen = %d" % (table['name1'], reclen))
recs = []
@ -436,7 +436,8 @@ class PG30_Def_Table:
# Just grab a field
f = self.flds[1]
txt += '"%s"\n' % f
txt += 'recfmt = %s (length=%d)' % (self.recfmt, struct.calcsize(self.recfmt))
txt += 'recfmt = %s (length=%d)' % (self.recfmt,
struct.calcsize(str(self.recfmt)))
return txt
@ -460,9 +461,10 @@ class PG30_Def:
raise ProgenError(_("Cannot find DEF file: %(deffname)s") % locals())
# This can throw a IOError
lines = open(fname).readlines()
import io
lines = io.open(fname, buffering=1, encoding='cp437', errors='strict').readlines()
lines = [l.strip() for l in lines]
content = '\n'.join(lines)
content = '\n'.join(lines).encode('utf-8')
parts = re.split(r'\n(?=\[)', content)
self.parts = {}
self.tables = {}