1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 '''
32 HttxLib Set with locking semanctics to store the allowed compression values
33 '''
34
35 from copy import deepcopy
36
37 from httxobject import HttxObject
38
39
41 '''
42 HttxLib Set with locking semanctics to store the allowed compression values
43
44 @ivar compressionset: holds the unique values
45 @type cache: set
46 '''
47
49 '''
50 Constructor. It delegates construction to the base class
51 L{HttxObject} and initializes the member variables
52
53 @param args: iterable of allowed compression values
54 @type args: list|tuple
55 '''
56 HttxObject.__init__(self)
57 self.compressionset = set(args)
58
59
61 '''
62 Deepcopy support.
63
64 @param memo: standard __deepcopy__ parameter to avoid circular references
65 @type memo: dict
66 @return: a cloned object
67 @rtype: L{HttxCompressionSet}
68 '''
69 clone = self.__class__()
70 with self.lock:
71 clone.compressionset = deepcopy(self.compressionset)
72 return clone
73
74
76 '''
77 Conversion to string
78
79 @return: a string containing the allowed compression types
80 @rtype: str
81 '''
82 return str(self.compressionset)
83
84
85 - def add(self, elem):
86 '''
87 Add a compression type to the set
88
89 @param elem: a compression type (like gzip)
90 @type elem: str
91 '''
92 with self.lock:
93 self.compressionset.add(elem)
94
95
97 '''
98 Remove a compression type from the set.
99
100 It mimics remove from Python set
101
102 @param elem: a compression type (like gzip)
103 @type elem: str
104 '''
105 with self.lock:
106 self.compressionset.remove(elem)
107
108
110 '''
111 Discard a compression type from the set
112
113 It mimics discard from Python set
114
115 @param elem: a compression type (like gzip)
116 @type elem: str
117 '''
118 with self.lock:
119 self.compressionset.discard(elem)
120
121
123 '''
124 Clear the set
125 '''
126 with self.lock:
127 self.compressionset.clear()
128
129
131 '''
132 Update the set with another set
133
134 @param other: another set to use in the update
135 @type other: set
136 '''
137 with self.lock:
138 self.compressionset.update(other)
139
140
141 - def join(self, sep = ', '):
142 '''
143 Utility function to return the values in the set as a string
144 separated by sep
145
146 @param sep: separator in the returned string
147 @type sep: str
148 @return: string composed of the set elements separated by sep
149 @rtype: str
150 '''
151 with self.lock:
152 return sep.join(self.compressionset)
153