[issue3799] Byte/string inconsistencies between different dbm modules

Skip Montanaro report at bugs.python.org
Mon Sep 8 02:26:16 CEST 2008


Skip Montanaro <skip at pobox.com> added the comment:

I'm not sure.  I've never done anything with the io module.  Simply
eliminating the bytes checks and letting it try to write the string
yields:

  File "/Users/skip/local/lib/python3.0/dbm/dumb.py", line 170, in 
__setitem__
    self._addkey(key, self._addval(val))
  File "/Users/skip/local/lib/python3.0/dbm/dumb.py", line 138, in 
_addval
    f.write(val)
  File "/Users/skip/local/lib/python3.0/io.py", line 1224, in write
    return BufferedWriter.write(self, b)
  File "/Users/skip/local/lib/python3.0/io.py", line 1034, in write
    raise TypeError("can't write str to binary stream")

I suppose you'd have to check if val is an instance of str and if so,
encode it as utf-8.  I notice in the existing code that it's doing
some key decoding assuming latin-1.  That would be an incompatibility,
but I think assuming latin-1 is wrong.

That said, I've attached a patch which passes all current unit tests.

Skip

----------
keywords: +patch
Added file: http://bugs.python.org/file11418/dumb.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3799>
_______________________________________


More information about the Python-bugs-list mailing list