Ran into this problem on Friday at a client site and just couldn't find a Python library that did everything I needed wrt providing login to TurboGears and properly uploading a file to a controller in the TurboGears application. Bothered me that there was no easy way to do this (seems like it should be trivial), so I just coded this little library up. Here's a sample script that uploads a "file" to a TurboGears controller:
from restclient import *
if __name__ == "__main__":
r = JSONClient(
'http://localhost:8081', user_name='user', password='password', login='.' ,
result = r(
data = ( 'test.jpg', '\000'*30 ),
mime_type = 'image/jpeg',
pprint.pprint( result )
with the controller looking like this:
@expose( format='json' )
def upload_test( self, data, mime_type):
"""A little test upload..."""
return dict( result=True )
Which isn't a huge change from the interface of the underlying library by Michael Foord, it just parses the named arguments into separate fields/files and does the TurboGears-specific login. As it turns out, the client needs something different, so oh well, wasted time. Still, maybe it will be useful to someone some day. Can't say it's been even lightly tested, so caveat abandonned software-or.