"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/chempy/pkl.py" between
pymol-v1.8.6.0.tar.bz2 and pymol-v2.1.0.tar.bz2

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

pkl.py  (pymol-v1.8.6.0.tar.bz2):pkl.py  (pymol-v2.1.0.tar.bz2)
skipping to change at line 21 skipping to change at line 21
#-* #-*
#-* #-*
#Z* ------------------------------------------------------------------- #Z* -------------------------------------------------------------------
from chempy import Storage from chempy import Storage
try: try:
import cPickle import cPickle
except ImportError: except ImportError:
import pickle import pickle
# Python 3: Unpickle printable ASCII strings in [TAB, DEL) to unicode,
# and everything else to bytes.
# This uses the Python implementation of pickle, not the fast cpython
# version, which unfortunately is much slower.
def _decode_string(self, value):
if all(8 < b < 127 for b in value):
return value.decode('ascii')
return value
pickle._Unpickler._decode_string = _decode_string
# string pickling backported from Python 2
def save_str(self, obj):
from struct import pack
if self.bin:
if not isinstance(obj, bytes):
obj = obj.encode('utf-8', 'ignore')
n = len(obj)
if n < 256:
self.write(pickle.SHORT_BINSTRING + pack("<B", n) + obj)
self.write(pickle.BINSTRING + pack("<i", n) + obj)
obj_repr = repr(obj).encode('utf-8', 'ignore').lstrip(b'b')
self.write(pickle.STRING + obj_repr + b'\n')
pickle._Pickler.dispatch[str] = save_str
pickle._Pickler.dispatch[bytes] = save_str
class cPickle: class cPickle:
dumps = pickle.dumps dumps = pickle.dumps
dump = pickle.dump dump = pickle.dump
def load(f): load = pickle._load
return pickle.load(f, errors='ignore')
def loads(s): def loads(s):
if not isinstance(s, bytes): if not isinstance(s, bytes):
s = s.encode(errors='ignore') s = s.encode(errors='ignore')
return pickle.loads(s, errors='ignore') return pickle._loads(s)
def configure_legacy_dump(cls, py2=False):
if py2:
cls.dumps = pickle._dumps
cls.dump = pickle._dump
cls.dumps = pickle.dumps
cls.dump = pickle.dump
class PKL(Storage): class PKL(Storage):
def fromFile(self,fname,**params): def fromFile(self,fname,**params):
fp = self.my_open(fname,'rb') fp = self.my_open(fname,'rb')
result = cPickle.load(fp) result = cPickle.load(fp)
fp.close() fp.close()
return result return result
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
 End of changes. 3 change blocks. 
3 lines changed or deleted 45 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)