Mercurial > cgi-bin > hgweb.cgi > curlyq
comparison writer.py @ 3:091c03f1b2e8
Getting it working...
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 26 Dec 2019 19:54:45 -0800 |
parents | 984876b6a095 |
children |
comparison
equal
deleted
inserted
replaced
2:8884b0bf779d | 3:091c03f1b2e8 |
---|---|
15 # V a r i a b l e s | 15 # V a r i a b l e s |
16 | 16 |
17 # We only support ASCII, ISO-8859-1, and anything capable of encoding | 17 # We only support ASCII, ISO-8859-1, and anything capable of encoding |
18 # the full Unicode set. Anything else is too sticky a wicket to want | 18 # the full Unicode set. Anything else is too sticky a wicket to want |
19 # to mess with. | 19 # to mess with. |
20 _CODECS_TO_NAME = {} | 20 CODECS_TO_NAME = {} |
21 for i in [ "US-ASCII", "ISO-8859-1", "UTF-8", "UTF-16", "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE", "UTF-32BE" ]: | 21 for i in [ "US-ASCII", "ISO-8859-1", "UTF-8", "UTF-16", "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE", "UTF-32BE" ]: |
22 _CODECS_TO_NAME[codecs.lookup(i)] = i | 22 CODECS_TO_NAME[codecs.lookup(i)] = i |
23 del i | 23 del i |
24 _MAXCHAR = { "US-ASCII": 127, "ISO-8859-1": 255 } | 24 _MAXCHAR = { "US-ASCII": 127, "ISO-8859-1": 255 } |
25 | 25 |
26 # There are WAY more HTML entities than this, but we're pessimistic about | 26 # There are WAY more HTML entities than this, but we're pessimistic about |
27 # what browsers "in the wild" support, so we stick to what XML supports. | 27 # what browsers "in the wild" support, so we stick to what XML supports. |
55 self.stream = stream | 55 self.stream = stream |
56 try: | 56 try: |
57 # A codec to use is available to the caller as .codec | 57 # A codec to use is available to the caller as .codec |
58 self.codec = codecs.lookup(encoding) | 58 self.codec = codecs.lookup(encoding) |
59 # Normalized encoding name is available to the caller as .encoding | 59 # Normalized encoding name is available to the caller as .encoding |
60 self.encoding = _CODECS_TO_NAME[self.codec] | 60 self.encoding = CODECS_TO_NAME[self.codec] |
61 except (KeyError, LookupError) as e: | 61 except (KeyError, LookupError) as e: |
62 raise ValueError("invalid encoding {0!r}".format(encoding)) | 62 raise ValueError("invalid encoding {0!r}".format(encoding)) |
63 self._maxchar = _MAXCHAR.get(self.encoding, 0x7fffffff) | 63 self._maxchar = _MAXCHAR.get(self.encoding, 0x7fffffff) |
64 | 64 |
65 # html.escape drops the ball, badly. It is too optimistic about what | 65 # html.escape drops the ball, badly. It is too optimistic about what |