Module check_types
[hide private]
[frames] | no frames]

Source Code for Module check_types

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2012 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Special module for checking types.""" 
24   
25  # Python module imports. 
26  io_module = True 
27  try: 
28      from io import IOBase    # Python 2.5+ import. 
29      file = None 
30  except ImportError: 
31      io_module = False 
32   
33   
34 -def is_filetype(obj):
35 """Check if the given Python object is a file. 36 37 @param obj: The Python object. 38 @type obj: anything 39 @return: True if the object is a file, False otherwise. 40 @rtype: bool 41 """ 42 43 # New style check. 44 if io_module: 45 return isinstance(obj, IOBase) 46 47 # Old style check. 48 else: 49 return isinstance(obj, file)
50 51
52 -def is_unicode(obj):
53 """Check if the given Python object is a unicode string. 54 55 @param obj: The Python object. 56 @type obj: anything 57 @return: True if the object is a unicode string, False otherwise. 58 @rtype: bool 59 """ 60 61 # Check using the unicode type (set in the compat module for Python 3). 62 return isinstance(obj, unicode)
63