Package pypat :: Package behavioral :: Module chain
[hide private]
[frames] | no frames]

Source Code for Module pypat.behavioral.chain

 1  from abc import ABCMeta, abstractmethod 
42   
43 44 -class Chain(object, metaclass=ABCMeta):
45 """ 46 Abstract Chain class as part of the Chain of Responsibility pattern. 47 48 - External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage} 49 - External Chain of Responsibility Pattern documentation: U{https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern} 50 """
51 - def __init__(self, chainlink):
52 """ 53 Initialize a new Chain instance. 54 55 @param chainlink: The starting chain link. 56 """ 57 self.chainlink = chainlink
58
59 - def handle(self, request):
60 """ 61 Handle a request. 62 63 @param request: The request to handle. 64 """ 65 try: 66 return self.chainlink.handle(request) 67 except AttributeError: 68 return self.fail()
69 70 @abstractmethod
71 - def fail(self):
72 """ 73 The method to call when the chain could not handle a request. 74 """ 75 pass
76