home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / digsby / web.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  2.5 KB  |  72 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from util import threaded, UrlQuery
  5. from hashlib import sha256
  6. import traceback
  7. import urllib2
  8. from logging import getLogger
  9. log = getLogger('digsby.web')
  10. ACCOUNT_URL = 'https://accounts.digsby.com/login.php'
  11.  
  12. class DigsbyHttpError(Exception):
  13.     pass
  14.  
  15.  
  16. class DigsbyHttp(object):
  17.     
  18.     def __init__(self, username, password, url = ACCOUNT_URL):
  19.         self.username = username
  20.         self.password = sha256(password).hexdigest()
  21.         self.url = url
  22.  
  23.     
  24.     def __repr__(self):
  25.         return '<%s to %s>' % (self.__class__.__name__, self.url)
  26.  
  27.     
  28.     def _urlopen(self, **params):
  29.         resp = digsby_webget_no_thread(self.url, user = self.username, key = self.password, **params)
  30.         if resp == 'ERR':
  31.             raise DigsbyHttpError('server indicated error: %r' % resp)
  32.         
  33.         return resp
  34.  
  35.     GET = _urlopen
  36.  
  37.  
  38. def digsby_acct_http(username, password, **params):
  39.     return digsby_webget_no_thread(ACCOUNT_URL, user = username, key = sha256(password).hexdigest(), **params)
  40.  
  41.  
  42. def digsby_webget(url, **params):
  43.     return digsby_webget_no_thread(url, **params)
  44.  
  45. digsby_webget = threaded(digsby_webget)
  46.  
  47. def digsby_webget_no_thread(url, **params):
  48.     log.info('GETting url %s', url)
  49.     url = UrlQuery(url, **params)
  50.     log.info_s('full query is %s', url)
  51.     req = urllib2.Request(str(url))
  52.     req.add_header('Cache-Control', 'no-cache')
  53.     req.add_header('User-Agent', 'Digsby')
  54.     response = None
  55.     
  56.     try:
  57.         response = urllib2.urlopen(req)
  58.         res = response.read()
  59.     except Exception:
  60.         e = None
  61.         log.error('Error opening %r: %r', url, e)
  62.         traceback.print_exc()
  63.         return None
  64.     finally:
  65.         if response is not None:
  66.             response.close()
  67.         
  68.  
  69.     log.info('response: %r', res)
  70.     return res
  71.  
  72.