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 ImgurApi(object):
- api_key = '086876da7b51c619ffddb16eaca51400'
- BASE = 'http://imgur.com/'
-
- def API_BASE(self):
- return net.httpjoin(self.BASE, 'api/')
-
- API_BASE = property(API_BASE)
-
- def upload(self, image):
- pass
-
- upload = apitools.apicall('data', name = 'upload', format = 'json')(upload)
-
- def get_response_handler(self, method_call, callback):
- if method_call.spec.format == 'json':
-
- def response_parser(data):
- import simplejson as json
- return {
- 'url': json.loads(data)['rsp']['image']['imgur_page'] }
-
- 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('rsp', { })
- print res
- return res
-
-
- def response_handler(resp):
-
- try:
- closing(resp).__enter__()
-
- try:
- data = resp.read()
- finally:
- pass
-
- api_response = response_parser(data)
- except Exception:
- e = None
- return callback.error(e)
-
- callback.success(api_response)
-
- return response_handler
-
-
- def send_method(self, call, callback = None):
- url = net.UrlQuery(call.get_endpoint(self.API_BASE) + '.' + call.spec.format)
- params = dict((lambda .0: for name, arg in .0:
- (name, arg.value))(call.bound_args.items()))
- params['key'] = self.api_key
- req = urllib2.Request(url, params)
- util.threaded(urllib2.urlopen)(req, callback = callback)
-
- send_method = callbacks.callsback(send_method)
-
-