annotate 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
rev   line source
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
1
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
2 class SemiProduct:
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
3
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
4 last_work = None
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
5 source = None
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
6 content = None
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
7
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
8 def __init__(self, **kwds):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
9 self.source = kwds.get('source','')
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
10
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
11 def __str__(self):
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
12 return self.content
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
13
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
14 class Resource(object):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
15
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
16 datas = {}
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
17
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
18 data_patterns = {}
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
19
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
20 def __init__(self, **kwds):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
21 self.datas = kwds.get('datas')
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
22
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
23 def __get__(self, key):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
24 try:
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
25 return self.datas[key]
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
26 except KeyError:
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
27 return self.key
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
28
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
29 def __set__(self, key, value):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
30 try:
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
31 self.datas[key]
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
32 except KeyError:
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
33 self.key = value
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
34
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
35 def sync(self):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
36 if not self.data_patterns: raise AttributeError("data patterns not defined.")
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
37
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
38 express = {}
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
39 for attr in self.attr_xpath.keys():
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
40 express[attr] = self.root_xpath+self.attr_xpath[attr]
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
41
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
42 def fn(e):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
43 for x in e: e[x] = e[x][0]
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
44 return e
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
45
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
46 self.datas = self.core.open(self.param).findall(express).process(fn).get_content()