home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- import base64
- import cookielib
- import logging
- import traceback
- import types
- import urllib2
- import util.net as util
- log = logging.getLogger('yahoo.login')
-
- class YahooAuthException(Exception):
- error_type = 'Unknown'
- error_msg = None
- known_codes = { }
-
- def __init__(self, resp_str):
- Exception.__init__(self, resp_str)
-
- try:
- code = self.code = resp_str.split()[0]
- except Exception:
- self.code = None
-
- self.error_msg = _error_messages.get(code)
- if code in self.known_codes:
- self.__class__ = self.known_codes[code]
-
-
-
- _error_types = [
- ('1212', 'Bad Password'),
- ('1213', 'Security Lock'),
- ('1221', 'Account Not Set Up'),
- ('1235', 'Bad Username'),
- ('1236', 'Rate Limit')]
- _error_messages = {
- '1212': _('Bad Password'),
- '1213': _('There is a security lock on your account. Log in to http://my.yahoo.com and try again.'),
- '1221': _('Account Not Set Up'),
- '1235': _('Bad Username'),
- '1236': _('Rate Limit') }
- for code, error_type in _error_types:
- name = ''.join([
- 'Yahoo'] + error_type.split() + [
- 'Exception'])
- klass = types.ClassType(name, (YahooAuthException,), dict(error_type = error_type))
- globals()[name] = YahooAuthException.known_codes[code] = klass
- del name
- del klass
- del code
- del error_type
-
-
- def yahoo_v15_auth(challenge, password, username, jar = None):
- jar = None if jar is not None else cookielib.CookieJar()
- http_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar), *util.net.GetDefaultHandlers())
- time = time
- import time
- now = int(time())
- url_password = util.net.UrlQuery('https://login.yahoo.com/config/pwtoken_get', src = 'ymsgr', ts = str(now), login = username, passwd = password, chal = challenge)
- resp = http_opener.open(url_password)
- resp = resp.read()
- log.info('Yahoo response starts: %r', resp[:100])
- if not resp.startswith('0'):
- raise YahooAuthException(resp)
- resp.startswith('0')
- token = resp.split('\r\n')[1].split('=')[1]
- url2 = util.net.UrlQuery('https://login.yahoo.com/config/pwtoken_login', src = 'ymsgr', ts = str(now), token = token)
- resp2 = http_opener.open(url2)
- resp2 = resp2.read()
- log.info('Yahoo response2 starts: %r', resp2[:100])
- lines = resp2.split('\r\n')
- crumb = lines[1].split('=')[1]
- y = lines[2]
- t = lines[3]
- y = y[2:]
- t = t[2:]
- return (crumb, y, t, jar)
-
-
- def yahoo64(buffer):
- return base64.b64encode(buffer, '._').replace('=', '-')
-
- LOAD_BALANCERS = [
- 'http://vcs2.msg.yahoo.com/capacity',
- 'http://vcs1.msg.yahoo.com/capacity']
- HTTP_LOAD_BALANCERS = [
- 'http://httpvcs2.msg.yahoo.com/capacity',
- 'http://httpvcs1.msg.yahoo.com/capacity']
-
- def get_load_balance_info(server):
- data = util.net.wget(server)
- site = data.split()
- pairs = [ line.split('=') for line in site ]
- d = dict(pairs)
- return d['CS_IP_ADDRESS']
-
-
- def async_get_load_balance_info(server, callback = None):
- asynchttp = asynchttp
- import common
-
- def success(req, resp):
-
- try:
- data = resp.read()
- site = data.splitlines()
- pairs = [ line.strip().split('=') for line in site ]
- d = dict((lambda .0: for x, y in .0:
- (x.strip(), y.strip()))(pairs))
- callback.success(d['CS_IP_ADDRESS'])
- except Exception:
- e = None
- traceback.print_exc()
- callback.error(e)
-
-
-
- def error(*a):
- callback.error(None)
-
-
- def timeout(*a):
- callback.timeout(None)
-
- asynchttp.httpopen(server, success = success, error = error, timeout = timeout)
-
-