def xmlrpc(request):

    if request.POST:

        redirect = request.POST.get('redirect_to')
        if redirect:
            return HttpResponseRedirect(redirect)

        output = dispatcher.run(request.raw_post_data)

        host = request.get_host()
        domain = Site.objects.get_current().domain
        if host != domain:
            for protocol in ('http', 'https'):
                output = output.replace(
                    '%s://%s/' % (protocol, domain),
                    '%s://%s/' % (protocol, host),
                )

        response = HttpResponse(mimetype='application/xml')
        response.write(strip_spaces_between_tags(output))
        return response

    methods = {}
    for method_name in dispatcher.system_listMethods():
        namespace = method_name.split('.')[0]
        methods.setdefault(namespace, SortedDict())
        methods[namespace][method_name] = get_method_info(
            dispatcher.funcs[method_name])

    method_lists = []
    for namespace in sorted(methods.keys()):
        method_lists.append((
            namespace,
            NAMESPACE_TITLES.get(namespace, namespace),
            methods[namespace].items(),
        ))

    return render_to_response(
        template_name='xmlrpc/xmlrpc.html',
        dictionary={
            'method_lists': method_lists,
        },
        context_instance=RequestContext(request),
    )
Beispiel #2
0
def xmlrpc(request):

    if request.POST:

        redirect = request.POST.get('redirect_to')
        if redirect:
            return HttpResponseRedirect(redirect)

        output = dispatcher.run(request.raw_post_data)

        host = request.get_host()
        domain = Site.objects.get_current().domain
        if host != domain:
            for protocol in ('http', 'https'):
                output = output.replace(
                    '%s://%s/' % (protocol, domain),
                    '%s://%s/' % (protocol, host),
                )

        response = HttpResponse(mimetype='application/xml')
        response.write(strip_spaces_between_tags(output))
        return response

    methods = {}
    for method_name in dispatcher.system_listMethods():
        namespace = method_name.split('.')[0]
        methods.setdefault(namespace, SortedDict())
        methods[namespace][method_name] = get_method_info(dispatcher.funcs[method_name])

    method_lists = []
    for namespace in sorted(methods.keys()):
        method_lists.append((
            namespace,
            NAMESPACE_TITLES.get(namespace, namespace),
            methods[namespace].items(),
        ))

    return render_to_response(
        template_name='xmlrpc/xmlrpc.html',
        dictionary={
            'method_lists': method_lists,
        },
        context_instance=RequestContext(request),
    )
Beispiel #3
0
    def system_methodSignature(self, method_name):
        """
        Gets a list describing the signature of specified method. The first
        value is the return type, and the following values are the argument
        types in the order that they must be passed in.

        :type method_name: string

        :returns: ['return type', 'arg1 type', 'arg2 type', ...]
        :rtype: array

        """

        try:
            method = self.funcs[method_name]
        except KeyError:
            raise Fault(404, 'Method not found.')

        method_info = get_method_info(method)

        return_type = method_info.get('returns', {}).get('type')
        if not return_type:
            # If the signature is not defined in the method's docstring,
            # then just abort and say we don't know the signature.
            return 'undef'

        arg_types = []
        for arg_info in method_info.get('args', {}).values():
            arg_type = arg_info.get('type')
            if arg_type:
                arg_types.append(arg_type)
            else:
                # If we have arg info but it's missing the type,
                # then just abort and say we don't know the signature.
                return 'undef'

        return [return_type] + arg_types