palmos.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_map)
  9. def decode(self,input,errors='strict'):
  10. return codecs.charmap_decode(input,errors,decoding_map)
  11. class IncrementalEncoder(codecs.IncrementalEncoder):
  12. def encode(self, input, final=False):
  13. return codecs.charmap_encode(input,self.errors,encoding_map)[0]
  14. class IncrementalDecoder(codecs.IncrementalDecoder):
  15. def decode(self, input, final=False):
  16. return codecs.charmap_decode(input,self.errors,decoding_map)[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 Map
  33. decoding_map = codecs.make_identity_dict(range(256))
  34. # The PalmOS character set is mostly iso-8859-1 with some differences.
  35. decoding_map.update({
  36. 0x0080: 0x20ac, # EURO SIGN
  37. 0x0082: 0x201a, # SINGLE LOW-9 QUOTATION MARK
  38. 0x0083: 0x0192, # LATIN SMALL LETTER F WITH HOOK
  39. 0x0084: 0x201e, # DOUBLE LOW-9 QUOTATION MARK
  40. 0x0085: 0x2026, # HORIZONTAL ELLIPSIS
  41. 0x0086: 0x2020, # DAGGER
  42. 0x0087: 0x2021, # DOUBLE DAGGER
  43. 0x0088: 0x02c6, # MODIFIER LETTER CIRCUMFLEX ACCENT
  44. 0x0089: 0x2030, # PER MILLE SIGN
  45. 0x008a: 0x0160, # LATIN CAPITAL LETTER S WITH CARON
  46. 0x008b: 0x2039, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK
  47. 0x008c: 0x0152, # LATIN CAPITAL LIGATURE OE
  48. 0x008d: 0x2666, # BLACK DIAMOND SUIT
  49. 0x008e: 0x2663, # BLACK CLUB SUIT
  50. 0x008f: 0x2665, # BLACK HEART SUIT
  51. 0x0090: 0x2660, # BLACK SPADE SUIT
  52. 0x0091: 0x2018, # LEFT SINGLE QUOTATION MARK
  53. 0x0092: 0x2019, # RIGHT SINGLE QUOTATION MARK
  54. 0x0093: 0x201c, # LEFT DOUBLE QUOTATION MARK
  55. 0x0094: 0x201d, # RIGHT DOUBLE QUOTATION MARK
  56. 0x0095: 0x2022, # BULLET
  57. 0x0096: 0x2013, # EN DASH
  58. 0x0097: 0x2014, # EM DASH
  59. 0x0098: 0x02dc, # SMALL TILDE
  60. 0x0099: 0x2122, # TRADE MARK SIGN
  61. 0x009a: 0x0161, # LATIN SMALL LETTER S WITH CARON
  62. 0x009c: 0x0153, # LATIN SMALL LIGATURE OE
  63. 0x009f: 0x0178, # LATIN CAPITAL LETTER Y WITH DIAERESIS
  64. })
  65. ### Encoding Map
  66. encoding_map = codecs.make_encoding_map(decoding_map)