def _wait_method(self, channel_id, allowed_methods, timeout=None):
<EOL>method_queue = self.channels[channel_id].method_queue<EOL>for queued_method in method_queue:<EOL><INDENT>method_sig = queued_method[<NUM_LIT:0>]<EOL>if (allowed_methods is None)or (method_sig in allowed_methods)or (method_sig == (<NUM_LIT:20>, <NUM_LIT>)):<EOL><INDENT>method_queue.remove(queued_method)<EOL>return queued_method<EOL><DEDENT><DEDENT>read_timeout = self.read_timeout<EOL>wait = self.wait<EOL>while <NUM_LIT:1>:<EOL><INDENT>channel, method_sig, args, content = read_timeout(timeout)<EOL>if channel == channel_id and (<EOL>allowed_methods is None or<EOL>method_sig in allowed_methods or<EOL>method_sig == (<NUM_LIT:20>, <NUM_LIT>)):<EOL><INDENT>return method_sig, args, content<EOL><DEDENT>if channel and method_sig in self.Channel._IMMEDIATE_METHODS:<EOL><INDENT>self.channels[channel].dispatch_method(<EOL>method_sig, args, content,<EOL>)<EOL>continue<EOL><DEDENT>self.channels[channel].method_queue.append(<EOL>(method_sig, args, content),<EOL>)<EOL>if not channel:<EOL><INDENT>wait()<EOL><DEDENT><DEDENT>
Wait for a method from the server destined for
        a particular channel.