utils.py 477 B

123456789101112131415161718192021222324
  1. from collections.abc import Iterable
  2. import six
  3. def str_coercible(cls):
  4. def __str__(self):
  5. return self.__unicode__()
  6. cls.__str__ = __str__
  7. return cls
  8. def is_sequence(value):
  9. return (
  10. isinstance(value, Iterable) and not isinstance(value, six.string_types)
  11. )
  12. def starts_with(iterable, prefix):
  13. """
  14. Returns whether or not given iterable starts with given prefix.
  15. """
  16. return list(iterable)[0:len(prefix)] == list(prefix)