Python sqlalchemy.sql.expression 模块,ClauseElement() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlalchemy.sql.expression.ClauseElement()

项目:muzi-scanner    作者:sdslabs    | 项目源码 | 文件源码
def get_or_create(self, session, model, **kwargs):
        try:
            query = session.query(model).filter_by(**kwargs)

            instance = query.first()

            if instance:
                return instance, False
            else:
                try:
                    params = dict((k, v) for k, v in kwargs.iteritems() if not isinstance(v, ClauseElement))

                    instance = model(**params)
                    session.add(instance)
                    session.commit()
            session.refresh(instance)

                    return instance, True
                except IntegrityError as e:
                    # We have failed to add track, rollback current session and continue
                    session.rollback()
                    print "[-]Failed to add, continuing"

        except Exception as e:
            raise e
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:arch-security-tracker    作者:archlinux    | 项目源码 | 文件源码
def create(self, model, defaults=None, **kwargs):
    params = dict((k, v) for k, v in kwargs.items() if not isinstance(v, ClauseElement))
    params.update(defaults or {})
    instance = model(**params)
    self.session.add(instance)
    self.session.flush()
    return instance
项目:triage    作者:dssg    | 项目源码 | 文件源码
def make_sql_clause(s, constructor):
    if not isinstance(s, ex.ClauseElement):
        return constructor(s)
    else:
        return s
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:Pirus    作者:REGOVAR    | 项目源码 | 文件源码
def get_or_create(session, model, defaults=None, **kwargs):
    """
        Generic method to get or create a SQLalchemy object from database
    """
    if defaults is None:
        defaults = {}
    try:
        query = session.query(model).filter_by(**kwargs)
        instance = query.first()
        if instance:
            return instance, False
        else:
            session.begin(nested=True)
            try:
                params = dict((k, v) for k, v in kwargs.items() if not isinstance(v, ClauseElement))
                params.update(defaults)
                instance = model(**params)
                session.add(instance)
                session.commit()
                return instance, True
            except IntegrityError as e:
                session.rollback()
                instance = query.one()
                return instance, False
    except Exception as e:
        raise e
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:books.archivelab.org    作者:ArchiveLabs    | 项目源码 | 文件源码
def get(cls, *args, **kwargs):
        """Generic 'smart' get function. Does different things based
        on number of arguments.  Some would call this a 'not smart'
        idea but we are not asking them.

        Single positional argument and no kwargs:
          args[0] is not of type ClauseElement:
            Looks up model by primary key of model specified by cls.PKEY
          args[0] is of type ClauseElement:
            Adds the clause emelemt to a where clause for a query on cls.

        Anything Else (any combination of multiple args and any kwargs):
          Converts all kwargs to clause elements, adds the args (all
          should be clause elements), and passes them together in as
          the where filter (all combined with AND) to a query on cls.
        """
        if len(args) == 1 and not isinstance(args[0], ClauseElement):
            terms = [getattr(cls, cls.PKEY) == args[0]]
        else:
            terms = list(args) + \
                [getattr(cls, k) == v for k, v in kwargs.items()]

        obj = cls.query.filter(*terms).first()
        if obj:
            return obj

        cause = dict(kwargs) if kwargs else list(args)
        raise ApiException(
            "Failed to get %s: %s" % (cls.__name__, cause),
            cause=list(cause.keys()) if kwargs else cause)
项目:books.archivelab.org    作者:ArchiveLabs    | 项目源码 | 文件源码
def exists(cls, *args, **kwargs):
        terms = None
        if len(args) == 1:
            if not isinstance(args[0], ClauseElement):
                terms = [getattr(cls, cls.PKEY) == args[0]]

        if not terms:
            terms = list(args) + \
                [getattr(cls, k) == v for k, v in kwargs.items()]

        res = db.query(getattr(cls, cls.PKEY)).filter(*terms).limit(1).first()
        if res:
            return res.id
        return False
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:python_ddd_flask    作者:igorvinnicius    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:python_ddd_flask    作者:igorvinnicius    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:QualquerMerdaAPI    作者:tiagovizoto    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:QualquerMerdaAPI    作者:tiagovizoto    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:carsus    作者:tardis-sn    | 项目源码 | 文件源码
def __new__(cls, value, unit=None):

        if (isinstance(value, QueryableAttribute) or
                isinstance(value, ClauseElement)):
            unit = Unit(unit) if unit is not None else dimensionless_unscaled
            value = np.array(value)
            value = value.view(cls)
            value._unit = unit
            return value

        else:
            return Quantity.__new__(Quantity, value, unit=unit)
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:python-flask-security    作者:weinbergdavid    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:python-flask-security    作者:weinbergdavid    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher
项目:flask    作者:bobohope    | 项目源码 | 文件源码
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate