fixed rangetoken issue with single byte values

This commit is contained in:
Binh 2012-07-10 15:41:47 -05:00
parent e8145c5616
commit b3aed20388
2 changed files with 13 additions and 23 deletions

View file

@ -97,7 +97,7 @@ class RangeToken(BaseToken):
@property
def value(self):
if '-' not in self._value:
return int(self._value)
return 1
return reduce(lambda x,y: y-x, map(int, self._value.split('-')))+1
@property

View file

@ -1,24 +1,16 @@
#!/usr/bin/python
from pyaccuwage.parser import RecordBuilder
from pyaccuwage.pdfexport import PDFRecordFinder
from pyaccuwage.pdfextract import PDFRecordFinder
import argparse
import sys
import os
parser = argparse.ArgumentParser(description="Parse and convert contents of IRS files into pyaccuwage e-file classes.")
parser.add_argument("-i", "--input", nargs=1, required=True, metavar="file", type=argparse.FileType('r'), help="Source PDF file, ie: p1220.pdf")
parser.add_argument("-f", "--full", help="Generate full python file, including related imports.", action="store_true")
parser.add_argument("-i", "--input", metavar="file", type=argparse.FileType('r'), help="Source PDF file, ie: p1220.pdf")
args = parser.parse_args()
"""
lines = []
for x in sys.stdin.readlines():
lines.append(x)
pdp = PastedDefParser()
tokens = pdp.load("".join(lines))
"""
def generate_imports():
return "\n".join([
"from pyaccuwage import model",
@ -33,15 +25,13 @@ def generate_class_begin(name):
if args.full:
sys.stdout.write(generate_imports())
if args.classname:
classname = args.classname
else:
classname = "GeneratedRecord"
sys.stdout.write(generate_class_begin(classname))
for x in tokens:
sys.stdout.write('\t' + x + '\n')
source_file = os.path.abspath(args.input[0].name)
doc = PDFRecordFinder(source_file)
records = doc.records()
builder = RecordBuilder()
for rec in records:
print 'name', rec[0]
for field in builder.load(map(lambda x:x.tuple, rec[1][1:])):
print field