On 10/01/10 15:08 +0100, Hartmut Goebel wrote:
> > But having one more depth in the dictionary will generate a bigger string.
> > I will work on the staticmethod eval on each object and submit a new
> > patch.
> 
> Two other approaches (based on http://dpaste.org/EOYw/):
> 
> a) Use a dict with only one argument (example will result in 222 chars)::
>     class PYSON(object):
>       [...]
>       def pyson(self):
>         return {
>             '__class__': [self.__class__.__name__,] + self._args
>             }
>     class PYSONDecoder(json.JSONDecoder):
>       [...]
>       def object_hook(self, dct):
>         if '__class__' in dct:
>             args = dct['__class__']
>             klass = globals().get(args[0])
>             return klass.eval(self.__context, *args[1:])
>         return dct
> 
>    ["id", {"__class__": ["If", {"__class__": ["Not", {"__class__": ["In",
> {"__class__": ["Eval", "context", {}]}, "company", null]}]}, "=",
> "!="]}, {"__class__": ["Get", {"__class__": ["Eval", "contex1", {}]},
> "company", 0]}]

The issue is that in json, it is a common practice to use __class__ to extend
json to handle new class. So it is expected to have a string as value, like I
do in the json-rpc patch.

> 
> 
> b) Use only lists (example will result in 132 chars)::
>     class PYSON(object):
>       [...]
>       def pyson(self):
>         return [self.__class__.__name__,] + self._args
>     class PYSONDecoder(json.JSONDecoder):
>       [...]
>       def object_hook(self, args):
>         klass = globals().get(args[0], None)
>         if klass:
>             return klass.eval(self.__context, *args[1:])
>         return dct
> 
>     ["id", ["If", ["Not", ["In", ["Eval", "context", {}], "company",
> null]], "=", "!="], ["Get", ["Eval", "contex1", {}], "company", 0]]
> 

The issue for this one is what about a list that will have one of this key
words ("Eval", "If" etc).

-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email: [email protected]
Jabber: [email protected]
Website: http://www.b2ck.com/
twitter: http://twitter.com/cedrickrier
identi.ca: http://identi.ca/cedrickrier

Attachment: pgpbw2RrpPTMp.pgp
Description: PGP signature

Reply via email to