palmos.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. """ Python Character Mapping Codec for PalmOS 3.5.
  2. Written by Sjoerd Mullender (sjoerd@acm.org); based on iso8859_15.py.
  3. """#"
  4. import codecs
  5. ### Codec APIs
  6. class Codec(codecs.Codec):
  7. def encode(self,input,errors='strict'):
  8. return codecs.charmap_encode(input,errors,encoding_table)
  9. def decode(self,input,errors='strict'):
  10. return codecs.charmap_decode(input,errors,decoding_table)
  11. class IncrementalEncoder(codecs.IncrementalEncoder):
  12. def encode(self, input, final=False):
  13. return codecs.charmap_encode(input,self.errors,encoding_table)[0]
  14. class IncrementalDecoder(codecs.IncrementalDecoder):
  15. def decode(self, input, final=False):
  16. return codecs.charmap_decode(input,self.errors,decoding_table)[0]
  17. class StreamWriter(Codec,codecs.StreamWriter):
  18. pass
  19. class StreamReader(Codec,codecs.StreamReader):
  20. pass
  21. ### encodings module API
  22. def getregentry():
  23. return codecs.CodecInfo(
  24. name='palmos',
  25. encode=Codec().encode,
  26. decode=Codec().decode,
  27. incrementalencoder=IncrementalEncoder,
  28. incrementaldecoder=IncrementalDecoder,
  29. streamreader=StreamReader,
  30. streamwriter=StreamWriter,
  31. )
  32. ### Decoding Table
  33. decoding_table = (
  34. '\x00' # 0x00 -> NULL
  35. '\x01' # 0x01 -> START OF HEADING
  36. '\x02' # 0x02 -> START OF TEXT
  37. '\x03' # 0x03 -> END OF TEXT
  38. '\x04' # 0x04 -> END OF TRANSMISSION
  39. '\x05' # 0x05 -> ENQUIRY
  40. '\x06' # 0x06 -> ACKNOWLEDGE
  41. '\x07' # 0x07 -> BELL
  42. '\x08' # 0x08 -> BACKSPACE
  43. '\t' # 0x09 -> HORIZONTAL TABULATION
  44. '\n' # 0x0A -> LINE FEED
  45. '\x0b' # 0x0B -> VERTICAL TABULATION
  46. '\x0c' # 0x0C -> FORM FEED
  47. '\r' # 0x0D -> CARRIAGE RETURN
  48. '\x0e' # 0x0E -> SHIFT OUT
  49. '\x0f' # 0x0F -> SHIFT IN
  50. '\x10' # 0x10 -> DATA LINK ESCAPE
  51. '\x11' # 0x11 -> DEVICE CONTROL ONE
  52. '\x12' # 0x12 -> DEVICE CONTROL TWO
  53. '\x13' # 0x13 -> DEVICE CONTROL THREE
  54. '\x14' # 0x14 -> DEVICE CONTROL FOUR
  55. '\x15' # 0x15 -> NEGATIVE ACKNOWLEDGE
  56. '\x16' # 0x16 -> SYNCHRONOUS IDLE
  57. '\x17' # 0x17 -> END OF TRANSMISSION BLOCK
  58. '\x18' # 0x18 -> CANCEL
  59. '\x19' # 0x19 -> END OF MEDIUM
  60. '\x1a' # 0x1A -> SUBSTITUTE
  61. '\x1b' # 0x1B -> ESCAPE
  62. '\x1c' # 0x1C -> FILE SEPARATOR
  63. '\x1d' # 0x1D -> GROUP SEPARATOR
  64. '\x1e' # 0x1E -> RECORD SEPARATOR
  65. '\x1f' # 0x1F -> UNIT SEPARATOR
  66. ' ' # 0x20 -> SPACE
  67. '!' # 0x21 -> EXCLAMATION MARK
  68. '"' # 0x22 -> QUOTATION MARK
  69. '#' # 0x23 -> NUMBER SIGN
  70. '$' # 0x24 -> DOLLAR SIGN
  71. '%' # 0x25 -> PERCENT SIGN
  72. '&' # 0x26 -> AMPERSAND
  73. "'" # 0x27 -> APOSTROPHE
  74. '(' # 0x28 -> LEFT PARENTHESIS
  75. ')' # 0x29 -> RIGHT PARENTHESIS
  76. '*' # 0x2A -> ASTERISK
  77. '+' # 0x2B -> PLUS SIGN
  78. ',' # 0x2C -> COMMA
  79. '-' # 0x2D -> HYPHEN-MINUS
  80. '.' # 0x2E -> FULL STOP
  81. '/' # 0x2F -> SOLIDUS
  82. '0' # 0x30 -> DIGIT ZERO
  83. '1' # 0x31 -> DIGIT ONE
  84. '2' # 0x32 -> DIGIT TWO
  85. '3' # 0x33 -> DIGIT THREE
  86. '4' # 0x34 -> DIGIT FOUR
  87. '5' # 0x35 -> DIGIT FIVE
  88. '6' # 0x36 -> DIGIT SIX
  89. '7' # 0x37 -> DIGIT SEVEN
  90. '8' # 0x38 -> DIGIT EIGHT
  91. '9' # 0x39 -> DIGIT NINE
  92. ':' # 0x3A -> COLON
  93. ';' # 0x3B -> SEMICOLON
  94. '<' # 0x3C -> LESS-THAN SIGN
  95. '=' # 0x3D -> EQUALS SIGN
  96. '>' # 0x3E -> GREATER-THAN SIGN
  97. '?' # 0x3F -> QUESTION MARK
  98. '@' # 0x40 -> COMMERCIAL AT
  99. 'A' # 0x41 -> LATIN CAPITAL LETTER A
  100. 'B' # 0x42 -> LATIN CAPITAL LETTER B
  101. 'C' # 0x43 -> LATIN CAPITAL LETTER C
  102. 'D' # 0x44 -> LATIN CAPITAL LETTER D
  103. 'E' # 0x45 -> LATIN CAPITAL LETTER E
  104. 'F' # 0x46 -> LATIN CAPITAL LETTER F
  105. 'G' # 0x47 -> LATIN CAPITAL LETTER G
  106. 'H' # 0x48 -> LATIN CAPITAL LETTER H
  107. 'I' # 0x49 -> LATIN CAPITAL LETTER I
  108. 'J' # 0x4A -> LATIN CAPITAL LETTER J
  109. 'K' # 0x4B -> LATIN CAPITAL LETTER K
  110. 'L' # 0x4C -> LATIN CAPITAL LETTER L
  111. 'M' # 0x4D -> LATIN CAPITAL LETTER M
  112. 'N' # 0x4E -> LATIN CAPITAL LETTER N
  113. 'O' # 0x4F -> LATIN CAPITAL LETTER O
  114. 'P' # 0x50 -> LATIN CAPITAL LETTER P
  115. 'Q' # 0x51 -> LATIN CAPITAL LETTER Q
  116. 'R' # 0x52 -> LATIN CAPITAL LETTER R
  117. 'S' # 0x53 -> LATIN CAPITAL LETTER S
  118. 'T' # 0x54 -> LATIN CAPITAL LETTER T
  119. 'U' # 0x55 -> LATIN CAPITAL LETTER U
  120. 'V' # 0x56 -> LATIN CAPITAL LETTER V
  121. 'W' # 0x57 -> LATIN CAPITAL LETTER W
  122. 'X' # 0x58 -> LATIN CAPITAL LETTER X
  123. 'Y' # 0x59 -> LATIN CAPITAL LETTER Y
  124. 'Z' # 0x5A -> LATIN CAPITAL LETTER Z
  125. '[' # 0x5B -> LEFT SQUARE BRACKET
  126. '\\' # 0x5C -> REVERSE SOLIDUS
  127. ']' # 0x5D -> RIGHT SQUARE BRACKET
  128. '^' # 0x5E -> CIRCUMFLEX ACCENT
  129. '_' # 0x5F -> LOW LINE
  130. '`' # 0x60 -> GRAVE ACCENT
  131. 'a' # 0x61 -> LATIN SMALL LETTER A
  132. 'b' # 0x62 -> LATIN SMALL LETTER B
  133. 'c' # 0x63 -> LATIN SMALL LETTER C
  134. 'd' # 0x64 -> LATIN SMALL LETTER D
  135. 'e' # 0x65 -> LATIN SMALL LETTER E
  136. 'f' # 0x66 -> LATIN SMALL LETTER F
  137. 'g' # 0x67 -> LATIN SMALL LETTER G
  138. 'h' # 0x68 -> LATIN SMALL LETTER H
  139. 'i' # 0x69 -> LATIN SMALL LETTER I
  140. 'j' # 0x6A -> LATIN SMALL LETTER J
  141. 'k' # 0x6B -> LATIN SMALL LETTER K
  142. 'l' # 0x6C -> LATIN SMALL LETTER L
  143. 'm' # 0x6D -> LATIN SMALL LETTER M
  144. 'n' # 0x6E -> LATIN SMALL LETTER N
  145. 'o' # 0x6F -> LATIN SMALL LETTER O
  146. 'p' # 0x70 -> LATIN SMALL LETTER P
  147. 'q' # 0x71 -> LATIN SMALL LETTER Q
  148. 'r' # 0x72 -> LATIN SMALL LETTER R
  149. 's' # 0x73 -> LATIN SMALL LETTER S
  150. 't' # 0x74 -> LATIN SMALL LETTER T
  151. 'u' # 0x75 -> LATIN SMALL LETTER U
  152. 'v' # 0x76 -> LATIN SMALL LETTER V
  153. 'w' # 0x77 -> LATIN SMALL LETTER W
  154. 'x' # 0x78 -> LATIN SMALL LETTER X
  155. 'y' # 0x79 -> LATIN SMALL LETTER Y
  156. 'z' # 0x7A -> LATIN SMALL LETTER Z
  157. '{' # 0x7B -> LEFT CURLY BRACKET
  158. '|' # 0x7C -> VERTICAL LINE
  159. '}' # 0x7D -> RIGHT CURLY BRACKET
  160. '~' # 0x7E -> TILDE
  161. '\x7f' # 0x7F -> DELETE
  162. '\u20ac' # 0x80 -> EURO SIGN
  163. '\x81' # 0x81 -> <control>
  164. '\u201a' # 0x82 -> SINGLE LOW-9 QUOTATION MARK
  165. '\u0192' # 0x83 -> LATIN SMALL LETTER F WITH HOOK
  166. '\u201e' # 0x84 -> DOUBLE LOW-9 QUOTATION MARK
  167. '\u2026' # 0x85 -> HORIZONTAL ELLIPSIS
  168. '\u2020' # 0x86 -> DAGGER
  169. '\u2021' # 0x87 -> DOUBLE DAGGER
  170. '\u02c6' # 0x88 -> MODIFIER LETTER CIRCUMFLEX ACCENT
  171. '\u2030' # 0x89 -> PER MILLE SIGN
  172. '\u0160' # 0x8A -> LATIN CAPITAL LETTER S WITH CARON
  173. '\u2039' # 0x8B -> SINGLE LEFT-POINTING ANGLE QUOTATION MARK
  174. '\u0152' # 0x8C -> LATIN CAPITAL LIGATURE OE
  175. '\u2666' # 0x8D -> BLACK DIAMOND SUIT
  176. '\u2663' # 0x8E -> BLACK CLUB SUIT
  177. '\u2665' # 0x8F -> BLACK HEART SUIT
  178. '\u2660' # 0x90 -> BLACK SPADE SUIT
  179. '\u2018' # 0x91 -> LEFT SINGLE QUOTATION MARK
  180. '\u2019' # 0x92 -> RIGHT SINGLE QUOTATION MARK
  181. '\u201c' # 0x93 -> LEFT DOUBLE QUOTATION MARK
  182. '\u201d' # 0x94 -> RIGHT DOUBLE QUOTATION MARK
  183. '\u2022' # 0x95 -> BULLET
  184. '\u2013' # 0x96 -> EN DASH
  185. '\u2014' # 0x97 -> EM DASH
  186. '\u02dc' # 0x98 -> SMALL TILDE
  187. '\u2122' # 0x99 -> TRADE MARK SIGN
  188. '\u0161' # 0x9A -> LATIN SMALL LETTER S WITH CARON
  189. '\x9b' # 0x9B -> <control>
  190. '\u0153' # 0x9C -> LATIN SMALL LIGATURE OE
  191. '\x9d' # 0x9D -> <control>
  192. '\x9e' # 0x9E -> <control>
  193. '\u0178' # 0x9F -> LATIN CAPITAL LETTER Y WITH DIAERESIS
  194. '\xa0' # 0xA0 -> NO-BREAK SPACE
  195. '\xa1' # 0xA1 -> INVERTED EXCLAMATION MARK
  196. '\xa2' # 0xA2 -> CENT SIGN
  197. '\xa3' # 0xA3 -> POUND SIGN
  198. '\xa4' # 0xA4 -> CURRENCY SIGN
  199. '\xa5' # 0xA5 -> YEN SIGN
  200. '\xa6' # 0xA6 -> BROKEN BAR
  201. '\xa7' # 0xA7 -> SECTION SIGN
  202. '\xa8' # 0xA8 -> DIAERESIS
  203. '\xa9' # 0xA9 -> COPYRIGHT SIGN
  204. '\xaa' # 0xAA -> FEMININE ORDINAL INDICATOR
  205. '\xab' # 0xAB -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
  206. '\xac' # 0xAC -> NOT SIGN
  207. '\xad' # 0xAD -> SOFT HYPHEN
  208. '\xae' # 0xAE -> REGISTERED SIGN
  209. '\xaf' # 0xAF -> MACRON
  210. '\xb0' # 0xB0 -> DEGREE SIGN
  211. '\xb1' # 0xB1 -> PLUS-MINUS SIGN
  212. '\xb2' # 0xB2 -> SUPERSCRIPT TWO
  213. '\xb3' # 0xB3 -> SUPERSCRIPT THREE
  214. '\xb4' # 0xB4 -> ACUTE ACCENT
  215. '\xb5' # 0xB5 -> MICRO SIGN
  216. '\xb6' # 0xB6 -> PILCROW SIGN
  217. '\xb7' # 0xB7 -> MIDDLE DOT
  218. '\xb8' # 0xB8 -> CEDILLA
  219. '\xb9' # 0xB9 -> SUPERSCRIPT ONE
  220. '\xba' # 0xBA -> MASCULINE ORDINAL INDICATOR
  221. '\xbb' # 0xBB -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
  222. '\xbc' # 0xBC -> VULGAR FRACTION ONE QUARTER
  223. '\xbd' # 0xBD -> VULGAR FRACTION ONE HALF
  224. '\xbe' # 0xBE -> VULGAR FRACTION THREE QUARTERS
  225. '\xbf' # 0xBF -> INVERTED QUESTION MARK
  226. '\xc0' # 0xC0 -> LATIN CAPITAL LETTER A WITH GRAVE
  227. '\xc1' # 0xC1 -> LATIN CAPITAL LETTER A WITH ACUTE
  228. '\xc2' # 0xC2 -> LATIN CAPITAL LETTER A WITH CIRCUMFLEX
  229. '\xc3' # 0xC3 -> LATIN CAPITAL LETTER A WITH TILDE
  230. '\xc4' # 0xC4 -> LATIN CAPITAL LETTER A WITH DIAERESIS
  231. '\xc5' # 0xC5 -> LATIN CAPITAL LETTER A WITH RING ABOVE
  232. '\xc6' # 0xC6 -> LATIN CAPITAL LETTER AE
  233. '\xc7' # 0xC7 -> LATIN CAPITAL LETTER C WITH CEDILLA
  234. '\xc8' # 0xC8 -> LATIN CAPITAL LETTER E WITH GRAVE
  235. '\xc9' # 0xC9 -> LATIN CAPITAL LETTER E WITH ACUTE
  236. '\xca' # 0xCA -> LATIN CAPITAL LETTER E WITH CIRCUMFLEX
  237. '\xcb' # 0xCB -> LATIN CAPITAL LETTER E WITH DIAERESIS
  238. '\xcc' # 0xCC -> LATIN CAPITAL LETTER I WITH GRAVE
  239. '\xcd' # 0xCD -> LATIN CAPITAL LETTER I WITH ACUTE
  240. '\xce' # 0xCE -> LATIN CAPITAL LETTER I WITH CIRCUMFLEX
  241. '\xcf' # 0xCF -> LATIN CAPITAL LETTER I WITH DIAERESIS
  242. '\xd0' # 0xD0 -> LATIN CAPITAL LETTER ETH (Icelandic)
  243. '\xd1' # 0xD1 -> LATIN CAPITAL LETTER N WITH TILDE
  244. '\xd2' # 0xD2 -> LATIN CAPITAL LETTER O WITH GRAVE
  245. '\xd3' # 0xD3 -> LATIN CAPITAL LETTER O WITH ACUTE
  246. '\xd4' # 0xD4 -> LATIN CAPITAL LETTER O WITH CIRCUMFLEX
  247. '\xd5' # 0xD5 -> LATIN CAPITAL LETTER O WITH TILDE
  248. '\xd6' # 0xD6 -> LATIN CAPITAL LETTER O WITH DIAERESIS
  249. '\xd7' # 0xD7 -> MULTIPLICATION SIGN
  250. '\xd8' # 0xD8 -> LATIN CAPITAL LETTER O WITH STROKE
  251. '\xd9' # 0xD9 -> LATIN CAPITAL LETTER U WITH GRAVE
  252. '\xda' # 0xDA -> LATIN CAPITAL LETTER U WITH ACUTE
  253. '\xdb' # 0xDB -> LATIN CAPITAL LETTER U WITH CIRCUMFLEX
  254. '\xdc' # 0xDC -> LATIN CAPITAL LETTER U WITH DIAERESIS
  255. '\xdd' # 0xDD -> LATIN CAPITAL LETTER Y WITH ACUTE
  256. '\xde' # 0xDE -> LATIN CAPITAL LETTER THORN (Icelandic)
  257. '\xdf' # 0xDF -> LATIN SMALL LETTER SHARP S (German)
  258. '\xe0' # 0xE0 -> LATIN SMALL LETTER A WITH GRAVE
  259. '\xe1' # 0xE1 -> LATIN SMALL LETTER A WITH ACUTE
  260. '\xe2' # 0xE2 -> LATIN SMALL LETTER A WITH CIRCUMFLEX
  261. '\xe3' # 0xE3 -> LATIN SMALL LETTER A WITH TILDE
  262. '\xe4' # 0xE4 -> LATIN SMALL LETTER A WITH DIAERESIS
  263. '\xe5' # 0xE5 -> LATIN SMALL LETTER A WITH RING ABOVE
  264. '\xe6' # 0xE6 -> LATIN SMALL LETTER AE
  265. '\xe7' # 0xE7 -> LATIN SMALL LETTER C WITH CEDILLA
  266. '\xe8' # 0xE8 -> LATIN SMALL LETTER E WITH GRAVE
  267. '\xe9' # 0xE9 -> LATIN SMALL LETTER E WITH ACUTE
  268. '\xea' # 0xEA -> LATIN SMALL LETTER E WITH CIRCUMFLEX
  269. '\xeb' # 0xEB -> LATIN SMALL LETTER E WITH DIAERESIS
  270. '\xec' # 0xEC -> LATIN SMALL LETTER I WITH GRAVE
  271. '\xed' # 0xED -> LATIN SMALL LETTER I WITH ACUTE
  272. '\xee' # 0xEE -> LATIN SMALL LETTER I WITH CIRCUMFLEX
  273. '\xef' # 0xEF -> LATIN SMALL LETTER I WITH DIAERESIS
  274. '\xf0' # 0xF0 -> LATIN SMALL LETTER ETH (Icelandic)
  275. '\xf1' # 0xF1 -> LATIN SMALL LETTER N WITH TILDE
  276. '\xf2' # 0xF2 -> LATIN SMALL LETTER O WITH GRAVE
  277. '\xf3' # 0xF3 -> LATIN SMALL LETTER O WITH ACUTE
  278. '\xf4' # 0xF4 -> LATIN SMALL LETTER O WITH CIRCUMFLEX
  279. '\xf5' # 0xF5 -> LATIN SMALL LETTER O WITH TILDE
  280. '\xf6' # 0xF6 -> LATIN SMALL LETTER O WITH DIAERESIS
  281. '\xf7' # 0xF7 -> DIVISION SIGN
  282. '\xf8' # 0xF8 -> LATIN SMALL LETTER O WITH STROKE
  283. '\xf9' # 0xF9 -> LATIN SMALL LETTER U WITH GRAVE
  284. '\xfa' # 0xFA -> LATIN SMALL LETTER U WITH ACUTE
  285. '\xfb' # 0xFB -> LATIN SMALL LETTER U WITH CIRCUMFLEX
  286. '\xfc' # 0xFC -> LATIN SMALL LETTER U WITH DIAERESIS
  287. '\xfd' # 0xFD -> LATIN SMALL LETTER Y WITH ACUTE
  288. '\xfe' # 0xFE -> LATIN SMALL LETTER THORN (Icelandic)
  289. '\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS
  290. )
  291. ### Encoding table
  292. encoding_table=codecs.charmap_build(decoding_table)