comparison pyikriam/lazy/www/work/__init__.py @ 62:a4c364888197

add ikriam game binding lib python version
author hychen@mluna
date Wed, 22 Oct 2008 04:04:32 +0800
parents
children 60c4b4b78a01
comparison
equal deleted inserted replaced
60:610bbe1824ef 62:a4c364888197
1 from lazy.www.work.fetch import Fetcher
2 from lazy.www.work.find import Finder
3 from lazy.www.core import SemiProduct
4 class WorkFlow:
5
6 serial_number = 0
7 working_product = None
8 worker = None
9
10 def __init__(self, worker):
11 self.set_worker(worker)
12
13 def set_worker(self, worker):
14 self.worker = worker
15 if self.worker.working_product is None:
16 self.working_product = SemiProduct()
17 else:
18 self.working_product = self.worker.working_product
19
20 def get_content(self):
21 return self.working_product.content
22
23 def change_worker(self, new_worker):
24 self.serial_number += 1
25 self.worker = new_worker
26
27 def is_fetcher(self, obj):
28 if obj is not None: return True
29
30 def get(self, data = {} ):
31 if not self.is_fetcher(self.worker) :
32 self.change_worker( Fetcher(self.working_product) )
33
34 self.working_product.content = self.worker.get(data)
35 return self
36
37 def post(self, data = {} ):
38 if not self.is_fetcher(self.worker):
39 self.change_worker( Fetcher(self.working_product) )
40
41 self.working_product.content = self.worker.post(data)
42 return self
43
44 def is_finder(self, obj):
45 if obj is not None: return True
46
47 def find(self, express):
48 #if not self.is_finder(self.worker):
49 self.worker = Finder(self.working_product)
50 self.working_product.content = self.worker.find(express)
51
52 return self