PageRenderTime 63ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/DICK.B1/IronPython/Lib/iptest/type_util.py

https://bitbucket.org/williamybs/uidipythontool
Python | 87 lines | 51 code | 17 blank | 19 comment | 14 complexity | fc0159f6bfb5583292340ab13d44e8a5 MD5 | raw file
  1. #####################################################################################
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # This source code is subject to terms and conditions of the Microsoft Public License. A
  6. # copy of the license can be found in the License.html file at the root of this distribution. If
  7. # you cannot locate the Microsoft Public License, please send an email to
  8. # ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. # by the terms of the Microsoft Public License.
  10. #
  11. # You must not remove this notice, or any other, from this software.
  12. #
  13. #
  14. #####################################################################################
  15. # types derived from built-in types
  16. class myint(int): pass
  17. class mylong(long): pass
  18. class myfloat(float): pass
  19. class mycomplex(complex): pass
  20. class mystr(str): pass
  21. class mytuple(tuple): pass
  22. class mylist(list): pass
  23. class mydict(dict): pass
  24. class myset(set): pass
  25. class myfrozenset(frozenset): pass
  26. import sys
  27. if not sys.platform == 'silverlight':
  28. class myfile(file): pass
  29. # to define type constant
  30. def _func(): pass
  31. class _class:
  32. def method(self): pass
  33. class types:
  34. functionType = type(_func)
  35. instancemethodType = type(_class().method)
  36. classType = type(_class)
  37. lambdaType = type(lambda : 1)
  38. if sys.platform in ['cli', 'silverlight']:
  39. object_attrs_before_clr_import = dir(object())
  40. import System
  41. object_attrs_after_clr_import = dir(object())
  42. clr_specific_attrs = [attr for attr in object_attrs_after_clr_import
  43. if attr not in object_attrs_before_clr_import]
  44. def remove_clr_specific_attrs(attr_list):
  45. return [attr for attr in attr_list if attr not in clr_specific_attrs]
  46. # CLR array shortcut
  47. array_cli = System.Array
  48. array_int = System.Array[int]
  49. array_long = System.Array[long]
  50. array_object = System.Array[object]
  51. array_byte = System.Array[System.Byte]
  52. # sample numberes?
  53. clr_signed_types = (System.SByte, System.Int16, System.Int32, System.Int64, System.Decimal, System.Single, System.Double)
  54. clr_unsigned_types = (System.Byte, System.UInt16, System.UInt32, System.UInt64)
  55. clr_all_types = clr_signed_types + clr_unsigned_types
  56. clr_all_plus1 = [t.Parse("1") for t in clr_all_types]
  57. clr_all_minus1 = [t.Parse("-1") for t in clr_signed_types]
  58. clr_all_max = [t.MaxValue for t in clr_all_types]
  59. clr_all_min = [t.MinValue for t in clr_all_types]
  60. clr_numbers = {}
  61. for t in clr_all_types:
  62. clr_numbers[t.__name__ + "Max"] = t.MaxValue
  63. clr_numbers[t.__name__ + "Min"] = t.MinValue
  64. clr_numbers[t.__name__ + "PlusOne"] = t.Parse("1")
  65. if not t in clr_unsigned_types:
  66. clr_numbers[t.__name__ + "MinusOne"] = t.Parse("-1")
  67. if __name__ == '__main__':
  68. # for eye check
  69. for x in dir(types):
  70. print "%-25s : %r" % (x, getattr(types, x))