1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  """Special module for checking types.""" 
 24   
 25   
 26  from numpy import complex64, complex128, float32, float64, int16, int32 
 27  try: 
 28      from numpy import complex256 
 29  except ImportError: 
 30      complex256 = complex128     
 31  try: 
 32      from numpy import float16 
 33  except ImportError: 
 34      float16 = float32     
 35  try: 
 36      from numpy import float128 
 37  except ImportError: 
 38      float128 = float64     
 39  try: 
 40      from numpy import int8 
 41  except ImportError: 
 42      int8 = int16     
 43  try: 
 44      from numpy import int64 
 45  except ImportError: 
 46      int64 = int32     
 47   
 48   
 49   
 50  from lib.compat import IOBase, unicode 
 51   
 52   
 54      """Check if the given number is a Python or numpy complex. 
 55   
 56      @param num: The number to check. 
 57      @type num:  anything. 
 58      @return:    True if the number is a complex, False otherwise. 
 59      @rtype:     bool 
 60      """ 
 61   
 62       
 63      if isinstance(num, complex): 
 64          return True 
 65   
 66       
 67      if isinstance(num, complex64): 
 68          return True 
 69      if isinstance(num, complex128): 
 70          return True 
 71      if isinstance(num, complex256): 
 72          return True 
 73   
 74       
 75      return False 
  76   
 77   
 79      """Check if the given Python object is a file. 
 80   
 81      @param obj:     The Python object. 
 82      @type obj:      anything 
 83      @return:        True if the object is a file, False otherwise. 
 84      @rtype:         bool 
 85      """ 
 86   
 87       
 88      if IOBase != None: 
 89          return isinstance(obj, IOBase) 
 90   
 91       
 92      else: 
 93          return isinstance(obj, file) 
  94   
 95   
 97      """Check if the given number is a Python or numpy float. 
 98   
 99      @param num: The number to check. 
100      @type num:  anything. 
101      @return:    True if the number is a float, False otherwise. 
102      @rtype:     bool 
103      """ 
104   
105       
106      if isinstance(num, float): 
107          return True 
108   
109       
110      if isinstance(num, float16): 
111          return True 
112      if isinstance(num, float32): 
113          return True 
114      if isinstance(num, float64): 
115          return True 
116      if isinstance(num, float128): 
117          return True 
118   
119       
120      return False 
 121   
122   
124      """Check if the given number is a Python or numpy int. 
125   
126      @param num: The number to check. 
127      @type num:  anything. 
128      @return:    True if the number is a int, False otherwise. 
129      @rtype:     bool 
130      """ 
131   
132       
133      if isinstance(num, int): 
134          return True 
135   
136       
137      if isinstance(num, int8): 
138          return True 
139      if isinstance(num, int16): 
140          return True 
141      if isinstance(num, int32): 
142          return True 
143      if isinstance(num, int64): 
144          return True 
145   
146       
147      return False 
 148   
149   
151      """Check if the given value is a Python list. 
152   
153      @param val: The value to check. 
154      @type val:  anything. 
155      @return:    True if the value is a list, False otherwise. 
156      @rtype:     bool 
157      """ 
158   
159       
160      if not isinstance(val, list): 
161          return False 
162   
163       
164      return True 
 165   
166   
168      """Check if the given value is a Python list of lists. 
169   
170      @param val: The value to check. 
171      @type val:  anything. 
172      @return:    True if the value is a list of lists, False otherwise. 
173      @rtype:     bool 
174      """ 
175   
176       
177      if not isinstance(val, list): 
178          return False 
179   
180       
181      if not isinstance(val[0], list): 
182          return False 
183   
184       
185      return True 
 186   
187   
189      """Check if the given number is a Python or numpy int or float. 
190   
191      @param num: The number to check. 
192      @type num:  anything. 
193      @return:    True if the number is an int or float, False otherwise. 
194      @rtype:     bool 
195      """ 
196   
197       
198      if is_float(num): 
199          return True 
200   
201       
202      if is_int(num): 
203          return True 
204   
205       
206      return False 
 207   
208   
210      """Check if the given Python object is a unicode string. 
211   
212      @param obj:     The Python object. 
213      @type obj:      anything 
214      @return:        True if the object is a unicode string, False otherwise. 
215      @rtype:         bool 
216      """ 
217   
218       
219      return isinstance(obj, unicode) 
 220