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)
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
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
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
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)
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)
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
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
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
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)
def field(extract): annotate.injectClassCallback('query field', 3, '_annotate_field', name, extract) return extract
def value(value_info): annotate.injectClassCallback("value", 3, "annotate_value", value_info)
def fetch_documents(effect): annotate.injectClassCallback('fetch_documents', 3, 'annotate_fetch_documents', effect)
def static_conditions(effect): annotate.injectClassCallback('static_conditions', 3, 'annotate_static_conditions', effect)
def attach_method(query_method, method): annotate.injectClassCallback("attach_method", 3, "attach_method", query_method, method)
def register(component, canonical_name, mode): annotate.injectClassCallback("dependency", 3, "_register_dependency", component, canonical_name, mode)
def attach_code(query_method, code): annotate.injectClassCallback('attach_code', 3, 'attach_code', query_method, code)
def expose(function, security_level=SecurityLevel.safe): annotate.injectClassCallback("recorded", 4, "_register_exposed", function, security_level) return function
def publish(function): annotate.injectClassCallback("publish", 4, "_register_published", function) return function
def field(name, default, serialize_as=None): f = Field(name, default, serialize_as) annotate.injectClassCallback("field", 3, "_register_field", f)
def attach_code(query_method, code): annotate.injectClassCallback("attach_code", 3, "attach_code", query_method, code)
def document_types(types): annotate.injectClassCallback( 'document_types', 3, '_annotate_document_types', types)
def test_mixin(fun): annotate.injectClassCallback("test_mixin", 3, "_register", fun) return fun
def aggregation(name, value_info, handler, field): annotate.injectClassCallback('aggregation', 3, 'annotate_aggregation', name, value_info, handler, field)
def db_connection(effect): annotate.injectClassCallback("db_connection", 3, "annotate_db_connection", effect)
def attach_constant(method, constant, value): annotate.injectClassCallback("attach_constant", 3, "attach_constant", method, constant, value)
def may_raise(factory): annotate.injectClassCallback("alert", 3, "_register_alert_factory", factory)
def query_target(target): annotate.injectClassCallback("query_target", 3, "annotate_query_target", target)
def _annotate(name, *args, **kwargs): method_name = "annotate_" + name annotate.injectClassCallback(name, 4, method_name, *args, **kwargs)
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)