robot
最新文章(10)
Mqskit 和其它相關工具
CPython 的 GC 二、三事
寫 Mecurial Extension 是件快樂的事!
Mozilla 台灣辨公室徵人啟事
關於 Apple 的兩項專利
core dump 之前的 frame
怎麼發出 beep 聲?
先承認你要找的是奴才吧!
程式碼要清的多乾淨?
FreeBSD 的 Thread-Local Storage 實作
首頁
新編
最新留言
Entries RSS
重要關鍵字(10)
coding (122)
Python (93)
FreeBSD (71)
WEB (61)
URL (48)
hardware (46)
javascript (36)
Linux (34)
blog (30)
C++ (16)
所有關鍵字
新增 URL
mez_xml template 的組合技
by thinker
2 Columns
關鍵字:
Python
WEB
coding
linkname:mez_xml http://heaven.branda.to/~thinker/GinGin_CGI.py/show_id_doc/259 產生的 template 不只能單獨使用,也可以將之組合在一起,形式一個較大的 template 。例如,有一個 template 叫 outter ,定義一個 tag 的 ezid 為 content 。另一個 template 為 inner ,我們可將 outter.content method,置換成 inner._root 。 _root 是每一個 mez_xml template 必有的 method ,代表 template 的 root node 。 組合的方式如下 {{{#!python outter_obj = outter(stdout) inner_obj = inner(stdout) del outter.content outter_obj.content = inner_obj._root }}} 第 3 行先將 outter class 的 content method 移除,若無這個步驟,會造成第 4 行錯誤。這是因為,每一個 template method 都被置換成 descriptor 了。不先移除 descriptor ,會造成 descriptor 的 __set__() 錯誤。第 4 行,將 outter instance (outter_obj) 的 content 屬性指定為 inner instance (inner_obj) 的 _root() method (bound)。如此一來,當 outter 產生輸出時,處理到 content 這個 node ,就會由 inner 接手處理。於是 outter 和 inner 組起出一個更大的 template 。 這個組合的技巧,其實我已經用很久了。但今日又花了點時間才試成功,主要是因為忘了執行第 3 行的動作。因此,特地留下此文做為記錄。
最後更新時間: 2007-11-23 01:11:29 CST |
引用
查詢:
COMMENTS: