home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / TYPES.PY < prev    next >
Encoding:
Python Source  |  2001-12-02  |  2.0 KB  |  87 lines

  1. """Define names for all type symbols known in the standard interpreter.
  2.  
  3. Types that are part of optional modules (e.g. array) are not listed.
  4. """
  5. from __future__ import generators
  6.  
  7. import sys
  8.  
  9. # Iterators in Python aren't a matter of type but of protocol.  A large
  10. # and changing number of builtin types implement *some* flavor of
  11. # iterator.  Don't check the type!  Use hasattr to check for both
  12. # "__iter__" and "next" attributes instead.
  13.  
  14. NoneType = type(None)
  15. TypeType = type
  16. ObjectType = object
  17.  
  18. IntType = int
  19. LongType = long
  20. FloatType = float
  21. try:
  22.     ComplexType = complex
  23. except NameError:
  24.     pass
  25.  
  26. StringType = str
  27. try:
  28.     UnicodeType = unicode
  29.     StringTypes = (StringType, UnicodeType)
  30. except NameError:
  31.     StringTypes = (StringType,)
  32.  
  33. BufferType = type(buffer(''))
  34.  
  35. TupleType = tuple
  36. ListType = list
  37. DictType = DictionaryType = dict
  38.  
  39. def _f(): pass
  40. FunctionType = type(_f)
  41. LambdaType = type(lambda: None)         # Same as FunctionType
  42. try:
  43.     CodeType = type(_f.func_code)
  44. except RuntimeError:
  45.     # Execution in restricted environment
  46.     pass
  47.  
  48. def g():
  49.     yield 1
  50. GeneratorType = type(g())
  51. del g
  52.  
  53. class _C:
  54.     def _m(self): pass
  55. ClassType = type(_C)
  56. UnboundMethodType = type(_C._m)         # Same as MethodType
  57. _x = _C()
  58. InstanceType = type(_x)
  59. MethodType = type(_x._m)
  60.  
  61. BuiltinFunctionType = type(len)
  62. BuiltinMethodType = type([].append)     # Same as BuiltinFunctionType
  63.  
  64. ModuleType = type(sys)
  65. FileType = file
  66. XRangeType = type(xrange(0))
  67.  
  68. try:
  69.     raise TypeError
  70. except TypeError:
  71.     try:
  72.         tb = sys.exc_info()[2]
  73.         TracebackType = type(tb)
  74.         FrameType = type(tb.tb_frame)
  75.     except AttributeError:
  76.         # In the restricted environment, exc_info returns (None, None,
  77.         # None) Then, tb.tb_frame gives an attribute error
  78.         pass
  79.     tb = None; del tb
  80.  
  81. SliceType = type(slice(0))
  82. EllipsisType = type(Ellipsis)
  83.  
  84. DictProxyType = type(TypeType.__dict__)
  85.  
  86. del sys, _f, _C, _x, generators                  # Not for export
  87.