Ticket #6910: persisted_sob_py3.patch

File persisted_sob_py3.patch, 2.0 KB (added by real, 8 years ago)

Porting sob to support python3.3 syntax.

  • twisted/persisted/sob.py

    diff --git twisted/persisted/sob.py twisted/persisted/sob.py
    index 89d9caa..1906ce4 100644
    Save and load Small OBjects to and from files, using various formats. 
    99Maintainer: Moshe Zadka
    1010"""
    1111
     12from __future__ import print_function,division,absolute_import
     13from twisted.python.compat import _PY3,NativeStringIO
     14
    1215import os, sys
    1316try:
    1417    import cPickle as pickle
    1518except ImportError:
    1619    import pickle
    17 try:
    18     import cStringIO as StringIO
    19 except ImportError:
    20     import StringIO
     20
    2121from hashlib import md5
    2222from twisted.python import log, runtime
    2323from twisted.persisted import styles
    24 from zope.interface import implements, Interface
     24from zope.interface import implementer, Interface
    2525
    2626# Note:
    2727# These encrypt/decrypt functions only work for data formats
    class IPersistable(Interface): 
    5858        """
    5959
    6060
     61@implementer(IPersistable)
    6162class Persistent:
    6263
    63     implements(IPersistable)
    64 
    6564    style = "pickle"
    6665
    6766    def __init__(self, original, name):
    class Persistent: 
    9291        if passphrase is None:
    9392            dumpFunc(self.original, f)
    9493        else:
    95             s = StringIO.StringIO()
     94            s = NativeStringIO()
    9695            dumpFunc(self.original, s)
    9796            f.write(_encrypt(passphrase, s.getvalue()))
    9897        f.close()
    def load(filename, style, passphrase=None): 
    164163    else:
    165164        _load, mode = pickle.load, 'rb'
    166165    if passphrase:
    167         fp = StringIO.StringIO(_decrypt(passphrase,
     166        fp = NativeStringIO(_decrypt(passphrase,
    168167                                        open(filename, 'rb').read()))
    169168    else:
    170169        fp = open(filename, mode)
    def loadValueFromFile(filename, variable, passphrase=None): 
    205204    if passphrase:
    206205        data = fileObj.read()
    207206        data = _decrypt(passphrase, data)
    208         exec data in d, d
     207        exec(data,d, d)
    209208    else:
    210         exec fileObj in d, d
     209        exec(fileObj,d, d)
    211210    value = d[variable]
    212211    return value
    213212