Пример #1
0
def view_factory(factory, allowed_fields=[], static_conditions=None,
                 fetch_documents=None):
    annotate.injectClassCallback(
        "view_factory", 3, "annotate_view_factory",
        factory, allowed_fields=allowed_fields,
        static_conditions=static_conditions,
        fetch_documents=fetch_documents)
Пример #2
0
def entry_point(function):
    '''Combined decorator of guarded.mutable and journal.recorded
    that ensure the call is not reentrant.

    If a function decorated with it is called from inside a recording
    context it will raise L{f.i.j.ReentrantCallError}.

    Because the function cannot be called from inside a recording context,
    it always returns a Deferred.

    Same as using::

      @journal.recorded(reentrant=False)
      @guard.mutable
      def spam(self, state, some, args):
          pass
    '''

    guard_wrapper = guard.mutable(function)

    # Register the function
    canonical = reflect.class_canonical_name(3)
    annotate.injectClassCallback("recorded", 4,
                                 "_register_recorded_call", guard_wrapper,
                                 class_canonical_name=canonical)

    def wrapper(self, *args, **kwargs):
        recorder = IRecorder(self)
        return recorder.call(guard_wrapper, args, kwargs, reentrant=False)

    return wrapper
Пример #3
0
def mutable(function):
    '''Combined decorator of guarded.mutable and journal.recorded.

    When called from outside a recording context, it returns a Deferred.
    When called from inside a recording context, it returns a L{fiber.Fiber}
    or any synchronous value.

    Same as using::

      @journal.recorded()
      @guard.mutable
      def spam(self, state, some, args):
          pass
    '''

    guard_wrapper = guard.mutable(function)

    # Register the function
    canonical = reflect.class_canonical_name(3)
    annotate.injectClassCallback("recorded", 4,
                                 "_register_recorded_call", guard_wrapper,
                                 class_canonical_name=canonical)

    def wrapper(self, *args, **kwargs):
        recorder = IRecorder(self)
        return recorder.call(guard_wrapper, args, kwargs)

    return wrapper
Пример #4
0
def get_graph(method, name, params):

    Action = action.MetaAction.new(
        name, ActionCategories.retrieve,
        effects=[call.model_perform(method.__name__)],
        params=params,
        result_info=value.InterfaceValue(graph.IGraph))

    annotate.injectClassCallback(name, 4, 'annotate_action', name, Action)

    return method
Пример #5
0
def get_graph(method, name, params):

    Action = action.MetaAction.new(
        name,
        ActionCategories.retrieve,
        effects=[call.model_perform(method.__name__)],
        params=params,
        result_info=value.InterfaceValue(graph.IGraph))

    annotate.injectClassCallback(name, 4, 'annotate_action', name, Action)

    return method
Пример #6
0
Файл: meta.py Проект: f3at/feat
def meta(name, value, scheme=None):
    """
    Adds meta information to a class definition.
    @param name: name of the meta data class
    @type name: str or unicode
    @param value: metadata value
    @type value: str or unicode
    @param scheme: format information about the value
    @type scheme: str or unicode or None
    """
    annotate.injectClassCallback("meta", 3, "annotate_meta",
                                 name, value, scheme=scheme)
Пример #7
0
def query_model(model):
    """
    Annotate the effect used to retrieve the model used as a result of the
    query. This is ment to provide the lighter view of the model when its
    retrieved as a list. If this is not specified the child_model is used.

    @param model: the child's model identity, model factory or effect
                  to get it, or None to use IModel adapter.
    @type model: str or unicode or callable or IModelFactory or None
    """
    annotate.injectClassCallback("query_model", 3, "annotate_query_model",
                                 model)
Пример #8
0
def recorded(function, custom_id=None, reentrant=True):
    """MUST only be used only with method from child
    classes of L{{Recorder}}."""
    canonical = reflect.class_canonical_name(3)
    annotate.injectClassCallback(
        "recorded", 4, "_register_recorded_call", function, custom_id=custom_id, class_canonical_name=canonical
    )

    def wrapper(self, *args, **kwargs):
        recorder = IRecorder(self)
        return recorder.call(function, args, kwargs, reentrant=reentrant)

    return wrapper
Пример #9
0
def field(name, extract=None):
    if callable(extract):
        annotate.injectClassCallback('query field', 3, '_annotate_field',
                                     name, extract)
    else:
        # used as decorator

        def field(extract):
            annotate.injectClassCallback('query field', 3, '_annotate_field',
                                         name, extract)
            return extract

        return field
Пример #10
0
    def decorator(method):
        def get_accompaniment(self, *args, **kwargs):
            """Create a method for the accompaniment"""
            return self.name + " wants " + accompaniment

        # Inject the new method in the class
        annotate.injectAttribute("accompany", 3, accompaniment, get_accompaniment)

        # Inject the original method with a new name
        annotate.injectAttribute("accompany", 3, "original_" + method.__name__, method)

        def wrapper(self, *args, **kwargs):
            """Wrapp a method call and add an accompaniment to its result"""
            result = method(self, *args, **kwargs)
            return result + " and " + accompaniment

        # Call the class to register the decorator
        annotate.injectClassCallback("accompany", 3, "_decorator", accompaniment, method, wrapper)

        return wrapper
Пример #11
0
def _inject_definition(relation, descriptor_type, factory, role, force):

    if not force and factory == BasePartner:
        raise DefinitionError(
            "BasePartner class cannot be used in has_one or has_many "
            "definitions. Instead you should create a subclass for each type "
            "of relation you are defining.")

    annotate.injectClassCallback("handler", 4, "_define_handler",
                                 descriptor_type, factory, role)
    annotate.injectClassCallback("relation", 4, "_append_relation",
                                 relation)

    @property
    def getter(self):
        return self.query(relation.name)

    def getter_with_role(self, role):
        return self.query_with_role(relation.name, role)


    annotate.injectAttribute("relation_getter", 4, relation.name, getter)
    annotate.injectAttribute("relation_getter", 4,
                             relation.name + "_with_role", getter_with_role)
Пример #12
0
 def field(extract):
     annotate.injectClassCallback('query field', 3, '_annotate_field',
                                  name, extract)
     return extract
Пример #13
0
def value(value_info):
    annotate.injectClassCallback("value", 3, "annotate_value", value_info)
Пример #14
0
def fetch_documents(effect):
    annotate.injectClassCallback('fetch_documents', 3,
                                 'annotate_fetch_documents',
                                 effect)
Пример #15
0
def static_conditions(effect):
    annotate.injectClassCallback('static_conditions', 3,
                                 'annotate_static_conditions',
                                 effect)
Пример #16
0
Файл: view.py Проект: f3at/feat
def attach_method(query_method, method):
    annotate.injectClassCallback("attach_method", 3, "attach_method", query_method, method)
Пример #17
0
def register(component, canonical_name, mode):
    annotate.injectClassCallback("dependency", 3, "_register_dependency",
                                 component, canonical_name, mode)
Пример #18
0
def attach_code(query_method, code):
    annotate.injectClassCallback('attach_code', 3, 'attach_code',
                                 query_method, code)
Пример #19
0
def expose(function, security_level=SecurityLevel.safe):
    annotate.injectClassCallback("recorded", 4,
                                 "_register_exposed", function,
                                 security_level)

    return function
Пример #20
0
def publish(function):
    annotate.injectClassCallback("publish", 4, "_register_published", function)
    return function
Пример #21
0
def field(name, default, serialize_as=None):
    f = Field(name, default, serialize_as)
    annotate.injectClassCallback("field", 3, "_register_field", f)
Пример #22
0
Файл: view.py Проект: f3at/feat
def attach_code(query_method, code):
    annotate.injectClassCallback("attach_code", 3, "attach_code", query_method, code)
Пример #23
0
def document_types(types):
    annotate.injectClassCallback(
        'document_types', 3, '_annotate_document_types', types)
Пример #24
0
def test_mixin(fun):
    annotate.injectClassCallback("test_mixin", 3, "_register", fun)
    return fun
Пример #25
0
def aggregation(name, value_info, handler, field):
    annotate.injectClassCallback('aggregation', 3, 'annotate_aggregation',
                                 name, value_info, handler, field)
Пример #26
0
def db_connection(effect):
    annotate.injectClassCallback("db_connection", 3, "annotate_db_connection",
                                 effect)
Пример #27
0
Файл: view.py Проект: f3at/feat
def attach_constant(method, constant, value):
    annotate.injectClassCallback("attach_constant", 3, "attach_constant", method, constant, value)
Пример #28
0
Файл: alert.py Проект: f3at/feat
def may_raise(factory):
    annotate.injectClassCallback("alert", 3, "_register_alert_factory",
                                 factory)
Пример #29
0
def query_target(target):
    annotate.injectClassCallback("query_target", 3, "annotate_query_target",
                                 target)
Пример #30
0
def _annotate(name, *args, **kwargs):
    method_name = "annotate_" + name
    annotate.injectClassCallback(name, 4, method_name, *args, **kwargs)
Пример #31
0
def factory(factory, allowed_fields=[],
            item_field=None, include_value=list()):
    annotate.injectClassCallback(
        "factory", 3, "annotate_factory", factory,
        allowed_fields=allowed_fields, include_value=include_value,
        item_field=item_field)