Beispiel #1
0
    def test_serialization_to_simple_dict(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        val = CCM(i=5, s='a', c=CM(i=7, s='b'))

        d = DictObject.object_to_flat_dict(CCM, val)

        assert d['i'] == 5
        assert d['s'] == 'a'
        assert d['c_i'] == 7
        assert d['c_s'] == 'b'

        assert len(d) == 4
Beispiel #2
0
    def __init__(self, app=None, validator=None, mime_type=None, tmp_dir=None,
                                                      tmp_delete_on_close=True):
        DictObject.__init__(self, app, validator, mime_type)

        self.tmp_dir = tmp_dir
        self.tmp_delete_on_close = tmp_delete_on_close
Beispiel #3
0
def get_object_as_dict(o, cls, wrapper_name=None):
    return list(DictObject._object_to_doc(cls, o, wrapper_name))[0]
Beispiel #4
0
def get_dict_as_object(d, cls):
    if issubclass(cls, Array):
        d = list(d.values())[0]  # FIXME: Hack!

    return DictObject._doc_to_object(cls, d)