alanmcintyre/btce-api — pull request #25 by zku (2013-11-29 17:40:05+00:00)
Title: Allow subtypes for btceapi.keyhandler.KeyHandler

This would also allow subtyped btceapi.keyhandler.KeyHandler instances. An example of a subtyped KeyHandler class might be one that defines a close() function so the KeyHandler can be used with the 'with' syntax.

```
#!/usr/bin/env python

from contextlib import closing
import btceapi
import mybtceconfig

class ClosableKeyHandler(btceapi.KeyHandler):
def __init__(self, filename):
super(ClosableKeyHandler, self).__init__(filename, True)

def close(self):
self.save(self.filename)

with closing(ClosableKeyHandler(mybtceconfig.keyFile())) as keyHandler:
tapi = btceapi.TradeAPI(mybtceconfig.key(), keyHandler)
info = tapi.getInfo()
print 'Current balance (USD): %s' % info.balance_usd
```