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