def process_frame(self, frame):
cmd_method = frame.cmd.lower()<EOL>if not cmd_method in VALID_COMMANDS:<EOL><INDENT>raise ProtocolError("<STR_LIT>".format(frame.cmd))<EOL><DEDENT>method = getattr(self, cmd_method, None)<EOL>if not self.engine.connected and method not in (self.connect, self.stomp):<EOL><INDENT>raise ProtocolError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>transaction = frame.headers.get('<STR_LIT>')<EOL>if not transaction or method in (self.begin, self.commit, self.abort):<EOL><INDENT>method(frame)<EOL><DEDENT>else:<EOL><INDENT>if not transaction in self.engine.transactions:<EOL><INDENT>raise ProtocolError(<EOL>"<STR_LIT>" % transaction)<EOL><DEDENT>self.engine.transactions[transaction].append(frame)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>self.engine.log.error("<STR_LIT>" % e)<EOL>self.engine.log.exception(e)<EOL>try:<EOL><INDENT>self.engine.connection.send_frame(ErrorFrame(str(e), str(e)))<EOL><DEDENT>except Exception as e:  <EOL><INDENT>self.engine.log.error("<STR_LIT>" % e)<EOL>self.engine.log.exception(e)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if frame.headers.get('<STR_LIT>') and method != self.connect:<EOL><INDENT>self.engine.connection.send_frame(ReceiptFrame(<EOL>receipt=frame.headers.get('<STR_LIT>')))<EOL><DEDENT><DEDENT>
Dispatches a received frame to the appropriate internal method.

@param frame: The frame that was received.
@type frame: C{stompclient.frame.Frame}