+ def _get_available_commands(self):
+ self.check_busy()
+ self._busy = 'help'
+ conn = self.conn
+ conn.write('help\n')
+ result = set()
+ line = self.conn.readline()
+ if not line == 'Commands:\n':
+ raise ClientError('unexpected help header ' + repr(line))
+ while True:
+ line = self.conn.readline()
+ if line == '\n':
+ break
+ if not line.startswith(' '):
+ raise ClientError('unexpected help line ' + repr(line))
+ cmd = line.strip()
+ if not cmd:
+ raise ClientError('unexpected help line ' + repr(line))
+ result.add(cmd)
+ # FIXME: confusing
+ not_ok = self.check_ok()
+ if not_ok:
+ raise not_ok
+ self._not_busy()
+ return frozenset(result)
+
+ def _require_command(self, name):
+ if name not in self._available_commands:
+ raise ClientError('server does not appear to provide %s command'
+ % name)
+