示例#1
0
class TestJID(unittest.TestCase):

    def setUp(self):
        self.jid = JID("user", "domain", "resource")

    def test_parse(self):
        jid = JID.parse("bob@work/mobile")
        self.assertEqual(str(jid), "bob@work/mobile")

    def test_str(self):
        self.assertEqual(str(self.jid), "user@domain/resource")

    def test_domainid(self):
        self.assertEqual(self.jid.domainid(), "domain")

    def test_nodeid(self):
        self.assertEqual(self.jid.nodeid(), "user@domain")

    def test_ressourceid(self):
        self.assertEqual(self.jid.ressourceid(), "user@domain/resource")

    def test_hashed(self):
        self.assertEqual(self.jid.hashed, "4b8b6b2035fefaeae824f59bd54ebaf763cd61ce")
示例#2
0
    def __init__(self, service, secret, tls=False):
        self.parser = DispatchParser()

        self.running = False

        self.handlers = []
        self.iq_handlers = []
        
        self.logger = None
        self.secret = secret
        self.jid = JID.parse(service)
        
        self.stream = ComponentStream(self.jid)
        self.register(self.stream)
        self.parser.register_default(self.default_handler)
        self.parser.register_default_start_element(self.handle_stream)
示例#3
0
    def __init__(self, jid, password, tls=False, registerclass=None):
        self.parser = DispatchParser()

        self.running = False
        self.available = False

        self.handlers = []
        self.iq_handlers = []
        
        self.logger = None
        self.jid = JID.parse(jid)
        
        self.stream = Stream(self.jid, password, tls=tls, register=registerclass != None)
        self.register(self.stream)
        self.parser.register_default(self.default_handler)

        if registerclass:
            self.register(registerclass(self, self.jid.node, password, unicode(self.jid)))
示例#4
0
    def init_client(self):
        """
        Initializes the XMPP client instance.
        """
        from headstock.client import AsyncClient

        jid = JID(self.settings.username, self.settings.domain,
                  self.settings.resource)
        self.client = AsyncClient(unicode(jid),
                                  self.settings.password,
                                  hostname=self.settings.hostname,
                                  port=self.settings.port,
                                  tls=self.settings.tls,
                                  registercls=None)
        log_path = None
        if self.settings.log_dir:
            log_path = "%s.log" % os.path.join(self.settings.log_dir,
                                               self.settings.username)
        self.client.set_log(path=log_path, stdout=self.settings.log_stdout)

        if self.settings.register:
            self.client.stream.register = True
            self.client.swap_handler(self.register,
                                     "register",
                                     "http://jabber.org/features/iq-register",
                                     once=True,
                                     forget=False)
            self.client.swap_handler(self.handle_registration,
                                     "query",
                                     XMPP_IBR_NS,
                                     once=True)
            self.client.swap_handler(self.handle_conflict,
                                     "conflict",
                                     XMPP_STANZA_ERROR_NS,
                                     once=True)
            self.client.swap_handler(self.handle_not_authorized,
                                     "not-authorized",
                                     XMPP_SASL_NS,
                                     once=True)
示例#5
0
    def init_client(self):
        """
        Initializes the XMPP client instance.
        """
        from headstock.client import KamaeliaClient

        registercls = None
        if self.settings.register:
            from headstock.register import Register
            registercls = Register

        jid = JID(self.settings.username, self.settings.domain,
                  self.settings.resource)
        self.client = KamaeliaClient(unicode(jid),
                                     self.settings.password,
                                     hostname=self.settings.hostname,
                                     port=self.settings.port,
                                     tls=self.settings.tls,
                                     registercls=registercls)
        log_path = None
        if self.settings.log_dir:
            log_path = "%s.log" % os.path.join(self.settings.log_dir,
                                               self.settings.username)
        self.client.set_log(path=log_path, stdout=self.settings.log_stdout)
示例#6
0
 def setUp(self):
     self.jid = JID("user", "domain", "resource")
示例#7
0
 def test_parse(self):
     jid = JID.parse("bob@work/mobile")
     self.assertEqual(str(jid), "bob@work/mobile")
示例#8
0
 def handle_jid(self, e):
     """
     Parses the bound JID and sets it to the stream.
     """
     self.jid = JID.parse(e.xml_text)
示例#9
0
 def handle_jid(self, e):
     """
     Parses the bound JID and sets it to the stream.
     """
     self.jid = JID.parse(e.xml_text)