Changeset 9508 for trunk/src/common/logger.py
- Timestamp:
- 04/21/08 00:58:47 (7 months ago)
- Files:
-
- 1 modified
-
trunk/src/common/logger.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/logger.py
r9481 r9508 699 699 #tmp, self.con.text_factory = self.con.text_factory, str 700 700 try: 701 self.cur.execute(' ''SELECT node, ver, ext, data FROM caps_cache;''');701 self.cur.execute('SELECT hash_method, hash, data FROM caps_cache;'); 702 702 except sqlite.OperationalError: 703 703 # might happen when there's no caps_cache table yet … … 706 706 return 707 707 #self.con.text_factory = tmp 708 709 for node, ver, ext, data in self.cur: 708 for hash_method, hash, data in self.cur: 710 709 # for each row: unpack the data field 711 710 # (format: (category, type, name, category, type, name, ... 712 711 # ..., 'FEAT', feature1, feature2, ...).join(' ')) 713 712 # NOTE: if there's a need to do more gzip, put that to a function 714 data =GzipFile(fileobj=StringIO(str(data))).read().split('\0')713 data = GzipFile(fileobj=StringIO(str(data))).read().split('\0') 715 714 i=0 716 identities=set() 717 features=set() 718 while i<(len(data)-2) and data[i]!='FEAT': 719 category=data[i] 720 type=data[i+1] 721 name=data[i+2] 722 identities.add((category,type,name)) 723 i+=3 715 identities = list() 716 features = list() 717 while i < (len(data) - 3) and data[i] != 'FEAT': 718 category = data[i] 719 type_ = data[i + 1] 720 lang = data[i + 2] 721 name = data[i + 3] 722 identities.append({'category': category, 'type': type_, 723 'xml:lang': lang, 'name': name}) 724 i += 4 724 725 i+=1 725 while i<len(data): 726 features.add(data[i]) 727 i+=1 728 if not ext: ext=None # to make '' a None 726 while i < len(data): 727 features.append(data[i]) 728 i += 1 729 729 730 730 # yield the row 731 yield node, ver, ext, identities, features732 733 def add_caps_entry(self, node, ver, ext, identities, features):731 yield hash_method, hash, identities, features 732 733 def add_caps_entry(self, hash_method, hash, identities, features): 734 734 data=[] 735 735 for identity in identities: 736 736 # there is no FEAT category 737 if identity[0]=='FEAT': return 738 if len(identity)<2 or not identity[2]: 739 data.extend((identity[0], identity[1], '')) 740 else: 741 data.extend(identity) 737 if identity['category'] == 'FEAT': 738 return 739 data.extend((identity.get('category'), identity.get('type', ''), 740 identity.get('xml:lang', ''), identity.get('name', ''))) 742 741 data.append('FEAT') 743 742 data.extend(features) … … 745 744 # if there's a need to do more gzip, put that to a function 746 745 string = StringIO() 747 gzip =GzipFile(fileobj=string, mode='w')746 gzip = GzipFile(fileobj=string, mode='w') 748 747 gzip.write(data) 749 748 gzip.close() 750 749 data = string.getvalue() 751 750 self.cur.execute(''' 752 INSERT INTO caps_cache ( node, ver, ext, data )753 VALUES (?, ?, ? , ?);754 ''', ( node, ver, ext, buffer(data))) # (1) -- note above751 INSERT INTO caps_cache ( hash_method, hash, data ) 752 VALUES (?, ?, ?); 753 ''', (hash_method, hash, buffer(data))) # (1) -- note above 755 754 try: 756 755 self.con.commit()
