62
|
1
|
|
2 class SemiProduct:
|
|
3
|
|
4 last_work = None
|
|
5 source = None
|
|
6 content = None
|
|
7
|
|
8 def __init__(self, **kwds):
|
|
9 self.source = kwds.get('source','')
|
|
10
|
|
11 def __str__(self):
|
246
|
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() |