Skip to content

Commit aa2841d

Browse files
Daniel NunesInfernio
authored andcommitted
Prepare moved stdlib modules for py3
This was just a simple rename with 'as' for moved stdlib modules in py3 to make it easier to port - all code changes are already done, all that's needed to fix is the import. ConfigParser was not changed because all that's needed is already the import itself, 2to3 can easily take care of that.
1 parent 30f16d7 commit aa2841d

10 files changed

Lines changed: 47 additions & 45 deletions

File tree

Mopy/bash/balt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from .exception import AbstractError, AccessDeniedError, ArgumentError, \
3535
BoltError, CancelError, SkipError, StateError
3636
#--Python
37-
import cPickle
37+
import cPickle as pickle # PY3
3838
import textwrap
3939
import time
4040
import threading
@@ -1331,7 +1331,7 @@ def OnData(self, x, y, data):
13311331
self.window.OnDropFiles(x, y, self.dataFile.GetFilenames())
13321332
elif dtype == self.dataList.GetFormat().GetType():
13331333
# ListCtrl indexes
1334-
data = cPickle.loads(self.dataList.GetData())
1334+
data = pickle.loads(self.dataList.GetData())
13351335
self.window._OnDropList(x, y, data)
13361336

13371337
def OnDragOver(self, x, y, dragResult):
@@ -1399,7 +1399,7 @@ def OnBeginDrag(self, event):
13991399
stop = index - 1
14001400
if stop < 0: stop = self.GetItemCount()
14011401

1402-
selected = cPickle.dumps(indexes, 1)
1402+
selected = pickle.dumps(indexes, 1)
14031403
ldata = wx.CustomDataObject('ListIndexes')
14041404
ldata.SetData(selected)
14051405

Mopy/bash/barb.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
the backup
3838
"""
3939

40-
import cPickle
40+
import cPickle as pickle # PY3
4141
import os
4242
from os.path import join as jo
4343

@@ -168,10 +168,10 @@ def _backup_settings(self, temp_dir):
168168
with temp_dir.join(u'backup.dat').open('wb') as out:
169169
# Bash version the settings were saved with, if this is newer
170170
# than the installed settings version, do not allow restore
171-
cPickle.dump(bass.settings['bash.version'], out, -1)
171+
pickle.dump(bass.settings['bash.version'], out, -1)
172172
# app version, if this doesn't match the installed settings
173173
# version, warn the user on restore
174-
cPickle.dump(AppVersion, out, -1)
174+
pickle.dump(AppVersion, out, -1)
175175
# create the backup archive in 7z format WITH solid compression
176176
# may raise StateError
177177
backup_dir, dest7z = self._backup_dest_file.head, self._backup_dest_file.tail
@@ -332,10 +332,10 @@ def _get_settings_versions(self):
332332
try:
333333
with backup_dat.open('rb') as ins:
334334
# version of Bash that created the backed up settings
335-
self._saved_settings_version = cPickle.load(ins)
335+
self._saved_settings_version = pickle.load(ins)
336336
# version of Bash that created the backup
337-
self._settings_saved_with = cPickle.load(ins)
338-
except (OSError, IOError, cPickle.UnpicklingError, EOFError):
337+
self._settings_saved_with = pickle.load(ins)
338+
except (OSError, IOError, pickle.UnpicklingError, EOFError):
339339
raise_bolt_error(u'Failed to read %s' % backup_dat)
340340
return self._saved_settings_version, self._settings_saved_with
341341

Mopy/bash/bash.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,16 @@ def __init__(self, msg):
475475
print u' An error occurred while displaying the second error.'
476476

477477
def _tkinter_error_dial(msg, but_kwargs):
478-
import Tkinter
479-
root_widget = Tkinter.Tk()
480-
frame = Tkinter.Frame(root_widget)
478+
import Tkinter as tkinter # PY3
479+
root_widget = tkinter.Tk()
480+
frame = tkinter.Frame(root_widget)
481481
frame.pack()
482-
button = Tkinter.Button(frame, command=root_widget.destroy, pady=15,
483-
borderwidth=5, relief=Tkinter.GROOVE, **but_kwargs)
484-
button.pack(fill=Tkinter.BOTH, expand=1, side=Tkinter.BOTTOM)
485-
w = Tkinter.Text(frame)
486-
w.insert(Tkinter.END, msg)
487-
w.config(state=Tkinter.DISABLED)
482+
button = tkinter.Button(frame, command=root_widget.destroy, pady=15,
483+
borderwidth=5, relief=tkinter.GROOVE, **but_kwargs)
484+
button.pack(fill=tkinter.BOTH, expand=1, side=tkinter.BOTTOM)
485+
w = tkinter.Text(frame)
486+
w.insert(tkinter.END, msg)
487+
w.config(state=tkinter.DISABLED)
488488
w.pack()
489489
root_widget.mainloop()
490490

Mopy/bash/basher/app_buttons.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,9 @@ def _update_pkl(fileName=None):
698698
based either on a list of new eids or the gmsts in the specified mod
699699
file. Updated pkl file is dropped in Mopy directory."""
700700
#--Data base
701-
import cPickle
701+
import cPickle as pickle # PY3
702702
try:
703-
fids = cPickle.load(GPath(bush.game.pklfile).open('r'))['GMST']
703+
fids = pickle.load(GPath(bush.game.pklfile).open('r'))['GMST']
704704
if fids:
705705
maxId = max(fids.values())
706706
else:
@@ -735,7 +735,7 @@ def _update_pkl(fileName=None):
735735
#--Changes?
736736
if maxId > maxOld:
737737
outData = {'GMST': fids}
738-
cPickle.dump(outData, GPath(bush.game.pklfile).open('w'))
738+
pickle.dump(outData, GPath(bush.game.pklfile).open('w'))
739739
print _(u"%d new gmst ids written to " + bush.game.pklfile) % (
740740
(maxId - maxOld),)
741741
else:

Mopy/bash/bolt.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#--Standard
2727
from __future__ import division
2828
import StringIO
29-
import cPickle
29+
import cPickle as pickle # PY3
3030
import chardet
3131
import codecs
3232
import collections
@@ -38,6 +38,7 @@
3838
import re
3939
import shutil
4040
import stat
41+
import string
4142
import struct
4243
import subprocess
4344
import sys
@@ -50,6 +51,12 @@
5051
# Internal
5152
from . import exception
5253

54+
# PY3
55+
try:
56+
from urllib.parse import quote
57+
except ImportError:
58+
from urllib import quote
59+
5360
# structure aliases, mainly introduced to reduce uses of 'pack' and 'unpack'
5461
struct_pack = struct.pack
5562
struct_unpack = struct.unpack
@@ -1364,7 +1371,7 @@ def load(self):
13641371
try:
13651372
with path.open('rb') as ins:
13661373
try:
1367-
firstPickle = cPickle.load(ins)
1374+
firstPickle = pickle.load(ins)
13681375
except ValueError:
13691376
cor = path
13701377
cor_name = GPath(path.s + u' (%s)' % timestamp() +
@@ -1373,8 +1380,8 @@ def load(self):
13731380
path, cor_name.tail), traceback=True)
13741381
continue # file corrupt - try next file
13751382
if firstPickle == 'VDATA2':
1376-
self.vdata.update(cPickle.load(ins))
1377-
self.data.update(cPickle.load(ins))
1383+
self.vdata.update(pickle.load(ins))
1384+
self.data.update(pickle.load(ins))
13781385
else:
13791386
raise PickleDict.Mold(path)
13801387
return 1 + (path == self.backup)
@@ -1394,7 +1401,7 @@ def save(self):
13941401
self.vdata['boltPaths'] = True # needed so pre 307 versions don't blow
13951402
with self.path.temp.open('wb') as out:
13961403
for data in ('VDATA2',self.vdata,self.data):
1397-
cPickle.dump(data,out,-1)
1404+
pickle.dump(data,out,-1)
13981405
self.path.untemp(doBackup=True)
13991406
return True
14001407

@@ -2068,7 +2075,6 @@ class WryeText(object):
20682075
@staticmethod
20692076
def genHtml(ins,out=None,*cssDirs):
20702077
"""Reads a wtxt input stream and writes an html output stream."""
2071-
import string, urllib
20722078
# Path or Stream? -----------------------------------------------
20732079
if isinstance(ins,(Path,str,unicode)):
20742080
srcPath = GPath(ins)
@@ -2116,7 +2122,7 @@ def subAnchor(match):
21162122
# urllib will automatically take any unicode characters and escape them, so to
21172123
# convert back to unicode for purposes of storing the string, everything will
21182124
# be in cp1252, due to the escapings.
2119-
anchor = unicode(urllib.quote(reWd.sub(u'',text).encode('utf8')),'cp1252')
2125+
anchor = unicode(quote(reWd.sub(u'',text).encode('utf8')),'cp1252')
21202126
count = 0
21212127
if re.match(u'' r'\d', anchor):
21222128
anchor = u'_' + anchor
@@ -2160,7 +2166,7 @@ def subLink(match):
21602166
address = text = match.group(1).strip()
21612167
if u'|' in text:
21622168
(address,text) = [chunk.strip() for chunk in text.split(u'|',1)]
2163-
if address == u'#': address += unicode(urllib.quote(reWd.sub(u'',text).encode('utf8')),'cp1252')
2169+
if address == u'#': address += unicode(quote(reWd.sub(u'',text).encode('utf8')),'cp1252')
21642170
if address.startswith(u'!'):
21652171
newWindow = u' target="_blank"'
21662172
if address == text:
@@ -2281,7 +2287,7 @@ def subLink(match):
22812287
elif maHead:
22822288
lead,text = maHead.group(1,2)
22832289
text = re.sub(u' *=*#?$','',text.strip())
2284-
anchor = unicode(urllib.quote(reWd.sub(u'',text).encode('utf8')),'cp1252')
2290+
anchor = unicode(quote(reWd.sub(u'',text).encode('utf8')),'cp1252')
22852291
level = len(lead)
22862292
if anchorHeaders:
22872293
if re.match(u'' r'\d', anchor):

Mopy/bash/bosh/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Imports ---------------------------------------------------------------------
3030
#--Python
31-
import cPickle
31+
import cPickle as pickle # PY3
3232
import collections
3333
import errno
3434
import os
@@ -3292,7 +3292,7 @@ def _loadBakOrEmpty(delBackup=False, ignoreBackup=False):
32923292
#--Set bass.settings ------------------------------------------------------
32933293
try:
32943294
bass.settings = _load()
3295-
except cPickle.UnpicklingError as err:
3295+
except pickle.UnpicklingError as err:
32963296
msg = _(
32973297
u"Error reading the Bash Settings database (the error is: '%s'). "
32983298
u"This is probably not recoverable with the current file. Do you "
@@ -3302,7 +3302,7 @@ def _loadBakOrEmpty(delBackup=False, ignoreBackup=False):
33023302
if usebck:
33033303
try:
33043304
bass.settings = _loadBakOrEmpty()
3305-
except cPickle.UnpicklingError as err:
3305+
except pickle.UnpicklingError as err:
33063306
msg = _(
33073307
u"Error reading the BackupBash Settings database (the "
33083308
u"error is: '%s'). This is probably not recoverable with "

Mopy/bash/bosh/converters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""BAIN Converters aka BCFs"""
2525

2626
from __future__ import division
27-
import cPickle
27+
import cPickle as pickle # PY3
2828
import re
2929
import sys
3030

@@ -300,9 +300,9 @@ def _translate(s):
300300
return re.sub(u'^(bolt|bosh)$', u'' r'bash.\1', s,
301301
flags=re.U)
302302
translator = _Translator(stream)
303-
map(self.__setattr__, self.persistBCF, cPickle.load(translator))
303+
map(self.__setattr__, self.persistBCF, pickle.load(translator))
304304
if fullLoad:
305-
map(self.__setattr__, self._converter_settings + self.volatile + self.addedSettings, cPickle.load(translator))
305+
map(self.__setattr__, self._converter_settings + self.volatile + self.addedSettings, pickle.load(translator))
306306
with self.fullPath.unicodeSafe() as converter_path:
307307
# Temp rename if its name wont encode correctly
308308
command = u'"%s" x "%s" BCF.dat -y -so -sccUTF-8' % (
@@ -313,7 +313,7 @@ def _translate(s):
313313
def save(self, destInstaller):
314314
#--Dump settings into BCF.dat
315315
def _dump(att, dat):
316-
cPickle.dump(tuple(map(self.__getattribute__, att)), dat, -1)
316+
pickle.dump(tuple(map(self.__getattribute__, att)), dat, -1)
317317
try:
318318
with bass.getTempDir().join(u'BCF.dat').open('wb') as f:
319319
_dump(self.persistBCF, f)

Mopy/bash/brec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""This module contains all of the basic types used to read ESP/ESM mod files.
2626
"""
2727
from __future__ import division
28-
import cPickle
28+
import cPickle as pickle # PY3
2929
import copy
3030
import os
3131
import re
@@ -2668,7 +2668,7 @@ def getGMSTFid(self):
26682668
fname = bush.game.pklfile
26692669
try:
26702670
with open(fname) as pkl_file:
2671-
cls.Ids = cPickle.load(pkl_file)[cls.classType]
2671+
cls.Ids = pickle.load(pkl_file)[cls.classType]
26722672
except:
26732673
old = bolt.deprintOn
26742674
bolt.deprintOn = True

Mopy/bash/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
DirectoryFileCollisionError, FileOperationError, NonExistentDriveError
3939

4040
try:
41-
import _winreg as winreg
41+
import _winreg as winreg # PY3
4242
except ImportError: # we're on linux
4343
winreg = None
4444
try:

scripts/build.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@
4646
import sys
4747
import tempfile
4848
import zipfile
49+
import _winreg as winreg # PY3
4950
from contextlib import contextmanager
5051
from distutils.dir_util import copy_tree
5152

5253
import pygit2
5354

5455
import utils
5556

56-
# PY3: should be 'import winreg'
57-
try:
58-
import winreg
59-
except ImportError:
60-
import _winreg as winreg
6157

6258
LOGGER = logging.getLogger(__name__)
6359

0 commit comments

Comments
 (0)