On Thu, May 28, 2015 at 9:01 AM, Marko Rauhamaa <[email protected]> wrote:
> Anssi Saari <[email protected]>:
>
>> Do you have an example of state pattern using nested classes and
>> python? With a quick look I didn't happen to find one in any language.
>
> Here's an sampling from my mail server:
I think I would be more inclined to use enums. This has the advantages
of not creating a new set of state classes for every connection
instance and that each state is a singleton instance, allowing things
like "if self.state is SMTPConnectionState.IDLE". It could look
something like this:
class SMTPConnectionState(Enum):
class IDLE:
@classmethod
def handle_command(cls, conn, cmd):
# ...
class SPF_HELO:
@classmethod
def terminate(cls, conn):
# ...
--
https://mail.python.org/mailman/listinfo/python-list