3 new revisions:
Revision: 0d603be1d484
Branch: default
Author: gbtami
Date: Fri Jan 2 12:02:04 2015 UTC
Log: Random PY3 fixes
https://code.google.com/p/pychess/source/detail?r=0d603be1d484
Revision: 8e172731d959
Branch: default
Author: gbtami
Date: Fri Jan 2 12:38:04 2015 UTC
Log: Another Python3 / fix
https://code.google.com/p/pychess/source/detail?r=8e172731d959
Revision: 705f9bdce58f
Branch: default
Author: gbtami
Date: Fri Jan 2 14:19:13 2015 UTC
Log: Python3 compatible FICS
https://code.google.com/p/pychess/source/detail?r=705f9bdce58f
==============================================================================
Revision: 0d603be1d484
Branch: default
Author: gbtami
Date: Fri Jan 2 12:02:04 2015 UTC
Log: Random PY3 fixes
https://code.google.com/p/pychess/source/detail?r=0d603be1d484
Modified:
/lib/pychess/Savers/pgn.py
/lib/pychess/Savers/pgnbase.py
/lib/pychess/Utils/Board.py
/lib/pychess/Utils/lutils/LBoard.py
=======================================
--- /lib/pychess/Savers/pgn.py Tue Dec 30 18:49:45 2014 UTC
+++ /lib/pychess/Savers/pgn.py Fri Jan 2 12:02:04 2015 UTC
@@ -222,10 +222,10 @@
if node.fen_was_applied:
ply = node.plyCount
if ply % 2 == 1:
- mvcount = "%d." % (ply/2+1)
+ mvcount = "%d." % (ply//2+1)
elif node.prev.prev is None or node != node.prev.next or
black_periods:
# initial game move, or initial variation move
- mvcount = "%d..." % (ply/2)
+ mvcount = "%d..." % (ply//2)
elif node.prev.children:
# move after real(not [%foo bar]) comment
need_mvcount = False
@@ -238,7 +238,7 @@
need_mvcount = True
break
if need_mvcount:
- mvcount = "%d..." % (ply/2)
+ mvcount = "%d..." % (ply//2)
else:
mvcount = ""
else:
=======================================
--- /lib/pychess/Savers/pgnbase.py Wed Dec 31 11:19:08 2014 UTC
+++ /lib/pychess/Savers/pgnbase.py Fri Jan 2 12:02:04 2015 UTC
@@ -95,8 +95,8 @@
notation, reason, boardfen = e.args
ply = last_board.plyCount
if ply % 2 == 0:
- moveno = "%d." % (ply/2+1)
- else: moveno = "%d..." % (ply/2+1)
+ moveno = "%d." % (ply//2+1)
+ else: moveno = "%d..." % (ply//2+1)
errstr1 = _("The game can't be read to end,
because of an error parsing move %(moveno)s '%(notation)s'.") % {
'moveno': moveno, 'notation': notation}
errstr2 = _("The move failed because %s.") % reason
@@ -105,8 +105,8 @@
except:
ply = last_board.plyCount
if ply % 2 == 0:
- moveno = "%d." % (ply/2+1)
- else: moveno = "%d..." % (ply/2+1)
+ moveno = "%d." % (ply//2+1)
+ else: moveno = "%d..." % (ply//2+1)
errstr1 = _( "Error parsing
move %(moveno)s %(mstr)s") % {"moveno": moveno, "mstr": mstr}
self.error = LoadingError (errstr1, "")
break
=======================================
--- /lib/pychess/Utils/Board.py Wed Dec 31 10:05:22 2014 UTC
+++ /lib/pychess/Utils/Board.py Fri Jan 2 12:02:04 2015 UTC
@@ -336,7 +336,7 @@
return self.board.asFen(enable_bfen)
def __repr__ (self):
- return str(self.board)
+ return repr(self.board)
def __getitem__ (self, cord):
return self.data[cord.y].get(cord.x)
=======================================
--- /lib/pychess/Utils/lutils/LBoard.py Tue Dec 30 22:44:51 2014 UTC
+++ /lib/pychess/Utils/lutils/LBoard.py Fri Jan 2 12:02:04 2015 UTC
@@ -1,4 +1,6 @@
from __future__ import absolute_import
+
+from pychess.compat import PY3
from pychess.Utils.const import *
from pychess.Utils.repr import reprColor
from .ldata import *
@@ -711,7 +713,7 @@
else: b += "."
b += " "
b += "\n# "
- return b
+ return b if PY3 else b.encode('utf8')
def asFen (self, enable_bfen=True):
fenstr = []
@@ -774,7 +776,7 @@
fenstr.append(str(self.fifty))
fenstr.append(" ")
- fullmove = (self.plyCount)/2 + 1
+ fullmove = (self.plyCount)//2 + 1
fenstr.append(str(fullmove))
return "".join(fenstr)
==============================================================================
Revision: 8e172731d959
Branch: default
Author: gbtami
Date: Fri Jan 2 12:38:04 2015 UTC
Log: Another Python3 / fix
https://code.google.com/p/pychess/source/detail?r=8e172731d959
Modified:
/lib/pychess/Savers/pgn.py
=======================================
--- /lib/pychess/Savers/pgn.py Fri Jan 2 12:02:04 2015 UTC
+++ /lib/pychess/Savers/pgn.py Fri Jan 2 12:38:04 2015 UTC
@@ -435,7 +435,7 @@
self.has_emt = self.has_emt and "TimeControl" in model.tags
if self.has_emt or self.has_eval:
if self.has_emt:
- blacks = len(model.moves)/2
+ blacks = len(model.moves)//2
whites = len(model.moves)-blacks
model.timemodel.intervals = [
==============================================================================
Revision: 705f9bdce58f
Branch: default
Author: gbtami
Date: Fri Jan 2 14:19:13 2015 UTC
Log: Python3 compatible FICS
https://code.google.com/p/pychess/source/detail?r=705f9bdce58f
Modified:
/lib/pychess/compat.py
/lib/pychess/ic/FICSConnection.py
/lib/pychess/ic/FICSObjects.py
/lib/pychess/ic/ICLounge.py
/lib/pychess/ic/TimeSeal.py
/lib/pychess/ic/VerboseTelnet.py
/lib/pychess/ic/managers/FingerManager.py
/lib/pychess/ic/managers/ListAndVarManager.py
=======================================
--- /lib/pychess/compat.py Wed Dec 31 11:54:58 2014 UTC
+++ /lib/pychess/compat.py Fri Jan 2 14:19:13 2015 UTC
@@ -7,6 +7,7 @@
if PY3:
basestring = str
+ cmp = lambda x, y: (x > y) - (x < y)
memoryview = memoryview
open = open
unichr = chr
@@ -24,6 +25,7 @@
from urllib.parse import urlencode
else:
basestring = basestring
+ cmp = cmp
memoryview = buffer
unicode = unicode
unichr = unichr
=======================================
--- /lib/pychess/ic/FICSConnection.py Tue Dec 30 14:13:27 2014 UTC
+++ /lib/pychess/ic/FICSConnection.py Fri Jan 2 14:19:13 2015 UTC
@@ -1,15 +1,16 @@
from __future__ import absolute_import
from __future__ import print_function
+
import bisect
import re
import socket
import time
import threading
-#from gobject import GObject, SIGNAL_RUN_FIRST
-from gi.repository import GObject
from collections import defaultdict
from threading import Event, Thread
+from gi.repository import GObject
+
import pychess
from pychess.System import fident
from pychess.System.Log import log
@@ -201,7 +202,7 @@
break
self.emit('connectingMsg', _("Setting up environment"))
- lines = self.client.readuntil("ics%")
+ lines = self.client.readuntil(b"ics%")
self._post_connect_hook(lines)
self.FatICS = self.client.FatICS
self.client.name = self.username
=======================================
--- /lib/pychess/ic/FICSObjects.py Wed Dec 31 10:05:22 2014 UTC
+++ /lib/pychess/ic/FICSObjects.py Fri Jan 2 14:19:13 2015 UTC
@@ -333,7 +333,7 @@
elif self.ratings[ratingtype].deviation ==
DEVIATION_PROVISIONAL:
ratingtotal += self.ratings[ratingtype].elo * 1
numratings += 1
- return numratings > 0 and ratingtotal / numratings or 0
+ return numratings > 0 and ratingtotal // numratings or 0
# FIXME: this isn't very accurate because of inflated standard ratings
# and deflated lightning ratings and needs work
=======================================
--- /lib/pychess/ic/ICLounge.py Wed Dec 31 10:05:22 2014 UTC
+++ /lib/pychess/ic/ICLounge.py Fri Jan 2 14:19:13 2015 UTC
@@ -12,7 +12,7 @@
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Pango
from pychess.ic import *
-from pychess.compat import StringIO
+from pychess.compat import cmp, StringIO
from pychess.System import conf, glock, uistuff
from pychess.System.GtkWorker import Publisher
from pychess.System.prefix import addDataPrefix
@@ -1781,14 +1781,14 @@
if self.loading_seek_editor is False and self.chainbox.active and \
difference is not self.lastdifference:
newcenter = rating - self.lastdifference
- self.widgets["ratingCenterSlider"].set_value(newcenter /
RATING_SLIDER_STEP)
+ self.widgets["ratingCenterSlider"].set_value(newcenter //
RATING_SLIDER_STEP)
else:
self.lastdifference = difference
def __clamp (self, rating):
assert isinstance(rating, int)
mod = rating % RATING_SLIDER_STEP
- if mod > RATING_SLIDER_STEP / 2:
+ if mod > RATING_SLIDER_STEP // 2:
return rating - mod + RATING_SLIDER_STEP
else:
return rating - mod
@@ -1879,15 +1879,15 @@
lightning = self.__getRating(TYPE_LIGHTNING)
if standard is not None:
- self.seekEditorWidgetDefaults["ratingCenterSlider"][0] =
standard / RATING_SLIDER_STEP
+ self.seekEditorWidgetDefaults["ratingCenterSlider"][0] =
standard // RATING_SLIDER_STEP
elif blitz is not None:
- self.seekEditorWidgetDefaults["ratingCenterSlider"][0] =
blitz / RATING_SLIDER_STEP
+ self.seekEditorWidgetDefaults["ratingCenterSlider"][0] =
blitz // RATING_SLIDER_STEP
if blitz is not None:
- self.seekEditorWidgetDefaults["ratingCenterSlider"][1] =
blitz / RATING_SLIDER_STEP
+ self.seekEditorWidgetDefaults["ratingCenterSlider"][1] =
blitz // RATING_SLIDER_STEP
if lightning is not None:
- self.seekEditorWidgetDefaults["ratingCenterSlider"][2] =
lightning / RATING_SLIDER_STEP
+ self.seekEditorWidgetDefaults["ratingCenterSlider"][2] =
lightning // RATING_SLIDER_STEP
elif blitz is not None:
- self.seekEditorWidgetDefaults["ratingCenterSlider"][2] =
blitz / RATING_SLIDER_STEP
+ self.seekEditorWidgetDefaults["ratingCenterSlider"][2] =
blitz // RATING_SLIDER_STEP
for i in range(1,4):
self.__loadSeekEditor(i)
=======================================
--- /lib/pychess/ic/TimeSeal.py Tue Dec 30 18:19:14 2014 UTC
+++ /lib/pychess/ic/TimeSeal.py Fri Jan 2 14:19:13 2015 UTC
@@ -1,4 +1,5 @@
from __future__ import print_function
+
import errno
import socket
import telnetlib
@@ -12,8 +13,8 @@
ENCODE = [ord(i) for i in "Timestamp (FICS) v1.0 - programmed by Henrik
Gram."]
ENCODELEN = len(ENCODE)
-G_RESPONSE = '\x029'
-FILLER = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+G_RESPONSE = b'\x029'
+FILLER = b"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
IAC_WONT_ECHO = b''.join([telnetlib.IAC, telnetlib.WONT, telnetlib.ECHO])
class CanceledException (Exception): pass
@@ -27,8 +28,8 @@
self.connected = False
self.canceled = False
self.FatICS = False
- self.buf = ''
- self.writebuf = ''
+ self.buf = bytearray(b"")
+ self.writebuf = bytearray(b"")
self.stateinfo = None
self.sock = None
@@ -48,7 +49,6 @@
if e.errno != errno.EINPROGRESS:
raise
self.sock.settimeout(None)
-
print(self.get_init_string(), file=self)
self.cook_some()
@@ -64,16 +64,16 @@
pass
def encode(self, inbuf, timestamp = None):
- assert inbuf == "" or inbuf[-1] != "\n"
+ assert inbuf == b"" or inbuf[-1] != b"\n"
if not timestamp:
timestamp = int(time.time()*1000 % 1e7)
- enc = inbuf + '\x18%d\x19' % timestamp
+ enc = inbuf + bytearray('\x18%d\x19' % timestamp, "ascii")
padding = 12 - len(enc)%12
filler = random.sample(FILLER, padding)
- enc += "".join(filler)
+ enc += bytearray(filler)
- buf = [ord(i) for i in enc]
+ buf = enc #[ord(i) for i in enc]
for i in range(0, len(buf), 12):
buf[i + 11], buf[i] = buf[i], buf[i + 11]
@@ -85,11 +85,10 @@
for i in range(len(buf)):
buf[i] |= 0x80
j = (i+encode_offset) % ENCODELEN
- buf[i] = chr((buf[i] ^ ENCODE[j]) - 32)
+ buf[i] = (buf[i] ^ ENCODE[j]) - 32
- buf.append( chr(0x80 | encode_offset))
-
- return ''.join(buf)
+ buf += bytearray([ 0x80 | encode_offset])
+ return buf
def get_init_string(self):
""" timeseal header: TIMESTAMP|bruce|Linux gruber 2.6.15-gentoo-r1
#9
@@ -97,10 +96,10 @@
2.00GHz GenuineIntel GNU/Linux| 93049 """
user = getpass.getuser()
uname = ' '.join(list(platform.uname()))
- return "TIMESTAMP|%(user)s|%(uname)s|" % locals()
+ return "TIMESTAMP|" + user + "|" + uname + "|"
def decode(self, buf, stateinfo = None):
- expected_table = "[G]\n\r"
+ expected_table = b"[G]\n\r"
# TODO: add support to FatICS's new zipseal protocol when it
finalizes
#expected_table = "[G]\n\r" if not self.FatICS else "[G]\r\n"
final_state = len(expected_table)
@@ -134,26 +133,26 @@
lookahead = []
state = 0
- return ''.join(result), g_count, (state, lookahead)
+ return bytearray(result), g_count, (state, lookahead)
def write(self, str):
- self.writebuf += str
- if "\n" not in self.writebuf:
+ self.writebuf += bytearray(str, "utf-8")
+ if b"\n" not in self.writebuf:
return
if not self.connected:
return
- i = self.writebuf.rfind("\n")
+ i = self.writebuf.rfind(b"\n")
str = self.writebuf[:i]
self.writebuf = self.writebuf[i+1:]
logstr = "*"*len(str) if self.sensitive else str
log.info(logstr, extra={"task": (
self.name, "raw")})
str = self.encode(str)
- self.sock.send(str+"\n")
+ self.sock.send(str+b"\n")
def readline(self):
- return self.readuntil("\n")
+ return self.readuntil(b"\n")
def readuntil(self, until):
if self.canceled:
@@ -164,7 +163,7 @@
if i >= 0:
stuff = self.buf[:i+len(until)]
self.buf = self.buf[i+len(until):]
- return stuff
+ return str(stuff.strip().decode("latin_1"))
self.cook_some()
def cook_some (self):
@@ -177,13 +176,13 @@
self.buf += recv
self.connected = True
- if "FatICS" in self.buf:
+ if b"FatICS" in self.buf:
self.FatICS = True
- elif "Starting FICS session" in self.buf:
+ elif b"Starting FICS session" in self.buf:
self.buf = self.buf.replace(IAC_WONT_ECHO, '')
else:
recv, g_count, self.stateinfo = self.decode(recv,
self.stateinfo)
- recv = recv.replace("\r","")
+ recv = recv.replace(b"\r", b"")
log.debug(recv, extra={"task": (
self.name, "raw")})
for i in range(g_count):
@@ -197,7 +196,7 @@
while True:
for i, until in enumerate(untils):
- start = self.buf.find(until)
+ start = self.buf.find(bytearray(until, "ascii"))
if start >= 0:
self.buf = self.buf[:start]
return i
=======================================
--- /lib/pychess/ic/VerboseTelnet.py Wed Dec 31 10:05:22 2014 UTC
+++ /lib/pychess/ic/VerboseTelnet.py Fri Jan 2 14:19:13 2015 UTC
@@ -30,11 +30,17 @@
def __hash__ (self):
return self.hash
-
+
+ # This used in PY2 only
def __cmp__ (self, other):
return self.callback == other.callback and \
self.regexps == other.regexps
+ # Needed in PY3
+ def __lt__ (self, other):
+ return len(self.regexps) < len(other.regexps)
+
+
RETURN_NO_MATCH, RETURN_MATCH, RETURN_NEED_MORE, RETURN_MATCH_END =
range(4)
@@ -158,7 +164,7 @@
def _get_lines (self):
lines = []
- line = self.telnet.readline().strip()
+ line = self.telnet.readline()
if line.startswith(self.line_prefix):
line = line[len(self.line_prefix)+1:]
@@ -174,11 +180,11 @@
extra={"task": (
self.telnet.name, "lines")})
return lines
code = int(code)
- line = text if text else self.telnet.readline().strip()
+ line = text if text else self.telnet.readline()
while not line.endswith(BLOCK_END):
lines.append(TelnetLine(line, code))
- line = self.telnet.readline().strip()
+ line = self.telnet.readline()
lines.append(TelnetLine(line[:-1], code))
log.debug("%s %s %s" %
@@ -186,7 +192,7 @@
extra={"task": (
self.telnet.name, "command_reply")})
else:
lines.append(TelnetLine(line, None))
-
+
log.debug("\n".join(line.line for line in lines).strip(),
extra={"task": (
self.telnet.name, "lines")})
if self.consolehandler:
=======================================
--- /lib/pychess/ic/managers/FingerManager.py Thu Sep 4 17:04:27 2014 UTC
+++ /lib/pychess/ic/managers/FingerManager.py Fri Jan 2 14:19:13 2015 UTC
@@ -305,7 +305,7 @@
rating = Rating(gametype.rating_type, *args)
else:
bestTime = self.parseShortDate(ratings[6][1:-1])
- args = map(int,ratings[:6]) + [bestTime]
+ args = list(map(int,ratings[:6])) + [bestTime]
rating = Rating(gametype.rating_type, *args)
finger.setRating(gametype.rating_type, rating)
elif groupdict["email"] != None:
=======================================
--- /lib/pychess/ic/managers/ListAndVarManager.py Tue Dec 30 16:36:34 2014
UTC
+++ /lib/pychess/ic/managers/ListAndVarManager.py Fri Jan 2 14:19:13 2015
UTC
@@ -2,9 +2,13 @@
from threading import Semaphore
+from pychess.compat import PY2
from pychess.ic import BLKCMD_SHOWLIST, BLKCMD_VARIABLES, BLKCMD_IVARIABLES
from pychess.System import conf
+def semaphore_value(s):
+ return s._Semaphore__value if PY2 else s._value
+
class ListAndVarManager:
def __init__ (self, connection):
@@ -54,9 +58,9 @@
def isReady (self):
# FatICS showlist output is not well formed yet
if self.connection.FatICS:
- return self.varLock._Semaphore__value
+ return semaphore_value(self.varLock)
else:
- return self.listLock._Semaphore__value and
self.varLock._Semaphore__value
+ return semaphore_value(self.listLock) and
semaphore_value(self.varLock)
def stop (self):
if not self.isReady():
@@ -101,7 +105,7 @@
if not listName in self.personalBackup:
self.personalBackup[listName] = set()
# Unlock if people are waiting of the backup
- if not self.listLock._Semaphore__value and \
+ if not semaphore_value(self.listLock) and \
len(self.personalLists) == len(self.personalBackup):
self.listLock.release()
onUpdateEmptyListitems.BLKCMD = BLKCMD_SHOWLIST
@@ -117,7 +121,7 @@
self.personalLists[listName] = items
self.personalBackup[listName] = items
# Unlock if people are waiting of the backup
- if not self.listLock._Semaphore__value and \
+ if not semaphore_value(self.listLock) and \
len(self.personalLists) == len(self.personalBackup):
self.listLock.release()
onUpdateListitems.BLKCMD = BLKCMD_SHOWLIST
@@ -144,7 +148,7 @@
self.variablesBackup[k] = v
# Unlock if people are waiting of the backup and we've got the
normal
# variable backup set. The interface variables automatically reset
- if not self.varLock._Semaphore__value and self.variablesBackup:
+ if not semaphore_value(self.varLock) and self.variablesBackup:
self.varLock.release()
onVariables.BLKCMD = BLKCMD_VARIABLES