All pastes #165699 Raw Edit

Cody Brocious

public python v1 · immutable
·published 2006-09-10 02:29 UTC
rendered paste body
#!/usr/bin/env python# encoding: utf-8"""fsm.pyCreated by Cody Brocious on 2006-09-09.Copyright (c) 2006 Falling Leaf Systems, LLC. All rights reserved."""class FSM:	def __init__(self):		self.old_state = None		self.state = self.startState		def run(self):		"""			Run state machine		"""		while True:			new_state = self.state(self.old_state)			self.old_state = self.state			self.state = new_state						if self.state == None or self.state == False:				break				return self.old_state		def startState(self, old_state):		"""			Initializes my state machine		"""		self.counter = 0				return self.runState		def runState(self, old_state):		"""			Increments my counter		"""				self.counter += 1				if self.counter % 1000 == 0:			return self.logState		else:			return self.runState		def logState(self, old_state):		"""			Logs my state output		"""				print 'Counter state', self.counter				if self.counter == 50000:			return self.endState		else:			return self.runState		def endState(self, old_state):		"""			Ends execution		"""				print 'Finished'				return Noneif __name__ == '__main__':    FSM().run()