diff ikweb/tools/lazy/www/work/find.py @ 247:7747bbe5b68e

start to develope Information Exchange Center of Ikariam Game. (prototpye)
author "Hisn Yi, Chen <ossug.hychen@gmail.com>"
date Mon, 01 Dec 2008 00:27:22 +0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ikweb/tools/lazy/www/work/find.py	Mon Dec 01 00:27:22 2008 +0800
@@ -0,0 +1,27 @@
+from lxml import etree
+from cStringIO import StringIO
+
+class Finder:
+
+    dom_tree = None
+    xpath = None
+
+    def __init__(self, working_product):
+        self.working_prodcut = working_product
+
+        self.encoding = 'utf8'
+    
+    def find(self, express , callback = None):
+        
+        if self.dom_tree is None:   self.set_dom_tree(self.working_prodcut.content)
+ 
+        xpath = self.dom_tree.xpath(express)
+        
+        if callback:    return self.callback(xpath)
+        return xpath
+
+    def set_dom_tree(self, content):
+        stream = StringIO(content)
+
+        parser = etree.XMLParser(encoding=self.encoding)
+        self.dom_tree = etree.parse(stream, parser)
\ No newline at end of file