1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Fix cardset change and similar pickling problems

see https://github.com/shlomif/PySolFC/issues/41 .
This commit is contained in:
Shlomi Fish 2017-06-23 15:37:44 +03:00
parent b7161a6632
commit 8d9cb53ecc

View file

@ -31,6 +31,7 @@ import traceback
from pysollib.mygettext import _ from pysollib.mygettext import _
from gettext import ungettext from gettext import ungettext
from six import BytesIO
# PySol imports # PySol imports
from pysollib.mfxutil import Pickler, Unpickler, UnpicklingError from pysollib.mfxutil import Pickler, Unpickler, UnpicklingError
@ -61,12 +62,9 @@ from pysollib.hint import DefaultHint
from pysollib.help import help_about from pysollib.help import help_about
if sys.version_info > (3,): if sys.version_info > (3,):
from io import StringIO
basestring = str basestring = str
long = int long = int
xrange = range xrange = range
else:
from cStringIO import StringIO
PLAY_TIME_TIMEOUT = 200 PLAY_TIME_TIMEOUT = 200
@ -614,7 +612,7 @@ class Game(object):
# restore a bookmarked game (e.g. after changing the cardset) # restore a bookmarked game (e.g. after changing the cardset)
def restoreGameFromBookmark(self, bookmark): def restoreGameFromBookmark(self, bookmark):
old_busy, self.busy = self.busy, 1 old_busy, self.busy = self.busy, 1
file = StringIO(bookmark) file = BytesIO(bookmark)
p = Unpickler(file) p = Unpickler(file)
game = self._undumpGame(p, self.app) game = self._undumpGame(p, self.app)
assert game.id == self.id assert game.id == self.id
@ -657,7 +655,7 @@ class Game(object):
self.updateTime() self.updateTime()
if bookmark: if bookmark:
id, random = self.id, self.random id, random = self.id, self.random
file = StringIO() file = BytesIO()
p = Pickler(file, 1) p = Pickler(file, 1)
self._dumpGame(p, bookmark=1) self._dumpGame(p, bookmark=1)
self.app.nextgame.bookmark = file.getvalue() self.app.nextgame.bookmark = file.getvalue()
@ -3019,7 +3017,7 @@ Congratulations, you did it !
_("Set bookmark"), _("Set bookmark"),
_("Replace existing bookmark %d ?") % (n+1)): _("Replace existing bookmark %d ?") % (n+1)):
return 0 return 0
file = StringIO() file = BytesIO()
p = Pickler(file, 1) p = Pickler(file, 1)
try: try:
self._dumpGame(p, bookmark=2) self._dumpGame(p, bookmark=2)
@ -3045,7 +3043,7 @@ Congratulations, you did it !
try: try:
s, moves_index = bm s, moves_index = bm
self.setCursor(cursor=CURSOR_WATCH) self.setCursor(cursor=CURSOR_WATCH)
file = StringIO(s) file = BytesIO(s)
p = Unpickler(file) p = Unpickler(file)
game = self._undumpGame(p, self.app) game = self._undumpGame(p, self.app)
assert game.id == self.id assert game.id == self.id