def set_r(self, pkey, data, notify=True): old = self._primary.get(pkey) if old is not None: self._unindex(pkey, old) self._primary[pkey] = data self._index(pkey, data) if pkey > self._pkey: self._pkey = pkey if notify: self._save() info_r = KeyValueChange(pkey, data, old) self.notify('change_r', info_r) self.notify('key_r:%s' % pkey, info_r) info = lambda: KeyValueChange(pkey, decodes(data), old and decodes(old)) self.notify('change', info) self.notify('key:%s' % pkey, info)
def main(): opt, args = getOptions('-hn') filename = args[0] data = open(filename).read() value = decodes(data) dir, name = os.path.split(filename) is_name = dir.endswith('names') or opt('-n') if is_name and type(value) is Record and value.type_name == 'ref': try: data = open(os.path.join(dir, '../caps', value.value['path'])).read() except IOError: pass else: value = decodes(data, check=False) pw(sys.stdout, value) print
def main(): opt, args = getOptions('-hn') filename = args[0] data = open(filename).read() value = decodes(data) dir, name = os.path.split(filename) is_name = dir.endswith('names') or opt('-n') if is_name and type(value) is Record and value.type_name == 'ref': try: data = open(os.path.join(dir, '../caps', value.value['path'])).read() except IOError: pass else: value = decodes(data, check=False) pw(sys.stdout, value) print
def update(self, filter, values, model=None): pkeys = [] for kv in self.select_r(filter): rec = decodes(kv.value) if updateFields(rec, values, model): pkeys.append(kv.key) self.set_r(kv.key, encodes(rec)) return pkeys
def set_r(self, pkey, data, notify=True): old = self._primary.get(pkey) if old is not None: self._unindex(pkey, old) self._primary[pkey] = data self._index(pkey, data) if pkey > self._pkey: self._pkey = pkey if notify: self._save() info_r = KeyValueChange(pkey, data, old) self.notify('change_r', info_r) self.notify('key_r:%s' % pkey, info_r) info = lambda: KeyValueChange(pkey, decodes(data), old and decodes( old)) self.notify('change', info) self.notify('key:%s' % pkey, info)
def update(self, filter, values, model=None): pkeys = [] for kv in self.select_r(filter): rec = decodes(kv.value) if updateFields(rec, values, model): pkeys.append(kv.key) self.set_r(kv.key, encodes(rec)) return pkeys
def filter(self, iter): for kv in iter: try: rec = decodes(kv.value) except: # Ignore/reject records which cannot be decoded. continue if self.query.match(rec): yield kv
def filter(self, iter): for kv in iter: try: rec = decodes(kv.value) except: # Ignore/reject records which cannot be decoded. continue if self.query.match(rec): yield kv
def _handle(self, ev, msg): if msg['pcol'] == 'json': addr = json.loads(msg['message'])['o'] else: addr = decodes(msg['message']) addr = addr.rstrip('/') + '/' # normalise path. for e in self.endpoints: if addr.startswith(e.path): e.notify(ev, msg) break
def __getitem__(self, path): # we get instantiated values if path in self.cache: return self.cache[path] ctx = self.make_context(self, path) obj = decodes(self.store[path], ctx) self._addRef(path, obj) if type(getattr(obj, 'ref', None)) is Ref: self.cache[path] = obj return obj
def _handle(self, ev, msg): if msg['pcol'] == 'json': addr = json.loads(msg['message'])['o'] else: addr = decodes(msg['message']) addr = addr.rstrip('/') + '/' # normalise path. for e in self.endpoints: if addr.startswith(e.path): e.notify(ev, msg) break
def getn(self, name): ctx = self.storage.make_context(self.storage) try: return decodes(self.store[name], ctx) except KeyError: pass ref = self._autoMake(name) if ref is None: raise NoSuchName(name) self.setn(name, ref) return ref
def _put(self, data, notify=True): self._pkey += 4 self._primary[self._pkey] = data self._index(self._pkey, data) if notify: self._save() info_r = KeyValueChange(self._pkey, data, None) self.notify('change_r', info_r) self.notify('key_r:%s' % self._pkey, info_r) info = lambda: KeyValueChange(self._pkey, decodes(data), None) self.notify('change', info) self.notify('key:%s' % self._pkey, info)
def _put(self, data, notify=True): self._pkey += 4 self._primary[self._pkey] = data self._index(self._pkey, data) if notify: self._save() info_r = KeyValueChange(self._pkey, data, None) self.notify('change_r', info_r) self.notify('key_r:%s' % self._pkey, info_r) info = lambda: KeyValueChange(self._pkey, decodes(data), None) self.notify('change', info) self.notify('key:%s' % self._pkey, info)
def _pop(self, pkey, notify=True): try: data = self._primary[pkey] except KeyError: raise KeyError(pkey) self._unindex(pkey, data) del self._primary[pkey] if notify: self._save() info_r = KeyValueChange(pkey, None, data) self.notify('change_r', info_r) self.notify('key_r:%s' % pkey, info_r) info = lambda: KeyValueChange(pkey, None, decodes(data)) self.notify('change', info) self.notify('key:%s' % pkey, info) return data
def _pop(self, pkey, notify=True): try: data = self._primary[pkey] except KeyError: raise KeyError(pkey) self._unindex(pkey, data) del self._primary[pkey] if notify: self._save() info_r = KeyValueChange(pkey, None, data) self.notify('change_r', info_r) self.notify('key_r:%s' % pkey, info_r) info = lambda: KeyValueChange(pkey, None, decodes(data)) self.notify('change', info) self.notify('key:%s' % pkey, info) return data
def _join1(self, l_pk, left, join, query, func): l_col, r_col, type = join.leftCol, join.rightCol, join.type if r_col != '#': r_col = ':' + r_col spec = '%s %s' % (r_col, type) limit = join.limit or sys.maxint try: key = l_pk if l_col == '#' else left[l_col] except (KeyError, AttributeError): to_join = [] else: filters = [query, Range(0, limit)] if query is not None else [Range(0, limit)] to_join = self.select_r([Key(spec, key)] + filters) if not to_join and join.nulls: to_join.append(KeyValue(0, encodes({}))) for kv in to_join: right = decodes(kv.value) func(l_pk, left, kv.key, right)
def _join1(self, l_pk, left, join, query, func): l_col, r_col, type = join.leftCol, join.rightCol, join.type if r_col != '#': r_col = ':' + r_col spec = '%s %s' % (r_col, type) limit = join.limit or sys.maxint try: key = l_pk if l_col == '#' else left[l_col] except (KeyError, AttributeError): to_join = [] else: filters = [query, Range(0, limit) ] if query is not None else [Range(0, limit)] to_join = self.select_r([Key(spec, key)] + filters) if not to_join and join.nulls: to_join.append(KeyValue(0, encodes({}))) for kv in to_join: right = decodes(kv.value) func(l_pk, left, kv.key, right)
def get(self, pkey): return decodes(self.get_r(pkey))
def index_r(self, rec): return self.index(decodes(rec))
def index_r(self, raw_rec): try: return self.index(decodes(raw_rec)) except: return '\0'
def update_r(self, filter, values, model=None): if model is not None: model = decodes(model) return self.update(filter, values, model)
def select(self, filter=None): kvl = self.select_r(filter) for kv in kvl: kv.value = decodes(kv.value) return kvl
def update_r(self, filter, values, model=None): if model is not None: model = decodes(model) return self.update(filter, values, model)
def __getslice__(self, i, j): return [decodes(s, self.storage_ctx) for s in self.log[i:j]]
def get(self, pkey): return decodes(self.get_r(pkey))
def index_r(self, raw_rec): try: return self.index(decodes(raw_rec)) except: return '\0'
def index_r(self, rec): return self.index(decodes(rec))
def convert(v1, v2, value): if v1.node_id == v2.node_id: return v2.localize(v1.delocalize(value)) return decodes(encodes(value, v1.encodeRemote), v2.decodeRemote)
def _join_r(self, left, join, query, func): for lkv in left: self._join1(lkv.key, decodes(lkv.value), join, query, func)
def __getitem__(self, i): return decodes(self.log[i], self.storage_ctx)
def _join_r(self, left, join, query, func): for lkv in left: self._join1(lkv.key, decodes(lkv.value), join, query, func)
def select(self, filter=None): kvl = self.select_r(filter) for kv in kvl: kv.value = decodes(kv.value) return kvl
def __getitem__(self, i): return decodes(self.log[i], self.storage_ctx)
def __getslice__(self, i, j): return [decodes(s, self.storage_ctx) for s in self.log[i:j]]