Example #1
0
def unquote_plus(string, errors='ignore'):
    """A wrapper for urllib.unquote_plus() that UTF-8 decodes strs.
    Should always return a unicode.

    errors - What to do on a decoding error? Default behavior is
    to ignore bytes that we can't decode."""
    return from_utf8(urllib.unquote_plus(to_utf8(string)), errors=errors)
Example #2
0
def unquote_plus(string, errors='ignore'):
    """A wrapper for urllib.unquote_plus() that UTF-8 decodes strs.
    Should always return a unicode.

    errors - What to do on a decoding error? Default behavior is
    to ignore bytes that we can't decode."""
    return from_utf8(urllib.unquote_plus(to_utf8(string)), errors=errors)
Example #3
0
def parse_qs(query_string, errors='ignore'):
    """Wrap urlparse.parse_qs() to handle URL-encoded strings stored in class unicode and similar travesties."""
    # Actually from urlparse, not urllib; might get its own urlparse_utf8.py some day.
    kwargs_bytes = urlparse.parse_qs(to_utf8(query_string))
    kwargs = dict(((
        key,
        [from_utf8(value, errors=errors) for value in value_list],
    ) for key, value_list in kwargs_bytes.iteritems()))
    return kwargs
Example #4
0
def parse_qs(query_string, errors='ignore'):
    """Wrap urlparse.parse_qs() to handle URL-encoded strings stored in class unicode and similar travesties."""
    # Actually from urlparse, not urllib; might get its own urlparse_utf8.py some day.
    kwargs_bytes = urlparse.parse_qs(to_utf8(query_string))
    kwargs = dict((
        (
            key,
            [from_utf8(value, errors=errors) for value in value_list],
        )
        for key, value_list in kwargs_bytes.items()
    ))
    return kwargs
Example #5
0
def splitvalue(string):
    return urllib.splitvalue(to_utf8(string))
Example #6
0
def quote_plus(string, *args, **kwargs):
    """A wrapper for urllib.quote_plus() that UTF-8 encodes string if
    query is unicode. Always returns a str."""
    assert isinstance(string, basestring), type(string)
    return urllib.quote_plus(to_utf8(string), *args, **kwargs)
Example #7
0
def quote(string, *args, **kwargs):
    """A wrapper for urllib.quote() that UTF-8 encodes string if
    query is unicode. Always returns a str."""
    return urllib.quote(to_utf8(string), *args, **kwargs)
Example #8
0
def urlencode(query, *args, **kwargs):
    """A wrapper for urllib.urlencode() that UTF-8 encodes query if
    query is unicode. Always returns a str."""
    return urllib.urlencode([(to_utf8(k), to_utf8(v))
                             for (k, v) in _pairs(query)], *args, **kwargs)
Example #9
0
def splitvalue(string):
    return urllib.splitvalue(to_utf8(string))
Example #10
0
def quote(string, *args, **kwargs):
    """A wrapper for urllib.quote() that UTF-8 encodes string if
    query is unicode. Always returns a str."""
    return urllib.quote(to_utf8(string), *args, **kwargs)
Example #11
0
def quote_plus(string, *args, **kwargs):
    """A wrapper for urllib.quote_plus() that UTF-8 encodes string if
    query is unicode. Always returns a str."""
    assert isinstance(string, basestring), type(string)
    return urllib.quote_plus(to_utf8(string), *args, **kwargs)
Example #12
0
 def encode_pair(key, val):
     if doseq and isinstance(val, (list, tuple)):
         return to_utf8(key), [to_utf8(item) for item in val]
     else:
         return to_utf8(key), to_utf8(val)
Example #13
0
 def splitvalue(string):
     return urlparse.splitvalue(to_utf8(string))
Example #14
0
 def encode_pair(key, val):
     if doseq and isinstance(val, (list, tuple)):
         return to_utf8(key), [to_utf8(item) for item in val]
     else:
         return to_utf8(key), to_utf8(val)
Example #15
0
def urlencode(query, *args, **kwargs):
    """A wrapper for urllib.urlencode() that UTF-8 encodes query if
    query is unicode. Always returns a str."""
    return urllib.urlencode([(to_utf8(k), to_utf8(v)) for (k, v) in _pairs(query)], *args, **kwargs)
Example #16
0
 def splitvalue(string):
     return urlparse.splitvalue(to_utf8(string))