Source code for pipeLionServer.services.abstractService

from pipeLionServer.core.error import PipeLionServerException
from pipeLionServer.core.error import PipeLionServerWarning

[docs]class AbstractService(object): """ the abstractService class defines in which way a Service will search for requests to define a new Service inherit this service object and name all your request-functions like: 1 | def reguest_YOURREQUESTNAME(self, YOURARGS): 2 | ... """ ## holds the dataBase instance dB = None def __init__(self, dataBase): """ constructor """ self.dB = dataBase
[docs] def makeRequest(self, request, **kwargs): """ method will call the instance method request_REQUEST(kwargs) in case it cannot find that function it will raise a PipeLionServerException :param request: name of the request function :type request: string :param kwargs: dictionary of arguments, which should be inputted to the instance-method :type kwargs: dictionary :returns: returnValue of request_REQUEST(kwargs) or PipeLionServerException :rtype: variant object """ if hasattr(self, "request_%s"%request): try: returnValue = eval('self.request_%s(**%s)'%(request, kwargs)) except Exception as errorMsg: returnValue = PipeLionServerException( 'the request-call %s of service %s caused the following error:' % ( request, self.__class__.__name__ ), errorMsg ) return returnValue else: return PipeLionServerException('the given request is not part of %s!'%self.__class__.__name__)