File: //usr/lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/jid.cpython-38.pyc
U
W[Q � @ sh d Z ddlmZmZ ddlmZmZmZ G dd� de�Z dd� Z
dd � Zi Zd
d� Z
G dd
� d
e�ZdS )a$
Jabber Identifier support.
This module provides an object to represent Jabber Identifiers (JIDs) and
parse string representations into them with proper checking for illegal
characters, case folding and canonicalisation through L{stringprep<twisted.words.protocols.jabber.xmpp_stringprep>}.
� )�_PY3�unicode)�nodeprep�resourceprep�nameprepc @ s e Zd ZdZdS )�
InvalidFormatzT
The given string could not be parsed into a valid Jabber Identifier (JID).
N)�__name__�
__module__�__qualname__�__doc__� r r �D/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/jid.pyr s r c C s� d}d}d}| � d�}| � d�}|dkrX|dkr6| }q�| d|� }| |d d� pTd}n�|dkr�| d|� pnd}| |d d� }nf||k r�| d|� p�d}| |d ||| � }| |d d� p�d}n | d|� }| |d d� p�d}t|||�S )a�
Parse given JID string into its respective parts and apply stringprep.
@param jidstring: string representation of a JID.
@type jidstring: L{unicode}
@return: tuple of (user, host, resource), each of type L{unicode} as
the parsed and stringprep'd parts of the given JID. If the
given string did not have a user or resource part, the respective
field in the tuple will hold L{None}.
@rtype: L{tuple}
N�@�/���r � )�find�prep)� jidstring�user�host�resourceZuser_sepZres_sepr r r
�parse s(
r c C s� | r6zt �t| ��} W q: tk
r2 td��Y q:X nd} |sHtd��n0zt�t|��}W n tk
rv td��Y nX |r�zt�t|��}W q� tk
r� td��Y q�X nd}| ||fS )a\
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}
zInvalid character in usernameNzServer address required.zInvalid character in hostnamezInvalid character in resource)r Zpreparer �UnicodeErrorr r r )r r r r r r
r D s&