def inner(apidata, indata): """ :param apidata: :type apidata: dprotocol instance :param indata: :type indata: iterable :param deep: how deep I'm :return: dict """ # apidata is a dprotocol instance, predefined inside our backend as # DProtocol implementation in both way it inherit from BaseProtocolActions which provides # IBaseProtocolActionsInterface for key, _ in apidata.to_dict().iteritems(): # so if we meet attribute from IBaseProtocolActionsInterface type means it's a sub protocol # and we have to call inner if IBaseProtocolActionsInterface.providedBy( getattr(apidata, key)): inner(getattr(apidata, key), indata) else: # otherwise we will looping over all items in indata for inner_key, inner_val in indata.iteritems(): # 1. we checking whether the inner_key exist directly in our root dict of apidata if inner_key in apidata.to_dict(): # if exist we get the value from apidata.to_dict().get(inner_key) with ik as key indata[inner_key] = apidata.to_dict().get( inner_key) elif isinstance(inner_val, dict): # 2.if inner_val is a dict first we will trying to get the apidata key # from this dict if key in inner_val: # if exist will update the indata for this key indata[inner_key].update( {key: apidata.to_dict().get(key)}) else: # else we pass the inner_val to our inner again for more # nested structures inner(apidata, inner_val) return indata
def inner(apidata, indata): """ :param apidata: :type apidata: dprotocol instance :param indata: :type indata: iterable :param deep: how deep I'm :return: dict """ # apidata is a dprotocol instance, predefined inside our backend as # DProtocol implementation in both way it inherit from BaseProtocolActions which provides # IBaseProtocolActionsInterface for key, _ in apidata.to_dict().iteritems(): # so if we meet attribute from IBaseProtocolActionsInterface type means it's a sub protocol # and we have to call inner if IBaseProtocolActionsInterface.providedBy(getattr(apidata, key)): inner(getattr(apidata, key), indata) else: # otherwise we will looping over all items in indata for inner_key, inner_val in indata.iteritems(): # 1. we checking whether the inner_key exist directly in our root dict of apidata if inner_key in apidata.to_dict(): # if exist we get the value from apidata.to_dict().get(inner_key) with ik as key indata[inner_key] = apidata.to_dict().get(inner_key) elif isinstance(inner_val, dict): # 2.if inner_val is a dict first we will trying to get the apidata key # from this dict if key in inner_val: # if exist will update the indata for this key indata[inner_key].update({key: apidata.to_dict().get(key)}) else: # else we pass the inner_val to our inner again for more # nested structures inner(apidata, inner_val) return indata
def test_base_protocol_actions(self): actions = BaseProtocolActions() self.assertTrue(IBaseProtocolActionsInterface.providedBy(actions))