"""
Build a search URL for the supplied argument or just a link to a search
engine if no args are present.

Defaults to google.  Edit the macro to modify the engine(/url).

This script doesn't encode the search string provided.  Seems to work fine
on IE 6 and FireFox 1.0.
"""

searchurl_prefix="http://www.google.com/search?hl=en&q="
searchurl="http://www.google.com/"

from StringIO import StringIO

def execute(hdf, args, env):

  url= None
  link= None
  if args:
      text = args
      url = searchurl_prefix + args
  else:
      text = "Search"
      url = searchurl

  buf = StringIO()
  buf.write('<a title="Search" href="%s">' % url)
  buf.write(text)
  buf.write('</a>\n')

  return buf.getvalue()

