元帅Obj是字符串还是二进制? [英] Marshal Obj is String or Binary?

查看:66
本文介绍了元帅Obj是字符串还是二进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




下面的示例显示封送数据结构的结果是

只是一个字符串

Hi,

The example below shows that result of a marshaled data structure is
nothing but a string

data = {2:''two'',3:''three''}
import marshal
bytes = marshal.dumps(数据)
类型(字节)
< type''str''> bytes
data = {2:''two'', 3:''three''}
import marshal
bytes = marshal.dumps(data)
type(bytes) <type ''str''> bytes



''{i\x02 \ x00 \ x00 \ x00t \ x03 \ x00 \ x00 \ x00twoi \\ \\ x03 \x00 \ x 00 \ x00t \ x05 \ x00 \ x00 \ x00three0''


现在,我需要将这些数据安全地存储在我的数据库中作为CLEAR TEXT,而不是
BLOB。在我看来它应该工作得很好,因为它是字符串

无论如何。那么,为什么O''reilly的Python Cookbook坚持将它保存为二进制文件和BLOB类型?


我错过了什么?


谢谢,

迈克


''{i\x02\x00\x00\x00t\x03\x00\x00\x00twoi\x03\x00\x 00\x00t\x05\x00\x00\x00three0''

Now, I need to store this data safely in my database as CLEAR TEXT, not
BLOB. It seems to me that it should work just fine since it is string
anyways. So, why does O''reilly''s Python Cookbook is insisting in saving
it as a binary file and BLOB type?

Am I missing out something?

Thanks,
Mike

推荐答案

在< 11 ********************** @ g47g2000cwa.googlegroups .com>中,Mike写道:
In <11**********************@g47g2000cwa.googlegroups .com>, Mike wrote:
下面的示例显示封送数据结构的结果只是一个字符串
The example below shows that result of a marshaled data structure is
nothing but a string
data = {2:''two'', 3:''三''}
导入元帅
bytes = marshal.dumps(数据)
类型(字节)< type''str''> bytes
data = {2:''two'', 3:''three''}
import marshal
bytes = marshal.dumps(data)
type(bytes) <type ''str''> bytes


''{i \ x02 \ x00 \ x00 \ x00t \ x03 \ x00 \ x00 \ x00twoi \ x03 \ x00 \ x 00 \x00t \ x05 \ x00 \ x00 \ x00three0''
现在,我需要将这些数据安全地存储在我的数据库中作为CLEAR TEXT,而不是BLOB。在我看来它应该工作得很好,因为它是字符串
无论如何。那么,为什么O''reilly的Python Cookbook坚持将它保存为二进制文件和BLOB类型?

我错过了什么?


''{i\x02\x00\x00\x00t\x03\x00\x00\x00twoi\x03\x00\x 00\x00t\x05\x00\x00\x00three0''

Now, I need to store this data safely in my database as CLEAR TEXT, not
BLOB. It seems to me that it should work just fine since it is string
anyways. So, why does O''reilly''s Python Cookbook is insisting in saving
it as a binary file and BLOB type?

Am I missing out something?




是的,字符串是* binary * data。但只有一小部分字符串在数据库中作为TEXT使用是安全的。
。你看到所有''\ x ??''逃脱了吗?

''\ x00''是*一个*字节!一个值为零的字节。你的DB

不允许使用`TEXT`类型。


Ciao,

Marc''BlackJack' 'Rintsch



Yes, that a string is *binary* data. But only a subset of strings is safe
to use as `TEXT` in databases. Do you see all those ''\x??'' escapes?
''\x00'' is *one* byte! A byte with the value zero. Something your DB
doesn''t allow in a `TEXT` type.

Ciao,
Marc ''BlackJack'' Rintsch


等一下。 \ x00可能在解组时表示一个字节,但只要

marshal将其视为\ x00,我认为我的数据库能够存储\ x 0 0

个字符。问题是什么?是那个吗 \?我可以逃脱...

实际上我认为我的django框架已经为我做了。


谢谢,

迈克

Wait a sec. \x00 may represent a byte when unmarshaled, but as long as
marshal likes it as \x00, I think my db is capable of storing \ x 0 0
characters. What is the problem? Is it that \? I could escape that...
actually I think my django framework already does that for me.

Thanks,
Mike


等一下。 \ x00可能在解组时表示一个字节,但只要

marshal将其视为\ x00,我认为我的数据库能够存储\ x 0 0

个字符。问题是什么?是那个吗 \?我可以逃脱...

实际上我认为我的django框架已经为我做了。


谢谢,

迈克

Wait a sec. \x00 may represent a byte when unmarshaled, but as long as
marshal likes it as \x00, I think my db is capable of storing \ x 0 0
characters. What is the problem? Is it that \? I could escape that...
actually I think my django framework already does that for me.

Thanks,
Mike


这篇关于元帅Obj是字符串还是二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆