1""" Python Character Mapping Codec koi8_t 2""" 3# http://ru.wikipedia.org/wiki/КОИ-8 4# http://www.opensource.apple.com/source/libiconv/libiconv-4/libiconv/tests/KOI8-T.TXT 5 6import codecs 7 8### Codec APIs 9 10class Codec(codecs.Codec): 11 12 def encode(self,input,errors='strict'): 13 return codecs.charmap_encode(input,errors,encoding_table) 14 15 def decode(self,input,errors='strict'): 16 return codecs.charmap_decode(input,errors,decoding_table) 17 18class IncrementalEncoder(codecs.IncrementalEncoder): 19 def encode(self, input, final=False): 20 return codecs.charmap_encode(input,self.errors,encoding_table)[0] 21 22class IncrementalDecoder(codecs.IncrementalDecoder): 23 def decode(self, input, final=False): 24 return codecs.charmap_decode(input,self.errors,decoding_table)[0] 25 26class StreamWriter(Codec,codecs.StreamWriter): 27 pass 28 29class StreamReader(Codec,codecs.StreamReader): 30 pass 31 32### encodings module API 33 34def getregentry(): 35 return codecs.CodecInfo( 36 name='koi8-t', 37 encode=Codec().encode, 38 decode=Codec().decode, 39 incrementalencoder=IncrementalEncoder, 40 incrementaldecoder=IncrementalDecoder, 41 streamreader=StreamReader, 42 streamwriter=StreamWriter, 43 ) 44 45 46### Decoding Table 47 48decoding_table = ( 49 '\x00' # 0x00 -> NULL 50 '\x01' # 0x01 -> START OF HEADING 51 '\x02' # 0x02 -> START OF TEXT 52 '\x03' # 0x03 -> END OF TEXT 53 '\x04' # 0x04 -> END OF TRANSMISSION 54 '\x05' # 0x05 -> ENQUIRY 55 '\x06' # 0x06 -> ACKNOWLEDGE 56 '\x07' # 0x07 -> BELL 57 '\x08' # 0x08 -> BACKSPACE 58 '\t' # 0x09 -> HORIZONTAL TABULATION 59 '\n' # 0x0A -> LINE FEED 60 '\x0b' # 0x0B -> VERTICAL TABULATION 61 '\x0c' # 0x0C -> FORM FEED 62 '\r' # 0x0D -> CARRIAGE RETURN 63 '\x0e' # 0x0E -> SHIFT OUT 64 '\x0f' # 0x0F -> SHIFT IN 65 '\x10' # 0x10 -> DATA LINK ESCAPE 66 '\x11' # 0x11 -> DEVICE CONTROL ONE 67 '\x12' # 0x12 -> DEVICE CONTROL TWO 68 '\x13' # 0x13 -> DEVICE CONTROL THREE 69 '\x14' # 0x14 -> DEVICE CONTROL FOUR 70 '\x15' # 0x15 -> NEGATIVE ACKNOWLEDGE 71 '\x16' # 0x16 -> SYNCHRONOUS IDLE 72 '\x17' # 0x17 -> END OF TRANSMISSION BLOCK 73 '\x18' # 0x18 -> CANCEL 74 '\x19' # 0x19 -> END OF MEDIUM 75 '\x1a' # 0x1A -> SUBSTITUTE 76 '\x1b' # 0x1B -> ESCAPE 77 '\x1c' # 0x1C -> FILE SEPARATOR 78 '\x1d' # 0x1D -> GROUP SEPARATOR 79 '\x1e' # 0x1E -> RECORD SEPARATOR 80 '\x1f' # 0x1F -> UNIT SEPARATOR 81 ' ' # 0x20 -> SPACE 82 '!' # 0x21 -> EXCLAMATION MARK 83 '"' # 0x22 -> QUOTATION MARK 84 '#' # 0x23 -> NUMBER SIGN 85 '$' # 0x24 -> DOLLAR SIGN 86 '%' # 0x25 -> PERCENT SIGN 87 '&' # 0x26 -> AMPERSAND 88 "'" # 0x27 -> APOSTROPHE 89 '(' # 0x28 -> LEFT PARENTHESIS 90 ')' # 0x29 -> RIGHT PARENTHESIS 91 '*' # 0x2A -> ASTERISK 92 '+' # 0x2B -> PLUS SIGN 93 ',' # 0x2C -> COMMA 94 '-' # 0x2D -> HYPHEN-MINUS 95 '.' # 0x2E -> FULL STOP 96 '/' # 0x2F -> SOLIDUS 97 '0' # 0x30 -> DIGIT ZERO 98 '1' # 0x31 -> DIGIT ONE 99 '2' # 0x32 -> DIGIT TWO 100 '3' # 0x33 -> DIGIT THREE 101 '4' # 0x34 -> DIGIT FOUR 102 '5' # 0x35 -> DIGIT FIVE 103 '6' # 0x36 -> DIGIT SIX 104 '7' # 0x37 -> DIGIT SEVEN 105 '8' # 0x38 -> DIGIT EIGHT 106 '9' # 0x39 -> DIGIT NINE 107 ':' # 0x3A -> COLON 108 ';' # 0x3B -> SEMICOLON 109 '<' # 0x3C -> LESS-THAN SIGN 110 '=' # 0x3D -> EQUALS SIGN 111 '>' # 0x3E -> GREATER-THAN SIGN 112 '?' # 0x3F -> QUESTION MARK 113 '@' # 0x40 -> COMMERCIAL AT 114 'A' # 0x41 -> LATIN CAPITAL LETTER A 115 'B' # 0x42 -> LATIN CAPITAL LETTER B 116 'C' # 0x43 -> LATIN CAPITAL LETTER C 117 'D' # 0x44 -> LATIN CAPITAL LETTER D 118 'E' # 0x45 -> LATIN CAPITAL LETTER E 119 'F' # 0x46 -> LATIN CAPITAL LETTER F 120 'G' # 0x47 -> LATIN CAPITAL LETTER G 121 'H' # 0x48 -> LATIN CAPITAL LETTER H 122 'I' # 0x49 -> LATIN CAPITAL LETTER I 123 'J' # 0x4A -> LATIN CAPITAL LETTER J 124 'K' # 0x4B -> LATIN CAPITAL LETTER K 125 'L' # 0x4C -> LATIN CAPITAL LETTER L 126 'M' # 0x4D -> LATIN CAPITAL LETTER M 127 'N' # 0x4E -> LATIN CAPITAL LETTER N 128 'O' # 0x4F -> LATIN CAPITAL LETTER O 129 'P' # 0x50 -> LATIN CAPITAL LETTER P 130 'Q' # 0x51 -> LATIN CAPITAL LETTER Q 131 'R' # 0x52 -> LATIN CAPITAL LETTER R 132 'S' # 0x53 -> LATIN CAPITAL LETTER S 133 'T' # 0x54 -> LATIN CAPITAL LETTER T 134 'U' # 0x55 -> LATIN CAPITAL LETTER U 135 'V' # 0x56 -> LATIN CAPITAL LETTER V 136 'W' # 0x57 -> LATIN CAPITAL LETTER W 137 'X' # 0x58 -> LATIN CAPITAL LETTER X 138 'Y' # 0x59 -> LATIN CAPITAL LETTER Y 139 'Z' # 0x5A -> LATIN CAPITAL LETTER Z 140 '[' # 0x5B -> LEFT SQUARE BRACKET 141 '\\' # 0x5C -> REVERSE SOLIDUS 142 ']' # 0x5D -> RIGHT SQUARE BRACKET 143 '^' # 0x5E -> CIRCUMFLEX ACCENT 144 '_' # 0x5F -> LOW LINE 145 '`' # 0x60 -> GRAVE ACCENT 146 'a' # 0x61 -> LATIN SMALL LETTER A 147 'b' # 0x62 -> LATIN SMALL LETTER B 148 'c' # 0x63 -> LATIN SMALL LETTER C 149 'd' # 0x64 -> LATIN SMALL LETTER D 150 'e' # 0x65 -> LATIN SMALL LETTER E 151 'f' # 0x66 -> LATIN SMALL LETTER F 152 'g' # 0x67 -> LATIN SMALL LETTER G 153 'h' # 0x68 -> LATIN SMALL LETTER H 154 'i' # 0x69 -> LATIN SMALL LETTER I 155 'j' # 0x6A -> LATIN SMALL LETTER J 156 'k' # 0x6B -> LATIN SMALL LETTER K 157 'l' # 0x6C -> LATIN SMALL LETTER L 158 'm' # 0x6D -> LATIN SMALL LETTER M 159 'n' # 0x6E -> LATIN SMALL LETTER N 160 'o' # 0x6F -> LATIN SMALL LETTER O 161 'p' # 0x70 -> LATIN SMALL LETTER P 162 'q' # 0x71 -> LATIN SMALL LETTER Q 163 'r' # 0x72 -> LATIN SMALL LETTER R 164 's' # 0x73 -> LATIN SMALL LETTER S 165 't' # 0x74 -> LATIN SMALL LETTER T 166 'u' # 0x75 -> LATIN SMALL LETTER U 167 'v' # 0x76 -> LATIN SMALL LETTER V 168 'w' # 0x77 -> LATIN SMALL LETTER W 169 'x' # 0x78 -> LATIN SMALL LETTER X 170 'y' # 0x79 -> LATIN SMALL LETTER Y 171 'z' # 0x7A -> LATIN SMALL LETTER Z 172 '{' # 0x7B -> LEFT CURLY BRACKET 173 '|' # 0x7C -> VERTICAL LINE 174 '}' # 0x7D -> RIGHT CURLY BRACKET 175 '~' # 0x7E -> TILDE 176 '\x7f' # 0x7F -> DELETE 177 '\u049b' # 0x80 -> CYRILLIC SMALL LETTER KA WITH DESCENDER 178 '\u0493' # 0x81 -> CYRILLIC SMALL LETTER GHE WITH STROKE 179 '\u201a' # 0x82 -> SINGLE LOW-9 QUOTATION MARK 180 '\u0492' # 0x83 -> CYRILLIC CAPITAL LETTER GHE WITH STROKE 181 '\u201e' # 0x84 -> DOUBLE LOW-9 QUOTATION MARK 182 '\u2026' # 0x85 -> HORIZONTAL ELLIPSIS 183 '\u2020' # 0x86 -> DAGGER 184 '\u2021' # 0x87 -> DOUBLE DAGGER 185 '\ufffe' # 0x88 -> UNDEFINED 186 '\u2030' # 0x89 -> PER MILLE SIGN 187 '\u04b3' # 0x8A -> CYRILLIC SMALL LETTER HA WITH DESCENDER 188 '\u2039' # 0x8B -> SINGLE LEFT-POINTING ANGLE QUOTATION MARK 189 '\u04b2' # 0x8C -> CYRILLIC CAPITAL LETTER HA WITH DESCENDER 190 '\u04b7' # 0x8D -> CYRILLIC SMALL LETTER CHE WITH DESCENDER 191 '\u04b6' # 0x8E -> CYRILLIC CAPITAL LETTER CHE WITH DESCENDER 192 '\ufffe' # 0x8F -> UNDEFINED 193 '\u049a' # 0x90 -> CYRILLIC CAPITAL LETTER KA WITH DESCENDER 194 '\u2018' # 0x91 -> LEFT SINGLE QUOTATION MARK 195 '\u2019' # 0x92 -> RIGHT SINGLE QUOTATION MARK 196 '\u201c' # 0x93 -> LEFT DOUBLE QUOTATION MARK 197 '\u201d' # 0x94 -> RIGHT DOUBLE QUOTATION MARK 198 '\u2022' # 0x95 -> BULLET 199 '\u2013' # 0x96 -> EN DASH 200 '\u2014' # 0x97 -> EM DASH 201 '\ufffe' # 0x98 -> UNDEFINED 202 '\u2122' # 0x99 -> TRADE MARK SIGN 203 '\ufffe' # 0x9A -> UNDEFINED 204 '\u203a' # 0x9B -> SINGLE RIGHT-POINTING ANGLE QUOTATION MARK 205 '\ufffe' # 0x9C -> UNDEFINED 206 '\ufffe' # 0x9D -> UNDEFINED 207 '\ufffe' # 0x9E -> UNDEFINED 208 '\ufffe' # 0x9F -> UNDEFINED 209 '\ufffe' # 0xA0 -> UNDEFINED 210 '\u04ef' # 0xA1 -> CYRILLIC SMALL LETTER U WITH MACRON 211 '\u04ee' # 0xA2 -> CYRILLIC CAPITAL LETTER U WITH MACRON 212 '\u0451' # 0xA3 -> CYRILLIC SMALL LETTER IO 213 '\xa4' # 0xA4 -> CURRENCY SIGN 214 '\u04e3' # 0xA5 -> CYRILLIC SMALL LETTER I WITH MACRON 215 '\xa6' # 0xA6 -> BROKEN BAR 216 '\xa7' # 0xA7 -> SECTION SIGN 217 '\ufffe' # 0xA8 -> UNDEFINED 218 '\ufffe' # 0xA9 -> UNDEFINED 219 '\ufffe' # 0xAA -> UNDEFINED 220 '\xab' # 0xAB -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK 221 '\xac' # 0xAC -> NOT SIGN 222 '\xad' # 0xAD -> SOFT HYPHEN 223 '\xae' # 0xAE -> REGISTERED SIGN 224 '\ufffe' # 0xAF -> UNDEFINED 225 '\xb0' # 0xB0 -> DEGREE SIGN 226 '\xb1' # 0xB1 -> PLUS-MINUS SIGN 227 '\xb2' # 0xB2 -> SUPERSCRIPT TWO 228 '\u0401' # 0xB3 -> CYRILLIC CAPITAL LETTER IO 229 '\ufffe' # 0xB4 -> UNDEFINED 230 '\u04e2' # 0xB5 -> CYRILLIC CAPITAL LETTER I WITH MACRON 231 '\xb6' # 0xB6 -> PILCROW SIGN 232 '\xb7' # 0xB7 -> MIDDLE DOT 233 '\ufffe' # 0xB8 -> UNDEFINED 234 '\u2116' # 0xB9 -> NUMERO SIGN 235 '\ufffe' # 0xBA -> UNDEFINED 236 '\xbb' # 0xBB -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK 237 '\ufffe' # 0xBC -> UNDEFINED 238 '\ufffe' # 0xBD -> UNDEFINED 239 '\ufffe' # 0xBE -> UNDEFINED 240 '\xa9' # 0xBF -> COPYRIGHT SIGN 241 '\u044e' # 0xC0 -> CYRILLIC SMALL LETTER YU 242 '\u0430' # 0xC1 -> CYRILLIC SMALL LETTER A 243 '\u0431' # 0xC2 -> CYRILLIC SMALL LETTER BE 244 '\u0446' # 0xC3 -> CYRILLIC SMALL LETTER TSE 245 '\u0434' # 0xC4 -> CYRILLIC SMALL LETTER DE 246 '\u0435' # 0xC5 -> CYRILLIC SMALL LETTER IE 247 '\u0444' # 0xC6 -> CYRILLIC SMALL LETTER EF 248 '\u0433' # 0xC7 -> CYRILLIC SMALL LETTER GHE 249 '\u0445' # 0xC8 -> CYRILLIC SMALL LETTER HA 250 '\u0438' # 0xC9 -> CYRILLIC SMALL LETTER I 251 '\u0439' # 0xCA -> CYRILLIC SMALL LETTER SHORT I 252 '\u043a' # 0xCB -> CYRILLIC SMALL LETTER KA 253 '\u043b' # 0xCC -> CYRILLIC SMALL LETTER EL 254 '\u043c' # 0xCD -> CYRILLIC SMALL LETTER EM 255 '\u043d' # 0xCE -> CYRILLIC SMALL LETTER EN 256 '\u043e' # 0xCF -> CYRILLIC SMALL LETTER O 257 '\u043f' # 0xD0 -> CYRILLIC SMALL LETTER PE 258 '\u044f' # 0xD1 -> CYRILLIC SMALL LETTER YA 259 '\u0440' # 0xD2 -> CYRILLIC SMALL LETTER ER 260 '\u0441' # 0xD3 -> CYRILLIC SMALL LETTER ES 261 '\u0442' # 0xD4 -> CYRILLIC SMALL LETTER TE 262 '\u0443' # 0xD5 -> CYRILLIC SMALL LETTER U 263 '\u0436' # 0xD6 -> CYRILLIC SMALL LETTER ZHE 264 '\u0432' # 0xD7 -> CYRILLIC SMALL LETTER VE 265 '\u044c' # 0xD8 -> CYRILLIC SMALL LETTER SOFT SIGN 266 '\u044b' # 0xD9 -> CYRILLIC SMALL LETTER YERU 267 '\u0437' # 0xDA -> CYRILLIC SMALL LETTER ZE 268 '\u0448' # 0xDB -> CYRILLIC SMALL LETTER SHA 269 '\u044d' # 0xDC -> CYRILLIC SMALL LETTER E 270 '\u0449' # 0xDD -> CYRILLIC SMALL LETTER SHCHA 271 '\u0447' # 0xDE -> CYRILLIC SMALL LETTER CHE 272 '\u044a' # 0xDF -> CYRILLIC SMALL LETTER HARD SIGN 273 '\u042e' # 0xE0 -> CYRILLIC CAPITAL LETTER YU 274 '\u0410' # 0xE1 -> CYRILLIC CAPITAL LETTER A 275 '\u0411' # 0xE2 -> CYRILLIC CAPITAL LETTER BE 276 '\u0426' # 0xE3 -> CYRILLIC CAPITAL LETTER TSE 277 '\u0414' # 0xE4 -> CYRILLIC CAPITAL LETTER DE 278 '\u0415' # 0xE5 -> CYRILLIC CAPITAL LETTER IE 279 '\u0424' # 0xE6 -> CYRILLIC CAPITAL LETTER EF 280 '\u0413' # 0xE7 -> CYRILLIC CAPITAL LETTER GHE 281 '\u0425' # 0xE8 -> CYRILLIC CAPITAL LETTER HA 282 '\u0418' # 0xE9 -> CYRILLIC CAPITAL LETTER I 283 '\u0419' # 0xEA -> CYRILLIC CAPITAL LETTER SHORT I 284 '\u041a' # 0xEB -> CYRILLIC CAPITAL LETTER KA 285 '\u041b' # 0xEC -> CYRILLIC CAPITAL LETTER EL 286 '\u041c' # 0xED -> CYRILLIC CAPITAL LETTER EM 287 '\u041d' # 0xEE -> CYRILLIC CAPITAL LETTER EN 288 '\u041e' # 0xEF -> CYRILLIC CAPITAL LETTER O 289 '\u041f' # 0xF0 -> CYRILLIC CAPITAL LETTER PE 290 '\u042f' # 0xF1 -> CYRILLIC CAPITAL LETTER YA 291 '\u0420' # 0xF2 -> CYRILLIC CAPITAL LETTER ER 292 '\u0421' # 0xF3 -> CYRILLIC CAPITAL LETTER ES 293 '\u0422' # 0xF4 -> CYRILLIC CAPITAL LETTER TE 294 '\u0423' # 0xF5 -> CYRILLIC CAPITAL LETTER U 295 '\u0416' # 0xF6 -> CYRILLIC CAPITAL LETTER ZHE 296 '\u0412' # 0xF7 -> CYRILLIC CAPITAL LETTER VE 297 '\u042c' # 0xF8 -> CYRILLIC CAPITAL LETTER SOFT SIGN 298 '\u042b' # 0xF9 -> CYRILLIC CAPITAL LETTER YERU 299 '\u0417' # 0xFA -> CYRILLIC CAPITAL LETTER ZE 300 '\u0428' # 0xFB -> CYRILLIC CAPITAL LETTER SHA 301 '\u042d' # 0xFC -> CYRILLIC CAPITAL LETTER E 302 '\u0429' # 0xFD -> CYRILLIC CAPITAL LETTER SHCHA 303 '\u0427' # 0xFE -> CYRILLIC CAPITAL LETTER CHE 304 '\u042a' # 0xFF -> CYRILLIC CAPITAL LETTER HARD SIGN 305) 306 307### Encoding table 308encoding_table=codecs.charmap_build(decoding_table) 309