def encode(self, model, data, **kwargs): # Retrieve item minimize protocol protocol = model.__protocols__.get('minimize') if model.__protocols__ else None if protocol is None: raise ValueError('Model %r has no "minimize" protocol defined' % model) if inspect.isfunction(protocol): protocol = protocol() return Minimize.encode(data, protocol)
def decode(self, model, encoded, children=True, ignore_keys=None, **kwargs): if model.__wrapper__: media = kwargs.get('media') if media is None: raise ValueError('Missing required parameters: "media"') model = model.resolve(media) # Retrieve item minimize protocol protocol = model.__protocols__.get('minimize') if model.__protocols__ else None if protocol is None: raise ValueError('Model %r has no "minimize" protocol defined' % model) if inspect.isfunction(protocol): protocol = protocol() return Minimize.decode( encoded, protocol, children=children, ignore_keys=ignore_keys )