(self, s)
| 106 | """Encodes each byte to an id. For 8-bit strings only.""" |
| 107 | |
| 108 | def encode(self, s): |
| 109 | numres = self._num_reserved_ids |
| 110 | if six.PY2: |
| 111 | if isinstance(s, unicode): |
| 112 | s = s.encode("utf-8") |
| 113 | return [ord(c) + numres for c in s] |
| 114 | # Python3: explicitly convert to UTF-8 |
| 115 | return [c + numres for c in s.encode("utf-8")] |
| 116 | |
| 117 | def decode(self, ids, strip_extraneous=False): |
| 118 | if strip_extraneous: |