Jason Tackaberry wrote: > Update of /cvsroot/freevo/kaa/vfs/src > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11411 > > Modified Files: > db.py > Log Message: > Fixes for unicode; lower min word length to 2. [...]
> ! if type == str: > ! values.append(utf8(attrs[name])) > ! else: > ! values.append(attrs[name]) I don't get it? Why use string at all? IMHO we should convert _every_ string to Unicode. And we can use sys.getfilesystemencoding() to convert file names from string to unicode. And if you provide an unicode oebject to os.listdir, all results are unicode, too. Only sys.getdefaultencoding() does not work and we need to work around it using locale functions. ,----[ foo.py ] | import sys | import locale | | print sys.getfilesystemencoding() | print sys.getdefaultencoding() | print locale.getdefaultlocale() | print locale.getpreferredencoding() `---- ,---- | [EMAIL PROTECTED]: ~ | phex-> LANG=en_US.UTF-8 python foo.py | UTF-8 | ascii | ['en_US', 'utf'] | UTF-8 | [EMAIL PROTECTED]: ~ | phex-> LANG=de_DE python foo.py | ISO-8859-1 | ascii | ['de_DE', 'ISO8859-1'] | ISO-8859-1 | [EMAIL PROTECTED]: ~ | phex-> `---- > + def _list_to_utf8_printable(self, items): > + """ > + Takes a list of mixed types and outputs a utf-8 encoded string. For > + example, a list [42, 'foo', None, "foo's string"], this returns the > + string: > + > + (42, 'foo', NULL, 'foo''s string') > + > + Single quotes are escaped as ''. This is suitable for use in SQL > + queries. > + """ > + fixed_items = [] > + for item in items: > + if type(item) in (int, long): > + fixed_items.append(str(item)) > + elif item == None: > + fixed_items.append("NULL") > + elif type(item) in (str, unicode): > + fixed_items.append("'%s'" % utf8(item.replace("'", "''"))) > + else: > + raise Exception, "Unsupported type '%s' given to > list_to_utf8_printable" % type(item) > + > + return "(" + ",".join(fixed_items) + ")" Not good. Always use unicode inside. If the vfs works with UTF-8 and my system with Latin-1, I get in trouble with strings. So always unicode. Dischi -- A 14.4 modem makes you want to get out and push!
pgp02GnXjldOc.pgp
Description: PGP signature