<s> """<STR_LIT>""" <EOL> __docformat__ = "<STR_LIT>" <EOL> from . etree import ElementClass <EOL> from . stanza import Stanza <EOL> IQ_TYPES = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:result>" , "<STR_LIT:error>" ) <EOL> class Iq ( Stanza ) : <EOL> """<STR_LIT>""" <EOL> element_name = "<STR_LIT:message>" <EOL> def __init__ ( self , element = None , from_jid = None , to_jid = None , <EOL> stanza_type = None , stanza_id = None , <EOL> error = None , error_cond = None , return_path = None , <EOL> language = None ) : <EOL> """<STR_LIT>""" <EOL> if stanza_type is None : <EOL> if element is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif stanza_type not in IQ_TYPES : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if element is None and stanza_id is None and stanza_type in ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) : <EOL> stanza_id = self . gen_id ( ) <EOL> if element is None : <EOL> element = "<STR_LIT>" <EOL> elif not isinstance ( element , ElementClass ) : <EOL> raise TypeError ( "<STR_LIT>" + repr ( element ) ) <EOL> Stanza . __init__ ( self , element , from_jid = from_jid , to_jid = to_jid , <EOL> stanza_type = stanza_type , stanza_id = stanza_id , <EOL> error = error , error_cond = error_cond , <EOL> return_path = return_path , language = language ) <EOL> if self . element_name != "<STR_LIT>" : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> result = Iq ( None , self . from_jid , self . to_jid , <EOL> self . stanza_type , self . stanza_id , self . error , <EOL> self . _return_path ( ) ) <EOL> if self . _payload is None : <EOL> self . decode_payload ( ) <EOL> for payload in self . _payload : <EOL> Stanza . add_payload ( result , payload ) <EOL> return result <EOL> def make_error_response ( self , cond ) : <EOL> """<STR_LIT>""" <EOL> if self . stanza_type in ( "<STR_LIT:result>" , "<STR_LIT:error>" ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> stanza = Iq ( stanza_type = "<STR_LIT:error>" , from_jid = self . to_jid , <EOL> to_jid = self . from_jid , stanza_id = self . stanza_id , <EOL> error_cond = cond ) <EOL> if self . _payload is None : <EOL> self . decode_payload ( ) <EOL> for payload in self . _payload : <EOL> Stanza . add_payload ( stanza , payload ) <EOL> return stanza <EOL> def make_result_response ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . stanza_type not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> stanza = Iq ( stanza_type = "<STR_LIT:result>" , from_jid = self . to_jid , <EOL> to_jid = self . from_jid , stanza_id = self . stanza_id ) <EOL> return stanza <EOL> def add_payload ( self , payload ) : <EOL> """<STR_LIT>""" <EOL> if self . _payload is None : <EOL> self . decode_payload ( ) <EOL> if len ( self . _payload ) >= <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return Stanza . add_payload ( self , payload ) </s>
