comparison runes.py @ 15:0be0586104b7

Plug the leak properly (I hope).
author David Barts <n5jrn@me.com>
date Fri, 27 Dec 2019 13:35:51 -0800
parents 152f6aa87d62
children 61772bf1f77c
comparison
equal deleted inserted replaced
14:152f6aa87d62 15:0be0586104b7
152 Runes.__setitem__(self, key, value) 152 Runes.__setitem__(self, key, value)
153 153
154 def __getitem__(self, key): 154 def __getitem__(self, key):
155 view = memoryview(self.buffer) 155 view = memoryview(self.buffer)
156 try: 156 try:
157 ret = view[key] 157 result = view[key]
158 try: 158 if isinstance (result, int):
159 if isinstance (ret, int): 159 return chr(result)
160 return chr(ret) 160 if isinstance(result, memoryview):
161 elif isinstance(ret, memoryview): 161 ret = self.codec.decode(result, 'replace')[0]
162 return self.codec.decode(ret, 'replace')[0] 162 result.release()
163 else: 163 return ret
164 raise AssertionError("this shouldn't happen") 164 else:
165 finally: 165 raise AssertionError("this shouldn't happen")
166 ret.release()
167 except IndexError: 166 except IndexError:
168 return "" 167 return ""
169 finally: 168 finally:
170 view.release() 169 view.release()
171 170