Beispiel #1
0
def _register_attribute(
    strategy,
    mapper,
    useobject,
    compare_function=None,
    typecallable=None,
    copy_function=None,
    mutable_scalars=False,
    uselist=False,
    callable_=None,
    proxy_property=None,
    active_history=False,
    impl_class=None,
    **kw
):

    prop = strategy.parent_property
    attribute_ext = util.to_list(prop.extension) or []

    if useobject and prop.single_parent:
        attribute_ext.append(_SingleParentValidator(prop))

    if getattr(prop, "backref", None):
        attribute_ext.append(prop.backref.extension)

    if prop.key in prop.parent._validators:
        attribute_ext.append(mapperutil.Validator(prop.key, prop.parent._validators[prop.key]))

    if useobject:
        attribute_ext.append(sessionlib.UOWEventHandler(prop.key))

    for m in mapper.polymorphic_iterator():
        if (m is prop.parent or not m.concrete) and m.has_property(prop.key):
            attributes.register_attribute_impl(
                m.class_,
                prop.key,
                parent_token=prop,
                mutable_scalars=mutable_scalars,
                uselist=uselist,
                copy_function=copy_function,
                compare_function=compare_function,
                useobject=useobject,
                extension=attribute_ext,
                trackparent=useobject,
                typecallable=typecallable,
                callable_=callable_,
                active_history=active_history,
                impl_class=impl_class,
                **kw
            )
Beispiel #2
0
def _register_attribute(
    strategy,
    mapper,
    useobject,
    compare_function=None,
    typecallable=None,
    copy_function=None,
    mutable_scalars=False,
    uselist=False,
    callable_=None,
    proxy_property=None,
    active_history=False,
    impl_class=None,
    **kw
):

    prop = strategy.parent_property
    attribute_ext = list(util.to_list(prop.extension, default=[]))

    if useobject and prop.single_parent:
        attribute_ext.insert(0, _SingleParentValidator(prop))

    if prop.key in prop.parent._validators:
        attribute_ext.insert(0, mapperutil.Validator(prop.key, prop.parent._validators[prop.key]))

    if useobject:
        attribute_ext.append(sessionlib.UOWEventHandler(prop.key))

    for m in mapper.self_and_descendants:
        if prop is m._props.get(prop.key):

            attributes.register_attribute_impl(
                m.class_,
                prop.key,
                parent_token=prop,
                mutable_scalars=mutable_scalars,
                uselist=uselist,
                copy_function=copy_function,
                compare_function=compare_function,
                useobject=useobject,
                extension=attribute_ext,
                trackparent=useobject,
                typecallable=typecallable,
                callable_=callable_,
                active_history=active_history,
                impl_class=impl_class,
                doc=prop.doc,
                **kw
            )
Beispiel #3
0
def _register_attribute(strategy,
                        mapper,
                        useobject,
                        compare_function=None,
                        typecallable=None,
                        copy_function=None,
                        mutable_scalars=False,
                        uselist=False,
                        callable_=None,
                        proxy_property=None,
                        active_history=False,
                        impl_class=None,
                        **kw):

    prop = strategy.parent_property
    attribute_ext = util.to_list(prop.extension) or []

    if useobject and prop.single_parent:
        attribute_ext.append(_SingleParentValidator(prop))

    if getattr(prop, 'backref', None):
        attribute_ext.append(prop.backref.extension)

    if prop.key in prop.parent._validators:
        attribute_ext.append(
            mapperutil.Validator(prop.key, prop.parent._validators[prop.key]))

    if useobject:
        attribute_ext.append(sessionlib.UOWEventHandler(prop.key))

    for m in mapper.polymorphic_iterator():
        if prop is m._props.get(prop.key):

            attributes.register_attribute_impl(
                m.class_,
                prop.key,
                parent_token=prop,
                mutable_scalars=mutable_scalars,
                uselist=uselist,
                copy_function=copy_function,
                compare_function=compare_function,
                useobject=useobject,
                extension=attribute_ext,
                trackparent=useobject,
                typecallable=typecallable,
                callable_=callable_,
                active_history=active_history,
                impl_class=impl_class,
                **kw)
Beispiel #4
0
def _register_attribute(strategy,
                        mapper,
                        useobject,
                        compare_function=None,
                        typecallable=None,
                        copy_function=None,
                        mutable_scalars=False,
                        uselist=False,
                        callable_=None,
                        proxy_property=None,
                        active_history=False,
                        impl_class=None,
                        **kw):

    prop = strategy.parent_property
    attribute_ext = list(util.to_list(prop.extension, default=[]))

    if useobject and prop.single_parent:
        attribute_ext.insert(0, _SingleParentValidator(prop))

    if prop.key in prop.parent._validators:
        attribute_ext.insert(
            0, mapperutil.Validator(prop.key,
                                    prop.parent._validators[prop.key]))

    if useobject:
        attribute_ext.append(sessionlib.UOWEventHandler(prop.key))

    for m in mapper.self_and_descendants:
        if prop is m._props.get(prop.key):

            attributes.register_attribute_impl(
                m.class_,
                prop.key,
                parent_token=prop,
                mutable_scalars=mutable_scalars,
                uselist=uselist,
                copy_function=copy_function,
                compare_function=compare_function,
                useobject=useobject,
                extension=attribute_ext,
                trackparent=useobject,
                typecallable=typecallable,
                callable_=callable_,
                active_history=active_history,
                impl_class=impl_class,
                doc=prop.doc,
                **kw)
Beispiel #5
0
def _register_attribute(strategy,
                        mapper,
                        useobject,
                        compare_function=None,
                        typecallable=None,
                        copy_function=None,
                        mutable_scalars=False,
                        uselist=False,
                        callable_=None,
                        proxy_property=None,
                        active_history=False,
                        impl_class=None,
                        **kw):

    prop = strategy.parent_property

    attribute_ext = list(util.to_list(prop.extension, default=[]))

    listen_hooks = []

    if useobject and prop.single_parent:
        listen_hooks.append(single_parent_validator)

    if prop.key in prop.parent._validators:
        listen_hooks.append(lambda desc, prop: mapperutil._validator_events(
            desc, prop.key, prop.parent._validators[prop.key]))

    if useobject:
        listen_hooks.append(unitofwork.track_cascade_events)

    # need to assemble backref listeners
    # after the singleparentvalidator, mapper validator
    backref = kw.pop('backref', None)
    if backref:
        listen_hooks.append(lambda desc, prop: attributes.backref_listeners(
            desc, backref, uselist))

    for m in mapper.self_and_descendants:
        if prop is m._props.get(prop.key):

            desc = attributes.register_attribute_impl(
                m.class_,
                prop.key,
                parent_token=prop,
                mutable_scalars=mutable_scalars,
                uselist=uselist,
                copy_function=copy_function,
                compare_function=compare_function,
                useobject=useobject,
                extension=attribute_ext,
                trackparent=useobject,
                typecallable=typecallable,
                callable_=callable_,
                active_history=active_history,
                impl_class=impl_class,
                doc=prop.doc,
                **kw)

            for hook in listen_hooks:
                hook(desc, prop)
Beispiel #6
0
def _register_attribute(strategy, mapper, useobject,
        compare_function=None, 
        typecallable=None,
        copy_function=None, 
        mutable_scalars=False, 
        uselist=False,
        callable_=None, 
        proxy_property=None, 
        active_history=False,
        impl_class=None, 
        **kw
):

    prop = strategy.parent_property

    attribute_ext = list(util.to_list(prop.extension, default=[]))

    listen_hooks = []

    if useobject and prop.single_parent:
        listen_hooks.append(single_parent_validator)

    if prop.key in prop.parent._validators:
        listen_hooks.append(
            lambda desc, prop: mapperutil._validator_events(desc, 
                                prop.key, 
                                prop.parent._validators[prop.key])
        )

    if useobject:
        listen_hooks.append(unitofwork.track_cascade_events)

    # need to assemble backref listeners
    # after the singleparentvalidator, mapper validator
    backref = kw.pop('backref', None)
    if backref:
        listen_hooks.append(
            lambda desc, prop: attributes.backref_listeners(desc, 
                                backref, 
                                uselist)
        )

    for m in mapper.self_and_descendants:
        if prop is m._props.get(prop.key):

            desc = attributes.register_attribute_impl(
                m.class_, 
                prop.key, 
                parent_token=prop,
                mutable_scalars=mutable_scalars,
                uselist=uselist, 
                copy_function=copy_function, 
                compare_function=compare_function, 
                useobject=useobject,
                extension=attribute_ext, 
                trackparent=useobject, 
                typecallable=typecallable,
                callable_=callable_, 
                active_history=active_history,
                impl_class=impl_class,
                doc=prop.doc,
                **kw
                )

            for hook in listen_hooks:
                hook(desc, prop)