@@ -144,6 +144,8 @@ def _verify_open(self):
144144 def __getitem__ (self , key ):
145145 if isinstance (key , str ):
146146 key = key .encode ('utf-8' )
147+ elif isinstance (key , bytearray ):
148+ key = bytes (key )
147149 self ._verify_open ()
148150 pos , siz = self ._index [key ] # may raise KeyError
149151 with _io .open (self ._datfile , 'rb' ) as f :
@@ -189,7 +191,9 @@ def __setitem__(self, key, val):
189191 raise error ('The database is opened for reading only' )
190192 if isinstance (key , str ):
191193 key = key .encode ('utf-8' )
192- elif not isinstance (key , (bytes , bytearray )):
194+ elif isinstance (key , bytearray ):
195+ key = bytes (key )
196+ elif not isinstance (key , bytes ):
193197 raise TypeError ("keys must be bytes or strings" )
194198 if isinstance (val , str ):
195199 val = val .encode ('utf-8' )
@@ -226,6 +230,8 @@ def __delitem__(self, key):
226230 raise error ('The database is opened for reading only' )
227231 if isinstance (key , str ):
228232 key = key .encode ('utf-8' )
233+ elif isinstance (key , bytearray ):
234+ key = bytes (key )
229235 self ._verify_open ()
230236 self ._modified = True
231237 # The blocks used by the associated value are lost.
@@ -249,6 +255,8 @@ def items(self):
249255 def __contains__ (self , key ):
250256 if isinstance (key , str ):
251257 key = key .encode ('utf-8' )
258+ elif isinstance (key , bytearray ):
259+ key = bytes (key )
252260 try :
253261 return key in self ._index
254262 except TypeError :
0 commit comments