[execnet-dev] testing vim with execnet
Adam
Adam.Schmalhofer at gmx.de
Thu Nov 19 18:29:57 CET 2009
Hi Holger,
holger krekel wrote:
> On Wed, Nov 18, 2009 at 12:55 +0100, Adam wrote:
> > However I can't access any of vim's python objects directly. I can only
> > let vim manipulate them (via vim.command) and exchange strings over
> > vim.current.buffer. e.g.:
> yes, true and nothing that could easily change i think.
Ok. This surprised me as socketserver has access to these.
> Maybe you could try to extract values via 'vim.eval'?
vim.eval gives access to vim-script but not vim's python. This gave me
the right hint for the solution (see below).
> I haven't used the vim-python-plugin myself yet, btw.
I didn't assume that. I asked here because I thought it wasn't needed
(see two above).
> > unpickling strings exchanged over vim.current.buffer fails, too.
>
> not sure what you mean - Strings should be sendable/receiveable. what
> exactly fails?
I thought that pickle strings where too exotic for vim.current.buffer.
Now, I really have no clue, what fails.[1] Pickling over vim.eval does
works, however.[2] Thank you for the idea. Now I'll work on sugaring it.
Problem solved.
--Adam
[1] I'm either making a stupid mistake or something really funky is
going on. If I type this into vim directly (without the vim.command
everything works.
Left for the interested. Irrelevant now as [2] works well:
>>> def test_execnet_buffer_pickle(vim_gateway):
>>> import pickle
>>> channel = vim_gateway.remote_exec(r"""
... import vim
... vim.command('py import pickle')
... vim.command('py import vim')
... vim.command('py b = pickle.dumps([1, 2, 3])')
... vim.command('py if b == "": b = "empty"')
... vim.command('py vim.current.buffer[0] = b.split("\n")[0]')
... vim.command('py if vim.current.buffer[0] == "": vim.current.buffer[0] = "broken"')
>>> channel.send(vim.current.buffer[0])""")
>>> buf = channel.receive()
>>> channel.close()
>>> assert buf != 'broken' # fails
>>> #assert '\n'.join(buf) == pickle.dumps([1, 2, 3]) # '(lp0\nI1\naI2\naI3\na.'
[2] The solution:
>>> def test_execnet_eval_pickle(vim_gateway):
>>> import pickle
>>> channel = vim_gateway.remote_exec(r"""
... import vim
... vim.command('py import pickle')
... vim.command('py import vim')
... vim.command('py b = pickle.dumps([1, 2, 3])')
... vim.command('''py vim.command("let execnet='%s'" % b)''')
... b = vim.eval("execnet")
... channel.send(b)""")
>>> buf = channel.receive()
>>> channel.close()
>>> assert buf == pickle.dumps([1, 2, 3]) # passes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/execnet-dev/attachments/20091119/98948241/attachment.pgp>
More information about the execnet-dev
mailing list