Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def serialize(self, dest, current, attribute, opts):
data = None
if opts and opts.get('ref'):
if not dest.get('relationships'):
dest['relationships'] = {}
def map_current(item):
return self.serialize_ref(item, current, attribute, opts)
if _.is_list(current.get(attribute)):
data = map(map_current, current[attribute])
else:
data = self.serialize_ref(current[attribute], current,
attribute, opts)
dest['relationships'][self.key_for_attribute(attribute)] = {}
if not opts.get('ignore_relationship_data'):
dest['relationships'][self.key_for_attribute(attribute)]['data'] = data
if opts.get('relationship_links'):
dest['relationships'][self.key_for_attribute(attribute)]['links'] = \
self.get_links(current[attribute], opts['relationship_links'], dest)
if opts.get('relationship_meta'):
dest['relationships'][self.key_for_attribute(attribute)]['meta'] = \
data = self.serialize_ref(current[attribute], current,
attribute, opts)
dest['relationships'][self.key_for_attribute(attribute)] = {}
if not opts.get('ignore_relationship_data'):
dest['relationships'][self.key_for_attribute(attribute)]['data'] = data
if opts.get('relationship_links'):
dest['relationships'][self.key_for_attribute(attribute)]['links'] = \
self.get_links(current[attribute], opts['relationship_links'], dest)
if opts.get('relationship_meta'):
dest['relationships'][self.key_for_attribute(attribute)]['meta'] = \
self.get_meta(current['attribute'], opts['relationship_meta'])
else:
if _.is_list(current[attribute]):
if len(current[attribute]) and _.is_dict(current[attribute][0]):
def map_current(item):
return self.serialize_nested(item, current, attribute,
opts)
data = map(map_current, current[attribute])
else:
data = current[attribute]
dest['attributes'][self.key_for_attribute(attribute)] = data
elif _.is_dict(current[attribute]):
data = self.serialize_nested(current[attribute], current,
attribute, opts)
dest['attributes'][self.key_for_attribute(attribute)] = data
else:
dest['attributes'][self.key_for_attribute(attribute)] = current[attribute]
def _is_complex_type(self, obj):
return _.is_list(obj) or _.is_dict(obj)
acc[self.key_for_attribute(key)] = self.key_for_attribute(value)
else:
acc[self.key_for_attribute(key)] = value
return acc, value, key
def map_function(item):
if self._is_complex_type(item):
return self.key_for_attribute(item)
else:
return item
if _.is_dict(attribute):
return _.transform(attribute, transform_callback)
elif _.is_list(attribute):
map(map_function, attribute)
else:
if _.is_function(self.opts.get('key_for_attribute')):
return self.opts['key_for_attribute'](attribute)
else:
caserized = inflector.caserize(attribute, self.opts)
return caserized