Package dlinklist :: Module linklist
[hide private]
[frames] | no frames]

Source Code for Module dlinklist.linklist

   1  # 
   2  # dlinklist/linklist.py 
   3  # 
   4  # ctypes wrappers for the Doubly Linked list API. 
   5  # 
   6  # $Author: cnobile $ 
   7  # $Date: 2012-01-15 05:40:52 $ 
   8  # $Revision: 1.11 $ 
   9  # 
  10   
  11  import logging, os 
  12  from ctypes import CDLL, CFUNCTYPE, POINTER, Structure, byref, cast, \ 
  13       string_at, c_void_p, c_int, c_ulong, c_bool, c_size_t, c_char_p 
  14   
  15   
  16  import dlinklist as dll 
17 18 19 -class Return(object):
20 """ 21 Many methods in the API return a status value, this class provides an 22 enumeration of the status valid return values. 23 """ 24 NORMAL = 0 # normal operation 25 MEM_ERROR = 1 # malloc error 26 ZERO_INFO = 2 # sizeof(Info) is zero 27 NULL_LIST = 3 # List is NULL 28 NOT_FOUND = 4 # Record not found 29 OPEN_ERROR = 5 # Cannot open file 30 WRITE_ERROR = 6 # File write error 31 READ_ERROR = 7 # File read error 32 NOT_MODIFIED = 8 # Unmodified list 33 NULL_FUNCTION = 9 # NULL function pointer 34 CONTINUE = 10 # Continue process--internal use only 35 _ERRORS = None 36 __MESSAGES = { 37 0: "Normal operation", 38 1: "malloc error", 39 2: "sizeof(Info) is zero", 40 3: "List is NULL", 41 4: "Record not found", 42 5: "Cannot open file", 43 6: "File write error", 44 7: "File read error", 45 8: "Unmodified list", 46 9: "NULL function pointer", 47 10: "Continue process--internal use only", 48 } 49 50 @classmethod
51 - def getMessage(self, num):
52 """ 53 Return a tuple consisting of the text name of the status return value 54 and the description of the status. If the return value is invalid the 55 number of the value is returned and the phrase 'Unknown error'. 56 57 @param num: The numeric value from the C{Return} class. 58 @type num: C{int} 59 @return: A tuple consisting of the text C{Return} value and the 60 description. 61 @rtype: C{(str} or C{int, str)} 62 """ 63 return (self._ERRORS.get(num, num), 64 self.__MESSAGES.get(num, "Unknown error"))
65 66 Return._ERRORS = dict([(v,k) for k,v in Return.__dict__.items() 67 if not k.startswith("_")])
68 69 70 -class SrchOrigin(object):
71 """ 72 Provides an enumeration of the search origin values. 73 """ 74 ORIGIN_DEFAULT = 0 # Use current origin setting 75 HEAD = 1 # Set origin to head pointer 76 CURRENT = 2 # Set origin to current pointer 77 TAIL = 3 # Set origin to tail pointer 78 _ORIGINS = None 79 __MESSAGES = { 80 0: "Use current origin setting", 81 1: "Set origin to head pointer", 82 2: "Set origin to current pointer", 83 3: "Set origin to tail pointer", 84 } 85 86 @classmethod
87 - def getMessage(self, num):
88 """ 89 Return a tuple consisting of the text name of the search origin value 90 and the description of the status. If the search origin value is 91 invalid the number of the value is returned and the phrase 92 'Unknown error'. 93 94 @param num: The numeric value from the C{SrchOrigin} class. 95 @type num: C{int} 96 @return: A tuple consisting of the text C{SrchOrigin} value and the 97 description. 98 @rtype: C{(str} or C{int, str)} 99 """ 100 return (self._ORIGINS.get(num, num), 101 self.__MESSAGES.get(num, "Unknown search origin"))
102 103 SrchOrigin._ORIGINS = dict([(v,k) for k,v in SrchOrigin.__dict__.items() 104 if not k.startswith("_")])
105 106 107 -class SrchDir(object):
108 """ 109 Provides an enumeration of the search direction values. 110 """ 111 DIRECTION_DEFAULT = 0 # Use current direction setting 112 DOWN = 1 # Set direction to down 113 UP = 2 # Set direction to up 114 _DIRS = None 115 __MESSAGES = { 116 0: "Use current direction setting", 117 1: "Set direction to down", 118 2: "Set direction to up", 119 } 120 121 @classmethod
122 - def getMessage(self, num):
123 """ 124 Return a tuple consisting of the text name of the search direction value 125 and the description of the status. If the search direction value is 126 invalid the number of the value is returned and the phrase 127 'Unknown error'. 128 129 @param num: The numeric value from the C{SrchDir} class. 130 @type num: C{int} 131 @return: A tuple consisting of the text C{SrchDir} value and the 132 description. 133 @rtype: C{(str} or C{int, str)} 134 """ 135 return (self._DIRS.get(num, num), 136 self.__MESSAGES.get(num, "Unknown search direction"))
137 138 SrchDir._DIRS = dict([(v,k) for k,v in SrchDir.__dict__.items() 139 if not k.startswith("_")])
140 141 142 -class InsertDir(object):
143 """ 144 Provides an enumeration of the insert direction values. 145 """ 146 INSERT_DEFAULT = 0 # Use current insert setting 147 ABOVE = 1 # Insert new record ABOVE current record 148 BELOW = 2 # Insert new record BELOW current record 149 _DIRS = None 150 __MESSAGES = { 151 0: "Use current insert setting", 152 1: "Insert new record ABOVE current record", 153 2: "Insert new record BELOW current record", 154 } 155 156 @classmethod
157 - def getMessage(self, num):
158 """ 159 Return a tuple consisting of the text name of the insert direction value 160 and the description of the status. If the insert direction value is 161 invalid the number of the value is returned and the phrase 162 'Unknown error'. 163 164 @param num: The numeric value from the C{InsertDir} class. 165 @type num: C{int} 166 @return: A tuple consisting of the text C{InsertDir} value and the 167 description. 168 @rtype: C{(str} or C{int, str)} 169 """ 170 return (self._DIRS.get(num, num), 171 self.__MESSAGES.get(num, "Unknown search direction"))
172 173 InsertDir._DIRS = dict([(v,k) for k,v in InsertDir.__dict__.items() 174 if not k.startswith("_")])
175 176 177 -class Node(Structure):
178 """ 179 This class holds the link list pointers and the Info structure pointer. 180 """ 181 _fields_ = [ 182 ('info', c_void_p), 183 ]
184 Node._fields_.append(('next', POINTER(Node))) 185 Node._fields_.append(('prior', POINTER(Node)))
186 187 188 -class List(Structure):
189 """ 190 This is the top level control structure which keeps track of the Node 191 structure pointers and various variables used in the API. 192 """ 193 _fields_ = ( 194 ('head', POINTER(Node)), 195 ('tail', POINTER(Node)), 196 ('current', POINTER(Node)), 197 ('saved', POINTER(Node)), 198 ('infosize', c_int), 199 ('listsize', c_ulong), 200 ('current_index', c_ulong), 201 ('save_index', c_ulong), 202 ('modified', c_bool), 203 ('search_origin', c_int), 204 ('search_dir', c_int), 205 )
206
207 208 -class Info(Structure):
209 _fields_ = []
210
211 212 -class SearchModes(Structure):
213 """ 214 This class is returned by the getSearchModes() method and contains the 215 current search origin and direction modes from the Controller List class. 216 """ 217 _fields_ = ( 218 ('search_origin', c_int), 219 ('search_dir', c_int), 220 )
221 1368