MCPcopy Create free account
hub / github.com/mongodb/motor / DelegateMethod

Class DelegateMethod

motor/metaprogramming.py:214–248  ·  view source on GitHub ↗

A method on the wrapped PyMongo object that does no I/O and can be called synchronously

Source from the content-addressed store, hash-verified

212
213
214class DelegateMethod(ReadOnlyProperty):
215 """A method on the wrapped PyMongo object that does no I/O and can be called
216 synchronously"""
217
218 def __init__(self, doc=None):
219 ReadOnlyProperty.__init__(self, doc)
220 self.wrap_class = None
221
222 def wrap(self, original_class):
223 self.wrap_class = original_class
224 return self
225
226 def create_attribute(self, cls, attr_name):
227 if self.wrap_class is None:
228 return ReadOnlyProperty.create_attribute(self, cls, attr_name)
229
230 method = getattr(cls.__delegate_class__, attr_name)
231 original_class = self.wrap_class
232
233 @functools.wraps(method)
234 def wrapper(self_, *args, **kwargs):
235 result = method(self_.delegate, *args, **kwargs)
236
237 # Don't call isinstance(), not checking subclasses.
238 if result.__class__ == original_class:
239 # Delegate to the current object to wrap the result.
240 return self_.wrap(result)
241 else:
242 return result
243
244 if self.doc:
245 wrapper.__doc__ = self.doc
246
247 wrapper.is_wrap_method = True # For Synchro.
248 return wrapper
249
250
251class MotorCursorChainingMethod(MotorAttributeFactory):

Callers 7

AgnosticGridOutClass · 0.90
AgnosticGridInClass · 0.90
AgnosticClientClass · 0.85
AgnosticDatabaseClass · 0.85
AgnosticCollectionClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…