Specifications
63
MOMSN =
AttachmentName[AttachmentName.index('_')+1:AttachmentName.index('.')]
ThisIMEIDir = BaseDir + '\\' + IMEI + '\\'#TODO make it more portable using
the path module
if not glob.glob(ThisIMEIDir): #this IMEI has already been seen
os.mkdir(BaseDir + '\\' + IMEI.encode(UnicodeEncoding))#TODO make it
more portable using the path module
Attachment.WriteToFile(ThisIMEIDir + AttachmentName)#TODO add
exceptions handling
with open(ThisIMEIDir + AttachmentName, 'rb') as InFile:#TODO add
exceptions handling
IsTooLong = False
IsTooShort = False
DataLine = InFile.read(420)
if len(DataLine) == 0: break
if DataLine[0].isdigit():
IsKnownBinaryFormat = False
MessageFormatNum = -9999
else:
MessageFormatNum = ord(DataLine[0])
try:
MessageFormat = FormatSpec[MessageFormatNum]
IsKnownBinaryFormat = True
except KeyError:
IsKnownBinaryFormat = False
UnknMsgFormNum = MessageFormatNum
if IsKnownBinaryFormat:#TODO bring all this "if" into the try logic
above
print '%s-%s (binary)' %(IMEI, MOMSN) , MessageFormat[2]
ExpectedMsgLen = FormatSpec[MessageFormatNum][3]
if len(DataLine) < ExpectedMsgLen:
IsTooShort = True
elif len(DataLine) > ExpectedMsgLen:
IsTooLong = True
BinaryMessage = DataLine[1:]
DataLine = '' #this is a bit crap but works... to be fixed when turning the
decoder into a func
BytePointer = 0
for ValueNum in range(0, MessageFormat[0]):#TODO - use an iterator
instead of indexes
ValueBytes = []
ValueBytesNum =
FormatBytesNum[MessageFormat[1][ValueNum]]
if MessageFormat[1][ValueNum] == 'f':
try:
for offset in range(0,ValueBytesNum):