Beispiel #1
0
    def handle_call(self, call):
        if (call.type != 'procedure_call'):
            raise SCSCPProtocolError('Bad message from client: %s.' % call.type, om=call.om())
        try:
            head = call.data.elem.name
            self.log.debug('Requested head: %s...' % head)
            
            if call.data.elem.cd == 'scscp2' and head in CD_SCSCP2:
                res = getattr(self, head)(call.data)
            elif call.data.elem.cd == 'arith1' and head in CD_ARITH1:
                args = [conv.to_python(a) for a in call.data.arguments]
                res = conv.to_openmath(CD_ARITH1[head](*args))
            elif call.data.elem.cd == 'scscp_transient_1' and head in CD_SCSCP_TRANSIENT1:
                args = [conv.to_python(a) for a in call.data.arguments]
                res = conv.to_openmath(CD_SCSCP_TRANSIENT1[head](*args))
            else:
                self.log.debug('...head unknown.')
                return self.scscp.terminated(call.id, om.OMError(
                    om.OMSymbol('unhandled_symbol', cd='error'), [call.data.elem]))

            strlog = str(res)
            self.log.debug('...sending result: %s' % (strlog[:20] + (len(strlog) > 20 and '...')))
            return self.scscp.completed(call.id, res)
        except (AttributeError, IndexError, TypeError):
            self.log.debug('...client protocol error.')
            return self.scscp.terminated(call.id, om.OMError(
                om.OMSymbol('unexpected_symbol', cd='error'), [call.data]))
        except Exception as e:
            self.log.exception('Unhandled exception:')
            return self.scscp.terminated(call.id, 'system_specific',
                                             'Unhandled exception %s.' % str(e))
 def is_allowed_head(self, data):
     head = data.arguments[0]
     return conv.to_openmath(
         (head.cd == 'scscp_trans_1' and head.name in CD_SCSCP_TRANS)
         or (head.cd == 'scscp2' and head.name in CD_SCSCP2)
         or (head.cd == 'singular' and head.name in CD_SINGULAR)
         or head.cd == 'scscp1')
Beispiel #3
0
 def is_allowed_head(self, data):
     head = data.arguments[0]
     return conv.to_openmath((head.cd == 'arith1' and head.name in CD_ARITH1)
                                 or (head.cd == 'scscp2' and head.name in CD_SCSCP2)
                                 or head.cd == 'scscp1')
Beispiel #4
0
def _conv_if_py(obj):
    if isinstance(obj, om.OMAny):
        return obj
    else:
        return convert.to_openmath(obj)
Beispiel #5
0
 def is_allowed_head(self, data):
     head = data.arguments[0]
     return conv.to_openmath((head.cd == 'arith1' and head.name in CD_ARITH1)
                                 or (head.cd == 'scscp2' and head.name in CD_SCSCP2)
                                 or head.cd == 'scscp1')
Beispiel #6
0
def _conv_if_py(obj):
    if isinstance(obj, om.OMAny):
        return obj
    else:
        return convert.to_openmath(obj)
Beispiel #7
0
 def handle_call(self, call, head):
     if call.data.elem.cd == 'arith1' and head in CD_ARITH1:
         args = [conv.to_python(a) for a in call.data.arguments]
         return conv.to_openmath(CD_ARITH1[head](*args))
     
     return super(SCSCPRequestHandler, self).handle_call(call, head)