utilClass.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. """
  3. -------------------------------------------------
  4. File Name: utilClass.py
  5. Description : tool class
  6. Author : JHao
  7. date: 2016/12/3
  8. -------------------------------------------------
  9. Change Activity:
  10. 2016/12/3: Class LazyProperty
  11. -------------------------------------------------
  12. """
  13. __author__ = 'JHao'
  14. class LazyProperty(object):
  15. """
  16. LazyProperty
  17. explain: http://www.spiderpy.cn/blog/5/
  18. """
  19. def __init__(self, func):
  20. self.func = func
  21. def __get__(self, instance, owner):
  22. if instance is None:
  23. return self
  24. else:
  25. value = self.func(instance)
  26. setattr(instance, self.func.__name__, value)
  27. return value
  28. from ConfigParser import ConfigParser
  29. class ConfigParse(ConfigParser):
  30. """
  31. rewrite ConfigParser, for support upper option
  32. """
  33. def __init__(self):
  34. ConfigParser.__init__(self)
  35. def optionxform(self, optionstr):
  36. return optionstr