A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
This PR is an attempt at reducing the number of assumptions about what whitespace can appear in messages received from engines. This is done in several parts:
A new function _next_token() extracts the next whitespace delimited word from a string, returning it with whitespace stripped out along with the rest of the line unchanged. This allows for string equality comparisons instead of str.startswith() and for the whitespace in the remaining string to be untouched, unlike with str.split().
UCI options are parsed with a regex split that splits off parameter names without changing the whitespace in the parameter values.
If a received line is expected to exactly match another string, it will be compared with a strip() version of it: if line.strip() == "readyok".
Fixes #970
This PR is an attempt at reducing the number of assumptions about what whitespace can appear in messages received from engines. This is done in several parts:
_next_token()
extracts the next whitespace delimited word from a string, returning it with whitespace stripped out along with the rest of the line unchanged. This allows for string equality comparisons instead ofstr.startswith()
and for the whitespace in the remaining string to be untouched, unlike withstr.split()
.strip()
version of it:if line.strip() == "readyok"
.Other repeated code is refactored into functions.