o
    ¼>hè  ã                   @   sÜ   U d Z ddlmZmZmZ ddlmZmZmZ G dd„ de	ƒZ
dedeeedf eeedf f fd	d
„Zdeedf dedeedf deeedf eeedf f fdd„Zi Zeedf ed< dd„ ZG dd„ dƒZdS )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>}.
é    )ÚDictÚTupleÚUnion)ÚnameprepÚnodeprepÚresourceprepc                   @   s   e Zd ZdZdS )ÚInvalidFormatzT
    The given string could not be parsed into a valid Jabber Identifier (JID).
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú‚/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/protocols/jabber/jid.pyr      s    r   Ú	jidstringÚreturnNc                 C   sô   d}d}d}|   d¡}|   d¡}|dkr,|dkr| }nY| d|… }| |d d… p*d}nH|dkrA| d|… p7d}| |d d… }n3||k rd| d|… pLd}| |d |||  … }| |d d… pbd}n| d|… }| |d d… psd}t|||ƒS )aÇ  
    Parse given JID string into its respective parts and apply stringprep.

    @param jidstring: string representation of a JID.
    @type jidstring: L{str}
    @return: tuple of (user, host, resource), each of type L{str} 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)r   ÚuserÚhostÚresourceÚuser_sepÚres_sepr   r   r   Úparse   s(   

r   r   r   r   c                 C   s¤   | rz	t  t| ƒ¡} W n ty   tdƒ‚w d} |stdƒ‚z	t t|ƒ¡}W n ty3   tdƒ‚w |rKz	t t|ƒ¡}W n tyJ   tdƒ‚w d}| ||fS )aP  
    Perform stringprep on all JID fragments.

    @param user: The user part of the JID.
    @type user: L{str}
    @param host: The host part of the JID.
    @type host: L{str}
    @param resource: The resource part of the JID.
    @type resource: L{str}
    @return: The given parts with stringprep applied.
    @rtype: L{tuple}
    zInvalid character in usernameNzServer address required.zInvalid character in hostnamezInvalid character in resource)r   ÚprepareÚstrÚUnicodeErrorr   r   r   )r   r   r   r   r   r   r   M   s,   ÿÿÿ
r   ÚJIDÚ__internJIDsc                 C   s$   | t v rt |  S t| ƒ}|t | < |S )z2
    Return interned JID.

    @rtype: L{JID}
    )r!   r    )r   Újr   r   r   Ú	internJID{   s
   r#   c                   @   sž   e Zd ZdZ		ddeedf deeeedf eeedf f df fdd„Zdd„ Zd	d
„ Z	dd„ Z
dedefdd„Zdd„ Zdd„ ZeZdefdd„ZdS )r    z‰
    Represents a stringprep'd Jabber ID.

    JID objects are hashable so they can be used in sets and as keys in
    dictionaries.
    Nr   Útuplec                 C   sF   |r
t |ƒ\}}}n|rt|Ž \}}}ntdƒ‚|| _|| _|| _d S )Nz?You must provide a value for either 'str' or 'tuple' arguments.)r   r   ÚRuntimeErrorr   r   r   )Úselfr   r$   r   r   Úresr   r   r   Ú__init__’   s   ÿ
zJID.__init__c                 C   s   | j r| j › d| j› S | jS )zÃ
        Extract the bare JID as a unicode string.

        A bare JID does not have a resource part, so this returns either
        C{user@host} or just C{host}.

        @rtype: L{str}
        r   )r   r   ©r&   r   r   r   Úuserhost¤   s   	zJID.userhostc                 C   s   | j r	t|  ¡ ƒS | S )a  
        Extract the bare JID.

        A bare JID does not have a resource part, so this returns a
        L{JID} object representing either C{user@host} or just C{host}.

        If the object this method is called upon doesn't have a resource
        set, it will return itself. Otherwise, the bare JID object will
        be created, interned using L{internJID}.

        @rtype: L{JID}
        )r   r#   r*   r)   r   r   r   ÚuserhostJID²   s   zJID.userhostJIDc                 C   sV   | j r| jr| j › d| j› d| j› S | j › d| j› S | jr(| j› d| j› S | jS )zW
        Return the string representation of this JID.

        @rtype: L{str}
        r   r   )r   r   r   r)   r   r   r   ÚfullÄ   s   zJID.fullÚotherr   c                 C   s2   t |tƒr| j|jko| j|jko| j|jkS tS )zá
        Equality comparison.

        L{JID}s compare equal if their user, host and resource parts all
        compare equal.  When comparing against instances of other types, it
        uses the default comparison.
        )Ú
isinstancer    r   r   r   ÚNotImplemented)r&   r-   r   r   r   Ú__eq__Õ   s   

ÿ
ýz
JID.__eq__c                 C   s   t | j| j| jfƒS )a  
        Calculate hash.

        L{JID}s with identical constituent user, host and resource parts have
        equal hash values.  In combination with the comparison defined on JIDs,
        this allows for using L{JID}s in sets and as dictionary keys.
        )Úhashr   r   r   r)   r   r   r   Ú__hash__æ   s   zJID.__hash__c                 C   s   |   ¡ S )zŽ
        Get unicode representation.

        Return the string representation of this JID as a unicode string.
        @see: L{full}
        ©r,   r)   r   r   r   Ú__unicode__ð   s   zJID.__unicode__c                 C   s   d|   ¡  S )z’
        Get object representation.

        Returns a string that would create a new JID object that compares equal
        to this one.
        zJID(%r)r3   r)   r   r   r   Ú__repr__ü   s   zJID.__repr__)NN)r	   r
   r   r   r   r   r   r(   r*   r+   r,   ÚobjectÚboolr0   r2   r4   Ú__str__r5   r   r   r   r   r    Š   s"    	ý
þ$
ý

)r   Útypingr   r   r   Ú.twisted.words.protocols.jabber.xmpp_stringprepr   r   r   Ú	Exceptionr   r   r   r   r!   Ú__annotations__r#   r    r   r   r   r   Ú<module>   s"   	,/
ÿÿ
ÿ
þ+