util.py 754 B

12345678910111213141516171819202122232425
  1. """Private utility methods used by the subset modules"""
  2. def _add_method(*clazzes):
  3. """Returns a decorator function that adds a new method to one or
  4. more classes."""
  5. def wrapper(method):
  6. done = []
  7. for clazz in clazzes:
  8. if clazz in done:
  9. continue # Support multiple names of a clazz
  10. done.append(clazz)
  11. assert clazz.__name__ != "DefaultTable", "Oops, table class not found."
  12. assert not hasattr(
  13. clazz, method.__name__
  14. ), "Oops, class '%s' has method '%s'." % (clazz.__name__, method.__name__)
  15. setattr(clazz, method.__name__, method)
  16. return None
  17. return wrapper
  18. def _uniq_sort(l):
  19. return sorted(set(l))