Re: [PATCH] Remove the encode/decode calls in DummyResponse.write()/getvalue() and take a more optimistic approach

[email protected] Thu, 15 Oct 2009 06:51:57 -0700
Newsgroups gmane.comp.python.cheetah
Message-ID <20091015135156.GC14392@banana>
On Thu, 15 Oct 2009, Aahz wrote:

> On Wed, Oct 14, 2009, R. Tyler Ballance wrote:
> >
> > +        try:
> > +            return chunk.decode('utf-8', 'strict')
> > +        except UnicodeDecodeError:
> > +            try:
> > +                return chunk.decode('latin-1', 'strict')
> > +            except UnicodeDecodeError:
> > +                return chunk.decode('ascii', 'ignore')
> > +        except AttributeError:
> > +            return unicode(chunk)
> > +        return chunk
> 
> Why is it safe to just return unicode() after AttributeError without
> another try/except?  Maybe you want to do unicode(chunk, errors='ignore')?

Fair point, I think the errors='ignore' kwarg is a good suggestion but I
did consider the unicode() call safe since "chunk" object in this case
is almost certainly an non-string type.

> 
> > +            return ''.join((self.safeConvert(c) for c in chunks))
> 
> Triple-checking: we now support only 2.4 and higher?

Yeah, I considered this after committing, wasn't entirely certain if
generators existed in Python 2.3 (don't use it locally, only have it
setup for Hudson[1]).


Really appreciate the code review, I feel much better about writing code
when it's had secondary review prior to merging it upstream. I've
re-rolled my patch and have pushed it up to
gitL//github.com/rtyler/cheetah.git/next and
git://github.com/cheetahtemplate/cheetah.git/next 


Cheers,
-R. Tyler Ballance

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkrXKPwACgkQFCbH3D9R4W/qTACfXZ5x+tNIrv1sInluLADs2owD
wGUAn0OnbbQUgOq6NzZuoV0yH5wdrhqt
=kt9J
-----END PGP SIGNATURE-----