Status -- More options and some better examples in subversion

166 views
Skip to first unread message

Patrick Maupin

unread,
Mar 14, 2010, 4:34:19 PM3/14/10
to rson-discuss
I am developing new capabilities in subversion, and it will probably
be awhile before I make another release, unless somebody finds a
really serious bug.

The RSON decoder is composed of lots of small parts, any of which can
be replaced by client code. This can be done either by subclassing
the RsonSystem class and then calling the dispatcher_factory() method
to create a new version of loads(), or by passing keyword arguments
into loads() to override various methods and attributes.

(Unfortunately, these methods and attributes are not yet documented
anywhere except in the actual code. But all the simplejson attributes
like parse_int and parse_float and object_hook are supported, as well
as some more generic ones.)

Either customization method (subclassing or keyword arguments) has the
same results. Subclassing might be slightly more efficient if your
program is making multiple calls to the decoder, but it is mainly a
matter of user preference.

As I replied to Baptiste earlier, by default, RSON dict keys do not
need to be strings (or even scalars). However, for JSON
compatibility, this might need to be enforced. The code which tests
against the simplejson testsuite subclasses RsonSystem, and, among
other compatibility changes, has an example of this sort of
restriction in it.

http://code.google.com/p/rson/source/browse/trunk/py2x/testbench/cjsontest.py

But, not only can stock RSON's capabilities be restricted in this
manner -- they can also be enhanced. For example, I now have an
example which relaxes the syntax for indentation such that single
values and key/value pairs can be mixed together at the same
indentation level.

Normally, you would think this is a bad thing -- it is neither a dict
nor an array, but some bizarre halfway in-between construct. I think
I just described XML, and, in fact, the example will generate XML from
RSON.

Example file containing some RSON and the XML it translated into:

http://code.google.com/p/rson/source/browse/trunk/py2x/tools/testxml.py

The code which sits on top of generic RSON and which was used to do
the transformation:

http://code.google.com/p/rson/source/browse/trunk/py2x/tools/toxml.py

Because I'm a mad scientist (please note that, definitionally, a mad
scientist doesn't even need to be that good of a scientist, and that
won't bother him as long as he is quite mad enough), I'm very pleased
with the results.

Unfortunately, I don't have an encoder yet, and the real-world
intervenes, so it will be awhile before I code something to round-trip
back the other way from XML to RSON.

Because RSON syntax is so flexible, actually creating an encoder for
RSON that makes results that people want to see might be difficult.
However, for spot solutions it is not so difficult. I have coded one
encoder that is really specific to rst2pdf stylesheets here:

http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/dumpstyle.py

The results might not look so good on other things, but it might give
some ideas on how to do an encoder.

But if anybody is interested in contributing an encoder, just say the
word and you can have commit privileges!

Thanks,
Pat

Reply all
Reply to author
Forward
0 new messages