o ¯bßã@stUdZddlmZddlmZmZmZGdd„deƒZdd„Z dd „Z iZ ee d fe d <d d „ZGdd „d ƒ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}. é)ÚDict)ÚnameprepÚnodeprepÚ resourceprepc@seZdZdZdS)Ú 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.pyrsrcCsôd}d}d}| d¡}| d¡}|dkr,|dkr|}nY|d|…}||dd…p*d}nH|dkrA|d|…p7d}||dd…}n3||krd|d|…pLd}||d|||…}||dd…pbd}n|d|…}||dd…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)Ú jidstringÚuserÚhostÚresourceÚuser_sepÚres_sepr r r Úparses(      rcCs¤|rz t t|ƒ¡}Wn tytdƒ‚wd}|stdƒ‚z t t|ƒ¡}Wn ty3tdƒ‚w|rKz t t|ƒ¡}Wn tyJtdƒ‚wd}|||fS)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} zInvalid character in usernameNzServer address required.zInvalid character in hostnamezInvalid character in resource)rÚprepareÚstrÚ UnicodeErrorrrr)rrrr r r rMs, ÿ ÿ ÿ rÚJIDÚ __internJIDscCs$|tvrt|St|ƒ}|t|<|S)z2 Return interned JID. @rtype: L{JID} )rr)rÚjr r r Ú internJIDys r c@sfeZdZdZddd„Zdd„Zdd„Zd d „Zd ed e fd d„Z dd„Z dd„Z e Z d efdd„ZdS)rz‰ Represents a stringprep'd Jabber ID. JID objects are hashable so they can be used in sets and as keys in dictionaries. NcCsH|s|stdƒ‚|rt|ƒ\}}}nt|Ž\}}}||_||_||_dS)Nz?You must provide a value for either 'str' or 'tuple' arguments.)Ú RuntimeErrorrrrrr)ÚselfrÚtuplerrÚresr r r Ú__init__sÿ z JID.__init__cCs|jr |j›d|j›S|jS)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 )rr©r"r r r ÚuserhostŸs z JID.userhostcCs|jr 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} )rr r'r&r r r Ú userhostJID­s zJID.userhostJIDcCsV|jr|jr|j›d|j›d|j›S|j›d|j›S|jr(|j›d|j›S|jS)zW Return the string representation of this JID. @rtype: L{str} r r)rrrr&r r r Úfull¿szJID.fullÚotherÚreturncCs2t|tƒr|j|jko|j|jko|j|jkStS)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. )Ú isinstancerrrrÚNotImplemented)r"r*r r r Ú__eq__Ðs   ÿ ýz JID.__eq__cCst|j|j|jfƒ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. )Úhashrrrr&r r r Ú__hash__ász JID.__hash__cCs| ¡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__ëszJID.__unicode__cCs d| ¡S)z’ Get object representation. Returns a string that would create a new JID object that compares equal to this one. zJID(%r)r1r&r r r Ú__repr__÷s z JID.__repr__)NN)rrr r r%r'r(r)ÚobjectÚboolr.r0r2Ú__str__rr3r r r r rˆs   N)r ÚtypingrÚ.twisted.words.protocols.jabber.xmpp_stringpreprrrÚ ExceptionrrrrrÚ__annotations__r rr r r r Ús /)