+def _strsymbol(symbol):
+ if isinstance(symbol, str):
+ return symbol
+ elif isinstance(symbol, Expression) and symbol.issymbol():
+ return str(symbol)
+ else:
+ raise TypeError('symbol must be a string or a symbol')
+
+def _strsymbols(symbols):
+ if isinstance(symbols, str):
+ return symbols.replace(',', ' ').split()
+ else:
+ return [_strsymbol(symbol) for symbol in symbols]
+
+
+class _ISCC:
+
+ command =['iscc']
+ debug = False
+
+ @classmethod
+ def eval(cls, input):
+ if not input.endswith(';'):
+ input += ';'
+ proc = subprocess.Popen(cls.command,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ universal_newlines=True)
+ output, error = proc.communicate(input=input)
+ output = output.strip()
+ if cls.debug:
+ print('iscc: {!r} -> {!r}'.format(input, output))
+ return output
+
+ @classmethod
+ def symbols(cls, symbols):
+ symbols = _strsymbols(symbols)
+ return '[{}]'.format(', '.join(symbols))
+
+ @classmethod
+ def constraints(cls, equalities, inequalities):
+ strings = []
+ for equality in equalities:
+ strings.append('{} = 0'.format(equality))
+ for inequality in inequalities:
+ strings.append('{} <= 0'.format(inequality))
+ return ' and '.join(strings)