Ahem...
I don't think changing a distributed Python library file is a solution in 
any way...

You can change the default encoding programatically, although it is not 
considered the best way:
http://blog.ianbicking.org/illusive-setdefaultencoding.html , 
http://faassen.n--tree.net/blog/view/weblog/2005/08/02/0

You should try to find a better solution, which has to exist, since 
everyone is struggling with unicode...

Am Freitag, 24. August 2012 01:24:27 UTC+2 schrieb enc0de:
>
> On Thursday, March 31, 2011 6:51:20 AM UTC+2, Bob Tanner wrote: 
> > I must be missing something simple or fundamental when it comes to TG2 
> and Unicode. Every time I step out of the ASCII world 
> the UnicodeDecodeError hits me. 
> > 
> > 
> > The table as dumped from MySQL 
> > 
> > 
> > 
> > -- 
> > -- Table structure for table `resourceitem` 
> > -- 
> > 
> > 
> > DROP TABLE IF EXISTS `resourceitem`; 
> > /*!40101 SET @saved_cs_client     = @@character_set_client */; 
> > /*!40101 SET character_set_client = utf8 */; 
> > CREATE TABLE `resourceitem` ( 
> >   `resourceid` binary(16) NOT NULL, 
> >   `item` int(11) NOT NULL, 
> >   `description` text, 
> >   `title` varchar(2000) DEFAULT NULL, 
> >   `publisher` varchar(2000) DEFAULT NULL, 
> >   `creator` varchar(2000) DEFAULT NULL, 
> >   `language` varchar(10) DEFAULT NULL, 
> >   `identifier` varchar(127) DEFAULT NULL, 
> >   `thumbnailurl` varchar(254) DEFAULT NULL, 
> >   `format` varchar(40) DEFAULT NULL, 
> >   `src` varchar(254) DEFAULT NULL, 
> >   `downloadtype` varchar(20) DEFAULT NULL, 
> > 
> >   UNIQUE KEY `resourceitem_resourceid` (`resourceid`,`item`), 
> >   KEY `resourceitem_creator` (`creator`(255)), 
> >   KEY `resourceitem_title` (`title`(255)), 
> >   KEY `resourceitem_thumbnailurl` (`thumbnailurl`), 
> >   KEY `resourceitem_identifier` (`identifier`), 
> >   KEY `resourceitem_src` (`src`), 
> >   KEY `resourceitem_publisher` (`publisher`(255)), 
> >   CONSTRAINT `resourceitem_ibfk_1` FOREIGN KEY (`resourceid`) REFERENCES 
> `resourcekey` (`resourceid`) 
> > ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
> > /*!40101 SET character_set_client = @saved_cs_client */; 
> > 
> > 
> > The TG2 model 
> > 
> > 
> > 
> > # -*- coding: utf-8 -*- 
> > """ResourceItem model module.""" 
> > 
> > 
> > from sqlalchemy import Column, Integer, String, Text, ForeignKey, 
> LargeBinary, Unicode, UnicodeText, Table 
> > from sqlalchemy.orm import relation 
> > from reports.model import DeclarativeBase 
> > 
> > 
> > __all__ = ['ResourceItemMode'] 
> > 
> > 
> > class ResourceItemModel(DeclarativeBase): 
> >     __tablename__ = 'resourceitem' 
> >      
> >     resourceid = Column(LargeBinary(16), nullable=False, 
> primary_key=True) 
> >     item = Column(Integer(11), nullable=False, primary_key=True) 
> >     description = Column(Text, nullable=True) 
> >     title = Column(Unicode(2000), nullable=True) 
> >     publisher = Column(Unicode(2000), nullable=True) 
> >     creator = Column(Unicode(2000), nullable=True) 
> >     language = Column(Unicode(10), nullable=True) 
> >     identifier = Column(Unicode(127), nullable=True) 
> >     thumbnailurl = Column(Unicode(254), nullable=True) 
> >     format = Column(Unicode(40), nullable=True) 
> >     src = Column(String(254), nullable=True) 
> >     downloadtype = Column(Unicode(20), nullable=True) 
> > 
> > 
> > One of the creators is Antoine de Saint-Exupéry <
> http://en.wikipedia.org/wiki/Antoine_de_Saint-Exup%C3%A9ry> and when I do 
> a mysql comment line query I get this: 
> > 
> > 
> > 
> > mysql> select creator   from resourceitem where creator like '%Antoine%' 
> ; 
> > +---------------------------+ 
> > | creator                   | 
> > +---------------------------+ 
> > | Saint-Exupéry, Antoine de | 
> > +---------------------------+ 
> > 1 row in set (0.00 sec) 
> > 
> > 
> > Looks properly decoded and display. I set up a simple CrudRestController 
> and did the boiler plate TG2 code: 
> > 
> > 
> > 
> > class ResourceItemController(CrudRestController): 
> >     model = ResourceItemModel 
> >      
> >     class new_form_type(AddRecordForm): 
> >         __model__ = ResourceItemModel 
> > 
> > 
> >     class edit_form_type(EditableForm): 
> >         __model__ = ResourceItemModel 
> >          
> >     class edit_filler_type(EditFormFiller): 
> >         __model__ = ResourceItemModel 
> >          
> >     class table_type(TableBase): 
> >         __model__ = ResourceItemModel 
> >          
> >     class table_filler_type(TableFiller): 
> >         __model__ = ResourceItemModel 
> >         __omit_fields__ = ['__actions__']        
> > 
> > 
> > 
> > class RootController(BaseController): 
> >     secc = SecureController() 
> >     admin = AdminController(model, DBSession, config_type=TGAdminConfig) 
> >     error = ErrorController() 
> > 
> > 
> >     resource_items = ResourceItemController(DBSession) 
> > 
> > 
> > Open web browser to http://127.0.0.1:8080/resource_items/ I get a 
> Server Error, the dreaded UnicodeDecodeError on Antoine de Saint-Exupéry 
> name. 
> > 
> > 
> > 
> > I'm not sure what I did wrong. 
> > 
> > 
> > Is the default template from sprox not <meta content="text/html; 
> charset=UTF-8"/> by chance? 
> > 
> > 
> > Any recommendations on how I can resolve my UnicodeDecodeError? 
> > 
> > 
> > Thanks. 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > -- 
> > Bob Tanner <[email protected]>                 | Phone : 
> 952-943-8700 
> > http://www.real-time.com, Linux, OSX, VMware | Fax      : 952-943-8500 
> > Key fingerprint = F785 DDFC CF94 7CE8 AA87 3A9D 3895 26F1 0DDB E378 
>
> Listen I have been on this same problem it's not genshi or anython it's 
> python itself just find the site.py in the python/Lib/site.py and look for 
>
> def setencoding(): 
>     """Set the string encoding used by the Unicode implementation.  The 
>     default is 'ascii', but if you're willing to experiment, you can 
>     change this.""" 
>     encoding = "ascii" # Default value set by _PyUnicode_Init() 
>
>
> you see the encoding = "ascii" change to look like this encoding = "utf-8" 
> and the whole problem is gone. 
>
> Yes the solution is that EASY

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/turbogears/-/IW-ILohXQ90J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to