comparison pyikriam/lazy/www/work/__init__.py @ 246:60c4b4b78a01

code clean
author "Hisn Yi, Chen <ossug.hychen@gmail.com>"
date Mon, 01 Dec 2008 00:25:07 +0800
parents a4c364888197
children
comparison
equal deleted inserted replaced
244:fd6c3660cd38 246:60c4b4b78a01
19 19
20 def get_content(self): 20 def get_content(self):
21 return self.working_product.content 21 return self.working_product.content
22 22
23 def change_worker(self, new_worker): 23 def change_worker(self, new_worker):
24 self.serial_number += 1 24 self.serial_number += 1
25 self.last_work = self
25 self.worker = new_worker 26 self.worker = new_worker
26 27
27 def is_fetcher(self, obj): 28 def is_fetcher(self, obj):
28 if obj is not None: return True 29 if obj.__class__.__name__ == 'Fetcher': return True
29 30
30 def get(self, data = {} ): 31 def get(self, data = {} ):
31 if not self.is_fetcher(self.worker) : 32 if self.worker.__class__.__name__ != 'FileStorager' and not self.is_fetcher(self.worker) :
32 self.change_worker( Fetcher(self.working_product) ) 33 self.change_worker( Fetcher(self.working_product) )
33 34
34 self.working_product.content = self.worker.get(data) 35 self.working_product.content = self.worker.get(data)
35 return self 36 return self
36 37
40 41
41 self.working_product.content = self.worker.post(data) 42 self.working_product.content = self.worker.post(data)
42 return self 43 return self
43 44
44 def is_finder(self, obj): 45 def is_finder(self, obj):
45 if obj is not None: return True 46 if obj.__class__.__name__ == 'Finder': return True
47
48 def findall(self, expresses):
49 if not self.is_finder(self.worker):
50 self.change_worker( Finder(self.working_product) )
51
52 ret = {}
53 for e in expresses.keys():
54 try:
55 ret[e] = self.worker.find(expresses[e])
56 except:
57 pass
58
59 self.working_product.content = ret
60
61 return self
46 62
47 def find(self, express): 63 def find(self, express):
48 #if not self.is_finder(self.worker): 64 #if not self.is_finder(self.worker):
49 self.worker = Finder(self.working_product) 65 self.change_worker( Finder(self.working_product) )
66 self.last_working_product = self.working_product
50 self.working_product.content = self.worker.find(express) 67 self.working_product.content = self.worker.find(express)
51 68
52 return self 69 return self
70
71 def process(self, fn):
72 self.working_product.content = fn(self.working_product.content)
73 return self