Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why does HDB iteritems() decode key and value #13

Open
mosasiru opened this issue Jan 7, 2016 · 0 comments
Open

why does HDB iteritems() decode key and value #13

mosasiru opened this issue Jan 7, 2016 · 0 comments

Comments

@mosasiru
Copy link

mosasiru commented Jan 7, 2016

I use python3.5 and tc 0.7.2.
Why HDB iteritems() decode key and value unlike items()?
Following is an example.

In [160]: db.open("test", tc.HDBOWRITER | tc.HDBOCREAT)
In [162]: db[b"hoge"] = b"fuga"
In [163]: db["ほげ".encode("utf-8")] = "ふが".encode("utf-8")
In [164]: db.items()
Out[164]:
[(b'hoge', b'fuga'),
 (b'\xe3\x81\xbb\xe3\x81\x92', b'\xe3\x81\xb5\xe3\x81\x8c')]

In [165]: list(db.iteritems())
Out[165]: [('hoge', 'fuga'), ('ほげ', 'ふが')]

So I have a trouble with below error when HDB include a value msgpack.packb() value.

In [8]: db[b"hoge"] = msgpack.packb([1,2,3])
In [9]: list(db.itervalues())
Out[9]: [b'\xe3\x81\xb5\xe3\x81\x8c']
In [10]: db.items()
Out[10]: [(b'\xe3\x81\xbb\xe3\x81\x92', b'\xe3\x81\xb5\xe3\x81\x8c')]
In [11]: list(db.iteritems())
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-10-9453a76d2e05> in <module>()
----> 1 list(db.iteritems())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 0: invalid start byte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant