<commit_before># -*- coding: utf-8 -*-
"""
    pyfire.stream.stanzas.iq.query
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Handles XMPP iq-query sub frames

    :copyright: 2011 by the pyfire Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""

import xml.etree.ElementTree as ET
from pyfire.contact import Contact


class Query(object):
    """Handles all iq-query xmpp frames"""

    __slots__ = ('handler', 'request', 'response')

    def handle(self, request):
        self.request = request
        self.response = ET.Element("query")

        if request.get("xmlns") in self.handler:
            self.handler[request.get("xmlns")](self)
        return self.response

    def roster(self):
        """RFC6121 Section 2"""
        self.response.set("xmlns", """jabber:iq:roster""")
        """ TODO: return real roster """
        contact = Contact("<EMAIL>")
        contact.subscription = "both"
        contact.approved = "true"
        self.response.append(contact.to_element())
        contact = Contact("<EMAIL>")
        contact.approved = "true"
        contact.subscription = "both"
        self.response.append(contact.to_element())

    def last(self):
        """XEP-0012"""
        self.response.set("xmlns", "jabber.iq.last")
        """ TODO: set real last activity of requested contact """
        self.response.set("seconds", "0")

    def disco_info(self):
        """XEP-0030"""<commit_msg>fixed generation of dummy contacts<commit_after># -*- coding: utf-8 -*-
"""
    pyfire.stream.stanzas.iq.query
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Handles XMPP iq-query sub frames

    :copyright: 2011 by the pyfire Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""

import xml.etree.ElementTree as ET
from pyfire.contact import Contact


class Query(object):
    """Handles all iq-query xmpp frames"""

    __slots__ = ('handler', 'request', 'response')

    def handle(self, request):
        self.request = request
        self.response = ET.Element("query")

        if request.get("xmlns") in self.handler:
            self.handler[request.get("xmlns")](self)
        return self.response

    def roster(self):
        """RFC6121 Section 2"""
        self.response.set("xmlns", """jabber:iq:roster""")
        """ TODO: return real roster """
        contact = Contact("<EMAIL>")
        contact.subscription = "both"
        contact.approved = True
        self.response.append(contact.to_element())
        contact = Contact("<EMAIL>")
        contact.approved = True
        contact.subscription = "both"
        self.response.append(contact.to_element())

    def last(self):
        """XEP-0012"""
        self.response.set("xmlns", "jabber.iq.last")
        """ TODO: set real last activity of requested contact """
        self.response.set("seconds", "0")

    def disco_info(self):
        """XEP-0030"""
{'fraction_non_alphanumeric': 0.1629425919559986, 'fraction_numerical': 0.013062908215881746, 'mean_word_length': 2.6975857687420586, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '5429461', 'n_tokens_mistral': 889, 'n_tokens_neox': 838, 'n_words': 209}