Good example of BadItem in dill module

I am learning the detect

Dill method and looking for a good simple example of a bad element - one that is elusive to Dill.

I first thought about the process and tried:

>>> proc = os.popen('ls -l')
>>> proc
<open file 'ls -l', mode 'r' at 0x10071d780>
>>> dill.detect.baditems(proc)
[]
>>> dill.dumps(proc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mikekilmer/Envs/env1/lib/python2.7/site-packages/dill/dill.py", line 143, in dumps
    dump(obj, file, protocol, byref)
  File "/Users/mikekilmer/Envs/env1/lib/python2.7/site-packages/dill/dill.py", line 136, in dump
    pik.dump(obj)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
    self.save(obj)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/mikekilmer/Envs/env1/lib/python2.7/site-packages/dill/dill.py", line 557, in save_file
    position = obj.tell()
IOError: [Errno 29] Illegal seek

      

What I expect if Dill uses search detectbaditems

as you cannot search for PIPE.

Then I thought I globals()

might have something to suggest. He suggested the same again IOerror

until proc

deleted, then gave:

>>> dill.detect.baditems(globals)
[<module 'pickle' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc'>, <module 'os' from '/Users/mikekilmer/Envs/env1/lib/python2.7/os.pyc'>, <__main__.Child object at 0x100776090>]

      

What would be a good simple example of an element that dill.detect will return as a bad element?

0


source to share


1 answer


dill.detect.baditems

should check for "bad elements" inside the object (ie check what is inside the object that doesn't split). Perhaps at the top level he should check to see if he himself is dissolving ... currently it is not, and it can be confusing.

Here I will demonstrate an obscene element that baditems

says that nothing is indelible inside, which is true. Then I'll show you how it baditems

finds unmanaged elements inside globals

and correctly identifies what can't be poisoned.



>>> x = iter([1,2,3,4,5])
>>> x
<listiterator object at 0x10d743510>
>>> import dill
>>> # everything inside a listiterator is serializable
>>> dill.detect.baditems(x)
[]
>>> # however, not everything in globals is serializable
>>> dill.detect.baditems(globals())
[<module '__builtin__' (built-in)>, <listiterator object at 0x10d743510>]

      

I hope this doesn't seem too controversial.

+1


source







All Articles