[Metakit] Python & Unicode
metakit at kaishaku.org
metakit at kaishaku.org
Fri Mar 10 17:48:34 CET 2006
> Thanks for the reply. Type S gives "not a python string", type B gives
> "wrong type for ByteProp". Here is the output:
>
> >>> db = metakit.storage("test.db", 2)
> >>> v = db.getas("test[name:B,test:S]")
> >>> v.append(name='abc',test='def')
> 0
> >>> for row in v: print row.name, row.test
> ...
> abc def
> >>> v.append(name=u'abc',test='def')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: wrong type for ByteProp
> >>> v.append(name='abc',test=u'def')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: not a Python string
You are sending a Python unicode object.
You need to send an array of bytes.
------------------------------------------------------------------------
import metakit
db = metakit.storage()
people = db.getas('[name:S,namei:B]')
u16be = '\x00\x4a\x00\x6f\x00\xe5\x00\x6f'
people.append(name='Joao',namei=u16be)
print people[0].name
print list(people[0].name)
print people[0].namei
print list(people[0].namei)
print people[0].namei.decode('utf-16be')
------------------------------------------------------------------------
C:\>unimeta
Joao
['J', 'o', 'a', 'o']
J o s o
['\x00', 'J', '\x00', 'o', '\x00', '\xe5', '\x00', 'o']
Joåo
------------------------------------------------------------------------
This prints correctly in DOS. I think it auto-converts to cp437 for
output. When I copy it into the clipboard it stores in some other
format... when I paste into my mail client "Becky" it may use even
some other format, and when it gets to you, perhaps even another...
The third line " J o s o" is already mangled away from what I see
in the DOS shell. The final line looks good, as å is a common char
in codecs, but I don't think I can say what it will look like in
your clients.
--
kai
More information about the Metakit
mailing list