*** /var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/ediffSLAMID Sun Sep 7 19:25:07 2008 --- /Users/skip/src/python/py3k/Lib/dbm/dumb.py Sun Sep 7 19:23:07 2008 *************** *** 116,122 **** sync = _commit def __getitem__(self, key): ! key = key.decode("latin-1") pos, siz = self._index[key] # may raise KeyError f = _io.open(self._datfile, 'rb') f.seek(pos) --- 116,123 ---- sync = _commit def __getitem__(self, key): ! if isinstance(key, str): ! key = key.encode("utf-8") # hashable bytes pos, siz = self._index[key] # may raise KeyError f = _io.open(self._datfile, 'rb') f.seek(pos) *************** *** 135,140 **** --- 136,143 ---- npos = ((pos + _BLOCKSIZE - 1) // _BLOCKSIZE) * _BLOCKSIZE f.write(b'\0'*(npos-pos)) pos = npos + if isinstance(val, str): + val = val.encode("utf-8") f.write(val) f.close() return (pos, len(val)) *************** *** 146,151 **** --- 149,156 ---- def _setval(self, pos, val): f = _io.open(self._datfile, 'rb+') f.seek(pos) + if isinstance(val, str): + val = val.encode("utf-8") f.write(val) f.close() return (pos, len(val)) *************** *** 161,171 **** f.close() def __setitem__(self, key, val): ! if not isinstance(key, bytes): ! raise TypeError("keys must be bytes") ! key = key.decode("latin-1") # hashable bytes ! if not isinstance(val, (bytes, bytearray)): ! raise TypeError("values must be byte strings") if key not in self._index: self._addkey(key, self._addval(val)) else: --- 166,175 ---- f.close() def __setitem__(self, key, val): ! if isinstance(key, str): ! key = key.encode("utf-8") # hashable bytes ! if isinstance(val, str): ! val = val.encode("utf-8") # hashable bytes if key not in self._index: self._addkey(key, self._addval(val)) else: *************** *** 191,197 **** # (so that _commit() never gets called). def __delitem__(self, key): ! key = key.decode("latin-1") # The blocks used by the associated value are lost. del self._index[key] # XXX It's unclear why we do a _commit() here (the code always --- 195,202 ---- # (so that _commit() never gets called). def __delitem__(self, key): ! if isinstance(key, str): ! key = key.encode("utf-8") # hashable bytes # The blocks used by the associated value are lost. del self._index[key] # XXX It's unclear why we do a _commit() here (the code always *************** *** 201,214 **** self._commit() def keys(self): ! return [key.encode("latin-1") for key in self._index.keys()] def items(self): ! return [(key.encode("latin-1"), self[key.encode("latin-1")]) ! for key in self._index.keys()] def __contains__(self, key): - key = key.decode("latin-1") return key in self._index def iterkeys(self): --- 206,217 ---- self._commit() def keys(self): ! return list(self._index.keys()) def items(self): ! return [(key, self[key]) for key in self._index.keys()] def __contains__(self, key): return key in self._index def iterkeys(self):