o b(@sdZddlZddlmZddlmZdZdZdZidd d d d d dd dddd dddd ddd d dddd dddd dd d d ddd d dddd d d!dd d"d#dd d$ddd d%dd d d&d'dd d(ddd d)d*dd ddd d+dd d'dd ddd d dd d,Z idd-d d.d!d/d#d0dd1dd2dd3dd4d'd5d6d7d d8dd9dd:d;d<d+d=d*d7d>d=Z Gd?d@d@e Z GdAdBdBe Z GdCdDdDe ZdEdFZdGdHZdIdJZdS)Kz 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-request400modify)codetypeconflict409cancelfeature-not-implemented501 forbidden403authgone302internal-server-error500waititem-not-found404z jid-malformednot-acceptable406 not-allowed405not-authorized401payment-required402zrecipient-unavailableredirectregistration-required407zremote-server-not-foundremote-server-timeout504503)zresource-constraintservice-unavailablezsubscription-requiredzundefined-conditionzunexpected-request)rr)rr)rr)rr)rr)rr )rr )rr)r!r408)r#r)r r )rr)r r 502)r&r)r&r 510c@sBeZdZUdZdZeeed<d ddZdefddZ d d Z dS) 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 namespacecCs&t|||_||_||_||_dS)N) Exception__init__ conditiontexttextLang appCondition)selfr.r/r0r1r3F/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/error.pyr-Ys  zBaseError.__init__returncCs*d|jj|j}|jr|d|j7}|S)Nz{} with condition {!r}z: )format __class____name__r.r/)r2messager3r3r4__str__`s  zBaseError.__str__cCsbtd}||j|jf|jr&|j|jdf|jd}|jr&|j|tdf<|jr/| |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} )Nerrorr/)contentlang) rElement addElementr+r.r/r0NS_XMLr1addChild)r2r;r/r3r3r4 getElementjs  zBaseError.getElement)NNN) r8 __module__ __qualname____doc__r+rstr__annotations__r-r:rBr3r3r3r4r*Bs   r*c@seZdZdZeZddZdS) StreamErrorzq Stream Error exception. Refer to RFC 3920, section 4.7.3, for the allowed values for C{condition}. cCs ddlm}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.xmlstreamrIr*rBuri)r2rIr;r3r3r4rBs zStreamError.getElementN)r8rCrDrENS_XMPP_STREAMSr+rBr3r3r3r4rH~s rHc@s0eZdZdZeZ d ddZddZddZdS) 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. NcCst||||||durzt|d}Wn tyYnw||_z t|d|_Wn ty7d|_Ynwg|_d|_dS)Nrr)r*r-STANZA_CONDITIONSKeyErrorrrchildreniq)r2r.rr/r0r1r3r3r4r-s    zStanzaError.__init__cCs(t|}|j|d<|jr|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} rr)r*rBrr)r2r;r3r3r4rBs  zStanzaError.getElementcCs8ddlm}||dd}t|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)rJrRcopyrPrArB)r2stanzarRresponser3r3r4rRs  zStanzaError.toResponse)NNNN) r8rCrDrENS_XMPP_STANZASr+r-rBrRr3r3r3r4rMs   rMcCsdd}d}d}d}|D]}|j|kr(|jdkr$t|}|tdf}q |j}q |}q ||||dS)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} Nr/r=)r.r/r0r1)elementsrKnamerF getAttributer@)r;errorNamespacer.r/r0r1elementr3r3r4 _parseErrors    r]cCs,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} r.r/r0r1)r]rLrH)r\r; exceptionr3r3r4exceptionFromStreamError s r_c Csg}d}}}}}}|D]A}|jdkrN|j|jkrN|d}|d}t|t} | d}| d}| d}| d}|sM|rMt|\}}t|j}q| |q|dur\t dSt |||||} || _ || _ | 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;rrr.r/r0r1) rXrYrKrZr]rWCODES_TO_CONDITIONSrFr;appendrMrPrU) rUrPr.r/r0r1rrr\r;r^r3r3r4exceptionFromStanzas,        rb)rErTtypingrtwisted.words.xishrr@rLrWrNr`r,r*rHrMr]r_rbr3r3r3r4s                        <P%