Sean,

I'd be ok with keeping loads/dumps as functions in geojsonlib/__init__.py
They could even raise DepricationWaring.

I've seen r1113's encoding.py, and it's similar to what I had in mind, but
not quite.

There's an extra level of indirection, geojsonlib/__init__ would define:

# nb. in the following, geojsonlib.encoding is renamed to codecs

def encode(obj, codec=None, *args, **kwargs):
     codec = codec or geojsonlib.codecs.default
     return codec.encode(obj, *args, **kwargs)

decode would be much the same.
Then I can write a CJson() codec (which defines encode and decode), and have
that used instead.

in geojsonlib.codecs, my hacked up version of the module goes something
like:

class JSONCodec(objet):
    def encode(self, obj, **kwargs): raise NotImplemented
    def decode(self, obj, **kwargs): raise NotImplemented

try:
   import simplejson
except ImportError:
   default = Codec()
else:
   class SimpleJSONCodec(JSONCodec):

       def encode(self obj, **kwargs):
            return simplejson.dumps(obj, **kwargs)

       def decode(self, obj, **kwargs):
            return simplejson.loads(obj, **kwargs)

   default = SimepJSONCodec


Cheers,
Matt

2008/6/18 Sean Gillies <[EMAIL PROTECTED]>:

> Matt,
>
> What would you think about keeping geojsonlib.dumps/loads as is for
> convenience and just raise exceptions if simplejson can't be imported?
> See rev 1113 -- I marked the dump/load feature as an "extra" in setup.py.
>
> Sean
>
> Matthew Russell wrote:
> > Hi,
> >
> > this is a proposal which Sean already +1'd in the recent "[Community]
> [Fwd:
> > [Geojson] GeoJSON 1.0 Released]" thread.
> >
> > The proposal is to remove the reliance on simplejson from geojsonlib (but
> > keeping simplejson as the default).
> >
> > I'n slight alteration to my previous api suggestion for the interface for
> > simplejson's peers,
> > I'd like to change the api from:
> >
> > geojsonlib.{dumps, dump, loads, load}
> >
> > to:
> >
> > json = geojsonlib.encode(obj, codec="geojsonlib.defaultcodec",
> *codec_args,
> > **codec_kwargs)
> >   - where obj is any python object supporting the geointerface, or a
> mapping
> >   - returns unicode or str
> >
> > obj = geojsonlib.decode(json, codec="geojsonlib.defaultcodec",
> *codec_args,
> > **codec_kwargs)
> >
> >   - where 'json' is a unicode or str instance.
> >   - reutrns a geojsonlib.GeoJSON instance or subclass thereof.
> >
> > The primary motivation for this is file encoding.
> > I'd like to keep the serialisation to file-like objects within the
> control
> > of the user at the I/O boundaries.
> > Removing the dump and load functions from geojsonlib would acheive this.
> > I also think the names encode and decode are better, since load and dumps
> > indicate serialization to disk.
> >
> > So, does anyone object if the api changes from:
> > geojsonlib.dumps -> geojson.encode
> > geojsonlib.loads -> geojson.decode
> > geojsonlib.dump -> file_like.write(geojsonlib.encode(obj))
> > geojsonlib.load -> geojsonlib.decode(file_like.read())
> >
> > ?
> >
> > Once this is implemented, simplejson will only be required in the default
> > case:
> >
> > .encode(obj), .decode(obj)
> >
> > and not if you want to use another JSON library, and have an adapter:
> >
> > e.g
> >
> > class CjsonEncoder:
> >      def encode(self, obj):
> >            ...
> >
> > .encode(obj, codec=CjsonEncoder)
> >
> > N.B:
> >
> > 'codec' can be a dotted path, or any namespace with a .encode or .decode
> > callable attribute as releveant.
> >
> > --
> > Cheers,
> > Matt
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Community mailing list
> > [email protected]
> > http://lists.gispython.org/mailman/listinfo/community
>
> _______________________________________________
> Community mailing list
> [email protected]
> http://lists.gispython.org/mailman/listinfo/community
>
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community

Reply via email to