From 3846acef926878441fd674d4918f1c80da0e9cb1 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Fri, 14 Sep 2018 16:19:51 +0300 Subject: [PATCH] Refactoring / code cleanup. See: * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well. --- pysollib/configobj/configobj.py | 5 +---- pysollib/hint.py | 7 +------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/pysollib/configobj/configobj.py b/pysollib/configobj/configobj.py index 6cb5b6d6..1546b362 100644 --- a/pysollib/configobj/configobj.py +++ b/pysollib/configobj/configobj.py @@ -1172,10 +1172,7 @@ class ConfigObj(Section): if isinstance(infile, string_types): self.filename = infile if os.path.isfile(infile): - if sys.version_info > (3,): - infile = six.text_type(open(infile).read()) or [] - else: - infile = open(infile).read() or [] + infile = six.text_type(open(infile).read()) or [] elif self.file_error: # raise an error if the file doesn't exist raise IOError('Config file not found: "%s".' % self.filename) diff --git a/pysollib/hint.py b/pysollib/hint.py index c4c5c89d..c272e116 100644 --- a/pysollib/hint.py +++ b/pysollib/hint.py @@ -27,7 +27,6 @@ import os import time import subprocess import re -import sys import six from io import BytesIO @@ -819,9 +818,7 @@ class Base_Solver_Hint: if os.name != 'nt': kw['close_fds'] = True p = subprocess.Popen(command, **kw) - bytes_board = board - if sys.version_info > (3,): - bytes_board = bytes(board, 'utf-8') + bytes_board = six.binary_type(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 @@ -910,8 +907,6 @@ class FreeCellSolver_Hint(Base_Solver_Hint): # Based on https://stackoverflow.com/questions/8898294 - thanks! def mydecode(s): - if sys.version_info < (3,): - pass # return s for encoding in "utf-8-sig", "utf-8": try: return s.decode(encoding)