def init_vars(self): self.ClientCounter = 0 #I kid you not, an 8 digit integer string representation encoded in hex # from the last 8 digits of the string representation of the lower word # of GetSystemTimeAsFileTime. Random seems just as good, since that value # in units of 100 nanoseconds, 8 digits will cycle every 10 seconds #http://forum.sharpdressedcodes.com/index.php?showtopic=589 #wtfinterns? from random import randint self.secret = '%08d' % randint(0, int('9' * 8)) self.Secret = (self.secret).encode('hex') self.jar = cookielib.CookieJar() self.client_http_opener = CookieJarHTTPMaster(jar=self.jar) self.server_http_opener = CookieJarHTTPMaster(jar=self.jar)
def yahoo_v15_auth(self, challenge, password, username, jar=None, callback=None): jar = jar if jar is not None else cookielib.CookieJar() http_opener = CookieJarHTTPMaster(jar=jar) from time import time now = int(time()) def bar(req, resp): resp = resp.read() log.info('Yahoo response starts: %r', resp[:100]) if not resp.startswith('0'): return callback.error(YahooAuthException(resp)) 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) http_opener.open( url2, success=lambda req, resp: self.cookie_crumbs_success( resp, jar, callback=callback), error=callback.error) url_password = util.net.UrlQuery( "https://login.yahoo.com/config/pwtoken_get", src='ymsgr', ts=str(now), login=username, passwd=password, chal=challenge) http_opener.open(url_password, success=bar, error=callback.error)