#204 StringCol can't treat other encoding except "ASCII"

closed-invalid
None
5
2007-01-10
2006-12-25
Anonymous
No

Hi, I'm Chinese. I'm very like SQLObject. But, I found a encoding bug in the class StringValidator. This class is in the script "col.py". When I input a other encoding string input or output from database with StringCol it will raise a UnicodeEncodeError, because I use GBK encoding to access the string. But in StringValidator Only allow "acsii" encoding.

I have fix it, the new code is below:

import sys

class StringValidator(validators.Validator):

def to_python(self, value, state):
if value is None:
return None
if isinstance(value, unicode):
return value.encode(sys.getdefaultencoding())
return value

def from_python(self, value, state):
if value is None:
return None
if isinstance(value, str):
return value
if isinstance(value, unicode):
return value.encode(sys.getdefaultencoding())
return value

Then, I can use StringCol to access a "GBK" encoding string. Also I must set the default encoding before this:

import sys
reload(sys)
sys.setdefaultencoding("GBK")

Please fix it, Thanks.
SQLObject 0.7.1

Discussion

  • Nobody/Anonymous

    Logged In: NO

    It's very surperise that I can't login. My account is gashero, and my email is "harry.python@gmail.com". Thanks!!!!!

     
  • Oleg Broytman

    Oleg Broytman - 2007-01-10
    • assigned_to: nobody --> phd
    • status: open --> closed-invalid
     
  • Oleg Broytman

    Oleg Broytman - 2007-01-10

    Logged In: YES
    user_id=4799
    Originator: NO

    This has been fixed in 0.7.2:

    * Fixed a number of unicode-related problems with newer MySQLdb.

    The encoding can now be set in the DB URI.

     

Log in to post a comment.