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)
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
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
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
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
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()
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
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
def process(value): if value is not None: return get_dict_as_object(json.loads(value), self.cls)