def events(self):<EOL>
while self._events:<EOL><INDENT>yield self._events.popleft()<EOL><DEDENT>try:<EOL><INDENT>for frame in self._proto.received_frames():<EOL><INDENT>if frame.opcode is Opcode.PING:<EOL><INDENT>assert frame.frame_finished and frame.message_finished<EOL>yield Ping(payload=frame.payload)<EOL><DEDENT>elif frame.opcode is Opcode.PONG:<EOL><INDENT>assert frame.frame_finished and frame.message_finished<EOL>yield Pong(payload=frame.payload)<EOL><DEDENT>elif frame.opcode is Opcode.CLOSE:<EOL><INDENT>code, reason = frame.payload<EOL>if self.state is ConnectionState.LOCAL_CLOSING:<EOL><INDENT>self._state = ConnectionState.CLOSED<EOL><DEDENT>else:<EOL><INDENT>self._state = ConnectionState.REMOTE_CLOSING<EOL><DEDENT>yield CloseConnection(code=code, reason=reason)<EOL><DEDENT>elif frame.opcode is Opcode.TEXT:<EOL><INDENT>yield TextMessage(<EOL>data=frame.payload,<EOL>frame_finished=frame.frame_finished,<EOL>message_finished=frame.message_finished,<EOL>)<EOL><DEDENT>elif frame.opcode is Opcode.BINARY:<EOL><INDENT>yield BytesMessage(<EOL>data=frame.payload,<EOL>frame_finished=frame.frame_finished,<EOL>message_finished=frame.message_finished,<EOL>)<EOL><DEDENT><DEDENT><DEDENT>except ParseFailed as exc:<EOL><INDENT>yield CloseConnection(code=exc.code, reason=str(exc))<EOL><DEDENT>
Return a generator that provides any events that have been generated
by protocol activity.

:returns: generator of :class:`Event <wsproto.events.Event>` subclasses