Coverage for jsanctions/helpers.py: 100%

# Coverage for jsanctions/helpers.py : 100%

## 22 statements

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

1 import logging

2 from typing import Dict, Any, Callable, Optional

3 import pytz

4

5 logger = logging.getLogger(__name__)

6

7

8 def 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

16 def 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