1# Demo of the new 2.3 self-referential view structures. 2# 3# Output: 4# 0 5# 00000 1 6# 11111 1 7# 22222 0 8# [Property('S', 's'), Property('V', 'sub')] 9# 00000 1 10# 11111 1 11# 22222 0 12# [Property('S', 's'), Property('I', 'i'), Property('V', 'sub')] 13# ok 14 15import os 16try: os.remove("_selfref.mk") 17except: pass 18 19import metakit 20db = metakit.storage('_selfref.mk',1) 21vw = db.getas('data[s:S,sub[^]]') 22 23print len(vw) 24 25v = vw 26for i in range(3): 27 v.append(s=`i`*5) 28 v = v[0].sub 29 30def show(vw): 31 for v in [vw[0], vw[0].sub[0], vw[0].sub[0].sub[0]]: 32 print v.s, len(v.sub) 33 print vw[0].sub[0].sub[0].sub.structure() 34 assert len(vw[0].sub[0].sub[0].sub) == 0 35 try: 36 metakit.dump(vw[0].sub[0].sub[0].sub[0].sub) 37 except IndexError: 38 pass 39 40show(vw) 41 42# note that (recursive!) on-the-fly restructuring works 43show(db.getas('data[s:S,i:I,sub[^]]')) 44 45db.commit() 46print 'ok' 47 48os.remove("_selfref.mk") 49