from django.utils.http import urlquote_plus


def urlencode(query, doseq=0, safe=''):
    """Custom urlencode that leaves static map delimiters ("|", ",", ":") alone.

    Based on Django's unicode-safe version of urllib.quote_plus.

    """
    safe = safe + '|,:'
    if hasattr(query, 'items'):
        query = query.items()
    if not doseq:
        return '&'.join([urlquote_plus(k, safe) + '=' + urlquote_plus(v, safe)
                         for k, v in query])
    else:
        return '&'.join([urlquote_plus(k, safe) + '=' + urlquote_plus(v, safe)
                         for k, s in query
                         for v in ((isinstance(s, basestring) and [s]) or
                                   (hasattr(s, '__len__') and s) or [s])])

@@ -325,30 +325,8 @@
 s()%0A
-    if not doseq:%0A    
     
@@ -400,146 +400,8 @@
 fe)%0A
-                         for k, v in query%5D)%0A    else:%0A        return '&'.join(%5Burlquote_plus(k, safe) + '=' + urlquote_plus(v, safe)%0A    
     
@@ -435,20 +435,16 @@
 n query%0A
-    
         
@@ -501,19 +501,16 @@
 and %5Bs%5D)
- or
 %0A       
@@ -537,13 +537,22 @@
     
-    (
+or (doseq and 
 hasa
@@ -575,16 +575,47 @@
 ) and s)
+%0A                              
  or %5Bs%5D)

Tweak custom urlencode.