Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
3.2 and tools.encode
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
dbrattli  
View profile  
 More options Jun 12, 8:10 am
From: dbrattli <dbrat...@gmail.com>
Date: Fri, 12 Jun 2009 05:10:59 -0700 (PDT)
Local: Fri, Jun 12 2009 8:10 am
Subject: 3.2 and tools.encode
Hi,

GearShift, http://code.google.com/p/python-gearshift/ exposes
templates similar to TurboGears, but the @expose has been rewritten as
a (before_finalize) CP tool, thus I can use them as decorators etc
without having to wrap the handler.

But now in 3.2 (trunk) I see that tools.encode is wrapping the
handler. A GearShift/TurboGears handler usually returns a dict and
right now tools.encode turns this dict into a list of keys. Thus my
Genshi template engine gets a list of keys instead of the dict it's
expecting. So I have to turn off tools.encode to get things working.
But then I need to force an encoding from Genshi since I cannot use
tools.encode anymore.

I guess there's a good reason for turning tools.encode into a
(before_handler) tool that wraps the handler, but  it makes it much
harder to write tools that processes various output from the handlers
that is not strings. That was the real advantage of using tools. I do
want output encoding, so this means that I will have to rewrite all my
before_finalize tools to become before_handler tools and then wrap the
handler myself (before tools.encode). I think I would prefer
tools.encode was done a bit later (before_finalize) as before.

-- Dag


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fumanchu  
View profile  
 More options Jun 14, 8:47 pm
From: fumanchu <fuman...@aminus.org>
Date: Sun, 14 Jun 2009 17:47:25 -0700 (PDT)
Local: Sun, Jun 14 2009 8:47 pm
Subject: Re: 3.2 and tools.encode
On Jun 12, 5:10 am, dbrattli <dbrat...@gmail.com> wrote:

Yes, it's always been a design flaw. Handlers were always meant to
return strings or iterables of strings only. Previous versions of
CherryPy were lax in this requirement, which allowed handlers to
return other things (such as dicts, as you have done), so that
response.body could be theoretically any type between the handler()
call and the finalize() call. Unfortunately, other types break Tools
which have abided by the (loosely-specified and loosely-enforced)
contract that response.body be a string or iterable of strings.

This became even more dangerous in the python3 branch, because byte
strings and unicode are no longer interchangeable nor automatically
coerce from one to the other. Rather than burden Tools with the
additional requirement to distinguish between bytes and unicode (and
most likely coerce back and forth a lot, slowing things down), I
decided to limit response.body even more: in 3.2 it must now be a
bytestring or iterable of bytestrings. In order to allow folks to
return unicode from handlers, therefore, tools.encoding had to move
and wrap the handler.

I'm sorry about the extra work required to change existing Tools. But
I think the few extra lines of code are outweighed by the interop
benefits of turning on any Tool you got from anywhere, without having
to worry about how it will interact with your custom response.body
return type.

More discussion welcome.

Robert Brewer
fuman...@aminus.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dbrattli  
View profile  
 More options Jun 15, 9:43 am
From: dbrattli <dbrat...@gmail.com>
Date: Mon, 15 Jun 2009 06:43:22 -0700 (PDT)
Local: Mon, Jun 15 2009 9:43 am
Subject: Re: 3.2 and tools.encode
Robert,

I get the point. You are right about keeping response.body encoded.
I'll start fixing my tools.

Thanks,

-- Dag

On Jun 15, 2:47 am, fumanchu <fuman...@aminus.org> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google