def process(value): retval = None if isinstance(value, string_types): value = json.loads(value) if value is not None: retval = self.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 os.fstat(retval.handle.fileno()).st_size > 0: h.mmap = mmap(h.fileno(), 0, access=ACCESS_READ) retval.data = [h.mmap] # FIXME: Where do we close this mmap? else: retval.data = [''] else: logger.error("File %r is not readable", path) return retval
def process(value): if value is None: return None if isinstance(value, six.text_type): value = json.loads(value) elif isinstance(value, six.binary_type): value = json.loads(value.decode('utf8')) retval = self.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) retval.handle = None retval.data = [b''] if not os.access(path, os.R_OK): logger.error("File %r is not readable", path) return retval h = retval.handle = SeekableFileProxy(open(path, 'rb')) if os.fstat(retval.handle.fileno()).st_size > 0: h.mmap = mmap(h.fileno(), 0, access=ACCESS_READ) retval.data = [h.mmap] # FIXME: Where do we close this mmap? return retval