- def _get_simple_response(self):
- data = self._read().strip()
- if data[0] == '+':
- return data[1:]
- self._check_for_error(data)
- raise InvalidResponse("Cannot parse first line '%s' for a simple response." % data, data)
-
- def _get_numeric_response(self, allow_negative=True):
- data = self._read().strip()
- try:
- value = int(data)
- except (TypeError, ValueError), e:
- pass
- else:
- if not allow_negative and value < 0:
- self._check_for_error(data)
- return value
- self._check_for_error(data)
- raise InvalidResponse("Cannot parse first line '%s' for a numeric response: %s." % (data, e), data)
-
- def _get_multi_response(self):
- results = list()
- try:
- num = self._get_numeric_response(allow_negative=False)
- except InvalidResponse, e:
- if e.args[1] == 'nil':
- return results
- raise
- while num:
- results.append(self._get_value(negative_as_nil=True))
- num -= 1
- return results
-
- def _check_for_error(self, data):
- if not data or data[0] != '-':
- return
- if data.startswith('-ERR'):
- raise ResponseError(data[4:].strip())
- try:
- error_len = int(data[1:])
- except (TypeError, ValueError):
- raise ResponseError("Unknown error format '%s'." % data)
- error_message = self._read().strip()[5:]
- raise ResponseError(error_message)
-