def tree2commands(self, adapter, session, lastcmds, xsync):
<EOL>assert xsync.tag == constants.NODE_SYNCML<EOL>assert len(xsync) == <NUM_LIT:2><EOL>assert xsync[<NUM_LIT:0>].tag == constants.CMD_SYNCHDR<EOL>assert xsync[<NUM_LIT:1>].tag == constants.NODE_SYNCBODY<EOL>version = xsync[<NUM_LIT:0>].findtext('<STR_LIT>')<EOL>if version != constants.SYNCML_VERSION_1_2:<EOL><INDENT>raise common.FeatureNotSupported('<STR_LIT>'% (version, constants.SYNCML_VERSION_1_2))<EOL><DEDENT>verdtd = xsync[<NUM_LIT:0>].findtext('<STR_LIT>')<EOL>if verdtd != constants.SYNCML_DTD_VERSION_1_2:<EOL><INDENT>raise common.FeatureNotSupported('<STR_LIT>'% (verdtd, constants.SYNCML_DTD_VERSION_1_2))<EOL><DEDENT>ret = self.initialize(adapter, session, xsync)<EOL>hdrcmd = ret[<NUM_LIT:0>]<EOL>if session.isServer:<EOL><INDENT>log.debug('<STR_LIT>',<EOL>hdrcmd.target, hdrcmd.sessionID, hdrcmd.msgID)<EOL><DEDENT>else:<EOL><INDENT>log.debug('<STR_LIT>',<EOL>lastcmds[<NUM_LIT:0>].target, lastcmds[<NUM_LIT:0>].sessionID, lastcmds[<NUM_LIT:0>].msgID)<EOL><DEDENT>try:<EOL><INDENT>return self._tree2commands(adapter, session, lastcmds, xsync, ret)<EOL><DEDENT>except Exception as e:<EOL><INDENT>if not session.isServer:<EOL><INDENT>raise<EOL><DEDENT>code = '<STR_LIT>' % (e.__class__.__module__, e.__class__.__name__)<EOL>msg  = '<STR_LIT>'.join(traceback.format_exception_only(type(e), e)).strip()<EOL>log.exception('<STR_LIT>', msg)<EOL>return [<EOL>hdrcmd,<EOL>state.Command(<EOL>name       = constants.CMD_STATUS,<EOL>cmdID      = '<STR_LIT:1>',<EOL>msgRef     = session.pendingMsgID,<EOL>cmdRef     = <NUM_LIT:0>,<EOL>sourceRef  = xsync[<NUM_LIT:0>].findtext('<STR_LIT>'),<EOL>targetRef  = xsync[<NUM_LIT:0>].findtext('<STR_LIT>'),<EOL>statusOf   = constants.CMD_SYNCHDR,<EOL>statusCode = constants.STATUS_COMMAND_FAILED,<EOL>errorCode  = code,<EOL>errorMsg   = msg,<EOL>errorTrace = '<STR_LIT>'.join(traceback.format_exception(type(e), e, sys.exc_info()[<NUM_LIT:2>])),<EOL>),<EOL>state.Command(name=constants.CMD_FINAL)]<EOL><DEDENT>
Consumes an ET protocol tree and converts it to state.Command commands