Neal Norwitz | d8407a7 | 2002-10-17 22:15:33 +0000 | [diff] [blame] | 1 | """ Python Character Mapping Codec for KOI8U. |
| 2 | |
| 3 | This character scheme is compliant to RFC2319 |
| 4 | |
| 5 | Written by Marc-Andre Lemburg (mal@lemburg.com). |
| 6 | Modified by Maxim Dzumanenko <mvd@mylinux.com.ua>. |
| 7 | |
| 8 | (c) Copyright 2002, Python Software Foundation. |
| 9 | |
| 10 | """#" |
| 11 | |
| 12 | import codecs, koi8_r |
| 13 | |
| 14 | ### Codec APIs |
| 15 | |
| 16 | class Codec(codecs.Codec): |
| 17 | |
| 18 | def encode(self,input,errors='strict'): |
| 19 | |
| 20 | return codecs.charmap_encode(input,errors,encoding_map) |
| 21 | |
| 22 | def decode(self,input,errors='strict'): |
| 23 | |
| 24 | return codecs.charmap_decode(input,errors,decoding_map) |
| 25 | |
| 26 | class StreamWriter(Codec,codecs.StreamWriter): |
| 27 | pass |
| 28 | |
| 29 | class StreamReader(Codec,codecs.StreamReader): |
| 30 | pass |
| 31 | |
| 32 | ### encodings module API |
| 33 | |
| 34 | def getregentry(): |
| 35 | |
| 36 | return (Codec().encode,Codec().decode,StreamReader,StreamWriter) |
| 37 | |
| 38 | ### Decoding Map |
| 39 | |
| 40 | decoding_map = koi8_r.decoding_map.copy() |
| 41 | decoding_map.update({ |
| 42 | 0x00a4: 0x0454, # CYRILLIC SMALL LETTER UKRAINIAN IE |
| 43 | 0x00a6: 0x0456, # CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I |
| 44 | 0x00a7: 0x0457, # CYRILLIC SMALL LETTER YI (UKRAINIAN) |
| 45 | 0x00ad: 0x0491, # CYRILLIC SMALL LETTER UKRAINIAN GHE WITH UPTURN |
Marc-André Lemburg | 361d66d | 2004-02-23 09:00:43 +0000 | [diff] [blame] | 46 | 0x00b4: 0x0404, # CYRILLIC CAPITAL LETTER UKRAINIAN IE |
Neal Norwitz | d8407a7 | 2002-10-17 22:15:33 +0000 | [diff] [blame] | 47 | 0x00b6: 0x0406, # CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I |
| 48 | 0x00b7: 0x0407, # CYRILLIC CAPITAL LETTER YI (UKRAINIAN) |
| 49 | 0x00bd: 0x0490, # CYRILLIC CAPITAL LETTER UKRAINIAN GHE WITH UPTURN |
| 50 | }) |
| 51 | |
| 52 | ### Encoding Map |
| 53 | |
| 54 | encoding_map = codecs.make_encoding_map(decoding_map) |