mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 17:10:41 +00:00
Update
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from time import sleep
|
||||
from .. import errors, specification
|
||||
from .. import specification
|
||||
from ..errors import cl_error_lookup, error_lookup, cqp_error_lookup
|
||||
import socket
|
||||
import struct
|
||||
|
||||
@ -434,58 +435,18 @@ class APIClient:
|
||||
byte_data = self.__recv_WORD()
|
||||
response_type = byte_data >> 8
|
||||
if response_type == specification.CL_ERROR:
|
||||
raise self.__create_cl_error(byte_data)
|
||||
raise cl_error_lookup[byte_data]()
|
||||
elif response_type == specification.CQP_ERROR:
|
||||
raise self.__create_cqp_error(byte_data)
|
||||
raise cqp_error_lookup[byte_data]()
|
||||
elif response_type == specification.DATA:
|
||||
return self.__recv_DATA(byte_data)
|
||||
elif response_type == specification.ERROR:
|
||||
raise self.__create_error(byte_data)
|
||||
raise error_lookup[byte_data]()
|
||||
elif response_type == specification.STATUS:
|
||||
return {'code': byte_data, 'msg': specification.lookup[byte_data]}
|
||||
else:
|
||||
raise Exception('Unknown response type: {}'.format(response_type))
|
||||
|
||||
def __create_cl_error(self, error_type):
|
||||
if error_type == specification.CL_ERROR_NO_SUCH_ATTRIBUTE:
|
||||
return errors.CLErrorNoSuchAttribute()
|
||||
elif error_type == specification.CL_ERROR_WRONG_ATTRIBUTE_TYPE:
|
||||
return errors.CLErrorWrongAttributeType()
|
||||
elif error_type == specification.CL_ERROR_OUT_OF_RANGE:
|
||||
return errors.CLErrorOutOfRange()
|
||||
elif error_type == specification.CL_ERROR_REGEX:
|
||||
return errors.CLErrorRegex()
|
||||
elif error_type == specification.CL_ERROR_CORPUS_ACCESS:
|
||||
return errors.CLErrorCorpusAccess()
|
||||
elif error_type == specification.CL_ERROR_OUT_OF_MEMORY:
|
||||
return errors.CLErrorOutOfMemory()
|
||||
elif error_type == specification.CL_ERROR_INTERNAL:
|
||||
return errors.CLErrorInternal()
|
||||
else:
|
||||
return errors.CLError(error_type)
|
||||
|
||||
def __create_cqp_error(self, error_type):
|
||||
if error_type == specification.CQP_ERROR_GENERAL:
|
||||
return errors.CQPErrorGeneral()
|
||||
elif error_type == specification.CQP_ERROR_INVALID_FIELD:
|
||||
return errors.CQPErrorInvalidField()
|
||||
elif error_type == specification.CQP_ERROR_OUT_OF_RANGE:
|
||||
return errors.CQPErrorOutOfRange()
|
||||
else:
|
||||
return errors.CQPError(error_type)
|
||||
|
||||
def __create_error(self, error_type):
|
||||
if error_type == specification.ERROR_GENERAL_ERROR:
|
||||
return errors.ErrorGeneralError()
|
||||
elif error_type == specification.ERROR_CONNECT_REFUSED:
|
||||
return errors.ErrorConnectRefused()
|
||||
elif error_type == specification.ERROR_USER_ABORT:
|
||||
return errors.ErrorUserAbort()
|
||||
elif error_type == specification.ERROR_SYNTAX_ERROR:
|
||||
return errors.ErrorSyntaxError()
|
||||
else:
|
||||
return errors.Error(error_type)
|
||||
|
||||
def __recv_DATA(self, data_type):
|
||||
if data_type == specification.DATA_BYTE:
|
||||
data = self.__recv_DATA_BYTE()
|
||||
|
Reference in New Issue
Block a user