diff --git a/sqlalchemy_utils/path.py b/sqlalchemy_utils/path.py index 7b8ad2b..5780e2a 100644 --- a/sqlalchemy_utils/path.py +++ b/sqlalchemy_utils/path.py @@ -1,6 +1,8 @@ from sqlalchemy.orm.attributes import InstrumentedAttribute +from .utils import str_coercible +@str_coercible class Path(object): def __init__(self, path, separator='.'): if isinstance(path, Path): @@ -34,6 +36,9 @@ class Path(object): def __ne__(self, other): return not (self == other) + def __unicode__(self): + return self.path + def get_attr(mixed, attr): if isinstance(mixed, InstrumentedAttribute): @@ -45,6 +50,7 @@ def get_attr(mixed, attr): return getattr(mixed, attr) +@str_coercible class AttrPath(object): def __init__(self, class_, path): self.class_ = class_ @@ -107,3 +113,6 @@ class AttrPath(object): def __ne__(self, other): return not (self == other) + + def __unicode__(self): + return str(self.path) diff --git a/sqlalchemy_utils/primitives/weekday.py b/sqlalchemy_utils/primitives/weekday.py index f4953e0..c57d1ee 100644 --- a/sqlalchemy_utils/primitives/weekday.py +++ b/sqlalchemy_utils/primitives/weekday.py @@ -5,7 +5,7 @@ except ImportError: # Python 2.6 port from total_ordering import total_ordering from sqlalchemy_utils import i18n -from .utils import str_coercible +from sqlalchemy_utils.utils import str_coercible @str_coercible diff --git a/sqlalchemy_utils/primitives/weekdays.py b/sqlalchemy_utils/primitives/weekdays.py index b8dffb7..715bc3d 100644 --- a/sqlalchemy_utils/primitives/weekdays.py +++ b/sqlalchemy_utils/primitives/weekdays.py @@ -1,6 +1,6 @@ import six -from .utils import str_coercible +from sqlalchemy_utils.utils import str_coercible from .weekday import WeekDay diff --git a/sqlalchemy_utils/primitives/utils.py b/sqlalchemy_utils/utils.py similarity index 100% rename from sqlalchemy_utils/primitives/utils.py rename to sqlalchemy_utils/utils.py diff --git a/tests/test_path.py b/tests/test_path.py index 660c032..cdccff3 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -133,6 +133,12 @@ class TestPath(object): assert path[0] == 's' assert path[1] == 's2' + def test_str(self): + assert str(Path('s.s2')) == 's.s2' + + def test_unicode(self): + assert unicode(Path('s.s2')) == u's.s2' + def test_getitem_with_slice(self): path = Path('s.s2.s3') assert path[1:] == Path('s2.s3')