a
    î½jË  ã                   @   sî  d Z ddlmZmZ ddlZdZdZdZed Zed	 Z	ed
 Z
ed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed Zed  Z ed! Z!ed" Z"ed# Z#ed$ Z$ed% Z%ed& Z&d'Z'd(Z(e(d) Z)d*Z*d+Z+d,Z,d-Z-d.Z.d/Z/d0Z0d1Z1d2Z2d3Z3d4Z4d5Z5d6Z6d7Z7d8Z8d9Z9d:Z:d;Z;e;d< Z<e;d= Z=d>Z>d?Z?d@Z@dAZAdBZBdCZCdDZDdEZEdFZFdGZGdHZHdIZIdJZJdKZKdLZLeLdM ZMeLdN ZNeLdO ZOeLdP ZPeLdQ ZQeLdR ZReLdS ZSeLdT ZTeLdU ZUeLdV ZVdWZWdXZXdYZYdZZZd[Z[d\Z\d]Z]d^Z^d_Z_d`Z`daZadbZbdcZcddZddeZedfZfdgZgdhZhdiZidjZjdkZkdlZldmZmdnZndoZodpZpdqZqdrZrdsZsdtZtduZudvZvdwZwi i  ZxZyetdxeufejdyevfecdzewffD ]†\ZzZ{Z|e| }d{¡dd… D ]fZ~e~ }d|¡\ZZ€ZZ‚e{d} e ƒ¡  „d~d}¡ Z…ezd e e†ƒ e…< e€ee‚gexezd e < e€rÚeeye€< qÚq¾[z[{[|[~[[€[[‚d€d„ Z‡d‚dƒ„ ZˆG d„d…„ d…e‰ƒZŠG d†d‡„ d‡e‰ƒZ‹G dˆd‰„ d‰e‹ƒZŒG dŠd‹„ d‹e‹ƒZG dŒd„ de‹ƒZŽG dŽd„ de‹ƒZG dd‘„ d‘e‹ƒZG d’d“„ d“e‹ƒZ‘G d”d•„ d•e‹ƒZ’G d–d—„ d—e‹ƒZ“G d˜d™„ d™e‹ƒZ”G dšd›„ d›e‹ƒZ•G dœd„ de‹ƒZ–G dždŸ„ dŸe‹ƒZ—G d d¡„ d¡e‹ƒZ˜G d¢d£„ d£e‹ƒZ™G d¤d¥„ d¥e‹ƒZšG d¦d§„ d§e‹ƒZ›G d¨d©„ d©e‹ƒZœG dªd«„ d«e‹ƒZG d¬d­„ d­e‹ƒZžG d®d¯„ d¯e‹ƒZŸG d°d±„ d±e‹ƒZ G d²d³„ d³e‹ƒZ¡G d´dµ„ dµe‹ƒZ¢G d¶d·„ d·e‹ƒZ£eŒeeŽeee‘e’e“e”e•e–e—e˜e™eše›eœeežeŸe e¡e¢e£d¸œZ¤G d¹dº„ dºƒZ¥G d»d¼„ d¼eƒZ¦G d½d¾„ d¾e¦ƒZ§G d¿dÀ„ dÀe¦ƒZ¨G dÁdÂ„ dÂe¦ƒZ©G dÃdÄ„ dÄeƒZªG dÅdÆ„ dÆe¦ƒZ«G dÇdÈ„ dÈeƒZ¬G dÉdÊ„ dÊeƒZ­G dËdÌ„ dÌeƒZ®G dÍdÎ„ dÎeƒZ¯dS )Ïz_
Protocol module contains tools that is needed for processing of
xmpp-related data structures.
é   )ÚNodeÚustré    Nz#http://jabber.org/protocol/activityz"http://jabber.org/protocol/addressz http://jabber.org/protocol/adminz	#add-userz#delete-userz#disable-userz#reenable-userz#end-user-sessionz#get-user-passwordz#change-user-passwordz#get-user-rosterz#get-user-lastloginz#user-statsz#edit-blacklistz#edit-whitelistz#get-registered-users-numz#get-disabled-users-numz#get-online-users-numz#get-active-users-numz#get-idle-users-numz#get-registered-users-listz#get-disabled-users-listz#get-online-users-listz#get-active-users-listz#get-idle-users-listz	#announcez	#set-motdz
#edit-motdz#delete-motdz#set-welcomez#delete-welcomez#edit-adminz#restartz	#shutdownzjabber:iq:agentszhttp://jabber.org/protocol/ampz#errorszjabber:iq:authzjabber:iq:avatarz urn:ietf:params:xml:ns:xmpp-bindzjabber:iq:browsez&http://jabber.org/protocol/bytestreamszhttp://jabber.org/protocol/capsz%http://jabber.org/protocol/chatstateszjabber:clientz#http://jabber.org/protocol/commandszjabber:component:acceptz0http://jabberd.jabberstudio.org/ns/component/1.0z#http://jabber.org/protocol/compresszjabber:x:dataz'http://jabber.org/protocol/xdata-layoutz)http://jabber.org/protocol/xdata-validatezjabber:x:delayzjabber:server:dialbackz http://jabber.org/protocol/discoz#infoz#itemszjabber:x:encryptedzjabber:x:eventz&http://jabber.org/protocol/feature-negz3http://jabber.org/protocol/si/profile/file-transferzjabber:iq:gatewayz!http://jabber.org/protocol/geoloczgc-1.0z#http://jabber.org/protocol/httpbindzhttp://jabber.org/protocol/ibbzpresence-invisibleÚiqzjabber:iq:lastÚmessagezhttp://jabber.org/protocol/moodzhttp://jabber.org/protocol/mucz#adminz#ownerz#uniquez#userz	#registerz#requestz#roomconfigz	#roominfoz#roomsz#trafficzhttp://jabber.org/protocol/nickz"http://jabber.org/protocol/offlinez"http://jabber.org/protocol/physlocÚpresencezjabber:iq:privacyzjabber:iq:privatez!http://jabber.org/protocol/pubsubzjabber:iq:registerzhttp://jabber.org/protocol/rczjabber:iq:rosterz"http://jabber.org/protocol/rosterxzjabber:iq:rpcz urn:ietf:params:xml:ns:xmpp-saslzjabber:iq:searchzjabber:serverz#urn:ietf:params:xml:ns:xmpp-sessionzhttp://jabber.org/protocol/siz http://jabber.org/protocol/sipubzjabber:x:signedz#urn:ietf:params:xml:ns:xmpp-stanzasz http://etherx.jabber.org/streamszjabber:iq:timezurn:ietf:params:xml:ns:xmpp-tlsz#http://jabber.org/protocol/vacationz
vcard-tempzvcard-temp:x:updatezjabber:iq:versionz&http://jabber.org/protocol/waitinglistz#http://jabber.org/protocol/xhtml-imz#urn:ietf:params:xml:ns:xmpp-streamsaS  
bad-format --  --  -- The entity has sent XML that cannot be processed.
bad-namespace-prefix --  --  -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix.
conflict --  --  -- The server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream.
connection-timeout --  --  -- The entity has not generated any traffic over the stream for some period of time.
host-gone --  --  -- The value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server.
host-unknown --  --  -- The value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server.
improper-addressing --  --  -- A stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value).
internal-server-error --  --  -- The server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream.
invalid-from -- cancel --  -- The JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource authorization.
invalid-id --  --  -- The stream ID or dialback ID is invalid or does not match an ID previously provided.
invalid-namespace --  --  -- The streams namespace name is something other than "http://etherx.jabber.org/streams" or the dialback namespace name is something other than "jabber:server:dialback".
invalid-xml --  --  -- The entity has sent invalid XML over the stream to a server that performs validation.
not-authorized --  --  -- The entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation.
policy-violation --  --  -- The entity has violated some local service policy.
remote-connection-failed --  --  -- The server is unable to properly connect to a remote resource that is required for authentication or authorization.
resource-constraint --  --  -- The server lacks the system resources necessary to service the stream.
restricted-xml --  --  -- The entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character.
see-other-host --  --  -- The server will not provide service to the initiating entity but is redirecting traffic to another host.
system-shutdown --  --  -- The server is being shut down and all active streams are being closed.
undefined-condition --  --  -- The error condition is not one of those defined by the other conditions in this list.
unsupported-encoding --  --  -- The initiating entity has encoded the stream in an encoding that is not supported by the server.
unsupported-stanza-type --  --  -- The initiating entity has sent a first-level child of the stream that is not supported by the server.
unsupported-version --  --  -- The value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server.
xml-not-well-formed --  --  -- The initiating entity has sent XML that is not well-formed.a  
bad-request -- 400 -- modify -- The sender has sent XML that is malformed or that cannot be processed.
conflict -- 409 -- cancel -- Access cannot be granted because an existing resource or session exists with the same name or address.
feature-not-implemented -- 501 -- cancel -- The feature requested is not implemented by the recipient or server and therefore cannot be processed.
forbidden -- 403 -- auth -- The requesting entity does not possess the required permissions to perform the action.
gone -- 302 -- modify -- The recipient or server can no longer be contacted at this address.
internal-server-error -- 500 -- wait -- The server could not process the stanza because of a misconfiguration or an otherwise-undefined internal server error.
item-not-found -- 404 -- cancel -- The addressed JID or item requested cannot be found.
jid-malformed -- 400 -- modify -- The value of the 'to' attribute in the sender's stanza does not adhere to the syntax defined in Addressing Scheme.
not-acceptable -- 406 -- cancel -- The recipient or server understands the request but is refusing to process it because it does not meet criteria defined by the recipient or server.
not-allowed -- 405 -- cancel -- The recipient or server does not allow any entity to perform the action.
not-authorized -- 401 -- auth -- The sender must provide proper credentials before being allowed to perform the action, or has provided improper credentials.
payment-required -- 402 -- auth -- The requesting entity is not authorized to access the requested service because payment is required.
recipient-unavailable -- 404 -- wait -- The intended recipient is temporarily unavailable.
redirect -- 302 -- modify -- The recipient or server is redirecting requests for this information to another entity.
registration-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because registration is required.
remote-server-not-found -- 404 -- cancel -- A remote server or service specified as part or all of the JID of the intended recipient does not exist.
remote-server-timeout -- 504 -- wait -- A remote server or service specified as part or all of the JID of the intended recipient could not be contacted within a reasonable amount of time.
resource-constraint -- 500 -- wait -- The server or recipient lacks the system resources necessary to service the request.
service-unavailable -- 503 -- cancel -- The server or recipient does not currently provide the requested service.
subscription-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because a subscription is required.
undefined-condition -- 500 --  -- 
unexpected-request -- 400 -- wait -- The recipient or server understood the request but was not expecting it at this time (e.g., the request was out of order).aû  
aborted --  --  -- The receiving entity acknowledges an <abort/> element sent by the initiating entity; sent in reply to the <abort/> element.
incorrect-encoding --  --  -- The data provided by the initiating entity could not be processed because the [BASE64]Josefsson, S., The Base16, Base32, and Base64 Data Encodings, July 2003. encoding is incorrect (e.g., because the encoding does not adhere to the definition in Section 3 of [BASE64]Josefsson, S., The Base16, Base32, and Base64 Data Encodings, July 2003.); sent in reply to a <response/> element or an <auth/> element with initial response data.
invalid-authzid --  --  -- The authzid provided by the initiating entity is invalid, either because it is incorrectly formatted or because the initiating entity does not have permissions to authorize that ID; sent in reply to a <response/> element or an <auth/> element with initial response data.
invalid-mechanism --  --  -- The initiating entity did not provide a mechanism or requested a mechanism that is not supported by the receiving entity; sent in reply to an <auth/> element.
mechanism-too-weak --  --  -- The mechanism requested by the initiating entity is weaker than server policy permits for that initiating entity; sent in reply to a <response/> element or an <auth/> element with initial response data.
not-authorized --  --  -- The authentication failed because the initiating entity did not provide valid credentials (this includes but is not limited to the case of an unknown username); sent in reply to a <response/> element or an <auth/> element with initial response data.
temporary-auth-failure --  --  -- The authentication failed because of a temporary error condition within the receiving entity; sent in reply to an <auth/> element or <response/> element.ZSTREAMZERRZSASLÚ
z -- Ú_ú-ú c                 C   s   | o|   ¡ dkS )z/ Returns true if the node is a positive reply. Úresult©ÚgetType©Únode© r   úS/Users/admin/.hermes/hermes-agent/venv/lib/python3.9/site-packages/xmpp/protocol.pyÚisResultNodeÎ   s    r   c                 C   s   | o|   ¡ dkS )z/ Returns true if the node is a negative reply. Úerrorr   r   r   r   r   ÚisErrorNodeÑ   s    r   c                   @   s   e Zd ZdZdS )ÚNodeProcessedzQ Exception that should be raised by handler when the handling should be stopped. N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   Õ   s   r   c                   @   s   e Zd ZdZdS )ÚStreamErrorz( Base exception class for stream errors.Nr   r   r   r   r   r   ×   s   r   c                   @   s   e Zd ZdS )Ú	BadFormatN©r   r   r   r   r   r   r   r   Ù   ó    r   c                   @   s   e Zd ZdS )ÚBadNamespacePrefixNr   r   r   r   r   r    Ú   r   r    c                   @   s   e Zd ZdS )ÚConflictNr   r   r   r   r   r!   Û   r   r!   c                   @   s   e Zd ZdS )ÚConnectionTimeoutNr   r   r   r   r   r"   Ü   r   r"   c                   @   s   e Zd ZdS )ÚHostGoneNr   r   r   r   r   r#   Ý   r   r#   c                   @   s   e Zd ZdS )ÚHostUnknownNr   r   r   r   r   r$   Þ   r   r$   c                   @   s   e Zd ZdS )ÚImproperAddressingNr   r   r   r   r   r%   ß   r   r%   c                   @   s   e Zd ZdS )ÚInternalServerErrorNr   r   r   r   r   r&   à   r   r&   c                   @   s   e Zd ZdS )ÚInvalidFromNr   r   r   r   r   r'   á   r   r'   c                   @   s   e Zd ZdS )Ú	InvalidIDNr   r   r   r   r   r(   â   r   r(   c                   @   s   e Zd ZdS )ÚInvalidNamespaceNr   r   r   r   r   r)   ã   r   r)   c                   @   s   e Zd ZdS )Ú
InvalidXMLNr   r   r   r   r   r*   ä   r   r*   c                   @   s   e Zd ZdS )ÚNotAuthorizedNr   r   r   r   r   r+   å   r   r+   c                   @   s   e Zd ZdS )ÚPolicyViolationNr   r   r   r   r   r,   æ   r   r,   c                   @   s   e Zd ZdS )ÚRemoteConnectionFailedNr   r   r   r   r   r-   ç   r   r-   c                   @   s   e Zd ZdS )ÚResourceConstraintNr   r   r   r   r   r.   è   r   r.   c                   @   s   e Zd ZdS )ÚRestrictedXMLNr   r   r   r   r   r/   é   r   r/   c                   @   s   e Zd ZdS )ÚSeeOtherHostNr   r   r   r   r   r0   ê   r   r0   c                   @   s   e Zd ZdS )ÚSystemShutdownNr   r   r   r   r   r1   ë   r   r1   c                   @   s   e Zd ZdS )ÚUndefinedConditionNr   r   r   r   r   r2   ì   r   r2   c                   @   s   e Zd ZdS )ÚUnsupportedEncodingNr   r   r   r   r   r3   í   r   r3   c                   @   s   e Zd ZdS )ÚUnsupportedStanzaTypeNr   r   r   r   r   r4   î   r   r4   c                   @   s   e Zd ZdS )ÚUnsupportedVersionNr   r   r   r   r   r5   ï   r   r5   c                   @   s   e Zd ZdS )ÚXMLNotWellFormedNr   r   r   r   r   r6   ð   r   r6   )z
bad-formatzbad-namespace-prefixÚconflictzconnection-timeoutz	host-gonezhost-unknownzimproper-addressingzinternal-server-errorzinvalid-fromz
invalid-idzinvalid-namespacezinvalid-xmlznot-authorizedzpolicy-violationzremote-connection-failedzresource-constraintzrestricted-xmlzsee-other-hostzsystem-shutdownzundefined-conditionzunsupported-encodingzunsupported-stanza-typezunsupported-versionzxml-not-well-formedc                   @   s|   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zd dd„Zdd„ ZdS )!ÚJIDzW JID object. JID can be built from string, modified, compared, serialised into string. NÚ c                 C   sº   |s|st dƒ‚n¤t|ƒt| ƒkr@|j|j|j  | _| _| _nv|r\|||  | _| _| _nZ| d¡d r~| dd¡\| _}nd| _| d¡d r¨| dd¡\| _| _n|d | _| _dS )zÉ Constructor. JID can be specified as string (jid argument) or as separate parts.
            Examples:
            JID('node@domain/resource')
            JID(node='node',domain='domain.org')
        z%JID must contain at least domain nameú@r   r9   ú/N)Ú
ValueErrorÚtyper   ÚdomainÚresourceÚfindÚsplit)ÚselfÚjidr   r>   r?   r   r   r   Ú__init__  s    ."$zJID.__init__c                 C   s   | j S )z! Return the node part of the JID r   ©rB   r   r   r   ÚgetNode  s    zJID.getNodec                 C   s   |  ¡ | _dS )zQ Set the node part of the JID to new value. Specify None to remove the node part.N)Úlowerr   ©rB   r   r   r   r   ÚsetNode  s    zJID.setNodec                 C   s   | j S )z# Return the domain part of the JID )r>   rE   r   r   r   Ú	getDomain!  s    zJID.getDomainc                 C   s   |  ¡ | _dS )z- Set the domain part of the JID to new value.N)rG   r>   )rB   r>   r   r   r   Ú	setDomain$  s    zJID.setDomainc                 C   s   | j S )z% Return the resource part of the JID ©r?   rE   r   r   r   ÚgetResource'  s    zJID.getResourcec                 C   s
   || _ dS )zY Set the resource part of the JID to new value. Specify None to remove the resource part.NrL   )rB   r?   r   r   r   ÚsetResource*  s    zJID.setResourcec                 C   s
   |   d¡S )zH Return the bare representation of JID. I.e. string value w/o resource. r   )Ú__str__rE   r   r   r   ÚgetStripped-  s    zJID.getStrippedc                 C   sB   zt |ƒ}W n ty    Y dS 0 | j|jko@|  d¡| d¡kS )z@ Compare the JID to another instance or to string for equality. r   )r8   r<   r?   rO   ©rB   Úotherr   r   r   Ú__eq__0  s    z
JID.__eq__c                 C   s   |   |¡ S )zD Compare the JID to another instance or to string for non-equality. )rS   rQ   r   r   r   Ú__ne__5  s    z
JID.__ne__c                 C   s   |   d¡t|ƒ  d¡kS )z> Compare the node and domain parts of the JID's for equality. r   )rO   r8   rQ   r   r   r   Ú	bareMatch8  s    zJID.bareMatchr   c                 C   s:   | j r| j d | j }n| j}|r6| jr6|d | j S |S )z Serialise JID into string. r:   r;   )r   r>   r?   )rB   Z	wresourcerC   r   r   r   rO   ;  s    zJID.__str__c                 C   s   t |  ¡ ƒS )zO Produce hash of the JID, Allows to use JID objects as keys of the dictionary. )ÚhashrO   rE   r   r   r   Ú__hash__A  s    zJID.__hash__)Nr9   r9   r9   )r   )r   r   r   r   rD   rF   rI   rJ   rK   rM   rN   rP   rS   rT   rU   rO   rW   r   r   r   r   r8     s   

r8   c                	   @   s¨   e Zd ZdZddddi g dddf	dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd#dd„Zd$dd„Zdd „ Zd!d"„ ZdS )%ÚProtocolz\ A "stanza" object class. Contains methods that are common for presences, iqs and messages. Nc
                 C   s  |si }|r||d< |r ||d< |r,||d< t j| ||||	d |	sR|rR|  |¡ | d rh|  | d ¡ | d r~|  | d ¡ |	r°t| ƒt|	ƒkr°| j|	jkr°d| jv r°| jd= d| _| j	dt
dD ]@}
z.|  ¡ rä|
 d	¡|  ¡ k rô|  |
 d	¡¡ W qÄ   Y qÄ0 qÄ|dur|  |¡ dS )
aå   Constructor, name is the name of the stanza i.e. 'message' or 'presence' or 'iq'.
            to is the value of 'to' attribure, 'typ' - 'type' attribute
            frn - from attribure, attrs - other attributes mapping, payload - same meaning as for simplexml payload definition
            timestamp - the time value that needs to be stamped over stanza
            xmlns - namespace of top stanza node
            node - parsed or unparsed stana to be taken as prototype.
        ÚtoÚfromr=   )ÚtagÚattrsÚpayloadr   ÚidNÚx©Ú	namespaceÚstamp)r   rD   ÚsetNamespaceÚsetToÚsetFromr=   Ú	__class__r\   Ú	timestampÚgetTagsÚNS_DELAYÚgetTimestampÚgetAttrÚsetTimestamp)rB   ÚnamerY   ÚtypÚfrmr\   r]   rg   Úxmlnsr   r_   r   r   r   rD   G  s    2.zProtocol.__init__c                 C   s   z
| d W S    Y dS 0 dS )z% Return value of the 'to' attribute. rY   Nr   rE   r   r   r   ÚgetTo^  s    zProtocol.getToc                 C   s   z
| d W S    Y dS 0 dS )z' Return value of the 'from' attribute. rZ   Nr   rE   r   r   r   ÚgetFromb  s    zProtocol.getFromc                 C   s   | j S )z7 Return the timestamp in the 'yyyymmddThhmmss' format. )rg   rE   r   r   r   rj   f  s    zProtocol.getTimestampc                 C   s
   |   d¡S )z) Return the value of the 'id' attribute. r^   ©rk   rE   r   r   r   ÚgetIDi  s    zProtocol.getIDc                 C   s   |   dt|ƒ¡ dS )z& Set the value of the 'to' attribute. rY   N©ÚsetAttrr8   ©rB   Úvalr   r   r   rd   l  s    zProtocol.setToc                 C   s
   |   d¡S )z+ Return the value of the 'type' attribute. r=   rs   rE   r   r   r   r   o  s    zProtocol.getTypec                 C   s   |   dt|ƒ¡ dS )z( Set the value of the 'from' attribute. rZ   Nru   rw   r   r   r   re   r  s    zProtocol.setFromc                 C   s   |   d|¡ dS )z( Set the value of the 'type' attribute. r=   N©rv   rw   r   r   r   ÚsetTypeu  s    zProtocol.setTypec                 C   s   |   d|¡ dS )z& Set the value of the 'id' attribute. r^   Nry   rw   r   r   r   ÚsetIDx  s    zProtocol.setIDc                 C   s@   |   d¡}|r<| ¡ D ]}| ¡ dkr| ¡   S q| ¡ S dS )z^ Return the error-condition (if present) or the textual description of the error (otherwise). r   ÚtextN)ÚgetTagÚgetChildrenÚgetNameÚgetData)rB   Zerrtagr[   r   r   r   ÚgetError{  s
    
zProtocol.getErrorc                 C   s   |   dd¡S )z# Return the error code. Obsolette. r   Úcode)Z
getTagAttrrE   r   r   r   ÚgetErrorCode‚  s    zProtocol.getErrorCodec                 C   sz   |r@t |ƒtt ¡ ƒv r.ttt |ƒ |d}q`tt|d|d}n t|ƒtdƒtdƒfv r`t|ƒ}|  d¡ | j|d dS )z> Set the error code. Obsolette. Use error-conditions instead. )r|   Úcancel)r‚   rn   r|   r9   r   r   N)	ÚstrÚlistÚ_errorcodesÚkeysÚ	ErrorNodeZERR_UNDEFINED_CONDITIONr=   rz   ÚaddChild)rB   r   r‚   r   r   r   ÚsetError…  s    * 
zProtocol.setErrorc                 C   s4   |st  dt  ¡ ¡}|| _| jdd| jitd dS )zBSet the timestamp. timestamp should be the yyyymmddThhmmss string.z%Y%m%dT%H:%M:%Sr_   rb   r`   N)ÚtimeÚstrftimeÚgmtimerg   ÚsetTagri   rw   r   r   r   rl     s    zProtocol.setTimestampc                 C   s0   g }|   ¡ D ]}| ¡ }||vr| |¡ q|S )zL Return the list of namespaces to which belongs the direct childs of element)r~   ÚgetNamespaceÚappend)rB   ÚpropsÚchildÚpropr   r   r   ÚgetProperties’  s
    zProtocol.getPropertiesc                 C   s   |dv rt |ƒ}|  ||¡S )z( Set the item 'item' to the value 'val'.)rY   rZ   )r8   rv   )rB   Úitemrx   r   r   r   Ú__setitem__™  s    zProtocol.__setitem__)N)N)r   r   r   r   rD   rq   rr   rj   rt   rd   r   re   rz   r{   r   rƒ   r‹   rl   r•   r—   r   r   r   r   rX   E  s"   

rX   c                
   @   sh   e Zd ZdZddddi dg dedf
dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zddd„ZdS )ÚMessagez( XMPP Message stanza - "push" mechanism.Nc                 C   s>   t j| d|||||||	|
d
 |r,|  |¡ |r:|  |¡ dS )aS   Create message object. You can specify recipient, text of message, type of message
            any additional attributes, sender of the message, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
            Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as message. r   ©rY   rn   r\   ro   r]   rg   rp   r   N)rX   rD   ÚsetBodyÚ
setSubject)rB   rY   Úbodyrn   Úsubjectr\   ro   r]   rg   rp   r   r   r   r   rD      s    zMessage.__init__c                 C   s
   |   d¡S )z Returns text of the message. rœ   ©Ú
getTagDatarE   r   r   r   ÚgetBody§  s    zMessage.getBodyc                 C   s
   |   d¡S )z! Returns subject of the message. r   rž   rE   r   r   r   Ú
getSubjectª  s    zMessage.getSubjectc                 C   s
   |   d¡S )z  Returns thread of the message. Úthreadrž   rE   r   r   r   Ú	getThread­  s    zMessage.getThreadc                 C   s   |   d|¡ dS )z Sets the text of the message. rœ   N©Ú
setTagDatarw   r   r   r   rš   °  s    zMessage.setBodyc                 C   s   |   d|¡ dS )z" Sets the subject of the message. r   Nr¤   rw   r   r   r   r›   ³  s    zMessage.setSubjectc                 C   s   |   d|¡ dS )z! Sets the thread of the message. r¢   Nr¤   rw   r   r   r   Ú	setThread¶  s    zMessage.setThreadc                 C   s6   t |  ¡ |  ¡ ||  ¡ d}|  ¡ }|r2| |¡ |S )zª Builds and returns another message object with specified text.
            The to, from, thread and type properties of new message are pre-set as reply to this message. )rY   ro   rœ   rn   )r˜   rr   rq   r   r£   r¦   )rB   r|   ÚmÚthr   r   r   Ú
buildReply¹  s    zMessage.buildReply)N)r   r   r   r   Ú	NS_CLIENTrD   r    r¡   r£   rš   r›   r¦   r©   r   r   r   r   r˜   ž  s   r˜   c                   @   s¨   e Zd ZdZdddddi ddg edfdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ ZdS )#ÚPresencez XMPP Presence object.Nc                 C   sL   t j| d|||||	||
|d
 |r,|  |¡ |r:|  |¡ |rH|  |¡ dS )ar   Create presence object. You can specify recipient, type of message, priority, show and status values
            any additional attributes, sender of the presence, timestamp, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
            Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as presence. r   r™   N)rX   rD   ÚsetPriorityÚsetShowÚ	setStatus)rB   rY   rn   ÚpriorityÚshowÚstatusr\   ro   rg   r]   rp   r   r   r   r   rD   Ã  s    zPresence.__init__c                 C   s
   |   d¡S )z& Returns the priority of the message. r¯   rž   rE   r   r   r   ÚgetPriorityË  s    zPresence.getPriorityc                 C   s
   |   d¡S )z( Returns the show value of the message. r°   rž   rE   r   r   r   ÚgetShowÎ  s    zPresence.getShowc                 C   s
   |   d¡S )z+ Returns the status string of the message. r±   rž   rE   r   r   r   Ú	getStatusÑ  s    zPresence.getStatusc                 C   s   |   d|¡ dS )z# Sets the priority of the message. r¯   Nr¤   rw   r   r   r   r¬   Ô  s    zPresence.setPriorityc                 C   s   |   d|¡ dS )z% Sets the show value of the message. r°   Nr¤   rw   r   r   r   r­   ×  s    zPresence.setShowc                 C   s   |   d|¡ dS )z( Sets the status string of the message. r±   Nr¤   rw   r   r   r   r®   Ú  s    zPresence.setStatusc                 C   s4   |   d¡D ]$}|  |¡D ]}| |¡    S q
d S )Nr_   )rh   rk   )rB   r[   ÚattrÚxtagr“   r   r   r   Ú_muc_getItemAttrÞ  s    zPresence._muc_getItemAttrc                 C   sP   |   d¡D ]@}|  d¡D ]0}|  |¡D ] }| ¡ | |¡f      S qq
dS )Nr_   r–   )NN)rh   r€   rk   )rB   r[   rµ   r¶   r“   Zcchildr   r   r   Ú_muc_getSubTagDataAttrâ  s
    "zPresence._muc_getSubTagDataAttrc                 C   s   |   dd¡S )z)Returns the presence role (for groupchat)r–   Zrole©r·   rE   r   r   r   ÚgetRoleè  s    zPresence.getRolec                 C   s   |   dd¡S )z0Returns the presence affiliation (for groupchat)r–   Zaffiliationr¹   rE   r   r   r   ÚgetAffiliationë  s    zPresence.getAffiliationc                 C   s   |   dd¡S )z5Returns the nick value (for nick change in groupchat)r–   Znickr¹   rE   r   r   r   ÚgetNickî  s    zPresence.getNickc                 C   s   |   dd¡S )z(Returns the presence jid (for groupchat)r–   rC   r¹   rE   r   r   r   ÚgetJidñ  s    zPresence.getJidc                 C   s   |   dd¡d S )ú2Returns the reason of the presence (for groupchat)Úreasonr9   r   ©r¸   rE   r   r   r   Ú	getReasonô  s    zPresence.getReasonc                 C   s   |   dd¡d S )r¾   ZactorrC   r   rÀ   rE   r   r   r   ÚgetActor÷  s    zPresence.getActorc                 C   s   |   dd¡S )z7Returns the status code of the presence (for groupchat)r±   r‚   r¹   rE   r   r   r   ÚgetStatusCodeú  s    zPresence.getStatusCode)r   r   r   r   rª   rD   r²   r³   r´   r¬   r­   r®   r·   r¸   rº   r»   r¼   r½   rÁ   rÂ   rÃ   r   r   r   r   r«   Á  s"    r«   c                   @   s|   e Zd ZdZddi ddg edfdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
ddd„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚIqz, XMPP Iq object - get/set dialog mechanism. Nc	           	   
   C   s:   t j| d||||||d |r(|  |¡ |r6|  |¡ dS )aB   Create Iq object. You can specify type, query namespace
            any additional attributes, recipient of the iq, sender of the iq, any additional payload (f.e. jabber:x:data node) and namespace in one go.
            Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as an iq. r   )rY   rn   r\   ro   rp   r   N)rX   rD   ÚsetQueryPayloadÚ
setQueryNS)	rB   rn   ZqueryNSr\   rY   ro   r]   rp   r   r   r   r   rD      s    zIq.__init__c                 C   s:   |   ¡ }d}|  ¡ D ] }d|ks,d| ¡ kr|} q6q|S )z< Return the IQ's child element if it exists, None otherwise.Nr   )r   r~   r   )rB   rn   Úqueryr“   r   r   r   ÚgetQuery  s    zIq.getQueryc                 C   s   |   ¡ }|r| ¡ S dS )z3 Return the namespace of the 'query' child element.N)rÈ   r   ©rB   r[   r   r   r   Ú
getQueryNS  s    zIq.getQueryNSc                 C   s   |   ¡  d¡S )z@ Return the 'node' attribute value of the 'query' child element.r   )rÈ   rk   rE   r   r   r   ÚgetQuerynode  s    zIq.getQuerynodec                 C   s   |   ¡ }|r| ¡ S dS )z* Return the 'query' child element payload.N)rÈ   Z
getPayloadrÉ   r   r   r   ÚgetQueryPayload  s    zIq.getQueryPayloadc                 C   s   |   ¡ }|r| ¡ S dS )z. Return the 'query' child element child nodes.N)rÈ   r~   rÉ   r   r   r   ÚgetQueryChildren  s    zIq.getQueryChildrenc                 C   s0   |   ¡ }|du r|  d¡}|dur,| |¡ |S )z› Change the name of the query node, creating it if needed. Keep the existing name if none is given (use 'query' if it's a creation). Return the query node.NrÇ   )rÈ   rŠ   ÚsetName)rB   rm   rÇ   r   r   r   ÚsetQuery  s    

zIq.setQueryc                 C   s   |   ¡  |¡ dS )z0 Set the namespace of the 'query' child element.N)rÏ   rc   )rB   ra   r   r   r   rÆ   '  s    zIq.setQueryNSc                 C   s   |   ¡  |¡ dS )z' Set the 'query' child element payload.N)rÏ   Z
setPayload)rB   r]   r   r   r   rÅ   *  s    zIq.setQueryPayloadc                 C   s   |   ¡  d|¡ dS )z= Set the 'node' attribute value of the 'query' child element.r   N)rÏ   rv   rH   r   r   r   ÚsetQuerynode-  s    zIq.setQuerynodec                 C   s@   t ||  ¡ |  ¡ d|  ¡ id}| |  ¡  ¡ ¡ |  ¡ ¡ |S )z’ Builds and returns another Iq object of specified type.
            The to, from and query child node of new Iq are pre-set as reply to this Iq. r^   )rY   ro   r\   )	rÄ   rr   rq   rt   rÏ   rÈ   r   rc   rÊ   )rB   rn   r   r   r   r   r©   0  s     zIq.buildReply)N)r   r   r   r   rª   rD   rÈ   rÊ   rË   rÌ   rÍ   rÏ   rÆ   rÅ   rÐ   r©   r   r   r   r   rÄ   þ  s   	
rÄ   c                   @   s   e Zd ZdZddd„ZdS )r‰   z¨ XMPP-style error element.
        In the case of stanza error should be attached to XMPP stanza.
        In the case of stream-level errors should be used separately. Nc           	      C   s¶   |t v r$t | \}}}| ¡ d }ndtddf\}}}}|r@|}|rH|}|rP|}t | di t|ƒg¡ |rv|  d|¡ |s„|  d¡ |r¢| jt|d i |gƒd	 |r²|  d
|¡ dS )zÍ Create new error node object.
            Mandatory parameter: name - name of error condition.
            Optional parameters: code, typ, text. Used for backwards compartibility with older XMPP protocol.r   Ú500r„   r9   r   r=   zstream:errorz textr   r‚   N)ÚERRORSrA   Ú
NS_STANZASr   rD   rv   rÎ   rŠ   )	rB   rm   r‚   rn   r|   Zcodr=   ÚtxtÚnsr   r   r   rD   ;  s    zErrorNode.__init__)NNN)r   r   r   r   rD   r   r   r   r   r‰   7  s   r‰   c                   @   s$   e Zd ZdZddd„Zd	dd„ZdS )
ÚErrorz< Used to quickly transform received stanza into error reply.r   c                 C   sP   |r t j| | ¡ | ¡ |d nt j| |d |  |¡ | ¡ dkrL| j| _dS )a   Create error reply basing on the received 'node' stanza and the 'error' error condition.
            If the 'node' is not the received stanza but locally created ('to' and 'from' fields needs not swapping)
            specify the 'reply' argument as false.)rY   ro   r   r   r   N)rX   rD   rr   rq   r‹   r   Ú
__dupstr__rO   )rB   r   r   Zreplyr   r   r   rD   N  s     
zError.__init__Nc                 C   s   dS )z¨ Dummy function used as preventor of creating error node in reply to error node.
            I.e. you will not be able to serialise "double" error into string.
        r9   r   )rB   Zdup1Údup2r   r   r   r×   V  s    zError.__dupstr__)r   )NN)r   r   r   r   rD   r×   r   r   r   r   rÖ   L  s   
rÖ   c                   @   s¼   e Zd ZdZddddddg dfdd„Zd+dd„Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ ZdS ),Ú	DataFieldzÚ This class is used in the DataForm class to describe the single data item.
        If you are working with jabber:x:data (XEP-0004, XEP-0068, XEP-0122)
        then you will need to work with instances of this class. Nr   c	           	      C   s¦   t j| d|d |r|  |¡ t|ƒttfv r:|  |¡ n|rH|  |¡ |rX|  |¡ n|sj|sj|  d¡ |rx|  	|¡ |r†|  
|¡ |r”|  |¡ |r¢|  |¡ dS )a   Create new data field of specified name,value and type.
            Also 'required','desc' and 'options' fields can be set.
            Alternatively other XML object can be passed in as the 'node' parameted to replicate it as a new datafiled.
            Úfieldr   ztext-singleN)r   rD   ÚsetVarr=   r†   ÚtupleÚ	setValuesÚsetValuerz   ÚsetRequiredÚsetLabelÚsetDescÚ
setOptions)	rB   rm   Úvaluern   ÚrequiredÚlabelÚdescÚoptionsr   r   r   r   rD   `  s    zDataField.__init__r   c                 C   s8   |r|   d¡ n$z|  d¡ W n ty2   Y dS 0 dS )z* Change the state of the 'required' flag. rä   N)r   ÚdelChildr<   )rB   Úreqr   r   r   rß   o  s    zDataField.setRequiredc                 C   s
   |   d¡S )z' Returns in this field a required one. rä   ©r}   rE   r   r   r   Ú
isRequiredu  s    zDataField.isRequiredc                 C   s   |   d|¡ dS )z Set the label of this field. rå   Nry   )rB   rå   r   r   r   rà   x  s    zDataField.setLabelc                 C   s
   |   d¡S )z! Return the label of this field. rå   rs   rE   r   r   r   ÚgetLabel{  s    zDataField.getLabelc                 C   s   |   d|¡ dS )z$ Set the description of this field. ræ   Nr¤   )rB   ræ   r   r   r   rá   ~  s    zDataField.setDescc                 C   s
   |   d¡S )z' Return the description of this field. ræ   rž   rE   r   r   r   ÚgetDesc  s    zDataField.getDescc                 C   s   |   d|¡ dS )z Set the value of this field. rã   Nr¤   rw   r   r   r   rÞ   „  s    zDataField.setValuec                 C   s
   |   d¡S )Nrã   rž   rE   r   r   r   ÚgetValue‡  s    zDataField.getValuec                 C   s.   |   d¡r|  d¡ q |D ]}|  |¡ qdS )z” Set the values of this field as values-list.
            Replaces all previous filed values! If you need to just add a value - use addValue method.rã   N)r}   rè   ÚaddValue)rB   Úlstrx   r   r   r   rÝ   ‰  s    zDataField.setValuesc                 C   s   |   di |g¡ dS )z> Add one more value to this field. Used in 'get' iq's or such.rã   N©rŠ   rw   r   r   r   rï   Ž  s    zDataField.addValuec                 C   s&   g }|   d¡D ]}| | ¡ ¡ q|S )z6 Return the list of values associated with this field.rã   )rh   r‘   r€   ©rB   Úretr[   r   r   r   Ú	getValues‘  s    zDataField.getValuesc                 C   s2   g }|   d¡D ]}| | d¡| d¡g¡ q|S )z; Return label-option pairs list associated with this field.Úoptionrå   rã   )rh   r‘   rk   rŸ   rò   r   r   r   Ú
getOptions–  s    *zDataField.getOptionsc                 C   s.   |   d¡r|  d¡ q |D ]}|  |¡ qdS )z8 Set label-option pairs list associated with this field.rõ   N)r}   rè   Ú	addOption)rB   rð   Úoptr   r   r   râ   ›  s    zDataField.setOptionsc                 C   sH   t |ƒttfv r$|  d¡ d|¡ n |  dd|d i¡ d|d ¡ dS )z. Add one more label-option pair to this field.rõ   rã   rå   r   r   N)r=   r…   rŠ   r¥   )rB   rø   r   r   r   r÷   Ÿ  s    $zDataField.addOptionc                 C   s
   |   d¡S )z Get type of this field. r=   rs   rE   r   r   r   r   £  s    zDataField.getTypec                 C   s   |   d|¡S )z Set type of this field. r=   ry   rw   r   r   r   rz   ¦  s    zDataField.setTypec                 C   s
   |   d¡S )z* Get 'var' attribute value of this field. Úvarrs   rE   r   r   r   ÚgetVar©  s    zDataField.getVarc                 C   s   |   d|¡S )z* Set 'var' attribute value of this field. rù   ry   rw   r   r   r   rÛ   ¬  s    zDataField.setVar)r   )r   r   r   r   rD   rß   rë   rà   rì   rá   rí   rÞ   rî   rÝ   rï   rô   rö   râ   r÷   r   rz   rú   rÛ   r   r   r   r   rÙ   \  s(   
rÙ   c                   @   sD   e Zd ZdZddd„Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Z	dS )ÚDataReportedas   This class is used in the DataForm class to describe the 'reported data field' data items which are used in
        'multiple item form results' (as described in XEP-0004).
        Represents the fields that will be returned from a search. This information is useful when
        you try to use the jabber:iq:search namespace to return dynamic form information.
        Nc                 C   sX   t j| d|d |rTg }|  ¡ D ],}| ¡ dkrB| t|d¡ q | |¡ q || _dS )aÌ   Create new empty 'reported data' field. However, note that, according XEP-0004:
            * It MUST contain one or more DataFields.
            * Contained DataFields SHOULD possess a 'type' and 'label' attribute in addition to 'var' attribute
            * Contained DataFields SHOULD NOT contain a <value/> element.
            Alternatively other XML object can be passed in as the 'node' parameted to replicate it as a new
            dataitem.
        Úreportedr   rÚ   N©r   rD   r~   r   r‘   rÙ   Úkids©rB   r   ÚnewkidsÚnr   r   r   rD   ¶  s    zDataReported.__init__c                 C   s   | j dd|idS ©z; Return the datafield object with name 'name' (if exists). rÚ   rù   )r\   rê   ©rB   rm   r   r   r   ÚgetFieldÅ  s    zDataReported.getFieldc                 C   s*   |   |¡}|r|S | jt|d|d|ƒdS )z® Create if nessessary or get the existing datafield object with name 'name' and return it.
            If created, attributes 'type' and 'label' are applied to new datafield.Nr   r   ©r  rŠ   rÙ   )rB   rm   rn   rå   Úfr   r   r   ÚsetFieldÈ  s    
zDataReported.setFieldc                 C   s   i }|   d¡D ]f}| d¡}| ¡ }t|tƒrb|dd… dkrbg }|  d¡D ]}| | ¡ ¡ qLn
| d¡}|||< q|  d¡rŒ|  	¡ |d< |S ©zT Represent dataitem as simple dictionary mapping of datafield names to their values.rÚ   rù   éúÿÿÿNú-multirã   Úinstructions©
rh   rk   r   Ú
isinstancer…   r‘   r€   rŸ   r}   ÚgetInstructions©rB   ró   rÚ   rm   rn   rx   Úir   r   r   ÚasDictÎ  s    
 

zDataReported.asDictc                 C   s"   |   |¡}|r| ¡ S tdƒ‚dS ©zJ Simple dictionary interface for getting datafields values by their names.zNo such fieldN©r  rî   Ú
IndexError©rB   rm   r–   r   r   r   Ú__getitem__Û  s    
zDataReported.__getitem__c                 C   s   |   |¡ |¡S ©zJ Simple dictionary interface for setting datafields values by their names.©r  rÞ   ©rB   rm   rx   r   r   r   r—   à  s    zDataReported.__setitem__)N)NN©
r   r   r   r   rD   r  r  r  r  r—   r   r   r   r   rû   °  s   

rû   c                   @   sB   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚDataItemzœ This class is used in the DataForm class to describe data items which are used in 'multiple
        item form results' (as described in XEP-0004).
        Nc                 C   sX   t j| d|d |rTg }|  ¡ D ],}| ¡ dkrB| t|d¡ q | |¡ q || _dS )a    Create new empty data item. However, note that, according XEP-0004, DataItem MUST contain ALL
            DataFields described in DataReported.
            Alternatively other XML object can be passed in as the 'node' parameted to replicate it as a new
            dataitem.
            r–   r   rÚ   Nrý   rÿ   r   r   r   rD   è  s    zDataItem.__init__c                 C   s   | j dd|idS r  rê   r  r   r   r   r  õ  s    zDataItem.getFieldc                 C   s"   |   |¡}|r|S | jt|ƒdS ©z[ Create if nessessary or get the existing datafield object with name 'name' and return it. r   r  ©rB   rm   r  r   r   r   r  ø  s    
zDataItem.setFieldc                 C   s   i }|   d¡D ]f}| d¡}| ¡ }t|tƒrb|dd… dkrbg }|  d¡D ]}| | ¡ ¡ qLn
| d¡}|||< q|  d¡rŒ|  	¡ |d< |S r  r  r  r   r   r   r  ý  s    
 

zDataItem.asDictc                 C   s"   |   |¡}|r| ¡ S tdƒ‚dS r  r  r  r   r   r   r  
  s    
zDataItem.__getitem__c                 C   s   |   |¡ |¡S r  r  r  r   r   r   r—     s    zDataItem.__setitem__)Nr  r   r   r   r   r  ä  s   
r  c                   @   s‚   e Zd ZdZdg ddfdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚDataFormz¥ DataForm class. Used for manipulating dataforms in XMPP.
        Relevant XEPs: 0004, 0068, 0122.
        Can be used in disco, pub-sub and many other applications.Nc           
      C   sŽ  t j| d|d |rg }|  ¡ D ]h}| ¡ dkrB| t|d¡ q | ¡ dkr`| t|d¡ q | ¡ dkr~| t|d¡ q | |¡ q || _|rž|  	|¡ |  
t¡ |r¶|  |¡ t|ƒti ƒkrôg }t| ¡ ƒD ]}| t||| ƒ¡ qÖ|}|D ]}	t|	ƒtdƒtdƒfv r"|  |	¡ qø|	jjdkr>| j |	¡ qø|	jjdkrZ| j |	¡ qø|	jjd	krv| j |	¡ qø| j t|	d¡ qød
S )a$  
            Create new dataform of type 'typ'; 'data' is the list of DataReported,
            DataItem and DataField instances that this dataform contains; 'title'
            is the title string.
            You can specify the 'node' argument as the other node to be used as
            base for constructing this dataform.

            title and instructions is optional and SHOULD NOT contain newlines.
            Several instructions MAY be present.
            'typ' can be one of ('form' | 'submit' | 'cancel' | 'result' )
            'typ' of reply iq can be ( 'result' | 'set' | 'set' | 'result' ) respectively.
            'cancel' form can not contain any fields. All other forms contains AT LEAST one field.
            'title' MAY be included in forms of type "form" and "result"
        r_   r   rÚ   r–   rü   r9   rÙ   r  rû   N)r   rD   r~   r   r‘   rÙ   r  rû   rþ   rz   rc   ÚNS_DATAÚsetTitler=   r†   rˆ   ÚaddInstructionsrf   r   )
rB   rn   ÚdataÚtitler   r   r  Únewdatarm   r“   r   r   r   rD     s,    
&&zDataForm.__init__c                 C   s
   |   d¡S )z Return the type of dataform. r=   rs   rE   r   r   r   r   <  s    zDataForm.getTypec                 C   s   |   d|¡ dS )z Set the type of dataform. r=   Nry   )rB   rn   r   r   r   rz   ?  s    zDataForm.setTypec                 C   s
   |   d¡S )z Return the title of dataform. r#  rž   rE   r   r   r   ÚgetTitleB  s    zDataForm.getTitlec                 C   s   |   d|¡ dS )z Set the title of dataform. r#  Nr¤   ©rB   r|   r   r   r   r   E  s    zDataForm.setTitlec                 C   s
   |   d¡S )z& Return the instructions of dataform. r  rž   rE   r   r   r   r  H  s    zDataForm.getInstructionsc                 C   s   |   d|¡ dS )z# Set the instructions of dataform. r  Nr¤   r&  r   r   r   ÚsetInstructionsK  s    zDataForm.setInstructionsc                 C   s   |   di |g¡ dS )z+ Add one more instruction to the dataform. r  Nrñ   r&  r   r   r   r!  N  s    zDataForm.addInstructionsc                 C   s   | j dd|idS r  rê   r  r   r   r   r  Q  s    zDataForm.getFieldc                 C   s"   |   |¡}|r|S | jt|ƒdS r  r  r  r   r   r   r  T  s    
zDataForm.setFieldc                 C   s   i }|   d¡D ]f}| d¡}| ¡ }t|tƒrb|dd… dkrbg }|  d¡D ]}| | ¡ ¡ qLn
| d¡}|||< q|  d¡rŒ|  	¡ |d< |S )zT Represent dataform as simple dictionary mapping of datafield names to their values.rÚ   rù   r	  Nr
  rã   r  r  r  r   r   r   r  Y  s    
 

zDataForm.asDictc                 C   s"   |   |¡}|r| ¡ S tdƒ‚dS r  r  r  r   r   r   r  f  s    
zDataForm.__getitem__c                 C   s   |   |¡ |¡S r  r  r  r   r   r   r—   k  s    zDataForm.__setitem__)r   r   r   r   rD   r   rz   r%  r   r  r'  r!  r  r  r  r  r—   r   r   r   r   r    s   %r  )°r   Z	simplexmlr   r   rŒ   ZNS_ACTIVITYZ
NS_ADDRESSZNS_ADMINZNS_ADMIN_ADD_USERZNS_ADMIN_DELETE_USERZNS_ADMIN_DISABLE_USERZNS_ADMIN_REENABLE_USERZNS_ADMIN_END_USER_SESSIONZNS_ADMIN_GET_USER_PASSWORDZNS_ADMIN_CHANGE_USER_PASSWORDZNS_ADMIN_GET_USER_ROSTERZNS_ADMIN_GET_USER_LASTLOGINZNS_ADMIN_USER_STATSZNS_ADMIN_EDIT_BLACKLISTZNS_ADMIN_EDIT_WHITELISTZNS_ADMIN_REGISTERED_USERS_NUMZNS_ADMIN_DISABLED_USERS_NUMZNS_ADMIN_ONLINE_USERS_NUMZNS_ADMIN_ACTIVE_USERS_NUMZNS_ADMIN_IDLE_USERS_NUMZNS_ADMIN_REGISTERED_USERS_LISTZNS_ADMIN_DISABLED_USERS_LISTZNS_ADMIN_ONLINE_USERS_LISTZNS_ADMIN_ACTIVE_USERS_LISTZNS_ADMIN_IDLE_USERS_LISTZNS_ADMIN_ANNOUNCEZNS_ADMIN_SET_MOTDZNS_ADMIN_EDIT_MOTDZNS_ADMIN_DELETE_MOTDZNS_ADMIN_SET_WELCOMEZNS_ADMIN_DELETE_WELCOMEZNS_ADMIN_EDIT_ADMINZNS_ADMIN_RESTARTZNS_ADMIN_SHUTDOWNZ	NS_AGENTSZNS_AMPZNS_AMP_ERRORSZNS_AUTHZ	NS_AVATARZNS_BINDZ	NS_BROWSEZNS_BYTESTREAMZNS_CAPSZNS_CHATSTATESrª   ZNS_COMMANDSZNS_COMPONENT_ACCEPTZNS_COMPONENT_1ZNS_COMPRESSr  ZNS_DATA_LAYOUTZNS_DATA_VALIDATEri   ZNS_DIALBACKZNS_DISCOZNS_DISCO_INFOZNS_DISCO_ITEMSZNS_ENCRYPTEDZNS_EVENTZ
NS_FEATUREZNS_FILEZ
NS_GATEWAYZ	NS_GEOLOCZNS_GROUPCHATZNS_HTTP_BINDZNS_IBBZNS_INVISIBLEZNS_IQZNS_LASTZ
NS_MESSAGEZNS_MOODZNS_MUCZNS_MUC_ADMINZNS_MUC_OWNERZNS_MUC_UNIQUEZNS_MUC_USERZNS_MUC_REGISTERZNS_MUC_REQUESTZNS_MUC_ROOMCONFIGZNS_MUC_ROOMINFOZNS_MUC_ROOMSZNS_MUC_TRAFICZNS_NICKZ
NS_OFFLINEZ
NS_PHYSLOCZNS_PRESENCEZ
NS_PRIVACYZ
NS_PRIVATEZ	NS_PUBSUBZNS_REGISTERZNS_RCZ	NS_ROSTERZ
NS_ROSTERXZNS_RPCZNS_SASLZ	NS_SEARCHZ	NS_SERVERZ
NS_SESSIONZNS_SIZ	NS_SI_PUBZ	NS_SIGNEDrÓ   Z
NS_STREAMSZNS_TIMEZNS_TLSZNS_VACATIONZNS_VCARDZNS_VCARD_UPDATEZ
NS_VERSIONZNS_WAITINGLISTZNS_XHTML_IMZNS_XMPP_STREAMSZxmpp_stream_error_conditionsZxmpp_stanza_error_conditionsZsasl_error_conditionsrÒ   r‡   rÕ   ZerrnameZerrpoolrA   ÚerrZcondr‚   rn   r|   ÚupperÚreplacerm   Úlocalsr   r   Ú	Exceptionr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   Zstream_exceptionsr8   rX   r˜   r«   rÄ   r‰   rÖ   rÙ   rû   r  r  r   r   r   r   Ú<module>   s‚  	
þé:Y#=9T4/