def db_replace_record(obj):
 if isinstance(obj, collections.Mapping):
  for (k, v) in six.iteritems(obj):
   if isinstance(v, api.Command):
    obj[k] = v.result
 elif (isinstance(obj, collections.Sequence) and (not isinstance(obj, six.string_types))):
  for (i, v) in enumerate(obj):
   if isinstance(v, api.Command):
    try:
     obj[i] = v.result
    except TypeError:
     return type(obj)((getattr(v, 'result', v) for v in obj))
 elif isinstance(obj, api.Command):
  obj = obj.result
 return obj

def db_replace_record ( obj ) : if isinstance ( obj , collections . Mapping ) : for ( k , v ) in six . iteritems ( obj ) : if isinstance ( v , api . Command ) : obj [ k ] = v . result elif ( isinstance ( obj , collections . Sequence ) and ( not isinstance ( obj , six . string_types ) ) ) : for ( i , v ) in enumerate ( obj ) : if isinstance ( v , api . Command ) : try : obj [ i ] = v . result except TypeError : return type ( obj ) ( ( getattr ( v , 'result' , v ) for v in obj ) ) elif isinstance ( obj , api . Command ) : obj = obj . result return obj
replace any api .