[Libguestfs] [PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
Nir Soffer
nsoffer at redhat.com
Fri Nov 22 21:23:40 UTC 2019
On Fri, Nov 22, 2019 at 11:14 PM Richard W.M. Jones <rjones at redhat.com> wrote:
>
> On Fri, Nov 22, 2019 at 02:55:31PM -0600, Eric Blake wrote:
> > On 11/22/19 1:53 PM, Richard W.M. Jones wrote:
> > >To avoid breaking existing plugins, Python plugins wishing to use
> > >version 2 of the API must opt in by declaring:
> > >
> > > def api_version():
> > > return 2
> > >
> > >(Plugins which do not do this are assumed to want API version 1).
> >
> > Could we also permit the python code to declare a global variable
> > instead of a function? But a function is just fine (and easier to
> > integrate the way we do all our other callbacks).
>
> I couldn't work out how to do this, plus we have the callback_defined
> function which makes this easy, so yes, I did the easy thing :-)
>
> > >@@ -54,20 +61,20 @@ def get_size(h):
> > > return len(disk)
> > >-def pread(h, count, offset):
> > >+def pread(h, count, offset, flags):
> > > global disk
> > > return disk[offset:offset+count]
> >
> > Do we really want to be passing 'flags' as an integer that the
> > python script must decode?
>
> While I'm no Python programmer, it does look as if existing Python
> core APIs are happy to use bitmasks, eg:
>
> https://docs.python.org/3/library/os.html#os.open
>
> and this is also easy to implement and keeps it similar to the C API.
Lot of python code is a thin wrapper over C code, and low level
details like flags
leak out to python, so this is a reasonable API.
But having more pythonic API can make python developer little happier when
working with this code. I don't know if it is worth the extra effort.
Nir
More information about the Libguestfs
mailing list