Skip to content

Commit

Permalink
trim usage of six
Browse files Browse the repository at this point in the history
This is artisanal manual craftwork :-)

     def mDone(self, button):
         if button == 0:        # "OK" or double click
-            if isinstance(self.tree.selection_key, six.string_types):
-                self.key = str(self.tree.selection_key)
-            else:
-                self.key = self.tree.selection_key
+            self.key = self.tree.selection_key
  • Loading branch information
a-detiste committed Sep 18, 2024
1 parent 1149d4f commit 70ec622
Show file tree
Hide file tree
Showing 27 changed files with 47 additions and 94 deletions.
4 changes: 1 addition & 3 deletions pysollib/customgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
UNLIMITED_MOVES
from pysollib.wizardutil import WizardWidgets

import six

# ************************************************************************
# *
# ************************************************************************
Expand All @@ -80,7 +78,7 @@
def get_settings(ss):
s = {}
for w in WizardWidgets:
if isinstance(w, six.string_types):
if isinstance(w, str):
continue
if w.var_name in ss:
v = ss[w.var_name]
Expand Down
13 changes: 5 additions & 8 deletions pysollib/game/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import random
import time
import traceback
from io import BytesIO
from pickle import Pickler, Unpickler, UnpicklingError

import attr
Expand Down Expand Up @@ -68,10 +69,6 @@
from pysollib.settings import VERSION, VERSION_TUPLE
from pysollib.struct_new import NewStruct

import six
from six import BytesIO
from six.moves import range

if TOOLKIT == 'tk':
from pysollib.ui.tktile.solverdialog import reset_solver_dialog
else:
Expand Down Expand Up @@ -104,7 +101,7 @@ def _updateStatus_process_key_val(tb, sb, k, v):
# self.top.wm_title("%s - %s"
# % (TITLE, self.getTitleName()))
return
if isinstance(v, six.string_types):
if isinstance(v, str):
if sb:
sb.updateText(gamenumber=v)
# self.top.wm_title("%s - %s %s" % (TITLE,
Expand Down Expand Up @@ -146,7 +143,7 @@ def _updateStatus_process_key_val(tb, sb, k, v):
if tb:
tb.updateText(player=_("Player\n"))
return
if isinstance(v, six.string_types):
if isinstance(v, str):
if tb:
# if self.app.opt.toolbar_size:
if tb.getSize():
Expand All @@ -168,7 +165,7 @@ def _updateStatus_process_key_val(tb, sb, k, v):
if v is None:
if sb:
sb.updateText(time='')
if isinstance(v, six.string_types):
if isinstance(v, str):
if sb:
sb.updateText(time=v)
return
Expand Down Expand Up @@ -1341,7 +1338,7 @@ def updateStatus(self, **kw):
if self.preview:
return
tb, sb = self.app.toolbar, self.app.statusbar
for k, v in six.iteritems(kw):
for k, v in kw.items():
_updateStatus_process_key_val(tb, sb, k, v)

def _unmapHandler(self, event):
Expand Down
2 changes: 0 additions & 2 deletions pysollib/games/mahjongg/mahjongg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
OpenStack
from pysollib.util import ANY_SUIT, NO_RANK

from six.moves import range


def factorial(x):
if x <= 1:
Expand Down
2 changes: 0 additions & 2 deletions pysollib/games/mahjongg/shisensho.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
InitialDealTalonStack
from pysollib.util import ANY_SUIT

from six.moves import range


class Shisen_Hint(AbstractHint):
TOP_MATCHING = False
Expand Down
2 changes: 0 additions & 2 deletions pysollib/games/special/samegame.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
OpenStack
from pysollib.util import ANY_SUIT

from six.moves import range


# ************************************************************************
# * Samegame
Expand Down
14 changes: 6 additions & 8 deletions pysollib/hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
from pysollib.settings import DEBUG, FCS_COMMAND
from pysollib.util import KING

import six

FCS_VERSION = None

# ************************************************************************
Expand Down Expand Up @@ -819,7 +817,7 @@ def run_solver(self, command, board):
if os.name != 'nt':
kw['close_fds'] = True
p = subprocess.Popen(command, **kw)
bytes_board = six.binary_type(board, 'utf-8')
bytes_board = bytes(board, 'utf-8')
pout, perr = p.communicate(bytes_board)
if p.returncode in (127, 1):
# Linux and Windows return codes for "command not found" error
Expand Down Expand Up @@ -1018,7 +1016,7 @@ def computeHints(self):
FCS_VERSION = (5, 0, 0)
else:
pout, _ = self.run_solver(FCS_COMMAND + ' --version', '')
s = six.text_type(pout.read(), encoding='utf-8')
s = str(pout.read(), encoding='utf-8')
m = re.search(r'version ([0-9]+)\.([0-9]+)\.([0-9]+)', s)
if m:
FCS_VERSION = (int(m.group(1)), int(m.group(2)),
Expand Down Expand Up @@ -1082,7 +1080,7 @@ def computeHints(self):
states = 0

for sbytes in pout:
s = six.text_type(sbytes, encoding='utf-8')
s = str(sbytes, encoding='utf-8')
if DEBUG >= 5:
print(s)

Expand Down Expand Up @@ -1127,7 +1125,7 @@ def computeHints(self):
self.solver_state = 'unsolved'
else:
for sbytes in pout:
s = six.text_type(sbytes, encoding='utf-8')
s = str(sbytes, encoding='utf-8')
if DEBUG:
print(s)
if self._determineIfSolverState(s):
Expand Down Expand Up @@ -1356,7 +1354,7 @@ def computeHints(self):
pout, perr = self.run_solver(command, board)

for sbytes in pout:
s = six.text_type(sbytes, encoding='utf-8')
s = str(sbytes, encoding='utf-8')
if DEBUG >= 5:
print(s)

Expand Down Expand Up @@ -1390,7 +1388,7 @@ def computeHints(self):
else:
self.solver_state = result.lower()
for sbytes in pout:
s = six.text_type(sbytes, encoding='utf-8')
s = str(sbytes, encoding='utf-8')
if DEBUG:
print(s)

Expand Down
4 changes: 2 additions & 2 deletions pysollib/kivy/selectgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#
# ---------------------------------------------------------------------------#

from collections import UserList

from kivy.clock import Clock

from pysollib.gamedb import GI
Expand All @@ -33,8 +35,6 @@
from pysollib.kivy.selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode
from pysollib.mygettext import _

from six.moves import UserList


# ************************************************************************
# * Nodes
Expand Down
9 changes: 3 additions & 6 deletions pysollib/mfxutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

from pysollib.settings import PACKAGE, TOOLKIT

import six
from six import print_

Image = ImageTk = ImageOps = ImageDraw = None
if TOOLKIT == 'tk':
try: # PIL
Expand Down Expand Up @@ -125,9 +122,9 @@ def print_err(s, level=1):
elif level == 2:
ss = PACKAGE+': DEBUG WARNING:'
try:
print_(ss, s, file=sys.stderr)
print(ss, s, file=sys.stderr)
except Exception:
print_(ss, s.encode(locale.getpreferredencoding()), file=sys.stderr)
print(ss, s.encode(locale.getpreferredencoding()), file=sys.stderr)
sys.stderr.flush()


Expand Down Expand Up @@ -184,7 +181,7 @@ def getprefdir(package):
def win32_getusername():
user = os.environ.get('USERNAME', '').strip()
try:
user = six.text_type(user, locale.getpreferredencoding())
user = str(user, locale.getpreferredencoding())
except Exception:
user = ''
return user
Expand Down
8 changes: 3 additions & 5 deletions pysollib/mygettext.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import gettext
import sys

import six


class myLocalGettext(object):
class myLocalGettext:
def __init__(self, lang):
self.language = lang

Expand All @@ -19,8 +17,8 @@ def translation(self):
return t

def maketext(self, msg):
if not isinstance(msg, six.text_type):
return six.text_type(msg, 'utf-8')
if not isinstance(msg, str):
return str(msg, 'utf-8')
return msg

def ungettext(self, msgid1, msgid2, n):
Expand Down
5 changes: 1 addition & 4 deletions pysollib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
from pysollib.pysoltk import STATUSBAR_ITEMS, TOOLBAR_BUTTONS, TOOLKIT
from pysollib.resource import CSI


import six

import validate

# ************************************************************************
Expand Down Expand Up @@ -663,7 +660,7 @@ def save(self, filename):
val = getattr(self, key)
if isinstance(val, str):
if sys.version_info < (3,):
val = six.text_type(val, 'utf-8')
val = str(val, 'utf-8')
config['general'][key] = val

config['general']['recent_gameid'] = self.recent_gameid
Expand Down
6 changes: 2 additions & 4 deletions pysollib/pysolgtk/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

from pysollib.mygettext import _

import six


class BasicStatusbar:
def __init__(self, top, row, column, columnspan):
Expand Down Expand Up @@ -60,7 +58,7 @@ def updateText(self, **kw):
for k, v in kw.items():
label = getattr(self, k + "_label")
label.pop(0)
label.push(0, six.text_type(v))
label.push(0, str(v))

def config(self, name, show):
# FIXME
Expand All @@ -70,7 +68,7 @@ def configLabel(self, name, **kw):
label = getattr(self, name + "_label")
# FIXME kw['fg']
label.pop(0)
label.push(0, six.text_type(kw['text']))
label.push(0, str(kw['text']))

def show(self, show=True, resize=False):
if show:
Expand Down
4 changes: 1 addition & 3 deletions pysollib/pysolgtk/tkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from pysollib.mygettext import _
from pysollib.settings import TITLE

import six

from tkwidget import MfxMessageDialog

if __name__ == '__main__':
Expand Down Expand Up @@ -71,7 +69,7 @@ def __init__(self, text, viewer, app):
self.indent = ''

def write(self, data):
data = six.text_type(data)
data = str(data)
self.text.insert(self.text.get_end_iter(), data, len(data))

def anchor_bgn(self, href, name, type):
Expand Down
4 changes: 1 addition & 3 deletions pysollib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
from pysollib.mygettext import _
from pysollib.settings import DEBUG

import six

# ************************************************************************
# * Abstract
# ************************************************************************
Expand Down Expand Up @@ -477,7 +475,7 @@ def getPreviewCardNames(self):

def updateCardback(self, backname=None, backindex=None):
# update default back
if isinstance(backname, six.string_types):
if isinstance(backname, str):
if backname in self.backnames:
backindex = self.backnames.index(backname)
if isinstance(backindex, int):
Expand Down
2 changes: 0 additions & 2 deletions pysollib/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from pysollib.mfxutil import format_time
from pysollib.mygettext import _

from six.moves import range

# ************************************************************************
# *
# ************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion pysollib/tile/selectgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# ---------------------------------------------------------------------------

import os
from collections import UserList

from pysollib.gamedb import GI
from pysollib.mfxutil import KwStruct, Struct, destruct
Expand All @@ -31,7 +32,6 @@
from pysollib.ui.tktile.selecttree import SelectDialogTreeData
from pysollib.ui.tktile.tkutil import bind, unbind_destroy

from six.moves import UserList
from six.moves import tkinter
from six.moves import tkinter_ttk as ttk

Expand Down
5 changes: 2 additions & 3 deletions pysollib/tile/selecttile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from pysollib.ui.tktile.selecttree import SelectDialogTreeData
from pysollib.ui.tktile.tkutil import bind

import six
from six.moves import tkinter
from six.moves import tkinter_colorchooser
from six.moves import tkinter_ttk as ttk
Expand Down Expand Up @@ -276,7 +275,7 @@ def initKw(self, kw):

def mDone(self, button):
if button == 0: # "OK" or double click
if isinstance(self.tree.selection_key, six.string_types):
if isinstance(self.tree.selection_key, str):
self.key = str(self.tree.selection_key)
else:
self.key = self.tree.selection_key
Expand Down Expand Up @@ -378,7 +377,7 @@ def updatePreview(self, key, scaling=-1):
canvas.deleteAllItems()

self.preview_scaling = scaling
if isinstance(key, six.string_types):
if isinstance(key, str):
if USE_PIL:
self.textScale['state'] = 'disabled'
# solid color
Expand Down
3 changes: 1 addition & 2 deletions pysollib/tile/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from pysollib.mygettext import _

import six
from six.moves import tkinter
from six.moves import tkinter_ttk as ttk

Expand Down Expand Up @@ -97,7 +96,7 @@ def _createSizegrip(self):
def updateText(self, **kw):
for k, v in kw.items():
label = getattr(self, k + '_label')
text = six.text_type(v)
text = str(v)
width = label['width']
if width and len(text) > width:
label['width'] = len(text)
Expand Down
Loading

0 comments on commit 70ec622

Please sign in to comment.