129 |
129 |
130 settings['_info'] = info.codeinfo # fbo "action_method" |
130 settings['_info'] = info.codeinfo # fbo "action_method" |
131 return wrapped |
131 return wrapped |
132 |
132 |
133 |
133 |
134 def get_annotation_adapter(context, key, factory, markers=None, notify=True, |
134 def get_annotation_adapter(context, key, factory=None, markers=None, notify=True, |
135 locate=True, parent=None, name=None): |
135 locate=True, parent=None, name=None): |
136 """Get an adapter via object's annotations, creating it if not existent |
136 """Get an adapter via object's annotations, creating it if not existent |
137 |
137 |
138 :param object context: context object which should be adapted |
138 :param object context: context object which should be adapted |
139 :param str key: annotations key to look for |
139 :param str key: annotations key to look for |
140 :param factory: if annotations key is not found, this is the factory which will be used to |
140 :param factory: if annotations key is not found, this is the factory which will be used to |
141 create a new object |
141 create a new object; if factory is None and is requested object can't be found, None is returned |
142 :param markers: if not None, list of marker interfaces which created adapter should provide |
142 :param markers: if not None, list of marker interfaces which created adapter should provide |
143 :param bool=True notify: if 'False', no notification event will be sent on object creation |
143 :param bool=True notify: if 'False', no notification event will be sent on object creation |
144 :param bool=True locate: if 'False', the new object is not attached to any parent |
144 :param bool=True locate: if 'False', the new object is not attached to any parent |
145 :param object=None parent: parent to which new object is attached |
145 :param object=None parent: parent to which new object is attached |
146 :param str=None name: if locate is not False, this is the name with which the new object is attached |
146 :param str=None name: if locate is not False, this is the name with which the new object is attached |
149 annotations = IAnnotations(context, None) |
149 annotations = IAnnotations(context, None) |
150 if annotations is None: |
150 if annotations is None: |
151 return None |
151 return None |
152 adapter = annotations.get(key) |
152 adapter = annotations.get(key) |
153 if adapter is None: |
153 if adapter is None: |
|
154 if factory is None: |
|
155 return None |
154 adapter = annotations[key] = factory() |
156 adapter = annotations[key] = factory() |
155 if markers: |
157 if markers: |
156 for marker in markers: |
158 for marker in markers: |
157 alsoProvides(adapter, marker) |
159 alsoProvides(adapter, marker) |
158 if notify: |
160 if notify: |