[Python-3000] Immutable bytes type and dbm modules

"Martin v. Löwis" martin at v.loewis.de
Sun Aug 5 22:49:33 CEST 2007


I changed bsddb so that it consistently produces and
consumes bytes only, and added convenience wrappers
StringKeys and StringValues for people whose database
are known to store only strings as either keys or
values; those get UTF-8 encoded.

While I could fix test_bsddb with these changes,
anydbm and whichdb broke, as they expect to use
string keys. Changing them to use bytes keys then
broke dumbdbm, which uses a dictionary internally
for the index.

This brings me to join others in the desire for
immutable bytes objects: I think such a type is
needed, and it should probably use the same
hash algorithm as str8.

I don't think it needs to be a separate type,
instead, bytes objects could have a idem-potent
.freeze() method which switches the "immutable"
bit on. There would be no way to switch it off
again.

If that is not acceptable, please tell me how else
to fix the dbm modules.

Regards,
Martin


More information about the Python-3000 mailing list