# 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
            if data[0] == u'[' and data[-1] == u']':
                try:
                    addr = _validate_ip_address(socket.AF_INET6, data[1:-1])
                    return "[{0}]".format(addr)
                except ValueError, err:
                    logger.debug("ValueError: {0}".format(err))
                    raise JIDError(u"Invalid IPv6 literal in JID domainpart")
            else:
                raise JIDError(u"Invalid use of '[' or ']' in JID domainpart")
        elif data[0].isdigit() and data[-1].isdigit():
            try:
                addr = _validate_ip_address(socket.AF_INET, data)
            except ValueError, err:
                logger.debug("ValueError: {0}".format(err))
        data = UNICODE_DOT_RE.sub(u".", data)
        data = data.rstrip(u".")
        labels = data.split(u".")
        try:
            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:

# 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

            if data[0] == u'[' and data[-1] == u']':
                try:
                    addr = _validate_ip_address(socket.AF_INET6, data[1:-1])
                    return "[{0}]".format(addr)
                except ValueError, err:
                    logger.debug("ValueError: {0}".format(err))
                    raise JIDError(u"Invalid IPv6 literal in JID domainpart")
            else:
                raise JIDError(u"Invalid use of '[' or ']' in JID domainpart")
        elif data[0].isdigit() and data[-1].isdigit():
            try:
                addr = _validate_ip_address(socket.AF_INET, data)
            except ValueError, err:
                logger.debug("ValueError: {0}".format(err))
        data = UNICODE_DOT_RE.sub(u".", data)
        data = data.rstrip(u".")
        labels = data.split(u".")
        try:
            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")