用wxPython通过剪贴板传递复杂的数据结构可以吗?
我希望我的 wxPython 应用程序支持应用程序的不同运行实例之间的剪切/复制/粘贴操作。是否可以简单地pickle数据结构,将其作为文本复制到剪贴板,然后取消pickle以进行粘贴操作?
我知道我必须检查数据是否有来自我的应用程序的迹象。或者我可以试着把里面的东西解开吗?如果 pickle 试图解开剪贴板上留下的任意文本,那么它的稳健性如何?
另外,通过这种方式复制的数据量是否有实际限制?
我今天在 Windows 和 Linux 上运行 - 还没有尝试过 Mac。
编辑 我知道文档中的评论。我并不真正关心恶意用户试图破坏他自己的软件实例,如果这是人们担心的,他们应该弃用pickle。我的问题是实用性的,而不是安全性的。
I'd like my wxPython application to support cut/copy/paste operations between different running instances of the application. Is it OK to simply pickle a data structure, copy it to clipboard as text, and then unpickle it for paste operations?
I know I'd have to check the data for some sign that it's from my app. Or could I just TRY to unpickle whatever is there? How robust is pickle at nicely failing if it tries to unpickle arbitrary text left on the clipboard?
Also, is there a practical limit to how much data could be copied this way?
I'm running on Windows and Linux today - have not tried Mac.
EDIT
I'm aware of that comment in the documentation. I don't really care about a malicious user trying to compromise his own instance of the software, if that's what people are worried about they should deprecate pickle. My questions are of practicality, not security.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该信任剪贴板中的数据来进行解封,除非您有可靠的方法来确保它是由您的应用程序写入的并且未被更改。
来自Python文档:
You should not trust data from the clipboard for unpickling, unless you have a sure way to make sure it was wrtten by your app, and has not been altered.
From the python documentation:
如果适用,我建议您使用众多 python 实现之一将数据与 json 相互转换。
使用剪贴板传输纯文本很容易,而且将 json 对象转换回 python 没有风险。
最后一件事:没有弃用的风险。
If applicable I suggest you to convert your data to and from json using one of the many python implementations.
Being plain text is easy to transfer using clipboard moreover there are no risks converting back a json object back to python.
One last thing: no risks of deprecation.