Imported Upstream version 0.1.5
SVN-Git Migration
8 years ago
0 | include README.rst | |
1 | recursive-include django_xmlrpc/locale * | |
2 | recursive-include django_xmlrpc/templates *.html |
0 | Metadata-Version: 1.0 | |
1 | Name: django-xmlrpc | |
2 | Version: 0.1.5 | |
3 | Summary: XML-RPC Server App for the Django framework. | |
4 | Home-page: https://github.com/Fantomas42/django-xmlrpc | |
5 | Author: Fantomas42 | |
6 | Author-email: fantomas42@gmail.com | |
7 | License: New BSD License | |
8 | Description: ============== | |
9 | Django XML-RPC | |
10 | ============== | |
11 | ||
12 | **Django_xmlrpc** offers a means by which a Django developer can expose their | |
13 | views (or indeed any other function) using XML-RPC. | |
14 | ||
15 | This is a fork of the version hosted at : | |
16 | https://code.launchpad.net/~aartemenko/django-xmlrpc/svetlyak40wt | |
17 | compatible with Django >= 1.4 and Python >= 2.5. | |
18 | ||
19 | If you want to use **django_xmlrpc** for an older version of Django or Python, | |
20 | please use an old release. | |
21 | ||
22 | .. contents:: | |
23 | ||
24 | Installation | |
25 | ============ | |
26 | ||
27 | You could retrieve the last sources from | |
28 | http://github.com/Fantomas42/django-xmlrpc and run the installation script | |
29 | :: | |
30 | ||
31 | $> python setup.py install | |
32 | ||
33 | or use pip :: | |
34 | ||
35 | $> pip install -e git://github.com/Fantomas42/django-xmlrpc.git#egg=django-xmlrpc | |
36 | ||
37 | Usage | |
38 | ===== | |
39 | ||
40 | Register **django_xmlrpc** in your INSTALLED_APPS section of your project' | |
41 | settings. | |
42 | ||
43 | Then register methods you want to handle like this in your project' | |
44 | settings. :: | |
45 | ||
46 | >>> XMLRPC_METHODS = (('path.to.your.method', 'Method name'), | |
47 | ... ('path.to.your.othermethod', 'Other Method name'),) | |
48 | ||
49 | Finally we need to register the url of the XML-RPC server. Insert something | |
50 | like this in your project's urls.py: :: | |
51 | ||
52 | >>> url(r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc', name='xmlrpc'), | |
53 | ||
54 | Keywords: django,service,xmlrpc | |
55 | Platform: UNKNOWN | |
56 | Classifier: Framework :: Django | |
57 | Classifier: Development Status :: 5 - Production/Stable | |
58 | Classifier: Environment :: Web Environment | |
59 | Classifier: Programming Language :: Python | |
60 | Classifier: Programming Language :: Python :: 3 | |
61 | Classifier: Intended Audience :: Developers | |
62 | Classifier: Operating System :: OS Independent | |
63 | Classifier: Topic :: Software Development :: Libraries :: Python Modules |
0 | ============== | |
1 | Django XML-RPC | |
2 | ============== | |
3 | ||
4 | **Django_xmlrpc** offers a means by which a Django developer can expose their | |
5 | views (or indeed any other function) using XML-RPC. | |
6 | ||
7 | This is a fork of the version hosted at : | |
8 | https://code.launchpad.net/~aartemenko/django-xmlrpc/svetlyak40wt | |
9 | compatible with Django >= 1.4 and Python >= 2.5. | |
10 | ||
11 | If you want to use **django_xmlrpc** for an older version of Django or Python, | |
12 | please use an old release. | |
13 | ||
14 | .. contents:: | |
15 | ||
16 | Installation | |
17 | ============ | |
18 | ||
19 | You could retrieve the last sources from | |
20 | http://github.com/Fantomas42/django-xmlrpc and run the installation script | |
21 | :: | |
22 | ||
23 | $> python setup.py install | |
24 | ||
25 | or use pip :: | |
26 | ||
27 | $> pip install -e git://github.com/Fantomas42/django-xmlrpc.git#egg=django-xmlrpc | |
28 | ||
29 | Usage | |
30 | ===== | |
31 | ||
32 | Register **django_xmlrpc** in your INSTALLED_APPS section of your project' | |
33 | settings. | |
34 | ||
35 | Then register methods you want to handle like this in your project' | |
36 | settings. :: | |
37 | ||
38 | >>> XMLRPC_METHODS = (('path.to.your.method', 'Method name'), | |
39 | ... ('path.to.your.othermethod', 'Other Method name'),) | |
40 | ||
41 | Finally we need to register the url of the XML-RPC server. Insert something | |
42 | like this in your project's urls.py: :: | |
43 | ||
44 | >>> url(r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc', name='xmlrpc'), |
0 | """__init__ module for the django_xmlrpc package | |
1 | ||
2 | Authors:: | |
3 | Graham Binns | |
4 | Julien Fache | |
5 | ||
6 | Credit must go to Brendan W. McAdams <brendan.mcadams@thewintergrp.com>, who | |
7 | posted the original SimpleXMLRPCDispatcher to the Django wiki: | |
8 | http://code.djangoproject.com/wiki/XML-RPC | |
9 | ||
10 | New BSD License | |
11 | =============== | |
12 | Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon | |
13 | ||
14 | All rights reserved. | |
15 | ||
16 | Redistribution and use in source and binary forms, with or without | |
17 | modification, are permitted provided that the following conditions are met: | |
18 | ||
19 | * Redistributions of source code must retain the above copyright notice, | |
20 | this list of conditions and the following disclaimer. | |
21 | * Redistributions in binary form must reproduce the above copyright notice, | |
22 | this list of conditions and the following disclaimer in the documentation | |
23 | and/or other materials provided with the distribution. | |
24 | * Neither the name of the <ORGANIZATION> nor the names of its contributors | |
25 | may be used to endorse or promote products derived from this software | |
26 | without specific prior written permission. | |
27 | ||
28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
32 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
33 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
34 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
35 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
36 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
37 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
38 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
39 | """ | |
40 | VERSION = (0, 1, 5) | |
41 | __version__ = '.'.join(map(str, VERSION)) |
0 | """Offers decorators to make the use of django_xmlrpc a great deal simpler | |
1 | ||
2 | Authors:: | |
3 | Graham Binns, | |
4 | Reza Mohammadi | |
5 | ||
6 | Credit must go to Brendan W. McAdams <brendan.mcadams@thewintergrp.com>, who | |
7 | posted the original SimpleXMLRPCDispatcher to the Django wiki: | |
8 | http://code.djangoproject.com/wiki/XML-RPC | |
9 | ||
10 | New BSD License | |
11 | =============== | |
12 | Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon | |
13 | ||
14 | All rights reserved. | |
15 | ||
16 | Redistribution and use in source and binary forms, with or without | |
17 | modification, are permitted provided that the following conditions are met: | |
18 | ||
19 | * Redistributions of source code must retain the above copyright notice, | |
20 | this list of conditions and the following disclaimer. | |
21 | * Redistributions in binary form must reproduce the above copyright notice, | |
22 | this list of conditions and the following disclaimer in the documentation | |
23 | and/or other materials provided with the distribution. | |
24 | * Neither the name of the <ORGANIZATION> nor the names of its contributors | |
25 | may be used to endorse or promote products derived from this software | |
26 | without specific prior written permission. | |
27 | ||
28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
32 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
33 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
34 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
35 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
36 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
37 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
38 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
39 | """ | |
40 | try: | |
41 | from xmlrpc.client import Fault | |
42 | except ImportError: # Python 2 | |
43 | from xmlrpclib import Fault | |
44 | from django.contrib.auth import authenticate | |
45 | from django.utils.translation import gettext as _ | |
46 | ||
47 | ||
48 | # Some constants for your pleasure | |
49 | #XXX: Any standardization? | |
50 | AUTHENTICATION_FAILED_CODE = 81 | |
51 | PERMISSION_DENIED_CODE = 82 | |
52 | ||
53 | ||
54 | class AuthenticationFailedException(Fault): | |
55 | """An XML-RPC fault to be raised when a permission_required authentication | |
56 | check fails | |
57 | ||
58 | Author | |
59 | """ | |
60 | def __init__(self): | |
61 | Fault.__init__(self, AUTHENTICATION_FAILED_CODE, | |
62 | _('Username and/or password is incorrect')) | |
63 | ||
64 | ||
65 | class PermissionDeniedException(Fault): | |
66 | """An XML-RPC fault to be raised when a permission_required permission | |
67 | check fails | |
68 | """ | |
69 | def __init__(self): | |
70 | Fault.__init__(self, PERMISSION_DENIED_CODE, _('Permission denied')) | |
71 | ||
72 | ||
73 | def xmlrpc_method(returns='string', args=None, name=None): | |
74 | """Adds a signature to an XML-RPC function and register | |
75 | it with the dispatcher. | |
76 | ||
77 | returns | |
78 | The return type of the function. This can either be a string | |
79 | description (e.g. 'string') or a type (e.g. str, bool) etc. | |
80 | ||
81 | args | |
82 | A list of the types of the arguments that the function accepts. These | |
83 | can be strings or types or a mixture of the two e.g. | |
84 | [str, bool, 'string'] | |
85 | """ | |
86 | # Args should be a list | |
87 | if args is None: | |
88 | args = [] | |
89 | ||
90 | def _xmlrpc_func(func): | |
91 | """Inner function for XML-RPC method decoration. Adds a signature to | |
92 | the method passed to it. | |
93 | ||
94 | func | |
95 | The function to add the signature to | |
96 | """ | |
97 | # Add a signature to the function | |
98 | func._xmlrpc_signature = { | |
99 | 'returns': returns, | |
100 | 'args': args | |
101 | } | |
102 | return func | |
103 | ||
104 | return _xmlrpc_func | |
105 | ||
106 | xmlrpc_func = xmlrpc_method | |
107 | ||
108 | ||
109 | # Don't use this decorator when your service is going to be | |
110 | # available in an unencrpted/untrusted network. | |
111 | # Configure HTTPS transport for your web server. | |
112 | def permission_required(perm=None): | |
113 | """Decorator for authentication. Uses Django's built in authentication | |
114 | framework to provide authenticated-only and permission-related access | |
115 | to XML-RPC methods | |
116 | ||
117 | perm | |
118 | The permission (as a string) that the user must hold to be able to | |
119 | call the function that is decorated with permission_required. | |
120 | """ | |
121 | def _dec(func): | |
122 | """An inner decorator. Adds the lookup code for the permission passed | |
123 | in the outer method to the function passed to it. | |
124 | ||
125 | func | |
126 | The function to add the permission check to | |
127 | """ | |
128 | def __authenticated_call(username, password, *args): | |
129 | """Inner inner decorator. Adds username and password parameters to | |
130 | a given XML-RPC function for authentication and permission | |
131 | checking purposes and modifies the method signature appropriately | |
132 | ||
133 | username | |
134 | The username used for authentication | |
135 | ||
136 | password | |
137 | The password used for authentication | |
138 | """ | |
139 | try: | |
140 | user = authenticate(username=username, password=password) | |
141 | if not user: | |
142 | raise AuthenticationFailedException | |
143 | if perm and not user.has_perm(perm): | |
144 | raise PermissionDeniedException | |
145 | except AuthenticationFailedException: | |
146 | raise | |
147 | except PermissionDeniedException: | |
148 | raise | |
149 | except: | |
150 | raise AuthenticationFailedException | |
151 | return func(user, *args) | |
152 | ||
153 | # Update the function's XML-RPC signature, if the method has one | |
154 | if hasattr(func, '_xmlrpc_signature'): | |
155 | sig = func._xmlrpc_signature | |
156 | ||
157 | # We just stick two string args on the front of sign['args'] to | |
158 | # represent username and password | |
159 | sig['args'] = (['string'] * 2) + sig['args'] | |
160 | __authenticated_call._xmlrpc_signature = sig | |
161 | ||
162 | # Update the function's docstring | |
163 | if func.__doc__: | |
164 | __authenticated_call.__doc__ = func.__doc__ + \ | |
165 | "\nNote: Authentication is required.""" | |
166 | if perm: | |
167 | __authenticated_call.__doc__ += (' this function requires ' | |
168 | '"%s" permission.' % perm) | |
169 | ||
170 | return __authenticated_call | |
171 | ||
172 | return _dec |
0 | """Offers a simple XML-RPC dispatcher for django_xmlrpc | |
1 | ||
2 | Author:: | |
3 | Graham Binns | |
4 | ||
5 | Credit must go to Brendan W. McAdams <brendan.mcadams@thewintergrp.com>, who | |
6 | posted the original SimpleXMLRPCDispatcher to the Django wiki: | |
7 | http://code.djangoproject.com/wiki/XML-RPC | |
8 | ||
9 | New BSD License | |
10 | =============== | |
11 | Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon | |
12 | ||
13 | All rights reserved. | |
14 | ||
15 | Redistribution and use in source and binary forms, with or without | |
16 | modification, are permitted provided that the following conditions are met: | |
17 | ||
18 | * Redistributions of source code must retain the above copyright notice, | |
19 | this list of conditions and the following disclaimer. | |
20 | * Redistributions in binary form must reproduce the above copyright notice, | |
21 | this list of conditions and the following disclaimer in the documentation | |
22 | and/or other materials provided with the distribution. | |
23 | * Neither the name of the <ORGANIZATION> nor the names of its contributors | |
24 | may be used to endorse or promote products derived from this software | |
25 | without specific prior written permission. | |
26 | ||
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
31 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
32 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
33 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
34 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
38 | """ | |
39 | from inspect import getargspec | |
40 | ||
41 | try: | |
42 | from xmlrpc.server import SimpleXMLRPCDispatcher | |
43 | except ImportError: # Python 2 | |
44 | from SimpleXMLRPCServer import SimpleXMLRPCDispatcher | |
45 | ||
46 | ||
47 | class DjangoXMLRPCDispatcher(SimpleXMLRPCDispatcher): | |
48 | """A simple XML-RPC dispatcher for Django. | |
49 | ||
50 | Subclassess SimpleXMLRPCServer.SimpleXMLRPCDispatcher for the purpose of | |
51 | overriding certain built-in methods (it's nicer than monkey-patching them, | |
52 | that's for sure). | |
53 | """ | |
54 | ||
55 | def system_methodSignature(self, method): | |
56 | """Returns the signature details for a specified method | |
57 | ||
58 | method | |
59 | The name of the XML-RPC method to get the details for | |
60 | """ | |
61 | # See if we can find the method in our funcs dict | |
62 | # TODO: Handle this better: We really should return something more | |
63 | # formal than an AttributeError | |
64 | func = self.funcs[method] | |
65 | ||
66 | try: | |
67 | sig = func._xmlrpc_signature | |
68 | except: | |
69 | sig = { | |
70 | 'returns': 'string', | |
71 | 'args': ['string' for arg in getargspec(func)[0]], | |
72 | } | |
73 | ||
74 | return [sig['returns']] + sig['args'] |
Binary diff not shown
0 | # SOME DESCRIPTIVE TITLE. | |
1 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | |
2 | # This file is distributed under the same license as the PACKAGE package. | |
3 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | |
4 | # | |
5 | msgid "" | |
6 | msgstr "" | |
7 | "Project-Id-Version: django-xmlrpc\n" | |
8 | "Report-Msgid-Bugs-To: \n" | |
9 | "POT-Creation-Date: 2010-07-31 15:33+0200\n" | |
10 | "PO-Revision-Date: 2010-07-31 15:50+0100\n" | |
11 | "Last-Translator: Fantomas <Fantomas42@gmail.com>\n" | |
12 | "Language-Team: Fantomas42 <fantomas42@gmail.com>\n" | |
13 | "MIME-Version: 1.0\n" | |
14 | "Content-Type: text/plain; charset=UTF-8\n" | |
15 | "Content-Transfer-Encoding: 8bit\n" | |
16 | "X-Poedit-Language: French\n" | |
17 | "X-Poedit-Country: FRANCE\n" | |
18 | "X-Poedit-SourceCharset: utf-8\n" | |
19 | ||
20 | #: decorators.py:60 | |
21 | msgid "Username and/or password is incorrect" | |
22 | msgstr "Nom d'utilisateur et/ou mot de passe incorrect" | |
23 | ||
24 | #: decorators.py:68 | |
25 | msgid "Permission denied" | |
26 | msgstr "Permission refusée" | |
27 | ||
28 | #: templates/xmlrpc_get.html:4 | |
29 | #: templates/xmlrpc_get.html.py:7 | |
30 | msgid "XML-RPC Service" | |
31 | msgstr "Service XML-RPC" | |
32 | ||
33 | #: templates/xmlrpc_get.html:9 | |
34 | msgid "You need to invoke this service using an XML-RPC Client." | |
35 | msgstr "Vous devez invoquer ce service en utilisant un client XML-RPC." | |
36 | ||
37 | #: templates/xmlrpc_get.html:11 | |
38 | msgid "The following methods are available :" | |
39 | msgstr "Les méthodes suivantes sont disponibles :" | |
40 | ||
41 | #: templates/xmlrpc_get.html:17 | |
42 | msgid "Types of argument" | |
43 | msgstr "Types d'argument" | |
44 | ||
45 | #: templates/xmlrpc_get.html:19 | |
46 | msgid "Type of return" | |
47 | msgstr "Type de retour" | |
48 |
0 | {% extends "admin/base_site.html" %} | |
1 | {% load i18n %} | |
2 | ||
3 | {% block title %}{% trans "XML-RPC Service" %}{% endblock %} | |
4 | ||
5 | {% block content %} | |
6 | <h2>{% trans "XML-RPC Service" %}</h2> | |
7 | ||
8 | <p>{% trans "You need to invoke this service using an XML-RPC Client." %}</p> | |
9 | ||
10 | <h3>{% trans "The following methods are available :" %}</h3> | |
11 | ||
12 | {% for m in methods %} | |
13 | <div class="functions"> | |
14 | <h4>{{ m.0 }}</h4> | |
15 | <div class="function_desc"> | |
16 | <strong>{% trans "Types of argument" %}{{ m.1.args|length|pluralize }} :</strong> {{ m.1.args }} | |
17 | <br /> | |
18 | <strong>{% trans "Type of return" %} :</strong> {{ m.1.returns }} | |
19 | <br /> | |
20 | <pre class="function_doc">{{ m.2 }}</pre> | |
21 | </div> | |
22 | </div> | |
23 | {% endfor %} | |
24 | {% endblock %} | |
25 |
0 | """Uses SimpleXMLRPCServer's SimpleXMLRPCDispatcher to serve XML-RPC requests | |
1 | ||
2 | Authors:: | |
3 | Graham Binns | |
4 | Reza Mohammadi | |
5 | Julien Fache | |
6 | ||
7 | Credit must go to Brendan W. McAdams <brendan.mcadams@thewintergrp.com>, who | |
8 | posted the original SimpleXMLRPCDispatcher to the Django wiki: | |
9 | http://code.djangoproject.com/wiki/XML-RPC | |
10 | ||
11 | New BSD License | |
12 | =============== | |
13 | Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon | |
14 | ||
15 | All rights reserved. | |
16 | ||
17 | Redistribution and use in source and binary forms, with or without | |
18 | modification, are permitted provided that the following conditions are met: | |
19 | ||
20 | * Redistributions of source code must retain the above copyright notice, | |
21 | this list of conditions and the following disclaimer. | |
22 | * Redistributions in binary form must reproduce the above copyright notice, | |
23 | this list of conditions and the following disclaimer in the documentation | |
24 | and/or other materials provided with the distribution. | |
25 | * Neither the name of the <ORGANIZATION> nor the names of its contributors | |
26 | may be used to endorse or promote products derived from this software | |
27 | without specific prior written permission. | |
28 | ||
29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
33 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
34 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
39 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
40 | """ | |
41 | from logging import getLogger | |
42 | from collections import Callable | |
43 | ||
44 | from django.conf import settings | |
45 | from django.template import RequestContext | |
46 | from django.shortcuts import render_to_response | |
47 | from django.core.exceptions import ImproperlyConfigured | |
48 | from django.http import HttpResponse | |
49 | from django.http import HttpResponseServerError | |
50 | from django.views.decorators.csrf import csrf_exempt | |
51 | ||
52 | from django_xmlrpc.decorators import xmlrpc_func | |
53 | from django_xmlrpc.dispatcher import DjangoXMLRPCDispatcher | |
54 | ||
55 | ||
56 | logger = getLogger('xmlrpc') | |
57 | xmlrpcdispatcher = DjangoXMLRPCDispatcher(allow_none=False, encoding=None) | |
58 | ||
59 | ||
60 | @xmlrpc_func(returns='string', args=['string']) | |
61 | def test_xmlrpc(text): | |
62 | """Simply returns the args passed to it as a string""" | |
63 | return "Here's a response! %s" % str(text) | |
64 | ||
65 | ||
66 | @csrf_exempt | |
67 | def handle_xmlrpc(request): | |
68 | """Handles XML-RPC requests. All XML-RPC calls should be forwarded here | |
69 | ||
70 | request | |
71 | The HttpRequest object that carries the XML-RPC call. If this is a | |
72 | GET request, nothing will happen (we only accept POST requests) | |
73 | """ | |
74 | if request.method == "POST": | |
75 | logger.info(request.body) | |
76 | try: | |
77 | response = HttpResponse(content_type='text/xml') | |
78 | response.write( | |
79 | xmlrpcdispatcher._marshaled_dispatch(request.body)) | |
80 | logger.debug(response) | |
81 | return response | |
82 | except: | |
83 | return HttpResponseServerError() | |
84 | else: | |
85 | methods = xmlrpcdispatcher.system_listMethods() | |
86 | method_list = [] | |
87 | ||
88 | for method in methods: | |
89 | sig_ = xmlrpcdispatcher.system_methodSignature(method) | |
90 | sig = { | |
91 | 'returns': sig_[0], | |
92 | 'args': ", ".join(sig_[1:]), | |
93 | } | |
94 | ||
95 | # this just reads your docblock, so fill it in! | |
96 | method_help = xmlrpcdispatcher.system_methodHelp(method) | |
97 | ||
98 | method_list.append((method, sig, method_help)) | |
99 | ||
100 | return render_to_response('xmlrpc_get.html', {'methods': method_list}, | |
101 | context_instance=RequestContext(request)) | |
102 | ||
103 | ||
104 | # Load up any methods that have been registered with the server in settings | |
105 | if hasattr(settings, 'XMLRPC_METHODS'): | |
106 | for path, name in settings.XMLRPC_METHODS: | |
107 | # if "path" is actually a function, just add it without fuss | |
108 | if isinstance(path, Callable): | |
109 | xmlrpcdispatcher.register_function(path, name) | |
110 | continue | |
111 | ||
112 | # Otherwise we try and find something that we can call | |
113 | i = path.rfind('.') | |
114 | module, attr = path[:i], path[i + 1:] | |
115 | ||
116 | try: | |
117 | mod = __import__(module, globals(), locals(), [attr]) | |
118 | except ImportError as ex: | |
119 | raise ImproperlyConfigured( | |
120 | "Error registering XML-RPC method: " | |
121 | "module %s can't be imported" % module) | |
122 | ||
123 | try: | |
124 | func = getattr(mod, attr) | |
125 | except AttributeError: | |
126 | raise ImproperlyConfigured( | |
127 | 'Error registering XML-RPC method: ' | |
128 | 'module %s doesn\'t define a method "%s"' % (module, attr)) | |
129 | ||
130 | if not isinstance(func, Callable): | |
131 | raise ImproperlyConfigured( | |
132 | 'Error registering XML-RPC method: ' | |
133 | '"%s" is not callable in module %s' % (attr, module)) | |
134 | ||
135 | xmlrpcdispatcher.register_function(func, name) | |
136 | ||
137 | ||
138 | # Finally, register the introspection and multicall methods with the XML-RPC | |
139 | # namespace | |
140 | xmlrpcdispatcher.register_introspection_functions() | |
141 | xmlrpcdispatcher.register_multicall_functions() |
0 | Metadata-Version: 1.0 | |
1 | Name: django-xmlrpc | |
2 | Version: 0.1.5 | |
3 | Summary: XML-RPC Server App for the Django framework. | |
4 | Home-page: https://github.com/Fantomas42/django-xmlrpc | |
5 | Author: Fantomas42 | |
6 | Author-email: fantomas42@gmail.com | |
7 | License: New BSD License | |
8 | Description: ============== | |
9 | Django XML-RPC | |
10 | ============== | |
11 | ||
12 | **Django_xmlrpc** offers a means by which a Django developer can expose their | |
13 | views (or indeed any other function) using XML-RPC. | |
14 | ||
15 | This is a fork of the version hosted at : | |
16 | https://code.launchpad.net/~aartemenko/django-xmlrpc/svetlyak40wt | |
17 | compatible with Django >= 1.4 and Python >= 2.5. | |
18 | ||
19 | If you want to use **django_xmlrpc** for an older version of Django or Python, | |
20 | please use an old release. | |
21 | ||
22 | .. contents:: | |
23 | ||
24 | Installation | |
25 | ============ | |
26 | ||
27 | You could retrieve the last sources from | |
28 | http://github.com/Fantomas42/django-xmlrpc and run the installation script | |
29 | :: | |
30 | ||
31 | $> python setup.py install | |
32 | ||
33 | or use pip :: | |
34 | ||
35 | $> pip install -e git://github.com/Fantomas42/django-xmlrpc.git#egg=django-xmlrpc | |
36 | ||
37 | Usage | |
38 | ===== | |
39 | ||
40 | Register **django_xmlrpc** in your INSTALLED_APPS section of your project' | |
41 | settings. | |
42 | ||
43 | Then register methods you want to handle like this in your project' | |
44 | settings. :: | |
45 | ||
46 | >>> XMLRPC_METHODS = (('path.to.your.method', 'Method name'), | |
47 | ... ('path.to.your.othermethod', 'Other Method name'),) | |
48 | ||
49 | Finally we need to register the url of the XML-RPC server. Insert something | |
50 | like this in your project's urls.py: :: | |
51 | ||
52 | >>> url(r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc', name='xmlrpc'), | |
53 | ||
54 | Keywords: django,service,xmlrpc | |
55 | Platform: UNKNOWN | |
56 | Classifier: Framework :: Django | |
57 | Classifier: Development Status :: 5 - Production/Stable | |
58 | Classifier: Environment :: Web Environment | |
59 | Classifier: Programming Language :: Python | |
60 | Classifier: Programming Language :: Python :: 3 | |
61 | Classifier: Intended Audience :: Developers | |
62 | Classifier: Operating System :: OS Independent | |
63 | Classifier: Topic :: Software Development :: Libraries :: Python Modules |
0 | MANIFEST.in | |
1 | README.rst | |
2 | setup.py | |
3 | django_xmlrpc/__init__.py | |
4 | django_xmlrpc/decorators.py | |
5 | django_xmlrpc/dispatcher.py | |
6 | django_xmlrpc/views.py | |
7 | django_xmlrpc.egg-info/PKG-INFO | |
8 | django_xmlrpc.egg-info/SOURCES.txt | |
9 | django_xmlrpc.egg-info/dependency_links.txt | |
10 | django_xmlrpc.egg-info/not-zip-safe | |
11 | django_xmlrpc.egg-info/top_level.txt | |
12 | django_xmlrpc/locale/fr/LC_MESSAGES/django.mo | |
13 | django_xmlrpc/locale/fr/LC_MESSAGES/django.po | |
14 | django_xmlrpc/templates/xmlrpc_get.html⏎ |
0 | django_xmlrpc |
0 | import os | |
1 | from setuptools import setup | |
2 | from setuptools import find_packages | |
3 | ||
4 | import django_xmlrpc | |
5 | ||
6 | ||
7 | setup(name='django-xmlrpc', | |
8 | version=django_xmlrpc.__version__, | |
9 | ||
10 | description='XML-RPC Server App for the Django framework.', | |
11 | long_description=open(os.path.join('README.rst')).read(), | |
12 | keywords='django, service, xmlrpc', | |
13 | ||
14 | author='Graham Binns', | |
15 | author_email='graham.binns@gmail.com', | |
16 | maintainer='Fantomas42', | |
17 | maintainer_email='fantomas42@gmail.com', | |
18 | url='https://github.com/Fantomas42/django-xmlrpc', | |
19 | ||
20 | packages=find_packages(), | |
21 | classifiers=[ | |
22 | 'Framework :: Django', | |
23 | 'Development Status :: 5 - Production/Stable', | |
24 | 'Environment :: Web Environment', | |
25 | 'Programming Language :: Python', | |
26 | 'Programming Language :: Python :: 3', | |
27 | 'Intended Audience :: Developers', | |
28 | 'Operating System :: OS Independent', | |
29 | 'Topic :: Software Development :: Libraries :: Python Modules'], | |
30 | ||
31 | license='New BSD License', | |
32 | include_package_data=True, | |
33 | zip_safe=False | |
34 | ) |