Add SEQUENCETYPE to handle the dict_keys type (#15953)

On python 3, there is a specific type for dict keys
instead of list, so previous tests based on Sequence didn't
not work anymore.
This commit is contained in:
Michael Scherer 2016-05-23 21:17:28 +02:00 committed by Brian Coca
parent c8f0cdbdfd
commit cf44db58e0

View file

@ -123,6 +123,12 @@ except ImportError:
Sequence = (list, tuple)
Mapping = (dict,)
try:
from collections.abc import KeysView
SEQUENCETYPE = (Sequence, KeysView)
except:
SEQUENCETYPE = Sequence
try:
import json
# Detect the python-json library which is incompatible
@ -386,7 +392,7 @@ def return_values(obj):
# (still must deal with surrogateescape on python3)
yield obj.encode('utf-8')
return
elif isinstance(obj, Sequence):
elif isinstance(obj, SEQUENCETYPE):
for element in obj:
for subelement in return_values(element):
yield subelement
@ -422,7 +428,7 @@ def remove_values(value, no_log_strings):
value = unicode(bytes_value, 'utf-8', errors='replace')
else:
value = bytes_value
elif isinstance(value, Sequence):
elif isinstance(value, SEQUENCETYPE):
return [remove_values(elem, no_log_strings) for elem in value]
elif isinstance(value, Mapping):
return dict((k, remove_values(v, no_log_strings)) for k, v in value.items())