def testNamePrep(self):
        self.assertEqual(nameprep.prepare("example.com"), "example.com")
        self.assertEqual(nameprep.prepare("Example.com"), "example.com")
        self.assertRaises(UnicodeError, nameprep.prepare, "*****@*****.**")
        self.assertRaises(UnicodeError, nameprep.prepare, "-example.com")
        self.assertRaises(UnicodeError, nameprep.prepare, "example-.com")

        self.assertEqual(nameprep.prepare("stra\u00dfe.example.com"),
                         "strasse.example.com")
    def testNamePrep(self):
        self.assertEqual(nameprep.prepare(u'example.com'), u'example.com')
        self.assertEqual(nameprep.prepare(u'Example.com'), u'example.com')
        self.assertRaises(UnicodeError, nameprep.prepare, u'*****@*****.**')
        self.assertRaises(UnicodeError, nameprep.prepare, u'-example.com')
        self.assertRaises(UnicodeError, nameprep.prepare, u'example-.com')

        self.assertEqual(nameprep.prepare(u'stra\u00dfe.example.com'),
                          u'strasse.example.com')
    def testNamePrep(self):
        self.assertEqual(nameprep.prepare(u'example.com'), u'example.com')
        self.assertEqual(nameprep.prepare(u'Example.com'), u'example.com')
        self.assertRaises(UnicodeError, nameprep.prepare, u'*****@*****.**')
        self.assertRaises(UnicodeError, nameprep.prepare, u'-example.com')
        self.assertRaises(UnicodeError, nameprep.prepare, u'example-.com')

        self.assertEqual(nameprep.prepare(u'stra\u00dfe.example.com'),
                          u'strasse.example.com')
    def testNamePrep(self):
        self.assertEquals(nameprep.prepare(u"example.com"), u"example.com")
        self.assertEquals(nameprep.prepare(u"Example.com"), u"example.com")
        self.assertRaises(UnicodeError, nameprep.prepare, u"*****@*****.**")
        self.assertRaises(UnicodeError, nameprep.prepare, u"-example.com")
        self.assertRaises(UnicodeError, nameprep.prepare, u"example-.com")

        if crippled:
            return

        self.assertEquals(nameprep.prepare(u"stra\u00dfe.example.com"), u"strasse.example.com")
Example #5
0
def prep(user, server, resource):
    """ Stringprep, backported from Twisted 2.0 """

    if user:
        try:
            user = nodeprep.prepare(unicode(user))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in username"
    else:
        user = None

    if not server:
        raise InvalidFormat, "Server address required."
    else:
        try:
            server = nameprep.prepare(unicode(server))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in resource"

    if resource:
        try:
            resource = resourceprep.prepare(unicode(resource))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in resource"
    else:
        resource = None

    return (user, server, resource)
Example #6
0
def prep(user, server, resource):
    """ Perform stringprep on all JID fragments """

    if user:
        try:
            user = nodeprep.prepare(unicode(user))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in username"
    else:
        user = None

    if not server:
        raise InvalidFormat, "Server address required."
    else:
        try:
            server = nameprep.prepare(unicode(server))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in hostname"

    if resource:
        try:
            resource = resourceprep.prepare(unicode(resource))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in resource"
    else:
        resource = None

    return (user, server, resource)
Example #7
0
def prep(user, host, resource):
    """
    Perform stringprep on all JID fragments.

    @param user: The user part of the JID.
    @type user: C{unicode}
    @param host: The host part of the JID.
    @type host: C{unicode}
    @param resource: The resource part of the JID.
    @type resource: C{unicode}
    @return: The given parts with stringprep applied.
    @rtype: C{tuple}
    """

    if user:
        try:
            user = nodeprep.prepare(unicode(user))
        except UnicodeError:
            raise InvalidFormat("Invalid character in username")
    else:
        user = None

    if not host:
        raise InvalidFormat("Server address required.")
    else:
        try:
            host = nameprep.prepare(unicode(host))
        except UnicodeError:
            raise InvalidFormat("Invalid character in hostname")

    if resource:
        try:
            resource = resourceprep.prepare(unicode(resource))
        except UnicodeError:
            raise InvalidFormat("Invalid character in resource")
    else:
        resource = None

    return (user, host, resource)
Example #8
0
File: jid.py Project: 0004c/VTK
def prep(user, host, resource):
    """
    Perform stringprep on all JID fragments.

    @param user: The user part of the JID.
    @type user: C{unicode}
    @param host: The host part of the JID.
    @type host: C{unicode}
    @param resource: The resource part of the JID.
    @type resource: C{unicode}
    @return: The given parts with stringprep applied.
    @rtype: C{tuple}
    """

    if user:
        try:
            user = nodeprep.prepare(unicode(user))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in username"
    else:
        user = None

    if not host:
        raise InvalidFormat, "Server address required."
    else:
        try:
            host = nameprep.prepare(unicode(host))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in hostname"

    if resource:
        try:
            resource = resourceprep.prepare(unicode(resource))
        except UnicodeError:
            raise InvalidFormat, "Invalid character in resource"
    else:
        resource = None

    return (user, host, resource)
 def test_nameprepTrailingDot(self):
     """
     A trailing dot in domain names is preserved.
     """
     self.assertEqual(nameprep.prepare("example.com."), "example.com.")
 def test_nameprepTrailingDot(self):
     """
     A trailing dot in domain names is preserved.
     """
     self.assertEqual(nameprep.prepare(u'example.com.'), u'example.com.')