Example #1
0
def prep(user, server, resource):
    '''Perform stringprep on all JID fragments and return the full jid'''
    # This function comes from
    #http://svn.twistedmatrix.com/cvs/trunk/twisted/words/protocols/jabber/jid.py

    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

    if user:
        if resource:
            return '%s@%s/%s' % (user, server, resource)
        else:
            return '%s@%s' % (user, server)
    else:
        if resource:
            return '%s/%s' % (server, resource)
        else:
            return server
Example #2
0
def prep(user, server, resource):
	'''Perform stringprep on all JID fragments and return the full jid'''
	# This function comes from
	#http://svn.twistedmatrix.com/cvs/trunk/twisted/words/protocols/jabber/jid.py

	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

	if user:
		if resource:
			return '%s@%s/%s' % (user, server, resource)
		else:
			return '%s@%s' % (user, server)
	else:
		if resource:
			return '%s/%s' % (server, resource)
		else:
			return server
Example #3
0
def prep(user, host, resource):
    """
    Perform stringprep on all JID fragments.

    @param user: The user part of the JID.
    @type user: L{unicode}
    @param host: The host part of the JID.
    @type host: L{unicode}
    @param resource: The resource part of the JID.
    @type resource: L{unicode}
    @return: The given parts with stringprep applied.
    @rtype: L{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 #4
0
from xmpp_stringprep import nodeprep
import json
import logging
import sys
import codecs
import os

sys.stdout = codecs.getwriter("utf-8")(sys.stdout)

for line in sys.stdin.read().split("\n")[:-1]:
	try:
		a = unicode(line.strip(), "utf-8")
		try:
			print nodeprep.prepare(a)
		except UnicodeError as e:
			print "ILLEGAL:unable to prepare:" + str(e)	
	except UnicodeError as e:
		print "ILLEGAL:unable to decode:" + str(e)