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)
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
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
def test_from_utf8_with_win1252able_object(): if PY2: with pytest.raises(UnicodeDecodeError): from_utf8(win1252able) else: assert repr(win1252able) == from_utf8(win1252able)
def test_from_utf8_with_win1252(): win1252 = UNICODE.utf8.encode('windows-1252', 'ignore') with pytest.raises(UnicodeDecodeError): from_utf8(win1252)