示例#1
0
    def func(class_obj):
        if class_obj._descriptor:
            class_obj._descriptor.name = name if name else class_obj.__name__
        else:
            class_obj._descriptor = _MessageDescriptor(name if name else class_obj.__name__)
            Serializer.register_message_descriptor(class_obj, class_obj._descriptor)

        return class_obj
示例#2
0
    def func(class_obj):
        if class_obj._descriptor is None:
            class_obj._descriptor = _MessageDescriptor()
            Serializer.register_message_descriptor(class_obj, class_obj._descriptor)

        field = _FieldDescriptor(
            name,
            field_type=field_type,
            list_item_type=list_item_type,
            list_item_class=list_item_class,
            object_class=object_class,
            enum_class=enum_class,
        )
        class_obj._descriptor.fields.append(field)
        return class_obj
示例#3
0
 def call_method(self, method_descriptor, message):
     try:
         message_data = Serializer.serialize(message)
         request = _RpcRequest('', method_descriptor.name, message_data)
         
         serialized = _RpcRequestSerializer.serialize(request)
         
         self.connect()
         self.send(serialized)
         if method_descriptor.response_class:
             response = self.receive()
             
             if Serializer.can_deserialize(response, ErrorMessage):
                 deserialized = Serializer.deserialize(response, ErrorMessage)
                 raise ServerException(deserialized.message)
             else:
                 return Serializer.deserialize(response, method_descriptor.response_class)
     finally:
         self.close()
示例#4
0
 def process_request(self, address, data):
     request = _RpcRequestSerializer.deserialize(data)
     self.logger.debug('Processing \'%s\' rpc method.' % request.method)
     
     for h in self._service_handlers:
         if h.can_handle(request.method):
             response = h.handle(request.method, request.data)
             if response:
                 return Serializer.serialize(response)
             else:
                 return None
     else:
         raise ServerException('Method %s is not supported.' % request.method)
示例#5
0
    def func(class_obj):
        class_obj._descriptor = descriptor
        Serializer.register_message_descriptor(class_obj, class_obj._descriptor)

        return class_obj
示例#6
0
 def handle_error(self, address, exception, exc_info):
     self.logger.error('Unhandled error: %s' % exception.message, exc_info=exc_info)
     return Serializer.serialize(ErrorMessage(exception.message))
示例#7
0
    def handle(self, method, data):
        method_descriptor = getattr(self._service, method)._descriptor
        
        message = Serializer.deserialize(data, method_descriptor.request_class)

        return method_descriptor.method(self._service, message)