62
|
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 |