1: #line 68 "wansung.ipk" 2: from array import array 3: 4: lead_first = 0x21 5: lead_last = 0x7D 6: trail_first = 0x21 7: trail_last = 0x7E 8: width = trail_last - trail_first + 1 9: kscsize = (lead_last - lead_first + 1) * width 10: 11: 12: tou = array('H') 13: filename = 'interscript/encoding/ksc5601-1987.dat' 14: f = open(filename,'rb') 15: tou.fromfile(f,kscsize) 16: f.close() 17: 18: def ksc5601_1987_to_unicode(ch): 19: hi = ch >> 8 20: lo = ch & 0xFF 21: if lead_first <= hi <= lead_last and trail_first <= lo <= trail_last: 22: return tou[(hi-lead_first)*width+lo-trail_first] 23: else: 24: return 0xFFFF 25: 26: def ksc5601_1987_to_utf8(s): 27: u = '' 28: i = 0 29: n = len(s) 30: while 1: 31: ch = s[i] 32: i = i + 1 33: ch = ch << 8 | s[i] 34: u = u + utf8(ksc5601_1987_to_unicode(ch)) 35: i = i + 1 36: if i==n: break 37: return u 38: