Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import logging 

2from typing import Dict, Any, Callable, Optional 

3import pytz 

4 

5logger = logging.getLogger(__name__) 

6 

7 

8def get_country_iso2_code(country_description: str) -> str: 

9 country = country_description.lower() 

10 for k, v in pytz.country_names.items(): 

11 if v.lower() == country: 

12 return k 

13 return '' 

14 

15 

16def dict_filter_attributes(data: Dict[str, Any], fn: Optional[Callable[[str, Any], Any]] = None) -> Dict[str, Any]: 

17 if isinstance(data, dict): 

18 for k, v in list(data.items()): 

19 if isinstance(v, dict): 

20 v = dict_filter_attributes(v, fn) 

21 elif isinstance(v, list): 

22 v = [dict_filter_attributes(e, fn) for e in v] 

23 elif k.startswith("@") and len(k) > 1 and isinstance(v, str): 

24 if fn is not None: 

25 v = fn(k, v) 

26 data[k] = v 

27 return data