Debian Codegraph @

django_xmlrpc/views.py

raw symbols SCIP
1 """Uses SimpleXMLRPCServer's SimpleXMLRPCDispatcher to serve XML-RPC requests
2
3 Authors::
4 Graham Binns
5 Reza Mohammadi
6 Julien Fache
7
8 Credit must go to Brendan W. McAdams <[email protected]>, who
9 posted the original SimpleXMLRPCDispatcher to the Django wiki:
10 http://code.djangoproject.com/wiki/XML-RPC
11
12 New BSD License
13 ===============
14 Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon
15
16 All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20
21 * Redistributions of source code must retain the above copyright notice,
22 this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright notice,
24 this list of conditions and the following disclaimer in the documentation
25 and/or other materials provided with the distribution.
26 * Neither the name of the <ORGANIZATION> nor the names of its contributors
27 may be used to endorse or promote products derived from this software
28 without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 """
42 from logging import getLogger
43
44 from django.http import HttpResponse
45 from django.http import HttpResponseServerError
46 from django.shortcuts import render
47 from django.views.decorators.csrf import csrf_exempt
48
49 from django_xmlrpc.dispatcher import xmlrpc_dispatcher
50
51
52 logger = getLogger('xmlrpc.views')
53
54
55 @csrf_exempt
56 def handle_xmlrpc(request):
57 """Handles XML-RPC requests. All XML-RPC calls should be forwarded here
58
59 request
60 The HttpRequest object that carries the XML-RPC call. If this is a
61 GET request, nothing will happen (we only accept POST requests)
62 """
63 if request.method == 'POST':
64 logger.info(request.body)
65 try:
66 response = HttpResponse(content_type='text/xml')
67 response.write(
68 xmlrpc_dispatcher._marshaled_dispatch(request.body))
69 logger.debug(response)
70 return response
71 except:
72 return HttpResponseServerError()
73 else:
74 methods = xmlrpc_dispatcher.system_listMethods()
75 method_list = []
76
77 for method in methods:
78 sig_ = xmlrpc_dispatcher.system_methodSignature(method)
79 sig = {
80 'returns': sig_[0],
81 'args': ', '.join(sig_[1:]),
82 }
83
84 # This just reads your docblock, so fill it in!
85 method_help = xmlrpc_dispatcher.system_methodHelp(method)
86
87 method_list.append((method, sig, method_help))
88
89 return render(request, 'xmlrpc_get.html', {'methods': method_list})