home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / imagehost / trim.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  3.6 KB  |  96 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from contextlib import closing
  5. import urllib2
  6. import util
  7. import util.net as net
  8. import util.apitools as apitools
  9. import util.callbacks as callbacks
  10.  
  11. class TrimApi(object):
  12.     api_key = 'R36NaKwgl6sSnbUePimqMZNC25hTeD2QZ6EEdf7u7zddq6kD'
  13.     BASE = 'http://api.tr.im/'
  14.     
  15.     def API_BASE(self):
  16.         return net.httpjoin(self.BASE, 'api/')
  17.  
  18.     API_BASE = property(API_BASE)
  19.     
  20.     def picim_url(self, media):
  21.         pass
  22.  
  23.     picim_url = apitools.apicall('data', name = 'picim_url.json', format = 'json')(picim_url)
  24.     
  25.     def get_response_handler(self, method_call, callback):
  26.         if method_call.spec.format == 'json':
  27.             
  28.             def response_parser(data):
  29.                 import simplejson as json
  30.                 return json.loads(data)
  31.  
  32.         else:
  33.             
  34.             def response_parser(data):
  35.                 import lxml.etree as ET
  36.                 doc = ET.fromstring(data)
  37.                 
  38.                 def keyval(node):
  39.                     if node.text and node.text.strip():
  40.                         return (node.tag, node.text.strip())
  41.                     if node.getchildren():
  42.                         return (node.tag, dict(map(keyval, node.getchildren())))
  43.                     if node.attrib:
  44.                         return (node.tag, dict(node.attrib))
  45.  
  46.                 print data
  47.                 res = dict((keyval(doc),)).get('trim', { })
  48.                 print res
  49.                 return res
  50.  
  51.         
  52.         def response_handler(resp):
  53.             closing(resp).__enter__()
  54.             
  55.             try:
  56.                 data = resp.read()
  57.             finally:
  58.                 pass
  59.  
  60.             api_response = response_parser(data)
  61.             callback.success(api_response)
  62.  
  63.         return response_handler
  64.  
  65.     
  66.     def send_method(self, call, callback = None):
  67.         url = net.UrlQuery(call.get_endpoint(self.API_BASE), api_key = self.api_key)
  68.         req = urllib2.Request(url, dict((lambda .0: for name, arg in .0:
  69. (name, arg.value))(call.bound_args.items())))
  70.         util.threaded(urllib2.urlopen)(req, callback = callback)
  71.  
  72.     send_method = callbacks.callsback(send_method)
  73.  
  74.  
  75. def main():
  76.     tp = util.threadpool.ThreadPool(5)
  77.     api = TrimApi()
  78.     media = urllib2.urlopen('http://antwrp.gsfc.nasa.gov/apod/image/0904/aprMoon_tanga.jpg').read()
  79.     
  80.     def success(resp):
  81.         print 'success'
  82.         print resp
  83.  
  84.     
  85.     def error(err):
  86.         print 'ohnoes'
  87.         print err
  88.  
  89.     api.picim_url(media, success = success, error = error)
  90.     tp.joinAll()
  91.  
  92. if __name__ == '__main__':
  93.     import digsbysite
  94.     main()
  95.  
  96.