The error basicly says that there are more than one method that are
registred to handle the object. Are you sure that the jsonify.when()
code isn't run more than once.

On 5/24/06, Joost Moesker <[EMAIL PROTECTED]> wrote:
>
> Hi, i'm trying to use jsonify to make sure that my custom Null objects
> are encoded as 'null'.  The following seems to work:
>
> >>> import turbojson
> >>> from turbojson.jsonify import jsonify
> >>> class Test2: pass
> ...
> >>> @jsonify.when("isinstance(obj, Test2)")
> ... def jsonify_test2(obj):
> ...      return None
> ...
> >>> turbojson.jsonify.encode(Test2())
> 'null'
> >>>
>
> Yet when I try to write a jsonify function for a Null object
> implementation:
>
> >>> class Null(object): # based on cookbook recipie 6.17
> ...     """ Null objects alwasy and reliable 'do nothing'."""
> ...     def __init__(self, *args, **kwars): pass
> ...     def __call__(self, *args, **kwars): return self
> ...     def __repr__(self): return 'Null()'
> ...     def __nonzero__(self): return False
> ...     def __getattr__(self, name): return self
> ...     def __setattr__(self, name, value): return self
> ...     def __delattr__(self, name): return self
> ...     def __getitem__(self, name): return self
> ...     def __setitem__(self, name, value): return self
> ...     def __delitem__(self, name): return self
> ...
> >>> @jsonify.when("isinstance(obj, Null)")
> ... def jsonify_null(obj):
> ...      return None
> ...
> >>> turbojson.jsonify.encode(Null())
> Traceback (most recent call last):
>   File "<console>", line 1, in ?
>   File
> "c:\python24\lib\site-packages\TurboJson-0.9.2-py2.4.egg\turbojson\jsonify.py",
> line 63, in encode
>     return _instance.encode(obj)
>   File
> "C:\Python24\lib\site-packages\simplejson-1.3-py2.4.egg\simplejson\encoder.py",
> line 270, in encode
>   File
> "C:\Python24\lib\site-packages\simplejson-1.3-py2.4.egg\simplejson\encoder.py",
> line 231, in _iterencode
>   File
> "C:\Python24\lib\site-packages\simplejson-1.3-py2.4.egg\simplejson\encoder.py",
> line 237, in _iterencode_default
>   File
> "c:\python24\lib\site-packages\TurboJson-0.9.2-py2.4.egg\turbojson\jsonify.py",
> line 58, in default
>     return jsonify(obj)
>   File "<string>", line 5, in jsonify
>   File "_speedups.pyx", line 376, in
> _speedups.BaseDispatcher.__getitem__
>   File
> "C:\Python24\lib\site-packages\ruledispatch-0.5a0dev_r2097-py2.4-win32.egg\dispatch\interfaces.py",
> line 15, in __call__
> AmbiguousMethod: ([(Signature((2, <class
> 'dispatch.strategy.Node'>)=TruthCriterion(True)), <function
> jsonify_explicit at 0x0118A0F0>), (Signature((0, <class
> 'dispatch.strategy.Node'>)=Null), <function jsonify_null at
> 0x018B19F0>)], (None,), {})
>
>
> The traceback doesn't help much :S... Anythoughts on this?
>
>
> >
>


-- 
cheers
    elvelind grandin

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to