コード例 #1
0
ファイル: sipc_auth.py プロジェクト: williamyangcn/iBlah_py
def _create_contact_from_buddy_xml_node(user, node):
    # Notice: a buddy could belongs to two groups
    attr = node.getAttribute

    contact = Contact(user = user)
    contact.uri = attr("u")
    contact.sid = get_sid_from_uri(contact.uri)
    contact.user_id = attr("i")
    contact.nickname = to_unicode_obj(attr("n"))
    contact.relation_status = int(attr("r"))

    buddy_list_id = attr("l")
    if buddy_list_id:
        gids = [gid for gid in buddy_list_id.split(";") if gid.strip() and int(gid) >= DEFAULT_GID]
        if len(gids) != 1:
            logger.error("!!! User (SID: %s) has multiple GID" % contact.sid)
            print "gids:", gids
        gid = int(gids[0])
    else:
        gid = DEFAULT_GID
    contact.set_gid(gid)

    contact.portrait_crc = 0

    return contact
コード例 #2
0
    def _consume_noti_sync_user_info_v4(self, res_obj):
        body_dom = minidom.parseString(res_obj.body)

        contact_list_nodes = body_dom.getElementsByTagName("contact-list")
        if not contact_list_nodes:
            return
        assert len(contact_list_nodes) == 1
        contact_list_node = contact_list_nodes[0]
        contact_list_version = contact_list_node.getAttribute("version")
        if self.user.contact_list_version != contact_list_version:
            self.user.contact_list_version = contact_list_version

        buddy_nodes = body_dom.getElementsByTagName("buddy")
        for buddy_node in buddy_nodes:
            attr = buddy_node.getAttribute
            user_id = attr("user-id")
            contact = self.user.group_agent.get_contact_by_user_id(user_id)

            # someone send add buddy application to you,
            # and you send buddy application before any reply,
            # contact will be not found in self.user.contact_list.
            if not contact:
                continue

            if attr("action") == "remove":
                logger.error("!!! Your buddy (uri: %s) %s you" %
                             (contact.uri, attr("action")))

                convs = self.user.conversations()
                conv = convs.get(contact.uri, None)
                if conv:
                    assert conv.sock != self.user.get_sock()
                    conv.over()
                    del conv
                self.user.group_agent.remove_user_by_user_id(user_id)

            elif attr("action") == "add":
                logger.info("!!! Your buddy (uri: %s) %s you" %
                            (contact.uri, attr("action")))

                cat = Contact(user=self.blah.user)
                map_node_attr_to_obj(buddy_node, cat)
                self.user.contact_list.append(cat)
                cat.buddy_lists = attr("buddy-lists")
                cat.online_notify = attr("online-notify")
                cat.permission_values = attr("permission-values")
コード例 #3
0
ファイル: contact_list_win.py プロジェクト: qq40660/iBlah_py
    def _consume_noti_sync_user_info_v4(self, res_obj):
        body_dom = minidom.parseString(res_obj.body)

        contact_list_nodes = body_dom.getElementsByTagName("contact-list")
        if not contact_list_nodes:
            return
        assert len(contact_list_nodes) == 1
        contact_list_node = contact_list_nodes[0]
        contact_list_version = contact_list_node.getAttribute("version")
        if self.user.contact_list_version != contact_list_version:
            self.user.contact_list_version = contact_list_version

        buddy_nodes = body_dom.getElementsByTagName("buddy")
        for buddy_node in buddy_nodes:
            attr = buddy_node.getAttribute
            user_id = attr("user-id")
            contact = self.user.group_agent.get_contact_by_user_id(user_id)

            # someone send add buddy application to you,
            # and you send buddy application before any reply,
            # contact will be not found in self.user.contact_list.
            if not contact:
                continue

            if attr("action") == "remove":
                logger.error("!!! Your buddy (uri: %s) %s you" % (contact.uri, attr("action")))

                convs = self.user.conversations()
                conv = convs.get(contact.uri, None)
                if conv:
                    assert conv.sock != self.user.get_sock()
                    conv.over()
                    del conv
                self.user.group_agent.remove_user_by_user_id(user_id)

            elif attr("action") == "add":
                logger.info("!!! Your buddy (uri: %s) %s you" % (contact.uri, attr("action")))

                cat = Contact(user = self.blah.user)
                map_node_attr_to_obj(buddy_node, cat)
                self.user.contact_list.append(cat)
                cat.buddy_lists = attr("buddy-lists")
                cat.online_notify = attr("online-notify")
                cat.permission_values = attr("permission-values")
コード例 #4
0
ファイル: user.py プロジェクト: williamyangcn/iBlah_py
def load_user_data_from_local_json(account_no, user):
    account = get_account_basic_info_by_account_no(account_no)
    if not account:
        logger.error("local personal config not found")
        return
    # there is basic account data, it is not the first time sign in
    sid = account["sid"]

    user_info_versions = get_data_from_local_json(sid,
                                                  "user_info_versions.json")
    if user_info_versions:
        logger.info("local user_info_versions.json found")
        user.version = user_info_versions["version"]
        user.custom_config_version = user_info_versions[
            "custom_config_version"]
        user.contact_list_version = user_info_versions["contact_list_version"]
    else:
        #delete_config_from_local_json(sid, "user_info_versions.json")
        return

    user.set_user_path(sid)
    user.set_portrait_save_path()

    # get from SIPC auth response body, results -> user-info -> personal node
    personal_node = get_data_from_local_json(sid, "personal_node.json")
    if personal_node:
        update_personal_node_from_local_config(user, personal_node)
#    update_personal_node_from_local_config(user, personal_config)

    custom_config = get_data_from_local_json(sid, "custom_config_node.json")
    if custom_config:
        user.custom_config_version = custom_config["data"]

    # results -> user-info > buddy-list node
    group_data = get_data_from_local_json(sid, "group_list_node.json")
    group_agent = GroupAgent()

    if group_data:
        groups_d = group_data["groups"]
        for gid, gname in groups_d.iteritems():
            group = Group(gid, gname)
            #group = Group(int(gid), gname)
            group_agent.add_group(group)

        for gid, gname in groups_d.iteritems():
            cat_datas = get_data_from_local_json(sid, "%s_list.json" % gname)
            cats_d = cat_datas["contacts"]
            for cat_d in cats_d.values():
                cat = Contact(user)
                map_dict_to_obj(cat_d, cat)
                group_agent.add_contact(cat)

    user.group_agent = group_agent
コード例 #5
0
ファイル: sipc_auth.py プロジェクト: williamyangcn/iBlah_py
def _parse_blacklist_node(user, contact_list_node):
    blacklist_node = contact_list_node.getElementsByTagName("blacklist")[0]

    for cat_node in blacklist_node.childNodes:
        if cat_node.nodeType == minidom.Node.TEXT_NODE:
            continue

        contact = Contact(user)
        contact.set_gid(BLACKLIST_GROUP_GID)
        attr = cat_node.getAttribute
        contact.uri = attr("u")
        contact.sid = get_sid_from_uri(contact.uri)
        contact.user_id = attr("i")
        user.group_agent.add_contact(contact)
コード例 #6
0
ファイル: sipc_auth.py プロジェクト: williamyangcn/iBlah_py
def _parse_chat_friends_node(user, contact_list_node):
    # strangers group list
    chat_friends_node = contact_list_node.getElementsByTagName("chat-friends")[0]

    for cat_node in chat_friends_node.childNodes:
        if cat_node.nodeType == minidom.Node.TEXT_NODE:
            continue

        contact = Contact(user)
        contact.set_gid(STRANGER_GROUP_GID)
        attr = cat_node.getAttribute
        contact.uri = attr("u")
        contact.sid = get_sid_from_uri(contact.uri)
        contact.user_id = attr("i")
        user.group_agent.add_contact(contact)
コード例 #7
0
ファイル: user.py プロジェクト: williamyangcn/iBlah_py
 def to_contact(self):
     contact = Contact(user=self)
     for i in contact.__dict__.keys():
         if i in self.__dict__:
             setattr(contact, i, self.__dict__[i])
     return contact