comparison runes.py @ 20:be0fd5c8121d

Can't use memoryview to base Runes on; different methods inside.
author David Barts <n5jrn@me.com>
date Sat, 28 Dec 2019 01:22:03 -0800
parents 0c8d787bc7e1
children 35f29952b51e
comparison
equal deleted inserted replaced
19:f8d0a5201dd7 20:be0fd5c8121d
23 # The most efficient 16-bit one on this platform 23 # The most efficient 16-bit one on this platform
24 encoding = "UTF-16" + sys.byteorder[0].upper() + "E" 24 encoding = "UTF-16" + sys.byteorder[0].upper() + "E"
25 codec = codecs.lookup(encoding) 25 codec = codecs.lookup(encoding)
26 26
27 def __init__(self, based_on=None): 27 def __init__(self, based_on=None):
28 if isinstance(based_on, (array.array, memoryview)): 28 if isinstance(based_on, array.array):
29 format = based_on.typecode if isinstance(based_on, array.array) else based_on.format 29 if based_on.typecode == 'H':
30 if format == 'H':
31 self.buffer = based_on 30 self.buffer = based_on
32 else: 31 else:
33 self.buffer = array.array('H', based_on) 32 self.buffer = array.array('H', based_on)
34 elif isinstance(based_on, str): 33 elif isinstance(based_on, str):
35 # A string should always be able to encode to runes. 34 # A string should always be able to encode to runes.