I have added support for naming objects in dumps, cross-references
and declarative support in dumps/loads too.
I can't now commit changes. This night I will commit changes to
sources and update project pages.
Here are examples of how it works now:
== Examples with loads==
===Example with recursive list===
>>> lst = pyon.loads("""
... lst = ['foo', lst]
... lst""")
>>> lst is lst[1]
True
===Example with recursive dict===
>>> d = pyon.loads("""
... d = {'a':'foo', 'b':d}
... d""")
>>> d is d['b']
True
===Example with cross-references===
>>> ob = pyon.loads("""
... lst = ['foo', lst, d]
... d = {'a':'foo', 'b':d, 'c':lst}
... [d, lst]""")
>>> lst = ob[1]
>>> d = ob[0]
>>> lst[1] is lst
True
>>> d is d['b']
True
>>> lst[2] is d
True
>>> d['c'] is lst
True
===Example with recursive class and cross-references===
>>> ob = pyon.loads("""
... c = C(parent=c, lst=lst, d=d)
... lst = ['foo', lst, d, c]
... d = {'a':'foo', 'b':d, 'c':lst, 'd':c}
... [d, lst, c]""")
>>> lst = ob[1]
>>> d = ob[0]
>>> c = ob[2]
>>> c.parent is c
True
>>> c.lst is lst
True
>>> c.d is d
True
>>> d is d['b']
True
>>> lst[2] is d
True
>>> d['c'] is lst
True
>>> d['d'] is c
True
>>> lst[3] is c
True
==Examples with dumps==
===Example with naming and assignments==
>>> p1 = (1,2)
>>> p2 = [1,2]
>>> pyon.dumps([p1,p2,p1,p2], fast=False)
_p__0=(1,2)
_p__1=[1,2]
[_p__0,_p__1,_p__0,_p__1]
>>> pyon.dumps([p1,p2,p1,p2], fast=False, p1=p1,p2=p2)
p1=(1,2)
p2=[1,2]
[p1,p2,p1,p2]
===Example with recursive list===
>>> lst = ['foo']
>>> lst.append(lst)
>>> pyon.dumps(lst, fast=False)
_p__0=['foo',_p__0]
_p__0
>>> pyon.dumps(lst, fast=False, lst=lst)
lst=['foo',lst]
lst
===Example with recursive dict===
>>> d = {'a':'foo'}
>>> d['b'] = d
>>> pyon.dumps(d, fast=False)
_p__0={'a':'foo', 'b':_p__0}
_p__0
>>> pyon.dumps(d, fast=False, d=d)
d={'a':'foo', 'b':d}
d
===Example with recursion in class instance==
class C(object):
def __reduce__(self):
return C, (), self.__dict__
>>> c= C()
>>> c.parent = c
>>> pyon.dumps(c, fast=False)
_p__0=C(parent=_p__0)
_p__0
>>> pyon.dumps(c, fast=False, c=c)
c=C(parent=c)
c
===Example with cross-refernce===
class C(object):
def __reduce__(self):
return C, (), self.__dict__
>>> lst = ['foo']
>>> lst.append(lst)
>>> d = {'a':'bar','b':lst}
>>> d['c'] = d
>>> c = C()
>>> c.lst = lst
>>> c.d = d
>>> c.parent = c
>>> d['d'] = c
>>> pyon.dumps([lst,d,c], fast = False, lst=lst, d=d)
lst=['foo',lst]
_p__1=C(lst=lst,d=d,parent=_p__1)
d={'a':'bar','c':d,'b':lst,'d':_p__1}
[lst,d,_p__1]
Best regards,
Zaur