1 | from AccessControl import ClassSecurityInfo |
---|
2 | |
---|
3 | try: |
---|
4 | from App.class_init import InitializeClass |
---|
5 | except ImportError: |
---|
6 | from Globals import InitializeClass |
---|
7 | |
---|
8 | |
---|
9 | class 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 | |
---|
42 | try: |
---|
43 | InitializeClass(SortedDict) |
---|
44 | except: |
---|
45 | pass |
---|