comparison smartopen/handlers.py @ 1:10fc4904c10f

now can pass data
author k0s <k0scist@gmail.com>
date Sat, 21 Nov 2009 17:29:39 -0500
parents d6fa501af82f
children f084e152dd47
comparison
equal deleted inserted replaced
0:d6fa501af82f 1:10fc4904c10f
17 return query 17 return query
18 18
19 def test(self, query): 19 def test(self, query):
20 return True 20 return True
21 21
22 def open(self, query):
23 if not self.test(query):
24 return False
25 url = self.url(query)
26 os.system("firefox '%s'" % url)
27 return True
28 22
29 class URL(Location): 23 class URL(Location):
30 """a straight URL""" 24 """a straight URL"""
31 25
32 def process(self, query): 26 def process(self, query):
44 site = urllib.urlopen(self.process(query)) 38 site = urllib.urlopen(self.process(query))
45 except IOError: 39 except IOError:
46 return False 40 return False
47 return True 41 return True
48 42
49 class GoogleMap(Location): 43 class GoogleMaps(Location):
50 """try to google-maps the address""" 44 """try to google-maps the address"""
51 45
52 def __init__(self): 46 def __init__(self):
53 gmapsurl='http://maps.google.com/maps?f=q&hl=en&q=' 47 gmapsurl='http://maps.google.com/maps?f=q&hl=en&q='
54 Location.__init__(self, gmapsurl) 48 Location.__init__(self, gmapsurl)
60 return urllib.quote_plus(theaddress) 54 return urllib.quote_plus(theaddress)
61 55
62 def test(self, query): 56 def test(self, query):
63 return bool(self.process(query)) 57 return bool(self.process(query))
64 58
65 class Revision(Location): 59 class Trac(Location):
66 def __init__(self): 60 def __init__(self, url):
67 revision_url = 'http://trac.openplans.org/openplans/changeset/' 61 self.url = url
68 Location.__init__(self, revision_url)
69
70 def process(self, query):
71 return query[1:]
72
73 def test(self, query):
74 if query[0] != 'r':
75 return False
76 return query[1:].isdigit()
77
78 62
79 63
80 class TracTicket(Location): 64 # TODO: need configuration
81 def __init__(self): 65 # class Revision(Location):
82 # url for # data 66 # def __init__(self):
83 number_url = 'http://trac.openplans.org/openplans/ticket/' 67 # revision_url = 'http://trac.openplans.org/openplans/changeset/'
84 Location.__init__(self, number_url) 68 # Location.__init__(self, revision_url)
85 69
86 def process(self, query): 70 # def process(self, query):
87 if query.startswith('#'): 71 # return query[1:]
88 return query[1:]
89 return query
90 72
91 def test(self, query): 73 # def test(self, query):
92 query = self.process(query) 74 # if query[0] != 'r':
93 if len(query.split()) != 1: 75 # return False
94 return False 76 # return query[1:].isdigit()
95 return query.isdigit() 77
78 # class TracTicket(Location):
79 # def __init__(self):
80 # # url for # data
81 # number_url = 'http://trac.openplans.org/openplans/ticket/'
82 # Location.__init__(self, number_url)
83
84 # def process(self, query):
85 # if query.startswith('#'):
86 # return query[1:]
87 # return query
88
89 # def test(self, query):
90 # query = self.process(query)
91 # if len(query.split()) != 1:
92 # return False
93 # return query.isdigit()
96 94
97 class Wikipedia(Location): 95 class Wikipedia(Location):
98 """try to open the query in wikipedia""" 96 """try to open the query in wikipedia"""
99 def __init__(self): 97 def __init__(self):
100 wikiurl = 'http://en.wikipedia.org/wiki/' 98 wikiurl = 'http://en.wikipedia.org/wiki/'