Package httxlib :: Module httxcompressionset
[hide private]
[frames] | no frames]

Source Code for Module httxlib.httxcompressionset

  1  #!/usr/bin/env python 
  2  # -*- coding: latin-1; py-indent-offset:4 -*- 
  3  ################################################################################ 
  4  #  
  5  # This file is part of HttxLib 
  6  # 
  7  # HttxLib is an HTTP(s) Python library suited multithreaded/multidomain 
  8  # applications 
  9  # 
 10  # Copyright (C) 2010-2011 Daniel Rodriguez (aka Daniel Rodriksson) 
 11  # Copyright (C) 2011 Sensible Odds Ltd 
 12  # 
 13  # You can learn more and contact the author at: 
 14  # 
 15  #    http://code.google.com/p/httxlib/ 
 16  # 
 17  # HttxLib is free software: you can redistribute it and/or modify 
 18  # it under the terms of the GNU General Public License as published by 
 19  # the Free Software Foundation, either version 3 of the License, or 
 20  # (at your option) any later version. 
 21  # 
 22  # HttxLib is distributed in the hope that it will be useful, 
 23  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 24  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 25  # GNU General Public License for more details. 
 26  # 
 27  # You should have received a copy of the GNU General Public License 
 28  # along with HttxLib. If not, see <http://www.gnu.org/licenses/>. 
 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   
40 -class HttxCompressionSet(HttxObject):
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
48 - def __init__(self, *args):
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
60 - def __deepcopy__(self, memo):
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
75 - def __str__(self):
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
96 - def remove(self, elem):
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
109 - def discard(self, elem):
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
122 - def clear(self):
123 ''' 124 Clear the set 125 ''' 126 with self.lock: 127 self.compressionset.clear()
128 129
130 - def update(self, other):
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