home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.5) import urllib2 import httplib from util import memoize from util.xml_tag import tag, post_xml from util.callbacks import callsback from logging import getLogger log = getLogger('yahoohttp') from traceback import print_exc def y_webrequest(url, data, cookies): headers = { 'Cookie': cookies['Y'] + '; ' + cookies['T'], 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5)', 'Cache-Control': 'no-cache' } req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) return response.read() _carriers = { } def get_carrier(yahoo, sms_number, callback = None): if sms_number in _carriers: return callback.success(_carriers[sms_number]) version = '8.1.0.209' intl = 'us' validate = tag('validate', intl = intl, version = version, qos = '0') validate.mobile_no['msisdn'] = sms_number validate._cdata = '\n' def on_response(validate): log.info('HTTP response to get_carrier:\n%s', validate._to_xml()) status = unicode(validate.mobile_no.status) log.info('<status> tag contents: %s', status) if status == 'Valid': carrier = str(validate.mobile_no.carrier) _carriers[sms_number] = carrier log.info('carrier for %s: %s', sms_number, carrier) return callback.success(carrier) elif status == 'Unknown': log.critical('unknown carrier for %s', sms_number) return callback.error() else: log.critical('unknown XML returned from mobile carrier lookup service') return callback.error() def on_error(validate): log.critical('could not connect to mobile carrier lookup web service') return callback.error() url = 'http://validate.msg.yahoo.com/mobileno?intl=%s&version=%s' % (intl, version) headers = { 'Cookie': yahoo.cookie_str, 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5)', 'Cache-Control': 'no-cache' } log.info('POSTing SMS carrier request to %s', url) xmlstr = validate._to_xml(self_closing = False, pretty = False) log.info(xmlstr) post_xml(url, xmlstr, success = on_response, error = on_error, **headers) success = '\n HTTP/1.1 200 OK\n Date: Fri, 04 May 2007 15:09:26 GMT\n P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"\n Content-Length: 140\n Connection: close\n Content-Type: text/html\n\n <validate>\n <mobile_no msisdn="17248406085">\n <status>Valid</status>\n <carrier>pcsms.us.verizon</carrier>\n </mobile_no>\n </validate>\n ' error = '\n HTTP/1.1 200 OK\n Date: Fri, 04 May 2007 15:12:19 GMT\n P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"\n Content-Length: 117\n Connection: close\n Content-Type: text/html\n\n <validate>\n <mobile_no msisdn="12">\n <status>Unknown</status>\n <carrier></carrier>\n </mobile_no>\n </validate>\n ' get_carrier = callsback(get_carrier) def send_sms(yahoo, sms_number, message, callback = None): try: if isinstance(message, unicode): message = message.encode('utf-8') sms_number = format_smsnumber(sms_number) def on_carrier(carrier): log.info('sending Yahoo SMS packet to %s on carrier %s', sms_number, carrier) me = yahoo.self_buddy if not me.remote_alias: pass yahoo.send('sms_message', 'available', [ 'frombuddy', me.name, 'sms_alias', me.name, 'to', sms_number, 'sms_carrier', carrier, 'message', message]) get_carrier(yahoo, sms_number, success = on_carrier, error = callback.error) except: print_exc() callback.success() send_sms = callsback(send_sms) def format_smsnumber(sms): if len(sms) == 10: return '1' + sms return sms if __name__ == '__main__': cookies = { 'Y': 'v=1&n=3lutd2l220eoo&l=a4l8dm0jj4hisqqv/o&p=m2l0e8v002000000&r=fr&lg=us&intl=us; path=/; domain=.yahoo.com', 'T': 'z=/V2OGB/bLPGB9ZlmrY27n5q&a=YAE&sk=DAAcD2qurh0ujr&d=YQFZQUUBb2sBWlcwLQF0aXABQldCb2lBAXp6AS9WMk9HQmdXQQ--; path=/; domain=.yahoo.com' } headers = { 'Cookie': '; '.join([ cookies['Y'], cookies['T']]), 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5)', 'Cache-Control': 'no-cache' } data = '<validate intl="us" version="8.1.0.209" qos="0"><mobile_no msisdn="17248406085"></mobile_no></validate>' conn = httplib.HTTPConnection('validate.msg.yahoo.com', 80) conn.set_debuglevel(10000) conn.request('POST', '/mobileno?intl=us&version=8.1.0.209', data, headers) resp = conn.getresponse() print resp.status, resp.reason if resp.status == 200: print resp.read()