Add str coercion to path classes
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
||||||
|
from .utils import str_coercible
|
||||||
|
|
||||||
|
|
||||||
|
@str_coercible
|
||||||
class Path(object):
|
class Path(object):
|
||||||
def __init__(self, path, separator='.'):
|
def __init__(self, path, separator='.'):
|
||||||
if isinstance(path, Path):
|
if isinstance(path, Path):
|
||||||
@@ -34,6 +36,9 @@ class Path(object):
|
|||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not (self == other)
|
return not (self == other)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.path
|
||||||
|
|
||||||
|
|
||||||
def get_attr(mixed, attr):
|
def get_attr(mixed, attr):
|
||||||
if isinstance(mixed, InstrumentedAttribute):
|
if isinstance(mixed, InstrumentedAttribute):
|
||||||
@@ -45,6 +50,7 @@ def get_attr(mixed, attr):
|
|||||||
return getattr(mixed, attr)
|
return getattr(mixed, attr)
|
||||||
|
|
||||||
|
|
||||||
|
@str_coercible
|
||||||
class AttrPath(object):
|
class AttrPath(object):
|
||||||
def __init__(self, class_, path):
|
def __init__(self, class_, path):
|
||||||
self.class_ = class_
|
self.class_ = class_
|
||||||
@@ -107,3 +113,6 @@ class AttrPath(object):
|
|||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not (self == other)
|
return not (self == other)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return str(self.path)
|
||||||
|
@@ -5,7 +5,7 @@ except ImportError:
|
|||||||
# Python 2.6 port
|
# Python 2.6 port
|
||||||
from total_ordering import total_ordering
|
from total_ordering import total_ordering
|
||||||
from sqlalchemy_utils import i18n
|
from sqlalchemy_utils import i18n
|
||||||
from .utils import str_coercible
|
from sqlalchemy_utils.utils import str_coercible
|
||||||
|
|
||||||
|
|
||||||
@str_coercible
|
@str_coercible
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from .utils import str_coercible
|
from sqlalchemy_utils.utils import str_coercible
|
||||||
from .weekday import WeekDay
|
from .weekday import WeekDay
|
||||||
|
|
||||||
|
|
||||||
|
@@ -133,6 +133,12 @@ class TestPath(object):
|
|||||||
assert path[0] == 's'
|
assert path[0] == 's'
|
||||||
assert path[1] == 's2'
|
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):
|
def test_getitem_with_slice(self):
|
||||||
path = Path('s.s2.s3')
|
path = Path('s.s2.s3')
|
||||||
assert path[1:] == Path('s2.s3')
|
assert path[1:] == Path('s2.s3')
|
||||||
|
Reference in New Issue
Block a user