# HG changeset patch # User Jeff Hammel # Date 1367420810 25200 # Node ID 1281d999618cda0e8d71460aaf89d0a27bd6f8e8 # Parent a62fbff067f884d63a412dc28f899203bea894df yep diff -r a62fbff067f8 -r 1281d999618c smartopen/handlers.py --- a/smartopen/handlers.py Wed May 01 06:56:12 2013 -0700 +++ b/smartopen/handlers.py Wed May 01 08:06:50 2013 -0700 @@ -1,8 +1,12 @@ +""" +handlers for smartopen +""" + import address import string +import subprocess import urllib import urllib2 -from subprocess import call class Location(object): """ @@ -14,12 +18,15 @@ # should/could strip here? def url(self, query): + """the URL to construct""" return self.baseurl + self.process(query) def process(self, query): - return query + """how to process the query""" + return query.strip() def test(self, query): + """whether the handler matches""" return True def exists(self, URL): @@ -173,12 +180,13 @@ return False class UbuntuPackage(Location): + # Note: only works where apt-cache is available def __init__(self): baseurl = 'http://packages.ubuntu.com/' Location.__init__(self, baseurl) def test(self, query): - if len(self.baseurl.strip().split()) > 1: + if len(query.strip().split()) > 1: return False # no spaces in packages # use `apt-cache show` for the package name @@ -206,10 +214,12 @@ # in theory both the home page and the ubuntu page could be interesting # (different handlers?) - returncode = call(['apt-cache', 'show', self.baseurl]) + returncode = subprocess.call(['apt-cache', 'show', query], stdout=subprocess.PIPE) if returncode: return False + return True + # TODO: # - https://mozillians.org/en-US/u/jhammel/ handler # - https://mozillians.org/en-US/u/williamr/ handler