mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-15 02:54:09 -04:00
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.
This commit is contained in:
parent
5f2cc55655
commit
3846acef92
2 changed files with 2 additions and 10 deletions
|
@ -1172,10 +1172,7 @@ class ConfigObj(Section):
|
||||||
if isinstance(infile, string_types):
|
if isinstance(infile, string_types):
|
||||||
self.filename = infile
|
self.filename = infile
|
||||||
if os.path.isfile(infile):
|
if os.path.isfile(infile):
|
||||||
if sys.version_info > (3,):
|
|
||||||
infile = six.text_type(open(infile).read()) or []
|
infile = six.text_type(open(infile).read()) or []
|
||||||
else:
|
|
||||||
infile = open(infile).read() or []
|
|
||||||
elif self.file_error:
|
elif self.file_error:
|
||||||
# raise an error if the file doesn't exist
|
# raise an error if the file doesn't exist
|
||||||
raise IOError('Config file not found: "%s".' % self.filename)
|
raise IOError('Config file not found: "%s".' % self.filename)
|
||||||
|
|
|
@ -27,7 +27,6 @@ import os
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import six
|
import six
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
@ -819,9 +818,7 @@ class Base_Solver_Hint:
|
||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
kw['close_fds'] = True
|
kw['close_fds'] = True
|
||||||
p = subprocess.Popen(command, **kw)
|
p = subprocess.Popen(command, **kw)
|
||||||
bytes_board = board
|
bytes_board = six.binary_type(board, 'utf-8')
|
||||||
if sys.version_info > (3,):
|
|
||||||
bytes_board = bytes(board, 'utf-8')
|
|
||||||
pout, perr = p.communicate(bytes_board)
|
pout, perr = p.communicate(bytes_board)
|
||||||
if p.returncode in (127, 1):
|
if p.returncode in (127, 1):
|
||||||
# Linux and Windows return codes for "command not found" error
|
# 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!
|
# Based on https://stackoverflow.com/questions/8898294 - thanks!
|
||||||
def mydecode(s):
|
def mydecode(s):
|
||||||
if sys.version_info < (3,):
|
|
||||||
pass # return s
|
|
||||||
for encoding in "utf-8-sig", "utf-8":
|
for encoding in "utf-8-sig", "utf-8":
|
||||||
try:
|
try:
|
||||||
return s.decode(encoding)
|
return s.decode(encoding)
|
||||||
|
|
Loading…
Add table
Reference in a new issue