As with the standard forms file, we read the alternate
forms file a line at a time, in Section 17.16, “Txny.__readAltLine(): Process one line of
the alt file”, which will raise SyntaxError for any line containing an error.
In order that the operator can get multiple errors out of
the file in one run, the current method ignores these
exceptions, but it inspects the error count from the
Log() singleton before and after reading
the file, and terminates execution if the count has changed.
# - - - T x n y . _ _ r e a d A l t
def __readAlt ( self, altFileName ):
'''Process the alternate forms file.
[ altFileName is a string ->
if altFileName names a readable alternate forms file
valid against itself, self.hier, and self.abTab ->
self.taxaTree +:= new taxa from that file
self.abTab +:= new bindings from that file
else ->
Log() +:= error message(s)
raise IOError ]
'''
#-- 1 --
# [ if file (altFileName) can be opened for reading ->
# scan := a Scan instance pointing at the start of
# that file
# errCount := error count from Log()
# else ->
# Log() +:= error message(s)
# raise IOError ]
try:
scan = Scan ( altFileName )
errCount = Log().count()
except IOError, detail:
raise IOError ( "Can't open alternate forms file '%s': "
"%s" % (altFileName, detail) )
#-- 2 --
# [ scan := scan advanced to end of file
# self.taxaTree +:= new taxa from scan
# self.abTab +:= new bindings from scan
# Log() +:= error messages about invalid lines in scan ]
while not scan.atEndFile:
#-- 2 body --
#-- 2.1 --
# [ if line in scan is valid ->
# scan := scan advanced to end of line
# self.taxaTree +:= new taxa from that line
# self.abTab +:= new bindings from that line
# else ->
# scan := scan advanced not past end of line
# Log() +:= error message(s)
try:
self.__readAltLine ( scan )
except SyntaxError:
pass
#-- 2.2 --
# [ scan := scan advanced to next line or end of file,
# whichever comes first ]
scan.nextLine()
#-- 3 --
# [ if Log().count() == errCount ->
# I
# else -> raise IOError ]
scan.close()
netErrCount = Log().count() - errCount
if netErrCount > 0:
raise IOError ( "Execution terminated due to %d errors in "
"the alternate forms file." % netErrCount )