Mix-ins for Start/Finish handling

develop
RusAnon 2010-05-03 18:02:16 +11:00
parent 3ccb7783c9
commit 7ac5b9a1fe
1 changed files with 56 additions and 0 deletions

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
"""
Mix-ins for bound classes
"""
class NeedsStart(object):
"""
This mixin enforces Start/Finish routines
"""
started = False
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.Start()
return self.started
else:
return False
def Start(self):
if self.api.prepare():
self.started = self.cls.Start(self)
return self.started
else:
return False
start = Start
def Finish(self):
if self.started:
self.cls.Finish(self)
self.started = False
finish = Finish
class NoStart(object):
"""
This mixin enforces Suspend, and disables Start/Finish
"""
def prepare(self):
"""
Enforce Suspend
"""
return self.api.prepare()
def Start(self):
raise Exception("{0.cls} does not need Start()".format(self))
start = Start
def Finish(self):
raise Exception("{0.cls} does not need Finish()".format(self))
finish = Finish