Exemplo n.º 1
0
def url():
    """Returns the url of the current request.

    >>> os.environ.update({"REQUEST_URI": "/path/to/script?foo=bar",
    ...                    "HTTP_HOST": "www.example.org",
    ...                    "SERVER_PORT": "80"})
    >>> url()
    URL('http', u'www.example.org', 80, [u'path', u'to', u'script'], [(u'foo', u'bar')], None)
    """
    path = os.environ["REQUEST_URI"]
    if "?" in path:
        path, query = path.split("?", 1)
        query = parse_query_string(query)
    else:
        query = None

    path = parse_path(path)
    port = server.port()

    scheme = "http"
    if port == 443:
        scheme = "https"

    return URL(scheme, host(), port, path, query, None)
Exemplo n.º 2
0
def handle_post_form_url_encoded(data):
    params = parse_query_string(data)
    content = validate_form({"content": {}}, params)
    create_entry(content)