Ñò +z2Wc@sÀdZddkZddklZlZd„Zed„ƒZed„ƒZdefd „ƒYZd efd „ƒYZ d e fd „ƒYZ dee fd„ƒYZ e Z eZeZdS(s"Basic classes with predefined properties Example usage: class Article(Gdtstruct): "A basic Article class" # fields and types are dynamically set by the initializer gdtstruct_properties([('title', Gdtstr, "The Title of the Article"), ('page', Gdtlist, "List of pages in the Article") ]) def __init__(self, *args): super(Article, self).__init__(*args) self.title = Gdtstr("") self.page = Gdtlist() class Page(Gdtstruct): # fields and types are dynamically set by the initializer gdtstruct_properties([('text', Gdtstr, "The text of the page"), ]) def __init__(self, *args): super(Page, self).__init__(*args) self.text = Gdtstr(args[0] if len(args) else "") a = Article() print Article.title.__doc__ print a.title = "My title" a.page.append(Page("page 1")) a.page.append(Page("page 2")) a.commit() print a print a.title = "My bad title" a.page[1].text = "bad page 2" a.page.append(Page("bad page 3")) print a print a.page.rollback() print a print a.rollback() print a Output of the example: The Title of the Article Article.title=My title Article.page.1.Page.text=page 1 Article.page.2.Page.text=page 2 Article.title=My bad title Article.page.1.Page.text=page 1 Article.page.2.Page.text=bad page 2 Article.page.3.Page.text=bad page 3 Article.title=My bad title Article.page.1.Page.text=page 1 Article.page.2.Page.text=page 2 Article.title=My title Article.page.1.Page.text=page 1 Article.page.2.Page.text=page 2 iÿÿÿÿNi(t TransactiontTransactionlistcsC‡fd†}ˆi|_ˆi|_ˆi|_ˆi|_|S(s6basic idea stolen from zope.interface.advice, P.J. Ebycs‰tidƒ}d|ijoYd|iijoFd|ijotdƒ‚n‡‡‡fd†}||id|iD]3}t||ƒot||t||ƒƒq q WdS(scopy from another objectN(R-RR$R (R!R>RA((s2/usr/share/system-config-network/netconfpkg/gdt.pyR#s N( RRRtsetR-tdictR/R;RR8RLR#(((s2/usr/share/system-config-network/netconfpkg/gdt.pyR?Ós     tGdtlistcBs;eZdZdZdd„Zd„Zd„Zd„ZRS(s7A list base class, which can hold Gdtobjects in a list.cCs¿|djo|ii}nd}d}x|D]‡}|d7}t|tƒoP|i}|ot||ƒ}n t|ƒ}||id||fƒ7}q0|d|||f7}q0W|S(s&returns a string in gdt representationRDiis%s.%ss %s.%d=%s N( RRERRHR5R<R RR8(R!R7RItiR%tkid((s2/usr/share/system-config-network/netconfpkg/gdt.pyR8s      cCsÑ|d|iijo |d=nt|dƒ}|t|ƒjo;x8td|t|ƒƒD]}|i|iƒƒq_Wn||d}t|tƒo|i|d|ƒn|i|ƒ||dTs  4 G@