Mercurial > hg > AuthRPC
annotate README.txt @ 31:183a9b11c78f
Added tag 0.3.1a for changeset a99009a7013c
author | Ben Croston <ben@croston.org> |
---|---|
date | Thu, 05 Apr 2012 20:46:44 +0100 |
parents | a99009a7013c |
children | fdddfd434bbd |
rev | line source |
---|---|
15 | 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 | 2 |
22
9459d63c1558
Added full support for Python 3
Ben Croston <ben@croston.org>
parents:
20
diff
changeset
|
3 This package depends on WebOb 1.2 (or above). This is automatically installed if you have an internet connection, otherwise download and install from http://pypi.python.org/pypi/WebOb |
15 | 4 |
5 Example Usage (Server): | |
6 | |
7 :: | |
8 | |
9 import hashlib | |
10 from wsgiref import simple_server | |
17 | 11 from AuthRPC.server import AuthRPCApp |
15 | 12 |
13 def myauth(username, password, useragent): | |
14 return username == 'myuser' and \ | |
24 | 15 password == hashlib.md5('secret'.encode()).hexdigest() and \ |
15 | 16 useragent == 'myprogram' |
17 | |
18 class api(object): | |
19 def do_something(self, myvar): | |
20 """Your code placed here""" | |
21 return 'Something', myvar | |
22 | |
30
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
23 application = AuthRPCApp(api(), auth=myauth, filepath='/home/myapp/datadir') |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
24 server = simple_server.make_server('localhost', 1234, application) |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
25 server.serve_forever() |
15 | 26 |
27 Example Usage (Client): | |
28 | |
29 :: | |
30 | |
20 | 31 from AuthRPC.client import ServerProxy, BatchCall |
28 | 32 |
15 | 33 client = ServerProxy('http://localhost:1234/', |
34 username='myuser', | |
35 password='secret', | |
36 user_agent='myprogram') | |
37 retval = client.do_something('test') | |
30
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
38 |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
39 # get a file and save local copy |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
40 file_contents_generator = client.__getfile__('myfile.pdf') |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
41 with open('myfile_downloaded.pdf', 'wb') as f: |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
42 for data in file_contents_generator: |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
43 f.write(data) |
a99009a7013c
- Use generator with __getfile__ (uses much less memory)
Ben Croston <ben@croston.org>
parents:
28
diff
changeset
|
44 |
20 | 45 batch = BatchCall(client) |
46 batch.do_something('call 1') | |
47 batch.do_something('call 2') | |
48 batch() | |
15 | 49 |