annotate README.txt @ 21:6df12f09f4f4

Fixed batch test
author Ben Croston <ben@croston.org>
date Sun, 01 Jan 2012 11:42:25 +0000
parents 4b62687da58a
children 9459d63c1558
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
1 This package provides a service based on JSONRPC with some small additions to the standard in order to enable authenticated requests. The WSGI specification is used for data communication. The package is broken down into two halves - a client and a server. For security, the server is best run over HTTPS, although this is not enforced.
4
ad5a8748afcf Add test framework
Ben Croston <ben@croston.org>
parents: 0
diff changeset
2
ad5a8748afcf Add test framework
Ben Croston <ben@croston.org>
parents: 0
diff changeset
3 The server depends on WebOb 1.0.0 and above. This is automatically installed if you have an internet connection, otherwise download and install from http://pypi.python.org/pypi/WebOb
ad5a8748afcf Add test framework
Ben Croston <ben@croston.org>
parents: 0
diff changeset
4
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
5 If you install under Python 3, only the client package is available at the moment, until WebOb has been ported to python 3.
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
6
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
7 Example Usage (Server):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
8
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
9 ::
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
10
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
11 import hashlib
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
12 from wsgiref import simple_server
17
Ben Croston <ben@croston.org>
parents: 16
diff changeset
13 from AuthRPC.server import AuthRPCApp
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
14
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
15 def myauth(username, password, useragent):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
16 return username == 'myuser' and \
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
17 password == hashlib.md5('secret').hexdigest() and \
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
18 useragent == 'myprogram'
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
19
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
20 class api(object):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
21 def do_something(self, myvar):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
22 """Your code placed here"""
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
23 return 'Something', myvar
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
24
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
25 application = AuthRPCApp(api(), auth=myauth)
16
686b998428de Update typo in README
Ben Croston <ben@croston.org>
parents: 15
diff changeset
26 simple_server.make_server('localhost', 1234, application)
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
27
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
28 Example Usage (Client):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
29
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
30 ::
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
31
20
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
32 from AuthRPC.client import ServerProxy, BatchCall
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
33 client = ServerProxy('http://localhost:1234/',
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
34 username='myuser',
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
35 password='secret',
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
36 user_agent='myprogram')
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
37 retval = client.do_something('test')
20
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
38 batch = BatchCall(client)
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
39 batch.do_something('call 1')
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
40 batch.do_something('call 2')
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
41 batch()
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
42