Winter Madness - Passing Python objects as Strings

  • Thread starter Hendrik van Rooyen
  • Start date
H

Hendrik van Rooyen

When the days get colder and the nights longer,
then evil things are hatched.

A can is like a pickle, in that it is a string, but anything
can be canned.
Unlike a pickle, a can cannot leave the process, though,
unless the object it points to lives in shared memory.

Here is the output of a test session:
python -i cantest.py

dir(Can) yields:
['__doc__', '__file__', '__name__', 'can', 'uncan']

Testing string object
s is: The quick brown fox jumps over the lazy dog
id(s) is: 47794404772392
ps = can(s) : 47794404772392
t = uncan(ps): The quick brown fox jumps over the lazy dog
t is s gives: True

Testing q = Queue.Queue()
q is: <Queue.Queue instance at 0x2b780085e830>
id(q) is: 47794404845616
pq = can(q) : 47794404845616
r = uncan(pq): <Queue.Queue instance at 0x2b780085e830>
r is q gives: True

Testing banana class object
b = banana() <__main__.banana object at 0x73d190>
id(b) is: 7590288
pb = can(c) : 7590288
c = uncan(pb): <__main__.banana object at 0x73d190>
c is b gives: True

That's it, folks!<end of test output>

Now I have only tested it on my system, which is 64 bit SuSe Linux.
I suspect it is fragile.
I know it is dangerous - if you uncan a random
number, then if you are lucky, you will get a segfault.
If you are not lucky, your life will be completely
changed.

If you have any interest, contact me and I will
send you the source.

- Hendrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top