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 datetime 

2import logging 

3 

4import suds 

5 

6logging.basicConfig(level=logging.INFO) 

7 

8 

9class ExactTargetHelpers: 

10 

11 @staticmethod 

12 def suds_to_dict(suds_obj_): 

13 """ 

14 Converts suds object to dict. 

15 Note: this function uses recursion 

16 :param suds_obj_: suds object 

17 :return: dict object 

18 """ 

19 if not hasattr(suds_obj_, '__keylist__'): 

20 if not isinstance(suds_obj_, type(None)): 

21 if isinstance(suds_obj_, suds.sax.text.Text): 

22 return str(suds_obj_) 

23 elif isinstance(suds_obj_, type(datetime.time)) or isinstance(suds_obj_, type(datetime.datetime)): 

24 return str(suds_obj_) 

25 else: 

26 return suds_obj_ 

27 else: 

28 return None 

29 data = {} 

30 fields = suds_obj_.__keylist__ 

31 for field in fields: 

32 value = getattr(suds_obj_, field) 

33 if isinstance(value, list): 

34 # recreate the list, converting objects within recursively. 

35 data[field] = [ExactTargetHelpers.suds_to_dict(item) for item in value] 

36 else: 

37 data[field] = ExactTargetHelpers.suds_to_dict(value) 

38 

39 return data