List Info

Thread: Custom Toolbox Configuration




Custom Toolbox Configuration
country flaguser name
United States
2007-06-07 07:09:25
I notice in the cp3 docs that custom toolboxes automatically
have
their own configuration space allocated.

I have a tool like so:

import cherrypy
toolbox = cherrypy._cptools.Toolbox("kg")

def unrepr_params(blank_nones=True):
    """ Tool that turns params into python
values and replaces
    empty values with None.
    """
    for param, value in cherrypy.request.params.items():
        try:
            value = cherrypy.lib.unrepr(value)
        except:
            pass
        if value == '' and blank_nones:
            value = None
        cherrypy.request.params[param] = value

toolbox.unrepr_params =
cherrypy.Tool('before_request_body',
unrepr_params)


With config like so:

config = {
'/': {

    'engine.autoreload_on' : False,

},
'kg' : {
    'unrepr_params.on' : True,
}

}

No dice. What am I doing wrong?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Custom Toolbox Configuration
country flaguser name
United Kingdom
2007-06-07 07:33:35
jlowery a écrit :
> I notice in the cp3 docs that custom toolboxes
automatically have
> their own configuration space allocated.
>
> I have a tool like so:
>
> import cherrypy
> toolbox = cherrypy._cptools.Toolbox("kg")
>
> def unrepr_params(blank_nones=True):
>     """ Tool that turns params into
python values and replaces
>     empty values with None.
>     """
>     for param, value in
cherrypy.request.params.items():
>         try:
>             value = cherrypy.lib.unrepr(value)
>         except:
>             pass
>         if value == '' and blank_nones:
>             value = None
>         cherrypy.request.params[param] = value
>
> toolbox.unrepr_params =
cherrypy.Tool('before_request_body',
> unrepr_params)
>
>
> With config like so:
>
> config = {
> '/': {
>
>     'engine.autoreload_on' : False,
>
> },
> 'kg' : {
>     'unrepr_params.on' : True,
> }
>
> }
>
> No dice. What am I doing wrong?
>
>   
It should be:

config = {
  'global': {
     'engine.autoreload_on' : False,
  },
  '/': {
    'kg.unrepr_params.on' : True,
  }
}

'kg' is the namspace prefix.

- Sylvain

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Custom Toolbox Configuration
country flaguser name
United States
2007-06-07 13:10:35
Thanks Sylvain. Works like a charm.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )