当前位置: 首页>>代码示例>>Python>>正文


Python types.TypeDecorator方法代码示例

本文整理汇总了Python中sqlalchemy.types.TypeDecorator方法的典型用法代码示例。如果您正苦于以下问题:Python types.TypeDecorator方法的具体用法?Python types.TypeDecorator怎么用?Python types.TypeDecorator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.types的用法示例。


在下文中一共展示了types.TypeDecorator方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: coerce_compared_value

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def coerce_compared_value(self, op, value):
        """Suggest a type for a 'coerced' Python value in an expression.

        Given an operator and value, gives the type a chance
        to return a type which the value should be coerced into.

        The default behavior here is conservative; if the right-hand
        side is already coerced into a SQL type based on its
        Python type, it is usually left alone.

        End-user functionality extension here should generally be via
        :class:`.TypeDecorator`, which provides more liberal behavior in that
        it defaults to coercing the other side of the expression into this
        type, thus applying special Python conversions above and beyond those
        needed by the DBAPI to both ides. It also provides the public method
        :meth:`.TypeDecorator.coerce_compared_value` which is intended for
        end-user customization of this behavior.

        """
        _coerced_type = _type_map.get(type(value), NULLTYPE)
        if _coerced_type is NULLTYPE or _coerced_type._type_affinity \
                is self._type_affinity:
            return self
        else:
            return _coerced_type 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:type_api.py

示例2: __init__

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def __init__(self, *args, **kwargs):
        """Construct a :class:`.TypeDecorator`.

        Arguments sent here are passed to the constructor
        of the class assigned to the ``impl`` class level attribute,
        assuming the ``impl`` is a callable, and the resulting
        object is assigned to the ``self.impl`` instance attribute
        (thus overriding the class attribute of the same name).

        If the class level ``impl`` is not a callable (the unusual case),
        it will be assigned to the same instance attribute 'as-is',
        ignoring those arguments passed to the constructor.

        Subclasses can override this to customize the generation
        of ``self.impl`` entirely.

        """

        if not hasattr(self.__class__, 'impl'):
            raise AssertionError("TypeDecorator implementations "
                                 "require a class-level variable "
                                 "'impl' which refers to the class of "
                                 "type being decorated")
        self.impl = to_instance(self.__class__.impl, *args, **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:type_api.py

示例3: _gen_dialect_impl

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def _gen_dialect_impl(self, dialect):
        """
        #todo
        """
        adapted = dialect.type_descriptor(self)
        if adapted is not self:
            return adapted

        # otherwise adapt the impl type, link
        # to a copy of this TypeDecorator and return
        # that.
        typedesc = self.load_dialect_impl(dialect).dialect_impl(dialect)
        tt = self.copy()
        if not isinstance(tt, self.__class__):
            raise AssertionError('Type object %s does not properly '
                                 'implement the copy() method, it must '
                                 'return an object of type %s' %
                                 (self, self.__class__))
        tt.impl = typedesc
        return tt 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:type_api.py

示例4: type_engine

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def type_engine(self, dialect):
        """Return a dialect-specific :class:`.TypeEngine` instance
        for this :class:`.TypeDecorator`.

        In most cases this returns a dialect-adapted form of
        the :class:`.TypeEngine` type represented by ``self.impl``.
        Makes usage of :meth:`dialect_impl` but also traverses
        into wrapped :class:`.TypeDecorator` instances.
        Behavior can be customized here by overriding
        :meth:`load_dialect_impl`.

        """
        adapted = dialect.type_descriptor(self)
        if not isinstance(adapted, type(self)):
            return adapted
        elif isinstance(self.impl, TypeDecorator):
            return self.impl.type_engine(dialect)
        else:
            return self.load_dialect_impl(dialect) 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:type_api.py

示例5: coerce_compared_value

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def coerce_compared_value(self, op, value):
        """Suggest a type for a 'coerced' Python value in an expression.

        Given an operator and value, gives the type a chance
        to return a type which the value should be coerced into.

        The default behavior here is conservative; if the right-hand
        side is already coerced into a SQL type based on its
        Python type, it is usually left alone.

        End-user functionality extension here should generally be via
        :class:`.TypeDecorator`, which provides more liberal behavior in that
        it defaults to coercing the other side of the expression into this
        type, thus applying special Python conversions above and beyond those
        needed by the DBAPI to both ides. It also provides the public method
        :meth:`.TypeDecorator.coerce_compared_value` which is intended for
        end-user customization of this behavior.

        """
        _coerced_type = _resolve_value_to_type(value)
        if _coerced_type is NULLTYPE or _coerced_type._type_affinity \
                is self._type_affinity:
            return self
        else:
            return _coerced_type 
开发者ID:yfauser,项目名称:planespotter,代码行数:27,代码来源:type_api.py

示例6: _makeType

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def _makeType(impl_):
    from sqlalchemy.types import TypeDecorator

    class Choice(TypeDecorator):
        impl = impl_

        def __init__(self, choices, **kw):
            self.choices = dict(choices)
            super(Choice, self).__init__(**kw)

        def process_bind_param(self, value, dialect):
            return [k for k, v in self.choices.iteritems() if v == value][0]

        def process_result_value(self, value, dialect):
            return self.choices[value]

    return Choice 
开发者ID:podhmo,项目名称:alchemyjsonschema,代码行数:19,代码来源:test_generate_schema_with_type_decorator.py

示例7: operate

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def operate(self, op, *other, **kwargs):
            kwargs['_python_is_types'] = self.expr.type.coerce_to_is_types
            return super(TypeDecorator.Comparator, self).operate(
                op, *other, **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:6,代码来源:type_api.py

示例8: reverse_operate

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def reverse_operate(self, op, other, **kwargs):
            kwargs['_python_is_types'] = self.expr.type.coerce_to_is_types
            return super(TypeDecorator.Comparator, self).reverse_operate(
                op, other, **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:6,代码来源:type_api.py

示例9: load_dialect_impl

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def load_dialect_impl(self, dialect):
        """Return a :class:`.TypeEngine` object corresponding to a dialect.

        This is an end-user override hook that can be used to provide
        differing types depending on the given dialect.  It is used
        by the :class:`.TypeDecorator` implementation of :meth:`type_engine`
        to help determine what type should ultimately be returned
        for a given :class:`.TypeDecorator`.

        By default returns ``self.impl``.

        """
        return self.impl 
开发者ID:jpush,项目名称:jbox,代码行数:15,代码来源:type_api.py

示例10: _has_bind_processor

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import TypeDecorator [as 别名]
def _has_bind_processor(self):
        """memoized boolean, check if process_bind_param is implemented.

        Allows the base process_bind_param to raise
        NotImplementedError without needing to test an expensive
        exception throw.

        """

        return self.__class__.process_bind_param.__code__ \
            is not TypeDecorator.process_bind_param.__code__ 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:type_api.py


注:本文中的sqlalchemy.types.TypeDecorator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。