source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/util.py @ 1938

Last change on this file since 1938 was 1910, checked in by mylan, 14 years ago

#160: clarify code, some clean-up

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1from AccessControl import ClassSecurityInfo
2
3try:
4    from App.class_init import InitializeClass
5except ImportError:
6    from Globals import InitializeClass
7
8
9class SortedDict(dict):
10    """ A sorted dictionary.
11    """
12    security = ClassSecurityInfo()
13
14    security.declarePublic('items')
15    def items(self):
16        primary_metatags = self.pmt
17        lst = [(name,self[name]) for name in primary_metatags                    \
18                                                 if name in self.keys()] +       \
19              [(name, self[name]) for name in self.keys()                        \
20                                                 if name not in primary_metatags]
21        return lst
22
23
24    security.declarePublic('__init__')
25    def __init__(self, *args, **kwargs):
26        super(SortedDict,self).__init__(*args, **kwargs)
27        self.pmt = []
28
29
30    security.declarePublic('__setitem__')
31    def __setitem__(self, i, y):
32        super(SortedDict,self).__setitem__(i, y)
33        if i not in self.pmt:
34            self.pmt.append(i)
35
36    security.declarePublic('pop')
37    def pop(self, k, *args, **kwargs):
38        super(SortedDict,self).pop(k, *args, **kwargs)
39        if k in self.pmt:
40            self.pmt.remove(k)
41
42try:
43    InitializeClass(SortedDict)
44except:
45    pass
Note: See TracBrowser for help on using the repository browser.