Files
deb-python-sqlalchemy-utils/sqlalchemy_utils/utils.py
Konsta Vesterinen e6ec12ae71 Add support for constraints, refs #161
Add support for foreign key constraints in has_index and has_unique_index. Remove has_indexed_foreign_key function (superceded now by more versatile has_index function).
2015-09-17 14:20:06 +03:00

30 lines
639 B
Python

import sys
from collections import Iterable
import six
def str_coercible(cls):
if sys.version_info[0] >= 3: # Python 3
def __str__(self):
return self.__unicode__()
else: # Python 2
def __str__(self):
return self.__unicode__().encode('utf8')
cls.__str__ = __str__
return cls
def is_sequence(value):
return (
isinstance(value, Iterable) and not isinstance(value, six.string_types)
)
def starts_with(iterable, prefix):
"""
Returns whether or not given iterable starts with given prefix.
"""
return list(iterable)[0:len(prefix)] == list(prefix)