view 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 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()