parent
b85e6e008d
commit
9b81c35d06
1 changed files with 20 additions and 3 deletions
|
@ -369,7 +369,12 @@ def return_values(obj):
|
||||||
sensitive values pre-jsonification."""
|
sensitive values pre-jsonification."""
|
||||||
if isinstance(obj, basestring):
|
if isinstance(obj, basestring):
|
||||||
if obj:
|
if obj:
|
||||||
yield obj
|
if isinstance(obj, bytes):
|
||||||
|
yield obj
|
||||||
|
else:
|
||||||
|
# Unicode objects should all convert to utf-8
|
||||||
|
# (still must deal with surrogateescape on python3)
|
||||||
|
yield obj.encode('utf-8')
|
||||||
return
|
return
|
||||||
elif isinstance(obj, Sequence):
|
elif isinstance(obj, Sequence):
|
||||||
for element in obj:
|
for element in obj:
|
||||||
|
@ -391,10 +396,22 @@ def remove_values(value, no_log_strings):
|
||||||
""" Remove strings in no_log_strings from value. If value is a container
|
""" Remove strings in no_log_strings from value. If value is a container
|
||||||
type, then remove a lot more"""
|
type, then remove a lot more"""
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
if value in no_log_strings:
|
if isinstance(value, unicode):
|
||||||
|
# This should work everywhere on python2. Need to check
|
||||||
|
# surrogateescape on python3
|
||||||
|
bytes_value = value.encode('utf-8')
|
||||||
|
value_is_unicode = True
|
||||||
|
else:
|
||||||
|
bytes_value = value
|
||||||
|
value_is_unicode = False
|
||||||
|
if bytes_value in no_log_strings:
|
||||||
return 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER'
|
return 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER'
|
||||||
for omit_me in no_log_strings:
|
for omit_me in no_log_strings:
|
||||||
value = value.replace(omit_me, '*' * 8)
|
bytes_value = bytes_value.replace(omit_me, '*' * 8)
|
||||||
|
if value_is_unicode:
|
||||||
|
value = unicode(bytes_value, 'utf-8', errors='replace')
|
||||||
|
else:
|
||||||
|
value = bytes_value
|
||||||
elif isinstance(value, Sequence):
|
elif isinstance(value, Sequence):
|
||||||
return [remove_values(elem, no_log_strings) for elem in value]
|
return [remove_values(elem, no_log_strings) for elem in value]
|
||||||
elif isinstance(value, Mapping):
|
elif isinstance(value, Mapping):
|
||||||
|
|
Loading…
Add table
Reference in a new issue