<commit_before>#
# archipelRosterQueryableEntity.py
#
# Copyright (C) 2010 <NAME> <<EMAIL>>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import xmpp

from archipelcore.utils import build_error_iq

ARCHIPEL_ERROR_CODE_GET_ROSTER          = -450001

ARCHIPEL_NS_ROSTER                      = "archipel:roster"


class TNRosterQueryableEntity (object):
    """
    this class makes TNArchipelEntity avatar controllable
    it allows to get and set avatars of the entity
    """

    def __init__(self, configuration, permission_center, xmppclient, log):
        """
        initialize the TNAvatarControllableEntity
        @type configuration: configuration object
        @param configuration: the configuration
        @type permission_center: TNPermissionCenter
        @param permission_center: the permission center of the entity
        @type xmppclient: xmpp.Dispatcher
        @param xmppclient: the entity xmpp client
        @type log: TNArchipelLog
        @param log: the logger of the entity
        """
        self.configuration          = configuration
        self.permission_center      = permission_center
        self.xmppclient             = xmppclient
        self.log                    = log


    ### subclass must implement this

    def check_acp(conn, iq):
        """
        function that verify if the ACP is valid
        @type conn: xmpp.Dispatcher
        @param conn: the connection
        @type iq: xmpp.Protocol.Iq
        @param iq: the IQ to check
        @raise: Exception if not implemented
        """
        raise Exception("Subclass of TNAvatarControllableEntity must implement check_acp")

    def check_perm(self, conn, stanza, action_name, error_code=-1, prefix=""):
        """
        function that verify if the permissions are granted
        @type conn: xmpp.Dispatcher
        @param conn: the connection
        @type stanza: xmpp.Node
        @param stanza: the stanza containing the action
        @type action_name: string
        @param action_name: the action to check
        @type error_code: int
        @param error_code: the error code to return
        @type prefix: string
        @param prefix: the prefix of the action
        @raise: Exception if not implemented
        """
        raise Exception("Subclass of TNAvatarControllableEntity must implement check_perm")

    def init_vocabulary(self):
        """
        initialize the vocabulary
        """
        item = {"commands" : ["roster", "users"],
                "parameters": [],
                "permissions": ["roster"],
                "method": self.message_roster,
                "description": "I'll give you the content of my roster"}
        self.add_message_registrar_item(item)


    def init_permissions(self):
        """
        intialize the Avatar permissions
        """
        self.permission_center.create_permission("getavatars", "Authorizes users to get entity avatars list", False)
        self.permission_center.create_permission("setavatar", "Authorizes users to set entity's avatar", False)
        self.permission_center.create_permission("roster", "Authorizes users to get the content of my roster", False)

    def register_handler(self):
        """
        initialize the avatar handlers
        """
        self.xmppclient.RegisterHandler('iq', self.process_roster_iq, ns=ARCHIPEL_NS_ROSTER)


    def process_roster_iq(self, conn, iq):
        """
        this method is invoked when a ARCHIPEL_NS_ROSTER IQ is received.
        it understands IQ of type:
            - getroster
        @type conn: xmpp.Dispatcher
        @param conn: ths instance of the current connection that send the stanza
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        """
        reply = None
        action = self.check_acp(conn, iq)
        self.check_perm(conn, iq, action, -1)
        if action == "getroster":
            reply = self.iq_get_roster(iq)
        if reply:
            conn.send(reply)<commit_msg>remove double permission declaration<commit_after>#
# archipelRosterQueryableEntity.py
#
# Copyright (C) 2010 <NAME> <<EMAIL>>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import xmpp

from archipelcore.utils import build_error_iq

ARCHIPEL_ERROR_CODE_GET_ROSTER          = -450001

ARCHIPEL_NS_ROSTER                      = "archipel:roster"


class TNRosterQueryableEntity (object):
    """
    this class makes TNArchipelEntity avatar controllable
    it allows to get and set avatars of the entity
    """

    def __init__(self, configuration, permission_center, xmppclient, log):
        """
        initialize the TNAvatarControllableEntity
        @type configuration: configuration object
        @param configuration: the configuration
        @type permission_center: TNPermissionCenter
        @param permission_center: the permission center of the entity
        @type xmppclient: xmpp.Dispatcher
        @param xmppclient: the entity xmpp client
        @type log: TNArchipelLog
        @param log: the logger of the entity
        """
        self.configuration          = configuration
        self.permission_center      = permission_center
        self.xmppclient             = xmppclient
        self.log                    = log


    ### subclass must implement this

    def check_acp(conn, iq):
        """
        function that verify if the ACP is valid
        @type conn: xmpp.Dispatcher
        @param conn: the connection
        @type iq: xmpp.Protocol.Iq
        @param iq: the IQ to check
        @raise: Exception if not implemented
        """
        raise Exception("Subclass of TNAvatarControllableEntity must implement check_acp")

    def check_perm(self, conn, stanza, action_name, error_code=-1, prefix=""):
        """
        function that verify if the permissions are granted
        @type conn: xmpp.Dispatcher
        @param conn: the connection
        @type stanza: xmpp.Node
        @param stanza: the stanza containing the action
        @type action_name: string
        @param action_name: the action to check
        @type error_code: int
        @param error_code: the error code to return
        @type prefix: string
        @param prefix: the prefix of the action
        @raise: Exception if not implemented
        """
        raise Exception("Subclass of TNAvatarControllableEntity must implement check_perm")

    def init_vocabulary(self):
        """
        initialize the vocabulary
        """
        item = {"commands" : ["roster", "users"],
                "parameters": [],
                "permissions": ["roster"],
                "method": self.message_roster,
                "description": "I'll give you the content of my roster"}
        self.add_message_registrar_item(item)


    def init_permissions(self):
        """
        intialize the Avatar permissions
        """
        self.permission_center.create_permission("roster", "Authorizes users to get the content of my roster", False)

    def register_handler(self):
        """
        initialize the avatar handlers
        """
        self.xmppclient.RegisterHandler('iq', self.process_roster_iq, ns=ARCHIPEL_NS_ROSTER)


    def process_roster_iq(self, conn, iq):
        """
        this method is invoked when a ARCHIPEL_NS_ROSTER IQ is received.
        it understands IQ of type:
            - getroster
        @type conn: xmpp.Dispatcher
        @param conn: ths instance of the current connection that send the stanza
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        """
        reply = None
        action = self.check_acp(conn, iq)
        self.check_perm(conn, iq, action, -1)
        if action == "getroster":
            reply = self.iq_get_roster(iq)
        if reply:
            conn.send(reply)
{'fraction_non_alphanumeric': 0.07398753894080996, 'fraction_numerical': 0.002892745883400089, 'mean_word_length': 2.485459480418767, 'pattern_counts': {'":': 10, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3111422', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2382, 'n_words': 857}