Loading ...
Sorry, an error occurred while loading the content.

Re: pyeval() error

Expand Messages
  • Marcin Szamotulski
    ... This the purpose of pyeval() and py3eval() functions which came with a recent patch (by Zyx). Thank you Zyx for showing me the weak points. I only used
    Message 1 of 11 , Sep 1, 2012
    • 0 Attachment
      On 16:06 Sat 01 Sep , Sean Estabrooks wrote:
      >
      >
      >
      > > > Prior to pyeval() function I was using
      > > >
      > > > vim.command("let dict=%s" % python_dict)
      > >
      > > I used json.dumps and a self-written dumper for this job. The above code is one of the worst ideas that could go into your head:
      >
      > This seems a little harsh. The above code is convenient and rather straightforward. Shouldn't we find a way to make it work?
      >
      > >
      > > 1. (string % tuple_or_value) notation is deprecated.
      > > 2. “"%s" % {u'«»': 1}” produces “{u'\xab\xbb': 1}” which can’t be handled in vim.
      > > 3. “"%s" % {'«»': 1}” produces “{'\xc2\xab\xc2\xbb': 1}” which is not handled by vim in a proper way.
      > > 4. There is a bunch of other things calling __repl__ on which will result in something vim won’t understand, but in this case vim won’t even understand simple unicode or utf-8 encoded strings as shown above.
      > >
      > > json.dumps minimizes the amount of problematic things (including converting keys to strings) and throws an exception if it can’t handle something, my interface does this as well. I do not do some type conversions that json.dumps does, json.dumps fails to handle some things which I handle (“pyeval('vim.current.buffer')” produces same output as “getline(1, '$')”, but “json.dumps(vim.current.buffer)” fails).
      > >
      > > Self-written dumper was used to get binary data: “json.dumps('\x80')” throws an exception while vim is fine with just having it embedded inside a string.
      > >
      >
      > Obviously it would be much better if everyone who is using python inside of Vim doesn't have to write their own custom code to transfer these values.  Do you have a plan in this regard or is this an open problem?
      >
      > Thanks,
      > Sean

      This the purpose of pyeval() and py3eval() functions which came with
      a recent patch (by Zyx).

      Thank you Zyx for showing me the weak points. I only used this for ASCII
      and integers, though at some point this would lead to a problem.

      Best,
      Marcin

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Sean Estabrooks
      ... Ah, looks good.  Thanks for setting me straight. Sean -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the
      Message 2 of 11 , Sep 1, 2012
      • 0 Attachment
        ----------------------------------------
        > Date: Sun, 2 Sep 2012 00:54:42 +0100
        > From: mszamot@...
        > To: vim_dev@...
        > Subject: Re: pyeval() error
        >
        > On 16:06 Sat 01 Sep , Sean Estabrooks wrote:
        ...
        >> Obviously it would be much better if everyone who is using python inside of Vim doesn't have to write their own custom code to transfer these values. Do you have a plan in this regard or is this an open problem?
        >>
        >
        > This the purpose of pyeval() and py3eval() functions which came with
        > a recent patch (by Zyx).
        >
        > Thank you Zyx for showing me the weak points. I only used this for ASCII
        > and integers, though at some point this would lead to a problem.

        Ah, looks good.  Thanks for setting me straight.

        Sean




        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • ZyX
        ... Not exactly. Try to transfer a few hundred KiBs with json.dumps and with my interface and you will see the difference. Self-written dumper is much, much
        Message 3 of 11 , Sep 2, 2012
        • 0 Attachment
          > This the purpose of pyeval() and py3eval() functions which came with
          > a recent patch (by Zyx).

          Not exactly. Try to transfer a few hundred KiBs with json.dumps and with my interface and you will see the difference. Self-written dumper is much, much slower as it is not written in C and it was necessary to make it able to get even more information from time to time. That was the real purpose as dumper is trivial and easy to write (though vim.bindeval interface solves custom dumpers problem as well).

          By the way, why almost everybody says that it were pyeval functions that were added in first place? Main change is vim.bindeval as you can write code like

          def return_to_vim(value):
          if hasattr(vim, 'bindeval'):
          vim.bindeval('d')['result']=value
          else:
          vim.eval('extend(d, {"result": '+dumps(value)+'})')
          and be compatible with old versions of vim. pyeval() does not allow you to do it so easily (though I can imagine Pyeval function that works in old vims as well, it is more to type). pyeval() is slightly faster, but it is negligible and constant difference.

          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        Your message has been successfully submitted and would be delivered to recipients shortly.