comparison 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
comparison
equal deleted inserted replaced
244:fd6c3660cd38 246:60c4b4b78a01
8 def __init__(self, **kwds): 8 def __init__(self, **kwds):
9 self.source = kwds.get('source','') 9 self.source = kwds.get('source','')
10 10
11 def __str__(self): 11 def __str__(self):
12 return self.content 12 return self.content
13
14 class Resource(object):
15
16 datas = {}
17
18 data_patterns = {}
19
20 def __init__(self, **kwds):
21 self.datas = kwds.get('datas')
22
23 def __get__(self, key):
24 try:
25 return self.datas[key]
26 except KeyError:
27 return self.key
28
29 def __set__(self, key, value):
30 try:
31 self.datas[key]
32 except KeyError:
33 self.key = value
34
35 def sync(self):
36 if not self.data_patterns: raise AttributeError("data patterns not defined.")
37
38 express = {}
39 for attr in self.attr_xpath.keys():
40 express[attr] = self.root_xpath+self.attr_xpath[attr]
41
42 def fn(e):
43 for x in e: e[x] = e[x][0]
44 return e
45
46 self.datas = self.core.open(self.param).findall(express).process(fn).get_content()