Skip to content

Commit 3975fd5

Browse files
authored
remove six usage (#187)
1 parent fa5b734 commit 3975fd5

12 files changed

+50
-114
lines changed

Diff for: src/diffpy/pdfgui/control/calculation.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
import copy
2020
import math
21+
import pickle
2122

2223
from diffpy.pdfgui.control.controlerrors import ControlConfigError, ControlKeyError, ControlValueError
2324
from diffpy.pdfgui.control.pdfcomponent import PDFComponent
24-
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps
25+
from diffpy.pdfgui.utils import safeCPickleDumps
2526

2627

2728
class Calculation(PDFComponent):
@@ -253,7 +254,7 @@ def load(self, z, subpath):
253254
254255
returns a tree of internal hierachy
255256
"""
256-
config = pickle_loads(z.read(subpath + "config"))
257+
config = pickle.loads(z.read(subpath + "config"), encoding="latin1")
257258
self.rmin = config["rmin"]
258259
self.rstep = config["rstep"]
259260
self.rmax = config["rmax"]

Diff for: src/diffpy/pdfgui/control/fitdataset.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ def load(self, z, subpath):
461461
z -- zipped project file
462462
subpath -- path to its own storage within project file
463463
"""
464-
from diffpy.pdfgui.utils import asunicode, pickle_loads
464+
import pickle
465+
466+
from diffpy.pdfgui.utils import asunicode
465467

466468
self.clear()
467469
subs = subpath.split("/")
@@ -471,7 +473,7 @@ def load(self, z, subpath):
471473
self.readObsStr(obsdata)
472474

473475
# data from calculation
474-
content = pickle_loads(z.read(subpath + "calc"))
476+
content = pickle.loads(z.read(subpath + "calc"), encoding="latin1")
475477
for item in FitDataSet.persistentItems:
476478
# skip items which are not in the project file
477479
if item not in content:

Diff for: src/diffpy/pdfgui/control/fitting.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
from __future__ import print_function
1717

18+
import pickle
1819
import threading
1920
import time
2021

2122
from diffpy.pdfgui.control.controlerrors import ControlError, ControlStatusError, ControlValueError
2223
from diffpy.pdfgui.control.organizer import Organizer
23-
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps
24+
from diffpy.pdfgui.utils import safeCPickleDumps
2425

2526
# helper routines to deal with PDFfit2 exceptions
2627

@@ -210,9 +211,11 @@ def load(self, z, subpath):
210211

211212
self.parameters = CtrlUnpickler.loads(z.read(subpath + "parameters"))
212213
if "steps" in rootDict:
213-
self.itemIndex, self.dataNameDict, self.snapshots = pickle_loads(z.read(subpath + "steps"))
214+
self.itemIndex, self.dataNameDict, self.snapshots = pickle.loads(
215+
z.read(subpath + "steps"), encoding="latin1"
216+
)
214217
if "result" in rootDict:
215-
self.rw, self.res = pickle_loads(z.read(subpath + "result"))
218+
self.rw, self.res = pickle.loads(z.read(subpath + "result"), encoding="latin1")
216219

217220
return Organizer.load(self, z, subpath)
218221

Diff for: src/diffpy/pdfgui/control/organizer.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,25 @@ def load(self, z, subpath):
160160
returns a tree of internal hierachy
161161
"""
162162
# subpath = projName/myName/
163-
from diffpy.pdfgui.utils import unquote_plain
163+
from urllib.parse import unquote_plus
164164

165165
subs = subpath.split("/")
166166
rootDict = z.fileTree[subs[0]][subs[1]]
167167
if "structure" in rootDict:
168168
for strucName in rootDict["structure"].keys():
169-
struc = FitStructure(unquote_plain(strucName))
169+
struc = FitStructure(unquote_plus(strucName))
170170
struc.load(z, subpath + "structure/" + strucName + "/")
171171
self.add(struc)
172172

173173
if "dataset" in rootDict:
174174
for datasetName in rootDict["dataset"].keys():
175-
dataset = FitDataSet(unquote_plain(datasetName))
175+
dataset = FitDataSet(unquote_plus(datasetName))
176176
dataset.load(z, subpath + "dataset/" + datasetName + "/")
177177
self.add(dataset)
178178

179179
if "calculation" in rootDict:
180180
for calcName in rootDict["calculation"].keys():
181-
calc = Calculation(unquote_plain(calcName))
181+
calc = Calculation(unquote_plus(calcName))
182182
calc.load(z, subpath + "calculation/" + calcName + "/")
183183
self.add(calc)
184184

@@ -193,14 +193,14 @@ def save(self, z, subpath):
193193
subpath -- path to its own storage within project file
194194
"""
195195
# strucs and datasets
196-
from diffpy.pdfgui.utils import quote_plain
196+
from urllib.parse import quote_plus
197197

198198
for struc in self.strucs:
199-
struc.save(z, subpath + "structure/" + quote_plain(struc.name) + "/")
199+
struc.save(z, subpath + "structure/" + quote_plus(struc.name) + "/")
200200
for dataset in self.datasets:
201-
dataset.save(z, subpath + "dataset/" + quote_plain(dataset.name) + "/")
201+
dataset.save(z, subpath + "dataset/" + quote_plus(dataset.name) + "/")
202202
for calc in self.calcs:
203-
calc.save(z, subpath + "calculation/" + quote_plain(calc.name) + "/")
203+
calc.save(z, subpath + "calculation/" + quote_plus(calc.name) + "/")
204204
return
205205

206206
def copy(self, other=None):

Diff for: src/diffpy/pdfgui/control/parameter.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
To be stored in Fitting.parameters { idx : parameter } dictionary
1818
"""
1919

20-
import six
21-
2220
from diffpy.pdfgui.control.controlerrors import (
2321
ControlError,
2422
ControlKeyError,
@@ -79,7 +77,7 @@ def setInitial(self, initial):
7977
if isinstance(initial, Fitting):
8078
self.__initial = "=" + initial.name
8179
self.__fitrepr = repr(initial)
82-
elif isinstance(initial, six.string_types) and initial[:1] == "=":
80+
elif isinstance(initial, str) and initial[:1] == "=":
8381
self.__initial = initial
8482
self.__findLinkedFitting()
8583
else:

Diff for: src/diffpy/pdfgui/control/pdfguicontrol.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
from __future__ import print_function
1717

18+
import io
1819
import os
20+
import pickle
1921
import sys
2022
import threading
2123
import time
22-
23-
import six
24-
import six.moves.cPickle as pickle
24+
from urllib.parse import quote_plus
2525

2626
from diffpy.pdfgui.control.calculation import Calculation
2727
from diffpy.pdfgui.control.controlerrors import ControlError, ControlFileError, ControlTypeError
@@ -30,7 +30,7 @@
3030
from diffpy.pdfgui.control.fitting import Fitting
3131
from diffpy.pdfgui.control.organizer import Organizer
3232
from diffpy.pdfgui.control.pdflist import PDFList
33-
from diffpy.pdfgui.utils import asunicode, quote_plain
33+
from diffpy.pdfgui.utils import asunicode
3434

3535

3636
class PDFGuiControl:
@@ -395,7 +395,7 @@ def _nameParser(namelist):
395395
continue
396396
fit = Fitting(name)
397397
# fitting name stored in rootDict should be quoted
398-
rdname = quote_plain(name)
398+
rdname = quote_plus(name)
399399
# but let's also handle old project files
400400
if rdname not in rootDict:
401401
rdname = name
@@ -450,7 +450,7 @@ def save(self, projfile=None):
450450
# fits also contain calculations
451451
for fit in self.fits:
452452
name = fit.name
453-
fit.save(z, projName + "/" + quote_plain(fit.name) + "/")
453+
fit.save(z, projName + "/" + quote_plus(fit.name) + "/")
454454
fitnames.append(name)
455455
if self.journal:
456456
z.writestr(projName + "/journal", asunicode(self.journal))
@@ -516,7 +516,7 @@ def redirectStdout(self):
516516
from diffpy.pdffit2 import output, redirect_stdout
517517

518518
if output.stdout is sys.stdout:
519-
redirect_stdout(six.StringIO())
519+
redirect_stdout(io.StringIO())
520520
return
521521

522522
def getEngineOutput(self):
@@ -525,7 +525,7 @@ def getEngineOutput(self):
525525

526526
txt = output.stdout.getvalue()
527527
output.stdout.close()
528-
redirect_stdout(six.StringIO())
528+
redirect_stdout(io.StringIO())
529529
return txt
530530

531531

@@ -571,7 +571,7 @@ def loads(s):
571571
missedModule = str(err).split(" ")[-1]
572572
if missedModule.find("pdfgui.control") == -1:
573573
raise err
574-
f = six.StringIO(s)
574+
f = io.StringIO(s)
575575
unpickler = pickle.Unpickler(f)
576576
unpickler.find_global = _find_global
577577
return unpickler.load()

Diff for: src/diffpy/pdfgui/gui/adddatapanel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def readConfiguration(self):
106106

107107
if remember:
108108
if self.cP.has_option("DATASET", "last"):
109-
self.fullpath = self.cP.getquoted("DATASET", "last")
109+
self.fullpath = self.cP.get("DATASET", "last")
110110
import os.path
111111

112112
if not os.path.exists(self.fullpath):
@@ -119,7 +119,7 @@ def updateConfiguration(self):
119119
"""Update the configuration for the 'DATASET'."""
120120
if not self.cP.has_section("DATASET"):
121121
self.cP.add_section("DATASET")
122-
self.cP.setquoted("DATASET", "last", self.fullpath)
122+
self.cP.set("DATASET", "last", self.fullpath)
123123
return
124124

125125
# EVENT CODE ####

Diff for: src/diffpy/pdfgui/gui/addphasepanel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def readConfiguration(self):
128128

129129
if remember:
130130
if self.cP.has_option("PHASE", "last"):
131-
self.fullpath = self.cP.getquoted("PHASE", "last")
131+
self.fullpath = self.cP.get("PHASE", "last")
132132
import os.path
133133

134134
if not os.path.exists(self.fullpath):
@@ -141,7 +141,7 @@ def updateConfiguration(self):
141141
"""Update the configuration for the 'DATASET'."""
142142
if not self.cP.has_section("PHASE"):
143143
self.cP.add_section("PHASE")
144-
self.cP.setquoted("PHASE", "last", self.fullpath)
144+
self.cP.set("PHASE", "last", self.fullpath)
145145
return
146146

147147
# EVENT CODE ####

Diff for: src/diffpy/pdfgui/gui/errorreportdialog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def onGoogle(self, event): # wxGlade: ErrorReportDialog.<event_handler>
151151
Search for path-independent module and function names and for
152152
error message extracted from exception traceback.
153153
"""
154-
from six.moves.urllib.parse import quote_plus
154+
from urllib.parse import quote_plus
155155

156156
traceback = self.text_ctrl_log.GetValue()
157157
terms = _extractSearchTerms(traceback)

Diff for: src/diffpy/pdfgui/gui/fittree.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""
2424

2525
import base64
26+
import pickle
2627
import re
2728

2829
import wx
@@ -31,7 +32,7 @@
3132
from diffpy.pdfgui.control.fitting import Fitting
3233
from diffpy.pdfgui.gui.pdfguiglobals import iconpath
3334
from diffpy.pdfgui.gui.wxextensions import wx12
34-
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps
35+
from diffpy.pdfgui.utils import safeCPickleDumps
3536

3637

3738
class FitTree(wx12.TreeCtrl):
@@ -610,7 +611,7 @@ def GetClipboard(self):
610611

611612
if cdatabytes[:16] == "pdfgui_cliboard=".encode():
612613
cdatabytes = cdatabytes[16:]
613-
cdata = pickle_loads(cdatabytes)
614+
cdata = pickle.loads(cdatabytes, encoding="latin1")
614615
except Exception:
615616
pass
616617
return cdata

Diff for: src/diffpy/pdfgui/gui/mainframe.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""This module contains the main window of PDFgui."""
1919

2020
import os.path
21+
from configparser import ConfigParser
2122

2223
import wx
2324
import wx.aui
@@ -48,7 +49,6 @@
4849
from diffpy.pdfgui.gui.temperatureseriespanel import TemperatureSeriesPanel
4950
from diffpy.pdfgui.gui.welcomepanel import WelcomePanel
5051
from diffpy.pdfgui.gui.wxextensions import wx12
51-
from diffpy.pdfgui.utils import QuotedConfigParser
5252

5353
(PDFCustomEvent, EVT_PDFCUSTOM) = wx.lib.newevent.NewEvent()
5454

@@ -300,9 +300,9 @@ def __customProperties(self):
300300
self.runningDict = {}
301301

302302
# The configuration parser for getting configuration data.
303-
# self.cP = QuotedConfigParser()
303+
# self.cP = Configparser()
304304
# Long try this to avoid DuplicateSectionError and ParsingError
305-
self.cP = QuotedConfigParser(strict=False, allow_no_value=True)
305+
self.cP = ConfigParser(strict=False, allow_no_value=True, interpolation=None)
306306

307307
# Set the program mode
308308
self.mode = "fitting"
@@ -984,7 +984,7 @@ def loadConfiguration(self):
984984
self.cP.read(localpath)
985985
for i in range(pdfguiglobals.MAXMRU, 0, -1):
986986
if self.cP.has_option("MRU", str(i)):
987-
filename = self.cP.getquoted("MRU", str(i))
987+
filename = self.cP.get("MRU", str(i))
988988
if filename:
989989
self.fileHistory.AddFileToHistory(filename)
990990

@@ -1029,7 +1029,7 @@ def updateConfiguration(self):
10291029

10301030
for i in range(self.fileHistory.GetCount()):
10311031
item = self.fileHistory.GetHistoryFile(i)
1032-
self.cP.setquoted("MRU", str(i + 1), item)
1032+
self.cP.set("MRU", str(i + 1), item)
10331033

10341034
# Window size
10351035
if not self.cP.has_section("SIZE"):
@@ -2522,8 +2522,7 @@ def onSaveCalc(self, event):
25222522
def onDocumentation(self, event):
25232523
"""Show information about the documentation."""
25242524
import webbrowser
2525-
2526-
from six.moves.urllib.request import pathname2url
2525+
from urllib.request import pathname2url
25272526

25282527
url = "file://" + pathname2url(docMainFile)
25292528
webbrowser.open(url)

0 commit comments

Comments
 (0)