comparison smartopen/handlers.py @ 2:f084e152dd47

add Trac handler
author k0s <k0scist@gmail.com>
date Sat, 21 Nov 2009 17:49:36 -0500
parents 10fc4904c10f
children d5343f681ef9
comparison
equal deleted inserted replaced
1:10fc4904c10f 2:f084e152dd47
55 55
56 def test(self, query): 56 def test(self, query):
57 return bool(self.process(query)) 57 return bool(self.process(query))
58 58
59 class Trac(Location): 59 class Trac(Location):
60 def __init__(self, url): 60 def __init__(self, baseurl):
61 self.url = url 61 baseurl = baseurl.strip('/') + '/'
62 Location.__init__(self, baseurl)
63
64 def process(self, query):
65 if query[0] == 'r':
66 if query[1:].isdigit():
67 return 'changeset/' + str(query[1:])
68 if query[0] == '#':
69 if query[1:].isdigit():
70 return 'ticket/' + str(query[1:])
71
72 def test(self, query):
73 return bool(self.process(query))
62 74
63
64 # TODO: need configuration
65 # class Revision(Location):
66 # def __init__(self):
67 # revision_url = 'http://trac.openplans.org/openplans/changeset/'
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 # 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()
94 75
95 class Wikipedia(Location): 76 class Wikipedia(Location):
96 """try to open the query in wikipedia""" 77 """try to open the query in wikipedia"""
97 def __init__(self): 78 def __init__(self):
98 wikiurl = 'http://en.wikipedia.org/wiki/' 79 wikiurl = 'http://en.wikipedia.org/wiki/'