(self, obj, k)
return v
Get the value from a resource (obj) using the specified field name (k).
        Various levels of defaults are supported. This is where we set defaults.
Get the value from a resource (obj) using the specified field name (k).
        Various levels of defaults are supported. This is where we set defaults.
Get the value from a resource ( obj ) using the specified field name ( k ) . Various levels of defaults are supported . This is where we set defaults .
def _get_coerced_resource_value(self, obj, k):
        """
        Get the value from a resource (obj) using the specified field name (k).
        Various levels of defaults are supported. This is where we set defaults.
        """

        from opsmop.core.resource import Resource

        if k in obj.kwargs:
            # if available, get the value of the key from the object
            v  = obj.kwargs[k]
        else:
            # the field wasn't set on the object
            if self.has_field('default'):
                # if we have a default, use it
                v = self.default
            elif self.loader:
                # if we have a default function that returns a value, use it instead
                v = self.loader()
            elif self.empty:
                # if we allow the object to be empty, and the requested type is a dict or list
                # return empty versions of those
                if self.kind == dict:
                    v = dict()
                elif self.kind == list:
                    v = []
                else:
                    raise Exception("%s, field %s, invalid use of 'empty' without a type" % (obj, k))
            else:
                raise Exception("%s, field %s, missing required value" % (obj, k))

        if issubclass(type(v), Resource) and self.of == list:
            # if something takes a list and one element is supplied, do what the user probably means
            v = [ v ]

        if type(v) == tuple:
            v = list(v)

        return v
def _get_coerced_resource_value ( self , obj , k ) : from opsmop . core . resource import Resource if k in obj . kwargs : # if available, get the value of the key from the object v = obj . kwargs [ k ] else : # the field wasn't set on the object if self . has_field ( 'default' ) : # if we have a default, use it v = self . default elif self . loader : # if we have a default function that returns a value, use it instead v = self . loader ( ) elif self . empty : # if we allow the object to be empty, and the requested type is a dict or list # return empty versions of those if self . kind == dict : v = dict ( ) elif self . kind == list : v = [ ] else : raise Exception ( "%s, field %s, invalid use of 'empty' without a type" % ( obj , k ) ) else : raise Exception ( "%s, field %s, missing required value" % ( obj , k ) ) if issubclass ( type ( v ) , Resource ) and self . of == list : # if something takes a list and one element is supplied, do what the user probably means v = [ v ] if type ( v ) == tuple : v = list ( v ) return v