Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
A Base Class for Better CherryPy Tools
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
  7 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
 
Eric Larson  
View profile  
 More options Sep 18 2012, 12:15 pm
From: Eric Larson <e...@ionrock.org>
Date: Tue, 18 Sep 2012 11:15:36 -0500
Local: Tues, Sep 18 2012 12:15 pm
Subject: A Base Class for Better CherryPy Tools
Hi All,

I'm a huge fan of CherryPy as it always seems to have the right design,
providing a flexible platform while keeping the mundane details out of
the way. Tools are a great example of this design. Unfortunately,
writing Tools always ends up being somewhat error prone and I end up
using copy and paste. Seeing as the actual API isn't terribly difficult
to get right, I wrote a base class similar to the SimplePlugin base
class for plugins that will hopefully make writing tools a little
easier.

I wrote up a blog about with the code included.

  http://ionrock.wordpress.com/2012/09/16/better-cherrypy-tools/[2]

Hopefully it is helpful to someone!

Eric


 
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.
Sylvain Hellegouarch  
View profile  
 More options Sep 18 2012, 3:29 pm
From: Sylvain Hellegouarch <s...@defuze.org>
Date: Tue, 18 Sep 2012 21:29:44 +0200
Local: Tues, Sep 18 2012 3:29 pm
Subject: Re: [cherrypy-users] A Base Class for Better CherryPy Tools

Hi Eric,

All good stuff really. I'm so used to writing tools that I often forget
that their current API may not be as straightforward as one could expect
(though hardly complex as you say). I like the idea
of automatically registering hookpoints. Though to be fair my tool methods
are named after their role not the hook point where they'll be attached.

For instance, let's take this simple redis tool:

https://bitbucket.org/Lawouach/cherrypy-recipes/src/c899e1b91417/web/...

It's more useful to me to understand what the methods do rather than where
they are actually set to be executed on.
--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach


 
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.
Sylvain Hellegouarch  
View profile  
 More options Sep 18 2012, 3:31 pm
From: Sylvain Hellegouarch <s...@defuze.org>
Date: Tue, 18 Sep 2012 21:31:47 +0200
Local: Tues, Sep 18 2012 3:31 pm
Subject: Re: [cherrypy-users] A Base Class for Better CherryPy Tools

Interestingly, a decorator of hookpoint would go a long way.

class MyTool(...):

@cherrypy.hookpoint('before_finalize')
def cleanup_some_resource(self):
    ....

--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach


 
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.
Eric Larson  
View profile  
 More options Sep 18 2012, 3:53 pm
From: Eric Larson <e...@ionrock.org>
Date: Tue, 18 Sep 2012 14:53:20 -0500
Local: Tues, Sep 18 2012 3:53 pm
Subject: Re: [cherrypy-users] A Base Class for Better CherryPy Tools

Sylvain Hellegouarch <s...@defuze.org> writes:
> On Tue, Sep 18, 2012 at 9:29 PM, Sylvain Hellegouarch <s...@defuze.org> wrote:
>     All good stuff really. I'm so used to writing tools that I often forget
>     that their current API may not be as straightforward as one could expect
>     (though hardly complex as you say).

Just to be clear, I don't consider it complex in that it is difficult to
understand or keep straight in your head. Rather the complexity happens
in that there isn't a single prescribed method for specific tasks. A
wealth of options rarely makes a decision easier.

I agree that Tools really are pretty simple, especially compared to WSGI
middleware.

> Interestingly, a decorator of hookpoint would go a long way.

> class MyTool(...):

> @cherrypy.hookpoint('before_finalize')
> def cleanup_some_resource(self):
>     ....

That is a great idea. I'll play around with it and see what comes of
it. Thanks for the feedback!

Eric


 
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.
Eric Larson  
View profile  
 More options Sep 18 2012, 9:24 pm
From: Eric Larson <e...@ionrock.org>
Date: Tue, 18 Sep 2012 20:23:53 -0500
Local: Tues, Sep 18 2012 9:23 pm
Subject: Re: [cherrypy-users] A Base Class for Better CherryPy Tools

Sylvain Hellegouarch <s...@defuze.org> writes:
> Interestingly, a decorator of hookpoint would go a long way.

> class MyTool(...):

> @cherrypy.hookpoint('before_finalize')
> def cleanup_some_resource(self):
>     ....

I played around with this for a minute and something didn't feel
right. I figured it would be just as easy to do something like this
using the same base class:

  class SomeTool(SimpleTool):

      def cleanup_resources(self):
          ...
      before_finalize = clean_resources

This is possible with a decorator, but this seems just as good IMO.

Thoughts?

Eric


 
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.
Sylvain Hellegouarch  
View profile  
 More options Sep 19 2012, 1:58 am
From: Sylvain Hellegouarch <s...@defuze.org>
Date: Wed, 19 Sep 2012 07:58:02 +0200
Local: Wed, Sep 19 2012 1:58 am
Subject: Re: [cherrypy-users] A Base Class for Better CherryPy Tools

Just as well indeed. Decorators have only the added value of being more
dynamic. You could for instance decide not to attach the hookpoint at
runtime. But that would make things quite complex at some point.
--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach

 
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.
Aric Coady  
View profile  
 More options Sep 19 2012, 12:52 pm
From: Aric Coady <aric.co...@gmail.com>
Date: Wed, 19 Sep 2012 09:52:56 -0700 (PDT)
Local: Wed, Sep 19 2012 12:52 pm
Subject: Re: [cherrypy-users] A Base Class for Better CherryPy Tools

 I think the decorator would be more useful for simple function-based
tools.  I've used this:

def tool(hook):
    def decorator(func):
        setattr(cherrypy.tools, func.__name__, cherrypy.Tool(hook, func))
        return func
    return decorator


 
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 »