Specifications

59
#what follows should be turned into methods of a future FormatSpecTable object
FormatSpecAreOK = True
for FormatSpecEntry in FormatSpec.iteritems():
#FormatSpecEntry[1][0]
if FormatSpecEntry[1][0] != len(FormatSpecEntry[1][1]):
print 'WARNING: bad format definition for message type %i (%s):\n format
unconsistency (%i values declared but %i specified)' %(FormatSpecEntry[0],
FormatSpecEntry[1][2],FormatSpecEntry[1][0],len(FormatSpecEntry[1][1]))
FormatSpecAreOK = False#sys.exit()
Length = 1#all messages have a trailing one-byte format ID
for ValueFormat in FormatSpecEntry[1][1]:
try:
Length += FormatBytesNum[ValueFormat]
except KeyError:#ValueFormat is not an existing key
Length = -1
print 'WARNING: Bad format definition for message type %i (%s):\n unknown
symbol "%s"' %(FormatSpecEntry[0], FormatSpecEntry[1][2],ValueFormat)
FormatSpecAreOK = False#sys.exit()
try:#if the byte length was specified in the format configuration, check it
if FormatSpec[FormatSpecEntry[0]][3] != Length:
print 'WARNING: Bad format definition for message type %i (%s):\n length
unconsistency (%i bytes declared but %i expected)' %(FormatSpecEntry[0],
FormatSpecEntry[1][2],FormatSpec[FormatSpecEntry[0]][3],Length)
FormatSpecAreOK = False#sys.exit()
except IndexError:#the byte length was not specified in the format configuration, so set
it now
FormatSpec[FormatSpecEntry[0]].append(Length)#it initializes a further element in
the table: the message length in bytes
if not FormatSpecAreOK:
print 'ERROR: the message format specifications need corrections'
sys.exit()
# return Length
UnicodeEncoding = 'cp850'
BaseDir = os.getcwd()
#BaseDir = BaseDir.encode(UnicodeEncoding)
try:
with open(BaseDir + '\\msgshash.dat', 'rb') as msgshash:
IsFirstRun = False
SeenMessageHashes = cPickle.load(msgshash)
except IOError:
IsFirstRun = True
print 'WARNING: msgshash.dat not found. Already processed messages (if any) may
be duplicated\n'