view pyikriam/lazy/www/core/__init__.py @ 306:2f36120aba83

merged
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 10 Dec 2008 00:42:31 +0800
parents 60c4b4b78a01
children
line wrap: on
line source

                          
class SemiProduct:

    last_work = None
    source = None
    content = None
    
    def __init__(self, **kwds):
        self.source = kwds.get('source','')        
        
    def __str__(self):        
        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()