[ovs-dev] [python idl 04/16] ovs.json: Actually implement the "pretty" option for serialization.
Ethan Jackson
ethan at nicira.com
Tue Sep 20 00:42:52 UTC 2011
I'm not sure that the _Serializer object is really adding much here.
It's nice to split up the logic into several functions, but that could
be done as nested definitions in the to_stream() function. I think
you would simply need to implement _serialize_string() and
_indent_line() as nested definitions. Then you could avoid some of
the OO boilerplate. Plus it would be obviously clear that the only
thing that cares about _Serializer is to_stream().
Anyways, that's a personally preference. If you think this approach
is better, it's probably fine.
> +SPACES_PER_LEVEL = 2
> +
> +class _Serializer(object):
A second newline is required above the class definition.
> + else:
> + raise Exception("can't serialize %s as JSON" % obj)
A newline is required after this raise.
Ethan
More information about the dev
mailing list