
    Yf(                        d Z ddlZddlmZ ddlmZ dZdZdZi dd	d
dddddddddddddddd
ddddddddddd	d
dddd
dddddd d!ddd"d#ddd$dddd%dd
dd&d'ddd(dddd)d*dddddd+ddd'dddddd	ddd,Z	i dd-d	d.d!d/d#d0dd1dd2dd3dd4d'd5d6d7dd8dd9dd:d;d<d+d=d*d7d>d=Z
 G d? d@e          Z G dA dBe          Z G dC dDe          ZdE ZdF ZdG ZdS )Hz
XMPP Error support.
    N)Optional)domishz$http://www.w3.org/XML/1998/namespacez#urn:ietf:params:xml:ns:xmpp-streamsz#urn:ietf:params:xml:ns:xmpp-stanzasbad-request400modify)codetypeconflict409cancelfeature-not-implemented501	forbidden403authgone302internal-server-error500waititem-not-found404zjid-malformednot-acceptable406not-allowed405not-authorized401payment-required402zrecipient-unavailableredirectregistration-required407zremote-server-not-foundremote-server-timeout504503)zresource-constraintservice-unavailablezsubscription-requiredzundefined-conditionzunexpected-request)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r"   r   408)r$   r   )r
   r   )r   r   )r   r   502)r'   r   )r'   r   510c                   H    e Zd ZU dZdZee         ed<   ddZdefdZ	d Z
dS )		BaseErroraK  
    Base class for XMPP error exceptions.

    @cvar namespace: The namespace of the C{error} element generated by
                     C{getElement}.
    @type namespace: C{str}
    @ivar condition: The error condition. The valid values are defined by
                     subclasses of L{BaseError}.
    @type contition: C{str}
    @ivar text: Optional text message to supplement the condition or application
                specific condition.
    @type text: C{unicode}
    @ivar textLang: Identifier of the language used for the message in C{text}.
                    Values are as described in RFC 3066.
    @type textLang: C{str}
    @ivar appCondition: Application specific condition element, supplementing
                        the error condition in C{condition}.
    @type appCondition: object providing L{domish.IElement}.
    N	namespacec                 r    t                               |            || _        || _        || _        || _        d S )N)	Exception__init__	conditiontexttextLangappCondition)selfr1   r2   r3   r4   s        V/var/www/html/env/lib/python3.11/site-packages/twisted/words/protocols/jabber/error.pyr0   zBaseError.__init__Y   s9    4   "	 (    returnc                 x    d                     | j        j        | j                  }| j        r|d| j        z   z  }|S )Nz{} with condition {!r}z: )format	__class____name__r1   r2   )r5   messages     r6   __str__zBaseError.__str__`   sE    *11N#T^
 
 9 	(tdi''Gr7   c                 6   t          j        d          }|                    | j        | j        f           | j        r;|                    | j        df| j                  }| j        r| j        |t          df<   | j        r|	                    | j                   |S )z
        Get XML representation from self.

        The method creates an L{domish} representation of the
        error data contained in this exception.

        @rtype: L{domish.Element}
        )Nerrorr2   )contentlang)
r   Element
addElementr-   r1   r2   r3   NS_XMLr4   addChild)r5   r@   r2   s      r6   
getElementzBaseError.getElementj   s     //$.$.9:::9 	7##T^V$<di#PPD} 7)-ff%& 	.NN4,---r7   )NNN)r<   
__module____qualname____doc__r-   r   str__annotations__r0   r>   rG    r7   r6   r,   r,   B   st          (  $Ix}###) ) ) )        r7   r,   c                       e Zd ZdZeZd ZdS )StreamErrorzq
    Stream Error exception.

    Refer to RFC 3920, section 4.7.3, for the allowed values for C{condition}.
    c                 T    ddl m} t                              |           }||_        |S )z
        Get XML representation from self.

        Overrides the base L{BaseError.getElement} to make sure the returned
        element is in the XML Stream namespace.

        @rtype: L{domish.Element}
        r   )
NS_STREAMS)(twisted.words.protocols.jabber.xmlstreamrQ   r,   rG   uri)r5   rQ   r@   s      r6   rG   zStreamError.getElement   s6     	HGGGGG$$T**	r7   N)r<   rH   rI   rJ   NS_XMPP_STREAMSr-   rG   rM   r7   r6   rO   rO   ~   s4           I    r7   rO   c                   ,    e Zd ZdZeZ	 ddZd Zd ZdS )StanzaErrora  
    Stanza Error exception.

    Refer to RFC 3920, section 9.3, for the allowed values for C{condition} and
    C{type}.

    @ivar type: The stanza error type. Gives a suggestion to the recipient
                of the error on how to proceed.
    @type type: C{str}
    @ivar code: A numeric identifier for the error condition for backwards
                compatibility with pre-XMPP Jabber implementations.
    Nc                    t                               | ||||           |%	 t          |         d         }n# t          $ r Y nw xY w|| _        	 t          |         d         | _        n# t          $ r
 d | _        Y nw xY wg | _        d | _        d S )Nr	   r   )r,   r0   STANZA_CONDITIONSKeyErrorr	   r   childreniq)r5   r1   r	   r2   r3   r4   s         r6   r0   zStanzaError.__init__   s     	4D(LIII<(3F;   		))4V<DII 	 	 	DIII	 s!   6 
AAA' 'A;:A;c                 p    t                               |           }| j        |d<   | j        r
| j        |d<   |S )z
        Get XML representation from self.

        Overrides the base L{BaseError.getElement} to make sure the returned
        element has a C{type} attribute and optionally a legacy C{code}
        attribute.

        @rtype: L{domish.Element}
        r	   r   )r,   rG   r	   r   )r5   r@   s     r6   rG   zStanzaError.getElement   s<     $$T**	f9 	& IE&Mr7   c                     ddl m}  ||d          }t          j        |j                  |_        |                    |                                            |S )a  
        Construct error response stanza.

        The C{stanza} is transformed into an error response stanza by
        swapping the C{to} and C{from} addresses and inserting an error
        element.

        @note: This creates a shallow copy of the list of child elements of the
               stanza. The child elements themselves are not copied themselves,
               and references to their parent element will still point to the
               original stanza element.

               The serialization of an element does not use the reference to
               its parent, so the typical use case of immediately sending out
               the constructed error response is not affected.

        @param stanza: the stanza to respond to
        @type stanza: L{domish.Element}
        r   )
toResponser@   )
stanzaType)rR   r^   copyrZ   rF   rG   )r5   stanzar^   responses       r6   r^   zStanzaError.toResponse   sb    ( 	HGGGGG:f999 Ifo66$//++,,,r7   )NNNN)	r<   rH   rI   rJ   NS_XMPP_STANZASr-   r0   rG   r^   rM   r7   r6   rV   rV      s^           I LP   (       r7   rV   c                     d}d}d}d}|                                  D ]N}|j        |k    r?|j        dk    r,t          |          }|                    t
          df          }D|j        }L|}O||||dS )a  
    Parses an error element.

    @param error: The error element to be parsed
    @type error: L{domish.Element}
    @param errorNamespace: The namespace of the elements that hold the error
                           condition and text.
    @type errorNamespace: C{str}
    @return: Dictionary with extracted error information. If present, keys
             C{condition}, C{text}, C{textLang} have a string value,
             and C{appCondition} has an L{domish.Element} value.
    @rtype: C{dict}
    Nr2   rB   )r1   r2   r3   r4   )elementsrS   namerK   getAttributerE   )r@   errorNamespacer1   r2   r3   r4   elements          r6   _parseErrorrj      s     IDHL>>## # #;.((|v%%7||"//0@AA#L		"LL $	  r7   c                     t          | t                    }t          |d         |d         |d         |d                   }|S )z
    Build an exception object from a stream error.

    @param element: the stream error
    @type element: L{domish.Element}
    @return: the generated exception object
    @rtype: L{StreamError}
    r1   r2   r3   r4   )rj   rT   rO   )ri   r@   	exceptions      r6   exceptionFromStreamErrorrm     sF     11EkE&M5+<eN>S I r7   c                 $   g }dx}x}x}x}x}}|                                  D ]}|j        dk    r|j        | j        k    r|                    d          }|                    d          }t	          |t
                    }	|	d         }|	d         }|	d         }|	d         }|s&|r$t          |         \  }}t          | j                  }|	                    |           |t          d          S t          |||||          }
||
_        | |
_        |
S )	z
    Build an exception object from an error stanza.

    @param stanza: the error stanza
    @type stanza: L{domish.Element}
    @return: the generated exception object
    @rtype: L{StanzaError}
    Nr@   r   r	   r1   r2   r3   r4   )re   rf   rS   rg   rj   rc   CODES_TO_CONDITIONSrK   r@   appendrV   rZ   ra   )ra   rZ   r1   r2   r3   r4   r	   r   ri   r@   rl   s              r6   exceptionFromStanzarq     s8    H?CCICCxC,C??$$ % %<7""w{fj'@'@''//D''//D99Ek*I=DZ(H 0L ) )"5d";	46<((OOG$$$$4   ItT8\JJI!IIr7   )rJ   r`   typingr   twisted.words.xishr   rE   rT   rc   rX   ro   r/   r,   rO   rV   rj   rm   rq   rM   r7   r6   <module>rt      s   
        % % % % % %	/77E84411 x@@ %00	
 UH-- eV<< uh77 eX66 uh77 E844 uf55 77 eV<< 11 eV<<  x@@!" eV<<#$ %*6::$)8<<&+V<<$)488#(&99-   2		$ 
% 
'	
 
  
' 
$ 
' 
, 
, 
! 
, 
0 
* 
,  
,!" 
,# *9 9 9 9 9	 9 9 9x    )   2M M M M M) M M M`" " "J  $% % % % %r7   