home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / yahoo / login.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  4.9 KB  |  130 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import base64
  5. import cookielib
  6. import logging
  7. import traceback
  8. import types
  9. import urllib2
  10. import util.net as util
  11. log = logging.getLogger('yahoo.login')
  12.  
  13. class YahooAuthException(Exception):
  14.     error_type = 'Unknown'
  15.     error_msg = None
  16.     known_codes = { }
  17.     
  18.     def __init__(self, resp_str):
  19.         Exception.__init__(self, resp_str)
  20.         
  21.         try:
  22.             code = self.code = resp_str.split()[0]
  23.         except Exception:
  24.             self.code = None
  25.  
  26.         self.error_msg = _error_messages.get(code)
  27.         if code in self.known_codes:
  28.             self.__class__ = self.known_codes[code]
  29.         
  30.  
  31.  
  32. _error_types = [
  33.     ('1212', 'Bad Password'),
  34.     ('1213', 'Security Lock'),
  35.     ('1221', 'Account Not Set Up'),
  36.     ('1235', 'Bad Username'),
  37.     ('1236', 'Rate Limit')]
  38. _error_messages = {
  39.     '1212': _('Bad Password'),
  40.     '1213': _('There is a security lock on your account. Log in to  http://my.yahoo.com and try again.'),
  41.     '1221': _('Account Not Set Up'),
  42.     '1235': _('Bad Username'),
  43.     '1236': _('Rate Limit') }
  44. for code, error_type in _error_types:
  45.     name = ''.join([
  46.         'Yahoo'] + error_type.split() + [
  47.         'Exception'])
  48.     klass = types.ClassType(name, (YahooAuthException,), dict(error_type = error_type))
  49.     globals()[name] = YahooAuthException.known_codes[code] = klass
  50.     del name
  51.     del klass
  52.     del code
  53.     del error_type
  54.  
  55.  
  56. def yahoo_v15_auth(challenge, password, username, jar = None):
  57.     jar = None if jar is not None else cookielib.CookieJar()
  58.     http_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar), *util.net.GetDefaultHandlers())
  59.     time = time
  60.     import time
  61.     now = int(time())
  62.     url_password = util.net.UrlQuery('https://login.yahoo.com/config/pwtoken_get', src = 'ymsgr', ts = str(now), login = username, passwd = password, chal = challenge)
  63.     resp = http_opener.open(url_password)
  64.     resp = resp.read()
  65.     log.info('Yahoo response starts: %r', resp[:100])
  66.     if not resp.startswith('0'):
  67.         raise YahooAuthException(resp)
  68.     resp.startswith('0')
  69.     token = resp.split('\r\n')[1].split('=')[1]
  70.     url2 = util.net.UrlQuery('https://login.yahoo.com/config/pwtoken_login', src = 'ymsgr', ts = str(now), token = token)
  71.     resp2 = http_opener.open(url2)
  72.     resp2 = resp2.read()
  73.     log.info('Yahoo response2 starts: %r', resp2[:100])
  74.     lines = resp2.split('\r\n')
  75.     crumb = lines[1].split('=')[1]
  76.     y = lines[2]
  77.     t = lines[3]
  78.     y = y[2:]
  79.     t = t[2:]
  80.     return (crumb, y, t, jar)
  81.  
  82.  
  83. def yahoo64(buffer):
  84.     return base64.b64encode(buffer, '._').replace('=', '-')
  85.  
  86. LOAD_BALANCERS = [
  87.     'http://vcs2.msg.yahoo.com/capacity',
  88.     'http://vcs1.msg.yahoo.com/capacity']
  89. HTTP_LOAD_BALANCERS = [
  90.     'http://httpvcs2.msg.yahoo.com/capacity',
  91.     'http://httpvcs1.msg.yahoo.com/capacity']
  92.  
  93. def get_load_balance_info(server):
  94.     data = util.net.wget(server)
  95.     site = data.split()
  96.     pairs = [ line.split('=') for line in site ]
  97.     d = dict(pairs)
  98.     return d['CS_IP_ADDRESS']
  99.  
  100.  
  101. def async_get_load_balance_info(server, callback = None):
  102.     asynchttp = asynchttp
  103.     import common
  104.     
  105.     def success(req, resp):
  106.         
  107.         try:
  108.             data = resp.read()
  109.             site = data.splitlines()
  110.             pairs = [ line.strip().split('=') for line in site ]
  111.             d = dict((lambda .0: for x, y in .0:
  112. (x.strip(), y.strip()))(pairs))
  113.             callback.success(d['CS_IP_ADDRESS'])
  114.         except Exception:
  115.             e = None
  116.             traceback.print_exc()
  117.             callback.error(e)
  118.  
  119.  
  120.     
  121.     def error(*a):
  122.         callback.error(None)
  123.  
  124.     
  125.     def timeout(*a):
  126.         callback.timeout(None)
  127.  
  128.     asynchttp.httpopen(server, success = success, error = error, timeout = timeout)
  129.  
  130.