# make it so that you can do @co.uk -- the default decorator rewrites the TLD def __getattr__(self, attr): return tld_rewriter(attr) @expose def archive(self, url): """shows a list of older versions of the page using the wayback machine at archive.org""" return "http://web.archive.org/web/*/%s" % url @expose def identity(self, url): """a no-op decorator""" return url @expose def tinyurl(self, url): """creates a tinyurl of the URL""" # we need to leave url raw here since tinyurl will actually # break if we send it a quoted url return "http://tinyurl.com/create.php?url=%s" % url class MshangBunny(bunny1.Bunny1): """An example""" def __init__(self): bunny1.Bunny1.__init__(self, MshangCommands(), ExampleDecorators()) if __name__ == "__main__": bunny1.main(MshangBunny())
def identity(self, url): """a no-op decorator""" return url @expose def tinyurl(self, url): """creates a tinyurl of the URL""" # we need to leave url raw here since tinyurl will actually # break if we send it a quoted url return "http://tinyurl.com/create.php?url=%s" % url class ExampleBunny(bunny1.Bunny1): """An example""" def __init__(self): bunny1.Bunny1.__init__(self, ExampleCommands(), ExampleDecorators()) # an example showing how you can handle URLs that happen before # the querystring by adding methods to the Bunny class instead of # the commands class @cherrypy.expose def header_gif(self): """the banner GIF for the bunny1 homepage""" cherrypy.response.headers["Content-Type"] = "image/gif" return bunny1.bunny1_file("header.gif") if __name__ == "__main__": bunny1.main(ExampleBunny())
</body> </html> """ @dont_expose def _opensearch_metadata(self): return { "short_name": "tikibunny", "description": "tikibunny", "template": self._my_url() + "?{searchTerms}", } bunny1.Bunny1Commands._opensearch_metadata = _opensearch_metadata class MyBunny(bunny1.Bunny1): def __init__(self): bunny1.Bunny1.__init__(self, MyCommands(), bunny1.Bunny1Decorators()) @cherrypy.expose def tiki_header_gif(self): """the banner GIF for the bunny1 homepage 123""" cherrypy.response.headers["Content-Type"] = "image/gif" return file("header_tiki.gif").read() # return bunny1.bunny1_file("header_tiki.gif") if __name__ == "__main__": bunny1.main(MyBunny())
from bunny1 import Content from bunny1 import q from bunny1 import qp from bunny1 import expose from bunny1 import dont_expose from bunny1 import escape from bunny1 import HTML class MyCommands(bunny1.Bunny1Commands): def your_command_here(self, arg): """this is where a description of your command goes""" return "http://www.example.com/?" % qp(arg) def another_command(self, arg): """this example will send content to the browser rather than redirecting""" raise HTML("some <u>html</u> " + escape("with some <angle brackets>")) # ... and you can add other commands by just defining more methods # in this class here class MyBunny(bunny1.Bunny1): def __init__(self): bunny1.Bunny1.__init__(self, MyCommands(), bunny1.Bunny1Decorators()) if __name__ == "__main__": bunny1.main(MyBunny())
return add_matcher class Bunny650Commands(bunny1.Bunny1Commands): @prefixes(r"\d+") def d(self, arg): """Redirects to a Phabricator diff""" return "https://phabricator.productinfrastructure.com/D" + arg @prefixes(r"\d+") def D(self, arg): return self.d(arg) def ios(self, arg): """Searches for Apple's iOS documentation on the given term""" apple_dev_url = "https://developer.apple.com/library/ios" return "https://www.google.com/#q=" + qp(arg + " site:" + apple_dev_url) def npm(self, arg): """Searches npm for modules with the given name""" return "https://npmjs.org/search?q=" + qp(arg) class Bunny650(bunny1.Bunny1): def __init__(self): bunny1.Bunny1.__init__(self, Bunny650Commands(), bunny1.Bunny1Decorators()) if __name__ == "__main__": bunny1.main(Bunny650())
@expose def identity(self, url): """a no-op decorator""" return url @expose def tinyurl(self, url): """creates a tinyurl of the URL""" # we need to leave url raw here since tinyurl will actually # break if we send it a quoted url return "http://tinyurl.com/create.php?url=%s" % url class ExampleBunny(bunny1.Bunny1): """An example""" def __init__(self): bunny1.Bunny1.__init__(self, ExampleCommands(), ExampleDecorators()) # an example showing how you can handle URLs that happen before # the querystring by adding methods to the Bunny class instead of # the commands class @cherrypy.expose def header_gif(self): """the banner GIF for the bunny1 homepage""" cherrypy.response.headers["Content-Type"] = "image/gif" return bunny1.bunny1_file("header.gif") if __name__ == "__main__": bunny1.main(ExampleBunny())
@expose def identity(self, url): """a no-op decorator""" return url @expose def tinyurl(self, url): """creates a tinyurl of the URL""" # we need to leave url raw here since tinyurl will actually # break if we send it a quoted url return "http://tinyurl.com/create.php?url=%s" % url class CustomBunny1(bunny1.Bunny1): def __init__(self, commands, decorators): bunny1.Bunny1.__init__(self, commands, decorators) # an example showing how you can handle URLs that happen before # the querystring by adding methods to the Bunny class instead of # the commands class @cherrypy.expose def header_gif(self): """the banner GIF for the bunny1 homepage""" cherrypy.response.headers["Content-Type"] = "image/gif" return bunny1.bunny1_file("header.gif") if __name__ == "__main__": bunny1.main(CustomBunny1(CustomCommands(), CustomDecorators()))