def _decode_unicode value charset errors Like the regular decode funct

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def _decode_unicode(value, charset, errors):
"""Like the regular decode function but this one raises an
`HTTPUnicodeError` if errors is `strict`."""
fallback = None
if errors.startswith('fallback:'):
fallback = errors[9:]
errors = 'strict'
try:
return value.decode(charset, errors)
except UnicodeError, e:
if fallback is not None:
return value.decode(fallback, 'ignore')
from werkzeug.exceptions import HTTPUnicodeError
raise HTTPUnicodeError(str(e))