File: utils.py

package info (click to toggle)
python-sqlalchemy-utils 0.42.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,236 kB
  • sloc: python: 13,002; makefile: 20
file content (20 lines) | stat: -rw-r--r-- 438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from collections.abc import Iterable


def str_coercible(cls):
    def __str__(self):
        return self.__unicode__()

    cls.__str__ = __str__
    return cls


def is_sequence(value):
    return isinstance(value, Iterable) and not isinstance(value, str)


def starts_with(iterable, prefix):
    """
    Returns whether or not given iterable starts with given prefix.
    """
    return list(iterable)[0 : len(prefix)] == list(prefix)