Пример #1
0
    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')
Пример #2
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)
Пример #3
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)