
    tf                     :   U d Z ddlmZmZmZ ddlmZmZmZ  G d de	          Z
dedeeedf         eeedf         f         f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Zi Zeedf         ed<   d Z G 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                       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__     a/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/words/protocols/jabber/jid.pyr
   r
      s           r   r
   	jidstringreturnNc                    d}d}d}|                      d          }|                      d          }|dk    r#|dk    r| }n| d|         }| |dz   d         pd}nn|dk    r| d|         pd}| |dz   d         }nN||k     r/| d|         pd}| |dz   |||z
  z            }| |dz   d         pd}n| d|         }| |dz   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{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_seps         r   parser       s6    DDH ~~c""HnnS!!G2~~b==DD QwY'D 1/74HHb==QxZ(0DDX\^^,DD'!! 8,4 AGh<N0O!OP$Wq[]]3;t !7+$Wq[]]3;tdH%%%r   r   r   r   c                    | r@	 t          j        t          |                     } n# t          $ r t	          d          w xY wd} |st	          d          	 t          j        t          |                    }n# t          $ r t	          d          w xY w|r@	 t          j        t          |                    }n# t          $ r t	          d          w xY 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   s      r   r   r   M   s-      	A#CII..DD 	A 	A 	A ?@@@	A  A6777	A#CII..DD 	A 	A 	A ?@@@	A  	A#+CMM::HH 	A 	A 	A ?@@@	A $!!s!   !& A !A9 9B!B; ;CJID__internJIDsc                 d    | t           v rt           |          S t          |           }|t           | <   |S )z2
    Return interned JID.

    @rtype: L{JID}
    )r&   r%   )r   js     r   	internJIDr)   {   s4     L  I&&	NN"#Yr   c                       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Zd Zd Z	d Z
d	ed
efdZd Zd ZeZd
ef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                     |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   ress         r   __init__zJID.__init__   sh    
  	#CjjOD$ 	"ElOD$Q   		r   c                 @    | 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.   s    r   userhostzJID.userhost   s.     9 	i--$)---9r   c                 V    | 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)   r3   r2   s    r   userhostJIDzJID.userhostJID   s)     = 	T]]__---Kr   c                     | j         r1| 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   r2   s    r   fullzJID.full   s|     9 		!} 2)AAdiAA$-AAA)11di111} !)55dm555y r   otherr   c                     t          |t                    r0| 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.   r8   s     r   __eq__z
JID.__eq__   sQ     eS!! 	"	UZ' 4I+4MU^3 "!r   c                 D    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   r2   s    r   __hash__zJID.__hash__   s     TY	4=9:::r   c                 *    |                                  S )z
        Get unicode representation.

        Return the string representation of this JID as a unicode string.
        @see: L{full}
        r7   r2   s    r   __unicode__zJID.__unicode__   s     yy{{r   c                 0    d|                                  z  S )z
        Get object representation.

        Returns a string that would create a new JID object that compares equal
        to this one.
        zJID(%r)rA   r2   s    r   __repr__zJID.__repr__   s     499;;&&r   )NN)r   r   r   r   r   r#   r   r0   r3   r5   r7   objectboolr<   r?   rB   __str__rD   r   r   r   r%   r%      s         !%MQ 39 U5d+S%T	2BBCTIJ   $    $! ! !""F "t " " " ""; ; ;   G'# ' ' ' ' ' 'r   )r   typingr   r   r   .twisted.words.protocols.jabber.xmpp_stringprepr   r   r   	Exceptionr
   r#   r    r   r&   __annotations__r)   r%   r   r   r   <module>rL      s     & % % % % % % % % %             I   ,&S ,&U5d#3S%T	:J#JK ,& ,& ,& ,&^("
T	
(""%("16sDy1A("
5dS%T	"223(" (" (" ("V "$d3: # # #  y' y' y' y' y' y' y' y' y' y'r   