Hi,
following is marshal and unmarshal script
import marshal
strng = """
print 'hello world'
"""
code = compile(strng, "<strng>", "exec")
data = marshal.dumps(c ode)
strng0 = marshal.loads(d ata)
print repr(data)
print "-"*100
print strng0
###Result:
'c\x00\x00\x00\ x00\x01\x00\x00 \x00s\x0f\x00\x 00\x00\x7f\x00\ x00\x7f\x02\x00 d\x00\x00GHd\x0 1\x00S(\x02\x00 \x00\x00s\x0b\x 00\x00\x00hello
worldN(\x00\x00 \x00\x00(\x00\x 00\x00\x00(\x00 \x00\x00\x00(\x 00\x00\x00\x00s \x07\x00\x00\x0 0<strng>s\x01\x 00\x00\x00?\x02 \x00s\x00\x00\x 00\x00'
----------------------------------------------------------------------------------------------------
<code object ? at 0x81690c0, file "<strng>", line 2>
Question:
1. why unmarshal data is
<code object ? at 0x81690c0, file "<strng>", line 2>
not
'c\x00\x00\x00\ x00\x01\x00\x00 \x00s\x0f\x00\x 00\x00\x7f\x00\ x00\x7f\x02\x00 d\x00\x00GHd\x0 1\x00S(\x02\x00 \x00\x00s\x0b\x 00\x00\x00hello
worldN(\x00\x00 \x00\x00(\x00\x 00\x00\x00(\x00 \x00\x00\x00(\x 00\x00\x00\x00s \x07\x00\x00\x0 0<strng>s\x01\x 00\x00\x00?\x02 \x00s\x00\x00\x 00\x00'
2. how safe is the compiled and serialize data.
'c\x00\x00\x00\ x00\x01\x00\x00 \x00s\x0f\x00\x 00\x00\x7f\x00\ x00\x7f\x02\x00 d\x00\x00GHd\x0 1\x00S(\x02\x00 \x00\x00s\x0b\x 00\x00\x00hello
worldN(\x00\x00 \x00\x00(\x00\x 00\x00\x00(\x00 \x00\x00\x00(\x 00\x00\x00\x00s \x07\x00\x00\x0 0<strng>s\x01\x 00\x00\x00?\x02 \x00s\x00\x00\x 00\x00'
following is marshal and unmarshal script
import marshal
strng = """
print 'hello world'
"""
code = compile(strng, "<strng>", "exec")
data = marshal.dumps(c ode)
strng0 = marshal.loads(d ata)
print repr(data)
print "-"*100
print strng0
###Result:
'c\x00\x00\x00\ x00\x01\x00\x00 \x00s\x0f\x00\x 00\x00\x7f\x00\ x00\x7f\x02\x00 d\x00\x00GHd\x0 1\x00S(\x02\x00 \x00\x00s\x0b\x 00\x00\x00hello
worldN(\x00\x00 \x00\x00(\x00\x 00\x00\x00(\x00 \x00\x00\x00(\x 00\x00\x00\x00s \x07\x00\x00\x0 0<strng>s\x01\x 00\x00\x00?\x02 \x00s\x00\x00\x 00\x00'
----------------------------------------------------------------------------------------------------
<code object ? at 0x81690c0, file "<strng>", line 2>
Question:
1. why unmarshal data is
<code object ? at 0x81690c0, file "<strng>", line 2>
not
'c\x00\x00\x00\ x00\x01\x00\x00 \x00s\x0f\x00\x 00\x00\x7f\x00\ x00\x7f\x02\x00 d\x00\x00GHd\x0 1\x00S(\x02\x00 \x00\x00s\x0b\x 00\x00\x00hello
worldN(\x00\x00 \x00\x00(\x00\x 00\x00\x00(\x00 \x00\x00\x00(\x 00\x00\x00\x00s \x07\x00\x00\x0 0<strng>s\x01\x 00\x00\x00?\x02 \x00s\x00\x00\x 00\x00'
2. how safe is the compiled and serialize data.
'c\x00\x00\x00\ x00\x01\x00\x00 \x00s\x0f\x00\x 00\x00\x7f\x00\ x00\x7f\x02\x00 d\x00\x00GHd\x0 1\x00S(\x02\x00 \x00\x00s\x0b\x 00\x00\x00hello
worldN(\x00\x00 \x00\x00(\x00\x 00\x00\x00(\x00 \x00\x00\x00(\x 00\x00\x00\x00s \x07\x00\x00\x0 0<strng>s\x01\x 00\x00\x00?\x02 \x00s\x00\x00\x 00\x00'
Comment