home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- from contextlib import closing
- import urllib2
- import util
- import util.net as net
- import util.apitools as apitools
- import util.callbacks as callbacks
-
- class TrimApi(object):
- api_key = 'R36NaKwgl6sSnbUePimqMZNC25hTeD2QZ6EEdf7u7zddq6kD'
- BASE = 'http://api.tr.im/'
-
- def API_BASE(self):
- return net.httpjoin(self.BASE, 'api/')
-
- API_BASE = property(API_BASE)
-
- def picim_url(self, media):
- pass
-
- picim_url = apitools.apicall('data', name = 'picim_url.json', format = 'json')(picim_url)
-
- def get_response_handler(self, method_call, callback):
- if method_call.spec.format == 'json':
-
- def response_parser(data):
- import simplejson as json
- return json.loads(data)
-
- else:
-
- def response_parser(data):
- import lxml.etree as ET
- doc = ET.fromstring(data)
-
- def keyval(node):
- if node.text and node.text.strip():
- return (node.tag, node.text.strip())
- if node.getchildren():
- return (node.tag, dict(map(keyval, node.getchildren())))
- if node.attrib:
- return (node.tag, dict(node.attrib))
-
- print data
- res = dict((keyval(doc),)).get('trim', { })
- print res
- return res
-
-
- def response_handler(resp):
- closing(resp).__enter__()
-
- try:
- data = resp.read()
- finally:
- pass
-
- api_response = response_parser(data)
- callback.success(api_response)
-
- return response_handler
-
-
- def send_method(self, call, callback = None):
- url = net.UrlQuery(call.get_endpoint(self.API_BASE), api_key = self.api_key)
- req = urllib2.Request(url, dict((lambda .0: for name, arg in .0:
- (name, arg.value))(call.bound_args.items())))
- util.threaded(urllib2.urlopen)(req, callback = callback)
-
- send_method = callbacks.callsback(send_method)
-
-
- def main():
- tp = util.threadpool.ThreadPool(5)
- api = TrimApi()
- media = urllib2.urlopen('http://antwrp.gsfc.nasa.gov/apod/image/0904/aprMoon_tanga.jpg').read()
-
- def success(resp):
- print 'success'
- print resp
-
-
- def error(err):
- print 'ohnoes'
- print err
-
- api.picim_url(media, success = success, error = error)
- tp.joinAll()
-
- if __name__ == '__main__':
- import digsbysite
- main()
-
-