def DebugFormat(self): print FormatAsBits((self.output, self.out_boff)) for i in xrange(self.idx_byte * 8 + self.idx_boff - 1): if not i % 8: sys.stdout.write("|") sys.stdout.write("-") print "^"
def DebugFormat(self): """ Prints out (to stdout) a representation intended to help with debugging """ print FormatAsBits((self.output, self.out_boff)) for i in xrange(self.idx_byte * 8 + self.idx_boff - 1): if not i % 8: sys.stdout.write("|") sys.stdout.write("-") print "^"
def main(): h = Huffman(request_freq_table) for s in test_data: print " encoding: ", s sp = [ord(c) for c in s] e_result = h.Encode(sp, False) print " e_result: ", FormatAsBits(e_result) d_result = ''.join(ListToStr(h.Decode(e_result[0], False, e_result[1]))) if d_result != s: print "difference found: ", d_result, " ", s else: print "It worked: ", s print
def main(): h = Huffman(request_freq_table) for s in test_data: print " encoding: ", s sp = [ord(c) for c in s] e_result = BitBucket() h.EncodeToBB(e_result, sp, True) print " e_result: ", FormatAsBits(e_result.GetAllBits()) d_result = ListToStr(h.DecodeFromBB(e_result, True, -1)) if d_result != s: print "difference found: d_result(%s) vs orig(%s)" % (repr(d_result), repr(s)) else: print "It worked: ", s print
def FormatCodeTable(self): """ Makes a formatted version of the code table, useful for debugging """ printable = string.digits + string.letters + string.punctuation + ' ' x = sorted([(i, FormatAsBits(self.code_table[i])) for i in xrange(len(self.code_table))]) retval = [] for entry in x: code, description = entry readable_code = "" if code < 128 and chr(code) in printable: readable_code = "'%c'" % chr(code) while len(readable_code) < 5: readable_code = " " + readable_code retval.append('%s (%3d): %s' % (readable_code, code, description)) return '\n'.join(retval)
def FormatCodeTable(self): """ Makes a formatted version of the code table, useful for debugging """ printable = string.digits + string.letters + string.punctuation + ' ' x = sorted([(i, FormatAsBits(self.code_table[i])) for i in xrange(len(self.code_table))]) retval = [] for entry in x: sym, description = entry code = self.canonical_code_table[sym][1] code_len = self.canonical_code_table[sym][0][1] readable_sym = "" if sym < 128 and chr(sym) in printable: readable_sym = "'%c'" % chr(sym) while len(readable_sym) < 5: readable_sym = " " + readable_sym s = '{0:5s} ({1:>3d}) {2:<40} {3:8x} [{4:}]'.format( readable_sym, sym, description, code, code_len) retval.append(s) return '\n'.join(retval)
def __repr__(self): return FormatAsBits((self.output, self.out_boff))