Em Quinta 27 Abril 2006 19:42, Simon Belak escreveu:
> Hi,
>
> I'm going to make everyone's life miserable again. ;)
>
> In r1279 I added support for "alternative" decorator syntax as used by
> PEAK to lessen the anguish of people still on Python 2.3. This
> unfortunately requires a bit different application of decorator() function.
>
> Before:
>
>    def foo(a):
>      def entagle(func)
>        def caller(func, *args, **kw):
>          func(*args, **kw)
>        return decorator(caller)(func)
>      return entagle
>
> after:
>
>    def foo(a):
>      def entagle(func)
>        def caller(func, *args, **kw):
>          func(*args, **kw)
>        return caller
>      return decorator(entagle)
>
> As an added bonus it is also marginally more concise.

I had, before:

@decorator
def my_decorator(func, *args, **kwords):
    ...

How should I translate it to the new syntax?  I'm not worried with supporting 
Python 2.3 here, so the easiness of the old syntax was very nice to me.

> While I was at it, I made another change. Until now decorator() added
> *args and **kw to the resulting function signature unless optional
> argument "argsink" was false.
> Well, "argsink" is no more. Instead we have a much more powerful (still
> optional) argument "signature" similar in composition to what
> inspect.getargspec() returns, allowing us to define an arbitrary
> signatures (mind, the function being decorated still needs to be able to
> digest this new parameter specification).
> To get the beloved care-free will-eat-anything signatures back a helper
> named weak_signature_decorator() is available.

I tried it as well, but it won't work with the above (mine) syntax.  I had to 
convert to your syntax to have it working...  But then, I started having 
other problems, specially with @turbogears.validate, which is failing always. 

> I invite all interested to take a look at decorator.py and
> test_decorator.py. The use of signature in anger can be observed in
> util.bind_args().
>
> Knowing myself I suggest we keep it in trunk for a while (maybe until
> after the sprint and than send it into the wild with nice and shiny
> documentation by it's side).

Here are my "attempts":

===============================================================================
def mensagem_json():
    def entangle(func):
        def caller(func, *args, **kwords):
            print "#################"
        return caller
    return decorator(entangle)
===============================================================================

What results in:

===============================================================================
Traceback (most recent call last):
  File "./start-siteamostras.py", line 26, in ?
    from siteamostras.controllers import Root
  File 
"/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/controllers/__init__.py",
 
line 18, in ?
    from siteamostras.controllers.toxicologia import Toxicologia
  File 
"/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/controllers/toxicologia.py",
 
line 24, in ?
    from siteamostras.controllers import analises
  File 
"/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/controllers/analises.py",
 
line 29, in ?
    class Analises(controllers.Controller):
  File 
"/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/controllers/analises.py",
 
line 213, in Analises
    @turbogears.expose()
TypeError: mensagem_json() takes no arguments (1 given)
===============================================================================

When I change it to:

===============================================================================
def mensagem_json(something):
    def entangle(func):
        def caller(func, *args, **kwords):
            print "#################"
        return caller
    return decorator(entangle)
===============================================================================

it runs, but @turbogears.validate fails.

Changing it to:

===============================================================================
def mensagem_json(func):
    def entangle(func):
        def caller(func, *args, **kwords):
            print "#################"
        return caller
    return decorator(entangle)
===============================================================================

Using weak_signature_decorator doesn't help and yields the same results.


In my code I have:

===============================================================================
    @turbogears.expose()
    @turbogears.error_handler(turbogears.util.bind_args(add = True)(analises))
    @turbogears.validate(form = formulario_analises)
    @identity.require(identity.conditions.in_group("latam_novo"))
    @mensagem_json
    def save(self, **kword):
        ...
===============================================================================

I hope I'm doing something wrong and that is easy to solve.

-- 
Jorge Godoy      <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to