Python sqlalchemy.orm.mapper.class_() Examples

The following are code examples for showing how to use sqlalchemy.orm.mapper.class_(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: flasky   Author: RoseOu   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ClauseAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 2
Project: Flask_Blog   Author: sugarguo   File: util.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 3
Project: jbox   Author: jpush   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 4
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 5
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 6
Project: oa_qian   Author: sunqb   File: util.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ClauseAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 7
Project: xuemc   Author: skycucumber   File: util.py    GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ClauseAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 8
Project: chihu   Author: yelongyu   File: util.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 9
Project: url_shortener   Author: martydill   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 10
Project: DevFest-MaxBond   Author: aiyyoi   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ClauseAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 11
Project: myBlog   Author: adxc   File: util.py    MIT License 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 12
Project: WRGameVideos-API   Author: thundernet8   File: util.py    GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 13
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 6 votes vote down vote up
def _setup(self, aliased_insp, adapt_on_names):
        self.__adapt_on_names = adapt_on_names
        mapper = aliased_insp.mapper
        alias = aliased_insp.selectable
        self.__target = mapper.class_
        self.__adapt_on_names = adapt_on_names
        self.__adapter = sql_util.ClauseAdapter(alias,
                            equivalents=mapper._equivalent_columns,
                            adapt_on_names=self.__adapt_on_names)
        for poly in aliased_insp.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self, poly.class_.__name__,
                    AliasedClass(poly.class_, alias, base_alias=self,
                            use_mapper_path=self._aliased_insp._use_mapper_path))

        self.__name__ = 'AliasedClass_%s' % self.__target.__name__ 
Example 14
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 6 votes vote down vote up
def class_mapper(class_, configure=True):
    """Given a class, return the primary :class:`.Mapper` associated
    with the key.

    Raises :class:`.UnmappedClassError` if no mapping is configured
    on the given class, or :class:`.ArgumentError` if a non-class
    object is passed.

    Equivalent functionality is available via the :func:`.inspect`
    function as::

        inspect(some_mapped_class)

    Using the inspection system will raise
    :class:`sqlalchemy.exc.NoInspectionAvailable` if the class is not mapped.

    """
    mapper = _inspect_mapped_class(class_, configure=configure)
    if mapper is None:
        if not isinstance(class_, type):
            raise sa_exc.ArgumentError(
                    "Class object expected, got '%r'." % class_)
        raise exc.UnmappedClassError(class_)
    else:
        return mapper 
Example 15
Project: flasky   Author: RoseOu   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)
        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 16
Project: flasky   Author: RoseOu   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 17
Project: flasky   Author: RoseOu   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            return getattr(self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 18
Project: flasky   Author: RoseOu   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        return '<AliasedInsp at 0x%x; %s>' % (
            id(self), self.class_.__name__) 
Example 19
Project: Flask_Blog   Author: sugarguo   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 20
Project: Flask_Blog   Author: sugarguo   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 21
Project: Flask_Blog   Author: sugarguo   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 22
Project: Flask_Blog   Author: sugarguo   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 23
Project: jbox   Author: jpush   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 24
Project: jbox   Author: jpush   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 25
Project: jbox   Author: jpush   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 26
Project: jbox   Author: jpush   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 27
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 28
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 29
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 30
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 31
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 32
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 33
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 34
Project: Mahjong-Solitaire   Author: MEASHY   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 35
Project: oa_qian   Author: sunqb   File: util.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)
        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 36
Project: oa_qian   Author: sunqb   File: util.py    Apache License 2.0 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 37
Project: oa_qian   Author: sunqb   File: util.py    Apache License 2.0 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            return getattr(self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 38
Project: oa_qian   Author: sunqb   File: util.py    Apache License 2.0 5 votes vote down vote up
def __repr__(self):
        return '<AliasedInsp at 0x%x; %s>' % (
            id(self), self.class_.__name__) 
Example 39
Project: analyzePF   Author: analyzeDFIR   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False,
                 represents_outer_join=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names,
            represents_outer_join
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 40
Project: analyzePF   Author: analyzeDFIR   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names,
                 represents_outer_join):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path
        self.represents_outer_join = represents_outer_join

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 41
Project: analyzePF   Author: analyzeDFIR   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 42
Project: analyzePF   Author: analyzeDFIR   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 43
Project: analyzePF   Author: analyzeDFIR   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 44
Project: xuemc   Author: skycucumber   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)
        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 45
Project: xuemc   Author: skycucumber   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 46
Project: xuemc   Author: skycucumber   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            return getattr(self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 47
Project: xuemc   Author: skycucumber   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def __repr__(self):
        return '<AliasedInsp at 0x%x; %s>' % (
            id(self), self.class_.__name__) 
Example 48
Project: chihu   Author: yelongyu   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 49
Project: chihu   Author: yelongyu   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 50
Project: chihu   Author: yelongyu   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 51
Project: chihu   Author: yelongyu   File: util.py    GNU General Public License v3.0 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 52
Project: url_shortener   Author: martydill   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 53
Project: url_shortener   Author: martydill   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 54
Project: url_shortener   Author: martydill   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            return getattr(self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 55
Project: url_shortener   Author: martydill   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 56
Project: DevFest-MaxBond   Author: aiyyoi   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)
        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 57
Project: DevFest-MaxBond   Author: aiyyoi   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 58
Project: DevFest-MaxBond   Author: aiyyoi   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            return getattr(self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 59
Project: DevFest-MaxBond   Author: aiyyoi   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        return '<AliasedInsp at 0x%x; %s>' % (
            id(self), self.class_.__name__) 
Example 60
Project: myBlog   Author: adxc   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 61
Project: myBlog   Author: adxc   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 62
Project: myBlog   Author: adxc   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 63
Project: myBlog   Author: adxc   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 64
Project: planespotter   Author: yfauser   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False,
                 represents_outer_join=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names,
            represents_outer_join
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 65
Project: planespotter   Author: yfauser   File: util.py    MIT License 5 votes vote down vote up
def __init__(self, entity, mapper, selectable, name,
                 with_polymorphic_mappers, polymorphic_on,
                 _base_alias, _use_mapper_path, adapt_on_names,
                 represents_outer_join):
        self.entity = entity
        self.mapper = mapper
        self.selectable = selectable
        self.name = name
        self.with_polymorphic_mappers = with_polymorphic_mappers
        self.polymorphic_on = polymorphic_on
        self._base_alias = _base_alias or self
        self._use_mapper_path = _use_mapper_path
        self.represents_outer_join = represents_outer_join

        self._adapter = sql_util.ColumnAdapter(
            selectable, equivalents=mapper._equivalent_columns,
            adapt_on_names=adapt_on_names, anonymize_labels=True)

        self._adapt_on_names = adapt_on_names
        self._target = mapper.class_

        for poly in self.with_polymorphic_mappers:
            if poly is not mapper:
                setattr(self.entity, poly.class_.__name__,
                        AliasedClass(poly.class_, selectable, base_alias=self,
                                     adapt_on_names=adapt_on_names,
                                     use_mapper_path=_use_mapper_path)) 
Example 66
Project: planespotter   Author: yfauser   File: util.py    MIT License 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 67
Project: planespotter   Author: yfauser   File: util.py    MIT License 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 68
Project: planespotter   Author: yfauser   File: util.py    MIT License 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 69
Project: WRGameVideos-API   Author: thundernet8   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, cls, alias=None,
                 name=None,
                 flat=False,
                 adapt_on_names=False,
                 #  TODO: None for default here?
                 with_polymorphic_mappers=(),
                 with_polymorphic_discriminator=None,
                 base_alias=None,
                 use_mapper_path=False):
        mapper = _class_to_mapper(cls)
        if alias is None:
            alias = mapper._with_polymorphic_selectable.alias(
                name=name, flat=flat)

        self._aliased_insp = AliasedInsp(
            self,
            mapper,
            alias,
            name,
            with_polymorphic_mappers
            if with_polymorphic_mappers
            else mapper.with_polymorphic_mappers,
            with_polymorphic_discriminator
            if with_polymorphic_discriminator is not None
            else mapper.polymorphic_on,
            base_alias,
            use_mapper_path,
            adapt_on_names
        )

        self.__name__ = 'AliasedClass_%s' % mapper.class_.__name__ 
Example 70
Project: WRGameVideos-API   Author: thundernet8   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 71
Project: WRGameVideos-API   Author: thundernet8   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            if mapper is self.mapper:
                return self
            else:
                return getattr(
                    self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (
                mapper, self) 
Example 72
Project: WRGameVideos-API   Author: thundernet8   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def __repr__(self):
        if self.with_polymorphic_mappers:
            with_poly = "(%s)" % ", ".join(
                mp.class_.__name__ for mp in self.with_polymorphic_mappers)
        else:
            with_poly = ""
        return '<AliasedInsp at 0x%x; %s%s>' % (
            id(self), self.class_.__name__, with_poly) 
Example 73
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def serialize(self):
        path = self.path
        return zip(
            [m.class_ for m in [path[i] for i in range(0, len(path), 2)]],
            [path[i].key for i in range(1, len(path), 2)] + [None]
        ) 
Example 74
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def class_(self):
        """Return the mapped class ultimately represented by this
        :class:`.AliasedInsp`."""
        return self.mapper.class_ 
Example 75
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def _entity_for_mapper(self, mapper):
        self_poly = self.with_polymorphic_mappers
        if mapper in self_poly:
            return getattr(self.entity, mapper.class_.__name__)._aliased_insp
        elif mapper.isa(self.mapper):
            return self
        else:
            assert False, "mapper %s doesn't correspond to %s" % (mapper, self) 
Example 76
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def __repr__(self):
        return '<AliasedInsp at 0x%x; %s>' % (
            id(self), self.class_.__name__) 
Example 77
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def _inspect_mapped_class(class_, configure=False):
    try:
        class_manager = attributes.manager_of_class(class_)
        if not class_manager.is_mapped:
            return None
        mapper = class_manager.mapper
        if configure and mapperlib.module._new_mappers:
            mapperlib.configure_mappers()
        return mapper

    except exc.NO_STATE:
        return None 
Example 78
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def _entity_descriptor(entity, key):
    """Return a class attribute given an entity and string name.

    May return :class:`.InstrumentedAttribute` or user-defined
    attribute.

    """
    insp = inspection.inspect(entity)
    if insp.is_selectable:
        description = entity
        entity = insp.c
    elif insp.is_aliased_class:
        entity = insp.entity
        description = entity
    elif hasattr(insp, "mapper"):
        description = entity = insp.mapper.class_
    else:
        description = entity

    try:
        return getattr(entity, key)
    except AttributeError:
        raise sa_exc.InvalidRequestError(
                    "Entity '%s' has no property '%s'" %
                    (description, key)
                ) 
Example 79
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def state_str(state):
    """Return a string describing an instance via its InstanceState."""

    if state is None:
        return "None"
    else:
        return '<%s at 0x%x>' % (state.class_.__name__, id(state.obj())) 
Example 80
Project: pipa-pay-server   Author: davidvon   File: util.py    Apache License 2.0 5 votes vote down vote up
def state_class_str(state):
    """Return a string describing an instance's class via its InstanceState."""

    if state is None:
        return "None"
    else:
        return '<%s>' % (state.class_.__name__, )