How to use the riffle.model.Model function in Riffle

To help you get started, we’ve selected a few Riffle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github exis-io / Exis / python / pyRiffle / riffle / cumin.py View on Github external
# Format passed in should be [bool]. Internal types should be homogenous
            # Output should be [bool]
            elif type(t) is list:
                if len(t) > 1:
                    raise utils.SyntaxError("Lists can only have one internal type.")

                if t[0] in [int, float, bool, str, list, dict]:
                    typeList.append([t[0].__name__])
                else: 
                    raise utils.SyntaxError("Unknown type ", t[0])

            # Same as above-- homogenous key:value pairs, OR just the dict itself
            elif t is dict:
                typelist.append({k: v.reflect() if isinstance(v, Model) else v for k, v in t})

            elif issubclass(t, model.Model):
                typeList.append(t.reflect())

            else:
                print 'Type ' + str(t) + ' is not natively serializible!'

    return json.dumps(typeList)
github exis-io / Exis / python / pyRiffle / riffle / cumin.py View on Github external
def marshall(args):
    ''' Ask models to serialize themselves, if present. Returns JSON. '''
    return json.dumps([x._serialize() if isinstance(x, model.Model) else x for x in args])
github exis-io / Exis / python / pyRiffle / riffle / cumin.py View on Github external
Objects and exceptions are recreated from dictionaries if appropriate. 
    '''

    # If types is None, allow all arguments
    if not types:
        return args

    # return tuple([x._deserialize() if isinstance(x, Model) else y for x, y in zip(types, args)])

    l = list()
    for x, y in zip(args, types):
        # Try to check if y is a Model, but if y is a list this will throw an exception
        # so deal with that properly
        try:
            b = issubclass(y, model.Model)
        except:
            b = False
        if b:
            l.append(y._deserialize(x))
        else:
            l.append(x)
    return tuple(l)