Exemple #1
0
 def post(self, env, callback=None):
     post_xml(self.POST_URL, env,
              callback=callback,
              Accept='*/*',
              SOAPAction=self.SOAP_ACT,
              ContentType='text/xml; charset=utf-8',
              **{'User-Agent':self.USER_AGENT})
Exemple #2
0
 def post(self, env, callback=None):
     post_xml(self.POST_URL,
              env,
              callback=callback,
              Accept='*/*',
              SOAPAction=self.SOAP_ACT,
              ContentType='text/xml; charset=utf-8',
              **{'User-Agent': self.USER_AGENT})
    def _get_profile(self, buddy, callback):
        request = xml_tag.tag("GetXmlFeed")

        ri = request.refreshInformation

        ri.cid = buddy.CID
        ri.storageAuthCache = ""
        ri.market = "%s-%s" % (hub.language.lower(), hub.country.upper())
        ri.brand = ""
        ri.maxElementCount = 15
        ri.maxCharacterCount = 200
        ri.maxImageCount = 6
        ri.applicationId = "Messenger Client 8.0"
        ri.updateAccessedTime = False

        yesterday = datetime.datetime.today() - datetime.timedelta(1)
        ri.spaceLastViewed = yesterday.isoformat()
        ri.profileLastViewed = yesterday.isoformat()
        ri.contactProfileLastViewed = yesterday.isoformat()

        ri.isActiveContact = False

        fs = ri.foreignStore
        fs.itemType = "Profile"
        fs.foreignId = "MyProfile"
        fs.lastChanged = yesterday.isoformat()
        fs.lastViewed = yesterday.isoformat()

        auth = xml_tag.tag("AuthTokenHeader")
        # auth.Token = self.ticket.encode('xml')
        token = str(self.tokens["spaces.live.com"].received.RequestedSecurityToken.BinarySecurityToken)
        assert token, token.received._to_xml()

        auth.Token = escape(token)
        auth.AuthPolicy = self.tokens["spaces.live.com"].policyref

        env = xml_tag.tag("envelope")  # soap_envelope("http://www.msn.com/webservices/spaces/v1/")

        env.Header(auth)
        env.Body(request)
        # del env._children[0]
        print env._to_xml(pretty=False)
        response = xml_tag.post_xml(
            "http://cid-%X.cc.services.spaces.live.com/contactcard/contactcardservice.asmx" % int(self.self_buddy.CID),
            env,
            success=lambda t: self.incoming_profile(t, buddy),
            error=lambda e: self.incoming_profile(e, buddy, True)
            # Cookie=token
        )
Exemple #4
0
    def _get_profile(self, buddy, callback):
        request = xml_tag.tag('GetXmlFeed')

        ri = request.refreshInformation

        ri.cid = buddy.CID
        ri.storageAuthCache = ''
        ri.market = '%s-%s' % (hub.language.lower(), hub.country.upper())
        ri.brand = ''
        ri.maxElementCount = 15
        ri.maxCharacterCount = 200
        ri.maxImageCount = 6
        ri.applicationId = 'Messenger Client 8.0'
        ri.updateAccessedTime = False

        yesterday = datetime.datetime.today() - datetime.timedelta(1)
        ri.spaceLastViewed = yesterday.isoformat()
        ri.profileLastViewed = yesterday.isoformat()
        ri.contactProfileLastViewed = yesterday.isoformat()

        ri.isActiveContact = False

        fs = ri.foreignStore
        fs.itemType = 'Profile'
        fs.foreignId = 'MyProfile'
        fs.lastChanged = yesterday.isoformat()
        fs.lastViewed = yesterday.isoformat()

        auth = xml_tag.tag('AuthTokenHeader')
        #auth.Token = self.ticket.encode('xml')
        token = str(self.tokens['spaces.live.com'].received.RequestedSecurityToken.BinarySecurityToken)
        assert token, token.received._to_xml()

        auth.Token = escape(token)
        auth.AuthPolicy = self.tokens['spaces.live.com'].policyref

        env = xml_tag.tag("envelope") #soap_envelope("http://www.msn.com/webservices/spaces/v1/")

        env.Header(auth)
        env.Body(request)
        #del env._children[0]
        print env._to_xml(pretty=False)
        response = xml_tag.post_xml("http://cid-%X.cc.services.spaces.live.com/contactcard/contactcardservice.asmx" % int(self.self_buddy.CID),
                                 env,
                                 success=lambda t: self.incoming_profile(t, buddy),
                                 error  =lambda e: self.incoming_profile(e, buddy, True)
                                 #Cookie=token
                                 )
Exemple #5
0
def get_carrier(yahoo, sms_number, callback=None):
    """
    Uses a Yahoo webservice to find a carrier string (like 'pcsms.us.version') for
    a mobile phone number.

    Requires Yahoo web cookies (in the yahoo.cookie_str property).

    These carrier strings can be used to send SMS messages through the Yahoo servers
    (see the send_sms function below).
    """

    # has this number's carrier already been looked up?
    global _carriers
    if sms_number in _carriers:
        return callback.success(_carriers[sms_number])

    # options for the request
    version = "8.1.0.209"
    intl = "us"

    # build request XML
    validate = tag("validate", intl=intl, version=version, qos="0")
    validate.mobile_no["msisdn"] = sms_number
    validate._cdata = "\n"

    # setup callbacks
    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":
            # got a valid carrier string; memoize it and return to the success callback.
            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()

    # setup HTTP POST
    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
    post_xml(url, xmlstr, success=on_response, error=on_error, **headers)
    """
    POST /mobileno?intl=us&version=8.1.0.209 HTTP/1.1
    Cookie: T=z=Vr0OGBVxJPGB9u7bOG1linxMjI2BjUyNjA2NU81NzA-&a=QAE&sk=DAAGhaQDlIYJTS&d=c2wBTlRVeEFUSTFNVGN4TWpneU1EYy0BYQFRQUUBenoBVnIwT0dCZ1dBAXRpcAFCV0JvaUE-; path=/; domain=.yahoo.com; Y=v=1&n=50s9nph28dhu3&l=386i1oqs/o&p=m2g0e3d012000000&r=g6&lg=us&intl=us&np=1; path=/; domain=.yahoo.com ;B=a6d0ooh2qsp2r&b=3&s=ko
    User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)
    Host: validate.msg.yahoo.com
    Content-Length: 105
    Cache-Control: no-cache

    <validate intl="us" version="8.1.0.209" qos="0"><mobile_no msisdn="17248406085"></mobile_no>
    </validate>
    """

    success = """
    HTTP/1.1 200 OK
    Date: Fri, 04 May 2007 15:09:26 GMT
    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"
    Content-Length: 140
    Connection: close
    Content-Type: text/html

    <validate>
      <mobile_no msisdn="17248406085">
        <status>Valid</status>
        <carrier>pcsms.us.verizon</carrier>
      </mobile_no>
    </validate>
    """

    error = """
Exemple #6
0
def get_carrier(yahoo, sms_number, callback = None):
    '''
    Uses a Yahoo webservice to find a carrier string (like 'pcsms.us.version') for
    a mobile phone number.

    Requires Yahoo web cookies (in the yahoo.cookie_str property).

    These carrier strings can be used to send SMS messages through the Yahoo servers
    (see the send_sms function below).
    '''

    # has this number's carrier already been looked up?
    global _carriers
    if sms_number in _carriers:
        return callback.success(_carriers[sms_number])

    # options for the request
    version = '8.1.0.209'
    intl    = 'us'

    # build request XML
    validate = tag('validate', intl = intl, version = version, qos = '0')
    validate.mobile_no['msisdn'] = sms_number
    validate._cdata = '\n'

    # setup callbacks
    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':
            # got a valid carrier string; memoize it and return to the success callback.
            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()

    # setup HTTP POST
    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
    post_xml(url, xmlstr, success = on_response, error = on_error, **headers)
    '''
    POST /mobileno?intl=us&version=8.1.0.209 HTTP/1.1
    Cookie: T=z=Vr0OGBVxJPGB9u7bOG1linxMjI2BjUyNjA2NU81NzA-&a=QAE&sk=DAAGhaQDlIYJTS&d=c2wBTlRVeEFUSTFNVGN4TWpneU1EYy0BYQFRQUUBenoBVnIwT0dCZ1dBAXRpcAFCV0JvaUE-; path=/; domain=.yahoo.com; Y=v=1&n=50s9nph28dhu3&l=386i1oqs/o&p=m2g0e3d012000000&r=g6&lg=us&intl=us&np=1; path=/; domain=.yahoo.com ;B=a6d0ooh2qsp2r&b=3&s=ko
    User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)
    Host: validate.msg.yahoo.com
    Content-Length: 105
    Cache-Control: no-cache

    <validate intl="us" version="8.1.0.209" qos="0"><mobile_no msisdn="17248406085"></mobile_no>
    </validate>
    '''

    success = \
    '''
    HTTP/1.1 200 OK
    Date: Fri, 04 May 2007 15:09:26 GMT
    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"
    Content-Length: 140
    Connection: close
    Content-Type: text/html

    <validate>
      <mobile_no msisdn="17248406085">
        <status>Valid</status>
        <carrier>pcsms.us.verizon</carrier>
      </mobile_no>
    </validate>
    '''

    error = \
    '''