Show
Ignore:
Timestamp:
04/21/08 00:58:47 (7 months ago)
Author:
asterix
Message:

new XEP-0115 implementation (version 1.5)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/logger.py

    r9481 r9508  
    699699                #tmp, self.con.text_factory = self.con.text_factory, str 
    700700                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;'); 
    702702                except sqlite.OperationalError: 
    703703                        # might happen when there's no caps_cache table yet 
     
    706706                        return 
    707707                #self.con.text_factory = tmp 
    708  
    709                 for node, ver, ext, data in self.cur: 
     708                for hash_method, hash, data in self.cur: 
    710709                        # for each row: unpack the data field 
    711710                        # (format: (category, type, name, category, type, name, ... 
    712711                        #   ..., 'FEAT', feature1, feature2, ...).join(' ')) 
    713712                        # 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') 
    715714                        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 
    724725                        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 
    729729 
    730730                        # yield the row 
    731                         yield node, ver, ext, identities, features 
    732  
    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): 
    734734                data=[] 
    735735                for identity in identities: 
    736736                        # 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', ''))) 
    742741                data.append('FEAT') 
    743742                data.extend(features) 
     
    745744                # if there's a need to do more gzip, put that to a function 
    746745                string = StringIO() 
    747                 gzip=GzipFile(fileobj=string, mode='w') 
     746                gzip = GzipFile(fileobj=string, mode='w') 
    748747                gzip.write(data) 
    749748                gzip.close() 
    750749                data = string.getvalue() 
    751750                self.cur.execute(''' 
    752                         INSERT INTO caps_cache ( node, ver, ext, data ) 
    753                         VALUES (?, ?, ?, ?); 
    754                         ''', (node, ver, ext, buffer(data))) # (1) -- note above 
     751                        INSERT INTO caps_cache ( hash_method, hash, data ) 
     752                        VALUES (?, ?, ?); 
     753                        ''', (hash_method, hash, buffer(data))) # (1) -- note above 
    755754                try: 
    756755                        self.con.commit()