Package testpackage :: Module util
[hide private]
[frames] | no frames]

Source Code for Module testpackage.util

 1  """ 
 2  Provides general-purpose utilities. 
 3   
 4  @sort: FirstClass, _SecondClass, method2, methodOne, CONSTANT_ONE, CONSTANT_TWO 
 5   
 6  @var CONSTANT_ONE: The first constant 
 7  @var CONSTANT_TWO: The second constant 
 8   
 9  @author: Kenneth J. Pronovici <pronovic@ieee.org> 
10  """ 
11   
12  CONSTANT_ONE       = "one" 
13  CONSTANT_TWO       = "two" 
14   
15 -class FirstClass(list):
16 17 """ 18 Special list class. 19 20 This is a special class that extends list. 21 22 It has some special behavior that users will find really interesting. 23 Or, it would if I had remembered to implement that. 24 """ 25
26 - def __eq__(self, other):
27 """ 28 Definition of C{==} operator for this class. 29 @param other: Other object to compare to. 30 @return: True/false depending on whether C{other is None} 31 """ 32 if other is None: 33 return False 34 else: 35 return True
36
37 -class _SecondClass(object):
38 39 """ 40 Represents something else that I forgot just now. 41 """ 42
43 - def __init__(self, name):
44 """ 45 Constructor. 46 @param name: Name of this instance 47 """ 48 self.name = name 49 self.state = None
50
51 -def methodOne(d):
52 """ 53 Returns the keys of the dictionary sorted by value. 54 55 There are cuter ways to do this in Python 2.4, but we were originally 56 attempting to stay compatible with Python 2.3. 57 58 @param d: Dictionary to operate on 59 @return: List of dictionary keys sorted in order by dictionary value. 60 """ 61 items = d.items() 62 items.sort(lambda x, y: cmp(x[1], y[1])) 63 return [key for key, value in items]
64
65 -def method2(d, keys):
66 """ 67 Removes all of the keys from the dictionary. 68 The dictionary is altered in-place. 69 Each key must exist in the dictionary. 70 @param d: Dictionary to operate on 71 @param keys: List of keys to remove 72 @raise KeyError: If one of the keys does not exist 73 """ 74 for key in keys: 75 del d[key]
76