Example #1
0
 def process(value):
     if isinstance(value, six.string_types):
         return get_dict_as_object(json.loads(value), self.cls,
                 ignore_wrappers=self.ignore_wrappers,
                 complex_as=self.complex_as)
     if value is not None:
         return get_dict_as_object(value, self.cls,
                 ignore_wrappers=self.ignore_wrappers,
                 complex_as=self.complex_as)
Example #2
0
 def process(value):
     if isinstance(value, six.string_types):
         return get_dict_as_object(json.loads(value),
                                   self.cls,
                                   ignore_wrappers=self.ignore_wrappers,
                                   complex_as=self.complex_as)
     if value is not None:
         return get_dict_as_object(value,
                                   self.cls,
                                   ignore_wrappers=self.ignore_wrappers,
                                   complex_as=self.complex_as)
Example #3
0
        def process(value):
            retval = None

            if isinstance(value, six.string_types):
                value = json.loads(value)

            if value is not None:
                retval = get_dict_as_object(
                    value,
                    self.cls,
                    ignore_wrappers=self.ignore_wrappers,
                    complex_as=self.complex_as)
                retval.store = self.store
                retval.abspath = path = join(self.store, retval.path)

                ret = os.access(path, os.R_OK)
                retval.handle = None
                retval.data = ['']

                if ret:
                    h = retval.handle = SeekableFileProxy(open(path, 'rb'))
                    if fstat(retval.handle.fileno()).st_size > 0:
                        h.mmap = mmap(h.fileno(), 0, access=ACCESS_READ)
                        retval.data = [h.mmap]
                    else:
                        retval.data = ['']
                else:
                    logger.error("File %r is not readable", path)

            return retval
Example #4
0
        def process(value):
            retval = None

            if isinstance(value, six.string_types):
                value = json.loads(value)

            if value is not None:
                retval = get_dict_as_object(
                    value,
                    self.cls,
                    ignore_wrappers=self.ignore_wrappers,
                    complex_as=self.complex_as)

                path = join(self.store, retval.path)
                retval.handle = open(path, 'rb')
                if fstat(retval.handle.fileno()).st_size > 0:
                    retval.data = [
                        mmap(retval.handle.fileno(), 0, access=ACCESS_READ)
                    ]
                else:
                    retval.data = ['']
                retval.store = self.store
                retval.abspath = path

            return retval
Example #5
0
        def process(value):
            retval = None

            if isinstance(value, six.string_types):
                value = json.loads(value)

            if value is not None:
                retval = get_dict_as_object(value, self.cls,
                        ignore_wrappers=self.ignore_wrappers,
                        complex_as=self.complex_as)
                retval.store = self.store
                retval.abspath = path = join(self.store, retval.path)

                ret = os.access(path, os.R_OK)
                retval.handle = None
                retval.data = ['']

                if ret:
                    h = retval.handle = SeekableFileProxy(open(path, 'rb'))
                    if fstat(retval.handle.fileno()).st_size > 0:
                        h.mmap = mmap(h.fileno(), 0, access=ACCESS_READ)
                        retval.data = [h.mmap]
                    else:
                        retval.data = ['']
                else:
                    logger.error("File %r is not readable", path)

            return retval
Example #6
0
    def test_the(self):
        class C(ComplexModel):
            __namespace__ = "tns"
            i = Integer
            s = Unicode
            a = Array(DateTime)

            def __eq__(self, other):
                print("Yaaay!")
                return  self.i == other.i and \
                        self.s == other.s and \
                        self.a == other.a

        c = C(i=5, s="x", a=[datetime(2011, 12, 22, tzinfo=pytz.utc)])

        for iw, ca in ((False, dict), (True, dict), (False, list), (True,
                                                                    list)):
            print()
            print('complex_as:', ca)
            d = get_object_as_dict(c, C, complex_as=ca)
            print(d)
            o = get_dict_as_object(d, C, complex_as=ca)
            print(o)
            print(c)
            assert o == c
Example #7
0
    def test_init(self):
        fn = inspect.stack()[0][3]
        from sqlalchemy.inspection import inspect as sqla_inspect

        class SomeClass1(TableModel):
            __tablename__ = "%s_%d" % (fn, 1)
            i = Integer32(pk=True)
            e = Unicode(32)

        from spyne.util.dictdoc import get_dict_as_object
        inst = get_dict_as_object(dict(i=4), SomeClass1)
        assert not sqla_inspect(inst).attrs.e.history.has_changes()
Example #8
0
    def test_init(self):
        fn = inspect.stack()[0][3]
        from sqlalchemy.inspection import inspect as sqla_inspect

        class SomeClass1(TableModel):
            __tablename__ = "%s_%d" % (fn, 1)
            i = Integer32(pk=True)
            e = Unicode(32)

        from spyne.util.dictdoc import get_dict_as_object
        inst = get_dict_as_object(dict(i=4), SomeClass1)
        assert not sqla_inspect(inst).attrs.e.history.has_changes()
Example #9
0
    def test_the(self):
        class C(ComplexModel):
            __namespace__ = "tns"
            i = Integer
            s = Unicode
            a = Array(DateTime)

            def __eq__(self, other):
                print "Yaaay!"
                return self.i == other.i and self.s == other.s and self.a == other.a

        c = C(i=5, s="x", a=[datetime(2011, 12, 22)])

        for iw, ca in ((False, dict), (True, dict), (False, list), (True, list)):
            print
            print "complex_as:", ca
            d = get_object_as_dict(c, C, complex_as=ca)
            print d
            o = get_dict_as_object(d, C, complex_as=ca)
            print o
            print c
            assert o == c
Example #10
0
    def test_the(self):
        class C(ComplexModel):
            __namespace__ = "tns"
            i = Integer
            s = Unicode
            a = Array(DateTime)

            def __eq__(self, other):
                print("Yaaay!")
                return  self.i == other.i and \
                        self.s == other.s and \
                        self.a == other.a

        c = C(i=5, s="x", a=[datetime(2011,12,22, tzinfo=pytz.utc)])

        for iw, ca in ((False,dict), (True,dict), (False,list), (True, list)):
            print()
            print('complex_as:', ca)
            d = get_object_as_dict(c, C, complex_as=ca)
            print(d)
            o = get_dict_as_object(d, C, complex_as=ca)
            print(o)
            print(c)
            assert o == c
Example #11
0
 def process(value):
     if value is not None:
         return get_dict_as_object(json.loads(value), self.cls)
Example #12
0
 def process(value):
     if value is not None:
         return get_dict_as_object(json.loads(value), self.cls)