diff pyikriam/lazy/www/core/__init__.py @ 246:60c4b4b78a01

code clean
author "Hisn Yi, Chen <ossug.hychen@gmail.com>"
date Mon, 01 Dec 2008 00:25:07 +0800
parents a4c364888197
children
line wrap: on
line diff
--- a/pyikriam/lazy/www/core/__init__.py	Fri Nov 14 02:05:48 2008 +0800
+++ b/pyikriam/lazy/www/core/__init__.py	Mon Dec 01 00:25:07 2008 +0800
@@ -9,4 +9,38 @@
         self.source = kwds.get('source','')        
         
     def __str__(self):        
-        return self.content
\ No newline at end of file
+        return self.content
+    
+class Resource(object):
+
+    datas = {}
+    
+    data_patterns = {}
+    
+    def __init__(self, **kwds):
+        self.datas = kwds.get('datas')
+        
+    def __get__(self, key):
+        try:
+            return self.datas[key]
+        except KeyError:
+            return self.key
+        
+    def __set__(self, key, value):
+        try:
+            self.datas[key]
+        except KeyError:
+            self.key = value
+            
+    def sync(self):
+        if not self.data_patterns:  raise AttributeError("data patterns not defined.")
+        
+        express = {}
+        for attr in self.attr_xpath.keys():
+            express[attr] = self.root_xpath+self.attr_xpath[attr]
+
+        def fn(e):
+            for x in e: e[x] = e[x][0]
+            return e
+
+        self.datas = self.core.open(self.param).findall(express).process(fn).get_content()        
\ No newline at end of file