annotate README.txt @ 30:a99009a7013c 0.3.1a

- Use generator with __getfile__ (uses much less memory) - Fixed security issue with __getfile__ - do not allow access to whole disk! - Handle exceptions in auth function - Fixed encrypting of no password - Changed README code examples
author Ben Croston <ben@croston.org>
date Thu, 05 Apr 2012 20:45:56 +0100
parents bea0c77734ca
children fdddfd434bbd
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
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
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
4
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
5 Example Usage (Server):
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 ::
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 import hashlib
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
10 from wsgiref import simple_server
17
Ben Croston <ben@croston.org>
parents: 16
diff changeset
11 from AuthRPC.server import AuthRPCApp
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
12
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
13 def myauth(username, password, useragent):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
14 return username == 'myuser' and \
24
d0b8c9edf4f5 Fixed error in README
Ben Croston <ben@croston.org>
parents: 22
diff changeset
15 password == hashlib.md5('secret'.encode()).hexdigest() and \
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
16 useragent == 'myprogram'
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
17
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
18 class api(object):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
19 def do_something(self, myvar):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
20 """Your code placed here"""
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
21 return 'Something', myvar
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
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
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
26
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
27 Example Usage (Client):
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
28
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
20
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
31 from AuthRPC.client import ServerProxy, BatchCall
28
bea0c77734ca Changed/renamed exceptions
Ben Croston <ben@croston.org>
parents: 26
diff changeset
32
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')
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
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
45 batch = BatchCall(client)
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
46 batch.do_something('call 1')
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
47 batch.do_something('call 2')
4b62687da58a Added batch requests
Ben Croston <ben@croston.org>
parents: 17
diff changeset
48 batch()
15
3c19ae16fc7a Renamed to AuthRPC
Ben Croston <ben@croston.org>
parents: 4
diff changeset
49