On Monday 07 January 2008 10:10:59 Daniel Fetchinson wrote:
> I have a number of classes that subclass SQLObject as well as a mixin
> class and now would like to jsonify them:
>
> class myclass1( SQLObject, Mixin ):
>     .........
>     .........
>
> class myclass2( SQLObject, Mixin ):
>     ..........
>     ..........
>
> Since I have other classes that only subclass SQLObject I need to keep
> the jsonify_sqlobject rule too but simply using @jsonify.when(
> 'isinstance( obj, Mixin )' ) raises an AmbiguousMethod exception
> because my objects match both isinstance( obj, SQLObject ) and
> isinstance( obj, Mixin ). After looking into RuleDispatch this is to
> be expected because neither of the two conditions is more specific
> than the other so an AmbiguousMethod exception is raised. So far I
> understand the story.
>
> When is not clear is how to work around it. How would I force
> RuleDispatch to use my rule? I thought @jsonify.before( 'isinstance(
> obj, Mixin )' ) would do the trick because the 'before' method would
> come before the primary rule but it doesn't work, only the original
> jsonify_sqlobject rule is run.

Just a thought, not sure if it works:

class MyBase(SQLObject, Mixin):
     pass

class myclass1(MyBase):
   . ...


If that works, go for it - if not, I'd say: one rule for each of your myclass* 
is ok, or do you write so many of them? You could of course use the same 
inner code then, either by registering one function for several signatures or 
via a delegated call.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to