Mercurial > eagle-eye
comparison pyikriam/lazy/www/__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 |
---|---|
13 | 13 |
14 def func(s): | 14 def func(s): |
15 return {'msg':s} | 15 return {'msg':s} |
16 | 16 |
17 try: | 17 try: |
18 c("http://example.tw/").get().find("#id > div") \ | 18 c("http://example.tw/").get().find("////ul/text()") \ |
19 .build_param( func ).post_to("http://example2.com") \ | 19 .build_param( func ).post_to("http://example2.com") \ |
20 .save_as('hellow.html') | 20 .save_as('hellow.html') |
21 except: | 21 except: |
22 pass | 22 pass |
23 | 23 |
36 print "the files can not be save with incorrect permission." | 36 print "the files can not be save with incorrect permission." |
37 else: | 37 else: |
38 print "unknow error." | 38 print "unknow error." |
39 """ | 39 """ |
40 from lazy.www.work import WorkFlow | 40 from lazy.www.work import WorkFlow |
41 from lazy.www.work.fetch import Fetcher, install_opener | 41 from lazy.www.work.fetch import Fetcher |
42 from lazy.www.work.storage import FileStorager | |
42 from lazy.www.core import SemiProduct | 43 from lazy.www.core import SemiProduct |
44 import os | |
45 import sys | |
46 import re | |
43 | 47 |
44 def c(url): | 48 def parse_scheme(scheme): |
49 try: | |
50 return re.findall("(\w+):\/\/(.*\/?)",scheme)[0] | |
51 except: | |
52 sys.stdout.write("the scheme is not supported.") | |
53 sys.exit() | |
54 | |
55 def c(scheme): | |
45 """ | 56 """ |
46 connect to a web apge | 57 connect to a web apge |
47 | 58 |
48 >>> c('http://localhost:8080').get().worker.working_product.content | 59 >>> c('http://localhost:8080').get().worker.working_product.content |
49 'It works!!\\n' | 60 'It works!!\\n' |
50 | 61 |
51 >>> c('http://localhost:8080').get().find('//text()') | 62 >>> c('http://localhost:8080').get().find('//text()') |
52 'It works!!\\n' | 63 'It works!!\\n' |
53 """ | 64 """ |
54 s= SemiProduct(source=url) | 65 target_type, path = parse_scheme(scheme) |
55 w = WorkFlow(Fetcher(s)) | |
56 return w | |
57 | 66 |
58 def lz_install(**kwds): | 67 #@todo: SemiProduct Factory. |
59 if('opener' == kwds.get('name')): | 68 if 'file' == target_type: |
60 install_opener(kwds.get('cookiefile')) | 69 s= SemiProduct(source=path) |
70 worker = FileStorager(s) | |
71 else: | |
72 s= SemiProduct(source=scheme) | |
73 worker = Fetcher(s) | |
74 return WorkFlow(worker) | |
61 | 75 |
62 if __name__ == '__main__': | 76 if __name__ == '__main__': |
63 import doctest | 77 import doctest |
64 doctest.testmod() | 78 doctest.testmod() |