[Zope3-dev] Re: [Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate - TALES.py:1.3

Jim Fulton jim@zope.com
Mon, 17 Jun 2002 07:26:46 -0400


Guido van Rossum wrote:
> 
> > > Sounds like FUD to me.  Maybe mixing string types causes problems in
> > > other languages, but Python's rules for combining ASCII and Unicode
> > > strings are designed to make mixing of the two always do the right
> > > thing.
> >
> > They fail miserably.
> >
> > They allow program errors to go undetected until the cause of the
> > errors cannot be determined. I just got bitten hard by this when
> > unicode from XML processing leaked into HTTP response data. This
> > promoted the HTTP response data to unicode, which "worked" until I
> > decided I wanted to output image data, which couldn't be promoted to
> > unicode.
> 
> I don't understand how a proposal to make all text literals Unicode
> would help here -- it would have the exact same problem from your
> example.

I wasn't commenting on a the proposal. I was commenting on the 
problem with automagic string<-->unicode conversion.

> > I've heard a number of horror stories like this.
> >
> > This is an example where implicit is worse than explicit.
> 
> If you want all default promotions from 8-bit strings to Unicode
> without an explicit encoding to fail, it's easy to accomplish by
> setting the default encoding to an encoding that always raises an
> error.
> 
> To do this:
> 
> import sys
> reload(sys) # This gives you back sys.setdefaultencoding()

That's a neat trick. Thanks!

> sys.setdefaultencoding("whatever")
> 
> (You'd have to define and register a decoding named "whatever" too.)

There's already one defined: 'disable'.

I set this in test.py and we got lots of failures, which we'll fix.
Interestingly, this made xmlrpclib actually hang.  I don't think
I'll disable the default encoding for production, but we will disable it
during testing and declare it poor style to rely on the default encoding.

Jim


--
Jim Fulton           mailto:jim@zope.com       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org