Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0822cd8
PY3: support print function in PY2
pavoljuhas Sep 25, 2019
15bbfa6
PY3: use fast cPickle module for Python 2
pavoljuhas Sep 25, 2019
e337d56
PY3: fix RawConfigParser import for PY2
pavoljuhas Sep 25, 2019
0cc295a
PY3: use six.StringIO for PY2/PY3 compatibility
pavoljuhas Sep 26, 2019
03fecd3
MNT: drop obsolete test code
pavoljuhas Sep 26, 2019
984df64
MNT: add todo-list of sources for 2to3 conversion
pavoljuhas Sep 26, 2019
ae9f498
PY3: 2to3 conversion of applications/pdfgui.py
pavoljuhas Sep 26, 2019
cefbaec
PY3: 2to3 check of control/calculation.py
pavoljuhas Sep 26, 2019
7dd95d0
PY3: 2to3 check of control/constraint.py
pavoljuhas Sep 26, 2019
8e67f19
PY3: 2to3 check of control/fitdataset.py
pavoljuhas Sep 26, 2019
28cb664
PY3: 2to3 check of control/fitstructure.py
pavoljuhas Sep 26, 2019
4e1e555
PY3: 2to3 check of control/fitting.py
pavoljuhas Sep 26, 2019
ef77eba
PY3: 2to3 check of control/organizer.py
pavoljuhas Sep 26, 2019
42b9c9d
PY3: 2to3 check of control/parameter.py
pavoljuhas Sep 26, 2019
4466b13
PY3: 2to3 check of control/pdfdataset.py
pavoljuhas Sep 26, 2019
ce15162
PY3: 2to3 check of control/pdfguicontrol.py
pavoljuhas Sep 26, 2019
d7f6d7e
PY3: 2to3 check of control/pdfguimacros.py
pavoljuhas Sep 26, 2019
8474e98
PY3: 2to3 check of control/pdflist.py
pavoljuhas Sep 26, 2019
c365b24
PY3: 2to3 check of control/pdfstructure.py
pavoljuhas Sep 26, 2019
e3f5757
PY3: 2to3 check of control/plotter.py
pavoljuhas Sep 26, 2019
453e9ab
PY3: 2to3 check of control/structureviewer.py
pavoljuhas Sep 26, 2019
a85ccc1
PY3: 2to3 check of gui/bondlengthdialog.py
pavoljuhas Sep 26, 2019
c2c3799
PY3: 2to3 check of gui/debugoptions.py
pavoljuhas Sep 26, 2019
1fd2756
PY3: 2to3 check of gui/dopingseriespanel.py
pavoljuhas Sep 26, 2019
1082ece
PY3: use six.moves.urllib for PY2/PY3 compatibility
pavoljuhas Sep 26, 2019
3b02236
PY3: 2to3 check of gui/errorwrapper.py
pavoljuhas Sep 26, 2019
0c75ae5
PY3: 2to3 check of gui/extendedplotframe.py
pavoljuhas Sep 26, 2019
93f0105
PY3: 2to3 check of gui/fittree.py
pavoljuhas Sep 26, 2019
9d613be
PY3: 2to3 check of gui/mainframe.py
pavoljuhas Sep 26, 2019
41fde5c
PY3: 2to3 check of gui/parameterspanel.py
pavoljuhas Sep 26, 2019
3a9a48a
PY3: 2to3 check of gui/phaseconfigurepanel.py
pavoljuhas Sep 26, 2019
19e4fc7
PY3: 2to3 check of gui/phaseconstraintspanel.py
pavoljuhas Sep 26, 2019
2801e1f
PY3: 2to3 check of gui/phasepanelutils.py
pavoljuhas Sep 26, 2019
ccf2aca
PY3: 2to3 check of gui/phasepanelutils.py
pavoljuhas Sep 26, 2019
e28d327
PY3: 2to3 check of gui/temperatureseriespanel.py
pavoljuhas Sep 26, 2019
8320f88
PY3: 2to3 check of gui/tooltips.py
pavoljuhas Sep 26, 2019
d08c0bc
PY3: 2to3 check of tests/testfitstructure.py
pavoljuhas Sep 26, 2019
2d902b2
PY3: 2to3 check of utils.py
pavoljuhas Sep 26, 2019
8ccf410
MNT: note completion of all 2to3 checks
pavoljuhas Sep 26, 2019
7743cd3
REL: add `six` to run dependencies
pavoljuhas Sep 26, 2019
0fa1444
REL: declare support for Python 3.7, 3.6, 3.5
pavoljuhas Sep 26, 2019
4e4baa9
CI: add travis tests for Python 3.5, 3.6, 3.7
pavoljuhas Sep 26, 2019
822e6c6
BLD: build conda for all supported Python versions
pavoljuhas Sep 26, 2019
c5f5af1
TST: use PY3 compatible imports in testdeps
pavoljuhas Sep 26, 2019
1f6ccb2
MNT: fix invalid escape sequences
pavoljuhas Sep 26, 2019
5dc3242
CI: stop using old conda packages
pavoljuhas Sep 26, 2019
a03d4c5
PY3: replace builtin `file()` --> `open()`
pavoljuhas Sep 26, 2019
41d8b0f
MNT: make sure to close any open files
pavoljuhas Sep 26, 2019
da5c13b
BUG: fix staticmethod in CtrlUnpickler class
pavoljuhas Sep 26, 2019
4d1451a
PY3: adjust QuotedConfigParser for Python 3
pavoljuhas Sep 26, 2019
5dfb4a3
PY3: remove unnecessary conversion to ASCII bytes
pavoljuhas Sep 26, 2019
0ceaaa0
PY3: convert text read from project zip to unicode
pavoljuhas Sep 26, 2019
a5a9f46
MNT: make sure string data are saved as unicode
pavoljuhas Sep 26, 2019
533b6e7
MNT: rename `bytes` variable to non-builtin name
pavoljuhas Sep 26, 2019
87ecea5
MNT: use `utf-8` as a standard encoding name
pavoljuhas Sep 26, 2019
121ea63
PY3: fix crashing `quote_plain`, `unquote_plain`
pavoljuhas Sep 30, 2019
3c92f1e
PY3: add `pickle_loads` with common interface
pavoljuhas Sep 30, 2019
e316562
PY3: unpickle FitDataSet with latin1 encoding
pavoljuhas Sep 30, 2019
a0c745e
ENH: write pickles with protocol 2
pavoljuhas Sep 30, 2019
0f363be
MNT: use safeCPickleDumps for all dumps
pavoljuhas Sep 30, 2019
e47cdd7
ENH: use 'encoding=latin1' default in pickle_loads
pavoljuhas Sep 30, 2019
60c62ef
ENH: replace pickle.loads with pickle_loads
pavoljuhas Sep 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PY3: use fast cPickle module for Python 2
Move all pickle imports to module level, no benefit to keep them local.
  • Loading branch information
pavoljuhas committed Sep 26, 2019
commit 15bbfa67b6b9214b227b4732d40475e72ab739e9
5 changes: 2 additions & 3 deletions src/diffpy/pdfgui/control/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import copy
import math
import types
import six.moves.cPickle as pickle

from diffpy.pdfgui.control.controlerrors import ControlConfigError
from diffpy.pdfgui.control.controlerrors import ControlKeyError
Expand Down Expand Up @@ -248,8 +248,7 @@ def load(self, z, subpath):

returns a tree of internal hierachy
"""
import cPickle
config = cPickle.loads(z.read(subpath + 'config'))
config = pickle.loads(z.read(subpath + 'config'))
self.rmin = config['rmin']
self.rstep = config['rstep']
self.rmax = config['rmax']
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/pdfgui/control/fitdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import copy
import six.moves.cPickle as pickle
import numpy

from diffpy.pdfgui.control.pdfdataset import PDFDataSet
Expand Down Expand Up @@ -455,12 +456,11 @@ def load(self, z, subpath):
self.clear()
subs = subpath.split('/')
rootDict = z.fileTree[subs[0]][subs[1]][subs[2]][subs[3]]
import cPickle
# raw data
self.readObsStr(z.read(subpath+'obs'))

# data from calculation
content = cPickle.loads(z.read(subpath+'calc'))
content = pickle.loads(z.read(subpath+'calc'))
for item in FitDataSet.persistentItems:
# skip items which are not in the project file
if item not in content: continue
Expand Down
6 changes: 3 additions & 3 deletions src/diffpy/pdfgui/control/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import print_function

import six.moves.cPickle as pickle
import threading
import time

Expand Down Expand Up @@ -193,15 +194,14 @@ def load(self, z, subpath):
subs = subpath.split('/')
rootDict = z.fileTree[subs[0]][subs[1]]

import cPickle
if rootDict.has_key('parameters'):
from diffpy.pdfgui.control.pdfguicontrol import CtrlUnpickler
self.parameters = CtrlUnpickler.loads(z.read(subpath+'parameters'))
if rootDict.has_key('steps'):
self.itemIndex, self.dataNameDict, self.snapshots = \
cPickle.loads(z.read(subpath+'steps'))
pickle.loads(z.read(subpath+'steps'))
if rootDict.has_key('result'):
self.rw, self.res = cPickle.loads(z.read(subpath+'result'))
self.rw, self.res = pickle.loads(z.read(subpath+'result'))

return Organizer.load(self, z, subpath)

Expand Down
12 changes: 5 additions & 7 deletions src/diffpy/pdfgui/control/pdfguicontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import threading
import time
import six.moves.cPickle as pickle

from diffpy.pdfgui.control.pdflist import PDFList
from diffpy.pdfgui.control.fitting import Fitting
Expand Down Expand Up @@ -359,7 +360,6 @@ def _nameParser(namelist):
self.projfile = projfile
organizations = []
import zipfile
from cPickle import PickleError
from diffpy.pdfgui.utils import quote_plain

# IOError can be raised when reading invalid zipfile
Expand Down Expand Up @@ -409,7 +409,7 @@ def _nameParser(namelist):
organizations.append(org)
self.add(fit)

except (IOError, zipfile.error, PickleError):
except (IOError, zipfile.error, pickle.PickleError):
raise ControlFileError(emsg_invalid_file)

# close input file if opened
Expand Down Expand Up @@ -437,7 +437,6 @@ def save(self, projfile=None):

import zipfile
import shutil
from cPickle import PickleError
import tempfile
from diffpy.pdfgui.utils import quote_plain

Expand All @@ -463,7 +462,7 @@ def save(self, projfile=None):
z.close()
shutil.copyfile(tmpfilename, self.projfile)

except (IOError, PickleError):
except (IOError, pickle.PickleError):
emsg = "Error when writing to %s" % self.projfile
raise ControlFileError(emsg)

Expand Down Expand Up @@ -568,9 +567,8 @@ class CtrlUnpickler:
pickle.
'''
def loads(s):
import cPickle
try:
return cPickle.loads(s)
return pickle.loads(s)
except ImportError,err:
missedModule = str(err).split(' ')[-1]
if missedModule.find('pdfgui.control') == -1:
Expand All @@ -580,7 +578,7 @@ def loads(s):
except ImportError:
from StringIO import StringIO
f = StringIO(s)
unpickler = cPickle.Unpickler(f)
unpickler = pickle.Unpickler(f)
unpickler.find_global = _find_global
return unpickler.load()
loads = _StaticMethod(loads)
Expand Down
11 changes: 3 additions & 8 deletions src/diffpy/pdfgui/gui/fittree.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import wx
import re
import cPickle
import six.moves.cPickle as pickle

from diffpy.pdfgui.gui.pdfguiglobals import iconpath
from diffpy.pdfgui.control.fitting import Fitting
Expand Down Expand Up @@ -556,7 +556,7 @@ def CopyBranch(self, startnode):
if isinstance(cdata, Fitting):
cdata = cdata.stripped()
cdata.type = nodetype
cdatastring = cPickle.dumps(cdata)
cdatastring = pickle.dumps(cdata)
cdatastring = "pdfgui_cliboard=" + cdatastring
textdata = wx.TextDataObject(cdatastring)
if not wx.TheClipboard.IsOpened():
Expand Down Expand Up @@ -589,14 +589,9 @@ def GetClipboard(self):
if cdatastring[:16] == "pdfgui_cliboard=":
cdatastring = cdatastring[16:]
try:
cdata = cPickle.loads(str(cdatastring))
cdata = pickle.loads(str(cdatastring))
except:
pass

#try:
# cdata = cPickle.loads(str(cdatastring))
#except (cPickle.UnpicklingError, UnicodeEncodeError, EOFError):
# cdata = None
return cdata

def PasteBranch(self, entrypoint = None):
Expand Down
14 changes: 7 additions & 7 deletions src/diffpy/pdfgui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

"""Small shared routines:
numericStringSort -- sort list of strings according to numeric value
safeCPickleDumps -- same as cPickleDumps, but safe for NaN and Inf
safeCPickleDumps -- same as pickle.dumps, but safe for NaN and Inf
"""


from ConfigParser import RawConfigParser
import six.moves.cPickle as pickle


def numericStringSort(lst):
Expand All @@ -41,20 +42,19 @@ def numericStringSort(lst):
return

def safeCPickleDumps(obj):
"""Get cPickle representation of an object possibly containing NaN or Inf.
By default it uses cPickle.HIGHEST_PROTOCOL, but falls back to ASCII
"""Get pickle representation of an object possibly containing NaN or Inf.
By default it uses pickle.HIGHEST_PROTOCOL, but falls back to ASCII
protocol 0 if there is SystemError frexp() exception.

obj -- object to be pickled

Return cPickle string.
Return pickle string.
"""
import cPickle
ascii_protocol = 0
try:
s = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL)
s = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
except SystemError:
s = cPickle.dumps(obj, ascii_protocol)
s = pickle.dumps(obj, ascii_protocol)
return s


Expand Down