Example #1
0
 def _finger(self, arg):
     """run finger on the host that this is running on"""
     p = subprocess.Popen(["finger", arg],
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
     return PRE("<span style='color: red;'>" + escape(p.stderr.read()) +
                "</span><hr />" + escape(p.stdout.read()))
Example #2
0
 def _cookies(self, arg):
     """show the cookies set on this server or search through them"""
     cookie = cherrypy.request.cookie
     html = ""
     for name in cookie.keys():
         val = cookie[name].value
         if not arg or (arg in name or arg in val):
             html += "<b>%s</b><br />%s<br /><br />" % (escape(str(name)), escape(str(val)))
     raise Content(html)
Example #3
0
 def _cookies(self, arg):
     """show the cookies set on this server or search through them"""
     cookie = cherrypy.request.cookie
     html = ""
     for name in cookie.keys():
         val = cookie[name].value
         if not arg or (arg in name or arg in val):
             html += "<b>%s</b><br />%s<br /><br />" % (escape(
                 str(name)), escape(str(val)))
     raise Content(html)
Example #4
0
    def list(self, arg):
        """show the list of methods you can use or search that list"""
        def is_exposed_method((name, method)):
            return not name.startswith("__") and callable(method) \
                       and method.__doc__ and not getattr(method, "dont_expose", False) \
                       and not getattr(method, "unlisted", False)

        arg_lower = None
        if arg:
            arg_lower = arg.lower()
            html = ""
            search_predicate = lambda (name, method): is_exposed_method((name,method)) and \
                               (arg_lower in name.lower() or arg_lower in method.__doc__)
        else:
            html = self._popularity_html(
                10) + "<hr ><b><i>All Commands</i></b><br />"
            search_predicate = is_exposed_method

        attr_names = dir(self)

        def attr_getter(name):
            return getattr(self, name)

        html += '<table>'
        html += ''.join([
            '<tr><td><b>%s</b></td><td>%s</td></tr>' %
            (name, escape(method.__doc__)) for name, method in ifilter(
                search_predicate,
                izip(attr_names, imap(attr_getter, attr_names)))
        ])
        html += '<table>'

        raise Content(html)
Example #5
0
 def eval(self, arg):
     try:
         return PRE(eval(arg))
     except Content:
         raise
     except Exception, e:
         return PRE("<span style='color: red;'>" + escape(str(e)) + "</span>")
Example #6
0
 def help(self, arg):
     """gets help with a specific command or shows the README for general help"""
     if arg:
         raise Content("<b>" + escape(arg) + "</b><br />" +
                       str(getattr(self, arg).__doc__))
     else:
         raise Content(self._help_html())
Example #7
0
    def list(self, arg):
        """show the list of methods you can use or search that list"""

        def is_exposed_method( (name, method) ):
            return not name.startswith("__") and callable(method) \
                       and method.__doc__ and not getattr(method, "dont_expose", False) \
                       and not getattr(method, "unlisted", False)

        arg_lower = None
        if arg:
            arg_lower = arg.lower()
            html = ""
            search_predicate = lambda (name, method): is_exposed_method((name,method)) and \
                               (arg_lower in name.lower() or arg_lower in method.__doc__)
        else:
            html = self._popularity_html(10) + "<hr ><b><i>All Commands</i></b><br />"
            search_predicate = is_exposed_method

        attr_names = dir(self)

        def attr_getter(name): return getattr(self, name)

        html += '<table>'
        html += ''.join(
            ['<tr><td><b>%s</b></td><td>%s</td></tr>' % (name, escape(method.__doc__)) for
             name, method in ifilter(search_predicate,
                                     izip(attr_names, imap(attr_getter, attr_names)))])
        html += '<table>'

        raise Content(html)
Example #8
0
 def unalias(self, arg):
     """unaliases an alias.  ex: unalias p"""
     if not arg:
         raise Content("usage:<br />unalias <i>alias</i>")
     cherrypy.response.cookie["alias." + arg] = ""
     cherrypy.response.cookie["alias." + arg]["expires"] = 0
     raise Content("unaliased <b>%s</b>" % escape(arg))
Example #9
0
 def unalias(self, arg):
     """unaliases an alias.  ex: unalias p"""
     if not arg:
         raise Content("usage:<br />unalias <i>alias</i>")
     cherrypy.response.cookie["alias." + arg] = ""
     cherrypy.response.cookie["alias." + arg]["expires"] = 0
     raise Content("unaliased <b>%s</b>" % escape(arg))
Example #10
0
 def eval(self, arg):
     try:
         return PRE(eval(arg))
     except Content:
         raise
     except Exception as e:
         return PRE("<span style='color: red;'>" + escape(str(e)) +
                    "</span>")
Example #11
0
 def alias(self, arg):
     """aliases one shortcut to another.  ex: alias p profile.  alias p will show what p is aliased to.  alias with no args will show all aliases."""
     words = arg.split()
     cookie = cherrypy.response.cookie
     try:
         alias = words[0]
         real = words[1]
         cookie["alias." + alias] = real
         raise Content("aliased <b>%s</b> to <b>%s</b>" %
                       (escape(alias), escape(real)))
     except IndexError:
         try:
             alias = words[0]
             try:
                 raise Content(
                     "<b>%s</b> is aliased to <b>%s</b>" %
                     (escape(alias),
                      escape(
                          cherrypy.request.cookie["alias." + alias].value)))
             except KeyError:
                 raise Content("<b>%s</b> is not aliased to anything." %
                               escape(arg))
         except IndexError:
             html = "usage:<br />alias <i>alias</i> <i>real-command</i><br />or<br />alias <i>alias</i><br /><hr />"
             cookie = cherrypy.request.cookie
             for name in cookie.keys():
                 if str(name).startswith("alias."):
                     html += "<b>%s</b> is aliased to <b>%s</b><br />" % (
                         escape(name[6:]), escape(cookie[name].value))
             raise Content(html)
Example #12
0
   def _opensearch(self, arg):
       """returns the OpenSearch description for this server"""
       m = self._opensearch_metadata()
       raise Content("""<?xml version="1.0" encoding="UTF-8" ?>
   <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
   <ShortName>""" + m["short_name"] + """</ShortName>
   <Description>""" + m["description"] + """</Description>
   <InputEncoding>UTF-8</InputEncoding>
   <Url type="text/html" template=\"""" + escape(m["template"]) + """\" />
 </OpenSearchDescription>
 """, "application/xml")
Example #13
0
 def _popularity_html(self, num=None):
     p = self.popularity
     pairs = [(val, key) for (key, val) in p.items() if key not in DONT_LIST_AS_POPULAR]
     pairs.sort()
     pairs.reverse()
     html = "<b><i>"
     if num:
         html += "%d " % num
     html += "Most Popular Commands</i></b><br />"
     if num:
         pairs = pairs[:num]
     for (times, method) in pairs:
         m = getattr(self, method)
         doc = m.__doc__
         if not getattr(m, "unlisted", False):
             if doc:
                 doc_str = " (%s)" % escape(doc)
             else:
                 doc_str = ""
             html += "<b>%s</b> used %d times%s<br />\n" % (escape(method), times, doc_str)
     return html
Example #14
0
   def _opensearch(self, arg):
       """returns the OpenSearch description for this server"""
       m = self._opensearch_metadata()
       raise Content(
           """<?xml version="1.0" encoding="UTF-8" ?>
   <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
   <ShortName>""" + m["short_name"] + """</ShortName>
   <Description>""" + m["description"] + """</Description>
   <InputEncoding>UTF-8</InputEncoding>
   <Url type="text/html" template=\"""" + escape(m["template"]) + """\" />
 </OpenSearchDescription>
 """, "application/xml")
Example #15
0
 def alias(self, arg):
     """aliases one shortcut to another.  ex: alias p profile.  alias p will show what p is aliased to.  alias with no args will show all aliases."""
     words = arg.split()
     cookie = cherrypy.response.cookie
     try:
         alias = words[0]
         real = words[1]
         cookie["alias." + alias] = real
         raise Content("aliased <b>%s</b> to <b>%s</b>" % (escape(alias), escape(real)))
     except IndexError:
         try:
             alias = words[0]
             try:
                 raise Content("<b>%s</b> is aliased to <b>%s</b>" % (escape(alias), escape(cherrypy.request.cookie["alias." + alias].value)))
             except KeyError:
                 raise Content("<b>%s</b> is not aliased to anything." % escape(arg))
         except IndexError:
             html = "usage:<br />alias <i>alias</i> <i>real-command</i><br />or<br />alias <i>alias</i><br /><hr />"
             cookie = cherrypy.request.cookie
             for name in cookie.keys():
                 if str(name).startswith("alias."):
                     html += "<b>%s</b> is aliased to <b>%s</b><br />" % (escape(name[6:]), escape(cookie[name].value))
             raise Content(html)
Example #16
0
 def _popularity_html(self, num=None):
     p = self.popularity
     pairs = [(val, key) for (key, val) in p.items()
              if key not in DONT_LIST_AS_POPULAR]
     pairs.sort()
     pairs.reverse()
     html = "<b><i>"
     if num:
         html += "%d " % num
     html += "Most Popular Commands</i></b><br />"
     if num:
         pairs = pairs[:num]
     for (times, method) in pairs:
         m = getattr(self, method)
         doc = m.__doc__
         if not getattr(m, "unlisted", False):
             if doc:
                 doc_str = " (%s)" % escape(doc)
             else:
                 doc_str = ""
             html += "<b>%s</b> used %d times%s<br />\n" % (escape(method),
                                                            times, doc_str)
     return html
Example #17
0
 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>"))
Example #18
0
 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>"))
Example #19
0
    def do_command(self, raw, a=(), k={}):
        """does the specified command"""

        self.commands.history.append(raw)
        if not raw:
            raw = DEFAULT_COMMAND

        # setup a namespace in the request for bunny1 stuff
        cherrypy.request.bunny1 = {"decorators": []}

        while True:
            try:
                (method, arg) = raw.split(None, 1)
            except ValueError:
                method = raw
                arg = ""
            if method.startswith("@") and method != "@":
                try:
                    d = getattr(self.decorators, method[1:])
                    if d.exposed:
                        cherrypy.request.bunny1["decorators"].append(d)
                    else:
                        # shold really use a different kind of exception
                        # and raise that here, but this works for now
                        raise DoesNotExist(method)
                    raw = arg
                except (AttributeError, DoesNotExist):
                    return self.error("no decorator named %s %s" %
                                      (escape(method), repr(self.decorators)))
            else:
                break

        # use aliases
        try:
            method = cherrypy.request.cookie["alias." + method].value
        except KeyError:
            pass

        # @ is a symbol that works if you have a server on your LAN
        # with the same name as a command you want to use
        if method == "@":
            try:
                (method, arg) = arg.split(None, 1)
            except ValueError:
                method = arg
                arg = ""

        # go to the default URL if there is just a decorator given
        if method == "":
            method = "url"
            arg = self.decorators.default_url()

        # if you type in a URL, just go there
        if urlparse.urlsplit(method)[0]:
            method = "url"
            arg = raw

        # debug mode: gives the URLs of redirects rather than redirecting
        if method == "_debug":
            try:
                return self.do_command(arg)
            except HTTPRedirect, redir:
                url = escape(redir.urls[0])
                return "<code><b>bunny1</b> DEBUG: redirect to <a href='%s'>%s</a></code>" % (
                    url, url)
Example #20
0
 def __init__(self, error_message):
     Content.__init__(self)
     self.html = "<span style='color: red; font-family: Courier New, Courier, Fixed-width; font-weight: bold;'>%s</span>" % escape(
         error_message)
Example #21
0
 def echo(self, arg):
     """returns back what you give to it"""
     raise Content(escape(arg))
Example #22
0
    def _help_html(self, examples=None, name="bunny1"):
        """the help page that gets shown if no command or 'help' is entered"""

        import random

        def bookmarklet(name):
            return """<a href="javascript:bunny1_url='""" + self._base_url(
            ) + """?';cmd=prompt('bunny1.  type &quot;help&quot; to get help or &quot;list&quot; to see commands you can use.',window.location);if(cmd){window.location=bunny1_url+escape(cmd);}else{void(0);}">""" + name + """</a>"""

        if not examples:
            examples = [
                "g phpsh",
                "fbpbz 1737",
                "wikinvest 2008 Financial Crisis",
                "popular",
                "ya what is the meaning of life?",
                "list Facebook",
                "fbs john",
                "php array_merge",
                "wp FBML",
                "fb mark zuckerberg",
                "gmaps 285 Hamilton Ave, Palo Alto, CA 94301",
                "gimg bisu",
                "rickroll",
                "yt i'm cool sushi654 yeah",
                "y osteria palo alto",
                "live james harrison",
            ]

        return """
<html>
<head>
<title>bunny1</title>
""" + self._opensearch_link() + """
<style>
BODY {
    font-family: Sans-serif;
    width: 800px;
}

code {
    color: darkgreen;
}

A {
    color: #3B5998;
}

small {
    width: 800px;
    text-align: center;
}

.header {
    position: absolute;
    top: 0px;
    left: 0px;
}

.test-query-input {
    width: 487px;
    font-size: 20px;
}

.header-placeholder {
    height: 45px;
}

</style>
</head>
<body>
<h1 class="header-placeholder"><img class="header" src="header.gif" /></h1>

<p>""" + name + """ is a tool that lets you write smart bookmarks in python and then share them across all your browsers and with a group of people or the whole world.  It was developed at <a href="http://www.facebook.com/">Facebook</a> and is widely used there.</p>

<form method="GET">
<p style="width: 820px; text-align: center;"><input class="test-query-input" id="b1cmd" type="text" name="___" value=""" + '"' + escape(
            random.choice(examples)
        ) + '"' + """/> <input type="submit" value=" try me "/></p>

<p>Type something like """ + " or ".join([
            """<a href="#" onclick="return false;"><code onclick="document.getElementById('b1cmd').value = this.innerHTML; return true;">"""
            + x + "</code></a>" for x in examples
        ]) + """.</p>

<p>Or you can see <a href="?list">a list of shortcuts you can use</a> with this example server.</p>

<h3>Running Your Own bunny1 Server</h3>
<ul>Download the <a href="http://github.com/ccheever/bunny1/">source code</a> for the project.  Or if you use setuptools, you can just <code>easy_install bunny1</code>.</ul>

<ul>To run an example server, just run <code>b1_example.py --port=8080</code>.</ul>

<ul>More detailed instructions for configuring and running your own server can be found in the <a href=""" + '"' + self._base_url(
        ) + """?readme">README</a>.  You can add your own commands with just a few lines of python.</ul>

<h3>Installing on Firefox</h3>
<ul>Type <code>about:config</code> into your location bar in Firefox.</ul>
<ul>Set the value of keyword.URL to be <code>""" + self._base_url(
        ) + """?</code></ul>
<ul>Make sure you include the <code>http://</code> at the beginning and the <code>?</code> at the end.</ul>
<ul>Now, type <code>list</code> or <code>wp FBML</code> into your location bar and hit enter.</ul>
<ul>Also, if you are a Firefox user and find bunny1 useful, you should check out <a href="http://labs.mozilla.com/projects/ubiquity/">Ubiquity</a>.</ul>

<h3>Installing on Safari</h3>
<ul>Drag this bookmarklet [""" + bookmarklet(
            name
        ) + """] to your bookmarks bar.</ul>
<ul>Now, visit the bookmarklet, and in the box that pops up, type <code>list</code> or <code>g facebook comments widget video</code> and hit enter.</ul>
<ul>In Safari, one thing you can do is make the bookmarklet the leftmost bookmark in your bookmarks bar, and then use <code>Command-1</code> to get to it.</ul>
<ul>Alternatively, you can get the location bar behavior of Firefox in Safari 3 by using the <a href="http://purefiction.net/keywurl/">keywurl</a> extension.</ul>

<h3>Installing on Google Chrome</h3>
<ul>Choose <code>Options</code> from the wrench menu to the right of the location bar in Chrome, then under the section <code>Default Search</code>, click the <code>Manage</code> button.  Click the <code>Add</code> button and then fill in the fields name, keyword, and URL with <code>""" + name + """</code>, <code>b1</code>, and <code>""" + self._base_url(
        ) + """?</code>.  Hit <code>OK</code> and then select """ + name + """ from the list of search engines and hit the <code>Make Default</code> button to make """ + name + """ your default search engine.  Type <code>list</code> into your location bar to see a list of commands you can use.</ul>

<h3>Installing on Internet Explorer</h3>
<ul>There aren't any great solutions for installing """ + name + """ on IE, but two OK solutions are:</ul>
<ul>You can use this bookmarklet [""" + bookmarklet(
            name
        ) + """] by dragging into your bookmarks bar and then clicking on it when you want to use """ + name + """.</ul>
<ul>Or, in IE7+, you can click the down arrow on the search bar to the right of your location bar and choose the starred """ + name + """ option there.  This will install the bunny OpenSearch plugin in your search bar.</ul>
Example #23
0
 def help(self, arg):
     """gets help with a specific command or shows the README for general help"""
     if arg:
         raise Content("<b>" + escape(arg) + "</b><br />" + str(getattr(self, arg).__doc__))
     else:
         raise Content(self._help_html())
Example #24
0
 def _help_html(self):
     # this won't work unless bunny1 is imported as a module.
     # at some point, it might be good to deal with that
     return "<html><head><title>bunny1</title>" + self._opensearch_link() + "</head><body><form><input type='text' name='" + COMMAND_QUERY_STRING_VAR + "' value='list'><input type='submit' value='try me'></form><pre>" + escape(bunny1_file("README")) + "</pre></body></html>"
Example #25
0
 def __init__(self, error_message):
     Content.__init__(self)
     self.html = "<span style='color: red; font-family: Courier New, Courier, Fixed-width; font-weight: bold;'>%s</span>" % escape(error_message)
Example #26
0
    def _help_html(self, examples=None, name="tikibunny"):
        """the help page that gets shown if no command or 'help' is entered"""

        import random

        def bookmarklet(name):
            return """<a href="javascript:bunny1_url='""" + self._base_url(
            ) + """?';cmd=prompt('bunny1.  type &quot;help&quot; to get help or &quot;list&quot; to see commands you can use.',window.location);if(cmd){window.location=bunny1_url+escape(cmd);}else{void(0);}">""" + name + """</a>"""

        if not examples:
            examples = ["ps", "jira PS-6872", "docs", "debug"]

        return """

<html>
<head>
<title>tikibunny</title>
""" + self._opensearch_link() + """
<style>
BODY {
    font-family: Sans-serif;
    width: 800px;
}

code {
    color: darkgreen;
}

A {
    color: #3B5998;
}

small {
    width: 800px;
    text-align: center;
}

.header {
    position: absolute;
    top: 0px;
    left: 0px;
}

.test-query-input {
    width: 487px;
    font-size: 20px;
}

.header-placeholder {
    height: 45px;
}

</style>
</head>
<body>
<h1 class="header-placeholder"><img class="header" src="tiki_header.gif" /></h1>

<p>""" + name + """ là một công cụ để bạn có thể dễ dàng tạo bookmark thông minh, được viết bằng python và có thể sử dụng các bookmarks này cho các trình duyệt web. Source code có thể được chia sẻ với tất cả các programmers khác. Công cụ này lần đầu tiên được phát triển tại <a href="http://www.facebook.com/">Facebook</a> và đã được sử dụng chính thức rộng rãi.</p>

<form method="GET">
<p style="width: 820px; text-align: center;"><input class="test-query-input" id="b1cmd" type="text" name="___" value=""" + '"' + escape(
            random.choice(examples)
        ) + '"' + """/> <input type="submit" value=" try me "/></p>

<p>Bạn có thể gõ thử """ + " or ".join([
            """<a href="#" onclick="return false;"><code onclick="document.getElementById('b1cmd').value = this.innerHTML; return true;">"""
            + x + "</code></a>" for x in examples
        ]) + """.</p>

<p>Hoặc bạn có thể xem <a href="?list">list những câu lệnh bookmarks</a> đang có sẵn trong server này.</p>

<h3>Bạn muốn tạo server riêng cho Bunny của bạn</h3>
<ul>Download <a href="https://github.com/phuongpham178/tikibunny">source code</a> cho project của bạn.  Hoặc nếu bạn dùng setuptools, bạn có thể <code>easy_install bunny1</code>.</ul>

<ul>Để chạy một server ví dụ, bạn có thể chạy  <code>b1_example.py --port=8080</code>.</ul>

<h3>Cài đặt trên Google Chrome</h3>
<ul>Chọn <code>Options</code> từ góc phải trên thanh menu bar của Chrome</ul>
<ul>Ở phần <code>Default Search</code>, chọn nút <code>Manage</code>.</ul>
<ul>Tìm dòng có tên <code>""" + name + """</code> và keyword <code>phuongpham.info</code> để đặt làm mặc định (default)</ul>
<ul>Bạn có thể thay đổi phần keyword từ <code>phuongpham.info</code> thành <code>bunny</code> hoặc <code>tiki</code> để làm phím tắt cho search engine này</ul>
<ul>Gõ <code>list</code> vào thanh địa chỉ để thấy được danh sách các commands bạn có thể xài.</ul>

<h3>Cài đặt trên Firefox</h3>
<ul>Type <code>about:config</code> into your location bar in Firefox.</ul>
<ul>Set the value of keyword.URL to be <code>""" + self._base_url(
        ) + """?</code></ul>
<ul>Make sure you include the <code>http://</code> at the beginning and the <code>?</code> at the end.</ul>
<ul>Now, type <code>list</code> or <code>wp FBML</code> into your location bar and hit enter.</ul>
<ul>Also, if you are a Firefox user and find bunny1 useful, you should check out <a href="http://labs.mozilla.com/projects/ubiquity/">Ubiquity</a>.</ul>

<h3>Cài đặt trên Safari</h3>
<ul>Drag this bookmarklet [""" + bookmarklet(
            name
        ) + """] to your bookmarks bar.</ul>
<ul>Now, visit the bookmarklet, and in the box that pops up, type <code>list</code> or <code>g facebook comments widget video</code> and hit enter.</ul>
<ul>In Safari, one thing you can do is make the bookmarklet the leftmost bookmark in your bookmarks bar, and then use <code>Command-1</code> to get to it.</ul>
<ul>Alternatively, you can get the location bar behavior of Firefox in Safari 3 by using the <a href="http://purefiction.net/keywurl/">keywurl</a> extension.</ul>

<h3>Installing on Internet Explorer</h3>
<ul>There aren't any great solutions for installing """ + name + """ on IE, but two OK solutions are:</ul>
<ul>You can use this bookmarklet [""" + bookmarklet(
            name
        ) + """] by dragging into your bookmarks bar and then clicking on it when you want to use """ + name + """.</ul>
<ul>Or, in IE7+, you can click the down arrow on the search bar to the right of your location bar and choose the starred """ + name + """ option there.  This will install the bunny OpenSearch plugin in your search bar.</ul>
Example #27
0
 def _help_html(self):
     # this won't work unless bunny1 is imported as a module.
     # at some point, it might be good to deal with that
     return "<html><head><title>bunny1</title>" + self._opensearch_link(
     ) + "</head><body><form><input type='text' name='" + COMMAND_QUERY_STRING_VAR + "' value='list'><input type='submit' value='try me'></form><pre>" + escape(
         bunny1_file("README")) + "</pre></body></html>"
Example #28
0
 def _finger(self, arg):
     """run finger on the host that this is running on"""
     p = subprocess.Popen(["finger", arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     return PRE("<span style='color: red;'>" + escape(p.stderr.read()) + "</span><hr />" + escape(p.stdout.read()))
Example #29
0
 def echo(self, arg):
     """returns back what you give to it"""
     raise Content(escape(arg))
Example #30
0
    def _help_html(self, examples=None, name="bunny1"):
        """the help page that gets shown if no command or 'help' is entered"""

        import random

        def bookmarklet(name):
            return """<a href="javascript:bunny1_url='""" + self._base_url() + """?';cmd=prompt('bunny1.  type &quot;help&quot; to get help or &quot;list&quot; to see commands you can use.',window.location);if(cmd){window.location=bunny1_url+escape(cmd);}else{void(0);}">""" + name + """</a>"""

        if not examples:
            examples = [
                    "g phpsh",
                    "fbpbz 1737",
                    "wikinvest 2008 Financial Crisis",
                    "popular",
                    "ya what is the meaning of life?",
                    "list Facebook",
                    "fbs john",
                    "php array_merge",
                    "wp FBML",
                    "fb mark zuckerberg",
                    "gmaps 285 Hamilton Ave, Palo Alto, CA 94301",
                    "gimg bisu",
                    "rickroll",
                    "yt i'm cool sushi654 yeah",
                    "y osteria palo alto",
                    "live james harrison",
                    ]

        return """
<html>
<head>
<title>bunny1</title>
""" + self._opensearch_link() + """
<style>
BODY {
    font-family: Sans-serif;
    width: 800px;
}

code {
    color: darkgreen;
}

A {
    color: #3B5998;
}

small {
    width: 800px;
    text-align: center;
}

.header {
    position: absolute;
    top: 0px;
    left: 0px;
}

.test-query-input {
    width: 487px;
    font-size: 20px;
}

.header-placeholder {
    height: 45px;
}

</style>
</head>
<body>
<h1 class="header-placeholder"><img class="header" src="header.gif" /></h1>

<p>""" + name + """ is a tool that lets you write smart bookmarks in python and then share them across all your browsers and with a group of people or the whole world.  It was developed at <a href="http://www.facebook.com/">Facebook</a> and is widely used there.</p>

<form method="GET">
<p style="width: 820px; text-align: center;"><input class="test-query-input" id="b1cmd" type="text" name="___" value=""" + '"' + escape(random.choice(examples)) + '"' + """/> <input type="submit" value=" try me "/></p>

<p>Type something like """ + " or ".join(["""<a href="#" onclick="return false;"><code onclick="document.getElementById('b1cmd').value = this.innerHTML; return true;">""" + x + "</code></a>" for x in examples]) + """.</p>

<p>Or you can see <a href="?list">a list of shortcuts you can use</a> with this example server.</p>

<h3>Running Your Own bunny1 Server</h3>
<ul>Download the <a href="http://github.com/ccheever/bunny1/">source code</a> for the project.  Or if you use setuptools, you can just <code>easy_install bunny1</code>.</ul>

<ul>To run an example server, just run <code>b1_example.py --port=8080</code>.</ul>

<ul>More detailed instructions for configuring and running your own server can be found in the <a href=""" + '"' + self._base_url() + """?readme">README</a>.  You can add your own commands with just a few lines of python.</ul>

<h3>Installing on Firefox</h3>
<ul>Type <code>about:config</code> into your location bar in Firefox.</ul>
<ul>Set the value of keyword.URL to be <code>""" + self._base_url() + """?</code></ul>
<ul>Make sure you include the <code>http://</code> at the beginning and the <code>?</code> at the end.</ul>
<ul>Now, type <code>list</code> or <code>wp FBML</code> into your location bar and hit enter.</ul>
<ul>Also, if you are a Firefox user and find bunny1 useful, you should check out <a href="http://labs.mozilla.com/projects/ubiquity/">Ubiquity</a>.</ul>

<h3>Installing on Safari</h3>
<ul>Drag this bookmarklet [""" + bookmarklet(name) + """] to your bookmarks bar.</ul>
<ul>Now, visit the bookmarklet, and in the box that pops up, type <code>list</code> or <code>g facebook comments widget video</code> and hit enter.</ul>
<ul>In Safari, one thing you can do is make the bookmarklet the leftmost bookmark in your bookmarks bar, and then use <code>Command-1</code> to get to it.</ul>
<ul>Alternatively, you can get the location bar behavior of Firefox in Safari 3 by using the <a href="http://purefiction.net/keywurl/">keywurl</a> extension.</ul>

<h3>Installing on Google Chrome</h3>
<ul>Choose <code>Options</code> from the wrench menu to the right of the location bar in Chrome, then under the section <code>Default Search</code>, click the <code>Manage</code> button.  Click the <code>Add</code> button and then fill in the fields name, keyword, and URL with <code>""" + name + """</code>, <code>b1</code>, and <code>""" + self._base_url() + """?</code>.  Hit <code>OK</code> and then select """ + name + """ from the list of search engines and hit the <code>Make Default</code> button to make """ + name + """ your default search engine.  Type <code>list</code> into your location bar to see a list of commands you can use.</ul>

<h3>Installing on Internet Explorer</h3>
<ul>There aren't any great solutions for installing """ + name + """ on IE, but two OK solutions are:</ul>
<ul>You can use this bookmarklet [""" + bookmarklet(name) + """] by dragging into your bookmarks bar and then clicking on it when you want to use """ + name + """.</ul>
<ul>Or, in IE7+, you can click the down arrow on the search bar to the right of your location bar and choose the starred """ + name + """ option there.  This will install the bunny OpenSearch plugin in your search bar.</ul>
Example #31
0
    def do_command(self, raw, a=(), k={}):
        """does the specified command"""

        self.commands.history.append(raw)
        if not raw:
            raw = DEFAULT_COMMAND

        # setup a namespace in the request for bunny1 stuff
        cherrypy.request.bunny1 = {"decorators": []}

        while True:
            try:
                (method, arg) = raw.split(None, 1)
            except ValueError:
                method = raw
                arg = ""
            if method.startswith("@") and method != "@":
                try:
                    d = getattr(self.decorators, method[1:])
                    if d.exposed:
                        cherrypy.request.bunny1["decorators"].append(d)
                    else:
                        # shold really use a different kind of exception
                        # and raise that here, but this works for now
                        raise DoesNotExist(method)
                    raw = arg
                except (AttributeError, DoesNotExist):
                    return self.error("no decorator named %s %s" % (escape(method), repr(self.decorators)))
            else:
                break

        # use aliases
        try:
            method = cherrypy.request.cookie["alias." + method].value
        except KeyError:
            pass

        # @ is a symbol that works if you have a server on your LAN
        # with the same name as a command you want to use
        if method == "@":
            try:
                (method, arg) = arg.split(None, 1)
            except ValueError:
                method = arg
                arg = ""

        # go to the default URL if there is just a decorator given
        if method == "":
            method = "url"
            arg = self.decorators.default_url()

        # if you type in a URL, just go there
        if urlparse.urlsplit(method)[0]:
            method = "url"
            arg = raw

        # debug mode: gives the URLs of redirects rather than redirecting
        if method == "_debug":
            try:
                return self.do_command(arg)
            except HTTPRedirect, redir:
                url = escape(redir.urls[0])
                return "<code><b>bunny1</b> DEBUG: redirect to <a href='%s'>%s</a></code>" % (url, url)