On Tue, 27 Dec 2011 20:43:01 -0500
Brian Theado <[email protected]> wrote:

>     getSaxUa can not unpickle


Shoot, that's annoying.  Past discussion has realized that pickling
things is a dubious approach, bat you're dealing with a pickled
datetime, and you'd hope that was safe enough, apparently not.

There's a lot of discussion on the web about this, but I can't find a
solution.  A simple test script up.py, is attached, but none of the
loads() calls in the 3.x code path work.

Cheers -Terry

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

import sys
from pickle import loads
from binascii import a2b_hex
d = '7d71005509636f6d706c6574656471016364617465746' \
    '96d650a6461746574696d650a710228550a07db0c1a16' \
    '3226013e477103747104527105732e'
    
if sys.version_info >= (3, 0):
    
    assert d.__class__.__name__ == 'str'
    d = d.encode('ascii')
    assert d.__class__.__name__ == 'bytes'
    
    data = a2b_hex(d)
    
    assert data.__class__.__name__ == 'bytes'
    
    # obj = loads(data, fix_imports=True)
    # obj = loads(data.decode('ascii'), fix_imports=True, encoding='ascii')
    # obj = loads(data.decode('latin-1'), fix_imports=True, encoding='latin-1')
    obj = loads(data, fix_imports=True, encoding='latin-1')
    
    print(obj)

else:
    
    assert d.__class__.__name__ == 'str'
    
    data = a2b_hex(d)
    obj = loads(data)
    print(obj)

Reply via email to