Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 def get(self, pkey):
     return decodes(self.get_r(pkey))
Exemplo n.º 20
0
 def index_r(self, rec):
     return self.index(decodes(rec))
Exemplo n.º 21
0
 def index_r(self, raw_rec):
     try:
         return self.index(decodes(raw_rec))
     except:
         return '\0'
Exemplo n.º 22
0
 def update_r(self, filter, values, model=None):
     if model is not None:
         model = decodes(model)
     return self.update(filter, values, model)
Exemplo n.º 23
0
 def select(self, filter=None):
     kvl = self.select_r(filter)
     for kv in kvl:
         kv.value = decodes(kv.value)
     return kvl
Exemplo n.º 24
0
 def update_r(self, filter, values, model=None):
     if model is not None:
         model = decodes(model)
     return self.update(filter, values, model)
Exemplo n.º 25
0
 def __getslice__(self, i, j):
     return [decodes(s, self.storage_ctx) for s in self.log[i:j]]
Exemplo n.º 26
0
 def get(self, pkey):
     return decodes(self.get_r(pkey))
Exemplo n.º 27
0
 def index_r(self, raw_rec):
     try:
         return self.index(decodes(raw_rec))
     except:
         return '\0'
Exemplo n.º 28
0
 def index_r(self, rec):
     return self.index(decodes(rec))
Exemplo n.º 29
0
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)
Exemplo n.º 30
0
 def _join_r(self, left, join, query, func):
     for lkv in left:
         self._join1(lkv.key, decodes(lkv.value), join, query, func)
Exemplo n.º 31
0
 def __getitem__(self, i):
     return decodes(self.log[i], self.storage_ctx)
Exemplo n.º 32
0
 def _join_r(self, left, join, query, func):
     for lkv in left:
         self._join1(lkv.key, decodes(lkv.value), join, query, func)
Exemplo n.º 33
0
 def select(self, filter=None):
     kvl = self.select_r(filter)
     for kv in kvl:
         kv.value = decodes(kv.value)
     return kvl
Exemplo n.º 34
0
 def __getitem__(self, i):
     return decodes(self.log[i], self.storage_ctx)
Exemplo n.º 35
0
 def __getslice__(self, i, j):
     return [decodes(s, self.storage_ctx) for s in self.log[i:j]]