from __pyjamas__ import JS
# TODO: implement safe
def quote(s, safe=''):
    """
    This function is equivalent to urllib.quote().

    Example:

    >>> quote("hey")
    'hey'
    >>> quote("$%&/?/+ s")
    '%24%25%26%2F%3F%2F%2B%20s'

    """
    from __javascript__ import encodeURIComponent
    return encodeURIComponent(s)

def urlencode(d):
    """
    Equivalent of urllib.urlencode().

    Examples:
    >>> urlencode({"a": 34, "bbb": "ccc"})
    'a=34&bbb=ccc'
    >>> urlencode({"a": 34, "bbb": "$%&/?/+ s"})
    'a=34&bbb=%24%25%26%2F%3F%2F%2B%20s'
    >>> urlencode({"a": 34})
    'a=34'
    >>> urlencode({})
    ''

    """
    s = ""
    for i, v in d.iteritems():
        s += "%s=%s&" % (i, quote(str(v)))
    if s != "":
        s = s[:-1]
    return s

@@ -323,16 +323,302 @@
 ent(s)%0A%0A
+def unquote_plus(s):%0A    %22%22%22%0A    This function is equivalent to urllib.unquote_plus%0A%0A    Example:%0A%0A    %3E%3E%3E unquote(%22hey%22)%0A    'hey'%0A    %3E%3E%3E unquote('%2524%2525%2526%252F%253F%252F%252B%2520s')%0A    %22$%25&/?/+ s%22%0A%0A    %22%22%22%0A    from __javascript__ import decodeURIComponent%0A    return decodeURIComponent(s)%0A%0A
 def urle

add urllib.unquote_plus