def list_full_charset(charset, write=sys.stdout.write): table = unicode_mapping(charset) import rfc1345 write("Dec Oct Hex UCS2 Mne %s\n" % recode.registry.aliases[charset][0]) insert_white = True for code in range(256): text = table[code] if text is None: insert_white = True else: if insert_white: write('\n') insert_white = False for character in text: unicode = ord(character) if code is None: write(' + + + ') else: write('%3d %.3o %.2x' % (code, code, code)) write(' %.4X' % unicode) fragments = [' %-3s' % rfc1345.table.get(unicode, '')] description = recode.unicode_description(unicode) if description is not None: fragments.append(description) write(' '.join(fragments).rstrip() + '\n') code = None
def encode(self, input, errors='strict'): if not input: return '', 0 import rfc1345 fragments = [] fragments.append("UCS2 Mne Description\n\n") for character in input: description = recode.unicode_description(ord(character)) or '' fragments.append(( ('%.4X %-3s %s' % (ord(character), rfc1345.table.get(ord(character), ''), description)).rstrip()) + '\n') return ''.join(fragments), len(input)
def encode(self, input, errors='strict'): if not input: return '', 0 import rfc1345 fragments = [] fragments.append("UCS2 Mne Description\n\n") for character in input: description = recode.unicode_description(ord(character)) or '' fragments.append( (('%.4X %-3s %s' % (ord(character), rfc1345.table.get(ord(character), ''), description)) .rstrip()) + '\n') return ''.join(fragments), len(input)