Пример #1
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)
Пример #2
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)
Пример #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)
Пример #4
0
Файл: jid.py Проект: 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 testNodePrep(self):
     self.assertEqual(nodeprep.prepare("user"), "user")
     self.assertEqual(nodeprep.prepare("User"), "user")
     self.assertRaises(UnicodeError, nodeprep.prepare, "us&er")
 def testNodePrep(self):
     self.assertEqual(nodeprep.prepare(u'user'), u'user')
     self.assertEqual(nodeprep.prepare(u'User'), u'user')
     self.assertRaises(UnicodeError, nodeprep.prepare, u'us&er')
 def testNodePrep(self):
     self.assertEqual(nodeprep.prepare(u'user'), u'user')
     self.assertEqual(nodeprep.prepare(u'User'), u'user')
     self.assertRaises(UnicodeError, nodeprep.prepare, u'us&er')
 def testNodePrep(self):
     self.assertEquals(nodeprep.prepare(u"user"), u"user")
     self.assertEquals(nodeprep.prepare(u"User"), u"user")
     self.assertRaises(UnicodeError, nodeprep.prepare, u"us&er")
Пример #9
0
def strlower(username):
    username = nodeprep.prepare(username)
    return username