"TurboGears Front-to-Back Web Framework"
__version__ = "0.8.9"
__author__ = "Kevin Dangoor"
__email__ = "dangoor+turbogears@gmail.com"
__copyright__ = "Copyright 2005 Kevin Dangoor"
__license__ = "MIT"

import sys
import urllib

from turbogears import startup

from turbogears import controllers
expose = controllers.expose
flash = controllers.flash

from turbogears import controllers, view, database, validators, command

def url(tgpath, tgparams=None, **kw):
    """Computes URLs.

    tgpath can be a list or a string. If the path is absolute (starts
    with a "/"), the server.webpath and the approot of the application
    are prepended to the path. In order for the approot to be
    detected properly, the root object should extend controllers.Root.

    Query parameters for the URL can be passed in as a dictionary in
    the second argument *or* as keyword parameters."""
    if not isinstance(tgpath, str):
        tgpath = "/".join(list(tgpath))
    if tgpath.startswith("/"):
        import cherrypy
        if cherrypy.request.approot != "/":
            tgpath = cherrypy.request.approot + tgpath
    
    if tgparams:
        tgparams.update(kw)
    else:
        tgparams = kw
    
    result = tgpath
    args = ["%s=%s" % (key, urllib.quote(str(value))) 
            for key, value in tgparams.items()]
    if args:
        result += "?" + "&".join(args)
    return result

__all__ = ["url", "expose", "flash", "view", "controllers", 
           "database", "command", "validators"]