Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r72384:c8d30edc0498
Date: 2014-07-08 09:48 +0200
http://bitbucket.org/pypy/pypy/changeset/c8d30edc0498/
Log: accept unicode keys
diff --git a/lib-python/2.7/test/test_gdbm.py b/lib-python/2.7/test/test_gdbm.py
--- a/lib-python/2.7/test/test_gdbm.py
+++ b/lib-python/2.7/test/test_gdbm.py
@@ -98,6 +98,17 @@
self.assertTrue(key in self.g)
self.assertTrue(self.g.has_key(key))
+ def test_unicode_key(self):
+ key = u'ab'
+ value = u'cd'
+ self.g = gdbm.open(filename, 'cf')
+ self.g[key] = value
+ self.g.close()
+ self.g = gdbm.open(filename, 'r')
+ self.assertEquals(self.g[key], value)
+ self.assertTrue(key in self.g)
+ self.assertTrue(self.g.has_key(key))
+
def test_main():
run_unittest(TestGdbm)
diff --git a/lib_pypy/gdbm.py b/lib_pypy/gdbm.py
--- a/lib_pypy/gdbm.py
+++ b/lib_pypy/gdbm.py
@@ -50,6 +50,8 @@
pass
def _fromstr(key):
+ if isinstance(key, unicode):
+ key = key.encode("ascii")
if not isinstance(key, str):
raise TypeError("gdbm mappings have string indices only")
return {'dptr': ffi.new("char[]", key), 'dsize': len(key)}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit