示例#1
1
    def handle_webchallenges(self, msg, body):
        challenge_info = msim_util.obj_list_from_msdict(body)

        self.api.got_webchallenge_info(challenge_info)
示例#2
0
    def handle_status(self, msg):
        '''
        buddy status message
        example: '\\bm\\100\\f\\20075341\\fg\\0\\msg\\|s|0|ss|Offline\\final\\'
        '''

        body = msim_util.pipe_list(msg.get('msg', ''))
        body.pop(0)
        body = msim_util.pipe_dict(body)

        source_id = msg.get('f')
        status_int = int(body.get('s'))
        status_message = body.get('ss')  # status message?

        # other keys:
        # ('ls', '')   - ??
        # ('ip', '170402424')   - ip address?
        # ('p', '0')   - ??
        # ('caps', '0')   - capabilities?
        # ('ts', '1250263988')   - timestamp

        status = {
                  0: 'offline',
                  1: 'available',
                  2: 'idle',
                  5: 'away',
                  }.get(status_int, 'available')

        self.api.got_buddy_presence(source_id, status, status_message)

        log.info('got bm_100 message: %r', body)
示例#3
0
    def handle_status(self, msg):
        '''
        buddy status message
        example: '\\bm\\100\\f\\20075341\\fg\\0\\msg\\|s|0|ss|Offline\\final\\'
        '''

        body = msim_util.pipe_list(msg.get('msg', ''))
        body.pop(0)
        body = msim_util.pipe_dict(body)

        source_id = msg.get('f')
        status_int = int(body.get('s'))
        status_message = body.get('ss')  # status message?

        # other keys:
        # ('ls', '')   - ??
        # ('ip', '170402424')   - ip address?
        # ('p', '0')   - ??
        # ('caps', '0')   - capabilities?
        # ('ts', '1250263988')   - timestamp

        status = {
            0: 'offline',
            1: 'available',
            2: 'idle',
            5: 'away',
        }.get(status_int, 'available')

        self.api.got_buddy_presence(source_id, status, status_message)

        log.info('got bm_100 message: %r', body)
示例#4
0
    def user_search(self, username, email, callback=None):
        if username is email is None:
            return

        if username is None:
            body = msim_util.msdict(Email=email)
        elif email is None:
            body = msim_util.msdict(UserName=username)

        self.send_msg(PersistMessage(self, 5, 7).Get(body=body),
                      use_rid=True, callback=callback)
示例#5
0
    def user_search(self, username, email, callback=None):
        if username is email is None:
            return

        if username is None:
            body = msim_util.msdict(Email=email)
        elif email is None:
            body = msim_util.msdict(UserName=username)

        self.send_msg(PersistMessage(self, 5, 7).Get(body=body),
                      use_rid=True,
                      callback=callback)
示例#6
0
    def handle_group_list(self, msg, body):
        groups = msim_util.obj_list_from_msdict(body)

        for group in groups:
            self.api.got_group(group)

        self.api.got_groups(groups)
示例#7
0
    def set_group_details(self,
                          infodict=None,
                          id=None,
                          name=None,
                          flag=None,
                          position=None,
                          callback=None):
        if infodict is None:
            infodict = {}
        else:
            infodict = dict(**infodict)

        if id is not None:
            infodict['GroupID'] = str(id)

        if name is not None:
            infodict['GroupName'] = str(name)

        if flag is not None:
            infodict['GroupFlag'] = str(flag)

        if position is not None:
            infodict['Position'] = str(position)

        self.send_msg(PersistMessage(
            self, 2, 16).Set(body=msim_util.msdict(**infodict)),
                      use_rid=True,
                      callback=callback)
示例#8
0
    def handle_group_list(self, msg, body):
        groups = msim_util.obj_list_from_msdict(body)

        for group in groups:
            self.api.got_group(group)

        self.api.got_groups(groups)
示例#9
0
    def handle_im(self, msg):

        sender_id = msg.get('f')
        msg_text = msg.get('msg')
        gid = msg.get('gid')

        if gid is not None:
            msg_type = 'group'
        else:
            msg_type = self.im_type(msg_text)

        if msg_type == 'zap':
            zap_id = int(msg_text[len(self.zap_id_str):])
            self.api.got_zap(sender_id, self.zap_strings[zap_id])

        elif msg_type == 'typing':
            self.api.got_typing(sender_id, {
                '%typing%': True,
                '%stoptyping%': False
            }.get(msg_text, False))

        elif msg_type == 'im':
            self.api.got_im(sender_id, msim_util.minihtml_to_html(msg_text))

        elif msg_type == 'group':
            source_id = sender_id
            group_id = gid
            actor_id = msg.get('aid')

            self.api.got_groupmsg(source_id, group_id, actor_id, msg_text)

        else:
            log.info('unknown IM type: %r', msg)
示例#10
0
    def handle_im(self, msg):

        sender_id = msg.get('f')
        msg_text = msg.get('msg')
        gid = msg.get('gid')

        if gid is not None:
            msg_type = 'group'
        else:
            msg_type = self.im_type(msg_text)

        if msg_type == 'zap':
            zap_id = int(msg_text[len(self.zap_id_str):])
            self.api.got_zap(sender_id, self.zap_strings[zap_id])

        elif msg_type == 'typing':
            self.api.got_typing(sender_id, {'%typing%': True, '%stoptyping%': False}.get(msg_text, False))

        elif msg_type == 'im':
            self.api.got_im(sender_id, msim_util.minihtml_to_html(msg_text))

        elif msg_type == 'group':
            source_id = sender_id
            group_id = gid
            actor_id = msg.get('aid')

            self.api.got_groupmsg(source_id, group_id, actor_id, msg_text)

        else:
            log.info('unknown IM type: %r', msg)
示例#11
0
    def edit_privacy_list(
        self,
        add_to_block=None,
        add_to_allow=None,
        remove_from_block=None,
        remove_from_allow=None,
        presence_vis=None,
        contact_vis=None,
    ):

        idlist = msim_util.pipe_list()

        for (c, vis) in (('w', presence_vis), ('c', contact_vis)):
            if vis is None:
                continue

            if vis == 'anyone':
                idlist.append(c + '0')
            elif vis == 'list':
                idlist.append(c + '1')
            elif vis in (0, 1):
                idlist.append(c + str(vis))
            else:
                raise Exception(
                    'Invalid value for %r visibility: %r. valid values are ("anyone", "list", 0, 1).',
                    c, vis)

        for (sym, val) in (('b+', add_to_block), ('a+', add_to_allow),
                           ('b-', remove_from_block), ('a-',
                                                       remove_from_allow)):
            if val is None:
                continue

            idlist.append(sym)
            if val == 'all':
                idlist.append('*')
            else:
                idlist.extend((str(x) for x in val))

        msg = msim_util.msmsg((
            ('blocklist', ''),
            ('sesskey', self.sesskey),
            ('idlist', str(idlist)),
        ))

        self.send_msg(msg)
示例#12
0
def myspace_auth_challenge_response(username, password, nonce):
    ips = net.myips('')

    numips = len(ips)
    ips = [ord(c) for c in ''.join(ips)]

    import struct
    extra = struct.pack('!I', numips)
    extra += ''.join(chr(x) for x in ips)

    return msim_util.crypt(nonce, password, username + '\0' + extra)
示例#13
0
def myspace_auth_challenge_response(username, password, nonce):
    ips = net.myips('')

    numips = len(ips)
    ips = [ord(c) for c in ''.join(ips)]

    import struct
    extra = struct.pack('!I', numips)
    extra += ''.join(chr(x) for x in ips)

    return msim_util.crypt(nonce, password, username + '\0' + extra)
示例#14
0
    def edit_privacy_list(self,
                          add_to_block=None,
                          add_to_allow=None,
                          remove_from_block=None,
                          remove_from_allow=None,
                          presence_vis=None,
                          contact_vis=None,
                          ):

        idlist = msim_util.pipe_list()

        for (c, vis) in (('w', presence_vis), ('c', contact_vis)):
            if vis is None:
                continue

            if vis == 'anyone':
                idlist.append(c + '0')
            elif vis == 'list':
                idlist.append(c + '1')
            elif vis in (0, 1):
                idlist.append(c + str(vis))
            else:
                raise Exception('Invalid value for %r visibility: %r. valid values are ("anyone", "list", 0, 1).', c, vis)

        for (sym, val) in (('b+', add_to_block), ('a+', add_to_allow), ('b-', remove_from_block), ('a-', remove_from_allow)):
            if val is None:
                continue

            idlist.append(sym)
            if val == 'all':
                idlist.append('*')
            else:
                idlist.extend((str(x) for x in val))

        msg = msim_util.msmsg((
            ('blocklist', ''),
            ('sesskey', self.sesskey),
            ('idlist', str(idlist)),
        ))

        self.send_msg(msg)
示例#15
0
 def _set_status(self, status, status_string=None, locstring=None):
     log.info_s('_set_status(%r, %r, %r)', status, status_string, locstring)
     if status_string is None:
         status_string = getattr(self, '_status_string', '')
     if locstring is None:
         locstring = getattr(self, '_loc_string', '')
     self._status = status
     self._status_string = status_string
     self._loc_string = locstring
     if status is None:
         log.info('got None for _set_status')
         return
     self.api.set_status(msimutil.status_to_int(status), status_string, locstring)
示例#16
0
 def _set_status(self, status, status_string=None, locstring=None):
     log.info_s('_set_status(%r, %r, %r)', status, status_string, locstring)
     if status_string is None:
         status_string = getattr(self, '_status_string', '')
     if locstring is None:
         locstring = getattr(self, '_loc_string', '')
     self._status = status
     self._status_string = status_string
     self._loc_string = locstring
     if status is None:
         log.info('got None for _set_status')
         return
     self.api.set_status(msimutil.status_to_int(status), status_string,
                         locstring)
示例#17
0
    def send_im(self, who, message, callback=None):
        _message, message = message, msim_util.escape(message)

        msg = msmsg((
            ('bm', BmMessage.Type.InstantMessage),
            ('sesskey', self.sesskey),
            ('t', who),
            ('cv', self.CLIENTVER),
            ('msg', message),
        ))
        try:
            self.send_msg(msg)
        except Exception, e:
            callback.error(e)
            raise
示例#18
0
    def send_im(self, who, message, callback=None):
        _message, message = message, msim_util.escape(message)

        msg = msmsg((
            ('bm',        BmMessage.Type.InstantMessage),
            ('sesskey',   self.sesskey),
            ('t',         who),
            ('cv',        self.CLIENTVER),
            ('msg',       message),
        ))
        try:
            self.send_msg(msg)
        except Exception, e:
            callback.error(e)
            raise
示例#19
0
    def handle_im_buddylist(self, msg, body):
        '''
        list of buddies
        '''
        buddies = msim_util.obj_list_from_msdict(body)

        log.info('got %r buddies!', len(buddies))

        for i, buddy in enumerate(buddies):
            id = buddy.get('ContactID', buddy.get('UserID'))
            if id is None:
                log.error('This info has no ID! %r', buddy)
                log.info('buddy #%r skipped (info = %r)', i, buddy)
                continue

            self.api.got_buddy(id, buddy)

        self.api.got_buddies(buddies)
示例#20
0
    def handle_im_buddylist(self, msg, body):
        '''
        list of buddies
        '''
        buddies = msim_util.obj_list_from_msdict(body)

        log.info('got %r buddies!', len(buddies))

        for i, buddy in enumerate(buddies):
            id = buddy.get('ContactID', buddy.get('UserID'))
            if id is None:
                log.error('This info has no ID! %r', buddy)
                log.info('buddy #%r skipped (info = %r)', i, buddy)
                continue

            self.api.got_buddy(id, buddy)

        self.api.got_buddies(buddies)
示例#21
0
    def set_group_details(self, infodict=None, id=None, name=None, flag=None, position=None, callback=None):
        if infodict is None:
            infodict = {}
        else:
            infodict = dict(**infodict)

        if id is not None:
            infodict['GroupID'] = str(id)

        if name is not None:
            infodict['GroupName'] = str(name)

        if flag is not None:
            infodict['GroupFlag'] = str(flag)

        if position is not None:
            infodict['Position'] = str(position)

        self.send_msg(PersistMessage(self, 2, 16).Set(body=msim_util.msdict(**infodict)),
                      use_rid=True, callback=callback)
示例#22
0
 def getURL(self, s, userid=None, pop=True):
     '''
     possible values of s include:
         friendmoods
         viewbirthdays
         home
     '''
     if userid is None:
         try:
             userid = self.api.userid
         except AttributeError:
             return 'http://www.myspace.com'
     chl = self.next_chl(pop)
     if chl is None:
         return 'http://www.myspace.com'
     n = msimutil.roflcopter(chl.key, self.api.sesskey, self.api.userid)
     return net.UrlQuery('http://home.myspace.com/Modules/IM/Pages/UrlRedirector.aspx',
                         challenge='%s-%s-%s' % (n, self.api.userid, self.api.sesskey),
                         response=str(self.make_chl_response(chl.data)),
                         target=s,
                         targetid=userid)
示例#23
0
 def getURL(self, s, userid=None, pop=True):
     '''
     possible values of s include:
         friendmoods
         viewbirthdays
         home
     '''
     if userid is None:
         try:
             userid = self.api.userid
         except AttributeError:
             return 'http://www.myspace.com'
     chl = self.next_chl(pop)
     if chl is None:
         return 'http://www.myspace.com'
     n = msimutil.roflcopter(chl.key, self.api.sesskey, self.api.userid)
     return net.UrlQuery(
         'http://home.myspace.com/Modules/IM/Pages/UrlRedirector.aspx',
         challenge='%s-%s-%s' % (n, self.api.userid, self.api.sesskey),
         response=str(self.make_chl_response(chl.data)),
         target=s,
         targetid=userid)
示例#24
0
 def delete_group(self, group_id, callback=None):
     self.send_msg(PersistMessage(
         self, 2, 16).Delete(body=msim_util.msdict(GroupID=str(group_id))),
                   use_rid=True,
                   callback=callback)
示例#25
0
 def delete_group(self, group_id, callback=None):
     self.send_msg(PersistMessage(self, 2, 16).Delete(body=msim_util.msdict(GroupID=str(group_id))),
                   use_rid=True, callback=callback)
示例#26
0
 def delete_contact_info(self, buddy_id, callback=None):
     self.send_msg(PersistMessage(
         self, 0,
         8).ActionDelete(body=msim_util.msdict(ContactID=buddy_id)),
                   use_rid=True,
                   callback=callback)
示例#27
0
 def request_self_social_info(self):
     self.send_msg(PersistMessage(self, 4, 5).Get(body=msim_util.msdict(UserID=str(self.userid))))
示例#28
0
 def add_top_friends(self, GroupName):
     self.send_msg(
         PersistMessage(self, 15,
                        22).Set(body=msim_util.msdict(GroupName=GroupName)))
示例#29
0
 def set_contact_info(self, buddy_id, infodict, callback=None):
     self.send_msg(PersistMessage(
         self, 0, 9).ActionSet(body=msim_util.msdict(**infodict)),
                   use_rid=True,
                   callback=callback)
示例#30
0
 def request_contact_social_info(self, uid):
     self.send_msg(
         PersistMessage(self, 4,
                        3).Get(body=msim_util.msdict(UserID=str(uid))))
示例#31
0
 def set_user_prefs(self, prefs_dict):
     self.send_msg(
         PersistMessage(self, 1,
                        10).ActionSet(body=msim_util.msdict(**prefs_dict)))
示例#32
0
 def set_contact_info(self, buddy_id, infodict, callback=None):
     self.send_msg(PersistMessage(self, 0, 9).ActionSet(body=msim_util.msdict(**infodict)),
                   use_rid=True, callback=callback)
示例#33
0
 def add_top_friends(self, GroupName):
     self.send_msg(PersistMessage(self, 15, 22).Set(body=msim_util.msdict(GroupName=GroupName)))
示例#34
0
 def make_chl_response(self, s):
     return b64encode(msimutil.crypt(s, self.password.lower())).strip('=')
示例#35
0
 def request_contact_im_info(self, uid):
     self.send_msg(PersistMessage(self, 1, 7).Get(body=msim_util.msdict(ContactID=str(uid))))
示例#36
0
    def handle_webchallenges(self, msg, body):
        challenge_info = msim_util.obj_list_from_msdict(body)

        self.api.got_webchallenge_info(challenge_info)
示例#37
0
 def request_contact_social_info(self, uid):
     self.send_msg(PersistMessage(self, 4, 3).Get(body=msim_util.msdict(UserID=str(uid))))
示例#38
0
 def set_user_prefs(self, prefs_dict):
     self.send_msg(PersistMessage(self, 1, 10).ActionSet(body=msim_util.msdict(**prefs_dict)))
示例#39
0
 def make_chl_response(self, s):
     return b64encode(msimutil.crypt(s, self.password.lower())).strip('=')
示例#40
0
 def request_self_social_info(self):
     self.send_msg(
         PersistMessage(
             self, 4,
             5).Get(body=msim_util.msdict(UserID=str(self.userid))))
示例#41
0
 def request_contact_im_info(self, uid):
     self.send_msg(
         PersistMessage(self, 1,
                        7).Get(body=msim_util.msdict(ContactID=str(uid))))
示例#42
0
 def delete_contact_info(self, buddy_id, callback=None):
     self.send_msg(PersistMessage(self, 0, 8).ActionDelete(body=msim_util.msdict(ContactID=buddy_id)),
                   use_rid=True, callback=callback)