예제 #1
0
def datawrap(v):
    type_ = _get(v, CLASS)

    if type_ is dict:
        m = Data()
        _set(m, SLOT, v)  # INJECT m.__dict__=v SO THERE IS NO COPY
        return m
    elif type_ is tuple:
        return FlatList(v)
    elif type_ is list:
        return FlatList(v)
    elif type_ in (Data, DataObject, FlatList, NullType):
        return v
    elif type_ in (none_type, text, binary_type, int, float, Decimal, datetime,
                   date):
        return v
    elif type_ in generator_types:
        return (to_data(vv) for vv in v)
    elif isinstance(v, (text, binary_type, int, float, Decimal, datetime, date,
                        FlatList, NullType, Mapping, none_type)):
        return v
    elif hasattr(v, "__data__"):
        return v.__data__()
    else:
        return DataObject(v)
예제 #2
0
def zip(keys, values):
    """
    CONVERT LIST OF KEY/VALUE PAIRS TO Data
    PLEASE `import dot`, AND CALL `dot.zip()`
    """
    output = Data()
    for i, k in enumerate(keys):
        if i >= len(values):
            break
        output[k] = values[i]
    return output
예제 #3
0
def wrap(v):
    type_ = _get(v, "__class__")

    if type_ is dict:
        m = Data(v)
        return m
        # m = object.__new__(Data)
        # object.__setattr__(m, "_dict", v)
        # return m

    elif type_ is NoneType:
        return Null
    elif type_ is list:
        return FlatList(v)
    elif type_ is GeneratorType:
        return (wrap(vv) for vv in v)
    else:
        return v