def handle_segment_ended(self):
if self._state[<NUM_LIT:1>].value.endevent is not None:<EOL><INDENT>self.events.append((self._state[<NUM_LIT:1>].value.endevent, self._state[<NUM_LIT:0>], None))<EOL><DEDENT>if self._state[<NUM_LIT:1>].value.multiplier is <NUM_LIT:2>:<EOL><INDENT>self.parentismap = <NUM_LIT:0><EOL>self.waitingforprop = <NUM_LIT:0><EOL><DEDENT>if(len(self._stack) is  <NUM_LIT:0>):<EOL><INDENT>self._scstate = ScannerState.IDLE            <EOL>return       <EOL><DEDENT>if self._state[<NUM_LIT:1>].value.valuetype is not ValueType.RAW:<EOL><INDENT>self._stack[-<NUM_LIT:1>][<NUM_LIT:3>] = self._stack[-<NUM_LIT:1>][<NUM_LIT:3>] - <NUM_LIT:1>  <EOL><DEDENT>if self._stack[-<NUM_LIT:1>][<NUM_LIT:3>] is <NUM_LIT:0>:<EOL><INDENT>self._scstate = ScannerState.SEGMENT_ENDED<EOL>self._state = self._stack.pop()  <EOL>if self._state[<NUM_LIT:1>].value.multiplier is <NUM_LIT:2>:<EOL><INDENT>self.parentismap = <NUM_LIT:1><EOL>self.waitingforprop = <NUM_LIT:1><EOL><DEDENT>self.handle_segment_ended()<EOL><DEDENT>else:<EOL><INDENT>if self._stack[-<NUM_LIT:1>][<NUM_LIT:1>].value.multiplier is <NUM_LIT:2>:<EOL><INDENT>self.parentismap = <NUM_LIT:1><EOL>self.waitingforprop = <NUM_LIT:1><EOL><DEDENT>self._scstate = ScannerState.WAITING_FOR_HEADER<EOL><DEDENT>
process end of the segment based on template