Mercurial > hg > AuthRPC
annotate README.txt @ 32:fdddfd434bbd 0.3.2a
- Remove dependency on distribute
- Tidy up pypi package contents
author | Ben Croston <ben@croston.org> |
---|---|
date | Sat, 19 Oct 2013 21:23:45 +0100 |
parents | a99009a7013c |
children |
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 |
32
fdddfd434bbd
- Remove dependency on distribute
Ben Croston <ben@croston.org>
parents:
30
diff
changeset
|
3 This package depends on WebOb 1.2 (or above). This is automatically installed if you have an internet connection and use pip, 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 |