annotate runes.py @ 21:35f29952b51e

Remove deadwood.
author David Barts <n5jrn@me.com>
date Sat, 28 Dec 2019 06:32:53 -0800
parents be0fd5c8121d
children a771878f6cf4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 #!/usr/bin/env python3
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
3
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 # I m p o r t s
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
5
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import array
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import codecs
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import collections
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import struct
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import sys
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
11
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 # C l a s s e s
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
13
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 class Runes(object):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 """
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 A mutable, fixed-length sequence of UTF-16 runes. The attributes
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 encoding and codec contain the name of the encoding and the codec
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 used to generate the UTF-16. The attribute buffer contains the
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 buffer (an array of 16-bit unsigned integers) used to back this
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 object; modifications to that array will be reflected in this
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 object.
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 """
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 # The most efficient 16-bit one on this platform
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 encoding = "UTF-16" + sys.byteorder[0].upper() + "E"
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 codec = codecs.lookup(encoding)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
26
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 def __init__(self, based_on=None):
20
be0fd5c8121d Can't use memoryview to base Runes on; different methods inside.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
28 if isinstance(based_on, array.array):
be0fd5c8121d Can't use memoryview to base Runes on; different methods inside.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
29 if based_on.typecode == 'H':
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 self.buffer = based_on
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 self.buffer = array.array('H', based_on)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 elif isinstance(based_on, str):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 # A string should always be able to encode to runes.
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 self.buffer = array.array('H', self.codec.encode(based_on, 'strict')[0])
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 elif based_on is None:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 self.buffer = array.array('H', bytes())
12
ab7d6e908034 Allow cloning.
David Barts <n5jrn@me.com>
parents: 10
diff changeset
38 elif isinstance(based_on, Runes):
ab7d6e908034 Allow cloning.
David Barts <n5jrn@me.com>
parents: 10
diff changeset
39 self.buffer = array.array('H', based_on.buffer)
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 self.buffer = array.array('H', based_on)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
42
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 def __str__(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 """
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 Convert this object to a string. We deliberately do not have a
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 __repr__ method, to underscore that runes are not strings.
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 """
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 # Runes might not always be able to decode to a string.
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 return self.codec.decode(self.buffer, 'replace')[0]
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
50
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 def __bytes__(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
52 return bytes(self.buffer)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
53
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 def __len__(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 return len(self.buffer)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
56
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 def __lt__(self, other):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 return self.buffer < other.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
59
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
60 def __le__(self, other):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
61 return self.buffer <= other.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
62
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
63 def __gt__(self, other):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 return self.buffer > other.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
65
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 def __ge__(self, other):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 return self.buffer >= other.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
68
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 def __eq__(self, other):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 return self.buffer == other.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
71
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 def __ne__(self, other):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 return self.buffer != other.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
74
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
75 def __hash__(self):
13
6acda841a690 Add support for shared substrings.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
76 raise TypeError("unhashable type")
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
77
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 def __bool__(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
79 return bool(self.buffer)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
80
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 def __getitem__(self, key):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 ret = self.buffer[key]
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 if isinstance(ret, array.array):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 return Runes(ret)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
86 return ret
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
87
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 def __setitem__(self, key, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 if isinstance(key, int):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 if isinstance(value, int):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
91 self.buffer[key] = value
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
92 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 raise TypeError("integer required")
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 elif isinstance(value, Runes):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
95 self.buffer[key] = value.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 raise TypeError("runes required")
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
98
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 def __delitem__(self, key):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 del self.buffer[key]
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
101
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 def clear(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 del self[:]
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
104
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
105 def __iter__(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
106 return iter(self.buffer)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
107
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
108 def __reversed__(self):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
109 return reversed(self.buffer)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
110
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
111 def append(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
112 if isinstance(value, int):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
113 self.buffer.append(value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
114 elif isinstance(value, Runes):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
115 self.buffer.extend(value.buffer)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
116 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
117 raise TypeError("integer or runes required")
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
118
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
119 def __contains__(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
120 return value in self.buffer
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
121
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 def index(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 return self.buffer.index(value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
124
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 def find(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 try:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
127 return self.index(value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 except ValueError:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
129 return -1
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
130
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
131 class Workspace(Runes):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
132 """
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
133 A Runes object that acts a bit more string-like, in that __setitem__
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
134 also accepts a string as an argument and __getitem__ always returns
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
135 a string. We also return empty strings instead of throwing IndexError
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 when attempting to read out-of-range values, because that makes life
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
137 easier for us when curling quotes.
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
138 """
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 def __setitem__(self, key, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 if isinstance(value, str):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
141 if isinstance(key, int):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 Runes.__setitem__(self, key, self._ord(value))
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 Runes.__setitem__(self, key, Runes(value))
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
145 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 Runes.__setitem__(self, key, value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
147
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
148 def __getitem__(self, key):
13
6acda841a690 Add support for shared substrings.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
149 view = memoryview(self.buffer)
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 try:
15
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
151 result = view[key]
16
61772bf1f77c Remove blank.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
152 if isinstance(result, int):
15
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
153 return chr(result)
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
154 if isinstance(result, memoryview):
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
155 ret = self.codec.decode(result, 'replace')[0]
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
156 result.release()
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
157 return ret
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
158 else:
0be0586104b7 Plug the leak properly (I hope).
David Barts <n5jrn@me.com>
parents: 14
diff changeset
159 raise AssertionError("this shouldn't happen")
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
160 except IndexError:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
161 return ""
13
6acda841a690 Add support for shared substrings.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
162 finally:
6acda841a690 Add support for shared substrings.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
163 view.release()
10
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
164
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 def append(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
166 if isinstance(value, str):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
167 Runes.append(self, Runes(value))
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
168 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
169 Runes.append(self, value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
170
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
171 def index(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
172 if isinstance(value, str):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
173 return Runes.index(self, self._ord(value))
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
174 else:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
175 return Runes.index(self, value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
176
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
177 def find(self, value):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
178 try:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
179 return self.index(value)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
180 except ValueError:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
181 return -1
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
182
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
183 def _ord(self, string):
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
184 length = len(string)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
185 if length != 1:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
186 raise ValueError("expected a character, but string of length {0} found".format(length))
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
187 raw = Runes(string)
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
188 if len(raw) != 1:
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
189 raise ValueError("character not in BMP")
397c178c5b98 Make it array-based.
David Barts <n5jrn@me.com>
parents:
diff changeset
190 return raw[0]