def mangle(line): line = string.strip(line) if (len(line) == 0): return (None, None) if (line[0] == '#'): return (None, line) checksumpos = string.find(line, '?') commentpos = string.find(line, '#') if (commentpos < 0): comment = None else: comment = ' ' + line[commentpos:] line = string.strip(line[0:commentpos]) if (checksumpos == 9): line = string.strip(line[0:checksumpos]) if (commentpos < 0): comment = ' ' + '# generated check sum' else: comment = comment + ' ' + 'Generated check sum' sum = 0 count = 0 for ix in line: sum = sum + (10 - count) * string.atoi(ix) count = count + 1 sum = sum % 11 if (sum != 0): sum = 11 - sum if (sum == 10): line = line + 'X' else: line = line + string.digits[sum] return (line, comment)