def setup_stanza_handlers(self, handler_objects, usage_restriction):
<EOL>iq_handlers = {"<STR_LIT>": {}, "<STR_LIT>": {}}<EOL>message_handlers = []<EOL>presence_handlers = []<EOL>for obj in handler_objects:<EOL><INDENT>if not isinstance(obj, XMPPFeatureHandler):<EOL><INDENT>continue<EOL><DEDENT>obj.stanza_processor = self<EOL>for dummy, handler in inspect.getmembers(obj, callable):<EOL><INDENT>if not hasattr(handler, "<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>element_name, stanza_type = handler._pyxmpp_stanza_handled<EOL>restr = handler._pyxmpp_usage_restriction<EOL>if restr and restr != usage_restriction:<EOL><INDENT>continue<EOL><DEDENT>if element_name == "<STR_LIT>":<EOL><INDENT>payload_class = handler._pyxmpp_payload_class_handled<EOL>payload_key = handler._pyxmpp_payload_key<EOL>if (payload_class, payload_key) in iq_handlers[stanza_type]:<EOL><INDENT>continue<EOL><DEDENT>iq_handlers[stanza_type][(payload_class, payload_key)] =handler<EOL>continue<EOL><DEDENT>elif element_name == "<STR_LIT:message>":<EOL><INDENT>handler_list = message_handlers<EOL><DEDENT>elif element_name == "<STR_LIT>":<EOL><INDENT>handler_list = presence_handlers<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>handler_list.append(handler)<EOL><DEDENT><DEDENT>with self.lock:<EOL><INDENT>self._iq_handlers = iq_handlers<EOL>self._presence_handlers = presence_handlers<EOL>self._message_handlers = message_handlers<EOL><DEDENT>
Install stanza handlers provided by `handler_objects`