# Path: pyxmpp2/xmppstringprep.py
# NODEPREP = Profile(
#     unassigned = (stringprep.in_table_a1,),
#     mapping = (b1_mapping, stringprep.map_table_b2),
#     normalization = nfkc,
#     prohibited = (  stringprep.in_table_c11, stringprep.in_table_c12,
#                     stringprep.in_table_c21, stringprep.in_table_c22,
#                     stringprep.in_table_c3, stringprep.in_table_c4,
#                     stringprep.in_table_c5, stringprep.in_table_c6,
#                     stringprep.in_table_c7, stringprep.in_table_c8,
#                     stringprep.in_table_c9,
#                     lambda x: x in NODEPREP_PROHIBITED ),
#     bidi = True)
# 
# RESOURCEPREP = Profile(
#     unassigned = (stringprep.in_table_a1,),
#     mapping = (b1_mapping,),
#     normalization = nfkc,
#     prohibited = (  stringprep.in_table_c12, stringprep.in_table_c21,
#                     stringprep.in_table_c22, stringprep.in_table_c3,
#                     stringprep.in_table_c4, stringprep.in_table_c5,
#                     stringprep.in_table_c6, stringprep.in_table_c7,
#                     stringprep.in_table_c8, stringprep.in_table_c9 ),
#     bidi = True)
# 
# Path: pyxmpp2/exceptions.py
# class JIDError(Error, ValueError):
#     "Exception raised when invalid JID is used"
#     pass
# 
# class StringprepError(Error):
#     """Exception raised when string preparation results in error."""
#     pass


import re
import weakref
import warnings
import socket
import logging
from encodings import idna
from .xmppstringprep import NODEPREP, RESOURCEPREP
from .exceptions import JIDError, StringprepError
            labels = [idna.nameprep(label) for label in labels]
        except UnicodeError:
            raise JIDError(u"Domain name invalid")
        for label in labels:
            if not STD3_LABEL_RE.match(label):
                raise JIDError(u"Domain name invalid")
            try:
                idna.ToASCII(label)
            except UnicodeError:
                raise JIDError(u"Domain name invalid")
        domain = u".".join(labels)
        if len(domain.encode("utf-8")) > 1023:
            raise JIDError(u"Domain name too long")
        return domain

    @staticmethod
    def __prepare_resource(data):
        """Prepare the resourcepart of the JID.

        :Parameters:
            - `data`: Resourcepart of the JID

        :raise JIDError: if the resource name is too long.
        :raise pyxmpp.xmppstringprep.StringprepError: if the
            resourcepart fails Resourceprep preparation."""
        if not data:
            return None
        data = unicode(data)
        try:
            resource = RESOURCEPREP.prepare(data)

# Path: pyxmpp2/xmppstringprep.py
# NODEPREP = Profile(
#     unassigned = (stringprep.in_table_a1,),
#     mapping = (b1_mapping, stringprep.map_table_b2),
#     normalization = nfkc,
#     prohibited = (  stringprep.in_table_c11, stringprep.in_table_c12,
#                     stringprep.in_table_c21, stringprep.in_table_c22,
#                     stringprep.in_table_c3, stringprep.in_table_c4,
#                     stringprep.in_table_c5, stringprep.in_table_c6,
#                     stringprep.in_table_c7, stringprep.in_table_c8,
#                     stringprep.in_table_c9,
#                     lambda x: x in NODEPREP_PROHIBITED ),
#     bidi = True)
# 
# RESOURCEPREP = Profile(
#     unassigned = (stringprep.in_table_a1,),
#     mapping = (b1_mapping,),
#     normalization = nfkc,
#     prohibited = (  stringprep.in_table_c12, stringprep.in_table_c21,
#                     stringprep.in_table_c22, stringprep.in_table_c3,
#                     stringprep.in_table_c4, stringprep.in_table_c5,
#                     stringprep.in_table_c6, stringprep.in_table_c7,
#                     stringprep.in_table_c8, stringprep.in_table_c9 ),
#     bidi = True)
# 
# Path: pyxmpp2/exceptions.py
# class JIDError(Error, ValueError):
#     "Exception raised when invalid JID is used"
#     pass
# 
# class StringprepError(Error):
#     """Exception raised when string preparation results in error."""
#     pass


# Path: pyxmpp2/jid.py
import re
import weakref
import warnings
import socket
import logging
from encodings import idna
from .xmppstringprep import NODEPREP, RESOURCEPREP
from .exceptions import JIDError, StringprepError

            labels = [idna.nameprep(label) for label in labels]
        except UnicodeError:
            raise JIDError(u"Domain name invalid")
        for label in labels:
            if not STD3_LABEL_RE.match(label):
                raise JIDError(u"Domain name invalid")
            try:
                idna.ToASCII(label)
            except UnicodeError:
                raise JIDError(u"Domain name invalid")
        domain = u".".join(labels)
        if len(domain.encode("utf-8")) > 1023:
            raise JIDError(u"Domain name too long")
        return domain

    @staticmethod
    def __prepare_resource(data):
        """Prepare the resourcepart of the JID.

        :Parameters:
            - `data`: Resourcepart of the JID

        :raise JIDError: if the resource name is too long.
        :raise pyxmpp.xmppstringprep.StringprepError: if the
            resourcepart fails Resourceprep preparation."""
        if not data:
            return None
        data = unicode(data)
        try:
            resource = RESOURCEPREP.prepare(data)

        except StringprepError, err: