Exemplo n.º 1
0
 def _get_reply(self):
     while True:
         r = self.file.readline()[:-1]
         if DEBUG:
             debug('< %s\n' % r)
         if r.startswith('R '):
             r = r[2:]
             if r.startswith('ERR '):
                 raise protocol_error(r[4:])
             elif r == 'UNSUPPORTED':
                 raise UnsupportedCommand()
             else:
                 return r
         elif r.startswith('M '):
             self._handle_async_message(r[2:])
         else:
             raise ProtocolViolation(r)
Exemplo n.º 2
0
 def _handle_async_message(self, message):
     if message == 'OPENED':
         self._open_status = JOB_DONE
     elif message.startswith('OPENFAIL '):
         self._open_status = JOB_NO
         self._open_path = None
         try:
             raise protocol_error(message[9:])
         except SystemOpenError as ex:
             message = self.get_last_error();
             if message is None:
                 raise ProtocolViolation
             ex.message = message
             raise
     elif message == 'NEW-RESULTS':
         self._n_stored_results = None
     elif message == 'SORTED':
         self._sort_status = JOB_DONE
     elif message.startswith('QUERY-DONE '):
         self._query_status = JOB_DONE
         self._n_stored_results = int(message[10:])
     else:
         raise ProtocolViolation