Skip to content

Commit

Permalink
added a inner mehtod to help clean up repeated code for dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ncbraner authored Dec 19, 2022
1 parent cb50873 commit d8f31db
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def client_response_hook(span: Span, message: dict):
import urllib
from functools import wraps
from timeit import default_timer
from typing import Tuple
from typing import Tuple, List, Dict

from asgiref.compatibility import guarantee_single_callable

Expand Down Expand Up @@ -277,19 +277,23 @@ def append_keys(key):
if isinstance(key, bytes):
returnable.append(key.decode("utf8"))
elif isinstance(key, str):
returnable.append(key)
returnable.append(key)

#carrier is a dict, so iterate over .items()
for _key, _val in carrier.items():

#if we have another dict, lets make a recursive call
if isinstance(_val, Dict):
def append_dict_keys(key, val):
#append our current key
append_keys(_key)

#append all keys within the dict
for x in self.keys(_val):
append_keys(x)
append_keys(x)

#carrier is a dict, so iterate over .items()
for _key, _val in carrier.items():

#if we have another dict, lets make a recursive call
if isinstance(_val, Dict):

append_dict_keys(_key, _val)

# if we have a list, lets iter over that. List can contain tuples(headers) dicts and string so lets approach them all as well
elif isinstance(_val, List):
Expand All @@ -301,11 +305,9 @@ def append_keys(key):

#check for the dict
elif isinstance(list_key, Dict):
append_keys(_key)

#append all keys within the dict
for x in self.keys(_val):
append_keys(x)
append_dict_keys(_key, _val)

else:
append_keys(list_key)

Expand Down

0 comments on commit d8f31db

Please sign in to comment.