'Get the widget handler for a method
@param r: the S3Request
@param method: the widget method'

def get_widget_handler(self, method):

    if self.component:
        resource = self.component
        if resource.link:
            resource = resource.link
    else:
        resource = self.resource
    (prefix, name) = (self.prefix, self.name)
    component_name = self.component_name
    custom_action = current.s3db.get_method(prefix, name, component_name=component_name, method=method)
    http = self.http
    handler = None
    if (method and custom_action):
        handler = custom_action
    if (http == 'GET'):
        if (not method):
            if (resource.count() == 1):
                method = 'read'
            else:
                method = 'list'
        transform = self.transformable()
        handler = self.get_handler(method, transform=transform)
    elif (http == 'PUT'):
        transform = self.transformable(method='import')
        handler = self.get_handler(method, transform=transform)
    elif (http == 'POST'):
        transform = self.transformable(method='import')
        return self.get_handler(method, transform=transform)
    elif (http == 'DELETE'):
        if method:
            return self.get_handler(method)
        else:
            return self.get_handler('delete')
    else:
        return None
    if (handler is None):
        handler = resource.crud
    if isinstance(handler, (type, types.ClassType)):
        handler = handler()
    return handler
