Exemple #1
0
 def test_unicodeASCII(self):
     """
     Unicode strings with ASCII code points are unchanged.
     """
     result = _coercedUnicode(u'text')
     self.assertEqual(result, u'text')
     self.assertIsInstance(result, unicodeCompat)
Exemple #2
0
 def test_unicodeNonASCII(self):
     """
     Unicode strings with non-ASCII code points are unchanged.
     """
     result = _coercedUnicode(u'\N{SNOWMAN}')
     self.assertEqual(result, u'\N{SNOWMAN}')
     self.assertIsInstance(result, unicodeCompat)
 def addContent(self, text):
     """ Add some text data to this Element. """
     text = _coercedUnicode(text)
     c = self.children
     if len(c) > 0 and isinstance(c[-1], unicode):
         c[-1] = c[-1] + text
     else:
         c.append(text)
     return c[-1]
Exemple #4
0
 def addContent(self, text):
     """ Add some text data to this Element. """
     text = _coercedUnicode(text)
     c = self.children
     if len(c) > 0 and isinstance(c[-1], str):
         c[-1] = c[-1] + text
     else:
         c.append(text)
     return c[-1]
Exemple #5
0
    def test_nativeASCII(self):
        """
        Native strings with ASCII code points are unchanged.

        On Python 2, this verifies that ASCII-only byte strings are accepted,
        whereas for Python 3 it is identical to L{test_unicodeASCII}.
        """
        result = _coercedUnicode('text')
        self.assertEqual(result, u'text')
        self.assertIsInstance(result, unicodeCompat)
Exemple #6
0
    def initialize(self):
        xs = self.xmlstream
        hs = domish.Element((self.xmlstream.namespace, "handshake"))
        digest = xmlstream.hashPassword(
            xs.sid, _coercedUnicode(xs.authenticator.password))
        hs.addContent(unicode(digest))

        # Setup observer to watch for handshake result
        xs.addOnetimeObserver("/handshake", self._cbHandshake)
        xs.send(hs)
        self._deferred = defer.Deferred()
        return self._deferred
    def initialize(self):
        xs = self.xmlstream
        hs = domish.Element((self.xmlstream.namespace, "handshake"))
        digest = xmlstream.hashPassword(
            xs.sid,
            _coercedUnicode(xs.authenticator.password))
        hs.addContent(unicode(digest))

        # Setup observer to watch for handshake result
        xs.addOnetimeObserver("/handshake", self._cbHandshake)
        xs.send(hs)
        self._deferred = defer.Deferred()
        return self._deferred
Exemple #8
0
    def _cbAuthQuery(self, iq):
        jid = self.xmlstream.authenticator.jid
        password = _coercedUnicode(self.xmlstream.authenticator.password)

        # Construct auth request
        reply = xmlstream.IQ(self.xmlstream, "set")
        reply.addElement(("jabber:iq:auth", "query"))
        reply.query.addElement("username", content = jid.user)
        reply.query.addElement("resource", content = jid.resource)

        # Prefer digest over plaintext
        if DigestAuthQry.matches(iq):
            digest = xmlstream.hashPassword(self.xmlstream.sid, password)
            reply.query.addElement("digest", content=unicode(digest))
        else:
            reply.query.addElement("password", content = password)

        d = reply.send()
        d.addCallbacks(self._cbAuth, self._ebAuth)
        return d