diff 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
line wrap: on
line diff
--- a/smartopen/handlers.py	Sat Nov 21 17:29:39 2009 -0500
+++ b/smartopen/handlers.py	Sat Nov 21 17:49:36 2009 -0500
@@ -57,40 +57,21 @@
         return bool(self.process(query))
 
 class Trac(Location):
-    def __init__(self, url):
-        self.url = url
-        
-
-# TODO: need configuration
-# class Revision(Location):
-#     def __init__(self):
-#         revision_url = 'http://trac.openplans.org/openplans/changeset/'
-#         Location.__init__(self, revision_url)
-
-#     def process(self, query):
-#         return query[1:]
+    def __init__(self, baseurl):
+        baseurl = baseurl.strip('/') + '/'
+        Location.__init__(self, baseurl)
 
-#     def test(self, query):
-#         if query[0] != 'r':
-#             return False
-#         return query[1:].isdigit()
-            
-# class TracTicket(Location):
-#     def __init__(self):
-#         # url for # data
-#         number_url = 'http://trac.openplans.org/openplans/ticket/'
-#         Location.__init__(self, number_url)
+    def process(self, query):
+        if query[0] == 'r':
+            if query[1:].isdigit():
+                return 'changeset/' + str(query[1:])
+        if query[0] == '#':
+            if query[1:].isdigit():
+                return 'ticket/' + str(query[1:])
 
-#     def process(self, query):
-#         if query.startswith('#'):
-#             return query[1:]        
-#         return query
-
-#     def test(self, query):
-#         query = self.process(query)
-#         if len(query.split()) != 1:
-#             return False
-#         return query.isdigit()
+    def test(self, query):
+        return bool(self.process(query))
+        
 
 class Wikipedia(Location):
     """try to open the query in wikipedia"""