Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. def executor(f):
  2.     def wrapper(self, *args, **kwargs):
  3.         f(self)
  4.         command = args[0]
  5.         getattr(self, command)(*args[1:], **kwargs)
  6.     return wrapper
  7.  
  8.  
  9. class Commands:
  10.     def __init__(self):
  11.         self.voda_v_kastrule = False
  12.         self.voda_v_chainike = False
  13.  
  14.     @executor
  15.     def pelmeshki(self):
  16.         self.voda_v_kastrule = not self.voda_v_kastrule
  17.         print('nalit vodu v kastrule' if self.voda_v_kastrule else 'slit vodu from kastrule')
  18.  
  19.     def svarit(self, count, sol=0):
  20.         print('varim', count)
  21.         print('sol', sol)
  22.  
  23.     def est(self, count, mayonaze=None):
  24.         print('em', count)
  25.         print('mayonaze', mayonaze)
  26.  
  27.     @executor
  28.     def chai(self):
  29.         if not self.voda_v_chainike:
  30.             self.voda_v_chainike = True
  31.             print('nalit vodu v chainike')
  32.  
  33.     def zavarit(self, count, chai_type='chorny'):
  34.         print('zavarit na', count, chai_type)
  35.  
  36.  
  37. c = Commands()
  38. pipeline = [
  39.     ('pelmeshki', (('svarit', 5), {'sol': '2'})),
  40.     ('pelmeshki', (('est', 4), {'mayonaze': True})),
  41.     ('chai', (('zavarit', 2), {'chai_type': 'zeleny'})),
  42. ]
  43. for action in pipeline:
  44.     getattr(c, action[0])(*action[1][0], **action[1][1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement